Skip to content

Commit 99834ec

Browse files
committed
Update Lyrics.js
1 parent 909eeb3 commit 99834ec

File tree

1 file changed

+96
-33
lines changed

1 file changed

+96
-33
lines changed

Lyrics.js

Lines changed: 96 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
registerPlugin({
22
name: 'Lyrics',
3-
version: '0.0.2',
3+
version: '0.0.3',
44
engine: '>= 0.9.17',
55
description: 'Search Lyrics from makeitpersonal.co',
66
author: 'NT5',
@@ -21,6 +21,25 @@ registerPlugin({
2121
title: 'Message format when no lyrics found',
2222
type: 'multiline',
2323
placeholder: 'Sorry, We don\'t have lyrics for "{song}" song yet'
24+
},
25+
{
26+
name: 'ly_command_blacklistusers',
27+
title: 'Banned users <comma saparated> ',
28+
type: 'string',
29+
placeholder: 'trollface, <id/username>...'
30+
},
31+
{
32+
name: 'ly_command_permissionsServerGroups',
33+
title: 'List of server groups that the bot should accept command and links (ID or Name)',
34+
type: 'array',
35+
vars: [
36+
{
37+
name: 'group',
38+
type: 'string',
39+
indent: 2,
40+
placeholder: 'Group name or id'
41+
}
42+
]
2443
}
2544
]
2645
}, function (sinusbot, config) {
@@ -75,9 +94,7 @@ registerPlugin({
7594
String.prototype.trunc = function (n, useWordBoundary) {
7695
if (this.length <= n) { return this; }
7796
var subString = this.substr(0, n - 1);
78-
return (useWordBoundary
79-
? subString.substr(0, subString.lastIndexOf(' '))
80-
: subString) + "...";
97+
return (useWordBoundary ? subString.substr(0, subString.lastIndexOf(' ')) : subString) + "...";
8198
};
8299

83100
var app = {
@@ -120,7 +137,7 @@ registerPlugin({
120137
plugin: {
121138
manifest: {
122139
running_time: Math.floor(Date.now() / 1000),
123-
version: '0.0.2',
140+
version: '0.0.3',
124141
authors: [
125142
{
126143
name: 'NT5',
@@ -136,6 +153,8 @@ registerPlugin({
136153
},
137154
command_trigger: config.ly_command_trigger || 'lyrics',
138155
autosearch: config.ly_autosearch,
156+
server_groups: config.ly_command_permissionsServerGroups || [],
157+
blacklistusers: (typeof config.ly_command_blacklistusers !== 'undefined' && config.ly_command_blacklistusers.length > 0 ? config.ly_command_blacklistusers.split(',') : []),
139158
messages: {
140159
error: config.ly_error_message || 'Sorry, We don\'t have lyrics for "{song}" song yet'
141160
}
@@ -219,51 +238,51 @@ registerPlugin({
219238
/*
220239
TODO
221240
- [BUG] Make sure if works in all cases
222-
- [BUG] Word truncate wrong
223241
*/
242+
243+
var parse_msg = function (options) {
244+
if (options.text.length >= maxlength) {
245+
var truncated = options.text.trunc(maxlength, true);
246+
var new_text = options.text.slice((truncated.length - 3), options.text.length);
247+
248+
options.chat(truncated);
249+
options.text = new_text;
250+
setTimeout(function () {
251+
parse_msg(options)
252+
}, timeoutdelay);
253+
} else {
254+
options.chat(options.text);
255+
}
256+
};
257+
224258
switch (options.mode) {
225259
case 1: // Private client message
226260
if (options.client) {
227-
if (options.text.length >= maxlength) {
228-
options.client.chat(options.text.trunc(maxlength));
229-
options.text = options.text.slice(maxlength, options.text.length);
230-
setTimeout(function () {
231-
app.msg(options)
232-
}, timeoutdelay);
233-
} else {
234-
options.client.chat(options.text);
235-
}
261+
parse_msg({
262+
text: options.text,
263+
chat: options.client.chat
264+
});
236265
} else {
237266
options.mode = 0;
238267
app.msg(options);
239268
}
240269
break;
241270
case 2: // Channel message
242271
if (options.channel) {
243-
if (options.text.length > maxlength) {
244-
options.channel.chat(options.text.trunc(maxlength));
245-
options.text = options.text.slice(maxlength, options.text.length);
246-
setTimeout(function () {
247-
app.msg(options)
248-
}, timeoutdelay);
249-
} else {
250-
options.channel.chat(options.text);
251-
}
272+
parse_msg({
273+
text: options.text,
274+
chat: options.channel.chat
275+
});
252276
} else {
253277
options.mode = 0;
254278
app.msg(options);
255279
}
256280
break;
257281
default: // Server message
258-
if (options.text.length > maxlength) {
259-
options.backend.chat(options.text.trunc(maxlength));
260-
options.text = options.text.slice(maxlength, options.text.length);
261-
setTimeout(function () {
262-
app.msg(options)
263-
}, timeoutdelay);
264-
} else {
265-
options.backend.chat(options.text);
266-
}
282+
parse_msg({
283+
text: options.text,
284+
chat: options.backend.chat
285+
});
267286
break;
268287
}
269288
},
@@ -403,6 +422,50 @@ registerPlugin({
403422

404423
if (client.isSelf()) return;
405424

425+
var permission = {
426+
config: {
427+
group: app.config.plugin.server_groups.map(function (arr) {
428+
return arr.group;
429+
}),
430+
banned: app.config.plugin.blacklistusers
431+
},
432+
group: {
433+
has_permission: function () {
434+
if (permission.config.group.length > 0) {
435+
var has_permission = false;
436+
client.getServerGroups().forEach(function (group) {
437+
if ((!has_permission) && ((permission.config.group.indexOf(group.name()) > -1) || (permission.config.group.indexOf(group.id()) > -1))) {
438+
has_permission = true;
439+
}
440+
});
441+
return has_permission;
442+
}
443+
return true;
444+
}
445+
},
446+
client: {
447+
is_banned: function () {
448+
if (permission.config.banned.length > 0) {
449+
if ((permission.config.banned.indexOf(client.name()) > -1) || (permission.config.banned.indexOf(client.uniqueID()) > -1))
450+
return true;
451+
}
452+
return false;
453+
}
454+
}
455+
};
456+
if (!permission.group.has_permission()) {
457+
engine.log('{client_name}, not have enough permission to execute script'.format({
458+
client_name: client.name()
459+
}));
460+
return;
461+
}
462+
if (permission.client.is_banned()) {
463+
engine.log('{client_name}, is banned from the bot and can\'t execute commands'.format({
464+
client_name: client.name()
465+
}));
466+
return;
467+
}
468+
406469
var cmd, par, text;
407470
// Regex text: !{command}[-{area}] {text}
408471
if ((text = app.config.plugin.regex.command.exec(ev.text)) !== null) {

0 commit comments

Comments
 (0)