Skip to content

Commit

Permalink
Merge branch 'main' into discord-2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Akarys42 committed Oct 15, 2021
2 parents 574f610 + 510f733 commit a7587cf
Show file tree
Hide file tree
Showing 93 changed files with 278 additions and 240 deletions.
6 changes: 2 additions & 4 deletions bot/__main__.py
@@ -1,11 +1,9 @@
import logging

import aiohttp

import bot
from bot import constants
from bot.bot import Bot, StartupError
from bot.log import setup_sentry
from bot.log import get_logger, setup_sentry

setup_sentry()

Expand All @@ -21,7 +19,7 @@
message = "Could not connect to Redis. Is it running?"

# The exception is logged with an empty message so the actual message is visible at the bottom
log = logging.getLogger("bot")
log = get_logger("bot")
log.fatal("", exc_info=e.exception)
log.fatal(message)

Expand Down
4 changes: 2 additions & 2 deletions bot/api.py
@@ -1,13 +1,13 @@
import asyncio
import logging
from typing import Optional
from urllib.parse import quote as quote_url

import aiohttp

from bot.log import get_logger
from .constants import Keys, URLs

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


class ResponseCodeError(ValueError):
Expand Down
4 changes: 2 additions & 2 deletions bot/bot.py
@@ -1,5 +1,4 @@
import asyncio
import logging
import socket
import warnings
from collections import defaultdict
Expand All @@ -14,8 +13,9 @@

from bot import api, constants
from bot.async_stats import AsyncStatsClient
from bot.log import get_logger

log = logging.getLogger('bot')
log = get_logger('bot')
LOCALHOST = "127.0.0.1"


Expand Down
12 changes: 3 additions & 9 deletions bot/constants.py
Expand Up @@ -9,8 +9,6 @@
out in the custom user configuration will stay
their default values from `config-default.yml`.
"""

import logging
import os
from collections.abc import Mapping
from enum import Enum
Expand All @@ -25,8 +23,6 @@
except ModuleNotFoundError:
pass

log = logging.getLogger(__name__)


def _env_var_constructor(loader, node):
"""
Expand Down Expand Up @@ -104,7 +100,7 @@ def _recursive_update(original, new):


if Path("config.yml").exists():
log.info("Found `config.yml` file, loading constants from it.")
print("Found `config.yml` file, loading constants from it.")
with open("config.yml", encoding="UTF-8") as f:
user_config = yaml.safe_load(f)
_recursive_update(_CONFIG_YAML, user_config)
Expand All @@ -123,11 +119,10 @@ def check_required_keys(keys):
if lookup is None:
raise KeyError(key)
except KeyError:
log.critical(
raise KeyError(
f"A configuration for `{key_path}` is required, but was not found. "
"Please set it in `config.yml` or setup an environment variable and try again."
)
raise


try:
Expand Down Expand Up @@ -186,8 +181,7 @@ def __getattr__(cls, name):
(cls.section, cls.subsection, name)
if cls.subsection is not None else (cls.section, name)
)
# Only an INFO log since this can be caught through `hasattr` or `getattr`.
log.info(f"Tried accessing configuration variable at `{dotted_path}`, but it could not be found.")
print(f"Tried accessing configuration variable at `{dotted_path}`, but it could not be found.")
raise AttributeError(repr(name)) from e

def __getitem__(cls, name):
Expand Down
5 changes: 3 additions & 2 deletions bot/converters.py
@@ -1,6 +1,5 @@
from __future__ import annotations

import logging
import re
import typing as t
from datetime import datetime
Expand All @@ -19,13 +18,15 @@
from bot.constants import URLs
from bot.errors import InvalidInfraction
from bot.exts.info.doc import _inventory_parser
from bot.log import get_logger
from bot.utils.extensions import EXTENSIONS, unqualify
from bot.utils.regex import INVITE_RE
from bot.utils.time import parse_duration_string

if t.TYPE_CHECKING:
from bot.exts.info.source import SourceType

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

