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

        await _telegramService.DeleteSenderMessageAsync();

        if (!_telegramService.IsFromSudo)
        {
            return;
        }

        var param1 = _telegramService.MessageTextParts.ElementAtOrDefault(1);

        switch (param1)
        {
        case "shutdown":
            await _telegramService.SendTextMessageAsync("Bot di jadwalkan untuk dimatikan..");

            _applicationLifetime.StopApplication();

            break;
        }
    }
Exemplo n.º 2
0
    public override async Task HandleAsync(IUpdateContext context, UpdateDelegate next, string[] args)
    {
        await _telegramService.AddUpdateContext(context);

        var msg = context.Update.Message;

        if (msg.ReplyToMessage != null)
        {
            msg = msg.ReplyToMessage;
        }

        var userId   = msg.From.Id;
        var nameLink = msg.GetFromNameLink();

        var sendText = $"{nameLink} tidak lagi Admin";

        var promote = await _telegramService.DemoteChatMemberAsync(userId);

        if (!promote.IsSuccess)
        {
            var errorCode    = promote.ErrorCode;
            var errorMessage = promote.ErrorMessage;

            sendText = $"Demote {nameLink} gagal" +
                       $"\nPesan: {errorMessage}";
        }

        await _telegramService.SendTextMessageAsync(sendText);
    }
Exemplo n.º 3
0
    public override async Task HandleAsync(IUpdateContext context, UpdateDelegate next, string[] args)
    {
        await _telegramService.AddUpdateContext(context);

        var txt     = _telegramService.Message.Text;
        var partTxt = txt.SplitText(" ").ToArray();
        var part1   = partTxt.ValueOfIndex(1);// Country

        await _telegramService.SendTextMessageAsync("🔍 Getting information..");

        string sendText;

        if (part1.IsNullOrEmpty())
        {
            Log.Information("Getting Covid info Global");

            sendText = await _lmaoCovidService.GetCovidAll();
        }
        else
        {
            Log.Information("Getting Covid info by Region: {Part1}", part1);
            sendText = await _lmaoCovidService.GetCovidByCountry(part1);
        }

        await _telegramService.EditMessageTextAsync(sendText);
    }
Exemplo n.º 4
0
        public override async Task HandleAsync(IUpdateContext context, UpdateDelegate next, string[] args)
        {
            await _telegramService.AddUpdateContext(context);

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

            if (await _authService.IsAuth(chatId))
            {
                await _telegramService.SendTextMessageAsync("Chat has been authorized!");

                return;
            }

            if (!_telegramService.IsFromSudo)
            {
                Log.Information("User ID: {0} isn't sudo!", fromId);

                await _telegramService.SendTextMessageAsync("You can't authorize this chat!");

                return;
            }

            await _telegramService.SendTextMessageAsync("Authorizing chat..");

            await _authService.SaveAuth(new AuthorizedChat()
            {
                ChatId       = chatId,
                AuthorizedBy = fromId,
                IsAuthorized = true,
                CreatedAt    = DateTime.Now
            });

            await _telegramService.EditMessageTextAsync("Chat has been authorized!");
        }
Exemplo n.º 5
0
    public override async Task HandleAsync(
        IUpdateContext context,
        UpdateDelegate next,
        string[] args
        )
    {
        await _telegramService.AddUpdateContext(context);

        var isSudoer = _telegramService.IsFromSudo;

        await _telegramService.DeleteSenderMessageAsync();

        if (!isSudoer)
        {
            Log.Debug("Only sudo can do Sync Kata!");
            return;
        }

        await _telegramService.AppendTextAsync("Sedang mengsinkronkan Word Filter");

        await _wordFilterService.UpdateWordListsCache();

        await _telegramService.AppendTextAsync("Selesai mengsinkronkan.");

        await _telegramService.DeleteAsync(delay : 3000);
    }
