diff options
53 files changed, 415 insertions, 276 deletions
diff --git a/modules/8ball.py b/modules/8ball.py index ebfb1b0c..60cdb261 100644 --- a/modules/8ball.py +++ b/modules/8ball.py @@ -29,10 +29,11 @@ CHOICES = [ ] class Module(ModuleManager.BaseModule): - @Utils.hook("received.command.8ball", min_args=1, usage="<question>") + @Utils.hook("received.command.8ball", min_args=1) def decide(selfs, event): """ - Ask the mystic 8ball a question! + :help: Ask the mystic 8ball a question! + :usage: <question> """ event["stdout"].write("You shake the magic ball... it " "says " + Utils.bold(random.choice(CHOICES))) diff --git a/modules/admin.py b/modules/admin.py index 1742758e..ac82dbcb 100644 --- a/modules/admin.py +++ b/modules/admin.py @@ -1,27 +1,31 @@ from src import ModuleManager, Utils class Module(ModuleManager.BaseModule): - @Utils.hook("received.command.changenickname", - permission="changenickname", min_args=1, usage="<nickname>") + @Utils.hook("received.command.changenickname", min_args=1) def change_nickname(self, event): """ - Change my nickname + :help: Change my nickname + :usage: <nickname> + :permission: changenickname """ nickname = event["args_split"][0] event["server"].send_nick(nickname) - @Utils.hook("received.command.raw", permission="raw", min_args=1, - usage="<raw line>") + @Utils.hook("received.command.raw", min_args=1) def raw(self, event): """ - Send a line of raw IRC data + :help: Send a line of raw IRC data + :usage: <raw line> + :permission: raw """ event["server"].send(event["args"]) - @Utils.hook("received.command.part", permission="part", usage="[#channel]") + @Utils.hook("received.command.part") def part(self, event): """ - Part from the current or given channel + :help: Part from the current or given channel + :usage: [channel] + :permission: part """ if event["args"]: target = event["args_split"][0] @@ -31,9 +35,10 @@ class Module(ModuleManager.BaseModule): event["stderr"].write("No channel provided") event["server"].send_part(target) - @Utils.hook("received.command.reconnect", permission="reconnect") + @Utils.hook("received.command.reconnect") def reconnect(self, event): """ - Reconnect to the current network + :help: Reconnect to the current network + :permission: reconnect """ event["server"].send_quit("Reconnecting") diff --git a/modules/auto_mode.py b/modules/auto_mode.py index d1851a58..ae233396 100644 --- a/modules/auto_mode.py +++ b/modules/auto_mode.py @@ -51,32 +51,36 @@ class Module(ModuleManager.BaseModule): event["stdout"].write("Removed automode %s from '%s'" % ( mode_name, target_user.nickname)) - @Utils.hook("received.command.addop", require_mode="o", min_args=1, - channel_only=True, usage="<nickname>") + @Utils.hook("received.command.addop", min_args=1, channel_only=True) def add_op(self, event): """ - Add a user to the auto-mode list as an op + :help: Add a user to the auto-mode list as an op + :usage: <nickname> + :require_mode: o """ self._add_mode(event, "o", "op") - @Utils.hook("received.command.removeop", require_mode="o", min_args=1, - channel_only=True, usage="<nickname>") + @Utils.hook("received.command.removeop", min_args=1, channel_only=True) def remove_op(self, event): """ - Remove a user from the auto-mode list as an op + :help: Remove a user from the auto-mode list as an op + :usage: <nickname> + :require_mode: o """ self._remove_mode(event, "o", "op") - @Utils.hook("received.command.addvoice", require_mode="o", min_args=1, - channel_only=True, usage="<nickname>") + @Utils.hook("received.command.addvoice", min_args=1, channel_only=True) def add_voice(self, event): """ - Add a user to the auto-mode list as a voice + :help: Add a user to the auto-mode list as a voice + :usage: <nickname> + :require_mode: o """ self._add_mode(event, "v", "voice") - @Utils.hook("received.command.removevoice", require_mode="o", min_args=1, - channel_only=True, usage="<nickname>") + @Utils.hook("received.command.removevoice", min_args=1, channel_only=True) def remove_voice(self, event): """ - Remove a user from the auto-mode list as anvoice + :help: Remove a user from the auto-mode list as a voice + :usage: <nickname> + :require_mode: o """ self._remove_mode(event, "v", "voice") diff --git a/modules/bitcoin.py b/modules/bitcoin.py index 1c88c0bb..07678d68 100644 --- a/modules/bitcoin.py +++ b/modules/bitcoin.py @@ -3,10 +3,11 @@ from src import ModuleManager, Utils class Module(ModuleManager.BaseModule): _name = "BTC" - @Utils.hook("received.command.btc", usage="[currency]") + @Utils.hook("received.command.btc") def btc(self, event): """ - Get the exchange rate of bitcoins + :help: Get the exchange rate of bitcoins + :usage: [currency] """ currency = (event["args"] or "USD").upper() page = Utils.get_url("https://blockchain.info/ticker", diff --git a/modules/books.py b/modules/books.py index 7a0204a6..e3642198 100644 --- a/modules/books.py +++ b/modules/books.py @@ -36,10 +36,11 @@ class Module(ModuleManager.BaseModule): else: event["stderr"].write("Failed to load results") - @Utils.hook("received.command.isbn", min_args=1, usage="<isbn>") + @Utils.hook("received.command.isbn", min_args=1) def isbn(self, event): """ - Get book information from a provided ISBN + :help: Get book information from a provided ISBN + :usage: <isbn> """ isbn = event["args_split"][0] if len(isbn) == 10: @@ -47,9 +48,10 @@ class Module(ModuleManager.BaseModule): isbn = isbn.replace("-", "") self.get_book("isbn:%s" % isbn, event) - @Utils.hook("received.command.book", min_args=1, usage="<book title>") + @Utils.hook("received.command.book", min_args=1) def book(self, event): """ - Get book information from a provided title + :help: Get book information from a provided title + :usage: <book title> """ self.get_book(event["args"], event) diff --git a/modules/channel_op.py b/modules/channel_op.py index a93d1137..49d9682c 100644 --- a/modules/channel_op.py +++ b/modules/channel_op.py @@ -33,11 +33,12 @@ class Module(ModuleManager.BaseModule): else: raise UserNotFoundException("That user is not in this channel") - @Utils.hook("received.command.kick|k", channel_only=True, - require_mode="o", usage="<nickname> [reason]", min_args=1) + @Utils.hook("received.command.kick|k", channel_only=True, min_args=1) def kick(self, event): """ - Kick a user from the current channel + :help: Kick a user from the current channel + :usage: <nickname> [reason] + :require_mode: o """ target = event["args_split"][0] reason = " ".join(event["args_split"][1:]) or None @@ -76,11 +77,12 @@ class Module(ModuleManager.BaseModule): event["target"].send_unban(target) return target - @Utils.hook("received.command.ban", channel_only=True, min_args=1, - require_mode="o", usage="<nickname/hostmask>") + @Utils.hook("received.command.ban", channel_only=True, min_args=1) def ban(self, event): """ - Ban a user/hostmask from the current channel + :help: Ban a user/hostmask from the current channel + :usage: <nickname/hostmask> + :require_mode: o """ self._ban(event["server"], event["target"], True, event["args_split"][0]) @@ -101,17 +103,26 @@ class Module(ModuleManager.BaseModule): self.bot.timers.add_persistent("unban", timeout, server_id=event["server"].id, channel_name=event["target"].name, hostmask=hostmask) - @Utils.hook("received.command.tempban|tban|tb", channel_only=True, - min_args=2, require_mode="o", usage="<nickname/hostmask>") + @Utils.hook("received.command.tempban|tb", channel_only=True, min_args=2) def temp_ban(self, event): + """ + :help: Temporarily ban someone from the current channel + :usage: <nickname/hostmask> + :require_mode: o + """ try: self._temp_ban(event, True) except InvalidTimeoutException as e: event["stderr"].set_prefix("Tempban") event["stderr"].write(str(e)) - @Utils.hook("received.command.tempkickban|tkban|tkb", channel_only=True, - min_args=2, require_mode="o", usage="<nickname/hostmask>") + @Utils.hook("received.command.tempkickban|tkb", channel_only=True, + min_args=2) def temp_kick_ban(self, event): + """ + :help: Temporarily kick and ban someone from the current channel + :usage: <nickname> + :require_mode: o + """ reason = " ".join(event["args_split"][2:]) or None event["stderr"].set_prefix("TKB") try: @@ -123,20 +134,22 @@ class Module(ModuleManager.BaseModule): except UserNotFoundException as e: event["stderr"].write(str(e)) - @Utils.hook("received.command.unban", channel_only=True, min_args=1, - require_mode="o", usage="<nickname/hostmask>") + @Utils.hook("received.command.unban", channel_only=True, min_args=1) def unban(self, event): """ - Unban a user/hostmask from the current channel + :help: Unban a user/hostmask from the current channel + :usage: <nickname/hostmask> + :require_mode: o """ self._ban(event["server"], event["target"], False, event["args_split"][0]) - @Utils.hook("received.command.kickban|kb", channel_only=True, - require_mode="o", usage="<nickname> [reason]", min_args=1) + @Utils.hook("received.command.kickban|kb", channel_only=True, min_args=1) def kickban(self, event): """ - Kick and ban a user from the current channel + :help: Kick and ban a user from the current channel + :usage: <nickname> [reason] + :require_mode: o """ target = event["args_split"][0] reason = " ".join(event["args_split"][1:]) or None @@ -147,56 +160,62 @@ class Module(ModuleManager.BaseModule): event["stderr"].set_prefix("Kickban") event["stderr"].write(str(e)) - @Utils.hook("received.command.op", channel_only=True, - require_mode="o", usage="[nickname]") + @Utils.hook("received.command.op", channel_only=True) def op(self, event): """ - Op a user in the current channel + :help: Op a user in the current channel + :usage: [nickname] + :require_mode: o """ target = event["user"].nickname if not event["args_split"] else event[ "args_split"][0] event["target"].send_mode("+o", target) - @Utils.hook("received.command.deop", channel_only=True, - require_mode="o", usage="[nickname]") + @Utils.hook("received.command.deop", channel_only=True) def deop(self, event): """ - Remove op from a user in the current channel + :help: Remove op from a user in the current channel + :usage: [nickname] + :require_mode: o """ target = event["user"].nickname if not event["args_split"] else event[ "args_split"][0] event["target"].send_mode("-o", target) - @Utils.hook("received.command.voice", channel_only=True, - require_mode="o", usage="[nickname]") + @Utils.hook("received.command.voice", channel_only=True) def voice(self, event): """ - Voice a user in the current channel + :help: Voice a user in the current channel + :usage: [nickname] + :require_mode: o """ target = event["user"].nickname if not event["args_split"] else event[ "args_split"][0] event["target"].send_mode("+v", target) - @Utils.hook("received.command.devoice", channel_only=True, - require_mode="o", usage="[nickname]") + @Utils.hook("received.command.devoice", channel_only=True) def devoice(self, event): """ - Remove voice from a user in the current channel + :help: Remove voice from a user in the current channel + :usage: [nickname] + :require_mode: o """ target = event["user"].nickname if not event["args_split"] else event[ "args_split"][0] event["target"].send_mode("-v", target) - @Utils.hook("received.command.topic", min_args=1, require_mode="o", - channel_only=True, usage="<topic>") + @Utils.hook("received.command.topic", min_args=1, channel_only=True) def topic(self, event): """ - Set the topic in the current channel + :help: Set the topic in the current channel + :usage: <topic> + :require_mode: o """ event["target"].send_topic(event["args"]) - @Utils.hook("received.command.tappend", min_args=1, require_mode="o", - channel_only=True, usage="<topic>") + @Utils.hook("received.command.tappend", min_args=1, channel_only=True) def tappend(self, event): """ - Append to the topic in the current channel + :help: Append to the topic in the current channel + :usage: <topic> + :require_mode: o """ event["target"].send_topic(event["target"].topic + event["args"]) diff --git a/modules/check_mode.py b/modules/check_mode.py index 2d0298b6..953b04e9 100644 --- a/modules/check_mode.py +++ b/modules/check_mode.py @@ -1,11 +1,11 @@ + from src import ModuleManager, Utils class Module(ModuleManager.BaseModule): @Utils.hook("preprocess.command") def preprocess_command(self, event): - if event["is_channel"] and event["hook"].kwargs.get( - "require_mode"): - required_mode = event["hook"].kwargs.get("require_mode")[0] + require_mode = event["hook"].get_kwarg("require_mode") + if event["is_channel"] and require_mode: if not event["target"].mode_or_above(event["user"], required_mode): return "You do not have permission to do this" diff --git a/modules/coins.py b/modules/coins.py index 4e0f966e..a27755d3 100644 --- a/modules/coins.py +++ b/modules/coins.py @@ -39,7 +39,7 @@ class Module(object): @Utils.hook("received.command.coins") def coins(self, event): """ - Show how many coins you have + :help: Show how many coins you have """ if event["args_split"]: target = event["server"].get_user(event["args_split"][0]) @@ -49,11 +49,12 @@ class Module(object): event["stdout"].write("%s has %s coin%s" % (target.nickname, "{0:.2f}".format(coins), "" if coins == 1 else "s")) - @Utils.hook("received.command.resetcoins", permission="resetcoins", - min_args=1, usage="<target>") + @Utils.hook("received.command.resetcoins", min_args=1) def reset_coins(self, event): """ - Reset a user's coins to 0 + :help: Reset a user's coins to 0 + :usage: <target> + :permission: resetcoins """ target = event["server"].get_user(event["args_split"][0]) coins = decimal.Decimal(target.get_setting("coins", "0.0")) @@ -64,11 +65,12 @@ class Module(object): target.del_setting("coins") event["stdout"].write("Reset coins for %s" % target.nickname) - @Utils.hook("received.command.givecoins", min_args=1, - usage="<nickname> <coins>", permission="givecoins") + @Utils.hook("received.command.givecoins", min_args=1) def give_coins(self, event): """ - Give coins to a user + :help: Give coins to a user + :usage: <nickname> <coins> + :permission: givecoins """ target = event["server"].get_user(event["args_split"][0]) coins = event["args_split"][1] @@ -86,7 +88,7 @@ class Module(object): @Utils.hook("received.command.richest") def richest(self, event): """ - Show the top 10 richest users + :help: Show the top 10 richest users """ all_coins = event["server"].get_all_user_settings("coins", []) all_coins = list(filter(lambda coin: decimal.Decimal(coin[1]), @@ -107,7 +109,7 @@ class Module(object): @Utils.hook("received.command.redeemcoins") def redeem_coins(self, event): """ - Redeem your free coins + :help: Redeem your free coins """ user_coins = decimal.Decimal(event["user"].get_setting( "coins", "0.0")) @@ -132,11 +134,11 @@ class Module(object): event["stderr"].write( "You can only redeem coins when you have none") - @Utils.hook("received.command.flip", usage="heads|tails <coin amount>", - min_args=2, authenticated=True) + @Utils.hook("received.command.flip", min_args=2, authenticated=True) def flip(self, event): """ - Bet on a coin flip + :help: Bet on a coin flip + :usage: heads|tails <coin amount> """ side_name = event["args_split"][0].lower() coin_bet = event["args_split"][1].lower() @@ -176,11 +178,11 @@ class Module(object): event["user"].nickname, side_name, coin_bet_str, "" if coin_bet == 1 else "s")) - @Utils.hook("received.command.sendcoins", min_args=2, - usage="<nickname> <amount>", authenticated=True) + @Utils.hook("received.command.sendcoins", min_args=2, authenticated=True) def send(self, event): """ - Send coins to another user + :help: Send coins to another user + :usage: <nickname> <amount> """ if event["user"].get_id() == event["server"].get_user(event[ "args_split"][0]).get_id(): @@ -245,11 +247,11 @@ class Module(object): str(coins)) event["timer"].redo() - @Utils.hook("received.command.roulette", min_args=2, - usage="<type> <amount>", authenticated=True) + @Utils.hook("received.command.roulette", min_args=2, authenticated=True) def roulette(self, event): """ - Spin a roulette wheel + :help: Spin a roulette wheel + :usage: <type> <amount> """ bets = event["args_split"][0].lower().split(",") if "0" in bets: diff --git a/modules/commands.py b/modules/commands.py index faa9740f..e58697a7 100644 --- a/modules/commands.py +++ b/modules/commands.py @@ -151,12 +151,15 @@ class Module(ModuleManager.BaseModule): self.message(event, command) def _get_help(self, hook): - return hook.kwargs.get("help", None) or hook.function.__doc__ + return hook.get_kwarg("help", None) or hook.docstring.description + def _get_usage(self, hook): + return hook.get_kwarg("usage", None) - @Utils.hook("received.command.help", usage="<command>") + @Utils.hook("received.command.help") def help(self, event): """ - Show help for a given command + :help: Show help for a given command + :usage: [command] """ if event["args"]: command = event["args_split"][0].lower() @@ -166,11 +169,6 @@ class Module(ModuleManager.BaseModule): help = self._get_help(hooks[0]) if help: - help = [line.strip() for line in help.split("\n")] - help = [line.strip() for line in help] - help = filter(None, help) - help = " ".join(help) - event["stdout"].write("%s: %s" % (command, help)) else: event["stderr"].write("No help available for %s" % command) @@ -186,10 +184,11 @@ class Module(ModuleManager.BaseModule): help_available = sorted(help_available) event["stdout"].write("Commands: %s" % ", ".join(help_available)) - @Utils.hook("received.command.usage", min_args=1, usage="<command>") + @Utils.hook("received.command.usage", min_args=1) def usage(self, event): """ - Show the usage for a given command + :help: Show the usage for a given command + :usage: <command> """ command_prefix = "" if event["is_channel"]: @@ -200,9 +199,11 @@ class Module(ModuleManager.BaseModule): if command in self.events.on("received").on( "command").get_children(): hooks = self.events.on("received.command").on(command).get_hooks() - if hooks and "usage" in hooks[0].kwargs: + usage = self._get_usage(hooks[0]) + + if usage: event["stdout"].write("Usage: %s%s %s" % (command_prefix, - command, hooks[0].kwargs["usage"])) + command, usage)) else: event["stderr"].write("No usage help available for %s" % command) else: @@ -211,16 +212,17 @@ class Module(ModuleManager.BaseModule): @Utils.hook("received.command.more", skip_out=True) def more(self, event): """ - Show more output from the last command + :help: Show more output from the last command """ if event["target"].last_stdout and event["target"].last_stdout.has_text(): event["target"].last_stdout.send() - @Utils.hook("received.command.ignore", min_args=1, usage="<nickname>", - permission="ignore") + @Utils.hook("received.command.ignore", min_args=1) def ignore(self, event): """ - Ignore commands from a given user + :help: Ignore commands from a given user + :usage: <nickname> + :permission: ignore """ user = event["server"].get_user(event["args_split"][0]) if user.get_setting("ignore", False): @@ -230,11 +232,12 @@ class Module(ModuleManager.BaseModule): user.set_setting("ignore", True) event["stdout"].write("Now ignoring '%s'" % user.nickname) - @Utils.hook("received.command.unignore", min_args=1, usage="<nickname>", - permission="unignore") + @Utils.hook("received.command.unignore", min_args=1) def unignore(self, event): """ - Unignore commands from a given user + :help: Unignore commands from a given user + :usage: <nickname> + :permission: unignore """ user = event["server"].get_user(event["args_split"][0]) if not user.get_setting("ignore", False): diff --git a/modules/define.py b/modules/define.py index 315099fe..dbd1e420 100644 --- a/modules/define.py +++ b/modules/define.py @@ -19,10 +19,11 @@ class Module(ModuleManager.BaseModule): return page - @Utils.hook("received.command.define", usage="<phrase>") + @Utils.hook("received.command.define") def define(self, event): """ - Define a provided term + :help: Define a provided term + :usage: <phrase> """ if event["args"]: word = event["args"] @@ -42,7 +43,7 @@ class Module(ModuleManager.BaseModule): @Utils.hook("received.command.randomword") def random_word(self, event): """ - Define a random word + :help: Define a random word """ if not self._last_called or (time.time()-self._last_called >= RANDOM_DELAY_SECONDS): diff --git a/modules/dice.py b/modules/dice.py index cb48efae..ee93f570 100644 --- a/modules/dice.py +++ b/modules/dice.py @@ -4,10 +4,11 @@ from src import ModuleManager, Utils ERROR_FORMAT = "Incorrect format! Format must be [number]d[number], e.g. 1d20" class Module(ModuleManager.BaseModule): - @Utils.hook("received.command.roll", min_args=1, usage="[1-5]d[1-20]") + @Utils.hook("received.command.roll", min_args=1) def roll_dice(self, event): """ - Roll some dice, DND style! + :help: Roll some dice, DND style! + :usage: [1-5]d[1-20] """ raw_input = event["args_split"][0] roll = raw_input.split("d") diff --git a/modules/dns.py b/modules/dns.py index 19ef7ea0..aa00b870 100644 --- a/modules/dns.py +++ b/modules/dns.py @@ -4,10 +4,11 @@ from src import ModuleManager, Utils class Module(ModuleManager.BaseModule): _name = "DNS" - @Utils.hook("received.command.dns", min_args=1, usage="<hostname>") + @Utils.hook("received.command.dns", min_args=1) def dns(self, event): """ - Get all addresses for a given hostname (IPv4/IPv6) + :help: Get all addresses for a given hostname (IPv4/IPv6) + :usage: <hostname> """ hostname = event["args_split"][0] try: diff --git a/modules/ducks.py b/modules/ducks.py index 84e22942..296f6430 100644 --- a/modules/ducks.py +++ b/modules/ducks.py @@ -119,7 +119,7 @@ class Module(object): @Utils.hook("received.command.decoy") def duck_decoy(self, event): """ - Prepare a decoy duck + :help: Prepare a decoy duck """ channel = event["target"] if self.is_duck_channel(channel) == False: @@ -225,7 +225,7 @@ class Module(object): @Utils.hook("received.command.bef") def befriend(self, event): """ - Befriend a duck + :help: Befriend a duck """ channel = event["target"] user = event["user"] @@ -263,7 +263,7 @@ class Module(object): @Utils.hook("received.command.bang") def shoot(self, event): """ - Shoot a duck + :help: Shoot a duck """ channel = event["target"] user = event["user"] @@ -302,7 +302,7 @@ class Module(object): @Utils.hook("received.command.duckstats") def duck_stats(self, event): """ - Show your duck stats + :help: Show your duck stats """ user = event["user"] channel = event["target"].name @@ -347,7 +347,7 @@ class Module(object): @Utils.hook("received.command.killers") def duck_enemies(self, event): """ - Show the top duck shooters + :help: Show the top duck shooters """ the_enemy = event["server"].find_all_user_channel_settings("ducks-shot") @@ -385,7 +385,7 @@ class Module(object): @Utils.hook("received.command.friends") def duck_friends(self, event): """ - Show the top duck friends + :help: Show the top duck friends """ friends = event["server"].find_all_user_channel_settings( "ducks-befriended") diff --git a/modules/eval.py b/modules/eval.py index 3db6bd3e..72131f70 100644 --- a/modules/eval.py +++ b/modules/eval.py @@ -4,10 +4,11 @@ from src import ModuleManager, Utils EVAL_URL = "https://eval.appspot.com/eval" class Module(ModuleManager.BaseModule): - @Utils.hook("received.command.eval", min_args=1, usage="<statement>") + @Utils.hook("received.command.eval", min_args=1) def eval(self, event): """ - Evaluate a python statement + :help: Evaluate a python statement + :usage: <statement> """ try: code, page = Utils.get_url(EVAL_URL, get_params={ diff --git a/modules/geoip.py b/modules/geoip.py index f20df6aa..38cc6043 100644 --- a/modules/geoip.py +++ b/modules/geoip.py @@ -5,10 +5,11 @@ URL_GEOIP = "http://ip-api.com/json/%s" class Module(ModuleManager.BaseModule): _name = "GeoIP" - @Utils.hook("received.command.geoip", min_args=1, usage="<IP>") + @Utils.hook("received.command.geoip", min_args=1) def geoip(self, event): """ - Get geoip data on a given IPv4/IPv6 address + :help: Get geoip data on a given IPv4/IPv6 address + :usage: <IP> """ page = Utils.get_url(URL_GEOIP % event["args_split"][0], json=True) diff --git a/modules/google.py b/modules/google.py index f6d8469c..e30e6cda 100644 --- a/modules/google.py +++ b/modules/google.py @@ -8,10 +8,11 @@ URL_GOOGLESEARCH = "https://www.googleapis.com/customsearch/v1" URL_GOOGLESUGGEST = "http://google.com/complete/search" class Module(ModuleManager.BaseModule): - @Utils.hook("received.command.google|g", usage="[search term]") + @Utils.hook("received.command.google|g") def google(self, event): """ - Get first Google result for a given search term + :help: Get first Google result for a given search term + :usage: [search term] """ phrase = event["args"] or event["target"].buffer.get() if phrase: diff --git a/modules/hash.py b/modules/hash.py index 4508d613..04b2f99c 100644 --- a/modules/hash.py +++ b/modules/hash.py @@ -2,10 +2,11 @@ import hashlib from src import ModuleManager, Utils class Module(ModuleManager.BaseModule): - @Utils.hook("received.command.hash", min_args=2, usage="<algo> <string>") + @Utils.hook("received.command.hash", min_args=2) def hash(self, event): """ - Hash a given string with a given algorithm + :help: Hash a given string with a given algorithm + :usage: <algo> <string> """ algorithm = event["args_split"][0].lower() if algorithm in hashlib.algorithms_available: diff --git a/modules/haveibeenpwned.py b/modules/haveibeenpwned.py index 0a328c3e..62566823 100644 --- a/modules/haveibeenpwned.py +++ b/modules/haveibeenpwned.py @@ -4,12 +4,12 @@ URL_HAVEIBEENPWNEDAPI = "https://haveibeenpwned.com/api/v2/breachedaccount/%s" URL_HAVEIBEENPWNED = "https://haveibeenpwned.com/" class Module(ModuleManager.BaseModule): - @Utils.hook("received.command.beenpwned", usage="<username/email>", - min_args=1) + @Utils.hook("received.command.beenpwned", min_args=1) def beenpwned(self, event): """ - Find out if a username, email or similar has appeared in any - hacked databases + :help: Find out if a username, email or similar has appeared in any + hacked databases + :usage: <username/email> """ page = Utils.get_url(URL_HAVEIBEENPWNEDAPI % event["args"], json=True, code=True) diff --git a/modules/ids.py b/modules/ids.py index fb81f492..8a71c7f5 100644 --- a/modules/ids.py +++ b/modules/ids.py @@ -6,7 +6,7 @@ class Module(ModuleManager.BaseModule): @Utils.hook("received.command.myid") def my_id(self, event): """ - Show your user ID + :help: Show your user ID """ event["stdout"].write("%s: %d" % (event["user"].nickname, event["user"].get_id())) @@ -14,7 +14,7 @@ class Module(ModuleManager.BaseModule): @Utils.hook("received.command.channelid", channel_only=True) def channel_id(self, event): """ - Show the current channel's ID + :help: Show the current channel's ID """ event["stdout"].write("%s: %d" % (event["target"].name, event["target"].id)) diff --git a/modules/imdb.py b/modules/imdb.py index 1d3a8ab5..a584a9e4 100644 --- a/modules/imdb.py +++ b/modules/imdb.py @@ -9,10 +9,11 @@ URL_IMDBTITLE = "http://imdb.com/title/%s" class Module(ModuleManager.BaseModule): _name = "IMDb" - @Utils.hook("received.command.imdb", min_args=1, usage="<movie/tv title>") + @Utils.hook("received.command.imdb", min_args=1) def imdb(self, event): """ - Search for a given title on IMDb + :help: Search for a given title on IMDb + :usage: <movie/tv title> """ page = Utils.get_url(URL_OMDB, get_params={ "t": event["args"], diff --git a/modules/in.py b/modules/in.py index 7fb7d7ea..f237bee6 100644 --- a/modules/in.py +++ b/modules/in.py @@ -5,10 +5,11 @@ SECONDS_MAX = Utils.SECONDS_WEEKS*8 SECONDS_MAX_DESCRIPTION = "8 weeks" class Module(ModuleManager.BaseModule): - @Utils.hook("received.command.in", min_args=2, usage="<time> <message>") + @Utils.hook("received.command.in", min_args=2) def in_command(self, event): """ - Set a reminder + :help: Set a reminder + :usage: <time> <message> """ seconds = Utils.from_pretty_time(event["args_split"][0]) message = " ".join(event["args_split"][1:]) diff --git a/modules/isgd.py b/modules/isgd.py index f55f17a7..ba7c5618 100644 --- a/modules/isgd.py +++ b/modules/isgd.py @@ -18,10 +18,11 @@ class Module(ModuleManager.BaseModule): if data and data["shorturl"]: return data["shorturl"] - @Utils.hook("received.command.shorten", min_args=1, usage="<url>") + @Utils.hook("received.command.shorten", min_args=1) def shorten(self, event): """ - Shorten a given URL using the is.gd service + :help: Shorten a given URL using the is.gd service + :usage: <url> """ link = self.events.on("get.shortlink").call_for_result( url=event["args"]) diff --git a/modules/karma.py b/modules/karma.py index 7191a90e..d2982765 100644 --- a/modules/karma.py +++ b/modules/karma.py @@ -48,10 +48,11 @@ class Module(ModuleManager.BaseModule): target=event["channel"], message="Try again in a couple of seconds") - @Utils.hook("received.command.karma", usage="[target]") + @Utils.hook("received.command.karma") def karma(self, event): """ - Get your or someone else's karma + :help: Get your or someone else's karma + :usage: [target] """ if event["args"]: target = event["args"] @@ -60,11 +61,12 @@ class Module(ModuleManager.BaseModule): karma = event["server"].get_setting("karma-%s" % target, 0) event["stdout"].write("%s has %s karma" % (target, karma)) - @Utils.hook("received.command.resetkarma", permission="resetkarma", - min_args=1, usage="<target>") + @Utils.hook("received.command.resetkarma", min_args=1) def reset_karma(self, event): """ - Reset a specified karma to 0 + :help: Reset a specified karma to 0 + :usage: <target> + :permission: resetkarme """ setting = "karma-%s" % event["args_split"][0] karma = event["server"].get_setting(setting, 0) diff --git a/modules/lastfm.py b/modules/lastfm.py index d02abd6f..8febe3c0 100644 --- a/modules/lastfm.py +++ b/modules/lastfm.py @@ -9,10 +9,11 @@ URL_SCROBBLER = "http://ws.audioscrobbler.com/2.0/" class Module(ModuleManager.BaseModule): _name = "last.fm" - @Utils.hook("received.command.np|listening|nowplaying", usage="[username]") + @Utils.hook("received.command.np|listening|nowplaying") def np(self, event): """ - Get the last listened to track from a user + :help: Get the last listened to track from a user + :usage: [username] """ if event["args_split"]: lastfm_username = event["args_split"][0] diff --git a/modules/modules.py b/modules/modules.py index 33ba140a..eaa0f2dd 100644 --- a/modules/modules.py +++ b/modules/modules.py @@ -1,11 +1,12 @@ from src import ModuleManager, Utils class Module(ModuleManager.BaseModule): - @Utils.hook("received.command.loadmodule", min_args=1, - permission="load-module", usage="<module-name>") + @Utils.hook("received.command.loadmodule", min_args=1) def load(self, event): """ - Load a module + :help: Load a module + :usage: <module name> + :permission: load-module """ name = event["args_split"][0].lower() if name in self.bot.modules.modules: @@ -14,11 +15,12 @@ class Module(ModuleManager.BaseModule): self.bot.modules.load_module(self.bot, name) event["stdout"].write("Loaded '%s'" % name) - @Utils.hook("received.command.unloadmodule", min_args=1, - permission="unload-module", usage="<module-name>") + @Utils.hook("received.command.unloadmodule", min_args=1) def unload(self, event): """ - Unload a module + :help: Unload a module + :usage: <module name> + :permission: unload-module """ name = event["args_split"][0].lower() if not name in self.bot.modules.modules: @@ -31,11 +33,12 @@ class Module(ModuleManager.BaseModule): self.bot.modules.unload_module(name) self.bot.modules.load_module(self.bot, name) - @Utils.hook("received.command.reloadmodule", min_args=1, - permission="reload-module", usage="<module-name>") + @Utils.hook("received.command.reloadmodule", min_args=1) def reload(self, event): """ - Reload a module + :help: Reload a module + :usage: <module name> + :permission: reload-module """ name = event["args_split"][0].lower() try: @@ -53,10 +56,11 @@ class Module(ModuleManager.BaseModule): return event["stdout"].write("Reloaded '%s'" % name) - @Utils.hook("received.command.reloadallmodules", permission="reload-module") + @Utils.hook("received.command.reloadallmodules") def reload_all(self, event): """ - Reload all modules + :help: Reload all modules + :permission: reload-all-modules """ reloaded = [] failed = [] @@ -78,11 +82,12 @@ class Module(ModuleManager.BaseModule): else: event["stdout"].write("Reloaded %d modules" % len(reloaded)) - @Utils.hook("received.command.enablemodule", min_args=1, - permission="enable-module", usage="<module-name>") + @Utils.hook("received.command.enablemodule", min_args=1) def enable(self, event): """ - Remove a module from the module blacklist + :help: Remove a module from the module blacklist + :usage: <module name> + :permission: enable-module """ name = event["args_split"][0].lower() blacklist = self.bot.get_setting("module-blacklist", []) @@ -94,11 +99,12 @@ class Module(ModuleManager.BaseModule): event["stdout"].write("Module '%s' has been enabled and can now " "be loaded" % name) - @Utils.hook("received.command.disablemodule", min_args=1, - permission="disable-module", usage="<module-name>") + @Utils.hook("received.command.disablemodule", min_args=1) def disable(self, event): """ - Add a module to the module blacklist + :help: Add a module to the module blacklist + :usage: <module name> + :permission: disable-module """ name = event["args_split"][0].lower() and_unloaded = "" diff --git a/modules/nr.py b/modules/nr.py index ee0f3379..ab9e5dfd 100644 --- a/modules/nr.py +++ b/modules/nr.py @@ -112,10 +112,11 @@ class Module(ModuleManager.BaseModule): def reduced_activities(self, string): return [a for a in self.activities(string) if a in self.PASSENGER_ACTIVITIES] @Utils.hook("telegram.command.nrtrains") - @Utils.hook("received.command.nrtrains", min_args=1, usage="<crs_id>") + @Utils.hook("received.command.nrtrains", min_args=1) def trains(self, event): """ - Get train/bus services for a station (Powered by NRE) + :help: Get train/bus services for a station (Powered by NRE) + :usage: <crs_id> """ client = self.client @@ -292,11 +293,12 @@ class Module(ModuleManager.BaseModule): event["stdout"].write("%s%s: %s" % (station_summary, " departures calling at %s" % filter["inter"] if filter["inter"] else '', trains_string)) @Utils.hook("telegram.command.nrservice") - @Utils.hook("received.command.nrservice", min_args=1, usage="<service_id>") + @Utils.hook("received.command.nrservice", min_args=1) def service(self, event): """ - Get train service information for a UID, headcode or RID - (Powered by NRE) + :help: Get train service information for a UID, headcode or RID + (Powered by NRE) + :usage: <service_id> """ client = self.client colours = self.COLOURS @@ -487,10 +489,11 @@ class Module(ModuleManager.BaseModule): ", ".join([s["summary"] for s in stations_filtered]))) @Utils.hook("telegram.command.nrhead") - @Utils.hook("received.command.nrhead", min_args=1, usage="<headcode>") + @Utils.hook("received.command.nrhead", min_args=1) def head(self, event): """ - Get information for a given headcode/UID/RID (Powered by NRE) + :help: Get information for a given headcode/UID/RID (Powered by NRE) + :usage: <headcode> """ client = self.client service_id = event["args_split"][0] @@ -508,10 +511,11 @@ class Module(ModuleManager.BaseModule): event["stdout"].write(", ".join(["h/%s r/%s u/%s rs/%s %s (%s) -> %s (%s)" % (a["trainid"], a["rid"], a["uid"], a["rsid"], a["originName"], a["originCrs"], a["destinationName"], a["destinationCrs"]) for a in services])) @Utils.hook("telegram.command.nrcode") - @Utils.hook("received.command.nrcode", min_args=1, usage="<code>") + @Utils.hook("received.command.nrcode", min_args=1) def service_code(self, event): """ - Get the text for a given delay/cancellation code (Powered by NRE) + :help: Get the text for a given delay/cancellation code (Powered by NRE) + :usage: <code> """ client = self.client diff --git a/modules/permissions.py b/modules/permissions.py index dde6b441..57b667d1 100644 --- a/modules/permissions.py +++ b/modules/permissions.py @@ -38,11 +38,11 @@ class Module(ModuleManager.BaseModule): user.identified_account_override = None user.identified_account_id_override = None - @Utils.hook("received.command.identify", private_only=True, min_args=1, - usage="[account] <password>") + @Utils.hook("received.command.identify", private_only=True, min_args=1) def identify(self, event): """ - Identify yourself + :help: Identify yourself + :usage: [account] <password> """ identity_mechanism = event["server"].get_setting("identity-mechanism", "internal") @@ -80,11 +80,11 @@ class Module(ModuleManager.BaseModule): else: event["stderr"].write("You are already identified") - @Utils.hook("received.command.register", private_only=True, min_args=1, - usage="<password>") + @Utils.hook("received.command.register", private_only=True, min_args=1) def register(self, event): """ - Register yourself + :help: Register yourself + :usage: <password> """ identity_mechanism = event["server"].get_setting("identity-mechanism", "internal") @@ -107,7 +107,7 @@ class Module(ModuleManager.BaseModule): @Utils.hook("received.command.logout", private_only=True) def logout(self, event): """ - Logout from your identified account + :help: Logout from your identified account """ if event["user"].identified_account_override: self._logout(event["user"]) @@ -116,10 +116,12 @@ class Module(ModuleManager.BaseModule): event["stderr"].write("You are not logged in") @Utils.hook("received.command.resetpassword", private_only=True, - min_args=2, usage="<nickname> <password>", permission="resetpassword") + min_args=2) def reset_password(self, event): """ - Reset a given user's password + :help: Reset a given user's password + :usage: <nickname> <password> + :permission: resetpassword """ target = event["server"].get_user(event["args_split"][0]) password = " ".join(event["args_split"][1:]) @@ -135,7 +137,7 @@ class Module(ModuleManager.BaseModule): @Utils.hook("preprocess.command") def preprocess_command(self, event): - permission = event["hook"].kwargs.get("permission", None) + permission = event["hook"].get_kwarg("permission", None) authenticated = event["hook"].kwargs.get("authenticated", False) identity_mechanism = event["server"].get_setting("identity-mechanism", @@ -166,7 +168,7 @@ class Module(ModuleManager.BaseModule): @Utils.hook("received.command.mypermissions", authenticated=True) def my_permissions(self, event): """ - Show your permissions + :help: Show your permissions """ permissions = event["user"].get_setting("permissions", []) event["stdout"].write("Your permissions: %s" % ", ".join(permissions)) @@ -177,11 +179,12 @@ class Module(ModuleManager.BaseModule): permissions = target.get_setting("permissions", []) return [target, registered, permissions] - @Utils.hook("received.command.givepermission", min_args=2, - permission="givepermission") + @Utils.hook("received.command.givepermission", min_args=2) def give_permission(self, event): """ - Give a given permission to a given user + :help: Give a given permission to a given user + :usage: <nickname> <permission> + :permission: givepermission """ permission = event["args_split"][1].lower() target, registered, permissions = self._get_user_details( @@ -199,11 +202,12 @@ class Module(ModuleManager.BaseModule): target.set_setting("permissions", permissions) event["stdout"].write("Gave permission '%s' to %s" % ( permission, target.nickname)) - @Utils.hook("received.command.removepermission", min_args=2, - permission="removepermission") + @Utils.hook("received.command.removepermission", min_args=2) def remove_permission(self, event): """ - Remove a given permission from a given user + :help: Remove a given permission from a given user + :usage: <nickname> <permission> + :permission: removepermission """ permission = event["args_split"][1].lower() target, registered, permissions = self._get_user_details( diff --git a/modules/pong.py b/modules/pong.py index c45e3aef..8742c678 100644 --- a/modules/pong.py +++ b/modules/pong.py @@ -1,6 +1,9 @@ from src import ModuleManager, Utils class Module(ModuleManager.BaseModule): - @Utils.hook("received.command.ping", help="Ping pong!") + @Utils.hook("received.command.ping") def pong(self, event): + """ + :help: Ping pong! + """ event["stdout"].write("Pong!") diff --git a/modules/quotes.py b/modules/quotes.py index 6cb1637a..6bfe78d7 100644 --- a/modules/quotes.py +++ b/modules/quotes.py @@ -7,11 +7,11 @@ class Module(ModuleManager.BaseModule): return [part.strip() for part in s.split("=", 1)] return None, None - @Utils.hook("received.command.quoteadd|qadd", min_args=1, - usage="<category> = <quote>") + @Utils.hook("received.command.quoteadd|qadd", min_args=1) def quote_add(self, event): """ - Add a quote to a category + :help: Add a quote to a category + :usage: <category> = <quote> """ category, quote = self.category_and_quote(event["args"]) if category and quote: @@ -23,11 +23,11 @@ class Module(ModuleManager.BaseModule): else: event["stderr"].write("Please provide a category AND quote") - @Utils.hook("received.command.quoteget|qget", min_args=1, - usage="<category> = <search>") + @Utils.hook("received.command.quoteget|qget", min_args=1) def quote_get(self, event): """ - Get a quote from a ccategory + :help: Get a quote from a ccategory + :usage: <category> = <search> """ category, to_find = self.category_and_quote(event["args"]) if category and to_find: @@ -46,11 +46,11 @@ class Module(ModuleManager.BaseModule): event["stderr"].write("Please provide a category and a " "part of a quote to find") - @Utils.hook("received.command.quotedel|qdel", min_args=1, - usage="<category> = <quote>") + @Utils.hook("received.command.quotedel|qdel", min_args=1) def quote_del(self, event): """ - Delete a quote from a category + :help: Delete a quote from a category + :usage: <category> = <quote> """ category, remove_quote = self.category_and_quote(event["args"]) remove_quote_lower = remove_quote.lower() @@ -71,10 +71,11 @@ class Module(ModuleManager.BaseModule): event["stderr"].write("Please provide a category and a quote " "to remove") - @Utils.hook("received.command.quote|q", usage="<category>", min_args=1) + @Utils.hook("received.command.quote|q", min_args=1) def quote(self, event): """ - Get a random quote from a category + :help: Get a random quote from a category + :usage: <category> """ category = event["args"].strip().lower() quotes = event["server"].get_setting("quotes-%s" % category, []) diff --git a/modules/random_number.py b/modules/random_number.py index a8451d88..5fa25748 100644 --- a/modules/random_number.py +++ b/modules/random_number.py @@ -4,10 +4,11 @@ from src import ModuleManager, Utils class Module(ModuleManager.BaseModule): _name = "Random" - @Utils.hook("received.command.random|rand", usage="[start] [end]") + @Utils.hook("received.command.random|rand") def random(self, event): """ - Get a random number + :help: Get a random number + :usage: [start] [end] """ start, end = "1", "100" if len(event["args_split"]) > 1: @@ -30,6 +31,6 @@ class Module(ModuleManager.BaseModule): @Utils.hook("received.command.guid") def guid(self, event): """ - Get a random guid + :help: Get a random guid """ event["stdout"].write(str(uuid.uuid4())) diff --git a/modules/seen.py b/modules/seen.py index 8a5c80fc..854bdc9c 100644 --- a/modules/seen.py +++ b/modules/seen.py @@ -7,10 +7,11 @@ class Module(ModuleManager.BaseModule): seen_seconds = time.time() event["user"].set_setting("seen", seen_seconds) - @Utils.hook("received.command.seen", min_args=1, usage="<username>") + @Utils.hook("received.command.seen", min_args=1) def seen(self, event): """ - Find out when a user was last seen + :help: Find out when a user was last seen + :usage: <nickname> """ seen_seconds = event["server"].get_user(event["args_split"][0] ).get_setting("seen") diff --git a/modules/set.py b/modules/set.py index 64a164b4..9da8fcfc 100644 --- a/modules/set.py +++ b/modules/set.py @@ -22,28 +22,31 @@ class Module(ModuleManager.BaseModule): else: event["stdout"].write("Available settings: %s" % ( ", ".join(settings_dict.keys()))) - @Utils.hook("received.command.set", usage="<setting> <value>") + @Utils.hook("received.command.set") def set(self, event): """ - Set a specified user setting + :help: Set a specified user setting + :usage: <setting> <value> """ self._set(self.exports.get_all("set"), event, event["user"]) @Utils.hook("received.command.channelset", channel_only=True, - usage="<setting> <value>", require_mode="o") + require_mode="o") @Utils.hook("received.command.channelsetoverride", channel_only=True, - usage="<setting> <value>", permission="channelsetoverride") + permission="channelsetoverride") def channel_set(self, event): """ - Get a specified channel setting for the current channel + :help: Get a specified channel setting for the current channel + :usage: <setting> <value> """ self._set(self.exports.get_all("channelset"), event, event["target"]) - @Utils.hook("received.command.serverset", usage="<setting> <value>", - permission="serverset") + @Utils.hook("received.command.serverset") def server_set(self, event): """ - Set a specified server setting for the current server + :help: Set a specified server setting for the current server + :usage: <setting> <value> + :permission: serverset """ self._set(self.exports.get_all("serverset"), event, event["server"]) @@ -54,30 +57,33 @@ class Module(ModuleManager.BaseModule): else: event["stdout"].write("'%s' has no value set" % setting) - @Utils.hook("received.command.get", min_args=1, usage="<setting>") + @Utils.hook("received.command.get", min_args=1) def get(self, event): """ - Get a specified user setting + :help: Get a specified user setting + :usage: <setting> """ setting = event["args_split"][0] self._get(event, setting, "", event["user"].get_setting( setting, None)) - @Utils.hook("received.command.channelget", channel_only=True, - usage="<setting>", min_args=1, require_mode="o") + @Utils.hook("received.command.channelget", channel_only=True, min_args=1) def channel_get(self, event): """ - Get a specified channel setting for the current channel + :help: Get a specified channel setting for the current channel + :usage: <setting> + :require_mode: o """ setting = event["args_split"][0] self._get(event, setting, " for %s" % event["target"].name, event["target"].get_setting(setting, None)) - @Utils.hook("received.command.serverget", usage="<setting>", min_args=1, - permission="serverget") + @Utils.hook("received.command.serverget", min_args=1) def server_get(self, event): """ - Get a specified server setting for the current server + :help: Get a specified server setting for the current server + :usage: <setting> + :permission: serverget """ setting = event["args_split"][0] self._get(event, setting, "", event["server"].get_setting( diff --git a/modules/soundcloud.py b/modules/soundcloud.py index 4ed2e787..301fe6be 100644 --- a/modules/soundcloud.py +++ b/modules/soundcloud.py @@ -13,7 +13,8 @@ class Module(ModuleManager.BaseModule): @Utils.hook("received.command.soundcloud|sc") def soundcloud(self, event): """ - Search SoundCloud + :help: Search SoundCloud + :usage: <term> """ query = None url = None diff --git a/modules/spotify.py b/modules/spotify.py index 6816cd50..4c2d3c57 100644 --- a/modules/spotify.py +++ b/modules/spotify.py @@ -7,7 +7,8 @@ class Module(ModuleManager.BaseModule): @Utils.hook("received.command.spotify", min_args=1) def spotify(self, event): """ - Search for a track on spotify + :help: Search for a track on spotify + :usage: <term> """ page = Utils.get_url(URL_SPOTIFY, get_params={"type": "track", "limit": 1, "q": event["args"]}, json=True) diff --git a/modules/stats.py b/modules/stats.py index 5cf78a54..4da48709 100644 --- a/modules/stats.py +++ b/modules/stats.py @@ -5,7 +5,7 @@ class Module(ModuleManager.BaseModule): @Utils.hook("received.command.uptime") def uptime(self, event): """ - Show my uptime + :help: Show my uptime """ seconds = int(time.time()-self.bot.start_time) event["stdout"].write("Uptime: %s" % Utils.to_pretty_time( @@ -14,7 +14,7 @@ class Module(ModuleManager.BaseModule): @Utils.hook("received.command.stats") def stats(self, event): """ - Show my network/channel/user stats + :help: Show my network/channel/user stats """ networks = len(self.bot.servers) channels = 0 diff --git a/modules/strax.py b/modules/strax.py index 385c825b..64c92313 100644 --- a/modules/strax.py +++ b/modules/strax.py @@ -5,8 +5,8 @@ class Module(ModuleManager.BaseModule): @Utils.hook("received.command.strax") def strax(self, event): """ - Suggests a glorious method of battle for the glory of the Sontaran - Empire, through IRC! + :help: Suggests a glorious method of battle for the glory of the + Sontaran Empire, through IRC! """ suggestion_greeting = ["Might I suggest", "Can I suggest", "Should we attack immediately with"] command_greeting = ["We should attack now with", "We must attack now with", "I suggest attacking with", diff --git a/modules/tfl.py b/modules/tfl.py index a1bdab4a..23c4cecf 100644 --- a/modules/tfl.py +++ b/modules/tfl.py @@ -46,10 +46,11 @@ class Module(ModuleManager.BaseModule): platform = m.group(2) return platform - @Utils.hook("received.command.tflbus", min_args=1, usage="<stop_id>") + @Utils.hook("received.command.tflbus", min_args=1) def bus(self, event): """ - Get bus due times for a TfL bus stop + :help: Get bus due times for a TfL bus stop + :usage: <stop_id> """ app_id = self.bot.config["tfl-api-id"] app_key = self.bot.config["tfl-api-key"] @@ -122,10 +123,11 @@ class Module(ModuleManager.BaseModule): else: event["stderr"].write("Bus ID '%s' unknown" % stop_id) - @Utils.hook("received.command.tflline", usage="<line_name>") + @Utils.hook("received.command.tflline") def line(self, event): """ - Get line status for TfL underground lines + :help: Get line status for TfL underground lines + :usage: <line_name> """ app_id = self.bot.config["tfl-api-id"] app_key = self.bot.config["tfl-api-key"] @@ -165,10 +167,11 @@ class Module(ModuleManager.BaseModule): else: event["stderr"].write("No results") - @Utils.hook("received.command.tflsearch", min_args=1, usage="<name>") + @Utils.hook("received.command.tflsearch", min_args=1) def search(self, event): """ - Get a list of TfL stop IDs for a given name + :help: Get a list of TfL stop IDs for a given name + :usage: <name> """ app_id = self.bot.config["tfl-api-id"] app_key = self.bot.config["tfl-api-key"] @@ -186,10 +189,11 @@ class Module(ModuleManager.BaseModule): else: event["stderr"].write("No results") - @Utils.hook("received.command.tflvehicle", min_args=1, usage="<ID>") + @Utils.hook("received.command.tflvehicle", min_args=1) def vehicle(self, event): """ - Get information for a given vehicle + :help: Get information for a given vehicle + :usage: <ID> """ app_id = self.bot.config["tfl-api-id"] app_key = self.bot.config["tfl-api-key"] @@ -206,11 +210,11 @@ class Module(ModuleManager.BaseModule): vehicle["vehicleId"], vehicle["lineName"], vehicle["destinationName"], vehicle["currentLocation"], vehicle["stationName"], vehicle["naptanId"], arrival_time, platform)) - @Utils.hook("received.command.tflservice", min_args=1, - usage="<service index>") + @Utils.hook("received.command.tflservice", min_args=1) def service(self, event): """ - Get service information and arrival estimates + :help: Get service information and arrival estimates + :usage: <service index> """ app_id = self.bot.config["tfl-api-id"] app_key = self.bot.config["tfl-api-key"] @@ -239,10 +243,11 @@ class Module(ModuleManager.BaseModule): a["expectedArrival"][11:16] ) for a in arrivals])) - @Utils.hook("received.command.tflstop", min_args=1, usage="<stop_id>") + @Utils.hook("received.command.tflstop", min_args=1) def stop(self, event): """ - Get information for a given stop + :help: Get information for a given stop + :usage: <stop_id> """ app_id = self.bot.config["tfl-api-id"] app_key = self.bot.config["tfl-api-key"] diff --git a/modules/thesaurus.py b/modules/thesaurus.py index b34c2f04..8d5d540e 100644 --- a/modules/thesaurus.py +++ b/modules/thesaurus.py @@ -5,11 +5,11 @@ from src import ModuleManager, Utils URL_THESAURUS = "http://words.bighugelabs.com/api/2/%s/%s/json" class Module(ModuleManager.BaseModule): - @Utils.hook("received.command.synonym|antonym", min_args=1, - usage="<word> [type]") + @Utils.hook("received.command.synonym|antonym", min_args=1) def thesaurus(self, event): """ - Get synonyms/antonyms for a provided phrase + :help: Get synonyms/antonyms for a provided phrase + :usage: <word> [type] """ phrase = event["args_split"][0] page = Utils.get_url(URL_THESAURUS % (self.bot.config[ diff --git a/modules/title.py b/modules/title.py index ee00bc37..6ec5c6d8 100644 --- a/modules/title.py +++ b/modules/title.py @@ -7,7 +7,8 @@ class Module(ModuleManager.BaseModule): @Utils.hook("received.command.title|t", usage="[URL]") def title(self, event): """ - Get the title of a URL + :help: Get the title of a URL + :usage: [URL] """ url = None if len(event["args"]) > 0: diff --git a/modules/to.py b/modules/to.py index 2bfe410d..2136d0c0 100644 --- a/modules/to.py +++ b/modules/to.py @@ -11,11 +11,12 @@ class Module(ModuleManager.BaseModule): if messages: event["channel"].del_user_setting(event["user"].get_id(), "to") - @Utils.hook("received.command.to", min_args=2, channel_only=True, - usage="<username> <message>") + @Utils.hook("received.command.to", min_args=2, channel_only=True) def to(self, event): """ - Relay a message to a user the next time they talk in this channel" + :help: Relay a message to a user the next time they talk in this + channel + :usage: <nickname> <message> """ target_user = event["server"].get_user(event["args_split"][0]) messages = event["target"].get_user_setting(target_user.get_id(), diff --git a/modules/todo.py b/modules/todo.py index 957accee..5d2f0eda 100644 --- a/modules/todo.py +++ b/modules/todo.py @@ -1,10 +1,11 @@ from src import ModuleManager, Utils class Module(ModuleManager.BaseModule): - @Utils.hook("received.command.todo", usage="[item number]") + @Utils.hook("received.command.todo") def todo(self, event): """ - Find out what's in your todo list + :help: Find out what's in your todo list + :usage: [item number] """ todo = event["user"].get_setting("todo", []) if event["args"]: @@ -20,10 +21,11 @@ class Module(ModuleManager.BaseModule): todo_count = len(todo) event["stdout"].write("There are %d items in your todo" % todo_count) - @Utils.hook("received.command.todoadd", min_args=1, usage="<description>") + @Utils.hook("received.command.todoadd", min_args=1) def todo_add(self, event): """ - Add something to your todo list + :help: Add something to your todo list + :usage: <description> """ arg_lower = event["args"].lower() todo = event["user"].get_setting("todo", []) @@ -36,10 +38,11 @@ class Module(ModuleManager.BaseModule): event["user"].set_setting("todo", todo) event["stdout"].write("Saved") - @Utils.hook("received.command.tododel", min_args=1, usage="<item number>") + @Utils.hook("received.command.tododel", min_args=1) def todo_del(self, event): """ - Remove something from your todo list + :help: Remove something from your todo list + :usage: <item number> """ todo = event["user"].get_setting("todo", []) if event["args_split"][0].isdigit() and int(event["args_split"][0]) > 0: diff --git a/modules/trakt.py b/modules/trakt.py index a902e9c1..f25a04ae 100644 --- a/modules/trakt.py +++ b/modules/trakt.py @@ -7,10 +7,11 @@ URL_TRAKTSLUG = "https://trakt.tv/%s/%s" @Utils.export("set", {"setting": "trakt", "help": "Set username on trakt.tv"}) class Module(ModuleManager.BaseModule): - @Utils.hook("received.command.nowwatching|nw", usage="[username]") + @Utils.hook("received.command.nowwatching|nw") def now_watching(self, event): """ - Get what you or another user is now watching on trakt.tv + :help: Get what you or another user is now watching on trakt.tv + :usage: [username] """ if event["args"]: username = event["args_split"][0] diff --git a/modules/translate.py b/modules/translate.py index 2b118140..b96a49a1 100644 --- a/modules/translate.py +++ b/modules/translate.py @@ -6,10 +6,12 @@ URL_LANGUAGES = "https://cloud.google.com/translate/docs/languages" REGEX_LANGUAGES = re.compile("(\w+)?:(\w+)? ") class Module(ModuleManager.BaseModule): - @Utils.hook("received.command.translate|tr", usage="[phrase]") + @Utils.hook("received.command.translate|tr") def translate(self, event): """ - Translate the provided phrase or the last line in thie current channel + :help: Translate the provided phrase or the last line in thie current + channel + :usage: [phrase] """ phrase = event["args"] if not phrase: diff --git a/modules/tweets.py b/modules/tweets.py index 4dc08789..f0aedcc4 100644 --- a/modules/tweets.py +++ b/modules/tweets.py @@ -19,10 +19,11 @@ class Module(ModuleManager.BaseModule): since, unit = Utils.time_unit(seconds_since) return "%s %s ago" % (since, unit) - @Utils.hook("received.command.tweet|tw", usage="[@username/URL/ID]") + @Utils.hook("received.command.tweet|tw") def tweet(self, event): """ - Get/find a tweet + :help: Get/find a tweet + :usage: [@username/URL/ID] """ api_key = self.bot.config["twitter-api-key"] api_secret = self.bot.config["twitter-api-secret"] diff --git a/modules/upc.py b/modules/upc.py index 8da063f5..5c295fc3 100644 --- a/modules/upc.py +++ b/modules/upc.py @@ -5,10 +5,11 @@ UPCITEMDB_URL = "https://api.upcitemdb.com/prod/trial/lookup" class Module(ModuleManager.BaseModule): _name = "UPC" - @Utils.hook("received.command.upc|ean|gtin", min_args=1, usage="<UPC|EAN>") + @Utils.hook("received.command.upc|ean|gtin", min_args=1) def upc(self, event): """ - Look up a product by UPC, EAN or GTIN + :help: Look up a product by UPC, EAN or GTIN + :usage: <UPC|EAN|GTIN> """ arg_len = len(event["args_split"][0]) if not arg_len == 12 and not arg_len == 13: diff --git a/modules/urbandictionary.py b/modules/urbandictionary.py index 6151afb8..2d5edd21 100644 --- a/modules/urbandictionary.py +++ b/modules/urbandictionary.py @@ -5,11 +5,11 @@ URL_URBANDICTIONARY = "http://api.urbandictionary.com/v0/define" REGEX_DEFNUMBER = re.compile("-n(\d+) \S+") class Module(ModuleManager.BaseModule): - @Utils.hook("received.command.urbandictionary|ud", min_args=1, - usage="<term>") + @Utils.hook("received.command.urbandictionary|ud", min_args=1) def ud(self, event): """ - Get the definition of a provided term from Urban Dictionary + :help: Get the definition of a provided term from Urban Dictionary + :usage: <term> """ term = event["args"] number = 1 diff --git a/modules/weather.py b/modules/weather.py index 33200958..a1c14f27 100644 --- a/modules/weather.py +++ b/modules/weather.py @@ -8,7 +8,8 @@ class Module(ModuleManager.BaseModule): @Utils.hook("received.command.weather", min_args=1, usage="<location>") def weather(self, event): """ - Get current weather data for a provided location + :help: Get current weather data for a provided location + :usage: <location> """ api_key = self.bot.config["openweathermap-api-key"] page = Utils.get_url(URL_WEATHER, get_params={ diff --git a/modules/wikipedia.py b/modules/wikipedia.py index f668b8ca..2b6a70c0 100644 --- a/modules/wikipedia.py +++ b/modules/wikipedia.py @@ -6,7 +6,8 @@ class Module(ModuleManager.BaseModule): @Utils.hook("received.command.wiki|wi", min_args=1) def wikipedia(self, event): """ - Get information from wikipedia + :help: Get information from wikipedia + :usage: <term> """ page = Utils.get_url(URL_WIKIPEDIA, get_params={ "action": "query", "prop": "extracts", diff --git a/modules/wolframalpha.py b/modules/wolframalpha.py index 292016e4..7d348df5 100644 --- a/modules/wolframalpha.py +++ b/modules/wolframalpha.py @@ -7,10 +7,11 @@ URL_WA = "https://api.wolframalpha.com/v1/result" class Module(ModuleManager.BaseModule): _name = "Wolfram|Alpha" - @Utils.hook("received.command.wolframalpha|wa", min_args=1, usage="<query>") + @Utils.hook("received.command.wolframalpha|wa", min_args=1) def wa(self, event): """ - Evauate a given string on Wolfram|Alpha + :help: Evauate a given string on Wolfram|Alpha + :usage: <query> """ code, result = Utils.get_url(URL_WA, get_params={"i": event["args"], "appid": self.bot.config["wolframalpha-api-key"], diff --git a/modules/words.py b/modules/words.py index 689f5c73..b9731f71 100644 --- a/modules/words.py +++ b/modules/words.py @@ -31,10 +31,11 @@ class Module(ModuleManager.BaseModule): self._channel_message(event["server"].get_user( event["server"].nickname), event) - @Utils.hook("received.command.words", channel_only=True, usage="<nickname>") + @Utils.hook("received.command.words", channel_only=True) def words(self, event): """ - See how many words you or the given nickname have used + :help: See how many words you or the given nickname have used + :usage: [nickname] """ if event["args_split"]: target = event["server"].get_user(event["args_split" @@ -51,11 +52,12 @@ class Module(ModuleManager.BaseModule): event["stdout"].write("%s has used %d words (%d in %s)" % ( target.nickname, total, this_channel, event["target"].name)) - @Utils.hook("received.command.trackword", min_args=1, - permission="track-word") + @Utils.hook("received.command.trackword", min_args=1) def track_word(self, event): """ - Start tracking a word + :help: Start tracking a word + :usage: <word> + :permission: track-word """ word = event["args_split"][0].lower() tracked_words = event["server"].get_setting("tracked-words", []) @@ -66,10 +68,11 @@ class Module(ModuleManager.BaseModule): else: event["stderr"].write("Already tracking '%s'" % word) - @Utils.hook("received.command.wordusers", min_args=1, usage="<word>") + @Utils.hook("received.command.wordusers", min_args=1) def word_users(self, event): """ - Show who has used a tracked word the most + :help: Show who has used a tracked word the most + :usage: <word> """ word = event["args_split"][0].lower() if word in event["server"].get_setting("tracked-words", []): diff --git a/modules/youtube.py b/modules/youtube.py index c90872a4..c44ac7fa 100644 --- a/modules/youtube.py +++ b/modules/youtube.py @@ -71,10 +71,11 @@ class Module(ModuleManager.BaseModule): video_id = search_page["items"][0]["id"]["videoId"] return "https://youtu.be/%s" % video_id - @Utils.hook("received.command.yt|youtube", usage="[query]") + @Utils.hook("received.command.yt|youtube") def yt(self, event): """ - Find a video on youtube + :help: Find a video on youtube + :usage: [query/URL] """ video_id = None search = None diff --git a/src/EventManager.py b/src/EventManager.py index b8a5ecfb..720fe0a1 100644 --- a/src/EventManager.py +++ b/src/EventManager.py @@ -1,4 +1,5 @@ import itertools, time, traceback +from src import Utils PRIORITY_URGENT = 0 PRIORITY_HIGH = 1 @@ -29,9 +30,15 @@ class EventCallback(object): self.function = function self.priority = priority self.kwargs = kwargs + self.docstring = Utils.parse_docstring(function.__doc__) + def call(self, event): return self.function(event) + def get_kwarg(self, name, default=None): + item = self.kwargs.get(name, default) + return item or self.docstring.items.get(name, default) + class MultipleEventHook(object): def __init__(self): self._event_hooks = set([]) diff --git a/src/Utils.py b/src/Utils.py index b5fa8452..e87330c2 100644 --- a/src/Utils.py +++ b/src/Utils.py @@ -313,3 +313,35 @@ def get_hashflags(filename): value = line_split[1] hashflags[hashflag] = value return hashflags.items() + +class Docstring(object): + def __init__(self, description, items): + self.description = description + self.items = items + +def parse_docstring(s): + description = "" + last_item = None + items = {} + if s: + for line in s.split("\n"): + line = line.strip() + + if line: + if line[0] == ":": + line_split = line.split(": ", 1) + + value = None + if len(line_split) > 1: + value = line_split[1] + + last_item = line_split[0][1:].lower() + items[last_item] = value + else: + if last_item: + items[last_item] += " %s" % line + else: + if description: + description += " " + description += line + return Docstring(description, items) |
