Exemplo n.º 1
0
        private static async void ExecuteTask(ScheduleData data)
        {
            _log.Debug("Eksekusi schedule: {0}", data.MessageId);

            switch (data.Operation)
            {
            case ScheduleData.Type.Delete:
                await BotClient.DeleteMessageAsync(data.ChatId, data.MessageId);

                break;

            case ScheduleData.Type.Edit:
                await BotClient.EditOrSendTextAsync(data.ChatId, data.MessageId, data.Text, data.ParseMode,
                                                    sendOnError : false);

                break;

            case ScheduleData.Type.Done:
                return;

            default:
                return;
            }

            data.Operation = ScheduleData.Type.Done;
            await _db.InsertOrReplaceSchedule(data);
        }
Exemplo n.º 2
0
        public async void Reload()
        {
            if (!_message.IsGodMode())
            {
                await BotClient.SendTextAsync(_message, "Kamu siapa? Kok berani-beraninya nyuruh aku 😡😡");

                return;
            }

            _message = await BotClient.SendTextAsync(_message, "Please wait...", true);

            await LoadLibraryAsync();

            await BotClient.EditOrSendTextAsync(_message, _message.MessageId, "Okey, it's done...");
        }
Exemplo n.º 3
0
        public async void GetMedia(string data)
        {
            if (!_message.IsPrivateChat())
            {
                return;
            }

            var matchUrl = Regex.Match(data, @"(https?://www.facebook\.com/.*[0-9]+/?)");

            if (!matchUrl.Success)
            {
                await BotClient.SendTextAsync(_message, "Link facebook salah?", true);

                return;
            }
            var facebookUrl = matchUrl.Groups[1].Value;

            _log.Debug("Found link : {0}", facebookUrl);

            _message = await BotClient.SendTextAsync(_message, "Tunggu sebentar...", true);

            try
            {
                var videourl = await GetVideoUrl(facebookUrl);

                if (string.IsNullOrWhiteSpace(videourl))
                {
                    _log.Debug("Video not available!");

                    await BotClient.EditOrSendTextAsync(_message.Chat.Id, _message.MessageId, "Gak ada videonya!");

                    return;
                }

                _log.Debug("Found video : {0}", videourl);

                await BotClient.SendVideoAsync(_message, videourl);
            }
            catch (Exception e)
            {
                _log.Error(e.Message);
                await BotClient.EditOrSendTextAsync(_message.Chat.Id, _message.MessageId, e.Message);
            }
        }
Exemplo n.º 4
0
        public async void DeleteWithButton(string hashtag, bool final = false)
        {
            if (!_callbackMode)
            {
                return;
            }
            if (_message.ReplyToMessage.From.Id == _callback.From.Id)
            {
                await SendCallbackResponse("Tunggu sebentar...");
            }
            else
            {
                await SendCallbackResponse(BotResponse.NoAccessToButton(), true);

                return;
            }

            if (!final)
            {
                var buttons = new InlineKeyboardMarkup(new List <InlineKeyboardButton>
                {
                    InlineKeyboardButton.WithCallbackData("Yakin", $"cmd=remove-final&data={hashtag}"),
                    InlineKeyboardButton.WithCallbackData("Tidak", $"cmd=manage&data=null")
                });

                await BotClient.EditOrSendTextAsync(_message, _message.MessageId,
                                                    $"Apakah kamu yakin mau menghapus #{hashtag}?",
                                                    button : buttons);
            }
            else
            {
                await Delete(hashtag);

                ManageList();
            }
        }
