/// <summary> /// Updates the fields on a GuildDescriptor with those that are contained in a GuildUpdate event's GuildDescriptor /// </summary> /// <param name="original"></param> /// <param name="updated"></param> public static void Update(GuildDescriptor original, GuildDescriptor updated) { foreach (FieldInfo info in UpdateableFields) { info.SetValue(original, info.GetValue(updated)); } }
public GuildDescriptor UpdateGuild(GuildDescriptor guild) { if (!MappedGuilds.TryGetValue(guild.Id, out GuildDescriptor original)) { throw new MappingException("Attempted to update a guild that was not previously tracked", guild); } GuildMapperTypeInfo.Update(original, guild); original.AfkChannel = original.afk_channel_id.HasValue ? original.Channels.First(c => c.id == original.afk_channel_id) : null; original.EmbedChannel = original.HasEmbedChannel ? original.Channels.First(c => c.id == original.embed_channel_id) : null; original.SystemChannel = original.HasSystemChannel ? original.Channels.First(c => c.id == original.system_channel_id) : null; return(original); }
public void Map(GuildDescriptor descriptor) { descriptor.AfkChannel = descriptor.afk_channel_id.HasValue ? descriptor.Channels.First(c => c.id == descriptor.afk_channel_id) : null; descriptor.EmbedChannel = descriptor.HasEmbedChannel ? descriptor.Channels.First(c => c.id == descriptor.embed_channel_id) : null; descriptor.SystemChannel = descriptor.HasSystemChannel ? descriptor.Channels.First(c => c.id == descriptor.system_channel_id) : null; foreach (MemberDescriptor member in descriptor.Members) { member.Guild = descriptor; member.guild_id = descriptor.Id; //member.Roles will be null before this. //descriptor.Roles contains the fully defined Role objects for the entire server //member.roles contains role IDs //The join query maps these two collections together to provide member.Roles with a fully defined set of Role objects //based on the role IDs assigned to the member member.Roles = descriptor.Roles.Join(member.roles, roleD => roleD.Id, roleId => roleId, (d, id) => d); member.PresenceState = descriptor.Presences.FirstOrDefault(p => p.user.id == member.User.Id); member.VoiceState = descriptor.VoiceStates.FirstOrDefault(v => v.user_id == member.User.Id); } foreach (ChannelDescriptor channel in descriptor.Channels) { channel.guild_id = descriptor.Id; if (channel is ChannelCategoryDescriptor catChannel) { catChannel.Guild = descriptor; } if (channel is TextChannelDescriptor txtChannel) { txtChannel.Guild = descriptor; txtChannel.ParentCategory = txtChannel.parent_id.HasValue ? (ChannelCategoryDescriptor)descriptor.Channels.First(c => c.Id == txtChannel.parent_id.Value) : null; } if (channel is VoiceChannelDescriptor voiChannel) { voiChannel.Guild = descriptor; voiChannel.ParentCategory = voiChannel.parent_id.HasValue ? (ChannelCategoryDescriptor)descriptor.Channels.First(c => c.Id == voiChannel.parent_id.Value) : null; } } descriptor.Owner = descriptor.Members.First(m => m.User.Id == descriptor.owner_id).User; MappedGuilds.TryAdd(descriptor.Id, descriptor); }
public void DeleteMap(GuildDescriptor guild) { MappedGuilds.Remove(guild.Id); }
public void DeleteMap(GuildDescriptor guild) { _guildMapper.DeleteMap(guild); }
public GuildDescriptor UpdateMap(GuildDescriptor guild) { return(_guildMapper.UpdateGuild(guild)); }
/// <summary> /// Provides post-deserialization mapping to a GuildDescriptor instance /// </summary> /// <param name="guild"></param> public void Map(GuildDescriptor guild) { _guildMapper.Map(guild); }