From 4279d9187033c7a7e2df04b4546913661b24c753 Mon Sep 17 00:00:00 2001 From: astridlol Date: Wed, 1 Nov 2023 13:36:30 -0400 Subject: [PATCH] chore: removed unused things --- src/guards/PreventBots.ts | 9 ----- src/guards/RequireGuildMember.ts | 23 ------------ src/guards/RequirePermission.ts | 34 ------------------ src/lib/General.ts | 35 +----------------- src/lib/Punishments.ts | 62 -------------------------------- src/lib/Time.ts | 29 --------------- 6 files changed, 1 insertion(+), 191 deletions(-) delete mode 100644 src/guards/PreventBots.ts delete mode 100644 src/guards/RequireGuildMember.ts delete mode 100644 src/guards/RequirePermission.ts delete mode 100644 src/lib/Punishments.ts delete mode 100644 src/lib/Time.ts diff --git a/src/guards/PreventBots.ts b/src/guards/PreventBots.ts deleted file mode 100644 index 8c163b1..0000000 --- a/src/guards/PreventBots.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { GuardFunction, ArgsOf } from 'discordx'; - -export const PreventBots: GuardFunction> = async ( - [message], - client, - next -) => { - if (client.user.id !== message.author.id) await next(); -}; diff --git a/src/guards/RequireGuildMember.ts b/src/guards/RequireGuildMember.ts deleted file mode 100644 index 7ef5c95..0000000 --- a/src/guards/RequireGuildMember.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { CommandInteraction, EmbedBuilder } from 'discord.js'; -import { GuardFunction } from 'discordx'; -import Colors from '../constants/Colors'; - -export const RequireGuildMember: GuardFunction = async ( - interaction, - _, - next -) => { - const member = interaction.options.get('member'); - - if (member !== null) return await next(); - - const embed = new EmbedBuilder() - .setColor(Colors.red) - .setTitle('Uh oh!') - .setDescription(`The member you've specified isn't here.`); - - interaction.reply({ - embeds: [embed], - ephemeral: true - }); -}; diff --git a/src/guards/RequirePermission.ts b/src/guards/RequirePermission.ts deleted file mode 100644 index 57115c6..0000000 --- a/src/guards/RequirePermission.ts +++ /dev/null @@ -1,34 +0,0 @@ -import { - CommandInteraction, - EmbedBuilder, - PermissionResolvable, - PermissionsBitField, - StringSelectMenuInteraction, - inlineCode -} from 'discord.js'; -import { GuardFunction } from 'discordx'; -import Colors from '../constants/Colors'; -import { prettify } from '../lib/General'; - -export function RequirePermission(permission: PermissionResolvable) { - const guard: GuardFunction = async ( - interaction, - _, - next - ) => { - const permissions = interaction.member.permissions as Readonly; - - if (permissions.has(permission)) return await next(); - - const _perm = prettify(permission.toString()); - - const noPerrmission = new EmbedBuilder().setColor(Colors.red).setTitle('You lack permission'); - noPerrmission.setDescription(`This command requires the ${inlineCode(_perm)} permission`); - interaction.reply({ - embeds: [noPerrmission], - ephemeral: true - }); - }; - - return guard; -} diff --git a/src/lib/General.ts b/src/lib/General.ts index 5706eac..643a59c 100644 --- a/src/lib/General.ts +++ b/src/lib/General.ts @@ -1,5 +1,3 @@ -import { APIEmbed } from 'discord.js'; - const prettify = (s: string, titleCase: boolean = false) => { let newString = s.replace(/(_|-)/gi, ' '); newString = newString.charAt(0).toUpperCase() + newString.slice(1); @@ -11,35 +9,4 @@ const prettify = (s: string, titleCase: boolean = false) => { .join(' '); }; -function replacePlaceholders( - s: string, - map: Map, - characters: string = '%%' -): string { - let placeholded = s; - - for (const [key, value] of map.entries()) { - const regex = new RegExp(`${characters[0]}${key}${characters[1]}`, 'g'); - placeholded = placeholded.replace(regex, value); - } - - return placeholded; -} - -function parseEmbed(obj: APIEmbed, map: Map): APIEmbed { - const result: APIEmbed = {}; - - for (const key in obj) { - if (Object.prototype.hasOwnProperty.call(obj, key)) { - if (key === 'color') { - result[key] = obj[key]; - continue; - } - result[key] = replacePlaceholders(obj[key], map); - } - } - - return result; -} - -export { prettify, replacePlaceholders, parseEmbed }; +export { prettify }; diff --git a/src/lib/Punishments.ts b/src/lib/Punishments.ts deleted file mode 100644 index 1b836a4..0000000 --- a/src/lib/Punishments.ts +++ /dev/null @@ -1,62 +0,0 @@ -import { GuildMember } from 'discord.js'; -import { prisma } from '..'; -import { convertDate, convertSeconds } from './Time'; - -export async function executePunishment(user: GuildMember) { - async function applyBan(points: number, duration?: number) { - user.ban({ - reason: `Reached ${points} violation points` - }); - await prisma.member.update({ - where: { - id: user.id - }, - data: { - punishedUntil: convertDate(`${duration}d`) - } - }); - } - - const violationLevels = [ - { threshold: 280, action: applyBan, duration: 90 }, - { threshold: 250, action: applyBan, duration: 60 }, - { threshold: 180, action: applyBan, duration: 30 }, - { threshold: 120, action: applyBan, duration: 14 }, - { - threshold: 80, - action: () => { - user.ban({ - reason: `Soft-banned for reaching 80 violation points`, - deleteMessageSeconds: 3600 // 1 hour - }); - } - }, - { - threshold: 50, - action: () => { - user.timeout(convertSeconds('3h'), 'Reached 50 violation points'); - } - }, - { - threshold: 20, - action: () => { - user.timeout(convertSeconds('1h'), 'Reached 20 violation points'); - } - } - ]; - - const member = await prisma.member.findUnique({ - where: { - id: user.id - } - }); - - for (const { threshold, action, duration } of violationLevels) { - if (member.points >= threshold) { - console.log(`executing punishment for ${threshold}`); - if (duration) await action(threshold, duration); - else await action(threshold); - return; - } - } -} diff --git a/src/lib/Time.ts b/src/lib/Time.ts deleted file mode 100644 index e314f47..0000000 --- a/src/lib/Time.ts +++ /dev/null @@ -1,29 +0,0 @@ -function convertTime(input: string, returnEpoch: boolean = true): number { - const [numericValue, timeUnit]: string[] = input.match(/\d+|\D+/g) || []; - - const timeUnitInMillis: { [key: string]: number } = { - s: 1000, - m: 1000 * 60, - h: 1000 * 60 * 60, - d: 1000 * 60 * 60 * 24 - }; - - const valueInMillis = timeUnitInMillis[timeUnit]; - - if (!valueInMillis) { - throw new Error('Invalid time unit specified'); - } - - const futureTimestamp = parseInt(numericValue) * valueInMillis; - return returnEpoch ? Date.now() + futureTimestamp : futureTimestamp; -} - -function convertDate(input: string): number { - return convertTime(input); -} - -function convertSeconds(input: string): number { - return convertTime(input, false); -} - -export { convertDate, convertSeconds };