Skip to content

Commit b6f6207

Browse files
committed
修复bug,新增部分事件响应
1 parent b44b234 commit b6f6207

4 files changed

Lines changed: 79 additions & 45 deletions

File tree

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,10 @@ $senduserimage QQ$
143143

144144

145145
### 更新日志
146+
0.1.10
147+
- 修复了在指令为戳.*时会与戳一戳事件标识产生奇妙的化学反应而导致报错的问题
148+
- 新增入群申请的函数
149+
146150
0.1.9
147151
- 新增获取艾特对象的QQ的函数
148152
- 新增戳一戳函数

nonebot_plugin_SimpleToWrite/__init__.py

Lines changed: 71 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import re
2-
from nonebot.adapters.onebot.v11 import MessageSegment,GroupMessageEvent,Event, PokeNotifyEvent, NotifyEvent, PrivateMessageEvent, PrivateMessageEvent, GroupIncreaseNoticeEvent
3-
from nonebot import on_message, on_notice
2+
from nonebot.adapters.onebot.v11 import MessageSegment,GroupMessageEvent,Event, PokeNotifyEvent, NotifyEvent, PrivateMessageEvent, PrivateMessageEvent, GroupIncreaseNoticeEvent, GroupRequestEvent
3+
from nonebot import on_message, on_notice, on_request
44
from pathlib import Path
55
import nonebot
66
from nonebot.rule import is_type
@@ -287,10 +287,15 @@ async def getusername(a, event, data):
287287
name = result['nickname']
288288
return name
289289
except nonebot.adapters.onebot.v11.exception.ActionFailed:
290-
logger.opt(colors=True).error(
291-
f"<yellow>错误!</yellow> <blue>无法获取</blue> <red>群成员</red> {a} <red>不存在</red>"
292-
)
293-
return None
290+
try:
291+
result = await bot.get_stranger_info(user_id=event.user_id)
292+
name = name['nickname']
293+
return name
294+
except nonebot.adapters.onebot.v11.exception.ActionFailed:
295+
logger.opt(colors=True).error(
296+
f"<yellow>错误!</yellow> <blue>无法获取</blue> <red>群成员</red> {a} <red>不存在</red>"
297+
)
298+
return None
294299
else:
295300
result = await bot.get_group_member_info(group_id=event.group_id,user_id=event.user_id)
296301
name = result['card']
@@ -622,16 +627,22 @@ async def parse_string(s,event,data):
622627

623628
return result
624629

630+
event_rule = ['[戳一戳]','[入群通知]','[加群请求]']
631+
625632
def poke(event: Event):
626633
return isinstance(event, PokeNotifyEvent)
627634

628635
def groupadd(event: Event):
629636
return isinstance(event, GroupIncreaseNoticeEvent)
630637

638+
def groupwantadd(event: Event):
639+
return isinstance(event, GroupRequestEvent)
640+
631641
grouprequest = on_message(rule=is_type(GroupMessageEvent))
632642
privaterequest = on_message(rule=is_type(PrivateMessageEvent))
633643
pokeevent=on_notice(rule=poke)
634644
groupaddevent=on_notice(rule=groupadd)
645+
groupwantaddevent=on_request(rule=groupwantadd)
635646

636647
@grouprequest.handle()
637648
async def _(event: GroupMessageEvent):
@@ -642,7 +653,7 @@ async def _(event: GroupMessageEvent):
642653
result = parse_string(s,event,qua)
643654
for key in result:
644655
match_data = re.search(rf'^{key}$', qua)
645-
if match_data:
656+
if match_data and key not in event_rule:
646657
result = result[key]
647658
data = match_data.groups()
648659
ans = ""
@@ -669,7 +680,7 @@ async def _(event: PrivateMessageEvent):
669680
result = parse_string(s,event,qua)
670681
for key in result:
671682
match_data = re.search(rf'^{key}$', qua)
672-
if match_data:
683+
if match_data and key not in event_rule:
673684
result = result[key]
674685
data = match_data.groups()
675686
ans = ""
@@ -689,44 +700,60 @@ async def _(event: PrivateMessageEvent):
689700

