1.加入了指令;
2.判断接收人从redis+本地缓存中提取; 3.做本地缓存与redis实时同步;
This commit is contained in:
65
robot.py
65
robot.py
@@ -23,7 +23,9 @@ from base.func_xinghuo_web import XinghuoWeb
|
||||
from base.func_claude import Claude
|
||||
from configuration import Config
|
||||
from constants import ChatType
|
||||
from group_auto.robot_command import GroupBotManager
|
||||
from job_mgmt import Job
|
||||
from group_auto.robot_command import Feature
|
||||
|
||||
__version__ = "39.2.4.0"
|
||||
|
||||
@@ -44,7 +46,8 @@ class Robot(Job):
|
||||
self.LOG = logging.getLogger("Robot")
|
||||
self.wxid = self.wcf.get_self_wxid()
|
||||
self.allContacts = self.getAllContacts()
|
||||
|
||||
GroupBotManager.load_local_cache()
|
||||
self.gbm = GroupBotManager()
|
||||
if ChatType.is_in_chat_types(chat_type):
|
||||
if chat_type == ChatType.TIGER_BOT.value and TigerBot.value_check(self.config.TIGERBOT):
|
||||
self.chat = TigerBot(self.config.TIGERBOT)
|
||||
@@ -127,6 +130,12 @@ class Robot(Job):
|
||||
def toChitchat(self, msg: WxMsg) -> bool:
|
||||
"""闲聊,接入 ChatGPT
|
||||
"""
|
||||
# 如果聊天内容来自自己,则进行指令判断
|
||||
if msg.from_self() and msg.from_group():
|
||||
command_str = re.sub(r"@.*?[\u2005|\s]", "", msg.content).replace(" ", "")
|
||||
rsp = GroupBotManager.handle_command(msg.roomid, command_str)
|
||||
self.sendTextMsg(rsp, msg.roomid, msg.sender)
|
||||
return True
|
||||
if not self.chat: # 没接 ChatGPT,固定回复
|
||||
rsp = "你@我干嘛?"
|
||||
else: # 接了 ChatGPT,智能回复
|
||||
@@ -140,6 +149,7 @@ class Robot(Job):
|
||||
elif q == '/总结':
|
||||
self.message_summary_robot((msg.roomid if msg.from_group() else msg.sender))
|
||||
return True
|
||||
# 群管理自动加入,减少服务重启管理
|
||||
else:
|
||||
rsp = self.chat.get_answer(q, (msg.roomid if msg.from_group() else msg.sender))
|
||||
|
||||
@@ -301,18 +311,40 @@ class Robot(Job):
|
||||
self.allContacts[msg.sender] = nickName[0]
|
||||
self.sendTextMsg(f"Hi {nickName[0]},我自动通过了你的好友请求。", msg.sender)
|
||||
|
||||
def send_group_txt_message(self, msg: str, feature: Feature):
|
||||
try:
|
||||
receivers = self.gbm.get_group_list()
|
||||
if not receivers:
|
||||
return
|
||||
for r in receivers:
|
||||
if self.gbm.get_group_permission(r, feature):
|
||||
self.sendTextMsg(msg, r)
|
||||
except Exception as e:
|
||||
self.LOG.error(f"send_group_txt_message:{feature.description} error:{e}")
|
||||
|
||||
def send_group_file_message(self, path: str, feature: Feature):
|
||||
try:
|
||||
receivers = self.gbm.get_group_list()
|
||||
if not receivers:
|
||||
return
|
||||
for r in receivers:
|
||||
if self.gbm.get_group_permission(r, feature):
|
||||
self.wcf.send_file(path, r)
|
||||
except Exception as e:
|
||||
self.LOG.error(f"send_group_file_message:{feature.description} error:{e}")
|
||||
|
||||
# ============================================== 业务内容==========================================================
|
||||
|
||||
def newsBaiduReportAuto(self) -> None:
|
||||
try:
|
||||
news = News().get_baidu_news()
|
||||
self.send_group_txt_message(news, Feature.DAILY_NEWS)
|
||||
except Exception as e:
|
||||
self.LOG.error(f"newsBaiduReportAuto error:{e}")
|
||||
|
||||
def newsBaiduReport(self, sender: str = None) -> None:
|
||||
try:
|
||||
news = News().get_baidu_news()
|
||||
# news = (
|
||||
# f"请根据新闻标题,按照新闻的类型(财经、彩票、房产、股票、家居、教育、科技、社会、时尚、时政、体育、星座、游戏、娱乐)进行分类;内容前加入当前日期和星期几" \
|
||||
# "内容格式如下:" \
|
||||
# "### 分类1" \
|
||||
# "1.#标题1" \
|
||||
# "2.#标题2" \
|
||||
# "分类之间使用--号进行分割,无内容则忽略该分组") + news
|
||||
|
||||
# rsp = self.chat.get_answer(news)
|
||||
self.sendTextMsg(news, sender)
|
||||
except Exception as e:
|
||||
self.LOG.error(f"newsBaiduReport error:{e}")
|
||||
@@ -326,13 +358,9 @@ class Robot(Job):
|
||||
|
||||
def sendEpicFreeGames(self):
|
||||
try:
|
||||
receivers = self.config.NEWS
|
||||
if not receivers:
|
||||
return
|
||||
if is_friday():
|
||||
games = get_free()
|
||||
for r in receivers:
|
||||
self.sendTextMsg(games, r)
|
||||
self.send_group_txt_message(games, Feature.EPIC)
|
||||
except Exception as e:
|
||||
self.LOG.error(f"sendEpicFreeGames error:{e}")
|
||||
|
||||
@@ -344,11 +372,12 @@ class Robot(Job):
|
||||
|
||||
def generateAndSendRanking(self):
|
||||
try:
|
||||
receivers = self.config.NEWS
|
||||
receivers = self.gbm.get_group_list()
|
||||
if not receivers:
|
||||
return
|
||||
for r in receivers:
|
||||
self.sendTextMsg(generate_and_send_ranking(r, self.allContacts), r)
|
||||
if self.gbm.get_group_permission(r, Feature.DAILY_SUMMARY):
|
||||
self.sendTextMsg(generate_and_send_ranking(r, self.allContacts), r)
|
||||
except Exception as e:
|
||||
self.LOG.error(f"SendRanking error:{e}")
|
||||
|
||||
@@ -356,7 +385,7 @@ class Robot(Job):
|
||||
try:
|
||||
path = pdf_file_path()
|
||||
# 暂时只发4K群
|
||||
self.wcf.send_file(path, "45317011307@chatroom")
|
||||
self.send_group_file_message(path, Feature.PDF_CAPABILITY)
|
||||
except Exception as e:
|
||||
self.LOG.error(f"generateSehuatangPdf error:{e}")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user