Exemplo n.º 1
0
async def view_locks(_, m: Message):

    (
        v_perm,
        vmsg,
        vmedia,
        vstickers,
        vanimations,
        vgames,
        vinlinebots,
        vwebprev,
        vpolls,
        vinfo,
        vinvite,
        vpin,
    ) = ("", "", "", "", "", "", "", "", "", "", "", "")

    chkmsg = await m.reply_text(tlang(m, "locks.check_perm_msg"))
    v_perm = m.chat.permissions

    async def convert_to_emoji(val: bool):
        if val is True:
            return "✅"
        return "❌"

    vmsg = await convert_to_emoji(v_perm.can_send_messages)
    vmedia = await convert_to_emoji(v_perm.can_send_media_messages)
    vstickers = await convert_to_emoji(v_perm.can_send_stickers)
    vanimations = await convert_to_emoji(v_perm.can_send_animations)
    vgames = await convert_to_emoji(v_perm.can_send_games)
    vinlinebots = await convert_to_emoji(v_perm.can_use_inline_bots)
    vwebprev = await convert_to_emoji(v_perm.can_add_web_page_previews)
    vpolls = await convert_to_emoji(v_perm.can_send_polls)
    vinfo = await convert_to_emoji(v_perm.can_change_info)
    vinvite = await convert_to_emoji(v_perm.can_invite_users)
    vpin = await convert_to_emoji(v_perm.can_pin_messages)

    if v_perm is not None:
        try:
            permission_view_str = (tlang(m, "locks.view_perm")).format(
                vmsg=vmsg,
                vmedia=vmedia,
                vstickers=vstickers,
                vanimations=vanimations,
                vgames=vgames,
                vinlinebots=vinlinebots,
                vwebprev=vwebprev,
                vpolls=vpolls,
                vinfo=vinfo,
                vinvite=vinvite,
                vpin=vpin,
            )
            LOGGER.info(f"{m.from_user.id} used locks cmd in {m.chat.id}")
            await chkmsg.edit_text(permission_view_str)

        except RPCError as e_f:
            await chkmsg.edit_text(tlang(m, "general.something_wrong"))
            await m.reply_text(e_f)

    return
Exemplo n.º 2
0
async def ban_usr(_, m: Message):

    user_id, user_first_name = await extract_user(m)
    try:
        await m.chat.kick_member(user_id)
        await m.reply_text(
            tlang(m, "admin.banned_user").format(
                admin=(await mention_html(m.from_user.first_name,
                                          m.from_user.id)),
                banned=(await mention_html(user_first_name, user_id)),
                chat_title=f"<b>{m.chat.title}</b>",
            ), )
    except ChatAdminRequired:
        await m.reply_text(tlang(m, "admin.not_admin"))
    except RightForbidden:
        await m.reply_text(tlang(m, tlang(m, "admin.bot_no_ban_right")))
    except RPCError as ef:
        await m.reply_text(
            tlang(m, "general.some_error").format(
                SUPPORT_GROUP=f"@{SUPPORT_GROUP}",
                ef=f"<code>{ef}</code>",
            ), )
        LOGGER.error(ef)

    return
Exemplo n.º 3
0
async def view_locks(c: Alita, m: Message):

    v_perm = ""
    vmsg = ""
    vmedia = ""
    vstickers = ""
    vanimations = ""
    vgames = ""
    vinlinebots = ""
    vwebprev = ""
    vpolls = ""
    vinfo = ""
    vinvite = ""
    vpin = ""

    chkmsg = await m.reply_text(tlang(m, "locks.check_perm_msg"))
    v_perm = await c.get_chat(m.chat.id)

    async def convert_to_emoji(val: bool):
        if val is True:
            return "✅"
        return "❌"

    vmsg = await convert_to_emoji(v_perm.permissions.can_send_messages)
    vmedia = await convert_to_emoji(v_perm.permissions.can_send_media_messages)
    vstickers = await convert_to_emoji(v_perm.permissions.can_send_stickers)
    vanimations = await convert_to_emoji(v_perm.permissions.can_send_animations
                                         )
    vgames = await convert_to_emoji(v_perm.permissions.can_send_games)
    vinlinebots = await convert_to_emoji(v_perm.permissions.can_use_inline_bots
                                         )
    vwebprev = await convert_to_emoji(
        v_perm.permissions.can_add_web_page_previews)
    vpolls = await convert_to_emoji(v_perm.permissions.can_send_polls)
    vinfo = await convert_to_emoji(v_perm.permissions.can_change_info)
    vinvite = await convert_to_emoji(v_perm.permissions.can_invite_users)
    vpin = await convert_to_emoji(v_perm.permissions.can_pin_messages)

    if v_perm is not None:
        try:
            permission_view_str = tlang(m, "locks.view_perm").format(
                vmsg=vmsg,
                vmedia=vmedia,
                vstickers=vstickers,
                vanimations=vanimations,
                vgames=vgames,
                vinlinebots=vinlinebots,
                vwebprev=vwebprev,
                vpolls=vpolls,
                vinfo=vinfo,
                vinvite=vinvite,
                vpin=vpin,
            )
            await chkmsg.edit_text(permission_view_str)

        except RPCError as e_f:
            await chkmsg.edit_text(tlang(m, "general.something_wrong"))
            await m.reply_text(e_f)

    return
