From bbe107b845571b0af449cf3686b5fab8084a3fde Mon Sep 17 00:00:00 2001 From: Chris Lovering Date: Sat, 25 Nov 2023 22:02:00 +0000 Subject: [PATCH] Always use the get_logger func from bot-core --- bot/bot.py | 5 ++--- bot/constants.py | 4 ++-- bot/exts/__init__.py | 5 +++-- bot/exts/avatar_modification/avatar_modify.py | 4 ++-- bot/exts/core/error_handler.py | 10 +++++----- bot/exts/core/extensions.py | 4 ++-- bot/exts/core/help.py | 4 ++-- bot/exts/core/internal_eval/_helpers.py | 5 +++-- bot/exts/core/internal_eval/_internal_eval.py | 4 ++-- .../hacktoberfest/hacktober_issue_finder.py | 4 ++-- bot/exts/events/hacktoberfest/hacktoberstats.py | 16 ++++++++-------- bot/exts/events/hacktoberfest/timeleft.py | 4 ++-- bot/exts/fun/anagram.py | 4 ++-- bot/exts/fun/battleship.py | 4 ++-- bot/exts/fun/fun.py | 4 ++-- bot/exts/fun/game.py | 4 ++-- bot/exts/fun/latex.py | 4 ++-- bot/exts/fun/magic_8ball.py | 4 ++-- bot/exts/fun/minesweeper.py | 4 ++-- bot/exts/fun/movie.py | 4 ++-- bot/exts/fun/quack.py | 4 ++-- bot/exts/fun/recommend_game.py | 4 ++-- bot/exts/fun/snakes/__init__.py | 5 +++-- bot/exts/fun/snakes/_converter.py | 4 ++-- bot/exts/fun/snakes/_snakes_cog.py | 4 ++-- bot/exts/fun/snakes/_utils.py | 4 ++-- bot/exts/fun/space.py | 4 ++-- bot/exts/fun/speedrun.py | 4 ++-- bot/exts/fun/trivia_quiz.py | 4 ++-- bot/exts/fun/xkcd.py | 6 +++--- bot/exts/holidays/easter/april_fools_vids.py | 4 ++-- bot/exts/holidays/easter/bunny_name_generator.py | 4 ++-- bot/exts/holidays/easter/earth_photos.py | 4 ++-- bot/exts/holidays/easter/easter_riddle.py | 4 ++-- bot/exts/holidays/easter/egg_decorating.py | 4 ++-- bot/exts/holidays/easter/egg_facts.py | 4 ++-- bot/exts/holidays/easter/egghead_quiz.py | 4 ++-- bot/exts/holidays/easter/traditions.py | 4 ++-- bot/exts/holidays/halloween/candy_collection.py | 4 ++-- bot/exts/holidays/halloween/eight_ball.py | 4 ++-- bot/exts/holidays/halloween/halloween_facts.py | 4 ++-- bot/exts/holidays/halloween/halloweenify.py | 4 ++-- bot/exts/holidays/halloween/monsterbio.py | 4 ++-- bot/exts/holidays/halloween/monstersurvey.py | 4 ++-- bot/exts/holidays/halloween/scarymovie.py | 4 ++-- bot/exts/holidays/halloween/spookygif.py | 4 ++-- bot/exts/holidays/halloween/spookynamerate.py | 4 ++-- bot/exts/holidays/halloween/spookyrating.py | 4 ++-- bot/exts/holidays/hanukkah/hanukkah_embed.py | 4 ++-- bot/exts/holidays/holidayreact.py | 4 ++-- bot/exts/holidays/pride/drag_queen_name.py | 4 ++-- bot/exts/holidays/pride/pride_anthem.py | 4 ++-- bot/exts/holidays/pride/pride_facts.py | 4 ++-- bot/exts/holidays/pride/pride_leader.py | 4 ++-- bot/exts/holidays/valentines/be_my_valentine.py | 4 ++-- bot/exts/holidays/valentines/lovecalculator.py | 4 ++-- bot/exts/holidays/valentines/movie_generator.py | 4 ++-- bot/exts/holidays/valentines/myvalenstate.py | 4 ++-- bot/exts/holidays/valentines/pickuplines.py | 4 ++-- bot/exts/holidays/valentines/savethedate.py | 4 ++-- bot/exts/holidays/valentines/valentine_zodiac.py | 4 ++-- bot/exts/holidays/valentines/whoisvalentine.py | 4 ++-- bot/exts/utilities/bookmark.py | 4 ++-- bot/exts/utilities/challenges.py | 4 ++-- bot/exts/utilities/emoji.py | 4 ++-- bot/exts/utilities/githubinfo.py | 4 ++-- bot/exts/utilities/realpython.py | 4 ++-- bot/exts/utilities/reddit.py | 4 ++-- bot/exts/utilities/rfc.py | 4 ++-- bot/exts/utilities/stackoverflow.py | 4 ++-- bot/exts/utilities/twemoji.py | 4 ++-- bot/exts/utilities/wikipedia.py | 4 ++-- bot/exts/utilities/wolfram.py | 4 ++-- bot/exts/utilities/wtf_python.py | 4 ++-- bot/utils/checks.py | 4 ++-- bot/utils/decorators.py | 8 ++++---- bot/utils/halloween/spookifications.py | 4 ++-- bot/utils/messages.py | 4 ++-- bot/utils/pagination.py | 4 ++-- 79 files changed, 173 insertions(+), 171 deletions(-) diff --git a/bot/bot.py b/bot/bot.py index c81bfc5f6e..4cb80f0095 100644 --- a/bot/bot.py +++ b/bot/bot.py @@ -1,14 +1,13 @@ -import logging - import discord from discord import DiscordException, Embed from discord.ext import commands from pydis_core import BotBase from pydis_core.utils import scheduling +from pydis_core.utils.logging import get_logger from bot import constants, exts -log = logging.getLogger(__name__) +log = get_logger(__name__) __all__ = ("Bot", ) diff --git a/bot/constants.py b/bot/constants.py index 20953771a3..b0c8accd6c 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -1,9 +1,9 @@ import enum -import logging from os import environ from types import MappingProxyType from pydantic import BaseSettings, SecretStr +from pydis_core.utils.logging import get_logger __all__ = ( "Channels", @@ -28,7 +28,7 @@ "POSITIVE_REPLIES", ) -log = logging.getLogger(__name__) +log = get_logger(__name__) PYTHON_PREFIX = "!" diff --git a/bot/exts/__init__.py b/bot/exts/__init__.py index cb9c5ae813..ae2036b737 100644 --- a/bot/exts/__init__.py +++ b/bot/exts/__init__.py @@ -1,10 +1,11 @@ -import logging import pkgutil from collections.abc import Iterator +from pydis_core.utils.logging import get_logger + __all__ = ("get_package_names",) -log = logging.getLogger(__name__) +log = get_logger(__name__) def get_package_names() -> Iterator[str]: diff --git a/bot/exts/avatar_modification/avatar_modify.py b/bot/exts/avatar_modification/avatar_modify.py index 4eae269fa9..5f0b240058 100644 --- a/bot/exts/avatar_modification/avatar_modify.py +++ b/bot/exts/avatar_modification/avatar_modify.py @@ -1,6 +1,5 @@ import asyncio import json -import logging import math import string import unicodedata @@ -11,13 +10,14 @@ import discord from discord.ext import commands +from pydis_core.utils.logging import get_logger from bot.bot import Bot from bot.constants import Colours, Emojis from bot.exts.avatar_modification._effects import PfpEffects from bot.utils.halloween import spookifications -log = logging.getLogger(__name__) +log = get_logger(__name__) _EXECUTOR = ThreadPoolExecutor(10) diff --git a/bot/exts/core/error_handler.py b/bot/exts/core/error_handler.py index 81b923fdbf..cf116ba029 100644 --- a/bot/exts/core/error_handler.py +++ b/bot/exts/core/error_handler.py @@ -1,10 +1,10 @@ -import logging import math import random from collections.abc import Iterable from discord import Embed, Message from discord.ext import commands +from pydis_core.utils.logging import get_logger from sentry_sdk import push_scope from bot.bot import Bot @@ -13,7 +13,7 @@ from bot.utils.decorators import InChannelCheckFailure, InMonthCheckFailure from bot.utils.exceptions import APIError, MovedCommandError, UserNotPlayingError -log = logging.getLogger(__name__) +log = get_logger(__name__) DELETE_DELAY = 10 @@ -32,7 +32,7 @@ def revert_cooldown_counter(command: commands.Command, message: Message) -> None if command._buckets.valid: bucket = command._buckets.get_bucket(message) bucket._tokens = min(bucket.rate, bucket._tokens + 1) - logging.debug("Cooldown counter reverted as the command was not used correctly.") + log.debug("Cooldown counter reverted as the command was not used correctly.") @staticmethod def error_embed(message: str, title: Iterable | str = ERROR_REPLIES) -> Embed: @@ -49,7 +49,7 @@ def error_embed(message: str, title: Iterable | str = ERROR_REPLIES) -> Embed: async def on_command_error(self, ctx: commands.Context, error: commands.CommandError) -> None: """Activates when a command raises an error.""" if getattr(error, "handled", False): - logging.debug(f"Command {ctx.command} had its error already handled locally; ignoring.") + log.debug(f"Command {ctx.command} had its error already handled locally; ignoring.") return parent_command = "" @@ -58,7 +58,7 @@ async def on_command_error(self, ctx: commands.Context, error: commands.CommandE ctx = subctx error = getattr(error, "original", error) - logging.debug( + log.debug( f"Error Encountered: {type(error).__name__} - {error!s}, " f"Command: {ctx.command}, " f"Author: {ctx.author}, " diff --git a/bot/exts/core/extensions.py b/bot/exts/core/extensions.py index f96b029234..cfba58c8aa 100644 --- a/bot/exts/core/extensions.py +++ b/bot/exts/core/extensions.py @@ -1,5 +1,4 @@ import functools -import logging from collections.abc import Mapping from enum import Enum @@ -7,6 +6,7 @@ from discord.ext import commands from discord.ext.commands import Context, group from pydis_core.utils._extensions import unqualify +from pydis_core.utils.logging import get_logger from bot import exts from bot.bot import Bot @@ -14,7 +14,7 @@ from bot.utils.checks import with_role_check from bot.utils.pagination import LinePaginator -log = logging.getLogger(__name__) +log = get_logger(__name__) UNLOAD_BLACKLIST = {f"{exts.__name__}.core.extensions"} diff --git a/bot/exts/core/help.py b/bot/exts/core/help.py index 9f96a333b7..7721d2000a 100644 --- a/bot/exts/core/help.py +++ b/bot/exts/core/help.py @@ -1,13 +1,13 @@ # Help command from Python bot. All commands that will be added to there in futures should be added to here too. import asyncio import itertools -import logging from contextlib import suppress from typing import NamedTuple from discord import Colour, Embed, HTTPException, Message, Reaction, User from discord.ext import commands from discord.ext.commands import CheckFailure, Cog as DiscordCog, Command, Context +from pydis_core.utils.logging import get_logger from bot import constants from bot.bot import Bot @@ -35,7 +35,7 @@ class Cog(NamedTuple): commands: list[Command] -log = logging.getLogger(__name__) +log = get_logger(__name__) class HelpQueryNotFoundError(ValueError): diff --git a/bot/exts/core/internal_eval/_helpers.py b/bot/exts/core/internal_eval/_helpers.py index 30c4b11c8b..766f116016 100644 --- a/bot/exts/core/internal_eval/_helpers.py +++ b/bot/exts/core/internal_eval/_helpers.py @@ -4,13 +4,14 @@ import functools import inspect import io -import logging import sys import traceback import types from typing import Any -log = logging.getLogger(__name__) +from pydis_core.utils.logging import get_logger + +log = get_logger(__name__) # A type alias to annotate the tuples returned from `sys.exc_info()` ExcInfo = tuple[type[Exception], Exception, types.TracebackType] diff --git a/bot/exts/core/internal_eval/_internal_eval.py b/bot/exts/core/internal_eval/_internal_eval.py index 1ae3c043f7..39ce558a1f 100644 --- a/bot/exts/core/internal_eval/_internal_eval.py +++ b/bot/exts/core/internal_eval/_internal_eval.py @@ -1,9 +1,9 @@ -import logging import re import textwrap import discord from discord.ext import commands +from pydis_core.utils.logging import get_logger from bot.bot import Bot from bot.constants import Client, Roles @@ -13,7 +13,7 @@ __all__ = ["InternalEval"] -log = logging.getLogger(__name__) +log = get_logger(__name__) FORMATTED_CODE_REGEX = re.compile( r"(?P(?P```)|``?)" # code delimiter: 1-3 backticks; (?P=block) only matches if it's a block diff --git a/bot/exts/events/hacktoberfest/hacktober_issue_finder.py b/bot/exts/events/hacktoberfest/hacktober_issue_finder.py index 69aa392433..dbf8f74797 100644 --- a/bot/exts/events/hacktoberfest/hacktober_issue_finder.py +++ b/bot/exts/events/hacktoberfest/hacktober_issue_finder.py @@ -1,15 +1,15 @@ -import logging import random from datetime import UTC, datetime import discord from discord.ext import commands +from pydis_core.utils.logging import get_logger from bot.bot import Bot from bot.constants import Month, Tokens from bot.utils.decorators import in_month -log = logging.getLogger(__name__) +log = get_logger(__name__) URL = "https://api.github.com/search/issues?per_page=100&q=is:issue+label:hacktoberfest+language:python+state:open" diff --git a/bot/exts/events/hacktoberfest/hacktoberstats.py b/bot/exts/events/hacktoberfest/hacktoberstats.py index 04dc4aaec4..e934525b86 100644 --- a/bot/exts/events/hacktoberfest/hacktoberstats.py +++ b/bot/exts/events/hacktoberfest/hacktoberstats.py @@ -1,4 +1,3 @@ -import logging import random import re from collections import Counter @@ -8,12 +7,13 @@ import discord from async_rediscache import RedisCache from discord.ext import commands +from pydis_core.utils.logging import get_logger from bot.bot import Bot from bot.constants import Colours, Month, NEGATIVE_REPLIES, Tokens from bot.utils.decorators import in_month -log = logging.getLogger(__name__) +log = get_logger(__name__) CURRENT_YEAR = datetime.now(tz=UTC).year # Used to construct GH API query PRS_FOR_SHIRT = 4 # Minimum number of PRs before a shirt is awarded @@ -56,7 +56,7 @@ async def hacktoberstats_group(self, ctx: commands.Context, github_username: str if await self.linked_accounts.contains(author_id): github_username = await self.linked_accounts.get(author_id) - logging.info(f"Getting stats for {author_id} linked GitHub account '{github_username}'") + log.info(f"Getting stats for {author_id} linked GitHub account '{github_username}'") else: msg = ( f"{author_mention}, you have not linked a GitHub account\n\n" @@ -100,10 +100,10 @@ async def unlink_user(self, ctx: commands.Context) -> None: stored_user = await self.linked_accounts.pop(author_id, None) if stored_user: await ctx.send(f"{author_mention}, your GitHub profile has been unlinked") - logging.info(f"{author_id} has unlinked their GitHub account") + log.info(f"{author_id} has unlinked their GitHub account") else: await ctx.send(f"{author_mention}, you do not currently have a linked GitHub account") - logging.info(f"{author_id} tried to unlink their GitHub account but no account was linked") + log.info(f"{author_id} tried to unlink their GitHub account but no account was linked") async def get_stats(self, ctx: commands.Context, github_username: str) -> None: """ @@ -140,7 +140,7 @@ async def get_stats(self, ctx: commands.Context, github_username: str) -> None: async def build_embed(self, github_username: str, prs: list[dict]) -> discord.Embed: """Return a stats embed built from github_username's PRs.""" - logging.info(f"Building Hacktoberfest embed for GitHub user: '{github_username}'") + log.info(f"Building Hacktoberfest embed for GitHub user: '{github_username}'") in_review, accepted = await self._categorize_prs(prs) n = len(accepted) + len(in_review) # Total number of PRs @@ -181,7 +181,7 @@ async def build_embed(self, github_username: str, prs: list[dict]) -> discord.Em value=accepted_str ) - logging.info(f"Hacktoberfest PR built for GitHub user '{github_username}'") + log.info(f"Hacktoberfest PR built for GitHub user '{github_username}'") return stats_embed async def get_october_prs(self, github_username: str) -> list[dict] | None: @@ -242,7 +242,7 @@ async def get_october_prs(self, github_username: str) -> list[dict] | None: log.info(f"No October PRs found for GitHub user: '{github_username}'") return [] - logging.info(f"Found {len(jsonresp['items'])} Hacktoberfest PRs for GitHub user: '{github_username}'") + log.info(f"Found {len(jsonresp['items'])} Hacktoberfest PRs for GitHub user: '{github_username}'") outlist = [] # list of pr information dicts that will get returned oct3 = datetime(int(CURRENT_YEAR), 10, 3, 23, 59, 59, tzinfo=UTC) hackto_topics = {} # cache whether each repo has the appropriate topic (bool values) diff --git a/bot/exts/events/hacktoberfest/timeleft.py b/bot/exts/events/hacktoberfest/timeleft.py index 8f46d79847..9fa1ef707d 100644 --- a/bot/exts/events/hacktoberfest/timeleft.py +++ b/bot/exts/events/hacktoberfest/timeleft.py @@ -1,11 +1,11 @@ -import logging from datetime import UTC, datetime from discord.ext import commands +from pydis_core.utils.logging import get_logger from bot.bot import Bot -log = logging.getLogger(__name__) +log = get_logger(__name__) class TimeLeft(commands.Cog): diff --git a/bot/exts/fun/anagram.py b/bot/exts/fun/anagram.py index 8210d1d55d..4e23c0798e 100644 --- a/bot/exts/fun/anagram.py +++ b/bot/exts/fun/anagram.py @@ -1,16 +1,16 @@ import asyncio import json -import logging import random from pathlib import Path import discord from discord.ext import commands +from pydis_core.utils.logging import get_logger from bot.bot import Bot from bot.constants import Colours -log = logging.getLogger(__name__) +log = get_logger(__name__) TIME_LIMIT = 60 diff --git a/bot/exts/fun/battleship.py b/bot/exts/fun/battleship.py index ded784beb9..a209ff0217 100644 --- a/bot/exts/fun/battleship.py +++ b/bot/exts/fun/battleship.py @@ -1,4 +1,3 @@ -import logging import random import re from dataclasses import dataclass @@ -6,11 +5,12 @@ import discord from discord.ext import commands +from pydis_core.utils.logging import get_logger from bot.bot import Bot from bot.constants import Colours -log = logging.getLogger(__name__) +log = get_logger(__name__) @dataclass diff --git a/bot/exts/fun/fun.py b/bot/exts/fun/fun.py index 16279dd7fe..66c4851729 100644 --- a/bot/exts/fun/fun.py +++ b/bot/exts/fun/fun.py @@ -1,5 +1,4 @@ import json -import logging import random from collections.abc import Iterable from pathlib import Path @@ -10,12 +9,13 @@ from discord.ext import commands from discord.ext.commands import BadArgument, Cog, Context from pydis_core.utils.commands import clean_text_or_reply +from pydis_core.utils.logging import get_logger from bot.bot import Bot from bot.constants import Client, Colours, Emojis from bot.utils import helpers, messages -log = logging.getLogger(__name__) +log = get_logger(__name__) def caesar_cipher(text: str, offset: int) -> Iterable[str]: diff --git a/bot/exts/fun/game.py b/bot/exts/fun/game.py index c9824f22a2..9c253ca122 100644 --- a/bot/exts/fun/game.py +++ b/bot/exts/fun/game.py @@ -1,5 +1,4 @@ import difflib -import logging import random import re from datetime import UTC, datetime, timedelta @@ -11,6 +10,7 @@ from discord.ext import tasks from discord.ext.commands import Cog, Context, group from pydis_core.utils import scheduling +from pydis_core.utils.logging import get_logger from bot.bot import Bot from bot.constants import STAFF_ROLES, Tokens @@ -40,7 +40,7 @@ "Accept": "application/json" } -logger = logging.getLogger(__name__) +logger = get_logger(__name__) REGEX_NON_ALPHABET = re.compile(r"[^a-z0-9]", re.IGNORECASE) diff --git a/bot/exts/fun/latex.py b/bot/exts/fun/latex.py index b7bd708ecb..cd7dba11c5 100644 --- a/bot/exts/fun/latex.py +++ b/bot/exts/fun/latex.py @@ -1,5 +1,4 @@ import hashlib -import logging import os import re import string @@ -11,12 +10,13 @@ from PIL import Image from aiohttp import client_exceptions, web from discord.ext import commands +from pydis_core.utils.logging import get_logger from bot.bot import Bot from bot.constants import Channels, WHITELISTED_CHANNELS from bot.utils.decorators import whitelist_override -log = logging.getLogger(__name__) +log = get_logger(__name__) FORMATTED_CODE_REGEX = re.compile( r"(?P(?P```)|``?)" # code delimiter: 1-3 backticks; (?P=block) only matches if it's a block r"(?(block)(?:(?P[a-z]+)\n)?)" # if we're in a block, match optional language (only letters plus newline) diff --git a/bot/exts/fun/magic_8ball.py b/bot/exts/fun/magic_8ball.py index 95d711c487..7bb3d8860a 100644 --- a/bot/exts/fun/magic_8ball.py +++ b/bot/exts/fun/magic_8ball.py @@ -1,13 +1,13 @@ import json -import logging import random from pathlib import Path from discord.ext import commands +from pydis_core.utils.logging import get_logger from bot.bot import Bot -log = logging.getLogger(__name__) +log = get_logger(__name__) ANSWERS = json.loads(Path("bot/resources/fun/magic8ball.json").read_text("utf8")) diff --git a/bot/exts/fun/minesweeper.py b/bot/exts/fun/minesweeper.py index 69be88d300..29cd8ee9ba 100644 --- a/bot/exts/fun/minesweeper.py +++ b/bot/exts/fun/minesweeper.py @@ -1,10 +1,10 @@ -import logging from collections.abc import Iterator from dataclasses import dataclass from random import randint, random import discord from discord.ext import commands +from pydis_core.utils.logging import get_logger from bot.bot import Bot from bot.constants import Client @@ -29,7 +29,7 @@ "x": ":x:" } -log = logging.getLogger(__name__) +log = get_logger(__name__) GameBoard = list[list[str | int]] diff --git a/bot/exts/fun/movie.py b/bot/exts/fun/movie.py index 3d36b11957..555c4503bd 100644 --- a/bot/exts/fun/movie.py +++ b/bot/exts/fun/movie.py @@ -1,4 +1,3 @@ -import logging import random from enum import Enum from typing import Any @@ -6,13 +5,14 @@ from aiohttp import ClientSession from discord import Embed from discord.ext.commands import Cog, Context, group +from pydis_core.utils.logging import get_logger from bot.bot import Bot from bot.constants import Tokens from bot.utils.exceptions import APIError from bot.utils.pagination import ImagePaginator -logger = logging.getLogger(__name__) +logger = get_logger(__name__) # Define base URL of TMDB BASE_URL = "https://api.themoviedb.org/3/" diff --git a/bot/exts/fun/quack.py b/bot/exts/fun/quack.py index 492e0c0fec..459cb4a220 100644 --- a/bot/exts/fun/quack.py +++ b/bot/exts/fun/quack.py @@ -1,16 +1,16 @@ -import logging import random from typing import Literal import discord from discord.ext import commands +from pydis_core.utils.logging import get_logger from bot.bot import Bot from bot.constants import Colours, NEGATIVE_REPLIES API_URL = "https://quackstack.pythondiscord.com" -log = logging.getLogger(__name__) +log = get_logger(__name__) class Quackstack(commands.Cog): diff --git a/bot/exts/fun/recommend_game.py b/bot/exts/fun/recommend_game.py index e972b9a569..7806ab2f56 100644 --- a/bot/exts/fun/recommend_game.py +++ b/bot/exts/fun/recommend_game.py @@ -1,14 +1,14 @@ import json -import logging from pathlib import Path from random import shuffle import discord from discord.ext import commands +from pydis_core.utils.logging import get_logger from bot.bot import Bot -log = logging.getLogger(__name__) +log = get_logger(__name__) game_recs = [] # Populate the list `game_recs` with resource files diff --git a/bot/exts/fun/snakes/__init__.py b/bot/exts/fun/snakes/__init__.py index be71ac4415..0af8ece296 100644 --- a/bot/exts/fun/snakes/__init__.py +++ b/bot/exts/fun/snakes/__init__.py @@ -1,10 +1,11 @@ -import logging + +from pydis_core.utils.logging import get_logger from bot.bot import Bot from bot.constants import Tokens from bot.exts.fun.snakes._snakes_cog import Snakes -log = logging.getLogger(__name__) +log = get_logger(__name__) async def setup(bot: Bot) -> None: diff --git a/bot/exts/fun/snakes/_converter.py b/bot/exts/fun/snakes/_converter.py index c24ba8c66f..43a99a9dcf 100644 --- a/bot/exts/fun/snakes/_converter.py +++ b/bot/exts/fun/snakes/_converter.py @@ -1,16 +1,16 @@ import json -import logging import random from collections.abc import Iterable import discord from discord.ext.commands import Context, Converter +from pydis_core.utils.logging import get_logger from rapidfuzz import fuzz from bot.exts.fun.snakes._utils import SNAKE_RESOURCES from bot.utils import disambiguate -log = logging.getLogger(__name__) +log = get_logger(__name__) class Snake(Converter): diff --git a/bot/exts/fun/snakes/_snakes_cog.py b/bot/exts/fun/snakes/_snakes_cog.py index dfe2903ad1..3f0a0764b9 100644 --- a/bot/exts/fun/snakes/_snakes_cog.py +++ b/bot/exts/fun/snakes/_snakes_cog.py @@ -1,6 +1,5 @@ import asyncio import colorsys -import logging import os import random import re @@ -16,6 +15,7 @@ from discord import Colour, Embed, File, Member, Message, Reaction from discord.errors import HTTPException from discord.ext.commands import Cog, CommandError, Context, bot_has_permissions, group +from pydis_core.utils.logging import get_logger from bot.bot import Bot from bot.constants import ERROR_REPLIES, Tokens @@ -23,7 +23,7 @@ from bot.exts.fun.snakes._converter import Snake from bot.utils.decorators import locked -log = logging.getLogger(__name__) +log = get_logger(__name__) # region: Constants diff --git a/bot/exts/fun/snakes/_utils.py b/bot/exts/fun/snakes/_utils.py index c48ecf8d29..8d24a6aade 100644 --- a/bot/exts/fun/snakes/_utils.py +++ b/bot/exts/fun/snakes/_utils.py @@ -1,6 +1,5 @@ import io import json -import logging import math import random from itertools import product @@ -10,6 +9,7 @@ from PIL.ImageDraw import ImageDraw from discord import File, Member, Reaction, User from discord.ext.commands import Cog, Context +from pydis_core.utils.logging import get_logger from bot.constants import MODERATION_ROLES @@ -354,7 +354,7 @@ def frame_to_png_bytes(image: Image) -> io.BytesIO: return stream -log = logging.getLogger(__name__) +log = get_logger(__name__) START_EMOJI = "\u2611" # :ballot_box_with_check: - Start the game CANCEL_EMOJI = "\u274C" # :x: - Cancel or leave the game ROLL_EMOJI = "\U0001F3B2" # :game_die: - Roll the die! diff --git a/bot/exts/fun/space.py b/bot/exts/fun/space.py index 3a666bfce2..f2c934bc24 100644 --- a/bot/exts/fun/space.py +++ b/bot/exts/fun/space.py @@ -1,4 +1,3 @@ -import logging import random from datetime import UTC, date, datetime from typing import Any @@ -7,12 +6,13 @@ from discord import Embed from discord.ext import tasks from discord.ext.commands import Cog, Context, group +from pydis_core.utils.logging import get_logger from bot.bot import Bot from bot.constants import Tokens from bot.utils.converters import DateConverter -logger = logging.getLogger(__name__) +logger = get_logger(__name__) NASA_BASE_URL = "https://api.nasa.gov" NASA_IMAGES_BASE_URL = "https://images-api.nasa.gov" diff --git a/bot/exts/fun/speedrun.py b/bot/exts/fun/speedrun.py index 43e570a2a7..3685b87075 100644 --- a/bot/exts/fun/speedrun.py +++ b/bot/exts/fun/speedrun.py @@ -1,13 +1,13 @@ import json -import logging from pathlib import Path from random import choice from discord.ext import commands +from pydis_core.utils.logging import get_logger from bot.bot import Bot -log = logging.getLogger(__name__) +log = get_logger(__name__) LINKS = json.loads(Path("bot/resources/fun/speedrun_links.json").read_text("utf8")) diff --git a/bot/exts/fun/trivia_quiz.py b/bot/exts/fun/trivia_quiz.py index 4f352b71ec..d7b49f7abf 100644 --- a/bot/exts/fun/trivia_quiz.py +++ b/bot/exts/fun/trivia_quiz.py @@ -1,6 +1,5 @@ import asyncio import json -import logging import operator import random import re @@ -13,12 +12,13 @@ import discord from discord.ext import commands, tasks +from pydis_core.utils.logging import get_logger from rapidfuzz import fuzz from bot.bot import Bot from bot.constants import Client, Colours, MODERATION_ROLES, NEGATIVE_REPLIES -logger = logging.getLogger(__name__) +logger = get_logger(__name__) DEFAULT_QUESTION_LIMIT = 7 STANDARD_VARIATION_TOLERANCE = 88 diff --git a/bot/exts/fun/xkcd.py b/bot/exts/fun/xkcd.py index 7b34795cd2..df00d89ddf 100644 --- a/bot/exts/fun/xkcd.py +++ b/bot/exts/fun/xkcd.py @@ -1,15 +1,15 @@ -import logging import re from random import randint from discord import Embed from discord.ext import tasks from discord.ext.commands import Cog, Context, command +from pydis_core.utils.logging import get_logger from bot.bot import Bot from bot.constants import Colours -log = logging.getLogger(__name__) +log = get_logger(__name__) COMIC_FORMAT = re.compile(r"latest|[0-9]+") BASE_URL = "https://xkcd.com" @@ -74,7 +74,7 @@ async def fetch_xkcd_comics(self, ctx: Context, comic: str | None) -> None: if info["img"][-3:] in ("jpg", "png", "gif"): embed.set_image(url=info["img"]) date = f"{info['year']}/{info['month']}/{info['day']}" - embed.set_footer(text=f"{date} - #{info['num']}, \'{info['safe_title']}\'") + embed.set_footer(text=f"{date} - #{info['num']}, '{info['safe_title']}'") embed.colour = Colours.soft_green else: embed.description = ( diff --git a/bot/exts/holidays/easter/april_fools_vids.py b/bot/exts/holidays/easter/april_fools_vids.py index 7f46a5694d..c89ee5a05f 100644 --- a/bot/exts/holidays/easter/april_fools_vids.py +++ b/bot/exts/holidays/easter/april_fools_vids.py @@ -1,13 +1,13 @@ -import logging import random from json import loads from pathlib import Path from discord.ext import commands +from pydis_core.utils.logging import get_logger from bot.bot import Bot -log = logging.getLogger(__name__) +log = get_logger(__name__) ALL_VIDS = loads(Path("bot/resources/holidays/easter/april_fools_vids.json").read_text("utf-8")) diff --git a/bot/exts/holidays/easter/bunny_name_generator.py b/bot/exts/holidays/easter/bunny_name_generator.py index 3034da4a64..011311995c 100644 --- a/bot/exts/holidays/easter/bunny_name_generator.py +++ b/bot/exts/holidays/easter/bunny_name_generator.py @@ -1,14 +1,14 @@ import json -import logging import random import re from pathlib import Path from discord.ext import commands +from pydis_core.utils.logging import get_logger from bot.bot import Bot -log = logging.getLogger(__name__) +log = get_logger(__name__) BUNNY_NAMES = json.loads(Path("bot/resources/holidays/easter/bunny_names.json").read_text("utf8")) diff --git a/bot/exts/holidays/easter/earth_photos.py b/bot/exts/holidays/easter/earth_photos.py index 66f1b07b36..6a88d4c8f0 100644 --- a/bot/exts/holidays/easter/earth_photos.py +++ b/bot/exts/holidays/easter/earth_photos.py @@ -1,12 +1,12 @@ -import logging import discord from discord.ext import commands +from pydis_core.utils.logging import get_logger from bot.bot import Bot from bot.constants import Colours, Tokens -log = logging.getLogger(__name__) +log = get_logger(__name__) API_URL = "https://api.unsplash.com/photos/random" diff --git a/bot/exts/holidays/easter/easter_riddle.py b/bot/exts/holidays/easter/easter_riddle.py index 6c29dd1754..f9ddc4292b 100644 --- a/bot/exts/holidays/easter/easter_riddle.py +++ b/bot/exts/holidays/easter/easter_riddle.py @@ -1,16 +1,16 @@ import asyncio -import logging import random from json import loads from pathlib import Path import discord from discord.ext import commands +from pydis_core.utils.logging import get_logger from bot.bot import Bot from bot.constants import Colours, NEGATIVE_REPLIES -log = logging.getLogger(__name__) +log = get_logger(__name__) RIDDLE_QUESTIONS = loads(Path("bot/resources/holidays/easter/easter_riddle.json").read_text("utf8")) diff --git a/bot/exts/holidays/easter/egg_decorating.py b/bot/exts/holidays/easter/egg_decorating.py index 1327f4d0eb..097f958d58 100644 --- a/bot/exts/holidays/easter/egg_decorating.py +++ b/bot/exts/holidays/easter/egg_decorating.py @@ -1,5 +1,4 @@ import json -import logging import random from contextlib import suppress from io import BytesIO @@ -8,11 +7,12 @@ import discord from PIL import Image from discord.ext import commands +from pydis_core.utils.logging import get_logger from bot.bot import Bot from bot.utils import helpers -log = logging.getLogger(__name__) +log = get_logger(__name__) HTML_COLOURS = json.loads(Path("bot/resources/fun/html_colours.json").read_text("utf8")) diff --git a/bot/exts/holidays/easter/egg_facts.py b/bot/exts/holidays/easter/egg_facts.py index 43b31c7b69..0e746c2963 100644 --- a/bot/exts/holidays/easter/egg_facts.py +++ b/bot/exts/holidays/easter/egg_facts.py @@ -1,16 +1,16 @@ -import logging import random from json import loads from pathlib import Path import discord from discord.ext import commands +from pydis_core.utils.logging import get_logger from bot.bot import Bot from bot.constants import Channels, Colours, Month from bot.utils.decorators import seasonal_task -log = logging.getLogger(__name__) +log = get_logger(__name__) EGG_FACTS = loads(Path("bot/resources/holidays/easter/easter_egg_facts.json").read_text("utf8")) diff --git a/bot/exts/holidays/easter/egghead_quiz.py b/bot/exts/holidays/easter/egghead_quiz.py index 046f9facef..a876ae8b46 100644 --- a/bot/exts/holidays/easter/egghead_quiz.py +++ b/bot/exts/holidays/easter/egghead_quiz.py @@ -1,16 +1,16 @@ import asyncio -import logging import random from json import loads from pathlib import Path import discord from discord.ext import commands +from pydis_core.utils.logging import get_logger from bot.bot import Bot from bot.constants import Colours -log = logging.getLogger(__name__) +log = get_logger(__name__) EGGHEAD_QUESTIONS = loads(Path("bot/resources/holidays/easter/egghead_questions.json").read_text("utf8")) diff --git a/bot/exts/holidays/easter/traditions.py b/bot/exts/holidays/easter/traditions.py index 3ac5617ca4..5d87abfd1b 100644 --- a/bot/exts/holidays/easter/traditions.py +++ b/bot/exts/holidays/easter/traditions.py @@ -1,13 +1,13 @@ import json -import logging import random from pathlib import Path from discord.ext import commands +from pydis_core.utils.logging import get_logger from bot.bot import Bot -log = logging.getLogger(__name__) +log = get_logger(__name__) traditions = json.loads(Path("bot/resources/holidays/easter/traditions.json").read_text("utf8")) diff --git a/bot/exts/holidays/halloween/candy_collection.py b/bot/exts/holidays/halloween/candy_collection.py index ca68888baa..ce3f5f6bde 100644 --- a/bot/exts/holidays/halloween/candy_collection.py +++ b/bot/exts/holidays/halloween/candy_collection.py @@ -1,15 +1,15 @@ -import logging import random import discord from async_rediscache import RedisCache from discord.ext import commands +from pydis_core.utils.logging import get_logger from bot.bot import Bot from bot.constants import Channels, Month from bot.utils.decorators import in_month -log = logging.getLogger(__name__) +log = get_logger(__name__) # chance is 1 in x range, so 1 in 20 range would give 5% chance (for add candy) ADD_CANDY_REACTION_CHANCE = 20 # 5% diff --git a/bot/exts/holidays/halloween/eight_ball.py b/bot/exts/holidays/halloween/eight_ball.py index 21b55a0157..10b2bda471 100644 --- a/bot/exts/holidays/halloween/eight_ball.py +++ b/bot/exts/holidays/halloween/eight_ball.py @@ -1,14 +1,14 @@ import asyncio import json -import logging import random from pathlib import Path from discord.ext import commands +from pydis_core.utils.logging import get_logger from bot.bot import Bot -log = logging.getLogger(__name__) +log = get_logger(__name__) RESPONSES = json.loads(Path("bot/resources/holidays/halloween/responses.json").read_text("utf8")) diff --git a/bot/exts/holidays/halloween/halloween_facts.py b/bot/exts/holidays/halloween/halloween_facts.py index a0d63f646a..daad26d359 100644 --- a/bot/exts/holidays/halloween/halloween_facts.py +++ b/bot/exts/holidays/halloween/halloween_facts.py @@ -1,15 +1,15 @@ import json -import logging import random from datetime import timedelta from pathlib import Path import discord from discord.ext import commands +from pydis_core.utils.logging import get_logger from bot.bot import Bot -log = logging.getLogger(__name__) +log = get_logger(__name__) SPOOKY_EMOJIS = [ "\N{BAT}", diff --git a/bot/exts/holidays/halloween/halloweenify.py b/bot/exts/holidays/halloween/halloweenify.py index a16ea6cc19..893674415a 100644 --- a/bot/exts/holidays/halloween/halloweenify.py +++ b/bot/exts/holidays/halloween/halloweenify.py @@ -1,4 +1,3 @@ -import logging from json import loads from pathlib import Path from random import choice @@ -7,10 +6,11 @@ from discord.errors import Forbidden from discord.ext import commands from discord.ext.commands import BucketType +from pydis_core.utils.logging import get_logger from bot.bot import Bot -log = logging.getLogger(__name__) +log = get_logger(__name__) HALLOWEENIFY_DATA = loads(Path("bot/resources/holidays/halloween/halloweenify.json").read_text("utf8")) diff --git a/bot/exts/holidays/halloween/monsterbio.py b/bot/exts/holidays/halloween/monsterbio.py index 8e83e9d178..18ec649dcd 100644 --- a/bot/exts/holidays/halloween/monsterbio.py +++ b/bot/exts/holidays/halloween/monsterbio.py @@ -1,15 +1,15 @@ import json -import logging import random from pathlib import Path import discord from discord.ext import commands +from pydis_core.utils.logging import get_logger from bot.bot import Bot from bot.constants import Colours -log = logging.getLogger(__name__) +log = get_logger(__name__) TEXT_OPTIONS = json.loads( Path("bot/resources/holidays/halloween/monster.json").read_text("utf8") diff --git a/bot/exts/holidays/halloween/monstersurvey.py b/bot/exts/holidays/halloween/monstersurvey.py index fdc15e13b5..5cfdae310d 100644 --- a/bot/exts/holidays/halloween/monstersurvey.py +++ b/bot/exts/holidays/halloween/monstersurvey.py @@ -1,12 +1,12 @@ import json -import logging import pathlib from discord import Embed from discord.ext import commands from discord.ext.commands import Bot, Cog, Context +from pydis_core.utils.logging import get_logger -log = logging.getLogger(__name__) +log = get_logger(__name__) EMOJIS = { "SUCCESS": "\u2705", diff --git a/bot/exts/holidays/halloween/scarymovie.py b/bot/exts/holidays/halloween/scarymovie.py index fbab3dd2cc..923a2a2427 100644 --- a/bot/exts/holidays/halloween/scarymovie.py +++ b/bot/exts/holidays/halloween/scarymovie.py @@ -1,13 +1,13 @@ -import logging import random from discord import Embed from discord.ext import commands +from pydis_core.utils.logging import get_logger from bot.bot import Bot from bot.constants import Colours, NEGATIVE_REPLIES, Tokens -log = logging.getLogger(__name__) +log = get_logger(__name__) class ScaryMovie(commands.Cog): diff --git a/bot/exts/holidays/halloween/spookygif.py b/bot/exts/holidays/halloween/spookygif.py index b3f9d70300..45e6936ee1 100644 --- a/bot/exts/holidays/halloween/spookygif.py +++ b/bot/exts/holidays/halloween/spookygif.py @@ -1,12 +1,12 @@ -import logging import discord from discord.ext import commands +from pydis_core.utils.logging import get_logger from bot.bot import Bot from bot.constants import Colours, Tokens -log = logging.getLogger(__name__) +log = get_logger(__name__) API_URL = "http://api.giphy.com/v1/gifs/random" diff --git a/bot/exts/holidays/halloween/spookynamerate.py b/bot/exts/holidays/halloween/spookynamerate.py index 78e8be8ef5..73674c315d 100644 --- a/bot/exts/holidays/halloween/spookynamerate.py +++ b/bot/exts/holidays/halloween/spookynamerate.py @@ -3,7 +3,6 @@ import random from collections import defaultdict from datetime import UTC, datetime, timedelta -from logging import getLogger from os import getenv from pathlib import Path @@ -12,12 +11,13 @@ from discord.colour import Colour from discord.ext import tasks from discord.ext.commands import Cog, Context, group +from pydis_core.utils.logging import get_logger from bot.bot import Bot from bot.constants import Channels, Client, Colours, Month from bot.utils.decorators import InMonthCheckFailure -logger = getLogger(__name__) +logger = get_logger(__name__) EMOJIS_VAL = { "\N{Jack-O-Lantern}": 1, diff --git a/bot/exts/holidays/halloween/spookyrating.py b/bot/exts/holidays/halloween/spookyrating.py index 373b658398..14530e6b38 100644 --- a/bot/exts/holidays/halloween/spookyrating.py +++ b/bot/exts/holidays/halloween/spookyrating.py @@ -1,16 +1,16 @@ import bisect import json -import logging import random from pathlib import Path import discord from discord.ext import commands +from pydis_core.utils.logging import get_logger from bot.bot import Bot from bot.constants import Colours -log = logging.getLogger(__name__) +log = get_logger(__name__) data: dict[str, dict[str, str]] = json.loads( Path("bot/resources/holidays/halloween/spooky_rating.json").read_text("utf8") diff --git a/bot/exts/holidays/hanukkah/hanukkah_embed.py b/bot/exts/holidays/hanukkah/hanukkah_embed.py index fd8edca166..973919a490 100644 --- a/bot/exts/holidays/hanukkah/hanukkah_embed.py +++ b/bot/exts/holidays/hanukkah/hanukkah_embed.py @@ -1,14 +1,14 @@ -import logging from datetime import UTC, date, datetime from discord import Embed from discord.ext import commands +from pydis_core.utils.logging import get_logger from bot.bot import Bot from bot.constants import Colours, Month from bot.utils.decorators import in_month -log = logging.getLogger(__name__) +log = get_logger(__name__) HEBCAL_URL = ( "https://www.hebcal.com/hebcal/?v=1&cfg=json&maj=on&min=on&mod=on&nx=on&" diff --git a/bot/exts/holidays/holidayreact.py b/bot/exts/holidays/holidayreact.py index 306cde5306..ef44115a2f 100644 --- a/bot/exts/holidays/holidayreact.py +++ b/bot/exts/holidays/holidayreact.py @@ -1,17 +1,17 @@ -import logging import random import re from typing import NamedTuple import discord from discord.ext.commands import Cog +from pydis_core.utils.logging import get_logger from bot.bot import Bot from bot.constants import Month from bot.utils import resolve_current_month from bot.utils.decorators import in_month -log = logging.getLogger(__name__) +log = get_logger(__name__) class Trigger(NamedTuple): diff --git a/bot/exts/holidays/pride/drag_queen_name.py b/bot/exts/holidays/pride/drag_queen_name.py index 0c1ca6fbc8..6a89db0a83 100644 --- a/bot/exts/holidays/pride/drag_queen_name.py +++ b/bot/exts/holidays/pride/drag_queen_name.py @@ -1,13 +1,13 @@ import json -import logging import random from pathlib import Path from discord.ext import commands +from pydis_core.utils.logging import get_logger from bot.bot import Bot -log = logging.getLogger(__name__) +log = get_logger(__name__) NAMES = json.loads(Path("bot/resources/holidays/pride/drag_queen_names.json").read_text("utf8")) diff --git a/bot/exts/holidays/pride/pride_anthem.py b/bot/exts/holidays/pride/pride_anthem.py index 1f214fc0b8..a2f2a576ce 100644 --- a/bot/exts/holidays/pride/pride_anthem.py +++ b/bot/exts/holidays/pride/pride_anthem.py @@ -1,13 +1,13 @@ import json -import logging import random from pathlib import Path from discord.ext import commands +from pydis_core.utils.logging import get_logger from bot.bot import Bot -log = logging.getLogger(__name__) +log = get_logger(__name__) VIDEOS = json.loads(Path("bot/resources/holidays/pride/anthems.json").read_text("utf8")) diff --git a/bot/exts/holidays/pride/pride_facts.py b/bot/exts/holidays/pride/pride_facts.py index 7dca953b75..4eec20acf1 100644 --- a/bot/exts/holidays/pride/pride_facts.py +++ b/bot/exts/holidays/pride/pride_facts.py @@ -1,17 +1,17 @@ import json -import logging import random from datetime import UTC, datetime from pathlib import Path import discord from discord.ext import commands +from pydis_core.utils.logging import get_logger from bot.bot import Bot from bot.constants import Channels, Colours, Month from bot.utils.decorators import seasonal_task -log = logging.getLogger(__name__) +log = get_logger(__name__) FACTS = json.loads(Path("bot/resources/holidays/pride/facts.json").read_text("utf8")) diff --git a/bot/exts/holidays/pride/pride_leader.py b/bot/exts/holidays/pride/pride_leader.py index 9f01ebf950..4ebd8e3489 100644 --- a/bot/exts/holidays/pride/pride_leader.py +++ b/bot/exts/holidays/pride/pride_leader.py @@ -1,16 +1,16 @@ import json -import logging import random from pathlib import Path import discord from discord.ext import commands +from pydis_core.utils.logging import get_logger from rapidfuzz import fuzz from bot import constants from bot.bot import Bot -log = logging.getLogger(__name__) +log = get_logger(__name__) PRIDE_RESOURCE = json.loads(Path("bot/resources/holidays/pride/prideleader.json").read_text("utf8")) MINIMUM_FUZZ_RATIO = 40 diff --git a/bot/exts/holidays/valentines/be_my_valentine.py b/bot/exts/holidays/valentines/be_my_valentine.py index 714d388403..8167979478 100644 --- a/bot/exts/holidays/valentines/be_my_valentine.py +++ b/bot/exts/holidays/valentines/be_my_valentine.py @@ -1,17 +1,17 @@ -import logging import random from json import loads from pathlib import Path import discord from discord.ext import commands +from pydis_core.utils.logging import get_logger from bot.bot import Bot from bot.constants import Channels, Colours, Month, PYTHON_PREFIX, Roles from bot.utils.decorators import in_month from bot.utils.exceptions import MovedCommandError -log = logging.getLogger(__name__) +log = get_logger(__name__) HEART_EMOJIS = [":heart:", ":gift_heart:", ":revolving_hearts:", ":sparkling_heart:", ":two_hearts:"] diff --git a/bot/exts/holidays/valentines/lovecalculator.py b/bot/exts/holidays/valentines/lovecalculator.py index 9b363c5ea1..83418f1408 100644 --- a/bot/exts/holidays/valentines/lovecalculator.py +++ b/bot/exts/holidays/valentines/lovecalculator.py @@ -1,7 +1,6 @@ import bisect import hashlib import json -import logging import random from collections.abc import Coroutine from pathlib import Path @@ -10,12 +9,13 @@ from discord import Member from discord.ext import commands from discord.ext.commands import BadArgument, Cog, clean_content +from pydis_core.utils.logging import get_logger from bot.bot import Bot from bot.constants import Channels, Month, PYTHON_PREFIX, Roles from bot.utils.decorators import in_month -log = logging.getLogger(__name__) +log = get_logger(__name__) LOVE_DATA = json.loads(Path("bot/resources/holidays/valentines/love_matches.json").read_text("utf8")) LOVE_DATA = sorted((int(key), value) for key, value in LOVE_DATA.items()) diff --git a/bot/exts/holidays/valentines/movie_generator.py b/bot/exts/holidays/valentines/movie_generator.py index 64b86f1b48..d11c128dfe 100644 --- a/bot/exts/holidays/valentines/movie_generator.py +++ b/bot/exts/holidays/valentines/movie_generator.py @@ -1,15 +1,15 @@ -import logging import random from os import environ import discord from discord.ext import commands +from pydis_core.utils.logging import get_logger from bot.bot import Bot TMDB_API_KEY = environ.get("TMDB_API_KEY") -log = logging.getLogger(__name__) +log = get_logger(__name__) class RomanceMovieFinder(commands.Cog): diff --git a/bot/exts/holidays/valentines/myvalenstate.py b/bot/exts/holidays/valentines/myvalenstate.py index 0f1c7dc949..365baa5608 100644 --- a/bot/exts/holidays/valentines/myvalenstate.py +++ b/bot/exts/holidays/valentines/myvalenstate.py @@ -1,16 +1,16 @@ import collections import json -import logging from pathlib import Path from random import choice import discord from discord.ext import commands +from pydis_core.utils.logging import get_logger from bot.bot import Bot from bot.constants import Colours -log = logging.getLogger(__name__) +log = get_logger(__name__) STATES = json.loads(Path("bot/resources/holidays/valentines/valenstates.json").read_text("utf8")) diff --git a/bot/exts/holidays/valentines/pickuplines.py b/bot/exts/holidays/valentines/pickuplines.py index 8562a07db7..281f23dc1a 100644 --- a/bot/exts/holidays/valentines/pickuplines.py +++ b/bot/exts/holidays/valentines/pickuplines.py @@ -1,15 +1,15 @@ -import logging import random from json import loads from pathlib import Path import discord from discord.ext import commands +from pydis_core.utils.logging import get_logger from bot.bot import Bot from bot.constants import Colours -log = logging.getLogger(__name__) +log = get_logger(__name__) PICKUP_LINES = loads(Path("bot/resources/holidays/valentines/pickup_lines.json").read_text("utf8")) diff --git a/bot/exts/holidays/valentines/savethedate.py b/bot/exts/holidays/valentines/savethedate.py index 7fd644dfff..073a6331fb 100644 --- a/bot/exts/holidays/valentines/savethedate.py +++ b/bot/exts/holidays/valentines/savethedate.py @@ -1,15 +1,15 @@ -import logging import random from json import loads from pathlib import Path import discord from discord.ext import commands +from pydis_core.utils.logging import get_logger from bot.bot import Bot from bot.constants import Colours -log = logging.getLogger(__name__) +log = get_logger(__name__) HEART_EMOJIS = [":heart:", ":gift_heart:", ":revolving_hearts:", ":sparkling_heart:", ":two_hearts:"] diff --git a/bot/exts/holidays/valentines/valentine_zodiac.py b/bot/exts/holidays/valentines/valentine_zodiac.py index f0c8978de2..26d6d19561 100644 --- a/bot/exts/holidays/valentines/valentine_zodiac.py +++ b/bot/exts/holidays/valentines/valentine_zodiac.py @@ -1,17 +1,17 @@ import calendar import json -import logging import random from datetime import UTC, datetime from pathlib import Path import discord from discord.ext import commands +from pydis_core.utils.logging import get_logger from bot.bot import Bot from bot.constants import Colours -log = logging.getLogger(__name__) +log = get_logger(__name__) LETTER_EMOJI = ":love_letter:" HEART_EMOJIS = [":heart:", ":gift_heart:", ":revolving_hearts:", ":sparkling_heart:", ":two_hearts:"] diff --git a/bot/exts/holidays/valentines/whoisvalentine.py b/bot/exts/holidays/valentines/whoisvalentine.py index c652e61693..6a25901a58 100644 --- a/bot/exts/holidays/valentines/whoisvalentine.py +++ b/bot/exts/holidays/valentines/whoisvalentine.py @@ -1,15 +1,15 @@ import json -import logging from pathlib import Path from random import choice import discord from discord.ext import commands +from pydis_core.utils.logging import get_logger from bot.bot import Bot from bot.constants import Colours -log = logging.getLogger(__name__) +log = get_logger(__name__) FACTS = json.loads(Path("bot/resources/holidays/valentines/valentine_facts.json").read_text("utf8")) diff --git a/bot/exts/utilities/bookmark.py b/bot/exts/utilities/bookmark.py index 22801d1433..51d01469dd 100644 --- a/bot/exts/utilities/bookmark.py +++ b/bot/exts/utilities/bookmark.py @@ -1,15 +1,15 @@ -import logging import random import discord from discord.ext import commands +from pydis_core.utils.logging import get_logger from bot.bot import Bot from bot.constants import Colours, ERROR_REPLIES, Icons, Roles from bot.utils.converters import WrappedMessageConverter from bot.utils.decorators import whitelist_override -log = logging.getLogger(__name__) +log = get_logger(__name__) MESSAGE_NOT_FOUND_ERROR = ( "You must either provide a reference to a valid message, or reply to one." diff --git a/bot/exts/utilities/challenges.py b/bot/exts/utilities/challenges.py index 6d1813bb07..f25a0ba771 100644 --- a/bot/exts/utilities/challenges.py +++ b/bot/exts/utilities/challenges.py @@ -1,15 +1,15 @@ -import logging from asyncio import to_thread from random import choice from bs4 import BeautifulSoup from discord import Embed, Interaction, SelectOption, ui from discord.ext import commands +from pydis_core.utils.logging import get_logger from bot.bot import Bot from bot.constants import Colours, Emojis, NEGATIVE_REPLIES -log = logging.getLogger(__name__) +log = get_logger(__name__) API_ROOT = "https://www.codewars.com/api/v1/code-challenges/{kata_id}" # Map difficulty for the kata to color we want to display in the embed. diff --git a/bot/exts/utilities/emoji.py b/bot/exts/utilities/emoji.py index bbaf6d2582..115e5148e5 100644 --- a/bot/exts/utilities/emoji.py +++ b/bot/exts/utilities/emoji.py @@ -1,4 +1,3 @@ -import logging import random import textwrap from collections import defaultdict @@ -6,13 +5,14 @@ from discord import Color, Embed, Emoji from discord.ext import commands +from pydis_core.utils.logging import get_logger from bot.bot import Bot from bot.constants import Colours, ERROR_REPLIES from bot.utils.pagination import LinePaginator from bot.utils.time import time_since -log = logging.getLogger(__name__) +log = get_logger(__name__) class Emojis(commands.Cog): diff --git a/bot/exts/utilities/githubinfo.py b/bot/exts/utilities/githubinfo.py index 41b9415a36..f567f836b3 100644 --- a/bot/exts/utilities/githubinfo.py +++ b/bot/exts/utilities/githubinfo.py @@ -1,4 +1,3 @@ -import logging import random import re from dataclasses import dataclass @@ -8,11 +7,12 @@ import discord from aiohttp import ClientResponse from discord.ext import commands +from pydis_core.utils.logging import get_logger from bot.bot import Bot from bot.constants import Colours, ERROR_REPLIES, Emojis, NEGATIVE_REPLIES, Tokens -log = logging.getLogger(__name__) +log = get_logger(__name__) GITHUB_API_URL = "https://api.github.com" diff --git a/bot/exts/utilities/realpython.py b/bot/exts/utilities/realpython.py index c63fca855f..ade0021e5d 100644 --- a/bot/exts/utilities/realpython.py +++ b/bot/exts/utilities/realpython.py @@ -1,14 +1,14 @@ -import logging from html import unescape from urllib.parse import quote_plus from discord import Embed from discord.ext import commands +from pydis_core.utils.logging import get_logger from bot.bot import Bot from bot.constants import Colours -logger = logging.getLogger(__name__) +logger = get_logger(__name__) API_ROOT = "https://realpython.com/search/api/v1/" ARTICLE_URL = "https://realpython.com{article_url}" diff --git a/bot/exts/utilities/reddit.py b/bot/exts/utilities/reddit.py index 5dd4a377c5..085be42ab6 100644 --- a/bot/exts/utilities/reddit.py +++ b/bot/exts/utilities/reddit.py @@ -1,5 +1,4 @@ import asyncio -import logging import random import textwrap from collections import namedtuple @@ -10,6 +9,7 @@ from discord.ext.commands import Cog, Context, group, has_any_role from discord.ext.tasks import loop from discord.utils import escape_markdown, sleep_until +from pydis_core.utils.logging import get_logger from bot.bot import Bot from bot.constants import Channels, ERROR_REPLIES, Emojis, Reddit as RedditConfig, STAFF_ROLES @@ -17,7 +17,7 @@ from bot.utils.messages import sub_clyde from bot.utils.pagination import ImagePaginator, LinePaginator -log = logging.getLogger(__name__) +log = get_logger(__name__) AccessToken = namedtuple("AccessToken", ["token", "expires_at"]) HEADERS = {"User-Agent": "python3:python-discord/bot:1.0.0 (by /u/PythonDiscord)"} diff --git a/bot/exts/utilities/rfc.py b/bot/exts/utilities/rfc.py index f1bbfb89e7..8143f5eee7 100644 --- a/bot/exts/utilities/rfc.py +++ b/bot/exts/utilities/rfc.py @@ -1,15 +1,15 @@ import datetime -import logging import pydantic from discord import Embed from discord.ext import commands +from pydis_core.utils.logging import get_logger from bot.bot import Bot from bot.constants import Colours, Roles from bot.utils.decorators import whitelist_override -logger = logging.getLogger(__name__) +logger = get_logger(__name__) API_URL = "https://datatracker.ietf.org/doc/rfc{rfc_id}/doc.json" DOCUMENT_URL = "https://datatracker.ietf.org/doc/rfc{rfc_id}" diff --git a/bot/exts/utilities/stackoverflow.py b/bot/exts/utilities/stackoverflow.py index 1eeff45b55..2ef284a216 100644 --- a/bot/exts/utilities/stackoverflow.py +++ b/bot/exts/utilities/stackoverflow.py @@ -1,14 +1,14 @@ -import logging from html import unescape from urllib.parse import quote_plus from discord import Embed, HTTPException from discord.ext import commands +from pydis_core.utils.logging import get_logger from bot.bot import Bot from bot.constants import Colours, Emojis -logger = logging.getLogger(__name__) +logger = get_logger(__name__) BASE_URL = "https://api.stackexchange.com/2.2/search/advanced" SO_PARAMS = { diff --git a/bot/exts/utilities/twemoji.py b/bot/exts/utilities/twemoji.py index a936f733bf..6552aa561b 100644 --- a/bot/exts/utilities/twemoji.py +++ b/bot/exts/utilities/twemoji.py @@ -1,16 +1,16 @@ -import logging import re from typing import Literal import discord from discord.ext import commands from emoji import EMOJI_DATA, is_emoji +from pydis_core.utils.logging import get_logger from bot.bot import Bot from bot.constants import Colours, Roles from bot.utils.decorators import whitelist_override -log = logging.getLogger(__name__) +log = get_logger(__name__) BASE_URLS = { "png": "https://raw.githubusercontent.com/twitter/twemoji/master/assets/72x72/", "svg": "https://raw.githubusercontent.com/twitter/twemoji/master/assets/svg/", diff --git a/bot/exts/utilities/wikipedia.py b/bot/exts/utilities/wikipedia.py index d12cb19d9c..6250f3e64d 100644 --- a/bot/exts/utilities/wikipedia.py +++ b/bot/exts/utilities/wikipedia.py @@ -1,16 +1,16 @@ -import logging import re from datetime import UTC, datetime from html import unescape from discord import Color, Embed, TextChannel from discord.ext import commands +from pydis_core.utils.logging import get_logger from bot.bot import Bot from bot.utils import LinePaginator from bot.utils.exceptions import APIError -log = logging.getLogger(__name__) +log = get_logger(__name__) SEARCH_API = ( "https://en.wikipedia.org/w/api.php" diff --git a/bot/exts/utilities/wolfram.py b/bot/exts/utilities/wolfram.py index e77573a722..b512071a15 100644 --- a/bot/exts/utilities/wolfram.py +++ b/bot/exts/utilities/wolfram.py @@ -1,4 +1,3 @@ -import logging from collections.abc import Callable from io import BytesIO from urllib.parse import urlencode @@ -8,12 +7,13 @@ from discord import Embed from discord.ext import commands from discord.ext.commands import BucketType, Cog, Context, check, group +from pydis_core.utils.logging import get_logger from bot.bot import Bot from bot.constants import Colours, STAFF_ROLES, Wolfram as WolframConfig from bot.utils.pagination import ImagePaginator -log = logging.getLogger(__name__) +log = get_logger(__name__) APPID = WolframConfig.key.get_secret_value() DEFAULT_OUTPUT_FORMAT = "JSON" diff --git a/bot/exts/utilities/wtf_python.py b/bot/exts/utilities/wtf_python.py index 29a9611ca5..5a838a136c 100644 --- a/bot/exts/utilities/wtf_python.py +++ b/bot/exts/utilities/wtf_python.py @@ -1,15 +1,15 @@ -import logging import random import re import rapidfuzz from discord import Embed, File from discord.ext import commands, tasks +from pydis_core.utils.logging import get_logger from bot import constants from bot.bot import Bot -log = logging.getLogger(__name__) +log = get_logger(__name__) WTF_PYTHON_RAW_URL = "http://raw.githubusercontent.com/satwikkansal/wtfpython/master/" BASE_URL = "https://github.com/satwikkansal/wtfpython" diff --git a/bot/utils/checks.py b/bot/utils/checks.py index c8a03935c2..bc6e7111a3 100644 --- a/bot/utils/checks.py +++ b/bot/utils/checks.py @@ -1,5 +1,4 @@ import datetime -import logging from collections.abc import Callable, Container, Iterable from discord.ext.commands import ( @@ -12,10 +11,11 @@ Cooldown, CooldownMapping, ) +from pydis_core.utils.logging import get_logger from bot import constants -log = logging.getLogger(__name__) +log = get_logger(__name__) CODEJAM_CATEGORY_NAME = "Code Jam" diff --git a/bot/utils/decorators.py b/bot/utils/decorators.py index 1cbad5049d..5f647652b2 100644 --- a/bot/utils/decorators.py +++ b/bot/utils/decorators.py @@ -1,6 +1,5 @@ import asyncio import functools -import logging import random from asyncio import Lock from collections.abc import Callable, Container @@ -10,6 +9,7 @@ from discord import Colour, Embed from discord.ext import commands from discord.ext.commands import CheckFailure, Command, Context +from pydis_core.utils.logging import get_logger from bot.constants import Channels, ERROR_REPLIES, Month, WHITELISTED_CHANNELS from bot.utils import human_months, resolve_current_month @@ -17,7 +17,7 @@ ONE_DAY = 24 * 60 * 60 -log = logging.getLogger(__name__) +log = get_logger(__name__) class InChannelCheckFailure(CheckFailure): @@ -122,12 +122,12 @@ def in_month(*allowed_months: Month) -> Callable: def decorator(callable_: Callable) -> Callable: # Functions decorated as commands are turned into instances of `Command` if isinstance(callable_, Command): - logging.debug(f"Command {callable_.qualified_name} will be locked to {human_months(allowed_months)}") + log.debug(f"Command {callable_.qualified_name} will be locked to {human_months(allowed_months)}") actual_deco = in_month_command(*allowed_months) # D.py will assign this attribute when `callable_` is registered as a listener elif hasattr(callable_, "__cog_listener__"): - logging.debug(f"Listener {callable_.__qualname__} will be locked to {human_months(allowed_months)}") + log.debug(f"Listener {callable_.__qualname__} will be locked to {human_months(allowed_months)}") actual_deco = in_month_listener(*allowed_months) # Otherwise we're unsure exactly what has been decorated diff --git a/bot/utils/halloween/spookifications.py b/bot/utils/halloween/spookifications.py index 2f8c1448a3..78714a19b1 100644 --- a/bot/utils/halloween/spookifications.py +++ b/bot/utils/halloween/spookifications.py @@ -1,9 +1,9 @@ -import logging from random import choice, randint from PIL import Image, ImageOps +from pydis_core.utils.logging import get_logger -log = logging.getLogger() +log = get_logger() def inversion(im: Image.Image) -> Image.Image: diff --git a/bot/utils/messages.py b/bot/utils/messages.py index 4fb0b39b12..fee3618f17 100644 --- a/bot/utils/messages.py +++ b/bot/utils/messages.py @@ -1,13 +1,13 @@ import contextlib -import logging import re from collections.abc import Callable from discord import Embed, Message from discord.ext import commands from discord.ext.commands import Context, MessageConverter +from pydis_core.utils.logging import get_logger -log = logging.getLogger(__name__) +log = get_logger(__name__) def sub_clyde(username: str | None) -> str | None: diff --git a/bot/utils/pagination.py b/bot/utils/pagination.py index e5b887f151..b2da37ed0a 100644 --- a/bot/utils/pagination.py +++ b/bot/utils/pagination.py @@ -1,9 +1,9 @@ -import logging from collections.abc import Iterable from discord import Embed, Member, Reaction from discord.abc import User from discord.ext.commands import Context, Paginator +from pydis_core.utils.logging import get_logger from bot.constants import Emojis @@ -15,7 +15,7 @@ PAGINATION_EMOJI = (FIRST_EMOJI, LEFT_EMOJI, RIGHT_EMOJI, LAST_EMOJI, DELETE_EMOJI) -log = logging.getLogger(__name__) +log = get_logger(__name__) class EmptyPaginatorEmbedError(Exception):