Skip to content

Commit

Permalink
Always use the get_logger func from bot-core
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisLovering committed Nov 25, 2023
1 parent 27a12e1 commit bbe107b
Show file tree
Hide file tree
Showing 79 changed files with 173 additions and 171 deletions.
5 changes: 2 additions & 3 deletions bot/bot.py
Original file line number Diff line number Diff line change
@@ -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", )

Expand Down
4 changes: 2 additions & 2 deletions bot/constants.py
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -28,7 +28,7 @@
"POSITIVE_REPLIES",
)

log = logging.getLogger(__name__)
log = get_logger(__name__)


PYTHON_PREFIX = "!"
Expand Down
5 changes: 3 additions & 2 deletions bot/exts/__init__.py
Original file line number Diff line number Diff line change
@@ -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]:
Expand Down
4 changes: 2 additions & 2 deletions bot/exts/avatar_modification/avatar_modify.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import asyncio
import json
import logging
import math
import string
import unicodedata
Expand All @@ -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)

Expand Down
10 changes: 5 additions & 5 deletions bot/exts/core/error_handler.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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:
Expand All @@ -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 = ""
Expand All @@ -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}, "
Expand Down
4 changes: 2 additions & 2 deletions bot/exts/core/extensions.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import functools
import logging
from collections.abc import Mapping
from enum import Enum

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
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"}
Expand Down
4 changes: 2 additions & 2 deletions bot/exts/core/help.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -35,7 +35,7 @@ class Cog(NamedTuple):
commands: list[Command]


log = logging.getLogger(__name__)
log = get_logger(__name__)


class HelpQueryNotFoundError(ValueError):
Expand Down
5 changes: 3 additions & 2 deletions bot/exts/core/internal_eval/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
4 changes: 2 additions & 2 deletions bot/exts/core/internal_eval/_internal_eval.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -13,7 +13,7 @@

__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
Expand Down
4 changes: 2 additions & 2 deletions bot/exts/events/hacktoberfest/hacktober_issue_finder.py
Original file line number Diff line number Diff line change
@@ -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"

Expand Down
16 changes: 8 additions & 8 deletions bot/exts/events/hacktoberfest/hacktoberstats.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import logging
import random
import re
from collections import Counter
Expand All @@ -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
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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:
"""
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions bot/exts/events/hacktoberfest/timeleft.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
4 changes: 2 additions & 2 deletions bot/exts/fun/anagram.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down
4 changes: 2 additions & 2 deletions bot/exts/fun/battleship.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import logging
import random
import re
from dataclasses import dataclass
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
Expand Down
4 changes: 2 additions & 2 deletions bot/exts/fun/fun.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import json
import logging
import random
from collections.abc import Iterable
from pathlib import Path
Expand All @@ -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]:
Expand Down
4 changes: 2 additions & 2 deletions bot/exts/fun/game.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import difflib
import logging
import random
import re
from datetime import UTC, datetime, timedelta
Expand All @@ -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
Expand Down Expand Up @@ -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)

Expand Down
Loading

0 comments on commit bbe107b

Please sign in to comment.