Пример #1
0
        protected async Task <bool> AnswerCallback(string text = null, bool ShowAlert = false)
        {
            try
            {
                if (this.Update.CallbackQuery != null && this.CallBackQueryId != null && text != null)
                {
                    return(await Telegram.AnswerCallbackQueryAsync(this.CallBackQueryId, text, ShowAlert));
                }

                if (this.Update.CallbackQuery != null && this.CallBackQueryId != null && text == null)
                {
                    return(await Telegram.AnswerCallbackQueryAsync(this.CallBackQueryId));
                }

                else
                {
                    return(false);
                }
            }

            catch
            {
                if (text != null)
                {
                    await Telegram.SendTextMessageAsync(this.ChatId, text);
                }

                return(true);
            }
        }
Пример #2
0
        private async Task ExecuteAsync()
        {
            var callbackData = CallbackQuery.Data;
            var fromId       = CallbackQuery.From.Id;

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

            var partCallbackData = callbackData.Split(" ");
            var action           = partCallbackData.ValueOfIndex(1);
            var target           = partCallbackData.ValueOfIndex(2).ToInt();
            var isAdmin          = await Telegram.IsAdminGroup(fromId)
                                   .ConfigureAwait(false);

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

            switch (action)
            {
            case "remove-warn":
                Log.Information($"Removing warn for {target}");
                await Telegram.RemoveWarnMemberStatAsync(target)
                .ConfigureAwait(false);

                await Telegram.EditMessageCallback($"Peringatan untuk UserID: {target} sudah di hapus")
                .ConfigureAwait(false);

                break;

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

            await Telegram.AnswerCallbackQueryAsync("Succed!")
            .ConfigureAwait(false);
        }
Пример #3
0
        private async Task ExecuteVerifyAsync()
        {
            var callbackData = CallbackQuery.Data;
            var fromId       = CallbackQuery.From.Id;

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

            var partCallbackData = callbackData.Split(" ");
            var userId           = partCallbackData.ValueOfIndex(1).ToInt();
            var answer           = "Tombol ini bukan untukmu Bep!";

            Log.Information($"Verify UserId: {userId}");
            if (fromId == userId)
            {
                await Telegram.RestrictMemberAsync(userId, true)
                .ConfigureAwait(false);

                answer = "Terima kasih sudah verifikasi!";
            }

            await Telegram.AnswerCallbackQueryAsync(answer)
            .ConfigureAwait(false);
        }