예제 #1
0
        public static void saveLog(Message m, EmITBotNetContext db)
        {
            string log = string.Format("{0}\t{1}\tFrom {2} {3} ({4}, {5}) : {6}", new PersianDateTime(m.Date).Date.ToString("yyyy/MM/dd"), m.Date.TimeOfDay.ToHHMMSS(), m.Chat.FirstName, m.Chat.LastName, m.Chat.Username, m.Chat.Id, m.Text);

            Console.WriteLine(log);
            // ثبت لاگ سیستم در پایگاه داده
            db.MessageLogs.Add(new MessageLog()
            {
                SenderID        = m.From.Id,
                SenderUserName  = m.From.Username,
                Message         = m.Text,
                MessageDateTime = m.Date
            });
            db.SaveChanges();
        }
예제 #2
0
        public EmITBotNetRunner(EmITBotNetBase botBase)
        {
            string apikey;

            try
            {
                apikey = System.IO.File.ReadAllText("ApiKey.txt");
            }
            catch
            {
                Console.WriteLine("Error in reading Bot Api Key");
                Console.ReadLine();
                return;
            }

            bot = new TelegramBotClient(apikey);
            botBase.setBot(bot);

            try
            {
                //string userName = await bot.GetMeAsync().Result.Username;
                Console.WriteLine("I'm a Telegram Bot and my Name is " +
                                  bot.GetMeAsync().Result.Username +
                                  " and I'm ready");
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error : " + ex.Message);
                Console.ReadLine();
                return;
            }

            this.botBase         = botBase;
            this.db              = botBase.db;
            bot.OnMessage       += Bot_OnMessage;
            bot.OnCallbackQuery += Bot_OnCallbackQuery;
            bot.StartReceiving();

            Console.ReadLine();
        }