Skip to content

Commit

Permalink
Chatushka (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
shpaker authored Aug 7, 2021
1 parent e2fe728 commit b13ac3f
Show file tree
Hide file tree
Showing 10 changed files with 80 additions and 9 deletions.
69 changes: 66 additions & 3 deletions chatushka/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ async def on_question_command(
)


@on_cron("*/1 * * * *")
def reminder_on_cron():
logger.debug(777777)
# @on_cron("*/1 * * * *")
# def reminder_on_cron():
# logger.debug(777777)


@on_commands("id")
Expand Down Expand Up @@ -150,6 +150,69 @@ async def on_joke_command(
)


@on_sensitive_commands("mute")
async def on_mute_command(
api: TelegramBotApi,
message: Message,
args: list[str],
) -> None:
if message.user.id not in settings.admins:
return None
if not args:
await api.send_message(
chat_id=message.chat.id,
text=f"🧐 уточни времянной период на который необходимо замьютить пользователя",
reply_to_message_id=message.message_id,
)
return None

if not message.reply_to_message:
await api.send_message(
chat_id=message.chat.id,
text=f"🧐 Комманда должна быть реплаем",
reply_to_message_id=message.message_id,
)
return None

try:
restrict_time = timedelta(hours=int(args[0]))
except ValueError:
restrict_time = timedelta(minutes=randrange(10, 30))
await api.send_message(
chat_id=message.chat.id,
text=f"🧐 не удалось спарсить значение и я решил, "
f"что надо замьютить {message.reply_to_message.user.readable_name} "
f"на {restrict_time} минут",
reply_to_message_id=message.message_id,
)

try:
is_success = await api.restrict_chat_member(
chat_id=message.chat.id,
user_id=message.reply_to_message.user.id,
permissions=ChatPermissions(
can_send_messages=False,
can_send_media_messages=False,
can_send_polls=False,
can_send_other_messages=False,
),
until_date=datetime.now(tz=timezone.utc) + restrict_time,
)
except ValueError:
is_success = False
if is_success:
await api.send_message(
chat_id=message.chat.id,
text=f"Пользователь {message.reply_to_message.user.readable_name} принял обет молчания",
)
return None
await api.send_message(
chat_id=message.chat.id,
text=f"Лапки коротковаты чтоб убить {message.user.readable_name}",
reply_to_message_id=message.message_id,
)


@on_sensitive_commands("suicide", "wtf") # type: ignore
async def on_suicide_command(
api: TelegramBotApi,
Expand Down
2 changes: 1 addition & 1 deletion chatushka/matchers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from chatushka.matchers.events import EventsMatcher
from chatushka.matchers.regex import RegexMatcher
from chatushka.protocols import MatcherProtocol
from chatushka.types import EventTypes
from chatushka.models import EventTypes

__all__ = (
"EventTypes",
Expand Down
2 changes: 1 addition & 1 deletion chatushka/matchers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from chatushka.transports.models import Message
from chatushka.transports.telegram_bot_api import TelegramBotApi
from chatushka.types import HANDLER_TYPING, MatchedToken
from chatushka.models import HANDLER_TYPING, MatchedToken


class MatcherBase(ABC):
Expand Down
2 changes: 1 addition & 1 deletion chatushka/matchers/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from chatushka.matchers.base import MatcherBase
from chatushka.transports.models import Message
from chatushka.types import MatchedToken
from chatushka.models import MatchedToken


class CommandsMatcher(MatcherBase):
Expand Down
2 changes: 1 addition & 1 deletion chatushka/matchers/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from chatushka.matchers.base import MatcherBase
from chatushka.transports.models import Message
from chatushka.types import EventTypes, MatchedToken
from chatushka.models import EventTypes, MatchedToken

logger = getLogger(__name__)

Expand Down
2 changes: 1 addition & 1 deletion chatushka/matchers/regex.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from chatushka.matchers.base import MatcherBase
from chatushka.transports.models import Message
from chatushka.types import MatchedToken, RegexMatchKwargs
from chatushka.models import MatchedToken, RegexMatchKwargs

logger = getLogger(__name__)

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion chatushka/protocols.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from chatushka.transports.models import Message
from chatushka.transports.telegram_bot_api import TelegramBotApi
from chatushka.types import HANDLER_TYPING, MatchedToken
from chatushka.models import HANDLER_TYPING, MatchedToken


class MatcherProtocol(Protocol):
Expand Down
4 changes: 4 additions & 0 deletions chatushka/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ class _Settings(BaseSettings):
"!",
)
allow_raw_command: bool = True
admins: tuple[int, ...] = (
514026725,
147727588,
)

class Config:
env_prefix = SETTINGS_ENV_PREFIX
Expand Down
4 changes: 4 additions & 0 deletions chatushka/transports/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ class Message(BaseModel):
user: User = Field(..., alias="from")
chat: Chat
text: str
reply_to_message: Optional["Message"] = None


Message.update_forward_refs()


class Update(BaseModel):
Expand Down

0 comments on commit b13ac3f

Please sign in to comment.