def main(): while True: try: bot.polling(none_stop=True) except Exception as e: print(e) time.sleep(3)
def referal_bot_loop(): while True: try: bot.polling(none_stop=True, interval=2) break except Exception as ex: print(ex) bot.stop_polling() time.sleep(15)
def start_bot(): if global_settings.DEBUG == True: bot.polling() else: import time print('STARTED') bot.remove_webhook() time.sleep(1) bot.set_webhook( url=WEBHOOK_URL, certificate=open('nginx-selfsigned.crt', 'r') ) app.run(host='127.0.0.1', port=5000, debug=True)
Мое имя QRcodeBot, и я умею делать QR-code из текста который вы отправите мне :) Отправьте мне любой текст и я в миг сделаю для вас QR-code. ''', parse_mode='Markdown') @bot.message_handler(commands=['help']) def help(message): bot.send_message(message.chat.id, f''' Что бы сделать QR-code напиши мне любое сообщение и я со скоростью света реализую его тебе ''') @bot.message_handler(content_types=['text']) def create_qrcode(message): do = message.text bot.send_message(message.chat.id, 'Начинаю делать QR-code по слову: ' + do) img = qrcode.make(do) img.save('QR-code.png') bot.send_photo(message.chat.id, photo=open('/home/dizinnes/PycharmProjects/QRcodeBot/QR-code.png', 'rb')) @bot.message_handler(content_types=['photo']) def know_qrcode(message): bot.send_message(message.chat.id, 'Вы отрпавили фото!') photo = message.chat.photo bot.send_message(message.chat_id, 'Принял фото сейчас же буду рассшифрововать: ' + photo) bot.polling()
bot.send_message(message.chat.id, config.answer_dev) @bot.message_handler(commands=['home']) def send_home(message): bot.send_message(message.chat.id, config.answer_dev) @bot.message_handler(content_types=['location']) def take_location(message): #print(message.json['date']) latitude = message.location.latitude longitude = message.location.longitude keyboard = types.InlineKeyboardMarkup() callback_button = types.InlineKeyboardButton(text="Детальніше", callback_data='more_forecast') keyboard.add(callback_button) bot.send_message(message.chat.id, get_loc_weather(latitude, longitude, message), reply_markup=keyboard) @bot.callback_query_handler(func=lambda call: True) def callback_inline(call): # Если сообщение из чата с ботом if call.message: if call.data == 'more_forecast': bot.send_message(call.message.chat.id, config.answer_dev) @bot.message_handler(func=lambda message: True) def text_message(message): bot.send_message(message.chat.id, get_city_weather(message.text)) bot.polling(none_stop=False, interval=0, timeout=20)
else: string += '*Sem alarmes ativos*\n' if len(id_equip) < 2: id_equip.append(equip['id']) data.clear() alarm.clear() data.append('dado{}'.format(equip['id'])) alarm.append('alarme{}'.format(equip['id'])) keyboard.row( # Lista dados para o equipamento informado types.InlineKeyboardButton('Dados', callback_data=data[0]), # Lista alarmes para o equipamento informado types.InlineKeyboardButton('Alarmes', callback_data=alarm[0])) # Volta para a lista de equipamentos keyboard.row( types.InlineKeyboardButton('Equipamentos', callback_data='equip')) bot.send_message( query.message.chat.id, "*Equipamento liberado para acesso:*\n\n{}".format(string), reply_markup=keyboard, parse_mode='MARKDOWN') # Upon calling this function, TeleBot starts polling the Telegram servers for new messages. # - none_stop: True/False (default False) - Don't stop polling when receiving an error from the Telegram servers # - interval: True/False (default False) - The interval between polling requests # Note: Editing this parameter harms the bot's response time # - timeout: integer (default 10) - Timeout in seconds for long polling. bot.polling(none_stop=True, interval=0, timeout=10)
# Euro to Ruble exchange rate @bot.message_handler(commands=['euro']) def any_euro(m): rate_euro(m) # Bitcoin to Dollar rate @bot.message_handler(commands=['btcdoll']) def any_btc(m): rate_btc(m) @bot.message_handler(commands=['cats']) def any_cats(m): cats(m) @bot.message_handler(commands=['dogs']) # help message handler def any_dogs(m): dogs(m) @bot.message_handler(content_types=['text']) def any_text(m): send_text(m) # Start Bot if __name__ == "__main__": bot.polling(none_stop=True, interval=0)
if not paqueteNuevo: bot.send_message( call.message.chat.id, f"\U0000274C Se ha presentado un error al eliminar el estado del paquete.", parse_mode="Markdown") else: bot.send_message( call.message.chat.id, text= f"\U00002705 Estado eliminado correctamente. El nuevo estado del paquete es ‘{paqueteNuevo.estado_actual_objeto.nombre}’ en la fecha: {ayudadores.formato_fecha_bonita(paqueteNuevo.fecha_estado_actual)}.", parse_mode="Markdown") ''' Mensaje por efecto ''' @bot.message_handler(func=lambda message: True) def on_fallback(message): bot.send_chat_action(message.chat.id, 'typing') sleep(1) response = logic.get_fallback_message(message.text) bot.reply_to(message, response) ######################################################### if __name__ == '__main__': bot.polling(timeout=20) #########################################################
@bot.message_handler(regexp=r"^(listar cuentas|lc)$") def on_list_accounts(message): bot.send_chat_action(message.chat.id, 'typing') text = "" if logic.check_admin(message.from_user.id): accounts = logic.list_accounts() text = "``` Listado de cuentas:\n\n" for account in accounts: text += f"| {account.id} | ${account.balance} |\n" text += "```" else: text = f"\U0000274C Esta funcionalidad sólo está disponible para administradores" bot.reply_to(message, text, parse_mode="Markdown") @bot.message_handler(func=lambda message: True) def on_fallback(message): bot.send_chat_action(message.chat.id, 'typing') sleep(1) bot.reply_to( message, "\U0001F63F Ups, no entendí lo que me dijiste.") ######################################################### if __name__ == '__main__': bot.polling(timeout=1) #########################################################
content_types=['text']) def tweet_menu(message): if message.text.lower() == TWEETER_MENU_LOWER[0]: bot.send_message( message.chat.id, 'Please send new tweet as text, file, photo, video, audio, IPFS hash, URL, contact, location, ' 'video or voice', reply_markup=TWEETER_KEYBOARD) elif message.text.lower() == TWEETER_MENU_LOWER[1]: state[message.chat.id] = States.S_START bot.send_message(message.chat.id, 'Main Menu', reply_markup=base_keyboard_reply_markup( message.from_user.id)) if __name__ == '__main__': if DEV_MODE: print('DEV_MODE') bot.polling(none_stop=True, timeout=100) else: # Handler to avoid disconnection while True: try: bot.polling(none_stop=True, timeout=100) except Exception as e: print(e) # restart in 15 sec time.sleep(15)
#!/usr/bin/env python3 # -*- coding: UTF-8 -*- import telebot from config import bot import message_handlers if __name__ == "__main__": bot.remove_webhook() bot.polling(none_stop=True)