public override ValueTask <InviteCreatedEventArgs> HandleDispatchAsync(IGatewayApiClient shard, InviteCreateJsonModel model) { var inviter = Optional.ConvertOrDefault(model.Inviter, x => new TransientUser(Client, x)) as IUser; var targetUser = Optional.ConvertOrDefault(model.TargetUser, x => new TransientUser(Client, x)) as IUser; var targetApplication = Optional.ConvertOrDefault(model.TargetApplication, x => new TransientApplication(Client, x)) as IApplication; var e = new InviteCreatedEventArgs(model.GuildId.GetValueOrNullable(), model.ChannelId, model.Code, model.CreatedAt, inviter, model.MaxAge, model.MaxUses, model.TargetType.GetValueOrNullable(), targetUser, targetApplication, model.Temporary, model.Uses); return(new(e)); }
public void Update(RoleJsonModel model) { Name = model.Name; Color = model.Color != 0 ? model.Color : null; IsHoisted = model.Hoist; Position = model.Position; Permissions = model.Permissions; IsManaged = model.Managed; IsMentionable = model.Mentionable; Tags = Optional.ConvertOrDefault(model.Tags, x => new RoleTags(x), RoleTags.Empty); }
public void Update(RoleJsonModel model) { Name = model.Name; Color = model.Color != 0 ? model.Color : null; IsHoisted = model.Hoist; IconHash = model.Icon.GetValueOrDefault(); Position = model.Position; Permissions = model.Permissions; IsManaged = model.Managed; IsMentionable = model.Mentionable; UnicodeEmoji = Optional.ConvertOrDefault(model.UnicodeEmoji, emojiName => new TransientEmoji(null, emojiName)); Tags = Optional.ConvertOrDefault(model.Tags, model => new TransientRoleTags(model), IRoleTags.Empty); }
public override void Update(MessageJsonModel model) { base.Update(model); EditedAt = model.EditedTimestamp; IsPinned = model.Pinned; MentionsEveryone = model.MentionEveryone; MentionedRoleIds = model.MentionRoles.ReadOnly(); Attachments = model.Attachments.ToReadOnlyList(model => new TransientAttachment(model)); Embeds = model.Embeds.ToReadOnlyList(model => new TransientEmbed(model)); Activity = Optional.ConvertOrDefault(model.Activity, model => new TransientMessageActivity(model)); Application = Optional.ConvertOrDefault(model.Application, model => new TransientMessageApplication(model)); Reference = Optional.ConvertOrDefault(model.MessageReference, model => new TransientMessageReference(model)); ReferencedMessage = Optional.Convert(model.ReferencedMessage, model => new TransientUserMessage(Client, model) as IUserMessage); Components = Optional.ConvertOrDefault(model.Components, (models, client) => models.ToReadOnlyList(client, (model, client) => new TransientRowComponent(client, model) as IRowComponent), Client) ?? Array.Empty <IRowComponent>(); Stickers = Optional.ConvertOrDefault(model.StickerItems, models => models.ToReadOnlyList(model => new TransientMessageSticker(model) as IMessageSticker), Array.Empty <IMessageSticker>()); }
public override ValueTask <ThreadMembersUpdatedEventArgs> HandleDispatchAsync(IGatewayApiClient shard, ThreadMembersUpdateJsonModel model) { var thread = Client.GetChannel(model.GuildId, model.Id) as CachedThreadChannel; thread?.Update(model); var addedMembers = new Dictionary <Snowflake, IThreadMember>(); if (model.AddedMembers.HasValue) { foreach (var memberModel in model.AddedMembers.Value) { addedMembers.Add(memberModel.UserId.Value, new TransientThreadMember(Client, memberModel)); } } var removedMemberIds = Optional.ConvertOrDefault(model.RemovedMemberIds, x => x.ReadOnly(), ReadOnlyList <Snowflake> .Empty); var e = new ThreadMembersUpdatedEventArgs(model.GuildId, model.Id, thread, model.MemberCount, addedMembers, removedMemberIds); return(new(e)); }
public override void Update(MessageJsonModel model) { base.Update(model); EditedAt = model.EditedTimestamp; IsPinned = model.Pinned; MentionsEveryone = model.MentionEveryone; MentionedRoleIds = model.MentionRoles.ReadOnly(); Attachments = model.Attachments.ToReadOnlyList(x => new Attachment(x)); Embeds = model.Embeds.ToReadOnlyList(x => new Embed(x)); Activity = Optional.ConvertOrDefault(model.Activity, x => new MessageActivity(x)); Application = Optional.ConvertOrDefault(model.Application, x => new MessageApplication(x)); Reference = Optional.ConvertOrDefault(model.MessageReference, x => new MessageReference(x)); Flags = model.Flags.GetValueOrDefault(); Stickers = Optional.ConvertOrDefault(model.Stickers, x => x.ToReadOnlyList(y => new Sticker(y)), Array.Empty <Sticker>()); if (model.Type == MessageType.Reply || model.ReferencedMessage.GetValueOrDefault() != null) { // Fix for Discord always sending an empty property. ReferencedMessage = Optional.Convert(model.ReferencedMessage, x => new TransientUserMessage(Client, x) as IUserMessage); } }
public void Update(MessageUpdateJsonModel model) { if (model.Author.HasValue) { if (_transientAuthor != null) { if (model.Member.HasValue) { model.Member.Value.User = model.Author; _transientAuthor = new TransientMember(Client, GuildId.Value, model.Member.Value); } else { _transientAuthor = new TransientUser(Client, model.Author.Value); } } } if (model.Content.HasValue) { Content = model.Content.Value; } if (model.Mentions.HasValue) { MentionedUsers = model.Mentions.Value.ToReadOnlyList(Client, (x, client) => { var user = client.GetUser(x.Id); if (user != null) { return(user); } return(new TransientUser(client, x) as IUser); }); } if (model.Reactions.HasValue) { Reactions = Optional.Convert(model.Reactions, x => x.ToReadOnlyDictionary(x => Emoji.Create(x.Emoji), x => new MessageReaction(x))); } if (model.EditedTimestamp.HasValue) { EditedAt = model.EditedTimestamp.Value; } if (model.Pinned.HasValue) { IsPinned = model.Pinned.Value; } if (model.MentionEveryone.HasValue) { MentionsEveryone = model.MentionEveryone.Value; } if (model.MentionRoles.HasValue) { MentionedRoleIds = model.MentionRoles.Value.ReadOnly(); } if (model.Attachments.HasValue) { Attachments = model.Attachments.Value.ToReadOnlyList(x => new Attachment(x)); } if (model.Embeds.HasValue) { Embeds = model.Embeds.Value.ToReadOnlyList(x => new Embed(x)); } if (model.Activity.HasValue) { Activity = Optional.ConvertOrDefault(model.Activity, x => new MessageActivity(x)); } if (model.Application.HasValue) { Application = Optional.ConvertOrDefault(model.Application, x => new MessageApplication(x)); } if (model.MessageReference.HasValue) { Reference = Optional.ConvertOrDefault(model.MessageReference, x => new MessageReference(x)); } if (model.Flags.HasValue) { Flags = model.Flags.Value; } if (model.ReferencedMessage.HasValue) { ReferencedMessage = Optional.Convert(model.ReferencedMessage, x => new TransientUserMessage(Client, x) as IUserMessage); } if (model.Components.HasValue) { Components = Optional.ConvertOrDefault(model.Components, (models, client) => models.ToReadOnlyList(client, (model, client) => TransientComponent.Create(client, model)), Client) ?? Array.Empty <IComponent>(); } if (model.StickerItems.HasValue) { Stickers = Optional.ConvertOrDefault(model.StickerItems, x => x.ToReadOnlyList(y => new MessageSticker(y)), Array.Empty <MessageSticker>()); } }