diff --git a/migrations/20231113165814_removeMessageTemplates.js b/migrations/20231113165814_removeMessageTemplates.js new file mode 100644 index 0000000..c453398 --- /dev/null +++ b/migrations/20231113165814_removeMessageTemplates.js @@ -0,0 +1,21 @@ +/** + * @param { import("knex").Knex } knex + * @returns { Promise } + */ +exports.up = function(knex) { + return knex.schema + .alterTable('counters', table => { + table.dropColumn('messageTemplate'); + }); +}; + +/** + * @param { import("knex").Knex } knex + * @returns { Promise } + */ +exports.down = function(knex) { + return knex.schema + .alterTable('counters', table => { + table.string('messageTemplate'); + }); +}; diff --git a/src/lib/counter.ts b/src/lib/counter.ts index 8da27fb..938dfd2 100644 --- a/src/lib/counter.ts +++ b/src/lib/counter.ts @@ -61,7 +61,6 @@ export async function getCounterConfigRaw(counter: Counter) { // just the ugly way of life config.set('emoji', counter.emoji); - config.set('messageTemplate', counter.messageTemplate || (counterConfigs.get('messageTemplate')!.default! as string)); // wow! this line is truly awful return config; } @@ -93,14 +92,6 @@ export async function setCounterConfig(id: number, option: string, value: string }); return; } - if (option === 'messageTemplate') { - await db('counters') - .where('id', id) - .update({ - 'messageTemplate': value - }); - return; - } const updated = await db('counterConfigurations') .update({ @@ -170,15 +161,15 @@ export const counterConfigs = new Map([ type: ConfigType.Bool, default: false }], + ['messageTemplate', { + type: ConfigType.String, + default: '**%user** has %action the counter by **%amt**.' + }], // these ones are fake and are just stand-ins for values defined inside the actual counters table ['emoji', { type: ConfigType.String, default: '' - }], - ['messageTemplate', { - type: ConfigType.String, - default: '**%user** has %action the counter by **%amt**.' }] ]); @@ -213,8 +204,8 @@ export async function updateCounter(bot: Client, counter: Counter, value: number export async function announceCounterUpdate(bot: Client, member: GuildMember, delta: number, counter: Counter, value: number) { const channel = await bot.channels.fetch(counter.channel) as TextChannel; - const template = counter.messageTemplate || counterConfigs.get('messageTemplate')!.default as string; - const anonymous = await getCounterConfig(counter.id, 'anonymous'); + const template = await getCounterConfig(counter.id, 'messageTemplate') as string; + const anonymous = await getCounterConfig(counter.id, 'anonymous') as boolean; const embed = new EmbedBuilder() //.setDescription(`**${member.toString()}** has ${delta > 0 ? 'increased' : 'decreased'} the counter by **${Math.abs(delta)}**.`) diff --git a/src/lib/db.ts b/src/lib/db.ts index ead541d..d1ae0ef 100644 --- a/src/lib/db.ts +++ b/src/lib/db.ts @@ -32,7 +32,6 @@ export interface Counter { channel: string, guild: string, message?: string, - messageTemplate?: string, allowlistConsumer: boolean, allowlistProducer: boolean }