Exemplo n.º 1
0
def register():
    weechat.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION,
        SCRIPT_LICENSE, SCRIPT_DESC, '', '')

    weechat.hook_print('', 'irc_332', '', 1, 'print_332', '')
    weechat.hook_print('', 'irc_topic', '', 1, 'print_topic', '')
    weechat.hook_signal('*,irc_in2_332', 'irc_in2_332', '')
    weechat.hook_signal('*,irc_in2_topic', 'irc_in2_topic', '')
Exemplo n.º 2
0
def signal_irc_pv_opened(data, signal, signal_data):
    global irc_pv_hook, irc_out_hook
    if weechat.buffer_get_string(signal_data, "plugin") == "irc":
        nick = weechat.buffer_get_string(signal_data, "localvar_channel")
        if weechat.info_get("irc_is_nick", nick) == "1":
            # query open, wait for a msg to come (query was open by user) or if we send a msg out
            # (query was open by us)
            unhook_all()
            server = weechat.buffer_get_string(signal_data, "localvar_server")
            irc_pv_hook = weechat.hook_signal("irc_pv", "signal_irc_pv", "%s,%s" % (signal_data, nick))
            irc_out_hook = weechat.hook_signal(server + ",irc_out_PRIVMSG", "signal_irc_out", "")
    return weechat.WEECHAT_RC_OK
def main():
    if not weechat.register("terminal_notifier", "Keith Smiley", "1.1.0", "MIT",
                            "Get OS X notifications for messages", "", ""):
        return weechat.WEECHAT_RC_ERROR

    if distutils.spawn.find_executable("osascript") is None:
        return weechat.WEECHAT_RC_OK

    weechat.hook_signal("weechat_pv", "notify", "")
    weechat.hook_signal("weechat_highlight", "notify", "")

    return weechat.WEECHAT_RC_OK
Exemplo n.º 4
0
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', '')
Exemplo n.º 5
0
def create_hooks():
    # create hooks
    weechat.hook_signal('quit', 'quit_signal_cb', '')
    weechat.hook_signal('upgrade_ended', 'upgrade_ended_cb', '')
    # low priority for hook_signal('buffer_opened') to ensure that buffer_autoset hook_signal() runs first
    weechat.hook_signal('1000|buffer_opened', 'buffer_opened_cb', '')
    weechat.hook_config('plugins.var.python.' + SCRIPT_NAME + '.*', 'toggle_refresh', '' )
    weechat.hook_signal('buffer_closing', 'buffer_closing_cb', '')
Exemplo n.º 6
0
def _highlight_msg_cb(data, buffer, date, tags, displayed,
                      highlight, prefix, message):
    '''Weechat message highlight callback. This is called when a message
    arrives with user's nick in it.

    https://weechat.org/files/doc/stable/weechat_plugin_api.en.html
    '''
    if not int(highlight) and 'notify_private' not in tags:
        return weechat.WEECHAT_RC_OK

    global g_pipe_write_fd
    global g_buffer_hook
    try:
        os.write(g_pipe_write_fd, 'SET')

    except OSError as e:
        weechat.unhook_all()
        weechat.prnt('', 'problem on using pipe fd, unhooking msg' %
                     str(e))

    if g_buffer_hook is None:
        g_buffer_hook = weechat.hook_signal('key_pressed',
                                            '_key_pressed_cb',
                                            '')

    return weechat.WEECHAT_RC_OK
Exemplo n.º 7
0
def setup_timeline(timelined, followed=False, search=False):
    """Sets up the main timeline window."""
    global hooks
    global user
    global tlid
    global buffers
    if not search:
        name = "timeline"
        title = "%s's timeline" % user.screen_name
        prefix = "__TIMELINE"
        search = False
        buf_cb = "tweet_cb"
    else:
        name = search
        title = "Twitter search for %s" % search
        prefix = md5(search).hexdigest()
        buf_cb = "tweet_cb"
    buf = wc.buffer_new(name, buf_cb, "", "stop_timelined", prefix)
    # Some naming
    wc.buffer_set(buf, "title", title)

    # We want mentions to highlight.
    wc.buffer_set(buf, "highlight_words", user.screen_name)

    if followed:
        # We want a nicklist to hold everyone we follow.
        wc.buffer_set(buf, "nicklist", "1")
        add_to_nicklist(buf, user.screen_name)

        for screen_name in followed:
            add_to_nicklist(buf, screen_name)

    storage_dir = wc.config_get_plugin("storage_dir")
    command = timelined + " " + storage_dir
    if search:
        command += " '%s'" % search
    timelinestream_hook = wc.hook_process(
        command,
        0, "timelined_cb", prefix)

    strkey = prefix + "STREAM"
    hooks[strkey] = timelinestream_hook

    # Check if there are new timeline entries every second.
    timelinedisplay_hook = wc.hook_timer(1 * 1000, 60, 0, "display_cb",
        prefix)
    diskey = prefix + "DISPLAY"
    hooks[diskey] = timelinedisplay_hook
    if search:
        wc.buffer_set(buf, "display", "1")
    buffers[prefix] = buf

    hooks['signal'] = wc.hook_signal("input_text_changed",
            "timeline_prompt_cb", "")

    if prefix is "__TIMELINE":
        tlid[prefix] = "timelined"
    else:
        tlid[prefix] = prefix
Exemplo n.º 8
0
def add_hooks():
  global hooks
  hooked_servers = OPTIONS['hooks.explicit_servers'].split(',')
  for server_name in hooked_servers:
    signal = "%s,irc_in2_join" % server_name
    # weechat.prnt('', "Adding hook on %s" % signal)
    hook = weechat.hook_signal(signal, "on_join_scan_cb", "")
    hooks.add(hook)
Exemplo n.º 9
0
def insert_word(buffer, word, prev_word):
    input_line = w.buffer_get_string(buffer, 'input')
    input_pos = w.buffer_get_integer(buffer, 'input_pos')

    strip_len = len(prev_word)
    left = input_line[0:input_pos - strip_len]
    new_pos = input_pos + len(word) - strip_len
    right = input_line[input_pos:]
    result = left + word + right

    # If we don't deactivate the hook temporarily it is triggered
    global hooks
    map(w.unhook, hooks)
    w.buffer_set(buffer, 'input', result)
    w.buffer_set(buffer, 'input_pos', str(new_pos))
    hooks = (w.hook_signal("input_text_*", "finish_hook", ""),
             w.hook_signal("*_switch", "finish_hook", ""))
Exemplo n.º 10
0
def apply_config():
	# Unhook all signals and hook the new ones.
	for hook in hooks:
		weechat.unhook(hook)
	for signal in config.signals:
		hooks.append(weechat.hook_signal(signal, 'on_signal', ''))

	if config.sort_on_config:
		do_sort()
Exemplo n.º 11
0
def apply_config():
	# Unhook all signals and hook the new ones.
	for hook in hooks:
		weechat.unhook(hook)
	for signal in config.signals:
		hooks.append(weechat.hook_signal(signal, 'on_signal', ''))

	if config.sort_on_config:
		debug('Sorting because configuration changed.')
		do_sort()
Exemplo n.º 12
0
def hook_all(server):
    global HOOKS

    notice = server + '.notice'
    modifier = server + '.modifier'

    if notice not in HOOKS:
        HOOKS[notice]   = weechat.hook_signal("%s,irc_raw_in_notice" % server, "auth_success_cb", server)
    if modifier not in HOOKS:
        HOOKS[modifier] = weechat.hook_modifier("irc_out_privmsg", "totp_login_modifier_cb", "")
Exemplo n.º 13
0
def imap_cmd(data, buffer, args):
    ''' Callback for /imap command '''

    global active_folder_line, active_message_line, active_folder_name, active_message_uid

    if not args:
        buffer_create()
        #print_messages()
        w.bar_item_update('imap_folders')
        w.command('', '/bar show imap')
        w.hook_signal('buffer_switch', 'toggle_imap_bar', '')
        w.command('', '/buffer %s' %SCRIPT_COMMAND)
    if args == 'folder_down':
        active_folder_line += 1
        w.bar_item_update('imap_folders')
    if args == 'folder_up':
        if active_folder_line > 0:
            active_folder_line -= 1
            w.bar_item_update('imap_folders')
    if args == 'message_down':
        active_message_line += 1
        print_messages(active_folder_name)
    if args == 'message_up':
        if active_message_line > 0:
            active_message_line -= 1
            print_messages(active_folder_name)
    if args == 'message_mark_read':
        if active_message_uid:
            imap = Imap()
            imap.mark_read(active_folder_name, active_message_uid)
            imap.logout()
            w.bar_item_update('imap_folders')
    if args == 'message_delete':
        if active_message_uid:
            imap = Imap()
            imap.delete(active_folder_name, active_message_uid)
            imap.logout()
            w.bar_item_update('imap_folders')
    if args == 'message_fetch':
        if active_message_uid:
            print_message()
    return w.WEECHAT_RC_OK
Exemplo n.º 14
0
def install_hooks():
    global HOOK,OPTIONS

    # Should never happen
    if any([HOOK[k] != '' for k in HOOK]):
        return

    if not OPTIONS['delay'] or not OPTIONS['timeout']:
        return

    debug_print("Installing timer with delay %s seconds" % OPTIONS['delay'])
    HOOK['timer'] = weechat.hook_timer(int(OPTIONS['delay']) * 1000, 0, 0, 'check_nicks', '')
    HOOK['redirect'] = weechat.hook_hsignal('irc_redirection_%s_ison' % SCRIPT_NAME, 'redirect_isonhandler', '' )
    HOOK['quit'] = weechat.hook_signal('*,irc_raw_in_quit', 'check_quit', '')
    HOOK['nick'] = weechat.hook_signal('*,irc_raw_in_nick', 'check_nick_change', '')

    for k in HOOK:
        if HOOK[k] == 0:
            weechat.prnt('', "%s: can't enable %s, hook_timer() failed" %
                         (weechat.prefix('error'), SCRIPT_NAME))
Exemplo n.º 15
0
def enable_logging():
    """ Connect to MongoDB and add our IRC hooks """

    global mongo_collection, logging_hooks

    # Attempt to connect to our configured MongoDB instance
    # TODO -- assert that mongo connection worked
    mongo_host = weechat.config_get_plugin('mongo_host')
    mongo_port = weechat.config_get_plugin('mongo_port')
    mongo_database_name = weechat.config_get_plugin('mongo_database')
    mongo_collection_name = weechat.config_get_plugin('mongo_collection')
    mongo_user = weechat.config_get_plugin('mongo_user')
    mongo_password = weechat.config_get_plugin('mongo_password')

    mongoclient_arguments = {
        'connectTimeoutMS': 1
    }

    if len(mongo_host) > 0:
        mongoclient_arguments['host'] = mongo_host

    if len(mongo_port) > 0:
        mongoclient_arguments['port'] = int(mongo_port)

    mongo_client = pymongo.MongoClient(**mongoclient_arguments)
    mongo_database = mongo_client[mongo_database_name]
    mongo_collection = mongo_database[mongo_collection_name]

    # Authenticate if we have a configured user
    if len(mongo_user) > 0:
        try:
            mongo_database.authenticate(mongo_user, password=mongo_password)
        except pymongo.errors.OperationFailure as e:
            weechat.prnt('', 'Couldn\'t authenticate to MongoDB DB {}: {}'.format(mongo_database_name, e.details['errmsg']))
            weechat.config_set_plugin('enabled', DISABLED)
            return

    # Set up our logging hooks
    hooks = [
        'irc_raw_in2_privmsg',
        'irc_raw_in2_join',
        'irc_raw_in2_part',
        'irc_raw_in2_mode',
        'irc_raw_in2_quit',
        'irc_out1_privmsg',
        'irc_out1_join',
        'irc_out1_part',
        'irc_out1_mode',
        'irc_out1_quit'
    ]

    for hook in hooks:
        logging_hooks.append(weechat.hook_signal('*,{}'.format(hook), 'log_to_mongo', ''))
Exemplo n.º 16
0
def main():
    '''Sets up WeeChat notifications.'''
    # Initialize options.
    for option, value in SETTINGS.items():
        if not weechat.config_is_set_plugin(option):
            weechat.config_set_plugin(option, value)
    # Initialize.
    name = "WeeChat"
    icon = "/usr/share/pixmaps/weechat.xpm"
    notifications = [
        'Public',
        'Private',
        'Action',
        'Notice',
        'Invite',
        'Highlight',
        'Server',
        'Channel',
        'DCC',
        'WeeChat'
    ]
    STATE['icon'] = icon
    # Register hooks.
    weechat.hook_signal(
        'irc_server_connected',
        'cb_irc_server_connected',
        '')
    weechat.hook_signal(
        'irc_server_disconnected',
        'cb_irc_server_disconnected',
        '')
    weechat.hook_signal('upgrade_ended', 'cb_upgrade_ended', '')
    weechat.hook_print('', '', '', 1, 'cb_process_message', '')
    weechat.hook_timer(1000, 1, 65535, "cb_buffer_tick", "")
    pynotify.init(name)
Exemplo n.º 17
0
def main():
    '''Sets up WeeChat notifications.'''
    # Initialize options.
    for option, value in SETTINGS.items():
        if not weechat.config_is_set_plugin(option):
            weechat.config_set_plugin(option, value)
    # Initialize.
    notifications = [
        'Public',
        'Private',
        'Action',
        'Notice',
        'Invite',
        'Highlight',
        'Server',
        'Channel',
        'DCC',
        'WeeChat'
    ]
    # Register hooks.
    weechat.hook_signal(
        'irc_server_connected',
        'cb_irc_server_connected',
        '')
    weechat.hook_signal(
        'irc_server_disconnected',
        'cb_irc_server_disconnected',
        '')
    weechat.hook_signal('upgrade_ended', 'cb_upgrade_ended', '')
    weechat.hook_print('', '', '', 1, 'cb_process_message', '')
Exemplo n.º 18
0
def main():
    '''Sets up WeeChat Growl notifications.'''
    # Initialize options.
    for option, value in SETTINGS.items():
        if not weechat.config_is_set_plugin(option):
            weechat.config_set_plugin(option, value)
    # Initialize Growl.
    name = "WeeChat"
    hostname = weechat.config_get_plugin('hostname')
    password = weechat.config_get_plugin('password')
    icon_path = os.path.join(weechat.info_get("weechat_dir", ""),
            weechat.config_get_plugin('icon'))
    try:
        icon = open(icon_path, "rb").read()
    except IOError:
        weechat.prnt('',
                'Weechat-Growl: {0} could not be opened. '.format(icon_path) +
                'Please make sure it exists.')
        icon = None

    notifications = [
        'Public',
        'Private',
        'Action',
        'Notice',
        'Invite',
        'Highlight',
        'Server',
        'Channel',
        'DCC',
        'WeeChat'
    ]
    if len(hostname) == 0:
        hostname = ''
    if len(password) == 0:
        password = ''
    growl = GrowlNotifier(
        applicationName=name,
        hostname=hostname,
        password=password,
        notifications=notifications,
        applicationIcon=icon)
    try:
        growl.register()
    except Exception as error:
        weechat.prnt('', 'growl: {0}'.format(error))
    STATE['growl'] = growl
    STATE['icon'] = icon
    # Register hooks.
    weechat.hook_signal(
        'irc_server_connected',
        'cb_irc_server_connected',
        '')
    weechat.hook_signal(
        'irc_server_disconnected',
        'cb_irc_server_disconnected',
        '')
    weechat.hook_signal('upgrade_ended', 'cb_upgrade_ended', '')
    weechat.hook_print('', '', '', 1, 'cb_process_message', '')
Exemplo n.º 19
0
def jmh_set_hooks():
    # prototype: hook = weechat.hook_signal(signal, callback, callback_data)
    weechat.hook_signal('weechat_highlight', 'message_highlight', '')
    weechat.hook_signal('irc_pv', 'message_private_irc', '')
    weechat.hook_signal('weechat_pv', 'message_private_weechat', '')
    # prototype: hook = weechat.hook_print(buffer, tags, message, strip_colors,
    #   callback, callback_data)
    weechat.hook_print('', 'notify_message', '', 1, 'message_weechat_print', '')
Exemplo n.º 20
0
def on_config_changed(*args, **kwargs):
	''' Called whenever the configuration changes. '''
	config.reload()

	# Unhook all signals and hook the new ones.
	for hook in hooks:
		weechat.unhook(hook)
	for signal in config.signals:
		hooks.append(weechat.hook_signal(signal, 'on_buffers_changed', ''))

	if config.sort_on_config:
		on_buffers_changed()

	return weechat.WEECHAT_RC_OK
Exemplo n.º 21
0
def main():
    if not weechat.register('hipchat', 'Joakim Recht <*****@*****.**>', '1.0',
                            'MIT', 'Hipchat utilities',
                            '', ''):
        return

    rooms_set_default_settings()
    rooms_reset_stored_sort_order()
    get_token()

    weechat.hook_command(
        'hipchat', 'Hipchat utilities',
        '[rooms | autojoin | whois <user> | fullnames | nicks [<pattern>]]',
        'rooms: List rooms\nautojoin: List autojoin rooms\nwhois <user>: Get information '
        'about a specific user - either @mention or email\nfullnames: Force populate full '
        'names in nicklists in all channels\nnicks <pattern>: List users, optionally by pattern. '
        'Use * in pattern as wildcard match.\n',
        'rooms|autojoin|whois|fullnames|nicks', 'hipchat_cmd', '')
    weechat.hook_completion('hipchat_mentions', 'Mentions', 'complete_mention', '')

    if weechat.config_get_plugin('enable_fullnames') == 'on':
        nicklist_download()
    weechat.hook_signal('nicklist_nick_added', 'update_fullname_join', '')
    weechat.hook_signal('hipchat_nicks_downloaded', 'show_nicks_cb', '')
Exemplo n.º 22
0
def signal_irc_pv_opened(data, signal, signal_data):
    """Callback for signal 'irc_pv_opened'."""
    global irc_pv_hook
    if weechat.buffer_get_string(signal_data, 'plugin') == 'irc':
        nick = weechat.buffer_get_string(signal_data, 'localvar_channel')
        if weechat.info_get('irc_is_nick', nick) == '1':
            unhook_irc_pv()
            if weechat.config_get_plugin('self_query') == 'on':
                exec_command(signal_data, nick)
            else:
                # query open, wait for a msg to come (query was open by user) or if we send a msg out
                # (query was open by us)
                server = weechat.buffer_get_string(signal_data, 'localvar_server')
                irc_pv_hook = weechat.hook_signal('irc_pv', 'signal_irc_pv',
                                                  '%s,%s' % (signal_data, nick))
    return weechat.WEECHAT_RC_OK
Exemplo n.º 23
0
def join_cb(data, signal, signal_data):
    dict_in = {"message": signal_data}
    dict_out = weechat.info_get_hashtable("irc_message_parse", dict_in)
    channel = dict_out["channel"]
    if channel != options["channel"]:
        return weechat.WEECHAT_RC_OK

    server = signal.split(",")[0]
    nick = dict_out["nick"]
    me = weechat.info_get("irc_nick", server)
    if nick != me:
        return weechat.WEECHAT_RC_OK

    weechat.prnt(gribble_buffer, "Channel %s joined" % channel)
    hook_msg = weechat.hook_signal("*,irc_in2_PRIVMSG", "privmsg_cb", "")
    weechat.prnt(gribble_buffer, "Sent eauth to %s" % gribble_nick)
    privmsg(server, gribble_nick, "eauth %s" % ident_nick)

    return weechat.WEECHAT_RC_OK
Exemplo n.º 24
0
def main():
    '''Sets up WeeChat notifications.'''
    # Initialize options.
    for option, value in SETTINGS.items():
        if not weechat.config_is_set_plugin(option):
            weechat.config_set_plugin(option, value)
    # Initialize.
    icon = "/usr/share/pixmaps/weechat.xpm"
    STATE['icon'] = icon
    # Register hooks.
    weechat.hook_signal(
        'irc_server_connected',
        'cb_irc_server_connected',
        '')
    weechat.hook_signal(
        'irc_server_disconnected',
        'cb_irc_server_disconnected',
        '')
    weechat.hook_signal('upgrade_ended', 'cb_upgrade_ended', '')
    weechat.hook_print('', '', '', 1, 'cb_process_message', '')
Exemplo n.º 25
0
def main():
    """Sets up WeeChat Growl notifications."""
    # Initialize options.
    for option, value in SETTINGS.items():
        if not weechat.config_is_set_plugin(option):
            weechat.config_set_plugin(option, value)
    # Initialize Growl.
    name = "WeeChat"
    hostname = weechat.config_get_plugin("hostname")
    password = weechat.config_get_plugin("password")
    icon = "file://{0}".format(os.path.join(weechat.info_get("weechat_dir", ""), weechat.config_get_plugin("icon")))
    notifications = [
        "Public",
        "Private",
        "Action",
        "Notice",
        "Invite",
        "Highlight",
        "Server",
        "Channel",
        "DCC",
        "WeeChat",
    ]
    if len(hostname) == 0:
        hostname = ""
    if len(password) == 0:
        password = ""
    growl = GrowlNotifier(
        applicationName=name, hostname=hostname, password=password, notifications=notifications, applicationIcon=icon
    )
    try:
        growl.register()
    except Exception as error:
        weechat.prnt("", "growl: {0}".format(error))
    STATE["growl"] = growl
    STATE["icon"] = icon
    # Register hooks.
    weechat.hook_signal("irc_server_connected", "cb_irc_server_connected", "")
    weechat.hook_signal("irc_server_disconnected", "cb_irc_server_disconnected", "")
    weechat.hook_signal("upgrade_ended", "cb_upgrade_ended", "")
    weechat.hook_print("", "", "", 1, "cb_process_message", "")
Exemplo n.º 26
0
def main():
    """Sets up WeeChat notifications."""
    # Initialize options.
    for option, value in SETTINGS.items():
        if not weechat.config_is_set_plugin(option):
            weechat.config_set_plugin(option, value)
    # Initialize.
    notifications = [
        "Public",
        "Private",
        "Action",
        "Notice",
        "Invite",
        "Highlight",
        "Server",
        "Channel",
        "DCC",
        "WeeChat",
    ]
    # Register hooks.
    weechat.hook_signal("irc_server_connected", "cb_irc_server_connected", "")
    weechat.hook_signal("irc_server_disconnected", "cb_irc_server_disconnected", "")
    weechat.hook_signal("upgrade_ended", "cb_upgrade_ended", "")
    weechat.hook_print("", "", "", 1, "cb_process_message", "")
