This repository has been archived by the owner on Jan 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
119 lines (91 loc) · 3.45 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
const { Intents, Client } = require("discord.js");
// Intents: Guilds, VoiceStates, GuildMesssages
const intents = [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_VOICE_STATES, Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.GUILD_MESSAGE_REACTIONS, Intents.FLAGS.GUILD_PRESENCES];
// Create Client
const client = new Client({ intents });
let DIY_COMMANDO;
const { reactions, guildsMeta } = require("./general.js");
const config = require("./config.json");
// Login
console.log("runIndexer is set to " + config.runIndexerOnStart);
if (config.runIndexerOnStart == true) {
require("./music/indexer.js").index().then(() => {
client.login(config.token);
});
}
else {
client.login(config.token);
}
console.log("Prefix "+config.PREFIX)
// table of command names and their corresponding files/functions
client.once("ready", () => {
console.log("Ready in " + client.guilds.cache.size + " guild(s).");
client.user.setActivity("Prefix: "+config.PREFIX, { type: "WATCHING" });
DIY_COMMANDO = require("./diy_commando.js");
});
// check if prefix is PREFIX, and if so return the command back
function checkCommand(content) {
if (!(content[0] == config.PREFIX)) {
return false;
}
const splitContent = content.slice(1).split(" ");
const command = splitContent[0].toLowerCase();
splitContent.shift();
const args = splitContent.join(" ");
return { command, args };
}
client.on("messageCreate", (message) => {
// check if the message is a command and parse args
const { command, args } = checkCommand(message.content);
// Check the command against the command table, and then run it
// We pass the command arg to the command function for different functionalities, ex. if ">music" is used instead of ">play" we use soundcloud exclusively
processCommand(command, args, message);
});
client.on("interactionCreate", async interaction => {
if (!interaction.isCommand()) return;
// console.log(interaction.commandName);
// console.log(interaction.options.data);
const command = interaction.commandName;
const argsArray = [];
for (const option of interaction.options.data) {
argsArray.push(option.value);
}
// console.log(argsArray);
const args = argsArray.join(" ");
interaction.react = async (reaction) => {
return interaction.editReply({ content: reaction, fetchReply: true, ephemeral: true });
};
await interaction.deferReply({ ephemeral: true, fetchReply: true });
interaction.author = interaction.member.user;
// console.log(interaction.member.displayName)
// console.log(interaction.author)
// follow up for addtoqueue message
interaction.reply = (replyArgs) => {
replyArgs.ephemeral = false;
replyArgs.fetchReply = true;
return interaction.followUp(replyArgs);
};
interaction.delete = interaction.deleteReply;
processCommand(command, args, interaction);
});
function processCommand(command, args, message) {
if (DIY_COMMANDO[command]) {
try {
DIY_COMMANDO[command](message, args, command);
// terminate spotify following if any commands are ran
if ((command != "queue" && command != "spotify") && guildsMeta[message.guild.id] && guildsMeta[message.guild.id].spotify) {
guildsMeta[message.guild.id].spotify = false;
}
}
catch (error) {
message.react(reactions.warning);
message.reply("```index.js: " + error + "```");
console.log(error);
}
}
}
if (require("./voice/correctVoiceConfig")() == 0) {
client.on("voiceStateUpdate", (oldState, newState) => {
require("./voice/voiceProcessing").trackVCMembers(oldState, newState, client.id);
});
}