Exemplo n.º 4
0
async def get_rules(c: Alita, m: Message):

    chat_id = m.chat.id
    rules = db.get_rules(chat_id)

    if not rules:
        await m.reply_text(tlang(m, "rules.no_rules"),
                           reply_to_message_id=m.message_id)
        return

    try:
        await c.send_message(
            m.from_user.id,
            tlang(m, "rules.get_rules").format(
                chat=f"<b>{m.chat.title}</b>",
                rules=rules,
            ),
        )
    except UserIsBlocked:
        me_name = await get_key("BOT_USERNAME")
        pm_kb = InlineKeyboardMarkup(
            [[InlineKeyboardButton("PM", url=f"https://t.me/{me_name}?start")]
             ], )
        await m.reply_text(
            tlang(m, "rules.pm_me"),
            reply_to_message_id=m.message_id,
            reply_markup=pm_kb,
        )
        return

    await m.reply_text(
        tlang(m, "rules.sent_pm_rules"),
        reply_to_message_id=m.message_id,
    )
    return
Exemplo n.º 5
0
async def set_lang(_, m: Message):

    args = m.text.split()

    if len(args) > 2:
        await m.reply_text(tlang(m, "langs.correct_usage"))
        return
    if len(args) == 2:
        lang_code = args[1]
        avail_langs = set(lang_dict.keys())
        if lang_code not in avail_langs:
            await m.reply_text(
                f"Please choose a valid language code from: {', '.join(avail_langs)}",
            )
            return
        db.set_lang(m.chat.id, lang_code)
        LOGGER.info(
            f"{m.from_user.id} change language to {lang_code} in {m.chat.id}")
        await m.reply_text(
            f"🌐 {((tlang(m, 'langs.changed')).format(lang_code=lang_code))}", )
        return
    await m.reply_text(
        (tlang(m, "langs.changelang")),
        reply_markup=InlineKeyboardMarkup([*(await gen_langs_kb())]),
    )
    return
Exemplo n.º 6
0
async def get_invitelink(c: Alita, m: Message):

    try:
        link = await c.export_chat_invite_link(m.chat.id)
        await m.reply_text(
            (tlang(m, "admin.invitelink")).format(
                chat_name=m.chat.id,
                link=link,
            ),
            disable_web_page_preview=True,
        )
        LOGGER.info(f"{m.from_user.id} exported invite link in {m.chat.id}")
    except ChatAdminRequired:
        await m.reply_text(tlang(m, "admin.not_admin"))
    except ChatAdminInviteRequired:
        await m.reply_text(tlang(m, "admin.no_invite_perm"))
    except RightForbidden:
        await m.reply_text(tlang(m, "admin.no_user_invite_perm"))
    except RPCError as ef:
        await m.reply_text(
            (tlang(m, "general.some_error")).format(
                SUPPORT_GROUP=SUPPORT_GROUP,
                ef=ef,
            ),
        )
        LOGGER.error(ef)
        LOGGER.error(format_exc())

    return
