Bug fixes, makefile for launch

This commit is contained in:
2022-12-09 11:19:45 +01:00
parent 24b3bc3b51
commit 647944d23c
25 changed files with 321 additions and 300 deletions

View File

@@ -7,7 +7,7 @@ import re
import time
import configuration
config = configuration.main_config["SLACK"]
slack_config = configuration.config["slack"]
models = configuration.models
class MessageIsUnwanted(Exception):
@@ -61,7 +61,7 @@ class Message:
@property
def is_by_human(self):
return self.user.user_id != config["bot_id"]
return self.user.user_id != slack_config["bot_id"]
@property
@@ -87,7 +87,7 @@ class BotApp(App):
def say_substitute(self, *args, **kwargs):
self.client.chat_postMessage(
channel=config["archive_id"],
channel=slack_config["archive_id"],
text=" - ".join(args),
**kwargs
)
@@ -101,7 +101,7 @@ class BotApp(App):
last_ts = presaved.slack_ts_full
result = self.client.conversations_history(
channel=config["archive_id"],
channel=slack_config["archive_id"],
oldest=last_ts
)
@@ -116,7 +116,7 @@ class BotApp(App):
while refetch: # we have not actually fetched them all
try:
result = self.client.conversations_history(
channel = config["archive_id"],
channel = slack_config["archive_id"],
cursor = result["response_metadata"]["next_cursor"],
oldest = last_ts
) # fetches 100 messages, older than the [-1](=oldest) element of new_fetches
@@ -126,8 +126,8 @@ class BotApp(App):
for m in new_messages:
return_messages.append(Message(m))
except SlackApiError: # Most likely a rate-limit
self.logger.error("Error while fetching channel messages. (likely rate limit) Retrying in {} seconds...".format(config["api_wait_time"]))
time.sleep(config["api_wait_time"])
self.logger.error("Error while fetching channel messages. (likely rate limit) Retrying in {} seconds...".format(slack_config["api_wait_time"]))
time.sleep(slack_config["api_wait_time"])
refetch = True
self.logger.info(f"Fetched {len(return_messages)} new channel messages.")
@@ -181,7 +181,7 @@ class BotRunner():
"""Stupid encapsulation so that we can apply the slack decorators to the BotApp"""
def __init__(self, callback, *args, **kwargs) -> None:
self.bot_worker = BotApp(callback, token=config["auth_token"])
self.bot_worker = BotApp(callback, token=slack_config["auth_token"])
@self.bot_worker.event(event="message", matchers=[is_message_in_archiving])
def handle_incoming_message(message, say):
@@ -195,7 +195,7 @@ class BotRunner():
def handle_all_other_reactions(event, say):
self.logger.log("Ignoring slack event that isn't a message")
self.handler = SocketModeHandler(self.bot_worker, config["app_token"])
self.handler = SocketModeHandler(self.bot_worker, slack_config["app_token"])
def start(self):
@@ -215,5 +215,5 @@ class BotRunner():
def is_message_in_archiving(message) -> bool:
return message["channel"] == config["archive_id"]
return message["channel"] == slack_config["archive_id"]