<commit_before>import math
import uuid
from functools import wraps

from telegram import InlineKeyboardButton, InlineKeyboardMarkup, ParseMode, ForceReply
from telegram.ext import ConversationHandler
from telegram.ext.dispatcher import run_async

import info
from constants import BrowseState
from contentparser import content_parser
from settings import with_voca_lang, translate
from util import botan_track
from vocadb import voca_db

ongoing = {}
replies = {}


@run_async
@translate
def next_page(bot, update, groups):
    key, cur_page = groups[1], groups[2]
    cur_page = int(cur_page)
    try:
        page_data, counts, context = ongoing[key](cur_page)
    except KeyError:
        bot.answer_callback_query(callback_query_id=update.callback_query.id, text='Expired! Please start over.')
        return ConversationHandler.END

    bot.edit_message_text(chat_id=update.callback_query.message.chat.id,
                          message_id=update.callback_query.message.message_id,
                          text=content_parser(page_data, context=context),
                          reply_markup=keyboard(key, counts),
                          parse_mode=ParseMode.HTML)
    bot.answer_callback_query(callback_query_id=update.callback_query.id)

    return BrowseState.page


def send_page_one(bot, update, key, page, state):
    page_data, counts, context = page(1)
    if counts[1] == 1 and len(page_data) == 1:
        entry = page_data[0]
        if 'songType' in entry:
            info.song(bot, update, [entry['id']])
        if 'artistType' in entry:
            info.artist(bot, update, [entry['id']])
        if 'discType' in entry:
            info.album(bot, update, [entry['id']])
        return None

    message_id = (update.message or update.callback_query.message).message_id
    if message_id in replies:
        sent_message = bot.edit_message_text(chat_id=(update.message or update.callback_query.message).chat.id,
                                             message_id=replies[message_id][1],
                                             text=content_parser(page_data, context=context),
                                             reply_markup=keyboard(key, counts),
                                             parse_mode=ParseMode.HTML)

    else:
        sent_message = bot.send_message(chat_id=(update.message or update.callback_query.message).chat.id,
                                        text=content_parser(page_data, context=context),
                                        reply_markup=keyboard(key, counts),
                                        parse_mode=ParseMode.HTML)

    replies[message_id] = (state, sent_message.message_id)

    if update.callback_query:
        bot.answer_callback_query(callback_query_id=update.callback_query.id)

    return BrowseState.page


def keyboard(key, counts):
    cur_page = counts[0] // 3 + 1
    last_page = math.ceil((counts[1]) / 3)

    data = 'page|{}|{}'.format(key, '{}')
    buttons = [InlineKeyboardButton('<< 1',
                                    callback_data=data.format(1) if cur_page > 1 else 'page'),
               InlineKeyboardButton('< {}'.format(cur_page - 1) if cur_page > 1 else ' ',
                                    callback_data=data.format((cur_page - 1)) if cur_page > 1 else 'page'),
               InlineKeyboardButton('•{}•'.format(cur_page),
                                    callback_data='page'),
               InlineKeyboardButton('{} >'.format(cur_page + 1) if cur_page < last_page else ' ',
                                    callback_data=data.format(cur_page + 1) if cur_page < last_page else 'page'),
               InlineKeyboardButton('{} >>'.format(last_page),
                                    callback_data=data.format(last_page) if cur_page < last_page else 'page')]
    return InlineKeyboardMarkup([buttons])


def page_wrapper(f):
    @wraps(f)
    # @run_async  # This is a bad idea xD
    def wrapper(bot, update, *args, **kwargs):
        key = str(<KEY>())

        if update.edited_message:
            update.message = update.edited_message

        page, state = f(bot, update, *args, **kwargs)
        # We might have just gotten a BrowseState instead of page.
        if page is None:
            return state

        state = send_page_one(bot, update, key, page, state)
        ongoing[key] = page
        return state

    return wrapper
<commit_msg>Change buttons to be more verbose<commit_after>import math
import uuid
from functools import wraps

