Skip to content

Commit

Permalink
add an optional alt template for thread naming
Browse files Browse the repository at this point in the history
  • Loading branch information
dariagrudzien committed Sep 11, 2023
1 parent edbf8e4 commit 057efe8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion juniorguru_chick/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ async def on_message(message: discord.Message) -> None:
elif channel_name == "past-vedle-pasti":
await create_thread(message, "{weekday} past na {author}")
elif channel_name == "můj-dnešní-objev":
await create_thread(message, "{weekday} objev od {author}")
await create_thread(message, "{weekday} objev od {author}", "Past na {author}: {name}")


@bot.event
Expand Down
8 changes: 5 additions & 3 deletions juniorguru_chick/lib/threads.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ async def fetch_starting_message(thread: discord.Thread) -> discord.Message | No
except discord.errors.NotFound:
return None

def name_thread(message: discord.Message, name_template) -> str | None:
"""If the message includes text in square brackets, use that as name for the thread. Otherwise, use the name template."""
def name_thread(message: discord.Message, name_template, alternative_name_template=None) -> str | None:
"""If the message includes text in square brackets, use that as name for the thread. Otherwise, use the provided name template."""
brackets_regex = re.compile(r"""
^
\[ # starts with [
Expand All @@ -43,7 +43,9 @@ def name_thread(message: discord.Message, name_template) -> str | None:
words = []
for part in parts:
words.append(part.strip())
name = ", ".join(words)
name_from_brackets = ", ".join(words)

name = alternative_name_template.format(author=message.author.display_name, name=name_from_brackets)
return name

else:
Expand Down

0 comments on commit 057efe8

Please sign in to comment.