Skip to content
This repository has been archived by the owner on Nov 11, 2020. It is now read-only.

Commit

Permalink
First commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
AKPWebDesign committed May 4, 2016
0 parents commit 5ca8602
Show file tree
Hide file tree
Showing 3 changed files with 148 additions and 0 deletions.
106 changes: 106 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
'use strict';
const MessageHandlerPlugin = require('../../lib/MessageHandlerPlugin');

class IRCJoinMsg extends MessageHandlerPlugin {
constructor(AKP48, config) {
super('IRCJoinMsg', AKP48);
var self = this;
this.instances = [];
this._config = config;
this._handle = null;

this.perms = [
'irc.channel.owner',
'irc.channel.op',
'irc.channel.protected',
'irc.channel.halfop',
'AKP48.owner',
'AKP48.op'
];

if(!this._config) {
this._config = {
channels: {
'#exampleChannel': 'This is an example message. Welcome, $user!'
}
};
this._AKP48.saveConfig(this._config, 'irc-join-msg');
}

this._AKP48.on('serverConnect', (id, instance) => {
self.instances.push(instance);

if(!self._handle) {
self._handle = function(channel, nick){
self.handleJoin(channel, nick, instance);
};
}

instance.on('join', self._handle);
});
}

unload() {
for (let svr of this.instances) {
svr.removeListener('join', this._handleJoin);
}
return true;
}
}

IRCJoinMsg.prototype.handleJoin = function (channel, nick, instance) {
GLOBAL.logger.silly(`${this._pluginName}: Received join event.`);
if(this._config.channels[channel]) {
var msg = this._config.channels[channel].replace(/\$user/g, nick);
instance.say(channel, msg);
}
};

IRCJoinMsg.prototype.handleMessage = function (msg, ctx, res) {

GLOBAL.logger.silly(`${this._pluginName}: Received command.`);
// if this isn't an IRC instance, drop the command.
if(!ctx.instanceType || ctx.instanceType !== 'irc') {
GLOBAL.logger.silly(`${this._pluginName}: Dropping command; not IRC instance.`);
return;
}
var good = false;

for (let perm in ctx.perms) {
if(this.perms.contains(perm)) {
good = true;
break;
}
}

if(!good) {return;}

if(msg.toLowerCase().startsWith('setmessage ')) {
//remove command from message
msg = msg.split(' ');
msg.splice(1, 0);
msg = msg.join(' ');

res(this.setMessage(msg, ctx));
}

if(msg.toLowerCase().startsWith('clearmessage ')) {
res(this.clearMessage(ctx));
}
};

IRCJoinMsg.prototype.setMessage = function (msg, chan) {
this._config.channels[chan] = msg;
this._AKP48.saveConfig(this._config, 'irc-join-msg');
return `Join message for ${chan} has been set to "${msg}"`;
};

IRCJoinMsg.prototype.clearMessage = function (chan) {
if(this._config.channels[chan]) {
delete this._config.channels[chan];
}
this._AKP48.saveConfig(this._config, 'irc-join-msg');
return `Join message for ${chan} has been cleared.`;
};

module.exports = IRCJoinMsg;
11 changes: 11 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "akp48-plugin-irc-join-msg",
"version": "1.0.0",
"description": "Sends a message to an IRC channel any time someone joins.",
"main": "main.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Austin Peterson <[email protected]>",
"license": "MIT"
}
31 changes: 31 additions & 0 deletions plugin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"name": "irc-join-msg",
"type": "MessageHandler",
"description": "Google commands for AKP48.",
"main": "main.js",
"commands": {
"setMessage": {
"helpText": "Sets the message that the bot sends in the current channel.",
"usageText": "<msg>",
"perms": [
"irc.channel.owner",
"irc.channel.op",
"irc.channel.protected",
"irc.channel.halfop",
"AKP48.owner",
"AKP48.op"
]
},
"clearMessage": {
"helpText": "Clear the message that the bot sends to the current channel, stopping it from being sent anymore.",
"perms": [
"irc.channel.owner",
"irc.channel.op",
"irc.channel.protected",
"irc.channel.halfop",
"AKP48.owner",
"AKP48.op"
]
}
}
}

0 comments on commit 5ca8602

Please sign in to comment.