Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to view previous topics with .topic command #1148

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Prev Previous commit
Next Next commit
Move form link to description
Because embed footers can't have markup, the topic suggestion hyperlink can't be in it. This commit moves it from the footer to the description of the embed.
Anonymous4045 committed May 12, 2024
commit d763ea933476133518483edd864cbbe00a8c59b8
19 changes: 13 additions & 6 deletions bot/exts/utilities/conversationstarters.py
Original file line number Diff line number Diff line change
@@ -41,7 +41,7 @@
self.bot = bot

@staticmethod
def _build_topic_embed(channel_id: int, previous_topic: None | str) -> tuple[discord.Embed, bool]:
def _build_topic_embed(channel_id: int, previous_description: None | str) -> tuple[discord.Embed, bool]:
"""
Build an embed containing a conversation topic.

@@ -53,13 +53,17 @@
footer = f"Suggest more topics [here]({SUGGESTION_FORM})!"
max_topics = 3

# Remove footer from previous description
previous_topic = None
if previous_description:
previous_topic = previous_description.split("\n\n")[0]
print(previous_topic)

Check failure on line 60 in bot/exts/utilities/conversationstarters.py

GitHub Actions / lint / Run linting & tests

Ruff (T201)

bot/exts/utilities/conversationstarters.py:60:13: T201 `print` found

embed = discord.Embed(
title="Conversation Starter",
color=discord.Colour.og_blurple()
)

embed.set_footer(text=footer)

try:
channel_topics = TOPICS[str(channel_id)]
except KeyError:
@@ -68,23 +72,26 @@
else:
new_topic = next(channel_topics)

def add_description(text: str) -> None:
embed.description = f"{text}\n\n{footer}"

if previous_topic is None:
# This is the first topic being sent
embed.description = new_topic
add_description(new_topic)
return embed, False

total_topics = previous_topic.count("\n") + 1

# Handle forced reactions after clear
if total_topics >= max_topics:
embed.description = previous_topic
add_description(new_topic)
return embed, True

# Add 1 before first topic
if total_topics == 1:
previous_topic = f"1. {previous_topic}"

embed.description = previous_topic + f"\n{total_topics + 1}. {new_topic}"
add_description(f"{previous_topic}\n{total_topics + 1}. {new_topic}")

# If this is the last topic, remove the reaction
if total_topics == max_topics - 1: