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
|
#!/usr/bin/env python3
# -*- encoding: utf-8 -*-
'''
@File : __init__.py
@Time : 2020/11/07 14:24:57
@Author : Kyomotoi
@Contact : [email protected]
@Github : https://github.com/Kyomotoi
@License : Copyright © 2018-2020 Kyomotoi, All Rights Reserved.
'''
__author__ = 'kyomotoi'
import json
from pathlib import Path
from random import choice
from nonebot.permission import SUPERUSER
from requests import exceptions
from nonebot.log import logger
from nonebot.rule import to_me
from nonebot.adapters.cqhttp import Bot, Event
from nonebot.plugin import on_command, on_message, on_notice, on_request
from utils.utils_times import countX
from utils.utils_yml import load_yaml
from utils.utils_error import errorRepo
from utils.utils_rule import check_banlist
from utils.utils_history import saveMessage
from utils.utils_request import request_api_text
CONFIG_PATH = Path('.') / 'config.yml'
config = load_yaml(CONFIG_PATH)['bot']
master = config['superusers']
# 收集 bot 所在群的聊天记录
MessageSave = on_message()
@MessageSave.handle() # type: ignore
async def _(bot: Bot, event: Event, state: dict) -> None:
user = str(event.user_id)
group = str(event.group_id)
message = str(event.message)
message_id = str(event.id)
if group == "None":
saveMessage(message_id, message, user)
else:
saveMessage(message_id, message, user, group)
logger.opt(colors=True).info(
f"[<yellow>{group}</yellow>]-U: (<blue>{user}</blue>) | Message: (<green>{message}</green>) Saved successfully"
)
# Call bot
callMe = on_message(rule=check_banlist())
@callMe.handle() # type: ignore
async def _(bot: Bot, event: Event, state: dict) -> None:
msg = str(event.raw_event['raw_message']).strip()
if "萝卜子" in msg:
await bot.send(event, "萝卜子是对咱的蔑称!!")
elif msg in config['nickname']:
await callMe.finish("叫咱有啥事吗w")
# 戳 一 戳
pokehah = on_command("戳一戳", rule=to_me() & check_banlist())
@pokehah.handle() # type: ignore
async def _poke(bot: Bot, event: Event, state: dict) -> None:
msg = choice([
"你再戳!", "?再戳试试?", "别戳了别戳了再戳就坏了555", "我爪巴爪巴,球球别再戳了", "你戳你🐎呢?!",
"那...那里...那里不能戳...绝对...", "(。´・ω・)ん?", "有事恁叫我,别天天一个劲戳戳戳!", "欸很烦欸!你戳🔨呢",
"?"
])
await pokehah.finish(msg)
async def poke_(bot: Bot, event: Event, state: dict) -> bool:
try:
return (event.raw_event['sub_type'] == 'poke'
and event.raw_event['target_id'] == int(event.self_id)
and event.raw_event['notice_type'] == 'notify')
except:
return False
poke = on_notice(rule=check_banlist() & poke_, block=True)
poke.handle()(_poke)
# 处理 进 / 退 群事件
groupEvent = on_notice()
@groupEvent.handle() # type: ignore
async def _(bot: Bot, event: Event, state: dict) -> None:
if event.raw_event['notice_type'] == 'group_increase':
if event.user_id != int(event.self_id):
await groupEvent.finish(
f'好欸!事新人[CQ:at,qq={event.raw_event["user_id"]}]')
elif event.user_id == int(event.self_id):
await groupEvent.finish("在下 ATRI,你可以叫我 亚托莉 或 アトリ !~w")
if event.raw_event['notice_type'] == 'group_decrease':
if event.user_id != int(event.self_id):
await groupEvent.finish(f'[{event.user_id}] 离开了我们...')
elif event.user_id == int(event.self_id):
for sup in master:
await bot.send_private_msg(
user_id=sup,
message=f'呜呜呜,主人,咱被群[{event.group_id}]扔出来了...')
# 处理 加好友 / 拉群 事件
selfEvent = on_request(rule=check_banlist())
FRIEND_ADD = 0
GROUP_INVITE = 0
@selfEvent.handle() # type: ignore
async def _(bot: Bot, event: Event, state: dict) -> None:
print(event.raw_event)
flag = event.raw_event['flag']
req_type = event.raw_event['request_type']
if req_type == 'friend':
for sup in master:
msg0 = '主人,收到一条好友请求:\n'
msg0 += f"请求人:{event.raw_event['user_id']}\n"
msg0 += f"申请信息:{event.raw_event['comment']}\n"
if FRIEND_ADD == 0:
msg0 += '由于主人未允许咱添加好友,已回拒'
await bot.set_friend_add_request(flag=flag, approve=False)
else:
msg0 += '由于主人已同意咱添加好友,已通过'
await bot.set_friend_add_request(flag=flag, approve=True)
await bot.send_private_msg(user_id=sup, message=msg0)
elif req_type == 'group' and event.raw_event['sub_type'] == 'invite':
for sup in master:
msg0 = '主人,收到一条群邀请:\n'
msg0 += f"邀请人:{event.raw_event['user_id']}\n"
msg0 += f"目标群:{event.raw_event['group_id']}\n"
if GROUP_INVITE == 0:
msg0 += '由于主人未允许咱添加群聊,已回拒'
await bot.set_group_add_request(
flag=flag,
sub_type=event.raw_event['sub_type'],
approve=False,
reason=f'ねね..ごんめね...\n主人不允许咱添加其他群聊...\n如需寻求帮助,请联系维护者:{sup}'
)
else:
msg0 += '由于主人已允许咱添加群聊,已同意'
await bot.set_group_add_request(
flag=flag,
sub_type=event.raw_event['sub_type'],
approve=True)
await bot.send_private_msg(user_id=sup, message=msg0)
# 控制 加好友 / 拉群 认证,默认关闭
controlSelfEvent = on_command('selfevent', permission=SUPERUSER)
@controlSelfEvent.handle() # type: ignore
async def _(bot: Bot, event: Event, state: dict) -> None:
args = str(event.message).strip()
msg0 = ''
global FRIEND_ADD, GROUP_INVITE
if not args:
msg0 = '-==ATRI INVITE Control System==-\n'
msg0 += 'Tips:\n'
msg0 += ' - For SUPERUSERS\n'
msg0 += ' - Normal all false\n'
msg0 += 'Usage:\n'
msg0 += ' - selfevent group-true/false\n'
msg0 += ' - selfevent friend-true/false\n'
await controlSelfEvent.finish(msg0)
if 'group-' in args:
if 'true' in args:
GROUP_INVITE = 1
elif 'friend-' in args:
if 'true' in args:
FRIEND_ADD = 1
else:
await controlSelfEvent.finish(msg0)
await controlSelfEvent.finish('DONE!')
# # 舆情监听系统
# listenPublicOpinion = on_message()
# file_PO = Path(
# '.') / 'ATRI' / 'plugins' / 'plugin_chat' / 'public_opinion.json'
# @groupEvent.handle() # type: ignore
# async def _(bot: Bot, event: Event, state: dict) -> None:
# with open(file_PO, 'r') as f:
# data = json.load(f)
# 口臭一下
fxxkMe = on_command('口臭一下',
aliases={'口臭', '骂我'},
rule=to_me() & check_banlist())
list_M = []
@fxxkMe.handle() # type: ignore
async def _(bot: Bot, event: Event, state: dict) -> None:
user = str(event.user_id)
global list_M
if countX(list_M, user) >= 3:
await fxxkMe.finish("不是??你这么想被咱骂的嘛??被咱骂就这么舒服的吗?!该......你该不会是.....M吧!")
list_M = list(set(list_M))
elif countX(list_M, user) >= 6:
await fxxkMe.finish("给我适可而止阿!?")
list_M = list(set(list_M))
else:
list_M.append(user)
URL = "https://nmsl.shadiao.app/api.php?level=min&lang=zh_cn"
msg = ""
try:
msg = request_api_text(URL)
except exceptions:
await fxxkMe.finish(errorRepo("请求错误"))
await fxxkMe.finish(msg)
# Hitokoto
hitokoto = on_command('一言',
aliases={'抑郁一下', '网抑云'},
rule=to_me() & check_banlist())
list_Y = []
@hitokoto.handle() # type: ignore
async def _(bot: Bot, event: Event, state: dict) -> None:
user = str(event.user_id)
global list_Y
if countX(list_Y, user) >= 3:
await hitokoto.finish("额......需要咱安慰一下嘛~?")
elif countX(list_Y, user) >= 6:
await hitokoto.finish("如果心里感到难受就赶快去睡觉奥!别再憋自己了!")
list_Y = list(set(list_Y))
else:
list_Y.append(user)
URL = "https://api.imjad.cn/hitokoto/?cat=a&charset=utf-8&length=50&encode=json&fun=sync&source="
info = {}
try:
info = json.loads(request_api_text(URL))
except:
await hitokoto.finish(errorRepo("请求错误"))
await hitokoto.finish(info["hitokoto"])
# laughFunny = on_command('来句笑话', rule=check_banlist())
# @laughFunny.handle() #type: ignore
# async def _(bot: Bot, event: Event, state: dict) -> None:
# name = event.sender['nickname']
# result = []
# LAUGH_FILE = Path('.') / 'ATRI' / 'plugins' / 'plugin_chat' / 'laugh.txt'
# with open(LAUGH_FILE, 'r', encoding='utf-8') as f:
# for line in f:
# result.append(line.strip('\n'))
# resu = choice(result)
# print(resu%name)
|