scripting tutorial?

Discussion about Perl, TCL or Python scripts and C/C++ plugins (using and writing them).

scripting tutorial?

Postby xchatuser » 13 Jul 2004 16:05

Sorry, I'm a noob to xchat.
Is there a tutorial for scripting in xchat?
xchatuser
 
Posts: 13
Joined: 12 Jul 2004 22:01

Postby MrScout » 13 Jul 2004 18:34

The simple answer is this:

There are manuals relating to the xchat interface into perl, python, tcl, and C (I think).

I personally do all my scripting in python. Basically how it works is this:

xchat runs a virtual machine (python, perl, etc) and executes code as required. (I think this is how it works... if its not, I'm always game to listen to correction).

So... there is not so much "xchat scripting" per se, as much as "writing scripts in language X for xchat". So, I recommend starting here:

http://www.python.org

and then going here
http://www.xchat.org/docs/

Scout
All polynomials are funny; some to a higher degree. Furthermore, all polynomials of degree zero are constantly funny.

Python Plugins by Request: PM me or find me at #kwikdeath on Gamesurge
MrScout
 
Posts: 76
Joined: 28 Jun 2004 06:01
Location: Angelo State University

Postby Khisanth » 13 Jul 2004 21:42

there is also a Ruby interface :)
Khisanth
 
Posts: 1724
Joined: 10 Jun 2004 05:23

Postby xchatuser » 13 Jul 2004 22:25

so I can write a perl script say "query.pl" which accesses remote or local mysql database and displays the contents in xchat?
xchatuser
 
Posts: 13
Joined: 12 Jul 2004 22:01

Postby Fang » 13 Jul 2004 22:51

You sure can, all you have to do once your script is written is to trigger it from within X-Chat. You can do that manually (with a simple IRC command), or automatically (when something happens on IRC, someone connecting, someone saying something, etc.). Check the Perl docs at xchat.org/docs/
Fang
 
Posts: 47
Joined: 19 Jun 2004 09:52

Postby xchatuser » 15 Jul 2004 23:31

Ok I have a perl script. How do I put it in xchat?

say user types "/query 'address'" and it outputs it in xchat...


This is what I have figured out so far but I have no idea if it is right.

script.pl
-----------------
Code: Select all
#!/usr/bin/perl

IRC::register ("my script", "1.0", "", "");

IRC::add_command_handler("query", "querythis");

sub querythis
{

#query code left out

IRC::print("Item: $id Name: $name Location: $location\n");

}

-------------------------------
Now how do I put it in xchat?[/code]
xchatuser
 
Posts: 13
Joined: 12 Jul 2004 22:01

Postby Fang » 16 Jul 2004 08:33

Put it in ~/.xchat2/, launch X-Chat.
Fang
 
Posts: 47
Joined: 19 Jun 2004 09:52

Postby xchatuser » 16 Jul 2004 17:21

how do you read in user input after the command?

/query 222.333.111.222

IRC::add_command_handler("query $address", "querythis");

?
xchatuser
 
Posts: 13
Joined: 12 Jul 2004 22:01

Postby xchatuser » 17 Jul 2004 19:42

Auto load plug in doesn't work. I have a perl script called myscript.pl and I have put it in \xchat and \xchat\plugins but when I run xchat it doesnt load it. When I manualy load the script it works fine.

I am on windows ME. And I have perl 5.8.4 installed and running fine.
xchatuser
 
Posts: 13
Joined: 12 Jul 2004 22:01

Postby MrScout » 17 Jul 2004 19:45

C:\Documents and Settings\Mark\Application Data\X-Chat 2

Scout
All polynomials are funny; some to a higher degree. Furthermore, all polynomials of degree zero are constantly funny.

Python Plugins by Request: PM me or find me at #kwikdeath on Gamesurge
MrScout
 
Posts: 76
Joined: 28 Jun 2004 06:01
Location: Angelo State University

Postby xchatuser » 17 Jul 2004 19:47

oh rofl.... C:\WINDOWS\Application Data\X-Chat 2 worked.
xchatuser
 
Posts: 13
Joined: 12 Jul 2004 22:01

Postby MrScout » 17 Jul 2004 23:03

Oh. There ya go. ;-) Glad we got that worked out! Feel free to holler at us more with other questions.



Scout
All polynomials are funny; some to a higher degree. Furthermore, all polynomials of degree zero are constantly funny.

Python Plugins by Request: PM me or find me at #kwikdeath on Gamesurge
MrScout
 
Posts: 76
Joined: 28 Jun 2004 06:01
Location: Angelo State University

Postby xchatuser » 17 Jul 2004 23:45

Is there a way to get user input after the command for example

/query 33.22.36.11

How would I get the 33.22.36.11 part in perl script?
xchatuser
 
Posts: 13
Joined: 12 Jul 2004 22:01

Postby Khisanth » 18 Jul 2004 00:10

xchatuser wrote:Is there a way to get user input after the command for example

/query 33.22.36.11

How would I get the 33.22.36.11 part in perl script?


Like this
Code: Select all
Xchat::register( "mumble", 0.1 );
Xchat::hook_command( "query", \&cmd_query );

sub cmd_query {
    # if you type "/query 1234" then $arg will contain 1234
    # however if you type "/query 1234 5678" $arg will still only contain
     # 1234 because 5678 will be in $_[0][2]
    my $arg = $_[0][1];
   
    if( <do some checks relating to $arg here> ) {
       <do stuff>
       # don't let xchat process this event any further because if $arg
       # contains something like 33.22.36.11, xchat is not going to do
       # anything useful unless you are trying to speak to someone with
       # the nick 33.22.36.11
       # Note: other plugins and scripts will still see this event with
       # EAT_XCHAT
       return Xchat::EAT_XCHAT;
    }
    # didn't meet our criteria for $arg, probably just a regular /query
    # so we will pass it on to xchat
    return Xchat::EAT_NONE;
}
Khisanth
 
Posts: 1724
Joined: 10 Jun 2004 05:23

Postby Fang » 18 Jul 2004 13:54

Amazing. A Perl script with actually more comments than real code.

A breakthrough. :o
Fang
 
Posts: 47
Joined: 19 Jun 2004 09:52

Next

Return to Scripts and Plugins

Who is online

Users browsing this forum: No registered users and 1 guest