Adding additional methods (mode, nick, ctcp etc.) to reduce use of raw.
Removing things like kiwi and action in favour of a unified ctcp method.
if (typeof msg[1] === 'undefined') {\r
msg[1] = '';\r
}\r
- kiwi.gateway.notice(data.nick, String.fromCharCode(1) + 'PING ' + msg[1] + String.fromCharCode(1));\r
+ kiwi.gateway.ctcp(false, 'PING', data.nick, msg[1]);\r
break;\r
case 'TIME':\r
- kiwi.gateway.notice(data.nick, String.fromCharCode(1) + 'TIME ' + (new Date()).toLocaleString() + String.fromCharCode(1));\r
+ kiwi.gateway.ctcp(false, 'TIME', data.nick, (new Date()).toLocaleString());\r
break;\r
}\r
Tabview.getServerTab().addMsg(null, 'CTCP Request', '[from ' + data.nick + '] ' + data.msg, 'ctcp');\r
text = $(this).text();
if (text !== kiwi.front.cache.original_topic) {
chan = Tabview.getCurrentTab().name;
- kiwi.gateway.setTopic(chan, text);
+ kiwi.gateway.topic(chan, text);
}
});
run: function (msg) {
- var parts, dest, t, pos, textRange, plugin_event, msg_sliced, tab;
+ var parts, dest, t, pos, textRange, plugin_event, msg_sliced, tab, nick;
// Run through any plugins
plugin_event = {command: msg};
console.log("calling show nick");
kiwi.front.ui.showChangeNick();
} else {
- console.log("sending raw");
- kiwi.gateway.raw(msg.substring(1));
+ console.log("sending nick");
+ kiwi.gateway.nick(msg.substring(1));
}
break;
if (Tabview.getCurrentTab().safe_to_close) {
Tabview.getCurrentTab().close();
} else {
- kiwi.gateway.raw(msg.substring(1) + ' ' + Tabview.getCurrentTab().name);
+ kiwi.gateway.part(Tabview.getCurrentTab().name);
}
} else {
- kiwi.gateway.raw(msg.substring(1));
+ kiwi.gateway.part(msg.substring(6));
}
break;
case '/msg':
if (typeof parts[1] !== "undefined") {
msg_sliced = msg.split(' ').slice(2).join(' ');
- kiwi.gateway.msg(parts[1], msg_sliced);
+ kiwi.gateway.privmsg(parts[1], msg_sliced);
tab = Tabview.getTab(parts[1]);
if (!tab) {
if (typeof parts[1] === 'undefined') {
return;
}
- kiwi.gateway.raw('KICK ' + Tabview.getCurrentTab().name + ' ' + msg.split(' ', 2)[1]);
+ t = msg.split(' ', 3);
+ nick = t[1];
+ kiwi.gateway.kick(Tabview.getCurrentTab().name, nick, t[2]);
break;
case '/quote':
case '/me':
tab = Tabview.getCurrentTab();
- kiwi.gateway.action(tab.name, msg.substring(4));
- //tab.addMsg(null, ' ', '* '+data.nick+' '+data.msg, 'color:green;');
+ kiwi.gateway.ctcp(true, 'ACTION', tab.name, msg.substring(4));
tab.addMsg(null, ' ', '* ' + kiwi.gateway.nick + ' ' + msg.substring(4), 'action', 'color:#555;');
break;
t.setSelectionRange(pos, pos);
}
} else {
- kiwi.gateway.setTopic(Tabview.getCurrentTab().name, msg.split(' ', 2)[1]);
- //kiwi.gateway.raw('TOPIC ' + Tabview.getCurrentTab().name + ' :' + msg.split(' ', 2)[1]);
+ kiwi.gateway.topic(Tabview.getCurrentTab().name, msg.split(' ', 2)[1]);
}
break;
case '/kiwi':
- kiwi.gateway.kiwi(Tabview.getCurrentTab().name, msg.substring(6));
+ kiwi.gateway.ctcp(true, 'KIWI', Tabview.getCurrentTab().name, msg.substring(6));
break;
case '/ctcp':
parts = parts.slice(1);
dest = parts.shift();
+ t = parts.shift();
msg = parts.join(' ');
-
- kiwi.gateway.msg(dest, String.fromCharCode(1) + msg + String.fromCharCode(1));
- Tabview.getServerTab().addMsg(null, 'CTCP Request', '[to ' + dest + '] ' + msg, 'ctcp');
+ console.log(parts);
+
+ kiwi.gateway.ctcp(true, t, dest, msg);
+ Tabview.getServerTab().addMsg(null, 'CTCP Request', '[to ' + dest + '] ' + t + ' ' + msg, 'ctcp');
break;
default:
//Tabview.getCurrentTab().addMsg(null, ' ', '--> Invalid command: '+parts[0].substring(1));
return;
}
if (Tabview.getCurrentTab().name !== 'server') {
- kiwi.gateway.msg(Tabview.getCurrentTab().name, msg);
+ kiwi.gateway.privmsg(Tabview.getCurrentTab().name, msg);
Tabview.getCurrentTab().addMsg(null, kiwi.gateway.nick, msg);
}
}
sendData: function () {},
- sync: function (callback) {
- if (this.session_id === null) {
- return;
- }
-
+ privmsg: function (target, msg, callback) {
var data = {
- method: 'sync',
- args: {}
+ method: 'privmsg',
+ args: {
+ target: target,
+ msg: msg
+ }
};
- kiwi.gateway.syncing = true;
kiwi.gateway.sendData(data, callback);
},
- debug: function (callback) {
+ notice: function (target, msg, callback) {
var data = {
- method: 'debug',
- args: {}
+ method: 'notice',
+ args: {
+ target: target,
+ msg: msg
+ }
};
kiwi.gateway.sendData(data, callback);
},
-
- msg: function (s_target, s_msg, callback) {
+ ctcp: function (request, type, target, params, callback) {
var data = {
- method: 'msg',
+ method: 'ctcp',
args: {
- target: s_target,
- msg: s_msg
+ request: request,
+ type: type,
+ target: target,
+ params: params,
}
};
-
+
kiwi.gateway.sendData(data, callback);
},
- action: function (s_target, s_msg, callback) {
+ join: function (channel, key, callback) {
var data = {
- method: 'action',
+ method: 'join',
args: {
- target: s_target,
- msg: s_msg
+ channel: channel,
+ key: key
}
};
kiwi.gateway.sendData(data, callback);
},
-
- kiwi: function (s_target, s_data, callback) {
+ part: function (channel, callback) {
var data = {
- method: 'kiwi',
+ method: 'part',
args: {
- target: s_target,
- data: s_data
+ channel: channel
}
};
+
kiwi.gateway.sendData(data, callback);
},
-
- notice: function (s_target, s_msg, callback) {
+ topic: function (channel, new_topic, callback) {
var data = {
- method: 'notice',
+ method: 'topic',
args: {
- target: s_target,
- msg: s_msg
+ channel: channel,
+ topic: new_topic
}
};
kiwi.gateway.sendData(data, callback);
},
-
- join: function (s_channel, callback) {
+ kick: function (channel, nick, reason, callback) {
var data = {
- method: 'join',
+ method: 'kick',
args: {
- channel: s_channel
+ channel: channel,
+ nick: nick,
+ reason: reason
}
};
kiwi.gateway.sendData(data, callback);
},
- setTopic: function (s_channel, new_topic, callback) {
+ quit: function (msg, callback) {
+ msg = msg || "";
var data = {
- method: 'topic',
+ method: 'quit',
args: {
- channel: s_channel,
- topic: new_topic
+ message: msg
}
};
kiwi.gateway.sendData(data, callback);
},
-
- raw: function (v_data, callback) {
+ raw: function (data, callback) {
var data = {
method: 'raw',
args: {
- data: v_data
+ data: data
}
};
kiwi.gateway.sendData(data, callback);
},
-
- quit: function (msg, callback) {
- //alert("closing");
- msg = msg || "";
+ nick: function (new_nick, callback) {
var data = {
- method: 'quit',
+ method: 'nick',
args: {
- message: msg
+ nick: new_nick
}
};
kiwi.gateway.sendData(data, callback);
- }
-
-
-
-
+ },
};
this.websocketMessage = function (websocket, msg, callback) {
- var args, obj;
+ var args, obj, channels, keys;
try {
msg.data = JSON.parse(msg.data);
args = msg.data.args;
switch (msg.data.method) {
- case 'msg':
+ case 'privmsg':
if ((args.target) && (args.msg)) {
obj = kiwi.kiwi_mod.run('msgsend', args, {websocket: websocket});
if (obj !== null) {
}
}
break;
- case 'action':
- if ((args.target) && (args.msg)) {
- websocket.sendServerLine('PRIVMSG ' + args.target + ' :' + String.fromCharCode(1) + 'ACTION ' + args.msg + String.fromCharCode(1));
- }
- break;
-
- case 'kiwi':
- if ((args.target) && (args.data)) {
- websocket.sendServerLine('PRIVMSG ' + args.target + ' :' + String.fromCharCode(1) + 'KIWI ' + args.data + String.fromCharCode(1));
+ case 'ctcp':
+ if ((args.target) && (args.type)) {
+ if (args.request) {
+ websocket.sendServerLine('PRIVMSG ' + args.target + ' :' + String.fromCharCode(1) + args.type.toUpperCase() + ' ' + args.params + String.fromCharCode(1));
+ } else {
+ websocket.sendServerLine('NOTICE ' + args.target + ' :' + String.fromCharCode(1) + args.type.toUpperCase() + ' ' + args.params + String.fromCharCode(1));
+ }
}
break;
case 'raw':
websocket.sendServerLine(args.data);
break;
+
case 'join':
+ if (args.channel) {
+ channels = args.channel.split(",");
+ keys = (args.key) ? args.key.split(",") : [];
+ _.each(channels, function (chan, index) {
+ websocket.sendServerLine('JOIN ' + chan + ' ' + (keys[index] || ''));
+ });
+ }
+ break;
+
+ case 'part':
if (args.channel) {
_.each(args.channel.split(","), function (chan) {
- websocket.sendServerLine('JOIN ' + chan);
+ websocket.sendServerLine('PART ' + chan);
});
}
break;
+
case 'topic':
if (args.channel) {
- websocket.sendServerLine('TOPIC ' + args.channel + ' :' + args.topic);
+ if (args.topic) {
+ websocket.sendServerLine('TOPIC ' + args.channel + ' :' + args.topic);
+ } else {
+ websocket.sendServerLine('TOPIC ' + args.channel);
+ }
+ }
+ break;
+
+ case 'kick':
+ if ((args.channel) && (args.nick)) {
+ websocket.sendServerLine('KICK ' + args.channel + ' ' + args.nick + ':' + args.reason);
}
break;
+
case 'quit':
websocket.ircSocket.end('QUIT :' + args.message + '\r\n');
websocket.sentQUIT = true;
websocket.ircSocket.destroySoon();
websocket.disconnect();
break;
+
case 'notice':
if ((args.target) && (args.msg)) {
websocket.sendServerLine('NOTICE ' + args.target + ' :' + args.msg);
}
break;
+
+ case 'mode':
+ if ((args.target) && (args.mode)) {
+ websocket.sendServerLine('MODE ' + args.target + ' ' + args.mode + ' ' + args.params);
+ }
+ break;
+
+ case 'nick':
+ if (args.nick) {
+ websocket.sendServerLine('NICK ' + args.nick);
+ }
+ break;
+
default:
}
if ((callback) && (typeof (callback) === 'function')) {