Skip to content

Commit

Permalink
[PATCH] Ruff fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Diapolo10 committed Oct 28, 2023
1 parent b552e1d commit 2a436af
Show file tree
Hide file tree
Showing 12 changed files with 99 additions and 174 deletions.
1 change: 1 addition & 0 deletions src/growlery/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Clan Quest OSRS hiscore bot."""
2 changes: 1 addition & 1 deletion src/growlery/__main__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Used to launch the bot as a module"""
"""Used to launch the bot as a module."""

import discord

Expand Down
2 changes: 1 addition & 1 deletion src/growlery/cogs/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Package for Discord cogs"""
"""Package for Discord cogs."""

from growlery.cogs.hiscores import Hiscores

Expand Down
70 changes: 24 additions & 46 deletions src/growlery/cogs/hiscores.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Implements commands for hiscores"""
"""Implement commands for hiscores."""

from __future__ import annotations

Expand All @@ -24,114 +24,96 @@


class Hiscores(commands.Cog): # pylint: disable=R0904
"""Hiscores commands"""
"""Hiscore commands."""

@commands.command('07hs')
async def default_hiscores(self: Hiscores, ctx: commands.Context, *, username: str | None = None) -> None:
"""Fetches default hiscores for the given username"""

"""Fetch default hiscores for the given username."""
await self.reply_with_hiscores(ctx, username, AccountType.NORMAL, AccountTypeName.NORMAL)

@commands.command('07hs-im')
async def ironman_hiscores(self: Hiscores, ctx: commands.Context, *, username: str | None = None) -> None:
"""Fetches ironman hiscores for the given username"""

"""Fetch ironman hiscores for the given username."""
await self.reply_with_hiscores(ctx, username, AccountType.IRONMAN, AccountTypeName.IRONMAN)

@commands.command('07hs-hcim')
async def hardcore_ironman_hiscores(self: Hiscores, ctx: commands.Context, *, username: str | None = None) -> None:
"""Fetches hardcore ironman hiscores for the given username"""

"""Fetch hardcore ironman hiscores for the given username."""
await self.reply_with_hiscores(ctx, username, AccountType.HARDCORE_IRONMAN, AccountTypeName.HARDCORE_IRONMAN)

@commands.command('07hs-uim')
async def ultimate_ironman_hiscores(self: Hiscores, ctx: commands.Context, *, username: str | None = None) -> None:
"""Fetches ultimate ironman hiscores for the given username"""

"""Fetch ultimate ironman hiscores for the given username."""
await self.reply_with_hiscores(ctx, username, AccountType.ULTIMATE_IRONMAN, AccountTypeName.ULTIMATE_IRONMAN)

@commands.command('07hs-skiller')
async def skiller_hiscores(self: Hiscores, ctx: commands.Context, *, username: str | None = None) -> None:
"""Fetches skiller hiscores for the given username"""

"""Fetch skiller hiscores for the given username."""
await self.reply_with_hiscores(ctx, username, AccountType.SKILLER, AccountTypeName.SKILLER)

@commands.command('07hs-def')
async def defence_pure_hiscores(self: Hiscores, ctx: commands.Context, *, username: str | None = None) -> None:
"""Fetches 1 Defence hiscores for the given username"""

"""Fetch 1 Defence hiscores for the given username."""
await self.reply_with_hiscores(ctx, username, AccountType.DEFENCE_PURE, AccountTypeName.DEFENCE_PURE)

@commands.command('07hs-minigames')
async def default_minigames(self: Hiscores, ctx: commands.Context, *, username: str | None = None) -> None:
"""Fetches default minigame hiscores for the given username"""

"""Fetch default minigame hiscores for the given username."""
await self.reply_with_minigames(ctx, username, AccountType.NORMAL, AccountTypeName.NORMAL)

@commands.command('07hs-im-minigames')
async def ironman_minigames(self: Hiscores, ctx: commands.Context, *, username: str | None = None) -> None:
"""Fetches ironman minigame hiscores for the given username"""

"""Fetch ironman minigame hiscores for the given username."""
await self.reply_with_minigames(ctx, username, AccountType.IRONMAN, AccountTypeName.IRONMAN)

