This repository has been archived by the owner on Jul 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
392 lines (326 loc) · 14.9 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
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
const {Client, WebhookClient , GatewayIntentBits, DiscordAPIError, Message, channelLink, EmbedBuilder, ActivityType, Collection} = require('discord.js');
const dotenv = require('dotenv')
const { DiscordTogether } = require('discord-together');
const wait = require('node:timers/promises').setTimeout;
const term = require( 'terminal-kit' ).terminal ;
console.log(`[WORKER] : Starting`);
dotenv.config();
console.log(`[CLIENT] : Creating instance`);
const client = new Client(
{
intents:[
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildVoiceStates
]
}
);
client.config = require("./config.json")
const { DisTube } = require('distube');
const { SoundCloudPlugin } = require("@distube/soundcloud");
const { SpotifyPlugin } = require('@distube/spotify')
const MusicAuthorprofile = client.config.defultauthorprofile
client.distube = new DisTube(client, {
leaveOnStop: false,
emitNewSongOnly: true,
emitAddSongWhenCreatingQueue: false,
emitAddListWhenCreatingQueue: false,
plugins: [
new SoundCloudPlugin(),
new SpotifyPlugin({
emitEventsAfterFetching: true
})
]
})
const cuteemoji = client.config.defultauthoremoji
const status = queue =>
`ระดับเสียง : \`${queue.volume}%\` | วนซ้ำเพลง : \`${
queue.repeatMode ? (queue.repeatMode === 2 ? 'คิวเพลงทั้งหมด' : 'เพลงนี้') : 'ปิด'
}\``
client.distube
.on('playSong', (queue, song) => {
client.distube.setVolume(queue, 35);
let Titlesong ;
if (song.source == "youtube") {
Titlesong = "title"
} else {
Titlesong = song.source
}
const PlayCMD = new EmbedBuilder()
.setTitle(`${cuteemoji} ${song.name}`)
//.setURL(`${song.url}`)
.setColor(14024959)
//.setAuthor({ name: `${song.name}` , iconURL: 'https://cdn.discordapp.com/attachments/988037995531759658/1082920882441289738/00028-3147869600.png'})
.setDescription(`กำลังเล่นเพลงในห้อง <#${queue.voiceChannel.id}> - โดย : ${song.user}\nผู้แต่ง : \`${song.uploader.name}\` ระยะเวลา : \`${song.formattedDuration}\` ระดับเสียง : \`${queue.volume}\``)
//.setImage(song.thumbnail)
//.setThumbnail(song.thumbnail)
.setFooter({ text: `ℹ แหล่งที่มา : ${Titlesong}` })
.setTimestamp()
queue.textChannel.send({ embeds : [PlayCMD] })
}
)
.on('addSong', (queue, song) => {
let Titlesong ;
if (song.source == "youtube") {
Titlesong = "title"
} else {
Titlesong = song.source
}
const AddsongCMD = new EmbedBuilder()
.setTitle(`${cuteemoji} ${song.name}`)
//.setURL(`${song.url}`)
.setColor(9240744)
//.setAuthor({ name: `${song.name}` , iconURL: 'https://cdn.discordapp.com/attachments/988037995531759658/1082920882441289738/00028-3147869600.png'})
.setDescription(`เพลงถูกเพิ่มไปยังคิวแล้ว - โดย : ${song.user}\nใช้คำสั่ง \`m.skip\` เพื่อข้ามเพลง`)
//.setThumbnail(song.thumbnail)
.setFooter({ text: `ℹ แหล่งที่มา : ${Titlesong}` })
.setTimestamp()
queue.textChannel.send({ embeds : [AddsongCMD] })
}
)
.on('addList', (queue, playlist) => {
const AddListCMD = new EmbedBuilder()
.setColor(14024959)
.setAuthor({ name: `${playlist.name}` , iconURL: `${MusicAuthorprofile}`})
.setDescription(`เพลย์ลิสถูกเพิ่มไปยังคิวแล้ว ทั้งหมด \`${playlist.songs.length}\` เพลง - โดย : ${song.user}\nใช้คำสั่ง \`/music skip\` เพื่อข้ามเพลง`)
.setTimestamp()
queue.textChannel.send({ embeds : [AddListCMD] })
}
)
.on('error', (channel, e) => {
if (channel) channel.send("```diff\n"+`- ${e.toString().slice(0, 1974)}`+" try again later !\n```")
else console.error(e)
})
.on('empty', queue => {
queue.textChannel.send(`ห้องนี้ไม่มีใครอยู่เลย หนูขอออกจากห้องนะคะ !`)
})
.on('searchNoResult', (message, query) => {
const NoseaCMD = new EmbedBuilder()
.setColor(16711680)
.setAuthor({ name: `${query}` , iconURL: `${MusicAuthorprofile}`})
.setDescription(`หนูไม่พบเพลงนี้ - ลองใส่ชื่อเพลง / ลิงค์ เพลงใหม่ดูสิ !`)
.setTimestamp()
message.channel.send({ embeds : [NoseaCMD] })
}
)
.on('finish', queue => queue.textChannel.send('เล่นเพลงเสร็จแล้วคะ !\nใช้คำสั่ง `m.stop` เพื่อนำบอทออกจากห้อง'))
/*
const webhookClient = new WebhookClient({ url: client.config.webhook });
console.log(`[CLIENT] : Debug mode is ON`);
client.on("debug", ( e ) => {
const Debugembed = new EmbedBuilder()
.setAuthor({ name: `Maoyumi Debug` , iconURL: 'https://cdn.discordapp.com/attachments/1061529756203499571/1083435558937837608/New_Project_13.png'})
.setDescription(`${e}`)
.setColor(657930);
webhookClient.send({
content: null,
embeds: [Debugembed]
});
//console.log(e)
});
*/
const prefix = client.config.prefix
client.discordTogether = new DiscordTogether(client);
console.log(`[CLIENT] : Finish create instance`);
console.log('[CLIENT] : Loading commands');
// Readcommandfile-nonslash
const fs = require("fs");
let CommandCount = 0;
let FolderCount = 0;
const Allcommand = [];
client.commands = new Collection();
client.slashcommands = new Collection();
const commandFolders = fs.readdirSync(`./Commands/`)
for (const folder of commandFolders) {
const commandFiles = fs.readdirSync(`./Commands/${folder}`).filter(file => file.endsWith('.js'));
FolderCount=FolderCount+1;
for (const file of commandFiles) {
const props = require(`./Commands/${folder}/${file}`);
//console.log(`[FS] : Loaded ${file}`)
CommandCount=CommandCount+1;
client.commands.set(props.config.name, props)
}
Allcommand.push(...commandFiles.map(file => file.replaceAll(".js","")));
}
// Readcommandfile-slash
let SlashCommandCount = 0;
let SlashCommandFolderCount = 0;
const SlashFunctions = fs.readdirSync("./Functions").filter(file => file.endsWith(".js"));
const SlasheventFiles = fs.readdirSync("./Events").filter(file => file.endsWith(".js"));
const SlashcommandFolders = fs.readdirSync("./SlashCommands");
(async () => {
for (file of SlashFunctions) {
require(`./Functions/${file}`)(client);
}
client.handleEvents(SlasheventFiles, "./Events");
client.handleCommands(SlashcommandFolders, "./SlashCommands");
})();
for (const folder of SlashcommandFolders) {
const SlashcommandFiles = fs.readdirSync(`./SlashCommands/${folder}`).filter(file => file.endsWith('.js'));
SlashCommandFolderCount=SlashCommandFolderCount+1;
for (const file of SlashcommandFiles) {
const props = require(`./SlashCommands/${folder}/${file}`);
//console.log(`[FS] : Loaded ${file}`)
SlashCommandCount=SlashCommandCount+1;
}
Allcommand.push(...SlashcommandFiles.map(file => file.replaceAll(".js","")));
}
client.allcommand = Allcommand
console.log(`[FS] : Successfully loaded ${FolderCount} folders`);
console.log(`[FS] : Successfully loaded ${CommandCount} commands`);
console.log(`[FS] : Successfully loaded ${SlashCommandFolderCount} [/] folders`);
console.log(`[FS] : Successfully loaded ${SlashCommandCount} [/] commands`);
console.log(`[CLIENT] : All commands => ${Allcommand} `);
// ---------------------------------------------------------------------
const cooldown = new Set();
function addToCooldown(ID) {
cooldown.add(ID);
setTimeout(() => {
cooldown.delete(ID);
}, 3000 /* 3 seconds */);
}
client.on("messageCreate", async message => {
if(message.author.bot) return;
if(message.channel.type === "dm") return;
let messageArray = message.content.split(" ");
let cmd = messageArray[0];
let args = messageArray.slice(1);
if(!cmd.startsWith(prefix)) return;
let commandfile = client.commands.get(cmd.slice(prefix.length));
const ListbanID = client.config.banID
const Authorprofile = client.config.defultauthorprofile
if (message.author.id == ListbanID) { //Blacklist People
const BlackPerms = new EmbedBuilder()
.setColor(16711680)
.setAuthor({ name: `คุณ ${message.author.username} ไม่มีสิทธ์ใช้งานคำสั่งของหนูนะคะ !\n(Banned by the owner)` , iconURL: `${Authorprofile}`})
.setTimestamp()
message.reply({ embeds: [BlackPerms] })
} else {
if (cooldown.has(message.author.id)) {
message.reply(`⏰ คุณ <@${message.author.id}> ใช้คำสั่งเร็วเกินไป !\nกรุณารอ \`3 วินาที\` เพื่อใช้คำสั่งอีกครั้ง`)
} else {
try {
commandfile.run(client,message,args)
addToCooldown(message.author.id);
} catch (error) {
message.reply("```diff\n- "+error+" try again later !\n```")
}
}
}
});
// ---------------------------------------------------------------------
const { OpenAIApi, Configuration } = require("openai")
const config = new Configuration({
apiKey: process.env.OPENAI_KEY
})
const openai = new OpenAIApi(config)
const PAST_MESSAGES = 3
// Chat Bot
client.on('messageCreate', async message => {
//if(message.channelId == "1060184115447599194" || message.channelId == "1061522412715376690" || message.channelId == "1061529756203499571") {
if(message.content.includes("มาวยูมิ") || message.content.includes('<@1060182470630330529>') || message.content.includes('Maoyumi') || message.content.includes('maoyumi') || message.content.includes("ม่าวยูมิ") || message.content.includes("ม่าว") || message.content.includes("มาว") || message.content.includes("Mao") || message.content.includes("mao")) {
if(message.author.bot) return;
let UserrealID = message.author.id
message.channel.sendTyping()
const ListbanID = client.config.banID
message.reply("<a:TYPING:1074264222864789565>").then(async message => {
if (UserrealID == ListbanID) { //Blacklist people
const rawBAns = [
"...","** ไม่มีการตอบกลับ... **",`บอทนี้ไม่สามารถใช้ได้ในชื่อ <@${message.author.id}> ไปใช้บอทตัวอื่นนะคะ :P`,"There's been a glitch | We're not quite sure what went wrong."
]
const BAns = Math.floor(Math.random() * rawBAns.length);
message.edit(`${cuteemoji} : `+rawBAns[BAns])
} else {
let messages = Array.from(await message.channel.messages.fetch({
limit: PAST_MESSAGES,
before: message.id
}))
messages = messages.map(m=>m[1])
messages.unshift(message)
let users = [...new Set([...messages.map(m=> m.author.username), client.user.username])]
let lastUser = users.pop()
let prompt = `The following is a conversation between ${users.join(", ")}, and ${lastUser}. \n\n`
for (let i = messages.length - 1; i >= 0; i--) {
const m = messages[i]
prompt += `${m.author.username}: ${m.content}\n`
}
//console.log("prompt:", prompt)
prompt += `${client.user.username}:`
try {
const response = await openai.createCompletion({
prompt,
model: "text-davinci-003",
max_tokens: 256,
stop: ["\n"]
})
const rawres = response.data.choices[0].text
let Ans = rawres.replaceAll("ฉัน", "หนู");
Ans = Ans.replaceAll("ผม", "หนู")
Ans = Ans.replaceAll("เรา", "หนู")
Ans = Ans.replaceAll("ครับ", "คะ")
message.edit(`${cuteemoji} : ${Ans}`)
} catch (error) {
message.edit("```diff\n- "+error+" try again later !\n```")
}
}
})
}
});
console.log("[CMD] : Loaded ChatBot")
// Web UI
/*
const express = require('express');
const app = express();
const path = require('path');
app.use(express.static(path.join(__dirname, '/Assets')))
app.get("/", (req, res) => {
res.sendFile(__dirname + "/Assets/index.html")
})
*/
// Web UI (Simple)
const app = require('express')();
app.get("/", (req, res) => {
res.send("Online!")
})
app.listen(5263)
console.log("----------")
console.log('[SERVICE] : Now online at port : 5263 | localhost:5263')
client.on('ready', async ()=>{
console.log(`[API] : Connected ${client.user.tag} successfully !`)
client.user.setPresence({ activities: [{ name: `/bot help | ${client.guilds.cache.size} Servers` , type: ActivityType.Streaming , url: "https://www.twitch.tv/maoyumi" }]});
console.log("[WORKER] : Finished")
await wait(3000)
await clearevery()
term.table( [
[ `${client.user.tag}` , 'Status : Online' ] ,
] , {
borderChars: 'lightRounded' ,
borderAttr: { color: 'magenta' } ,
width: 60 ,
fit: true
}
) ;
console.log("[Console] : Log now clear")
})
//Join servermessage
client.on('guildCreate', guild => {
const Authorprofile = client.config.defultauthorprofile
const Botname = client.config.botname
const ServerMessage = new EmbedBuilder()
.setColor(14024959)
.setTitle(`ขอบคุณที่เชิญหนูเข้า - Server นี้นะ`)
.setDescription(`สวัสดีทุกคนนะคะหนูชื่อ - ${Botname}\nเป็น ChatBot ที่สร้างจาก FujaTyping\n.....\nคำสั่งขอหนู ณ ตอนนี้\n- ใช้คำสั่ง \`/bot help\` เพื่อดูคำสั่งทั้งหมด`)
//.setImage("https://cdn.discordapp.com/attachments/1024635780360056883/1069976864178839632/ezgif-4-83f97196ce.png")
.setThumbnail(`${Authorprofile}`)
.setTimestamp()
.setFooter({ text: 'Welcome message from system !'});
guild.systemChannel.send({ embeds: [ServerMessage] })
});
console.log("[GUILD] : Loaded JoinServer")
function clearevery() {
console.clear()
}
console.log('[API] : Connecting to Discord network');
client.login(process.env.TOKEN)