コード例 #1
0
ファイル: misc.py プロジェクト: qabshire174/Hitsuki
def paginate_modules(chat_id, page_n: int, module_dict: Dict, prefix, chat=None) -> List:
    if not chat:
        modules = sorted(
            [EqInlineKeyboardButton(tld(chat_id, x.__mod_name__),
                                    callback_data="{}_module({})".format(prefix, x.__mod_name__.lower())) for x
             in module_dict.values()])
    else:
        modules = sorted(
            [EqInlineKeyboardButton(tld(chat_id, x.__mod_name__),
                                    callback_data="{}_module({},{})".format(prefix, chat, x.__mod_name__.lower())) for x
             in module_dict.values()])

    pairs = list(zip(modules[::2], modules[1::2]))

    if len(modules) % 2 == 1:
        pairs.append((modules[-1],))

    max_num_pages = ceil(len(pairs) / 7)
    modulo_page = page_n % max_num_pages

    # can only have a certain amount of buttons side by side
    if len(pairs) > 7:
        pairs = pairs[modulo_page * 7:7 * (modulo_page + 1)] + [
            (EqInlineKeyboardButton("⏪", callback_data="{}_prev({})".format(prefix, modulo_page)),
             EqInlineKeyboardButton("⬅️ Back", callback_data="bot_start"),
             EqInlineKeyboardButton("⏩", callback_data="{}_next({})".format(prefix, modulo_page)))]
    else:
        pairs += [[EqInlineKeyboardButton("⬅️ Back", callback_data="bot_start")]]

    return pairs
コード例 #2
0
ファイル: __main__.py プロジェクト: qabshire174/Hitsuki
def send_start(bot, update):
    # Try to remove old message
    try:
        query = update.callback_query
        query.message.delete()
    except:
        pass

    chat = update.effective_chat  # type: Optional[Chat] and unused variable
    text = (tld(chat.id, "Hey *{}* , I'm *{}*"))

    text += (tld(chat.id, "This Bot Is For Testing."))

    keyboard = [[
        InlineKeyboardButton(text="Master",
                             url="https://t.me/Unknown_Hacker_X")
    ]]
    keyboard = [[
        InlineKeyboardButton(text="Source Code",
                             url="https://github.com/yasirarism/Hitsuki")
    ]]
    keyboard += [[
        InlineKeyboardButton(text="🛠 Control Panel",
                             callback_data="cntrl_panel_M")
    ]]
    keyboard += [[
        InlineKeyboardButton(text="🇺🇸 Language", callback_data="set_lang_"),
        InlineKeyboardButton(text="❔ Help", callback_data="help_back")
    ]]

    update.effective_message.reply_text(
        text,
        reply_markup=InlineKeyboardMarkup(keyboard),
        parse_mode=ParseMode.MARKDOWN,
        disable_web_page_preview=True)
コード例 #3
0
def add_blacklist(bot: Bot, update: Update):
    msg = update.effective_message  # type: Optional[Message]
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    words = msg.text.split(None, 1)

    conn = connected(bot, update, chat, user.id)
    if conn:
        chat_id = conn
        chat_name = dispatcher.bot.getChat(conn).title
    else:
        chat_id = update.effective_chat.id
        if chat.type == "private":
            exit(1)
        else:
            chat_name = chat.title

    if len(words) > 1:
        text = words[1]
        to_blacklist = list(set(trigger.strip() for trigger in text.split("\n") if trigger.strip()))
        for trigger in to_blacklist:
            sql.add_to_blacklist(chat_id, trigger.lower())

        if len(to_blacklist) == 1:
            msg.reply_text(tld(chat.id, "Added <code>{}</code> to the blacklist in <b>{}</b>!").format(
                html.escape(to_blacklist[0]), chat_name),
                           parse_mode=ParseMode.HTML)

        else:
            msg.reply_text(tld(chat.id,
                               "Added <code>{}</code> to the blacklist in <b>{}</b>!").format(len(to_blacklist)),
                           chat_name, parse_mode=ParseMode.HTML)

    else:
        msg.reply_text(tld(chat.id, "Tell me what words you would like to add to the blacklist."))
