Added @mention command to learn about the bot

This commit is contained in:
Ean Milligan (Bastion) 2022-05-13 18:57:45 -04:00
parent 72b715b188
commit 5b27abbba9
5 changed files with 45 additions and 4 deletions

View File

@ -10,7 +10,7 @@ await dbClient.execute("INSERT INTO all_keys(userid,apiKey) values(?,?)", [confi
console.log("Inesrtion done");
console.log("Attempting to insert default commands into command_cnt");
const commands = ["ping", "rip", "rollhelp", "help", "info", "version", "report", "stats", "roll", "emojis", "api", "privacy"];
const commands = ["ping", "rip", "rollhelp", "help", "info", "version", "report", "stats", "roll", "emojis", "api", "privacy", "mention"];
for (let i = 0; i < commands.length; i++) {
await dbClient.execute("INSERT INTO command_cnt(command) values(?)", [commands[i]]).catch(e => {
console.log(`Failed to insert into database`, e);

12
mod.ts
View File

@ -100,9 +100,17 @@ startBot({
if (message.isBot) return;
// Ignore all messages that are not commands
if (message.content.indexOf(config.prefix) !== 0) return;
if (message.content.indexOf(config.prefix) !== 0) {
// Handle @bot messages
if (message.mentionedUserIds[0] === botId && (message.content.trim().startsWith(`<@${botId}>`) || message.content.trim().startsWith(`<@!${botId}>`))) {
commands.handleMentions(message);
}
// return as we are done handling this command
return;
}
log(LT.LOG, `Handling message ${JSON.stringify(message)}`);
log(LT.LOG, `Handling [[command message: ${JSON.stringify(message)}`);
// Split into standard command + args format
const args = message.content.slice(config.prefix.length).trim().split(/[ \n]+/g);

View File

@ -10,6 +10,7 @@ import { stats } from "./stats.ts";
import { api } from "./apiCmd.ts";
import { emoji } from "./emoji.ts";
import { roll } from "./roll.ts";
import { handleMentions } from "./handleMentions.ts";
export default {
ping,
@ -23,5 +24,6 @@ export default {
stats,
api,
emoji,
roll
roll,
handleMentions
};

View File

@ -0,0 +1,22 @@
import { dbClient } from "../db.ts";
import {
// Discordeno deps
DiscordenoMessage,
// Log4Deno deps
LT, log
} from "../../deps.ts";
import { constantCmds } from "../constantCmds.ts";
export const handleMentions = (message: DiscordenoMessage) => {
log(LT.LOG, `Handling @mention message: ${JSON.stringify(message)}`);
// Light telemetry to see how many times a command is being run
dbClient.execute(`CALL INC_CNT("mention");`).catch(e => {
log(LT.ERROR, `Failed to call stored procedure INC_CNT: ${JSON.stringify(e)}`);
});
message.send(constantCmds.mention).catch(e => {
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
});
};

View File

@ -159,6 +159,15 @@ export const constantCmds = {
title: "Compiling latest statistics . . ."
}]
},
mention: {
embeds: [{
title: `Hello! I am ${config.name}!`,
fields: [{
name: "I am a bot that specializes in rolling dice and doing basic algebra",
value: `To learn about my available commands, please run \`${config.prefix}help\``
}]
}]
},
privacy: {
embeds: [{
title: "Privacy Policy",