Пример #1
0
 public void Handle(GroupChatMessageArrived eventObject)
 {
     if (TestMessageFilter(eventObject))
     {
         ReceiveGroupMessage(eventObject, MessageFilter.Matches(eventObject.Message.Body));
     }
 }
 public void Handle(GroupChatMessageArrived eventObject)
 {
     foreach (string file in Directory.GetFiles(ScriptFolder, "*.js"))
     {
         try
         {
             ArrayInstance result = RunScriptFromFile(eventObject, file);
             NotifyResults(result);
         }
         catch (Exception ex)
         {
             _eventNotifier.SendText(string.Format("I'm having trouble with {0}", file));
         }
     }
     foreach (string file in Directory.GetFiles(ScriptFolder, "*.coffee"))
     {
         try
         {
             ArrayInstance result = RunCoffeeScriptFromFile(eventObject, file);
             NotifyResults(result);
         }
         catch (Exception ex)
         {
             _eventNotifier.SendText(string.Format("I'm having trouble with {0}", file));
         }
     }
 }
Пример #3
0
 public void Setup()
 {
     var to = new Jid("*****@*****.**");
     var from = new Jid("*****@*****.**");
     var msg = new Message(to, from, MessageType.groupchat, "slow clap");
     var eventObj = new GroupChatMessageArrived(msg, "testroom");
     _notifier = Substitute.For<IEventNotifier>();
     var handler = new GroupChatScriptHandler(_notifier);
     handler.ScriptFolder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "scripts");
     handler.Handle(eventObj);
 }
Пример #4
0
 public override void ReceiveGroupMessage(GroupChatMessageArrived message, MatchCollection matches)
 {
     if (count.IsMatch(message.Message.Body))
         StartCounting(count.Match(message.Message.Body).Groups[1].ToString());
     else if (stopcount.IsMatch(message.Message.Body))
         StopCounting(stopcount.Match(message.Message.Body).Groups[1].ToString());
     else if (tally.IsMatch(message.Message.Body))
         ReportTally(tally.Match(message.Message.Body).Groups[1].ToString());
     else
         foreach (string text in runningCount.Keys.ToList())
         {
             if (message.Message.Body.IndexOf(text, StringComparison.OrdinalIgnoreCase) >= 0)
                 runningCount[text]++;
         }
 }
Пример #5
0
 public override void ReceiveGroupMessage(GroupChatMessageArrived message, MatchCollection matches)
 {
     Group search = matches[0].Groups[1];
     var client = new WebClient();
     string response = client.DownloadString(string.Format("http://search.twitter.com/search.json?q={0}", search));
     var queryResult = JsonConvert.DeserializeObject<TwitterQueryResult>(response);
     if (queryResult.results != null && queryResult.results.Count > 0)
     {
         _eventNotifier.SendText(string.Format("{0} tweeted about {1}:\n{2} ({3})",
             queryResult.results[0].from_user,
             search,
             queryResult.results[0].text,
             queryResult.results[0].GetTweetUrl()));
     }
 }
Пример #6
0
 public virtual bool TestMessageFilter(GroupChatMessageArrived eventObj)
 {
     return (MessageFilter.IsMatch(eventObj.Message.Body));
 }
Пример #7
0
 public abstract void ReceiveGroupMessage(GroupChatMessageArrived message, MatchCollection matches);
 private ArrayInstance RunScriptFromFile(GroupChatMessageArrived eventObject, string file)
 {
     return RunScript(eventObject, File.ReadAllText(file));
 }
 private ArrayInstance RunScript(GroupChatMessageArrived eventObject, string js)
 {
     var jsEngine = new ScriptEngine();
     jsEngine.ExecuteFile(Path.Combine(BaseScriptFolder, "hubotScriptInvoker.js"));
     jsEngine.Execute(js);
     jsEngine.SetGlobalValue("messageBody", eventObject.Message.Body);
     jsEngine.Execute(GetJSInvoker(eventObject));
     jsEngine.Execute("module.exports(bot);");
     var result = jsEngine.GetGlobalValue("messages") as ArrayInstance;
     return result;
 }
Пример #10
0
 private string GetJSInvoker(GroupChatMessageArrived eventObj)
 {
     return string.Format("message = new MessageObject('{0}','{1}',messageBody);",
         quoteForJS(eventObj.Room),
         quoteForJS(eventObj.Message.From));
 }