-
-
Notifications
You must be signed in to change notification settings - Fork 48
Added module name-list-cleaner #178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: beta-discordjs14
Are you sure you want to change the base?
Changes from all commits
81e26b6
cd38e3a
208be14
1933727
92664c6
fee61fa
5c0b6ea
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| { | ||
| "description": { | ||
| "en": "Configure the function of the module here", | ||
| "de": "Stelle hier die Funktionen des Modules ein" | ||
| }, | ||
| "humanName": { | ||
| "en": "Configuration", | ||
| "de": "Konfiguration" | ||
| }, | ||
| "filename": "config.json", | ||
| "content": [ | ||
| { | ||
| "name": "keepNickname", | ||
| "humanName": { | ||
| "en": "Keep nickname", | ||
| "de": "Nickname behalten" | ||
| }, | ||
| "default": { | ||
| "en": true | ||
| }, | ||
| "description": { | ||
| "en": "If yes: special characters will be removed from nicknames; if no: the nickname will be removed and the username will be shown instead.", | ||
| "de": "Wenn ja: Sonderzeichen werden aus den Nicknames entfernt; wenn nein: der Nickname wird entfernt und stattdessen der Benutzername angezeigt." | ||
| }, | ||
| "type": "boolean" | ||
| }, | ||
| { | ||
| "name": "symbolWhitelist", | ||
| "humanName": { | ||
| "en": "Character Whitelist/Blacklist", | ||
| "de": "Zeichen Whitelist/Blacklist" | ||
| }, | ||
| "default": { | ||
| "en": [] | ||
| }, | ||
| "description": { | ||
| "en": "A list of characters that should be allowed (whitelist) or blocked (blacklist) at the start of usernames. If the list is empty, all non-alphanumeric characters will be removed.", | ||
| "de": "Eine Liste von Zeichen, die am Anfang von Benutzernamen erlaubt (Whitelist) oder blockiert (Blacklist) werden sollen. Wenn die Liste leer ist, werden alle nicht-alphanumerischen Zeichen entfernt." | ||
| }, | ||
| "type": "array", | ||
| "content": "string" | ||
| }, | ||
| { | ||
| "name": "isBlacklist", | ||
| "humanName": { | ||
| "en": "Use blacklist instead of whitelist", | ||
| "de": "Blacklist statt Whitelist verwenden" | ||
| }, | ||
| "default": { | ||
| "en": false | ||
| }, | ||
| "description": { | ||
| "en": "If yes: the list of characters will be treated as a blacklist (characters in the list will be blocked); if no: the list will be treated as a whitelist (only characters in the list and alphanumeric characters will be allowed).", | ||
| "de": "Wenn ja: die Liste der Zeichen wird als Blacklist behandelt (Zeichen in der Liste werden blockiert); wenn nein: die Liste wird als Whitelist behandelt (nur Zeichen in der Liste und alphanumerische Zeichen werden erlaubt)." | ||
| }, | ||
| "type": "boolean" | ||
| }, | ||
| { | ||
| "name": "userWhitelist", | ||
| "humanName": { | ||
| "en": "User Whitelist", | ||
| "de": "Benutzer-Whitelist" | ||
| }, | ||
| "default": { | ||
| "en": [] | ||
| }, | ||
| "description": { | ||
| "en": "A list of user IDs that should be exempt from the username check. Usernames of these users will not be modified.", | ||
| "de": "Eine Liste von Benutzer-IDs, die von der Benutzernamenprüfung ausgenommen werden sollen. Die Benutzernamen dieser Benutzer werden nicht geändert." | ||
| }, | ||
| "type": "array", | ||
| "content": "userID" | ||
| }, | ||
| { | ||
| "name": "alsoCheckUsernames", | ||
| "humanName": { | ||
| "en": "Also check usernames", | ||
| "de": "Auch Benutzernamen überprüfen" | ||
| }, | ||
| "default": { | ||
| "en": false | ||
| }, | ||
| "description": { | ||
| "en": "If yes: not only nicknames but also usernames will be checked for special characters and modified accordingly. If no: only nicknames will be checked and modified, usernames will be left unchanged.", | ||
| "de": "Wenn ja: nicht nur Nicknames, sondern auch Benutzernamen werden auf Sonderzeichen überprüft und entsprechend geändert. Wenn nein: nur Nicknames werden überprüft und geändert, Benutzernamen bleiben unverändert." | ||
| }, | ||
| "type": "boolean" | ||
| } | ||
| ] | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| const {renameMember} = require('../renameMember'); | ||
|
|
||
| module.exports.run = async function (client) { | ||
| for (const member of client.guild.members.cache.values()) { | ||
| await renameMember(client, member); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| const {renameMember} = require("../renameMember"); | ||
| module.exports.run = async function (client, oldGuildMember, newGuildMember) { | ||
|
|
||
| if (!client.botReadyAt) return; | ||
| if (newGuildMember.guild.id !== client.guild.id) return; | ||
| if (oldGuildMember.nickname === newGuildMember.nickname && oldGuildMember.user.username === newGuildMember.user.username) return; | ||
| await renameMember(client, newGuildMember); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| { | ||
| "name": "name-list-cleaner", | ||
| "humanReadableName": { | ||
| "en": "Name List Cleaner", | ||
| "de": "Namenslisten Cleaner" | ||
| }, | ||
| "author": { | ||
| "name": "hfgd", | ||
| "link": "https://github.com/hfgd123", | ||
| "scnxOrgID": "2" | ||
| }, | ||
| "openSourceURL": "https://github.com/hfgd123/CustomDCBot/tree/main/modules/name-list-cleaner", | ||
| "config-example-files": [ | ||
| "configs/config.json" | ||
| ], | ||
| "events-dir": "/events", | ||
| "tags": [ | ||
| "tools" | ||
| ], | ||
| "description": { | ||
| "en": "Remove special characters from the beginning of usernames", | ||
| "de": "Entferne Sonderzeichen vom Anfang von Benutzernamen" | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,65 @@ | ||||||||||||||||||||||||||||||
| const {localize} = require("../../src/functions/localize"); | ||||||||||||||||||||||||||||||
| renameMember = async function (client, guildMember) { | ||||||||||||||||||||||||||||||
| let newName; | ||||||||||||||||||||||||||||||
|
Comment on lines
+2
to
+3
|
||||||||||||||||||||||||||||||
| const moduleConf = client.configurations['name-list-cleaner']['config']; | ||||||||||||||||||||||||||||||
| if (moduleConf.userWhitelist.includes(guildMember.user.id)) return; | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| if (guildMember.nickname !== null) { | ||||||||||||||||||||||||||||||
| newName = await checkUsername(client, guildMember.nickname, false); | ||||||||||||||||||||||||||||||
| if (newName === guildMember.nickname) return; | ||||||||||||||||||||||||||||||
| } else if (moduleConf.alsoCheckUsernames) { | ||||||||||||||||||||||||||||||
| newName = await checkUsername(client, guildMember.user.username, true); | ||||||||||||||||||||||||||||||
| if (newName === guildMember.user.username) return; | ||||||||||||||||||||||||||||||
| } else return; | ||||||||||||||||||||||||||||||
| if (guildMember.guild.ownerId === guildMember.id) { | ||||||||||||||||||||||||||||||
| client.logger.error('[name-list-cleaner] ' + localize('name-list-cleaner', 'owner-cannot-be-renamed', {u: guildMember.user.username})) | ||||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| if (moduleConf.keepNickname) { | ||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||
| await guildMember.setNickname(newName, localize('name-list-cleaner', 'nickname-changed', {u: guildMember.user.username})); | ||||||||||||||||||||||||||||||
| } catch (e) { | ||||||||||||||||||||||||||||||
| client.logger.error('[name-list-cleaner] ' + localize('name-list-cleaner', 'nickname-error', {u: guildMember.user.username, e: e})) | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||
hfgd123 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||
| if (guildMember.nickname === null) { | ||||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||
| await guildMember.setNickname(null, localize('name-list-cleaner', 'nickname-reset', {u: guildMember.user.username})); | ||||||||||||||||||||||||||||||
| } catch (e) { | ||||||||||||||||||||||||||||||
| client.logger.error('[name-list-cleaner] ' + localize('name-list-cleaner', 'nickname-error', {u: guildMember.user.username, e: e})) | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| module.exports.renameMember = renameMember; | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| async function checkUsername(client, name, isUsername) { | ||||||||||||||||||||||||||||||
| const moduleConf = client.configurations['name-list-cleaner']['config']; | ||||||||||||||||||||||||||||||
| if (name.length === 0) { | ||||||||||||||||||||||||||||||
| if (isUsername) { | ||||||||||||||||||||||||||||||
| return 'User' | ||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||
| return null; | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| if (moduleConf.symbolWhitelist.length === 0) { | ||||||||||||||||||||||||||||||
| if (name.charAt(0).match(/^[a-zA-Z0-9]$/)) { | ||||||||||||||||||||||||||||||
| return name; | ||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||
| return await checkUsername(client, name.substring(1), isUsername); | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
Comment on lines
+48
to
+53
|
||||||||||||||||||||||||||||||
| } else if (!moduleConf.symbolWhitelist.includes(name.charAt(0)) && !moduleConf.isBlacklist) { | ||||||||||||||||||||||||||||||
| if (name.charAt(0).match(/^[a-zA-Z0-9]$/)) { | ||||||||||||||||||||||||||||||
|
Comment on lines
+49
to
+55
|
||||||||||||||||||||||||||||||
| if (name.charAt(0).match(/^[a-zA-Z0-9]$/)) { | |
| return name; | |
| } else { | |
| return await checkUsername(client, name.substring(1), isUsername); | |
| } | |
| } else if (!moduleConf.symbolWhitelist.includes(name.charAt(0)) && !moduleConf.isBlacklist) { | |
| if (name.charAt(0).match(/^[a-zA-Z0-9]$/)) { | |
| if (name.charAt(0).match(/^[\p{L}\p{N}]$/u)) { | |
| return name; | |
| } else { | |
| return await checkUsername(client, name.substring(1), isUsername); | |
| } | |
| } else if (!moduleConf.symbolWhitelist.includes(name.charAt(0)) && !moduleConf.isBlacklist) { | |
| if (name.charAt(0).match(/^[\p{L}\p{N}]$/u)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you want it to accept anything else, you can whitelist it, ig
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
imagine whitelisting every chinese character
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
true... But at the same time: Where would you draw the line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
guildMemberUpdategenerally won’t fire for global username changes (those emituserUpdate), so theoldGuildMember.user.username !== newGuildMember.user.usernamecheck is unlikely to catch username edits. IfalsoCheckUsernamesis meant to react to username changes, add auserUpdateevent handler (and map the updated user to the guild member) instead of relying onguildMemberUpdate.