Exemplo n.º 6
0
    public override async Task HandleAsync(
        IUpdateContext context,
        UpdateDelegate next,
        string[] args
        )
    {
        await _telegramService.AddUpdateContext(context);

        var msg      = _telegramService.Message;
        var chatId   = msg.Chat.Id;
        var msgId    = msg.MessageId;
        var msgText  = msg.Text;
        var dateDate = DateTime.UtcNow.ToString("yyyy-MM-dd", new DateTimeFormatInfo());

        var checkUserPermission = await _telegramService.CheckUserPermission();

        if (!checkUserPermission)
        {
            var send = "Maaf, hanya Admin yang dapat mengekspor daftar RSS";
            await _telegramService.SendTextMessageAsync(send);

            return;
        }

        var rssSettings = await _rssService.GetRssSettingsAsync(chatId);

        Log.Information("RssSettings: {V}", rssSettings.ToJson(true));

        var listRss = new StringBuilder();

        foreach (var rss in rssSettings)
        {
            listRss.AppendLine(rss.UrlFeed);
        }

        Log.Debug("ListUrl: \n{ListRss}", listRss);

        var listRssStr = listRss.ToString().Trim();
        var sendText   = "Daftar RSS ini tidak terenkripsi, dapat di pulihkan di obrolan mana saja. " +
                         "Tambahkan parameter -e agar daftar RSS terenkripsi.";

        if (msgText.Contains("-e", StringComparison.CurrentCulture))
        {
            Log.Information("List RSS will be encrypted.");
            listRssStr = listRssStr.AesEncrypt();
            sendText   = "Daftar RSS ini terenkripsi, hanya dapat di pulihkan di obrolan ini!";
        }

        var filePath = $"{chatId}/rss-feed_{dateDate}_{msgId}.txt";
        await listRssStr.WriteTextAsync(filePath);

        var fileSend = Path.Combine("Storage", "Caches") + $"/{filePath}";
        await _telegramService.SendMediaAsync(
            fileSend,
            MediaType.LocalDocument,
            sendText
            );

        fileSend.DeleteFile();
    }
Exemplo n.º 7
0
    public override async Task HandleAsync(
        IUpdateContext context,
        UpdateDelegate next,
        string[] args
        )
    {
        await _telegramService.AddUpdateContext(context);

        var chatId = _telegramService.ChatId;

        var checkUserPermission = await _telegramService.CheckUserPermission();

        if (!checkUserPermission)
        {
            Log.Warning("Delete RSS only for admin or private chat!");
            await _telegramService.DeleteAsync();

            return;
        }

        var urlFeed = _telegramService.Message.Text.GetTextWithoutCmd();

        await _telegramService.SendTextMessageAsync($"Sedang menghapus {urlFeed}");

        var delete = await _rssService.DeleteRssAsync(chatId, urlFeed);

        var success = delete.ToBool()
            ? "berhasil."
            : "gagal. Mungkin RSS tersebut sudah di hapus atau belum di tambahkan";

        await _telegramService.EditMessageTextAsync($"Hapus {urlFeed} {success}");

        await _rssFeedService.ReRegisterRssFeedByChatId(chatId);
    }
Exemplo n.º 8
0
    public async Task HandleAsync(
        IUpdateContext context,
        UpdateDelegate next,
        CancellationToken cancellationToken
        )
    {
        await _telegramService.AddUpdateContext(context);

        var chatId = _telegramService.ChatId;
        var update = _telegramService.Update;

        try
        {
            await next(context, cancellationToken);
        }
        catch (Exception exception)
        {
            var htmlMessage = HtmlMessage.Empty
                              .Bold("🗒 Message: ").CodeBr(exception.Message).Br()
                              .BoldBr("🔄 Update: ").CodeBr(update.ToJson(true)).Br()
                              .BoldBr("🛑 Exception: ").CodeBr(exception.ToStringDemystified()).Br();

            await _eventLogService.SendEventLogCoreAsync(htmlMessage.ToString());
        }
    }
Exemplo n.º 9
0
    public override async Task HandleAsync(
        IUpdateContext context,
        UpdateDelegate next,
        string[] args
        )
    {
        await _telegramService.AddUpdateContext(context);

        var chatId = _telegramService.ChatId;

        if (!await _telegramService.CheckUserPermission())
        {
            Log.Warning("This command only for sudo!");
            return;
        }

        await _telegramService.AppendTextAsync("Memulai Job RSS..");

        _rssFeedService.UnRegisterRssFeedByChatId(chatId);

        var rssSettings = await _rssService.GetRssSettingsAsync(chatId);

        var rssCount = rssSettings.Count();

        foreach (var rssSetting in rssSettings)
        {
            var urlFeed = rssSetting.UrlFeed;

            _rssFeedService.RegisterUrlFeed(chatId, urlFeed);
        }

        await _telegramService.AppendTextAsync($"Sebanyak {rssCount} RSS berhasil dimulai");
    }
