-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* WIP * WIP * feat: restore legacy travel command * fix: texts and labels, add not a move requirement * fix: import after rebase * chore: review * fix: build
- Loading branch information
geisterfurz007
authored
Sep 1, 2023
1 parent
d274093
commit 2957e35
Showing
16 changed files
with
900 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { | ||
Command, | ||
CommandHandler, | ||
DiscordEvent, | ||
} from "../../../event-distribution"; | ||
import { | ||
ThreadAutoArchiveDuration, | ||
ButtonInteraction, | ||
TextChannel, | ||
} from "discord.js"; | ||
import { ChatNames } from "../../../collections/chat-names"; | ||
import { TravelDataMessageConverter } from "./travel-data-message-converter"; | ||
|
||
@Command({ | ||
event: DiscordEvent.BUTTON_CLICKED, | ||
customId: "travel-approve", | ||
}) | ||
class ApproveTravelButton extends CommandHandler<DiscordEvent.BUTTON_CLICKED> { | ||
async handle(interaction: ButtonInteraction): Promise<void> { | ||
const message = interaction.message; | ||
const guild = interaction.guild!; | ||
|
||
const details = TravelDataMessageConverter.fromMessage(message, guild); | ||
|
||
const member = guild.members.resolve(interaction.user.id); | ||
if (!member) throw new Error("Could not resolve approving member!"); | ||
|
||
const approver = member.displayName; | ||
const newContent = message.content + `\n\nApproved by ${approver}`; | ||
// Remove buttons as early as possible before someone else votes as well | ||
await message.edit({ content: newContent, components: [] }); | ||
|
||
const travelChannel = interaction.guild?.channels.cache.find( | ||
(c): c is TextChannel => c.name === ChatNames.TRAVELING_TOGETHER | ||
); | ||
if (!travelChannel) throw new Error("Could not find travel channel!"); | ||
|
||
const messageWithMentions = TravelDataMessageConverter.toMessage( | ||
details, | ||
true | ||
); | ||
|
||
const travelPost = | ||
messageWithMentions + | ||
"\n\nClick on the thread right below this line if you're interested to join the chat and talk about it 🙂"; | ||
const travelMessage = await travelChannel?.send(travelPost); | ||
|
||
const ticketMember = await guild.members.fetch(details.userId); | ||
const threadName = `${ticketMember.displayName} in ${details.places}`; | ||
const trimmedThreadname = threadName.substring(0, 100); | ||
|
||
await travelMessage.startThread({ | ||
name: trimmedThreadname, | ||
autoArchiveDuration: ThreadAutoArchiveDuration.OneWeek, | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { | ||
Command, | ||
CommandHandler, | ||
DiscordEvent, | ||
EventLocation, | ||
} from "../../../event-distribution"; | ||
import { ButtonInteraction } from "discord.js"; | ||
|
||
@Command({ | ||
event: DiscordEvent.BUTTON_CLICKED, | ||
customId: "travel-cancel", | ||
location: EventLocation.DIRECT_MESSAGE, | ||
}) | ||
class CancelTravelButton extends CommandHandler<DiscordEvent.BUTTON_CLICKED> { | ||
async handle(interaction: ButtonInteraction): Promise<void> { | ||
await interaction.message.delete(); | ||
await interaction.reply( | ||
"Feel free to open up a new travel ticket anytime using the /travel command!" | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
import { | ||
Command, | ||
CommandHandler, | ||
DiscordEvent, | ||
} from "../../../event-distribution"; | ||
import { | ||
ActionRowBuilder, | ||
ButtonBuilder, | ||
ButtonInteraction, | ||
ButtonStyle, | ||
ModalSubmitInteraction, | ||
TextInputBuilder, | ||
TextInputStyle, | ||
} from "discord.js"; | ||
import { | ||
TravelDataMessageConverter, | ||
TripDetails, | ||
} from "./travel-data-message-converter"; | ||
|
||
@Command({ | ||
event: DiscordEvent.BUTTON_CLICKED, | ||
customId: "travel-decline", | ||
}) | ||
class DeclineTravelButton extends CommandHandler<DiscordEvent.BUTTON_CLICKED> { | ||
async handle(interaction: ButtonInteraction): Promise<void> { | ||
const message = interaction.message; | ||
const originalMessage = message.content; | ||
const guild = interaction.guild!; | ||
const details = TravelDataMessageConverter.fromMessage(message, guild); | ||
|
||
const member = guild.members.resolve(interaction.user.id); | ||
if (!member) throw new Error("Could not resolve approving member!"); | ||
|
||
const decliner = member.displayName; | ||
const newContent = | ||
message.content + `\n\n${decliner} is currently declining...`; | ||
await message.edit({ content: newContent }); | ||
|
||
const { userId } = details; | ||
|
||
const reasonInput = new ActionRowBuilder<TextInputBuilder>({ | ||
components: [ | ||
new TextInputBuilder({ | ||
customId: "reason", | ||
style: TextInputStyle.Paragraph, | ||
required: true, | ||
label: "Reason", | ||
}), | ||
], | ||
}); | ||
|
||
const modalId = "travel-decline-reason-" + userId; | ||
await interaction.showModal({ | ||
title: "Decline reason", | ||
customId: modalId, | ||
components: [reasonInput], | ||
}); | ||
try { | ||
const submission = await interaction.awaitModalSubmit({ | ||
time: 5 * 60 * 1000, | ||
filter: (i) => i.customId === modalId, | ||
}); | ||
|
||
await this.declineWithReason(submission, originalMessage, details); | ||
} catch { | ||
await interaction.update({ content: originalMessage }); | ||
} | ||
} | ||
|
||
async declineWithReason( | ||
submission: ModalSubmitInteraction, | ||
originalMessage: string, | ||
details: TripDetails | ||
) { | ||
const reason = submission.fields.getTextInputValue("reason").trim(); | ||
if (!submission.isFromMessage()) return; | ||
const guild = submission.guild!; | ||
const member = guild.members.resolve(submission.user.id); | ||
if (!member) throw new Error("Could not resolve approving member!"); | ||
|
||
const decliner = member.displayName; | ||
|
||
if (!reason) { | ||
await submission.update({ content: originalMessage }); | ||
return; | ||
} | ||
|
||
await submission.update({ | ||
content: | ||
originalMessage + `\n\nDeclined by ${decliner}\nReason: ${reason}`, | ||
components: [], | ||
}); | ||
|
||
const editButtonId = "travel-edit"; | ||
const editButton = new ButtonBuilder({ | ||
label: "Edit", | ||
style: ButtonStyle.Primary, | ||
customId: editButtonId, | ||
emoji: "✏", | ||
}); | ||
|
||
const cancelButtonId = "travel-cancel"; | ||
const cancelButton = new ButtonBuilder({ | ||
label: "Cancel", | ||
style: ButtonStyle.Danger, | ||
customId: cancelButtonId, | ||
}); | ||
|
||
const dm = await submission.client.users.createDM(details.userId); | ||
await dm.send({ | ||
content: `Hello there! A moderator has declined your travel ticket with the following reason: ${reason} | ||
This was your submission: | ||
--- | ||
${originalMessage} | ||
--- | ||
You can edit or cancel your ticket: | ||
`, | ||
components: [ | ||
new ActionRowBuilder<ButtonBuilder>({ | ||
components: [editButton, cancelButton], | ||
}), | ||
], | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { | ||
Command, | ||
CommandHandler, | ||
DiscordEvent, | ||
} from "../../../event-distribution"; | ||
import { ButtonInteraction } from "discord.js"; | ||
import { TravelEditing } from "./travel-editing"; | ||
import { TravelDataMessageConverter } from "./travel-data-message-converter"; | ||
|
||
@Command({ | ||
event: DiscordEvent.BUTTON_CLICKED, | ||
customId: "travel-edit", | ||
}) | ||
class EditTravelButton extends CommandHandler<DiscordEvent.BUTTON_CLICKED> { | ||
async handle(interaction: ButtonInteraction): Promise<void> { | ||
const editing = new TravelEditing(); | ||
const guild = interaction.client.guilds.resolve(process.env.GUILD_ID); | ||
|
||
if (!guild) throw new Error("Yeet"); | ||
|
||
const details = TravelDataMessageConverter.fromMessage( | ||
interaction.message, | ||
guild | ||
); | ||
|
||
const { details: finalDetails, interaction: editInteraction } = | ||
await editing.doEditing(details, interaction, false); | ||
await editing.sendApprovalMessage(finalDetails, guild); | ||
|
||
await editInteraction.update({ | ||
content: | ||
"I've sent everything to the mods! Have some patience while they take a look at the updates :)", | ||
components: [], | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { | ||
Command, | ||
CommandHandler, | ||
DiscordEvent, | ||
HandlerRejectedReason, | ||
} from "../../../../event-distribution"; | ||
import { Message } from "discord.js"; | ||
import { maybeCreateTicket, TicketType } from "../../common"; | ||
import { promptAndSendForApproval } from "./common"; | ||
|
||
@Command({ | ||
event: DiscordEvent.MESSAGE, | ||
trigger: "!travel", | ||
allowedRoles: ["Seek Discomfort"], | ||
description: "This handler is to create a travel ticket.", | ||
stateful: false, | ||
errors: { | ||
[HandlerRejectedReason.MISSING_ROLE]: `Before meeting up with people, it's probably best to let others know who you are! This command requires the 'Seek Discomfort' role which you can get by introducing yourself in #introductions!\n\nIf you already posted your introduction, make sure it's longer than just two or three sentences and give the support team some time to check it :)`, | ||
}, | ||
}) | ||
class OpenTravelTicket implements CommandHandler<DiscordEvent.MESSAGE> { | ||
async handle(message: Message): Promise<void> { | ||
const channel = await maybeCreateTicket( | ||
message, | ||
TicketType.TRAVEL, | ||
`Hi ${message.member?.toString()}, let's collect all important information for your trip!`, | ||
false | ||
); | ||
|
||
if (!channel) return; | ||
|
||
await promptAndSendForApproval(channel, message.author.id); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.