当前位置: 首页>>代码示例>>Java>>正文


Java ChatMessage类代码示例

本文整理汇总了Java中com.skype.ChatMessage的典型用法代码示例。如果您正苦于以下问题:Java ChatMessage类的具体用法?Java ChatMessage怎么用?Java ChatMessage使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ChatMessage类属于com.skype包,在下文中一共展示了ChatMessage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: handleCommand

import com.skype.ChatMessage; //导入依赖的package包/类
/**
 * This methods handles the command preprocess and execution. It does all
 * necessary checking before executing the command. Checking if commands are
 * enabled if this user can execute a command and more. (check
 * {@link #canExecuteCommand(String, ChatMessage)}
 * <p>
 * If the user is administrator he can execute the command no matter what.
 *
 * @param commandMessage
 *            the command message.
 * @throws SkypeException
 *             the skype exception
 */
public void handleCommand(ChatMessage commandMessage) throws SkypeException {
	final String senderId = commandMessage.getSenderId();
	final String[] splittedCommand = preprocessCommand(commandMessage,commandMessage.getSenderId());
	final CommandData data = createCommandData(commandMessage, splittedCommand);
	Command command = null;

	try {
		command = getCommand(splittedCommand);
	} catch (UnknownCommandException e) {
		commandMessage.getChat().send("Unknown command.");
		return;
	}

	if (!canExecuteCommand(senderId, command.getName()))
		return;

	extraHandling(splittedCommand, data);

	command.setData(data);
	CommandInvoker.execute(command);
	findSenderInformation(senderId).increaseTotalCommandsToday(); //increase commands
}
 
开发者ID:Cuniq,项目名称:SkypeBot,代码行数:36,代码来源:CommandHandler.java

示例2: preprocessCommand

import com.skype.ChatMessage; //导入依赖的package包/类
/**
 * Receives a command and the id of sender. The command format is
 * "!CommandName [list_of_parameters]". It splits the command and each one of
 * parameters to a String array and removes the exclamation mark from the
 * beginning of command. Also checks if the sender of command is the owner of the
 * bot, if yes then we delete the command from skype client.
 * 
 * @param commandMessage
 *            The message with hold the command as a big string
 * @return the commandMessage text splitted.
 * @throws SkypeException
 */
private String[] preprocessCommand(ChatMessage commandMessage,
		String senderId) throws SkypeException {

	final String[] splittedCommand = StringUtil
		.splitIgoringQuotes(commandMessage.getContent());

	//Remove ! from the beginning of command 
	splittedCommand[COMMAND_NAME_POS] =
		splittedCommand[COMMAND_NAME_POS].substring(EXCLAMATION_POSITION).toLowerCase();

	//TODO: Give user a config option for that.
	if (isSenderBotsOwner(senderId))
		commandMessage.setContent("");

	return splittedCommand;

}
 
开发者ID:Cuniq,项目名称:SkypeBot,代码行数:30,代码来源:CommandHandler.java

示例3: handleNormalChat

import com.skype.ChatMessage; //导入依赖的package包/类
public void handleNormalChat(ChatMessage message, Long timeSend) throws SkypeException {
	UserInformation userInfo = users.get((message.getSender().getId()));
	userInfo.increaseTotalMessagesToday();

	if (userInfo.getLastMessage() == null) {
		userInfo.setLastMessage(message, timeSend);
		return;
	}
		
	if (Config.EnableWarnings) {
		if (!canHandleWarning(message))
			return;

		if (timeSend - userInfo.getLastMessageTime() < Config.WarningInterval) {
			userInfo.increaseWarning();
		}

		if (userInfo.getWarnings() >= Config.WarningNumber) {
			userInfo.ResetWarnings();
			takeWarningAction(message);
		}

		userInfo.setLastMessage(message, timeSend);
	}

}
 
开发者ID:Cuniq,项目名称:SkypeBot,代码行数:27,代码来源:NormalChatHandler.java

示例4: takeWarningAction

import com.skype.ChatMessage; //导入依赖的package包/类
private void takeWarningAction(ChatMessage message) {
	try {
		Chat outputChat = message.getChat();
		String senderID = message.getSender().getId();

		if (WARNING_ACTION == Config.WARNING_ACTION_SET_LISTENER)
			outputChat.send("/setrole " + senderID + " LISTENER");
		else if (WARNING_ACTION == Config.WARNING_ACTION_KICK)
			outputChat.send("/kick " + senderID);
		else if (WARNING_ACTION == Config.WARNING_ACTION_KICKBAN)
			outputChat.send("/kickban " + senderID);

	} catch (SkypeException e) {
		//sending command with api throws exception. Ignore them.
	}

}
 
