1 | "use strict";
|
2 |
|
3 | var bot = global.bot_reference;
|
4 | var bot_proto = global.bot_proto_reference;
|
5 |
|
6 | function parsable(int) {
|
7 | return !isNaN(int);
|
8 | }
|
9 |
|
10 |
|
11 |
|
12 |
|
13 | bot_proto.prototype.sendMessage = function(msg, target) {
|
14 | if(typeof msg != 'string') return;
|
15 | bot.sendCommand('sendtextmessage', {'targetmode': 1, 'target': target, 'msg': msg});
|
16 | return this;
|
17 | }
|
18 |
|
19 | bot_proto.prototype.sendPoke = function(msg, target) {
|
20 | bot.sendCommand('clientpoke', {'clid': target, 'msg': msg});
|
21 | return this;
|
22 | }
|
23 |
|
24 | bot_proto.prototype.say = function(msg) {
|
25 | bot.sendCommand('sendtextmessage', {'targetmode': 3, 'target': bot.config['virtual-server'], 'msg': msg});
|
26 | return this;
|
27 | }
|
28 |
|
29 | bot_proto.prototype.sayChannel = function(msg, target) {
|
30 | bot.sendCommand('sendtextmessage', {'targetmode': 2, 'target': target, 'msg': msg});
|
31 | return this;
|
32 | }
|
33 |
|
34 |
|
35 |
|
36 |
|
37 | bot_proto.prototype.clientlist = function(callbackFunction) {
|
38 | bot.sendCommand('clientlist', null, function(err, data, raw) {
|
39 | var clients = raw.split('|');
|
40 | var returnClients = [];
|
41 | var args;
|
42 | for(var i=0; i<clients.length; i++) {
|
43 | args = clients[i].split(' ');
|
44 | var returnClient = {};
|
45 | for(var x=0; x<args.length; x++) {
|
46 | var argument = args[x].split(/=(.+)?/);
|
47 | returnClient[argument[0]] = bot.decode(argument[1]);
|
48 | }
|
49 | returnClients.push(returnClient);
|
50 | }
|
51 | if(typeof callbackFunction == 'function') callbackFunction(returnClients);
|
52 | });
|
53 | return this;
|
54 | }
|
55 |
|
56 | bot_proto.prototype.clientdblist = function(callbackFunction) {
|
57 | bot.sendCommand('clientdblist', null, function(err, data, raw) {
|
58 | var clients = raw.split('|');
|
59 | var returnClients = [];
|
60 | var args;
|
61 | for(var i=0; i<clients.length; i++) {
|
62 | args = clients[i].split(' ');
|
63 | var returnClient = {};
|
64 | for(var x=0; x<args.length; x++) {
|
65 | var argument = args[x].split(/=(.+)?/);
|
66 | returnClient[argument[0]] = bot.decode(argument[1]);
|
67 | }
|
68 | returnClients.push(returnClient);
|
69 | }
|
70 | if(typeof callbackFunction == 'function') callbackFunction(returnClients);
|
71 | });
|
72 | return this;
|
73 | }
|
74 |
|
75 | bot_proto.prototype.clientfind = function(client_nickname, callbackFunction) {
|
76 | bot.sendCommand('clientfind', {'pattern': client_nickname}, function(err, data) {
|
77 | if(typeof callbackFunction == 'function') callbackFunction(err, data);
|
78 | });
|
79 | return this;
|
80 | }
|
81 |
|
82 | bot_proto.prototype.clientdbfind = function (client_nickname, callbackFunction) {
|
83 | bot.sendCommand('clientdbfind', {'pattern': client_nickname}, function(err, data) {
|
84 | if(typeof callbackFunction == 'function') callbackFunction(err, data);
|
85 | });
|
86 | }
|
87 |
|
88 | bot_proto.prototype.clientinfo = function(clid, callbackFunction) {
|
89 | var client_found = false;
|
90 |
|
91 | if(typeof clid == 'string') {
|
92 | if(parsable(clid)) {
|
93 | clid = parseInt(clid);
|
94 | if(clid == undefined) clid = -1;
|
95 | client_found = true;
|
96 | } else {
|
97 | bot.clientfind(clid, function(err, data) {
|
98 | clid = data["clid"];
|
99 | client_found = true;
|
100 | });
|
101 | }
|
102 | } else if (Number.isInteger(clid)) client_found = true;
|
103 |
|
104 | var continueFunction = setInterval(function() {
|
105 | if(client_found) {
|
106 | clearInterval(continueFunction);
|
107 | bot.sendCommand('clientinfo', {'clid': clid}, function(err, clientinfo) {
|
108 | clientinfo["clid"] = clid;
|
109 | if(typeof callbackFunction == 'function') callbackFunction(err, clientinfo);
|
110 | });
|
111 | }
|
112 | }, 0);
|
113 | return this;
|
114 | }
|
115 |
|
116 | bot_proto.prototype.clientmove = function(clid, cid, callbackFunction) {
|
117 | var client_found = false;
|
118 |
|
119 | if(typeof clid == 'string') {
|
120 | if(parsable(clid)) {
|
121 | clid = parseInt(clid);
|
122 | if(clid == undefined) clid = -1;
|
123 | client_found = true;
|
124 | } else {
|
125 | bot.clientfind(clid, function(err, data) {
|
126 | clid = data["clid"];
|
127 | client_found = true;
|
128 | });
|
129 | }
|
130 | } else if (Number.isInteger(clid)) client_found = true;
|
131 |
|
132 | var continueFunction = setInterval(function() {
|
133 | if(client_found) {
|
134 | clearInterval(continueFunction);
|
135 | bot.sendCommand('clientmove', {'clid': clid, 'cid': cid}, function(err, data) {
|
136 | data["clid"] = clid;
|
137 | if(typeof callbackFunction == 'function') callbackFunction(err, data);
|
138 | });
|
139 | }
|
140 | }, 0);
|
141 | return this;
|
142 | }
|
143 |
|
144 | bot_proto.prototype.clientkick = function(clid, reasonid, reasonmsg, callbackFunction) {
|
145 | var client_found = false;
|
146 |
|
147 | if(typeof clid == 'string') {
|
148 | if(parsable(clid)) {
|
149 | clid = parseInt(clid);
|
150 | if(clid == undefined) clid = -1;
|
151 | client_found = true;
|
152 | } else {
|
153 | bot.clientfind(clid, function(err, data) {
|
154 | clid = data["clid"];
|
155 | client_found = true;
|
156 | });
|
157 | }
|
158 | } else if (Number.isInteger(clid)) client_found = true;
|
159 |
|
160 | var continueFunction = setInterval(function() {
|
161 | if(client_found) {
|
162 | clearInterval(continueFunction);
|
163 | bot.sendCommand('clientkick', {'clid': clid, 'reasonid': reasonid, 'reasonmsg': reasonmsg}, function(err, data) {
|
164 | data["clid"] = clid;
|
165 | if(typeof callbackFunction == 'function') callbackFunction(err, data);
|
166 | });
|
167 | }
|
168 | }, 0);
|
169 | return this;
|
170 | }
|
171 |
|
172 |
|
173 |
|
174 |
|
175 | bot_proto.prototype.channellist = function(callbackFunction) {
|
176 | bot.sendCommand('channellist', null, function(err, data, raw) {
|
177 | var channels = raw.split('|');
|
178 | var returnChannels = [];
|
179 | var args;
|
180 | for(var i=0; i<channels.length; i++) {
|
181 | args = channels[i].split(' ');
|
182 | var returnChannel = {};
|
183 | for(var x=0; x<args.length; x++) {
|
184 | var argument = args[x].split(/=(.+)?/);
|
185 | returnChannel[argument[0]] = bot.decode(argument[1]);
|
186 | }
|
187 | returnChannels.push(returnChannel);
|
188 | }
|
189 | if(typeof callbackFunction == 'function') callbackFunction(returnChannels);
|
190 | });
|
191 | return this;
|
192 | }
|
193 |
|
194 | bot_proto.prototype.channelcreate = function(channel_name, channel_params, callbackFunction) {
|
195 | if(channel_params == null) channel_params = {};
|
196 | channel_params['channel_name'] = channel_name;
|
197 | bot.sendCommand('channelcreate', channel_params, function(err, data) {
|
198 | if(typeof callbackFunction == 'function') callbackFunction(err, data);
|
199 | });
|
200 | return this;
|
201 | }
|
202 |
|
203 | bot_proto.prototype.channeldelete = function(cid, callbackFunction) {
|
204 | bot.sendCommand('channeldelete', {'cid': cid}, function(err, data) {
|
205 | if(typeof callbackFunction == 'function') callbackFunction(err, data);
|
206 | });
|
207 | return this;
|
208 | }
|
209 |
|
210 | bot_proto.prototype.channeledit = function(cid, channel_params, callbackFunction) {
|
211 | channel_params["cid"] = cid;
|
212 | bot.sendCommand('channeledit', channel_params, function(err, data) {
|
213 | if(typeof callbackFunction == 'function') callbackFunction(err, data);
|
214 | });
|
215 | return this;
|
216 | }
|
217 |
|
218 | bot_proto.prototype.channelfind = function(channel_name, callbackFunction) {
|
219 | bot.sendCommand('channelfind', {'pattern': channel_name}, function(err, data) {
|
220 | if(typeof callbackFunction == 'function') callbackFunction(err, data);
|
221 | });
|
222 | return this;
|
223 | }
|
224 |
|
225 | bot_proto.prototype.channelinfo = function(cid, callbackFunction) {
|
226 | var channel_found = false;
|
227 |
|
228 | if(typeof cid == 'string') {
|
229 | if(parsable(cid)) {
|
230 | cid = parseInt(cid);
|
231 | if(cid == undefined) cid = -1;
|
232 | channel_found = true;
|
233 | } else {
|
234 | bot.channelfind(cid, function(err, data) {
|
235 | cid = data["cid"];
|
236 | channel_found = true;
|
237 | });
|
238 | }
|
239 | } else if (Number.isInteger(cid)) channel_found = true;
|
240 |
|
241 | var continueFunction = setInterval(function() {
|
242 | if(channel_found) {
|
243 | clearInterval(continueFunction);
|
244 | bot.sendCommand('channelinfo', {'cid': cid}, function(err, channelinfo) {
|
245 | channelinfo["cid"] = cid;
|
246 | if(typeof callbackFunction == 'function') callbackFunction(err, channelinfo);
|
247 | });
|
248 | }
|
249 | }, 0);
|
250 | return this;
|
251 | }
|
252 |
|
253 |
|
254 |
|
255 |
|
256 | bot_proto.prototype.groupAddClient = function (sgid, targetdbid, callbackFunction) {
|
257 | bot.sendCommand('servergroupaddclient', {'sgid': sgid, 'cldbid': targetdbid}, function(err, data) {
|
258 | if(typeof callbackFunction == 'function') callbackFunction(err, data);
|
259 | });
|
260 | return this;
|
261 | }
|
262 |
|
263 | bot_proto.prototype.groupDelClient = function(sgid, targetdbid, callbackFunction) {
|
264 | bot.sendCommand('servergroupdelclient', {'sgid': sgid, 'cldbid': targetdbid}, function(err, data) {
|
265 | if(typeof callbackFunction == 'function') callbackFunction(err, data);
|
266 | });
|
267 | return this;
|
268 | }
|