stage
This commit is contained in:
57
bot/femboygenerator.py
Normal file
57
bot/femboygenerator.py
Normal file
@ -0,0 +1,57 @@
|
||||
from dataclasses import dataclass
|
||||
import os
|
||||
import random
|
||||
from telebot.types import Message
|
||||
|
||||
from exception import UnknownAnimationType
|
||||
|
||||
|
||||
@dataclass(frozen=True, init=True, eq=True)
|
||||
class FemboyGeneratorResult:
|
||||
send: bool
|
||||
message: Message | None = None
|
||||
media_type: str | None = None
|
||||
media_path: str | None = None
|
||||
|
||||
|
||||
class FemboyGeneratorMsgProcessor:
|
||||
ODDS = 1/200
|
||||
TRIGGER_WORDS = [
|
||||
"uwu",
|
||||
"femboy",
|
||||
"фембой",
|
||||
]
|
||||
|
||||
def __init__(self, msg: Message):
|
||||
self._msg = msg
|
||||
|
||||
def process_trigger_words(self) -> bool:
|
||||
t = self._msg.text.lower()
|
||||
for tw in self.TRIGGER_WORDS:
|
||||
if tw in t:
|
||||
return True
|
||||
return False
|
||||
|
||||
@staticmethod
|
||||
def pick_random_media() -> str:
|
||||
return random.choice(os.listdir("femboys"))
|
||||
|
||||
@staticmethod
|
||||
def get_media_type(path: str) -> str:
|
||||
if path.endswith((".jpg", ".jpeg", ".png")):
|
||||
return "pic"
|
||||
elif path.endswith((".mp4", ".m4a", ".gif")):
|
||||
return "gif"
|
||||
raise UnknownAnimationType("Unknown media type in femboys folder -w-")
|
||||
|
||||
def process(self) -> FemboyGeneratorResult:
|
||||
if self._msg:
|
||||
if random.random() < self.ODDS or self.process_trigger_words():
|
||||
random_file_path = self.pick_random_media()
|
||||
return FemboyGeneratorResult(
|
||||
send=True,
|
||||
message=self._msg,
|
||||
media_type=self.get_media_type(random_file_path),
|
||||
media_path=random_file_path
|
||||
)
|
||||
return FemboyGeneratorResult(send=False)
|
||||
Reference in New Issue
Block a user