Added role updates via PRESENCE_UPDATE

This commit is contained in:
RogueException
2015-10-22 02:25:06 -03:00
parent 83c998168f
commit 235ff5f7c7
3 changed files with 16 additions and 14 deletions

View File

@@ -48,6 +48,8 @@ namespace Discord.API
public string GameId; public string GameId;
[JsonProperty("status")] [JsonProperty("status")]
public string Status; public string Status;
[JsonProperty("roles")] //TODO: Might be temporary
public string[] Roles;
} }
public class VoiceMemberInfo : MemberReference public class VoiceMemberInfo : MemberReference
{ {

View File

@@ -621,13 +621,7 @@ namespace Discord
case "PRESENCE_UPDATE": case "PRESENCE_UPDATE":
{ {
var data = e.Payload.ToObject<PresenceUpdateEvent>(_serializer); var data = e.Payload.ToObject<PresenceUpdateEvent>(_serializer);
var member = _members[data.User.Id, data.GuildId]; var member = _members.GetOrAdd(data.User.Id, data.GuildId);
/*if (_config.TrackActivity)
{
var user = _users[data.User.Id];
if (user != null)
user.UpdateActivity(DateTime.UtcNow);
}*/
if (member != null) if (member != null)
{ {
member.Update(data); member.Update(data);

View File

@@ -95,13 +95,8 @@ namespace Discord
Update(model.User); Update(model.User);
if (model.JoinedAt.HasValue) if (model.JoinedAt.HasValue)
JoinedAt = model.JoinedAt.Value; JoinedAt = model.JoinedAt.Value;
if (model.Roles != null)
//Set roles, with the everyone role added too UpdateRoles(model.Roles);
string[] newRoles = new string[model.Roles.Length + 1];
newRoles[0] = Server.EveryoneRoleId;
for (int i = 0; i < model.Roles.Length; i++)
newRoles[i + 1] = model.Roles[i];
RoleIds = newRoles;
UpdatePermissions(); UpdatePermissions();
} }
@@ -118,6 +113,8 @@ namespace Discord
if (model.User != null) if (model.User != null)
Update(model.User as UserReference); Update(model.User as UserReference);
if (model.Roles != null)
UpdateRoles(model.Roles);
if (model.Status != null && Status != model.Status) if (model.Status != null && Status != model.Status)
{ {
Status = model.Status; Status = model.Status;
@@ -148,6 +145,15 @@ namespace Discord
if (model.IsServerSuppressed != null) if (model.IsServerSuppressed != null)
IsServerSuppressed = model.IsServerSuppressed.Value; IsServerSuppressed = model.IsServerSuppressed.Value;
} }
private void UpdateRoles(string[] roleIds)
{
//Set roles, with the everyone role added too
string[] newRoles = new string[roleIds.Length + 1];
newRoles[0] = Server.EveryoneRoleId;
for (int i = 0; i < roleIds.Length; i++)
newRoles[i + 1] = roleIds[i];
RoleIds = newRoles;
}
internal void UpdateActivity(DateTime? activity = null) internal void UpdateActivity(DateTime? activity = null)
{ {