use interaction handler
This commit is contained in:
6 files changed
+37
-14
No files matched your search
+1
-1
@@ -63,8 +63,8 @@ module.exports = {
|
||||
socket.emit('botping', {message:'hello there'});
|
||||
socket.on('botpong', (data) => {
|
||||
if (debugConsole) client.log('Debug: Socket responded')
|
||||
return interaction.send({ content: `Debug: Socket responded` })
|
||||
socket.disconnect();
|
||||
return interaction.send({ content: `Debug: Socket responded` })
|
||||
});
|
||||
|
||||
} else if (command == "apicheck") {
|
||||
|
||||
@@ -104,10 +104,14 @@ module.exports = {
|
||||
)
|
||||
}
|
||||
|
||||
interaction.send({ embeds: [nameResult], components: [row] });
|
||||
|
||||
client.on("interactionCreate", ButtonInteraction => {
|
||||
const socket = io.connect(client.config.socket);
|
||||
return interaction.send({ embeds: [nameResult], components: [row] });
|
||||
});
|
||||
},
|
||||
},
|
||||
Interactions: {
|
||||
license: {
|
||||
run: async (client, ButtonInteraction, { GuildDB }) => {
|
||||
const socket = io.connect(client.config.socket);
|
||||
|
||||
let queryString = ButtonInteraction.customId;
|
||||
let query = {
|
||||
@@ -124,12 +128,11 @@ module.exports = {
|
||||
}
|
||||
socket.emit("update_drivers_license_status", query);
|
||||
socket.on("bot_updated_drivers_license_status", (res) => {
|
||||
if (!res.success) ButtonInteraction.update({ content: 'Failed to update license.', embeds: [], components: [] });
|
||||
socket.disconnect();
|
||||
if (!res.success) return ButtonInteraction.update({ content: 'Failed to update license.', embeds: [], components: [] });
|
||||
});
|
||||
return ButtonInteraction.update({ content: 'Successfully updated license.', embeds: [], components: [] });
|
||||
});
|
||||
});
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -66,9 +66,10 @@ module.exports = {
|
||||
const socket = io.connect(client.config.socket);
|
||||
socket.emit('bot_update_status', req);
|
||||
socket.on('bot_updated_status', (res) => {
|
||||
interaction.send({ content: `Succesfully updated <@${interaction.member.user.id}>'s status to \`${args[0].value}\`` });
|
||||
socket.disconnect();
|
||||
return interaction.send({ content: `Succesfully updated <@${interaction.member.user.id}>'s status to \`${args[0].value}\`` });
|
||||
});
|
||||
return;
|
||||
},
|
||||
},
|
||||
}
|
||||
+1
-1
@@ -2,7 +2,7 @@ require('dotenv').config()
|
||||
|
||||
module.exports = {
|
||||
Dev: "PRODUCTION",
|
||||
Version: "3.1.3",
|
||||
Version: "3.1.4",
|
||||
Admins: ["362791661274660874"], // Admins of the bot
|
||||
DefaultPrefix: "?",
|
||||
socket: "https://www.linespolice-cad.com/",
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
@@ -13,6 +13,7 @@ class LinesPoliceCadBot extends Client {
|
||||
|
||||
this.config = config;
|
||||
this.commands = new Collection();
|
||||
this.interactionHandlers = new Collection();
|
||||
this.logger = new Logger(path.join(__dirname, "..", "logs/Logs.log"));
|
||||
|
||||
if (this.config.Token === "")
|
||||
@@ -23,7 +24,7 @@ class LinesPoliceCadBot extends Client {
|
||||
this.db;
|
||||
this.dbo;
|
||||
this.connectMongo(this.config.mongoURI, this.config.dbo);
|
||||
this.LoadCommands();
|
||||
this.LoadCommandsAndInteractionHandlers();
|
||||
this.LoadEvents();
|
||||
|
||||
this.Ready = false;
|
||||
@@ -121,7 +122,7 @@ class LinesPoliceCadBot extends Client {
|
||||
|
||||
exists(n) {return null != n && undefined != n && "" != n}
|
||||
|
||||
LoadCommands() {
|
||||
LoadCommandsAndInteractionHandlers() {
|
||||
let CommandsDir = path.join(__dirname, '..', 'commands');
|
||||
fs.readdir(CommandsDir, (err, files) => {
|
||||
if (err) this.log(err);
|
||||
@@ -135,6 +136,11 @@ class LinesPoliceCadBot extends Client {
|
||||
", Reason: File doesn't had run/name/desciption"
|
||||
);
|
||||
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]);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user