示例#1
0
        public async Task Top(
            [Summary("The type of the chart. Either albums or artists.")]
            ChartType type,
            [Summary("The time span for the chart. Overall, year, 6month, 3month, month or week.")]
            string span,
            [OverrideTypeReader(typeof(ChartSizeReader))][Summary("Chart size. Supported sizes are 3x3, 4x4 and 5x5.")]
            ChartSize size,
            [Summary(
                 "Pass this argument if you want to include names next to your chart. Accepted values are `-c` and `-t`. Currently there is no difference between them.")]
            string caption = "")
        {
            if (!await Preconditions.Preconditions.InChartposting(Context))
            {
                return;
            }

            var user = await FindUserAsync();

            if (user.LastFm == null)
            {
                await Error("You'll need to link your last.fm profile first.");
            }

            caption = caption.ToLowerInvariant();
            var withCaption = caption == "captions" || caption == "-c" || caption == "-t" || caption == "titles";

            var result = await chartService.GetChartAsync(size, type, user.LastFm, span, withCaption);

            if (result == null)
            {
                await Error(
                    "Something went wrong obtaining the chart information. Check the given parameters and try again");

                return;
            }

            using (Stream stream = new MemoryStream(result))
            {
                await Context.Channel.SendFileAsync(
                    stream,
                    $"{Context.User.Username}_top_{type}_{size}.png",
                    $"Top {type.ToString().ToLowerInvariant()} for {Context.User.Username}:");
            }
        }