From 34f430e351c63aac8e3125325824e7bb4a4f6f3c Mon Sep 17 00:00:00 2001 From: oko Date: Tue, 8 Mar 2022 15:52:03 -0800 Subject: [PATCH] implement logging & config to moderation --- commands/moderation.py | 34 +++++++++++++++++++--------------- configmanager.py | 9 +++++++-- kiafumi.py | 10 +++------- 3 files changed, 29 insertions(+), 24 deletions(-) diff --git a/commands/moderation.py b/commands/moderation.py index c69d372..ed2be46 100644 --- a/commands/moderation.py +++ b/commands/moderation.py @@ -1,28 +1,32 @@ import discord.commands from discord.ext import commands +from configmanager import ConfigManager import datetime -class Moderation(commands.Cog, name="Moderation"): +memberlogs = ConfigManager.get()['Channels']['MemberLogs'] +print (memberlogs) + +class Moderation(commands.Cog, name='Moderation'): def __init__(self, bot): self.bot = bot - @commands.Cog.listener() + @commands.Cog.listener() # Join log async def on_member_join(self, member): - guild = member.guild - if guild.system_channel is not None: - embed = discord.Embed(color=discord.Color.green(), description=f"{member.mention} | **Joined Discord**: {member.created_at.date()}", timestamp=datetime.datetime.now()) - embed.set_author(name=f"{member} ({member.id})", icon_url=f"{member.display_avatar.url}?128") - embed.set_footer(text="User Left") - await guild.system_channel.send(embeds=[embed]) + channel = self.bot.get_channel(memberlogs) + if channel is not None: + embed = discord.Embed(color=discord.Color.green(), description=f'{member.mention} | **Joined Discord**: {member.created_at.date()}', timestamp=datetime.datetime.now()) + embed.set_author(name=f'{member} ({member.id})', icon_url=f'{member.display_avatar.url}?128') + embed.set_footer(text='User Left') + await member.guild.channel.send(embeds=[embed]) - @commands.Cog.listener() + @commands.Cog.listener() # Leave log async def on_member_remove(self, member): - guild = member.guild - if guild.system_channel is not None: - embed = discord.Embed(color=discord.Color.red(), description=f"{member.mention} | **Joined Server**: {member.joined_at.date()}", timestamp=datetime.datetime.now()) - embed.set_author(name=f"{member} ({member.id})", icon_url=f"{member.display_avatar.url}?128") - embed.set_footer(text="User Left") - await guild.system_channel.send(embeds=[embed]) + channel = self.bot.get_channel(memberlogs) + if channel is not None: + embed = discord.Embed(color=discord.Color.red(), description=f'{member.mention} | **Joined Server**: {member.joined_at.date()}', timestamp=datetime.datetime.now()) + embed.set_author(name=f'{member} ({member.id})', icon_url=f'{member.display_avatar.url}?128') + embed.set_footer(text='User Left') + await member.guild.channel.send(embeds=[embed]) def setup(bot): bot.add_cog(Moderation(bot)) \ No newline at end of file diff --git a/configmanager.py b/configmanager.py index 38dda41..cab513b 100644 --- a/configmanager.py +++ b/configmanager.py @@ -1,12 +1,17 @@ import configparser +import logging + +class LoggingManager(): + logging.basicConfig(level=logging.INFO) + log = logging.getLogger() class ConfigManager(): - def read_config(): + def get(): config = configparser.ConfigParser() config.read('config.ini') return config - def write_config(): + def set(): config = configparser.ConfigParser() config.read('config.ini') return config \ No newline at end of file diff --git a/kiafumi.py b/kiafumi.py index 856ad02..fb2c417 100644 --- a/kiafumi.py +++ b/kiafumi.py @@ -1,20 +1,16 @@ import discord -from discord.ext import commands -import logging -from configmanager import ConfigManager +from configmanager import ConfigManager, LoggingManager intents = discord.Intents.default() intents.members = True bot = discord.Bot(intents=intents) -setting = ConfigManager.read_config() -token = setting['Bot']['Token'] -logger = logging.getLogger() +token = ConfigManager.get()['Bot']['Token'] class Kiafumi(discord.Bot): @bot.event async def on_ready(): - logger.info(f'Logged on as {bot.user}!') + LoggingManager.log.info(f'Logged on as {bot.user}!') for ext in ['commands.fun', 'commands.moderation']: bot.load_extension(ext)