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
|
2016-05-03 21:31:55 +02:00
|
|
|
|
:toc: left
|
2014-01-23 18:38:53 +01:00
|
|
|
|
:toclevels: 3
|
2016-05-03 21:31:55 +02:00
|
|
|
|
:toc-title: Table des matières
|
2016-05-04 23:12:35 +02:00
|
|
|
|
:sectnums:
|
2016-05-03 21:31:55 +02:00
|
|
|
|
:docinfo1:
|
2009-06-28 12:00:16 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Ce manuel documente le client de messagerie instantanée WeeChat, il fait
|
|
|
|
|
partie de WeeChat.
|
|
|
|
|
|
2016-12-04 13:13:41 +01:00
|
|
|
|
La dernière version de ce document peut être téléchargée sur cette page :
|
2014-12-13 09:16:09 +01:00
|
|
|
|
https://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
|
2016-12-04 13:13:41 +01:00
|
|
|
|
l'un des langages de script supportés :
|
2011-10-26 19:25:51 +02:00
|
|
|
|
|
|
|
|
|
* python
|
|
|
|
|
* perl
|
|
|
|
|
* ruby
|
|
|
|
|
* lua
|
|
|
|
|
* tcl
|
|
|
|
|
* guile (scheme)
|
2015-03-07 15:16:37 +01:00
|
|
|
|
* javascript
|
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
|
|
|
|
|
2016-11-20 23:04:55 +01:00
|
|
|
|
* Vous devez utiliser `import weechat`.
|
2016-06-15 08:01:45 +02:00
|
|
|
|
* Les fonctions `+print*+` se nomment `+prnt*+` en python (car _print_ est un mot
|
2016-11-20 23:04:55 +01:00
|
|
|
|
clé réservé).
|
|
|
|
|
* Les fonctions sont appelées par `weechat.xxx(arg1, arg2, ...)`.
|
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
|
|
|
|
|
2016-11-20 23:04:55 +01:00
|
|
|
|
* Les fonctions sont appelées par `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
|
|
|
|
|
2016-11-20 23:04:55 +01: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
|
2016-12-04 15:02:07 +01:00
|
|
|
|
fonction `Weechat.config_new_option` reçoit les fonctions de rappel dans un tableau de
|
|
|
|
|
6 chaînes de caractères (3 fonctions de rappel + 3 chaînes de données), donc un appel à
|
2016-12-04 13:13:41 +01:00
|
|
|
|
cette fonction ressemble à ceci :
|
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
|
|
|
|
|
2013-11-04 21:41:34 +01:00
|
|
|
|
==== Lua
|
2011-10-26 19:25:51 +02:00
|
|
|
|
|
2016-11-20 23:04:55 +01:00
|
|
|
|
* Les fonctions sont appelées par `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
|
|
|
|
|
2016-11-20 23:04:55 +01:00
|
|
|
|
* Les fonctions sont appelées par `weechat::xxx arg1 arg2 ...`.
|
2011-10-26 19:25:51 +02:00
|
|
|
|
|
2013-11-04 21:41:34 +01:00
|
|
|
|
==== Guile (scheme)
|
2011-10-26 19:25:51 +02:00
|
|
|
|
|
2016-11-20 23:04:55 +01:00
|
|
|
|
* Les fonctions sont appelées par `(weechat:xxx arg1 arg2 ...)`.
|
2011-10-26 19:25:51 +02:00
|
|
|
|
* 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
|
2016-12-04 13:13:41 +01:00
|
|
|
|
paramètres excède la limite de Guile :
|
2011-10-26 19:25:51 +02:00
|
|
|
|
** config_new_section
|
|
|
|
|
** config_new_option
|
|
|
|
|
** bar_new
|
2009-06-28 12:00:16 +02:00
|
|
|
|
|
2015-03-07 15:16:37 +01:00
|
|
|
|
==== Javascript
|
|
|
|
|
|
2016-11-20 23:04:55 +01:00
|
|
|
|
* Les fonctions sont appelées par `weechat.xxx(arg1, arg2, ...);`.
|
2015-03-07 15:16:37 +01: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.
|
|
|
|
|
|
2016-12-04 13:13:41 +01: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
|
|
|
|
|
2016-12-04 13:13:41 +01:00
|
|
|
|
Paramètres :
|
2009-06-28 12:00:16 +02:00
|
|
|
|
|
2016-12-04 13:13:41 +01:00
|
|
|
|
* _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)
|
2016-12-04 13:13:41 +01:00
|
|
|
|
* _charset_ : chaîne, jeu de caractères du script (si votre script est UTF-8,
|
2012-11-05 22:04:49 +01:00
|
|
|
|
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
|
|
|
|
|
2016-12-04 13:13:41 +01:00
|
|
|
|
Exemple, pour chaque langage :
|
2009-06-28 12:00:16 +02:00
|
|
|
|
|
2016-12-04 13:13:41 +01:00
|
|
|
|
* Python :
|
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
|
|
|
|
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
|
|
|
|
|
2016-12-04 13:13:41 +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", "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
|
|
|
|
|
2016-12-04 13:13:41 +01:00
|
|
|
|
* Ruby :
|
2009-06-28 12:00:16 +02:00
|
|
|
|
|
|
|
|
|
[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
|
|
|
|
|
2016-12-04 13:13:41 +01:00
|
|
|
|
* Lua :
|
2009-06-28 12:00:16 +02:00
|
|
|
|
|
|
|
|
|
[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
|
|
|
|
|
2016-12-04 13:13:41 +01:00
|
|
|
|
* Tcl :
|
2009-06-28 12:00:16 +02:00
|
|
|
|
|
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
|
|
|
|
|
2016-12-04 13:13:41 +01: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" "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
|
|
|
|
|
2016-12-04 13:13:41 +01:00
|
|
|
|
* Javascript :
|
2015-03-07 15:16:37 +01:00
|
|
|
|
|
|
|
|
|
[source,javascript]
|
|
|
|
|
----
|
|
|
|
|
weechat.register("test_js", "FlashCode", "1.0", "GPL3", "Test script", "", "");
|
|
|
|
|
weechat.print("", "Bonjour, du script javascript !");
|
|
|
|
|
----
|
|
|
|
|
|
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,
|
2016-12-04 13:13:41 +01:00
|
|
|
|
par exemple :
|
2013-01-26 07:48:20 +01:00
|
|
|
|
|
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
|
2013-11-04 21:41:34 +01:00
|
|
|
|
----
|
2013-01-26 07:48:20 +01:00
|
|
|
|
|
2016-12-04 13:13:41 +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
|
|
|
|
----
|
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
|
2013-11-04 21:41:34 +01:00
|
|
|
|
----
|
2009-06-28 12:00:16 +02:00
|
|
|
|
|
2016-05-04 22:19:27 +02:00
|
|
|
|
Vous pouvez faire un lien dans le répertoire _langage/autoload_ pour charger
|
2009-06-28 12:00:16 +02:00
|
|
|
|
automatiquement le script quand WeeChat démarre.
|
|
|
|
|
|
2016-12-04 13:13:41 +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
|
2016-05-04 22:19:27 +02:00
|
|
|
|
dans le répertoire _autoload_ est automatiquement créé.
|
2013-01-26 07:48:20 +01:00
|
|
|
|
|
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.
|
2016-05-04 22:19:27 +02:00
|
|
|
|
Vous pouvez consulter la _Référence API Extension WeeChat_ pour le détail de
|
2016-12-04 13:13:41 +01:00
|
|
|
|
chaque fonction de l'API : prototype, paramètres, valeurs de retour, exemples.
|
2009-06-28 12:00:16 +02:00
|
|
|
|
|
2016-05-04 22:19:27 +02:00
|
|
|
|
Il est important de bien faire la différence entre une _extension_ et un
|
2016-12-04 13:13:41 +01:00
|
|
|
|
_script_ : une _extension_ est un fichier binaire compilé et chargé avec la
|
2016-05-04 22:19:27 +02:00
|
|
|
|
commande `/plugin`, tandis qu'un _script_ est un fichier texte chargé par une
|
|
|
|
|
extension comme _python_ par la commande `/python`.
|
2009-06-28 12:00:16 +02:00
|
|
|
|
|
2016-05-04 22:19:27 +02:00
|
|
|
|
Quand votre script _test.py_ appelle une fonction de l'API WeeChat, le chemin
|
2016-12-04 13:13:41 +01:00
|
|
|
|
est le suivant :
|
2009-06-28 12:00:16 +02:00
|
|
|
|
|
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
|
|
|
|
|
2016-12-04 15:02:07 +01:00
|
|
|
|
Quand WeeChat appelle une fonction de rappel dans votre script _test.py_, le chemin
|
2016-12-04 13:13:41 +01:00
|
|
|
|
est inversé :
|
2009-06-28 12:00:16 +02:00
|
|
|
|
|
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
|
2016-12-04 13:13:41 +01:00
|
|
|
|
WeeChat), vous pouvez faire :
|
2009-10-09 15:46:29 +02:00
|
|
|
|
|
|
|
|
|
[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
|
2016-12-04 13:13:41 +01:00
|
|
|
|
rapport de crash ;)
|
2009-10-09 15:46:29 +02:00
|
|
|
|
|
2010-03-07 22:23:44 +01:00
|
|
|
|
[[callbacks]]
|
2016-12-04 15:02:07 +01:00
|
|
|
|
=== Fonctions de rappel
|
2009-10-09 15:46:29 +02:00
|
|
|
|
|
2016-12-04 15:02:07 +01:00
|
|
|
|
Toutes les fonction de rappel WeeChat doivent retourner WEECHAT_RC_OK ou
|
|
|
|
|
WEECHAT_RC_ERROR (l'exception est la fonction de rappel du modificateur, qui
|
|
|
|
|
retourne une chaîne de caractères).
|
2009-10-09 15:46:29 +02:00
|
|
|
|
|
2016-12-04 15:02:07 +01:00
|
|
|
|
Les fonction de rappel 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
|
2009-10-09 15:46:29 +02:00
|
|
|
|
valeur (ce n'est pas un pointeur).
|
|
|
|
|
|
2016-12-04 15:02:07 +01:00
|
|
|
|
Exemple de fonction de rappel, pour chaque langage :
|
2013-01-26 08:22:04 +01:00
|
|
|
|
|
2016-12-04 13:13:41 +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
|
|
|
|
|
2016-12-04 13:13:41 +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
|
|
|
|
|
2016-12-04 13:13:41 +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
|
|
|
|
|
2016-12-04 13:13:41 +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
|
|
|
|
|
2016-12-04 13:13:41 +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
|
|
|
|
|
2016-12-04 13:13:41 +01: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
|
|
|
|
|
2016-12-04 13:13:41 +01: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");
|
|
|
|
|
----
|
|
|
|
|
|
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
|
2016-05-04 22:19:27 +02:00
|
|
|
|
_Référence API Extension WeeChat_.
|
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
|
|
|
|
=== Fonctions
|
2009-06-28 12:00:16 +02:00
|
|
|
|
|
2016-12-04 13:13:41 +01:00
|
|
|
|
Liste des fonctions de l'API script :
|
2009-06-28 12:00:16 +02:00
|
|
|
|
|
2016-05-05 10:01:02 +02:00
|
|
|
|
[width="75",cols="1,3",options="header"]
|
2013-11-04 21:41:34 +01:00
|
|
|
|
|===
|
2016-05-05 10:01:02 +02:00
|
|
|
|
| Catégorie | Fonctions
|
|
|
|
|
|
|
|
|
|
| général |
|
2010-03-07 22:23:44 +01:00
|
|
|
|
register
|
2016-05-05 10:01:02 +02:00
|
|
|
|
|
|
|
|
|
| extensions |
|
2010-03-07 22:23:44 +01:00
|
|
|
|
plugin_get_name
|
2016-05-05 10:01:02 +02:00
|
|
|
|
|
|
|
|
|
| chaînes |
|
|
|
|
|
charset_set +
|
|
|
|
|
iconv_to_internal +
|
|
|
|
|
iconv_from_internal +
|
|
|
|
|
gettext +
|
|
|
|
|
ngettext +
|
|
|
|
|
strlen_screen +
|
|
|
|
|
string_match +
|
|
|
|
|
string_has_highlight +
|
|
|
|
|
string_has_highlight_regex +
|
|
|
|
|
string_mask_to_regex +
|
|
|
|
|
string_remove_color +
|
|
|
|
|
string_is_command_char +
|
|
|
|
|
string_input_for_buffer +
|
|
|
|
|
string_eval_expression +
|
|
|
|
|
string_eval_path_home
|
|
|
|
|
|
|
|
|
|
| répertoires |
|
|
|
|
|
mkdir_home +
|
|
|
|
|
mkdir +
|
|
|
|
|
mkdir_parents
|
|
|
|
|
|
|
|
|
|
| listes triées |
|
|
|
|
|
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 |
|
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
|
|
|
|
|
|
|
|
|
|
| associations de touches |
|
|
|
|
|
key_bind +
|
|
|
|
|
key_unbind
|
|
|
|
|
|
|
|
|
|
| affichage |
|
|
|
|
|
prefix +
|
|
|
|
|
color +
|
2016-12-04 13:13:41 +01:00
|
|
|
|
print (pour python : prnt) +
|
2017-06-11 08:20:12 +02:00
|
|
|
|
print_date_tags (pour python : prnt_date_tags) +
|
2016-12-04 13:13:41 +01:00
|
|
|
|
print_y (pour python : prnt_y) +
|
2016-05-05 10:01:02 +02:00
|
|
|
|
log_print
|
|
|
|
|
|
|
|
|
|
| hooks |
|
|
|
|
|
hook_command +
|
|
|
|
|
hook_command_run +
|
|
|
|
|
hook_timer +
|
|
|
|
|
hook_fd +
|
|
|
|
|
hook_process +
|
|
|
|
|
hook_process_hashtable +
|
|
|
|
|
hook_connect +
|
|
|
|
|
hook_print +
|
|
|
|
|
hook_signal +
|
|
|
|
|
hook_signal_send +
|
|
|
|
|
hook_hsignal +
|
|
|
|
|
hook_hsignal_send +
|
|
|
|
|
hook_config +
|
|
|
|
|
hook_completion +
|
2017-06-11 08:20:12 +02:00
|
|
|
|
hook_completion_get_string +
|
2016-05-05 10:01:02 +02:00
|
|
|
|
hook_completion_list_add +
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
| 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 +
|
|
|
|
|
buffer_string_replace_local_var +
|
|
|
|
|
buffer_match_list
|
|
|
|
|
|
|
|
|
|
| fenêtres |
|
|
|
|
|
current_window +
|
|
|
|
|
window_search_with_buffer +
|
|
|
|
|
window_get_integer +
|
|
|
|
|
window_get_string +
|
|
|
|
|
window_get_pointer +
|
|
|
|
|
window_set_title
|
|
|
|
|
|
|
|
|
|
| liste des pseudos |
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
| barres |
|
|
|
|
|
bar_item_search +
|
|
|
|
|
bar_item_new +
|
|
|
|
|
bar_item_update +
|
|
|
|
|
bar_item_remove +
|
|
|
|
|
bar_search +
|
|
|
|
|
bar_new +
|
|
|
|
|
bar_set +
|
|
|
|
|
bar_update +
|
|
|
|
|
bar_remove
|
|
|
|
|
|
|
|
|
|
| commandes |
|
2010-03-07 22:23:44 +01:00
|
|
|
|
command
|
2016-05-05 10:01:02 +02:00
|
|
|
|
|
2010-03-07 22:23:44 +01:00
|
|
|
|
| infos |
|
2016-05-05 10:01:02 +02:00
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
| 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
|
|
|
|
|
2016-12-04 13:13:41 +01:00
|
|
|
|
Liste des constantes de l'API script :
|
2009-06-28 12:00:16 +02:00
|
|
|
|
|
2016-05-05 10:01:02 +02:00
|
|
|
|
[width="75%",cols="1,3",options="header"]
|
2013-11-04 21:41:34 +01:00
|
|
|
|
|===
|
2016-05-05 10:01:02 +02:00
|
|
|
|
|
|
|
|
|
| Catégorie | Constantes
|
|
|
|
|
|
|
|
|
|
| codes retour |
|
|
|
|
|
WEECHAT_RC_OK +
|
|
|
|
|
WEECHAT_RC_OK_EAT +
|
|
|
|
|
WEECHAT_RC_ERROR
|
|
|
|
|
|
2010-03-07 22:23:44 +01:00
|
|
|
|
| fichiers de configuration |
|
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
|
|
|
|
|
|
|
|
|
|
| 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 +
|
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
|
|
|
|
== 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
|
2016-05-04 22:19:27 +02:00
|
|
|
|
_Référence API Extension WeeChat_.
|
2010-03-07 22:23:44 +01:00
|
|
|
|
|
|
|
|
|
[[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>>).
|
|
|
|
|
|
2016-12-04 13:13:41 +01:00
|
|
|
|
Exemples :
|
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
|
|
|
|
# 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
|
2016-12-04 13:13:41 +01:00
|
|
|
|
# (le nom complet d'un tampon est extension.nom, par exemple : "irc.freenode.#weechat")
|
2010-03-07 22:23:44 +01:00
|
|
|
|
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]
|
2015-03-07 15:16:37 +01:00
|
|
|
|
La fonction d'affichage est appelée `print` en
|
|
|
|
|
Perl/Ruby/Lua/Tcl/Guile/Javascript et `prnt` en Python.
|
2010-03-07 22:23:44 +01:00
|
|
|
|
|
|
|
|
|
[[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].
|
|
|
|
|
|
2016-12-04 13:13:41 +01:00
|
|
|
|
Exemples :
|
2010-03-07 22:23:44 +01:00
|
|
|
|
|
|
|
|
|
[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.
|
|
|
|
|
|
2016-12-04 15:02:07 +01:00
|
|
|
|
Deux fonctions de rappel peuvent être appelés (ils sont optionnels) : une pour
|
|
|
|
|
les données en entrée (quand vous tapez du texte et pressez [Enter] sur le
|
|
|
|
|
tampon), l'autre est appelée lorsque le tampon est fermé (par exemple avec
|
|
|
|
|
`/buffer close`).
|
2010-03-07 22:23:44 +01:00
|
|
|
|
|
2016-12-04 13:13:41 +01:00
|
|
|
|
Exemple :
|
2010-03-07 22:23:44 +01:00
|
|
|
|
|
|
|
|
|
[source,python]
|
2013-11-04 21:41:34 +01:00
|
|
|
|
----
|
2016-12-04 15:02:07 +01:00
|
|
|
|
# fonction de rappel pour les données reçues en entrée
|
2010-03-07 22:23:44 +01:00
|
|
|
|
def buffer_input_cb(data, buffer, input_data):
|
|
|
|
|
# ...
|
|
|
|
|
return weechat.WEECHAT_RC_OK
|
|
|
|
|
|
2016-12-04 15:02:07 +01:00
|
|
|
|
# fonction de rappel appelée lorsque le tampon est fermé
|
2010-03-07 22:23:44 +01:00
|
|
|
|
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.
|
|
|
|
|
|
2016-12-04 13:13:41 +01:00
|
|
|
|
Exemples :
|
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
|
|
|
|
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
|
|
|
|
|
|
|
|
|
Il est possible d'ajouter, lire ou supprimer des variables locales dans le
|
2016-12-04 13:13:41 +01:00
|
|
|
|
tampon :
|
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
|
|
|
|
# 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
|
2016-12-04 13:13:41 +01:00
|
|
|
|
WeeChat :
|
2010-03-07 22:23:44 +01:00
|
|
|
|
|
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.
|
|
|
|
|
|
2016-12-04 13:13:41 +01:00
|
|
|
|
Exemple :
|
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 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
|
|
|
|
|
2016-12-04 13:13:41 +01:00
|
|
|
|
Puis sous WeeChat :
|
2010-03-07 22:23:44 +01:00
|
|
|
|
|
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
|
|
|
|
|
2016-12-04 13:13:41 +01:00
|
|
|
|
Exemple :
|
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 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
|
2016-12-04 15:02:07 +01:00
|
|
|
|
fonction de rappel sera appelée quand des données seront prêtes. Elle peut être
|
|
|
|
|
appelée plusieurs fois.
|
2010-03-07 22:23:44 +01:00
|
|
|
|
|
2016-12-04 15:02:07 +01:00
|
|
|
|
Pour le dernier appel à votre fonction de rappel, _rc_ est positionné à 0 ou
|
|
|
|
|
une valeur positive, c'est le code retour de la commande.
|
2010-03-07 22:23:44 +01:00
|
|
|
|
|
2016-12-04 13:13:41 +01:00
|
|
|
|
Exemple :
|
2010-03-07 22:23:44 +01:00
|
|
|
|
|
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.
|
|
|
|
|
|
2016-12-04 13:13:41 +01:00
|
|
|
|
Exemple de transfert d'URL sans option : la page HTML sera reçue comme "out"
|
2016-12-04 15:02:07 +01:00
|
|
|
|
dans la fonction de rappel (sortie standard du processus) :
|
2012-01-19 13:56:48 +01:00
|
|
|
|
|
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:
|
2016-12-04 13:13:41 +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
|
|
|
|
|
|
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]
|
|
|
|
|
Toutes les infos disponibles à propos de WeeChat sont sur la page
|
2014-12-13 09:16:09 +01:00
|
|
|
|
https://weechat.org/dev/info
|
2013-03-16 16:06:16 +01:00
|
|
|
|
|
2016-12-04 13:13:41 +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_ :
|
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("", "Fin du transfert (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
|
|
|
|
----
|
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
|
2016-05-04 22:19:27 +02:00
|
|
|
|
_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.
|
|
|
|
|
|
2016-12-04 13:13:41 +01:00
|
|
|
|
Exemple :
|
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
|
|
|
|
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.
|
|
|
|
|
|
2016-12-04 13:13:41 +01:00
|
|
|
|
Exemple :
|
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
|
|
|
|
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", "")
|
2015-03-07 15:16:37 +01:00
|
|
|
|
# pour les autres langages, remplacez "python" par le langage (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
|
|
|
|
==== 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
|
2016-12-04 13:13:41 +01:00
|
|
|
|
weechat.prnt("", "la valeur de l'option weechat.look.item_time_format est : %s"
|
2010-03-07 22:23:44 +01:00
|
|
|
|
% (weechat.config_string(weechat.config_get("weechat.look.item_time_format"))))
|
|
|
|
|
|
|
|
|
|
# booléen
|
2016-12-04 13:13:41 +01:00
|
|
|
|
weechat.prnt("", "la valeur de l'option weechat.look.day_change est : %d"
|
2010-03-07 22:23:44 +01:00
|
|
|
|
% (weechat.config_boolean(weechat.config_get("weechat.look.day_change"))))
|
|
|
|
|
|
|
|
|
|
# entier
|
2016-12-04 13:13:41 +01:00
|
|
|
|
weechat.prnt("", "la valeur de l'option weechat.look.scroll_page_percent est : %d"
|
2010-03-07 22:23:44 +01:00
|
|
|
|
% (weechat.config_integer(weechat.config_get("weechat.look.scroll_page_percent"))))
|
|
|
|
|
|
|
|
|
|
# couleur
|
2016-12-04 13:13:41 +01:00
|
|
|
|
weechat.prnt("", "la valeur de l'option weechat.color.chat_delimiters est : %s"
|
2010-03-07 22:23:44 +01:00
|
|
|
|
% (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,
|
2016-12-04 13:13:41 +01:00
|
|
|
|
PRIVMSG, 301, ..) :
|
2010-03-07 22:23:44 +01:00
|
|
|
|
|
|
|
|
|
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):
|
2016-12-04 13:13:41 +01:00
|
|
|
|
# signal est par exemple : "freenode,irc_in2_join"
|
|
|
|
|
# signal_data est le message IRC, par exemple : ":nick!user@host JOIN :#canal"
|
2010-03-07 22:23:44 +01:00
|
|
|
|
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) a rejoint ce canal !" % (msg["nick"], msg["host"]))
|
2010-03-07 22:23:44 +01:00
|
|
|
|
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
|
|
|
|
|
2015-06-27 17:00:53 +02:00
|
|
|
|
Le résultat est une table de hachage avec les clés suivantes
|
2016-12-04 13:13:41 +01:00
|
|
|
|
(les exemples de valeurs sont construits avec ce message :
|
|
|
|
|
`@time=2015-06-27T16:40:35.000Z :nick!user@host PRIVMSG #weechat :hello!`) :
|
2015-06-27 17:00:53 +02:00
|
|
|
|
|
|
|
|
|
[width="100%",cols="1,^2,10,8",options="header"]
|
|
|
|
|
|===
|
|
|
|
|
| Clé | Version de WeeChat | Description | Exemple
|
|
|
|
|
|
|
|
|
|
| tags | ≥ 0.4.0 |
|
2016-11-26 23:19:41 +01:00
|
|
|
|
Les étiquettes dans le message (peut être vide). |
|
2015-06-27 17:00:53 +02:00
|
|
|
|
`time=2015-06-27T16:40:35.000Z`
|
|
|
|
|
|
|
|
|
|
| message_without_tags | ≥ 0.4.0 |
|
|
|
|
|
Le message sans les étiquettes (la même chose que le message s'il n'y a pas
|
2016-11-26 23:19:41 +01:00
|
|
|
|
d'étiquettes). |
|
2015-06-27 17:00:53 +02:00
|
|
|
|
`:nick!user@host PRIVMSG #weechat :hello!`
|
|
|
|
|
|
|
|
|
|
| nick | ≥ 0.3.4 |
|
2016-11-26 23:19:41 +01:00
|
|
|
|
Le pseudo d'origine. |
|
2015-06-27 17:00:53 +02:00
|
|
|
|
`nick`
|
|
|
|
|
|
|
|
|
|
| host | ≥ 0.3.4 |
|
2016-11-26 23:19:41 +01:00
|
|
|
|
L'hôte d'origine (incluant le pseudo). |
|
2015-06-27 17:00:53 +02:00
|
|
|
|
`nick!user@host`
|
|
|
|
|
|
|
|
|
|
| command | ≥ 0.3.4 |
|
2016-11-26 23:19:41 +01:00
|
|
|
|
La commande (_PRIVMSG_, _NOTICE_, ...). |
|
2015-06-27 17:00:53 +02:00
|
|
|
|
`PRIVMSG`
|
|
|
|
|
|
|
|
|
|
| channel | ≥ 0.3.4 |
|
2016-11-26 23:19:41 +01:00
|
|
|
|
Le canal cible. |
|
2015-06-27 17:00:53 +02:00
|
|
|
|
`#weechat`
|
|
|
|
|
|
|
|
|
|
| arguments | ≥ 0.3.4 |
|
2016-11-26 23:19:41 +01:00
|
|
|
|
Les paramètres de la commande (incluant le canal). |
|
2015-06-27 17:00:53 +02:00
|
|
|
|
`#weechat :hello!`
|
|
|
|
|
|
|
|
|
|
| text | ≥ 1.3 |
|
2016-11-26 23:19:41 +01:00
|
|
|
|
Le texte (par exemple un message utilisateur). |
|
2015-06-27 17:00:53 +02:00
|
|
|
|
`hello!`
|
|
|
|
|
|
2015-08-14 21:25:27 +02:00
|
|
|
|
| pos_command | ≥ 1.3 |
|
2016-11-26 23:19:41 +01:00
|
|
|
|
La position de _command_ dans le message ("-1" si _command_ n'a pas été trouvé). |
|
2015-08-14 21:25:27 +02:00
|
|
|
|
`47`
|
|
|
|
|
|
|
|
|
|
| pos_arguments | ≥ 1.3 |
|
2016-11-26 23:19:41 +01:00
|
|
|
|
La position de _arguments_ dans le message ("-1" si _arguments_ n'a pas été trouvé). |
|
2015-08-14 21:25:27 +02:00
|
|
|
|
`55`
|
|
|
|
|
|
|
|
|
|
| pos_channel | ≥ 1.3 |
|
2016-11-26 23:19:41 +01:00
|
|
|
|
La position de _channel_ dans le message ("-1" si _channel_ n'a pas été trouvé). |
|
2015-08-14 21:25:27 +02:00
|
|
|
|
`55`
|
|
|
|
|
|
2015-06-27 17:00:53 +02:00
|
|
|
|
| pos_text | ≥ 1.3 |
|
2016-11-26 23:19:41 +01:00
|
|
|
|
La position de _text_ dans le message ("-1" si _text_ n'a pas été trouvé). |
|
2015-06-27 17:00:53 +02:00
|
|
|
|
`65`
|
|
|
|
|
|===
|
|
|
|
|
|
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",
|
|
|
|
|
# "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
|
|
|
|
==== 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.
|
|
|
|
|
|
2016-12-04 13:13:41 +01:00
|
|
|
|
Exemple :
|
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
|
|
|
|
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
|
2016-05-04 22:19:27 +02:00
|
|
|
|
_info_get("version_number")_, donc vous devez vérifier que la valeur de retour
|
2010-03-07 22:23:44 +01:00
|
|
|
|
n'est *pas* vide.
|
|
|
|
|
|
2016-12-04 13:13:41 +01:00
|
|
|
|
Pour obtenir la version sous forme de chaîne :
|
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
|
|
|
|
# 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
|
|
|
|
----
|
2016-12-04 13:13:41 +01:00
|
|
|
|
# répertoire de WeeChat, par exemple : "/home/xxxx/.weechat"
|
|
|
|
|
weechat.prnt("", "Répertoire WeeChat : %s" % weechat.info_get("weechat_dir", ""))
|
2010-03-07 22:23:44 +01:00
|
|
|
|
|
|
|
|
|
# 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.
|
|
|
|
|
|
2016-12-04 13:13:41 +01:00
|
|
|
|
Exemple :
|
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
|
|
|
|
# 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.
|