コード例 #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;

            _globalBanService = new GlobalBanService(msg);

            var chatId     = msg.Chat.Id;
            var fromId     = msg.From.Id;
            var partedText = msg.Text.Split(" ");
            var param0     = partedText.ValueOfIndex(0) ?? "";
            var param1     = partedText.ValueOfIndex(1) ?? "";
            var userId     = param1;
            var reason     = msg.Text
                             .Replace(param0, "", StringComparison.CurrentCulture)
                             .Replace(param1, "", StringComparison.CurrentCulture).Trim();

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

                return;
            }

            if (param1 == "sync")
            {
                await _telegramService.SendTextAsync("Memperbarui cache..")
                .ConfigureAwait(false);

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

                await _telegramService.EditAsync("Selesai memperbarui..")
                .ConfigureAwait(false);

                return;
            }

            if (msg.ReplyToMessage == null)
            {
                if (param1.IsNullOrEmpty())
                {
                    await _telegramService.SendTextAsync("Balas seseorang yang mau di ban")
                    .ConfigureAwait(false);

                    return;
                }

                userId = param1;
                reason = msg.Text
                         .Replace(param0, "", StringComparison.CurrentCulture)
                         .Replace(param1, "", StringComparison.CurrentCulture).Trim();
            }
            else
            {
                var repMsg = msg.ReplyToMessage;
                userId = repMsg.From.Id.ToString();
                reason = msg.Text
                         .Replace(param0, "", StringComparison.CurrentCulture).Trim();
            }

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

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

            var banData = new GlobalBanData()
            {
                UserId     = userId.ToInt(),
                BannedBy   = fromId,
                BannedFrom = chatId,
                ReasonBan  = reason.IsNullOrEmpty() ? "no-reason" : reason
            };

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

            if (isBan)
            {
                await _telegramService.EditAsync("Pengguna sudah di ban")
                .ConfigureAwait(false);

                return;
            }

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

            var save = await _globalBanService.SaveBanAsync(banData)
                       .ConfigureAwait(false);

            // var save = await _globalBanService.SaveBanAsync(data);
            Log.Information($"SaveBan: {save}");

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

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


            await _telegramService.EditAsync("Pengguna berhasil di tambahkan.")
            .ConfigureAwait(false);

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