"""
Cog for the on_member_update event.
Logs from this event include:
    Nickname changes in a guild (guild_member_nickname)

Part of the Gabby Gums Discord Logger.
"""

import logging
from typing import TYPE_CHECKING, Optional, Dict, List, Union, Tuple, NamedTuple

import discord
from discord.ext import commands

from embeds import member_nick_update

if TYPE_CHECKING:
    from bot import GGBot

log = logging.getLogger(__name__)


class MemberUpdate(commands.Cog):
    def __init__(self, bot: 'GGBot'):
        self.bot = bot


    @commands.Cog.listener()
    async def on_member_update(self, before: discord.Member, after: discord.Member):
        """Handles the 'on Member Update' event."""
        event_type_nick = "guild_member_nickname"  # nickname
        event_type_update = "guild_member_update"  # Everything else. Currently unused.

        if before.nick != after.nick:

            log_channel = await self.bot.get_event_or_guild_logging_channel(after.guild.id, event_type_nick, after.id)
            if log_channel is None:
                # Silently fail if no log channel is configured.
                return

            embed = member_nick_update(before, after)
            # await log_channel.send(embed=embed)
            await self.bot.send_log(log_channel, event_type_nick, embed=embed)


def setup(bot):
    bot.add_cog(MemberUpdate(bot))

"""
Cog for the on_member_update event.
Logs from this event include:
    Nickname changes in a guild (guild_member_nickname)

Part of the Gabby Gums Discord Logger.
"""

import logging
from typing import TYPE_CHECKING, Optional, Dict, List, Union, Tuple, NamedTuple

import discord
from discord.ext import commands

from embeds import member_nick_update

if TYPE_CHECKING:
    from bot import GGBot

log = logging.getLogger(__name__)


class MemberUpdate(commands.Cog):
    def __init__(self, bot: 'GGBot'):
        self.bot = bot


    @commands.Cog.listener()
    async def on_member_update(self, before: discord.Member, after: discord.Member):
        """Handles the 'on Member Update' event."""
        event_type_nick = "guild_member_nickname"  # nickname
        event_type_update = "guild_member_update"  # Everything else. Currently unused.

        if before.nick != after.nick:

            log_channel = await self.bot.get_event_or_guild_logging_channel(after.guild.id, event_type_nick, after.id)
            if log_channel is None:
                # Silently fail if no log channel is configured.
                return

            embed = member_nick_update(before, after)
            # await log_channel.send(embed=embed)
            await self.bot.send_log(log_channel, event_type_nick, embed=embed)


def setup(bot):
    bot.add_cog(MemberUpdate(bot))

Cog for the on_member_update event. Logs from this event include:     Nickname changes in a guild (guild_member_nickname)  Part of the Gabby Gums Discord Logger. Handles the 'on Member Update' event. # nickname # Everything else. Currently unused. # Silently fail if no log channel is configured. # await log_channel.send(embed=embed)