python类InlineKeyboardButton()的实例源码

info.py 文件源码 项目:VocaBot 作者: bomjacob 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def song_keyboard(data, inline=False):
    if not data:
        return
    keyboard = [[]]
    keyboard[-1].append(InlineKeyboardButton(text=Emoji.SCROLL + _('Lyrics'),
                                             callback_data='ly|{}'.format(data['id'])))

    # TODO: Add "Artist Info" button to inline

    # If it's from an entry search we get pVs instead of pvServices
    if 'pVs' in data:
        data['pvServices'] = ', '.join([x['service'] for x in data['pVs']])

    if not data['pvServices'] == 'Nothing':
        keyboard.append([])
        for service in PV_SERVICES:
            if service in data['pvServices']:
                callback_data = 'pv|{}|{}'.format(data['id'], service)
                keyboard[-1].append(InlineKeyboardButton(text=Emoji.MOVIE_CAMERA + service,
                                                         callback_data=callback_data))

    keyboard.append([
        InlineKeyboardButton(text=_('Share song'), switch_inline_query='!s#{}'.format(data['id'])),
        InlineKeyboardButton(text=_('View on VocaDB.net'), url=vocadb_url(data, song=True))
    ])

    return InlineKeyboardMarkup(keyboard)


# noinspection PyTypeChecker
info.py 文件源码 项目:VocaBot 作者: bomjacob 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def artist_keyboard(data, inline=False):
    if not data:
        return
    keyboard = []
    if not inline:
        keyboard.append([
            InlineKeyboardButton(text=Emoji.TOP_WITH_UPWARDS_ARROW_ABOVE + _('Popular songs'),
                                 callback_data='arlist|ps|{}'.format(data['id'])),
            InlineKeyboardButton(text=Emoji.CLOCK_FACE_THREE_OCLOCK + _('Latest songs'),
                                 callback_data='arlist|ls|{}'.format(data['id']))
        ])
        keyboard.append([
            InlineKeyboardButton(text=Emoji.TOP_WITH_UPWARDS_ARROW_ABOVE + _('Popular albums'),
                                 callback_data='arlist|pa|{}'.format(data['id'])),
            InlineKeyboardButton(text=Emoji.CLOCK_FACE_THREE_OCLOCK + _('Latest albums'),
                                 callback_data='arlist|la|{}'.format(data['id']))
        ])

    keyboard.append([
        InlineKeyboardButton(text=_('Share artist'), switch_inline_query='!ar#{}'.format(data['id'])),
        InlineKeyboardButton(text=_('View on VocaDB.net'), url=vocadb_url(data, artist=True))
    ])

    return InlineKeyboardMarkup(keyboard)


# noinspection PyTypeChecker
info.py 文件源码 项目:VocaBot 作者: bomjacob 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def album_keyboard(data, inline=False):
    if not data:
        return
    keyboard = [[]]
    keyboard[-1].append(InlineKeyboardButton(text=Emoji.MUSICAL_SCORE + _('Tracks'),
                                             callback_data='allist|{}'.format(data['id'])))

    keyboard.append([
        InlineKeyboardButton(text=_('Share Album'), switch_inline_query='!al#{}'.format(data['id'])),
        InlineKeyboardButton(text=_('View on VocaDB.net'), url=vocadb_url(data, album=True))
    ])

    return InlineKeyboardMarkup(keyboard)
info.py 文件源码 项目:VocaBot 作者: bomjacob 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def lyrics(bot, update, groups, lang):
    data = voca_db.song(groups[0], lang=lang, fields='MainPicture, Names, Lyrics, Artists, PVs')

    reply_keyboard = InlineKeyboardMarkup([
        [InlineKeyboardButton(get_lyric_lang(lyric['translationType'], lyric['cultureCode']),
                              callback_data='ly|{}|{}'.format(data['id'],
                                                              lyric['id'])) for lyric in data['lyrics']]])

    inline = bool(update.callback_query.inline_message_id)

    if data['lyrics']:
        if groups[1] == '':
            text = _('What language would you like the lyrics for <b>{name} by {artist}</b> in?').format(
                name=data['name'],
                artist=data['artistString'])
            edit_message_text(bot, update, send_if_possible=True,
                              text=text,
                              reply_markup=reply_keyboard,
                              parse_mode=ParseMode.HTML)
            update.callback_query.answer()
        else:
            for lyric in data['lyrics']:
                if lyric['id'] == int(groups[1]):
                    text = ''
                    if inline:
                        text = content_parser(data, info=True, inline=True, bot_name=bot.username)
                    text += '\n\n' + Emoji.SCROLL
                    text += _('<b>{lang} lyrics for {song} by {artist}</b>\n'
                              '{lyrics}').format(song=data['name'],
                                                 artist=data['artistString'],
                                                 lang=get_lyric_lang(lyric['translationType'], lyric['cultureCode'],
                                                                     long=True),
                                                 lyrics=lyric['value'])
                    edit_message_text(bot, update,
                                      text=text,
                                      reply_markup=song_keyboard(data, inline=True) if inline else reply_keyboard,
                                      parse_mode=ParseMode.HTML)
                    update.callback_query.answer()
    else:
        update.callback_query.answer(_('No lyrics found.'))
