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,13 +120,24 @@ async def get_ipwhois_result(loop, ip: str) -> NoReturn | dict:
|
|||
cache=Cache.MEMORY,
|
||||
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:
|
||||
handler = ipinfo.getHandler(apikey, request_options={"timeout": 7})
|
||||
return (handler.getDetails(ip)).all
|
||||
except RequestQuotaExceededError:
|
||||
return {}
|
||||
|
||||
try:
|
||||
handler = ipinfo.getHandlerAsync(
|
||||
apikey, request_options={"timeout": 7}
|
||||
return await asyncio.wait_for(
|
||||
loop.run_in_executor(None, _get_ipinfo_result, str(ip)),
|
||||
timeout=8,
|
||||
)
|
||||
return (await handler.getDetails(ip)).all
|
||||
except RequestQuotaExceededError:
|
||||
except asyncio.exceptions.TimeoutError:
|
||||
return {}
|
||||
|
||||
|
||||
|
|
|
@ -103,6 +103,8 @@ class Network(commands.Cog):
|
|||
self._peeringdb_net = await s.json()
|
||||
except asyncio.exceptions.TimeoutError:
|
||||
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))
|
||||
|
||||
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)
|
||||
|
||||
|
|
|
@ -332,7 +332,10 @@ class Tux(commands.AutoShardedBot):
|
|||
self.console.log(
|
||||
"Canceling", task.get_name(), f"({task.get_coro()})"
|
||||
)
|
||||
task.cancel()
|
||||
try:
|
||||
task.cancel()
|
||||
except Exception as e:
|
||||
self.console.log(e)
|
||||
await asyncio.gather(*pending, return_exceptions=False)
|
||||
|
||||
await super().close()
|
||||
|
|
Loading…
Reference in a new issue