Skip to content

Commit

Permalink
添加启动脚本,更新readme
Browse files Browse the repository at this point in the history
  • Loading branch information
NekoRabi authored May 11, 2022
1 parent 0fcc394 commit ccbed75
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 22 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,14 @@

本程序 `WebSocketAdapter` 的端口号为 `17280`

提供docker,但需要自己build (我本地环境不知道为什么跑不了docker),部署流程包内有说明

# 环境

我自己电脑是Python 3.8 Java 15, 服务器是 Python 3.9 Java 17.

**建议使用 Python 3.9 和 Java 17**

已知Python 3.10 可能有问题跑不起来,如已安装并报错,请降级安装python 3.8-9 *以后会去解决3.10的问题*

# 关于风控
Expand Down
76 changes: 54 additions & 22 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,10 @@
replydata = load_replydata()
create_helpimg()
cmdbuffer = commandcache()
rootLogger = create_logger(config['loglevel'])
qqlogger = getQQlogger()
rootLogger = create_logger(config['loglevel'])

black_list = dict(user=[], group=[])
black_list['user'] = config['blacklist']
black_list['group'] = config['mutegrouplist']
black_list = dict(user=config['blacklist'], group=config['mutegrouplist'])
whiteList = config['whitelist']
admin: list = config['admin']
master = config['master']
Expand All @@ -38,15 +36,14 @@
norepeatgroup = config['norepeatgroup']
qhsettings = config['qhsettings']
disnudgegroup = config['disnudgegroup']
stfinder = setufinder(botname)
stfinder = SetuFinder(botname)
bot = create_bot(config)



if master not in admin:
admin.append(master)
print(f"机器人{botname}启动中\tQQ : {bot.qq}\nadapter : {bot.adapter_info}")


async def asyqh_autopaipu():
result = asygetqhpaipu()
print("查询新的雀魂对局信息有:")
Expand Down Expand Up @@ -79,7 +76,8 @@ def is_havingadmin(event: GroupMessage):
return True


def getreply(reply: list = None, text: str = None, rndimg: bool = False, imgpath: str = None,at:int=None) -> MessageChain:
def getreply(reply: list = None, text: str = None, rndimg: bool = False, imgpath: str = None,
at: int = None) -> MessageChain:
msgchain = []
if at:
msgchain.append(At(at))
Expand All @@ -98,6 +96,36 @@ def getreply(reply: list = None, text: str = None, rndimg: bool = False, imgpath
Image(path=f"{imgpath}"))
return MessageChain(msgchain)

# 配置热重载


# @bot.on(MessageEvent)
# async def reloadconfig(event:MessageEvent):
# if event.sender.id == master:
# msg = "".join(map(str, event.message_chain[Plain]))
# m = re.match(
# fr"^{commandpre}reloadconfig\s*$", msg.strip())
# if m:
# global config,black_list,whiteList,admin,master,settings,botname,commandpre,alarmclockgroup,silencegroup,repeatconfig,norepeatgroup,qhsettings,disnudgegroup
# config = load_config()
#
# black_list = dict(user=config['blacklist'], group=config['mutegrouplist'])
# whiteList = config['whitelist']
# admin = config['admin']
# master = config['master']
# settings = config['settings']
# botname = config['botconfig']['botname']
# commandpre = config['commandpre']
# alarmclockgroup = config['alarmclockgroup']
# silencegroup = config['silencegroup']
# repeatconfig = config['repeatconfig']
# norepeatgroup = config['norepeatgroup']
# qhsettings = config['qhsettings']
# disnudgegroup = config['disnudgegroup']
#
# return await bot.send(event,"配置热重载完成,可能会出现意料之外的错误,建议重新启动。")



# 聊天记录存储
@bot.on(MessageEvent)
Expand Down Expand Up @@ -289,7 +317,7 @@ async def setu(event: GroupMessage):
if not cmdbuffer.updategroupcache(groupcommand(event.group.id, event.sender.id, 'setu')):
return bot.send(event, getreply(text="你冲的频率太频繁了,休息一下吧", rndimg=True, at=event.sender.id))
try:
imginfo = stfinder.getsetu(m1.group(2),groupid=event.group.id)
imginfo = stfinder.getsetu(m1.group(2), groupid=event.group.id)
if imginfo['FoundError']:
return await bot.send(event, getreply(text=imginfo['ErrorMsg']))
await bot.send(event, MessageChain([Image(url=imginfo['url'])]))
Expand All @@ -302,8 +330,8 @@ async def setu(event: GroupMessage):
await bot.send(event, [At(event.sender.id), " 能不能少冲点啊,这次就不给你发了"])
else:
if settings['setu'] and event.group.id in config['setugroups']:
if not cmdbuffer.updategroupcache(groupcommand(event.group.id,event.sender.id,'setu')):
return bot.send(event,getreply(text="你冲的频率太频繁了,休息一下吧",rndimg=True,at=event.sender.id))
if not cmdbuffer.updategroupcache(groupcommand(event.group.id, event.sender.id, 'setu')):
return bot.send(event, getreply(text="你冲的频率太频繁了,休息一下吧", rndimg=True, at=event.sender.id))

