searchbot-discord/extensions/betterlogging.py

67 lines
1.8 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
2020-03-05 06:02:20 +00:00
# Better Logging
# Adds some better logging with utils.logging.
2020-03-05 06:02:20 +00:00
'''Better Logging 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):
2020-03-04 00:42:35 +00:00
"""Logs guild joining."""
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):
2020-03-04 00:42:35 +00:00
"""Logs guild leaving."""
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")
2020-03-04 00:42:35 +00:00
@commands.Cog.listener()
async def on_command(self, ctx):
"""Logs command calls."""
msg = (
f"**`{ctx.command.name}`** called by "
2020-03-04 00:48:40 +00:00
f"**{ctx.author}** in _\"{ctx.guild if ctx.guild else 'DMs'}\"_."
2020-03-04 00:42:35 +00:00
)
2020-03-04 00:44:16 +00:00
await self.info(content=msg, name="Command Call")
2020-03-04 00:42:35 +00:00
async def cog_check(self, ctx):
return commands.is_owner()(ctx.command)
def setup(bot):
bot.add_cog(BetterLogging(bot))