This page deals with the functions, constants and classes EiskaltDC++ exports into QtScript (i.e. how it bridges its C++ world with the QtScript world in the ScriptEngine, and not with QtScript in general). See Working With QtScript for an introduction, and QtScript Example Scripts for some examples. Exported Functions- Eval (script_code) - Executes code script_code
- Import(<extension>) - Import classes from given extension into script namespace. Allowed extensions:
- qt.core
- qt.gui
- qt.network
- qt.xml
- qt.dbus
- Include (script_file) - Executes another script file in this script
- QScriptValue getMagnets(file1, file2, file3, ...) - Returns string array of magnets for file1, file2, file3. Files must be currently shared by the user.
- QScriptValue shellExec(program_name, arg1, arg2, arg3, ...) - Executes program <program_name> with given arguments arg1, arg2, arg3, ... This returns immediately with a useless return value. For a more powerful way of running commands, look at the ShellCommandRunner class.
Exported Constants- SCRIPTS_PATH - Global script installation path
- SCRIPT_PATH - Directory that contains the currently-executing script file (note that this errors if you use this from the Script Console)
Exported ClassesAntiSpam- bool isInBlack(const QString&) const
- bool isInWhite(const QString&) const
- bool isInGray (const QString&) const
- bool isInAny (const QString&) const
- bool isInSandBox(const QString&) const
- Note: If isInSandBox("some_nick") is true, then AntiSpam is checking the user authority at this time. TODO: What exactly does this mean?
- void addToBlack(const QList<QString> &nicks)
- void addToWhite(const QList<QString> &nicks)
- void addToGray(const QList<QString> &nicks)
- void remFromBlack(const QList<QString> &nicks)
- void remFromWhite(const QList<QString> &nicks)
- void remFromGray(const QList<QString> &nicks)
- void clearBlack()
- void clearGray()
- void clearWhite()
- void clearAll()
ClientManagerScript- quint64 getAvailable() - Returns total size of share on all hubs
- QStringList getConnectedHubs()
- QString getConnection(const QString &cid) - online/offline TODO: Confirm this
- QStringList getHubs(const QString &cid) - Returns all hub URLs that the user with CID cid is connected to
- QStringList getHubNames(const QString &cid) - Returns all hub names that the user with CID cid is connected to
- QString getMyCID() - Returns your globally unique client ID (TODO: Actually global?), for example 'I75AD5TYZ5IYRQU7GLA645FHXT6ADD3UIYGXJQ'
- QStringList getNicks(const QString &cid) - Returns all nicks that the user with CID cid has currently TODO: Actually currently?
- quint64 getUserCount()
- bool isConnected(const QString &url)
- bool isActive() - true if a connection has been made with at least one hub TODO: Confirm
- void sendPM(const QString &cid, const QString &hubUrl, const QString &msg) - Send PM on the relevant hub to the user specified by the CID
Signals- void connected(const QString &url)
- void disconnected(const QString &url)
- void updated(const QString &url)
DownloadQueue- QStringList getSources() - Returns a string list of targets in the format: file::nick1(CID) nick2(CID) nick3(CID) ...
- void removeSource(const QString &cid, const QString &target) - Removes user from the specified target
- void removeTarget(const QString &target) - Removes target from the queue
Signals- void added (const QString &target)
- void moved (const QString &old_target, const QString &new_target)
- void removed(const QString &target)
FavoriteHubsWork in progress.
FavoriteUsers- bool addUserToFav(const QString &cid)
- bool remUserFromFav(const QString &cid)
- QStringList getUsers() const - Returns string list of favourite users in the format: NICK;CID;HOST
HashManagerScript- QString getTTH(const QString &FileName, quint64 size) - Returns TTH of the file aFileName of the specified size - file must be shared
- QString getTTH(const QString &FileName) - Returns TTH of the file aFileName - file must be shared
- void stopHashing(const QString &baseDir) - Stop hashing of the directory baseDir
- void rebuild() - Rebuild HashIndex
- void startup() - Starts HashManager
- void shutdown() - Stops HashManager
- bool pauseHashing()
- void resumeHashing()
- bool isHashingPaused()
Signals- void done(const QString &file, const QString &tth) - Emitted when hashing of file file with TTH tth is finished
HubFrameThe HubFrame class is central to Eiskalt scripting, and represents the hub object. - HubFrame(const QString &hub_url, const QString &hub_encoding) - Constructor. Creates a new hub frame for url <hub_url> with encoding <hub_encoding>
- void addStatus(QString)
- void clearChat()
- void disableChat()
- void disablePrivateMessages(bool disable) - Pass disable as true to unhook the internal slot Eiskalt uses to subscribe to private message signals, thus disabling its processing of them. This is intended for a scripter to then hook his own function to the corePrivateMsg signal and implement any message processing logic he/she wants (i.e. run a bot that receives PM'd commands at the same time as the normal user receives/sends normal messages). To reenable normal PM processing, call this function passing disable as false.
- QString getHubUrl()
- QString getHubName()
- bool isOP (const QString &nick) - Returns boolean indicating whether the passed nick is an OP on the hub or not
- void sendMsg(const QString &message) - Sends message to hubchat
Signals- void coreMessage (const VarMap&) - Emitted when a user posts in hubchat. VarMap is a list of strings, currently the following useful information is available:
- VarMap["MSG"]: Message containing the highlight
- VarMap["NICK"]: Nick of highlighter
- VarMap["TIME"]: Time the message was received. Formatting is according to your chat (extended) timestamp configuration
- void corePrivateMsg (const !VarMap&) - Emitted when you send or receive a PM. VarMap is a list of strings, currently the following useful information is available:
- VarMap["CID"]: The client ID of the other side of the PM (even when the event signifies an outgoing PM)
- VarMap["ECHO"]: Indicates whether the PM is outgoing (true) or incoming (false). Normally you would only be interested in incoming PMs (i.e. another user has PM'd you)
- VarMap["MSG"]: Message containing the highlight
- VarMap["NICK"]: Nick of highlighter
- VarMap["TIME"]: Time the message was received. Formatting is according to your chat (extended) timestamp configuration
- void highlighted (const !VarMap&) - Emitted when someone highlights your nick or uses a custom highlight string in hubchat. VarMap is a list of strings, currently the following useful information is available:
- VarMap["MSG"]: Message containing the highlight
- VarMap["NICK"]: Nick of highlighter
- VarMap["TIME"]: Time the message was received. Formatting is according to your chat (extended) timestamp configuration
- VarMap["TRIGGER"]: The actual string causing the highlight (Eiskalt can highlight on custom strings, including your nick)
HubManager- QObject* getHubObject() - Returns the active hub's HubFrame or NULL if there is no active hub currently.
- QList<HubFrame*> getHubs() const - Returns a list of HubFrames associated with all registered hubs TODO: Connected?
- HubFrame* getHub(const QString &url)
Signals- void hubRegistered(QObject*) - Emitted when a hub window is opened, exposes the HubFrame object
- void hubUnregistered(QObject*) - Emitted when a hub window is closed, exposes the HubFrame object
- void newMessage(HubFrame *frame, const QString &hubUrl, const QString &cid, const QString &nick, const QString &msg) TODO: Does this actually exist??
LogManagerScriptSignals- void message(const QString &tstamp, const QString &msg)
MainWindowMain window handle. TODO: Precise difference from MainWindowScript? Is this actually a 'constant' or really a class? - void addActionOnToolBar(QAction* action)
- void remActionFromToolbar(QAction* action)
- void addArenaWidget(ArenaWidget*) - Allows widget to be mapped on arena
- void remArenaWidget(ArenaWidget*) - Disallows widget to be mapped on arena TODO: Disallows? Dont you mean remove?
- void mapWidgetOnArena(ArenaWidget*) - Show widget on arena
- void remWidgetFromArena(ArenaWidget*) - Remove widget from arena
- void addArenaWidgetOnToolbar(ArenaWidget*, bool keepFocus = false) - Show tab on tabbar for widget
- void remArenaWidgetFromToolbar(ArenaWidget*) - Remove tab from tabbar for widget
MainWindowScript- bool addToolButton(const QString &name, const QString &title, const QIcon &icon) - Add button to the MainWindow toolbar. Button will be registered as MainWindow.ToolBar.name
- bool remToolButton(const QString &name) - Removes button from toolbar
- bool addMenu(QMenu *menu) - Add menu menu to menubar
- bool remMenu(QMenu *menu) - Removes menu menu from menubar
Notification- void switchModule(int id) - Change notify module to module with ID <id>. 0 - QtModule, 1 - DBusModule.
- void showMessage(int type, const QString &title, const QString &message) - Shows message <message> with title <title>.
- Note: variable <type> is predefined as NOTIFY_ANY
ScriptWidgetScriptWidget extends ArenaWidget class, so it can be used for creating custom user widgets (see MainWindow class for details) - QString title()
- QString shortTitle()
- QWidget* widget()
- QMenu* menu()
SearchFrame- void fastSearch(const QString &target, bool isTTH)
- void searchAlternates(const QString &TTH)
- void searchFile(const QString &file_name)
ShellCommandRunner- ShellCommandRunner(program_name, arg1, arg2, arg3, ...) - Constructor. Prepares object to execute program <program_name> with given arguments arg1, arg2, arg3, ...
- void cancel() - Cancel the command execution
- int exitCode() - Exit code resulting from successful/unsuccessful command run - allows you to differentiate failures. For access to this property, include the instance of ShellCommandRunner that you are using in the function you connect to the finished signal - see closure example in Working With QtScript, Connecting To Signals
- void run() - Execute the command with given arguments, as specified in the constructor
Signals- void finished(bool ok, QString output) - Emits when command execution has finished. When ok returns as true the command has completed successfully, otherwise the command has failed. On success, output returns the command's stdout, on failure the command's stderr.
|
А как использовать более одного (main.js) скрипта?
>А как использовать более одного (main.js) скрипта? Include (script_file) - executes another script file in this script
Сори за слепоту...
А когда-нибудь планируется возможность получать содержимое чата, а не только отправлять его?
> А когда-нибудь планируется возможность получать содержимое чата, а не только отправлять его?
Вы имеете в виду получение каждого нового сообщения или весь текст чата? Первое думаю можно сделать сигналом вида HubFrame?.newMessage(hubUrl, CID, tstamp, nick, msg)
Конечно первое :)
Эх, еще бы до кучи иметь возможность сохранять какие-нибудь данные/настройки...
Vovochka, void newMessage(HubFrame? frame, const QString &hubUrl, const QString &cid, const QString &nick, const QString &msg) - сигнал передающий вполне достаточную информацию о сообщении (не ПМ).
Думаю настройки для скриптов можно прикрутить следующим образом - добавить в окружения скриптов переменную которая хранит путь до файлов настроек клиента, вам останется только использовать QFile для собсвенного файла настроек.
А чем не проще просто дать переменную settings для скрипта, которая бы автоматически сохранялась после изменений? Уж в самом страшном случае сделать какой-нибудь options_save({key:'val'}) и option_get('key')
Теперь можно просто использовать класс QSettings
ScriptEngine?> Starting /usr/share/eiskaltdcpp/scripts/test/main.js ... ScriptEngine?> Warning! qt.core not found!
Qt актуальной версии установлен.
pacman -S qtscriptgenerator Установка qtscriptgenerator помогла.
I want to make script that would resolve IP of chat message senders for further logging. By deafult in log-files saving only own IP and IP those users which I was connected directly (down- or uploading some files). I think is look like this:
Import("qt.core"); Import("qt.gui"); var a=new Array(); //array for storing CIDs that was used for resolving IP var b=new Boolean(0); //switcher for allow resolving var e=new HubManager(); //class instance e["newMessage(frame,hubUrl,cid,nick,msg)"].connect(newMessageReceived); //after receiving new chat message - call (connect) event (signal) handler function newMessageReceived(){ for(c=0;c<a.length;c++){ //cycle for checkin each CID in the array if(cid!=a[c]){ //if CID was not used early for resolving b=1; //allow resoving }else{ //if CID already was used c=a.length; //stop cycle } } if(b==1){ *resolveIP(cid); //resolve message sender's IP by CID* a[a.length+1]=cid; //remember new CID } }After resolving user IPs I believe eiskalt will remember them and log to the log-files through %userI4. Main question is HOW to realize method resolveIP(cid) - may be init getting filelist or other more silently way?
Подскажите инструменты для отладки скриптов, в линуксе
Run client and enable script in ScriptManager? - где там такое??