Project

General

Profile

Instruction about how to add custom script

Igor Khomenko
Added over 5 years ago

I'm trying to add custom script https://projects.tigase.org/projects/tigase-muc/repository/revisions/master/entry/src/main/groovy/muc/admin/room-remove.groovy

using command

bin/tclmt.sh -u ... -p ... -s ... add-script muc room-remove "Room Remove" groovy "scripts/Room-remove.groovy"

and got message:

Sep 6, 2013 4:07:19 PM tigase.xml.db.XMLDB setupNewDB

INFO: Create empty DB.

awaiting response...

Note

Script loaded successfuly.

But when i'm trying to run it - got warning No script with id room-remove

bin/tclmt.sh -u ... -p ... -s ... room-remove

Sep 6, 2013 4:10:34 PM tigase.xml.db.XMLDB setupNewDB

INFO: Create empty DB.

No script with id room-remove

Is there any info about what is the right way to add custom script?

UPD1:

Next i had tried with -save key and got error:

configuration not saved due to exception = /ubuntuuser/.tigase/tclmt.xml (No such file or directory)

java.io.FileNotFoundException: /ubuntuuser/.tigase/tclmt.xml (No such file or directory)

at java.io.FileOutputStream.open(Native Method)

at java.io.FileOutputStream.(FileOutputStream.java:209)

at java.io.FileOutputStream.(FileOutputStream.java:131)

at tigase.xml.db.XMLDB.write(XMLDB.java:510)

at tigase.xml.db.XMLDB.sync(XMLDB.java:503)

at tigase.tclmt.Config.setData(Config.java:126)

at tigase.tclmt.Config.sync(Config.java:88)

at tigase.tclmt.Tclmt.main(Tclmt.java:219)

awaiting response...

Note

Script loaded successfuly.

Okay, let's create /ubuntuuser/.tigase:

mkdir /ubuntuuser/.tigase

After that option -save works OK

Now i have my config file, i can print it

cat /ubuntuuser/.tigase/tclmt.xml

Nothing changed

UPD2:

Resolved, was wrong format of metadata, see example there https://projects.tigase.org/projects/tclmt/wiki/Scripting_introduction


Replies (9)

(1)

Added by Andrzej Wójcik IoT 1 CloudTigaseTeam over 5 years ago

Could you explain in which file/script format of metadata was wrong and how it was wrong? I would like to correct this error.

(1)

Added by Igor Khomenko over 5 years ago

There is still some misunderstanding for me - i tried to use this script https://projects.tigase.org/projects/tigase-muc/repository/revisions/master/entry/src/main/groovy/muc/admin/room-remove.groovy

I put it to /scripts folder inside tclmt

Command bin/tclmt.sh list showed me that it is available

Available commands:

...

room-remove Room remove

...

But looks like i can't use it via TCLMT because of environment.

Could you please guide me where can we use this script (room-remove.groovy)

(1)

Added by Andrzej Wójcik IoT 1 CloudTigaseTeam over 5 years ago

You uploaded script to your server properly using following command:


To execute uploaded room-remove command you should use TCMLT's remote command, example below:

Added by Igor Khomenko over 5 years ago

Thanks, this is really step forward!

Ok, i uploaded this script to server, next, trying to execute:

bin/tclmt.sh -debug -u ... -p ... -s ... remote muc room-remove room-name carroom reason testreason alternate-jid carroom@muc.chat.mysite.com

and got error

awaiting response...

Note: Script execution error.

Error message: tigase.util.TigaseStringprepException: Illegal characters in string.

Debug info: [tigase.util.TigaseStringprepException: Illegal characters in string., javax.script.ScriptException: tigase.util.TigaseStringprepException: Illegal characters in string., org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:318), org.codehaus.groovy.jsr223.GroovyCompiledScript.eval(GroovyCompiledScript.java:41), tigase.server.script.Script.runCommand(Script.java:182), tigase.server.BasicComponent.processScriptCommand(BasicComponent.java:885), tigase.server.AbstractMessageReceiver$QueueListener.run(AbstractMessageReceiver.java:1324), null]

looks like something wrong with JID, because i see that it must be jid-single (in comparison with room-name: text-single)

Don't know what does it mean, could you please suggest

Added by Andrzej Wójcik IoT 1 CloudTigaseTeam over 5 years ago

Please try using example from below:

TCLMT scripts are usually create in way which you should not pass name of parameter in command line. Name of parameter is resolved by order of parameters.
(1)

Added by Igor Khomenko over 5 years ago

Got the same result

bin/tclmt.sh -u ... -p ... remote muc room-remove carroom test roomjid@muc.chat.mysite.com

Sep 12, 2013 7:30:01 PM tigase.xml.db.XMLDB setupNewDB

INFO: Create empty DB.

awaiting response...

awaiting response...

Note: Script execution error.

Error message: tigase.util.TigaseStringprepException: Illegal characters in string.

Debug info: [tigase.util.TigaseStringprepException: Illegal characters in string., javax.script.ScriptException: tigase.util.TigaseStringprepException: Illegal characters in string., org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:318), org.codehaus.groovy.jsr223.GroovyCompiledScript.eval(GroovyCompiledScript.java:41), tigase.server.script.Script.runCommand(Script.java:182), tigase.server.BasicComponent.processScriptCommand(BasicComponent.java:885), tigase.server.AbstractMessageReceiver$QueueListener.run(AbstractMessageReceiver.java:1324), null]

maybe something wrong with this line in script

tigase.xmpp.BareJID jid = tigase.xmpp.BareJID.bareJIDInstance(roomName+"@"+p.getStanzaTo().getBareJID().toString());

Is there any way to debug remote script, kind of logs. ? Thanks a lot for support

Added by Igor Khomenko over 5 years ago

Ok guys,

i updated script, made it simpler to use

and it works like a charm

here it is:

// AS:Description: Remove room

// AS:CommandId: room-remove

// AS:Component: muc

import tigase.server.Command

import tigase.server.Packet

def ROOM_JID_KEY = "room-jid"

def Packet p = (Packet)packet

def roomJID = Command.getFieldValue(p, ROOM_JID_KEY)

if (roomJID == null) {

// No data to process, let's ask user to provide

// a list of words

def res = (Packet)p.commandResult(Command.DataType.form)

Command.addFieldValue(res, ROOM_JID_KEY, "", "text-single", "Room jid")

return res

}

if (roomJID != null){

tigase.xmpp.BareJID jid = tigase.xmpp.BareJID.bareJIDInstance(roomJID);

def room=mucRepository.getRoom(jid);

if(room==null){

return "Room doesn't exists"

}

ownerModule.destroy(room, roomJID, "admin cleanup");

return "Room "+room.getRoomJID()+" removed";

}

(1)
Avatar?id=6023&size=32x32

Added by Artur Hefczyc TigaseTeam over 5 years ago

Thank you for submitting your version of the script, we will look at it.

Avatar?id=6023&size=32x32

Added by Artur Hefczyc TigaseTeam over 5 years ago

You can track the progress in issue: #1564

    (1-9/9)