upload_dino command
This commit is contained in:
parent
370051c1b3
commit
cbd19659b0
@ -27,7 +27,9 @@
|
|||||||
"Dino Data",
|
"Dino Data",
|
||||||
"Colorization",
|
"Colorization",
|
||||||
"Max Character Status Values",
|
"Max Character Status Values",
|
||||||
"Dino Ancestry"
|
"Dino Ancestry",
|
||||||
|
"DinoAncestors",
|
||||||
|
"DinoAncestorsMale"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"mods": {
|
"mods": {
|
||||||
|
|||||||
@ -12,11 +12,8 @@ class MissingFile(Exception):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def open_zip(file: str) -> zipfile.ZipFile:
|
def load_zip(file) -> zipfile.ZipFile:
|
||||||
if file.endswith('.zip'):
|
return zipfile.ZipFile(file)
|
||||||
return zipfile.ZipFile(file)
|
|
||||||
else:
|
|
||||||
raise FileNotFoundError('File name must end in .zip')
|
|
||||||
|
|
||||||
|
|
||||||
def check_for_mods(game_file) -> list:
|
def check_for_mods(game_file) -> list:
|
||||||
@ -104,7 +101,7 @@ def generate_game_ini(game_config, mods, directory):
|
|||||||
print(game_config.sections())
|
print(game_config.sections())
|
||||||
if mods:
|
if mods:
|
||||||
game_config['/script/shootergame.shootergamemode']['ModIDS'] = ', '.join(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)
|
game_config.write(f, space_around_delimiters=False)
|
||||||
|
|
||||||
|
|
||||||
@ -113,5 +110,5 @@ def generate_dino_files(dino_data, directory):
|
|||||||
print(filename)
|
print(filename)
|
||||||
dino['Dino Data']['Guid'] = guid.get_guid_string(int(dino['Dino Data']['DinoID1']),
|
dino['Dino Data']['Guid'] = guid.get_guid_string(int(dino['Dino Data']['DinoID1']),
|
||||||
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)
|
||||||
|
|||||||
@ -1,20 +1,53 @@
|
|||||||
import discord
|
import discord
|
||||||
from discord.ext import commands
|
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:
|
class Uploader:
|
||||||
def __init__(self, bot):
|
def __init__(self, bot):
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
|
|
||||||
@commands.command(name='submit', aliases=['upload'])
|
@commands.command(name='upload', aliases=['submit'])
|
||||||
async def upload_dino(self, ctx, official: str='unofficial'):
|
async def upload_dino(self, ctx, official: str='unofficial', singleplayer: bool=False):
|
||||||
if official == 'unofficial':
|
if ctx.message.attachments:
|
||||||
pass
|
attachment = ctx.message.attachements[0]
|
||||||
elif official == 'official':
|
if attachment.filename.endswith('.zip'):
|
||||||
pass
|
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:
|
||||||
|
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:
|
else:
|
||||||
await ctx.send(f'{official} is not a valid option. Please specify "official" or "unofficial" or leave it '
|
await ctx.send('Please attach a zip file to the command.')
|
||||||
f'blank to default to "unofficial"')
|
|
||||||
|
|
||||||
|
|
||||||
def setup(bot):
|
def setup(bot):
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user