-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
84 lines (70 loc) · 2.66 KB
/
Copy pathindex.js
File metadata and controls
84 lines (70 loc) · 2.66 KB
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
require('dotenv').config();
const { Client } = require('eris');
const fetch = require('node-fetch').default;
const prefix = 'afk!';
const baseUrl = 'https://afk.monkedev.com/api/users';
// const baseUrl = 'http://localhost:8080/api/users';
const bot = new Client(process.env.BotToken, {});
bot.connect();
bot.on('ready', () => {
console.log(`${bot.user.username} ready!`);
bot.editStatus('idle', {
type: 3,
name: `${prefix}help`
});
});
const helpMessage =
`
\`${prefix}lb\` - Point leaderboard
\`${prefix}info [user]\` - Some info on a user
\`${prefix}help\` - This
`
const coolDown = new Set();
bot.on('messageCreate', async (msg) => {
msg.channel.send = msg.channel.createMessage;
if(msg.content.startsWith(prefix + 'lb' || prefix + 'leaderboard')) {
if(msg.channel.id !== '779440159292522546') return msg.channel.createMessage('Try using the leaderboard command in <#779440159292522546> instead.');
const cooldown = coolDown.has(msg.author.id + '_lb');
if(cooldown) return;
else {
coolDown.add(msg.author.id + '_lb');
setTimeout(() => {
coolDown.delete(msg.author.id + '_lb')
}, 12 * 1000);
}
const res = await (await fetch( baseUrl, {headers: { auth: process.env.AccessToken, lb: true}} )).json();
let desc = '';
let count = 1;
res.forEach(user => {
desc += `${count}. ${user.username}#${user.disc} @ ${user.points}\n`;
count++;
});
return msg.channel.send({embed: {color: 0xf7c38e, description: desc.slice(0, 2000)}});
};
if(msg.content.startsWith(prefix + 'info')) {
const res = await (await fetch( baseUrl, {headers: { auth: process.env.AccessToken, lb: false}} )).json();
const user = msg.mentions[0] || msg.author;
const info = await res.find(x => x.id == user.id);
if(!info) return msg.channel.send(`:x: No data on ${user.username}#${user.discriminator}`);
return msg.channel.send({embed: {
color: 0xf7c38e,
author: {
name: user.username,
icon_url: user.avatarURL
},
fields: [
{
name: 'Points',
value: info.points
}
]
}});
};
if(msg.content.startsWith(prefix + 'help')) {
return msg.channel.send(helpMessage);
};
if(msg.content.startsWith(prefix + 'ping')) {
const message = await msg.channel.send('Pinging...');
message.edit(`API: \`${msg.channel.guild.shard.latency}\`\nMessage: \`${Date.now() - message.timestamp}\``);
};
});