Skip to content

Commit

Permalink
Update ban command to check for open tickets
Browse files Browse the repository at this point in the history
The number of message-delete days for the ban command has been updated to be dependent on whether the user has any open tickets. If the user has any open tickets, the number of delete days is set to 0. Otherwise, it is set to 7. This has been applied across all instances of ban commands in moderation.
  • Loading branch information
FabiChan99 committed Dec 22, 2023
1 parent 246ec75 commit 2fe015b
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/Commands/Moderation/BanRequestCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ public async Task BanRequest(CommandContext ctx, DiscordUser user, [RemainingTex
var semoji = sent ? "<:yes:861266772665040917>" : "<:no:861266772724023296>";
try
{
await ctx.Guild.BanMemberAsync(user.Id, 7, ReasonString);
await ctx.Guild.BanMemberAsync(user.Id, await Helpers.GenerateBannDeleteMessageDays(user.Id), ReasonString);
var dm = sent ? "" : "";
b_users += $"{user.UsernameWithDiscriminator} | DM: {dm}\n";
}
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/Moderation/BanUserCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public async Task BanMember(CommandContext ctx, DiscordUser user, [RemainingText
var semoji = sent ? "<:yes:861266772665040917>" : "<:no:861266772724023296>";
try
{
await ctx.Guild.BanMemberAsync(user.Id, 7, ReasonString);
await ctx.Guild.BanMemberAsync(user.Id, await Helpers.GenerateBannDeleteMessageDays(user.Id), ReasonString);
var dm = sent ? "" : "";
b_users += $"{user.UsernameWithDiscriminator} | DM: {dm}\n";
}
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/Moderation/MultiBanCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public async Task MultiBan(CommandContext ctx, [RemainingText] string ids_and_re
var semoji = sent ? "<:yes:861266772665040917>" : "<:no:861266772724023296>";
try
{
await ctx.Guild.BanMemberAsync(user.Id, 7, reasonString);
await ctx.Guild.BanMemberAsync(user.Id, await Helpers.GenerateBannDeleteMessageDays(user.Id), reasonString);
var dm = sent ? "" : "";
b_users += $"{user.UsernameWithDiscriminator} | DM: {dm}\n";
}
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/Moderation/MultiBanRequestCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ public async Task MultiBanRequest(CommandContext ctx, [RemainingText] string ids
var semoji = sent ? "<:yes:861266772665040917>" : "<:no:861266772724023296>";
try
{
await ctx.Guild.BanMemberAsync(user.Id, 7, ReasonString);
await ctx.Guild.BanMemberAsync(user.Id, await Helpers.GenerateBannDeleteMessageDays(user.Id), ReasonString);
var dm = sent ? "" : "";
b_users += $"{user.UsernameWithDiscriminator} | DM: {dm}\n";
}
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/Moderation/MultiWarnCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public async Task MultiWarnUser(CommandContext ctx, [RemainingText] string ids_a
{
if (BanEnabled)
{
await ctx.Guild.BanMemberAsync(user, 7, reasonString);
await ctx.Guild.BanMemberAsync(user, await Helpers.GenerateBannDeleteMessageDays(user.Id), reasonString);
uAction = "Gebannt";
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/Moderation/PermaWarnCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public async Task PermaWarnUser(CommandContext ctx, DiscordUser user, [Remaining
{
if (BanEnabled)
{
await ctx.Guild.BanMemberAsync(user, 7, reasonString);
await ctx.Guild.BanMemberAsync(user, await Helpers.GenerateBannDeleteMessageDays(user.Id), reasonString);
uAction = "Gebannt";
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/Moderation/WarnUserCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public async Task WarnUser(CommandContext ctx, DiscordUser user, [RemainingText]
{
if (BanEnabled)
{
await ctx.Guild.BanMemberAsync(user, 7, reasonString);
await ctx.Guild.BanMemberAsync(user, await Helpers.GenerateBannDeleteMessageDays(user.Id), reasonString);
uAction = "Gebannt";
}
}
Expand Down
31 changes: 31 additions & 0 deletions src/Utils/Helpers.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#region

using AGC_Management.Entities;
using AGC_Management.Services;
using DisCatSharp.CommandsNext;
using DisCatSharp.Entities;
using DisCatSharp.Enums;
Expand Down Expand Up @@ -214,6 +215,36 @@ public static string GenerateCaseID()
return uniqueID;
}

public static async Task<bool> UserHasOpenTicket(ulong UserId)
{
string con = TicketDatabaseService.GetConnectionString();
await using var connection = new NpgsqlConnection(con);
await connection.OpenAsync();
string query = $"SELECT COUNT(*) FROM ticketcache WHERE ticket_users @> ARRAY[{(long)UserId}::bigint]";
await using NpgsqlCommand cmd = new(query, connection);
int rowCount = Convert.ToInt32(cmd.ExecuteScalar());
if (rowCount > 0)
{
await connection.CloseAsync();
return true;
}
await connection.CloseAsync();
return false;
}

public static async Task<int> GenerateBannDeleteMessageDays(ulong UserId)
{
bool hasOpenTicket = await UserHasOpenTicket(UserId);
if (hasOpenTicket)
{
return 0;
}
else
{
return 7;
}
}

public static async Task SendWarnAsChannel(CommandContext ctx, DiscordUser user, DiscordEmbed uembed, string caseid)
{
DiscordEmbed userembed = uembed;
Expand Down

0 comments on commit 2fe015b

Please sign in to comment.