This repository has been archived by the owner on Jan 11, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
app.js
130 lines (102 loc) · 3.32 KB
/
app.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
const { Client } = require('eris');
const WebServer = require('./server');
const config = require('./config');
const db = require('./utils/db');
class Automa extends Client {
constructor (token, clientOptions) {
const options = {
...clientOptions,
getAllUsers: true,
restMode: true
};
super(token, options);
this.webServer = new WebServer(this);
db.configure(this);
}
async fetchUser (userId, fetch = true) {
if (!userId || !this.shards.get(0).ready) {
return null;
}
let user;
if (!this.users.has(userId) && fetch) {
const restUser = await this.getRESTUser(userId).catch(() => null);
if (restUser) {
user = this.users.add(restUser);
}
} else {
user = this.users.get(userId);
}
return user;
}
get listGuild () {
return this.guilds.get(config.management.listGuild);
}
/**
* Checks the cache for the given user ID, and returns the effective avatar URL, otherwise default.
* @param {String} userId The ID of the user to get the avatar for.
* @param {String?} discriminator The discriminator, if applicable.
* @param {Number} size The desired size of the avatar.
* @returns {String} The avatar URl for the user.
*/
getAvatarFor (userId, discriminator = null, size = 512) {
if (this.users.has(userId)) {
return this.users.get(userId).dynamicAvatarURL('png', size);
}
if (discriminator) {
return `https://cdn.discordapp.com/embed/avatars/${discriminator % 5}.png`;
}
return 'https://cdn.discordapp.com/embed/avatars/1.png';
}
start () {
this.connect();
this.once('ready', () => {
this.webServer.start();
});
}
}
const bot = new Automa(config.bot.token);
bot.on('messageCreate', async (msg) => {
if (msg.author.bot || !msg.content.startsWith(config.bot.prefix)) {
return;
}
const [command, ...args] = msg.content.slice(config.bot.prefix.length).split(' ');
if (command === 'ping') {
msg.channel.createMessage('ponk :ping_pong:');
}
if (command === 'queue') {
const bots = await db.table('bots').filter({ approved: false }).orderBy('added').limit(10);
msg.channel.createMessage({
embed: {
title: `First ${bots.length} bots in the queue`,
description: bots.map(b => `[${b.username}](https://discordapp.com/oauth2/authorize?client_id=${b.id}&scope=bot)`).join('\n') || 'None'
}
});
}
if (command === 'owner') {
if (msg.mentions.length === 0) {
return msg.channel.createMessage('You need to mention a bot.');
}
const botId = msg.mentions[0].id;
const botOwnerId = await db.table('bots').get(botId)('owner').default(false);
if (!botOwnerId) {
return msg.channel.createMessage('No bots found with that ID');
}
const user = bot.users.get(botOwnerId);
if (!user) {
return msg.channel.createMessage(`${botOwnerId} (User not cached/in server.)`);
}
msg.channel.createMessage(`${user.username}#${user.discriminator} (${user.id})`);
}
if (command === 'eval') {
if (msg.author.id !== '180093157554388993') {
return;
}
try {
const res = eval(args.join(' '));
msg.channel.createMessage(require('util').inspect(res, { depth: 0 }) || 'No result');
} catch (e) {
msg.channel.createMessage(e.message);
}
}
});
bot.start();