Skip to content

Commit

Permalink
v2.4.0 - Bug fixes + feature improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Reishimanfr committed May 30, 2024
1 parent d58f48a commit 22d8694
Show file tree
Hide file tree
Showing 43 changed files with 602 additions and 259 deletions.
3 changes: 1 addition & 2 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ PLAYER_TIMEOUT=10
# have any emojis added to it.
CUSTOM_EMOJIS_GUILD_ID=1234567890

# This changes if the bot should leave servers in which it's been inactive for
# 3 months
# This changes if the bot should leave servers in which it's been inactive for 3 months
LEAVE_INACTIVE_GUILDS=true

# Changes if (/) commands should be registered on bot start.
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ lavalink
plugins
docker-compose.yml
package-lock.json
icons.json
icons.json
database.sqlite
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"watch": "nodemon --quiet --watch src/** --exec sucrase-node src/index.ts",
"start": "sucrase-node src/index.ts"
},
"version": "2.3.5",
"version": "2.4.0",
"dependencies": {
"axios": "^1.6.0",
"chalk": "^4.0.0",
Expand Down
11 changes: 6 additions & 5 deletions src/Classes/Bot.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Client, type ClientOptions, Collection, REST, type RESTPostAPIChatInputApplicationCommandsJSONBody, Routes } from 'discord.js'
import { Client, Collection, REST, type RESTPostAPIChatInputApplicationCommandsJSONBody, Routes } from 'discord.js'
import { logger } from '../Helpers/Logger'
import { type NodeGroup, Poru } from 'poru'
import { readdirSync, statSync, writeFileSync } from 'node:fs'
Expand Down Expand Up @@ -94,11 +94,12 @@ class Bot extends Client<true> {

await emojisGuild.emojis.create({
attachment: fullPath,
name: name
name: name,
reason: 'Emoji used by TWM to display various elements in commands. This is REQUIRED and should NOT be messed with.',
})
.then(_ => {
logger.debug(`Created emoji -> ${_.name} (${_.toString()})`)
emojisData[name] = _.toString()
.then(emoji => {
logger.debug(`Created emoji -> ${emoji.name} (${emoji.toString()})`)
emojisData[name] = emoji.toString()
})
.catch(error => {
logger.error(`Failed to create emoji from file ${file} falling back to default icon: ${error.stack}`)
Expand Down
82 changes: 67 additions & 15 deletions src/Commands/config/player-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,13 @@ const player_config: Command = {
)

const res = await interaction.reply({
content: 'Select a option for the music player you want to configure.',
components: [optionsMenu],
ephemeral: true
ephemeral: true,
embeds: [
new EmbedBuilder()
.setAuthor({ name: '[ Select an option to change. ]' })
.setColor('#8b00cc')
]
})

const collector = res.createMessageComponentCollector({
Expand All @@ -152,9 +156,12 @@ const player_config: Command = {
[optionName]: toggledOption
}, { where: { guildId: interaction.guildId } })

await interaction.followUp({
content: `**${optionLabel}** toggled to **${toggledOption}**`,
ephemeral: true
await interaction.editReply({
embeds: [
new EmbedBuilder()
.setAuthor({ name: `[ ${optionLabel} turned ${toggledOption ? 'on' : 'off'}. ]`})
.setColor(embedColor)
]
})

return
Expand All @@ -171,16 +178,24 @@ const player_config: Command = {

collector.on('end', async () => {
await interaction.editReply({
embeds: [
new EmbedBuilder()
.setAuthor({ name: '[ Command timed out. ]'})
.setColor(embedColor)
],
components: [],
content: 'This interaction has expired.'
})
})
}
}

async function setDjRole(interaction: ChatInputCommandInteraction) {
await interaction.editReply({
content: 'Mention the role you\'d like to set as the DJ role.'
embeds: [
new EmbedBuilder()
.setAuthor({ name: '[ Mention the new DJ role: ]'})
.setColor(embedColor)
]
})

const awaitRole = await interaction.channel?.awaitMessages({
Expand All @@ -205,7 +220,13 @@ async function setDjRole(interaction: ChatInputCommandInteraction) {
.catch(() => undefined)

if (!isValidRole) {
await interaction.editReply('This doesn\'t seem to be a valid role ID.')
await interaction.editReply({
embeds: [
new EmbedBuilder()
.setAuthor({ name: '[ This doesn\'t looks like a valid role ID. ]'})
.setColor(embedColor)
]
})
return
}

Expand All @@ -217,13 +238,21 @@ async function setDjRole(interaction: ChatInputCommandInteraction) {
}, { where: { guildId: interaction.guildId } })

await interaction.editReply({
content: `New DJ role set to ${roleMention(correctRole)}!`
embeds: [
new EmbedBuilder()
.setAuthor({ name: `[ New DJ role set to ${roleMention(correctRole)}. ]`})
.setColor(embedColor)
]
})
}

async function setVoteSkipMembers(interaction: ChatInputCommandInteraction) {
await interaction.editReply({
content: 'Input a new member requirement for vote skips to occur.'
embeds: [
new EmbedBuilder()
.setAuthor({ name: '[ Provide the new amount of members for vote skipping: ]'})
.setColor(embedColor)
],
})

const awaitAmount = await interaction.channel?.awaitMessages({
Expand All @@ -238,8 +267,13 @@ async function setVoteSkipMembers(interaction: ChatInputCommandInteraction) {
const newAmount = Number(rawAmount.content)

if (Number.isNaN(newAmount)) {

await interaction.editReply({
content: 'The provided value is not a valid number.'
embeds: [
new EmbedBuilder()
.setAuthor({ name: '[ Provided value is not a valid number. ]'})
.setColor(embedColor)
]
})
return
}
Expand All @@ -249,13 +283,21 @@ async function setVoteSkipMembers(interaction: ChatInputCommandInteraction) {
}, { where: { guildId: interaction.guildId } })

await interaction.editReply({
content: `New member requirement set to **${newAmount} members**!`
embeds: [
new EmbedBuilder()
.setAuthor({ name: `[ New amount of members set to ${newAmount}. ]`})
.setColor(embedColor)
]
})
}

async function setVoteSkipThreshold(interaction: ChatInputCommandInteraction) {
await interaction.editReply({
content: 'Input a new voting threshold for vote skips to be accepted.'
embeds: [
new EmbedBuilder()
.setAuthor({ name: '[ Provide the new voting threshold for vote skips: ]'})
.setColor(embedColor)
]
})

const awaitAmount = await interaction.channel?.awaitMessages({
Expand All @@ -271,7 +313,11 @@ async function setVoteSkipThreshold(interaction: ChatInputCommandInteraction) {

if (Number.isNaN(newAmount)) {
await interaction.editReply({
content: 'The provided value is not a valid number.'
embeds: [
new EmbedBuilder()
.setAuthor({ name: '[ Provided value is not a valid number. ]'})
.setColor(embedColor)
]
})
return
}
Expand All @@ -281,7 +327,11 @@ async function setVoteSkipThreshold(interaction: ChatInputCommandInteraction) {
}, { where: { guildId: interaction.guildId } })

await interaction.editReply({
content: `New vote skip threshold set to **${newAmount}%**!`
embeds: [
new EmbedBuilder()
.setAuthor({ name: `[ New vote skip threshold set to ${newAmount}. ]`})
.setColor(embedColor)
]
})
}

Expand All @@ -306,6 +356,7 @@ Voting threshold: \`${data.voteSkipThreshold}%\`
Disconnect on queue end: \`${isEnabled(data.queueEndDisconnect)}\`
Resend message on new track: \`${isEnabled(data.resendMessageOnEnd)}\`
Update now playing message: \`${isEnabled(data.dynamicNowPlaying)}\``)
.setColor(embedColor)

await interaction.editReply({
embeds: [configEmbed]
Expand Down Expand Up @@ -367,6 +418,7 @@ async function sponsorBlockConfig(interaction: ChatInputCommandInteraction) {
iconURL: interaction.guild?.iconURL() ?? undefined
})
.setDescription(`### Select a option to toggle in the menu below\n${formatSettings(settings)}`)
.setColor(embedColor)
}

const response = await interaction.editReply({
Expand Down
54 changes: 43 additions & 11 deletions src/Commands/config/starboard-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,11 @@ const starboard_config: Command<false> = {

if (data.boardId === newChannel.id) {
return interaction.reply({
content: '`❌` - Starboard is already set to this channel.',
embeds: [
new EmbedBuilder()
.setAuthor({ name: '[ Starboard already set to this channel. ]' })
.setColor(embedColor)
],
ephemeral: true
})
}
Expand All @@ -89,15 +93,23 @@ const starboard_config: Command<false> = {

if (!permissions?.has('SendMessages')) {
return interaction.reply({
content: '`❌` - I can\'t send messages in this channel.',
embeds: [
new EmbedBuilder()
.setAuthor({ name: '[ I can\'t send messages in that channel. ]' })
.setColor(embedColor)
],
ephemeral: true
})
}

data.boardId = newChannel.id

await interaction.reply({
content: '`✅` New starboard channel set.',
embeds: [
new EmbedBuilder()
.setAuthor({ name: '[ New starboard channel set. ]' })
.setColor(embedColor)
],
ephemeral: true
})

Expand All @@ -109,15 +121,23 @@ const starboard_config: Command<false> = {

if (data.amount === newReactionsAmount) {
return interaction.reply({
content: '`❌` - Required reactions amount is already set to this value.',
embeds: [
new EmbedBuilder()
.setAuthor({ name: '[ Required amount of reactions is already set to this value. ]' })
.setColor(embedColor)
],
ephemeral: true
})
}

data.amount = newReactionsAmount

await interaction.reply({
content: '`✅` New reactions amount set.',
embeds: [
new EmbedBuilder()
.setAuthor({ name: '[ New reactions amount set. ]' })
.setColor(embedColor)
],
ephemeral: true
})

Expand All @@ -132,13 +152,17 @@ const starboard_config: Command<false> = {
newEmojisInput
.split(', ')
.map(emoji => emoji.trim())
.filter(emoji => emoji.match(/^(:\w+:|<(a|):\w+:\d+>|\p{Emoji}+)$/gu)))
.filter(emoji => emoji.match(/<a?:.+?:\d{18}>|\p{Extended_Pictographic}/gu)))
]

data.emojis = newEmojis.join(' ')

await interaction.reply({
content: '`✅` New emojis set.',
embeds: [
new EmbedBuilder()
.setAuthor({ name: '[ New emojis set. ]' })
.setColor(embedColor)
],
ephemeral: true
})

Expand All @@ -156,7 +180,11 @@ const starboard_config: Command<false> = {
for (const channel of newIgnoredChannels) {
if (!channels.find(c => c?.id === channel)) {
return interaction.reply({
content: `\`❌\` - Channel ID \`${channel}\` doesn't seem to be valid. Please run the command again and provide the correct channel IDs.`,
embeds: [
new EmbedBuilder()
.setAuthor({ name: `[ "${channel}" doesn't seem to be valid. ]`})
.setColor(embedColor)
],
ephemeral: true
})
}
Expand All @@ -165,7 +193,11 @@ const starboard_config: Command<false> = {
data.bannedChannels = newIgnoredChannels.join(' ')

await interaction.reply({
content: '`✅` New ignored channels set.',
embeds: [
new EmbedBuilder()
.setAuthor({ name: '[ Ignored channels set. ]'})
.setColor(embedColor)
],
ephemeral: true
})

Expand Down Expand Up @@ -198,8 +230,8 @@ function createConfigEmbed(interaction: ChatInputCommandInteraction<'cached'>, d
.setFields(
{ name: '🧵 Channel⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀', value: data.boardId ? channelLink(data.boardId) : '`Not set`', inline: true },
{ name: '🔢 Reactions amount⠀⠀', value: `\`${data.amount} reaction${data.amount > 1 ? 's' : ''}\``, inline: true },
{ name: '🤗 Emojis⠀⠀⠀⠀⠀⠀', value: data.emojis.replace(/ /g, ', '), inline: true },
{ name: '🤗 Emojis⠀⠀⠀⠀⠀⠀', value: data.emojis.replace(/ /g, ', ') ?? '`Not set`', inline: true },
{ name: '❌ Ignored channels', value: bannedChannels.length ? bannedChannels.map(c => channelMention(c)).join(', ') : '`Not set`' } // Formatting sucks
)
.setColor(data.boardId ? 'Green' : 'Red')
.setColor(data.boardId ? embedColor : 'Red')
}
14 changes: 11 additions & 3 deletions src/Commands/music/clear.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SlashCommandBuilder } from 'discord.js'
import { EmbedBuilder, SlashCommandBuilder } from 'discord.js'
import type { Command } from '../../Types/Command'

const clear: Command<true> = {
Expand All @@ -25,15 +25,23 @@ const clear: Command<true> = {
callback: async ({ interaction, player }) => {
if (player.queue.length <= 0) {
return interaction.reply({
content: '`❌` - Nothing to clear.',
embeds: [
new EmbedBuilder()
.setDescription('[ Queue is empty. Nothing to clear. ]')
.setColor(embedColor)
],
ephemeral: true
})
}

player.queue.length = 0

await interaction.reply({
content: '`✅` - Queue cleared.',
embeds: [
new EmbedBuilder()
.setDescription('[ Queue cleared. ]')
.setColor(embedColor)
],
ephemeral: true
})
}
Expand Down
Loading

0 comments on commit 22d8694

Please sign in to comment.