Exemplo n.º 5
0
        public async void ManageList()
        {
            if (!_callbackMode)
            {
                // harus grup chat
                if (await IsNotInGroup())
                {
                    return;
                }

                // cek admin atau bukan
                if (await IsNotAdmin())
                {
                    return;
                }
            }
            else
            {
                if (_message.ReplyToMessage.From.Id == _callback.From.Id)
                {
                    await SendCallbackResponse("Tunggu sebentar...");
                }
                else
                {
                    await SendCallbackResponse(BotResponse.NoAccessToButton(), true);

                    return;
                }
            }

            var list = await _db.GetBookmarks(_message.Chat.Id);

            if (list.Count == 0)
            {
                _log.Ignore("Tidak ada list di {0}", _message.ChatName());

                var norespon = "Bookmark/Hashtag *kosong*.";
                if (_callbackMode)
                {
                    await BotClient.EditOrSendTextAsync(_message, _message.MessageId, norespon, ParseMode.Markdown);
                }
                else
                {
                    await BotClient.SendTextAsync(_message, norespon, parse : ParseMode.Markdown);
                }

                return;
            }

            var respon = $"<b>Kelola Bookmark</b>\n" +
                         $"Total : {list.Count} hashtag";
            var buttonRows = new List <List <InlineKeyboardButton> >();

            foreach (var hashtag in list.OrderBy(h => h.KeyName))
            {
                var buttonColumns = new List <InlineKeyboardButton>
                {
                    InlineKeyboardButton.WithCallbackData(hashtag.KeyName, $"cmd=info&data={hashtag.KeyName}"),
                    InlineKeyboardButton.WithCallbackData("Hapus", $"cmd=remove&data={hashtag.KeyName}")
                };
                buttonRows.Add(buttonColumns);
            }

            var     buttons = new InlineKeyboardMarkup(buttonRows.ToArray());
            Message sentMessage;

            if (_callbackMode)
            {
                sentMessage =
                    await BotClient.EditOrSendTextAsync(_message, _message.MessageId, respon, ParseMode.Html, buttons);
            }
            else
            {
                sentMessage = await BotClient.SendTextAsync(_message, respon, true, ParseMode.Html, buttons);
            }

            if (sentMessage == null)
            {
                return;
            }

            // schedule edit pesan keluar
            var schedule = new ScheduleData
            {
                ChatId    = sentMessage.Chat.Id,
                MessageId = sentMessage.MessageId,
                DateTime  = DateTime.Now.AddMinutes(30),
                Operation = ScheduleData.Type.Edit,
                Text      = "Perintah ini telah kadaluarsa.",
                ParseMode = ParseMode.Html
            };

            Schedule.RegisterNew(schedule);
        }
Exemplo n.º 6
0
        public async void GenerateList(bool useButton, bool update = false)
        {
            if (!update)
            {
                // harus grup chat
                if (await IsNotInGroup())
                {
                    return;
                }
            }
            else if (_callbackMode)
            {
                await SendCallbackResponse("Tunggu sebentar...");
            }

            var list = await _db.GetBookmarks(_message.Chat.Id);

            if (list.Count == 0)
            {
                _log.Ignore("Tidak ada list di {0}", _message.ChatName());

                var respon =
                    "Bookmark/Hashtag *kosong*.\nTapi kamu bisa panggil semua admin di grup ini dengan #admin atau #mimin.";
                await BotClient.SendTextAsync(_message, respon, parse : ParseMode.Markdown);

                return;
            }

            if (!useButton)
            {
                var count   = 1;
                var padding = list.Count.ToString().Length;
                var respon  = $"<b>Daftar Hashtag</b>\nGenerated : {DateTime.Now}\nTotal : {list.Count}\n—— —— —— ——";
                foreach (var hashtag in list.OrderBy(h => h.KeyName))
                {
                    var num = count.ToString().PadLeft(padding, '0');
                    respon += $"\n{num}. #{hashtag.KeyName}";
                    count++;
                }

                var sentMessage = await BotClient.SendTextAsync(_message, respon, parse : ParseMode.Html);

                if (sentMessage == null)
                {
                    return;
                }
                var schedule = new ScheduleData
                {
                    ChatId    = _message.Chat.Id,
                    MessageId = sentMessage.MessageId,
                    DateTime  = DateTime.Now.AddMinutes(10),
                    Operation = ScheduleData.Type.Edit,
                    Text      = "Daftar hashtag kadaluarsa!\nGunakan /hashtag untuk melihat daftar lagi."
                };
                Schedule.RegisterNew(schedule);
            }
            else
            {
                var respon     = $"<b>Daftar Bookmark</b>\nGenerated : {DateTime.Now}\nTotal : {list.Count}";
                var buttonRows = new List <List <InlineKeyboardButton> >();

                // tombol update -- atas
                var updateButton = new List <InlineKeyboardButton>
                {
                    InlineKeyboardButton.WithCallbackData("🔄 Perbarui Bookmark 🔄", $"cmd=generate&data=null")
                };
                buttonRows.Add(updateButton);

                foreach (var hashtag in list.OrderBy(h => h.KeyName))
                {
                    var buttonColumns = new List <InlineKeyboardButton>();

                    // private grup tdk punya username
                    if (string.IsNullOrWhiteSpace(_message.Chat.Username))
                    {
                        var button =
                            InlineKeyboardButton.WithCallbackData(hashtag.KeyName, $"cmd=call&data=" + hashtag.KeyName);
                        buttonColumns.Add(button);
                    }
                    else
                    {
                        var button =
                            InlineKeyboardButton.WithUrl(hashtag.KeyName,
                                                         $"https://t.me/{_message.Chat.Username}/{hashtag.MessageId}");
                        buttonColumns.Add(button);
                    }

                    buttonRows.Add(buttonColumns);
                }

                // tombol update -- bawah
                buttonRows.Add(updateButton);

                var buttons = new InlineKeyboardMarkup(buttonRows.ToArray());

                if (!update)
                {
                    await BotClient.SendTextAsync(_message, respon, parse : ParseMode.Html, button : buttons);
                }
                else
                {
                    await BotClient.EditOrSendTextAsync(_message, _message.MessageId, respon, ParseMode.Html, buttons);
                }
            }
        }