690701
@pokeevent.handle()
691702
async def _(event: NotifyEvent):
692-
if event.group_id == 809613000:
693-
file_path = 'dicpro.txt'
694-
695-
s = parse_file(file_path)
696-
s = s.replace('$', '&#36;')
697-
698-
result = await parse_string(s,event,data=None)
699-
if "[戳一戳]" in result:
700-
result = result["[戳一戳]"]
701-
ans = ""
702-
if len(result) != 0:
703-
for i in range(len(result)):
704-
key = result[i]
705-
match = re.search(r'^&#36;(\w+)\s+(.+)&#36;$', key)
706-
data = ""
707-
if match:
708-
func_name, param = match.groups()
709-
ans += await my_function(func_name, param, event,data)
710-
await pokeevent.send(ans)
703+
file_path = 'dicpro.txt'
704+
s = parse_file(file_path)
705+
s = s.replace('$', '&#36;')
706+
result = await parse_string(s,event,data=None)
707+
if "[戳一戳]" in result:
708+
result = result["[戳一戳]"]
709+
ans = ""
710+
if len(result) != 0:
711+
for i in range(len(result)):
712+
key = result[i]
713+
match = re.search(r'^&#36;(\w+)\s+(.+)&#36;$', key)
714+
data = ""
715+
if match:
716+
func_name, param = match.groups()
717+
ans += await my_function(func_name, param, event,data)
718+
await pokeevent.send(ans)
711719

712720
@groupaddevent.handle()
713721
async def _(event: GroupIncreaseNoticeEvent):
714-
if event.group_id == 809613000:
715-
file_path = 'dicpro.txt'
722+
file_path = 'dicpro.txt'
723+
s = parse_file(file_path)
724+
s = s.replace('$', '&#36;')
716725

717-
s = parse_file(file_path)
718-
s = s.replace('$', '&#36;')
726+
result = await parse_string(s,event,data=None)
727+
if "[入群通知]" in result:
728+
result = result["[入群通知]"]
729+
ans = ""
730+
if len(result) != 0:
731+
for i in range(len(result)):
732+
key = result[i]
733+
match = re.search(r'^&#36;(\w+)\s+(.+)&#36;$', key)
734+
data = ""
735+
if match:
736+
func_name, param = match.groups()
737+
ans += await my_function(func_name, param, event,data)
738+
await pokeevent.send(ans)
719739

720-
result = await parse_string(s,event,data=None)
721-
if "[入群通知]" in result:
722-
result = result["[入群通知]"]
723-
ans = ""
724-
if len(result) != 0:
725-
for i in range(len(result)):
726-
key = result[i]
727-
match = re.search(r'^&#36;(\w+)\s+(.+)&#36;$', key)
728-
data = ""
729-
if match:
730-
func_name, param = match.groups()
731-
ans += await my_function(func_name, param, event,data)
732-
await pokeevent.send(ans)
740+
@groupwantaddevent.handle()
741+
async def _(event: GroupRequestEvent):
742+
file_path = 'dicpro.txt'
743+
744+
s = parse_file(file_path)
745+
s = s.replace('$', '&#36;')
746+
747+
result = await parse_string(s,event,data=None)
748+
if "[加群请求]" in result:
749+
result = result["[加群请求]"]
750+
ans = ""
751+
if len(result) != 0:
752+
for i in range(len(result)):
753+
key = result[i]
754+
match = re.search(r'^&#36;(\w+)\s+(.+)&#36;$', key)
755+
data = ""
756+
if match:
757+
func_name, param = match.groups()
758+
ans += await my_function(func_name, param, event,data)
759+
await groupwantaddevent.send(ans)

nonebot_plugin_SimpleToWrite/teach/教学文件/变量大全/文字.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ $getselfid QQ$ 作用:获取botid
3838

3939
[入群通知] 作用:事件响应处理 方法和[戳一戳]一样,就不写单独的教程了,看戳一戳的就行了
4040

41+
[加群请求] 作用:事件响应处理 方法和[戳一戳]一样,就不写单独的教程了,看戳一戳的就行了
42+
4143
$getgroupname 任意参数$ 作用:获取触发指令的群名称(不识别参数)
4244

4345
$getusername QQ(或指定QQ号)$ 作用:获取在当前群内指定QQ的昵称
@@ -48,5 +50,6 @@ $getat n$ 作用:获取艾特对象的QQ号(返回正则后第n+1个艾特
4850

4951
$sendpoke QQ(或指定QQ号)$ 作用:发送对群内指定QQ号的戳一戳(llob最新版本可支持主动戳一戳)
5052

53+
5154
##仅对要进行特殊说明的函数做单独讲解
5255
作者:STES沐霖韵

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "nonebot_plugin_SimpleToWrite"
3-
version = "0.1.9"
3+
version = "0.1.10"
44
description = "为0编程基础的小白提供便捷的功能编写"
55
authors = [
66
{ name="STESmly", email="STESmly@mail.com" },

0 commit comments

Comments
 (0)