Example #1
0
        public BotHostModule(Bot bot, SprocketManager sprockets, IEnumerable<ISprocketInitializer> sprocketInitializers)
            : base("bot")
        {
            _bot = bot;
            _sprockets = sprockets;
            _sprocketInitializers = sprocketInitializers;

            Get["/start"] = _ =>
            {
                try
                {
                    StartBot();

                    return "Bot Started";
                }
                catch (Exception e)
                {
                    return e.Message;
                }
            };

            Get["/stop"] = _ =>
            {
                try
                {
                    ShutDownBot();
                    return "Bot Shut Down";
                }
                catch (Exception e)
                {
                    return e.Message;
                }
            };

            // This is for ensuring that the process doesn't die permanently --
            // We create a task with MomentApp (TBD whether we will use this permanently
            Get["/keepalive"] = _ =>
            {
                ScheduleKeepAlive(Request.Url.ToString());
                return "OK";
            };

            Get["/launch"] = _ =>
            {
                //TODO: verify there is an auth token
                LoadCoffeeScript();
                return "";
            };

            Post["/join"] = _ =>
                                {
                                    _bot.Join(Request.Form.Room);
                                    return Response.AsRedirect("/Rooms");
                                };

            Get["/leave"] = _ =>
                                {
                                    _bot.Leave(Request.Query.Room);
                                    return Response.AsRedirect("/Rooms");
                                };
            Post["/send/{room}"] = _ =>
                                       {
                                           _bot.Say(Request.Form.Message, _.Room);
                                           return Response.AsRedirect("/");
                                       };

            Post["/attach"] = _ =>
                                  {
                                      AttachScript(Request.Form.script);
                                      return Response.AsRedirect("/");
                                  };

            Post["/disable/{sprocket}"] = _ =>
                                              {
                                                  var sprocket = sprockets[_.Sprocket];
                                                  _bot.DisableSprocket(sprocket);
                                                  return Response.AsRedirect("/");
                                              };

            Post["/enable/{sprocket}"] = _ =>
                                              {
                                                  var sprocket = sprockets[_.Sprocket];
                                                  _bot.EnableSprocket(sprocket);
                                                  return Response.AsRedirect("/");
                                              };
        }
Example #2
0
 public HomeModule(IEnumerable<IAnnounce> announcers, SprocketManager sprockets, Bot bot)
 {
     Get["/"] = _ => View["Home/Index", new { Announcers = announcers, Sprockets = sprockets, Bot = bot }];
     Get["/Rooms"] = _ => View["Home/Rooms", bot.Rooms];
 }
Example #3
0
        public BotHostModule(Bot bot, SprocketManager sprockets, IEnumerable <ISprocketInitializer> sprocketInitializers)
            : base("bot")
        {
            _bot                  = bot;
            _sprockets            = sprockets;
            _sprocketInitializers = sprocketInitializers;

            Get["/start"] = _ =>
            {
                try
                {
                    StartBot();

                    return("Bot Started");
                }
                catch (Exception e)
                {
                    return(e.Message);
                }
            };

            Get["/stop"] = _ =>
            {
                try
                {
                    ShutDownBot();
                    return("Bot Shut Down");
                }
                catch (Exception e)
                {
                    return(e.Message);
                }
            };

            // This is for ensuring that the process doesn't die permanently --
            // We create a task with MomentApp (TBD whether we will use this permanently
            Get["/keepalive"] = _ =>
            {
                ScheduleKeepAlive(Request.Url.ToString());
                return("OK");
            };

            Get["/launch"] = _ =>
            {
                //TODO: verify there is an auth token
                LoadCoffeeScript();
                return("");
            };

            Post["/join"] = _ =>
            {
                _bot.Join(Request.Form.Room);
                return(Response.AsRedirect("/Rooms"));
            };

            Get["/leave"] = _ =>
            {
                _bot.Leave(Request.Query.Room);
                return(Response.AsRedirect("/Rooms"));
            };
            Post["/send/{room}"] = _ =>
            {
                _bot.Say(Request.Form.Message, _.Room);
                return(Response.AsRedirect("/"));
            };

            Post["/attach"] = _ =>
            {
                AttachScript(Request.Form.script);
                return(Response.AsRedirect("/"));
            };

            Post["/disable/{sprocket}"] = _ =>
            {
                var sprocket = sprockets[_.Sprocket];
                _bot.DisableSprocket(sprocket);
                return(Response.AsRedirect("/"));
            };

            Post["/enable/{sprocket}"] = _ =>
            {
                var sprocket = sprockets[_.Sprocket];
                _bot.EnableSprocket(sprocket);
                return(Response.AsRedirect("/"));
            };
        }
Example #4
0
 public HomeModule(IEnumerable <IAnnounce> announcers, SprocketManager sprockets, Bot bot)
 {
     Get["/"]      = _ => View["Home/Index", new { Announcers = announcers, Sprockets = sprockets, Bot = bot }];
     Get["/Rooms"] = _ => View["Home/Rooms", bot.Rooms];
 }