Overhaul Bot and utilize Discord Embed#20
Overhaul Bot and utilize Discord Embed#20kphoenix137 wants to merge 11 commits intodiasurgical:mainfrom
Conversation
StephenCWills
left a comment
There was a problem hiding this comment.
I really like how this is looking now. Here are a few more suggestions for cleaning things up a bit.
|
Come to think of it, it might be tough to resolve those conflicts with |
9577cff to
125cefb
Compare
Add "Game Closed" to replace game id Remove Players and Options as inline Update game icons Modify game title based on 4 letter code Update missing game ids Handle undefined difficulty and game speed Change unknown to custom for tick rate Overhaul Revert to DevilutionX Game List channel Update bot.py Co-authored-by: Stephen C. Wills <[email protected]> Update bot.py Co-authored-by: Stephen C. Wills <[email protected]> Update commands.py Co-authored-by: Stephen C. Wills <[email protected]> Update game_manager.py Co-authored-by: Stephen C. Wills <[email protected]> Update bot.py Co-authored-by: Stephen C. Wills <[email protected]> Update bot.py Co-authored-by: Stephen C. Wills <[email protected]> Pass config as param Avoid using outdated config Fix mistake Delete discord_bot.py Rename bot.py Return types Appease mypy Change code to British More British
I'll have to change my setup ... but i should have done so a long time ago |
|
Need to update this line to not lower code quality: https://github.com/diasurgical/devilutionx-gamelist/blob/main/.github/workflows/mypy.yml#L23 |
Not sure what you mean |
StephenCWills
left a comment
There was a problem hiding this comment.
I tried going through the commits that you rebased over to see if anything got lost. Most of it was either incorporated, re-implemented, or inconsequential. But I did notice a couple things.
No longer available to admins, only bot owner(s).
Requested changes have been addressed
| def censor_bad_words(name: str) -> str: | ||
| """Replaces banned words in a player's name with asterisks.""" | ||
| name_upper = name.upper() | ||
| for bad_word in BANNED_WORDS: | ||
| if bad_word in name_upper: | ||
| masked_word = "*" * len(bad_word) # Replace with asterisks | ||
| pattern = re.compile( | ||
| re.escape(bad_word), re.IGNORECASE | ||
| ) # Case-insensitive match | ||
| name = pattern.sub(masked_word, name) # Replace in original case | ||
| return name |
There was a problem hiding this comment.
This allows people to infer what words the banlist contains, it's not currently part of the repo I assume by design.
It's also possible to have overlapping banned words, e.g. if "potato" and "tomato" are banned, the name "potatomato" will be censored as either "******mato" or "pota******" depending on the order of the banlist with this code (because you're searching in name_upper but performing the substitution in name).
There was a problem hiding this comment.
... it's not currently part of the repo I assume by design.
If I were to guess, the main reason is so that AJenbo can add words ad-hoc when he feels he needs to, without having to open a PR here or commit changes to the repo.
Good points about overlapping words and being able to infer, though. Perhaps we should just censor the whole name and solve both issues?
| def debug_print( | ||
| *args: Any, sep: str = " ", end: str = "\n", file: Any = None, flush: bool = False | ||
| ) -> None: | ||
| """Prints messages only if debug mode is enabled.""" | ||
| if CONFIG.get("debug", False): | ||
| print(*args, sep=sep, end=end, file=file, flush=flush) |
There was a problem hiding this comment.
Any reason you went back to basic print() output instead of using the existing logging config? You could still let people choose logging level via the config file (with the more widely used trace/debug/info/warning/error levels instead of just debug/warning)
| def sanitize_player_name(name: str) -> str: | ||
| """Removes forbidden characters from a player's name.""" | ||
| return re.sub(FORBIDDEN_CHARS, "", name) # Strip invalid characters |
There was a problem hiding this comment.
I believe the choice to hide games with an invalid player name was deliberate as it's assumed players with these names are malicious. Any players which have a name containing one of these characters have set it using external tools. Vanilla Diablo/DevilutionX don't allow inputting these characters in a name. This is also missing the filtering/validation the current code applies to ensure that no ASCII control characters or multibyte sequences are present in a players name.
| # Run Bot | ||
| with open("./discord_bot_token", "r") as file: | ||
| token = file.readline().strip() |
There was a problem hiding this comment.
The discord token used by the bot is currently part of the config file discord_bot.json. Renaming the config file to config.json is fine imo but I'd rather see the token remain as a config option instead of a bare file. If you'd rather split secret and non-secret options a convention used by other programs is to have config.json and config.private.json, where the latter is excluded from source control. E.g. in the current main branch discord_bot.json is listed in .gitignore and discord_bot.json.template provides an example of the expected structure. You could even put channel id in there since that's closely related to the auth token and not really of any use to other people.
| players = ", ".join( | ||
| censor_bad_words(sanitize_player_name(player)) for player in game["players"] | ||
| ) |
There was a problem hiding this comment.
It appears you've dropped the code that escapes discord formatting characters in player names. This will cause players with valid names (e.g. "M`din") to trigger discord's markdown parser and cause odd formatting to get applied to the embed message.
Adds embeds, as well as overhauling the whole python end of the bot.
Features:
./devilutionx-gamelist) based on OS usedimagesdirectory to automatically have that graphic display in the embed for the respective game type