public PingMiddleware(IMiddleware next, PingPlugin pingPlugin) : base(next)
        {
            _pingPlugin = pingPlugin;

            HandlerMappings = new[]
            {
                new HandlerMapping
                {
                    ValidHandles  = ExactMatchHandle.For("ping stop", "stop pinging me"),
                    Description   = "Stops sending you pings",
                    EvaluatorFunc = StopPingingHandler
                },
                new HandlerMapping
                {
                    ValidHandles  = ExactMatchHandle.For("ping list"),
                    Description   = "Lists all of the people currently being pinged",
                    EvaluatorFunc = ListPingHandler
                },
                new HandlerMapping
                {
                    ValidHandles  = ExactMatchHandle.For("ping me"),
                    Description   = "Sends you a ping about every second",
                    EvaluatorFunc = PingHandler
                },
            };
        }
Beispiel #2
0
        public void should_return_false_when_message_doesnt_contains_text(string exactText, string message)
        {
            // given
            var handle = new ExactMatchHandle(exactText);

            // when
            bool isMatch = handle.IsMatch(message);

            // then
            isMatch.ShouldBeFalse();
        }
Beispiel #3
0
 public HelpMiddleware(IMiddleware next) : base(next)
 {
     HandlerMappings = new[]
     {
         new HandlerMapping
         {
             ValidHandles  = ExactMatchHandle.For("hello", "hi", "hey", "help"),
             Description   = "Can I take your order?",
             EvaluatorFunc = HelpHandler
         }
     };
 }
 public YieldTestMiddleware(IMiddleware next) : base(next)
 {
     HandlerMappings = new[]
     {
         new HandlerMapping
         {
             ValidHandles  = ExactMatchHandle.For("yield test"),
             EvaluatorFunc = YieldTest,
             Description   = "Just tests delayed messages"
         }
     };
 }
 public WelcomeResponder()
 {
     Handlers = new[]
     {
         new HandlerMapping
         {
             ValidHandles  = ExactMatchHandle.For("hello", "hi"),
             Description   = "",
             EvaluatorFunc = HandleMessage
         }
     };
 }
Beispiel #6
0
 public AboutMiddleware(IMiddleware next) : base(next)
 {
     HandlerMappings = new[]
     {
         new HandlerMapping
         {
             ValidHandles  = ExactMatchHandle.For("about"),
             Description   = "Tells you some stuff about this bot :-)",
             EvaluatorFunc = AboutHandler
         }
     };
 }
Beispiel #7
0
 public StatsMiddleware(IMiddleware next, StatsPlugin statsPlugin) : base(next)
 {
     _statsPlugin    = statsPlugin;
     HandlerMappings = new[]
     {
         new HandlerMapping
         {
             ValidHandles  = ExactMatchHandle.For("stats"),
             Description   = "Returns interesting stats about your noobot installation",
             EvaluatorFunc = StatsHandler
         }
     };
 }
 public JokeMiddleware(IMiddleware next, StatsPlugin statsPlugin) : base(next)
 {
     _statsPlugin    = statsPlugin;
     HandlerMappings = new[]
     {
         new HandlerMapping
         {
             ValidHandles  = ExactMatchHandle.For("joke", "tell me a joke"),
             Description   = "Tells a random joke",
             EvaluatorFunc = JokeHandler
         }
     };
 }
Beispiel #9
0
 public TestMiddleware(IMiddleware next) : base(next)
 {
     HandlerMappings = new[]
     {
         new HandlerMapping
         {
             ValidHandles  = ExactMatchHandle.For("tttt"),
             EvaluatorFunc = TestHandler,
             Description   = "This is the description for the test handler",
             VisibleInHelp = true
         }
     };
 }
 public WelcomeMiddleware(IMiddleware next, StatsPlugin statsPlugin) : base(next)
 {
     _statsPlugin    = statsPlugin;
     HandlerMappings = new[]
     {
         new HandlerMapping
         {
             ValidHandles  = ExactMatchHandle.For("hi", "hey", "hello", "wuzzup"),
             Description   = "Try saying hi and see what happens",
             EvaluatorFunc = WelcomeHandler
         }
     };
 }
