Added logging, fixed some typos in core

This commit is contained in:
Adriene Hutchins 2020-03-03 14:03:50 -05:00
parent 6ff7d823cb
commit 91709f3957
6 changed files with 68 additions and 12 deletions

View File

@ -0,0 +1,51 @@
# -*- coding: utf-8 -*-
# Search Functionality
# Provides search results from SearX
'''Search Cog'''
import discord
from discord.ext import commands
class BetterLogging(commands.Cog):
"""Provides more logging for certain events with utils.logging."""
def __init__(self, bot):
# Main Stuff
self.bot = bot
self.request = bot.request
self.emoji = "\U0001F4CB"
# Loggers
self.info = bot.logging.info
self.warn = bot.logging.warn
self.error = bot.logging.error
self.debug = bot.logging.debug
@commands.Cog.listener()
async def on_guild_join(self, guild):
msg = f"\U0001F4C8 **Joined {guild.name}**\n\n"
msg += f"_Owner:_ {guild.owner}\n"
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")
@commands.Cog.listener()
async def on_guild_remove(self, guild):
msg = f"**\U0001F4C9 Left {guild.name}**\n\n"
msg += f"_Owner:_ {guild.owner}\n"
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")
async def cog_check(self, ctx):
return commands.is_owner()(ctx.command)
def setup(bot):
bot.add_cog(BetterLogging(bot))

View File

@ -74,11 +74,13 @@ class Core(commands.Cog):
msg = (
"**Thanks for checking me out!**\n\n"
"Use the following link to add me:\n"
f"*<https://discordapp.com/oauth2/authorize?client_id={self.bot.user.id}&scope=bot>*"
f"*<https://discordapp.com/oauth2/authorize?client_id={self.bot.user.id}&scope=bot"
)
if self.bot.config['PERMS'] is not None:
msg += f"&permissions={self.bot.config['PERMS']}"
msg += f"&permissions={self.bot.config['PERMS']}>*"
else:
msg += ">*"
await ctx.send(msg)
@ -208,11 +210,15 @@ Number of extensions present: {len(ctx.bot.cogs)}
@commands.is_owner()
async def leave(self, ctx):
"""Makes the bot leave the server this was called in."""
await ctx.send(
"\U0001F4A8 **Leaving server.**"
"_If you want me back, add me or get an admin to._")
await ctx.guild.leave()
if ctx.guild:
await ctx.send(
"\U0001F4A8 **Leaving server.** "
"_If you want me back, add me or get an admin to._")
await ctx.guild.leave()
else:
await ctx.send(
"**Can't leave!** _This channel is not inside a guild_")
def cog_unload(self):
self.bot.help_command = self._original_help_command

View File

@ -53,7 +53,6 @@ class Logging():
formatted_tb = ''.join(formatted_tb)
original_exc = traceback.format_exception(
type(error), error, error.__traceback__)
print(original_exc)
# Hastebins Traceback
try:

View File

@ -18,11 +18,11 @@ class Online():
async def hastebin(self, string):
"""Posts a string to hastebin."""
url = "https://hastebin.com/documents"
url = "https://hasteb.in/documents"
data = string.encode('utf-8')
async with self.request.post(url=url, data=data) as haste_response:
haste_key = (await haste_response.json())['key']
haste_url = f"http://hastebin.com/{haste_key}"
haste_url = f"http://hasteb.in/{haste_key}"
return haste_url
def get_webhook(self, url: str):

View File

@ -198,14 +198,14 @@ async def on_command_error(ctx, error):
# Prerequisites
embed_fallback = f"**An error occured: {type(error).__name__}. Please contact {bot.appinfo.owner}.**"
error_embed = await bot.logging.error(error, ctx, ctx.command.cog.__name__)
error_embed = await bot.logging.error(error, ctx, ctx.command.cog.qualified_name)
# Sending
await ctx.send(embed_fallback, embed=error_embed)
# If anything else goes wrong, just go ahead and send it in chat.
else:
await bot.logging.error(error, ctx, ctx.command.cog.__name__)
await bot.logging.error(error, ctx, ctx.command.cog.qualified_name)
await ctx.send(error)
# NOTE Bot Entry Point
# Starts the bot