diff options
Diffstat (limited to 'bot')
79 files changed, 173 insertions, 171 deletions
@@ -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 20953771..b0c8accd 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 @@ __all__ = (      "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 cb9c5ae8..ae2036b7 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 4eae269f..5f0b2400 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 @@ from typing import TypeVar  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 81b923fd..cf116ba0 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.commands import get_command_suggestions  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 @@ class CommandErrorHandler(commands.Cog):          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 @@ class CommandErrorHandler(commands.Cog):      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 @@ class CommandErrorHandler(commands.Cog):              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 f96b0292..cfba58c8 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 import Colour, Embed  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.constants import Client, Emojis, MODERATION_ROLES, Roles  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 9f96a333..7721d200 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 30c4b11c..766f1160 100644 --- a/bot/exts/core/internal_eval/_helpers.py +++ b/bot/exts/core/internal_eval/_helpers.py @@ -4,13 +4,14 @@ import contextlib  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 1ae3c043..39ce558a 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 @@ from ._helpers import EvalContext  __all__ = ["InternalEval"] -log = logging.getLogger(__name__) +log = get_logger(__name__)  FORMATTED_CODE_REGEX = re.compile(      r"(?P<delim>(?P<block>```)|``?)"        # 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 69aa3924..dbf8f747 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 04dc4aae..e934525b 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 @@ from urllib.parse import quote_plus  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 @@ class HacktoberStats(commands.Cog):              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 @@ class HacktoberStats(commands.Cog):          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 @@ class HacktoberStats(commands.Cog):      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 @@ class HacktoberStats(commands.Cog):              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 @@ class HacktoberStats(commands.Cog):              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 8f46d798..9fa1ef70 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 8210d1d5..4e23c079 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 ded784be..a209ff02 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 @@ from functools import partial  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 16279dd7..66c48517 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 import Embed  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 c9824f22..9c253ca1 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 import Embed  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 @@ BASE_HEADERS = {      "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 b7bd708e..cd7dba11 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 @@ import discord  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<delim>(?P<block>```)|``?)"        # code delimiter: 1-3 backticks; (?P=block) only matches if it's a block      r"(?(block)(?:(?P<lang>[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 95d711c4..7bb3d886 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 69be88d3..29cd8ee9 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 @@ MESSAGE_MAPPING = {      "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 3d36b119..555c4503 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 typing import Any  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 492e0c0f..459cb4a2 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 e972b9a5..7806ab2f 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 be71ac44..0af8ece2 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 c24ba8c6..43a99a9d 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 dfe2903a..3f0a0764 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 aiohttp import ClientTimeout  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 import _utils as utils  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 c48ecf8d..8d24a6aa 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 import Image  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 3a666bfc..f2c934bc 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 urllib.parse import urlencode  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 43e570a2..3685b870 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 4f352b71..d7b49f7a 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 @@ from pathlib import Path  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 7b34795c..df00d89d 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 @@ class XKCD(Cog):          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 7f46a569..c89ee5a0 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 3034da4a..01131199 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 66f1b07b..6a88d4c8 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 6c29dd17..f9ddc429 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 1327f4d0..097f958d 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 @@ from pathlib import Path  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 43b31c7b..0e746c29 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 046f9fac..a876ae8b 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 3ac5617c..5d87abfd 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 ca68888b..ce3f5f6b 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 21b55a01..10b2bda4 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 a0d63f64..daad26d3 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 a16ea6cc..89367441 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 @@ import discord  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 8e83e9d1..18ec649d 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 fdc15e13..5cfdae31 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 fbab3dd2..923a2a24 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 b3f9d703..45e6936e 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 78e8be8e..73674c31 100644 --- a/bot/exts/holidays/halloween/spookynamerate.py +++ b/bot/exts/holidays/halloween/spookynamerate.py @@ -3,7 +3,6 @@ import json  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 import Embed, Reaction, TextChannel, User  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 373b6583..14530e6b 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 fd8edca1..973919a4 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 306cde53..ef44115a 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 0c1ca6fb..6a89db0a 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 1f214fc0..a2f2a576 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 7dca953b..4eec20ac 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 9f01ebf9..4ebd8e34 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 714d3884..81679794 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 9b363c5e..83418f14 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 @@ import discord  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 64b86f1b..d11c128d 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 0f1c7dc9..365baa56 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 8562a07d..281f23dc 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 7fd644df..073a6331 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 f0c8978d..26d6d195 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 c652e616..6a25901a 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 22801d14..51d01469 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 6d1813bb..f25a0ba7 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 bbaf6d25..115e5148 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 datetime import UTC, datetime  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 41b9415a..f567f836 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 @@ from urllib.parse import quote  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 c63fca85..ade0021e 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 5dd4a377..085be42a 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 import Colour, Embed, TextChannel  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.converters import Subreddit  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 f1bbfb89..8143f5ee 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 1eeff45b..2ef284a2 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 a936f733..6552aa56 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 d12cb19d..6250f3e6 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 e77573a7..b512071a 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 @@ import discord  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 29a9611c..5a838a13 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 c8a03935..bc6e7111 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 @@ from discord.ext.commands import (      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 1cbad504..5f647652 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 weakref import WeakValueDictionary  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 @@ from bot.utils.checks import in_whitelist_check  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 2f8c1448..78714a19 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 4fb0b39b..fee3618f 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 e5b887f1..b2da37ed 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 @@ DELETE_EMOJI = Emojis.trashcan  # [:trashcan:]  PAGINATION_EMOJI = (FIRST_EMOJI, LEFT_EMOJI, RIGHT_EMOJI, LAST_EMOJI, DELETE_EMOJI) -log = logging.getLogger(__name__) +log = get_logger(__name__)  class EmptyPaginatorEmbedError(Exception):  |