add report command

This commit is contained in:
Ean Milligan (Bastion) 2023-01-11 22:23:27 -05:00
parent db492f312f
commit d8bd5694fb
8 changed files with 68 additions and 136 deletions

View File

@ -42,8 +42,8 @@ import { handleLFGStep, handleMemberJoin, handleMemberLeave, urlToIds } from './
import { constantCmds, editBtns, lfgStepQuestions } from './src/constantCmds.ts';
import { jsonParseBig, jsonStringifyBig } from './src/utils.ts';
import { DEBUG, LOCALMODE } from './flags.ts';
import config from './config.ts';
import { DEBUG, LOCALMODE } from '../flags.ts';
import config from '../config.ts';
// Initialize DB client
const dbClient = await new Client().connect({
@ -94,7 +94,7 @@ const ALPHABET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
// Start up the Discord Bot
startBot({
token: LOCALMODE ? config.localtoken : config.token,
token: LOCALMODE ? config.localToken : config.token,
intents: [Intents.GuildMessages, Intents.DirectMessages, Intents.Guilds],
eventHandlers: {
ready: () => {
@ -393,32 +393,7 @@ startBot({
// All commands below here
// ping
// Its a ping test, what else do you want.
if (command === 'ping') {
// Light telemetry to see how many times a command is being run
dbClient.execute(`CALL INC_CNT("ping");`).catch((e) => {
log(LT.ERROR, `Failed to call stored procedure INC_CNT: ${jsonStringifyBig(e)}`);
});
// Calculates ping between sending a message and editing it, giving a nice round-trip latency.
try {
const m = await message.send({
embeds: [{
title: 'Ping?',
}],
});
m.edit({
embeds: [{
title: `Pong! Latency is ${m.timestamp - message.timestamp}ms.`,
}],
});
} catch (e) {
log(LT.ERROR, `Failed to send message: ${jsonStringifyBig(message)} | ${jsonStringifyBig(e)}`);
}
} // lfg
// Handles all LFG commands, creating, editing, deleting
else if (command === 'lfg') {
if (command === 'lfg') {
// Light telemetry to see how many times a command is being run
dbClient.execute(`CALL INC_CNT("lfg");`).catch((e) => {
log(LT.ERROR, `Failed to call stored procedure INC_CNT: ${jsonStringifyBig(e)}`);
@ -998,53 +973,6 @@ startBot({
});
}
}
} // report or r (command that failed)
// Manually report something that screwed up
else if (command === 'report' || command === 'r') {
// Light telemetry to see how many times a command is being run
dbClient.execute(`CALL INC_CNT("report");`).catch((e) => {
log(LT.ERROR, `Failed to call stored procedure INC_CNT: ${jsonStringifyBig(e)}`);
});
sendMessage(config.reportChannel, 'USER REPORT:\n' + args.join(' ')).catch((e) => {
log(LT.ERROR, `Failed to send message: ${jsonStringifyBig(message)} | ${jsonStringifyBig(e)}`);
});
message.send(constantCmds.report).catch((e) => {
log(LT.ERROR, `Failed to send message: ${jsonStringifyBig(message)} | ${jsonStringifyBig(e)}`);
});
} // version or v
// Returns version of the bot
else if (command === 'version' || command === 'v') {
// Light telemetry to see how many times a command is being run
dbClient.execute(`CALL INC_CNT("version");`).catch((e) => {
log(LT.ERROR, `Failed to call stored procedure INC_CNT: ${jsonStringifyBig(e)}`);
});
message.send(constantCmds.version).catch((e) => {
log(LT.ERROR, `Failed to send message: ${jsonStringifyBig(message)} | ${jsonStringifyBig(e)}`);
});
} // info or i
// Info command, prints short desc on bot and some links
else if (command === 'info' || command === 'i') {
// Light telemetry to see how many times a command is being run
dbClient.execute(`CALL INC_CNT("info");`).catch((e) => {
log(LT.ERROR, `Failed to call stored procedure INC_CNT: ${jsonStringifyBig(e)}`);
});
message.send(constantCmds.info).catch((e) => {
log(LT.ERROR, `Failed to send message: ${jsonStringifyBig(message)} | ${jsonStringifyBig(e)}`);
});
} // help or h or ?
// Help command, prints available commands
else if (command === 'help' || command === 'h' || command === '?') {
// Light telemetry to see how many times a command is being run
dbClient.execute(`CALL INC_CNT("help");`).catch((e) => {
log(LT.ERROR, `Failed to call stored procedure INC_CNT: ${jsonStringifyBig(e)}`);
});
message.send(constantCmds.help).catch((e) => {
log(LT.ERROR, `Failed to send message: ${jsonStringifyBig(message)} | ${jsonStringifyBig(e)}`);
});
}
},
interactionCreate: async (interact, member) => {

View File

@ -1,37 +1,8 @@
import { ActionRow, DiscordButtonStyles } from '../deps.ts';
import config from '../config.ts';
import config from '../../config.ts';
export const constantCmds = {
help: {
embeds: [{
title: `${config.name} Help`,
fields: [
{
name: 'All commands must have the bot\'s prefix before them.',
value: `Default is \`${config.prefix}\`, send <@847256159123013722> to change it.`,
},
{
name: 'LFG Commands',
value: `
\`lfg help\` - More detailed help for the LFG commands
\`lfg create\` - Create a new LFG post
\`lfg edit\` - Edit an existing LFG post
\`lfg delete\` - Delete an existing LFG post
`,
},
{
name: 'Utility Commands',
value: `
\`info\` - Information about the bot
\`ping\` - Pings the bot to check its connection
\`report [TEXT]\` - Report an issue to the developer
\`version\` - Prints the bot's current version
`,
},
],
}],
},
lfgHelp: {
embeds: [{
title: `${config.name} LFG Help`,
@ -74,33 +45,6 @@ export const constantCmds = {
],
}],
},
info: {
embeds: [{
fields: [
{
name: 'Group Up, the LFG bot',
value: `Group Up is developed by Ean AKA Burn_E99.
Want to check out my source code? Check it out [here](https://github.com/Burn-E99/GroupUp).
Need help with this bot? Join my support server [here](https://discord.gg/peHASXMZYv).`,
},
],
}],
},
version: {
embeds: [{
title: `My current version is ${config.version}`,
}],
},
report: {
embeds: [{
fields: [
{
name: 'Failed command has been reported to my developer.',
value: 'For more in depth support, and information about planned maintenance, please join the support server [here](https://discord.gg/peHASXMZYv).',
},
],
}],
},
lfgDelete1: {
embeds: [{
fields: [

View File

@ -14,7 +14,7 @@ import {
import { jsonStringifyBig } from './utils.ts';
import { ActiveLFG, BuildingLFG } from './mod.d.ts';
import config from '../config.ts';
import config from '../../config.ts';
// getRandomStatus() returns status as string
// Gets a new random status for the bot

View File

@ -10,6 +10,7 @@ export type { BotWithCache } from 'https://deno.land/x/discordeno@17.0.1/plugins
export {
ActivityTypes,
ApplicationCommandFlags,
ApplicationCommandOptionTypes,
ApplicationCommandTypes,
createBot,
editBotMember,

View File

@ -20,3 +20,11 @@ export const getRandomStatus = (guildCount: number): string => {
export const isLFGChannel = (channelId: bigint) => {
return (lfgChannels.includes(channelId) || channelId === 0n) ? ApplicationCommandFlags.Ephemeral : undefined;
};
export const generateReport = (msg: string) => ({
embeds: [{
color: infoColor2,
title: 'USER REPORT:',
description: msg || 'No message',
}],
});

View File

@ -3,8 +3,9 @@ import { Commands } from '../types/commandTypes.ts';
import utils from '../utils.ts';
import info from './info.ts';
import report from './report.ts';
export const commands: Array<Commands> = [info];
export const commands: Array<Commands> = [info, report];
export const createSlashCommands = async (bot: Bot) => {
const globalCommands: MakeRequired<CreateApplicationCommand, 'name'>[] = [];

View File

@ -12,7 +12,7 @@ const details: CommandDetails = {
};
const execute = (bot: Bot, interaction: Interaction) => {
dbClient.execute(queries.callIncCnt('report')).catch((e) => utils.commonLoggers.dbError('info.ts', 'call sproc INC_CNT on', e));
dbClient.execute(queries.callIncCnt('info')).catch((e) => utils.commonLoggers.dbError('info.ts', 'call sproc INC_CNT on', e));
bot.helpers.sendInteractionResponse(
interaction.id,
interaction.token,

50
src/commands/report.ts Normal file
View File

@ -0,0 +1,50 @@
import config from '../../config.ts';
import { ApplicationCommandOptionTypes, ApplicationCommandTypes, Bot, Interaction, InteractionResponseTypes, sendMessage } from '../../deps.ts';
import { generateReport, isLFGChannel, successColor } from '../commandUtils.ts';
import { dbClient, queries } from '../db.ts';
import { CommandDetails } from '../types/commandTypes.ts';
import utils from '../utils.ts';
const details: CommandDetails = {
name: 'report',
description: `Information about ${config.name} and its developer`,
type: ApplicationCommandTypes.ChatInput,
options: [
{
name: 'issue',
type: ApplicationCommandOptionTypes.String,
description: 'Please describe the issue you were having.',
required: true,
minLength: 1,
maxLength: 2000,
},
],
};
const execute = (bot: Bot, interaction: Interaction) => {
console.log(interaction);
dbClient.execute(queries.callIncCnt('report')).catch((e) => utils.commonLoggers.dbError('report.ts', 'call sproc INC_CNT on', e));
sendMessage(bot, config.reportChannel, generateReport(interaction.data?.options?.[0].value as string || 'Missing Options')).catch((e: Error) =>
utils.commonLoggers.interactionSendError('report.ts:28', interaction, e)
);
bot.helpers.sendInteractionResponse(
interaction.id,
interaction.token,
{
type: InteractionResponseTypes.ChannelMessageWithSource,
data: {
flags: isLFGChannel(interaction.channelId || 0n),
embeds: [{
color: successColor,
title: 'Failed command has been reported to my developer.',
description: `For more in depth support, and information about planned maintenance, please join the support server [here](${config.links.supportServer}).`,
}],
},
},
).catch((e: Error) => utils.commonLoggers.interactionSendError('report.ts:44', interaction, e));
};
export default {
details,
execute,
};