summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKyomotoi <[email protected]>2021-03-07 15:24:17 +0800
committerKyomotoi <[email protected]>2021-03-07 15:24:17 +0800
commitda888ff020805a38a17e5f83705aeb42ffa992ba (patch)
tree28fa5cc06c3b77970ced9136f12ed2bd94436926
parent51624483cb23e8922cbdf5f529e1dcb2342333a7 (diff)
downloadATRI-da888ff020805a38a17e5f83705aeb42ffa992ba.tar.gz
ATRI-da888ff020805a38a17e5f83705aeb42ffa992ba.tar.bz2
ATRI-da888ff020805a38a17e5f83705aeb42ffa992ba.zip
♻️⚡️ 重构 Service,优化部分代码
-rw-r--r--ATRI/__init__.py43
-rw-r--r--ATRI/config.py29
-rw-r--r--ATRI/data/service/limit.service.json1
-rw-r--r--ATRI/exceptions.py19
-rw-r--r--ATRI/plugins/admin.py16
-rw-r--r--ATRI/plugins/anime-search/__init__.py16
-rw-r--r--ATRI/plugins/anime-search/data_source.py16
-rw-r--r--ATRI/plugins/anti-rubbish.py18
-rw-r--r--ATRI/plugins/call-owner.py19
-rw-r--r--ATRI/plugins/code-runner.py29
-rw-r--r--ATRI/plugins/curse/__init__.py16
-rw-r--r--ATRI/plugins/drifting-bottle/__init__.py16
-rw-r--r--ATRI/plugins/essential.py43
-rw-r--r--ATRI/plugins/funny.py16
-rw-r--r--ATRI/plugins/github.py62
-rw-r--r--ATRI/plugins/hitokoto.py16
-rw-r--r--ATRI/plugins/rich/__init__.py24
-rw-r--r--ATRI/plugins/rich/data_source.py16
-rw-r--r--ATRI/plugins/status.py16
-rw-r--r--ATRI/plugins/tex.py52
-rw-r--r--ATRI/plugins/utils/__init__.py16
-rw-r--r--ATRI/plugins/utils/data_source.py16
-rw-r--r--ATRI/rule.py29
-rw-r--r--ATRI/service.py455
-rw-r--r--ATRI/service/__init__.py95
-rw-r--r--ATRI/service/banlist.py53
-rw-r--r--ATRI/service/httppost.py216
-rw-r--r--ATRI/service/limit.py53
-rw-r--r--ATRI/utils/file.py5
-rw-r--r--ATRI/utils/request.py7
-rw-r--r--config.yml13
-rw-r--r--main.py55
32 files changed, 942 insertions, 554 deletions
diff --git a/ATRI/__init__.py b/ATRI/__init__.py
new file mode 100644
index 0000000..4458ad8
--- /dev/null
+++ b/ATRI/__init__.py
@@ -0,0 +1,43 @@
+#!/usr/bin/env python3
+# -*- coding:utf-8 -*-
+'''
+File: __init__.py
+Created Date: 2021-03-07 11:22:06
+Author: Kyomotoi
+License: GPLv3
+Project: https://github.com/Kyomotoi/ATRI
+--------
+Last Modified: Sunday, 7th March 2021 3:01:51 pm
+Modified By: Kyomotoi ([email protected])
+--------
+Copyright (c) 2021 Kyomotoi
+'''
+
+from time import sleep
+
+import nonebot as nb
+from nonebot.adapters.cqhttp import Bot as ATRIBot
+
+from .config import RUNTIME_CONFIG
+from .log import logger
+
+
+__version__ = "YHN-001-A01"
+
+
+def asgi():
+ return nb.get_asgi()
+
+
+def init():
+ nb.init(**RUNTIME_CONFIG)
+ driver = nb.get_driver()
+ driver.register_adapter("cqhttp", ATRIBot)
+ nb.load_plugins('ATRI/plugins')
+ logger.info(f"Now running: {__version__}")
+ sleep(3)
+
+
+def run(app):
+ nb.run(app=app)
diff --git a/ATRI/config.py b/ATRI/config.py
index 4a8ed10..caff717 100644
--- a/ATRI/config.py
+++ b/ATRI/config.py
@@ -1,3 +1,19 @@
+#!/usr/bin/env python3
+# -*- coding:utf-8 -*-
+'''
+File: config.py
+Created Date: 2021-02-02 16:43:54
+Author: Kyomotoi
+License: GPLv3
+Project: https://github.com/Kyomotoi/ATRI
+--------
+Last Modified: Sunday, 7th March 2021 2:31:06 pm
+Modified By: Kyomotoi ([email protected])
+--------
+Copyright (c) 2021 Kyomotoi
+'''
+
from pathlib import Path
from datetime import timedelta
from ipaddress import IPv4Address
@@ -10,19 +26,6 @@ config = load_yml(CONFIG_PATH)
nonebot_config = config['BotSelfConfig']
-COPYRIGHT = """
- █████ ████████ ██████ ██
-██ ██ ██ ██ ██ ██
-███████ ██ ██████ ██
-██ ██ ██ ██ ██ ██
-██ ██ ██ ██ ██ ██
-=========================================
-Copyright © 2021 Kyomotoi, All Rights Reserved.
-Project: https://github.com/Kyomotoi/ATRI
-"""
-
-VERSION = "YHN-001-A01"
-
RUNTIME_CONFIG = {
"host": IPv4Address(nonebot_config.get('host', '127.0.0.1')),
"port": int(nonebot_config.get('port', '8080')),
diff --git a/ATRI/data/service/limit.service.json b/ATRI/data/service/limit.service.json
deleted file mode 100644
index 9e26dfe..0000000
--- a/ATRI/data/service/limit.service.json
+++ /dev/null
@@ -1 +0,0 @@
-{} \ No newline at end of file
diff --git a/ATRI/exceptions.py b/ATRI/exceptions.py
index ebf23de..e2fe475 100644
--- a/ATRI/exceptions.py
+++ b/ATRI/exceptions.py
@@ -1,3 +1,19 @@
+#!/usr/bin/env python3
+# -*- coding:utf-8 -*-
+'''
+File: exceptions.py
+Created Date: 2021-02-02 18:24:59
+Author: Kyomotoi
+License: GPLv3
+Project: https://github.com/Kyomotoi/ATRI
+--------
+Last Modified: Sunday, 7th March 2021 3:00:35 pm
+Modified By: Kyomotoi ([email protected])
+--------
+Copyright (c) 2021 Kyomotoi
+'''
+
import time
import json
import string
@@ -91,10 +107,9 @@ class GetStatusError(BaseBotException):
@run_postprocessor # type: ignore
-async def _(matcher: Matcher, exception: Optional[Exception],
+async def _track_error(matcher: Matcher, exception: Optional[Exception],
event: MessageEvent, state: dict) -> None:
"""检测Bot运行中的报错,并进行提醒"""
- print(114514)
if not exception:
return
diff --git a/ATRI/plugins/admin.py b/ATRI/plugins/admin.py
index 6cc3ed6..45acf4b 100644
--- a/ATRI/plugins/admin.py
+++ b/ATRI/plugins/admin.py
@@ -1,3 +1,19 @@
+#!/usr/bin/env python3
+# -*- coding:utf-8 -*-
+'''
+File: admin.py
+Created Date: 2021-02-04 21:17:12
+Author: Kyomotoi
+License: GPLv3
+Project: https://github.com/Kyomotoi/ATRI
+--------
+Last Modified: Sunday, 7th March 2021 3:14:01 pm
+Modified By: Kyomotoi ([email protected])
+--------
+Copyright (c) 2021 Kyomotoi
+'''
+
import json
import time
from pathlib import Path
diff --git a/ATRI/plugins/anime-search/__init__.py b/ATRI/plugins/anime-search/__init__.py
index 61f523b..3ff8964 100644
--- a/ATRI/plugins/anime-search/__init__.py
+++ b/ATRI/plugins/anime-search/__init__.py
@@ -1,3 +1,19 @@
+#!/usr/bin/env python3
+# -*- coding:utf-8 -*-
+'''
+File: __init__.py
+Created Date: 2021-02-19 22:16:34
+Author: Kyomotoi
+License: GPLv3
+Project: https://github.com/Kyomotoi/ATRI
+--------
+Last Modified: Sunday, 7th March 2021 3:18:10 pm
+Modified By: Kyomotoi ([email protected])
+--------
+Copyright (c) 2021 Kyomotoi
+'''
+
import re
import json
diff --git a/ATRI/plugins/anime-search/data_source.py b/ATRI/plugins/anime-search/data_source.py
index 3646162..22a7501 100644
--- a/ATRI/plugins/anime-search/data_source.py
+++ b/ATRI/plugins/anime-search/data_source.py
@@ -1,3 +1,19 @@
+#!/usr/bin/env python3
+# -*- coding:utf-8 -*-
+'''
+File: data_source.py
+Created Date: 2021-02-19 22:16:42
+Author: Kyomotoi
+License: GPLv3
+Project: https://github.com/Kyomotoi/ATRI
+--------
+Last Modified: Sunday, 7th March 2021 3:18:18 pm
+Modified By: Kyomotoi ([email protected])
+--------
+Copyright (c) 2021 Kyomotoi
+'''
+
SIMPLE = "万与丑专业丛东丝丢两严丧个丬丰临为丽举么义乌乐乔习乡书买乱争于亏云亘亚产亩亲亵亸亿仅从仑仓仪们价众优伙会伛伞伟传伤伥伦伧伪伫体余佣佥侠侣侥侦侧侨侩侪侬俣俦俨俩俪俭债倾偬偻偾偿傥傧储傩儿兑兖党兰关兴兹养兽冁内冈册写军农冢冯冲决况冻净凄凉凌减凑凛几凤凫凭凯击凼凿刍划刘则刚创删别刬刭刽刿剀剂剐剑剥剧劝办务劢动励劲劳势勋勐勚匀匦匮区医华协单卖卢卤卧卫却卺厂厅历厉压厌厍厕厢厣厦厨厩厮县参叆叇双发变叙叠叶号叹叽吁后吓吕吗吣吨听启吴呒呓呕呖呗员呙呛呜咏咔咙咛咝咤咴咸哌响哑哒哓哔哕哗哙哜哝哟唛唝唠唡唢唣唤唿啧啬啭啮啰啴啸喷喽喾嗫呵嗳嘘嘤嘱噜噼嚣嚯团园囱围囵国图圆圣圹场坂坏块坚坛坜坝坞坟坠垄垅垆垒垦垧垩垫垭垯垱垲垴埘埙埚埝埯堑堕塆墙壮声壳壶壸处备复够头夸夹夺奁奂奋奖奥妆妇妈妩妪妫姗姜娄娅娆娇娈娱娲娴婳婴婵婶媪嫒嫔嫱嬷孙学孪宁宝实宠审宪宫宽宾寝对寻导寿将尔尘尧尴尸尽层屃屉届属屡屦屿岁岂岖岗岘岙岚岛岭岳岽岿峃峄峡峣峤峥峦崂崃崄崭嵘嵚嵛嵝嵴巅巩巯币帅师帏帐帘帜带帧帮帱帻帼幂幞干并广庄庆庐庑库应庙庞废庼廪开异弃张弥弪弯弹强归当录彟彦彻径徕御忆忏忧忾怀态怂怃怄怅怆怜总怼怿恋恳恶恸恹恺恻恼恽悦悫悬悭悯惊惧惨惩惫惬惭惮惯愍愠愤愦愿慑慭憷懑懒懔戆戋戏戗战戬户扎扑扦执扩扪扫扬扰抚抛抟抠抡抢护报担拟拢拣拥拦拧拨择挂挚挛挜挝挞挟挠挡挢挣挤挥挦捞损捡换捣据捻掳掴掷掸掺掼揸揽揿搀搁搂搅携摄摅摆摇摈摊撄撑撵撷撸撺擞攒敌敛数斋斓斗斩断无旧时旷旸昙昼昽显晋晒晓晔晕晖暂暧札术朴机杀杂权条来杨杩杰极构枞枢枣枥枧枨枪枫枭柜柠柽栀栅标栈栉栊栋栌栎栏树栖样栾桊桠桡桢档桤桥桦桧桨桩梦梼梾检棂椁椟椠椤椭楼榄榇榈榉槚槛槟槠横樯樱橥橱橹橼檐檩欢欤欧歼殁殇残殒殓殚殡殴毁毂毕毙毡毵氇气氢氩氲汇汉污汤汹沓沟没沣沤沥沦沧沨沩沪沵泞泪泶泷泸泺泻泼泽泾洁洒洼浃浅浆浇浈浉浊测浍济浏浐浑浒浓浔浕涂涌涛涝涞涟涠涡涢涣涤润涧涨涩淀渊渌渍渎渐渑渔渖渗温游湾湿溃溅溆溇滗滚滞滟滠满滢滤滥滦滨滩滪漤潆潇潋潍潜潴澜濑濒灏灭灯灵灾灿炀炉炖炜炝点炼炽烁烂烃烛烟烦烧烨烩烫烬热焕焖焘煅煳熘爱爷牍牦牵牺犊犟状犷犸犹狈狍狝狞独狭狮狯狰狱狲猃猎猕猡猪猫猬献獭玑玙玚玛玮环现玱玺珉珏珐珑珰珲琎琏琐琼瑶瑷璇璎瓒瓮瓯电画畅畲畴疖疗疟疠疡疬疮疯疱疴痈痉痒痖痨痪痫痴瘅瘆瘗瘘瘪瘫瘾瘿癞癣癫癯皑皱皲盏盐监盖盗盘眍眦眬着睁睐睑瞒瞩矫矶矾矿砀码砖砗砚砜砺砻砾础硁硅硕硖硗硙硚确硷碍碛碜碱碹磙礼祎祢祯祷祸禀禄禅离秃秆种积称秽秾稆税稣稳穑穷窃窍窑窜窝窥窦窭竖竞笃笋笔笕笺笼笾筑筚筛筜筝筹签简箓箦箧箨箩箪箫篑篓篮篱簖籁籴类籼粜粝粤粪粮糁糇紧絷纟纠纡红纣纤纥约级纨纩纪纫纬纭纮纯纰纱纲纳纴纵纶纷纸纹纺纻纼纽纾线绀绁绂练组绅细织终绉绊绋绌绍绎经绐绑绒结绔绕绖绗绘给绚绛络绝绞统绠绡绢绣绤绥绦继绨绩绪绫绬续绮绯绰绱绲绳维绵绶绷绸绹绺绻综绽绾绿缀缁缂缃缄缅缆缇缈缉缊缋缌缍缎缏缐缑缒缓缔缕编缗缘缙缚缛缜缝缞缟缠缡缢缣缤缥缦缧缨缩缪缫缬缭缮缯缰缱缲缳缴缵罂网罗罚罢罴羁羟羡翘翙翚耢耧耸耻聂聋职聍联聩聪肃肠肤肷肾肿胀胁胆胜胧胨胪胫胶脉脍脏脐脑脓脔脚脱脶脸腊腌腘腭腻腼腽腾膑臜舆舣舰舱舻艰艳艹艺节芈芗芜芦苁苇苈苋苌苍苎苏苘苹茎茏茑茔茕茧荆荐荙荚荛荜荞荟荠荡荣荤荥荦荧荨荩荪荫荬荭荮药莅莜莱莲莳莴莶获莸莹莺莼萚萝萤营萦萧萨葱蒇蒉蒋蒌蓝蓟蓠蓣蓥蓦蔷蔹蔺蔼蕲蕴薮藁藓虏虑虚虫虬虮虽虾虿蚀蚁蚂蚕蚝蚬蛊蛎蛏蛮蛰蛱蛲蛳蛴蜕蜗蜡蝇蝈蝉蝎蝼蝾螀螨蟏衅衔补衬衮袄袅袆袜袭袯装裆裈裢裣裤裥褛褴襁襕见观觃规觅视觇览觉觊觋觌觍觎觏觐觑觞触觯詟誉誊讠计订讣认讥讦讧讨让讪讫训议讯记讱讲讳讴讵讶讷许讹论讻讼讽设访诀证诂诃评诅识诇诈诉诊诋诌词诎诏诐译诒诓诔试诖诗诘诙诚诛诜话诞诟诠诡询诣诤该详诧诨诩诪诫诬语诮误诰诱诲诳说诵诶请诸诹诺读诼诽课诿谀谁谂调谄谅谆谇谈谊谋谌谍谎谏谐谑谒谓谔谕谖谗谘谙谚谛谜谝谞谟谠谡谢谣谤谥谦谧谨谩谪谫谬谭谮谯谰谱谲谳谴谵谶谷豮贝贞负贠贡财责贤败账货质贩贪贫贬购贮贯贰贱贲贳贴贵贶贷贸费贺贻贼贽贾贿赀赁赂赃资赅赆赇赈赉赊赋赌赍赎赏赐赑赒赓赔赕赖赗赘赙赚赛赜赝赞赟赠赡赢赣赪赵赶趋趱趸跃跄跖跞践跶跷跸跹跻踊踌踪踬踯蹑蹒蹰蹿躏躜躯车轧轨轩轪轫转轭轮软轰轱轲轳轴轵轶轷轸轹轺轻轼载轾轿辀辁辂较辄辅辆辇辈辉辊辋辌辍辎辏辐辑辒输辔辕辖辗辘辙辚辞辩辫边辽达迁过迈运还这进远违连迟迩迳迹适选逊递逦逻遗遥邓邝邬邮邹邺邻郁郄郏郐郑郓郦郧郸酝酦酱酽酾酿释里鉅鉴銮錾钆钇针钉钊钋钌钍钎钏钐钑钒钓钔钕钖钗钘钙钚钛钝钞钟钠钡钢钣钤钥钦钧钨钩钪钫钬钭钮钯钰钱钲钳钴钵钶钷钸钹钺钻钼钽钾钿铀铁铂铃铄铅铆铈铉铊铋铍铎铏铐铑铒铕铗铘铙铚铛铜铝铞铟铠铡铢铣铤铥铦铧铨铪铫铬铭铮铯铰铱铲铳铴铵银铷铸铹铺铻铼铽链铿销锁锂锃锄锅锆锇锈锉锊锋锌锍锎锏锐锑锒锓锔锕锖锗错锚锜锞锟锠锡锢锣锤锥锦锨锩锫锬锭键锯锰锱锲锳锴锵锶锷锸锹锺锻锼锽锾锿镀镁镂镃镆镇镈镉镊镌镍镎镏镐镑镒镕镖镗镙镚镛镜镝镞镟镠镡镢镣镤镥镦镧镨镩镪镫镬镭镮镯镰镱镲镳镴镶长门闩闪闫闬闭问闯闰闱闲闳间闵闶闷闸闹闺闻闼闽闾闿阀阁阂阃阄阅阆阇阈阉阊阋阌阍阎阏阐阑阒阓阔阕阖阗阘阙阚阛队阳阴阵阶际陆陇陈陉陕陧陨险随隐隶隽难雏雠雳雾霁霉霭靓静靥鞑鞒鞯鞴韦韧韨韩韪韫韬韵页顶顷顸项顺须顼顽顾顿颀颁颂颃预颅领颇颈颉颊颋颌颍颎颏颐频颒颓颔颕颖颗题颙颚颛颜额颞颟颠颡颢颣颤颥颦颧风飏飐飑飒飓飔飕飖飗飘飙飚飞飨餍饤饥饦饧饨饩饪饫饬饭饮饯饰饱饲饳饴饵饶饷饸饹饺饻饼饽饾饿馀馁馂馃馄馅馆馇馈馉馊馋馌馍馎馏馐馑馒馓馔馕马驭驮驯驰驱驲驳驴驵驶驷驸驹驺驻驼驽驾驿骀骁骂骃骄骅骆骇骈骉骊骋验骍骎骏骐骑骒骓骔骕骖骗骘骙骚骛骜骝骞骟骠骡骢骣骤骥骦骧髅髋髌鬓魇魉鱼鱽鱾鱿鲀鲁鲂鲄鲅鲆鲇鲈鲉鲊鲋鲌鲍鲎鲏鲐鲑鲒鲓鲔鲕鲖鲗鲘鲙鲚鲛鲜鲝鲞鲟鲠鲡鲢鲣鲤鲥鲦鲧鲨鲩鲪鲫鲬鲭鲮鲯鲰鲱鲲鲳鲴鲵鲶鲷鲸鲹鲺鲻鲼鲽鲾鲿鳀鳁鳂鳃鳄鳅鳆鳇鳈鳉鳊鳋鳌鳍鳎鳏鳐鳑鳒鳓鳔鳕鳖鳗鳘鳙鳛鳜鳝鳞鳟鳠鳡鳢鳣鸟鸠鸡鸢鸣鸤鸥鸦鸧鸨鸩鸪鸫鸬鸭鸮鸯鸰鸱鸲鸳鸴鸵鸶鸷鸸鸹鸺鸻鸼鸽鸾鸿鹀鹁鹂鹃鹄鹅鹆鹇鹈鹉鹊鹋鹌鹍鹎鹏鹐鹑鹒鹓鹔鹕鹖鹗鹘鹚鹛鹜鹝鹞鹟鹠鹡鹢鹣鹤鹥鹦鹧鹨鹩鹪鹫鹬鹭鹯鹰鹱鹲鹳鹴鹾麦麸黄黉黡黩黪黾鼋鼌鼍鼗鼹齄齐齑齿龀龁龂龃龄龅龆龇龈龉龊龋龌龙龚龛龟志制咨只里系范松没尝尝闹面准钟别闲干尽脏拼"
TRADITION = "萬與醜專業叢東絲丟兩嚴喪個爿豐臨為麗舉麼義烏樂喬習鄉書買亂爭於虧雲亙亞產畝親褻嚲億僅從侖倉儀們價眾優夥會傴傘偉傳傷倀倫傖偽佇體餘傭僉俠侶僥偵側僑儈儕儂俁儔儼倆儷儉債傾傯僂僨償儻儐儲儺兒兌兗黨蘭關興茲養獸囅內岡冊寫軍農塚馮衝決況凍淨淒涼淩減湊凜幾鳳鳧憑凱擊氹鑿芻劃劉則剛創刪別剗剄劊劌剴劑剮劍剝劇勸辦務勱動勵勁勞勢勳猛勩勻匭匱區醫華協單賣盧鹵臥衛卻巹廠廳曆厲壓厭厙廁廂厴廈廚廄廝縣參靉靆雙發變敘疊葉號歎嘰籲後嚇呂嗎唚噸聽啟吳嘸囈嘔嚦唄員咼嗆嗚詠哢嚨嚀噝吒噅鹹呱響啞噠嘵嗶噦嘩噲嚌噥喲嘜嗊嘮啢嗩唕喚呼嘖嗇囀齧囉嘽嘯噴嘍嚳囁嗬噯噓嚶囑嚕劈囂謔團園囪圍圇國圖圓聖壙場阪壞塊堅壇壢壩塢墳墜壟壟壚壘墾坰堊墊埡墶壋塏堖塒塤堝墊垵塹墮壪牆壯聲殼壺壼處備復夠頭誇夾奪奩奐奮獎奧妝婦媽嫵嫗媯姍薑婁婭嬈嬌孌娛媧嫻嫿嬰嬋嬸媼嬡嬪嬙嬤孫學孿寧寶實寵審憲宮寬賓寢對尋導壽將爾塵堯尷屍盡層屭屜屆屬屢屨嶼歲豈嶇崗峴嶴嵐島嶺嶽崠巋嶨嶧峽嶢嶠崢巒嶗崍嶮嶄嶸嶔崳嶁脊巔鞏巰幣帥師幃帳簾幟帶幀幫幬幘幗冪襆幹並廣莊慶廬廡庫應廟龐廢廎廩開異棄張彌弳彎彈強歸當錄彠彥徹徑徠禦憶懺憂愾懷態慫憮慪悵愴憐總懟懌戀懇惡慟懨愷惻惱惲悅愨懸慳憫驚懼慘懲憊愜慚憚慣湣慍憤憒願懾憖怵懣懶懍戇戔戲戧戰戩戶紮撲扡執擴捫掃揚擾撫拋摶摳掄搶護報擔擬攏揀擁攔擰撥擇掛摯攣掗撾撻挾撓擋撟掙擠揮撏撈損撿換搗據撚擄摑擲撣摻摜摣攬撳攙擱摟攪攜攝攄擺搖擯攤攖撐攆擷擼攛擻攢敵斂數齋斕鬥斬斷無舊時曠暘曇晝曨顯晉曬曉曄暈暉暫曖劄術樸機殺雜權條來楊榪傑極構樅樞棗櫪梘棖槍楓梟櫃檸檉梔柵標棧櫛櫳棟櫨櫟欄樹棲樣欒棬椏橈楨檔榿橋樺檜槳樁夢檮棶檢欞槨櫝槧欏橢樓欖櫬櫚櫸檟檻檳櫧橫檣櫻櫫櫥櫓櫞簷檁歡歟歐殲歿殤殘殞殮殫殯毆毀轂畢斃氈毿氌氣氫氬氳彙漢汙湯洶遝溝沒灃漚瀝淪滄渢溈滬濔濘淚澩瀧瀘濼瀉潑澤涇潔灑窪浹淺漿澆湞溮濁測澮濟瀏滻渾滸濃潯濜塗湧濤澇淶漣潿渦溳渙滌潤澗漲澀澱淵淥漬瀆漸澠漁瀋滲溫遊灣濕潰濺漵漊潷滾滯灩灄滿瀅濾濫灤濱灘澦濫瀠瀟瀲濰潛瀦瀾瀨瀕灝滅燈靈災燦煬爐燉煒熗點煉熾爍爛烴燭煙煩燒燁燴燙燼熱煥燜燾煆糊溜愛爺牘犛牽犧犢強狀獷獁猶狽麅獮獰獨狹獅獪猙獄猻獫獵獼玀豬貓蝟獻獺璣璵瑒瑪瑋環現瑲璽瑉玨琺瓏璫琿璡璉瑣瓊瑤璦璿瓔瓚甕甌電畫暢佘疇癤療瘧癘瘍鬁瘡瘋皰屙癰痙癢瘂癆瘓癇癡癉瘮瘞瘺癟癱癮癭癩癬癲臒皚皺皸盞鹽監蓋盜盤瞘眥矓著睜睞瞼瞞矚矯磯礬礦碭碼磚硨硯碸礪礱礫礎硜矽碩硤磽磑礄確鹼礙磧磣堿镟滾禮禕禰禎禱禍稟祿禪離禿稈種積稱穢穠穭稅穌穩穡窮竊竅窯竄窩窺竇窶豎競篤筍筆筧箋籠籩築篳篩簹箏籌簽簡籙簀篋籜籮簞簫簣簍籃籬籪籟糴類秈糶糲粵糞糧糝餱緊縶糸糾紆紅紂纖紇約級紈纊紀紉緯紜紘純紕紗綱納紝縱綸紛紙紋紡紵紖紐紓線紺絏紱練組紳細織終縐絆紼絀紹繹經紿綁絨結絝繞絰絎繪給絢絳絡絕絞統綆綃絹繡綌綏絛繼綈績緒綾緓續綺緋綽緔緄繩維綿綬繃綢綯綹綣綜綻綰綠綴緇緙緗緘緬纜緹緲緝縕繢緦綞緞緶線緱縋緩締縷編緡緣縉縛縟縝縫縗縞纏縭縊縑繽縹縵縲纓縮繆繅纈繚繕繒韁繾繰繯繳纘罌網羅罰罷羆羈羥羨翹翽翬耮耬聳恥聶聾職聹聯聵聰肅腸膚膁腎腫脹脅膽勝朧腖臚脛膠脈膾髒臍腦膿臠腳脫腡臉臘醃膕齶膩靦膃騰臏臢輿艤艦艙艫艱豔艸藝節羋薌蕪蘆蓯葦藶莧萇蒼苧蘇檾蘋莖蘢蔦塋煢繭荊薦薘莢蕘蓽蕎薈薺蕩榮葷滎犖熒蕁藎蓀蔭蕒葒葤藥蒞蓧萊蓮蒔萵薟獲蕕瑩鶯蓴蘀蘿螢營縈蕭薩蔥蕆蕢蔣蔞藍薊蘺蕷鎣驀薔蘞藺藹蘄蘊藪槁蘚虜慮虛蟲虯蟣雖蝦蠆蝕蟻螞蠶蠔蜆蠱蠣蟶蠻蟄蛺蟯螄蠐蛻蝸蠟蠅蟈蟬蠍螻蠑螿蟎蠨釁銜補襯袞襖嫋褘襪襲襏裝襠褌褳襝褲襇褸襤繈襴見觀覎規覓視覘覽覺覬覡覿覥覦覯覲覷觴觸觶讋譽謄訁計訂訃認譏訐訌討讓訕訖訓議訊記訒講諱謳詎訝訥許訛論訩訟諷設訪訣證詁訶評詛識詗詐訴診詆謅詞詘詔詖譯詒誆誄試詿詩詰詼誠誅詵話誕詬詮詭詢詣諍該詳詫諢詡譸誡誣語誚誤誥誘誨誑說誦誒請諸諏諾讀諑誹課諉諛誰諗調諂諒諄誶談誼謀諶諜謊諫諧謔謁謂諤諭諼讒諮諳諺諦謎諞諝謨讜謖謝謠謗諡謙謐謹謾謫譾謬譚譖譙讕譜譎讞譴譫讖穀豶貝貞負貟貢財責賢敗賬貨質販貪貧貶購貯貫貳賤賁貰貼貴貺貸貿費賀貽賊贄賈賄貲賃賂贓資賅贐賕賑賚賒賦賭齎贖賞賜贔賙賡賠賧賴賵贅賻賺賽賾贗讚贇贈贍贏贛赬趙趕趨趲躉躍蹌蹠躒踐躂蹺蹕躚躋踴躊蹤躓躑躡蹣躕躥躪躦軀車軋軌軒軑軔轉軛輪軟轟軲軻轤軸軹軼軤軫轢軺輕軾載輊轎輈輇輅較輒輔輛輦輩輝輥輞輬輟輜輳輻輯轀輸轡轅轄輾轆轍轔辭辯辮邊遼達遷過邁運還這進遠違連遲邇逕跡適選遜遞邐邏遺遙鄧鄺鄔郵鄒鄴鄰鬱郤郟鄶鄭鄆酈鄖鄲醞醱醬釅釃釀釋裏钜鑒鑾鏨釓釔針釘釗釙釕釷釺釧釤鈒釩釣鍆釹鍚釵鈃鈣鈈鈦鈍鈔鍾鈉鋇鋼鈑鈐鑰欽鈞鎢鉤鈧鈁鈥鈄鈕鈀鈺錢鉦鉗鈷缽鈳鉕鈽鈸鉞鑽鉬鉭鉀鈿鈾鐵鉑鈴鑠鉛鉚鈰鉉鉈鉍鈹鐸鉶銬銠鉺銪鋏鋣鐃銍鐺銅鋁銱銦鎧鍘銖銑鋌銩銛鏵銓鉿銚鉻銘錚銫鉸銥鏟銃鐋銨銀銣鑄鐒鋪鋙錸鋱鏈鏗銷鎖鋰鋥鋤鍋鋯鋨鏽銼鋝鋒鋅鋶鐦鐧銳銻鋃鋟鋦錒錆鍺錯錨錡錁錕錩錫錮鑼錘錐錦鍁錈錇錟錠鍵鋸錳錙鍥鍈鍇鏘鍶鍔鍤鍬鍾鍛鎪鍠鍰鎄鍍鎂鏤鎡鏌鎮鎛鎘鑷鐫鎳鎿鎦鎬鎊鎰鎔鏢鏜鏍鏰鏞鏡鏑鏃鏇鏐鐔钁鐐鏷鑥鐓鑭鐠鑹鏹鐙鑊鐳鐶鐲鐮鐿鑔鑣鑞鑲長門閂閃閆閈閉問闖閏闈閑閎間閔閌悶閘鬧閨聞闥閩閭闓閥閣閡閫鬮閱閬闍閾閹閶鬩閿閽閻閼闡闌闃闠闊闋闔闐闒闕闞闤隊陽陰陣階際陸隴陳陘陝隉隕險隨隱隸雋難雛讎靂霧霽黴靄靚靜靨韃鞽韉韝韋韌韍韓韙韞韜韻頁頂頃頇項順須頊頑顧頓頎頒頌頏預顱領頗頸頡頰頲頜潁熲頦頤頻頮頹頷頴穎顆題顒顎顓顏額顳顢顛顙顥纇顫顬顰顴風颺颭颮颯颶颸颼颻飀飄飆飆飛饗饜飣饑飥餳飩餼飪飫飭飯飲餞飾飽飼飿飴餌饒餉餄餎餃餏餅餑餖餓餘餒餕餜餛餡館餷饋餶餿饞饁饃餺餾饈饉饅饊饌饢馬馭馱馴馳驅馹駁驢駔駛駟駙駒騶駐駝駑駕驛駘驍罵駰驕驊駱駭駢驫驪騁驗騂駸駿騏騎騍騅騌驌驂騙騭騤騷騖驁騮騫騸驃騾驄驏驟驥驦驤髏髖髕鬢魘魎魚魛魢魷魨魯魴魺鮁鮃鯰鱸鮋鮓鮒鮊鮑鱟鮍鮐鮭鮚鮳鮪鮞鮦鰂鮜鱠鱭鮫鮮鮺鯗鱘鯁鱺鰱鰹鯉鰣鰷鯀鯊鯇鮶鯽鯒鯖鯪鯕鯫鯡鯤鯧鯝鯢鯰鯛鯨鯵鯴鯔鱝鰈鰏鱨鯷鰮鰃鰓鱷鰍鰒鰉鰁鱂鯿鰠鼇鰭鰨鰥鰩鰟鰜鰳鰾鱈鱉鰻鰵鱅鰼鱖鱔鱗鱒鱯鱤鱧鱣鳥鳩雞鳶鳴鳲鷗鴉鶬鴇鴆鴣鶇鸕鴨鴞鴦鴒鴟鴝鴛鴬鴕鷥鷙鴯鴰鵂鴴鵃鴿鸞鴻鵐鵓鸝鵑鵠鵝鵒鷳鵜鵡鵲鶓鵪鶤鵯鵬鵮鶉鶊鵷鷫鶘鶡鶚鶻鶿鶥鶩鷊鷂鶲鶹鶺鷁鶼鶴鷖鸚鷓鷚鷯鷦鷲鷸鷺鸇鷹鸌鸏鸛鸘鹺麥麩黃黌黶黷黲黽黿鼂鼉鞀鼴齇齊齏齒齔齕齗齟齡齙齠齜齦齬齪齲齷龍龔龕龜誌製谘隻裡係範鬆冇嚐嘗鬨麵準鐘彆閒乾儘臟拚"
diff --git a/ATRI/plugins/anti-rubbish.py b/ATRI/plugins/anti-rubbish.py
index b6ef12a..7350789 100644
--- a/ATRI/plugins/anti-rubbish.py
+++ b/ATRI/plugins/anti-rubbish.py
@@ -1,3 +1,19 @@
+#!/usr/bin/env python3
+# -*- coding:utf-8 -*-
+'''
+File: anti-rubbish.py
+Created Date: 2021-02-15 12:39:24
+Author: Kyomotoi
+License: GPLv3
+Project: https://github.com/Kyomotoi/ATRI
+--------
+Last Modified: Sunday, 7th March 2021 3:13:51 pm
+Modified By: Kyomotoi ([email protected])
+--------
+Copyright (c) 2021 Kyomotoi
+'''
+
import json
from pathlib import Path
from datetime import datetime
@@ -64,7 +80,7 @@ async def _rubbish(bot: Bot, event: GroupMessageEvent) -> None:
f"吃过厕所自助餐的有:\n"
) + noob_list
await rubbish.finish(msg)
-
+
elif cmd[0] == "read":
try:
user = cmd[1]
diff --git a/ATRI/plugins/call-owner.py b/ATRI/plugins/call-owner.py
index f6174f5..c09276f 100644
--- a/ATRI/plugins/call-owner.py
+++ b/ATRI/plugins/call-owner.py
@@ -1,10 +1,25 @@
+#!/usr/bin/env python3
+# -*- coding:utf-8 -*-
+'''
+File: call-owner.py
+Created Date: 2021-02-19 23:02:45
+Author: Kyomotoi
+License: GPLv3
+Project: https://github.com/Kyomotoi/ATRI
+--------
+Last Modified: Sunday, 7th March 2021 3:13:40 pm
+Modified By: Kyomotoi ([email protected])
+--------
+Copyright (c) 2021 Kyomotoi
+'''
+
from nonebot.permission import SUPERUSER
from nonebot.plugin import on_command
from nonebot.typing import T_State
from nonebot.adapters.cqhttp import (
Bot,
- MessageEvent,
- GroupMessageEvent
+ MessageEvent
)
from ATRI.rule import is_in_banlist
diff --git a/ATRI/plugins/code-runner.py b/ATRI/plugins/code-runner.py
index f31f049..0761384 100644
--- a/ATRI/plugins/code-runner.py
+++ b/ATRI/plugins/code-runner.py
@@ -1,3 +1,19 @@
+#!/usr/bin/env python3
+# -*- coding:utf-8 -*-
+'''
+File: code-runner.py
+Created Date: 2021-02-20 07:43:44
+Author: Kyomotoi
+License: GPLv3
+Project: https://github.com/Kyomotoi/ATRI
+--------
+Last Modified: Sunday, 7th March 2021 3:13:28 pm
+Modified By: Kyomotoi ([email protected])
+--------
+Copyright (c) 2021 Kyomotoi
+'''
+
"""
Idea from: https://github.com/cczu-osa/aki
"""
@@ -45,6 +61,15 @@ code_runner = on_command("/code", rule=is_in_banlist() & is_in_dormant())
@code_runner.handle()
async def _code_runner(bot: Bot, event: MessageEvent) -> None:
msg = str(event.message).split("\n")
+
+ if msg[0] == "list":
+ msg0 = "咱现在支持的语言如下:\n"
+ msg0 += ", ".join(map(str, SUPPORTED_LANGUAGES.keys()))
+
+ await code_runner.finish(msg0)
+ elif not msg[0]:
+ await code_runner.finish("请键入/help以获取更多支持...")
+
laug = msg[0].replace("\r", "")
if laug not in SUPPORTED_LANGUAGES:
await code_runner.finish("该语言暂不支持...")
@@ -77,11 +102,11 @@ async def _code_runner(bot: Bot, event: MessageEvent) -> None:
out, remained_out = out[:60 * 10], out[60 * 10:]
if remained_lines or remained_out:
- out += f"\n(输出过多,已忽略剩余内容)"
+ out += f"\n(太多了太多了...)"
if out:
await bot.send(event, f"{k}:\n\n{out}")
sent = True
if not sent:
- await code_runner.finish("运行完成,没有任何输出")
+ await code_runner.finish("Running success! Nothing print.")
diff --git a/ATRI/plugins/curse/__init__.py b/ATRI/plugins/curse/__init__.py
index e2edbb5..f78e022 100644
--- a/ATRI/plugins/curse/__init__.py
+++ b/ATRI/plugins/curse/__init__.py
@@ -1,3 +1,19 @@
+#!/usr/bin/env python3
+# -*- coding:utf-8 -*-
+'''
+File: __init__.py
+Created Date: 2021-02-04 17:58:27
+Author: Kyomotoi
+License: GPLv3
+Project: https://github.com/Kyomotoi/ATRI
+--------
+Last Modified: Sunday, 7th March 2021 3:14:41 pm
+Modified By: Kyomotoi ([email protected])
+--------
+Copyright (c) 2021 Kyomotoi
+'''
+
from nonebot.plugin import on_command
from nonebot.adapters.cqhttp import Bot, MessageEvent
diff --git a/ATRI/plugins/drifting-bottle/__init__.py b/ATRI/plugins/drifting-bottle/__init__.py
index e69de29..c9bd0a7 100644
--- a/ATRI/plugins/drifting-bottle/__init__.py
+++ b/ATRI/plugins/drifting-bottle/__init__.py
@@ -0,0 +1,16 @@
+#!/usr/bin/env python3
+# -*- coding:utf-8 -*-
+'''
+File: __init__.py
+Created Date: 2021-02-15 11:45:36
+Author: Kyomotoi
+License: GPLv3
+Project: https://github.com/Kyomotoi/ATRI
+--------
+Last Modified: Sunday, 7th March 2021 3:14:36 pm
+Modified By: Kyomotoi ([email protected])
+--------
+Copyright (c) 2021 Kyomotoi
+'''
+
diff --git a/ATRI/plugins/essential.py b/ATRI/plugins/essential.py
index a8ba021..f7d9840 100644
--- a/ATRI/plugins/essential.py
+++ b/ATRI/plugins/essential.py
@@ -1,9 +1,26 @@
+#!/usr/bin/env python3
+# -*- coding:utf-8 -*-
+'''
+File: essential.py
+Created Date: 2021-02-04 12:53:00
+Author: Kyomotoi
+License: GPLv3
+Project: https://github.com/Kyomotoi/ATRI
+--------
+Last Modified: Sunday, 7th March 2021 3:13:09 pm
+Modified By: Kyomotoi ([email protected])
+--------
+Copyright (c) 2021 Kyomotoi
+'''
+
import time
import json
import shutil
from pathlib import Path
from random import choice
+import nonebot
from nonebot.adapters import Bot
from nonebot.plugin import on_notice, on_request
from nonebot.adapters.cqhttp.message import Message
@@ -24,12 +41,14 @@ from ATRI.log import logger
from ATRI.exceptions import WriteError
from ATRI.config import nonebot_config
from ATRI.rule import is_in_banlist
-from ATRI.service.httppost import HttpPost
-from main import driver
+from ATRI.service import Service as sv
PLUGIN_INFO_DIR = Path('.') / 'ATRI' / 'data' / 'service' / 'plugins'
+
+driver = nonebot.get_driver()
+
@driver.on_startup
async def startup() -> None:
logger.info("アトリは、高性能ですから!")
@@ -56,7 +75,7 @@ async def shutdown() -> None:
@driver.on_bot_connect
async def connect(bot) -> None:
for superuser in nonebot_config["superusers"]:
- await HttpPost.send_private_msg(
+ await sv.NetworkPost.send_private_msg(
int(superuser),
"WebSocket 成功连接,数据开始传输。"
)
@@ -66,7 +85,7 @@ async def connect(bot) -> None:
async def disconnect(bot) -> None:
for superuser in nonebot_config["superusers"]:
try:
- await HttpPost.send_private_msg(
+ await sv.NetworkPost.send_private_msg(
int(superuser),
"WebSocket 貌似断开了呢..."
)
@@ -110,7 +129,7 @@ async def _request_friend_event(bot, event: FriendRequestEvent) -> None:
f"申请信息:{event.comment}\n"
f"申请码:{event.flag}"
)
- await HttpPost.send_private_msg(
+ await sv.NetworkPost.send_private_msg(
user_id=int(superuser),
message=msg
)
@@ -152,7 +171,7 @@ async def _request_group_event(bot, event: GroupRequestEvent) -> None:
f"申请信息:{event.comment}\n"
f"申请码:{event.flag}"
)
- await HttpPost.send_private_msg(
+ await sv.NetworkPost.send_private_msg(
user_id=int(superuser),
message=msg
)
@@ -177,7 +196,7 @@ async def _group_member_event(bot: Bot, event) -> None:
f"咱被群 {event.group_id} 里的 {event.operator_id} 扔出来了..."
)
for superuser in nonebot_config["superusers"]:
- await HttpPost.send_private_msg(
+ await sv.NetworkPost.send_private_msg(
user_id=int(superuser),
message=msg
)
@@ -192,7 +211,7 @@ group_admin_event = on_notice()
async def _group_admin_event(bot: Bot, event: GroupAdminNoticeEvent) -> None:
if event.is_tome():
for superuser in nonebot_config["superusers"]:
- await HttpPost.send_private_msg(
+ await sv.NetworkPost.send_private_msg(
user_id=int(superuser),
message=f"好欸!主人!我在群 {event.group_id} 成为了管理!!"
)
@@ -211,7 +230,7 @@ async def _group_ban_event(bot: Bot, event: GroupBanNoticeEvent) -> None:
f"时长...是 {event.duration} 秒"
)
for superuser in nonebot_config["superusers"]:
- await HttpPost.send_private_msg(
+ await sv.NetworkPost.send_private_msg(
user_id=int(superuser),
message=msg
)
@@ -221,7 +240,7 @@ async def _group_ban_event(bot: Bot, event: GroupBanNoticeEvent) -> None:
f"咱在群 {event.group_id} 被 {event.operator_id} 上的口球解除了!"
)
for superuser in nonebot_config["superusers"]:
- await HttpPost.send_private_msg(
+ await sv.NetworkPost.send_private_msg(
user_id=int(superuser),
message=msg
)
@@ -271,7 +290,7 @@ async def _recall_event(bot: Bot, event) -> None:
await bot.send(event, "咱看到惹~!")
for superuser in nonebot_config["superusers"]:
- await HttpPost.send_private_msg(
+ await sv.NetworkPost.send_private_msg(
user_id=int(superuser),
message=msg
)
@@ -293,7 +312,7 @@ async def _recall_event(bot: Bot, event) -> None:
)
for superuser in nonebot_config["superusers"]:
- await HttpPost.send_private_msg(
+ await sv.NetworkPost.send_private_msg(
user_id=int(superuser),
message=msg
)
diff --git a/ATRI/plugins/funny.py b/ATRI/plugins/funny.py
index c691abd..39a691d 100644
--- a/ATRI/plugins/funny.py
+++ b/ATRI/plugins/funny.py
@@ -1,3 +1,19 @@
+#!/usr/bin/env python3
+# -*- coding:utf-8 -*-
+'''
+File: funny.py
+Created Date: 2021-02-04 21:17:21
+Author: Kyomotoi
+License: GPLv3
+Project: https://github.com/Kyomotoi/ATRI
+--------
+Last Modified: Sunday, 7th March 2021 3:13:19 pm
+Modified By: Kyomotoi ([email protected])
+--------
+Copyright (c) 2021 Kyomotoi
+'''
+
from pathlib import Path
from random import choice, randint
diff --git a/ATRI/plugins/github.py b/ATRI/plugins/github.py
new file mode 100644
index 0000000..118d6f5
--- /dev/null
+++ b/ATRI/plugins/github.py
@@ -0,0 +1,62 @@
+#!/usr/bin/env python3
+# -*- coding:utf-8 -*-
+'''
+File: github.py
+Created Date: 2021-02-26 23:22:34
+Author: Kyomotoi
+License: GPLv3
+Project: https://github.com/Kyomotoi/ATRI
+--------
+Last Modified: Sunday, 7th March 2021 3:11:56 pm
+Modified By: Kyomotoi ([email protected])
+--------
+Copyright (c) 2021 Kyomotoi
+'''
+
+import re
+import json
+
+from nonebot.plugin import on_message
+from nonebot.adapters.cqhttp import Bot, MessageEvent
+
+from ATRI.rule import is_in_banlist, is_in_dormant
+from ATRI.utils.request import get_bytes
+from ATRI.exceptions import RequestTimeOut
+
+
+URL = "https://api.github.com/repos/{owner}/{repo}/issues/{issue_number}"
+
+
+github_issues = on_message(rule=is_in_banlist() & is_in_dormant())
+
+@github_issues.handle()
+async def _github_issues(bot: Bot, event: MessageEvent) -> None:
+ msg = str(event.message)
+ patt = r"https://github.com/(.*)/(.*)/issues/(.*)"
+ need_info = re.findall(patt, msg)
+ if not need_info:
+ return
+
+ for i in need_info:
+ need_info = list(i)
+ owner = need_info[0]
+ repo = need_info[1]
+ issue_number = need_info[2]
+ url = URL.format(owner=owner,
+ repo=repo,
+ issue_number=issue_number)
+
+ try:
+ data = await get_bytes(url)
+ except RequestTimeOut:
+ return
+
+ data = json.loads(data)
+ msg0 = (
+ f"{repo}: #{issue_number} {data['state']}\n"
+ f"comments: {data['comments']}\n"
+ f"update: {data['updated_at']}\n"
+ f"{data['body']}"
+ )
+ await github_issues.finish(msg0)
diff --git a/ATRI/plugins/hitokoto.py b/ATRI/plugins/hitokoto.py
index 7f7eae6..ff686fc 100644
--- a/ATRI/plugins/hitokoto.py
+++ b/ATRI/plugins/hitokoto.py
@@ -1,3 +1,19 @@
+#!/usr/bin/env python3
+# -*- coding:utf-8 -*-
+'''
+File: hitokoto.py
+Created Date: 2021-02-04 17:40:21
+Author: Kyomotoi
+License: GPLv3
+Project: https://github.com/Kyomotoi/ATRI
+--------
+Last Modified: Sunday, 7th March 2021 3:11:44 pm
+Modified By: Kyomotoi ([email protected])
+--------
+Copyright (c) 2021 Kyomotoi
+'''
+
import os
import json
from pathlib import Path
diff --git a/ATRI/plugins/rich/__init__.py b/ATRI/plugins/rich/__init__.py
index d20a234..7f9369e 100644
--- a/ATRI/plugins/rich/__init__.py
+++ b/ATRI/plugins/rich/__init__.py
@@ -1,3 +1,19 @@
+#!/usr/bin/env python3
+# -*- coding:utf-8 -*-
+'''
+File: __init__.py
+Created Date: 2021-02-07 09:34:23
+Author: Kyomotoi
+License: GPLv3
+Project: https://github.com/Kyomotoi/ATRI
+--------
+Last Modified: Sunday, 7th March 2021 3:14:28 pm
+Modified By: Kyomotoi ([email protected])
+--------
+Copyright (c) 2021 Kyomotoi
+'''
+
import re
import json
from aiohttp.client import ClientSession
@@ -25,7 +41,7 @@ bilibili_rich = on_message(
@bilibili_rich.handle()
async def _bilibili_rich(bot: Bot, event: MessageEvent) -> None:
global waiting_list
- msg = str(event.raw_message)
+ msg = str(event.raw_message).replace("\\", "")
user = event.user_id
bv = False
@@ -45,9 +61,9 @@ async def _bilibili_rich(bot: Bot, event: MessageEvent) -> None:
except:
return
else:
- bv_url = re.findall(r"(..........b23...\S+\=)", msg)
- bv_url = bv_url[0].replace("\\", "")
- print(bv_url)
+ patt = r"(?:(?:https?|ftp):\/\/)?[\w/\-?=%.]+\.[\w/\-&?=%.]+"
+ bv_url = re.findall(patt, msg)
+ bv_url = bv_url[3]
async with ClientSession() as session:
async with session.get(
url=bv_url) as r:
diff --git a/ATRI/plugins/rich/data_source.py b/ATRI/plugins/rich/data_source.py
index 32ac219..d3e7d6e 100644
--- a/ATRI/plugins/rich/data_source.py
+++ b/ATRI/plugins/rich/data_source.py
@@ -1,3 +1,19 @@
+#!/usr/bin/env python3
+# -*- coding:utf-8 -*-
+'''
+File: data_source.py
+Created Date: 2021-02-07 09:34:31
+Author: Kyomotoi
+License: GPLv3
+Project: https://github.com/Kyomotoi/ATRI
+--------
+Last Modified: Sunday, 7th March 2021 3:14:31 pm
+Modified By: Kyomotoi ([email protected])
+--------
+Copyright (c) 2021 Kyomotoi
+'''
+
table = 'fZodR9XQDSUm21yCkr6zBqiveYah8bt4xsWpHnJE7jL5VG3guMTKNPAwcF'
tr = {}
for i in range(58):
diff --git a/ATRI/plugins/status.py b/ATRI/plugins/status.py
index 576d45e..fe10dea 100644
--- a/ATRI/plugins/status.py
+++ b/ATRI/plugins/status.py
@@ -1,3 +1,19 @@
+#!/usr/bin/env python3
+# -*- coding:utf-8 -*-
+'''
+File: status.py
+Created Date: 2021-02-19 21:52:56
+Author: Kyomotoi
+License: GPLv3
+Project: https://github.com/Kyomotoi/ATRI
+--------
+Last Modified: Sunday, 7th March 2021 3:11:30 pm
+Modified By: Kyomotoi ([email protected])
+--------
+Copyright (c) 2021 Kyomotoi
+'''
+
import psutil
from nonebot.plugin import on_command
diff --git a/ATRI/plugins/tex.py b/ATRI/plugins/tex.py
deleted file mode 100644
index 01eabf7..0000000
--- a/ATRI/plugins/tex.py
+++ /dev/null
@@ -1,52 +0,0 @@
-import re
-from urllib.parse import quote_plus
-from nonebot.adapters.cqhttp.message import Message, MessageSegment
-
-from nonebot.plugin import on_command
-from nonebot.adapters.cqhttp import Bot, MessageEvent
-from nonebot.typing import T_State
-
-from ATRI.exceptions import RequestTimeOut
-from ATRI.rule import is_in_banlist, is_in_dormant
-from ATRI.utils.request import post_bytes
-
-
-ZHIHU_TEX_SVG_URL_FORMAT = 'https://www.zhihu.com/equation?tex='
-LATEX2PNG_API_URL = 'http://latex2png.com/'
-LATEX2PNG_IMAGE_URL_FORMAT = 'http://latex2png.com/output//'
-
-
-tex = on_command("/tex", rule=is_in_banlist() & is_in_dormant())
-
-async def _tex(bot: Bot, event: MessageEvent, state: T_State) -> None:
- tex_code = str(event.message).strip()
- if tex_code:
- state["tex_code"] = tex_code
-
[email protected]("tex_code", prompt="请告诉咱需要生成图片的的Tex公式")
-async def __tex(bot: Bot, event: MessageEvent, state: T_State) -> None:
- tex_code = state["tex_code"]
- try:
- req = await post_bytes(
- LATEX2PNG_API_URL,
- params={
- "latex": tex_code,
- "res": "600",
- "color": "000000"
- }
- )
- except RequestTimeOut:
- raise RequestTimeOut("Failed to request!")
-
- html = str(req)
- m = re.search(r"latex_[0-9a-z]+\.png", html)
- if not m:
- await tex.finish("生成失败,等会再试试吧...")
-
- await tex.finish(
- Message(
- MessageSegment.image(LATEX2PNG_IMAGE_URL_FORMAT + m.group(0)) +
- "\n" + ZHIHU_TEX_SVG_URL_FORMAT + quote_plus(tex_code)
- )
- )
diff --git a/ATRI/plugins/utils/__init__.py b/ATRI/plugins/utils/__init__.py
index 1bf1461..47c3b47 100644
--- a/ATRI/plugins/utils/__init__.py
+++ b/ATRI/plugins/utils/__init__.py
@@ -1,3 +1,19 @@
+#!/usr/bin/env python3
+# -*- coding:utf-8 -*-
+'''
+File: __init__.py
+Created Date: 2021-02-04 21:14:48
+Author: Kyomotoi
+License: GPLv3
+Project: https://github.com/Kyomotoi/ATRI
+--------
+Last Modified: Sunday, 7th March 2021 3:14:16 pm
+Modified By: Kyomotoi ([email protected])
+--------
+Copyright (c) 2021 Kyomotoi
+'''
+
import re
from nonebot.plugin import on_command
diff --git a/ATRI/plugins/utils/data_source.py b/ATRI/plugins/utils/data_source.py
index f41a1d1..6d018f1 100644
--- a/ATRI/plugins/utils/data_source.py
+++ b/ATRI/plugins/utils/data_source.py
@@ -1,3 +1,19 @@
+#!/usr/bin/env python3
+# -*- coding:utf-8 -*-
+'''
+File: data_source.py
+Created Date: 2021-02-04 21:14:59
+Author: Kyomotoi
+License: GPLv3
+Project: https://github.com/Kyomotoi/ATRI
+--------
+Last Modified: Sunday, 7th March 2021 3:14:22 pm
+Modified By: Kyomotoi ([email protected])
+--------
+Copyright (c) 2021 Kyomotoi
+'''
+
import re
import random
diff --git a/ATRI/rule.py b/ATRI/rule.py
index abc90f8..3b9c403 100644
--- a/ATRI/rule.py
+++ b/ATRI/rule.py
@@ -1,3 +1,19 @@
+#!/usr/bin/env python3
+# -*- coding:utf-8 -*-
+'''
+File: rule.py
+Created Date: 2021-02-03 15:33:57
+Author: Kyomotoi
+License: GPLv3
+Project: https://github.com/Kyomotoi/ATRI
+--------
+Last Modified: Sunday, 7th March 2021 2:58:18 pm
+Modified By: Kyomotoi ([email protected])
+--------
+Copyright (c) 2021 Kyomotoi
+'''
+
import datetime
from random import choice
@@ -6,9 +22,7 @@ from nonebot.adapters.cqhttp.event import Event
from nonebot.adapters.cqhttp import GroupMessageEvent, PokeNotifyEvent
from .config import config
-from .service.limit import Limit
-from .service.banlist import BanSystem
-from .service import Service
+from .service import Service as sv
from .utils.list import count_list, del_list_aim
from .utils.apscheduler import scheduler, DateTrigger
@@ -16,22 +30,23 @@ from .utils.apscheduler import scheduler, DateTrigger
def is_in_service(service: str) -> Rule:
async def _is_in_service(bot, event, state) -> bool:
if isinstance(event, GroupMessageEvent):
- return await Limit.auth_service(service, event.group_id)
- return await Limit.auth_service(service)
+ return sv.auth_service(service, event.group_id)
+ else:
+ return sv.auth_service(service, None)
return Rule(_is_in_service)
def is_in_banlist() -> Rule:
async def _is_in_banlist(bot, event, state) -> bool:
- return BanSystem.is_in_list(str(event.get_user_id()))
+ return sv.BlockSystem.auth_user(int(event.get_user_id()))
return Rule(_is_in_banlist)
def is_in_dormant() -> Rule:
async def _is_in_dormant(bot, event, state) -> bool:
- return Service.is_dormant()
+ return sv.Dormant.is_dormant()
return Rule(_is_in_dormant)
diff --git a/ATRI/service.py b/ATRI/service.py
new file mode 100644
index 0000000..8ce3c22
--- /dev/null
+++ b/ATRI/service.py
@@ -0,0 +1,455 @@
+#!/usr/bin/env python3
+# -*- coding:utf-8 -*-
+'''
+File: service.py
+Created Date: 2021-02-27 11:01:39
+Author: Kyomotoi
+License: GPLv3
+Project: https://github.com/Kyomotoi/ATRI
+--------
+Last Modified: Sunday, 7th March 2021 2:56:28 pm
+Modified By: Kyomotoi ([email protected])
+--------
+Copyright (c) 2021 Kyomotoi
+'''
+
+import os
+import json
+from pathlib import Path
+from datetime import datetime
+from typing import (
+ Dict,
+ Any,
+ List,
+ Set,
+ Tuple,
+ Type,
+ Union,
+ Optional,
+ TYPE_CHECKING
+)
+from nonebot.matcher import Matcher
+from nonebot.permission import Permission
+from nonebot.typing import T_State, T_Handler, T_RuleChecker
+from nonebot.rule import Rule, command, keyword
+
+from .log import logger as log
+from .config import config
+from .utils.request import post_bytes
+
+if TYPE_CHECKING:
+ from nonebot.adapters import Bot, Event
+
+
+SERVICE_DIR = Path('.') / 'ATRI' / 'data' / 'service'
+os.makedirs(SERVICE_DIR, exist_ok=True)
+
+
+matcher_list: list = []
+is_sleep: bool = False
+
+
+def _load_service_config(service: str, docs: str = None) -> dict:
+ file_name = service + ".json"
+ file = SERVICE_DIR / file_name
+ try:
+ data = json.loads(file.read_bytes())
+ except:
+ service_info = {
+ "name": service,
+ "docs": docs,
+ "disable_group": []
+ }
+ with open(file, "w") as r:
+ r.write(json.dumps(service_info, indent=4))
+ data = service_info
+ return data
+
+
+def _save_service_config(service: str, data: dict) -> None:
+ file_name = service + ".json"
+ file = SERVICE_DIR / file_name
+ with open(file, "w") as r:
+ r.write(json.dumps(data, indent=4))
+
+
+class Service:
+ """
+ 集成一套服务管理,block准确至个人
+ 计划搭配前端使用
+ """
+ @staticmethod
+ def manual_reg_service(service: str):
+ file_name = service + ".json"
+ file = SERVICE_DIR / file_name
+ service_info = {
+ "name": service,
+ "docs": None,
+ "disable_group": []
+ }
+ with open(file, "w") as r:
+ r.write(json.dumps(service_info, indent=4))
+
+ @staticmethod
+ def auth_service(service: str, group: Optional[int] = None) -> bool:
+ data = _load_service_config(service)
+ return False if group in data["disable_group"] else True
+
+ @staticmethod
+ def control_service(service: str, group: int, is_enable: bool) -> None:
+ data = _load_service_config(service)
+ sv_group = data.get('disable_group', [])
+ if is_enable:
+ sv_group.remove(group)
+ log.info(f"Service {service} has been enabled.")
+ else:
+ sv_group.append(group)
+ log.info(f"Service {service} has been disabled.")
+ data["disable_group"] = sv_group
+ _save_service_config(service, data)
+
+ @staticmethod
+ def on_message(rule: Optional[Union[Rule, T_RuleChecker]] = None,
+ permission: Optional[Permission] = None,
+ *,
+ handlers: Optional[List[T_Handler]] = None,
+ temp: bool = False,
+ priority: int = 1,
+ block: bool = True,
+ state: Optional[T_State] = None) -> Type[Matcher]:
+ matcher = Matcher.new("message",
+ Rule() & rule,
+ permission or Permission(),
+ temp=temp,
+ priority=priority,
+ block=block,
+ handlers=handlers,
+ default_state=state)
+ return matcher
+
+ @staticmethod
+ def on_notice(name: str,
+ docs: str,
+ rule: Optional[Union[Rule, T_RuleChecker]] = None,
+ *,
+ handlers: Optional[List[T_Handler]] = None,
+ temp: bool = False,
+ priority: int = 1,
+ block: bool = False,
+ state: Optional[T_State] = None) -> Type[Matcher]:
+ matcher = Matcher.new("notice",
+ Rule() & rule,
+ Permission(),
+ temp=temp,
+ priority=priority,
+ block=block,
+ handlers=handlers,
+ default_state=state)
+ _load_service_config(name, docs)
+ matcher_list.append(name)
+ return matcher
+
+ @staticmethod
+ def on_request(name: str,
+ docs: str,
+ rule: Optional[Union[Rule, T_RuleChecker]] = None,
+ *,
+ handlers: Optional[List[T_Handler]] = None,
+ temp: bool = False,
+ priority: int = 1,
+ block: bool = False,
+ state: Optional[T_State] = None) -> Type[Matcher]:
+ matcher = Matcher.new("request",
+ Rule() & rule,
+ Permission(),
+ temp=temp,
+ priority=priority,
+ block=block,
+ handlers=handlers,
+ default_state=state)
+ _load_service_config(name, docs)
+ matcher_list.append(name)
+ return matcher
+
+ @classmethod
+ def on_command(cls,
+ name: str,
+ docs: str,
+ cmd: Union[str, Tuple[str, ...]],
+ rule: Optional[Union[Rule, T_RuleChecker]] = None,
+ aliases: Optional[Set[Union[str, Tuple[str, ...]]]] = None,
+ **kwargs) -> Type[Matcher]:
+ async def _strip_cmd(bot: "Bot", event: "Event", state: T_State):
+ message = event.get_message()
+ segment = message.pop(0)
+ new_message = message.__class__(
+ str(segment).lstrip()
+ [len(state["_prefix"]["raw_command"]):].lstrip()) # type: ignore
+ for new_segment in reversed(new_message):
+ message.insert(0, new_segment)
+
+ handlers = kwargs.pop("handlers", [])
+ handlers.insert(0, _strip_cmd)
+
+ commands = set([cmd]) | (aliases or set())
+ _load_service_config(name, docs)
+ matcher_list.append(name)
+ return cls.on_message(command(*commands) & rule,
+ handlers=handlers, **kwargs)
+
+ @classmethod
+ def on_keyword(cls,
+ name: str,
+ docs: str,
+ keywords: Set[str],
+ rule: Optional[Union[Rule, T_RuleChecker]] = None,
+ **kwargs) -> Type[Matcher]:
+ _load_service_config(name, docs)
+ matcher_list.append(name)
+ return cls.on_message(keyword(*keywords) & rule, **kwargs)
+
+
+ class NetworkPost:
+ URL = (
+ f"http://{config['NetworkPost']['host']}:"
+ f"{config['NetworkPost']['port']}/"
+ )
+
+ @classmethod
+ async def send_private_msg(cls,
+ user_id: int,
+ message: str,
+ auto_escape: bool = False): # -> Dict[str, Any]
+ url = cls.URL + "send_private_msg?"
+ params = {
+ "user_id": user_id,
+ "message": message,
+ "auto_escape": f"{auto_escape}"
+ }
+ result = json.loads(await post_bytes(url, params))
+ log.debug(result)
+ return result
+
+ @classmethod
+ def send_group_msg(cls,
+ group_id: int,
+ message: Union[str],
+ auto_escape: Optional[bool] = ...) -> Dict[str, Any]:
+ ...
+
+ @classmethod
+ def send_msg(cls,
+ message_type: Optional[str] = ...,
+ user_id: Optional[int] = ...,
+ group_id: Optional[int] = ...,
+ message = Union[str],
+ auto_escape: bool = ...) -> Dict[str, Any]:
+ ...
+
+ @classmethod
+ def delete_msg(cls,
+ message_id: int):
+ ...
+
+ @classmethod
+ def get_msg(cls,
+ message_id: int) -> Dict[str, Any]:
+ ...
+
+ @classmethod
+ def get_forward_msg(cls,
+ id: int):
+ ...
+
+ @classmethod
+ def send_like(cls,
+ user_id: int,
+ times: int = ...):
+ ...
+
+ @classmethod
+ def set_group_kick(cls,
+ group_id: int,
+ user_id: int,
+ reject_add_request: bool = ...):
+ ...
+
+ @classmethod
+ def set_group_ban(cls,
+ group_id: int,
+ user_id: int,
+ duration: int = ...):
+ ...
+
+ @classmethod
+ def set_group_anonymous_ban(cls,
+ group_id: int,
+ anonymous: Optional[Dict[str, Any]] = ...,
+ flag: Optional[str] = ...,
+ duration: int = ...):
+ ...
+
+ @classmethod
+ def set_group_whole_ban(cls,
+ group_id: int,
+ enable: bool = ...):
+ ...
+
+ @classmethod
+ def set_group_admin(cls,
+ group_id: int,
+ user_id: int,
+ enable: bool = ...):
+ ...
+
+ @classmethod
+ def set_group_anonymous(cls,
+ group_id: int,
+ enable: bool = ...):
+ ...
+
+ @classmethod
+ def set_group_card(cls):
+ ...
+
+ @classmethod
+ def set_group_name(cls):
+ ...
+
+ @classmethod
+ def set_group_leave(cls):
+ ...
+
+ @classmethod
+ def set_group_special_title(cls):
+ ...
+
+ @classmethod
+ def set_friend_add_request(cls):
+ ...
+
+ @classmethod
+ def set_group_add_request(cls):
+ ...
+
+ @classmethod
+ def get_login_info(cls):
+ ...
+
+ @classmethod
+ def get_stranger_info(cls):
+ ...
+
+ @classmethod
+ def get_friend_list(cls):
+ ...
+
+ @classmethod
+ def get_group_info(cls):
+ ...
+
+ @classmethod
+ def get_group_list(cls):
+ ...
+
+ @classmethod
+ def get_group_member_info(cls):
+ ...
+
+ @classmethod
+ def get_group_member_list(cls):
+ ...
+
+ @classmethod
+ def get_group_honor_info(cls):
+ ...
+
+ @classmethod
+ def get_cookies(cls):
+ ...
+
+ @classmethod
+ def get_csrf_token(cls):
+ ...
+
+ @classmethod
+ def get_credentials(cls):
+ ...
+
+ @classmethod
+ def get_record(cls):
+ ...
+
+ @classmethod
+ def get_image(cls):
+ ...
+
+ @classmethod
+ def can_send_image(cls):
+ ...
+
+ @classmethod
+ def can_send_record(cls):
+ ...
+
+ @classmethod
+ def get_status(cls):
+ ...
+
+ @classmethod
+ def get_version_info(cls):
+ ...
+
+ @classmethod
+ def set_restart(cls):
+ ...
+
+ @classmethod
+ def clean_cache(cls):
+ ...
+
+
+ class Dormant:
+ @staticmethod
+ def is_dormant() -> bool:
+ return False if is_sleep else True
+
+ @staticmethod
+ def control_dormant(is_enable: bool) -> None:
+ global is_sleep
+ if is_enable:
+ is_sleep = True
+ else:
+ is_sleep = False
+
+
+ class BlockSystem:
+ file_name = "ban.json"
+ path = SERVICE_DIR / file_name
+
+ @classmethod
+ def get_list(cls) -> dict:
+ try:
+ return json.loads(cls.path.read_bytes())
+ except:
+ with open(cls.path, "w") as r:
+ json.dump("{}", r)
+ return {}
+
+ @classmethod
+ def auth_user(cls, user: int) -> bool:
+ return False if user in cls.get_list() else True
+
+ @classmethod
+ def control_list(cls, user: int, is_enable: bool) -> None:
+ data = cls.get_list()
+ if is_enable:
+ data[user] = datetime.now().__str__
+ log.info(f"New blocked user: {user} | Time: {datetime.now()}")
+ else:
+ del data[user]
+ log.info(f"User {user} has been unblock.")
+
+ with open(cls.path, "w") as r:
+ json.dump(data, r) \ No newline at end of file
diff --git a/ATRI/service/__init__.py b/ATRI/service/__init__.py
deleted file mode 100644
index 6b18ba1..0000000
--- a/ATRI/service/__init__.py
+++ /dev/null
@@ -1,95 +0,0 @@
-import os
-import json
-from pathlib import Path
-from pydantic import BaseModel
-from typing import Optional
-
-from ATRI.log import logger
-from ATRI.exceptions import WriteError
-
-
-SERVICE_DIR = Path('.') / 'ATRI' / 'data' / 'service'
-PLUGIN_INFO_DIR = Path('.') / 'ATRI' / 'data' / 'service' / 'plugins'
-os.makedirs(SERVICE_DIR, exist_ok=True)
-os.makedirs(PLUGIN_INFO_DIR, exist_ok=True)
-
-sleep = False
-
-class Service:
- class ServiceInfo(BaseModel):
- name: str
- _type: str
- docs: Optional[str] = None
- command: Optional[list] = None
-
- @classmethod
- def register(
- cls,
- service_name: str,
- service_type: str,
- docs: Optional[str] = None,
- command: Optional[list] = None
- ) -> None:
- """
- 启动时保存各个服务信息,便于后续网页控制台调用
- 增强管理
- """
- file_name = f"{service_name}.function.json"
- path = SERVICE_DIR / file_name
- path.parent.mkdir(exist_ok=True, parents=True)
- try:
- data = json.loads(path.read_bytes())
- except:
- data = {}
-
- data = cls.ServiceInfo(
- name=service_name,
- _type=service_type,
- docs=docs,
- command=command
- )
- try:
- with open(path, 'w', encoding='utf-8') as target:
- target.write(
- json.dumps(
- data.dict(), indent=4
- )
- )
- except WriteError:
- raise WriteError("Writing file failed!")
- else:
- pass
-
- # TODO: shitcode-style
- docs_judge = "N" if not docs else "Y"
- a = " "
- log_center = ""
- log_head = f"Success register service: [{service_name}]."
- log_suffix = f"Docs [{docs_judge}]. Type [{service_type}]"
- log_head_lenght = len(log_head)
- log_suffix_lenght = len(log_suffix)
- log_center_lenght = 120 - (
- log_head_lenght + log_suffix_lenght
- )
- for _ in range(log_center_lenght): log_center = log_center + a
- log_print = log_head + log_center + log_suffix
- logger.info(log_print)
-
- @staticmethod
- def is_dormant() -> bool:
- """
- 为bot提供休眠,期间不会响应除了 superusers 以外的用户的信息
- 触发在于 Rule
- """
- return False if sleep else True
-
- @staticmethod
- def control_dormant(_type: bool) -> None:
- """
- 更改休眠状态
- """
- global sleep
- if _type:
- sleep = True
- else:
- sleep = False
diff --git a/ATRI/service/banlist.py b/ATRI/service/banlist.py
deleted file mode 100644
index e1ce6b7..0000000
--- a/ATRI/service/banlist.py
+++ /dev/null
@@ -1,53 +0,0 @@
-import json
-import aiofiles
-from typing import Optional
-
-from ATRI.exceptions import WriteError
-from . import SERVICE_DIR
-
-
-class BanSystem:
-
- file_name = "banlist.service.json"
- path = SERVICE_DIR / file_name
- path.parent.mkdir(exist_ok=True, parents=True)
- try:
- data = json.loads(path.read_bytes())
- except:
- data = {}
-
- @classmethod
- def get_list(cls) -> dict:
- return cls.data
-
- @classmethod
- def is_in_list(cls, user: Optional[str]) -> bool:
- return False if user in cls.data else True
-
- @classmethod
- async def add_to_list(cls, user: Optional[str]) -> None:
- cls.data[user] = user
- try:
- async with aiofiles.open(
- cls.path, 'w', encoding='utf-8') as target:
- await target.write(
- json.dumps(
- cls.data, indent=4
- )
- )
- except WriteError:
- raise WriteError("Writing file failed!")
-
- @classmethod
- async def del_from_list(cls, user: Optional[str]) -> None:
- del cls.data[user]
- try:
- async with aiofiles.open(
- cls.path, 'w', encoding='utf-8') as target:
- await target.write(
- json.dumps(
- cls.data, indent=4
- )
- )
- except WriteError:
- raise WriteError("Writing file failed!")
diff --git a/ATRI/service/httppost.py b/ATRI/service/httppost.py
deleted file mode 100644
index 75aff8f..0000000
--- a/ATRI/service/httppost.py
+++ /dev/null
@@ -1,216 +0,0 @@
-'''
-获取更多帮助 >> https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md
-'''
-import json
-from typing import (
- Optional,
- Union,
- Dict,
- Any
-)
-
-from ATRI.log import logger
-from ATRI.config import config
-from ATRI.utils.request import post_bytes
-
-
-URL = (
- f"http://{config['HttpPost']['host']}:"
- f"{config['HttpPost']['port']}/"
-)
-
-
-class HttpPost:
-
- @classmethod
- async def send_private_msg(cls,
- user_id: int,
- message: str,
- auto_escape: bool = False): # -> Dict[str, Any]
- url = URL + "send_private_msg?"
- params = {
- "user_id": user_id,
- "message": message,
- "auto_escape": f"{auto_escape}"
- }
- result = json.loads(await post_bytes(url, params))
- logger.debug(result)
- return result
-
- @classmethod
- def send_group_msg(cls,
- group_id: int,
- message: Union[str],
- auto_escape: Optional[bool] = ...) -> Dict[str, Any]:
- ...
-
- @classmethod
- def send_msg(cls,
- message_type: Optional[str] = ...,
- user_id: Optional[int] = ...,
- group_id: Optional[int] = ...,
- message = Union[str],
- auto_escape: bool = ...) -> Dict[str, Any]:
- ...
-
- @classmethod
- def delete_msg(cls,
- message_id: int):
- ...
-
- @classmethod
- def get_msg(cls,
- message_id: int) -> Dict[str, Any]:
- ...
-
- @classmethod
- def get_forward_msg(cls,
- id: int):
- ...
-
- @classmethod
- def send_like(cls,
- user_id: int,
- times: int = ...):
- ...
-
- @classmethod
- def set_group_kick(cls,
- group_id: int,
- user_id: int,
- reject_add_request: bool = ...):
- ...
-
- @classmethod
- def set_group_ban(cls,
- group_id: int,
- user_id: int,
- duration: int = ...):
- ...
-
- @classmethod
- def set_group_anonymous_ban(cls,
- group_id: int,
- anonymous: Optional[Dict[str, Any]] = ...,
- flag: Optional[str] = ...,
- duration: int = ...):
- ...
-
- @classmethod
- def set_group_whole_ban(cls,
- group_id: int,
- enable: bool = ...):
- ...
-
- @classmethod
- def set_group_admin(cls,
- group_id: int,
- user_id: int,
- enable: bool = ...):
- ...
-
- @classmethod
- def set_group_anonymous(cls,
- group_id: int,
- enable: bool = ...):
- ...
-
- @classmethod
- def set_group_card(cls):
- ...
-
- @classmethod
- def set_group_name(cls):
- ...
-
- @classmethod
- def set_group_leave(cls):
- ...
-
- @classmethod
- def set_group_special_title(cls):
- ...
-
- @classmethod
- def set_friend_add_request(cls):
- ...
-
- @classmethod
- def set_group_add_request(cls):
- ...
-
- @classmethod
- def get_login_info(cls):
- ...
-
- @classmethod
- def get_stranger_info(cls):
- ...
-
- @classmethod
- def get_friend_list(cls):
- ...
-
- @classmethod
- def get_group_info(cls):
- ...
-
- @classmethod
- def get_group_list(cls):
- ...
-
- @classmethod
- def get_group_member_info(cls):
- ...
-
- @classmethod
- def get_group_member_list(cls):
- ...
-
- @classmethod
- def get_group_honor_info(cls):
- ...
-
- @classmethod
- def get_cookies(cls):
- ...
-
- @classmethod
- def get_csrf_token(cls):
- ...
-
- @classmethod
- def get_credentials(cls):
- ...
-
- @classmethod
- def get_record(cls):
- ...
-
- @classmethod
- def get_image(cls):
- ...
-
- @classmethod
- def can_send_image(cls):
- ...
-
- @classmethod
- def can_send_record(cls):
- ...
-
- @classmethod
- def get_status(cls):
- ...
-
- @classmethod
- def get_version_info(cls):
- ...
-
- @classmethod
- def set_restart(cls):
- ...
-
- @classmethod
- def clean_cache(cls):
- ...
diff --git a/ATRI/service/limit.py b/ATRI/service/limit.py
deleted file mode 100644
index 2ea3f95..0000000
--- a/ATRI/service/limit.py
+++ /dev/null
@@ -1,53 +0,0 @@
-import json
-from pathlib import Path
-from typing import Optional
-
-from ATRI.utils.file import write_file
-from . import SERVICE_DIR
-
-
-class Limit:
- @staticmethod
- def _get_file(group: Optional[int] = None) -> Path:
- file_name = f"{group}.service.json"
- LIMIT_DIR = SERVICE_DIR / "limit"
- path = LIMIT_DIR / file_name
-
- if not LIMIT_DIR.exists():
- LIMIT_DIR.mkdir()
- return path
-
- @classmethod
- def _read_file(cls, group: Optional[int] = None) -> dict:
- try:
- data = json.loads(cls._get_file(group).read_bytes())
- except:
- data = {}
- return data
-
- @classmethod
- async def auth_service(cls, service: str, group: Optional[int] = None) -> bool:
- data = cls._read_file(group)
- if service not in data:
- data[service] = True
- await write_file(cls._get_file(group), json.dumps(data))
-
- if data[service]:
- return True
- else:
- return False
-
- @classmethod
- async def control_service(
- cls,
- service: str,
- status: bool,
- group: Optional[int] = None
- ) -> None:
- data = cls._read_file(group)
- if service not in data:
- data[service] = True
- await write_file(cls._get_file(group), json.dumps(data))
-
- data[service] = status
- await write_file(cls._get_file(group), json.dumps(data))
diff --git a/ATRI/utils/file.py b/ATRI/utils/file.py
index 4699f5d..7afbead 100644
--- a/ATRI/utils/file.py
+++ b/ATRI/utils/file.py
@@ -1,7 +1,10 @@
import aiofiles
+import urllib
from pathlib import Path
-from ATRI.exceptions import WriteError
+from ATRI.exceptions import RequestTimeOut, WriteError
+
+from .request import get_content
async def write_file(path: Path, text, encoding='utf-8') -> None:
diff --git a/ATRI/utils/request.py b/ATRI/utils/request.py
index 31285e8..145b470 100644
--- a/ATRI/utils/request.py
+++ b/ATRI/utils/request.py
@@ -18,6 +18,13 @@ async def get_bytes(url: str, headers: Optional[dict] = None) -> bytes:
return result
+async def get_content(url: str, headers: Optional[dict] = None):
+ async with ClientSession() as session:
+ async with session.get(url, headers=headers) as r:
+ result = await r.content.read()
+ return result
+
+
async def post_bytes(url: str,
params: Optional[dict] = None,
json: Optional[dict] = None) -> bytes:
diff --git a/config.yml b/config.yml
index 3a73f28..d405530 100644
--- a/config.yml
+++ b/config.yml
@@ -1,3 +1,8 @@
+/*
+ * File: config.yml
+ * Project: https://github.com/Kyomotoi/ATRI
+ */
+
BotSelfConfig:
host: "127.0.0.1"
port: 25565
@@ -9,6 +14,10 @@ BotSelfConfig:
session_expire_timeout: 3
session_exciting_time: 3
-HttpPost:
+NetworkPost:
+ host: "127.0.0.1"
+ port: 23333
+
+AdminPage:
host: "127.0.0.1"
- port: 23333 \ No newline at end of file
+ port: 11451 \ No newline at end of file
diff --git a/main.py b/main.py
index 1d3afbe..d80d30c 100644
--- a/main.py
+++ b/main.py
@@ -1,44 +1,23 @@
#!/usr/bin/env python3
-# -*- encoding: utf-8 -*-
-
+# -*- coding:utf-8 -*-
'''
-@File : main.py
-@Time : 2021/02/02 15:51:44
-@Author : Kyomotoi
-@Contact : [email protected]
-@Github : https://github.com/Kyomotoi
-@License : Copyright © 2018-2021 Kyomotoi, All Rights Reserved.
+File: main.py
+Created Date: 2021-02-02 15:51:30
+Author: Kyomotoi
+License: GPLv3
+Project: https://github.com/Kyomotoi/ATRI
+--------
+Last Modified: Sunday, 7th March 2021 12:25:07 pm
+Modified By: Kyomotoi ([email protected])
+--------
+Copyright (c) 2021 Kyomotoi
'''
-__author__ = 'kyomotoi'
-
-from time import sleep
-from os import get_terminal_size
-
-import nonebot
-from nonebot.adapters.cqhttp import Bot as CQHTTPBot
-
-from ATRI.log import logger
-from ATRI.config import RUNTIME_CONFIG, COPYRIGHT, VERSION
-
-
-try:
- width, height = get_terminal_size()
-except OSError:
- width, height = 0, 0
-nonebot.init(**RUNTIME_CONFIG)
-app = nonebot.get_asgi()
-driver = nonebot.get_driver()
-driver.register_adapter("cqhttp", CQHTTPBot)
-nonebot.load_plugins('ATRI/plugins')
+import ATRI
+ATRI.init()
+app = ATRI.asgi()
-if __name__ == "__main__":
- logger.warning(
- '\n'.join(
- i.center(width) for i in COPYRIGHT.splitlines()
- )
- )
- logger.info(f"Now running: {VERSION}")
- sleep(3)
- nonebot.run(app='main:app')
+if __name__ == '__main__':
+ ATRI.run('main:app')