async Task AddMessage(IMessage arg, LogContext _db_ = null) { if (!(arg is IUserMessage umsg)) { return; } if (!(arg.Channel is IGuildChannel guildChannel)) { return; } if (arg.Author.IsBot || arg.Author.IsWebhook) { return; } var content = new MsgContent() { Message = umsg.Id, Content = umsg.Content, Timestamp = umsg.Timestamp.DateTime, }; bool dispose = false; if (_db_ == null) { dispose = true; _db_ = DB(); } _db_.Contents.Add(content); _db_.SaveChanges(); var msg = new MsgModel(umsg); msg.ContentId = content.Id; _db_.Messages.Add(msg); await _db_.SaveChangesAsync(); Console.ForegroundColor = ConsoleColor.Black; Console.BackgroundColor = ConsoleColor.White; Console.WriteLine($"{getWhere(umsg)}: {arg.Author.Username}: {arg.Content}"); Console.ForegroundColor = ConsoleColor.White; Console.BackgroundColor = ConsoleColor.Black; Info($"Starting attachment handle for {arg.Id} on thread {Thread.CurrentThread.Name} | {Thread.CurrentThread.ManagedThreadId}"); foreach (var attch in umsg.Attachments) { HandleAttachment(attch, guildChannel.Guild, umsg.Id); } Info($"Ended attachment handle for {arg.Id} on thread {Thread.CurrentThread.Name} | {Thread.CurrentThread.ManagedThreadId}"); if (dispose) { _db_.Dispose(); } }
public DbMsg(MsgService s, MsgModel model) : base(s) { Id = model.Message; Content = s.GetLatestContent(Id)?.Content.TrimEnd(); Author = Program.Client.GetGuild(model.Guild)?.GetUser(model.Author) ?? null; Author ??= Program.Client.GetUser(model.Author); if (Author == null) { var dbu = new DbUser(model.Author); dbu.Username = s.GetNamesFor(model.Author).LastOrDefault()?.Name; Author = dbu; } Attachments = model.Attachments; Embeds = new List <IEmbed>(); ChannelId = model.Channel; Channel = Program.Client.GetChannel(ChannelId); }