本文整理汇总了Python中weechat.prefix函数的典型用法代码示例。如果您正苦于以下问题:Python prefix函数的具体用法?Python prefix怎么用?Python prefix使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了prefix函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: emojis_cb
def emojis_cb(data, bufferptr, args):
args = args.split(" ")
if not args:
weechat.prnt("", "%s%s: invalid arguments (help on command: /help %s)" % (weechat.prefix("error"), SCRIPT_NAME, SCRIPT_NAME))
return weechat.WEECHAT_RC_OK
if args[0] == "reload":
# reload emoji database from file
reload_emojis()
return weechat.WEECHAT_RC_OK
if args[0] == "add" and len(args) == 3:
# add new emoji to database
name, emoji = args[1:3]
colonized_name = ":{}:".format(name)
if ":" in name:
weechat.prnt("", "%s%s: name may not contain ':'" % (weechat.prefix("error"), SCRIPT_NAME))
return weechat.WEECHAT_RC_OK
if colonized_name in EMOJIS:
weechat.prnt("", "%s%s: emoji with name \"%s\" already exists" % (weechat.prefix("error"), SCRIPT_NAME, name))
return weechat.WEECHAT_RC_OK
add_emoji(name, emoji)
weechat.prnt("", "%s: emoji %s added: %s" % (SCRIPT_NAME, name, emoji))
return weechat.WEECHAT_RC_OK
if args[0] == "show" and len(args) == 2:
name = args[1]
colonized_name = ":{}:".format(name)
if colonized_name not in EMOJIS:
weechat.prnt("", "%s%s: emoji with name \"%s\" does not exist" % (weechat.prefix("error"), SCRIPT_NAME, name))
return weechat.WEECHAT_RC_OK
emoji = EMOJIS[colonized_name]
weechat.prnt("", "%s: %s: %s" % (SCRIPT_NAME, name, emoji))
return weechat.WEECHAT_RC_OK
weechat.prnt("", "%s%s: invalid arguments (help on command: /help %s)" % (weechat.prefix("error"), SCRIPT_NAME, SCRIPT_NAME))
return weechat.WEECHAT_RC_OK
示例2: cron_at_cmd_cb
def cron_at_cmd_cb(data, buffer, args):
""" Command /at. """
global crontab, cron_commands
if args in ["", "list"]:
cron_list()
return weechat.WEECHAT_RC_OK
if args == "debug":
cron_list(debug=True)
return weechat.WEECHAT_RC_OK
argv = args.split(None, 3)
if len(argv) >= 4:
if argv[2] not in cron_commands:
weechat.prnt("", "%scron: unknown keyword \"%s\""
% (weechat.prefix("error"), argv[2]))
return weechat.WEECHAT_RC_ERROR
hour_min = cron_at_time(argv[0])
if hour_min == None:
weechat.prnt("", "%scron: invalid time \"%s\""
% (weechat.prefix("error"), argv[0]))
return weechat.WEECHAT_RC_OK
cron_add(str(hour_min[1]), str(hour_min[0]), "*", "*", "*",
"1", argv[1], argv[2] + " " + argv[3])
return weechat.WEECHAT_RC_OK
weechat.prnt("", "%scron: invalid arguments" % weechat.prefix("error"))
return weechat.WEECHAT_RC_OK
示例3: theme_unpack
def theme_unpack():
"""Unpack theme file (themes.tar.bz2)."""
filename = theme_config_get_tarball_filename()
if not os.path.isfile(filename):
weechat.prnt('',
'{0}{1}: file not found: {1}'
''.format(weechat.prefix('error'),
SCRIPT_NAME,
filename))
return False
try:
tar = tarfile.open(filename, 'r:bz2')
tar.extractall(path=theme_config_get_dir())
tar.close()
except (tarfile.ReadError, tarfile.CompressionError, IOError):
weechat.prnt('',
'{0}{1}: invalid file (format .tar.bz2 expected): {2}'
''.format(weechat.prefix('error'),
SCRIPT_NAME,
filename))
weechat.prnt('',
'{0}{1}: try /unset theme.themes.url'
''.format(weechat.prefix('error'), SCRIPT_NAME))
return False
return True
示例4: opall
def opall(data, buffer, args):
channel = weechat.buffer_get_string(buffer, 'localvar_channel')
server = weechat.buffer_get_string(buffer, 'localvar_server')
if not weechat.info_get('irc_is_channel', channel):
weechat.prnt(buffer, '%sopall: Not an IRC channel' % weechat.prefix('error'))
return weechat.WEECHAT_RC_OK
toOp = withoutOp(server, channel)
if len(toOp) == 0:
return weechat.WEECHAT_RC_OK
# how many people can we op at once
modes = int(weechat.info_get('irc_server_isupport_value', '%s,MODES' % server)) or 0
if modes == 0:
weechat.prnt(buffer, '%sopall: failed to determine MODES' % weechat.prefix('error'))
return weechat.WEECHAT_RC_ERROR
frm = 0
to = modes
while len(toOp) > frm:
weechat.command(buffer, '/OP %s' % ' '.join(toOp[frm:to]))
frm = to
to += modes
return weechat.WEECHAT_RC_OK
示例5: shell_process_cb
def shell_process_cb(data, command, rc, stdout, stderr):
"""Callback for hook_process()."""
global cmd_hook_process, cmd_buffer, cmd_stdout, cmd_stderr, cmd_send_to_buffer
cmd_stdout += stdout
cmd_stderr += stderr
if int(rc) >= 0:
if cmd_stdout:
lines = cmd_stdout.rstrip().split('\n')
if cmd_send_to_buffer == 'current':
for line in lines:
weechat.command(cmd_buffer, '%s' % line)
else:
weechat.prnt(cmd_buffer, '')
if cmd_send_to_buffer != 'new':
weechat.prnt(cmd_buffer, '%sCommand "%s" (rc %d), stdout:'
% (SHELL_PREFIX, data, int(rc)))
for line in lines:
weechat.prnt(cmd_buffer, ' \t%s' % line)
if cmd_stderr:
lines = cmd_stderr.rstrip().split('\n')
if cmd_send_to_buffer == 'current':
for line in lines:
weechat.command(cmd_buffer, '%s' % line)
else:
weechat.prnt(cmd_buffer, '')
if cmd_send_to_buffer != 'new':
weechat.prnt(cmd_buffer, '%s%sCommand "%s" (rc %d), stderr:'
% (weechat.prefix('error'), SHELL_PREFIX, data, int(rc)))
for line in lines:
weechat.prnt(cmd_buffer, '%s%s' % (weechat.prefix('error'), line))
cmd_hook_process = ''
shell_set_title()
return weechat.WEECHAT_RC_OK
示例6: send_prowl_notification
def send_prowl_notification(chan, message, isPrivate):
# Error checking - we need a valid prowl API key to be set in order to send a Prowl notification
prowl_api_key = weechat.config_get_plugin('prowl_api_key')
if (prowl_api_key == ''):
show_config_help()
weechat.prnt('', '%sweeprowl - Could not send Prowl notification.' % weechat.prefix('error'))
return
# Build the Prowl API request
params = urllib.urlencode({
'apikey': prowl_api_key,
'application': 'weechat',
'event': 'IRC ' + 'Private Message' if isPrivate else 'Mention/Hilight',
'description': 'Channel: ' + chan + '\n' + message
})
# Make the Prowl API request
conn = httplib.HTTPSConnection('api.prowlapp.com')
conn.request('POST', '/publicapi/add?' + params)
# Error checking - make sure the Prowl API request was successful
response = conn.getresponse()
if (response.status != 200):
weechat.prnt('', '%sweeprowl - Error: There was a problem communicating with the Prowl API!' % weechat.prefix('error'))
weechat.prnt('', '%sweeprowl - Prowl API response information:' % weechat.prefix('error'))
weechat.prnt('', '%sweeprowl - Response status code = %s' % (weechat.prefix('error'), response.status))
weechat.prnt('', '%sweeprowl - Response reason phrase = %s' % (weechat.prefix('error'), response.reason))
weechat.prnt('', '%sweeprowl - Could not send Prowl notification.' % weechat.prefix('error'))
conn.close()
示例7: purgelogs_cb
def purgelogs_cb(data, buffer, args):
global basedir,purgelogs_commands,check_only, i
basedir = get_path()
if basedir == "":
return w.WEECHAT_RC_OK
argv = args.split(None, 2)
""" argument "check" is set? """
if len(argv) == 3:
if argv[2] == "delete":
check_only = False # delete
w.command("","/mute /plugin unload logger")
else:
check_only = True # show only
w.prnt("", "weechat-logs:")
if len(argv) >= 1:
if argv[0] not in purgelogs_commands:
w.prnt("", "%s %s: unknown keyword \"%s\""
% (w.prefix("error"), SCRIPT_NAME, argv[0]))
if is_number(argv[1]) is False:
w.prnt("", "%s %s: wrong value \"%s\""
% (w.prefix("error"), SCRIPT_NAME, argv[1]))
if argv[0] in ["", "age"]:
i = 0
dellog_by_date(argv[1])
if argv[0] in ["", "size"]:
i = 0
dellog_by_size(argv[1])
if check_only is False:
w.command("","/mute /plugin load logger")
return w.WEECHAT_RC_OK
示例8: get_autojoin_list
def get_autojoin_list(server):
ptr_config_autojoin = weechat.config_get("irc.server.%s.autojoin" % server)
# option not found! server does not exist
if not ptr_config_autojoin:
weechat.prnt(buffer, "%s%s: server '%s' does not exist." % (weechat.prefix("error"), SCRIPT_NAME, server))
return weechat.WEECHAT_RC_OK
# get value from autojoin option
channels = weechat.config_string(ptr_config_autojoin)
if not channels:
return 1, 1
# check for keys
if len(re.findall(r" ", channels)) == 0:
list_of_channels = channels.split(",")
list_of_keys = []
elif len(re.findall(r" ", channels)) == 1:
list_of_channels2, list_of_keys = channels.split(" ")
list_of_channels = list_of_channels2.split(",")
else:
weechat.prnt("", "%s%s: irc.server.%s.autojoin not valid..." % (weechat.prefix("error"), SCRIPT_NAME, server))
return 0, 0
return list_of_channels, list_of_keys
示例9: connect
def connect(self):
self.create_buffer()
self.disconnect()
weechat.prnt(self.buffer,
'Connecting to %s:%s'
% (self.get_option('host'), self.get_option('port')))
try:
hints = socket.getaddrinfo(self.get_option('host'),
self.get_option('port'),
socket.AF_UNSPEC, socket.SOCK_STREAM,
0, socket.AI_PASSIVE)
except socket.error as e:
weechat.prnt(self.buffer,
'%s%s' % (weechat.prefix('error'), e.args[1]))
else:
for res in hints:
af, socktype, proto, canonname, sa = res
try:
self.socket = socket.socket(af, socktype, proto)
self.socket.connect(sa)
except socket.error:
self.socket = None
continue
break
if self.socket is None:
weechat.prnt(self.buffer,
'%sCould not connect' % (weechat.prefix('error'),))
else:
self.hook_fd = weechat.hook_fd(self.socket.fileno(), 1, 0, 0,
'wee_ns_hook_fd_cb', '')
示例10: wg_parse_xml
def wg_parse_xml():
"""
Parse XML scripts list and return dictionary with list, with key 'id'.
Example of item return in dictionary :
'119': { 'name' : 'weeget',
'version' : '0.1',
'url' : 'http://www.weechat.org/files/scripts/weeget.py',
'language' : 'python',
'license' : 'GPL3',
'md5sum' : 'd500714fc19b0e10cc4e339e70739e4ad500714fc19b0e10cc4e339e70739e4a',
'tags' : 'scripts',
'desc_en' : 'Scripts manager.',
'desc_fr' : 'Gestionnaire de scripts.',
'requirements': 'python 2.5',
'min_weechat' : '0.3.0',
'max_weechat' : '',
'author' : 'FlashCode',
'mail' : 'flashcode [at] flashtux [dot] org',
'added' : '2009-04-05 22:39:18',
'updated' : '0000-00-00 00:00:00' }
"""
global wg_scripts, wg_action, wg_action_args
wg_scripts = {}
try:
f = gzip.open(wg_config_get_cache_filename(), "rb")
string = f.read()
f.close()
except:
weechat.prnt("", "%s%s: unable to read xml file"
% (weechat.prefix("error"), SCRIPT_NAME))
else:
try:
dom = xml.dom.minidom.parseString(string)
except:
weechat.prnt("",
"%s%s: unable to parse xml list of scripts"
% (weechat.prefix("error"), SCRIPT_NAME))
# discard action
wg_action = ""
wg_action_args = ""
else:
for scriptNode in dom.getElementsByTagName("plugin"):
id = scriptNode.getAttribute("id")
script = {}
for node in scriptNode.childNodes:
if node.nodeType == node.ELEMENT_NODE:
if node.firstChild != None:
nodename = node.nodeName
value = node.firstChild.data
if sys.version_info < (3,):
# python 2.x: convert unicode to str (in python 3.x, id and text are already strings)
nodename = nodename.encode("utf-8")
value = value.encode("utf-8")
script[nodename] = value
if script["language"] in SCRIPT_EXTENSION:
script["full_name"] = script["name"] + "." + SCRIPT_EXTENSION[script["language"]]
if wg_check_version(script):
wg_scripts[id] = script
wg_execute_action()
示例11: gweather_data_cb
def gweather_data_cb(data, command, rc, stdout, stderr):
'''
Callback for the data fetching process.
'''
global last_city, last_lang, last_run, last_format
global gweather_hook_process, gweather_stdout, gweather_output
if rc == weechat.WEECHAT_HOOK_PROCESS_ERROR or stderr != '':
weechat.prnt('', '%sgweather: Weather information fetching failed: %s' % (\
weechat.prefix("error"), stderr))
return weechat.WEECHAT_RC_ERROR
if stdout:
gweather_stdout += stdout
if int(rc) < 0:
# Process not ready
return weechat.WEECHAT_RC_OK
# Update status variables for succesful run
last_run = time()
last_city = weechat.config_get_plugin('city')
last_lang = weechat.config_get_plugin('language')
last_format = weechat.config_get_plugin('format')
gweather_hook_process = ''
if not gweather_stdout:
return weechat.WEECHAT_RC_OK
try:
# The first row should contain "content-type" from HTTP header
content_type, xml_response = gweather_stdout.split('\n', 1)
except:
# Failed to split received data in two at carridge return
weechat.prnt('', '%sgweather: Invalid data received' % (weechat.prefix("error")))
gweather_stdout = ''
return weechat.WEECHAT_RC_ERROR
gweather_stdout = ''
# Determine the used character set in the response
try:
charset = content_type.split('charset=')[1]
except:
charset = 'utf-8'
if charset.lower() != 'utf-8':
xml_response = xml_response.decode(charset).encode('utf-8')
# Feed the respose to parser and parsed data to formatting
weather_data = parse_google_weather(xml_response)
gweather_output = format_weather(weather_data)
# Request bar item to update to the latest "gweather_output"
weechat.bar_item_update('gweather')
return weechat.WEECHAT_RC_OK
示例12: my_process_cb
def my_process_cb(data, command, rc, out, err):
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
data = ast.literal_eval(data)
buffer = data[0]
end_mes = data[1]
if out != "":
if out[0] != "[" and out[0] != "{":
#If message is just a string print it
weechat.prnt(buffer, "%s%s" % (weechat.prefix("network"), out))
return weechat.WEECHAT_RC_OK
process_output = ast.literal_eval(out)
#List message
if len(end_mes) >= 1 and end_mes[0] == "L":
if isinstance(process_output[-1], int):
t_id = dict_tweet(str(process_output[-1])) + "\t"
process_output = process_output[:-1]
more = " ..."
else:
t_id = weechat.prefix("network")
more = ""
for nick in process_output:
if end_mes == "LYFollowing":
add_to_nicklist(buffer,nick)
elif script_options['tweet_nicks']:
add_to_nicklist(buffer,nick,tweet_nicks_group[buffer])
weechat.prnt_date_tags(buffer, 0, "no_highlight",
"%s%s: %s%s" % (t_id, end_mes[1:], process_output, more))
return weechat.WEECHAT_RC_OK
if end_mes == "About":
weechat.prnt(buffer, "Nick: %s | Name: %s | Protected: %s" % (process_output['screen_name'],
process_output['name'],
process_output['protected']))
weechat.prnt(buffer, "Description: %s" % process_output['description'])
weechat.prnt(buffer, "Location: %s | Time zone: %s" % (process_output['location'], process_output['time_zone']))
weechat.prnt(buffer, "Created at: %s | Verified user: %s" % (process_output['created_at'], process_output['verified']))
weechat.prnt(buffer, "Following: %s | Followers: %s | Favourites: %s | Tweets: %s" % (process_output['friends_count'],
process_output['followers_count'],
process_output['favourites_count'],
process_output['statuses_count']))
weechat.prnt(buffer, "Are you currently following this person: %s" % (process_output['following']))
return weechat.WEECHAT_RC_OK
print_tweet_data(buffer,process_output,end_mes)
if end_mes != "id" and end_mes != "":
weechat.prnt(buffer, "%s%s" % (weechat.prefix("network"), end_mes))
if err != "":
weechat.prnt("", "stderr: %s" % err)
return weechat.WEECHAT_RC_OK
示例13: notify_cb
def notify_cb(data, command, return_code, out, err):
if return_code == weechat.WEECHAT_HOOK_PROCESS_ERROR:
weechat.prnt("", "%s pushbullet.py got err command %s" % (weechat.prefix("error"), command))
return weechat.WEECHAT_RC_OK
# weechat.prnt("", "command:%s return_code:%s out:%s err:%s" % (command, return_code, out, err))
j = json.loads(out)
if "error" in j:
weechat.prnt("", "%s weechat-pushbullet.py %s %s" % (weechat.prefix("error"), j["error"]["type"], j["error"]["message"]))
return weechat.WEECHAT_RC_OK
示例14: add_key_to_list
def add_key_to_list(server, channel, new_key):
autojoin_list = get_autojoin(server)
if not autojoin_list:
return weechat.WEECHAT_RC_OK
# check autojoin for space
if len(re.findall(r" ", autojoin_list)) == 0:
weechat.prnt(
"", '%s%s: no password(s) set in autojoin for server "%s".' % (weechat.prefix("error"), SCRIPT_NAME, server)
)
return weechat.WEECHAT_RC_OK
if len(re.findall(r" ", autojoin_list)) > 1:
weechat.prnt(
"",
'%s%s: autojoin format for server "%s" invalid (two or more spaces).'
% (weechat.prefix("error"), SCRIPT_NAME, server),
)
return weechat.WEECHAT_RC_OK
# split autojoin option to a channel and a key list
arg_channel, arg_keys = autojoin_list.split(" ")
argv_channels = arg_channel.split(",")
argv_keys = arg_keys.split(",")
# search for channel name in list of channels and get position
if channel in argv_channels:
channel_pos_in_list = argv_channels.index(channel)
# enough keys in list? list counts from 0!
if channel_pos_in_list + 1 > len(argv_keys):
weechat.prnt(
"",
'%s%s: not enough keys in list or channel position is not valid. check out autojoin option for server "%s".'
% (weechat.prefix("error"), SCRIPT_NAME, server),
)
return weechat.WEECHAT_RC_OK
sec_data = check_key_for_secure(argv_keys, channel_pos_in_list)
# check weechat version and if secure option is on and secure data will be used for this key?
if int(version) >= 0x00040200 and OPTIONS["secure"].lower() == "on" and sec_data == 1:
sec_data_name = argv_keys[channel_pos_in_list][11:-1]
weechat.command("", "%s/secure set %s %s" % (use_mute(), sec_data_name, new_key))
else:
if sec_data == 1:
weechat.prnt(
"",
'%s%s: key for channel "%s.%s" not changed! option "plugins.var.python.%s.secure" is off and you are using secured data for key.'
% (weechat.prefix("error"), SCRIPT_NAME, server, channel, SCRIPT_NAME),
)
return weechat.WEECHAT_RC_OK
argv_keys[channel_pos_in_list] = new_key
new_joined_option = "%s %s" % (",".join(argv_channels), ",".join(argv_keys))
save_autojoin_option(server, new_joined_option)
return weechat.WEECHAT_RC_OK
示例15: weather_data_cb
def weather_data_cb(data, command, rc, stdout, stderr):
"""
Callback for the data fetching process.
"""
global last_city, last_run
global gweather_hook_process, gweather_stdout, gweather_output
if rc == weechat.WEECHAT_HOOK_PROCESS_ERROR or stderr != "":
weechat.prnt("", "%sgweather: Weather information fetching failed: %s" % (weechat.prefix("error"), stderr))
return weechat.WEECHAT_RC_ERROR
if stdout:
gweather_stdout += stdout
if int(rc) < 0:
# Process not ready
return weechat.WEECHAT_RC_OK
# Update status variables for succesful run
last_run = time()
last_location = weechat.config_get_plugin("location")
gweather_hook_process = ""
if not gweather_stdout:
return weechat.WEECHAT_RC_OK
try:
# The first row should contain "content-type" from HTTP header
content_type, xml_response = gweather_stdout.split("\n", 1)
except:
# Failed to split received data in two at carridge return
weechat.prnt("", "%sweather: Invalid data received" % (weechat.prefix("error")))
gweather_stdout = ""
return weechat.WEECHAT_RC_ERROR
gweather_stdout = ""
# Determine the used character set in the response
try:
charset = content_type.split("charset=")[1]
except:
charset = "utf-8"
if charset.lower() != "utf-8":
xml_response = xml_response.decode(charset).encode("utf-8")
# Feed the respose to parser and parsed data to formatting
weather_data = parse_google_weather(xml_response)
gweather_output = format_weather(weather_data)
if gweather_output:
weechat.command(weechat.current_buffer(), gweather_output)
return weechat.WEECHAT_RC_OK