mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-11 17:58:26 -04:00
add: Added admin-only .warndelete command
This commit is contained in:
@@ -273,6 +273,31 @@ public partial class Administration
|
|||||||
.SendAsync();
|
.SendAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Cmd]
|
||||||
|
[RequireContext(ContextType.Guild)]
|
||||||
|
[UserPerm(GuildPerm.Administrator)]
|
||||||
|
public Task WarnDelete(IGuildUser user, int index)
|
||||||
|
=> WarnDelete(user.Id, index);
|
||||||
|
|
||||||
|
[Cmd]
|
||||||
|
[RequireContext(ContextType.Guild)]
|
||||||
|
[UserPerm(GuildPerm.Administrator)]
|
||||||
|
public async Task WarnDelete(ulong userId, int index)
|
||||||
|
{
|
||||||
|
if (--index < 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var warn = await _service.WarnDelete(userId, index);
|
||||||
|
|
||||||
|
if (warn is null)
|
||||||
|
{
|
||||||
|
await Response().Error(strs.warning_not_found).SendAsync();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await Response().Confirm(strs.warning_deleted(Format.Bold(index.ToString()))).SendAsync();
|
||||||
|
}
|
||||||
|
|
||||||
[Cmd]
|
[Cmd]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
[UserPerm(GuildPerm.BanMembers)]
|
[UserPerm(GuildPerm.BanMembers)]
|
||||||
@@ -286,6 +311,7 @@ public partial class Administration
|
|||||||
{
|
{
|
||||||
if (index < 0)
|
if (index < 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var success = await _service.WarnClearAsync(ctx.Guild.Id, userId, index, ctx.User.ToString());
|
var success = await _service.WarnClearAsync(ctx.Guild.Id, userId, index, ctx.User.ToString());
|
||||||
var userStr = Format.Bold((ctx.Guild as SocketGuild)?.GetUser(userId)?.ToString() ?? userId.ToString());
|
var userStr = Format.Bold((ctx.Guild as SocketGuild)?.GetUser(userId)?.ToString() ?? userId.ToString());
|
||||||
if (index == 0)
|
if (index == 0)
|
||||||
|
@@ -89,7 +89,8 @@ public class UserPunishService : INService, IReadyExecutor
|
|||||||
{
|
{
|
||||||
ps = uow.GuildConfigsForId(guildId, set => set.Include(x => x.WarnPunishments)).WarnPunishments;
|
ps = uow.GuildConfigsForId(guildId, set => set.Include(x => x.WarnPunishments)).WarnPunishments;
|
||||||
|
|
||||||
previousCount = uow.Set<Warning>().ForId(guildId, userId)
|
previousCount = uow.Set<Warning>()
|
||||||
|
.ForId(guildId, userId)
|
||||||
.Where(w => !w.Forgiven && w.UserId == userId)
|
.Where(w => !w.Forgiven && w.UserId == userId)
|
||||||
.Sum(x => x.Weight);
|
.Sum(x => x.Weight);
|
||||||
|
|
||||||
@@ -483,7 +484,8 @@ public class UserPunishService : INService, IReadyExecutor
|
|||||||
}
|
}
|
||||||
else if (template is null)
|
else if (template is null)
|
||||||
{
|
{
|
||||||
uow.Set<BanTemplate>().Add(new()
|
uow.Set<BanTemplate>()
|
||||||
|
.Add(new()
|
||||||
{
|
{
|
||||||
GuildId = guildId,
|
GuildId = guildId,
|
||||||
Text = text
|
Text = text
|
||||||
@@ -594,4 +596,24 @@ public class UserPunishService : INService, IReadyExecutor
|
|||||||
var output = SmartText.CreateFrom(template);
|
var output = SmartText.CreateFrom(template);
|
||||||
return await _repSvc.ReplaceAsync(output, repCtx);
|
return await _repSvc.ReplaceAsync(output, repCtx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<Warning> WarnDelete(ulong userId, int index)
|
||||||
|
{
|
||||||
|
await using var uow = _db.GetDbContext();
|
||||||
|
|
||||||
|
var warn = await uow.GetTable<Warning>()
|
||||||
|
.Where(x => x.UserId == userId)
|
||||||
|
.OrderByDescending(x => x.DateAdded)
|
||||||
|
.Skip(index)
|
||||||
|
.FirstOrDefaultAsyncLinqToDB();
|
||||||
|
|
||||||
|
if (warn is not null)
|
||||||
|
{
|
||||||
|
await uow.GetTable<Warning>()
|
||||||
|
.Where(x => x.Id == warn.Id)
|
||||||
|
.DeleteAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
return warn;
|
||||||
|
}
|
||||||
}
|
}
|
@@ -947,6 +947,10 @@ warnexpire:
|
|||||||
warnclear:
|
warnclear:
|
||||||
- warnclear
|
- warnclear
|
||||||
- warnc
|
- warnc
|
||||||
|
warndelete:
|
||||||
|
- warndelete
|
||||||
|
- warnrm
|
||||||
|
- warnd
|
||||||
warnpunishlist:
|
warnpunishlist:
|
||||||
- warnpunishlist
|
- warnpunishlist
|
||||||
- warnpl
|
- warnpl
|
||||||
|
@@ -3178,6 +3178,13 @@ warnclear:
|
|||||||
desc: "The ID of the user whose warnings are being cleared."
|
desc: "The ID of the user whose warnings are being cleared."
|
||||||
index:
|
index:
|
||||||
desc: "The index of the warning to be cleared, or 0 to clear all warnings."
|
desc: "The index of the warning to be cleared, or 0 to clear all warnings."
|
||||||
|
warndelete:
|
||||||
|
desc: Deletes a warning from a user by its index.
|
||||||
|
ex:
|
||||||
|
- 3
|
||||||
|
params:
|
||||||
|
- index:
|
||||||
|
desc: "The index of the warning to be deleted."
|
||||||
warnpunishlist:
|
warnpunishlist:
|
||||||
desc: Lists punishments for warnings.
|
desc: Lists punishments for warnings.
|
||||||
ex:
|
ex:
|
||||||
|
@@ -702,6 +702,7 @@
|
|||||||
"warn_count": "{0} current, {1} total",
|
"warn_count": "{0} current, {1} total",
|
||||||
"warnlog_for": "Warnlog for {0}",
|
"warnlog_for": "Warnlog for {0}",
|
||||||
"warnpl_none": "No punishments set.",
|
"warnpl_none": "No punishments set.",
|
||||||
|
"warning_not_found": "Warning not found.",
|
||||||
"warn_expire_set_delete": "Warnings will be deleted after {0} days.",
|
"warn_expire_set_delete": "Warnings will be deleted after {0} days.",
|
||||||
"warn_expire_set_clear": "Warnings will be cleared after {0} days.",
|
"warn_expire_set_clear": "Warnings will be cleared after {0} days.",
|
||||||
"warn_expire_reset": "Warnings will no longer expire.",
|
"warn_expire_reset": "Warnings will no longer expire.",
|
||||||
@@ -712,6 +713,7 @@
|
|||||||
"warn_punish_rem": "Having {0} warnings will no longer trigger a punishment.",
|
"warn_punish_rem": "Having {0} warnings will no longer trigger a punishment.",
|
||||||
"warn_punish_set": "I will apply {0} punishment to users with {1} warnings.",
|
"warn_punish_set": "I will apply {0} punishment to users with {1} warnings.",
|
||||||
"warn_punish_set_timed": "I will apply {0} punishment for {2} to users with {1} warnings.",
|
"warn_punish_set_timed": "I will apply {0} punishment for {2} to users with {1} warnings.",
|
||||||
|
"warning_deleted": "Warning {0} has been deleted.",
|
||||||
"time_new": "Time",
|
"time_new": "Time",
|
||||||
"timezone": "Timezone",
|
"timezone": "Timezone",
|
||||||
"timezone_db_api_key": "You need to activate your TimezoneDB API key. You can do so by clicking on the link you've received in the email with your API key.",
|
"timezone_db_api_key": "You need to activate your TimezoneDB API key. You can do so by clicking on the link you've received in the email with your API key.",
|
||||||
|
Reference in New Issue
Block a user