log attachments

This commit is contained in:
Adam R Grey 2023-06-05 15:25:43 -04:00
parent e4f7d88e35
commit 51fba995c3
2 changed files with 18 additions and 29 deletions

View File

@ -94,7 +94,8 @@ public class DiscordInterface
m.MentionsMe = true; m.MentionsMe = true;
} }
if((suMessage.Author.Id != client.CurrentUser.Id)){ if ((suMessage.Author.Id != client.CurrentUser.Id))
{
if (await thingmanagementdoer.Instance.ActOn(m)) if (await thingmanagementdoer.Instance.ActOn(m))
{ {
m.ActedOn = true; m.ActedOn = true;
@ -171,17 +172,23 @@ public class DiscordInterface
internal vassago.Models.Attachment UpsertAttachment(IAttachment dAttachment) internal vassago.Models.Attachment UpsertAttachment(IAttachment dAttachment)
{ {
var addPlease = false;
var a = _db.Attachments.FirstOrDefault(ai => ai.ExternalId == dAttachment.Id); var a = _db.Attachments.FirstOrDefault(ai => ai.ExternalId == dAttachment.Id);
if (a == null) if (a == null)
{ {
var creating = _db.Attachments.Add(new vassago.Models.Attachment()); addPlease = true;
a = creating.Entity; a = new vassago.Models.Attachment();
} }
a.ContentType = dAttachment.ContentType; a.ContentType = dAttachment.ContentType;
a.Description = dAttachment.Description; a.Description = dAttachment.Description;
a.Filename = dAttachment.Filename; a.Filename = dAttachment.Filename;
a.Size = dAttachment.Size; a.Size = dAttachment.Size;
a.Source = new Uri(dAttachment.Url); a.Source = new Uri(dAttachment.Url);
if (addPlease)
{
_db.Attachments.Add(a);
}
return a; return a;
} }
@ -194,12 +201,7 @@ public class DiscordInterface
addPlease = true; addPlease = true;
m = new Message(); m = new Message();
} }
m.Attachments = m.Attachments ?? new List<vassago.Models.Attachment>();
if (m == null)
{
var creating = _db.Messages.Add(new Message() { Author = null, Channel = null });
m = creating.Entity;
}
if (dMessage.Attachments?.Any() == true) if (dMessage.Attachments?.Any() == true)
{ {
m.Attachments = new List<vassago.Models.Attachment>(); m.Attachments = new List<vassago.Models.Attachment>();
@ -208,12 +210,10 @@ public class DiscordInterface
m.Attachments.Add(UpsertAttachment(da)); m.Attachments.Add(UpsertAttachment(da));
} }
} }
//m.Attachments = new List<
m.Author = UpsertUser(dMessage.Author); m.Author = UpsertUser(dMessage.Author);
m.Channel = UpsertChannel(dMessage.Channel); m.Channel = UpsertChannel(dMessage.Channel);
m.Content = dMessage.Content; m.Content = dMessage.Content;
m.ExternalId = dMessage.Id; m.ExternalId = dMessage.Id;
//m.ExternalRepresentation
m.Timestamp = dMessage.EditedTimestamp ?? dMessage.CreatedAt; m.Timestamp = dMessage.EditedTimestamp ?? dMessage.CreatedAt;
if (dMessage.MentionedUserIds?.FirstOrDefault(muid => muid == client.CurrentUser.Id) != null) if (dMessage.MentionedUserIds?.FirstOrDefault(muid => muid == client.CurrentUser.Id) != null)

View File

@ -14,15 +14,4 @@ public class User //more like "user's account - no concept of the person outside
public bool IsBot { get; set; } //webhook counts public bool IsBot { get; set; } //webhook counts
public Channel SeenInChannel { get; set; } public Channel SeenInChannel { get; set; }
public string Protocol { get; set; } public string Protocol { get; set; }
public User(){}
public User(User u)
{
Type t = typeof(User);
PropertyInfo[] properties = t.GetProperties();
foreach (PropertyInfo pi in properties)
{
pi.SetValue(this, pi.GetValue(u, null), null);
}
}
} }