Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| efa52dffbc | |||
| 3354289207 | |||
| 4fbf308650 | |||
| 4033b6f6b5 | |||
| d3a6decef6 | |||
| 4718e68c78 | |||
| 7c282105d3 |
+9
-1
@@ -10,7 +10,7 @@ import {
|
||||
} from 'discord.js';
|
||||
import { Logger } from './utils/log';
|
||||
import { config } from './utils/config';
|
||||
import { CommandManager } from './commands';
|
||||
import { Command, CommandCategory, CommandManager } from './commands';
|
||||
import { DatabaseManager } from './modules/db';
|
||||
|
||||
type BotEventListeners = {
|
||||
@@ -83,6 +83,14 @@ export class Bot {
|
||||
await this.client.login(config.token);
|
||||
}
|
||||
|
||||
public getCommands(): Array<Command> {
|
||||
return this.cmdMgr.getAll();
|
||||
}
|
||||
|
||||
public getCategories(): Array<CommandCategory> {
|
||||
return this.cmdMgr.getCategories();
|
||||
}
|
||||
|
||||
/*
|
||||
event listeners
|
||||
*/
|
||||
|
||||
+1
-1
@@ -43,7 +43,7 @@ export interface CommandCategoryInfo {
|
||||
description: string;
|
||||
}
|
||||
|
||||
interface CommandCategory {
|
||||
export interface CommandCategory {
|
||||
info: CommandCategoryInfo;
|
||||
commands: Command[];
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
import { CommandCategoryInfo } from '../../commands';
|
||||
|
||||
const info: CommandCategoryInfo = {
|
||||
name: 'General',
|
||||
description: 'General / uncategorized commands'
|
||||
};
|
||||
|
||||
export default info;
|
||||
@@ -0,0 +1,32 @@
|
||||
import { ChatInputCommandInteraction, EmbedBuilder, SlashCommandBuilder } from "discord.js";
|
||||
import { Command } from "../../commands";
|
||||
import { Bot } from "../../bot";
|
||||
|
||||
const builder = new SlashCommandBuilder()
|
||||
.setName('commands')
|
||||
.setDescription('Shows a list of all the commands.');
|
||||
|
||||
const cmd: Command = {
|
||||
name: builder.name,
|
||||
builder: builder,
|
||||
execute: async (interaction: ChatInputCommandInteraction): Promise<void> => {
|
||||
const responseEmbed = new EmbedBuilder()
|
||||
.setColor("Blurple")
|
||||
.setTitle("Command List");
|
||||
|
||||
const bot = Bot.get;
|
||||
bot.getCategories().forEach(({ info, commands }) => {
|
||||
const fieldBody = commands
|
||||
.filter(({ builder }) => builder)
|
||||
.map(({ builder }) => `• **${builder?.name}** - ${builder?.description}`)
|
||||
.join("\n");
|
||||
|
||||
responseEmbed.addFields({ name: info.name, value: fieldBody });
|
||||
});
|
||||
|
||||
await interaction.reply({ embeds: [responseEmbed] });
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
export default cmd;
|
||||
@@ -0,0 +1,16 @@
|
||||
import { ChatInputCommandInteraction, SlashCommandBuilder } from "discord.js";
|
||||
import { Command } from "../../commands";
|
||||
|
||||
const builder = new SlashCommandBuilder()
|
||||
.setName('ping')
|
||||
.setDescription('Pong.');
|
||||
|
||||
const cmd: Command = {
|
||||
name: builder.name,
|
||||
builder: builder,
|
||||
execute: async (interaction: ChatInputCommandInteraction): Promise<void> => {
|
||||
interaction.reply('pong!');
|
||||
}
|
||||
};
|
||||
|
||||
export default cmd;
|
||||
@@ -1,5 +1,7 @@
|
||||
import { ChatInputCommandInteraction, SlashCommandBuilder } from 'discord.js';
|
||||
import { Command } from '../../commands';
|
||||
import { getVoiceConnection, VoiceConnectionStatus } from '@discordjs/voice';
|
||||
import { AudioStreamManager } from '../../modules/audiostreams';
|
||||
|
||||
const builder = new SlashCommandBuilder()
|
||||
.setName('tts-clear')
|
||||
@@ -10,11 +12,19 @@ const cmd: Command = {
|
||||
builder: builder,
|
||||
requiresAdmin: true,
|
||||
execute: async (interaction: ChatInputCommandInteraction): Promise<void> => {
|
||||
if (!interaction.guildId) {
|
||||
if (!interaction.guild) {
|
||||
interaction.reply('This command only works on Guilds');
|
||||
return;
|
||||
}
|
||||
|
||||
const voiceConnection = getVoiceConnection(interaction.guild.id);
|
||||
if (voiceConnection?.state.status !== VoiceConnectionStatus.Ready) return;
|
||||
|
||||
const stream = AudioStreamManager.get.getOrCreateStream(voiceConnection);
|
||||
|
||||
const queue = stream.getQueue('TTS');
|
||||
queue.clear();
|
||||
|
||||
interaction.reply('Queue cleared.');
|
||||
}
|
||||
};
|
||||
|
||||
@@ -50,9 +50,11 @@ const cmd: Command = {
|
||||
const modes = TTSManager.get.getModules();
|
||||
|
||||
const filtered: string[] = modes
|
||||
.filter((mode) =>
|
||||
mode.name.toLowerCase().startsWith(focused.value.toLowerCase())
|
||||
)
|
||||
.filter((mode) => {
|
||||
return mode.name
|
||||
? mode.name.toLowerCase().startsWith(focused.value.toLowerCase())
|
||||
: undefined;
|
||||
})
|
||||
.map((mode) => mode.name)
|
||||
.slice(0, 25);
|
||||
|
||||
|
||||
@@ -1,37 +1,37 @@
|
||||
import { TTSModule, TTSResponse } from "../tts";
|
||||
import { TTSModule, TTSResponse } from '../tts';
|
||||
|
||||
import { VoicesManager, Communicate } from 'edge-tts-universal';
|
||||
|
||||
class AzureTTS implements TTSModule {
|
||||
private voices: Array<string> | undefined = undefined;
|
||||
private voices: Array<string> | undefined = undefined;
|
||||
|
||||
public name: string = "Azure";
|
||||
public name: string = 'Azure';
|
||||
|
||||
async getVoices(): Promise<Array<string> | undefined> {
|
||||
if (!this.voices) {
|
||||
const voiceMgr = await VoicesManager.create();
|
||||
const voiceQuery = await voiceMgr.find({});
|
||||
async getVoices(): Promise<Array<string> | undefined> {
|
||||
if (!this.voices) {
|
||||
const voiceMgr = await VoicesManager.create();
|
||||
const voiceQuery = await voiceMgr.find({});
|
||||
|
||||
this.voices = voiceQuery.map((voice) => voice.ShortName);
|
||||
}
|
||||
this.voices = voiceQuery.map((voice) => voice.ShortName);
|
||||
}
|
||||
|
||||
return this.voices;
|
||||
};
|
||||
return this.voices;
|
||||
}
|
||||
|
||||
async generate(voice: string, text: string): Promise<TTSResponse> {
|
||||
const comm = new Communicate(text, {
|
||||
voice: voice
|
||||
});
|
||||
async generate(voice: string, text: string): Promise<TTSResponse> {
|
||||
const comm = new Communicate(text, {
|
||||
voice: voice
|
||||
});
|
||||
|
||||
const buffers: Buffer[] = [];
|
||||
for await (const chunk of comm.stream()) {
|
||||
if (chunk.type === 'audio' && chunk.data) {
|
||||
buffers.push(chunk.data);
|
||||
}
|
||||
}
|
||||
const buffers: Buffer[] = [];
|
||||
for await (const chunk of comm.stream()) {
|
||||
if (chunk.type === 'audio' && chunk.data) {
|
||||
buffers.push(chunk.data);
|
||||
}
|
||||
}
|
||||
|
||||
return { data: Buffer.concat(buffers) };
|
||||
};
|
||||
return { data: Buffer.concat(buffers) };
|
||||
}
|
||||
}
|
||||
|
||||
export default new AzureTTS();
|
||||
|
||||
Reference in New Issue
Block a user