public override async Task InvokeAsync(CommandContext ctx, string[] args)
        {
            if (args.Length < 1)
            {
                await ctx.ReplyAsync(Util.GenerateInvalidUsage(ctx.Bot, this));

                return;
            }

            string animeName = String.Join(' ', args);

            if (animeName.Length < 4)
            {
                await ctx.ReplyAsync("Please have your search query be more than four characters long.");

                return;
            }

            var client = new MalClient(ctx.Bot.Configuration.MALUsername, ctx.Bot.Configuration.MALPassword);

            MALAnimeEntry entry;

            try { entry = await client.FirstAnimeAsync(animeName); }
            catch (HttpRequestException e)
            {
                Console.WriteLine(e.ToString());
                await ctx.ReplyAsync("The request to the API failed. Looks like the service might be down, try again later.");

                return;
            }

            if (entry == null)
            {
                await ctx.ReplyAsync("No results were found for your query.");

                return;
            }

            string desc = Util.BBCodeToMarkdown(HttpUtility.HtmlDecode(Regex.Replace(entry.Synopsis, @"<(?:[^>=]|='[^']*'|=""[^""]*""|=[^'""][^\s>]*)*>", "")));

            EmbedBuilder embed = new EmbedBuilder
            {
                Color        = Util.CyanColor,
                Title        = entry.Title,
                Description  = desc.Length > 2000 ? desc.Substring(0, 1996) + "..." : desc,
                ThumbnailUrl = entry.Image
            };

            embed.AddField("Rating", entry.Score);
            embed.AddField("Episodes", entry.Episodes == 0 ? "Unknown" : entry.Episodes.ToString());
            embed.AddField("Type", entry.Type);
            embed.AddField("Status", entry.Status);
            embed.AddField("Started Airing", entry.StartDate == "0000-00-00" ? "N/A" : entry.StartDate);
            embed.AddField("Ended Airing", entry.EndDate == "0000-00-00" ? "N/A" : entry.EndDate);
            embed.WithFooter("https://myanimelist.net", "https://i.imgur.com/DcMFqr6.jpg");

            await ctx.ReplyAsync(embed.Build());
        }
Esempio n. 2
0
        /// <summary>
        /// Instantiates the MALUser class
        /// </summary>
        /// <param name="client">Web Client object that will hadle the request</param>
        public MALUser(object client)
        {
            userID = null;
            isAuthenticated = false;

            // Assign verification url
            verificationUrl = "http://myanimelist.net/api/account/verify_credentials.xml";

            malClient = client as MalClient;
        }
        public static async Task <string> Query(string queryString, MalClient client)
        {
            var resp = await client.HttpClient.GetStreamAsync(queryString);

            // Get response string
            var reader     = new StreamReader(resp);
            var respString = reader.ReadToEnd();

            return(respString);
        }
Esempio n. 4
0
        public static async Task<string> Query(string queryString, MalClient client)
        {
            var resp = await client.HttpClient.GetStreamAsync(queryString);

            // Get response string
            var reader = new StreamReader(resp);
            var respString = reader.ReadToEnd();

            return respString;
        }
Esempio n. 5
0
        /// <summary>
        /// Instantiates the MALUser class
        /// </summary>
        /// <param name="client">Web Client object that will hadle the request</param>
        public MALUser(object client)
        {
            userID          = null;
            isAuthenticated = false;

            // Assign verification url
            verificationUrl = "http://myanimelist.net/api/account/verify_credentials.xml";

            malClient = client as MalClient;
        }
Esempio n. 6
0
        /// <summary>
        /// Instantiates the MALUser class
        /// </summary>
        /// <param name="uName">User name for the authenticating user</param>
        /// <param name="pw">Password for the authenticating user</param>
        /// <param name="client">Web Client object that will hadle the request</param>
        public MALUser(string uName, string pw, object client)
        {
            userName = uName;
            password = pw;
            userID = null;
            isAuthenticated = false;

            // Assign verification url
            verificationUrl = "http://myanimelist.net/api/account/verify_credentials.xml";

            malClient = client as MalClient;
            AuthenticateUser();     // Authenticate user
        }
Esempio n. 7
0
        /// <summary>
        /// Instantiates the MALUser class
        /// </summary>
        /// <param name="uName">User name for the authenticating user</param>
        /// <param name="pw">Password for the authenticating user</param>
        /// <param name="client">Web Client object that will hadle the request</param>
        public MALUser(string uName, string pw, object client)
        {
            userName        = uName;
            password        = pw;
            userID          = null;
            isAuthenticated = false;

            // Assign verification url
            verificationUrl = "http://myanimelist.net/api/account/verify_credentials.xml";

            malClient = client as MalClient;
            AuthenticateUser();     // Authenticate user
        }
