|
6 | 6 |
|
7 | 7 | from bottle import MultiDict |
8 | 8 |
|
9 | | -from models.github import EventType, convert_str_to_event_type |
| 9 | +from models.github import EventType, convert_keywords_to_events |
10 | 10 | from models.slack import Channel |
11 | 11 | from utils.json import JSON |
12 | 12 | from utils.storage import Storage |
@@ -60,11 +60,7 @@ def run_subscribe_command( |
60 | 60 | :param args: `list` of events to subscribe to. |
61 | 61 | """ |
62 | 62 | repo: str = args[0] |
63 | | - new_events: set[EventType] = { |
64 | | - convert_str_to_event_type(arg) for arg in args[1:] |
65 | | - } |
66 | | - # Remove all the entries which do not correspond to a correct [EventType]. |
67 | | - new_events -= {None} |
| 63 | + new_events = convert_keywords_to_events(args[1:]) |
68 | 64 | if repo in self.subscriptions: |
69 | 65 | channels: set[Channel] = self.subscriptions[repo] |
70 | 66 | channel: Channel | None = next( |
@@ -129,21 +125,21 @@ def run_unsubscribe_command( |
129 | 125 | if channel is not None: |
130 | 126 | # If this channel has subscribed to some events |
131 | 127 | # from this repo, update the list of events. |
132 | | - events = channel.events |
133 | | - for arg in args[1:]: |
134 | | - event: EventType | None = convert_str_to_event_type(arg) |
| 128 | + current_events = channel.events |
| 129 | + chosen_events = convert_keywords_to_events(args[1:]) |
| 130 | + for event in chosen_events: |
135 | 131 | try: |
136 | | - events.remove(event) |
| 132 | + current_events.remove(event) |
137 | 133 | except KeyError: |
138 | 134 | # This means that the user tried to unsubscribe from |
139 | 135 | # an event that wasn't subscribed to in the first place. |
140 | 136 | pass |
141 | 137 | self.subscriptions[repo].remove(channel) |
142 | | - if len(events) != 0: |
| 138 | + if len(current_events) != 0: |
143 | 139 | self.subscriptions[repo].add( |
144 | 140 | Channel( |
145 | 141 | name=current_channel, |
146 | | - events=events, |
| 142 | + events=current_events, |
147 | 143 | ) |
148 | 144 | ) |
149 | 145 | return self.run_list_command(current_channel=current_channel, ephemeral=True) |
@@ -186,6 +182,17 @@ def run_list_command( |
186 | 182 | "type": "divider", |
187 | 183 | }, |
188 | 184 | ] |
| 185 | + if len(blocks) == 0: |
| 186 | + prompt = "This channel has not yet subscribed to anything." |
| 187 | + prompt += "You can subscribe to your favorite repositories " |
| 188 | + prompt += "using the `/subscribe` command. For more info, use the `/help` command." |
| 189 | + |
| 190 | + blocks = [ |
| 191 | + { |
| 192 | + "type": "mrkdwn", |
| 193 | + "text": prompt, |
| 194 | + }, |
| 195 | + ] |
189 | 196 | return { |
190 | 197 | "response_type": "ephemeral" if ephemeral else "in_channel", |
191 | 198 | "blocks": blocks, |
@@ -222,9 +229,12 @@ def run_help_command() -> dict[str, Any]: |
222 | 229 | "text": ( |
223 | 230 | "*Events*\n" |
224 | 231 | "GitHub events are abbreviated as follows:\n" |
| 232 | + "0. `default` or no arguments: Subscribe " |
| 233 | + "to the most common and important events.\n" |
| 234 | + "1. `all` or `*`: Subscribe to every supported event.\n" |
225 | 235 | + " ".join( |
226 | 236 | [ |
227 | | - f"{i + 1}. `{event.keyword}`: {event.docs}\n" |
| 237 | + f"{i + 2}. `{event.keyword}`: {event.docs}\n" |
228 | 238 | for i, event in enumerate(EventType) |
229 | 239 | ] |
230 | 240 | ) |
|
0 commit comments