private async Task DiscordShardedClientOnChannelCreated(SocketChannel arg) { if (ChannelCreated != null) { await ChannelCreated.Invoke(this, arg).ConfigureAwait(false); } }
private void OnSocketReceived(IAsyncResult ar) { var listener = (TcpListener)ar.AsyncState; TcpClient client; try { client = listener.EndAcceptTcpClient(ar); listenWaiter.Set(); var channel = new TcpChannel(client); channel.IsInitiative = false; Env.Instance.Logger.Trace("HandleIncomingUnsecureRequest: New command channel accepted from: {0}", client.Client.RemoteEndPoint); //没有发送任何事件,直到收到Connect消息。 ChannelCreated?.Invoke(channel); } catch (SocketException e) { //TODO 要不要在这里结束worker? listenWaiter.Set(); return; } catch (ObjectDisposedException e) { //TODO 谁抛出这个异常的? Debug.WriteLine("Exception happened OnSocketReceived" + e.StackTrace); return; } }
private void OnChannelCreated(JsonChannel arg) { var channel = Channels.AddChannel(arg); if (channel is null) { return; } ChannelCreated?.Invoke(this, channel); }
private void OnChannelCreated(SocketFrame gatewayEvent) { GatewayEventArgs <Channel> eventArgs; if (IsChannelAGuildChannel(gatewayEvent)) { eventArgs = new GatewayEventArgs <Channel>(gatewayEvent.GetData <GuildChannel>()); } else { eventArgs = new GatewayEventArgs <Channel>(gatewayEvent.GetData <DirectMessageChannel>()); } ChannelCreated?.Invoke(this, eventArgs); }
//private CancellationTokenSource _channelCancellSource; //private CancellationTokenSource _source; private async Task ListenAction(CancellationToken token) { TcpListener tcpListener = new TcpListener(IPAddress.Any, port); Action cleanup = () => { tcpListener?.Stop(); tcpListener = null; }; token.Register(cleanup); try { tcpListener.Start(); } catch (Exception) { throw new Exception("Can not start ChannelManager, Port is occupied."); } while (!token.IsCancellationRequested) { TcpClient client = await tcpListener.AcceptTcpClientAsync(); #pragma warning disable 4014 Task.Run(() => #pragma warning restore 4014 { var channel = new TcpChannel(client); channel.IsInitiative = false; //没有发送任何事件,直到收到Connect消息。 ChannelCreated?.Invoke(channel); }, token); } cleanup(); //TODO 需要测试! 如果_listenTask.Wait, 这里把_listenTask设置为null,是不会报错。 Stop(); }
public void StartTrackingChannel(string channelId) { ChannelCreated.Invoke(this, new ChannelCreatedEventArgs(channelId)); }
// ROUTED DISCORD EVENTS // #region internal async Task OnChannelCreated(SocketChannel x) => await(ChannelCreated?.Invoke(x) ?? 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; } }
private void RaiseChannelCreated(string channel, string uuid) { ChannelCreated?.Invoke(this, new PresenceEventArgs(channel, uuid)); }
private void OnChannelCreated(IChannel found) { ChannelCreated?.Invoke(this, found); }
protected virtual void OnChannelCreated(Channel channel, User user, Server server) { ChannelCreated?.Invoke(this, new ChannelCreatedEvent(channel, user, server, _client)); }