Example #1
0
        public async Task ProfileCommand([Remainder] SocketGuildUser user = null)
        {
            SocketGuildUser target;

            if (user != null)
            {
                target = user;
            }
            else
            {
                target = Context.User as SocketGuildUser;
            }

            var profile = await _userAccounts.GetAccountAsync(target);

            var embed = new EmbedBuilder
            {
                Title = string.IsNullOrEmpty(profile[AccountItem.WikidotUsername])
                    ? target?.Nickname ?? target?.Username
                    : $"{target?.Nickname ?? target?.Username} - {profile[AccountItem.WikidotUsername]}",
                ThumbnailUrl = target?.GetAvatarUrl(),
                Description  = profile.ToString()
            };

            if (profile[AccountItem.ProfileColor] != null)
            {
                embed.Color = new Color(Convert.ToUInt32(profile[AccountItem.ProfileColor].Remove(0, 1), 16));
            }

            await Context.Channel.SendMessageAsync(embed : embed.Build());
        }
Example #2
0
        public async Task AssignPointsCommand(PointType type)
        {
            if (!_authorizedUsers.Contains(Context.User.Id))
            {
                return;
            }

            // ReSharper disable once MethodHasAsyncOverload
            _webClient.DownloadFile(new Uri(Context.Message.Attachments.First().Url), "points");
            var file = await File.ReadAllLinesAsync("points");

            string typeString;
            string pattern;

            switch (type)
            {
            case PointType.Translation:
                pattern    = "([0-9]{18}),Bodů,(\"[0-9]*,[0-9]*|[0-9]*)";
                typeString = "Překladatelské";
                File.Move("points", "translation-points", true);
                break;

            case PointType.Writing:
                pattern    = "([0-9]{18}),([0-9]*)";
                typeString = "Spisovatelské";
                File.Move("points", "writing-points", true);
                break;

            case PointType.Correction:
                pattern    = "([0-9]{18});([0-9]*(,[0-9]*|))";
                typeString = "Korektorské";
                File.Move("points", "correction-points", true);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(type), type, null);
            }

            var matches      = file.Select(s => Regex.Match(s, pattern)).ToList();
            var changes      = new StringBuilder($"**{typeString.ToUpper()} BODY**\n\n");
            var numOfChanges = 0;

            foreach (var match in matches.Where(match => match.Success))
            {
                ulong id;
                float points;

                try
                {
                    id     = Convert.ToUInt64(match.Groups[1].Value);
                    points = SanitizePointValue(match.Groups[2].Value);
                }
                catch (InvalidOperationException)
                {
                    // Row was formatted weirdly or data couldn't be converted
                    // Either way we continue
                    continue;
                }

                var account = await _accounts.GetAccountAsync(id);

                if (type == PointType.Translation && account.Id == 227114285074087938)
                {
                    points = 999999;                                                                    // Utylike
                }
                // ReSharper disable once CompareOfFloatsByEqualityOperator
                if (account.Points[type] == points)
                {
                    continue;
                }

                changes.Append($"`{account.Id}` {account.Points[type]} -> {points}\n");
                account.Points[type] = points;
                numOfChanges++;
            }

            changes.Append($"\n{typeString} body aktualizovány u {numOfChanges} lidí. Díky, " +
                           $"{Context.User.Username} {_pairs.GetString("AGRLOVE_EMOTE")}");

            var message = changes.ToString();

            if (numOfChanges == 0)
            {
                message = "Nejspíš si mi nahrál špatný soubor. Podívej se a zkus to znovu!";
            }

            _logger.LogInformation("Updated points: {Message}", message);
            await _accounts.UpdateRanks(type);

            await ReplyAsync(message);

            if (!(_client.GetChannel(ulong.Parse(_pairs.GetString("LOGGING_CHANNEL_ID"))) is SocketTextChannel o5) ||
                numOfChanges == 0)
            {
                return;
            }
            await o5.SendMessageAsync(message);
        }