Skip to content

Commit

Permalink
Improving main structure using ideas from bolt-python-starter-template (
Browse files Browse the repository at this point in the history
  • Loading branch information
marcieltorres authored Feb 14, 2024
1 parent 8587377 commit 1f6202c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
9 changes: 2 additions & 7 deletions src/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
from slack_bolt.adapter.socket_mode.async_handler import AsyncSocketModeHandler
from slack_bolt.async_app import AsyncApp

from src.messages.constants import DEFAULT_WARNING_MESSAGE
from src.rules.pattern import pattern
from src.listeners.register import register_listeners

logConfig("./logging.conf", disable_existing_loggers=False)
logger = getLogger(__name__)
Expand All @@ -17,13 +16,9 @@

app = AsyncApp(token=SLACK_BOT_TOKEN)

@app.message(pattern.compiled_pattern)
async def say_hello_regex(say, message, client):
user = message['user']
await say(text=DEFAULT_WARNING_MESSAGE.format(name=f'<@{user}>'), thread_ts=message.get('ts'))

async def main():
try:
await register_listeners(app)
handler = AsyncSocketModeHandler(app, SLACK_APP_TOKEN)
await handler.start_async()
except Exception as ex:
Expand Down
20 changes: 20 additions & 0 deletions src/listeners/messages/regex_message.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from logging import getLogger

from slack_bolt import App

from src.messages.constants import DEFAULT_WARNING_MESSAGE
from src.rules.pattern import pattern

logger = getLogger(__name__)


async def register(app: App):
app.message(pattern.compiled_pattern)(regex_message_callback)


async def regex_message_callback(message, say):
try:
user = message['user']
await say(text=DEFAULT_WARNING_MESSAGE.format(name=f'<@{user}>'), thread_ts=message.get('ts'))
except Exception as e:
logger.error(e)
5 changes: 5 additions & 0 deletions src/listeners/register.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from src.listeners.messages.regex_message import register as register_regex_message


async def register_listeners(app):
await register_regex_message(app)

0 comments on commit 1f6202c

Please sign in to comment.