Finalized hide-warn command

This commit is contained in:
Ean Milligan (Bastion) 2022-05-09 19:18:49 -04:00
parent 88faa27278
commit eba7e028b2
4 changed files with 22 additions and 12 deletions

View File

@ -185,6 +185,7 @@ const start = async (): Promise<void> => {
// Check if user is authenticated to use this endpoint // Check if user is authenticated to use this endpoint
let authorized = false; let authorized = false;
let hideWarn = false;
// Check if the db has the requested userid/channelid combo, and that the requested userid matches the userid linked with the api key // Check if the db has the requested userid/channelid combo, and that the requested userid matches the userid linked with the api key
const dbChannelQuery = await dbClient.query("SELECT active, banned FROM allowed_channels WHERE userid = ? AND channelid = ?", [apiUserid, BigInt(query.get("channel") || "0")]); const dbChannelQuery = await dbClient.query("SELECT active, banned FROM allowed_channels WHERE userid = ? AND channelid = ?", [apiUserid, BigInt(query.get("channel") || "0")]);
@ -193,11 +194,12 @@ const start = async (): Promise<void> => {
// Get the guild from the channel and make sure user is in said guild // Get the guild from the channel and make sure user is in said guild
const guild = cache.channels.get(BigInt(query.get("channel") || ""))?.guild; const guild = cache.channels.get(BigInt(query.get("channel") || ""))?.guild;
if (guild && guild.members.get(BigInt(query.get("user") || ""))?.id) { if (guild && guild.members.get(BigInt(query.get("user") || ""))?.id) {
const dbGuildQuery = await dbClient.query("SELECT active, banned FROM allowed_guilds WHERE guildid = ? AND channelid = ?", [guild.id, BigInt(query.get("channel") || "0")]); const dbGuildQuery = await dbClient.query("SELECT active, banned, hidewarn FROM allowed_guilds WHERE guildid = ? AND channelid = ?", [guild.id, BigInt(query.get("channel") || "0")]);
// Make sure guild allows API rolls // Make sure guild allows API rolls
if (dbGuildQuery.length === 1 && dbGuildQuery[0].active && !dbGuildQuery[0].banned) { if (dbGuildQuery.length === 1 && dbGuildQuery[0].active && !dbGuildQuery[0].banned) {
authorized = true; authorized = true;
hideWarn = dbGuildQuery[0].hidewarn;
} }
} }
} }
@ -240,7 +242,7 @@ const start = async (): Promise<void> => {
const returnmsg = solver.parseRoll(rollCmd, config.prefix, config.postfix, query.has("m"), query.has("n"), query.has("o") ? (query.get("o")?.toLowerCase() || "") : ""); const returnmsg = solver.parseRoll(rollCmd, config.prefix, config.postfix, query.has("m"), query.has("n"), query.has("o") ? (query.get("o")?.toLowerCase() || "") : "");
// Alert users why this message just appeared and how they can report abues pf this feature // Alert users why this message just appeared and how they can report abues pf this feature
const apiPrefix = `The following roll was conducted using my built in API. If someone in this channel did not request this roll, please report API abuse here: <${config.api.supportURL}>\n\n`; const apiPrefix = hideWarn ? '' : `The following roll was conducted using my built in API. If someone in this channel did not request this roll, please report API abuse here: <${config.api.supportURL}>\n\n`;
let m, returnText = ""; let m, returnText = "";
// Handle sending the error message to whoever called the api // Handle sending the error message to whoever called the api

View File

@ -38,7 +38,7 @@ export const allowBlock = 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 // 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}ed`)).catch(e => {
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`); log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
}); });
}; };

View File

@ -11,7 +11,7 @@ import { generateApiFailed, generateApiSuccess } from "../../constantCmds.ts";
export const showHideWarn = async (message: DiscordenoMessage, apiArg: string) => { 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)}`); log(LT.ERROR, `Failed to query DB: ${JSON.stringify(e0)}`);
message.send(generateApiFailed(apiArg)).catch(e1 => { message.send(generateApiFailed(`${apiArg} on`)).catch(e1 => {
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e1)}`); log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e1)}`);
}); });
return; return;
@ -21,7 +21,7 @@ export const showHideWarn = async (message: DiscordenoMessage, apiArg: string) =
// Since guild is not in our DB, add it in // 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)}`); log(LT.ERROR, `Failed to insert into DB: ${JSON.stringify(e0)}`);
message.send(generateApiFailed(apiArg)).catch(e1 => { message.send(generateApiFailed(`${apiArg} on`)).catch(e1 => {
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e1)}`); log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e1)}`);
}); });
return; return;
@ -30,7 +30,7 @@ export const showHideWarn = async (message: DiscordenoMessage, apiArg: string) =
// Since guild is in our DB, update it // 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)}`); log(LT.ERROR, `Failed to update DB: ${JSON.stringify(e0)}`);
message.send(generateApiFailed(apiArg)).catch(e1 => { message.send(generateApiFailed(`${apiArg} on`)).catch(e1 => {
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e1)}`); log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e1)}`);
}); });
return; return;

View File

@ -21,7 +21,7 @@ export const constantCmds = {
{ {
name: "The Artificer's API Details:", name: "The Artificer's API Details:",
value: `The Artificer has a built in API that allows user to roll dice into Discord using third party programs. value: `The Artificer has a built in API that allows user to roll dice into Discord using third party programs.
By default, API rolls are blocked from being sent in your guild. By default, API rolls are blocked from being sent in your guild. The API warning is also enabled by default.
These commands may only be used by the Owner or Admins of your guild. These commands may only be used by the Owner or Admins of your guild.
For information on how to use the API, please check the GitHub README for more information [here](https://github.com/Burn-E99/TheArtificer). For information on how to use the API, please check the GitHub README for more information [here](https://github.com/Burn-E99/TheArtificer).
@ -38,19 +38,27 @@ export const constantCmds = {
inline: true inline: true
}, { }, {
name: `\`${config.prefix}api status\``, name: `\`${config.prefix}api status\``,
value: "Shows the current status of the API for this guild", value: "Shows the current status of the API for the channel this was run in",
inline: true inline: true
}, { }, {
name: `\`${config.prefix}api allow/enable\``, name: `\`${config.prefix}api allow/enable\``,
value: "Allows API Rolls to be sent to this guild", value: "Allows API Rolls to be sent to the channel this was run in",
inline: true inline: true
}, { }, {
name: `\`${config.prefix}api block/disable\``, name: `\`${config.prefix}api block/disable\``,
value: "Blocks API Rolls from being sent to this guild", value: "Blocks API Rolls from being sent to the channel this was run in",
inline: true inline: true
}, { }, {
name: `\`${config.prefix}api delete\``, name: `\`${config.prefix}api delete\``,
value: "Deletes this guild from The Artificer's database", value: "Deletes this channel's settings from The Artificer's database",
inline: true
}, {
name: `\`${config.prefix}api show-warn\``,
value: "Shows the API warning on all rolls sent to the channel this was run in",
inline: true
}, {
name: `\`${config.prefix}api hide-warn\``,
value: "Hides the API warning on all rolls sent to the channel this was run in",
inline: true inline: true
} }
] ]
@ -379,7 +387,7 @@ export const generateApiStatus = (banned: boolean, active: boolean) => ({
export const generateApiSuccess = (args: string) => ({ export const generateApiSuccess = (args: string) => ({
embeds: [{ embeds: [{
title: `API rolls have successfully been ${args}ed for this guild.` title: `API rolls have successfully been ${args} for this guild.`
}] }]
}); });