Skip to content

Commit

Permalink
4.1.0 stable build | Merge pull request #23 from RainyXeon/dev
Browse files Browse the repository at this point in the history
  • Loading branch information
RainyXeon authored Dec 27, 2023
2 parents a7df911 + be88cd9 commit 5459d0a
Show file tree
Hide file tree
Showing 72 changed files with 1,102 additions and 657 deletions.
20 changes: 20 additions & 0 deletions src/@types/Button.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import {
ButtonInteraction,
CacheType,
InteractionCollector,
Message,
} from "discord.js";
import { Manager } from "../manager.js";
import { KazagumoPlayer } from "kazagumo.mod";

export class PlayerButton {
name: string = "";
async run(
client: Manager,
message: ButtonInteraction,
language: string,
player: KazagumoPlayer,
nplaying: Message,
collector: InteractionCollector<ButtonInteraction<"cached">>
): Promise<any> {}
}
30 changes: 15 additions & 15 deletions src/lavaScrap/autofixLavalink.ts → src/autofix/AutoFixLavalink.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Manager } from "../manager.js";
import { LavalinkDataType } from "../@types/Lavalink.js";
import { checkLavalinkServer } from "./checkLavalinkServer.js";
import { CheckLavalinkServer } from "./CheckLavalinkServer.js";
const regex =
/^(wss?|ws?:\/\/)([0-9]{1,3}(?:\.[0-9]{1,3}){3}|[^\/]+):([0-9]{1,5})$/;

