1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
|
import os
import re
import time
import json
import sqlite3
import aiohttp
from urllib.parse import urlencode
from random import choice, randint
from pathlib import Path
from datetime import datetime
from random import choice
import nonebot
from nonebot import on_command, CommandSession
from nonebot.helpers import send_to_superusers
import config
from ATRI.modules.error import errorBack
from ATRI.modules.b64 import b64_str_img_url
from ATRI.modules.response import request_api_params
from ATRI.modules.funcControl import checkSwitch, checkNoob
bot = nonebot.get_bot()
master = config.SUPERUSERS
apikey_LOLI = config.LoliconAPI
APP_ID = config.BaiduApiID
API_KEY = config.BaiduApiKEY
SECRECT_KEY = config.BaiduApiSECRET
__plugin_name__ = "setu"
__plugin_name1__ = "setu_img"
URL = 'https://api.lolicon.app/setu/'
SETU_REPLY = """Title: {title}
Pid: {pid}
{setu}
---------------
Complete time:{time}s"""
def now_time():
now_ = datetime.now()
hour = now_.hour
minute = now_.minute
now = hour + minute / 60
return now
setu_type = 1
@on_command('setu', patterns = (r"来[点丶张份副个幅][涩色瑟][图圖]|[涩色瑟][图圖]来|[涩色瑟][图圖][gkd|GKD|搞快点]|[gkd|GKD|搞快点][涩色瑟][图圖]|[图圖]来|[我你她他它]想要[点丶张份副][涩色瑟][图圖]|我想要[1一][张份幅副个只][涩色瑟][图圖]|[我你她他它]想[看|look][涩涩|色色]的东西"), only_to_me = False)
async def setu(session: CommandSession):
start = time.perf_counter()
user = session.event.user_id
group = session.event.group_id
if checkNoob(user, group):
if 0 <= now_time() < 5.5:
await session.send(
choice(
[
'zzzz......',
'zzzzzzzz......',
'zzz...好涩哦..zzz....',
'别...不要..zzz..那..zzz..',
'嘻嘻..zzz..呐~..zzzz..'
]
)
)
else:
if checkSwitch(__plugin_name__, group):
res = randint(1,10)
if 1 <= res <= 9:
res = randint(1,4)
if 1 <= res <= 3:
if setu_type == 1:
res = randint(1,5)
await session.send('别急!正在找图!')
con = sqlite3.connect(Path('.') / 'ATRI' / 'data' / 'sqlite' / 'setu' / 'nearR18.db')
cur = con.cursor()
msg = cur.execute('SELECT * FROM nearR18 ORDER BY RANDOM() limit 1;')
if 1 <= res <= 4:
for i in msg:
pid = i[0]
title = i[1]
img = i[7]
end = time.perf_counter()
await session.send(
SETU_REPLY.format(
title = title,
pid = pid,
setu = img,
time = round(end - start, 3)
)
)
elif res == 5:
for i in msg:
pid = i[0]
title = i[1]
img = i[7]
end = time.perf_counter()
await session.send('我找到涩图了!但我发给主人了\nο(=•ω<=)ρ⌒☆')
await send_to_superusers(
bot,
message = f"主人,从群{group}来的涩图!热乎着!\nTitle: {title}\nPid: {pid}\n{img}\nComplete time: {round(end - start, 3)}"
)
elif setu_type == 2:
res = randint(1,5)
await session.send('别急!正在找图!')
start = time.perf_counter()
values = {
"apikey": apikey_LOLI,
"r18": "0",
"num": "1"
}
try:
dc = json.loads(request_api_params(URL, values))
title = dc["data"][0]["title"]
pid = dc["data"][0]["pid"]
setu = dc["data"][0]["url"] #b64.b64_str_img_url(dc["data"][0]["url"])
except:
session.finish(errorBack('请求数据失败'))
if 1 <= res <= 4:
end = time.perf_counter()
await session.send(
SETU_REPLY.format(
title = title,
pid = pid,
setu = dc["data"][0]["url"],
time = round(end - start, 3)
)
)
elif res == 5:
end = time.perf_counter()
await session.send('我找到涩图了!但我发给主人了\nο(=•ω<=)ρ⌒☆')
await send_to_superusers(
bot,
message = f"主人,从群{group}来的涩图!热乎着!\nTitle: {title}\nPid: {pid}\n{setu}\nComplete time: {round(end - start, 3)}"
)
elif res == 4:
img = choice(
[
'SP.jpg', 'SP1.jpg', 'SP2.jpg'
]
)
img = Path('.') / 'ATRI' / 'data' / 'emoji' / f'{img}'
img = os.path.abspath(img)
await session.send(f'[CQ:image,file=file:///{img}]')
elif res == 10:
img = choice(
[
'GDZ.png', 'SHZY1.jpg', 'SHZY2.jpg', 'SHZY3.jpg', 'SHZY4.jpg', 'SHZY5.jpg', 'SHZY6.jpg'
]
)
img = Path('.') / 'ATRI' / 'data' / 'img' / 'niceIMG' / f'{img}'
img = os.path.abspath(img)
await session.send(f'[CQ:image,file=file:///{img}]')
else:
await session.send('该功能已关闭...')
@on_command('change_setu_type', aliases = ['涩图导向'], only_to_me = False)
async def _(session: CommandSession):
global setu_type
if session.event.user_id == master:
msg = session.event.raw_message.split(' ', 1)
s_type = msg[1]
if s_type == '数据库':
setu_type = 1
elif s_type == '接口':
setu_type = 2
else:
session.finish('请检查输入~~~(')
await session.send('okay~~~~')
@bot.on_message("group")
async def _(context):
start = time.perf_counter()
user = context["user_id"]
group = context["group_id"]
if checkNoob(user, group):
if checkSwitch(__plugin_name1__, group):
try:
img = str(context["message"])
pattern = re.compile(r"url=(.*)]")
img = re.findall(pattern, img)
img = img[0].replace('url=', '')
img = img.replace(']', '')
print(img)
except:
return
try:
img = b64_str_img_url(img)
print('转换图片至base64成功')
except:
return
try:
host = f'https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id={API_KEY}&client_secret={SECRECT_KEY}'
headers = {
'Content-Type': 'application/json;charset=UTF-8'
}
res = json.loads(request_api_params(host, headers))
access_token=res['access_token']
url = f'https://aip.baidubce.com/rest/2.0/ocr/v1/general?access_token={access_token}'
headers = {'Content-Type': 'application/x-www-form-urlencoded'}
data = urlencode({'image': img})
# res = requests.post(url=url, headers=headers, data=data)
async def func0(url, headers, data):
async with aiohttp.ClientSession() as client:
async with client.post(url, headers = headers, data = data) as req:
res = await req.read()
return res
words = json.loads(str(func0(url, headers, data)))['words_result'][0]['words']
print('BaiduAPI请求成功')
except:
return
if re.findall(r"[涩色]图|炼铜", words):
if checkSwitch(__plugin_name__, group):
res = randint(1,10)
if 1 <= res <= 9:
res = randint(1,5)
if 1 <= res <= 4:
if setu_type == 1:
res = randint(1,5)
await bot.send_group_msg(group_id = group, message = '别急!正在找图!') # type: ignore
con = sqlite3.connect(Path('.') / 'ATRI' / 'data' / 'sqlite' / 'setu' / 'nearR18.db')
cur = con.cursor()
msg = cur.execute('SELECT * FROM nearR18 ORDER BY RANDOM() limit 1;')
if 1 <= res <= 4:
for i in msg:
pid = i[0]
title = i[1]
img = i[7]
end = time.perf_counter()
msg = SETU_REPLY.format(
title = title,
pid = pid,
setu = img,
time = round(end - start, 3)
)
await bot.send_group_msg(group_id = group, message = msg) # type: ignore
elif res == 5:
for i in msg:
pid = i[0]
title = i[1]
img = i[7]
end = time.perf_counter()
await bot.send_group_msg(group_id = group, message = '我找到涩图了!但我发给主人了\nο(=•ω<=)ρ⌒☆') # type: ignore
await send_to_superusers(
bot,
message = f"主人,从群{group}来的涩图!热乎着!\nTitle: {title}\nPid: {pid}\n{img}\nComplete time: {round(end - start, 3)}"
)
elif setu_type == 2:
res = randint(1,5)
await bot.send_group_msg(group_id = group, message = '别急!正在找图!') # type: ignore
start = time.perf_counter()
values = {
"apikey": apikey_LOLI,
"r18": "0",
"num": "1"
}
try:
dc = json.loads(request_api_params(URL, values))
title = dc["data"][0]["title"]
pid = dc["data"][0]["pid"]
setu = dc["data"][0]["url"] #b64.b64_str_img_url(dc["data"][0]["url"])
except:
await bot.send_group_msg(group_id = group, message = errorBack('数据请求失败')) # type: ignore
return
if 1 <= res <= 4:
end = time.perf_counter()
msg = SETU_REPLY.format(
title = title,
pid = pid,
setu = img,
time = round(end - start, 3)
)
await bot.send_group_msg(group_id = group, message = msg) # type: ignore
elif res == 5:
end = time.perf_counter()
await bot.send_group_msg(group_id = group, message = '我找到涩图了!但我发给主人了\nο(=•ω<=)ρ⌒☆') # type: ignore
await send_to_superusers(
bot,
message = f"主人,从群{group}来的涩图!热乎着!\nTitle: {title}\nPid: {pid}\n{setu}\nComplete time: {round(end - start, 3)}"
)
elif res == 5:
img = choice(
[
'SP.jpg', 'SP1.jpg', 'SP2.jpg'
]
)
img = Path('.') / 'ATRI' / 'data' / 'emoji' / f'{img}'
img = os.path.abspath(img)
await bot.send_group_msg(group_id = group, message = f'[CQ:image,file=file:///{img}]') # type: ignore
elif res == 10:
img = choice(
[
'GDZ.png', 'SHZY1.jpg', 'SHZY2.jpg', 'SHZY3.jpg', 'SHZY4.jpg', 'SHZY5.jpg', 'SHZY6.jpg'
]
)
img = Path('.') / 'ATRI' / 'data' / 'img' / 'niceIMG' / f'{img}'
img = os.path.abspath(img)
await bot.send_group_msg(group_id = group, message = f'[CQ:image,file=file:///{img}]') # type: ignore
else:
pass
else:
pass
|