Exemplo n.º 10
0
    public async Task HandleAsync(
        IUpdateContext context,
        UpdateDelegate next,
        CancellationToken cancellationToken
        )
    {
        await _telegramService.AddUpdateContext(context);

        _logger.LogTrace("NewUpdate: {@V}", _telegramService.Update);

        // Pre-Task is should be awaited.
        var preTaskResult = await _telegramService.OnUpdatePreTaskAsync();

        // Last, do additional task which bot may do
        _telegramService.OnUpdatePostTaskAsync().InBackground();

        if (!preTaskResult)
        {
            _logger.LogInformation(
                "Next handler at ChatId: {ChatId} is ignored because pre-task is not success. UpdateType: {UpdateType}",
                _telegramService.ChatId,
                _telegramService.Update.Type
                );
            return;
        }

        _logger.LogDebug("Continue to next Handler");

        await next(context, cancellationToken);
    }
Exemplo n.º 11
0
        public async Task HandleAsync(IUpdateContext context, UpdateDelegate next, CancellationToken cancellationToken)
        {
            await _telegramService.AddUpdateContext(context);

            Log.Debug("New Update..");

            await next(context, cancellationToken);
        }
Exemplo n.º 12
0
    public override async Task HandleAsync(
        IUpdateContext context,
        UpdateDelegate next,
        string[] args
        )
    {
        await _telegramService.AddUpdateContext(context);

        var tagVal   = _telegramService.MessageTextParts.ValueOfIndex(1);
        var chatId   = _telegramService.ChatId;
        var fromId   = _telegramService.FromId;
        var sendText = "Hanya Admin Grup yang dapat menghapus Tag.";

        if (
            !_telegramService.IsFromSudo &&
            !await _telegramService.CheckUserPermission()
            )
        {
            await _telegramService.SendTextMessageAsync(sendText);

            Log.Debug
            (
                "UserId {UserId} don't have privilege for remove tag on ChatId {ChatId}!",
                fromId, chatId
            );
            return;
        }

        if (tagVal.IsNullOrEmpty())
        {
            await _telegramService.SendTextMessageAsync("Tag apa yg mau di hapus?");

            return;
        }

        await _telegramService.SendTextMessageAsync("Memeriksa..");

        var isExist = await _tagsService.IsExist(chatId, tagVal);

        if (isExist)
        {
            Log.Information("Sedang menghapus tag {TagVal}", tagVal);
            var unTag = await _tagsService.DeleteTag(chatId, tagVal);

            if (unTag)
            {
                sendText = $"Hapus tag {tagVal} berhasil";
            }

            await _telegramService.EditMessageTextAsync(sendText);

            await _tagsService.UpdateCacheAsync(chatId);
        }
        else
        {
            await _telegramService.EditMessageTextAsync($"Tag {tagVal} tidak di temukan");
        }
    }
Exemplo n.º 13
0
    public override async Task HandleAsync(
        IUpdateContext context,
        UpdateDelegate next,
        string[] args
        )
    {
        await _telegramService.AddUpdateContext(context);

        await _telegramService.GetBotListAsync();
    }
Exemplo n.º 14
0
        public override async Task HandleAsync(
            IUpdateContext context,
            UpdateDelegate next,
            string[] args
            )
        {
            await _telegramService.AddUpdateContext(context);

            await _telegramService.SaveShalatTimeCityAsync();
        }
Exemplo n.º 15
0
    public async Task HandleAsync(
        UpdateContext context,
        UpdateDelegate <UpdateContext> next,
        CancellationToken cancellationToken
        )
    {
        await _telegramService.AddUpdateContext(context);

        await _telegramService.FindNoteAsync();
    }
