Skip to content

Commit

Permalink
overhaul
Browse files Browse the repository at this point in the history
  • Loading branch information
akpi816218 committed Apr 3, 2024
1 parent a44c416 commit c759e84
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 91 deletions.
10 changes: 1 addition & 9 deletions src/commands/about.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')}`
)}.`
)
]
});
Expand Down
51 changes: 8 additions & 43 deletions src/commands/admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
PermissionFlagsBits,
SlashCommandBuilder,
bold,
channelMention,
roleMention,
underscore,
userMention
Expand Down Expand Up @@ -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);
});
});
});
Expand Down Expand Up @@ -223,48 +218,22 @@ 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() ||
channel.isVoiceBased() ||
!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(
Expand All @@ -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!`
);
}
}
Expand Down
38 changes: 13 additions & 25 deletions src/commands/bday.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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()
Expand All @@ -56,10 +49,7 @@ export const data = new SlashCommandBuilder()
export const help = new CommandHelpEntry(
'bday',
"Register your birthday or view another's",
[
'register <month: number> <day: number> <year: number>',
'view [user: user || @self]'
]
['register <month: number> <day: number>', 'view [user: user || @self]']
);

export const execute = async (interaction: ChatInputCommandInteraction) => {
Expand All @@ -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;
}
Expand All @@ -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({
Expand Down
4 changes: 1 addition & 3 deletions src/commands/donate.ts → src/commands/donate.tsdisabled
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ export const execute = async (interaction: ChatInputCommandInteraction) => {
components: [
new ActionRowBuilder<ButtonBuilder>().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')
)
Expand Down
22 changes: 12 additions & 10 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down
5 changes: 5 additions & 0 deletions src/struct/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,8 @@ export interface PopulatedGuildConfig extends BaseGuildConfig {
};
systemchannel: Snowflake | null;
}

export interface BirthdayData {
month: number;
date: number;
}
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"strict": true,
"skipLibCheck": true,
"target": "ESNext",
"lib": ["ESNext", "ES2022"],
"lib": ["ESNext", "ES2022", "ES5", "ES6"],
"noEmit": true,
"resolveJsonModule": true,
"isolatedModules": true,
Expand Down

0 comments on commit c759e84

Please sign in to comment.