Merge remote-tracking branch 'origin/master'
# Conflicts: # submissions_temp/Sandmann.zip # submissions_temp/coldino_hhta.zip # submissions_temp/coldino_sp.zip # submissions_temp/donlexa.zip
This commit is contained in:
@@ -45,6 +45,13 @@ def rename_section(cfg, sec, sec_new):
|
||||
return cfg
|
||||
|
||||
|
||||
def get_server_guid(server_file):
|
||||
server_file = server_file.encode()
|
||||
# p = s.pack((int.from_bytes(hash.encode(), byteorder='little') >> 64) & max_int,
|
||||
# int.from_bytes(hash.encode(), byteorder='little') & max_int)
|
||||
|
||||
|
||||
|
||||
def process_file(in_file, file_type) -> ConfigParser:
|
||||
with open(f'{config_dir}{bot_config_file}') as f:
|
||||
bot_config = json.load(f)
|
||||
@@ -97,19 +104,27 @@ def process_files(z) -> (ConfigParser, ConfigParser, list):
|
||||
try:
|
||||
with open(f'{path}{filename}', encoding='utf-8') as file:
|
||||
game_config = process_file(file, 'game.ini')
|
||||
file.seek(0)
|
||||
mods = check_for_mods(file)
|
||||
file.seek(0)
|
||||
server_file = file.read()
|
||||
except UnicodeDecodeError as e:
|
||||
print(e)
|
||||
try:
|
||||
with open(f'{path}{filename}', 'w+b') as file:
|
||||
with open(f'{path}{filename}', 'rb') as file:
|
||||
contents = file.read()
|
||||
file.write(contents.decode('utf-16-le').encode('utf-8'))
|
||||
with open(f'{path}{filename}', encoding='utf-8') as file:
|
||||
with open(f'{path}utf8{filename}', 'wb') as f:
|
||||
f.write(contents.decode('utf-16-le').replace('\uFEFF', '').encode('utf-8'))
|
||||
with open(f'{path}utf8{filename}', encoding='utf-8') as file:
|
||||
game_config = process_file(file, 'game.ini')
|
||||
file.seek(0)
|
||||
mods = check_for_mods(file)
|
||||
file.seek(0)
|
||||
server_file = file.read()
|
||||
except UnicodeDecodeError as e:
|
||||
print(e)
|
||||
return 0, 0, 0
|
||||
server_guid = get_server_guid(server_file)
|
||||
elif 'DinoExport' in filename:
|
||||
# Get the contents of all DinoExport_*.ini files loaded into a dict
|
||||
print(filename)
|
||||
@@ -154,7 +169,7 @@ def generate_dino_files(dino_data, directory):
|
||||
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}_' \
|
||||
directory = f'{storage_dir}/{ctx.author.id}/{filename.replace(".zip", "")}_' \
|
||||
f'{ctx.message.created_at.strftime("%Y%m%dT%H%M%S")}'
|
||||
os.mkdir(directory)
|
||||
generate_game_ini(game_ini, mods, directory)
|
||||
|
||||
+117
-8
@@ -1,3 +1,4 @@
|
||||
import asyncio
|
||||
import discord
|
||||
from discord.ext import commands
|
||||
from io import BytesIO
|
||||
@@ -20,6 +21,11 @@ class Uploader:
|
||||
attachment = ctx.message.attachments[0]
|
||||
if attachment.filename.endswith('.zip'):
|
||||
async with ctx.typing():
|
||||
if not os.path.isdir(f'{storage_dir}/orig/'):
|
||||
os.mkdir(f'{storage_dir}/orig/')
|
||||
with open(f'{storage_dir}/orig/{attachment.filename.replace(".zip", "")}_'
|
||||
f'{ctx.message.created_at.strftime("%Y%m%dT%H%M%S")}.zip', 'wb') as file:
|
||||
await attachment.save(file)
|
||||
with BytesIO() as file:
|
||||
await attachment.save(file)
|
||||
unzipped = process_files.load_zip(file)
|
||||
@@ -33,18 +39,117 @@ class Uploader:
|
||||
'Please make sure the files have not been renamed.')
|
||||
else:
|
||||
if official == 'unofficial' and game_ini == ConfigParser():
|
||||
await msg.edit(content='Game.ini is missing or is not valid.')
|
||||
return
|
||||
elif official == 'official' and game_ini == ConfigParser():
|
||||
await msg.delete()
|
||||
msg = await ctx.send(f'{ctx.author.mention} Game.ini is missing or is not valid.\n'
|
||||
f'Select {self.bot.unicode_emojis["o"]} to process as Official\n'
|
||||
f'Select {self.bot.unicode_emojis["y"]} if you would like to '
|
||||
f'provide Game.ini separately.\n'
|
||||
f'Select {self.bot.unicode_emojis["x"]} to cancel your upload\n'
|
||||
f'Please wait until all reactions are loaded before making '
|
||||
f'your selection')
|
||||
await msg.add_reaction(self.bot.unicode_emojis["o"])
|
||||
await msg.add_reaction(self.bot.unicode_emojis["y"])
|
||||
await msg.add_reaction(self.bot.unicode_emojis["x"])
|
||||
|
||||
def echeck(reaction, user):
|
||||
return user == ctx.author and str(reaction.emoji) in [self.bot.unicode_emojis["o"],
|
||||
self.bot.unicode_emojis["y"],
|
||||
self.bot.unicode_emojis["x"]]
|
||||
|
||||
try:
|
||||
reaction, user = await self.bot.wait_for('reaction_add', timeout=60.0, check=echeck)
|
||||
except asyncio.TimeoutError:
|
||||
await msg.edit(content=f'{ctx.author.mention} Game.ini is missing or not valid.\n'
|
||||
f'Canceling request due to timeout.')
|
||||
return
|
||||
else:
|
||||
try:
|
||||
await msg.clear_reactions()
|
||||
except (discord.Forbidden, discord.HTTPException):
|
||||
print('clear_reactions failed.')
|
||||
pass
|
||||
if str(reaction.emoji) == self.bot.unicode_emojis["o"]:
|
||||
await msg.edit(content="You chose to process as official.")
|
||||
await asyncio.sleep(4.0)
|
||||
official = 'official'
|
||||
elif str(reaction.emoji) == self.bot.unicode_emojis["y"]:
|
||||
await msg.edit(content="You chose to provide the Game.ini file.\n"
|
||||
"I will wait for 5 minutes for you to send a message "
|
||||
"containing the word `game` with a single file attached "
|
||||
"named `Game.ini`")
|
||||
|
||||
def mcheck(m):
|
||||
return 'game' in m.content.lower() and \
|
||||
m.channel == ctx.channel and \
|
||||
m.author == ctx.author and \
|
||||
len(m.attachments) > 0 and \
|
||||
m.attachments[0].filename == 'Game.ini'
|
||||
|
||||
try:
|
||||
game_msg = await self.bot.wait_for('message', timeout=300.0, check=mcheck)
|
||||
except asyncio.TimeoutError:
|
||||
await msg.edit(content=f'{ctx.author.mention} Timeout reached.\n'
|
||||
f'Your request has been canceled.')
|
||||
return
|
||||
else:
|
||||
await msg.edit(content='File Received.')
|
||||
await asyncio.sleep(2)
|
||||
await msg.edit(content='Processing... Please Wait.')
|
||||
with BytesIO() as f:
|
||||
game_msg.attachments[0].save(f)
|
||||
game_ini = process_files.process_file(f, 'game.ini')
|
||||
elif str(reaction.emoji) == self.bot.unicode_emojis['x']:
|
||||
await msg.edit(content='Your request has been canceled.')
|
||||
return
|
||||
|
||||
if official == 'official' and game_ini == ConfigParser():
|
||||
if not singleplayer:
|
||||
await msg.delete()
|
||||
msg = await ctx.send(f'Is this from SinglePlayer or a server?\n'
|
||||
f"select {self.bot.unicode_emojis['y']} for SP or "
|
||||
f"{self.bot.unicode_emojis['x']} for server.")
|
||||
await msg.add_reaction(self.bot.unicode_emojis["y"])
|
||||
await msg.add_reaction(self.bot.unicode_emojis["x"])
|
||||
|
||||
def echeck(reaction, user):
|
||||
return user == ctx.author and str(reaction.emoji) \
|
||||
in [self.bot.unicode_emojis["y"], self.bot.unicode_emojis["x"]]
|
||||
|
||||
try:
|
||||
reaction, user = await self.bot.wait_for('reaction_add', timeout=60.0,
|
||||
check=echeck)
|
||||
except asyncio.TimeoutError:
|
||||
await msg.edit(
|
||||
content=f'{ctx.author.mention} Game.ini is missing or not valid.\n'
|
||||
f'Canceling request due to timeout.')
|
||||
return
|
||||
else:
|
||||
try:
|
||||
await msg.clear_reactions()
|
||||
except (discord.Forbidden, discord.HTTPException):
|
||||
print('clear_reactions failed.')
|
||||
pass
|
||||
if str(reaction.emoji) == self.bot.unicode_emojis["y"]:
|
||||
await msg.edit(content="You selected SinglePlayer.")
|
||||
await asyncio.sleep(4.0)
|
||||
singleplayer = True
|
||||
elif str(reaction.emoji) == self.bot.unicode_emojis["x"]:
|
||||
await msg.edit(content="You selected Server.")
|
||||
await asyncio.sleep(4.0)
|
||||
singleplayer = False
|
||||
|
||||
if singleplayer:
|
||||
game_ini.add_section('/script/shootergame.shootergamemode')
|
||||
game_ini.set('/script/shootergame.shootergamemode',
|
||||
'bUseSingleplayerSettings',
|
||||
True)
|
||||
elif official not in ['official', 'unofficial']:
|
||||
await msg.edit(content=f'{official} is not a valid option. Please specify "official" '
|
||||
f'or "unofficial" or leave it blank to default to "unofficial"')
|
||||
"True")
|
||||
|
||||
if official not in ['official', 'unofficial']:
|
||||
await msg.edit(content=f'{ctx.author.mention} {official} is not a valid option.\n'
|
||||
f'Please specify "official" or "unofficial" or leave it blank '
|
||||
f'to default to "unofficial"')
|
||||
return
|
||||
|
||||
await msg.edit(content='Processing... Syncing with GitHub')
|
||||
pull_status = await utils.git_pull(self.bot.loop, storage_dir)
|
||||
if pull_status == 'Completed':
|
||||
@@ -59,13 +164,17 @@ class Uploader:
|
||||
await msg.edit(content='Processing... Committed... Pushing files to GitHub')
|
||||
push_status = await utils.git_push(self.bot.loop, storage_dir)
|
||||
if push_status == 'Completed':
|
||||
await msg.edit(content=f'{ctx.author.mention} Upload complete.')
|
||||
await msg.delete()
|
||||
msg = await ctx.send(f'{ctx.author.mention} Upload complete.\n'
|
||||
f'Uploaded {len(dinos_data)} dinos as {official} '
|
||||
f'{"singleplayer" if singleplayer else "server"}')
|
||||
else:
|
||||
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:
|
||||
await self.bot.get_user(owner_id).send(f'There was an error with git commit')
|
||||
await msg.edit(content='There was an error committing the files\n'
|
||||
'Dusty.P has been notified and will get this fixed')
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user