summaryrefslogtreecommitdiff
path: root/ATRI/plugins
diff options
context:
space:
mode:
authorRuoqi Yang <[email protected]>2022-11-12 19:48:17 +0800
committerRuoqi Yang <[email protected]>2022-11-12 19:49:45 +0800
commit1edec27af9e44b75d8d5db2830b544f89646bd87 (patch)
tree28d798b6f6298a15302d8ed1899fd233c2980aa6 /ATRI/plugins
parentbea3e0c4d36e66f7e69bf1e245dfed2eaf511862 (diff)
downloadATRI-1edec27af9e44b75d8d5db2830b544f89646bd87.tar.gz
ATRI-1edec27af9e44b75d8d5db2830b544f89646bd87.tar.bz2
ATRI-1edec27af9e44b75d8d5db2830b544f89646bd87.zip
refactor plugin anti_effort and geoip
Diffstat (limited to 'ATRI/plugins')
-rw-r--r--ATRI/plugins/anti_effort/__init__.py2
-rw-r--r--ATRI/plugins/geoip.py14
2 files changed, 13 insertions, 3 deletions
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}"
+ )