!qdel should be able to delete from channel-only quotes
This commit is contained in:
parent
5ff5b07c22
commit
bf9fadec77
1 changed files with 19 additions and 9 deletions
|
@ -14,10 +14,10 @@ class Module(ModuleManager.BaseModule):
|
||||||
return category, None
|
return category, None
|
||||||
return category, quote.strip()
|
return category, quote.strip()
|
||||||
|
|
||||||
def _get_quotes(self, server, category):
|
def _get_quotes(self, target, category):
|
||||||
return server.get_setting("quotes-%s" % category, [])
|
return target.get_setting("quotes-%s" % category, [])
|
||||||
def _set_quotes(self, server, category, quotes):
|
def _set_quotes(self, target, category, quotes):
|
||||||
server.set_setting("quotes-%s" % category, quotes)
|
target.set_setting("quotes-%s" % category, quotes)
|
||||||
|
|
||||||
@utils.hook("received.command.qadd", alias_of="quoteadd")
|
@utils.hook("received.command.qadd", alias_of="quoteadd")
|
||||||
@utils.hook("received.command.quoteadd", min_args=1)
|
@utils.hook("received.command.quoteadd", min_args=1)
|
||||||
|
@ -39,6 +39,9 @@ class Module(ModuleManager.BaseModule):
|
||||||
else:
|
else:
|
||||||
event["stderr"].write("Please provide a category AND quote")
|
event["stderr"].write("Please provide a category AND quote")
|
||||||
|
|
||||||
|
def _target_zip(self, target, quotes):
|
||||||
|
return [[u, t, q, target] for u, t, q in quotes]
|
||||||
|
|
||||||
@utils.hook("received.command.qdel", alias_of="quotedel")
|
@utils.hook("received.command.qdel", alias_of="quotedel")
|
||||||
@utils.hook("received.command.quotedel", min_args=1)
|
@utils.hook("received.command.quotedel", min_args=1)
|
||||||
@utils.kwarg("help", "Delete a given quote from a given category")
|
@utils.kwarg("help", "Delete a given quote from a given category")
|
||||||
|
@ -48,27 +51,34 @@ class Module(ModuleManager.BaseModule):
|
||||||
category = category or event["args"].strip()
|
category = category or event["args"].strip()
|
||||||
|
|
||||||
message = None
|
message = None
|
||||||
setting = "quotes-%s" % category
|
quotes = self._target_zip(event["server"],
|
||||||
quotes = event["server"].get_setting(setting, [])
|
self._get_quotes(event["server"], category))
|
||||||
|
if event["is_channel"]:
|
||||||
|
quotes += self._target_zip(event["target"],
|
||||||
|
self._get_quotes(event["target"], category))
|
||||||
|
quotes = sorted(quotes, key=lambda q: q[1])
|
||||||
|
|
||||||
if not quotes:
|
if not quotes:
|
||||||
raise utils.EventError("Quote category '%s' not found" %
|
raise utils.EventError("Quote category '%s' not found" %
|
||||||
category)
|
category)
|
||||||
|
|
||||||
|
found_target = None
|
||||||
if not remove_quote == None:
|
if not remove_quote == None:
|
||||||
remove_quote_lower = remove_quote.lower()
|
remove_quote_lower = remove_quote.lower()
|
||||||
for nickname, time_added, quote in quotes[:]:
|
for nickname, time_added, quote, target in quotes[:]:
|
||||||
if quote.lower() == remove_quote_lower:
|
if quote.lower() == remove_quote_lower:
|
||||||
quotes.remove([nickname, time_added, quote])
|
quotes.remove([nickname, time_added, quote])
|
||||||
|
found_target = target
|
||||||
message = "Removed quote from '%s'"
|
message = "Removed quote from '%s'"
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
if quotes:
|
if quotes:
|
||||||
quotes.pop(-1)
|
quote = quotes.pop(-1)
|
||||||
|
found_target = quote[-1]
|
||||||
message = "Removed last '%s' quote"
|
message = "Removed last '%s' quote"
|
||||||
|
|
||||||
if not message == None:
|
if not message == None:
|
||||||
event["server"].set_setting(setting, quotes)
|
self._set_quotes(found_target, category, quotes)
|
||||||
event["stdout"].write(message % category)
|
event["stdout"].write(message % category)
|
||||||
else:
|
else:
|
||||||
event["stderr"].write("Quote not found")
|
event["stderr"].write("Quote not found")
|
||||||
|
|
Loading…
Reference in a new issue