settings.py 文件源码 项目:VocaBot 作者: bomjacob 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def send_changer(bot, update, setting):
    user = get_user(bot, update)
    if setting in user:
        global settings
        keyboard = [InlineKeyboardButton(button_text, callback_data='set|{}|{}'.format(setting, button_id)) for
                    button_id, button_text in settings[setting]['trans'].items()]
        keyboard = InlineKeyboardMarkup([keyboard])
        bot.edit_message_text(chat_id=update.callback_query.message.chat.id,
                              message_id=update.callback_query.message.message_id,
                              text=settings[setting]['msg'],
                              reply_markup=keyboard,
                              parse_mode=ParseMode.HTML)
    else:
        update.callback_query.answer(_('Unknown setting, try again.'))
keyboards.py 文件源码 项目:ImgurPlus 作者: DcSoK 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def defaul_res():
    button0 = InlineKeyboardButton(text="48x48", callback_data="48x48")
    button1 = InlineKeyboardButton(text="72x72", callback_data="72x72")
    button2 = InlineKeyboardButton(text="96x96", callback_data="96x96")
    button3 = InlineKeyboardButton(text="144x144", callback_data="144x144")
    button4 = InlineKeyboardButton(text="Custom resolution", callback_data="custom")
    button5 = InlineKeyboardButton(text="Default resolution", callback_data="default")
    buttons_list = [[button0, button1, button2, button3], [button5]]
    keyboard = InlineKeyboardMarkup(buttons_list)
    return keyboard
keyboards.py 文件源码 项目:ImgurPlus 作者: DcSoK 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def github_link_kb():
    button0 = InlineKeyboardButton(text="Source code", url="https://github.com/DcSoK/ImgurPlus")
    buttons_list = [[button0]]
    keyboard = InlineKeyboardMarkup(buttons_list)
    return keyboard
emotbot.py 文件源码 项目:Automate-it 作者: PacktPublishing 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def start(bot, update):
    keyboard = [
                [InlineKeyboardButton("Happy", callback_data='1'),
                 InlineKeyboardButton("Whatever", callback_data='2')],
                [InlineKeyboardButton("Sad", callback_data='3')]]

    reply_markup = InlineKeyboardMarkup(keyboard)

    update.message.reply_text('Hey there! How do you feel today?', reply_markup=reply_markup)
telegbot.py 文件源码 项目:forushandeBot 作者: pouya-barzegar 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def gen_category(categories, buttonfield,
                 callbackfield, callbackheader, url=""):
    cat_names = []
    for item in categories:
        print(item)
        cat_names.append(item[buttonfield])
    logger.info("generated a list from the name of categories; {}"
                .format(cat_names))

    button_list = [InlineKeyboardButton(s, url=url.format(str(categories[cat_names.index(s)][callbackfield])),
                                        callback_data=callbackheader + str(categories[cat_names.index(s)][callbackfield]))
                   for s in cat_names]
    return cat_names, button_list
teamspeak.py 文件源码 项目:teamSpeakTelegram 作者: jossalgon 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def generate_invitation(bot, update):
    message = update.message
    token = utils.generate_invitation()
    link = 'https://telegram.me/%s?start=%s' % (bot.username, token)
    share_link = 'https://telegram.me/share/url?url={0}&text=Click%20the%20link%20to%20join%20the%20teamspeak%20bot'.format(link)
    keyboard = [[InlineKeyboardButton(_('Join'), url=link)],
                [InlineKeyboardButton(_('Share link'), url=share_link)]]
    reply_markup = InlineKeyboardMarkup(keyboard)
    bot.sendMessage(message.chat_id, '?? ' + _('Welcome to TeamSpeak bot') + ' ??\n\n' +
                    _('This is an invitation to use the TeamSpeak bot'),
                    reply_markup=reply_markup)
