@@ -1005,13 +1005,18 @@ async def default_mute_time(self, ctx: commands.Context, *, time: Optional[MuteT
1005
1005
await self .config .guild (ctx .guild ).default_time .clear ()
1006
1006
await ctx .send (_ ("Default mute time removed." ))
1007
1007
else :
1008
- data = time .get ("duration" , {} )
1009
- if not data :
1008
+ duration = time .get ("duration" , None )
1009
+ if not duration :
1010
1010
return await ctx .send (_ ("Please provide a valid time format." ))
1011
- await self .config .guild (ctx .guild ).default_time .set (data .total_seconds ())
1011
+ if duration >= timedelta (days = 365000 ):
1012
+ # prevent setting a default time now that might eventually cause an overflow
1013
+ # later as the date goes up. 1000 years gives us approximately 8000 more years
1014
+ # of wiggle room.
1015
+ return await ctx .send (_ ("Please provide a more reasonable default time frame." ))
1016
+ await self .config .guild (ctx .guild ).default_time .set (duration .total_seconds ())
1012
1017
await ctx .send (
1013
1018
_ ("Default mute time set to {time}." ).format (
1014
- time = humanize_timedelta (timedelta = data )
1019
+ time = humanize_timedelta (timedelta = duration )
1015
1020
)
1016
1021
)
1017
1022
@@ -1142,15 +1147,15 @@ async def timeout(
1142
1147
return await ctx .send (_ ("You cannot mute me." ))
1143
1148
if ctx .author in users :
1144
1149
return await ctx .send (_ ("You cannot mute yourself." ))
1145
- duration = time_and_reason .get ("duration" , None )
1146
- if duration and duration > timedelta (days = 28 ):
1147
- await ctx .send (_ (MUTE_UNMUTE_ISSUES ["mute_is_too_long" ]))
1148
- return
1150
+ until = time_and_reason .get ("until" , None )
1149
1151
reason = time_and_reason .get ("reason" , None )
1150
1152
time = ""
1151
- until = None
1152
- if duration :
1153
- until = datetime .now (timezone .utc ) + duration
1153
+ duration = None
1154
+ if until :
1155
+ duration = time_and_reason .get ("duration" )
1156
+ if duration and duration > timedelta (days = 28 ):
1157
+ await ctx .send (_ (MUTE_UNMUTE_ISSUES ["mute_is_too_long" ]))
1158
+ return
1154
1159
length = humanize_timedelta (timedelta = duration )
1155
1160
time = _ (" for {length} until {duration}" ).format (
1156
1161
length = length , duration = discord .utils .format_dt (until )
@@ -1159,7 +1164,8 @@ async def timeout(
1159
1164
else :
1160
1165
default_duration = await self .config .guild (ctx .guild ).default_time ()
1161
1166
if default_duration :
1162
- until = datetime .now (timezone .utc ) + timedelta (seconds = default_duration )
1167
+ duration = timedelta (seconds = default_duration )
1168
+ until = ctx .message .created_at + duration
1163
1169
length = humanize_timedelta (seconds = default_duration )
1164
1170
time = _ (" for {length} until {duration}" ).format (
1165
1171
length = length , duration = discord .utils .format_dt (until )
@@ -1227,12 +1233,12 @@ async def mute(
1227
1233
if not await self ._check_for_mute_role (ctx ):
1228
1234
return
1229
1235
async with ctx .typing ():
1230
- duration = time_and_reason .get ("duration " , None )
1236
+ until = time_and_reason .get ("until " , None )
1231
1237
reason = time_and_reason .get ("reason" , None )
1232
1238
time = ""
1233
- until = None
1234
- if duration :
1235
- until = datetime . now ( timezone . utc ) + duration
1239
+ duration = None
1240
+ if until :
1241
+ duration = time_and_reason . get ( " duration" )
1236
1242
length = humanize_timedelta (timedelta = duration )
1237
1243
time = _ (" for {length} until {duration}" ).format (
1238
1244
length = length , duration = discord .utils .format_dt (until )
@@ -1241,7 +1247,8 @@ async def mute(
1241
1247
else :
1242
1248
default_duration = await self .config .guild (ctx .guild ).default_time ()
1243
1249
if default_duration :
1244
- until = datetime .now (timezone .utc ) + timedelta (seconds = default_duration )
1250
+ duration = timedelta (seconds = default_duration )
1251
+ until = ctx .message .created_at + duration
1245
1252
length = humanize_timedelta (seconds = default_duration )
1246
1253
time = _ (" for {length} until {duration}" ).format (
1247
1254
length = length , duration = discord .utils .format_dt (until )
@@ -1377,18 +1384,26 @@ async def channel_mute(
1377
1384
if ctx .author in users :
1378
1385
return await ctx .send (_ ("You cannot mute yourself." ))
1379
1386
async with ctx .typing ():
1380
- duration = time_and_reason .get ("duration " , None )
1387
+ until = time_and_reason .get ("until " , None )
1381
1388
reason = time_and_reason .get ("reason" , None )
1382
1389
time = ""
1383
- until = None
1384
- if duration :
1385
- until = datetime .now (timezone .utc ) + duration
1386
- time = _ (" until {duration}" ).format (duration = discord .utils .format_dt (until ))
1390
+ duration = None
1391
+ if until :
1392
+ duration = time_and_reason .get ("duration" )
1393
+ length = humanize_timedelta (timedelta = duration )
1394
+ time = _ (" for {length} until {duration}" ).format (
1395
+ length = length , duration = discord .utils .format_dt (until )
1396
+ )
1397
+
1387
1398
else :
1388
1399
default_duration = await self .config .guild (ctx .guild ).default_time ()
1389
1400
if default_duration :
1390
- until = datetime .now (timezone .utc ) + timedelta (seconds = default_duration )
1391
- time = _ (" until {duration}" ).format (duration = discord .utils .format_dt (until ))
1401
+ duration = timedelta (seconds = default_duration )
1402
+ until = ctx .message .created_at + duration
1403
+ length = humanize_timedelta (seconds = default_duration )
1404
+ time = _ (" for {length} until {duration}" ).format (
1405
+ length = length , duration = discord .utils .format_dt (until )
1406
+ )
1392
1407
author = ctx .message .author
1393
1408
channel = ctx .message .channel
1394
1409
if isinstance (channel , discord .Thread ):
0 commit comments