better command routing
This commit is contained in:
@@ -8,7 +8,7 @@ import emotes
|
|||||||
import help
|
import help
|
||||||
from utils import debug
|
from utils import debug
|
||||||
|
|
||||||
VERSION = "1.0"
|
VERSION = "1.1-dev"
|
||||||
t0 = datetime.now()
|
t0 = datetime.now()
|
||||||
|
|
||||||
# Loading token
|
# Loading token
|
||||||
@@ -18,6 +18,25 @@ token = os.getenv('DISCORD_TOKEN')
|
|||||||
client = discord.Client()
|
client = discord.Client()
|
||||||
|
|
||||||
|
|
||||||
|
async def info(message, args):
|
||||||
|
"""
|
||||||
|
Computes the %info command
|
||||||
|
|
||||||
|
:param message: message sent
|
||||||
|
:type message: :class:`discord.Message`
|
||||||
|
:param args: arguments of the command
|
||||||
|
:type args: list[:class:`str`]
|
||||||
|
"""
|
||||||
|
await message.channel.send(f"```Discord Analyst v{VERSION} started at {t0:%Y-%m-%d %H:%M}```")
|
||||||
|
|
||||||
|
|
||||||
|
COMMANDS = {
|
||||||
|
"%help": help.compute,
|
||||||
|
"%emotes": emotes.compute,
|
||||||
|
"%info": info
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@client.event
|
@client.event
|
||||||
async def on_ready():
|
async def on_ready():
|
||||||
"""
|
"""
|
||||||
@@ -47,6 +66,13 @@ async def on_message(message):
|
|||||||
if message.author == client.user:
|
if message.author == client.user:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
args = message.content.split(" ")
|
||||||
|
|
||||||
|
if len(args) < 1 or args[0] not in COMMANDS:
|
||||||
|
return
|
||||||
|
|
||||||
|
debug(message, f"command '{message.content}'")
|
||||||
|
|
||||||
# Check if bot can respond on current channel or DM user
|
# Check if bot can respond on current channel or DM user
|
||||||
permissions = message.channel.permissions_for(message.guild.me)
|
permissions = message.channel.permissions_for(message.guild.me)
|
||||||
if not permissions.send_messages:
|
if not permissions.send_messages:
|
||||||
@@ -58,14 +84,7 @@ async def on_message(message):
|
|||||||
return
|
return
|
||||||
|
|
||||||
# Redirect to the correct command
|
# Redirect to the correct command
|
||||||
args = message.content.split(" ")
|
await COMMANDS[args[0]](message, args)
|
||||||
if args[0] == "%info":
|
|
||||||
debug(message, f"command '{message.content}'")
|
|
||||||
await message.channel.send(f"Discord Analyst v{VERSION} started at {t0.isoformat()}")
|
|
||||||
if args[0] == "%help":
|
|
||||||
await help.compute(message, args)
|
|
||||||
if args[0] == "%emotes":
|
|
||||||
await emotes.compute(message, args)
|
|
||||||
|
|
||||||
|
|
||||||
# Launch client
|
# Launch client
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ async def compute(message, args):
|
|||||||
:param args: arguments of the command
|
:param args: arguments of the command
|
||||||
:type args: list[str]
|
:type args: list[str]
|
||||||
"""
|
"""
|
||||||
debug(message, f"command '{message.content}'")
|
|
||||||
|
|
||||||
# Select correct response to send
|
# Select correct response to send
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user