Prototype: int ascii_strcasecmp (t_weechat_plugin *plugin, char *string1, char *string2)
Locale and case independent string comparison.
Arguments:
plugin: pointer to plugin structure
string1: first string for comparison
string2: second string for comparison
Return value: difference between two strings: negative if string1 < string2, zero if string1 == string2, positive if string1 > string2
Example:
if (plugin->ascii_strcasecmp (plugin, "abc", "def") != 0) ...
Prototype: int ascii_strncasecmp (t_weechat_plugin *plugin, char *string1, char *string2, int max)
Locale and case independent string comparison, for "max" chars.
Arguments:
plugin: pointer to plugin struct
string1: first string for comparison
string2: second string for comparison
max: max number of chars for comparison
Return value: difference between two strings: negative if string1 < string2, zero if string1 == string2, positive if string1 > string2
Example:
if (plugin->ascii_strncasecmp (plugin, "abc", "def", 2) != 0) ...
Prototype: char **explode_string (t_weechat_plugin *plugin, char *string, char *separators, int num_items_max, int *num_items)
Explode a string according to one or more delimiter(s).
Arguments:
plugin: pointer to plugin struct
string: string to explode
separators: delimiters used for explosion
num_items_max: maximum number of items
created (0 = no limit)
num_items: pointer to int which will
contain number of items created
Return value: array of strings, NULL if problem.
Note: result has to be free by a call to "free_exloded_string" after use.
Example:
char **argv;
int argc;
argv = plugin->explode_string (plugin, string, " ", 0, &argc);
...
if (argv != NULL)
plugin->free_exploded_string (plugin, argv);
Prototype: char **free_exploded_string (t_weechat_plugin *plugin, char **string)
Free memory used by a string explosion.
Arguments:
plugin: pointer to plugin structure
string: string exploded by
"explode_string" function
Return value: none.
Example:
char *argv;
int argc;
argv = plugin->explode_string (plugin, string, " ", 0, &argc);
...
if (argv != NULL)
plugin->free_exploded_string (plugin, argv);
Prototype: void exec_on_files (t_weechat_plugin *plugin, char *repertoire, int (*callback)(t_weechat_plugin *, char *))
Execute a function on all files of a directory.
Arguments:
plugin: pointer to plugin structure
directory: directory for searching files
callback: function called for each file
found
Return value: none.
Example:
int callback (t_weechat_plugin *plugin, char *file)
{
plugin->print_server (plugin, "file: %s", file);
return 1;
}
...
plugin->exec_on_files (plugin, "/tmp", &callback);
Prototype: void print (t_weechat_plugin *plugin, char *server, char *channel, char *message, ...)
Display a message on a WeeChat buffer, identified by server and channel (both may be NULL for current buffer).
Arguments:
plugin: pointer to plugin structure
server: internal name of server to find
buffer for message display (may be NULL)
channel: name of channel to find buffer
for message display (may be NULL)
message: message
Return value: none.
Examples:
plugin->print (plugin, NULL, NULL, "hello"); plugin->print (plugin, NULL, "#weechat", "hello"); plugin->print (plugin, "freenode", "#weechat", "hello");
Prototype: void print_server (t_weechat_plugin *plugin, char *message, ...)
Display a message on current server buffer.
Arguments:
plugin: pointer to plugin structure
message: message
Return value: none.
Example:
plugin->print_server (plugin, "hello");
Prototype: void print_infobar (t_weechat_plugin *plugin, int time, char *message, ...)
Display a message in infobar for a specified time.
Arguments:
plugin: pointer to plugin structure
time: time (in seconds) for displaying
message (0 = never erased)
Return value: none.
Example:
plugin->print_infobar (plugin, 5, "hello");
Prototype: void infobar_remove (t_weechat_plugin *plugin, int count)
Remove one or more messages in infobar stack.
Arguments:
plugin: pointer to plugin structure
count: number of messages to remove
(if argument is <= 0, then all messages are removed)
Return value: none.
Example:
plugin->infobar_remove (1);
Prototype: void log (t_weechat_plugin *plugin, char *server, char *channel, char *message, ...)
Write a message in log file for a server or a channel.
Arguments:
plugin: pointer to plugin structure
server: internal name of server to find
buffer for log (may be NULL)
channel: name of channel to find buffer
for log (may be NULL)
message: message
Return value: none.
Example:
plugin->log (plugin, "freenode", "#weechat", "test");
Prototype: t_plugin_handler *msg_handler_add (t_weechat_plugin *plugin, char *message, t_plugin_handler_func *function, char *handler_args, void *handler_pointer)
Add an IRC message handler, called when an IRC message is received.
Arguments:
plugin: pointer to plugin structure
message: name of IRC message.
To know list of IRC messages, please consult
RFCs
1459 and
2812.
Moreover you can use a special name, prefixed by "weechat_" to catch
special events, as written in table below:
| Name | Description |
|---|---|
weechat_pv | private message received |
weechat_highlight | message with highlight (on a channel or pv) |
weechat_ctcp | CTCP message received (VERSION, PING, ..) |
weechat_dcc | DCC message received (chat or file) |
function: function called when message
is received
It uses following prototype: int my_function (t_weechat_plugin *plugin, int argc, char **argv, char *handler_args, void *handler_pointer)
Argument argc is set to 3, following values are set in argv array:
argv[0] = server name
argv[1] = IRC message
argv[2] = command arguments
handler_args: arguments given to function
when called
handler_pointer: pointer given to function
when called
Return value: pointer to new message handler.
Note: function called when message is received has to return one of following values:
PLUGIN_RC_KO: function failed
PLUGIN_RC_OK: function successfully
completed
PLUGIN_RC_OK_IGNORE_WEECHAT: message
will not be sent to WeeChat
PLUGIN_RC_OK_IGNORE_PLUGINS: message
will not be sent to other plugins
PLUGIN_RC_OK_IGNORE_ALL: message
will not be sent to WeeChat neither other plugins
Example:
int msg_kick (t_weechat_plugin *plugin, char *server, char *command,
char *arguments, char *handler_args, void *handler_pointer)
{
plugin->print (plugin, server, NULL, "KICK received");
return PLUGIN_RC_OK;
}
...
plugin->msg_handler_add (plugin, "KICK", &msg_kick, NULL, NULL);
Prototype: t_plugin_handler *cmd_handler_add (t_weechat_plugin *plugin, char *command, char *description, char *arguments, char *arguments_description, char *completion_template, t_plugin_handler_func *fonction, char *handler_args, void *handler_pointer)
Add a WeeChat command handler, called when user uses command (for example /command).
Arguments:
plugin: pointer to plugin structure
command: the new command name, which
may be an existing command (be careful, replaced command
will not be available until plugin is unloaded)
description: short command description
(displayed by /help command)
arguments: short description of command
arguments (displayed by /help command)
arguments_description: long description
of command arguments (displayed by /help command)
completion_template: template for
completion, like "abc|%w def|%i"
which means "abc" or a WeeChat command for first argument,
"def" or IRC command for second.
An empty string lets WeeChat complete any argument with
a nick from current channel, NULL disable completion for
all command arguments.
Following codes can be used:
| Code | Description |
|---|---|
%- | no completion for argument |
%a | alias |
%A | alias and commands (WeeChat, IRC and plugins) |
%c | current channel |
%C | channels of current server |
%h | plugins commands |
%i | IRC commands (sent) |
%I | IRC commands (received) |
%k | key functions |
%n | nicks of current channel |
%N | nicks and hostnames of current channel |
%o | setup options |
%O | plugin options |
%p | default "part" message |
%q | default "quit" message |
%s | current server name |
%S | all servers names |
%t | topic of current channel |
%v | setup option value |
%V | plugin option value |
%w | WeeChat commands |
function: function called when command
is executed
It uses following prototype: int my_function (t_weechat_plugin *plugin, int argc, char **argv, char *handler_args, void *handler_pointer)
Argument argc is set to 3, following values are set in argc array:
argv[0] = server name
argv[1] = command
argv[2] = command arguments
handler_args: arguments given to function
when called
handler_pointer: pointer given to function
when called
Return value: pointer to new command handler.
Note: function called when command is executed has to return one of following values:
PLUGIN_RC_KO: function failed
PLUGIN_RC_OK: function successfully
completed
Example:
int cmd_test (t_weechat_plugin *plugin, char *server,
char *command, char *arguments, char *handler_args,
void *handler_pointer)
{
plugin->print (plugin, server, NULL,
"test command, nick: %s",
(arguments) ? arguments : "none");
return PLUGIN_RC_OK;
}
...
plugin->cmd_handler_add (plugin, "test", "Test command",
"[nick]", "nick: nick of channel",
"%n", &cmd_test, NULL, NULL);
Prototype: t_plugin_handler *timer_handler_add (t_weechat_plugin *plugin, int interval, t_plugin_handler_func *function, char *handler_args, void *handler_pointer)
Add a timer handler which periodically calls a function.
Arguments:
plugin: pointer to plugin structure
interval: interval (in seconds) between
two calls of function.
function: function called
It uses following prototype: int my_function (t_weechat_plugin *plugin, int argc, char **argv, char *handler_args, void *handler_pointer)
Argument argc is set to 0, and argv is set to NULL.
handler_args: arguments given to function
when called
handler_pointer: pointer given to function
when called
Return value: pointer to new timer handler.
Note: function called has to return one of following values:
PLUGIN_RC_KO: function failed
PLUGIN_RC_OK: function successfully
completed
Example:
int my_timer (t_weechat_plugin *plugin, char *server, char *command,
char *arguments, char *handler_args, void *handler_pointer)
{
plugin->print (plugin, NULL, NULL, "my timer");
return PLUGIN_RC_OK;
}
...
plugin->timer_handler_add (plugin, 60, &my_timer);
Prototype: t_plugin_handler *keyboard_handler_add (t_weechat_plugin *plugin, t_plugin_handler_func *function, char *handler_args, void *handler_pointer)
Add a keyboard handler, called for any key pressed.
Arguments:
plugin: pointer to plugin structure
function: function called
It uses following prototype: int my_function (t_weechat_plugin *plugin, int argc, char **argv, char *handler_args, void *handler_pointer)
Argument argc is set to 3, following values are set in argc array:
argv[0] = key pressed (name of internal function or '*' followed by a key code)
argv[1] = command line before key action
argv[2] = command line after key action
handler_args: arguments given to function
when called
handler_pointer: pointer given to function
when called
Return value: pointer to new message handler.
Note: function called has to return one of following values:
PLUGIN_RC_KO: function failed
PLUGIN_RC_OK: function successfully
completed
Example:
int keyb_handler (t_weechat_plugin *plugin, int argc, char **argv,
char *handler_args, void *handler_pointer)
{
if (argc == 2)
{
plugin->print (plugin, NULL, NULL, "key pressed: %s", argv[0]);
if (argv[1] && (argv[1][0] == '1'))
plugin->print (plugin, NULL, NULL, "input text changed");
else
plugin->print (plugin, NULL, NULL, "input text not changed");
}
return PLUGIN_RC_OK;
}
...
plugin->keyboard_handler_add (plugin, &keyb_handler);
Prototype: void handler_remove (t_weechat_plugin *plugin, t_plugin_handler *handler)
Remove a command or message handler.
Arguments:
plugin: pointer to plugin structure
handler: handler to remove
Return value: none.
Example:
plugin->handler_remove (plugin, my_handler);
Prototype: void handler_remove_all (t_weechat_plugin *plugin)
Remove all handlers for a plugin.
Arguments:
plugin: pointer to plugin structure
Return value: none.
Example:
plugin->handler_remove_all (plugin);
Prototype: void exec_command (t_weechat_plugin *plugin, char *server, char *channel, char *command)
Execute a WeeChat command (or send a message to a channel).
Arguments:
plugin: pointer to plugin structure
server: internal name of server for
executing command (may be NULL)
channel: name of channel for executing
command (may be NULL)
command: command
Return value: none.
Examples:
plugin->exec_command (plugin, NULL, NULL, "/help nick"); plugin->exec_command (plugin, "freenode", "#weechat", "hello");
Prototype: char *get_info (t_weechat_plugin *plugin, char *info, char *server)
Return an info about WeeChat or a channel.
Arguments:
plugin: pointer to plugin structure
info : name of info to read:
| Info | Description |
|---|---|
version | WeeChat's version |
nick | nick |
channel | name of channel (NULL for a server or private) |
server | name of server |
away | "away" flag |
inactivity | number of seconds since last key was pressed |
input | content of command line for current window |
input_mask | content of color mask for command line |
input_pos | cursor position in command line |
weechat_dir | WeeChat home directory (by default: ~/.weechat/) |
weechat_libdir | WeeChat system lib directory |
weechat_sharedir | WeeChat system share directory |
server: internal name of server for
reading info (if needed)
Return value: information asked, NULL if not found.
Note: result has to be free by a call to "free" function after use.
Examples:
char *version = plugin->get_info (plugin, "version", NULL);
char *nick = plugin->get_info (plugin, "nick", "freenode");
char *inactivity = plugin->get_info (plugin, "inactivity", NULL);
plugin->print (plugin, NULL, NULL,
"WeeChat version %s, you are %s on freenode "
"(inactive for %s seconds)",
version, nick, inactivity);
if (version)
free (version);
if (nick)
free (nick);
if (inactivity)
free (inactivity);
Prototype: t_plugin_info_dcc *get_dcc_info (t_weechat_plugin *plugin)
Return list of DCC currently active or finished.
Arguments:
plugin: pointer to plugin structure
Return value: linked list of DCC.
| Type | Field | Description |
|---|---|---|
| char * | server | IRC server |
| char * | channel | IRC channel |
| int | type | DCC type: 0 = chat received, 1 = chat sent, 2 = file received, 3 = file sent |
| int* | status | DCC status: 0 = waiting, 1 = connecting, 2 = active, 3 = finished, 4 = failed, 5 = interrupted by user |
| time_t | start_time | date/time of DCC creation |
| time_t | start_transfer | date/time of DCC transfer start |
| unsigned long | addr | IP address of remote user |
| int | port | port used for DCC |
| char * | nick | remote nick |
| char * | filename | file name |
| char * | local_filename | local file name |
| int | filename_suffix | suffix if renaming file |
| unsigned long | size | file size |
| unsigned long | pos | position in file |
| unsigned long | start_resume | start position after interruption |
| unsigned long | bytes_per_sec | number of bytes per second since transfer start |
| t_plugin_dcc_info * | prev_dcc | pointer to previous DCC info |
| t_plugin_dcc_info * | next_dcc | pointer to next DCC info |
Note: result has to be free by a call to "free_dcc_info" function after use.
Examples:
t_plugin_dcc_info *dcc_info = plugin->get_dcc_info (plugin);
for (ptr_dcc = dcc_info; ptr_dcc; ptr_dcc = ptr_dcc->next_dcc)
{
plugin->print_server (plugin, "DCC type=%d, with: %s",
ptr_dcc->type, ptr_dcc->nick);
}
if (dcc_info)
plugin->free_dcc_info (plugin, dcc_info);
Prototype: void free_dcc_info (t_weechat_plugin *plugin, t_plugin_dcc_info *dcc_info)
Free memory used by a DCC list.
Arguments:
plugin: pointer to plugin structure
dcc_info: pointer to DCC list returned by
"get_dcc_info" function
Return value: none.
Example:
plugin->free_dcc_info (plugin, dcc_info);
Prototype: t_plugin_server_info *get_server_info (t_weechat_plugin *plugin)
Return list of IRC servers (connected or not).
Arguments:
plugin: pointer to plugin structure
Return value: linked list of IRC servers.
| Type | Field | Description |
|---|---|---|
| char * | name | server internal name |
| int | autoconnect | 1 if autoconnect at start-up, 0 otherwise |
| int | autoreconnect | 1 if autoreconnect when disconnected, 0 otherwise |
| int | autoreconnect_delay | delay before trying again connection |
| int | command_line | 1 if server was on command line (so it is temporary), 0 otherwise |
| char * | address | server address (host or IP) |
| int | port | port |
| int | ipv6 | IPv6 connection |
| int | ssl | SSL connection |
| char * | password | server password |
| char * | nick1 | first nickname |
| char * | nick2 | alternate nickname |
| char * | nick3 | second alternate nickname |
| char * | username | user name |
| char * | real name | real name |
| char * | command | command run once connected |
| int | command_delay | delay after execution of command |
| char * | autojoin | channels joined automatically |
| int | autorejoin | 1 if channels are rejoined when kicked, 0 otherwise |
| char * | notify_levels | channels notify levels |
| char * | charset_decode_iso | channels charsets for decoding ISO |
| char * | charset_decode_utf | channels charsets for decoding UTF |
| char * | charset_encode | channels charsets for encoding messages |
| int | is_connected | 1 if connected to server, 0 otherwise |
| int | ssl_connected | 1 if connected with SSL, 0 otherwise |
| char * | nick | current nickname |
| int | is_away | 1 if away, 0 otherwise |
| time_t | away_time | time when user is marking as away |
| int | lag | lag (in milliseconds) |
| t_plugin_server_info * | prev_server | pointer to previous server info |
| t_plugin_server_info * | next_server | pointer to next server info |
Note: result has to be free by a call to "free_server_info" function after use.
Example:
t_plugin_server_info *server_info, *ptr_server_info;
server_info = plugin->get_server_info (plugin);
if (server_info)
{
for (ptr_server_info = server_info; ptr_server_info;
ptr_server_info = ptr_server_info->next_server)
{
plugin->print (plugin, NULL, NULL,
"server: %s, address: %s, port: %d %s",
ptr_server_info->name,
ptr_server_info->address,
ptr_server_info->port,
(ptr_server_info->is_connected) ? "(connected)" : "");
}
plugin->free_server_info (plugin, server_info);
}
Prototype: void free_server_info (t_weechat_plugin *plugin, t_plugin_server_info *server_info)
Free memory used by server info list.
Arguments:
plugin: pointer to plugin structure
server_info: pointer to server list
returned by "get_server_info" function
Return value: none.
Example:
plugin->free_server_info (plugin, server_info);
Prototype: t_plugin_channel_info *get_channel_info (t_weechat_plugin *plugin, char *server)
Return list of IRC channels for a server.
Arguments:
plugin: pointer to plugin structure
server: internal server name
Return value: linked list of IRC channels for server.
| Type | Field | Description |
|---|---|---|
| int | type | 0 for a channel, 1 for a private |
| char * | name | name of channel |
| char * | topic | topic of channel |
| char * | modes | channel modes |
| int | limit | user limit |
| char * | key | channel key |
| int | nicks_count | number of nicks on channel |
| t_plugin_channel_info * | prev_channel | pointer to previous channel info |
| t_plugin_channel_info * | next_channel | pointer to next channel info |
Note: result has to be free by a call to "free_channel_info" function after use.
Example:
t_plugin_channel_info *channel_info, *ptr_chan_info;
channel_info = plugin->get_channel_info (plugin, "freenode");
if (channel_info)
{
for (ptr_chan_info = channel_info; ptr_chan_info;
ptr_chan_info = ptr_chan_info->next_channel)
{
plugin->print (plugin, NULL, NULL,
" %s (type %d)",
ptr_chan_info->name,
ptr_chan_info->type);
}
plugin->free_channel_info (plugin, channel_info);
}
Prototype: void free_channel_info (t_weechat_plugin *plugin, t_plugin_channel_info *channel_info)
Free memory used by channel info list.
Arguments:
plugin: pointer to plugin structure
channel_info: pointer to channel info list
returned by "get_channel_info" function
Return value: none.
Example:
plugin->free_channel_info (plugin, channel_info);
Prototype: t_plugin_nick_info *get_nick_info (t_weechat_plugin *plugin, char *server, char *channel)
Return list of nicks for a channel.
Arguments:
plugin: pointer to plugin structure
server: internal server name
channel: channel name
Return value: linked list of nicks on channel.
| Type | Field | Description |
|---|---|---|
| char * | nick | nick name |
| char * | host | hostname |
| int | flags | nick flags, binary "or" between values (1 = channel owner, 2 = channel admin, 4 = op, 8 = halfop, 16 = voice, 32 = away) |
| t_plugin_nick_info * | prev_nick | pointer to previous nick info |
| t_plugin_nick_info * | next_nick | pointer to next nick info |
Note: result has to be free by a call to "free_nick_info" function after use.
Example:
t_plugin_nick_info *nick_info, *ptr_nick_info;
nick_info = plugin->get_nick_info (plugin, "freenode", "#weechat");
if (nick_info)
{
for (ptr_nick_info = nick_info; ptr_nick_info;
ptr_nick_info = ptr_nick_info->next_nick)
{
plugin->print (plugin, NULL, NULL,
" %s (flags: %d)",
ptr_nick_info->nick,
ptr_nick_info->flags);
}
plugin->free_nick_info (plugin, nick_info);
}
Prototype: void free_nick_info (t_weechat_plugin *plugin, t_plugin_nick_info *nick_info)
Free memory used by nick info list.
Arguments:
plugin: pointer to plugin structure
nick_info: pointer to nick info list
returned by "get_nick_info" function
Return value: none.
Example:
plugin->free_nick_info (plugin, nick_info);
Prototype: char *get_config (t_weechat_plugin *plugin, char *option)
Return value of a WeeChat config option.
Arguments:
plugin: pointer to plugin structure
option: name of option to read
Return value: option value, NULL if not found.
Note: result has to be free by a call to "free" function after use.
Examples:
char *value1 = plugin->get_config (plugin, "look_set_title"); char *value2 = plugin->get_config (plugin, "freenode.server_autojoin");
Prototype: int set_config (t_weechat_plugin *plugin, char *option, char *value)
Update value of a WeeChat config option.
Arguments:
plugin: pointer to plugin structure
option: name of option to update
value: new value for option
Return value: 1 if option was successfully updated, 0 if an error occurred.
Example:
plugin->set_config (plugin, "look_nicklist", "off");
Prototype: char *get_plugin_config (t_weechat_plugin *plugin, char *option)
Return value of a plugin option.
Option is read from file "~/.weechat/plugins.rc"
and is like: "plugin.option=value"
(note: plugin name is automatically added).
Arguments:
plugin: pointer to plugin structure
option: name of option to read
Return value: option value, NULL if not found.
Note: result has to be free by a call to "free" function after use.
Example:
char *value = plugin->get_plugin_config (plugin, "my_var");
Prototype: int set_plugin_config (t_weechat_plugin *plugin, char *option, char *value)
Update value of a plugin option.
Option is written in file "~/.weechat/plugins.rc"
and is like: "plugin.option=value"
(note: plugin name is automatically added).
Arguments:
plugin: pointer to plugin structure
option: name of option to update
value: new value for option
Return value: 1 if option was successfully updated, 0 if an error occurred.
Example :
plugin->set_plugin_config (plugin, "my_var", "value");