You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
1.6KB

  1. import discord
  2. from Roxbot.settings import guild_settings
  3. from Roxbot.load_config import embedcolour
  4. async def log(guild, channel, command_name, **kwargs):
  5. logging = guild_settings.get(guild).logging
  6. if logging["enabled"]:
  7. embed = discord.Embed(title="{} command logging".format(command_name), colour=embedcolour)
  8. for key, value in kwargs.items():
  9. embed.add_field(name=key, value=value)
  10. return await channel.send(embed=embed)
  11. class Logging:
  12. def __init__(self, bot_client):
  13. self.bot = bot_client
  14. async def on_member_join(self, member):
  15. logging = guild_settings.get(member.guild).logging
  16. if logging["enabled"]:
  17. channel = self.bot.get_channel(logging["channel"])
  18. embed = discord.Embed(title="{} joined the server".format(member), colour=embedcolour)
  19. embed.add_field(name="ID", value=member.id)
  20. embed.add_field(name="Mention", value=member.mention)
  21. embed.add_field(name="Date Account Created", value="{:%a %Y/%m/%d %H:%M:%S} UTC".format(member.created_at))
  22. embed.add_field(name="Date Joined", value="{:%a %Y/%m/%d %H:%M:%S} UTC".format(member.joined_at))
  23. embed.set_thumbnail(url=member.avatar_url)
  24. return await channel.send(embed=embed)
  25. async def on_member_remove(self, member):
  26. # TODO: Add some way of detecting whether a user left/was kicked or was banned.
  27. logging = guild_settings.get(member.guild).logging
  28. if logging["enabled"]:
  29. channel = self.bot.get_channel(logging["channel"])
  30. embed = discord.Embed(description="{} left the server".format(member), colour=embedcolour)
  31. return await channel.send(embed=embed)
  32. def setup(bot_client):
  33. bot_client.add_cog(Logging(bot_client))