Skip to content

Commit

Permalink
Merge pull request #90 from RainyXeon/dev
Browse files Browse the repository at this point in the history
Critical security issue patch
  • Loading branch information
RainyXeon authored May 11, 2024
2 parents c514dd9 + 384d8b7 commit 1bf74a9
Show file tree
Hide file tree
Showing 28 changed files with 107 additions and 63 deletions.
2 changes: 1 addition & 1 deletion src/commands/Music/File.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export default class implements Command {

const TotalDuration = player.queue.duration;

if (handler.message) await handler.message.delete();
if (handler.message) await handler.message.delete().catch(() => null);

if (result.type === "PLAYLIST") {
const embed = new EmbedBuilder()
Expand Down
2 changes: 1 addition & 1 deletion src/commands/Music/Nowplaying.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export default class implements Command {
const currentNP = client.nowPlaying.get(`${handler.guild?.id}`);
if (currentNP) {
clearInterval(currentNP.interval);
await currentNP.msg?.delete();
await currentNP.msg?.delete().catch(() => null);
client.nowPlaying.delete(`${handler.guild?.id}`);
}

Expand Down
2 changes: 1 addition & 1 deletion src/commands/Music/Play.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export default class implements Command {

const TotalDuration = player.queue.duration;

if (handler.message) await handler.message.delete();
if (handler.message) await handler.message.delete().catch(() => null);

if (result.type === "TRACK") {
const embed = new EmbedBuilder()
Expand Down
4 changes: 2 additions & 2 deletions src/commands/Playlist/Delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,14 @@ export default class implements Command {
.setColor(client.color);
interaction.reply({ embeds: [embed] });
collector.stop();
msg?.delete();
msg?.delete().catch(() => null);
} else if (id == "no") {
const embed = new EmbedBuilder()
.setDescription(`${client.getString(handler.language, "command.playlist", "delete_no")}`)
.setColor(client.color);
interaction.reply({ embeds: [embed] });
collector.stop();
msg?.delete();
msg?.delete().catch(() => null);
}
});

Expand Down
46 changes: 44 additions & 2 deletions src/commands/Premium/Profile.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { CommandInteraction, EmbedBuilder } from "discord.js";
import { EmbedBuilder } from "discord.js";
import moment from "moment";
import { Manager } from "../../manager.js";
import { Accessableby, Command } from "../../structures/Command.js";
import { CommandHandler } from "../../structures/CommandHandler.js";
import { Premium } from "../../database/schema/Premium.js";

export default class implements Command {
public name = ["pm", "profile"];
Expand All @@ -22,7 +23,10 @@ export default class implements Command {
public async execute(client: Manager, handler: CommandHandler) {
await handler.deferReply();

const PremiumPlan = client.premiums.get(`${handler.user?.id}`);
if (handler.user?.id == client.owner) return this.owner(client, handler);
if (client.config.bot.ADMIN.includes(handler.user?.id ?? "null")) return this.admin(client, handler);

const PremiumPlan = (await client.db.premium.get(`${handler.user?.id}`)) as Premium;
const expires = moment(PremiumPlan && PremiumPlan.expiresAt !== "lifetime" ? PremiumPlan.expiresAt : 0).format(
"do/MMMM/YYYY (HH:mm:ss)"
);
Expand All @@ -44,4 +48,42 @@ export default class implements Command {

return handler.editReply({ embeds: [embed] });
}

owner(client: Manager, handler: CommandHandler) {
const embed = new EmbedBuilder()
.setAuthor({
name: `${client.getString(handler.language, "command.premium", "profile_author")}`,
iconURL: client.user!.displayAvatarURL(),
})
.setDescription(
`${client.getString(handler.language, "command.premium", "profile_desc", {
user: String(handler.user?.tag),
plan: "dreamvast@owner",
expires: "lifetime",
})}`
)
.setColor(client.color)
.setTimestamp();

return handler.editReply({ embeds: [embed] });
}

admin(client: Manager, handler: CommandHandler) {
const embed = new EmbedBuilder()
.setAuthor({
name: `${client.getString(handler.language, "command.premium", "profile_author")}`,
iconURL: client.user!.displayAvatarURL(),
})
.setDescription(
`${client.getString(handler.language, "command.premium", "profile_desc", {
user: String(handler.user?.tag),
plan: "dreamvast@admin",
expires: "lifetime",
})}`
)
.setColor(client.color)
.setTimestamp();

return handler.editReply({ embeds: [embed] });
}
}
1 change: 0 additions & 1 deletion src/commands/Premium/Redeem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ export default class implements Command {
});
await handler.editReply({ embeds: [embed] });
await client.db.code.delete(`${input.toUpperCase()}`);
client.premiums.set(String(handler.user?.id), newPreUser);
await this.sendRedeemLog(client, newPreUser, handler.user);
return;
}
Expand Down
1 change: 0 additions & 1 deletion src/commands/Premium/Remove.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ export default class implements Command {

if (db.isPremium) {
await client.db.premium.delete(`${id}`);
client.premiums.delete(id);

const embed = new EmbedBuilder()
.setDescription(
Expand Down
6 changes: 3 additions & 3 deletions src/commands/Utils/Setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,9 @@ export default class implements Command {
)
.setColor(client.color);

if (fetchedCategory) await fetchedCategory.delete();
if (fetchedVoiceChannel) await fetchedVoiceChannel.delete();
if (fetchedTextChannel) await fetchedTextChannel.delete();
if (fetchedCategory) await fetchedCategory.delete().catch(() => null);
if (fetchedVoiceChannel) await fetchedVoiceChannel.delete().catch(() => null);
if (fetchedTextChannel) await fetchedTextChannel.delete().catch(() => null);

await client.db.setup.delete(`${handler.guild!.id}`);

Expand Down
10 changes: 0 additions & 10 deletions src/database/setup/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,6 @@ export class ClientDataService {
.setTimestamp();
}

async setupPremium() {
const users = await this.client.db.premium.all();
if (users && users.length !== 0)
users.forEach(async (data) => {
this.client.premiums.set(data.value.id, data.value);
});
}

async setupInfoChennel() {
cron.schedule("*/5 * * * * *", async () => {
const SetupChannel = new Map();
Expand Down Expand Up @@ -87,8 +79,6 @@ export class ClientDataService {
const Client = chalk.hex("#02f75c");
const client_mess = Client("Client: ");
this.client.logger.setup(import.meta.url, client_mess + "Setting up data for client...");

this.setupPremium();
this.setupInfoChennel();

this.client.logger.setup(import.meta.url, client_mess + "Setting up data for client complete!");
Expand Down
9 changes: 4 additions & 5 deletions src/database/setup/premium.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,16 @@ export class PremiumScheduleSetup {
cron.schedule("0 */1 * * * *", () => this.setupChecker());
}

setupChecker() {
const premium = Array.from(this.client.premiums.values());
const users = premium.filter((data) => data.isPremium == true && data.expiresAt !== "lifetime");
if (users && users.length !== 0) this.checkUser(users);
async setupChecker() {
const premium = Array.from(await this.client.db.premium.all());
const users = premium.filter((data) => data.value.isPremium == true && data.value.expiresAt !== "lifetime");
if (users && users.length !== 0) this.checkUser(users.map((data) => data.value));
}

async checkUser(users: Premium[]) {
for (let data of users) {
if (data.expiresAt !== "lifetime" && Date.now() >= data.expiresAt) {
await this.client.db.premium.delete(data.id);
this.client.premiums.delete(data.id);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/events/guild/interactionCreate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export default class {
if (returnData.result !== "PermissionPass") return respondError(interaction, returnData);
}
//////////////////////////////// Permission check end ////////////////////////////////
const premiumUser = client.premiums.get(interaction.user.id);
const premiumUser = await client.db.premium.get(interaction.user.id);
const isHavePremium = !premiumUser || !premiumUser.isPremium;
if (
command.accessableby == Accessableby.Manager &&
Expand Down
2 changes: 1 addition & 1 deletion src/events/guild/messageCreate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ export default class {
//////////////////////////////// Permission check end ////////////////////////////////

//////////////////////////////// Access check start ////////////////////////////////
const premiumUser = client.premiums.get(message.author.id);
const premiumUser = await client.db.premium.get(message.author.id);
const isHavePremium = !premiumUser || !premiumUser.isPremium;
if (command.accessableby == Accessableby.Owner && message.author.id != client.owner)
return message.reply({
Expand Down
9 changes: 6 additions & 3 deletions src/events/guild/voiceStateUpdate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ export default class {
})
: null;
setTimeout(
async () => ((!setup || setup == null || setup.channel !== player.textId) && msg ? msg.delete() : true),
async () =>
(!setup || setup == null || setup.channel !== player.textId) && msg ? msg.delete().catch(() => null) : true,
client.config.bot.DELETE_MSG_TIMEOUT
);
}
Expand All @@ -118,7 +119,7 @@ export default class {
setTimeout(async () => {
const isChannelAvalible = await client.channels.fetch(msg.channelId).catch(() => undefined);
if (!isChannelAvalible) return;
!setup || setup == null || setup.channel !== player.textId ? msg.delete() : true;
!setup || setup == null || setup.channel !== player.textId ? msg.delete().catch(() => null) : true;
}, client.config.bot.DELETE_MSG_TIMEOUT);
}

Expand All @@ -141,7 +142,9 @@ export default class {
const msg = newPlayer && leaveEmbed ? await leaveEmbed.send({ embeds: [TimeoutEmbed] }) : undefined;
setTimeout(
async () =>
msg && (!setup || setup == null || setup.channel !== player.textId) ? msg.delete() : undefined,
msg && (!setup || setup == null || setup.channel !== player.textId)
? msg.delete().catch(() => null)
: undefined,
client.config.bot.DELETE_MSG_TIMEOUT
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/events/player/playerDestroy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export default class {
const setup = await client.db.setup.get(player.guildId);
const msg = await channel.send({ embeds: [embed] });
setTimeout(
async () => (!setup || setup == null || setup.channel !== channel.id ? msg.delete() : true),
async () => (!setup || setup == null || setup.channel !== channel.id ? msg.delete().catch(() => null) : true),
client.config.bot.DELETE_MSG_TIMEOUT
);
}
Expand Down
6 changes: 2 additions & 4 deletions src/events/player/playerException.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { EmbedBuilder, TextChannel } from "discord.js";
import util from "node:util";
import { AutoReconnectBuilderService } from "../../services/AutoReconnectBuilderService.js";
import { ClearMessageService } from "../../services/ClearMessageService.js";
import { RainlinkPlayer } from "../../rainlink/main.js";
import { RainlinkPlayer, RainlinkPlayerState } from "../../rainlink/main.js";

export default class {
async execute(client: Manager, player: RainlinkPlayer, data: Record<string, any>) {
Expand All @@ -30,8 +30,6 @@ export default class {

const currentPlayer = client.rainlink.players.get(player.guildId) as RainlinkPlayer;
if (!currentPlayer) return;
if (currentPlayer.voiceId !== null) {
await player.destroy();
}
if (currentPlayer.state !== RainlinkPlayerState.DESTROYED) await player.destroy();
}
}
2 changes: 1 addition & 1 deletion src/events/player/playerPause.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default class {

const nowPlaying = client.nplayingMsg.get(`${player.guildId}`);
if (nowPlaying) {
nowPlaying.edit({ components: [playerRowOneEdited, playerRowTwo] });
nowPlaying.msg.edit({ components: [playerRowOneEdited, playerRowTwo] });
}

const setup = await client.db.setup.get(`${player.guildId}`);
Expand Down
2 changes: 1 addition & 1 deletion src/events/player/playerResume.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default class {

const nowPlaying = client.nplayingMsg.get(`${player.guildId}`);
if (nowPlaying) {
nowPlaying.edit({ components: [playerRowOne, playerRowTwo] });
nowPlaying.msg.edit({ components: [playerRowOne, playerRowTwo] });
}

const setup = await client.db.setup.get(`${player.guildId}`);
Expand Down
2 changes: 1 addition & 1 deletion src/events/player/playerStop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export default class {
const setup = await client.db.setup.get(player.guildId);
const msg = await channel.send({ embeds: [embed] });
setTimeout(
async () => (!setup || setup == null || setup.channel !== channel.id ? msg.delete() : true),
async () => (!setup || setup == null || setup.channel !== channel.id ? msg.delete().catch(() => null) : true),
client.config.bot.DELETE_MSG_TIMEOUT
);
}
Expand Down
4 changes: 2 additions & 2 deletions src/events/player/queueEmpty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { TextChannel } from "discord.js";
import { Manager } from "../../manager.js";
import { AutoReconnectBuilderService } from "../../services/AutoReconnectBuilderService.js";
import { ClearMessageService } from "../../services/ClearMessageService.js";
import { RainlinkPlayer } from "../../rainlink/main.js";
import { RainlinkPlayer, RainlinkPlayerState } from "../../rainlink/main.js";

export default class {
async execute(client: Manager, player: RainlinkPlayer) {
Expand Down Expand Up @@ -51,6 +51,6 @@ export default class {
const channel = (await client.channels.fetch(player.textId).catch(() => undefined)) as TextChannel;
if (data !== null && data && data.twentyfourseven && channel) new ClearMessageService(client, channel, player);

await player.destroy();
if (player.state !== RainlinkPlayerState.DESTROYED) await player.destroy();
}
}
7 changes: 5 additions & 2 deletions src/events/track/trackEnd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Manager } from "../../manager.js";
import { TextChannel } from "discord.js";
import { ClearMessageService } from "../../services/ClearMessageService.js";
import { AutoReconnectBuilderService } from "../../services/AutoReconnectBuilderService.js";
import { RainlinkPlayer } from "../../rainlink/main.js";
import { RainlinkPlayer, RainlinkPlayerState } from "../../rainlink/main.js";

export default class {
async execute(client: Manager, player: RainlinkPlayer) {
Expand Down Expand Up @@ -30,6 +30,9 @@ export default class {

if (player.loop !== "none") return new ClearMessageService(client, channel, player);
}
await player.destroy();

const currentPlayer = client.rainlink.players.get(player.guildId) as RainlinkPlayer;
if (!currentPlayer) return;
if (currentPlayer.state !== RainlinkPlayerState.DESTROYED) await player.destroy();
}
}
8 changes: 5 additions & 3 deletions src/events/track/trackResolveError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Manager } from "../../manager.js";
import { TextChannel, EmbedBuilder } from "discord.js";
import { AutoReconnectBuilderService } from "../../services/AutoReconnectBuilderService.js";
import { ClearMessageService } from "../../services/ClearMessageService.js";
import { RainlinkPlayer, RainlinkTrack } from "../../rainlink/main.js";
import { RainlinkPlayer, RainlinkPlayerState, RainlinkTrack } from "../../rainlink/main.js";

export default class {
async execute(client: Manager, player: RainlinkPlayer, track: RainlinkTrack, message: string) {
Expand Down Expand Up @@ -37,7 +37,7 @@ export default class {
const setup = await client.db.setup.get(player.guildId);
const msg = await channel.send({ embeds: [embed] });
setTimeout(
async () => (!setup || setup == null || setup.channel !== channel.id ? msg.delete() : true),
async () => (!setup || setup == null || setup.channel !== channel.id ? msg.delete().catch(() => null) : true),
client.config.bot.DELETE_MSG_TIMEOUT
);
}
Expand All @@ -48,6 +48,8 @@ export default class {
if (data247 !== null && data247 && data247.twentyfourseven && channel)
new ClearMessageService(client, channel, player);

await player.destroy();
const currentPlayer = client.rainlink.players.get(player.guildId) as RainlinkPlayer;
if (!currentPlayer) return;
if (currentPlayer.state !== RainlinkPlayerState.DESTROYED) await player.destroy();
}
}
8 changes: 6 additions & 2 deletions src/events/track/trackStart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ export default class {
: undefined;

if (!nplaying) return;
client.nplayingMsg.set(player.guildId, nplaying);

const collector = nplaying.createMessageComponentCollector({
componentType: ComponentType.Button,
Expand All @@ -146,6 +145,8 @@ export default class {
},
});

client.nplayingMsg.set(player.guildId, { coll: collector, msg: nplaying });

collector.on("collect", async (message: ButtonInteraction): Promise<void> => {
const id = message.customId;
const button = client.plButton.get(id);
Expand All @@ -159,7 +160,10 @@ export default class {
client.logger.error(import.meta.url, err);
}
}
collector?.removeAllListeners();
});

collector.on("end", (): void => {
collector.removeAllListeners();
});
}
}
Loading

0 comments on commit 1bf74a9

Please sign in to comment.