-
Notifications
You must be signed in to change notification settings - Fork 4
/
group_list.js
executable file
·75 lines (69 loc) · 2.77 KB
/
group_list.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/**
* Forum: https://forum.sinusbot.com/resources/group-list.388/
* GitHub: https://github.com/irgendwr/sinusbot-scripts
*/
registerPlugin({
name: 'Group List',
version: '1.1.0',
description: 'List the servers groups and their IDs with the `!groups` command.',
author: 'Jonas Bögle (irgendwr)',
backends: ['ts3', 'discord'],
vars: [{
name: 'admins',
title: 'UIDs of users which have access to the command',
type: 'strings',
default: []
}]
}, (_, config, meta) => {
const event = require('event')
const engine = require('engine')
const backend = require('backend')
const format = require('format')
engine.log(`Loaded ${meta.name} v${meta.version} by ${meta.author}.`)
event.on('load', () => {
const command = require('command')
if (!command) {
engine.log('command.js library not found! Please download command.js to your scripts folder and restart the SinusBot, otherwise this script will not work.');
engine.log('command.js can be found here: https://github.com/Multivit4min/Sinusbot-Command/blob/master/command.js');
return;
}
command.createCommand('groups')
.alias('grouplist')
.help('Lists the servers groups and their IDs')
.manual('Lists the servers groups and their IDs')
.checkPermission(allowAdminCommands)
.addArgument(command.createArgument('string').setName('name').optional())
.exec((/** @type {Client} */client, /** @type {object} */args, /** @type {(msg:string)=>void} */reply) => {
let resp = format.bold('Groups:')
if (args.name && args.name !== '') {
// TODO: split into multiple messages if too long
backend.getServerGroups().forEach(group => {
if (group.name().includes(args.name)) {
resp += '\n * `' + group.name() + '`, ID: `' + group.id() + '`'
}
})
} else {
// TODO: split into multiple messages if too long
backend.getServerGroups().forEach(group => {
resp += '\n * `' + group.name() + '`, ID: `' + group.id() + '`'
})
}
reply(resp)
})
})
/**
* Checks if a client is allowed to use admin commands.
* @param {Client} client
* @returns {boolean}
*/
function allowAdminCommands(client) {
switch (engine.getBackend()) {
case "discord":
return config.admins.includes(client.uid().split("/")[1])
case "ts3":
return config.admins.includes(client.uid())
default:
throw new Error(`Unknown backend ${engine.getBackend()}`)
}
}
})