send dm on failure to parse
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
parent
9ae406dfb3
commit
f8afee69bd
@ -1,7 +1,6 @@
|
||||
import { format } from "date-fns"
|
||||
import add from "date-fns/add"
|
||||
import { DateResolvable, Guild, GuildScheduledEvent, GuildScheduledEventCreateOptions } from "discord.js"
|
||||
import { client } from "../../.."
|
||||
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"
|
||||
|
||||
@ -49,8 +48,8 @@ export function determineRepetitionCount(description: string): { totalAmount: nu
|
||||
|
||||
export function buildNewRepetitionString(repetitionInfo: RepetitonInfo) {
|
||||
if (repetitionInfo.endDate)
|
||||
return `$rep:${repetitionInfo.schedule}:${format(repetitionInfo.endDate, 'yyyy-MM-dd')}`
|
||||
return `$rep:${repetitionInfo.schedule}:${repetitionInfo.alreadyOccured + 1}/${repetitionInfo.totalAmount}`
|
||||
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 {
|
||||
@ -104,6 +103,7 @@ export function checkIfRepetitionStringIsValid(description: string): string {
|
||||
}
|
||||
|
||||
export async function validateRepetitionStringAndSendMessageOnFail(event: GuildScheduledEvent): Promise<void> {
|
||||
console.log('This should not be accessed')
|
||||
|
||||
const validResponses = [
|
||||
'valid',
|
||||
@ -114,13 +114,6 @@ export async function validateRepetitionStringAndSendMessageOnFail(event: GuildS
|
||||
// do success things?
|
||||
} else {
|
||||
const creatorMessage = `The repetition string in your event could not be parsed. Reason: ${resultstring}`
|
||||
console.log(creatorMessage)
|
||||
if (!event.creatorId) throw new CustomError('No creator ID present', errorCodes.no_creator_id)
|
||||
const creator = await client.users.fetch(event.creatorId)
|
||||
console.log(`Creator ${JSON.stringify(creator)}`)
|
||||
if (creator)
|
||||
if (!creator.dmChannel)
|
||||
await creator.createDM()
|
||||
await creator.dmChannel?.send(creatorMessage)
|
||||
sendFailureDM(creatorMessage, event.creatorId ?? undefined)
|
||||
}
|
||||
}
|
||||
|
12
server/helper/sendFailureDM.ts
Normal file
12
server/helper/sendFailureDM.ts
Normal file
@ -0,0 +1,12 @@
|
||||
import { client } from "../.."
|
||||
import { CustomError, errorCodes } from "../interfaces"
|
||||
|
||||
export async function sendFailureDM(creatorMessage: string, creatorId?: string): Promise<void> {
|
||||
if (!creatorId) throw new CustomError('No creator ID present', errorCodes.no_creator_id)
|
||||
const creator = await client.users.fetch(creatorId)
|
||||
console.log(`Creator ${JSON.stringify(creator)}`)
|
||||
if (creator)
|
||||
if (!creator.dmChannel)
|
||||
await creator.createDM()
|
||||
await creator.dmChannel?.send(creatorMessage)
|
||||
}
|
@ -66,6 +66,9 @@ export class Schedule {
|
||||
throw new CustomError('Schedule type not supported', errorCodes.schedule_not_supported)
|
||||
}
|
||||
}
|
||||
public getSanitizedScheduleString(): string {
|
||||
return this._scheduleString
|
||||
}
|
||||
private getBaseScheduleNameFromVariableString(): string {
|
||||
if (this._scheduleString.includes('week')) return 'weekly'
|
||||
if (this._scheduleString.includes('day')) return 'daily'
|
||||
|
Loading…
Reference in New Issue
Block a user