internal CachedSystemMessage(ICachedMessageChannel channel, CachedUser author, MessageModel model) : base(channel, author, model) { Type = (SystemMessageType)(model.Type - 1); RawContent = model.Content.GetValueOrDefault(); Update(model); }
internal CachedUserMessage(ICachedMessageChannel channel, CachedUser author, MessageModel model) : base(channel, author, model) { IsTextToSpeech = model.Tts.GetValueOrDefault(); Nonce = model.Nonce.GetValueOrDefault(); WebhookId = model.WebhookId.GetValueOrDefault(); Update(model); }
internal CachedMessage(ICachedMessageChannel channel, CachedUser author, MessageModel model) : base(channel.Client, model.Id) { Channel = channel; Author = author; _reactions = new LockedDictionary <IEmoji, ReactionData>(model.Reactions.HasValue ? model.Reactions.Value?.Length ?? 0 : 0); }
internal CachedMessage(DiscordClient client, MessageModel model, ICachedMessageChannel channel, CachedUser author) : base(client, model.Id) { Channel = channel; Author = author; _reactions = Extensions.CreateConcurrentDictionary <IEmoji, ReactionData>(model.Reactions.HasValue ? model.Reactions.Value.Length : 0); Reactions = new ReadOnlyConcurrentDictionary <IEmoji, ReactionData>(_reactions); }
public Task HandleInviteCreateAsync(PayloadModel payload) { var model = Serializer.ToObject <InviteCreateModel>(payload.D); CachedGuild guild = null; CachedChannel channel; CachedUser inviter = null; if (model.GuildId != null) { guild = GetGuild(model.GuildId.Value); channel = guild.GetChannel(model.ChannelId); if (model.Inviter.HasValue) { inviter = guild.GetMember(model.Inviter.Value.Id); } } else { channel = GetPrivateChannel(model.ChannelId); if (model.Inviter.HasValue) { inviter = GetUser(model.Inviter.Value.Id); } } if (inviter == null && model.Inviter.HasValue) { inviter = new CachedUnknownUser(_client, model.Inviter.Value); } return(_client._inviteCreated.InvokeAsync(new InviteCreatedEventArgs( _client, guild, new SnowflakeOptional <CachedChannel>(channel, model.ChannelId), inviter, model.Code, model.Temporary, model.MaxUses, model.MaxAge, model.CreatedAt))); }
internal static CachedMessage Create(DiscordClient client, MessageModel model, ICachedMessageChannel channel, CachedUser author) { return(model.Type switch { MessageType.Default => new CachedUserMessage(client, model, channel, author), _ => new CachedSystemMessage(client, model, channel, author), });
internal CachedDmChannel(DiscordClient client, ChannelModel model) : base(client, model) { Recipient = client.GetOrAddSharedUser(model.Recipients.Value[0]); Update(model); }
public Task HandleMessageUpdateAsync(PayloadModel payload) { var model = payload.D.ToType <MessageModel>(); ICachedMessageChannel channel; CachedGuild guild = null; if (model.GuildId != null) { guild = GetGuild(model.GuildId.Value); channel = guild.GetTextChannel(model.ChannelId); } else { channel = GetPrivateChannel(model.ChannelId); } if (channel == null) { Log(LogSeverity.Warning, $"Uncached channel in MessageUpdated. Id: {model.ChannelId}"); return(Task.CompletedTask); } var message = channel.GetMessage(model.Id); var before = message?.Clone(); var isWebhook = model.WebhookId.HasValue; if (message == null) { CachedUser author = null; if (!model.Author.HasValue && !isWebhook) { Log(LogSeverity.Warning, "Unknown message and author has no value in MessageUpdated."); return(Task.CompletedTask); } else if (!isWebhook) { if (guild != null) { if (guild.Members.TryGetValue(model.Author.Value.Id, out var member)) { author = member; } else if (model.Member.HasValue) { author = GetOrAddMember(guild, model.Member.Value, model.Author.Value); } } else { author = GetUser(model.Author.Value.Id); } } else { // TODO? // (if isWebhook and no author) return(Task.CompletedTask); } if (author == null) { // TODO Log(LogSeverity.Error, "Author is still null in MessageUpdate."); return(Task.CompletedTask); } message = new CachedUserMessage(channel, author, model); } else { message.Update(model); } return(_client._messageUpdated.InvokeAsync(new MessageUpdatedEventArgs(channel, new SnowflakeOptional <CachedUserMessage>(before, model.Id), message))); }
internal static CachedMessage Create(ICachedMessageChannel channel, CachedUser author, MessageModel model) => model.Type switch {
internal CachedSystemMessage(DiscordClient client, MessageModel model, ICachedMessageChannel channel, CachedUser author) : base(client, model, channel, author) { Type = (SystemMessageType)(model.Type - 1); RawContent = model.Content.GetValueOrDefault(); }