Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Collections;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Text;
- using System.Windows.Forms;
- using System.Threading;
- using agsXMPP;
- using agsXMPP.Collections;
- using agsXMPP.protocol.client;
- using agsXMPP.protocol.x.muc;
- using SKYPE4COMLib;
- namespace TestXMPP
- {
- public partial class Form1 : Form
- {
- private XmppClientConnection xmpp = new XmppClientConnection();
- private MucManager muc = null;
- private Skype skype = new Skype();
- private Jid piratpartiet_jid = new Jid("piratpartiet@chat.piratpartiet.se");
- //private Jid admin_jid = new Jid("admin@chat.piratpartiet.se");
- private Hashtable room_maps = new Hashtable();
- public Form1()
- {
- InitializeComponent();
- }
- private void Form1_Load(object sender, EventArgs e) {
- room_maps.Add("#simon.rosenqvist.87/$21416bb7b5fe785e", piratpartiet_jid);
- //room_maps.Add("#rickard.olsson/$4e4ad1e593717944", piratpartiet_jid);
- //room_maps.Add("#pvzkth/$72698363351022ba", admin_jid);
- /*
- xmpp.OnReadXml += delegate(object o, String s)
- {
- Console.WriteLine("XML Recv: " + s);
- };
- xmpp.OnWriteXml += delegate(object o, String s)
- {
- Console.WriteLine("XML Write: " + s);
- };
- */
- xmpp.OnLogin += delegate(object o)
- {
- xmpp.SendMyPresence();
- muc = new MucManager(xmpp);
- foreach (Jid value in room_maps.Values)
- {
- //muc.AcceptDefaultConfiguration(room);
- muc.JoinRoom(value, xmpp.Username, true);
- agsXMPP.protocol.client.Message message = new agsXMPP.protocol.client.Message(value, MessageType.groupchat , "Hai ppl! //XMPPSkypeBot");
- //xmpp.Send(message);
- }
- };
- xmpp.OnError += delegate(object o, Exception x)
- {
- Console.WriteLine("EXCEPTION RECEIVED!");
- Console.WriteLine(x.Message);
- };
- xmpp.OnMessage += delegate(object o, agsXMPP.protocol.client.Message ms)
- {
- String body = ms.Body;
- //String xmppsender = ms.To.User.ToString();
- String xmppsender = ms.From.Resource.ToString();
- String chatid = ms.From.Bare.ToString();
- Console.WriteLine(xmppsender);
- if (room_maps.ContainsValue(new Jid(chatid)) && !body.StartsWith(skype.CurrentUser.FullName)) //Are we in this chat? + Loop check
- {
- String key = FindKey(new Jid(chatid));
- Console.WriteLine("Mapped to: " + key);
- IChat skypechat = skype.get_Chat(key);
- skypechat.SendMessage(xmppsender + ": " + body);
- Thread.Sleep(5000);
- }
- };
- //xmpp.Server = "piratechat.net";
- //xmpp.ConnectServer = "piratechat.net";
- //xmpp.Username = "cluez";
- //xmpp.Password = "";
- xmpp.Server = "xmpp.piratpartiet.se";
- xmpp.ConnectServer = "xmpp.piratpartiet.se";
- xmpp.Username = "xmppskype";
- xmpp.Password = "";
- xmpp.Open();
- skype.Attach(7, false); //Protocol version 7, do not wait
- skype.MessageStatus += new _ISkypeEvents_MessageStatusEventHandler(skype_MessageStatus);
- }
- private void skype_MessageStatus(ChatMessage msg, TChatMessageStatus status)
- {
- if (status == TChatMessageStatus.cmsReceived)
- {
- //agsXMPP.protocol.client.Message xmppmessage = new agsXMPP.protocol.client.Message(new Jid("cluez@piratechat.net"), MessageType.chat, msg.Body);
- //xmpp.Send(xmppmessage);
- if (room_maps.ContainsKey(msg.ChatName))
- {
- Jid tmpjid = (Jid)room_maps[msg.ChatName];
- agsXMPP.protocol.client.Message message = new agsXMPP.protocol.client.Message(tmpjid, MessageType.groupchat, msg.Sender.FullName + ": " + msg.Body);
- xmpp.Send(message);
- }
- }
- if (status == TChatMessageStatus.cmsSent)
- {
- if (room_maps.ContainsKey(msg.ChatName) && !msg.Body.Contains(":"))
- {
- Jid tmpjid = (Jid)room_maps[msg.ChatName];
- agsXMPP.protocol.client.Message message = new agsXMPP.protocol.client.Message(tmpjid, MessageType.groupchat, msg.Sender.FullName + ": " + msg.Body);
- xmpp.Send(message);
- }
- }
- }
- private void button1_Click(object sender, EventArgs e)
- {
- MessageBox.Show("Connection State: " + xmpp.XmppConnectionState.ToString());
- MessageBox.Show("Authenticated: " + xmpp.Authenticated.ToString());
- }
- public string FindKey(Jid myValue)
- {
- string myKey="";
- foreach (String aKey in room_maps.Keys)
- {
- if (room_maps[aKey].Equals(myValue)) myKey = aKey;
- }
- return myKey;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement