1 20 21 package freecs.commands; 22 import freecs.interfaces.ICommand; 23 import freecs.interfaces.IGroupState; 24 import freecs.interfaces.IUserStates; 25 import freecs.content.MessageState; 26 import freecs.core.Group; 27 import freecs.core.User; 28 29 34 public class CmdAck extends AbstractCommand { 35 public final String cmd= "/ack"; 36 private static final ICommand selve=new CmdAck(); 37 38 private CmdAck () { } 39 40 public static ICommand getInstance () { 41 return selve; 42 } 43 44 public boolean execute (MessageState msgState, String param) { 45 if (!msgState.sender.hasRight(IUserStates.IS_MODERATOR)) { 46 msgState.msgTemplate = "error.noRight.noModAdmin"; 47 msgState.sender.sendMessage (msgState.mp); 48 return false; 49 } 50 if (!msgState.sender.getGroup().hasState(IGroupState.MODERATED)) { 51 msgState.targetGroup=msgState.sender.getGroup(); 52 msgState.msgTemplate = "error.ack.groupNotModerated"; 53 msgState.sender.sendMessage (msgState.mp); 54 return false; 55 } 56 if (param.length () < 1) { 57 msgState.msgTemplate = "error.ack.noArg"; 58 msgState.sender.sendMessage (msgState.mp); 59 return false; 60 } 61 62 int pos = param.indexOf(" "); 63 if (pos == -1) { 64 msgState.msgTemplate = "error.ack.noMessage"; 65 msgState.sender.sendMessage (msgState.mp); 66 return false; 67 } 68 String uname = param.substring(0,pos).trim(); 69 User u = getUser(msgState, uname); 70 if (u == null) 71 return false; 72 String msg = param.substring (pos).trim(); 73 User moderator = msgState.sender; 74 Group g = moderator.getGroup(); 75 if (!g.equals (u.getGroup())) { 76 msgState.msgTemplate = "error.ack.userNotInGroup"; 77 moderator.sendMessage (msgState.mp); 78 return false; 79 } 80 msgState.sender = u; 81 if (msg.startsWith ("/")) { 82 pos = msg.indexOf (" "); 83 ICommand ic = CommandSet.getCommandSet().getCommand(msg.substring (0,pos)); 84 ic.execute (msgState, msg.substring (pos).trim ()); 85 } else { 86 msgState.msgTemplate = "message.send"; 87 msgState.message = msg; 88 g.sendModeratedMessage (msgState.mp); 89 } 90 msgState.msgTemplate="message.ack"; 91 msgState.message = msg; 92 msgState.sender = moderator; 93 moderator.sendMessage (msgState.mp); 94 return true; 95 } 96 } 97 | Popular Tags |