protected override async Task PerformInternal(CommandParametersModel parameters) { if (parameters.Arguments.Count == 1 && parameters.Arguments[0].Length == this.CombinationLength) { if (int.TryParse(parameters.Arguments[0], out int guess) && guess > 0) { this.TotalAmount += this.GetPrimaryBetAmount(parameters); this.AddSpecialIdentifiersToParameters(parameters); if (guess == this.CurrentCombination) { parameters.SpecialIdentifiers[GameCommandModelBase.GamePayoutSpecialIdentifier] = this.TotalAmount.ToString(); this.PerformPrimarySetPayout(parameters.User, this.TotalAmount); this.ClearData(); await this.SuccessfulCommand.Perform(parameters); } else { parameters.SpecialIdentifiers[LockBoxGameCommandModel.GameHitmanHintSpecialIdentifier] = (guess < this.CurrentCombination) ? MixItUp.Base.Resources.GameCommandLockBoxLow : MixItUp.Base.Resources.GameCommandLockBoxHigh; await this.FailureCommand.Perform(parameters); } await this.PerformCooldown(parameters); return; } else { await ChannelSession.Services.Chat.SendMessage(MixItUp.Base.Resources.GameCommandLockBoxNotNumber); } } else { await ChannelSession.Services.Chat.SendMessage(string.Format(MixItUp.Base.Resources.GameCommandLockBoxIncorrectLength, this.CombinationLength)); } await this.Requirements.Refund(parameters); }
protected override async Task PerformInternal(CommandParametersModel parameters) { await this.SetSelectedUser(this.PlayerSelectionType, parameters); if (parameters.TargetUser != null) { if (await this.ValidateTargetUserPrimaryBetAmount(parameters)) { this.runParameters = parameters; this.runCancellationTokenSource = new CancellationTokenSource(); #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed AsyncRunner.RunAsyncBackground(async(cancellationToken) => { await DelayNoThrow(this.TimeLimit * 1000, cancellationToken); if (this.gameActive && cancellationToken != null && !cancellationToken.IsCancellationRequested) { this.gameActive = false; await this.NotAcceptedCommand.Perform(parameters); await this.Requirements.Refund(parameters); await this.PerformCooldown(parameters); } this.ClearData(); }, this.runCancellationTokenSource.Token); #pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed this.gameActive = true; await this.StartedCommand.Perform(parameters); return; } } else { await ChannelSession.Services.Chat.SendMessage(MixItUp.Base.Resources.GameCommandCouldNotFindUser); } }
protected override async Task PerformInternal(CommandParametersModel parameters) { if (ChannelSession.Services.Twitter.IsConnected) { if (this.ActionType == TwitterActionTypeEnum.SendTweet) { string tweet = await this.ReplaceStringWithSpecialModifiers(this.TweetText, parameters); string imagePath = await this.ReplaceStringWithSpecialModifiers(this.ImagePath, parameters); if (!string.IsNullOrEmpty(tweet)) { if (TwitterActionModel.CheckIfTweetContainsTooManyTags(tweet)) { await ChannelSession.Services.Chat.SendMessage("The tweet you specified can not be sent because it contains an @mention"); return; } Result result = await ChannelSession.Services.Twitter.SendTweet(tweet, imagePath); if (!result.Success) { await ChannelSession.Services.Chat.SendMessage("Twitter Error: " + result.Message); } } } else if (this.ActionType == TwitterActionTypeEnum.UpdateName) { Result result = await ChannelSession.Services.Twitter.UpdateName(this.NameUpdate); if (!result.Success) { await ChannelSession.Services.Chat.SendMessage("Twitter Error: " + result.Message); } } } }
private Result CreateErrorMessage(CommandParametersModel parameters) { string role = EnumLocalizationHelper.GetLocalizedName(this.Role); if (this.Role == UserRoleEnum.Subscriber) { string tierText = string.Empty; switch (this.SubscriberTier) { case 1: tierText = MixItUp.Base.Resources.Tier1; break; case 2: tierText = MixItUp.Base.Resources.Tier2; break; case 3: tierText = MixItUp.Base.Resources.Tier3; break; } role = tierText + " " + role; } else if (this.Role == UserRoleEnum.VIPExclusive) { role = EnumLocalizationHelper.GetLocalizedName(UserRoleEnum.VIP); } return(new Result(string.Format(MixItUp.Base.Resources.RoleErrorInsufficientRole, role))); }
protected override async Task PerformInternal(CommandParametersModel parameters) { if (ChannelSession.Services.Streamlabs.IsConnected) { switch (this.ActionType) { case StreamlabsActionTypeEnum.SpinWheel: await ChannelSession.Services.Streamlabs.SpinWheel(); break; case StreamlabsActionTypeEnum.EmptyJar: await ChannelSession.Services.Streamlabs.EmptyJar(); break; case StreamlabsActionTypeEnum.RollCredits: await ChannelSession.Services.Streamlabs.RollCredits(); break; } } }
protected override async Task PerformInternal(CommandParametersModel parameters) { int betAmount = this.GetPrimaryBetAmount(parameters); this.TotalAmount += betAmount; if (this.TotalAmount >= this.MinimumAmountForPayout && this.GenerateProbability() <= this.ProbabilityPercentage) { int payout = this.GenerateRandomNumber(this.TotalAmount, this.PayoutMinimumPercentage / 100.0d, this.PayoutMaximumPercentage / 100.0d); this.PerformPrimarySetPayout(parameters.User, payout); this.TotalAmount -= payout; parameters.SpecialIdentifiers[GameCommandModelBase.GameTotalAmountSpecialIdentifier] = this.TotalAmount.ToString(); parameters.SpecialIdentifiers[GameCommandModelBase.GamePayoutSpecialIdentifier] = payout.ToString(); await this.SuccessCommand.Perform(parameters); } else { parameters.SpecialIdentifiers[GameCommandModelBase.GameTotalAmountSpecialIdentifier] = this.TotalAmount.ToString(); await this.FailureCommand.Perform(parameters); } await this.PerformCooldown(parameters); }
private async Task BackgroundDonationCheck(CancellationToken token) { IEnumerable <PatreonCampaignMember> pledges = await this.GetCampaignMembers(); if (pledges != null && pledges.Count() > 0) { this.members = pledges.ToList(); foreach (PatreonCampaignMember member in this.members) { if (!this.currentMembersAndTiers.ContainsKey(member.UserID) || !this.currentMembersAndTiers[member.UserID].Equals(member.TierID)) { PatreonTier tier = this.Campaign.GetTier(member.TierID); if (tier != null) { CommandParametersModel parameters = new CommandParametersModel(); parameters.User = await ChannelSession.Services.User.GetUserFullSearch(member.User.Platform, member.User.PlatformUserID, member.User.PlatformUsername); if (parameters.User != null) { parameters.User.Data.PatreonUserID = member.UserID; } else { parameters.User = UserViewModel.Create(member.User.PlatformUsername); } parameters.SpecialIdentifiers[SpecialIdentifierStringBuilder.PatreonTierNameSpecialIdentifier] = tier.Title; parameters.SpecialIdentifiers[SpecialIdentifierStringBuilder.PatreonTierAmountSpecialIdentifier] = tier.Amount.ToString(); parameters.SpecialIdentifiers[SpecialIdentifierStringBuilder.PatreonTierImageSpecialIdentifier] = tier.ImageUrl; await ChannelSession.Services.Events.PerformEvent(EventTypeEnum.PatreonSubscribed, parameters); } } this.currentMembersAndTiers[member.UserID] = member.TierID; } } }
public static async Task ProcessDonationEvent(EventTypeEnum type, UserDonationModel donation, List <string> arguments = null, Dictionary <string, string> additionalSpecialIdentifiers = null) { CommandParametersModel parameters = new CommandParametersModel(donation.User, donation.Platform, arguments, donation.GetSpecialIdentifiers()); if (additionalSpecialIdentifiers != null) { foreach (var kvp in additionalSpecialIdentifiers) { parameters.SpecialIdentifiers[kvp.Key] = kvp.Value; } } foreach (StreamPassModel streamPass in ChannelSession.Settings.StreamPass.Values) { if (parameters.User.HasPermissionsTo(streamPass.Permission)) { streamPass.AddAmount(donation.User.Data, (int)Math.Ceiling(streamPass.DonationBonus * donation.Amount)); } } parameters.User.Data.TotalAmountDonated += donation.Amount; ChannelSession.Settings.LatestSpecialIdentifiersData[SpecialIdentifierStringBuilder.LatestDonationUserData] = parameters.User.ID; ChannelSession.Settings.LatestSpecialIdentifiersData[SpecialIdentifierStringBuilder.LatestDonationAmountData] = donation.AmountText; await ChannelSession.Services.Alerts.AddAlert(new AlertChatMessageViewModel(StreamingPlatformTypeEnum.All, parameters.User, string.Format("{0} Donated {1}", parameters.User.FullDisplayName, donation.AmountText), ChannelSession.Settings.AlertDonationColor)); await ChannelSession.Services.Events.PerformEvent(type, parameters); try { GlobalEvents.DonationOccurred(donation); } catch (Exception ex) { Logger.Log(ex); } }
public async Task UpdateItem(OverlayItemModelBase item, CommandParametersModel parameters) { if (item != null) { try { JObject jobj = await item.GetProcessedItem(parameters); if (jobj != null) { if (item is OverlayImageItemModel || item is OverlayVideoItemModel || item is OverlaySoundItemModel) { this.SetLocalFile(jobj["FileID"].ToString(), jobj["FilePath"].ToString()); jobj["FullLink"] = OverlayItemModelBase.GetFileFullLink(jobj["FileID"].ToString(), jobj["FileType"].ToString(), jobj["FilePath"].ToString()); } await this.SendPacket("Update", jobj); } } catch (Exception ex) { Logger.Log(ex); } } }
protected UserViewModel GetRandomUser(CommandParametersModel parameters) { CurrencyRequirementModel currencyRequirement = this.GetPrimaryCurrencyRequirement(); int betAmount = this.GetPrimaryBetAmount(parameters); if (currencyRequirement != null && betAmount > 0) { string currencyName = currencyRequirement.Currency?.Name; List <UserViewModel> users = new List <UserViewModel>(ChannelSession.Services.User.GetAllWorkableUsers(parameters.Platform).Shuffle()); users.Remove(parameters.User); foreach (UserViewModel user in users) { if (!user.Data.IsCurrencyRankExempt && currencyRequirement.Currency.HasAmount(user.Data, betAmount)) { return(user); } } return(null); } else { return(ChannelSession.Services.User.GetRandomUser(parameters, excludeCurrencyRankExempt: true)); } }
protected override async Task PerformInternal(CommandParametersModel parameters) { if (this.ActionType == DiscordActionTypeEnum.SendMessage) { if (this.channel == null) { this.channel = await ChannelSession.Services.Discord.GetChannel(this.ChannelID); } if (this.channel != null) { string message = await this.ReplaceStringWithSpecialModifiers(this.MessageText, parameters); await ChannelSession.Services.Discord.CreateMessage(this.channel, message, this.FilePath); } } else if (this.ActionType == DiscordActionTypeEnum.MuteSelf) { await ChannelSession.Services.Discord.MuteServerMember(ChannelSession.Services.Discord.Server, ChannelSession.Services.Discord.User, this.ShouldMuteDeafen); } else if (this.ActionType == DiscordActionTypeEnum.DeafenSelf) { await ChannelSession.Services.Discord.DeafenServerMember(ChannelSession.Services.Discord.Server, ChannelSession.Services.Discord.User, this.ShouldMuteDeafen); } }
protected override async Task PerformInternal(CommandParametersModel parameters) { if (ChannelSession.Services.FileService.FileExists(this.Url)) { await this.ProcessContents(parameters, await ChannelSession.Services.FileService.ReadFile(this.Url)); } else { using (AdvancedHttpClient httpClient = new AdvancedHttpClient()) { httpClient.DefaultRequestHeaders.Add("User-Agent", $"MixItUp/{Assembly.GetEntryAssembly().GetName().Version.ToString()} (Web call from Mix It Up; https://mixitupapp.com; [email protected])"); httpClient.DefaultRequestHeaders.Add("Twitch-UserID", (ChannelSession.TwitchUserNewAPI != null) ? ChannelSession.TwitchUserNewAPI.id : string.Empty); httpClient.DefaultRequestHeaders.Add("Twitch-UserLogin", (ChannelSession.TwitchUserNewAPI != null) ? ChannelSession.TwitchUserNewAPI.login : string.Empty); using (HttpResponseMessage response = await httpClient.GetAsync(await ReplaceStringWithSpecialModifiers(this.Url, parameters, encode: true))) { if (response.IsSuccessStatusCode) { await this.ProcessContents(parameters, await response.Content.ReadAsStringAsync()); } } } } }
protected override async Task PerformInternal(CommandParametersModel parameters) { if (this.ActionType == ModerationActionTypeEnum.ClearChat) { await ChannelSession.Services.Chat.ClearMessages(); } else { UserViewModel targetUser = null; if (!string.IsNullOrEmpty(this.TargetUsername)) { string username = await ReplaceStringWithSpecialModifiers(this.TargetUsername, parameters); targetUser = ChannelSession.Services.User.GetActiveUserByUsername(username, parameters.Platform); } else { targetUser = parameters.User; } if (targetUser != null) { if (this.ActionType == ModerationActionTypeEnum.PurgeUser) { await ChannelSession.Services.Chat.PurgeUser(targetUser); } else if (this.ActionType == ModerationActionTypeEnum.BanUser) { await ChannelSession.Services.Chat.BanUser(targetUser); } else if (this.ActionType == ModerationActionTypeEnum.UnbanUser) { await ChannelSession.Services.Chat.UnbanUser(targetUser); } else if (this.ActionType == ModerationActionTypeEnum.ModUser) { await ChannelSession.Services.Chat.ModUser(targetUser); } else if (this.ActionType == ModerationActionTypeEnum.UnmodUser) { await ChannelSession.Services.Chat.UnmodUser(targetUser); } else if (this.ActionType == ModerationActionTypeEnum.AddModerationStrike) { string moderationReason = "Manual Moderation Strike"; if (!string.IsNullOrEmpty(this.ModerationReason)) { moderationReason = await ReplaceStringWithSpecialModifiers(this.ModerationReason, parameters); } await targetUser.AddModerationStrike(moderationReason); } else if (this.ActionType == ModerationActionTypeEnum.RemoveModerationStrike) { await targetUser.RemoveModerationStrike(); } else if (this.ActionType == ModerationActionTypeEnum.TimeoutUser) { if (!string.IsNullOrEmpty(this.TimeoutAmount)) { string timeAmountString = await ReplaceStringWithSpecialModifiers(this.TimeoutAmount, parameters); if (uint.TryParse(timeAmountString, out uint timeAmount)) { await ChannelSession.Services.Chat.TimeoutUser(targetUser, timeAmount); } } } } } }
private void AddSpecialIdentifiersToParameters(CommandParametersModel parameters) { parameters.SpecialIdentifiers[GameCommandModelBase.GameTotalAmountSpecialIdentifier] = this.TotalAmount.ToString(); }
public async Task Queue(Guid commandID, CommandParametersModel parameters) { await this.Queue(ChannelSession.Settings.GetCommand(commandID), parameters); }
public static async Task ProcessJSONToSpecialIdentifiers(string body, Dictionary <string, string> jsonToSpecialIdentifiers, CommandParametersModel parameters) { JToken jToken = JToken.Parse(body); foreach (var kvp in jsonToSpecialIdentifiers) { string key = await ReplaceStringWithSpecialModifiers(kvp.Key, parameters); string[] splits = key.Split(new char[] { '/', '\\' }, StringSplitOptions.RemoveEmptyEntries); if (splits.Count() > 0) { JToken currentToken = jToken; for (int i = 0; i < splits.Count(); i++) { if (currentToken is JObject) { JObject jobjToken = (JObject)currentToken; if (jobjToken.ContainsKey(splits[i])) { currentToken = jobjToken[splits[i]]; } else { currentToken = null; break; } } else if (currentToken is JArray) { JArray jarrayToken = (JArray)currentToken; if (int.TryParse(splits[i], out int index) && index >= 0 && index < jarrayToken.Count) { currentToken = jarrayToken[index]; } else { currentToken = null; break; } } else { currentToken = null; break; } } if (currentToken != null) { parameters.SpecialIdentifiers[kvp.Value] = await ReplaceStringWithSpecialModifiers(HttpUtility.HtmlDecode(currentToken.ToString()), parameters); } } } }
public override async Task CustomRun(CommandParametersModel parameters) { await this.RefundCooldown(parameters); if (string.IsNullOrEmpty(this.runWord)) { this.runWord = await this.GetRandomWord(this.CustomWordsFilePath); this.runBetAmount = this.GetPrimaryBetAmount(parameters); this.runParameters = parameters; this.runUsers[parameters.User] = parameters; this.GetPrimaryCurrencyRequirement()?.SetTemporaryAmount(this.runBetAmount); this.runCancellationTokenSource = new CancellationTokenSource(); #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed AsyncRunner.RunAsyncBackground(async(cancellationToken) => { await DelayNoThrow(this.TimeLimit * 1000, cancellationToken); if (cancellationToken != null && cancellationToken.IsCancellationRequested) { return; } this.runParameters.SpecialIdentifiers[WordScrambleGameCommandModel.GameWordScrambleAnswerSpecialIdentifier] = this.runWord; this.runParameters.SpecialIdentifiers[WordScrambleGameCommandModel.GameWordScrambleWordSpecialIdentifier] = this.runWordScrambled = this.runWord.Shuffle(); if (this.runUsers.Count < this.MinimumParticipants) { await this.RunSubCommand(this.NotEnoughPlayersCommand, this.runParameters); foreach (var kvp in this.runUsers.ToList()) { await this.Requirements.Refund(kvp.Value); } await this.PerformCooldown(this.runParameters); this.ClearData(); return; } await this.RunSubCommand(this.WordScramblePrepareCommand, this.runParameters); await DelayNoThrow(5000, cancellationToken); if (cancellationToken != null && cancellationToken.IsCancellationRequested) { return; } GlobalEvents.OnChatMessageReceived += GlobalEvents_OnChatMessageReceived; await this.RunSubCommand(this.WordScrambleBeginCommand, this.runParameters); await DelayNoThrow(this.WordScrambleTimeLimit * 1000, cancellationToken); if (cancellationToken != null && cancellationToken.IsCancellationRequested) { return; } GlobalEvents.OnChatMessageReceived -= GlobalEvents_OnChatMessageReceived; if (!string.IsNullOrEmpty(this.runWord)) { await this.RunSubCommand(this.UserFailureCommand, this.runParameters); await this.PerformCooldown(this.runParameters); } this.ClearData(); }, this.runCancellationTokenSource.Token); #pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed await this.RunSubCommand(this.StartedCommand, this.runParameters); await this.RunSubCommand(this.UserJoinCommand, this.runParameters); return; } else if (!this.runUsers.ContainsKey(parameters.User)) { this.runUsers[parameters.User] = parameters; await this.RunSubCommand(this.UserJoinCommand, parameters); return; } else { await ChannelSession.Services.Chat.SendMessage(MixItUp.Base.Resources.GameCommandAlreadyUnderway); } await this.Requirements.Refund(parameters); }
protected bool ValidatePrimaryCurrencyAmount(CommandParametersModel parameters, int amount) { CurrencyRequirementModel currencyRequirement = this.GetPrimaryCurrencyRequirement(); return((currencyRequirement != null) ? currencyRequirement.Currency.HasAmount(parameters.User.Data, amount) : false); }
protected int GetPrimaryBetAmount(CommandParametersModel parameters) { CurrencyRequirementModel currencyRequirement = this.GetPrimaryCurrencyRequirement(); return((currencyRequirement != null) ? currencyRequirement.GetAmount(parameters) : 0); }
public override async Task CustomRun(CommandParametersModel parameters) { await this.RefundCooldown(parameters); var lastTargetUser = this.lastTossParameters?.TargetUser; if (this.gameActive && lastTargetUser != parameters.User) { // The game is underway and it's not the user's turn await ChannelSession.Services.Chat.SendMessage(MixItUp.Base.Resources.GameCommandAlreadyUnderway); await this.Requirements.Refund(parameters); return; } await this.SetSelectedUser(this.PlayerSelectionType, parameters); if (parameters.TargetUser != null) { if (this.startParameters == null) { this.gameActive = true; this.startParameters = parameters; if (this.ResetTimeOnToss) { this.RestartTossTime(); } else { #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed AsyncRunner.RunAsyncBackground(async(token) => { await DelayNoThrow(1000 * RandomHelper.GenerateRandomNumber(this.LowerTimeLimit, this.UpperTimeLimit), token); this.gameActive = false; this.SetGameWinners(this.lastTossParameters, new List <CommandParametersModel>() { this.lastTossParameters }); await this.RunSubCommand(this.PotatoExplodeCommand, this.lastTossParameters); await this.PerformCooldown(this.startParameters); this.ClearData(); }, new CancellationToken()); #pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed } await this.RunSubCommand(this.StartedCommand, parameters); } else { if (this.ResetTimeOnToss) { this.RestartTossTime(); } await this.RunSubCommand(this.TossPotatoCommand, parameters); } this.lastTossParameters = parameters; return; } else { await ChannelSession.Services.Chat.SendMessage(MixItUp.Base.Resources.GameCommandCouldNotFindUser); } await this.Requirements.Refund(parameters); }
protected override async Task PerformInternal(CommandParametersModel parameters) { if (this.ActionType == GameQueueActionType.EnableDisableQueue) { if (ChannelSession.Services.GameQueueService.IsEnabled) { await ChannelSession.Services.GameQueueService.Disable(); } else { await ChannelSession.Services.GameQueueService.Enable(); } } else if (this.ActionType == GameQueueActionType.EnableQueue) { await ChannelSession.Services.GameQueueService.Enable(); } else if (this.ActionType == GameQueueActionType.DisableQueue) { await ChannelSession.Services.GameQueueService.Disable(); } else { if (!ChannelSession.Services.GameQueueService.IsEnabled) { await ChannelSession.Services.Chat.SendMessage("The game queue is not currently enabled"); return; } UserViewModel targetUser = parameters.User; if (!string.IsNullOrEmpty(this.TargetUsername)) { string username = await ReplaceStringWithSpecialModifiers(this.TargetUsername, parameters); targetUser = ChannelSession.Services.User.GetActiveUserByUsername(username, parameters.Platform); if (targetUser == null) { await ChannelSession.Services.Chat.SendMessage("The user could not be found"); return; } } if (this.ActionType == GameQueueActionType.JoinQueue) { await ChannelSession.Services.GameQueueService.Join(targetUser); } else if (this.ActionType == GameQueueActionType.JoinFrontOfQueue) { await ChannelSession.Services.GameQueueService.JoinFront(targetUser); } else if (this.ActionType == GameQueueActionType.QueuePosition) { await ChannelSession.Services.GameQueueService.PrintUserPosition(targetUser); } else if (this.ActionType == GameQueueActionType.QueueStatus) { await ChannelSession.Services.GameQueueService.PrintStatus(); } else if (this.ActionType == GameQueueActionType.LeaveQueue) { await ChannelSession.Services.GameQueueService.Leave(targetUser); } if (this.ActionType == GameQueueActionType.SelectFirst) { await ChannelSession.Services.GameQueueService.SelectFirst(); } else if (this.ActionType == GameQueueActionType.SelectRandom) { await ChannelSession.Services.GameQueueService.SelectRandom(); } else if (this.ActionType == GameQueueActionType.SelectFirstType) { if (this.RoleRequirement != null) { await ChannelSession.Services.GameQueueService.SelectFirstType(this.RoleRequirement); } else { await ChannelSession.Services.GameQueueService.SelectFirst(); } } else if (this.ActionType == GameQueueActionType.ClearQueue) { await ChannelSession.Services.GameQueueService.Clear(); } } }
protected override async Task PerformInternal(CommandParametersModel parameters) { IStreamingSoftwareService ssService = null; if (this.SelectedStreamingSoftware == StreamingSoftwareTypeEnum.OBSStudio) { ssService = ChannelSession.Services.OBSStudio; } else if (this.SelectedStreamingSoftware == StreamingSoftwareTypeEnum.XSplit) { ssService = ChannelSession.Services.XSplit; } else if (this.SelectedStreamingSoftware == StreamingSoftwareTypeEnum.StreamlabsOBS) { ssService = ChannelSession.Services.StreamlabsOBS; } if (ssService != null && ssService.IsEnabled) { Logger.Log(LogLevel.Debug, "Checking for Streaming Software connection"); if (!ssService.IsConnected) { Result result = await ssService.Connect(); if (!result.Success) { Logger.Log(LogLevel.Error, result.Message); return; } } Logger.Log(LogLevel.Debug, "Performing for Streaming Software connection"); if (ssService.IsConnected) { string name = null; if (!string.IsNullOrEmpty(this.ItemName)) { name = await ReplaceStringWithSpecialModifiers(this.ItemName, parameters); } string parentName = null; if (!string.IsNullOrEmpty(this.ParentName)) { parentName = await ReplaceStringWithSpecialModifiers(this.ParentName, parameters); } if (this.ActionType == StreamingSoftwareActionTypeEnum.StartStopStream) { await ssService.StartStopStream(); } else if (this.ActionType == StreamingSoftwareActionTypeEnum.StartStopRecording) { await ssService.StartStopRecording(); } else if (this.ActionType == StreamingSoftwareActionTypeEnum.SaveReplayBuffer) { await ssService.SaveReplayBuffer(); } else if (this.ActionType == StreamingSoftwareActionTypeEnum.Scene) { if (!string.IsNullOrEmpty(name)) { await ssService.ShowScene(name); } } else if (this.ActionType == StreamingSoftwareActionTypeEnum.SourceFilterVisibility) { if (!string.IsNullOrEmpty(name) && !string.IsNullOrEmpty(parentName)) { await ssService.SetSourceFilterVisibility(parentName, name, this.Visible); } } else if (!string.IsNullOrEmpty(name)) { if (this.ActionType == StreamingSoftwareActionTypeEnum.WebBrowserSource && !string.IsNullOrEmpty(this.SourceURL)) { await ssService.SetWebBrowserSourceURL(parentName, name, await ReplaceStringWithSpecialModifiers(this.SourceURL, parameters)); } else if (this.ActionType == StreamingSoftwareActionTypeEnum.TextSource && !string.IsNullOrEmpty(this.SourceText) && !string.IsNullOrEmpty(this.SourceTextFilePath)) { try { if (!Directory.Exists(Path.GetDirectoryName(this.SourceTextFilePath))) { Directory.CreateDirectory(Path.GetDirectoryName(this.SourceTextFilePath)); } using (StreamWriter writer = new StreamWriter(File.Open(this.SourceTextFilePath, FileMode.Create))) { writer.Write(await ReplaceStringWithSpecialModifiers(this.SourceText, parameters)); writer.Flush(); } } catch (Exception ex) { Logger.Log(ex); } } else if (this.ActionType == StreamingSoftwareActionTypeEnum.SourceDimensions && this.SourceDimensions != null) { await ssService.SetSourceDimensions(parentName, name, this.SourceDimensions); } await ssService.SetSourceVisibility(parentName, name, this.Visible); } else if (this.ActionType == StreamingSoftwareActionTypeEnum.SceneCollection && !string.IsNullOrEmpty(name)) { await ssService.SetSceneCollection(name); } } } else { Logger.Log(LogLevel.Error, "The Streaming Software selected is not enabled: " + this.SelectedStreamingSoftware); } }
protected async Task PerformCooldown(CommandParametersModel parameters) { await this.Requirements.Requirements.FirstOrDefault(r => r is CooldownRequirementModel).Perform(parameters); }
protected override async Task <Dictionary <string, string> > GetTemplateReplacements(CommandParametersModel parameters) { Dictionary <string, string> replacementSets = await base.GetTemplateReplacements(parameters); replacementSets["BACKGROUND_COLOR"] = this.BackgroundColor; replacementSets["BORDER_COLOR"] = this.BorderColor; replacementSets["TEXT_COLOR"] = this.TextColor; replacementSets["TEXT_FONT"] = this.TextFont; replacementSets["WIDTH"] = this.Width.ToString(); replacementSets["HEIGHT"] = this.Height.ToString(); replacementSets["TEXT_HEIGHT"] = ((int)(0.4 * ((double)this.Height))).ToString(); return(replacementSets); }
private async void GlobalEvents_OnChatCommandMessageReceived(object sender, ChatMessageViewModel message) { try { if (this.TimeLeft > 0 && this.Winner == null && this.giveawayCommand.DoesMessageMatchTriggers(message, out IEnumerable <string> arguments)) { CommandParametersModel parameters = new CommandParametersModel(message); parameters.Arguments = new List <string>(arguments); int entries = 1; if (pastWinners.Contains(message.User.ID)) { await ChannelSession.Services.Chat.SendMessage("You have already won a giveaway and can not enter this one"); return; } if (arguments.Count() > 0 && ChannelSession.Settings.GiveawayMaximumEntries > 1) { if (!int.TryParse(arguments.ElementAt(0), out entries) || entries < 1) { entries = 1; } } int currentEntries = 0; if (this.enteredUsers.ContainsKey(message.User.ID)) { currentEntries = this.enteredUsers[message.User.ID].Entries; } if ((entries + currentEntries) > ChannelSession.Settings.GiveawayMaximumEntries) { await ChannelSession.Services.Chat.SendMessage(string.Format("You may only enter {0} time(s), you currently have entered {1} time(s)", ChannelSession.Settings.GiveawayMaximumEntries, currentEntries)); return; } Result result = await ChannelSession.Settings.GiveawayRequirementsSet.Validate(parameters); if (result.Success) { foreach (CurrencyRequirementModel requirement in ChannelSession.Settings.GiveawayRequirementsSet.Currency) { int totalAmount = requirement.MinAmount * entries; result = requirement.ValidateAmount(message.User, totalAmount); if (!result.Success) { await requirement.SendErrorChatMessage(message.User, result); return; } } foreach (InventoryRequirementModel requirement in ChannelSession.Settings.GiveawayRequirementsSet.Inventory) { int totalAmount = requirement.Amount * entries; result = requirement.ValidateAmount(message.User, totalAmount); if (!result.Success) { await requirement.SendErrorChatMessage(message.User, result); return; } } await ChannelSession.Settings.GiveawayRequirementsSet.Perform(parameters); // Do additional currency / inventory performs passed on how many additional entries they put in for (int i = 1; i < entries; i++) { foreach (CurrencyRequirementModel requirement in ChannelSession.Settings.GiveawayRequirementsSet.Currency) { await requirement.Perform(parameters); } foreach (InventoryRequirementModel requirement in ChannelSession.Settings.GiveawayRequirementsSet.Inventory) { await requirement.Perform(parameters); } } if (!this.enteredUsers.ContainsKey(message.User.ID)) { this.enteredUsers[message.User.ID] = new GiveawayUser() { User = message.User, Entries = 0 }; this.previousEnteredUsers[message.User.ID] = this.enteredUsers[message.User.ID]; } GiveawayUser giveawayUser = this.enteredUsers[message.User.ID]; if (giveawayUser != null) { giveawayUser.Entries += entries; Dictionary <string, string> specialIdentifiers = this.GetSpecialIdentifiers(); specialIdentifiers["usergiveawayentries"] = entries.ToString(); specialIdentifiers["usergiveawaytotalentries"] = giveawayUser.Entries.ToString(); await ChannelSession.Settings.GetCommand(ChannelSession.Settings.GiveawayUserJoinedCommandID).Perform(new CommandParametersModel(message.User, arguments, specialIdentifiers)); GlobalEvents.GiveawaysChangedOccurred(usersUpdated: true); } } } else if (this.Winner != null && this.Winner.Equals(message.User) && message.PlainTextMessage.Equals("!claim", StringComparison.InvariantCultureIgnoreCase)) { await ChannelSession.Settings.GetCommand(ChannelSession.Settings.GiveawayWinnerSelectedCommandID).Perform(new CommandParametersModel(this.Winner, this.GetSpecialIdentifiers())); await this.End(); } } catch (Exception ex) { Logger.Log(ex); } }
protected override Task <bool> ValidateRequirements(CommandParametersModel parameters) { return(base.ValidateRequirements(parameters)); }
public CommandEditorWindowViewModelBase(CommandTypeEnum type) { this.Type = type; this.SaveCommand = this.CreateCommand(async(parameter) => { CommandModelBase command = await this.ValidateAndBuildCommand(); if (command != null) { if (!command.IsEmbedded) { ChannelSession.Settings.SetCommand(command); await ChannelSession.SaveSettings(); } await this.SaveCommandToSettings(command); this.CommandSaved(this, command); } }); this.TestCommand = this.CreateCommand(async(parameter) => { if (!await this.CheckForResultErrors(await this.ValidateActions())) { IEnumerable <ActionModelBase> actions = await this.GetActions(); if (actions != null) { await CommandModelBase.RunActions(actions, CommandParametersModel.GetTestParameters(this.GetTestSpecialIdentifiers())); } } }); this.ExportCommand = this.CreateCommand(async(parameter) => { CommandModelBase command = await this.ValidateAndBuildCommand(); if (command != null) { string fileName = ChannelSession.Services.FileService.ShowSaveFileDialog(this.Name + MixItUpCommandFileExtension); if (!string.IsNullOrEmpty(fileName)) { await FileSerializerHelper.SerializeToFile(fileName, command); } } }); this.ImportCommand = this.CreateCommand(async(parameter) => { try { CommandModelBase command = await CommandEditorWindowViewModelBase.ImportCommandFromFile(); if (command != null) { // TODO Check if the imported command type matches the currently edited command. If so, import additional information. foreach (ActionModelBase action in command.Actions) { await this.AddAction(action); } } } catch (Exception ex) { Logger.Log(ex); await DialogHelper.ShowMessage(MixItUp.Base.Resources.FailedToImportCommand); } }); }
protected override async Task PerformRequirements(CommandParametersModel parameters) { parameters.SpecialIdentifiers[GameCommandModelBase.GameBetSpecialIdentifier] = this.GetPrimaryBetAmount(parameters).ToString(); await this.Requirements.Perform(parameters, RequirementSkipTypes); }
private void ClearData() { this.gameActive = false; this.startParameters = null; this.lastTossParameters = null; }
protected override Task PerformInternal(CommandParametersModel parameters) { return(base.PerformInternal(parameters)); }