Made logging not block.

This commit is contained in:
Adriene Hutchins 2020-04-07 19:56:01 -04:00
parent c64e52b865
commit e36d60ef24
5 changed files with 48 additions and 42 deletions

View File

@ -34,7 +34,7 @@ class BetterLogging(commands.Cog):
msg += f"_Member Count:_ {guild.member_count}\n\n" msg += f"_Member Count:_ {guild.member_count}\n\n"
msg += f"_Guild Count now {len(self.bot.guilds)}._" msg += f"_Guild Count now {len(self.bot.guilds)}._"
await self.info(content=msg, name="Guild Join") self.info(content=msg, name="Guild Join")
@commands.Cog.listener() @commands.Cog.listener()
async def on_guild_remove(self, guild): async def on_guild_remove(self, guild):
@ -45,7 +45,7 @@ class BetterLogging(commands.Cog):
msg += f"_Member Count:_ {guild.member_count}\n\n" msg += f"_Member Count:_ {guild.member_count}\n\n"
msg += f"_Guild Count now {len(self.bot.guilds)}._" msg += f"_Guild Count now {len(self.bot.guilds)}._"
await self.info(content=msg, name="Guild Leave") self.info(content=msg, name="Guild Leave")
@commands.Cog.listener() @commands.Cog.listener()
async def on_command(self, ctx): async def on_command(self, ctx):
@ -56,7 +56,7 @@ class BetterLogging(commands.Cog):
f"**{ctx.author}** in _\"{ctx.guild if ctx.guild else 'DMs'}\"_." f"**{ctx.author}** in _\"{ctx.guild if ctx.guild else 'DMs'}\"_."
) )
await self.info(content=msg, name="Command Call") self.info(content=msg, name="Command Call")
async def cog_check(self, ctx): async def cog_check(self, ctx):
return commands.is_owner()(ctx.command) return commands.is_owner()(ctx.command)

View File

@ -116,7 +116,7 @@ class BotList(commands.Cog, name='Bot List'):
responses['dad'] = resp.status responses['dad'] = resp.status
log_msg = f"**Botlists updated!**\n\n```{responses}```" log_msg = f"**Botlists updated!**\n\n```{responses}```"
await self.debug(content=log_msg, name='List Update') self.debug(content=log_msg, name='List Update')
# Finalization # Finalization
return responses return responses

View File

