import sys import time import amanobot from amanobot.loop import MessageLoop """ $ python3 skeleton.py <token> A skeleton for your amanobot programs. """ def handle(msg): flavor = amanobot.flavor(msg) summary = amanobot.glance(msg, flavor=flavor) print(flavor, summary) TOKEN = sys.argv[1] # get token from command-line bot = amanobot.Bot(TOKEN) MessageLoop(bot, handle).run_as_thread() print('Listening ...') # Keep the program running. while 1: time.sleep(10)
if query_data != 'start': self._score[self._answer == int(query_data)] += 1 self._answer = self._show_next_question() def on__idle(self, event): text = '%d out of %d' % (self._score[True], self._score[True]+self._score[False]) self.editor.editMessageText( text + '\n\nThis message will disappear in 5 seconds to test deleteMessage', reply_markup=None) time.sleep(5) self.editor.deleteMessage() self.close() TOKEN = sys.argv[1] bot = amanobot.DelegatorBot(TOKEN, [ pave_event_space()( per_chat_id(), create_open, QuizStarter, timeout=3), pave_event_space()( per_callback_query_origin(), create_open, Quizzer, timeout=10), ]) MessageLoop(bot).run_as_thread() print('Listening ...') while 1: time.sleep(10)
dict(text='Aguarde...', callback_data='a') ]]) articles.append( InlineQueryResultArticle( id=a['link'], title=f'{a["musica"]} - {a["autor"]}', input_message_content=InputTextMessageContent( message_text='Aguarde...', parse_mode='markdown', disable_web_page_preview=True), reply_markup=teclado)) if not articles: articles = [ InlineQueryResultArticle( id='abcde', title=f'sem resultado', input_message_content=InputTextMessageContent( message_text=f"sem resultado para {msg['query']}")) ] bot.answerInlineQuery(msg['id'], results=articles, is_personal=True) print('LyricsPyRobot...') MessageLoop(bot, handle_thread).run_forever() while True: pass
switch_pm_parameter='Optional_start_parameter') else: return dict(results=results) answerer.answer(msg, compute) def on_chosen_inline_result(msg): result_id, from_id, query_string = amanobot.glance( msg, flavor='chosen_inline_result') print('Chosen Inline Result:', result_id, from_id, query_string) TOKEN = sys.argv[1] # get token from command-line bot = amanobot.Bot(TOKEN) answerer = amanobot.helper.Answerer(bot) MessageLoop( bot, { 'chat': on_chat_message, 'callback_query': on_callback_query, 'inline_query': on_inline_query, 'chosen_inline_result': on_chosen_inline_result }).run_as_thread() print('Listening ...') # Keep the program running. while 1: time.sleep(10)
# -*- coding: utf-8 -*- import amanobot from amanobot.loop import MessageLoop from time import sleep def recebendo(msg): with open('bot_pack/centralMessages.txt', 'r', encoding='utf-8') as file: print(file.readline([1])) # bot.download_file(msg['voice']['file_id'], "D:\usuario\Documents\oice_hall") # bot.download_file(msg['voice']['file_id'], r'C:\hall') # bot.download_file(msg['voice']['file_id'], r'D:\usuario\Documents\oice_hall.mp3') #bot.download_file(msg['voice']['file_id'], r'D:\usuario\Documents\oice_hall.mp3') # Coloca seu token do seu bot aqui em baixo TOKEN = "870167339:AAEXvrPJf8NR9GWoOTWUvw-gdeGPy7kDkDE" bot = amanobot.Bot(TOKEN) MessageLoop(bot, {'chat': recebendo}).run_as_thread() while True: sleep(5)
LabeledPrice(label='International', amount=1234) ]) ]) def on_pre_checkout_query(msg): query_id, from_id, invoice_payload, currency, total_amount = amanobot.glance( msg, flavor='pre_checkout_query', long=True) print('Pre-Checkout query:') print(query_id, from_id, invoice_payload, currency, total_amount) pprint(msg) print(PreCheckoutQuery(**msg)) bot.answerPreCheckoutQuery(query_id, True) TOKEN = sys.argv[1] PAYMENT_PROVIDER_TOKEN = sys.argv[2] bot = amanobot.Bot(TOKEN) MessageLoop( bot, { 'chat': on_chat_message, 'shipping_query': on_shipping_query, 'pre_checkout_query': on_pre_checkout_query }).run_as_thread() while 1: time.sleep(10)
input_message_content=InputTextMessageContent( message_text=f"sem resultado para {msg['query']}"))] bot.answerInlineQuery(msg['id'], results=articles, is_personal=True, cache_time=0) def chosen_inline_result(msg): try: a = lyricspy.letra(msg['result_id']) mik = re.split(r'^(https?://)?(letras\.mus.br/|(m\.|www\.)?letras\.mus\.br)', a["link"])[-1] teclado = InlineKeyboardMarkup( inline_keyboard=[[dict(text='Telegra.ph', callback_data=f'tell-{mik}|{msg["from"]["id"]}')]]) if a.get('traducao'): teclado = InlineKeyboardMarkup(inline_keyboard=[ [dict(text='Telegra.ph', callback_data=f'tell-{mik}|{msg["from"]["id"]}')] + [dict(text='Tradução', callback_data=f'tr_{mik}|{msg["from"]["id"]}')]]) print(teclado) bot.editMessageText(msg['inline_message_id'], '[{} - {}]({})\n{}'.format(a['musica'], a['autor'], a['link'], a['letra']), parse_mode='markdown', disable_web_page_preview=True, reply_markup=teclado) except Exception as e: print(e) bot.editMessageText(msg['inline_message_id'], f'ocorreu um erro ao exibir a letra\nErro:{e}') print('LyricsPyRobot...') MessageLoop(bot, dict(chat=handle_thread, callback_query=callback_thread, inline_query=inline_thread, chosen_inline_result=chosen_thread)).run_forever()
bot.sendMessage(chat_id, 'Por enquanto eu só conheço esses sites!') elif query_data == 'co': bot.sendMessage(chat_id, 'Conteúdo:', reply_markup=botao4()) elif query_data == 'M': bot.sendMessage(chat_id, '***OPÇÕES DO MENU CLIQUE***', reply_markup=botao2()) elif query_data == 'ha': bot.sendMessage(chat_id, 'https://anos-80.mp3cielo.com/') bot.sendMessage(chat_id, CD) elif query_data == 'mu': for i in audio[0:51]: bot.sendAudio(from_id, audio=i) bot.sendMessage(from_id, 'Por enquanto só enviarei esses!') bot.sendMessage(chat_id, f"Enviei no seu privado {name}") elif query_data == 'curs': bot.sendMessage(chat_id, f"Sem cursos no momento!") elif query_data == 'li': bot.sendMessage(chat_id, 'Ainda não tenho livros adicionados aqui!') # TOKEN = "771827013:AAFDYw87Xv9pnSGUPLp6H8BLFnf-iu-ANo8" TOKEN = "870167339:AAEXvrPJf8NR9GWoOTWUvw-gdeGPy7kDkDE" bot = amanobot.Bot(TOKEN) MessageLoop(bot, {'chat': recebendo, 'callback_query': on_callback_query}).run_as_thread() while True: sleep(5)
flavor='inline_query') print('Inline Query:', query_id, from_id, query_string) articles = [ InlineQueryResultArticle(id='abc', title='ABC', input_message_content=InputTextMessageContent( message_text='Hello')) ] bot.answerInlineQuery(query_id, articles) def on_chosen_inline_result(msg): result_id, from_id, query_string = amanobot.glance( msg, flavor='chosen_inline_result') print('Chosen Inline Result:', result_id, from_id, query_string) TOKEN = sys.argv[1] # get token from command-line bot = amanobot.Bot(TOKEN) MessageLoop( bot, { 'inline_query': on_inline_query, 'chosen_inline_result': on_chosen_inline_result }).run_as_thread() while 1: time.sleep(10)
for chat_id in getChats(): try: #print(chat_id[0]) bot.sendChatAction(chat_id[0],'typing') except: print(chat_id[0] + " indisponvel") pass else: EnviaPerguntas(chat_id[0]) print("Mensagem Enviada via Cron") elif (sys.argv[1]) == 'Resposta': for chat_id in getChats(): try: #print(chat_id[0]) bot.sendChatAction(chat_id[0],'typing') except: print(chat_id[0] + " indisponvel") pass else: CarregaRespostas(chat_id[0]) else: MessageLoop(bot, {'chat':handle, 'callback_query':callback}).run_as_thread() # print ('Executando HealthCheck...') while 1: time.sleep(10)
if len(sys.argv) > 1: data = datetime.now(timezone('Brazil/East')).strftime('%Y%m%d') if(sys.argv[1]) == 'Pergunta': for chat_id in getChats(): try: #print(chat_id[0]) bot.sendChatAction(chat_id[0],'typing') except: print(chat_id[0] + " indisponível") pass else: EnviaPergunta(chat_id[0], data) print("Mensagem Enviada via Cron") elif (sys.argv[1]) == 'Resposta': for chat_id in getChats(): try: #print(chat_id[0]) bot.sendChatAction(chat_id[0],'typing') except: print(chat_id[0] + " indisponível") pass else: CarregaResultado(chat_id[0]) else: MessageLoop(bot, {'chat':handle}).run_as_thread() print ('Executando Saude Magrathea...') while 1: time.sleep(10)
import sys import time import amanobot from amanobot.loop import MessageLoop from amanobot.namedtuple import InlineKeyboardMarkup, InlineKeyboardButton def on_chat_message(msg): content_type, chat_type, chat_id = amanobot.glance(msg) keyboard = InlineKeyboardMarkup(inline_keyboard=[ [InlineKeyboardButton(text='Press me', callback_data='press')], ]) bot.sendMessage(chat_id, 'Use inline keyboard', reply_markup=keyboard) def on_callback_query(msg): query_id, from_id, query_data = amanobot.glance(msg, flavor='callback_query') print('Callback Query:', query_id, from_id, query_data) bot.answerCallbackQuery(query_id, text='Got it') TOKEN = sys.argv[1] # get token from command-line bot = amanobot.Bot(TOKEN) MessageLoop(bot, {'chat': on_chat_message, 'callback_query': on_callback_query}).run_as_thread() print('Listening ...') while 1: time.sleep(10)
from var import BOT_NAME from private import prod_token chat_backend = get_chatbot() def main_loop(msg): content_type, chat_type, chat_id = amanobot.glance(msg) if content_type == "text": msg_text = msg["text"].lower() check = True # In a group always respond when mentioned # or respond 10% of the time if chat_type == "group" and not random.random() < 0.05: check = BOT_NAME in msg_text if check: msg_text = msg_text.replace(BOT_NAME, "").strip() resp = chat_backend.get_response(msg_text) resp = str(resp) bot.sendMessage(chat_id, resp) bot = amanobot.Bot(prod_token) MessageLoop(bot, main_loop).run_as_thread() while True: time.sleep(10)