1
0
Fork 1
mirror of https://github.com/TeamOctolings/Octobot.git synced 2025-05-02 20:19:55 +03:00

Fix durations blocking command handler thread

Add "This punishment will expire in" text to ban/mute notifications
This commit is contained in:
l1ttleO 2022-02-12 23:54:45 +05:00
parent 04facc3de2
commit e41a459f6f
Signed by: Octol1ttle
GPG key ID: B77C34313AEE1FFF
6 changed files with 51 additions and 28 deletions

View file

@ -28,7 +28,12 @@ public class BanCommand : Command {
var authorMention = author.Mention;
var guildBanMessage = $"({Utils.GetNameAndDiscrim(author)}) {reason}";
var memberToBan = await guild.GetUserAsync(toBan.Id);
var notification = string.Format(Messages.UserBanned, authorMention, toBan.Mention, Utils.WrapInline(reason));
var expiresIn = duration.TotalSeconds > 0
? string.Format(Messages.PunishmentExpiresIn, Environment.NewLine,
DateTimeOffset.Now.ToUnixTimeSeconds() + duration.TotalSeconds)
: "";
var notification = string.Format(Messages.UserBanned, authorMention, toBan.Mention, Utils.WrapInline(reason),
expiresIn);
await CommandHandler.CheckPermissions(author, GuildPermission.BanMembers);
if (memberToBan != null)
@ -44,14 +49,16 @@ public class BanCommand : Command {
await Utils.SilentSendAsync(await guild.GetSystemChannelAsync(), notification);
await Utils.SilentSendAsync(await Utils.GetAdminLogChannel(guild), notification);
async void UnbanWhenExpires() {
try {
await UnbanCommand.UnbanUser(guild, null, await guild.GetCurrentUserAsync(), toBan,
Messages.PunishmentExpired);
} catch (ApplicationException) {}
if (duration.TotalSeconds > 0) {
var task = new Task(async () => {
await Task.Delay(duration);
try {
await UnbanCommand.UnbanUser(guild, null, await guild.GetCurrentUserAsync(), toBan,
Messages.PunishmentExpired);
} catch (ApplicationException) {}
});
task.Start();
}
await Utils.StartDelayed(new Task(UnbanWhenExpires), duration);
}
public override List<string> GetAliases() {