Ejemplo n.º 1
0
        public void tritBOT()
        {
            while (stopThread != true)
            {
                string datelog2 = DateTime.Now.ToString("yyyy:MM:dd HH:mm:ss");

                DateTime time   = DateTime.Now;
                string   format = time.ToString("d");



                Pesan    pesen = new Pesan();
                SendMail email = new SendMail();

                Console.WriteLine("Initializing Bot...");
                bot = new TelegramBot(System.IO.File.ReadAllText("apikey.txt"));

                Console.WriteLine("Bot initialized.");
                Console.WriteLine("Hi, i'm {0}! ID: {1}", bot.Me.FirstName, bot.Me.Id);

                Console.WriteLine(" This Threat BOT  {0} ", datelog2);
                new Task(PollMessages).Start();


                Console.ReadLine();
                Thread.Sleep(durasi_pull);
            }
        }
Ejemplo n.º 2
0
        public async void PollMessages()
        {
            string datelog = DateTime.Now.ToString("yyyy:MM:dd HH:mm:ss");

            Pesan     pesen = new Pesan();
            DBConnect db    = new DBConnect();

            string CekJam = DateTime.Now.ToString("yyyy-MM-dd HH:mm");

            while (true)
            {
                var result = await bot.GetMessages();

                string datelog2 = DateTime.Now.ToString("yyyy:MM:dd HH:mm:ss");
                string jam      = DateTime.Now.ToString("HH:mm");



                foreach (Message m in result)
                {
                    if (m.Chat != null)
                    {
                        Console.WriteLine("[{0}] {1}: {2}", m.Chat.Title, m.From.Username, m.Text);
                    }
                    else
                    {
                        Console.WriteLine("{0}: {1}", m.From.Username, m.Text);
                    }

                    HandleMessage(m);
                    //pesen.HandleMessage(m);
                }

                Console.WriteLine("Bot Running -> {0}", datelog2);
            }
        }