コード例 #4
0
def antispam(bot: Bot, update: Update, args: List[str]):
    chat = update.effective_chat  # type: Optional[Chat]
    if len(args) > 0:
        if args[0].lower() in ["on", "yes"]:
            sql.enable_antispam(chat.id)
            update.effective_message.reply_text(
                tld(
                    chat.id,
                    "I've enabled antispam security in this group. This will help to protect you "
                    "from spammers, unsavoury characters, and the biggest trolls."
                ))
        elif args[0].lower() in ["off", "no"]:
            sql.disable_antispam(chat.id)
            update.effective_message.reply_text(
                tld(
                    chat.id,
                    "I've disabled antispam security in this group. GBans won't affect your users "
                    "anymore. You'll be less protected from any trolls and spammers "
                    "though!"))
    else:
        update.effective_message.reply_text(
            tld(
                chat.id,
                "Give me some arguments to choose a setting! on/off, yes/no!\n\n"
                "Your current setting is: {}\n"
                "When True, any gbans that happen will also happen in your group. "
                "When False, they won't, leaving you at the possible mercy of "
                "spammers.").format(sql.does_chat_gban(chat.id)))
コード例 #5
0
def blacklist(bot: Bot, update: Update, args: List[str]):
    msg = update.effective_message  # type: Optional[Message]
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]

    conn = connected(bot, update, chat, user.id, need_admin=False)
    if conn:
        chat_id = conn
        chat_name = dispatcher.bot.getChat(conn).title
    else:
        if chat.type == "private":
            exit(1)
        else:
            chat_id = update.effective_chat.id
            chat_name = chat.title

    filter_list = tld(chat.id, "<b>Blacklist filters active in {}:</b>\n").format(chat_name)

    all_blacklisted = sql.get_chat_blacklist(chat_id)

    if len(args) > 0 and args[0].lower() == 'copy':
        for trigger in all_blacklisted:
            filter_list += "<code>{}</code>\n".format(html.escape(trigger))
    else:
        for trigger in all_blacklisted:
            filter_list += " • <code>{}</code>\n".format(html.escape(trigger))

    split_text = split_message(filter_list)
    for text in split_text:
        if filter_list == tld(chat.id, "<b>Blacklist filters active in {}:</b>\n").format(
                chat_name):  # We need to translate
            msg.reply_text(tld(chat.id, "There are no blacklist filters in <b>{}</b>!").format(chat_name),
                           parse_mode=ParseMode.HTML)
            return
        msg.reply_text(text, parse_mode=ParseMode.HTML)
コード例 #6
0
def get_id(bot: Bot, update: Update, args: List[str]):
    user_id = extract_user(update.effective_message, args)
    chat = update.effective_chat  # type: Optional[Chat]
    if user_id:
        if update.effective_message.reply_to_message and update.effective_message.reply_to_message.forward_from:
            user1 = update.effective_message.reply_to_message.from_user
            user2 = update.effective_message.reply_to_message.forward_from
            update.effective_message.reply_text(tld(chat.id,
                                                    "The original sender, {}, has an ID of `{}`.\nThe forwarder, {}, has an ID of `{}`.").format(
                escape_markdown(user2.first_name),
                user2.id,
                escape_markdown(user1.first_name),
                user1.id),
                parse_mode=ParseMode.MARKDOWN)
        else:
            user = bot.get_chat(user_id)
            update.effective_message.reply_text(
                tld(chat.id, "{}'s id is `{}`.").format(escape_markdown(user.first_name), user.id),
                parse_mode=ParseMode.MARKDOWN)
    else:
        chat = update.effective_chat  # type: Optional[Chat]
        if chat.type == "private":
            update.effective_message.reply_text(tld(chat.id, "Your id is `{}`.").format(chat.id),
                                                parse_mode=ParseMode.MARKDOWN)

        else:
            update.effective_message.reply_text(tld(chat.id, "This group's id is `{}`.").format(chat.id),
                                                parse_mode=ParseMode.MARKDOWN)
コード例 #7
0
ファイル: admin.py プロジェクト: MhdRezza/Eva
def invite(bot: Bot, update: Update):
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    conn = connected(bot, update, chat, user.id, need_admin=False)
    if conn:
        chatP = dispatcher.bot.getChat(conn)
    else:
        chatP = update.effective_chat
        if chat.type == "private":
            exit(1)

    if chatP.username:
        update.effective_message.reply_text(chatP.username)
    elif chatP.type == chatP.SUPERGROUP or chatP.type == chatP.CHANNEL:
        bot_member = chatP.get_member(bot.id)
        if bot_member.can_invite_users:
            invitelink = chatP.invite_link
            # print(invitelink)
            if not invitelink:
                invitelink = bot.exportChatInviteLink(chatP.id)

            update.effective_message.reply_text(invitelink)
        else:
            update.effective_message.reply_text(
                tld(
                    chat.id,
                    "I don't have access to the invite link, try changing my permissions!"
                ))
    else:
        update.effective_message.reply_text(
            tld(
                chat.id,
                "Sorry, but I can give invite links only for supergroups and channels!"
            ))