Exemplo n.º 16
0
    public override async Task HandleAsync(
        IUpdateContext context,
        UpdateDelegate next,
        string[] args
        )
    {
        await _telegramService.AddUpdateContext(context);

        await _telegramService.DeleteForceSubsChannelAsync();
    }
Exemplo n.º 17
0
    public async Task HandleAsync(
        IUpdateContext context,
        UpdateDelegate next,
        CancellationToken cancellationToken
        )
    {
        await _telegramService.AddUpdateContext(context);

        _telegramService.SendWelcomeMessageAsync().InBackground();
    }
Exemplo n.º 18
0
    public override async Task HandleAsync(
        IUpdateContext context,
        UpdateDelegate next,
        string[] args
        )
    {
        await _telegramService.AddUpdateContext(context);

        await _telegramService.SaveInlineSettingsAsync();
    }
Exemplo n.º 19
0
    public async Task HandleAsync(
        IUpdateContext context,
        UpdateDelegate next,
        CancellationToken cancellationToken
        )
    {
        await _telegramService.AddUpdateContext(context);

        await _telegramService.OnInlineQueryAsync();
    }
Exemplo n.º 20
0
    public override async Task HandleAsync(
        IUpdateContext context,
        UpdateDelegate next,
        string[] args
        )
    {
        await _telegramService.AddUpdateContext(context);

        await _telegramService.SendAboutUsernameAsync();
    }
Exemplo n.º 21
0
        public override async Task HandleAsync(IUpdateContext context, UpdateDelegate next, string[] args)
        {
            await _telegramService.AddUpdateContext(context);

            var message = _telegramService.Message;

            await _easyCachingProvider.SetAsync($"message{message.MessageId}", message, TimeSpan.FromMinutes(10));

            await _telegramService.SendTextMessageAsync("Pong!");
        }
Exemplo n.º 22
0
    public override async Task HandleAsync(
        IUpdateContext context,
        UpdateDelegate next,
        string[] args
        )
    {
        await _telegramService.AddUpdateContext(context);

        _telegramService.ReadQrAsync().InBackground();
    }
Exemplo n.º 23
0
    public override async Task HandleAsync(
        IUpdateContext context,
        UpdateDelegate next,
        string[] args
        )
    {
        await _telegramService.AddUpdateContext(context);

        var msg    = _telegramService.Message;
        var chat   = _telegramService.Message.Chat;
        var chatId = _telegramService.ChatId;

        await _telegramService.DeleteSenderMessageAsync();

        if (!await _telegramService.CheckUserPermission())
        {
            Log.Warning("Settings command only for Admin group or Private chat");
            return;
        }

        Log.Information("Initializing reset Settings");
        await _telegramService.DeleteAsync(msg.MessageId);

        await _telegramService.SendTextMessageAsync("Sedang mengembalikan ke Pengaturan awal");

        var data = new Dictionary <string, object>()
        {
            ["chat_id"]                   = chat.Id,
            ["chat_title"]                = chat.Title,
            ["enable_afk_status"]         = 1,
            ["enable_anti_malfiles"]      = 1,
            ["enable_fed_cas_ban"]        = 1,
            ["enable_fed_es2_ban"]        = 1,
            ["enable_fed_spamwatch"]      = 1,
            ["enable_url_filtering"]      = 1,
            ["enable_human_verification"] = 1,
            ["enable_reply_notification"] = 1,
            ["enable_warn_username"]      = 1,
            ["enable_word_filter_group"]  = 1,
            ["enable_word_filter_global"] = 1,
            ["enable_welcome_message"]    = 1
        };

        var update = await _settingsService.SaveSettingsAsync(data);

        await _settingsService.UpdateCacheAsync(chatId);

        Log.Information("Result: {Update}", update);

        await _telegramService.EditMessageTextAsync("Pengaturan awal berhasil di kembalikan");

        await _telegramService.DeleteAsync(_telegramService.EditedMessageId, 2000);

        Log.Information("Settings has been reset");
    }
