XChat 2.0 Plugin Interface
plugin20.html revision 0.97
Latest version of this document is available at: http://xchat.org/docs/plugin20.html
Information:
Introduction
Sample plugin
What is word and word_eol?
Lists and fields
Functions:
xchat_hook_command
xchat_hook_fd
xchat_hook_print
xchat_hook_server
xchat_hook_timer
xchat_unhook
xchat_command
xchat_commandf
xchat_print
xchat_printf
xchat_emit_print
xchat_find_context
xchat_get_context
xchat_get_info
xchat_get_prefs
xchat_set_context
xchat_nickcmp
xchat_list_get
xchat_list_free
xchat_list_fields
xchat_list_next
xchat_list_str
xchat_list_int
Plugins for XChat are originally meant to be written in C. Now, there
is an interface for Euphoria. The interface aims to keep 100%
binary compatability. This means that if you upgrade XChat, you will
not need to recompile your plugins, they'll continue to work. The
only real requirement of
an XChat plugin, is that it define a "xchat_plugin_init" or equivalent
symbol. This
is your entry point function, the routine_id of which, should be
assigned to xchatPluginInitID. All your global variables and functions
will not be exported. Plugins are only compile-able and Windows,
currently. It has been tested with Borland only, but may work with
other compilers. For example:
ecw -bor -dll c:\projects\xchat-plugin\myplugin.ew
exw XChat-Setup.exw c:\projects\xchat-plugin
emake
This simple plugin autoOps anyone who joins a channel you're in. It
also
adds a new command /AUTOOPTOGGLE, which can be used to turn the feature
ON
or OFF. Every XChat plugin must assign a routine id to
xchatPluginInitID. A routine id for xchatPluginDeinitID is optional.
Note: A plugin may define the symbol 'xchat_plugin_init' or
'xchat_plugin_deinit', but they may not be global.
include xchat-plugin.ew
xchat_plugin ph -- plugin handle
integer enable enable = 1
object VOID
function join_cb(sequence word, atom userdata)
if (enable) then
-- Op ANYONE who joins
xchat_commandf(ph, "OP %s", {word[1]})
-- word[1] is the nickname, as in the Settings->Lists->EventTexts window in xchat
end if
return XCHAT_EAT_NONE -- don't eat this event, xchat needs to see it!
end function
function autooptoggle_cb(sequence word, sequence word_eol, atom userdata)
if not(enable) then
enable = 1
xchat_print(ph, "AutoOping Now Enabled!\n")
else
enable = 0
xchat_print(ph, "AutoOping Now Disabled!\n")
end if
return XCHAT_EAT_ALL -- eat this command so xchat and other plugins can't process it
end function
function plugin_init(xchat_plugin plugin_handle, sequence arg)
sequence plugin_name, plugin_desc, plugin_version
-- we need to save this for use with any xchat_* functions
ph = plugin_handle
plugin_name = "AutoOp"
plugin_desc = "Auto Ops Anyone that Joins"
plugin_version = "0.1"
VOID = xchat_hook_command(ph, "AutoOpToggle", XCHAT_PRI_NORM, routine_id("autooptoggle_cb"),
"Usage: AUTOOPTOGGLE, Turns OFF/ON Auto Oping", 0)
VOID = xchat_hook_print(ph, "Join", XCHAT_PRI_NORM, routine_id("join_cb"), 0)
xchat_print(ph, "AutoOpPlugin Loaded Successfully!\n")
return {plugin_name, plugin_desc, plugin_version}
end function
xchatPluginInitID = routine_id("plugin_init")
They are arrays of strings. They contain the parameters the user
entered
for the particular command. For example, if you executed:
/command NICK hi there
word[1] is command
word[2] is NICK
word[3] is hi
word[4] is there
word_eol[1] is command NICK hi there
word_eol[2] is NICK hi there
word_eol[3] is hi there
word_eol[4] is there
These sequences are simply provided for your convenience. They are
automatically converted from C pointer arrays. Both sequences are
limited to 31 elements.
Lists of information (DCCs, Channels, Userlist etc) can be retreived
with xchat_list_get. The types of lists
and fields available are:
"channels" - list of channels, querys and their servers.
Name |
Description |
Type |
channel |
Channel or query name |
string |
context |
xchat_context pointer. Can be used with
xchat_set_context |
string |
network |
Network name to which this channel belongs
(Added in version 2.0.2. Older versions will return
NULL) |
string |
server |
Server name to which this channel belongs |
string |
type |
Type of context this is: 1-Server 2-Channel 3-Dialog
(Added in version 2.0.2. Older versions will return -1) |
int |
"dcc" - list of DCC file transfers. Fields:
Name |
Description |
Type |
address32 |
Address of the remote user (ipv4 address) |
int |
cps |
Bytes per second (speed) |
int |
destfile |
Destination full pathname |
string |
file |
File name |
string |
nick |
Nickname of person who the file is from/to |
string |
port |
TCP port number |
int |
pos |
Bytes sent/received |
int |
resume |
Point at which this file was resumed (or zero if it was
not resumed) |
int |
size |
File size in bytes |
int |
status |
DCC Status: 0-Queued 1-Active 2-Failed 3-Done
4-Connecting 5-Aborted |
int |
type |
DCC Type: 0-Send 1-Receive 2-ChatRecv 3-ChatSend |
int |
"ignore" - current ignore list.
Name |
Description |
Type |
mask |
Ignore mask. .e.g: *!*@*.aol.com |
string |
flags |
Bit field of flags. 0=Private 1=Notice 2=Channel 3=Ctcp
4=Invite 5=UnIgnore 6=NoSave 7=DCC |
int |
"users" - list of users in the current channel.
Name |
Description |
Type |
nick |
Nick name |
string |
host |
Host name in the form: user@host (or NULL if not known). |
string |
prefix |
Prefix character, .e.g: @ or +. Points to a single char. |
string |
Example:
list = xchat_list_get(ph, "dcc")
if (list) then
xchat_print(ph, "--- DCC LIST ------------------\n"&
"File To/From KB/s Position\n")
while xchat_list_next(ph, list) do
xchat_printf(ph, "%6s %10s %.2f %d\n", {
xchat_list_str(ph, list, "file"),
xchat_list_str(ph, list, "nick"),
xchat_list_int(ph, list, "cps") / 1024,
xchat_list_int(ph, list, "pos")})
end while
xchat_list_free(ph, list)
end if
Functions
Prototype: xchat_hook xchat_hook_command(xchat_plugin ph,
sequence name, integer pri, xchat_cmd_cb callb, sequence help_text,
object userdata)
Description: Adds a new /command.
Arguments:
ph: Plugin handle (as given to xchat_plugin_init).
name: Name of the command (without the forward slash).
pri: Priority of this command. Use XCHAT_PRI_NORM.
callb: Routine ID of callback function. This will be called
when the user
executes the given command name.
help_text: String of text to display when the user executes
/help for this command. May be "" if you're lazy.
userdata: Data passed to the callback function.
Returns: Pointer to the hook. Can be passed to xchat_unhook.
Example:
function onotice_cb(sequence word, sequence word_eol, object userdata)
if length(word_eol[2]) = 0 then
xchat_printf(ph, "Second arg must be the message!\n", {})
return XCHAT_EAT_ALL
end if
xchat_commandf(ph, "NOTICE @%s :%s", {xchat_get_info(ph, "channel"), word_eol[2]})
return XCHAT_EAT_ALL
end function
hook = xchat_hook_command(ph, "ONOTICE", XCHAT_PRI_NORM, routine_id("onotice_cb"),
"Usage: ONOTICE <message> Sends a notice to all ops", 0)
Prototype: xchat_hook xchat_hook_fd(xchat_plugin ph, integer fd,
integer flags, xchat_fd_cb callb, object userdata)
Description: Hooks a socket or file descriptor.
Arguments:
ph: Plugin handle (as given to xchat_plugin_init).
fd: The file descriptor or socket.
flags: One or more of XCHAT_FD_READ, XCHAT_FD_WRITE,
XCHAT_FD_EXCEPTION. Use bitwise OR to combine them.
callb: Routine ID of callback function. This will be called
when the socket
is available for reading/writing or exception (depending on your chosen
flags)
userdata: Data passed to the callback function.
Returns: Pointer to the hook. Can be passed to xchat_unhook.
Prototype: xchat_hook xchat_hook_print(xchat_plugin ph,
sequence name, integer
pri, xchat_print_cb callb, object userdata)
Description: Registers a function to trap any print events.
The event names may be any available in the "Edit Event Texts" window.
There are also some extra "special" events you may hook using this
function.
Currently they are:
"Open Context" - Called when a new xchat_context is
created.
"Close Context" - Called when a xchat_context pointer is closed.
"Focus Tab" - Called when a tab is brought to front.
"Focus Window" - Called a toplevel window is focused, or the main
tab-window is focused by the window manager.
"DCC Chat Text" - Called when some text from a DCC Chat arrives. It
provides these elements in the word[] sequence:
word[1] Address
word[2] Port
word[3] Nick
word[4] The Message
Arguments:
ph: Plugin handle (as given to xchat_plugin_init).
name: Name of the print event (as in Edit Event Texts Window).
pri: Priority of this command. Use XCHAT_PRI_NORM.
callb: Routine ID of callback function. This will be called
when this event
name is printed.
userdata: Data passed to the callback function.
Returns: Pointer to the hook. Can be passed to xchat_unhook.
Example:
function youpart_cb(sequence word, object userdata)
xchat_printf(ph, "You have left channel %s\n", {word[3]})
return XCHAT_EAT_XCHAT -- dont let xchat do its normal printing
end function
hookID = xchat_hook_print(ph, "You Part", XCHAT_PRI_NORM, routine_id("youpart_cb"), NULL)
Prototype: xchat_hook xchat_hook_server(xchat_plugin ph,
sequence name, integer pri, xchat_serv_cb callb, object userdata)
Description: Registers a function to be called when a certain
server event occurs. You can
use this to trap PRIVMSG, NOTICE, PART, a server numeric etc... If you
want to
hook every line that comes from the IRC server, you may use the special
name of "RAW LINE".
Arguments:
ph: Plugin handle (as given to xchat_plugin_init).
name: Name of the server event.
pri: Priority of this command. Use XCHAT_PRI_NORM.
callb: Routine ID of callback function. This will be called
when this event
is received from the server.
userdata: Data passed to the callback function.
Returns: Pointer to the hook. Can be passed to xchat_unhook.
Example:
function kick_cb(sequence word, sequence word_eol, object userdata)
xchat_printf(ph, "%s was kicked from %s (reason=%s)\n", {word[4], word[3], word_eol[5]})
return XCHAT_EAT_NONE -- don't eat this event, let other plugins and xchat see it too
end function
hookID = xchat_hook_server(ph, "KICK", XCHAT_PRI_NORM, kick_cb, NULL)
Prototype: xchat_hook xchat_hook_timer(xchat_plugin ph, integer
timeout, xchat_timer_cb callb, object userdata)
Description: Registers a function to be called every "timeout"
milliseconds.
Arguments:
ph: Plugin handle (as given to xchat_plugin_init).
timeout: Timeout in milliseconds (1000 is 1 second).
callb: Routine ID of callback function. This will be called
every "timeout"
milliseconds.
userdata: Data passed to the callback function.
Returns: Pointer to the hook. Can be passed to xchat_unhook.
Example:
xchat_hook myhook
function stop_cb(sequence word, sequence word_eol, object userdata)
if myhook != NULL then
void = xchat_unhook(ph, myhook)
myhook = NULL
xchat_print(ph, "Timeout removed!\n")
end if
return XCHAT_EAT_ALL
end function
function timeout_cb(object userdata)
xchat_print(ph, "Annoying message every 5 seconds! Type /STOP to stop it.\n")
return 1 -- return 1 to keep the timeout going
end function
myhook = xchat_hook_timer(ph, 5000, routine_id("timeout_cb"), NULL)
void = xchat_hook_command(ph, "STOP", XCHAT_PRI_NORM, routine_id("stop_cb"), NULL, NULL)
Prototype: object xchat_unhook(xchat_plugin ph, xchat_hook hook)
Description: Unhooks any hook registered with
xchat_hook_print/server/timer/command.
Arguments:
ph: Plugin handle (as given to xchat_plugin_init).
hook: Pointer to the hook, as returned by xchat_hook_*.
Returns: The userdata you originally gave to xchat_hook_*.
Prototype: xchat_command(xchat_plugin ph, sequence command)
Description: Executes a command as if it were typed in xchat's
input box.
Arguments:
ph: Plugin handle (as given to xchat_plugin_init).
command: Command to execute, without the forward slash "/".
Prototype: xchat_commandf(xchat_plugin ph, sequence format,
sequence params)
Description: Executes a command as if it were typed in xchat's
input box and provides string formating like printf.
Arguments:
ph: Plugin handle (as given to xchat_plugin_init).
format: The format string.
params: The format string's
parameters.
Prototype: xchat_print(xchat_plugin ph, sequence text)
Description: Prints some text to the current tab/window.
Arguments:
ph: Plugin handle (as given to xchat_plugin_init).
text: Text to print. May contain mIRC color codes.
Prototype: xchat_printf(xchat_plugin ph, sequence format,
sequence params)
Description: Prints some text to the current tab/window and
provides formating like printf.
Arguments:
ph: Plugin handle (as given to xchat_plugin_init).
format: The format string.
params: The format string's
parameters.
Prototype: integer xchat_emit_print(xchat_plugin ph, sequence
event_name, sequence params)
Description: Generates a print event. This can be any
event found in the Preferences > Lists > Text Events window.
Arguments:
ph: Plugin handle (as given to xchat_plugin_init).
event_name: Text event to print.
params: Parameters for the
text event.
Returns: 1-Success 0-Failure.
Example:
void = xchat_emit_print(ph, "Channel Message", {"John", "Hi there", "@"})
Prototype: xchat_context xchat_find_context(xchat_plugin ph,
sequence servname, sequence channel)
Description: Finds a context based on a channel and
servername. If servname is "", it finds any channel (or query) by the
given name. If channel is "", it finds the front-most tab/window of
the given servname. If "" is given for both arguments, the currently
focused tab/window will be returned.
Arguments:
ph: Plugin handle (as given to xchat_plugin_init).
servname: Servername or "".
channel: Channelname or "".
Returns: Context pointer (for use with xchat_set_context) or
NULL.
Prototype: xchat_context xchat_get_context(xchat_plugin ph)
Description: Returns the current context for your plugin. You
can use this later with xchat_set_context.
Arguments:
ph: Plugin handle (as given to xchat_plugin_init).
Returns: Context pointer (for use with xchat_set_context).
Prototype: sequence xchat_get_info(xchat_plugin ph, sequence id)
Description: Returns information based on your current context.
Arguments:
ph: Plugin handle (as given to xchat_plugin_init).
id: ID of the information you want. Currently supported IDs
are (case sensitive):
away |
away reason or "" if you are not away. |
channel |
current channel name. |
host |
real hostname of the server you connected to. |
network |
current network name or "". |
nick |
your current nick name. |
server |
current server name (what the server claims to be).""
if you are not connected. |
topic |
current channel topic. |
version |
xchat version number. |
xchatdir |
xchat config directory, e.g.: /home/user/.xchat. |
Returns: A string of the requested information, or "".
Prototype: object xchat_get_prefs(xchat_plugin ph, sequence
name)
Description: Provides xchat's setting information (that which is
available through the /set command).
Arguments:
ph: Plugin handle (as given to xchat_plugin_init).
name: Setting name required.
Returns: ""-Failed "<some text>"-Returned a string
<number>-Returned an Integer /Boolean.
Example:
object nick
nick = xchat_get_prefs(ph, "irc_nick1")
if sequence(nick) and length(nick) > 0 then
xchat_printf(ph, "Current nickname setting: %s\n", {str})
end if
Prototype: integer xchat_set_context(xchat_plugin ph,
xchat_context ctx)
Description: Changes your current context to the one given.
Arguments:
ph: Plugin handle (as given to xchat_plugin_init).
ctx: Context to change to (obtained with xchat_get_context or
xchat_find_context).
Returns: 1 for success, 0 for failure.
Prototype: integer xchat_nickcmp(xchat_plugin ph, sequence s1,
sequence s2)
Description: Performs a nick name comparision, based on the
current server connection. This might be a RFC1459 compliant string
compare, or
plain ascii (in the case of DALNet). Use this to compare channels and
nicknames. The function works the same way as strcasecmp.
Arguments:
ph: Plugin handle (as given to xchat_plugin_init).
s1: String to compare.
s2: String to compare s1 to.
Quote from RFC1459:
Because of IRC's scandanavian origin, the characters {}|
are considered to be the lower case equivalents of the characters []\,
respectively. This is a critical issue when determining the equivalence
of two nicknames.
Returns: An integer less than, equal to, or greater than zero if
s1 is found, respectively, to be less than, to match, or be greater
than s2.