mirror of
https://github.com/Tyrrrz/DiscordChatExporter.git
synced 2026-02-14 15:53:30 -07:00
Add support for reactions (#62)
This commit is contained in:
parent
61dce7c1a8
commit
e8436faf66
|
|
@ -25,11 +25,13 @@ namespace DiscordChatExporter.Core.Models
|
||||||
|
|
||||||
public IReadOnlyList<Embed> Embeds { get; }
|
public IReadOnlyList<Embed> Embeds { get; }
|
||||||
|
|
||||||
|
public IReadOnlyList<Reaction> Reactions { get; }
|
||||||
|
|
||||||
public IReadOnlyList<User> MentionedUsers { get; }
|
public IReadOnlyList<User> MentionedUsers { get; }
|
||||||
|
|
||||||
public Message(string id, string channelId, MessageType type, User author, DateTime timestamp,
|
public Message(string id, string channelId, MessageType type, User author, DateTime timestamp,
|
||||||
DateTime? editedTimestamp, string content, IReadOnlyList<Attachment> attachments,
|
DateTime? editedTimestamp, string content, IReadOnlyList<Attachment> attachments,
|
||||||
IReadOnlyList<Embed> embeds, IReadOnlyList<User> mentionedUsers)
|
IReadOnlyList<Embed> embeds, IReadOnlyList<Reaction> reactions, IReadOnlyList<User> mentionedUsers)
|
||||||
{
|
{
|
||||||
Id = id;
|
Id = id;
|
||||||
ChannelId = channelId;
|
ChannelId = channelId;
|
||||||
|
|
@ -40,6 +42,7 @@ namespace DiscordChatExporter.Core.Models
|
||||||
Content = content;
|
Content = content;
|
||||||
Attachments = attachments;
|
Attachments = attachments;
|
||||||
Embeds = embeds;
|
Embeds = embeds;
|
||||||
|
Reactions = reactions;
|
||||||
MentionedUsers = mentionedUsers;
|
MentionedUsers = mentionedUsers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
26
DiscordChatExporter.Core/Models/Reaction.cs
Normal file
26
DiscordChatExporter.Core/Models/Reaction.cs
Normal file
|
|
@ -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>
|
||||||
</div>
|
</div>
|
||||||
{{ end }}
|
{{ 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 }}
|
{{ end }}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -88,3 +88,7 @@ a {
|
||||||
.chatlog__embed-footer {
|
.chatlog__embed-footer {
|
||||||
color: #ffffff99;
|
color: #ffffff99;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.chatlog__reaction {
|
||||||
|
background-color: rgba(255, 255, 255, 0.0392157);
|
||||||
|
}
|
||||||
|
|
@ -49,3 +49,7 @@ a {
|
||||||
.chatlog__edited-timestamp {
|
.chatlog__edited-timestamp {
|
||||||
color: #99aab5;
|
color: #99aab5;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.chatlog__reaction {
|
||||||
|
background-color: rgba(79, 84, 92, 0.0588235);
|
||||||
|
}
|
||||||
|
|
@ -284,3 +284,25 @@ img {
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
font-size: .75em;
|
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);
|
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)
|
private Message ParseMessage(JToken json)
|
||||||
{
|
{
|
||||||
// Get basic data
|
// Get basic data
|
||||||
|
|
@ -173,11 +183,15 @@ namespace DiscordChatExporter.Core.Services
|
||||||
// Get embeds
|
// Get embeds
|
||||||
var embeds = json["embeds"].EmptyIfNull().Select(ParseEmbed).ToArray();
|
var embeds = json["embeds"].EmptyIfNull().Select(ParseEmbed).ToArray();
|
||||||
|
|
||||||
|
// Get reactions
|
||||||
|
var reactions = json["reactions"].EmptyIfNull().Select(ParseReaction).ToArray();
|
||||||
|
|
||||||
// Get mentioned users
|
// Get mentioned users
|
||||||
var mentionedUsers = json["mentions"].EmptyIfNull().Select(ParseUser).ToArray();
|
var mentionedUsers = json["mentions"].EmptyIfNull().Select(ParseUser).ToArray();
|
||||||
|
|
||||||
|
|
||||||
return new Message(id, channelId, type, author, timestamp, editedTimestamp, content, attachments, embeds,
|
return new Message(id, channelId, type, author, timestamp, editedTimestamp, content, attachments, embeds,
|
||||||
mentionedUsers);
|
reactions, mentionedUsers);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in a new issue