Exemplo n.º 1
0
        public async Task SubscribeToAnime([Remainder] string args)
        {
            if (Context.Guild == null)
            {
                return;
            }

            if (string.IsNullOrEmpty(args))
            {
                await ReplyAsync($"{Context.User.Mention}, uh... you didn't specify an anime. Please do so.");

                return;
            }

            // future proofing for the possibility for extra arguments.
            string anime = args;

            // search for the anime.
            AniListModel[] animeList = await AnilistRequest.FindAnime(anime);

            if (animeList.Length == 0)
            {
                return;
            }


            GuildUserWaiter guildUserWaiter = new GuildUserWaiter(Context.Guild.Id, Context.User.Id, WaiterFunction,
                                                                  animeList);

            guildUserWaiter.ParentMessage = Context.Message;

            var s = new StringBuilder("What anime?\n```Ini\n");

            for (int i = 0; i < animeList.Length; i++)
            {
                s.AppendLine($"{i + 1} \t= {animeList[i].Title.EnglishTitle ?? animeList[i].Title.RomajiTitle}");
            }

            s.AppendLine("```");

            IMessage msg = await ReplyAsync(s.ToString());

            guildUserWaiter.AddAssociatedMessage(msg);
            ResponseModule.ResponseModule.AddWaiter(guildUserWaiter);
        }
Exemplo n.º 2
0
        public async Task Unsub([Remainder] string text)
        {
            // This command can only be used within guilds.
            if (Context.Guild == null)
            {
                return;
            }

            if (string.IsNullOrEmpty(text))
            {
                await ReplyAsync($"{Context.User.Mention}, ばか.. what do you want to unsubscribe from?");

                return;
            }

            string anime = text.ToLower();

            // get all anime in this guild and from this user.
            var col = Database.Database.GetDatabaseAndSubscriptionCollection().collection;
            var asd = col.FindAll().ToList();
            var guildAnimeCollection = asd
                                       .Where(x =>
                                              x.Guild == Context.Guild.Id &&
                                              x.SubscribedUsers.Contains(Context.User.Id)
                                              ).ToList();

            if (guildAnimeCollection.Count == 0)
            {
                await ReplyAsync($"{Context.User.Mention}, you're not subscribed to any anime.");

                return;
            }

            // get the candidates
            var unsubCandidates = guildAnimeCollection.Where(x =>
                                                             (x.AnimeTitle.EnglishTitle ?? x.AnimeTitle.RomajiTitle).ToLower().Contains(anime))
                                  .Take(10).ToList();

            if (unsubCandidates.Count == 0)
            {
                await ReplyAsync($"{Context.User.Mention}, no anime found with that name.");

                return;
            }

            var guildUserWaiter =
                new GuildUserWaiter(Context.Guild.Id, Context.User.Id,
                                    UnsubscribeWaiter, unsubCandidates);

            guildUserWaiter.ParentMessage = Context.Message;

            var s = new StringBuilder("What anime?\n```Ini\n");

            for (int i = 0; i < unsubCandidates.Count; i++)
            {
                s.AppendLine(
                    $"{i + 1} \t= {unsubCandidates[i].AnimeTitle.EnglishTitle ?? unsubCandidates[i].AnimeTitle.RomajiTitle}");
            }

            s.AppendLine("```");

            var msg = await ReplyAsync(s.ToString());

            guildUserWaiter.AddAssociatedMessage(msg);
            ResponseModule.ResponseModule.AddWaiter(guildUserWaiter);
        }
Exemplo n.º 3
0
        private async Task <bool> WaiterFunction(SocketMessage message, object @params)
        {
            string content = message.Content;
            int    n;

            if (!int.TryParse(content, out n))
            {
                return(false);
            }
            if (!(@params is AniListModel[] animeList))
            {
                return(false);
            }
            if (n < 1 || n > animeList.Length + 1)
            {
                return(false);
            }

            n--;
            var anim = new AnimeGuildModel()
            {
                AnimeID              = animeList[n].ID,
                Anime                = animeList[n],
                AnimeTitle           = animeList[n].Title,
                Guild                = ((IGuildChannel)message.Channel).GuildId,
                Channel              = message.Channel.Id,
                MinAnnounceQuality   = Quality.SevenTwentyP,
                LastAnnouncedEpisode = 0,
                WantedSubgroupTitle  = new [] { "horriblesubs", "erai-raws" }
            };

            if (DatabaseSubscriber.SubscribeToAnime(ref anim, message.Author.Id))
            {
                Embed embed          = CreateEmbed(anim, message);
                var   succeedMessage = await ReplyAsync("", embed : embed);

                await succeedMessage.AddReactionAsync(new Emoji("❤"));

                var guildUserWaiter = new GuildUserWaiter(Context.Guild.Id, Context.User.Id,
                                                          async(messageId, reaction, anime) =>
                {
                    if (reaction.Emote.Name != "❤")
                    {
                        return(false);
                    }
                    var a = anim;
                    DatabaseSubscriber.SubscribeToAnime(ref a, reaction.UserId);
                    try
                    {
                        var e = CreateEmbed(a, message);
                        await succeedMessage.ModifyAsync(x => x.Embed = e);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e);
                    }

                    return(false);
                }, anim, false);

                guildUserWaiter.ParentMessage = succeedMessage;
                ResponseModule.ResponseModule.AddWaiter(guildUserWaiter);
            }
            else
            {
                await ReplyAsync($"{message.Author.Mention} ばか! (´-ω-`). You already subscribed to {anim.AnimeTitle.EnglishTitle ?? anim.AnimeTitle.RomajiTitle}.");
            }

            return(true);
        }