コード例 #8
0
def check_flood(bot: Bot, update: Update) -> str:
    user = update.effective_user  # type: Optional[User]
    chat = update.effective_chat  # type: Optional[Chat]
    msg = update.effective_message  # type: Optional[Message]

    if not user:  # ignore channels
        return ""

    # ignore admins
    if is_user_admin(chat, user.id):
        sql.update_flood(chat.id, None)
        return ""

    should_ban = sql.update_flood(chat.id, user.id)
    if not should_ban:
        return ""

    try:
        bot.restrict_chat_member(chat.id, user.id, can_send_messages=False)
        msg.reply_text(tld(chat.id, "I like to leave the flooding to natural disasters. But you, you were just a "
                       "disappointment. *Muted*!"))

        return "<b>{}:</b>" \
               "\n#MUTED" \
               "\n<b>User:</b> {}" \
               "\nFlooded the group.".format(html.escape(chat.title),
                                             mention_html(user.id, user.first_name))

    except BadRequest:
        msg.reply_text(tld(chat.id, "I can't mute people here, give me permissions first! Until then, I'll disable antiflood."))
        sql.set_flood(chat.id, 0)
        return "<b>{}:</b>" \
               "\n#INFO" \
               "\nDon't have mute permissions, so automatically disabled antiflood.".format(chat.title)
コード例 #9
0
def markdown_help(bot: Bot, update: Update):
    chat = update.effective_chat  # type: Optional[Chat]
    update.effective_message.reply_text(tld(chat.id, "MARKDOWN_HELP-K"), parse_mode=ParseMode.HTML)
    update.effective_message.reply_text(tld(chat.id, "Try forwarding the following message to me, and you'll see!"))
    update.effective_message.reply_text(tld(chat.id, "/save test This is a markdown test. _italics_, *bold*, `code`, "
                                                     "[URL](example.com) [button](buttonurl:github.com) "
                                                     "[button2](buttonurl://google.com:same)"))
コード例 #10
0
ファイル: language.py プロジェクト: DevTeady/Hitsuki-1
def locale(bot, update, args):
    chat = update.effective_chat
    if len(args) > 0:
        locale = args[0].lower()
        if locale in list_locales:
            if locale in ('en|pt'):
                switch_to_locale(chat.id, locale)
                update.message.reply_text(
                    tld(chat.id, 'Switched to {} successfully!').format(
                        list_locales[locale]))
            else:
                update.message.reply_text(
                    tld(
                        chat.id, "{} is not supported yet!".format(
                            list_locales[locale])))
        else:
            update.message.reply_text(
                tld(
                    chat.id,
                    "Is that even a valid language code? Use an internationally accepted ISO code!"
                ))
    else:
        LANGUAGE = prev_locale(chat.id)
        if LANGUAGE:
            locale = LANGUAGE.locale_name
            native_lang = list_locales[locale]
            update.message.reply_text(tld(
                chat.id,
                "Current locale for this chat is: *{}*".format(native_lang)),
                                      parse_mode=ParseMode.MARKDOWN)
        else:
            update.message.reply_text(
                "Current locale for this chat is: *English*",
                parse_mode=ParseMode.MARKDOWN)
コード例 #11
0
ファイル: admin.py プロジェクト: MhdRezza/Eva
def adminlist(bot, update):
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    conn = connected(bot, update, chat, user.id, need_admin=False)
    if conn:
        chatP = dispatcher.bot.getChat(conn)
    else:
        chatP = update.effective_chat
        if chat.type == "private":
            exit(1)

    administrators = chatP.get_administrators()

    text = tld(chat.id, "Admins in") + " *{}*:".format(
        chatP.title or tld(chat.id, "this chat"))
    for admin in administrators:
        user = admin.user
        status = admin.status
        if status == "creator":
            name = user.first_name + (user.last_name or "") + tld(
                chat.id, " (Creator)")
        else:
            name = user.first_name + (user.last_name or "")
        text += f"\n• `{name}`"

    update.effective_message.reply_text(text, parse_mode=ParseMode.MARKDOWN)
