diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index a260f1a..6ef15dc 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -13,14 +13,15 @@ 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 + python3 -m pip install --upgrade nextcord - 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: 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..92ac692 100644 --- a/_orangcbot/extensions/delete_response.py +++ b/_orangcbot/extensions/delete_response.py @@ -13,16 +13,14 @@ 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 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: 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/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/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..d369ca5 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 @@ -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/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.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 267def6..08a2a85 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, @@ -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 info := 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") @@ -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") 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 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"]