-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
64 lines (55 loc) · 1.8 KB
/
index.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
const serverId = 'xxx';
const textChannelId = 'xxx';
const token = 'xxx';
const commandPrefix = '!';
import { Client } from 'guilded.js';
//
//
//
async function commandFlare(args) {
console.log(`commandFlare(args=${args})`);
let target = args[0];
await sendChannelText(textChannelId, `TODO: Find target=${target} users and send flare`);
const members = await guilded.members.fetchMany(serverId);
members.forEach(member => {
console.log('member.user.name', member.user.name);
})
}
//
//
//
async function sendChannelText(channelId, text) {
console.log(`sendChannelText(channelId=${channelId}, text="${text}")`);
await guilded.messages.send(textChannelId, text);
}
function connect() {
const guilded = new Client({ token });
guilded.on('ready', () => {
console.log(`ready: arguments`, arguments);
console.log('connected to Guilded!');
sendChannelText(textChannelId, 'FlareBot at your service!\nCommands:\n!flare ...');
});
guilded.on('exit', () => {
console.log(`exit: arguments`, arguments);
});
guilded.on('error', () => {
console.log(`error: arguments`, arguments);
});
guilded.on('messageCreated', async (message) => {
//console.log(`messageCreated: message`, message);
const {id: messageId, content, channelId} = message;
if (!content.startsWith(commandPrefix)) return;
if (channelId != textChannelId) return;
//console.log(`messageCreated: content`, content);
let [commandName, ...args] = content.slice(commandPrefix.length).trim().split(/ +/);
commandName = commandName.toLowerCase();
//console.log('messageCreated: commandName', commandName);
//console.log('messageCreated: args', args);
if (commandName == 'flare') {
await commandFlare(args);
}
});
guilded.login();
return guilded;
}
const guilded = connect();