diff --git a/default-locales.json b/default-locales.json index fe69c104..bb37977e 100644 --- a/default-locales.json +++ b/default-locales.json @@ -361,6 +361,10 @@ "all-users": "All Users", "bots": "Bots", "humans": "Humans" + }, + "status-role": { + "fulfilled": "Status-role condition is fulfilled", + "not-fulfilled": "Status-role condition is no longer fulfilled" } } } \ No newline at end of file diff --git a/modules/status-roles/configs/config.json b/modules/status-roles/configs/config.json new file mode 100644 index 00000000..1aa0b9d9 --- /dev/null +++ b/modules/status-roles/configs/config.json @@ -0,0 +1,33 @@ +{ + "filename": "config.json", + "humanname-de": "Konfiguration", + "humanname-en": "Configuration", + "description-en": "Configure the function of the module here", + "description-de": "Stelle hier die Funktionen des Modules ein", + "content": [ + { + "field_name": "words", + "humanname-en": "Words", + "humanname-de": "Statusinhalt", + "default": [], + "type": "array", + "content": "string", + "description-en": "Words users should have in their status.", + "description-de": "Wörter, die Nutzer in ihrem Status haben sollen.", + "params-de": {}, + "default-de": [] + }, + { + "field_name": "roles", + "humanname-en": "Roles", + "humanname-de": "Rollen", + "default": [], + "type": "array", + "content": "roleID", + "description-en": "Roles to give to users with one of the words in their status", + "description-de": "Rollen, die an Nutzer mit einem der Wörter im Status vergeben werden sollen", + "params-de": {}, + "default-de": [] + } + ] +} diff --git a/modules/status-roles/events/presenceUpdate.js b/modules/status-roles/events/presenceUpdate.js new file mode 100644 index 00000000..36b3101d --- /dev/null +++ b/modules/status-roles/events/presenceUpdate.js @@ -0,0 +1,36 @@ +const {localize} = require('../../../src/functions/localize'); + +module.exports.run = async function (client, oldPresence, newPresence) { + + if (!client.botReadyAt) return; + if (newPresence.member.guild.id !== client.guildID) return; + const moduleConfig = client.configurations['status-roles']['config']; + const roles = moduleConfig.roles; + const status = moduleConfig.words; + const member = newPresence.member; + + if (newPresence.activities.length > 0) { + if (newPresence.activities[0].state) { + if (status.some(word => newPresence.activities[0].state.toLowerCase().includes(word.toLowerCase()))) { + return member.roles.add(roles, localize('status-role', 'fulfilled')); + } else { + removeRoles(); + } + } else { + removeRoles(); + } + } else { + removeRoles(); + } + + /** + * Removes the roles of an user who no longer fulfills the criteria + */ + function removeRoles() { + for (let i = 0; i < roles.length; i++) { + if (member.roles.cache.has(roles[i])) { + member.roles.remove(roles[i], localize('status-role', 'not-fulfilled')); + } + } + } +}; diff --git a/modules/status-roles/module.json b/modules/status-roles/module.json new file mode 100644 index 00000000..afad7759 --- /dev/null +++ b/modules/status-roles/module.json @@ -0,0 +1,18 @@ +{ + "name": "status-roles", + "humanReadableName-de": "Status-Rollen", + "humanReadableName-en": "Status-roles", + "author": { + "name": "hfgd", + "link": "https://github.com/hfgd123", + "scnxOrgID": "2" + }, + "openSourceURL": "https://github.com/hfgd123/CustomDCBot/tree/main/modules/status-roles", + "description-en": "Simple module to reward users who have an invite to your server in their status!", + "description-de": "Einfaches Modul, um Nutzer zu belohnen, die einen Link zu deinem Server in ihrem Status haben!", + "events-dir": "/events", + "config-example-files": [ + "configs/config.json" + ], + "tags": ["administration"] +}