Compare commits
3 Commits
d5e3ad8e99
...
db7b52d66e
Author | SHA1 | Date |
---|---|---|
Jill | db7b52d66e | |
Jill | 8d66d125b8 | |
Jill | 98e80af87d |
|
@ -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');
|
||||
});
|
||||
};
|
|
@ -92,8 +92,8 @@ bot.on(Events.InteractionCreate, async (interaction) => {
|
|||
try {
|
||||
await command.execute(interaction, interaction.member);
|
||||
} catch (error) {
|
||||
if (interaction.isRepliable() && !interaction.replied && !interaction.deferred) interaction.reply({ content: '`ERROR`', ephemeral: true });
|
||||
if (interaction.deferred) interaction.followUp('`ERROR`');
|
||||
if (interaction.isRepliable() && !interaction.replied && !interaction.deferred) interaction.reply({ content: `\`ERROR\`\n\`\`\`\n${error}\n\`\`\``, ephemeral: true });
|
||||
if (interaction.deferred) interaction.followUp(`\`ERROR\`\n\`\`\`\n${error}\n\`\`\``);
|
||||
log.error(error);
|
||||
}
|
||||
} else if (interaction.isAutocomplete()) {
|
||||
|
|
|
@ -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,23 @@ export const counterConfigs = new Map([
|
|||
type: ConfigType.Bool,
|
||||
default: false
|
||||
}],
|
||||
['messageTemplate', {
|
||||
type: ConfigType.String,
|
||||
default: '**%user** has %action the counter by **%amt**.'
|
||||
}],
|
||||
['messageTemplateIncrease', {
|
||||
type: ConfigType.String,
|
||||
default: ''
|
||||
}],
|
||||
['messageTemplateDecrease', {
|
||||
type: ConfigType.String,
|
||||
default: ''
|
||||
}],
|
||||
|
||||
// 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 +212,13 @@ 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');
|
||||
let template = await getCounterConfig(counter.id, 'messageTemplate') as string;
|
||||
const templateIncrease = await getCounterConfig(counter.id, 'messageTemplateIncrease') as string;
|
||||
if (templateIncrease !== '' && delta > 0) template = templateIncrease;
|
||||
const templateDecrease = await getCounterConfig(counter.id, 'messageTemplateDecrease') as string;
|
||||
if (templateDecrease !== '' && delta < 0) template = templateDecrease;
|
||||
|
||||
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)}**.`)
|
||||
|
@ -223,6 +227,7 @@ export async function announceCounterUpdate(bot: Client, member: GuildMember, de
|
|||
.replaceAll('%user', anonymous ? 'someone' : member.toString())
|
||||
.replaceAll('%action', delta > 0 ? 'increased' : 'decreased')
|
||||
.replaceAll('%amt', Math.abs(delta).toString())
|
||||
.replaceAll('%total', value.toString())
|
||||
)
|
||||
.setTimestamp()
|
||||
.setFooter({
|
||||
|
|
|
@ -32,7 +32,6 @@ export interface Counter {
|
|||
channel: string,
|
||||
guild: string,
|
||||
message?: string,
|
||||
messageTemplate?: string,
|
||||
allowlistConsumer: boolean,
|
||||
allowlistProducer: boolean
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue