public void ShouldNotReturnCommandIfIsNotWholeWord() { var parser = new SlackCommandParser("scbot", "U123"); string command; Assert.False(parser.TryGetCommand(new Message("a-channel", "a-user", "scbot untrack foo"), "track", out command)); }
public void ShouldReturnFalseWhenNotMentioned() { var parser = new SlackCommandParser("scbot", "U03JWF43N"); string command; Assert.False(parser.TryGetCommand(new Message("a-channel", "a-user", "something irrelevant"), out command)); Assert.Null(command); }
public void ShouldStillStripBotNameFromPMs() { var parser = new SlackCommandParser("scbot", "U03JWF43N"); string command; Assert.True(parser.TryGetCommand(new Message("D03JWF44C", "a-user", "scbot: do the thing"), out command)); Assert.AreEqual("do the thing", command); }
public void ShouldReturnCommandWhenItContainsNewlines() { var parser = new SlackCommandParser("scbot", "U03JWF43N"); string command; Assert.True(parser.TryGetCommand(new Message("a-channel", "a-user", "<@U03JWF43N> do the \n\nthing"), out command)); Assert.AreEqual("do the \n\nthing", command); }
public void ShouldNotReturnCommandWhenMentionedInMiddleOfMessage() { var parser = new SlackCommandParser("scbot", "U03JWF43N"); string command; Assert.False(parser.TryGetCommand(new Message("a-channel", "a-user", "I'm going to mention scbot in this message"), out command)); Assert.Null(command); }
public void ShouldReturnCommandWhenMentionedAtStartOfMessage(string ping) { var parser = new SlackCommandParser("scbot", "U03JWF43N"); string command; Assert.True(parser.TryGetCommand(new Message("a-channel", "a-user", string.Format("{0} do the thing", ping)), out command)); Assert.AreEqual("do the thing", command); }
public void ShouldAlwaysTreatPMsAsMentions() { // channel names that start with D are direct messages (or PMs) so the bot is always being addressed directly var parser = new SlackCommandParser("scbot", "U03JWF43N"); string command; Assert.True(parser.TryGetCommand(new Message("D03JWF44C", "a-user", "do the thing"), out command)); Assert.AreEqual("do the thing", command); }
public static async Task MainAsync(Configuration configuration, CancellationToken cancel) { var persistence = new JsonFileKeyValueStore(new FileInfo(configuration.Get("db-file-location"))); var gamesPersistence = new JsonFileKeyValueStore(new FileInfo(configuration.Get("games-db-location"))); var slackApi = new SlackApi(configuration.Get("slack-api-key")); var slackRtm = await(ReconnectingSlackRealTimeMessaging.CreateAsync( async() => await slackApi.StartRtm())); var aliasList = GetAliasList(slackRtm.InstanceInfo.Users); var commandParser = new SlackCommandParser("scbot", slackRtm.InstanceInfo.BotId); var webClient = new WebClient(); var features = new FeatureMessageProcessor(commandParser, NoteProcessor.Create(commandParser, persistence), //ZendeskTicketTracker.Create(commandParser, persistence, configuration), RecordReplayTraceManagement.Create(commandParser), SeatingPlans.Create(commandParser, webClient), Webcams.Create(commandParser, configuration), Silly.Create(commandParser, webClient), Installers.Create(commandParser, webClient), Polls.Create(commandParser), RollBuildNumbers.Create(commandParser, configuration), ReviewFactory.Create(commandParser, webClient, configuration), LabelPrinting.Create(commandParser, webClient, configuration), Jira.Create(commandParser), CompareTeamEmails.Create(commandParser, configuration), GamesProcessor.Create(commandParser, gamesPersistence, aliasList) ); var pasteBin = new HasteServerPasteBin(webClient, configuration.Get("haste-server-url")); var newChannelNotificationsChannel = configuration.GetWithDefault("new-channels-notification-channel", null); var newChannelProcessor = GetNewChannelProcessor(newChannelNotificationsChannel); var bot = new Bot( new ErrorReportingMessageProcessor( new ConcattingMessageProcessor(features), pasteBin), newChannelProcessor); var handler = new SlackMessageHandler(bot, slackRtm.InstanceInfo.BotId); MainLoop(slackRtm, handler, slackApi, cancel); }