update ducks.py to use command specs (and not docstrings)

This commit is contained in:
jesopo 2020-02-15 00:22:36 +00:00
parent 298493c3e4
commit aa02ba843c

View file

@ -94,11 +94,10 @@ class Module(ModuleManager.BaseModule):
stderr.write("%s: %s" % (user.nickname, message)) stderr.write("%s: %s" % (user.nickname, message))
@utils.hook("received.command.bef", alias_of="befriend") @utils.hook("received.command.bef", alias_of="befriend")
@utils.hook("received.command.befriend", channel_only=True) @utils.hook("received.command.befriend")
@utils.kwarg("help", "Befriend a duck")
@utils.spec("!-channelonly")
def befriend(self, event): def befriend(self, event):
"""
:help: Befriend a duck
"""
if event["target"].duck_active: if event["target"].duck_active:
action = self._duck_action(event["target"], event["user"], action = self._duck_action(event["target"], event["user"],
"befriended", "ducks-befriended") "befriended", "ducks-befriended")
@ -106,11 +105,10 @@ class Module(ModuleManager.BaseModule):
else: else:
self._no_duck(event["target"], event["user"], event["stderr"]) self._no_duck(event["target"], event["user"], event["stderr"])
@utils.hook("received.command.trap", channel_only=True) @utils.hook("received.command.trap")
@utils.kwarg("help", "Trap a duck")
@utils.spec("!-channelonly")
def trap(self, event): def trap(self, event):
"""
:help: Trap a duck
"""
if event["target"].duck_active: if event["target"].duck_active:
action = self._duck_action(event["target"], event["user"], action = self._duck_action(event["target"], event["user"],
"trapped", "ducks-shot") "trapped", "ducks-shot")
@ -118,34 +116,29 @@ class Module(ModuleManager.BaseModule):
else: else:
self._no_duck(event["target"], event["user"], event["stderr"]) self._no_duck(event["target"], event["user"], event["stderr"])
def _target(self, target, is_channel, query):
if query:
if not query == "*":
return query
elif is_channel:
return target.name
@utils.hook("received.command.friends") @utils.hook("received.command.friends")
@utils.kwarg("help", "Show top 10 duck friends")
@utils.spec("?<channel>word")
def friends(self, event): def friends(self, event):
""" query = self._target(event["target"], event["is_channel"],
:help: Show top 10 duck friends event["spec"][0])
:usage: [channel]
"""
query = None
if event["args"]:
if not event["args_split"][0] == "*":
query = event["args_split"][0]
elif event["is_channel"]:
query = event["target"].name
stats = self._top_duck_stats(event["server"], event["target"], stats = self._top_duck_stats(event["server"], event["target"],
"ducks-befriended", "friends", query) "ducks-befriended", "friends", query)
event["stdout"].write(stats) event["stdout"].write(stats)
@utils.hook("received.command.enemies") @utils.hook("received.command.enemies")
@utils.kwarg("help", "Show top 10 duck enemies")
@utils.spec("?<channel>word")
def enemies(self, event): def enemies(self, event):
""" query = self._target(event["target"], event["is_channel"],
:help: Show top 10 duck enemies event["spec"][0])
:usage: [channel]
"""
query = None
if event["args"]:
if not event["args_split"][0] == "*":
query = event["args_split"][0]
elif event["is_channel"]:
query = event["target"].name
stats = self._top_duck_stats(event["server"], event["target"], stats = self._top_duck_stats(event["server"], event["target"],
"ducks-shot", "enemies", query) "ducks-shot", "enemies", query)
@ -179,14 +172,10 @@ class Module(ModuleManager.BaseModule):
return nickname return nickname
@utils.hook("received.command.duckstats") @utils.hook("received.command.duckstats")
@utils.kwarg("help", "Get yours, or someone else's, duck stats")
@utils.spec("?<nickname>ouser")
def duckstats(self, event): def duckstats(self, event):
""" target_user = event["spec"][0] or event["user"]
:help: Get yours, or someone else's, duck stats
:usage: [nickname]
"""
target_user = event["user"]
if event["args"]:
target_user = event["server"].get_user(event["args_split"][0])
befs = target_user.get_channel_settings_per_setting( befs = target_user.get_channel_settings_per_setting(
"ducks-befriended") "ducks-befriended")