Ejemplo n.º 3
0
        public void HandleMessage(Message pesan)
        {
            DBConnect db = new DBConnect();

            MessageTarget target     = ((MessageTarget)pesan.Chat ?? pesan.From);
            Pesan         pesanClass = new Pesan();

            if (pesan.Text == null)
            {
                return;
            }
            else
            {
                Int32  targetID = target.Id;            //klo minus berarti group
                Int32  idFrom   = pesan.From.Id;        //id pengirim chat user
                string First    = pesan.From.FirstName; //first name pengirim chat
                string last     = pesan.From.LastName;  // last name pengirim chat
                string usernmae = pesan.From.Username;  //username pengirim chat
                Int32  chatid   = pesan.MessageId;      //id pesan
                string botname  = bot.Me.FirstName;     //nama bot

                string tipe      = null;
                string namagroup = target.ToString();

                string[] pecahGroup = namagroup.Split('.');

                tipe = pecahGroup[2].ToString();

                if (pesan.Text == "#")
                {
                    return;
                }

                string txt = pesanClass.filterPesan(pesan.Text, idFrom, First, last, usernmae, chatid);

                db.InsertChat(chatid.ToString(), idFrom.ToString(), pesan.Text.ToString(), botname.ToString(), tipe.ToString(), null, chatid.ToString());

                //messageid,userid,text,botname,type,replymessage_id,updateid


                if (txt == null)
                {
                    string messageToSend = "Maaf Format Pesan " + pesan.From.Username + " Salah Silahkan Ulangi kembali dengan Format: " + FORMAT_PESAN;

                    // bot.SendMessage(target, messageToSend, false, pesan, new ForceReplyOptions(true));
                }
                else
                {
                    string[] pecah         = txt.Split('|');
                    string   messageToSend = null;

                    #region swit
                    switch (pecah[0].ToString())
                    {
                    case "WRONG":
                        messageToSend = "Maaf Format Pesan " + pesan.From.FirstName + " Salah Silahkan Ulangi kembali dengan Format: " + FORMAT_PESAN;
                        //bot.SendMessage(target, messageToSend, false, pesan, new ForceReplyOptions(true));
                        bot.SendMessage(target, messageToSend);


                        break;

                    case "SAVE":
                        messageToSend = "Terima kasih Bapak atau Ibu " + pesan.From.FirstName.ToUpper() + " Laporan anda kami terima ";
                        //bot.SendMessage(target, messageToSend, false, pesan, new ForceReplyOptions(true));
                        bot.SendMessage(target, messageToSend);

                        break;

                    case "RegisOn":
                        messageToSend = "Maaf " + pesan.From.FirstName + " Anda Sudah Terdaftar di System";
                        // bot.SendMessage(target, messageToSend, false, pesan, new ForceReplyOptions(true));
                        bot.SendMessage(target, messageToSend);

                        break;

                    case "RegisSuccess":
                        messageToSend = "Proses Registrasi Akun Anda Berhasil Terima kasih, " + pesan.From.FirstName.ToUpper();

                        //bot.SendMessage(target, messageToSend, false, pesan, new ForceReplyOptions(true));
                        bot.SendMessage(target, messageToSend);

                        break;

                    case "ME":
                        string message = "\xF0\x9F\x98\x81";
                        string encode  = RestSharp.Contrib.HttpUtility.UrlEncode(message);
                        messageToSend = " Hai \n1.ID anda=" + idFrom + " ,\n2.Firstname=" + First + " , \n3.lastname=" + last + ", \n4.username="******"LaporanSudahAda":
                        messageToSend = "Anda Sudah Mengirim 5 Laporan hari ini Bapak/Ibu  ," + pesan.From.FirstName + " Maaf Laporan anda kami tolak ";
                        // bot.SendMessage(target, messageToSend, false, pesan, new ForceReplyOptions(true));
                        bot.SendMessage(target, messageToSend);

                        break;

                    case "LaporanTersimpan":
                        messageToSend = "Terima kasih Bapak atau Ibu  " + pesan.From.FirstName.ToUpper() + " Laporan anda kami terima ";
                        //bot.SendMessage(target, messageToSend, false, pesan, new ForceReplyOptions(true));
                        bot.SendMessage(target, messageToSend);

                        pesanClass.ForWardMessage("Laporan dari Bapak atau Ibu " + pesan.From.FirstName.ToUpper() + " \n deskripsi laporan : \n" + pesan.Text);
                        pesanClass.ForWardMessage2("Laporan dari  Bapak atau /Ibu " + pesan.From.FirstName.ToUpper() + " \n deskripsi laporan : \n" + pesan.Text);

                        //pesanClass.ForWardMessage("136331911",);

                        break;

                    case "HELP":
                        messageToSend = "Hai Perkenankan Saya Adalah Assiten kalian saat ini aku Versi 1.0,"
                                        + "\nBiasanya orang orang menyebut ku BOT atau Robot "
                                        + "\nTugas ku adalah untuk membantu mencatat apa yang kalian kerjakan dan mengingatkan kalian\n "
                                        + "\nUntuk Mencatat laporan kalian aku perlu beberapa parameter khusus "
                                        + "\nAgar aku bisa membedakan mana perintah kalian yang perlu aku catat dan tidak perlu aku catat.\n"
                                        + "\n1.Format yang aku catat untuk laporan sbb:"
                                        + "\n\nkepada siapa#laporan#judul laporan#isi laporan\n"
                                        + "\nbaiklah sekarang akan aku contohkan dalam penulisan nya. contohnya dibawah ini\n"
                                        + "\nkepada yth camat Tamansari perihal#laporan#kinerja ku dihari senin 25 April 2015#kegiatan kerja 27 april 2016# hr ini telah melaksanakan agenda surat masuk dan agenda surat keluar Hormat saya Bapak Budi."
                                        + "\n\n\n2.selain mencatat laporan harian kalian kalian bisa menggunakan perintah \n"
                                        + "\n 2.1. #me ( perintah yg anda ketik) untuk mengetahui detail akun anda pribadi "
                                        + "\n 2.2. #register (perintah yang anda ketik) untuk mendaftarkan Data anda di system aku."
                                        + "\n\n3. Oh iya Pesan yang sekarang kalian terima ini hanya bisa dipanggil dengan perintah #help"
                                        + "\n\n Hatur nuhun. ";

                        // bot.SendMessage(target, messageToSend, false, pesan, new ForceReplyOptions(true));
                        bot.SendPhoto(target, new FileStream("perhatian.png", FileMode.Open), "Versi 1.0", "perhatian.png");
                        bot.SendMessage(target, messageToSend);


                        break;

                    default:

                        break;
                    }
                    #endregion

                    Int32  targetID2 = target.Id;            //klo minus berarti group
                    Int32  idFrom2   = pesan.From.Id;        //id pengirim chat user
                    string First2    = pesan.From.FirstName; //first name pengirim chat
                    string last2     = pesan.From.LastName;  // last name pengirim chat
                    string username2 = pesan.From.Username;  //username pengirim chat
                    Int32  chatid2   = pesan.MessageId;      //id pesan
                    string botname2  = bot.Me.FirstName;     //nama bot

                    string tipe2      = null;
                    string namagroup2 = target.ToString();

                    string[] pecahGroup2 = namagroup2.Split('.');

                    tipe2 = pecahGroup2[2].ToString();



                    db.InsertChat(chatid2.ToString(), idFrom2.ToString(), messageToSend, botname2.ToString(), tipe2.ToString(), chatid2.ToString(), chatid2.ToString());
                }
            }
        }//end void
