Skip to content

Commit

Permalink
buffer_autoclose.py 0.6: add setting to prefer closing some buffers
Browse files Browse the repository at this point in the history
E.g. the Matrix script maps private rooms with multiple people to
buffers in weechat which are nominally not private. This means that
these rooms pile up, which is normally solved for real 1:1 private
chats.

Fix the problem by adding a way to autoclose also non-private buffers.

No behavior is changed unless the new config option is set.
  • Loading branch information
vmiklos committed May 4, 2024
1 parent 2db7f4a commit 9bf4ff4
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion python/buffer_autoclose.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
# (this script requires WeeChat 0.3.0 or newer)
#
# History:
# 2024-05-04, Miklos Vajna
# version 0.6: Allow autoclosing explicitly listed non-private buffers as well
# 2018-04-10, Sébastien Helleu <flashcode@flashtux.org>
# version 0.5: fix infolist_time for WeeChat >= 2.2 (WeeChat returns a long
# integer instead of a string)
Expand All @@ -37,14 +39,15 @@

SCRIPT_NAME = "buffer_autoclose"
SCRIPT_AUTHOR = "xt <xt@bash.no>"
SCRIPT_VERSION = "0.5"
SCRIPT_VERSION = "0.6"
SCRIPT_LICENSE = "GPL3"
SCRIPT_DESC = "Automatically close inactive private message buffers"

settings = {
'interval': '1', # How often in minutes to check
'age_limit': '30', # How old in minutes before auto close
'ignore': '', # Buffers to ignore (use full name: server.buffer_name)
'prefer': '', # Buffers to prefer, even if they are not private (use full name: server.buffer_name)
}

if w.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION, SCRIPT_LICENSE,
Expand All @@ -66,6 +69,10 @@ def get_all_buffers():
infolist = w.infolist_get('buffer', '', '')
while w.infolist_next(infolist):
buffer_type = w.buffer_get_string(w.infolist_pointer(infolist, 'pointer'), 'localvar_type')
name = w.buffer_get_string(w.infolist_pointer(infolist, 'pointer'), 'name')
if name in w.config_get_plugin('prefer').split(','):
buffers.append(w.infolist_pointer(infolist, 'pointer'))
continue
if buffer_type == 'private': # we only close private message buffers for now
buffers.append(w.infolist_pointer(infolist, 'pointer'))
w.infolist_free(infolist)
Expand Down

0 comments on commit 9bf4ff4

Please sign in to comment.