diff options
Diffstat (limited to 'ATRI/plugins')
-rw-r--r-- | ATRI/plugins/chat.py | 5 | ||||
-rw-r--r-- | ATRI/plugins/check_data.py | 53 | ||||
-rw-r--r-- | ATRI/plugins/upload_sqlite.py | 45 | ||||
-rw-r--r-- | ATRI/plugins/welcome.py | 27 | ||||
-rw-r--r-- | ATRI/plugins/wordcloud.py | 72 | ||||
-rw-r--r-- | ATRI/plugins/wordcloud/wordcloud.json | 1 |
6 files changed, 147 insertions, 56 deletions
diff --git a/ATRI/plugins/chat.py b/ATRI/plugins/chat.py index 2d18156..9ca5251 100644 --- a/ATRI/plugins/chat.py +++ b/ATRI/plugins/chat.py @@ -34,7 +34,7 @@ async def _(): groups = [group['group_id'] for group in group_list] res = randint(1,2) if res == 1: - msg = random.choice( + msg = choice( [ '啊......早上好...(哈欠)', '唔......吧唧...早上...哈啊啊~~~\n早上好......', @@ -71,7 +71,7 @@ async def _(): groups = [group['group_id'] for group in group_list] res = randint(1,2) if res == 1: - msg = random.choice( + msg = choice( [ '忙累了一天,快休息吧', '辛苦了一天,准备睡觉吧', @@ -513,6 +513,7 @@ async def _(session: CommandSession): await session.send('是主人的话...那算了...呜呜\n即使到达了ATRI的最低忍耐限度......') noobList = list(set(noobList)) pass + else: await session.send(f'[CQ:at,qq={user}]哼!接下来10分钟别想让我理你!') bL[f"{user}"] = f"{user}" diff --git a/ATRI/plugins/check_data.py b/ATRI/plugins/check_data.py new file mode 100644 index 0000000..0fd7217 --- /dev/null +++ b/ATRI/plugins/check_data.py @@ -0,0 +1,53 @@ +import json +import sqlite3 +from pathlib import Path +from nonebot import on_command, CommandSession + + + +@on_command('data_list', aliases = ['数据总量'], only_to_me = False) +async def _(session: CommandSession): + user = session.event.user_id + with open('ATRI/plugins/noobList/noobList.json', 'r') as f: + data = json.load(f) + + if str(user) in data.keys(): + pass + else: + con = sqlite3.connect(Path('.') / 'ATRI' / 'data' / 'sqlite' / 'setu' / 'normal.db') # setu-normal + cur = con.cursor() + cur.execute("select * from normal") + data_normal = len(cur.fetchall()) + con.close() + + con = sqlite3.connect(Path('.') / 'ATRI' / 'data' / 'sqlite' / 'setu' / 'nearR18.db') # setu-nearR18 + cur = con.cursor() + cur.execute("select * from nearR18") + data_nearR18 = len(cur.fetchall()) + con.close() + + con = sqlite3.connect(Path('.') / 'ATRI' / 'data' / 'sqlite' / 'setu' / 'r18.db') # setu-r18 + cur = con.cursor() + cur.execute("select * from r18") + data_r18 = len(cur.fetchall()) + con.close() + + con = sqlite3.connect(Path('.') / 'ATRI' / 'data' / 'sqlite' / 'cloudmusic' / 'cloudmusic.db') # cloudmusic + cur = con.cursor() + cur.execute("select * from cloudmusic") + data_cloudmusic = len(cur.fetchall()) + con.close() + + with open('ATRI/plugins/wordcloud/wordcloud.json', 'r') as f: + data = json.load(f) + data_repo = len(data) + + await session.send( + f"""目前螃蟹™数据库收录了: +涩图: + normal: {data_normal} + nearR18: {data_nearR18} + r18:{data_r18} +网抑云语录:{data_cloudmusic} +词汇量:{data_repo}""" + )
\ No newline at end of file diff --git a/ATRI/plugins/upload_sqlite.py b/ATRI/plugins/upload_sqlite.py index 2d40cf3..6a1e52a 100644 --- a/ATRI/plugins/upload_sqlite.py +++ b/ATRI/plugins/upload_sqlite.py @@ -134,47 +134,4 @@ async def _(session: CommandSession): end = time.perf_counter() - await session.send(f'数据上传完成!\n耗时: {round(end - start, 3)}s') - - -@on_command('data_list', aliases = ['查看上传数据', '数据总量'], only_to_me = False) -async def _(session: CommandSession): - user = session.event.user_id - with open('ATRI/plugins/noobList/noobList.json', 'r') as f: - data = json.load(f) - - if str(user) in data.keys(): - pass - else: - con = sqlite3.connect(Path('.') / 'ATRI' / 'data' / 'sqlite' / 'setu' / 'normal.db') # setu-normal - cur = con.cursor() - cur.execute("select * from normal") - data_normal = len(cur.fetchall()) - con.close() - - con = sqlite3.connect(Path('.') / 'ATRI' / 'data' / 'sqlite' / 'setu' / 'nearR18.db') # setu-nearR18 - cur = con.cursor() - cur.execute("select * from nearR18") - data_nearR18 = len(cur.fetchall()) - con.close() - - con = sqlite3.connect(Path('.') / 'ATRI' / 'data' / 'sqlite' / 'setu' / 'r18.db') # setu-r18 - cur = con.cursor() - cur.execute("select * from r18") - data_r18 = len(cur.fetchall()) - con.close() - - con = sqlite3.connect(Path('.') / 'ATRI' / 'data' / 'sqlite' / 'cloudmusic' / 'cloudmusic.db') # cloudmusic - cur = con.cursor() - cur.execute("select * from cloudmusic") - data_cloudmusic = len(cur.fetchall()) - con.close() - - await session.send( - f"""目前螃蟹™数据库收录了: - 涩图: - normal: {data_normal} - nearR18: {data_nearR18} - r18:{data_r18} - 网抑云语录:{data_cloudmusic}""" - )
\ No newline at end of file + await session.send(f'数据上传完成!\n耗时: {round(end - start, 3)}s')
\ No newline at end of file diff --git a/ATRI/plugins/welcome.py b/ATRI/plugins/welcome.py index 8f44300..6e2a9d0 100644 --- a/ATRI/plugins/welcome.py +++ b/ATRI/plugins/welcome.py @@ -9,6 +9,7 @@ from aiocqhttp.exceptions import ActionFailed import config # type: ignore + bot = nonebot.get_bot() master = config.MASTER() @@ -23,8 +24,19 @@ async def _(session: NoticeSession): else: await session.send(f'[CQ:at,qq={user}]\nねえ❤...是新人欸!\nここでは遠慮はいらないのだからね❤') -@on_notice('firend_add') +@on_notice('group_decrease') async def _(session: NoticeSession): + user = str(session.event.user_id) + now = str(session.event.operator_id) + + if now == user: + inf = await bot.get_stranger_info(user_id = user) # type: ignore + name = inf['nickname'] + await session.send(f'{name}({user}) 跑了') + + +@on_request('friend_add') +async def _(session: RequestSession): user = session.event.user_id await bot.send_private_msg( user_id = master, # type: ignore @@ -35,6 +47,10 @@ async def _(session: NoticeSession): data = json.load(f) if data["approve_friend_add"] == 0: + try: + await session.approve() + except ActionFailed as e: + print(e.retcode) await bot.send_private_msg( user_id = master, # type: ignore message = '由于主人已同意ATRI接近陌生人,故请求已同意!' @@ -54,15 +70,6 @@ async def _(session: NoticeSession): message = f'主人似乎不想让ATRI接触陌生人呢...' ) -@on_request('friend_add') -async def _(session: RequestSession): - with open(Path('.') / 'ATRI' / 'plugins' / 'switch' / 'switch.json', 'r') as f: - data = json.load(f) - - if data["approve_friend_add"] == 0: - await session.approve() - - @on_request('group') async def _(session: RequestSession): group = session.event.group_id diff --git a/ATRI/plugins/wordcloud.py b/ATRI/plugins/wordcloud.py new file mode 100644 index 0000000..4913727 --- /dev/null +++ b/ATRI/plugins/wordcloud.py @@ -0,0 +1,72 @@ +import json +from pathlib import Path +from random import randint +import nonebot +from nonebot import on_command +from nonebot import CommandSession +from nonebot import MessageSegment + +import config # type: ignore + + +bot = nonebot.get_bot() +master = config.MASTER() + + +@on_command('add_word', aliases = ['增加词汇'], only_to_me = False) +async def _(session: CommandSession): + if session.event.user_id == master: + msg = session.event.raw_message.split(' ', 3) + w_tpye = msg[0] + word = msg[1] + repo = msg[2] + prob = int(msg[3]) + with open('ATRI/plugins/wordcloud/wordcloud.json', 'r') as f: + data = json.load(f) + + if w_tpye == '添加词云' or '上传词云': + if word in data.keys(): + await session.send('该词已存在~!') + + else: + data[f"{word}"] = [f"{repo}",prob] + f = open('ATRI/plugins/wordcloud/wordcloud.json', 'w') + f.write(json.dumps(data)) + f.close() + session.finish(f"学習しました!\nWord:[{word}]\nRepo:[{repo}]\nProbability:[{'%.2f%%' % (round(1 / prob , 1) * 100)}]") + + elif w_tpye == '删除词云': + if word in data.keys(): + data.pop(word) + await session.send(f'已成功从ATRI记忆模块中抹除[{word}]') + + else: + session.finish(f'ATRI貌似没法从记忆中找到关键词[{word}]呢...') + + [email protected]_message("group") +async def repo(context): + user = context["user_id"] + group = context["group_id"] + word = context["message"] + print(word) + with open('ATRI/plugins/noobList/noobList.json', 'r') as f: + nL = json.load(f) + + if str(user) in nL.keys(): + pass + else: + with open('ATRI/plugins/wordcloud/wordcloud.json', 'r') as f: + data = json.load(f) + + if str(word) in data.keys(): + lt = data[f"{word}"] + print(lt) + msg = lt[0] + prob = int(lt[1]) + res = randint(1,prob) + if res == 1: + await bot.send_msg( + group_id = group, + message = msg + ) # type: ignore
\ No newline at end of file diff --git a/ATRI/plugins/wordcloud/wordcloud.json b/ATRI/plugins/wordcloud/wordcloud.json new file mode 100644 index 0000000..fb478b5 --- /dev/null +++ b/ATRI/plugins/wordcloud/wordcloud.json @@ -0,0 +1 @@ +{"test": ["TesT is SuccEss!", 1]}
\ No newline at end of file |