Exemplo n.º 7
0
async def unpinall_calllback(c: Alita, q: CallbackQuery):
    user_id = q.from_user.id
    user_status = (await q.message.chat.get_member(user_id)).status
    if user_status not in {"creator", "administrator"}:
        await q.answer(
            "You're not even an admin, don't try this explosive shit!",
            show_alert=True,
        )
        return
    if user_status != "creator":
        await q.answer(
            "You're just an admin, not owner\nStay in your limits!",
            show_alert=True,
        )
        return
    try:
        await c.unpin_all_chat_messages(q.message.chat.id)
        LOGGER.info(
            f"{q.from_user.id} unpinned all messages in {q.message.chat.id}")
        await q.message.edit_text(tlang(q, "pin.unpinned_all_msg"))
    except ChatAdminRequired:
        await q.message.edit_text(tlang(q, "admin.notadmin"))
    except RightForbidden:
        await q.message.edit_text(tlang(q, "pin.no_rights_unpin"))
    except RPCError as ef:
        await q.message.edit_text((tlang(q, "general.some_error")).format(
            SUPPORT_GROUP=SUPPORT_GROUP,
            ef=ef,
        ), )
        LOGGER.error(ef)
    return
Exemplo n.º 8
0
async def get_lyrics(_, m: Message):
    if len(m.text.split()) <= 1:
        await m.reply_text(tlang(m, "general.check_help"))
        return

    query = m.text.split(None, 1)[1]
    LOGGER.info(f"{m.from_user.id} used lyrics cmd in {m.chat.id}")
    song = ""
    if not query:
        await m.edit_text(tlang(m, "utils.song.no_song_given"))
        return

    em = await m.reply_text(
        (tlang(m, "utils.song.searching").format(song_name=query)), )
    song = Song.find_song(query)
    if song:
        if song.lyrics:
            reply = song.format()
        else:
            reply = tlang(m, "utils.song.no_lyrics_found")
    else:
        reply = tlang(m, "utils.song.song_not_found")
    try:
        await em.edit_text(reply)
    except MessageTooLong:
        with BytesIO(str.encode(await remove_markdown_and_html(reply))) as f:
            f.name = "lyrics.txt"
            await m.reply_document(document=f, )
        await em.delete()
    return
Exemplo n.º 9
0
async def rm_blacklist(_, m: Message):

    chat_bl = db.get_chat_blacklist(m.chat.id)
    if not isinstance(chat_bl, bool):
        pass
    else:
        if len(m.text.split()) >= 2:
            bl_word = m.text.split(None, 1)[1]
            if bl_word in chat_bl:
                db.rm_from_blacklist(m.chat.id, bl_word.lower())
                await m.reply_text(
                    tlang(m, "blacklist.rm_blacklist").format(
                        bl_word=f"<code>{bl_word}</code>",
                    ),
                )
                return
            await m.reply_text(
                tlang(m, "blacklist.no_bl_found").format(
                    bl_word=f"<code>{bl_word}</code>",
                ),
            )
        else:
            await m.reply_text(
                tlang(m, "general.check_help"),
                reply_to_message_id=m.message_id,
            )
    return
Exemplo n.º 10
0
async def commands_menu(_, q: CallbackQuery):

    keyboard = InlineKeyboardMarkup(inline_keyboard=[
        *(await gen_cmds_kb(q)),
        [
            InlineKeyboardButton(
                f"« {(tlang(q, 'general.back_btn'))}",
                callback_data="start_back",
            ),
        ],
    ], )
    try:
        await q.message.edit_text(
            (tlang(q, "general.commands_available")),
            reply_markup=keyboard,
        )
    except MessageNotModified:
        pass
    except QueryIdInvalid:
        await q.message.reply_text(
            (tlang(q, "general.commands_available")),
            reply_markup=keyboard,
        )
    await q.answer()
    return
Exemplo n.º 11
0
async def paste_it(_, m: Message):
    replymsg = await m.reply_text((tlang(m, "utils.paste.pasting")),
                                  quote=True)
    try:
        if m.reply_to_message:
            if m.reply_to_message.document:
                dl_loc = await m.reply_to_message.download()
                with open(dl_loc) as f:
                    txt = f.read()
                remove(dl_loc)
            else:
                txt = m.reply_to_message.text
        else:
            txt = m.text.split(None, 1)[1]
        ur = "https://hastebin.com/documents"
        r = await http.post(ur, json={"content": txt})
        url = f"https://hastebin.com/{r.json().get('key')}"
        await replymsg.edit_text(
            (tlang(m, "utils.paste.pasted_nekobin")),
            reply_markup=ikb([[((tlang(m, "utils.paste.nekobin_btn")), url,
                                "url")]]),
        )
        LOGGER.info(f"{m.from_user.id} used paste cmd in {m.chat.id}")
    except Exception as e:
        await replymsg.edit_text(f"Error: {e}")
        return
    return
