1 /*** 2 * 3 */ 4 package hu.elte.tribus.services; 5 6 import hu.elte.tribus.interfaces.AnsverFinder; 7 import hu.elte.tribus.interfaces.ConversationDao; 8 import hu.elte.tribus.interfaces.QaDao; 9 import hu.elte.tribus.interfaces.UserDao; 10 import hu.elte.tribus.interfaces.UserTracker; 11 import hu.elte.tribus.model.Topic; 12 13 import java.io.IOException; 14 import java.util.ArrayList; 15 import java.util.List; 16 17 import org.apache.log4j.Logger; 18 import org.schwering.irc.lib.IRCConnection; 19 20 /*** 21 * @author kocka 22 * 23 */ 24 public class IRCService { 25 26 private String nickName = null; 27 private String ircServer = null; 28 private int port = 6667; 29 private List<String> channels = new ArrayList<String>(); 30 private String password; 31 32 private static final Logger logger = Logger.getLogger(IRCService.class); 33 34 private IRCConnection connection; 35 36 private UserTracker tracker; 37 38 private AnsverFinder ansverFinder; 39 40 private UserDao userDao; 41 42 private QaDao qaDao; 43 44 private ConversationDao conversationDao; 45 46 public void init() { 47 logger.info("initializing irc connection"); 48 connection = new IRCConnection(ircServer, new int[]{port}, password, nickName, "yikulju","Yikulju FAQ-O-MAT"); 49 try { 50 connection.setColors(false); 51 connection.setPong(true); 52 connection.setDaemon(true); 53 connection.connect(); 54 for(Topic topic : qaDao.getTopicList()) { 55 connection.doJoin("#"+topic.getName(), topic.getDesc()); 56 connection.doTopic(topic.getDesc()); 57 } 58 } catch (IOException e) { 59 logger.error("Could not connect trying later", e); 60 } 61 logger.info("joined all channells"); 62 } 63 64 public void stop(){ 65 connection.close(); 66 } 67 68 public List<String> getChannels() { 69 return channels; 70 } 71 72 public void setChannels(List<String> channels) { 73 this.channels = channels; 74 } 75 76 public String getIrcServer() { 77 return ircServer; 78 } 79 80 public void setIrcServer(String ircServer) { 81 this.ircServer = ircServer; 82 } 83 84 public String getNickName() { 85 return nickName; 86 } 87 88 public void setNickName(String nickName) { 89 this.nickName = nickName; 90 } 91 92 public int getPort() { 93 return port; 94 } 95 96 public void setPort(int port) { 97 this.port = port; 98 } 99 100 public String getPassword() { 101 return password; 102 } 103 104 public void setPassword(String password) { 105 this.password = password; 106 } 107 108 public AnsverFinder getAnsverFinder() { 109 return ansverFinder; 110 } 111 112 public void setAnsverFinder(AnsverFinder ansverFinder) { 113 this.ansverFinder = ansverFinder; 114 } 115 116 public UserTracker getTracker() { 117 return tracker; 118 } 119 120 public void setTracker(UserTracker tracker) { 121 this.tracker = tracker; 122 } 123 124 public UserDao getUserDao() { 125 return userDao; 126 } 127 128 public void setUserDao(UserDao userDao) { 129 this.userDao = userDao; 130 } 131 132 public QaDao getQaDao() { 133 return qaDao; 134 } 135 136 public void setQaDao(QaDao qaDao) { 137 this.qaDao = qaDao; 138 } 139 140 public ConversationDao getConversationDao() { 141 return conversationDao; 142 } 143 144 public void setConversationDao(ConversationDao conversationDao) { 145 this.conversationDao = conversationDao; 146 } 147 148 }