本文整理汇总了Python中weechat.infolist_string函数的典型用法代码示例。如果您正苦于以下问题:Python infolist_string函数的具体用法?Python infolist_string怎么用?Python infolist_string使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了infolist_string函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: match_against_nicklist
def match_against_nicklist(server, channel, hostmask):
"""Compare the hostmask against all users in the channel"""
infolist = w.infolist_get("irc_nick", "", "{},{}".format(server, channel))
if "$a:" in hostmask or "$~a" in hostmask:
field = "account"
hostmask = hostmask.replace("$a:", "")
hostfield = False
else:
field = "host"
hostfield = True
extban_unreg = hostmask == "$~a"
matches = []
while w.infolist_next(infolist):
name = w.infolist_string(infolist, "name")
if hostfield:
host = name + "!" + w.infolist_string(infolist, field)
else:
host = w.infolist_string(infolist, field)
if ((extban_unreg and host == "*") or
(not extban_unreg and w.string_match(host, hostmask, 0))):
matches.append(name)
w.infolist_free(infolist)
return matches
示例2: channel_block
def channel_block(server, channel):
fail = None
config_cycle = lambda opt: weechat.config_string_to_boolean(weechat.config_get_plugin("cycle_%s" % opt))
channels = weechat.infolist_get("irc_channel", "", "%s,%s" % (server, channel))
if weechat.infolist_next(channels):
modes = weechat.infolist_string(channels, "modes")
if " " in modes:
modes, modes_args = modes.split(" ", 1)
if not config_cycle("key") and weechat.infolist_string(channels, "key") != "":
fail = "cycle_key"
elif not config_cycle("invite") and "i" in modes:
fail = "cycle_invite"
elif not config_cycle("detach"):
fail = "cycle_detach"
weechat.infolist_free(channels)
if fail:
weechat.prnt("", "%s: won't automatically cycle %s.%s: %s" % (SCRIPT_NAME, server, channel, fail))
else:
servers[server]["channels"].append(channel)
buffer = weechat.buffer_search("irc", server)
weechat.command(buffer, "/part %s" % channel)
weechat.command(buffer, "/nick %s" % servers[server]["nick"])
示例3: find_channels
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
示例4: buffer_opened_closed_cb
def buffer_opened_closed_cb(data, signal, signal_data):
global OPTIONS
# localvar not set in this moment? :-(
# server = weechat.buffer_get_string(signal_data, 'localvar_server') # get internal servername
infolist = weechat.infolist_get('buffer', signal_data, '')
weechat.infolist_next(infolist)
plugin_name = weechat.infolist_string(infolist, 'plugin_name')
name = weechat.infolist_string(infolist, 'name')
weechat.infolist_free(infolist)
# TODO how about matrix script or other non-irc channel buffer? no idea! help is welcome
if plugin_name != "irc": # for example /fset, /color etc.pp buffer
return weechat.WEECHAT_RC_OK
if OPTIONS['activity'].lower() == 'no' or OPTIONS['activity'].lower() == 'off' or OPTIONS['activity'].lower() == '0':
weechat.command('','/allchan -exclude=%s /buffer hide' % OPTIONS['channel_exclude'])
if not signal_data: # signal_data available?
weechat.command(signal_data,'/allchan -current /buffer unhide')
else: # signal_data empty!
weechat.command('','/allchan /buffer hide')
exclude_server('')
single_channel_exclude()
else:
weechat.command('','/allchan /buffer hide')
exclude_hotlist()
return weechat.WEECHAT_RC_OK
示例5: get_nicklist
def get_nicklist(server, channel):
global options
regex_flags = 0
if options['ignore_case']:
regex_flags = re.IGNORECASE
ignore_list = w.config_get_plugin('ignore_list')
if ignore_list == '':
ignore_match = lambda x: False
else:
ignore_match = re.compile('(%s)$' % ignore_list.replace(',', '|'), regex_flags).match
server = w.buffer_get_string(w.current_buffer(), 'localvar_server')
my_nick = w.info_get('irc_nick', server)
nicklist = {}
infolist_nicklist = w.infolist_get('nicklist', w.current_buffer(), '')
while w.infolist_next(infolist_nicklist):
nick = w.infolist_string(infolist_nicklist, 'name')
prefix = w.infolist_string(infolist_nicklist, 'prefix')
nick_type = w.infolist_string(infolist_nicklist, 'type')
if nick_type != 'nick' or (options['ignore_self'] and nick == my_nick) or ignore_match(nick):
pass
else:
if not nicklist.has_key(prefix):
nicklist[prefix]=[]
nicklist[prefix].append(nick)
w.infolist_free(infolist_nicklist)
return nicklist
示例6: bufsave_cmd
def bufsave_cmd(data, buffer, args):
''' Callback for /bufsave command '''
filename = args
if not filename:
w.command('', '/help %s' %SCRIPT_COMMAND)
return w.WEECHAT_RC_OK
if exists(filename):
w.prnt('', "Error: target file already exists!")
return w.WEECHAT_RC_OK
infolist = w.infolist_get('buffer_lines', buffer, '')
channel = w.buffer_get_string(buffer, 'name')
try:
fp = file(filename, 'w')
except:
w.prnt('', "Error writing to target file!")
return w.WEECHAT_RC_OK
while w.infolist_next(infolist):
fp.write('%s %s %s\n' %(\
w.infolist_time(infolist, 'date'),
cstrip(w.infolist_string(infolist, 'prefix')),
cstrip(w.infolist_string(infolist, 'message')),
))
w.infolist_free(infolist)
return w.WEECHAT_RC_OK
示例7: get_option_list_and_desc
def get_option_list_and_desc(option, displayname):
"""Get list of options and description for option(s)."""
global cmdhelp_settings, cmdhelp_option_infolist
global cmdhelp_option_infolist_fields
options = []
description = ''
cmdhelp_option_infolist = weechat.infolist_get('option', '', option)
if cmdhelp_option_infolist:
cmdhelp_option_infolist_fields = {}
while weechat.infolist_next(cmdhelp_option_infolist):
options.append(weechat.infolist_string(cmdhelp_option_infolist,
'full_name'))
if not description:
fields = weechat.infolist_fields(cmdhelp_option_infolist)
for field in fields.split(','):
items = field.split(':', 1)
if len(items) == 2:
cmdhelp_option_infolist_fields[items[1]] = items[0]
description = re.compile(r'\$\{[^\}]+\}').sub(
format_option, cmdhelp_settings['format_option'])
if displayname:
description = '%s%s%s: %s' % (
weechat.color(cmdhelp_settings['color_option_name']),
weechat.infolist_string(cmdhelp_option_infolist,
'full_name'),
weechat.color(cmdhelp_settings['color_option_help']),
description)
weechat.infolist_free(cmdhelp_option_infolist)
cmdhelp_option_infolist = ''
cmdhelp_option_infolist_fields = {}
return options, description
示例8: reorder_buffers
def reorder_buffers():
global buffers
bufcopy = dict(buffers)
priolist = []
while len(bufcopy):
priolist.append(max(bufcopy, key=bufcopy.get))
bufcopy.pop(max(bufcopy, key=bufcopy.get))
pointerlist = {}
infolist = wee.infolist_get("buffer", "", "")
while wee.infolist_next(infolist): # go through the buffers and jot down relevant pointers
for name in priolist:
try:
bufname = wee.infolist_string(infolist, "name").split('.', 1)[1]
except IndexError:
bufname = wee.infolist_string(infolist, "name")
if name == bufname:
if name in pointerlist:
pointerlist[name].append(
wee.infolist_pointer(infolist, "pointer"))
else:
pointerlist[name] = [wee.infolist_pointer(
infolist, "pointer")]
index = 1
if(maintop):
index += 1
for name in priolist:
if name in pointerlist:
for pointer in pointerlist[name]:
wee.buffer_set(pointer, "number", str(index))
index += 1
return
示例9: get_patterns_in_config
def get_patterns_in_config(filter):
d = {}
infolist = weechat.infolist_get('option', '', 'plugins.var.python.%s.%s' %(SCRIPT_NAME, filter))
while weechat.infolist_next(infolist):
name = weechat.infolist_string(infolist, 'option_name')
name = name[len('python.%s.' %SCRIPT_NAME):]
# channels might have dots in their names, so we'll strip type from right and server
# from left. Lets hope that users doesn't use dots in server names.
name, _, type = name.rpartition('.')
if type not in ('op', 'halfop', 'voice'):
# invalid option
continue
server, _, channel = name.partition('.')
value = weechat.infolist_string(infolist, 'value')
if not value:
continue
else:
value = value.split(',')
key = (server, channel)
if key not in d:
d[key] = {type:value}
else:
d[key][type] = value
weechat.infolist_free(infolist)
return d
示例10: get_options
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
示例11: get_help_command
def get_help_command(plugin, input_cmd, input_args):
"""Get help for command in input."""
global cmdhelp_settings
if input_cmd == 'set' and input_args:
return get_help_option(input_args)
infolist = weechat.infolist_get('hook', '', 'command,%s' % input_cmd)
cmd_plugin_name = ''
cmd_command = ''
cmd_args = ''
cmd_desc = ''
while weechat.infolist_next(infolist):
cmd_plugin_name = (weechat.infolist_string(infolist, 'plugin_name') or
'core')
cmd_command = weechat.infolist_string(infolist, 'command')
cmd_args = weechat.infolist_string(infolist, 'args_nls')
cmd_desc = weechat.infolist_string(infolist, 'description')
if weechat.infolist_pointer(infolist, 'plugin') == plugin:
break
weechat.infolist_free(infolist)
if cmd_plugin_name == 'alias':
return '%sAlias %s%s%s => %s%s' % (
weechat.color(cmdhelp_settings['color_alias']),
weechat.color(cmdhelp_settings['color_alias_name']),
cmd_command,
weechat.color(cmdhelp_settings['color_alias']),
weechat.color(cmdhelp_settings['color_alias_value']),
cmd_desc,
)
if input_args:
cmd_args = get_command_arguments(input_args, cmd_args)
if not cmd_args:
return None
return '%s%s' % (weechat.color(cmdhelp_settings['color_arguments']),
cmd_args)
示例12: get_list_commands
def get_list_commands(plugin, input_cmd, input_args):
"""Get list of commands (beginning with current input)."""
global cmdhelp_settings
infolist = weechat.infolist_get('hook', '', 'command,%s*' % input_cmd)
commands = []
plugin_names = []
while weechat.infolist_next(infolist):
commands.append(weechat.infolist_string(infolist, 'command'))
plugin_names.append(
weechat.infolist_string(infolist, 'plugin_name') or 'core')
weechat.infolist_free(infolist)
if commands:
if len(commands) > 1 or commands[0].lower() != input_cmd.lower():
commands2 = []
for index, command in enumerate(commands):
if commands.count(command) > 1:
commands2.append('%s(%s)' % (command, plugin_names[index]))
else:
commands2.append(command)
return '%s%d commands: %s%s' % (
weechat.color(cmdhelp_settings['color_list_count']),
len(commands2),
weechat.color(cmdhelp_settings['color_list']),
', '.join(commands2))
return None
示例13: reorder_buffers
def reorder_buffers():
"""Reorders the buffers once the whitelist has changed
"""
count = 2
chan = ""
ilist = weechat.infolist_get("buffer", "", "")
for chan in whitelist:
if -1 == chan.find(".#"): #network name is not set, matching by short_name
weechat.infolist_reset_item_cursor(ilist)
while weechat.infolist_next(ilist):
if weechat.infolist_string(ilist, "short_name") == chan:
chan = weechat.infolist_string(ilist, "name")
break
buff = weechat.buffer_search("irc", chan)
if buff:
weechat.buffer_set(buff, "number", str(count))
count += 1
weechat.infolist_free(ilist)
return weechat.WEECHAT_RC_OK
示例14: get_clones_for_buffer
def get_clones_for_buffer(infolist_buffer_name, hostname_to_match=None):
matches = {}
infolist = weechat.infolist_get("irc_nick", "", infolist_buffer_name)
while(weechat.infolist_next(infolist)):
ident_hostname = weechat.infolist_string(infolist, "host")
host_matchdata = re.match('([^@]+)@(\S+)', ident_hostname)
if not host_matchdata:
continue
hostname = host_matchdata.group(2).lower()
ident = host_matchdata.group(1).lower()
if weechat.config_get_plugin("compare_idents") == "on":
hostkey = ident_hostname.lower()
else:
hostkey = hostname
if hostname_to_match and hostname_to_match.lower() != hostkey:
continue
nick = weechat.infolist_string(infolist, "name")
matches.setdefault(hostkey,[]).append({
'nick': nick,
'mask': "%s!%s" % (
format_from_config(nick, "colors.mask.nick"),
format_from_config(ident_hostname, "colors.mask.identhost")),
'ident': ident,
'ident_hostname': ident_hostname,
'hostname': hostname,
})
weechat.infolist_free(infolist)
#Select only the results that have more than 1 match for a host
return dict((k, v) for (k, v) in matches.iteritems() if len(v) > 1)
示例15: keydict_update
def keydict_update(*args):
'''Populate a python dictionary with relevant key=>buffer mappings.'''
global keydict
keylist = w.infolist_get('key', '', '')
if w.config_get_plugin('use_keybindings') == 'on':
while w.infolist_next(keylist):
key = w.infolist_string(keylist, 'key')
# we dont want jump sequences
if 'j' in key:
continue
key = key.replace('meta-', '')
key = key.replace('ctrl-', '^')
if w.config_get_plugin('skip_number_binds') == 'on':
# skip entries where buffer number = key, typically entries below 11
if key.isdigit():
continue
command = w.infolist_string(keylist, 'command')
# we only care about commands that leads to buffers
if command.startswith('/buffer'):
command = command.replace('/buffer ', '')
buffer = command.lstrip('*')
keydict[buffer] = key
w.infolist_free(keylist)
return w.WEECHAT_RC_OK