|
@ -55,13 +55,11 @@ async def on_ready(): |
|
|
|
|
|
|
|
|
@bot.event |
|
|
@bot.event |
|
|
async def on_message(message): |
|
|
async def on_message(message): |
|
|
if running_on_panel == False: |
|
|
|
|
|
# Account link |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if not running_on_panel: |
|
|
# Binflop |
|
|
# Binflop |
|
|
if len(message.attachments) > 0: |
|
|
if len(message.attachments) > 0: |
|
|
if message.attachments[0].url.endswith( |
|
|
|
|
|
('.png', '.jpg', '.jpeg', '.mp4', '.mov', '.avi', '.gif', '.image')) == False: |
|
|
|
|
|
|
|
|
if not message.attachments[0].url.endswith( |
|
|
|
|
|
('.png', '.jpg', '.jpeg', '.mp4', '.mov', '.avi', '.gif', '.image')): |
|
|
download = message.attachments[0].url |
|
|
download = message.attachments[0].url |
|
|
async with aiohttp.ClientSession() as session: |
|
|
async with aiohttp.ClientSession() as session: |
|
|
async with session.get(download, allow_redirects=True) as r: |
|
|
async with session.get(download, allow_redirects=True) as r: |
|
@ -88,9 +86,10 @@ async def on_message(message): |
|
|
await timings.analyze_timings(message) |
|
|
await timings.analyze_timings(message) |
|
|
await bot.process_commands(message) |
|
|
await bot.process_commands(message) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@bot.event |
|
|
@bot.event |
|
|
async def on_raw_reaction_add(payload): |
|
|
async def on_raw_reaction_add(payload): |
|
|
if running_on_panel == True: |
|
|
|
|
|
|
|
|
if running_on_panel: |
|
|
global verification_message |
|
|
global verification_message |
|
|
global verification_channel |
|
|
global verification_channel |
|
|
if payload.message_id != verification_message: |
|
|
if payload.message_id != verification_message: |
|
@ -127,44 +126,47 @@ async def on_raw_reaction_add(payload): |
|
|
await member.edit(roles=[]) |
|
|
await member.edit(roles=[]) |
|
|
await member.send("Your Discord account has successfully been unlinked from your Panel account!") |
|
|
await member.send("Your Discord account has successfully been unlinked from your Panel account!") |
|
|
logging.info( |
|
|
logging.info( |
|
|
'successfully unlinked ' + member.name + "#" + str(member.discriminator) + " (" + str(member.id) + ")") |
|
|
|
|
|
|
|
|
'successfully unlinked ' + member.name + "#" + str(member.discriminator) + " (" + str( |
|
|
|
|
|
member.id) + ")") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@bot.command() |
|
|
@bot.command() |
|
|
async def ping(ctx): |
|
|
async def ping(ctx): |
|
|
if running_on_panel == True: |
|
|
|
|
|
|
|
|
if running_on_panel: |
|
|
await ctx.send(f'Private bot ping is {round(bot.latency * 1000)}ms') |
|
|
await ctx.send(f'Private bot ping is {round(bot.latency * 1000)}ms') |
|
|
if running_on_panel == False: |
|
|
|
|
|
|
|
|
if not running_on_panel: |
|
|
await ctx.send(f'Public bot ping is {round(bot.latency * 1000)}ms') |
|
|
await ctx.send(f'Public bot ping is {round(bot.latency * 1000)}ms') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@bot.command(name="react", pass_context=True) |
|
|
@bot.command(name="react", pass_context=True) |
|
|
@has_permissions(administrator=True) |
|
|
@has_permissions(administrator=True) |
|
|
async def react(ctx, url, reaction): |
|
|
async def react(ctx, url, reaction): |
|
|
if running_on_panel == False: |
|
|
|
|
|
|
|
|
if not running_on_panel: |
|
|
channel = await bot.fetch_channel(int(url.split("/")[5])) |
|
|
channel = await bot.fetch_channel(int(url.split("/")[5])) |
|
|
message = await channel.fetch_message(int(url.split("/")[6])) |
|
|
message = await channel.fetch_message(int(url.split("/")[6])) |
|
|
await message.add_reaction(reaction) |
|
|
await message.add_reaction(reaction) |
|
|
logging.info('reacted to ' + url + ' with ' + reaction) |
|
|
logging.info('reacted to ' + url + ' with ' + reaction) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@bot.command(name="lag", pass_context=True) |
|
|
@bot.command(name="lag", pass_context=True) |
|
|
@commands.guild_only() |
|
|
@commands.guild_only() |
|
|
async def lag(ctx): |
|
|
async def lag(ctx): |
|
|
if running_on_panel == False: |
|
|
|
|
|
|
|
|
if not running_on_panel: |
|
|
if ctx.guild.id == guild_id: |
|
|
if ctx.guild.id == guild_id: |
|
|
guild = discord.utils.get(bot.guilds, id=guild_id) |
|
|
guild = discord.utils.get(bot.guilds, id=guild_id) |
|
|
role = discord.utils.find(lambda r: r.id == crabwings_role_id, guild.roles) |
|
|
role = discord.utils.find(lambda r: r.id == crabwings_role_id, guild.roles) |
|
|
if role in ctx.author.roles: |
|
|
if role in ctx.author.roles: |
|
|
ssh_client = paramiko.SSHClient() |
|
|
ssh_client = paramiko.SSHClient() |
|
|
ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) |
|
|
ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) |
|
|
ssh_client.connect(hostname=crabwings_ip, username=crabwings_username, password=crabwings_password, port=crabwings_port) |
|
|
|
|
|
|
|
|
ssh_client.connect(hostname=crabwings_ip, username=crabwings_username, password=crabwings_password, |
|
|
|
|
|
port=crabwings_port) |
|
|
stdin, stdout, stderr = ssh_client.exec_command('service wings restart') |
|
|
stdin, stdout, stderr = ssh_client.exec_command('service wings restart') |
|
|
await ctx.send("Success, resolved Crabwings lag!") |
|
|
await ctx.send("Success, resolved Crabwings lag!") |
|
|
logging.info(".lag successfully executed by " + ctx.author.name + "#" + str(ctx.author.discriminator)) |
|
|
logging.info(".lag successfully executed by " + ctx.author.name + "#" + str(ctx.author.discriminator)) |
|
|
else: |
|
|
else: |
|
|
await ctx.send("You must be a Crabwings client/subuser to use this command.") |
|
|
await ctx.send("You must be a Crabwings client/subuser to use this command.") |
|
|
logging.info(".lag unsuccessfully attempted by " + ctx.author.name + "#" + str(ctx.author.discriminator)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
logging.info( |
|
|
|
|
|
".lag unsuccessfully attempted by " + ctx.author.name + "#" + str(ctx.author.discriminator)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@tasks.loop(minutes=10) |
|
|
@tasks.loop(minutes=10) |
|
@ -193,10 +195,10 @@ async def updater(): |
|
|
i += 1 |
|
|
i += 1 |
|
|
already_exists = False |
|
|
already_exists = False |
|
|
for server2 in modified_servers['servers']: |
|
|
for server2 in modified_servers['servers']: |
|
|
if already_exists == False: |
|
|
|
|
|
|
|
|
if not already_exists: |
|
|
if server['attributes']['uuid'] == server2['uuid']: |
|
|
if server['attributes']['uuid'] == server2['uuid']: |
|
|
already_exists = True |
|
|
already_exists = True |
|
|
if already_exists == False: |
|
|
|
|
|
|
|
|
if not already_exists: |
|
|
headers = { |
|
|
headers = { |
|
|
'Accept': 'application/json', |
|
|
'Accept': 'application/json', |
|
|
'Content-Type': 'application/json', |
|
|
'Content-Type': 'application/json', |
|
@ -207,13 +209,14 @@ async def updater(): |
|
|
server['attributes']['limits']['memory']) + ', "swap": 0, "disk": ' + str( |
|
|
server['attributes']['limits']['memory']) + ', "swap": 0, "disk": ' + str( |
|
|
server['attributes']['limits']['disk']) + ', "io": ' + str( |
|
|
server['attributes']['limits']['disk']) + ', "io": ' + str( |
|
|
server['attributes']['limits']['io']) + ', "cpu": ' + str( |
|
|
server['attributes']['limits']['io']) + ', "cpu": ' + str( |
|
|
server['attributes']['limits']['cpu']) + ', "threads": null, "feature_limits": { "databases": ' + str( |
|
|
|
|
|
|
|
|
server['attributes']['limits'][ |
|
|
|
|
|
'cpu']) + ', "threads": null, "feature_limits": { "databases": ' + str( |
|
|
server['attributes']['feature_limits']['databases']) + ', "allocations": ' + str( |
|
|
server['attributes']['feature_limits']['databases']) + ', "allocations": ' + str( |
|
|
server['attributes']['feature_limits']['allocations']) + ', "backups": 3 } }' |
|
|
server['attributes']['feature_limits']['allocations']) + ', "backups": 3 } }' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async with aiohttp.ClientSession() as session: |
|
|
async with aiohttp.ClientSession() as session: |
|
|
async with session.patch('https://panel.birdflop.com/api/application/servers/' + str(server['attributes']['id']) + '/build', headers=headers, data=data) as response: |
|
|
|
|
|
|
|
|
async with session.patch('https://panel.birdflop.com/api/application/servers/' + str( |
|
|
|
|
|
server['attributes']['id']) + '/build', headers=headers, data=data) as response: |
|
|
if response.status == 200: |
|
|
if response.status == 200: |
|
|
modified_servers['servers'].append({ |
|
|
modified_servers['servers'].append({ |
|
|
'uuid': str(server['attributes']['uuid']) |
|
|
'uuid': str(server['attributes']['uuid']) |
|
@ -226,7 +229,8 @@ async def updater(): |
|
|
|
|
|
|
|
|
logging.info("modified " + str(server['attributes']['name']) + ' with data ' + data) |
|
|
logging.info("modified " + str(server['attributes']['name']) + ' with data ' + data) |
|
|
else: |
|
|
else: |
|
|
logging.info("failed to modify " + str(server['attributes']['name']) + ' with data ' + data) |
|
|
|
|
|
|
|
|
logging.info( |
|
|
|
|
|
"failed to modify " + str(server['attributes']['name']) + ' with data ' + data) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Plugin Updater |
|
|
# Plugin Updater |
|
@ -292,7 +296,7 @@ async def before_updater(): |
|
|
await bot.wait_until_ready() |
|
|
await bot.wait_until_ready() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if running_on_panel == True: |
|
|
|
|
|
|
|
|
if running_on_panel: |
|
|
for file_name in os.listdir('./cogs'): |
|
|
for file_name in os.listdir('./cogs'): |
|
|
if file_name.endswith('_panel.py'): |
|
|
if file_name.endswith('_panel.py'): |
|
|
bot.load_extension(f'cogs.{file_name[:-3]}') |
|
|
bot.load_extension(f'cogs.{file_name[:-3]}') |
|
@ -301,7 +305,7 @@ else: |
|
|
if file_name.endswith('_public.py'): |
|
|
if file_name.endswith('_public.py'): |
|
|
bot.load_extension(f'cogs.{file_name[:-3]}') |
|
|
bot.load_extension(f'cogs.{file_name[:-3]}') |
|
|
|
|
|
|
|
|
if running_on_panel == True: |
|
|
|
|
|
|
|
|
if running_on_panel: |
|
|
print("running on panel, starting loops") |
|
|
print("running on panel, starting loops") |
|
|
updater.start() |
|
|
updater.start() |
|
|
linking_updater = bot.get_cog('Linking_updater') |
|
|
linking_updater = bot.get_cog('Linking_updater') |
|
|