Skip to content

Commit

Permalink
Merge branch 'dev' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
DarkView committed Mar 6, 2021
2 parents 310d9b7 + b0bde4b commit 2356d8f
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 10 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
## Version 1.3
- New command: `rtRefresh`
Allows any owner to instantly refresh all reactions

The bot now removes and re-applies all reactions it manages automatically every 30 minutes and on restart.
In case you want to immediately refresh, you can use the `rtRefresh` command which advances the next check so it happens right away.

Please read the [command documentation](https://github.com/MMPlugins/ReactionThreads#commands) to learn how to use this new command!

## Version 1.2
- New command: `rtList`
Allows any owner to list all reactions the bot currently has registered
Expand Down
17 changes: 13 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
## A plugin for [Dragory's ModMail](https://github.com/dragory/modmailbot) that allows users to open threads with reactions
**Currently on Version 1.2**
**Currently on Version 1.3**
A full [changelog can be found here](https://github.com/MMPlugins/ReactionThreads/blob/main/CHANGELOG.md).
Plugin written and maintained by [DarkView](https://github.com/DarkView) (Dark#1010 on Discord)

Expand All @@ -13,6 +13,9 @@ Table of Contents:
- [Commands](#commands)
- [Adding/Registering a reaction](#addingregistering-a-reaction)
- [Removing/De-Registering a reaction](#removingde-registering-a-reaction)
- [Adding/Removing/Displaying custom responses](#addingremovingdisplaying-custom-responses)
- [Listing all reactions](#listing-all-reactions)
- [Refreshing all reactions](#refreshing-all-reactions)

## Setup
Make sure you are running at least v3.3.0 of Modmail.
Expand Down Expand Up @@ -73,9 +76,14 @@ If you want to completely remove a response, pass one of the following without a
This command and its functionality was made by [YetAnotherConnor](https://github.com/YetAnotherConnor).

### Listing all reactions
Signature: Signature: `!rtList [Any ID]`
Signature: `!rtList [Any ID]`
This will return a list of all current reactions that match the ID filter if one is given.
- `Any ID` can be any of the IDs available for reactions: `Channel ID`, `Message ID` and `Category ID`. If this parameter is passed, only reactions that are on that message or in that channel etc. get listed.
- `Any ID` can be any of the IDs available for reactions: `Channel ID`, `Message ID` and `Category ID`. If this parameter is passed, only reactions that are on that message or in that channel etc. get listed.

### Refreshing all reactions
Signature: `!rtRefresh`
This will refresh all reactions this plugin manages.
This happens every 30 minutes automatically, and this command advances the next refresh to happen immediately.


Table of Contents:
Expand All @@ -89,6 +97,7 @@ Table of Contents:
- [Adding/Registering a reaction](#addingregistering-a-reaction)
- [Removing/De-Registering a reaction](#removingde-registering-a-reaction)
- [Adding/Removing/Displaying custom responses](#addingremovingdisplaying-custom-responses)
- [Listing all reactions](#listing-all-reactions)
- [Listing all reactions](#listing-all-reactions)
- [Refreshing all reactions](#refreshing-all-reactions)

Plugin written and maintained by [DarkView](https://github.com/DarkView) (Dark#1010 on Discord)
42 changes: 36 additions & 6 deletions reactionThreads.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
module.exports = function ({ bot, config, commands, knex, threads }) {
const fs = require("fs");
const pluginVersion = "1.2";
const pluginVersion = "1.3";
const changelogUrl = "=> https://daark.de/RTCL <=";
let reactions = [];
const emptyResponse = ["none", "nothing", "empty", "null", "-"];
let refreshTimeout = null;

// Check if ownerId is specified in the config, warn otherwise
const ownerId = config["reactionThreads-ownerId"];
Expand Down Expand Up @@ -246,24 +247,51 @@ module.exports = function ({ bot, config, commands, knex, threads }) {
}
};

//#region reaction refresh loop
const refreshReactions = async (msg = null) => {
clearTimeout(refreshTimeout);
if (msg) {
if (!isOwner(msg)) return;
msg = await msg.channel.createMessage(`Refreshing all reactions...`);
}

for (const react of reactions) {
if (react.channelId === "version") continue;
const emoji = react.emoji.replace(">", "");

await bot.removeMessageReaction(react.channelId, react.messageId, emoji, bot.user.id).catch(() => {});
await bot.addMessageReaction(react.channelId, react.messageId, emoji);
}

if (msg) {
await msg.edit(`Done!`);
}
refreshTimeout = setTimeout(() => {
refreshReactions();
}, 1000 * 60 * 30); //Refresh reactions every 30 minutes
}

refreshReactions();
//#endregion

//#region versioncheck
// Check the plugin version and notify of any updates that happened
let foundVersion = null;
let reactVersion = null;
for (const reaction of reactions) {
if (reaction.channelId == "version") {
foundVersion = reaction.messageId;
reactVersion = reaction;
break;
}
}

if (foundVersion != null && foundVersion != pluginVersion) {
if (reactVersion.messageId != null && reactVersion.messageId != pluginVersion) {
console.info(
`[ReactionThreads] Plugin updated to version ${pluginVersion}, please read the changelog at ${changelogUrl} as there may be important or breaking changes!`,
);
reactions.splice(reactions.indexOf({ channelId: "version", messageId: foundVersion }), 1);
reactions.splice(reactions.indexOf(reactVersion), 1);
reactions.push({ channelId: "version", messageId: pluginVersion });
saveReactions();
} else if (foundVersion == null) {
} else if (reactVersion == null) {
reactions.push({ channelId: "version", messageId: pluginVersion });
saveReactions();
}
Expand Down Expand Up @@ -317,6 +345,8 @@ module.exports = function ({ bot, config, commands, knex, threads }) {

commands.addInboxServerCommand("rtList", [{ name: "anyId", type: "string", required: false }], listReactionsCmd);

commands.addInboxServerCommand("rtRefresh", [], refreshReactions);

bot.on("messageReactionAdd", onReactionAdd);
//#endregion
};

0 comments on commit 2356d8f

Please sign in to comment.