Skip to content

Commit

Permalink
πŸ› οΈ Remove generics and fix inappropriate code
Browse files Browse the repository at this point in the history
  • Loading branch information
Nich87 committed Dec 3, 2023
1 parent ea7f568 commit 08b00a9
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 34 deletions.
2 changes: 1 addition & 1 deletion src/Events/onVoiceStateUpdate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ export async function onVoiceStateUpdate(oldState: VoiceState, newState: VoiceSt
queueManager.deleteQueue(newState.guild.id);
}

if (!queueManager.getQueue(newState.guild.id)) queueManager.setQueue(newState.guild.id, new Queue<string>());
if (!queueManager.getQueue(newState.guild.id)) queueManager.setQueue(newState.guild.id, new Queue());
}
4 changes: 2 additions & 2 deletions src/classes/player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export class YTPlayer {
private connection: import('@discordjs/voice').VoiceConnection;
public player: import('@discordjs/voice').AudioPlayer;
public serverId: Snowflake;
public queue: Queue<string>;
public queue: Queue;
public volume: number;
public isPlaying: boolean;
public resource: import('@discordjs/voice').AudioResource | null;
Expand All @@ -24,7 +24,7 @@ export class YTPlayer {
selfMute: false
});
this.player = createAudioPlayer();
this.queue = queueManager.getQueue(serverId) as Queue<string>;
this.queue = queueManager.getQueue(serverId) as Queue;
this.volume = 100 / 10;
this.player
.on('subscribe', () => {
Expand Down
10 changes: 5 additions & 5 deletions src/classes/queue.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Snowflake } from 'discord.js';

export class Queue<T> {
export class Queue {
private _store: string[];
public loop: 'none' | 'queue' | 'track';

Expand Down Expand Up @@ -53,21 +53,21 @@ export class Queue<T> {
}
}
class QueueManager {
private _queues: Map<Snowflake, Queue<string>>;
private _queues: Map<Snowflake, Queue>;

constructor() {
this._queues = new Map();
}

public get queues(): Map<Snowflake, Queue<string>> {
public get queues(): Map<Snowflake, Queue> {
return this._queues;
}

public getQueue(serverId: Snowflake): Queue<string> | undefined {
public getQueue(serverId: Snowflake): Queue | undefined {
return this._queues.get(serverId);
}

public setQueue(serverId: Snowflake, queue: Queue<string>): void {
public setQueue(serverId: Snowflake, queue: Queue): void {
this._queues.set(serverId, queue);
}

Expand Down
22 changes: 11 additions & 11 deletions src/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import { skipCommand } from './skip';
import { stopCommand } from './stop';

export const commands = {
changeVolume: changeVolumeCommand,
help: helpCommand,
loop: loopCommand,
nowplaying: nowplayingCommand,
pause: pauseCommand,
play: playCommand,
queue: queueCommand,
resume: resumeCommand,
skip: skipCommand,
stop: stopCommand
};
changeVolume: changeVolumeCommand,
help: helpCommand,
loop: loopCommand,
nowplaying: nowplayingCommand,
pause: pauseCommand,
play: playCommand,
queue: queueCommand,
resume: resumeCommand,
skip: skipCommand,
stop: stopCommand
};
8 changes: 4 additions & 4 deletions src/commands/loop.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { queueManager } from '../classes/queue';
import { queueManager, Queue } from '../classes/queue';
import { player } from './play';
import { Message, EmbedBuilder } from 'discord.js';

export async function loopCommand(message: Message, args: string[]) {
if (typeof player === 'undefined') return message.reply({ content: 'ε‹•η”»γŒε†η”Ÿγ•γ‚Œγ¦γ„γΎγ›γ‚“γ€‚' });
const queue = queueManager.queues.get(message.guildId!);
const queue = queueManager.queues.get(message.guildId!) as Queue;
args = args.filter((arg) => arg !== '');
if (args.length === 0) {
queue?.loop === 'none' ? queue?.setLoop('queue') : queue?.setLoop('none');
queue.loop === 'none' ? queue.setLoop('queue') : queue.setLoop('none');
} else if (args.length === 1) {
switch (args[0]) {
case 'none':
Expand All @@ -30,6 +30,6 @@ export async function loopCommand(message: Message, args: string[]) {
}

message.reply({
embeds: [new EmbedBuilder().addFields({ name: 'Looping', value: queue?.loop! }).setColor('Green')]
embeds: [new EmbedBuilder().addFields({ name: 'Looping', value: queue.loop! }).setColor('Green')]
});
}
2 changes: 1 addition & 1 deletion src/commands/nowplaying.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Message } from 'discord.js';

export async function nowplayingCommand(message: Message) {
if (typeof player === 'undefined') return message.reply({ content: 'ε‹•η”»γŒε†η”Ÿγ•γ‚Œγ¦γ„γΎγ›γ‚“γ€‚' });
const queue = queueManager.getQueue(message.guild?.id as string) as Queue<string>;
const queue = queueManager.getQueue(message.guild?.id as string) as Queue;
if (!queue.currentSong) return message.reply({ content: 'γ‚­γƒ₯γƒΌγ«ζ›²γŒγ‚γ‚ŠγΎγ›γ‚“γ€‚' });
const info = await getSongInfo(queue.currentSong);
return message.reply(info);
Expand Down
6 changes: 3 additions & 3 deletions src/commands/play.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export async function playCommand(message: Message) {
if (typeof queueManager.getQueue(message.guild?.id as string) === 'undefined') {
queueManager.setQueue(message.guild?.id as string, new Queue());
}
const queue = queueManager.getQueue(message.guild?.id as string)?.store as string[];
const queue = queueManager.getQueue(message.guild?.id as string) as Queue;

player = new YTPlayer(message.guild?.id as string, message.member?.voice.channel as VoiceBasedChannel);
url = message.content.split(' ')[1];
Expand Down Expand Up @@ -49,7 +49,7 @@ export async function playCommand(message: Message) {
});

if (!queue.length || player.isPlaying) {
queue.push(url);
queue.addSong(url);
const info = await ytdl.getInfo(url);
message.reply({
embeds: [
Expand All @@ -66,7 +66,7 @@ export async function playCommand(message: Message) {
});
if (queue.length === 1) return player.play();
} else {
queue.push(url);
queue.addSong(url);
const info = await ytdl.getInfo(url);
message.reply({
embeds: [
Expand Down
8 changes: 4 additions & 4 deletions src/commands/queue.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { songResolver } from '../Utils/songResolver';
import { queueManager } from '../classes/queue';
import { Queue, queueManager } from '../classes/queue';
import { player } from './play';
import { Message, EmbedBuilder } from 'discord.js';
import ytdl from 'ytdl-core';

export async function queueCommand(message: Message) {
if (typeof player === 'undefined') return message.reply({ content: 'ε‹•η”»γŒε†η”Ÿγ•γ‚Œγ¦γ„γΎγ›γ‚“γ€‚' });
const queue = queueManager.getQueue(message.guildId!);
if (!queue?.store.length) {
const queue = queueManager.getQueue(message.guildId!) as Queue;
if (!queue.length) {
return message.reply({
embeds: [new EmbedBuilder().addFields({ name: 'Info', value: 'γ‚­γƒ₯γƒΌγŒη©Ίγ§γ™γ€‚' }).setColor('Yellow')]
});
}
const embed = new EmbedBuilder().setTitle('Queue').setColor('Blue').setTimestamp();
for (let i = 0; i < queue.store.length; i++) {
for (let i = 0; i < queue.length; i++) {
const url = queue.store[i];
const info = await ytdl.getInfo(url);
const song = songResolver(info, message.author.username, message.author.avatarURL()!);
Expand Down
6 changes: 3 additions & 3 deletions src/commands/skip.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { queueManager } from '../classes/queue';
import { Queue, queueManager } from '../classes/queue';
import { player } from './play';
import { Message, EmbedBuilder } from 'discord.js';

export async function skipCommand(message: Message) {
if (typeof player === 'undefined') return message.reply({ content: 'ε‹•η”»γŒε†η”Ÿγ•γ‚Œγ¦γ„γΎγ›γ‚“γ€‚' });
const queue = queueManager.queues.get(message.guildId!);
const queue = queueManager.queues.get(message.guildId!) as Queue;

if (!queue?.store.length) {
if (!queue.length) {
return message.reply({
embeds: [new EmbedBuilder().addFields({ name: 'Info', value: 'γ‚­γƒ₯γƒΌγŒη©Ίγ§γ™γ€‚' }).setColor('Yellow')]
});
Expand Down

0 comments on commit 08b00a9

Please sign in to comment.