本文整理汇总了Python中weechat.hook_process函数的典型用法代码示例。如果您正苦于以下问题:Python hook_process函数的具体用法?Python hook_process怎么用?Python hook_process使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了hook_process函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: wu_autoc
def wu_autoc(data, command, return_code, out, err):
""" weather underground auto search """
global jname
if return_code == w.WEECHAT_HOOK_PROCESS_ERROR:
w.prnt("", "Error with command `%s'" % command)
return w.WEECHAT_RC_OK
if return_code > 0:
w.prnt("", "return_code = %d" % return_code)
if err != "":
w.prnt("", "stderr: %s" % err)
if out != "":
i = json.loads(out)
try:
loc = next((l for l in i["RESULTS"] if l["type"] == "city"), None)
if loc is None:
weebuffer("Unable to locate query.")
return w.WEECHAT_RC_OK
except:
weebuffer("Invalid query. Try again.")
return w.WEECHAT_RC_OK
jname = loc["name"]
location = loc["l"]
prefix = "[weatherbot] mode:"
if mode == "conditions":
cond_url = "url:http://api.wunderground.com/api/{}/conditions{}.json".format(options["apikey"], location)
w.prnt("", '{} {} {}'.format(prefix, mode, location))
w.hook_process(cond_url, 30 * 1000, "wu_cond", "")
if mode == "forecast":
fore_url = "url:http://api.wunderground.com/api/{}/forecast{}.json".format(options["apikey"], location)
w.prnt("", '{} {} {}'.format(prefix, mode, location))
w.hook_process(fore_url, 30 * 1000, "wu_fore", "")
return w.WEECHAT_RC_OK
示例2: triggerwatch
def triggerwatch(data, buffer, args):
global kserver, kchannel, knick, mode
if options["enabled"] == "on":
try:
null, srvmsg = args.split(" PRIVMSG ", 1)
except:
return w.WEECHAT_RC_OK
try:
kchannel, query = srvmsg.split(" :{} ".format(options["weather_trigger"]), 1)
mode = "conditions"
except ValueError:
try:
kchannel, query = srvmsg.split(" :{} ".format(options["forecast_trigger"]), 1)
mode = "forecast"
except ValueError:
return w.WEECHAT_RC_OK
kserver = str(buffer.split(",", 1)[0])
knick = w.info_get("irc_nick_from_host", args)
query = query.replace(" ", "%20")
autoc_url = "url:http://autocomplete.wunderground.com/aq?query={}&format=JSON".format(query)
w.hook_process(autoc_url, 30 * 1000, "wu_autoc", "")
return w.WEECHAT_RC_OK
示例3: hook_process
def hook_process(args, callback, stdin=None, userdata=None):
# same as hook_timer. injects a random name in __main__ to
# wrap around the actual callback.
state = {
'stdout': '',
'stderr': '',
}
@functools.wraps(callback)
def _hook_process_helper(genfuncname, command, rc, out, err):
state['stdout'] += out
state['stderr'] += err
if rc == weechat.WEECHAT_HOOK_PROCESS_RUNNING:
return weechat.WEECHAT_RC_OK
remove_func(genfuncname)
result = callback(rc, state['stdout'], state['stderr'], userdata)
if result is None:
result = weechat.WEECHAT_RC_OK
return result
genfuncname = inject_func(_hook_process_helper)
cmd = ' '.join(pipes.quote(arg) for arg in args)
weechat.hook_process(cmd, 30*1000, genfuncname, genfuncname)
示例4: hipchat_cmd
def hipchat_cmd(data, buffer, args):
bitlbee_server = weechat.buffer_get_string(buffer, 'name').split('.')[0]
if buffer == weechat.buffer_search_main():
weechat.prnt('', 'Hipchat commands must be run in IRC buffer')
return weechat.WEECHAT_RC_ERROR
if args.startswith('rooms'):
room_args = args.split(' ', 1)
if room_args[-1].startswith('**'):
keyEvent(data, buffer, room_args[-1][2:])
return weechat.WEECHAT_RC_OK
rooms_initialise_list(bitlbee_server)
weechat.hook_process("url:https://api.hipchat.com/v2/room?auth_token=%s&max-results=1000" %
get_token(), 30 * 1000, "room_list_cb", "")
elif args == 'autojoin':
rooms_initialise_list(bitlbee_server)
nick = weechat.info_get('irc_nick', bitlbee_server)
weechat.hook_process('url:https://api.hipchat.com/v2/user/@%s/preference/auto-join?'
'auth_token=%s&max-results=500' % (nick, get_token()),
30 * 1000, 'room_list_cb', '')
elif args.startswith('whois'):
whois_start(args[5:].strip())
elif args == 'fullnames':
update_fullnames(buffer)
elif args.startswith('nicks'):
show_nicks(args.split(' ', 1)[-1])
return weechat.WEECHAT_RC_OK
示例5: async_slack_api_request
def async_slack_api_request(browser, request, data):
t = int(time.time())
request += "?t=%s" % t
data["token"] = stuff["api_token"]
data = urllib.urlencode(data)
command = 'curl --data "%s" https://%s/api/%s' % (data,domain,request)
w.hook_process(command, 5000, '', '')
return True
示例6: imap_timer_cb
def imap_timer_cb(data, remaining_calls):
"""Timer callback to update imap bar item."""
if WEECHAT_VERSION >= 0x01050000:
w.hook_process('func:imap_get_unread', 30 * 1000,
'imap_process_cb', '')
else:
imap_update_content(imap_get_unread(None)) # this can block WeeChat!
return w.WEECHAT_RC_OK
示例7: postIm
def postIm(message, handler=None, label=None, title=None):
USERNAME = weechat.config_get_plugin("username")
PASSWORD = weechat.config_get_plugin("password")
if USERNAME != "" and PASSWORD != "":
url = "http://im.kayac.com/api/post/" + USERNAME
opt_dict = {"message": "[%s] - %s\n%s" % (label, title, message), "password": PASSWORD}
opt = urllib.urlencode(opt_dict)
cmd = 'python -c \'from urllib2 import Request, urlopen; urlopen(Request("%s", "%s"))\'' % (url, opt)
weechat.hook_process(cmd, 10000, "hook_process_cb", "")
示例8: fn_connected
def fn_connected(data, signal, signal_data):
global ip_from_option
# check if xfer option exists
own_ip_option = w.config_get("xfer.network.own_ip")
if not own_ip_option:
return w.WEECHAT_RC_OK
ip_from_option = w.config_string(own_ip_option)
w.hook_process("url:%s" % OPTIONS["url"], 60000, "fn_setip", "")
return w.WEECHAT_RC_OK
示例9: do_url
def do_url(item):
try:
query = urlparse.parse_qs(item[1]["postfields"])
if query.has_key("channel") and item[0].find('history') > -1:
channel = query["channel"][0]
channel = channels.find(channel)
channel.server.buffer_prnt("downloading channel history for %s" % (channel.name), backlog=True)
except:
pass
command = 'curl --data "%s" %s' % (item[1]["postfields"], item[0][4:])
w.hook_process(command, 10000, item[3], item[4])
示例10: oauth_dance
def oauth_dance(buffer, pin = ""):
#Auth the twitter client
if pin == "":
weechat.prnt(buffer,"Hi there! We're gonna get you all set up to use this plugin.")
weechat.hook_process("python3 " + SCRIPT_FILE_PATH + " " + "'' " + "'' " +
"auth", 10 * 1000, "oauth_proc_cb", "auth1")
else:
oauth_verifier = pin.strip()
weechat.hook_process("python3 " + SCRIPT_FILE_PATH + " " +
script_options["oauth_token"] + " " + script_options["oauth_secret"] + " " +
"auth "+ oauth_verifier, 10 * 1000, "oauth_proc_cb", "auth2")
示例11: cowcall
def cowcall(data, buffer, args):
cowfile, sep, say = args.partition(" ")
if cowfile == "" or say == "":
return weechat.WEECHAT_RC_ERROR
say = re.sub(pat, r'\\\1', say)
channel = weechat.buffer_get_string(buffer, "localvar_channel")
server = weechat.buffer_get_string(buffer, "localvar_server")
weechat.hook_process("cowsay -f {} {}".format(cowfile, say),
2000,
"cowchat",
"{};{}".format(server, channel))
return weechat.WEECHAT_RC_OK
示例12: oauth_proc_cb
def oauth_proc_cb(data, command, rc, out, err):
global script_options
buffer = twit_buf
if rc == weechat.WEECHAT_HOOK_PROCESS_ERROR:
weechat.prnt("", "Error with command '%s'" %
command.replace(script_options["oauth_token"],"").replace(script_options["oauth_secret"],""))
return weechat.WEECHAT_RC_OK
if out != "":
if data == "nick":
weechat.config_set_plugin('screen_name', out.strip())
finish_init()
elif data == "friends":
process_output = ast.literal_eval(out)
if isinstance(process_output[-1], int):
t_id = dict_tweet(str(process_output[-1])) + "\t"
process_output = process_output[:-1]
weechat.prnt_date_tags(buffer, 0, "no_highlight", t_id +
"It sees like you are following more than 250 people. Due to twitter api limits " +
"it is nearly impossible to get large groups of followers in one go. However the " +
"nicks will be added when they tweet something so if you don't have to be able " +
"autocomplete them from the start this is not a problem for you." +
" If you want to get the rest of the nicks you can use the id of this text.")
for nick in process_output:
add_to_nicklist(buffer,nick)
#Get latest tweets from timeline
buffer_input_cb("silent", buffer, ":new")
elif data == "auth1":
#First auth step to request pin code
oauth_token, oauth_token_secret = parse_oauth_tokens(out)
script_options['oauth_token'] = oauth_token
script_options['oauth_secret'] = oauth_token_secret
weechat.prnt(buffer,"""
Copy the PIN number that appears on the linked web page and type ":auth <pin>"
in weechat. For example ":auth 123456"
""")
oauth_url = ('https://api.twitter.com/oauth/authorize?oauth_token=' +
oauth_token)
weechat.prnt(buffer," Please go here to get your PIN: " + oauth_url)
elif data == "auth2":
oauth_token, oauth_token_secret = parse_oauth_tokens(out)
weechat.config_set_plugin('oauth_token', oauth_token)
weechat.config_set_plugin('oauth_secret', oauth_token_secret)
weechat.config_set_plugin('auth_complete', "on")
weechat.prnt(buffer," Done! now you can begin using this script!")
weechat.hook_process("python3 " + SCRIPT_FILE_PATH + " " +
script_options["oauth_token"] + " " + script_options["oauth_secret"] + " " +
"settings []", 10 * 1000, "oauth_proc_cb", "nick")
return weechat.WEECHAT_RC_OK
示例13: giphy_cb
def giphy_cb(data, buf, args):
if not args:
weechat.prnt(buf, '[giphy]:\t%sNothing to search for. :(' % (RED,))
return weechat.WEECHAT_RC_ERROR
s_args = args.split()
if s_args[0][0] == '#':
weechat.prnt(buf, '[giphy]:\t%sFancy searches aren\'t allowed yet. :(' % (RED,))
return weechat.WEECHAT_RC_ERROR
args = ' '.join(s_args)
cmd = 'url:https://api.giphy.com/v1/gifs/search?' + urlencode({'q': args, 'api_key': 'dc6zaTOxFJmzC', 'limit': 1})
cmd_to_query[cmd] = Query(buf, args)
weechat.hook_process(cmd, 10000, 'hook_process_cb', '')
return weechat.WEECHAT_RC_OK
示例14: run_rl
def run_rl(srv, chn):
logfile = '~/.weechat/logs/irc.%s.%s.weechatlog' % (srv, chn)
cmd = '''tail -c "+$[ 1 + $[ RANDOM % $(stat -c '%s' ''' + \
logfile + \
''') ]]" ''' + \
logfile + \
'''| head -n21 | tail -n20 2>/dev/null | ''' \
'''grep -Pv '(-->|<--|You are now known as)' | shuf -n1 | cut -f3-'''
weechat.hook_process(
"bash -c %s" % (escapeshellarg(cmd)),
5000,
"run_proc_cb",
json.dumps({'srv': srv, 'chn': chn, 'fmt': "%s"}))
示例15: shorten
def shorten(buffer, url):
shortener = weechat.config_get_plugin('shortener')
if shortener == 'rldn.net':
url = "url:http://rldn.net/api/{url}".format(url=url)
if shortener == 'is.gd':
url = "url:http://is.gd/create.php?format=simple&url={url}".format(url=url)
if shortener == 'v.gd':
url = "url:http://v.gd/create.php?format=simple&url={url}".format(url=url)
weechat.hook_process(url,
30 * 1000,
"print_short",
buffer)
return weechat.WEECHAT_RC_OK