Exemplo n.º 24
0
    public override async Task HandleAsync(
        IUpdateContext context,
        UpdateDelegate next,
        string[] args
        )
    {
        await _telegramService.AddUpdateContext(context);

        var fromId       = _telegramService.FromId;
        var chatId       = _telegramService.ChatId;
        var messageTexts = _telegramService.MessageTextParts;
        var reasonBan    = messageTexts.ElementAtOrDefault(1) ?? "Import from Bot";

        if (!_telegramService.IsFromSudo)
        {
            await _telegramService.DeleteSenderMessageAsync();
        }

        var repMessage = _telegramService.ReplyToMessage;

        if (repMessage.Type != MessageType.Document)
        {
            await _telegramService.SendTextMessageAsync("Reply persan dokument untuk Import Global Ban. Biasanya berkas .xsv atau .json");
        }

        var document         = repMessage.Document;
        var documentFileName = document.FileName;

        await _telegramService.AppendTextAsync("Mengambil berkas..");

        var fileName = await _telegramService.DownloadFileAsync("import_gban");

        await _telegramService.AppendTextAsync($"Menguraikan berkas {documentFileName}");

        var import = await _globalBanService.ImportFile
                     (
            fileName,
            new GlobalBanItem()
        {
            ReasonBan  = reasonBan,
            BannedBy   = fromId,
            BannedFrom = chatId
        }
                     );

        if (import > 0)
        {
            await _telegramService.AppendTextAsync($"Sebanyak {import} item berhasil ditambahkan");
        }
        else
        {
            await _telegramService.AppendTextAsync($"Semua data sudah ditambahkan");
        }
    }
Exemplo n.º 25
0
    public override async Task HandleAsync(
        IUpdateContext context,
        UpdateDelegate next,
        string[] args
        )
    {
        await _telegramService.AddUpdateContext(context);

        var fromNameLink = _telegramService.FromNameLink;
        var fromId       = _telegramService.FromId;
        var chatId       = _telegramService.ChatId;
        var afkReason    = _telegramService.MessageOrEditedText.GetTextWithoutCmd();

        if (_telegramService.CheckFromAnonymous() ||
            _telegramService.CheckSenderChannel())
        {
            await _telegramService.SendTextMessageAsync("Mode AFK dimatikan untuk Pengguna Anonymous");

            return;
        }

        var settings = await _settingsService.GetSettingsByGroup(chatId);

        if (!settings.EnableAfkStatus)
        {
            await _telegramService.DeleteSenderMessageAsync();

            return;
        }

        var data = new Dictionary <string, object>()
        {
            { "user_id", fromId },
            { "chat_id", chatId },
            { "is_afk", 1 },
            { "afk_start", DateTime.Now },
            { "afk_end", DateTime.Now }
        };

        var sendText = $"{fromNameLink} Sedang afk.";

        if (afkReason.IsNotNullOrEmpty())
        {
            data.Add("afk_reason", afkReason);

            sendText += $"\n<i>{afkReason}</i>";
        }

        await _telegramService.SendTextMessageAsync(sendText);

        await _afkService.SaveAsync(data);

        await _afkService.UpdateAfkByIdCacheAsync(fromId);
    }
Exemplo n.º 26
0
    public override async Task HandleAsync(IUpdateContext context, UpdateDelegate next, string[] args)
    {
        await _telegramService.AddUpdateContext(context);

        var message     = _telegramService.Message;
        var messageText = _telegramService.Message.Text.GetTextWithoutCmd();
        var chatId      = message.Chat.Id;
        var partsText   = messageText.Split(" ");
        var param1      = partsText.ValueOfIndex(0);

        var isBeta = await _telegramService.IsBeta();

        if (!_telegramService.IsFromSudo)
        {
            if (isBeta)
            {
                await _telegramService.SendTextMessageAsync("Fitur Wget saat ini masih dibatasi.");

                return;
            }

            if (chatId != -1001272521285)
            {
                await _telegramService.SendTextMessageAsync("Fitur Wget dapat di gunakan di grup @WinTenMirror");

                return;
            }
        }

        if (param1.IsNullOrEmpty())
        {
            await _telegramService.SendTextMessageAsync("Silakan sertakan tautan yang akan di download");

            return;
        }

        await _telegramService.SendTextMessageAsync($"Preparing download file " +
                                                    $"\nUrl: {param1}");

        if (param1.IsMegaUrl())
        {
            await _megamapiService.DownloadFileAsync(param1, answer => {
                return(_telegramService.CallbackAnswerAsync(answer));
            });
        }
        else if (param1.IsUptoboxUrl())
        {
            // await _telegramService.DownloadUrlAsync();
        }
        else
        {
            // await _telegramService.DownloadFile(param1);
        }
    }
