-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Option to filter including/excluding remixes (#1747)
* Option to filter including/excluding remixes * Add remix description to GAMEPLAY.md * Remove exclusively playing remixes * Deprecate text command
- Loading branch information
1 parent
a48bd8d
commit 981f84d
Showing
17 changed files
with
410 additions
and
0 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
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,236 @@ | ||
import { DEFAULT_REMIX_PREFERENCE, OptionAction } from "../../constants"; | ||
import { IPCLogger } from "../../logger"; | ||
import { | ||
getDebugLogHeader, | ||
getInteractionValue, | ||
sendDeprecatedTextCommandMessage, | ||
sendOptionsMessage, | ||
} from "../../helpers/discord_utils"; | ||
import CommandPrechecks from "../../command_prechecks"; | ||
import Eris from "eris"; | ||
import GameOption from "../../enums/game_option_name"; | ||
import GuildPreference from "../../structures/guild_preference"; | ||
import LocaleType from "../../enums/locale_type"; | ||
import MessageContext from "../../structures/message_context"; | ||
import RemixPreference from "../../enums/option_types/remix_preference"; | ||
import Session from "../../structures/session"; | ||
import i18n from "../../helpers/localization_manager"; | ||
import type { DefaultSlashCommand } from "../interfaces/base_command"; | ||
import type BaseCommand from "../interfaces/base_command"; | ||
import type CommandArgs from "../../interfaces/command_args"; | ||
import type HelpDocumentation from "../../interfaces/help"; | ||
|
||
const logger = new IPCLogger("remix"); | ||
|
||
export default class RemixCommand implements BaseCommand { | ||
preRunChecks = [ | ||
{ checkFn: CommandPrechecks.competitionPrecheck }, | ||
{ checkFn: CommandPrechecks.notSpotifyPrecheck }, | ||
]; | ||
|
||
aliases = ["remixes"]; | ||
|
||
validations = { | ||
minArgCount: 0, | ||
maxArgCount: 1, | ||
arguments: [ | ||
{ | ||
name: "remixPreference", | ||
type: "enum" as const, | ||
enums: Object.values(RemixPreference), | ||
}, | ||
], | ||
}; | ||
|
||
help = (guildID: string): HelpDocumentation => ({ | ||
name: "remix", | ||
description: i18n.translate(guildID, "command.remix.help.description"), | ||
usage: "/remix set\nremix:[include | exclude]\n\n/remix reset", | ||
examples: [ | ||
{ | ||
example: "`/remix set remix:include`", | ||
explanation: i18n.translate( | ||
guildID, | ||
"command.remix.help.example.include" | ||
), | ||
}, | ||
{ | ||
example: "`/remix set remix:exclude`", | ||
explanation: i18n.translate( | ||
guildID, | ||
"command.remix.help.example.exclude" | ||
), | ||
}, | ||
{ | ||
example: "`/remix reset`", | ||
explanation: i18n.translate( | ||
guildID, | ||
"command.remix.help.example.reset", | ||
{ defaultRemix: `\`${DEFAULT_REMIX_PREFERENCE}\`` } | ||
), | ||
}, | ||
], | ||
priority: 130, | ||
}); | ||
|
||
slashCommands = (): Array< | ||
DefaultSlashCommand | Eris.ChatInputApplicationCommandStructure | ||
> => [ | ||
{ | ||
type: Eris.Constants.ApplicationCommandTypes.CHAT_INPUT, | ||
options: [ | ||
{ | ||
name: OptionAction.SET, | ||
description: i18n.translate( | ||
LocaleType.EN, | ||
"command.remix.help.description" | ||
), | ||
description_localizations: Object.values(LocaleType) | ||
.filter((x) => x !== LocaleType.EN) | ||
.reduce( | ||
(acc, locale) => ({ | ||
...acc, | ||
[locale]: i18n.translate( | ||
locale, | ||
"command.remix.help.description" | ||
), | ||
}), | ||
{} | ||
), | ||
|
||
type: Eris.Constants.ApplicationCommandOptionTypes | ||
.SUB_COMMAND, | ||
options: [ | ||
{ | ||
name: "remix", | ||
description: i18n.translate( | ||
LocaleType.EN, | ||
"command.remix.interaction.remix" | ||
), | ||
description_localizations: Object.values(LocaleType) | ||
.filter((x) => x !== LocaleType.EN) | ||
.reduce( | ||
(acc, locale) => ({ | ||
...acc, | ||
[locale]: i18n.translate( | ||
locale, | ||
"command.remix.interaction.remix" | ||
), | ||
}), | ||
{} | ||
), | ||
|
||
type: Eris.Constants.ApplicationCommandOptionTypes | ||
.STRING, | ||
required: true, | ||
choices: Object.values(RemixPreference).map( | ||
(remixPreference) => ({ | ||
name: remixPreference, | ||
value: remixPreference, | ||
}) | ||
), | ||
}, | ||
], | ||
}, | ||
{ | ||
name: OptionAction.RESET, | ||
description: i18n.translate( | ||
LocaleType.EN, | ||
"misc.interaction.resetOption", | ||
{ optionName: "remix" } | ||
), | ||
description_localizations: Object.values(LocaleType) | ||
.filter((x) => x !== LocaleType.EN) | ||
.reduce( | ||
(acc, locale) => ({ | ||
...acc, | ||
[locale]: i18n.translate( | ||
locale, | ||
"misc.interaction.resetOption", | ||
{ optionName: "remix" } | ||
), | ||
}), | ||
{} | ||
), | ||
|
||
type: Eris.Constants.ApplicationCommandOptionTypes | ||
.SUB_COMMAND, | ||
options: [], | ||
}, | ||
], | ||
}, | ||
]; | ||
|
||
call = async ({ message }: CommandArgs): Promise<void> => { | ||
logger.warn("Text-based command not supported for remix"); | ||
await sendDeprecatedTextCommandMessage( | ||
MessageContext.fromMessage(message) | ||
); | ||
}; | ||
|
||
static async updateOption( | ||
messageContext: MessageContext, | ||
remixPreference: RemixPreference | null, | ||
interaction?: Eris.CommandInteraction | ||
): Promise<void> { | ||
const guildPreference = await GuildPreference.getGuildPreference( | ||
messageContext.guildID | ||
); | ||
|
||
const reset = remixPreference == null; | ||
if (reset) { | ||
await guildPreference.reset(GameOption.REMIX_PREFERENCE); | ||
logger.info( | ||
`${getDebugLogHeader(messageContext)} | Remix preference reset.` | ||
); | ||
} else { | ||
await guildPreference.setRemixPreference(remixPreference); | ||
logger.info( | ||
`${getDebugLogHeader( | ||
messageContext | ||
)} | Remix preference set to ${remixPreference}` | ||
); | ||
} | ||
|
||
await sendOptionsMessage( | ||
Session.getSession(messageContext.guildID), | ||
messageContext, | ||
guildPreference, | ||
[{ option: GameOption.REMIX_PREFERENCE, reset }], | ||
false, | ||
undefined, | ||
undefined, | ||
interaction | ||
); | ||
} | ||
|
||
/** | ||
* @param interaction - The interaction | ||
* @param messageContext - The message context | ||
*/ | ||
async processChatInputInteraction( | ||
interaction: Eris.CommandInteraction, | ||
messageContext: MessageContext | ||
): Promise<void> { | ||
const { interactionName, interactionOptions } = | ||
getInteractionValue(interaction); | ||
|
||
let remixValue: RemixPreference | null; | ||
|
||
const action = interactionName as OptionAction; | ||
if (action === OptionAction.RESET) { | ||
remixValue = null; | ||
} else if (action === OptionAction.SET) { | ||
remixValue = interactionOptions["remix"] as RemixPreference; | ||
} else { | ||
logger.error(`Unexpected interaction name: ${interactionName}`); | ||
remixValue = null; | ||
} | ||
|
||
await RemixCommand.updateOption( | ||
messageContext, | ||
remixValue, | ||
interaction | ||
); | ||
} | ||
} |
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.