Esempio n. 1
0
        static void Main(string[] args)
        {
            var app = ShellHelper.CreateConsoleApp("cv4pve-botgram", "Telegram bot for Proxmox VE");

            var optToken = app.Option("--token", "Telegram API token bot", CommandOptionType.SingleValue)
                           .DependOn(app, CommandOptionExtension.HOST_OPTION_NAME);

            var optChatsId = app.Option("--chatsId", "Telegram Chats Id valid for communication (comma separated)", CommandOptionType.SingleValue);

            app.OnExecute(() =>
            {
                var chatsId = new List <long>();
                foreach (var chatId in (optChatsId.Value() + "").Split(","))
                {
                    if (long.TryParse(chatId, out var id))
                    {
                        chatsId.Add(id);
                    }
                }

                var botManager = new BotManager(app.GetHost().Value(),
                                                app.GetApiToken().Value(),
                                                app.GetUsername().Value(),
                                                app.GetPasswordFromOption(),
                                                optToken.Value(),
                                                chatsId.ToArray(),
                                                app.Out);
                botManager.StartReceiving();

                Console.ReadLine();

                try { botManager.StopReceiving(); }
                catch { }

                app.Out.WriteLine("End application");
            });

            app.ExecuteConsoleApp(args);
        }
        internal static void Commands(CommandLineApplication app)
        {
            var optToken = app.Option("--token", "Telegram API token bot", CommandOptionType.SingleValue)
                           .IsRequired();

            app.OnExecute(() =>
            {
                (PveHelper.Host, PveHelper.Port, PveHelper.Username, PveHelper.Password) = app.GetOptionsConnection();

                var botManager = new BotManager(optToken.Value());
                botManager.StartReceiving();

                Console.WriteLine($@"Start listening 
Telegram
  User: @{botManager.Username}
Proxmox VE
  Host: {PveHelper.Host}
  Username: {PveHelper.Username}");

                Console.ReadLine();
                botManager.StopReceiving();
                Console.WriteLine("End application");
            });
        }