Skip to content

Commit c8c5c50

Browse files
add support for matching to existing webhook's names as well as their IDs
1 parent 7c3aaa8 commit c8c5c50

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

botstrap.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -297,14 +297,23 @@ def create_webhook(self, name: str, channel_id_: int) -> str:
297297

298298
config_str += "\n#Webhooks\n"
299299
existing_webhooks = discord_client.get_all_guild_webhooks()
300-
for webhook_name, webhook_model in Webhooks :
300+
for webhook_name, webhook_model in Webhooks:
301+
formatted_webhook_name = webhook_name.replace("_", " ").title()
301302
for existing_hook in existing_webhooks:
302-
if existing_hook["id"] == str(webhook_model.id):
303+
if (
304+
# check the existing ID matches the configured one
305+
existing_hook["id"] == str(webhook_model.id)
306+
or (
307+
# check if the name and the channel ID match the configured ones
308+
existing_hook["name"] == formatted_webhook_name
309+
and existing_hook["channel_id"] == str(all_channels[webhook_name])
310+
)
311+
):
303312
webhook_id = existing_hook["id"]
304313
break
305314
else:
306315
webhook_channel_id = int(all_channels[webhook_name])
307-
webhook_id = discord_client.create_webhook(webhook_name, webhook_channel_id)
316+
webhook_id = discord_client.create_webhook(formatted_webhook_name, webhook_channel_id)
308317
config_str += f"webhooks_{webhook_name}__id={webhook_id}\n"
309318
config_str += f"webhooks_{webhook_name}__channel={all_channels[webhook_name]}\n"
310319

0 commit comments

Comments
 (0)