Skip to content

Commit

Permalink
Reorganized command structure
Browse files Browse the repository at this point in the history
  • Loading branch information
Struck713 committed Feb 23, 2024
1 parent d61ebaa commit b6056ad
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 155 deletions.
2 changes: 1 addition & 1 deletion src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import commands from "./commands";
import { StateManager } from "./lib/state";
import YTDlpWrap from "yt-dlp-wrap";
import { Embeds } from "./lib/utils/embeds";
import { PollManager } from "./commands/poll";
import { PollManager } from "./commands/admin/poll";

export const ytdl = new YTDlpWrap(youtube.binary_path);
export const client = new Client({
Expand Down
6 changes: 3 additions & 3 deletions src/commands/deploy.ts → src/commands/admin/deploy.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { SlashCommandBuilder } from "discord.js";
import { Command, deploy } from "../lib/command";
import { Embeds } from "../lib/utils/embeds";
import commands from ".";
import { Command, deploy } from "../../lib/command";
import { Embeds } from "../../lib/utils/embeds";
import commands from "..";

const MY_SNOWFLAKE = "140520164629151744";

Expand Down
13 changes: 6 additions & 7 deletions src/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ import { Play } from "../commands/voice/play";
import { Skip } from "../commands/voice/skip"
import { Queue } from "../commands/voice/queue";
import { Stop } from "../commands/voice/stop";
import { Deploy } from "../commands/deploy";
import { Status } from "../commands/status";
import { Meme } from "./meme";
import { Help } from "./help";
import { Poll } from "./poll";
import { Oobinate } from "./oob";
import { Deploy } from "./admin/deploy";
import { Status } from "./misc/status";
import { Meme } from "./silly/meme";
import { Help } from "./misc/help";
import { Oobinate } from "./silly/oob";

const commands = [ Help, Play, Skip, Queue, Stop, Meme, Oobinate, Poll, Status, Deploy ];
const commands = [ Help, Play, Skip, Queue, Stop, Meme, Oobinate, Status, Deploy ];
export default commands;
6 changes: 3 additions & 3 deletions src/commands/help.ts → src/commands/misc/help.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { SlashCommandBuilder } from "discord.js";
import { Command } from "../lib/command";
import { Embeds } from "../lib/utils/embeds";
import commands from ".";
import { Command } from "../../lib/command";
import { Embeds } from "../../lib/utils/embeds";
import commands from "..";

export const Help: Command = {
data: new SlashCommandBuilder()
Expand Down
8 changes: 4 additions & 4 deletions src/commands/status.ts → src/commands/misc/status.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { SlashCommandBuilder } from "discord.js";
import { Command } from "../lib/command";
import { Embeds } from "../lib/utils/embeds";
import { Style } from "../lib/utils/style";
import Time from "../lib/utils/time";
import { Command } from "../../lib/command";
import { Embeds } from "../../lib/utils/embeds";
import { Style } from "../../lib/utils/style";
import Time from "../../lib/utils/time";

const STARTUP_TIME = Date.now();

Expand Down
103 changes: 0 additions & 103 deletions src/commands/poll.ts

This file was deleted.

4 changes: 2 additions & 2 deletions src/commands/meme.ts → src/commands/silly/meme.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { AttachmentBuilder, SlashCommandBuilder } from "discord.js";
import { Command } from "../lib/command";
import { Command } from "../../lib/command";
import axios from "axios";
import { Embeds } from "../lib/utils/embeds";
import { Embeds } from "../../lib/utils/embeds";

export const Meme: Command = {
data: new SlashCommandBuilder()
Expand Down
4 changes: 2 additions & 2 deletions src/commands/oob.ts → src/commands/silly/oob.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { SlashCommandBuilder } from "discord.js";
import { Command } from "../lib/command";
import { Embeds } from "../lib/utils/embeds";
import { Command } from "../../lib/command";
import { Embeds } from "../../lib/utils/embeds";

export const Oobinate: Command = {
data: new SlashCommandBuilder()
Expand Down
52 changes: 23 additions & 29 deletions src/commands/voice/play.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import * as VoiceManager from "../../lib/voice";
export const Play: Command = {
data: new SlashCommandBuilder()
.setName("play")
.setDescription("Play sound in a voice channel using a URL.")
.setDescription("Play a song by search.")
.addStringOption(option => option.setName("search").setRequired(true).setDescription("A valid YouTube search, picking the top result.")),
execute: async (client, interaction) => {
execute: async (_, interaction) => {

if (!interaction.guild || !interaction.member) {
await Embeds.error(interaction, "You are not in a guild!");
Expand All @@ -23,32 +23,18 @@ export const Play: Command = {
return;
}

let search = interaction.options.get("search", false);
if (search) {
let metadata = await YouTubeAPI.search(search.value as string);
if (!metadata) {
await Embeds.error(interaction, `Could not find anything associated with \`${search.value}\``);
return;
}

let connection = VoiceManager.getVoiceFromGuildId(interaction.guild.id);
if (connection) {
connection.play(metadata);
Embeds.create()
.setAuthor({ name: "Added to queue" })
.setTitle(metadata.getTitle())
.setURL(metadata.getUrl())
.setDescription(`by ${metadata.getAuthor()}`)
.setImage(metadata.getThumbnailUrl())
.send(interaction);
return;
}

connection = VoiceManager.initializeVoice(user.voice.channel);
let search = interaction.options.get("search", true);
let metadata = await YouTubeAPI.search(search.value as string);
if (!metadata) {
await Embeds.error(interaction, `Could not find anything associated with \`${search.value}\``);
return;
}

let connection = VoiceManager.getVoiceFromGuildId(interaction.guild.id);
if (connection) {
connection.play(metadata);

await Embeds.create()
.setAuthor({ name: "Now Playing"})
Embeds.create()
.setAuthor({ name: "Added to queue" })
.setTitle(metadata.getTitle())
.setURL(metadata.getUrl())
.setDescription(`by ${metadata.getAuthor()}`)
Expand All @@ -57,7 +43,15 @@ export const Play: Command = {
return;
}

await Embeds.error(interaction, `Please specify either a search or valid YouTube URL.`);
return;
connection = VoiceManager.initializeVoice(user.voice.channel);
connection.play(metadata);

await Embeds.create()
.setAuthor({ name: "Now Playing"})
.setTitle(metadata.getTitle())
.setURL(metadata.getUrl())
.setDescription(`by ${metadata.getAuthor()}`)
.setImage(metadata.getThumbnailUrl())
.send(interaction);
},
}
6 changes: 5 additions & 1 deletion src/lib/utils/embeds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ export namespace Embeds {
.setColor(Style.Color.DEFAULT)
.setTimestamp()
.setFooter({ text: Style.ENGINE_VERSION, iconURL: Style.PROFILE_URL });
return Object.assign(embed, { send: (interaction: CommandInteraction<CacheType>) => { return interaction.followUp({ embeds: [embed] }); } });
return Object.assign(embed, {
send: (interaction: CommandInteraction<CacheType>) => {
return interaction.followUp({ embeds: [embed] });
}
});
}

export const error = async (interaction: CommandInteraction<CacheType>, message: string, subtitle?: string) => {
Expand Down

0 comments on commit b6056ad

Please sign in to comment.