Skip to content

Commit

Permalink
feat: move optional chat features into dedicated apps
Browse files Browse the repository at this point in the history
  • Loading branch information
philchristensen committed Oct 20, 2024
1 parent f0b1d05 commit ca893a3
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 31 deletions.
File renamed without changes.
6 changes: 6 additions & 0 deletions django_slackbot/app_home/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# -*- coding: utf-8 -*-
from django.apps import AppConfig


class AppHomeConfig(AppConfig):
name = 'django_slackbot.app_home'
37 changes: 37 additions & 0 deletions django_slackbot/app_home/chat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# -*- coding: utf-8 -*-
import logging
from urllib.parse import urlencode, parse_qs, urlparse

from slackblocks import SectionBlock, HeaderBlock, DividerBlock
from slackblocks.messages import BaseMessage

from django_slackbot.chat import app

log = logging.getLogger(__name__)

class ViewMessage(BaseMessage):
def _resolve(self):
result = {**super()._resolve()}
result.pop("mrkdwn", None)
result.pop("text", None)
return result

@app.event("app_home_opened")
def app_home_opened(event, ack, client):
ack()
details = client.auth_test()
channels = client.users_conversations(types="public_channel,private_channel")
channellist = ''
for channel in channels['channels']:
channellist += f"* <#{channel['id']}>\n"
view = ViewMessage(blocks=[
HeaderBlock(f":wave: Hello, I'm {details['user']}!"),
DividerBlock(),
SectionBlock("\n*Active in Channels:*"),
DividerBlock(),
SectionBlock(f"{channellist}"),
])
client.views_publish(
user_id = event['user'],
view = dict(type="home", **view)
)
29 changes: 0 additions & 29 deletions django_slackbot/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
import os

from slack_bolt import App
from slackblocks import SectionBlock, HeaderBlock, DividerBlock
from slackblocks.messages import BaseMessage
from crontab import CronTab

app = App(token=os.environ.get("SLACK_BOT_TOKEN"))
Expand All @@ -18,33 +16,6 @@ def _schedule(f):
return _schedule
app.schedule = app_schedule

class ViewMessage(BaseMessage):
def _resolve(self):
result = {**super()._resolve()}
result.pop("mrkdwn", None)
result.pop("text", None)
return result

@app.event("app_home_opened")
def app_home_opened(event, ack, client):
ack()
details = client.auth_test()
channels = client.users_conversations(types="public_channel,private_channel")
channellist = ''
for channel in channels['channels']:
channellist += f"* <#{channel['id']}>\n"
view = ViewMessage(blocks=[
HeaderBlock(f":wave: Hello, I'm {details['user']}!"),
DividerBlock(),
SectionBlock("\n*Active in Channels:*"),
DividerBlock(),
SectionBlock(f"{channellist}"),
])
client.views_publish(
user_id = event['user'],
view = dict(type="home", **view)
)

def check_access(client, group_id, user_id):
response = client.usergroups_users_list(usergroup=group_id)
return user_id in response['users']
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@


class FrinkiacConfig(AppConfig):
name = 'examples.frinkiac'
name = 'django_slackbot.frinkiac'
File renamed without changes.
3 changes: 2 additions & 1 deletion examples/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
'django.contrib.messages',
'django.contrib.staticfiles',
'django_slackbot',
'examples.frinkiac'
'django_slackbot.frinkiac',
'django_slackbot.app_home',
]

MIDDLEWARE = [
Expand Down

0 comments on commit ca893a3

Please sign in to comment.