Exemplo n.º 12
0
async def get_invitelink(c: Alita, m: Message):

    try:
        link = await c.export_chat_invite_link(m.chat.id)
        await m.reply_text(
            tlang(m, "admin.invitelink").format(
                chat_name=f"<b>{m.chat.id}</b>",
                link=link,
            ),
        )
    except ChatAdminRequired:
        await m.reply_text(tlang(m, "admin.not_admin"))
    except ChatAdminInviteRequired:
        await m.reply_text(tlang(m, "admin.noinviteperm"))
    except RightForbidden:
        await m.reply_text(tlang(m, "no_invite_perm"))
    except RPCError as ef:
        await m.reply_text(
            tlang(m, "general.some_error").format(
                SUPPORT_GROUP=f"@{SUPPORT_GROUP}",
                ef=f"<code>{ef}</code>",
            ),
        )
        LOGGER.error(ef)

    return
Exemplo n.º 13
0
async def weebify(_, m: Message):
    if len(m.text.split()) >= 2:
        args = m.text.split(None, 1)[1]
    elif m.reply_to_message and len(m.text.split()) == 1:
        args = m.reply_to_message.text
    else:
        await m.reply_text(
            "Please reply to a message or enter text after command to weebify it.",
        )
        return
    if not args:
        await m.reply_text(tlang(m, "utils.weebify.weebify_what"))
        return

    # Use split to convert to list
    # Not using list itself becuase black changes it to long format...
    normiefont = "a b c d e f g h i j k l m n o p q r s t u v w x y z".split()
    weebyfont = "卂 乃 匚 刀 乇 下 厶 卄 工 丁 长 乚 从 𠘨 口 尸 㔿 尺 丂 丅 凵 リ 山 乂 丫 乙".split()

    string = "  ".join(args).lower()
    for normiecharacter in string:
        if normiecharacter in normiefont:
            weebycharacter = weebyfont[normiefont.index(normiecharacter)]
            string = string.replace(normiecharacter, weebycharacter)

    await m.reply_text(
        (tlang(m, "utils.weebify.weebified_string").format(string=string)), )
    LOGGER.info(f"{m.from_user.id} weebified '{args}' in {m.chat.id}")
    return
Exemplo n.º 14
0
async def reload_admins(_, m: Message):

    ADMINDICT = await get_key("ADMINDICT")  # Load ADMINDICT from string

    try:
        adminlist = []
        async for i in m.chat.iter_members(filter="administrators"):
            if i.user.is_deleted:
                continue
            adminlist.append(
                (
                    i.user.id,
                    f"@{i.user.username}" if i.user.username else i.user.first_name,
                ),
            )
        ADMINDICT[str(m.chat.id)] = adminlist
        await set_key("ADMINDICT", ADMINDICT)
        await m.reply_text(tlang(m, "admin.adminlist.reloaded_admins"))
    except RPCError as ef:
        await m.reply_text(
            tlang(m, "general.some_error").format(
                SUPPORT_GROUP=f"@{SUPPORT_GROUP}",
                ef=f"<code>{ef}</code>",
            ),
        )
        LOGGER.error(ef)
    return
Exemplo n.º 15
0
async def clean_linked(_, m: Message):
    pinsdb = Pins(m.chat.id)

    if len(m.text.split()) == 1:
        status = pinsdb.get_settings()["cleanlinked"]
        await m.reply_text(
            tlang(m, "pin.antichannelpin.current_status").format(
                status=status, ), )
        return

    if len(m.text.split()) == 2:
        if m.command[1] in ("yes", "on", "true"):
            pinsdb.cleanlinked_on()
            LOGGER.info(f"{m.from_user.id} enabled CleanLinked in {m.chat.id}")
            msg = "Turned on CleanLinked! Now all the messages from linked channel will be deleted!"
        elif m.command[1] in ("no", "off", "false"):
            pinsdb.cleanlinked_off()
            LOGGER.info(
                f"{m.from_user.id} disabled CleanLinked in {m.chat.id}")
            msg = "Turned off CleanLinked! Messages from linked channel will not be deleted!"
        else:
            await m.reply_text(tlang(m, "general.check_help"))
            return

    await m.reply_text(msg)
    return
