Skip to content

Commit

Permalink
Merge pull request #78 from murpii/pr_testing_fixes
Browse files Browse the repository at this point in the history
Testing fixes
  • Loading branch information
murpii authored Feb 9, 2024
2 parents ef9835f + 535e208 commit d595216
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 33 deletions.
72 changes: 47 additions & 25 deletions cogs/map_testing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def by_releases_webhook(message: discord.Message) -> bool:
def has_map(message: discord.Message) -> bool:
return message.attachments and message.attachments[0].filename.endswith('.map')

def tester_check():
def staff_check():
def predicate(ctx: commands.Context) -> bool:
return ctx.channel.id in ctx.cog._map_channels and is_staff(ctx.author)
return commands.check(predicate)
Expand Down Expand Up @@ -437,14 +437,14 @@ async def handle_map_release(self, message: discord.Message):
await map_channel.set_state(state=MapState.RELEASED)

@commands.command()
@tester_check()
@staff_check()
async def reset(self, ctx: commands.Context):
"""Reset a map"""
map_channel = self.get_map_channel(ctx.channel.id)
await map_channel.set_state(state=MapState.TESTING)

@commands.command()
@tester_check()
@staff_check()
async def waiting(self, ctx: commands.Context):
"""Set a map to waiting"""
map_channel = self.get_map_channel(ctx.channel.id)
Expand All @@ -456,38 +456,60 @@ async def waiting(self, ctx: commands.Context):
await self.bot.pool.execute(query, map_channel.id)

@commands.command()
@tester_check()
@staff_check()
async def ready(self, ctx: commands.Context):
"""Ready a map"""
map_channel = self.get_map_channel(ctx.channel.id)
try:
if map_channel.state == MapState.TESTING and is_staff(ctx.author):
print(ctx.author.roles)
if ROLE_TRIAL_TESTER in [role.id for role in ctx.author.roles]:
msg = 'First ready set by Trial Tester. It needs to be tested again by an official tester before fully evaluated.'
else:
msg = 'First ready set. It needs to be tested again by a different tester before fully evaluated.'
await ctx.reply(msg)
await map_channel.set_state(state=MapState.RC, ready_state_set_by=ctx.author.mention)
elif map_channel.state == MapState.RC and any(
role_id in [role.id for role in ctx.author.roles] for role_id in [ROLE_ADMIN, ROLE_TESTER]):

if map_channel.state == MapState.READY:
await ctx.reply('Map is already set to Ready. If the channel name hasn\'t been updated yet, wait a couple of minutes.')
return

if map_channel.initial_ready == ctx.author.mention:
await ctx.reply('You cannot ready the map again. It needs to be tested again by a different tester.')
return

if map_channel.state == MapState.TESTING:
if ROLE_ADMIN in [role.id for role in ctx.author.roles]:
await ctx.reply('The map is now ready to be released!')
await map_channel.set_state(state=MapState.READY, ready_state_set_by=ctx.author.mention)
elif ROLE_TRIAL_TESTER in [role.id for role in ctx.author.roles]:
msg = 'First ready set by Trial Tester. It needs to be tested again by an official tester before fully evaluated.'
await ctx.reply(msg)
await map_channel.set_state(state=MapState.RC, ready_state_set_by=ctx.author.mention)
else:
if map_channel.state == MapState.WAITING and is_staff(ctx.author):
await ctx.reply('Unable to ready a map in `WAITING`. Reset the map first, then try again.')
except ValueError as error:
await ctx.reply(f"{error}")
msg = 'First ready set. It needs to be tested again by a different tester before fully evaluated.'
await ctx.reply(msg)
await map_channel.set_state(state=MapState.RC, ready_state_set_by=ctx.author.mention)
elif map_channel.state == MapState.RC and any(
role_id in [role.id for role in ctx.author.roles] for role_id in [ROLE_ADMIN, ROLE_TESTER]):
await ctx.reply('The map is now ready to be released!')
await map_channel.set_state(state=MapState.READY, ready_state_set_by=ctx.author.mention)
else:
if map_channel.state == MapState.WAITING and is_staff(ctx.author):
await ctx.reply('Unable to ready a map in `WAITING`. Reset the map first, then try again.')

