mirror of
https://github.com/correl/mercenary.git
synced 2024-11-23 19:19:51 +00:00
Tied the mIRC script engine to the gui app's command parser
git-svn-id: file:///srv/svn/ircclient/trunk@6 a9804ffe-773b-11dd-bd7c-89c3ef1d2733
This commit is contained in:
parent
1cf438da9b
commit
34b445fe87
6 changed files with 100 additions and 81 deletions
|
@ -9,8 +9,10 @@ set (guiapp_MOC_HEADERS
|
||||||
QT4_WRAP_CPP (guiapp_MOC_SOURCES ${guiapp_MOC_HEADERS})
|
QT4_WRAP_CPP (guiapp_MOC_SOURCES ${guiapp_MOC_HEADERS})
|
||||||
QT4_WRAP_UI (guiapp_ui chatwindow.ui)
|
QT4_WRAP_UI (guiapp_ui chatwindow.ui)
|
||||||
include_directories(${ircclient_SOURCE_DIR}/src)
|
include_directories(${ircclient_SOURCE_DIR}/src)
|
||||||
|
include_directories(${ircclient_SOURCE_DIR}/mirc/includes)
|
||||||
include_directories(${CMAKE_CURRENT_BINARY_DIR})
|
include_directories(${CMAKE_CURRENT_BINARY_DIR})
|
||||||
link_directories(${ircclient_BINARY_DIR}/src)
|
link_directories(${ircclient_BINARY_DIR}/src)
|
||||||
|
link_directories(${ircclient_BINARY_DIR}/mirc/src)
|
||||||
|
|
||||||
add_executable(guiapp ${guiapp_SOURCES} ${guiapp_MOC_SOURCES} ${guiapp_ui})
|
add_executable(guiapp ${guiapp_SOURCES} ${guiapp_MOC_SOURCES} ${guiapp_ui})
|
||||||
target_link_libraries (guiapp ircclient ${LIBS})
|
target_link_libraries (guiapp ircclient mirc ${LIBS})
|
|
@ -2,6 +2,8 @@
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
|
|
||||||
MessageHandler::MessageHandler( IRCClient *irc, QWidget *parent ) : QTabWidget( parent ) {
|
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;
|
this->irc = irc;
|
||||||
connect( irc, SIGNAL( messageRcvd( QString, QString, QString, QStringList, QString ) ), this, SLOT( messageRcvd( QString, QString, QString, QStringList, QString ) ) );
|
connect( irc, SIGNAL( messageRcvd( QString, QString, QString, QStringList, QString ) ), this, SLOT( messageRcvd( QString, QString, QString, QStringList, QString ) ) );
|
||||||
connect( irc, SIGNAL( registered() ), this, SLOT( autoRun() ) );
|
connect( irc, SIGNAL( registered() ), this, SLOT( autoRun() ) );
|
||||||
|
@ -94,82 +96,10 @@ void MessageHandler::messageRcvdDCC( QString nickName, QString text ) {
|
||||||
|
|
||||||
void MessageHandler::processCmd( QString cmdText ) {
|
void MessageHandler::processCmd( QString cmdText ) {
|
||||||
qDebug() << cmdText;
|
qDebug() << cmdText;
|
||||||
QStringList args = cmdText.split( ' ' );
|
|
||||||
QStringList newargs;
|
|
||||||
|
|
||||||
QString cmd = args.takeFirst().toLower();
|
MIRCScript *script = new MIRCScript(this->scriptManager);
|
||||||
for( int i = 0; i < args.count(); i++ ) {
|
script->parse(cmdText);
|
||||||
if( args[i].startsWith( '$' ) ) {
|
script->run();
|
||||||
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(); }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
void MessageHandler::autoRun() {
|
void MessageHandler::autoRun() {
|
||||||
//irc->join( "#pinet" );
|
//irc->join( "#pinet" );
|
||||||
|
@ -213,3 +143,80 @@ void MessageHandler::connectedDCCChat( QString nickName ) {
|
||||||
|
|
||||||
void MessageHandler::sentRAW( QString text ) { qDebug() << ">>> " << text.trimmed(); }
|
void MessageHandler::sentRAW( QString text ) { qDebug() << ">>> " << text.trimmed(); }
|
||||||
void MessageHandler::rcvdRAW( 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) {
|
||||||
|
}
|
||||||
|
|
|
@ -2,8 +2,9 @@
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
#include <QPointer>
|
#include <QPointer>
|
||||||
#include "../src/ircclient.h"
|
#include <ircclient.h>
|
||||||
#include "../src/dccserver.h"
|
#include <dccserver.h>
|
||||||
|
#include <mirc.h>
|
||||||
#include "chatwindow.h"
|
#include "chatwindow.h"
|
||||||
|
|
||||||
class MessageHandler : public QTabWidget {
|
class MessageHandler : public QTabWidget {
|
||||||
|
@ -17,12 +18,17 @@ private:
|
||||||
bool DCCSendAhead;
|
bool DCCSendAhead;
|
||||||
QHash< int, DCCServer* > DCCServers;
|
QHash< int, DCCServer* > DCCServers;
|
||||||
QHash< QString, int > DCCNicks;
|
QHash< QString, int > DCCNicks;
|
||||||
|
MIRCScriptManager *scriptManager;
|
||||||
|
|
||||||
void _addWindow( QString name, QString defaultCmd = "", bool focusOnOpen = false );
|
void _addWindow( QString name, QString defaultCmd = "", bool focusOnOpen = false );
|
||||||
QString parseVar( QString text );
|
QString parseVar( QString text );
|
||||||
public:
|
public:
|
||||||
MessageHandler( IRCClient *irc, QWidget *parent = 0 );
|
MessageHandler( IRCClient *irc, QWidget *parent = 0 );
|
||||||
|
|
||||||
|
void alias_join(QStringList args);
|
||||||
|
void alias_msg(QStringList args);
|
||||||
public slots:
|
public slots:
|
||||||
|
bool call_alias(QString alias, QStringList args);
|
||||||
void messageRcvd( QString type, QString src, QString dest, QStringList values, QString text );
|
void messageRcvd( QString type, QString src, QString dest, QStringList values, QString text );
|
||||||
void messageSentDCC( QString nickName, QString text );
|
void messageSentDCC( QString nickName, QString text );
|
||||||
void messageRcvdDCC( QString nickName, QString text );
|
void messageRcvdDCC( QString nickName, QString text );
|
||||||
|
|
|
@ -34,6 +34,8 @@ public:
|
||||||
QString variable(QString variable);
|
QString variable(QString variable);
|
||||||
void variable(QString variable, QString value);
|
void variable(QString variable, QString value);
|
||||||
QMap<QString, QString> variables();
|
QMap<QString, QString> variables();
|
||||||
|
signals:
|
||||||
|
void unknown_alias(QString alias, QStringList arguments);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -22,9 +22,11 @@ QMap<QString, QString> MIRCScriptManager::variables() {
|
||||||
|
|
||||||
void MIRCScriptManager::call_alias(QString alias, QStringList arguments) {
|
void MIRCScriptManager::call_alias(QString alias, QStringList arguments) {
|
||||||
// This is where we flip through and attempt to call an alias
|
// 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()) {
|
if (internal_aliases.find(alias) != internal_aliases.end()) {
|
||||||
internal_aliases[alias](arguments);
|
internal_aliases[alias](arguments);
|
||||||
|
} else {
|
||||||
|
//TODO: check known scripted aliases!!!
|
||||||
|
emit unknown_alias(alias, arguments);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue