private async void PlayButton_Click(object sender, RoutedEventArgs e)
        {
            this.PlayButton.Visibility = Visibility.Collapsed;
            this.StopButton.Visibility = Visibility.Visible;

            this.EditButton.IsEnabled   = false;
            this.DeleteButton.IsEnabled = false;
            this.EnableDisableToggleSwitch.IsEnabled = false;

            CommandBase command = this.GetCommandFromCommandButtons <CommandBase>(this);

            if (command != null)
            {
                await command.PerformAndWait(ChannelSession.GetCurrentUser(), new List <string>() { "@" + ChannelSession.GetCurrentUser().UserName });

                if (command is PermissionsCommandBase)
                {
                    PermissionsCommandBase permissionCommand = (PermissionsCommandBase)command;
                    permissionCommand.ResetCooldown(ChannelSession.GetCurrentUser());
                }
                this.SwitchToPlay();
            }

            this.RaiseEvent(new RoutedEventArgs(CommandButtonsControl.PlayClickedEvent, this));
        }
Beispiel #2
0
        private async Task AddMessage(ChatMessageViewModel message)
        {
            this.Messages.Add(message);

            if (!this.ChatUsers.ContainsKey(message.User.ID))
            {
                await this.AddUser(message.User);
            }

            if (this.DisableChat && !message.ID.Equals(Guid.Empty))
            {
                await this.DeleteMessage(message.ID);

                return;
            }

            string moderationReason;

            if (message.ShouldBeModerated(out moderationReason))
            {
                await this.DeleteMessage(message.ID);

                string whisperMessage = " due to chat moderation for the following reason: " + moderationReason + ". Please watch what you type in chat or further actions will be taken.";

                message.User.ChatOffenses++;
                if (ChannelSession.Settings.ModerationTimeout5MinuteOffenseCount > 0 && message.User.ChatOffenses >= ChannelSession.Settings.ModerationTimeout5MinuteOffenseCount)
                {
                    await this.Whisper(message.User.UserName, "You have been timed out from chat for 5 minutes" + whisperMessage);

                    await this.TimeoutUser(message.User.UserName, 300);
                }
                else if (ChannelSession.Settings.ModerationTimeout1MinuteOffenseCount > 0 && message.User.ChatOffenses >= ChannelSession.Settings.ModerationTimeout1MinuteOffenseCount)
                {
                    await this.Whisper(message.User.UserName, "You have been timed out from chat for 1 minute" + whisperMessage);

                    await this.TimeoutUser(message.User.UserName, 60);
                }
                else
                {
                    await this.Whisper(message.User.UserName, "Your message has been deleted" + whisperMessage);
                }
                return;
            }

            if (ChannelSession.IsStreamer && ChatMessageCommandViewModel.IsCommand(message) && !message.User.Roles.Contains(UserRole.Banned))
            {
                ChatMessageCommandViewModel messageCommand = new ChatMessageCommandViewModel(message);

                GlobalEvents.ChatCommandMessageReceived(messageCommand);

                PermissionsCommandBase command = ChannelSession.AllChatCommands.FirstOrDefault(c => c.ContainsCommand(messageCommand.CommandName));
                if (command != null)
                {
                    await command.Perform(message.User, messageCommand.CommandArguments);
                }
            }
        }
        private async Task <bool> CheckMessageForCommandAndRun(ChatMessageViewModel message)
        {
            PermissionsCommandBase command = this.CheckMessageForCommand(message);

            if (command != null)
            {
                Util.Logger.LogDiagnostic(string.Format("Command Found For Message - {0} - {1}", message.ToString(), command.ToString()));

                await this.RunMessageCommand(message, command);

                return(true);
            }
            return(false);
        }
Beispiel #4
0
        private async Task <bool> CheckMessageForCommandAndRun(ChatMessageViewModel message)
        {
            if (!ChannelSession.Settings.AllowCommandWhispering && message.IsWhisper)
            {
                return(false);
            }

            if (ChannelSession.BotUser != null && ChannelSession.Settings.IgnoreBotAccountCommands && message.User != null && message.User.ID.Equals(ChannelSession.BotUser.id))
            {
                return(false);
            }

            if (ChannelSession.Settings.CommandsOnlyInYourStream && !message.IsInUsersChannel)
            {
                return(false);
            }

            if (ChannelSession.IsStreamer && !message.User.MixerRoles.Contains(MixerRoleEnum.Banned))
            {
                GlobalEvents.ChatCommandMessageReceived(message);

                List <PermissionsCommandBase> commandsToCheck = new List <PermissionsCommandBase>(ChannelSession.AllChatCommands);
                commandsToCheck.AddRange(message.User.Data.CustomCommands);
                PermissionsCommandBase command = commandsToCheck.FirstOrDefault(c => c.ContainsCommand(message.CommandName));
                if (command != null)
                {
                    await command.Perform(message.User, message.CommandArguments);

                    if (ChannelSession.Settings.DeleteChatCommandsWhenRun)
                    {
                        await this.DeleteMessage(message.ID);
                    }

                    return(true);
                }
            }

            return(false);
        }
        private PermissionsCommandBase CheckMessageForCommand(ChatMessageViewModel message)
        {
            Util.Logger.LogDiagnostic(string.Format("Checking Message For Command - {0}", message.ToString()));

            if (!ChannelSession.Settings.AllowCommandWhispering && message.IsWhisper)
            {
                return(null);
            }

            if (ChannelSession.BotUser != null && ChannelSession.Settings.IgnoreBotAccountCommands && message.User != null && message.User.ID.Equals(ChannelSession.BotUser.id))
            {
                return(null);
            }

            if (ChannelSession.Settings.CommandsOnlyInYourStream && !message.IsInUsersChannel)
            {
                return(null);
            }

            if (ChannelSession.IsStreamer && !message.User.MixerRoles.Contains(MixerRoleEnum.Banned))
            {
                GlobalEvents.ChatCommandMessageReceived(message);

                List <PermissionsCommandBase> commandsToCheck = new List <PermissionsCommandBase>(ChannelSession.AllEnabledChatCommands);
                commandsToCheck.AddRange(message.User.Data.CustomCommands);

                PermissionsCommandBase command = commandsToCheck.FirstOrDefault(c => c.MatchesCommand(message.Message));
                if (command == null)
                {
                    command = commandsToCheck.FirstOrDefault(c => c.ContainsCommand(message.Message));
                }

                return(command);
            }

            return(null);
        }
        private async Task RunMessageCommand(ChatMessageViewModel message, PermissionsCommandBase command)
        {
            await command.Perform(message.User, command.GetArgumentsFromText(message.Message));

            bool delete = false;

            if (ChannelSession.Settings.DeleteChatCommandsWhenRun)
            {
                if (!command.Requirements.Settings.DontDeleteChatCommandWhenRun)
                {
                    delete = true;
                }
            }
            else if (command.Requirements.Settings.DeleteChatCommandWhenRun)
            {
                delete = true;
            }

            if (delete)
            {
                Util.Logger.LogDiagnostic(string.Format("Deleting Message As Chat Command - {0}", message.Message));
                await this.DeleteMessage(message);
            }
        }
