Beispiel #1
0
 private async Task DiscordShardedClientOnMessageUpdated(Cacheable <IMessage, ulong> arg1, SocketMessage arg2, ISocketMessageChannel arg3)
 {
     if (MessageUpdated != null)
     {
         await MessageUpdated.Invoke(this, arg1, arg2, arg3).ConfigureAwait(false);
     }
 }
Beispiel #2
0
        public void RegisterEvents()
        {
            connection.On <ChatListModel>("NewChat", (chat) =>
            {
                NewChat?.Invoke(chat);
            });

            connection.On <MessageModel>("ReceiveMessage", (message) =>
            {
                message.IsMyMessage = false;
                NewCompanionMessage?.Invoke(message);
                if (!Client.Notifications.Any(x => String.Equals(message.ChatId, x)) &&
                    !Properties.UserSettings.Default.AllNotifications)
                {
                    Notify(message);
                }
            });

            connection.On <MessageModel>("MessageDeleted", (message) =>
            {
                MessageDeleted?.Invoke(message);
            });

            connection.On <MessageModel>("MessageUpdated", (message) =>
            {
                MessageUpdated?.Invoke(message);
            });
        }
 /// <summary>
 /// Constructs a new <see cref="BaseSocketClientAbstraction"/> around an existing <see cref="WebSocket.BaseSocketClient"/>.
 /// </summary>
 /// <param name="baseSocketClient">The value to use for <see cref="WebSocket.BaseSocketClient"/>.</param>
 /// <exception cref="ArgumentNullException">Throws for <paramref name="baseSocketClient"/>.</exception>
 protected BaseSocketClientAbstraction(BaseSocketClient baseSocketClient)
     : base(baseSocketClient)
 {
     baseSocketClient.ChannelCreated         += x => ChannelCreated?.InvokeAsync(x.Abstract()) ?? Task.CompletedTask;
     baseSocketClient.ChannelDestroyed       += x => ChannelDestroyed?.InvokeAsync(x.Abstract()) ?? Task.CompletedTask;
     baseSocketClient.ChannelUpdated         += (x, y) => ChannelUpdated?.InvokeAsync(x.Abstract(), y.Abstract()) ?? Task.CompletedTask;
     baseSocketClient.CurrentUserUpdated     += (x, y) => CurrentUserUpdated?.InvokeAsync(x.Abstract(), y.Abstract()) ?? Task.CompletedTask;
     baseSocketClient.GuildAvailable         += x => GuildAvailable?.InvokeAsync(x.Abstract()) ?? Task.CompletedTask;
     baseSocketClient.GuildMembersDownloaded += x => GuildMembersDownloaded?.InvokeAsync(x.Abstract()) ?? Task.CompletedTask;
     baseSocketClient.GuildMemberUpdated     += (x, y) => GuildMemberUpdated?.InvokeAsync(x.Abstract(), y.Abstract()) ?? Task.CompletedTask;
     baseSocketClient.GuildUnavailable       += x => GuildUnavailable?.InvokeAsync(x.Abstract()) ?? Task.CompletedTask;
     baseSocketClient.GuildUpdated           += (x, y) => GuildUpdated?.InvokeAsync(x.Abstract(), y.Abstract()) ?? Task.CompletedTask;
     baseSocketClient.JoinedGuild            += x => JoinedGuild?.InvokeAsync(x.Abstract()) ?? Task.CompletedTask;
     baseSocketClient.LeftGuild             += x => LeftGuild?.InvokeAsync(x.Abstract()) ?? Task.CompletedTask;
     baseSocketClient.MessageReceived       += x => MessageReceived?.InvokeAsync(x.Abstract()) ?? Task.CompletedTask;
     baseSocketClient.MessageUpdated        += (x, y, z) => MessageUpdated?.InvokeAsync(x.Abstract(), y.Abstract(), z.Abstract()) ?? Task.CompletedTask;
     baseSocketClient.MessageDeleted        += (x, y) => MessageDeleted?.InvokeAsync(x.Abstract(), y.Abstract()) ?? Task.CompletedTask;
     baseSocketClient.ReactionAdded         += (x, y, z) => ReactionAdded?.InvokeAsync(x.Abstract(), y.Abstract(), z.Abstract()) ?? Task.CompletedTask;
     baseSocketClient.ReactionRemoved       += (x, y, z) => ReactionRemoved?.InvokeAsync(x.Abstract(), y.Abstract(), z.Abstract()) ?? Task.CompletedTask;
     baseSocketClient.ReactionsCleared      += (x, y) => ReactionsCleared?.InvokeAsync(x.Abstract(), y.Abstract()) ?? Task.CompletedTask;
     baseSocketClient.RecipientAdded        += x => RecipientAdded?.InvokeAsync(x.Abstract()) ?? Task.CompletedTask;
     baseSocketClient.RecipientRemoved      += x => RecipientRemoved?.InvokeAsync(x.Abstract()) ?? Task.CompletedTask;
     baseSocketClient.RoleCreated           += x => RoleCreated?.InvokeAsync(x.Abstract()) ?? Task.CompletedTask;
     baseSocketClient.RoleDeleted           += x => RoleDeleted?.InvokeAsync(x.Abstract()) ?? Task.CompletedTask;
     baseSocketClient.RoleUpdated           += (x, y) => RoleUpdated?.InvokeAsync(x.Abstract(), y.Abstract()) ?? Task.CompletedTask;
     baseSocketClient.UserBanned            += (x, y) => UserBanned?.InvokeAsync(x.Abstract(), y.Abstract()) ?? Task.CompletedTask;
     baseSocketClient.UserIsTyping          += (x, y) => UserIsTyping?.InvokeAsync(x.Abstract(), y.Abstract()) ?? Task.CompletedTask;
     baseSocketClient.UserJoined            += x => UserJoined?.InvokeAsync(x.Abstract()) ?? Task.CompletedTask;
     baseSocketClient.UserLeft              += x => UserLeft?.InvokeAsync(x.Abstract()) ?? Task.CompletedTask;
     baseSocketClient.UserUnbanned          += (x, y) => UserUnbanned?.InvokeAsync(x.Abstract(), y.Abstract()) ?? Task.CompletedTask;
     baseSocketClient.UserUpdated           += (x, y) => UserUpdated?.InvokeAsync(x.Abstract(), y.Abstract()) ?? Task.CompletedTask;
     baseSocketClient.UserVoiceStateUpdated += (x, y, z) => UserVoiceStateUpdated?.InvokeAsync(x.Abstract(), y.Abstract(), z.Abstract()) ?? Task.CompletedTask;
     baseSocketClient.VoiceServerUpdated    += x => VoiceServerUpdated?.InvokeAsync(x.Abstract()) ?? Task.CompletedTask;
 }
        public void PublishMessageUpdated(Guid messageId, string text)
        {
            var evt = new MessageUpdated
            {
                MessageId   = messageId,
                UpdatedText = text
            };

            _publisher.Publish(evt, _messageContext.ReplyTo ?? string.Empty, new Guid(_messageContext.CorrelationId), _contentType).Wait();

            Console.WriteLine($"MessageUpdated published. Id={messageId}, CorrelationId = {_messageContext.CorrelationId}");
        }
