Exemplo n.º 1
0
        private async Task SendCallbackResponse(string text, bool showAlert = false)
        {
            if (_callback == null)
            {
                return;
            }

            await BotClient.AnswerCallbackQueryAsync(_callback.Id, text, showAlert);
        }
Exemplo n.º 2
0
        public async void ShowInfo(string hashtag)
        {
            if (!_callbackMode)
            {
                return;
            }

            var query = await _db.GetBookmarkByHashtag(_message.Chat.Id, hashtag);

            if (query == null)
            {
                await BotClient.AnswerCallbackQueryAsync(_callback.Id, $"Tidak ada #{hashtag} di grup ini!", true);

                return;
            }

            await BotClient.AnswerCallbackQueryAsync(_callback.Id,
                                                     $"Hashtag : {query.KeyName}\n" +
                                                     $"MessageId : {query.MessageId}\n" +
                                                     $"Set By : {query.ByName}\n" +
                                                     $"DateTime : {query.DateTime}", true);
        }
Exemplo n.º 3
0
        public async void Manage(string data = null)
        {
            if (!_callbackMode)
            {
                if (!_message.IsGroupChat())
                {
                    return;
                }

                // cek admin atau bukan
                if (!await _message.IsAdminThisGroup())
                {
                    _log.Warning("User {0} bukan admin grup!", _message.FromName());
                    await BotClient.SendTextAsync(_message, $"Maaf kaka... Kamu bukan admin grup ini!");

                    return;
                }
            }
            else
            {
                if (_message.ReplyToMessage.From.Id == _callback.From.Id)
                {
                    await BotClient.AnswerCallbackQueryAsync(_callback.Id, "Tunggu sebentar...");
                }
                else
                {
                    //Kamu tidak mempunyai hak untuk memencet tombol ini!
                    await BotClient.AnswerCallbackQueryAsync(_callback.Id, BotResponse.NoAccessToButton(), true);

                    return;
                }
            }

            // cari kontak yg ada
            var existContact = await _db.FindContact(_message.Chat.Id);

            if (string.IsNullOrWhiteSpace(data))
            {
                var buttons = new InlineKeyboardMarkup(new List <InlineKeyboardButton>
                {
                    InlineKeyboardButton.WithCallbackData("Aktifkan", $"cmd=greeting&data=enable"),
                    InlineKeyboardButton.WithCallbackData("Nonaktifkan", $"cmd=greeting&data=disable")
                });
                await BotClient.SendTextAsync(_message,
                                              $"Pengaturan ucapan selamat datang.\nStatus sekarang : " +
                                              (existContact.Greeting ? "aktif." : "nonaktif."),
                                              true, button : buttons);

                return;
            }

            var contact = new SQLite.Contact
            {
                Id       = _message.Chat.Id,
                Name     = _message.ChatName(),
                UserName = _message.Chat.Username,
                Private  = _message.Chat.Type == ChatType.Private,
                Blocked  = existContact.Blocked,
                Greeting = data.Equals("enable", StringComparison.OrdinalIgnoreCase)
            };

            var result = await _db.InsertOrReplaceContact(contact);

            if (!result)
            {
                return;
            }

            _log.Debug("Greeting {0} telah diperbaharui ({1})", _message.ChatName(), contact.Greeting);
            await BotClient.EditOrSendTextAsync(_message, _message.MessageId,
                                                $"Ucapan selamat datang telah " + (contact.Greeting ? "diaktifkan." : "dinonaktifkan."));
        }
Exemplo n.º 4
0
        private async void GetThreadPost(WebRequest threadRequest)
        {
            if (_callbackMode)
            {
                await BotClient.AnswerCallbackQueryAsync(_callback.Id, "Tunggu sebentar...");
            }

            string content;

            try
            {
                // akses thread/search
                content = await WebClient.GetOrPostStringAsync(threadRequest);

                // cek html atau kode alien?
                if (!content.Contains("html"))
                {
                    throw new Exception("Result bukan html!");
                }
            }
            catch (Exception e)
            {
                _log.Error(e.Message);
                await BotClient.SendTextAsync(_message, "Mohon maaf...\n" +
                                              "Plugin mobilism sedang mengalami gangguan.\n" +
                                              "Cobalah beberapa saat lagi.");

                return;
            }

            _log.Debug("Regex link download...");

            var pattern = "<div.+class=\"content\".+<span.*>(.+?)</span><br />.+" +
                          "Requirements:(.+?)<br />[\\s\\S]+" +
                          "Download Instructions:([\\s\\S]+?)</div>";

            var post = Regex.Match(content, pattern);

            if (!post.Success)
            {
                _log.Error("Post download tidak ditemukan!");
                await BotClient.SendTextAsync(_message, "Mohon maaf...\nPlugin mobilism tidak bisa membaca thread.");

                return;
            }

            _log.Debug("Menyiapkan link download...");

            var title   = post.Groups[1].Value.RemoveHtmlTag();
            var require = post.Groups[2].Value.RemoveHtmlTag();
            var link    = post.Groups[3].Value.RemoveHtmlTag(true);
            var request = _message.FromNameWithMention(ParseMode.Html, true);

            var respon = $"<b>{title}</b>" +
                         $"\n—— —— —— —— —— ——\n" +
                         $"Requirements : {require}\n" +
                         $"Download Instructions :\n{link}";

            if (_message.IsGroupChat())
            {
                respon = respon +
                         $"\n—— —— —— —— —— ——\n" +
                         $"Requested By : {request}";
            }

            await BotClient.SendTextAsync(_message, respon, parse : ParseMode.Html, preview : false);
        }