Compare commits

..

No commits in common. "d2aa1f46cc868b5b17cd81471573fc088dac7726" and "e4f7d88e358dc6dc7b2c0d7f8570e888e1f28c5e" have entirely different histories.

3 changed files with 34 additions and 17 deletions

View File

@ -82,7 +82,7 @@ public class DiscordInterface
if (suMessage == null) if (suMessage == null)
{ {
Console.WriteLine($"{messageParam.Content}, but not a user message"); Console.WriteLine($"{messageParam.Content}, but not a user message");
return; return;
} }
Console.WriteLine($"#{suMessage.Channel}[{DateTime.Now}][{suMessage.Author.Username} [id={suMessage.Author.Id}]][msg id: {suMessage.Id}] {suMessage.Content}"); Console.WriteLine($"#{suMessage.Channel}[{DateTime.Now}][{suMessage.Author.Username} [id={suMessage.Author.Id}]][msg id: {suMessage.Id}] {suMessage.Content}");
@ -94,13 +94,13 @@ 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;
{ Console.WriteLine("survived a savechanges: 103");
m.ActedOn = true;
}
} }
}
_db.SaveChanges(); _db.SaveChanges();
} }
@ -120,6 +120,7 @@ public class DiscordInterface
// seenIn.Add(defaultChannel); // seenIn.Add(defaultChannel);
// u.SeenInChannels = seenIn; // u.SeenInChannels = seenIn;
// _db.SaveChanges(); // _db.SaveChanges();
Console.WriteLine("survived a savechanges: 123");
// } // }
return thingmanagementdoer.Instance.OnJoin(u, defaultChannel); return thingmanagementdoer.Instance.OnJoin(u, defaultChannel);
@ -170,25 +171,20 @@ 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)
{ {
addPlease = true; var creating = _db.Attachments.Add(new vassago.Models.Attachment());
a = new vassago.Models.Attachment(); a = creating.Entity;
} }
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;
} }
internal Message UpsertMessage(IUserMessage dMessage) internal Message UpsertMessage(IUserMessage dMessage)
{ {
var addPlease = false; var addPlease = false;
@ -198,7 +194,12 @@ 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>();
@ -207,10 +208,12 @@ 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)
@ -222,8 +225,8 @@ public class DiscordInterface
_db.Messages.Add(m); _db.Messages.Add(m);
} }
m.Reply = (t) => { return dMessage.ReplyAsync(t); }; m.Reply = (t) => {return dMessage.ReplyAsync(t);};
m.React = (e) => { return dMessage.AddReactionAsync(Emote.Parse(e)); }; m.React = (e) => {return dMessage.AddReactionAsync(Emote.Parse(e));};
return m; return m;
} }
internal Channel UpsertChannel(IMessageChannel channel) internal Channel UpsertChannel(IMessageChannel channel)

View File

@ -47,6 +47,7 @@ namespace vassago.DiscordInterface
{ {
Console.WriteLine($"deleting command {existingCommand.Name} - (created at {existingCommand.CreatedAt}, it's in guild {existingCommand.Guild?.Id} while I'm in {guild?.Id})"); Console.WriteLine($"deleting command {existingCommand.Name} - (created at {existingCommand.CreatedAt}, it's in guild {existingCommand.Guild?.Id} while I'm in {guild?.Id})");
await existingCommand.DeleteAsync(); await existingCommand.DeleteAsync();
Console.WriteLine("survived");
} }
else else
{ {
@ -55,6 +56,7 @@ namespace vassago.DiscordInterface
{ {
Console.WriteLine($"overwriting command {existingCommand.Name}"); Console.WriteLine($"overwriting command {existingCommand.Name}");
await myVersion.register(false, client, guild); await myVersion.register(false, client, guild);
Console.WriteLine($"survived");
} }
myVersion.alreadyRegistered = true; myVersion.alreadyRegistered = true;
} }
@ -63,6 +65,7 @@ namespace vassago.DiscordInterface
{ {
Console.WriteLine($"creating new command {remaining.Id} ({(remaining.guild == null ? "global" : $"for guild {remaining.guild}")})"); Console.WriteLine($"creating new command {remaining.Id} ({(remaining.guild == null ? "global" : $"for guild {remaining.guild}")})");
await remaining.register(true, client, guild); await remaining.register(true, client, guild);
Console.WriteLine($"survived");
} }
} }

View File

@ -14,4 +14,15 @@ 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);
}
}
} }