コード例 #1
0
ファイル: language.py プロジェクト: sirsleon/Yeojares
def locale_button(bot, update):
    chat = update.effective_chat
    user = update.effective_user
    query = update.callback_query
    lang_match = re.findall(r"en-US|en-GB|id|ru|es", query.data)
    if lang_match:
        if lang_match[0]:
            switch_to_locale(chat.id, lang_match[0])
            query.answer(text=tld(chat.id, 'language_switch_success_pm').
                         format(list_locales[lang_match[0]]))
        else:
            query.answer(text="Error!", show_alert=True)

    try:
        LANGUAGE = prev_locale(chat.id)
        locale = LANGUAGE.locale_name
        curr_lang = list_locales[locale]
    except Exception:
        curr_lang = "English (US)"

    text = tld(chat.id, "language_select_language")
    text += tld(chat.id, "language_user_language").format(curr_lang)

    conn = connected(bot, update, chat, user.id, need_admin=False)

    if conn:
        try:
            chatlng = prev_locale(conn).locale_name
            chatlng = list_locales[chatlng]
            text += tld(chat.id, "language_chat_language").format(chatlng)
        except Exception:
            chatlng = "English (US)"

    text += tld(chat.id, "language_sel_user_lang")

    bot.edit_message_text(
        chat_id=query.message.chat_id,
        message_id=query.message.message_id,
        text=text,
        parse_mode=ParseMode.MARKDOWN,
        reply_markup=InlineKeyboardMarkup([[
            InlineKeyboardButton("English (US) 🇺🇸",
                                 callback_data="set_lang_en-US"),
            InlineKeyboardButton("English (UK) 🇬🇧",
                                 callback_data="set_lang_en-GB")
        ]] + [[
            InlineKeyboardButton("Indonesian 🇮🇩",
                                 callback_data="set_lang_id"),
            InlineKeyboardButton("Russian 🇷🇺",
                                 callback_data="set_lang_ru")
        ]] + [[
            InlineKeyboardButton("Spanish 🇪🇸",
                                 callback_data="set_lang_es")
        ]] + [[
            InlineKeyboardButton(f"{tld(chat.id, 'btn_go_back')}",
                                 callback_data="bot_start")
        ]]))

    # query.message.delete()
    bot.answer_callback_query(query.id)
コード例 #2
0
ファイル: locks.py プロジェクト: Muttahir6/monicatgbot
def build_lock_message(chat, chatP, user, chatname):
    locks = sql.get_locks(chat.id)
    restr = sql.get_restr(chat.id)
    chat_name = chat.title
    if not (locks or restr):
        res = tld(chatP.id,
                  "There are no current locks in *{}*.".format(chat_name))
    else:
        res = tld(chatP.id, "These are the locks in *{}*:".format(chat_name))
        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
コード例 #3
0
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 not conn == False:
        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:
                print("Test")
                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,
                "I can only give you invite links for supergroups and channels, sorry!"
            ))
コード例 #4
0
def list_handlers(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 not conn == False:
        chat_id = conn
        chat_name = dispatcher.bot.getChat(conn).title
        filter_list = tld(chat.id, "*List of filters in {}:*\n")
    else:
        chat_id = update.effective_chat.id
        if chat.type == "private":
            chat_name = tld(chat.id, "local filters")
            filter_list = tld(chat.id, "*local filters:*\n")
        else:
            chat_name = chat.title
            filter_list = tld(chat.id, "*Filters in {}*:\n")

    all_handlers = sql.get_chat_triggers(chat_id)

    if not all_handlers:
        update.effective_message.reply_text(tld(chat.id, "No filters in {}!").format(chat_name))
        return

    for keyword in all_handlers:
        entry = " • `{}`\n".format(escape_markdown(keyword))
        if len(entry) + len(filter_list) > telegram.MAX_MESSAGE_LENGTH:
            update.effective_message.reply_text(filter_list.format(chat_name), parse_mode=telegram.ParseMode.MARKDOWN)
            filter_list = entry
        else:
            filter_list += entry

    update.effective_message.reply_text(filter_list.format(chat_name), parse_mode=telegram.ParseMode.MARKDOWN)
コード例 #5
0
ファイル: __main__.py プロジェクト: alexmason007/CTRL
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]
    first_name = update.effective_user.first_name 
    text = PM_START_TEXT.format(escape_markdown(first_name), escape_markdown(bot.first_name), OWNER_ID, parse_mode=ParseMode.MARKDOWN)
                
    keyboard = [[
        InlineKeyboardButton(text=tld(chat.id, 'Support Group'),
                             url="https://t.me/ctrlsupport")
        ]]
    keyboard += [[
        InlineKeyboardButton(text=tld(chat.id, '❔ Help'), callback_data="help_back")
    ]]

    update.effective_message.reply_text(
        text,
        reply_markup=InlineKeyboardMarkup(keyboard),
        parse_mode=ParseMode.MARKDOWN,
        disable_web_page_preview=True)
コード例 #6
0
def join_fed(bot: Bot, update: Update, args: List[str]):
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]

    administrators = chat.get_administrators()

    if user.id in SUDO_USERS:
        pass
    else:
        for admin in administrators:
            status = admin.status
            if status == "creator":
                print(admin)
                if str(admin.user.id) == str(user.id):
                    pass
                else:
                    update.effective_message.reply_text(
                        tld(chat.id, "Only group creator can do it!"))
                    return

    if len(args) >= 1:
        sql.chat_join_fed(args[0], chat.id)
        update.effective_message.reply_text(tld(chat.id, "Joined to fed!"))
    else:
        update.effective_message.reply_text(
            tld(chat.id, "Please write federation id to join!"))
コード例 #7
0
ファイル: misc.py プロジェクト: Userbot007/Savita
def get_time(bot: Bot, update: Update, args: List[str]):
    location = " ".join(args)
    if location.lower() == bot.first_name.lower():
        send_message(update.effective_message,
                     "Its always banhammer time for me!")
        bot.send_sticker(update.effective_chat.id, BAN_STICKER)
        return

    res = requests.get(
        'https://dev.virtualearth.net/REST/v1/timezone/?query={}&key={}'.
        format(location, MAPS_API))

    if res.status_code == 200:
        loc = res.json()
        if len(loc['resourceSets'][0]['resources'][0]
               ['timeZoneAtLocation']) == 0:
            send_message(update.effective_message,
                         tl(update.effective_message, "Location not Found!"))
            return
        placename = loc['resourceSets'][0]['resources'][0][
            'timeZoneAtLocation'][0]['placeName']
        localtime = loc['resourceSets'][0]['resources'][0][
            'timeZoneAtLocation'][0]['timeZone'][0]['convertedTime'][
                'localTime']
        time = datetime.strptime(
            localtime, '%Y-%m-%dT%H:%M:%S').strftime("%H:%M:%S %A, %d %B")
        send_message(update.effective_message,
                     tld(update.effective_message,
                         "It now `{}` in `{}`").format(time, placename),
                     parse_mode="markdown")
    else:
        send_message(update.effective_message,
                     tld(update.effective_message,
                         "Use `/time name place`\nEx: `/time Kolkata`"),
                     parse_mode="markdown")
