Added user interaction to upload_dino

This commit is contained in:
Dusty.P 2018-05-09 20:20:25 -08:00
parent d056a12e26
commit aa785de50c
2 changed files with 94 additions and 7 deletions

1
bot.py
View File

@ -54,6 +54,7 @@ class Submitter(commands.Bot):
'poop': '💩', 'poop': '💩',
'boom': '💥', 'boom': '💥',
'left_fist': '🤛', 'left_fist': '🤛',
'o': '🇴',
} }
async def connect_db(self): async def connect_db(self):

View File

@ -1,4 +1,4 @@
import discord import asyncio
from discord.ext import commands from discord.ext import commands
from io import BytesIO from io import BytesIO
from .imports import process_files, utils from .imports import process_files, utils
@ -33,18 +33,103 @@ class Uploader:
'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 msg.edit(content='Game.ini is missing or is not valid.') await msg.edit(content=f'{ctx.author.mention} Game.ini is missing or is not valid.\n'
return f'Select {self.bot.unicode_emojis["o"]} to process as Official\n'
elif official == 'official' and game_ini == ConfigParser(): 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: if singleplayer:
game_ini.add_section('/script/shootergame.shootergamemode') game_ini.add_section('/script/shootergame.shootergamemode')
game_ini.set('/script/shootergame.shootergamemode', game_ini.set('/script/shootergame.shootergamemode',
'bUseSingleplayerSettings', 'bUseSingleplayerSettings',
True) True)
elif official not in ['official', 'unofficial']:
await msg.edit(content=f'{official} is not a valid option. Please specify "official" ' if official not in ['official', 'unofficial']:
f'or "unofficial" or leave it blank to default to "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 return
await msg.edit(content='Processing... Syncing with GitHub') await msg.edit(content='Processing... Syncing with GitHub')
pull_status = await utils.git_pull(self.bot.loop, storage_dir) pull_status = await utils.git_pull(self.bot.loop, storage_dir)
if pull_status == 'Completed': if pull_status == 'Completed':
@ -66,6 +151,7 @@ class Uploader:
await msg.edit(content='There was an error pushing the files to GitHub\n' await msg.edit(content='There was an error pushing the files to GitHub\n'
'Dusty.P has been notified and will get this fixed') 'Dusty.P has been notified and will get this fixed')
else: 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' await msg.edit(content='There was an error committing the files\n'
'Dusty.P has been notified and will get this fixed') 'Dusty.P has been notified and will get this fixed')
else: else: