From a54361c57158ed9b74cb908a73763f9932bea24b Mon Sep 17 00:00:00 2001 From: SileNce5k Date: Mon, 12 May 2025 01:38:36 +0200 Subject: [PATCH 01/71] Add basic cpu info to processInfo global --- server.js | 6 ++++++ server/ready.js | 2 ++ util/updateCpuPercentage.js | 10 ++++++++++ 3 files changed, 18 insertions(+) create mode 100644 util/updateCpuPercentage.js diff --git a/server.js b/server.js index b38abe4..1f7aefe 100644 --- a/server.js +++ b/server.js @@ -49,6 +49,12 @@ client.whitelist = { user: new Collection() } +client.processInfo = { + cpuPercentage: 0, + ramUsage: 0, + previousCpuUsage: process.cpuUsage() +} + createAndLoadWhitelistTable(client.whitelist); client.settings.set("presenceType", presenceType); diff --git a/server/ready.js b/server/ready.js index 20324b7..2a862bb 100644 --- a/server/ready.js +++ b/server/ready.js @@ -1,6 +1,7 @@ const loadServerPrefixes = require('../util/loadServerPrefixes'); const checkTimer = require('../util/timer/checkTimer'); const updatePresence = require('../util/updatePresence'); +const updateCpuPercentage = require('../util/updateCpuPercentage') module.exports = function(client, enableLoginMessage, loginChannel, loginMessage) { updatePresence(client) @@ -13,4 +14,5 @@ module.exports = function(client, enableLoginMessage, loginChannel, loginMessage } loadServerPrefixes(client) checkTimer(client); + updateCpuPercentage(client.processInfo); } diff --git a/util/updateCpuPercentage.js b/util/updateCpuPercentage.js new file mode 100644 index 0000000..2c0135a --- /dev/null +++ b/util/updateCpuPercentage.js @@ -0,0 +1,10 @@ +const os = require('os'); +const updateCpuPercentage = require('./updateCpuPercentage'); +module.exports = async function (processInfo) { + const newCpuUsage = process.cpuUsage(processInfo.cpuPercentage); + processInfo.previousCpuUsage = process.cpuUsage(); + processInfo.cpuPercentage = (newCpuUsage.system + newCpuUsage.user) / 60_000_000 / os.cpus().length; + + setTimeout(updateCpuPercentage, 60000, processInfo); +} + From 9cb5ea22cb16b68c59b6b8a55de9ec2a94ac75af Mon Sep 17 00:00:00 2001 From: SileNce5k Date: Mon, 12 May 2025 03:08:25 +0200 Subject: [PATCH 02/71] Add top albums to fm command --- commands/misc/fm.js | 5 +++++ util/lastfm/getTopAlbums.js | 39 +++++++++++++++++-------------------- 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/commands/misc/fm.js b/commands/misc/fm.js index 8d07401..5c771da 100644 --- a/commands/misc/fm.js +++ b/commands/misc/fm.js @@ -35,6 +35,11 @@ module.exports = { args.shift(); sendText = await getTopTracks(message.author.id, args, message.guild); break; + case "topalbums": + case "topalbum": + case "abl": + sendText = await getTopAlbums(message.author.id, args, message.guild) + break; case "cover": sendText = await getCurrentCover(message.author.id, message.guild); break; diff --git a/util/lastfm/getTopAlbums.js b/util/lastfm/getTopAlbums.js index 049393d..b87a403 100644 --- a/util/lastfm/getTopAlbums.js +++ b/util/lastfm/getTopAlbums.js @@ -93,27 +93,24 @@ module.exports = async function (userID, option, guild, compatibility=false) { }); }); } - // const embed = new EmbedBuilder() - // .setAuthor({name: `Top ${duration} albums for ${nickname}`, iconURL: user.user.avatarURL({ dynamic: true, size: 4096 })}) - // .setThumbnail(albums[0].cover) - // .setColor(15780145) - // let tracksInfo = ""; - // for(let i = 0; i < albums.length; i++){ - // let pluralCharacter = albums[i].playcount > 1 ? 's' : ''; - // let track = `${i}. **${albums[i].artist}** - ${albums[i].song} - *${albums[i].playcount} play${pluralCharacter}*`; - // if(i < albums.length - 1){ - // tracksInfo += `${track}\n`; - // }else{ - // tracksInfo += `${track}`; - // } - // } - // embed.addFields({ - // name: ` `, value: `${tracksInfo}` - // },) - // sendText.embed = embed; - // if(compatibility) + const embed = new EmbedBuilder() + .setAuthor({name: `Top ${duration} albums for ${nickname}`, iconURL: user.user.avatarURL({ dynamic: true, size: 4096 })}) + .setColor(15780145) + let albumInfo = ""; + for(let i = 0; i < albums.length; i++){ + let pluralCharacter = albums[i].playcount > 1 ? 's' : ''; + let album = `${i}. **${albums[i].artist}** - ${albums[i].name} - *${albums[i].playcount} play${pluralCharacter}*`; + if(i < albums.length - 1){ + albumInfo += `${album}\n`; + }else{ + albumInfo += `${album}`; + } + } + embed.setDescription(albumInfo); + sendText.embed = embed; + if(compatibility) return albums; - // else - // return sendText; + else + return sendText; } \ No newline at end of file From 4f57499cca0c79896bf9b37d9da7dd2107b72bfc Mon Sep 17 00:00:00 2001 From: SileNce5k Date: Mon, 12 May 2025 17:52:03 +0200 Subject: [PATCH 03/71] Add top artists to fm command --- commands/misc/fm.js | 6 ++++++ util/lastfm/getTopArtists.js | 39 +++++++++++++++++------------------- 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/commands/misc/fm.js b/commands/misc/fm.js index 5c771da..cda2f45 100644 --- a/commands/misc/fm.js +++ b/commands/misc/fm.js @@ -40,6 +40,12 @@ module.exports = { case "abl": sendText = await getTopAlbums(message.author.id, args, message.guild) break; + case "topartists": + case "topartist": + case "ta": + case "as": + sendText = await getTopArtists(message.author.id, args, message.guild); + break; case "cover": sendText = await getCurrentCover(message.author.id, message.guild); break; diff --git a/util/lastfm/getTopArtists.js b/util/lastfm/getTopArtists.js index 2318180..40cbe3f 100644 --- a/util/lastfm/getTopArtists.js +++ b/util/lastfm/getTopArtists.js @@ -92,27 +92,24 @@ module.exports = async function (userID, option, guild, compatibility=false) { }); }); } - // const embed = new EmbedBuilder() - // .setAuthor({name: `Top ${duration} tracks for ${nickname}`, iconURL: user.user.avatarURL({ dynamic: true, size: 4096 })}) - // .setThumbnail(tracks[0].cover) - // .setColor(15780145) - // let tracksInfo = ""; - // for(let i = 0; i < tracks.length; i++){ - // let pluralCharacter = tracks[i].playcount > 1 ? 's' : ''; - // let track = `${i}. **${tracks[i].artist}** - ${tracks[i].song} - *${tracks[i].playcount} play${pluralCharacter}*`; - // if(i < tracks.length - 1){ - // tracksInfo += `${track}\n`; - // }else{ - // tracksInfo += `${track}`; - // } - // } - // embed.addFields({ - // name: ` `, value: `${tracksInfo}` - // },) - // sendText.embed = embed; - // if(compatibility) + const embed = new EmbedBuilder() + .setAuthor({name: `Top ${duration} artists for ${nickname}`, iconURL: user.user.avatarURL({ dynamic: true, size: 4096 })}) + .setColor(15780145) + let artistsInfo = ""; + for(let i = 0; i < artists.length; i++){ + let pluralCharacter = artists[i].playcount > 1 ? 's' : ''; + let track = `${i}. **${artists[i].name}** - *${artists[i].playcount} play${pluralCharacter}*`; + if(i < artists.length - 1){ + artistsInfo += `${track}\n`; + }else{ + artistsInfo += `${track}`; + } + } + embed.setDescription(artistsInfo); + sendText.embed = embed; + if(compatibility) return artists; - // else - // return sendText; + else + return sendText; } \ No newline at end of file From 6592f258829d8bd5afd1afea174ad4578210fd42 Mon Sep 17 00:00:00 2001 From: SileNce5k Date: Mon, 12 May 2025 17:55:45 +0200 Subject: [PATCH 04/71] Shift arguments so time option works --- commands/misc/fm.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/commands/misc/fm.js b/commands/misc/fm.js index cda2f45..3efd216 100644 --- a/commands/misc/fm.js +++ b/commands/misc/fm.js @@ -38,12 +38,14 @@ module.exports = { case "topalbums": case "topalbum": case "abl": + args.shift(); sendText = await getTopAlbums(message.author.id, args, message.guild) break; case "topartists": case "topartist": case "ta": case "as": + args.shift(); sendText = await getTopArtists(message.author.id, args, message.guild); break; case "cover": From 9ac900bc4d435a36c8e7c7ff217c943a26a8eb0c Mon Sep 17 00:00:00 2001 From: SileNce5k Date: Mon, 12 May 2025 18:00:23 +0200 Subject: [PATCH 05/71] fm: Add top artists and albums to moreHelp --- commands/misc/fm.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/commands/misc/fm.js b/commands/misc/fm.js index 3efd216..5aa6035 100644 --- a/commands/misc/fm.js +++ b/commands/misc/fm.js @@ -17,6 +17,8 @@ module.exports = { "They behave the same (for example: `fmtt` and `fm tt`)", "Set username: `fmset `", "Get current scrobble: `fm`", + "Get top artists `fmas`", + "Get top albums: `fmabl`", "Get top tracks: `fmtt`", "Get album cover for current scrobble: `fmcover`", "Get a roast from an LLM using your top artists and albums: `fmroast`" From be8d9660ba7d2a75f375f88765983d7f7ff5c5a7 Mon Sep 17 00:00:00 2001 From: SileNce5k Date: Mon, 12 May 2025 20:11:34 +0200 Subject: [PATCH 06/71] Fix permissions checking not working if false --- commands/misc/prefix.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/commands/misc/prefix.js b/commands/misc/prefix.js index 19ec7d1..954c834 100644 --- a/commands/misc/prefix.js +++ b/commands/misc/prefix.js @@ -1,10 +1,11 @@ const setServerPrefix = require("../../util/setServerPrefix"); +const { PermissionsBitField } = require('discord.js'); module.exports = { name: 'prefix', description: 'Change the prefix of the bot in this server.', execute({ message, client, args, prefix }) { - if (!message.member.permissions.has('MANAGE_GUILD')) { + if (!message.member.permissions.has(PermissionsBitField.Flags.ManageGuild)) { message.channel.send("You do not have sufficient permissions(MANAGE_GUILD) to change the prefix of this server.") return; } From c74f323c1b4d1e89ec17d088e13cdfd9a1efb903 Mon Sep 17 00:00:00 2001 From: SileNce5k Date: Tue, 13 May 2025 00:19:35 +0200 Subject: [PATCH 07/71] Log command executed before executing Sometimes I use shift() on the args to handle them which causes the logging to not log everything 100% accurately --- server/message.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/message.js b/server/message.js index 08d860d..fb15f3b 100644 --- a/server/message.js +++ b/server/message.js @@ -27,8 +27,8 @@ module.exports = function(client, owners, message, globalPrefix){ } if (command.admin && owners.indexOf(message.author.id.toString()) == -1) return; try { - command.execute({ message: message, args: args, client: client, prefix: prefix, owners: owners, globalPrefix: globalPrefix}) console.log(`${message.author.username}(id: ${message.author.id}) executed ${command.name} with '${args}' as arguments`) + command.execute({ message: message, args: args, client: client, prefix: prefix, owners: owners, globalPrefix: globalPrefix}) } catch (error) { let divider = "------------------------" console.log(divider) From ed77c2aaf1ceb376ab276026671bd05e81f06ac0 Mon Sep 17 00:00:00 2001 From: SileNce5k Date: Sat, 17 May 2025 11:15:05 +0200 Subject: [PATCH 08/71] Allow dates to be used in timer command And some general cleanup of a couple of functions. --- commands/misc/timer.js | 11 ++++++----- server.js | 1 + util/timer/createTimer.js | 23 ++++++++++++++++------- util/timer/parseTime.js | 20 +++++--------------- util/timer/timeUntil.js | 20 ++++++++++++++++++++ 5 files changed, 48 insertions(+), 27 deletions(-) create mode 100644 util/timer/timeUntil.js diff --git a/commands/misc/timer.js b/commands/misc/timer.js index 746689b..472af1b 100644 --- a/commands/misc/timer.js +++ b/commands/misc/timer.js @@ -4,11 +4,11 @@ const parseTime = require('../../util/timer/parseTime'); const showTimer = require('../../util/timer/showTimer'); module.exports = { name: "timer", - description: "Set a timer for a time in minutes.", + description: "Set a timer for a date or time duration.", moreHelp: ["Usage:" ,"`timer [add|create] `" ,"`timer