Update guild delete and clean map

This commit is contained in:
Ean Milligan (Bastion) 2023-04-21 02:41:37 -04:00
parent 4011cf74d6
commit 815364305b
3 changed files with 17 additions and 9 deletions

View File

@ -13,7 +13,7 @@ console.log('Attempt to drop all tables');
await dbClient.execute(`DROP PROCEDURE IF EXISTS INC_CNT;`); await dbClient.execute(`DROP PROCEDURE IF EXISTS INC_CNT;`);
await dbClient.execute(`DROP TABLE IF EXISTS command_cnt;`); await dbClient.execute(`DROP TABLE IF EXISTS command_cnt;`);
await dbClient.execute(`DROP TABLE IF EXISTS guild_settings;`); await dbClient.execute(`DROP TABLE IF EXISTS guild_settings;`);
await dbClient.execute(`DROP TABLE IF EXISTS active_event;`); await dbClient.execute(`DROP TABLE IF EXISTS active_events;`);
console.log('Tables dropped'); console.log('Tables dropped');
console.log('Attempting to create table command_cnt'); console.log('Attempting to create table command_cnt');
@ -52,9 +52,9 @@ await dbClient.execute(`
`); `);
console.log('Table created'); console.log('Table created');
console.log('Attempting to create table active_event'); console.log('Attempting to create table active_events');
await dbClient.execute(` await dbClient.execute(`
CREATE TABLE active_event ( CREATE TABLE active_events (
messageId bigint unsigned NOT NULL, messageId bigint unsigned NOT NULL,
channelId bigint unsigned NOT NULL, channelId bigint unsigned NOT NULL,
guildId bigint unsigned NOT NULL, guildId bigint unsigned NOT NULL,

View File

@ -13,8 +13,8 @@ export const dbClient = await new Client().connect({
export const queries = { export const queries = {
callIncCnt: (cmdName: string) => `CALL INC_CNT("${cmdName}");`, callIncCnt: (cmdName: string) => `CALL INC_CNT("${cmdName}");`,
insertEvent: 'INSERT INTO active_event(messageId,channelId,guildId,ownerId,eventTime) values(?,?,?,?,?)', insertEvent: 'INSERT INTO active_events(messageId,channelId,guildId,ownerId,eventTime) values(?,?,?,?,?)',
deleteEvent: 'DELETE FROM active_event WHERE channelId = ? AND messageId = ?', deleteEvent: 'DELETE FROM active_events WHERE channelId = ? AND messageId = ?',
}; };
export const lfgChannelSettings: Map<string, LfgChannelSetting> = new Map(); export const lfgChannelSettings: Map<string, LfgChannelSetting> = new Map();

View File

@ -1,20 +1,28 @@
import config from '../../config.ts'; import config from '../../config.ts';
import { Bot, log, LT } from '../../deps.ts'; import { Bot, log, LT } from '../../deps.ts';
import { warnColor } from '../commandUtils.ts'; import { warnColor } from '../commandUtils.ts';
import { dbClient } from '../db.ts'; import { dbClient, lfgChannelSettings } from '../db.ts';
import utils from '../utils.ts'; import utils from '../utils.ts';
export const guildDelete = async (bot: Bot, guildId: bigint) => { export const guildDelete = async (bot: Bot, guildId: bigint) => {
log(LT.LOG, `Handling leaving guild ${utils.jsonStringifyBig(guildId)}`); log(LT.LOG, `Handling leaving guild ${utils.jsonStringifyBig(guildId)}`);
// Clean the DB
try { try {
await dbClient.execute('DELETE FROM guild_prefix WHERE guildId = ?', [guildId]); await dbClient.execute('DELETE FROM guild_settings WHERE guildId = ?', [guildId]);
await dbClient.execute('DELETE FROM guild_mod_role WHERE guildId = ?', [guildId]); await dbClient.execute('DELETE FROM active_events WHERE guildId = ?', [guildId]);
await dbClient.execute('DELETE FROM guild_clean_channel WHERE guildId = ?', [guildId]);
} catch (e) { } catch (e) {
log(LT.WARN, `Failed to remove guild from DB: ${utils.jsonStringifyBig(e)}`); log(LT.WARN, `Failed to remove guild from DB: ${utils.jsonStringifyBig(e)}`);
} }
// Clean lfgChannelSettings
lfgChannelSettings.forEach((_val, key) => {
if (key.startsWith(`${guildId}-`)) {
lfgChannelSettings.delete(key);
}
});
// Send Log Message
bot.helpers.sendMessage(config.logChannel, { bot.helpers.sendMessage(config.logChannel, {
embeds: [{ embeds: [{
title: 'Removed from Guild', title: 'Removed from Guild',