use interaction handler

This commit is contained in:
SowinskiBraeden committed 2023-01-21 16:03:55 -08:00
1 parent 2a8252289c
commit 05930e8d33
6 files changed
+38 -15

No files matched your search

+1 -1
View File
@@ -63,8 +63,8 @@ module.exports = {
socket.emit('botping', {message:'hello there'}); socket.emit('botping', {message:'hello there'});
socket.on('botpong', (data) => { socket.on('botpong', (data) => {
if (debugConsole) client.log('Debug: Socket responded') if (debugConsole) client.log('Debug: Socket responded')
return interaction.send({ content: `Debug: Socket responded` })
socket.disconnect(); socket.disconnect();
return interaction.send({ content: `Debug: Socket responded` })
}); });
} else if (command == "apicheck") { } else if (command == "apicheck") {
+12 -9
View File
@@ -104,10 +104,14 @@ module.exports = {
) )
} }
interaction.send({ embeds: [nameResult], components: [row] }); return interaction.send({ embeds: [nameResult], components: [row] });
});
client.on("interactionCreate", ButtonInteraction => { },
const socket = io.connect(client.config.socket); },
Interactions: {
license: {
run: async (client, ButtonInteraction, { GuildDB }) => {
const socket = io.connect(client.config.socket);
let queryString = ButtonInteraction.customId; let queryString = ButtonInteraction.customId;
let query = { let query = {
@@ -124,12 +128,11 @@ module.exports = {
} }
socket.emit("update_drivers_license_status", query); socket.emit("update_drivers_license_status", query);
socket.on("bot_updated_drivers_license_status", (res) => { socket.on("bot_updated_drivers_license_status", (res) => {
if (!res.success) ButtonInteraction.update({ content: 'Failed to update license.', embeds: [], components: [] });
socket.disconnect(); socket.disconnect();
if (!res.success) return ButtonInteraction.update({ content: 'Failed to update license.', embeds: [], components: [] });
}); });
return ButtonInteraction.update({ content: 'Successfully updated license.', embeds: [], components: [] }); return ButtonInteraction.update({ content: 'Successfully updated license.', embeds: [], components: [] });
}); }
}); }
}, }
},
} }
+3 -2
View File
@@ -66,9 +66,10 @@ module.exports = {
const socket = io.connect(client.config.socket); const socket = io.connect(client.config.socket);
socket.emit('bot_update_status', req); socket.emit('bot_update_status', req);
socket.on('bot_updated_status', (res) => { socket.on('bot_updated_status', (res) => {
interaction.send({ content: `Succesfully updated <@${interaction.member.user.id}>'s status to \`${args[0].value}\`` });
socket.disconnect(); socket.disconnect();
}); return interaction.send({ content: `Succesfully updated <@${interaction.member.user.id}>'s status to \`${args[0].value}\`` });
});
return;
}, },
}, },
} }
+1 -1
View File
@@ -2,7 +2,7 @@ require('dotenv').config()
module.exports = { module.exports = {
Dev: "PRODUCTION", Dev: "PRODUCTION",
Version: "3.1.3", Version: "3.1.4",
Admins: ["362791661274660874"], // Admins of the bot Admins: ["362791661274660874"], // Admins of the bot
DefaultPrefix: "?", DefaultPrefix: "?",
socket: "https://www.linespolice-cad.com/", socket: "https://www.linespolice-cad.com/",
+13
View File
@@ -0,0 +1,13 @@
module.exports = async (client, interaction) => {
if (interaction.isCommand()) return;
/*
This file hanldes all button interactions from any command
*/
let GuildDB = await client.GetGuild(interaction.guildId);
const interactionName = interaction.customId.split('-')[0];
let interactionHandler = client.interactionHandlers.get(interactionName);
interactionHandler.run(client, interaction, GuildDB);
}
+8 -2
View File
@@ -13,6 +13,7 @@ class LinesPoliceCadBot extends Client {
this.config = config; this.config = config;
this.commands = new Collection(); this.commands = new Collection();
this.interactionHandlers = new Collection();
this.logger = new Logger(path.join(__dirname, "..", "logs/Logs.log")); this.logger = new Logger(path.join(__dirname, "..", "logs/Logs.log"));
if (this.config.Token === "") if (this.config.Token === "")
@@ -23,7 +24,7 @@ class LinesPoliceCadBot extends Client {
this.db; this.db;
this.dbo; this.dbo;
this.connectMongo(this.config.mongoURI, this.config.dbo); this.connectMongo(this.config.mongoURI, this.config.dbo);
this.LoadCommands(); this.LoadCommandsAndInteractionHandlers();
this.LoadEvents(); this.LoadEvents();
this.Ready = false; this.Ready = false;
@@ -121,7 +122,7 @@ class LinesPoliceCadBot extends Client {
exists(n) {return null != n && undefined != n && "" != n} exists(n) {return null != n && undefined != n && "" != n}
LoadCommands() { LoadCommandsAndInteractionHandlers() {
let CommandsDir = path.join(__dirname, '..', 'commands'); let CommandsDir = path.join(__dirname, '..', 'commands');
fs.readdir(CommandsDir, (err, files) => { fs.readdir(CommandsDir, (err, files) => {
if (err) this.log(err); if (err) this.log(err);
@@ -135,6 +136,11 @@ class LinesPoliceCadBot extends Client {
", Reason: File doesn't had run/name/desciption" ", Reason: File doesn't had run/name/desciption"
); );
this.commands.set(file.split(".")[0].toLowerCase(), cmd); this.commands.set(file.split(".")[0].toLowerCase(), cmd);
if (this.exists(cmd.Interactions)) {
for (let [interaction, handler] of Object.entries(cmd.Interactions)) {
this.interactionHandlers.set(interaction, handler);
}
}
this.log("Command Loaded: " + file.split(".")[0]); this.log("Command Loaded: " + file.split(".")[0]);
}); });
}); });