本文整理汇总了Python中weechat.hook_config函数的典型用法代码示例。如果您正苦于以下问题:Python hook_config函数的具体用法?Python hook_config怎么用?Python hook_config使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了hook_config函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_hooks
def create_hooks():
# create hooks
weechat.hook_signal('quit', 'quit_signal_cb', '')
weechat.hook_signal('upgrade_ended', 'upgrade_ended_cb', '')
weechat.hook_signal('buffer_opened', 'buffer_opened_cb', '')
weechat.hook_config('plugins.var.python.' + SCRIPT_NAME + '.*', 'toggle_refresh', '' )
weechat.hook_signal('buffer_closing', 'buffer_closing_cb', '')
示例2: main
def main():
""" Entry point, initializes everything """
weechat.register(
SCRIPT_NAME,
SCRIPT_AUTHOR,
SCRIPT_VERSION,
SCRIPT_LICENSE,
SCRIPT_DESCRIPTION,
"", # Shutdown callback function
"", # Charset (blank for utf-8)
)
# Default values for settings
default_settings = {
'dbfile': os.path.join(
weechat.info_get("weechat_dir", ""), "emojis-db.dat")
}
# Apply default configuration values if anything is unset
for option, default in default_settings.items():
if not weechat.config_is_set_plugin(option):
weechat.config_set_plugin(option, default)
# Hook callbacks
weechat.hook_config("plugins.var.python." + SCRIPT_NAME + ".*",
"configuration_cb", "")
weechat.hook_command_run("/input return", "transform_cb", "")
weechat.hook_command_run("/input complete*", "complete_cb", "")
#weechat.hook_modifier("input_text_display", "collapse_cb", "")
# Command callbacks
weechat.hook_command( # command name
SCRIPT_NAME,
# description
" display :common_name: with its emoji equivalent",
# arguments
"reload"
" || add <name> <emoji>"
" || show <emoji>",
# description of arguments
" name: emoji name, sans colons\n"
"emoji: text that replaces :name:\n",
# completions
"reload || add || show %(emoji_name)", "emojis_cb", "")
weechat.hook_completion("emoji_name", "Emoji name", "emoji_name_completion_cb", "")
dbfile = weechat.config_get_plugin("dbfile")
weechat.prnt("", "%s: Loading emojis from %s" % (SCRIPT_NAME, dbfile))
try:
load_emojis(dbfile)
except IOError as e:
weechat.prnt("",
"%s%s: Database file %s is missing or inaccessible." \
% (weechat.prefix("error"), SCRIPT_NAME, dbfile))
raise e # TODO: handle this better instead of brutally aborting
示例3: init_config
def init_config():
for option, (default_value, description) in SW_CONFIG_DEFAULTS.items():
if not weechat.config_is_set_plugin(option):
weechat.config_set_plugin(option, default_value)
sw_config[option] = default_value
else:
sw_config[option] = weechat.config_get_plugin(option)
weechat.config_set_desc_plugin(option, '%s (default: "%s")' % (description, default_value))
weechat.hook_config('plugins.var.python.' + SCRIPT_NAME + '.*', 'update_config', '')
示例4: main
def main():
""" Entry point, initializes everything """
weechat.register(
SCRIPT_NAME,
SCRIPT_AUTHOR,
SCRIPT_VERSION,
SCRIPT_LICENSE,
SCRIPT_DESCRIPTION,
"", # Shutdown callback function
"", # Charset (blank for utf-8)
)
# Default values for settings
default_settings = {
'dbfile': os.path.join(
weechat.info_get("weechat_dir", ""), "emojis-db.dat")
}
# Apply default configuration values if anything is unset
for option, default in default_settings.items():
if not weechat.config_is_set_plugin(option):
weechat.config_set_plugin(option, default)
# Hook callbacks
weechat.hook_config(
"plugins.var.python." + SCRIPT_NAME + ".*",
"configuration_cb", "")
weechat.hook_command_run("/input return", "transform_cb", "")
weechat.hook_command_run("/input complete*", "complete_cb", "")
# Command callbacks
weechat.hook_command(
"reloademojis", "reload emojis from file",
"", "", "", "reload_emojis_cb", "")
dbfile = weechat.config_get_plugin("dbfile")
weechat.prnt("", "%s: Loading emojis from %s" % (SCRIPT_NAME, dbfile))
try:
load_emojis(dbfile)
except IOError as e:
weechat.prnt(
"",
"%s%s: Database file %s is missing or inaccessible."
% (weechat.prefix("error"), SCRIPT_NAME, dbfile))
raise e # TODO: handle this better instead of brutally aborting
示例5: init_script
def init_script():
global default_settings
for option, default_value in default_settings.items():
if not weechat.config_is_set_plugin(option):
weechat.config_set_plugin(option, default_value)
weechat.hook_command(
"weemustfeed",
"open/switch to weemustfeed buffer",
"",
"",
"",
"weemustfeed_command_cb", ""
)
weechat.hook_config(
"plugins.var.python.weemustfeed.interval",
"weemustfeed_reset_timer_cb", ""
)
示例6: config_init
def config_init():
"""Add configuration options to weechat."""
global KEEP_ALIVE_TIMEOUT
config = {
"hide_inactive": ("off", "Hide inactive buffers"),
"hide_private": ("off", "Hide private buffers"),
"unhide_low": ("off",
"Unhide a buffer when a low priority message (like JOIN, PART, etc.) has been received"),
"exemptions": ("", "An enumeration of buffers that should not get hidden"),
"keep_open": ("off", "Keep a buffer open for a short amount of time"),
"keep_open_timeout": ("60 * 1000", "Timeout in milliseconds for how long a selected buffer should be kept around"),
}
for option, default_value in config.items():
if weechat.config_get_plugin(option) == "":
weechat.config_set_plugin(option, default_value[0])
weechat.config_set_desc_plugin(
option, '{} (default: "{}")'.format(default_value[1], default_value[0]))
weechat.hook_config("plugins.var.python.buffer_autohide.keep_open_timeout", "timeout_config_changed_cb", "")
if weechat.config_is_set_plugin("keep_open_timeout"):
KEEP_ALIVE_TIMEOUT = eval_expr(weechat.config_get_plugin("keep_open_timeout"))
示例7: main
def main():
at_config('load')
# hook our config
weechat.hook_config(STRIP_VAR+'*','at_config','')
# hook the nick complete
weechat.hook_command_run('/input complete_next', 'at_completion', '')
# hook the /atcomplete
weechat.hook_command('atcomplete','manage @nick completion plugin',
'[enable|disable|toggle] '
' | [servers [list | add name | del name]]'
' | [buffers [list | add name | del name]]',
'args desc',
'status %-'
' || enable %-'
' || disable %-'
' || toggle %-'
' || server list|add|del %(buffers_names)'
' || buffer list|add|del %(buffers_names)'
,
'at_control','')
# hook the completetion for /atcomplete
weechat.hook_completion('plugin_at_completion','@nick completion','at_complete','')
示例8:
ignore_nick and ignore_text in plugins.var.python.%(script)s
Each config option accepts a comma separated list of patterns.
Wildcards '*', '?' and char groups [..] can be used.
An ignore exception can be added by prefixing '!' in the pattern.
Examples:
Setting 'ignore_nick' to 'troll,b[0o]t':
will ignore notifications from troll, bot and b0t.
Setting 'ignore_channel' to '*ubuntu*,!#ubuntu-offtopic':
will ignore notifications from any channel with the word 'ubuntu'
except from #ubuntu-offtopic.
Daemon:
%(script)s script needs to connect to an external daemon for send
notifications, which can be used in localhost or remotely.
Download the daemon from:
%(daemon_url)s
and check its help with ./%(daemon)s --help.
See also help in script file.
""" %dict(script=SCRIPT_NAME, daemon_url=DAEMON_URL, daemon=DAEMON)
,'test|notify|restart|quit', 'cmd_notify', '')
weechat.hook_config('plugins.var.python.%s.ignore_*' %SCRIPT_NAME, 'ignore_update', '')
weechat.hook_config('plugins.var.python.%s.server_*' %SCRIPT_NAME, 'server_update', '')
weechat.hook_print('', 'notify_message', '', 1, 'notify_msg', workaround)
weechat.hook_print('', 'notify_private', '', 1, 'notify_msg', workaround)
# vim:set shiftwidth=4 tabstop=4 softtabstop=4 expandtab textwidth=100:
示例9: fish_config_init
"\n"
"Without arguments this command lists all keys.\n"
"\n"
"Examples:\n"
"Set the key for a channel: /blowkey set -server freenet #blowfish key\n"
"Remove the key: /blowkey remove #blowfish\n"
"Set the key for a query: /blowkey set nick secret+key\n"
"List all keys: /blowkey\n\n"
"\n** stores keys in plaintext by default **\n\n"
"DH1080: /blowkey exchange nick\n"
"\nPlease read the source for a note about DH1080 key exchange\n",
"list"
"|| genkey"
"|| set %(irc_channel)|%(nicks)|-server %(irc_servers) %- "
"|| remove %(irc_channel)|%(nicks)|-server %(irc_servers) %- "
"|| exchange %(nick)|-server %(irc_servers) %-",
"fish_cmd_blowkey", "")
fish_config_init()
fish_config_read()
fish_secure()
weechat.hook_modifier("irc_in_notice", "fish_modifier_in_notice_cb", "")
weechat.hook_modifier("irc_in_privmsg", "fish_modifier_in_privmsg_cb", "")
weechat.hook_modifier("irc_in_topic", "fish_modifier_in_topic_cb", "")
weechat.hook_modifier("irc_in_332", "fish_modifier_in_332_cb", "")
weechat.hook_modifier("irc_out_privmsg", "fish_modifier_out_privmsg_cb", "")
weechat.hook_modifier("irc_out_topic", "fish_modifier_out_topic_cb", "")
weechat.hook_modifier("input_text_for_buffer", "fish_modifier_input_text", "")
weechat.hook_config("fish.secure.key", "fish_secure_key_cb", "")
示例10: purge
" size : greater than <Kib> for log-files to purge\n"
" size_ls : less than <Kib> for log-files to purge\n"
" age : older than <days> for log-files to purge (maximum value: 9999)\n"
" age_ls : younger than <days> for log-files to purge\n"
" delete : argument for security reasons\n"
"\n"
# str_commands + "\n"
"Examples:\n"
" show log-files older than 100 days\n"
" /" + SCRIPT_NAME + " age 100\n"
" purge log-files older than 100 days\n"
" /" + SCRIPT_NAME + " age 100 delete\n"
" show log-files younger than 10 days\n"
" /" + SCRIPT_NAME + " age_ls 10\n"
" purge log-files younger than 10 days\n"
" /" + SCRIPT_NAME + " age_ls 10 delete\n"
" show log-files greater than 100 KiB\n"
" /" + SCRIPT_NAME + " size 100\n"
" purge log-files greater than 100 KiB\n"
" /" + SCRIPT_NAME + " size 100 delete\n",
"age|age_ls|size|size_ls %-",
"purgelogs_cb", "")
w.hook_config('plugins.var.python.%s.blacklist' %SCRIPT_NAME, 'update_blacklist', '')
for option, default_value in purgelogs_options.items():
# for option, default_value in purgelogs_options.iteritems():
if w.config_get_plugin(option) == "":
w.config_set_plugin(option, default_value)
else:
blacklist = w.config_get_plugin('blacklist').split(',')
示例11: config_changed
def config_changed(data, option, value):
init_config()
return w.WEECHAT_RC_OK
def tc_action_cb():
global tc_options
if tc_options['warn_command']:
if tc_options['warn_command'] == '$bell':
f = open('/dev/tty', 'w')
f.write('\a')
f.close()
else:
os.system(tc_options['warn_command'])
return w.WEECHAT_RC_OK
if __name__ == "__main__" and import_ok:
if w.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION,
SCRIPT_LICENSE, SCRIPT_DESC,
"", ""):
version = w.info_get("version_number", "") or 0
init_config() # read configuration
tc_bar_item_update() # update status bar display
w.hook_signal('input_text_changed', 'tc_bar_item_update', '')
w.hook_signal('input_text_cursor_moved','tc_bar_item_update','')
w.hook_command_run('/input move_previous_char','command_run_cb','')
w.hook_command_run('/input delete_previous_char','command_run_cb','')
w.hook_signal('buffer_switch','tc_bar_item_update','')
w.hook_config('plugins.var.python.' + SCRIPT_NAME + ".*", "config_changed", "")
w.bar_item_new('tc', 'tc_bar_item', '')
示例12: Ignores
if __name__ == "__main__":
if w.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION, SCRIPT_LICENSE,
SCRIPT_DESC, "", ""):
# Set default settings
for option, default_value in settings.iteritems():
if not w.config_is_set_plugin(option):
w.config_set_plugin(option, default_value)
ignore_buffers = Ignores('ignore_buffers')
w.hook_print("", "", "://", 1, "url_print_cb", "")
w.hook_timer(\
int(w.config_get_plugin('reannounce_wait')) * 1000 * 60,
0,
0,
"purge_cb",
'')
weechat.hook_config('plugins.var.python.%s.ignore_buffers' %SCRIPT_NAME, 'ignore_update', '')
color_chat_delimiters = weechat.color('chat_delimiters')
color_chat_nick = weechat.color('chat_nick')
color_reset = weechat.color('reset')
color_chat_buffer = weechat.color('chat_buffer')
# pretty printing
script_nick = '%s[%s%s%s]%s' %(color_chat_delimiters,
color_chat_nick,
w.config_get_plugin('global_prefix'),
color_chat_delimiters,
color_reset)
示例13: Config
## Example
As an example, consider the following rule list:
0: core = 0
1: irc = 2
2: * = 1
3: irc.server.*.#* = 1
4: irc.server.*.* = 0
Rule 0 ensures the core buffer is always sorted first.
Rule 1 sorts IRC buffers last and rule 2 puts all remaining buffers in between the two.
Rule 3 and 4 would make no sense with the group_irc option off.
With the option on though, these rules will sort private buffers before regular channel buffers.
Rule 3 matches channel buffers and assigns them a higher score,
while rule 4 matches the buffers that remain and assigns them a lower score.
The same effect could also be achieved with a single rule:
irc.server.*.[^#]* = 0
'''
command_completion = 'sort||rules list|add|insert|update|delete|move|swap||replacements list|add|insert|update|delete|move|swap'
if weechat.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION, SCRIPT_LICENSE, SCRIPT_DESC, "", ""):
config = Config('autosort')
weechat.hook_config('autosort.*', 'on_config_changed', '')
weechat.hook_command('autosort', command_description, '', '', command_completion, 'on_autosort_command', 'NULL')
on_config_changed()
示例14: update_blacklist
return w.WEECHAT_RC_OK
def update_blacklist(*args):
''' Set the blacklist for channels and nicks. '''
global ignore_channels, ignore_nicks
ignore_channels = w.config_string(colorize_config_option['blacklist_channels']).split(',')
ignore_nicks = w.config_string(colorize_config_option['blacklist_nicks']).split(',')
return w.WEECHAT_RC_OK
if __name__ == "__main__":
if w.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION, SCRIPT_LICENSE,
SCRIPT_DESC, "", ""):
colorize_config_init()
colorize_config_read()
# Run once to get data ready
update_blacklist()
populate_nicks()
w.hook_signal('nicklist_nick_added', 'add_nick', '')
w.hook_signal('nicklist_nick_removed', 'remove_nick', '')
w.hook_modifier('weechat_print', 'colorize_cb', '')
# Hook config for changing colors
w.hook_config('weechat.color.chat_nick_colors', 'populate_nicks', '')
# Hook for working togheter with other scripts (like colorize_lines)
w.hook_modifier('colorize_nicks', 'colorize_cb', '')
# Hook for modifying input
w.hook_modifier('250|input_text_display', 'colorize_input_cb', '')
# Hook for updating blacklist (this could be improved to use fnmatch)
weechat.hook_config('%s.look.blacklist*' % SCRIPT_NAME, 'update_blacklist', '')
示例15:
" /uotp list\n"+
" /uotp add freenode 4c6fdb7d0659bae2a16d23bab99678462b9f7897\n"+
" /uotp add freenode jrx5 w7ig lg5o filn eo5l tfty iyvz 66ex\n"+
" /uotp remove freenode\n"+
" /uotp enable freenode\n"+
" /uotp disable freenode",
"otp %(irc_servers)"
" || list"
" || add %(irc_servers)"
" || remove %(configured_servers)"
" || enable %(irc_servers)"
" || disable %(disabled_servers)",
"options_cb", "")
weechat.hook_signal("irc_server_connecting", "signal_cb", "")
weechat.hook_signal("irc_server_disconnected", "signal_cb", "")
weechat.hook_config("plugins.var.python.undernet_totp.otp_server_names", "config_update_cb", "")
weechat.hook_completion("configured_servers", "list of otp configured servers", "server_completion_cb", "configured_servers")
weechat.hook_completion("disabled_servers", "list of disabled servers", "server_completion_cb", "enabled_servers")
weechat.hook_modifier("input_text_display", "hide_secret_cb", "")
for option, default_value in SETTINGS.items():
if weechat.config_get_plugin(option) == "":
weechat.config_set_plugin(option, default_value[0])
weechat.config_set_desc_plugin(option, '%s (default: %s)' % (default_value[1], default_value[0]))
# For now we enable the hooks until it's possible to force script plugins to
# load before the irc plugin on weechat startup, otherwise the irc_server_connecting signal
# get missed.
for server in enabled_servers():
hook_all(server)