private async Task RunGameWispCommand(EventCommand command, GameWispSubscribeEvent subscribeEvent) { if (command != null) { UserViewModel user = new UserViewModel(0, subscribeEvent.Username); UserModel userModel = await ChannelSession.Connection.GetUser(subscribeEvent.Username); if (userModel != null) { user = new UserViewModel(userModel); } GameWispTier tier = null; if (ChannelSession.Services.GameWisp != null) { tier = ChannelSession.Services.GameWisp.ChannelInfo.GetActiveTiers().FirstOrDefault(t => t.ID.ToString().Equals(subscribeEvent.TierID)); } command.AddSpecialIdentifier("subscribemonths", subscribeEvent.SubscribeMonths.ToString()); command.AddSpecialIdentifier("subscribeamount", subscribeEvent.Amount); if (tier != null) { command.AddSpecialIdentifier("subscribetier", tier.Title); } await command.Perform(user); } }
public void SubscriberStatusChangeOccurred(GameWispSubscribeEvent eventData) { if (this.OnSubscriberStatusChangeOccurred != null) { this.OnSubscriberStatusChangeOccurred(this, eventData); } }
private async Task RunGameWispCommand(EventCommand command, GameWispSubscribeEvent subscribeEvent) { if (command != null) { UserViewModel user = new UserViewModel(0, subscribeEvent.Username); UserModel userModel = await ChannelSession.Connection.GetUser(subscribeEvent.Username); if (userModel != null) { user = new UserViewModel(userModel); } GameWispTier tier = null; if (ChannelSession.Services.GameWisp != null) { tier = ChannelSession.Services.GameWisp.ChannelInfo.GetActiveTiers().FirstOrDefault(t => t.ID.ToString().Equals(subscribeEvent.TierID)); } Dictionary <string, string> specialIdentifiers = new Dictionary <string, string>(); specialIdentifiers["subscribemonths"] = subscribeEvent.SubscribeMonths.ToString(); specialIdentifiers["subscribeamount"] = subscribeEvent.Amount; if (tier != null) { specialIdentifiers["subscribetier"] = tier.Title; } await command.Perform(user, arguments : null, extraSpecialIdentifiers : specialIdentifiers); } }
public override async Task Connect() { await base.Connect(); this.SocketReceiveWrapper("unauthorized", (errorData) => { MixItUp.Base.Util.Logger.Log(errorData.ToString()); }); this.SocketReceiveWrapper("disconnect", (errorData) => { MixItUp.Base.Util.Logger.Log(errorData.ToString()); this.service.WebSocketDisconnectedOccurred(); }); this.SocketReceiveWrapper("connect", (connectData) => { JObject jobj = new JObject(); jobj["key"] = GameWispService.ClientID; jobj["secret"] = ChannelSession.SecretManager.GetSecret("GameWispSecret"); this.SocketSendWrapper("authentication", jobj); }); this.SocketReceiveWrapper("authenticated", (authData) => { if (authData != null) { JObject sendJObj = new JObject(); sendJObj["access_token"] = this.oauthToken.accessToken; this.SocketSendWrapper("channel-connect", sendJObj); } }); this.SocketReceiveWrapper("app-channel-connected", (appChannelData) => { if (appChannelData != null) { JObject jobj = JObject.Parse(appChannelData.ToString()); if (jobj != null && jobj["data"] != null && jobj["data"]["status"] != null && jobj["data"]["channel_id"] != null) { if (jobj["data"]["status"].ToString().Equals("authenticated")) { this.channelID = jobj["data"]["channel_id"].ToString(); } } } }); this.SocketEventReceiverWrapper <GameWispWebSocketEvent>("subscriber-new", (eventData) => { GameWispSubscribeEvent subscribeEvent = new GameWispSubscribeEvent(eventData.Data); this.service.SubscribeOccurred(subscribeEvent); Task.Run(async() => { await this.RunGameWispCommand(ChannelSession.Constellation.FindMatchingEventCommand(EnumHelper.GetEnumName(OtherEventTypeEnum.GameWispSubscribed)), subscribeEvent); }); }); this.SocketEventReceiverWrapper <GameWispWebSocketEvent>("subscriber-renewed", (eventData) => { GameWispResubscribeEvent resubscribeEvent = new GameWispResubscribeEvent(eventData.Data); this.service.ResubscribeOccurred(resubscribeEvent); Task.Run(async() => { await this.RunGameWispCommand(ChannelSession.Constellation.FindMatchingEventCommand(EnumHelper.GetEnumName(OtherEventTypeEnum.GameWispResubscribed)), resubscribeEvent); }); }); this.SocketEventReceiverWrapper <GameWispWebSocketEvent>("subscriber-benefits-change", (eventData) => { this.service.SubscriberBenefitsChangeOccurred(new GameWispBenefitsChangeEvent(eventData.Data)); }); this.SocketEventReceiverWrapper <GameWispWebSocketEvent>("subscriber-status-change", (eventData) => { GameWispSubscribeEvent subscribeEvent = new GameWispSubscribeEvent(eventData.Data); this.service.SubscriberStatusChangeOccurred(subscribeEvent); Task.Run(async() => { await this.RunGameWispCommand(ChannelSession.Constellation.FindMatchingEventCommand(EnumHelper.GetEnumName(OtherEventTypeEnum.GameWispSubscribed)), subscribeEvent); }); }); this.SocketEventReceiverWrapper <GameWispWebSocketEvent>("subscriber-anniversary", (eventData) => { this.service.SubscriberAnniversaryOccurred(new GameWispAnniversaryEvent(eventData.Data)); }); for (int i = 0; i < 10 && !this.ConnectedAndAuthenticated; i++) { await Task.Delay(1000); } if (this.ConnectedAndAuthenticated) { this.service.WebSocketConnectedOccurred(); } }