diff --git a/config.ini b/config.ini index f889d9c3..71092962 100644 --- a/config.ini +++ b/config.ini @@ -8,6 +8,7 @@ Database_Host = PSQLDB host Database_User = -- Database_Password = -- Database = -- +Ticket_Database = -- [EmbedConfig] DefaultEmbedColor = 2F84A2 diff --git a/src/Commands/Moderation/ExtendedModerationSystem.cs b/src/Commands/Moderation/ExtendedModerationSystem.cs index 2a2092a4..22b1c749 100644 --- a/src/Commands/Moderation/ExtendedModerationSystem.cs +++ b/src/Commands/Moderation/ExtendedModerationSystem.cs @@ -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(); + string bot_indicator = user.IsBot ? "<:bot:1012035481573265458>" : ""; string user_status = member?.Presence?.Status.ToString() ?? "Offline"; @@ -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"; @@ -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" diff --git a/src/Helpers/Helpers.cs b/src/Helpers/Helpers.cs index e16e2975..9cb22e3e 100644 --- a/src/Helpers/Helpers.cs +++ b/src/Helpers/Helpers.cs @@ -1,5 +1,6 @@ using DisCatSharp.CommandsNext; using DisCatSharp.Entities; +using Npgsql; namespace AGC_Management.Helpers; @@ -32,9 +33,29 @@ public static async Task CheckForReason(CommandContext ctx, string reason) return false; } - - - + public static async Task 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 MergeOverwrites(DiscordChannel userChannel, List overwrites, out IEnumerable targetOverwrites)