···11-# -*- coding: utf-8 -*-
22-#
33-# Copyright (c) 2013-2020 by nils_2 <weechatter@arcor.de>
44-#
55-# add/del channel(s) to/from autojoin option
66-#
77-# This program is free software; you can redistribute it and/or modify
88-# it under the terms of the GNU General Public License as published by
99-# the Free Software Foundation; either version 3 of the License, or
1010-# (at your option) any later version.
1111-#
1212-# This program is distributed in the hope that it will be useful,
1313-# but WITHOUT ANY WARRANTY; without even the implied warranty of
1414-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1515-# GNU General Public License for more details.
1616-#
1717-# You should have received a copy of the GNU General Public License
1818-# along with this program. If not, see <http://www.gnu.org/licenses/>.
1919-#
2020-# idea by azizLIGHTS
2121-#
2222-# 2020-10-20: nils_2, (freenode.#weechat)
2323-# 0.7 : fix problem with empty fields (reported by MutantMummy: https://github.com/weechat/scripts/issues/438)
2424-# 2017-01-06: nils_2, (freenode.#weechat)
2525-# 0.6 : fix problem with non existing server (reported by Niols)
2626-# 2016-12-19: nils_2, (freenode.#weechat)
2727-# 0.5 : fix problem with empty autojoin (reported by Caelum)
2828-# 2016-06-05: nils_2, (freenode.#weechat)
2929-# 0.4 : make script python3 compatible
3030-# 2015-11-14: nils_2, (freenode.#weechat)
3131-# 0.3 : fix: problem with (undef) option
3232-# 2014-01-19: nils_2, (freenode.#weechat)
3333-# 0.2 : fix: adding keys to already existing keys failed
3434-# 2013-12-22: nils_2, (freenode.#weechat)
3535-# 0.1 : initial release
3636-#
3737-# requires: WeeChat version 0.3.x
3838-#
3939-# Development is currently hosted at
4040-# https://github.com/weechatter/weechat-scripts
4141-4242-try:
4343- import weechat,re
4444-4545-except Exception:
4646- print("This script must be run under WeeChat.")
4747- print("Get WeeChat now at: http://www.weechat.org/")
4848- quit()
4949-5050-SCRIPT_NAME = "autojoinem"
5151-SCRIPT_AUTHOR = "nils_2 <weechatter@arcor.de>"
5252-SCRIPT_VERSION = "0.7"
5353-SCRIPT_LICENSE = "GPL"
5454-SCRIPT_DESC = "add/del channel(s) to/from autojoin option"
5555-5656-OPTIONS = { 'sorted' : ('off','channels will be sorted in autojoin-option. if autojoin-option contains channel-keys, this option will be ignored.'),
5757- }
5858-5959-def add_autojoin_cmd_cb(data, buffer, args):
6060- if args == "": # no args given. quit
6161- return weechat.WEECHAT_RC_OK
6262-6363- argv = args.strip().split(' ')
6464-6565- # remove empty fields
6666- argv2 = [feld for feld in argv if feld != '']
6767- argv = argv2
6868-6969-# if (len(argv) <= 1):
7070-# weechat.prnt(buffer,"%s%s: too few arguments." % (weechat.prefix('error'),SCRIPT_NAME))
7171-# return weechat.WEECHAT_RC_OK
7272-7373- server = weechat.buffer_get_string(buffer, 'localvar_server') # current server
7474- channel = weechat.buffer_get_string(buffer, 'localvar_channel') # current channel
7575- buf_type = weechat.buffer_get_string(buffer, 'localvar_type')
7676-7777- # only "add <servername>" given by user
7878- if (len(argv) == 2):
7979- weechat.prnt(buffer,"%s%s: invalid number of arguments." % (weechat.prefix('error'),SCRIPT_NAME))
8080- return weechat.WEECHAT_RC_OK
8181-8282- # '-key' keyword in command line?
8383- if '-key' in argv:
8484- found_key_word = argv.index('-key')
8585- key_words = argv[int(found_key_word)+1:]
8686- # don't use "-key" in argv
8787- argv = argv[:int(found_key_word)]
8888-8989- # ADD argument
9090- if (argv[0].lower() == 'add'):
9191- # add current channel to autojoin. Only option "add" was given..
9292- if (len(argv) == 1):
9393- if server == "" or channel == "" or server == channel or buf_type == "" or buf_type != 'channel':
9494- weechat.prnt(buffer,"%s%s: current buffer is not a channel buffer." % (weechat.prefix('error'),SCRIPT_NAME))
9595- return weechat.WEECHAT_RC_OK
9696- list_of_channels, list_of_current_keys = get_autojoin_list(buffer,server)
9797- # no channels in option!
9898- if list_of_channels == 1 and list_of_current_keys == 1:
9999- ptr_config_autojoin = weechat.config_get('irc.server.%s.autojoin' % server)
100100- rc = weechat.config_option_set(ptr_config_autojoin,channel,1)
101101- return weechat.WEECHAT_RC_OK
102102- if channel in list_of_channels:
103103- weechat.prnt(buffer,"%s%s: channel '%s' already in autojoin for server '%s'" % (weechat.prefix("error"),SCRIPT_NAME,channel,server))
104104- else:
105105- # first char of channel '#' ?
106106- if channel[0] == '#':
107107- if '-key' in args and len(key_words) > 1:
108108- weechat.prnt(buffer,"%s%s: too many key(s) for given channel(s) " % (weechat.prefix('error'),SCRIPT_NAME))
109109- return weechat.WEECHAT_RC_OK
110110- elif '-key' in args and len(key_words) == 1:
111111- list_of_channels.insert(0,channel)
112112- list_of_current_keys = ','.join(key_words)
113113- # strip leading ','
114114- if list_of_current_keys[0] == ',':
115115- list_of_current_keys = list_of_current_keys.lstrip(',')
116116- else:
117117- list_of_channels.append(channel)
118118-119119- if not set_autojoin_list(server,list_of_channels, list_of_current_keys):
120120- weechat.prnt(buffer,"%s%s: set new value for option failed..." % (weechat.prefix('error'),SCRIPT_NAME))
121121- # server and channels given by user
122122- elif (len(argv) >= 3):
123123- server = argv[1]
124124- list_of_channels = argv[2:]
125125- if '-key' in args and len(list_of_channels) < len(key_words):
126126- weechat.prnt(buffer,"%s%s: too many key(s) for given channel(s) " % (weechat.prefix('error'),SCRIPT_NAME))
127127- return weechat.WEECHAT_RC_OK
128128-129129- list_of_current_channels,list_of_current_keys = get_autojoin_list(buffer,server)
130130- # autojoin option is empty
131131- if list_of_current_channels == 1:
132132- # no channel -> no key!
133133- list_of_current_keys = ""
134134- if '-key' in args:
135135- list_of_current_keys = ','.join(key_words)
136136- # strip leading ','
137137- if list_of_current_keys[0] == ',':
138138- list_of_current_keys = list_of_current_keys.lstrip(',')
139139- if not set_autojoin_list(server,list_of_channels, list_of_current_keys):
140140- weechat.prnt(buffer,"%s%s: set new value for option failed..." % (weechat.prefix('error'),SCRIPT_NAME))
141141- else:
142142- if '-key' in args:
143143- j = 0
144144- new_keys = []
145145- list_of_new_keys = []
146146- for i in list_of_channels:
147147- if i not in list_of_current_channels and j <= len(key_words):
148148-# weechat.prnt(buffer,"channel: %s, channel key is: '%s'" % (i,key_words[j]))
149149- list_of_current_channels.insert(j,i)
150150- new_keys.insert(j,key_words[j])
151151- j += 1
152152- missing_channels = list_of_current_channels
153153- list_of_new_keys = ','.join(new_keys)
154154- if list_of_current_keys:
155155- list_of_current_keys = list_of_new_keys + ',' + list_of_current_keys
156156- else:
157157- list_of_current_keys = list_of_new_keys
158158- # strip leading ','
159159- if list_of_current_keys[0] == ',':
160160- list_of_current_keys = list_of_current_keys.lstrip(',')
161161- else:
162162- # check given channels with channels already set in option
163163- missing_channels = get_difference(list_of_channels,list_of_current_channels)
164164- missing_channels = list_of_current_channels + missing_channels
165165-166166- if not set_autojoin_list(server,missing_channels, list_of_current_keys):
167167- weechat.prnt(buffer,"%s%s: set new value for option failed..." % (weechat.prefix('error'),SCRIPT_NAME))
168168- return weechat.WEECHAT_RC_OK
169169-170170- # DEL argument
171171- if (argv[0].lower() == 'del'):
172172- # del current channel from autojoin. Only option "del" was given..
173173- if (len(argv) == 1):
174174- if server == "" or channel == "" or server == channel or buf_type == "" or buf_type != 'channel':
175175- weechat.prnt(buffer,"%s%s: current buffer is not a channel buffer." % (weechat.prefix('error'),SCRIPT_NAME))
176176- return weechat.WEECHAT_RC_OK
177177- list_of_channels, list_of_keys = get_autojoin_list(buffer,server)
178178- # no channels in option, nothing to delete
179179- if list_of_channels == 1 and list_of_current_keys == 1:
180180- return weechat.WEECHAT_RC_OK
181181- if channel not in list_of_channels:
182182- weechat.prnt(buffer,"%s%s: channel '%s' not found in autojoin for server '%s'" % (weechat.prefix("error"),SCRIPT_NAME,channel,server))
183183- return weechat.WEECHAT_RC_OK
184184- else:
185185- # first char of channel '#' ?
186186- if channel[0] == '#':
187187- channel_key_index = list_of_channels.index(channel)
188188- if not list_of_keys:
189189- list_of_channels.remove(list_of_channels[channel_key_index])
190190- list_of_current_keys = ''
191191- else:
192192- list_of_keys_tup = list_of_keys.split(",")
193193- list_of_current_keys = list_of_keys
194194- # channel does not have a key (position of channel > number of keys!)
195195- if channel_key_index + 1 > len(list_of_keys_tup):
196196- list_of_channels.remove(list_of_channels[channel_key_index])
197197- # remove channel and key from autjoin option
198198- else:
199199- list_of_channels.remove(list_of_channels[channel_key_index])
200200- list_of_keys_tup.remove(list_of_keys_tup[channel_key_index])
201201- # does a key exists, after removing?
202202- if len(list_of_keys_tup) > 0:
203203- list_of_current_keys = ','.join(list_of_keys_tup)
204204- # strip leading ','
205205- if list_of_current_keys[0] == ',':
206206- list_of_current_keys = list_of_current_keys.lstrip(',')
207207- else: # all keys deleted
208208- list_of_current_keys = ''
209209-210210- # unset option if everything is gone.
211211- if not list_of_channels and not list_of_current_keys:
212212- ptr_config_autojoin = weechat.config_get('irc.server.%s.autojoin' % server)
213213- if ptr_config_autojoin:
214214- rc = weechat.config_option_unset(ptr_config_autojoin)
215215- return weechat.WEECHAT_RC_OK
216216-217217- if not set_autojoin_list(server,list_of_channels, list_of_current_keys):
218218- weechat.prnt(buffer,"%s%s: set new value for option failed..." % (weechat.prefix('error'),SCRIPT_NAME))
219219-220220- # server and channels given by user
221221- elif (len(argv) >= 3):
222222- server = argv[1]
223223- list_of_current_channels,list_of_current_keys = get_autojoin_list(buffer,server)
224224-225225- # autojoin option is empty
226226- if list_of_current_channels == 1:
227227- weechat.prnt(buffer,"%s%s: nothing to delete..." % (weechat.prefix('error'),SCRIPT_NAME))
228228- return weechat.WEECHAT_RC_OK
229229- else:
230230- list_of_channels = args.split(" ")[2:]
231231- if list_of_current_keys:
232232- list_of_current_keys_tup = list_of_current_keys.split(",")
233233- else:
234234- list_of_current_keys_tup = ''
235235-236236- for i in list_of_channels:
237237- # check if given channel is in list of options
238238- if not i in list_of_current_channels:
239239- continue
240240- channel_key_index = list_of_current_channels.index(i)
241241- # channel does not have a key (position of channel > number of keys!)
242242- if channel_key_index + 1 > len(list_of_current_keys_tup):
243243- list_of_current_channels.remove(i)
244244-# if len(list_of_current_channels) <= 0:
245245-# list_of_current_channels = ''
246246- else: # remove channel and key from autjoin option
247247- list_of_current_channels.remove(i)
248248- list_of_current_keys_tup.remove(list_of_current_keys_tup[channel_key_index])
249249- # does an key exists, after removing?
250250- if len(list_of_current_keys_tup) > 0:
251251- list_of_current_keys = ','.join(list_of_current_keys_tup)
252252- # strip leading ','
253253- if list_of_current_keys[0] == ',':
254254- list_of_current_keys = list_of_current_keys.lstrip(',')
255255- else: # all keys deleted
256256- list_of_current_keys = ''
257257-258258-# for j in list_of_current_channels:
259259-# weechat.prnt(buffer,"chan:%s" % j)
260260-# for j in list_of_current_keys_tup:
261261-# weechat.prnt(buffer,"key :%s" % j)
262262-263263- # unset option if everything is gone.
264264- if not list_of_current_channels and not list_of_current_keys:
265265- ptr_config_autojoin = weechat.config_get('irc.server.%s.autojoin' % server)
266266- if ptr_config_autojoin:
267267- rc = weechat.config_option_unset(ptr_config_autojoin)
268268- return weechat.WEECHAT_RC_OK
269269-270270- if not set_autojoin_list(server,list_of_current_channels, list_of_current_keys):
271271- weechat.prnt(buffer,"%s%s: set new value for option failed..." % (weechat.prefix('error'),SCRIPT_NAME))
272272-273273- return weechat.WEECHAT_RC_OK
274274-275275-def get_difference(list1, list2):
276276- return list(set(list1).difference(set(list2)))
277277-278278-# returns a list of channels and a list of keys
279279-# 1 = something failed, 0 = channel found
280280-def get_autojoin_list(buffer,server):
281281- ptr_config_autojoin = weechat.config_get('irc.server.%s.autojoin' % server)
282282- # option not found! server does not exist
283283- if not ptr_config_autojoin:
284284- weechat.prnt("","%s%s: server '%s' does not exist." % (weechat.prefix('error'),SCRIPT_NAME,server))
285285- return 1,1
286286-287287- # get value from autojoin option
288288- channels = weechat.config_string(ptr_config_autojoin)
289289- if not channels:
290290- return 1,1
291291-292292- # check for keys
293293- if len(re.findall(r" ", channels)) == 0:
294294- list_of_channels = channels.split(",")
295295- list_of_keys = []
296296- elif len(re.findall(r" ", channels)) == 1:
297297- list_of_channels2,list_of_keys = channels.split(" ")
298298- list_of_channels = list_of_channels2.split(",")
299299- else:
300300- weechat.prnt("","%s%s: irc.server.%s.autojoin not valid..." % (weechat.prefix('error'),SCRIPT_NAME,server))
301301- return 1,1
302302-303303- return list_of_channels, list_of_keys
304304-305305-def set_autojoin_list(server,list_of_channels, list_of_keys):
306306- ptr_config_autojoin = weechat.config_get('irc.server.%s.autojoin' % server)
307307- if not ptr_config_autojoin:
308308- return 0
309309-310310- if OPTIONS['sorted'].lower() == 'on' and not list_of_keys:
311311- # no keys, sort the channel-list
312312- channels = '%s' % ','.join(sorted(list_of_channels))
313313- else:
314314- # don't sort channel-list with given key
315315- channels = '%s' % ','.join(list_of_channels)
316316-317317- # strip leading ','
318318- if channels[0] == ',':
319319- channels = channels.lstrip(',')
320320-321321- # add keys to list of channels
322322- if list_of_keys:
323323- channels = '%s %s' % (channels,list_of_keys)
324324-325325- rc = weechat.config_option_set(ptr_config_autojoin,channels,1)
326326- if not rc:
327327- return 0
328328- return 1
329329-330330-def autojoinem_completion_cb(data, completion_item, buffer, completion):
331331-# server = weechat.buffer_get_string(buffer, 'localvar_server') # current buffer
332332- input_line = weechat.buffer_get_string(buffer, 'input')
333333-334334- # get information out of the input_line
335335- argv = input_line.strip().split(" ",3)
336336- if (len(argv) >= 3 and argv[1] == 'del'):
337337- server = argv[2]
338338-339339- list_of_channels,list_of_keys = get_autojoin_list(buffer,server)
340340- if list_of_channels == 1:
341341- return weechat.WEECHAT_RC_OK
342342-343343- if (len(argv) >= 4 and argv[1] == 'del'):
344344- list_of_current_channels = argv[3].split(' ')
345345- missing_channels = get_difference(list_of_channels,list_of_current_channels)
346346- if not missing_channels:
347347- return weechat.WEECHAT_RC_OK
348348- list_of_channels = missing_channels
349349-350350- for i, elem in enumerate(list_of_channels):
351351- weechat.hook_completion_list_add(completion, list_of_channels[i], 0, weechat.WEECHAT_LIST_POS_END)
352352- return weechat.WEECHAT_RC_OK
353353-# ================================[ weechat options & description ]===============================
354354-def init_options():
355355- for option,value in OPTIONS.items():
356356- weechat.config_set_desc_plugin(option, '%s (default: "%s")' % (value[1], value[0]))
357357- if not weechat.config_is_set_plugin(option):
358358- weechat.config_set_plugin(option, value[0])
359359- OPTIONS[option] = value[0]
360360- else:
361361- OPTIONS[option] = weechat.config_get_plugin(option)
362362-363363-def toggle_refresh(pointer, name, value):
364364- global OPTIONS
365365- option = name[len('plugins.var.python.' + SCRIPT_NAME + '.'):] # get optionname
366366- OPTIONS[option] = value # save new value
367367- return weechat.WEECHAT_RC_OK
368368-# ================================[ main ]===============================
369369-if __name__ == "__main__":
370370- if weechat.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION, SCRIPT_LICENSE, SCRIPT_DESC, '', ''):
371371- version = weechat.info_get("version_number", "") or 0
372372- weechat.hook_command(SCRIPT_NAME,SCRIPT_DESC,
373373- 'add <server> [<channel1>[ <channel2>...]] | [-key <channelkey> [<channelkey>...]] ||'
374374- 'del <server> [<channel1>[ <channel2>...]]',
375375- 'add <server> <channel>: add channel to irc.server.<servername>.autojoin\n'
376376- ' -key <channelkey>: name of channelkey\n'
377377- 'del <server> <channel>: del channel from irc.server.<servername>.autojoin\n'
378378- '\n'
379379- 'Examples:\n'
380380- ' add current channel to corresponding server option:\n'
381381- ' /' + SCRIPT_NAME + ' add\n'
382382- ' add all channels from all server to corresponding server option:\n'
383383- ' /allchan /' + SCRIPT_NAME + ' add\n'
384384- ' add channel #weechat to autojoin option on server freenode:\n'
385385- ' /' + SCRIPT_NAME + ' add freenode #weechat\n'
386386- ' add channel #weechat and #weechat-de to autojoin option on server freenode, with channel key for channel #weechat:\n'
387387- ' /' + SCRIPT_NAME + ' add freenode #weechat #weechat-de -key my_channel_key\n'
388388- ' del channels #weechat and #weechat-de from autojoin option on server freenode:\n'
389389- ' /' + SCRIPT_NAME + ' del freenode #weechat #weechat-de',
390390- 'add %(irc_servers) %(irc_server_channels)|%*||'
391391- 'del %(irc_servers) %(plugin_autojoinem)|%*',
392392- 'add_autojoin_cmd_cb', '')
393393-394394- init_options()
395395- weechat.hook_completion('plugin_autojoinem', 'autojoin_completion', 'autojoinem_completion_cb', '')
396396- weechat.hook_config('plugins.var.python.' + SCRIPT_NAME + '.*', 'toggle_refresh', '')
397397-398398-# if int(version) >= 0x00030600:
399399-# else:
400400-# weechat.prnt("","%s%s %s" % (weechat.prefix("error"),SCRIPT_NAME,": needs version 0.3.6 or higher"))
401401-# weechat.command("","/wait 1ms /python unload %s" % SCRIPT_NAME)
···11+# -*- coding: utf-8 -*-
22+#
33+# weestats.py, version 0.2 for WeeChat version 0.3
44+# Latest development version: https://github.com/FiXato/weechat_scripts
55+#
66+# Inserts some statistics into your input field about the buffers/windows
77+# you have open.
88+# Example: 151 buffers (46 merged): 135 channels, 9 servers, 3 queries,
99+# 1 script, 1 python, 1 perl, 1 core; 3 windows
1010+#
1111+## History:
1212+#
1313+### 2012-03-29: FiXato:
1414+# * version 0.1: initial release.
1515+# * Display a count of all the different buffers you have open.
1616+# * Display a count of all the open windows.
1717+# * version 0.2: Getting the splits.
1818+# * Displays the how many vertical and horizontal windows.
1919+# (not quite sure if my approximation is correct though..)
2020+# * Fixed possible memleak (forgot to free an infolist)
2121+### 2015-05-02: arza:
2222+# * version 0.3:
2323+# * handle non-#-channels
2424+# * numerical sort for buffer info
2525+# * moved window split info to option -split
2626+# * simplified the output
2727+### 2019-07-05: Sébastien Helleu:
2828+# * version 0.4:
2929+# * make script compatible with Python 3
3030+#
3131+## Acknowledgements:
3232+# * Sebastien "Flashcode" Helleu, for developing the kick-ass chat/IRC
3333+# client WeeChat
3434+#
3535+## TODO:
3636+# - Add more statistics, such as:
3737+# - average and total history lines.
3838+# - average and total topic/title lengths
3939+# - how many are displayed in a window
4040+#
4141+## Copyright (c) 2012 Filip H.F. "FiXato" Slagter,
4242+# <FiXato+WeeChat [at] Gmail [dot] com>
4343+# https://google.com/profiles/FiXato
4444+#
4545+# Permission is hereby granted, free of charge, to any person obtaining
4646+# a copy of this software and associated documentation files (the
4747+# "Software"), to deal in the Software without restriction, including
4848+# without limitation the rights to use, copy, modify, merge, publish,
4949+# distribute, sublicense, and/or sell copies of the Software, and to
5050+# permit persons to whom the Software is furnished to do so, subject to
5151+# the following conditions:
5252+#
5353+# The above copyright notice and this permission notice shall be
5454+# included in all copies or substantial portions of the Software.
5555+#
5656+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
5757+# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
5858+# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
5959+# NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
6060+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
6161+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
6262+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
6363+#
6464+6565+from __future__ import print_function
6666+6767+SCRIPT_NAME = "weestats"
6868+SCRIPT_AUTHOR = "Filip H.F. 'FiXato' Slagter <fixato [at] gmail [dot] com>"
6969+SCRIPT_VERSION = "0.4"
7070+SCRIPT_LICENSE = "MIT"
7171+SCRIPT_DESC = "Useless statistics about your open buffers and windows"
7272+SCRIPT_COMMAND = "weestats"
7373+SCRIPT_CLOSE_CB = "close_cb"
7474+7575+import_ok = True
7676+7777+try:
7878+ import weechat as w
7979+except ImportError:
8080+ print("This script must be run under WeeChat.")
8181+ import_ok = False
8282+8383+def close_cb(*kwargs):
8484+ return w.WEECHAT_RC_OK
8585+8686+def command_main(data, buffer, args):
8787+ infolist = w.infolist_get("buffer", "", "")
8888+ buffer_groups = {}
8989+ results = []
9090+ buffer_count = 0
9191+ merge_count = 0
9292+ numbers = set()
9393+ while w.infolist_next(infolist):
9494+ bplugin = w.infolist_string(infolist, "plugin_name")
9595+ bname = w.infolist_string(infolist, "name")
9696+ bpointer = w.infolist_pointer(infolist, "pointer")
9797+ bnumber = w.infolist_integer(infolist, "number")
9898+ btype = w.buffer_get_string(bpointer, 'localvar_type')
9999+ if not bnumber in numbers:
100100+ numbers.add(bnumber)
101101+ else:
102102+ merge_count += 1
103103+104104+ if btype == 'server':
105105+ bdesc = 'servers'
106106+ elif btype == 'channel':
107107+ bdesc = 'channels'
108108+ elif btype == 'private':
109109+ bdesc = 'queries'
110110+ else:
111111+ bdesc = bplugin
112112+113113+ buffer_groups.setdefault(bdesc,[]).append({'name': bname, 'pointer': bpointer})
114114+115115+ w.infolist_free(infolist)
116116+117117+ infolist = w.infolist_get("window", "", "")
118118+ windows_v = set()
119119+ windows_h = set()
120120+ windows = set()
121121+ while w.infolist_next(infolist):
122122+ window = w.infolist_pointer(infolist, "pointer")
123123+ window_w = w.infolist_integer(infolist, "width_pct")
124124+ window_h = w.infolist_integer(infolist, "height_pct")
125125+ windows.add(window)
126126+ if window_h == 100 and window_w != 100:
127127+ windows_v.add(window)
128128+ elif window_w == 100 and window_h != 100:
129129+ windows_h.add(window)
130130+ #else: #both 100%, thus no splits
131131+ w.infolist_free(infolist)
132132+133133+ window_count = len(windows)
134134+135135+ for desc, buffers in buffer_groups.items():
136136+ buffer_count += len(buffers)
137137+ results.append('%i %s' % (len(buffers), desc))
138138+139139+ buffer_stats = ', '.join(sorted(results, key = lambda item: (int(item.partition(' ')[0]) if item[0].isdigit() else float('inf'), item),reverse=True)) # descending numerical sort of strings
140140+ stats_string = '%i buffers (%i merged): %s; %i windows' % (buffer_count, merge_count, buffer_stats, window_count)
141141+ if '-split' in args:
142142+ stats_string += ": %i vertically / %i horizontally split" % (len(windows_v), len(windows_h))
143143+ w.command("", "/input insert %s" % stats_string)
144144+ return w.WEECHAT_RC_OK
145145+146146+if __name__ == "__main__" and import_ok:
147147+ if w.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION,
148148+ SCRIPT_LICENSE, SCRIPT_DESC, SCRIPT_CLOSE_CB, ""):
149149+150150+ w.hook_command(SCRIPT_COMMAND,
151151+ SCRIPT_DESC,
152152+ "-split",
153153+ "Inserts useless statistics about your open buffers and windows into your input line.\n"
154154+ "-split: Include information about window splits.",
155155+ "-split",
156156+ "command_main", "")