diff --git a/src/commands/about.ts b/src/commands/about.ts index daf403f..0998054 100644 --- a/src/commands/about.ts +++ b/src/commands/about.ts @@ -68,15 +68,7 @@ export const execute = async (interaction: ChatInputCommandInteraction) => { )}.\n\nAll features are free to use, but if you would like to support the development of this bot, you can donate ${hyperlink( 'here', 'https://discog.localplayer.dev/donate' - )}.\n\nMeanwhile, here are some commands you can try out:\n- ${inlineCode( - '/anime image' - )}\n- ${inlineCode('/announce')}\n- ${inlineCode( - '/github profile' - )}\n- ${inlineCode('/identity bio set')}\n- ${inlineCode( - '/info guild' - )}\n- ${inlineCode('/ping')}\n- ${inlineCode( - '/poll' - )}\n- ${inlineCode('/schedule')}\n- ${inlineCode('/unix')}` + )}.` ) ] }); diff --git a/src/commands/admin.ts b/src/commands/admin.ts index cbb2ea6..446efef 100644 --- a/src/commands/admin.ts +++ b/src/commands/admin.ts @@ -7,6 +7,7 @@ import { PermissionFlagsBits, SlashCommandBuilder, bold, + channelMention, roleMention, underscore, userMention @@ -86,12 +87,6 @@ export const data = new SlashCommandBuilder() .setName('channel') .setDescription('Channel to lock') .setRequired(false); - }) - .addBooleanOption(option => { - return option - .setName('unlock') - .setDescription('Unlock the channel instead') - .setRequired(false); }); }); }); @@ -223,11 +218,10 @@ const handlers = { return; } const channel = interaction.options.getChannel('channel') - ? await interaction.guild.channels.fetch( - interaction.options.getChannel('channel')!.id - ) - : interaction.channel, - unlock = interaction.options.getBoolean('unlock', false); + ? await interaction.guild.channels.fetch( + interaction.options.getChannel('channel')!.id + ) + : interaction.channel; if ( !channel || channel.isDMBased() || @@ -235,36 +229,11 @@ const handlers = { !channel.isTextBased() ) { await interaction.editReply( - 'Error: cannot lock/unlock this channel.\nCause may be insufficient permissions or invalid channel type.' + 'Error: cannot lock this channel.\nCause may be insufficient permissions or invalid channel type.' ); return; } - if (!unlock) { - if (channel.isThread()) - await channel.setLocked(true, 'Channel locked by DisCog'); - else - await channel.permissionOverwrites.edit( - interaction.guild.roles.everyone, - { - AddReactions: false, - AttachFiles: false, - CreateInstantInvite: false, - CreatePrivateThreads: false, - CreatePublicThreads: false, - EmbedLinks: false, - ManageMessages: false, - ManageThreads: false, - ReadMessageHistory: true, - SendMessages: false, - SendMessagesInThreads: false, - SendTTSMessages: false, - SendVoiceMessages: false, - Speak: false, - UseApplicationCommands: false, - ViewChannel: true - } - ); - } else if (channel.isThread()) + if (channel.isThread()) await channel.setLocked(false, 'Channel locked by DisCog'); else await channel.permissionOverwrites.edit( @@ -289,11 +258,7 @@ const handlers = { } ); await interaction.editReply( - `Channel ${channel} has been ${unlock ? 'unlocked' : 'locked'}!${ - unlock - ? '\nAll permissions have been reset to predefined defaults.' - : '' - }` + `Channel ${channelMention(channel.id)} has been locked!` ); } } diff --git a/src/commands/bday.ts b/src/commands/bday.ts index 665e963..cb88835 100644 --- a/src/commands/bday.ts +++ b/src/commands/bday.ts @@ -8,6 +8,7 @@ import { import { CommandHelpEntry } from '../struct/CommandHelpEntry'; import { openKv } from '@deno/kv'; import { DENO_KV_URL, DatabaseKeys } from '../config'; +import { BirthdayData } from '../struct/database'; export const data = new SlashCommandBuilder() .setName('bday') @@ -32,14 +33,6 @@ export const data = new SlashCommandBuilder() .setMaxValue(31) .setRequired(true); }) - .addIntegerOption(option => { - return option - .setName('year') - .setDescription('Year of birth') - .setMinValue(1) - .setMaxValue(new Date().getFullYear()) - .setRequired(true); - }) ) .addSubcommand( new SlashCommandSubcommandBuilder() @@ -56,10 +49,7 @@ export const data = new SlashCommandBuilder() export const help = new CommandHelpEntry( 'bday', "Register your birthday or view another's", - [ - 'register ', - 'view [user: user || @self]' - ] + ['register ', 'view [user: user || @self]'] ); export const execute = async (interaction: ChatInputCommandInteraction) => { @@ -69,18 +59,13 @@ export const execute = async (interaction: ChatInputCommandInteraction) => { await interaction.deferReply({ ephemeral: true }); - const bday = new Date(); - bday.setFullYear( - interaction.options.getInteger('year', true), - interaction.options.getInteger('month', true) - 1, - interaction.options.getInteger('date', true) - ); - await db.set( - [DatabaseKeys.Bday, interaction.user.id], - bday.toLocaleDateString() - ); + const bday: BirthdayData = { + month: interaction.options.getInteger('month', true), + date: interaction.options.getInteger('date', true) + }; + await db.set([DatabaseKeys.Bday, interaction.user.id], bday); await interaction.editReply({ - content: `Your birthday is set to ${bday.toLocaleDateString()}` + content: `Your birthday is set to ${bday.month}/${bday.date}.` }); break; } @@ -89,14 +74,17 @@ export const execute = async (interaction: ChatInputCommandInteraction) => { await interaction.deferReply(); const id = interaction.options.getUser('user')?.id ?? interaction.user.id; - const ubday = (await db.get([DatabaseKeys.Bday, id])).value; + const ubday = (await db.get([DatabaseKeys.Bday, id])).value as + | BirthdayData + | undefined + | null; await interaction.editReply({ embeds: [ new EmbedBuilder() .setTitle('User Birthday') .setDescription( ubday - ? `${userMention(id)}'s birthday is on ${ubday}.` + ? `${userMention(id)}'s birthday is on ${ubday.month}/${ubday.date}.` : `${userMention(id)} has not registered their birthday.` ) .setFooter({ diff --git a/src/commands/donate.ts b/src/commands/donate.tsdisabled similarity index 89% rename from src/commands/donate.ts rename to src/commands/donate.tsdisabled index 32c8b96..cc3df6b 100644 --- a/src/commands/donate.ts +++ b/src/commands/donate.tsdisabled @@ -21,9 +21,7 @@ export const execute = async (interaction: ChatInputCommandInteraction) => { components: [ new ActionRowBuilder().setComponents( new ButtonBuilder() - .setURL( - 'https://sry-but-not-accepting-donations-rn-but-tysm-anyway.com' - ) + .setURL('https://discog.localplayer.dev/donate/') .setStyle(ButtonStyle.Link) .setLabel('Donate') ) diff --git a/src/index.ts b/src/index.ts index cac0b76..7e90abb 100644 --- a/src/index.ts +++ b/src/index.ts @@ -30,6 +30,7 @@ import { readdirSync } from 'fs'; import { scheduleJob } from 'node-schedule'; import { openKv } from '@deno/kv'; import { Jsoning } from 'jsoning'; +import { BirthdayData } from './struct/database'; argv.shift(); argv.shift(); @@ -299,17 +300,18 @@ logger.debug('Set up error handling.'); logger.info('Process setup complete.'); async function bdayInterval() { - const db = new Jsoning('botfiles/bday.db.json'); const today = new Date(); - const allBirthdays = Object.entries(db.all()); - const birthdaysToday = allBirthdays.filter(([, bday]) => { - const bdaydate = new Date(bday); - return ( - bdaydate.getMonth() == today.getMonth() && - bdaydate.getDate() == today.getDate() - ); - }); - for (const [id] of birthdaysToday) { + const allBirthdays: { id: string; data: BirthdayData }[] = []; + for await (const val of db.list({ prefix: [DatabaseKeys.Bday] })) + allBirthdays.push({ + id: val.key[1].toString(), + data: val.value as BirthdayData + }); + const birthdaysToday = allBirthdays.filter( + ({ data }) => + data.month == today.getMonth() + 1 && data.date == today.getDate() + ); + for (const { id } of birthdaysToday) { const user = await client.users.fetch(id); for (let guild of client.guilds.cache.values()) { guild = await guild.fetch(); diff --git a/src/struct/database.ts b/src/struct/database.ts index 913d153..77c1610 100644 --- a/src/struct/database.ts +++ b/src/struct/database.ts @@ -76,3 +76,8 @@ export interface PopulatedGuildConfig extends BaseGuildConfig { }; systemchannel: Snowflake | null; } + +export interface BirthdayData { + month: number; + date: number; +} diff --git a/tsconfig.json b/tsconfig.json index a6d5f27..c1d095a 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -7,7 +7,7 @@ "strict": true, "skipLibCheck": true, "target": "ESNext", - "lib": ["ESNext", "ES2022"], + "lib": ["ESNext", "ES2022", "ES5", "ES6"], "noEmit": true, "resolveJsonModule": true, "isolatedModules": true,