Browse Source

Update bot.py

pull/6/head
Purpur 4 years ago
committed by GitHub
parent
commit
30f5d04eff
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 86
      bot.py

86
bot.py

@ -76,7 +76,6 @@ async def on_message(message):
await timings.analyze_timings(message)
await bot.process_commands(message)
@bot.event
async def on_raw_reaction_add(payload):
global verification_message
@ -134,6 +133,89 @@ async def react(ctx, url, reaction):
@tasks.loop(minutes=10)
async def updater():
logging.info("Synchronizing roles")
file = open('users.json', 'r')
data = json.load(file)
file.close()
guild = bot.get_guild(guild_id)
i = -1
for client in data['users']:
i += 1
member = guild.get_member(client['discord_id'])
if member:
api_key = client['client_api_key']
url = "https://panel.birdflop.com/api/client"
headers = {
'Accept': 'application/json',
'Authorization': 'Bearer ' + api_key,
}
async with aiohttp.ClientSession() as session:
async with session.get(url, headers=headers) as response:
if response.status == 200:
# Formats response for servers in JSON format
servers_json_response = await response.json()
user_client = False
user_subuser = False
user_crabwings = False
user_duckfeet = False
user_elktail = False
for server in servers_json_response['data']:
server_owner = server['attributes']['server_owner']
if server_owner == True:
user_client = True
elif server_owner == False:
user_subuser = True
server_node = server['attributes']['node']
if server_node == "Crabwings - NYC":
user_crabwings = True
elif server_node == "Duckfeet - EU":
user_duckfeet = True
elif server_node == "Elktail - EU":
user_elktail = True
role = discord.utils.get(guild.roles, id=client_role_id)
if user_client == True:
await member.add_roles(role)
else:
await member.remove_roles(role)
role = discord.utils.get(guild.roles, id=subuser_role_id)
if user_subuser == True:
await member.add_roles(role)
else:
await member.remove_roles(role)
role = discord.utils.get(guild.roles, id=crabwings_role_id)
if user_crabwings == True:
await member.add_roles(role)
else:
await member.remove_roles(role)
role = discord.utils.get(guild.roles, id=duckfeet_role_id)
if user_duckfeet == True:
await member.add_roles(role)
else:
await member.remove_roles(role)
role = discord.utils.get(guild.roles, id=elktail_role_id)
if user_elktail == True:
await member.add_roles(role)
else:
await member.remove_roles(role)
else:
data['users'].pop(i)
json_dumps = json.dumps(data, indent=2)
file = open('users.json', 'w')
file.write(json_dumps)
file.close()
await member.edit(roles=[])
logging.info("removed discord_id " + str(client['discord_id']) + " with client_id " + str(
client['client_id']) + " and INVALID client_api_key " + client['client_api_key'])
else:
data['users'].pop(i)
json_dumps = json.dumps(data, indent=2)
file = open('users.json', 'w')
file.write(json_dumps)
file.close()
logging.info("removed discord_id " + str(client['discord_id']) + " with client_id " + str(
client['client_id']) + " and client_api_key " + client['client_api_key'])
# Update backups
logging.info('Ensuring backups')
url = "https://panel.birdflop.com/api/application/servers"
@ -264,6 +346,8 @@ for file_name in os.listdir('./cogs'):
bot.load_extension(f'cogs.{file_name[:-3]}')
updater.start()
linking_updater = bot.get_cog('Linking_updater')
await linking_updater.linking_updater.start()
bot.run(token)
# full name: message.author.name + "#" + str(message.author.discriminator) + " (" + str(message.author.id) + ")"

Loading…
Cancel
Save