Exemplo n.º 27
0
    public override async Task HandleAsync(IUpdateContext context, UpdateDelegate next, string[] args)
    {
        await _telegramService.AddUpdateContext(context);

        var msg      = context.Update.Message;
        var sendText = "Balas pesan yg mau di report";

        if (_telegramService.IsPrivateChat)
        {
            return;
        }

        if (msg.ReplyToMessage != null)
        {
            var repMsg = msg.ReplyToMessage;

            if (msg.From.Id != repMsg.From.Id)
            {
                var mentionAdmins = await _telegramService.GetMentionAdminsStr();

                var reporterNameLink = msg.GetFromNameLink();
                var reportedNameLink = repMsg.GetFromNameLink();
                var repMsgLink       = repMsg.GetMessageLink();

                sendText = $"Ada laporan nich." +
                           $"\n{reporterNameLink} melaporkan {reportedNameLink}" +
                           $"{mentionAdmins}";

                var keyboard = new InlineKeyboardMarkup(new[]
                {
                    new[]
                    {
                        InlineKeyboardButton.WithCallbackData("Hapus", "PONG"),
                        InlineKeyboardButton.WithCallbackData("Tendang", "PONG")
                    },
                    new[]
                    {
                        InlineKeyboardButton.WithCallbackData("Ban", "PONG"),
                        InlineKeyboardButton.WithUrl("Ke Pesan", repMsgLink)
                    }
                });

                await _telegramService.SendTextMessageAsync(sendText)
                ;

                return;
            }

            sendText = "Melaporkan diri sendiri? 🤔";
        }

        await _telegramService.SendTextMessageAsync(sendText);
    }
Exemplo n.º 28
0
    public async Task HandleAsync(
        IUpdateContext context,
        UpdateDelegate next,
        CancellationToken cancellationToken
        )
    {
        await _telegramService.AddUpdateContext(context);

        _telegramService.OnCallbackReceiveAsync().InBackground();

        await next(context, cancellationToken);
    }
Exemplo n.º 29
0
    public override async Task HandleAsync(IUpdateContext context, UpdateDelegate next, string[] args)
    {
        await _telegramService.AddUpdateContext(context);

        if (!await _botService.IsBeta())
        {
            return;
        }

        var chatId = _telegramService.Message.Chat.Id;

        // await _metricService.GetStat();
    }
Exemplo n.º 30
0
    public override async Task HandleAsync(
        IUpdateContext context,
        UpdateDelegate next,
        string[] args
        )
    {
        await _telegramService.AddUpdateContext(context);

        var msg    = _telegramService.Message;
        var chatId = _telegramService.ChatId;

        if (!await _telegramService.CheckFromAdminOrAnonymous())
        {
            return;
        }

        if (msg.ReplyToMessage == null)
        {
            await _telegramService.SendTextMessageAsync("Balas sebuah gambar, video, atau dokumen yang akan di jadikan Welcome media");

            return;
        }

        var repMsg      = msg.ReplyToMessage;
        var mediaFileId = repMsg.GetFileId();

        if (mediaFileId.IsNotNullOrEmpty())
        {
            var mediaType = repMsg.Type;

            await _telegramService.SendTextMessageAsync("Sedang menyimpan Welcome Media..");

            Log.Information("MediaId: {MediaFileId}", mediaFileId);

            await _settingsService.UpdateCell(chatId, "welcome_media", mediaFileId);

            await _settingsService.UpdateCell(chatId, "welcome_media_type", mediaType);

            Log.Information("Save media success..");

            await _telegramService.EditMessageTextAsync
            (
                "Welcome Media berhasil di simpan." +
                "\nKetik /welcome untuk melihat perubahan"
            );
        }
        else
        {
            await _telegramService.SendTextMessageAsync("Media tidak terdeteksi di pesan yg di reply tersebut.");
        }
    }