Ejemplo n.º 4
0
        public void JustInfo()
        {
            string CekDate = DateTime.Now.ToString("yyyy-MM-dd 15:00");
            string hari    = DateTime.Now.ToString("dd-MM-yyyy");


            DateTime time   = DateTime.Now;
            string   format = time.ToString("d");

            string cs = @"server=localhost;userid=root;
            password="******";database=telegram-tamansari";

            MySqlConnection conn  = null;
            MySqlConnection conn2 = null;

            MySqlDataReader rdr  = null;
            MySqlDataReader rdr2 = null;

            conn  = new MySqlConnection(cs);
            conn2 = new MySqlConnection(cs);

            conn.Open();
            string stm = " SELECT id,first_name FROM user ";

            MySqlCommand cmd = new MySqlCommand(stm, conn);

            cmd.Parameters.AddWithValue("@waktu", format);
            rdr = cmd.ExecuteReader();

            while (rdr.Read())
            {
                string id_telegram = rdr[0].ToString();
                string firstname   = rdr[1].ToString();


                try
                {
                    string       sql  = " SELECT * FROM alert WHERE userid!=@id and  DATE_FORMAT(created_at,'%d/%m/%Y')=@waktu";
                    MySqlCommand cmd2 = new MySqlCommand(sql, conn2);
                    conn2.Open();
                    cmd2.Parameters.AddWithValue("@id", id_telegram);
                    cmd2.Parameters.AddWithValue("@waktu", format);
                    rdr2 = cmd2.ExecuteReader();

                    if (rdr2.HasRows)
                    {
                    }
                    else
                    {
                        string messageToSend = "Bapak / Ibu " + firstname.ToUpper() + " Yth , Sekedar mengingatkan u ";

                        string TOKEN = Token();

                        InsertAlert(id_telegram, messageToSend);

                        Pesan pesan = new Pesan();

                        pesan.pm(TOKEN, id_telegram, messageToSend);
                    }
                    conn2.Close();
                }
                catch (Exception error)
                {
                    conn.Close();
                    Log log = new Log();
                    log.CreateLog("error-alert", error.StackTrace, error.Message, null);

                    SendMail mail = new SendMail();
                    mail.SendEmailKeIT("Error alert", error.Message);
                }
            }
            rdr2.Dispose();

            rdr.Dispose();
            conn.Close();
            conn2.Close();
        }
