private void SetUpMessagePinEvents() { _listener.Listen(data => { var d = (GatewayEvent.ChannelPinsUpdate)data.Data; List <PinnedMessageData> args = PinEventArgs.Create(d.ChannelId, _client); foreach (PinnedMessageData d2 in args) { var b = new EventBubbler <PinEventArgs>(); ServerTextChannel channel; Message msg; Server server; if (d2.Added.Count > 0) { msg = d2.Added[0]; b.Append(msg.OnPin); channel = ServerTextChannel.GetCached(d.ChannelId); if (channel != null) { b.Append(channel.OnMessagePin); server = channel.Server.GetCachedValue(); if (server != null) { b.Append(server.OnMessagePin); } } b.Append(Message.OnPinAny); } else { msg = d2.Removed[0]; b.Append(msg.OnUnpin); channel = ServerTextChannel.GetCached(d.ChannelId); if (channel != null) { b.Append(channel.OnMessageUnpin); server = channel.Server.GetCachedValue(); if (server != null) { b.Append(server.OnMessageUnpin); } } b.Append(Message.OnUnpinAny); } b.Invoke(_client, new PinEventArgs(d2)); } }, ResponseListener.Unbounded, GatewayOpCode.Dispatch, GatewayEvent.ChannelPinsUpdate.Id); }
// TODO: Events for other things private void SetUpChannelEvents() { // CHANNEL EVENT: Create _listener.Listen(data => { var d = (GatewayEvent.Channel)data.Data; var args = new ChannelEventArgs(d.Data); var b = new EventBubbler <ChannelEventArgs>(); Server i0; // ReSharper disable once SwitchStatementMissingSomeCases (ignoring ServerVoice) switch (d.Data.Type) { case ChannelType.DirectMessage: b.Append(DirectMessageTextChannel.OnCreate); b.Append(TextChannel.OnCreate); b.Append(ChannelUtils.OnDirectMessageChannelCreate); b.Append(ChannelUtils.OnChannelCreate); b.Append(ChannelUtils.OnCreate); break; case ChannelType.GroupDirectMessage: b.Append(DirectMessageTextChannel.OnCreate); b.Append(TextChannel.OnCreate); b.Append(ChannelUtils.OnDirectMessageChannelCreate); b.Append(ChannelUtils.OnChannelCreate); b.Append(ChannelUtils.OnCreate); break; case ChannelType.ServerText: i0 = ((IServerChannel)d.Data).Server.GetCachedValue(); if (i0 != null) { b.Append(i0.OnTextChannelCreate); } if (i0 != null) { b.Append(i0.OnNonCatChannelCreate); } if (i0 != null) { b.Append(i0.OnChannelCreate); } b.Append(ServerTextChannel.OnCreate); b.Append(TextChannel.OnCreate); b.Append(ChannelUtils.OnNonCatServerChannelCreate); b.Append(ChannelUtils.OnServerChannelCreate); b.Append(ChannelUtils.OnChannelCreate); b.Append(ChannelUtils.OnCreate); break; case ChannelType.ServerCategory: i0 = ((IServerChannel)d.Data).Server.GetCachedValue(); if (i0 != null) { b.Append(i0.OnCategoryCreate); } if (i0 != null) { b.Append(i0.OnChannelCreate); } b.Append(ChannelCategory.OnCreate); b.Append(ChannelUtils.OnServerChannelCreate); b.Append(ChannelUtils.OnCreate); break; } b.Invoke(_client, args); }, ResponseListener.Unbounded, GatewayOpCode.Dispatch, GatewayEvent.Channel.CreateId); // CHANNEL EVENT: Delete _listener.Listen(data => { var d = (GatewayEvent.Channel)data.Data; var args = new ChannelEventArgs(d.Data); var b = new EventBubbler <ChannelEventArgs>(); b.Append(((IInternalChannel)d.Data).OnDelete); Server i0; // ReSharper disable once SwitchStatementMissingSomeCases (ignoring ServerVoice) switch (d.Data.Type) { case ChannelType.DirectMessage: b.Append(DirectMessageTextChannel.OnDeleteAny); b.Append(TextChannel.OnDeleteAny); b.Append(ChannelUtils.OnDirectMessageChannelDelete); b.Append(ChannelUtils.OnChannelDelete); b.Append(ChannelUtils.OnDelete); break; case ChannelType.GroupDirectMessage: b.Append(DirectMessageTextChannel.OnDeleteAny); b.Append(TextChannel.OnDeleteAny); b.Append(ChannelUtils.OnDirectMessageChannelDelete); b.Append(ChannelUtils.OnChannelDelete); b.Append(ChannelUtils.OnDelete); break; case ChannelType.ServerText: i0 = ((IServerChannel)d.Data).Server.GetCachedValue(); if (i0 != null) { b.Append(i0.OnTextChannelDelete); } if (i0 != null) { b.Append(i0.OnNonCatChannelDelete); } if (i0 != null) { b.Append(i0.OnChannelDelete); } b.Append(ServerTextChannel.OnDeleteAny); b.Append(TextChannel.OnDeleteAny); b.Append(ChannelUtils.OnNonCatServerChannelDelete); b.Append(ChannelUtils.OnServerChannelDelete); b.Append(ChannelUtils.OnChannelDelete); b.Append(ChannelUtils.OnDelete); break; case ChannelType.ServerCategory: i0 = ((IServerChannel)d.Data).Server.GetCachedValue(); if (i0 != null) { b.Append(i0.OnCategoryDelete); } if (i0 != null) { b.Append(i0.OnChannelDelete); } b.Append(ChannelCategory.OnDeleteAny); b.Append(ChannelUtils.OnServerChannelDelete); b.Append(ChannelUtils.OnDelete); break; } b.Invoke(_client, args); d.Data.Uncache(); }, ResponseListener.Unbounded, GatewayOpCode.Dispatch, GatewayEvent.Channel.DeleteId); // CHANNEL EVENT: Update _listener.Listen(data => { var d = (GatewayEvent.Channel)data.Data; var args = new ChannelEventArgs(d.Data); var b = new EventBubbler <ChannelEventArgs>(); b.Append(((IInternalChannel)d.Data).OnUpdate); Server i0; // ReSharper disable once SwitchStatementMissingSomeCases (ignoring ServerVoice) switch (d.Data.Type) { case ChannelType.DirectMessage: b.Append(DirectMessageTextChannel.OnUpdateAny); b.Append(TextChannel.OnUpdateAny); b.Append(ChannelUtils.OnDirectMessageChannelUpdate); b.Append(ChannelUtils.OnChannelUpdate); b.Append(ChannelUtils.OnUpdate); break; case ChannelType.GroupDirectMessage: b.Append(DirectMessageTextChannel.OnUpdateAny); b.Append(TextChannel.OnUpdateAny); b.Append(ChannelUtils.OnDirectMessageChannelUpdate); b.Append(ChannelUtils.OnChannelUpdate); b.Append(ChannelUtils.OnUpdate); break; case ChannelType.ServerText: i0 = ((IServerChannel)d.Data).Server.GetCachedValue(); if (i0 != null) { b.Append(i0.OnTextChannelUpdate); } if (i0 != null) { b.Append(i0.OnNonCatChannelUpdate); } if (i0 != null) { b.Append(i0.OnChannelUpdate); } b.Append(ServerTextChannel.OnUpdateAny); b.Append(TextChannel.OnUpdateAny); b.Append(ChannelUtils.OnNonCatServerChannelUpdate); b.Append(ChannelUtils.OnServerChannelUpdate); b.Append(ChannelUtils.OnChannelUpdate); b.Append(ChannelUtils.OnUpdate); break; case ChannelType.ServerCategory: i0 = ((IServerChannel)d.Data).Server.GetCachedValue(); if (i0 != null) { b.Append(i0.OnCategoryUpdate); } if (i0 != null) { b.Append(i0.OnChannelUpdate); } b.Append(ChannelCategory.OnUpdateAny); b.Append(ChannelUtils.OnServerChannelUpdate); b.Append(ChannelUtils.OnUpdate); break; } b.Invoke(_client, args); }, ResponseListener.Unbounded, GatewayOpCode.Dispatch, GatewayEvent.Channel.UpdateId); }