@@ -109,8 +109,11 @@ async def mod_log(self, actor: discord.Member, action: str, target: Union[discor
109
109
# Add source guild after Preformed by to embed if the modlog is being sent to a DM
110
110
modlog_embed .insert_field_at (2 , name = "Source Guild" , value = f"**{ actor .guild .name } ** ({ actor .guild .id } )" )
111
111
await target .send (embed = modlog_embed )
112
+ # Remove the source guild line from the embed
112
113
except discord .Forbidden :
113
114
await orig_channel .send ("Failed to DM modlog to user" )
115
+ finally :
116
+ modlog_embed .remove_field (2 )
114
117
modlog_channel = await GuildModLog .get_by (guild_id = actor .guild .id ) if guild_override is None else \
115
118
await GuildModLog .get_by (guild_id = guild_override )
116
119
if orig_channel is not None :
@@ -169,10 +172,11 @@ async def start_punishment_timers(self):
169
172
punishment_type = r .type_of_punishment
170
173
reason = r .reason or ""
171
174
seconds = max (int (r .target_ts - time .time ()), 1 )
175
+ self_inflicted = r .self_inflicted
172
176
await PunishmentTimerRecords .delete (id = r .id )
173
177
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 } " )
176
180
177
181
async def restart_all_timers (self ):
178
182
"""Restarts all timers"""
@@ -194,7 +198,8 @@ async def punishment_timer(self, seconds, target: discord.Member, punishment, re
194
198
asyncio .current_task ().set_name (f"PunishmentTimer for { target } " )
195
199
self .punishment_timer_tasks .append (asyncio .current_task ())
196
200
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" )
198
203
199
204
if seconds == 0 :
200
205
return
@@ -207,7 +212,8 @@ async def punishment_timer(self, seconds, target: discord.Member, punishment, re
207
212
orig_channel_id = orig_channel .id if orig_channel else 0 ,
208
213
type_of_punishment = punishment .type ,
209
214
reason = reason ,
210
- target_ts = int (seconds + time .time ())
215
+ target_ts = int (seconds + time .time ()),
216
+ self_inflicted = not global_modlog
211
217
)
212
218
await ent .update_or_add ()
213
219
@@ -1276,7 +1282,7 @@ async def initial_create(cls):
1276
1282
)""" )
1277
1283
1278
1284
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 ):
1280
1286
super ().__init__ ()
1281
1287
self .id = input_id
1282
1288
self .guild_id = guild_id
@@ -1286,6 +1292,7 @@ def __init__(self, guild_id, actor_id, target_id, type_of_punishment, target_ts,
1286
1292
self .target_ts = target_ts
1287
1293
self .orig_channel_id = orig_channel_id
1288
1294
self .reason = reason
1295
+ self .self_inflicted = self_inflicted
1289
1296
1290
1297
@classmethod
1291
1298
async def get_by (cls , ** kwargs ):
@@ -1297,10 +1304,19 @@ async def get_by(cls, **kwargs):
1297
1304
type_of_punishment = result .get ("type_of_punishment" ),
1298
1305
target_ts = result .get ("target_ts" ),
1299
1306
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" ) )
1301
1308
result_list .append (obj )
1302
1309
return result_list
1303
1310
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
+
1304
1320
1305
1321
def setup (bot ):
1306
1322
"""Adds the moderation cog to the bot."""
0 commit comments