From da5de23d88eb856465a60597f7f440783790a863 Mon Sep 17 00:00:00 2001 From: maskduck Date: Thu, 30 May 2024 12:44:05 +0700 Subject: [PATCH 1/7] Add ruff linter --- .github/workflows/lint.yml | 6 +++--- .pre-commit-config.yaml | 13 ++++++++----- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index a260f1a..fc689ac 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -13,14 +13,14 @@ jobs: id: python uses: actions/setup-python@v2 with: - python-version: '3.9' + python-version: '3.11' - name: Install dependencies id: install-deps run: | - python3 -m pip install --upgrade black + python3 -m pip install --upgrade ruff python3 -m pip install --upgrade requests - name: Test 1 - run: "black --check ." + uses: chartboost/ruff-action@v1 env: PR_TESTING: 1 - name: Test 2 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 646dd74..969715e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,12 +3,15 @@ ci: style: auto fixes from pre-commit hooks autofix_prs: true repos: - - repo: https://github.com/psf/black - rev: 24.4.2 + - repo: https://github.com/astral-sh/ruff-pre-commit + # Ruff version. + rev: v0.4.6 hooks: - - id: black - name: Run black in files - + # Run the linter. + - id: ruff + args: [ --fix ] + # Run the formatter. + - id: ruff-format - repo: https://github.com/pycqa/isort rev: 5.13.2 hooks: From cdde1b4572a6df02997fd7cdd6a12766d0c1c848 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 30 May 2024 05:44:49 +0000 Subject: [PATCH 2/7] style: auto fixes from pre-commit hooks --- _orangcbot/__main__.py | 4 +--- _orangcbot/extensions/archwiki.py | 4 ++-- _orangcbot/extensions/delete_response.py | 2 -- _orangcbot/extensions/dns.py | 1 - _orangcbot/extensions/fun.py | 1 - _orangcbot/extensions/nixwiki.py | 2 +- _orangcbot/extensions/nonsense.py | 2 +- _orangcbot/extensions/suggestions.py | 2 +- _orangcbot/extensions/tags_reworked.py | 2 +- _orangcbot/extensions/testing_functions.py | 1 - 10 files changed, 7 insertions(+), 14 deletions(-) diff --git a/_orangcbot/__main__.py b/_orangcbot/__main__.py index 13cbd0c..d0afb85 100644 --- a/_orangcbot/__main__.py +++ b/_orangcbot/__main__.py @@ -1,15 +1,13 @@ from __future__ import annotations -from os import environ, getenv +from os import environ from dotenv import load_dotenv load_dotenv() import os -import traceback import nextcord -import psycopg2 from nextcord import ApplicationError, Intents from nextcord.ext import application_checks as ac from nextcord.ext import commands, help_commands diff --git a/_orangcbot/extensions/archwiki.py b/_orangcbot/extensions/archwiki.py index 81faeed..61d2dee 100644 --- a/_orangcbot/extensions/archwiki.py +++ b/_orangcbot/extensions/archwiki.py @@ -1,10 +1,10 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Final, Generic, Self, TypeVar +from typing import Final, Generic, Self, TypeVar import aiohttp import nextcord -from nextcord import SlashOption, slash_command +from nextcord import SlashOption from nextcord.ext import commands, menus T = TypeVar("T") diff --git a/_orangcbot/extensions/delete_response.py b/_orangcbot/extensions/delete_response.py index 21ef1d3..df4be13 100644 --- a/_orangcbot/extensions/delete_response.py +++ b/_orangcbot/extensions/delete_response.py @@ -13,7 +13,6 @@ async def on_raw_reaction_add(self, event: nextcord.RawReactionActionEvent) -> N if event.event_type == "REACTION_ADD": # print(event.emoji == "<:delete:1236642973576331328>") if str(event.emoji) == "<:delete:1236642973576331328>": - # Do not delete suggestions if event.channel_id == 1236200920317169695: return @@ -22,7 +21,6 @@ async def on_raw_reaction_add(self, event: nextcord.RawReactionActionEvent) -> N ) if self._bot.get_user(event.user_id).bot == False: # type: ignore[reportOptionalMemberAccess] if n.author.id == self._bot.user.id: # type: ignore[reportOptionalMemberAccess] - await n.delete() else: pass diff --git a/_orangcbot/extensions/dns.py b/_orangcbot/extensions/dns.py index cdf1926..0d28774 100644 --- a/_orangcbot/extensions/dns.py +++ b/_orangcbot/extensions/dns.py @@ -4,7 +4,6 @@ from typing import TYPE_CHECKING import nextcord -import whois from dns import resolver as _dnsresolver from nextcord.ext import commands diff --git a/_orangcbot/extensions/fun.py b/_orangcbot/extensions/fun.py index 2c11bd9..54bdaa8 100644 --- a/_orangcbot/extensions/fun.py +++ b/_orangcbot/extensions/fun.py @@ -12,7 +12,6 @@ import datetime # import os -from os import getenv _psl = PSL() import random diff --git a/_orangcbot/extensions/nixwiki.py b/_orangcbot/extensions/nixwiki.py index ea60821..c31d812 100644 --- a/_orangcbot/extensions/nixwiki.py +++ b/_orangcbot/extensions/nixwiki.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Generic, TypeVar +from typing import Generic, TypeVar import aiohttp import nextcord diff --git a/_orangcbot/extensions/nonsense.py b/_orangcbot/extensions/nonsense.py index e663276..9ddcf2b 100644 --- a/_orangcbot/extensions/nonsense.py +++ b/_orangcbot/extensions/nonsense.py @@ -1,7 +1,7 @@ from __future__ import annotations import re -from typing import TYPE_CHECKING, Literal, Optional +from typing import TYPE_CHECKING, Optional import aiohttp import nextcord diff --git a/_orangcbot/extensions/suggestions.py b/_orangcbot/extensions/suggestions.py index d8b47e0..e23bd99 100644 --- a/_orangcbot/extensions/suggestions.py +++ b/_orangcbot/extensions/suggestions.py @@ -10,7 +10,7 @@ # from models.basecog import BaseCog if TYPE_CHECKING: - from nextcord import TextChannel + pass class Suggestion(commands.Cog): diff --git a/_orangcbot/extensions/tags_reworked.py b/_orangcbot/extensions/tags_reworked.py index 267def6..db7d953 100644 --- a/_orangcbot/extensions/tags_reworked.py +++ b/_orangcbot/extensions/tags_reworked.py @@ -113,7 +113,7 @@ async def callback(self, interaction: nextcord.Interaction) -> None: try: cursor.execute( # f"INSERT INTO taginfo VALUES('{id.hex}', '{self.my_name.value}', '{self.my_title.value}', '{self.my_content.value}', '{str(interaction.user.id)}')" - f"INSERT INTO taginfo VALUES(%s, %s, %s, %s, %s)", + "INSERT INTO taginfo VALUES(%s, %s, %s, %s, %s)", ( id.hex, self.my_name.value, diff --git a/_orangcbot/extensions/testing_functions.py b/_orangcbot/extensions/testing_functions.py index 16bf2cd..33af03a 100644 --- a/_orangcbot/extensions/testing_functions.py +++ b/_orangcbot/extensions/testing_functions.py @@ -1,4 +1,3 @@ -import nextcord from nextcord.ext import commands From 0e8ff3deb8b6512a407f9abbea443637e449e03f Mon Sep 17 00:00:00 2001 From: maskduck Date: Thu, 30 May 2024 12:54:18 +0700 Subject: [PATCH 3/7] Fix errors mentioned by ruff --- .github/workflows/lint.yml | 1 + _orangcbot/extensions/delete_response.py | 2 +- _orangcbot/extensions/tags.py | 1 + _orangcbot/extensions/tags_reworked.py | 4 ++-- 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index fc689ac..6ef15dc 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -19,6 +19,7 @@ jobs: run: | python3 -m pip install --upgrade ruff python3 -m pip install --upgrade requests + python3 -m pip install --upgrade nextcord - name: Test 1 uses: chartboost/ruff-action@v1 env: diff --git a/_orangcbot/extensions/delete_response.py b/_orangcbot/extensions/delete_response.py index df4be13..92ac692 100644 --- a/_orangcbot/extensions/delete_response.py +++ b/_orangcbot/extensions/delete_response.py @@ -19,7 +19,7 @@ async def on_raw_reaction_add(self, event: nextcord.RawReactionActionEvent) -> N n = await self._bot.get_channel(event.channel_id).fetch_message( event.message_id ) - if self._bot.get_user(event.user_id).bot == False: # type: ignore[reportOptionalMemberAccess] + if not self._bot.get_user(event.user_id).bot: # type: ignore[reportOptionalMemberAccess] if n.author.id == self._bot.user.id: # type: ignore[reportOptionalMemberAccess] await n.delete() else: diff --git a/_orangcbot/extensions/tags.py b/_orangcbot/extensions/tags.py index 79a1f9f..f6d2713 100644 --- a/_orangcbot/extensions/tags.py +++ b/_orangcbot/extensions/tags.py @@ -1,3 +1,4 @@ +# ruff: noqa from nextcord.ext import commands nohelp = """ diff --git a/_orangcbot/extensions/tags_reworked.py b/_orangcbot/extensions/tags_reworked.py index db7d953..205b261 100644 --- a/_orangcbot/extensions/tags_reworked.py +++ b/_orangcbot/extensions/tags_reworked.py @@ -207,7 +207,7 @@ async def find( """Request a tag""" with self._db.cursor() as cursor: cursor.execute("SELECT * FROM taginfo\nWHERE name=%s", (tag_name,)) - if info := cursor.fetchone(): + if cursor.fetchone() is not None: # print(info) await interaction.send( embed=nextcord.Embed( @@ -228,7 +228,7 @@ async def delete( """Delete a tag""" with self._db.cursor() as cursor: cursor.execute("SELECT * FROM taginfo WHERE name=%s", (tag_name,)) - if info := cursor.fetchone(): + if cursor.fetchone() is not None: cursor.execute("DELETE FROM taginfo WHERE name=%s", (tag_name,)) self._db.commit() await interaction.send("Done") From afad0c19fa4882f00d40eec37a99c184ffcda42d Mon Sep 17 00:00:00 2001 From: maskduck Date: Thu, 30 May 2024 12:55:46 +0700 Subject: [PATCH 4/7] Add ruff config --- _orangcbot/extensions/emoji.py | 24 ++++++++++++++++++++++++ ruff.toml | 5 +++++ 2 files changed, 29 insertions(+) create mode 100644 _orangcbot/extensions/emoji.py create mode 100644 ruff.toml diff --git a/_orangcbot/extensions/emoji.py b/_orangcbot/extensions/emoji.py new file mode 100644 index 0000000..e12fcaa --- /dev/null +++ b/_orangcbot/extensions/emoji.py @@ -0,0 +1,24 @@ +from __future__ import annotations + +import nextcord +from nextcord import Attachment, Interaction, SlashOption, slash_command +from nextcord.ext import commands + + +class Emoji(commands.Cog): + def __init__(self, bot: commands.Bot) -> None: + self._bot: commands.Bot = bot + + @slash_command() + async def add_emoji( + self, + interaction: Interaction, + ) -> None: + pass + + @add_emoji.subcommand() + async def emojigg( + self, + interaction: Interaction, + emoji_id: str = SlashOption(description="The emoji.gg ID", required=True), + ) -> None: ... diff --git a/ruff.toml b/ruff.toml new file mode 100644 index 0000000..996be2a --- /dev/null +++ b/ruff.toml @@ -0,0 +1,5 @@ + +[lint] +# Enable Pyflakes (`F`) and a subset of the pycodestyle (`E`) codes by default. +select = ["E4", "E7", "E9", "F"] +ignore = ["E741", "E402", "E722"] From dda117399c5298ea49128ddb70a4bd84b31da70e Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 30 May 2024 05:55:54 +0000 Subject: [PATCH 5/7] style: auto fixes from pre-commit hooks --- _orangcbot/extensions/emoji.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/_orangcbot/extensions/emoji.py b/_orangcbot/extensions/emoji.py index e12fcaa..86476af 100644 --- a/_orangcbot/extensions/emoji.py +++ b/_orangcbot/extensions/emoji.py @@ -1,7 +1,6 @@ from __future__ import annotations -import nextcord -from nextcord import Attachment, Interaction, SlashOption, slash_command +from nextcord import Interaction, SlashOption, slash_command from nextcord.ext import commands From 7dd5d4bf4a4fc61286bc4a295a77209b60dcf5bc Mon Sep 17 00:00:00 2001 From: MaskDuck Date: Thu, 30 May 2024 12:59:18 +0700 Subject: [PATCH 6/7] delete unneeded file --- _orangcbot/extensions/emoji.py | 23 ----------------------- 1 file changed, 23 deletions(-) delete mode 100644 _orangcbot/extensions/emoji.py diff --git a/_orangcbot/extensions/emoji.py b/_orangcbot/extensions/emoji.py deleted file mode 100644 index 86476af..0000000 --- a/_orangcbot/extensions/emoji.py +++ /dev/null @@ -1,23 +0,0 @@ -from __future__ import annotations - -from nextcord import Interaction, SlashOption, slash_command -from nextcord.ext import commands - - -class Emoji(commands.Cog): - def __init__(self, bot: commands.Bot) -> None: - self._bot: commands.Bot = bot - - @slash_command() - async def add_emoji( - self, - interaction: Interaction, - ) -> None: - pass - - @add_emoji.subcommand() - async def emojigg( - self, - interaction: Interaction, - emoji_id: str = SlashOption(description="The emoji.gg ID", required=True), - ) -> None: ... From 895a06079a02fd54fe47511a6b021014d4106d1a Mon Sep 17 00:00:00 2001 From: maskduck Date: Thu, 30 May 2024 13:04:06 +0700 Subject: [PATCH 7/7] Fix ruff problems --- _orangcbot/extensions/github.py | 2 +- _orangcbot/extensions/nonsense.py | 4 ++-- _orangcbot/extensions/rules.py | 1 + _orangcbot/extensions/tags_reworked.py | 4 ++-- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/_orangcbot/extensions/github.py b/_orangcbot/extensions/github.py index db55db6..27bdc7e 100644 --- a/_orangcbot/extensions/github.py +++ b/_orangcbot/extensions/github.py @@ -42,7 +42,7 @@ async def on_message(self, message: nextcord.Message): return full_matches: List[re.Match] = re.findall(FULL_MATCH_ANY_REPO, message.content) # print(full_matches) - is_a_dev_matches: List[re.Match] = re.findall( + is_a_dev_matches: List[re.Match] = re.findall( # noqa: F841 MATCH_IS_A_DEV_ONLY, message.content ) pr_list: List[_PRRawObject] = [] diff --git a/_orangcbot/extensions/nonsense.py b/_orangcbot/extensions/nonsense.py index 9ddcf2b..d369ca5 100644 --- a/_orangcbot/extensions/nonsense.py +++ b/_orangcbot/extensions/nonsense.py @@ -266,7 +266,7 @@ async def check( self, ctx: commands.Context, domain: SubdomainNameConverter ) -> None: try: - data = await request( + await request( True, "GET", f"https://raw.githubusercontent.com/is-a-dev/register/main/domains/{domain}.json", @@ -291,7 +291,7 @@ async def check( ), ) -> None: try: - data = await request( + await request( True, "GET", f"https://raw.githubusercontent.com/is-a-dev/register/main/domains/{domain}.json", diff --git a/_orangcbot/extensions/rules.py b/_orangcbot/extensions/rules.py index 6ee9d2f..85776ca 100644 --- a/_orangcbot/extensions/rules.py +++ b/_orangcbot/extensions/rules.py @@ -3,6 +3,7 @@ from typing import Final, List, Optional, Tuple import nextcord +from nextcord import Embed from nextcord.ext import commands, menus RULES: Final[List[str]] = [ diff --git a/_orangcbot/extensions/tags_reworked.py b/_orangcbot/extensions/tags_reworked.py index 205b261..08a2a85 100644 --- a/_orangcbot/extensions/tags_reworked.py +++ b/_orangcbot/extensions/tags_reworked.py @@ -207,7 +207,7 @@ async def find( """Request a tag""" with self._db.cursor() as cursor: cursor.execute("SELECT * FROM taginfo\nWHERE name=%s", (tag_name,)) - if cursor.fetchone() is not None: + if info := cursor.fetchone() is not None: # print(info) await interaction.send( embed=nextcord.Embed( @@ -320,7 +320,7 @@ async def delete(self, ctx: commands.Context, tag_name: str): """Delete a tag.""" with self._db.cursor() as cursor: cursor.execute("SELECT * FROM taginfo WHERE name=%s", (tag_name,)) - if info := cursor.fetchone(): + if cursor.fetchone(): cursor.execute("DELETE FROM taginfo WHERE name=%s", (tag_name,)) self._db.commit() await ctx.send("Done")