2022-05-04 23:09:46 +00:00
|
|
|
import requests
|
|
|
|
import threading
|
|
|
|
from .const import *
|
|
|
|
|
2022-07-10 14:25:42 +00:00
|
|
|
headers = {"Authorization": f"Bot {DISCORD_BOT_TOKEN}"}
|
|
|
|
|
2022-05-04 23:09:46 +00:00
|
|
|
def discord_wrap(f):
|
|
|
|
|
|
|
|
def wrapper(*args, **kwargs):
|
|
|
|
|
|
|
|
user=args[0]
|
|
|
|
if not user.discord_id:
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
thread=threading.Thread(target=f, args=args, kwargs=kwargs)
|
|
|
|
thread.start()
|
|
|
|
|
|
|
|
wrapper.__name__=f.__name__
|
|
|
|
return wrapper
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@discord_wrap
|
|
|
|
def add_role(user, role_name):
|
|
|
|
role_id = ROLES[role_name]
|
2022-07-08 16:21:13 +00:00
|
|
|
url = f"https://discordapp.com/api/guilds/{DISCORD_SERVER_ID}/members/{user.discord_id}/roles/{role_id}"
|
2022-05-04 23:09:46 +00:00
|
|
|
requests.put(url, headers=headers, timeout=5)
|
|
|
|
|
|
|
|
@discord_wrap
|
|
|
|
def remove_role(user, role_name):
|
|
|
|
role_id = ROLES[role_name]
|
2022-07-08 16:21:13 +00:00
|
|
|
url = f"https://discordapp.com/api/guilds/{DISCORD_SERVER_ID}/members/{user.discord_id}/roles/{role_id}"
|
2022-05-04 23:09:46 +00:00
|
|
|
requests.delete(url, headers=headers, timeout=5)
|
|
|
|
|
|
|
|
@discord_wrap
|
|
|
|
def remove_user(user):
|
2022-07-08 16:21:13 +00:00
|
|
|
url=f"https://discordapp.com/api/guilds/{DISCORD_SERVER_ID}/members/{user.discord_id}"
|
2022-05-04 23:09:46 +00:00
|
|
|
requests.delete(url, headers=headers, timeout=5)
|
|
|
|
|
|
|
|
@discord_wrap
|
|
|
|
def set_nick(user, nick):
|
2022-07-08 16:21:13 +00:00
|
|
|
url=f"https://discordapp.com/api/guilds/{DISCORD_SERVER_ID}/members/{user.discord_id}"
|
2022-05-04 23:09:46 +00:00
|
|
|
data={"nick": nick}
|
|
|
|
requests.patch(url, headers=headers, json=data, timeout=5)
|
|
|
|
|
|
|
|
def send_discord_message(message):
|
|
|
|
data={"content": message}
|
|
|
|
requests.post("https://discordapp.com/api/channels/924485611715452940/messages", headers=headers, data=data, timeout=5)
|
2022-07-10 14:25:42 +00:00
|
|
|
requests.post("https://discordapp.com/api/channels/924486091795484732/messages", headers=headers, data=data, timeout=5)
|
|
|
|
|
|
|
|
def send_wpd_message(message):
|
|
|
|
data={"content": message}
|
2022-08-25 13:35:28 +00:00
|
|
|
requests.post("https://discordapp.com/api/channels/1012354438113017896/messages", headers=headers, data=data, timeout=5)
|