|
@@ -4,7 +4,7 @@ import asyncio
|
|
|
|
|
|
import aiosqlite
|
|
|
|
|
|
-from .types import CommandConfiguration, Message, Response, Context
|
|
|
+from .types import CommandConfiguration, Message, Response, Context, Command
|
|
|
|
|
|
# TODO logging
|
|
|
|
|
@@ -48,15 +48,16 @@ class Rollbot(Generic[RawMsg]):
|
|
|
if message.text is None:
|
|
|
return
|
|
|
|
|
|
- cleaned = message.text.lstrip()
|
|
|
- if len(cleaned) == 0 or cleaned[0] not in self.command_config.bangs:
|
|
|
+ message.command = Command.from_text(message.text)
|
|
|
+ if (
|
|
|
+ message.command is None
|
|
|
+ or message.command.bang not in self.command_config.bangs
|
|
|
+ ):
|
|
|
return
|
|
|
|
|
|
- parts = cleaned[1:].lstrip().split(maxsplit=1)
|
|
|
- if len(parts) == 0:
|
|
|
- return
|
|
|
-
|
|
|
- command = self.command_config.aliases.get(parts[0], parts[0])
|
|
|
+ command = self.command_config.aliases.get(
|
|
|
+ message.command.name, message.command.name
|
|
|
+ )
|
|
|
res = self.command_config.call_and_response.get(command, None)
|
|
|
if res is not None:
|
|
|
await self.respond(Response.from_message(message, res))
|