Exemplo n.º 16
0
async def anti_channel_pin(_, m: Message):
    pinsdb = Pins(m.chat.id)

    if len(m.text.split()) == 1:
        status = pinsdb.get_settings()["antichannelpin"]
        await m.reply_text(
            tlang(m, "pin.antichannelpin.current_status").format(
                status=status, ), )
        return

    if len(m.text.split()) == 2:
        if m.command[1] in ("yes", "on", "true"):
            pinsdb.antichannelpin_on()
            LOGGER.info(
                f"{m.from_user.id} enabled antichannelpin in {m.chat.id}")
            msg = tlang(m, "pin.antichannelpin.turned_on")
        elif m.command[1] in ("no", "off", "false"):
            pinsdb.antichannelpin_off()
            LOGGER.info(
                f"{m.from_user.id} disabled antichannelpin in {m.chat.id}")
            msg = tlang(m, "pin.antichannelpin.turned_off")
        else:
            await m.reply_text(tlang(m, "general.check_help"))
            return

    await m.reply_text(msg)
    return
Exemplo n.º 17
0
async def unmute_usr(c: Alita, m: Message):
    from alita import BOT_ID

    if len(m.text.split()) == 1 and not m.reply_to_message:
        await m.reply_text("I can't unmute nothing!")
        return

    user_id, user_first_name, _ = await extract_user(c, m)

    if user_id == BOT_ID:
        await m.reply_text(
            "Huh, why would I unmute myself if you are using me?")
        return

    try:
        await m.chat.restrict_member(user_id, m.chat.permissions)
        LOGGER.info(f"{m.from_user.id} unmuted {user_id} in {m.chat.id}")
        await m.reply_text((tlang(m, "admin.unmute.unmuted_user")).format(
            admin=(await mention_html(m.from_user.first_name, m.from_user.id)),
            unmuted=(await mention_html(user_first_name, user_id)),
        ), )
    except ChatAdminRequired:
        await m.reply_text(tlang(m, "admin.not_admin"))
    except UserNotParticipant:
        await m.reply_text(
            "How can I unmute a user who is not a part of this chat?")
    except RightForbidden:
        await m.reply_text(tlang(m, "admin.unmute.bot_no_right"))
    except RPCError as ef:
        await m.reply_text((tlang(m, "general.some_error")).format(
            SUPPORT_GROUP=SUPPORT_GROUP,
            ef=ef,
        ), )
        LOGGER.error(ef)
    return
Exemplo n.º 18
0
async def reload_admins(_, m: Message):
    global TEMP_ADMIN_CACHE_BLOCK

    if m.chat.type != "supergroup":
        return await m.reply_text(
            "This command is made to be used in groups only!", )

    if ((m.chat.id in set(TEMP_ADMIN_CACHE_BLOCK.keys()))
            and (m.from_user.id not in SUPPORT_STAFF)
            and TEMP_ADMIN_CACHE_BLOCK[m.chat.id] == "manualblock"):
        await m.reply_text("Can only reload admin cache once per 10 mins!")
        return

    try:
        await admin_cache_reload(m, "admincache")
        TEMP_ADMIN_CACHE_BLOCK[m.chat.id] = "manualblock"
        await m.reply_text(tlang(m, "admin.adminlist.reloaded_admins"))
        LOGGER.info(f"Admincache cmd use in {m.chat.id} by {m.from_user.id}")
    except RPCError as ef:
        await m.reply_text((tlang(m, "general.some_error")).format(
            SUPPORT_GROUP=SUPPORT_GROUP,
            ef=ef,
        ), )
        LOGGER.error(ef)
        LOGGER.error(format_exc())
    return
Exemplo n.º 19
0
async def paste_it(_, m: Message):

    replymsg = await m.reply_text((tlang(m, "utils.paste.pasting")), quote=True)

    if m.reply_to_message:
        if m.reply_to_message.document:
            dl_loc = await m.reply_to_message.download()
            with open(dl_loc) as f:
                txt = f.read()
            remove(dl_loc)
        else:
            txt = m.reply_to_message.text
    else:
        txt = m.text.split(None, 1)[1]

    url = (await paste(txt))[0]

    await replymsg.edit_text(
        (tlang(m, "utils.paste.pasted_nekobin")),
        reply_markup=InlineKeyboardMarkup(
            [
                [
                    InlineKeyboardButton(
                        (tlang(m, "utils.paste.nekobin_btn")),
                        url=url,
                    ),
                ],
            ],
        ),
    )
    LOGGER.info(f"{m.from_user.id} used paste cmd in {m.chat.id}")

    return
Exemplo n.º 20
0
async def get_formatting_info(_, q: CallbackQuery):
    cmd = q.data.split(".")[1]
    kb = ikb([[((tlang(q, "general.back_btn")), "back.formatting")]])

    if cmd == "md_formatting":
        await q.message.edit_text(
            tlang(q, "formatting.md_help"),
            reply_markup=kb,
            parse_mode="html",
        )
    elif cmd == "fillings":
        await q.message.edit_text(
            tlang(q, "formatting.filling_help"),
            reply_markup=kb,
            parse_mode="html",
        )
    elif cmd == "random_content":
        await q.message.edit_text(
            tlang(q, "formatting.random_help"),
            reply_markup=kb,
            parse_mode="html",
        )

    await q.answer()
    return
Exemplo n.º 21
0
async def add_blacklist(_, m: Message):
    db = Blacklist(m.chat.id)

    if len(m.text.split()) < 2:
        await m.reply_text(tlang(m, "general.check_help"))
        return

    bl_words = ((m.text.split(None, 1)[1]).lower()).split()
    all_blacklisted = db.get_blacklists()
    already_added_words, rep_text = [], ""

    for bl_word in bl_words:
        if bl_word in all_blacklisted:
            already_added_words.append(bl_word)
            continue
        db.add_blacklist(bl_word)

    if already_added_words:
        rep_text = (
            ", ".join([f"<code>{i}</code>" for i in bl_words])
            + " already added in blacklist, skipped them!"
        )
    LOGGER.info(f"{m.from_user.id} added new blacklists ({bl_words}) in {m.chat.id}")
    await m.reply_text(
        (tlang(m, "blacklist.added_blacklist")).format(
            trigger=", ".join(f"<code>{i}</code>" for i in bl_words),
        )
        + (f"\n{rep_text}" if rep_text else ""),
    )

    await m.stop_propagation()
Exemplo n.º 22
0
async def priv_rules(_, m: Message):

    chat_id = m.chat.id
    if len(m.text.split()) == 2:
        option = (m.text.split())[1]
        if option in ("on", "yes"):
            db.set_privrules(chat_id, True)
            LOGGER.info(f"{m.from_user.id} enabled privaterules in {m.chat.id}")
            msg = tlang(m, "rules.priv_rules.turned_on").format(chat_name=m.chat.title)
        elif option in ("off", "no"):
            db.set_privrules(chat_id, False)
            LOGGER.info(f"{m.from_user.id} disbaled privaterules in {m.chat.id}")
            msg = tlang(m, "rules.priv_rules.turned_off").format(chat_name=m.chat.title)
        else:
            msg = tlang(m, "rules.priv_rules.no_option")
        await m.reply_text(msg)
    elif len(m.text.split()) == 1:
        curr_pref = db.get_privrules(m.chat.id)
        msg = tlang(m, "rules.priv_rules.current_preference").format(
            current_option=curr_pref,
        )
        LOGGER.info(f"{m.from_user.id} fetched privaterules preference in {m.chat.id}")
        await m.reply_text(msg)
    else:
        await m.replt_text(tlang(m, "general.check_help"))

    return
Exemplo n.º 23
0
async def set_bl_action(_, m: Message):
    db = Blacklist(m.chat.id)

    if len(m.text.split()) == 2:
        action = m.text.split(None, 1)[1]
        valid_actions = ("ban", "kick", "mute", "warn", "none")
        if action not in valid_actions:
            await m.reply_text(
                (
                    "Choose a valid blacklist action from "
                    + ", ".join(f"<code>{i}</code>" for i in valid_actions)
                ),
            )

            return
        db.set_action(action)
        LOGGER.info(
            f"{m.from_user.id} set blacklist action to '{action}' in {m.chat.id}",
        )
        await m.reply_text(
            (tlang(m, "blacklist.action_set")).format(action=action),
        )
    elif len(m.text.split()) == 1:
        action = db.get_action()
        LOGGER.info(f"{m.from_user.id} checking blacklist action in {m.chat.id}")
        await m.reply_text(
            (tlang(m, "blacklist.action_get")).format(action=action),
        )
    else:
        await m.reply_text(tlang(m, "general.check_help"))

    return
Exemplo n.º 24
0
async def view_blacklist(_, m: Message):
    db = Blacklist(m.chat.id)

    LOGGER.info(f"{m.from_user.id} checking blacklists in {m.chat.id}")

    chat_title = m.chat.title
    blacklists_chat = (tlang(m, "blacklist.curr_blacklist_initial")).format(
        chat_title=chat_title,
    )
    all_blacklisted = db.get_blacklists()

    if not all_blacklisted:
        await m.reply_text(
            (tlang(m, "blacklist.no_blacklist")).format(
                chat_title=chat_title,
            ),
        )
        return

    blacklists_chat += "\n".join(
        f" • <code>{escape(i)}</code>" for i in all_blacklisted
    )

    await m.reply_text(blacklists_chat)
    return
