Archived
1
0
Fork 0
This commit is contained in:
flash 2017-05-21 03:30:45 +02:00
parent a2528d64da
commit 8a22b05cc4
3 changed files with 19 additions and 8 deletions

View file

@ -674,8 +674,8 @@ namespace Maki
private void ShardManager_OnMessageCreate(GatewayShard shard, Message message)
{
DiscordChannel channel = channels.Find(x => x.Id == message.ChannelId);
DiscordMember member = members.Find(x => x.User.Id == message.User.Id && x.Server == channel.Server);
DiscordMessage msg = new DiscordMessage(this, message, member, channel);
DiscordMember member = members.Where(x => x.User.Id == message.User.Id && x.Server == channel.Server).FirstOrDefault();
DiscordMessage msg = new DiscordMessage(this, message, channel, member);
messages.Add(msg);
OnMessageCreate?.Invoke(msg);
}
@ -696,7 +696,7 @@ namespace Maki
RestResponse<Message> getMsg = RestClient.Request<Message>(RestRequestMethod.GET, RestEndpoints.ChannelMessage(message.ChannelId, message.Id));
DiscordChannel channel = channels.Where(x => x.Id == getMsg.Response.ChannelId).FirstOrDefault();
DiscordMember member = members.Where(x => x.User.Id == getMsg.Response.User.Id && (channel.Server == null || channel.Server == x.Server)).FirstOrDefault();
msg = new DiscordMessage(this, getMsg.Response, member, channel);
msg = new DiscordMessage(this, getMsg.Response, channel, member);
messages.Add(msg);
}

View file

@ -50,7 +50,7 @@ namespace Maki
}
);
DiscordMessage message = new DiscordMessage(client, msg.Response, client.members.Find(x => x.User.Id == msg.Response.User.Id), this);
DiscordMessage message = new DiscordMessage(client, msg.Response, this, client.members.Find(x => x.User.Id == msg.Response.User.Id));
client.messages.Add(message);
return message;
}

View file

@ -10,7 +10,8 @@ namespace Maki
{
public readonly ulong Id;
public readonly DateTime Sent;
public readonly DiscordMember Sender;
public readonly DiscordMember Member;
public readonly DiscordUser User;
public readonly DiscordChannel Channel;
private readonly Discord client;
@ -26,15 +27,25 @@ namespace Maki
|| (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 == Sender.User;
public bool IsMe => client.Me == User;
internal DiscordMessage(Discord discord, Message msg, DiscordMember member, DiscordChannel channel)
internal DiscordMessage(Discord discord, Message msg, DiscordChannel channel, DiscordMember member = null)
{
client = discord;
Id = msg.Id;
Sent = msg.Sent;
Text = msg.Content;
Sender = member;
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();