From 01818b95286bc2bf96a4adad42c2194e487f373a Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Wed, 21 Mar 2018 16:33:12 +0300 Subject: drop xmpp-wip --- .../main/java/com/juick/components/XMPPBot.java | 113 --------------------- 1 file changed, 113 deletions(-) delete mode 100644 juick-xmpp-wip/src/main/java/com/juick/components/XMPPBot.java (limited to 'juick-xmpp-wip/src/main/java/com/juick/components/XMPPBot.java') diff --git a/juick-xmpp-wip/src/main/java/com/juick/components/XMPPBot.java b/juick-xmpp-wip/src/main/java/com/juick/components/XMPPBot.java deleted file mode 100644 index 27206a32..00000000 --- a/juick-xmpp-wip/src/main/java/com/juick/components/XMPPBot.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Copyright (C) 2008-2017, Juick - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package com.juick.components; - -import com.juick.User; -import com.juick.server.helpers.UserInfo; -import com.juick.service.PMQueriesService; -import com.juick.service.UserService; -import org.apache.commons.io.IOUtils; -import org.apache.commons.lang3.math.NumberUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.core.env.Environment; -import rocks.xmpp.addr.Jid; -import rocks.xmpp.core.XmppException; -import rocks.xmpp.core.stanza.model.Message; -import rocks.xmpp.extensions.component.accept.ExternalComponent; -import rocks.xmpp.extensions.vcard.temp.VCardManager; -import rocks.xmpp.extensions.vcard.temp.model.VCard; - -import javax.annotation.PostConstruct; -import javax.inject.Inject; -import java.io.IOException; -import java.net.URL; - -/** - * Created by vt on 12/11/2016. - */ -@SpringBootApplication -public class XMPPBot implements AutoCloseable { - private static final Logger logger = LoggerFactory.getLogger(XMPPBot.class); - @Inject - private UserService userService; - @Inject - private PMQueriesService pmQueriesService; - @Inject - private Environment env; - - Jid juickJid; - - private ExternalComponent component; - - @PostConstruct - @Inject - public void init() { - component = ExternalComponent.create(env.getProperty("component_name", "juick.com"), - env.getProperty("component_password", "secret"), env.getProperty("component_host", "localhost"), - NumberUtils.toInt(env.getProperty("component_port", "5347"), 5347)); - juickJid = Jid.of(env.getProperty("xmppbot_jid", "juick@juick.com/Juick")); - try { - VCardManager vCardManager = component.getManager(VCardManager.class); - vCardManager.setEnabled(true); - VCard ownVCard = new VCard(); - ownVCard.setNickname("Juick"); - ownVCard.setUrl(new URL("http://juick.com/")); - ownVCard.setPhoto(new VCard.Image("image/png", IOUtils.toByteArray(getClass().getClassLoader().getResourceAsStream("vCard.png")))); - vCardManager.setVCard(ownVCard); - component.addInboundMessageListener(e -> { - Message message = e.getMessage(); - if (message.getType().equals(Message.Type.ERROR) || message.getType().equals(Message.Type.GROUPCHAT)) { - return; - } - String text = message.getBody().trim(); - String command = text.toUpperCase(); - User user = userService.getUserByJID(message.getFrom().asBareJid().toString()); - if (command.equals("VCARD")) { - try { - VCard vCard = vCardManager.getVCard(message.getFrom().asBareJid()).getResult(); - UserInfo info = new UserInfo(); - info.setFullName(vCard.getFormattedName()); - info.setCountry(vCard.getAddresses().get(0).getCountry()); - info.setUrl(vCard.getUrl().toString()); - userService.updateUserInfo(user, info); - component.sendMessage(new Message(message.getFrom(), Message.Type.CHAT, "vCard updated")); - } catch (XmppException vce) { - logger.warn("vcard exception", vce); - } - } - }); - component.connect(); - } catch (XmppException | IOException e) { - logger.error("bot connection error", e); - } - } - - @Override - public void close() throws Exception { - if (component != null) - component.close(); - - logger.info("ExternalComponent on xmpp-bot destroyed"); - } - public static void main(String[] args) { - SpringApplication.run(XMPPBot.class, args); - } -} -- cgit v1.2.3