allow !grab for 1 to 3 most recent lines (default is 1)
This commit is contained in:
parent
7db17c0962
commit
6cfab3f344
1 changed files with 20 additions and 8 deletions
|
@ -107,20 +107,32 @@ class Module(ModuleManager.BaseModule):
|
||||||
|
|
||||||
@utils.hook("received.command.grab", alias_of="quotegrab")
|
@utils.hook("received.command.grab", alias_of="quotegrab")
|
||||||
@utils.hook("received.command.quotegrab", min_args=1, channel_only=True)
|
@utils.hook("received.command.quotegrab", min_args=1, channel_only=True)
|
||||||
|
@utils.kwarg("usage", "<nickname> [line-count]")
|
||||||
def quote_grab(self, event):
|
def quote_grab(self, event):
|
||||||
line = event["target"].buffer.find_from(event["args_split"][0])
|
line_count = 1
|
||||||
if line:
|
if len(event["args_split"]) > 1:
|
||||||
|
line_count = utils.parse.try_int(event["args_split"][1])
|
||||||
|
if not line_count or not (0 < line_count < 4):
|
||||||
|
raise utils.EventError(
|
||||||
|
"Please provide a number between 1 and 3")
|
||||||
|
|
||||||
|
target = event["args_split"][0]
|
||||||
|
lines = event["target"].buffer.find_many_from(target, line_count)
|
||||||
|
if lines:
|
||||||
|
lines.reverse()
|
||||||
target = event["server"]
|
target = event["server"]
|
||||||
if event["target"].get_setting("channel-quotes", False):
|
if event["target"].get_setting("channel-quotes", False):
|
||||||
target = event["target"]
|
target = event["target"]
|
||||||
|
|
||||||
quotes = self._get_quotes(target, line.sender)
|
quotes = self._get_quotes(target, target)
|
||||||
|
|
||||||
text = None
|
lines_str = []
|
||||||
|
for line in lines:
|
||||||
if line.action:
|
if line.action:
|
||||||
text = "* %s %s" % (line.sender, line.message)
|
lines_str.append("* %s %s" % (line.sender, line.message))
|
||||||
else:
|
else:
|
||||||
text = "<%s> %s" % (line.sender, line.message)
|
lines_str.append("<%s> %s" % (line.sender, line.message))
|
||||||
|
text = " ".join(lines_str)
|
||||||
|
|
||||||
quotes.append([event["user"].name, int(time.time()), text])
|
quotes.append([event["user"].name, int(time.time()), text])
|
||||||
self._set_quotes(target, line.sender, quotes)
|
self._set_quotes(target, line.sender, quotes)
|
||||||
|
|
Loading…
Reference in a new issue