public override async Task UpdateExistingCommand(CommandModelBase command) { await base.UpdateExistingCommand(command); ChatCommandModel cCommand = (ChatCommandModel)command; cCommand.Triggers = this.GetChatTriggers(); cCommand.IncludeExclamation = this.IncludeExclamation; cCommand.Wildcards = this.Wildcards; }
private void CommandButtons_EditClicked(object sender, RoutedEventArgs e) { ChatCommandModel command = ((CommandListingButtonsControl)sender).GetCommandFromCommandButtons <ChatCommandModel>(); if (command != null) { CommandEditorWindow window = CommandEditorWindow.GetCommandEditorWindow(command); window.CommandSaved += Window_CommandSaved; window.ForceShow(); } }
private async void CommandButtons_DeleteClicked(object sender, RoutedEventArgs e) { await this.Window.RunAsyncOperation(async() => { ChatCommandModel command = ((CommandListingButtonsControl)sender).GetCommandFromCommandButtons <ChatCommandModel>(); if (command != null) { ChannelSession.Services.Command.ChatCommands.Remove(command); ChannelSession.Settings.RemoveCommand(command); ChannelSession.Services.Chat.RebuildCommandTriggers(); this.viewModel.RemoveCommand(command); await ChannelSession.SaveSettings(); } }); }
public IEnumerable <NewAutoChatCommandModel> GetNewAutoChatCommands() { List <NewAutoChatCommandModel> commandsToAdd = new List <NewAutoChatCommandModel>(); if (this.StreamPass != null) { ChatCommandModel statusCommand = new ChatCommandModel("User " + this.StreamPass.Name, new HashSet <string>() { this.StreamPass.SpecialIdentifier }); statusCommand.Requirements.AddBasicRequirements(); statusCommand.Requirements.Role.Role = UserRoleEnum.User; statusCommand.Requirements.Cooldown.Type = CooldownTypeEnum.Standard; statusCommand.Requirements.Cooldown.IndividualAmount = 5; statusCommand.Actions.Add(new ChatActionModel(string.Format("@$username is level ${0} with ${1} points!", this.StreamPass.UserLevelSpecialIdentifier, this.StreamPass.UserAmountSpecialIdentifier))); commandsToAdd.Add(new NewAutoChatCommandModel(string.Format("!{0} - {1}", statusCommand.Triggers.First(), "Shows User's Amount"), statusCommand)); ChatCommandModel addCommand = new ChatCommandModel("Add " + this.StreamPass.Name, new HashSet <string>() { "add" + this.StreamPass.SpecialIdentifier }); addCommand.Requirements.AddBasicRequirements(); addCommand.Requirements.Role.Role = UserRoleEnum.Mod; addCommand.Requirements.Cooldown.Type = CooldownTypeEnum.Standard; addCommand.Requirements.Cooldown.IndividualAmount = 5; addCommand.Actions.Add(new ConsumablesActionModel(this.StreamPass, ConsumablesActionTypeEnum.AddToSpecificUser, "$arg2text", username: "******")); addCommand.Actions.Add(new ChatActionModel(string.Format("@$targetusername received $arg2text points for {0}!", this.StreamPass.Name))); commandsToAdd.Add(new NewAutoChatCommandModel(string.Format("!{0} - {1}", addCommand.Triggers.First(), "Adds Amount To Specified User"), addCommand)); ChatCommandModel addAllCommand = new ChatCommandModel("Add All " + this.StreamPass.Name, new HashSet <string>() { "addall" + this.StreamPass.SpecialIdentifier }); addAllCommand.Requirements.AddBasicRequirements(); addAllCommand.Requirements.Role.Role = UserRoleEnum.Mod; addAllCommand.Requirements.Cooldown.Type = CooldownTypeEnum.Standard; addAllCommand.Requirements.Cooldown.IndividualAmount = 5; addAllCommand.Actions.Add(new ConsumablesActionModel(this.StreamPass, ConsumablesActionTypeEnum.AddToAllChatUsers, "$arg1text")); addAllCommand.Actions.Add(new ChatActionModel(string.Format("Everyone got $arg1text points for {0}!", this.StreamPass.Name))); commandsToAdd.Add(new NewAutoChatCommandModel(string.Format("!{0} - {1}", addAllCommand.Triggers.First(), "Adds Amount To All Chat Users"), addAllCommand)); } return(commandsToAdd); }
public ChatCommandEditorWindowViewModel(ChatCommandModel existingCommand) : base(existingCommand) { if (existingCommand.Triggers.Any(t => t.Contains(' '))) { this.Triggers = string.Join(";", existingCommand.Triggers); // If this is the only trigger, we need to add a semi-colon to the end if (existingCommand.Triggers.Count == 1) { this.Triggers += ";"; } } else { this.Triggers = string.Join(" ", existingCommand.Triggers); } this.Wildcards = existingCommand.Wildcards; this.IncludeExclamation = existingCommand.IncludeExclamation; }
public override Task <Result> Validate() { if (string.IsNullOrWhiteSpace(this.Name)) { return(Task.FromResult(new Result(MixItUp.Base.Resources.ACommandNameMustBeSpecified))); } if (string.IsNullOrWhiteSpace(this.Triggers)) { return(Task.FromResult(new Result(MixItUp.Base.Resources.ChatCommandMissingTriggers))); } if (!ChatCommandModel.IsValidCommandTrigger(this.Triggers)) { return(Task.FromResult(new Result(MixItUp.Base.Resources.ChatCommandInvalidTriggers))); } HashSet <string> triggers = this.GetChatTriggers(); if (this.IncludeExclamation) { triggers = new HashSet <string>(triggers.Select(t => "!" + t)); } foreach (ChatCommandModel command in ChannelSession.Services.Command.AllEnabledChatAccessibleCommands) { if (this.existingCommand != command) { foreach (string trigger in command.GetFullTriggers()) { if (triggers.Contains(trigger)) { return(Task.FromResult(new Result(string.Format(MixItUp.Base.Resources.ChatCommandTriggerAlreadyExists, trigger)))); } } } } return(Task.FromResult(new Result())); }
public Task End() { this.backgroundThreadCancellationTokenSource.Cancel(); if (this.Winner != null) { pastWinners.Add(this.Winner.ID); } this.TimeLeft = 0; this.giveawayCommand = null; this.enteredUsers.Clear(); this.IsRunning = false; GlobalEvents.GiveawaysChangedOccurred(usersUpdated: true); GlobalEvents.OnChatMessageReceived -= GlobalEvents_OnChatCommandMessageReceived; return(Task.FromResult(0)); }
private async void ContextMenuChatCommand_Click(object sender, RoutedEventArgs e) { if (this.AlertsListView.SelectedItem != null && this.AlertsListView.SelectedItem is ChatMessageViewModel) { ChatMessageViewModel message = (ChatMessageViewModel)this.AlertsListView.SelectedItem; if (message.User != null) { if (e.Source is MenuItem) { MenuItem menuItem = (MenuItem)e.Source; if (menuItem.DataContext != null && menuItem.DataContext is ChatCommandModel) { ChatCommandModel command = (ChatCommandModel)menuItem.DataContext; await command.Perform(new CommandParametersModel(platform : message.Platform, arguments : new List <string>() { message.User.Username }) { TargetUser = message.User }); } } } } }
public async Task <string> Start(string item) { if (this.IsRunning) { return("A giveaway is already underway"); } if (string.IsNullOrEmpty(item)) { return("The name of the giveaway item must be specified"); } this.Item = item; if (ChannelSession.Settings.GiveawayTimer <= 0) { return("The giveaway length must be greater than 0"); } if (ChannelSession.Settings.GiveawayReminderInterval < 0) { return("The giveaway reminder must be 0 or greater"); } if (ChannelSession.Settings.GiveawayMaximumEntries <= 0) { return("The maximum entries must be greater than 0"); } if (string.IsNullOrEmpty(ChannelSession.Settings.GiveawayCommand)) { return("Giveaway command must be specified"); } if (ChannelSession.Settings.GiveawayCommand.Any(c => !Char.IsLetterOrDigit(c))) { return("Giveaway Command can only contain letters and numbers"); } await ChannelSession.SaveSettings(); this.IsRunning = true; this.Winner = null; this.giveawayCommand = new ChatCommandModel("Giveaway Command", new HashSet <string>() { ChannelSession.Settings.GiveawayCommand }); if (ChannelSession.Settings.GiveawayAllowPastWinners) { this.pastWinners.Clear(); } this.TimeLeft = ChannelSession.Settings.GiveawayTimer * 60; this.enteredUsers.Clear(); this.previousEnteredUsers.Clear(); GlobalEvents.GiveawaysChangedOccurred(usersUpdated: true); this.backgroundThreadCancellationTokenSource = new CancellationTokenSource(); this.backgroundThreadReRollCancellationTokenSource = new CancellationTokenSource(); #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed Task.Run(async() => { await this.GiveawayTimerBackground(); }, this.backgroundThreadCancellationTokenSource.Token); #pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed await ChannelSession.Settings.GetCommand(ChannelSession.Settings.GiveawayStartedReminderCommandID).Perform(new CommandParametersModel(this.GetSpecialIdentifiers())); return(null); }
public async Task AddMessage(ChatMessageViewModel message) { try { message.ProcessingStartTime = DateTimeOffset.Now; Logger.Log(LogLevel.Debug, string.Format("Message Received - {0} - {1} - {2}", message.ID.ToString(), message.ProcessingStartTime, message)); // Pre message processing if (message is UserChatMessageViewModel) { if (message.User != null) { if (message.Platform == StreamingPlatformTypeEnum.Twitch) { UserViewModel activeUser = ChannelSession.Services.User.GetUserByTwitchID(message.User.TwitchID); if (activeUser != null) { message.User = activeUser; } } message.User.UpdateLastActivity(); if (message.IsWhisper && ChannelSession.Settings.TrackWhispererNumber && !message.IsStreamerOrBot && message.User.WhispererNumber == 0) { 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)); }); } } } // Add message to chat list bool showMessage = true; if (ChannelSession.Settings.HideBotMessages && message.User != null && ChannelSession.TwitchBotNewAPI != null && message.User.TwitchID.Equals(ChannelSession.TwitchBotNewAPI.id)) { showMessage = false; } if (!(message is AlertChatMessageViewModel) || !ChannelSession.Settings.OnlyShowAlertsInDashboard) { this.messagesLookup[message.ID] = message; if (showMessage) { if (ChannelSession.Settings.LatestChatAtTop) { this.Messages.Insert(0, message); } else { this.Messages.Add(message); } } if (this.Messages.Count > ChannelSession.Settings.MaxMessagesInChat) { ChatMessageViewModel removedMessage = (ChannelSession.Settings.LatestChatAtTop) ? this.Messages.Last() : this.Messages.First(); this.messagesLookup.Remove(removedMessage.ID); this.Messages.Remove(removedMessage); } } // Post message processing if (message is UserChatMessageViewModel && message.User != null) { if (message.IsWhisper && !message.IsStreamerOrBot) { if (!string.IsNullOrEmpty(ChannelSession.Settings.NotificationChatWhisperSoundFilePath)) { await ChannelSession.Services.AudioService.Play(ChannelSession.Settings.NotificationChatWhisperSoundFilePath, ChannelSession.Settings.NotificationChatWhisperSoundVolume, ChannelSession.Settings.NotificationsAudioOutput); } if (!string.IsNullOrEmpty(message.PlainTextMessage)) { EventTrigger trigger = new EventTrigger(EventTypeEnum.ChatWhisperReceived, message.User); trigger.SpecialIdentifiers["message"] = message.PlainTextMessage; await ChannelSession.Services.Events.PerformEvent(trigger); } // Don't send this if it's in response to another "You are whisperer #" message if (ChannelSession.Settings.TrackWhispererNumber && message.User.WhispererNumber > 0 && !message.PlainTextMessage.StartsWith("You are whisperer #", StringComparison.InvariantCultureIgnoreCase)) { await ChannelSession.Services.Chat.Whisper(message.User, $"You are whisperer #{message.User.WhispererNumber}.", sendAsStreamer : false); } } else { if (this.DisableChat) { Logger.Log(LogLevel.Debug, string.Format("Deleting Message As Chat Disabled - {0} - {1}", message.ID, message)); await this.DeleteMessage(message); return; } if (!string.IsNullOrEmpty(ChannelSession.Settings.NotificationChatTaggedSoundFilePath) && message.IsStreamerTagged) { await ChannelSession.Services.AudioService.Play(ChannelSession.Settings.NotificationChatTaggedSoundFilePath, ChannelSession.Settings.NotificationChatTaggedSoundVolume, ChannelSession.Settings.NotificationsAudioOutput); } else if (!string.IsNullOrEmpty(ChannelSession.Settings.NotificationChatMessageSoundFilePath)) { await ChannelSession.Services.AudioService.Play(ChannelSession.Settings.NotificationChatMessageSoundFilePath, ChannelSession.Settings.NotificationChatMessageSoundVolume, ChannelSession.Settings.NotificationsAudioOutput); } if (message.User != null && !this.userEntranceCommands.Contains(message.User.ID)) { this.userEntranceCommands.Add(message.User.ID); if (ChannelSession.Settings.GetCommand(message.User.Data.EntranceCommandID) != null) { await ChannelSession.Settings.GetCommand(message.User.Data.EntranceCommandID).Perform(new CommandParametersModel(message.User, message.Platform, message.ToArguments())); } } if (!string.IsNullOrEmpty(message.PlainTextMessage)) { EventTrigger trigger = new EventTrigger(EventTypeEnum.ChatMessageReceived, message.User); trigger.SpecialIdentifiers["message"] = message.PlainTextMessage; await ChannelSession.Services.Events.PerformEvent(trigger); } message.User.Data.TotalChatMessageSent++; string primaryTaggedUsername = message.PrimaryTaggedUsername; if (!string.IsNullOrEmpty(primaryTaggedUsername)) { UserViewModel primaryTaggedUser = ChannelSession.Services.User.GetUserByUsername(primaryTaggedUsername, message.Platform); if (primaryTaggedUser != null) { primaryTaggedUser.Data.TotalTimesTagged++; } } } await message.User.RefreshDetails(); if (!message.IsWhisper && await message.CheckForModeration()) { await this.DeleteMessage(message); return; } IEnumerable <string> arguments = null; if (!string.IsNullOrEmpty(message.PlainTextMessage) && message.User != null && !message.User.UserRoles.Contains(UserRoleEnum.Banned)) { if (!ChannelSession.Settings.AllowCommandWhispering && message.IsWhisper) { return; } if (ChannelSession.Settings.IgnoreBotAccountCommands) { if (ChannelSession.TwitchBotNewAPI != null && message.User.TwitchID.Equals(ChannelSession.TwitchBotNewAPI.id)) { return; } } Logger.Log(LogLevel.Debug, string.Format("Checking Message For Command - {0} - {1}", message.ID, message)); bool commandTriggered = false; if (message.User.Data.CustomCommandIDs.Count > 0) { Dictionary <string, CommandModelBase> userOnlyTriggersToCommands = new Dictionary <string, CommandModelBase>(); List <ChatCommandModel> userOnlyWildcardCommands = new List <ChatCommandModel>(); foreach (Guid commandID in message.User.Data.CustomCommandIDs) { ChatCommandModel command = (ChatCommandModel)ChannelSession.Settings.GetCommand(commandID); if (command != null && command.IsEnabled) { if (command.Wildcards) { userOnlyWildcardCommands.Add(command); } else { foreach (string trigger in command.GetFullTriggers()) { userOnlyTriggersToCommands[trigger.ToLower()] = command; } } } } if (!commandTriggered && userOnlyWildcardCommands.Count > 0) { foreach (ChatCommandModel command in userOnlyWildcardCommands) { if (command.DoesMessageMatchWildcardTriggers(message, out arguments)) { await this.RunChatCommand(message, command, arguments); commandTriggered = true; break; } } } if (!commandTriggered && userOnlyTriggersToCommands.Count > 0) { commandTriggered = await this.CheckForChatCommandAndRun(message, userOnlyTriggersToCommands); } } if (!commandTriggered) { foreach (ChatCommandModel command in this.wildcardCommands) { if (command.DoesMessageMatchWildcardTriggers(message, out arguments)) { await this.RunChatCommand(message, command, arguments); commandTriggered = true; break; } } } if (!commandTriggered) { commandTriggered = await this.CheckForChatCommandAndRun(message, this.triggersToCommands); } } foreach (InventoryModel inventory in ChannelSession.Settings.Inventory.Values.ToList()) { if (inventory.ShopEnabled && ChatCommandModel.DoesMessageMatchTriggers(message, new List <string>() { inventory.ShopCommand }, out arguments)) { await inventory.PerformShopCommand(message.User, arguments, message.Platform); } else if (inventory.TradeEnabled && ChatCommandModel.DoesMessageMatchTriggers(message, new List <string>() { inventory.TradeCommand }, out arguments)) { await inventory.PerformTradeCommand(message.User, arguments, message.Platform); } } if (ChannelSession.Settings.RedemptionStoreEnabled) { if (ChatCommandModel.DoesMessageMatchTriggers(message, new List <string>() { ChannelSession.Settings.RedemptionStoreChatPurchaseCommand }, out arguments)) { await RedemptionStorePurchaseModel.Purchase(message.User, arguments); } else if (ChatCommandModel.DoesMessageMatchTriggers(message, new List <string>() { ChannelSession.Settings.RedemptionStoreModRedeemCommand }, out arguments)) { await RedemptionStorePurchaseModel.Redeem(message.User, arguments); } } GlobalEvents.ChatMessageReceived(message); await this.WriteToChatEventLog(message); } Logger.Log(LogLevel.Debug, string.Format("Message Processing Complete: {0} - {1} ms", message.ID, message.ProcessingTime)); if (message.ProcessingTime > 500) { Logger.Log(LogLevel.Error, string.Format("Long processing time detected for the following message: {0} - {1} ms - {2}", message.ID.ToString(), message.ProcessingTime, message)); } } catch (Exception ex) { Logger.Log(ex); } }
public IEnumerable <NewAutoChatCommandModel> GetNewAutoChatCommands() { List <NewAutoChatCommandModel> commandsToAdd = new List <NewAutoChatCommandModel>(); if (this.Currency != null) { ChatCommandModel statusCommand = new ChatCommandModel("User " + this.Currency.Name, new HashSet <string>() { this.Currency.SpecialIdentifier }); statusCommand.Requirements.AddBasicRequirements(); statusCommand.Requirements.Role.Role = UserRoleEnum.User; statusCommand.Requirements.Cooldown.Type = CooldownTypeEnum.Standard; statusCommand.Requirements.Cooldown.IndividualAmount = 5; string statusChatText = string.Empty; if (this.Currency.IsRank) { statusChatText = string.Format("@$username is a ${0} with ${1} {2}!", this.Currency.UserRankNameSpecialIdentifier, this.Currency.UserAmountSpecialIdentifier, this.Currency.Name); } else { statusChatText = string.Format("@$username has ${0} {1}!", this.Currency.UserAmountSpecialIdentifier, this.Currency.Name); } statusCommand.Actions.Add(new ChatActionModel(statusChatText)); commandsToAdd.Add(new NewAutoChatCommandModel(string.Format("!{0} - {1}", statusCommand.Triggers.First(), "Shows User's Amount"), statusCommand)); if (this.Currency.SpecialTracking == CurrencySpecialTrackingEnum.None) { ChatCommandModel addCommand = new ChatCommandModel("Add " + this.Currency.Name, new HashSet <string>() { "add" + this.Currency.SpecialIdentifier }); addCommand.Requirements.AddBasicRequirements(); addCommand.Requirements.Role.Role = UserRoleEnum.Mod; addCommand.Requirements.Cooldown.Type = CooldownTypeEnum.Standard; addCommand.Requirements.Cooldown.IndividualAmount = 5; addCommand.Actions.Add(new ConsumablesActionModel(this.Currency, ConsumablesActionTypeEnum.AddToSpecificUser, "$arg2text", username: "******")); addCommand.Actions.Add(new ChatActionModel(string.Format("@$targetusername received $arg2text {0}!", this.Currency.Name))); commandsToAdd.Add(new NewAutoChatCommandModel(string.Format("!{0} - {1}", addCommand.Triggers.First(), "Adds Amount To Specified User"), addCommand)); ChatCommandModel addAllCommand = new ChatCommandModel("Add All " + this.Currency.Name, new HashSet <string>() { "addall" + this.Currency.SpecialIdentifier }); addAllCommand.Requirements.AddBasicRequirements(); addAllCommand.Requirements.Role.Role = UserRoleEnum.Mod; addAllCommand.Requirements.Cooldown.Type = CooldownTypeEnum.Standard; addAllCommand.Requirements.Cooldown.IndividualAmount = 5; addAllCommand.Actions.Add(new ConsumablesActionModel(this.Currency, ConsumablesActionTypeEnum.AddToAllChatUsers, "$arg1text")); addAllCommand.Actions.Add(new ChatActionModel(string.Format("Everyone got $arg1text {0}!", this.Currency.Name))); commandsToAdd.Add(new NewAutoChatCommandModel(string.Format("!{0} - {1}", addAllCommand.Triggers.First(), "Adds Amount To All Chat Users"), addAllCommand)); if (!this.Currency.IsRank) { ChatCommandModel giveCommand = new ChatCommandModel("Give " + this.Currency.Name, new HashSet <string>() { "give" + this.Currency.SpecialIdentifier }); giveCommand.Requirements.AddBasicRequirements(); giveCommand.Requirements.Role.Role = UserRoleEnum.User; giveCommand.Requirements.Cooldown.Type = CooldownTypeEnum.Standard; giveCommand.Requirements.Cooldown.IndividualAmount = 5; giveCommand.Actions.Add(new ConsumablesActionModel(this.Currency, ConsumablesActionTypeEnum.AddToSpecificUser, "$arg2text", username: "******", deductFromUser: true)); giveCommand.Actions.Add(new ChatActionModel(string.Format("@$username gave @$targetusername $arg2text {0}!", this.Currency.Name))); commandsToAdd.Add(new NewAutoChatCommandModel(string.Format("!{0} - {1}", giveCommand.Triggers.First(), "Gives Amount To Specified User"), giveCommand)); } } } return(commandsToAdd); }