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: | diff --git a/CHANGELOG.md b/CHANGELOG.md index 3f6670a..3fec378 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ ## v3.4.x +#### v3.4.3 (#29) +* 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 @@ -32,4 +36,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/_list-guilds.js b/_list-guilds.js new file mode 100644 index 0000000..0829c91 --- /dev/null +++ b/_list-guilds.js @@ -0,0 +1,38 @@ +/* + * Quick and dirty script to list out what guilds the bot is in and optionally leave some. + */ + +const guildsToLeave = ['1224396616555823124']; + +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 () => { + const guildChecks = []; + console.log(`Logged in as ${client.user.tag}`); + console.log('Guilds:'); + 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); + }); + await Promise.all(guildChecks); + console.log('All guilds checked.'); + client.destroy(); +}); + +client.login(token); \ No newline at end of file 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/dot-commands/gif.js b/dot-commands/gif.js index dc2ff98..9aacfc5 100644 --- a/dot-commands/gif.js +++ b/dot-commands/gif.js @@ -22,14 +22,28 @@ 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); 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(async (refMsg) => { + // Send the reply to the referenced message + await refMsg.reply(commandData.embed_url); + }).catch(async (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/functions.js b/functions.js index 01466b5..fc3f73b 100644 --- a/functions.js +++ b/functions.js @@ -671,6 +671,29 @@ const functions = { }); }); }, + checkBannedServers(client, statusChannel) { + if ( !config.bannedServers || !statusChannel ) 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 (config.bannedServers.includes(guild.id)) { + console.log(` Leaving banned server: ${guild.name}`); + statusChannel.send(`<@${process.env.ownerId}> 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 c97a05d..42f29ce 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,10 @@ 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 statusChannel.send(`${new Date().toISOString()} -- <@${process.env.ownerId}>\nStartup Sequence Complete`).catch(e => console.error(e)); + // Check for banned servers + fn.checkBannedServers(client, statusChannel); }); // slash-commands @@ -146,4 +148,16 @@ client.on('messageCreate', message => { return; }); +// Guild Joins and Leaves: +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, statusChannel); +}); + +client.on('guildDelete', guild => { + 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 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": {