Implemented /me command.

fix-message-formatting
Danny van Heumen 11 years ago
parent 99fc21c915
commit fa89f86404

@ -857,9 +857,10 @@ public void command(final ChatRoomIrcImpl chatroom, final String message)
*/ */
public void command(final Contact contact, final String message) public void command(final Contact contact, final String message)
{ {
// WARNING: This command method should not be used. // OTR seems to be compatible with the command syntax (starts with '/')
LOGGER.warn("Not handling IM message as commands, because of danger" // and there were no other obvious problems so we decided to implement
+ "of corrupting plug-ins that hook into IM conversations."); // IRC command support for IM infrastructure too.
this.command(contact.getAddress(), message);
} }
/** /**
@ -870,27 +871,30 @@ public void command(final Contact contact, final String message)
*/ */
private void command(final String source, final String message) private void command(final String source, final String message)
{ {
final String target; final IRCApi irc = this.session.get();
final String command; final String msg = message.toLowerCase();
if (message.toLowerCase().startsWith("/msg ")) if (msg.startsWith("/msg "))
{ {
String part = message.substring(5); final String part = message.substring(5);
int endOfNick = part.indexOf(' '); int endOfNick = part.indexOf(' ');
if (endOfNick == -1) if (endOfNick == -1)
{ {
throw new IllegalArgumentException("Invalid private message " throw new IllegalArgumentException("Invalid private message "
+ "format. Message was not sent."); + "format. Message was not sent.");
} }
target = part.substring(0, endOfNick); final String target = part.substring(0, endOfNick);
command = part.substring(endOfNick + 1); final String command = part.substring(endOfNick + 1);
irc.message(target, command);
}
else if (msg.startsWith("/me "))
{
final String command = message.substring(4);
irc.act(source, command);
} }
else else
{ {
target = source; irc.message(source, message);
command = message;
} }
final IRCApi irc = this.session.get();
irc.message(target, command);
} }
/** /**

Loading…
Cancel
Save