forked from wangxyd/nicesuno
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathctext.py
278 lines (239 loc) · 8.14 KB
/
ctext.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
# encoding:utf-8
import os
import re
import io
import json
import base64
import pickle
import requests
from PIL import Image
from plugins import *
from lib import itchat
from lib.itchat.content import *
from bridge.reply import Reply, ReplyType
from config import conf
from common.log import logger
COMMANDS = {
"suno_help": {
"alias": ["suno_help", "suno帮助", "suno文档","sunohelp"],
"desc": "suno帮助",
},
"suno_admin_cmd": {
"alias": ["suno_admin_cmd", "suno管理员指令"],
"desc": "suno管理员指令",
},
"suno_admin_password": {
"alias": ["suno_admin_password", "suno管理员认证"],
"args": ["口令"],
"desc": "suno管理员认证",
},
}
ADMIN_COMMANDS = {
"suno_g_info": {
"alias": ["suno_g_info", "查询用户信息"],
"desc": "查询数据库中用户昵称和对应的剩余次数",
},
"suno_stop": {
"alias": ["suno_stop", "暂停suno服务"],
"desc": "暂停suno服务",
},
"suno_enable": {
"alias": ["suno_enable", "启用suno服务"],
"desc": "启用suno服务",
},
"set_suno_admin_password": {
"alias": ["set_suno_admin_password", "设置管理员口令"],
"args": ["口令"],
"desc": "修改管理员口令",
},
"suno_g_admin_list": {
"alias": ["suno_g_admin_list", "查询管理员列表"],
"desc": "查询管理员列表",
},
"suno_s_admin_list": {
"alias": ["suno_s_admin_list", "添加管理员"],
"args": ["用户ID或昵称"],
"desc": "添加管理员",
},
"suno_r_admin_list": {
"alias": ["suno_r_admin_list", "移除管理员"],
"args": ["用户ID或昵称或序列号"],
"desc": "移除管理员",
},
"suno_c_admin_list": {
"alias": ["suno_c_admin_list", "清空管理员"],
"desc": "清空管理员",
},
"suno_s_limit": {
"alias": ["suno_s_limit", "设置每日作图数限制"],
"args": ["限制值"],
"desc": "设置每日作图数限制",
},
"suno_r_limit": {
"alias": ["suno_r_limit", "清空重置用户作图数限制"],
"desc": "清空重置用户作图数限制",
},
"suno_g_wgroup": {
"alias": ["suno_g_wgroup", "查询白名单群组"],
"desc": "查询白名单群组",
},
"suno_s_wgroup": {
"alias": ["suno_s_wgroup", "添加白名单群组"],
"args": ["群组名称"],
"desc": "添加白名单群组",
},
"suno_r_wgroup": {
"alias": ["suno_r_wgroup", "移除白名单群组"],
"args": ["群组名称或序列号"],
"desc": "移除白名单群组",
},
"suno_c_wgroup": {
"alias": ["suno_c_wgroup", "清空白名单群组"],
"desc": "清空白名单群组",
},
"suno_g_wuser": {
"alias": ["suno_g_wuser", "查询白名单用户"],
"desc": "查询白名单用户",
},
"suno_s_wuser": {
"alias": ["suno_s_wuser", "添加白名单用户"],
"args": ["用户ID或昵称"],
"desc": "添加白名单用户",
},
"suno_r_wuser": {
"alias": ["suno_r_wuser", "移除白名单用户"],
"args": ["用户ID或昵称或序列号"],
"desc": "移除白名单用户",
},
"suno_c_wuser": {
"alias": ["suno_c_wuser", "清空白名单用户"],
"desc": "清空白名单用户",
},
"suno_g_bgroup": {
"alias": ["suno_g_bgroup", "查询黑名单群组"],
"desc": "查询黑名单群组",
},
"suno_s_bgroup": {
"alias": ["suno_s_bgroup", "添加黑名单群组"],
"args": ["群组名称"],
"desc": "添加黑名单群组",
},
"suno_r_bgroup": {
"alias": ["suno_r_bgroup", "移除黑名单群组"],
"args": ["群组名称或序列号"],
"desc": "移除黑名单群组",
},
"suno_c_bgroup": {
"alias": ["suno_c_bgroup", "清空黑名单群组"],
"desc": "清空黑名单群组",
},
"suno_g_buser": {
"alias": ["suno_g_buser", "查询黑名单用户"],
"desc": "查询黑名单用户",
},
"suno_s_buser": {
"alias": ["suno_s_buser", "添加黑名单用户"],
"args": ["用户ID或昵称"],
"desc": "添加黑名单用户",
},
"suno_r_buser": {
"alias": ["suno_r_buser", "移除黑名单用户"],
"args": ["用户ID或昵称或序列号"],
"desc": "移除黑名单用户",
},
"suno_c_buser": {
"alias": ["suno_c_buser", "清空黑名单用户"],
"desc": "清空黑名单用户",
},
}
def read_pickle(path):
with open(path, "rb") as f:
data = pickle.load(f)
return data
def write_pickle(path, content):
with open(path, "wb") as f:
pickle.dump(content, f)
return True
def read_file(path):
with open(path, mode="r", encoding="utf-8") as f:
return f.read()
def write_file(path, content):
with open(path, "w", encoding="utf-8") as f:
json.dump(content, f, indent=4)
return True
def Text(msg, e_context: EventContext):
return send(msg, e_context, ReplyType.TEXT)
def Image_file(msg, e_context: EventContext):
return send(msg, e_context, ReplyType.IMAGE)
def Image_url(msg, e_context: EventContext):
return send(msg, e_context, ReplyType.IMAGE_URL)
def Info(msg, e_context: EventContext):
return send(msg, e_context, ReplyType.INFO)
def Error(msg, e_context: EventContext):
return send(msg, e_context, ReplyType.ERROR)
def send(reply, e_context: EventContext, reply_type=ReplyType.TEXT, action=EventAction.BREAK_PASS):
if isinstance(reply, Reply):
if not reply.type and reply_type:
reply.type = reply_type
else:
reply = Reply(reply_type, reply)
e_context["reply"] = reply
e_context.action = action
return
def Textr(msg, e_context: EventContext):
return send_reply(msg, e_context, ReplyType.TEXT)
def Image_filer(msg, e_context: EventContext):
return send_reply(msg, e_context, ReplyType.IMAGE)
def Image_url_reply(msg, e_context: EventContext):
return send_reply(msg, e_context, ReplyType.IMAGE_URL)
def Info_reply(msg, e_context: EventContext):
return send_reply(msg, e_context, ReplyType.INFO)
def Error_reply(msg, e_context: EventContext):
return send_reply(msg, e_context, ReplyType.ERROR)
def send_reply(reply, e_context: EventContext, reply_type=ReplyType.TEXT):
if isinstance(reply, Reply):
if not reply.type and reply_type:
reply.type = reply_type
else:
reply = Reply(reply_type, reply)
channel = e_context['channel']
context = e_context['context']
# reply的包装步骤
rd = channel._decorate_reply(context, reply)
# reply的发送步骤
return channel._send_reply(context, rd)
def search_friends(name):
userInfo = {
"user_id": "",
"user_nickname": ""
}
# 判断是id还是昵称
if name.startswith("@"):
friends = itchat.search_friends(userName=name)
else:
friends = itchat.search_friends(name=name)
if friends and len(friends) > 0:
if isinstance(friends, list):
userInfo["user_id"] = friends[0]["UserName"]
userInfo["user_nickname"] = friends[0]["NickName"]
else:
userInfo["user_id"] = friends["UserName"]
userInfo["user_nickname"] = friends["NickName"]
return userInfo
def env_detection(self, e_context: EventContext):
trigger_prefix = conf().get("plugin_trigger_prefix", "$")
reply = None
# 如果用户是管理员或者在白名单用户列表中,则不受限制
if self.userInfo["isadmin"] or self.userInfo["iswuser"]:
return True
# 如果用户不在白名单用户列表中且使用次数已用完
if not self.userInfo["limit"]:
# 检查是否在白名单群组中
if self.userInfo["iswgroup"]:
return True
else:
reply = Reply(ReplyType.ERROR, "[suno] 您今日的使用次数已用完,请明日再来")
e_context["reply"] = reply
e_context.action = EventAction.BREAK_PASS
return False
return True