@ -102,7 +102,7 @@ class Search(commands.Cog, name="Basic"):
f"&url={quote_plus(search_url)}" f"&url={quote_plus(search_url)}"
) )
await self.debug(search_url, name="_search_logic") self.debug(search_url, name="_search_logic")
# Searching # Searching
headers = { headers = {
@ -113,7 +113,6 @@ class Search(commands.Cog, name="Basic"):
} }
async with self.request.get(search_url, headers=headers) as resp: async with self.request.get(search_url, headers=headers) as resp:
to_parse = await resp.json() to_parse = await resp.json()
print(to_parse)
# Sends results # Sends results
return to_parse['data']['result']['items'] return to_parse['data']['result']['items']
@ -169,8 +168,6 @@ class Search(commands.Cog, name="Basic"):
f"{other_msg}\n\n_Powered by Qwant._" f"{other_msg}\n\n_Powered by Qwant._"
) )
print(msg)
msg = re.sub( msg = re.sub(
r'(https?://(?:www\.)?[-a-zA-Z0-9@:%._+~#=]+\.' r'(https?://(?:www\.)?[-a-zA-Z0-9@:%._+~#=]+\.'
r'[a-zA-Z0-9()]+\b[-a-zA-Z0-9()@:%_+.~#?&/=]*)', r'[a-zA-Z0-9()]+\b[-a-zA-Z0-9()@:%_+.~#?&/=]*)',
@ -180,7 +177,7 @@ class Search(commands.Cog, name="Basic"):
# Sends message # Sends message
await self.info( self.info(
f"**New Search** - `{ctx.author}` in `{ctx.guild}`\n\n{msg}", f"**New Search** - `{ctx.author}` in `{ctx.guild}`\n\n{msg}",
name="New Search" name="New Search"
) )

View File

@ -8,6 +8,7 @@
import traceback import traceback
from typing import Optional from typing import Optional
import asyncio
import discord import discord
from discord.ext.commands import Context from discord.ext.commands import Context
@ -96,13 +97,14 @@ class Logging():
# Provides completed embed # Provides completed embed
return error_embed return error_embed
async def info(self, content: str, def info(self, content: str,
embed: Optional[discord.Embed] = None, embed: Optional[discord.Embed] = None,
name: Optional[str] = None): name: Optional[str] = None):
"""Logs info and sends it to the appropriate places.""" """Logs info and sends it to the appropriate places."""
if self.info_hook: if self.info_hook:
return await self.info_hook.send( async def task():
await self.info_hook.send(
content=content, content=content,
username=( username=(
f"{self.bot.user.name} - {name if name else 'unknown'}" f"{self.bot.user.name} - {name if name else 'unknown'}"
@ -110,16 +112,18 @@ class Logging():
avatar_url=str(self.bot.user.avatar_url), avatar_url=str(self.bot.user.avatar_url),
embed=embed embed=embed
) )
asyncio.create_task(task())
else: else:
return return
async def warn(self, content: str, def warn(self, content: str, embed: Optional[discord.Embed] = None,
embed: Optional[discord.Embed] = None,
name: Optional[str] = None): name: Optional[str] = None):
"""Logs warnings and sends them to the appropriate places.""" """Logs warnings and sends them to the appropriate places."""
if self.warn_hook: if self.warn_hook:
return await self.warn_hook.send( async def task():
await self.warn_hook.send(
content=content, content=content,
username=( username=(
f"{self.bot.user.name} - {name if name else 'unknown'}" f"{self.bot.user.name} - {name if name else 'unknown'}"
@ -127,6 +131,8 @@ class Logging():
avatar_url=str(self.bot.user.avatar_url), avatar_url=str(self.bot.user.avatar_url),
embed=embed embed=embed
) )
asyncio.create_task(task())
else: else:
return return
@ -168,13 +174,14 @@ class Logging():
) )
return error_embed return error_embed
async def debug(self, content: str, def debug(self, content: str,
embed: Optional[discord.Embed] = None, embed: Optional[discord.Embed] = None,
name: Optional[str] = None): name: Optional[str] = None):
"""Logs warnings and sends them to the appropriate places.""" """Logs warnings and sends them to the appropriate places."""
if self.debug_hook and (self.maintenance or self.debug_toggle): if self.debug_hook and (self.maintenance or self.debug_toggle):
return await self.debug_hook.send( async def task():
await self.debug_hook.send(
content=f"```{content}```", content=f"```{content}```",
username=( username=(
f"{self.bot.user.name} - {name if name else 'unknown'}" f"{self.bot.user.name} - {name if name else 'unknown'}"
@ -182,6 +189,8 @@ class Logging():
avatar_url=str(self.bot.user.avatar_url), avatar_url=str(self.bot.user.avatar_url),
embed=embed embed=embed
) )
asyncio.create_task(task())
else: else:
return return

View File

@ -113,7 +113,7 @@
# Reached if error with returned results # Reached if error with returned results
except (KeyError, IndexError) as e: except (KeyError, IndexError) as e:
# Logging # Logging
await self.warn( self.warn(
f"A user encountered a(n) `{e}` with <{instance}> when searching for `{query}`. " f"A user encountered a(n) `{e}` with <{instance}> when searching for `{query}`. "
"Consider removing it or looking into it.", "Consider removing it or looking into it.",
name="Failed Instance" name="Failed Instance"
@ -201,7 +201,7 @@
msg = await self._old_search_logic(query, is_nsfw, category) msg = await self._old_search_logic(query, is_nsfw, category)
await ctx.send(msg) await ctx.send(msg)
await self.info( self.info(
content=( content=(
f"**{ctx.author}** searched for `{query}` " f"**{ctx.author}** searched for `{query}` "
f"in \"{ctx.guild}\" and got this:" f"in \"{ctx.guild}\" and got this:"