新增点歌插件。

This commit is contained in:
liuwei
2025-03-18 15:45:07 +08:00
parent adfa3505a5
commit ede83d6c94
8 changed files with 417 additions and 37 deletions

View File

@@ -66,6 +66,9 @@ from xiuren.xiuren_pdf import generate_pdf_from_images
from db.connection import DBConnectionManager
from message_util import MessageUtil
# 在文件顶部导入装饰器
from job_decorators import scheduled_job, register_scheduled_jobs
class Robot(Job):
"""个性化自己的机器人
@@ -75,6 +78,9 @@ class Robot(Job):
self.wcf = wcf
self.config = config
self.LOG = logging.getLogger("Robot")
# 在初始化结束时注册所有被装饰的定时任务
register_scheduled_jobs(self)
self.wxid = self.wcf.get_self_wxid()
self.allContacts = self.get_all_contacts()
self.LOG.info(f"DB+REDIS 连接池开始初始化")
@@ -111,7 +117,6 @@ class Robot(Job):
"plugin_registry": self.plugin_registry,
"db_pool": self.db_pool,
"redis_pool": self.redis_pool,
"all_contacts": self.allContacts,
"message_util": self.message_util
}
@@ -571,7 +576,8 @@ class Robot(Job):
"timestamp": time.time(),
"wcf": self.wcf, # 提供wcf对象让插件可以直接发送消息
"message_util": self.message_util, # 提供消息工具类
"gbm": self.gbm # 每次从程序变量中取,保证最新
"gbm": self.gbm, # 每次从程序变量中取,保证最新
"all_contacts": self.allContacts
}
# 检查插件是否可以处理该消息
@@ -591,7 +597,7 @@ class Robot(Job):
return False
# ============================================== 业务内容==========================================================
@scheduled_job(cron="0 0 8 * * *", name="每日新闻推送")
def news_baidu_report_auto(self) -> None:
try:
news = News().get_baidu_news()
@@ -613,6 +619,8 @@ class Robot(Job):
except Exception as e:
self.LOG.error(f"newsEnReport error{e}")
# 使用装饰器标记定时任务 星期五 10:30 执行
@scheduled_job(cron="0 30 10 * * 5", name="Epic免费游戏推送")
def send_epic_free_games(self):
try:
if is_friday():
@@ -621,12 +629,15 @@ class Robot(Job):
except Exception as e:
self.LOG.error(f"sendEpicFreeGames error{e}")
# 使用装饰器标记定时任务
@scheduled_job(cron="0 0 * * * *", name="消息统计入库")
def message_count_to_db(self):
try:
self.message_storage.write_to_db()
except Exception as e:
self.LOG.error(f"write_to_db error{e}")
@scheduled_job(cron="0 0 15 * * *", name="发送色花堂")
def generate_sehuatang_pdf(self):
try:
path = pdf_file_path()
@@ -635,6 +646,7 @@ class Robot(Job):
except Exception as e:
self.LOG.error(f"generateSehuatangPdf error{e}")
@scheduled_job(cron="0 30 9 * * *", name="发送消息排行榜")
def generate_and_send_ranking(self):
try:
receivers = self.gbm.get_group_list()
@@ -661,6 +673,7 @@ class Robot(Job):
self.LOG.error(f"message_summary_robot error{e}")
# 设置定时任务
@scheduled_job(cron="0 0 18 * * *", name="每天发一个游戏任务")
def game_auto_tasks(self):
try:
group_ids = get_group_ids()
@@ -675,6 +688,7 @@ class Robot(Job):
except Exception as e:
self.LOG.error(f"message_summary_robot error{e}")
@scheduled_job(cron="0 30 1 * * *", name="每天下载10组图")
def xiu_ren_download_task(self):
try:
# 每天下载10组图然后发一个帖子PDF
@@ -682,9 +696,9 @@ class Robot(Job):
except Exception as e:
self.LOG.error(f"xiu_ren_download_task error{e}")
@scheduled_job(cron="0 30 17 * * *", name="发送秀人PDF")
def xiu_ren_pdf_send(self):
try:
pub_path = generate_pdf_from_images("xiuren")
self.wcf.send_file(pub_path, "45317011307@chatroom")
except Exception as e: