aboutsummaryrefslogtreecommitdiff
path: root/modules/quotes.py
diff options
context:
space:
mode:
authorGravatar jesopo2019-01-26 15:55:20 +0000
committerGravatar jesopo2019-01-26 15:55:20 +0000
commit5b4954a96c3cd10ec0f614da2d59b3044541c59b (patch)
tree8d3d39b3d728596ccb2ad36ef2a4e17ab3899d9c /modules/quotes.py
parentAdd `find_from` to IRCBuffer.Buffer, to find the most recent line from a given (diff)
signature
add !quotegrab to take the last message from a user and quote it (quotes.py)
Diffstat (limited to 'modules/quotes.py')
-rw-r--r--modules/quotes.py24
1 files changed, 21 insertions, 3 deletions
diff --git a/modules/quotes.py b/modules/quotes.py
index ab3e4d18..6c8d55cf 100644
--- a/modules/quotes.py
+++ b/modules/quotes.py
@@ -7,6 +7,11 @@ class Module(ModuleManager.BaseModule):
return [part.strip() for part in s.split("=", 1)]
return None, None
+ def _get_quotes(self, server, category):
+ return server.get_setting("quotes-%s" % category, [])
+ def _set_quotes(self, server, category, quotes):
+ server.set_setting("quote-%s" % category, quotes)
+
@utils.hook("received.command.qadd", alias_of="quoteadd")
@utils.hook("received.command.quoteadd", min_args=1)
def quote_add(self, event):
@@ -16,10 +21,9 @@ class Module(ModuleManager.BaseModule):
"""
category, quote = self.category_and_quote(event["args"])
if category and quote:
- setting = "quotes-%s" % category
- quotes = event["server"].get_setting(setting, [])
+ quotes = self._get_quotes(event["server"], category)
quotes.append([event["user"].name, int(time.time()), quote])
- event["server"].set_setting(setting, quotes)
+ self._set_quotes(event["server"], quotes)
event["stdout"].write("Quote added")
else:
event["stderr"].write("Please provide a category AND quote")
@@ -89,3 +93,17 @@ class Module(ModuleManager.BaseModule):
event["stdout"].write("%s: %s" % (category, quote))
else:
event["stderr"].write("There are no quotes for this category")
+
+ @utils.hook("received.command.quotegrab", min_args=1, channel_only=True)
+ def quote_grab(self, event):
+ line = event["target"].buffer.find_from(event["args_split"][0])
+ if line:
+ quotes = self._get_quotes(event["server"], line.sender)
+ if line.action:
+ quotes.append("* %s %s" % (line.sender, line.message))
+ else:
+ quotes.append("<%s> %s" % (line.sender, line.message))
+ self._set_quotes(event["server"], quotes)
+ event["stdout"].write("Quote added")
+ else:
+ event["stderr"].write("Nothing found to quote")