Exemplo n.º 25
0
async def rm_blacklist(_, m: Message):
    db = Blacklist(m.chat.id)

    if len(m.text.split()) < 2:
        await m.reply_text(tlang(m, "general.check_help"))
        return

    chat_bl = db.get_blacklists()
    non_found_words, rep_text = [], ""
    bl_words = ((m.text.split(None, 1)[1]).lower()).split()

    for bl_word in bl_words:
        if bl_word not in chat_bl:
            non_found_words.append(bl_word)
            continue
        db.remove_blacklist(bl_word)

    if non_found_words == bl_words:
        return await m.reply_text("Blacklists not found!")

    if non_found_words:
        rep_text = (
            "Could not find " + ", ".join(f"<code>{i}</code>" for i in non_found_words)
        ) + " in blcklisted words, skipped them."

    LOGGER.info(f"{m.from_user.id} removed blacklists ({bl_words}) in {m.chat.id}")
    await m.reply_text(
        (tlang(m, "blacklist.rm_blacklist")).format(
            bl_words=", ".join(f"<code>{i}</code>" for i in bl_words),
        )
        + (f"\n{rep_text}" if rep_text else ""),
    )

    await m.stop_propagation()
Exemplo n.º 26
0
async def pin_message(c: Alita, m: Message):

    pin_args = m.text.split(None, 1)
    if m.reply_to_message:
        try:
            disable_notification = True

            if len(pin_args) >= 2 and pin_args[1] in [
                    "alert", "notify", "loud"
            ]:
                disable_notification = False

            await c.pin_chat_message(
                m.chat.id,
                m.reply_to_message.message_id,
                disable_notification=disable_notification,
            )
            await m.reply_text(tlang(m, "pin.pinned_msg"))

        except ChatAdminRequired:
            await m.reply_text(tlang(m, "admin.not_admin"))
        except RightForbidden:
            await m.reply_text(tlang(m, "pin.no_rights_pin"))
        except RPCError as ef:
            await m.reply_text(
                tlang(m, "general.some_error").format(
                    SUPPORT_GROUP=f"@{SUPPORT_GROUP}",
                    ef=f"<code>{ef}</code>",
                ), )
            LOGGER.error(ef)
    else:
        await m.reply_text(tlang(m, "admin.nopinmsg"))

    return
Exemplo n.º 27
0
async def spurge(c: Alita, m: Message):
    if m.chat.type != "supergroup":
        await m.reply_text(tlang(m, "purge.err_basic"))
        return

    if m.reply_to_message:
        message_ids = list(range(m.reply_to_message.message_id, m.message_id))

        def divide_chunks(l: list, n: int = 100):
            for i in range(0, len(l), n):
                yield l[i:i + n]

        # Dielete messages in chunks of 100 messages
        m_list = list(divide_chunks(message_ids))

        try:
            for plist in m_list:
                await c.delete_messages(
                    chat_id=m.chat.id,
                    message_ids=plist,
                    revoke=True,
                )
            await m.delete()
        except MessageDeleteForbidden:
            await m.reply_text(tlang(m, "purge.old_msg_err"))
            return
        except RPCError as ef:
            await m.reply_text((tlang(m, "general.some_error")).format(
                SUPPORT_GROUP=SUPPORT_GROUP,
                ef=ef,
            ), )
        return
    await m.reply_text("Reply to a message to start spurge !")
    return
Exemplo n.º 28
0
async def gban_list(_, m: Message):
    banned_users = db.load_from_db()

    if not banned_users:
        await m.reply_text(tlang(m, "antispam.none_gbanned"))
        return

    banfile = tlang(m, "antispam.here_gbanned_start")
    for user in banned_users:
        banfile += f"[x] <b>{Users.get_user_info(user['_id'])['name']}</b> - <code>{user['_id']}</code>\n"
        if user["reason"]:
            banfile += f"<b>Reason:</b> {user['reason']}\n"

    try:
        await m.reply_text(banfile)
    except MessageTooLong:
        with BytesIO(str.encode(await remove_markdown_and_html(banfile))) as f:
            f.name = "gbanlist.txt"
            await m.reply_document(
                document=f,
                caption=tlang(m, "antispam.here_gbanned_start"),
            )

    LOGGER.info(f"{m.from_user.id} exported gbanlist in {m.chat.id}")

    return
