Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add commands for mixed pools #84

Merged
merged 3 commits into from
Dec 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .flake8
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[flake8]
exclude = wwrando, wwrando-dev-tanjo3, wwrando-random-settings
exclude = wwrando, wwrando-dev-tanjo3, wwrando-random-settings, wwrando-mixed-pools
max-line-length = 120
extend-ignore = E203, W503
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,7 @@
path = wwrando-random-settings
url = https://github.com/wooferzfg/wwrando.git
branch = random-settings
[submodule "wwrando-mixed-pools"]
path = wwrando-mixed-pools
url = https://github.com/wooferzfg/wwrando.git
branch = mixed-pools-tourney
16 changes: 14 additions & 2 deletions randobot/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
class SeedType(Enum):
STANDARD = 1
SPOILER_LOG = 2
DEV = 3
RANDOM_SETTINGS = 4
RANDOM_SETTINGS = 3


STANDARD_PERMALINKS = OrderedDict([
Expand Down Expand Up @@ -67,6 +66,19 @@ class SeedType(Enum):
DEV_VERSION = "1.9.10_dev"
DEV_DOWNLOAD = "https://github.com/tanjo3/wwrando/releases"

MP_PERMALINKS = OrderedDict([
("mixed-pools", "MS4xMC4wX2Q1MTRhMjIAQQDfsGDs8CcC4vgJxj0AACQfAAAAEA=="),
])
MP_DEFAULT = ["mixed-pools"]

MP_SL_PERMALINKS = OrderedDict([
("mixed-pools-sl", "MS4xMC4wX2Q1MTRhMjIAQQDfsGDs8CcC4vgJxj0AACQfAAAAAA=="),
])
MP_SL_DEFAULT = ["mixed-pools-sl"]

MP_PATH = "wwrando-mixed-pools"
MP_DOWNLOAD = "https://github.com/wooferzfg/wwrando/releases/tag/mixed-pools-tourney-build"

RS_PATH = "wwrando-random-settings"
RS_VERSION = "v1.3.1"
RS_DOWNLOAD = "https://github.com/tanjo3/wwrando/releases/tag/RS_v1.3.1"
Expand Down
10 changes: 7 additions & 3 deletions randobot/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,19 @@ class Generator:
def __init__(self, github_token):
self.github_token = github_token

def generate_seed(self, randomizer_path, permalink, username, generate_spoiler_log):
def generate_seed(self, randomizer_path, permalink, username, generate_spoiler_log, new_args_format=False):
trimmed_name = re.sub(r'\W+', '', username)[:12]
random_suffix = shortuuid.ShortUUID().random(length=10)
seed_name = f"{trimmed_name}{random_suffix}"
file_name = "".join(random.choice(string.digits) for _ in range(6))

if new_args_format:
args = f"--noui --dry --seed={seed_name} --permalink={permalink}"
else:
args = f"-noui -seed={seed_name} -permalink={permalink}"

os.system(
f"/venv/{randomizer_path}/bin/python {randomizer_path}/wwrando.py "
f"-noui -seed={seed_name} -permalink={permalink}"
f"/venv/{randomizer_path}/bin/python {randomizer_path}/wwrando.py {args}"
)

permalink_file_name = f"permalink_{seed_name}.txt"
Expand Down
98 changes: 78 additions & 20 deletions randobot/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def room_setup(self):
self.state["permalink_available"] = False
self.state["file_name_available"] = False
self.state["permalink"] = None
self.state["example_permalink"] = None
self.state["seed_hash"] = None
self.state["spoiler_log_url"] = None
self.state["planning_time"] = constants.DEFAULT_PLANNING_TIME
Expand Down Expand Up @@ -336,12 +337,35 @@ async def ex_rolldevseed(self, args, message):

username = message.get('user', {}).get('name')
generated_seed = await self._generate_seed(constants.DEV_PATH, settings_permalink, username, False)
await self.update_race_room_with_generated_seed(settings_permalink, generated_seed, SeedType.DEV)
await self.update_race_room_with_generated_seed(settings_permalink, generated_seed, SeedType.STANDARD)
await self.send_message(
f"Please note that this seed has been rolled on the {constants.DEV_VERSION} version of the randomizer. "
f"You can download it here: {constants.DEV_DOWNLOAD}"
)

async def ex_rollmpseed(self, args, message):
if not await self.can_roll_standard_seed(message):
return

await self.send_message("Rolling seed...")

settings_permalink = await self.choose_permalink(
constants.MP_DEFAULT,
constants.MP_PERMALINKS,
args
)

username = message.get('user', {}).get('name')
generated_seed = await self._generate_seed(
constants.MP_PATH,
settings_permalink,
username,
generate_spoiler_log=False,
new_args_format=True,
)
await self.update_race_room_with_generated_seed(settings_permalink, generated_seed, SeedType.STANDARD)
await self.print_mixed_pools_build()

async def ex_randomsettings(self, args, message):
if not await self.can_roll_standard_seed(message):
return
Expand Down Expand Up @@ -381,6 +405,20 @@ async def can_roll_standard_seed(self, message):

return True

async def can_start_spoiler_log_race(self, message):
if self.state.get("locked") and not can_monitor(message):
await self.send_message(
"Seed rolling is locked. Only the creator of this room, a race monitor, "
"or a moderator can roll a seed. (Use !unlock to unlock seed rolling.)"
)
return False

if self.state.get("spoiler_log_seed_rolled"):
await self.send_message("Seed already rolled!")
return False

return True

async def update_race_room_with_generated_seed(self, settings_permalink, generated_seed, type):
permalink = generated_seed.get("permalink")
seed_hash = generated_seed.get("seed_hash")
Expand Down Expand Up @@ -433,18 +471,10 @@ async def ex_startspoilerlogtimer(self, args, message):
await self.send_message("Race already started!")
return

self.loop.create_task(self.start_spoiler_log_race(None, None))
self.loop.create_task(self.start_spoiler_log_race())

async def ex_startspoilerlograce(self, args, message):
if self.state.get("locked") and not can_monitor(message):
await self.send_message(
"Seed rolling is locked. Only the creator of this room, a race monitor, "
"or a moderator can roll a seed. (Use !unlock to unlock seed rolling.)"
)
return

if self.state.get("spoiler_log_seed_rolled"):
await self.send_message("Seed already rolled!")
if not await self.can_start_spoiler_log_race(message):
return

settings_permalink = await self.choose_permalink(
Expand All @@ -454,16 +484,38 @@ async def ex_startspoilerlograce(self, args, message):
)
username = message.get('user', {}).get('name')

self.loop.create_task(self.start_spoiler_log_race(settings_permalink, username))
await self.send_message("Rolling seed...")
generated_seed = await self._generate_seed(constants.STANDARD_PATH, settings_permalink, username, True)
await self.update_race_room_with_generated_seed(settings_permalink, generated_seed, SeedType.SPOILER_LOG)

async def start_spoiler_log_race(self, settings_permalink, username):
self.state["spoiler_log_seed_rolled"] = True
self.loop.create_task(self.start_spoiler_log_race())

async def ex_startmpspoilerlograce(self, args, message):
if not await self.can_start_spoiler_log_race(message):
return

if settings_permalink:
await self.send_message("Rolling seed...")
settings_permalink = await self.choose_permalink(
constants.MP_SL_DEFAULT,
constants.MP_SL_PERMALINKS,
args
)
username = message.get('user', {}).get('name')

generated_seed = await self._generate_seed(constants.STANDARD_PATH, settings_permalink, username, True)
await self.update_race_room_with_generated_seed(settings_permalink, generated_seed, SeedType.SPOILER_LOG)
await self.send_message("Rolling seed...")
generated_seed = await self._generate_seed(
constants.MP_PATH,
settings_permalink,
username,
generate_spoiler_log=True,
new_args_format=True,
)
await self.update_race_room_with_generated_seed(settings_permalink, generated_seed, SeedType.SPOILER_LOG)
await self.print_mixed_pools_build()

self.loop.create_task(self.start_spoiler_log_race())

async def start_spoiler_log_race(self):
self.state["spoiler_log_seed_rolled"] = True

planning_time = self.state.get("planning_time")

Expand Down Expand Up @@ -618,6 +670,12 @@ async def print_banned_presets(self):
def seconds_remaining(self):
return (self.state.get("race_start_time") - datetime.now()).total_seconds()

async def print_mixed_pools_build(self):
await self.send_message(
f"Please note that this seed has been rolled on the Mixed Pools Tournament version of the randomizer. "
f"You can download it here: {constants.MP_DOWNLOAD}"
)

async def print_example_permalink(self):
example_permalink = self.state.get("example_permalink")
if example_permalink:
Expand Down Expand Up @@ -742,9 +800,9 @@ def _is_permalink(self, permalink_or_preset):
return True
return False

async def _generate_seed(self, randomizer_path, permalink, username, generate_spoiler_log):
async def _generate_seed(self, *args, **kwargs):
try:
return self.generator.generate_seed(randomizer_path, permalink, username, generate_spoiler_log)
return self.generator.generate_seed(*args, **kwargs)
except Exception:
await self.send_message("Failed to generate seed!")
raise Exception("Failed to generate seed")
Loading