using System.Collections.Generic; using System.Threading.Tasks; using DeukBot4.Utilities; using Npgsql; namespace DeukBot4.Database.ServerSettings { public class ServerSetting { public ServerSetting(ulong serverId, ulong mutedRoleId = 0, List enabledJokes = null) { ServerId = serverId; MutedRoleId = mutedRoleId; EnabledJokes = enabledJokes ?? new List(); } public ulong ServerId { get; } public ulong MutedRoleId { get; private set; } public List EnabledJokes { get; private set; } public async Task SetMutedRoleId(ulong id) { MutedRoleId = id; using (var conn = new DatabaseConnection()) { using (var cmd = new NpgsqlCommand()) { cmd.Connection = conn; cmd.CommandText = "UPDATE server_settings SET muted_role = @val WHERE server_id = @key"; cmd.Parameters.AddWithValue("val", id.ToLong()); cmd.Parameters.AddWithValue("key", ServerId.ToLong()); await cmd.ExecuteNonQueryAsync(); } } } public async Task SetEnabledJokes(List enabledJokes) { EnabledJokes = enabledJokes; using (var conn = new DatabaseConnection()) { using (var cmd = new NpgsqlCommand()) { cmd.Connection = conn; cmd.CommandText = "UPDATE server_settings SET enabled_jokes = @val WHERE server_id = @key"; cmd.Parameters.AddWithValue("val", string.Join(",", enabledJokes)); cmd.Parameters.AddWithValue("key", ServerId.ToLong()); await cmd.ExecuteNonQueryAsync(); } } } } }