DISCORD_EPOCH_DT = datetime.utcfromtimestamp(DISCORD_EPOCH / 1000)
RE_USER_MENTION = re.compile(r"<@!?([0-9]+)>$")
Expand Down
4 changes: 2 additions & 2 deletions bot/decorators.py
@@ -1,6 +1,5 @@
import asyncio
import functools
import logging
import types
import typing as t
from contextlib import suppress
Expand All @@ -10,11 +9,12 @@
from discord.ext.commands import Cog, Context

from bot.constants import Channels, DEBUG_MODE, RedirectOutput
from bot.log import get_logger
from bot.utils import function, scheduling
from bot.utils.checks import ContextCheckFailure, in_whitelist_check
from bot.utils.function import command_wraps

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


def in_whitelist(
Expand Down
4 changes: 2 additions & 2 deletions bot/exts/backend/branding/_cog.py
@@ -1,6 +1,5 @@
import asyncio
import contextlib
import logging
import random
import typing as t
from datetime import timedelta
Expand All @@ -17,9 +16,10 @@
from bot.constants import Branding as BrandingConfig, Channels, Colours, Guild, MODERATION_ROLES
from bot.decorators import mock_in_debug
from bot.exts.backend.branding._repository import BrandingRepository, Event, RemoteObject
from bot.log import get_logger
from bot.utils import scheduling

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


class AssetType(Enum):
Expand Down
4 changes: 2 additions & 2 deletions bot/exts/backend/branding/_repository.py
@@ -1,4 +1,3 @@
import logging
import typing as t
from datetime import date, datetime

Expand All @@ -7,6 +6,7 @@
from bot.bot import Bot
from bot.constants import Keys
from bot.errors import BrandingMisconfiguration
from bot.log import get_logger

# Base URL for requests into the branding repository.
BRANDING_URL = "https://api.github.com/repos/python-discord/branding/contents"
Expand All @@ -25,7 +25,7 @@
# Format used to parse date strings after we inject `ARBITRARY_YEAR` at the end.
DATE_FMT = "%B %d %Y" # Ex: July 10 2020

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


class RemoteObject:
Expand Down
5 changes: 2 additions & 3 deletions bot/exts/backend/config_verifier.py
@@ -1,12 +1,11 @@
import logging

from discord.ext.commands import Cog

from bot import constants
from bot.bot import Bot
from bot.log import get_logger
from bot.utils import scheduling

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


class ConfigVerifier(Cog):
Expand Down
4 changes: 2 additions & 2 deletions bot/exts/backend/error_handler.py
@@ -1,5 +1,4 @@
import difflib
import logging
import typing as t

from discord import Embed
Expand All @@ -11,9 +10,10 @@
from bot.constants import Colours, Icons, MODERATION_ROLES
from bot.converters import TagNameConverter
from bot.errors import InvalidInfractedUserError, LockedResourceError
from bot.log import get_logger
from bot.utils.checks import ContextCheckFailure

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


class ErrorHandler(Cog):
Expand Down
5 changes: 2 additions & 3 deletions bot/exts/backend/logging.py
@@ -1,13 +1,12 @@
import logging

from discord import Embed
from discord.ext.commands import Cog

from bot.bot import Bot
from bot.constants import Channels, DEBUG_MODE
from bot.log import get_logger
from bot.utils import scheduling

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


class Logging(Cog):
Expand Down
4 changes: 2 additions & 2 deletions bot/exts/backend/sync/_cog.py
@@ -1,4 +1,3 @@
import logging
from typing import Any, Dict

from discord import Member, Role, User
Expand All @@ -9,9 +8,10 @@
from bot.api import ResponseCodeError
from bot.bot import Bot
from bot.exts.backend.sync import _syncers
from bot.log import get_logger
from bot.utils import scheduling

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


class Sync(Cog):
Expand Down
4 changes: 2 additions & 2 deletions bot/exts/backend/sync/_syncers.py
@@ -1,5 +1,4 @@
import abc
import logging
import typing as t
from collections import namedtuple

Expand All @@ -9,9 +8,10 @@

import bot
from bot.api import ResponseCodeError
from bot.log import get_logger
from bot.utils.members import get_or_fetch_member

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

CHUNK_SIZE = 1000

Expand Down
4 changes: 2 additions & 2 deletions bot/exts/events/code_jams/_channels.py
@@ -1,11 +1,11 @@
import logging
import typing as t

import discord

from bot.constants import Categories, Channels, Roles
from bot.log import get_logger

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

MAX_CHANNELS = 50
CATEGORY_NAME = "Code Jam"
Expand Down
4 changes: 2 additions & 2 deletions bot/exts/events/code_jams/_cog.py
@@ -1,6 +1,5 @@
import asyncio
import csv
import logging
import typing as t
from collections import defaultdict

Expand All @@ -11,10 +10,11 @@
from bot.bot import Bot
from bot.constants import Emojis, Roles
from bot.exts.events.code_jams import _channels
from bot.log import get_logger
from bot.utils.members import get_or_fetch_member
from bot.utils.services import send_to_paste_service

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

TEAM_LEADERS_COLOUR = 0x11806a
DELETION_REACTION = "\U0001f4a5"
Expand Down
4 changes: 2 additions & 2 deletions bot/exts/filters/antimalware.py
@@ -1,4 +1,3 @@
import logging
import typing as t
from os.path import splitext

Expand All @@ -8,8 +7,9 @@
from bot.bot import Bot
from bot.constants import Channels, Filter, URLs
from bot.exts.events.code_jams._channels import CATEGORY_NAME as JAM_CATEGORY_NAME
from bot.log import get_logger

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

PY_EMBED_DESCRIPTION = (
"It looks like you tried to attach a Python file - "
Expand Down
5 changes: 2 additions & 3 deletions bot/exts/filters/antispam.py
@@ -1,5 +1,4 @@
import asyncio
import logging
from collections import defaultdict
from collections.abc import Mapping
from dataclasses import dataclass, field
Expand All @@ -21,12 +20,12 @@
from bot.converters import Duration
from bot.exts.events.code_jams._channels import CATEGORY_NAME as JAM_CATEGORY_NAME
from bot.exts.moderation.modlog import ModLog
from bot.log import get_logger
from bot.utils import lock, scheduling
from bot.utils.message_cache import MessageCache
from bot.utils.messages import format_user, send_attachments


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

RULE_FUNCTION_MAPPING = {
'attachments': rules.apply_attachments,
Expand Down
4 changes: 2 additions & 2 deletions bot/exts/filters/filter_lists.py
@@ -1,4 +1,3 @@
import logging
from typing import Optional

from discord import Colour, Embed
Expand All @@ -8,10 +7,11 @@
from bot.api import ResponseCodeError
from bot.bot import Bot
from bot.converters import ValidDiscordServerInvite, ValidFilterListType
from bot.log import get_logger
from bot.pagination import LinePaginator
from bot.utils import scheduling

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


class FilterLists(Cog):
Expand Down
4 changes: 2 additions & 2 deletions bot/exts/filters/filtering.py
@@ -1,5 +1,4 @@
import asyncio
import logging
import re
from datetime import datetime, timedelta
from typing import Any, Dict, List, Mapping, NamedTuple, Optional, Tuple, Union
Expand All @@ -21,11 +20,12 @@
)
from bot.exts.events.code_jams._channels import CATEGORY_NAME as JAM_CATEGORY_NAME
from bot.exts.moderation.modlog import ModLog
from bot.log import get_logger
from bot.utils import scheduling
from bot.utils.messages import format_user
from bot.utils.regex import INVITE_RE

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

# Regular expressions
CODE_BLOCK_RE = re.compile(
Expand Down
5 changes: 2 additions & 3 deletions bot/exts/filters/security.py
@@ -1,10 +1,9 @@
import logging

from discord.ext.commands import Cog, Context, NoPrivateMessage

from bot.bot import Bot
from bot.log import get_logger

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


class Security(Cog):
Expand Down

0 comments on commit a7587cf

Please sign in to comment.