public async Task BanCommandAsync(CommandContext ctx, [Description("User id of the user to ban")] ulong userId, [Description("Length of the ban")] TimeSpan?banLength = null, [Description("Reason they were banned")] [RemainingText] string reason = "unspecified") { try { if (DiscordBot.Bot?.Rest is not null) { await DiscordBot.Bot.Rest.CreateGuildBanAsync(ctx.Guild.Id, userId, 0, reason); } } catch { await RespondBasicErrorAsync($"Failed to ban {userId}"); return; } DateTime?bannedUntil = null; if (!(banLength is null)) { var cfg = this._model.Find <GuildModeration>(ctx.Guild.Id); if (cfg is null) { cfg = new GuildModeration(ctx.Guild.Id); this._model.Add(cfg); await this._model.SaveChangesAsync(); } bannedUntil = DateTime.UtcNow.Add((TimeSpan)banLength); this._model.Update(cfg); cfg.UserBans[userId] = (DateTime)bannedUntil; await this._model.SaveChangesAsync(); } await RespondBasicSuccessAsync($"Banned {userId} {(banLength is null ? "permanetly" : $"until {bannedUntil?.ToShortDateString() ?? "forever"}")}"); }
public async Task BanCommandAsync(CommandContext ctx, [Description("User to ban from the server. Can be a user mention or ID")] DiscordMember user, [Description("Length of the ban")] TimeSpan?banLength = null, [Description("Reason they were banned")] [RemainingText] string reason = "unspecified") { try { await user.BanAsync(0, reason); } catch { await RespondBasicErrorAsync($"Failed to ban {user.Mention}"); return; } DateTime?bannedUntil = null; if (!(banLength is null)) { var cfg = this._model.Find <GuildModeration>(ctx.Guild.Id); if (cfg is null) { cfg = new GuildModeration(ctx.Guild.Id); this._model.Add(cfg); await this._model.SaveChangesAsync(); } bannedUntil = DateTime.UtcNow.Add((TimeSpan)banLength); this._model.Update(cfg); cfg.UserBans[user.Id] = (DateTime)bannedUntil; await this._model.SaveChangesAsync(); } await RespondBasicSuccessAsync($"Banned {user.Mention} {(banLength is null ? "permanetly" : $"until {bannedUntil?.ToShortDateString() ?? "forever"}")}"); }