@@ -31,18 +31,29 @@ def run(self, raw_json: MultiDict) -> dict[str, Any] | None:
3131 current_channel : str = "#" + json ["channel_name" ]
3232 command : str = json ["command" ]
3333 args : list [str ] = str (json ["text" ]).split ()
34+ result : dict [str , Any ] | None = None
3435 if command == "/subscribe" and len (args ) > 0 :
35- self .run_subscribe_command (current_channel = current_channel , args = args )
36+ result = self .run_subscribe_command (
37+ current_channel = current_channel ,
38+ args = args ,
39+ )
3640 elif command == "/unsubscribe" and len (args ) > 0 :
37- self .run_unsubscribe_command (current_channel = current_channel , args = args )
41+ result = self .run_unsubscribe_command (
42+ current_channel = current_channel ,
43+ args = args ,
44+ )
3845 elif command == "/list" :
39- return self .run_list_command (current_channel = current_channel )
46+ result = self .run_list_command (current_channel = current_channel )
4047 elif command == "/help" :
41- return self .run_help_command ()
48+ result = self .run_help_command ()
4249 Storage .export_subscriptions (self .subscriptions )
43- return None
50+ return result
4451
45- def run_subscribe_command (self , current_channel : str , args : list [str ]) -> None :
52+ def run_subscribe_command (
53+ self ,
54+ current_channel : str ,
55+ args : list [str ],
56+ ) -> dict [str , Any ]:
4657 """
4758 Triggered by "/subscribe". Adds the passed events to the channel's subscriptions.
4859 :param current_channel: Name of the current channel.
@@ -93,8 +104,13 @@ def run_subscribe_command(self, current_channel: str, args: list[str]) -> None:
93104 events = new_events ,
94105 )
95106 }
107+ return self .run_list_command (current_channel = current_channel , ephemeral = True )
96108
97- def run_unsubscribe_command (self , current_channel : str , args : list [str ]) -> None :
109+ def run_unsubscribe_command (
110+ self ,
111+ current_channel : str ,
112+ args : list [str ],
113+ ) -> dict [str , Any ]:
98114 """
99115 Triggered by "/unsubscribe". Removes the passed events from the channel's subscriptions.
100116 :param current_channel: Name of the current channel.
@@ -130,11 +146,17 @@ def run_unsubscribe_command(self, current_channel: str, args: list[str]) -> None
130146 events = events ,
131147 )
132148 )
149+ return self .run_list_command (current_channel = current_channel , ephemeral = True )
133150
134- def run_list_command (self , current_channel : str ) -> dict [str , Any ]:
151+ def run_list_command (
152+ self ,
153+ current_channel : str ,
154+ ephemeral : bool = False ,
155+ ) -> dict [str , Any ]:
135156 """
136157 Triggered by "/list". Sends a message listing the current channel's subscriptions.
137158 :param current_channel: Name of the current channel.
159+ :param ephemeral: Whether message should be ephemeral or not.
138160 :return: Message containing subscriptions for the passed channel.
139161 """
140162 blocks : list [dict ] = []
@@ -149,7 +171,9 @@ def run_list_command(self, current_channel: str) -> dict[str, Any]:
149171 )
150172 if channel is None :
151173 continue
152- events_string = ", " .join (event .keyword for event in channel .events )
174+ events_string = ", " .join (
175+ f"`{ event .name .lower ()} `" for event in channel .events
176+ )
153177 blocks += [
154178 {
155179 "type" : "section" ,
@@ -163,7 +187,7 @@ def run_list_command(self, current_channel: str) -> dict[str, Any]:
163187 },
164188 ]
165189 return {
166- "response_type" : "in_channel" ,
190+ "response_type" : "ephemeral" if ephemeral else " in_channel" ,
167191 "blocks" : blocks ,
168192 }
169193
0 commit comments