Exemplo n.º 27
0
                " add irc.freenode.#savannah highlight_words_add weechat\n"
                "  disable highlights from nick \"mike\" on freenode server, channel #weechat (requires WeeChat >= 0.3.4):\n"
                "    /" + SCRIPT_COMMAND +
                " add irc.freenode.#weechat hotlist_max_level_nicks_add mike:2\n"
                "  disable hotlist changes for nick \"bot\" on freenode server (all channels) (requires WeeChat >= 0.3.4):\n"
                "    /" + SCRIPT_COMMAND +
                " add irc.freenode.* hotlist_max_level_nicks_add bot:-1",
                "add %(buffers_plugins_names)|%(buffer_autoset_current_buffer) %(buffer_properties_set)"
                " || del %(buffer_autoset_options)", "bas_cmd", "")
            weechat.hook_completion("buffer_autoset_current_buffer",
                                    "current buffer name for buffer_autoset",
                                    "bas_completion_current_buffer_cb", "")
            weechat.hook_completion("buffer_autoset_options",
                                    "list of options for buffer_autoset",
                                    "bas_completion_options_cb", "")
            weechat.hook_signal("buffer_opened", "bas_signal_buffer_opened_cb",
                                "")

            # core buffer is already open on script startup, check manually!
            bas_signal_buffer_opened_cb("", "", weechat.buffer_search_main())
# ==================================[ end ]===================================


def bas_unload_script():
    """ Function called when script is unloaded. """
    global bas_config_file

    if bas_config_file:
        bas_config_write()
    return weechat.WEECHAT_RC_OK
Exemplo n.º 28
0
def add_hook(signal, item):
    global hooks
    # signal already exists?
    if signal in hooks:
        return
    hooks[item] = weechat.hook_signal(signal, "bar_item_update", "")
Exemplo n.º 29
0
        buf = weechat.current_buffer()
    if os.path.exists(weechat_dir + "/cryptkey." +
                      weechat.buffer_get_string(buf, "short_name")):
        return weechat.config_get_plugin("statusbar_indicator")
    else:
        return ""


# for subprocess.Popen call
PIPE = -1

# register plugin
if weechat.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION, SCRIPT_LICENSE,
                    SCRIPT_DESC, "", "UTF-8"):
    weechat_dir = weechat.info_get("weechat_data_dir", "") \
        or weechat.info_get("weechat_dir", "")
    version = weechat.info_get("version_number", "") or 0
    if int(version) < 0x00030000:
        weechat.prnt(
            "", "%s%s: WeeChat 0.3.0 is required for this script." %
            (weechat.prefix("error"), SCRIPT_NAME))
    else:
        weechat.bar_item_new('encryption', 'encryption_statusbar', '')
        for option, default_value in script_options.iteritems():
            if not weechat.config_is_set_plugin(option):
                weechat.config_set_plugin(option, default_value)
        # register the modifiers
        weechat.hook_modifier("irc_in_privmsg", "decrypt", "")
        weechat.hook_modifier("irc_out_privmsg", "encrypt", "")
        weechat.hook_signal("buffer_switch", "update_encryption_status", "")
Exemplo n.º 30
0
    if match:
        channel = match.group(1)
        channel_block(server, channel)

    return weechat.WEECHAT_RC_OK


def freenode_cb(data, signal, signal_data):
    server = signal.split(",")[0]
    parsed = parse_message(signal_data)

    channel_block(server, parsed["args"][2])

    return weechat.WEECHAT_RC_OK


if __name__ == "__main__" and IMPORT_OK:
    if weechat.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION,
                        SCRIPT_LICENSE, SCRIPT_DESC, "", ""):
        weechat.hook_signal("*,irc_out1_nick", "nick_out_cb", "")
        weechat.hook_signal("*,irc_in_nick", "nick_in_cb", "")
        weechat.hook_signal("*,irc_in_447", "unreal_cb", "")
        weechat.hook_signal("*,irc_in_435", "freenode_cb", "")

        for option, value in SETTINGS.items():
            if not weechat.config_is_set_plugin(option):
                weechat.config_set_plugin(option, value[0])

            weechat.config_set_desc_plugin(
                option, "%s (default: \"%s\")" % (value[1], value[0]))
Exemplo n.º 31
0
weechat.register("tmuxnotify", "lukaszkorecki", "0.1", "GPL",
                 "tmuxnotify: weechat notifications in tmux", "", "")

# script options
settings = {
    "show_hilights": "on",
    "show_priv_msg": "on",
}

for option, default_value in settings.items():
    if weechat.config_get_plugin(option) == "":
        weechat.config_set_plugin(option, default_value)

# Hook privmsg/hilights
weechat.hook_signal("weechat_pv", "notify_show_priv", "")
weechat.hook_signal("weechat_highlight", "notify_show_hi", "")


# Functions
def notify_show_hi(data, signal, message):
    """Sends highlight message to be printed on notification"""
    if weechat.config_get_plugin('show_hilights') == "on":
        show_notification("IRC Mention")
    return weechat.WEECHAT_RC_OK


def notify_show_priv(data, signal, message):
    """Sends private message to be printed on notification"""
    if weechat.config_get_plugin('show_priv_msg') == "on":
        show_notification("IRC Message")
Exemplo n.º 32
0
Arquivo: hank.py Projeto: emilypi/hank
    fmt = udata['fmt']
    if rci >= 0:
        weechat.prnt("", "hankbot: rc=%d command=%s stderr=%s stdout=%s" % \
            (rci, command, curl_stderr, curl_stdout))
        if rci == 0:
            curl_stdout = curl_stdout.strip()
            curl_stdout = ''.join([i if ord(i) < 128 else '?' for i in curl_stdout])
            if curl_stdout != "":
                say(udata['srv'], udata['chn'], fmt % (curl_stdout))
        else:
            say(udata['srv'], udata['chn'], ':(')
        curl_stdout = ""
        curl_stderr = ""
    return weechat.WEECHAT_RC_OK

weechat.hook_signal("*,irc_in2_privmsg", "msg_cb", "");

NOUN_LIST = [
   "achiever",
   "acoustics",
   "act",
   "activity",
   "actor",
   "addition",
   "adjustment",
   "advertisement",
   "advice",
   "aftermath",
   "afternoon",
   "afterthought",
   "agreement",
Exemplo n.º 33
0
    splitted = type_data.split(',')
    pointer = splitted[0]
    nick = ','.join(splitted[1:])
    if pointer not in colored_nicks:
        colored_nicks[pointer] = {}
    my_nick = weechat.buffer_get_string(pointer, 'localvar_nick')
    nick_color = colorize_nick_color(nick, my_nick)
    colored_nicks[pointer][nick] = nick_color
    return weechat.WEECHAT_RC_OK


def remove_nick(data, signal, type_data):
    global colored_nicks
    splitted = type_data.split(',')
    pointer = splitted[0]
    nick = ','.join(splitted[1:])
    if pointer in colored_nicks and nick in colored_nicks[pointer]:
        del colored_nicks[pointer][nick]
    return weechat.WEECHAT_RC_OK


if weechat.register('colorize_nicks', 'acidvegas', '1.0', 'ISC',
                    'colorize nicks', '', ''):
    populate_nicks()
    weechat.hook_signal('nicklist_nick_added', 'add_nick', '')
    weechat.hook_signal('nicklist_nick_removed', 'remove_nick', '')
    weechat.hook_modifier('weechat_print', 'colorize_cb', '')
    weechat.hook_config('weechat.color.chat_nick_colors', 'populate_nicks', '')
    weechat.hook_config('weechat.look.nick_color_hash', 'populate_nicks', '')
    weechat.hook_modifier('colorize_nicks', 'colorize_cb', '')
    weechat.hook_modifier('250|input_text_display', 'colorize_input_cb', '')
Exemplo n.º 34
0
# 2009-02-08, FlashCode <*****@*****.**>:
#     version 0.1: initial release
#

import weechat

SCRIPT_NAME    = "whois_on_query"
SCRIPT_AUTHOR  = "FlashCode <*****@*****.**>"
SCRIPT_VERSION = "0.2"
SCRIPT_LICENSE = "GPL3"
SCRIPT_DESC    = "Whois on query"

# script options
settings = {
    "command": "/whois $nick $nick",
}

weechat.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION, SCRIPT_LICENSE,
                 SCRIPT_DESC, "", "")
