Advertisement
Guest User

Untitled

a guest
Jul 10th, 2017
497
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.50 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.Threading;
  10. using agsXMPP;
  11. using agsXMPP.Collections;
  12. using agsXMPP.protocol.client;
  13. using agsXMPP.protocol.x.muc;
  14. using SKYPE4COMLib;
  15.  
  16. namespace TestXMPP
  17. {
  18. public partial class Form1 : Form
  19. {
  20. private XmppClientConnection xmpp = new XmppClientConnection();
  21. private MucManager muc = null;
  22. private Skype skype = new Skype();
  23. private Jid piratpartiet_jid = new Jid("piratpartiet@chat.piratpartiet.se");
  24. //private Jid admin_jid = new Jid("admin@chat.piratpartiet.se");
  25. private Hashtable room_maps = new Hashtable();
  26.  
  27. public Form1()
  28. {
  29. InitializeComponent();
  30. }
  31.  
  32. private void Form1_Load(object sender, EventArgs e) {
  33. room_maps.Add("#simon.rosenqvist.87/$21416bb7b5fe785e", piratpartiet_jid);
  34. //room_maps.Add("#rickard.olsson/$4e4ad1e593717944", piratpartiet_jid);
  35. //room_maps.Add("#pvzkth/$72698363351022ba", admin_jid);
  36.  
  37. /*
  38. xmpp.OnReadXml += delegate(object o, String s)
  39. {
  40. Console.WriteLine("XML Recv: " + s);
  41. };
  42.  
  43. xmpp.OnWriteXml += delegate(object o, String s)
  44. {
  45. Console.WriteLine("XML Write: " + s);
  46. };
  47. */
  48.  
  49. xmpp.OnLogin += delegate(object o)
  50. {
  51.  
  52. xmpp.SendMyPresence();
  53. muc = new MucManager(xmpp);
  54.  
  55. foreach (Jid value in room_maps.Values)
  56. {
  57. //muc.AcceptDefaultConfiguration(room);
  58. muc.JoinRoom(value, xmpp.Username, true);
  59.  
  60. agsXMPP.protocol.client.Message message = new agsXMPP.protocol.client.Message(value, MessageType.groupchat , "Hai ppl! //XMPPSkypeBot");
  61. //xmpp.Send(message);
  62. }
  63. };
  64.  
  65.  
  66. xmpp.OnError += delegate(object o, Exception x)
  67. {
  68. Console.WriteLine("EXCEPTION RECEIVED!");
  69. Console.WriteLine(x.Message);
  70.  
  71.  
  72. };
  73.  
  74. xmpp.OnMessage += delegate(object o, agsXMPP.protocol.client.Message ms)
  75. {
  76.  
  77. String body = ms.Body;
  78. //String xmppsender = ms.To.User.ToString();
  79. String xmppsender = ms.From.Resource.ToString();
  80. String chatid = ms.From.Bare.ToString();
  81.  
  82. Console.WriteLine(xmppsender);
  83.  
  84. if (room_maps.ContainsValue(new Jid(chatid)) && !body.StartsWith(skype.CurrentUser.FullName)) //Are we in this chat? + Loop check
  85. {
  86. String key = FindKey(new Jid(chatid));
  87.  
  88. Console.WriteLine("Mapped to: " + key);
  89. IChat skypechat = skype.get_Chat(key);
  90. skypechat.SendMessage(xmppsender + ": " + body);
  91.  
  92. Thread.Sleep(5000);
  93. }
  94. };
  95.  
  96. //xmpp.Server = "piratechat.net";
  97. //xmpp.ConnectServer = "piratechat.net";
  98. //xmpp.Username = "cluez";
  99. //xmpp.Password = "";
  100. xmpp.Server = "xmpp.piratpartiet.se";
  101. xmpp.ConnectServer = "xmpp.piratpartiet.se";
  102. xmpp.Username = "xmppskype";
  103. xmpp.Password = "";
  104.  
  105. xmpp.Open();
  106.  
  107. skype.Attach(7, false); //Protocol version 7, do not wait
  108. skype.MessageStatus += new _ISkypeEvents_MessageStatusEventHandler(skype_MessageStatus);
  109. }
  110.  
  111. private void skype_MessageStatus(ChatMessage msg, TChatMessageStatus status)
  112. {
  113. if (status == TChatMessageStatus.cmsReceived)
  114. {
  115. //agsXMPP.protocol.client.Message xmppmessage = new agsXMPP.protocol.client.Message(new Jid("cluez@piratechat.net"), MessageType.chat, msg.Body);
  116. //xmpp.Send(xmppmessage);
  117.  
  118. if (room_maps.ContainsKey(msg.ChatName))
  119. {
  120. Jid tmpjid = (Jid)room_maps[msg.ChatName];
  121. agsXMPP.protocol.client.Message message = new agsXMPP.protocol.client.Message(tmpjid, MessageType.groupchat, msg.Sender.FullName + ": " + msg.Body);
  122. xmpp.Send(message);
  123. }
  124. }
  125. if (status == TChatMessageStatus.cmsSent)
  126. {
  127. if (room_maps.ContainsKey(msg.ChatName) && !msg.Body.Contains(":"))
  128. {
  129. Jid tmpjid = (Jid)room_maps[msg.ChatName];
  130. agsXMPP.protocol.client.Message message = new agsXMPP.protocol.client.Message(tmpjid, MessageType.groupchat, msg.Sender.FullName + ": " + msg.Body);
  131. xmpp.Send(message);
  132. }
  133. }
  134. }
  135.  
  136. private void button1_Click(object sender, EventArgs e)
  137. {
  138. MessageBox.Show("Connection State: " + xmpp.XmppConnectionState.ToString());
  139. MessageBox.Show("Authenticated: " + xmpp.Authenticated.ToString());
  140. }
  141.  
  142.  
  143. public string FindKey(Jid myValue)
  144. {
  145. string myKey="";
  146.  
  147. foreach (String aKey in room_maps.Keys)
  148. {
  149. if (room_maps[aKey].Equals(myValue)) myKey = aKey;
  150. }
  151.  
  152. return myKey;
  153. }
  154.  
  155.  
  156. }
  157. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement