Esempio n. 1
0
        public static async Task StartBotsAsync(bool advancedModeDebugDisguised, bool runOnlyUserBot,
                                                bool runOnlyNormalBot)
        {
            var moderationBots = 0;
            var anonBots       = 0;

            GlobalVariables.Bots = new Dictionary <long, TelegramBotAbstract>();
            if (_botInfos != null && advancedModeDebugDisguised == false && runOnlyUserBot == false)
            {
                foreach (var bot in _botInfos)
                {
                    var botClient = new TelegramBotClient(bot.GetToken());
                    GlobalVariables.Bots[botClient.BotId] =
                        new TelegramBotAbstract(botClient, bot.GetWebsite(), bot.GetContactString(),
                                                BotTypeApi.REAL_BOT, bot.GetOnMessage().Item2);
                    if (!bot.AcceptsMessages())
                    {
                        continue;
                    }

                    var onmessageMethod2 = bot.GetOnMessage();
                    if (onmessageMethod2 == null || onmessageMethod2.Item1 == null)
                    {
                        continue;
                    }

                    botClient.OnMessage += onmessageMethod2.Item1;
                    botClient.StartReceiving(bot.GetAllowedUpdates());

                    if (bot.Callback())
                    {
                        botClient.OnCallbackQuery += bot.GetCallbackEvent();
                    }

                    if (onmessageMethod2.Item2 == BotStartMethods.Moderation)
                    {
                        moderationBots++;
                    }

                    if (onmessageMethod2.Item2 == BotStartMethods.Anon)
                    {
                        anonBots++;
                    }
                }
            }

            if (_userBotsInfos != null && advancedModeDebugDisguised == false && runOnlyNormalBot == false)
            {
                foreach (var userbot in _userBotsInfos)
                {
                    var client = await UserbotConnect.ConnectAsync(userbot);

                    var userId = userbot.GetUserId();
                    if (userId != null)
                    {
                        TelegramBotAbstract x2 = null;

                        try
                        {
                            x2 = new TelegramBotAbstract(client,
                                                         userbot.GetWebsite(), userbot.GetContactString(), userId.Value, BotTypeApi.USER_BOT,
                                                         userbot.GetOnMessage().Item2);
                        }
                        catch
                        {
                            ;
                        }

                        GlobalVariables.Bots[userId.Value] = x2;

                        var method = userbot.GetMethod();
                        if (method != null)
                        {
                            switch (method)
                            {
                            case 'a':
                            case 'A':     //Administration
                            {
                                _ = Bots.Administration.Main.MainMethodAsync(GlobalVariables.Bots[userId.Value]);
                                break;
                            }
                            }
                        }
                    }
                    else
                    {
                        try
                        {
                            client.Dispose();
                        }
                        catch
                        {
                            ;
                        }
                    }
                }
            }

            if (_botDisguisedAsUserBotInfos != null && advancedModeDebugDisguised && runOnlyUserBot == false &&
                runOnlyNormalBot == false)
            {
                foreach (var userbot in _botDisguisedAsUserBotInfos)
                {
                    var client = await UserbotConnect.ConnectAsync(userbot);

                    var userId = userbot.GetUserId();
                    if (userId != null)
                    {
                        GlobalVariables.Bots[userId.Value] = new TelegramBotAbstract(client,
                                                                                     userbot.GetWebsite(), userbot.GetContactString(), userId.Value,
                                                                                     BotTypeApi.DISGUISED_BOT, userbot.GetOnMessage().Item2);

                        _ = TestThingsDisguisedAsync(userId.Value);
                    }
                    else
                    {
                        try
                        {
                            client.Dispose();
                        }
                        catch
                        {
                            ;
                        }
                    }
                }
            }

            if (GlobalVariables.Bots.Keys.Count > 0 && moderationBots > 0)
            {
                var t = new Thread(ThreadAsync.DoThingsAsyncBot);
                t.Start();
            }

            if (GlobalVariables.Bots.Keys.Count > 0 && anonBots > 0)
            {
                var t = new Thread(Bots.Anon.ThreadAsync.DoThingsAsyncBotAsync);
                t.Start();
            }
        }
Esempio n. 2
0
        private static async Task StartBotsAsync(bool advancedModeDebugDisguised)
        {
            GlobalVariables.Bots = new Dictionary <long, TelegramBotAbstract>();
            if (_botInfos != null && advancedModeDebugDisguised == false)
            {
                foreach (var bot in _botInfos)
                {
                    var botClient = new TelegramBotClient(bot.GetToken());
                    GlobalVariables.Bots[botClient.BotId] =
                        new TelegramBotAbstract(botClient, bot.GetWebsite(), bot.GetContactString(),
                                                BotTypeApi.REAL_BOT);
                    if (!bot.AcceptsMessages())
                    {
                        continue;
                    }

                    var onmessageMethod = bot.GetOnMessage();
                    if (onmessageMethod == null)
                    {
                        continue;
                    }

                    botClient.OnMessage += onmessageMethod;
                    botClient.StartReceiving();
                }
            }

            if (_userBotsInfos != null && advancedModeDebugDisguised == false)
            {
                foreach (var userbot in _userBotsInfos)
                {
                    var client = await UserbotConnect.ConnectAsync(userbot);

                    var userId = userbot.GetUserId();
                    if (userId != null)
                    {
                        GlobalVariables.Bots[userId.Value] = new TelegramBotAbstract(client,
                                                                                     userbot.GetWebsite(), userbot.GetContactString(), userId.Value, BotTypeApi.USER_BOT);

                        _ = TestThingsAsync(userId.Value);
                    }
                    else
                    {
                        try
                        {
                            client.Dispose();
                        }
                        catch
                        {
                            ;
                        }
                    }
                }
            }

            if (_botDisguisedAsUserBotInfos != null && advancedModeDebugDisguised)
            {
                foreach (var userbot in _botDisguisedAsUserBotInfos)
                {
                    var client = await UserbotConnect.ConnectAsync(userbot);

                    var userId = userbot.GetUserId();
                    if (userId != null)
                    {
                        GlobalVariables.Bots[userId.Value] = new TelegramBotAbstract(client,
                                                                                     userbot.GetWebsite(), userbot.GetContactString(), userId.Value,
                                                                                     BotTypeApi.DISGUISED_BOT);

                        _ = TestThingsDisguisedAsync(userId.Value);
                    }
                    else
                    {
                        try
                        {
                            client.Dispose();
                        }
                        catch
                        {
                            ;
                        }
                    }
                }
            }

            if (GlobalVariables.Bots.Keys.Count > 0)
            {
                var t = new Thread(CheckMessagesToSend);
                t.Start();
            }
        }