try:
imginfo = stfinder.getsetu(m2.group(3), event.group.id, m2.group(1))
Expand All @@ -324,6 +352,8 @@ async def getmajsoulhelp(event: MessageEvent):
msg = "".join(map(str, event.message_chain[Plain]))
m = re.match(fr'^{commandpre}(help|帮助)\s*$', msg.strip())
if m and settings['help']:
# if not cmdbuffer.updategroupcache(groupcommand(event.group.id, event.sender.id, 'help')):
# return bot.send(event, getreply(text="帮助文档刚刚才发过哦~", rndimg=True, at=event.sender.id))
return await bot.send(event, Image(path="./images/help.png"))


Expand Down Expand Up @@ -417,7 +447,7 @@ async def enableqhplugin(event: GroupMessage):
async def qhpt(event: GroupMessage):
msg = "".join(map(str, event.message_chain[Plain]))
# 匹配指令
m = re.match(fr'^{commandpre}(qhpt|雀魂分数|雀魂pt)\s*([\w_、,\.,\'\"!]+)\s*([34])?\s*([0-9]+)?\s*$', msg.strip())
m = re.match(fr'^{commandpre}(qhpt|雀魂分数|雀魂pt)\s*([\w_、,\.,\'\"!]+)\s*([34])?\s*([0-9]+)?\s*$', msg.strip())
if m:
if qhsettings['qhpt'] and event.group.id not in qhsettings['disptgroup']:

Expand All @@ -431,7 +461,7 @@ async def qhpt(event: GroupMessage):
else:
result = query(m.group(2))
if result['error']:
await bot.send(event,result['msg'])
await bot.send(event, result['msg'])
else:
await bot.send(event, Image(path=f'./images/MajsoulInfo/qhpt{m.group(2)}.png'))
return
Expand All @@ -441,7 +471,7 @@ async def qhpt(event: GroupMessage):
async def getrecentqhpaipu(event: GroupMessage):
msg = "".join(map(str, event.message_chain[Plain]))
m = re.match(
fr'^{commandpre}(qhpaipu|雀魂最近对局)\s*([\w_、,\.,\'\"!]+)\s*([34])*\s*([0-9]+)?\s*$', msg.strip())
fr'^{commandpre}(qhpaipu|雀魂最近对局)\s*([\w_、,\.,\'\"!]+)\s*([34])*\s*([0-9]+)?\s*$', msg.strip())
if m:
if qhsettings['qhpaipu'] and event.group.id not in qhsettings['dispaipugroup']:

Expand Down Expand Up @@ -471,7 +501,7 @@ async def getplayerdetails(event: GroupMessage):
msg = "".join(map(str, event.message_chain[Plain]))

m = re.match(
fr'^{commandpre}(qhinfo|雀魂玩家详情)\s*([\w_、,\.,\'\"!]+)\s*(\d+)\s*(\w+)*\s*(\w+)*\s*$', msg.strip())
fr'^{commandpre}(qhinfo|雀魂玩家详情)\s*([\w_、,\.,\'\"!]+)\s*(\d+)\s*(\w+)*\s*(\w+)*\s*$', msg.strip())
if m:
if qhsettings['qhinfo'] and event.group.id not in qhsettings['disinfogroup']:

Expand Down Expand Up @@ -499,7 +529,8 @@ async def getmondetails(event: GroupMessage):
msg = "".join(map(str, event.message_chain[Plain]))