export class autofixLavalink {
export class AutoFixLavalink {
client: Manager;
constructor(client: Manager) {
this.client = client;
Expand All @@ -13,8 +13,8 @@ export class autofixLavalink {

async execute() {
this.client.logger.lavalink("----- Starting autofix lavalink... -----");
if (this.client.lavalink_list.length == 0) {
new checkLavalinkServer(this.client);
if (this.client.lavalinkList.length == 0) {
new CheckLavalinkServer(this.client);
return this.fixLavalink();
} else return this.fixLavalink();
}
Expand All @@ -24,7 +24,7 @@ export class autofixLavalink {
await this.removeCurrentLavalink();
const nodeInfo = await this.applyNewLavalink();

this.client.lavalink_using.push({
this.client.lavalinkUsing.push({
host: nodeInfo.host,
port: nodeInfo.port,
pass: nodeInfo.pass,
Expand All @@ -36,11 +36,11 @@ export class autofixLavalink {
checkLavalink() {
if (
this.client.manager.shoukaku.nodes.size !== 0 &&
this.client.lavalink_using.length == 0
this.client.lavalinkUsing.length == 0
) {
this.client.manager.shoukaku.nodes.forEach((data, index) => {
const res = regex.exec(data["url"]);
this.client.lavalink_using.push({
this.client.lavalinkUsing.push({
host: res![2],
port: Number(res![3]),
pass: data["auth"],
Expand All @@ -54,26 +54,26 @@ export class autofixLavalink {
async removeCurrentLavalink() {
if (
this.client.manager.shoukaku.nodes.size == 0 &&
this.client.lavalink_using.length != 0
this.client.lavalinkUsing.length != 0
) {
this.client.used_lavalink.push(this.client.lavalink_using[0]);
this.client.lavalink_using.splice(0, 1);
this.client.lavalinkUsed.push(this.client.lavalinkUsing[0]);
this.client.lavalinkUsing.splice(0, 1);
} else if (
this.client.manager.shoukaku.nodes.size !== 0 &&
this.client.lavalink_using.length !== 0
this.client.lavalinkUsing.length !== 0
) {
this.client.used_lavalink.push(this.client.lavalink_using[0]);
this.client.lavalinkUsed.push(this.client.lavalinkUsing[0]);
await this.client.manager.shoukaku.removeNode(
this.client.lavalink_using[0].name
this.client.lavalinkUsing[0].name
);
this.client.lavalink_using.splice(0, 1);
this.client.lavalinkUsing.splice(0, 1);
}
}

async applyNewLavalink() {
const online_list: LavalinkDataType[] = [];

this.client.lavalink_list.filter(async (data) => {
this.client.lavalinkList.filter(async (data) => {
if (data.online == true) return online_list.push(data);
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Manager } from "../manager.js";
import { Headers } from "../@types/Lavalink.js";
import { getLavalinkServer } from "./getLavalinkServer.js";
import { GetLavalinkServer } from "./GetLavalinkServer.js";
import Websocket from "ws";

export class checkLavalinkServer {
export class CheckLavalinkServer {
client: Manager;
constructor(client: Manager) {
this.client = client;
Expand All @@ -15,12 +15,12 @@ export class checkLavalinkServer {
"Running check lavalink server from [https://lavalink.darrennathanael.com/] source"
);

const getLavalinkServerClass = new getLavalinkServer();
const getLavalinkServerClass = new GetLavalinkServer();

const lavalink_data = await getLavalinkServerClass.execute();

if (this.client.lavalink_list.length !== 0)
this.client.lavalink_list.length = 0;
if (this.client.lavalinkList.length !== 0)
this.client.lavalinkList.length = 0;

for (let i = 0; i < lavalink_data!.length; i++) {
const config = lavalink_data![i];
Expand All @@ -36,7 +36,7 @@ export class checkLavalinkServer {

this.checkServerStatus(url, headers)
.then(() => {
this.client.lavalink_list.push({
this.client.lavalinkList.push({
host: config.host,
port: config.port,
pass: config.pass,
Expand All @@ -46,7 +46,7 @@ export class checkLavalinkServer {
});
})
.catch(() => {
this.client.lavalink_list.push({
this.client.lavalinkList.push({
host: config.host,
port: config.port,
pass: config.pass,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import fse from "fs-extra";
import { LoggerService } from "../services/LoggerService.js";
import Token from "markdown-it/lib/token.js";

export class getLavalinkServer {
export class GetLavalinkServer {
logger: any;
constructor() {
this.logger = new LoggerService().init();
Expand Down
File renamed without changes.
35 changes: 35 additions & 0 deletions src/buttons/Clear.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import {
ButtonInteraction,
CacheType,
InteractionCollector,
Message,
} from "discord.js";
import { KazagumoPlayer } from "kazagumo.mod";
import { PlayerButton } from "../@types/Button.js";
import { Manager } from "../manager.js";
import { ReplyInteractionService } from "../utilities/ReplyInteractionService.js";

export default class implements PlayerButton {
name = "clear";
async run(
client: Manager,
message: ButtonInteraction<CacheType>,
language: string,
player: KazagumoPlayer,
nplaying: Message<boolean>,
collector: InteractionCollector<ButtonInteraction<"cached">>
): Promise<any> {
if (!player) {
collector.stop();
}
player.queue.clear();

new ReplyInteractionService(
client,
message,
`${client.i18n.get(language, "player", "clear_msg")}`
);

return;
}
}
77 changes: 77 additions & 0 deletions src/buttons/Loop.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import {
ButtonInteraction,
CacheType,
InteractionCollector,
Message,
} from "discord.js";
import { KazagumoPlayer } from "kazagumo.mod";
import { PlayerButton } from "../@types/Button.js";
import { Manager } from "../manager.js";
import { KazagumoLoop } from "../@types/Lavalink.js";
import { ReplyInteractionService } from "../utilities/ReplyInteractionService.js";

export default class implements PlayerButton {
name = "loop";
async run(
client: Manager,
message: ButtonInteraction<CacheType>,
language: string,
player: KazagumoPlayer,
nplaying: Message<boolean>,
collector: InteractionCollector<ButtonInteraction<"cached">>
): Promise<any> {
if (!player) {
collector.stop();
}

async function setLoop247(loop: string) {
if (await client.db.autoreconnect.get(player.guildId)) {
await client.db.autoreconnect.set(
`${player.guildId}.config.loop`,
loop
);
}
}

switch (player.loop) {
case "none":
await player.setLoop(KazagumoLoop.track);

setLoop247(String(KazagumoLoop.none));

new ReplyInteractionService(
client,
message,
`${client.i18n.get(language, "music", "loop_current")}`
);

break;

case "track":
await player.setLoop(KazagumoLoop.queue);

setLoop247(String(KazagumoLoop.none));

new ReplyInteractionService(
client,
message,
`${client.i18n.get(language, "music", "loop_all")}`
);

break;

case "queue":
await player.setLoop(KazagumoLoop.none);

setLoop247(String(KazagumoLoop.none));

new ReplyInteractionService(
client,
message,
`${client.i18n.get(language, "music", "unloopall")}`
);

break;
}
}
}
53 changes: 53 additions & 0 deletions src/buttons/Pause.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import {
ButtonInteraction,
CacheType,
InteractionCollector,
Message,
} from "discord.js";
import { KazagumoPlayer } from "kazagumo.mod";
import { PlayerButton } from "../@types/Button.js";
import { Manager } from "../manager.js";
import {
playerRowOne,
playerRowOneEdited,
playerRowTwo,
} from "../utilities/PlayerControlButton.js";
import { ReplyInteractionService } from "../utilities/ReplyInteractionService.js";

export default class implements PlayerButton {
name = "pause";
async run(
client: Manager,
message: ButtonInteraction<CacheType>,
language: string,
player: KazagumoPlayer,
nplaying: Message<boolean>,
collector: InteractionCollector<ButtonInteraction<"cached">>
): Promise<any> {
if (!player) {
collector.stop();
}
await player.pause(!player.paused);
const uni = player.paused
? `${client.i18n.get(language, "player", "switch_pause")}`
: `${client.i18n.get(language, "player", "switch_resume")}`;

player.paused
? nplaying.edit({
components: [playerRowOneEdited, playerRowTwo],
})
: nplaying.edit({
components: [playerRowOne, playerRowTwo],
});

await new ReplyInteractionService(
client,
message,
`${client.i18n.get(language, "player", "pause_msg", {
pause: uni,
})}`
);

client.emit("playerPause", player);
}
}
42 changes: 42 additions & 0 deletions src/buttons/Previous.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import {
ButtonInteraction,
CacheType,
InteractionCollector,
Message,
} from "discord.js";
import { KazagumoPlayer } from "kazagumo.mod";
import { PlayerButton } from "../@types/Button.js";
import { Manager } from "../manager.js";
import { ReplyInteractionService } from "../utilities/ReplyInteractionService.js";

export default class implements PlayerButton {
name = "replay";
async run(
client: Manager,
message: ButtonInteraction<CacheType>,
language: string,
player: KazagumoPlayer,
nplaying: Message<boolean>,
collector: InteractionCollector<ButtonInteraction<"cached">>
): Promise<any> {
if (!player) {
collector.stop();
}
if (player.queue.previous.length == 0)
return await new ReplyInteractionService(
client,
message,
`${client.i18n.get(language, "music", "previous_notfound")}`
);

await player.queue.unshift(player.queue.previous[0]);
await player.skip();

await new ReplyInteractionService(
client,
message,
`${client.i18n.get(language, "music", "previous_msg")}`
);
return;
}
}
Loading

0 comments on commit 5459d0a

Please sign in to comment.