Beispiel #11
0
 public IncidentManagementMiddleware(IMiddleware next, IncidentManagementPlugin incidentManagementPlugin, ILog log)
     : base(next)
 {
     this.incidentManagementPlugin = incidentManagementPlugin;
     this.log             = log;
     this.HandlerMappings = new[]
     {
         new HandlerMapping
         {
             ValidHandles  = StartsWithHandle.For($"{Configuration.Prefix} new"),
             EvaluatorFunc = this.NewIncidentHandler,
             Description   = $"Declares a new incident. {this.newIncidentHelpText}",
             VisibleInHelp = true
         },
         new HandlerMapping
         {
             ValidHandles  = ExactMatchHandle.For($"{Configuration.Prefix} resolve"),
             EvaluatorFunc = this.ResolveIncidentHandler,
             Description   = $"Resolve the incident associated with current channel. {this.resolveIncidentHelpText}",
             VisibleInHelp = true
         },
         new HandlerMapping
         {
             ValidHandles  = StartsWithHandle.For($"{Configuration.Prefix} postmortem"),
             EvaluatorFunc = this.AddPostmortemLinkToIncidentHandler,
             Description   = $"Adds the postmortem link to the incident associated with current channel. {this.postmortemIncidentHelpText}",
             VisibleInHelp = true
         },
         new HandlerMapping
         {
             ValidHandles  = ExactMatchHandle.For($"{Configuration.Prefix} close"),
             EvaluatorFunc = this.CloseIncidentHandler,
             Description   = $"Close the incident associated with current channel. {this.closeIncidentHelpText}",
             VisibleInHelp = true
         },
         new HandlerMapping
         {
             ValidHandles  = ExactMatchHandle.For($"{Configuration.Prefix} list active"),
             EvaluatorFunc = this.ListActiveIncidentHandler,
             Description   = $"Lists active incidents. {this.listActiveIncidentHelpText}",
             VisibleInHelp = true
         },
         new HandlerMapping
         {
             ValidHandles  = ExactMatchHandle.For($"{Configuration.Prefix} list recent"),
             EvaluatorFunc = this.ListRecentIncidentHandler,
             Description   = $"Lists recent incidents. {this.listRecentIncidentHelpText}",
             VisibleInHelp = true
         },
     };
 }
        public AdminMiddleware(
            IMiddleware next,
            AdminPlugin adminPlugin,
            SchedulePlugin schedulePlugin,
            INoobotCore noobotCore,
            ILogger log) : base(next)
        {
            _adminPlugin    = adminPlugin;
            _schedulePlugin = schedulePlugin;
            _noobotCore     = noobotCore;
            _log            = log;

            HandlerMappings = new[]
            {
                new HandlerMapping
                {
                    ValidHandles  = ExactMatchHandle.For("admin pin"),
                    EvaluatorFunc = PinHandler,
                    Description   = "This function is used to authenticate a user as admin",
                    VisibleInHelp = false
                },
                new HandlerMapping
                {
                    ValidHandles  = ExactMatchHandle.For("admin schedules list"),
                    EvaluatorFunc = SchedulesListHandler,
                    Description   = "[Requires authentication] Will return a list of all schedules.",
                    VisibleInHelp = false
                },
                new HandlerMapping
                {
                    ValidHandles  = ExactMatchHandle.For("admin schedules delete"),
                    EvaluatorFunc = DeleteSchedulesHandler,
                    Description   = "[Requires authentication] This will delete all schedules.",
                    VisibleInHelp = false
                },
                new HandlerMapping
                {
                    ValidHandles  = ExactMatchHandle.For("admin channels"),
                    EvaluatorFunc = ChannelsHandler,
                    Description   = "[Requires authentication] Will return all channels connected.",
                    VisibleInHelp = false
                },
                new HandlerMapping
                {
                    ValidHandles  = ExactMatchHandle.For("admin help", "admin list"),
                    EvaluatorFunc = AdminHelpHandler,
                    Description   = "[Requires authentication] Lists all available admin functions",
                    VisibleInHelp = false
                }
            };
        }
        public SpotifyMiddleWare(IMiddleware next, SpotifyPlugin spotifyPlugin) : base(next)
        {
            this._spotifyPlugin = spotifyPlugin;

            this.HandlerMappings = new[]
            {
                new HandlerMapping
                {
                    ValidHandles  = ExactMatchHandle.For("who is the captain"),
                    Description   = "What spotify account is this",
                    EvaluatorFunc = this.GetSpotifyUserDetails,
                    VisibleInHelp = false
                },
                new HandlerMapping
                {
                    ValidHandles  = ExactMatchHandle.For("lets start the party"),
                    Description   = "creates a playlist for beer o clock",
                    EvaluatorFunc = this.CreateSpotifyPlaylist,
                    VisibleInHelp = false
                },
                new HandlerMapping
                {
                    ValidHandles  = RegexHandle.For("(tune\\sthis\\s)<(spotify:track:.{22})>", "(tune\\sthis\\s)(.{22})"),
                    Description   = "add a track to the playlist",
                    EvaluatorFunc = this.AddTrackToPlaylist,
                    VisibleInHelp = true
                },
                new HandlerMapping
                {
                    ValidHandles  = ExactMatchHandle.For("Get devices"),
                    Description   = "Finds devices available for playback",
                    EvaluatorFunc = this.GetAvialableSpotifyDevices,
                    VisibleInHelp = false
                },
                new HandlerMapping
                {
                    ValidHandles  = RegexHandle.For(this._setDeviceRegEx),
                    Description   = "Set the player device by device ID",
                    EvaluatorFunc = this.SetDevice,
                    VisibleInHelp = false
                },
                new HandlerMapping
                {
                    ValidHandles  = ExactMatchHandle.For("start the tunes"),
                    Description   = "Starts the music",
                    EvaluatorFunc = this.PlayResumeMusic,
                    VisibleInHelp = false
                },
            };
        }
        public FlickrMiddleware(IMiddleware next, IConfigReader configReader, StatsPlugin statsPlugin) : base(next)
        {
            _configReader = configReader;
            _statsPlugin  = statsPlugin;

            HandlerMappings = new[]
            {
                new HandlerMapping
                {
                    ValidHandles  = ExactMatchHandle.For("flickr", "pic"),
                    Description   = "Finds a pics from flickr - usage: /flickr birds",
                    EvaluatorFunc = FlickrHandler,
                }
            };
        }
        public ConfirmMiddleware(IMiddleware next, IOrderCache orderCache) : base(next)
        {
            _orderCache = orderCache;


            HandlerMappings = new[]
            {
                new HandlerMapping
                {
                    ValidHandles  = ExactMatchHandle.For(_positiveResponses.Concat(_negativeResponses).ToArray()),
                    Description   = "Please confirm this order is correct",
                    EvaluatorFunc = ConfirmHandler
                }
            };
        }
 public FlightFinderMiddleware(
     IMiddleware next,
     IFlightFinderClient flightFinderClient,
     ILog log,
     AuthorizationPlugin authorizationPlugin) : base(next)
 {
     _flightFinderClient  = flightFinderClient;
     _authorizationPlugin = authorizationPlugin;
     HandlerMappings      = new[]
     {
         new HandlerMapping
         {
             ValidHandles  = ExactMatchHandle.For("tflights"),
             Description   = "Cheapest upcoming weekend flights to Turkey (Istanbul)",
             EvaluatorFunc = ((Func <IncomingMessage, IValidHandle, IEnumerable <ResponseMessage> >)Handler).WithErrorHandling(log)
         }
     };
 }
