Skip to content

Commit

Permalink
Create a new buffer object aswell
Browse files Browse the repository at this point in the history
  • Loading branch information
tesence committed Aug 4, 2024
1 parent eb93720 commit b20f96f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
4 changes: 1 addition & 3 deletions gumo/api/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
Define a client to interact with the Ori and the Blind Forest Randomizer API
"""

import io
import logging
from urllib import parse
import random
Expand Down Expand Up @@ -119,11 +118,10 @@ async def get_seed(self, seed_name: str = None, logic_mode: str = None, key_mode
seed_data = await self._get_seed_data(seed_name=seed_name, logic_mode=logic_mode, key_mode=key_mode,
goal_mode=goal_mode, spawn=spawn, variations=variations,
item_pool=item_pool, relic_count=relic_count)
seed_buffer = io.BytesIO(bytes(seed_data['players'][0]['seed'], encoding="utf8"))
return {
'seed_header': seed_data['players'][0]['seed'].split("\n")[0],
'spoiler_url': f"{SEEDGEN_API_URL}{seed_data['players'][0]['spoiler_url']}",
'map_url': f"{SEEDGEN_API_URL}{seed_data['map_url']}",
'history_url': f"{SEEDGEN_API_URL}{seed_data['history_url']}",
'seed_buffers': [seed_buffer]
'seed_file_content': seed_data['players'][0]['seed']
}
6 changes: 4 additions & 2 deletions gumo/modules/league.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import logging
from datetime import datetime, time, timedelta
import functools
import io
import os
import random
import re
Expand Down Expand Up @@ -350,8 +351,9 @@ async def league_seed(self, interaction: discord.Interaction):
interaction (discord.Interaction): discord interaction object
"""
await interaction.response.defer(ephemeral=True)
seed_files = [discord.File(sd, filename='randomizer.dat') for sd in self._seed_data['seed_buffers']]
return await interaction.followup.send(content=f"`{self._seed_data['seed_header']}`", files=seed_files)
seed_buffer = io.BytesIO(bytes(self._seed_data['seed_file_content'], encoding="utf8"))
seed_file = discord.File(seed_buffer, filename='randomizer.dat')
return await interaction.followup.send(content=f"`{self._seed_data['seed_header']}`", files=[seed_file])

async def _league_seed(self):
"""
Expand Down
10 changes: 6 additions & 4 deletions gumo/modules/seed.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
- "/daily": the default seed generation command, forcing the seed name to the current date YYYY-MM-DD.
"""

import io
import logging
from datetime import datetime
from typing import Optional
Expand Down Expand Up @@ -76,8 +77,8 @@ async def seed(self, interaction: discord.Interaction,
await interaction.response.defer()
seed_settings = {s[0]: s[1] for s in interaction.namespace if not s[0].startswith('variation')}
variations = (s[1] for s in interaction.namespace if s[0].startswith('variation'))
message, files = await self._get_seed_message(**seed_settings, variations=variations)
return await interaction.followup.send(content=message, files=files)
message, file = await self._get_seed_message(**seed_settings, variations=variations)
return await interaction.followup.send(content=message, files=[file])

@app_commands.command(name='daily')
@app_commands.describe(logic_mode="Randomizer logic mode")
Expand Down Expand Up @@ -153,12 +154,13 @@ async def _get_seed_message(self, seed_name: str = None, logic_mode: str = None,
seed_data = await self.api_client.get_seed(seed_name=seed_name, logic_mode=logic_mode, key_mode=key_mode,
goal_mode=goal_mode, spawn=spawn, variations=variations,
item_pool=item_pool, relic_count=relic_count)
seed_files = [discord.File(sd, filename='randomizer.dat') for sd in seed_data['seed_buffers']]
seed_buffer = io.BytesIO(bytes(seed_data['seed_file_content'], encoding="utf8"))
seed_file = discord.File(seed_buffer, filename='randomizer.dat')
message = f"`{seed_data['seed_header']}`\n" \
f"**Spoiler**: [link]({seed_data['spoiler_url']})\n" \
f"**Map**: [link]({seed_data['map_url']})\n" \
f"**History**: [link]({seed_data['history_url']})"
return message, seed_files
return message, seed_file

@seed.error
@daily.error
Expand Down

0 comments on commit b20f96f

Please sign in to comment.