Fix mc!stopchathere command being broken

Fix webhook deletion logic
master
Tristan Gosselin-Hane 6 years ago
parent 4b34297695
commit 8560604c29
No known key found for this signature in database
GPG Key ID: D2282BE1CF7B78DA
  1. 14
      minecraft-discord-bridge/minecraft_discord_bridge.py

@ -405,7 +405,7 @@ def main():
channel_webhooks = await discord_channel.webhooks() channel_webhooks = await discord_channel.webhooks()
found = False found = False
for webhook in channel_webhooks: for webhook in channel_webhooks:
if webhook.name == "_minecraft": if webhook.name == "_minecraft" and webhook.user == discord_bot.user:
WEBHOOKS.append(webhook.url) WEBHOOKS.append(webhook.url)
found = True found = True
log.debug("Found webhook {} in channel {}".format(webhook.name, discord_channel.name)) log.debug("Found webhook {} in channel {}".format(webhook.name, discord_channel.name))
@ -545,16 +545,20 @@ def main():
deleted = session.query(DiscordChannel).filter_by(channel_id=this_channel).delete() deleted = session.query(DiscordChannel).filter_by(channel_id=this_channel).delete()
session.commit() session.commit()
session.close() session.close()
for webhook in message.channel: for webhook in await message.channel.webhooks():
if webhook.name == "_minecraft": if webhook.name == "_minecraft" and webhook.user == discord_bot.user:
del WEBHOOKS[webhook.url] # Copy the list to avoid some problems since
# we're deleting indicies form it as we loop
# through it
if webhook.url in WEBHOOKS[:]:
WEBHOOKS.remove(webhook.url)
await webhook.delete() await webhook.delete()
if deleted < 1: if deleted < 1:
msg = "The bot was not chatting here!" msg = "The bot was not chatting here!"
await message.channel.send(msg) await message.channel.send(msg)
return return
else: else:
msg = "The bot will no longer here!" msg = "The bot will no longer chat here!"
await message.channel.send(msg) await message.channel.send(msg)
return return

Loading…
Cancel
Save