加群消息测试
This commit is contained in:
2
group_add/config.toml
Normal file
2
group_add/config.toml
Normal file
@@ -0,0 +1,2 @@
|
||||
[GroupAdd]
|
||||
enable = true
|
||||
90
group_add/main.py
Normal file
90
group_add/main.py
Normal file
@@ -0,0 +1,90 @@
|
||||
import logging
|
||||
from datetime import datetime
|
||||
|
||||
import mysql.connector.pooling
|
||||
import tomllib
|
||||
import redis
|
||||
from wcferry import Wcf, WxMsg
|
||||
|
||||
from robot_cmd.robot_command import GroupBotManager
|
||||
|
||||
|
||||
class GroupAdd:
|
||||
def __init__(self, wcf: Wcf, gbm: GroupBotManager, all_contacts: dict):
|
||||
# 读取配置文件
|
||||
with open("group_video_man/config.toml", "rb") as f:
|
||||
plugin_config = tomllib.load(f)
|
||||
|
||||
config = plugin_config["GroupAdd"]
|
||||
self.LOG = logging.getLogger(__name__)
|
||||
|
||||
self.enable = config["enable"]
|
||||
self.wcf = wcf
|
||||
self.gbm = gbm
|
||||
self.all_contacts = all_contacts
|
||||
|
||||
self.LOG.info(f"[加群提醒] 组件初始化完成")
|
||||
|
||||
def handle_message(self, message: WxMsg):
|
||||
if not self.enable:
|
||||
return
|
||||
now_time = str(datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
|
||||
nick_name = self.all_contacts.get(message.sender, message.sender)
|
||||
|
||||
user_info = self.wcf.query_sql("MicroMsg.db", f"SELECT * FROM Contact WHERE UserName = '{message.sender}';")
|
||||
|
||||
self.LOG.info(f"GroupAdd contact:{user_info}")
|
||||
|
||||
BigHeadImgUrl = ""
|
||||
url = "https://hot.imsyy.top/#/"
|
||||
outxml = f"""
|
||||
<?xml version="1.0"?>
|
||||
<msg>
|
||||
<appmsg appid="" sdkver="1">
|
||||
<title>👏欢迎 {nick_name} 加入群聊!🎉</title>
|
||||
<des>⌚时间:{now_time}</des>
|
||||
<action>view</action>
|
||||
<type>5</type>
|
||||
<showtype>0</showtype>
|
||||
<content />
|
||||
<url>{url}</url>
|
||||
<dataurl />
|
||||
<lowurl />
|
||||
<lowdataurl />
|
||||
<recorditem />
|
||||
<thumburl>{BigHeadImgUrl}</thumburl>
|
||||
<messageaction />
|
||||
<laninfo />
|
||||
<extinfo />
|
||||
<sourceusername />
|
||||
<sourcedisplayname />
|
||||
<commenturl />
|
||||
<appattach>
|
||||
<totallen>0</totallen>
|
||||
<attachid />
|
||||
<emoticonmd5 />
|
||||
<fileext />
|
||||
<aeskey />
|
||||
</appattach>
|
||||
<webviewshared>
|
||||
<publisherId />
|
||||
<publisherReqId>0</publisherReqId>
|
||||
</webviewshared>
|
||||
<weappinfo>
|
||||
<pagepath />
|
||||
<username />
|
||||
<appid />
|
||||
<appservicetype>0</appservicetype>
|
||||
</weappinfo>
|
||||
<websearch />
|
||||
</appmsg>
|
||||
<fromusername>Jyunere</fromusername>
|
||||
<scene>0</scene>
|
||||
<appinfo>
|
||||
<version>1</version>
|
||||
<appname></appname>
|
||||
</appinfo>
|
||||
<commenturl></commenturl>
|
||||
</msg>
|
||||
|
||||
"""
|
||||
6
robot.py
6
robot.py
@@ -29,6 +29,7 @@ from configuration import Config
|
||||
from constants import ChatType
|
||||
from game_task.game_task_encyclopedia import game_process_message, setup_schedule, get_group_ids, \
|
||||
run_random_task_assignment
|
||||
from group_add.main import GroupAdd
|
||||
from group_auto.group_auto_invite import get_first_group_id, process_command
|
||||
from group_auto.group_member_change import GroupMemberChange
|
||||
from group_video.bot_video import BotVideo
|
||||
@@ -96,6 +97,8 @@ class Robot(Job):
|
||||
self.xiuren = Xiuren(wcf, self.gbm)
|
||||
# 美腿模块
|
||||
self.beautyleg = BeautyLeg(wcf, self.gbm)
|
||||
# 加群测试
|
||||
self.group_add = GroupAdd(wcf, self.gbm, self.allContacts)
|
||||
|
||||
if ChatType.is_in_chat_types(chat_type):
|
||||
if chat_type == ChatType.TIGER_BOT.value and TigerBot.value_check(self.config.TIGERBOT):
|
||||
@@ -321,6 +324,9 @@ class Robot(Job):
|
||||
self.LOG.error(f"game_message_load error:{e}")
|
||||
try:
|
||||
# TODO 群人员添加也是消息类型10000的消息
|
||||
if msg.type == 10000:
|
||||
self.group_add.handle_message(msg)
|
||||
|
||||
result = self.gmc.process_message(msg.roomid, msg.xml)
|
||||
# 判断是否没有变化
|
||||
if "$NO_CHANGE$" not in result:
|
||||
|
||||
Reference in New Issue
Block a user