Example #1
0
        internal static SocketGlobalUser Create(DiscordSocketClient discord, ClientState state, Model model)
        {
            var entity = new SocketGlobalUser(discord, model.Id);

            entity.Update(state, model);
            return(entity);
        }
Example #2
0
 internal SocketDMChannel(DiscordSocketClient discord, ulong id, SocketGlobalUser recipient)
     : base(discord, id)
 {
     Recipient = recipient;
     if (Discord.MessageCacheSize > 0)
     {
         _messages = new MessageCache(Discord, this);
     }
 }
Example #3
0
 public SocketDMUser(SocketGlobalUser user)
 {
     User = user;
 }
Example #4
0
 internal SocketSelfUser(DiscordSocketClient discord, SocketGlobalUser globalUser)
     : base(discord, globalUser.Id)
 {
     GlobalUser = globalUser;
 }
Example #5
0
 internal SocketGuildUser(SocketGuild guild, SocketGlobalUser globalUser)
     : base(guild.Discord, globalUser.Id)
 {
     Guild      = guild;
     GlobalUser = globalUser;
 }
Example #6
0
 internal SocketGroupUser(SocketGroupChannel channel, SocketGlobalUser globalUser)
     : base(channel.Discord, globalUser.Id)
 {
     Channel    = channel;
     GlobalUser = globalUser;
 }
Example #7
0
        internal virtual void Update(ClientState state, Model model)
        {
            Type = model.Type;

            if (model.Timestamp.IsSpecified)
            {
                _timestampTicks = model.Timestamp.Value.UtcTicks;
            }

            if (model.Content.IsSpecified)
            {
                Content = model.Content.Value;
            }

            if (model.Application.IsSpecified)
            {
                // create a new Application from the API model
                Application = new MessageApplication()
                {
                    Id          = model.Application.Value.Id,
                    CoverImage  = model.Application.Value.CoverImage,
                    Description = model.Application.Value.Description,
                    Icon        = model.Application.Value.Icon,
                    Name        = model.Application.Value.Name
                };
            }

            if (model.Activity.IsSpecified)
            {
                // create a new Activity from the API model
                Activity = new MessageActivity()
                {
                    Type    = model.Activity.Value.Type.Value,
                    PartyId = model.Activity.Value.PartyId.GetValueOrDefault()
                };
            }

            if (model.Reference.IsSpecified)
            {
                // Creates a new Reference from the API model
                Reference = new MessageReference
                {
                    GuildId           = model.Reference.Value.GuildId,
                    InternalChannelId = model.Reference.Value.ChannelId,
                    MessageId         = model.Reference.Value.MessageId,
                    FailIfNotExists   = model.Reference.Value.FailIfNotExists
                };
            }

            if (model.Components.IsSpecified)
            {
                Components = model.Components.Value.Select(x => new ActionRowComponent(x.Components.Select <IMessageComponent, IMessageComponent>(y =>
                {
                    switch (y.Type)
                    {
                    case ComponentType.Button:
                        {
                            var parsed = (API.ButtonComponent)y;
                            return(new Discord.ButtonComponent(
                                       parsed.Style,
                                       parsed.Label.GetValueOrDefault(),
                                       parsed.Emote.IsSpecified
                                        ? parsed.Emote.Value.Id.HasValue
                                            ? new Emote(parsed.Emote.Value.Id.Value, parsed.Emote.Value.Name, parsed.Emote.Value.Animated.GetValueOrDefault())
                                            : new Emoji(parsed.Emote.Value.Name)
                                        : null,
                                       parsed.CustomId.GetValueOrDefault(),
                                       parsed.Url.GetValueOrDefault(),
                                       parsed.Disabled.GetValueOrDefault()));
                        }

                    case ComponentType.SelectMenu:
                        {
                            var parsed = (API.SelectMenuComponent)y;
                            return(new SelectMenuComponent(
                                       parsed.CustomId,
                                       parsed.Options.Select(z => new SelectMenuOption(
                                                                 z.Label,
                                                                 z.Value,
                                                                 z.Description.GetValueOrDefault(),
                                                                 z.Emoji.IsSpecified
                                        ? z.Emoji.Value.Id.HasValue
                                            ? new Emote(z.Emoji.Value.Id.Value, z.Emoji.Value.Name, z.Emoji.Value.Animated.GetValueOrDefault())
                                            : new Emoji(z.Emoji.Value.Name)
                                        : null,
                                                                 z.Default.ToNullable())).ToList(),
                                       parsed.Placeholder.GetValueOrDefault(),
                                       parsed.MinValues,
                                       parsed.MaxValues,
                                       parsed.Disabled
                                       ));
                        }

                    default:
                        return(null);
                    }
                }).ToList())).ToImmutableArray();
            }
            else
            {
                Components = new List <ActionRowComponent>();
            }

            if (model.UserMentions.IsSpecified)
            {
                var value = model.UserMentions.Value;
                if (value.Length > 0)
                {
                    var newMentions = ImmutableArray.CreateBuilder <SocketUser>(value.Length);
                    for (int i = 0; i < value.Length; i++)
                    {
                        var val = value[i];
                        if (val != null)
                        {
                            var user = Channel.GetUserAsync(val.Id, CacheMode.CacheOnly).GetAwaiter().GetResult() as SocketUser;
                            if (user != null)
                            {
                                newMentions.Add(user);
                            }
                            else
                            {
                                newMentions.Add(SocketUnknownUser.Create(Discord, state, val));
                            }
                        }
                    }
                    _userMentions = newMentions.ToImmutable();
                }
            }

            if (model.Interaction.IsSpecified)
            {
                Interaction = new MessageInteraction <SocketUser>(model.Interaction.Value.Id,
                                                                  model.Interaction.Value.Type,
                                                                  model.Interaction.Value.Name,
                                                                  SocketGlobalUser.Create(Discord, state, model.Interaction.Value.User));
            }

            if (model.Flags.IsSpecified)
            {
                Flags = model.Flags.Value;
            }
        }
Example #8
0
 public SocketGuildUser(SocketGuild guild, SocketGlobalUser user, PresenceModel model)
     : base(guild, user, model)
 {
 }
Example #9
0
 public SocketGuildUser(SocketGuild guild, SocketGlobalUser user, Model model)
     : base(guild, user, model)
 {
     //Presence = new Presence(null, UserStatus.Offline);
 }
Example #10
0
 public SocketGroupUser(SocketGroupChannel channel, SocketGlobalUser user)
     : base(channel, user)
 {
 }