Skip to content

Commit

Permalink
v2.3.5: Privacy updates and bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
reishimanfr committed May 6, 2024
1 parent ef11793 commit ca2ceb6
Show file tree
Hide file tree
Showing 9 changed files with 191 additions and 79 deletions.
87 changes: 43 additions & 44 deletions src/Commands/config/player-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,66 +62,65 @@ const player_config: Command = {
.setCustomId('options-select')
.setOptions(
{
label: 'View config',
description: 'Shows the current configuration of the player.',
value: 'showConfig',
emoji: '⚙️'
label: "Config",
description: "Display current player settings.",
value: "showConfig",
emoji: "⚙️"
},
{
label: 'Sponsorblock auto skipping',
description: 'Configures skipping sponsored segments automatically with sponsorblock.',
value: 'sponsorBlockConfig',
emoji: '⏭'
label: "Sponsor Skip",
description: "Automatically skip sponsored segments with Sponsorblock.",
value: "sponsorBlockConfig",
emoji: "⏭"
},
{
label: 'Leave on queue end',
description: 'Toggles if the bot should leave after a queue ends.',
value: 'queueEndDisconnect',
emoji: '👋'
label: "Auto-Leave",
description: "Automatically leave after queue ends.",
value: "queueEndDisconnect",
emoji: "👋"
},
{
label: 'Vote skipping',
description: 'Toggles if skipping a song requires users to vote to skip.',
value: 'voteSkipToggle',
emoji: '⏩'
label: "Vote Skip",
description: "Require votes to skip a song.",
value: "voteSkipToggle",
emoji: "⏩"
},
{
label: 'Resend message after song end',
description: 'Toggles if the bot should resend the now playing message on new track.',
value: 'resendMessageOnEnd',
emoji: '↪️'
label: "Resend On End",
description: "Resend the 'now playing' message for new tracks.",
value: "resendMessageOnEnd",
emoji: "↪️"
},
{
label: 'Dynamic now playing message',
description: 'Toggles if the bot should update the now playing message every 15s.',
value: 'dynamicNowPlaying',
emoji: '🔄'
label: "Dynamic Now Playing",
description: "Update 'now playing' message every 15s.",
value: "dynamicNowPlaying",
emoji: "🔄"
},
{
label: 'Require DJ role',
description: 'Toggles if members are required to have the DJ role to use commands.',
value: 'requireDjRole',
emoji: '❗'
label: "DJ Role Required",
description: "Members need DJ role to use commands.",
value: "requireDjRole",
emoji: "❗"
},
{
label: 'DJ role',
description: 'Sets the role to be considered the "DJ role".',
value: 'djRoleId',
emoji: '✨'
{
label: "Set DJ Role",
description: "Define the DJ role.",
value: "djRoleId",
emoji: "✨"
},
{
label: 'Vote skipping member amount',
description: 'Sets how many members must be in voice channel for voting to be enabled.',
value: 'voteSkipMembers',
emoji: '🔢'
{
label: "Vote Skip Members",
description: "Number of members needed to enable voting.",
value: "voteSkipMembers",
emoji: "🔢"
},
{
label: 'Vote skipping threshold (%)',
description: 'Sets the % of members required to vote "yes" to skip a song.',
value: 'setVoteSkipThreshold',
emoji: '🔢'
}
)
label: "Vote Skip Threshold",
description: "Percentage of 'yes' votes required to skip a song.",
value: "setVoteSkipThreshold",
emoji: "🔢"
})
)