Exemplo n.º 7
0
        public async void GetMedia(string data)
        {
            if (!_message.IsPrivateChat())
            {
                return;
            }

            if (_twitter == null)
            {
                await BotClient.SendTextAsync(_message,
                                              "Tolong, bilang ke admin paijem suruh isi auth token twitter. Terima kasih");

                return;
            }

            var regex = Regex.Match(data, @"twitter.com\/.*status\/([0-9]+)");

            if (!regex.Success)
            {
                return;
            }

            ulong.TryParse(regex.Groups[1].Value, out ulong statusId);

            _log.Debug("Found twitter id : {0}", statusId);

            _message = await BotClient.SendTextAsync(_message, "Tunggu sebentar...", true);

            var status = await _twitter.Status
                         .Where(x => x.ID == statusId && x.Type == StatusType.Show && x.TweetMode == TweetMode.Extended)
                         .SingleOrDefaultAsync();

            var foundVideo = false;

            foreach (var media in status?.ExtendedEntities?.MediaEntities)
            {
                if (media.Type != "video")
                {
                    continue;
                }

                foundVideo = true;
                var video = media.VideoInfo?.Variants
                            .Where(x => x.ContentType == "video/mp4")
                            .OrderByDescending(x => x.BitRate)
                            .First();

                _log.Debug("Found video : {0}", video.Url);

                await BotClient.SendVideoAsync(_message, video.Url, media.MediaUrlHttps, status.FullText);
            }

            if (foundVideo)
            {
                await BotClient.DeleteMessageAsync(_message.Chat.Id, _message.MessageId);
            }
            else
            {
                await BotClient.EditOrSendTextAsync(_message, _message.MessageId, "Gak ada videonya!");
            }
        }
Exemplo n.º 8
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.º 9
0
        public async void GetKeys()
        {
            _message = await BotClient.SendTextAsync(_message, "Tunggu sebentar ya...", true);

            try
            {
                _log.Debug("Mengakses {0}", apiUrl);

                var request = new WebRequest
                {
                    Url    = apiUrl,
                    Method = WebMethod.Get
                };
                var response = await WebClient.GetOrPostStringAsync(request);

                _log.Debug("Parsing key eset...");

                var result = string.Empty;
                var found  = false;

                // regex table
                var mTable = Regex.Matches(response, @"(<thead[\s\S]*?</tbody>)");
                _log.Debug("Found : {0} Product", mTable.Count);
                foreach (Match table in mTable)
                {
                    // regex product
                    var rName = Regex.Match(table.Groups[1].Value, "<h3>(.*)</h3>");
                    if (!rName.Success)
                    {
                        continue;
                    }

                    _log.Debug("Product : {0}", rName.Groups[1].Value);
                    result += string.Format("<b>{0}</b>\n", rName.Groups[1].Value);

                    // regex key
                    var mRow = Regex.Matches(table.Groups[1].Value, @"(<tr>[\s\S]*?</tr>)");
                    foreach (Match row in mRow)
                    {
                        var rKey = Regex.Match(row.Groups[1].Value, @"td.*>(.*)</td.*\s<td.*>(.*)</td(?:.*\s<td.*>(.*)</td)?");
                        if (!rKey.Success)
                        {
                            continue;
                        }

                        _log.Debug("Key : {0}", rKey.Groups[1].Value);

                        found = true;
                        var key = string.Empty;

                        if (string.IsNullOrWhiteSpace(rKey.Groups[3].Value))
                        {
                            key = string.Format("<code>{0}</code> | {1}", rKey.Groups[1].Value, rKey.Groups[2].Value);
                        }
                        else
                        {
                            key = string.Format("<code>{0} : {1}</code> | {2}", rKey.Groups[1].Value, rKey.Groups[2].Value, rKey.Groups[3].Value);
                        }

                        result += string.Format("» {0}\n", key);
                    }
                    result += "\n";
                }

                // footer
                result += "—— —— —— —— —— ——\n";

                // regex title
                var rTitle = Regex.Match(response, "<h2.*title.*>(.*)</h2>");
                if (rTitle.Success)
                {
                    result += rTitle.Groups[1].Value + Environment.NewLine;
                }

                // footer end
                result += "Compatibility keys: <code>ESSP</code> > <code>EIS</code> > <code>ESS</code> > <code>EAV</code>.\n" +
                          "<i>This means that the EIS key is suitable for ESS and EAV. ESSP is a universal key.</i>";

                if (!found)
                {
                    result = "Mohon maaf... Key tidak tersedia!";
                }

                await BotClient.EditOrSendTextAsync(_message, _message.MessageId, result, ParseMode.Html);
            }
            catch (Exception e)
            {
                _log.Error(e.Message);

                await BotClient.EditOrSendTextAsync(_message, _message.MessageId,
                                                    "Mohon maaf...\nPlugin eset saat ini sedang mengalami gangguan!");

                return;
            }
        }
