-
-
Notifications
You must be signed in to change notification settings - Fork 47
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
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/username-check", | ||
| "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,52 @@ | ||||||||||||||
| const {localize} = require("../../src/functions/localize"); | ||||||||||||||
| renameMember = async function (client, guildMember) { | ||||||||||||||
| let newName; | ||||||||||||||
| 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); | ||||||||||||||
| if (newName === guildMember.nickname) return; | ||||||||||||||
| } else if (moduleConf.alsoCheckUsername) { | ||||||||||||||
|
||||||||||||||
| } else if (moduleConf.alsoCheckUsername) { | |
| } else if (moduleConf.alsoCheckUsernames) { |
Copilot
AI
Feb 17, 2026
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.
The log prefix here is [nicknames] but the message is for the name-list-cleaner module. This makes operational debugging harder; switch the prefix/tag to [name-list-cleaner] for consistency with the rest of this file’s logging.
| client.logger.error('[nicknames] ' + localize('name-list-cleaner', 'owner-cannot-be-renamed', {u: guildMember.user.username})) | |
| client.logger.error('[name-list-cleaner] ' + localize('name-list-cleaner', 'owner-cannot-be-renamed', {u: guildMember.user.username})) |
Copilot
AI
Feb 17, 2026
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 alsoCheckUsernames is enabled and keepNickname is false, this code will attempt setNickname(null, ...) even when the member already has no nickname (no-op but still an API call + audit log entry). Consider short-circuiting when guildMember.nickname === null in this branch to avoid unnecessary requests.
| } else { | |
| } else { | |
| if (guildMember.nickname === null) { | |
| return; | |
| } |
Copilot
AI
Feb 17, 2026
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.
In the keepNickname === false branch, setNickname(null, ...) is awaited without error handling. Other nickname-changing code in this repo wraps setNickname in try/catch (or .catch) to avoid unhandled rejections when the bot lacks permissions / role hierarchy is too low; apply the same handling here.
| await guildMember.setNickname(null, localize('name-list-cleaner', 'nickname-reset', {u: guildMember.user.username})); | |
| 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})) | |
| } |
Copilot
AI
Feb 17, 2026
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.
When the input name consists entirely of stripped characters, this returns the hard-coded string 'INVALID NAME', which would then be applied as a nickname. Consider returning null/'' and handling that in renameMember (e.g., reset nickname or skip) so the bot never sets a literal "INVALID NAME" nickname.
| if (name.length === 0) return 'INVALID NAME'; | |
| if (moduleConf.symbolWhitelist === []) { | |
| if (name.length === 0) return null; | |
| if (!Array.isArray(moduleConf.symbolWhitelist) || moduleConf.symbolWhitelist.length === 0) { |
Copilot
AI
Feb 17, 2026
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.
moduleConf.symbolWhitelist === [] will always be false in JS (array reference comparison). This breaks the intended “empty list” behavior (especially when isBlacklist is true). Use an emptiness check like Array.isArray(...) && symbolWhitelist.length === 0 (and ensure the empty-list behavior matches the config description).
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.
openSourceURLpoints tomodules/username-check, which doesn’t match this module’s name/path (modules/name-list-cleaner). Update it to the correct repository URL so metadata consumers can find the module’s source.