-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
75 lines (75 loc) · 3.3 KB
/
index.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
const Discord = require("discord.js");
const DiscordConfig = require("./config/discord.json")
const BotConfig = require("./config/bot.json")
const PteroConfig = require("./config/pterodactyl.json")
const fs = require('fs')
const bot = new Discord.Client({ disableMentions: 'everyone' });
const moment = require('moment-timezone');
console.clear()
const logo = fs.readFileSync('./resource/logo.txt', 'utf8')
console.log("\x1b[36m\x1b[1m" + logo.split("\n").join("\n\x1b[36m\x1b[1m") + "\x1b[0m")
if (BotConfig["force_support"] === true) {
if (process.version.replace("v", "").split(".")[0] < 14) {
console.warn("你的NodeJS版本过旧, 目前只支持v14或以上, 请更新你的NodeJS版本!")
process.exit()
}
}
moment.locale(BotConfig["language"]);
if (BotConfig.timezone["enabled"] === true) {
moment.tz(BotConfig["timezone"].tz)
}
if (BotConfig["CorrectPath"] === true) {
process.chdir(__dirname)
}
let includes = ["log", "info", "warn", "error"]
if (BotConfig["debug"] === true) {
includes.push('debug')
} else {
console.debug = function () { }
}
if (!fs.existsSync(`./resource/language/${BotConfig["language"]}.json`)) {
console.info(`无法检测到 ${BotConfig["language"]} 的语言文件, 请添加该语言的语言文件后再重新启动`)
console.info(`Could not find language ${BotConfig["language"]} 's language file, please make sure the language file exists then you start again`)
process.exit()
}
const LangPath = `./resource/language/${BotConfig["language"]}.json`
let language = require(LangPath)
bot.prefix = DiscordConfig.prefix
bot.commands = new Discord.Collection();
bot.aliases = new Discord.Collection();
bot.roles = new Discord.Collection();
bot.categories = fs.readdirSync("./commands/");
require('console-stamp')(console, {
format: `:mydate().blue :prefix().green :label()`,
include: includes,
tokens: {
mydate: () => {
return `[${moment().format(`${BotConfig["moment-format"]}`)}]`;
},
prefix: () => {
return `[${language["bot"].prefix}]`
}
}
});
console.info("\x1b[36m" + language["start"].notice)
console.info("\x1b[36m" + language["start"].notice2)
require(`./handlers/command`)(bot, language);
bot.on('ready', () => {
bot.user.setPresence({ activity: { name: DiscordConfig["activity"].first["activity"], type: DiscordConfig["activity"].first["type"] }, status: DiscordConfig["activity"].first["status"] })
setInterval(async () => {
let textList = DiscordConfig["activity"].activities
let x = Math.floor(Math.random() * textList.length)
bot.user.setPresence({ activity: { name: textList[x].activity, type: textList[x].type }, status: textList[x].status })
}, 30000)
require("./events/client/ready")(bot, language)
require("./events/client/console")(bot, language)
console.log(language["handle"].loading["done_1"])
})
bot.on('message', async message => {
require('./events/guild/message')(bot, message, DiscordConfig, PteroConfig, language)
})
bot.login(DiscordConfig["token"])
process.on('unhandledRejection', error => {
let pre = `\n============================================================\n--- DO NOT REPORT THIS TO HS FOREVER AS A BUG OR A CRASH ---\n============================================================\n`
console.error(pre, error, pre);
});