Skip to content

Commit

Permalink
Merge pull request #51 from Dunedan/fix-crash-on-invalid-nicknames
Browse files Browse the repository at this point in the history
Fix crash of moderation bot for invalid nicknames
  • Loading branch information
Dunedan authored Jan 20, 2025
2 parents 9b2c0ab + d10e432 commit f0f5a84
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,4 @@ convention = "pep257"
[tool.ruff.lint.pylint]
max-args = 10
max-nested-blocks = 4
max-returns = 8
17 changes: 14 additions & 3 deletions xpartamupp/modbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
from simplemma.strategies.dictionaries import TrieDictionaryFactory
from slixmpp import ClientXMPP, Message
from slixmpp.exceptions import IqError
from slixmpp.jid import JID
from slixmpp.jid import JID, InvalidJID
from slixmpp.plugins.xep_0045 import MUCPresence
from sqlalchemy import create_engine, func, select, text
from sqlalchemy.dialects.sqlite.base import SQLiteDialect
Expand Down Expand Up @@ -584,7 +584,7 @@ async def _muc_check_profanity(self, msg: Message) -> None:
offending_content=msg_body,
)

async def _muc_command_message(self, msg: Message) -> None:
async def _muc_command_message(self, msg: Message) -> None: # noqa: C901
"""Process messages in the command MUC room.
Detect commands posted in the command MUC room and act on them.
Expand Down Expand Up @@ -626,7 +626,18 @@ async def _muc_command_message(self, msg: Message) -> None:
await self.send_profanity_term_list(args.lang)
return

user = JID(args.user + "@" + self.boundjid.domain)
try:
user = JID(
"".join([c for c in args.user if c.isprintable()]) + "@" + self.boundjid.domain
)
except InvalidJID:
self.send_message(
mto=self.command_room,
mbody=f'"{args.user}" is an invalid nickname.',
mtype="groupchat",
)
return

moderator = JID(moderator)
reason = " ".join(args.reason)

Expand Down

0 comments on commit f0f5a84

Please sign in to comment.