コード例 #12
0
def build_lock_message(chat, chatP, user, chatname):
    locks = sql.get_locks(chat.id)
    restr = sql.get_restr(chat.id)
    if not (locks or restr):
        res = tld(chatP.id, "There are no current locks in *{}*.".format(chatname))
    else:
        res = tld(chatP.id, "These are the locks in *{}*:".format(chatname))
        if locks:
            res += "\n - sticker = `{}`" \
                   "\n - audio = `{}`" \
                   "\n - voice = `{}`" \
                   "\n - document = `{}`" \
                   "\n - video = `{}`" \
                   "\n - videonote = `{}`" \
                   "\n - contact = `{}`" \
                   "\n - photo = `{}`" \
                   "\n - gif = `{}`" \
                   "\n - url = `{}`" \
                   "\n - bots = `{}`" \
                   "\n - forward = `{}`" \
                   "\n - game = `{}`" \
                   "\n - location = `{}`".format(locks.sticker, locks.audio, locks.voice, locks.document,
                                                 locks.video, locks.videonote, locks.contact, locks.photo, locks.gif,
                                                 locks.url,
                                                 locks.bots, locks.forward, locks.game, locks.location)
        if restr:
            res += "\n - messages = `{}`" \
                   "\n - media = `{}`" \
                   "\n - other = `{}`" \
                   "\n - previews = `{}`" \
                   "\n - all = `{}`".format(restr.messages, restr.media, restr.other, restr.preview,
                                            all([restr.messages, restr.media, restr.other, restr.preview]))
    return res
コード例 #13
0
def del_lockables(bot: Bot, update: Update):
    chat = update.effective_chat  # type: Optional[Chat]
    message = update.effective_message  # type: Optional[Message]

    for lockable, filter in LOCK_TYPES.items():
        if filter(message) and sql.is_locked(chat.id, lockable) and can_delete(chat, bot.id):
            if lockable == "bots":
                new_members = update.effective_message.new_chat_members
                for new_mem in new_members:
                    if new_mem.is_bot:
                        if not is_bot_admin(chat, bot.id):
                            message.reply_text(tld(chat.id,
                                                   "I see a bot, and I've been told to stop them joining... but I'm not admin!"))
                            return

                        chat.kick_member(new_mem.id)
                        message.reply_text(
                            tld(chat.id, "Only admins are allowed to add bots to this chat! Get outta here."))
            else:
                try:
                    message.delete()
                except BadRequest as excp:
                    if excp.message == "Message to delete not found":
                        pass
                    else:
                        LOGGER.exception("ERROR in lockables")

            break
コード例 #14
0
ファイル: admin.py プロジェクト: MhdRezza/Eva
def promote(bot: Bot, update: Update, args: List[str]) -> str:
    message = update.effective_message  # type: Optional[Message]
    user = update.effective_user  # type: Optional[User]
    chat = update.effective_chat  # type: Optional[Chat]
    conn = connected(bot, update, chat, user.id)
    if conn:
        chatD = dispatcher.bot.getChat(conn)
    else:
        chatD = update.effective_chat
        if chat.type == "private":
            exit(1)

    if not chatD.get_member(bot.id).can_promote_members:
        update.effective_message.reply_text(
            "I can't promote/demote people here! "
            "Make sure I'm admin and can appoint new admins.")

    user_id = extract_user(message, args)
    if not user_id:
        message.reply_text(
            tld(chat.id, "You don't seem to be referring to a user."))
        return ""

    user_member = chatD.get_member(user_id)
    if user_member.status == 'administrator' or user_member.status == 'creator':
        message.reply_text(
            tld(chat.id,
                "How am I meant to promote someone who's already an admin?"))
        return ""

    if user_id == bot.id:
        message.reply_text(
            tld(chat.id,
                "I can't promote myself! Get an admin to do it for me."))
        return ""

    # set same perms as bot - bot can't assign higher perms than itself!
    bot_member = chatD.get_member(bot.id)

    bot.promoteChatMember(
        chatD.id,
        user_id,
        can_change_info=bot_member.can_change_info,
        can_post_messages=bot_member.can_post_messages,
        can_edit_messages=bot_member.can_edit_messages,
        can_delete_messages=bot_member.can_delete_messages,
        # can_invite_users=bot_member.can_invite_users,
        can_restrict_members=bot_member.can_restrict_members,
        can_pin_messages=bot_member.can_pin_messages,
        can_promote_members=bot_member.can_promote_members)

    message.reply_text(tld(chat.id,
                           f"Successfully promoted in *{chatD.title}*!"),
                       parse_mode=ParseMode.MARKDOWN)
    return f"<b>{html.escape(chatD.title)}:</b>" \
           "\n#PROMOTED" \
           f"\n<b>• Admin:</b> {mention_html(user.id, user.first_name)}" \
           f"\n<b>• User:</b> {mention_html(user_member.user.id, user_member.user.first_name)}"
