From 9d819253e06bcdb7ee558c97f4b7cca315bd8974 Mon Sep 17 00:00:00 2001 From: Skylar Grant Date: Mon, 27 Jan 2025 15:53:49 -0500 Subject: [PATCH 01/10] Improve .gif replies, testing only --- CHANGELOG.md | 5 ++++- dot-commands/gif.js | 18 ++++++++++++++++-- package.json | 2 +- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3f6670a..3ea6a42 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,7 @@ ## v3.4.x +#### v3.4.3 (#29) +* [WIP] Fix `.gif` replies to redirect to the original replyee + #### v3.4.2 (#28) * Added `.drink` and aliases @@ -32,4 +35,4 @@ v3.0.4 - Add ability to use multiple aliases v3.0.5 - Add ability to save strains v3.0.6 - Move `.strain` to `/strain` and add Autocomplete v3.0.7 - Add `.spongebob` replies -v3.0.8 - Add ability to open requests by pages \ No newline at end of file +v3.0.8 - Add ability to open requests by pages diff --git a/dot-commands/gif.js b/dot-commands/gif.js index dc2ff98..18861d2 100644 --- a/dot-commands/gif.js +++ b/dot-commands/gif.js @@ -29,7 +29,21 @@ module.exports = { return; }; commandData.embed_url = res.data.results[0].url; - message.reply(commandData.embed_url); + + // Handle when the invoking message is a reply to someone else + if (message.reference) { + // Fetch the referenced message from the channels' MessageManager + await message.channel.messages.fetch(message.reference.messageId).then((refMsg) => { + // Send the reply to the referenced message + await refMsg.reply(commandData.embed_url); + }).catch((e) => { + // Failed fetching the message from the channel, fallback to regular send + console.error(e); + await message.reply(commandData.embed_url); + }); + } else { + await message.reply(commandData.embed_url); + } }).catch(err => console.error(err)); // tenor.Search.Query(commandData.args, "1").then(res => { // if (res[0] == undefined) { @@ -51,4 +65,4 @@ module.exports = { message.reply(gifData.url); } } -} \ No newline at end of file +} diff --git a/package.json b/package.json index 1251782..1031769 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "nodbot", - "version": "3.4.2", + "version": "3.4.3", "description": "Nods and Nod Accessories", "main": "main.js", "dependencies": { -- 2.45.2 From c330af29fa4fff0f03a35a1bc0872e1a8ba0be38 Mon Sep 17 00:00:00 2001 From: Skylar Grant Date: Mon, 27 Jan 2025 16:14:21 -0500 Subject: [PATCH 02/10] Fix erroneous async issues --- dot-commands/gif.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dot-commands/gif.js b/dot-commands/gif.js index 18861d2..9aacfc5 100644 --- a/dot-commands/gif.js +++ b/dot-commands/gif.js @@ -22,7 +22,7 @@ module.exports = { `&key=${process.env.tenorAPIKey}` + '&limit=1' + `&contentfilter=off` - ).then(res => { + ).then(async (res) => { if (process.env.isDev) console.log(res.data.results); if (res.data.results[0] == undefined) { message.reply('Sorry I was unable to find a GIF of ' + commandData.args); @@ -33,10 +33,10 @@ module.exports = { // Handle when the invoking message is a reply to someone else if (message.reference) { // Fetch the referenced message from the channels' MessageManager - await message.channel.messages.fetch(message.reference.messageId).then((refMsg) => { + await message.channel.messages.fetch(message.reference.messageId).then(async (refMsg) => { // Send the reply to the referenced message await refMsg.reply(commandData.embed_url); - }).catch((e) => { + }).catch(async (e) => { // Failed fetching the message from the channel, fallback to regular send console.error(e); await message.reply(commandData.embed_url); -- 2.45.2 From c3e6e0823bdcfdc79360c7f138bb0f5cb11efe45 Mon Sep 17 00:00:00 2001 From: Skylar Grant Date: Mon, 27 Jan 2025 16:36:27 -0500 Subject: [PATCH 03/10] Add 3.4.3 updates --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3ea6a42..3fec378 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,10 @@ ## v3.4.x #### v3.4.3 (#29) -* [WIP] Fix `.gif` replies to redirect to the original replyee +* Fix `.gif` replies to redirect to the original replyee (#26) #### v3.4.2 (#28) * Added `.drink` and aliases +* Changed `.joint` responses to be standalone instead of replies #### v3.4.1 (#27) * Adding command to change nicknames -- 2.45.2 From a6d55ada7516ea4e91c2411b0bf91877379817d8 Mon Sep 17 00:00:00 2001 From: Skylar Grant Date: Fri, 31 Jan 2025 18:55:07 -0500 Subject: [PATCH 04/10] . --- _list-guilds.js | 31 +++++++++++++++++++++++++++++++ main.js | 17 ++++++++++++++--- 2 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 _list-guilds.js diff --git a/_list-guilds.js b/_list-guilds.js new file mode 100644 index 0000000..1a85f44 --- /dev/null +++ b/_list-guilds.js @@ -0,0 +1,31 @@ +/* + * Quick and dirty script to list out what guilds the bot is in and optionally leave some. + */ + +const guildsToLeave = ['1219254855789711432']; + +const dotenv = require('dotenv').config(); +const token = process.env.TOKEN; +const Discord = require('discord.js'); + +const client = new Discord.Client({ + intents: [ + 'GUILDS' + ] +}); + +client.on('ready', async () => { + console.log(`Logged in as ${client.user.tag}`); + console.log('Guilds:'); + client.guilds.cache.forEach(async (guild) => { + console.log(` - ${guild.name} (${guild.id})`); + if (guildsToLeave.includes(guild.id)) { + console.log(` Leaving ${guild.name}`); + await guild.leave(); + } + }); + console.log('Done.'); + client.destroy(); +}); + +client.login(token); \ No newline at end of file diff --git a/main.js b/main.js index c97a05d..e798340 100644 --- a/main.js +++ b/main.js @@ -31,6 +31,7 @@ const { GifData, CommandData } = require('./CustomModules/NodBot.js'); const ButtonHandlers = require('./CustomModules/ButtonHandlers.js'); const InteractionStorage = require('./CustomModules/InteractionStorage.js'); const isDev = process.env.isDev; +let statusChannel; client.once('ready', async () => { fn.collections.interactionStorage(client); @@ -48,9 +49,8 @@ client.once('ready', async () => { await fn.avWx.metar.getAllICAOs(); await fn.avWx.datis.getAllICAOs(); // console.log(JSON.stringify(icaoArray)); - client.channels.fetch(statusChannelId).then(channel => { - channel.send(`${new Date().toISOString()} -- <@${process.env.ownerId}>\nStartup Sequence Complete`); - }); + statusChannel = await client.channels.fetch(statusChannelId).catch(e => console.error(e)); + await channel.send(`${new Date().toISOString()} -- <@${process.env.ownerId}>\nStartup Sequence Complete`).catch(e => console.error(e)); }); // slash-commands @@ -146,4 +146,15 @@ client.on('messageCreate', message => { return; }); +// Guild Joins and Leaves: +client.on('guildCreate', async guild => { + await statusChannel.send(`I've been added to a new guild: ${guild.name} (${guild.id})`) + .catch(e => console.error(e)); +}); + +client.on('guildDelete', async guild => { + await statusChannel.send(`I've been removed from a guild: ${guild.name} (${guild.id})`) + .catch(e => console.error(e)); +}); + client.login(token); \ No newline at end of file -- 2.45.2 From 231ceeee9b87d003edb260bc2b21c89673f93ce7 Mon Sep 17 00:00:00 2001 From: Skylar Grant Date: Fri, 31 Jan 2025 19:18:28 -0500 Subject: [PATCH 05/10] Fix startup message --- _list-guilds.js | 22 +++++++++++++++------- main.js | 10 +++++----- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/_list-guilds.js b/_list-guilds.js index 1a85f44..70edcba 100644 --- a/_list-guilds.js +++ b/_list-guilds.js @@ -2,7 +2,7 @@ * Quick and dirty script to list out what guilds the bot is in and optionally leave some. */ -const guildsToLeave = ['1219254855789711432']; +const guildsToLeave = ['1224396616555823124']; const dotenv = require('dotenv').config(); const token = process.env.TOKEN; @@ -15,16 +15,24 @@ const client = new Discord.Client({ }); client.on('ready', async () => { + const guildChecks = []; console.log(`Logged in as ${client.user.tag}`); console.log('Guilds:'); - client.guilds.cache.forEach(async (guild) => { - console.log(` - ${guild.name} (${guild.id})`); - if (guildsToLeave.includes(guild.id)) { - console.log(` Leaving ${guild.name}`); - await guild.leave(); - } + client.guilds.cache.forEach((guild) => { + const p = new Promise((resolve, reject) => { + console.log(` - ${guild.name} (${guild.id})`); + if (guildsToLeave.includes(guild.id)) { + console.log(` Leaving ${guild.name}`); + guild.leave().then(resolve).catch(reject); + } else { + resolve(); + } + }); + guildChecks.push(p); }); console.log('Done.'); + await Promise.all(guildChecks); + console.log('All guilds checked.'); client.destroy(); }); diff --git a/main.js b/main.js index e798340..0d0e695 100644 --- a/main.js +++ b/main.js @@ -50,7 +50,7 @@ client.once('ready', async () => { await fn.avWx.datis.getAllICAOs(); // console.log(JSON.stringify(icaoArray)); statusChannel = await client.channels.fetch(statusChannelId).catch(e => console.error(e)); - await channel.send(`${new Date().toISOString()} -- <@${process.env.ownerId}>\nStartup Sequence Complete`).catch(e => console.error(e)); + await statusChannel.send(`${new Date().toISOString()} -- <@${process.env.ownerId}>\nStartup Sequence Complete`).catch(e => console.error(e)); }); // slash-commands @@ -147,13 +147,13 @@ client.on('messageCreate', message => { }); // Guild Joins and Leaves: -client.on('guildCreate', async guild => { - await statusChannel.send(`I've been added to a new guild: ${guild.name} (${guild.id})`) +client.on('guildCreate', guild => { + statusChannel.send(`I've been added to a new guild: ${guild.name} (${guild.id})`) .catch(e => console.error(e)); }); -client.on('guildDelete', async guild => { - await statusChannel.send(`I've been removed from a guild: ${guild.name} (${guild.id})`) +client.on('guildDelete', guild => { + statusChannel.send(`I've been removed from a guild: ${guild.name} (${guild.id})`) .catch(e => console.error(e)); }); -- 2.45.2 From efcf613ea4f08619fd0e3b8736e70f018ee60a75 Mon Sep 17 00:00:00 2001 From: Skylar Grant Date: Fri, 31 Jan 2025 19:30:39 -0500 Subject: [PATCH 06/10] . --- _list-guilds.js | 1 - config.json | 3 ++- functions.js | 22 ++++++++++++++++++++++ main.js | 3 +++ 4 files changed, 27 insertions(+), 2 deletions(-) diff --git a/_list-guilds.js b/_list-guilds.js index 70edcba..0829c91 100644 --- a/_list-guilds.js +++ b/_list-guilds.js @@ -30,7 +30,6 @@ client.on('ready', async () => { }); guildChecks.push(p); }); - console.log('Done.'); await Promise.all(guildChecks); console.log('All guilds checked.'); client.destroy(); diff --git a/config.json b/config.json index 488a934..9a73f7e 100644 --- a/config.json +++ b/config.json @@ -3,5 +3,6 @@ "validCommands": [], "roaches": [], "icaoIds": [], - "datisICAOs": [] + "datisICAOs": [], + "bannedServers": ["1224396616555823124"] } \ No newline at end of file diff --git a/functions.js b/functions.js index 01466b5..9fdfd11 100644 --- a/functions.js +++ b/functions.js @@ -671,6 +671,28 @@ const functions = { }); }); }, + checkBannedServers(client) { + if ( !config.bannedServers ) return; + const guildChecks = []; + console.log('Guild Check:'); + client.guilds.cache.forEach((guild) => { + const p = new Promise((resolve, reject) => { + console.log(` - ${guild.name} (${guild.id})`); + if (guildsToLeave.includes(guild.id)) { + console.log(` Leaving banned server: ${guild.name}`); + guild.leave().then(resolve).catch(reject); + } else { + resolve(); + } + }); + guildChecks.push(p); + }); + Promise.all(guildChecks).then(() => { + console.log('All guilds checked.'); + }).catch((err) => { + console.error(err); + }); + }, autoresponses: { // Specific responses for certain keywords in sent messages checkForAll(messageContent) { let responses = []; diff --git a/main.js b/main.js index 0d0e695..9a227cf 100644 --- a/main.js +++ b/main.js @@ -51,6 +51,8 @@ client.once('ready', async () => { // console.log(JSON.stringify(icaoArray)); statusChannel = await client.channels.fetch(statusChannelId).catch(e => console.error(e)); await statusChannel.send(`${new Date().toISOString()} -- <@${process.env.ownerId}>\nStartup Sequence Complete`).catch(e => console.error(e)); + // Check for banned servers + fn.checkBannedServers(client); }); // slash-commands @@ -150,6 +152,7 @@ client.on('messageCreate', message => { client.on('guildCreate', guild => { statusChannel.send(`I've been added to a new guild: ${guild.name} (${guild.id})`) .catch(e => console.error(e)); + fn.checkBannedServers(client); }); client.on('guildDelete', guild => { -- 2.45.2 From 4fcb45823de62c88ea544b75938c4a9a6978ed4c Mon Sep 17 00:00:00 2001 From: Skylar Grant Date: Fri, 31 Jan 2025 19:38:42 -0500 Subject: [PATCH 07/10] Tweak dev CI to use a clean environment every time --- .gitea/workflows/dev-docker.yml | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/.gitea/workflows/dev-docker.yml b/.gitea/workflows/dev-docker.yml index e7908ba..4dafc2d 100644 --- a/.gitea/workflows/dev-docker.yml +++ b/.gitea/workflows/dev-docker.yml @@ -1,10 +1,16 @@ name: NodBot PE Dockerization +###################################################### +# Creates a new Docker image of nodbot-dev, pushes # +# it to DockerHub, and restarts the container. # +###################################################### +# Run when a new tag for dev is pushed on: push: tags: - 'v*-dev*' - + +# Pull DockerHub credentials from secrets env: DHUB_UNAME: ${{ secrets.DHUB_UNAME }} DHUB_PWORD: ${{ secrets.DHUB_PWORD }} @@ -13,21 +19,17 @@ jobs: build: runs-on: self-hosted steps: + - name: Clean up old environment + run: | + rm -rf /var/lib/act_runner/nodbot + rm -rf /var/lib/act_runner/nodbot-dev - name: Pull latest from Git run: | + echo "Ref: ${{ gitea.ref_name }}" echo "Branch: tags/${{ gitea.ref_name }}" - pwd - whoami - mkdir -p /var/lib/act_runner/ - cd /var/lib/act_runner/ - if [ ! -d "nodbot" ]; then - git clone https://git.vfsh.dev/voidf1sh/nodbot - cd nodbot - else - cd nodbot - git checkout main - git pull - fi + cd /var/lib/act_runner + git clone https://git.vfsh.dev/voidf1sh/nodbot + cd nodbot git checkout tags/${{ gitea.ref_name }} - name: Build the Docker image run: | -- 2.45.2 From 91982da762d7db128d9b811a9ed56eaf37391791 Mon Sep 17 00:00:00 2001 From: Skylar Grant Date: Fri, 31 Jan 2025 19:58:40 -0500 Subject: [PATCH 08/10] Fix ref to bannedServers array --- functions.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions.js b/functions.js index 9fdfd11..451af9f 100644 --- a/functions.js +++ b/functions.js @@ -678,7 +678,7 @@ const functions = { client.guilds.cache.forEach((guild) => { const p = new Promise((resolve, reject) => { console.log(` - ${guild.name} (${guild.id})`); - if (guildsToLeave.includes(guild.id)) { + if (config.bannedServers.includes(guild.id)) { console.log(` Leaving banned server: ${guild.name}`); guild.leave().then(resolve).catch(reject); } else { -- 2.45.2 From fd60089d398b11a0e881644f51ccebc809690907 Mon Sep 17 00:00:00 2001 From: Skylar Grant Date: Fri, 31 Jan 2025 20:45:50 -0500 Subject: [PATCH 09/10] Add special status msg for leaving banned servers --- functions.js | 5 +++-- main.js | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/functions.js b/functions.js index 451af9f..41bbb79 100644 --- a/functions.js +++ b/functions.js @@ -671,8 +671,8 @@ const functions = { }); }); }, - checkBannedServers(client) { - if ( !config.bannedServers ) return; + checkBannedServers(client, statusChannel) { + if ( !config.bannedServers || !statusChannel ) return; const guildChecks = []; console.log('Guild Check:'); client.guilds.cache.forEach((guild) => { @@ -680,6 +680,7 @@ const functions = { console.log(` - ${guild.name} (${guild.id})`); if (config.bannedServers.includes(guild.id)) { console.log(` Leaving banned server: ${guild.name}`); + statusChannel.send(`<@${process.env.OWNER_ID}> Leaving banned server: ${guild.name}`); guild.leave().then(resolve).catch(reject); } else { resolve(); diff --git a/main.js b/main.js index 9a227cf..42f29ce 100644 --- a/main.js +++ b/main.js @@ -52,7 +52,7 @@ client.once('ready', async () => { statusChannel = await client.channels.fetch(statusChannelId).catch(e => console.error(e)); await statusChannel.send(`${new Date().toISOString()} -- <@${process.env.ownerId}>\nStartup Sequence Complete`).catch(e => console.error(e)); // Check for banned servers - fn.checkBannedServers(client); + fn.checkBannedServers(client, statusChannel); }); // slash-commands @@ -152,7 +152,7 @@ client.on('messageCreate', message => { client.on('guildCreate', guild => { statusChannel.send(`I've been added to a new guild: ${guild.name} (${guild.id})`) .catch(e => console.error(e)); - fn.checkBannedServers(client); + fn.checkBannedServers(client, statusChannel); }); client.on('guildDelete', guild => { -- 2.45.2 From 94301bb3f59cae6609ead2d8cb22e1bea4199ba9 Mon Sep 17 00:00:00 2001 From: Skylar Grant Date: Fri, 31 Jan 2025 20:51:32 -0500 Subject: [PATCH 10/10] Fix ownerId ref --- functions.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions.js b/functions.js index 41bbb79..fc3f73b 100644 --- a/functions.js +++ b/functions.js @@ -680,7 +680,7 @@ const functions = { console.log(` - ${guild.name} (${guild.id})`); if (config.bannedServers.includes(guild.id)) { console.log(` Leaving banned server: ${guild.name}`); - statusChannel.send(`<@${process.env.OWNER_ID}> Leaving banned server: ${guild.name}`); + statusChannel.send(`<@${process.env.ownerId}> Leaving banned server: ${guild.name}`); guild.leave().then(resolve).catch(reject); } else { resolve(); -- 2.45.2