コード例 #8
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)
コード例 #9
0
ファイル: misc.py プロジェクト: codacy-badger/Sakiyabot
def get_id(update, context):
    chat = update.effective_chat
    args = context.args
    user_id = extract_user(update.effective_message, args)
    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='markdown')
        else:
            user = context.bot.get_chat(user_id)
            chat = update.effective_chat
            update.effective_message.reply_text(tld(
                chat.id, "User {}'s id is `{}`.").format(
                    escape_markdown(user.first_name), user.id),
                                                parse_mode='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='markdown')

        else:
            update.effective_message.reply_text(tld(
                chat.id, "This group's id is `{}`.").format(chat.id),
                                                parse_mode='markdown')
コード例 #10
0
    def disable(bot: Bot, update: Update, args: List[str]):
        chat = update.effective_chat  # type: Optional[Chat]
        user = update.effective_user  # type: Optional[User]

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

        if len(args) >= 1:
            disable_cmd = args[0]
            if disable_cmd.startswith(CMD_STARTERS):
                disable_cmd = disable_cmd[1:]

            if disable_cmd in set(DISABLE_CMDS + DISABLE_OTHER):
                sql.disable_command(chatD.id, disable_cmd)
                update.effective_message.reply_text(
                    tld(chat.id, "Disabled the use of `{}` in *{}*").format(
                        disable_cmd, chatD.title),
                    parse_mode=ParseMode.MARKDOWN)
            else:
                update.effective_message.reply_text(
                    tld(chat.id, "That command can't be disabled"))

        else:
            update.effective_message.reply_text(
                tld(chat.id, "What should I disable?"))
コード例 #11
0
def getsticker(bot: Bot, update: Update):
    msg = update.effective_message
    chat_id = update.effective_chat.id
    if msg.reply_to_message:
        if msg.reply_to_message and msg.reply_to_message.sticker:
            file_id = msg.reply_to_message.sticker.file_id
            newFile = bot.get_file(file_id)
            newFile.download('sticker.png')
            bot.sendDocument(chat_id, document=open('sticker.png', 'rb'))
            os.remove("sticker.png")
        elif msg.reply_to_message.photo:
            file_id = msg.reply_to_message.photo[-1].file_id
            newFile = bot.get_file(file_id)
            newFile.download('sticker.png')
            bot.sendDocument(chat_id, document=open('sticker.png', 'rb'))
            os.remove("sticker.png")
        elif msg.reply_to_message.document:
            file_id = msg.reply_to_message.document.file_id
            newFile = bot.get_file(file_id)
            newFile.download('sticker.png')
            bot.sendDocument(chat_id, document=open('sticker.png', 'rb'))
            os.remove("sticker.png")
        else:
            update.effective_message.reply_text(
                tld(
                    chat_id,
                    "Unknown format sticker/photo/document are the supported formats."
                ))
    else:
        update.effective_message.reply_text(
            tld(
                chat_id,
                "Please reply to a sticker/photo/document for me to upload its PNG."
            ))
コード例 #12
0
    def commands(bot: Bot, update: Update):
        chat = update.effective_chat
        user = update.effective_user  # type: Optional[User]

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

        disabled = sql.get_all_disabled(chatD.id)
        if not disabled:
            update.effective_message.reply_text(
                tld(chat.id,
                    "No commands are disabled! in *{}*!").format(chatD.title))

        text = build_curr_disabled(chatD.id, chat.id)

        update.effective_message.reply_text(tld(
            chat.id,
            "The following commands are currently restricted in *{}*:\n{}").
                                            format(chatD.title, text),
                                            parse_mode=ParseMode.MARKDOWN)
コード例 #13
0
    def enable(bot: Bot, update: Update, args: List[str]):
        chat = update.effective_chat  # type: Optional[Chat]
        user = update.effective_user  # type: Optional[User]

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

        if len(args) >= 1:
            enable_cmd = args[0]
            if enable_cmd.startswith(CMD_STARTERS):
                enable_cmd = enable_cmd[1:]

            if sql.enable_command(chatD.id, enable_cmd):
                update.effective_message.reply_text(
                    tld(chat.id, "Enabled the use of `{}` in *{}*").format(
                        enable_cmd, chatD.title),
                    parse_mode=ParseMode.MARKDOWN)
            else:
                update.effective_message.reply_text(
                    tld(chat.id, "Is that even disabled?"))

        else:
            update.effective_message.reply_text(
                tld(chat.id, "What should I enable?"))
コード例 #14
0
ファイル: language.py プロジェクト: the-blank-x/Joker_v2bot
def locale_button(bot, update):
    chat = update.effective_chat
    query = update.callback_query
    lang_match = re.findall(r"en|ru", query.data)
    if lang_match:
        if lang_match[0]:
            switch_to_locale(chat.id, lang_match[0])
            text = tld(chat.id, "*Language changed*")
        else:
            text = "Im sorry, error!"

        query.message.reply_text(text,
                                 parse_mode=ParseMode.MARKDOWN,
                                 reply_markup=InlineKeyboardMarkup([[
                                     InlineKeyboardButton(
                                         text="Back",
                                         callback_data="help_back")
                                 ]]))

    else:
        query.message.reply_text(
            tld(chat.id, "*Select language*"),
            parse_mode=ParseMode.MARKDOWN,
            reply_markup=InlineKeyboardMarkup([[
                InlineKeyboardButton("English 🇺🇸",
                                     callback_data="set_lang_en"),
                InlineKeyboardButton("Russian 🇷🇺",
                                     callback_data="set_lang_ru")
            ]] + [[InlineKeyboardButton("Back", callback_data="help_back")]]))

    print(lang_match)
    query.message.delete()
    bot.answer_callback_query(query.id)
コード例 #15
0
def leave_fed(bot: Bot, update: Update, args: List[str]):
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    fed_id = sql.get_fed_id(chat.id)

    administrators = chat.get_administrators()

    if user.id in SUDO_USERS:
        pass
    else:
        for admin in administrators:
            status = admin.status
            if status == "creator":
                print(admin)
                if str(admin.user.id) == str(user.id):
                    pass
                else:
                    update.effective_message.reply_text(
                        tld(chat.id, "Only group creator can do it!"))
                    return

    if sql.chat_leave_fed(chat.id) == True:
        update.effective_message.reply_text(
            tld(chat.id, "successfully Left from federation!"))
    else:
        update.effective_message.reply_text(tld(chat.id, "Error!"))
コード例 #16
0
def fed_admin(bot: Bot, update: Update, args: List[str]):

        chat = update.effective_chat  # type: Optional[Chat]
        user = update.effective_user  # type: Optional[User]
        fed_id = sql.get_fed_id(chat.id)

        if not fed_id:
            update.effective_message.reply_text(tld(chat.id, "This group is not in any federation!"))
            return

        if is_user_fed_admin(fed_id, user.id) == False:
            update.effective_message.reply_text(tld(chat.id, "Only fed admins can do this!"))
            return

        print(fed_id)
        user = update.effective_user  # type: Optional[Chat]
        chat = update.effective_chat  # type: Optional[Chat]
        info = sql.get_fed_info(fed_id)

        text = "\n\n<b>Federation Admins:</b>"
        user = bot.get_chat(info.owner_id) 
        text += "\n• {} - <code>{}</code> (Creator)".format(mention_html(user.id, user.first_name), user.id)

        h = sql.all_fed_users(fed_id)
        for O in h:
                user = bot.get_chat(O) 
                text += "\n• {} - <code>{}</code>".format(mention_html(user.id, user.first_name), user.id, O)

        update.effective_message.reply_text(text, parse_mode=ParseMode.HTML)
コード例 #17
0
def set_frules(bot: Bot, update: Update, args: List[str]):
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    fed_id = sql.get_fed_id(chat.id)

    if is_user_fed_admin(fed_id, user.id) == False:
        update.effective_message.reply_text(
            tld(chat.id, "Only fed admins can do this!"))
        return

    if len(args) >= 1:
        msg = update.effective_message  # type: Optional[Message]
        raw_text = msg.text
        args = raw_text.split(
            None, 1)  # use python's maxsplit to separate cmd and args
        if len(args) == 2:
            txt = args[1]
            offset = len(txt) - len(
                raw_text)  # set correct offset relative to command
            markdown_rules = markdown_parser(txt,
                                             entities=msg.parse_entities(),
                                             offset=offset)
        sql.set_frules(fed_id, markdown_rules)
        update.effective_message.reply_text(
            tld(chat.id, "Rules setuped for this fed!"))
    else:
        update.effective_message.reply_text(tld(chat.id,
                                                "Please write rules!"))
コード例 #18
0
def set_frules(bot: Bot, update: Update, args: List[str]):
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    fed_id = sql.get_fed_id(chat.id)

    if not fed_id:
        update.effective_message.reply_text(tld(chat.id, "This chat is not in any federation!"))
        return

    if is_user_fed_admin(fed_id, user.id) == False:
        update.effective_message.reply_text(tld(chat.id, "Only fed admins can do this!"))
        return

    if len(args) >= 1:
        msg = update.effective_message  # type: Optional[Message]
        raw_text = msg.text
        args = raw_text.split(None, 1)  # use python's maxsplit to separate cmd and args
        if len(args) == 2:
            txt = args[1]
            offset = len(txt) - len(raw_text)  # set correct offset relative to command
            markdown_rules = markdown_parser(txt, entities=msg.parse_entities(), offset=offset)
        x = sql.set_frules(fed_id, markdown_rules)
        if not x:
            update.effective_message.reply_text(tld(chat.id, "Big F! There is an error while setting federation rules! If you wondered why please ask it in support group!"))
            return

        rules = sql.get_fed_info(fed_id).fed_name
        update.effective_message.reply_text(tld(chat.id, f"Rules are set for {rules}!"))
    else:
        update.effective_message.reply_text(tld(chat.id, "Please write rules to set it up!"))
コード例 #19
0
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]
    first_name = update.effective_user.first_name
    text = PM_START_TEXT.format(escape_markdown(first_name),
                                escape_markdown(bot.first_name),
                                OWNER_ID,
                                parse_mode=ParseMode.MARKDOWN)

    keyboard = [[
        InlineKeyboardButton(text=tld(chat.id, '🥳Add To Group'),
                             url="https://t.me/KING_NGY_BOT?startgroup=true"),
        InlineKeyboardButton(text="❓ Help", callback_data="help_back")
    ]]
    keyboard += [[
        InlineKeyboardButton(text=tld(chat.id, '👥 Support Channel'),
                             url="https://t.me/NGY_BOTS")
    ]]
    keyboard += [[
        InlineKeyboardButton(text=tld(chat.id, '😎 CREATE BY LEGEND'),
                             url="https://t.me/NGYNY")
    ]]

    update.effective_message.reply_text(
        text,
        reply_markup=InlineKeyboardMarkup(keyboard),
        parse_mode=ParseMode.MARKDOWN,
        disable_web_page_preview=True)