Beispiel #17
0
 public NewRelicMiddleware(IMiddleware next, NewRelicPlugin newRelicPlugin, ILog log)
     : base(next)
 {
     this.newRelicPlugin  = newRelicPlugin;
     this.HandlerMappings = new[]
     {
         new HandlerMapping
         {
             ValidHandles  = ExactMatchHandle.For($"{Configuration.CommandPrefix} applications"),
             EvaluatorFunc = this.ApplicationsHandler,
             Description   = $"Gets applications summary from NewRelic. '{Configuration.CommandPrefix} applications'",
             VisibleInHelp = true
         },
         new HandlerMapping
         {
             ValidHandles  = ExactMatchHandle.For($"{Configuration.CommandPrefix} applications detail"),
             EvaluatorFunc = this.ApplicationsDetailHandler,
             Description   = $"Gets applications detail from NewRelic. {Configuration.CommandPrefix} applications detail",
             VisibleInHelp = true
         },
         new HandlerMapping
         {
             ValidHandles  = ExactMatchHandle.For($"{Configuration.CommandPrefix} applications detail unhealthy"),
             EvaluatorFunc = this.UnhealthyApplicationsDetailHandler,
             Description   = $"Gets applications detail from NewRelic which are unhealthy. `applications detail unhealthy`",
             VisibleInHelp = true
         },
         new HandlerMapping
         {
             ValidHandles  = StartsWithHandle.For($"{Configuration.CommandPrefix} application detail"),
             EvaluatorFunc = this.ApplicationDetailHandler,
             Description   = $"Gets application detail for one or more applications from NewRelic. {this.applicationDetailHelpText}",
             VisibleInHelp = true
         },
         new HandlerMapping
         {
             ValidHandles  = StartsWithHandle.For($"{Configuration.CommandPrefix} application metrics"),
             EvaluatorFunc = this.ApplicationMetricsHandler,
             Description   = $"Gets application metrics from NewRelic for the requested application id. {this.applicationMetricsHelpText}",
             VisibleInHelp = false
         },
     };
 }
