wormhole/commands/moderation.py: 9 commands missing null check on _net() result #8

Open
opened 2026-07-27 04:04:30 -04:00 by everestmcarthur · 0 comments
everestmcarthur commented 2026-07-27 04:04:30 -04:00 (Migrated from github.com)

Summary

The recent commit 1fbb265 added null checks for network existence to settings.py — but the same fix was not applied to moderation.py. Nine moderation commands call _net(name) and immediately use the result without checking if it's None, causing an unhandled crash (AttributeError/TypeError) when an invalid network name is given.

Affected commands

Line Command
L44 wh_mod_unban
L59 wh_mod_mute
L76 wh_mod_unmute
L91 wh_mod_banserver
L104 wh_mod_unbanserver
L117 wh_mod_muteserver
L130 wh_mod_unmuteserver
L145 wh_mod_allowserver
L158 wh_mod_removeallow

Example (L44 — wh_mod_unban)

nd = await self._net(name)          # ← returns None if network doesn't exist
async with self.config.networks() as ns:
    bans = ns[name].get("banned_users", [])  # ← KeyError / crash if nd is None

Fix

Add an early-return guard after every _net() call, identical to how settings.py handles it:

nd = await self._net(name)
if not nd:
    return await ctx.send(embed=err_embed(f"Network `{name}` not found."))

This is the same pattern already used in wh_mod_ban (L25), wh_mod_purge (L173), and all of settings.py.

## Summary The recent commit [1fbb265](https://github.com/everestmcarthur/EveCogs/commit/1fbb265) added null checks for network existence to **settings.py** — but the same fix was **not applied to moderation.py**. Nine moderation commands call `_net(name)` and immediately use the result without checking if it's `None`, causing an unhandled crash (`AttributeError`/`TypeError`) when an invalid network name is given. ## Affected commands | Line | Command | |------|---------| | L44 | `wh_mod_unban` | | L59 | `wh_mod_mute` | | L76 | `wh_mod_unmute` | | L91 | `wh_mod_banserver` | | L104 | `wh_mod_unbanserver` | | L117 | `wh_mod_muteserver` | | L130 | `wh_mod_unmuteserver` | | L145 | `wh_mod_allowserver` | | L158 | `wh_mod_removeallow` | ## Example (L44 — `wh_mod_unban`) ```python nd = await self._net(name) # ← returns None if network doesn't exist async with self.config.networks() as ns: bans = ns[name].get("banned_users", []) # ← KeyError / crash if nd is None ``` ## Fix Add an early-return guard after every `_net()` call, identical to how settings.py handles it: ```python nd = await self._net(name) if not nd: return await ctx.send(embed=err_embed(f"Network `{name}` not found.")) ``` This is the same pattern already used in `wh_mod_ban` (L25), `wh_mod_purge` (L173), and all of settings.py.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: SheWhoReignsSupreme/EveCogs#8
No description provided.