Skip to content

Commit

Permalink
refactor: pep8 for tower, second iteration
Browse files Browse the repository at this point in the history
  • Loading branch information
maduck committed Aug 4, 2020
1 parent ba72644 commit 81b285c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 29 deletions.
38 changes: 18 additions & 20 deletions bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -799,36 +799,34 @@ async def edit_tower_floor(self, message, lang, prefix, floor, scroll_ii, scroll

short = my_data["short"]

rA = self.tower_data.edit_floor(prefix=prefix, guild=message.guild,
message=message, floor=floor, room="II", scroll=scroll_ii)
rB = self.tower_data.edit_floor(prefix=prefix, guild=message.guild,
message=message, floor=floor, room="III", scroll=scroll_iii)
rC = self.tower_data.edit_floor(prefix=prefix, guild=message.guild,
message=message, floor=floor, room="IV", scroll=scroll_iv)
rD = self.tower_data.edit_floor(prefix=prefix, guild=message.guild,
message=message, floor=floor, room="V", scroll=scroll_v)
room_a = self.tower_data.edit_floor(prefix=prefix, guild=message.guild,
message=message, floor=floor, room="II", scroll=scroll_ii)
room_b = self.tower_data.edit_floor(prefix=prefix, guild=message.guild,
message=message, floor=floor, room="III", scroll=scroll_iii)
room_c = self.tower_data.edit_floor(prefix=prefix, guild=message.guild,
message=message, floor=floor, room="IV", scroll=scroll_iv)
room_d = self.tower_data.edit_floor(prefix=prefix, guild=message.guild,
message=message, floor=floor, room="V", scroll=scroll_v)
# Mythic Room
if scroll_vi != None:
if scroll_vi is not None:
log.info(scroll_vi)
rE = self.tower_data.edit_floor(prefix=prefix, guild=message.guild,
message=message, floor=floor, room="VI", scroll=scroll_vi)
room_e = self.tower_data.edit_floor(prefix=prefix, guild=message.guild, message=message, floor=floor,
room="VI", scroll=scroll_vi)
else:
rE = (True, '')
room_e = (True, '')

success = rA[0] and rB[0] and rC[0] and rD[0] and rE[0]
success = all([room_a[0], room_b[0], room_c[0], room_d[0], room_e[0]])

if short:
# This is a reaction.
await self.react(message, bool_to_emoticon(success))
else:
# It's an embed.
e = discord.Embed(title='Tower of Doom', color=self.WHITE)
edit_text = '\n'.join([
f"{'Success' if rA[0] else 'Failure'}: {rA[1]}",
f"{'Success' if rB[0] else 'Failure'}: {rB[1]}",
f"{'Success' if rC[0] else 'Failure'}: {rC[1]}",
f"{'Success' if rD[0] else 'Failure'}: {rD[1]}",
f"{'Success' if rE[0] else 'Failure'}: {rE[1]}" if scroll_vi != None else ''
f"{'Success' if room_a[0] else 'Failure'}: {room_a[1]}",
f"{'Success' if room_b[0] else 'Failure'}: {room_b[1]}",
f"{'Success' if room_c[0] else 'Failure'}: {room_c[1]}",
f"{'Success' if room_d[0] else 'Failure'}: {room_d[1]}",
f"{'Success' if room_e[0] else 'Failure'}: {room_e[1]}" if scroll_vi is not None else ''
])

e.add_field(name='Edit Tower (Floor)', value=edit_text)
Expand Down
16 changes: 8 additions & 8 deletions tower_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,14 @@ def edit_floor(self, prefix, guild, message, floor, room, scroll):
try:
floor_number = atoi(floor)
except Exception:
log.debug(f"Couldn't find floor {floor} in {my_data['floors']}")
# log.debug(f"Couldn't find floor {floor} in {my_data['floors']}")
return f'Invalid floor {floor}'

try:
room_key = self.get_key_from_alias(my_data, 'rooms', room)
room_display = my_data['rooms'][room_key][0]
except KeyError:
log.debug(f"Couldn't find room {room} in {my_data['rooms']}")
# log.debug(f"Couldn't find room {room} in {my_data['rooms']}")
return False, f'Couldn\'t find room {room}'

# Mythic room below floor 25? always a scroll.
Expand All @@ -167,10 +167,10 @@ def edit_floor(self, prefix, guild, message, floor, room, scroll):
@staticmethod
def format_floor(my_data, display, floor, floor_data):
rooms = [
f'{my_data["rooms"]["II"][0]} = {my_data["scrolls"].get(floor_data.get("II", "unknown"))[0]} ',
f'{my_data["rooms"]["III"][0]} = {my_data["scrolls"].get(floor_data.get("III", "unknown"))[0]} ',
f'{my_data["rooms"]["IV"][0]} = {my_data["scrolls"].get(floor_data.get("IV", "unknown"))[0]} ',
f'{my_data["rooms"]["V"][0]} = {my_data["scrolls"].get(floor_data.get("V", "unknown"))[0]} ',
f'{my_data["rooms"]["II"][0]} = {my_data["scrolls"].get(floor_data.get("II", "unknown"))[0]}, ',
f'{my_data["rooms"]["III"][0]} = {my_data["scrolls"].get(floor_data.get("III", "unknown"))[0]}, ',
f'{my_data["rooms"]["IV"][0]} = {my_data["scrolls"].get(floor_data.get("IV", "unknown"))[0]}, ',
f'{my_data["rooms"]["V"][0]} = {my_data["scrolls"].get(floor_data.get("V", "unknown"))[0]}, ',
f'{my_data["rooms"]["VI"][0]} = {my_data["scrolls"].get(floor_data.get("VI", "unknown"))[0]}'
]
if floor_data.get('II', 'unknown') in my_data['hide']:
Expand Down Expand Up @@ -223,7 +223,7 @@ def format_output(self, guild, color, channel):

e = discord.Embed(title='Tower of Doom', color=color)
e.add_field(name=f'#{channel.name}', value=tower_text)
log.warn(e.fields)
# log.warn(e.fields)
return e

def set_option(self, guild, option, value, boolean=False):
Expand Down Expand Up @@ -273,7 +273,7 @@ def format_output_config(self, prefix, guild, color):
e.add_field(name='Rooms', value=rooms_text, inline=True)

# TODO: Revise get() to make this cleaner.
log.debug(my_data["scrolls"])
# log.debug(my_data["scrolls"])
scrolls_text = '\n'.join([
f'Armor: {", ".join(my_data["scrolls"]["armor"])}',
f'Attack: {", ".join(my_data["scrolls"]["attack"])}',
Expand Down
2 changes: 1 addition & 1 deletion util.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ def merge(a, b, path=None):
pass
# raise Exception('Conflict at %s' % '.'.join(path + [str(key)]))
else:
print(f"FILL: {key} : {b[key]}")
# print(f"FILL: {key} : {b[key]}")
a[key] = b[key]
return a

0 comments on commit 81b285c

Please sign in to comment.