m = re.match(
fr'^{commandpre}(qhyb|雀魂月报)\s*([\w_、,\.,\'\"!]+)\s*([34])?\s*([0-9]{{4}})?[-]?([0-9]{{1,2}})?\s*$', msg.strip())
fr'^{commandpre}(qhyb|雀魂月报)\s*([\w_、,\.,。\'\"!]+)\s*([34])?\s*([0-9]{{4}})?[-]?([0-9]{{1,2}})?\s*$',
msg.strip())
if m:
if qhsettings['qhyb'] and event.group.id not in qhsettings['disybgroup']:
if not cmdbuffer.updategroupcache(groupcommand(event.group.id, event.sender.id, 'qhyb')):
Expand Down Expand Up @@ -533,7 +564,7 @@ async def getqhwatcher(event: GroupMessage):
async def addmajsoulwatch(event: GroupMessage):
msg = "".join(map(str, event.message_chain[Plain]))
# 匹配指令
m = re.match(fr'^{commandpre}(qhadd|雀魂添加关注)\s*([\w_、,\.,\'\"!]+)\s*$', msg.strip())
m = re.match(fr'^{commandpre}(qhadd|雀魂添加关注)\s*([\w_、,\.,\'\"!]+)\s*$', msg.strip())
if m:
if event.group.id not in qhsettings['disautoquerygroup']:
# if is_havingadmin(event):
Expand All @@ -549,7 +580,7 @@ async def addmajsoulwatch(event: GroupMessage):
async def delwatcher(event: GroupMessage):
msg = "".join(map(str, event.message_chain[Plain]))
# 匹配指令
m = re.match(fr'^{commandpre}(qhdel|雀魂删除关注)\s*([\w_、,\.,\'\"!]+)\s*$', msg.strip())
m = re.match(fr'^{commandpre}(qhdel|雀魂删除关注)\s*([\w_、,\.,\'\"!]+)\s*$', msg.strip())
if m:
if event.group.id not in qhsettings['disautoquerygroup']:
# if is_havingadmin(event):
Expand Down Expand Up @@ -637,7 +668,7 @@ async def addmajsoulwatch(event: GroupMessage):
async def addtenhouwatch(event: GroupMessage):
msg = "".join(map(str, event.message_chain[Plain]))
# 匹配指令
m = re.match(fr'^{commandpre}(thpt|天凤pt|天凤分数)\s*([\w_、,,\'\\\.!!]+)\s*$', msg.strip())
m = re.match(fr'^{commandpre}(thpt|天凤pt|天凤分数)\s*([\w_、,,\'\\\.!!]+)\s*$', msg.strip())
if m:

if not cmdbuffer.updategroupcache(groupcommand(event.group.id, event.sender.id, 'thpt')):
Expand All @@ -649,7 +680,7 @@ async def addtenhouwatch(event: GroupMessage):
async def addtenhouwatch(event: GroupMessage):
msg = "".join(map(str, event.message_chain[Plain]))
# 匹配指令
m = re.match(fr'^{commandpre}(thadd|天凤添加关注)\s*([\w_、,,\'\\\.!!]+)\s*$', msg.strip())
m = re.match(fr'^{commandpre}(thadd|天凤添加关注)\s*([\w_、,,\'\\\.!!]+)\s*$', msg.strip())
if m:
if is_havingadmin(event):
await bot.send(event, addthwatch(m.group(2), event.group.id))
Expand All @@ -661,7 +692,7 @@ async def addtenhouwatch(event: GroupMessage):
async def deltenhouwatcher(event: GroupMessage):
msg = "".join(map(str, event.message_chain[Plain]))
# 匹配指令
m = re.match(fr'^{commandpre}(thdel|天凤删除关注)\s*([\w_、,,\'\\\.!!]+)\s*$', msg.strip())
m = re.match(fr'^{commandpre}(thdel|天凤删除关注)\s*([\w_、,,\'\\\.!!]+)\s*$', msg.strip())
if m:
if is_havingadmin(event):
await bot.send(event,
Expand Down Expand Up @@ -973,7 +1004,8 @@ async def diyreply(event: GroupMessage):
m1 = re.match(fr'^{commandpre}我超(\w+)\s*\.', msg.strip())
if m1:
if '呆' not in m1.group(1):
return await bot.send(event,f"考试中 {event.sender.member_name}想抄{m1.group(1)}的答案🥵{m1.group(1)}一直挡着说 不要抄了 不要抄了🥵当时{m1.group(1)}的眼泪都流下来了🥵可是{event.sender.member_name}还是没听{m1.group(1)}说的🥺一直在抄{m1.group(1)}🥵呜呜呜呜🥺 因为卷子是正反面 说亲自动手 趁监考老师不注意的时候把{m1.group(1)}翻到反面 翻来覆去抄{m1.group(1)}🥵抄完前面抄后面🥵🥵🥵")
return await bot.send(event,
f"考试中 {event.sender.member_name}想抄{m1.group(1)}的答案🥵{m1.group(1)}一直挡着说 不要抄了 不要抄了🥵当时{m1.group(1)}的眼泪都流下来了🥵可是{event.sender.member_name}还是没听{m1.group(1)}说的🥺一直在抄{m1.group(1)}🥵呜呜呜呜🥺 因为卷子是正反面 说亲自动手 趁监考老师不注意的时候把{m1.group(1)}翻到反面 翻来覆去抄{m1.group(1)}🥵抄完前面抄后面🥵🥵🥵")

senderid = event.sender.id
if botname == "":
Expand Down
3 changes: 3 additions & 0 deletions start.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@echo off
python main.py
pause
2 changes: 2 additions & 0 deletions start.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
python main.py
exit

0 comments on commit ccbed75

Please sign in to comment.