Skip to content

Commit

Permalink
factor out word denylist
Browse files Browse the repository at this point in the history
  • Loading branch information
technillogue committed Jul 24, 2022
1 parent f2a9c93 commit 4f41f18
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions imogen/imogen.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,12 @@ def gpt_prompt(prompt: str = "") -> str:
return completion["choices"][0]["text"].strip()


def should_not_allow(msg: Message) -> bool:
return any(
bad in msg.text for bad in ["porn", "rape", "orgy", "sex"]
) and not is_admin(msg)


class Imogen(GelatoBot):
# pylint: disable=too-many-public-methods, no-self-use
def __init__(self, bot_number: Optional[str] = None) -> None:
Expand Down Expand Up @@ -632,7 +638,7 @@ async def enqueue_prompt(
if attachments != "target" and not msg.text.strip():
return "a prompt is required"
logging.info(msg.full_text)
if not self any(bad in msg.text for bad in ["porn", "rape", "orgy", "sex"]) and not is_admin(msg):
if should_not_allow(msg):
return "no"
if attachments == "init":
params.update(await self.upload_attachment(msg))
Expand Down Expand Up @@ -788,7 +794,7 @@ async def do_diffuse(
if not msg.text.strip():
return "a prompt is required"
logging.info(msg.full_text)
if any(bad in msg.text for bad in ["porn", "rape", "orgy", "sex"]) and not is_admin(msg):
if should_not_allow(msg):
return "no"
params = {}
if not msg.group:
Expand Down Expand Up @@ -821,7 +827,7 @@ async def do_dalle(
if not msg.text.strip():
return "a prompt is required"
logging.info(msg.full_text)
if any(bad in msg.text for bad in ["porn", "orgy", "sex"]) and not is_admin(msg):
if should_not_allow(msg):
return "no"
params = {}
if not msg.group:
Expand Down Expand Up @@ -1072,6 +1078,7 @@ async def do_matrix(self, msg: Message) -> Response:
await self.do_diffuse(msg)
await self.do_imagine(msg)
await self.do_imagine_likely(msg)
return "ok"


@dataclass
Expand Down

0 comments on commit 4f41f18

Please sign in to comment.