diff --git a/guiapp/CMakeLists.txt b/guiapp/CMakeLists.txt index 2a3dde3..99fdd9f 100644 --- a/guiapp/CMakeLists.txt +++ b/guiapp/CMakeLists.txt @@ -9,8 +9,10 @@ set (guiapp_MOC_HEADERS QT4_WRAP_CPP (guiapp_MOC_SOURCES ${guiapp_MOC_HEADERS}) QT4_WRAP_UI (guiapp_ui chatwindow.ui) include_directories(${ircclient_SOURCE_DIR}/src) +include_directories(${ircclient_SOURCE_DIR}/mirc/includes) include_directories(${CMAKE_CURRENT_BINARY_DIR}) link_directories(${ircclient_BINARY_DIR}/src) +link_directories(${ircclient_BINARY_DIR}/mirc/src) add_executable(guiapp ${guiapp_SOURCES} ${guiapp_MOC_SOURCES} ${guiapp_ui}) -target_link_libraries (guiapp ircclient ${LIBS}) \ No newline at end of file +target_link_libraries (guiapp ircclient mirc ${LIBS}) \ No newline at end of file diff --git a/guiapp/messagehandler.cpp b/guiapp/messagehandler.cpp index 93bbfa4..70c4225 100644 --- a/guiapp/messagehandler.cpp +++ b/guiapp/messagehandler.cpp @@ -2,6 +2,8 @@ #include MessageHandler::MessageHandler( IRCClient *irc, QWidget *parent ) : QTabWidget( parent ) { + this->scriptManager = new MIRCScriptManager(); + connect(this->scriptManager, SIGNAL( unknown_alias( QString, QStringList ) ), this, SLOT( call_alias( QString, QStringList ) ) ); this->irc = irc; connect( irc, SIGNAL( messageRcvd( QString, QString, QString, QStringList, QString ) ), this, SLOT( messageRcvd( QString, QString, QString, QStringList, QString ) ) ); connect( irc, SIGNAL( registered() ), this, SLOT( autoRun() ) ); @@ -94,82 +96,10 @@ void MessageHandler::messageRcvdDCC( QString nickName, QString text ) { void MessageHandler::processCmd( QString cmdText ) { qDebug() << cmdText; - QStringList args = cmdText.split( ' ' ); - QStringList newargs; - - QString cmd = args.takeFirst().toLower(); - for( int i = 0; i < args.count(); i++ ) { - if( args[i].startsWith( '$' ) ) { - args[i] = parseVar( args[i] ); - //QString var = args[i].right( args[i].length() - 1 ); - //if( variables.contains( var ) ) { args[i] = variables[var].toString(); } - } - } - if( cmd == "server" || cmd == "connect" ) { - if( args.count() < 1 ) { return; } - irc->quit( tr( "Changing servers" ) ); - QString host = args.takeFirst(); - int port = 0; - if( host.contains( ':' ) ) { - QStringList splitHost = host.split( ':' ); - host = splitHost.takeFirst(); - port = splitHost.join( "" ).toInt(); - } - port = port > 0 ? port : 6667; - QString nickName = args.count() > 0 ? args.takeFirst() : irc->getNickName(); - QString userName = args.count() > 0 ? args.takeFirst() : irc->getUserName(); - QString realName = args.count() > 0 ? args.join( " " ) : irc->getRealName(); - irc->connectAndRegister( - host, // Host - port > 0 ? port : 6667, // Port - nickName, - userName, - realName ); - } else if( cmd == "nick" ) { - if( args.count() < 1 ) { return; } - irc->nick( args[0] ); - } else if( cmd == "msg" || cmd == "privmsg" ) { - if( args.count() < 2 ) { return; } - newargs += args.takeFirst(); - if( newargs[0].startsWith( "=") ) { - // DCC Chat - ((DCCChatServer*)DCCServers[DCCNicks[newargs[0].right( newargs[0].length() - 1 )]])->sendText( args.join( " " ) ); - } else { - irc->msg( newargs[0], args.join( " " ) ); - } - // Update existing chat windows with the sent message - QString window; - QStringList windows = newargs[0].split( "," ); - foreach( window, windows ) { - if( !window.startsWith( "=" ) && this->windows.keys().contains( window ) ) { this->windows[window]->message( irc->getNickName(), args.join( " " ) ); } - } - } else if( cmd == "notice" ) { - if( args.count() < 2 ) { return; } - QString dest = args.takeFirst(); - irc->notice( dest, args.join( " " ) ); - } else if( cmd == "ctcp" ) { - if( args.count() < 2 ) { return; } - newargs += args.takeFirst(); - irc->ctcp( newargs[0], args.join( " " ) ); - } else if( cmd == "join" ) { - irc->join( args.join( "," ) ); - } else if( cmd == "set" ) { - QString var = args.takeFirst(); - variables[var] = args.join( " " ); - } else if( cmd == "dcc" ) { - if( args.count() < 2 ) { return; } - QString type = args.takeFirst(); - QString nick = args.takeFirst(); - if( type == "chat" ) { - startDCC( nick ); - } else if( type == "send" ) { - if( args.count() == 0 ) { return; } - startDCC( nick, args.join( " " ) ); - } - } else if( cmd == "quit" || cmd == "q" ) { - if( args.count() > 0 ) { irc->quit( args.join( " " ) ); } - else { irc->quit(); } - } + + MIRCScript *script = new MIRCScript(this->scriptManager); + script->parse(cmdText); + script->run(); } void MessageHandler::autoRun() { //irc->join( "#pinet" ); @@ -213,3 +143,80 @@ void MessageHandler::connectedDCCChat( QString nickName ) { void MessageHandler::sentRAW( QString text ) { qDebug() << ">>> " << text.trimmed(); } void MessageHandler::rcvdRAW( QString text ) { qDebug() << "<<< " << text.trimmed(); } + +bool MessageHandler::call_alias(QString alias, QStringList args) { + QStringList newargs; + if( alias == "server" || alias == "connect" ) { + if( args.count() < 1 ) { return true; } + irc->quit( tr( "Changing servers" ) ); + QString host = args.takeFirst(); + int port = 0; + if( host.contains( ':' ) ) { + QStringList splitHost = host.split( ':' ); + host = splitHost.takeFirst(); + port = splitHost.join( "" ).toInt(); + } + port = port > 0 ? port : 6667; + QString nickName = args.count() > 0 ? args.takeFirst() : irc->getNickName(); + QString userName = args.count() > 0 ? args.takeFirst() : irc->getUserName(); + QString realName = args.count() > 0 ? args.join( " " ) : irc->getRealName(); + irc->connectAndRegister( + host, // Host + port > 0 ? port : 6667, // Port + nickName, + userName, + realName ); + } else if( alias == "nick" ) { + if( args.count() < 1 ) { return true; } + irc->nick( args[0] ); + } else if( alias == "msg" || alias == "privmsg" ) { + if( args.count() < 2 ) { return true; } + newargs += args.takeFirst(); + if( newargs[0].startsWith( "=") ) { + // DCC Chat + ((DCCChatServer*)DCCServers[DCCNicks[newargs[0].right( newargs[0].length() - 1 )]])->sendText( args.join( " " ) ); + } else { + irc->msg( newargs[0], args.join( " " ) ); + } + // Update existing chat windows with the sent message + QString window; + QStringList windows = newargs[0].split( "," ); + foreach( window, windows ) { + if( !window.startsWith( "=" ) && this->windows.keys().contains( window ) ) { this->windows[window]->message( irc->getNickName(), args.join( " " ) ); } + } + } else if( alias == "notice" ) { + if( args.count() < 2 ) { return true; } + QString dest = args.takeFirst(); + irc->notice( dest, args.join( " " ) ); + } else if( alias == "ctcp" ) { + if( args.count() < 2 ) { return true; } + newargs += args.takeFirst(); + irc->ctcp( newargs[0], args.join( " " ) ); + } else if( alias == "join" ) { + irc->join( args.join( "," ) ); + } else if( alias == "set" ) { + QString var = args.takeFirst(); + variables[var] = args.join( " " ); + } else if( alias == "dcc" ) { + if( args.count() < 2 ) { return true; } + QString type = args.takeFirst(); + QString nick = args.takeFirst(); + if( type == "chat" ) { + startDCC( nick ); + } else if( type == "send" ) { + if( args.count() == 0 ) { return true; } + startDCC( nick, args.join( " " ) ); + } + } else if( alias == "quit" || alias == "q" ) { + if( args.count() > 0 ) { irc->quit( args.join( " " ) ); } + else { irc->quit(); } + } else { + return false; + } + return true; +} +void MessageHandler::alias_join(QStringList args) { + irc->join( args.join( "," ) ); +} +void MessageHandler::alias_msg(QStringList args) { +} diff --git a/guiapp/messagehandler.h b/guiapp/messagehandler.h index 30650dc..1561ac9 100644 --- a/guiapp/messagehandler.h +++ b/guiapp/messagehandler.h @@ -2,8 +2,9 @@ #include #include #include -#include "../src/ircclient.h" -#include "../src/dccserver.h" +#include +#include +#include #include "chatwindow.h" class MessageHandler : public QTabWidget { @@ -17,12 +18,17 @@ private: bool DCCSendAhead; QHash< int, DCCServer* > DCCServers; QHash< QString, int > DCCNicks; + MIRCScriptManager *scriptManager; void _addWindow( QString name, QString defaultCmd = "", bool focusOnOpen = false ); QString parseVar( QString text ); public: MessageHandler( IRCClient *irc, QWidget *parent = 0 ); + + void alias_join(QStringList args); + void alias_msg(QStringList args); public slots: + bool call_alias(QString alias, QStringList args); void messageRcvd( QString type, QString src, QString dest, QStringList values, QString text ); void messageSentDCC( QString nickName, QString text ); void messageRcvdDCC( QString nickName, QString text ); diff --git a/mirc/CMakeLists.txt b/mirc/CMakeLists.txt index fde6ed1..32801ea 100644 --- a/mirc/CMakeLists.txt +++ b/mirc/CMakeLists.txt @@ -14,4 +14,4 @@ add_library (mirc STATIC ${mirc_SOURCES} ${mirc_MOC_SOURCES}) link_directories(${CMAKE_CURRENT_BINARY_DIR}) add_executable(mirctest src/main.cpp) -target_link_libraries (mirctest mirc ${LIBS}) \ No newline at end of file +target_link_libraries (mirctest mirc ${LIBS}) diff --git a/mirc/includes/mirc.h b/mirc/includes/mirc.h index 0e70cf9..408915e 100644 --- a/mirc/includes/mirc.h +++ b/mirc/includes/mirc.h @@ -34,6 +34,8 @@ public: QString variable(QString variable); void variable(QString variable, QString value); QMap variables(); +signals: + void unknown_alias(QString alias, QStringList arguments); }; #endif diff --git a/mirc/src/mirc.cpp b/mirc/src/mirc.cpp index 659155a..8e792dd 100644 --- a/mirc/src/mirc.cpp +++ b/mirc/src/mirc.cpp @@ -22,9 +22,11 @@ QMap MIRCScriptManager::variables() { void MIRCScriptManager::call_alias(QString alias, QStringList arguments) { // This is where we flip through and attempt to call an alias - //mirc_script_engine::alias_echo(QStringList("[MANAGER]") << alias << arguments); if (internal_aliases.find(alias) != internal_aliases.end()) { internal_aliases[alias](arguments); + } else { + //TODO: check known scripted aliases!!! + emit unknown_alias(alias, arguments); } }