Beispiel #1
0
        private async Task HandleMessageAsync(SocketMessage message)
        {
            if (!CommandUtilities.HasPrefix(message.Content, config["prefix"], StringComparison.OrdinalIgnoreCase, out string output))
            {
                return;
            }
            if (!(message.Channel is SocketTextChannel textChannel) || !(message.Author is SocketGuildUser guildUser))
            {
                await message.Channel.SendMessageAsync(embed : EmbedUtils.UnsupportedEnvironment);

                return;
            }
            if (!guildUser.Guild.CurrentUser.GetPermissions(textChannel).SendMessages)
            {
                return;
            }

            var context = new ScrapContext(client, message as SocketUserMessage, provider);
            var result  = await commands.ExecuteAsync(output, context);

            if (!(result is FailedResult failedResult))
            {
                return;
            }
            if (failedResult is CommandNotFoundResult)
            {
                return;
            }

            await message.Channel.SendMessageAsync(embed : EmbedUtils.FailedResultEmbed(failedResult));
        }
Beispiel #2
0
        public static async Task <bool> RunHardChecksAsync(this Module module, ScrapContext context)
        {
            var checks = module.Checks
                         .Where(x => x is HardCheckAttribute)
                         .Select(x => x as HardCheckAttribute).ToList();

            var checkResults = await Task.WhenAll(checks.Select(x => x.CheckAsync(context).AsTask()));

            return(!checkResults.Any(x => !x.IsSuccessful));
        }
Beispiel #3
0
        public static async Task <bool> RunSoftChecksAsync(this Command command, ScrapContext context)
        {
            var checks = command.Checks
                         .Where(x => x is SoftCheckAttribute)
                         .Select(x => x as SoftCheckAttribute).ToList();

            var checkResults = await Task.WhenAll(checks.Select(x => x.CheckAsync(context).AsTask()));

            return(checkResults.Any(x => !x.IsSuccessful));
        }
Beispiel #4
0
        //public ActionResult IndexResource()
        //{
        //    return View();
        //}

        //public ActionResult Files()
        //{
        //    return View();
        //}


        //prueba Scraping
        private String getScrapData(ClimaticPublication pub)
        {
            string userIpAddress = this.Request.UserHostAddress;

            //return ScrapContext.loadScrapByPubID(pubID);
            try
            {
                String href = "";
                if (pub.nodeIndex > 0)
                {
                    href = ScrapContext.scrapPubByPubIndex(pub.source, pub.nodeIndex, pub.tagType);
                }
                else
                {
                    switch (pub.idPublication)
                    {
                    case 26:
                        href = ScrapContext.scrap26anomSST();
                        break;

                    case 29:
                        href = ScrapContext.scrap29anomDepth();
                        break;

                    //ENOS plumas
                    case 66:
                        href = ScrapContext.scrapInGroup(pub.idPublication, pub.source);
                        break;

                    case 67:
                        href = ScrapContext.scrapInGroup(pub.idPublication, pub.source);
                        break;

                    default:
                        break;
                    }
                }
                return(href);
            }
            catch (Exception ex)
            {
                DBcontext.setPiactProblem(ex.Message, ex.StackTrace, userIpAddress, "IP", "BETA");
                return("Server error");
            }
        }
        public async Task <string> PreRequestAsync(string uri = null)
        {
            if (string.IsNullOrWhiteSpace(uri))
            {
                return("uri is null or empty");
            }

            try
            {
                var baseAddress = new Uri(uri ?? DefaultUrl);
                //var handler = new HttpClientHandler
                //{
                //    UseCookies = true
                //};

                //_httpClient = _httpClient ?? new HttpClient(handler)
                //{
                //    BaseAddress = baseAddress
                //};
                _httpClient.BaseAddress = baseAddress;

                var message = new HttpRequestMessage(HttpMethod.Get, "/");
                message.Headers.Add("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/22.0.1207.1 Safari/537.1");

                _scrapContext = new ScrapContext
                {
                    Message = message
                };

                return("OK");
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
        }