-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
86 lines (69 loc) · 2.71 KB
/
Copy pathindex.js
File metadata and controls
86 lines (69 loc) · 2.71 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
85
86
const { Client } = require('eris');
const config = require('./config.json');
const fs = require('fs');
const fetch = require('node-fetch').default;
const pm = require('pretty-ms');
class apiBot extends Client {
constructor(token, options) {
super(token, options);
this.baseLink = config.BASE_API_LINK;
this.config = config;
this.commands = new Map();
this.alli = new Map();
};
};
const bot = new apiBot(config.BOT_TOKEN, {});
bot.on('messageCreate', async msg => {
if(msg.author.bot || !msg.channel.guild || !msg.content.toLowerCase().startsWith(bot.config.PREFIX)) return;
let args = msg.content.slice(bot.config.PREFIX.length).split(' ');
const cmd = bot.commands.get(args[0].toLowerCase()) || bot.alli.get(args[0].toLowerCase());
if(!cmd) return;
if(!bot.config.ADMINS.includes(msg.author.id) && cmd.admin) return msg.channel.createMessage('You cant use this command bro.');
cmd.run(msg, args.slice(1));
});
let message;
bot.on('ready', async () => {
console.log(bot.user.username + ' is ready!');
bot.editStatus("idle", {
name: `${bot.config.PREFIX}help`,
type: 3
});
if(!message && !bot.config.messageID) {
message = await bot.createMessage(bot.config.channelID, 'Hello World');
bot.config.messageID = message.id;
fs.writeFileSync(__dirname + '/config.json', JSON.stringify(bot.config));
} else message = await bot.getMessage(bot.config.channelID, bot.config.messageID);
setInterval(async () => {
const before = Date.now();
let res = await fetch('https://api.monkedev.com/info?key=' + bot.config.API_KEY);
const ping = Date.now() - before;
res = await res.json();
message.edit({
content: '',
embed: {
title: 'API Stats',
description: `**Ping:** \`${pm(ping)}\`\
\n**Alltime req (3/20/2021 ~ Now):** \`${res.req.allTime.toLocaleString()}\`\
\n**Req (This process)**: \`${res.req.thisProcess.toLocaleString()}\`\
\n**Avg req/m**: \`${(res.req.thisProcess / ((res.uptime / 1000) / 60)).toFixed(2).toLocaleUpperCase()}\``,
color: 0xf7c38e,
footer: {
text: 'Last Updated'
},
timestamp: new Date
}
});
}, 60 * 1000);
});
const Init = async () => {
const dirs = fs.readdirSync(__dirname + '/commands');
dirs.forEach(dir => {
const file = new (require(__dirname + '/commands/' + dir))(bot);
bot.commands.set(file.name, file);
file.alli.forEach(alli => {
bot.alli.set(alli, file);
});
});
bot.connect();
};
Init();