-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.ts
68 lines (55 loc) · 1.81 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
import { DiscordClient } from './src/util/discord-client';
import { prefix } from './config.json';
import { setAllCommands } from './src/commands/all-commands';
import { config } from 'dotenv';
config(); // Import .env environment variables
const client = new DiscordClient({
messageCacheLifetime: 2,
messageCacheMaxSize: 2,
messageSweepInterval: 30
})
client.on('ready', () => {
client.user.setPresence({
activity: {
name: `${prefix}help`,
type: 'LISTENING'
}
})
})
setAllCommands(client);
client.on('ready', () => console.log('Logged in as ', client.user.username));
client.on('rateLimit', console.log);
client.onCommand('set_status', '', async (msg) => {
if (client.dblIntegration) {
const botInfo = await client.dbl.getBot(client.user.id);
let isOwner = false;
botInfo.owners.forEach(ownerId => {
// Need to do this because topgg API is broken. It says ownerId is a number but it is a string.
if (ownerId.toString() === msg.author.id.toString()) isOwner = true;
})
if (!isOwner) return;
}
const statusType = msg.content.toUpperCase().split(' ')[1].trim();
const statusMsg = msg.content.split(' ').slice(2).join(' ');
if ((statusType === 'LISTENING' || statusType === 'WATCHING') && statusMsg !== '') {
client.user.setPresence({
activity: {
name: statusMsg,
type: <'LISTENING' | 'WATCHING'>statusType
}
})
client.setTimeout(() => {
client.user.setPresence({
activity: {
name: `${prefix}help`,
type: 'LISTENING'
}
})
}, 3 * 24 * 60 * 60 * 1000) // 3 days
}
})
const tryLogin = () => {
console.log('Login failed. Trying again');
setTimeout(() => client.login(process.env.DISCORD_TOKEN).catch(tryLogin), 1000);
}
client.login(process.env.DISCORD_TOKEN).catch(tryLogin);