Add support for reactions (#62)

pull/66/head
IntriguingTiles 6 years ago committed by Alexey Golub
parent 61dce7c1a8
commit e8436faf66

@ -25,11 +25,13 @@ namespace DiscordChatExporter.Core.Models
public IReadOnlyList<Embed> Embeds { get; }
public IReadOnlyList<Reaction> Reactions { get; }
public IReadOnlyList<User> MentionedUsers { get; }
public Message(string id, string channelId, MessageType type, User author, DateTime timestamp,
DateTime? editedTimestamp, string content, IReadOnlyList<Attachment> attachments,
IReadOnlyList<Embed> embeds, IReadOnlyList<User> mentionedUsers)
IReadOnlyList<Embed> embeds, IReadOnlyList<Reaction> reactions, IReadOnlyList<User> mentionedUsers)
{
Id = id;
ChannelId = channelId;
@ -40,6 +42,7 @@ namespace DiscordChatExporter.Core.Models
Content = content;
Attachments = attachments;
Embeds = embeds;
Reactions = reactions;
MentionedUsers = mentionedUsers;
}

@ -0,0 +1,26 @@
using System;
namespace DiscordChatExporter.Core.Models
{
public class Reaction
{
public int Count { get; }
public bool Me { get; }
public string Id { get; }
public string Name { get; }
public string Emoji { get; }
public Reaction(int count, bool me, string id, string name)
{
Count = count;
Me = me;
Id = id;
Name = name;
Emoji = (id == "" ? name : $"<:{name}:{id}>");
}
}
}

@ -181,6 +181,16 @@
</div>
</div>
{{ end }}
{{~ # Reactions }}
<div class="chatlog__reactions">
{{ for reaction in message.Reactions}}
<div class="chatlog__reaction">
<div class="chatlog__reaction-emoji">{{ reaction.Emoji | FormatContent }}</div>
<div class="chatlog__reaction-count">{{ reaction.Count }}</div>
</div>
{{ end }}
</div>
{{ end }}
</div>
</div>

@ -87,4 +87,8 @@ a {
.chatlog__embed-footer {
color: #ffffff99;
}
.chatlog__reaction {
background-color: rgba(255, 255, 255, 0.0392157);
}

@ -48,4 +48,8 @@ a {
.chatlog__edited-timestamp {
color: #99aab5;
}
.chatlog__reaction {
background-color: rgba(79, 84, 92, 0.0588235);
}

@ -283,4 +283,26 @@ img {
.chatlog__embed-footer-text {
font-weight: 600;
font-size: .75em;
}
.chatlog__reactions {
display: flex;
}
.chatlog__reaction {
margin: 2px;
border-radius: 3px;
display: block;
padding-right: 6px;
}
.chatlog__reaction-emoji {
display: inline;
margin-left: 3px;
padding-right: 3px;
font-size: large;
}
.chatlog__reaction-count {
display: inline;
}

@ -138,6 +138,16 @@ namespace DiscordChatExporter.Core.Services
return new Embed(title, url, timestamp, color, author, description, fields, thumbnail, image, footer);
}
private Reaction ParseReaction(JToken json)
{
var count = json["count"].Value<int>();
var me = json["me"].Value<bool>();
var id = json["emoji"]["id"]?.ToString();
var name = json["emoji"]["name"].ToString();
return new Reaction(count, me, id, name);
}
private Message ParseMessage(JToken json)
{
// Get basic data
@ -173,11 +183,15 @@ namespace DiscordChatExporter.Core.Services
// Get embeds
var embeds = json["embeds"].EmptyIfNull().Select(ParseEmbed).ToArray();
// Get reactions
var reactions = json["reactions"].EmptyIfNull().Select(ParseReaction).ToArray();
// Get mentioned users
var mentionedUsers = json["mentions"].EmptyIfNull().Select(ParseUser).ToArray();
return new Message(id, channelId, type, author, timestamp, editedTimestamp, content, attachments, embeds,
mentionedUsers);
reactions, mentionedUsers);
}
}
}
Loading…
Cancel
Save