Added @mention command to learn about the bot
This commit is contained in:
parent
72b715b188
commit
5b27abbba9
|
@ -10,7 +10,7 @@ await dbClient.execute("INSERT INTO all_keys(userid,apiKey) values(?,?)", [confi
|
||||||
console.log("Inesrtion done");
|
console.log("Inesrtion done");
|
||||||
|
|
||||||
console.log("Attempting to insert default commands into command_cnt");
|
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++) {
|
for (let i = 0; i < commands.length; i++) {
|
||||||
await dbClient.execute("INSERT INTO command_cnt(command) values(?)", [commands[i]]).catch(e => {
|
await dbClient.execute("INSERT INTO command_cnt(command) values(?)", [commands[i]]).catch(e => {
|
||||||
console.log(`Failed to insert into database`, e);
|
console.log(`Failed to insert into database`, e);
|
||||||
|
|
12
mod.ts
12
mod.ts
|
@ -100,9 +100,17 @@ startBot({
|
||||||
if (message.isBot) return;
|
if (message.isBot) return;
|
||||||
|
|
||||||
// Ignore all messages that are not commands
|
// 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
|
// Split into standard command + args format
|
||||||
const args = message.content.slice(config.prefix.length).trim().split(/[ \n]+/g);
|
const args = message.content.slice(config.prefix.length).trim().split(/[ \n]+/g);
|
||||||
|
|
|
@ -10,6 +10,7 @@ import { stats } from "./stats.ts";
|
||||||
import { api } from "./apiCmd.ts";
|
import { api } from "./apiCmd.ts";
|
||||||
import { emoji } from "./emoji.ts";
|
import { emoji } from "./emoji.ts";
|
||||||
import { roll } from "./roll.ts";
|
import { roll } from "./roll.ts";
|
||||||
|
import { handleMentions } from "./handleMentions.ts";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
ping,
|
ping,
|
||||||
|
@ -23,5 +24,6 @@ export default {
|
||||||
stats,
|
stats,
|
||||||
api,
|
api,
|
||||||
emoji,
|
emoji,
|
||||||
roll
|
roll,
|
||||||
|
handleMentions
|
||||||
};
|
};
|
||||||
|
|
|
@ -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)}`);
|
||||||
|
});
|
||||||
|
};
|
|
@ -159,6 +159,15 @@ export const constantCmds = {
|
||||||
title: "Compiling latest statistics . . ."
|
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: {
|
privacy: {
|
||||||
embeds: [{
|
embeds: [{
|
||||||
title: "Privacy Policy",
|
title: "Privacy Policy",
|
||||||
|
|
Loading…
Reference in New Issue