Fix log channel clearing

This commit is contained in:
Ske 2019-06-21 13:52:34 +02:00
parent 2c3c46002a
commit 6e7950722d

View File

@ -6,7 +6,7 @@ using Discord;
namespace PluralKit.Bot { namespace PluralKit.Bot {
public class ServerDefinition { public class ServerDefinition {
public ulong Id { get; set; } public ulong Id { get; set; }
public ulong LogChannel { get; set; } public ulong? LogChannel { get; set; }
} }
public class LogChannelService { public class LogChannelService {
@ -31,17 +31,17 @@ namespace PluralKit.Bot {
public async Task<ITextChannel> GetLogChannel(IGuild guild) { public async Task<ITextChannel> GetLogChannel(IGuild guild) {
var server = await _connection.QueryFirstOrDefaultAsync<ServerDefinition>("select * from servers where id = @Id", new { Id = guild.Id }); var server = await _connection.QueryFirstOrDefaultAsync<ServerDefinition>("select * from servers where id = @Id", new { Id = guild.Id });
if (server == null) return null; if (server?.LogChannel == null) return null;
return await _client.GetChannelAsync(server.LogChannel) as ITextChannel; return await _client.GetChannelAsync(server.LogChannel.Value) as ITextChannel;
} }
public async Task SetLogChannel(IGuild guild, ITextChannel newLogChannel) { public async Task SetLogChannel(IGuild guild, ITextChannel newLogChannel) {
var def = new ServerDefinition { var def = new ServerDefinition {
Id = guild.Id, Id = guild.Id,
LogChannel = newLogChannel.Id LogChannel = newLogChannel?.Id
}; };
await _connection.QueryAsync("insert into servers (id, log_channel) values (@Id, @LogChannel)", def); await _connection.QueryAsync("insert into servers (id, log_channel) values (@Id, @LogChannel) on conflict (id) do update set log_channel = @LogChannel", def);
} }
} }
} }