mirror of
https://github.com/TitanEmbeds/Titan.git
synced 2024-12-25 22:47:04 +01:00
Delete webhooks if too much during message post
This commit is contained in:
parent
2a1e6ffe98
commit
018d73a43c
@ -168,7 +168,10 @@ def get_channel_webhook_url(guild_id, channel_id):
|
|||||||
if channel_id == webhook["channel_id"] and webhook["name"] == name:
|
if channel_id == webhook["channel_id"] and webhook["name"] == name:
|
||||||
return {
|
return {
|
||||||
"id": webhook["id"],
|
"id": webhook["id"],
|
||||||
"token": webhook["token"]
|
"token": webhook["token"],
|
||||||
|
"name": webhook.get("name"),
|
||||||
|
"guild_id": webhook.get("guild_id"),
|
||||||
|
"channel_id": webhook.get("channel_id")
|
||||||
}
|
}
|
||||||
webhook = discord_api.create_webhook(channel_id, name)
|
webhook = discord_api.create_webhook(channel_id, name)
|
||||||
if webhook and "content" in webhook:
|
if webhook and "content" in webhook:
|
||||||
@ -176,6 +179,24 @@ def get_channel_webhook_url(guild_id, channel_id):
|
|||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def delete_webhook_if_too_much(webhook):
|
||||||
|
if not webhook:
|
||||||
|
return
|
||||||
|
guild_id = webhook["guild_id"]
|
||||||
|
if guild_webhooks_enabled(guild_id):
|
||||||
|
guild = redisqueue.get_guild(guild_id)
|
||||||
|
guild_webhooks = guild["webhooks"]
|
||||||
|
total_wh_cnt = len(guild_webhooks)
|
||||||
|
titan_wh_cnt = 0
|
||||||
|
for wh in guild_webhooks:
|
||||||
|
if wh["name"].startswith("[Titan] "):
|
||||||
|
titan_wh_cnt = titan_wh_cnt + 1
|
||||||
|
if titan_wh_cnt > 0 and total_wh_cnt >= 8:
|
||||||
|
try:
|
||||||
|
discord_api.delete_webhook(webhook["id"], webhook["token"])
|
||||||
|
except:
|
||||||
|
pass # not my problem now
|
||||||
|
|
||||||
def get_all_users(guild_id):
|
def get_all_users(guild_id):
|
||||||
users = redisqueue.list_guild_members(guild_id)
|
users = redisqueue.list_guild_members(guild_id)
|
||||||
mem = []
|
mem = []
|
||||||
@ -334,6 +355,7 @@ def post():
|
|||||||
username = username + "#" + str(session['discriminator'])
|
username = username + "#" + str(session['discriminator'])
|
||||||
avatar = session['avatar']
|
avatar = session['avatar']
|
||||||
message = discord_api.execute_webhook(webhook.get("id"), webhook.get("token"), username, avatar, content, file)
|
message = discord_api.execute_webhook(webhook.get("id"), webhook.get("token"), username, avatar, content, file)
|
||||||
|
delete_webhook_if_too_much(webhook)
|
||||||
else:
|
else:
|
||||||
message = discord_api.create_message(channel_id, content, file)
|
message = discord_api.create_message(channel_id, content, file)
|
||||||
status_code = message['code']
|
status_code = message['code']
|
||||||
|
Loading…
Reference in New Issue
Block a user