move messageTemplates out of counters table

This commit is contained in:
Jill 2023-11-13 20:01:19 +03:00
parent 98e80af87d
commit 8d66d125b8
Signed by: oat
GPG Key ID: 33489AA58A955108
3 changed files with 27 additions and 16 deletions

View File

@ -0,0 +1,21 @@
/**
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.up = function(knex) {
return knex.schema
.alterTable('counters', table => {
table.dropColumn('messageTemplate');
});
};
/**
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.down = function(knex) {
return knex.schema
.alterTable('counters', table => {
table.string('messageTemplate');
});
};

View File

@ -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<Counter>('counters')
.where('id', id)
.update({
'messageTemplate': value
});
return;
}
const updated = await db<CounterConfiguration>('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)}**.`)

View File

@ -32,7 +32,6 @@ export interface Counter {
channel: string,
guild: string,
message?: string,
messageTemplate?: string,
allowlistConsumer: boolean,
allowlistProducer: boolean
}