Triggers - weechat/weechat GitHub Wiki
Important compatibility notes:
- All these triggers require WeeChat ≥ 1.1.
- With WeeChat ≥ 3.8, the trigger regex can start with a command letter:
s
for regex replace (default) ory
for chars translation. If using WeeChat ≤ 3.7, you must remove the leadings
(if present), and the commandy
is not supported. - You may need to replace
\S
with[^ ]
in regular expressions on non-GNU platform (eg. FreeBSD).
/trigger add url_color modifier "weechat_print" "${tg_tags} !~ irc_quit" ";[a-z]+://\S+;${color:32}${re:0}${color:reset};" ""
/trigger add greentext modifier "weechat_print" "${tg_message_nocolor} =~ ^>[^:._]" "/(.*)/${tg_prefix}\t${color:34}${tg_message}" ""
/trigger addreplace input_backtick modifier "500|input_text_display" "" "/(^| )(`[^`]+)($|(`)($|[,.?!:; ]))/${re:1}${color:,darkgray}${re:2}${re:4}${color:,default}${re:5}/"
/trigger addreplace print_backtick modifier "weechat_print" "" "/(^|\t|\d| )(`[^`]+`)([,.?!:; ]|$)/${re:1}${color:,darkgray}${re:2}${color:,default}${re:3}/"
/trigger add irc_join modifier 2000|weechat_print "${tg_tags} =~ ,irc_join," "/.*/${tg_prefix}\t${color:237}${tg_message_nocolor}"
/trigger add irc_join modifier 2000|weechat_print "${tg_tags} =~ ,irc_join," "/.*[^(]\((.*)\).*/${color:237}${tg_tag_nick} with host ${re:1} joined ${channel}/tg_message_nocolor /.*/${tg_prefix}\t${tg_message_nocolor}"
/trigger add irc_part modifier 2000|weechat_print "${tg_tags} =~ ,irc_part," "/.*[^(]\((.*)\).*\ (.*)/${color:237}${tg_tag_nick} with host ${re:1} part ${channel} with message ${re:2}/tg_message_nocolor /.*/${tg_prefix}\t${tg_message_nocolor}"
/trigger add irc_quit modifier 2000|weechat_print "${tg_tags} =~ ,irc_quit," "/.*[^(]\((.*)\).*\ (\(.*\))/${color:237}${tg_tag_nick} with host ${re:1} quit ${channel} with message ${re:2}/tg_message_nocolor /.*/${tg_prefix}\t${tg_message_nocolor}"
/trigger add irc_nick modifier 2000|weechat_print "${tg_tags} =~ ,irc_nick," "/.*irc_nick1_([^,]*),irc_nick2_([^,]*).*/You are now known as ${re:2}, formerly known as ${re:1}/tg_tags /.*/${tg_prefix}\t${tg_tags}"
/trigger add nick_color_action modifier "weechat_print" "${tg_tags} =~ ,irc_action, && ${tg_tags} !~ ,self_msg," "/.*/${info:nick_color,${tg_tag_nick}}${tg_prefix_nocolor}\t${tg_message}" "" "" "none"
/trigger add join modifier "weechat_print" "${tg_tags} =~ irc_join|irc_nick_back" ";\(\x1927([a-zA-Z0-9^~@:./_-]+)[^a-z]+\);${color:28}(${color:22}${re:1}${color:28}); ;([#&!]\S+);${color:0}${re:1};" ""
/trigger add part modifier "weechat_print" "${tg_tags} =~ irc_part" ";\(\x1927([a-zA-Z0-9^~@:./_-]+)[^a-z]+\);${color:124}(${color:88}${re:1}${color:124}); ;\(\x19...([^@]+)\x19..\);${color:124}(${color:88}${re:1}${color:124}); ;([#&]\S+);${color:238}${re:1}; ;([#&]\S+$);${color:0}${re:1};" ""
/trigger add quit modifier "weechat_print" "${tg_tags} =~ irc_quit" ";\(\x1927([a-zA-Z0-9^~@:./_-]+)[^a-z]+\);${color:88}(${color:52}${re:1}${color:88}); ;\(\x19...([^@]+)\x19..\);${color:88}(${color:52}${re:1}${color:88});" ""
/trigger add mode modifier "weechat_print" "${tg_tags} =~ irc_mode" ";Mode;${color:240}Mode; ; by ; ${color:240}by ; ;(\+\S+);${color:29}${re:1}; ;\[\x1c(-\S+);[${color:137}${re:1};" ""
/trigger add nick modifier "weechat_print" "${tg_tags} =~ irc_nick" ";is now known as;${color:242}is now known as;" ""
/trigger add disconnect modifier "weechat_print" "${tg_tags} !~ . && ${tg_buffer} !~ irc.server." "; irc: disconnected from server;\t$${color:240}irc: disconnected from server$;" ""
/trigger add userlabel modifier "weechat_print" "" "/^[^@]+@(.+)$/${re:1}/tg_tag_host /^.+$/${re:0} ${color:darkgray}${plugins.var.trigger.userlabel.${tg_tag_host}}" ""
This trigger uses hostname of user from variable ${tg_tag_host}
to determine what label should be appended. Since the variable contains both username and host, we strip it off using the first regex. The second regex is for appending the label that is stored in option plugins.var.trigger.userlabel.*
.
To test, set label [idiot]
for user with host unaffiliated/tomoe-mami/x-1769741
:
/set plugins.var.trigger.userlabel.unaffiliated/tomoe-mami/x-1769741 [idiot]
<botnick> <foo> message --> <foo> message
weechat_print level change:
/trigger add relaybot modifier weechat_print "${tg_tag_host} == ~bot@botmask" "/[^<]*<([^>]+)> (.*)/${re:1}\t${re:2}/"
IRC message level change:
/trigger add relaybot2 modifier "irc_in2_privmsg" "${nick} == botnick" "/^(:)(botnick)(!\S+@\S+ )(PRIVMSG #channel :)<(\S+)> (.*)/${re:1}${re:5}${re:3}${re:4}${re:6}/" ""
/trigger add relaybot modifier "weechat_print" "${buffer.full_name} != perl.highmon && ${tg_tag_nick} =~ ${plugins.var.trigger.relaybot.nick}" "/^([^\t]*)\t[[<]([^]>]+)(\]|>)\s?(.*)$/${color:red}→${info:nick_color,${re:2}}${re:2}\t${re:4}/" "" "" "none"
/trigger add relaybot_action modifier "weechat_print" "${tg_tags} =~ ,irc_action, && ${buffer.full_name} != perl.highmon && ${tg_tag_nick} =~ ${plugins.var.trigger.relaybot.nick}" "/^[^\t]*\t(\S*)\s[[<]([^]>]+)(\]|>)\s?(.*)$/${tg_prefix}\t${color:red}→${info:nick_color,${re:2}}${re:2}${color:reset} ${re:4}/" "" "" "none"
Create option plugins.var.trigger.relaybot.nick
and into it write a regex by which nicknames are matched for relay bots, for example ^relaybot*$
.
Shows messages in pink when a woman is talking and blue if he's a man. You need to enable the mouse. Then press the middle-click button on a nickname in the nicklist and press 'f' if she's a woman or 'm' for a man.
/key bindctxt cursor @item(buffer_nicklist):f /window ${_window_number};/trigger add female_${nick} modifier weechat_print "\${tg_tags} =~ ,irc_privmsg, && \${tg_tag_nick} == ${nick}" "/(.*)/\${tg_prefix}\t\${color:magenta}\${tg_message}/";/cursor stop
/key bindctxt cursor @item(buffer_nicklist):m /window ${_window_number};/trigger add male_${nick} modifier weechat_print "\${tg_tags} =~ ,irc_privmsg, && \${tg_tag_nick} == ${nick}" "/(.*)/\${tg_prefix}\t\${color:lightblue}\${tg_message}/";/cursor stop
/trigger add color_my_lines modifier "weechat_print" "${tg_tags} =~ ,nick_YOURNICK," "/.*/${tg_prefix}\t${color:196}${tg_message_nocolor}" ""
/trigger addreplace colorize_line_highlight line * "${highlight}" "/.*/${color:default,${weechat.color.chat_highlight_bg}}${re:0}/message
Adds /dim and /undim commands
/alias add dim trigger addreplace dim_$server_$1 modifier weechat_print "${tg_tag_nick} == $1 && \${server} == $server" "/(.*)/${color:darkgray}${tg_prefix_nocolor}\t${color:darkgray}${tg_message_nocolor}/"; print \---\t$1 is now dimmed on $server
/alias add undim trigger del dim_$server_$1; print \---\t$1 is no longer dimmed
Modifies dim trigger when the user changes nick
/trigger addreplace dim_change_nick signal *,irc_in_nick "" "" "/mute /trigger rename dim_${server}_${nick} dim_${server}_${text}; /mute /trigger set dim_${server}_${text} conditions \"\${tg_tag_nick} == ${text} && \${server} == ${server}\""
/trigger add no_color modifier "weechat_print" "${channel} =~ #weechat && ${tg_tags} =~ ,irc_privmsg," "/(.*)/${tg_prefix_nocolor}\t${tg_message_nocolor}" ""
/trigger add znctoserver modifier "irc_in_privmsg" "${host} == *[email protected] || ${host} == *[email protected] || ${host} == *[email protected] || ${host} == *[email protected]" "/.*//" "/print -buffer server.${server} znc: ${text}"
prefix_align_max
only works when using prefix alignment but nick length limiting may be useful without as well. Modify the length after ${curscr:
as desired.
/trigger addreplace nick_cut modifier weechat_print "" "/^([^\t]*)\t(.*)$/${cutscr:10,+,${re:1}}\t${re:2}/"
Only replace full URLs:
/trigger addreplace tcoexpand modifier weechat_print "${channel} =~ #twitter_" "!https://t.co/[^ ]+ <([^>…]+)>!https://${re:1}!"
Remove truncated expanded URLs:
/trigger addreplace notcoexpand modifier weechat_print "${channel} =~ #twitter_" "!<[^…]+…>!!"
- Highlight the connect msgs and the nick
- Highlight if the connect class is "main" (Inspircd)
- Makes it easy to see that a user is on an external connection
- Highlight the quit msgs and the nick
- Highlight xline msgs
- Makes it quick to see when dnsbl catches connections
/trigger addreplace ircd_notice_con modifier weechat_print "${tg_tags} =~ irc_notice" "/(CONNECT:)(.*: )([^ !]+)(!.*)/${color:02}${re:1}${color:reset}${re:2}${color:14}${re:3}${color:reset}${re:4}/" ""
/trigger addreplace ircd_notice_con_main modifier weechat_print "${tg_tags} =~ irc_notice" "/(CONNECT:)(.*class )(main)(.*)/${re:1}${re:2}${color:01}${re:3}${color:reset}${re:4}/" ""
/trigger addreplace ircd_notice_quit modifier weechat_print "${tg_tags} =~ irc_notice" "/(QUIT:)(.*: )([^ !]+)(!.*)/${color:03}${re:1}${color:reset}${re:2}${color:06}${re:3}${color:reset}${re:4}/" ""
/trigger addreplace ircd_notice_xline modifier weechat_print "${tg_tags} =~ irc_notice" "/(XLINE:)(.*)/${color:01}${re:1}${color:reset}${re:2}/" ""
E.g. to change the notify_message
tag to notify_private
for all messages in #weechat so messages shows as private messages in the hotlist and buflist:
/trigger addreplace weechat_notify_private line *;irc.libera.#weechat "" /,notify_message,/,notify_private,/tags
/trigger addreplace delete_jpq line "*;irc.freenode.*" "${tags} =~ ,irc_(join|part|quit)," "/.*//buffer_name"
/trigger addreplace delete_topic line "*;irc.freenode.#weechat" "${tags} =~ ,irc_topic," "/.*//buffer_name"
/trigger addreplace idlebot line "*;*;irc_notice+notify_private+nick_idlebot" "" "/.*/irc.libera.#idleRPG/buffer_name"
/trigger add jnotify signal *,irc_in_join "${server}.${channel}.${nick} =~ freenode.#weechat.FlashCode" "" "/exec -bg beep -f 400"
/trigger add dice_bot print "" "${name} == server.#my_channel && ${tg_message_nocolor} =~ ^!dice" "" "/exec -o -sh shuf -i 1-6 -n 1" "ok" "none"
More complicated than it needs to be because it HTML escapes "\", """, "&", "<" and ">" because of libnotify oddities and uses tg_message
as a temporary variable.
/trigger add osd print '' '${tg_highlight}' '/.*/${weechat.look.nick_prefix}${tg_prefix_nocolor}${weechat.look.nick_suffix} ${tg_message_nocolor}/ /&/&/ /[\\]/\/ /"/"/ /</</ />/>/' '/exec -norc -nosw notify-send -i weechat -- "${buffer.full_name}" "${tg_message}"'
Also notify on private messages:
/trigger add osd2 print '' '(${tg_highlight} || ${tg_tag_notify} == private) && ${buffer.notify} > 0' '/.*/${weechat.look.nick_prefix}${tg_prefix_nocolor}${weechat.look.nick_suffix} ${tg_message_nocolor}/ /&/&/ /[\\]/\/ /"/"/ /</</ />/>/' '/exec -norc -nosw notify-send -i weechat -- "${buffer.full_name}" "${tg_message}"'
/trigger add pong print "" "${type} == private && ${tg_message} == ping" "" "pong"
/trigger add foobar print "" "${tg_notify} && ${tg_tag_nick} && ${tg_message_nocolor} == .foo" "" "${tg_tag_nick}: bar"
/trigger add respond print "" "${tg_message_nocolor} =~ \(\((.*)\)\)" "/.*\(\((.*)\)\).*/${re:1}/" "your text: ${tg_message}" "ok"
/trigger add whois_on_query signal irc_pv_opened
/trigger set whois_on_query command /command -buffer ${buffer[${tg_signal_data}].full_name} * wii ${buffer[${tg_signal_data}].local_variables.channel}
A few notes:
- In a signal trigger,
${buffer}
always points to current buffer not the buffer where the signal occurred. - Because of point 1, we have to use
/command -buffer
to prevent Weechat from executing the command in the wrong buffer. - To get the buffer where the signal occurred and all its properties we have to use the hdata syntax:
${buffer[<pointer>].<property>}
. Inirc_pv_opened
signal, the variable${tg_signal_data}
contains the newly created buffer pointer so we use that. -
irc_pv_opened
signal doesn't have variable for the target/recipient nickname of a query buffer. There is${nick}
but it's for your own nickname. The only way to get the target nickname is by accessing buffer's local variablechannel
(not to be confused with IRC channel). That's why we use${buffer[${tg_signal_data}].local_variables.channel}
for/wii
parameter.
Create an Alias called aop that allows you to op (or any other mode +o, +v) a user based on their host on channel join (useful for networks without services) -- You have to use /aop on the buffer you want the auto op on, also this now works on networks other than freenode but you will need at least WeeChat 1.0-dev (git: v0.4.3-566-gfe872f2) [May 28th] as there was a bug originally.
/alias add aop /trigger addreplace opme$2 signal *,irc_in_join "${server}.${channel}.${host} =~ $server.$channel.$1" "" "/quote -server $server mode $channel +o ${nick}"
/aop *!*@example.org name
Sometimes you want people to be able to change the topic in your channel but you'd like to enforce a delay before the topic can be set again, thus when topic changes set +t, wait, set -t -- Example for channel ##vp on server named "freenode" (look at /help wait to adjust the delay):
/trigger addreplace topiclock signal *,irc_in_topic "${server}.${channel} =~ freenode.##vp" "" "/quote -server freenode mode ##vp +t;/wait 2m /quote -server freenode mode ##vp -t"
The above can be made generic using /alias like in the first example. irc_in_* is a signal name, this can be very useful, as you can see irc_in_join and irc_in_topic were used, but there are many more, just look at the tags.
/trigger addreplace jointhrottle_retry signal *,irc_in2_480;*,irc_in2_471 "" "" "/print -buffer irc.server.${server} Attempting rejoin to ${channel} in 1 minute; /wait 60 /join -noswitch -server ${server} ${channel}"
/trigger add awaylog print "" "${tg_highlight} && ${away}" "" "/print -buffer server.${server} ${color:darkgray}${buffer.short_name} ${tg_prefix}${color:${weechat.color.chat_nick_suffix}}${weechat.look.nick_suffix} ${tg_message}"
/trigger add beep_all_in_weechat print "irc.freenode.#weechat" "${tg_displayed} && ${tg_tags} !!- ,notify_none," "" "/print -beep"
/trigger add mybeep print "" "${tg_displayed} && (${tg_highlight} || ${tg_msg_pv})" "" "/print -beep;/exec -bg /usr/bin/play /home/user1/.weechat/glass.ogg" "ok" "none"
/trigger add otherbeep print "" "${tg_message} =~ urgent" "" "/print -beep;/exec -bg /usr/bin/play /home/user1/.weechat/glassdouble.ogg" "ok" "none"
/trigger add block_ctcp modifier "irc_in_privmsg" "${arguments} =~ ^[^ ]+ :${\x01}.*${\x01}$ && ${arguments} !~ ^[^ ]+ :${\x01}ACTION" "/.*//"
"channel" has to be your own nick
/trigger add block_query_FlashCode modifier "irc_in_privmsg" "${tg_modifier_data} == freenode && ${nick} == FlashCode && ${channel} == ${info:irc_nick,${server}}" "/.*//" ""
/trigger add quakenet_undernet_pm signal quakenet,irc_in_privmsg;undernet,irc_in_privmsg "${host} !~ (users.quakenet.org|users.undernet.org|[email protected]) && ${channel} == ${info:irc_nick,${server}}" "" "/msg -server ${server} ${nick} Please set the umode +x to chat with me.;/quote -server ${server} silence +${host}" "ok"
/trigger add replacebox modifier irc_out1_PRIVMSG "" "/\[x\]/☑/ /\[ \]/☐"
/trigger add spaces_out modifier "input_text_for_buffer" "" "/ +$//"
/trigger add apostrophe modifier "input_text_for_buffer" "${tg_string} !~ ^/" "/([a-zA-Z])'([a-zA-Z])/${re:1}’${re:2}/"
/trigger add apostrophe modifier "input_text_for_buffer;input_text_display" "${tg_string} !~ ^/" "/([a-zA-Z])'([a-zA-Z])/${re:1}’${re:2}/"
Toggle time display on buffer, like toggle_time.py
/trigger add cmd_toggle_time command toggle_time
/trigger set cmd_toggle_time regex /.*/${weechat.look.buffer_time_format}\n/tg_argv0 /^[^\n]+\n$//tg_argv0 /^\n$/${tg_argv1}/tg_argv0
/trigger set cmd_toggle_time command /mute /set weechat.look.buffer_time_format "${tg_argv0}"
The \n
in the regex part is needed because WeeChat's regex can not replace empty string (/^$/${tg_argv1}/tg_argv0
doesn't work).
After creating this trigger you can run /toggle_time
followed by format of time. For example: /toggle_time %H:%M:%S
On Weechat >= 1.8, you can simplify the trigger by removing the regex part and just use the new ${if:}
format:
/trigger set cmd_toggle_time regex ""
/trigger set cmd_toggle_time command /mute /set weechat.look.buffer_time_format "${if:${weechat.look.buffer_time_format}==?${tg_argv1}:}"
On Weechat >= 3.4, /toggle
is available and you no longer need a trigger to toggle the display of time in the chat area. Instead, you can simply run:
/mute /toggle weechat.look.buffer_time_format
Which you can bind to a key:
/key bind meta-t /mute /toggle weechat.look.buffer_time_format
/set weechat.look.hotlist_add_conditions "${away} || ${buffer} != ${window.buffer}"
/trigger addreplace windowswitch signal window_switch "" "" "/command -buffer ${buffer.full_name} * /buffer set hotlist -1"
Reset read marker when switching away from a buffer displayed in an inactive window (requires perlexec.pl)
/trigger add bufferswitch signal "buffer_switch" "" "" "/perlexec weechat::buffer_set(weechat::hdata_get_list(weechat::hdata_get('buffer'),'gui_buffer_last_displayed'), 'unread', 0)\;"
/trigger add force_redraw signal "window_switch;buffer_switch" "" "" "/wait 1ms /window refresh"
/trigger addreplace detach timer 10000;0;0 "" "" "/allchan /eval /perlexec weechat::command('', '/command -buffer irc.\${server}.\${channel} core /buffer hide') if ((${date:%s} - \${buffer[\${info:irc_buffer,\${server},\${channel}}].lines.last_line.data.date}) > 100 && '\${window.buffer.full_name}' !~ 'irc.\${server}.\${channel}' && '\${buffer[\${info:irc_buffer,\${server},\${channel}}].hotlist}' eq '0x0')"
And unhide them on any new messages, or if you manually switch to a hidden buffer
/trigger addreplace reattach print "" "${buffer.hidden} == 1 && ${tg_tag_notify} == message" "" "/command -buffer irc.$server.$channel core /buffer unhide"
/trigger addreplace reattach_on_switch signal buffer_switch "${buffer[${tg_signal_data}].hidden} == 1" "" "/command -buffer ${buffer[${tg_signal_data}].full_name} core /buffer unhide"
Temporarily unhide manually hidden buffers when they are relevant
If you have a manually hidden buffer, such as a large tech support channel, you might want to temporarily have this channel unhidden during a conversation that you are participating in. This trigger will unhide a hidden buffer whenever you say something in it. By default the buffer will be visible for an hour since your last message; you can adjust this time by setting plugins.var.trigger.unhide.time
to the desired number of seconds.
/trigger add unhide print "" "(${buffer.hidden} || ${trigger.trigger.hide_${buffer}.enabled}) && ${tg_displayed} && ${tg_tags} =~ ,self_msg," "" "/buffer unhide; /mute /trigger addreplace hide_${buffer} timer ${if:${plugins.var.trigger.unhide.time}?${plugins.var.trigger.unhide.time}:3600}000\;1\;1 '' '' '/buffer hide ${buffer.full_name}' '' delete"
/trigger add space signal "*,irc_in_privmsg;*,irc_out_privmsg" "" "" "/print -buffer ${server}.${channel}" "ok" "none"
This trigger will automatically change the buffer in a target window to that of the current buffer's server buffer.
First we have to store the target window's number in a variable, plugins.var.trigger.switch_active_server_buffer.target_window
. For instance, set it to the current window's number:
/eval /set plugins.var.trigger.switch_active_server_buffer.target_window "${window.number}"
Now we can use this variable in the trigger:
/trigger add switch_active_server_buffer signal "window_switch;buffer_switch" "${window.number} != ${plugins.var.trigger.switch_active_server_buffer.target_window} && ${server} !=" "" "/eval /mute -core /set plugins.var.trigger.switch_active_server_buffer.previous_window ${window.number}; /eval /mute -core /set plugins.var.trigger.switch_active_server_buffer.server_buffer ${server}; /window ${plugins.var.trigger.switch_active_server_buffer.target_window}; /buffer ${plugins.var.trigger.switch_active_server_buffer.server_buffer}; /window ${plugins.var.trigger.switch_active_server_buffer.previous_window}"
When you switch between windows, or buffers, it will now briefly switch to your target window, change its displayed buffer to the server buffer of the buffer you switched to, and immediately make the previous window active again.
/trigger add input_command_color modifier "500|input_text_display" "${tg_string} =~ ^/($|[^/])" "#/(.+)#${color:39}/${color:74}${re:1}#"
/trigger add preview_nick_colors modifier 2000|input_text_display
/trigger set preview_nick_colors conditions ${tg_string} =~ ^/set\s+weechat\.color\.chat_nick_colors\s+
/trigger set preview_nick_colors regex /^\S+\s+\S+(.+)$/${re:1}/tg_string_nocolor /([^",]+)/${color:${re:1}}${re:1}${color:default}/tg_string_nocolor /^(\S+\s+\S+).*$/${re:1}${tg_string_nocolor}/tg_string
Similar to script zerotab.py, this will complete the last nickname who sent message to current channel if you press Tab while Weechat's input is empty. It needs two triggers. The first one is for watching incoming message and putting the nickname who sent that message into buffer's localvar last_nick
.
/trigger add last_nick print irc.*;notify_message
/trigger set last_nick conditions ${tg_displayed} && ${type} == channel && ${tg_tag_nick} != ${nick}
/trigger set last_nick command /buffer set localvar_set_last_nick ${tg_tag_nick}
The second one is for inserting the value of localvar last_nick
to input bar.
/trigger add complete_last_nick command_run "/input complete_next"
/trigger set complete_last_nick conditions ${type} == channel && ${buffer.input_buffer_length} == 0 && ${last_nick}
/trigger set complete_last_nick command /input insert ${last_nick}
/trigger add spacecmd modifier input_text_for_buffer "${tg_string} =~ ^\s+/" /.*// "/print "${tg_string_nocolor}" prevented"
Avoid sending misformatted commands/messages, starting with a space (this /trigger replaces the unwanted_msg.py script)
/trigger add unwanted_msg modifier "input_text_for_buffer" "${tg_string} =~ ^\s+(/|.|,)" "/.*//" "/print -current -tags no_log unwanted message deleted:${tg_string_nocolor}" "" "none"
/trigger addreplace joinwithoutjoin modifier "input_text_for_buffer" "${tg_string} =~ ^#" "/.*//" "/join -server ${server} ${tg_string_nocolor}" ""
Prints TEST
to core buffer when meta-t
is pressed:
/trigger add key_test signal key_combo_default "${tg_signal_data} == ${\01}[t" "" "/print -core TEST"
To use modifiers in key_combo_*
signal triggers the following has to be taken into account:
-
meta-
should be checked as${\01}[
-
ctrl-
should be checked as${\01}
/trigger add relay_awayclear signal relay_client_connected "" "" "/away -all"
/trigger add relay_setaway signal relay_client_disconnected "" "" "/away -all I am away"
/trigger add relay_setaway signal relay_client_disconnected "${info:relay_client_count,connected} == 0" "" "/away -all I am away"
Useful for calling from an ACME client post-renew hook (killall -s HUP weechat
or similar).
/trigger addreplace hup_relay_ssl signal "3000|signal_sighup" "" "" "/relay sslcertkey" "ok_eat"
Using the google play nightly build (or newer), Opers will likely get a deluge of android notices due to connect/quits.
The following will reduce all server notices on all networks to be a normal message level, preventing android notices:
/trigger addreplace server_notice_priority line "" "${tags} =~ irc_notice" "/notify_private/notify_message/tags"
And this inspircd flavored version will leave XLINE (gline/etc) messages at the higher priority:
/trigger addreplace server_notice_priority line "" "${tags} =~ irc_notice && ${message} !~ XLINE:" "/notify_private/notify_message/tags"
We can use trigger to automatically set away status after certain amount of inactivity. A timer
trigger will be used for checking ${info:inactivity}
(variable that contains the amount of seconds with no key/mouse activity) and setting the away status. For removing the away status, we'll use a signal key_pressed
trigger. There is one problem with signal key_pressed
. Weechat treats special keys like arrow up/F1/Home/etc as multiple "keys" (for example, arrow up is ^[
, [
, and A
) and will call the trigger multiple times. This means we can not simply use /away
inside this trigger to remove the away status because it will send IRC command AWAY
to server multiple times. We're going to need a custom away command.
/trigger add cmd_custom_away command custom_away
/trigger set cmd_custom_away conditions (${tg_argv_eol1} && ${plugins.var.trigger.away_flag} != on) || (${tg_argv_eol1} == && ${plugins.var.trigger.away_flag} == on)
/trigger set cmd_custom_away regex /.+/${tg_argv1}\n/tg_argv0 /^.+\n$/on/tg_argv0 /^\n$/off/tg_argv0
/trigger set cmd_custom_away command /mute /away -all ${tg_argv_eol1};/mute /set plugins.var.trigger.away_flag ${tg_argv0}
That ${tg_argv_eol1} ==
in the condition
isn't a typo. That's how to check if a variable is not set inside trigger.
If you're using Weechat >= 1.2 you can replace plugins.var.trigger.away_flag
with environment variable (so you won't clutter plugins.conf
). For example:
/trigger set cmd_custom_away conditions (${tg_argv_eol1} && ${env:weechat_away} != on) || (${tg_argv_eol1} == && ${env:weechat_away} == on)
/trigger set cmd_custom_away command /mute /away -all ${tg_argv_eol1};/mute /set env weechat_away ${tg_argv0}
You can test the new command by running:
/custom_away foo
/custom_away bar
/custom_away
/custom_away
If the trigger is correctly set, only the first and the third command will have any effect.
Now we create the timer trigger and set its interval to 5 minutes (300000 ms):
/trigger addoff autoaway_idle_timer timer 300000;0;0
/trigger set autoaway_idle_timer conditions ${info:inactivity} >= 300
/trigger set autoaway_idle_timer command /custom_away Auto-away after 5 min. of no activity;/mute /trigger enable autoaway_idle_key;/wait 1s /mute /trigger disable autoaway_idle_timer
The /wait 1s
is needed because Weechat prevent a trigger from disabling itself while it's still running.
Next is the key pressed trigger:
/trigger addoff autoaway_idle_key signal key_pressed
/trigger set autoaway_idle_key command /custom_away;/mute /trigger enable autoaway_idle_timer;/wait 1s /mute /trigger disable autoaway_idle_key
Finally to test it just run /trigger enable autoaway_idle_timer
and idle for 5 minutes.
/trigger add upgrade_scripts signal day_changed "" "" "/script update;/wait 10s /script upgrade" "ok"
/trigger add cycle timer 5000 "${info:inactivity} > 10" "" "/buffer +1"
Auto kick ban a user with his host when you press 'B' on a nick in cursor mode (you need the perlexec.pl script).
There is a little problem: we /who the user in case his host do not figure in the infolist. But the /who will be useful only if the last channel the user joined is the channel we want to kickban him (https://github.com/weechat/weechat/issues/470) Otherwise you could remove /who ${nick} and put /who ${channel}. If you do that you may want to change /wait 2s to /wait 5s
/key bindctxt cursor @item(buffer_nicklist):b /window ${_window_number};/who ${channel};/wait 2s /perlexec my $infolist = weechat::infolist_get("irc_nick", "", q(${server},${channel},${nick}))\;weechat::infolist_next($infolist)\;my $host = (split("@", weechat::infolist_string($infolist, "host")))[1]\;if (!defined($host)) { weechat::command("", q(/print -core I dont have the host of ${nick} please try again))\; } else { weechat::command("", q(/trigger addreplace auto_kb_${server}_${channel}_${date:%Y_%m_%d_%H_%M_%S} signal ${server},irc_in_join "\${channel} =~ ${channel} && \${host} =~ ) . $host . q(" "" "/command -buffer irc.${server}.${channel} irc /kickban ${channel} ${nick}!*@) . $host . q( bye bye" "ok"))\;weechat::command("", q(/kickban ${channel} ${nick} bye bye))\; } weechat::infolist_free($infolist);/cursor stop
Use this to run a command after joining a channel, through autojoin
or manually:
/trigger add [name] signal "irc_channel_opened" "${buffer[${tg_signal_data}].full_name} =~ [channel_name]" "" "[command]"
Replace [name]
, [channel_name]
, and [command]
with what you're after, of course.
As as example, you may want to login to a channel bot, but said channel bot won't let you login to it unless you're in the same channel that it's in. Not a problem. Replace [command]
with something like /msg -server [server_name] [bot_nick] [msg_command]
, like this:
/msg -server freenode foobot login myname mypass
Put it all together and the trigger should look close to this:
/trigger add postjoincmd signal "irc_channel_opened" "${buffer[${tg_signal_data}].full_name} =~ #funtimes" "" "/msg -server freenode chanbot login myname mypass"
Huge thanks to nils_2 and sim642 in #weechat
for the information needed to put this together.
/trigger add kick_on_nick signal "*,irc_in_join" "${server}.${channel}.${nick} =* freenode.#weechat.flash*" "" "/wait 3 /command -buffer irc.${server}.${channel} irc /ban ${channel} ${nick}; /wait 3 /command -buffer irc.${server}.${channel} irc /kick ${channel} ${nick} Bye bye" "ok" "none"
The above triggers will not work if you reconnect to the irc-server and then rejoin the channels you were in, because the channel buffer already exists and so the irc_channel_opened
signal doesn't fire. In that case it's necessary to hook your trigger to the irc_in_join
signal.
/trigger addreplace [name] signal '*,irc_in_join' "${server}.${channel}.${nick} =~ [server].[channel].[your_nick]" "" "[command]"
The command stays the same, but I like to run it with /wait
because I want to make sure my nick is properly registered with NickServ before it runs:
/wait 60 /msg -server freenode foobot login myname mypass
Put it all together and the trigger should look close to this:
/trigger addreplace postjoincmd signal "*,irc_in_join" "${server}.${channel}.${nick} =~ freenode.#funtimes.MyNick" "" "/wait 60 /msg -server freenode chanbot login MyNick mypass"
Thanks to sim642, catbeard and echelon on #weechat
for their help.
Prints full buffer names into core buffer when they are closed. Useful for seeing what buffer you closed if you used /close
accidentally.
/trigger add close_report signal "buffer_closing" "" "" "/print -core Buffer closed: ${buffer[${tg_signal_data}].full_name}"
To run the command /upgrade -quit
when SIGTERM is received by WeeChat:
/trigger add sigterm signal "2000|signal_sigterm" "" "" "/upgrade -quit" "ok_eat" "none"
/trigger add hupgrade signal "signal_sighup" "" "" "/upgrade -quit" "ok" "none"
/trigger add numberjump modifier "2000|input_text_for_buffer" "${tg_string} =~ ^/[0-9]+$" "=\/([0-9]+)=/buffer *${re:1}=" "" "" "none"
(This trigger is obsolete with WeeChat ≥ 3.5. Use /autjoin command).
/trigger add autojoin signal "*,irc_in_join" "" "" "/autojoinem add ${server} ${channel};/mute save" "ok" "none"
/trigger add autopart signal "*,irc_in_part" "" "" "/autojoinem del ${server} ${channel};/mute save" "ok" "none"
Configure autojoin for all servers according to currently joined channels during /QUIT (requires autojoinem.py)
(This trigger is obsolete with WeeChat ≥ 3.5. Use /autojoin command).
/trigger add autojoinem_on_quit signal "quit" "" "" "/allchan /autojoinem add" "ok" "none"
Freenode incorrectly announced MONITOR
support in 005 message but actually doesn't support it so /notify doesn't work. This removes the incorrect support announcement, allowing fallback to polling.
/trigger add freenode_monitor modifier "irc_in_005" "${tg_modifier_data} == freenode" "/MONITOR ?//" ""
/trigger add click_channel_join focus chat "${_key} == button1 && ${_chat_word} ==* #*" "" "/command -buffer ${_buffer_full_name} * /join ${_chat_word}"
To only add the /join
command to the input line, rather than joining the channel directly:
/trigger add click_channel_join focus chat "${_key} == button1 && ${_chat_word} ==* #*" "" "/command -buffer ${_buffer_full_name} * /input insert /join ${_chat_word}"
Before using these, make sure to enable mouse mode by pressing alt+m if you haven't already.
Remember /trigger monitor trigger_name
and /debug tags
(run again to disable).
Documentation: https://weechat.org/files/doc/devel/weechat_user.en.html#trigger_plugin