Praxis_Bot/commands/command_base.py
dtookey 7c870caa92 implemented a few doodads on the AbstractCommand class to make integration easier.
Modified do_command to receive the Twitch_Module class from twitch_script.py and the twitch.chat.Message from the bot

implemented the loader in the bot
2020-10-02 13:49:39 -04:00

40 lines
1.2 KiB
Python

from abc import ABCMeta, abstractmethod
from enum import Enum, auto
import twitch.chat
from twitch_script import Twitch_Module
class AbstractCommand(metaclass=ABCMeta):
"""
This is the base class for commands. In order to load a command a few conditions must be met:
1) The class name MUST begin with 'Command' i.e. CommandTTS, CommandBan, etc...
2) the class MUST extend AbstractCommand
Generally, it would be advisable to define the command (something like !so, !tts, !songrequest) as a variable of the
class and to then call super().__init__(command)
"""
class CommandType(Enum):
NONE = auto()
TWITCH = auto()
DISCORD = auto()
def __init__(self, command: str, n_args: int = 0, command_type=CommandType.NONE):
self.command = command
self.n_args = n_args
self.command_type = command_type
# no touch!
def get_args(self, text: str) -> list:
return text.split(" ")[0:self.n_args + 1]
# no touch!
def get_command(self) -> str:
return self.command
@abstractmethod
def do_command(self, bot: Twitch_Module, twitch_message: twitch.chat.Message):
pass