weechat.hook_signal("irc_pv_opened", "signal_irc_pv_opened", "")
for option, default_value in settings.iteritems():
    if weechat.config_get_plugin(option) == "":
        weechat.config_set_plugin(option, default_value)

def signal_irc_pv_opened(data, signal, signal_data):
    if weechat.buffer_get_string(signal_data, "plugin") == "irc":
        channel = weechat.buffer_get_string(signal_data, "localvar_channel")
        if weechat.info_get("irc_is_channel", channel) != "1":
            weechat.command(signal_data, weechat.config_get_plugin("command").replace("$nick", channel))
    return weechat.WEECHAT_RC_OK
Exemplo n.º 35
0
AUTHOR="Kolter"

DELIMITER="|@|"

import_ok = True
try:
    import weechat
except:
    print "Script must be run under weechat. http://www.weechat.org"
    import_ok = False

import re

weechat.register (NAME, AUTHOR, VERSION, "GPL2", "Auto authentification while changing nick", "", "")

weechat.hook_signal("*,irc_in2_notice", "auth_notice_check", "")
weechat.hook_command(
    "autoauth",
    "Auto authentification while changing nick",
    "{ add $nick $pass [$server=current] | del $nick [$server=current] | list | cmd [$command [$server=current]] | ns [$Nick[!username[@host]]] [$server=current] }",
    "  add : add authorization for $nick with password $pass for $server\n"
    "  del : del authorization for $nick for $server\n"
    " list : list all authorization settings\n"
    "  cmd : command(s) (separated by '|') to run when identified for $server\n"
    "         %n will be replaced by current nick in each command\n"
    "   ns : set NickServ mask (or part of mask) for $server, the NickServ nick is mandatory",
    "add|del|list|cmd %- %S %S",
    "auth_command",
    ""
    )
Exemplo n.º 36
0
# script options
settings = {
    "autosave": "off",
}

if w.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION, SCRIPT_LICENSE,
              SCRIPT_DESC, "", ""):

    w.hook_command(
        SCRIPT_COMMAND, SCRIPT_DESC, "[--run]",
        "   --run: actually run the commands instead of displaying\n", "--run",
        "autojoin_cb", "")

    #w.hook_signal('*,irc_in2_join', 'autosave_channels_on_activity', '')
    #w.hook_signal('*,irc_in2_part', 'autosave_channels_on_activity', '')
    w.hook_signal('quit', 'autosave_channels_on_quit', '')

# Init everything
for option, default_value in settings.items():
    if w.config_get_plugin(option) == "":
        w.config_set_plugin(option, default_value)


def autosave_channels_on_quit(signal, callback, callback_data):
    ''' Autojoin current channels '''
    if w.config_get_plugin(option) != "on":
        return w.WEECHAT_RC_OK

    items = find_channels()

    # print/execute commands
Exemplo n.º 37
0
    if "/" in username:
        username = username.split("/")[0]
    add_server = [
        "/server",
        "add",
        net_name,
        addr,
        "-temp",
        "-ssl",
        "-username="******"/" + net_name,
    ]

    for k in ["password", "sasl_mechanism", "sasl_username", "sasl_password"]:
        v = weechat.config_string(
            weechat.config_get("irc.server." + server + "." + k))
        add_server.append("-" + k + "=" + v)

    weechat.command(weechat.buffer_search("core", "weechat"),
                    " ".join(add_server))
    weechat.command(weechat.buffer_search("core", "weechat"),
                    "/connect " + net_name)

    return weechat.WEECHAT_RC_OK_EAT


weechat.hook_signal("*,irc_raw_in_376", "handle_isupport_end_msg",
                    "")  # RPL_ENDOFMOTD
weechat.hook_signal("*,irc_raw_in_422", "handle_isupport_end_msg",
                    "")  # ERR_NOMOTD
weechat.hook_signal("*,irc_raw_in_bouncer", "handle_bouncer_msg", "")
Exemplo n.º 38
0
            " remove: delete one-time password configuration for a server\n" +
            " enable: re-enable one-time password authentication for a server\n"
            +
            "disable: disable one-time password authentiction without removing the seed for a server\n\n"
            + "Examples:\n" + "  /uotp otp\n" + "  /uotp otp freenode\n" +
            "  /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(
Exemplo n.º 39
0
if import_ok and weechat.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION, SCRIPT_LICENSE,
        SCRIPT_DESC, '', ''):

    # colors
    color_delimiter = weechat.color('chat_delimiters')
    color_chat_nick = weechat.color('chat_nick')
    color_reset     = weechat.color('reset')

    # pretty [SCRIPT_NAME]
    script_nick = '%s[%s%s%s]%s' % (color_delimiter,
                                    color_chat_nick,
                                    SCRIPT_NAME,
                                    color_delimiter,
                                    color_reset)

    weechat.hook_signal('*,irc_in2_311', 'whois_cb', '') # /whois
    weechat.hook_signal('*,irc_in2_314', 'whois_cb', '') # /whowas
    weechat.hook_command('country', cmd_country.__doc__, 'update | (nick|ip|uri)',
            "       update: Downloads/updates ip database with country codes.\n"
            "nick, ip, uri: Gets country and local time for a given ip, domain or nick.",
            'update||%(nick)', 'cmd_country', '')

    # settings
    for opt, val in settings.items():
        if not weechat.config_is_set_plugin(opt):
            weechat.config_set_plugin(opt, val)

    if not check_database():
        say("IP database not found. You must download a database with '/country update' before "
                "using this script.")
Exemplo n.º 40
0