Beispiel #5
0
 private async Task ReadOutputAsync(TextReader reader)
 {
     await Task.Run(() =>
     {
         string processOutput;
         string lastMessage = null;
         while ((processOutput = reader.ReadLine()) != null)
         {
             lastMessage = processOutput;
             MessageUpdated?.Invoke(this, new MessageUpdatedEventArgs {
                 Message = lastMessage
             });
         }
         MessageUpdated?.Invoke(this, new MessageUpdatedEventArgs {
             Message = $@"[已完成]{lastMessage}"
         });
     });
 }
Beispiel #6
0
 internal async Task OnMessageUpdated(Cacheable <IMessage, ulong> before, SocketMessage after, ISocketMessageChannel channel) => await(MessageUpdated?.Invoke(before, after, channel) ?? Task.CompletedTask);
        void OnEvent(string eventname, int seq, JsonNode data)
        {
            sequence = seq;
            switch (eventname)
            {
            case "READY":
                gatewayversion = data.SelectValue <int>("v");
                sessionid      = data.SelectValue <string>("session_id");
                OnConnected();
                break;

            case "RESUMED":
                OnConnected();
                break;

            case "INVALID_SESSION":
                Disconnect(1021, "Authentication failure", /*data.SelectValue<bool>("d")*/ false);
                break;

            case "CHANNEL_CREATE":
                ChannelCreated?.Invoke(JSON.Serializer.Read <Channel>(data));
                break;

            case "CHANNEL_UPDATE":
                ChannelUpdated?.Invoke(JSON.Serializer.Read <Channel>(data));
                break;

            case "CHANNEL_DELETE":
                ChannelDeleted?.Invoke(JSON.Serializer.Read <Channel>(data));
                break;

            case "CHANNEL_PINS_UPDATED":
                ChannelPinUpdated?.Invoke(data.SelectValue <string>("channel_id"));
                break;

            case "MESSAGE_CREATE":
                MessageCreated?.Invoke(JSON.Serializer.Read <Message>(data));
                break;

            case "MESSAGE_UPDATE":
                MessageUpdated?.Invoke(JSON.Serializer.Read <Message>(data));
                break;

            case "MESSAGE_DELETE":
                MessageDeleted?.Invoke(data.SelectValue <string>("channel_id"), data.SelectValue <string>("id"));
                break;

            case "MESSAGE_DELETE_BULK":
                MessagesDeleted?.Invoke(data.SelectValue <string>("channel_id"), data.SelectValue <string[]>("ids"));
                break;

            case "GUILD_CREATE":
                GuildCreated?.Invoke(JSON.Serializer.Read <Guild>(data));
                break;

            case "GUILD_UPDATE":
                GuildUpdated?.Invoke(JSON.Serializer.Read <Guild>(data));
                break;

            case "GUILD_DELETE":
                GuildDeleted?.Invoke(JSON.Serializer.Read <UnavailableGuild>(data));
                break;

            case "GUILD_BAN_ADD":
                UserBanned?.Invoke(JSON.Serializer.Read <GuildUser>(data));
                break;

            case "GUILD_BAN_REMOVED":
                UserUnbanned?.Invoke(JSON.Serializer.Read <GuildUser>(data));
                break;

            case "GUILD_EMOJIS_UPDATE":
                EmojisUpdated?.Invoke(data.SelectValue <string>("guild_id"), JSON.Serializer.Read <Emoji[]>(data["emojis"]));
                break;

            case "GUILD_INTEGRATIONS_UPDATE":
                GuildIntegrationsUpdated?.Invoke(data.SelectValue <string>("guild_id"));
                break;

            case "GUILD_MEMBER_ADD":
                GuildMemberAdded?.Invoke(data.SelectValue <string>("guild_id"), JSON.Serializer.Read <GuildMember>(data));
                break;

            case "GUILD_MEMBER_REMOVE":
                GuildMemberRemoved?.Invoke(data.SelectValue <string>("guild_id"), JSON.Serializer.Read <User>(data));
                break;

            case "GUILD_MEMBER_UPDATE":
                GuildMemberUpdated?.Invoke(data.SelectValue <string>("guild_id"), JSON.Serializer.Read <Role[]>(data["roles"]), JSON.Serializer.Read <User>(data["user"]), data.SelectValue <string>("nick"));
                break;

            case "GUILD_MEMBERS_CHUNK":
                GuildMembersChunk?.Invoke(data.SelectValue <string>("guild_id"), JSON.Serializer.Read <GuildMember[]>(data["members"]));
                break;

            case "GUILD_ROLE_CREATE":
                GuildRoleCreated?.Invoke(data.SelectValue <string>("guild_id"), JSON.Serializer.Read <Role>(data["role"]));
                break;

            case "GUILD_ROLE_UPDATE":
                GuildRoleUpdated?.Invoke(data.SelectValue <string>("guild_id"), JSON.Serializer.Read <Role>(data["role"]));
                break;

            case "GUILD_ROLE_DELETE":
                GuildRoleDeleted?.Invoke(data.SelectValue <string>("guild_id"), data.SelectValue <string>("role_id"));
                break;

            case "MESSAGE_REACTION_ADD":
                MessageReactionAdded?.Invoke(data.SelectValue <string>("user_id"), data.SelectValue <string>("channel_id"), data.SelectValue <string>("message_id"), JSON.Serializer.Read <Emoji>(data["emoji"]));
                break;

            case "MESSAGE_REACTION_REMOVE":
                MessageReactionRemoved?.Invoke(data.SelectValue <string>("user_id"), data.SelectValue <string>("channel_id"), data.SelectValue <string>("message_id"), JSON.Serializer.Read <Emoji>(data["emoji"]));
                break;

            case "MESSAGE_REACTION_REMOVE_ALL":
                MessageReactionRemovedAll?.Invoke(data.SelectValue <string>("channel_id"), data.SelectValue <string>("message_id"));
                break;

            case "PRESENCE_UPDATE":
                PresenceUpdated?.Invoke(JSON.Serializer.Read <PresenceUpdate>(data));
                break;

            case "TYPING_START":
                TypingStarted?.Invoke(data.SelectValue <string>("guild_id"), data.SelectValue <string>("user_id"), data.SelectValue <int>("timestamp").ToDateTime());
                break;

            case "USER_UPDATE":
                UserUpdated?.Invoke(JSON.Serializer.Read <User>(data));
                break;

            case "VOICE_STATE_UPDATE":
                VoiceStateUpdated?.Invoke(JSON.Serializer.Read <VoiceState>(data));
                break;

            case "VOICE_SERVER_UPDATE":
                VoiceServerUpdated?.Invoke(data.SelectValue <string>("token"), data.SelectValue <string>("guild_id"), data.SelectValue <string>("endpoint"));
                break;

            case "WEBHOOKS_UPDATE":
                WebhooksUpdated?.Invoke(data.SelectValue <string>("guild_id"), data.SelectValue <string>("channel_id"));
                break;

            default:
                Logger.Warning(this, $"'{eventname}' event not handled", data.ToString());
                break;
            }
        }
