📄 command.java
字号:
package com.afuer.chat;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* Handles the admin command.
*/
public class Command {
private static Log log = LogFactory.getLog(EmotIcon.class);
private static Map commandMap = new HashMap();
private static final String CMD_SUSPEND = "suspend";
private static final String CMD_RESUME = "resume";
private static final String CMD_CLEAR = "clear";
private static final String CMD_CLEARLAST = "clearlast";
private static final String CMD_CLEARMSG = "clearmsg";
private static final String CMD_CLEARALL = "clearall";
private static final String CMD_STICKY = "sticky";
private static final String CMD_REMOVESTICKY = "removesticky";
private static final String CMD_LIMIT = "limit";
private static final String CMD_MSGLENGTH = "msglength";
private static final String CMD_ENABLEURL = "enableurl";
private static final String CMD_DISABLEURL = "disableurl";
private static final String CMD_ENABLEIMAGE = "enableimage";
private static final String CMD_DISABLEIMAGE = "disableimage";
private static final String CMD_RELOADEMOTICON = "releademoticon";
private static final String CMD_ENABLEUSEREMOTICON = "enableuseremoticon";
private static final String CMD_DISABLEUSEREMOTICON = "disableuseremoticon";
private static final String CMD_ENABLEMSGEMOTICON = "enablemsgemoticon";
private static final String CMD_DISABLEMSGEMOTICON = "disablemsgemoticon";
private static final String CMD_ENABLEHTMLESCAPE = "enablehtmlescape";
private static final String CMD_DISABLEHTMLESCAPE = "disablehtmlescape";
private static final String CMD_INVISIBLE = "invisible";
private static final String CMD_VISIBLE = "visible";
static void init(String configFile) {
InputStream is = null;
Properties prop = new Properties();
try {
is = new FileInputStream(configFile);
prop.load(is);
commandMap.clear();
for (Iterator it = prop.keySet().iterator(); it.hasNext();) {
String key = (String) it.next();
String value = prop.getProperty(key);
commandMap.put(value, key);
}
}
catch (IOException ex) {
log.error(ex, ex);
}
finally {
if (is != null) {
try {
is.close();
}
catch (IOException ex) {
log.warn("Exception when closing input stream", ex);
}
}
}
}
/**
* @return true if a command is processed
*/
static boolean process(String t, Chat chat, ChatConfig config) {
// check command prefix
String commandPrefix = ChatConfig.getInstance().getCommandPrefix();
if (commandPrefix != null && commandPrefix.length() > 0) {
if (!t.startsWith(commandPrefix)) {
return false;
}
t = t.substring(commandPrefix.length());
}
String commandPart = t;
String argPart = "";
long argNum = 0;
int pos = commandPart.indexOf(" ");
if (pos > 0) {
argPart = commandPart.substring(pos + 1).trim();
try {
argNum = Long.parseLong(argPart);
}
catch (NumberFormatException ex) {
; // do nothing
}
commandPart = commandPart.substring(0, pos).trim();
}
String command = (String) commandMap.get(commandPart);
if (CMD_SUSPEND.equals(command)) {
config.setSuspend(true);
}
else if (CMD_RESUME.equals(command)) {
config.setSuspend(false);
}
else if (CMD_CLEAR.equals(command)) {
if (argPart.length() > 0) {
if (argNum > 0) {
for (int i = 0; i < argNum && chat.getNonStickyMessage().size() > 0; i++) {
chat.removeLastMessage();
}
}
else if (argNum < 0) {
for (int i = 0; i < (-argNum) && chat.getNonStickyMessage().size() > 0; i++) {
chat.removeFirstMessage();
}
}
}
else {
chat.clearMessage();
}
}
else if (CMD_CLEARLAST.equals(command)) {
chat.removeFirstMessage();
}
else if (CMD_CLEARMSG.equals(command)) {
chat.clearMessage();
}
else if (CMD_CLEARALL.equals(command)) {
chat.clearMessage();
chat.clearSticky();
}
else if (CMD_STICKY.equals(command)) {
if (argPart.length() > 0) {
chat.setSticky(argNum);
}
}
else if (CMD_REMOVESTICKY.equals(command)) {
if (argPart.length() > 0) {
chat.removeSticky(argNum);
}
}
else if (CMD_LIMIT.equals(command)) {
if (argNum > 0) {
config.setLimit((int) argNum);
}
}
else if (CMD_MSGLENGTH.equals(command)) {
if (argNum > 0) {
config.setMsgLength((int) argNum);
}
}
else if (CMD_ENABLEURL.equals(command)) {
config.setEnableUrl(true);
}
else if (CMD_DISABLEURL.equals(command)) {
config.setEnableUrl(false);
}
else if (CMD_ENABLEIMAGE.equals(command)) {
config.setEnableImage(true);
}
else if (CMD_DISABLEIMAGE.equals(command)) {
config.setEnableImage(false);
}
else if (CMD_RELOADEMOTICON.equals(command)) {
EmotIcon.reInit();
}
else if (CMD_ENABLEUSEREMOTICON.equals(command)) {
config.setEnableUserEmotIcon(true);
}
else if (CMD_DISABLEUSEREMOTICON.equals(command)) {
config.setEnableUserEmotIcon(false);
}
else if (CMD_ENABLEMSGEMOTICON.equals(command)) {
config.setEnableMsgEmotIcon(true);
}
else if (CMD_DISABLEMSGEMOTICON.equals(command)) {
config.setEnableMsgEmotIcon(false);
}
else if (CMD_ENABLEHTMLESCAPE.equals(command)) {
config.setEnableHtmlEscape(true);
}
else if (CMD_DISABLEHTMLESCAPE.equals(command)) {
config.setEnableHtmlEscape(false);
}
else if (CMD_VISIBLE.equals(command)) {
;
}
else if (CMD_INVISIBLE.equals(command)) {
;
}
else {
return false;
}
return true;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -