Adds some more polish
This commit is contained in:
parent
b3d0b3a90c
commit
11bd836ec3
18 changed files with 272 additions and 29 deletions
60
source/Discord/Commands/Bot.ts
Normal file
60
source/Discord/Commands/Bot.ts
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
import {CacheType, ChatInputCommandInteraction, hyperlink, PermissionFlagsBits, SlashCommandBuilder} from "discord.js";
|
||||
import {ChatInteractionCommand, Command} from "./Command";
|
||||
import * as fs from "node:fs";
|
||||
import {UserError} from "../UserError";
|
||||
import {ifError} from "node:assert";
|
||||
import {BuildContextGetter} from "../../Utilities/BuildContext";
|
||||
import {EmbedLibrary} from "../EmbedLibrary";
|
||||
|
||||
export class BotCommand implements Command, ChatInteractionCommand {
|
||||
definition(): SlashCommandBuilder {
|
||||
return new SlashCommandBuilder()
|
||||
.setName("bot")
|
||||
.setDescription("Offers some information about the bot")
|
||||
.setDefaultMemberPermissions(PermissionFlagsBits.Administrator)
|
||||
.addSubcommand(command => command
|
||||
.setName("build")
|
||||
.setDescription("Displays some information about the build the bot is running on.")
|
||||
)
|
||||
}
|
||||
|
||||
execute(interaction: ChatInputCommandInteraction<CacheType>): Promise<void> {
|
||||
switch (interaction.options.getSubcommand()) {
|
||||
case "build":
|
||||
this.displayBuildInfos(interaction);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private displayBuildInfos(interaction: ChatInputCommandInteraction<CacheType>) {
|
||||
const buildContext = new BuildContextGetter().getContext();
|
||||
if (!buildContext) {
|
||||
throw new UserError("Can't find required deploy information", "Using a valid docker image or (when running on a dev build) running `npm run build` once.");
|
||||
}
|
||||
|
||||
const embed = EmbedLibrary.base("Current Build")
|
||||
.setFields(
|
||||
[
|
||||
{
|
||||
name: "Build Target",
|
||||
value: buildContext.target,
|
||||
inline: true
|
||||
},
|
||||
{
|
||||
name: "Build Label",
|
||||
value: buildContext.label,
|
||||
inline: true
|
||||
},
|
||||
{
|
||||
name: "Latest Commit",
|
||||
value: hyperlink(buildContext.commitHash, buildContext.commitLink)
|
||||
}
|
||||
]
|
||||
)
|
||||
|
||||
interaction.reply({
|
||||
embeds: [embed]
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -5,12 +5,14 @@ import {PlaydatesCommand} from "./Playdates";
|
|||
import {RESTPostAPIChatInputApplicationCommandsJSONBody} from "discord.js";
|
||||
import {Nullable} from "../../types/Nullable";
|
||||
import {ServerCommand} from "./Server";
|
||||
import {BotCommand} from "./Bot";
|
||||
|
||||
const commands: Set<Command> = new Set<Command>([
|
||||
new HelloWorldCommand(),
|
||||
new GroupCommand(),
|
||||
new PlaydatesCommand(),
|
||||
new ServerCommand()
|
||||
new ServerCommand(),
|
||||
new BotCommand()
|
||||
]);
|
||||
|
||||
export default class Commands {
|
||||
|
|
|
|||
|
|
@ -33,6 +33,10 @@ import {ServerConfigurationProvider} from "../../Configuration/Server/ServerConf
|
|||
import {ServerConfigurationRepository} from "../../Database/Repositories/ServerConfigurationRepository";
|
||||
import {PermissionError} from "../PermissionError";
|
||||
import {EmbedLibrary, EmbedType} from "../EmbedLibrary";
|
||||
import {EventHandler} from "../../Events/EventHandler";
|
||||
import {ElementChangedEvent} from "../../Events/EventClasses/ElementChangedEvent";
|
||||
import GroupConfiguration from "../../Database/tables/GroupConfiguration";
|
||||
import Groups from "../../Database/tables/Groups";
|
||||
|
||||
export class GroupCommand implements Command, ChatInteractionCommand, AutocompleteCommand {
|
||||
private static GOODBYE_MESSAGES: string[] = [
|
||||
|
|
@ -50,7 +54,7 @@ export class GroupCommand implements Command, ChatInteractionCommand, Autocomple
|
|||
definition(): SlashCommandBuilder {
|
||||
// @ts-expect-error Slash command expects more than needed.
|
||||
return new SlashCommandBuilder()
|
||||
.setName('groups')
|
||||
.setName('group')
|
||||
.setDescription(`Manages groups`)
|
||||
.addSubcommand(create =>
|
||||
create.setName("create")
|
||||
|
|
@ -289,9 +293,9 @@ export class GroupCommand implements Command, ChatInteractionCommand, Autocomple
|
|||
type: MenuItemType.Collection,
|
||||
children: [
|
||||
{
|
||||
traversalKey: "newPlaydates",
|
||||
label: "New Playdates",
|
||||
description: "Sets the channel, where the group gets notified, when new Playdates are set.",
|
||||
traversalKey: "notifications",
|
||||
label: "Notifications",
|
||||
description: "Sets the channel, where the group gets notified, when things are happening, such as a new playdate is created.",
|
||||
},
|
||||
{
|
||||
traversalKey: "playdateReminders",
|
||||
|
|
@ -369,6 +373,17 @@ export class GroupCommand implements Command, ChatInteractionCommand, Autocomple
|
|||
group.leader.memberid = newLeader.id
|
||||
repo.update(group);
|
||||
|
||||
Container.get<EventHandler>(EventHandler.name)
|
||||
.dispatch(new ElementChangedEvent<GroupModel>(
|
||||
Groups.name,
|
||||
{
|
||||
id: group.id,
|
||||
leader: {
|
||||
memberid: newLeader.id
|
||||
}
|
||||
}
|
||||
))
|
||||
|
||||
await interaction.reply({
|
||||
embeds: [
|
||||
EmbedLibrary.base(
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ export class PlaydatesCommand implements Command, AutocompleteCommand, ChatInter
|
|||
definition(): SlashCommandBuilder {
|
||||
// @ts-expect-error Command builder is improperly marked as incomplete.
|
||||
return new SlashCommandBuilder()
|
||||
.setName("playdates")
|
||||
.setName("playdate")
|
||||
.setDescription("Manage your playdates")
|
||||
.addSubcommand((subcommand) => subcommand
|
||||
.setName("create")
|
||||
|
|
@ -153,7 +153,7 @@ export class PlaydatesCommand implements Command, AutocompleteCommand, ChatInter
|
|||
|
||||
playdateRepo.create(playdate);
|
||||
|
||||
const embed = EmbedLibrary.playdate(
|
||||
const embed = EmbedLibrary.withGroup(
|
||||
group,
|
||||
"Created a play-date.",
|
||||
":white_check_mark: Your playdate has been created! You and your group get notified, when its time.",
|
||||
|
|
@ -198,7 +198,7 @@ export class PlaydatesCommand implements Command, AutocompleteCommand, ChatInter
|
|||
private async list(interaction: ChatInputCommandInteraction, group: GroupModel) {
|
||||
const playdates = Container.get<PlaydateRepository>(PlaydateRepository.name).findFromGroup(group);
|
||||
|
||||
const embed = EmbedLibrary.playdate(
|
||||
const embed = EmbedLibrary.withGroup(
|
||||
group,
|
||||
"Created a play-date.",
|
||||
null,
|
||||
|
|
@ -242,7 +242,7 @@ export class PlaydatesCommand implements Command, AutocompleteCommand, ChatInter
|
|||
|
||||
repo.delete(playdateId);
|
||||
|
||||
const embed = EmbedLibrary.playdate(
|
||||
const embed = EmbedLibrary.withGroup(
|
||||
group,
|
||||
"Playdate deleted",
|
||||
`:x: Deleted ${time(selected.from_time, 'F')} - ${time(selected.to_time, 'F')}`,
|
||||
|
|
@ -296,7 +296,7 @@ export class PlaydatesCommand implements Command, AutocompleteCommand, ChatInter
|
|||
});
|
||||
}
|
||||
|
||||
const embed = EmbedLibrary.playdate(
|
||||
const embed = EmbedLibrary.withGroup(
|
||||
group,
|
||||
"Imported play-dates",
|
||||
`:white_check_mark: Your ${playdates.length} playdates has been created! You and your group get notified, when its time.`,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue