Added hideWarn cmd file with template code
This commit is contained in:
parent
0d1ef83f50
commit
88faa27278
|
@ -51,6 +51,13 @@ export const api = async (message: DiscordenoMessage, args: string[]) => {
|
||||||
else if (apiArg === "status") {
|
else if (apiArg === "status") {
|
||||||
apiCommands.status(message);
|
apiCommands.status(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// [[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") {
|
||||||
|
apiCommands.showHideWarn(message, apiArg);
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} 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)}`);
|
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
|
||||||
|
|
|
@ -2,10 +2,12 @@ import { help } from "./apiHelp.ts";
|
||||||
import { allowBlock } from "./allowBlock.ts";
|
import { allowBlock } from "./allowBlock.ts";
|
||||||
import { deleteGuild } from "./deleteGuild.ts";
|
import { deleteGuild } from "./deleteGuild.ts";
|
||||||
import { status } from "./status.ts";
|
import { status } from "./status.ts";
|
||||||
|
import { showHideWarn } from "./showHideWarn.ts";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
help,
|
help,
|
||||||
allowBlock,
|
allowBlock,
|
||||||
deleteGuild,
|
deleteGuild,
|
||||||
status
|
status,
|
||||||
|
showHideWarn
|
||||||
};
|
};
|
||||||
|
|
|
@ -19,7 +19,7 @@ export const allowBlock = async (message: DiscordenoMessage, apiArg: string) =>
|
||||||
|
|
||||||
if (guildQuery.length === 0) {
|
if (guildQuery.length === 0) {
|
||||||
// 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,active) values(?,?)`, [message.guildId, message.channelId, ((apiArg === "allow" || apiArg === "enable") ? 1 : 0)]).catch(e0 => {
|
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)}`);
|
log(LT.ERROR, `Failed to insert into 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)}`);
|
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e1)}`);
|
||||||
|
@ -36,6 +36,7 @@ export const allowBlock = async (message: DiscordenoMessage, apiArg: string) =>
|
||||||
return;
|
return;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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)).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)}`);
|
||||||
|
|
|
@ -0,0 +1,44 @@
|
||||||
|
import { dbClient } from "../../db.ts";
|
||||||
|
import {
|
||||||
|
// Discordeno deps
|
||||||
|
DiscordenoMessage,
|
||||||
|
|
||||||
|
// Log4Deno deps
|
||||||
|
LT, log
|
||||||
|
} 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 => {
|
||||||
|
log(LT.ERROR, `Failed to query DB: ${JSON.stringify(e0)}`);
|
||||||
|
message.send(generateApiFailed(apiArg)).catch(e1 => {
|
||||||
|
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e1)}`);
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
});
|
||||||
|
|
||||||
|
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 => {
|
||||||
|
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 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)).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)).catch(e => {
|
||||||
|
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
|
||||||
|
});
|
||||||
|
};
|
Loading…
Reference in New Issue