return;
QString cmd;
QString msg = msg_;
- if(!msg.startsWith('/')) {
+ // leading slashes indicate there's a command to call unless there is anothere one in the first section (like a path /proc/cpuinfo)
+ int secondSlashPos = msg.indexOf('/', 1);
+ int firstSpacePos = msg.indexOf(' ');
+ if(!msg.startsWith('/') || (secondSlashPos != -1 && (secondSlashPos < firstSpacePos || firstSpacePos == -1))) {
+ if(msg.startsWith("//"))
+ msg.remove(0, 1); // //asdf is transformed to /asdf
cmd = QString("SAY");
} else {
cmd = msg.section(' ', 0, 0).remove(0, 1).toUpper();
Q_UNUSED(bufferInfo)
QString awayMsg = msg;
+ IrcUser *me = network()->me();
+
// if there is no message supplied we have to check if we are already away or not
if(msg.isEmpty()) {
- IrcUser *me = network()->me();
if(me && !me->isAway())
awayMsg = networkConnection()->identity()->awayReason();
}
-
+ if(me)
+ me->setAwayMessage(awayMsg);
+
putCmd("AWAY", serverEncode(awayMsg));
}
emit putCmd("INVITE", serverEncode(params));
}
-void UserInputHandler::handleJ(const BufferInfo &bufferInfo, const QString &msg) {
- QString trimmed = msg.trimmed();
- if(trimmed.length() == 0) return;
- if(trimmed[0].isLetter()) trimmed.prepend("#");
- handleJoin(bufferInfo, trimmed);
-}
-
void UserInputHandler::handleJoin(const BufferInfo &bufferInfo, const QString &msg) {
Q_UNUSED(bufferInfo)
QStringList params = msg.trimmed().split(" ");
QStringList chans = params[0].split(",");
QStringList keys;
+ int i;
+ for(i = 0; i < chans.count(); i++) {
+ if (chans.at(i)[0].isLetterOrNumber())
+ chans[i].prepend(QChar('#'));
+ }
+ params[0] = chans.join(",");
if(params.count() > 1) keys = params[1].split(",");
emit putCmd("JOIN", serverEncode(params)); // FIXME handle messages longer than 512 bytes!
- int i = 0;
+ i = 0;
for(; i < keys.count(); i++) {
if(i >= chans.count()) break;
networkConnection()->addChannelKey(chans[i], keys[i]);
emit putCmd("PART", params);
}
+void UserInputHandler::handlePing(const BufferInfo &bufferInfo, const QString &msg) {
+ Q_UNUSED(bufferInfo)
+
+ QString param = msg;
+ if(param.isEmpty())
+ param = QTime::currentTime().toString("hh:mm:ss.zzz");
+
+ putCmd("PING", serverEncode(param));
+}
+
// TODO: implement queries
void UserInputHandler::handleQuery(const BufferInfo &bufferInfo, const QString &msg) {
Q_UNUSED(bufferInfo)
}
void UserInputHandler::defaultHandler(QString cmd, const BufferInfo &bufferInfo, const QString &msg) {
- Q_UNUSED(bufferInfo)
+ for(int i = 0; i < coreSession()->aliasManager().count(); i++) {
+ if(coreSession()->aliasManager()[i].name.toLower() == cmd.toLower()) {
+ expand(coreSession()->aliasManager()[i].expansion, bufferInfo, msg);
+ return;
+ }
+ }
emit displayMsg(Message::Error, BufferInfo::StatusBuffer, "", QString("Error: %1 %2").arg(cmd).arg(msg));
}
+void UserInputHandler::expand(const QString &alias, const BufferInfo &bufferInfo, const QString &msg) {
+ QStringList commands = alias.split(QRegExp("; ?"));
+ QStringList params = msg.split(' ');
+ for(int i = 0; i < commands.count(); i++) {
+ QString command = commands[i];
+ for(int j = params.count(); j > 0; j--) {
+ IrcUser *ircUser = network()->ircUser(params[j - 1]);
+ command = command.replace(QString("$%1:hostname").arg(j), ircUser ? ircUser->host() : QString("*"));
+ command = command.replace(QString("$%1").arg(j), params[j - 1]);
+ }
+ command = command.replace("$0", msg);
+ command = command.replace("$channelname", bufferInfo.bufferName());
+ command = command.replace("$currentnick", network()->myNick());
+ handleUserInput(bufferInfo, command);
+ }
+}
+
+