Beispiel #18
0
 public SlackTest(IMiddleware next, StatsPlugin statsPlugin) : base(next)
 {
     this.HandlerMappings = new HandlerMapping[]
     {
         new HandlerMapping()
         {
             ValidHandles  = ExactMatchHandle.For("can i have a beer", "what time is it"),
             Description   = "Checks if it is Beer O Clock",
             EvaluatorFunc =
                 new Func <IncomingMessage, IValidHandle, IEnumerable <ResponseMessage> >(this.CheckWhatTimeItIs),
             VisibleInHelp = false
         },
         new HandlerMapping()
         {
             ValidHandles  = ExactMatchHandle.For("test"),
             Description   = "Checks if it is Beer O Clock",
             EvaluatorFunc =
                 new Func <IncomingMessage, IValidHandle, IEnumerable <ResponseMessage> >(this.Booop),
             VisibleInHelp = false
         },
     };
 }
        public AuthorizationMiddleware(AuthorizationPlugin authorizationPlugin, IMiddleware next) : base(next)
        {
            _authorizationPlugin = authorizationPlugin;

            HandlerMappings = new[]
            {
                new HandlerMapping
                {
                    ValidHandles = ValidHandle.For(
                        "auth (grant|deny) [permissionName] [userEmail]",
                        x => PermissionCommandParser.TryParsePermissionCommandExpression(x).WasSuccessful),
                    Description   = "Grants or denies access to a command. Usage: auth grant tflights [email protected], [email protected]",
                    EvaluatorFunc = HandleGrantOrDenyPermission,
                },
                new HandlerMapping
                {
                    ValidHandles  = ExactMatchHandle.For("auth ls"),
                    Description   = "Will provide the full list of permissions",
                    EvaluatorFunc = HandleListAllPermissions
                },
                new HandlerMapping
                {
                    ValidHandles = ValidHandle.For(
                        "auth ls -u [userEmail]",
                        x => PermissionCommandParser.TryParsePermissionsByUserExpression(x).WasSuccessful),
                    Description   = "Will provide the full list of permissions for a user",
                    EvaluatorFunc = HandleListPermissionsByUser
                },
                new HandlerMapping
                {
                    ValidHandles = ValidHandle.For(
                        "auth ls -p [permissionName]",
                        x => PermissionCommandParser.TryParseUsersByPermissionExpression(x).WasSuccessful),
                    Description   = "Will provide the full list of users who have the specified permission",
                    EvaluatorFunc = HandleListUsersByPermissions
                }
            };
        }
        public ScheduleMiddleware(IMiddleware next, SchedulePlugin schedulePlugin) : base(next)
        {
            _schedulePlugin = schedulePlugin;

            HandlerMappings = new[]
            {
                new HandlerMapping
                {
                    ValidHandles  = StartsWithHandle.For("schedule hourly"),
                    Description   = "Schedule a command to execute every hour on the current channel. Usage: `@{bot} schedule hourly @{bot} tell me a joke`",
                    EvaluatorFunc = HourlyHandler,
                },
                new HandlerMapping
                {
                    ValidHandles  = StartsWithHandle.For("schedule daily"),
                    Description   = "Schedule a command to execute every day on the current channel. Usage: `@{bot} schedule daily @{bot} tell me a joke`",
                    EvaluatorFunc = DayHandler,
                },
                new HandlerMapping
                {
                    ValidHandles  = StartsWithHandle.For("schedule cronjob"),
                    Description   = "Schedule a cron job for this channel. Usage: `@{bot} schedule cronjob '0 15 10 * * ?' @{bot} tell me a joke`",
                    EvaluatorFunc = CronHandler,
                },
                new HandlerMapping
                {
                    ValidHandles  = ExactMatchHandle.For("schedule list"),
                    Description   = "List all schedules on the current channel",
                    EvaluatorFunc = ListHandlerForChannel,
                },
                new HandlerMapping
                {
                    ValidHandles  = StartsWithHandle.For("schedule delete"),
                    Description   = "Delete a schedule in this channel. You must enter a valid {guid}",
                    EvaluatorFunc = DeleteHandlerForChannel,
                },
            };
        }
Beispiel #21
0
 public CalculatorMiddleware(IMiddleware next, StatsPlugin statsPlugin) : base(next)
 {
     _statsPlugin    = statsPlugin;
     HandlerMappings = new[]
     {
         new HandlerMapping
         {
             ValidHandles           = ExactMatchHandle.For("calc"),
             Description            = "Calculate mathematical expressions - usage: calc ((1+2)*3)/4",
             EvaluatorFunc          = CalculateHandler,
             MessageShouldTargetBot = false
         },
         new HandlerMapping
         {
             ValidHandles             = new IValidHandle[] { new AlwaysMatchHandle() },
             Description              = "Try to calculate mathematical expressions without the 'calc' prefix - usage: ((1+2)*3)/4",
             EvaluatorFunc            = CalculateHandler,
             MessageShouldTargetBot   = false,
             ShouldContinueProcessing = true,
             VisibleInHelp            = false
         }
     };
 }