コード例 #20
0
def new_fed(bot: Bot, update: Update):
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    message = update.effective_message
    fednam = message.text[len('/newfed '):]
    if not fednam == '':
        fed_id = str(uuid.uuid4())
        fed_name = fednam
        LOGGER.info(fed_id)

        #if fednam == 'Name':
        #     fed_id = "Name"

        x = sql.new_fed(user.id, fed_name, fed_id)
        if not x:
            update.effective_message.reply_text(tld(chat.id, "Big F! There is an error while creating Federations, Kindly get into my support group and ask what is going on!"))
            return

        update.effective_message.reply_text("*You have successfully created a new federation!*"\
                                            "\nName: `{}`"\
                                            "\nID: `{}`"
                                            "\n\nUse command below to join the federation:"
                                            "\n`/joinfed {}`".format(fed_name, fed_id, fed_id), parse_mode=ParseMode.MARKDOWN)
        bot.send_message(
            MESSAGE_DUMP,
           "Federation <b>{}</b> has been created with ID: <pre>{}</pre>".format(fed_name, fed_id),parse_mode=ParseMode.HTML)
    else:
        update.effective_message.reply_text(tld(chat.id, "Please write federation name!"))
コード例 #21
0
def stop_filter(bot: Bot, update: Update):
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    args = update.effective_message.text.split(None, 1)

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

    if len(args) < 2:
        return

    chat_filters = sql.get_chat_triggers(chat_id)

    if not chat_filters:
        update.effective_message.reply_text(tld(chat.id, "No filters are active in {}!").format(chat_name))
        return

    for keyword in chat_filters:
        if keyword == args[1]:
            sql.remove_filter(chat_id, args[1])
            update.effective_message.reply_text(tld(chat.id, "Yep, I'll stop replying to that in *{}*.").format(chat_name), parse_mode=telegram.ParseMode.MARKDOWN)
            raise DispatcherHandlerStop

    update.effective_message.reply_text(tld(chat.id, "That's not a current filter - run /filters for all active filters."))
