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)
super(MessageCounter, self).__init__(*args, **kwargs) self._count = 0 def on_chat_message(self, msg): self._count += 1 self.sender.sendMessage(self._count) TOKEN = sys.argv[1] PORT = int(sys.argv[2]) URL = sys.argv[3] app = Flask(__name__) bot = amanobot.DelegatorBot(TOKEN, [ pave_event_space()(per_chat_id(), create_open, MessageCounter, timeout=10), ]) webhook = OrderedWebhook(bot) @app.route('/webhook', methods=['GET', 'POST']) def pass_update(): webhook.feed(request.data) return 'OK' if __name__ == '__main__': try: bot.setWebhook(URL) # Sometimes it would raise this error, but webhook still set successfully.
self._close_ballot() self.sender.sendMessage('Time is up:\nYes: %d\nNo: %d\nSilent: %d' % result) def on_close(self, ex): global votes if self._ballot_box is None: try: del votes[self.id] except KeyError: pass else: votes[self.id] = (self._ballot_box, self._keyboard_msg_ident, self._expired_event) from pprint import pprint pprint(votes) TOKEN = sys.argv[1] bot = amanobot.DelegatorBot(TOKEN, [ include_callback_query_chat_id(pave_event_space())( per_chat_id(types=['group']), create_open, VoteCounter, timeout=10), ]) MessageLoop(bot).run_as_thread() print('Listening ...') while 1: time.sleep(10)
for key, item in flex.items(): msg += f'\n *{key}:* {item}' self.sender.sendMessage(msg, parse_mode='Markdown') return except: self.sender.sendMessage( "Não encontrei informações da Flex de " + argumento) return def on_callback_query(self, msg): query_id, from_id, query_data = amanobot.glance( msg, flavor='callback_query') pass def on__idle(self, event): # print('Em caso de dúvidas, contate a STI por telefone. O ramal 0000.') pass TOKEN = '1366501748:AAHD61_3d0brQKvpGDCRt3caB7sG5yJJx-M' bot = amanobot.DelegatorBot(TOKEN, [ include_callback_query_chat_id(pave_event_space())( per_chat_id(types='all'), create_open, Chat, timeout=10), ]) MessageLoop(bot).run_as_thread() print('Listening ...') while 1: time.sleep(10)
self._cancel_last() self.sender.sendMessage('Thank you!') self.close() else: self.bot.answerCallbackQuery(query_id, text='Ok. But I am going to keep asking.') self._cancel_last() self._propose() def on__idle(self, event): self.sender.sendMessage('I know you may need a little time. I will always be here for you.') self.close() def on_close(self, ex): # Save to database global propose_records propose_records[self.id] = (self._count, self._edit_msg_ident) TOKEN = sys.argv[1] bot = amanobot.DelegatorBot(TOKEN, [ include_callback_query_chat_id( pave_event_space())( per_chat_id(types=['private']), create_open, Lover, timeout=10), ]) MessageLoop(bot).run_as_thread() print('Listening ...') while 1: time.sleep(10)
# 2. Define event-handling function def on__alarm(self, event): print(event) # see what the event object actually looks like self.sender.sendMessage('Beep beep, time to wake up!') def on_chat_message(self, msg): try: delay = float(msg['text']) # 3. Schedule event # The second argument is the event spec: a 2-tuple of (flavor, dict). # Put any custom data in the dict. Retrieve them in the event-handling function. self.scheduler.event_later(delay, ('_alarm', {'payload': delay})) self.sender.sendMessage( 'Got it. Alarm is set at %.1f seconds from now.' % delay) except ValueError: self.sender.sendMessage('Not a number. No alarm set.') TOKEN = sys.argv[1] bot = amanobot.DelegatorBot(TOKEN, [ pave_event_space()(per_chat_id(), create_open, AlarmSetter, timeout=10), ]) MessageLoop(bot).run_as_thread() print('Listening ...') while 1: time.sleep(10)
guess = int(msg['text']) except ValueError: self.sender.sendMessage('Give me a number, please.') return # check the guess against the answer ... if guess != self._answer: # give a descriptive hint hint = self._hint(self._answer, guess) self.sender.sendMessage(hint) else: self.sender.sendMessage('Correct!') self.close() def on__idle(self, event): self.sender.sendMessage('Game expired. The answer is %d' % self._answer) self.close() TOKEN = sys.argv[1] bot = amanobot.DelegatorBot(TOKEN, [ pave_event_space()(per_chat_id(), create_open, Player, timeout=10), ]) MessageLoop(bot).run_as_thread() print('Listening ...') while 1: time.sleep(10)
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)
guess = int(msg['text']) except ValueError: self.sender.sendMessage('Give me a number, please.') return # check the guess against the answer ... if guess != self._answer: # give a descriptive hint hint = self._hint(self._answer, guess) self.sender.sendMessage(hint) else: self.sender.sendMessage('Correct!') self.close() def on__idle(self, event): self.sender.sendMessage('Game expired. The answer is %d' % self._answer) self.close() TOKEN = sys.argv[1] bot = amanobot.DelegatorBot(TOKEN, [ pave_event_space()( per_chat_id(), create_open, Player, timeout=10), ]) MessageLoop(bot).run_as_thread() print('Listening ...') while 1: time.sleep(10)