Beispiel #7
0
        private async void PlayButton_Click(object sender, RoutedEventArgs e)
        {
            this.PlayButton.Visibility = Visibility.Collapsed;
            this.StopButton.Visibility = Visibility.Visible;

            this.EditButton.IsEnabled   = false;
            this.DeleteButton.IsEnabled = false;
            this.EnableDisableToggleSwitch.IsEnabled = false;

            CommandBase command = this.GetCommandFromCommandButtons <CommandBase>(this);

            if (command != null)
            {
                UserViewModel currentUser = await ChannelSession.GetCurrentUser();

                Dictionary <string, string> extraSpecialIdentifiers = new Dictionary <string, string>();
                if (command is EventCommand)
                {
                    EventCommand eventCommand = command as EventCommand;
                    switch (eventCommand.EventType)
                    {
                    case Mixer.Base.Clients.ConstellationEventTypeEnum.channel__id__hosted:
                        extraSpecialIdentifiers["hostviewercount"] = "123";
                        break;

                    case Mixer.Base.Clients.ConstellationEventTypeEnum.channel__id__resubscribed:
                        extraSpecialIdentifiers["usersubmonths"] = "5";
                        break;
                    }

                    switch (eventCommand.OtherEventType)
                    {
                    case OtherEventTypeEnum.GameWispSubscribed:
                    case OtherEventTypeEnum.GameWispResubscribed:
                        extraSpecialIdentifiers["subscribemonths"] = "999";
                        extraSpecialIdentifiers["subscribetier"]   = "Test Tier";
                        extraSpecialIdentifiers["subscribeamount"] = "$12.34";
                        break;

                    case OtherEventTypeEnum.StreamlabsDonation:
                    case OtherEventTypeEnum.GawkBoxDonation:
                    case OtherEventTypeEnum.TiltifyDonation:
                    case OtherEventTypeEnum.ExtraLifeDonation:
                    case OtherEventTypeEnum.TipeeeStreamDonation:
                    case OtherEventTypeEnum.TreatStreamDonation:
                    case OtherEventTypeEnum.StreamJarDonation:
                        UserDonationModel donation = new UserDonationModel()
                        {
                            Amount    = 12.34,
                            Message   = "Test donation message",
                            ImageLink = currentUser.AvatarLink
                        };

                        switch (eventCommand.OtherEventType)
                        {
                        case OtherEventTypeEnum.StreamlabsDonation: donation.Source = UserDonationSourceEnum.Streamlabs; break;

                        case OtherEventTypeEnum.GawkBoxDonation: donation.Source = UserDonationSourceEnum.GawkBox; break;

                        case OtherEventTypeEnum.TiltifyDonation: donation.Source = UserDonationSourceEnum.Tiltify; break;

                        case OtherEventTypeEnum.ExtraLifeDonation: donation.Source = UserDonationSourceEnum.ExtraLife; break;

                        case OtherEventTypeEnum.TipeeeStreamDonation: donation.Source = UserDonationSourceEnum.TipeeeStream; break;

                        case OtherEventTypeEnum.TreatStreamDonation: donation.Source = UserDonationSourceEnum.TreatStream; break;

                        case OtherEventTypeEnum.StreamJarDonation: donation.Source = UserDonationSourceEnum.StreamJar; break;
                        }

                        foreach (var kvp in donation.GetSpecialIdentifiers())
                        {
                            extraSpecialIdentifiers[kvp.Key] = kvp.Value;
                        }
                        extraSpecialIdentifiers["donationtype"] = "Pizza";
                        break;

                    case OtherEventTypeEnum.PatreonSubscribed:
                        extraSpecialIdentifiers[SpecialIdentifierStringBuilder.PatreonTierNameSpecialIdentifier]   = "Super Tier";
                        extraSpecialIdentifiers[SpecialIdentifierStringBuilder.PatreonTierAmountSpecialIdentifier] = "12.34";
                        extraSpecialIdentifiers[SpecialIdentifierStringBuilder.PatreonTierImageSpecialIdentifier]  = "https://xforgeassets002.xboxlive.com/xuid-2535473787585366-public/b7a1d715-3a9e-4bdd-a030-32f9e2e0f51e/0013_lots-o-stars_256.png";
                        break;

                    case OtherEventTypeEnum.TwitterStreamTweetRetweet:
                        break;

                    case OtherEventTypeEnum.MixerSkillUsed:
                        extraSpecialIdentifiers["skillname"]     = "Lots of stars";
                        extraSpecialIdentifiers["skilltype"]     = EnumHelper.GetEnumName(SkillTypeEnum.Sticker);
                        extraSpecialIdentifiers["skillcosttype"] = "Embers";
                        extraSpecialIdentifiers["skillcost"]     = "50";
                        extraSpecialIdentifiers["skillimage"]    = "https://xforgeassets002.xboxlive.com/xuid-2535473787585366-public/b7a1d715-3a9e-4bdd-a030-32f9e2e0f51e/0013_lots-o-stars_256.png";
                        extraSpecialIdentifiers["skillissparks"] = false.ToString();
                        extraSpecialIdentifiers["skillisembers"] = true.ToString();
                        extraSpecialIdentifiers["skillmessage"]  = "Hello World!";
                        break;

                    case OtherEventTypeEnum.MixerMilestoneReached:
                        extraSpecialIdentifiers["milestoneamount"]               = "100";
                        extraSpecialIdentifiers["milestoneremainingamount"]      = "100";
                        extraSpecialIdentifiers["milestonereward"]               = "$10.00";
                        extraSpecialIdentifiers["milestonenextamount"]           = "100";
                        extraSpecialIdentifiers["milestonenextremainingamount"]  = "100";
                        extraSpecialIdentifiers["milestonenextreward"]           = "$10.00";
                        extraSpecialIdentifiers["milestonefinalamount"]          = "100";
                        extraSpecialIdentifiers["milestonefinalremainingamount"] = "100";
                        extraSpecialIdentifiers["milestonefinalreward"]          = "$10.00";
                        extraSpecialIdentifiers["milestoneearnedamount"]         = "100";
                        extraSpecialIdentifiers["milestoneearnedreward"]         = "$10.00";
                        break;

                    case OtherEventTypeEnum.MixerSparksUsed:
                        extraSpecialIdentifiers["sparkamount"] = "10";
                        break;

                    case OtherEventTypeEnum.MixerEmbersUsed:
                        extraSpecialIdentifiers["emberamount"] = "10";
                        break;
                    }
                }
                else if (command is InteractiveCommand)
                {
                    InteractiveCommand iCommand = (InteractiveCommand)command;

                    extraSpecialIdentifiers["mixplaycontrolid"]   = iCommand.Name;
                    extraSpecialIdentifiers["mixplaycontrolcost"] = "123";
                }
                else if (command is CustomCommand)
                {
                    if (command.Name.Equals(InventoryWindow.ItemsBoughtCommandName) || command.Name.Equals(InventoryWindow.ItemsSoldCommandName))
                    {
                        extraSpecialIdentifiers["itemtotal"]    = "5";
                        extraSpecialIdentifiers["itemname"]     = "Chocolate Bars";
                        extraSpecialIdentifiers["itemcost"]     = "500";
                        extraSpecialIdentifiers["currencyname"] = "CURRENCY_NAME";
                    }
                }

                await command.PerformAndWait(currentUser, new List <string>() { "@" + currentUser.UserName }, extraSpecialIdentifiers);

                if (command is PermissionsCommandBase)
                {
                    PermissionsCommandBase permissionCommand = (PermissionsCommandBase)command;
                    permissionCommand.ResetCooldown(await ChannelSession.GetCurrentUser());
                }
                this.SwitchToPlay();
            }

            this.RaiseEvent(new RoutedEventArgs(CommandButtonsControl.PlayClickedEvent, this));
        }
        private async Task <ChatMessageViewModel> AddMessage(ChatMessageEventModel messageEvent)
        {
            UserViewModel user = await ChannelSession.ActiveUsers.AddOrUpdateUser(messageEvent.GetUser());

            if (user == null)
            {
                user = new UserViewModel(messageEvent);
            }
            else
            {
                await user.RefreshDetails();
            }
            user.UpdateLastActivity();

            ChatMessageViewModel message = new ChatMessageViewModel(messageEvent, user);

            Util.Logger.LogDiagnostic(string.Format("Message Received - {0}", message.ToString()));

            if (!message.IsWhisper && !this.userEntranceCommands.Contains(user.ID))
            {
                this.userEntranceCommands.Add(user.ID);
                if (user.Data.EntranceCommand != null)
                {
                    await user.Data.EntranceCommand.Perform(user);
                }
            }

            if (this.Messages.ContainsKey(message.ID))
            {
                return(null);
            }
            this.Messages[message.ID] = message;

            if (this.DisableChat && !message.ID.Equals(Guid.Empty))
            {
                Util.Logger.LogDiagnostic(string.Format("Deleting Message As Chat Disabled - {0}", message.Message));
                await this.DeleteMessage(message);

                return(message);
            }

            if (!ModerationHelper.MeetsChatInteractiveParticipationRequirement(user) || !ModerationHelper.MeetsChatEmoteSkillsOnlyParticipationRequirement(user, message))
            {
                Util.Logger.LogDiagnostic(string.Format("Deleting Message As User does not meet requirement - {0} - {1}", ChannelSession.Settings.ModerationChatInteractiveParticipation, message.Message));

                await this.DeleteMessage(message);

                await ModerationHelper.SendChatInteractiveParticipationWhisper(user, isChat : true);

                return(message);
            }

            string moderationReason = await message.ShouldBeModerated();

            if (!string.IsNullOrEmpty(moderationReason))
            {
                Util.Logger.LogDiagnostic(string.Format("Message Should Be Moderated - {0}", message.ToString()));

                bool shouldBeModerated         = true;
                PermissionsCommandBase command = this.CheckMessageForCommand(message);
                if (command != null && string.IsNullOrEmpty(await ModerationHelper.ShouldBeFilteredWordModerated(user, message.Message)))
                {
                    shouldBeModerated = false;
                }

                if (shouldBeModerated)
                {
                    Util.Logger.LogDiagnostic(string.Format("Moderation Being Performed - {0}", message.ToString()));

                    message.ModerationReason = moderationReason;
                    await this.DeleteMessage(message);

                    return(message);
                }
            }

            if (!string.IsNullOrEmpty(ChannelSession.Settings.NotificationChatWhisperSoundFilePath) && message.IsWhisper)
            {
                await ChannelSession.Services.AudioService.Play(ChannelSession.Settings.NotificationChatWhisperSoundFilePath, 100);
            }
            else if (!string.IsNullOrEmpty(ChannelSession.Settings.NotificationChatTaggedSoundFilePath) && message.IsUserTagged)
            {
                await ChannelSession.Services.AudioService.Play(ChannelSession.Settings.NotificationChatTaggedSoundFilePath, 100);
            }
            else if (!string.IsNullOrEmpty(ChannelSession.Settings.NotificationChatMessageSoundFilePath))
            {
                await ChannelSession.Services.AudioService.Play(ChannelSession.Settings.NotificationChatMessageSoundFilePath, 100);
            }

            GlobalEvents.ChatMessageReceived(message);

            if (!await this.CheckMessageForCommandAndRun(message))
            {
                if (message.IsWhisper && ChannelSession.Settings.TrackWhispererNumber && !message.IsStreamerOrBot())
                {
                    await this.whisperNumberLock.WaitAndRelease(() =>
                    {
                        if (!whisperMap.ContainsKey(message.User.ID))
                        {
                            whisperMap[message.User.ID] = whisperMap.Count + 1;
                        }
                        message.User.WhispererNumber = whisperMap[message.User.ID];
                        return(Task.FromResult(0));
                    });

                    await ChannelSession.Chat.Whisper(message.User.UserName, $"You are whisperer #{message.User.WhispererNumber}.", false);
                }
            }

            return(message);
        }
