Skip to content

Commit

Permalink
feat: Create /suggest command.
Browse files Browse the repository at this point in the history
vxern committed Oct 30, 2022
1 parent 9250a8d commit 976006d
Showing 3 changed files with 136 additions and 1 deletion.
49 changes: 49 additions & 0 deletions assets/localisations/commands.ts
Original file line number Diff line number Diff line change
@@ -1523,6 +1523,55 @@ class Commands {
},
});

static readonly suggest = typedLocalisations({
name: {
'English': 'suggest',
'Polish': 'zasugeruj',
'Romanian': 'sugerează',
},
description: {
'English': 'Passes a suggestion over to the server staff.',
'Polish': 'Przekazuje sugestię moderacji serwera.',
'Romanian': 'Transmite o sugestie personalului serverului.',
},
options: {
suggestion: {
name: {
'English': 'suggestion',
'Polish': 'sugestia',
'Romanian': 'sugestie',
},
description: {
'English': 'The suggestion to pass over to the server staff.',
'Polish': 'Sugestia, która ma zostać przekazana moderacji serwera.',
'Romanian': 'Sugestia care să fie transmisă personalului serverului.',
},
},
},
strings: {
// Do not localise; this is a public feedback message.
suggestionReceived: {
header: {
'English': 'Suggestion!',
},
body: {
'English': (userMention: string, suggestion: string) =>
`${userMention} has made a suggestion:\n\n` + `*${suggestion}*`,
},
},
suggestionMade: {
'English':
'Your suggestion has been passed over to the server staff.\n\n' +
'We will keep you posted for developments regarding it.',
'Polish': 'Twoja sugestia została przekazana moderacji serwera.\n\n' +
'Będziemy na bieżąco informować Cię o zmianach w jej zakresie.',
'Romanian':
'Sugestia ta a fost transmisă personalului serverului.\n\n' +
'Te vom ține la curent cu evoluțiile din cadrul acesteia.',
},
},
});

static readonly praise = typedLocalisations({
name: {
'English': 'praise',
85 changes: 85 additions & 0 deletions src/commands/server/commands/suggest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import { Commands } from '../../../../assets/localisations/commands.ts';
import {
createLocalisations,
localise,
} from '../../../../assets/localisations/types.ts';
import {
ApplicationCommandFlags,
ApplicationCommandOptionTypes,
Bot,
Interaction,
InteractionResponseTypes,
sendInteractionResponse,
sendMessage,
} from '../../../../deps.ts';
import { Client } from '../../../client.ts';
import configuration from '../../../configuration.ts';
import { mention, MentionTypes } from '../../../formatting.ts';
import { defaultLanguage } from '../../../types.ts';
import { getTextChannel, parseArguments } from '../../../utils.ts';
import { CommandBuilder } from '../../command.ts';

const command: CommandBuilder = {
...createLocalisations(Commands.suggest),
defaultMemberPermissions: ['VIEW_CHANNEL'],
handle: makeSuggestion,
options: [{
...createLocalisations(Commands.suggest.options.suggestion),
type: ApplicationCommandOptionTypes.String,
required: true,
}],
};

async function makeSuggestion(
[client, bot]: [Client, Bot],
interaction: Interaction,
): Promise<void> {
const guild = client.cache.guilds.get(interaction.guildId!);
if (!guild) return;

const conferenceChannel = getTextChannel(
guild,
configuration.guilds.channels.conference,
);
if (!conferenceChannel) return;

const [{ suggestion }] = parseArguments(interaction.data?.options, {});
if (!suggestion) return;

sendMessage(bot, conferenceChannel.id, {
embeds: [{
title: `🌿 ${
localise(
Commands.suggest.strings.suggestionReceived.header,
defaultLanguage,
)
}`,
description: localise(
Commands.suggest.strings.suggestionReceived.body,
defaultLanguage,
)(mention(interaction.user.id, MentionTypes.User), suggestion),
color: configuration.interactions.responses.colors.darkGreen,
}],
});

return void sendInteractionResponse(
bot,
interaction.id,
interaction.token,
{
type: InteractionResponseTypes.ChannelMessageWithSource,
data: {
flags: ApplicationCommandFlags.Ephemeral,
embeds: [{
description: localise(
Commands.suggest.strings.suggestionMade,
interaction.locale,
),
color: configuration.interactions.responses.colors.green,
}],
},
},
);
}

export default command;
3 changes: 2 additions & 1 deletion src/commands/server/module.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import post from './commands/post.ts';
import suggest from './commands/suggest.ts';

const commands = [post];
const commands = [post, suggest];

export default commands;

0 comments on commit 976006d

Please sign in to comment.