Beispiel #1
0
        private void OnReady(Ready arg)
        {
            Guard.IsNotNull(arg, nameof(arg));

            Self.SetSelfUser(arg.User);

            var guildSettings   = new Dictionary <ulong, GuildSettings>();
            var channelSettings = new Dictionary <ulong, ChannelSettings>();

            foreach (var jsonGuildSettings in arg.GuildSettings)
            {
                var gs = new GuildSettings(jsonGuildSettings, out ChannelSettings[] css);
                guildSettings.Add(gs.GuildId ?? 0, gs);
                foreach (var cs in css)
                {
                    channelSettings.Add(cs.ChannelId, cs);
                }
            }

            foreach (var guild in arg.Guilds)
            {
                GuildSettings?thisGuildSettings = null;
                guildSettings.TryGetValue(guild.Id, out thisGuildSettings);

                // All child members are handled here
                Guilds.AddGuild(guild, thisGuildSettings, channelSettings);
            }

            foreach (var channel in arg.PrivateChannels)
            {
                ChannelSettings?thisChannelSettings = null;
                channelSettings?.TryGetValue(channel.Id, out thisChannelSettings);

                Channels.AddChannel(channel, null, thisChannelSettings);
            }

            foreach (var readState in arg.ReadStates)
            {
                Channels.AddReadState(readState);
            }

            foreach (var presence in arg.Presences)
            {
                Users.AddPresence(presence);
            }

            foreach (var relationship in arg.Relationships)
            {
                Users.AddRelationship(relationship);
            }

            Self.UpdateSettings(arg.Settings);

            Guard.IsNotNull(Self.CurrentUser, nameof(Self.CurrentUser));

            LoggedIn?.Invoke(this, Self.CurrentUser);
        }