1
= Guida allo Scripting di WeeChat
2
:author: Sébastien Helleu
3
:email: flashcode@flashtux.org
9
Questo manuale documenta il client di chat WeeChat, ed è parte
12
La versione più recente di questo documento si trova qui:
13
http://weechat.org/doc
19
WeeChat (Wee Enhanced Environment for Chat) è un client di chat libero,
20
veloce e leggero, realizzato per molti sistemi operativi.
22
Questo manuale documenta come scrivere script per WeeChat, usando uno dei
23
linguaggi di scripting supportati:
33
Quasi tutti gli esempi in questo manuale sono scritti in Python, ma l'API
34
è identica per gli altri linguaggi.
36
[[scripts_in_weechat]]
39
[[languages_specificities]]
40
=== Specifiche per i linguaggi
44
* E necessario `import weechat`
45
* Le funzioni `print*` sono chiamate `prnt*` in python (dato che 'print'
46
è una parola riservata)
47
* Le funzioni sono chiamate con `weechat.xxx(arg1, arg2, ...)`
51
* Le funzioni sono chiamate con `weechat::xxx(arg1, arg2, ...);`
55
* E necessario definire 'weechat_init' e chiamare 'register' all'interno
56
* Le funzioni sono chiamate con `Weechat.xxx(arg1, arg2, ...)`
57
* A causa di una limitazione di Ruby (massimo 15 argomenti per funzione), la
58
funzione `WeeChat.config_new_option` riceve le callback in un array di 6
59
stringhe (3 callback + 3 stringhe di dati), così che una chiamata a questa
64
Weechat.config_new_option(config, section, "name", "string", "description of option", "", 0, 0,
65
"value", "value", 0, ["check_cb", "", "change_cb", "", "delete_cb", ""])
70
* Le funzioni sono chiamate con `weechat.xxx(arg1, arg2, ...)`
74
* Le funzioni sono chiamate con `weechat::xxx arg1 arg2 ...`
78
* Le funzioni sono chiamate con `(weechat:xxx arg1 arg2 ...)`
79
* Le seguenti funzioni prendono un elenco di argomenti (invece di più argomenti
80
come per le altre funzioni), poiché il numero di argomenti eccede il numero
81
di argomenti consentiti in Guile:
87
=== Registrare una funzione
89
Tutti gli script WeeChat devono "registrare" loro stessi in WeeChat, e questo
90
deve essere la prima funzione chiamata nello script di WeeChat.
96
weechat.register(name, author, version, license, description, shutdown_function, charset)
101
* 'name': stringa, nome interno dello script
102
* 'author': stringa, nome dell'autore
103
* 'version': stringa, versione dello script
104
* 'license': stringa, licenza dello script
105
* 'description': stringa, breve descrizione dello script
106
* 'shutdown_function': stringa, nome della funzione chiamata quando lo script
107
viene scaricato (può essere una stringa vuota)
108
* 'charset': stringa, set caratteri dello script (se il proprio script è in UTF-8,
109
è possibile utilizzare un valore nullo qui, dato che UTF-8 è il set caratteri predefinito)
111
Esempio di script, per ogni linguaggio:
119
weechat.register("test_python", "FlashCode", "1.0", "GPL3", "Test script", "", "")
120
weechat.prnt("", "Hello, from python script!")
127
weechat::register("test_perl", "FlashCode", "1.0", "GPL3", "Test script", "", "");
128
weechat::print("", "Hello, from perl script!");
136
Weechat.register("test_ruby", "FlashCode", "1.0", "GPL3", "Test script", "", "")
137
Weechat.print("", "Hello, from ruby script!")
138
return Weechat::WEECHAT_RC_OK
146
weechat.register("test_lua", "FlashCode", "1.0", "GPL3", "Test script", "", "")
147
weechat.print("", "Hello, from lua script!")
154
weechat::register "test_tcl" "FlashCode" "1.0" "GPL3" "Test script" "" ""
155
weechat::print "" "Hello, from tcl script!"
162
(weechat:register "test_scheme" "FlashCode" "1.0" "GPL3" "Test script" "" "")
163
(weechat:print "" "Hello, from scheme script!")
167
=== Caricare uno script
169
Si raccomanda di usare il plugin "script" per caricare gli script, ad esempio:
172
/script load script.py
173
/script load script.pl
174
/script load script.rb
175
/script load script.lua
176
/script load script.tcl
177
/script load script.scm
180
Ogni linguaggio ha anche il suo comando specifico:
183
/python load python/script.py
184
/perl load perl/script.pl
185
/ruby load ruby/script.rb
186
/lua load lua/script.lua
187
/tcl load tcl/script.tcl
188
/guile load guile/script.scm
191
È possibile creare un link nella directory 'linguaggio/autoload' per caricare
192
automaticamente gli script all'avvio di WeeChat.
194
Ad esempio con Python:
197
$ cd ~/.weechat/python/autoload
202
Quando viene installato un script con il comando `/script install` il link nella
203
directory 'autoload' viene creato automaticamente'.
205
[[differences_with_c_api]]
206
== Differenze con le API in C
208
Le API per gli script sono quasi identiche di quelle per i plugin C.
209
È possibile consultare '*' per i dettagli su ogni funzione nelle API:
210
prototipo, argomenti, valori restituiti, esempi.
212
È importante fare la differenza tra un 'plugin' ed uno 'script':
213
un plugin è un file binario compilato e caricato con il comando
214
`plugin`, mentre uno 'script' è un file di testo caricato tramite
215
un plugin come 'python' con il comando `python`.
217
Quando il proprio script 'test.py' chiama una funzione delle API di
218
Weechat, il path è simile a questo:
221
┌──────────────────────┐ ╔══════════════════╗
222
│ python plugin │ ║ WeeChat "core" ║
223
├────────────┬─────────┤ ╟─────────┐ ║
224
test.py ─────► │ script API │ C API │ ─────► ║ C API │ ║
225
└────────────┴─────────┘ ╚═════════╧════════╝
228
Quando WeeChat chiama una callback nel proprio script 'test.py', è
229
l'opposto del path precedente:
232
╔══════════════════╗ ┌──────────────────────┐
233
║ WeeChat "core" ║ │ python plugin │
234
║ ┌─────────╢ ├─────────┬────────────┤
235
║ │ C API ║ ─────► │ C API │ script API │ ─────► test.py
236
╚════════╧═════════╝ └─────────┴────────────┘
242
Come è già noto probabilmente, non esistono realmente i "puntatori"
243
negli script. Quando le funzioni API restituiscono un puntatore, viene
244
covertito in una stringa per lo script.
246
Ad esempio, se la funzione restituisce il puntatore 0x1234ab56, lo
247
script riceverà la stringa "0x1234ab56".
249
E quando una funzione API si aspetta un puntatore nell'argomento, lo script
250
deve fornire quel valore stringa. Il plugin C lo convertirà in un puntatore reale
251
prima di chiamare la funzione API in C.
253
Sono consentite stringhe vuote oppure "0x0", valgono come NULL in C.
254
Ad esempio, per stampare dei dati sul buffer core (il buffer principale di
255
WeeChat), è possibile fare questo:
259
weechat.prnt("", "hi!")
263
In molte funzioni, per motivi legati alla velocità, WeeChat non verifica se
264
il puntatore è corretto oppure no. È il proprio lavoro controllare che si
265
stia fornendo un puntatore valido, altrimenti potrebbe comparire una
266
bella segnalazione per un errore ;)
271
Quasi tutte le callback di WeeChat devono restituire WEECHAT_RC_OK
272
oppure WEECHAT_RC_ERROR (l'eccezione è la callback modifier, che
273
restituisce una stringa).
275
Le callback in C utilizzano un argomento "data", che è un puntatore.
276
Nelle API per gli script, questo "data" è una stringa con un qualsiasi
277
valore (non è un puntatore).
279
Esempio di callback, per ogni linguaggio:
285
def timer_cb(data, remaining_calls):
286
weechat.prnt("", "timer! data=%s" % data)
287
return weechat.WEECHAT_RC_OK
289
weechat.hook_timer(1000, 0, 1, "timer_cb", "test")
297
my ($data, $remaining_calls) = @_;
298
weechat::print("", "timer! data=$data");
299
return weechat::WEECHAT_RC_OK;
302
weechat::hook_timer(1000, 0, 1, "timer_cb", "test");
309
def timer_cb(data, remaining_calls)
310
Weechat.print("", "timer! data=#{data}");
311
return Weechat::WEECHAT_RC_OK
314
Weechat.hook_timer(1000, 0, 1, "timer_cb", "test");
321
function timer_cb(data, remaining_calls)
322
weechat.print("", "timer! data="..data)
323
return weechat.WEECHAT_RC_OK
326
weechat.hook_timer(1000, 0, 1, "timer_cb", "test")
333
proc timer_cb { data remaining_calls } {
334
weechat::print {} "timer! data=$data"
335
return $::weechat::WEECHAT_RC_OK
338
weechat::hook_timer 1000 0 1 timer_cb test
345
(define (timer_cb data remaining_calls)
346
(weechat:print "" (string-append "timer! data=" data))
347
weechat:WEECHAT_RC_OK
350
(weechat:hook_timer 1000 0 1 "timer_cb" "test")
356
Per maggiori informazioni sulle funzioni nelle API,
357
consultare 'Referenze API per Plugin di WeeChat'.
359
[[script_api_functions]]
362
Elenco di funzioni nelle API per gli script:
364
[width="100%",cols="^1,10",options="header"]
366
| Categoria | Funzioni
372
charset_set, iconv_to_internal, iconv_from_internal, gettext, ngettext, +
373
strlen_screen, string_match, string_has_highlight, string_has_highlight_regex,
374
string_mask_to_regex, string_remove_color, string_is_command_char,
375
string_input_for_buffer, string_eval_expression
377
mkdir_home, mkdir, mkdir_parents
379
list_new, list_add, list_search, list_search_pos, list_casesearch,
380
list_casesearch_pos, list_get, list_set, list_next, list_prev, list_string,
381
list_size, list_remove, list_remove_all, list_free
382
| file di configurazione |
383
config_new, config_new_section, config_search_section, config_new_option,
384
config_search_option, +
385
config_string_to_boolean, config_option_reset, config_option_set,
386
config_option_set_null, config_option_unset, config_option_rename,
387
config_option_is_null, config_option_default_is_null, +
388
config_boolean, config_boolean_default, config_integer, config_integer_default,
389
config_string, config_string_default, config_color, config_color_default, +
390
config_write_option, config_write_line, config_write, config_read,
392
config_option_free, config_section_free_options, config_section_free,
394
config_get, config_get_plugin, config_is_set_plugin, config_set_plugin,
395
config_set_desc_plugin, config_unset_plugin
396
| combinazione tasti |
399
prefix, color, print (for python: prnt), print_date_tags (for python:
400
prnt_date_tags), print_y (for python: prnt_y), log_print
402
hook_command, hook_command_run, hook_timer, hook_fd, hook_process,
403
hook_process_hashtable, hook_connect, hook_print, hook_signal,
404
hook_signal_send, hook_hsignal, hook_hsignal_send, hook_config,
405
hook_completion, hook_completion_list_add, hook_modifier, hook_modifier_exec,
406
hook_info, hook_info_hashtable, hook_infolist, hook_focus, hook_set, unhook,
409
buffer_new, current_buffer, buffer_search, buffer_search_main, buffer_clear,
410
buffer_close, buffer_merge, buffer_unmerge, buffer_get_integer,
411
buffer_get_string, buffer_get_pointer, buffer_set,
412
buffer_string_replace_local_var, buffer_match_list
414
current_window, window_search_with_buffer, window_get_integer,
415
window_get_string, window_get_pointer, window_set_title
417
nicklist_add_group, nicklist_search_group, nicklist_add_nick,
418
nicklist_search_nick, nicklist_remove_group, nicklist_remove_nick,
419
nicklist_remove_all, nicklist_group_get_integer, nicklist_group_get_string,
420
nicklist_group_get_pointer, nicklist_group_set, nicklist_nick_get_integer,
421
nicklist_nick_get_string, nicklist_nick_get_pointer, nicklist_nick_set
423
bar_item_search, bar_item_new, bar_item_update, bar_item_remove, bar_search,
424
bar_new, bar_set, bar_update, bar_remove
428
info_get, info_get_hashtable
430
infolist_new, infolist_new_item, infolist_new_var_integer,
431
infolist_new_var_string, infolist_new_var_pointer, infolist_new_var_time, +
432
infolist_get, infolist_next, infolist_prev, infolist_reset_item_cursor, +
433
infolist_fields, infolist_integer, infolist_string, infolist_pointer, +
434
infolist_time, infolist_free
436
hdata_get, hdata_get_var_offset, hdata_get_var_type_string,
437
hdata_get_var_array_size, hdata_get_var_array_size_string,
438
hdata_get_var_hdata, hdata_get_list, hdata_check_pointer, hdata_move,
439
hdata_search, hdata_char, hdata_integer, hdata_long, hdata_string,
440
hdata_pointer, hdata_time, hdata_hashtable, hdata_update, hdata_get_string
442
upgrade_new, upgrade_write_object, upgrade_read, upgrade_close
445
[[script_api_constants]]
448
Elenco di costanti nelle API per gli script:
450
[width="100%",cols="^1,10",options="header"]
452
| Categoria | Costanti
453
| codici restituiti |
454
WEECHAT_RC_OK, WEECHAT_RC_OK_EAT, WEECHAT_RC_ERROR
455
| file di configurazione |
456
WEECHAT_CONFIG_READ_OK, WEECHAT_CONFIG_READ_MEMORY_ERROR,
457
WEECHAT_CONFIG_READ_FILE_NOT_FOUND, WEECHAT_CONFIG_WRITE_OK,
458
WEECHAT_CONFIG_WRITE_ERROR, WEECHAT_CONFIG_WRITE_MEMORY_ERROR, +
459
WEECHAT_CONFIG_OPTION_SET_OK_CHANGED, WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE,
460
WEECHAT_CONFIG_OPTION_SET_ERROR, WEECHAT_CONFIG_OPTION_SET_OPTION_NOT_FOUND,
461
WEECHAT_CONFIG_OPTION_UNSET_OK_NO_RESET, WEECHAT_CONFIG_OPTION_UNSET_OK_RESET,
462
WEECHAT_CONFIG_OPTION_UNSET_OK_REMOVED, WEECHAT_CONFIG_OPTION_UNSET_ERROR
464
WEECHAT_LIST_POS_SORT, WEECHAT_LIST_POS_BEGINNING, WEECHAT_LIST_POS_END
466
WEECHAT_HOTLIST_LOW, WEECHAT_HOTLIST_MESSAGE, WEECHAT_HOTLIST_PRIVATE,
467
WEECHAT_HOTLIST_HIGHLIGHT
469
WEECHAT_HOOK_PROCESS_RUNNING, WEECHAT_HOOK_PROCESS_ERROR
470
| hook su connessione |
471
WEECHAT_HOOK_CONNECT_OK, WEECHAT_HOOK_CONNECT_ADDRESS_NOT_FOUND,
472
WEECHAT_HOOK_CONNECT_IP_ADDRESS_NOT_FOUND, WEECHAT_HOOK_CONNECT_CONNECTION_REFUSED,
473
WEECHAT_HOOK_CONNECT_PROXY_ERROR, WEECHAT_HOOK_CONNECT_LOCAL_HOSTNAME_ERROR,
474
WEECHAT_HOOK_CONNECT_GNUTLS_INIT_ERROR, WEECHAT_HOOK_CONNECT_GNUTLS_HANDSHAKE_ERROR,
475
WEECHAT_HOOK_CONNECT_MEMORY_ERROR, WEECHAT_HOOK_CONNECT_TIMEOUT,
476
WEECHAT_HOOK_CONNECT_SOCKET_ERROR
478
WEECHAT_HOOK_SIGNAL_STRING, WEECHAT_HOOK_SIGNAL_INT, WEECHAT_HOOK_SIGNAL_POINTER
484
Questo capitolo spiega alcuni compiti comuni, con degli esempi.
485
Verranno utilizzati soltanto degli elementi parziali contenuti
486
nelle API, per un riferimento completo consultare
487
'Referenze API per Plugin di WeeChat'.
492
[[buffers_display_messages]]
493
==== Visualizzare messaggi
495
Una stringa vuota è utilizzata spesso per lavorare con il buffer core di
496
WeeChat. Per gli altri buffer, è necessario fornire un puntatore (come
497
stringa, consultare <<pointers,pointers>>).
503
# visualizza "hello" sul buffer core
504
weechat.prnt("", "hello")
506
# visualizza "hello" sul buffer core, ma non salva sul file di log
507
# (solo versioni >= 0.3.3)
508
weechat.prnt_date_tags("", 0, "no_log", "hello")
510
# visualizza il prefisso "==>" ed il messaggio "hello" sul buffer corrente
511
# (prefisso e messaggio vanno separati da una tabulazione)
512
weechat.prnt(weechat.current_buffer(), "==>\thello")
514
# visualizza un messaggio di errore sul buffer core (con il prefisso di errore)
515
weechat.prnt("", "%swrong arguments" % weechat.prefix("error"))
517
# visualizza messaggio con il colore sul buffer core
518
weechat.prnt("", "text %syellow on blue" % weechat.color("yellow,blue"))
520
# cerca buffer e visualizza messaggiosearch buffer and display message
521
# (il nome completo del buffer è plugin.nome, ad esempio: "irc.freenode.#weechat")
522
buffer = weechat.buffer_search("irc", "freenode.#weechat")
523
weechat.prnt(buffer, "message on #weechat channel")
525
# altra soluzione per cercare un buffer IRC (migliore)
526
# (nota: server e canale sono separati da virgola)
527
buffer = weechat.info_get("irc_buffer", "freenode,#weechat")
528
weechat.prnt(buffer, "message on #weechat channel")
532
La funzione print si chiama `print` in Perl/Ruby/Lua/Tcl e `prnt` in Python.
534
[[buffers_send_text]]
535
==== Invia testo al buffer
537
È possibile inviare del testo o un comando ad un buffer. È esattamente come
538
se si digitasse del testo o un comando, seguiti da [Enter].
542
// TRANSLATION MISSING
545
# execute command "/help" on current buffer (result is on core buffer)
546
weechat.command("", "/help")
548
# invia "hello" sul canale IRC #weechat (gli utenti sul canale vedranno il messaggio)
549
buffer = weechat.info_get("irc_buffer", "freenode,#weechat")
550
weechat.command(buffer, "hello")
554
==== Creare un nuovo buffer
556
È possibile creare un nuovo buffer nel proprio script, per poi utilizzarlo per
557
visualizzare i messaggi.
559
Possono essere chiamate due callback (sono opzionali): una per i dati in
560
input (quando viene digitato del testo e premuto [Enter] sul buffer), l'altra
561
quando il buffer viene chiuso (ad esempio con `/buffer close`).
567
# callback per i dati ricevuti in input
568
def buffer_input_cb(data, buffer, input_data):
570
return weechat.WEECHAT_RC_OK
572
# callback chiamata alla chiusura del buffer
573
def buffer_close_cb(data, buffer):
575
return weechat.WEECHAT_RC_OK
578
buffer = weechat.buffer_new("mybuffer", "buffer_input_cb", "", "buffer_close_cb", "")
581
weechat.buffer_set(buffer, "title", "Questo titolo è per il mio buffer.")
583
# disabilita il logging, impostando la variabile locale "no_log" ad "1"
584
weechat.buffer_set(buffer, "localvar_set_no_log", "1")
587
[[buffers_properties]]
588
==== Proprietà dei buffer
590
Si possono leggere le proprietà del buffer, come stringa, intero o puntatore.
596
buffer = weechat.current_buffer()
598
number = weechat.buffer_get_integer(buffer, "number")
599
name = weechat.buffer_get_string(buffer, "name")
600
short_name = weechat.buffer_get_string(buffer, "short_name")
603
È possibile aggiungere, leggere o eliminare le variabili locali nel buffer:
607
# aggiunge la variabile locale
608
weechat.buffer_set(buffer, "localvar_set_myvar", "my_value")
610
# legge la variabile locale
611
myvar = weechat.buffer_get_string(buffer, "localvar_myvar")
613
# elimina la variabile locale
614
weechat.buffer_set(buffer, "localvar_del_myvar", "")
617
Per impostare le variabili locali di un buffer, digitare questo comando
628
==== Aggiungere un nuovo comando
630
Aggiunge un comando personalizzato con `hook_command`. Si può fare uso di
631
un template di completamento personalizzato per completare gli argomenti
638
def my_command_cb(data, buffer, args):
640
return weechat.WEECHAT_RC_OK
642
hook = weechat.hook_command("myfilter", "descrizione di myfilter",
643
"[list] | [enable|disable|toggle [name]] | [add name plugin.buffer tags regex] | [del name|-all]",
644
"descrizione degli argomenti...",
646
" || enable %(filters_names)"
647
" || disable %(filters_names)"
648
" || toggle %(filters_names)"
649
" || add %(filters_names) %(buffers_plugins_names)|*"
650
" || del %(filters_names)|-all",
659
/myfilter arguments...
663
==== Aggiungere un timer
665
Aggiungere un timer con `hook_timer`.
671
def timer_cb(data, remaining_calls):
673
return weechat.WEECHAT_RC_OK
675
# timer chiamato ogni minuto quandi i secondi sono 00
676
weechat.hook_timer(60 * 1000, 60, 0, "timer_cb", "")
680
==== Eseguire un processo in background
682
È possibile eseguire un processo in background con `hook_process`. La
683
callback verrà chiamata quando i dati sono pronti. Può essere chiamata
686
Per l'ultima chiamata alla callback, 'rc' è impostato a zero o su un
687
valore positivo, è il codice restituito dal comando.
695
def my_process_cb(data, command, rc, out, err):
696
global process_output
698
process_output += out
700
weechat.prnt("", process_output)
701
return weechat.WEECHAT_RC_OK
703
weechat.hook_process("/bin/ls -l /etc", 10 * 1000, "my_process_cb", "")
707
==== Trasferimento URL
709
_Novità nella versione 0.3.7._
711
Per scaricare un URL (o inviare verso un URL), è necessario usare la funzione
712
`hook_process` oppure `hook_process_hashtable` se ci fosse bisogno di impostare
713
delle opzioni per il trasferimento dell'URL.
715
Esempio di trasferimento di un URL senza opzioni: la pagina HTML verrà
716
ricevuta come "out" nella callback (output standard di un processo):
720
# Mostra la versione stabile corrente di WeeChat.
723
def weechat_process_cb(data, command, rc, out, err):
724
global weechat_version
726
weechat_version += out
728
weechat.prnt("", "Current WeeChat stable is: %s" % weechat_version)
729
return weechat.WEECHAT_RC_OK
731
weechat.hook_process("url:http://weechat.org/dev/info/stable/",
732
30 * 1000, "weechat_process_cb", "")
736
Tutte le informazioni disponibili su Weechat sono sulla pagina
737
http://weechat.org/dev/info
739
Esempio di trasferimento di un URL con un'opzione: scaricare l'ultimo pacchetto
740
di sviluppo di WeeChat nel file '/tmp/weechat-devel.tar.gz':
744
def my_process_cb(data, command, rc, out, err):
746
weechat.prnt("", "End of transfer (rc=%s)" % rc)
747
return weechat.WEECHAT_RC_OK
749
weechat.hook_process_hashtable("url:http://weechat.org/files/src/weechat-devel.tar.gz",
750
{ "file_out": "/tmp/weechat-devel.tar.gz" },
751
30 * 1000, "my_process_cb", "")
754
Per maggiori informazioni sul trasferimento degli URL e le opzioni disponibili,
755
consultare le funzioni `hook_process` e `hook_process_hashtable` in 'Referenze
759
=== Configurazione / opzioni
761
[[config_options_set_script]]
762
==== Impostare l'opzione per lo script
764
La funzione `config_is_set_plugin` viene utilizzare per verificare se un'opzione
765
è impostata oppure no, e `config_set_plugin` per impostare l'opzione.
772
"option1" : "value1",
773
"option2" : "value2",
774
"option3" : "value3",
776
for option, default_value in script_options.items():
777
if not weechat.config_is_set_plugin(option):
778
weechat.config_set_plugin(option, default_value)
781
[[config_options_detect_changes]]
782
==== Rilevare le modifiche
784
È necessario utilizzare `hook_config` per essere notificati se l'utente dovesse
785
modificare alcune opzioni dello script.
791
SCRIPT_NAME = "myscript"
795
def config_cb(data, option, value):
796
"""Callback called when a script option is changed."""
797
# for example, read all script options to script variables...
799
return weechat.WEECHAT_RC_OK
803
weechat.hook_config("plugins.var.python." + SCRIPT_NAME + ".*", "config_cb", "")
804
# for other languages, change "python" with your language ("perl", "ruby", "lua" or "tcl")
807
[[config_options_weechat]]
808
==== Leggere le opzioni di WeeChat
810
La funzione `config_get` restituisce il puntatore all'opzione. Poi, in base al tipo
811
di opzione, è necessario chiamare `config_string`, `config_boolean`,
812
`config_integer` oppure `config_color`.
817
weechat.prnt("", "value of option weechat.look.item_time_format is: %s"
818
% (weechat.config_string(weechat.config_get("weechat.look.item_time_format"))))
821
weechat.prnt("", "value of option weechat.look.day_change is: %d"
822
% (weechat.config_boolean(weechat.config_get("weechat.look.day_change"))))
825
weechat.prnt("", "value of option weechat.look.scroll_page_percent is: %d"
826
% (weechat.config_integer(weechat.config_get("weechat.look.scroll_page_percent"))))
829
weechat.prnt("", "value of option weechat.color.chat_delimiters is: %s"
830
% (weechat.config_color(weechat.config_get("weechat.color.chat_delimiters"))))
836
[[irc_catch_messages]]
837
==== Catturare messaggi
839
Il plugin IRC invia due segnali per un messaggio ricevuto (`xxx` è il nome
840
interno del server IRC, `yyy` è il nome del comando IRC come JOIN, QUIT,
844
segnale inviato prima di esaminare il messaggio
847
segnale inviato dopo aver esaminato il messaggio
851
def join_cb(data, signal, signal_data):
852
# signal è per esempio: "freenode,irc_in2_join"
853
# signal_data è il messaggio IRC message, ad esempio: ":nick!user@host JOIN :#channel"
854
nick = weechat.info_get("irc_nick_from_host", signal_data)
855
server = signal.split(",")[0]
856
channel = signal_data.split(":")[-1]
857
buffer = weechat.info_get("irc_buffer", "%s,%s" % (server, channel))
859
weechat.prnt(buffer, "Eheh, %s has joined this channel!" % nick)
860
return weechat.WEECHAT_RC_OK
862
# può essere utile qui utilizzare "*" come server, per catturare
863
# i messaggi JOIN su tutti i server IRC
864
weechat.hook_signal("*,irc_in2_join", "join_cb", "")
867
[[irc_modify_messages]]
868
==== Modificare i messaggi
870
Il plugin IRC invia un "modificatore" chiamato "irc_in_xxx" ("xxx" è il comando
871
IRC) per un messaggio ricevuto, in modo da poterlo modificare.
875
def modifier_cb(data, modifier, modifier_data, string):
876
# aggiunge il nome del server a tutti i messaggi ricevuti
877
# (ok non è molto utile, ma è solo un esempio!)
878
return "%s %s" % (string, modifier_data)
880
weechat.hook_modifier("irc_in_privmsg", "modifier_cb", "")
884
A malformed message could crash WeeChat or cause severe problems!
885
Un messaggio errato può mandare in crash WeeChat o causare seri problemi!
887
[[irc_message_parse]]
888
==== Verifica messaggio
890
_Novità nella versione 0.3.4._
892
È possibile verificare un messaggio irc con una info_hashtable chiamata
897
dict = weechat.info_get_hashtable("irc_message_parse",
898
{ "message": ":nick!user@host PRIVMSG #weechat :message here" })
899
weechat.prnt("", "dict: %s" % dict)
902
# dict: {'nick': 'nick', 'host': 'nick!user@host', 'command': 'PRIVMSG', 'arguments': '#weechat :message here', 'channel': '#weechat'}
908
[[infos_weechat_version]]
909
==== Versione di WeeChat
911
Il modo migliore per verificare la versione è richiedere "version_number" e
912
comparare l'intero con il numero di versione esadecimale.
918
version = weechat.info_get("version_number", "") or 0
919
if int(version) >= 0x00030200:
920
weechat.prnt("", "This is WeeChat 0.3.2 or newer")
922
weechat.prnt("", "This is WeeChat 0.3.1 or older")
926
Le versioni ≤ 0.3.1.1 restituiscono una stringa vuota per
927
'info_get("version_number")', per cui bisogna verificare che
928
il valore restituito *non* sia vuoto.
930
To get version as string:
934
# this will display for example "Version 0.3.2"
935
weechat.prnt("", "Version %s" % weechat.info_get("version", ""))
939
==== Altre informazioni
943
# la directory home di WeeChat, ad esempio: "/home/xxxx/.weechat"
944
weechat.prnt("", "WeeChat home dir: %s" % weechat.info_get("weechat_dir", ""))
946
# inattività della tastiera
947
weechat.prnt("", "Inactivity since %s seconds" % weechat.info_get("inactivity", ""))
954
==== Leggere una lista info
956
È possibile leggere una lista info compilata da WeeChat
963
# legge la lista info "buffer", per ottenere la lista dei buffer
964
infolist = weechat.infolist_get("buffer", "", "")
966
while weechat.infolist_next(infolist):
967
name = weechat.infolist_string(infolist, "name")
968
weechat.prnt("", "buffer: %s" % name)
969
weechat.infolist_free(infolist)
973
Non dimenticare di chiamare `infolist_free` per liberare la memoria
974
utilizzata dalla lista info, perché WeeChat non libererà automaticamente