add "lstring" command spec; "last string" - explicit args or last message
This commit is contained in:
parent
c1543ed899
commit
616eb84264
2 changed files with 13 additions and 7 deletions
|
@ -10,19 +10,14 @@ REGEX_LANGUAGES = re.compile("(\w+)?:(\w+)? ")
|
||||||
class Module(ModuleManager.BaseModule):
|
class Module(ModuleManager.BaseModule):
|
||||||
@utils.hook("received.command.tr", alias_of="translate")
|
@utils.hook("received.command.tr", alias_of="translate")
|
||||||
@utils.hook("received.command.translate")
|
@utils.hook("received.command.translate")
|
||||||
|
@utils.spec("!<phrase>lstring")
|
||||||
def translate(self, event):
|
def translate(self, event):
|
||||||
"""
|
"""
|
||||||
:help: Translate the provided phrase or the last line in thie current
|
:help: Translate the provided phrase or the last line in thie current
|
||||||
channel
|
channel
|
||||||
:usage: [phrase]
|
:usage: [phrase]
|
||||||
"""
|
"""
|
||||||
phrase = event["args"]
|
phrase = event["spec"][0]
|
||||||
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.")
|
|
||||||
source_language = "auto"
|
source_language = "auto"
|
||||||
target_language = "en"
|
target_language = "en"
|
||||||
|
|
||||||
|
|
|
@ -88,6 +88,17 @@ class Module(ModuleManager.BaseModule):
|
||||||
if args:
|
if args:
|
||||||
value = server.get_user(args[0], create=True)
|
value = server.get_user(args[0], create=True)
|
||||||
n = 1
|
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":
|
elif argument_type.type == "channelonly":
|
||||||
if channel:
|
if channel:
|
||||||
value = True
|
value = True
|
||||||
|
|
Loading…
Reference in a new issue