开发者ID:Cuniq,项目名称:SkypeBot,代码行数:18,代码来源:NormalChatHandler.java

示例5: chatMessageSent

import com.skype.ChatMessage; //导入依赖的package包/类
/**
 * This is the main method of this class. For every message user sends it checks
 * if it is "!addlister" and if it then it clears the message from skype and adds
 * one {@link GroupChatListener listener} for this specific chat.
 * 
 * <p>
 * Also this method checks if user has activated edit lister. If he has then it
 * also registers and one {@link GroupChatEditListener editListener} for the
 * specific chat.
 * 
 * @see com.skype.ChatMessageListener#chatMessageSent(com.skype.ChatMessage)
 * 
 */
@Override
public void chatMessageSent(ChatMessage sent) throws SkypeException {
	if (!sent.getContent().equalsIgnoreCase("!addlistener"))
		return;

	Chat chat = sent.getChat();
	if (!registeredChats.contains(chat)) {
		sent.setContent("");

		GroupChatListener group = new GroupChatListener(chat);
		Skype.addChatMessageListener(group);

		//System.out.println(chat.getWindowTitle());

		if (Config.EnableEdits)
			Skype.addChatMessageEditListener(group.getEditListener());

		registeredChats.add(chat);
	}
}
 
开发者ID:Cuniq,项目名称:SkypeBot,代码行数:34,代码来源:GroupChatAdderListener.java

示例6: handle

import com.skype.ChatMessage; //导入依赖的package包/类
private void handle(ChatMessage message) throws Exception {
    if (!CHATBOT_TROLL) {
        try {
            String[] args = message.getContent().split(" ");
            if (commands.containsKey(args[0])) {
                String response = commands.get(args[0]).command(message, Arrays.copyOfRange(args, 1, args.length));
                if (response == null) return;
                Keyboard.type(response);
                if (DEBUG) System.out.println(response);
            }
        } catch (SkypeException e) {
            System.out.println("invalid message " + message);
            e.printStackTrace();
        }
    } else {
        ChatterBotSession bot;
        if (!cleverBots.containsKey(message.getSenderId()))
            cleverBots.put(message.getSenderId(), botFactory.create(ChatterBotType.CLEVERBOT).createSession());
        bot = cleverBots.get(message.getSenderId());
        Keyboard.type(bot.think(
                message.
                        getContent()));
    }
}
 
开发者ID:rowtn,项目名称:SkypeNet,代码行数:25,代码来源:SkypeNet.java

示例7: clearMessages

import com.skype.ChatMessage; //导入依赖的package包/类
/**
 * This method is responsible for removing messages which are no longer editable.
 */
private void clearMessages() {
	Set<ChatMessage> keys = messages.keySet();

	for (ChatMessage message : keys) {
		try {

			if (!message.isEditable())
				messages.remove(message);

		} catch (SkypeException e) {
			new WarningPopup(e.getMessage());
		}
	}
}
 
开发者ID:Cuniq,项目名称:SkypeBot,代码行数:18,代码来源:HourlyNonEditableMessageCleaner.java

示例8: Consumer

import com.skype.ChatMessage; //导入依赖的package包/类
public Consumer(LinkedList<Pair<ChatMessage, Long>> buffer, ConcurrentHashMap<String, UserInformation> users,
				ConcurrentHashMap<ChatMessage, String> msg) {
	setName("Consumer");
	this.buffer = buffer;
	this.messages = msg;

	commandHandler = new CommandHandler(users);
	normalHandler = new NormalChatHandler(users);
}
 
开发者ID:Cuniq,项目名称:SkypeBot,代码行数:10,代码来源:Consumer.java

示例9: addMessageAndNotifyConsumer

import com.skype.ChatMessage; //导入依赖的package包/类
public void addMessageAndNotifyConsumer(ChatMessage msg) {
	Pair<ChatMessage, Long> pair = new Pair<ChatMessage, Long>(msg, System.currentTimeMillis());
	buffer.add(pair);
	synchronized (buffer) {
		buffer.notify();
	}
}
 
开发者ID:Cuniq,项目名称:SkypeBot,代码行数:8,代码来源:Producer.java

示例10: createCommandData

