diff options
Diffstat (limited to 'ATRI')
-rw-r--r-- | ATRI/configs/default_config.yml | 4 | ||||
-rw-r--r-- | ATRI/configs/models.py | 6 | ||||
-rw-r--r-- | ATRI/plugins/anti_effort/__init__.py | 2 | ||||
-rw-r--r-- | ATRI/plugins/geoip.py | 33 | ||||
-rw-r--r-- | ATRI/plugins/manage/__init__.py | 2 | ||||
-rw-r--r-- | ATRI/utils/request.py | 6 |
6 files changed, 53 insertions, 0 deletions
diff --git a/ATRI/configs/default_config.yml b/ATRI/configs/default_config.yml index 34ab716..ab8a3bd 100644 --- a/ATRI/configs/default_config.yml +++ b/ATRI/configs/default_config.yml @@ -33,3 +33,7 @@ SauceNAO: Setu: reverse_proxy: true reverse_proxy_domain: "i.pixiv.re" + +GeoIP: + account_id: + license_key: diff --git a/ATRI/configs/models.py b/ATRI/configs/models.py index a23d7f2..8e8869d 100644 --- a/ATRI/configs/models.py +++ b/ATRI/configs/models.py @@ -40,12 +40,18 @@ class Setu(BaseModel): reverse_proxy_domain: str +class GeoIP(BaseModel): + account_id: str + license_key: str + + class ConfigModel(BaseModel): ConfigVersion: str BotConfig: BotConfig WithGoCQHTTP: WithGoCQHTTP SauceNAO: SauceNAO Setu: Setu + GeoIP: GeoIP class RuntimeConfig(BaseModel): 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 new file mode 100644 index 0000000..bbe8d60 --- /dev/null +++ b/ATRI/plugins/geoip.py @@ -0,0 +1,33 @@ +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: + 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 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}" + ) 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("好欸!申请已通过!") diff --git a/ATRI/utils/request.py b/ATRI/utils/request.py index 8310116..28640c6 100644 --- a/ATRI/utils/request.py +++ b/ATRI/utils/request.py @@ -23,3 +23,9 @@ async def post(url: str, **kwargs): log.debug(f"POST {url} by {proxy if proxy else 'No proxy'} | MORE: \n {kwargs}") async with httpx.AsyncClient(proxies=proxy, timeout=timeout) as client: # type: ignore return await client.post(url, **kwargs) + + +async def delete(url: str, **kwargs): + log.debug(f"DELETE {url} by {proxy if proxy else 'No proxy'} | MORE: \n {kwargs}") + async with httpx.AsyncClient(proxies=proxy, timeout=timeout) as client: # type: ignore + return await client.delete(url, **kwargs) |