2019-04-19 18:48:37 +00:00
|
|
|
using System.Threading.Tasks;
|
2020-02-12 14:16:19 +00:00
|
|
|
|
2019-04-19 18:48:37 +00:00
|
|
|
using Discord;
|
2020-02-12 14:16:19 +00:00
|
|
|
|
|
|
|
using PluralKit.Core;
|
|
|
|
|
2019-07-18 15:13:42 +00:00
|
|
|
using Serilog;
|
2019-04-19 18:48:37 +00:00
|
|
|
|
2019-04-21 13:33:22 +00:00
|
|
|
namespace PluralKit.Bot {
|
2019-06-21 11:49:58 +00:00
|
|
|
public class LogChannelService {
|
2019-04-19 18:48:37 +00:00
|
|
|
private IDiscordClient _client;
|
2019-04-22 15:10:18 +00:00
|
|
|
private EmbedService _embed;
|
2019-10-27 22:01:20 +00:00
|
|
|
private IDataStore _data;
|
2019-07-18 15:13:42 +00:00
|
|
|
private ILogger _logger;
|
2019-04-19 18:48:37 +00:00
|
|
|
|
2019-10-27 22:01:20 +00:00
|
|
|
public LogChannelService(IDiscordClient client, EmbedService embed, ILogger logger, IDataStore data)
|
2019-04-19 18:48:37 +00:00
|
|
|
{
|
2019-10-27 22:01:20 +00:00
|
|
|
_client = client;
|
|
|
|
_embed = embed;
|
|
|
|
_data = data;
|
2019-07-18 15:13:42 +00:00
|
|
|
_logger = logger.ForContext<LogChannelService>();
|
2019-04-19 18:48:37 +00:00
|
|
|
}
|
|
|
|
|
2019-12-28 11:00:52 +00:00
|
|
|
public async Task LogMessage(PKSystem system, PKMember member, ulong messageId, ulong originalMsgId, IGuildChannel originalChannel, IUser sender, string content, GuildConfig? guildCfg = null)
|
2019-11-03 18:15:50 +00:00
|
|
|
{
|
2019-12-28 11:00:52 +00:00
|
|
|
if (guildCfg == null)
|
|
|
|
guildCfg = await _data.GetOrCreateGuildConfig(originalChannel.GuildId);
|
|
|
|
|
2019-11-03 18:15:50 +00:00
|
|
|
// Bail if logging is disabled either globally or for this channel
|
2019-12-28 11:00:52 +00:00
|
|
|
if (guildCfg.Value.LogChannel == null) return;
|
|
|
|
if (guildCfg.Value.LogBlacklist.Contains(originalChannel.Id)) return;
|
2019-11-03 18:15:50 +00:00
|
|
|
|
|
|
|
// Bail if we can't find the channel
|
2019-12-28 11:00:52 +00:00
|
|
|
if (!(await _client.GetChannelAsync(guildCfg.Value.LogChannel.Value) is ITextChannel logChannel)) return;
|
2019-04-19 18:48:37 +00:00
|
|
|
|
2019-08-08 05:36:09 +00:00
|
|
|
var embed = _embed.CreateLoggedMessageEmbed(system, member, messageId, originalMsgId, sender, content, originalChannel);
|
2019-07-15 15:53:01 +00:00
|
|
|
|
|
|
|
var url = $"https://discordapp.com/channels/{originalChannel.GuildId}/{originalChannel.Id}/{messageId}";
|
|
|
|
await logChannel.SendMessageAsync(text: url, embed: embed);
|
2019-04-19 18:48:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|