Skip to content

Commit

Permalink
Moved all collection functions off the client class
Browse files Browse the repository at this point in the history
  • Loading branch information
CuteNikki committed Sep 17, 2024
1 parent c88a6d6 commit 435f547
Show file tree
Hide file tree
Showing 138 changed files with 837 additions and 618 deletions.
4 changes: 3 additions & 1 deletion src/buttons/general/ping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ import { t } from 'i18next';

import { Button } from 'classes/button';

import { getUserLanguage } from 'db/user';

export default new Button({
customId: 'button-ping-update',
isAuthorOnly: false,
isCustomIdIncluded: false,
permissions: [],
botPermissions: ['SendMessages'],
async execute({ interaction, client }) {
const lng = await client.getUserLanguage(interaction.user.id);
const lng = await getUserLanguage(interaction.user.id);

const sent = await interaction.update({
content: t('ping.pinging', { lng }),
Expand Down
5 changes: 3 additions & 2 deletions src/buttons/moderation/ban.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { t } from 'i18next';
import { Button } from 'classes/button';

import { infractionModel, InfractionType } from 'models/infraction';
import { getUserLanguage } from 'db/user';

import { logger } from 'utils/logger';

Expand All @@ -19,11 +20,11 @@ export default new Button({
const targetId = interaction.customId.split('_')[1];
const target = await client.users.fetch(targetId).catch((err) => logger.debug({ err, targetId }, 'Could not fetch user'));

const lng = await client.getUserLanguage(interaction.user.id);
const lng = await getUserLanguage(interaction.user.id);

if (!target) return interaction.reply(t('ban.failed', { lng }));

const targetLng = await client.getUserLanguage(targetId);
const targetLng = await getUserLanguage(targetId);
const reason = 'Suspicious Account';

const banned = await guild.bans
Expand Down
5 changes: 3 additions & 2 deletions src/buttons/moderation/kick.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { t } from 'i18next';
import { Button } from 'classes/button';

import { infractionModel, InfractionType } from 'models/infraction';
import { getUserLanguage } from 'db/user';

import { logger } from 'utils/logger';

Expand All @@ -19,10 +20,10 @@ export default new Button({
const targetId = interaction.customId.split('_')[1];
const targetMember = await guild.members.fetch(targetId).catch((err) => logger.debug({ err, targetId }, 'Could not fetch user'));

const lng = await client.getUserLanguage(interaction.user.id);
const lng = await getUserLanguage(interaction.user.id);

if (!targetMember) return interaction.reply(t('kick.target.invalid', { lng }));
const targetLng = await client.getUserLanguage(targetId);
const targetLng = await getUserLanguage(targetId);
const reason = 'Suspicious Account';

const kicked = await targetMember.kick(reason).catch((err) => logger.debug({ err, targetId }, 'Could not kick user'));
Expand Down
6 changes: 4 additions & 2 deletions src/buttons/ticket/claim.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import { t } from 'i18next';

import { Button } from 'classes/button';

import { ticketModel } from 'models/ticket';
import { getGuildSettings } from 'db/guild';

export default new Button({
customId: 'button-tickets-claim',
isCustomIdIncluded: true,
permissions: [],
botPermissions: ['SendMessages'],
async execute({ client, interaction }) {
async execute({ interaction }) {
if (!interaction.inCachedGuild() || !interaction.channelId) return;
const { user, guildId, channelId, customId } = interaction;

const currentConfig = await client.getGuildSettings(guildId);
const currentConfig = await getGuildSettings(guildId);
const lng = currentConfig.language;

const system = currentConfig.ticket.systems.find((system) => system._id.toString() === customId.split('_')[1]);
Expand Down
5 changes: 3 additions & 2 deletions src/buttons/ticket/close.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { t } from 'i18next';
import { Button } from 'classes/button';

import { ticketModel } from 'models/ticket';
import { getGuildSettings } from 'db/guild';

import { logger } from 'utils/logger';

Expand All @@ -12,11 +13,11 @@ export default new Button({
isCustomIdIncluded: true,
permissions: [],
botPermissions: ['ManageChannels', 'SendMessages'],
async execute({ interaction, client }) {
async execute({ interaction }) {
if (!interaction.inCachedGuild() || !interaction.channelId) return;
const { user, guildId, channelId, customId } = interaction;

const currentConfig = await client.getGuildSettings(guildId);
const currentConfig = await getGuildSettings(guildId);
const lng = currentConfig.language;

const system = currentConfig.ticket.systems.find((system) => system._id.toString() === customId.split('_')[1]);
Expand Down
5 changes: 3 additions & 2 deletions src/buttons/ticket/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { t } from 'i18next';
import { Button } from 'classes/button';

import { ticketModel } from 'models/ticket';
import { getGuildSettings } from 'db/guild';

import { logger } from 'utils/logger';

Expand All @@ -12,14 +13,14 @@ export default new Button({
isCustomIdIncluded: true,
permissions: [],
botPermissions: ['ManageChannels', 'SendMessages'],
async execute({ interaction, client }) {
async execute({ interaction }) {
if (!interaction.inCachedGuild()) return;
await interaction.deferReply({ ephemeral: true });
const { user, guildId, customId, guild } = interaction;

const choiceIndex = parseInt(customId.split('_')[2]);

const currentConfig = await client.getGuildSettings(guildId);
const currentConfig = await getGuildSettings(guildId);
const lng = currentConfig.language;

const system = currentConfig.ticket.systems.find((system) => system._id.toString() === customId.split('_')[1]);
Expand Down
5 changes: 3 additions & 2 deletions src/buttons/ticket/delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { t } from 'i18next';
import { Button } from 'classes/button';

import { ticketModel } from 'models/ticket';
import { getGuildSettings } from 'db/guild';

import { logger } from 'utils/logger';

Expand All @@ -12,11 +13,11 @@ export default new Button({
isCustomIdIncluded: true,
permissions: [],
botPermissions: ['ManageChannels', 'SendMessages'],
async execute({ interaction, client }) {
async execute({ interaction }) {
if (!interaction.inCachedGuild()) return;
const { guildId, channelId, customId } = interaction;

const currentConfig = await client.getGuildSettings(guildId);
const currentConfig = await getGuildSettings(guildId);
const lng = currentConfig.language;

const system = currentConfig.ticket.systems.find((system) => system._id.toString() === customId.split('_')[1]);
Expand Down
5 changes: 3 additions & 2 deletions src/buttons/ticket/lock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { t } from 'i18next';
import { Button } from 'classes/button';

import { ticketModel } from 'models/ticket';
import { getGuildSettings } from 'db/guild';

import { logger } from 'utils/logger';

Expand All @@ -12,11 +13,11 @@ export default new Button({
isCustomIdIncluded: true,
permissions: [],
botPermissions: ['ManageChannels', 'SendMessages'],
async execute({ interaction, client }) {
async execute({ interaction }) {
if (!interaction.inCachedGuild()) return;
const { user, guildId, channelId, customId } = interaction;

const currentConfig = await client.getGuildSettings(guildId);
const currentConfig = await getGuildSettings(guildId);
const lng = currentConfig.language;

const system = currentConfig.ticket.systems.find((system) => system._id.toString() === customId.split('_')[1]);
Expand Down
5 changes: 3 additions & 2 deletions src/buttons/ticket/save.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { t } from 'i18next';
import { Button } from 'classes/button';

import { ticketModel } from 'models/ticket';
import { getGuildSettings } from 'db/guild';

import { logger } from 'utils/logger';

Expand All @@ -13,11 +14,11 @@ export default new Button({
isCustomIdIncluded: true,
permissions: [],
botPermissions: ['SendMessages'],
async execute({ interaction, client }) {
async execute({ interaction }) {
if (!interaction.inCachedGuild()) return;
const { guildId, customId } = interaction;

const currentConfig = await client.getGuildSettings(guildId);
const currentConfig = await getGuildSettings(guildId);
const lng = currentConfig.language;

const system = currentConfig.ticket.systems.find((system) => system._id.toString() === customId.split('_')[1]);
Expand Down
5 changes: 3 additions & 2 deletions src/buttons/ticket/unlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { t } from 'i18next';
import { Button } from 'classes/button';

import { ticketModel } from 'models/ticket';
import { getGuildSettings } from 'db/guild';

import { logger } from 'utils/logger';

Expand All @@ -12,11 +13,11 @@ export default new Button({
isCustomIdIncluded: true,
permissions: [],
botPermissions: ['ManageChannels', 'SendMessages'],
async execute({ interaction, client }) {
async execute({ interaction }) {
if (!interaction.inCachedGuild()) return;
const { guildId, customId } = interaction;

const currentConfig = await client.getGuildSettings(guildId);
const currentConfig = await getGuildSettings(guildId);
const lng = currentConfig.language;

const system = currentConfig.ticket.systems.find((system) => system._id.toString() === customId.split('_')[1]);
Expand Down
6 changes: 4 additions & 2 deletions src/buttons/welcome/add-role.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ import { t } from 'i18next';

import { Button } from 'classes/button';

import { getUserLanguage } from 'db/user';

export default new Button({
customId: 'button-welcome-add-role',
permissions: ['ManageGuild'],
isAuthorOnly: true,
async execute({ client, interaction }) {
const lng = await client.getUserLanguage(interaction.user.id);
async execute({ interaction }) {
const lng = await getUserLanguage(interaction.user.id);

await interaction.showModal(
new ModalBuilder()
Expand Down
6 changes: 4 additions & 2 deletions src/buttons/welcome/remove-role.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ import { t } from 'i18next';

import { Button } from 'classes/button';

import { getUserLanguage } from 'db/user';

export default new Button({
customId: 'button-welcome-remove-role',
permissions: ['ManageGuild'],
isAuthorOnly: true,
async execute({ client, interaction }) {
async execute({ interaction }) {
if (!interaction.inCachedGuild()) return;
const lng = await client.getUserLanguage(interaction.user.id);
const lng = await getUserLanguage(interaction.user.id);

await interaction.showModal(
new ModalBuilder()
Expand Down
15 changes: 9 additions & 6 deletions src/commands/config/counting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import { t } from 'i18next';

import { Command, ModuleType } from 'classes/command';

import { getUserLanguage } from 'db/user';
import { getGuildSettings, updateGuildSettings } from 'db/guild';

export default new Command({
module: ModuleType.Config,
data: new SlashCommandBuilder()
Expand Down Expand Up @@ -36,8 +39,8 @@ export default new Command({
await interaction.deferReply();
const { options, guildId } = interaction;

const lng = await client.getUserLanguage(interaction.user.id);
const config = await client.getGuildSettings(guildId);
const lng = await getUserLanguage(interaction.user.id);
const config = await getGuildSettings(guildId);

switch (options.getSubcommand()) {
case 'setup':
Expand All @@ -56,7 +59,7 @@ export default new Command({
});
}

await client.updateGuildSettings(guildId, {
await updateGuildSettings(guildId, {
$set: {
counting: {
channelId: channel.id,
Expand Down Expand Up @@ -117,15 +120,15 @@ export default new Command({
let response = '';

if (channel && channel.id !== config.counting.channelId) {
await client.updateGuildSettings(guildId, {
await updateGuildSettings(guildId, {
$set: {
['counting.channelId']: channel.id,
},
});
response += t('counting.edit_channel', { lng, channel: `<#${channel.id}>` });
}
if (resetOnFail !== null && resetOnFail !== config.counting.resetOnFail) {
await client.updateGuildSettings(guildId, {
await updateGuildSettings(guildId, {
$set: {
['counting.resetOnFail']: resetOnFail,
},
Expand All @@ -152,7 +155,7 @@ export default new Command({
});
}

await client.updateGuildSettings(guildId, {
await updateGuildSettings(guildId, {
$set: {
['counting.channelId']: null,
['counting.resetOnFail']: false,
Expand Down
18 changes: 11 additions & 7 deletions src/commands/config/custom-voice-setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import { t } from 'i18next';

import { Command, ModuleType } from 'classes/command';

import { getUserLanguage } from 'db/user';
import { getGuildSettings, updateGuildSettings } from 'db/guild';
import { getCustomVoiceChannelsByGuild } from 'db/voice';

export default new Command({
module: ModuleType.Config,
botPermissions: ['ManageChannels', 'MoveMembers'],
Expand Down Expand Up @@ -35,8 +39,8 @@ export default new Command({
async execute({ client, interaction }) {
if (!interaction.inCachedGuild()) return;

const lng = await client.getUserLanguage(interaction.user.id);
const config = await client.getGuildSettings(interaction.guildId);
const lng = await getUserLanguage(interaction.user.id);
const config = await getGuildSettings(interaction.guildId);

switch (interaction.options.getSubcommand()) {
case 'channel':
Expand All @@ -48,15 +52,15 @@ export default new Command({
}

if (!channel) {
await client.updateGuildSettings(interaction.guild.id, { $unset: { ['customVC.channelId']: 1 } });
await updateGuildSettings(interaction.guild.id, { $unset: { ['customVC.channelId']: 1 } });
return interaction.reply({ embeds: [new EmbedBuilder().setColor(client.colors.customVC).setDescription(t('custom_vc.channel.removed', { lng }))] });
}

if (channel.id === config.customVC.channelId) {
return interaction.reply({ embeds: [new EmbedBuilder().setColor(client.colors.error).setDescription(t('custom_vc.channel.already', { lng }))] });
}

await client.updateGuildSettings(interaction.guild.id, { $set: { ['customVC.channelId']: channel.id } });
await updateGuildSettings(interaction.guild.id, { $set: { ['customVC.channelId']: channel.id } });
interaction.reply({ embeds: [new EmbedBuilder().setColor(client.colors.customVC).setDescription(t('custom_vc.channel.success', { lng, channel }))] });
}
break;
Expand All @@ -69,21 +73,21 @@ export default new Command({
}

if (!channel) {
await client.updateGuildSettings(interaction.guild.id, { $unset: { ['customVC.parentId']: 1 } });
await updateGuildSettings(interaction.guild.id, { $unset: { ['customVC.parentId']: 1 } });
return interaction.reply({ embeds: [new EmbedBuilder().setColor(client.colors.customVC).setDescription(t('custom_vc.parent.removed', { lng }))] });
}

if (channel.id === config.customVC.parentId) {
return interaction.reply({ embeds: [new EmbedBuilder().setColor(client.colors.error).setDescription(t('custom_vc.parent.already', { lng }))] });
}

await client.updateGuildSettings(interaction.guild.id, { $set: { ['customVC.parentId']: channel.id } });
await updateGuildSettings(interaction.guild.id, { $set: { ['customVC.parentId']: channel.id } });
interaction.reply({ embeds: [new EmbedBuilder().setColor(client.colors.customVC).setDescription(t('custom_vc.parent.success', { lng }))] });
}
break;
case 'info':
{
const channels = await client.getCustomVoiceChannelsByGuild(interaction.guild.id);
const channels = await getCustomVoiceChannelsByGuild(interaction.guild.id);

interaction.reply({
embeds: [
Expand Down
Loading

0 comments on commit 435f547

Please sign in to comment.