This repository has been archived by the owner on Apr 29, 2024. It is now read-only.
forked from greys-bots/ticket-golem
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.js
87 lines (65 loc) · 2.81 KB
/
bot.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
const Discord = require("discord.js");
const fs = require("fs");
require('dotenv').config();
const bot = new Discord.Client({partials: ['MESSAGE', 'USER', 'CHANNEL', 'GUILD_MEMBER', 'REACTION']});
bot.chars = process.env.CHARS;
bot.prefix = process.env.PREFIX;
bot.owner = process.env.OWNER;
bot.invlink = process.env.INVITE;
bot.fetch = require('node-fetch');
bot.status = 0;
bot.statuses = [
() => `tg!h | in ${bot.guilds.cache.size} guilds.`,
() => `tg!h | serving ${bot.users.cache.size} users.`
];
bot.updateStatus = async function(){
var target = bot.statuses[bot.status % bot.statuses.length];
if(typeof target == "function") bot.user.setActivity(await target());
else bot.user.setActivity(target);
bot.status++;
setTimeout(()=> bot.updateStatus(), 5 * 60 * 1000)
}
async function setup() {
bot.db = await require(__dirname + '/stores/__db')(bot);
files = fs.readdirSync(__dirname + "/events");
files.forEach(f => bot.on(f.slice(0,-3), (...args) => require(__dirname + "/events/"+f)(...args,bot)));
bot.utils = require(__dirname + "/utils");
var data = bot.utils.loadCommands(__dirname + "/commands");
Object.keys(data).forEach(k => bot[k] = data[k]);
}
bot.writeLog = async (log) => {
if(!fs.existsSync('./logs')) fs.mkdirSync('./logs');
let now = new Date();
let ndt = `${(now.getMonth() + 1).toString().length < 2 ? "0"+ (now.getMonth() + 1) : now.getMonth()+1}.${now.getDate().toString().length < 2 ? "0"+ now.getDate() : now.getDate()}.${now.getFullYear()}`;
if(!fs.existsSync(`./logs/${ndt}.log`)){
fs.writeFile(`./logs/${ndt}.log`,log+"\r\n",(err)=>{
if(err) console.log(`Error while attempting to write log ${ndt}\n`+err.stack);
});
} else {
fs.appendFile(`./logs/${ndt}.log`,log+"\r\n",(err)=>{
if(err) console.log(`Error while attempting to apend to log ${ndt}\n`+err);
});
}
}
bot.parseCommand = async function(bot, msg, args) {
if(!args[0]) return undefined;
var command = bot.commands.get(bot.aliases.get(args[0].toLowerCase()));
if(!command) return {command, nargs: args};
args.shift();
if(args[0] && command.subcommands && command.subcommands.get(command.sub_aliases.get(args[0].toLowerCase()))) {
command = command.subcommands.get(command.sub_aliases.get(args[0].toLowerCase()));
args.shift();
}
return {command, nargs: args};
}
bot.formatTime = (date) => {
if(typeof date == "string") date = new Date(date);
return `${(date.getMonth()+1) < 10 ? "0"+(date.getMonth()+1) : (date.getMonth()+1)}.${(date.getDate()) < 10 ? "0"+(date.getDate()) : (date.getDate())}.${date.getFullYear()} at ${date.getHours() < 10 ? "0"+date.getHours() : date.getHours()}:${date.getMinutes() < 10 ? "0"+date.getMinutes() : date.getMinutes()}`
}
bot.on("ready",()=>{
console.log("Ready");
bot.updateStatus();
})
setup();
bot.login(process.env.TOKEN)
.catch(e => console.log("Trouble connecting:\n"+e));