const res = await interaction.reply({
Expand Down
66 changes: 66 additions & 0 deletions src/Commands/util/delete-my-data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { ActionRowBuilder, ButtonBuilder, ButtonStyle, ComponentType, SlashCommandBuilder } from 'discord.js'
import type { Command } from '../../Types/Command'
import { playlists } from '../../Models'
import { logger } from '../../Helpers/Logger'

const deleteMyData: Command<false> = {
data: new SlashCommandBuilder()
.setName('delete-my-data')
.setDescription('Deletes everything from the database related to you.'),

permissions: {},

callback: async ({ interaction }) => {
const confirmationMessage = await interaction.reply({
content: 'Are you absolutely sure you want to delete everything in the database related to you?\n:warning: **This will also delete any playlists you created/imported.**\nServer specific music player settings won\'t be changed in any way.',
ephemeral: true,
components: [
new ActionRowBuilder<ButtonBuilder>()
.addComponents(
new ButtonBuilder()
.setCustomId('yes')
.setEmoji('✅')
.setLabel('Yes, I\'m 100% sure.')
.setStyle(ButtonStyle.Secondary),

new ButtonBuilder()
.setCustomId('no')
.setEmoji('❌')
.setLabel('No, I\'ve changed my mind.')
.setStyle(ButtonStyle.Secondary),
)
]
})

const optionCollector = await confirmationMessage.awaitMessageComponent({
componentType: ComponentType.Button,
idle: 120000
})

if (!optionCollector) {
return interaction.editReply({
components: [],
content: 'Command timed out. Your data will not be deleted.'
})
}

if (optionCollector.customId === 'no') {
return interaction.editReply({
components: [],
content: 'Cancelling data deletion.'
})
}

const toDelete = [playlists] // Array in case we want to add something here

for (const part of toDelete) {
try {
await part.destroy({ where: { userId: interaction.user.id } })
} catch (error) {
logger.error(`Failed to delete user data for ${interaction.user.id}: ${error.stack}`)
}
}
}
}

export default deleteMyData
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,13 @@ const togglePlayback: Button = {
},

run: async ({ interaction, player }) => {
const member = await interaction.guild?.members.fetch(interaction.user.id)

if (!member?.voice.channel) {
return interaction.reply({
content: 'You must be in a voice channel to use this command.',
ephemeral: true
})
}

await interaction.deferUpdate()
player.pause(!player.isPaused)
player.messageManger.updatePlayerMessage()

interaction.reply({
content: player.isPaused ? 'Paused' : 'Resumed',
ephemeral: true
})
}
}

Expand Down
24 changes: 24 additions & 0 deletions src/Events/Bot/Buttons/queue.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import type { Button } from '../../../Types/Button'

const queue: Button = {
name: 'queue',
musicOptions: {},
run: async ({ interaction, player}) => {
if (!player.queue.length) {
return interaction.reply({
content: 'The queue is empty.',
ephemeral: true
})
}

const embed = player.queueManager.createQueueEmbed()[0]
const description = `${embed.data.description}\n:warning: For full list of songs use the \`/queue\` command.`

await interaction.reply({
embeds: [embed.setDescription(description)],
ephemeral: true
})
}
}

export default queue
24 changes: 0 additions & 24 deletions src/Events/Bot/Buttons/showQueue.ts

This file was deleted.

26 changes: 26 additions & 0 deletions src/Events/Bot/GuildDelete.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Delete everything related to the guild from which we got kicked out of
import { Events, type Guild } from 'discord.js'
import type { Event } from '../../Types/Event';
import { PlayerSettings, SponsorBlockDb, serverStats, starboardConfig, starboardEntries } from '../../Models'
import { logger } from '../../Helpers/Logger'

const GuildDelete: Event = {
name: Events.GuildDelete,
once: false,

execute: async (guild: Guild) => {
logger.warn(`Deleting database entries for guild "${guild.name}" (${guild.id})`)

const classes = [PlayerSettings, serverStats, SponsorBlockDb, starboardConfig, starboardEntries]

for (const part of classes) {
try {
await part.destroy({ where: { guildId: guild.id } })
} catch (error) {
logger.error(`Failed to delete database entry after leaving server ${guild.name} (${guild.id}): ${error.stack}`)
}
}
}
}

export default GuildDelete
14 changes: 14 additions & 0 deletions src/Events/Bot/Warn.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Events } from 'discord.js'
import type { Event } from '../../Types/Event';
import { logger } from '../../Helpers/Logger'

const Warn: Event = {
name: Events.Warn,
once: false,

execute: (info: string) => {
logger.warn(`Discord.js warning: ${info}`)
}
}

export default Warn
12 changes: 12 additions & 0 deletions src/Helpers/Logger.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,47 @@
import chalk from "chalk"
import moment from 'moment'
require('dotenv').config()

const logLevel = process.env.LOG_LEVEL

// 0 1 2 3 4 5
const levelNames = ['trace', 'debug', 'info', 'warn', 'error', 'fatal']
const level = levelNames.indexOf(logLevel)

class logger {
private shutUpAboutStaticClassesBiomeThanks() { }

// biome-ignore lint/suspicious/noExplicitAny: Leave me alone please
static trace(...items: any) {
if (level > 0) return
const base = chalk.gray(`[${moment().format('hh:mm:ss.SSS')}]`)
console.log(`${base} ${chalk.magenta('TRACE:')} ${items}`)
}

// biome-ignore lint/suspicious/noExplicitAny: Leave me alone please
static debug(...items: any) {
if (level > 1) return
const base = chalk.gray(`[${moment().format('hh:mm:ss.SSS')}]`)
console.log(`${base} ${chalk.blue('DEBUG:')} ${items}`)
}

// biome-ignore lint/suspicious/noExplicitAny: Leave me alone please
static info(...items: any) {
if (level > 2) return
const base = chalk.gray(`[${moment().format('hh:mm:ss.SSS')}]`)
console.log(`${base} ${chalk.greenBright('INFO:')} ${items}`)
}

// biome-ignore lint/suspicious/noExplicitAny: Leave me alone please
static warn(...items: any) {
if (level > 3) return
const base = chalk.gray(`[${moment().format('hh:mm:ss.SSS')}]`)
console.log(`${base} ${chalk.yellowBright('WARN:')} ${items}`)
}

// biome-ignore lint/suspicious/noExplicitAny: Leave me alone please
static error(...items: any) {
if (level > 4) return
const base = chalk.gray(`[${moment().format('hh:mm:ss.SSS')}]`)
console.log(`${base} ${chalk.redBright('ERROR:')} ${items}`)
}
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,4 @@ cron.schedule('*/1 * * * *', () => {
client.user.setPresence({
activities: [{ name: activityName, type: activityType }]
})
})
})

0 comments on commit ca2ceb6

Please sign in to comment.