예제 #1
0
 public WordFilterController(
     WordFilterService wordFilterService,
     QueryService queryService
     )
 {
     _wordFilterService = wordFilterService;
 }
        public override async Task HandleAsync(IUpdateContext context, UpdateDelegate next, string[] args,
                                               CancellationToken cancellationToken)
        {
            _requestProvider   = new RequestProvider(context);
            _wordFilterService = new WordFilterService(context.Update.Message);

            var msg           = context.Update.Message;
            var cleanedMsg    = msg.Text.GetTextWithoutCmd();
            var partedMsg     = cleanedMsg.Split(" ");
            var paramOption   = partedMsg.ValueOfIndex(1);
            var word          = partedMsg.ValueOfIndex(0);
            var isGlobalBlock = false;

            var isSudoer = _requestProvider.IsSudoer();
            var isAdmin  = await _requestProvider.IsAdminGroup();

            if (isSudoer || isAdmin)
            {
                var where = new Dictionary <string, object>()
                {
                    { "word", word }
                };

                if (paramOption == "-g" && isSudoer)
                {
                    isGlobalBlock = true;
                    await _requestProvider.SendTextAsync("Kata ini akan di blokir dengan mode Group-wide!");
                }

                if (!isSudoer)
                {
                    await _requestProvider.SendTextAsync("Hanya Sudoer yang dapat memblokir Kata mode Group-wide!");
                }

                if (paramOption != "-g")
                {
                    where.Add("chat_id", msg.Chat.Id);
                }

                if (word != "")
                {
                    var isExist = await _wordFilterService.IsExistAsync(where);

                    if (!isExist)
                    {
                        var save = await _wordFilterService.SaveWordAsync(word, isGlobalBlock);

                        await _requestProvider.SendTextAsync(save.ToJson());
                    }
                    else
                    {
                        await _requestProvider.SendTextAsync("Sudah");
                    }
                }
                else
                {
                    await _requestProvider.SendTextAsync("Apa kata?");
                }
            }
        }
예제 #3
0
 public KataSyncCommand(
     TelegramService telegramService,
     WordFilterService wordFilterService
     )
 {
     _telegramService   = telegramService;
     _wordFilterService = wordFilterService;
 }
예제 #4
0
 public DeleteKataCommand(
     ILogger logger,
     TelegramService telegramService,
     WordFilterService wordFilterService
     )
 {
     _logger            = logger;
     _telegramService   = telegramService;
     _wordFilterService = wordFilterService;
 }
예제 #5
0
 /// <summary>
 /// Instantiate UpdateHandler
 /// </summary>
 /// <param name="logger"></param>
 /// <param name="chatRestrictionModule"></param>
 /// <param name="antiSpamService"></param>
 /// <param name="settingsService"></param>
 /// <param name="wordFilterService"></param>
 public UpdateHandler(
     ILogger <UpdateHandler> logger,
     ChatRestrictionModule chatRestrictionModule,
     AntiSpamService antiSpamService,
     SettingsService settingsService,
     WordFilterService wordFilterService
     )
 {
     _logger = logger;
     _chatRestrictionModule = chatRestrictionModule;
     _antiSpamService       = antiSpamService;
     _settingsService       = settingsService;
     _wordFilterService     = wordFilterService;
 }
예제 #6
0
 public WordFilterController(WordFilterService wordFilterService)
 {
     this.wordFilterService = wordFilterService;
 }
예제 #7
0
        public override async Task HandleAsync(IUpdateContext context, UpdateDelegate next, string[] args,
                                               CancellationToken cancellationToken)
        {
            _telegramService   = new TelegramService(context);
            _wordFilterService = new WordFilterService(context.Update.Message);

            var msg           = context.Update.Message;
            var cleanedMsg    = msg.Text.GetTextWithoutCmd();
            var partedMsg     = cleanedMsg.Split(" ");
            var paramOption   = partedMsg.ValueOfIndex(1) ?? "";
            var word          = partedMsg.ValueOfIndex(0);
            var isGlobalBlock = false;

            var isSudoer = _telegramService.IsSudoer();
            var isAdmin  = await _telegramService.IsAdminGroup()
                           .ConfigureAwait(false);

            if (!isSudoer && !isAdmin)
            {
                return;
            }

            if (word.IsValidUrl())
            {
                word = word.ParseUrl().Path;
            }

            var where = new Dictionary <string, object>()
            {
                { "word", word }
            };

            if (paramOption.IsContains("-"))
            {
                if (paramOption.IsContains("g") && isSudoer) // Global
                {
                    isGlobalBlock = true;
                    await _telegramService.AppendTextAsync("Kata ini akan di blokir Global!")
                    .ConfigureAwait(false);
                }

                if (paramOption.IsContains("d"))
                {
                }

                if (paramOption.IsContains("c"))
                {
                }
            }

            if (!paramOption.IsContains("g"))
            {
                @where.Add("chat_id", msg.Chat.Id);
            }

            if (!isSudoer)
            {
                await _telegramService.AppendTextAsync("Hanya Sudoer yang dapat memblokir Kata mode Group-wide!")
                .ConfigureAwait(false);
            }

            if (word.IsNotNullOrEmpty())
            {
                await _telegramService.AppendTextAsync("Sedang menambahkan kata")
                .ConfigureAwait(false);

                var isExist = await _wordFilterService.IsExistAsync(@where)
                              .ConfigureAwait(false);

                if (!isExist)
                {
                    var save = await _wordFilterService.SaveWordAsync(word, isGlobalBlock)
                               .ConfigureAwait(false);

                    await _telegramService.AppendTextAsync("Kata berhasil di tambahkan")
                    .ConfigureAwait(false);
                }
                else
                {
                    await _telegramService.AppendTextAsync("Kata sudah di tambahkan")
                    .ConfigureAwait(false);
                }
            }
            else
            {
                await _telegramService.SendTextAsync("Apa kata yg mau di blok?")
                .ConfigureAwait(false);
            }

            await _telegramService.DeleteAsync(delay : 3000)
            .ConfigureAwait(false);
        }