diff options
author | Vitaly Takmazov | 2016-02-03 13:54:12 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2016-02-03 13:54:12 +0300 |
commit | e80e13c27e6f06c52a3dc8602cd1f02abdfc3180 (patch) | |
tree | a309a04f63bd0e4eefae4b0583e88352f1f0e802 /src/main/java/com/juick/xmpp/JuickBot.java | |
parent | 380018da475ff41d3375e7f2bea0a192a4d9b178 (diff) |
WIP
Diffstat (limited to 'src/main/java/com/juick/xmpp/JuickBot.java')
-rw-r--r-- | src/main/java/com/juick/xmpp/JuickBot.java | 52 |
1 files changed, 27 insertions, 25 deletions
diff --git a/src/main/java/com/juick/xmpp/JuickBot.java b/src/main/java/com/juick/xmpp/JuickBot.java index 6104d19d..56260f97 100644 --- a/src/main/java/com/juick/xmpp/JuickBot.java +++ b/src/main/java/com/juick/xmpp/JuickBot.java @@ -1,6 +1,6 @@ package com.juick.xmpp; -import com.juick.JuickNotificator; +import com.juick.JuickApplication; import com.juick.User; import com.juick.server.PMQueries; import com.juick.server.TagQueries; @@ -22,12 +22,14 @@ public class JuickBot { JdbcTemplate sql; Stream xmpp; - JuickNotificator notificator; + JuickApplication notificator; + S2SComponent s2s; - public JuickBot(JuickNotificator notificator, JdbcTemplate sql, Stream xmpp) { + public JuickBot(JuickApplication notificator, S2SComponent s2s) { this.notificator = notificator; - this.sql = sql; - this.xmpp = xmpp; + sql = notificator.getSql(); + xmpp = notificator.getRouter(); + this.s2s = s2s; } public static final JID JuickJID = new JID("juick", "juick.com", "Juick"); @@ -74,7 +76,7 @@ public class JuickBot { reply.from = new JID(p.to.Username, p.to.Host, null); reply.to = new JID(p.from.Username, p.from.Host, null); reply.type = Presence.Type.unsubscribe; - S2SComponent.sendOut(reply); + s2s.sendOut(reply); return true; } else if (p.type.equals(Presence.Type.probe)) { int uid_to = 0; @@ -88,12 +90,12 @@ public class JuickBot { reply.from.Resource = "Juick"; reply.to = p.from; reply.priority = 10; - S2SComponent.sendOut(reply); + s2s.sendOut(reply); } else { Presence reply = new Presence(p.to, p.from, Presence.Type.error); reply.id = p.id; reply.addChild(new Error(Error.Type.cancel, "item-not-found")); - S2SComponent.sendOut(reply); + s2s.sendOut(reply); return true; } return true; @@ -111,19 +113,19 @@ public class JuickBot { if (canSubscribe) { Presence reply = new Presence(p.to, p.from, Presence.Type.subscribed); - S2SComponent.sendOut(reply); + s2s.sendOut(reply); reply.from.Resource = "Juick"; reply.priority = 10; reply.type = null; - S2SComponent.sendOut(reply); + s2s.sendOut(reply); return true; } else { Presence reply = new Presence(p.to, p.from, Presence.Type.error); reply.id = p.id; reply.addChild(new Error(Error.Type.cancel, "item-not-found")); - S2SComponent.sendOut(reply); + s2s.sendOut(reply); return true; } } else if (p.type.equals(Presence.Type.unsubscribe)) { @@ -135,7 +137,7 @@ public class JuickBot { } Presence reply = new Presence(p.to, p.from, Presence.Type.unsubscribed); - S2SComponent.sendOut(reply); + s2s.sendOut(reply); } return false; @@ -162,7 +164,7 @@ public class JuickBot { } else { reply.body = "Внимание, системное сообщение!\nВаш JabberID не обнаружен в списке доверенных. Для того, чтобы отправить сообщение пользователю " + username + "@juick.com, пожалуйста зарегистрируйте свой JabberID в системе: http://juick.com/signup?type=xmpp&hash=" + signuphash + "\nЕсли у вас уже есть учетная запись на Juick, вы сможете присоединить этот JabberID к ней.\n\nWarning, system message!\nYour JabberID is not found in our server's white list. To send a message to " + username + "@juick.com, please sign up: http://juick.com/signup?type=xmpp&hash=" + signuphash + "\nIf you already have an account on Juick, you will be proposed to attach this JabberID to your existing account."; } - S2SComponent.sendOut(reply); + s2s.sendOut(reply); return true; } @@ -176,7 +178,7 @@ public class JuickBot { Message reply = new Message(msg.to, msg.from, Message.Type.error); reply.id = msg.id; reply.addChild(new Error(Error.Type.cancel, "item-not-found")); - S2SComponent.sendOut(reply); + s2s.sendOut(reply); return true; } @@ -217,14 +219,14 @@ public class JuickBot { mm.from = new JID("juick", "juick.com", "Juick"); mm.body = "Private message from @" + jmsg.getUser().getUName() + ":\n" + msg.body; } - S2SComponent.sendOut(mm); + s2s.sendOut(mm); } } else { Message reply = new Message(msg.to, msg.from, Message.Type.error); reply.id = msg.id; reply.addChild(new Error(Error.Type.cancel, "not-allowed")); - S2SComponent.sendOut(reply); + s2s.sendOut(reply); } return true; @@ -268,26 +270,26 @@ public class JuickBot { return false; } - private static void commandPing(Message m) { + private void commandPing(Message m) { Presence p = new Presence(JuickJID, m.from); p.priority = 10; - S2SComponent.sendOut(p); + s2s.sendOut(p); Message reply = new Message(JuickJID, m.from, Message.Type.chat); reply.body = "PONG"; - S2SComponent.sendOut(reply); + s2s.sendOut(reply); } - private static void commandHelp(Message m) { + private void commandHelp(Message m) { Message reply = new Message(JuickJID, m.from, Message.Type.chat); reply.body = HELPTEXT; - S2SComponent.sendOut(reply); + s2s.sendOut(reply); } private void commandLogin(Message m, User user_from) { Message reply = new Message(JuickJID, m.from, Message.Type.chat); reply.body = "http://juick.com/login?" + UserQueries.getHashByUID(sql, user_from.getUID()); - S2SComponent.sendOut(reply); + s2s.sendOut(reply); } private void commandPM(Message m, User user_from, String user_to, String body) { @@ -346,7 +348,7 @@ public class JuickBot { mm.from = new JID("juick", "juick.com", "Juick"); mm.body = "Private message from @" + user_from.getUName() + ":\n" + body; } - S2SComponent.sendOut(mm); + s2s.sendOut(mm); } } @@ -358,7 +360,7 @@ public class JuickBot { reply.type = Message.Type.error; reply.body = "Error " + ret; } - S2SComponent.sendOut(reply); + s2s.sendOut(reply); } private void commandBLShow(Message m, User user_from) { @@ -390,6 +392,6 @@ public class JuickBot { Message reply = new Message(JuickJID, m.from, Message.Type.chat); reply.body = txt; - S2SComponent.sendOut(reply); + s2s.sendOut(reply); } } |