本文整理汇总了Python中weechat.hook_process函数的典型用法代码示例。如果您正苦于以下问题:Python hook_process函数的具体用法?Python hook_process怎么用?Python hook_process使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了hook_process函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
开发者ID:deflax,项目名称:weechat-weatherbot,代码行数:35,代码来源:weatherbot.py
示例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
开发者ID:deflax,项目名称:weechat-weatherbot,代码行数:26,代码来源:weatherbot.py
示例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)
开发者ID:NuclearW,项目名称:tools,代码行数:26,代码来源:__init__.py
示例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
开发者ID:recht,项目名称:weechat-plugins,代码行数:30,代码来源:hipchat.py
示例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
开发者ID:mkrisher,项目名称:wee-slack,代码行数:8,代码来源:wee_slack.py
示例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
开发者ID:oakkitten,项目名称:scripts,代码行数:8,代码来源:imap_status.py
示例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", "")
开发者ID:norrs,项目名称:weechat-plugins,代码行数:9,代码来源:im_kayac_com_notify.py
示例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
开发者ID:Shrews,项目名称:scripts,代码行数:9,代码来源:xfer_setip.py
示例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])
开发者ID:ishigoemon,项目名称:wee-slack,代码行数:11,代码来源:wee_slack.py
示例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")
开发者ID:Arlefreak,项目名称:dotfiles,代码行数:11,代码来源:weetweet.py
示例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
开发者ID:telnoratti,项目名称:weechatrc,代码行数:12,代码来源:cowchat.py
示例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
开发者ID:Arlefreak,项目名称:dotfiles,代码行数:52,代码来源:weetweet.py
示例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
开发者ID:mattrobenolt,项目名称:weechat-giphy,代码行数:13,代码来源:giphy.py
示例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"}))
开发者ID:wetfish,项目名称:hank,代码行数:13,代码来源:hank.py
示例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
开发者ID:itsamenathan,项目名称:weechat_scripts,代码行数:13,代码来源:shorturl.py
示例16: scp_file
def scp_file(filename, remote_dir):
command_string = "scp -q"
if configurations['local_identity_key'] != "":
command_string += " -i " + configurations['local_identity_key']
if configurations['remote_port'] != "":
command_string += " -P " + configurations['remote_port']
command_string += " " + filename
if configurations['remote_user'] != "":
command_string += " " + configurations['remote_user'] + "@"
command_string += configurations['remote_host']
command_string += ":"
command_string += remote_dir
weechat.hook_process(command_string, 0, 'xfer_scp_process_cb', filename)
开发者ID:Ratler,项目名称:weechat-scripts,代码行数:14,代码来源:xfer_scp.py
示例17: cmd_help
def cmd_help(data, buffer, args):
# Get current list of ignored channels in list form
ignored_channels = get_ignored_channels()
# Used for checking for ignore/unignore commands and getting the arguments
ignore_command = re.match("^ignore\s+(.+)", args)
unignore_command = re.match("^unignore\s+(.+)", args)
if(ignore_command is not None):
channels_to_ignore = ignore_command.group(1).split(' ')
for channel in channels_to_ignore:
if channel not in ignored_channels:
ignored_channels.append(channel)
w.config_set_plugin("ignored_channels", ','.join(ignored_channels))
w.prnt("", "Updated. Ignored channels: %s" % w.config_get_plugin("ignored_channels"))
elif(unignore_command is not None):
channels_to_unignore = unignore_command.group(1).split(' ')
for channel in channels_to_unignore:
if channel in ignored_channels:
ignored_channels.remove(channel)
w.config_set_plugin("ignored_channels", ','.join(ignored_channels))
w.prnt("", "Updated. Ignored channels: %s" % w.config_get_plugin("ignored_channels"))
elif(args == "listignores"):
w.prnt("", "Ignored channels: %s" % w.config_get_plugin("ignored_channels"))
elif(args == "listdevices"):
apikey = w.config_get_plugin("api_key")
apiurl = "https://%[email protected]/v2/devices" % (apikey)
w.hook_process("url:" + apiurl, 20000, "process_devicelist_cb", "")
else:
w.prnt("", """
Weebullet requires an API key from your Pushbullet account to work. Set your API key with:
/set plugins.var.python.weebullet.api_key <KEY>
Weebullet will by default only send notifications when you are marked away on IRC. You can change this with:
/set plugins.var.python.weebullet.away_only [0|1]
Weebullet will by default send to all devices associated with your Pushbullet account. You can change this with:
/set plugins.var.python.weebullet.device_iden <ID>
Weebullet can ignore repeated notifications if they arrive too often. You can set this with (0 or blank to disable):
/set plugins.var.python.weebullet.min_notify_interval <NUMBER>
You can get a list of your devices from the Pushbullet website, or by using
/weebullet listdevices
""")
return w.WEECHAT_RC_OK
开发者ID:sim642,项目名称:weebullet,代码行数:50,代码来源:weebullet.py
示例18: msg_cb
def msg_cb(data, buffer, date, tags, displayed, highlight, prefix, message):
if not checkTime(date):
return weechat.WEECHAT_RC_OK
match = re.match("^!xander (.+)$", message, re.IGNORECASE)
if match is None:
return weechat.WEECHAT_RC_OK
groups = match.groups()
if len(groups) == 0:
return weechat.WEECHAT_RC_OK
weechat.hook_process("say -v Xander -- '{}'".format(groups[0]), 0, "", "")
return weechat.WEECHAT_RC_OK
开发者ID:lieuwex,项目名称:dotfiles,代码行数:14,代码来源:xander.py
示例19: wg_download_file
def wg_download_file(url, filename, timeout, callback, callback_data):
"""Download a file with an URL. Return hook_process created."""
version = weechat.info_get("version_number", "") or 0
if int(version) >= 0x00030700:
return weechat.hook_process_hashtable("url:%s" % url,
{ "file_out": filename },
timeout,
callback, callback_data)
else:
script = [ "import sys",
"try:",
" if sys.version_info >= (3,):",
" import urllib.request",
" response = urllib.request.urlopen('%s')" % url,
" else:",
" import urllib2",
" response = urllib2.urlopen(urllib2.Request('%s'))" % url,
" f = open('%s', 'wb')" % filename,
" f.write(response.read())",
" response.close()",
" f.close()",
"except Exception as e:",
" print('error:' + str(e))" ]
return weechat.hook_process("python -c \"%s\"" % "\n".join(script),
timeout,
callback, callback_data)
开发者ID:SammyLin,项目名称:chef-osx,代码行数:26,代码来源:weeget.py
示例20: wg_update_cache
def wg_update_cache():
""" Download list of scripts and update local cache. """
global wg_config_option, wg_hook_process, wg_stdout
# get data from website, via hook_process
if wg_hook_process["update"] != "":
weechat.unhook(wg_hook_process["update"])
wg_hook_process["update"] = ""
weechat.prnt("", "%s: downloading list of scripts..." % SCRIPT_NAME)
wg_stdout["update"] = ""
wg_config_create_dir()
url = weechat.config_string(wg_config_option["scripts_url"])
filename = wg_config_get_cache_filename()
wg_hook_process["update"] = weechat.hook_process(
"python -c \"import urllib, urllib2\n"
"req = urllib2.Request('" + url + "')\n"
"try:\n"
" response = urllib2.urlopen(req)\n"
" file = open('" + filename + "', 'w')\n"
" file.write(response.read())\n"
" response.close()\n"
" file.close()\n"
"except urllib2.URLError, e:\n"
" print 'error:%s' % e.code\n"
"\"",
TIMEOUT_UPDATE, "wg_process_update_cb", "")
开发者ID:zachwlewis,项目名称:dotfiles,代码行数:25,代码来源:weeget.py
注:本文中的weechat.hook_process函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论