2014-02-02 09:49:59 +01:00
|
|
|
= Guide pour scripts WeeChat
|
2014-01-23 18:38:53 +01:00
|
|
|
:author: Sébastien Helleu
|
|
|
|
:email: flashcode@flashtux.org
|
|
|
|
:lang: fr
|
|
|
|
:toc:
|
|
|
|
:toclevels: 3
|
2009-06-28 12:00:16 +02:00
|
|
|
|
|
|
|
|
|
|
|
Ce manuel documente le client de messagerie instantanée WeeChat, il fait
|
|
|
|
partie de WeeChat.
|
|
|
|
|
|
|
|
La dernière version de ce document peut être téléchargée sur cette page :
|
2013-05-23 15:21:41 +02:00
|
|
|
http://weechat.org/doc
|
2009-06-28 12:00:16 +02:00
|
|
|
|
|
|
|
|
|
|
|
[[introduction]]
|
2013-11-04 21:41:34 +01:00
|
|
|
== Introduction
|
2009-06-28 12:00:16 +02:00
|
|
|
|
|
|
|
WeeChat (Wee Enhanced Environment for Chat) est un client de discussion libre,
|
|
|
|
rapide et léger, conçu pour différents systèmes d'exploitation.
|
|
|
|
|
|
|
|
Ce manuel documente la façon d'écrire des scripts pour WeeChat, en utilisant
|
2011-10-26 19:25:51 +02:00
|
|
|
l'un des langages de script supportés :
|
|
|
|
|
|
|
|
* python
|
|
|
|
* perl
|
|
|
|
* ruby
|
|
|
|
* lua
|
|
|
|
* tcl
|
|
|
|
* guile (scheme)
|
2009-06-28 12:00:16 +02:00
|
|
|
|
|
|
|
[NOTE]
|
|
|
|
La majorité des exemples de cette documentation sont écrits en Python, mais
|
|
|
|
l'API est la même pour les autres langages.
|
|
|
|
|
|
|
|
[[scripts_in_weechat]]
|
2013-11-04 21:41:34 +01:00
|
|
|
== Scripts dans WeeChat
|
2009-06-28 12:00:16 +02:00
|
|
|
|
2014-01-29 22:37:33 +01:00
|
|
|
[[languages_specificities]]
|
2013-11-04 21:41:34 +01:00
|
|
|
=== Spécificités des langages
|
2009-06-28 12:00:16 +02:00
|
|
|
|
2013-11-04 21:41:34 +01:00
|
|
|
==== Python
|
2009-06-28 12:00:16 +02:00
|
|
|
|
2011-10-26 19:25:51 +02:00
|
|
|
* Vous devez utiliser `import weechat`
|
|
|
|
* Les fonctions `print*` se nomment `prnt*` en python (car 'print' est un mot
|
|
|
|
clé réservé)
|
|
|
|
* Les fonctions sont appelées par `weechat.xxx(arg1, arg2, ...)`
|
|
|
|
|
2013-11-04 21:41:34 +01:00
|
|
|
==== Perl
|
2011-10-26 19:25:51 +02:00
|
|
|
|
|
|
|
* Les fonctions sont appelées par `weechat::xxx(arg1, arg2, ...);`
|
|
|
|
|
2013-11-04 21:41:34 +01:00
|
|
|
==== Ruby
|
2011-10-26 19:25:51 +02:00
|
|
|
|
|
|
|
* Vous devez définir 'weechat_init' et appeler 'register' dedans
|
|
|
|
* Les fonctions sont appelées par `Weechat.xxx(arg1, arg2, ...)`
|
2013-03-22 19:54:44 +01:00
|
|
|
* En raison d'une limitation de Ruby (15 paramètres maximum par fonction), la
|
|
|
|
fonction `Weechat.config_new_option` reçoit les "callbacks" dans un tableau de
|
|
|
|
6 chaînes de caractères (3 callbacks + 3 chaînes de données), donc un appel à
|
|
|
|
cette fonction ressemble à ceci :
|
|
|
|
|
|
|
|
[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
|
|
|
|
2013-11-04 21:41:34 +01:00
|
|
|
==== Lua
|
2011-10-26 19:25:51 +02:00
|
|
|
|
|
|
|
* Les fonctions sont appelées par `weechat.xxx(arg1, arg2, ...)`
|
|
|
|
|
2013-11-04 21:41:34 +01:00
|
|
|
==== Tcl
|
2011-10-26 19:25:51 +02:00
|
|
|
|
|
|
|
* Les fonctions sont appelées par `weechat::xxx arg1 arg2 ...`
|
|
|
|
|
2013-11-04 21:41:34 +01:00
|
|
|
==== Guile (scheme)
|
2011-10-26 19:25:51 +02:00
|
|
|
|
|
|
|
* Les fonctions sont appelées par `(weechat:xxx arg1 arg2 ...)`
|
|
|
|
* Les fonctions suivantes prennent une liste de paramètres en entrée (au lieu
|
|
|
|
de plusieurs paramètres pour les autres fonctions), car le nombre de
|
|
|
|
paramètres excède la limite de Guile :
|
|
|
|
** config_new_section
|
|
|
|
** config_new_option
|
|
|
|
** bar_new
|
2009-06-28 12:00:16 +02:00
|
|
|
|
2010-03-07 22:23:44 +01:00
|
|
|
[[register_function]]
|
2013-11-04 21:41:34 +01:00
|
|
|
=== Fonction register
|
2009-06-28 12:00:16 +02:00
|
|
|
|
|
|
|
Tous les scripts WeeChat doivent s'enregistrer ("register") auprès de WeeChat,
|
|
|
|
et cela doit être la première fonction WeeChat appelée dans le script.
|
|
|
|
|
2009-06-28 20:47:13 +02:00
|
|
|
Prototype :
|
2009-06-28 12:00:16 +02:00
|
|
|
|
|
|
|
[source,python]
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2009-06-28 12:00:16 +02:00
|
|
|
weechat.register(name, author, version, license, description, shutdown_function, charset)
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2009-06-28 12:00:16 +02:00
|
|
|
|
|
|
|
Paramètres :
|
|
|
|
|
|
|
|
* 'name' : chaîne, nom interne du script
|
|
|
|
* 'author' : chaîne, nom de l'auteur
|
|
|
|
* 'version' : chaîne, version du script
|
|
|
|
* 'license' : chaîne, licence du script
|
|
|
|
* 'description' : chaîne, description courte du script
|
|
|
|
* 'shutdown_function' : chaîne, nom de la fonction appelée lorsque le script
|
2012-11-05 22:04:49 +01:00
|
|
|
est déchargé (peut être une chaîne vide)
|
|
|
|
* 'charset' : chaîne, jeu de caractères du script (si votre script est UTF-8,
|
|
|
|
vous pouvez utiliser une valeur vide ici, car UTF-8 est le jeu de caractères
|
|
|
|
par défaut)
|
2009-06-28 12:00:16 +02:00
|
|
|
|
2010-03-07 22:23:44 +01:00
|
|
|
Exemple, pour chaque langage :
|
2009-06-28 12:00:16 +02:00
|
|
|
|
|
|
|
* python :
|
|
|
|
|
|
|
|
[source,python]
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2009-06-28 12:00:16 +02:00
|
|
|
import weechat
|
|
|
|
|
|
|
|
weechat.register("test_python", "FlashCode", "1.0", "GPL3", "Script de test", "", "")
|
|
|
|
weechat.prnt("", "Bonjour, du script python !")
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2009-06-28 12:00:16 +02:00
|
|
|
|
2011-10-26 19:25:51 +02:00
|
|
|
* perl :
|
|
|
|
|
|
|
|
[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", "Script de test", "", "");
|
|
|
|
weechat::print("", "Bonjour, du script perl !");
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2011-10-26 19:25:51 +02:00
|
|
|
|
2009-06-28 12:00:16 +02:00
|
|
|
* ruby :
|
|
|
|
|
|
|
|
[source,ruby]
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2009-06-28 12:00:16 +02:00
|
|
|
def weechat_init
|
|
|
|
Weechat.register("test_ruby", "FlashCode", "1.0", "GPL3", "Script de test", "", "")
|
|
|
|
Weechat.print("", "Bonjour, du script ruby !")
|
|
|
|
return Weechat::WEECHAT_RC_OK
|
|
|
|
end
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2009-06-28 12:00:16 +02:00
|
|
|
|
|
|
|
* lua :
|
|
|
|
|
|
|
|
[source,lua]
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2009-06-28 12:00:16 +02:00
|
|
|
weechat.register("test_lua", "FlashCode", "1.0", "GPL3", "Script de test", "", "")
|
|
|
|
weechat.print("", "Bonjour, du script lua !")
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2009-06-28 12:00:16 +02:00
|
|
|
|
|
|
|
* tcl :
|
|
|
|
|
2011-10-26 19:25:51 +02:00
|
|
|
[source,tcl]
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2009-06-28 12:00:16 +02:00
|
|
|
weechat::register "test_tcl" "FlashCode" "1.0" "GPL3" "Script de test" "" ""
|
|
|
|
weechat::print "" "Bonjour, du script tcl !"
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2009-06-28 12:00:16 +02:00
|
|
|
|
2011-10-26 19:25:51 +02:00
|
|
|
* guile (scheme):
|
|
|
|
|
|
|
|
[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" "Script de test" "" "")
|
|
|
|
(weechat:print "" "Bonjour, du script scheme !")
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2011-10-26 19:25:51 +02:00
|
|
|
|
2009-06-28 12:00:16 +02:00
|
|
|
[[load_script]]
|
2013-11-04 21:41:34 +01:00
|
|
|
=== Chargement du script
|
2009-06-28 12:00:16 +02:00
|
|
|
|
2013-01-26 08:22:04 +01:00
|
|
|
Il est recommandé d'utiliser l'extension "script" pour charger les scripts,
|
2013-01-26 07:48:20 +01:00
|
|
|
par exemple :
|
|
|
|
|
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
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2013-01-26 07:48:20 +01:00
|
|
|
|
|
|
|
Chaque langage a également sa propre commande :
|
2009-06-28 12:00:16 +02:00
|
|
|
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2009-06-28 12:00:16 +02:00
|
|
|
/python load python/script.py
|
2011-10-26 19:25:51 +02:00
|
|
|
/perl load perl/script.pl
|
2009-06-28 12:00:16 +02:00
|
|
|
/ruby load ruby/script.rb
|
|
|
|
/lua load lua/script.lua
|
|
|
|
/tcl load tcl/script.tcl
|
2011-10-26 19:25:51 +02:00
|
|
|
/guile load guile/script.scm
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2009-06-28 12:00:16 +02:00
|
|
|
|
|
|
|
Vous pouvez faire un lien dans le répertoire 'langage/autoload' pour charger
|
|
|
|
automatiquement le script quand WeeChat démarre.
|
|
|
|
|
2010-03-07 22:23:44 +01:00
|
|
|
Par exemple en Python :
|
2009-06-28 12:00:16 +02:00
|
|
|
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2010-03-07 22:23:44 +01:00
|
|
|
$ cd ~/.weechat/python/autoload
|
|
|
|
$ ln -s ../script.py
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2009-06-28 12:00:16 +02:00
|
|
|
|
2013-01-26 07:48:20 +01:00
|
|
|
[NOTE]
|
|
|
|
Lors de l'installation d'un script avec la commande `/script install` le lien
|
|
|
|
dans le répertoire 'autoload' est automatiquement créé.
|
|
|
|
|
2009-10-09 15:46:29 +02:00
|
|
|
[[differences_with_c_api]]
|
2013-11-04 21:41:34 +01:00
|
|
|
== Différences avec l'API C
|
2009-06-28 12:00:16 +02:00
|
|
|
|
|
|
|
L'API script est quasiment identique à l'API C.
|
|
|
|
Vous pouvez consulter la 'Référence API Extension WeeChat' pour le détail de
|
|
|
|
chaque fonction de l'API : prototype, paramètres, valeurs de retour, exemples.
|
|
|
|
|
|
|
|
Il est important de bien faire la différence entre une 'extension' et un
|
|
|
|
'script' : une 'extension' est un fichier binaire compilé et chargé avec la
|
|
|
|
commande `/plugin`, tandis qu'un 'script' est un fichier texte chargé par une
|
2010-12-04 13:50:54 +01:00
|
|
|
extension comme 'python' par la commande `/python`.
|
2009-06-28 12:00:16 +02:00
|
|
|
|
2009-06-28 20:47:13 +02:00
|
|
|
Quand votre script 'test.py' appelle une fonction de l'API WeeChat, le chemin
|
2009-06-28 12:00:16 +02:00
|
|
|
est le suivant :
|
|
|
|
|
2013-11-04 21:41:34 +01:00
|
|
|
....
|
2013-01-26 11:42:02 +01:00
|
|
|
┌──────────────────────┐ ╔══════════════════╗
|
|
|
|
│ extension python │ ║ WeeChat "core" ║
|
|
|
|
├────────────┬─────────┤ ╟─────────┐ ║
|
|
|
|
test.py ─────► │ API script │ API C │ ─────► ║ API C │ ║
|
|
|
|
└────────────┴─────────┘ ╚═════════╧════════╝
|
2013-11-04 21:41:34 +01:00
|
|
|
....
|
2009-06-28 12:00:16 +02:00
|
|
|
|
2009-06-28 20:47:13 +02:00
|
|
|
Quand WeeChat appelle un "callback" dans votre script 'test.py', le chemin
|
2009-06-28 12:00:16 +02:00
|
|
|
est inversé :
|
|
|
|
|
2013-11-04 21:41:34 +01:00
|
|
|
....
|
2013-01-26 11:42:02 +01:00
|
|
|
╔══════════════════╗ ┌──────────────────────┐
|
|
|
|
║ WeeChat "core" ║ │ extension python │
|
|
|
|
║ ┌─────────╢ ├─────────┬────────────┤
|
|
|
|
║ │ API C ║ ─────► │ API C │ API script │ ─────► test.py
|
|
|
|
╚════════╧═════════╝ └─────────┴────────────┘
|
2013-11-04 21:41:34 +01:00
|
|
|
....
|
2009-06-28 12:00:16 +02:00
|
|
|
|
2010-03-07 22:23:44 +01:00
|
|
|
[[pointers]]
|
2013-11-04 21:41:34 +01:00
|
|
|
=== Pointeurs
|
2009-10-09 15:46:29 +02:00
|
|
|
|
|
|
|
Comme vous le savez probablement, il n'y a pas vraiment de "pointeurs" dans les
|
|
|
|
scripts. Donc quand les fonctions de l'API retournent un pointeur, il est
|
|
|
|
converti en chaîne pour le script.
|
|
|
|
|
|
|
|
Par exemple, si une fonction retourne le pointeur 0x1234ab56, le script recevra
|
|
|
|
la chaîne "0x1234ab56".
|
|
|
|
|
|
|
|
Et quand une fonction de l'API attend un pointeur dans ses paramètres, le
|
|
|
|
script doit envoyer cette valeur sous forme de chaîne. L'extension C la
|
|
|
|
convertira en pointeur réel avant d'appeler la fonction de l'API C.
|
|
|
|
|
|
|
|
Une chaîne vide ou "0x0" sont autorisées, cela signifie le pointeur NULL en C.
|
|
|
|
Par exemple, pour afficher un message sur le tampon core (tampon principal
|
|
|
|
WeeChat), vous pouvez faire :
|
|
|
|
|
|
|
|
[source,python]
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2009-10-09 15:46:29 +02:00
|
|
|
weechat.prnt("", "bonjour !")
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2009-10-09 15:46:29 +02:00
|
|
|
|
|
|
|
[WARNING]
|
|
|
|
Dans beaucoup de fonctions, pour des raisons de vitesse, WeeChat ne vérifie pas
|
|
|
|
si votre pointeur est correct ou pas. Il est de votre responsabilité de
|
|
|
|
vérifier que vous donnez un pointeur valide, sinon vous pourriez voir un joli
|
|
|
|
rapport de crash ;)
|
|
|
|
|
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
|
|
|
|
|
|
|
Tous les "callbacks" WeeChat doivent retourner WEECHAT_RC_OK ou
|
2014-01-29 22:37:33 +01:00
|
|
|
WEECHAT_RC_ERROR (l'exception est le callback du modificateur, qui retourne une
|
2009-10-09 15:46:29 +02:00
|
|
|
chaîne de caractères).
|
|
|
|
|
|
|
|
Les "callbacks" C utilisent un paramètre "data", qui est un pointeur. Dans
|
|
|
|
l'API script, ce "data" est une chaîne de caractères avec n'importe quelle
|
|
|
|
valeur (ce n'est pas un pointeur).
|
|
|
|
|
2013-01-26 08:22:04 +01:00
|
|
|
Exemple de callback, pour chaque langage :
|
|
|
|
|
|
|
|
* 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
|
|
|
|
|
|
|
* perl:
|
|
|
|
|
|
|
|
[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
|
|
|
|
|
|
|
* ruby:
|
|
|
|
|
|
|
|
[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
|
|
|
|
2013-01-26 08:22:04 +01:00
|
|
|
* lua:
|
|
|
|
|
|
|
|
[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
|
|
|
|
|
|
|
* tcl:
|
|
|
|
|
|
|
|
[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
|
|
|
|
|
|
|
* guile (scheme):
|
|
|
|
|
|
|
|
[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
|
|
|
|
|
|
|
[[script_api]]
|
2013-11-04 21:41:34 +01:00
|
|
|
== API script
|
2009-10-09 15:46:29 +02:00
|
|
|
|
|
|
|
Pour plus d'informations sur les fonctions de l'API, merci de consulter la
|
|
|
|
'Référence API Extension WeeChat'.
|
|
|
|
|
2010-03-07 22:23:44 +01:00
|
|
|
[[script_api_functions]]
|
2013-11-04 21:41:34 +01:00
|
|
|
=== Fonctions
|
2009-06-28 12:00:16 +02:00
|
|
|
|
|
|
|
Liste des fonctions de l'API script :
|
|
|
|
|
2010-03-07 22:23:44 +01:00
|
|
|
[width="100%",cols="^1,10",options="header"]
|
2013-11-04 21:41:34 +01:00
|
|
|
|===
|
2010-03-07 22:23:44 +01:00
|
|
|
| Catégorie | Fonctions
|
|
|
|
| général |
|
|
|
|
register
|
|
|
|
| extensions |
|
|
|
|
plugin_get_name
|
|
|
|
| chaînes |
|
2010-03-20 13:32:08 +01:00
|
|
|
charset_set, iconv_to_internal, iconv_from_internal, gettext, ngettext, +
|
2014-01-11 09:39:12 +01:00
|
|
|
strlen_screen, string_match, string_has_highlight, string_has_highlight_regex,
|
2011-08-01 19:25:01 +02:00
|
|
|
string_mask_to_regex, string_remove_color, string_is_command_char,
|
2013-04-21 10:48:38 +02:00
|
|
|
string_input_for_buffer, string_eval_expression
|
2010-03-07 22:23:44 +01:00
|
|
|
| répertoires |
|
|
|
|
mkdir_home, mkdir, mkdir_parents
|
|
|
|
| listes triées |
|
2011-08-01 19:25:01 +02:00
|
|
|
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
|
|
|
| fichiers de configuration |
|
|
|
|
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,
|
2011-08-01 19:25:01 +02:00
|
|
|
config_set_desc_plugin, config_unset_plugin
|
2011-08-20 10:52:27 +02:00
|
|
|
| associations de touches |
|
|
|
|
key_bind, key_unbind
|
2010-03-07 22:23:44 +01:00
|
|
|
| affichage |
|
|
|
|
prefix, color, print (for python: prnt), print_date_tags (for python:
|
|
|
|
prnt_date_tags), print_y (for python: prnt_y), log_print
|
|
|
|
| hooks |
|
|
|
|
hook_command, hook_command_run, hook_timer, hook_fd, hook_process,
|
2012-01-19 11:25:38 +01:00
|
|
|
hook_process_hashtable, hook_connect, hook_print, hook_signal,
|
|
|
|
hook_signal_send, hook_hsignal, hook_hsignal_send, hook_config,
|
|
|
|
hook_completion, hook_completion_list_add, hook_modifier, hook_modifier_exec,
|
2014-01-11 09:39:12 +01:00
|
|
|
hook_info, hook_info_hashtable, hook_infolist, hook_focus, hook_set, unhook,
|
|
|
|
unhook_all
|
2010-03-07 22:23:44 +01:00
|
|
|
| tampons |
|
|
|
|
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,
|
2011-08-01 19:25:01 +02:00
|
|
|
buffer_string_replace_local_var, buffer_match_list
|
2010-03-07 22:23:44 +01:00
|
|
|
| fenêtres |
|
2011-08-01 19:25:01 +02:00
|
|
|
current_window, window_search_with_buffer, window_get_integer,
|
|
|
|
window_get_string, window_get_pointer, window_set_title
|
2010-03-07 22:23:44 +01:00
|
|
|
| liste des pseudos |
|
|
|
|
nicklist_add_group, nicklist_search_group, nicklist_add_nick,
|
|
|
|
nicklist_search_nick, nicklist_remove_group, nicklist_remove_nick,
|
2010-10-29 18:40:25 +02:00
|
|
|
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
|
2010-03-07 22:23:44 +01:00
|
|
|
| barres |
|
|
|
|
bar_item_search, bar_item_new, bar_item_update, bar_item_remove, bar_search,
|
|
|
|
bar_new, bar_set, bar_update, bar_remove
|
|
|
|
| commandes |
|
|
|
|
command
|
|
|
|
| infos |
|
2010-08-27 15:59:06 +02:00
|
|
|
info_get, info_get_hashtable
|
2010-03-07 22:23:44 +01:00
|
|
|
| infolists |
|
|
|
|
infolist_new, infolist_new_item, infolist_new_var_integer,
|
|
|
|
infolist_new_var_string, infolist_new_var_pointer, infolist_new_var_time, +
|
2010-10-20 13:11:24 +02:00
|
|
|
infolist_get, infolist_next, infolist_prev, infolist_reset_item_cursor, +
|
|
|
|
infolist_fields, infolist_integer, infolist_string, infolist_pointer, +
|
|
|
|
infolist_time, infolist_free
|
2011-08-01 19:25:01 +02:00
|
|
|
| hdata |
|
|
|
|
hdata_get, hdata_get_var_offset, hdata_get_var_type_string,
|
2013-04-21 10:48:38 +02:00
|
|
|
hdata_get_var_array_size, hdata_get_var_array_size_string,
|
2011-12-17 17:03:39 +01:00
|
|
|
hdata_get_var_hdata, hdata_get_list, hdata_check_pointer, hdata_move,
|
2013-04-21 11:26:52 +02:00
|
|
|
hdata_search, hdata_char, hdata_integer, hdata_long, hdata_string,
|
|
|
|
hdata_pointer, hdata_time, hdata_hashtable, hdata_update, hdata_get_string
|
2010-03-07 22:23:44 +01:00
|
|
|
| mise à jour |
|
|
|
|
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
|
|
|
=== Constantes
|
2009-06-28 12:00:16 +02:00
|
|
|
|
|
|
|
Liste des constantes de l'API script :
|
|
|
|
|
2010-03-07 22:23:44 +01:00
|
|
|
[width="100%",cols="^1,10",options="header"]
|
2013-11-04 21:41:34 +01:00
|
|
|
|===
|
2010-03-07 22:23:44 +01:00
|
|
|
| Catégorie | Constantes
|
|
|
|
| codes retour |
|
|
|
|
WEECHAT_RC_OK, WEECHAT_RC_OK_EAT, WEECHAT_RC_ERROR
|
|
|
|
| fichiers de configuration |
|
|
|
|
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
|
|
|
|
| listes triées |
|
|
|
|
WEECHAT_LIST_POS_SORT, WEECHAT_LIST_POS_BEGINNING, WEECHAT_LIST_POS_END
|
|
|
|
| hotlist |
|
|
|
|
WEECHAT_HOTLIST_LOW, WEECHAT_HOTLIST_MESSAGE, WEECHAT_HOTLIST_PRIVATE,
|
|
|
|
WEECHAT_HOTLIST_HIGHLIGHT
|
|
|
|
| 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,
|
2012-10-14 10:59:00 +02:00
|
|
|
WEECHAT_HOOK_CONNECT_MEMORY_ERROR, WEECHAT_HOOK_CONNECT_TIMEOUT,
|
|
|
|
WEECHAT_HOOK_CONNECT_SOCKET_ERROR
|
2010-03-07 22:23:44 +01: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
|
|
|
== Tâches courantes
|
2010-03-07 22:23:44 +01:00
|
|
|
|
|
|
|
Ce chapitre montre quelques tâches courantes, avec des exemples.
|
|
|
|
Seule une partie de l'API est utilisée ici, pour une référence complète, voir la
|
|
|
|
'Référence API Extension WeeChat'.
|
|
|
|
|
|
|
|
[[buffers]]
|
2013-11-04 21:41:34 +01:00
|
|
|
=== Tampons
|
2010-03-07 22:23:44 +01:00
|
|
|
|
|
|
|
[[buffers_display_messages]]
|
2013-11-04 21:41:34 +01:00
|
|
|
==== Afficher des messages
|
2010-03-07 22:23:44 +01:00
|
|
|
|
|
|
|
Une chaîne vide est souvent utilisée pour travailler avec le tampon core WeeChat.
|
|
|
|
Pour les autres tampons, vous devez passer un pointeur (sous forme de chaîne,
|
|
|
|
voir <<pointers,pointeurs>>).
|
|
|
|
|
|
|
|
Exemples :
|
|
|
|
|
|
|
|
[source,python]
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2010-03-07 22:23:44 +01:00
|
|
|
# afficher "bonjour" sur le tampon core
|
|
|
|
weechat.prnt("", "bonjour")
|
|
|
|
|
2010-07-28 11:59:19 +02:00
|
|
|
# afficher "bonjour" sur le tampon core, mais ne pas l'écrire dans le fichier de log
|
|
|
|
# (version >= 0.3.3 seulement)
|
|
|
|
weechat.prnt_date_tags("", 0, "no_log", "bonjour")
|
|
|
|
|
2010-03-07 22:23:44 +01:00
|
|
|
# afficher le préfixe "==>" et le message "bonjour" sur le tampon courant
|
|
|
|
# (le préfixe et le message doivent être séparés par une tabulation)
|
|
|
|
weechat.prnt(weechat.current_buffer(), "==>\tbonjour")
|
|
|
|
|
|
|
|
# afficher un message d'erreur sur le tampon core (avec le préfixe d'erreur)
|
|
|
|
weechat.prnt("", "%smauvais paramètres" % weechat.prefix("error"))
|
|
|
|
|
|
|
|
# afficher un message avec de la couleur sur le tampon core
|
|
|
|
weechat.prnt("", "texte %sjaune sur bleu" % weechat.color("yellow,blue"))
|
|
|
|
|
|
|
|
# chercher un tampon et afficher un message
|
|
|
|
# (le nom complet d'un tampon est extension.nom, par exemple : "irc.freenode.#weechat")
|
|
|
|
buffer = weechat.buffer_search("irc", "freenode.#weechat")
|
|
|
|
weechat.prnt(buffer, "message sur le canal #weechat")
|
|
|
|
|
|
|
|
# autre solution pour chercher un tampon IRC (meilleure)
|
|
|
|
# (notez que le serveur et le canal sont séparés par une virgule)
|
|
|
|
buffer = weechat.info_get("irc_buffer", "freenode,#weechat")
|
|
|
|
weechat.prnt(buffer, "message sur le canal #weechat")
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2010-03-07 22:23:44 +01:00
|
|
|
|
|
|
|
[NOTE]
|
|
|
|
La fonction d'affichage est appelée `print` en Perl/Ruby/Lua/Tcl et `prnt` en
|
|
|
|
Python.
|
|
|
|
|
|
|
|
[[buffers_send_text]]
|
2013-11-04 21:41:34 +01:00
|
|
|
==== Envoyer du texte au tampon
|
2010-03-07 22:23:44 +01:00
|
|
|
|
|
|
|
Vous pouvez envoyer du texte ou une commande à un tampon. C'est exactement comme
|
|
|
|
si vous tapiez le texte sur la ligne de commande et que vous pressiez [Enter].
|
|
|
|
|
|
|
|
Exemples :
|
|
|
|
|
|
|
|
[source,python]
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2013-06-29 13:56:28 +02:00
|
|
|
# exécuter la commande "/help" sur le tampon courant (le résultat est sur le tampon core)
|
2010-03-07 22:23:44 +01:00
|
|
|
weechat.command("", "/help")
|
|
|
|
|
|
|
|
# envoyer "bonjour" au canal IRC #weechat (les utilisateurs sur le canal verront le message)
|
|
|
|
buffer = weechat.info_get("irc_buffer", "freenode,#weechat")
|
|
|
|
weechat.command(buffer, "bonjour")
|
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
|
|
|
==== Créer un nouveau tampon
|
2010-03-07 22:23:44 +01:00
|
|
|
|
|
|
|
Vous pouvez créer un nouveau tampon dans votre script, et l'utiliser pour
|
|
|
|
afficher des messages.
|
|
|
|
|
|
|
|
Deux "callbacks" peuvent être appelés (ils sont optionnels) : un pour les données
|
|
|
|
en entrée (quand vous tapez du texte et pressez [Enter] sur le tampon), l'autre
|
|
|
|
est appelé lorsque le tampon est fermé (par exemple avec `/buffer close`).
|
|
|
|
|
|
|
|
Exemple :
|
|
|
|
|
|
|
|
[source,python]
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2010-03-07 22:23:44 +01:00
|
|
|
# callback pour les données reçues en entrée
|
|
|
|
def buffer_input_cb(data, buffer, input_data):
|
|
|
|
# ...
|
|
|
|
return weechat.WEECHAT_RC_OK
|
|
|
|
|
|
|
|
# callback appelé lorsque le tampon est fermé
|
|
|
|
def buffer_close_cb(data, buffer):
|
|
|
|
# ...
|
|
|
|
return weechat.WEECHAT_RC_OK
|
|
|
|
|
|
|
|
# créer le tampon
|
|
|
|
buffer = weechat.buffer_new("montampon", "buffer_input_cb", "", "buffer_close_cb", "")
|
|
|
|
|
|
|
|
# définir le titre
|
|
|
|
weechat.buffer_set(buffer, "title", "Ceci est le titre du tampon.")
|
|
|
|
|
|
|
|
# désactiver l'enregistrement (log), en définissant la variable locale "no_log" à "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
|
|
|
==== Propriétés du tampon
|
2010-03-07 22:23:44 +01:00
|
|
|
|
|
|
|
Vous pouvez lire des propriétés du tampon, sous forme de chaîne, entier ou
|
|
|
|
pointeur.
|
|
|
|
|
|
|
|
Exemples :
|
|
|
|
|
|
|
|
[source,python]
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2010-03-07 22:23:44 +01:00
|
|
|
buffer = weechat.current_buffer()
|
|
|
|
|
|
|
|
number = weechat.buffer_get_integer(buffer, "number")
|
|
|
|
name = weechat.buffer_get_string(buffer, "name")
|
|
|
|
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
|
|
|
|
|
|
|
Il est possible d'ajouter, lire ou supprimer des variables locales dans le
|
|
|
|
tampon :
|
|
|
|
|
|
|
|
[source,python]
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2010-03-07 22:23:44 +01:00
|
|
|
# ajouter une variable locale
|
|
|
|
weechat.buffer_set(buffer, "localvar_set_myvar", "my_value")
|
|
|
|
|
|
|
|
# lire une variable locale
|
|
|
|
myvar = weechat.buffer_get_string(buffer, "localvar_myvar")
|
|
|
|
|
|
|
|
# supprimer une variable locale
|
|
|
|
weechat.buffer_set(buffer, "localvar_del_myvar", "")
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2010-03-07 22:23:44 +01:00
|
|
|
|
|
|
|
Pour voir les variables locales d'un tampon, exécutez cette commande dans
|
|
|
|
WeeChat :
|
|
|
|
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2010-03-07 22:23:44 +01:00
|
|
|
/buffer localvar
|
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
|
|
|
==== Ajouter une nouvelle commande
|
2010-03-07 22:23:44 +01:00
|
|
|
|
|
|
|
Ajoutez une nouvelle commande avec `hook_command`. Vous pouvez utiliser une
|
|
|
|
complétion personnalisée pour compléter les paramètres de votre commande.
|
|
|
|
|
|
|
|
Exemple :
|
|
|
|
|
|
|
|
[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("monfiltre", "description de mon filtre",
|
|
|
|
"[list] | [enable|disable|toggle [name]] | [add name plugin.buffer tags regex] | [del name|-all]",
|
|
|
|
"description des paramètres...",
|
|
|
|
"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
|
|
|
|
|
|
|
Puis sous WeeChat :
|
|
|
|
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2010-03-07 22:23:44 +01:00
|
|
|
/help monfiltre
|
|
|
|
|
|
|
|
/monfiltre paramètres...
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2010-03-07 22:23:44 +01:00
|
|
|
|
|
|
|
[[hook_timer]]
|
2014-01-29 22:37:33 +01:00
|
|
|
==== Ajouter un minuteur
|
2010-03-07 22:23:44 +01:00
|
|
|
|
2014-01-29 22:37:33 +01:00
|
|
|
Ajoutez un minuteur avec `hook_timer`.
|
2010-03-07 22:23:44 +01:00
|
|
|
|
|
|
|
Exemple :
|
|
|
|
|
|
|
|
[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
|
|
|
|
|
2014-01-29 22:37:33 +01:00
|
|
|
# minuteur appelé chaque minute quand la seconde est 00
|
2010-03-07 22:23:44 +01: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
|
|
|
==== Lancer un processus en tâche de fond
|
2010-03-07 22:23:44 +01:00
|
|
|
|
|
|
|
Vous pouvez lancer un processus en tâche de fond avec `hook_process`. Votre
|
|
|
|
"callback" sera appelé quand des données seront prêtes. Il peut être appelé
|
|
|
|
plusieurs fois.
|
|
|
|
|
|
|
|
Pour le dernier appel à votre "callback", 'rc' est positionné à 0 ou une valeur
|
|
|
|
positive, c'est le code retour de la commande.
|
|
|
|
|
|
|
|
Exemple :
|
|
|
|
|
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
|
|
|
==== Transfert d'URL
|
2012-01-19 13:56:48 +01:00
|
|
|
|
|
|
|
_Nouveau dans la version 0.3.7._
|
|
|
|
|
|
|
|
Pour télécharger une URL (ou poster vers une URL), vous devez utiliser la
|
|
|
|
fonction `hook_process`, ou `hook_process_hashtable` si vous avez besoin
|
|
|
|
d'options pour le transfert d'URL.
|
|
|
|
|
|
|
|
Exemple de transfert d'URL sans option : la page HTML sera reçue comme "out"
|
|
|
|
dans le "callback" (sortie standard du processus) :
|
|
|
|
|
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
|
|
|
# Afficher la version stable courante de 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("", "La version stable courante de WeeChat est : %s" % weechat_version)
|
2010-03-07 22:23:44 +01:00
|
|
|
return weechat.WEECHAT_RC_OK
|
|
|
|
|
2013-05-23 15:21:41 +02:00
|
|
|
weechat.hook_process("url:http://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]
|
|
|
|
Toutes les infos disponibles à propos de WeeChat sont sur la page
|
2013-05-23 15:21:41 +02:00
|
|
|
http://weechat.org/dev/info
|
2013-03-16 16:06:16 +01:00
|
|
|
|
2012-01-19 13:56:48 +01:00
|
|
|
Exemple de transfert d'URL avec une option : télécharger le dernier paquet de
|
|
|
|
développement WeeChat dans le fichier '/tmp/weechat-devel.tar.gz' :
|
|
|
|
|
|
|
|
[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("", "Fin du transfert (rc=%s)" % rc)
|
|
|
|
return weechat.WEECHAT_RC_OK
|
|
|
|
|
|
|
|
weechat.hook_process_hashtable("url:http://weechat.org/files/src/weechat-devel.tar.gz",
|
|
|
|
{ "file_out": "/tmp/weechat-devel.tar.gz" },
|
|
|
|
30 * 1000, "my_process_cb", "")
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2012-01-19 13:56:48 +01:00
|
|
|
|
|
|
|
Pour plus d'information sur le transfert d'URL et les options disponibles, voir
|
|
|
|
les fonctions `hook_process` et `hook_process_hashtable` dans la
|
|
|
|
'Référence API Extension WeeChat'.
|
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
|
|
|
==== Définir des options pour le script
|
2010-03-07 22:23:44 +01:00
|
|
|
|
|
|
|
La fonction `config_is_set_plugin` est utilisée pour vérifier si une option est
|
|
|
|
définie ou pas, et `config_set_plugin` pour définir une option.
|
|
|
|
|
|
|
|
Exemple :
|
|
|
|
|
|
|
|
[source,python]
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2010-03-07 22:23:44 +01:00
|
|
|
script_options = {
|
|
|
|
"option1" : "valeur1",
|
|
|
|
"option2" : "valeur2",
|
|
|
|
"option3" : "valeur3",
|
|
|
|
}
|
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
|
|
|
==== Détecter des changements
|
2010-03-07 22:23:44 +01:00
|
|
|
|
|
|
|
Vous devez utiliser `hook_config` pour être notifié si l'utilisateur modifie
|
|
|
|
certaines options du script.
|
|
|
|
|
|
|
|
Exemple :
|
|
|
|
|
|
|
|
[source,python]
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2010-03-07 22:23:44 +01:00
|
|
|
SCRIPT_NAME = "monscript"
|
|
|
|
|
|
|
|
# ...
|
|
|
|
|
|
|
|
def config_cb(data, option, value):
|
2012-01-19 13:56:48 +01:00
|
|
|
"""Callback appelé lorsqu'une option du script est modifiée."""
|
2010-03-07 22:23:44 +01:00
|
|
|
# par exemple, relire toutes les options du script dans des variables du script...
|
|
|
|
# ...
|
|
|
|
return weechat.WEECHAT_RC_OK
|
|
|
|
|
|
|
|
# ...
|
|
|
|
|
|
|
|
weechat.hook_config("plugins.var.python." + SCRIPT_NAME + ".*", "config_cb", "")
|
2013-01-07 10:31:32 +01:00
|
|
|
# pour les autres langages, remplacez "python" par le langage ("perl", "ruby", "lua" ou "tcl")
|
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
|
|
|
==== Lire les options WeeChat
|
2010-03-07 22:23:44 +01:00
|
|
|
|
|
|
|
La fonction `config_get` retourne un pointeur vers une option. Ensuite, en
|
|
|
|
fonction du type de l'option, il faut appeler `config_string`, `config_boolean`,
|
|
|
|
`config_integer` ou `config_color`.
|
|
|
|
|
|
|
|
[source,python]
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2010-03-07 22:23:44 +01:00
|
|
|
# chaîne
|
|
|
|
weechat.prnt("", "la valeur de l'option weechat.look.item_time_format est : %s"
|
|
|
|
% (weechat.config_string(weechat.config_get("weechat.look.item_time_format"))))
|
|
|
|
|
|
|
|
# booléen
|
|
|
|
weechat.prnt("", "la valeur de l'option weechat.look.day_change est : %d"
|
|
|
|
% (weechat.config_boolean(weechat.config_get("weechat.look.day_change"))))
|
|
|
|
|
|
|
|
# entier
|
|
|
|
weechat.prnt("", "la valeur de l'option weechat.look.scroll_page_percent est : %d"
|
|
|
|
% (weechat.config_integer(weechat.config_get("weechat.look.scroll_page_percent"))))
|
|
|
|
|
|
|
|
# couleur
|
|
|
|
weechat.prnt("", "la valeur de l'option weechat.color.chat_delimiters est : %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
|
|
|
==== Intercepter des messages
|
2010-03-07 22:23:44 +01:00
|
|
|
|
|
|
|
L'extension IRC envoie deux signaux pour un message reçu (`xxx` est le nom
|
|
|
|
interne du serveur IRC, `yyy` est le nom de la commande IRC comme JOIN, QUIT,
|
|
|
|
PRIVMSG, 301, ..):
|
|
|
|
|
|
|
|
xxxx,irc_in_yyy::
|
|
|
|
signal envoyé avant traitement du message
|
|
|
|
|
|
|
|
xxx,irc_in2_yyy::
|
|
|
|
message sent après traitement du message
|
|
|
|
|
|
|
|
[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 est par exemple : "freenode,irc_in2_join"
|
|
|
|
# signal_data est le message IRC, par exemple : ":nick!user@host JOIN :#canal"
|
|
|
|
nick = weechat.info_get("irc_nick_from_host", signal_data)
|
|
|
|
server = signal.split(",")[0]
|
|
|
|
channel = signal_data.split(":")[-1]
|
|
|
|
buffer = weechat.info_get("irc_buffer", "%s,%s" % (server, channel))
|
|
|
|
if buffer:
|
|
|
|
weechat.prnt(buffer, "Eheh, %s a rejoint le canal !" % nick)
|
|
|
|
return weechat.WEECHAT_RC_OK
|
|
|
|
|
|
|
|
# il est pratique ici d'utiliser "*" comme serveur, pour intercepter les
|
|
|
|
# messages JOIN de tous les serveurs IRC
|
|
|
|
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
|
|
|
==== Modifier des messages
|
2010-10-25 13:09:11 +02:00
|
|
|
|
2014-01-29 22:37:33 +01:00
|
|
|
L'extension IRC envoie un modificateur appelé "irc_in_xxx" ("xxx" est la
|
|
|
|
commande IRC) pour un message reçu, de sorte que vous puissiez le modifier.
|
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):
|
|
|
|
# ajouter le nom du serveur à tous les messages reçus
|
|
|
|
# (ok ce n'est pas très utile, mais c'est juste un exemple !)
|
|
|
|
return "%s %s" % (string, modifier_data)
|
|
|
|
|
|
|
|
weechat.hook_modifier("irc_in_privmsg", "modifier_cb", "")
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2010-10-25 13:09:11 +02:00
|
|
|
|
|
|
|
[WARNING]
|
|
|
|
Un message mal formé peut provoquer un plantage de WeeChat ou de sérieux
|
|
|
|
problèmes !
|
|
|
|
|
2011-08-26 10:31:37 +02:00
|
|
|
[[irc_message_parse]]
|
2013-11-04 21:41:34 +01:00
|
|
|
==== Analyser un message
|
2010-10-25 13:09:11 +02:00
|
|
|
|
|
|
|
_Nouveau dans la version 0.3.4._
|
|
|
|
|
|
|
|
Vous pouvez analyser un message IRC avec l'info_hashtable appelée
|
2011-08-26 10:31:37 +02:00
|
|
|
"irc_message_parse".
|
2010-10-25 13:09:11 +02:00
|
|
|
|
|
|
|
[source,python]
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2011-08-26 10:31:37 +02:00
|
|
|
dict = weechat.info_get_hashtable("irc_message_parse",
|
2010-10-25 13:09:11 +02:00
|
|
|
{ "message": ":nick!user@host PRIVMSG #weechat :message ici" })
|
|
|
|
weechat.prnt("", "dict: %s" % dict)
|
|
|
|
|
|
|
|
# output:
|
|
|
|
# dict: {'nick': 'nick', 'host': 'nick!user@host', 'command': 'PRIVMSG', 'arguments': '#weechat :message ici', 'channel': '#weechat'}
|
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
|
|
|
==== Version de WeeChat
|
2010-03-07 22:23:44 +01:00
|
|
|
|
|
|
|
Le meilleur moyen de vérifier la version est de demander "version_number" et de
|
|
|
|
faire une comparaison entre nombre entiers avec la version hexadécimale de la
|
|
|
|
version.
|
|
|
|
|
|
|
|
Exemple :
|
|
|
|
|
|
|
|
[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("", "C'est WeeChat 0.3.2 ou plus récent")
|
|
|
|
else:
|
|
|
|
weechat.prnt("", "C'est WeeChat 0.3.1 ou plus ancien")
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2010-03-07 22:23:44 +01:00
|
|
|
|
|
|
|
[NOTE]
|
2011-08-04 16:13:34 +02:00
|
|
|
Les versions ≤ 0.3.1.1 retournent une chaîne vide pour
|
2010-03-07 22:23:44 +01:00
|
|
|
'info_get("version_number")', donc vous devez vérifier que la valeur de retour
|
|
|
|
n'est *pas* vide.
|
|
|
|
|
|
|
|
Pour obtenir la version sous forme de chaîne :
|
|
|
|
|
|
|
|
[source,python]
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2010-03-07 22:23:44 +01:00
|
|
|
# ceci affichera par exemple "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
|
|
|
==== Autres infos
|
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
|
|
|
# répertoire de WeeChat, par exemple : "/home/xxxx/.weechat"
|
|
|
|
weechat.prnt("", "Répertoire WeeChat : %s" % weechat.info_get("weechat_dir", ""))
|
|
|
|
|
|
|
|
# inactivité clavier
|
|
|
|
weechat.prnt("", "Inactivité depuis %s secondes" % 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
|
|
|
==== Lire une infolist
|
2010-03-07 22:23:44 +01:00
|
|
|
|
|
|
|
Vous pouvez lire une infolist construite par WeeChat ou d'autres extensions.
|
|
|
|
|
|
|
|
Exemple :
|
|
|
|
|
|
|
|
[source,python]
|
2013-11-04 21:41:34 +01:00
|
|
|
----
|
2010-03-07 22:23:44 +01:00
|
|
|
# lecture de l'infolist "buffer", pour avoir la liste des tampons
|
|
|
|
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]
|
|
|
|
N'oubliez pas d'appeler `infolist_free` pour libérer la mémoire utilisée par
|
|
|
|
l'infolist, car WeeChat ne libère par automatiquement cette mémoire.
|