remove last quote if none is provided in !qdel

This commit is contained in:
jesopo 2019-07-11 20:47:39 +01:00
parent ab45c65fb4
commit d3f09c5618

View file

@ -62,23 +62,33 @@ class Module(ModuleManager.BaseModule):
:usage: <category> = <quote> :usage: <category> = <quote>
""" """
category, remove_quote = self.category_and_quote(event["args"]) category, remove_quote = self.category_and_quote(event["args"])
remove_quote_lower = remove_quote.lower() category = category or event["args"].strip()
if category and remove_quote:
setting = "quotes-%s" % category message = None
quotes = event["server"].get_setting(setting, []) setting = "quotes-%s" % category
removed = False quotes = event["server"].get_setting(setting, [])
if not quotes:
raise utils.EventError("Quote category '%s' not found" %
category)
if not remove_quote == None:
remove_quote_lower = remove_quote.lower()
for nickname, time_added, quote in quotes[:]: for nickname, time_added, quote 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])
removed = True message = "Removed quote from '%s'"
if removed: break
event["server"].set_setting(setting, quotes)
event["stdout"].write("Removed quote")
else:
event["stderr"].write("Quote not found")
else: else:
event["stderr"].write("Please provide a category and a quote " if quotes:
"to remove") quotes.pop(-1)
message = "Removed last '%s' quote"
if not message == None:
event["server"].set_setting(setting, quotes)
event["stdout"].write(message % category)
else:
event["stderr"].write("Quote not found")
@utils.hook("received.command.q", alias_of="quote") @utils.hook("received.command.q", alias_of="quote")
@utils.hook("received.command.quote", min_args=1) @utils.hook("received.command.quote", min_args=1)