Exemple #1
0
        private void ChatMessageReceived(object sender, OnChatCommandReceivedArgs e)
        {
            // check if correct command
            if (e.Command.CommandText.ToLower() != "roulette")
            {
                return;
            }

            // check if arguments are valid
            if (e.Command.ArgumentsAsList.Count < 2)
            {
                return;
            }

            if (int.TryParse(e.Command.ArgumentsAsList[0], out int rouletteBet))
            {
                var userId = Convert.ToInt32(e.Command.ChatMessage.UserId);

                // check if already registered
                if (registeredUsers.Any(u => u.UserId == userId))
                {
                    return;
                }

                // check if user has enough currency
                if (!_databaseCurrencyHandler.HasUserEnoughCurrency(userId, rouletteBet))
                {
                    return;
                }
                else
                {
                    _databaseCurrencyHandler.Remove.Remove(userId, rouletteBet);
                }

                var betType = GetBetType(e.Command.ArgumentsAsList[1]);
                if (betType == BetTypes.Unknown)
                {
                    return;
                }

                var user = new User {
                    Name     = e.Command.ChatMessage.DisplayName,
                    UserId   = userId,
                    BetValue = rouletteBet,
                    BetType  = betType
                };

                registeredUsers.Add(user);
            }
        }
Exemple #2
0
        private void ChatCommandReceived(object sender, OnChatCommandReceivedArgs e)
        {
            if (string.Compare(e.Command.CommandText, Config.Instance.Storage.StreamGames.Bankheist.General.Command) == 0)
            {
                // continue only if CooldownDatetime is null (never running) or cooldown is lower than Datetime.now
                if (_nextStartAfterCooldown == default(DateTime) || _nextStartAfterCooldown.TimeOfDay <= DateTime.Now.TimeOfDay)
                {
                    // check if chat argument is an integer
                    if (int.TryParse(e.Command.ArgumentsAsString, out int bankheistBet))
                    {
                        var userId = Convert.ToInt32(e.Command.ChatMessage.UserId);
                        // check if user has enough currency
                        if (_databaseCurrencyHandler.HasUserEnoughCurrency(userId, bankheistBet))
                        {
                            // first startup? then create userlist and writes in chat that Bankheist is started
                            if (_userList == null)
                            {
                                _userList = new List <Models.Streamgames.Bankheist.UserBetModel>();
                                WriteBankheistStartupInChat();
                                AddUserToList(userId, bankheistBet, e.Command.ChatMessage.DisplayName);
                                StartBankheistEndTimer();
                            }
                            else
                            {
                                // check if user is already in list
                                if (_userList.SingleOrDefault(u => u.TwitchID == userId) == null)
                                {
                                    AddUserToList(userId, bankheistBet, e.Command.ChatMessage.DisplayName);
                                }
                            }

                            _databaseCurrencyHandler.Remove.Remove(userId, bankheistBet);
                        }
                    }
                }
                else
                {
                    AivaClient.Instance.TwitchClient.SendMessage(
                        AivaClient.Instance.Channel,
                        "Bankheist is on cooldown!",
                        AivaClient.DryRun);
                }
            }
        }
Exemple #3
0
        private async void ChatCommandReceived(object sender, OnChatCommandReceivedArgs e)
        {
            if (!CheckCommand(e.Command.CommandText))
            {
                return;
            }

            // multi vote
            if (_properties.BlockMultiRegister)
            {
                if ((_registredUserIds.SingleOrDefault(u => u == Convert.ToInt32(e.Command.ChatMessage.UserId))) != 0)
                {
                    return;
                }
            }

            // join permission
            if (_properties.JoinPermission != Models.Enums.JoinPermission.Everyone)
            {
                if (_properties.JoinPermission == Models.Enums.JoinPermission.Subscriber)
                {
                    if (!e.Command.ChatMessage.IsSubscriber)
                    {
                        return;
                    }
                }

                if (_properties.JoinPermission == Models.Enums.JoinPermission.Moderation)
                {
                    if (!e.Command.ChatMessage.IsModerator)
                    {
                        return;
                    }
                }
            }

            // check follower
            if (_properties.BeFollower)
            {
                var isFollowing = await AivaClient.Instance.TwitchApi.Users.v5.UserFollowsChannelAsync(
                    userId : e.Command.ChatMessage.UserId,
                    channelId : AivaClient.Instance.ChannelId).ConfigureAwait(false);

                if (!isFollowing)
                {
                    return;
                }
            }

            // check currency
            if (_properties.IsCostEnabled)
            {
                var userId = Convert.ToInt32(e.Command.ChatMessage.UserId);
                if (!_databaseCurrencyHandler.HasUserEnoughCurrency(
                        twitchID: userId,
                        currencyToCheck: _properties.Cost))
                {
                    return;
                }
                else
                {
                    _databaseCurrencyHandler.Remove.Remove(
                        twitchID: userId,
                        value: _properties.Cost);
                }
            }

            ConfirmUserRegistration(e);
        }
Exemple #4
0
        /// <summary>
        /// Fires when a command was received
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void AddSongCommandReceived(object sender, OnChatCommandReceivedArgs e)
        {
            if (String.Compare(Properties.Command.TrimStart('!'), e.Command.CommandText, true) == 0)
            {
                // price
                if (Properties.IsCostEnabled)
                {
                    if (!_currencyDatabaseHandler.HasUserEnoughCurrency(
                            twitchID: Convert.ToInt32(e.Command.ChatMessage.UserId),
                            currencyToCheck: Properties.Cost))
                    {
                        return;
                    }
                }

                // permissions
                if (Properties.JoinPermission != Models.Enums.JoinPermission.Everyone)
                {
                    if (Properties.JoinPermission == Models.Enums.JoinPermission.Subscriber)
                    {
                        if (!e.Command.ChatMessage.IsSubscriber)
                        {
                            return;
                        }
                    }

                    if (Properties.JoinPermission == Models.Enums.JoinPermission.Moderation)
                    {
                        if (!e.Command.ChatMessage.IsModerator)
                        {
                            return;
                        }
                    }
                }

                // follower
                if (Properties.BeFollower)
                {
                    var followerCheck = await AivaClient.Instance.TwitchApi.Users.v5.UserFollowsChannelAsync(e.Command.ChatMessage.UserId, AivaClient.Instance.ChannelId).ConfigureAwait(false);

                    if (!followerCheck)
                    {
                        return;
                    }
                }

                // get song model
                var songModel = await GenerateSongModel(e.Command.ArgumentsAsString, e.Command.ChatMessage.DisplayName, Convert.ToInt32(e.Command.ChatMessage.UserId)).ConfigureAwait(false);

                // remove currency from user
                if (Properties.IsCostEnabled)
                {
                    _currencyDatabaseHandler.Remove.Remove(
                        Convert.ToInt32(e.Command.ChatMessage.UserId),
                        Properties.Cost);
                }

                // call song found
                OnNewSong?.Invoke(this, songModel);
            }
        }