Skip to content

Commit

Permalink
greet
Browse files Browse the repository at this point in the history
  • Loading branch information
honzajavorek committed May 26, 2023
1 parent 9ed1154 commit 2bc337c
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 5 deletions.
9 changes: 7 additions & 2 deletions juniorguru_chick/bot.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import os
import asyncio
import logging

Expand Down Expand Up @@ -71,11 +70,17 @@ async def on_thread_create(thread: discord.Thread) -> None:
await handle_candidate_thread(starting_message, thread, is_bot)


async def add_intro_messages(thread: discord.Thread):
await thread.send(**intro.greet())
await thread.send(**intro.game())
await add_members_with_role(thread, intro.GREETER_ROLE_ID)


async def handle_intro_thread(starting_message: discord.Message, thread: discord.Thread, is_bot: bool) -> None:
emojis = intro.choose_intro_emojis(starting_message.content)
logger.info(f"Processing thread {thread.name!r} (reacting with {emojis!r} and more…)")
tasks = [ensure_thread_name(thread, intro.THREAD_NAME_TEMPLATE),
add_members_with_role(thread, intro.GREETER_ROLE_ID)]
add_intro_messages(thread)]
tasks.extend([starting_message.add_reaction(emoji) for emoji in emojis])
await asyncio.gather(*tasks)

Expand Down
50 changes: 47 additions & 3 deletions juniorguru_chick/lib/intro.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import re
from textwrap import dedent
from typing import Any

from discord import ui, ButtonStyle, Embed


GREETER_ROLE_ID = 1062755787153358879

THREAD_NAME_TEMPLATE = "Ahoj, já jsem {author}!"
THREAD_NAME_TEMPLATE = "Ahoj {author}!"

PATTERNS_EMOJIS_MAPPING = {
re.compile(r'\bpython\w*\b', re.I): ['<:python:842331892091322389>'],
Expand Down Expand Up @@ -45,10 +49,50 @@
}


def choose_intro_emojis(message_content: str) -> list[str]:
def choose_intro_emojis(intro_message_content: str) -> list[str]:
"""Returns a list of emoji reactions suitable for given message"""
emojis = set()
for pattern_re, pattern_emojis in PATTERNS_EMOJIS_MAPPING.items():
if pattern_re.search(message_content):
if pattern_re.search(intro_message_content):
emojis.update(pattern_emojis)
return ["👋", "🐣", "👍"] + list(emojis)


def greet() -> dict[str, Any]:
content = (
'Píp, píp! Tady kuře, místní robot. '
'Vítej v klubu 👋'
'\n\n'
'Dík, že se představuješ. '
'Když o tobě víme víc, můžeme ti líp radit <:meowthumbsup:842730599906279494> '
'\n\n'
# TODO https://github.com/juniorguru/juniorguru-chick/issues/12
'- Nevíš co dál? Popiš svou situaci do <#788826407412170752>\n'
'- Vybíráš kurz? Založ vlákno v <#1075052469303906335>\n'
'- Hledáš konkrétní recenze? Zkus vyhledávání\n'
'- Dotaz? Hurá do <#1067439203983568986>\n'
'- Záznamy přednášek? <#788822884948770846>\n'
'- Něco jiného? <#769966887055392768> snese cokoliv\n'
'- Nevíš, jak to tady funguje? Ptej se v <#806215364379148348>'
'\n\n'
'A nezapomeň, že junior.guru není jenom klub. '
'Tady aspoň dva odkazy, které fakt nechceš minout: '
)
view = ui.View(ui.Button(emoji='📖',
label='Příručka',
url='https://junior.guru/handbook/',
style=ButtonStyle.secondary),
ui.Button(emoji='🧑‍🏫',
label='Kurzy',
url='https://junior.guru/courses/',
style=ButtonStyle.secondary))
return dict(content=content, view=view)


def game() -> dict[str, Any]:
content = (
'Pokud chceš, můžeme si tady teď zahrát malou hru. '
'Napiš o sobě **tři krátké věty**. Dvě pravdy a jednu lež. '
'Ostatní můžou hádat, co z toho není pravda 😎 '
)
return dict(content=content)

0 comments on commit 2bc337c

Please sign in to comment.