Ejemplo n.º 1
0
        private Embed CreateEmbed(AnimeGuildModel agm, SocketMessage message)
        {
            var embedBuilder = new EmbedBuilder()
                               .WithTitle("Wow! You just subscribed to an anime!")
                               .WithAuthor(message.Author)
                               .WithDescription(
                $"When a new episode of {agm.AnimeTitle.EnglishTitle ?? agm.AnimeTitle.RomajiTitle} comes out, " +
                $"you will be notified 😉😉")
                               .WithFooter("Click the ❤️ to subscribe to this anime as well 😁!");


            var users = string.Join(" ", GetSubscribedUsers(agm.SubscribedUsers, message.Author.Id));

            if (string.IsNullOrEmpty(users))
            {
                users = "Hmmm... It's just you!";
            }
            embedBuilder.AddField(x =>
            {
                x.IsInline = true;
                x.Name     = "Also subscribed";
                x.Value    = $"{users}";
            });

            var a = agm.Anime;

            if (a.NextAiringEpisode?.AiringAt != null)
            {
                // ReSharper disable once PossibleInvalidOperationException
                int b = a.NextAiringEpisode.Value.AiringAt.Value;

                var dateTime = new DateTime(1970, 1, 1)
                               .AddSeconds(b);


                embedBuilder.AddField(x =>
                {
                    var e = a.NextAiringEpisode.Value.Episode;

                    x.IsInline = true;
                    x.Name     = $"Next Episode{(e.HasValue ? $": {e.Value.ToString()}" : "")}";
                    x.Value    = $"{dateTime.DayOfWeek.ToString()} ({dateTime.Day} " +
                                 $"{CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(dateTime.Month)})";
                });
            }

            return(embedBuilder.Build());
        }
        private static string GetImportantSubgroup(string s1, string s2, AnimeGuildModel m)
        {
            if (s1 == null)
            {
                return(s2);
            }
            if (s2 == null)
            {
                return(s1);
            }

            // if this is confusing, future me, this lowers all strings in the array
            int is1 = Array.IndexOf(m.WantedSubgroupTitle.Select(x => x.ToLower()).ToArray(), s1.ToLower());
            int is2 = Array.IndexOf(m.WantedSubgroupTitle.Select(x => x.ToLower()).ToArray(), s2.ToLower());

            is1 = is1 < 0 ? int.MaxValue : is1;
            is2 = is2 < 0 ? int.MaxValue : is2;

            return(is1 < is2 ? s1 : s2);
        }
Ejemplo n.º 3
0
        public static bool UnsubscribeFromAnime(ref AnimeGuildModel animeGuildModel, ulong userId)
        {
            animeGuildModel.SubscribedUsers =
                animeGuildModel.SubscribedUsers.ToList().Where(x => x != userId)
                .ToArray();

            var  c       = Database.GetDatabaseAndSubscriptionCollection();
            bool success = true;

            if (animeGuildModel.SubscribedUsers.Length == 0)
            {
                success = c.collection.Delete(animeGuildModel.Id);
            }
            else
            {
                success = c.collection.Update(animeGuildModel);
            }

            return(success);
        }
Ejemplo n.º 4
0
        public static bool SubscribeToAnime(ref AnimeGuildModel rAnimeGuildModel, ulong userId)
        {
            var c               = Database.GetDatabaseAndSubscriptionCollection();
            var agm             = rAnimeGuildModel;
            var animeguildmodel = c.collection
                                  .FindOne(x => x.Guild == agm.Guild && x.AnimeID == agm.AnimeID);

            bool success = true;

            // If the guild subscription does not exist,
            // create it.
            // otherwise, try to subscribe the current user to the anime.
            // if the user is already subscribed, this function will return false.
            // in any other cases, it will return true. (Even when it might have failed theoratically...)
            if (animeguildmodel == null)
            {
                agm.SubscribedUsers = new [] { userId };
                c.collection.Insert(agm);
            }
            else
            {
                rAnimeGuildModel = animeguildmodel;

                var subbedUsers = animeguildmodel.SubscribedUsers.ToList();
                if (subbedUsers.Contains(userId))
                {
                    success = false;
                }
                else
                {
                    subbedUsers.Add(userId);
                    animeguildmodel.SubscribedUsers = subbedUsers.ToArray();
                    c.collection.Update(animeguildmodel);
                }
            }

            return(success);
        }
 private static string GetMentions(AnimeGuildModel model)
 {
     return(model.SubscribedUsers.Aggregate("", (current, user) => current + $"<@{user}>"));
 }
Ejemplo n.º 6
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);
        }
Ejemplo n.º 7
0
 public static void AddQuoteWaiter(AnimeGuildModel model)
 {
     ResponseModule.ResponseModule.AddWaiter(new GuildUserWaiter(
                                                 model.Guild, 0, QuoteMessageReceived, WaitsForOwner: false, @params: model, DeleteOnSuccess: false));
 }