utils.py 文件源码 项目:teamSpeakTelegram 作者: jossalgon 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def paginate_items(bot, update, chat_data, items, principal_property, backend_property, text, callback, additional_row=None):
    message = update.effective_message
    chat_id = message.chat_id
    markup = []
    first_message = bool(update.message)

    page = chat_data[message.message_id]['pages'] if not first_message else 1

    start = 10 * (page - 1) if page > 1 else 0
    end = start + 10 if start + 10 < len(items) else len(items)
    for i in range(start, end, 2):
        item1 = items[i]
        row = [InlineKeyboardButton(item1[principal_property],
                                    callback_data='%s_DETAIL_%s' % (callback, str(item1[backend_property])))]
        if i + 1 < len(items):
            item2 = items[i + 1]
            row.append(InlineKeyboardButton(item2[principal_property],
                                            callback_data='%s_DETAIL_%s' % (callback, str(item2[backend_property]))))
        markup.append(row)

    markup = markup_append_pagination(bot, update, items, markup, page, callback)

    if additional_row is not None:
        markup.append(additional_row)

    reply_markup = InlineKeyboardMarkup(markup)

    if len(items) == 0:
        text = _('No results')
    if not first_message:
        bot.edit_message_text(text, chat_id=chat_id, message_id=message.message_id, reply_markup=reply_markup,
                              parse_mode='Markdown')
    else:
        msg = bot.send_message(chat_id, text, disable_notification=True, reply_markup=reply_markup,
                               parse_mode='Markdown')
        chat_data[msg.message_id] = dict()
        chat_data[msg.message_id]['pages'] = page
utils.py 文件源码 项目:teamSpeakTelegram 作者: jossalgon 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def send_ts_groups_by_user(bot, update, chat_data, cldbid):
    text = '?? ' + _('*Group list:*') + '\n\n' \
           + _('Here is the TeamSpeak group list of this user, pressing any of them will take you to his detail.')

    back_button_row = [InlineKeyboardButton('?? ' + _('Back'), callback_data='GROUP_BY_USER_%s_BACK' % cldbid)]

    clean_pages(chat_data, update.effective_message.message_id)

    paginate_items(bot, update, chat_data, items=get_ts_groups_by_client_id(cldbid),
                   principal_property='name', backend_property='sgid', text=text, callback='GROUP',
                   additional_row=back_button_row)
inlinekeyboarddemo.py 文件源码 项目:telegram_robot 作者: uts-magic-lab 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def start(bot, update):
    keyboard = [[InlineKeyboardButton("Option 1", callback_data='1'),
                 InlineKeyboardButton("Option 2", callback_data='2')],

                [InlineKeyboardButton("Option 3", callback_data='3')]]

    reply_markup = InlineKeyboardMarkup(keyboard)

    update.message.reply_text('Please choose:', reply_markup=reply_markup)
bot.py 文件源码 项目:JackOfAllGroups-telegram-bot 作者: Kyraminol 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def cmd_settings(bot, update):
    message = update.message
    msg_parse(bot, update)
    text = ""
    keyboard = []
    if message.chat.type == "private":
        text = "Cosa vuoi impostare?"
        keyboard += [[InlineKeyboardButton("Impostazioni globali", callback_data="settings.set.0"),
                      InlineKeyboardButton("Impostazioni per gruppo", callback_data="settings.groups")]]
        keyboard += [[InlineKeyboardButton("Aiuto", callback_data="help.main")]]
        keyboard += [[InlineKeyboardButton("Lascia un suggerimento", callback_data="feedback.leave"),
                      InlineKeyboardButton("Informazioni sviluppatore", callback_data="dev.info")]]
        reply_markup = InlineKeyboardMarkup(keyboard)
        bot.send_message(message.chat.id, markdown_to_html(text), reply_to_message_id=message.message_id, reply_markup=reply_markup, parse_mode=ParseMode.HTML)
animebot.py 文件源码 项目:animebot 作者: EV3REST 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def inline(bot, update): #Inline Handler & Parser
    query = update.inline_query.query
    if query is None:
        query = 'rating:s'
        client = Pybooru('Yandere')
        posts = client.posts_list(tags=query, limit=50)
        lposts = len(posts)
        inlinequery = list()
        reply_markup = InlineKeyboardMarkup([InlineKeyboardButton("More", callback_data='More')])
        for post in posts:
            inlinequery.append(InlineQueryResultPhoto(
                    type='photo',
                    id=uuid4(),
                    photo_url=post['file_url'],
                    photo_width=post['preview_width']*6,
                    photo_height=post['preview_height']*6,
                    #reply_markup=reply_markup,
                    thumb_url=post['preview_url']),)
        bot.answerInlineQuery(update.inline_query.id, results=inlinequery, switch_pm_text="Help", switch_pm_parameter="ihelp")
        inlinequery.clear()
    else:
        client = Pybooru('Yandere')
        posts = client.posts_list(tags=query, limit=50)
        lposts = len(posts)
        inlinequery = list()
        reply_markup = InlineKeyboardMarkup([InlineKeyboardButton("More", callback_data='More')])
        for post in posts:
            inlinequery.append(InlineQueryResultPhoto(
                    type='photo',
                    id=uuid4(),
                    photo_url=post['file_url'],
                    photo_width=post['preview_width']*6,
                    photo_height=post['preview_height']*6,
                    #reply_markup=reply_markup,
                    thumb_url=post['preview_url']),)
        bot.answerInlineQuery(update.inline_query.id, results=inlinequery, switch_pm_text="Help", switch_pm_parameter="ihelp")
        inlinequery.clear()