Exemplo n.º 10
0
        public async void GetLatestRelease(string data)
        {
            Gapps gapps;
            var   value = await GetOption(data);

            if (value.Error)
            {
                return;
            }

            _log.Debug("Platform: {0} | Android: {1} | Variant: {2} | Cari gapps...", value.Arch, value.Android, value.Variant);

            try
            {
                var client = new RestClient("https://api.opengapps.org/list");
                var req    = new RestRequest();
                req.AddHeader("Sec-Fetch-Mode", "cors");
                req.AddHeader("Referer", "https://opengapps.org/");
                req.AddHeader("Origin", "https://opengapps.org");
                req.AddHeader("User-Agent", App.UserAgent);
                req.AddHeader("DNT", "1");

                _message = await BotClient.SendTextAsync(_message, "Tunggu sebentar, aku carikan dulu...");

                _log.Debug("Getting json from api...");
                var res = await client.ExecuteTaskAsync(req);

                gapps = JsonConvert.DeserializeObject <Gapps>(res.Content);
            }
            catch (Exception e)
            {
                _log.Error(e.Message);

                await BotClient.EditOrSendTextAsync(_message, _message.MessageId,
                                                    "Mohon maaf...\nPlugin opengapps saat ini sedang mengalami gangguan!");

                return;
            }

            var textResult = $"*OpenGapps*\n—— —— ——\n" +
                             $"Platform : `{value.Arch}`\n" +
                             $"Android : `{value.Android}`\n";

            if (string.IsNullOrWhiteSpace(value.Variant))
            {
                textResult += $"Variant : `all`";
            }
            else
            {
                textResult += $"Variant : `{value.Variant}`";
            }

            var listGapps = new List <Tuple <string, string> >();

            foreach (var propArch in typeof(Archs).GetProperties())
            {
                if (propArch.Name != value.Arch)
                {
                    continue;
                }

                var arch = (Arch)propArch.GetValue(gapps.archs);
                if (arch == null)
                {
                    continue;
                }

                textResult += $"\nRelease : `{arch.date}`";
                foreach (var propAndroid in typeof(Apis).GetProperties())
                {
                    if (propAndroid.GetJsonPropertyName() != value.Android)
                    {
                        continue;
                    }

                    var package = (Variants)propAndroid.GetValue(arch.apis);
                    if (package == null)
                    {
                        continue;
                    }

                    foreach (var variant in package.variants)
                    {
                        if (!string.IsNullOrWhiteSpace(value.Variant) && variant.name != value.Variant)
                        {
                            continue;
                        }

                        listGapps.Add(new Tuple <string, string>(variant.name, variant.zip));
                    }
                }
            }

            var buttonRows = new List <List <InlineKeyboardButton> >();

            if (listGapps.Count == 0)
            {
                textResult += $"\n—— —— ——\nTidak ada atau tidak ketemu!";
                var buttonLink = new List <InlineKeyboardButton>
                {
                    InlineKeyboardButton.WithUrl("Visit Website!", "https://opengapps.org")
                };
                buttonRows.Add(buttonLink);
            }
            else if (listGapps.Count == 1)
            {
                var name       = Path.GetFileName(listGapps[0].Item2);
                var buttonLink = new List <InlineKeyboardButton>
                {
                    InlineKeyboardButton.WithUrl(name, listGapps[0].Item2)
                };
                buttonRows.Add(buttonLink);
            }
            else
            {
                var skip = 0;
                while (true)
                {
                    var take = listGapps.Skip(skip).Take(3);
                    if (take.Count() == 0)
                    {
                        break;
                    }

                    var buttonRow = new List <InlineKeyboardButton>();
                    foreach (var t in take)
                    {
                        buttonRow.Add(InlineKeyboardButton.WithUrl(t.Item1, t.Item2));
                    }

                    buttonRows.Add(buttonRow);
                    skip += 3;
                }
            }

            var buttons = new InlineKeyboardMarkup(buttonRows.ToArray());
            await BotClient.EditOrSendTextAsync(_message, _message.MessageId, textResult, ParseMode.Markdown, buttons, false);
        }