1 18 package net.sf.drftpd.event.irc; 19 20 import java.util.Iterator ; 21 22 import net.sf.drftpd.SlaveUnavailableException; 23 import net.sf.drftpd.master.ConnectionManager; 24 import net.sf.drftpd.master.RemoteSlave; 25 import net.sf.drftpd.slave.SlaveStatus; 26 import net.sf.drftpd.util.ReplacerUtils; 27 28 import org.apache.log4j.Level; 29 import org.apache.log4j.Logger; 30 import org.drftpd.plugins.SiteBot; 31 import org.tanesha.replacer.ReplacerEnvironment; 32 33 import f00f.net.irc.martyr.GenericAutoService; 34 import f00f.net.irc.martyr.InCommand; 35 import f00f.net.irc.martyr.State; 36 import f00f.net.irc.martyr.commands.MessageCommand; 37 38 42 public class Slaves extends GenericAutoService implements IRCPluginInterface { 43 44 private static final Logger logger = Logger.getLogger(Slaves.class); 45 46 private SiteBot _listener; 47 48 public Slaves(SiteBot listener) { 49 super(listener.getIRCConnection()); 50 _listener = listener; 51 } 52 53 public String getCommands() { 54 return "!slaves"; 55 } 56 57 private ConnectionManager getConnectionManager() { 58 return _listener.getConnectionManager(); 59 } 60 61 protected void updateCommand(InCommand inCommand) { 62 if (!(inCommand instanceof MessageCommand)) 63 return; 64 MessageCommand msgc = (MessageCommand) inCommand; 65 if (!((MessageCommand) inCommand).getMessage().equals("!slaves")) 66 return; 67 if (msgc.isPrivateToUs(_listener.getIRCConnection().getClientState())) 68 return; 69 String chan = msgc.getDest(); 70 71 for (Iterator iter = 72 getConnectionManager().getSlaveManager().getSlaves().iterator(); 73 iter.hasNext(); 74 ) { 75 RemoteSlave rslave = (RemoteSlave) iter.next(); 76 String statusString; 77 78 ReplacerEnvironment env = 79 new ReplacerEnvironment(SiteBot.GLOBAL_ENV); 80 env.add("slave", rslave.getName()); 81 82 try { 83 SlaveStatus status; 84 try { 85 status = rslave.getStatus(); 86 } catch (SlaveUnavailableException e1) { 87 String chan1 = chan; 88 _listener.sayChannel( 89 chan1, 90 ReplacerUtils.jprintf( 91 "slaves.offline", 92 env, 93 Slaves.class)); 94 continue; 95 } 96 SiteBot.fillEnvSlaveStatus(env, status, _listener.getSlaveManager()); 97 98 statusString = 99 ReplacerUtils.jprintf("slaves", env, Slaves.class); 100 } catch (RuntimeException t) { 101 logger.log( 102 Level.WARN, 103 "Caught RuntimeException in !slaves loop", 104 t); 105 statusString = ReplacerUtils.jprintf( 106 "slaves.offline", 107 env, 108 Slaves.class); 109 } 110 String chan1 = chan; 111 String string = statusString; 112 _listener.sayChannel(chan1, string); 113 } 114 115 } 116 117 protected void updateState(State state) { 118 } 119 120 } 121 | Popular Tags |