diff --git a/.env b/.env deleted file mode 100644 index d1ffd3d..0000000 --- a/.env +++ /dev/null @@ -1,2 +0,0 @@ -# TOKEN='INPUT DISCORD TOKEN HERE' -# OWNER_ID='INPUT YOUR DISCORD ID' \ No newline at end of file diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..d736f5d --- /dev/null +++ b/.env.example @@ -0,0 +1,2 @@ +TOKEN='INPUT DISCORD TOKEN HERE' +OWNER_ID='INPUT YOUR DISCORD ID' \ No newline at end of file diff --git a/.gitignore b/.gitignore index dd227de..867b141 100644 --- a/.gitignore +++ b/.gitignore @@ -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/ \ No newline at end of file +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/ \ No newline at end of file diff --git a/cogs/valorant.py b/cogs/valorant.py index c01a220..8012464 100644 --- a/cogs/valorant.py +++ b/cogs/valorant.py @@ -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) @@ -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) @@ -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: @@ -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) @@ -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) @@ -289,7 +302,7 @@ 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) @@ -297,6 +310,7 @@ async def bundle(self, interaction: Interaction, bundle: str) -> None: # 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: @@ -304,6 +318,12 @@ async def bundles(self, interaction: Interaction) -> 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) + # endpoint endpoint = await self.get_endpoint(interaction.user.id, interaction.locale) @@ -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': diff --git a/install.bat b/install.bat index 39a9971..84f6851 100644 --- a/install.bat +++ b/install.bat @@ -1 +1,2 @@ -pip install -r requirements.txt \ No newline at end of file +python -m venv .venv +".venv/scripts/pip.exe" install -r requirements.txt \ No newline at end of file diff --git a/start.bat b/start.bat new file mode 100644 index 0000000..1585061 --- /dev/null +++ b/start.bat @@ -0,0 +1 @@ +".venv/scripts/python.exe" main.py \ No newline at end of file diff --git a/utils/valorant/cache.py b/utils/valorant/cache.py index 0d596a2..c742445 100644 --- a/utils/valorant/cache.py +++ b/utils/valorant/cache.py @@ -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) diff --git a/utils/valorant/view.py b/utils/valorant/view.py index 0328af1..74a13f2 100644 --- a/utils/valorant/view.py +++ b/utils/valorant/view.py @@ -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()