-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(guards): interactions locale extractor (#12)
- Loading branch information
Bartholomé
committed
Aug 9, 2022
1 parent
1a4fc1a
commit f284e5c
Showing
13 changed files
with
90 additions
and
53 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
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,36 @@ | ||
import { GuardFunction, SimpleCommandMessage } from 'discordx' | ||
import { ContextMenuCommandInteraction, CommandInteraction as DCommandInteraction, Interaction, MessageContextMenuCommandInteraction, UserContextMenuCommandInteraction, CommandInteraction, SelectMenuInteraction, ButtonInteraction } from 'discord.js' | ||
|
||
import { getLocaleFromInteraction, L } from '@i18n' | ||
import { resolveUser, replyToInteraction } from '@utils/functions' | ||
|
||
import { generalConfig } from '@config' | ||
|
||
/** | ||
* Extract locale from any interaction and pass it as guard data | ||
*/ | ||
export const Disabled: GuardFunction<Interaction> = async (interaction, client, next, guardData) => { | ||
|
||
if ( | ||
interaction instanceof SimpleCommandMessage | ||
|| interaction instanceof CommandInteraction | ||
|| interaction instanceof ContextMenuCommandInteraction | ||
|| interaction instanceof SelectMenuInteraction | ||
|| interaction instanceof ButtonInteraction | ||
) { | ||
|
||
const sanitizedLocale = getLocaleFromInteraction(interaction as AllInteractions) | ||
|
||
const interactionData: InteractionData = { | ||
sanitizedLocale: sanitizedLocale, | ||
localize: L[sanitizedLocale] | ||
} | ||
|
||
guardData = { | ||
...guardData, | ||
...interactionData | ||
} | ||
} | ||
|
||
await next() | ||
} |
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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
export * from './BaseError' | ||
export * from './BaseController' | ||
export * from './BaseController' |
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