Beispiel #9
0
        public static async Task Version42Upgrade(string filePath)
        {
            SettingsV2Model settings = await FileSerializerHelper.DeserializeFromFile <SettingsV2Model>(filePath, ignoreErrors : true);

            if (settings.IsStreamer)
            {
                List <UserQuoteModel> quotes = new List <UserQuoteModel>();
                await ChannelSession.Services.Database.Read(settings.DatabaseFilePath, "SELECT * FROM Quotes", (Dictionary <string, object> data) =>
                {
                    string json = (string)data["Data"];
                    json        = json.Replace("MixItUp.Base.ViewModel.User.UserQuoteViewModel", "MixItUp.Base.Model.User.UserQuoteModel");
                    quotes.Add(JSONSerializerHelper.DeserializeFromString <UserQuoteModel>(json));
                });

                await ChannelSession.Services.Database.BulkWrite(settings.DatabaseFilePath, "REPLACE INTO Quotes(ID, Data) VALUES(@ID, @Data)",
                                                                 quotes.Select(q => new Dictionary <string, object>()
                {
                    { "@ID", q.ID.ToString() }, { "@Data", JSONSerializerHelper.SerializeToString(q) }
                }));
            }

            await settings.Initialize();

#pragma warning disable CS0612 // Type or member is obsolete
            if (settings.DiagnosticLogging)
            {
                ChannelSession.AppSettings.DiagnosticLogging = true;
            }
#pragma warning restore CS0612 // Type or member is obsolete


#pragma warning disable CS0612 // Type or member is obsolete
            foreach (UserCurrencyModel oldCurrency in settings.Currencies.Values)
            {
                CurrencyModel newCurrency = new CurrencyModel();

                newCurrency.ID                     = oldCurrency.ID;
                newCurrency.Name                   = oldCurrency.Name;
                newCurrency.AcquireAmount          = oldCurrency.AcquireAmount;
                newCurrency.AcquireInterval        = oldCurrency.AcquireInterval;
                newCurrency.MinimumActiveRate      = oldCurrency.MinimumActiveRate;
                newCurrency.OfflineAcquireAmount   = oldCurrency.OfflineAcquireAmount;
                newCurrency.OfflineAcquireInterval = oldCurrency.OfflineAcquireInterval;
                newCurrency.MaxAmount              = oldCurrency.MaxAmount;
                newCurrency.SpecialIdentifier      = oldCurrency.SpecialIdentifier;
                newCurrency.SubscriberBonus        = oldCurrency.SubscriberBonus;
                newCurrency.ModeratorBonus         = oldCurrency.ModeratorBonus;
                newCurrency.OnFollowBonus          = oldCurrency.OnFollowBonus;
                newCurrency.OnHostBonus            = oldCurrency.OnHostBonus;
                newCurrency.OnSubscribeBonus       = oldCurrency.OnSubscribeBonus;
                newCurrency.ResetInterval          = (Model.Currency.CurrencyResetRateEnum)((int)oldCurrency.ResetInterval);
                newCurrency.ResetStartCadence      = oldCurrency.ResetStartCadence;
                newCurrency.LastReset              = oldCurrency.LastReset;
                newCurrency.IsPrimary              = oldCurrency.IsPrimary;

                if (oldCurrency.RankChangedCommand != null)
                {
                    settings.SetCustomCommand(oldCurrency.RankChangedCommand);
                    newCurrency.RankChangedCommandID = oldCurrency.RankChangedCommand.ID;
                }

                foreach (UserRankViewModel rank in oldCurrency.Ranks)
                {
                    newCurrency.Ranks.Add(new RankModel(rank.Name, rank.MinimumPoints));
                }

                settings.Currency[newCurrency.ID] = newCurrency;
            }

            foreach (UserInventoryModel oldInventory in settings.Inventories.Values)
            {
                InventoryModel newInventory = new InventoryModel();

                newInventory.ID                = oldInventory.ID;
                newInventory.Name              = oldInventory.Name;
                newInventory.DefaultMaxAmount  = oldInventory.DefaultMaxAmount;
                newInventory.SpecialIdentifier = oldInventory.SpecialIdentifier;
                newInventory.ShopEnabled       = oldInventory.ShopEnabled;
                newInventory.ShopCommand       = oldInventory.ShopCommand;
                newInventory.ShopCurrencyID    = oldInventory.ShopCurrencyID;
                newInventory.TradeEnabled      = oldInventory.TradeEnabled;
                newInventory.TradeCommand      = oldInventory.TradeCommand;

                if (oldInventory.ItemsBoughtCommand != null)
                {
                    settings.SetCustomCommand(oldInventory.ItemsBoughtCommand);
                    newInventory.ItemsBoughtCommandID = oldInventory.ItemsBoughtCommand.ID;
                }
                else
                {
                    CustomCommand buyCommand = new CustomCommand(InventoryWindowViewModel.ItemsBoughtCommandName);
                    buyCommand.Actions.Add(new ChatAction("You bought $itemtotal $itemname for $itemcost $currencyname", sendAsStreamer: false));
                    settings.SetCustomCommand(buyCommand);
                    newInventory.ItemsBoughtCommandID = buyCommand.ID;
                }

                if (oldInventory.ItemsSoldCommand != null)
                {
                    settings.SetCustomCommand(oldInventory.ItemsSoldCommand);
                    newInventory.ItemsSoldCommandID = oldInventory.ItemsSoldCommand.ID;
                }
                else
                {
                    CustomCommand sellCommand = new CustomCommand(InventoryWindowViewModel.ItemsSoldCommandName);
                    sellCommand.Actions.Add(new ChatAction("You sold $itemtotal $itemname for $itemcost $currencyname", sendAsStreamer: false));
                    settings.SetCustomCommand(sellCommand);
                    newInventory.ItemsSoldCommandID = sellCommand.ID;
                }

                if (oldInventory.ItemsTradedCommand != null)
                {
                    settings.SetCustomCommand(oldInventory.ItemsTradedCommand);
                    newInventory.ItemsTradedCommandID = oldInventory.ItemsTradedCommand.ID;
                }
                else
                {
                    CustomCommand tradeCommand = new CustomCommand(InventoryWindowViewModel.ItemsTradedCommandName);
                    tradeCommand.Actions.Add(new ChatAction("@$username traded $itemtotal $itemname to @$targetusername for $targetitemtotal $targetitemname", sendAsStreamer: false));
                    settings.SetCustomCommand(tradeCommand);
                    newInventory.ItemsTradedCommandID = tradeCommand.ID;
                }

                foreach (UserInventoryItemModel oldItem in oldInventory.Items.Values.ToList())
                {
                    InventoryItemModel newItem = new InventoryItemModel(oldItem.Name, oldItem.MaxAmount, oldItem.BuyAmount, oldItem.SellAmount);
                    newItem.ID = oldItem.ID;
                    newInventory.Items[newItem.ID] = newItem;
                }

                settings.Inventory[newInventory.ID] = newInventory;
            }
#pragma warning restore CS0612 // Type or member is obsolete

            if (settings.GiveawayRequirements != null && settings.GiveawayRequirements.Inventory != null && settings.Inventory.ContainsKey(settings.GiveawayRequirements.Inventory.InventoryID))
            {
                InventoryModel inventory = settings.Inventory[settings.GiveawayRequirements.Inventory.InventoryID];
#pragma warning disable CS0612 // Type or member is obsolete
                if (inventory != null && !string.IsNullOrEmpty(settings.GiveawayRequirements.Inventory.ItemName))
                {
                    InventoryItemModel item = inventory.GetItem(settings.GiveawayRequirements.Inventory.ItemName);
                    if (item != null)
                    {
                        settings.GiveawayRequirements.Inventory.ItemID = item.ID;
                    }
                    settings.GiveawayRequirements.Inventory.ItemName = null;
                }
#pragma warning restore CS0612 // Type or member is obsolete
            }

            foreach (CommandBase command in SettingsV2Upgrader.GetAllCommands(settings))
            {
                if (command is PermissionsCommandBase)
                {
                    PermissionsCommandBase pCommand = (PermissionsCommandBase)command;
                    if (pCommand.Requirements != null && pCommand.Requirements.Inventory != null && settings.Inventory.ContainsKey(pCommand.Requirements.Inventory.InventoryID))
                    {
                        InventoryModel inventory = settings.Inventory[pCommand.Requirements.Inventory.InventoryID];
#pragma warning disable CS0612 // Type or member is obsolete
                        if (inventory != null && !string.IsNullOrEmpty(pCommand.Requirements.Inventory.ItemName))
                        {
                            InventoryItemModel item = inventory.GetItem(pCommand.Requirements.Inventory.ItemName);
                            if (item != null)
                            {
                                pCommand.Requirements.Inventory.ItemID = item.ID;
                            }
                            pCommand.Requirements.Inventory.ItemName = null;
                        }
#pragma warning restore CS0612 // Type or member is obsolete
                    }
                }
            }

            List <UserDataModel> usersToRemove = new List <UserDataModel>();
            foreach (UserDataModel user in settings.UserData.Values.ToList())
            {
                if (user.MixerID <= 0)
                {
                    usersToRemove.Add(user);
                }
            }

            foreach (UserDataModel user in usersToRemove)
            {
                settings.UserData.Remove(user.ID);
            }

            await ChannelSession.Services.Settings.Save(settings);
        }
        public static async Task TestCommand(CommandBase command)
        {
            if (command != null)
            {
                UserViewModel currentUser = ChannelSession.GetCurrentUser();

                Dictionary <string, string> extraSpecialIdentifiers = new Dictionary <string, string>();
                if (command is EventCommand)
                {
                    EventCommand eventCommand = command as EventCommand;
                    switch (eventCommand.EventCommandType)
                    {
                    case EventTypeEnum.TwitchChannelHosted:
                    case EventTypeEnum.TwitchChannelRaided:
                        extraSpecialIdentifiers["hostviewercount"] = "123";
                        extraSpecialIdentifiers["raidviewercount"] = "123";
                        break;

                    case EventTypeEnum.TwitchChannelSubscribed:
                        extraSpecialIdentifiers["message"]         = "Test Message";
                        extraSpecialIdentifiers["usersubplanname"] = "Plan Name";
                        extraSpecialIdentifiers["usersubplan"]     = "Tier 1";
                        break;

                    case EventTypeEnum.TwitchChannelResubscribed:
                        extraSpecialIdentifiers["message"]         = "Test Message";
                        extraSpecialIdentifiers["usersubplanname"] = "Plan Name";
                        extraSpecialIdentifiers["usersubplan"]     = "Tier 1";
                        extraSpecialIdentifiers["usersubmonths"]   = "5";
                        extraSpecialIdentifiers["usersubstreak"]   = "3";
                        break;

                    case EventTypeEnum.TwitchChannelSubscriptionGifted:
                        extraSpecialIdentifiers["usersubplanname"]     = "Plan Name";
                        extraSpecialIdentifiers["usersubplan"]         = "Tier 1";
                        extraSpecialIdentifiers["usersubmonthsgifted"] = "3";
                        extraSpecialIdentifiers["isanonymous"]         = "false";
                        break;

                    case EventTypeEnum.TwitchChannelMassSubscriptionsGifted:
                        extraSpecialIdentifiers["subsgiftedamount"]         = "5";
                        extraSpecialIdentifiers["subsgiftedlifetimeamount"] = "100";
                        extraSpecialIdentifiers["usersubplan"] = "Tier 1";
                        extraSpecialIdentifiers["isanonymous"] = "false";
                        break;

                    case EventTypeEnum.TwitchChannelBitsCheered:
                        extraSpecialIdentifiers["bitsamount"] = "10";
                        extraSpecialIdentifiers["Message"]    = "Test Message";
                        break;

                    case EventTypeEnum.TwitchChannelPointsRedeemed:
                        extraSpecialIdentifiers["rewardname"] = "Test Reward";
                        extraSpecialIdentifiers["rewardcost"] = "100";
                        extraSpecialIdentifiers["message"]    = "Test Message";
                        break;

                    case EventTypeEnum.ChatUserTimeout:
                        extraSpecialIdentifiers["timeoutlength"] = "5m";
                        break;

                    case EventTypeEnum.StreamlabsDonation:
                    case EventTypeEnum.TiltifyDonation:
                    case EventTypeEnum.ExtraLifeDonation:
                    case EventTypeEnum.TipeeeStreamDonation:
                    case EventTypeEnum.TreatStreamDonation:
                    case EventTypeEnum.StreamJarDonation:
                    case EventTypeEnum.JustGivingDonation:
                    case EventTypeEnum.StreamElementsDonation:
                        UserDonationModel donation = new UserDonationModel()
                        {
                            Amount    = 12.34,
                            Message   = "Test donation message",
                            ImageLink = currentUser.AvatarLink
                        };

                        switch (eventCommand.EventCommandType)
                        {
                        case EventTypeEnum.StreamlabsDonation: donation.Source = UserDonationSourceEnum.Streamlabs; break;

                        case EventTypeEnum.TiltifyDonation: donation.Source = UserDonationSourceEnum.Tiltify; break;

                        case EventTypeEnum.ExtraLifeDonation: donation.Source = UserDonationSourceEnum.ExtraLife; break;

                        case EventTypeEnum.TipeeeStreamDonation: donation.Source = UserDonationSourceEnum.TipeeeStream; break;

                        case EventTypeEnum.TreatStreamDonation: donation.Source = UserDonationSourceEnum.TreatStream; break;

                        case EventTypeEnum.StreamJarDonation: donation.Source = UserDonationSourceEnum.StreamJar; break;

                        case EventTypeEnum.JustGivingDonation: donation.Source = UserDonationSourceEnum.JustGiving; break;

                        case EventTypeEnum.StreamElementsDonation: donation.Source = UserDonationSourceEnum.StreamElements; break;
                        }

                        foreach (var kvp in donation.GetSpecialIdentifiers())
                        {
                            extraSpecialIdentifiers[kvp.Key] = kvp.Value;
                        }
                        extraSpecialIdentifiers["donationtype"] = "Pizza";
                        break;

                    case EventTypeEnum.PatreonSubscribed:
                        extraSpecialIdentifiers[SpecialIdentifierStringBuilder.PatreonTierNameSpecialIdentifier]   = "Super Tier";
                        extraSpecialIdentifiers[SpecialIdentifierStringBuilder.PatreonTierAmountSpecialIdentifier] = "12.34";
                        extraSpecialIdentifiers[SpecialIdentifierStringBuilder.PatreonTierImageSpecialIdentifier]  = "https://xforgeassets002.xboxlive.com/xuid-2535473787585366-public/b7a1d715-3a9e-4bdd-a030-32f9e2e0f51e/0013_lots-o-stars_256.png";
                        break;

                    case EventTypeEnum.StreamlootsCardRedeemed:
                        extraSpecialIdentifiers["streamlootscardname"]  = "Test Card";
                        extraSpecialIdentifiers["streamlootscardimage"] = "https://res.cloudinary.com/streamloots/image/upload/f_auto,c_scale,w_250,q_90/static/e19c7bf6-ca3e-49a8-807e-b2e9a1a47524/en_dl_character.png";
                        extraSpecialIdentifiers["streamlootscardvideo"] = "https://cdn.streamloots.com/uploads/5c645b78666f31002f2979d1/3a6bf1dc-7d61-4f93-be0a-f5dc1d0d33b6.webm";
                        extraSpecialIdentifiers["streamlootscardsound"] = "https://static.streamloots.com/b355d1ef-d931-4c16-a48f-8bed0076401b/alerts/default.mp3";
                        extraSpecialIdentifiers["streamlootsmessage"]   = "Test Message";
                        break;

                    case EventTypeEnum.StreamlootsPackPurchased:
                    case EventTypeEnum.StreamlootsPackGifted:
                        extraSpecialIdentifiers["streamlootspurchasequantity"] = "1";
                        break;
                    }
                }
                else if (command is CustomCommand)
                {
                    if (command.Name.Equals(InventoryWindowViewModel.ItemsBoughtCommandName) || command.Name.Equals(InventoryWindowViewModel.ItemsSoldCommandName))
                    {
                        extraSpecialIdentifiers["itemtotal"]    = "5";
                        extraSpecialIdentifiers["itemname"]     = "Chocolate Bars";
                        extraSpecialIdentifiers["itemcost"]     = "500";
                        extraSpecialIdentifiers["currencyname"] = "CURRENCY_NAME";
                    }
                    else if (command.Name.Contains("Moderation Strike"))
                    {
                        extraSpecialIdentifiers[ModerationService.ModerationReasonSpecialIdentifier] = "Bad Stuff";
                    }
                    else if (command.Name.Equals(RedemptionStorePurchaseModel.ManualRedemptionNeededCommandName) || command.Name.Equals(RedemptionStorePurchaseModel.DefaultRedemptionCommandName))
                    {
                        extraSpecialIdentifiers[RedemptionStoreProductModel.ProductNameSpecialIdentifier] = "Test Product";
                    }
                    else
                    {
                        extraSpecialIdentifiers["queueposition"] = "1";
                    }
                }

                await command.PerformAndWait(currentUser, StreamingPlatformTypeEnum.None, new List <string>() { "@" + currentUser.Username }, extraSpecialIdentifiers);

                if (command is PermissionsCommandBase)
                {
                    PermissionsCommandBase permissionCommand = (PermissionsCommandBase)command;
                    permissionCommand.ResetCooldown(ChannelSession.GetCurrentUser());
                }
            }
        }
