예제 #1
0
async def echo():
    """Shows how to use waiter."""

    msg = "🔹 Now i will send you back all messages in raw format like @ShowJsonBot.\n\n" \
          "Hit /cancel to exit."

    kb = InlineKeyboard()
    kb.callback('Stop!', 'stop')

    SendMessage(context.chat.id, msg, reply_markup=kb.render()).webhook()

    while True:

        # here waiting next request
        # this is python's async generator
        yield next_all()

        if context.message.text == '/cancel':
            SendMessage(context.chat.id, "🔹 Ok! See you later!").webhook()
            return

        # print reminder every five updates
        if not context.update.update_id % 5:
            await SendMessage(
                context.chat.id,
                "🔹 I am in <code>echo</code> mode. Hit /cancel to exit."
            ).send()

        prepared = escape.html(
            json.dumps(context.update.raw, ensure_ascii=False, indent=1))
        SendMessage(context.chat.id,
                    f"<code>{prepared}</code>",
                    reply_to_message_id=context.message.message_id).webhook()
예제 #2
0
async def echo(ctx: Context):
    """Shows how to use waiter."""

    msg = "🔹 Now i will send you back all messages in raw foramat like @ShowJsonBot.\n\n" \
          "Hit /cancel to exit."

    whr = SendMessage(ctx.update.message.chat.chat_id, msg)
    ctx.webhook_request(whr)

    while True:

        # here waiting next request
        # this is python's async generator
        ctx: Context = (yield next_all())

        if ctx.update.message.text == '/cancel':
            whr = SendMessage(ctx.update.message.chat.chat_id,
                              "🔹 Ok! See you later!")
            ctx.webhook_request(whr)
            return

        # print reminder every five updates
        if not ctx.update.update_id % 5:
            await ctx.bot.send_message(
                ctx.update.message.chat.chat_id,
                "🔹 I am in <code>echo</code> mode. Hit /cancel to exit.")

        prepared = escape.html(
            json.dumps(ctx.update.raw, ensure_ascii=False, indent=1))
        whr = SendMessage(ctx.update.message.chat.chat_id,
                          f"<code>{prepared}</code>",
                          reply_to_message_id=ctx.update.message.message_id)
        ctx.webhook_request(whr)
예제 #3
0
async def start_command():
    """This is asynchronous handler. You can use here any async code."""
    kb = ReplyKeyboard()
    kb.text("Русский").row()
    kb.text("Uzbek").row()
    SendMessage(
        context2.message.user.user_id,
        'Добро пожаловать в наш бот, пожалуйста выберите язык использования',
        reply_markup=kb.render()).webhook()
    while True:
        yield next_all()

        if context2.message.text == 'Русский':
            kb = ReplyKeyboard()
            kb.text("Главное меню").row()

            SendMessage(context2.message.user.user_id,
                        'Вы выбрали Русский язык.\nДобро пожаловать в бот!',
                        reply_markup=kb.render()).webhook()
            return
        elif context2.message.text == "O'zbek":
            kb = ReplyKeyboard()
            kb.text("Asosiy menu").row()

            SendMessage(context2.message.user.user_id,
                        'O\'zbek tilini tanladingiz.\nBotga hush kelibsiz!',
                        reply_markup=kb.render()).webhook()
            return
        SendMessage(context2.message.user.user_id,
                    'Wrong input, no such one available.').webhook()
예제 #4
0
def enigma_cmd():
    while True:
        new_id = token_urlsafe(8)
        if new_id not in enigmas:
            break

    estat = Munch()
    enigmas[new_id] = estat

    estat.input = ''
    estat.output = ''
    estat.rotors = 4
    estat.rotors_list = ['Beta', 'I', 'II', 'III']
    estat.rings_list = ['A', 'A', 'A', 'A']
    estat.reflector = 'C-Thin'
    estat.plugboard = []
    estat.display = ['A', 'A', 'A', 'A']

    m = MSG.setup.format(setting=MSG.setup_rotors,
                         display=' '.join(estat.display),
                         reflector=estat.reflector,
                         rotors=' '.join(estat.rotors_list),
                         rings=' '.join(estat.rings_list),
                         plugboard=' '.join(estat.plugboard) if len(
                             estat.plugboard) else MSG.plugboard_empty,
                         idisplay=' '.join(estat.display))

    SendMessage(context2.message.chat.chat_id, m, reply_markup=rotors_kb(new_id)).webhook()
예제 #5
0
def help_command(ctx: Context):
    """Handler can also be simple function.

    But remember - in async environment you shouldn't use here hard synchronous code.

    This handler also demonstrates how to make webhook-request.

    If you use webhook executor this will be send as reply of received a webhook.
    Otherwise bot's router will fallback to send by regular call."""

    whr = SendMessage(ctx.update.message.user.user_id,
                      "🔹 Bot's help.\n"
                      "\n"
                      "/start - Print welcome message.\n"
                      "/help - Show this message."
                      "\n"
                      "\n"
                      "/keyboard - Shows keyboard.\n"
                      "/keyboard_location - Shows keyboard with location button.\n"
                      "/keyboard_contact - Shows keyboard with contact button.\n"
                      "/cancel - Removes current keyboard.\n"
                      "\n"
                      "/simple_inline_keyboard - Shows simple inline keyboard.\n"
                      "/arranged_inline_keyboard - Shows how to arrange inline keyboard.\n"
                      "/arranged_scheme_inline_keyboard - Shows how to arrange inline keyboard by scheme.\n"
                      "\n"
                      "/echo - Waiting next request in same handler.\n"
                      "\n"
                      "/inline - Shows how to use inline mode.\n"
                      "\n"
                      "/enigma - Enigma cypher machine")

    ctx.webhook_request(whr)
예제 #6
0
파일: echo.py 프로젝트: Abdvkh/requestBot
async def stop():
    """Shows how break existing waiter."""

    yield commonwaiters.drop_waiter()

    await EditMessageReplyMarkup(chat_id=context2.chat.chat_id, message_id=context2.message.message_id).send()
    await AnswerCallbackQuery(context2.update.callback_query.query_id).send()
    SendMessage(context2.chat.chat_id, "🔹 Ok! See you later!").webhook()
예제 #7
0
def unknown():
    """\
    This is about how to use priority.

    This handler caches all messages to bot, but since we set priority
    to 2048 handler will be called if no other handlers was do.

    Default priority in Dispatcher is 1024, so for
    set the order of handlers you can use @priority decorator."""

    SendMessage(context2.user.user_id,
                "🔹 I don't known what to do. May be /help?").webhook()
예제 #8
0
def unknown():
    T = data.current_T.get()
    SendMessage(context.user.user_id, T('unknown')).webhook()
예제 #9
0
def cancel_command():
    """Removes current reply keyboard"""

    SendMessage(context.user.id,
                "🔹 What's next?",
                reply_markup=ReplyKeyboardRemove()).webhook()
예제 #10
0
async def start_command():
    SendMessage(context.user.user_id, 'input the filter').send()
    variant = context.callback.message
    await SendMessage(context.user.user_id, variant).send()