import com.skype.ChatMessage; //导入依赖的package包/类
private CommandData createCommandData(ChatMessage commandMessage,
	String[] splittedCommand) throws SkypeException {

	final Chat commandChat = commandMessage.getChat();

	return new CommandData(commandChat, commandMessage.getSender(), users,
		botAdmins, copyArrayWithoutCommand(splittedCommand));
}
 
开发者ID:Cuniq,项目名称:SkypeBot,代码行数:9,代码来源:CommandHandler.java

示例11: canHandleWarning

import com.skype.ChatMessage; //导入依赖的package包/类
private boolean canHandleWarning(ChatMessage message) throws SkypeException {
	if (message.getChat().getAllMembers().length <= 2) //Spam handling only for groups
		return false;
	if (!Config.EnableSelfWarnings && message.getId().equals(BotUserInfo.getBotUserID()))
		return false;
	return true;
}
 
开发者ID:Cuniq,项目名称:SkypeBot,代码行数:8,代码来源:NormalChatHandler.java

示例12: MessageEditHandler

import com.skype.ChatMessage; //导入依赖的package包/类
/**
 * Instantiates a new message edit handler.
 *
 * @param messages
 *            the messages to keep track of.
 */
public MessageEditHandler(ConcurrentHashMap<ChatMessage, String> messages) {
	this.messages = messages;

	if (editOutputMethod == Config.EDIT_OUTPUT_TO_FILE) {
		writer = openLogFile();
	} else { //No file needed
		writer = null;
	}
}
 
开发者ID:Cuniq,项目名称:SkypeBot,代码行数:16,代码来源:MessageEditHandler.java

示例13: handle

import com.skype.ChatMessage; //导入依赖的package包/类
/**
 * This method will send the edited message to the right place based on user's
 * option in config. If the user has disables self edits then it will return.
 * 
 * @throws SkypeException
 */
private void handle(ChatMessage msg) throws SkypeException {
	if (!Config.EnableSelfEdits && msg.getId().equals(BotUserInfo.getBotUserID()))
		return;

	if (editOutputMethod == Config.EDIT_OUTPUT_SAME_CHAT) {
		msg.getChat().send("Original from " + msg.getSenderDisplayName() + ": " + messages.get(msg));
	} else if (editOutputMethod == Config.EDIT_OUTPUT_TO_FILE) {
		writeToFile(writer, "Original from " + msg.getSenderDisplayName() + ": " + messages.get(msg) + "\r\n");
		flushWriter();
	} else { //Config.EDIT_OUTPUT_PRIVATE_CHAT
		msg.getSender().send("Original from " + msg.getSenderDisplayName() + ": " + messages.get(msg));
	}
}
 
开发者ID:Cuniq,项目名称:SkypeBot,代码行数:20,代码来源:MessageEditHandler.java

示例14: chatMessageEdited

import com.skype.ChatMessage; //导入依赖的package包/类
/**
 * If a message is edited then this method will be invoked. If the edit was made
 * from this group then it will call its {@link #editHandler handler} to handle
 * the edit.
 * 
 * @see com.skype.ChatMessageEditListener#chatMessageEdited(com.skype.ChatMessage,
 *      java.util.Date, com.skype.User)
 */
@Override
public void chatMessageEdited(ChatMessage editedMessage, Date eventDate, User who) {
	try {

		if (!editedMessage.getChat().equals(groupListeningTo))
			return;

		editHandler.handleEdit(editedMessage);

	} catch (SkypeException e) {
		System.out.println(e.getMessage());
		//If users chose method 2 then the self edits will throw an error, that why we ignore them.
	}
}
 
开发者ID:Cuniq,项目名称:SkypeBot,代码行数:23,代码来源:GroupChatEditListener.java

示例15: GroupChatListener

import com.skype.ChatMessage; //导入依赖的package包/类
/**
 * Instantiates a new group listener. Registers the handlers and creates the
 * information classes for the users of chat.
 *
 * @param groupChat
 *            The group chat for which we added the listener
 */
public GroupChatListener( Chat groupChat ){
	group = groupChat;

	initiateUserInformations();
	memberManager = new GroupChatMemberManager(users);

	list = new LinkedList<Pair<ChatMessage, Long>>();
	initiateProducerConsumerThreads();

	hourlyMessageClean.startTimer();
}
 
开发者ID:Cuniq,项目名称:SkypeBot,代码行数:19,代码来源:GroupChatListener.java


注:本文中的com.skype.ChatMessage类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。