Log DMs in specified channel
This commit is contained in:
parent
356baa51b8
commit
f225d226a2
|
@ -2,6 +2,7 @@
|
|||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using DeukBot4.Utilities;
|
||||
using Discord;
|
||||
using Discord.WebSocket;
|
||||
|
||||
namespace DeukBot4.MessageHandlers
|
||||
|
@ -29,17 +30,38 @@ namespace DeukBot4.MessageHandlers
|
|||
}
|
||||
}
|
||||
|
||||
private static ITextChannel _dmChannel;
|
||||
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}"));
|
||||
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)
|
||||
{
|
||||
var lowerCasedContent = message.Content.RemoveSpecialCharacters();
|
||||
var lowerCasedContent = message.Content.ToLowerInvariant().RemoveSpecialCharacters();
|
||||
if (lowerCasedContent.Contains("origin"))
|
||||
return;
|
||||
|
||||
|
|
|
@ -20,6 +20,8 @@ namespace DeukBot4
|
|||
public List<ServerChannelIDs> BackupChannels { get; private set; }
|
||||
[JsonProperty]
|
||||
public ImageBackupHandler.NextCloudSettings NextcloudSettings { get; private set; }
|
||||
[JsonProperty]
|
||||
public ulong DmChannel { get; private set; }
|
||||
|
||||
|
||||
public static Settings FromJsonFile(string filepath)
|
||||
|
|
|
@ -5,8 +5,8 @@ namespace DeukBot4.Utilities
|
|||
public static class StringExtensions
|
||||
{
|
||||
public static string RemoveSpecialCharacters(this string str) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
foreach (char c in str) {
|
||||
var sb = new StringBuilder();
|
||||
foreach (var c in str) {
|
||||
if (char.IsLetterOrDigit(c) || char.IsWhiteSpace(c)) {
|
||||
sb.Append(c);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue