def find_channels(): """Return list of servers and channels""" #@TODO: make it return a dict with more options like "nicks_count etc." items = {} infolist = w.infolist_get('irc_server', '', '') # populate servers while w.infolist_next(infolist): items[w.infolist_string(infolist, 'name')] = '' w.infolist_free(infolist) # populate channels per server for server in items.keys(): keys = [] keyed_channels = [] unkeyed_channels = [] items[server] = '' #init if connected but no channels infolist = w.infolist_get('irc_channel', '', server) while w.infolist_next(infolist): if w.infolist_integer(infolist, 'nicks_count') == 0: #parted but still open in a buffer: bit hackish continue if w.infolist_integer(infolist, 'type') == 0: key = w.infolist_string(infolist, "key") if len(key) > 0: keys.append(key) keyed_channels.append(w.infolist_string(infolist, "name")) else : unkeyed_channels.append(w.infolist_string(infolist, "name")) items[server] = ','.join(keyed_channels + unkeyed_channels) if len(keys) > 0: items[server] += ' %s' % ','.join(keys) w.infolist_free(infolist) return items
def hotlist_dict(): """Return the contents of the hotlist as a dictionary. The returned dictionary has the following structure: >>> hotlist = { ... "0x0": { # string representation of the buffer pointer ... "count_low": 0, ... "count_message": 0, ... "count_private": 0, ... "count_highlight": 0, ... } ... } """ hotlist = {} infolist = weechat.infolist_get("hotlist", "", "") while weechat.infolist_next(infolist): buffer_pointer = weechat.infolist_pointer(infolist, "buffer_pointer") hotlist[buffer_pointer] = {} hotlist[buffer_pointer]["count_low"] = weechat.infolist_integer( infolist, "count_00") hotlist[buffer_pointer]["count_message"] = weechat.infolist_integer( infolist, "count_01") hotlist[buffer_pointer]["count_private"] = weechat.infolist_integer( infolist, "count_02") hotlist[buffer_pointer]["count_highlight"] = weechat.infolist_integer( infolist, "count_03") weechat.infolist_free(infolist) return hotlist
def find_channels(): """Return list of servers and channels""" #@TODO: make it return a dict with more options like "nicks_count etc." items = {} infolist = w.infolist_get('irc_server', '', '') # populate servers while w.infolist_next(infolist): items[w.infolist_string(infolist, 'name')] = '' w.infolist_free(infolist) # populate channels per server for server in items.keys(): items[server] = '' #init if connected but no channels infolist = w.infolist_get('irc_channel', '', server) while w.infolist_next(infolist): if w.infolist_integer(infolist, 'nicks_count') == 0: #parted but still open in a buffer: bit hackish continue if w.infolist_integer(infolist, 'type') == 0: channel = w.infolist_string(infolist, "buffer_short_name") items[server] += '%s,' %channel w.infolist_free(infolist) return items
def command_main(data, buffer, args): infolist = w.infolist_get("buffer", "", "") buffer_groups = {} results = [] buffer_count = 0 merge_count = 0 numbers = set() while w.infolist_next(infolist): bplugin = w.infolist_string(infolist, "plugin_name") bname = w.infolist_string(infolist, "name") bpointer = w.infolist_pointer(infolist, "pointer") bnumber = w.infolist_integer(infolist, "number") if not bnumber in numbers: numbers.add(bnumber) else: merge_count += 1 btype = bplugin if bplugin == 'irc': if 'server.' in bname: btype = '%s servers' % btype elif '#' in bname: btype = '%s channels' % btype else: btype = '%s queries' % btype buffer_groups.setdefault(btype, []).append({ 'name': bname, 'pointer': bpointer }) w.infolist_free(infolist) infolist = w.infolist_get("window", "", "") windows_v = set() windows_h = set() windows = set() while w.infolist_next(infolist): window = w.infolist_pointer(infolist, "pointer") window_w = w.infolist_integer(infolist, "width_pct") window_h = w.infolist_integer(infolist, "height_pct") windows.add(window) if window_h == 100 and window_w != 100: windows_v.add(window) elif window_w == 100 and window_h != 100: windows_h.add(window) #else: #both 100%, thus no splits w.infolist_free(infolist) window_count = len(windows) for bplugin, buffers in buffer_groups.iteritems(): buffer_count += len(buffers) results.append('%i %s' % (len(buffers), bplugin)) buffer_stats = ', '.join(sorted(results)) stats_string = '%i windows used (%i vertically / %i horizontally split). %i (of which %i merged) buffers open: %s' % ( window_count, len(windows_v), len(windows_h), buffer_count, merge_count, buffer_stats) w.command("", "/input insert %s" % stats_string) return w.WEECHAT_RC_OK
def update_title(data, signal, signal_data): ''' The callback that adds title. ''' if w.config_get_plugin('short_name') == 'on': title = w.buffer_get_string(w.current_buffer(), 'short_name') else: title = w.buffer_get_string(w.current_buffer(), 'name') hotlist = w.infolist_get('hotlist', '', '') hot_text = '' while w.infolist_next(hotlist): priority = w.infolist_integer(hotlist, 'priority') if priority >= int(w.config_get_plugin('title_priority')): number = w.infolist_integer(hotlist, 'buffer_number') thebuffer = w.infolist_pointer(hotlist, 'buffer_pointer') name = w.buffer_get_string(thebuffer, 'short_name') hot_text += ' %s' % number if hot_text: title += ' [A:%s]' % hot_text w.infolist_free(hotlist) w.window_set_title(title) return w.WEECHAT_RC_OK
def find_channels(): """Return list of servers and channels""" #@TODO: make it return a dict with more options like "nicks_count etc." items = {} infolist = w.infolist_get('irc_server', '', '') # populate servers while w.infolist_next(infolist): items[w.infolist_string(infolist, 'name')] = '' w.infolist_free(infolist) # populate channels per server for server in items.keys(): keys = [] channels = [] items[server] = '' #init if connected but no channels infolist = w.infolist_get('irc_channel', '', server) while w.infolist_next(infolist): if w.infolist_integer(infolist, 'nicks_count') == 0: #parted but still open in a buffer: bit hackish continue if w.infolist_integer(infolist, 'type') == 0: channels.append(w.infolist_string(infolist, "name")) key = w.infolist_string(infolist, "key") if len(key) > 0: keys.append(key) items[server] = ','.join(channels) if len(keys) > 0: items[server] += ' %s' % ','.join(keys) w.infolist_free(infolist) return items
def find_channels(): """Return list of servers and channels""" items = {} infolist = w.infolist_get('irc_server', '', '') # populate servers while w.infolist_next(infolist): items[w.infolist_string(infolist, 'name')] = '' w.infolist_free(infolist) # populate channels per server for server in items.keys(): channels = [] infolist = w.infolist_get('irc_channel', '', server) while w.infolist_next(infolist): if w.infolist_integer(infolist, 'nicks_count') == 0: # parted but still open in a buffer: bit hackish continue if w.infolist_integer(infolist, 'type') == 0: name = w.infolist_string(infolist, "name") key = w.infolist_string(infolist, "key") channels.append((name, key)) # sort by name, keyed channels first channels.sort(key=lambda c: (not c[1], c[0])) items[server] = ','.join(name for name, key in channels) keys = ','.join(key for name, key in channels if key) if keys: items[server] += ' ' + keys w.infolist_free(infolist) return items
def find_channels(): """Return list of servers and channels""" #@TODO: make it return a dict with more options like "nicks_count etc." items = {} infolist = w.infolist_get('irc_server', '', '') # populate servers while w.infolist_next(infolist): items[w.infolist_string(infolist, 'name')] = '' w.infolist_free(infolist) # populate channels per server for server in items.keys(): items[server] = '' #init if connected but no channels infolist = w.infolist_get('irc_channel', '', server) while w.infolist_next(infolist): if w.infolist_integer(infolist, 'nicks_count') == 0: #parted but still open in a buffer: bit hackish continue if w.infolist_integer(infolist, 'type') == 0: channel = w.infolist_string(infolist, "buffer_short_name") items[server] += '%s,' % channel w.infolist_free(infolist) return items
def command_main(data, buffer, args): infolist = w.infolist_get("buffer", "", "") buffer_groups = {} results = [] buffer_count = 0 merge_count = 0 numbers = set() while w.infolist_next(infolist): bplugin = w.infolist_string(infolist, "plugin_name") bname = w.infolist_string(infolist, "name") bpointer = w.infolist_pointer(infolist, "pointer") bnumber = w.infolist_integer(infolist, "number") btype = w.buffer_get_string(bpointer, 'localvar_type') if not bnumber in numbers: numbers.add(bnumber) else: merge_count += 1 if btype == 'server': bdesc = 'servers' elif btype == 'channel': bdesc = 'channels' elif btype == 'private': bdesc = 'queries' else: bdesc = bplugin buffer_groups.setdefault(bdesc,[]).append({'name': bname, 'pointer': bpointer}) w.infolist_free(infolist) infolist = w.infolist_get("window", "", "") windows_v = set() windows_h = set() windows = set() while w.infolist_next(infolist): window = w.infolist_pointer(infolist, "pointer") window_w = w.infolist_integer(infolist, "width_pct") window_h = w.infolist_integer(infolist, "height_pct") windows.add(window) if window_h == 100 and window_w != 100: windows_v.add(window) elif window_w == 100 and window_h != 100: windows_h.add(window) #else: #both 100%, thus no splits w.infolist_free(infolist) window_count = len(windows) for desc, buffers in buffer_groups.iteritems(): buffer_count += len(buffers) results.append('%i %s' % (len(buffers), desc)) 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 stats_string = '%i buffers (%i merged): %s; %i windows' % (buffer_count, merge_count, buffer_stats, window_count) if '-split' in args: stats_string += ": %i vertically / %i horizontally split" % (len(windows_v), len(windows_h)) w.command("", "/input insert %s" % stats_string) return w.WEECHAT_RC_OK
def chanact_cb(*args): ''' Callback ran on hotlist changes ''' global keydict hotlist = w.infolist_get('hotlist', '', '') activity = [] while w.infolist_next(hotlist): priority = w.infolist_integer(hotlist, 'priority') if priority < int(w.config_get_plugin('lowest_priority')): continue int_number = w.infolist_integer(hotlist, 'buffer_number') number = str(int_number) thebuffer = w.infolist_pointer(hotlist, 'buffer_pointer') name = w.buffer_get_string(thebuffer, 'short_name') color = w.config_get_plugin('color_default') if priority > 0: color = w.config_get_plugin('color_%s' %priority) if number in keydict: number = keydict[number] entry = '%s%s%s' % (w.color(color), number, w.color('reset')) elif name in keydict: name = keydict[name] entry = '%s%s%s' % (w.color(color), name, w.color('reset')) elif name: entry = '%s%s%s:%s%s%s' % ( w.color('default'), number, w.color('reset'), w.color(color), name[:int(w.config_get_plugin('item_length'))], w.color('reset')) else: entry = '%s%s%s' % ( w.color(color), number, w.color(reset)) activity.append((entry, thebuffer, sort_rank(thebuffer, priority), int_number)) if w.config_get_plugin('sort_by_number') == "on": activity.sort(key=lambda t: int(t[3])) else: activity.sort(key=lambda t: int(t[2]), reverse=True) w.infolist_free(hotlist) if activity: message = w.config_get_plugin('message') delim = w.config_get_plugin('delimiter') return message + delim.join(a[0] for a in activity) else: return ''
def chanact_cb(*args): ''' Callback ran on hotlist changes ''' global keydict hotlist = w.infolist_get('hotlist', '', '') activity = [] while w.infolist_next(hotlist): priority = w.infolist_integer(hotlist, 'priority') if priority < int(w.config_get_plugin('lowest_priority')): continue int_number = w.infolist_integer(hotlist, 'buffer_number') number = str(int_number) thebuffer = w.infolist_pointer(hotlist, 'buffer_pointer') name = w.buffer_get_string(thebuffer, 'short_name') color = w.config_get_plugin('color_default') if priority > 0: color = w.config_get_plugin('color_%s' %priority) if number in keydict: number = keydict[number] entry = '%s%s%s' % (w.color(color), number, w.color('reset')) elif name in keydict: name = keydict[name] entry = '%s%s%s' % (w.color(color), name, w.color('reset')) elif name: entry = '%s%s%s:%s%s%s' % ( w.color('default'), number, w.color('reset'), w.color(color), name[:int(w.config_get_plugin('item_length'))], w.color('reset')) else: entry = '%s%s%s' % ( w.color(color), number, w.color('reset')) activity.append((entry, thebuffer, sort_rank(thebuffer, priority), int_number)) if w.config_get_plugin('sort_by_number') == "on": activity.sort(key=lambda t: int(t[3])) else: activity.sort(key=lambda t: int(t[2]), reverse=True) w.infolist_free(hotlist) if activity: message = w.config_get_plugin('message') delim = w.config_get_plugin('delimiter') return message + delim.join(a[0] for a in activity) else: return ''
def get_connected_servers() -> Generator[str, None, None]: """ return a list of connected servers that are not AWAY """ infolist = w.infolist_get("irc_server", "", "") if infolist: while w.infolist_next(infolist): if (w.infolist_integer(infolist, "is_connected") and not w.infolist_integer(infolist, "is_away")): yield w.infolist_string(infolist, "name") w.infolist_free(infolist)
def scroll_buffer(self): infolist = weechat.infolist_get("window", "", "current") if (weechat.infolist_next(infolist)): start_line_y = weechat.infolist_integer(infolist, "start_line_y") chat_height = weechat.infolist_integer(infolist, "chat_height") if(start_line_y > self.current_line): weechat.command(self.url_buffer, "/window scroll -%i" %(start_line_y - self.current_line)) elif(start_line_y <= self.current_line - chat_height): weechat.command(self.url_buffer, "/window scroll +%i"%(self.current_line - start_line_y - chat_height + 1)) weechat.infolist_free(infolist)
def command_main(data, buffer, args): infolist = w.infolist_get("buffer", "", "") buffer_groups = {} results = [] buffer_count = 0 merge_count = 0 numbers = set() while w.infolist_next(infolist): bplugin = w.infolist_string(infolist, "plugin_name") bname = w.infolist_string(infolist, "name") bpointer = w.infolist_pointer(infolist, "pointer") bnumber = w.infolist_integer(infolist, "number") if not bnumber in numbers: numbers.add(bnumber) else: merge_count += 1 btype = bplugin if bplugin == 'irc': if 'server.' in bname: btype = '%s servers' % btype elif '#' in bname: btype = '%s channels' % btype else: btype = '%s queries' % btype buffer_groups.setdefault(btype,[]).append({'name': bname, 'pointer': bpointer}) w.infolist_free(infolist) infolist = w.infolist_get("window", "", "") windows_v = set() windows_h = set() windows = set() while w.infolist_next(infolist): window = w.infolist_pointer(infolist, "pointer") window_w = w.infolist_integer(infolist, "width_pct") window_h = w.infolist_integer(infolist, "height_pct") windows.add(window) if window_h == 100 and window_w != 100: windows_v.add(window) elif window_w == 100 and window_h != 100: windows_h.add(window) #else: #both 100%, thus no splits w.infolist_free(infolist) window_count = len(windows) for bplugin, buffers in buffer_groups.iteritems(): buffer_count += len(buffers) results.append('%i %s' % (len(buffers), bplugin)) buffer_stats = ', '.join(sorted(results)) stats_string = '%i windows used (%i vertically / %i horizontally split). %i (of which %i merged) buffers open: %s' % (window_count, len(windows_v), len(windows_h), buffer_count, merge_count, buffer_stats) w.command("", "/input insert %s" % stats_string) return w.WEECHAT_RC_OK
def exclude_hotlist(): if OPTIONS['hotlist'] == '0' or OPTIONS['hotlist'] =='': return weechat.WEECHAT_RC_OK infolist = weechat.infolist_get('hotlist', '', '') while weechat.infolist_next(infolist): buffer_number = weechat.infolist_integer(infolist, 'buffer_number') priority = weechat.infolist_integer(infolist, 'priority') if int(OPTIONS['hotlist']) == priority or OPTIONS['hotlist'] == '4': weechat.command('','/buffer unhide %s' % buffer_number) weechat.infolist_free(infolist) return weechat.WEECHAT_RC_OK
def exclude_hotlist(): if OPTIONS['hotlist'] == '0' or OPTIONS['hotlist'] == '': return weechat.WEECHAT_RC_OK infolist = weechat.infolist_get('hotlist', '', '') while weechat.infolist_next(infolist): buffer_number = weechat.infolist_integer(infolist, 'buffer_number') priority = weechat.infolist_integer(infolist, 'priority') if int(OPTIONS['hotlist']) == priority or OPTIONS['hotlist'] == '4': weechat.command('', '/buffer unhide %s' % buffer_number) weechat.infolist_free(infolist) return weechat.WEECHAT_RC_OK
def lb_check_outside_window(): global lb_buffer, lb_curline if (lb_buffer): infolist = weechat.infolist_get("window", "", "current") if (weechat.infolist_next(infolist)): start_line_y = weechat.infolist_integer(infolist, "start_line_y") chat_height = weechat.infolist_integer(infolist, "chat_height") if(start_line_y > lb_curline): weechat.command(lb_buffer, "/window scroll -%i" %(start_line_y - lb_curline)) elif(start_line_y <= lb_curline - chat_height): weechat.command(lb_buffer, "/window scroll +%i"%(lb_curline - start_line_y - chat_height + 1)) weechat.infolist_free(infolist)
def get_logfile(): logfilename = "" current_buffer = weechat.current_buffer() infolist = weechat.infolist_get('logger_buffer', '', '') while weechat.infolist_next(infolist): bpointer = weechat.infolist_pointer(infolist, 'buffer') if current_buffer == bpointer: logfilename = weechat.infolist_string(infolist, 'log_filename') log_enabled = weechat.infolist_integer(infolist, 'log_enabled') log_level = weechat.infolist_integer(infolist, 'log_level') weechat.infolist_free(infolist) # free infolist() return logfilename
def get_logfile(): logfilename = "" current_buffer = weechat.current_buffer() infolist = weechat.infolist_get('logger_buffer','','') while weechat.infolist_next(infolist): bpointer = weechat.infolist_pointer(infolist, 'buffer') if current_buffer == bpointer: logfilename = weechat.infolist_string(infolist, 'log_filename') log_enabled = weechat.infolist_integer(infolist, 'log_enabled') log_level = weechat.infolist_integer(infolist, 'log_level') weechat.infolist_free(infolist) # free infolist() return logfilename
def ugCheckLineOutsideWindow(): global urlGrab , urlGrabSettings, urlgrab_buffer, current_line, max_buffer_length if (urlgrab_buffer): infolist = weechat.infolist_get("window", "", "current") if (weechat.infolist_next(infolist)): start_line_y = weechat.infolist_integer(infolist, "start_line_y") chat_height = weechat.infolist_integer(infolist, "chat_height") if(start_line_y > current_line): weechat.command(urlgrab_buffer, "/window scroll -%i" %(start_line_y - current_line)) elif(start_line_y <= current_line - chat_height): weechat.command(urlgrab_buffer, "/window scroll +%i"%(current_line - start_line_y - chat_height + 1)) weechat.infolist_free(infolist)
def buffer_check_outside_window(): global curline if script_buffer(): infolist = weechat.infolist_get("window", "", "current") if weechat.infolist_next(infolist): start_line_y = weechat.infolist_integer(infolist, "start_line_y") chat_height = weechat.infolist_integer(infolist, "chat_height") if start_line_y > curline: weechat.command(script_buffer(), "/window scroll -%i" % (start_line_y - curline)) elif start_line_y <= curline - chat_height: weechat.command(script_buffer(), "/window scroll +%i" % (curline - start_line_y - chat_height + 1)) weechat.infolist_free(infolist)
def infolist_log_buffer(ptr_buffer): log_level = None infolist = weechat.infolist_get('logger_buffer','','') while weechat.infolist_next(infolist): bpointer = weechat.infolist_pointer(infolist, 'buffer') if ptr_buffer == bpointer: log_enabled = weechat.infolist_integer(infolist, 'log_enabled') log_level = weechat.infolist_integer(infolist, 'log_level') weechat.infolist_free(infolist) # free infolist() if not log_level: return 'disabled' else: return log_level
def get_servers(): """Get the servers that are not away, or were set away by this script""" infolist = w.infolist_get("irc_server", "", "") buffers = [] while w.infolist_next(infolist): if not w.infolist_integer(infolist, "is_connected") == 1: continue if not w.infolist_integer(infolist, "is_away") or w.infolist_string( infolist, "away_message" ) == w.config_get_plugin("message"): buffers.append((w.infolist_pointer(infolist, "buffer"), w.infolist_string(infolist, "nick"))) w.infolist_free(infolist) return buffers
def get_servers(): '''Get the servers that are not away, or were set away by this script''' infolist = w.infolist_get('irc_server', '', '') buffers = [] while w.infolist_next(infolist): if not w.infolist_integer(infolist, 'is_connected') == 1: continue if not w.infolist_integer(infolist, 'is_away') or \ w.infolist_string(infolist, 'away_message') == \ w.config_get_plugin('message'): buffers.append((w.infolist_pointer(infolist, 'buffer'), w.infolist_string(infolist, 'nick'))) w.infolist_free(infolist) return buffers
def check_nicks(data, remaining_calls): serverlist = OPTIONS['serverlist'].split(',') infolist = weechat.infolist_get('irc_server', '', '') while weechat.infolist_next(infolist): servername = weechat.infolist_string(infolist, 'name') ptr_buffer = weechat.infolist_pointer(infolist, 'buffer') nick = weechat.infolist_string(infolist, 'nick') ssl_connected = weechat.infolist_integer(infolist, 'ssl_connected') is_connected = weechat.infolist_integer(infolist, 'is_connected') if servername in serverlist: if nick and ssl_connected + is_connected: ison(ptr_buffer, servername, nick, server_nicks(servername)) weechat.infolist_free(infolist) return weechat.WEECHAT_RC_OK
def checknicks(data, remaining_calls): serverlist = OPTIONS['serverlist'].split(',') infolist = weechat.infolist_get('irc_server','','') while weechat.infolist_next(infolist): servername = weechat.infolist_string(infolist, 'name') bufpointer = weechat.infolist_pointer(infolist,'buffer') nick = weechat.infolist_string(infolist, 'nick') ssl_connected = weechat.infolist_integer(infolist,'ssl_connected') is_connected = weechat.infolist_integer(infolist,'is_connected') if servername in serverlist: if nick and ssl_connected + is_connected: ison(bufpointer,servername,nick,servernicks(servername)) weechat.infolist_free(infolist) return weechat.WEECHAT_RC_OK
def check_nicks(data, remaining_calls): infolist = weechat.infolist_get('irc_server','','') while weechat.infolist_next(infolist): servername = weechat.infolist_string(infolist, 'name') ptr_buffer = weechat.infolist_pointer(infolist,'buffer') nick = weechat.infolist_string(infolist, 'nick') ssl_connected = weechat.infolist_integer(infolist,'ssl_connected') is_connected = weechat.infolist_integer(infolist,'is_connected') if server_enabled(servername): if nick and ssl_connected + is_connected: ison(servername,nick,server_nicks(servername)) weechat.infolist_free(infolist) return weechat.WEECHAT_RC_OK
def get_servers(): '''Get the servers that are not away, or were set away by this script''' infolist = w.infolist_get('irc_server','','') buffers = [] while w.infolist_next(infolist): if not w.infolist_integer(infolist, 'is_connected') == 1: continue if not w.infolist_integer(infolist, 'is_away') or \ w.infolist_string(infolist, 'away_message') == \ w.config_get_plugin('message'): buffers.append((w.infolist_pointer(infolist, 'buffer'), w.infolist_string(infolist, 'nick'))) w.infolist_free(infolist) return buffers
def get_options(): """ Get list of config options in a dict with 4 indexes: config, section, option, xxx. """ global plugin_list, ignore_options options = \ defaultdict(lambda: defaultdict(lambda: defaultdict(defaultdict))) infolist = weechat.infolist_get('option', '', '') while weechat.infolist_next(infolist): full_name = weechat.infolist_string(infolist, 'full_name') if not re.search('|'.join(ignore_options), full_name): config = weechat.infolist_string(infolist, 'config_name') if config in plugin_list and 'o' in plugin_list[config]: section = weechat.infolist_string(infolist, 'section_name') option = weechat.infolist_string(infolist, 'option_name') for key in ('type', 'string_values', 'default_value', 'description'): options[config][section][option][key] = \ weechat.infolist_string(infolist, key) for key in ('min', 'max', 'null_value_allowed'): options[config][section][option][key] = \ weechat.infolist_integer(infolist, key) weechat.infolist_free(infolist) return options
def disable_logging(self): """Return the previous logger level and set the buffer logger level to 0. If it was already 0, return None.""" # If previous_log_level has not been previously set, return the level # we detect now. if not hasattr(self, 'previous_log_level'): infolist = weechat.infolist_get('logger_buffer', '', '') buf = self.buffer() previous_log_level = 0 while weechat.infolist_next(infolist): if weechat.infolist_pointer(infolist, 'buffer') == buf: previous_log_level = weechat.infolist_integer( infolist, 'log_level') if self.is_logged(): weechat.command(buf, '/mute logger disable') self.print_buffer( 'Logs have been temporarily disabled for the session. They will be restored upon finishing the OTR session.') break weechat.infolist_free(infolist) return previous_log_level # If previous_log_level was already set, it means we already altered it # and that we just detected an already modified logging level. # Return the pre-existing value so it doesn't get lost, and we can # restore it later. else: return self.previous_log_level
def format_option(match): """Replace ${xxx} by its value in option format.""" global cmdhelp_settings, cmdhelp_option_infolist, cmdhelp_option_infolist_fields string = match.group() end = string.find('}') if end < 0: return string field = string[2:end] color1 = '' color2 = '' pos = field.find(':') if pos: color1 = field[0:pos] field = field[pos + 1:] if color1: color1 = weechat.color(color1) color2 = weechat.color(cmdhelp_settings['color_option_help']) fieldtype = cmdhelp_option_infolist_fields.get(field, '') if fieldtype == 'i': string = str(weechat.infolist_integer(cmdhelp_option_infolist, field)) elif fieldtype == 's': string = weechat.infolist_string(cmdhelp_option_infolist, field) elif fieldtype == 'p': string = weechat.infolist_pointer(cmdhelp_option_infolist, field) elif fieldtype == 't': string = weechat.infolist_time(cmdhelp_option_infolist, field) return '%s%s%s' % (color1, string, color2)
def format_option(match): """Replace ${xxx} by its value in option format.""" global cmdhelp_settings, cmdhelp_option_infolist global cmdhelp_option_infolist_fields string = match.group() end = string.find('}') if end < 0: return string field = string[2:end] color1 = '' color2 = '' pos = field.find(':') if pos: color1 = field[0:pos] field = field[pos+1:] if color1: color1 = weechat.color(color1) color2 = weechat.color(cmdhelp_settings['color_option_help']) fieldtype = cmdhelp_option_infolist_fields.get(field, '') if fieldtype == 'i': string = str(weechat.infolist_integer(cmdhelp_option_infolist, field)) elif fieldtype == 's': string = weechat.infolist_string(cmdhelp_option_infolist, field) elif fieldtype == 'p': string = weechat.infolist_pointer(cmdhelp_option_infolist, field) elif fieldtype == 't': date = weechat.infolist_time(cmdhelp_option_infolist, field) # since WeeChat 2.2, infolist_time returns a long integer instead of # a string if not isinstance(date, str): date = time.strftime('%F %T', time.localtime(int(date))) string = date return '%s%s%s' % (color1, string, color2)
def set_away(message, overridable_messages=[]): '''Sets away status, but respectfully (so it doesn't change already set statuses''' if (w.config_get_plugin('away') == '1'): return # No need to go away again (this prevents some repeated messages) if (debug): w.prnt('', "Setting away to %s" % message) serverlist = w.infolist_get('irc_server', '', '') if serverlist: buffers = [] while w.infolist_next(serverlist): if w.infolist_integer(serverlist, 'is_away') == 0: if (debug): w.prnt( '', "Not away on %s" % w.infolist_string(serverlist, 'name')) ptr = w.infolist_pointer(serverlist, 'buffer') if ptr: buffers.append(ptr) elif w.infolist_string(serverlist, 'away_message') in overridable_messages: if (debug): w.prnt( '', "%s is in %s" % (w.infolist_string(serverlist, 'away_message'), repr(overridable_messages))) buffers.append(w.infolist_pointer(serverlist, 'buffer')) w.infolist_free(serverlist) if (debug): w.prnt('', repr(buffers)) for buffer in buffers: w.command(buffer, "/away %s" % message) w.config_set_plugin('away', '1')
def format_option(match): """Replace ${xxx} by its value in option format.""" global cmdhelp_settings, cmdhelp_option_infolist global cmdhelp_option_infolist_fields string = match.group() end = string.find('}') if end < 0: return string field = string[2:end] color1 = '' color2 = '' pos = field.find(':') if pos: color1 = field[0:pos] field = field[pos + 1:] if color1: color1 = weechat.color(color1) color2 = weechat.color(cmdhelp_settings['color_option_help']) fieldtype = cmdhelp_option_infolist_fields.get(field, '') if fieldtype == 'i': string = str(weechat.infolist_integer(cmdhelp_option_infolist, field)) elif fieldtype == 's': string = weechat.infolist_string(cmdhelp_option_infolist, field) elif fieldtype == 'p': string = weechat.infolist_pointer(cmdhelp_option_infolist, field) elif fieldtype == 't': date = weechat.infolist_time(cmdhelp_option_infolist, field) # since WeeChat 2.2, infolist_time returns a long integer instead of # a string if not isinstance(date, str): date = time.strftime('%F %T', time.localtime(int(date))) string = date return '%s%s%s' % (color1, string, color2)
def format_option(match): """Replace ${xxx} by its value in option format.""" global cmdhelp_settings, cmdhelp_option_infolist, cmdhelp_option_infolist_fields string = match.group() end = string.find('}') if end < 0: return string field = string[2:end] color1 = '' color2 = '' pos = field.find(':') if pos: color1 = field[0:pos] field = field[pos+1:] if color1: color1 = weechat.color(color1) color2 = weechat.color(cmdhelp_settings['color_option_help']) fieldtype = cmdhelp_option_infolist_fields.get(field, '') if fieldtype == 'i': string = str(weechat.infolist_integer(cmdhelp_option_infolist, field)) elif fieldtype == 's': string = weechat.infolist_string(cmdhelp_option_infolist, field) elif fieldtype == 'p': string = weechat.infolist_pointer(cmdhelp_option_infolist, field) elif fieldtype == 't': string = weechat.infolist_time(cmdhelp_option_infolist, field) return '%s%s%s' % (color1, string, color2)
def get_matching_buffers(input): """ Return list with buffers matching user input """ global buffers_pos list = [] if len(input) == 0: buffers_pos = 0 input = input.lower() infolist = weechat.infolist_get("buffer", "", "") while weechat.infolist_next(infolist): if weechat.config_get_plugin("short_name") == "on": name = weechat.infolist_string(infolist, "short_name") else: name = weechat.infolist_string(infolist, "name") number = weechat.infolist_integer(infolist, "number") matching = name.lower().find(input) >= 0 if not matching and input[-1] == ' ': matching = name.lower().endswith(input.strip()) if not matching and input.isdigit(): matching = str(number).startswith(input) if len(input) == 0 or matching: list.append({"number": number, "name": name}) if len(input) == 0 and weechat.infolist_pointer(infolist, "pointer") == weechat.current_buffer(): buffers_pos = len(list) - 1 weechat.infolist_free(infolist) return list
def _find_first_buffer_number(): infolist = weechat.infolist_get('buffer', '', '') while weechat.infolist_next(infolist): short_name = weechat.infolist_string(infolist, 'short_name') if _newserv_match(short_name): number = weechat.infolist_integer(infolist, 'number') return number
def get_matching_buffers(input): """ Return list with buffers matching user input """ global buffers_pos list = [] if len(input) == 0: buffers_pos = 0 input = input.lower() infolist = weechat.infolist_get("buffer", "", "") while weechat.infolist_next(infolist): if weechat.config_get_plugin("short_name") == "on": name = weechat.infolist_string(infolist, "short_name") else: name = weechat.infolist_string(infolist, "name") number = weechat.infolist_integer(infolist, "number") matching = name.lower().find(input) >= 0 if not matching and input[-1] == ' ': matching = name.lower().endswith(input.strip()) if not matching and input.isdigit(): matching = str(number).startswith(input) if len(input) == 0 or matching: list.append({"number": number, "name": name}) if len(input) == 0 and weechat.infolist_pointer( infolist, "pointer") == weechat.current_buffer(): buffers_pos = len(list) - 1 weechat.infolist_free(infolist) return list
def disable_logging(self): """Return the previous logger level and set the buffer logger level to 0. If it was already 0, return None.""" # If previous_log_level has not been previously set, return the level # we detect now. if not hasattr(self, 'previous_log_level'): infolist = weechat.infolist_get('logger_buffer', '', '') buf = self.buffer() previous_log_level = 0 while weechat.infolist_next(infolist): if weechat.infolist_pointer(infolist, 'buffer') == buf: previous_log_level = weechat.infolist_integer( infolist, 'log_level') if self.is_logged(): weechat.command(buf, '/mute logger disable') self.print_buffer( 'Logs have been temporarily disabled for the session. They will be restored upon finishing the OTR session.' ) break weechat.infolist_free(infolist) return previous_log_level # If previous_log_level was already set, it means we already altered it # and that we just detected an already modified logging level. # Return the pre-existing value so it doesn't get lost, and we can # restore it later. else: return self.previous_log_level
def get_servers(): '''Get the servers that are not away, or were set away by this script.''' ignores = w.config_get_plugin('ignore').split(',') infolist = w.infolist_get('irc_server', '', '') buffers = [] while w.infolist_next(infolist): if (not w.infolist_integer(infolist, 'is_connected') == 1 or w.infolist_string(infolist, 'name') in ignores): continue if (not w.config_string_to_boolean(w.config_get_plugin('set_away')) or not w.infolist_integer(infolist, 'is_away') or w.config_get_plugin('message') in w.infolist_string( infolist, 'away_message')): buffers.append((w.infolist_pointer(infolist, 'buffer'), w.infolist_string(infolist, 'nick'))) w.infolist_free(infolist) return buffers
def check_nicks(data, remaining_calls): serverlist = OPTIONS["serverlist"].split(",") infolist = weechat.infolist_get("irc_server", "", "") while weechat.infolist_next(infolist): servername = weechat.infolist_string(infolist, "name") ptr_buffer = weechat.infolist_pointer(infolist, "buffer") nick = weechat.infolist_string(infolist, "nick") ssl_connected = weechat.infolist_integer(infolist, "ssl_connected") is_connected = weechat.infolist_integer(infolist, "is_connected") server_matched = re.search(r"\b({})\b".format("|".join(serverlist)), servername) if servername in serverlist or server_matched and is_connected: if nick and ssl_connected + is_connected: ison(ptr_buffer, servername, nick, server_nicks(servername)) weechat.infolist_free(infolist) return weechat.WEECHAT_RC_OK
def get_logfile(window): current_buffer = weechat.window_get_pointer(window,"buffer") if current_buffer == "": return "" log_filename = "" log_enabled = 0 infolist = weechat.infolist_get('logger_buffer','','') while weechat.infolist_next(infolist): bpointer = weechat.infolist_pointer(infolist, 'buffer') if current_buffer == bpointer: log_filename = weechat.infolist_string(infolist, 'log_filename') log_enabled = weechat.infolist_integer(infolist, 'log_enabled') log_level = weechat.infolist_integer(infolist, 'log_level') weechat.infolist_free(infolist) # free infolist() return (log_filename,log_enabled)
def should_send(buffer, tags, nick, highlighted): if not nick: # a nick is required to form a correct message, bail return False if highlighted: if weechat.config_get_plugin('notify_on_highlight') != 'on': # notifying on highlights is disabled, bail return False elif weechat.buffer_get_string(buffer, 'localvar_type') == 'private': if weechat.config_get_plugin('notify_on_privmsg') != 'on': # notifying on private messages is disabled, bail return False else: # not a highlight or private message, bail return False notify_when = weechat.config_get_plugin('notify_when') if notify_when == 'never': # user has opted to not be notified, bail return False elif notify_when == 'away': # user has opted to only be notified when away infolist_args = ( weechat.buffer_get_string(buffer, 'localvar_channel'), weechat.buffer_get_string(buffer, 'localvar_server'), weechat.buffer_get_string(buffer, 'localvar_nick') ) if not None in infolist_args: infolist = weechat.infolist_get('irc_nick', '', ','.join(infolist_args)) if infolist: away_status = weechat.infolist_integer(infolist, 'away') weechat.infolist_free(infolist) if not away_status: # user is not away, bail return False elif notify_when == 'detached': # user has opted to only be notified when detached (relays) num_relays = weechat.info_get('relay_client_count', 'connected') if num_relays == 0: # no relays connected, bail return False if nick == weechat.buffer_get_string(buffer, 'localvar_nick'): # the sender was the current user, bail return False if nick in weechat.config_get_plugin('ignore_nicks').split(','): # the sender was on the ignore list, bail return False for buffer_name in get_buffer_names(buffer): if buffer_name in weechat.config_get_plugin('ignore_buffers').split(','): # the buffer was on the ignore list, bail return False return True
def chanact_cb(*kwargs): ''' Callback ran on hotlist changes ''' global keydict result = '' hotlist = w.infolist_get('hotlist', '', '') while w.infolist_next(hotlist): priority = w.infolist_integer(hotlist, 'priority') if priority < int(w.config_get_plugin('lowest_priority')): continue number = str(w.infolist_integer(hotlist, 'buffer_number')) thebuffer = w.infolist_pointer(hotlist, 'buffer_pointer') name = w.buffer_get_string(thebuffer, 'short_name') color = w.config_get_plugin('color_default') if priority > 0: color = w.config_get_plugin('color_%s' %priority) if number in keydict: number = keydict[number] result += '%s%s%s' % (w.color(color), number, w.color('reset')) elif name in keydict: name = keydict[name] result += '%s%s%s' % (w.color(color), name, w.color('reset')) elif name: result += '%s%s%s:%s%s%s' % ( w.color('default'), number, w.color('reset'), w.color(color), name[:int(w.config_get_plugin('item_length'))], w.color('reset')) else: result += '%s%s%s' % ( w.color(color), number, w.color(reset)) result += w.config_get_plugin('delimiter') w.infolist_free(hotlist) if result: result = '%s%s' % (w.config_get_plugin('message'), result.rstrip(w.config_get_plugin('delimiter'))) return result
def infolist_get_first_entry_from_hotlist(): infolist = weechat.infolist_get('hotlist', '', '') if infolist: weechat.infolist_next(infolist) # go to first entry in hotlist buffer_name = weechat.infolist_string(infolist, 'buffer_name') buffer_number = weechat.infolist_integer(infolist, 'buffer_number') ptr_buffer = weechat.infolist_pointer(infolist, 'buffer_pointer') weechat.infolist_free(infolist) return buffer_name, ptr_buffer, buffer_number
def infolist_relay(): infolist_relay = weechat.infolist_get('relay', '', '') if infolist_relay: while weechat.infolist_next(infolist_relay): status = weechat.infolist_integer(infolist_relay, 'status') status_string = weechat.infolist_string(infolist_relay, 'status_string') # weechat.prnt('', '%d %s' % (status, status_string)) weechat.infolist_free(infolist_relay) # don't forget to free() infolist! return weechat.WEECHAT_RC_OK
def get_matching_buffers(input): """ Return list with buffers matching user input """ global buffers_pos list = [] if len(input) == 0: buffers_pos = 0 input = input.lower() infolist = weechat.infolist_get("buffer", "", "") while weechat.infolist_next(infolist): if weechat.config_get_plugin("short_name") == "on": name = weechat.infolist_string(infolist, "short_name") else: name = weechat.infolist_string(infolist, "name") if weechat.config_get_plugin( "use_core_instead_weechat") == "on" and name == "weechat": name = "core" number = weechat.infolist_integer(infolist, "number") full_name = weechat.infolist_string(infolist, "full_name") if not full_name: full_name = "%s.%s" % (weechat.infolist_string( infolist, "plugin_name"), weechat.infolist_string(infolist, "name")) pointer = weechat.infolist_pointer(infolist, "pointer") matching = name.lower().find(input) >= 0 if not matching and input[-1] == ' ': matching = name.lower().endswith(input.strip()) if not matching and input.isdigit(): matching = str(number).startswith(input) if len(input) == 0 or matching: list.append({ "number": number, "name": name, "full_name": full_name, "pointer": pointer }) if len(input) == 0 and pointer == weechat.current_buffer(): buffers_pos = len(list) - 1 weechat.infolist_free(infolist) if not weechat.config_string_to_boolean( weechat.config_get_plugin('sort_by_activity')): return list # sort buffers like in hotlist. hotlist = [] infolist = weechat.infolist_get("hotlist", "", "") while weechat.infolist_next(infolist): hotlist.append(weechat.infolist_pointer(infolist, "buffer_pointer")) weechat.infolist_free(infolist) last_index = len(hotlist) def priority(b): try: return hotlist.index(b["pointer"]) except ValueError: # not in hotlist, always last. return last_index return sorted(list, key=priority)
def update_channel(server, channel=None): channel_infolist = weechat.infolist_get('irc_channel', '', server) while weechat.infolist_next(channel_infolist): _channel = weechat.infolist_string(channel_infolist, 'name') if channel: _channel = caseInsensibleKey(_channel) if _channel not in channel: continue channel_stats[server, _channel] = weechat.infolist_integer(channel_infolist, 'nicks_count') weechat.infolist_free(channel_infolist)
def get_fit_size(self): widths = [] heights = [] infolist = weechat.infolist_get("window", "", "") while weechat.infolist_next(infolist): buffer = weechat.infolist_pointer(infolist, "buffer") if buffer == self.buffer: width = weechat.infolist_integer(infolist, "chat_width") height = weechat.infolist_integer(infolist, "chat_height") widths.append(width) heights.append(height) weechat.infolist_free(infolist) if widths and heights: return (min(heights), min(widths)) else: return None
def hotlist(): hotlist_items = [] hotlist = weechat.infolist_get("hotlist", "", "") while weechat.infolist_next(hotlist): buffer_number = weechat.infolist_integer(hotlist, "buffer_number") buffer = weechat.infolist_pointer(hotlist, "buffer_pointer") short_name = weechat.buffer_get_string(buffer, "short_name") hotlist_items.append("%s:%s" % (buffer_number, short_name)) weechat.infolist_free(hotlist) return ",".join(hotlist_items)
def get_open_buffers(): buffers = [] infolist = w.infolist_get("buffer", "", "") if infolist: while w.infolist_next(infolist): name = w.infolist_string(infolist, "name") number = w.infolist_integer(infolist, "number") _ = "{0}:{1}".format(number, name) buffers.append(_) w.infolist_free(infolist) return buffers
def irc_servers(): ''' Disconnected IRC servers, workaround for /away -all bug in v. < 0.3.2 ''' serverlist = w.infolist_get('irc_server', '', '') buffers = [] if serverlist: while w.infolist_next(serverlist): if w.infolist_integer(serverlist, 'is_connected') == 0: buffers.append((w.infolist_pointer(serverlist, 'buffer'))) w.infolist_free(serverlist) return buffers