Beispiel #8
0
        private void SubscribeToEvents()
        {
            _subscriptions.Apply(x => x.Dispose());
            _subscriptions.Clear();

            #region Channel

            _subscriptions.Add(_connection.On <ChannelSummaryResponse>(ClientEvents.ChannelUpdated,
                                                                       channel =>
            {
                ChannelUpdated?.Invoke(channel);
            }));

            _subscriptions.Add(_connection.On <Guid>(ClientEvents.ChannelClosed,
                                                     channelId =>
            {
                ChannelClosed?.Invoke(channelId);
            }));

            #endregion

            #region Message

            _subscriptions.Add(_connection.On <MessageResponse>(ClientEvents.MessageAdded,
                                                                message =>
            {
                MessageAdded?.Invoke(message);
            }));

            _subscriptions.Add(_connection.On <MessageResponse>(ClientEvents.MessageUpdated,
                                                                message =>
            {
                MessageUpdated?.Invoke(message);
            }));

            _subscriptions.Add(_connection.On <Guid, Guid>(ClientEvents.MessageDeleted,
                                                           (deletedMessageId, channelId) =>
            {
                MessageDeleted?.Invoke(deletedMessageId, channelId);
            }));

            _subscriptions.Add(_connection.On <Guid>(ClientEvents.LastReadMessageChanged,
                                                     channelId =>
            {
                LastReadMessageUpdated?.Invoke(channelId);
            }));

            #endregion

            #region Member

            _subscriptions.Add(_connection.On <ChannelSummaryResponse>(ClientEvents.MemberJoined,
                                                                       (channel) =>
            {
                MemberJoined?.Invoke(channel);
            }));

            _subscriptions.Add(_connection.On <Guid>(ClientEvents.MemberLeft,
                                                     (channelId) =>
            {
                MemberLeft?.Invoke(channelId);
            }));

            _subscriptions.Add(_connection.On <MemberSummaryResponse, Guid>(ClientEvents.MemberDeleted,
                                                                            (member, channelId) =>
            {
                MemberDeleted?.Invoke(member, channelId);
            }));

            #endregion
        }