コード例 #15
0
ファイル: github.py プロジェクト: MhdRezza/Eva
def delRepo(bot: Bot, update: Update, args: List[str]):
    chat_id = update.effective_chat.id
    msg = update.effective_message
    if (len(args) != 1):
        msg.reply_text(tld(chat_id, "Invalid repo name!"))
        return
    sql.rm_repo(str(chat_id), args[0])
    msg.reply_text(tld(chat_id, "Repo shortcut deleted successfully!"))
    return
コード例 #16
0
def decide(bot: Bot, update: Update):
    chat = update.effective_chat
    r = randint(1, 100)
    if r <= 65:
        update.message.reply_text(tld(chat.id, "Yes."))
    elif r <= 90:
        update.message.reply_text(tld(chat.id, "No."))
    else:
        update.message.reply_text(tld(chat.id, "Maybe."))
コード例 #17
0
def flood(bot: Bot, update: Update):
    chat = update.effective_chat  # type: Optional[Chat]

    limit = sql.get_flood_limit(chat.id)
    if limit == 0:
        update.effective_message.reply_text(tld(chat.id, "I'm not currently enforcing flood control!"))
    else:
        update.effective_message.reply_text(tld(chat.id,
            "I'm currently muting users if they send more than {} consecutive messages.").format(limit))
コード例 #18
0
ファイル: github.py プロジェクト: MhdRezza/Eva
def saveRepo(bot: Bot, update: Update, args: List[str]):
    chat_id = update.effective_chat.id
    msg = update.effective_message
    if (len(args) != 2):
        msg.reply_text(
            tld(chat_id, "Invalid data, use <reponame> <user>/<repo>"))
        return
    sql.add_repo_to_db(str(chat_id), args[0], args[1])
    msg.reply_text(tld(chat_id, "Repo shortcut saved successfully!"))
    return
コード例 #19
0
def __user_info__(user_id, chat_id):
    if user_id == dispatcher.bot.id:
        return tld(
            chat_id,
            "I've seen them in... Wow. Are they stalking me? They're in all the same places I am... oh. It's me."
        )
    num_chats = sql.get_user_num_chats(user_id)
    return tld(
        chat_id,
        "I've seen them in <code>{}</code> chats in total.").format(num_chats)
コード例 #20
0
def check_afk(bot, update, user_id, fst_name):
    chat = update.effective_chat  # type: Optional[Chat]
    if sql.is_afk(user_id):
        user = sql.check_afk_status(user_id)
        if not user.reason:
            res = tld(chat.id, f"{fst_name} is AFK!")
        else:
            res = tld(
                chat.id,
                f"{fst_name} is AFK! says its because of:\n{user.reason}")
        update.effective_message.reply_text(res)
