File tree 2 files changed +11
-30
lines changed
2 files changed +11
-30
lines changed Original file line number Diff line number Diff line change @@ -68,21 +68,18 @@ async def handle_message(event: MessageEvent):
68
68
else :
69
69
await event .reply (Image (img_url [0 ]), quote = False )
70
70
elif parts :
71
- match = re .match (r'来(\d+|零|两|一|二|三|四|五|六|七|八|九)(张|份)(色图|涩图) ' , parts [ 0 ] )
71
+ match = re .match (r'[色涩]图 *([\d零两一二三四五六七八九])[张份](.*) ' , message )
72
72
if match :
73
73
quantity = match .group (1 )
74
- try :
75
- num = int (quantity )
76
- except :
74
+ if quantity in '零两一二三四五六七八九' :
77
75
num = int (c2d .chineseToDigits (quantity ))
78
- tag = parts [1 :] if len (parts ) > 1 else None
76
+ else :
77
+ num = int (quantity )
78
+ tag = match .group (2 )
79
79
logger .info (f"数量: { num } , 标签: { tag } " )
80
80
img_url = await fetch_and_save_image (tag , num )
81
81
if img_url is None :
82
82
await event .reply ("图库查找无结果" , quote = True )
83
83
else :
84
- index = 1
85
- for i_url in img_url :
86
- logger .info (f"第{ index } 份色图发送中" )
87
- index += 1
88
- await event .reply (Image (i_url ), quote = False )
84
+ images = [Image (url ) for url in img_url ]
85
+ await event .reply (images )
Original file line number Diff line number Diff line change 1
- import re
2
-
3
1
import aiohttp
4
2
5
3
from anon .event import MessageEvent
@@ -30,21 +28,7 @@ async def fetch_and_save_image(limit: bool = False) -> list:
30
28
31
29
@pm .register_event ([MessageEvent ])
32
30
async def cat (event : MessageEvent ):
33
- message = event .msg .text ()
34
- if re .fullmatch (r'喵+' , message ):
35
- # 计算“喵”的数量
36
- count = len (message ) // len ('喵' )
37
- if count == 1 :
38
- img_url = await fetch_and_save_image (False )
39
- logger .info ('喵' )
40
- elif count > 1 :
41
- img_url = await fetch_and_save_image (True )
42
- await event .reply ("不管多少个喵,只要大于1个都会返回10张图的喵~" , quote = True )
43
- logger .info (f'收到了{ count } 个喵!' )
44
- else :
45
- return
46
- index = 1
47
- for i_url in img_url :
48
- logger .info (f"第{ index } 份猫图发送中" )
49
- index += 1
50
- await event .reply (Image (i_url ), quote = False )
31
+ count = event .raw .count ('喵' )
32
+ if count :
33
+ img_urls = await fetch_and_save_image (False if count == 1 else True )
34
+ await event .reply ([Image (url ) for url in img_urls ][:count ])
You can’t perform that action at this time.
0 commit comments