@commands.command('07hs-hcim-minigames')
async def hardcore_ironman_minigames(self: Hiscores, ctx: commands.Context, *, username: str | None = None) -> None:
"""Fetches hardcore ironman minigame hiscores for the given username"""

"""Fetch hardcore ironman minigame hiscores for the given username."""
await self.reply_with_minigames(ctx, username, AccountType.HARDCORE_IRONMAN, AccountTypeName.HARDCORE_IRONMAN)

@commands.command('07hs-uim-minigames')
async def ultimate_ironman_minigames(self: Hiscores, ctx: commands.Context, *, username: str | None = None) -> None:
"""Fetches ultimate ironman minigame hiscores for the given username"""

"""Fetch ultimate ironman minigame hiscores for the given username."""
await self.reply_with_minigames(ctx, username, AccountType.ULTIMATE_IRONMAN, AccountTypeName.ULTIMATE_IRONMAN)

@commands.command('07hs-skiller-minigames')
async def skiller_minigames(self: Hiscores, ctx: commands.Context, *, username: str | None = None) -> None:
"""Fetches skiller minigame hiscores for the given username"""

"""Fetch skiller minigame hiscores for the given username."""
await self.reply_with_minigames(ctx, username, AccountType.SKILLER, AccountTypeName.SKILLER)

@commands.command('07hs-def-minigames')
async def defence_pure_minigames(self: Hiscores, ctx: commands.Context, *, username: str | None = None) -> None:
"""Fetches 1 Defence minigame hiscores for the given username"""

"""Fetch 1 Defence minigame hiscores for the given username."""
await self.reply_with_minigames(ctx, username, AccountType.DEFENCE_PURE, AccountTypeName.DEFENCE_PURE)

@commands.command('07hs-bosses')
async def default_bosses(self: Hiscores, ctx: commands.Context, *, username: str | None = None) -> None:
"""Fetches default boss hiscores for the given username"""

"""Fetch default boss hiscores for the given username."""
await self.reply_with_bosses(ctx, username, AccountType.NORMAL, AccountTypeName.NORMAL)

@commands.command('07hs-im-bosses')
async def ironman_bosses(self: Hiscores, ctx: commands.Context, *, username: str | None = None) -> None:
"""Fetches ironman boss hiscores for the given username"""

"""Fetch ironman boss hiscores for the given username."""
await self.reply_with_bosses(ctx, username, AccountType.IRONMAN, AccountTypeName.IRONMAN)

@commands.command('07hs-hcim-bosses')
async def hardcore_ironman_bosses(self: Hiscores, ctx: commands.Context, *, username: str | None = None) -> None:
"""Fetches hardcore ironman boss hiscores for the given username"""

"""Fetch hardcore ironman boss hiscores for the given username."""
await self.reply_with_bosses(ctx, username, AccountType.HARDCORE_IRONMAN, AccountTypeName.HARDCORE_IRONMAN)

@commands.command('07hs-uim-bosses')
async def ultimate_ironman_bosses(self: Hiscores, ctx: commands.Context, *, username: str | None = None) -> None:
"""Fetches ultimate ironman boss hiscores for the given username"""

"""Fetch ultimate ironman boss hiscores for the given username."""
await self.reply_with_bosses(ctx, username, AccountType.ULTIMATE_IRONMAN, AccountTypeName.ULTIMATE_IRONMAN)

@commands.command('07hs-skiller-bosses')
async def skiller_bosses(self: Hiscores, ctx: commands.Context, *, username: str | None = None) -> None:
"""Fetches skiller boss hiscores for the given username"""

"""Fetch skiller boss hiscores for the given username."""
await self.reply_with_bosses(ctx, username, AccountType.SKILLER, AccountTypeName.SKILLER)

@commands.command('07hs-def-bosses')
async def defence_pure_bosses(self: Hiscores, ctx: commands.Context, *, username: str | None = None) -> None:
"""Fetches 1 Defence boss hiscores for the given username"""

"""Fetch 1 Defence boss hiscores for the given username."""
await self.reply_with_bosses(ctx, username, AccountType.DEFENCE_PURE, AccountTypeName.DEFENCE_PURE)