animebot.py 文件源码 项目:animebot 作者: EV3REST 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def idd(bot, update, tags=None, chat_id=None):
    randomint = randint(1000, 10000000)
    try:
        bot.sendChatAction(chat_id, "upload_document")
        tags = update.message.text.split(' ', 1)[1]
        chat_id = update.message.chat_id
        try:
            client = Pybooru('Yandere')
            posts = client.posts_list(tags="id:"+str(tags), limit=1)
            for post in posts:
                urllib.request.urlretrieve(post['file_url'], "tmp/anime_bot_" + str(randomint) + ".jpg")
                tmp_data = "Uploader: " + post['author']  + "\nID: " + str(post['id'])
                globalarray[chat_id] = dict(data=tmp_data)
            photo = open('tmp/anime_bot_' + str(randomint) + ".jpg", 'rb')
            reply_markup = InlineKeyboardMarkup([[InlineKeyboardButton("More", callback_data='More')]])
            bot.sendDocument(chat_id, photo, reply_markup=reply_markup)
            os.remove('tmp/anime_bot_' + str(randomint) + ".jpg")
        except Exception as e:
            print(e)
    except:
        bot.sendChatAction(chat_id, "upload_document")
        client = Pybooru('Yandere')
        try:
            posts = client.posts_list(tags="id:"+str(tags), limit=1)
            for post in posts:
                urllib.request.urlretrieve(post['file_url'], "tmp/anime_bot_" + str(randomint) + ".jpg")
                tmp_data = "Uploader: " + post['author']  + "\nID: " + str(post['id'])
                globalarray[chat_id] = dict(data=tmp_data)
            photo = open('tmp/anime_bot_' + str(randomint) + ".jpg", 'rb')
            reply_markup = InlineKeyboardMarkup([[InlineKeyboardButton("More", callback_data='More')]])
            bot.sendDocument(chat_id, photo, reply_markup=reply_markup)
            os.remove('tmp/anime_bot_' + str(randomint) + ".jpg")
        except Exception as e:
            print(e)
items.py 文件源码 项目:python-telegram-dialog-bot 作者: Saluev 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def convert(self):
        return InlineKeyboardButton(text=self.text, **self.options)
alarm_bot.py 文件源码 项目:AlarmBot 作者: guysoft 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def new_alarm(self, bot, update):
        keyboard = [[InlineKeyboardButton("Daily"),
                     InlineKeyboardButton("Weekday Only")],
        [InlineKeyboardButton("Close")]]

        reply_markup = ReplyKeyboardMarkup(keyboard, one_time_keyboard=True)

        update.message.reply_text('Select type of alarm, or /cancel to cancel:', reply_markup=reply_markup)
        return self.ALARM_TYPE
alarm_bot.py 文件源码 项目:AlarmBot 作者: guysoft 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def set_timezone(self, bot, update):
        keyboard = []

        for continent in sorted(get_timezones().keys()):
            keyboard.append([InlineKeyboardButton(continent)])

        reply_markup = ReplyKeyboardMarkup(keyboard, one_time_keyboard=True)
        update.message.reply_text('Please select a continent, or /cancel to cancel:', reply_markup=reply_markup)
        return self.TIMEZONE_CONTINENT
alarm_bot.py 文件源码 项目:AlarmBot 作者: guysoft 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def timezone_continent(self, bot, update):
        reply = handle_cancel(update)
        if reply is None:
            keyboard = []
            self.selected_continent = update.message.text
            for continent in sorted(get_timezones()[self.selected_continent]):
                keyboard.append([InlineKeyboardButton(continent)])
            reply_markup = ReplyKeyboardMarkup(keyboard, one_time_keyboard=True)
            update.message.reply_text('Please select a timezone, or /cancel to cancel:', reply_markup=reply_markup)

            return self.TIMEZONE_TIME
        return ConversationHandler.END


问题


面经


文章

微信
公众号

扫码关注公众号