Example #1
0
        public async Task StatsAsync(string commandName, string statsName)
        {
            SetMemberConfig(Context.User.Id);
            if (PersistenceService.AvailableStats.Contains(commandName))
            {
                await StatsAsync(commandName);

                return;
            }

            if (commandName.Trim().ToLower() != "reset")
            {
                await HandleErrorAsync(StatError.NoSuchCommand);

                return;
            }

            if (!PersistenceService.AvailableStats.Contains(statsName))
            {
                await HandleErrorAsync(StatError.NoSuchCommand);

                return;
            }

            PersistenceService.ClearUserRecord(statsName, Context.User.Id);
            await Context.Channel.SendMessageAsync(_userLocalization["clear_message"].ToString());
        }
Example #2
0
        public async Task StatsAsync(string commandName)
        {
            SetMemberConfig(Context.User.Id);

            if (commandName == "reset")
            {
                PersistenceService.ClearUserRecord(Context.User.Id);
                await Context.Channel.SendMessageAsync(_userLocalization["clear_message"].ToString());

                return;
            }

            if (!PersistenceService.AvailableStats.Contains(commandName))
            {
                await HandleErrorAsync(StatError.NoSuchCommand);

                return;
            }

            var msg = _userLocalization["result"].ToString()
                      .Replace("{user}", Context.User.Username)
                      .Replace("{command}", commandName);

            var embed = GetEmbeddedMessage(msg);

            var records = PersistenceService.GetUserRecord(commandName, Context.User.Id);

            if (records.First().Value is int || records.First().Value is double)
            {
                var orderedRecords = records.OrderByDescending(pair => (double)pair.Value);

                foreach (var record in orderedRecords)
                {
                    embed.Fields.Add(new EmbedFieldBuilder
                    {
                        IsInline = true,
                        Name     = $"**{record.Key}**",
                        Value    = record.Value
                    });
                }
            }
            else
            {
                foreach (var record in records)
                {
                    var field = new EmbedFieldBuilder
                    {
                        IsInline = true,
                        Name     = $"**{record.Key}**",
                        Value    = "- "
                    };

                    foreach (var ending in record.Value)
                    {
                        field.Value += $"__{ending.Key}__: {ending.Value}\n";
                    }

                    field.Value = field.Value.ToString().Replace("- ", string.Empty);

                    embed.Fields.Add(field);
                }
            }

            if (Helper.GetMemberConfig(Context.User.Id)?.Language == "jp")
            {
                msg.Replace("time(s)", "回");
            }

            await Context.Channel.SendMessageAsync(embed : embed.Build());
        }