if __name__ == "__main__" and IMPORT_OK:
    if weechat.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION,
                        SCRIPT_LICENSE, SCRIPT_DESC, "", ""):
        weechat.hook_hsignal("10000|buffer_open_full_name",
                             "buffer_open_full_name_opened_cb", "")
        weechat.hook_hsignal("0|buffer_open_full_name",
                             "buffer_open_full_name_unhandled_cb", "")

        weechat.hook_hsignal("500|buffer_open_full_name",
                             "buffer_open_full_name_table_cb", "")

        weechat.hook_hsignal("500|buffer_open_full_name",
                             "buffer_open_full_name_irc_cb", "")
        weechat.hook_signal("irc_server_connected", "irc_server_connected_cb",
                            "")

        weechat.hook_command(
            SCRIPT_COMMAND, SCRIPT_DESC, """closed [-noswitch|-list]
  || [-noswitch] <full name>""",
            """      closed: open most recently closed buffer
closed -list: list most recently closed buffers
   -noswitch: try not to switch to new buffer

Without subcommand, this command opens a buffer with given full name.

Option "{prefix}.max_closed" specifies the number of most recently closed buffers that are remembered.

If option "{prefix}.layout_apply" is on and "/layout apply" is executed, closed buffers in the layout are opened."""
            .format(prefix="plugins.var.python.{}".format(SCRIPT_NAME)),
            """closed -noswitch|-list %-
Exemplo n.º 41
0
    weechat.hook_modifier('irc_in_privmsg', 'message_in_cb', '')
    weechat.hook_modifier('irc_out_privmsg', 'message_out_cb', '')

    weechat.hook_command(
        SCRIPT_NAME, SCRIPT_HELP, 'start [NICK SERVER] || '
        'finish [NICK SERVER] || '
        'smp ask NICK SERVER SECRET [QUESTION] || '
        'smp respond NICK SERVER SECRET || '
        'smp abort NICK SERVER || '
        'trust [NICK SERVER] || '
        'distrust [NICK SERVER] || '
        'log [on|off] || '
        'policy [POLICY on|off]', '', 'start %(nick) %(irc_servers) %-||'
        'finish %(nick) %(irc_servers) %-||'
        'smp ask|respond %(nick) %(irc_servers) %-||'
        'smp abort %(nick) %(irc_servers) %-||'
        'trust %(nick) %(irc_servers) %-||'
        'distrust %(nick) %(irc_servers) %-||'
        'log on|off %-||'
        'policy %(otr_policy) on|off %-||', 'command_cb', '')

    weechat.hook_completion('otr_policy', 'OTR policies',
                            'policy_completion_cb', '')

    weechat.hook_config('logger.level.irc.*', 'logger_level_update_cb', '')

    weechat.hook_signal('buffer_switch', 'buffer_switch_cb', '')

    OTR_STATUSBAR = weechat.bar_item_new(SCRIPT_NAME, 'otr_statusbar_cb', '')
    weechat.bar_item_update(SCRIPT_NAME)
Exemplo n.º 42
0
    if weechat.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION, SCRIPT_LICENSE, SCRIPT_DESC, '', ''):
        version = weechat.info_get('version_number', '') or 0
        if int(version) >= 0x00030700:
            weechat.hook_command(SCRIPT_NAME,SCRIPT_DESC,
            'save',
            'save : manual saving of the query list\n',
            '',
            'hook_command_cb', '')

            stored_query_buffers_per_server = get_stored_list_of_query_buffers()
            for (server_name, channels) in get_current_query_buffers().items():
                # Reopen the buffers for the channels in the servers we already have open:
                open_stored_query_buffers_for_server(server_name)

                stored_query_buffers_per_server.setdefault(server_name, set([]))
                debug_print("Already have %s channels for server %s: %s" % (len(stored_query_buffers_per_server[server_name]), server_name, ','.join(stored_query_buffers_per_server[server_name])))
                debug_print("Adding: %s" % channels)
                stored_query_buffers_per_server[server_name].update(channels)
                debug_print("Now have %s channels for server %s: %s" % (len(stored_query_buffers_per_server[server_name]), server_name, ','.join(stored_query_buffers_per_server[server_name])))
            save_stored_query_buffers_to_file()
            weechat.hook_signal('quit', 'quit_signal_cb', '')
#            weechat.hook_signal('relay_client_disconnected', 'quit_signal_cb', '')
#            weechat.hook_signal('relay_client_connected', 'irc_server_connected_signal_cb', '')
            weechat.hook_signal('irc_server_opened', 'irc_server_opened_cb', '')
            weechat.hook_signal('irc_server_connected', 'irc_server_connected_signal_cb','')
            weechat.hook_signal('irc_server_disconnected', 'remove_server_from_servers_closing_cb', '')

            # TODO: make these triggers optional?
            weechat.hook_signal('irc_pv_opened', 'irc_pv_opened_cb', '')
            weechat.hook_signal('buffer_closing', 'buffer_closing_signal_cb', '')
Exemplo n.º 43
0
                        "/whois " + nick + " " + nick)

    return weechat.WEECHAT_RC_OK


def whois_data_minbif(data, signal, signal_data):
    """Get data from irc_in_311 and parse name from there. """
    if "facebook" in signal_data:
        realname = signal_data[signal_data.index(" :"):].strip(" :")
        nick = signal_data[signal_data.index("_"):signal_data.
                           index(" ", signal_data.index("_"))]
        weechat.prnt("", str(nicksToRename))

    if nick in nicksToRename:
        nicksToRename.remove(nick)
        ircname = re.sub("[^A-Za-z0-9]", "", realname)[:24]
        weechat.prnt("", ircname)
        if ircname != nick:
            weechat.command(weechat.buffer_search("irc", myBuffer),
                            "rename %s %s" % (nick, ircname))

    return weechat.WEECHAT_RC_OK


weechat.hook_signal(
    myServer + ",irc_in_join", "message_join_minbif",
    "")  #calls message_join_minbif when someone joins the channel
weechat.hook_signal(
    myServer + ",irc_in_311", "whois_data_minbif",
    "")  #calls the facebook name reassigner when /whois is called.
Exemplo n.º 44
0
    weechat.hook_modifier('irc_in_privmsg', 'ircrypt_decrypt_hook', '')
    weechat.hook_modifier('irc_out_privmsg', 'ircrypt_encrypt_hook', '')

    weechat.hook_command(
        'ircrypt',
        'Commands to manage IRCrypt options and execute IRCrypt commands',
        '[list]'
        '| set-key [-server <server>] <target> <key> '
        '| remove-key [-server <server>] <target> '
        '| set-cipher [-server <server>] <target> <cipher> '
        '| remove-cipher [-server <server>] <target> '
        '| plain [-server <server>] [-channel <channel>] <message>',
        SCRIPT_HELP_TEXT,
        'list || set-key %(irc_channel)|%(nicks)|-server %(irc_servers) %- '
        '|| remove-key %(irc_channel)|%(nicks)|-server %(irc_servers) %- '
        '|| set-cipher %(irc_channel)|-server %(irc_servers) %- '
        '|| remove-cipher |%(irc_channel)|-server %(irc_servers) %- '
        '|| plain |-channel %(irc_channel)|-server %(irc_servers) %-',
        'ircrypt_command', '')
    weechat.bar_item_new('ircrypt', 'ircrypt_encryption_statusbar', '')
    weechat.hook_signal('ircrypt_buffer_opened', 'update_encryption_status',
                        '')


def ircrypt_unload_script():
    '''Hook to ensure the configuration is properly written to disk when the
	script is unloaded.
	'''
    ircrypt_config_write()
    return weechat.WEECHAT_RC_OK
Exemplo n.º 45
0
    # Set up script options.
    for option, value in vimode_settings.items():
        if weechat.config_is_set_plugin(option):
            vimode_settings[option] = weechat.config_get_plugin(option)
        else:
            weechat.config_set_plugin(option, value[0])
            vimode_settings[option] = value[0]
        weechat.config_set_desc_plugin(
            option, "%s (default: \"%s\")" % (value[1], value[0]))
    # Warn the user about possible problems if necessary.
    if not weechat.config_string_to_boolean(vimode_settings['no_warn']):
        check_warnings()
    # Create bar items and setup hooks.
    weechat.bar_item_new("mode_indicator", "cb_mode_indicator", '')
    weechat.bar_item_new("cmd_text", "cb_cmd_text", '')
    weechat.bar_item_new("vi_buffer", "cb_vi_buffer", '')
    vi_cmd = weechat.bar_new("vi_cmd", "off", "0", "root", '', "bottom",
                             "vertical", "vertical", "0", "0", "default",
                             "default", "default", "0", "cmd_text")
    weechat.hook_config('plugins.var.python.%s.*' % SCRIPT_NAME, 'cb_config',
                        '')
    weechat.hook_signal("key_pressed", "cb_key_pressed", '')
    weechat.hook_signal("key_combo_default", "cb_key_combo_default", '')
    weechat.hook_command(
        "vimode", SCRIPT_DESC, "[help | bind_keys [--list]]",
        "     help: show help\n"
        "bind_keys: unbind problematic keys, and bind"
        " recommended keys to use in WeeChat\n"
        "          --list: only list changes", "help || bind_keys |--list",
        "cb_vimode_cmd", '')
Exemplo n.º 46
0
    if not w.info_get("irc_is_channel", channel):
        w.prnt(buffer, "error: Active buffer does not appear to be a channel.")
        return w.WEECHAT_RC_ERROR

    server = w.buffer_get_string(buffer, 'localvar_server')
    target = w.buffer_search("irc", f"{server}.{channel}")
    masks = list(filter(bool, args.split(" ")))
    if masks:
        casemap = _get_casemap(server)
        unique_masks = _unique_masks(casemap, masks)
        _match_for_buffer(False, casemap, target, server, channel,
                          unique_masks)

    return w.WEECHAT_RC_OK


SETTINGS = {
    "whitelist":
    ["", "CSV servers and buffer names to enable mask matching on"]
}

if import_ok and w.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION,
                            SCRIPT_LICENSE, SCRIPT_DESC, "", ""):
    for name, (default, description) in SETTINGS.items():
        if not w.config_is_set_plugin(name):
            w.config_set_plugin(name, default)
            w.config_set_desc_plugin(name, description)

    w.hook_signal("*,irc_in_MODE", "on_channel_mode", "")
    w.hook_command("mm2", "maskmatch2", "", "", "", "on_command", "")
Exemplo n.º 47
0
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', '')
Exemplo n.º 48
0
    color_peak = weechat.color('green')
    color_low = weechat.color('red')
    color_avg = weechat.color('brown')
    color_bold = weechat.color('white')

    # pretty [chanop]
    script_nick = '%s[%s%s%s]%s' % (color_delimiter, color_chat_nick,
                                    SCRIPT_NAME, color_delimiter, color_reset)

    for opt, val in settings.iteritems():
        if not weechat.config_is_set_plugin(opt):
            weechat.config_set_plugin(opt, val)

    script_load()

    weechat.hook_signal('*,irc_in2_join', 'join_cb', '')
    weechat.hook_signal('*,irc_in2_part', 'join_cb', '')
    weechat.hook_signal('*,irc_in2_quit', 'quit_cb', '')

    weechat.hook_command(
        'chanstat',
        "Display channel's statistics.",
        '[--save | --load]',
        "Displays channel peak, lowest and average users for current channel.\n"
        "  --save: forces saving the stats database.\n"
        "  --load: forces loading the stats database (Overwriting actual values).\n",
        #" --print: sends /chanstat output to the current channel.",
        '--save|--load',
        'chanstat_cmd',
        '')
Exemplo n.º 49
0
def my_config_cb(data, option, value):
    global options

    for boolean_option in boolean_options:
        if option.endswith(boolean_option):
            if value in booleans.keys():
                options[boolean_option] = booleans[w.config_get_plugin(
                    boolean_option)]
            else:
                w.prnt(
                    '',
                    'Error: "%s" is not a boolean, please use "on" or "off"' %
                    w.config_get_plugin(boolean_option))
                w.config_set_plugin(
                    boolean_option,
                    invertdict(booleans)[options[boolean_option]])
    write_file()
    return w.WEECHAT_RC_OK


for option in settings.keys():
    w.hook_config("plugins.var.python.%s.%s" % (name, option), "my_config_cb",
                  "")

###  HOOKS  ###

w.hook_command("hl2file_clear", "", "", "", "", "clear_file_cb", "")
w.hook_signal("buffer_switch", "buffer_switch_cb", "")
w.hook_signal("window_switch", "buffer_switch_cb", "")
w.hook_print("", "", "", 1, "my_print_cb", "")
Exemplo n.º 50
0
    return weechat.WEECHAT_RC_OK


def whois_data_bitlbee(data, signal, signal_data):
    nick = signal_data.split()[3]
    realname = signal_data[signal_data.rindex(':') + 1:]

    if nick in nicksToRename:
        nicksToRename.remove(nick)

        ircname = re.sub("[^A-Za-z0-9]", "", realname)[:24]
        if ircname != nick:
            weechat.command(
                weechat.buffer_search("irc", bitlbeeBuffer),
                "/msg %s rename %s %s" % (bitlbeeChannel, nick, ircname))
            weechat.command(weechat.buffer_search("irc", bitlbeeBuffer),
                            "/msg %s save" % (bitlbeeChannel))

    return weechat.WEECHAT_RC_OK


if mode == "minbif":
    weechat.hook_signal(minbifServer + ",irc_in_join", "message_join_minbif",
                        "")
    weechat.hook_signal(minbifServer + ",irc_in_320", "whois_data_minbif", "")
if mode == "bitlbee":
    weechat.hook_signal(bitlbeeServer + ",irc_in_join", "message_join_bitlbee",
                        "")
    weechat.hook_signal(bitlbeeServer + ",irc_in_311", "whois_data_bitlbee",
                        "")
Exemplo n.º 51
0
            'buffer_number': buffer_number,
            'low_messages': low_messages,
            'channel_messages': channel_messages,
            'private_messages': private_messages,
            'highlight_messages': highlight_messages,
            0: low_messages,
            1: channel_messages,
            2: private_messages,
            3: highlight_messages,
            'short_name': short_name
        })

    weechat.infolist_free(hotlist)

    write_file({'hotlist': data})

    return weechat.WEECHAT_RC_OK


if __name__ == '__main__':
    if weechat.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION,
                        SCRIPT_LICENSE, SCRIPT_DESC, '', ''):

        for opt, val in SETTINGS.iteritems():
            if not weechat.config_is_set_plugin(opt):
                weechat.config_set_plugin(opt, val)

        weechat.hook_signal('hotlist_changed', 'hotlist_changed', '')

# vim:set shiftwidth=4 tabstop=4 softtabstop=4 expandtab textwidth=80:
Exemplo n.º 52
0
    if int(num_relays) == 0:
        set_away(False)

    num_relays = weechat.info_get('relay_client_count', 'connected')
    return weechat.WEECHAT_RC_OK

def relay_disconnected(data, signal, signal_data):
    global num_relays

    if DEBUG():
        weechat.prnt('', 'DETACH_AWAY: last #relays: ' + str(num_relays))

    if int(num_relays) > 0:
        set_away(True)

    num_relays = weechat.info_get('relay_client_count', 'connected')
    return weechat.WEECHAT_RC_OK

# register plugin
weechat.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION, SCRIPT_LICENSE, SCRIPT_DESC, '', '')

# register for relay status
weechat.hook_signal('relay_client_connected', 'relay_connected', '')
weechat.hook_signal('relay_client_disconnected', 'relay_disconnected', '')

# register configuration defaults
for option, value in SETTINGS.items():
    if not weechat.config_is_set_plugin(option):
        weechat.config_set_plugin(option, value[0])
    weechat.config_set_desc_plugin(option, '%s (default: "%s")' % (value[1], value[0]))
Exemplo n.º 53
0
    # signal is for example: "freenode,irc_in2_join"
    # signal_data is IRC message, for example: ":nick!user@host JOIN :#channel"
    server = signal.split(",")[0]
    msg = weechat.info_get_hashtable("irc_message_parse",
                                     {"message": signal_data})
    buffer = weechat.info_get("irc_buffer", "%s,%s" % (server, msg["channel"]))
    if buffer:
        weechat.prnt(
            buffer, "%s (%s) has joined this channel jsfh sdjskjdf sf!" %
            (msg["nick"], msg["host"]))
    return weechat.WEECHAT_RC_OK


# it is useful here to use "*" as server, to catch JOIN messages on all IRC
# servers
weechat.hook_signal("*,irc_in2_join", "join_cb", "")

joinchan = "#clingclang"

connectme()

weechat.prnt("", "Hello, from python script! This should be loca only!")

#make a buffer (just a text space)
buffer = weechat.buffer_new("mybuffer", "buffer_input_cb", "",
                            "buffer_close_cb", "")
weechat.buffer_set(buffer, "title", "This is title for my buffer.")
weechat.buffer_set(buffer, "localvar_set_no_log", "1")

weechat.command(buffer,
                "hello")  #command is a literal IRC command; msg, join, whever
Exemplo n.º 54
0
        init_options()
        weechat.hook_config('plugins.var.python.' + SCRIPT_NAME + '.*',
                            'toggle_refresh', '')

        if OPTIONS['activity'].lower() == 'no' or OPTIONS['activity'].lower(
        ) == 'off' or OPTIONS['activity'].lower() == '0':
            # hide all channels
            weechat.command(
                '', '/allchan -exclude=%s /buffer hide' %
                OPTIONS['channel_exclude'])
            # show channel from current server
            server = weechat.buffer_get_string(weechat.current_buffer(),
                                               'localvar_server')
            if server:
                weechat.command(server, '/allchan -current /buffer unhide')
            exclude_server()
            single_channel_exclude()
        else:
            weechat.command('', '/allchan /buffer hide')
        exclude_hotlist()

        weechat.hook_signal('buffer_switch', 'buffer_switch_cb', '')
        weechat.hook_signal('buffer_opened', 'buffer_opened_closed_cb', '')
        weechat.hook_signal('buffer_closed', 'buffer_opened_closed_cb', '')
        weechat.hook_signal('window_switch', 'window_switch_cb', '')
        weechat.hook_signal('irc_server_connected', 'irc_server_connected_cb',
                            '')
        weechat.hook_signal('irc_server_disconnected',
                            'irc_server_disconnected_cb', '')
        weechat.hook_signal('hotlist_changed', 'hotlist_changed_cb', '')
Exemplo n.º 55
0
            0] == '_' and server == gmailhostname:
        nicksToRename.add(nick)
        weechat.command(weechat.buffer_search("irc", myBuffer),
                        "/whois " + nick + " " + nick)

    return weechat.WEECHAT_RC_OK


def whois_data_minbif(data, signal, signal_data):
    if fullname in signal_data:
        nick = signal_data.split(fullname)[0].strip()
        nick = nick[1:nick.index(' :')]
        nick = nick.split(' ')
        nick = nick[3]
        realname = signal_data.split(fullname)[1].strip()

        if nick in nicksToRename:
            nicksToRename.remove(nick)
            ircname = re.sub("[^A-Za-z0-9]", "", realname)[:24]
            if ircname != nick:
                weechat.command(
                    weechat.buffer_search("irc", myBuffer),
                    "/quote -server %s svsnick %s %s" %
                    (myServer, nick, ircname))

    return weechat.WEECHAT_RC_OK


weechat.hook_signal(myServer + ",irc_in_join", "message_join_minbif", "")
weechat.hook_signal(myServer + ",irc_in_320", "whois_data_minbif", "")
Exemplo n.º 56
0
    hotlist = hotlist_dict()
    buffer = weechat.info_get("irc_buffer", "{},{}".format(server, channel))

    if not buffer in hotlist.keys():
        # just some background noise
        return WEECHAT_RC_OK

    if (weechat.config_get_plugin("unhide_low") == "on"
            and hotlist[buffer]["count_low"] > 0
            or hotlist[buffer]["count_message"] > 0
            or hotlist[buffer]["count_private"] > 0
            or hotlist[buffer]["count_highlight"] > 0):
        weechat.buffer_set(buffer, "hidden", "0")

    return WEECHAT_RC_OK


if (__name__ == '__main__' and import_ok
        and weechat.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION,
                             SCRIPT_LICENSE, SCRIPT_DESC, '', '')):
    weechat_version = weechat.info_get("version_number", "") or 0
    if int(weechat_version) >= 0x01000000:
        config_init()
        CURRENT_BUFFER = weechat.current_buffer()
        weechat.hook_signal("buffer_switch", "hide_buffer_cb", "")
        weechat.hook_signal("*,irc_in2_*", "unhide_buffer_cb", "")
    else:
        weechat.prnt(
            "", "{}{} requires WeeChat version 1.0 or higher".format(
                weechat.prefix('error'), SCRIPT_NAME))
Exemplo n.º 57
0
    color_reset     = weechat.color('reset')
    color_peak      = weechat.color('green')
    color_low       = weechat.color('red')
    color_avg       = weechat.color('brown')
    color_bold      = weechat.color('white')

    # pretty [chanop]
    script_nick = '%s[%s%s%s]%s' %(color_delimiter, color_chat_nick, SCRIPT_NAME, color_delimiter,
            color_reset)

    for opt, val in settings.iteritems():
		if not weechat.config_is_set_plugin(opt):
			weechat.config_set_plugin(opt, val)

    script_load()

    weechat.hook_signal('*,irc_in2_join', 'join_cb', '')
    weechat.hook_signal('*,irc_in2_part', 'join_cb', '')
    weechat.hook_signal('*,irc_in2_quit', 'quit_cb', '')

    weechat.hook_command('chanstat', "Display channel's statistics.", '[--save | --load]',
            "Displays channel peak, lowest and average users for current channel.\n"
            "  --save: forces saving the stats database.\n"
            "  --load: forces loading the stats database (Overwriting actual values).\n",
            #" --print: sends /chanstat output to the current channel.",
            '--save|--load', 'chanstat_cmd', '')

    weechat.hook_command('chanstat_debug', '', '', '', '', 'cmd_debug', '')

# vim:set shiftwidth=4 tabstop=4 softtabstop=4 expandtab textwidth=100:
Exemplo n.º 58
0
    else:
        # show help message
        w.command('', '/help ' + NAME)

    return w.WEECHAT_RC_OK

def quit_cb(data, signal, signal_data):
    """save config on quit"""

    save_conf(None)

    return w.WEECHAT_RC_OK

if __name__ == '__main__':
    if w.register(NAME, AUTHOR, VERSION, LICENSE, DESCRIPTION, "", ""):
        w.hook_command(NAME, DESCRIPTION, 'save [path] || load [path]', '', 'save || load', 'autoconf_cb', '')

        # set default config
        for option, value in SETTINGS.items():
            if not w.config_is_set_plugin(option):
                w.config_set_plugin(option, value[0])
                w.config_set_desc_plugin(option, '%s  (default: "%s")' % (value[1], value[0]))

        if 'on' in w.config_get_plugin('autoload'):
            load_conf(None)

        if 'on' in w.config_get_plugin('autosave'):
            w.hook_signal('quit', 'quit_cb', '')


Exemplo n.º 59
0
Arquivo: hank.py Projeto: wetfish/hank
        'transsexual t**s',
        'unison o****m',
        'virgin how to',
        'whoredom'
        'xxx sex',
        'youngster sex',
        'zebra sex'])

def run_proc_cb(udata, command, rc, stdout, stderr):
    global curl_stdout, curl_stderr
    curl_stdout += stdout
    curl_stderr += stderr
    rci = int(rc)
    udata = json.loads(udata)
    fmt = udata['fmt']
    if rci >= 0:
        weechat.prnt("", "hankbot: rc=%d command=%s stderr=%s stdout=%s" % \
            (rci, command, curl_stderr, curl_stdout))
        if rci == 0:
            # curl_stdout = curl_stdout.strip()
            # curl_stdout = ''.join([i if ord(i) < 128 else '?' for i in curl_stdout])
            if curl_stdout != "":
                say(udata['srv'], udata['chn'], fmt % (curl_stdout))
        else:
            say(udata['srv'], udata['chn'], ':(')
        curl_stdout = ""
        curl_stderr = ""
    return weechat.WEECHAT_RC_OK

weechat.hook_signal("*,irc_in2_privmsg", "msg_cb", "");
Exemplo n.º 60
0
                                                   'localvar_server')
                irc_pv_hook = weechat.hook_signal(
                    'irc_pv', 'signal_irc_pv', '%s,%s' % (signal_data, nick))
    return weechat.WEECHAT_RC_OK


def signal_irc_pv(data, signal, signal_data):
    """Callback for signal 'irc_pv'."""
    buffer, nick = data.split(',')
    if signal_data.startswith(':' + nick + '!'):
        # ok, run command
        exec_command(buffer, nick)
    unhook_irc_pv()
    return weechat.WEECHAT_RC_OK


if __name__ == '__main__' and import_ok:
    if weechat.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION,
                        SCRIPT_LICENSE, SCRIPT_DESC, '', ''):
        # set default settings
        version = weechat.info_get('version_number', '') or 0
        for option, value in woq_settings_default.items():
            if not weechat.config_is_set_plugin(option):
                weechat.config_set_plugin(option, value[0])
            if int(version) >= 0x00030500:
                weechat.config_set_desc_plugin(
                    option, '%s (default: "%s")' % (value[1], value[0]))

        # hook signal 'irc_pv_opened'
        weechat.hook_signal('irc_pv_opened', 'signal_irc_pv_opened', '')