Skip to content

Commit

Permalink
Improve regex
Browse files Browse the repository at this point in the history
  • Loading branch information
trickeydan committed Sep 17, 2024
1 parent 5208b2b commit 2bc92f3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
7 changes: 5 additions & 2 deletions kmibot/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,16 @@ async def get_fact_for_person(self, person_id: UUID) -> FactSchema:
data = await self._request("GET", f"v2/people/{person_id}/fact/")
return FactSchema.model_validate(data)

async def create_accusation(self, created_by: UUID, suspect: UUID, quote: str) -> None:
async def create_accusation(
self, created_by: UUID, suspect: UUID, quote: str
) -> AccusationSchema:
payload = {
"quote": quote,
"suspect": str(suspect),
"created_by": str(created_by),
}
await self._request("POST", "v2/court/accusations/", json=payload)
data = await self._request("POST", "v2/court/accusations/", json=payload)
return AccusationSchema.model_validate(data)

async def get_accusation(self, accusation_id: UUID) -> AccusationSchema:
data = await self._request("GET", f"v2/court/accusations/{accusation_id}/")
Expand Down
7 changes: 4 additions & 3 deletions kmibot/modules/ferry/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import asyncio
from logging import getLogger
import re
from typing import TYPE_CHECKING

import discord
Expand Down Expand Up @@ -57,9 +58,9 @@ async def on_reaction_add(self, reaction: discord.Reaction, user: discord.User)

async def on_message(self, message: discord.Message) -> None:
assert self.client.user
if (
message.author != self.client.user
and self.client.config.ferry.banned_word in message.content
pattern = rf"\b{self.client.config.ferry.banned_word}\b"
if message.author != self.client.user and re.match(
pattern, message.content, flags=re.IGNORECASE
):
LOGGER.info(f"{message.author.display_name} ferried in #{message.channel}")
for emoji in self.client.config.ferry.emoji_reacts:
Expand Down

0 comments on commit 2bc92f3

Please sign in to comment.