@commands.command()
@staff_check()
async def mapstate(self, ctx: commands.Context):
"""Print the current MapState of the channel."""
map_channel = self.get_map_channel(ctx.channel.id)

if map_channel:
await ctx.send(f"The current MapState of this channel is: {map_channel.state} \n"
f"The user who has ready'ed the map is: {map_channel.initial_ready}")
else:
await ctx.send("This channel is not a map channel.")

@commands.command()
@tester_check()
@staff_check()
async def decline(self, ctx: commands.Context):
"""Decline a map"""
map_channel = self.get_map_channel(ctx.channel.id)
await map_channel.set_state(state=MapState.DECLINED)

@commands.command()
@tester_check()
@staff_check()
async def released(self, ctx: commands.Context):
"""Mark a map as released"""
map_channel = self.get_map_channel(ctx.channel.id)
Expand All @@ -502,7 +524,7 @@ async def released(self, ctx: commands.Context):
await map_channel.set_state(state=MapState.RELEASED)

@commands.command()
@tester_check()
@staff_check()
async def edit(self, ctx: commands.Context, *args: str):
"""Edits a map according to the passed arguments"""
subm = None
Expand Down Expand Up @@ -532,13 +554,13 @@ async def edit(self, ctx: commands.Context, *args: str):
await ctx.channel.send(stdout, file=file)

@commands.command()
@tester_check()
@staff_check()
async def optimize(self, ctx: commands.Context):
"""Shortcut for the `edit` command, passes the arguments `--remove-everything-unused` and `--shrink-layers`"""
await self.edit(ctx, "--remove-everything-unused", "--shrink-tiles-layers")

@commands.group()
@tester_check()
@staff_check()
async def change(self, ctx: commands.Context):
"""Change details of a map"""
pass
Expand Down Expand Up @@ -603,7 +625,7 @@ async def manage_tester_error(self, ctx: commands.Context, error: commands.Comma
await ctx.send('Could not find that user')

@commands.command()
@tester_check()
@staff_check()
async def archive_imm(self, ctx: commands.Context):
"""Archive map channel immediately"""
map_channel = self.get_map_channel(ctx.channel.id)
Expand Down
16 changes: 8 additions & 8 deletions cogs/map_testing/map_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ def _initial_ready(self) -> str:

@property
def topic(self) -> str:
return '\n'.join((self.details, self.preview_url, self.mapper_mentions, self._initial_ready))
topic = [i for i in (self.details, self.preview_url, self.mapper_mentions, self._initial_ready) if
i is not None]
return '\n'.join(topic)

async def update(self, name: str=None, mappers: List[str]=None, server: str=None):
prev_details = self.details
Expand All @@ -95,10 +97,8 @@ async def update(self, name: str=None, mappers: List[str]=None, server: str=None
await self.edit(name=str(self), topic=self.topic)

async def set_state(self, *, state: MapState, ready_state_set_by: str = None):
if ready_state_set_by is not None and ready_state_set_by == self.initial_ready:
raise ValueError('You cannot ready the map again. It needs to be tested again by a different tester.')

self.state = state

if state is MapState.TESTING:
category_id = CAT_MAP_TESTING
elif state is MapState.RC:
Expand All @@ -110,10 +110,10 @@ async def set_state(self, *, state: MapState, ready_state_set_by: str = None):

options = {'name': str(self)}

if ready_state_set_by is None:
self.initial_ready = ''
else:
if ready_state_set_by is not None:
self.initial_ready = ready_state_set_by
else:
self.initial_ready = None

if category_id != self.category_id:
options['category'] = category = self.guild.get_channel(category_id)
Expand All @@ -131,7 +131,7 @@ async def from_submission(cls, isubm: InitialSubmission, **options):
self.server = isubm.server
self.state = MapState.TESTING
self.mapper_mentions = isubm.author.mention
self.initial_ready = str()
self.initial_ready = None
self._channel = await isubm.channel.category.create_text_channel(str(self), topic=self.topic, **options)

# Workaround for Discord API issue
Expand Down

0 comments on commit d595216

Please sign in to comment.