Auto push to github
This commit is contained in:
parent
ae90dcde84
commit
b73bb47445
6
.idea/dictionaries/Dustin_Pianalto.xml
generated
6
.idea/dictionaries/Dustin_Pianalto.xml
generated
@ -2,15 +2,21 @@
|
|||||||
<dictionary name="Dustin.Pianalto">
|
<dictionary name="Dustin.Pianalto">
|
||||||
<words>
|
<words>
|
||||||
<w>aiohttp</w>
|
<w>aiohttp</w>
|
||||||
|
<w>aren</w>
|
||||||
<w>asctime</w>
|
<w>asctime</w>
|
||||||
<w>chans</w>
|
<w>chans</w>
|
||||||
<w>coro</w>
|
<w>coro</w>
|
||||||
<w>customsearch</w>
|
<w>customsearch</w>
|
||||||
|
<w>dinos</w>
|
||||||
<w>emojis</w>
|
<w>emojis</w>
|
||||||
<w>exts</w>
|
<w>exts</w>
|
||||||
<w>levelname</w>
|
<w>levelname</w>
|
||||||
<w>lockdown</w>
|
<w>lockdown</w>
|
||||||
<w>msecs</w>
|
<w>msecs</w>
|
||||||
|
<w>shootergame</w>
|
||||||
|
<w>shootergamemode</w>
|
||||||
|
<w>singleplayer</w>
|
||||||
|
<w>strftime</w>
|
||||||
</words>
|
</words>
|
||||||
</dictionary>
|
</dictionary>
|
||||||
</component>
|
</component>
|
||||||
@ -112,3 +112,13 @@ def generate_dino_files(dino_data, directory):
|
|||||||
int(dino['Dino Data']['DinoID2']))
|
int(dino['Dino Data']['DinoID2']))
|
||||||
with open(f'{directory}/{filename}', 'w') as f:
|
with open(f'{directory}/{filename}', 'w') as f:
|
||||||
dino.write(f, space_around_delimiters=False)
|
dino.write(f, space_around_delimiters=False)
|
||||||
|
|
||||||
|
|
||||||
|
def generate_files(storage_dir, ctx, filename, game_ini, dinos_data, mods):
|
||||||
|
if not os.path.isdir(f'{storage_dir}/{ctx.author.id}'):
|
||||||
|
os.mkdir(f'{storage_dir}/{ctx.author.id}')
|
||||||
|
directory = f'{storage_dir}/{ctx.author.id}/{filename}_' \
|
||||||
|
f'{ctx.message.created_at.strftime("%Y%m%dT%H%M%S")}'
|
||||||
|
os.mkdir(directory)
|
||||||
|
generate_game_ini(game_ini, mods, directory)
|
||||||
|
generate_dino_files(dinos_data, directory)
|
||||||
|
|||||||
@ -82,3 +82,21 @@ async def run_command(args):
|
|||||||
stdout, stderr = await process.communicate()
|
stdout, stderr = await process.communicate()
|
||||||
# Return stdout
|
# Return stdout
|
||||||
return stdout.decode().strip()
|
return stdout.decode().strip()
|
||||||
|
|
||||||
|
|
||||||
|
async def git_add(loop, directory, file):
|
||||||
|
return await asyncio.wait_for(loop.create_task(run_command(f'git -C {directory} add {file}')), 120)
|
||||||
|
|
||||||
|
|
||||||
|
async def git_commit(loop, directory, message):
|
||||||
|
return await asyncio.wait_for(loop.create_task(run_command(f'git -C {directory} commit -m {message}')), 120)
|
||||||
|
|
||||||
|
|
||||||
|
async def git_push(loop, directory):
|
||||||
|
result = await asyncio.wait_for(loop.create_task(run_command(f'git -C {directory} push')), 240)
|
||||||
|
return result if 'error: failed' in result else 'Completed'
|
||||||
|
|
||||||
|
|
||||||
|
async def git_pull(loop, directory):
|
||||||
|
result = await asyncio.wait_for(loop.create_task(run_command(f'git -C {directory} pull')), 240)
|
||||||
|
return result if 'CONFLICT' in result else 'Completed'
|
||||||
|
|||||||
@ -1,11 +1,12 @@
|
|||||||
import discord
|
import discord
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
from .imports import process_files
|
from .imports import process_files, utils
|
||||||
from configparser import ConfigParser
|
from configparser import ConfigParser
|
||||||
import os
|
import os
|
||||||
|
|
||||||
storage_dir = '../ASB_dino_submissions'
|
storage_dir = '../ASB_dino_submissions'
|
||||||
|
owner_id = 351794468870946827
|
||||||
|
|
||||||
|
|
||||||
class Uploader:
|
class Uploader:
|
||||||
@ -14,40 +15,64 @@ class Uploader:
|
|||||||
|
|
||||||
@commands.command(name='upload', aliases=['submit'])
|
@commands.command(name='upload', aliases=['submit'])
|
||||||
async def upload_dino(self, ctx, official: str='unofficial', singleplayer: bool=False):
|
async def upload_dino(self, ctx, official: str='unofficial', singleplayer: bool=False):
|
||||||
|
msg = await ctx.send('Processing... Please Wait')
|
||||||
if ctx.message.attachments:
|
if ctx.message.attachments:
|
||||||
attachment = ctx.message.attachments[0]
|
attachment = ctx.message.attachments[0]
|
||||||
if attachment.filename.endswith('.zip'):
|
if attachment.filename.endswith('.zip'):
|
||||||
|
async with ctx.typing():
|
||||||
with BytesIO() as file:
|
with BytesIO() as file:
|
||||||
await attachment.save(file)
|
await attachment.save(file)
|
||||||
unzipped = process_files.load_zip(file)
|
unzipped = process_files.load_zip(file)
|
||||||
game_ini, dinos_data, mods = process_files.process_files(unzipped)
|
game_ini, dinos_data, mods = process_files.process_files(unzipped)
|
||||||
if dinos_data == dict():
|
if dinos_data == dict():
|
||||||
await ctx.send('There aren\'t any DinoExport files in the zip file attached.\n'
|
await msg.edit(content='There aren\'t any DinoExport files in the zip file attached.\n'
|
||||||
'Please make sure the files have not been renamed.')
|
'Please make sure the files have not been renamed.')
|
||||||
else:
|
else:
|
||||||
if official == 'unofficial' and game_ini == ConfigParser():
|
if official == 'unofficial' and game_ini == ConfigParser():
|
||||||
await ctx.send('Game.ini is missing or is not valid.')
|
await msg.edit(content='Game.ini is missing or is not valid.')
|
||||||
return
|
return
|
||||||
elif official == 'official' and game_ini == ConfigParser():
|
elif official == 'official' and game_ini == ConfigParser():
|
||||||
if singleplayer:
|
if singleplayer:
|
||||||
game_ini.add_section('/script/shootergame.shootergamemode')
|
game_ini.add_section('/script/shootergame.shootergamemode')
|
||||||
game_ini.set('/script/shootergame.shootergamemode', 'bUseSingleplayerSettings', True)
|
game_ini.set('/script/shootergame.shootergamemode',
|
||||||
|
'bUseSingleplayerSettings',
|
||||||
|
True)
|
||||||
elif official not in ['official', 'unofficial']:
|
elif official not in ['official', 'unofficial']:
|
||||||
await ctx.send(f'{official} is not a valid option. Please specify "official" or '
|
await msg.edit(content=f'{official} is not a valid option. Please specify "official" '
|
||||||
f'"unofficial" or leave it blank to default to "unofficial"')
|
f'or "unofficial" or leave it blank to default to "unofficial"')
|
||||||
return
|
return
|
||||||
if not os.path.isdir(f'{storage_dir}/{ctx.author.id}'):
|
await msg.edit('Processing... Syncing with GitHub')
|
||||||
os.mkdir(f'{storage_dir}/{ctx.author.id}')
|
pull_status = utils.git_pull(self.bot.loop, storage_dir)
|
||||||
directory = f'{storage_dir}/{ctx.author.id}/{attachment.filename}_' \
|
if pull_status == 'Completed':
|
||||||
f'{ctx.message.created_at.strftime("%Y%m%dT%H%M%S")}'
|
await msg.edit('Processing... Sync complete... Generating new files')
|
||||||
os.mkdir(directory)
|
process_files.generate_files(storage_dir, ctx, attachment.filename,
|
||||||
process_files.generate_game_ini(game_ini, mods, directory)
|
game_ini, dinos_data, mods)
|
||||||
process_files.generate_dino_files(dinos_data, directory)
|
await msg.edit('Processing... Files generated... Committing changes')
|
||||||
await ctx.send('Upload complete.')
|
utils.git_add(self.bot.loop, storage_dir, '*')
|
||||||
|
utils.git_commit(self.bot.loop,
|
||||||
|
storage_dir,
|
||||||
|
f'Uploaded {len(dinos_data)} dinos {official}')
|
||||||
|
await msg.edit('Processing... Committed... Pushing files to GitHub')
|
||||||
|
push_status = utils.git_push(self.bot.loop, storage_dir)
|
||||||
|
if push_status == 'Completed':
|
||||||
|
await msg.edit(content=f'{ctx.author.mention} Upload complete.')
|
||||||
else:
|
else:
|
||||||
await ctx.send('Please attach a zip file to the command.')
|
await self.bot.get_user(owner_id).send(f'There was an error with git push'
|
||||||
|
f'\n{push_status}')
|
||||||
|
await msg.edit(content='There was an error pushing the files to GitHub\n'
|
||||||
|
'Dusty.P has been notified and will get this fixed')
|
||||||
else:
|
else:
|
||||||
await ctx.send('Please attach a zip file to the command.')
|
await self.bot.get_user(owner_id).send(f'There was an error with git pull\n'
|
||||||
|
f'{pull_status}')
|
||||||
|
process_files.generate_files('submissions_temp', ctx, attachment.filename,
|
||||||
|
game_ini, dinos_data, mods)
|
||||||
|
await msg.edit(content='Could not sync with GitHub.\n'
|
||||||
|
'Dusty.P has been notified and your files are stored in a '
|
||||||
|
'temporary location')
|
||||||
|
else:
|
||||||
|
await msg.edit(content='Please attach a zip file to the command.')
|
||||||
|
else:
|
||||||
|
await msg.edit(content='Please attach a zip file to the command.')
|
||||||
|
|
||||||
|
|
||||||
def setup(bot):
|
def setup(bot):
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user