summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastien Helleu <flashcode@flashtux.org>2006-11-07 23:03:06 +0000
committerSebastien Helleu <flashcode@flashtux.org>2006-11-07 23:03:06 +0000
commitb5a7d8e99e372378cb47069a3d2ad0bf65ccc530 (patch)
tree6cb30c000b3d59a21b28d2bdcde76be6b9f55f3a
parent101e623b75b58ecb1f8805ad830e4deb79dbb69b (diff)
downloadweechat-b5a7d8e99e372378cb47069a3d2ad0bf65ccc530.zip
Updated "pyexec.py" script
-rw-r--r--scripts/python/pyexec.py28
1 files changed, 20 insertions, 8 deletions
diff --git a/scripts/python/pyexec.py b/scripts/python/pyexec.py
index 53b3f6bee..93bef6851 100644
--- a/scripts/python/pyexec.py
+++ b/scripts/python/pyexec.py
@@ -4,25 +4,31 @@
License: GPL version 2 or later
"""
-version = "0.1"
+version = "0.2"
helptext = """ The WeeChat script-API is imported into the global namespace, you can
- call all API functions (for instance get_nick_info) directly. The modules
+ call all API functions (for instance "get_info") directly. The modules
"sys", "os" and "math" are imported by default.
Any occurance of ";; " is treated as a newline.
- For automatic string conversion, use:
+ For automatic argument conversion to string, use:
"send" instead of "command"
"echo" instead of "prnt" (prints only to current buffer)
(also provided: "echo_server", "echo_infobar")
+ Additional shortcut functions:
+ "nicks()" returns a dictionary of nicknames for the current channel.
+ It takes a channelname and a servername as optional arguments.
+
Examples:
/pyexec for i in range(3): send(i+1);; echo("Done")
- /pyexec for nick in ["nick1", "nick2"]: send("/op " + nick)
+ /pyexec for nick in nicks(): send("/voice " + nick)
+ /pyexec echo(2**64)
"""
-from weechat import *
+from __future__ import division
import sys, os, math
+from weechat import *
register("PyExec", version, "", "Run Python code in WeeChat")
add_command_handler("pyexec", "pyexec", " Runs Python code directly from the WeeChat command line.", "[Python code]", helptext)
@@ -39,12 +45,18 @@ def echo_infobar(time, text):
def send(text):
return command(str(text))
+def nicks(channel=None, server=None):
+ if not server:
+ server = get_info("server")
+ if not channel:
+ channel = get_info("channel")
+ return get_nick_info(server, channel)
+
def pyexec(server, pycode):
try:
- for pyline in pycode.split(";; "):
- exec pyline
+ exec pycode.replace(";; ", "\n")
except:
(e_type, e_value, e_trace) = sys.exc_info()
- prnt("PyExec: %s [%s] in line: \"%s\"" % (e_type, e_value, pyline))
+ prnt("PyExec: %s: %s" % (str(e_type).replace("exceptions.", ""), e_value))
return PLUGIN_RC_OK