Skip to content

Commit

Permalink
api.valtracker.gg commented out due to DNS error (#110)
Browse files Browse the repository at this point in the history
* Feature: gitignore template

* Feature: bat .venv

* Fix: assets cache gitignore

* Fix: api.valtracker.gg/bundles
  • Loading branch information
c7e715d1b04b17683718fb1e8944cc28 committed Apr 18, 2024
1 parent 7d40f6a commit 08fce6e
Show file tree
Hide file tree
Showing 8 changed files with 238 additions and 54 deletions.
2 changes: 0 additions & 2 deletions .env

This file was deleted.

2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
TOKEN='INPUT DISCORD TOKEN HERE'
OWNER_ID='INPUT YOUR DISCORD ID'
166 changes: 162 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,163 @@
*.pyc
.vscode
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
data/
.idea/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

# VALORANT assets cache
data/
25 changes: 24 additions & 1 deletion cogs/valorant.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ async def store(self, interaction: Interaction, username: str = None, password:

await interaction.response.defer(ephemeral=is_private_message)

if not interaction.guild:
raise ValorantBotError('This command can only be used in a server')

# setup emoji
await setup_emoji(self.bot, interaction.guild, interaction.locale)

Expand Down Expand Up @@ -167,6 +170,9 @@ async def point(self, interaction: Interaction, username: str = None, password:

response = ResponseLanguage(interaction.command.name, interaction.locale)

if not interaction.guild:
raise ValorantBotError('This command can only be used in a server')

# setup emoji
await setup_emoji(self.bot, interaction.guild, interaction.locale)

Expand Down Expand Up @@ -204,6 +210,7 @@ async def mission(self, interaction: Interaction, username: str = None, password
)

@app_commands.command(description='Show skin offers on the nightmarket')
@app_commands.guild_only()
# @dynamic_cooldown(cooldown_5s)
async def nightmarket(self, interaction: Interaction, username: str = None, password: str = None) -> None:

Expand All @@ -212,6 +219,9 @@ async def nightmarket(self, interaction: Interaction, username: str = None, pass

await interaction.response.defer(ephemeral=is_private_message)

if not interaction.guild:
raise ValorantBotError('This command can only be used in a server')

# setup emoji
await setup_emoji(self.bot, interaction.guild, interaction.locale)

Expand Down Expand Up @@ -269,6 +279,9 @@ async def bundle(self, interaction: Interaction, bundle: str) -> None:

response = ResponseLanguage(interaction.command.name, interaction.locale)

if not interaction.guild:
raise ValorantBotError('This command can only be used in a server')

# setup emoji
await setup_emoji(self.bot, interaction.guild, interaction.locale)

Expand All @@ -289,21 +302,28 @@ async def bundle(self, interaction: Interaction, bundle: str) -> None:
for i in cache['bundles']
if bundle.lower() in cache['bundles'][i]['names'][str(VLR_locale)].lower()
]
find_bundle = find_bundle_en_US if len(find_bundle_en_US) > 0 else find_bundle_locale
find_bundle = (find_bundle_en_US if len(find_bundle_en_US) > 0 else find_bundle_locale)[:25]

# bundle view
view = View.BaseBundle(interaction, find_bundle, response)
await view.start()

# inspired by https://github.com/giorgi-o
@app_commands.command(description="Show the current featured bundles")
@app_commands.guild_only()
# @dynamic_cooldown(cooldown_5s)
async def bundles(self, interaction: Interaction) -> None:

await interaction.response.defer()

response = ResponseLanguage(interaction.command.name, interaction.locale)

if not interaction.guild:
raise ValorantBotError('This command can only be used in a server')

# setup emoji
await setup_emoji(self.bot, interaction.guild, interaction.locale)

# endpoint
endpoint = await self.get_endpoint(interaction.user.id, interaction.locale)

Expand Down Expand Up @@ -376,6 +396,9 @@ async def debug(
self.db.insert_skin_price(skin_price, force=True)

elif bug == 'Emoji not loading':
if not interaction.guild:
raise ValorantBotError('This command can only be used in a server')

await setup_emoji(self.bot, interaction.guild, interaction.locale, force=True)

elif bug == 'Cache not loading':
Expand Down
3 changes: 2 additions & 1 deletion install.bat
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
pip install -r requirements.txt
python -m venv .venv
".venv/scripts/pip.exe" install -r requirements.txt
1 change: 1 addition & 0 deletions start.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
".venv/scripts/python.exe" main.py
92 changes: 46 additions & 46 deletions utils/valorant/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,52 +189,52 @@ def fetch_bundles() -> None:
'expires': None,
}

resp2 = requests.get(f'https://api.valtracker.gg/bundles')

for bundle2 in resp2.json()['data']:
if bundle2['uuid'] in bundles:
bundle = bundles[bundle2.get('uuid')]
items = []
default = {'amount': 1, 'discount': 0}
for weapon in bundle2['weapons']:
items.append(
{
'uuid': weapon['levels'][0]['uuid'],
'type': 'e7c63390-eda7-46e0-bb7a-a6abdacd2433',
'price': weapon.get('price'),
**default,
}
)
for buddy in bundle2['buddies']: #
items.append(
{
'uuid': buddy['levels'][0]['uuid'],
'type': 'dd3bf334-87f3-40bd-b043-682a57a8dc3a',
'price': buddy.get('price'),
**default,
}
)
for card in bundle2['cards']: #
items.append(
{
'uuid': card['uuid'],
'type': '3f296c07-64c3-494c-923b-fe692a4fa1bd',
'price': card.get('price'),
**default,
}
)
for spray in bundle2['sprays']:
items.append(
{
'uuid': spray['uuid'],
'type': 'd5f120f8-ff8c-4aac-92ea-f2b5acbe9475',
'price': spray.get('price'),
**default,
}
)

bundle['items'] = items
bundle['price'] = bundle2['price']
#resp2 = requests.get(f'https://api.valtracker.gg/bundles')

#for bundle2 in resp2.json()['data']:
# if bundle2['uuid'] in bundles:
# bundle = bundles[bundle2.get('uuid')]
# items = []
# default = {'amount': 1, 'discount': 0}
# for weapon in bundle2['weapons']:
# items.append(
# {
# 'uuid': weapon['levels'][0]['uuid'],
# 'type': 'e7c63390-eda7-46e0-bb7a-a6abdacd2433',
# 'price': weapon.get('price'),
# **default,
# }
# )
# for buddy in bundle2['buddies']: #
# items.append(
# {
# 'uuid': buddy['levels'][0]['uuid'],
# 'type': 'dd3bf334-87f3-40bd-b043-682a57a8dc3a',
# 'price': buddy.get('price'),
# **default,
# }
# )
# for card in bundle2['cards']: #
# items.append(
# {
# 'uuid': card['uuid'],
# 'type': '3f296c07-64c3-494c-923b-fe692a4fa1bd',
# 'price': card.get('price'),
# **default,
# }
# )
# for spray in bundle2['sprays']:
# items.append(
# {
# 'uuid': spray['uuid'],
# 'type': 'd5f120f8-ff8c-4aac-92ea-f2b5acbe9475',
# 'price': spray.get('price'),
# **default,
# }
# )

# bundle['items'] = items
# bundle['price'] = bundle2['price']

data['bundles'] = bundles
JSON.save('cache', data)
Expand Down
1 change: 1 addition & 0 deletions utils/valorant/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ def build_select(self) -> None:

@ui.select(placeholder='Select a bundle:')
async def select_bundle(self, interaction: Interaction, select: ui.Select):
# TODO: fix freeze
self.build_embeds(int(select.values[0]))
self.fill_items()
self.update_button()
Expand Down

0 comments on commit 08fce6e

Please sign in to comment.