-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.ts
79 lines (72 loc) · 2.53 KB
/
index.ts
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
76
77
78
79
import { Client, Message } from 'discord.js';
import { emoji } from 'node-emoji';
import * as path from 'path';
import { AccumulatorMessage } from './AccumulatorMessage';
import { AttachMessage } from './AttachMessage';
import { CounterMessage } from './CounterMessage';
import { EchoMessage } from './EchoMessage';
import { NumericEmojiMessage } from './NumericEmojiMessage';
import { MessageEmbedMessage } from './MessageEmbedMessage';
import { ToggleMessage } from './ToggleMessage';
// tslint:disable-next-line no-var-requires
const secrets = require(path.resolve(__dirname, '..', 'secrets.json'));
const client = new Client();
client.on('ready', async () => {
// tslint:disable-next-line:no-console
console.info(`Client ready`);
const attachMessage = new AttachMessage();
client.on('message', async (message) => {
if (! message.content.startsWith('$')) { return; }
const [command, ...args] = message.content.substr(1).split(' ');
if (command === 'help') {
message.reply(`
Available commands are:
- help
- count [startCount]
- echo <msg>
- acc
- num
- toggle
- attach
- retro
- rich
`);
} else if (command === 'count') {
new CounterMessage({
initialCounterValue: Number(args[0] || '0'),
}).sendTo(message.channel);
} else if (command === 'echo') {
new EchoMessage(args.join(' ')).replyTo(message);
} else if (command === 'acc') {
new AccumulatorMessage().sendTo(message.channel);
} else if (command === 'num') {
new NumericEmojiMessage().sendTo(message.channel);
} else if (command === 'toggle') {
new ToggleMessage().sendTo(message.channel);
} else if (command === 'attach') {
const dummyMsg = await message.channel.send('dummy message') as Message;
attachMessage.attachTo(dummyMsg);
} else if (command === 'retro') {
const dummyMsg = await message.channel.send('taken over in 3 seconds') as Message;
dummyMsg.react(emoji.thumbsup).then(() => {
setTimeout(() => {
new CounterMessage({
initialCounterValue: 0,
}).attachTo(dummyMsg);
}, 3000);
});
} else if (command === 'rich') {
new MessageEmbedMessage().sendTo(message.channel);
}
});
});
client.login(secrets.discord_token)
.then(() => {
// tslint:disable-next-line:no-console
console.info(`Login successful`);
})
.catch((err) => {
// tslint:disable-next-line:no-console
console.error(`Login failed`);
throw err;
});