fwqfqwf
This commit is contained in:
49
main.py
49
main.py
@@ -35,14 +35,15 @@ models.Base.metadata.create_all(bind=engine)
|
|||||||
|
|
||||||
app = FastAPI()
|
app = FastAPI()
|
||||||
|
|
||||||
|
|
||||||
# 全局消息变量
|
# 全局消息变量
|
||||||
globalMsgData=None
|
globalMsgData = None
|
||||||
|
|
||||||
|
|
||||||
def is_chinese(char):
|
def is_chinese(char):
|
||||||
"""检查字符是否为中文字符。"""
|
"""检查字符是否为中文字符。"""
|
||||||
return '\u4e00' <= char <= '\u9fff'
|
return '\u4e00' <= char <= '\u9fff'
|
||||||
|
|
||||||
|
|
||||||
def convert_special_chars_to_emoji(input_string):
|
def convert_special_chars_to_emoji(input_string):
|
||||||
output = []
|
output = []
|
||||||
for char in input_string:
|
for char in input_string:
|
||||||
@@ -57,13 +58,11 @@ def convert_special_chars_to_emoji(input_string):
|
|||||||
emoji_representation = f"[@emoji={code_point}]"
|
emoji_representation = f"[@emoji={code_point}]"
|
||||||
# 将非中文且非 ASCII 字符替换为 emoji 代码点形式
|
# 将非中文且非 ASCII 字符替换为 emoji 代码点形式
|
||||||
output.append(emoji_representation)
|
output.append(emoji_representation)
|
||||||
|
|
||||||
# 将列表中的字符组合成一个字符串
|
# 将列表中的字符组合成一个字符串
|
||||||
return ''.join(output)
|
return ''.join(output)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# 转换emoji字符串为[]
|
# 转换emoji字符串为[]
|
||||||
def transOldemoji(oldEmoji=None):
|
def transOldemoji(oldEmoji=None):
|
||||||
# oldEmoji = "异度世界🤖"
|
# oldEmoji = "异度世界🤖"
|
||||||
@@ -82,13 +81,13 @@ def transOldemoji(oldEmoji=None):
|
|||||||
# 在 Unicode 编码后添加 ']'
|
# 在 Unicode 编码后添加 ']'
|
||||||
# 如果原始字符串中的 \\uXXX 是在方括号中,需要保留方括号
|
# 如果原始字符串中的 \\uXXX 是在方括号中,需要保留方括号
|
||||||
# 替换后,如果需要,可以调整这一步骤,根据特定需求
|
# 替换后,如果需要,可以调整这一步骤,根据特定需求
|
||||||
converted_string = re.sub(r'\[@emoji=[0-9a-fA-F]{4}\]', lambda match: f'{match.group()}]', converted_string)
|
converted_string = re.sub(r'\[@emoji=[0-9a-fA-F]{4}\]',
|
||||||
converted_string=converted_string.replace('[\\@', '[@')
|
lambda match: f'{match.group()}]',
|
||||||
|
converted_string)
|
||||||
|
converted_string = converted_string.replace('[\\@', '[@')
|
||||||
# 输出转换后的字符串
|
# 输出转换后的字符串
|
||||||
print(converted_string)
|
print(converted_string)
|
||||||
return converted_string
|
return converted_string
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Dependency
|
# Dependency
|
||||||
@@ -195,15 +194,15 @@ def h5group(nickname, db: Session = Depends(get_db)):
|
|||||||
newtext = unquote(nickname, 'utf-8')
|
newtext = unquote(nickname, 'utf-8')
|
||||||
# pattern = r'收到(\w+)的在看'
|
# pattern = r'收到(\w+)的在看'
|
||||||
pattern = r'收到([\w\[\]@=]+)的在看'
|
pattern = r'收到([\w\[\]@=]+)的在看'
|
||||||
print("newtext",newtext)
|
print("newtext", newtext)
|
||||||
|
|
||||||
# 处理emoji转为[@emoji=1f916] 格式
|
# 处理emoji转为[@emoji=1f916] 格式
|
||||||
newtext=transOldemoji(newtext)
|
newtext = transOldemoji(newtext)
|
||||||
print("newtextemoji",newtext)
|
print("newtextemoji", newtext)
|
||||||
|
|
||||||
# 不是 ASCII 字符,则获取该字符的 Unicode 代码点
|
# 不是 ASCII 字符,则获取该字符的 Unicode 代码点
|
||||||
newtext = convert_special_chars_to_emoji(newtext)
|
newtext = convert_special_chars_to_emoji(newtext)
|
||||||
print("newtextASI",newtext)
|
print("newtextASI", newtext)
|
||||||
matches = re.findall(pattern, newtext)
|
matches = re.findall(pattern, newtext)
|
||||||
print("matches", matches)
|
print("matches", matches)
|
||||||
matchesString = None
|
matchesString = None
|
||||||
@@ -229,25 +228,29 @@ def h5group(nickname, db: Session = Depends(get_db)):
|
|||||||
allFriend = WXBotService.get_address_list(config.account_wxid)
|
allFriend = WXBotService.get_address_list(config.account_wxid)
|
||||||
for friendItem in allFriend['data']["contactList"]:
|
for friendItem in allFriend['data']["contactList"]:
|
||||||
if friendItem['nickname'] == matchesString:
|
if friendItem['nickname'] == matchesString:
|
||||||
# if matchesString in friendItem['nickname']:
|
# if matchesString in friendItem['nickname']:
|
||||||
new_wxid = friendItem['wxid']
|
new_wxid = friendItem['wxid']
|
||||||
else:
|
else:
|
||||||
# print('通过nickname查不到wxid')
|
# print('通过nickname查不到wxid')
|
||||||
pass
|
pass
|
||||||
if new_wxid:
|
if new_wxid:
|
||||||
WXBotService.send_text_message(
|
|
||||||
robot_wxid=config.account_wxid,
|
# WXBotService.add_group_members_40_more(
|
||||||
from_wxid=new_wxid,
|
# robot_wxid=config.account_wxid,
|
||||||
msg=f'已收到-[在看]支持,谢谢,即将发送群聊邀请\n[本消息是机器人自动回复]')
|
# from_wxid=config.chatroomId, #异度星球群
|
||||||
WXBotService.add_group_members_40_more(
|
# new_wxid=new_wxid)
|
||||||
robot_wxid=config.account_wxid,
|
|
||||||
from_wxid=config.chatroomId, #异度星球群
|
|
||||||
new_wxid=new_wxid)
|
|
||||||
print('new_wxid--', new_wxid)
|
print('new_wxid--', new_wxid)
|
||||||
# global globalMsgData
|
# global globalMsgData
|
||||||
# # 发送小程序
|
# # 发送小程序
|
||||||
# print("globalMsgData",globalMsgData)
|
# print("globalMsgData",globalMsgData)
|
||||||
utils.sendminiProgram(data=None,account_wxid= config.account_wxid, wxid=new_wxid,msgXml= planetXml)
|
utils.sendminiProgram(data=None,
|
||||||
|
account_wxid=config.account_wxid,
|
||||||
|
wxid=new_wxid,
|
||||||
|
msgXml=planetXml)
|
||||||
|
WXBotService.send_text_message(
|
||||||
|
robot_wxid=config.account_wxid,
|
||||||
|
from_wxid=new_wxid,
|
||||||
|
msg=f'已收到-[在看]支持,谢谢,请从小程序,点击"立即加入"\n[本消息是机器人自动回复]')
|
||||||
return {"code": 200, "success": "ok", "message": "群聊邀请已发送"}
|
return {"code": 200, "success": "ok", "message": "群聊邀请已发送"}
|
||||||
else:
|
else:
|
||||||
return {"code": 200, "success": "ok", "message": "查不到nickname"}
|
return {"code": 200, "success": "ok", "message": "查不到nickname"}
|
||||||
|
|||||||
Reference in New Issue
Block a user