-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdicBot.js
147 lines (144 loc) · 4.94 KB
/
dicBot.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
const Discord = require("discord.js");
const Client = require("./main.js").Clirnt;
const parameter = require("./dic-parameter.js");
const log = require("./functions.js").log;
const dicBot = new (class {
constructor() {
//**ローカル関数軍************************************************************************************
this.functions = new (class {
getMokuji() {
let mokuji = "";
for (let content of parameter.dictionary) {
mokuji += content.word + "\n";
}
parameter.dictionary.push({
word: "s-目次",
mean: `現在載っている言葉:\n ${mokuji}`
});
}
})();
}
//**準備**********************************************************************************************
Preparation() {
this.functions.getMokuji();
}
//**本体**********************************************************************************************
Run(message) {
const database = require("./main.js").database;
const system_database = database.system.DictionaryBot;
const prefixString = parameter.prefix;
//const prefixString = system_database.normalPrefix;
const prefix = new RegExp(prefixString, "i");
const content = message.content;
const channel = message.channel;
if (content.match(prefix)) {
let guild;
let nickname;
if (message.channel.type == "dm") {
guild = "DM";
nickname = null;
} else {
guild = message.guild.name;
nickname = message.member.nickname;
}
const author = message.author;
const elseMessage = parameter.elseMessage;
const dictionary = parameter.dictionary;
//channel.send(JSON.stringify(Bot.database, null, 4));
//editLast(Bot.functions.getDataID("variable"), `{"test":null}`);
let search = content.replace(prefix, "");
if (search == "about") {
channel.send(parameter.about());
log(
1,
`**Show about** Server:[${guild}] Channel:[${channel.toString()}] User:[${
author.username
} (${nickname})]`
);
return;
}
if (search.match(/^s-news /i)) {
const adminIDs = require("./main.js").parameter.userIDs;
if (Object.values(adminIDs).indexOf(message.author.id) + 1) {
const ch_name = "db-お知らせ";
let news = search.replace(/^s-news /i, "");
Client.channels.cache.forEach(newsChannel => {
if (newsChannel.name === ch_name) {
newsChannel.send(news);
let embed = new Discord.MessageEmbed()
.setColor(0x00ff00)
.setTitle("お知らせを配信しました。")
.setDescription(news)
.setTimestamp(new Date());
channel.send(embed);
}
});
} else {
let news = search.replace(/^s-news /i, "");
let embed = new Discord.MessageEmbed()
.setColor(0xff0000)
.setTitle("実行エラー")
.setDescription("このコマンドは開発者限定です。")
.setTimestamp(new Date());
channel.send(embed);
}
return;
}
if ((search = "s-help")) {
channel.send(parameter.help());
log(
1,
`**Show help** Server:[${guild}] Channel:[${channel.toString()}] User:[${
author.username
} (${nickname})]`
);
return;
}
//channel.send({content:"test",embed:{title:"test"}})
for (let item of dictionary) {
const embedColor = parameter.embedColor;
const embedFooter = parameter.embedFooter;
let reg = new RegExp(`^${item.word}`, "i");
if (search.match(reg)) {
if (item.mean == "" || item.writing) {
channel.send(
parameter.sendMessage(
search,
embedColor,
parameter.inProductionMessage,
embedFooter
)
);
return;
}
channel.send(
parameter.sendMessage(search, embedColor, item.mean, embedFooter)
);
log(
1,
`**Searched** Status:[hit] Word:[${search}] Server:[${guild}] Channel:[${channel.toString()}] User:[${
author.username
} (${nickname})]`
);
return;
}
}
if (!search == "") {
channel.send(parameter.elseMessage(search));
/* Client.users.cache
.get(Bot.functions.getAdminID())
.send(
`存在しない言葉「${search}」が検索されました。 by ${author.username}`
);*/
log(
1,
`**Searched** Status:[Couldn't hit] Word:[${search}] Server:[${guild}] Channel:[${channel.toString()}] User:[${
author.username
} (${nickname})]`
);
log(2, `${search}`);
}
}
}
})();
module.exports = dicBot;