From 2ad06a1467110ec7aa0f5bfe8671acde01239042 Mon Sep 17 00:00:00 2001 From: hfgd Date: Wed, 1 Jun 2022 17:32:06 +0200 Subject: [PATCH] Committing SCDerox's auto-react update, after understanding it (at least I think so) --- modules/auto-react/{ => configs}/config.json | 0 modules/auto-react/configs/replies.json | 27 ++++++++++++++++++++ modules/auto-react/events/messageCreate.js | 22 ++++++++++++++++ modules/auto-react/module.json | 4 ++- 4 files changed, 52 insertions(+), 1 deletion(-) rename modules/auto-react/{ => configs}/config.json (100%) create mode 100644 modules/auto-react/configs/replies.json diff --git a/modules/auto-react/config.json b/modules/auto-react/configs/config.json similarity index 100% rename from modules/auto-react/config.json rename to modules/auto-react/configs/config.json diff --git a/modules/auto-react/configs/replies.json b/modules/auto-react/configs/replies.json new file mode 100644 index 00000000..918bee63 --- /dev/null +++ b/modules/auto-react/configs/replies.json @@ -0,0 +1,27 @@ +{ + "filename": "replies.json", + "humanname-de": "Antworten", + "humanname-en": "Replies", + "configElements": true, + "content": [ + { + "field_name": "members", + "default": "", + "humanname-de": "Nutzer", + "humanname-en": "User", + "type": "string", + "description-en": "Here you can add a member to be replied on mentions of them", + "description-de": "Du kannst hier einen Nutzer für Antworten auf Erwähnungen dessen eintragen" + }, + { + "field_name": "reply", + "default": "", + "humanname-de": "Antwort", + "humanname-en": "Reply", + "type": "string", + "description-en": "Here you can add the reply message", + "description-de": "Du kannst hier die Antwort eintragen", + "allowEmbed": true + } + ] +} \ No newline at end of file diff --git a/modules/auto-react/events/messageCreate.js b/modules/auto-react/events/messageCreate.js index 7a0a5058..fe4f5a1d 100644 --- a/modules/auto-react/events/messageCreate.js +++ b/modules/auto-react/events/messageCreate.js @@ -1,3 +1,4 @@ +const {embedType} = require('../../../src/functions/helpers'); module.exports.run = async (client, msg) => { if (!client.botReadyAt) return; if (msg.interaction || msg.system || !msg.guild || msg.guild.id !== client.config.guildID) return; @@ -5,6 +6,7 @@ module.exports.run = async (client, msg) => { await checkMembers(msg); await checkCategory(msg); await checkAuthor(msg); + await checkMembersReply(msg); }; /** @@ -56,6 +58,26 @@ async function checkCategory(msg) { }); } +/** + * Checks for member pings in a message and replys with the configured message + * @private + * @param msg + * @returns {Promise} + */ +async function checkMembersReply(msg) { + const moduleConfig = msg.client.configurations['auto-react']['replies']; + if (!msg.mentions.users) return; + if (msg.author.id === msg.client.user.id) return; + for (const m of msg.mentions.users.values()) { + const matches = moduleConfig.filter(c => c.members === m.id); + for (const element of matches) { + await msg.reply(embedType(element.reply, {}, {ephemeral: true})).catch(() => { + }); + } + } +} + + /** * Checks if a message need reactions (and reacts if needed) because it was send in a configured channel * @private diff --git a/modules/auto-react/module.json b/modules/auto-react/module.json index d9d5e137..fa6fbf63 100644 --- a/modules/auto-react/module.json +++ b/modules/auto-react/module.json @@ -2,6 +2,7 @@ "name": "auto-react", "humanReadableName-de": "Automatisches Reagieren", "humanReadableName-en": "Automatic reactions", + "fa-icon": "far fa-smile", "author": { "scnxOrgID": "1", "name": "SCDerox (SC Network Team)", @@ -12,7 +13,8 @@ "description-de": "Reagiert automatisch mit ausgewählten Emojs in einem ausgewählten Channel und bei Pings", "events-dir": "/events", "config-example-files": [ - "config.json" + "configs/config.json", + "configs/replies.json" ], "tags": [ "fun"