This repository has been archived by the owner on Apr 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmybot.js
67 lines (54 loc) · 1.89 KB
/
mybot.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
const Discord = require ("discord.js");
const client = new Discord.Client();
const config = require("./config.json");
const fs = require("fs");
var http = require("http");
var util = require("util");
var mongodb = require('mongodb');
require("dotenv").config();
var dbkey = process.env.DB_KEY
client.commands = new Discord.Collection();
fs.readdir("./cmd/" , (err, files) => {
if (err) throw err;
let cmdfile = files.filter (f => f.split(".").pop() === "js");
if (cmdfile.length <= 0) {
console.log("No command found uwu");
return;
}
console.log(`Loading ${cmdfile.length} command(s), please wait...`);
cmdfile.forEach((f, i) => {
let props = require(`./cmd/${f}`);
console.log(`${i+1} : ${f} loaded`);
if(f != 'ojsamadroid.js')client.commands.set(props.help.name, props);
});
});
let uri = 'mongodb+srv://' + dbkey + '@elainadb-r6qx3.mongodb.net/test?retryWrites=true';
let maindb = '';
mongodb.MongoClient.connect(uri, {useNewUrlParser: true}, function(err, db) {
if (err) throw err;
maindb = db.db('ElainaDB');
console.log("db connection established");
})
client.on("ready", () => {
console.log("Elaina is up and running");
setInterval(trackfunc, 600000);
function trackfunc () {
let cmd = client.commands.get("trackfunc");
cmd.run(client, message = "", args = {}, maindb);
}
});
client.on("message", (message) => {
let msgArray = message.content.split(/\s+/g);
let command = msgArray[0];
let args = msgArray.slice(1);
if (message.content.includes("m.mugzone.net/chart/")) {
let cmd = client.commands.get("malodychart")
cmd.run(client, message, args);
}
if (!message.content.startsWith(config.prefix)|| message.author.bot) return;
let cmd = client.commands.get(command.slice(config.prefix.length));
if (cmd) {
cmd.run(client, message, args, maindb);
}
});
client.login(process.env.BOT_TOKEN);