Beispiel #1
0
        static void Main(string[] args)
        {
            TaskScheduler.UnobservedTaskException      += TaskScheduler_UnobservedTaskException;
            AppDomain.CurrentDomain.UnhandledException += (s, e) =>
            {
                Console.WriteLine((e.ExceptionObject as Exception).Message);
            };
            var teamcityConfig = new Rest.TeamCity.ConfigurationProvider();
            var restClient     = new RestClient(
                teamcityConfig.Host,
                teamcityConfig.Login,
                teamcityConfig.Password,
                MediaType.Json);
            var tc               = new TeamCityApi(restClient);
            var gateway          = new Gateway(new[] { tc });
            var presenterFactory = new PresenterFactory();
            var output           = new Output(
                presenterFactory,
                new IOutputStream[] {
                new ConsoleStream(),
                new FileStream("log.txt")
            });
            var cancellationSource = new CancellationTokenSource();

            output.Write("build bot greetings you");
            output.Write("type exit to leave bot");

            var client   = new TelegramBotClient(new ConfigurationProvider().ApiKey);
            var commands = new List <CommandBase>
            {
                new StartCommand(cancellationSource),
                new ExitCommand(cancellationSource),
                new TeamcityGetBuildQueueCommand(gateway.For <ITeamCity>(), cancellationSource),
                new TeamcityGetProjectsCommand(gateway.For <ITeamCity>(), cancellationSource),
                new TeamcityGetProjectCommand(gateway.For <ITeamCity>(), cancellationSource),
                new TeamcityGetBranchesCommand(gateway.For <ITeamCity>(), cancellationSource),
                new TeamcityGetBuildsCommand(gateway.For <ITeamCity>(), cancellationSource),
                new TeamcityGetBuildTypesCommand(gateway.For <ITeamCity>(), cancellationSource),
                new TeamcityGetBuildCommand(gateway.For <ITeamCity>(), cancellationSource),
                new TeamcityGetAgentsCommand(gateway.For <ITeamCity>(), cancellationSource),
                new TeamcityEnqueueBuild(gateway.For <ITeamCity>(), cancellationSource),
                new TeamcityGetRunningBuildsCommand(gateway.For <ITeamCity>(), cancellationSource),
                new TeamcityEnqueueAgentCommand(gateway.For <ITeamCity>(), cancellationSource),
                new TeamcityGetBranchCommand(gateway.For <ITeamCity>(), cancellationSource)
            };
            var help = new HelpCommand(commands, cancellationSource);

            commands.Add(help);
            var commandsExecutor = new CommandsExecutor(commands);
            var inputStream      = new InputPipeline();
            var consoleListener  = new ConsoleCommandProducer(inputStream);
            var runLooper        = new RunLooper(inputStream, commandsExecutor, consoleListener, output, cancellationSource);
            var store            = new MemoryStore();

            using (var botWrapper = new BotWrapper(client, inputStream, presenterFactory, cancellationSource, commandsExecutor, output, store))
            {
                botWrapper.Start();
                runLooper.Run();
            }
        }
Beispiel #2
0
        public CommandResponse MyAddress(CommandEventArgs args)
        {
            BotWrapper.ActivateAddress(long.Parse(args.Target));
            var    address = BotWrapper.GetAddress(long.Parse(args.Target));
            string active  = address.IsNotificationEnabled ? "active" : "not active";

            return(new CommandResponse($"Your address `{address.Id}` is `{active}`", parseMode: Telegram.Bot.Types.Enums.ParseMode.Markdown));
        }
Beispiel #3
0
        public CommandResponse GetAll(CommandEventArgs args)
        {
            var address = BotWrapper.GetAddresses();

            if (address != null && address.Any())
            {
                return(new CommandResponse($"`{String.Join($"\n",address)}`", parseMode: Telegram.Bot.Types.Enums.ParseMode.Markdown));
            }
            else
            {
                return(new CommandResponse($"Here is empty. Press /start to add address to monitoring"));
            }
        }
Beispiel #4
0
        public CommandResponse GetAddress(CommandEventArgs args)
        {
            var address = BotWrapper.GetAddress(long.Parse(args.Target));

            if (address != null)
            {
                return(new CommandResponse($"I monitoring now `{address.Id}` for balance lower than `{address.BalanceLowerThan}`", parseMode: Telegram.Bot.Types.Enums.ParseMode.Markdown));
            }
            else
            {
                return(new CommandResponse($"Here is empty. Press /start to add address to monitoring"));
            }
        }
Beispiel #5
0
 public LanguageNode(BotWrapper botWrapper, MetaText requestMessage = null, MetaText answerMessage = null,
                     byte pageSize = 6, bool needBack = true) : base
     (
         new SelectSingleInputNode <string>(
             DefaultStrings.Language,
             DefaultStrings.Language,
             botWrapper.Languages,
             requestMessage == null ? null : new MetaDoubleKeyboardedMessage(requestMessage),
             pageSize, needBack: needBack),
         new ActionNode(
             (session) => session.Language = session.Vars.GetVar <string>(DefaultStrings.Language),
             answerMessage == null ? null : new MetaInlineMessage(answerMessage)
             )
     )
 {
     TailNode.SetParent(HeadNode);
 }
Beispiel #6
0
        static void Main(string[] args)
        {
            try
            {
                //var container = new UnityContainer();
                //ConfigureContainer(container);

                HostFactory.Run(c =>
                {
                    c.SetServiceName("Richard bot");
                    c.SetDisplayName("Richard bot");
                    c.SetDescription("Discord, twitch bot for lekker spelen fans");

                    c.UseNLog();

                    c.Service(factory =>
                    {
                        BotWrapper.Init().Wait();
                        QuartzServer server = QuartzServerFactory.CreateServer();
                        server.Initialize().Wait();
                        return(server);
                    });

                    c.EnablePauseAndContinue();

                    //install options
                    c.StartAutomatically(); // Start the service automatically
                    c.RunAsLocalService();  //Runs the service using the local system account.
                });
            }
            catch (Exception oei)
            {
                System.Console.Write(oei.StackTrace);
            }
#if DEBUG
            Console.WriteLine("Service stopped!");
            Console.ReadLine();
#endif
        }
 //  [ChatSurvey(Name = nameof(UserSurveyExample))]
 public override void SubmitSurvey(long userId, UserSurveyExample survey)
 {
     BotWrapper.SendMessageToAll($"User {userId} was submitted survey: \n```{JsonConvert.SerializeObject(survey)}```");
 }
Beispiel #8
0
        public CommandResponse GetActualBalance(CommandEventArgs args)
        {
            var address = BotWrapper.GetAddress(long.Parse(args.Target));

            return(new CommandResponse($"Your address `{address.Id}` balance is `{address.Balance}`", parseMode: Telegram.Bot.Types.Enums.ParseMode.Markdown));
        }
Beispiel #9
0
 protected override void OnEntityUpdated(Type entityType, object entityValue)
 {
     BotWrapper.SendMessageToAll($"{entityType.FullName} was updated {Emoji.Dice}");
 }