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"_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()
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"_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()
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'}\"_."
)
await self.info(content=msg, name="Command Call")
self.info(content=msg, name="Command Call")
async def cog_check(self, ctx):
return commands.is_owner()(ctx.command)

View File

@ -116,7 +116,7 @@ class BotList(commands.Cog, name='Bot List'):
responses['dad'] = resp.status
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
return responses

View File

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

View File

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

View File

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