コード例 #22
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 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 wont 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)))
コード例 #23
0
def start(bot: Bot, update: Update, args: List[str]):
    chat = update.effective_chat  # type: Optional[Chat]
    query = update.callback_query
    if update.effective_chat.type == "private":
        if len(args) >= 1:
            if args[0].lower() == "help":
                send_help(
                    update.effective_chat.id,
                    tld(chat.id, "send-help").
                    format("" if not ALLOW_EXCL else tld(
                        chat.id,
                        "\nAll commands can either be used with `/` or `!`.\n")
                           ))

            elif args[0].lower().startswith("stngs_"):
                match = re.match("stngs_(.*)", args[0].lower())
                chat = dispatcher.bot.getChat(match.group(1))

                if is_user_admin(chat, update.effective_user.id):
                    send_settings(match.group(1),
                                  update.effective_user.id,
                                  user=False)
                else:
                    send_settings(match.group(1),
                                  update.effective_user.id,
                                  user=True)

            elif args[0][1:].isdigit() and "rules" in IMPORTED:
                IMPORTED["rules"].send_rules(update, args[0], from_pm=True)

        else:
            send_start(bot, update)
    else:
        update.effective_message.reply_text(
            "Heya:) PM Me if you have any questions on how to use Me!")
コード例 #24
0
def get_help(bot: Bot, update: Update):
    chat = update.effective_chat  # type: Optional[Chat]
    args = update.effective_message.text.split(None, 1)

    # ONLY send help in PM
    if chat.type != chat.PRIVATE:

        update.effective_message.reply_text("Contact me in PM to get the list of possible commands.",
                                            reply_markup=InlineKeyboardMarkup(
                                                [[InlineKeyboardButton(text="Help",
                                                                       url="t.me/{}?start=help".format(
                                                                           bot.username))]]))
        return

    elif len(args) >= 2 and any(args[1].lower() == x for x in HELPABLE):
        module = args[1].lower()
        mod_name = tld(chat.id, HELPABLE[module].__mod_name__)
        help_txt = tld_help(chat.id, HELPABLE[module].__mod_name__)

        if help_txt == False:
            help_txt = HELPABLE[module].__help__

        text = tld(chat.id, "Here is the help for the *{}* module:\n{}").format(mod_name, help_txt)
        send_help(chat.id, text, InlineKeyboardMarkup([[InlineKeyboardButton(text=tld(chat.id, "Back"), callback_data="help_back")]]))

    else:
        send_help(chat.id, tld(chat.id, "send-help").format(dispatcher.bot.first_name, "" if not ALLOW_EXCL else tld(chat.id, "\nAll commands can either be used with `/` or `!`.\n")))
コード例 #25
0
ファイル: locks.py プロジェクト: Muttahir6/monicatgbot
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
コード例 #26
0
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 not conn == False:
        chatP = dispatcher.bot.getChat(conn)
    else:
        chatP = update.effective_chat
        if chat.type == "private":
            exit(1)

    administrators = chatP.get_administrators()

    print(chat.id, user.id)

    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 = "[{}](tg://user?id={})".format(
                user.first_name +
                (user.last_name or ""), user.id) + tld(chat.id, " (Creator)")
        else:
            name = "[{}](tg://user?id={})".format(
                user.first_name + (user.last_name or ""), user.id)
        text += "\n• {}".format(name)

    update.effective_message.reply_text(text, parse_mode=ParseMode.MARKDOWN)
コード例 #27
0
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 not conn == False:
        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.")
        exit(1)

    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 that'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)}"
コード例 #28
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, "{} is HIDDEN!").format(fst_name)
        else:
            res = tld(chat.id, "{} is HIDDEN! says its because of: \n{}").format(fst_name, user.reason)
        update.effective_message.reply_text(res)
コード例 #29
0
ファイル: afk.py プロジェクト: yemepilla/MissSabrina
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)
コード例 #30
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 banning users if they send more than {} consecutive messages.").format(limit))