From 2e3fcbb7ab7cd90d8f66692e7579b924cade4e7f Mon Sep 17 00:00:00 2001 From: Ryan Huber Date: Thu, 9 Feb 2017 09:19:37 -0800 Subject: decorators and tag fix --- wee_slack.py | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/wee_slack.py b/wee_slack.py index 3b41067..9aa6b1d 100644 --- a/wee_slack.py +++ b/wee_slack.py @@ -1,6 +1,8 @@ #-*- coding: utf-8 -*- # +from functools import wraps + import time import json import pickle @@ -66,6 +68,30 @@ SLACK_API_TRANSLATOR = { } +###### Decorators have to be up here + +def slack_buffer_or_ignore(f): + """ + Only run this function if we're in a slack buffer, else ignore + """ + @wraps(f) + def wrapper(current_buffer, *args, **kwargs): + if current_buffer in EVENTROUTER.weechat_controller.buffers: + return w.WEECHAT_RC_OK + return f(current_buffer, *args, **kwargs) + return wrapper + +def slack_buffer_required(f): + """ + Only run this function if we're in a slack buffer, else print error + """ + @wraps(f) + def wrapper(current_buffer, *args, **kwargs): + if current_buffer not in EVENTROUTER.weechat_controller.buffers: + return w.WEECHAT_RC_ERROR + return f(current_buffer, *args, **kwargs) + return wrapper + NICK_GROUP_HERE = "0|Here" NICK_GROUP_AWAY = "1|Away" @@ -2311,6 +2337,7 @@ def modify_print_time(buffer, new_id, time): def tag(tagset, user=None): if user: + user.replace(" ", "_") default_tag = "nick_" + user else: default_tag = 'nick_unknown' @@ -2335,6 +2362,7 @@ def tag(tagset, user=None): ###### New/converted command_ commands +@slack_buffer_or_ignore def join_command_cb(data, current_buffer, args): args = args.split() if len(args) < 2: @@ -2539,7 +2567,6 @@ def load_emoji(): dbg("Unexpected error: {}".format(sys.exc_info()), 5) return w.WEECHAT_RC_OK - def setup_hooks(): cmds = {k[8:]: v for k, v in globals().items() if k.startswith("command_")} -- cgit