public bool DoesMeetRankRequirement(UserDataViewModel userData) { if (userData.IsCurrencyRankExempt) { return(true); } UserCurrencyViewModel currency = this.GetCurrency(); if (currency == null) { return(false); } UserRankViewModel rank = this.RequiredRank; if (rank == null) { return(false); } if (!userData.HasCurrencyAmount(currency, rank.MinimumPoints)) { return(false); } UserCurrencyDataViewModel userCurrencyData = userData.GetCurrency(currency); if (this.MustEqual && userCurrencyData.GetRank() != rank && !userData.IsCurrencyRankExempt) { return(false); } return(true); }
public static void RankChanged(UserCurrencyDataViewModel currency) { if (GlobalEvents.OnRankChanged != null) { GlobalEvents.OnRankChanged(null, currency); } }
public bool DoesMeetCurrencyRequirement(UserDataViewModel userData) { if (userData.IsCurrencyRankExempt) { return(true); } UserCurrencyViewModel currency = this.GetCurrency(); if (currency == null) { return(false); } UserRankViewModel rank = this.RequiredRank; if (rank == null) { return(false); } UserCurrencyDataViewModel userCurrencyData = userData.GetCurrency(currency); return(this.DoesMeetCurrencyRequirement(userCurrencyData.Amount)); }
private static async void GlobalEvents_OnRankChanged(object sender, UserCurrencyDataViewModel currency) { if (currency.Currency.RankChangedCommand != null && ChannelSession.Chat.ChatUsers.ContainsKey(currency.User.ID) == true) { var user = ChannelSession.Chat.ChatUsers[currency.User.ID]; await currency.Currency.RankChangedCommand.Perform(user); } }
public UserCurrencyIndividualEditorControl(UserCurrencyDataViewModel currencyData) { this.currencyData = currencyData; InitializeComponent(); this.Loaded += UserCurrencyIndividualEditorControl_Loaded; }
private void TextBox_TextChanged(object sender, System.Windows.Controls.TextChangedEventArgs e) { TextBox textBox = (TextBox)sender; UserCurrencyDataViewModel currencyData = (UserCurrencyDataViewModel)textBox.DataContext; if (!string.IsNullOrEmpty(textBox.Text) && int.TryParse(textBox.Text, out int amount) && amount >= 0) { currencyData.Amount = amount; } }
private void CurrencyAmountTextBox_TextChanged(object sender, TextChangedEventArgs e) { TextBox textBox = (TextBox)sender; UserCurrencyDataViewModel currencyData = (UserCurrencyDataViewModel)textBox.DataContext; if (!string.IsNullOrEmpty(textBox.Text) && int.TryParse(textBox.Text, out int amount) && amount >= 0) { this.user.Data.SetCurrencyAmount(currencyData.Currency, amount); } }
private async Task HandleUserSpecialIdentifiers(UserViewModel user, string identifierHeader) { if (user != null) { await user.RefreshDetails(); if (ChannelSession.Settings.UserData.ContainsKey(user.ID)) { UserDataViewModel userData = ChannelSession.Settings.UserData[user.ID]; foreach (UserCurrencyViewModel currency in ChannelSession.Settings.Currencies.Values) { UserCurrencyDataViewModel currencyData = userData.GetCurrency(currency); UserRankViewModel rank = currencyData.GetRank(); this.ReplaceSpecialIdentifier(identifierHeader + currency.UserRankNameSpecialIdentifier, rank.Name); this.ReplaceSpecialIdentifier(identifierHeader + currency.UserAmountSpecialIdentifier, currencyData.Amount.ToString()); } this.ReplaceSpecialIdentifier(identifierHeader + UserSpecialIdentifierHeader + "time", userData.ViewingTimeString); this.ReplaceSpecialIdentifier(identifierHeader + UserSpecialIdentifierHeader + "hours", userData.ViewingHoursString); this.ReplaceSpecialIdentifier(identifierHeader + UserSpecialIdentifierHeader + "mins", userData.ViewingMinutesString); } if (this.ContainsSpecialIdentifier(identifierHeader + UserSpecialIdentifierHeader + "game")) { GameTypeModel game = await ChannelSession.Connection.GetGameType(user.GameTypeID); if (game != null) { this.ReplaceSpecialIdentifier(identifierHeader + UserSpecialIdentifierHeader + "game", game.name.ToString()); } else { this.ReplaceSpecialIdentifier(identifierHeader + UserSpecialIdentifierHeader + "game", "Unknown"); } } this.ReplaceSpecialIdentifier(identifierHeader + UserSpecialIdentifierHeader + "followage", user.FollowAgeString); this.ReplaceSpecialIdentifier(identifierHeader + UserSpecialIdentifierHeader + "subage", user.SubscribeAgeString); this.ReplaceSpecialIdentifier(identifierHeader + UserSpecialIdentifierHeader + "submonths", user.SubscribeMonths.ToString()); this.ReplaceSpecialIdentifier(identifierHeader + UserSpecialIdentifierHeader + "avatar", user.AvatarLink); this.ReplaceSpecialIdentifier(identifierHeader + UserSpecialIdentifierHeader + "url", "https://www.mixer.com/" + user.UserName); this.ReplaceSpecialIdentifier(identifierHeader + UserSpecialIdentifierHeader + "name", user.UserName); this.ReplaceSpecialIdentifier(identifierHeader + UserSpecialIdentifierHeader + "id", user.ID.ToString()); if (this.ContainsSpecialIdentifier(identifierHeader + UserSpecialIdentifierHeader + "followers")) { ExpandedChannelModel channel = await ChannelSession.Connection.GetChannel(user.UserName); this.ReplaceSpecialIdentifier(identifierHeader + UserSpecialIdentifierHeader + "followers", channel?.numFollowers.ToString() ?? "0"); } } }
private static async void GlobalEvents_OnRankChanged(object sender, UserCurrencyDataViewModel currency) { if (currency.Currency.RankChangedCommand != null) { UserViewModel user = await ChannelSession.ActiveUsers.GetUserByID(currency.User.ID); if (user != null) { await currency.Currency.RankChangedCommand.Perform(user); } } }
private async Task RefreshData() { this.DataContext = null; await this.user.RefreshDetails(force : true); this.CurrencyRankStackPanel.Children.Clear(); foreach (UserCurrencyViewModel currency in ChannelSession.Settings.Currencies.Values.ToList()) { UserCurrencyDataViewModel currencyData = this.user.Data.GetCurrency(currency); this.CurrencyRankStackPanel.Children.Add(new UserCurrencyIndividualEditorControl(currencyData)); } this.InventoryStackPanel.Children.Clear(); foreach (UserInventoryViewModel inventory in ChannelSession.Settings.Inventories.Values.ToList()) { UserInventoryDataViewModel inventoryData = this.user.Data.GetInventory(inventory); this.InventoryStackPanel.Children.Add(new UserInventoryEditorControl(inventory, inventoryData)); } this.UserOnlyChatCommandsListView.Visibility = Visibility.Collapsed; this.userOnlyCommands.Clear(); if (this.user.Data.CustomCommands.Count > 0) { this.UserOnlyChatCommandsListView.Visibility = Visibility.Visible; foreach (ChatCommand command in this.user.Data.CustomCommands) { this.userOnlyCommands.Add(command); } } if (this.user.Data.EntranceCommand != null) { this.NewEntranceCommandButton.Visibility = Visibility.Collapsed; this.ExistingEntranceCommandButtons.Visibility = Visibility.Visible; this.ExistingEntranceCommandButtons.DataContext = this.user.Data.EntranceCommand; } else { this.NewEntranceCommandButton.Visibility = Visibility.Visible; this.ExistingEntranceCommandButtons.Visibility = Visibility.Collapsed; } if (ChannelSession.Services.Patreon != null) { this.PatreonUserComboBox.IsEnabled = true; this.PatreonUserComboBox.ItemsSource = ChannelSession.Services.Patreon.CampaignMembers; this.PatreonUserComboBox.SelectedItem = this.user.PatreonUser; } this.DataContext = this.user; }
private async Task RefreshData() { await this.user.RefreshDetails(); this.ranks.Clear(); this.currencies.Clear(); foreach (UserCurrencyViewModel currency in ChannelSession.Settings.Currencies.Values.ToList()) { UserCurrencyDataViewModel currencyData = this.user.Data.GetCurrency(currency); if (currencyData.Currency.IsRank) { this.ranks.Add(new UserCurrencyIndividualEditorControl(currencyData)); } else { this.currencies.Add(new UserCurrencyIndividualEditorControl(currencyData)); } } this.UserOnlyChatCommandsListView.Visibility = Visibility.Collapsed; this.userOnlyCommands.Clear(); if (this.user.Data.CustomCommands.Count > 0) { this.UserOnlyChatCommandsListView.Visibility = Visibility.Visible; foreach (ChatCommand command in this.user.Data.CustomCommands) { this.userOnlyCommands.Add(command); } } if (this.user.Data.EntranceCommand != null) { this.NewEntranceCommandButton.Visibility = Visibility.Collapsed; this.ExistingEntranceCommandButtons.Visibility = Visibility.Visible; this.ExistingEntranceCommandButtons.DataContext = this.user.Data.EntranceCommand; } else { this.NewEntranceCommandButton.Visibility = Visibility.Visible; this.ExistingEntranceCommandButtons.Visibility = Visibility.Collapsed; } this.DataContext = null; this.DataContext = this.user; }
public bool TrySubtractAmount(UserDataViewModel userData, int amount) { if (this.DoesMeetCurrencyRequirement(amount)) { UserCurrencyViewModel currency = this.GetCurrency(); if (currency == null) { return(false); } UserCurrencyDataViewModel userCurrencyData = userData.GetCurrency(currency); if (userCurrencyData.Amount < amount) { return(false); } userCurrencyData.Amount -= amount; return(true); } return(false); }
protected override async Task PerformInternal(UserViewModel user, IEnumerable <string> arguments) { if (ChannelSession.Chat != null) { UserCurrencyDataViewModel currencyData = user.Data.GetCurrency(this.CurrencyID); if (currencyData != null) { currencyData.Amount += this.Amount; if (!string.IsNullOrEmpty(this.ChatText)) { string message = await this.ReplaceStringWithSpecialModifiers(this.ChatText, user, arguments); if (this.IsWhisper) { await ChannelSession.Chat.Whisper(user.UserName, message); } else { await ChannelSession.Chat.SendMessage(message); } } } } }
public async Task ReplaceCommonSpecialModifiers(UserViewModel user, IEnumerable <string> arguments = null) { foreach (string counter in ChannelSession.Counters.Keys) { this.ReplaceSpecialIdentifier(counter, ChannelSession.Counters[counter].ToString()); } foreach (var kvp in SpecialIdentifierStringBuilder.CustomSpecialIdentifiers) { this.ReplaceSpecialIdentifier(kvp.Key, kvp.Value); } this.ReplaceSpecialIdentifier("date", DateTimeOffset.Now.ToString("d")); this.ReplaceSpecialIdentifier("time", DateTimeOffset.Now.ToString("t")); this.ReplaceSpecialIdentifier("datetime", DateTimeOffset.Now.ToString("g")); if (user != null) { if (string.IsNullOrEmpty(user.AvatarLink)) { user.AvatarLink = UserViewModel.DefaultAvatarLink; } if (user.AvatarLink.Equals(UserViewModel.DefaultAvatarLink)) { UserModel avatarUser = await ChannelSession.Connection.GetUser(user.UserName); if (!string.IsNullOrEmpty(user.AvatarLink)) { user.AvatarLink = avatarUser.avatarUrl; } } for (int i = 0; i < ChannelSession.Settings.Currencies.Count; i++) { UserCurrencyViewModel currency = ChannelSession.Settings.Currencies.Values.ElementAt(i); UserCurrencyDataViewModel currencyData = user.Data.GetCurrency(currency); UserRankViewModel rank = currencyData.GetRank(); this.ReplaceSpecialIdentifier(currency.UserRankNameSpecialIdentifier, rank.Name); this.ReplaceSpecialIdentifier(currency.UserAmountSpecialIdentifier, currencyData.Amount.ToString()); } this.ReplaceSpecialIdentifier("usertime", user.Data.ViewingTimeString); this.ReplaceSpecialIdentifier("userhours", user.Data.ViewingHoursString); this.ReplaceSpecialIdentifier("usermins", user.Data.ViewingMinutesString); this.ReplaceSpecialIdentifier("userfollowage", user.FollowAgeString); this.ReplaceSpecialIdentifier("usersubage", user.SubscribeAgeString); this.ReplaceSpecialIdentifier("usersubmonths", user.SubscribeMonths.ToString()); if (this.ContainsSpecialIdentifier("usergame")) { GameTypeModel game = await ChannelSession.Connection.GetGameType(user.GameTypeID); this.ReplaceSpecialIdentifier("usergame", game.name.ToString()); } this.ReplaceSpecialIdentifier("useravatar", user.AvatarLink); this.ReplaceSpecialIdentifier("userurl", "https://www.mixer.com/" + user.UserName); this.ReplaceSpecialIdentifier("username", user.UserName); this.ReplaceSpecialIdentifier("userid", user.ID.ToString()); } if (arguments != null) { for (int i = 0; i < arguments.Count(); i++) { string username = arguments.ElementAt(i); username = username.Replace("@", ""); UserModel argUserModel = await ChannelSession.Connection.GetUser(username); if (argUserModel != null) { UserViewModel argUser = new UserViewModel(argUserModel); await argUser.SetDetails(); if (ChannelSession.Settings.UserData.ContainsKey(argUser.ID)) { UserDataViewModel userData = ChannelSession.Settings.UserData[argUser.ID]; for (int c = 0; c < ChannelSession.Settings.Currencies.Count; c++) { UserCurrencyViewModel currency = ChannelSession.Settings.Currencies.Values.ElementAt(i); UserCurrencyDataViewModel currencyData = userData.GetCurrency(currency); UserRankViewModel rank = currencyData.GetRank(); this.ReplaceSpecialIdentifier("arg" + (i + 1) + currency.UserRankNameSpecialIdentifier, rank.Name); this.ReplaceSpecialIdentifier("arg" + (i + 1) + currency.UserAmountSpecialIdentifier, currencyData.Amount.ToString()); } this.ReplaceSpecialIdentifier("arg" + (i + 1) + "usertime", userData.ViewingTimeString); this.ReplaceSpecialIdentifier("arg" + (i + 1) + "userhours", userData.ViewingHoursString); this.ReplaceSpecialIdentifier("arg" + (i + 1) + "usermins", userData.ViewingMinutesString); } if (this.ContainsSpecialIdentifier("arg" + (i + 1) + "usergame")) { GameTypeModel game = await ChannelSession.Connection.GetGameType(argUser.GameTypeID); this.ReplaceSpecialIdentifier("arg" + (i + 1) + "usergame", game.name.ToString()); } this.ReplaceSpecialIdentifier("arg" + (i + 1) + "userfollowage", argUser.FollowAgeString); this.ReplaceSpecialIdentifier("arg" + (i + 1) + "usersubage", argUser.SubscribeAgeString); this.ReplaceSpecialIdentifier("arg" + (i + 1) + "usersubmonths", argUser.SubscribeMonths.ToString()); this.ReplaceSpecialIdentifier("arg" + (i + 1) + "useravatar", argUser.AvatarLink); this.ReplaceSpecialIdentifier("arg" + (i + 1) + "userurl", "https://www.mixer.com/" + argUser.UserName); this.ReplaceSpecialIdentifier("arg" + (i + 1) + "username", argUser.UserName); this.ReplaceSpecialIdentifier("arg" + (i + 1) + "userid", argUser.ID.ToString()); } this.ReplaceSpecialIdentifier("arg" + (i + 1) + "text", arguments.ElementAt(i)); } this.ReplaceSpecialIdentifier("allargs", string.Join(" ", arguments)); } }
private async Task HandleUserSpecialIdentifiers(UserViewModel user, string identifierHeader) { if (user != null && this.ContainsSpecialIdentifier(identifierHeader + UserSpecialIdentifierHeader)) { await user.RefreshDetails(); if (ChannelSession.Settings.UserData.ContainsKey(user.ID)) { UserDataViewModel userData = ChannelSession.Settings.UserData[user.ID]; foreach (UserCurrencyViewModel currency in ChannelSession.Settings.Currencies.Values.OrderByDescending(c => c.UserAmountSpecialIdentifier)) { UserCurrencyDataViewModel currencyData = userData.GetCurrency(currency); UserRankViewModel rank = currencyData.GetRank(); UserRankViewModel nextRank = currencyData.GetNextRank(); this.ReplaceSpecialIdentifier(identifierHeader + currency.UserRankNextNameSpecialIdentifier, nextRank.Name); this.ReplaceSpecialIdentifier(identifierHeader + currency.UserAmountNextSpecialIdentifier, nextRank.MinimumPoints.ToString()); this.ReplaceSpecialIdentifier(identifierHeader + currency.UserRankNameSpecialIdentifier, rank.Name); this.ReplaceSpecialIdentifier(identifierHeader + currency.UserAmountSpecialIdentifier, currencyData.Amount.ToString()); } foreach (UserInventoryViewModel inventory in ChannelSession.Settings.Inventories.Values.OrderByDescending(c => c.UserAmountSpecialIdentifierHeader)) { if (this.ContainsSpecialIdentifier(identifierHeader + inventory.UserAmountSpecialIdentifierHeader)) { UserInventoryDataViewModel inventoryData = userData.GetInventory(inventory); List <string> allItemsList = new List <string>(); foreach (UserInventoryItemViewModel item in inventory.Items.Values.OrderByDescending(i => i.Name)) { int amount = inventoryData.GetAmount(item); if (amount > 0) { allItemsList.Add(item.Name + " x" + amount); } string itemSpecialIdentifier = identifierHeader + inventory.UserAmountSpecialIdentifierHeader + item.SpecialIdentifier; this.ReplaceSpecialIdentifier(itemSpecialIdentifier, amount.ToString()); } if (allItemsList.Count > 0) { this.ReplaceSpecialIdentifier(identifierHeader + inventory.UserAllAmountSpecialIdentifier, string.Join(", ", allItemsList.OrderBy(i => i))); } else { this.ReplaceSpecialIdentifier(identifierHeader + inventory.UserAllAmountSpecialIdentifier, "Nothing"); } } } this.ReplaceSpecialIdentifier(identifierHeader + UserSpecialIdentifierHeader + "time", userData.ViewingTimeString); this.ReplaceSpecialIdentifier(identifierHeader + UserSpecialIdentifierHeader + "hours", userData.ViewingHoursString); this.ReplaceSpecialIdentifier(identifierHeader + UserSpecialIdentifierHeader + "mins", userData.ViewingMinutesString); this.ReplaceSpecialIdentifier(identifierHeader + UserSpecialIdentifierHeader + "moderationstrikes", userData.ModerationStrikes.ToString()); } this.ReplaceSpecialIdentifier(identifierHeader + UserSpecialIdentifierHeader + "primaryrole", user.PrimaryRoleString); this.ReplaceSpecialIdentifier(identifierHeader + UserSpecialIdentifierHeader + "avatar", user.AvatarLink); this.ReplaceSpecialIdentifier(identifierHeader + UserSpecialIdentifierHeader + "url", "https://www.mixer.com/" + user.UserName); this.ReplaceSpecialIdentifier(identifierHeader + UserSpecialIdentifierHeader + "name", user.UserName); this.ReplaceSpecialIdentifier(identifierHeader + UserSpecialIdentifierHeader + "id", user.ID.ToString()); this.ReplaceSpecialIdentifier(identifierHeader + UserSpecialIdentifierHeader + "sparks", user.Sparks.ToString()); this.ReplaceSpecialIdentifier(identifierHeader + UserSpecialIdentifierHeader + "mixerage", user.MixerAgeString); this.ReplaceSpecialIdentifier(identifierHeader + UserSpecialIdentifierHeader + "followage", user.FollowAgeString); this.ReplaceSpecialIdentifier(identifierHeader + UserSpecialIdentifierHeader + "subage", user.MixerSubscribeAgeString); this.ReplaceSpecialIdentifier(identifierHeader + UserSpecialIdentifierHeader + "submonths", user.SubscribeMonths.ToString()); this.ReplaceSpecialIdentifier(identifierHeader + UserSpecialIdentifierHeader + "title", user.Title); this.ReplaceSpecialIdentifier(identifierHeader + UserSpecialIdentifierHeader + "fanprogressionnext", user.FanProgression?.level?.nextLevelXp.ToString()); this.ReplaceSpecialIdentifier(identifierHeader + UserSpecialIdentifierHeader + "fanprogressionrank", user.FanProgression?.level?.level.ToString()); this.ReplaceSpecialIdentifier(identifierHeader + UserSpecialIdentifierHeader + "fanprogressioncolor", user.FanProgression?.level?.color?.ToString()); this.ReplaceSpecialIdentifier(identifierHeader + UserSpecialIdentifierHeader + "fanprogressionimage", user.FanProgression?.level?.LargeGIFAssetURL?.ToString()); this.ReplaceSpecialIdentifier(identifierHeader + UserSpecialIdentifierHeader + "fanprogression", user.FanProgression?.level?.currentXp.ToString()); if (this.ContainsSpecialIdentifier(identifierHeader + UserSpecialIdentifierHeader + "followers") || this.ContainsSpecialIdentifier(identifierHeader + UserSpecialIdentifierHeader + "game") || this.ContainsSpecialIdentifier(identifierHeader + UserSpecialIdentifierHeader + "channel")) { ExpandedChannelModel channel = await ChannelSession.Connection.GetChannel(user.UserName); this.ReplaceSpecialIdentifier(identifierHeader + UserSpecialIdentifierHeader + "followers", channel?.numFollowers.ToString() ?? "0"); if (channel.type != null) { this.ReplaceSpecialIdentifier(identifierHeader + UserSpecialIdentifierHeader + "gameimage", channel.type.coverUrl); this.ReplaceSpecialIdentifier(identifierHeader + UserSpecialIdentifierHeader + "game", channel.type.name.ToString()); } this.ReplaceSpecialIdentifier(identifierHeader + UserSpecialIdentifierHeader + "channelid", channel.id.ToString()); this.ReplaceSpecialIdentifier(identifierHeader + UserSpecialIdentifierHeader + "channellive", channel.online.ToString()); this.ReplaceSpecialIdentifier(identifierHeader + UserSpecialIdentifierHeader + "channelfeatured", channel.featured.ToString()); } } }
public UserCurrencyDeveloperAPIModel(UserCurrencyDataViewModel currencyData) { this.ID = currencyData.Currency.ID; this.Amount = currencyData.Amount; }
private async void GlobalEvents_OnChatCommandMessageReceived(object sender, ChatMessageCommandViewModel e) { if (this.giveawayEnabled) { if (this.selectedWinner == null && e.CommandName.Equals(ChannelSession.Settings.GiveawayCommand)) { if (this.enteredUsers.Contains(e.User)) { await ChannelSession.Chat.Whisper(e.User.UserName, "You have already entered into this giveaway, stay tuned to see who wins!"); return; } bool isUserValid = true; if (ChannelSession.Settings.GiveawayUserRole == UserRole.Follower) { isUserValid = e.User.IsFollower; } else if (ChannelSession.Settings.GiveawayUserRole == UserRole.Subscriber) { isUserValid = e.User.Roles.Contains(UserRole.Subscriber); } if (isUserValid) { if (ChannelSession.Settings.GiveawayRankRequirement != null && ChannelSession.Settings.GiveawayRankRequirement.GetCurrency() != null) { UserCurrencyDataViewModel rankData = e.User.Data.GetCurrency(ChannelSession.Settings.GiveawayRankRequirement.GetCurrency()); if (!ChannelSession.Settings.GiveawayRankRequirement.DoesMeetRankRequirement(e.User.Data)) { await ChannelSession.Settings.GiveawayRankRequirement.SendRankNotMetWhisper(e.User); return; } } if (ChannelSession.Settings.GiveawayCurrencyRequirement != null && ChannelSession.Settings.GiveawayCurrencyRequirement.GetCurrency() != null) { UserCurrencyDataViewModel currencyData = e.User.Data.GetCurrency(ChannelSession.Settings.GiveawayCurrencyRequirement.GetCurrency()); if (!ChannelSession.Settings.GiveawayCurrencyRequirement.TrySubtractAmount(e.User.Data)) { await ChannelSession.Settings.GiveawayCurrencyRequirement.SendCurrencyNotMetWhisper(e.User); return; } } await ChannelSession.Chat.Whisper(e.User.UserName, "You have been entered into the giveaway, stay tuned to see who wins!"); await this.Dispatcher.BeginInvoke(new Action(() => { if (!this.enteredUsers.Contains(e.User)) { this.enteredUsers.Add(e.User); } })); } else { await ChannelSession.Chat.Whisper(e.User.UserName, string.Format("You are not able to enter this giveaway as it is only for {0}", ChannelSession.Settings.GiveawayUserRole)); } } else if (this.selectedWinner != null && e.CommandName.Equals("claim") && this.selectedWinner.Equals(e.User)) { await ChannelSession.Chat.SendMessage(string.Format("@{0} has claimed their prize! Listen closely to the streamer for instructions on getting your prize.", e.User.UserName)); await this.EndGiveaway(); } } }
protected override async Task PerformInternal(UserViewModel user, IEnumerable <string> arguments) { if (ChannelSession.Chat != null) { UserCurrencyDataViewModel senderCurrencyData = user.Data.GetCurrency(this.CurrencyID); List <UserCurrencyDataViewModel> receiverCurrencyDatas = new List <UserCurrencyDataViewModel>(); if (!string.IsNullOrEmpty(this.Username)) { string usernameString = await this.ReplaceStringWithSpecialModifiers(this.Username, user, arguments); UserModel receivingUser = await ChannelSession.Connection.GetUser(usernameString); if (receivingUser != null) { UserDataViewModel userData = ChannelSession.Settings.UserData.GetValueIfExists(receivingUser.id, new UserDataViewModel(new UserViewModel(receivingUser))); receiverCurrencyDatas.Add(userData.GetCurrency(this.CurrencyID)); } else { await ChannelSession.Chat.Whisper(user.UserName, "The user could not be found"); return; } } else if (this.GiveToAllUsers) { foreach (UserViewModel chatUser in await ChannelSession.ChannelUsers.GetAllWorkableUsers()) { receiverCurrencyDatas.Add(chatUser.Data.GetCurrency(this.CurrencyID)); } receiverCurrencyDatas.Remove(senderCurrencyData); } else { receiverCurrencyDatas.Add(senderCurrencyData); } if (receiverCurrencyDatas.Count > 0) { string amountTextValue = await this.ReplaceStringWithSpecialModifiers(this.Amount, user, arguments); if (int.TryParse(amountTextValue, out int amountValue)) { if (this.DeductFromUser) { if (senderCurrencyData.Amount < amountValue) { await ChannelSession.Chat.Whisper(user.UserName, string.Format("You do not have the required {0} {1} to do this", amountValue, ChannelSession.Settings.Currencies[this.CurrencyID].Name)); return; } senderCurrencyData.Amount -= amountValue; } foreach (UserCurrencyDataViewModel receiverCurrencyData in receiverCurrencyDatas) { receiverCurrencyData.Amount += amountValue; } if (!string.IsNullOrEmpty(this.ChatText)) { string message = await this.ReplaceStringWithSpecialModifiers(this.ChatText, user, arguments); if (this.IsWhisper) { foreach (UserCurrencyDataViewModel receiverCurrencyData in receiverCurrencyDatas) { await ChannelSession.Chat.Whisper(receiverCurrencyData.User.UserName, message); } } else { await ChannelSession.Chat.SendMessage(message); } } } else { await ChannelSession.Chat.Whisper(user.UserName, string.Format("{0} is not a valid amount of {1}", amountTextValue, ChannelSession.Settings.Currencies[this.CurrencyID].Name)); return; } } } }
public UserCurrencyIndividualEditorControl(UserCurrencyDataViewModel currencyData) : this() { this.currencyData = currencyData; }
protected override async Task PerformInternal(UserViewModel user, IEnumerable <string> arguments) { if (ChannelSession.Chat != null) { if (!ChannelSession.GameQueueEnabled) { await ChannelSession.Chat.Whisper(user.UserName, "The game queue is not currently enabled"); return; } if (this.GameQueueType == GameQueueActionType.JoinQueue) { int position = ChannelSession.GameQueue.IndexOf(user); if (position == -1) { if (!user.IsFollower) { await user.SetDetails(true); } if (ChannelSession.Settings.GameQueueMustFollow && !user.IsFollower) { await ChannelSession.Chat.Whisper(user.UserName, "You must be a follower of the channel to use the game queue"); return; } UserCurrencyDataViewModel rankData = null; if (ChannelSession.Settings.GameQueueRankRequirement != null) { rankData = user.Data.GetCurrency(ChannelSession.Settings.GameQueueRankRequirement.CurrencyID); if (!ChannelSession.Settings.GameQueueRankRequirement.DoesMeetRankRequirement(user.Data)) { await ChannelSession.Settings.GameQueueRankRequirement.SendRankNotMetWhisper(user); return; } } UserCurrencyDataViewModel currencyData = null; if (ChannelSession.Settings.GameQueueCurrencyRequirement != null) { currencyData = user.Data.GetCurrency(ChannelSession.Settings.GameQueueCurrencyRequirement.CurrencyID); if (!ChannelSession.Settings.GameQueueCurrencyRequirement.TrySubtractAmount(user.Data)) { await ChannelSession.Settings.GameQueueCurrencyRequirement.SendCurrencyNotMetWhisper(user); return; } } if (ChannelSession.Settings.GameQueueSubPriority && user.Roles.Contains(UserRole.Subscriber)) { int totalSubs = ChannelSession.GameQueue.Count(u => u.Roles.Contains(UserRole.Subscriber)); ChannelSession.GameQueue.Insert(totalSubs, user); } else { ChannelSession.GameQueue.Add(user); } } await this.PrintUserPosition(user); } else if (this.GameQueueType == GameQueueActionType.QueuePosition) { await this.PrintUserPosition(user); } else if (this.GameQueueType == GameQueueActionType.QueueStatus) { StringBuilder message = new StringBuilder(); message.Append(string.Format("There are currently {0} waiting to play with @{1}.", ChannelSession.GameQueue.Count(), ChannelSession.Channel.user.username)); if (ChannelSession.GameQueue.Count() > 0) { message.Append(" The following users are next up to play: "); List <string> users = new List <string>(); for (int i = 0; i < ChannelSession.GameQueue.Count() && i < 5; i++) { users.Add("@" + ChannelSession.GameQueue[i].UserName); } message.Append(string.Join(", ", users)); message.Append("."); } await ChannelSession.Chat.SendMessage(message.ToString()); } else if (this.GameQueueType == GameQueueActionType.LeaveQueue) { ChannelSession.GameQueue.Remove(user); await ChannelSession.Chat.Whisper(user.UserName, string.Format("You have left the queue to play with @{0}.", ChannelSession.Channel.user.username)); } else if (this.GameQueueType == GameQueueActionType.RemoveFirst) { if (ChannelSession.GameQueue.Count() > 0) { UserViewModel firstUser = ChannelSession.GameQueue.ElementAt(0); ChannelSession.GameQueue.RemoveAt(0); await ChannelSession.Chat.SendMessage(string.Format("it's time to play @{0}! Listen carefully for instructions on how to join @{1}", firstUser.UserName, ChannelSession.Channel.user.username)); } } GlobalEvents.GameQueueUpdated(); } }