From e17c7601daaab66b47c59d31a0162f89094294a1 Mon Sep 17 00:00:00 2001 From: mightypanders Date: Sun, 16 Apr 2023 02:01:56 +0200 Subject: [PATCH] delete unused files --- server/commands/pong.ts | 9 -- server/constants.ts | 52 ---------- server/eventHandler.ts | 33 ------- server/handler/repeatingEvents/helper.ts | 119 ----------------------- 4 files changed, 213 deletions(-) delete mode 100644 server/commands/pong.ts delete mode 100644 server/constants.ts delete mode 100644 server/eventHandler.ts delete mode 100644 server/handler/repeatingEvents/helper.ts diff --git a/server/commands/pong.ts b/server/commands/pong.ts deleted file mode 100644 index e74b626..0000000 --- a/server/commands/pong.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { Command } from '../structures/command' -export default new Command({ - name: 'ping', - description: 'Does a pong, duh', - run: async ({ interaction }) => { - console.log(`Ping interaction received.`) - interaction.followUp('pong') - } -}) diff --git a/server/constants.ts b/server/constants.ts deleted file mode 100644 index 2e0d3ec..0000000 --- a/server/constants.ts +++ /dev/null @@ -1,52 +0,0 @@ -import { localized_string } from "./interfaces" - -export const reactions = { - troll_grin: "U+1F92A", - angry_face: "U+1F621", - ok: "U+1F44C" -} -export const commands = { - LIST_COMMAND: "list", - REGISTER_COMMAND: "register", - REMOVE_COMMAND: "remove", - SHOW_FOR_STEAM_COMMAND: "forsteam", - SHOW_COMMAND: "show" -} -export const msg_strings: localized_string = { - greeting: { - german: "Ich wurde neugestartet. Bitte registriert euch erneut, falls ihr automatisch gemutet werden wollt :)", - english: "I have been restarted. Please register again if you want to be muted automatically :)" - }, - fmt_registered_user: { - german: "Habe den Steamname {steam_name} mit dem Discordnamen {discord_name} verknüpft.", - english: "Registered the steam name {steam_name} for the discord name {discord_name}." - }, - fmt_registered_for_steam: { - german: "Aktuell registriert für User {steam_name}: {discord_name}", - english: "Currently registered for user {steam_name}: {discord_name}" - }, - fmt_registered_for_discord: { - german: "Aktuell registriert für User {discord_name}: {steam_name}", - english: "Currently registered for user {discord_name}: {steam_name}" - }, - user_was_not_registered: { - german: "Du warst gar nicht registriert.", - english: "You weren't even registered.", - }, - user_has_been_removed: { - german: "Du wurdest aus der Liste entfernt.", - english: "You were removed from the list.", - }, - currently_registered: { - german: "Aktuell registriert: \n {playerlist}", - english: "Currently registered: \n {playerlist}" - }, - troll_rejection: { - german: "Nöööö, du nicht...", - english: "Naaaah, not you..." - }, - troll_rejection_second_part: { - german: "Spaß, hab dich registriert: :P", - english: "Just kidding, you are registered: :P" - } -} diff --git a/server/eventHandler.ts b/server/eventHandler.ts deleted file mode 100644 index 77b8148..0000000 --- a/server/eventHandler.ts +++ /dev/null @@ -1,33 +0,0 @@ -import { Collection, Guild, GuildScheduledEvent, Snowflake } from "discord.js"; - -export default class eventHandler { - - public constructor() { - console.log('constructed') - } - public getNextEvent(guild: Guild): string { - const eventManager = guild.scheduledEvents - const events = eventManager.cache - const sortedEvents = events.sort(function(a, b) { return Number(a.scheduledStartAt) - Number(b.scheduledStartAt) }) - - console.log(JSON.stringify(events)) - console.log(JSON.stringify(sortedEvents)) - - return sortedEvents.first()?.toString() ?? "" - } - public listAllEvents(guild: Guild): string { - - const eventManager = guild.scheduledEvents - const events: Collection = eventManager.cache - const entries = events.values() - let output = "" - - for (const e of entries) { - console.log(e) - output += "\n" - output += e.toString() - } - console.log(output) - return output - } -} diff --git a/server/handler/repeatingEvents/helper.ts b/server/handler/repeatingEvents/helper.ts deleted file mode 100644 index 4c2e4b7..0000000 --- a/server/handler/repeatingEvents/helper.ts +++ /dev/null @@ -1,119 +0,0 @@ -import { format } from "date-fns" -import { Guild, GuildScheduledEvent, GuildScheduledEventCreateOptions } from "discord.js" -import { sendFailureDM } from "../../helper/sendFailureDM" -import { CustomError, errorCodes, Maybe } from "../../interfaces" -import { RepetitonInfo, Schedule, supportedSchedule } from "../../types/scheduledEventTypes" - -export const repetitionMarkerIsFound = (desc: string): boolean => desc.includes('$rep') -export function createEventInGuild(guild: Guild, eventInfo: GuildScheduledEventCreateOptions): Promise { - return guild.scheduledEvents.create(eventInfo) -} -export function getRepetitonInfo(description: string): RepetitonInfo { - - const lines = description.split(`\n`) - const repetitionString = lines.find(x => x.startsWith('$rep:')) - if (!repetitionString) - throw new CustomError('Cant find repetition string', errorCodes.no_string_present) - const scheduleString = determineScheduleString(repetitionString) - const schedule: Schedule = new Schedule(scheduleString) - const { totalAmount, alreadyOccured } = determineRepetitionCount(repetitionString) - const endDate = determineEndDate(repetitionString) - return { - totalAmount, - alreadyOccured, - schedule, - endDate - } -} - -export function determineScheduleString(repetitionLine: string): supportedSchedule { - const segments = repetitionLine.split(':') - const scheduleSegment = segments[1] - if (scheduleSegment) - return scheduleSegment - else - throw new CustomError('No schedule segment found', errorCodes.no_schedule) -} - -export function determineRepetitionCount(description: string): { totalAmount: number; alreadyOccured: number } { - const segments = description.split(':') - const amountSegment = segments[2] - if (amountSegment) { - const amounts = amountSegment.split('/') - return { totalAmount: Number(amounts[1]) ?? 0, alreadyOccured: Number(amounts[0]) ?? 0 } - } else { - throw new CustomError('No amount was defined', errorCodes.no_repetition_amount) - } -} - -export function buildNewRepetitionString(repetitionInfo: RepetitonInfo) { - if (repetitionInfo.endDate) - return `$rep:${repetitionInfo.schedule.getSanitizedScheduleString()}:${format(repetitionInfo.endDate, 'yyyy-MM-dd')}` - return `$rep:${repetitionInfo.schedule.getSanitizedScheduleString()}:${repetitionInfo.alreadyOccured + 1}/${repetitionInfo.totalAmount}` -} - -export function addRepetitonStringToEventDescription(oldguildScheduledEvent: string, newRepetitonString: string): string | undefined { - const lines = oldguildScheduledEvent.split(`\n`) - const repLineIndex = lines.findIndex(x => x.startsWith('$rep:')) - const newLines = lines.filter((_, index) => repLineIndex !== index) - newLines.push(newRepetitonString) - return newLines.join('\n') -} - -function determineEndDate(description: string): Maybe { - const segments = description.split(':') - if (segments.length === 3) { - // rep:sched:countOrDate - const segmentValue = segments[2] - if (segmentValue.includes('/')) { - if (segmentValue.match(/\//g) || [].length !== 2) { - return - } - } - const dateValue = new Date(segmentValue) - return dateValue - } - else if (segments.length === 4) { - // rep:sched:count:date - const segmentValue = segments[3] - const dateValue = new Date(segmentValue) - return dateValue - } - return -} -export function checkIfRepetitionStringIsValid(description: string): string { - if (!description) return 'not_present' - if (repetitionMarkerIsFound(description)) { - let repetitionInfo - try { - repetitionInfo = getRepetitonInfo(description) - if (!repetitionInfo.schedule) return 'no_schedule' - if (!repetitionInfo.totalAmount && !repetitionInfo.alreadyOccured && !repetitionInfo.endDate) { - if (!repetitionInfo.totalAmount || !repetitionInfo.alreadyOccured) return 'no_amount' - if (!repetitionInfo.endDate) return 'no_end' - } - return 'valid' - } catch (error) { - if (error instanceof CustomError) { - return error.getCode() - } - return 'invalid' - } - } return 'not_present' -} - -export async function validateRepetitionStringAndSendMessageOnFail(event: GuildScheduledEvent): Promise { - console.log('This should not be accessed') - - const validResponses = [ - 'valid', - 'not_present' - ] - const resultstring: string = checkIfRepetitionStringIsValid(event.description ?? "") - if (validResponses.includes(resultstring)) { - // do success things? - } else { - const creatorMessage = `The repetition string in your event could not be parsed. Reason: ${resultstring}` - sendFailureDM(creatorMessage, event.creatorId ?? undefined) - } -}