#27 Added handler for received messages

This commit is contained in:
Serraniel 2019-02-25 18:51:46 +01:00
parent d3aa91f826
commit 20f58e16c3
Signed by untrusted user who does not match committer: Serraniel
GPG key ID: 3690B4E7364525D3
2 changed files with 41 additions and 0 deletions

View file

@ -14,7 +14,9 @@
#endregion
using Discord;
using Discord.WebSocket;
using DML.AppCore.Classes;
using SweetLib.Utils.Extensions;
using SweetLib.Utils.Logger;
using System.Collections.Generic;
using System.Threading.Tasks;
@ -129,5 +131,42 @@ namespace DML.Application.Classes
Logger.Trace("SchedulerTask started");
// TODO
}
public Task HandleMessageReceived(SocketMessage msg)
{
Logger.Trace($"Received message: Id: {msg.Id}, Channel: {msg.Channel.Id}, Attachments: {msg.Attachments.Count}");
if (msg.Attachments.Count > 0)
{
foreach (var job in JobList)
{
if (job.State != JobState.Listening || job.ChannelId != msg.Channel.Id)
{
continue;
}
Logger.Debug($"Job found [{job.Id}]");
foreach (var attachment in msg.Attachments)
{
var mediaData = new MediaData
{
Id = attachment.Id,
GuildId = (msg.Channel as SocketTextChannel)?.Guild?.Id ?? 0,
ChannelId = msg.Channel.Id,
DownloadSource = attachment.Url,
Filename = attachment.Filename,
TimeStamp = msg.CreatedAt.UtcDateTime.ToUnixTimeStamp(),
FileSize = attachment.Size
};
mediaData.Store();
}
job.LastMessageId = msg.Id;
job.Store();
}
}
return Task.CompletedTask;
}
}
}

View file

@ -307,6 +307,8 @@ namespace DML.Application.Core
});
}
DMLClient.Client.MessageReceived += Scheduler.HandleMessageReceived;
splash.Close();
Logger.Info("Starting scheduler...");