Sonar Cleanup - Phase 5
This commit is contained in:
parent
9eff1f0835
commit
aa97a1514c
|
@ -9,14 +9,17 @@ import {
|
|||
import { generateApiFailed, generateApiSuccess } from '../../constantCmds.ts';
|
||||
|
||||
export const allowBlock = async (message: DiscordenoMessage, apiArg: string) => {
|
||||
let errorOutInitial = false;
|
||||
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;
|
||||
errorOutInitial = true;
|
||||
});
|
||||
if (errorOutInitial) return;
|
||||
|
||||
let errorOut = false;
|
||||
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(
|
||||
|
@ -25,7 +28,7 @@ export const allowBlock = async (message: DiscordenoMessage, apiArg: string) =>
|
|||
message.send(generateApiFailed(apiArg)).catch((e1) => {
|
||||
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e1)}`);
|
||||
});
|
||||
return;
|
||||
errorOut = true;
|
||||
},
|
||||
);
|
||||
} else {
|
||||
|
@ -36,10 +39,11 @@ export const allowBlock = async (message: DiscordenoMessage, apiArg: string) =>
|
|||
message.send(generateApiFailed(apiArg)).catch((e1) => {
|
||||
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e1)}`);
|
||||
});
|
||||
return;
|
||||
errorOut = true;
|
||||
},
|
||||
);
|
||||
}
|
||||
if (errorOut) 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) => {
|
||||
|
|
|
@ -9,13 +9,15 @@ import {
|
|||
import { constantCmds } from '../../constantCmds.ts';
|
||||
|
||||
export const deleteGuild = async (message: DiscordenoMessage) => {
|
||||
let errorOut = false;
|
||||
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) => {
|
||||
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e1)}`);
|
||||
});
|
||||
return;
|
||||
errorOut = true;
|
||||
});
|
||||
if (errorOut) 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) => {
|
||||
|
|
|
@ -9,14 +9,17 @@ import {
|
|||
import { generateApiFailed, generateApiSuccess } from '../../constantCmds.ts';
|
||||
|
||||
export const showHideWarn = async (message: DiscordenoMessage, apiArg: string) => {
|
||||
let errorOutInitial = false;
|
||||
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) => {
|
||||
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e1)}`);
|
||||
});
|
||||
return;
|
||||
errorOutInitial = true;
|
||||
});
|
||||
if (errorOutInitial) return;
|
||||
|
||||
let errorOut = false;
|
||||
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) => {
|
||||
|
@ -24,7 +27,7 @@ export const showHideWarn = async (message: DiscordenoMessage, apiArg: string) =
|
|||
message.send(generateApiFailed(`${apiArg} on`)).catch((e1) => {
|
||||
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e1)}`);
|
||||
});
|
||||
return;
|
||||
errorOut = true;
|
||||
});
|
||||
} else {
|
||||
// Since guild is in our DB, update it
|
||||
|
@ -33,9 +36,10 @@ export const showHideWarn = async (message: DiscordenoMessage, apiArg: string) =
|
|||
message.send(generateApiFailed(`${apiArg} on`)).catch((e1) => {
|
||||
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e1)}`);
|
||||
});
|
||||
return;
|
||||
errorOut = true;
|
||||
});
|
||||
}
|
||||
if (errorOut) 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) => {
|
||||
|
|
|
@ -10,13 +10,15 @@ import { constantCmds, generateApiStatus } from '../../constantCmds.ts';
|
|||
|
||||
export const status = async (message: DiscordenoMessage) => {
|
||||
// Get status of guild from the db
|
||||
let errorOut = false;
|
||||
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) => {
|
||||
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e1)}`);
|
||||
});
|
||||
return;
|
||||
errorOut = true;
|
||||
});
|
||||
if (errorOut) return;
|
||||
|
||||
// Check if we got an item back or not
|
||||
if (guildQuery.length > 0) {
|
||||
|
|
Loading…
Reference in New Issue