diff options
Diffstat (limited to 'pydis_site')
21 files changed, 73 insertions, 38 deletions
diff --git a/pydis_site/apps/api/migrations/0093_user_alts.py b/pydis_site/apps/api/migrations/0093_user_alts.py index fa5f2102..db6807b4 100644 --- a/pydis_site/apps/api/migrations/0093_user_alts.py +++ b/pydis_site/apps/api/migrations/0093_user_alts.py @@ -36,6 +36,6 @@ class Migration(migrations.Migration): ), migrations.AddConstraint( model_name='useraltrelationship', - constraint=models.CheckConstraint(check=models.Q(('source', models.F('target')), _negated=True), name='api_useraltrelationship_prevent_alt_to_self'), + constraint=models.CheckConstraint(condition=models.Q(('source', models.F('target')), _negated=True), name='api_useraltrelationship_prevent_alt_to_self'), ), ] diff --git a/pydis_site/apps/api/models/bot/user.py b/pydis_site/apps/api/models/bot/user.py index 4d317b8e..7f49fa86 100644 --- a/pydis_site/apps/api/models/bot/user.py +++ b/pydis_site/apps/api/models/bot/user.py @@ -76,7 +76,9 @@ class User(ModelReprMixin, models.Model): def __str__(self): """Returns the name and discriminator for the current user, for display purposes.""" - return f"{self.name}#{self.discriminator:04d}" + if self.discriminator: + return f"{self.name}#{self.discriminator:04d}" + return self.name @property def top_role(self) -> Role: @@ -137,6 +139,6 @@ class UserAltRelationship(ModelReprMixin, ModelTimestampMixin, models.Model): ), models.CheckConstraint( name="%(app_label)s_%(class)s_prevent_alt_to_self", - check=~models.Q(source=models.F("target")), + condition=~models.Q(source=models.F("target")), ), ] diff --git a/pydis_site/apps/api/tests/test_models.py b/pydis_site/apps/api/tests/test_models.py index 456ac408..0804384c 100644 --- a/pydis_site/apps/api/tests/test_models.py +++ b/pydis_site/apps/api/tests/test_models.py @@ -187,3 +187,9 @@ class StringDunderMethodTests(SimpleTestCase): "Nomination of Hemlock's Cat#7777 (active)", str(self.nomination) ) + + +class UserTests(SimpleTestCase): + def test_str_without_discriminator(self) -> None: + user = User(name="lemonfannumber1") + self.assertEqual(str(user), "lemonfannumber1") diff --git a/pydis_site/apps/api/views.py b/pydis_site/apps/api/views.py index 05a2bb02..da0bfe49 100644 --- a/pydis_site/apps/api/views.py +++ b/pydis_site/apps/api/views.py @@ -348,7 +348,7 @@ class GitHubWebhookFilterView(APIView): headers.pop('Content-Length', None) headers.pop('Content-Type', None) headers.pop('Host', None) - request = urllib.request.Request( # noqa: S310 + request = urllib.request.Request( f'https://discord.com/api/webhooks/{webhook_id}/{webhook_token}/github?wait=1', data=payload, headers={'Content-Type': 'application/json', **headers}, diff --git a/pydis_site/apps/content/resources/guides/pydis-guides/contributing/bot.md b/pydis_site/apps/content/resources/guides/pydis-guides/contributing/bot.md index a414bc20..9fc0f882 100644 --- a/pydis_site/apps/content/resources/guides/pydis-guides/contributing/bot.md +++ b/pydis_site/apps/content/resources/guides/pydis-guides/contributing/bot.md @@ -57,11 +57,11 @@ See [here](../creating-bot-account) for help with setting up a bot account. Once #### Privileged Intents It is necessary to explicitly request that your Discord bot receives certain gateway events. -The Python bot requires the `Server Member Intent` to function. +The Python bot requires `Server Member Intent` and `Message Content Intent` to function. In order to enable it, visit the [Developer Portal](https://discord.com/developers/applications/) (from where you copied your bot's login token) and scroll down to the `Privileged Gateway Intents` section. The `Presence Intent` is not necessary and can be left disabled. -If your bot fails to start with a `PrivilegedIntentsRequired` exception, this indicates that the required intent was not enabled. +If your bot fails to start with a `PrivilegedIntentsRequired` exception, this indicates that the required intents were not enabled. --- diff --git a/pydis_site/apps/content/resources/guides/pydis-guides/contributing/setting-test-server-and-bot-account.md b/pydis_site/apps/content/resources/guides/pydis-guides/contributing/setting-test-server-and-bot-account.md index 43d1c8f5..e9555575 100644 --- a/pydis_site/apps/content/resources/guides/pydis-guides/contributing/setting-test-server-and-bot-account.md +++ b/pydis_site/apps/content/resources/guides/pydis-guides/contributing/setting-test-server-and-bot-account.md @@ -18,8 +18,11 @@ icon: fab fa-discord 4. Change your bot's `Public Bot` setting off so only you can invite it, save, and then get your **Bot Token** with the `Copy` button. > **Note:** **DO NOT** post your bot token anywhere public, or it can and will be compromised. 5. Save your **Bot Token** somewhere safe to use in the project settings later. -6. In the `OAuth2` tab, grab the **Client ID**. -7. Replace `<CLIENT_ID_HERE>` in the following URL and visit it in the browser to invite your bot to your new test server. +6. Scroll down to the `Privileged Gateway Intents` section and enable required intents. +> For Sir Lancebot, you need to enable `Server Member Intent`. For Python Bot, you need to enable `Server Member Intent` and `Message Content Intent`. +> Failure to do so will result in a `PrivilegedIntentsRequired` exception when you start the bot. +7. In the `OAuth2` tab, grab the **Client ID**. +8. Replace `<CLIENT_ID_HERE>` in the following URL and visit it in the browser to invite your bot to your new test server. ```plaintext https://discordapp.com/api/oauth2/authorize?client_id=<CLIENT_ID_HERE>&permissions=8&scope=bot ``` diff --git a/pydis_site/apps/content/resources/guides/pydis-guides/contributing/sir-lancebot.md b/pydis_site/apps/content/resources/guides/pydis-guides/contributing/sir-lancebot.md index 56d95db4..5693d00c 100644 --- a/pydis_site/apps/content/resources/guides/pydis-guides/contributing/sir-lancebot.md +++ b/pydis_site/apps/content/resources/guides/pydis-guides/contributing/sir-lancebot.md @@ -27,7 +27,7 @@ To do this, you will need a Gitpod account, which you can get [here](https://www Afterwards, click on [this link](https://gitpod.io/#/github.com/python-discord/sir-lancebot) to spin up a new workspace for Sir Lancebot. Then run the following commands in the terminal after the existing tasks have finished running: ```sh git remote rename origin upstream -git add remote origin https://github.com/{your_username}/sir-lancebot +git remote add origin https://github.com/{your_username}/sir-lancebot ``` Make sure you replace `{your_username}` with your Github username. These commands will set the Sir Lancebot repository as the secondary remote, and your fork as the primary remote. This means you can easily grab new changes from the main Sir Lancebot repository. diff --git a/pydis_site/apps/content/resources/guides/python-guides/discord-embed-limits.md b/pydis_site/apps/content/resources/guides/python-guides/discord-embed-limits.md index ca97462b..b1385016 100644 --- a/pydis_site/apps/content/resources/guides/python-guides/discord-embed-limits.md +++ b/pydis_site/apps/content/resources/guides/python-guides/discord-embed-limits.md @@ -11,11 +11,11 @@ If you plan on using embed responses for your bot you should know the limits of - A **field name/title** is limited to **256 character** and the **value of the field** is limited to **1024 characters** - Embed **footer** is limited to **2048 characters** - Embed **author name** is limited to **256 characters** -- The **total of characters** allowed in an embed is **6000** +- The **total characters** of all embeds in a single message is limited to **6000** +- A message is limited to **10 embeds** Now if you need to get over this limit (for example for a help command), you would need to use pagination. There are several ways to do that: -- A library called **[disputils](https://pypi.org/project/disputils)** - An experimental library made by the discord.py developer called **[discord-ext-menus](https://github.com/Rapptz/discord-ext-menus)** - Make your own setup using **[wait_for()](https://discordpy.readthedocs.io/en/stable/ext/commands/api.html#discord.ext.commands.Bot.wait_for)** and wait for a reaction to be added diff --git a/pydis_site/apps/content/resources/guides/python-guides/vps-services.md b/pydis_site/apps/content/resources/guides/python-guides/vps-services.md index 00c6bfac..9a4a28c9 100644 --- a/pydis_site/apps/content/resources/guides/python-guides/vps-services.md +++ b/pydis_site/apps/content/resources/guides/python-guides/vps-services.md @@ -9,7 +9,7 @@ toc: 2 If you need to run your bot 24/7 (with no downtime), you should consider using a virtual private server (VPS). Here is a list of VPS services that are sufficient for running Discord bots. * Europe - * [netcup](https://www.netcup.eu/?ref=177518) + * [netcup](https://www.netcup.com/?ref=177518) * Germany & Austria data centres. * Great affiliate program. * [Yandex Cloud](https://cloud.yandex.ru/) @@ -42,17 +42,3 @@ While these may seem like nice and free services, it has a lot more caveats than - They use a shared IP for everything running on the service. This one is important - if someone is running a user bot on their service and gets banned, everyone on that IP will be banned. Including you. - -### Heroku -- Bots are not what the platform is designed for. Heroku is designed to provide web servers (like Django, Flask, etc). This is why they give you a domain name and open a port on their local emulator. - -- Heroku's environment is heavily containerized, making it significantly underpowered for a standard use case. - -- Heroku's environment is volatile. In order to handle the insane amount of users trying to use it for their own applications, Heroku will dispose your environment every time your application dies unless you pay. - -- Heroku has minimal system dependency control. If any of your Python requirements need C bindings (such as PyNaCl - binding to libsodium, or lxml binding to libxml), they are unlikely to function properly, if at all, in a native - environment. As such, you often need to resort to adding third-party buildpacks to facilitate otherwise normal - CPython extension functionality. (This is the reason why voice doesn't work natively on heroku) - -- Heroku only offers a limited amount of time on their free programme for your applications. If you exceed this limit, which you probably will, they'll shut down your application until your free credit resets. diff --git a/pydis_site/apps/home/tests/test_repodata_helpers.py b/pydis_site/apps/home/tests/test_repodata_helpers.py index acf4a817..6715444b 100644 --- a/pydis_site/apps/home/tests/test_repodata_helpers.py +++ b/pydis_site/apps/home/tests/test_repodata_helpers.py @@ -5,6 +5,7 @@ from unittest import mock from django.test import TestCase from django.utils import timezone +from httpx import HTTPStatusError from pydis_site.apps.home.models import RepositoryMetadata from pydis_site.apps.home.views import HomeView @@ -20,6 +21,16 @@ def mocked_requests_get(*args, **kwargs) -> "MockResponse": # noqa: F821 def json(self): return self.json_data + def raise_for_status(self): + if not 200 >= self.status_code < 400: + raise HTTPStatusError( + # NOTE: We only consume the response status code when working with this helper. + # If we ever need the request, this shim needs to be updated. + f"Received non-200/300 status code when performing request: HTTP {self.status_code}", + request=None, + response=self + ) + if args[0] == HomeView.github_api: json_path = Path(__file__).resolve().parent / "mock_github_api_response.json" with open(json_path) as json_file: @@ -98,6 +109,14 @@ class TestRepositoryMetadataHelpers(TestCase): self.assertIsNotNone(success_data.json_data) self.assertIsNone(fail_data.json_data) + @mock.patch('httpx.get', side_effect=mocked_requests_get) + def test_mocked_requests_raise_status(self, mock_get: mock.MagicMock): + """Tests if our mocked_requests_get raises an exception for bad statuses.""" + fail_data = mock_get("failtest") + + with self.assertRaises(HTTPStatusError): + fail_data.raise_for_status() + @mock.patch('httpx.get') def test_falls_back_to_database_on_error(self, mock_get: mock.MagicMock): """Tests that fallback to the database is performed when we get garbage back.""" diff --git a/pydis_site/apps/home/views.py b/pydis_site/apps/home/views.py index 71f95293..0df84478 100644 --- a/pydis_site/apps/home/views.py +++ b/pydis_site/apps/home/views.py @@ -1,4 +1,5 @@ import logging +from json.decoder import JSONDecodeError import httpx from django.core.handlers.wsgi import WSGIRequest @@ -53,14 +54,24 @@ class HomeView(View): repo_dict = {} try: # Fetch the data from the GitHub API - api_data: list[dict] = httpx.get( + resp = httpx.get( self.github_api, headers=self.headers, timeout=settings.TIMEOUT_PERIOD - ).json() + ) + + resp.raise_for_status() + + api_data: list[dict] = resp.json() except httpx.TimeoutException: log.error("Request to fetch GitHub repository metadata for timed out!") return repo_dict + except httpx.HTTPStatusError as ex: + log.error(f"Received HTTP {ex.response.status_code} from GitHub repository metadata request!") + return repo_dict + except JSONDecodeError: + log.error("GitHub returned invalid JSON for repository metadata!") + return repo_dict # Process the API data into our dict for repo in api_data: diff --git a/pydis_site/apps/resources/apps.py b/pydis_site/apps/resources/apps.py index 51cb064b..2d85d3a7 100644 --- a/pydis_site/apps/resources/apps.py +++ b/pydis_site/apps/resources/apps.py @@ -91,7 +91,7 @@ class ResourcesConfig(AppConfig): # A complete list of valid filter names self.valid_filters = { "topics": [to_kebabcase(topic) for topic in self.filters["Topics"]["filters"]], - "payment_tiers": [ + "payment-tiers": [ to_kebabcase(tier) for tier in self.filters["Payment tiers"]["filters"] ], "type": [to_kebabcase(type_) for type_ in self.filters["Type"]["filters"]], diff --git a/pydis_site/apps/resources/resources/discord_py_masterclass.yaml b/pydis_site/apps/resources/resources/discord_py_masterclass.yaml new file mode 100644 index 00000000..52338338 --- /dev/null +++ b/pydis_site/apps/resources/resources/discord_py_masterclass.yaml @@ -0,0 +1,12 @@ +description: A whistlestop tour of the functionality of discord.py, the most popular Python library for Discord +name: Discord.py Masterclass +title_url: https://fallendeity.github.io/discord.py-masterclass +tags: + topics: + - discord bots + payment_tiers: + - free + difficulty: + - intermediate + type: + - tutorial diff --git a/pydis_site/apps/resources/resources/people_postgres_data.yaml b/pydis_site/apps/resources/resources/people_postgres_data.yaml index ce5ad4a8..9f955a9f 100644 --- a/pydis_site/apps/resources/resources/people_postgres_data.yaml +++ b/pydis_site/apps/resources/resources/people_postgres_data.yaml @@ -4,7 +4,7 @@ description: People, Postgres, Data specializes in building users of Postgres Aurora for Postgres, Google Postgres, PostgreSQL.Org Postgres, Greenplum, Timescale and ZomboDB. They take a holistic approach to their community inviting not only technical topics but Professional Development and Life in general including movies, games, books and travel. -title_image: https://media.discordapp.net/attachments/748954447857844318/750519488268730377/people_postgres_data.png +title_image: /static/images/resources/people_postgres_data.png title_image_dark: /static/images/resources_dark/people_postgres_data.png title_url: https://postgresconf.org/ urls: diff --git a/pydis_site/apps/staff/templatetags/__init__.py b/pydis_site/apps/staff/templatetags/__init__.py index e8b6983a..ba67bd50 100644 --- a/pydis_site/apps/staff/templatetags/__init__.py +++ b/pydis_site/apps/staff/templatetags/__init__.py @@ -1,3 +1,3 @@ from .deletedmessage_filters import footer_datetime, hex_colour -__all__ = ["hex_colour", "footer_datetime"] +__all__ = ["footer_datetime", "hex_colour"] diff --git a/pydis_site/settings.py b/pydis_site/settings.py index dcb37b54..e5ae7cbd 100644 --- a/pydis_site/settings.py +++ b/pydis_site/settings.py @@ -56,7 +56,7 @@ if not STATIC_BUILD: send_default_pii=True, release=f"site@{GIT_SHA}", profiles_sample_rate=1.0, - enable_tracing=True, + traces_sample_rate=1.0, enable_db_query_source=True, db_query_source_threshold_ms=100, # Queries slower that 100ms will include the source in the event ) diff --git a/pydis_site/static/images/resources/people_postgres_data.png b/pydis_site/static/images/resources/people_postgres_data.png Binary files differnew file mode 100644 index 00000000..b144bf1f --- /dev/null +++ b/pydis_site/static/images/resources/people_postgres_data.png diff --git a/pydis_site/static/images/resources_dark/people_postgres_data.png b/pydis_site/static/images/resources_dark/people_postgres_data.png Binary files differindex 8e207a62..23beb237 100644 --- a/pydis_site/static/images/resources_dark/people_postgres_data.png +++ b/pydis_site/static/images/resources_dark/people_postgres_data.png diff --git a/pydis_site/templates/base/footer.html b/pydis_site/templates/base/footer.html index eacc7429..d5f2b067 100644 --- a/pydis_site/templates/base/footer.html +++ b/pydis_site/templates/base/footer.html @@ -1,7 +1,7 @@ <footer class="footer has-background-grey-darker"> <div class="content has-text-centered has-text-grey-lighter"> <p> - Powered by <a href="https://www.linode.com/?r=3bc18ce876ff43ea31f201b91e8e119c9753f085"><span id="linode-logo">Linode</span></a> and <a href="https://www.netcup.eu/?ref=177518"><span id="netcup-logo">netcup</span></a><br>Built with <a href="https://www.djangoproject.com/"><span id="django-logo">django</span></a> and <a href="https://bulma.io"><span id="bulma-logo">Bulma</span></a> <br/> © {% now "Y" %} <span id="pydis-text">Python Discord</span> + Powered by <a href="https://www.linode.com/?r=3bc18ce876ff43ea31f201b91e8e119c9753f085"><span id="linode-logo">Linode</span></a> and <a href="https://www.netcup.com/?ref=177518"><span id="netcup-logo">netcup</span></a><br>Built with <a href="https://www.djangoproject.com/"><span id="django-logo">django</span></a> and <a href="https://bulma.io"><span id="bulma-logo">Bulma</span></a> <br/> © {% now "Y" %} <span id="pydis-text">Python Discord</span> </p> </div> </footer> diff --git a/pydis_site/templates/events/pages/code-jams/_index.html b/pydis_site/templates/events/pages/code-jams/_index.html index 953e7382..bdf7d43d 100644 --- a/pydis_site/templates/events/pages/code-jams/_index.html +++ b/pydis_site/templates/events/pages/code-jams/_index.html @@ -8,10 +8,6 @@ {% block title %}Code Jams{% endblock %} {% block event_content %} - <div class="notification is-success"> - The <strong>2024 Summer Code Jam</strong> is currently underway and you can still enter! - <strong>The qualifier is open until July 10</strong>; check out the details <a href="{% url "events:page" path="code-jams/11" %}">here</a>. - </div> <p> If you've been around the server for a while, or you just happened to join at the right time, you may have heard of something known as a Code Jam. diff --git a/pydis_site/templates/home/index.html b/pydis_site/templates/home/index.html index c7d14fd6..8ebf186e 100644 --- a/pydis_site/templates/home/index.html +++ b/pydis_site/templates/home/index.html @@ -188,7 +188,7 @@ Sponsors </h1> <div class="columns is-vcentered"> - <a href="https://www.netcup.eu/?ref=177518" class="column is-one-third"> + <a href="https://www.netcup.com/?ref=177518" class="column is-one-third"> <img class="light-image" src="{% static "images/sponsors/netcup.png" %}" alt="netcup" loading="lazy"/> <img class="dark-image" src="{% static "images/sponsors_dark/netcup.png" %}" alt="netcup" loading="lazy"/> </a> |