mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-10 17:28:27 -04:00
timed ban should now work with userids (users who are not in the server yet), closes #400
This commit is contained in:
@@ -356,24 +356,24 @@ public class MuteService : INService
|
|||||||
|
|
||||||
public async Task TimedBan(
|
public async Task TimedBan(
|
||||||
IGuild guild,
|
IGuild guild,
|
||||||
IUser user,
|
ulong userId,
|
||||||
TimeSpan after,
|
TimeSpan after,
|
||||||
string reason,
|
string reason,
|
||||||
int pruneDays)
|
int pruneDays)
|
||||||
{
|
{
|
||||||
await guild.AddBanAsync(user.Id, pruneDays, reason);
|
await guild.AddBanAsync(userId, pruneDays, reason);
|
||||||
await using (var uow = _db.GetDbContext())
|
await using (var uow = _db.GetDbContext())
|
||||||
{
|
{
|
||||||
var config = uow.GuildConfigsForId(guild.Id, set => set.Include(x => x.UnbanTimer));
|
var config = uow.GuildConfigsForId(guild.Id, set => set.Include(x => x.UnbanTimer));
|
||||||
config.UnbanTimer.Add(new()
|
config.UnbanTimer.Add(new()
|
||||||
{
|
{
|
||||||
UserId = user.Id,
|
UserId = userId,
|
||||||
UnbanAt = DateTime.UtcNow + after
|
UnbanAt = DateTime.UtcNow + after
|
||||||
}); // add teh unmute timer to the database
|
}); // add teh unmute timer to the database
|
||||||
uow.SaveChanges();
|
await uow.SaveChangesAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
StartUn_Timer(guild.Id, user.Id, after, TimerType.Ban); // start the timer
|
StartUn_Timer(guild.Id, userId, after, TimerType.Ban); // start the timer
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task TimedRole(
|
public async Task TimedRole(
|
||||||
|
@@ -402,12 +402,21 @@ public partial class Administration
|
|||||||
[UserPerm(GuildPerm.BanMembers)]
|
[UserPerm(GuildPerm.BanMembers)]
|
||||||
[BotPerm(GuildPerm.BanMembers)]
|
[BotPerm(GuildPerm.BanMembers)]
|
||||||
[Priority(1)]
|
[Priority(1)]
|
||||||
public async Task Ban(StoopidTime time, IUser user, [Leftover] string msg = null)
|
public Task Ban(StoopidTime time, IUser user, [Leftover] string msg = null)
|
||||||
|
=> Ban(time, user.Id, msg);
|
||||||
|
|
||||||
|
[Cmd]
|
||||||
|
[RequireContext(ContextType.Guild)]
|
||||||
|
[UserPerm(GuildPerm.BanMembers)]
|
||||||
|
[BotPerm(GuildPerm.BanMembers)]
|
||||||
|
[Priority(0)]
|
||||||
|
public async Task Ban(StoopidTime time, ulong userId, [Leftover] string msg = null)
|
||||||
{
|
{
|
||||||
if (time.Time > TimeSpan.FromDays(49))
|
if (time.Time > TimeSpan.FromDays(49))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var guildUser = await ((DiscordSocketClient)Context.Client).Rest.GetGuildUserAsync(ctx.Guild.Id, user.Id);
|
var guildUser = await ((DiscordSocketClient)Context.Client).Rest.GetGuildUserAsync(ctx.Guild.Id, userId);
|
||||||
|
|
||||||
|
|
||||||
if (guildUser is not null && !await CheckRoleHierarchy(guildUser))
|
if (guildUser is not null && !await CheckRoleHierarchy(guildUser))
|
||||||
return;
|
return;
|
||||||
@@ -429,13 +438,14 @@ public partial class Administration
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var user = await ctx.Client.GetUserAsync(userId);
|
||||||
var banPrune = await _service.GetBanPruneAsync(ctx.Guild.Id) ?? 7;
|
var banPrune = await _service.GetBanPruneAsync(ctx.Guild.Id) ?? 7;
|
||||||
await _mute.TimedBan(ctx.Guild, user, time.Time, (ctx.User + " | " + msg).TrimTo(512), banPrune);
|
await _mute.TimedBan(ctx.Guild, userId, time.Time, (ctx.User + " | " + msg).TrimTo(512), banPrune);
|
||||||
var toSend = _eb.Create()
|
var toSend = _eb.Create()
|
||||||
.WithOkColor()
|
.WithOkColor()
|
||||||
.WithTitle("⛔️ " + GetText(strs.banned_user))
|
.WithTitle("⛔️ " + GetText(strs.banned_user))
|
||||||
.AddField(GetText(strs.username), user.ToString(), true)
|
.AddField(GetText(strs.username), user?.ToString() ?? userId.ToString(), true)
|
||||||
.AddField("ID", user.Id.ToString(), true)
|
.AddField("ID", userId.ToString(), true)
|
||||||
.AddField(GetText(strs.duration),
|
.AddField(GetText(strs.duration),
|
||||||
time.Time.Humanize(3, minUnit: TimeUnit.Minute, culture: Culture),
|
time.Time.Humanize(3, minUnit: TimeUnit.Minute, culture: Culture),
|
||||||
true);
|
true);
|
||||||
|
@@ -157,7 +157,7 @@ public class UserPunishService : INService, IReadyExecutor
|
|||||||
if (minutes == 0)
|
if (minutes == 0)
|
||||||
await guild.AddBanAsync(user, reason: reason, pruneDays: banPrune);
|
await guild.AddBanAsync(user, reason: reason, pruneDays: banPrune);
|
||||||
else
|
else
|
||||||
await _mute.TimedBan(user.Guild, user, TimeSpan.FromMinutes(minutes), reason, banPrune);
|
await _mute.TimedBan(user.Guild, user.Id, TimeSpan.FromMinutes(minutes), reason, banPrune);
|
||||||
break;
|
break;
|
||||||
case PunishmentAction.Softban:
|
case PunishmentAction.Softban:
|
||||||
banPrune = await GetBanPruneAsync(user.GuildId) ?? 7;
|
banPrune = await GetBanPruneAsync(user.GuildId) ?? 7;
|
||||||
|
Reference in New Issue
Block a user