Skip to content

Commit

Permalink
+ Added print debugs (modlog doesnt work on certain guilds)
Browse files Browse the repository at this point in the history
  • Loading branch information
null2264 committed Aug 12, 2021
1 parent f394f53 commit 4e3cf05
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions exts/events/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,24 @@ async def doModlog(
channel = await bot.getGuildConfig(guild.id, "modlogCh", "guildChannels")
channel = bot.get_channel(channel)

print("^ getting channel ----\n", channel)

if moderator.id == bot.user.id:
print("mod action using bot")
# This usually True when mods use moderation commands
# Or when bots doing automod stuff
if reason and channel:
print('getting "real identity"')
# Get the real moderator
match = REASON_REGEX.match(reason)
if match:
modId = match.group(1)
moderator = bot.get_user(modId) or await bot.fetch_user(modId)
reason = match.group(2)
print('got "real identity"')

else:
print("manual moderation action")
# Since moderation is done manually, caselog will be done here
await doCaselog(
bot,
Expand All @@ -69,9 +75,12 @@ async def doModlog(
)

if not channel:
print("No channel found, abort")
# No channel found, don't do modlog
return

print("creating embed, info:\n", channel, moderator, reason)

e = ZEmbed.minimal(
title="Modlog - {}".format(type.title()),
description=(
Expand All @@ -83,6 +92,8 @@ async def doModlog(
e.set_footer(text=f"ID: {member.id}")
await channel.send(embed=e)

print("sending modlog to", channel)


class EventHandler(commands.Cog, CogMixin):
"""Place for to put random events."""
Expand Down Expand Up @@ -195,16 +206,20 @@ async def onMemberBan(self, guild: discord.Guild, member: discord.Member) -> Non
entries = await guild.audit_logs(
limit=5, action=discord.AuditLogAction.ban
).flatten()
print("^ entries ----\n", entries)
entry: discord.AuditLogEntry = discord.utils.find(
lambda e: e.target == member, entries
)
print("^ entry ----\n", entry)
except discord.Forbidden:
entry = None

if entry is not None:
print("doing modlog ----")
await doModlog(
self.bot, guild, entry.target, entry.user, "ban", entry.reason
)
print("^ modlog done ----")

@commands.Cog.listener("on_command_error")
async def onCommandError(self, ctx, error) -> Optional[discord.Message]:
Expand Down

0 comments on commit 4e3cf05

Please sign in to comment.