Messages watcher registration

This commit is contained in:
klemek
2020-11-06 19:43:30 +01:00
parent 5ed605ab7b
commit beae7278a7
2 changed files with 10 additions and 3 deletions
+1 -1
View File
@@ -4,7 +4,7 @@ __pycache__
.env .env
error_* error_*
*.log *.log
test.py *test*.py
*.pyc *.pyc
.pytest_cache .pytest_cache
.coverage .coverage
+8 -1
View File
@@ -31,7 +31,7 @@ class Bot(object):
def __init__(self, app_name: str, version: str, *, alias: str = None): def __init__(self, app_name: str, version: str, *, alias: str = None):
# constants # constants
self.token_env_var = "DISCORD_TOKEN" self.token_env_var = "DISCORD_TOKEN"
self.remove_mentions = True # remove mentions from arguments self.remove_mentions = False # remove mentions from arguments
self.alias = alias # can call bot with {alias}{command_name} self.alias = alias # can call bot with {alias}{command_name}
self.any_mention = False # bot mention can be anywhere self.any_mention = False # bot mention can be anywhere
self.log_calls = False self.log_calls = False
@@ -48,6 +48,7 @@ class Bot(object):
self.__t0 = None self.__t0 = None
self.__last_error = None self.__last_error = None
# init # init
self.__watcher = None
self.__commands = [] self.__commands = []
self.__fallback = None self.__fallback = None
self.games = [f"v{version}", self.games = [f"v{version}",
@@ -133,6 +134,9 @@ class Bot(object):
if message.author == self.client.user: if message.author == self.client.user:
return # Ignore self messages return # Ignore self messages
if self.__watcher is not None:
await self.__watcher(self.client, message)
is_direct = message.channel.type == discord.ChannelType.private is_direct = message.channel.type == discord.ChannelType.private
is_mention = self.any_mention and self.client.user in message.mentions \ is_mention = self.any_mention and self.client.user in message.mentions \
@@ -201,6 +205,9 @@ class Bot(object):
def register_fallback(self, compute: CommandFunction): def register_fallback(self, compute: CommandFunction):
self.__fallback = compute self.__fallback = compute
def register_watcher(self, compute: CommandFunction):
self.__watcher = compute
def start(self): def start(self):
logging.info(f"Current PID: {os.getpid()}") logging.info(f"Current PID: {os.getpid()}")
env_file_found = load_dotenv() env_file_found = load_dotenv()