Skip to content

Commit

Permalink
配置更新,修改错别字
Browse files Browse the repository at this point in the history
  • Loading branch information
NekoRabi authored May 15, 2022
1 parent b4adc23 commit 93717fb
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 94 deletions.
25 changes: 15 additions & 10 deletions config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,14 @@ replyimgpath : 真寻 # 表情包路径

loglevel: INFO # 日志等级

# 在某群禁用 摸头事件
disnudgegroup:
- 0
# "戳一戳"配置文件
nudgeconfig:
# 在某群禁用 摸头事件
disnudgegroup:
- 0
sendnudgechance: 1 # 被戳时 以 "戳一戳" 还击的概率
supersendnudgechance: 0.2 # 还击的"戳一戳"中,触发超级还击的概率
supernudgequantity: 10 # 单次超级还击的发送 "戳一戳" 的次数

# 在某群关闭自动回复
norepeatgroup:
Expand All @@ -46,7 +51,7 @@ welcomeinfo: # 新人入群欢迎词,%ps%为新人名字,%gn%为群聊名
whitelist:
- 0 # 白名单

# 开启色图的群聊
# 色图群聊
setugroups:
- 0

Expand All @@ -58,7 +63,7 @@ settings: # 各项开关
setu: false # 色图
silence: false # 全局沉默,降低发言频率
norepeat: false # 全局自动回复
help: True
help: true

repeatconfig: # 回复、打断相关,要求值从上到下排序为从大到小,值为 百分数
repeatQ: 20 # 复读问号 的概率
Expand All @@ -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
40 changes: 5 additions & 35 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down
27 changes: 12 additions & 15 deletions plugin/MajSoulInfo/majsoulinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,30 +40,26 @@

aiotimeout = aiohttp.ClientTimeout(total=10)

serverErrorHTML='<html><body><h1>503 Service Unavailable</h1>'

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"
Expand Down Expand Up @@ -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"}
Expand All @@ -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)
Expand Down Expand Up @@ -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')

Expand Down
12 changes: 6 additions & 6 deletions plugin/Setu/setu.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand All @@ -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:
Expand All @@ -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
Expand Down
66 changes: 42 additions & 24 deletions plugin/preinit/load_application.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
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 = {}


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)
Expand All @@ -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']
Expand All @@ -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,
Expand Down Expand Up @@ -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)
5 changes: 2 additions & 3 deletions utils/__init__.py
Original file line number Diff line number Diff line change
@@ -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 *
from utils.text_to_img import *
2 changes: 1 addition & 1 deletion utils/dictshuffle.py
Original file line number Diff line number Diff line change
@@ -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 = {}
Expand Down

0 comments on commit 93717fb

Please sign in to comment.