From 93717fbfc92a64f9427362a1909a8c7e19683e38 Mon Sep 17 00:00:00 2001
From: Syaro <91415593+NekoRabi@users.noreply.github.com>
Date: Sun, 15 May 2022 17:56:14 +0800
Subject: [PATCH] =?UTF-8?q?=E9=85=8D=E7=BD=AE=E6=9B=B4=E6=96=B0=EF=BC=8C?=
=?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=94=99=E5=88=AB=E5=AD=97?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
config/config.yml | 25 ++++++-----
main.py | 40 +++---------------
plugin/MajSoulInfo/majsoulinfo.py | 27 ++++++------
plugin/Setu/setu.py | 12 +++---
plugin/preinit/load_application.py | 66 +++++++++++++++++++-----------
utils/__init__.py | 5 +--
utils/dictshuffle.py | 2 +-
7 files changed, 83 insertions(+), 94 deletions(-)
diff --git a/config/config.yml b/config/config.yml
index 196444b..2172dc3 100644
--- a/config/config.yml
+++ b/config/config.yml
@@ -29,9 +29,14 @@ replyimgpath : 真寻 # 表情包路径
loglevel: INFO # 日志等级
-# 在某群禁用 摸头事件
-disnudgegroup:
- - 0
+# "戳一戳"配置文件
+nudgeconfig:
+ # 在某群禁用 摸头事件
+ disnudgegroup:
+ - 0
+ sendnudgechance: 1 # 被戳时 以 "戳一戳" 还击的概率
+ supersendnudgechance: 0.2 # 还击的"戳一戳"中,触发超级还击的概率
+ supernudgequantity: 10 # 单次超级还击的发送 "戳一戳" 的次数
# 在某群关闭自动回复
norepeatgroup:
@@ -46,7 +51,7 @@ welcomeinfo: # 新人入群欢迎词,%ps%为新人名字,%gn%为群聊名
whitelist:
- 0 # 白名单
-# 开启色图的群聊
+# 色图群聊
setugroups:
- 0
@@ -58,7 +63,7 @@ settings: # 各项开关
setu: false # 色图
silence: false # 全局沉默,降低发言频率
norepeat: false # 全局自动回复
- help: True
+ help: true
repeatconfig: # 回复、打断相关,要求值从上到下排序为从大到小,值为 百分数
repeatQ: 20 # 复读问号 的概率
@@ -75,13 +80,13 @@ qhsettings: # 是否启用
qhpaipu: true
disptgroup: # 在某群禁用 qhpt
- 0
- disinfogroup: # 在某群禁用 qhinfo
+ disinfogroup:
- 0
- disslgroup: # 在某群禁用 qhsl
+ disslgroup:
- 0
- disybgroup: # 在某群禁用 qhyb
+ disybgroup:
- 0
- disautoquerygroup:
+ disautoquerygroup:
- 0
- dispaipugroup: # 在某群禁用 qhpaipu
+ dispaipugroup:
- 0
diff --git a/main.py b/main.py
index abb93a9..4a6b43b 100644
--- a/main.py
+++ b/main.py
@@ -35,7 +35,7 @@
repeatconfig = config['repeatconfig']
norepeatgroup = config['norepeatgroup']
qhsettings = config['qhsettings']
- disnudgegroup = config['disnudgegroup']
+ nudgeconfig = config['nudgeconfig']
stfinder = SetuFinder(botname)
bot = create_bot(config)
@@ -96,36 +96,6 @@ 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)
@@ -1141,7 +1111,7 @@ async def Nudgepetpet(event: NudgeEvent):
return
if (not settings['silence']) or settings['nudgereply']:
if event.subject.kind == 'Group':
- if not (event.subject.id in silencegroup or event.subject.id in disnudgegroup):
+ if not (event.subject.id in silencegroup or event.subject.id in nudgeconfig['disnudgegroup']):
target = event.target
if target == bot.qq:
if sender in admin:
@@ -1154,13 +1124,13 @@ async def Nudgepetpet(event: NudgeEvent):
Image(
path=f'./images/PetPet/temp/tempPetPet-{target}.gif')))
else:
- if random.random() < 0.2:
- if random.random() < 0.2:
+ if random.random() < nudgeconfig['sendnudgechance']:
+ if random.random() < nudgeconfig['supersendnudgechance']:
await bot.send_group_message(event.subject.id,
getreply(
reply=replydata['nudgedata']['supernudgereply'],
rndimg=True))
- for i in range(10):
+ for i in range(nudgeconfig['supernudgequantity']):
await bot.send_nudge(subject=event.subject.id, target=sender, kind='Group')
return
else:
diff --git a/plugin/MajSoulInfo/majsoulinfo.py b/plugin/MajSoulInfo/majsoulinfo.py
index 36d67df..6e5e9c5 100644
--- a/plugin/MajSoulInfo/majsoulinfo.py
+++ b/plugin/MajSoulInfo/majsoulinfo.py
@@ -40,30 +40,26 @@
aiotimeout = aiohttp.ClientTimeout(total=10)
+serverErrorHTML='
503 Service Unavailable
'
-async def asysearchplayer(username, type = "3"):
- if type == "3":
- url = f"https://ak-data-1.sapk.ch/api/v2/pl3/search_player/{username}?limit=20"
- else:
- url = f"https://ak-data-5.sapk.ch/api/v2/pl4/search_player/{username}?limit=20"
-
+async def asysearchqh(url, type="3"):
try:
async with aiohttp.ClientSession(connector=aiohttp.TCPConnector(ssl=False, limit=5), timeout=aiotimeout,
headers={'User-Agent': random.choice(user_agent_list)}) as session:
- if type == "4":
- async with session.get(url) as response:
- text = await response.text()
- return dict(msg=json.loads(text), error=False)
+ async with session.get(url) as response:
+ text = await response.text()
+ return dict(msg=json.loads(text), error=False)
except asyncio.exceptions.TimeoutError as e:
- print(f"雀魂段位查询超时,{e}")
+ print(f"查询超时,{e}")
return dict(msg="查询超时,请再试一次", error=True)
-def getcertaininfo(username: str, selecttype: str = "4", selectindex: int = 0):
+def getcertaininfo(username: str, selecttype: str = "4", selectindex: int = None):
s = requests.Session()
s.mount('http://', HTTPAdapter(max_retries=3))
s.mount('https://', HTTPAdapter(max_retries=3))
-
+ if not selectindex:
+ selectindex = 0
try:
if selecttype == "3":
url = f"https://ak-data-1.sapk.ch/api/v2/pl3/search_player/{username}?limit=20"
@@ -106,7 +102,7 @@ def getcertaininfo(username: str, selecttype: str = "4", selectindex: int = 0):
return "读取超时"
-def getinfo(username: str, selecttype: str = "", selectindex: int = 0):
+def getinfo(username: str, selecttype: str = "4", selectindex: int = 0):
muti3 = False
muti4 = False
headers = {'User-Agent': random.choice(user_agent_list), "Connection": "close"}
@@ -122,6 +118,7 @@ def getinfo(username: str, selecttype: str = "", selectindex: int = 0):
f"https://ak-data-1.sapk.ch/api/v2/pl3/search_player/{username}?limit=20",
headers=headers, timeout=10)
pl3 = eval(xhr3.text)
+
xhr4 = s4.get(
f"https://ak-data-5.sapk.ch/api/v2/pl4/search_player/{username}?limit=20",
headers=headers, timeout=10)
@@ -153,7 +150,7 @@ def getinfo(username: str, selecttype: str = "", selectindex: int = 0):
def getplayerdetail(playername: str, selecttype: str, selectlevel: list = None, model='基本') -> dict:
- if not model in ['基本', '更多', '立直', '血统', 'all']:
+ if model not in ['基本', '更多', '立直', '血统', 'all']:
return dict(msg="参数输入有误哦,可用的参数为'基本'、'更多'、'立直'、'血统'、'all'", error=True)
cx = sqlite3.connect('./database/MajSoulInfo/majsoul.sqlite')
diff --git a/plugin/Setu/setu.py b/plugin/Setu/setu.py
index 3233ee9..b416769 100644
--- a/plugin/Setu/setu.py
+++ b/plugin/Setu/setu.py
@@ -61,9 +61,9 @@ async def getsetuinfo(description: str, num: int) -> dict:
return text
-class setufinder:
+class SetuFinder:
- def __init__(self,botname):
+ def __init__(self, botname):
with open(r'./config/Setu/config.yml') as f:
config = yaml.safe_load(f)
self.r18setting = config['r18setting']
@@ -77,7 +77,7 @@ def keyword_transform(self, keywords: str, value):
elif keywords == "tag":
tag = ""
for v in value:
- tag += f"{value}"
+ tag += f"{v}"
return tag
def getsetu(self, description, groupid, num=1) -> dict:
@@ -86,15 +86,15 @@ def getsetu(self, description, groupid, num=1) -> dict:
if description:
if 'r18' in description or 'R18' in description:
if groupid not in self.r18groups:
- imginfo = dict(FoundError=True,ErrorMsg="本群未开启R18")
+ imginfo = dict(FoundError=True, ErrorMsg="本群未开启R18")
return imginfo
if self.botname in description and not self.allowsearchself:
- return dict(FoundError=True,ErrorMsg="不许搜咱的图")
+ return dict(FoundError=True, ErrorMsg="不许搜咱的图")
content = finish_all_asytasks([getsetuinfo(description, num)])
response = content[0]
if len(response['data']) == 0:
- imginfo = dict(FoundError=True,ErrorMsg="没找到这样的图片呢")
+ imginfo = dict(FoundError=True, ErrorMsg="没找到这样的图片呢")
else:
imginfo: dict = response['data'][0]
imginfo['FoundError'] = False
diff --git a/plugin/preinit/load_application.py b/plugin/preinit/load_application.py
index 80d6244..dc78076 100644
--- a/plugin/preinit/load_application.py
+++ b/plugin/preinit/load_application.py
@@ -1,7 +1,7 @@
import yaml
import os
import json
-from utils.text_to_img import whitebgk_blacktext
+from utils.text_to_img import text_to_image
config = {}
replydata = {}
@@ -9,7 +9,7 @@
def load_config() -> dict:
try:
- with open(r'./config/config.yml') as f:
+ with open(r'./config/config.yml', encoding="gbk") as f:
config = yaml.safe_load(f)
for k, v in config.items():
print(k, v)
@@ -25,7 +25,7 @@ def load_config() -> dict:
repeatconfig = config['repeatconfig']
norepeatgroup = config['norepeatgroup']
qhsettings = config['qhsettings']
- disnudgegroup = config['disnudgegroup']
+ nudgeconfig = config['nudgeconfig']
loglevel = config['loglevel']
replydata['replyimgpath'] = config['replyimgpath']
master = config['master']
@@ -38,7 +38,7 @@ def load_config() -> dict:
except Exception as e:
print(f'{e} 缺失')
print("文件打开错误,尝试生成初始文件中...")
- with open(r'./config.yml', 'w') as f:
+ with open(r'./config.yml', 'w', encoding="gbk") as f:
yaml.dump(dict(admin=[0], whitelist=[0], blacklist=[0], mutegrouplist=[0], setugroups=[0],
welcomeinfo=["欢迎%ps%加入%gn%"], alarmclockgroup=[0],
silencegroup=[0], norepeatgroup=[0], disnudgegroup=[0], commandpre="", searchfrequency=6,
@@ -106,23 +106,41 @@ def load_replydata() -> dict:
def create_helpimg():
- helptext = "指令帮助 ()内为可选项,[]为必选项,{}为可用参数,<>为类型:\n" \
- "qhpt / 雀魂分数 / 雀魂pt [玩家名] (3/4) (序号):查询该玩家的段位分\n" \
- "qhsl / 雀魂十连 ({限时/常驻}) :来一次模拟雀魂十连\n" \
- "qhadd / 雀魂添加关注 [玩家名] :将一个玩家添加至雀魂自动查询,有新对局记录时会广播\n" \
- "qhgetwatch / 雀魂获取本群关注 :获取本群所有的雀魂关注的玩家\n" \
- "qhdel / 雀魂删除关注 [玩家名] :将一个玩家从雀魂自动查询中移除,不再自动广播对局记录\n" \
- "qhpaipu / 雀魂最近对局 [玩家名] [{3/4}] ({1-10}) :查询一个玩家最近n场3/4人对局记录\n" \
- "qhinfo / 雀魂玩家详情 [玩家名] [{3/4}] ({基本/立直/血统/all}):查询一个玩家的详细数据\n" \
- "qhyb / 雀魂月报 [玩家名] [{3/4}] [yyyy-mm] :查询一个玩家yy年mm月的3/4麻对局月报\n" \
- "thpt / 天凤pt / 天凤分数 [玩家名] : 查询玩家的天凤pt ( 但该功能还存在问题\n" \
- "thadd / 天凤添加关注 [玩家名] :将一个玩家添加指天凤的自动查询,有新对局会广播\n" \
- "thdel / 天凤删除关注 [玩家名] :将一个玩家从天凤自动查询中移除,不再自动广播对局记录\n" \
- "举牌 [<文本>] :将文本写在举牌小人上发出来,最多40字\n" \
- "亲/亲亲 @用户 : 两人互亲\n" \
- "摸/摸摸/摸头 @用户 : 摸某人头\n" \
- "重开 / remake : 异世界转生\n" \
- "bw [<文本>] [<图片>] : 返回一张黑白处理后的图片,底部有一行文字\n" \
- "签到 : 顾名思义,就是签到\n" \
- "项目地址 : 获取项目链接\n"
- whitebgk_blacktext(path='help.png', text=helptext)
+ grouphelp = "指令帮助 ()内为可选项,[]为必选项,{}为可用参数,<>为类型:\n" \
+ "qhpt / 雀魂分数 / 雀魂pt [玩家名] (3/4) (序号):查询该玩家的段位分\n" \
+ "qhsl / 雀魂十连 ({限时/常驻}) :来一次模拟雀魂十连\n" \
+ "qhadd / 雀魂添加关注 [玩家名] :将一个玩家添加至雀魂自动查询,有新对局记录时会广播\n" \
+ "qhgetwatch / 雀魂获取本群关注 :获取本群所有的雀魂关注的玩家\n" \
+ "qhdel / 雀魂删除关注 [玩家名] :将一个玩家从雀魂自动查询中移除,不再自动广播对局记录\n" \
+ "qhpaipu / 雀魂最近对局 [玩家名] [{3/4}] ({1-10}) :查询一个玩家最近n场3/4人对局记录\n" \
+ "qhinfo / 雀魂玩家详情 [玩家名] [{3/4}] ({基本/立直/血统/all}):查询一个玩家的详细数据\n" \
+ "qhyb / 雀魂月报 [玩家名] [{3/4}] [yyyy-mm] :查询一个玩家yy年mm月的3/4麻对局月报\n" \
+ "thpt / 天凤pt / 天凤分数 [玩家名] : 查询玩家的天凤pt ( 但该功能还存在问题\n" \
+ "thadd / 天凤添加关注 [玩家名] :将一个玩家添加指天凤的自动查询,有新对局会广播\n" \
+ "thdel / 天凤删除关注 [玩家名] :将一个玩家从天凤自动查询中移除,不再自动广播对局记录\n" \
+ "thgetwatch / 天凤获取本群关注 :获取本群所有的天凤关注的玩家\n" \
+ "举牌 [<文本>] :将文本写在举牌小人上发出来,最多40字\n" \
+ "亲/亲亲 @用户 : 两人互亲\n" \
+ "[A]鸡打. / 我超[A]. : 返回一段主体为A发病文\n" \
+ "摸/摸摸/摸头 @用户 : 摸某人头\n" \
+ "重开 / remake : 异世界转生\n" \
+ "bw [<文本>] [<图片>] : 返回一张黑白处理后的图片,底部有一行文字\n" \
+ "签到 : 顾名思义,就是签到\n" \
+ "项目地址 : 获取项目链接\n"
+ adminhelp = "私聊指令:\n" \
+ "addadmin / deladmin QQ号 :添加或者删除机器人管理员\n" \
+ "addwhitelist /delwhitelist QQ号 :修改白名单\n" \
+ "addblacklist / delblacklist QQ: 修改黑名单\n" \
+ "ping :ping一下服务器,用于验证机器人存活\n" \
+ "silence on/true/off/false :开启全局沉默模式,减少信息输出\n" \
+ "freshqh : 刷新本地雀魂牌谱数据库\n" \
+ "群管理指令:\n" \
+ "open/enable/开启 涩图/色图/setu : 开启本群色图功能\n" \
+ "close/disable/关闭 涩图/色图/setu : 关闭本群色图\n" \
+ "disable/enable 【雀魂指令】 :关闭本群某项雀魂功能\n" \
+ "silence on/true/off/false :开启本群沉默模式,减少信息输出\n" \
+ "norepeat on/true/…… : 开启或关闭本群复读功能\n" \
+ "" \
+ "项目地址 : 获取项目链接\n"
+ text_to_image(path='help.png', text=grouphelp)
+ text_to_image(path='adminhelp.png',text=adminhelp)
diff --git a/utils/__init__.py b/utils/__init__.py
index 3aebae7..f2f718a 100644
--- a/utils/__init__.py
+++ b/utils/__init__.py
@@ -1,4 +1,3 @@
-from utils.dictshuffle import ditc_shuffle
-from utils.Logger import create_logger,getQQlogger
+from utils.Logger import create_logger, getQQlogger
from utils.bufferpool import msgbufferpool
-from utils.text_to_img import *
\ No newline at end of file
+from utils.text_to_img import *
diff --git a/utils/dictshuffle.py b/utils/dictshuffle.py
index 719007d..a6f3b7a 100644
--- a/utils/dictshuffle.py
+++ b/utils/dictshuffle.py
@@ -1,7 +1,7 @@
import random
# 一个无效的字典乱序方法
-def ditc_shuffle(dicts:dict):
+def dict_shuffle(dicts:dict):
dict_key_ls = list(dicts.keys())
random.shuffle(dict_key_ls)
new_dict = {}