示例#1
0
        public SpamScanner(SpamBlock sender)
        {
            Regex rex;

            FindLevel = LevelMatches.Alert;
            foreach (string s in sender.alert_strings)
            {
                if (sender.CompositionTypes.Exists(x => x == TelegramDataTypes.Text))
                {
                    scan_matches.AddRange(Find(s, sender.IncUpdate.message.text, PlaceMatches.MessageText));
                }
                if (sender.CompositionTypes.Exists(x => x == TelegramDataTypes.Caption))
                {
                    scan_matches.AddRange(Find(s, sender.IncUpdate.message.caption, PlaceMatches.Caption));
                }
            }

            foreach (string r in sender.alert_regexes)
            {
                rex = new Regex(r, RegexOptions.IgnoreCase);
                if (sender.CompositionTypes.Exists(x => x == TelegramDataTypes.Text))
                {
                    scan_matches.AddRange(Find(rex, sender.IncUpdate.message.text, PlaceMatches.MessageText));
                }
                if (sender.CompositionTypes.Exists(x => x == TelegramDataTypes.Caption))
                {
                    scan_matches.AddRange(Find(rex, sender.IncUpdate.message.caption, PlaceMatches.Caption));
                }
            }

            //////////////////////////////////////////////////////
            FindLevel = LevelMatches.Block;
            foreach (string s in sender.block_strings)
            {
                if (sender.CompositionTypes.Exists(x => x == TelegramDataTypes.Text))
                {
                    scan_matches.AddRange(Find(s, sender.IncUpdate.message.text, PlaceMatches.MessageText));
                }
                if (sender.CompositionTypes.Exists(x => x == TelegramDataTypes.Caption))
                {
                    scan_matches.AddRange(Find(s, sender.IncUpdate.message.caption, PlaceMatches.Caption));
                }
            }

            foreach (string r in sender.block_regexes)
            {
                rex = new Regex(r, RegexOptions.IgnoreCase);
                if (sender.CompositionTypes.Exists(x => x == TelegramDataTypes.Text))
                {
                    scan_matches.AddRange(Find(rex, sender.IncUpdate.message.text, PlaceMatches.MessageText));
                }
                if (sender.CompositionTypes.Exists(x => x == TelegramDataTypes.Caption))
                {
                    scan_matches.AddRange(Find(rex, sender.IncUpdate.message.caption, PlaceMatches.Caption));
                }
            }
        }
示例#2
0
        static void Main(string[] args)
        {
            Log.WriteLine("Hello World!");
            List <IncomingArgsClass> arg_parser = new ParserArguments().Parse(args);

            if (!arg_parser.Exists(x => x.name_argument.ToLower() == "api_key_telegram_bot"))
            {
                Log.WriteLine("Отсутсвует API Telegram auth key", LogStatusEnum.Alarm);
                return;
            }

            anti_spam = new SpamBlock(arg_parser.SingleOrDefault(x => x.name_argument.ToLower() == "api_key_telegram_bot").value_argument);

            if (anti_spam.telegram_client.Me is null)
            {
                Log.WriteLine("Telegram бот не запущен. Проверьте подключение к интернету и api_key_telegram_bot", LogStatusEnum.Alarm);
                return;
            }

            if (arg_parser.Exists(x => x.name_argument.ToLower() == "bot_admin_username"))
            {
                anti_spam.BotAdminUsername = arg_parser.SingleOrDefault(x => x.name_argument.ToLower() == "bot_admin_username").value_argument;
                Log.WriteLine("bot_admin_username="******"Отсутсвует bot_admin_username. Некому управлять ботом в режиме Online", LogStatusEnum.Notice);
            }

            if (
                arg_parser.Exists(x => x.name_argument.ToLower() == "webhook_api_url") &&
                arg_parser.Exists(x => x.name_argument.ToLower() == "hmac_sign_key") &&
                arg_parser.Exists(x => x.name_argument.ToLower() == "hmac_sign_secret"))
            {
                anti_spam.SetWebhook(arg_parser.SingleOrDefault(x => x.name_argument.ToLower() == "webhook_api_url").value_argument, arg_parser.SingleOrDefault(x => x.name_argument.ToLower() == "hmac_sign_key").value_argument, arg_parser.SingleOrDefault(x => x.name_argument.ToLower() == "hmac_sign_secret").value_argument);
                Log.WriteLine("Установлен Webhook/HMAC > " + anti_spam.WebhookAddress, LogStatusEnum.Norma);
            }

            foreach (IncomingArgsClass arg in arg_parser.Where(x => x.name_argument.ToLower() == "block_text"))
            {
                anti_spam.block_strings.Add(arg.value_argument);
            }

            foreach (IncomingArgsClass arg in arg_parser.Where(x => x.name_argument.ToLower() == "block_regex"))
            {
                anti_spam.block_regexes.Add(arg.value_argument);
            }

            foreach (IncomingArgsClass arg in arg_parser.Where(x => x.name_argument.ToLower() == "alert_text"))
            {
                anti_spam.alert_strings.Add(arg.value_argument);
            }

            foreach (IncomingArgsClass arg in arg_parser.Where(x => x.name_argument.ToLower() == "alert_regex"))
            {
                anti_spam.alert_regexes.Add(arg.value_argument);
            }

            Check_telegram();
            Log.WriteLine("Завершение работы", LogStatusEnum.Trace);
            Environment.Exit(1);
        }