コード例 #21
0
def media(bot: Bot, update: Update, args: List[str]) -> str:
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    message = update.effective_message  # type: Optional[Message]

    conn = connected(bot, update, chat, user.id)
    if conn:
        chatD = dispatcher.bot.getChat(conn)
    else:
        if chat.type == "private":
            exit(1)
        else:
            chatD = chat

    user_id = extract_user(message, args)
    if not user_id:
        message.reply_text(tld(chat.id,
                               "You'll need to either give me a username to unrestrict, or reply to someone to be unrestricted."))
        return ""

    member = chatD.get_member(int(user_id))

    if member.status != 'kicked' and member.status != 'left':
        if member.can_send_messages and member.can_send_media_messages \
                and member.can_send_other_messages and member.can_add_web_page_previews:
            message.reply_text(
                tld(chat.id, "This user already has the rights to send anything in {}.").format(chatD.title))
        else:
            bot.restrict_chat_member(chatD.id, int(user_id),
                                     can_send_messages=True,
                                     can_send_media_messages=True,
                                     can_send_other_messages=True,
                                     can_add_web_page_previews=True)
            keyboard = []
            reply = tld(chat.id, "Yep, {} can send media again in {}!").format(
                mention_html(member.user.id, member.user.first_name), chatD.title)
            message.reply_text(reply, reply_markup=keyboard, parse_mode=ParseMode.HTML)
            return "<b>{}:</b>" \
                   "\n#UNRESTRICTED" \
                   "\n<b>• Admin:</b> {}" \
                   "\n<b>• User:</b> {}" \
                   "\n<b>• ID:</b> <code>{}</code>".format(html.escape(chatD.title),
                                                           mention_html(user.id, user.first_name),
                                                           mention_html(member.user.id, member.user.first_name),
                                                           user_id)
    else:
        message.reply_text(
            tld(chat.id, "This user isn't even in the chat, unrestricting them won't make them send anything than they "
                         "already do!"))

    return ""
コード例 #22
0
def unlock(bot: Bot, update: Update, args: List[str]) -> str:
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    message = update.effective_message  # type: Optional[Message]
    if is_user_admin(chat, message.from_user.id):
        if len(args) >= 1:
            if args[0] in LOCK_TYPES:
                sql.update_lock(chat.id, args[0], locked=False)
                message.reply_text(tld(chat.id, "Unlocked {} for everyone!").format(args[0]))
                return "<b>{}:</b>" \
                       "\n#UNLOCK" \
                       "\n<b>Admin:</b> {}" \
                       "\nUnlocked <code>{}</code>.".format(html.escape(chat.title),
                                                            mention_html(user.id, user.first_name), args[0])

            elif args[0] in RESTRICTION_TYPES:
                sql.update_restriction(chat.id, args[0], locked=False)
                """
                members = users_sql.get_chat_members(chat.id)
                if args[0] == "messages":
                    unrestr_members(bot, chat.id, members, media=False, other=False, previews=False)

                elif args[0] == "media":
                    unrestr_members(bot, chat.id, members, other=False, previews=False)

                elif args[0] == "other":
                    unrestr_members(bot, chat.id, members, previews=False)

                elif args[0] == "previews":
                    unrestr_members(bot, chat.id, members)

                elif args[0] == "all":
                    unrestr_members(bot, chat.id, members, True, True, True, True)
                """
                message.reply_text(tld(chat.id, "Unlocked {} for everyone!").format(args[0]))

                return "<b>{}:</b>" \
                       "\n#UNLOCK" \
                       "\n<b>Admin:</b> {}" \
                       "\nUnlocked <code>{}</code>.".format(html.escape(chat.title),
                                                            mention_html(user.id, user.first_name), args[0])
            else:
                message.reply_text(
                    tld(chat.id, "What are you trying to unlock...? Try /locktypes for the list of lockables"))

        else:
            bot.sendMessage(chat.id, tld(chat.id, "What are you trying to unlock...?"))

    return ""
コード例 #23
0
def wiki(bot: Bot, update: Update):
	chat = update.effective_chat
	msg = update.effective_message
	chat_id = update.effective_chat.id
	args = update.effective_message.text.split(None, 1)
	teks = args[1]
	message = update.effective_message
	getlang = langsql.get_lang(chat_id)
	if str(getlang) == "en":
		wikipedia.set_lang("en")
	else:
		wikipedia.set_lang("pt")
	try:
		pagewiki = wikipedia.page(teks)
	except wikipedia.exceptions.PageError:
		send_message(update.effective_message, (tld(chat.id, "No results found")))
		return
	except wikipedia.exceptions.DisambiguationError as refer:
		rujuk = str(refer).split("\n")
		if len(rujuk) >= 6:
			batas = 6
		else:
			batas = len(rujuk)
		teks = ""
		for x in range(batas):
			if x == 0:
				if getlang == "en":
					teks += rujuk[x].replace('pode se referir a', 'may refer to')+"\n"
				else:
					teks += rujuk[x]+"\n"
			else:
				teks += "- `"+rujuk[x]+"`\n"
		send_message(update.effective_message, teks, parse_mode="markdown")
		return
	except IndexError:
		send_message(update.effective_message, (tld(chat.id, "Write a message to search from wikipedia sources")))
		return
	judul = pagewiki.title
	summary = pagewiki.summary
	if update.effective_message.chat.type == "private":
		send_message(update.effective_message, (tld(chat.id, "The result of {} are:\n\n<b>{}</b>\n{}").format(teks, judul, summary)), parse_mode=ParseMode.HTML)
	else:
		if len(summary) >= 200:
			judul = pagewiki.title
			summary = summary[:200]+"..."
			button = InlineKeyboardMarkup([[InlineKeyboardButton(text=(tld(chat.id, "Read more...")), url="t.me/{}?start=wiki-{}".format(bot.username, teks.replace(' ', '_')))]])
		else:
			button = None
		send_message(update.effective_message, (tld(chat.id, "The result of {} are:\n\n<b>{}</b>\n{}").format(teks, judul, summary)), parse_mode=ParseMode.HTML, reply_markup=button)