from telegram import InlineKeyboardButton, InlineKeyboardMarkup, ParseMode, ForceReply
from telegram.ext import ConversationHandler
from telegram.ext.dispatcher import run_async

import info
from constants import BrowseState
from contentparser import content_parser
from settings import with_voca_lang, translate
from util import botan_track
from vocadb import voca_db

ongoing = {}
replies = {}


@run_async
@translate
def next_page(bot, update, groups):
    key, cur_page = groups[1], groups[2]
    cur_page = int(cur_page)
    try:
        page_data, counts, context = ongoing[key](cur_page)
    except KeyError:
        bot.answer_callback_query(callback_query_id=update.callback_query.id, text='Expired! Please start over.')
        return ConversationHandler.END

    bot.edit_message_text(chat_id=update.callback_query.message.chat.id,
                          message_id=update.callback_query.message.message_id,
                          text=content_parser(page_data, context=context),
                          reply_markup=keyboard(key, counts),
                          parse_mode=ParseMode.HTML)
    bot.answer_callback_query(callback_query_id=update.callback_query.id)

    return BrowseState.page


def send_page_one(bot, update, key, page, state):
    page_data, counts, context = page(1)
    if counts[1] == 1 and len(page_data) == 1:
        entry = page_data[0]
        if 'songType' in entry:
            info.song(bot, update, [entry['id']])
        if 'artistType' in entry:
            info.artist(bot, update, [entry['id']])
        if 'discType' in entry:
            info.album(bot, update, [entry['id']])
        return None

    message_id = (update.message or update.callback_query.message).message_id
    if message_id in replies:
        sent_message = bot.edit_message_text(chat_id=(update.message or update.callback_query.message).chat.id,
                                             message_id=replies[message_id][1],
                                             text=content_parser(page_data, context=context),
                                             reply_markup=keyboard(key, counts),
                                             parse_mode=ParseMode.HTML)

    else:
        sent_message = bot.send_message(chat_id=(update.message or update.callback_query.message).chat.id,
                                        text=content_parser(page_data, context=context),
                                        reply_markup=keyboard(key, counts),
                                        parse_mode=ParseMode.HTML)

    replies[message_id] = (state, sent_message.message_id)

    if update.callback_query:
        bot.answer_callback_query(callback_query_id=update.callback_query.id)

    return BrowseState.page


def keyboard(key, counts):
    cur_page = counts[0] // 3 + 1
    last_page = math.ceil((counts[1]) / 3)

    data = 'page|{}|{}'.format(key, '{}')
    buttons = [InlineKeyboardButton('First',
                                    callback_data=data.format(1) if cur_page > 1 else 'page'),
               InlineKeyboardButton('Previous'.format(cur_page - 1) if cur_page > 1 else ' ',
                                    callback_data=data.format((cur_page - 1)) if cur_page > 1 else 'page'),
               InlineKeyboardButton('•{}•'.format(cur_page),
                                    callback_data='page'),
               InlineKeyboardButton('Next'.format(cur_page + 1) if cur_page < last_page else ' ',
                                    callback_data=data.format(cur_page + 1) if cur_page < last_page else 'page'),
               InlineKeyboardButton('Last'.format(last_page),
                                    callback_data=data.format(last_page) if cur_page < last_page else 'page')]
    return InlineKeyboardMarkup([buttons])


def page_wrapper(f):
    @wraps(f)
    # @run_async  # This is a bad idea xD
    def wrapper(bot, update, *args, **kwargs):
        key = str(<KEY>

        if update.edited_message:
            update.message = update.edited_message

        page, state = f(bot, update, *args, **kwargs)
        # We might have just gotten a BrowseState instead of page.
        if page is None:
            return state

        state = send_page_one(bot, update, key, page, state)
        ongoing[key] = page
        return state

    return wrapper

{'fraction_non_alphanumeric': 0.09652597035192939, 'fraction_numerical': 0.004865904718795971, 'mean_word_length': 2.2349926793557833, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 32, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '302067', 'n_tokens_mistral': 2516, 'n_tokens_neox': 2451, 'n_words': 555}