word_cloud_bot/main.py

34 lines
1.1 KiB
Python
Raw Normal View History

2021-05-05 02:59:30 +00:00
from telegram.ext import Updater
from config import TOKEN
2021-06-21 08:18:25 +00:00
from func import start_handler, ping_handler, chat_content_handler, check_schedule, rank_handler, stat_handler
2021-05-05 08:13:28 +00:00
import schedule
2021-06-21 08:18:25 +00:00
from task import schedule_task, flush_redis, do_task, do_user_task
2021-05-05 08:13:28 +00:00
import threading
2021-06-20 08:56:30 +00:00
# 开始定时任务 - 群组分析
schedule.every().day.at('12:00').do(schedule_task)
2021-05-08 02:18:24 +00:00
schedule.every().day.at('18:00').do(schedule_task)
schedule.every().day.at('23:30').do(schedule_task)
2021-05-05 10:17:21 +00:00
schedule.every().day.at('23:59').do(flush_redis)
2021-05-08 02:18:24 +00:00
# 测试代码,每分钟推送数据,非测试目的不要取消注释下一行
# schedule.every(1).minutes.do(schedule_task)
2021-05-05 08:13:28 +00:00
2021-06-21 08:18:25 +00:00
# 开启分析线程,当队列中有任务时,会取出任务分析生成数据
2021-05-08 02:18:24 +00:00
threading.Thread(target=do_task).start()
2021-06-21 08:18:25 +00:00
threading.Thread(target=do_user_task).start()
2021-05-08 02:18:24 +00:00
2021-05-05 08:13:28 +00:00
threading.Thread(target=check_schedule).start()
2021-05-05 02:59:30 +00:00
updater = Updater(token=TOKEN, use_context=True)
dispatcher = updater.dispatcher
dispatcher.add_handler(start_handler)
2021-06-20 10:51:23 +00:00
dispatcher.add_handler(ping_handler)
2021-05-08 02:18:24 +00:00
dispatcher.add_handler(rank_handler)
2021-06-21 08:18:25 +00:00
dispatcher.add_handler(stat_handler)
2021-05-05 03:10:01 +00:00
dispatcher.add_handler(chat_content_handler)
2021-05-05 02:59:30 +00:00
updater.start_polling()
updater.idle()