コード例 #24
0
ファイル: log_channel.py プロジェクト: MhdRezza/Eva
    def setlog(bot: Bot, update: Update):
        message = update.effective_message  # type: Optional[Message]
        chat = update.effective_chat  # type: Optional[Chat]
        if chat.type == chat.CHANNEL:
            message.reply_text(
                tld(
                    chat.id,
                    "Now, forward the /setlog to the group you want to tie this channel to!"
                ))

        elif message.forward_from_chat:
            sql.set_chat_log_channel(chat.id, message.forward_from_chat.id)
            try:
                message.delete()
            except BadRequest as excp:
                if excp.message == "Message to delete not found":
                    pass
                else:
                    LOGGER.exception(
                        "Error deleting message in log channel. Should work anyway though."
                    )

            try:
                bot.send_message(
                    message.forward_from_chat.id,
                    tld(
                        chat.id,
                        "This channel has been set as the log channel for {}."
                    ).format(chat.title or chat.first_name))
            except Unauthorized as excp:
                if excp.message == "Forbidden: bot is not a member of the channel chat":
                    bot.send_message(
                        chat.id, tld(chat.id, "Successfully set log channel!"))
                else:
                    LOGGER.exception("ERROR in setting the log channel.")

            bot.send_message(chat.id,
                             tld(chat.id, "Successfully set log channel!"))

        else:
            message.reply_text(
                tld(
                    chat.id, "*The steps to set a log channel are:*\n"
                    " • add bot to the desired channel\n"
                    " • send /setlog to the channel\n"
                    " • forward the /setlog to the group\n"),
                ParseMode.MARKDOWN)
コード例 #25
0
def cmd_get(bot: Bot, update: Update, args: List[str]):
    chat = update.effective_chat  # type: Optional[Chat]
    if len(args) >= 2 and args[1].lower() == "noformat":
        get(bot, update, args[0], show_none=True, no_format=True)
    elif len(args) >= 1:
        get(bot, update, args[0], show_none=True)
    else:
        send_message(update.effective_message, (tld(chat.id, "Get what?")))
コード例 #26
0
ファイル: log_channel.py プロジェクト: MhdRezza/Eva
    def unsetlog(bot: Bot, update: Update):
        message = update.effective_message  # type: Optional[Message]
        chat = update.effective_chat  # type: Optional[Chat]

        log_channel = sql.stop_chat_logging(chat.id)
        if log_channel:
            try:
                bot.send_message(
                    log_channel,
                    tld(chat.id, "Channel has been unlinked from {}").format(
                        chat.title))
                message.reply_text(tld(chat.id,
                                       "Log channel has been un-set."))
            except:
                print("Nut")
        else:
            message.reply_text(tld(chat.id,
                                   "No log channel has been set yet!"))
