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 { format } from "date-fns"
|
||||||
import add from "date-fns/add"
|
import { Guild, GuildScheduledEvent, GuildScheduledEventCreateOptions } from "discord.js"
|
||||||
import { DateResolvable, Guild, GuildScheduledEvent, GuildScheduledEventCreateOptions } from "discord.js"
|
import { sendFailureDM } from "../../helper/sendFailureDM"
|
||||||
import { client } from "../../.."
|
|
||||||
import { CustomError, errorCodes, Maybe } from "../../interfaces"
|
import { CustomError, errorCodes, Maybe } from "../../interfaces"
|
||||||
import { RepetitonInfo, Schedule, supportedSchedule } from "../../types/scheduledEventTypes"
|
import { RepetitonInfo, Schedule, supportedSchedule } from "../../types/scheduledEventTypes"
|
||||||
|
|
||||||
@ -49,8 +48,8 @@ export function determineRepetitionCount(description: string): { totalAmount: nu
|
|||||||
|
|
||||||
export function buildNewRepetitionString(repetitionInfo: RepetitonInfo) {
|
export function buildNewRepetitionString(repetitionInfo: RepetitonInfo) {
|
||||||
if (repetitionInfo.endDate)
|
if (repetitionInfo.endDate)
|
||||||
return `$rep:${repetitionInfo.schedule}:${format(repetitionInfo.endDate, 'yyyy-MM-dd')}`
|
return `$rep:${repetitionInfo.schedule.getSanitizedScheduleString()}:${format(repetitionInfo.endDate, 'yyyy-MM-dd')}`
|
||||||
return `$rep:${repetitionInfo.schedule}:${repetitionInfo.alreadyOccured + 1}/${repetitionInfo.totalAmount}`
|
return `$rep:${repetitionInfo.schedule.getSanitizedScheduleString()}:${repetitionInfo.alreadyOccured + 1}/${repetitionInfo.totalAmount}`
|
||||||
}
|
}
|
||||||
|
|
||||||
export function addRepetitonStringToEventDescription(oldguildScheduledEvent: string, newRepetitonString: string): string | undefined {
|
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> {
|
export async function validateRepetitionStringAndSendMessageOnFail(event: GuildScheduledEvent): Promise<void> {
|
||||||
|
console.log('This should not be accessed')
|
||||||
|
|
||||||
const validResponses = [
|
const validResponses = [
|
||||||
'valid',
|
'valid',
|
||||||
@ -114,13 +114,6 @@ export async function validateRepetitionStringAndSendMessageOnFail(event: GuildS
|
|||||||
// do success things?
|
// do success things?
|
||||||
} else {
|
} else {
|
||||||
const creatorMessage = `The repetition string in your event could not be parsed. Reason: ${resultstring}`
|
const creatorMessage = `The repetition string in your event could not be parsed. Reason: ${resultstring}`
|
||||||
console.log(creatorMessage)
|
sendFailureDM(creatorMessage, event.creatorId ?? undefined)
|
||||||
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)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
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)
|
throw new CustomError('Schedule type not supported', errorCodes.schedule_not_supported)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public getSanitizedScheduleString(): string {
|
||||||
|
return this._scheduleString
|
||||||
|
}
|
||||||
private getBaseScheduleNameFromVariableString(): string {
|
private getBaseScheduleNameFromVariableString(): string {
|
||||||
if (this._scheduleString.includes('week')) return 'weekly'
|
if (this._scheduleString.includes('week')) return 'weekly'
|
||||||
if (this._scheduleString.includes('day')) return 'daily'
|
if (this._scheduleString.includes('day')) return 'daily'
|
||||||
|
Loading…
Reference in New Issue
Block a user