2014-02-02 09:49:59 +01:00
|
|
|
= WeeChat scripting guide
|
2014-01-23 18:38:53 +01:00
|
|
|
:author: Sébastien Helleu
|
|
|
|
:email: flashcode@flashtux.org
|
|
|
|
:lang: en
|
2016-05-03 21:31:55 +02:00
|
|
|
:toc: left
|
2019-10-12 22:21:48 +02:00
|
|
|
:toclevels: 4
|
2016-05-04 23:12:35 +02:00
|
|
|
:sectnums:
|
2019-10-12 22:21:48 +02:00
|
|
|
:sectnumlevels: 3
|
2016-05-03 21:31:55 +02:00
|
|
|
:docinfo1:
|
2009-05-28 16:07:40 +02:00
|
|
|
|
|
|
|
|
|
|
|
This manual documents WeeChat chat client, it is part of WeeChat.
|
|
|
|
|
|
|
|
Latest version of this document can be found on this page:
|
2014-12-13 09:16:09 +01:00
|
|
|
https://weechat.org/doc
|
2009-05-28 16:07:40 +02:00
|
|
|
|
|
|
|
|
|
|
|
[[introduction]]
|
2013-11-04 21:41:34 +01:00
|
|
|
== Introduction
|
2009-05-28 16:07:40 +02:00
|
|
|
|
|
|
|
WeeChat (Wee Enhanced Environment for Chat) is a free chat client, fast and
|
|
|
|
light, designed for many operating systems.
|
|
|
|
|
2011-10-26 19:25:51 +02:00
|
|
|
This manual documents way to write scripts for WeeChat, using one of supported
|
|
|
|
script languages:
|
|
|
|
|
2017-09-03 14:35:00 +02:00
|
|
|
* Python
|
|
|
|
* Perl
|
|
|
|
* Ruby
|
|
|
|
* Lua
|
|
|
|
* Tcl
|
|
|
|
* Guile (Scheme)
|
2017-09-23 16:24:52 +02:00
|
|
|
* JavaScript
|
2017-09-03 14:35:00 +02:00
|
|
|
* PHP
|
2009-05-28 16:07:40 +02:00
|
|
|
|
|
|
|
[NOTE]
|
|
|
|
Almost all examples in this doc are written in Python, but API is the same for
|
|
|
|
other languages.
|
|
|
|
|
|
|
|
[[scripts_in_weechat]]
|
2013-11-04 21:41:34 +01:00
|
|
|
== Scripts in WeeChat
|
2009-05-28 16:07:40 +02:00
|
|
|
|
2019-05-12 09:25:45 +02:00
|
|
|
[[weechat_architecture]]
|
|
|
|
=== WeeChat architecture
|
|
|
|
|
|
|
|
WeeChat is single-threaded, and this applies to scripts as well.
|
|
|
|
|
|
|
|
The code of a script is executed:
|
|
|
|
|
|
|
|
* when the script is loaded: typically a call to the
|
|
|
|
<<register_function,register function>>
|
|
|
|
* when a hook callback is called by WeeChat (see the chapter <<hooks,Hooks>>).
|
|
|
|
|
|
|
|
When the code of a script is executed, WeeChat waits for the end of execution
|
|
|
|
before going on. Therefore the script must *NOT* do blocking operations like
|
2020-04-25 00:12:51 +02:00
|
|
|
network calls without using a dedicated API function like `+hook_process+`.
|
2019-05-12 09:25:45 +02:00
|
|
|
|
|
|
|
[IMPORTANT]
|
|
|
|
A script must *NEVER* fork or create threads without using a dedicated API
|
|
|
|
function, this can crash WeeChat. +
|
2020-04-25 00:12:51 +02:00
|
|
|
If something must be run in background, the function `+hook_process+` can be used.
|
2019-05-12 09:25:45 +02:00
|
|
|
See example in the chapter <<hook_process,Run a background process>>
|
2020-04-25 00:12:51 +02:00
|
|
|
and the documentation on the function `+hook_process+` in the
|
2019-05-12 09:25:45 +02:00
|
|
|
link:weechat_plugin_api.en.html#_hook_process[WeeChat plugin API reference].
|
|
|
|
|
2014-01-29 22:37:33 +01:00
|
|
|
[[languages_specificities]]
|
2013-11-04 21:41:34 +01:00
|
|
|
=== Languages specificities
|
2009-05-28 16:07:40 +02:00
|
|
|
|
2013-11-04 21:41:34 +01:00
|
|
|
==== Python
|
2009-05-28 16:07:40 +02:00
|
|
|
|
2019-10-12 22:21:48 +02:00
|
|
|
===== Module
|
|
|
|
|
|
|
|
WeeChat defines a `weechat` module which must be imported with `import weechat`.
|
|
|
|
|
|
|
|
===== Functions
|
|
|
|
|
2020-04-25 00:12:51 +02:00
|
|
|
Functions are called with `+weechat.xxx(arg1, arg2, ...)+`.
|
2019-10-12 22:21:48 +02:00
|
|
|
|
|
|
|
Functions `+print*+` are called `+prnt*+` in python (because `print` was a
|
|
|
|
reserved keyword in Python 2).
|
|
|
|
|
|
|
|
===== Strings received in callbacks
|
|
|
|
|
|
|
|
In Python 3 and with WeeChat ≥ 2.7, the strings received in callbacks have type
|
|
|
|
`str` if the string has valid UTF-8 data (which is the most common case),
|
|
|
|
or `bytes` if the string is not UTF-8 valid. So the callback should take care
|
|
|
|
about this type if some invalid UTF-8 content can be received.
|
|
|
|
|
|
|
|
Some invalid UTF-8 data may be received in these cases, so the callback can
|
|
|
|
receive a string of type `str` or `bytes` (this list is not exhaustive):
|
|
|
|
|
|
|
|
[width="100%",cols="3m,3m,3m,8",options="header"]
|
|
|
|
|===
|
|
|
|
| API function | Arguments | Examples | Description
|
|
|
|
|
|
|
|
| hook_modifier |
|
|
|
|
irc_in_yyy |
|
|
|
|
pass:[irc_in_privmsg] +
|
|
|
|
pass:[irc_in_notice] |
|
|
|
|
A message received in IRC plugin, before it is decoded to UTF-8 (used
|
|
|
|
internally). +
|
|
|
|
+
|
2020-04-25 00:12:51 +02:00
|
|
|
It is recommended to use modifier `+irc_in2_yyy+` instead, the string received
|
2019-10-12 22:21:48 +02:00
|
|
|
is always UTF-8 valid. +
|
2020-04-25 00:12:51 +02:00
|
|
|
See function `+hook_modifier+` in the
|
2019-10-12 22:21:48 +02:00
|
|
|
link:weechat_plugin_api.en.html#_hook_modifier[WeeChat plugin API reference].
|
|
|
|
|
|
|
|
| hook_signal |
|
|
|
|
xxx,irc_out_yyy +
|
|
|
|
xxx,irc_outtags_yyy |
|
|
|
|
pass:[*,irc_out_privmsg] +
|
|
|
|
pass:[*,irc_out_notice] +
|
|
|
|
pass:[*,irc_outtags_privmsg] +
|
|
|
|
pass:[*,irc_outtags_notice] |
|
|
|
|
A message sent by IRC plugin, after it is encoded to the `encode` charset
|
|
|
|
defined by the user (if different from the default `UTF-8`). +
|
|
|
|
+
|
2020-04-25 00:12:51 +02:00
|
|
|
It is recommended to use signal `+xxx,irc_out1_yyy+` instead, the string received
|
2019-10-12 22:21:48 +02:00
|
|
|
is always UTF-8 valid. +
|
2020-04-25 00:12:51 +02:00
|
|
|
See function `+hook_signal+` in the
|
2019-10-12 22:21:48 +02:00
|
|
|
link:weechat_plugin_api.en.html#_hook_signal[WeeChat plugin API reference].
|
|
|
|
|
|
|
|
| hook_process +
|
|
|
|
hook_process_hashtable |
|
|
|
|
- |
|
|
|
|
- |
|
|
|
|
Output of the command, sent to the callback, can contain invalid UTF-8 data.
|
|
|
|
|
|
|
|
|===
|
|
|
|
|
|
|
|
In Python 2, which is now deprecated and should not be used any more, the
|
2019-10-13 08:18:30 +02:00
|
|
|
strings sent to callbacks are always of type `str`, and may contain invalid
|
2019-10-12 22:21:48 +02:00
|
|
|
UTF-8 data, in the cases mentioned above.
|
2011-10-26 19:25:51 +02:00
|
|
|
|
2013-11-04 21:41:34 +01:00
|
|
|
==== Perl
|
2011-10-26 19:25:51 +02:00
|
|
|
|
2019-10-12 22:21:48 +02:00
|
|
|
===== Functions
|
|
|
|
|
2020-04-25 00:12:51 +02:00
|
|
|
Functions are called with `+weechat::xxx(arg1, arg2, ...);+`.
|
2011-10-26 19:25:51 +02:00
|
|
|
|
2013-11-04 21:41:34 +01:00
|
|
|
==== Ruby
|
2011-10-26 19:25:51 +02:00
|
|
|
|
2019-10-12 22:21:48 +02:00
|
|
|
===== Initialization
|
|
|
|
|
|
|
|
You have to define _weechat_init_ and call _register_ inside.
|
|
|
|
|
|
|
|
===== Functions
|
|
|
|
|
2020-04-25 00:12:51 +02:00
|
|
|
Functions are called with `+Weechat.xxx(arg1, arg2, ...)+`.
|
2019-10-12 22:21:48 +02:00
|
|
|
|
|
|
|
Due to a limitation of Ruby (15 arguments max by function), the function
|
2020-04-25 00:12:51 +02:00
|
|
|
`+Weechat.config_new_option+` receives the callbacks in an array of 6 strings
|
2019-10-12 22:21:48 +02:00
|
|
|
(3 callbacks + 3 data strings), so a call to this function looks like:
|
2013-03-22 19:54:44 +01:00
|
|
|
|
|
|
|
[source,ruby]
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2013-03-22 19:54:44 +01:00
|
|
|
Weechat.config_new_option(config, section, "name", "string", "description of option", "", 0, 0,
|
|
|
|
"value", "value", 0, ["check_cb", "", "change_cb", "", "delete_cb", ""])
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2011-10-26 19:25:51 +02:00
|
|
|
|
2020-06-21 18:59:54 +02:00
|
|
|
And the function `+Weechat.bar_new+` receives the colors in an array of 4 strings
|
|
|
|
(color_fg, color_delim, color_bg, color_bg_inactive), so a call to this function
|
|
|
|
looks like:
|
|
|
|
|
|
|
|
[source,ruby]
|
|
|
|
----
|
|
|
|
Weechat.bar_new("name", "off", "0", "window", "", "left", "vertical", "vertical", "0", "0",
|
|
|
|
["default", "default", "default", "default"], "0", "items")
|
|
|
|
----
|
|
|
|
|
2013-11-04 21:41:34 +01:00
|
|
|
==== Lua
|
2011-10-26 19:25:51 +02:00
|
|
|
|
2019-10-12 22:21:48 +02:00
|
|
|
===== Functions
|
|
|
|
|
2020-04-25 00:12:51 +02:00
|
|
|
Functions are called with `+weechat.xxx(arg1, arg2, ...)+`.
|
2011-10-26 19:25:51 +02:00
|
|
|
|
2013-11-04 21:41:34 +01:00
|
|
|
==== Tcl
|
2011-10-26 19:25:51 +02:00
|
|
|
|
2019-10-12 22:21:48 +02:00
|
|
|
===== Functions
|
|
|
|
|
2020-04-25 00:12:51 +02:00
|
|
|
Functions are called with `+weechat::xxx arg1 arg2 ...+`.
|
2011-10-26 19:25:51 +02:00
|
|
|
|
2017-09-03 14:35:00 +02:00
|
|
|
==== Guile (Scheme)
|
2011-10-26 19:25:51 +02:00
|
|
|
|
2019-10-12 22:21:48 +02:00
|
|
|
===== Functions
|
|
|
|
|
2020-04-25 00:12:51 +02:00
|
|
|
Functions are called with `+(weechat:xxx arg1 arg2 ...)+`.
|
2019-10-12 22:21:48 +02:00
|
|
|
|
|
|
|
The following functions take one list of arguments (instead of many arguments
|
|
|
|
for other functions), because number of arguments exceed number of allowed
|
|
|
|
arguments in Guile:
|
|
|
|
|
|
|
|
* config_new_section
|
|
|
|
* config_new_option
|
|
|
|
* bar_new
|
2009-05-28 16:07:40 +02:00
|
|
|
|
2017-09-23 16:24:52 +02:00
|
|
|
==== JavaScript
|
2015-03-07 15:16:37 +01:00
|
|
|
|
2019-10-12 22:21:48 +02:00
|
|
|
===== Functions
|
|
|
|
|
2020-04-25 00:12:51 +02:00
|
|
|
Functions are called with `+weechat.xxx(arg1, arg2, ...);+`.
|
2015-03-07 15:16:37 +01:00
|
|
|
|
2017-09-03 14:35:00 +02:00
|
|
|
==== PHP
|
|
|
|
|
2019-10-12 22:21:48 +02:00
|
|
|
===== Functions
|
|
|
|
|
2020-04-25 00:12:51 +02:00
|
|
|
Functions are called with `+weechat_xxx(arg1, arg2, ...);+`.
|
2017-09-03 14:35:00 +02:00
|
|
|
|
2010-03-07 22:23:44 +01:00
|
|
|
[[register_function]]
|
2013-11-04 21:41:34 +01:00
|
|
|
=== Register function
|
2009-05-28 16:07:40 +02:00
|
|
|
|
|
|
|
All WeeChat scripts must "register" themselves to WeeChat, and this must be
|
|
|
|
first WeeChat function called in script.
|
|
|
|
|
2009-06-28 20:47:13 +02:00
|
|
|
Prototype:
|
2009-05-28 16:07:40 +02:00
|
|
|
|
|
|
|
[source,python]
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2009-05-28 16:07:40 +02:00
|
|
|
weechat.register(name, author, version, license, description, shutdown_function, charset)
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2009-05-28 16:07:40 +02:00
|
|
|
|
|
|
|
Arguments:
|
|
|
|
|
2016-05-04 22:19:27 +02:00
|
|
|
* _name_: string, internal name of script
|
|
|
|
* _author_: string, author name
|
|
|
|
* _version_: string, script version
|
|
|
|
* _license_: string, script license
|
|
|
|
* _description_: string, short description of script
|
|
|
|
* _shutdown_function_: string, name of function called when script is unloaded
|
2012-11-05 22:04:49 +01:00
|
|
|
(can be empty string)
|
2016-05-04 22:19:27 +02:00
|
|
|
* _charset_: string, script charset (if your script is UTF-8, you can use blank
|
2012-11-05 22:04:49 +01:00
|
|
|
value here, because UTF-8 is default charset)
|
2009-05-28 16:07:40 +02:00
|
|
|
|
2009-06-28 20:47:13 +02:00
|
|
|
Example of script, for each language:
|
2009-05-28 16:07:40 +02:00
|
|
|
|
2015-03-09 21:12:02 +01:00
|
|
|
* Python:
|
2009-05-28 16:07:40 +02:00
|
|
|
|
|
|
|
[source,python]
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2009-05-28 16:07:40 +02:00
|
|
|
import weechat
|
|
|
|
|
|
|
|
weechat.register("test_python", "FlashCode", "1.0", "GPL3", "Test script", "", "")
|
|
|
|
weechat.prnt("", "Hello, from python script!")
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2009-05-28 16:07:40 +02:00
|
|
|
|
2015-03-09 21:12:02 +01:00
|
|
|
* Perl:
|
2011-10-26 19:25:51 +02:00
|
|
|
|
|
|
|
[source,perl]
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2011-10-26 19:25:51 +02:00
|
|
|
weechat::register("test_perl", "FlashCode", "1.0", "GPL3", "Test script", "", "");
|
|
|
|
weechat::print("", "Hello, from perl script!");
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2011-10-26 19:25:51 +02:00
|
|
|
|
2015-03-09 21:12:02 +01:00
|
|
|
* Ruby:
|
2009-05-28 16:07:40 +02:00
|
|
|
|
|
|
|
[source,ruby]
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2009-05-28 16:07:40 +02:00
|
|
|
def weechat_init
|
|
|
|
Weechat.register("test_ruby", "FlashCode", "1.0", "GPL3", "Test script", "", "")
|
|
|
|
Weechat.print("", "Hello, from ruby script!")
|
|
|
|
return Weechat::WEECHAT_RC_OK
|
|
|
|
end
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2009-05-28 16:07:40 +02:00
|
|
|
|
2015-03-09 21:12:02 +01:00
|
|
|
* Lua:
|
2009-05-28 16:07:40 +02:00
|
|
|
|
|
|
|
[source,lua]
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2009-05-28 16:07:40 +02:00
|
|
|
weechat.register("test_lua", "FlashCode", "1.0", "GPL3", "Test script", "", "")
|
|
|
|
weechat.print("", "Hello, from lua script!")
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2009-05-28 16:07:40 +02:00
|
|
|
|
2015-03-09 21:12:02 +01:00
|
|
|
* Tcl:
|
2009-05-28 16:07:40 +02:00
|
|
|
|
2011-10-26 19:25:51 +02:00
|
|
|
[source,tcl]
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2009-05-28 16:07:40 +02:00
|
|
|
weechat::register "test_tcl" "FlashCode" "1.0" "GPL3" "Test script" "" ""
|
|
|
|
weechat::print "" "Hello, from tcl script!"
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2009-05-28 16:07:40 +02:00
|
|
|
|
2017-09-03 14:35:00 +02:00
|
|
|
* Guile (Scheme):
|
2011-10-26 19:25:51 +02:00
|
|
|
|
|
|
|
[source,lisp]
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2011-10-26 19:25:51 +02:00
|
|
|
(weechat:register "test_scheme" "FlashCode" "1.0" "GPL3" "Test script" "" "")
|
|
|
|
(weechat:print "" "Hello, from scheme script!")
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2011-10-26 19:25:51 +02:00
|
|
|
|
2017-09-23 16:24:52 +02:00
|
|
|
* JavaScript:
|
2015-03-07 15:16:37 +01:00
|
|
|
|
|
|
|
[source,javascript]
|
|
|
|
----
|
|
|
|
weechat.register("test_js", "FlashCode", "1.0", "GPL3", "Test script", "", "");
|
|
|
|
weechat.print("", "Hello, from javascript script!");
|
|
|
|
----
|
|
|
|
|
2017-09-03 14:35:00 +02:00
|
|
|
* PHP:
|
|
|
|
|
|
|
|
[source,php]
|
|
|
|
----
|
2017-09-09 15:20:38 +02:00
|
|
|
weechat_register('test_php', 'FlashCode', '1.0', 'GPL3', 'Test script', '', '');
|
|
|
|
weechat_print('', 'Hello, from PHP script!');
|
2017-09-03 14:35:00 +02:00
|
|
|
----
|
|
|
|
|
2009-05-28 16:07:40 +02:00
|
|
|
[[load_script]]
|
2013-11-04 21:41:34 +01:00
|
|
|
=== Load script
|
2009-05-28 16:07:40 +02:00
|
|
|
|
2013-01-26 07:48:20 +01:00
|
|
|
It is recommended to use the "script" plugin to load scripts, for example:
|
|
|
|
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2013-01-26 07:48:20 +01:00
|
|
|
/script load script.py
|
|
|
|
/script load script.pl
|
|
|
|
/script load script.rb
|
|
|
|
/script load script.lua
|
|
|
|
/script load script.tcl
|
|
|
|
/script load script.scm
|
2015-03-07 15:16:37 +01:00
|
|
|
/script load script.js
|
2017-09-03 14:35:00 +02:00
|
|
|
/script load script.php
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2013-01-26 07:48:20 +01:00
|
|
|
|
|
|
|
Each language has also its own command:
|
2009-05-28 16:07:40 +02:00
|
|
|
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2015-03-07 15:16:37 +01:00
|
|
|
/python load script.py
|
|
|
|
/perl load script.pl
|
|
|
|
/ruby load script.rb
|
|
|
|
/lua load script.lua
|
|
|
|
/tcl load script.tcl
|
|
|
|
/guile load script.scm
|
|
|
|
/javascript load script.js
|
2017-09-03 14:35:00 +02:00
|
|
|
/php load script.php
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2009-05-28 16:07:40 +02:00
|
|
|
|
2016-05-04 22:19:27 +02:00
|
|
|
You can make link in directory _language/autoload_ to autoload script when
|
2009-05-28 16:07:40 +02:00
|
|
|
WeeChat is starting.
|
|
|
|
|
2010-03-07 22:23:44 +01:00
|
|
|
For example with Python:
|
2009-05-28 16:07:40 +02:00
|
|
|
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2021-05-08 20:56:49 +02:00
|
|
|
$ cd ~/.local/share/weechat/python/autoload
|
2010-03-07 22:23:44 +01:00
|
|
|
$ ln -s ../script.py
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2009-05-28 16:07:40 +02:00
|
|
|
|
2013-01-26 07:48:20 +01:00
|
|
|
[NOTE]
|
2016-05-04 22:19:27 +02:00
|
|
|
When installing a script with command `/script install` the link in _autoload_
|
2013-01-26 07:48:20 +01:00
|
|
|
directory is automatically created.
|
|
|
|
|
2009-10-09 15:46:29 +02:00
|
|
|
[[differences_with_c_api]]
|
2013-11-04 21:41:34 +01:00
|
|
|
== Differences with C API
|
2009-05-28 16:07:40 +02:00
|
|
|
|
|
|
|
Script API is almost the same as C plugin API.
|
2017-08-21 23:35:04 +02:00
|
|
|
You can look at link:weechat_plugin_api.en.html[WeeChat plugin API reference]
|
|
|
|
for detail about each function in API: prototype, arguments, return values, examples.
|
2009-05-28 16:07:40 +02:00
|
|
|
|
2016-05-04 22:19:27 +02:00
|
|
|
It's important to make difference between a _plugin_ and a _script_: a
|
|
|
|
_plugin_ is a binary file compiled and loaded with command `/plugin`, whereas
|
|
|
|
a _script_ is a text file loaded with a plugin like _python_ with command
|
2010-03-07 22:23:44 +01:00
|
|
|
`/python`.
|
2009-05-28 16:07:40 +02:00
|
|
|
|
2016-05-04 22:19:27 +02:00
|
|
|
When your script _test.py_ calls a WeeChat API function, path is like that:
|
2009-05-28 16:07:40 +02:00
|
|
|
|
2013-11-04 21:41:34 +01:00
|
|
|
....
|
2013-01-26 11:42:02 +01:00
|
|
|
┌──────────────────────┐ ╔══════════════════╗
|
|
|
|
│ python plugin │ ║ WeeChat "core" ║
|
|
|
|
├────────────┬─────────┤ ╟─────────┐ ║
|
|
|
|
test.py ─────► │ script API │ C API │ ─────► ║ C API │ ║
|
|
|
|
└────────────┴─────────┘ ╚═════════╧════════╝
|
2013-11-04 21:41:34 +01:00
|
|
|
....
|
2009-05-28 16:07:40 +02:00
|
|
|
|
2016-05-04 22:19:27 +02:00
|
|
|
When WeeChat calls a callback in your script _test.py_, it's reverse of
|
2009-05-28 16:07:40 +02:00
|
|
|
previous path:
|
|
|
|
|
2013-11-04 21:41:34 +01:00
|
|
|
....
|
2013-01-26 11:42:02 +01:00
|
|
|
╔══════════════════╗ ┌──────────────────────┐
|
|
|
|
║ WeeChat "core" ║ │ python plugin │
|
|
|
|
║ ┌─────────╢ ├─────────┬────────────┤
|
|
|
|
║ │ C API ║ ─────► │ C API │ script API │ ─────► test.py
|
|
|
|
╚════════╧═════════╝ └─────────┴────────────┘
|
2013-11-04 21:41:34 +01:00
|
|
|
....
|
2009-05-28 16:07:40 +02:00
|
|
|
|
2010-03-07 22:23:44 +01:00
|
|
|
[[pointers]]
|
2013-11-04 21:41:34 +01:00
|
|
|
=== Pointers
|
2009-10-09 15:46:29 +02:00
|
|
|
|
|
|
|
As you probably know, there is not really "pointers" in scripts. So when API
|
|
|
|
functions return pointer, it is converted to string for script.
|
|
|
|
|
|
|
|
For example, if function return pointer 0x1234ab56, script will get string
|
|
|
|
"0x1234ab56".
|
|
|
|
|
|
|
|
And when an API function expects a pointer in arguments, script must give that
|
|
|
|
string value. C plugin will convert it to real pointer before calling C API
|
|
|
|
function.
|
|
|
|
|
|
|
|
Empty string or "0x0" are allowed, they means NULL in C.
|
|
|
|
For example, to print data on core buffer (WeeChat main buffer), you can do:
|
|
|
|
|
|
|
|
[source,python]
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2009-10-09 15:46:29 +02:00
|
|
|
weechat.prnt("", "hi!")
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2009-10-09 15:46:29 +02:00
|
|
|
|
|
|
|
[WARNING]
|
|
|
|
In many functions, for speed reasons, WeeChat does not check if your pointer
|
|
|
|
is correct or not. It's your job to check you're giving a valid pointer,
|
|
|
|
otherwise you may see a nice crash report ;)
|
|
|
|
|
2010-03-07 22:23:44 +01:00
|
|
|
[[callbacks]]
|
2013-11-04 21:41:34 +01:00
|
|
|
=== Callbacks
|
2009-10-09 15:46:29 +02:00
|
|
|
|
|
|
|
Almost all WeeChat callbacks must return WEECHAT_RC_OK or WEECHAT_RC_ERROR
|
|
|
|
(exception is modifier callback, which returns a string).
|
|
|
|
|
2020-05-27 22:26:31 +02:00
|
|
|
C callbacks are using "callback_pointer" and "callback_data" arguments, which
|
|
|
|
are pointers. In script API, there is only "callback_data" (or "data"), and it
|
|
|
|
is a string instead of a pointer.
|
2009-10-09 15:46:29 +02:00
|
|
|
|
2013-01-26 08:22:04 +01:00
|
|
|
Example of callback, for each language:
|
|
|
|
|
2015-03-09 21:12:02 +01:00
|
|
|
* Python:
|
2009-10-09 15:46:29 +02:00
|
|
|
|
|
|
|
[source,python]
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2013-01-26 08:22:04 +01:00
|
|
|
def timer_cb(data, remaining_calls):
|
|
|
|
weechat.prnt("", "timer! data=%s" % data)
|
|
|
|
return weechat.WEECHAT_RC_OK
|
|
|
|
|
|
|
|
weechat.hook_timer(1000, 0, 1, "timer_cb", "test")
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2013-01-26 08:22:04 +01:00
|
|
|
|
2015-03-09 21:12:02 +01:00
|
|
|
* Perl:
|
2013-01-26 08:22:04 +01:00
|
|
|
|
|
|
|
[source,perl]
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2013-01-26 08:22:04 +01:00
|
|
|
sub timer_cb {
|
|
|
|
my ($data, $remaining_calls) = @_;
|
|
|
|
weechat::print("", "timer! data=$data");
|
|
|
|
return weechat::WEECHAT_RC_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
weechat::hook_timer(1000, 0, 1, "timer_cb", "test");
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2013-01-26 08:22:04 +01:00
|
|
|
|
2015-03-09 21:12:02 +01:00
|
|
|
* Ruby:
|
2013-01-26 08:22:04 +01:00
|
|
|
|
|
|
|
[source,ruby]
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2013-01-26 08:22:04 +01:00
|
|
|
def timer_cb(data, remaining_calls)
|
|
|
|
Weechat.print("", "timer! data=#{data}");
|
|
|
|
return Weechat::WEECHAT_RC_OK
|
|
|
|
end
|
|
|
|
|
|
|
|
Weechat.hook_timer(1000, 0, 1, "timer_cb", "test");
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2009-10-09 15:46:29 +02:00
|
|
|
|
2015-03-09 21:12:02 +01:00
|
|
|
* Lua:
|
2013-01-26 08:22:04 +01:00
|
|
|
|
|
|
|
[source,lua]
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2013-01-26 08:22:04 +01:00
|
|
|
function timer_cb(data, remaining_calls)
|
|
|
|
weechat.print("", "timer! data="..data)
|
2013-03-24 19:56:43 +01:00
|
|
|
return weechat.WEECHAT_RC_OK
|
2013-01-26 08:22:04 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
weechat.hook_timer(1000, 0, 1, "timer_cb", "test")
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2013-01-26 08:22:04 +01:00
|
|
|
|
2015-03-09 21:12:02 +01:00
|
|
|
* Tcl:
|
2013-01-26 08:22:04 +01:00
|
|
|
|
|
|
|
[source,tcl]
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2013-01-26 08:22:04 +01:00
|
|
|
proc timer_cb { data remaining_calls } {
|
|
|
|
weechat::print {} "timer! data=$data"
|
|
|
|
return $::weechat::WEECHAT_RC_OK
|
|
|
|
}
|
|
|
|
|
|
|
|
weechat::hook_timer 1000 0 1 timer_cb test
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2013-01-26 08:22:04 +01:00
|
|
|
|
2017-09-03 14:35:00 +02:00
|
|
|
* Guile (Scheme):
|
2013-01-26 08:22:04 +01:00
|
|
|
|
|
|
|
[source,lisp]
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2013-02-19 22:49:59 +01:00
|
|
|
(define (timer_cb data remaining_calls)
|
|
|
|
(weechat:print "" (string-append "timer! data=" data))
|
2013-01-26 08:22:04 +01:00
|
|
|
weechat:WEECHAT_RC_OK
|
|
|
|
)
|
|
|
|
|
|
|
|
(weechat:hook_timer 1000 0 1 "timer_cb" "test")
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2009-10-09 15:46:29 +02:00
|
|
|
|
2017-09-23 16:24:52 +02:00
|
|
|
* JavaScript:
|
2015-03-07 15:16:37 +01:00
|
|
|
|
|
|
|
[source,javascript]
|
|
|
|
----
|
|
|
|
function timer_cb(data, remaining_calls) {
|
|
|
|
weechat.print("", "timer! data=" + data);
|
|
|
|
return weechat.WEECHAT_RC_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
weechat.hook_timer(1000, 0, 1, "timer_cb", "test");
|
|
|
|
----
|
|
|
|
|
2017-09-03 14:35:00 +02:00
|
|
|
* PHP:
|
|
|
|
|
|
|
|
[source,php]
|
|
|
|
----
|
2017-09-09 15:20:38 +02:00
|
|
|
$timer_cb = function ($data, $remaining_calls) {
|
|
|
|
weechat_print('', 'timer! data=' . $data);
|
2017-09-03 14:35:00 +02:00
|
|
|
return WEECHAT_RC_OK;
|
2017-09-09 15:20:38 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
weechat_hook_timer(1000, 0, 1, $timer_cb, 'test');
|
2017-09-03 14:35:00 +02:00
|
|
|
----
|
|
|
|
|
2009-10-09 15:46:29 +02:00
|
|
|
[[script_api]]
|
2013-11-04 21:41:34 +01:00
|
|
|
== Script API
|
2009-10-09 15:46:29 +02:00
|
|
|
|
2017-08-21 23:35:04 +02:00
|
|
|
For more information about functions in API, please read the
|
|
|
|
link:weechat_plugin_api.en.html[WeeChat plugin API reference].
|
2009-10-09 15:46:29 +02:00
|
|
|
|
2010-03-07 22:23:44 +01:00
|
|
|
[[script_api_functions]]
|
2013-11-04 21:41:34 +01:00
|
|
|
=== Functions
|
2009-05-28 16:07:40 +02:00
|
|
|
|
|
|
|
List of functions in script API:
|
|
|
|
|
2020-04-18 20:38:52 +02:00
|
|
|
[width="100%",cols="1,3",options="header"]
|
2013-11-04 21:41:34 +01:00
|
|
|
|===
|
2016-05-05 10:01:02 +02:00
|
|
|
| Category | Functions
|
|
|
|
|
|
|
|
| general |
|
2010-03-07 22:23:44 +01:00
|
|
|
register
|
2016-05-05 10:01:02 +02:00
|
|
|
|
|
|
|
| plugins |
|
2010-03-07 22:23:44 +01:00
|
|
|
plugin_get_name
|
2016-05-05 10:01:02 +02:00
|
|
|
|
|
|
|
| strings |
|
|
|
|
charset_set +
|
|
|
|
iconv_to_internal +
|
|
|
|
iconv_from_internal +
|
|
|
|
gettext +
|
|
|
|
ngettext +
|
|
|
|
strlen_screen +
|
|
|
|
string_match +
|
2019-02-26 20:02:07 +01:00
|
|
|
string_match_list +
|
2016-05-05 10:01:02 +02:00
|
|
|
string_has_highlight +
|
|
|
|
string_has_highlight_regex +
|
|
|
|
string_mask_to_regex +
|
2018-04-07 13:20:58 +02:00
|
|
|
string_format_size +
|
2020-08-22 08:55:16 +02:00
|
|
|
string_color_code_size +
|
2016-05-05 10:01:02 +02:00
|
|
|
string_remove_color +
|
|
|
|
string_is_command_char +
|
|
|
|
string_input_for_buffer +
|
|
|
|
string_eval_expression +
|
|
|
|
string_eval_path_home
|
|
|
|
|
|
|
|
| directories |
|
|
|
|
mkdir_home +
|
|
|
|
mkdir +
|
|
|
|
mkdir_parents
|
|
|
|
|
|
|
|
| sorted lists |
|
|
|
|
list_new +
|
|
|
|
list_add +
|
|
|
|
list_search +
|
|
|
|
list_search_pos +
|
|
|
|
list_casesearch +
|
|
|
|
list_casesearch_pos +
|
|
|
|
list_get +
|
|
|
|
list_set +
|
|
|
|
list_next +
|
|
|
|
list_prev +
|
|
|
|
list_string +
|
|
|
|
list_size +
|
|
|
|
list_remove +
|
|
|
|
list_remove_all +
|
|
|
|
list_free
|
|
|
|
|
2010-03-07 22:23:44 +01:00
|
|
|
| configuration files |
|
2016-05-05 10:01:02 +02:00
|
|
|
config_new +
|
|
|
|
config_new_section +
|
|
|
|
config_search_section +
|
|
|
|
config_new_option +
|
|
|
|
config_search_option +
|
|
|
|
config_string_to_boolean +
|
|
|
|
config_option_reset +
|
|
|
|
config_option_set +
|
|
|
|
config_option_set_null +
|
|
|
|
config_option_unset +
|
|
|
|
config_option_rename +
|
|
|
|
config_option_is_null +
|
|
|
|
config_option_default_is_null +
|
|
|
|
config_boolean +
|
|
|
|
config_boolean_default +
|
|
|
|
config_integer +
|
|
|
|
config_integer_default +
|
|
|
|
config_string +
|
|
|
|
config_string_default +
|
|
|
|
config_color +
|
|
|
|
config_color_default +
|
|
|
|
config_write_option +
|
|
|
|
config_write_line +
|
|
|
|
config_write +
|
|
|
|
config_read +
|
|
|
|
config_reload +
|
|
|
|
config_option_free +
|
|
|
|
config_section_free_options +
|
|
|
|
config_section_free +
|
|
|
|
config_free +
|
|
|
|
config_get +
|
|
|
|
config_get_plugin +
|
|
|
|
config_is_set_plugin +
|
|
|
|
config_set_plugin +
|
|
|
|
config_set_desc_plugin +
|
|
|
|
config_unset_plugin
|
|
|
|
|
|
|
|
| key bindings |
|
|
|
|
key_bind +
|
|
|
|
key_unbind
|
|
|
|
|
|
|
|
| display |
|
|
|
|
prefix +
|
|
|
|
color +
|
|
|
|
print (for python: prnt) +
|
2017-06-11 08:20:12 +02:00
|
|
|
print_date_tags (for python: prnt_date_tags) +
|
2016-05-05 10:01:02 +02:00
|
|
|
print_y (for python: prnt_y) +
|
|
|
|
log_print
|
|
|
|
|
|
|
|
| hooks |
|
|
|
|
hook_command +
|
|
|
|
hook_command_run +
|
|
|
|
hook_timer +
|
|
|
|
hook_fd +
|
|
|
|
hook_process +
|
|
|
|
hook_process_hashtable +
|
|
|
|
hook_connect +
|
2018-08-12 21:45:00 +02:00
|
|
|
hook_line +
|
2016-05-05 10:01:02 +02:00
|
|
|
hook_print +
|
|
|
|
hook_signal +
|
|
|
|
hook_signal_send +
|
|
|
|
hook_hsignal +
|
|
|
|
hook_hsignal_send +
|
|
|
|
hook_config +
|
|
|
|
hook_completion +
|
|
|
|
hook_modifier +
|
|
|
|
hook_modifier_exec +
|
|
|
|
hook_info +
|
|
|
|
hook_info_hashtable +
|
|
|
|
hook_infolist +
|
|
|
|
hook_focus +
|
|
|
|
hook_set +
|
|
|
|
unhook +
|
2014-01-11 09:39:12 +01:00
|
|
|
unhook_all
|
2016-05-05 10:01:02 +02:00
|
|
|
|
|
|
|
| buffers |
|
|
|
|
buffer_new +
|
|
|
|
current_buffer +
|
|
|
|
buffer_search +
|
|
|
|
buffer_search_main +
|
|
|
|
buffer_clear +
|
|
|
|
buffer_close +
|
|
|
|
buffer_merge +
|
|
|
|
buffer_unmerge +
|
|
|
|
buffer_get_integer +
|
|
|
|
buffer_get_string +
|
|
|
|
buffer_get_pointer +
|
|
|
|
buffer_set +
|
|
|
|
buffer_string_replace_local_var +
|
|
|
|
buffer_match_list
|
|
|
|
|
|
|
|
| windows |
|
|
|
|
current_window +
|
|
|
|
window_search_with_buffer +
|
|
|
|
window_get_integer +
|
|
|
|
window_get_string +
|
|
|
|
window_get_pointer +
|
|
|
|
window_set_title
|
|
|
|
|
|
|
|
| nicklist |
|
|
|
|
nicklist_add_group +
|
|
|
|
nicklist_search_group +
|
|
|
|
nicklist_add_nick +
|
|
|
|
nicklist_search_nick +
|
|
|
|
nicklist_remove_group +
|
|
|
|
nicklist_remove_nick +
|
|
|
|
nicklist_remove_all +
|
|
|
|
nicklist_group_get_integer +
|
|
|
|
nicklist_group_get_string +
|
|
|
|
nicklist_group_get_pointer +
|
|
|
|
nicklist_group_set +
|
|
|
|
nicklist_nick_get_integer +
|
|
|
|
nicklist_nick_get_string +
|
|
|
|
nicklist_nick_get_pointer +
|
|
|
|
nicklist_nick_set
|
|
|
|
|
|
|
|
| bars |
|
|
|
|
bar_item_search +
|
|
|
|
bar_item_new +
|
|
|
|
bar_item_update +
|
|
|
|
bar_item_remove +
|
|
|
|
bar_search +
|
|
|
|
bar_new +
|
|
|
|
bar_set +
|
|
|
|
bar_update +
|
|
|
|
bar_remove
|
|
|
|
|
|
|
|
| commands |
|
2019-02-28 00:14:38 +01:00
|
|
|
command +
|
|
|
|
command_options
|
2016-05-05 10:01:02 +02:00
|
|
|
|
2020-04-27 00:14:36 +02:00
|
|
|
| completion |
|
|
|
|
completion_new +
|
|
|
|
completion_search +
|
2020-05-08 10:49:20 +02:00
|
|
|
completion_get_string +
|
|
|
|
completion_list_add +
|
2020-04-27 00:14:36 +02:00
|
|
|
completion_free
|
|
|
|
|
2016-05-05 10:01:02 +02:00
|
|
|
| infos |
|
|
|
|
info_get +
|
|
|
|
info_get_hashtable
|
|
|
|
|
|
|
|
| infolists |
|
|
|
|
infolist_new +
|
|
|
|
infolist_new_item +
|
|
|
|
infolist_new_var_integer +
|
|
|
|
infolist_new_var_string +
|
|
|
|
infolist_new_var_pointer +
|
|
|
|
infolist_new_var_time +
|
|
|
|
infolist_get +
|
|
|
|
infolist_next +
|
|
|
|
infolist_prev +
|
|
|
|
infolist_reset_item_cursor +
|
2017-06-11 08:20:12 +02:00
|
|
|
infolist_search_var +
|
2016-05-05 10:01:02 +02:00
|
|
|
infolist_fields +
|
|
|
|
infolist_integer +
|
|
|
|
infolist_string +
|
|
|
|
infolist_pointer +
|
|
|
|
infolist_time +
|
|
|
|
infolist_free
|
|
|
|
|
|
|
|
| hdata |
|
|
|
|
hdata_get +
|
|
|
|
hdata_get_var_offset +
|
|
|
|
hdata_get_var_type_string +
|
|
|
|
hdata_get_var_array_size +
|
|
|
|
hdata_get_var_array_size_string +
|
|
|
|
hdata_get_var_hdata +
|
|
|
|
hdata_get_list +
|
|
|
|
hdata_check_pointer +
|
|
|
|
hdata_move +
|
|
|
|
hdata_search +
|
|
|
|
hdata_char +
|
|
|
|
hdata_integer +
|
|
|
|
hdata_long +
|
|
|
|
hdata_string +
|
|
|
|
hdata_pointer +
|
|
|
|
hdata_time +
|
|
|
|
hdata_hashtable +
|
2017-06-11 08:20:12 +02:00
|
|
|
hdata_compare +
|
2016-05-05 10:01:02 +02:00
|
|
|
hdata_update +
|
|
|
|
hdata_get_string
|
|
|
|
|
|
|
|
| upgrade |
|
|
|
|
upgrade_new +
|
|
|
|
upgrade_write_object +
|
|
|
|
upgrade_read +
|
|
|
|
upgrade_close
|
2013-11-04 21:41:34 +01:00
|
|
|
|===
|
2010-03-07 22:23:44 +01:00
|
|
|
|
|
|
|
[[script_api_constants]]
|
2013-11-04 21:41:34 +01:00
|
|
|
=== Constants
|
2009-05-28 16:07:40 +02:00
|
|
|
|
|
|
|
List of constants in script API:
|
|
|
|
|
2020-04-18 20:38:52 +02:00
|
|
|
[width="100%",cols="1,3",options="header"]
|
2013-11-04 21:41:34 +01:00
|
|
|
|===
|
2016-05-05 10:01:02 +02:00
|
|
|
| Category | Constants
|
|
|
|
|
|
|
|
| return codes |
|
|
|
|
WEECHAT_RC_OK +
|
|
|
|
WEECHAT_RC_OK_EAT +
|
|
|
|
WEECHAT_RC_ERROR
|
|
|
|
|
2010-03-07 22:23:44 +01:00
|
|
|
| configuration files |
|
2016-05-05 10:01:02 +02:00
|
|
|
WEECHAT_CONFIG_READ_OK +
|
|
|
|
WEECHAT_CONFIG_READ_MEMORY_ERROR +
|
|
|
|
WEECHAT_CONFIG_READ_FILE_NOT_FOUND +
|
|
|
|
WEECHAT_CONFIG_WRITE_OK +
|
|
|
|
WEECHAT_CONFIG_WRITE_ERROR +
|
|
|
|
WEECHAT_CONFIG_WRITE_MEMORY_ERROR +
|
|
|
|
WEECHAT_CONFIG_OPTION_SET_OK_CHANGED +
|
|
|
|
WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE +
|
|
|
|
WEECHAT_CONFIG_OPTION_SET_ERROR +
|
|
|
|
WEECHAT_CONFIG_OPTION_SET_OPTION_NOT_FOUND +
|
|
|
|
WEECHAT_CONFIG_OPTION_UNSET_OK_NO_RESET +
|
|
|
|
WEECHAT_CONFIG_OPTION_UNSET_OK_RESET +
|
|
|
|
WEECHAT_CONFIG_OPTION_UNSET_OK_REMOVED +
|
|
|
|
WEECHAT_CONFIG_OPTION_UNSET_ERROR
|
|
|
|
|
|
|
|
| sorted lists |
|
|
|
|
WEECHAT_LIST_POS_SORT +
|
|
|
|
WEECHAT_LIST_POS_BEGINNING +
|
|
|
|
WEECHAT_LIST_POS_END
|
|
|
|
|
|
|
|
| hotlist |
|
|
|
|
WEECHAT_HOTLIST_LOW +
|
|
|
|
WEECHAT_HOTLIST_MESSAGE +
|
|
|
|
WEECHAT_HOTLIST_PRIVATE +
|
2010-03-07 22:23:44 +01:00
|
|
|
WEECHAT_HOTLIST_HIGHLIGHT
|
2016-05-05 10:01:02 +02:00
|
|
|
|
|
|
|
| hook process |
|
|
|
|
WEECHAT_HOOK_PROCESS_RUNNING +
|
|
|
|
WEECHAT_HOOK_PROCESS_ERROR
|
|
|
|
|
|
|
|
| hook connect |
|
|
|
|
WEECHAT_HOOK_CONNECT_OK +
|
|
|
|
WEECHAT_HOOK_CONNECT_ADDRESS_NOT_FOUND +
|
|
|
|
WEECHAT_HOOK_CONNECT_IP_ADDRESS_NOT_FOUND +
|
|
|
|
WEECHAT_HOOK_CONNECT_CONNECTION_REFUSED +
|
|
|
|
WEECHAT_HOOK_CONNECT_PROXY_ERROR +
|
|
|
|
WEECHAT_HOOK_CONNECT_LOCAL_HOSTNAME_ERROR +
|
|
|
|
WEECHAT_HOOK_CONNECT_GNUTLS_INIT_ERROR +
|
|
|
|
WEECHAT_HOOK_CONNECT_GNUTLS_HANDSHAKE_ERROR +
|
|
|
|
WEECHAT_HOOK_CONNECT_MEMORY_ERROR +
|
|
|
|
WEECHAT_HOOK_CONNECT_TIMEOUT +
|
2012-10-14 10:59:00 +02:00
|
|
|
WEECHAT_HOOK_CONNECT_SOCKET_ERROR
|
2016-05-05 10:01:02 +02:00
|
|
|
|
|
|
|
| hook signal |
|
|
|
|
WEECHAT_HOOK_SIGNAL_STRING +
|
|
|
|
WEECHAT_HOOK_SIGNAL_INT +
|
|
|
|
WEECHAT_HOOK_SIGNAL_POINTER
|
2013-11-04 21:41:34 +01:00
|
|
|
|===
|
2010-03-07 22:23:44 +01:00
|
|
|
|
|
|
|
[[common_tasks]]
|
2013-11-04 21:41:34 +01:00
|
|
|
== Common tasks
|
2010-03-07 22:23:44 +01:00
|
|
|
|
|
|
|
This chapter shows some common tasks, with examples.
|
2017-08-21 23:35:04 +02:00
|
|
|
Only partial things in API are used here, for full reference, see the
|
|
|
|
link:weechat_plugin_api.en.html[WeeChat plugin API reference].
|
2010-03-07 22:23:44 +01:00
|
|
|
|
|
|
|
[[buffers]]
|
2013-11-04 21:41:34 +01:00
|
|
|
=== Buffers
|
2010-03-07 22:23:44 +01:00
|
|
|
|
|
|
|
[[buffers_display_messages]]
|
2013-11-04 21:41:34 +01:00
|
|
|
==== Display messages
|
2010-03-07 22:23:44 +01:00
|
|
|
|
|
|
|
An empty string is often used to work with WeeChat core buffer. For other
|
|
|
|
buffers, you must give pointer (as string, see <<pointers,pointers>>).
|
|
|
|
|
|
|
|
Examples:
|
|
|
|
|
|
|
|
[source,python]
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2010-03-07 22:23:44 +01:00
|
|
|
# display "hello" on core buffer
|
|
|
|
weechat.prnt("", "hello")
|
|
|
|
|
2010-07-28 11:59:19 +02:00
|
|
|
# display "hello" on core buffer, but do not write it to log file
|
|
|
|
# (version >= 0.3.3 only)
|
|
|
|
weechat.prnt_date_tags("", 0, "no_log", "hello")
|
|
|
|
|
2010-03-07 22:23:44 +01:00
|
|
|
# display prefix "==>" and message "hello" on current buffer
|
|
|
|
# (prefix and message must be separated by tab)
|
|
|
|
weechat.prnt(weechat.current_buffer(), "==>\thello")
|
|
|
|
|
|
|
|
# display error message on core buffer (with error prefix)
|
|
|
|
weechat.prnt("", "%swrong arguments" % weechat.prefix("error"))
|
|
|
|
|
|
|
|
# display message with color on core buffer
|
|
|
|
weechat.prnt("", "text %syellow on blue" % weechat.color("yellow,blue"))
|
|
|
|
|
|
|
|
# search buffer and display message
|
|
|
|
# (full name of buffer is plugin.name, for example: "irc.freenode.#weechat")
|
|
|
|
buffer = weechat.buffer_search("irc", "freenode.#weechat")
|
|
|
|
weechat.prnt(buffer, "message on #weechat channel")
|
|
|
|
|
|
|
|
# other solution to find an IRC buffer (better)
|
|
|
|
# (note that server and channel are separated by a comma)
|
|
|
|
buffer = weechat.info_get("irc_buffer", "freenode,#weechat")
|
|
|
|
weechat.prnt(buffer, "message on #weechat channel")
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2010-03-07 22:23:44 +01:00
|
|
|
|
|
|
|
[NOTE]
|
2017-09-23 16:34:26 +02:00
|
|
|
Print function is called `prnt` in Python and `print` in other languages.
|
2010-03-07 22:23:44 +01:00
|
|
|
|
|
|
|
[[buffers_send_text]]
|
2013-11-04 21:41:34 +01:00
|
|
|
==== Send text to buffer
|
2010-03-07 22:23:44 +01:00
|
|
|
|
|
|
|
You can send text or command to a buffer. This is exactly like if you type text
|
|
|
|
on command line and press [Enter].
|
|
|
|
|
|
|
|
Examples:
|
|
|
|
|
|
|
|
[source,python]
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2013-06-29 13:56:28 +02:00
|
|
|
# execute command "/help" on current buffer (result is on core buffer)
|
2010-03-07 22:23:44 +01:00
|
|
|
weechat.command("", "/help")
|
|
|
|
|
|
|
|
# send "hello" to #weechat IRC channel (users on channel will see message)
|
|
|
|
buffer = weechat.info_get("irc_buffer", "freenode,#weechat")
|
|
|
|
weechat.command(buffer, "hello")
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2010-03-07 22:23:44 +01:00
|
|
|
|
|
|
|
[[buffers_new]]
|
2013-11-04 21:41:34 +01:00
|
|
|
==== Create new buffer
|
2010-03-07 22:23:44 +01:00
|
|
|
|
|
|
|
You can create a new buffer in your script, then use it for displaying messages.
|
|
|
|
|
|
|
|
Two callbacks can be called (they are optional): one for input data (when you
|
|
|
|
type some text and press [Enter] on buffer), the other is called when buffer is
|
|
|
|
closed (for example by `/buffer close`).
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
|
|
|
[source,python]
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2010-03-07 22:23:44 +01:00
|
|
|
# callback for data received in input
|
|
|
|
def buffer_input_cb(data, buffer, input_data):
|
|
|
|
# ...
|
|
|
|
return weechat.WEECHAT_RC_OK
|
|
|
|
|
|
|
|
# callback called when buffer is closed
|
|
|
|
def buffer_close_cb(data, buffer):
|
|
|
|
# ...
|
|
|
|
return weechat.WEECHAT_RC_OK
|
|
|
|
|
|
|
|
# create buffer
|
|
|
|
buffer = weechat.buffer_new("mybuffer", "buffer_input_cb", "", "buffer_close_cb", "")
|
|
|
|
|
|
|
|
# set title
|
|
|
|
weechat.buffer_set(buffer, "title", "This is title for my buffer.")
|
|
|
|
|
|
|
|
# disable logging, by setting local variable "no_log" to "1"
|
|
|
|
weechat.buffer_set(buffer, "localvar_set_no_log", "1")
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2010-03-07 22:23:44 +01:00
|
|
|
|
|
|
|
[[buffers_properties]]
|
2013-11-04 21:41:34 +01:00
|
|
|
==== Buffer properties
|
2010-03-07 22:23:44 +01:00
|
|
|
|
|
|
|
You can read buffer properties, as string, integer or pointer.
|
|
|
|
|
|
|
|
Examples:
|
|
|
|
|
|
|
|
[source,python]
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2010-03-07 22:23:44 +01:00
|
|
|
buffer = weechat.current_buffer()
|
|
|
|
|
2014-07-05 16:45:48 +02:00
|
|
|
number = weechat.buffer_get_integer(buffer, "number")
|
|
|
|
name = weechat.buffer_get_string(buffer, "name")
|
2010-03-07 22:23:44 +01:00
|
|
|
short_name = weechat.buffer_get_string(buffer, "short_name")
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2010-03-07 22:23:44 +01:00
|
|
|
|
|
|
|
It is possible to add, read or delete local variables in buffer:
|
|
|
|
|
|
|
|
[source,python]
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2010-03-07 22:23:44 +01:00
|
|
|
# add local variable
|
|
|
|
weechat.buffer_set(buffer, "localvar_set_myvar", "my_value")
|
|
|
|
|
|
|
|
# read local variable
|
|
|
|
myvar = weechat.buffer_get_string(buffer, "localvar_myvar")
|
|
|
|
|
|
|
|
# delete local variable
|
|
|
|
weechat.buffer_set(buffer, "localvar_del_myvar", "")
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2010-03-07 22:23:44 +01:00
|
|
|
|
|
|
|
To see local variables of a buffer, do this command in WeeChat:
|
|
|
|
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2020-12-19 17:07:52 +01:00
|
|
|
/buffer listvar
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2010-03-07 22:23:44 +01:00
|
|
|
|
|
|
|
[[hooks]]
|
2013-11-04 21:41:34 +01:00
|
|
|
=== Hooks
|
2010-03-07 22:23:44 +01:00
|
|
|
|
|
|
|
[[hook_command]]
|
2013-11-04 21:41:34 +01:00
|
|
|
==== Add new command
|
2010-03-07 22:23:44 +01:00
|
|
|
|
2020-04-25 00:12:51 +02:00
|
|
|
Add a custom command with `+hook_command+`. You can use a custom completion
|
2010-03-07 22:23:44 +01:00
|
|
|
template to complete arguments of your command.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
|
|
|
[source,python]
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2010-03-07 22:23:44 +01:00
|
|
|
def my_command_cb(data, buffer, args):
|
|
|
|
# ...
|
|
|
|
return weechat.WEECHAT_RC_OK
|
|
|
|
|
|
|
|
hook = weechat.hook_command("myfilter", "description of myfilter",
|
|
|
|
"[list] | [enable|disable|toggle [name]] | [add name plugin.buffer tags regex] | [del name|-all]",
|
|
|
|
"description of arguments...",
|
|
|
|
"list"
|
|
|
|
" || enable %(filters_names)"
|
|
|
|
" || disable %(filters_names)"
|
|
|
|
" || toggle %(filters_names)"
|
|
|
|
" || add %(filters_names) %(buffers_plugins_names)|*"
|
|
|
|
" || del %(filters_names)|-all",
|
|
|
|
"my_command_cb", "")
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2010-03-07 22:23:44 +01:00
|
|
|
|
|
|
|
And then in WeeChat:
|
|
|
|
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2010-03-07 22:23:44 +01:00
|
|
|
/help myfilter
|
|
|
|
|
|
|
|
/myfilter arguments...
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2010-03-07 22:23:44 +01:00
|
|
|
|
|
|
|
[[hook_timer]]
|
2013-11-04 21:41:34 +01:00
|
|
|
==== Add a timer
|
2010-03-07 22:23:44 +01:00
|
|
|
|
2020-04-25 00:12:51 +02:00
|
|
|
Add a timer with `+hook_timer+`.
|
2010-03-07 22:23:44 +01:00
|
|
|
|
|
|
|
Example:
|
|
|
|
|
|
|
|
[source,python]
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2010-03-07 22:23:44 +01:00
|
|
|
def timer_cb(data, remaining_calls):
|
|
|
|
# ...
|
|
|
|
return weechat.WEECHAT_RC_OK
|
|
|
|
|
|
|
|
# timer called each minute when second is 00
|
|
|
|
weechat.hook_timer(60 * 1000, 60, 0, "timer_cb", "")
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2010-03-07 22:23:44 +01:00
|
|
|
|
|
|
|
[[hook_process]]
|
2013-11-04 21:41:34 +01:00
|
|
|
==== Run a background process
|
2010-03-07 22:23:44 +01:00
|
|
|
|
2020-04-25 00:12:51 +02:00
|
|
|
You can run a background process with `+hook_process+`. Your callback will be
|
2010-03-07 22:23:44 +01:00
|
|
|
called when data is ready. It may be called many times.
|
|
|
|
|
2016-05-04 22:19:27 +02:00
|
|
|
For the last call to your callback, _rc_ is set to 0 or positive value, it's
|
2010-03-07 22:23:44 +01:00
|
|
|
return code of command.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
2012-01-19 13:56:48 +01:00
|
|
|
[source,python]
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2012-01-19 13:56:48 +01:00
|
|
|
process_output = ""
|
|
|
|
|
|
|
|
def my_process_cb(data, command, rc, out, err):
|
|
|
|
global process_output
|
|
|
|
if out != "":
|
|
|
|
process_output += out
|
|
|
|
if int(rc) >= 0:
|
|
|
|
weechat.prnt("", process_output)
|
|
|
|
return weechat.WEECHAT_RC_OK
|
|
|
|
|
|
|
|
weechat.hook_process("/bin/ls -l /etc", 10 * 1000, "my_process_cb", "")
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2012-01-19 13:56:48 +01:00
|
|
|
|
|
|
|
[[url_transfer]]
|
2013-11-04 21:41:34 +01:00
|
|
|
==== URL transfer
|
2012-01-19 13:56:48 +01:00
|
|
|
|
|
|
|
_New in version 0.3.7._
|
|
|
|
|
2020-04-25 00:12:51 +02:00
|
|
|
To download URL (or post to URL), you have to use function `+hook_process+`, or
|
|
|
|
`+hook_process_hashtable+` if you need to set options for URL transfer.
|
2012-01-19 13:56:48 +01:00
|
|
|
|
|
|
|
Example of URL transfer without option: the HTML page will be received as "out"
|
|
|
|
in callback (standard output of process):
|
|
|
|
|
2010-03-07 22:23:44 +01:00
|
|
|
[source,python]
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2013-03-16 16:06:16 +01:00
|
|
|
# Display current stable version of WeeChat.
|
|
|
|
weechat_version = ""
|
2010-03-07 22:23:44 +01:00
|
|
|
|
2013-03-16 16:06:16 +01:00
|
|
|
def weechat_process_cb(data, command, rc, out, err):
|
|
|
|
global weechat_version
|
2012-01-19 13:56:48 +01:00
|
|
|
if out != "":
|
2013-03-16 16:06:16 +01:00
|
|
|
weechat_version += out
|
2010-03-07 22:23:44 +01:00
|
|
|
if int(rc) >= 0:
|
2013-03-16 16:06:16 +01:00
|
|
|
weechat.prnt("", "Current WeeChat stable is: %s" % weechat_version)
|
2010-03-07 22:23:44 +01:00
|
|
|
return weechat.WEECHAT_RC_OK
|
|
|
|
|
2014-12-13 09:16:09 +01:00
|
|
|
weechat.hook_process("url:https://weechat.org/dev/info/stable/",
|
2013-03-16 16:06:16 +01:00
|
|
|
30 * 1000, "weechat_process_cb", "")
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2012-01-19 13:56:48 +01:00
|
|
|
|
2013-03-16 16:06:16 +01:00
|
|
|
[TIP]
|
2014-12-13 09:16:09 +01:00
|
|
|
All infos available about WeeChat are on page https://weechat.org/dev/info
|
2013-03-16 16:06:16 +01:00
|
|
|
|
2012-01-19 13:56:48 +01:00
|
|
|
Example of URL transfer with an option: download latest WeeChat development
|
2016-05-04 22:19:27 +02:00
|
|
|
package in file _/tmp/weechat-devel.tar.gz_:
|
2012-01-19 13:56:48 +01:00
|
|
|
|
|
|
|
[source,python]
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2012-01-19 13:56:48 +01:00
|
|
|
def my_process_cb(data, command, rc, out, err):
|
|
|
|
if int(rc) >= 0:
|
|
|
|
weechat.prnt("", "End of transfer (rc=%s)" % rc)
|
|
|
|
return weechat.WEECHAT_RC_OK
|
|
|
|
|
2014-12-13 09:16:09 +01:00
|
|
|
weechat.hook_process_hashtable("url:https://weechat.org/files/src/weechat-devel.tar.gz",
|
2014-07-05 16:45:48 +02:00
|
|
|
{"file_out": "/tmp/weechat-devel.tar.gz"},
|
2012-01-19 13:56:48 +01:00
|
|
|
30 * 1000, "my_process_cb", "")
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2010-03-07 22:23:44 +01:00
|
|
|
|
2012-01-19 13:56:48 +01:00
|
|
|
For more information about URL transfer and available options, see functions
|
2020-04-25 00:12:51 +02:00
|
|
|
`+hook_process+` and `+hook_process_hashtable+` in
|
2017-08-21 23:35:04 +02:00
|
|
|
link:weechat_plugin_api.en.html#_hook_process[WeeChat plugin API reference].
|
2012-01-19 13:56:48 +01:00
|
|
|
|
2010-03-07 22:23:44 +01:00
|
|
|
[[config_options]]
|
2013-11-04 21:41:34 +01:00
|
|
|
=== Config / options
|
2010-03-07 22:23:44 +01:00
|
|
|
|
|
|
|
[[config_options_set_script]]
|
2013-11-04 21:41:34 +01:00
|
|
|
==== Set options for script
|
2010-03-07 22:23:44 +01:00
|
|
|
|
2020-04-25 00:12:51 +02:00
|
|
|
Function `+config_is_set_plugin+` is used to check if an option is set or not,
|
|
|
|
and `+config_set_plugin+` to set option.
|
2010-03-07 22:23:44 +01:00
|
|
|
|
|
|
|
Example:
|
|
|
|
|
|
|
|
[source,python]
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2010-03-07 22:23:44 +01:00
|
|
|
script_options = {
|
2019-05-24 21:53:17 +02:00
|
|
|
"option1": "value1",
|
|
|
|
"option2": "value2",
|
|
|
|
"option3": "value3",
|
2010-03-07 22:23:44 +01:00
|
|
|
}
|
2013-01-07 10:00:02 +01:00
|
|
|
for option, default_value in script_options.items():
|
2010-03-07 22:23:44 +01:00
|
|
|
if not weechat.config_is_set_plugin(option):
|
|
|
|
weechat.config_set_plugin(option, default_value)
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2010-03-07 22:23:44 +01:00
|
|
|
|
|
|
|
[[config_options_detect_changes]]
|
2013-11-04 21:41:34 +01:00
|
|
|
==== Detect changes
|
2010-03-07 22:23:44 +01:00
|
|
|
|
2020-04-25 00:12:51 +02:00
|
|
|
You must use `+hook_config+` to be notified if user changes some script options.
|
2010-03-07 22:23:44 +01:00
|
|
|
|
|
|
|
Example:
|
|
|
|
|
|
|
|
[source,python]
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2010-03-07 22:23:44 +01:00
|
|
|
SCRIPT_NAME = "myscript"
|
|
|
|
|
|
|
|
# ...
|
|
|
|
|
|
|
|
def config_cb(data, option, value):
|
2012-01-19 13:56:48 +01:00
|
|
|
"""Callback called when a script option is changed."""
|
2010-03-07 22:23:44 +01:00
|
|
|
# for example, read all script options to script variables...
|
|
|
|
# ...
|
|
|
|
return weechat.WEECHAT_RC_OK
|
|
|
|
|
|
|
|
# ...
|
|
|
|
|
|
|
|
weechat.hook_config("plugins.var.python." + SCRIPT_NAME + ".*", "config_cb", "")
|
2015-03-07 15:16:37 +01:00
|
|
|
# for other languages, change "python" with your language (perl/ruby/lua/tcl/guile/javascript)
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2010-03-07 22:23:44 +01:00
|
|
|
|
|
|
|
[[config_options_weechat]]
|
2013-11-04 21:41:34 +01:00
|
|
|
==== Read WeeChat options
|
2010-03-07 22:23:44 +01:00
|
|
|
|
2020-04-25 00:12:51 +02:00
|
|
|
Function `+config_get+` returns pointer to option. Then, depending on option type,
|
|
|
|
you must call `+config_string+`, `+config_boolean+`, `+config_integer+` or
|
|
|
|
`+config_color+`.
|
2010-03-07 22:23:44 +01:00
|
|
|
|
|
|
|
[source,python]
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2010-03-07 22:23:44 +01:00
|
|
|
# string
|
|
|
|
weechat.prnt("", "value of option weechat.look.item_time_format is: %s"
|
|
|
|
% (weechat.config_string(weechat.config_get("weechat.look.item_time_format"))))
|
|
|
|
|
|
|
|
# boolean
|
|
|
|
weechat.prnt("", "value of option weechat.look.day_change is: %d"
|
|
|
|
% (weechat.config_boolean(weechat.config_get("weechat.look.day_change"))))
|
|
|
|
|
|
|
|
# integer
|
|
|
|
weechat.prnt("", "value of option weechat.look.scroll_page_percent is: %d"
|
|
|
|
% (weechat.config_integer(weechat.config_get("weechat.look.scroll_page_percent"))))
|
|
|
|
|
|
|
|
# color
|
|
|
|
weechat.prnt("", "value of option weechat.color.chat_delimiters is: %s"
|
|
|
|
% (weechat.config_color(weechat.config_get("weechat.color.chat_delimiters"))))
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2010-03-07 22:23:44 +01:00
|
|
|
|
|
|
|
[[irc]]
|
2013-11-04 21:41:34 +01:00
|
|
|
=== IRC
|
2010-03-07 22:23:44 +01:00
|
|
|
|
|
|
|
[[irc_catch_messages]]
|
2013-11-04 21:41:34 +01:00
|
|
|
==== Catch messages
|
2010-03-07 22:23:44 +01:00
|
|
|
|
2019-10-12 22:21:48 +02:00
|
|
|
IRC plugin sends four signals for a message received (`xxx` is IRC internal
|
2010-03-07 22:23:44 +01:00
|
|
|
server name, `yyy` is IRC command name like JOIN, QUIT, PRIVMSG, 301, ..):
|
|
|
|
|
2019-10-12 22:21:48 +02:00
|
|
|
xxx,irc_in_yyy::
|
|
|
|
signal sent before processing message, only if message is *not* ignored
|
2010-03-07 22:23:44 +01:00
|
|
|
|
|
|
|
xxx,irc_in2_yyy::
|
2019-10-12 22:21:48 +02:00
|
|
|
signal sent after processing message, only if message is *not* ignored
|
|
|
|
|
|
|
|
xxx,irc_raw_in_yyy::
|
|
|
|
signal sent before processing message, even if message is ignored
|
|
|
|
|
|
|
|
xxx,irc_raw_in2_yyy::
|
|
|
|
signal sent after processing message, even if message is ignored
|
2010-03-07 22:23:44 +01:00
|
|
|
|
|
|
|
[source,python]
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2010-03-07 22:23:44 +01:00
|
|
|
def join_cb(data, signal, signal_data):
|
|
|
|
# signal is for example: "freenode,irc_in2_join"
|
|
|
|
# signal_data is IRC message, for example: ":nick!user@host JOIN :#channel"
|
|
|
|
server = signal.split(",")[0]
|
2017-06-03 15:42:05 +02:00
|
|
|
msg = weechat.info_get_hashtable("irc_message_parse", {"message": signal_data})
|
|
|
|
buffer = weechat.info_get("irc_buffer", "%s,%s" % (server, msg["channel"]))
|
2010-03-07 22:23:44 +01:00
|
|
|
if buffer:
|
2017-06-03 15:42:05 +02:00
|
|
|
weechat.prnt(buffer, "%s (%s) has joined this channel!" % (msg["nick"], msg["host"]))
|
2010-03-07 22:23:44 +01:00
|
|
|
return weechat.WEECHAT_RC_OK
|
|
|
|
|
|
|
|
# it is useful here to use "*" as server, to catch JOIN messages on all IRC
|
|
|
|
# servers
|
|
|
|
weechat.hook_signal("*,irc_in2_join", "join_cb", "")
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2010-03-07 22:23:44 +01:00
|
|
|
|
2010-10-25 13:09:11 +02:00
|
|
|
[[irc_modify_messages]]
|
2013-11-04 21:41:34 +01:00
|
|
|
==== Modify messages
|
2010-10-25 13:09:11 +02:00
|
|
|
|
2019-10-12 22:21:48 +02:00
|
|
|
IRC plugin sends two "modifiers" for a message received ("xxx" is IRC command),
|
|
|
|
so that you can modify it:
|
|
|
|
|
|
|
|
irc_in_xxx::
|
|
|
|
modifier sent before charset decoding: use with caution, the string may
|
|
|
|
contain invalid UTF-8 data; use only for raw operations on a message
|
|
|
|
|
|
|
|
irc_in2_xxx::
|
|
|
|
modifier sent after charset decoding, so the string received is always
|
|
|
|
UTF-8 valid (*recommended*)
|
2010-10-25 13:09:11 +02:00
|
|
|
|
|
|
|
[source,python]
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2010-10-25 13:09:11 +02:00
|
|
|
def modifier_cb(data, modifier, modifier_data, string):
|
|
|
|
# add server name to all messages received
|
2013-01-07 10:31:32 +01:00
|
|
|
# (OK that's not very useful, but that's just an example!)
|
2010-10-25 13:09:11 +02:00
|
|
|
return "%s %s" % (string, modifier_data)
|
|
|
|
|
2019-10-12 22:21:48 +02:00
|
|
|
weechat.hook_modifier("irc_in2_privmsg", "modifier_cb", "")
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2010-10-25 13:09:11 +02:00
|
|
|
|
|
|
|
[WARNING]
|
|
|
|
A malformed message could crash WeeChat or cause severe problems!
|
|
|
|
|
2011-08-26 10:31:37 +02:00
|
|
|
[[irc_message_parse]]
|
2013-11-04 21:41:34 +01:00
|
|
|
==== Parse message
|
2010-10-25 13:09:11 +02:00
|
|
|
|
|
|
|
_New in version 0.3.4._
|
|
|
|
|
2011-08-26 10:31:37 +02:00
|
|
|
You can parse an IRC message with info_hashtable called "irc_message_parse".
|
2010-10-25 13:09:11 +02:00
|
|
|
|
2015-06-27 17:00:53 +02:00
|
|
|
The result is a hashtable with following keys
|
|
|
|
(the example values are built with this message:
|
2020-04-25 00:12:51 +02:00
|
|
|
`+@time=2015-06-27T16:40:35.000Z :nick!user@host PRIVMSG #weechat :hello!+`):
|
2015-06-27 17:00:53 +02:00
|
|
|
|
2021-04-11 09:47:13 +02:00
|
|
|
[width="100%",cols="3,^2,10,7",options="header"]
|
2015-06-27 17:00:53 +02:00
|
|
|
|===
|
2021-04-11 09:47:13 +02:00
|
|
|
| Key | Since WeeChat ^(1)^ | Description | Example
|
2015-06-27 17:00:53 +02:00
|
|
|
|
2021-04-11 09:47:13 +02:00
|
|
|
| tags | 0.4.0 |
|
2016-11-26 23:19:41 +01:00
|
|
|
The tags in message (can be empty). |
|
2020-04-25 00:12:51 +02:00
|
|
|
`+time=2015-06-27T16:40:35.000Z+`
|
2015-06-27 17:00:53 +02:00
|
|
|
|
2021-04-11 09:47:13 +02:00
|
|
|
| message_without_tags | 0.4.0 |
|
2016-11-26 23:19:41 +01:00
|
|
|
The message without the tags (the same as message if there are no tags). |
|
2020-04-25 00:12:51 +02:00
|
|
|
`+:nick!user@host PRIVMSG #weechat :hello!+`
|
2015-06-27 17:00:53 +02:00
|
|
|
|
2021-04-11 09:47:13 +02:00
|
|
|
| nick | 0.3.4 |
|
2016-11-26 23:19:41 +01:00
|
|
|
The origin nick. |
|
2020-04-25 00:12:51 +02:00
|
|
|
`+nick+`
|
2015-06-27 17:00:53 +02:00
|
|
|
|
2021-04-11 09:47:13 +02:00
|
|
|
| user | 2.7 |
|
2019-09-27 20:52:00 +02:00
|
|
|
The origin user. |
|
2020-04-25 00:12:51 +02:00
|
|
|
`+user+`
|
2019-09-27 20:52:00 +02:00
|
|
|
|
2021-04-11 09:47:13 +02:00
|
|
|
| host | 0.3.4 |
|
2016-11-26 23:19:41 +01:00
|
|
|
The origin host (includes the nick). |
|
2020-04-25 00:12:51 +02:00
|
|
|
`+nick!user@host+`
|
2015-06-27 17:00:53 +02:00
|
|
|
|
2021-04-11 09:47:13 +02:00
|
|
|
| command | 0.3.4 |
|
2016-11-26 23:19:41 +01:00
|
|
|
The command (_PRIVMSG_, _NOTICE_, ...). |
|
2020-04-25 00:12:51 +02:00
|
|
|
`+PRIVMSG+`
|
2015-06-27 17:00:53 +02:00
|
|
|
|
2021-04-11 09:47:13 +02:00
|
|
|
| channel | 0.3.4 |
|
2016-11-26 23:19:41 +01:00
|
|
|
The target channel. |
|
2020-04-25 00:12:51 +02:00
|
|
|
`+#weechat+`
|
2015-06-27 17:00:53 +02:00
|
|
|
|
2021-04-11 09:47:13 +02:00
|
|
|
| arguments | 0.3.4 |
|
2016-11-26 23:19:41 +01:00
|
|
|
The command arguments (includes the channel). |
|
2020-04-25 00:12:51 +02:00
|
|
|
`+#weechat :hello!+`
|
2015-06-27 17:00:53 +02:00
|
|
|
|
2021-04-11 09:47:13 +02:00
|
|
|
| text | 1.3 |
|
2016-11-26 23:19:41 +01:00
|
|
|
The text (for example user message). |
|
2020-04-25 00:12:51 +02:00
|
|
|
`+hello!+`
|
2015-06-27 17:00:53 +02:00
|
|
|
|
2021-04-11 09:47:13 +02:00
|
|
|
| pos_command | 1.3 |
|
2016-11-26 23:19:41 +01:00
|
|
|
The index of _command_ in message ("-1" if _command_ was not found). |
|
2020-04-25 00:12:51 +02:00
|
|
|
`+47+`
|
2015-08-14 21:25:27 +02:00
|
|
|
|
2021-04-11 09:47:13 +02:00
|
|
|
| pos_arguments | 1.3 |
|
2016-11-26 23:19:41 +01:00
|
|
|
The index of _arguments_ in message ("-1" if _arguments_ was not found). |
|
2020-04-25 00:12:51 +02:00
|
|
|
`+55+`
|
2015-08-14 21:25:27 +02:00
|
|
|
|
2021-04-11 09:47:13 +02:00
|
|
|
| pos_channel | 1.3 |
|
2016-11-26 23:19:41 +01:00
|
|
|
The index of _channel_ in message ("-1" if _channel_ was not found). |
|
2020-04-25 00:12:51 +02:00
|
|
|
`+55+`
|
2015-08-14 21:25:27 +02:00
|
|
|
|
2021-04-11 09:47:13 +02:00
|
|
|
| pos_text | 1.3 |
|
2016-11-26 23:19:41 +01:00
|
|
|
The index of _text_ in message ("-1" if _text_ was not found). |
|
2020-04-25 00:12:51 +02:00
|
|
|
`+65+`
|
2015-06-27 17:00:53 +02:00
|
|
|
|===
|
|
|
|
|
2021-04-11 09:47:13 +02:00
|
|
|
[NOTE]
|
|
|
|
^(1)^ The key has been introduced in this WeeChat version.
|
|
|
|
|
2010-10-25 13:09:11 +02:00
|
|
|
[source,python]
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2015-06-27 17:00:53 +02:00
|
|
|
dict = weechat.info_get_hashtable(
|
|
|
|
"irc_message_parse",
|
|
|
|
{"message": "@time=2015-06-27T16:40:35.000Z :nick!user@host PRIVMSG #weechat :hello!"})
|
|
|
|
|
|
|
|
# dict == {
|
|
|
|
# "tags": "time=2015-06-27T16:40:35.000Z",
|
|
|
|
# "message_without_tags": ":nick!user@host PRIVMSG #weechat :hello!",
|
|
|
|
# "nick": "nick",
|
2019-09-27 20:52:00 +02:00
|
|
|
# "user": "user",
|
2015-06-27 17:00:53 +02:00
|
|
|
# "host": "nick!user@host",
|
|
|
|
# "command": "PRIVMSG",
|
|
|
|
# "channel": "#weechat",
|
|
|
|
# "arguments": "#weechat :hello!",
|
|
|
|
# "text": "hello!",
|
2015-08-14 21:25:27 +02:00
|
|
|
# "pos_command": "47",
|
|
|
|
# "pos_arguments": "55",
|
|
|
|
# "pos_channel": "55",
|
2015-06-27 17:00:53 +02:00
|
|
|
# "pos_text": "65",
|
|
|
|
# }
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2010-10-25 13:09:11 +02:00
|
|
|
|
2010-03-07 22:23:44 +01:00
|
|
|
[[infos]]
|
2013-11-04 21:41:34 +01:00
|
|
|
=== Infos
|
2010-03-07 22:23:44 +01:00
|
|
|
|
|
|
|
[[infos_weechat_version]]
|
2013-11-04 21:41:34 +01:00
|
|
|
==== WeeChat version
|
2010-03-07 22:23:44 +01:00
|
|
|
|
|
|
|
The best way to check version is to ask "version_number" and make integer
|
2011-05-13 16:46:44 +02:00
|
|
|
comparison with hexadecimal version number.
|
2010-03-07 22:23:44 +01:00
|
|
|
|
|
|
|
Example:
|
|
|
|
|
|
|
|
[source,python]
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2010-03-07 22:23:44 +01:00
|
|
|
version = weechat.info_get("version_number", "") or 0
|
|
|
|
if int(version) >= 0x00030200:
|
|
|
|
weechat.prnt("", "This is WeeChat 0.3.2 or newer")
|
|
|
|
else:
|
|
|
|
weechat.prnt("", "This is WeeChat 0.3.1 or older")
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2010-03-07 22:23:44 +01:00
|
|
|
|
|
|
|
[NOTE]
|
2016-05-04 22:19:27 +02:00
|
|
|
Versions ≤ 0.3.1.1 return empty string for _info_get("version_number")_ so you
|
2010-03-07 22:23:44 +01:00
|
|
|
must check that value returned is *not* empty.
|
|
|
|
|
|
|
|
To get version as string:
|
|
|
|
|
|
|
|
[source,python]
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2010-03-07 22:23:44 +01:00
|
|
|
# this will display for example "Version 0.3.2"
|
|
|
|
weechat.prnt("", "Version %s" % weechat.info_get("version", ""))
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2010-03-07 22:23:44 +01:00
|
|
|
|
|
|
|
[[infos_other]]
|
2013-11-04 21:41:34 +01:00
|
|
|
==== Other infos
|
2010-03-07 22:23:44 +01:00
|
|
|
|
|
|
|
[source,python]
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2021-05-08 20:56:49 +02:00
|
|
|
# WeeChat config directory, for example: "/home/user/.config/weechat"
|
|
|
|
weechat.prnt("", "WeeChat config dir: %s" % weechat.info_get("weechat_config_dir", ""))
|
2010-03-07 22:23:44 +01:00
|
|
|
|
|
|
|
# keyboard inactivity
|
|
|
|
weechat.prnt("", "Inactivity since %s seconds" % weechat.info_get("inactivity", ""))
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2010-03-07 22:23:44 +01:00
|
|
|
|
|
|
|
[[infolists]]
|
2013-11-04 21:41:34 +01:00
|
|
|
=== Infolists
|
2010-03-07 22:23:44 +01:00
|
|
|
|
|
|
|
[[infolists_read]]
|
2013-11-04 21:41:34 +01:00
|
|
|
==== Read an infolist
|
2010-03-07 22:23:44 +01:00
|
|
|
|
|
|
|
You can read infolist built by WeeChat or other plugins.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
|
|
|
[source,python]
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2010-03-07 22:23:44 +01:00
|
|
|
# read infolist "buffer", to get list of buffers
|
|
|
|
infolist = weechat.infolist_get("buffer", "", "")
|
|
|
|
if infolist:
|
|
|
|
while weechat.infolist_next(infolist):
|
|
|
|
name = weechat.infolist_string(infolist, "name")
|
|
|
|
weechat.prnt("", "buffer: %s" % name)
|
|
|
|
weechat.infolist_free(infolist)
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2010-03-07 22:23:44 +01:00
|
|
|
|
|
|
|
[IMPORTANT]
|
2020-04-25 00:12:51 +02:00
|
|
|
Don't forget to call `+infolist_free+` to free memory used by infolist, because
|
2010-03-07 22:23:44 +01:00
|
|
|
WeeChat will not automatically free memory.
|