private async void PubSub_OnChannelPointsRedeemed(object sender, PubSubChannelPointsRedemptionEventModel packet) { PubSubChannelPointsRedeemedEventModel redemption = packet.redemption; UserViewModel user = ChannelSession.Services.User.GetActiveUserByPlatformID(StreamingPlatformTypeEnum.Twitch, redemption.user.id); if (user == null) { user = await UserViewModel.Create(redemption.user); } List <string> arguments = null; Dictionary <string, string> eventCommandSpecialIdentifiers = new Dictionary <string, string>(); eventCommandSpecialIdentifiers["rewardname"] = redemption.reward.title; eventCommandSpecialIdentifiers["rewardcost"] = redemption.reward.cost.ToString(); if (!string.IsNullOrEmpty(redemption.user_input)) { eventCommandSpecialIdentifiers["message"] = redemption.user_input; arguments = new List <string>(redemption.user_input.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)); } if (string.IsNullOrEmpty(await ChannelSession.Services.Moderation.ShouldTextBeModerated(user, redemption.user_input))) { await ChannelSession.Services.Events.PerformEvent(EventTypeEnum.TwitchChannelPointsRedeemed, new CommandParametersModel(user, arguments, eventCommandSpecialIdentifiers)); TwitchChannelPointsCommandModel command = ChannelSession.Services.Command.TwitchChannelPointsCommands.FirstOrDefault(c => string.Equals(c.ChannelPointRewardID.ToString(), redemption.reward.id, StringComparison.CurrentCultureIgnoreCase)); if (command == null) { command = ChannelSession.Services.Command.TwitchChannelPointsCommands.FirstOrDefault(c => string.Equals(c.Name, redemption.reward.title, StringComparison.CurrentCultureIgnoreCase)); } if (command != null) { Dictionary <string, string> channelPointSpecialIdentifiers = new Dictionary <string, string>(eventCommandSpecialIdentifiers); await ChannelSession.Services.Command.Queue(command, new CommandParametersModel(user, platform : StreamingPlatformTypeEnum.Twitch, arguments : arguments, specialIdentifiers : channelPointSpecialIdentifiers)); } } await ChannelSession.Services.Alerts.AddAlert(new AlertChatMessageViewModel(StreamingPlatformTypeEnum.Twitch, user, string.Format("{0} Redeemed {1}", user.FullDisplayName, redemption.reward.title), ChannelSession.Settings.AlertChannelPointsColor)); }
private async void PubSub_OnChannelPointsRedeemed(object sender, PubSubChannelPointsRedemptionEventModel packet) { PubSubChannelPointsRedeemedEventModel redemption = packet.redemption; UserViewModel user = ChannelSession.Services.User.GetUserByTwitchID(redemption.user.id); if (user == null) { user = new UserViewModel(redemption.user); } List <string> arguments = null; Dictionary <string, string> specialIdentifiers = new Dictionary <string, string>(); specialIdentifiers["rewardname"] = redemption.reward.title; specialIdentifiers["rewardcost"] = redemption.reward.cost.ToString(); if (!string.IsNullOrEmpty(redemption.user_input)) { specialIdentifiers["message"] = redemption.user_input; arguments = new List <string>(redemption.user_input.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)); } EventTrigger trigger = new EventTrigger(EventTypeEnum.TwitchChannelPointsRedeemed, user, specialIdentifiers); trigger.Arguments = arguments; await ChannelSession.Services.Events.PerformEvent(trigger); TwitchChannelPointsCommand command = ChannelSession.Settings.TwitchChannelPointsCommands.FirstOrDefault(c => string.Equals(c.Name, redemption.reward.title, StringComparison.CurrentCultureIgnoreCase)); if (command != null) { await command.Perform(user, arguments : arguments, extraSpecialIdentifiers : specialIdentifiers); } await ChannelSession.Services.Alerts.AddAlert(new AlertChatMessageViewModel(StreamingPlatformTypeEnum.Twitch, user, string.Format("{0} Redeemed {1}", user.Username, redemption.reward.title), ChannelSession.Settings.AlertChannelPointsColor)); }