upload_dino command

This commit is contained in:
Dusty.P 2018-05-09 01:25:39 -08:00
parent 370051c1b3
commit cbd19659b0
3 changed files with 48 additions and 16 deletions

View File

@ -27,7 +27,9 @@
"Dino Data",
"Colorization",
"Max Character Status Values",
"Dino Ancestry"
"Dino Ancestry",
"DinoAncestors",
"DinoAncestorsMale"
]
},
"mods": {

View File

@ -12,11 +12,8 @@ class MissingFile(Exception):
pass
def open_zip(file: str) -> zipfile.ZipFile:
if file.endswith('.zip'):
def load_zip(file) -> zipfile.ZipFile:
return zipfile.ZipFile(file)
else:
raise FileNotFoundError('File name must end in .zip')
def check_for_mods(game_file) -> list:
@ -104,7 +101,7 @@ def generate_game_ini(game_config, mods, directory):
print(game_config.sections())
if mods:
game_config['/script/shootergame.shootergamemode']['ModIDS'] = ', '.join(mods)
with open(f'{directory}Game.ini', 'w') as f:
with open(f'{directory}/Game.ini', 'w') as f:
game_config.write(f, space_around_delimiters=False)
@ -113,5 +110,5 @@ def generate_dino_files(dino_data, directory):
print(filename)
dino['Dino Data']['Guid'] = guid.get_guid_string(int(dino['Dino Data']['DinoID1']),
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)

View File

@ -1,20 +1,53 @@
import discord
from discord.ext import commands
from io import BytesIO
from .imports import process_files
from configparser import ConfigParser
import os
storage_dir = '../ASB_dino_submissions'
class Uploader:
def __init__(self, bot):
self.bot = bot
@commands.command(name='submit', aliases=['upload'])
async def upload_dino(self, ctx, official: str='unofficial'):
if official == 'unofficial':
pass
elif official == 'official':
pass
@commands.command(name='upload', aliases=['submit'])
async def upload_dino(self, ctx, official: str='unofficial', singleplayer: bool=False):
if ctx.message.attachments:
attachment = ctx.message.attachements[0]
if attachment.filename.endswith('.zip'):
with BytesIO() as file:
await attachment.save(file)
unzipped = process_files.load_zip(file)
game_ini, dinos_data, mods = process_files.process_files(unzipped)
if dinos_data == dict():
await ctx.send('There aren\'t any DinoExport files in the zip file attached.\n'
'Please make sure the files have not been renamed.')
else:
await ctx.send(f'{official} is not a valid option. Please specify "official" or "unofficial" or leave it '
f'blank to default to "unofficial"')
if official == 'unofficial' and game_ini == ConfigParser():
await ctx.send('Game.ini is missing or is not valid.')
return
elif official == 'official' and game_ini == ConfigParser():
if singleplayer:
game_ini.add_section('/script/shootergame.shootergamemode')
game_ini.set('/script/shootergame.shootergamemode', 'bUseSingleplayerSettings', True)
elif official not in ['official', 'unofficial']:
await ctx.send(f'{official} is not a valid option. Please specify "official" or '
f'"unofficial" or leave it blank to default to "unofficial"')
return
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}/{attachment.filename}_' \
f'{ctx.message.created_at.strftime("%Y%m%dT%H%M%S")}'
os.mkdir(directory)
process_files.generate_game_ini(game_ini, directory, mods)
process_files.generate_dino_files(dinos_data, directory)
await ctx.send('Upload complete.')
else:
await ctx.send('Please attach a zip file to the command.')
else:
await ctx.send('Please attach a zip file to the command.')
def setup(bot):