mirror of
https://github.com/Burn-E99/TheArtificer.git
synced 2026-06-04 09:03:50 -04:00
added deno.json, ran deno fmt to standardize formatting
This commit is contained in:
@@ -1,16 +1,16 @@
|
||||
import { ping } from "./ping.ts";
|
||||
import { rip } from "./rip.ts";
|
||||
import { rollHelp } from "./rollHelp.ts";
|
||||
import { help } from "./help.ts";
|
||||
import { info } from "./info.ts";
|
||||
import { privacy } from "./privacy.ts";
|
||||
import { version } from "./version.ts";
|
||||
import { report } from "./report.ts";
|
||||
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";
|
||||
import { ping } from './ping.ts';
|
||||
import { rip } from './rip.ts';
|
||||
import { rollHelp } from './rollHelp.ts';
|
||||
import { help } from './help.ts';
|
||||
import { info } from './info.ts';
|
||||
import { privacy } from './privacy.ts';
|
||||
import { version } from './version.ts';
|
||||
import { report } from './report.ts';
|
||||
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,
|
||||
@@ -25,5 +25,5 @@ export default {
|
||||
api,
|
||||
emoji,
|
||||
roll,
|
||||
handleMentions
|
||||
handleMentions,
|
||||
};
|
||||
|
||||
@@ -1,65 +1,57 @@
|
||||
import { dbClient } from "../db.ts";
|
||||
import { dbClient } from '../db.ts';
|
||||
import {
|
||||
// Discordeno deps
|
||||
DiscordenoMessage, hasGuildPermissions,
|
||||
|
||||
DiscordenoMessage,
|
||||
hasGuildPermissions,
|
||||
log,
|
||||
// Log4Deno deps
|
||||
LT, log
|
||||
} from "../../deps.ts";
|
||||
import apiCommands from "./apiCmd/_index.ts";
|
||||
import { constantCmds } from "../constantCmds.ts";
|
||||
LT,
|
||||
} from '../../deps.ts';
|
||||
import apiCommands from './apiCmd/_index.ts';
|
||||
import { constantCmds } from '../constantCmds.ts';
|
||||
|
||||
export const api = async (message: DiscordenoMessage, args: string[]) => {
|
||||
// Light telemetry to see how many times a command is being run
|
||||
dbClient.execute(`CALL INC_CNT("api");`).catch(e => {
|
||||
dbClient.execute(`CALL INC_CNT("api");`).catch((e) => {
|
||||
log(LT.ERROR, `Failed to call stored procedure INC_CNT: ${JSON.stringify(e)}`);
|
||||
});
|
||||
|
||||
// Local apiArg in lowercase
|
||||
const apiArg = (args[0] || "help").toLowerCase();
|
||||
const apiArg = (args[0] || 'help').toLowerCase();
|
||||
|
||||
// Alert users who DM the bot that this command is for guilds only
|
||||
if (message.guildId === 0n) {
|
||||
message.send(constantCmds.apiGuildOnly).catch(e => {
|
||||
message.send(constantCmds.apiGuildOnly).catch((e) => {
|
||||
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// Makes sure the user is authenticated to run the API command
|
||||
if (await hasGuildPermissions(message.authorId, message.guildId, ["ADMINISTRATOR"])) {
|
||||
if (await hasGuildPermissions(message.authorId, message.guildId, ['ADMINISTRATOR'])) {
|
||||
// [[api help
|
||||
// Shows API help details
|
||||
if (apiArg === "help") {
|
||||
if (apiArg === 'help') {
|
||||
apiCommands.help(message);
|
||||
}
|
||||
|
||||
// [[api allow/block
|
||||
} // [[api allow/block
|
||||
// Lets a guild admin allow or ban API rolls from happening in said guild
|
||||
else if (apiArg === "allow" || apiArg === "block" || apiArg === "enable" || apiArg === "disable") {
|
||||
else if (apiArg === 'allow' || apiArg === 'block' || apiArg === 'enable' || apiArg === 'disable') {
|
||||
apiCommands.allowBlock(message, apiArg);
|
||||
}
|
||||
|
||||
// [[api delete
|
||||
} // [[api delete
|
||||
// Lets a guild admin delete their server from the database
|
||||
else if (apiArg === "delete") {
|
||||
else if (apiArg === 'delete') {
|
||||
apiCommands.deleteGuild(message);
|
||||
}
|
||||
|
||||
// [[api status
|
||||
} // [[api status
|
||||
// Lets a guild admin check the status of API rolling in said guild
|
||||
else if (apiArg === "status") {
|
||||
else if (apiArg === 'status') {
|
||||
apiCommands.status(message);
|
||||
}
|
||||
|
||||
// [[api show-warn/hide-warn
|
||||
} // [[api show-warn/hide-warn
|
||||
// Lets a guild admin decide if the API warning should be shown on messages from the API
|
||||
else if (apiArg === "show-warn" || apiArg === "hide-warn") {
|
||||
else if (apiArg === 'show-warn' || apiArg === 'hide-warn') {
|
||||
apiCommands.showHideWarn(message, apiArg);
|
||||
}
|
||||
|
||||
} else {
|
||||
message.send(constantCmds.apiPermError).catch(e => {
|
||||
message.send(constantCmds.apiPermError).catch((e) => {
|
||||
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import { help } from "./apiHelp.ts";
|
||||
import { allowBlock } from "./allowBlock.ts";
|
||||
import { deleteGuild } from "./deleteGuild.ts";
|
||||
import { status } from "./status.ts";
|
||||
import { showHideWarn } from "./showHideWarn.ts";
|
||||
import { help } from './apiHelp.ts';
|
||||
import { allowBlock } from './allowBlock.ts';
|
||||
import { deleteGuild } from './deleteGuild.ts';
|
||||
import { status } from './status.ts';
|
||||
import { showHideWarn } from './showHideWarn.ts';
|
||||
|
||||
export default {
|
||||
help,
|
||||
allowBlock,
|
||||
deleteGuild,
|
||||
status,
|
||||
showHideWarn
|
||||
showHideWarn,
|
||||
};
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
import { dbClient } from "../../db.ts";
|
||||
import { dbClient } from '../../db.ts';
|
||||
import {
|
||||
// Discordeno deps
|
||||
DiscordenoMessage,
|
||||
|
||||
log,
|
||||
// Log4Deno deps
|
||||
LT, log
|
||||
} from "../../../deps.ts";
|
||||
import { generateApiFailed, generateApiSuccess } from "../../constantCmds.ts";
|
||||
LT,
|
||||
} from '../../../deps.ts';
|
||||
import { generateApiFailed, generateApiSuccess } from '../../constantCmds.ts';
|
||||
|
||||
export const allowBlock = async (message: DiscordenoMessage, apiArg: string) => {
|
||||
const guildQuery = await dbClient.query(`SELECT guildid, channelid FROM allowed_guilds WHERE guildid = ? AND channelid = ?`, [message.guildId, message.channelId]).catch(e0 => {
|
||||
const guildQuery = await dbClient.query(`SELECT guildid, channelid FROM allowed_guilds WHERE guildid = ? AND channelid = ?`, [message.guildId, message.channelId]).catch((e0) => {
|
||||
log(LT.ERROR, `Failed to query DB: ${JSON.stringify(e0)}`);
|
||||
message.send(generateApiFailed(apiArg)).catch(e1 => {
|
||||
message.send(generateApiFailed(apiArg)).catch((e1) => {
|
||||
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e1)}`);
|
||||
});
|
||||
return;
|
||||
@@ -19,26 +19,30 @@ export const allowBlock = async (message: DiscordenoMessage, apiArg: string) =>
|
||||
|
||||
if (guildQuery.length === 0) {
|
||||
// Since guild is not in our DB, add it in
|
||||
await dbClient.execute(`INSERT INTO allowed_guilds(guildid,channelid,active) values(?,?,?)`, [message.guildId, message.channelId, ((apiArg === "allow" || apiArg === "enable") ? 1 : 0)]).catch(e0 => {
|
||||
log(LT.ERROR, `Failed to insert into DB: ${JSON.stringify(e0)}`);
|
||||
message.send(generateApiFailed(apiArg)).catch(e1 => {
|
||||
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e1)}`);
|
||||
});
|
||||
return;
|
||||
});
|
||||
await dbClient.execute(`INSERT INTO allowed_guilds(guildid,channelid,active) values(?,?,?)`, [message.guildId, message.channelId, (apiArg === 'allow' || apiArg === 'enable') ? 1 : 0]).catch(
|
||||
(e0) => {
|
||||
log(LT.ERROR, `Failed to insert into DB: ${JSON.stringify(e0)}`);
|
||||
message.send(generateApiFailed(apiArg)).catch((e1) => {
|
||||
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e1)}`);
|
||||
});
|
||||
return;
|
||||
},
|
||||
);
|
||||
} else {
|
||||
// Since guild is in our DB, update it
|
||||
await dbClient.execute(`UPDATE allowed_guilds SET active = ? WHERE guildid = ? AND channelid = ?`, [((apiArg === "allow" || apiArg === "enable") ? 1 : 0), message.guildId, message.channelId]).catch(e0 => {
|
||||
log(LT.ERROR, `Failed to update DB: ${JSON.stringify(e0)}`);
|
||||
message.send(generateApiFailed(apiArg)).catch(e1 => {
|
||||
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e1)}`);
|
||||
});
|
||||
return;
|
||||
});
|
||||
await dbClient.execute(`UPDATE allowed_guilds SET active = ? WHERE guildid = ? AND channelid = ?`, [(apiArg === 'allow' || apiArg === 'enable') ? 1 : 0, message.guildId, message.channelId]).catch(
|
||||
(e0) => {
|
||||
log(LT.ERROR, `Failed to update DB: ${JSON.stringify(e0)}`);
|
||||
message.send(generateApiFailed(apiArg)).catch((e1) => {
|
||||
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e1)}`);
|
||||
});
|
||||
return;
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
// We won't get here if there's any errors, so we know it has bee successful, so report as such
|
||||
message.send(generateApiSuccess(`${apiArg}ed`)).catch(e => {
|
||||
message.send(generateApiSuccess(`${apiArg}ed`)).catch((e) => {
|
||||
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import {
|
||||
// Discordeno deps
|
||||
DiscordenoMessage,
|
||||
|
||||
log,
|
||||
// Log4Deno deps
|
||||
LT, log
|
||||
} from "../../../deps.ts";
|
||||
import { constantCmds } from "../../constantCmds.ts";
|
||||
LT,
|
||||
} from '../../../deps.ts';
|
||||
import { constantCmds } from '../../constantCmds.ts';
|
||||
|
||||
export const help = (message: DiscordenoMessage) => {
|
||||
message.send(constantCmds.apiHelp).catch(e => {
|
||||
message.send(constantCmds.apiHelp).catch((e) => {
|
||||
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -1,24 +1,24 @@
|
||||
import { dbClient } from "../../db.ts";
|
||||
import { dbClient } from '../../db.ts';
|
||||
import {
|
||||
// Discordeno deps
|
||||
DiscordenoMessage,
|
||||
|
||||
log,
|
||||
// Log4Deno deps
|
||||
LT, log
|
||||
} from "../../../deps.ts";
|
||||
import { constantCmds } from "../../constantCmds.ts";
|
||||
LT,
|
||||
} from '../../../deps.ts';
|
||||
import { constantCmds } from '../../constantCmds.ts';
|
||||
|
||||
export const deleteGuild = async (message: DiscordenoMessage) => {
|
||||
await dbClient.execute(`DELETE FROM allowed_guilds WHERE guildid = ? AND channelid = ?`, [message.guildId, message.channelId]).catch(e0 => {
|
||||
await dbClient.execute(`DELETE FROM allowed_guilds WHERE guildid = ? AND channelid = ?`, [message.guildId, message.channelId]).catch((e0) => {
|
||||
log(LT.ERROR, `Failed to query DB: ${JSON.stringify(e0)}`);
|
||||
message.send(constantCmds.apiDeleteFail).catch(e1 => {
|
||||
message.send(constantCmds.apiDeleteFail).catch((e1) => {
|
||||
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e1)}`);
|
||||
});
|
||||
return;
|
||||
});
|
||||
|
||||
// We won't get here if there's any errors, so we know it has bee successful, so report as such
|
||||
message.send(constantCmds.apiRemoveGuild).catch(e => {
|
||||
message.send(constantCmds.apiRemoveGuild).catch((e) => {
|
||||
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
import { dbClient } from "../../db.ts";
|
||||
import { dbClient } from '../../db.ts';
|
||||
import {
|
||||
// Discordeno deps
|
||||
DiscordenoMessage,
|
||||
|
||||
log,
|
||||
// Log4Deno deps
|
||||
LT, log
|
||||
} from "../../../deps.ts";
|
||||
import { generateApiFailed, generateApiSuccess } from "../../constantCmds.ts";
|
||||
LT,
|
||||
} from '../../../deps.ts';
|
||||
import { generateApiFailed, generateApiSuccess } from '../../constantCmds.ts';
|
||||
|
||||
export const showHideWarn = async (message: DiscordenoMessage, apiArg: string) => {
|
||||
const guildQuery = await dbClient.query(`SELECT guildid, channelid FROM allowed_guilds WHERE guildid = ? AND channelid = ?`, [message.guildId, message.channelId]).catch(e0 => {
|
||||
const guildQuery = await dbClient.query(`SELECT guildid, channelid FROM allowed_guilds WHERE guildid = ? AND channelid = ?`, [message.guildId, message.channelId]).catch((e0) => {
|
||||
log(LT.ERROR, `Failed to query DB: ${JSON.stringify(e0)}`);
|
||||
message.send(generateApiFailed(`${apiArg} on`)).catch(e1 => {
|
||||
message.send(generateApiFailed(`${apiArg} on`)).catch((e1) => {
|
||||
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e1)}`);
|
||||
});
|
||||
return;
|
||||
@@ -19,18 +19,18 @@ export const showHideWarn = async (message: DiscordenoMessage, apiArg: string) =
|
||||
|
||||
if (guildQuery.length === 0) {
|
||||
// Since guild is not in our DB, add it in
|
||||
await dbClient.execute(`INSERT INTO allowed_guilds(guildid,channelid,hidewarn) values(?,?,?)`, [message.guildId, message.channelId, ((apiArg === "hide-warn") ? 1 : 0)]).catch(e0 => {
|
||||
await dbClient.execute(`INSERT INTO allowed_guilds(guildid,channelid,hidewarn) values(?,?,?)`, [message.guildId, message.channelId, (apiArg === 'hide-warn') ? 1 : 0]).catch((e0) => {
|
||||
log(LT.ERROR, `Failed to insert into DB: ${JSON.stringify(e0)}`);
|
||||
message.send(generateApiFailed(`${apiArg} on`)).catch(e1 => {
|
||||
message.send(generateApiFailed(`${apiArg} on`)).catch((e1) => {
|
||||
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e1)}`);
|
||||
});
|
||||
return;
|
||||
});
|
||||
} else {
|
||||
// Since guild is in our DB, update it
|
||||
await dbClient.execute(`UPDATE allowed_guilds SET hidewarn = ? WHERE guildid = ? AND channelid = ?`, [((apiArg === "hide-warn") ? 1 : 0), message.guildId, message.channelId]).catch(e0 => {
|
||||
await dbClient.execute(`UPDATE allowed_guilds SET hidewarn = ? WHERE guildid = ? AND channelid = ?`, [(apiArg === 'hide-warn') ? 1 : 0, message.guildId, message.channelId]).catch((e0) => {
|
||||
log(LT.ERROR, `Failed to update DB: ${JSON.stringify(e0)}`);
|
||||
message.send(generateApiFailed(`${apiArg} on`)).catch(e1 => {
|
||||
message.send(generateApiFailed(`${apiArg} on`)).catch((e1) => {
|
||||
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e1)}`);
|
||||
});
|
||||
return;
|
||||
@@ -38,7 +38,7 @@ export const showHideWarn = async (message: DiscordenoMessage, apiArg: string) =
|
||||
}
|
||||
|
||||
// We won't get here if there's any errors, so we know it has bee successful, so report as such
|
||||
message.send(generateApiSuccess(apiArg)).catch(e => {
|
||||
message.send(generateApiSuccess(apiArg)).catch((e) => {
|
||||
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
import { dbClient } from "../../db.ts";
|
||||
import { dbClient } from '../../db.ts';
|
||||
import {
|
||||
// Discordeno deps
|
||||
DiscordenoMessage,
|
||||
|
||||
log,
|
||||
// Log4Deno deps
|
||||
LT, log
|
||||
} from "../../../deps.ts";
|
||||
import { constantCmds, generateApiStatus } from "../../constantCmds.ts";
|
||||
LT,
|
||||
} from '../../../deps.ts';
|
||||
import { constantCmds, generateApiStatus } from '../../constantCmds.ts';
|
||||
|
||||
export const status = async (message: DiscordenoMessage) => {
|
||||
// Get status of guild from the db
|
||||
const guildQuery = await dbClient.query(`SELECT active, banned FROM allowed_guilds WHERE guildid = ? AND channelid = ?`, [message.guildId, message.channelId]).catch(e0 => {
|
||||
const guildQuery = await dbClient.query(`SELECT active, banned FROM allowed_guilds WHERE guildid = ? AND channelid = ?`, [message.guildId, message.channelId]).catch((e0) => {
|
||||
log(LT.ERROR, `Failed to query DB: ${JSON.stringify(e0)}`);
|
||||
message.send(constantCmds.apiStatusFail).catch(e1 => {
|
||||
message.send(constantCmds.apiStatusFail).catch((e1) => {
|
||||
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e1)}`);
|
||||
});
|
||||
return;
|
||||
@@ -22,17 +22,17 @@ export const status = async (message: DiscordenoMessage) => {
|
||||
if (guildQuery.length > 0) {
|
||||
// Check if guild is banned from using API and return appropriate message
|
||||
if (guildQuery[0].banned) {
|
||||
message.send(generateApiStatus(true, false)).catch(e => {
|
||||
message.send(generateApiStatus(true, false)).catch((e) => {
|
||||
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
|
||||
});
|
||||
} else {
|
||||
message.send(generateApiStatus(false, guildQuery[0].active)).catch(e => {
|
||||
message.send(generateApiStatus(false, guildQuery[0].active)).catch((e) => {
|
||||
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
|
||||
});
|
||||
}
|
||||
} else {
|
||||
// Guild is not in DB, therefore they are blocked
|
||||
message.send(generateApiStatus(false, false)).catch(e => {
|
||||
message.send(generateApiStatus(false, false)).catch((e) => {
|
||||
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,40 +1,40 @@
|
||||
import config from "../../config.ts";
|
||||
import { dbClient } from "../db.ts";
|
||||
import config from '../../config.ts';
|
||||
import { dbClient } from '../db.ts';
|
||||
import {
|
||||
// Discordeno deps
|
||||
DiscordenoMessage,
|
||||
|
||||
log,
|
||||
// Log4Deno deps
|
||||
LT, log
|
||||
} from "../../deps.ts";
|
||||
import { EmojiConf } from "../mod.d.ts";
|
||||
LT,
|
||||
} from '../../deps.ts';
|
||||
import { EmojiConf } from '../mod.d.ts';
|
||||
|
||||
const allEmojiAliases: string[] = [];
|
||||
|
||||
config.emojis.forEach((emoji: EmojiConf) => {
|
||||
allEmojiAliases.push(...emoji.aliases)
|
||||
allEmojiAliases.push(...emoji.aliases);
|
||||
});
|
||||
|
||||
export const emoji = (message: DiscordenoMessage, command: string) => {
|
||||
// shortcut
|
||||
// shortcut
|
||||
if (allEmojiAliases.indexOf(command)) {
|
||||
// Start looping thru the possible emojis
|
||||
config.emojis.some((emoji: EmojiConf) => {
|
||||
log(LT.LOG, `Checking if command was emoji ${JSON.stringify(emoji)}`);
|
||||
// If a match gets found
|
||||
if (emoji.aliases.indexOf(command || "") > -1) {
|
||||
if (emoji.aliases.indexOf(command || '') > -1) {
|
||||
// Light telemetry to see how many times a command is being run
|
||||
dbClient.execute(`CALL INC_CNT("emojis");`).catch(e => {
|
||||
dbClient.execute(`CALL INC_CNT("emojis");`).catch((e) => {
|
||||
log(LT.ERROR, `Failed to call stored procedure INC_CNT: ${JSON.stringify(e)}`);
|
||||
});
|
||||
|
||||
// Send the needed emoji1
|
||||
message.send(`<${emoji.animated ? "a" : ""}:${emoji.name}:${emoji.id}>`).catch(e => {
|
||||
message.send(`<${emoji.animated ? 'a' : ''}:${emoji.name}:${emoji.id}>`).catch((e) => {
|
||||
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
|
||||
});
|
||||
// And attempt to delete if needed
|
||||
if (emoji.deleteSender) {
|
||||
message.delete().catch(e => {
|
||||
message.delete().catch((e) => {
|
||||
log(LT.WARN, `Failed to delete message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,22 +1,22 @@
|
||||
import { dbClient } from "../db.ts";
|
||||
import { dbClient } from '../db.ts';
|
||||
import {
|
||||
// Discordeno deps
|
||||
DiscordenoMessage,
|
||||
|
||||
log,
|
||||
// Log4Deno deps
|
||||
LT, log
|
||||
} from "../../deps.ts";
|
||||
import { constantCmds } from "../constantCmds.ts";
|
||||
LT,
|
||||
} 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 => {
|
||||
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 => {
|
||||
message.send(constantCmds.mention).catch((e) => {
|
||||
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
import { dbClient } from "../db.ts";
|
||||
import { dbClient } from '../db.ts';
|
||||
import {
|
||||
// Discordeno deps
|
||||
DiscordenoMessage,
|
||||
|
||||
log,
|
||||
// Log4Deno deps
|
||||
LT, log
|
||||
} from "../../deps.ts";
|
||||
import { constantCmds } from "../constantCmds.ts";
|
||||
LT,
|
||||
} from '../../deps.ts';
|
||||
import { constantCmds } from '../constantCmds.ts';
|
||||
|
||||
export const help = (message: DiscordenoMessage) => {
|
||||
// Light telemetry to see how many times a command is being run
|
||||
dbClient.execute(`CALL INC_CNT("help");`).catch(e => {
|
||||
dbClient.execute(`CALL INC_CNT("help");`).catch((e) => {
|
||||
log(LT.ERROR, `Failed to call stored procedure INC_CNT: ${JSON.stringify(e)}`);
|
||||
});
|
||||
|
||||
message.send(constantCmds.help).catch(e => {
|
||||
message.send(constantCmds.help).catch((e) => {
|
||||
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
import { dbClient } from "../db.ts";
|
||||
import { dbClient } from '../db.ts';
|
||||
import {
|
||||
// Discordeno deps
|
||||
DiscordenoMessage,
|
||||
|
||||
log,
|
||||
// Log4Deno deps
|
||||
LT, log
|
||||
} from "../../deps.ts";
|
||||
import { constantCmds } from "../constantCmds.ts";
|
||||
LT,
|
||||
} from '../../deps.ts';
|
||||
import { constantCmds } from '../constantCmds.ts';
|
||||
|
||||
export const info = (message: DiscordenoMessage) => {
|
||||
// Light telemetry to see how many times a command is being run
|
||||
dbClient.execute(`CALL INC_CNT("info");`).catch(e => {
|
||||
dbClient.execute(`CALL INC_CNT("info");`).catch((e) => {
|
||||
log(LT.ERROR, `Failed to call stored procedure INC_CNT: ${JSON.stringify(e)}`);
|
||||
});
|
||||
|
||||
message.send(constantCmds.info).catch(e => {
|
||||
message.send(constantCmds.info).catch((e) => {
|
||||
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
import { dbClient } from "../db.ts";
|
||||
import { dbClient } from '../db.ts';
|
||||
import {
|
||||
// Discordeno deps
|
||||
DiscordenoMessage,
|
||||
|
||||
log,
|
||||
// Log4Deno deps
|
||||
LT, log
|
||||
} from "../../deps.ts";
|
||||
import { generatePing } from "../constantCmds.ts";
|
||||
LT,
|
||||
} from '../../deps.ts';
|
||||
import { generatePing } from '../constantCmds.ts';
|
||||
|
||||
export const ping = async (message: DiscordenoMessage) => {
|
||||
// Light telemetry to see how many times a command is being run
|
||||
dbClient.execute(`CALL INC_CNT("ping");`).catch(e => {
|
||||
dbClient.execute(`CALL INC_CNT("ping");`).catch((e) => {
|
||||
log(LT.ERROR, `Failed to call stored procedure INC_CNT: ${JSON.stringify(e)}`);
|
||||
});
|
||||
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
import { dbClient } from "../db.ts";
|
||||
import { dbClient } from '../db.ts';
|
||||
import {
|
||||
// Discordeno deps
|
||||
DiscordenoMessage,
|
||||
|
||||
log,
|
||||
// Log4Deno deps
|
||||
LT, log
|
||||
} from "../../deps.ts";
|
||||
import { constantCmds } from "../constantCmds.ts";
|
||||
LT,
|
||||
} from '../../deps.ts';
|
||||
import { constantCmds } from '../constantCmds.ts';
|
||||
|
||||
export const privacy = (message: DiscordenoMessage) => {
|
||||
// Light telemetry to see how many times a command is being run
|
||||
dbClient.execute(`CALL INC_CNT("privacy");`).catch(e => {
|
||||
dbClient.execute(`CALL INC_CNT("privacy");`).catch((e) => {
|
||||
log(LT.ERROR, `Failed to call stored procedure INC_CNT: ${JSON.stringify(e)}`);
|
||||
});
|
||||
|
||||
message.send(constantCmds.privacy).catch(e => {
|
||||
message.send(constantCmds.privacy).catch((e) => {
|
||||
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -1,29 +1,30 @@
|
||||
import config from "../../config.ts";
|
||||
import { dbClient } from "../db.ts";
|
||||
import config from '../../config.ts';
|
||||
import { dbClient } from '../db.ts';
|
||||
import {
|
||||
// Discordeno deps
|
||||
DiscordenoMessage, sendMessage,
|
||||
|
||||
DiscordenoMessage,
|
||||
log,
|
||||
// Log4Deno deps
|
||||
LT, log
|
||||
} from "../../deps.ts";
|
||||
import { constantCmds, generateReport } from "../constantCmds.ts";
|
||||
LT,
|
||||
sendMessage,
|
||||
} from '../../deps.ts';
|
||||
import { constantCmds, generateReport } from '../constantCmds.ts';
|
||||
|
||||
export const report = (message: DiscordenoMessage, args: string[]) => {
|
||||
// Light telemetry to see how many times a command is being run
|
||||
dbClient.execute(`CALL INC_CNT("report");`).catch(e => {
|
||||
dbClient.execute(`CALL INC_CNT("report");`).catch((e) => {
|
||||
log(LT.ERROR, `Failed to call stored procedure INC_CNT: ${JSON.stringify(e)}`);
|
||||
});
|
||||
|
||||
if (args.join(" ")) {
|
||||
sendMessage(config.reportChannel, generateReport(args.join(" "))).catch(e => {
|
||||
if (args.join(' ')) {
|
||||
sendMessage(config.reportChannel, generateReport(args.join(' '))).catch((e) => {
|
||||
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
|
||||
});
|
||||
message.send(constantCmds.report).catch(e => {
|
||||
message.send(constantCmds.report).catch((e) => {
|
||||
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
|
||||
});
|
||||
} else {
|
||||
message.send(constantCmds.reportFail).catch(e => {
|
||||
message.send(constantCmds.reportFail).catch((e) => {
|
||||
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
import { dbClient } from "../db.ts";
|
||||
import { dbClient } from '../db.ts';
|
||||
import {
|
||||
// Discordeno deps
|
||||
DiscordenoMessage,
|
||||
|
||||
log,
|
||||
// Log4Deno deps
|
||||
LT, log
|
||||
} from "../../deps.ts";
|
||||
import { constantCmds } from "../constantCmds.ts";
|
||||
LT,
|
||||
} from '../../deps.ts';
|
||||
import { constantCmds } from '../constantCmds.ts';
|
||||
|
||||
export const rip = (message: DiscordenoMessage) => {
|
||||
// Light telemetry to see how many times a command is being run
|
||||
dbClient.execute(`CALL INC_CNT("rip");`).catch(e => {
|
||||
dbClient.execute(`CALL INC_CNT("rip");`).catch((e) => {
|
||||
log(LT.ERROR, `Failed to call stored procedure INC_CNT: ${JSON.stringify(e)}`);
|
||||
});
|
||||
|
||||
message.send(constantCmds.rip).catch(e => {
|
||||
message.send(constantCmds.rip).catch((e) => {
|
||||
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -1,26 +1,27 @@
|
||||
import config from "../../config.ts";
|
||||
import { DEVMODE } from "../../flags.ts";
|
||||
import { dbClient, queries } from "../db.ts";
|
||||
import config from '../../config.ts';
|
||||
import { DEVMODE } from '../../flags.ts';
|
||||
import { dbClient, queries } from '../db.ts';
|
||||
import {
|
||||
// Discordeno deps
|
||||
DiscordenoMessage, sendDirectMessage,
|
||||
|
||||
DiscordenoMessage,
|
||||
log,
|
||||
// Log4Deno deps
|
||||
LT, log
|
||||
} from "../../deps.ts";
|
||||
import solver from "../solver/_index.ts";
|
||||
import { constantCmds, generateDMFailed } from "../constantCmds.ts";
|
||||
import rollFuncs from "./roll/_index.ts";
|
||||
LT,
|
||||
sendDirectMessage,
|
||||
} from '../../deps.ts';
|
||||
import solver from '../solver/_index.ts';
|
||||
import { constantCmds, generateDMFailed } from '../constantCmds.ts';
|
||||
import rollFuncs from './roll/_index.ts';
|
||||
|
||||
export const roll = async (message: DiscordenoMessage, args: string[], command: string) => {
|
||||
// Light telemetry to see how many times a command is being run
|
||||
dbClient.execute(`CALL INC_CNT("roll");`).catch(e => {
|
||||
dbClient.execute(`CALL INC_CNT("roll");`).catch((e) => {
|
||||
log(LT.ERROR, `Failed to call stored procedure INC_CNT: ${JSON.stringify(e)}`);
|
||||
});
|
||||
|
||||
// If DEVMODE is on, only allow this command to be used in the devServer
|
||||
if (DEVMODE && message.guildId !== config.devServer) {
|
||||
message.send(constantCmds.indev).catch(e => {
|
||||
message.send(constantCmds.indev).catch((e) => {
|
||||
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
|
||||
});
|
||||
return;
|
||||
@@ -28,7 +29,7 @@ export const roll = async (message: DiscordenoMessage, args: string[], command:
|
||||
|
||||
// Rest of this command is in a try-catch to protect all sends/edits from erroring out
|
||||
try {
|
||||
const originalCommand = `${config.prefix}${command} ${args.join(" ")}`;
|
||||
const originalCommand = `${config.prefix}${command} ${args.join(' ')}`;
|
||||
|
||||
const m = await message.send(constantCmds.rolling);
|
||||
|
||||
@@ -41,10 +42,10 @@ export const roll = async (message: DiscordenoMessage, args: string[], command:
|
||||
}
|
||||
|
||||
// Rejoin all of the args and send it into the solver, if solver returns a falsy item, an error object will be substituded in
|
||||
const rollCmd = `${command} ${args.join(" ")}`;
|
||||
const returnmsg = solver.parseRoll(rollCmd, modifiers) || { error: true, errorCode: "EmptyMessage", errorMsg: "Error: Empty message", line1: "", line2: "", line3: "" };
|
||||
const rollCmd = `${command} ${args.join(' ')}`;
|
||||
const returnmsg = solver.parseRoll(rollCmd, modifiers) || { error: true, errorCode: 'EmptyMessage', errorMsg: 'Error: Empty message', line1: '', line2: '', line3: '' };
|
||||
|
||||
let returnText = "";
|
||||
let returnText = '';
|
||||
|
||||
// If there was an error, report it to the user in hopes that they can determine what they did wrong
|
||||
if (returnmsg.error) {
|
||||
@@ -53,7 +54,7 @@ export const roll = async (message: DiscordenoMessage, args: string[], command:
|
||||
|
||||
if (DEVMODE && config.logRolls) {
|
||||
// If enabled, log rolls so we can verify the bots math
|
||||
dbClient.execute(queries.insertRollLogCmd(0, 1), [originalCommand, returnmsg.errorCode, m.id]).catch(e => {
|
||||
dbClient.execute(queries.insertRollLogCmd(0, 1), [originalCommand, returnmsg.errorCode, m.id]).catch((e) => {
|
||||
log(LT.ERROR, `Failed to insert into DB: ${JSON.stringify(e)}`);
|
||||
});
|
||||
}
|
||||
@@ -64,7 +65,7 @@ export const roll = async (message: DiscordenoMessage, args: string[], command:
|
||||
|
||||
if (!modifiers.superNoDetails) {
|
||||
if (modifiers.noDetails) {
|
||||
returnText += "\nDetails suppressed by -nd flag.";
|
||||
returnText += '\nDetails suppressed by -nd flag.';
|
||||
} else {
|
||||
returnText += `\nDetails:\n${modifiers.spoiler}${returnmsg.line3}${modifiers.spoiler}`;
|
||||
}
|
||||
@@ -74,30 +75,31 @@ export const roll = async (message: DiscordenoMessage, args: string[], command:
|
||||
// If the roll was a GM roll, send DMs to all the GMs
|
||||
if (modifiers.gmRoll) {
|
||||
// Make a new return line to be sent to the roller
|
||||
const normalText = `<@${message.authorId}>${returnmsg.line1}\nResults have been messaged to the following GMs: ${modifiers.gms.join(" ")}`;
|
||||
const normalText = `<@${message.authorId}>${returnmsg.line1}\nResults have been messaged to the following GMs: ${modifiers.gms.join(' ')}`;
|
||||
|
||||
// And message the full details to each of the GMs, alerting roller of every GM that could not be messaged
|
||||
modifiers.gms.forEach(async e => {
|
||||
modifiers.gms.forEach(async (e) => {
|
||||
log(LT.LOG, `Messaging GM ${e}`);
|
||||
// If its too big, collapse it into a .txt file and send that instead.
|
||||
const b = await new Blob([returnText as BlobPart], { "type": "text" });
|
||||
const b = await new Blob([returnText as BlobPart], { 'type': 'text' });
|
||||
|
||||
if (b.size > 8388290) {
|
||||
// Update return text
|
||||
// todo: embedify
|
||||
returnText = `<@${message.authorId}>${returnmsg.line1}\n${returnmsg.line2}\nFull details could not be attached to this messaged as a \`.txt\` file as the file would be too large for Discord to handle. If you would like to see the details of rolls, please send the rolls in multiple messages instead of bundled into one.`;
|
||||
returnText =
|
||||
`<@${message.authorId}>${returnmsg.line1}\n${returnmsg.line2}\nFull details could not be attached to this messaged as a \`.txt\` file as the file would be too large for Discord to handle. If you would like to see the details of rolls, please send the rolls in multiple messages instead of bundled into one.`;
|
||||
|
||||
// Attempt to DM the GMs and send a warning if it could not DM a GM
|
||||
await sendDirectMessage(BigInt(e.substring(2, (e.length - 1))), returnText).catch(() => {
|
||||
await sendDirectMessage(BigInt(e.substring(2, e.length - 1)), returnText).catch(() => {
|
||||
message.send(generateDMFailed(e));
|
||||
});
|
||||
} else {
|
||||
// Update return
|
||||
// Update return
|
||||
// todo: embedify
|
||||
returnText = `<@${message.authorId}>${returnmsg.line1}\n${returnmsg.line2}\nFull details have been attached to this messaged as a \`.txt\` file for verification purposes.`;
|
||||
|
||||
// Attempt to DM the GMs and send a warning if it could not DM a GM
|
||||
await sendDirectMessage(BigInt(e.substring(2, (e.length - 1))), { "content": returnText, "file": { "blob": b, "name": "rollDetails.txt" } }).catch(() => {
|
||||
await sendDirectMessage(BigInt(e.substring(2, e.length - 1)), { 'content': returnText, 'file': { 'blob': b, 'name': 'rollDetails.txt' } }).catch(() => {
|
||||
message.send(generateDMFailed(e));
|
||||
});
|
||||
}
|
||||
@@ -108,7 +110,7 @@ export const roll = async (message: DiscordenoMessage, args: string[], command:
|
||||
|
||||
if (DEVMODE && config.logRolls) {
|
||||
// If enabled, log rolls so we can verify the bots math
|
||||
dbClient.execute(queries.insertRollLogCmd(0, 0), [originalCommand, returnText, m.id]).catch(e => {
|
||||
dbClient.execute(queries.insertRollLogCmd(0, 0), [originalCommand, returnText, m.id]).catch((e) => {
|
||||
log(LT.ERROR, `Failed to insert into DB: ${JSON.stringify(e)}`);
|
||||
});
|
||||
}
|
||||
@@ -116,23 +118,25 @@ export const roll = async (message: DiscordenoMessage, args: string[], command:
|
||||
// When not a GM roll, make sure the message is not too big
|
||||
if (returnText.length > 2000) {
|
||||
// If its too big, collapse it into a .txt file and send that instead.
|
||||
const b = await new Blob([returnText as BlobPart], { "type": "text" });
|
||||
const b = await new Blob([returnText as BlobPart], { 'type': 'text' });
|
||||
|
||||
if (b.size > 8388290) {
|
||||
// Update return text
|
||||
returnText = `<@${message.authorId}>${returnmsg.line1}\n${returnmsg.line2}\nDetails have been ommitted from this message for being over 2000 characters. Full details could not be attached to this messaged as a \`.txt\` file as the file would be too large for Discord to handle. If you would like to see the details of rolls, please send the rolls in multiple messages instead of bundled into one.`;
|
||||
returnText =
|
||||
`<@${message.authorId}>${returnmsg.line1}\n${returnmsg.line2}\nDetails have been ommitted from this message for being over 2000 characters. Full details could not be attached to this messaged as a \`.txt\` file as the file would be too large for Discord to handle. If you would like to see the details of rolls, please send the rolls in multiple messages instead of bundled into one.`;
|
||||
|
||||
// Send the results
|
||||
m.edit(returnText);
|
||||
} else {
|
||||
// Update return text
|
||||
returnText = `<@${message.authorId}>${returnmsg.line1}\n${returnmsg.line2}\nDetails have been ommitted from this message for being over 2000 characters. Full details have been attached to this messaged as a \`.txt\` file for verification purposes.`;
|
||||
returnText =
|
||||
`<@${message.authorId}>${returnmsg.line1}\n${returnmsg.line2}\nDetails have been ommitted from this message for being over 2000 characters. Full details have been attached to this messaged as a \`.txt\` file for verification purposes.`;
|
||||
|
||||
// Remove the original message to send new one with attachment
|
||||
m.delete();
|
||||
|
||||
// todo: embedify
|
||||
await message.send({ "content": returnText, "file": { "blob": b, "name": "rollDetails.txt" } });
|
||||
await message.send({ 'content': returnText, 'file': { 'blob': b, 'name': 'rollDetails.txt' } });
|
||||
}
|
||||
} else {
|
||||
// Finally send the text
|
||||
@@ -141,7 +145,7 @@ export const roll = async (message: DiscordenoMessage, args: string[], command:
|
||||
|
||||
if (DEVMODE && config.logRolls) {
|
||||
// If enabled, log rolls so we can verify the bots math
|
||||
dbClient.execute(queries.insertRollLogCmd(0, 0), [originalCommand, returnText, m.id]).catch(e => {
|
||||
dbClient.execute(queries.insertRollLogCmd(0, 0), [originalCommand, returnText, m.id]).catch((e) => {
|
||||
log(LT.ERROR, `Failed to insert into DB: ${JSON.stringify(e)}`);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { getModifiers } from "./getModifiers.ts";
|
||||
import { getModifiers } from './getModifiers.ts';
|
||||
|
||||
export default {
|
||||
getModifiers
|
||||
getModifiers,
|
||||
};
|
||||
|
||||
@@ -1,88 +1,88 @@
|
||||
import config from "../../../config.ts";
|
||||
import { DEVMODE } from "../../../flags.ts";
|
||||
import { dbClient, queries } from "../../db.ts";
|
||||
import config from '../../../config.ts';
|
||||
import { DEVMODE } from '../../../flags.ts';
|
||||
import { dbClient, queries } from '../../db.ts';
|
||||
import {
|
||||
// Discordeno deps
|
||||
DiscordenoMessage,
|
||||
|
||||
log,
|
||||
// Log4Deno deps
|
||||
LT, log
|
||||
} from "../../../deps.ts";
|
||||
import { generateRollError } from "../../constantCmds.ts";
|
||||
import { RollModifiers } from "../../mod.d.ts";
|
||||
LT,
|
||||
} from '../../../deps.ts';
|
||||
import { generateRollError } from '../../constantCmds.ts';
|
||||
import { RollModifiers } from '../../mod.d.ts';
|
||||
|
||||
export const getModifiers = (m: DiscordenoMessage, args: string[], command: string, originalCommand: string): RollModifiers => {
|
||||
const errorType = "Modifiers invalid:";
|
||||
const errorType = 'Modifiers invalid:';
|
||||
const modifiers: RollModifiers = {
|
||||
noDetails: false,
|
||||
superNoDetails: false,
|
||||
spoiler: "",
|
||||
spoiler: '',
|
||||
maxRoll: false,
|
||||
nominalRoll: false,
|
||||
gmRoll: false,
|
||||
gms: [],
|
||||
order: "",
|
||||
order: '',
|
||||
valid: false,
|
||||
count: false
|
||||
count: false,
|
||||
};
|
||||
|
||||
// Check if any of the args are command flags and pull those out into the modifiers object
|
||||
for (let i = 0; i < args.length; i++) {
|
||||
log(LT.LOG, `Checking ${command}${args.join(" ")} for command modifiers ${i}`);
|
||||
log(LT.LOG, `Checking ${command}${args.join(' ')} for command modifiers ${i}`);
|
||||
let defaultCase = false;
|
||||
switch (args[i].toLowerCase()) {
|
||||
case "-c":
|
||||
case '-c':
|
||||
modifiers.count = true;
|
||||
break;
|
||||
case "-nd":
|
||||
case '-nd':
|
||||
modifiers.noDetails = true;
|
||||
break;
|
||||
case "-snd":
|
||||
case '-snd':
|
||||
modifiers.superNoDetails = true;
|
||||
break;
|
||||
case "-s":
|
||||
modifiers.spoiler = "||";
|
||||
case '-s':
|
||||
modifiers.spoiler = '||';
|
||||
break;
|
||||
case "-m":
|
||||
case '-m':
|
||||
modifiers.maxRoll = true;
|
||||
break;
|
||||
case "-n":
|
||||
case '-n':
|
||||
modifiers.nominalRoll = true;
|
||||
break;
|
||||
case "-gm":
|
||||
case '-gm':
|
||||
modifiers.gmRoll = true;
|
||||
|
||||
// -gm is a little more complex, as we must get all of the GMs that need to be DMd
|
||||
while (((i + 1) < args.length) && args[i + 1].startsWith("<@")) {
|
||||
while (((i + 1) < args.length) && args[i + 1].startsWith('<@')) {
|
||||
log(LT.LOG, `Finding all GMs, checking args ${JSON.stringify(args)}`);
|
||||
// Keep looping thru the rest of the args until one does not start with the discord mention code
|
||||
modifiers.gms.push(args[i + 1].replace(/[!]/g, ""));
|
||||
args.splice((i + 1), 1);
|
||||
modifiers.gms.push(args[i + 1].replace(/[!]/g, ''));
|
||||
args.splice(i + 1, 1);
|
||||
}
|
||||
if (modifiers.gms.length < 1) {
|
||||
// If -gm is on and none were found, throw an error
|
||||
m.edit(generateRollError(errorType, "Must specifiy at least one GM by @mentioning them"));
|
||||
m.edit(generateRollError(errorType, 'Must specifiy at least one GM by @mentioning them'));
|
||||
|
||||
if (DEVMODE && config.logRolls) {
|
||||
// If enabled, log rolls so we can verify the bots math
|
||||
dbClient.execute(queries.insertRollLogCmd(0, 1), [originalCommand, "NoGMsFound", m.id]).catch(e => {
|
||||
dbClient.execute(queries.insertRollLogCmd(0, 1), [originalCommand, 'NoGMsFound', m.id]).catch((e) => {
|
||||
log(LT.ERROR, `Failed to insert into DB: ${JSON.stringify(e)}`);
|
||||
});
|
||||
}
|
||||
return modifiers;
|
||||
}
|
||||
break;
|
||||
case "-o":
|
||||
case '-o':
|
||||
// Shift the -o out of the array so the next item is the direction
|
||||
args.splice(i, 1);
|
||||
|
||||
if (!args[i] || args[i].toLowerCase()[0] !== "d" && args[i].toLowerCase()[0] !== "a") {
|
||||
|
||||
if (!args[i] || args[i].toLowerCase()[0] !== 'd' && args[i].toLowerCase()[0] !== 'a') {
|
||||
// If -o is on and asc or desc was not specified, error out
|
||||
m.edit(generateRollError(errorType, "Must specifiy `a` or `d` to order the rolls ascending or descending"));
|
||||
m.edit(generateRollError(errorType, 'Must specifiy `a` or `d` to order the rolls ascending or descending'));
|
||||
|
||||
if (DEVMODE && config.logRolls) {
|
||||
// If enabled, log rolls so we can verify the bots math
|
||||
dbClient.execute(queries.insertRollLogCmd(0, 1), [originalCommand, "NoOrderFound", m.id]).catch(e => {
|
||||
dbClient.execute(queries.insertRollLogCmd(0, 1), [originalCommand, 'NoOrderFound', m.id]).catch((e) => {
|
||||
log(LT.ERROR, `Failed to insert into DB: ${JSON.stringify(e)}`);
|
||||
});
|
||||
}
|
||||
@@ -105,11 +105,11 @@ export const getModifiers = (m: DiscordenoMessage, args: string[], command: stri
|
||||
|
||||
// maxRoll and nominalRoll cannot both be on, throw an error
|
||||
if (modifiers.maxRoll && modifiers.nominalRoll) {
|
||||
m.edit(generateRollError(errorType, "Cannot maximise and nominise the roll at the same time"));
|
||||
m.edit(generateRollError(errorType, 'Cannot maximise and nominise the roll at the same time'));
|
||||
|
||||
if (DEVMODE && config.logRolls) {
|
||||
// If enabled, log rolls so we can verify the bots math
|
||||
dbClient.execute(queries.insertRollLogCmd(0, 1), [originalCommand, "MaxAndNominal", m.id]).catch(e => {
|
||||
dbClient.execute(queries.insertRollLogCmd(0, 1), [originalCommand, 'MaxAndNominal', m.id]).catch((e) => {
|
||||
log(LT.ERROR, `Failed to insert into DB: ${JSON.stringify(e)}`);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
import { dbClient } from "../db.ts";
|
||||
import { dbClient } from '../db.ts';
|
||||
import {
|
||||
// Discordeno deps
|
||||
DiscordenoMessage,
|
||||
|
||||
log,
|
||||
// Log4Deno deps
|
||||
LT, log
|
||||
} from "../../deps.ts";
|
||||
import { constantCmds } from "../constantCmds.ts";
|
||||
LT,
|
||||
} from '../../deps.ts';
|
||||
import { constantCmds } from '../constantCmds.ts';
|
||||
|
||||
export const rollHelp = (message: DiscordenoMessage) => {
|
||||
// Light telemetry to see how many times a command is being run
|
||||
dbClient.execute(`CALL INC_CNT("rollhelp");`).catch(e => {
|
||||
dbClient.execute(`CALL INC_CNT("rollhelp");`).catch((e) => {
|
||||
log(LT.ERROR, `Failed to call stored procedure INC_CNT: ${JSON.stringify(e)}`);
|
||||
});
|
||||
|
||||
message.send(constantCmds.rollHelp).catch(e => {
|
||||
message.send(constantCmds.rollHelp).catch((e) => {
|
||||
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -1,16 +1,18 @@
|
||||
import { dbClient } from "../db.ts";
|
||||
import { dbClient } from '../db.ts';
|
||||
import {
|
||||
// Discordeno deps
|
||||
cache, cacheHandlers, DiscordenoMessage,
|
||||
|
||||
cache,
|
||||
cacheHandlers,
|
||||
DiscordenoMessage,
|
||||
log,
|
||||
// Log4Deno deps
|
||||
LT, log
|
||||
} from "../../deps.ts";
|
||||
import { constantCmds, generateStats } from "../constantCmds.ts";
|
||||
LT,
|
||||
} from '../../deps.ts';
|
||||
import { constantCmds, generateStats } from '../constantCmds.ts';
|
||||
|
||||
export const stats = async (message: DiscordenoMessage) => {
|
||||
// Light telemetry to see how many times a command is being run
|
||||
dbClient.execute(`CALL INC_CNT("stats");`).catch(e => {
|
||||
dbClient.execute(`CALL INC_CNT("stats");`).catch((e) => {
|
||||
log(LT.ERROR, `Failed to call stored procedure INC_CNT: ${JSON.stringify(e)}`);
|
||||
});
|
||||
|
||||
@@ -18,19 +20,19 @@ export const stats = async (message: DiscordenoMessage) => {
|
||||
const m = await message.send(constantCmds.loadingStats);
|
||||
|
||||
// Calculate how many times commands have been run
|
||||
const rollQuery = await dbClient.query(`SELECT count FROM command_cnt WHERE command = "roll";`).catch(e => {
|
||||
const rollQuery = await dbClient.query(`SELECT count FROM command_cnt WHERE command = "roll";`).catch((e) => {
|
||||
log(LT.ERROR, `Failed to query DB: ${JSON.stringify(e)}`);
|
||||
});
|
||||
const totalQuery = await dbClient.query(`SELECT SUM(count) as count FROM command_cnt;`).catch(e => {
|
||||
const totalQuery = await dbClient.query(`SELECT SUM(count) as count FROM command_cnt;`).catch((e) => {
|
||||
log(LT.ERROR, `Failed to query DB: ${JSON.stringify(e)}`);
|
||||
});
|
||||
const rolls = BigInt(rollQuery[0].count);
|
||||
const total = BigInt(totalQuery[0].count);
|
||||
|
||||
const cachedGuilds = await cacheHandlers.size("guilds");
|
||||
const cachedChannels = await cacheHandlers.size("channels");
|
||||
const cachedMembers = await cacheHandlers.size("members");
|
||||
m.edit(generateStats(cachedGuilds + cache.dispatchedGuildIds.size, cachedChannels + cache.dispatchedChannelIds.size, cachedMembers, rolls, total - rolls)).catch(e => {
|
||||
const cachedGuilds = await cacheHandlers.size('guilds');
|
||||
const cachedChannels = await cacheHandlers.size('channels');
|
||||
const cachedMembers = await cacheHandlers.size('members');
|
||||
m.edit(generateStats(cachedGuilds + cache.dispatchedGuildIds.size, cachedChannels + cache.dispatchedChannelIds.size, cachedMembers, rolls, total - rolls)).catch((e) => {
|
||||
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
|
||||
});
|
||||
} catch (e) {
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
import { dbClient } from "../db.ts";
|
||||
import { dbClient } from '../db.ts';
|
||||
import {
|
||||
// Discordeno deps
|
||||
DiscordenoMessage,
|
||||
|
||||
log,
|
||||
// Log4Deno deps
|
||||
LT, log
|
||||
} from "../../deps.ts";
|
||||
import { constantCmds } from "../constantCmds.ts";
|
||||
LT,
|
||||
} from '../../deps.ts';
|
||||
import { constantCmds } from '../constantCmds.ts';
|
||||
|
||||
export const version = (message: DiscordenoMessage) => {
|
||||
// Light telemetry to see how many times a command is being run
|
||||
dbClient.execute(`CALL INC_CNT("version");`).catch(e => {
|
||||
dbClient.execute(`CALL INC_CNT("version");`).catch((e) => {
|
||||
log(LT.ERROR, `Failed to call stored procedure INC_CNT: ${JSON.stringify(e)}`);
|
||||
});
|
||||
|
||||
message.send(constantCmds.version).catch(e => {
|
||||
message.send(constantCmds.version).catch((e) => {
|
||||
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user