public static async Task <bool> OnCallbackPinMessageAsync(this TelegramService telegramService)
    {
        var chatId = telegramService.ChatId;

        if (!await telegramService.CheckFromAdminOrAnonymous())
        {
            await telegramService.AnswerCallbackQueryAsync("Kamu tidak memiliki izin untuk melakukan tidakan!", true);

            return(true);
        }

        var messageId           = telegramService.GetCallbackDataAt <int>(1);
        var pinMode             = telegramService.GetCallbackDataAt <string>(2);
        var disableNotification = pinMode == "silent";

        var client = telegramService.Client;

        await client.UnpinChatMessageAsync(chatId, messageId);

        await client.PinChatMessageAsync(
            chatId : chatId,
            messageId : messageId,
            disableNotification : disableNotification
            );

        await telegramService.DeleteCurrentCallbackMessageAsync();

        return(true);
    }
Exemplo n.º 2
0
    public async Task <bool> ExecuteAsync()
    {
        Log.Information("Receiving Ping callback");

        var callbackData = _callbackQuery.Data;

        Log.Debug("CallbackData: {0}", callbackData);

        var answerCallback = $"Callback: {callbackData}";

        await _telegramService.AnswerCallbackQueryAsync(answerCallback, showAlert : true);

        return(true);
    }
    public static async Task <bool> OnCallbackPingAsync(this TelegramService telegramService)
    {
        Log.Information("Receiving Ping callback");
        var callbackQuery = telegramService.CallbackQuery;

        var callbackData = callbackQuery.Data;

        Log.Debug("CallbackData: {CallbackData}", callbackData);

        var answerCallback = $"Callback: {callbackData}";

        await telegramService.AnswerCallbackQueryAsync(answerCallback, showAlert : true);

        return(true);
    }
Exemplo n.º 4
0
    public async Task <bool> ExecuteAsync()
    {
        Log.Information("Receiving Verify Callback");

        var callbackData = _callbackQuery.Data;
        var chatId       = _callbackQuery.Message.Chat.Id;
        var fromId       = _callbackQuery.From.Id;

        Log.Information(
            "CallbackData: {CallbackData} from {FromId}",
            callbackData,
            fromId
            );

        var partCallbackData = callbackData.Split(" ");
        var action           = partCallbackData.ValueOfIndex(1);
        var target           = partCallbackData.ValueOfIndex(2).ToInt();
        var isAdmin          = await _privilegeService.IsAdminAsync(chatId, fromId);

        if (!isAdmin)
        {
            Log.Information("UserId: {FromId} is not Admin in this chat!", fromId);
            return(false);
        }

        switch (action)
        {
        case "remove-warn":
            Log.Information("Removing warn for {Target}", target);
            // await _telegramService.RemoveWarnMemberStatAsync(target);
            await _telegramService.EditMessageCallback($"Peringatan untuk UserID: {target} sudah di hapus");

            break;

        default:
            Log.Information("Action {Action} is undefined", action);
            break;
        }

        await _telegramService.AnswerCallbackQueryAsync("Succed!");

        return(true);
    }
    public static async Task <bool> OnCallbackDeleteAsync(this TelegramService telegramService)
    {
        var chatId        = telegramService.ChatId;
        var fromId        = telegramService.FromId;
        var messageTarget = telegramService.GetCallbackDataAt <string>(1);

        Log.Information(
            "Callback delete message at ChatId: {ChatId}. Target: {MessageTarget}",
            chatId,
            messageTarget
            );

        if (!await telegramService.CheckUserPermission())
        {
            Log.Information(
                "UserId: '{UserId}' at ChatId: '{ChatId}' has no permission to delete message",
                fromId,
                chatId
                );

            await telegramService.AnswerCallbackQueryAsync("Kamu tidak mempunyai akses melakukan tindakan ini!", true);

            return(true);
        }

        if (messageTarget == "current-message")
        {
            await telegramService.DeleteCurrentCallbackMessageAsync();
        }
        else
        {
            var messageId = telegramService.GetCallbackDataAt <int>(1);
            await telegramService.DeleteAsync(messageId);
        }

        return(true);
    }
    public static async Task <bool> OnCallbackForceSubAsync(this TelegramService telegramService)
    {
        var chatId = telegramService.ChatId;

        Log.Information("Receiving Ping callback");

        if (!await telegramService.CheckFromAdminOrAnonymous())
        {
            await telegramService.AnswerCallbackQueryAsync("Kamu tidak memiliki izin untuk melakukan tidakan!", true);

            return(true);
        }

        var fSubsService = telegramService.GetRequiredService <ForceSubsService>();

        var callbackAction = telegramService.GetCallbackDataAt <string>(1);
        var channelId      = telegramService.GetCallbackDataAt <long>(2);

        await fSubsService.DeleteSubsAsync(chatId, channelId);

        await telegramService.EditMessageCallback("Channel berhasil dihapus dari daftar subs!");

        return(true);
    }
Exemplo n.º 7
0
    public async Task <bool> ExecuteAsync()
    {
        var       chatId            = _telegramService.ChatId;
        var       chatTitle         = _telegramService.ChatTitle;
        var       messageId         = _telegramService.CallBackMessageId;
        var       answerHeader      = $"RSS Control for {chatTitle}";
        var       answerDescription = string.Empty;
        var       part  = _telegramService.CallbackQuery.Data?.Split(" ");
        var       rssId = part !.ElementAtOrDefault(2);
        var       page  = 0;
        const int take  = 5;

        if (!await _telegramService.CheckUserPermission())
        {
            await _telegramService.AnswerCallbackQueryAsync("Anda tidak mempunyai akses", true);

            return(false);
        }

        var rssFind = new RssSettingFindDto()
        {
            ChatId = chatId
        };

        var updateValue = new Dictionary <string, object>()
        {
            { "updated_at", DateTime.UtcNow }
        };

        switch (part.ElementAtOrDefault(1))
        {
        case "stop-all":
            updateValue.Add("is_enabled", false);
            answerDescription = $"Semua service berhasil dimatikan";
            break;

        case "start-all":
            updateValue.Add("is_enabled", true);
            answerDescription = "Semua service berhasil diaktifkan";
            break;

        case "start":
            rssFind.Id = rssId.ToInt64();
            updateValue.Add("is_enabled", true);
            answerDescription = "Service berhasil di aktifkan";
            break;

        case "stop":
            rssFind.Id = rssId.ToInt64();
            updateValue.Add("is_enabled", false);
            answerDescription = "Service berhasil dimatikan";
            break;

        case "attachment-off":
            rssFind.Id = rssId.ToInt64();
            updateValue.Add("include_attachment", false);
            answerDescription = "Attachment tidak akan ditambahkan";
            break;

        case "attachment-on":
            rssFind.Id = rssId.ToInt64();
            updateValue.Add("include_attachment", true);
            answerDescription = "Berhasil mengaktifkan attachment";
            break;

        case "delete":
            await _rssService.DeleteRssAsync(
                chatId : chatId,
                columnName : "id",
                columnValue : rssId
                );

            answerDescription = "Service berhasil dihapus";
            break;

        case "navigate-page":
            var toPage = part.ElementAtOrDefault(2).ToInt();
            page = toPage;
            answerDescription = "Halaman " + (toPage + 1);
            break;
        }

        await _rssService.UpdateRssSettingAsync(rssFind, updateValue);

        await _rssFeedService.ReRegisterRssFeedByChatId(chatId);

        var answerCombined = answerHeader + Environment.NewLine + answerDescription;

        var btnMarkupCtl = await _rssService.GetButtonMarkup(
            chatId : chatId,
            page : page,
            take : take
            );

        if (answerDescription.IsNotNullOrEmpty())
        {
            await _telegramService.EditMessageCallback(answerCombined, btnMarkupCtl);

            if (part.ElementAtOrDefault(1)?.Contains("all") ?? false)
            {
                await _telegramService.AnswerCallbackQueryAsync(answerCombined, true);
            }
        }

        await _messageHistoryService.UpdateDeleteAtAsync(
            new MessageHistoryFindDto()
        {
            ChatId    = chatId,
            MessageId = messageId
        },
            DateTime.UtcNow.AddMinutes(10)
            );

        return(true);
    }
    public static async Task <bool> OnCallbackVerifyAsync(this TelegramService telegramService)
    {
        Log.Information("Executing Verify Callback");

        var callbackQuery = telegramService.CallbackQuery;
        var callbackData  = callbackQuery.Data;
        var fromId        = telegramService.FromId;
        var chatId        = telegramService.ChatId;

        var stepHistoriesService    = telegramService.GetRequiredService <StepHistoriesService>();
        var userProfilePhotoService = telegramService.GetRequiredService <UserProfilePhotoService>();

        Log.Debug(
            "CallbackData: {CallbackData} from {FromId}",
            callbackData,
            fromId
            );

        var partCallbackData = callbackData.Split(" ");
        var callBackParam1   = partCallbackData.ElementAtOrDefault(1);
        var answer           = "Tombol ini bukan untukmu Bep!";

        Log.Debug("Verify Param1: {Param}", callBackParam1);

        Log.Information("Starting Verify from History for UserId: {UserId}", fromId);
        var needVerifyList = (await stepHistoriesService.GetStepHistoryVerifyCore(
                                  new StepHistory()
        {
            ChatId = chatId,
            UserId = fromId
        }
                                  )).ToList();

        if (!needVerifyList.Any())
        {
            answer = "Kamu tidak perlu verifikasi!";
        }
        else
        {
            await userProfilePhotoService.ResetUserProfilePhotoCacheAsync(fromId);

            foreach (var step in needVerifyList)
            {
                var updateHistory = step;
                updateHistory.UpdatedAt = DateTime.Now;

                switch (step.Name)
                {
                case StepHistoryName.ChatMemberUsername:
                    Log.Debug("Verifying Username for UserId {UserId}", fromId);
                    if (telegramService.HasUsername)
                    {
                        updateHistory.Status = StepHistoryStatus.HasVerify;
                    }
                    break;

                case StepHistoryName.ChatMemberPhoto:
                    Log.Debug("Verifying User Profile Photo for UserId {UserId}", fromId);
                    if (await userProfilePhotoService.HasUserProfilePhotosAsync(fromId))
                    {
                        updateHistory.Status = StepHistoryStatus.HasVerify;
                    }
                    break;

                case StepHistoryName.ForceSubscription:
                    var chatMember = await telegramService.ChatService.GetChatMemberAsync(
                        chatId : chatId,
                        userId : fromId,
                        evictAfter : true
                        );

                    if (chatMember.Status != ChatMemberStatus.Left)
                    {
                        updateHistory.Status = StepHistoryStatus.HasVerify;
                    }

                    break;

                case StepHistoryName.HumanVerification:
                    updateHistory.Status = StepHistoryStatus.HasVerify;
                    break;

                default:
                    break;
                }

                await stepHistoriesService.SaveStepHistory(updateHistory);
            }

            var afterVerify = await stepHistoriesService.GetStepHistoryVerifyCore(
                new StepHistory()
            {
                ChatId = chatId,
                UserId = fromId
            }
                );

            if (!afterVerify.Any())
            {
                await telegramService.UnmuteChatMemberAsync(fromId);

                answer = "Terima kasih sudah verifikasi!";
            }
            else
            {
                answer = "Silakan lakukan sesuai instruksi, lalu tekan Verifikasi";
            }
        }

        await telegramService.AnswerCallbackQueryAsync(answer);

        return(true);
    }
    public static async Task <bool> OnCallbackGlobalBanAsync(this TelegramService telegramService)
    {
        var chatId        = telegramService.ChatId;
        var fromId        = telegramService.FromId;
        var chatUsername  = telegramService.Chat.Username;
        var message       = telegramService.CallbackMessage;
        var callbackDatas = telegramService.CallbackQueryDatas;

        if (!await telegramService.CheckFromAdminOrAnonymous())
        {
            Log.Debug(
                "UserId: {UserId} is not admin at ChatId: {ChatId}",
                fromId,
                chatId
                );

            return(false);
        }

        var globalBanService = telegramService.GetRequiredService <GlobalBanService>();
        var eventLogService  = telegramService.GetRequiredService <EventLogService>();

        var action = telegramService.GetCallbackDataAt <string>(1);
        var userId = telegramService.GetCallbackDataAt <long>(2);

        var replyToMessageId = telegramService.ReplyToMessage?.MessageId ?? -1;

        var answerCallback = string.Empty;

        var messageLog = HtmlMessage.Empty
                         .TextBr("Global Ban di tambahkan baru")
                         .Bold("Ban By: ").CodeBr(fromId.ToString())
                         .Bold("UserId: ").CodeBr(userId.ToString());

        switch (action)
        {
        case "add":
            await globalBanService.SaveBanAsync(
                new GlobalBanItem
            {
                UserId     = userId,
                ReasonBan  = "@" + chatUsername,
                BannedBy   = fromId,
                BannedFrom = chatId,
                CreatedAt  = DateTime.UtcNow
            }
                );

            await globalBanService.UpdateCache(userId);

            await telegramService.KickMemberAsync(userId, untilDate : DateTime.Now.AddSeconds(30));

            await eventLogService.SendEventLogAsync(
                chatId : chatId,
                message : message,
                text : messageLog.ToString(),
                forwardMessageId : replyToMessageId,
                deleteForwardedMessage : true,
                messageFlag : MessageFlag.GBan
                );

            telegramService.DeleteMessageManyAsync(customUserId: userId).InBackground();

            answerCallback = "Berhasil Memblokir Pengguna!";

            break;

        case "del":
            await globalBanService.DeleteBanAsync(userId);

            await globalBanService.UpdateCache(userId);

            answerCallback = "Terima kasih atas konfirmasinya!";

            break;
        }

        await telegramService.AnswerCallbackQueryAsync(answerCallback, true);

        await telegramService.DeleteCurrentCallbackMessageAsync();

        return(true);
    }