summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNatrixAeria <upezu@student.kit.edu>2020-09-28 02:48:38 +0200
committerNatrixAeria <upezu@student.kit.edu>2020-09-28 02:48:38 +0200
commit89e0c7df2b88daf83b6a415c1ab2b95e2d6bc46d (patch)
treec2ded0c4b7ff7a76a5a399d41e0df35f1f52ef7b
parent778b54f50f81151cbd1bd2e62f5c6d69c4ca0cf0 (diff)
Alter command property syntax
-rw-r--r--bot.py19
-rw-r--r--command_utils.py28
2 files changed, 20 insertions, 27 deletions
diff --git a/bot.py b/bot.py
index a7e042a..ced131d 100644
--- a/bot.py
+++ b/bot.py
@@ -1,14 +1,17 @@
+import discord
import config
-from command_utils import Command, CommandClient
+from command_utils import command, CommandClient
class Client(CommandClient):
async def on_ready(self):
print(f'the bot {config.NAME} is logged in as "{self.user}"')
- @Command.help_command
- @Command.names('help', 'hepl', 'h', '?')
- @Command.description('display this help message')
+ @command(
+ names = ('help', 'hepl', 'h', '?'),
+ description = 'display this help message',
+ is_help = True
+ )
async def help(self, ctx):
command_doc = '\n'.join(
f' * {config.COMMAND_PREFIX.strip()} {c.names[0]:15} - {c.description}'
@@ -16,8 +19,10 @@ class Client(CommandClient):
await ctx.answer(f'''```
{config.HELP_TEXT}\nThese are all available commands:\n{command_doc}```''')
- @Command.names('init', 'create', 'inti', 'craete', 'cretae', 'c', 'i', '+')
- @Command.description('create a new lobby')
+ @command(
+ names = ('init', 'create', 'inti', 'craete', 'cretae', 'c', 'i', '+'),
+ description = 'create a new lobby'
+ )
async def init(self, ctx):
await ctx.answer(f'NIY')
@@ -28,5 +33,5 @@ if __name__ == '__main__':
if token is None:
print('error: no token was given')
exit(1)
- bot = Client()
+ bot = Client(activity=discord.Game(name=config))
bot.run(token)
diff --git a/command_utils.py b/command_utils.py
index b679975..6a82e7b 100644
--- a/command_utils.py
+++ b/command_utils.py
@@ -50,24 +50,12 @@ class CommandClient(discord.Client, metaclass=CommandClientMeta):
return await self.run_help(ctx)
-class Command:
- @classmethod
- def names(cls, *names):
- def meta(f):
- f.command = True
- f.names = names
- return f
- return meta
-
- @classmethod
- def description(cls, description):
- def meta(f):
- f.command = True
- f.description = description
- return f
- return meta
-
- @classmethod
- def help_command(cls, f):
- f.help_command = True
+def command(names=[], description='', is_help=False):
+ def meta(f):
+ f.command = True
+ f.names = names
+ f.description = description
+ if is_help:
+ f.help_command = is_help
return f
+ return meta