Skip to content

Commit

Permalink
Merge pull request #69 from Linguition/feat-suggest-command
Browse files Browse the repository at this point in the history
Version 1.3.0 - Implement a `/suggest` command.
  • Loading branch information
vxern authored Oct 30, 2022
2 parents 68e9963 + a6c2e4f commit f68500b
Show file tree
Hide file tree
Showing 13 changed files with 187 additions and 26 deletions.
61 changes: 55 additions & 6 deletions assets/localisations/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@ class Commands {
`Utilizatorul ${userMention} a primit un timeout pentru: ${reason}\n\n` +
`Timeout-ul va expira ${until}.`,
},
// Do not localise; This is a public feedback message.
// Do not localise; this is a public feedback message.
timedOutDirect: {
'English': (until: string, reason: string) =>
`You have been timed out for: ${reason}\n\n` +
Expand All @@ -687,7 +687,7 @@ class Commands {
'Romanian': (userMention: string) =>
`Utilizatorul ${userMention} nu mai are un timeout.`,
},
// Do not localise; This is a public feedback message.
// Do not localise; this is a public feedback message.
timeoutClearedDirect: {
'English': 'Your timeout has been cleared.',
},
Expand Down Expand Up @@ -738,7 +738,7 @@ class Commands {
'Romanian': (userMention: string, reason: string) =>
`Utilizatorul ${userMention} a fost grațiat de avertizarea sa pentru: ${reason}`,
},
// Do not localise; This is a public feedback message.
// Do not localise; this is a public feedback message.
pardonedDirect: {
'English': (reason: string, relativeTime: string) =>
`You have been pardoned from the warning given to you ${relativeTime}.\n\n` +
Expand Down Expand Up @@ -783,19 +783,19 @@ class Commands {
'Romanian': (userMention: string, warningCount: number) =>
`Utilizatorul ${userMention} a fost avertizat. Avertizări în total: ${warningCount}.`,
},
// Do not localise; This is a public feedback message.
// Do not localise; this is a public feedback message.
reachedKickStage: {
'English': (reason: string) =>
`You have been warned for: ${reason}\n\n` +
'You have surpassed the maximum number of warnings, and have subsequently been kicked from the server.',
},
// Do not localise; This is a public feedback message.
// Do not localise; this is a public feedback message.
reachedBanStage: {
'English': (reason: string) =>
`You have been warned for: ${reason}\n\n` +
'You have surpassed the maximum number of warnings twice, and have subsequently been permanently banned from the server.',
},
// Do not localise; This is a public feedback message.
// Do not localise; this is a public feedback message.
warnedDirect: {
'English': (
reason: string,
Expand Down Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion assets/localisations/information.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Guild } from '../../deps.ts';
import { getChannelMention } from '../../src/commands/secret/data/information/information-sections.ts';
import { list } from '../../src/formatting.ts';
import { getChannelMention } from '../../src/utils.ts';

const memesChannel = 'memes';

Expand Down
4 changes: 2 additions & 2 deletions src/commands/modules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import information from './information/module.ts';
import language from './language/module.ts';
import moderation from './moderation/module.ts';
//import music from './music/module.ts';
import secret from './secret/module.ts';
import server from './server/module.ts';
import social from './social/module.ts';

const modules = [
information,
language,
moderation,
//music,
secret,
server,
social,
];

Expand Down
5 changes: 0 additions & 5 deletions src/commands/secret/module.ts

This file was deleted.

File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ import {
import { Client } from '../../../../client.ts';
import configuration from '../../../../configuration.ts';
import { defaultLanguage } from '../../../../types.ts';
import { fromHex } from '../../../../utils.ts';
import { getChannelMention } from '../../data/information/information-sections.ts';
import { fromHex, getChannelMention } from '../../../../utils.ts';

function postWelcome(
[client, bot]: [Client, Bot],
Expand Down
94 changes: 94 additions & 0 deletions src/commands/server/commands/suggest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
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 { log } from '../../../controllers/logging/logging.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,
}],
});

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,
}],
},
},
);

return log(
[client, bot],
guild,
'suggestionSend',
interaction.member!,
suggestion,
);
}

export default command;
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,5 @@ async function getInvite(
return newInvite;
}

function getChannelMention(guild: Guild, name: string): string {
const channel = getTextChannel(guild, name);
if (!channel) return name;

return mention(channel.id, MentionTypes.Channel);
}

export { getChannelMention };
export type { InformationSection };
export default informationSections;
6 changes: 6 additions & 0 deletions src/commands/server/module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import post from './commands/post.ts';
import suggest from './commands/suggest.ts';

const commands = [post, suggest];

export default commands;
4 changes: 3 additions & 1 deletion src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const settings = {
// Configuration settings pertaining to the guild channels.
channels: {
logging: 'journal',
conference: 'conference',
verification: 'verifications',
voiceChat: 'Voice Chat',
},
Expand Down Expand Up @@ -166,13 +167,14 @@ const settings = {
// The standardised, available set of colours the bot can utilise for its embed messages.
colors: {
red: fromHex('#b42f2f'),
darkRed: fromHex('#820000'),
green: fromHex('#89ef59'),
darkGreen: fromHex('#479621'),
blue: fromHex('#6269ed'),
yellow: fromHex('#f2f277'),
// This colour matches the colour of an embed message,
// making it seem like there is no colour stripe.
invisible: fromHex('#36393f'),
darkRed: fromHex('#820000'),
},
// The standardised, available set of custom emojis the bot can utilise for its embed messages.
emojis: {
Expand Down
16 changes: 16 additions & 0 deletions src/controllers/logging/generators/guild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ type GuildEvents = {

/** A member has been praised. */
praiseAdd: [member: Member, praise: Praise, by: User];

/** A suggestion has been made. */
suggestionSend: [member: Member, suggestion: string];
};

/** Contains the message generators for (custom) guild events. */
Expand Down Expand Up @@ -363,6 +366,19 @@ ${trim(change.content.body, 300)}`;
originGuildId === member.guildId,
color: configuration.interactions.responses.colors.green,
},
suggestionSend: {
title: `🌿 Suggestion made`,
message: (client, member, suggestion) => {
const memberUser = client.cache.users.get(member.id);
if (!memberUser) return;

return `${diagnosticMentionUser(memberUser)} has made a suggestion.\n\n` +
`Suggestion: **${suggestion}**`;
},
filter: (_client, originGuildId, member, _suggestion) =>
originGuildId === member.guildId,
color: configuration.interactions.responses.colors.darkGreen,
},
};

export default generators;
Expand Down
10 changes: 9 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {
TextStyles,
User,
} from '../deps.ts';
import { code } from './formatting.ts';
import { code, mention, MentionTypes } from './formatting.ts';
import { addCollector, Client } from './client.ts';
import configuration from './configuration.ts';
import { Language } from './types.ts';
Expand Down Expand Up @@ -565,12 +565,20 @@ function parseArguments<
return [args as R, focused];
}

function getChannelMention(guild: Guild, name: string): string {
const channel = getTextChannel(guild, name);
if (!channel) return name;

return mention(channel.id, MentionTypes.Channel);
}

export {
chunk,
createInteractionCollector,
createVerificationPrompt,
diagnosticMentionUser,
fromHex,
getChannelMention,
getGuildIconURLFormatted,
getTextChannel,
guildAsAuthor,
Expand Down

0 comments on commit f68500b

Please sign in to comment.