コード例 #1
0
        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?");
                }
            }
        }
コード例 #2
0
    public override async Task HandleAsync(
        IUpdateContext context,
        UpdateDelegate next,
        string[] args
        )
    {
        await _telegramService.AddUpdateContext(context);

        var chatId = _telegramService.ChatId;
        var fromId = _telegramService.FromId;

        var messageTextParts = _telegramService.MessageTextParts;
        var word             = messageTextParts.ElementAtOrDefault(1) ?? string.Empty;
        var paramOption      = messageTextParts.ElementAtOrDefault(2) ?? string.Empty;

        var isGlobalBlock = false;

        var isSudoer = _telegramService.IsFromSudo;

        if (!isSudoer)
        {
            await _telegramService.DeleteSenderMessageAsync();

            Log.Information("Currently add Kata is limited only Sudo");
            return;
        }

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

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

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

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

        if (!word.IsNotNullOrEmpty())
        {
            await _telegramService.SendTextMessageAsync("Apa kata yg mau di blok?");
        }
        else
        {
            var isExist = await _wordFilterService.IsExistAsync(@where);

            if (isExist)
            {
                await _telegramService.AppendTextAsync("Kata sudah di tambahkan");
            }
            else
            {
                await _telegramService.AppendTextAsync("Sedang menambahkan kata");

                await _wordFilterService.SaveWordAsync(new WordFilter()
                {
                    Word      = word,
                    ChatId    = chatId,
                    IsGlobal  = isGlobalBlock,
                    FromId    = fromId,
                    CreatedAt = DateTime.Now
                });

                await _telegramService.AppendTextAsync("Kata berhasil di tambahkan");

                await _wordFilterService.UpdateWordListsCache();
            }
        }

        await _telegramService.DeleteAsync(delay : 3000);
    }
コード例 #3
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);
        }