Esempio n. 8
0
        public async Task SearchMalAnimeAsync([Summary("Title to search")][Remainder] string name = "Azur Lane")
        {
            Logger.LogInfo($"Searching for {name} on myanimelist");

            ulong[] ids = await MalClient.GetAnimeIdAsync(name);

            AnimeResult[] resultCache = new AnimeResult[ids.Length];

            await PaginatedMessageService.SendPaginatedDataAsyncMessageAsync(Context.Channel, ids, async (ulong id, int index, EmbedFooterBuilder footer) => {
                if (resultCache[index].MalId != 0)
                {
                    return(GetAnimeResultEmbed(resultCache[index], index, footer));
                }
                else
                {
                    AnimeResult result = resultCache[index] = await MalClient.GetDetailedAnimeResultsAsync(id);
                    return(GetAnimeResultEmbed(result, index, footer));
                }
            });
        }
        public override async Task InvokeAsync(CommandContext ctx, string[] args)
        {
            if (args.Length < 1)
            {
                await ctx.ReplyAsync(Util.GenerateInvalidUsage(ctx.Bot, this));

                return;
            }

            string animeName = String.Join(' ', args);

            if (animeName.Length < 4)
            {
                await ctx.ReplyAsync("Please have your search query be more than four characters long.");

                return;
            }

            MalClient m = new MalClient(ctx.Bot.Configuration.MALUsername, ctx.Bot.Configuration.MALPassword);

            MALAnimeEntry anime = await m.FirstAnimeAsync(animeName);

            if (anime == null)
            {
                await ctx.ReplyAsync("We couldn't find that anime in the MAL database. Try an alternate name.");

                return;
            }

            var client = new TwistClient(ctx.DbContext);

            TwistEntry entry = await client.GetEntryAsync(anime.Id) ?? await client.GetEntryAsync(anime.Title);

            EmbedBuilder embed;

            if (entry == null)
            {
                embed = new EmbedBuilder
                {
                    Title        = "Anime Not Found",
                    Color        = Util.CyanColor,
                    ThumbnailUrl = anime.Image,
                    Description  = $"*{anime.Title}* wasn't found on twist.moe. Some possible alternate sources are listed below for your convenience."
                };

                embed.AddField("Alternate Sources", $"[Nyaa](https://nyaa.pantsu.cat/search?c=_&userID=0&q={WebUtility.UrlEncode(anime.Title)})\n[KissAnime](http://kissanime.ru/Search/Anime?keyword={WebUtility.UrlEncode(anime.Title)})");

                await ctx.ReplyAsync(embed.Build());

                return;
            }

            string desc = Util.BBCodeToMarkdown(HttpUtility.HtmlDecode(Regex.Replace(anime.Synopsis, @"<(?:[^>=]|='[^']*'|=""[^""]*""|=[^'""][^\s>]*)*>", "")));

            embed = new EmbedBuilder
            {
                Title        = entry.Url,
                Url          = entry.Url,
                ThumbnailUrl = anime.Image,
                Color        = Util.CyanColor,
                Description  = $"A stream was located for *{anime.Title}* on twist.moe. Click the link above to continue.\n\n[MAL Entry](https://myanimelist.net/anime/{anime.Id}/)"
            };
            embed.AddField("Description", desc.Length > 1024 ? desc.Substring(0, 1021) + "..." : desc);
            embed.WithFooter("https://twist.moe", "https://twist.moe/public/icons/fav_x16.png");

            await ctx.ReplyAsync(embed.Build());
        }
Esempio n. 10
0
 public AnimeListManager(MalClient client)
 {
     malClient = client;
 }
Esempio n. 11
0
 public AnimeListManager(MalClient client)
 {
     malClient = client;
 }
Esempio n. 12
0
        private async Task MainAsync(string[] args, ILogger logger)
        {
            this.logger = logger;
            this.args   = args;
            logger.Information("[Geekbot] Initing Stuff");

            client = new DiscordSocketClient(new DiscordSocketConfig
            {
                LogLevel            = LogSeverity.Verbose,
                MessageCacheSize    = 1000,
                AlwaysDownloadUsers = true
            });
            client.Log += DiscordLogger;
            commands    = new CommandService();

            try
            {
                var redisMultiplexer = ConnectionMultiplexer.Connect("127.0.0.1:6379");
                redis = redisMultiplexer.GetDatabase(6);
                logger.Information($"[Redis] Connected to db {redis.Database}");
            }
            catch (Exception e)
            {
                logger.Fatal(e, "[Redis] Redis Connection Failed");
                Environment.Exit(102);
            }

            if (args.Contains("--migrate"))
            {
                Console.WriteLine("\nYou are about to migrate the database, this will overwrite an already migrated database?");
                Console.Write("Are you sure [y:N]: ");
                var migrateDbConfirm = Console.ReadKey();
                Console.WriteLine();
                if (migrateDbConfirm.Key == ConsoleKey.Y)
                {
                    logger.Warning("[Geekbot] Starting Migration");
                    await DbMigration.MigrateDatabaseToHash(redis, logger);

                    logger.Warning("[Geekbot] Finished Migration");
                }
                else
                {
                    logger.Information("[Geekbot] Not Migrating db");
                }
            }

            token = redis.StringGet("discordToken");
            if (token.IsNullOrEmpty)
            {
                Console.Write("Your bot Token: ");
                var newToken = Console.ReadLine();
                redis.StringSet("discordToken", newToken);
                redis.StringSet("Game", "Ping Pong");
                token      = newToken;
                firstStart = true;
            }

            services = new ServiceCollection();

            userRepository = new UserRepository(redis, logger);
            var errorHandler  = new ErrorHandler(logger);
            var RandomClient  = new Random();
            var fortunes      = new FortunesProvider(RandomClient, logger);
            var checkEmImages = new CheckEmImageProvider(RandomClient, logger);
            var pandaImages   = new PandaProvider(RandomClient, logger);
            var malClient     = new MalClient(redis, logger);

            services.AddSingleton <IErrorHandler>(errorHandler);
            services.AddSingleton(redis);
            services.AddSingleton <ILogger>(logger);
            services.AddSingleton <IUserRepository>(userRepository);
            services.AddSingleton(RandomClient);
            services.AddSingleton <IFortunesProvider>(fortunes);
            services.AddSingleton <ICheckEmImageProvider>(checkEmImages);
            services.AddSingleton <IPandaProvider>(pandaImages);
            services.AddSingleton <IMalClient>(malClient);

            logger.Information("[Geekbot] Connecting to Discord");

            await Login();

            await Task.Delay(-1);
        }