Skip to content

Commit

Permalink
Implement Ticketcount to a user
Browse files Browse the repository at this point in the history
  • Loading branch information
FabiChan99 committed Nov 1, 2023
1 parent 42f9d3a commit 5ef1310
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
1 change: 1 addition & 0 deletions config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Database_Host = PSQLDB host
Database_User = --
Database_Password = --
Database = --
Ticket_Database = --

[EmbedConfig]
DefaultEmbedColor = 2F84A2
Expand Down
9 changes: 9 additions & 0 deletions src/Commands/Moderation/ExtendedModerationSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ public async Task UserInfoCommand(CommandContext ctx, DiscordUser user)
{
isMember = false;
}
string ticketcount = "Tickets konnten nicht abgerufen werden.";
ticketcount = await Helpers.Helpers.GetTicketCount(user.Id).ToString();

Check failure on line 98 in src/Commands/Moderation/ExtendedModerationSystem.cs

View workflow job for this annotation

GitHub Actions / build

'string' does not contain a definition for 'GetAwaiter' and no accessible extension method 'GetAwaiter' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 98 in src/Commands/Moderation/ExtendedModerationSystem.cs

View workflow job for this annotation

GitHub Actions / build

'string' does not contain a definition for 'GetAwaiter' and no accessible extension method 'GetAwaiter' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)


string bot_indicator = user.IsBot ? "<:bot:1012035481573265458>" : "";
string user_status = member?.Presence?.Status.ToString() ?? "Offline";
Expand Down Expand Up @@ -300,6 +303,9 @@ public async Task UserInfoCommand(CommandContext ctx, DiscordUser user)
userinfostring += "**Kommunikations-Timeout**\n";
userinfostring +=
$"{(member.IsCommunicationDisabled ? $"Nutzer getimeouted bis: {member.CommunicationDisabledUntil.Value.Timestamp()}" : "Nutzer nicht getimeouted")}\n\n";
userinfostring += "**Anzahl Tickets**\n";
userinfostring +=
$"{ticketcount}\n\n";
userinfostring +=
$"**Aktueller Voice-Channel**\n{(member.VoiceState != null && member.VoiceState.Channel != null ? member.VoiceState.Channel.Mention : "Mitglied nicht in einem Voice-Channel")}\n\n";
userinfostring += $"**__Alle Verwarnungen ({warncount})__**\n";
Expand Down Expand Up @@ -447,6 +453,9 @@ public async Task UserInfoCommand(CommandContext ctx, DiscordUser user)
userinfostring += $"**Infobadges:** {bot_indicator} {bs_icon} {banicon}\n\n";
userinfostring += "**Der Online-Status und die Plattform**\n";
userinfostring += $"{status_indicator} | Nicht ermittelbar - User ist nicht auf dem Server\n\n";
userinfostring += "**Anzahl Tickets**\n";
userinfostring +=
$"{ticketcount}\n\n";
userinfostring += $"**__Alle Verwarnungen ({warncount})__**\n";
userinfostring += warnlist.Count == 0
? "Es wurden keine gefunden.\n"
Expand Down
27 changes: 24 additions & 3 deletions src/Helpers/Helpers.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using DisCatSharp.CommandsNext;
using DisCatSharp.Entities;
using Npgsql;

namespace AGC_Management.Helpers;

Expand Down Expand Up @@ -32,9 +33,29 @@ public static async Task<bool> CheckForReason(CommandContext ctx, string reason)
return false;
}




public static async Task<long> GetTicketCount(ulong userid)
{
try
{
var dbConfigSection = GlobalProperties.DebugMode ? "DatabaseCfgDBG" : "DatabaseCfg";
var DbHost = BotConfig.GetConfig()[dbConfigSection]["Database_Host"];
var DbUser = BotConfig.GetConfig()[dbConfigSection]["Database_User"];
var DbPass = BotConfig.GetConfig()[dbConfigSection]["Database_Password"];
var DbName = BotConfig.GetConfig()[dbConfigSection]["Ticket_Database"];

await using var con = new NpgsqlConnection($"Host={DbHost};Username={DbUser};Password={DbPass};Database={DbName}");
await con.OpenAsync();
await using var cmd = new NpgsqlCommand($"SELECT COUNT(*) FROM ticketstore WHERE ticket_owner = {userid}", con);
var result = await cmd.ExecuteScalarAsync();
await con.CloseAsync();
return (long) result;
}
catch (Exception e)
{
Console.WriteLine(e);
return 0;
}
}

public static IEnumerable<DiscordOverwriteBuilder> MergeOverwrites(DiscordChannel userChannel, List<DiscordOverwriteBuilder> overwrites,
out IEnumerable<DiscordOverwriteBuilder> targetOverwrites)
Expand Down

0 comments on commit 5ef1310

Please sign in to comment.