1 25 26 package org.snipsnap.notification.jabber; 27 28 import org.jivesoftware.smack.Chat; 29 import org.jivesoftware.smack.XMPPConnection; 30 import org.jivesoftware.smack.packet.Message; 31 import org.radeox.util.logging.Logger; 32 import org.snipsnap.app.Application; 33 34 41 42 public class JabberBot { 43 private static JabberBot instance; 44 private XMPPConnection con; 45 46 public static synchronized JabberBot getInstance() { 47 if (null == instance) { 48 instance = new JabberBot(); 49 } 50 return instance; 51 } 52 53 public JabberBot() { 54 try { 55 con = new XMPPConnection("snipsnap.org"); 56 con.login("snipbot", "snipbot"); 57 61 } catch (Exception e) { 63 Logger.warn("Unable to start JabberBot", e); 64 } 65 } 66 67 public void send(String user, String message) { 68 try { 69 Logger.debug("Sending '" + message + "' to '" + user + "' ..."); 70 Chat chat = con.createChat(user); 71 Message newMessage = chat.createMessage(); 72 newMessage.setBody("message!"); 73 newMessage.setSubject(Application.get().getConfiguration().getName()); 74 chat.sendMessage(newMessage); 75 Logger.debug("Sent."); 76 } catch (Exception e) { 77 Logger.warn("Unable to send message to " + user, e); 78 } 79 } 80 } 81 | Popular Tags |