private async void WelcomeMessageCheck(object sender, OnMessageReceivedArgs e)
        {
            if (e.ChatMessage.Message.StartsWith("!"))
            {
                return;
            }
            if (_filterManager.CheckIfUserIdFiltered(e.ChatMessage.UserId))
            {
                return;
            }
            _talkerCounter.AddTalker(new UserBase(e.ChatMessage.DisplayName, e.ChatMessage.UserId));
            if (_presenceCounter.CheckIfPresent(e.ChatMessage.UserId))
            {
                return;
            }
            _presenceCounter.MakePresent(e.ChatMessage.UserId);
            var user = await _dataAccess.RetrieveUserFromTableAsync(DatabaseTables.UserPoints, e.ChatMessage.UserId).ConfigureAwait(false);

            if (user == null)
            {
                _twitchConnection.Client.SendMessage(e.ChatMessage.Channel,
                                                     $"/me Bine ai venit {e.ChatMessage.DisplayName}!");
                return;
            }

            if (!int.TryParse(user.Rank, out var userRank))
            {
                _twitchConnection.Client.SendMessage(e.ChatMessage.Channel,
                                                     "/me Could not parse rank. Send LOGS!");
                Log.Error("Could Not Parse Rank {rank}, {user}", userRank, user);
                return;
            }
            _twitchConnection.Client.SendMessage(e.ChatMessage.Channel,
                                                 $"/me Bine ai venit {_rankManager.GetRank(userRank).Name} {e.ChatMessage.DisplayName}!");
        }
        public async Task <string> ProcessorAsync(OnChatCommandReceivedArgs e)
        {
            if (string.IsNullOrEmpty(e.Command.ArgumentsAsString))
            {
                return("/me Nu ai introdus nici un item pentru giveaway!");
            }
            Log.Information("Giveaway started!");
            try
            {
                var userList = await _apiRetriever.GetChattersUsersAsync(_configuration.ChannelName).ConfigureAwait(false);

                userList.RemoveAll(x =>
                                   string.Equals(x.Name, _configuration.ChannelName, StringComparison.CurrentCultureIgnoreCase));
                var getDatabaseUsersTasks = new List <Task <IDatabaseUser> >();
                for (var i = 0; i < userList.Count; i++)
                {
                    if (!_filterManager.CheckIfUserIdFiltered(userList[i].Id))
                    {
                        getDatabaseUsersTasks.Add(
                            _dataAccess.RetrieveUserFromTableAsync(DatabaseTables.UserPoints, userList[i].Id));
                        continue;
                    }

                    userList.RemoveAll(x => x.Id == userList[i].Id);
                    i--;
                }

                var databaseUsers = (await Task.WhenAll(getDatabaseUsersTasks).ConfigureAwait(false)).ToList();
                databaseUsers.RemoveAll(x => x == null);

                var query =
                    from databaseUser in databaseUsers
                    join user in userList on databaseUser.UserId equals user.Id
                    where int.Parse(databaseUser.Rank) >= 2
                    select new UserStructureData(user.DisplayName, databaseUser.Id, user.Id, databaseUser.Points,
                                                 databaseUser.Minutes, databaseUser.Rank);
                var sourceAccounts = query.ToList();
                if (sourceAccounts.Count < 1)
                {
                    return("/me Nu exista oameni eligibili pentru giveaway");
                }

                var randomNumber = _random.Next(0, sourceAccounts.Count);
                var winner       =
                    $"/me {sourceAccounts[randomNumber].DisplayName} a castigat {e.Command.ArgumentsAsString}!";
                var builder = new StringBuilder();
                builder.Append("/me Inscrisi: ");
                foreach (var user in sourceAccounts)
                {
                    builder.AppendFormat("{0}, ", user.DisplayName);
                }

                Log.Information("Giveaway ran with success!");
                _twitchConnection.Client.SendMessage(e.Command.ChatMessage.Channel, builder.ToString());
                return(winner);
            }
            catch (Exception exception)
            {
                Log.Error(exception, "GiveawayCommand failed!");
                return("/me SORRY, GIVEAWAY FAILED, PLEASE TRY AGAIN LATER, also send logs, thx");
            }
        }
示例#3
0
        public async Task <string> ProcessorAsync(OnChatCommandReceivedArgs e)
        {
            if (e.Command.ArgumentsAsList.Count < 1)
            {
                return(StandardMessages.FilterFormat);
            }

            User user = null;

            if (e.Command.ArgumentsAsList.Count >= 2)
            {
                try
                {
                    user = await _apiRetriever.GetUserByUsernameAsync(e.Command.ArgumentsAsList[1])
                           .ConfigureAwait(false);
                }
                catch (Exception exception)
                {
                    Log.Error(exception.Message, "Bad request {parameter}", e.Command.ArgumentsAsString);
                    return(String.Format(StandardMessages.ErrorMessages.InvalidName, e.Command.ArgumentsAsList[1]));
                }

                if (user == null)
                {
                    return(String.Format(StandardMessages.ErrorMessages.UserMissing, e.Command.ArgumentsAsList[1]));
                }
            }

            switch (e.Command.ArgumentsAsList[0])
            {
            case "get":
            {
                if (user != null)
                {
                    if (_filterManager.CheckIfUserIdFiltered(user.Id))
                    {
                        return($"/me {user.DisplayName} este filtrat!");
                    }
                    return($"/me {user.DisplayName} nu este filtrat!");
                }

                var filteredUsers = _filterManager.RetrieveFilteredUsers();
                if (filteredUsers.Count <= 0)
                {
                    return("/me Nici un User filtrat!");
                }
                var builder = new StringBuilder();
                builder.Append("Useri filtrati:");
                for (var i = 0; i < filteredUsers.Count; i++)
                {
                    builder.Append($" {filteredUsers[i].DisplayName},");
                }
                return($"/me {builder}");
            }

            case "add":
            {
                if (user == null)
                {
                    return(StandardMessages.FilterFormat);
                }
                if (await _filterManager.AddToFilterAsync(new UserBase(user.DisplayName, user.Id))
                    .ConfigureAwait(false))
                {
                    return($"/me {user.DisplayName} adaugat la Filtru!");
                }
                return($"/me {user.DisplayName} deja in Filtru!");
            }

            case "rem":
            case "remove":
            {
                if (user == null)
                {
                    return(StandardMessages.FilterFormat);
                }
                if (await _filterManager.RemoveFromFilterAsync(new UserBase(user.DisplayName, user.Id))
                    .ConfigureAwait(false))
                {
                    return($"/me {user.DisplayName} sters din Filtru!");
                }
                return($"/me {user.DisplayName} nu este in Filtru!");
            }

            default:
                return(StandardMessages.FilterFormat);
            }
        }