コード例 #27
0
ファイル: bans.py プロジェクト: MhdRezza/Eva
def ban(bot: Bot, update: Update, args: List[str]) -> str:
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    message = update.effective_message  # type: Optional[Message]

    user_id, reason = extract_user_and_text(message, args)

    if not user_id:
        message.reply_text(tld(chat.id, "You don't seem to be referring to a user."))
        return ""

    try:
        member = chat.get_member(user_id)
    except BadRequest as excp:
        if excp.message == "User not found":
            message.reply_text(tld(chat.id, "I can't seem to find this user"))
            return ""
        else:
            raise

    if user_id == bot.id:
        message.reply_text(tld(chat.id, "I'm not gonna BAN myself, are you crazy?"))
        return ""

    if is_user_ban_protected(chat, user_id, member):
        message.reply_text(tld(chat.id, "Why would I ban an admin? That sounds like a pretty dumb idea."))
        return ""

    log = "<b>{}:</b>" \
          "\n#BANNED" \
          "\n<b>• Admin:</b> {}" \
          "\n<b>• User:</b> {}" \
          "\n<b>• ID:</b> <code>{}</code>".format(html.escape(chat.title), mention_html(user.id, user.first_name),
                                                  mention_html(member.user.id, member.user.first_name), user_id)

    reply = "{} has been banned!".format(mention_html(member.user.id, member.user.first_name))

    if reason:
        log += "\n<b>Reason:</b> {}".format(reason)

    try:
        chat.kick_member(user_id)
        bot.send_sticker(chat.id, BAN_STICKER)  # banhammer marie sticker
        message.reply_text(tld(chat.id, "Banned!"))
        return log

    except BadRequest as excp:
        if excp.message == "Reply message not found":
            # Do not reply
            bot.send_sticker(chat.id, BAN_STICKER)  # banhammer marie sticker
            message.reply_text(tld(chat.id, "Banned!"), quote=False)
            return log
        else:
            LOGGER.warning(update)
            LOGGER.exception("ERROR banning user %s in chat %s (%s) due to %s", user_id, chat.title, chat.id,
                             excp.message)
            message.reply_text(tld(chat.id, "Well damn, I can't ban that user."))

    return ""
コード例 #28
0
def __user_info__(user_id, chat_id):
    is_gbanned = sql.is_user_gbanned(user_id)
    is_gmuted = sql.is_user_gmuted(user_id)

    if not user_id in SUDO_USERS:

        text = tld(chat_id, "Globally banned: <b>{}</b>")
        if is_gbanned:
            text = text.format(tld(chat_id, "Yes"))
            user = sql.get_gbanned_user(user_id)
            if user.reason:
                text += tld(chat_id,
                            "\nReason: {}").format(html.escape(user.reason))
        else:
            text = text.format(tld(chat_id, "No"))

        return text
    else:
        return ""
コード例 #29
0
def afk(bot: Bot, update: Update):
    chat = update.effective_chat  # type: Optional[Chat]
    args = update.effective_message.text.split(None, 1)
    if len(args) >= 2:
        reason = args[1]
    else:
        reason = ""

    sql.set_afk(update.effective_user.id, reason)
    fname = update.effective_user.first_name
    update.effective_message.reply_text(tld(chat.id, f"{fname} is now AFK!"))
コード例 #30
0
ファイル: __main__.py プロジェクト: DevTeady/Hitsuki-1
def send_start(bot, update):
    # Try to remove old message
    try:
        query = update.callback_query
        query.message.delete()
    except:
        pass

    chat = update.effective_chat  # type: Optional[Chat] and unused variable
    text = (tld(
        chat.id,
        "Halo guys! Nama saya *Frozen Bot* - Saya disini untuk membantumu mengatur grup!\nKlik tombol bantuan untuk mengetahui bagaimana cara menggunakan saya.\n\nIkuti [YasirPedia Channel](https://t.me/YasirPediaChannel) jika kamu ingin mendapatkan informasi seputar teknologi!\n\n"
    ))

    text += (tld(
        chat.id,
        "Bot ini di atur oleh [Yasir Aris M](tg://user?id={617426792})\n\nIngin memasukkanku ke grup? [Klik Disini!](t.me/YasirAssistant_bot?startgroup=true)"
    ))

    keyboard = [[
        InlineKeyboardButton(text="📃 Channel Saya",
                             url="https://t.me/YasirPediaChannel")
    ]]
    keyboard = [[
        InlineKeyboardButton(text="Source Code",
                             url="https://github.com/yasirarism/Hitsuki")
    ]]
    keyboard += [[
        InlineKeyboardButton(text="🛠 Control Panel",
                             callback_data="cntrl_panel_M")
    ]]
    keyboard += [[
        InlineKeyboardButton(text="🇺🇸 Bahasa", callback_data="set_lang_"),
        InlineKeyboardButton(text="❔ Bantuan", callback_data="help_back")
    ]]

    update.effective_message.reply_text(
        text,
        reply_markup=InlineKeyboardMarkup(keyboard),
        parse_mode=ParseMode.MARKDOWN,
        disable_web_page_preview=True)