Skip to content

Commit

Permalink
Merge branch 'main' into feat/events
Browse files Browse the repository at this point in the history
  • Loading branch information
abhayymishraa authored Jan 29, 2025
2 parents b66121a + 5ea79c2 commit 53d9e26
Show file tree
Hide file tree
Showing 9 changed files with 234 additions and 47 deletions.
16 changes: 16 additions & 0 deletions backend/apps/slack/MANIFEST.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,22 @@ features:
url: https://nest.owasp.dev/integrations/slack/commands/
description: Browse OWASP events
should_escape: false
- command: /news
url: https://nest.owasp.dev/integrations/slack/commands/
description: OWASP news
should_escape: false
- command: /contact
url: https://nest.owasp.dev/integrations/slack/commands/
description: Contact OWASP
should_escape: false
- command: /community
url: https://nest.owasp.dev/integrations/slack/commands/
description: Explore OWASP community
should_escape: false
- command: /users
url: https://nest.owasp.dev/integrations/slack/commands/
description: OWASP users list
should_escape: false
oauth_config:
scopes:
user:
Expand Down
2 changes: 2 additions & 0 deletions backend/apps/slack/commands/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
board,
chapters,
committees,
community,
contact,
contribute,
donate,
Expand All @@ -15,4 +16,5 @@
projects,
sponsors,
staff,
users,
)
30 changes: 30 additions & 0 deletions backend/apps/slack/commands/community.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"""Slack bot community command."""

from django.conf import settings

from apps.common.constants import NL
from apps.slack.apps import SlackConfig
from apps.slack.blocks import markdown

COMMAND = "/community"


def community_handler(ack, command, client):
"""Slack /community command handler."""
ack()

if not settings.SLACK_COMMANDS_ENABLED:
return

blocks = [
markdown(
f"Please visit <https://nest.owasp.dev/community/users/|OWASP community> page{NL}"
),
]

conversation = client.conversations_open(users=command["user_id"])
client.chat_postMessage(channel=conversation["channel"]["id"], blocks=blocks)


if SlackConfig.app:
community_handler = SlackConfig.app.command(COMMAND)(community_handler)
8 changes: 8 additions & 0 deletions backend/apps/slack/commands/owasp.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def owasp_handler(ack, command, client):
board,
chapters,
committees,
community,
contact,
contribute,
donate,
Expand All @@ -28,6 +29,7 @@ def owasp_handler(ack, command, client):
projects,
sponsors,
staff,
users,
)

ack()
Expand All @@ -41,6 +43,7 @@ def owasp_handler(ack, command, client):
f"• `{COMMAND} board` -- OWASP Global Board information{NL}"
f"• `{COMMAND} chapters` -- Explore OWASP chapters{NL}"
f"• `{COMMAND} committees` -- Explore OWASP committees{NL}"
f"• `{COMMAND} community` -- Explore OWASP community{NL}"
f"• `{COMMAND} contact` -- Contact OWASP{NL}"
f"• `{COMMAND} contribute` -- OWASP projects contribution opportunities{NL}"
f"• `{COMMAND} donate` -- Support OWASP with a donation{NL}"
Expand All @@ -52,6 +55,7 @@ def owasp_handler(ack, command, client):
f"• `{COMMAND} projects` -- Explore OWASP projects{NL}"
f"• `{COMMAND} sponsors` -- Get a list of OWASP sponsors{NL}"
f"• `{COMMAND} staff` -- OWASP corporate structure{NL}"
f"• `{COMMAND} users` -- OWASP contributors{NL}"
),
]
conversation = client.conversations_open(users=command["user_id"])
Expand All @@ -66,6 +70,8 @@ def owasp_handler(ack, command, client):
chapters.chapters_handler(ack, command, client)
case "committees":
committees.committees_handler(ack, command, client)
case "community":
community.community_handler(ack, command, client)
case "contact":
contact.contact_handler(ack, command, client)
case "contribute":
Expand All @@ -88,6 +94,8 @@ def owasp_handler(ack, command, client):
sponsors.sponsors_handler(ack, command, client)
case "staff":
staff.staff_handler(ack, command, client)
case "users":
users.users_handler(ack, command, client)
case _:
blocks = [
markdown(f"*`{COMMAND} {escape(handler)}` is not supported*{NL}"),
Expand Down
28 changes: 28 additions & 0 deletions backend/apps/slack/commands/users.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""Slack bot users command."""

from django.conf import settings

from apps.common.constants import NL
from apps.slack.apps import SlackConfig
from apps.slack.blocks import markdown

COMMAND = "/users"


def users_handler(ack, command, client):
"""Slack /users command handler."""
ack()

if not settings.SLACK_COMMANDS_ENABLED:
return

blocks = [
markdown(f"Please visit <https://nest.owasp.dev/users/users/|OWASP users> page{NL}"),
]

conversation = client.conversations_open(users=command["user_id"])
client.chat_postMessage(channel=conversation["channel"]["id"], blocks=blocks)


if SlackConfig.app:
users_handler = SlackConfig.app.command(COMMAND)(users_handler)
2 changes: 2 additions & 0 deletions backend/apps/slack/events/app_home_opened.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def app_home_opened_handler(event, client, ack):
f"{TAB}• /board{NL}"
f"{TAB}• /chapters{NL}"
f"{TAB}• /committees{NL}"
f"{TAB}• /community{NL}"
f"{TAB}• /contact{NL}"
f"{TAB}• /contribute{NL}"
f"{TAB}• /donate{NL}"
Expand All @@ -48,6 +49,7 @@ def app_home_opened_handler(event, client, ack):
f"{TAB}• /projects{NL}"
f"{TAB}• /sponsors{NL}"
f"{TAB}• /staff{NL}"
f"{TAB}• /users{NL}"
),
],
}
Expand Down
Loading

0 comments on commit 53d9e26

Please sign in to comment.