wwf
This commit is contained in:
56
main.py
56
main.py
@@ -31,16 +31,18 @@ from urllib.parse import quote, unquote
|
||||
import re
|
||||
import emoji
|
||||
|
||||
|
||||
models.Base.metadata.create_all(bind=engine)
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
|
||||
testEmo="异度世界🤖"
|
||||
|
||||
newtestEmo=WXBotService.emoji_to_unicode(testEmo)
|
||||
print ("newtestEmo",newtestEmo)
|
||||
oldEmoji = "异度世界🤖"
|
||||
original_string = WXBotService.emoji_to_unicode(oldEmoji)
|
||||
print("original_string", original_string)
|
||||
# 定义正则表达式模式,匹配 \\uXXXX 形式的 Unicode 编码
|
||||
unicode_regex = r'\\u([0-9a-fA-F]{4})'
|
||||
# 使用正则表达式替换
|
||||
converted_string = re.sub(unicode_regex, r'[@emoji=\1]', original_string)
|
||||
print("converted_string", converted_string)
|
||||
|
||||
|
||||
# Dependency
|
||||
@@ -107,7 +109,9 @@ def addH5openid(h5openid, wxid, db: Session = Depends(get_db)):
|
||||
# 机器人id
|
||||
account_wxid = config.account_wxid
|
||||
# 新增用户
|
||||
new_user = utils.saveWxidInfo(account_wxid=config.account_wxid,wxid=wxid, h5openid=h5openid)
|
||||
new_user = utils.saveWxidInfo(account_wxid=config.account_wxid,
|
||||
wxid=wxid,
|
||||
h5openid=h5openid)
|
||||
# "errmsg":r['errmsg'],,"errcode":r['errcode']
|
||||
# return {"session_key":r['session_key'],"unionid":r['unionid'],"openid":r['openid']}
|
||||
return new_user
|
||||
@@ -146,16 +150,16 @@ def h5group(nickname, db: Session = Depends(get_db)):
|
||||
pattern = r'收到(\w+)的在看'
|
||||
print(newtext)
|
||||
matches = re.findall(pattern, newtext)
|
||||
print("matches",matches)
|
||||
matchesString=None
|
||||
if len(matches)>0:
|
||||
matchesString=matches[0]
|
||||
print("matchesString",matchesString)
|
||||
|
||||
print("matches", matches)
|
||||
matchesString = None
|
||||
if len(matches) > 0:
|
||||
matchesString = matches[0]
|
||||
print("matchesString", matchesString)
|
||||
|
||||
if matchesString:
|
||||
matchesString=remove_emojis(matchesString) #删除emoji字符串
|
||||
matchesString = remove_emojis(matchesString) #删除emoji字符串
|
||||
print("匹配到的结果:", matchesString)
|
||||
# 判断是否在群中
|
||||
# 判断是否在群中
|
||||
inGroup = False
|
||||
groupList = WXBotService.get_group_members_list(
|
||||
robot_wxid=config.account_wxid, from_wxid=config.chatroomId)
|
||||
@@ -170,15 +174,16 @@ def h5group(nickname, db: Session = Depends(get_db)):
|
||||
allFriend = WXBotService.get_address_list(config.account_wxid)
|
||||
for friendItem in allFriend['data']["contactList"]:
|
||||
# if friendItem['nickname'] == matchesString:
|
||||
if matchesString in friendItem['nickname'] :
|
||||
if matchesString in friendItem['nickname']:
|
||||
new_wxid = friendItem['wxid']
|
||||
else:
|
||||
# print('通过nickname查不到wxid')
|
||||
pass
|
||||
if new_wxid:
|
||||
WXBotService.send_text_message(robot_wxid=config.account_wxid,
|
||||
from_wxid=new_wxid,
|
||||
msg=f'已收到-[在看]支持,谢谢,即将发送群聊邀请\n[本消息是机器人自动回复]')
|
||||
WXBotService.send_text_message(
|
||||
robot_wxid=config.account_wxid,
|
||||
from_wxid=new_wxid,
|
||||
msg=f'已收到-[在看]支持,谢谢,即将发送群聊邀请\n[本消息是机器人自动回复]')
|
||||
WXBotService.add_group_members_40_more(
|
||||
robot_wxid=config.account_wxid,
|
||||
from_wxid=config.chatroomId, #异度星球群
|
||||
@@ -191,7 +196,6 @@ def h5group(nickname, db: Session = Depends(get_db)):
|
||||
print("未找到匹配项,或者有特殊字符")
|
||||
|
||||
|
||||
|
||||
# 创建用户
|
||||
@app.post("/users")
|
||||
# schemas.UserCreate决定了swagger文档
|
||||
@@ -243,6 +247,7 @@ def helloget(q: dict):
|
||||
def remove_emojis(text):
|
||||
return ''.join(c for c in text if c not in emoji.UNICODE_EMOJI)
|
||||
|
||||
|
||||
# 监听机器人post日志消息
|
||||
@app.post("/wxbot")
|
||||
# def hellopost(requestData:schemas.User):
|
||||
@@ -365,18 +370,19 @@ def kp(event_data):
|
||||
# WXBotService.add_group_members_40_more(robot_wxid='wxid_sfvsru738v3122',
|
||||
# from_wxid='49187487591@chatroom',
|
||||
# new_wxid='wxid_4413224132412')
|
||||
print("data",data)
|
||||
if "emoji" in wx_name:
|
||||
# 发送小程序
|
||||
print("data", data)
|
||||
if "emoji" in wx_name:
|
||||
# 发送小程序
|
||||
utils.sendminiProgram(data, account_wxid, wxid, planetXml)
|
||||
else:
|
||||
# H5链接
|
||||
# H5链接
|
||||
WXBotService.send_link_message(
|
||||
account_wxid,
|
||||
wxid,
|
||||
title="欢迎加入微信群",
|
||||
desc="请查看规则",
|
||||
url=f'https://link.hackrobot.cn#/pages/index/index?wxid={wxid}',
|
||||
url=
|
||||
f'https://link.hackrobot.cn#/pages/index/index?wxid={wxid}',
|
||||
pic=
|
||||
"https://www.hackrobot.cn/wp-content/uploads/2023/05/cropped-cropped-Screenshot-2023-05-22-at-17.26.38.png"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user