Permalink
Browse files

Core file push

  • Loading branch information...
1 parent fa1fafb commit 4c43f266115a6f95e56b99deaf28cd4ba3030464 @patHyatt committed Mar 13, 2012
View
@@ -0,0 +1,133 @@
+
+Microsoft Visual Studio Solution File, Format Version 11.00
+# Visual Studio 2010
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XmppBot", "XMPP_bot\XmppBot.csproj", "{5A73E507-2C67-48CA-BD24-CEA8898E9180}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XmppBot.Common", "XmppBot.Common\XmppBot.Common.csproj", "{7553588F-7628-4689-B02B-CC2F504F82C2}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XmppBot.Extensions", "XmppBot.Extensions\XmppBot.Extensions.csproj", "{5D5F4F04-F8FF-45BA-97E5-C4F73CCEBBD8}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Vocus50.Core.Utils", "..\..\..\..\..\..\_Source\Vocus50\DotNet\Vocus50.Core\Vocus50.Core.Utils\Vocus50.Core.Utils.csproj", "{941A3622-267A-4CFC-94C2-A0143B3E2741}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XmppBot.Extensions.Tests", "XmppBot.Extensions.Tests\XmppBot.Extensions.Tests.csproj", "{2940CE50-51C0-4F4B-84E6-BDE639A7A9BD}"
+EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{EE28B61C-BAAF-47CB-9D65-719DFD690C48}"
+ ProjectSection(SolutionItems) = preProject
+ Local.testsettings = Local.testsettings
+ TraceAndTestImpact.testsettings = TraceAndTestImpact.testsettings
+ XMPP_bot.vsmdi = XMPP_bot.vsmdi
+ EndProjectSection
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XmppBot.Plugin.Twss", "XmppBot.Plugin.Twss\XmppBot.Plugin.Twss.csproj", "{441AEB93-29CB-445E-9C6A-F4CCFDF0CB99}"
+EndProject
+Global
+ GlobalSection(TestCaseManagementSettings) = postSolution
+ CategoryFile = XMPP_bot.vsmdi
+ EndGlobalSection
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Debug|Mixed Platforms = Debug|Mixed Platforms
+ Debug|x86 = Debug|x86
+ Release|Any CPU = Release|Any CPU
+ Release|Mixed Platforms = Release|Mixed Platforms
+ Release|x86 = Release|x86
+ Release64|Any CPU = Release64|Any CPU
+ Release64|Mixed Platforms = Release64|Mixed Platforms
+ Release64|x86 = Release64|x86
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {5A73E507-2C67-48CA-BD24-CEA8898E9180}.Debug|Any CPU.ActiveCfg = Debug|x86
+ {5A73E507-2C67-48CA-BD24-CEA8898E9180}.Debug|Mixed Platforms.ActiveCfg = Debug|x86
+ {5A73E507-2C67-48CA-BD24-CEA8898E9180}.Debug|Mixed Platforms.Build.0 = Debug|x86
+ {5A73E507-2C67-48CA-BD24-CEA8898E9180}.Debug|x86.ActiveCfg = Debug|x86
+ {5A73E507-2C67-48CA-BD24-CEA8898E9180}.Debug|x86.Build.0 = Debug|x86
+ {5A73E507-2C67-48CA-BD24-CEA8898E9180}.Release|Any CPU.ActiveCfg = Release|x86
+ {5A73E507-2C67-48CA-BD24-CEA8898E9180}.Release|Mixed Platforms.ActiveCfg = Release|x86
+ {5A73E507-2C67-48CA-BD24-CEA8898E9180}.Release|Mixed Platforms.Build.0 = Release|x86
+ {5A73E507-2C67-48CA-BD24-CEA8898E9180}.Release|x86.ActiveCfg = Release|x86
+ {5A73E507-2C67-48CA-BD24-CEA8898E9180}.Release|x86.Build.0 = Release|x86
+ {5A73E507-2C67-48CA-BD24-CEA8898E9180}.Release64|Any CPU.ActiveCfg = Release|x86
+ {5A73E507-2C67-48CA-BD24-CEA8898E9180}.Release64|Mixed Platforms.ActiveCfg = Release|x86
+ {5A73E507-2C67-48CA-BD24-CEA8898E9180}.Release64|Mixed Platforms.Build.0 = Release|x86
+ {5A73E507-2C67-48CA-BD24-CEA8898E9180}.Release64|x86.ActiveCfg = Release|x86
+ {5A73E507-2C67-48CA-BD24-CEA8898E9180}.Release64|x86.Build.0 = Release|x86
+ {7553588F-7628-4689-B02B-CC2F504F82C2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {7553588F-7628-4689-B02B-CC2F504F82C2}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {7553588F-7628-4689-B02B-CC2F504F82C2}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
+ {7553588F-7628-4689-B02B-CC2F504F82C2}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
+ {7553588F-7628-4689-B02B-CC2F504F82C2}.Debug|x86.ActiveCfg = Debug|Any CPU
+ {7553588F-7628-4689-B02B-CC2F504F82C2}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {7553588F-7628-4689-B02B-CC2F504F82C2}.Release|Any CPU.Build.0 = Release|Any CPU
+ {7553588F-7628-4689-B02B-CC2F504F82C2}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
+ {7553588F-7628-4689-B02B-CC2F504F82C2}.Release|Mixed Platforms.Build.0 = Release|Any CPU
+ {7553588F-7628-4689-B02B-CC2F504F82C2}.Release|x86.ActiveCfg = Release|Any CPU
+ {7553588F-7628-4689-B02B-CC2F504F82C2}.Release64|Any CPU.ActiveCfg = Release|Any CPU
+ {7553588F-7628-4689-B02B-CC2F504F82C2}.Release64|Any CPU.Build.0 = Release|Any CPU
+ {7553588F-7628-4689-B02B-CC2F504F82C2}.Release64|Mixed Platforms.ActiveCfg = Release|Any CPU
+ {7553588F-7628-4689-B02B-CC2F504F82C2}.Release64|Mixed Platforms.Build.0 = Release|Any CPU
+ {7553588F-7628-4689-B02B-CC2F504F82C2}.Release64|x86.ActiveCfg = Release|Any CPU
+ {5D5F4F04-F8FF-45BA-97E5-C4F73CCEBBD8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {5D5F4F04-F8FF-45BA-97E5-C4F73CCEBBD8}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {5D5F4F04-F8FF-45BA-97E5-C4F73CCEBBD8}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
+ {5D5F4F04-F8FF-45BA-97E5-C4F73CCEBBD8}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
+ {5D5F4F04-F8FF-45BA-97E5-C4F73CCEBBD8}.Debug|x86.ActiveCfg = Debug|Any CPU
+ {5D5F4F04-F8FF-45BA-97E5-C4F73CCEBBD8}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {5D5F4F04-F8FF-45BA-97E5-C4F73CCEBBD8}.Release|Any CPU.Build.0 = Release|Any CPU
+ {5D5F4F04-F8FF-45BA-97E5-C4F73CCEBBD8}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
+ {5D5F4F04-F8FF-45BA-97E5-C4F73CCEBBD8}.Release|Mixed Platforms.Build.0 = Release|Any CPU
+ {5D5F4F04-F8FF-45BA-97E5-C4F73CCEBBD8}.Release|x86.ActiveCfg = Release|Any CPU
+ {5D5F4F04-F8FF-45BA-97E5-C4F73CCEBBD8}.Release64|Any CPU.ActiveCfg = Release|Any CPU
+ {5D5F4F04-F8FF-45BA-97E5-C4F73CCEBBD8}.Release64|Any CPU.Build.0 = Release|Any CPU
+ {5D5F4F04-F8FF-45BA-97E5-C4F73CCEBBD8}.Release64|Mixed Platforms.ActiveCfg = Release|Any CPU
+ {5D5F4F04-F8FF-45BA-97E5-C4F73CCEBBD8}.Release64|Mixed Platforms.Build.0 = Release|Any CPU
+ {5D5F4F04-F8FF-45BA-97E5-C4F73CCEBBD8}.Release64|x86.ActiveCfg = Release|Any CPU
+ {941A3622-267A-4CFC-94C2-A0143B3E2741}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {941A3622-267A-4CFC-94C2-A0143B3E2741}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {941A3622-267A-4CFC-94C2-A0143B3E2741}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
+ {941A3622-267A-4CFC-94C2-A0143B3E2741}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
+ {941A3622-267A-4CFC-94C2-A0143B3E2741}.Debug|x86.ActiveCfg = Debug|Any CPU
+ {941A3622-267A-4CFC-94C2-A0143B3E2741}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {941A3622-267A-4CFC-94C2-A0143B3E2741}.Release|Any CPU.Build.0 = Release|Any CPU
+ {941A3622-267A-4CFC-94C2-A0143B3E2741}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
+ {941A3622-267A-4CFC-94C2-A0143B3E2741}.Release|Mixed Platforms.Build.0 = Release|Any CPU
+ {941A3622-267A-4CFC-94C2-A0143B3E2741}.Release|x86.ActiveCfg = Release|Any CPU
+ {941A3622-267A-4CFC-94C2-A0143B3E2741}.Release64|Any CPU.ActiveCfg = Release64|Any CPU
+ {941A3622-267A-4CFC-94C2-A0143B3E2741}.Release64|Any CPU.Build.0 = Release64|Any CPU
+ {941A3622-267A-4CFC-94C2-A0143B3E2741}.Release64|Mixed Platforms.ActiveCfg = Release64|Any CPU
+ {941A3622-267A-4CFC-94C2-A0143B3E2741}.Release64|Mixed Platforms.Build.0 = Release64|Any CPU
+ {941A3622-267A-4CFC-94C2-A0143B3E2741}.Release64|x86.ActiveCfg = Release64|Any CPU
+ {2940CE50-51C0-4F4B-84E6-BDE639A7A9BD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {2940CE50-51C0-4F4B-84E6-BDE639A7A9BD}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {2940CE50-51C0-4F4B-84E6-BDE639A7A9BD}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
+ {2940CE50-51C0-4F4B-84E6-BDE639A7A9BD}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
+ {2940CE50-51C0-4F4B-84E6-BDE639A7A9BD}.Debug|x86.ActiveCfg = Debug|Any CPU
+ {2940CE50-51C0-4F4B-84E6-BDE639A7A9BD}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {2940CE50-51C0-4F4B-84E6-BDE639A7A9BD}.Release|Any CPU.Build.0 = Release|Any CPU
+ {2940CE50-51C0-4F4B-84E6-BDE639A7A9BD}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
+ {2940CE50-51C0-4F4B-84E6-BDE639A7A9BD}.Release|Mixed Platforms.Build.0 = Release|Any CPU
+ {2940CE50-51C0-4F4B-84E6-BDE639A7A9BD}.Release|x86.ActiveCfg = Release|Any CPU
+ {2940CE50-51C0-4F4B-84E6-BDE639A7A9BD}.Release64|Any CPU.ActiveCfg = Release|Any CPU
+ {2940CE50-51C0-4F4B-84E6-BDE639A7A9BD}.Release64|Any CPU.Build.0 = Release|Any CPU
+ {2940CE50-51C0-4F4B-84E6-BDE639A7A9BD}.Release64|Mixed Platforms.ActiveCfg = Release|Any CPU
+ {2940CE50-51C0-4F4B-84E6-BDE639A7A9BD}.Release64|Mixed Platforms.Build.0 = Release|Any CPU
+ {2940CE50-51C0-4F4B-84E6-BDE639A7A9BD}.Release64|x86.ActiveCfg = Release|Any CPU
+ {441AEB93-29CB-445E-9C6A-F4CCFDF0CB99}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {441AEB93-29CB-445E-9C6A-F4CCFDF0CB99}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {441AEB93-29CB-445E-9C6A-F4CCFDF0CB99}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
+ {441AEB93-29CB-445E-9C6A-F4CCFDF0CB99}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
+ {441AEB93-29CB-445E-9C6A-F4CCFDF0CB99}.Debug|x86.ActiveCfg = Debug|Any CPU
+ {441AEB93-29CB-445E-9C6A-F4CCFDF0CB99}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {441AEB93-29CB-445E-9C6A-F4CCFDF0CB99}.Release|Any CPU.Build.0 = Release|Any CPU
+ {441AEB93-29CB-445E-9C6A-F4CCFDF0CB99}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
+ {441AEB93-29CB-445E-9C6A-F4CCFDF0CB99}.Release|Mixed Platforms.Build.0 = Release|Any CPU
+ {441AEB93-29CB-445E-9C6A-F4CCFDF0CB99}.Release|x86.ActiveCfg = Release|Any CPU
+ {441AEB93-29CB-445E-9C6A-F4CCFDF0CB99}.Release64|Any CPU.ActiveCfg = Release|Any CPU
+ {441AEB93-29CB-445E-9C6A-F4CCFDF0CB99}.Release64|Any CPU.Build.0 = Release|Any CPU
+ {441AEB93-29CB-445E-9C6A-F4CCFDF0CB99}.Release64|Mixed Platforms.ActiveCfg = Release|Any CPU
+ {441AEB93-29CB-445E-9C6A-F4CCFDF0CB99}.Release64|Mixed Platforms.Build.0 = Release|Any CPU
+ {441AEB93-29CB-445E-9C6A-F4CCFDF0CB99}.Release64|x86.ActiveCfg = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+EndGlobal
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<configuration>
+ <appSettings>
+ <!--All of this info can be found on the XMPP/Jabber info section @ https://YOUR-SUBDOMAIN.hipchat.com/account/xmpp-->
+ <add key="Server" value="chat.hipchat.com"/>
+ <!--Username i.e. 1234_56789-->
+ <add key="User" value=""/>
+ <!--Password, this is not displayed on page-->
+ <add key="Password" value=""/>
+ <!--Necessary to avoid bot reciving room history-->
+ <add key="Resource" value="bot"/>
+ <!--Room nickname-->
+ <add key="RoomNick" value=""/>
+ <!--Comma separated list of rooms for your bot to join i.e. 1234_builds, 1234_development-->
+ <add key="Rooms" value=""/>
+ </appSettings>
+</configuration>
View
@@ -0,0 +1,163 @@
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.ComponentModel.Composition;
+using System.ComponentModel.Composition.Hosting;
+using System.Configuration;
+using System.Reflection;
+using System.Text;
+using System.Threading.Tasks;
+
+using agsXMPP;
+using agsXMPP.protocol.client;
+using agsXMPP.protocol.iq.roster;
+using agsXMPP.protocol.x.muc;
+
+using XmppBot.Common;
+using System.Timers;
+
+namespace XMPP_bot
+{
+ class Program
+ {
+ private static DirectoryCatalog _catalog = null;
+ private static XmppClientConnection _client = null;
+ private static Dictionary<string, string> _roster = new Dictionary<string, string>(20);
+ private static Dictionary<string, string> _tempRoster = new Dictionary<string, string>(20);
+
+ static void Main(string[] args)
+ {
+ _catalog = new DirectoryCatalog(Environment.CurrentDirectory + "\\plugins\\");
+ _catalog.Changed += new EventHandler<ComposablePartCatalogChangeEventArgs>(_catalog_Changed);
+ LoadPlugins();
+
+ _client = new XmppClientConnection(ConfigurationManager.AppSettings["Server"]);
+
+ //_client.ConnectServer = "talk.google.com"; //necessary if connecting to Google Talk
+ _client.AutoResolveConnectServer = false;
+
+ _client.OnLogin += new ObjectHandler(xmpp_OnLogin);
+ _client.OnMessage += new MessageHandler(xmpp_OnMessage);
+
+ Console.WriteLine("Connecting...");
+ _client.Resource = ConfigurationManager.AppSettings["Resource"];
+ _client.Open(ConfigurationManager.AppSettings["User"], ConfigurationManager.AppSettings["Password"]);
+ Console.WriteLine("Connected.");
+
+ _client.OnRosterStart += new ObjectHandler(_client_OnRosterStart);
+ _client.OnRosterItem += new XmppClientConnection.RosterHandler(_client_OnRosterItem);
+ _client.OnRosterEnd += new ObjectHandler(_client_OnRosterEnd);
+
+ while (true)
+ {
+ System.Threading.Thread.Sleep(200);
+ }
+ }
+
+ static void _catalog_Changed(object sender, ComposablePartCatalogChangeEventArgs e)
+ {
+ _catalog.Refresh();
+ }
+
+ static void _client_OnRosterStart(object sender)
+ {
+ _tempRoster = new Dictionary<string, string>(20);
+ }
+
+ static void _client_OnRosterEnd(object sender)
+ {
+ _roster = _tempRoster;
+ }
+
+ static void _client_OnRosterItem(object sender, RosterItem item)
+ {
+ if (!_tempRoster.ContainsKey(item.Jid.User))
+ _tempRoster.Add(item.Jid.User, item.Name);
+ }
+
+ static void xmpp_OnLogin(object sender)
+ {
+ MucManager mucManager = new MucManager(_client);
+
+ string[] rooms = ConfigurationManager.AppSettings["Rooms"].Split(',');
+
+ foreach (string room in rooms)
+ {
+ Jid jid = new Jid(room + "@" + "conf.hipchat.com");
+ //mucManager.AcceptDefaultConfiguration(jid);
+ mucManager.JoinRoom(jid, ConfigurationManager.AppSettings["RoomNick"]);
+ }
+ }
+
+ static void xmpp_OnMessage(object sender, Message msg)
+ {
+ if (!String.IsNullOrEmpty(msg.Body))
+ {
+ Console.WriteLine("Message : {0} - from {1}", msg.Body, msg.From);
+
+ string user;
+
+ if (msg.Type != MessageType.groupchat)
+ {
+ if (!_roster.TryGetValue(msg.From.User, out user))
+ {
+ user = "Unknown User";
+ }
+ }
+ else
+ {
+ user = msg.From.Resource;
+ }
+
+ if (user == ConfigurationManager.AppSettings["RoomNick"])
+ return;
+
+ ParsedLine line = new ParsedLine(msg.Body.Trim(), user);
+
+ switch (line.Command)
+ {
+ case "close":
+ SendMessage(msg.From.Bare, "I'm a quitter...", msg.Type);
+ Environment.Exit(1);
+ return;
+
+ case "reload":
+ SendMessage(msg.From.Bare, LoadPlugins(), msg.Type);
+ break;
+
+ default:
+ Parallel.ForEach<IXmppBotPlugin>(Plugins,
+ plugin => SendMessage(msg.From.Bare, plugin.Evaluate(line), msg.Type)
+ );
+
+ break;
+ }
+ }
+ }
+
+ public static void SendMessage(Jid to, string text, MessageType type)
+ {
+ if (text == null) return;
+
+ _client.Send(new Message(to, type, text));
+ }
+
+ [ImportMany(AllowRecomposition = true)]
+ public static IEnumerable<IXmppBotPlugin> Plugins { get; set; }
+
+ private static string LoadPlugins()
+ {
+ var container = new CompositionContainer(_catalog);
+ Plugins = container.GetExportedValues<IXmppBotPlugin>();
+
+ StringBuilder builder = new StringBuilder();
+ builder.AppendLine("Loaded the following plugins");
+ foreach (var part in _catalog.Parts)
+ {
+ builder.AppendFormat("\t{0}\n", part.ToString());
+ }
+
+ return builder.ToString();
+ }
+ }
+}
@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("XMPP_bot")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("XMPP_bot")]
+[assembly: AssemblyCopyright("Copyright © 2011")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components. If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("f2719dd7-7cc6-411d-9a45-b6a99deab714")]
+
+// Version information for an assembly consists of the following four values:
+//
+// Major Version
+// Minor Version
+// Build Number
+// Revision
+//
+// You can specify all the values or you can default the Build and Revision Numbers
+// by using the '*' as shown below:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
Oops, something went wrong.

0 comments on commit 4c43f26

Please sign in to comment.