Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

transcribe ephemeral context menu #8

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions languages/en-US.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ export default {
PONG: "Pong! (Host latency of {{hostLatency}}ms)",

TRANSCRIBE_COMMAND_NAME: "Transcribe",
TRANSCRIBE_EPHEMERAL_COMMAND_NAME: "Transcribe Ephemeral",

PREMIUM_COMMAND_NAME: "premium",
PREMIUM_COMMAND_DESCRIPTION: "Manage Yapper premium.",
Expand Down
55 changes: 36 additions & 19 deletions src/bot/applicationCommands/transcribe/transcribeContextMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,7 @@ import type ExtendedClient from "../../../../lib/extensions/ExtendedClient.js";
import Functions, { TranscriptionModel } from "../../../../lib/utilities/functions.js";
import type { APIInteractionWithArguments } from "../../../../typings/index";

export default class TranscribeContextMenu extends ApplicationCommand {
/**
* Create our transcribe context menu command.
*
* @param client - Our extended client.
*/
public constructor(client: ExtendedClient) {
super(client, {
options: {
...client.languageHandler.generateLocalizationsForApplicationCommandOptionTypeStringWithChoices({
name: "TRANSCRIBE_COMMAND_NAME",
}),
type: ApplicationCommandType.Message,
integration_types: [ApplicationIntegrationType.GuildInstall, ApplicationIntegrationType.UserInstall],
contexts: [0, 1, 2],
},
});
}

export class BaseTranscribeContextMenu extends ApplicationCommand {
/**
* Run this application command.
*
Expand All @@ -42,10 +24,12 @@ export default class TranscribeContextMenu extends ApplicationCommand {
public override async run({
interaction,
language,
ephemeral,
}: {
interaction: APIInteractionWithArguments<APIMessageApplicationCommandInteraction>;
language: Language;
shardId: number;
ephemeral: boolean;
}) {
const message = interaction.data.resolved.messages[interaction.data.target_id];

Expand Down Expand Up @@ -139,6 +123,7 @@ export default class TranscribeContextMenu extends ApplicationCommand {
await this.client.api.interactions.reply(interaction.id, interaction.token, {
content: language.get("TRANSCRIBING"),
allowed_mentions: { parse: [] },
...(ephemeral && { flags: MessageFlags.Ephemeral }),
});

const endpointHealth = await Functions.getEndpointHealth(TranscriptionModel.LARGEV3);
Expand All @@ -165,3 +150,35 @@ export default class TranscribeContextMenu extends ApplicationCommand {
});
}
}

export default class TranscribeContextMenu extends BaseTranscribeContextMenu {
/**
* Create our transcribe context menu command.
*
* @param client - Our extended client.
*/
public constructor(client: ExtendedClient) {
super(client, {
options: {
...client.languageHandler.generateLocalizationsForApplicationCommandOptionTypeStringWithChoices({
name: "TRANSCRIBE_COMMAND_NAME",
}),
type: ApplicationCommandType.Message,
integration_types: [ApplicationIntegrationType.GuildInstall, ApplicationIntegrationType.UserInstall],
contexts: [0, 1, 2],
},
});
}

public override async run({
interaction,
language,
shardId,
}: {
interaction: APIInteractionWithArguments<APIMessageApplicationCommandInteraction>;
language: Language;
shardId: number;
}) {
return super.run({ interaction, language, shardId, ephemeral: false });
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import type { APIMessageApplicationCommandInteraction } from "@discordjs/core";
import { ApplicationCommandType, ApplicationIntegrationType } from "@discordjs/core";
import type Language from "../../../../lib/classes/Language.js";
import type ExtendedClient from "../../../../lib/extensions/ExtendedClient.js";
import type { APIInteractionWithArguments } from "../../../../typings/index";
import { BaseTranscribeContextMenu } from "./transcribeContextMenu.js";

export default class TranscribeEphemeralContextMenu extends BaseTranscribeContextMenu {
/**
* Create our transcribe context menu command.
*
* @param client - Our extended client.
*/
public constructor(client: ExtendedClient) {
super(client, {
options: {
...client.languageHandler.generateLocalizationsForApplicationCommandOptionTypeStringWithChoices({
name: "TRANSCRIBE_EPHEMERAL_COMMAND_NAME",
}),
type: ApplicationCommandType.Message,
integration_types: [ApplicationIntegrationType.GuildInstall, ApplicationIntegrationType.UserInstall],
contexts: [0, 1, 2],
},
});
}

public override async run({
interaction,
language,
shardId,
}: {
interaction: APIInteractionWithArguments<APIMessageApplicationCommandInteraction>;
language: Language;
shardId: number;
}) {
return super.run({ interaction, language, shardId, ephemeral: true });
}
}