Beispiel #9
0
 public void Write(string message)
 {
     _messages += message + "\r\n";
     MessageUpdated?.Invoke(this, new EventArgs());
 }
Beispiel #10
0
 internal void OnMessageUpdated(object sender, MessageUpdatedEventArgs messageEvent)
 {
     MessageUpdated?.Invoke(sender as IGeneratedAlgorithm, messageEvent);
 }
Beispiel #11
0
 private void OnMessageUpdated(JsonMessage arg)
 => MessageUpdated?.Invoke(this, new Message(arg, this));
Beispiel #12
0
 private Task MessageUpdatedAsync(Cacheable <IMessage, ulong> before, SocketMessage after, ISocketMessageChannel channel)
 {
     MessageUpdated?.Invoke(before, after, channel);
     return(Task.CompletedTask);
 }
Beispiel #13
0
 public void When(MessageUpdated messageUpdated)
 {
 }
Beispiel #14
0
 private async Task MessageUpdatedAsync(Cacheable <IMessage, ulong> before, SocketMessage after, ISocketMessageChannel channel)
 {
     MessageUpdated?.Invoke(before, after, channel);
 }
Beispiel #15
0
 void IChatServiceCallback.MessageUpdated(ChatMessage message)
 {
     _eventDispatcher.Add(() => MessageUpdated.SafeInvoke(message));
 }