From 8aba97ec5c4d9dd001e01427defd9bbd6bdb47cf Mon Sep 17 00:00:00 2001 From: Ruoqi Yang Date: Sat, 12 Nov 2022 18:56:50 +0800 Subject: fix: add friend request handling --- ATRI/plugins/essential/__init__.py | 4 ++-- ATRI/plugins/manage/__init__.py | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'ATRI/plugins') diff --git a/ATRI/plugins/essential/__init__.py b/ATRI/plugins/essential/__init__.py index 4635583..020653e 100644 --- a/ATRI/plugins/essential/__init__.py +++ b/ATRI/plugins/essential/__init__.py @@ -45,7 +45,7 @@ friend_add_event = plugin.on_request("好友申请", "好友申请检测") @friend_add_event.handle() -async def _(event: FriendRequestEvent): +async def _(bot: Bot, event: FriendRequestEvent): path = __ESSENTIAL_DIR / "friend_add.json" file = FileDealer(path) if not path.is_file(): @@ -62,7 +62,7 @@ async def _(event: FriendRequestEvent): user_id=user_id, comment=apply_comment, time=now_time, - ) + ).dict() await file.write(json.dumps(data)) result = ( diff --git a/ATRI/plugins/manage/__init__.py b/ATRI/plugins/manage/__init__.py index 0268ec9..03de2fe 100644 --- a/ATRI/plugins/manage/__init__.py +++ b/ATRI/plugins/manage/__init__.py @@ -290,6 +290,8 @@ async def _deal_approve_friend_add( except Exception: await approve_friend_add.finish("同意失败...尝试下手动?") data = Manage().load_friend_apply_list() + if apply_code not in data: + await approve_friend_add.reject("申请码不存在...请检查是否输入正确") data.pop(apply_code) Manage().save_friend_apply_list(data) await approve_friend_add.finish("好欸!申请已通过!") -- cgit v1.2.3 From b251cd28e24c08e9170a11535fc121441b324d4f Mon Sep 17 00:00:00 2001 From: Ruoqi Yang Date: Thu, 10 Nov 2022 12:29:10 +0800 Subject: add plugin: geoip loopup --- ATRI/plugins/geoip.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 ATRI/plugins/geoip.py (limited to 'ATRI/plugins') diff --git a/ATRI/plugins/geoip.py b/ATRI/plugins/geoip.py new file mode 100644 index 0000000..a6521c2 --- /dev/null +++ b/ATRI/plugins/geoip.py @@ -0,0 +1,28 @@ +from nonebot.params import ArgStr +import geoip2.webservice +from ATRI.service import Service +from ATRI import conf + + +geoip = Service("GEOIP查询").document("search ip in MaxMind GEOIP databases") + +query_geoip = geoip.on_command("ip查询", "查询IP的地理位置", aliases={"IP查询", "查询IP"}) + +LANG = "zh-CN" + + +@query_geoip.got("ip_address", prompt="地址是?(支持ipv4/ipv6)") +async def _(ip_address: str = ArgStr()): + with geoip2.webservice.Client(conf.GeoIP.account_id, + conf.GeoIP.license_key, + host="geolite.info") as client: + response = client.city(ip_address) + country = response.country.names[LANG] + city = response.city.names[LANG] + subdivision = "" + if response.subdivisions: + subdivision = response.subdivisions[0].names[LANG] + await query_geoip.finish( + f"IP: {ip_address}\n" + f"{country}{subdivision}{city}" + ) -- cgit v1.2.3 From 751980112e14f0c86e3760c2595c46bf96fe5cfd Mon Sep 17 00:00:00 2001 From: Ruoqi Yang Date: Sat, 12 Nov 2022 19:23:36 +0800 Subject: remove unused parameter --- ATRI/plugins/essential/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ATRI/plugins') diff --git a/ATRI/plugins/essential/__init__.py b/ATRI/plugins/essential/__init__.py index 020653e..f8e3cb1 100644 --- a/ATRI/plugins/essential/__init__.py +++ b/ATRI/plugins/essential/__init__.py @@ -45,7 +45,7 @@ friend_add_event = plugin.on_request("好友申请", "好友申请检测") @friend_add_event.handle() -async def _(bot: Bot, event: FriendRequestEvent): +async def _(event: FriendRequestEvent): path = __ESSENTIAL_DIR / "friend_add.json" file = FileDealer(path) if not path.is_file(): -- cgit v1.2.3 From 009c3e9242038d6880a80b65378e4b2051d12530 Mon Sep 17 00:00:00 2001 From: Lint Action Date: Sat, 12 Nov 2022 11:26:37 +0000 Subject: =?UTF-8?q?:rotating=5Flight:=20=E8=87=AA=E5=8A=A8=E8=BF=9B?= =?UTF-8?q?=E8=A1=8C=E4=BB=A3=E7=A0=81=E6=A0=BC=E5=BC=8F=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ATRI/plugins/geoip.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'ATRI/plugins') diff --git a/ATRI/plugins/geoip.py b/ATRI/plugins/geoip.py index a6521c2..fe09ab2 100644 --- a/ATRI/plugins/geoip.py +++ b/ATRI/plugins/geoip.py @@ -13,16 +13,13 @@ LANG = "zh-CN" @query_geoip.got("ip_address", prompt="地址是?(支持ipv4/ipv6)") async def _(ip_address: str = ArgStr()): - with geoip2.webservice.Client(conf.GeoIP.account_id, - conf.GeoIP.license_key, - host="geolite.info") as client: + with geoip2.webservice.Client( + conf.GeoIP.account_id, conf.GeoIP.license_key, host="geolite.info" + ) as client: response = client.city(ip_address) country = response.country.names[LANG] city = response.city.names[LANG] subdivision = "" if response.subdivisions: subdivision = response.subdivisions[0].names[LANG] - await query_geoip.finish( - f"IP: {ip_address}\n" - f"{country}{subdivision}{city}" - ) + await query_geoip.finish(f"IP: {ip_address}\n" f"{country}{subdivision}{city}") -- cgit v1.2.3 From 1edec27af9e44b75d8d5db2830b544f89646bd87 Mon Sep 17 00:00:00 2001 From: Ruoqi Yang Date: Sat, 12 Nov 2022 19:48:17 +0800 Subject: refactor plugin anti_effort and geoip --- ATRI/plugins/anti_effort/__init__.py | 2 ++ ATRI/plugins/geoip.py | 14 +++++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) (limited to 'ATRI/plugins') diff --git a/ATRI/plugins/anti_effort/__init__.py b/ATRI/plugins/anti_effort/__init__.py index aa38f78..f44869f 100644 --- a/ATRI/plugins/anti_effort/__init__.py +++ b/ATRI/plugins/anti_effort/__init__.py @@ -225,6 +225,8 @@ async def _(): raw_data = json.loads(file_path.read_bytes()) data = raw_data["data"] data = sorted(data, key=lambda x: x["recent_count"], reverse=True) + if len(data) == 0: + continue winner = data[0] winner_id = int(winner["user_id"]) winner_nickname = winner["user_nickname"] diff --git a/ATRI/plugins/geoip.py b/ATRI/plugins/geoip.py index fe09ab2..bbe8d60 100644 --- a/ATRI/plugins/geoip.py +++ b/ATRI/plugins/geoip.py @@ -16,10 +16,18 @@ async def _(ip_address: str = ArgStr()): with geoip2.webservice.Client( conf.GeoIP.account_id, conf.GeoIP.license_key, host="geolite.info" ) as client: + await query_geoip.send("正在查询...请稍候") response = client.city(ip_address) country = response.country.names[LANG] city = response.city.names[LANG] + org = response.traits.autonomous_system_organization + network = str(response.traits.network) subdivision = "" - if response.subdivisions: - subdivision = response.subdivisions[0].names[LANG] - await query_geoip.finish(f"IP: {ip_address}\n" f"{country}{subdivision}{city}") + if subs := response.subdivisions: + subdivision = subs[0].names[LANG] + await query_geoip.finish( + f"IP: {ip_address}\n" + f"{country}{subdivision}{city}\n" + f"运营商{org}\n" + f"网段{network}" + ) -- cgit v1.2.3