예제 #1
0
    public override async Task HandleAsync(
        IUpdateContext context,
        UpdateDelegate next,
        string[] args
        )
    {
        await _telegramService.AddUpdateContext(context);

        var partedText = _telegramService.MessageTextParts;
        var param1     = partedText.ElementAtOrDefault(1);// User ID

        if (!_telegramService.IsFromSudo)
        {
            Log.Warning("Not sudo can't execute this command..");
            return;
        }

        if (param1.IsNullOrEmpty())
        {
            await _telegramService.SendTextMessageAsync("Spesifikasikan ID Pengguna yang mau di hapus dari Global Ban");

            return;
        }

        var userId = param1.ToInt64();

        Log.Information("Execute Global DelBan");
        await _telegramService.SendTextMessageAsync("Mempersiapkan..");

        var isBan = await _globalBanService.IsExist(userId);

        Log.Information("IsBan: {IsBan}", isBan);
        if (!isBan)
        {
            await _telegramService.EditMessageTextAsync("Pengguna tidak di ban");

            return;
        }

        await _telegramService.EditMessageTextAsync("Memperbarui informasi..");

        var save = await _globalBanService.DeleteBanAsync(userId);

        Log.Information("SaveBan: {Save}", save);

        await _telegramService.EditMessageTextAsync("Memperbarui Cache..");

        await _globalBanService.UpdateCache(userId);

        await _telegramService.EditMessageTextAsync("Pengguna berhasil di hapus");
    }
예제 #2
0
        public override async Task HandleAsync(IUpdateContext context, UpdateDelegate next, string[] args,
                                               CancellationToken cancellationToken)
        {
            _telegramService = new TelegramService(context);
            var msg        = _telegramService.Message;
            var chatId     = msg.Chat.Id;
            var fromId     = msg.From.Id;
            var partedText = msg.Text.Split(" ");
            var param1     = partedText.ValueOfIndex(1); // User ID

            _globalBanService = new GlobalBanService(msg);

            if (!fromId.IsSudoer())
            {
                await _telegramService.SendTextAsync("Anda haram melakukan ini")
                .ConfigureAwait(false);

                return;
            }

            var repMsg = msg.ReplyToMessage;
            var userId = param1.ToInt();

            Log.Information("Execute Global DelBan");
            await _telegramService.SendTextAsync("Mempersiapkan..")
            .ConfigureAwait(false);

            // await _telegramService.DeleteAsync(msg.MessageId);

            var isBan = await _globalBanService.IsExist(userId)
                        .ConfigureAwait(false);

            Log.Information($"IsBan: {isBan}");
            if (!isBan)
            {
                await _telegramService.EditAsync("Pengguna tidak di ban")
                .ConfigureAwait(false);

                return;
            }

            await _telegramService.EditAsync("Memperbarui informasi..")
            .ConfigureAwait(false);

            var save = await _globalBanService.DeleteBanAsync(userId)
                       .ConfigureAwait(false);

            Log.Information($"SaveBan: {save}");

            await _telegramService.EditAsync("Memperbarui Cache..")
            .ConfigureAwait(false);

            await Sync.SyncGBanToLocalAsync()
            .ConfigureAwait(false);

            await _telegramService.EditAsync("Misi berhasil.")
            .ConfigureAwait(false);

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