Skip to content

Commit

Permalink
修复了色图问题
Browse files Browse the repository at this point in the history
  • Loading branch information
NekoRabi authored May 2, 2022
1 parent 13c6c31 commit 5e82f50
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 21 deletions.
43 changes: 34 additions & 9 deletions command_help.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# 指令面板
```
help / 帮助
```
使用 `help`或者`帮助`来呼出指令面板

# 私聊命令

```
Expand Down Expand Up @@ -67,7 +73,7 @@ norepeat on/true/任意
### **最重要的指令 `qhpt`**

```
qhpt / 雀魂分数 [玩家名] ({3/4}) (index)
qhpt / 雀魂分数 / 雀魂pt [玩家名] ({3/4}) (index)
```

查询该玩家的雀魂段位分 ( 最后两个参数一般不需要,下面会给出使用实例 )
Expand Down Expand Up @@ -160,6 +166,10 @@ freshqh

## 天凤相关

```
thpt / 天凤分数 / 天凤pt [玩家名]
```
查天凤分数 **该功能存在bug,是实验性功能**
```
thadd [玩家名]
```
Expand Down Expand Up @@ -246,12 +256,27 @@ bw [文字] [图片]

发送一段内容主体为A的文字 **( 不要漏掉 '点' `.`)**

<hr>

```
open/enable/开启 涩图/色图/setu
```
在本群开启色图

```
close|disable|关闭 涩图 / 色图 / setu
```
在本群关闭色图

<details>
<summary>其他</summary>
<h3>色色 (默认关闭)</h3>
<pre><code>
setu/涩图/色图 (tag)
</code></pre>
从<a href="https://api.lolicon.app/#/setu">网站</a>请求一份(指定tag的)色图
</details>
色图两种请求方式

第一种:
```
色图 / 涩图 /setu (tag)
```
第二种直接写正则了: 来(1|一)?(张|份)(\w+)?\s*(的)?\s*(色图|涩图)\s*$
```
来张色图
```
**该功能默认关闭**
59 changes: 54 additions & 5 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,19 +312,68 @@ async def forceAt(event: GroupMessage):
return await bot.send(event, MessageChain([At(target), Plain(f" {m.group(1)}")]))


@bot.on(GroupMessage)
async def enablesetu(event: GroupMessage):
msg = "".join(map(str, event.message_chain[Plain]))
m = re.match(fr'^{commandpre}(open|enable|开启)\s*(涩图|色图|setu)\s*$', msg.strip())
if m:
if is_havingadmin(event):
groupid = event.group.id
if groupid in config['setugroups']:
await bot.send(event, getreply(text="本群已开启色图",rndimg=True))
else:
config['setugroups'].append(groupid)
with open(r'./config.yml', 'w') as file:
yaml.dump(config, file, allow_unicode=True)
await bot.send(event, getreply(text="色图开启成功", rndimg=True))

@bot.on(GroupMessage)
async def disablesetu(event: GroupMessage):
msg = "".join(map(str, event.message_chain[Plain]))

m = re.match(fr'^{commandpre}(close|disable|关闭)\s*(涩图|色图|setu)\s*$', msg.strip())
if m:
if is_havingadmin(event):
groupid = event.group.id
if groupid in config['setugroups']:
config['setugroups'].remove(groupid)
with open(r'./config.yml', 'w') as file:
yaml.dump(config, file, allow_unicode=True)
await bot.send(event, getreply(text="色图已关闭",rndimg=True))
else:
await bot.send(event, getreply(text="本群色图已关闭", rndimg=True))

@bot.on(GroupMessage)
async def setu(event: GroupMessage):
msg = "".join(map(str, event.message_chain[Plain]))
# 匹配指令
m1 = re.match(fr'^{commandpre}(色图|涩图|setu)\s*(\w+)?\s*$', msg.strip())
m2 = re.match(fr"^{commandpre}来张(r18)?\s*(的)?\s*(色图|涩图)\s*$", msg.strip())
m2 = re.match(fr"^{commandpre}来张(\w+)?\s*(的)?\s*(色图|涩图)\s*$", msg.strip())
if m1:
if random.random() * 100 < 10:
print(f"发出对{event.sender.id}的少冲提醒")
await bot.send(event, [At(event.sender.id), " 能不能少冲点啊"])
await bot.send(event, [At(event.sender.id), " 能不能少冲点啊,这次就不给你发了"])
else:
if settings['setu'] and event.group.id in settings['setugroups']:
imginfo = getsetu(m1.group(2).strip())
if settings['setu'] and event.group.id in config['setugroups']:
imginfo = getsetu(m1.group(2))
if imginfo['notFound']:
await bot.send(event, getreply(text="没找到该图片呢"))
return
try:
await bot.send(event, MessageChain([Image(url=imginfo['url'])]))
except Exception as e:
print(f"色图请求失败:{e}")
await bot.send(event, MessageChain([Plain(f"出错了!这肯定不是{botname}的问题!")]))
elif m2:
if random.random() * 100 < 10:
print(f"发出对{event.sender.id}的少冲提醒")
await bot.send(event, [At(event.sender.id), " 能不能少冲点啊,这次就不给你发了"])
else:
if settings['setu'] and event.group.id in config['setugroups']:
imginfo = getsetu(m2.group(1))
if imginfo['notFound']:
await bot.send(event, getreply(text="没找到该图片呢"))
return
try:
await bot.send(event, MessageChain([Image(url=imginfo['url'])]))
except Exception as e:
Expand Down Expand Up @@ -480,7 +529,7 @@ async def getplayerdetails(event: GroupMessage):
msg = "".join(map(str, event.message_chain[Plain]))

m = re.match(
fr'^{commandpre}(qhinfo|雀魂玩家详情)\s*([\w_、,\.,\'\"!]+)\s*(\w+)*\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
19 changes: 12 additions & 7 deletions plugin/Setu/setu.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def getsetuinfo(requiretarget: dict) -> dict:
keyword_transform(k, v)


def getsetu(tag: str="") -> dict:
def getsetu(tag: str = "") -> dict:
user_agent_list = [
"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36",
"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36",
Expand All @@ -51,16 +51,21 @@ def getsetu(tag: str="") -> dict:
s = requests.Session()
s.mount('http://', HTTPAdapter(max_retries=3))
s.mount('https://', HTTPAdapter(max_retries=3))
if tag == "":
if tag:
response = s.get(
f"https://api.lolicon.app/setu/v2",
f"https://api.lolicon.app/setu/v2?tag={tag}",
headers={'User-Agent': random.choice(user_agent_list)})
else:
response = s.get(
f"https://api.lolicon.app/setu/v2?tag={tag}",
f"https://api.lolicon.app/setu/v2",
headers={'User-Agent': random.choice(user_agent_list)})
response = response.text
response = eval(response.replace("false","False"))
imginfo: dict = response['data'][0]
imginfo['url'] = imginfo['urls']['original'].replace("cat","re")
response = eval(response.replace("false", "False"))
print(response)
if len(response['data']) == 0:
imginfo = dict(notFound=True)
else:
imginfo: dict = response['data'][0]
imginfo['notFound'] = False
imginfo['url'] = imginfo['urls']['original'].replace("cat", "re")
return imginfo

0 comments on commit 5e82f50

Please sign in to comment.