Ejemplo n.º 5
0
        public void Alert()
        {
            string CekDate = DateTime.Now.ToString("yyyy-MM-dd 15:00");
            string hari    = DateTime.Now.ToString("dd-MM-yyyy");


            DateTime time   = DateTime.Now;
            string   format = DateTime.Now.ToString("dd/MM/yyyy");

            string cs = @"server=localhost;userid=root;
            password="******";database=telegram-tamansari";

            MySqlConnection conn  = null;
            MySqlConnection conn2 = null;

            MySqlDataReader rdr = null;

            conn  = new MySqlConnection(cs);
            conn2 = new MySqlConnection(cs);

            conn.Open();
            string stm = " SELECT id,first_name FROM user WHERE id NOT IN "
                         + "( "
                         + "   SELECT userid FROM laporan "
                         + "   WHERE DATE_FORMAT(created_at,'%d/%m/%Y')='" + format + "'"
                         + " ) and  id!='206390585' ORDER BY first_name ASC";

            MySqlCommand cmd = new MySqlCommand(stm, conn);

            //cmd.Parameters.AddWithValue("@waktu", format);
            rdr = cmd.ExecuteReader();

            while (rdr.Read())
            {
                string id_telegram = rdr[0].ToString();
                string firstname   = rdr[1].ToString();


                try
                {
                    #region off
                    //string sql = " SELECT * FROM alert WHERE userid=@id and  DATE_FORMAT(created_at,'%d/%m/%Y')=@waktu";
                    //MySqlCommand cmd2 = new MySqlCommand(sql, conn2);
                    //conn2.Open();
                    //cmd2.Parameters.AddWithValue("@id", id_telegram);
                    //cmd2.Parameters.AddWithValue("@waktu", format);
                    //rdr2 = cmd2.ExecuteReader();

                    //if (rdr2.HasRows)
                    //{

                    //    string messageToSend = "Bapak / Ibu " + firstname.ToUpper() + " Anda Belum Melaporkan Pekerjaan Dinas Harian " + hari +" Mohon Untuk Segera Mengirimkan Laporan tks";

                    //    string TOKEN = Token();

                    //    InsertAlert(id_telegram, messageToSend);

                    //    Pesan pesan = new Pesan();

                    //    pesan.pm(TOKEN, id_telegram, messageToSend);

                    //}
                    //else
                    //{
                    //    string messageToSend = "Bapak / Ibu " + firstname.ToUpper() + " Anda Belum Melaporkan Pekerjaan Dinas Harian " + hari + " Mohon Untuk Segera Mengirimkan Laporan tks";

                    //    string TOKEN = Token();

                    //    InsertAlert(id_telegram, messageToSend);

                    //    Pesan pesan = new Pesan();

                    //    pesan.pm(TOKEN, id_telegram, messageToSend);


                    //}
                    #endregion
                    Log log = new Log();
                    log.CreateLog("alert", id_telegram, firstname + "| " + stm, null);

                    string messageToSend = "Bapak / Ibu " + firstname.ToUpper() + ", \nAnda Belum Melaporkan Pekerjaan Dinas Harian " + hari + " Mohon Untuk Segera Mengirimkan Laporan \nTerima kasih";

                    string TOKEN = Token();

                    InsertAlert(id_telegram, messageToSend);

                    Pesan pesan = new Pesan();

                    pesan.pm(TOKEN, id_telegram, messageToSend);
                    conn2.Close();
                }
                catch (Exception error)
                {
                    conn.Close();
                    Log log = new Log();
                    log.CreateLog("error-alert", error.StackTrace, error.Message, null);

                    SendMail mail = new SendMail();
                    mail.SendEmailKeIT("Error alert", error.Message);
                }
            }
            //rdr2.Dispose();

            rdr.Dispose();
            conn.Close();
            // conn2.Close();
        }