aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar jesopo2020-01-29 17:15:54 +0000
committerGravatar jesopo2020-01-29 17:15:54 +0000
commit616eb84264b5d21a25ce0355d6f744fdb3aeb644 (patch)
tree5b984cac953563f7fa3cefa0dd46b84544405f24
parentSpecArgumentTypeString should return None when no args (diff)
signature
add "lstring" command spec; "last string" - explicit args or last message
-rw-r--r--modules/translate.py9
-rw-r--r--src/core_modules/command_spec.py11
2 files changed, 13 insertions, 7 deletions
diff --git a/modules/translate.py b/modules/translate.py
index e11de291..3f31f224 100644
--- a/modules/translate.py
+++ b/modules/translate.py
@@ -10,19 +10,14 @@ REGEX_LANGUAGES = re.compile("(\w+)?:(\w+)? ")
class Module(ModuleManager.BaseModule):
@utils.hook("received.command.tr", alias_of="translate")
@utils.hook("received.command.translate")
+ @utils.spec("!<phrase>lstring")
def translate(self, event):
"""
:help: Translate the provided phrase or the last line in thie current
channel
:usage: [phrase]
"""
- phrase = event["args"]
- if not phrase:
- phrase = event["target"].buffer.get()
- if phrase:
- phrase = utils.irc.strip_font(phrase.message)
- if not phrase:
- raise utils.EventError("No phrase provided.")
+ phrase = event["spec"][0]
source_language = "auto"
target_language = "en"
diff --git a/src/core_modules/command_spec.py b/src/core_modules/command_spec.py
index d8ac84d4..ffcf77ed 100644
--- a/src/core_modules/command_spec.py
+++ b/src/core_modules/command_spec.py
@@ -88,6 +88,17 @@ class Module(ModuleManager.BaseModule):
if args:
value = server.get_user(args[0], create=True)
n = 1
+ elif argument_type.type == "lstring":
+ if args:
+ value = " ".join(args)
+ n = len(args)
+ else:
+ last_message = (channel or user).buffer.get()
+ if last_message:
+ value = last_message.message
+ n = 0
+ else:
+ n = 1
elif argument_type.type == "channelonly":
if channel:
value = True