Exemplo n.º 29
0
async def smute_usr(c: Alita, m: Message):
    if len(m.text.split()) == 1 and not m.reply_to_message:
        await m.reply_text("Я не могу никого замьютить!")
        return

    try:
        user_id, _, _ = await extract_user(c, m)
    except Exception:
        return

    if not user_id:
        await m.reply_text("Cannot find user to mute")
        return
    if user_id == Config.BOT_ID:
        await m.reply_text("Huh, why would I mute myself?")
        return

    if user_id in SUPPORT_STAFF:
        LOGGER.info(
            f"{m.from_user.id} trying to mute {user_id} (SUPPORT_STAFF) in {m.chat.id}",
        )
        await m.reply_text(tlang(m, "admin.support_cannot_restrict"))
        return

    try:
        admins_group = {i[0] for i in ADMIN_CACHE[m.chat.id]}
    except KeyError:
        admins_group = await admin_cache_reload(m, "mute")

    if user_id in admins_group:
        await m.reply_text(tlang(m, "admin.mute.admin_cannot_mute"))
        return

    try:
        await m.chat.restrict_member(
            user_id,
            ChatPermissions(),
        )
        LOGGER.info(f"{m.from_user.id} smuted {user_id} in {m.chat.id}")
        await m.delete()
        if m.reply_to_message:
            await m.reply_to_message.delete()
            return
        return
    except ChatAdminRequired:
        await m.reply_text(tlang(m, "admin.not_admin"))
    except RightForbidden:
        await m.reply_text(tlang(m, "admin.mute.bot_no_right"))
    except UserNotParticipant:
        await m.reply_text(
            "How can I mute a user who is not a part of this chat?")
    except RPCError as ef:
        await m.reply_text((tlang(m, "general.some_error")).format(
            SUPPORT_GROUP=SUPPORT_GROUP,
            ef=ef,
        ), )
        LOGGER.error(ef)

    return
Exemplo n.º 30
0
    async def perform_action_blacklist(m: Message, action: str, trigger: str):
        if action == "kick":
            await m.chat.kick_member(m.from_user.id, int(time() + 45))
            await m.reply_text(
                tlang(m, "blacklist.bl_watcher.action_kick").format(
                    user=m.from_user.username
                    or f"<b>{m.from_user.first_name}</b>", ), )

        elif action == "ban":
            (await m.chat.kick_member(m.from_user.id, ))
            await m.reply_text(
                tlang(m, "blacklist.bl_watcher.action_ban").format(
                    user=m.from_user.username
                    or f"<b>{m.from_user.first_name}</b>", ), )

        elif action == "mute":
            await m.chat.restrict_member(
                m.from_user.id,
                ChatPermissions(),
            )

            await m.reply_text(
                tlang(m, "blacklist.bl_watcher.action_mute").format(
                    user=m.from_user.username
                    or f"<b>{m.from_user.first_name}</b>", ), )

        elif action == "warn":
            warns_settings_db = WarnSettings(m.chat.id)
            warns_db = Warns(m.chat.id)
            warn_settings = warns_settings_db.get_warnings_settings()
            warn_reason = bl_db.get_reason()
            _, num = warns_db.warn_user(m.from_user.id, warn_reason)
            if num >= warn_settings["warn_limit"]:
                if warn_settings["warn_mode"] == "kick":
                    await m.chat.ban_member(
                        m.from_user.id,
                        until_date=int(time() + 45),
                    )
                    action = "kicked"
                elif warn_settings["warn_mode"] == "ban":
                    await m.chat.ban_member(m.from_user.id)
                    action = "banned"
                elif warn_settings["warn_mode"] == "mute":
                    await m.chat.restrict_member(m.from_user.id,
                                                 ChatPermissions())
                    action = "muted"
                await m.reply_text((
                    f"Warnings {num}/{warn_settings['warn_limit']}\n"
                    f"{(await mention_html(m.from_user.first_name, m.from_user.id))} has been <b>{action}!</b>"
                ), )
                return
            await m.reply_text(
                (
                    f"{(await mention_html(m.from_user.first_name, m.from_user.id))} warned {num}/{warn_settings['warn_limit']}\n"
                    # f"Last warn was for:\n<i>{warn_reason}</i>"
                    f"Last warn was for:\n<i>{warn_reason.format(trigger)}</i>"
                ), )
        return