Skip to content

Commit 00086b0

Browse files
authored
Merge pull request #378 from JayFromProgramming/master
Fixed long standing selfdeafen modlog bug
2 parents 742522a + f5cc570 commit 00086b0

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

dozer/cogs/moderation.py

+22-6
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,11 @@ async def mod_log(self, actor: discord.Member, action: str, target: Union[discor
109109
# Add source guild after Preformed by to embed if the modlog is being sent to a DM
110110
modlog_embed.insert_field_at(2, name="Source Guild", value=f"**{actor.guild.name}** ({actor.guild.id})")
111111
await target.send(embed=modlog_embed)
112+
# Remove the source guild line from the embed
112113
except discord.Forbidden:
113114
await orig_channel.send("Failed to DM modlog to user")
115+
finally:
116+
modlog_embed.remove_field(2)
114117
modlog_channel = await GuildModLog.get_by(guild_id=actor.guild.id) if guild_override is None else \
115118
await GuildModLog.get_by(guild_id=guild_override)
116119
if orig_channel is not None:
@@ -169,10 +172,11 @@ async def start_punishment_timers(self):
169172
punishment_type = r.type_of_punishment
170173
reason = r.reason or ""
171174
seconds = max(int(r.target_ts - time.time()), 1)
175+
self_inflicted = r.self_inflicted
172176
await PunishmentTimerRecords.delete(id=r.id)
173177
self.bot.loop.create_task(self.punishment_timer(seconds, target, PunishmentTimerRecords.type_map[punishment_type], reason, actor,
174-
orig_channel))
175-
# getLogger('dozer').info(f"Restarted {PunishmentTimerRecords.type_map[punishment_type].__name__} of {target} in {guild}")
178+
orig_channel, not self_inflicted))
179+
DOZER_LOGGER.debug(f"Restarted {PunishmentTimerRecords.type_map[punishment_type].__name__} of {target} in {guild}")
176180

177181
async def restart_all_timers(self):
178182
"""Restarts all timers"""
@@ -194,7 +198,8 @@ async def punishment_timer(self, seconds, target: discord.Member, punishment, re
194198
asyncio.current_task().set_name(f"PunishmentTimer for {target}")
195199
self.punishment_timer_tasks.append(asyncio.current_task())
196200

197-
DOZER_LOGGER.info(f"Starting {punishment.__name__} timer of \"{target}\" in \"{target.guild}\" will expire in {seconds} seconds")
201+
DOZER_LOGGER.info(f"Starting{' self' if not global_modlog else ''} {punishment.__name__} timer of \"{target}\" in \"{target.guild}\" will "
202+
f"expire in {seconds} seconds")
198203

199204
if seconds == 0:
200205
return
@@ -207,7 +212,8 @@ async def punishment_timer(self, seconds, target: discord.Member, punishment, re
207212
orig_channel_id=orig_channel.id if orig_channel else 0,
208213
type_of_punishment=punishment.type,
209214
reason=reason,
210-
target_ts=int(seconds + time.time())
215+
target_ts=int(seconds + time.time()),
216+
self_inflicted=not global_modlog
211217
)
212218
await ent.update_or_add()
213219

@@ -1276,7 +1282,7 @@ async def initial_create(cls):
12761282
)""")
12771283

12781284
def __init__(self, guild_id, actor_id, target_id, type_of_punishment, target_ts, orig_channel_id=None, reason=None,
1279-
input_id=None):
1285+
input_id=None, self_inflicted=False):
12801286
super().__init__()
12811287
self.id = input_id
12821288
self.guild_id = guild_id
@@ -1286,6 +1292,7 @@ def __init__(self, guild_id, actor_id, target_id, type_of_punishment, target_ts,
12861292
self.target_ts = target_ts
12871293
self.orig_channel_id = orig_channel_id
12881294
self.reason = reason
1295+
self.self_inflicted = self_inflicted
12891296

12901297
@classmethod
12911298
async def get_by(cls, **kwargs):
@@ -1297,10 +1304,19 @@ async def get_by(cls, **kwargs):
12971304
type_of_punishment=result.get("type_of_punishment"),
12981305
target_ts=result.get("target_ts"),
12991306
orig_channel_id=result.get("orig_channel_id"), reason=result.get("reason"),
1300-
input_id=result.get('id'))
1307+
input_id=result.get('id'), self_inflicted=result.get("self_inflicted"))
13011308
result_list.append(obj)
13021309
return result_list
13031310

1311+
async def version_1(self):
1312+
"""DB migration v1"""
1313+
async with db.Pool.acquire() as conn:
1314+
await conn.execute(f"""
1315+
ALTER TABLE {self.__tablename__} ADD self_inflicted bool NOT NULL DEFAULT false;
1316+
""")
1317+
1318+
__versions__ = [version_1]
1319+
13041320

13051321
def setup(bot):
13061322
"""Adds the moderation cog to the bot."""

0 commit comments

Comments
 (0)