Example #1
0
        private static void LaunchBot(OurBot ourBot)
        {
            try
            {
                ourBot.TBot   = new TelegramBotClient(ourBot.Token);
                ourBot.Status = BotStatus.Offline;
            }
            catch (ArgumentException)
            {
                ourBot.Status = BotStatus.NotFound;
                return;
            }

            DBHelper.CheckDB(ourBot.TBot.GetMeAsync().Result.Username);
            ourBot.Scheme = SchemeBase.GetShemeFor(ourBot);
            ourBot.TBot.OnCallbackQuery += TBot_OnCallbackQuery;
            ourBot.TBot.OnMessage       += TBot_OnMessage;
            ourBot.TBot.StartReceiving();
            ourBot.Status = BotStatus.Online;
            if (!Bots.ContainsKey(ourBot.TBot))
            {
                Bots.Add(ourBot.TBot, ourBot);
            }
            else
            {
                Bots[ourBot.TBot] = ourBot;
            }
        }
Example #2
0
        public static void RegisterNewBot(string token, int ownerId, string schemeName)
        {
            var bot = new OurBot()
            {
                TBot       = new TelegramBotClient(token),
                Token      = token,
                OwnerId    = ownerId,
                SchemeName = schemeName
            };

            bot.Owner = DBHelper.GetBotOwner(bot);
            SchemeBase.GetShemeFor(bot);  // initialize scheme and store texts
            using (var db = DBHelper.GetConnection())
            {
                db.Insert(bot);
            }
            LaunchBot(bot);
            BotLaunched?.Invoke(null, new BotLaunchedArgs(bot));
        }