Log DMs in specified channel

This commit is contained in:
Deukhoofd 2018-05-18 13:36:06 +02:00
parent 356baa51b8
commit f225d226a2
No known key found for this signature in database
GPG Key ID: B4C087AC81641654
3 changed files with 28 additions and 4 deletions

View File

@ -2,6 +2,7 @@
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using DeukBot4.Utilities; using DeukBot4.Utilities;
using Discord;
using Discord.WebSocket; using Discord.WebSocket;
namespace DeukBot4.MessageHandlers namespace DeukBot4.MessageHandlers
@ -29,17 +30,38 @@ namespace DeukBot4.MessageHandlers
} }
} }
private static ITextChannel _dmChannel;
private static async Task HandlePrivateMessage(SocketMessage message) private static async Task HandlePrivateMessage(SocketMessage message)
{ {
if (message.Channel is ISocketPrivateChannel) if (message.Channel is IPrivateChannel)
{ {
await Logger.Log(($"Private Message: {message.Author.Username}- {message.Content}")); await Logger.Log(($"Private Message: {message.Author.Username}- {message.Content}"));
if (_dmChannel == null)
{
_dmChannel = (ITextChannel) Program.Client.GetChannel(Program.Settings.DmChannel);
}
var eb = new EmbedBuilder
{
Author = new EmbedAuthorBuilder
{
Name = message.Author.Username,
IconUrl = message.Author.GetAvatarUrl(),
},
Description = message.Content,
Color = Color.Gold,
Timestamp = message.CreatedAt,
Footer = new EmbedFooterBuilder
{
Text = $"User ID: {message.Author.Id}"
}
};
await _dmChannel.SendMessageAsync("", embed: eb.Build());
} }
} }
private static async Task DeltaHandler(SocketMessage message) private static async Task DeltaHandler(SocketMessage message)
{ {
var lowerCasedContent = message.Content.RemoveSpecialCharacters(); var lowerCasedContent = message.Content.ToLowerInvariant().RemoveSpecialCharacters();
if (lowerCasedContent.Contains("origin")) if (lowerCasedContent.Contains("origin"))
return; return;

View File

@ -20,6 +20,8 @@ namespace DeukBot4
public List<ServerChannelIDs> BackupChannels { get; private set; } public List<ServerChannelIDs> BackupChannels { get; private set; }
[JsonProperty] [JsonProperty]
public ImageBackupHandler.NextCloudSettings NextcloudSettings { get; private set; } public ImageBackupHandler.NextCloudSettings NextcloudSettings { get; private set; }
[JsonProperty]
public ulong DmChannel { get; private set; }
public static Settings FromJsonFile(string filepath) public static Settings FromJsonFile(string filepath)

View File

@ -5,8 +5,8 @@ namespace DeukBot4.Utilities
public static class StringExtensions public static class StringExtensions
{ {
public static string RemoveSpecialCharacters(this string str) { public static string RemoveSpecialCharacters(this string str) {
StringBuilder sb = new StringBuilder(); var sb = new StringBuilder();
foreach (char c in str) { foreach (var c in str) {
if (char.IsLetterOrDigit(c) || char.IsWhiteSpace(c)) { if (char.IsLetterOrDigit(c) || char.IsWhiteSpace(c)) {
sb.Append(c); sb.Append(c);
} }