This repository has been archived on 2021-03-28. You can view files and clone it, but cannot push or open issues/pull-requests.
frank/frank/frank.py

35 lines
854 B
Python

import shlex
from typing import List
import discord
class Frank(discord.Client):
PREFIX = "fr"
def __init__(self, modules: List["Module"]):
super().__init__()
self._modules = modules
self._loaded_modules = []
async def on_ready(self):
print("Connected")
# Startup all modules
for module in self._modules:
loaded = module(self)
await loaded.start()
self._loaded_modules.append(loaded)
print("All modules loaded")
async def on_message(self, message: str):
cmd = shlex.split(message.content.strip())
if cmd[0] == "fr":
matched_mods = (mod for mod in self._loaded_modules if mod.PREFIX == cmd[1])
module = next(matched_mods, None)
if module:
await module.command(cmd[2:])