-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
306 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
138 changes: 138 additions & 0 deletions
138
src/interactions/commands/Bot Creators/switchbind/switchbind.ts
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,138 @@ | ||
import { DatabaseManager } from "@database/DatabaseManager"; | ||
import { CommandCategory } from "@enums/core/CommandCategory"; | ||
import { SlashCommand } from "structures/core/SlashCommand"; | ||
import { Constants } from "@core/Constants"; | ||
import { MessageCreator } from "@utils/creators/MessageCreator"; | ||
import { ApplicationCommandOptionType } from "discord.js"; | ||
import { NumberHelper } from "@utils/helpers/NumberHelper"; | ||
import { SwitchbindLocalization } from "@localization/interactions/commands/Bot Creators/switchbind/SwitchbindLocalization"; | ||
import { CommandHelper } from "@utils/helpers/CommandHelper"; | ||
import { InteractionHelper } from "@utils/helpers/InteractionHelper"; | ||
import { ConstantsLocalization } from "@localization/core/constants/ConstantsLocalization"; | ||
|
||
export const run: SlashCommand["run"] = async (client, interaction) => { | ||
const localization = new SwitchbindLocalization( | ||
CommandHelper.getLocale(interaction), | ||
); | ||
|
||
if ( | ||
!CommandHelper.isExecutedByBotOwner(interaction) && | ||
(!interaction.inCachedGuild() || | ||
!interaction.member.roles.cache.has("803154670380908575")) | ||
) { | ||
interaction.ephemeral = true; | ||
|
||
return InteractionHelper.reply(interaction, { | ||
content: MessageCreator.createReject( | ||
new ConstantsLocalization(localization.language).getTranslation( | ||
Constants.noPermissionReject, | ||
), | ||
), | ||
}); | ||
} | ||
|
||
await InteractionHelper.deferReply(interaction); | ||
|
||
const uid = interaction.options.getInteger("uid", true); | ||
|
||
if ( | ||
!NumberHelper.isNumberInRange( | ||
uid, | ||
Constants.uidMinLimit, | ||
Constants.uidMaxLimit, | ||
true, | ||
) | ||
) { | ||
return InteractionHelper.reply(interaction, { | ||
content: localization.getTranslation("invalidUid"), | ||
}); | ||
} | ||
|
||
const user = await ( | ||
await client.guilds.fetch(Constants.mainServer) | ||
).members.fetch(interaction.options.getUser("user", true)); | ||
|
||
const bindInfo = | ||
await DatabaseManager.elainaDb.collections.userBind.getFromUid(uid); | ||
|
||
if (!bindInfo) { | ||
return InteractionHelper.reply(interaction, { | ||
content: MessageCreator.createReject( | ||
localization.getTranslation("uidNotBinded"), | ||
), | ||
}); | ||
} | ||
|
||
const result = await bindInfo.moveBind(uid, user.id, localization.language); | ||
|
||
if (result.failed()) { | ||
return InteractionHelper.reply(interaction, { | ||
content: MessageCreator.createReject( | ||
localization.getTranslation("switchFailed"), | ||
result.reason, | ||
), | ||
}); | ||
} | ||
|
||
InteractionHelper.reply(interaction, { | ||
content: MessageCreator.createAccept( | ||
localization.getTranslation("switchSuccessful"), | ||
), | ||
}); | ||
}; | ||
|
||
export const category: SlashCommand["category"] = CommandCategory.botCreators; | ||
|
||
export const config: SlashCommand["config"] = { | ||
name: "switchbind", | ||
description: | ||
"Switches an osu!droid account bind from one Discord account to another.", | ||
options: [ | ||
{ | ||
name: "uid", | ||
required: true, | ||
type: ApplicationCommandOptionType.Integer, | ||
description: "The uid of the osu!droid account to switch.", | ||
minValue: Constants.uidMinLimit, | ||
}, | ||
{ | ||
name: "user", | ||
required: true, | ||
type: ApplicationCommandOptionType.User, | ||
description: "The user to switch the bind to.", | ||
}, | ||
], | ||
example: [ | ||
{ | ||
command: "switchbind uid:51076 user:@Rian8337#0001", | ||
arguments: [ | ||
{ | ||
name: "uid", | ||
value: 51076, | ||
}, | ||
{ | ||
name: "user", | ||
value: "@Rian8337#0001", | ||
}, | ||
], | ||
description: | ||
"will switch the osu!droid account with uid 51076's bind to Rian8337.", | ||
}, | ||
{ | ||
command: "switchbind uid:5475 user:132783516176875520", | ||
arguments: [ | ||
{ | ||
name: "uid", | ||
value: 5475, | ||
}, | ||
{ | ||
name: "user", | ||
value: "132783516176875520", | ||
}, | ||
], | ||
description: | ||
"will switch the osu!droid account with uid 5475's bind to the Discord account with ID 132783516176875520.", | ||
}, | ||
], | ||
permissions: ["Special"], | ||
}; |
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
27 changes: 27 additions & 0 deletions
27
src/localization/interactions/commands/Bot Creators/switchbind/SwitchbindLocalization.ts
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,27 @@ | ||
import { Localization } from "@localization/base/Localization"; | ||
import { Translations } from "@localization/base/Translations"; | ||
import { SwitchbindENTranslation } from "./translations/SwitchbindENTranslation"; | ||
import { SwitchbindESTranslation } from "./translations/SwitchbindESTranslation"; | ||
import { SwitchbindIDTranslation } from "./translations/SwitchbindIDTranslation"; | ||
import { SwitchbindKRTranslation } from "./translations/SwitchbindKRTranslation"; | ||
|
||
export interface SwitchbindStrings { | ||
readonly invalidUid: string; | ||
readonly uidNotBinded: string; | ||
readonly switchFailed: string; | ||
readonly switchSuccessful: string; | ||
} | ||
|
||
/** | ||
* Localizations for the `switchbind` command. | ||
*/ | ||
export class SwitchbindLocalization extends Localization<SwitchbindStrings> { | ||
protected override readonly localizations: Readonly< | ||
Translations<SwitchbindStrings> | ||
> = { | ||
en: new SwitchbindENTranslation(), | ||
kr: new SwitchbindKRTranslation(), | ||
id: new SwitchbindIDTranslation(), | ||
es: new SwitchbindESTranslation(), | ||
}; | ||
} |
14 changes: 14 additions & 0 deletions
14
...ion/interactions/commands/Bot Creators/switchbind/translations/SwitchbindENTranslation.ts
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,14 @@ | ||
import { Translation } from "@localization/base/Translation"; | ||
import { SwitchbindStrings } from "../SwitchbindLocalization"; | ||
|
||
/** | ||
* The English translation of the `switchbind` command. | ||
*/ | ||
export class SwitchbindENTranslation extends Translation<SwitchbindStrings> { | ||
override readonly translations: SwitchbindStrings = { | ||
invalidUid: "Hey, please enter a valid uid!", | ||
uidNotBinded: "I'm sorry, this uid is not bound to anyone!", | ||
switchFailed: "I'm sorry, I'm unable to switch the bind: %s.", | ||
switchSuccessful: "Successfully switched bind.", | ||
}; | ||
} |
14 changes: 14 additions & 0 deletions
14
...ion/interactions/commands/Bot Creators/switchbind/translations/SwitchbindESTranslation.ts
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,14 @@ | ||
import { Translation } from "@localization/base/Translation"; | ||
import { SwitchbindStrings } from "../SwitchbindLocalization"; | ||
|
||
/** | ||
* The Spanish translation of the `switchbind` command. | ||
*/ | ||
export class SwitchbindESTranslation extends Translation<SwitchbindStrings> { | ||
override readonly translations: SwitchbindStrings = { | ||
invalidUid: "Hey, por favor ingresa un uid válido!", | ||
uidNotBinded: "Lo siento, ese uid no esta asociado a nadie!", | ||
switchFailed: "Lo siento, no puedo cambiar el enlace: %s.", | ||
switchSuccessful: "Enlace cambiado correctamente.", | ||
}; | ||
} |
14 changes: 14 additions & 0 deletions
14
...ion/interactions/commands/Bot Creators/switchbind/translations/SwitchbindIDTranslation.ts
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,14 @@ | ||
import { Translation } from "@localization/base/Translation"; | ||
import { SwitchbindStrings } from "../SwitchbindLocalization"; | ||
|
||
/** | ||
* The Indonesian translation of the `switchbind` command. | ||
*/ | ||
export class SwitchbindIDTranslation extends Translation<SwitchbindStrings> { | ||
override readonly translations: SwitchbindStrings = { | ||
invalidUid: "Hei, mohon berikan uid yang benar!", | ||
uidNotBinded: "Maaf, uid ini tidak terhubung ke seorang pengguna!", | ||
switchFailed: "Maaf, aku tidak bisa memindahkan uid tersebut: %s.", | ||
switchSuccessful: "Berhasil memindahkan uid.", | ||
}; | ||
} |
14 changes: 14 additions & 0 deletions
14
...ion/interactions/commands/Bot Creators/switchbind/translations/SwitchbindKRTranslation.ts
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,14 @@ | ||
import { Translation } from "@localization/base/Translation"; | ||
import { SwitchbindStrings } from "../SwitchbindLocalization"; | ||
|
||
/** | ||
* The Korean translation of the `switchbind` command. | ||
*/ | ||
export class SwitchbindKRTranslation extends Translation<SwitchbindStrings> { | ||
override readonly translations: SwitchbindStrings = { | ||
invalidUid: "저기, 올바른 uid를 입력해 주세요!", | ||
uidNotBinded: "죄송해요, 이 uid는 누구에게도 바인딩 되어있지 않아요!", | ||
switchFailed: "죄송해요, 바인딩을 변경할 수 없어요: %s.", | ||
switchSuccessful: "성공적으로 바인딩을 변경했어요.", | ||
}; | ||
} |