diff --git a/bot.py b/bot.py index ce7e770..2616529 100644 --- a/bot.py +++ b/bot.py @@ -54,6 +54,7 @@ class Submitter(commands.Bot): 'poop': '💩', 'boom': '💥', 'left_fist': '🤛', + 'o': '🇴', } async def connect_db(self): diff --git a/exts/uploader.py b/exts/uploader.py index 2c97796..6e0de7a 100644 --- a/exts/uploader.py +++ b/exts/uploader.py @@ -1,4 +1,4 @@ -import discord +import asyncio from discord.ext import commands from io import BytesIO from .imports import process_files, utils @@ -33,18 +33,103 @@ 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.edit(content=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: + 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('Your request has been canceled.') + return + + if official == 'official' and game_ini == ConfigParser(): + if not singleplayer: + await msg.edit(content=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.") + + 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: + 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"') + + 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': @@ -66,6 +151,7 @@ class Uploader: 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: