Skip to content

Commit

Permalink
add check for version number
Browse files Browse the repository at this point in the history
  • Loading branch information
mousetail committed Feb 24, 2023
1 parent 165c085 commit 26b1407
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 33 deletions.
70 changes: 41 additions & 29 deletions cogs/maplist.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from utils.files import compress_file, download_file, get_download_filename, upload_to_gameserver, upload_to_redirect, remote_file_exists, redirect_file_exists, check_redirect_hash
from utils.search import search_downloads, ForumUserNotFoundException
from utils.discord import not_nobot_role_slash, roles_required
from utils.misc import contains_version_number

from models import Maps

Expand All @@ -33,10 +34,9 @@
class MapList(Cog):
cog_command_error = cog_error_handler


@slash_command(
name="uploadcheck",
description=config.uploadcheck.help,
name="uploadcheck",
description=config.uploadcheck.help,
guild_ids=global_config.bot_guild_ids,
checks=[
roles_required(config.uploadcheck.role_names),
Expand All @@ -47,9 +47,12 @@ async def uploadcheck(self, ctx, map_name):
await ctx.defer()

us, eu, redirect = await asyncio.gather(
remote_file_exists(f"{map_name}.bsp", **global_config.sftp.us_tf2maps_net),
remote_file_exists(f"{map_name}.bsp", **global_config.sftp.eu_tf2maps_net),
redirect_file_exists(f"{map_name}.bsp.bz2", global_config['vultr_s3_client']),
remote_file_exists(f"{map_name}.bsp", **
global_config.sftp.us_tf2maps_net),
remote_file_exists(f"{map_name}.bsp", **
global_config.sftp.eu_tf2maps_net),
redirect_file_exists(f"{map_name}.bsp.bz2",
global_config['vultr_s3_client']),
)

output = ""
Expand All @@ -72,10 +75,9 @@ async def uploadcheck(self, ctx, map_name):

await ctx.respond(embed=embed, content="")


@slash_command(
name="add",
description=config.add.help,
name="add",
description=config.add.help,
guild_ids=global_config.bot_guild_ids,
checks=[
roles_required(config.add.role_names),
Expand All @@ -88,8 +90,8 @@ async def add(self, ctx, link, *, notes=""):
await self.add_map(ctx, message, link, notes)

@slash_command(
name="update",
description=config.update.help,
name="update",
description=config.update.help,
guild_ids=global_config.bot_guild_ids,
checks=[
roles_required(config.update.role_names),
Expand All @@ -113,10 +115,9 @@ async def update(self, ctx, map_name, link, *, notes=""):
message = await ctx.respond(f"{loading} Updating your map...")
await self.add_map(ctx, message, link, notes, old_map=maps[0])


@slash_command(
name="delete",
description=config.delete.help,
name="delete",
description=config.delete.help,
guild_ids=global_config.bot_guild_ids,
checks=[
roles_required(config.delete.role_names),
Expand All @@ -142,10 +143,9 @@ async def delete(self, ctx, map_name):
await maps[0].delete()
await ctx.respond(f"{success} Deleted `{maps[0].map}` from the list.")


@slash_command(
name="maps",
description=config.maps.help,
name="maps",
description=config.maps.help,
guild_ids=global_config.bot_guild_ids,
checks=[
roles_required(config.maps.role_names),
Expand All @@ -159,7 +159,7 @@ async def maps(self, ctx):

# live_maps = await Maps.filter(Q(map=us_server.map) | Q(map=eu_server.map), played__gte=hour_ago).all()
await ctx.defer()
live_maps = [] # TODO why is this sometimes returning many entires?
live_maps = [] # TODO why is this sometimes returning many entires?
maps = await Maps.filter(status="pending").all()

map_names = ""
Expand All @@ -169,12 +169,15 @@ async def maps(self, ctx):
else:
map_names += f"• {item.map}\n"

embed = discord.Embed(description=f"There are **{len(maps)}** maps waiting to be played.\nhttps://bot.tf2maps.net/maplist\n\u200b")
embed.set_author(name=f"Map Testing Queue", url="https://bot.tf2maps.net/maplist", icon_url="https://cdn.discordapp.com/emojis/829026378078224435.png?v=1")
embed = discord.Embed(
description=f"There are **{len(maps)}** maps waiting to be played.\nhttps://bot.tf2maps.net/maplist\n\u200b")
embed.set_author(name=f"Map Testing Queue", url="https://bot.tf2maps.net/maplist",
icon_url="https://cdn.discordapp.com/emojis/829026378078224435.png?v=1")

if live_maps:
live_map_names = "\n".join([i.map for i in live_maps])
embed.add_field(name="Now Playing", value=live_map_names, inline=False)
embed.add_field(name="Now Playing",
value=live_map_names, inline=False)

embed.add_field(name="Map Queue", value=map_names, inline=False)
embed.set_footer(text=global_config.bot_footer)
Expand Down Expand Up @@ -216,7 +219,7 @@ async def add_map(self, ctx, message, link, notes="", old_map=None):
filename = await get_download_filename(link)
filepath = os.path.join(tempfile.mkdtemp(), filename)
map_name = re.sub("\.bsp$", "", filename)

# Must be a BSP
if not re.search("\.bsp$", filename):
await message.edit(content=f"{warning} `{map_name}` is not a BSP!")
Expand All @@ -231,7 +234,7 @@ async def add_map(self, ctx, message, link, notes="", old_map=None):
# Download the map
await message.edit(content=f"{loading} Found file name: `{filename}`. Downloading...")
await download_file(link, filepath)

# Compress file for redirect
await message.edit(content=f"{loading} Compressing `{filename}` for faster downloads...")
compressed_file = compress_file(filepath)
Expand All @@ -245,21 +248,31 @@ async def add_map(self, ctx, message, link, notes="", old_map=None):
# Upload to servers
await message.edit(content=f"{loading} Uploading `{filename}` to servers...")
await asyncio.gather(
upload_to_gameserver(filepath, **global_config.sftp.us_tf2maps_net),
upload_to_gameserver(filepath, **global_config.sftp.eu_tf2maps_net),
upload_to_redirect(compressed_file, global_config['vultr_s3_client'])
upload_to_gameserver(
filepath, **global_config.sftp.us_tf2maps_net),
upload_to_gameserver(
filepath, **global_config.sftp.eu_tf2maps_net),
upload_to_redirect(
compressed_file, global_config['vultr_s3_client'])
)

# Insert map into DB
await message.edit(content=f"{loading} Putting `{map_name}` into the map queue...")

if not contains_version_number(map_name):
version_warning = f"\n\n{warning} Your map seems to not include a version number. You must include a version number for your map to be tested."\
"\nThe map was still uploaded. You can use `/update` to replace it with a verision that includes a proper version number. If you did "\
"include one, disregard this message"
else:
version_warning = ""

if old_map:
old_map.url = link
old_map.map = map_name
if notes:
old_map.notes = notes
await old_map.save()
await message.edit(content=f"{success} Updated `{map_name}` successfully! Ready for testing!")
await message.edit(content=f"{success} Updated `{map_name}` successfully! Ready for testing!{version_warning}")
else:
await Maps.create(
discord_user_handle=f"{ctx.author.name}#{ctx.author.discriminator}",
Expand All @@ -270,8 +283,7 @@ async def add_map(self, ctx, message, link, notes="", old_map=None):
notes=notes,
added=datetime.now()
)
await message.edit(content=f"{success} Uploaded `{map_name}` successfully! Ready for testing!")

await message.edit(content=f"{success} Uploaded `{map_name}` successfully! Ready for testing!{version_warning}")

@staticmethod
async def parse_link(link):
Expand Down
13 changes: 9 additions & 4 deletions utils/misc.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import random
import string
import asyncio
import re


def get_random_password(length=8):
Expand Down Expand Up @@ -30,13 +31,17 @@ def readable_time(elapsed):
hours = int((elapsed / (60 * 60)) % 24)
minutes = int((elapsed % (60 * 60)) / 60)

if(days > 0):
if (days > 0):
readable += str(days) + " days "

if(hours > 0):
if (hours > 0):
readable += str(hours) + " hours "

if(minutes > 0):
if (minutes > 0):
readable += str(minutes) + " minutes "

return readable
return readable


def contains_version_number(map_name: str) -> bool:
return bool(re.search(r"\d|final|rc|beta|alpha"))

0 comments on commit 26b1407

Please sign in to comment.