Beispiel #11
0
        private async void PlayButton_Click(object sender, RoutedEventArgs e)
        {
            this.PlayButton.Visibility = Visibility.Collapsed;
            this.StopButton.Visibility = Visibility.Visible;

            this.EditButton.IsEnabled   = false;
            this.DeleteButton.IsEnabled = false;
            this.EnableDisableToggleSwitch.IsEnabled = false;

            CommandBase command = this.GetCommandFromCommandButtons <CommandBase>(this);

            if (command != null)
            {
                UserViewModel currentUser = await ChannelSession.GetCurrentUser();

                Dictionary <string, string> extraSpecialIdentifiers = new Dictionary <string, string>();
                if (command is EventCommand)
                {
                    EventCommand eventCommand = command as EventCommand;
                    switch (eventCommand.EventType)
                    {
                    case Mixer.Base.Clients.ConstellationEventTypeEnum.channel__id__hosted:
                        extraSpecialIdentifiers["hostviewercount"] = "123";
                        break;

                    case Mixer.Base.Clients.ConstellationEventTypeEnum.channel__id__resubscribed:
                        extraSpecialIdentifiers["usersubmonths"] = "5";
                        break;

                    case Mixer.Base.Clients.ConstellationEventTypeEnum.progression__id__levelup:
                        extraSpecialIdentifiers["userfanprogressionnext"]  = "200";
                        extraSpecialIdentifiers["userfanprogressionrank"]  = "10";
                        extraSpecialIdentifiers["userfanprogressioncolor"] = "#c642ea";
                        extraSpecialIdentifiers["userfanprogressionimage"] = "https://static.mixer.com/img/design/ui/fan-progression/v1_badges/purple/large.gif";
                        extraSpecialIdentifiers["userfanprogression"]      = "100";
                        break;
                    }

                    switch (eventCommand.OtherEventType)
                    {
                    case OtherEventTypeEnum.GameWispSubscribed:
                    case OtherEventTypeEnum.GameWispResubscribed:
                        extraSpecialIdentifiers["subscribemonths"] = "999";
                        extraSpecialIdentifiers["subscribetier"]   = "Test Tier";
                        extraSpecialIdentifiers["subscribeamount"] = "$12.34";
                        break;

                    case OtherEventTypeEnum.StreamlabsDonation:
                    case OtherEventTypeEnum.GawkBoxDonation:
                    case OtherEventTypeEnum.TiltifyDonation:
                    case OtherEventTypeEnum.ExtraLifeDonation:
                    case OtherEventTypeEnum.TipeeeStreamDonation:
                    case OtherEventTypeEnum.TreatStreamDonation:
                    case OtherEventTypeEnum.StreamJarDonation:
                        UserDonationModel donation = new UserDonationModel()
                        {
                            Amount    = 12.34,
                            Message   = "Test donation message",
                            ImageLink = currentUser.AvatarLink
                        };

                        switch (eventCommand.OtherEventType)
                        {
                        case OtherEventTypeEnum.StreamlabsDonation: donation.Source = UserDonationSourceEnum.Streamlabs; break;

                        case OtherEventTypeEnum.GawkBoxDonation: donation.Source = UserDonationSourceEnum.GawkBox; break;

                        case OtherEventTypeEnum.TiltifyDonation: donation.Source = UserDonationSourceEnum.Tiltify; break;

                        case OtherEventTypeEnum.ExtraLifeDonation: donation.Source = UserDonationSourceEnum.ExtraLife; break;

                        case OtherEventTypeEnum.TipeeeStreamDonation: donation.Source = UserDonationSourceEnum.TipeeeStream; break;

                        case OtherEventTypeEnum.TreatStreamDonation: donation.Source = UserDonationSourceEnum.TreatStream; break;

                        case OtherEventTypeEnum.StreamJarDonation: donation.Source = UserDonationSourceEnum.StreamJar; break;
                        }

                        foreach (var kvp in donation.GetSpecialIdentifiers())
                        {
                            extraSpecialIdentifiers[kvp.Key] = kvp.Value;
                        }
                        extraSpecialIdentifiers["donationtype"] = "Pizza";
                        break;

                    case OtherEventTypeEnum.PatreonSubscribed:
                        extraSpecialIdentifiers[SpecialIdentifierStringBuilder.PatreonTierNameSpecialIdentifier]   = "Super Tier";
                        extraSpecialIdentifiers[SpecialIdentifierStringBuilder.PatreonTierAmountSpecialIdentifier] = "12.34";
                        extraSpecialIdentifiers[SpecialIdentifierStringBuilder.PatreonTierImageSpecialIdentifier]  = "https://xforgeassets002.xboxlive.com/xuid-2535473787585366-public/b7a1d715-3a9e-4bdd-a030-32f9e2e0f51e/0013_lots-o-stars_256.png";
                        break;

                    case OtherEventTypeEnum.StreamlootsCardRedeemed:
                        extraSpecialIdentifiers["streamlootscardname"]  = "Test Card";
                        extraSpecialIdentifiers["streamlootscardimage"] = "https://res.cloudinary.com/streamloots/image/upload/f_auto,c_scale,w_250,q_90/static/e19c7bf6-ca3e-49a8-807e-b2e9a1a47524/en_dl_character.png";
                        extraSpecialIdentifiers["streamlootscardvideo"] = "https://cdn.streamloots.com/uploads/5c645b78666f31002f2979d1/3a6bf1dc-7d61-4f93-be0a-f5dc1d0d33b6.webm";
                        extraSpecialIdentifiers["streamlootscardsound"] = "https://static.streamloots.com/b355d1ef-d931-4c16-a48f-8bed0076401b/alerts/default.mp3";
                        extraSpecialIdentifiers["streamlootsmessage"]   = "Test Message";
                        break;

                    case OtherEventTypeEnum.StreamlootsPackPurchased:
                    case OtherEventTypeEnum.StreamlootsPackGifted:
                        extraSpecialIdentifiers["streamlootspurchasequantity"] = "1";
                        break;

                    case OtherEventTypeEnum.TwitterStreamTweetRetweet:
                        break;

                    case OtherEventTypeEnum.MixerSkillUsed:
                        extraSpecialIdentifiers["skillname"]     = "Lots of stars";
                        extraSpecialIdentifiers["skilltype"]     = EnumHelper.GetEnumName(SkillTypeEnum.Sticker);
                        extraSpecialIdentifiers["skillcosttype"] = "Embers";
                        extraSpecialIdentifiers["skillcost"]     = "50";
                        extraSpecialIdentifiers["skillimage"]    = "https://xforgeassets002.xboxlive.com/xuid-2535473787585366-public/b7a1d715-3a9e-4bdd-a030-32f9e2e0f51e/0013_lots-o-stars_256.png";
                        extraSpecialIdentifiers["skillissparks"] = false.ToString();
                        extraSpecialIdentifiers["skillisembers"] = true.ToString();
                        extraSpecialIdentifiers["skillmessage"]  = "Hello World!";
                        break;

                    case OtherEventTypeEnum.MixerMilestoneReached:
                        extraSpecialIdentifiers["milestoneamount"]               = "100";
                        extraSpecialIdentifiers["milestoneremainingamount"]      = "100";
                        extraSpecialIdentifiers["milestonereward"]               = "$10.00";
                        extraSpecialIdentifiers["milestonenextamount"]           = "100";
                        extraSpecialIdentifiers["milestonenextremainingamount"]  = "100";
                        extraSpecialIdentifiers["milestonenextreward"]           = "$10.00";
                        extraSpecialIdentifiers["milestonefinalamount"]          = "100";
                        extraSpecialIdentifiers["milestonefinalremainingamount"] = "100";
                        extraSpecialIdentifiers["milestonefinalreward"]          = "$10.00";
                        extraSpecialIdentifiers["milestoneearnedamount"]         = "100";
                        extraSpecialIdentifiers["milestoneearnedreward"]         = "$10.00";
                        break;

                    case OtherEventTypeEnum.MixerSparksUsed:
                        extraSpecialIdentifiers["sparkamount"] = "10";
                        break;

                    case OtherEventTypeEnum.MixerEmbersUsed:
                        extraSpecialIdentifiers["emberamount"] = "10";
                        break;
                    }
                }
                else if (command is InteractiveCommand)
                {
                    InteractiveCommand iCommand = (InteractiveCommand)command;

                    extraSpecialIdentifiers["mixplaycontrolid"]   = iCommand.Name;
                    extraSpecialIdentifiers["mixplaycontrolcost"] = "123";
                    extraSpecialIdentifiers["mixplaycontroltext"] = "Button Name";
                }
                else if (command is CustomCommand)
                {
                    if (command.Name.Equals(InventoryWindow.ItemsBoughtCommandName) || command.Name.Equals(InventoryWindow.ItemsSoldCommandName))
                    {
                        extraSpecialIdentifiers["itemtotal"]    = "5";
                        extraSpecialIdentifiers["itemname"]     = "Chocolate Bars";
                        extraSpecialIdentifiers["itemcost"]     = "500";
                        extraSpecialIdentifiers["currencyname"] = "CURRENCY_NAME";
                    }
                    else if (command.Name.Contains("Moderation Strike"))
                    {
                        extraSpecialIdentifiers[ModerationHelper.ModerationReasonSpecialIdentifier] = "Bad Stuff";
                    }
                    else
                    {
                        extraSpecialIdentifiers["songtitle"]           = "Test Song";
                        extraSpecialIdentifiers["songalbumart"]        = SpotifySongRequestProviderService.SpotifyDefaultAlbumArt;
                        extraSpecialIdentifiers["songusername"]        = currentUser.UserName;
                        extraSpecialIdentifiers["spotifysongtitle"]    = "Test Song";
                        extraSpecialIdentifiers["spotifysongalbumart"] = SpotifySongRequestProviderService.SpotifyDefaultAlbumArt;
                        extraSpecialIdentifiers["queueposition"]       = "1";
                    }
                }

                await command.PerformAndWait(currentUser, new List <string>() { "@" + currentUser.UserName }, extraSpecialIdentifiers);

                if (command is PermissionsCommandBase)
                {
                    PermissionsCommandBase permissionCommand = (PermissionsCommandBase)command;
                    permissionCommand.ResetCooldown(await ChannelSession.GetCurrentUser());
                }
                this.SwitchToPlay();
            }

            this.RaiseEvent(new RoutedEventArgs(CommandButtonsControl.PlayClickedEvent, this));
        }