Beispiel #1
0
def main():

    # ТУТ БУДЕТ НАШ КОД РАБОТЫ С БАЗОЙ ДАННЫХ
    # КОД ДАЛЬНЕЙШИХ ПРИМЕРОВ ВСТАВЛЯТЬ В ЭТО МЕСТО

    # Не забываем закрыть соединение с базой данных

    TOKEN = sys.argv[1]  # get token from command-line

    bot = telepot.aio.DelegatorBot(TOKEN, [
        pave_event_space()(
            per_chat_id(), create_open, AttendanceStarter, timeout=3),
        pave_event_space()(
            per_callback_query_origin(), create_open, Attendance, timeout=60),
    ])

    loop = asyncio.get_event_loop()

    loop.create_task(MessageLoop(bot).run_forever())
    print('Listening ...')

    loop.run_forever()
Beispiel #2
0
        if 'favourite' in query_data:
            download_to = query_data.strip('favourite_')
            with open(torrents_cfg['t_file_magnet'], 'rb') as hFile:
                torrent = pickle.load(hFile)
            try:
                self.command.torrent_add(torrent['torrent'],
                                         download_dir=favourites[download_to])
                await self.bot.sendMessage(from_id,
                                           "Link has been added to the queue",
                                           reply_markup=None)
                await self.show_torrents_list(from_id)
            except Exception as e:
                await self.bot.sendMessage(from_id, e, reply_markup=None)

    async def on__idle(self, event):
        await asyncio.sleep(1)
        self.close()


teletor = telepot.aio.DelegatorBot(telegram_bot['token'], [
    pave_event_space()(per_chat_id(), create_open, TorrentBot, timeout=10),
    pave_event_space()(
        per_callback_query_origin(), create_open, TorrentBot, timeout=10),
])

if __name__ == '__main__':
    loop = asyncio.get_event_loop()
    loop.create_task(teletor.message_loop())
    loop.run_forever()
Beispiel #3
0
    chunk_size = len(lst) // chunk_count
    return [lst[i:i + chunk_size] for i in range(0, len(lst), chunk_size)]


'''
    keyboard = InlineKeyboardMarkup(inline_keyboard=[
        [InlineKeyboardButton(text='Press me', callback_data='4')],
    ])

    bot.sendMessage(chat_id, 'Use inline keyboard', reply_markup=keyboard)
'''

TOKEN = sys.argv[1]  # get token from command-line

# bot = telepot.aio.Bot(TOKEN)

bot = telepot.aio.DelegatorBot(TOKEN, [
    pave_event_space()(
        per_chat_id(), create_open, SheluderStarter, timeout=3),
    pave_event_space()(
        per_callback_query_origin(), create_open, Sheluder, timeout=60),
])


loop = asyncio.get_event_loop()

loop.create_task(MessageLoop(bot).run_forever())
print('Listening ...')

loop.run_forever()
Beispiel #4
0
        if query_data != 'start':
            self._score[self._answer == int(query_data)] += 1

        self._answer = await self._show_next_question()

    async def on__idle(self, event):
        text = '%d out of %d' % (self._score[True], self._score[True]+self._score[False])
        await self.editor.editMessageText(
            text + '\n\nThis message will disappear in 5 seconds to test deleteMessage',
            reply_markup=None)

        await asyncio.sleep(5)
        await self.editor.deleteMessage()
        self.close()


TOKEN = sys.argv[1]

bot = telepot.aio.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),
])

loop = asyncio.get_event_loop()
loop.create_task(MessageLoop(bot).run_forever())
print('Listening ...')

loop.run_forever()
Beispiel #5
0
    async def on_callback_query(self, msg):
        query_id, from_id, query_data = glance(msg, flavor='callback_query')
        print(msg)

        letter = {
            'name': msg['from']['first_name'],
            'chid': msg['message']['chat']['id'],
            'type': '',
            'orgn': msg['message']['text']
        }

        q = query_data.split('♡')
        print(q)


me = key_.adds('me')
mew = key_.adds('mew')

bot = telepot.aio.DelegatorBot(key_.kids('beta'), [
    pave_event_space()(per_chat_id(), create_open, Emperor, timeout=3),
    pave_event_space()(
        per_callback_query_origin(), create_open, Slave, timeout=300),
])

sys.stdout = Unbuffered(sys.stdout)
loop = asyncio.get_event_loop()
loop.create_task(MessageLoop(bot).run_forever())
print('<--- --- Listening ... --- --->')
loop.run_forever()
            # 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}))
            await self.sender.sendMessage(
                'Got it. Alarm is set at %.1f seconds from now.' % delay)
        except ValueError:
            await self.sender.sendMessage('Not a number. No alarm set.')


if __name__ == "__main__":
    bot = telepot.aio.DelegatorBot(TOKEN, [
        pave_event_space()(
            per_chat_id(), create_open, MyChatHandler, timeout=3),
        pave_event_space()(per_callback_query_origin(),
                           create_open,
                           MyCallbackQueryHandler,
                           timeout=10),
    ])

    # Тестирую события и отложенные уведомления:
    # bot = telepot.aio.DelegatorBot(TOKEN, [
    #     pave_event_space()(
    #         per_chat_id(), create_open, AlarmSetter, timeout=10),
    # ])

    loop = asyncio.get_event_loop()
    loop.create_task(MessageLoop(bot).run_forever())
    print('Listening ...')
Beispiel #7
0
            self._score[self._answer == int(query_data)] += 1

        self._answer = await self._show_next_question()

    async def on__idle(self, event):
        text = '%d out of %d' % (self._score[True],
                                 self._score[True] + self._score[False])
        await self.editor.editMessageText(
            text +
            '\n\nThis message will disappear in 5 seconds to test deleteMessage',
            reply_markup=None)

        await asyncio.sleep(5)
        await self.editor.deleteMessage()
        self.close()


TOKEN = sys.argv[1]

bot = telepot.aio.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),
])

loop = asyncio.get_event_loop()
loop.create_task(MessageLoop(bot).run_forever())
print('Listening ...')

loop.run_forever()