예제 #1
0
async def _(event):
    if event.fwd_from:
        return
    input_str = event.pattern_match.group(1)
    try:
        sql.set_flood(event.chat_id, input_str)
        sql.__load_flood_settings()
        await edit_or_reply(
            event,
            "Antiflood updated to {} in the current chat".format(input_str))
    except Exception as e:  # pylint:disable=C0103,W0703
        await edit_or_reply(event, str(e))
예제 #2
0
import asyncio

from telethon.tl.functions.channels import EditBannedRequest
from telethon.tl.types import ChatBannedRights

import jarvis.plugins.sql_helper.antiflood_sql as sql
from jarvis import CMD_HELP
from jarvis.utils import admin_cmd, edit_or_reply, sudo_cmd

CHAT_FLOOD = sql.__load_flood_settings()
# warn mode for anti flood
ANTI_FLOOD_WARN_MODE = ChatBannedRights(until_date=None,
                                        view_messages=None,
                                        send_messages=True)


@jarvis.on(admin_cmd(incoming=True))
async def _(event):
    # logger.info(CHAT_FLOOD)
    if not CHAT_FLOOD:
        return
    if not (str(event.chat_id) in CHAT_FLOOD):
        return
    should_ban = sql.update_flood(event.chat_id, event.message.from_id)
    if not should_ban:
        return
    try:
        await event.client(
            EditBannedRequest(event.chat_id, event.message.from_id,
                              ANTI_FLOOD_WARN_MODE))
    except Exception as e:  # pylint:disable=C0103,W0703