From 0b4bd5e96923a36f31d03b17e6ef7a453a7f4acb Mon Sep 17 00:00:00 2001 From: rsuen Date: Sat, 9 Feb 2008 03:14:57 +0000 Subject: Resolve bug 216467 - [IRC] [KOSMOS] add support for CQs --- .../bot/kosmos/ChatRoomMessageHandler.java | 42 ++++++++++++++++++---- .../presence/bot/kosmos/CustomMessages.java | 1 + .../internal/presence/bot/kosmos/custom.properties | 3 ++ 3 files changed, 39 insertions(+), 7 deletions(-) (limited to 'applications') diff --git a/applications/kosmos/bundles/org.eclipse.ecf.presence.bot.kosmos/src/org/eclipse/ecf/internal/presence/bot/kosmos/ChatRoomMessageHandler.java b/applications/kosmos/bundles/org.eclipse.ecf.presence.bot.kosmos/src/org/eclipse/ecf/internal/presence/bot/kosmos/ChatRoomMessageHandler.java index 54605af67..c31dfc19a 100644 --- a/applications/kosmos/bundles/org.eclipse.ecf.presence.bot.kosmos/src/org/eclipse/ecf/internal/presence/bot/kosmos/ChatRoomMessageHandler.java +++ b/applications/kosmos/bundles/org.eclipse.ecf.presence.bot.kosmos/src/org/eclipse/ecf/internal/presence/bot/kosmos/ChatRoomMessageHandler.java @@ -66,7 +66,7 @@ public class ChatRoomMessageHandler implements IChatRoomMessageHandler { private static final String LICENSE = "###############################################################################" //$NON-NLS-1$ + NEWLINE - + "# Copyright (c) 2007 Remy Suen and others." //$NON-NLS-1$ + + "# Copyright (c) 2007, 2008 Remy Suen and others." //$NON-NLS-1$ + NEWLINE + "# All rights reserved. This program and the accompaning materials" //$NON-NLS-1$ + NEWLINE @@ -412,6 +412,15 @@ public class ChatRoomMessageHandler implements IChatRoomMessageHandler { sendMessage(roomID, (target != null ? target + ": " : "") + NLS.bind(CustomMessages .getString(CustomMessages.SearchPlugins), searchString)); } + + private void sendCQ(ID roomID, String target, String id, String comment) { + String suffix = id; + if (comment != null) { + suffix += "#c" + comment; + } + sendMessage(roomID, (target != null ? target + ": " : "") + NLS.bind(CustomMessages + .getString(CustomMessages.CQ), id, suffix)); + } private void writeToHTML(File file, String title, Properties properties) throws IOException { FileWriter out = new FileWriter(file); @@ -590,14 +599,12 @@ public class ChatRoomMessageHandler implements IChatRoomMessageHandler { String key = (String)keys.nextElement(); Pattern pattern = Pattern.compile(key); cmdMatcher = pattern.matcher(msg); - if (cmdMatcher.matches()) - { + if (cmdMatcher.matches()) { break; } } - if (cmdMatcher != null && cmdMatcher.matches()) - { + if (cmdMatcher != null && cmdMatcher.matches()) { if (cmdMatcher.group(1).equals("add ")) { //$NON-NLS-1$ if (operators.contains(fromID.getName())) { learn(roomID, cmdMatcher.group(2)); @@ -627,7 +634,7 @@ public class ChatRoomMessageHandler implements IChatRoomMessageHandler { int index = msg.indexOf('c'); if (index == -1) { try { - // check if what's before the 'c' is a valid number + // try to parse the string to see that we have a valid number Integer.parseInt(msg); sendBug(roomID, target, msg, null); } catch (NumberFormatException e) { @@ -635,7 +642,7 @@ public class ChatRoomMessageHandler implements IChatRoomMessageHandler { } } else { try { - // check if what's before the 'c' is a valid number + // try to parse the string to see that we have a valid number Integer.parseInt(msg.substring(0, index)); sendBug(roomID, target, msg.substring(0, index), msg .substring(index + 1)); @@ -643,6 +650,27 @@ public class ChatRoomMessageHandler implements IChatRoomMessageHandler { // ignored } } + } else if (cmdMatcher.group(1).equals("cq") || cmdMatcher.group(1).equals("cq ")) { //$NON-NLS-1$ //$NON-NLS-2$ + msg = cmdMatcher.group(2); + int index = msg.indexOf('c'); + if (index == -1) { + try { + // try to parse the string to see that we have a valid number + Integer.parseInt(msg); + sendCQ(roomID, target, msg, null); + } catch (NumberFormatException e) { + // ignored + } + } else { + try { + // try to parse the string to see that we have a valid number + Integer.parseInt(msg.substring(0, index)); + sendCQ(roomID, target, msg.substring(0, index), msg + .substring(index + 1)); + } catch (NumberFormatException e) { + // ignored + } + } } else if (cmdMatcher.group(1).equals("javadoc ") || cmdMatcher.group(1).equals("api ")) { //$NON-NLS-1$ //$NON-NLS-2$ sendJavaDoc(roomID, target, cmdMatcher.group(2)); } else if (cmdMatcher.group(1).equals("news ") || cmdMatcher.group(1).equals("newsgroup ")) { //$NON-NLS-1$ //$NON-NLS-2$ diff --git a/applications/kosmos/bundles/org.eclipse.ecf.presence.bot.kosmos/src/org/eclipse/ecf/internal/presence/bot/kosmos/CustomMessages.java b/applications/kosmos/bundles/org.eclipse.ecf.presence.bot.kosmos/src/org/eclipse/ecf/internal/presence/bot/kosmos/CustomMessages.java index 8167ad0bf..b0e29c71d 100644 --- a/applications/kosmos/bundles/org.eclipse.ecf.presence.bot.kosmos/src/org/eclipse/ecf/internal/presence/bot/kosmos/CustomMessages.java +++ b/applications/kosmos/bundles/org.eclipse.ecf.presence.bot.kosmos/src/org/eclipse/ecf/internal/presence/bot/kosmos/CustomMessages.java @@ -40,6 +40,7 @@ public class CustomMessages { static final String EclipseHelp = "EclipseHelp"; //$NON-NLS-1$ static final String MessageList = "MessageList"; //$NON-NLS-1$ static final String SearchPlugins = "SearchPlugins"; //$NON-NLS-1$ + static final String CQ = "CQ"; //$NON-NLS-1$ private static final String RESOURCE_BUNDLE = "org.eclipse.ecf.internal.presence.bot.kosmos.custom"; //$NON-NLS-1$ diff --git a/applications/kosmos/bundles/org.eclipse.ecf.presence.bot.kosmos/src/org/eclipse/ecf/internal/presence/bot/kosmos/custom.properties b/applications/kosmos/bundles/org.eclipse.ecf.presence.bot.kosmos/src/org/eclipse/ecf/internal/presence/bot/kosmos/custom.properties index 90f04cc30..7c9c97ee4 100644 --- a/applications/kosmos/bundles/org.eclipse.ecf.presence.bot.kosmos/src/org/eclipse/ecf/internal/presence/bot/kosmos/custom.properties +++ b/applications/kosmos/bundles/org.eclipse.ecf.presence.bot.kosmos/src/org/eclipse/ecf/internal/presence/bot/kosmos/custom.properties @@ -53,3 +53,6 @@ MessageList = Check out the list of available messages and commands I provide - SearchPlugins_Regex = (searchplugins )(.+) SearchPlugins = Try searching for plug-ins: http://www.eclipseplugincentral.com/modules.php?name=search&action=search&q={0} - http://www.eclipse-plugins.info/eclipse/search.jsp?query={0} +CQ_Regex = (cq|cq |)([0-9]+(c[0-9]+)?) +CQ = See CQ {0} - https://dev.eclipse.org/ipzilla/show_bug.cgi?id={1} + -- cgit v1.2.3