From 4cb8f14a20c77ce2662ab343b27f4118181293fa Mon Sep 17 00:00:00 2001 From: thakryptex Date: Tue, 26 Apr 2016 18:40:36 +0300 Subject: [PATCH] bot20 example - password or pin generator bot --- examples/bot20-pass_generator-example.py | 39 ++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 examples/bot20-pass_generator-example.py diff --git a/examples/bot20-pass_generator-example.py b/examples/bot20-pass_generator-example.py new file mode 100644 index 0000000..47ea0e5 --- /dev/null +++ b/examples/bot20-pass_generator-example.py @@ -0,0 +1,39 @@ +# -*- coding: utf-8 -*- + +import telebot # https://github.com/eternnoir/pyTelegramBotAPI +from telebot import types +import random +import string + +bot = telebot.TeleBot('your_token') + +markup = types.InlineKeyboardMarkup() +item_text = types.InlineKeyboardButton('Generate password', callback_data="password") +item_num = types.InlineKeyboardButton('Generate PIN', callback_data="pin") +markup.row(item_text, item_num) + + +@bot.message_handler(commands=['start']) +def start(message): + bot.send_message(message.chat.id, "*Hi there!*\nPress one of the buttons to generate a *password* or a *PIN*.", + reply_markup=markup, parse_mode='Markdown') + + +@bot.callback_query_handler(func=lambda call: call.data == 'password') +def btn_pass(call): + symbols = string.ascii_letters + string.digits + text = ''.join(random.choice(symbols) for _ in range(8)) + bot.edit_message_text(text, call.from_user.id, call.message.message_id, reply_markup=markup) + bot.answer_callback_query(call.id, text="Password is generated") + + +@bot.callback_query_handler(func=lambda call: call.data == 'pin') +def btn_pin(call): + symbols = string.digits + text = ''.join(random.choice(symbols) for _ in range(4)) + bot.edit_message_text(text, call.from_user.id, call.message.message_id, reply_markup=markup) + bot.answer_callback_query(call.id, text="PIN is generated") + + +if __name__ == "__main__": + bot.polling(True)