plugins-evert/fun/plugin.ts

93 lines
5.4 KiB
TypeScript
Raw Normal View History

2020-12-05 10:00:00 +00:00
import {
Plugin,
Configurable,
EventListener,
DependencyLoad
} from '@squeebot/core/lib/plugin';
import { IMessage } from '@squeebot/core/lib/types';
const alpaca = ['a3d53439', '870b9e10', 'c40c5aad', '77e87cd4', '5815410d', '1855876d', 'd134d47f', '6e0db005', 'b2e471da', 'd083213f', '9ac93967', '1f53ea27', '00ab6411', 'bfdc0079', 'ce29fc6f', '552665d0', '8be91f16', 'b7499ec2', 'b9d52259', '6e505095', '4bc30df8', 'c1854975', 'fe87532c', '9e6cb311', '9e6d6e69', 'f79992bf', '11aa0714', 'c27e712f', '8ee7d28c', 'd79b158f', 'a495bad4', 'df93dc7e', '57ed2f42', '9e2c0722', '3a6c0bab', '4268b737', '490f09bf', 'f6d8fca6', '3d3d96b1', 'f1d82aaa', 'fb1a6e0e', '31a96aee', 'a0cc346f', '9f88d146', 'a55a91a4', '83ee2889', '94c60ee3', '30e66d58', '27870c50', '7adf19c6', '2920ceac', 'ddd62b77', '86a6efe7', '02d2d4f4', 'bebd657c', '1c5a3508', 'c3c6fc4b', '1761ebbc', '7eeaab38', 'd9a12e72', '42356945', 'dff46a1a', '413c741a', 'a7761c60', 'f3316806', '782b8b6c', '6547d625', 'd17bea20', 'fdc5c329', '56bb5991', '9a9ebe09', '8bb0818e', '4692f354', '9d91ce89', 'b3fb3715', '0d03a684', '115af660', '845031e2', '945d26bd', 'd3b1dd25', 'c2cb872f', '0c202666', '357e5195', 'fef6732c', '8a88104e', '1fdbc9ec', 'f6ad84dc', '473eb851', 'd078e723', '5079e902', '8a81a94f', '285c6ef8', '443b7f25', '0ba9ecac', '36d044a9', '7fa1366e', '88dedd53', '7839d770', '50ee9fd7', 'f0a4f672', '74526d28', '639106bf', '8aa61988', 'f6615095', '42385e98', 'ba94be4d', '8c81f5ee', '7bfb19f9', '5cc54d76', '962d2cfb', 'eaee222d', '994575be', '114927a6', 'd3119ed2', 'ce62f835', '0dc3fbb7', 'dc7f629f', '103d03cb', '96e54eb1', 'be395291', 'c469785e', '0c3d13cf', 'f61a1b43', 'bb64b44e', 'c8cdf1e7', '9cd9589a', '92f745d3', 'c9a168e4', 'b5a59c3e', 'ae5e3337', 'ff2a8f2d', 'eef41a7e', 'ef4fad05', '4a2f3a69', '7f9af8df', '9731dcba', 'f4b64638', 'f19b7a28', '87b5f9bb', '8e261176', '6353444c', '68cf22f1', 'e8c05fa5', '0d080496', 'f15c48a1', 'd0dcb52d', '1774d947', 'ead69e2f', '16a9d0d0', 'bae38658', '1b802c4b', '4502f826', '0a4bbb94', '957892e3', '54b50c3b', '6d0e742e', 'e3231c9d', '4e88f997', 'de8a6111', '9d9ff907', 'dbecd1de', 'c11dd818', '6ce07218', 'e73aec0b', 'e5a030b1', '52c22730', '6648a887', 'dabec190', '079c58e1', '94b7882c', 'ac905c5f', '11845f34', '87a871cd', 'bacb3cb9', '9f8584fd', 'f6788d62', 'fae5c010', '8d73c238', '1fe8c363', 'c7408956', '313bd1fb', '0a2de87a', '0fec45a8', '5a23fe9f', '9496c280', 'dc04d424', '1dee8f8b', '44f222a4', 'a0d96fd5', '70563299', 'b3e7bfd2', '49f47c49', '20d103e1', '7ebe873a', '7b13e329', '85cc1c96', 'b569d2d5', '61ccd52f', '8e99ecad', '63b87b93', '3b2e9d58', 'c07a484a', '3e414e22', 'ea030f21', 'd94348a6', '87b486cf', 'fbd5f38e', '81d7c9fc', '4a8aec26', '0d5cb865', 'f840c174', '8762c66d', '5a99399c', 'c00c8cf1', '122ae6de', 'adb4efc5', '84e09e92', 'b21658fd', 'c25cfcaf', '0ac96278', 'a8e49500', '05a639ef', 'bb10bed8', '6a844be3', 'ab06cede', 'b9a8c57e', '6e6b1745', 'a8bf0e1d', 'ae9c19bf', '0392b422', '9dc049e4', '61efd0d2', 'f0759c3d', '29482eb7', 'aa059afe', '7a03c62f', 'a8a8b79c', '59629470', 'c1949ac1', '721db006', '486a31f9', '793cf9cd', '81eb3518', '319c6398', 'd35b269d', '1d1a5014', 'a10506a9', 'ed61196c', '5fd4c99e', '1d92b5ab', 'c34a7a0e', 'ad19db59', '25346668', '0b17393e', '466bd057', 'f9860642', '7d74f7d0', '6719ce53', '95864f2a', 'e810e07c', '9a0a127d', '428f9e7c', '98d645ba', '444a27d5', '999f6fe9'];
@Configurable({
simpleReplies: {
ping: 'pong'
}
})
class FunPlugin extends Plugin {
@EventListener('pluginUnload')
public unloadEventHandler(plugin: string | Plugin): void {
if (plugin === this.name || plugin === this) {
this.emit('pluginUnloaded', this);
}
}
initialize(): void {
// Hug action
this.on('message', (data: IMessage) => {
const messageRefined = data.text.toLowerCase().trim().replace(/@/g, '');
const myName = data.source.me.name.toLowerCase();
const myID = data.source.me.id;
// IRC and Discord support
if (messageRefined.includes(`hugs ${myName}`)
|| messageRefined.includes(`hugs <!${myID}>`)) {
2020-12-05 10:00:00 +00:00
// Add a little bit of delay (personal preference)
setTimeout(() => {
if (data.sender) {
data.resolve(data.source.format.format('action', 'hugs ' +
data.mention(data.sender)));
}
}, 1000);
}
});
}
@DependencyLoad('simplecommands')
addCommands(cmd: any): void {
const cmds: any = [];
if (this.config.config.simpleReplies) {
const simpleReply = this.config.config.simpleReplies;
for (const name in simpleReply) {
cmds.push({
name,
plugin: this.name,
execute: async (msg: IMessage): Promise<boolean> => {
msg.resolve(simpleReply[name]);
return true;
},
hidden: true
});
}
}
cmds.push({
name: 'hug',
plugin: this.name,
execute: async (msg: IMessage): Promise<boolean> => {
2020-12-05 16:14:35 +00:00
if (!msg.sender) {
return true;
}
msg.resolve(msg.source.format.format('action', 'hugs %s'), msg.mention(msg.sender));
2020-12-05 10:00:00 +00:00
return true;
},
hidden: true
});
cmds.push({
name: 'alpaca',
plugin: this.name,
execute: async (msg: IMessage): Promise<boolean> => {
const rand = Math.floor(Math.random() * alpaca.length);
msg.resolve('http://jocketf.se/c/' + alpaca[rand]);
return true;
},
hidden: true
});
cmd.registerCommand(cmds);
}
}
module.exports = FunPlugin;