Ejemplo n.º 1
0
 public KarmaMiddleware(IMiddleware next, KarmaRepositoryPlugin karmaRepositoryPlugin, KarmaPlugin karmaPlugin) : base(next)
 {
     _karmaRepositoryPlugin = karmaRepositoryPlugin;
     _karmaPlugin           = karmaPlugin;
     HandlerMappings        = new[]
     {
         new HandlerMapping
         {
             ValidHandles           = RegexHandle.For(KarmaPlugin.OperatorRegex),
             Description            = "Allows upvoting and downvoting on things and people with `--` and `++`.",
             EvaluatorFunc          = KarmaHandler,
             MessageShouldTargetBot = false,
             VisibleInHelp          = false
         },
         new HandlerMapping
         {
             ValidHandles           = RegexHandle.For(KarmaPlugin.ListKarmaRegex),
             Description            = "List recorded karma",
             EvaluatorFunc          = ListHandler,
             MessageShouldTargetBot = true,
             VisibleInHelp          = true
         },
         new HandlerMapping
         {
             ValidHandles           = RegexHandle.For(KarmaPlugin.ListReasonRegex),
             Description            = "List reasons for a karma entry",
             EvaluatorFunc          = ReasonHandler,
             MessageShouldTargetBot = true,
             VisibleInHelp          = true
         }
     };
 }
Ejemplo n.º 2
0
        public LboMiddleware(IMiddleware next, LboPlugin lboPlugin, ILog log) : base(next)
        {
            this.log       = log;
            this.lboPlugin = lboPlugin;

            this.HandlerMappings = new[]
            {
                new HandlerMapping
                {
                    ValidHandles  = RegexHandle.For($"^{Configuration.Prefix} [^ ]+ drain.+"),
                    EvaluatorFunc = this.DrainHandler,
                    Description   = $"Drains a node on the load balancer. '{GetHelpText(LoadBalancerActions.Drain)}'",
                    VisibleInHelp = false
                },
                new HandlerMapping
                {
                    ValidHandles  = RegexHandle.For($"^{Configuration.Prefix} [^ ]+ halt.+"),
                    EvaluatorFunc = this.HaltHandler,
                    Description   = $"Halts a node on the load balancer. '{GetHelpText(LoadBalancerActions.Halt)}'",
                    VisibleInHelp = false
                },
                new HandlerMapping
                {
                    ValidHandles  = RegexHandle.For($"^{Configuration.Prefix} [^ ]+ online.+"),
                    EvaluatorFunc = this.OnlineHandler,
                    Description   = $"Brings a node online on the load balancer. '{GetHelpText(LoadBalancerActions.Online)}'",
                    VisibleInHelp = false
                },
            };
        }
Ejemplo n.º 3
0
        public void should_return_false_when_message_doesnt_contains_text(string exactText, string message)
        {
            // given
            var handle = new RegexHandle(exactText);

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

            // then
            isMatch.ShouldBeFalse();
        }
Ejemplo n.º 4
0
        public void should_return_true_when_message_contains_text(string regex, string message)
        {
            // given
            var handle = new RegexHandle(regex);

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

            // then
            isMatch.ShouldBeTrue();
        }
Ejemplo n.º 5
0
 public EasterEggMiddleware(IMiddleware next) : base(next)
 {
     HandlerMappings = new[]
     {
         new HandlerMapping
         {
             ValidHandles  = RegexHandle.For("open (.*) door"),
             EvaluatorFunc = PodBayDoorHandler,
             Description   = "Opens the pod bay doors",
             VisibleInHelp = false
         }
     };
 }
Ejemplo n.º 6
0
        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
                },
            };
        }
Ejemplo n.º 7
0
 public KarmaMiddleware(IMiddleware next, KarmaRepositoryPlugin karmaRepositoryPlugin, KarmaPlugin karmaPlugin) : base(next)
 {
     _karmaRepositoryPlugin = karmaRepositoryPlugin;
     _karmaPlugin           = karmaPlugin;
     HandlerMappings        = new[]
     {
         new HandlerMapping
         {
             ValidHandles           = RegexHandle.For(KarmaPlugin.IncomingMessageRegex),
             Description            = "Allows upvoting and downvoting on things and people with `--` and `++`.",
             EvaluatorFunc          = KarmaHandler,
             MessageShouldTargetBot = false,
             VisibleInHelp          = false
         }
     };
 }
 public PearlOfWisdomMiddleware(IMiddleware next) : base(next)
 {
     HandlerMappings = new[]
     {
         new HandlerMapping
         {
             MessageShouldTargetBot   = false,
             ValidHandles             = StartsWithHandle.For("złota myśl", "cytat", "dowcip", "kawał", "coś śmiesznego"),
             EvaluatorFunc            = PearlOfWisdomHandler,
             ShouldContinueProcessing = false,
         },
         new HandlerMapping
         {
             MessageShouldTargetBot   = false,
             ValidHandles             = RegexHandle.For("zyg[munt|a|uś]"),
             EvaluatorFunc            = PearlOfWisdomHandler,
             ShouldContinueProcessing = false,
         },
     };
 }