-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
108 lines (100 loc) · 3.31 KB
/
main.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// Response for Uptime Robot
const http = require("http");
http
.createServer(function(request, response) {
response.writeHead(200, { "Content-Type": "text/plain" });
response.end("Discord bot is active now \n");
})
.listen(3000);
// Discord bot implements
const Discord = require("discord.js");
const Client = new Discord.Client();
exports.Clirnt = Client;
const dicBot = require('./dicBot.js');
const functions = require('./functions.js');
const log = functions.log
//::実行::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
//##bot#######################################################################################################################
const Bot = new (class {
//::グローバルパラメータ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
constructor() {
this.parameter = {
adminName: "yaakiyu",
userIDs: {
yaakiyu: "693025129806037003",
uni: "687599949093011495"
},
saverConfigID: "705035857102503997"
};
this.database = {
system: null,
user: null,
variable: null
};
this.functions = new (class {
getAdminID() {
return Bot.parameter.userIDs[Bot.parameter.adminName];
}
getDataID(type) {
return new Promise((resolve, reject) => {
functions.fetchMessages(Bot.parameter.saverConfigID, { limit: 1 }).then(
messages => {
resolve(JSON.parse(messages.first().content).databaseIDs[type]);
}
);
});
}
})();
}
readDatabase() {
let setDataFunctions = [];
for (let key of Object.keys(this.database)) {
let setData = resolve => {
this.functions.getDataID(key).then(({ channel, message }) => {
functions.fetchMessages(channel, message).then(messages => {
if (messages.content != void 0) {
this.database[key] = JSON.parse(messages.content);
} else {
this.database[key] = JSON.parse(messages.first().content);
}
resolve();
});
});
};
setDataFunctions.push(setData);
}
let setDataPromise = setDataFunctions.map(func => new Promise(func));
return Promise.all(setDataPromise);
}
Preparation() {
return this.readDatabase();
}
//::実行:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Run() {
Client.user.setActivity("ヘルプはdb:help");
dicBot.Preparation();
Client.on("message", message => {
if (!message.author.bot) {
dicBot.Run(message);
//notice(message);
}
});
//functions.send(`705032035747496037`, `{"test":0}`);
}
})();
//::起動:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Client.on("ready", message => {
Bot.Preparation().then(() => {
module.exports.database = Bot.database
console.log("準備完了");
log(0, "**Bot is ready!**");
//getLastMessage("703133624567988244");
console.dir(Bot.database);
Bot.Run();
});
});
if (process.env.DISCORD_BOT_TOKEN == undefined) {
console.log("please set ENV: DISCORD_BOT_TOKEN");
process.exit(0);
}
Client.login(process.env.DISCORD_BOT_TOKEN);