implement logging & config to moderation

This commit is contained in:
Anya 2022-03-08 15:52:03 -08:00
parent 758af39da0
commit 34f430e351
3 changed files with 29 additions and 24 deletions

View file

@ -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))

View file

@ -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

View file

@ -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)