fix(commands:iplocalise|Network): close TUXBOT-BOT-4T, close TUXBOT-BOT-4S
This commit is contained in:
parent
f8f56add97
commit
09e69166ad
3 changed files with 23 additions and 7 deletions
|
@ -120,15 +120,26 @@ async def get_ipwhois_result(loop, ip: str) -> NoReturn | dict:
|
||||||
cache=Cache.MEMORY,
|
cache=Cache.MEMORY,
|
||||||
namespace="network",
|
namespace="network",
|
||||||
)
|
)
|
||||||
async def get_ipinfo_result(apikey: str, ip: str) -> dict:
|
async def get_ipinfo_result(loop, apikey: str, ip: str) -> dict:
|
||||||
|
def _get_ipinfo_result(_ip: str) -> NoReturn | dict:
|
||||||
|
"""
|
||||||
|
Q. Why no getHandlerAsync ?
|
||||||
|
A. Use of this return "Unclosed client session" and "Unclosed connector"
|
||||||
|
"""
|
||||||
try:
|
try:
|
||||||
handler = ipinfo.getHandlerAsync(
|
handler = ipinfo.getHandler(apikey, request_options={"timeout": 7})
|
||||||
apikey, request_options={"timeout": 7}
|
return (handler.getDetails(ip)).all
|
||||||
)
|
|
||||||
return (await handler.getDetails(ip)).all
|
|
||||||
except RequestQuotaExceededError:
|
except RequestQuotaExceededError:
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
|
try:
|
||||||
|
return await asyncio.wait_for(
|
||||||
|
loop.run_in_executor(None, _get_ipinfo_result, str(ip)),
|
||||||
|
timeout=8,
|
||||||
|
)
|
||||||
|
except asyncio.exceptions.TimeoutError:
|
||||||
|
return {}
|
||||||
|
|
||||||
|
|
||||||
@cached(
|
@cached(
|
||||||
ttl=24 * 3600,
|
ttl=24 * 3600,
|
||||||
|
|
|
@ -103,6 +103,8 @@ class Network(commands.Cog):
|
||||||
self._peeringdb_net = await s.json()
|
self._peeringdb_net = await s.json()
|
||||||
except asyncio.exceptions.TimeoutError:
|
except asyncio.exceptions.TimeoutError:
|
||||||
pass
|
pass
|
||||||
|
else:
|
||||||
|
log.log(logging.INFO, "_update_peering_db")
|
||||||
|
|
||||||
# =========================================================================
|
# =========================================================================
|
||||||
# =========================================================================
|
# =========================================================================
|
||||||
|
@ -126,7 +128,7 @@ class Network(commands.Cog):
|
||||||
ip_hostname = await get_hostname(self.bot.loop, str(ip_address))
|
ip_hostname = await get_hostname(self.bot.loop, str(ip_address))
|
||||||
|
|
||||||
ipinfo_result = await get_ipinfo_result(
|
ipinfo_result = await get_ipinfo_result(
|
||||||
self.__config.ipinfoKey, ip_address
|
self.bot.loop, self.__config.ipinfoKey, ip_address
|
||||||
)
|
)
|
||||||
ipwhois_result = await get_ipwhois_result(self.bot.loop, ip_address)
|
ipwhois_result = await get_ipwhois_result(self.bot.loop, ip_address)
|
||||||
|
|
||||||
|
|
|
@ -332,7 +332,10 @@ class Tux(commands.AutoShardedBot):
|
||||||
self.console.log(
|
self.console.log(
|
||||||
"Canceling", task.get_name(), f"({task.get_coro()})"
|
"Canceling", task.get_name(), f"({task.get_coro()})"
|
||||||
)
|
)
|
||||||
|
try:
|
||||||
task.cancel()
|
task.cancel()
|
||||||
|
except Exception as e:
|
||||||
|
self.console.log(e)
|
||||||
await asyncio.gather(*pending, return_exceptions=False)
|
await asyncio.gather(*pending, return_exceptions=False)
|
||||||
|
|
||||||
await super().close()
|
await super().close()
|
||||||
|
|
Loading…
Reference in a new issue