fixed unban/unmute timers wrongly trying to unban users on all servers at once

This commit is contained in:
Toastie 2025-03-14 18:04:58 +13:00
parent 775d77e94e
commit 612c230b7b
Signed by: toastie_t0ast
GPG key ID: 0861BE54AD481DC7
2 changed files with 129 additions and 108 deletions
src/EllieBot/Modules/Administration

View file

@ -15,7 +15,12 @@ public enum MuteType
public class MuteService : IEService, IReadyExecutor
{
public enum TimerType { Mute, Ban, AddRole }
public enum TimerType
{
Mute,
Ban,
AddRole
}
private static readonly OverwritePermissions _denyOverwrite = new(addReactions: PermValue.Deny,
sendMessages: PermValue.Deny,
@ -121,8 +126,12 @@ public class MuteService : IEService, IReadyExecutor
if (type == MuteType.All)
{
try
{ await usr.ModifyAsync(x => x.Mute = true); }
catch { }
{
await usr.ModifyAsync(x => x.Mute = true);
}
catch
{
}
var muteRole = await GetMuteRole(usr.Guild);
if (!usr.RoleIds.Contains(muteRole.Id))
@ -160,7 +169,9 @@ public class MuteService : IEService, IReadyExecutor
await usr.ModifyAsync(x => x.Mute = true);
UserMuted(usr, mod, MuteType.Voice, reason);
}
catch { }
catch
{
}
}
else if (type == MuteType.Chat)
{
@ -197,11 +208,17 @@ public class MuteService : IEService, IReadyExecutor
if (usr is not null)
{
try
{ await usr.ModifyAsync(x => x.Mute = false); }
catch { }
{
await usr.ModifyAsync(x => x.Mute = false);
}
catch
{
}
try
{ await usr.RemoveRoleAsync(await GetMuteRole(usr.Guild)); }
{
await usr.RemoveRoleAsync(await GetMuteRole(usr.Guild));
}
catch
{
/*ignore*/
@ -240,7 +257,9 @@ public class MuteService : IEService, IReadyExecutor
//if it doesn't exist, create it
{
try
{ muteRole = await guild.CreateRoleAsync(muteRoleName, isMentionable: false); }
{
muteRole = await guild.CreateRoleAsync(muteRoleName, isMentionable: false);
}
catch
{
//if creations fails, maybe the name is not correct, find default one, if doesn't work, create default one
@ -443,8 +462,6 @@ public class MuteService : IEService, IReadyExecutor
.Where(x => Queries.GuildOnShard(x.GuildId, _shardData.TotalShards, _shardData.ShardId))
.ToListAsyncLinqToDB();
foreach (var conf in configs)
{
foreach (var x in unmuteTimers)
{
TimeSpan after;
@ -458,7 +475,7 @@ public class MuteService : IEService, IReadyExecutor
after = unmute > max ? max : unmute;
}
StartUn_Timer(conf.GuildId, x.UserId, after, TimerType.Mute);
StartUn_Timer(x.GuildId, x.UserId, after, TimerType.Mute);
}
foreach (var x in unbanTimers)
@ -474,7 +491,7 @@ public class MuteService : IEService, IReadyExecutor
after = unban > max ? max : unban;
}
StartUn_Timer(conf.GuildId, x.UserId, after, TimerType.Ban);
StartUn_Timer(x.GuildId, x.UserId, after, TimerType.Ban);
}
foreach (var x in unroleTimers)
@ -490,8 +507,7 @@ public class MuteService : IEService, IReadyExecutor
after = unban > max ? max : unban;
}
StartUn_Timer(conf.GuildId, x.UserId, after, TimerType.AddRole, x.RoleId);
}
StartUn_Timer(x.GuildId, x.UserId, after, TimerType.AddRole, x.RoleId);
}
_client.UserJoined += Client_UserJoined;

View file

@ -716,8 +716,13 @@ public partial class Administration
var banPrune = await _service.GetBanPruneAsync(ctx.Guild.Id) ?? 7;
await ctx.Guild.AddBanAsync(user, banPrune, ("Softban | " + ctx.User + " | " + msg).TrimTo(512));
try
{ await ctx.Guild.RemoveBanAsync(user); }
catch { await ctx.Guild.RemoveBanAsync(user); }
{
await ctx.Guild.RemoveBanAsync(user);
}
catch
{
}
var toSend = CreateEmbed()
.WithOkColor()