mirror of
https://github.com/darksaid98/cadence-discord-bot.git
synced 2026-12-03 14:38:49 +00:00
Export type in locale util
This commit is contained in:
1 parent
e1b0aea7fc
commit
115b9cc0b2
26 files changed
+131
-150
No files matched your search
@@ -25,7 +25,7 @@ import {
|
||||
BaseSlashCommandReturnType
|
||||
} from '../../types/interactionTypes';
|
||||
import { Validator, ValidatorParams } from '../../types/utilTypes';
|
||||
import { TFunction } from 'i18next';
|
||||
import { Translator } from '../utils/localeUtil';
|
||||
|
||||
abstract class BaseInteraction {
|
||||
embedOptions: EmbedOptions;
|
||||
@@ -72,7 +72,7 @@ abstract class BaseInteraction {
|
||||
return durationFormat;
|
||||
}
|
||||
|
||||
protected getFormattedTrackUrl(track: Track, translator: TFunction): string {
|
||||
protected getFormattedTrackUrl(track: Track, translator: Translator): string {
|
||||
const trackTitle = track.title ?? translator('musicPlayerCommon.unavailableTrackTitle');
|
||||
const trackUrl = track.url ?? track.raw.url;
|
||||
if (!trackTitle || !trackUrl) {
|
||||
@@ -81,7 +81,7 @@ abstract class BaseInteraction {
|
||||
return `**[${trackTitle}](${trackUrl})**`;
|
||||
}
|
||||
|
||||
protected getDisplayTrackDurationAndUrl(track: Track, translator: TFunction): string {
|
||||
protected getDisplayTrackDurationAndUrl(track: Track, translator: Translator): string {
|
||||
const formattedDuration = this.getFormattedDuration(track);
|
||||
const formattedUrl = this.getFormattedTrackUrl(track, translator);
|
||||
|
||||
@@ -117,7 +117,7 @@ abstract class BaseInteraction {
|
||||
protected getFooterDisplayPageInfo(
|
||||
interaction: ChatInputCommandInteraction,
|
||||
queue: GuildQueue | GuildQueueHistory,
|
||||
translator: TFunction
|
||||
translator: Translator
|
||||
): EmbedFooterData {
|
||||
const pageIndex: number = (interaction.options.getInteger('page') || 1) - 1;
|
||||
const totalPages: number = Math.ceil(queue.tracks.data.length / 10) || 1;
|
||||
@@ -130,13 +130,13 @@ abstract class BaseInteraction {
|
||||
};
|
||||
}
|
||||
|
||||
protected getDisplayTrackRequestedBy = (track: Track, translator: TFunction): string => {
|
||||
protected getDisplayTrackRequestedBy = (track: Track, translator: Translator): string => {
|
||||
return track.requestedBy
|
||||
? `<@${track.requestedBy.id}>`
|
||||
: translator('musicPlayerCommon.unavailableRequestedBy');
|
||||
};
|
||||
|
||||
protected getDisplayQueueProgressBar(queue: GuildQueue, translator: TFunction): string {
|
||||
protected getDisplayQueueProgressBar(queue: GuildQueue, translator: Translator): string {
|
||||
const timestamp: PlayerTimestamp = queue.node.getTimestamp()!;
|
||||
let progressBar: string = `**\`${timestamp.current.label}\`** ${queue.node.createProgressBar({
|
||||
queue: false,
|
||||
@@ -189,7 +189,7 @@ abstract class BaseInteractionWithEmbedResponse extends BaseInteraction {
|
||||
protected getEmbedQueueAuthor(
|
||||
interaction: MessageComponentInteraction | ChatInputCommandInteraction,
|
||||
queue: GuildQueue,
|
||||
translator: TFunction
|
||||
translator: Translator
|
||||
): EmbedAuthorOptions {
|
||||
const bitrate = queue.channel ? queue.channel.bitrate / 1000 : 0;
|
||||
return {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Track } from 'discord-player';
|
||||
import { TFunction } from 'i18next';
|
||||
import { Translator } from './localeUtil';
|
||||
|
||||
export function shouldUseLastQuery(query: string, lastQuery?: string, timestamp?: number): boolean {
|
||||
return Boolean(
|
||||
@@ -11,7 +11,7 @@ export function isQueryTooShort(query: string): boolean {
|
||||
return query.length < 3;
|
||||
}
|
||||
|
||||
export function getTrackName(track: Track, translator: TFunction): string {
|
||||
export function getTrackName(track: Track, translator: Translator): string {
|
||||
const name = translator('autocomplete.trackName', {
|
||||
title: track.title,
|
||||
author: track.author
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { QueueRepeatMode } from 'discord-player';
|
||||
import { TFunction } from 'i18next';
|
||||
import { Translator } from './localeUtil';
|
||||
import { EmbedOptions } from '../../types/configTypes';
|
||||
|
||||
export function formatDuration(durationMs: number): string {
|
||||
@@ -22,14 +22,14 @@ export function formatDuration(durationMs: number): string {
|
||||
}
|
||||
}
|
||||
|
||||
export function formatSlashCommand(commandName: string, translator: TFunction): string {
|
||||
export function formatSlashCommand(commandName: string, translator: Translator): string {
|
||||
const translatedName = translator(`commands.${commandName}.metadata.name`, {
|
||||
defaultValue: commandName
|
||||
});
|
||||
return `**\`/${translatedName}\`**`;
|
||||
}
|
||||
|
||||
export function formatRepeatMode(repeatMode: QueueRepeatMode, translator: TFunction): string {
|
||||
export function formatRepeatMode(repeatMode: QueueRepeatMode, translator: Translator): string {
|
||||
switch (repeatMode) {
|
||||
case QueueRepeatMode.AUTOPLAY:
|
||||
return translator('musicPlayerCommon.queueRepeatMode.autoplay');
|
||||
@@ -45,7 +45,7 @@ export function formatRepeatMode(repeatMode: QueueRepeatMode, translator: TFunct
|
||||
export function formatRepeatModeDetailed(
|
||||
repeatMode: QueueRepeatMode,
|
||||
embedOptions: EmbedOptions,
|
||||
translator: TFunction,
|
||||
translator: Translator,
|
||||
state: string = 'info'
|
||||
) {
|
||||
let icon: string;
|
||||
|
||||
@@ -10,10 +10,12 @@ import {
|
||||
SlashCommandSubcommandsOnlyBuilder
|
||||
} from 'discord.js';
|
||||
import { lstatSync, readdirSync } from 'fs';
|
||||
import i18n from 'i18next';
|
||||
import i18n, { TFunction } from 'i18next';
|
||||
import i18nextFsBackend, { FsBackendOptions } from 'i18next-fs-backend';
|
||||
import { join } from 'path';
|
||||
|
||||
export type Translator = TFunction;
|
||||
|
||||
export const translatorInstance = i18n.createInstance();
|
||||
const localeDir = join(__dirname, '..', '..', '..', 'locales');
|
||||
|
||||
@@ -36,15 +38,15 @@ translatorInstance.use(i18nextFsBackend).init<FsBackendOptions>({
|
||||
}
|
||||
});
|
||||
|
||||
export function useServerTranslator(interaction: BaseInteraction) {
|
||||
export function useServerTranslator(interaction: BaseInteraction): Translator {
|
||||
return translatorInstance.getFixedT(interaction.guildLocale ?? 'en-US');
|
||||
}
|
||||
|
||||
export function useUserTranslator(interaction: BaseInteraction) {
|
||||
export function useUserTranslator(interaction: BaseInteraction): Translator {
|
||||
return translatorInstance.getFixedT(interaction.locale ?? 'en-US');
|
||||
}
|
||||
|
||||
export function useLanguageTranslator(language: LocaleString) {
|
||||
export function useLanguageTranslator(language: LocaleString): Translator {
|
||||
return translatorInstance.getFixedT(language ?? 'en-US');
|
||||
}
|
||||
|
||||
|
||||
@@ -2,12 +2,12 @@ import osu from 'node-os-utils';
|
||||
import { ExtendedClient } from '../../types/clientTypes';
|
||||
import { fetchTotalGuildStatistics, fetchTotalPlayerStatistics } from './shardUtils';
|
||||
import { getUptimeFormatted } from './getUptimeFormatted';
|
||||
import { TFunction } from 'i18next';
|
||||
import { Translator } from './localeUtil';
|
||||
|
||||
export async function getBotStatistics(
|
||||
client: ExtendedClient,
|
||||
version: string,
|
||||
translator: TFunction
|
||||
translator: Translator
|
||||
): Promise<string> {
|
||||
const releaseVersion: string = version;
|
||||
const { totalGuildCount, totalMemberCount } = await fetchTotalGuildStatistics(client);
|
||||
@@ -27,7 +27,7 @@ export async function getBotStatistics(
|
||||
);
|
||||
}
|
||||
|
||||
export async function getPlayerStatistics(client: ExtendedClient, translator: TFunction): Promise<string> {
|
||||
export async function getPlayerStatistics(client: ExtendedClient, translator: Translator): Promise<string> {
|
||||
const { totalVoiceConnections, totalTracksInQueues, totalListeners } = await fetchTotalPlayerStatistics(client);
|
||||
|
||||
return (
|
||||
@@ -45,7 +45,7 @@ export async function getPlayerStatistics(client: ExtendedClient, translator: TF
|
||||
);
|
||||
}
|
||||
|
||||
export async function getSystemStatus(executionId: string, extended: boolean, translator: TFunction): Promise<string> {
|
||||
export async function getSystemStatus(executionId: string, extended: boolean, translator: Translator): Promise<string> {
|
||||
const uptimeString: string = getUptimeFormatted({ executionId });
|
||||
const usedMemoryInMB: number = Math.ceil((await osu.mem.info()).usedMemMb);
|
||||
const cpuUsage: number = await osu.cpu.usage();
|
||||
@@ -74,6 +74,6 @@ export async function getSystemStatus(executionId: string, extended: boolean, tr
|
||||
);
|
||||
}
|
||||
|
||||
export function getDiscordStatus(client: ExtendedClient, translator: TFunction): string {
|
||||
export function getDiscordStatus(client: ExtendedClient, translator: Translator): string {
|
||||
return translator('statistics.discordStatus.apiLatency', { value: client.ws.ping });
|
||||
}
|
||||
Reference in new issue
Block a user