@classmethod
Expand All @@ -140,8 +122,7 @@ async def reply_with_hiscores(cls: type[Hiscores],
username: str | None,
account_type: AccountType,
account_type_name: AccountTypeName) -> Message:
"""Replies to the chat with the given username's hiscores"""

"""Reply to the chat with the given username's hiscores."""
result = "Hiscores not found."

if username is None:
Expand All @@ -160,8 +141,7 @@ async def reply_with_minigames(cls: type[Hiscores],
username: str | None,
account_type: AccountType,
account_type_name: AccountTypeName) -> Message:
"""Replies to the chat with the given username's hiscores"""

"""Reply to the chat with the given username's hiscores."""
result = "Hiscores not found."

if username is None:
Expand All @@ -180,8 +160,7 @@ async def reply_with_bosses(cls: type[Hiscores],
username: str | None,
account_type: AccountType,
account_type_name: AccountTypeName) -> Message | None:
"""Replies to the chat with the given username's hiscores"""

"""Reply to the chat with the given username's hiscores."""
result = "Hiscores not found."

if username is None:
Expand All @@ -207,8 +186,7 @@ async def reply_with_bosses(cls: type[Hiscores],

@staticmethod
async def _fetch_hiscores(username: str, account_type: AccountType) -> list[list[str]] | None:
"""Handles fetching the hiscores for RuneScape accounts"""

"""Handle fetching the hiscores for RuneScape accounts."""
url: str = RUNESCAPE_HISCORES_LITE_URL.format(
hiscores='_oldschool',
gamemode=account_type,
Expand Down
6 changes: 3 additions & 3 deletions src/growlery/config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""This file contains the global configuration settings for the Discord bot"""
"""Global configuration settings for the Discord bot."""

import os
from enum import Enum
Expand Down Expand Up @@ -135,7 +135,7 @@


class AccountType(str, Enum):
"""Specifies different supported account types"""
"""Specify different supported account types."""

NORMAL = ''
IRONMAN = '_ironman'
Expand All @@ -146,7 +146,7 @@ class AccountType(str, Enum):


class AccountTypeName(str, Enum):
"""Specifies names for different supported account types"""
"""Specify names for different supported account types."""

NORMAL = ''
IRONMAN = 'Ironman'
Expand Down
9 changes: 4 additions & 5 deletions src/growlery/http_request.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Code for sending and handling HTTP requests to external services"""
"""Code for sending and handling HTTP requests to external services."""

import logging
from http import HTTPStatus
Expand All @@ -9,8 +9,7 @@


async def fetch_page_content(url: str, status_message_override: dict[HTTPStatus, str] | None = None) -> str:
"""Handles fetching the content from a given web address"""

"""Fetch the content from a given web address."""
result = ''
status_message = {
HTTPStatus.NOT_FOUND: "Could not find resource.",
Expand All @@ -33,7 +32,7 @@ async def fetch_page_content(url: str, status_message_override: dict[HTTPStatus,
),
)

except aiohttp.ClientConnectionError as err:
logger.error("Connection error: %s", err)
except aiohttp.ClientConnectionError:
logger.exception("Connection error")

return result
10 changes: 4 additions & 6 deletions src/growlery/main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Implements the core of the bot"""
"""Implement the core of the bot."""

from __future__ import annotations

Expand All @@ -21,11 +21,10 @@


class MyBot(commands.Bot):
"""Logs events related to the bot"""
"""Log events related to the bot."""

async def on_ready(self: MyBot) -> None:
"""Message indicating that the bot is online"""

"""Message indicating that the bot is online."""
logger.info("Installing cogs...")

for cog in cog_list:
Expand All @@ -34,8 +33,7 @@ async def on_ready(self: MyBot) -> None:
logger.info("Logged in as %s", self.user)

async def on_message(self: MyBot, message: discord.message.Message) -> None: # pylint: disable=W0221
"""New message detected"""

"""Handle message."""
if message.author == self.user:
return

Expand Down
Loading

0 comments on commit 2a436af

Please sign in to comment.