-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy path__init__.py
358 lines (287 loc) · 12.7 KB
/
__init__.py
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
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
# 2022.10.14 18:07
import re
from hoshino import Service, priv
from . import db,until
sv_help = '''
[帮助绘图]查看帮助
'''.strip()
sv = Service(
name = '绘图', #功能名
use_priv = priv.NORMAL, #使用权限
manage_priv = priv.ADMIN, #管理权限
visible = True, #是否可见
enable_on_default = True, #是否默认启用
bundle = '娱乐', #属于哪一类
help_ = sv_help #帮助文本
)
@sv.on_fullmatch(["帮助绘图"])
async def cwbangzhu(bot, ev):
msg = await until.helpyou()
await bot.send(ev, msg, at_sender=True)
@sv.on_fullmatch("元素法典目录")
async def cwbangzhu1(bot, ev):
msg = await until.helpyou1()
await bot.send(ev, msg, at_sender=True)
@sv.on_prefix('绘图')
async def text2img(bot, ev):
#await bot.send(ev, f"收到指令,处理中~", at_sender=True) #触发回馈示例,喜欢就取消注释
gid = ev.group_id
uid = ev.user_id
tags = ev.message.extract_plain_text().strip()
tag_dict,error_msg,tags_guolv=await until.process_tags(gid,uid,tags) #tags处理过程
if len(error_msg):
await bot.send(ev, f"已报错:{error_msg}", at_sender=True)
if len(tags_guolv):
await bot.send(ev, f"已过滤:{tags_guolv}", at_sender=True)
result_msg,error_msg = await until.get_imgdata(tag_dict,way=0)
if len(error_msg):
await bot.finish(ev, f"已报错:{error_msg}", at_sender=True)
#result_msg = f"[CQ:reply,id={ev.message_id}]{result_msg}" #回复形式发送,喜欢就取消注释,并注释下一行
await bot.send(ev, result_msg, at_sender=True)
@sv.on_prefix('SD绘图')
async def text2img_sd(bot, ev):
to_del = await bot.send(ev, f"收到指令,AI创作中~", at_sender=True) #反馈互动
gid = ev.group_id
uid = ev.user_id
tags = ev.message.extract_plain_text().strip()
tag_dict,error_msg,tags_guolv=await until.process_tags(gid,uid,tags) #tags处理过程
if len(error_msg):
await bot.send(ev, f"已报错:{error_msg}", at_sender=True)
if len(tags_guolv):
await bot.send(ev, f"已过滤:{tags_guolv}", at_sender=True)
result_msg,error_msg = await until.get_imgdata_sd(tag_dict,way=0)
if len(error_msg):
await bot.finish(ev, f"已报错:{error_msg}", at_sender=True)
try:
await bot.delete_msg(message_id=to_del['message_id'])#撤回反馈互动,防止刷屏
except:
await bot.send(ev, f"请给bot管理员以解锁全部功能")
#result_msg = f"[CQ:reply,id={ev.message_id}]{result_msg}" #回复形式发送,喜欢就取消注释,并注释下一行
await bot.send(ev, result_msg, at_sender=True)
@sv.on_keyword("以图绘图")
async def img2img(bot, ev):
to_del = await bot.send(ev, f"收到指令,AI创作中~", at_sender=True) #反馈互动
gid = ev.group_id
uid = ev.user_id
tags = ev.message.extract_plain_text().replace("以图绘图","").strip()
if ev.message[0].type == "reply":
tmsg = await bot.get_msg(message_id=int(ev.message[0].data['id']))
ev.message = tmsg["message"]
b_io,shape,error_msg,size = await until.get_pic_d(ev.message) #图片获取过程
if len(error_msg):
await bot.finish(ev, f"已报错:{error_msg}", at_sender=True)
tag_dict,error_msg,tags_guolv=await until.process_tags(gid,uid,tags) #tags处理过程
if len(error_msg):
await bot.send(ev, f"已报错:{error_msg}", at_sender=True)
if len(tags_guolv):
await bot.send(ev, f"已过滤:{tags_guolv}", at_sender=True)
result_msg,error_msg = await until.get_imgdata_sd(tag_dict,way=1,shape=shape,b_io=b_io,size=size) #绘图过程
if len(error_msg):
await bot.finish(ev, f"已报错:{error_msg}", at_sender=True)
try:
await bot.delete_msg(message_id=to_del['message_id'])#撤回反馈互动,防止刷屏
except:
await bot.send(ev, f"请给bot管理员以解锁全部功能")
await bot.send(ev, result_msg, at_sender=True)
@sv.on_keyword("解析pic")
async def get_pic_msg(bot, ev):
if ev.message[0].type == "reply":
tmsg = await bot.get_msg(message_id=int(ev.message[0].data['id']))
ev.message = tmsg["message"]
msg = await until.get_pic_msg_temp(ev.message)
await bot.send(ev, msg, at_sender=True)
@sv.on_keyword("观察pic")
async def get_pic_descrip(bot, ev):
if ev.message[0].type == "reply":
tmsg = await bot.get_msg(message_id=int(ev.message[0].data['id']))
ev.message = tmsg["message"]
b_io,shape,error_msg,size = await until.get_pic_d(ev.message) #图片获取过程
if len(error_msg):
await bot.finish(ev, f"已报错:{error_msg}", at_sender=True)
msg = await until.get_pic_descrip_(b_io)
await bot.send(ev, msg, at_sender=True)
@sv.on_keyword("增强pic")
async def get_pic_strong(bot,ev):
if ev.message[0].type == "reply":
tmsg = await bot.get_msg(message_id=int(ev.message[0].data['id']))
ev.message = tmsg["message"]
b_io,shape,error_msg,size = await until.get_pic_d(ev.message) #图片获取过程
if len(error_msg):
await bot.finish(ev, f"已报错:{error_msg}", at_sender=True)
msg = await until.get_pic_strong_(b_io)
await bot.send(ev, msg, at_sender=True)
@sv.on_suffix('XP排行')
async def get_xp_list(bot, ev):
msg = ev.message.extract_plain_text()
gid = ev.group_id
uid = ev.user_id
result_msg,error_msg = await until.get_xp_list_(msg,gid,uid)
if len(error_msg):
await bot.finish(ev, f"已报错:{error_msg}", at_sender=True)
await bot.send(ev, result_msg, at_sender=True)
@sv.on_suffix('XP缝合')
async def get_xp_pic(bot, ev):
gid = ev.group_id
uid = ev.user_id
msg = ev.message.extract_plain_text()
tags,error_msg = await until.get_xp_pic_(msg,gid,uid)
if len(error_msg):
await bot.finish(ev, f"已报错:{error_msg}", at_sender=True)
tag_dict,error_msg,tags_guolv=await until.process_tags(gid,uid,tags,add_db=0,arrange_tags=0) #tags处理过程
if len(error_msg):
await bot.send(ev, f"已报错:{error_msg}", at_sender=True)
if len(tags_guolv):
await bot.send(ev, f"已过滤:{tags_guolv}", at_sender=True)
result_msg,error_msg = await until.get_imgdata(tag_dict,way=0)
await bot.send(ev, result_msg, at_sender=True)
@sv.on_keyword('上传pic')
async def upload_header(bot, ev):
if ev.message[0].type == "reply":
tmsg = await bot.get_msg(message_id=int(ev.message[0].data['id']))
ev.message = tmsg["message"]
b_io,shape,error_msg,size = await until.get_pic_d(ev.message)
if len(error_msg):
await bot.finish(ev, f"已报错:{error_msg}", at_sender=True)
data = b_io.getvalue()
pic_hash,pic_dir,error_msg = await until.save_pic(data)
if len(error_msg):
await bot.finish(ev, f"已报错:{error_msg}", at_sender=True)
try:
seed=(str(ev.message).split(f"scale:")[0]).split('seed:')[1].strip()
scale=(str(ev.message).split(f"tags:")[0]).split('scale:')[1].strip()
tags=(str(ev.message).split(f"tags:")[1])
pic_msg = tags + f"&seed={seed}" + f"&scale={scale}"
except:
await bot.finish(ev, '格式出错', at_sender=True)
try:
db.add_pic(ev.group_id, ev.user_id, pic_hash, pic_dir, pic_msg)
await bot.send(ev, f'上传成功!', at_sender=True)
except Exception as e:
await bot.send(ev, f"报错:{e}",at_sender=True)
@sv.on_prefix(('查看pic'))
async def check_pic(bot, ev):
gid = ev.group_id
uid = ev.user_id
msg = ev.message.extract_plain_text()
result_msg,error_msg = await until.check_pic_(gid,uid,msg)
if len(error_msg):
await bot.finish(ev, f"已报错:{error_msg}", at_sender=True)
await bot.send(ev, result_msg, at_sender=True)
@sv.on_rex((r'^快捷绘图 ([0-9]\d*)(.*)'))
async def quick_img(bot, ev):
gid = ev.group_id
uid = ev.user_id
match = ev['match']
id = match.group(1)
tags = match.group(2)
msg = db.get_pic_data_id(id)
(a,b) = msg
msg = re.sub("&seed=[0-9]\d*", "", b, count=0, flags=0)
tags +=f",{msg}"
tag_dict,error_msg,tags_guolv=await until.process_tags(gid,uid,tags) #tags处理过程
if len(error_msg):
await bot.send(ev, f"已报错:{error_msg}", at_sender=True)
if len(tags_guolv):
await bot.send(ev, f"已过滤:{tags_guolv}", at_sender=True)
result_msg,error_msg = await until.get_imgdata(tag_dict)
if len(error_msg):
await bot.finish(ev, f"已报错:{error_msg}", at_sender=True)
await bot.send(ev, result_msg, at_sender=True)
@sv.on_prefix("点赞pic")
async def img_thumb(bot, ev):
id = ev.message.extract_plain_text().strip()
if not id.isdigit() and '*' not in id:
await bot.finish(ev, '图片ID???')
msg = db.add_pic_thumb(id)
await bot.send(ev, msg, at_sender=True)
@sv.on_prefix("删除pic")
async def del_img(bot, ev):
if not priv.check_priv(ev,priv.SUPERUSER):
msg = "只有超管才能删除"
await bot.finish(ev, msg, at_sender=True)
id = ev.message.extract_plain_text().strip()
if not id.isdigit() and '*' not in id:
await bot.finish(ev, '图片ID???')
msg = db.del_pic(id)
await bot.send(ev, msg, at_sender=True)
@sv.on_fullmatch(["SD模型目录"])
async def model_list(bot, ev):
msg = await until.get_model_list()
await bot.send(ev, msg, at_sender=True)
@sv.on_prefix("SD模型切换")
async def model_change(bot, ev):
if not priv.check_priv(ev,priv.ADMIN):
msg = "只有管理才能切换"
await bot.finish(ev, msg, at_sender=True)
model = ev.message.extract_plain_text().strip()
msg = await until.change_model(model)
if msg:
await bot.send(ev, msg, at_sender=True)
else:
await bot.finish(ev, '模型切换成功', at_sender=True)
@sv.on_prefix("元素法典")
async def magic_book(bot, ev):
msg = ev.message.extract_plain_text().strip()
if msg == "目录":
msg =f"元素法典目录:\n{str(until.magic_data_title)}"
await bot.finish(ev, msg, at_sender=True)
tag_dict,error_msg = await until.get_magic_book_(msg)
if len(error_msg):
await bot.finish(ev, f"{error_msg}", at_sender=True)
result_msg,error_msg = await until.get_imgdata(tag_dict,way=0)
if len(error_msg):
await bot.finish(ev, f"已报错:{error_msg}", at_sender=True)
await bot.send(ev, result_msg, at_sender=True)
@sv.on_prefix("SD元素法典")
async def magic_book_sd(bot, ev):
msg = ev.message.extract_plain_text().strip()
tag_dict,error_msg = await until.get_magic_book_(msg)
if len(error_msg):
await bot.finish(ev, f"{error_msg}", at_sender=True)
result_msg,error_msg = await until.get_imgdata_sd(tag_dict,way=0)
if len(error_msg):
await bot.finish(ev, f"已报错:{error_msg}", at_sender=True)
await bot.send(ev, result_msg, at_sender=True)
@sv.on_prefix("SD元素法典")
async def magic_book_sd(bot, ev):
msg = ev.message.extract_plain_text().strip()
if msg == "目录":
msg =f"元素法典目录:\n{str(until.magic_data_title)}"
await bot.finish(ev, msg, at_sender=True)
tag_dict,error_msg = await until.get_magic_book_(msg)
if len(error_msg):
await bot.finish(ev, f"{error_msg}", at_sender=True)
result_msg,error_msg = await until.get_imgdata_sd(tag_dict,way=0)
if len(error_msg):
await bot.finish(ev, f"已报错:{error_msg}", at_sender=True)
await bot.send(ev, result_msg, at_sender=True)
@sv.on_keyword("鉴赏图片")
async def img2tags(bot, ev):
msg = ev.message.extract_plain_text()
if ev.message[0].type == "reply":
tmsg = await bot.get_msg(message_id=int(ev.message[0].data['id']))
ev.message = tmsg["message"]
result_msg,error_msg = await until.img2tags_(ev.message,msg)
if len(error_msg):
await bot.finish(ev, f"已报错:{error_msg}", at_sender=True)
await bot.send(ev, result_msg, at_sender=True)
@sv.on_keyword('超分pic')
async def get_pic_super(bot, ev):
msg = ev.message.extract_plain_text()
if ev.message[0].type == "reply":
tmsg = await bot.get_msg(message_id=int(ev.message[0].data['id']))
ev.message = tmsg["message"]
result_msg,error_msg = await until.pic_super_(ev.message,msg)
if len(error_msg):
await bot.finish(ev, f"已报错:{error_msg}", at_sender=True)
await bot.send(ev, result_msg, at_sender=True)
@sv.on_keyword("动漫化")
async def img2anime(bot, ev):
msg = ev.message.extract_plain_text()
if ev.message[0].type == "reply":
tmsg = await bot.get_msg(message_id=int(ev.message[0].data['id']))
ev.message = tmsg["message"]
result_msg,error_msg = await until.img2anime_(ev.message,msg)
if len(error_msg):
await bot.finish(ev, f"已报错:{error_msg}", at_sender=True)
await bot.send(ev, result_msg, at_sender=True)