@@ -43,12 +43,14 @@ def __init__(self, bot: Bot):
43
43
self .bot = bot
44
44
45
45
@staticmethod
46
- def _build_topic_embed (channel_id : int , previous_topic : None | str ) -> discord .Embed :
46
+ def _build_topic_embed (channel_id : int , previous_topic : None | str ) -> tuple [ discord .Embed , bool ] :
47
47
"""
48
48
Build an embed containing a conversation topic.
49
49
50
50
If in a Python channel, a python-related topic will be given.
51
51
Otherwise, a random conversation topic will be received by the user.
52
+
53
+ Also returns a value that determines whether or not to remove the reaction afterwards
52
54
"""
53
55
# No matter what, the form will be shown.
54
56
embed = discord .Embed (
@@ -66,7 +68,7 @@ def _build_topic_embed(channel_id: int, previous_topic: None | str) -> discord.E
66
68
67
69
if previous_topic is None :
68
70
# This is the first topic being sent
69
- return embed
71
+ return embed , False
70
72
71
73
total_topics = previous_topic .count ("\n " ) + 1
72
74
# Add 1 before first topic
@@ -78,8 +80,9 @@ def _build_topic_embed(channel_id: int, previous_topic: None | str) -> discord.E
78
80
# When the embed will be larger than the limit, use the previous embed instead
79
81
if len (embed .title ) > 256 :
80
82
embed .title = previous_topic
83
+ return embed , True
81
84
82
- return embed
85
+ return embed , False
83
86
84
87
@staticmethod
85
88
def _predicate (
@@ -119,7 +122,10 @@ async def _listen_for_refresh(
119
122
try :
120
123
# The returned discord.Message object from discord.Message.edit is different from the current
121
124
# discord.Message object, so it must be reassigned to update properly
122
- message = await message .edit (embed = self ._build_topic_embed (message .channel .id , message .embeds [0 ].title ))
125
+ embed , remove_reactions = self ._build_topic_embed (message .channel .id , message .embeds [0 ].title )
126
+ message = await message .edit (embed = embed )
127
+ if remove_reactions :
128
+ await message .clear_reaction ("🔄" )
123
129
except discord .NotFound :
124
130
break
125
131
@@ -135,7 +141,7 @@ async def topic(self, ctx: commands.Context) -> None:
135
141
136
142
Allows the refresh of a topic by pressing an emoji.
137
143
"""
138
- message = await ctx .send (embed = self ._build_topic_embed (ctx .channel .id , None ))
144
+ message = await ctx .send (embed = self ._build_topic_embed (ctx .channel .id , None )[ 0 ] )
139
145
self .bot .loop .create_task (self ._listen_for_refresh (ctx .author , message ))
140
146
141
147
0 commit comments