Пример #1
0
        public async Task User(CommandContext ctx, [Description("Никнейм пользователя")] string nickname)
        {
            var user = await db.GetUser(ctx.User.Id.ToString());

            if (user == null)
            {
                await ctx.RespondAsync($"{ctx.Message.Author.Mention}\nДля этого тебе нужно авторизоваться!\n\nОтправь команду `!shiki auth` и выполни полученные инструкции.");

                return;
            }

            var found = await api.SearchUser(nickname, user.AccessToken);

            if (found.StatusCode == HttpStatusCode.Unauthorized)
            {
                await CommandsHelper.UpdateTokens(user.ClientId, user.RefreshToken, db);

                user = await db.GetUser(ctx.User.Id.ToString());

                found = await api.SearchUser(nickname, user.AccessToken);
            }

            if (found.StatusCode == HttpStatusCode.NotFound)
            {
                var notFoundEmbed = CommandsHelper.BuildNotFoundEmbed();
                await ctx.RespondAsync(embed : notFoundEmbed);

                return;
            }

            var embed = CommandsHelper.BuildUserInfoEmbed(found.Content);
            await ctx.RespondAsync(embed : embed);
        }
Пример #2
0
        public async Task Hi(CommandContext ctx, [Description("Тип искомого контента (anime / ranobe / manga)")] string type, [Description("Название искомого контента")] string title)
        {
            if (!CommandsHelper.TitleSearchTypes.Contains(type))
            {
                await ctx.RespondAsync("Неизвестный тип контента.\nОтправьте `!shiki help` чтобы посмотреть список комманд.");

                return;
            }

            var user = await db.GetUser(ctx.User.Id.ToString());

            if (user == null)
            {
                await ctx.RespondAsync($"{ctx.Message.Author.Mention}\nДля этого тебе нужно авторизоваться!\n\nОтправь команду `!shiki auth` и выполни полученные инструкции.");

                return;
            }

            var found = await api.SearchTitleByQuery(type, title, user.AccessToken);

            if (found.StatusCode == HttpStatusCode.Unauthorized)
            {
                await CommandsHelper.UpdateTokens(user.ClientId, user.RefreshToken, db);

                user = await db.GetUser(ctx.User.Id.ToString());

                found = await api.SearchTitleByQuery(type, title, user.AccessToken);
            }

            Dictionary <int, TitleInfo> mappedTitles = new Dictionary <int, TitleInfo>();

            for (int idx = 0; idx < found.Content.Count; idx++)
            {
                mappedTitles.Add(idx + 1, found.Content[idx]);
            }

            if (mappedTitles.Count == 0)
            {
                var notFoundEmbed = CommandsHelper.BuildNotFoundEmbed();
                await ctx.RespondAsync(embed : notFoundEmbed);

                return;
            }

            var resultsEmbed = CommandsHelper.BuildTitleListEmbed(mappedTitles);
            await ctx.RespondAsync(embed : resultsEmbed);

            var interactivity = ctx.Client.GetInteractivityModule();
            int titleIndex    = 0;

            do
            {
                var choice = await interactivity.WaitForMessageAsync(m => m.Author.Id == ctx.User.Id, TimeSpan.FromMinutes(1));

                if (choice == null)
                {
                    await ctx.RespondAsync("Я устал ждать... Увидимся позже.");

                    return;
                }

                try {
                    titleIndex = Convert.ToInt32(choice.Message.Content);
                } catch (FormatException) {
                    continue;
                }


                if (titleIndex < 1 || titleIndex > BotConfig.SearchLimit)
                {
                    continue;
                }
            } while (titleIndex < 1 || titleIndex > BotConfig.SearchLimit);


            var response = await api.SearchTitleById(type, mappedTitles[titleIndex].id);

            var embed = CommandsHelper.BuildTitleEmbed(response.Content, type);

            await ctx.RespondAsync(embed : embed);
        }