74 lines
2.8 KiB
C#
74 lines
2.8 KiB
C#
using Maki.Rest;
|
|
using Maki.Structures.Messages;
|
|
using Maki.Structures.Rest;
|
|
using System;
|
|
using System.Linq;
|
|
|
|
namespace Maki
|
|
{
|
|
public class DiscordMessage
|
|
{
|
|
public readonly ulong Id;
|
|
public readonly DateTime Sent;
|
|
public readonly DiscordMember Member;
|
|
public readonly DiscordUser User;
|
|
public readonly DiscordChannel Channel;
|
|
private readonly Discord client;
|
|
|
|
public string Text { get; internal set; }
|
|
public DateTime Edited { get; internal set; }
|
|
public DiscordMember[] MentionsUsers { get; internal set; }
|
|
public DiscordRole[] MentionsRoles { get; internal set; }
|
|
public bool MentionsEveryone { get; internal set; }
|
|
public bool IsPinned { get; internal set; }
|
|
|
|
public bool MentionsMe(bool everyone = false, bool roles = true) =>
|
|
(everyone && MentionsEveryone)
|
|
|| (Channel.Type != DiscordChannelType.Private && roles && client.members.Where(x => x.User == client.Me && x.Server == Channel.Server).First().Roles.Where(x => MentionsRoles.Contains(x)).Count() > 0)
|
|
|| MentionsUsers.Select(x => x.User).Contains(client.Me);
|
|
|
|
public bool IsMe => client.Me == User;
|
|
|
|
internal DiscordMessage(Discord discord, Message msg, DiscordChannel channel, DiscordMember member = null)
|
|
{
|
|
client = discord;
|
|
Id = msg.Id;
|
|
Sent = msg.Sent;
|
|
Text = msg.Content;
|
|
|
|
if (member != null)
|
|
{
|
|
Member = member;
|
|
User = member.User;
|
|
} else
|
|
{
|
|
member = null;
|
|
User = client.users.Where(x => x.Id == msg.User.Id).FirstOrDefault();
|
|
}
|
|
|
|
Channel = channel;
|
|
MentionsUsers = client.members.Where(x => x.Server == channel.Server && msg.Mentions.Select(y => y.Id).Contains(x.User.Id)).ToArray();
|
|
MentionsRoles = client.roles.Where(x => x.Server == channel.Server && msg.MentionsRoles.Contains(x.Id)).ToArray();
|
|
MentionsEveryone = msg.MentioningEveryone;
|
|
IsPinned = msg.IsPinned == true;
|
|
}
|
|
|
|
public DiscordMessage Edit(string text = null, DiscordEmbed embed = null)
|
|
{
|
|
RestResponse<Message> msg = client.RestClient.Request<Message>(RestRequestMethod.PATCH, RestEndpoints.ChannelMessage(Channel.Id, Id), new MessageEdit {
|
|
Text = text,
|
|
Embed = embed?.ToStruct(),
|
|
});
|
|
|
|
Text = msg.Response.Content;
|
|
Edited = msg.Response.Edited ?? DateTime.UtcNow;
|
|
|
|
return this;
|
|
}
|
|
|
|
public void Delete()
|
|
{
|
|
client.RestClient.Request<object>(RestRequestMethod.DELETE, RestEndpoints.ChannelMessage(Channel.Id, Id));
|
|
}
|
|
}
|
|
}
|