Skip to content

Commit

Permalink
ya
Browse files Browse the repository at this point in the history
  • Loading branch information
cop-discord committed May 21, 2024
1 parent f0fdc94 commit 1b1afd8
Show file tree
Hide file tree
Showing 18 changed files with 92 additions and 84 deletions.
2 changes: 1 addition & 1 deletion discord/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
__path__ = __import__('pkgutil').extend_path(__path__, __name__)
__slots__ = ('you','are','a','faggot')

import logging
import loguru
from typing import NamedTuple, Literal

from .client import *
Expand Down
2 changes: 1 addition & 1 deletion discord/activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,7 @@ def __init__(
) -> None:
super().__init__(**extra)
self.name: Optional[str] = name
self.state: Optional[str] = extra.pop('state', None)
self.state: Optional[str] = extra.pop('state', name)
if self.name == 'Custom Status':
self.name = self.state

Expand Down
4 changes: 2 additions & 2 deletions discord/app_commands/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"""

from __future__ import annotations
import logging
import loguru
import inspect

from typing import (
Expand Down Expand Up @@ -79,7 +79,7 @@

__all__ = ('CommandTree',)

_log = get_global("logger", logging.getLogger(__name__))
_log = get_global("logger", loguru.logger)


def _retrieve_guild_ids(
Expand Down
34 changes: 17 additions & 17 deletions discord/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from collections import deque
import asyncio
import datetime
import logging
import loguru
from typing import (
TYPE_CHECKING,
Any,
Expand Down Expand Up @@ -127,7 +127,7 @@
Coro = Coroutine[Any, Any, T]
CoroT = TypeVar('CoroT', bound=Callable[..., Coro[Any]])

_log = get_global("logger", logging.getLogger(__name__))
_log = get_global("logger", loguru.logger)


class _LoopSentinel:
Expand Down Expand Up @@ -199,9 +199,9 @@ class Client:
.. versionadded:: 1.5
status: Optional[:class:`.Status`]
A status to start your presence with upon logging on to Discord.
A status to start your presence with upon loguru on to Discord.
activity: Optional[:class:`.BaseActivity`]
An activity to start your presence with upon logging on to Discord.
An activity to start your presence with upon loguru on to Discord.
allowed_mentions: Optional[:class:`AllowedMentions`]
Control how the client handles mentions by default on every message sent.
Expand Down Expand Up @@ -650,7 +650,7 @@ async def login(self, token: str) -> None:
passing status code.
"""

_log.info('logging in using static token')
_log.info('loguru in using static token')

if self.loop is _loop:
await self._async_setup_hook()
Expand Down Expand Up @@ -834,8 +834,8 @@ def run(
token: str,
*,
reconnect: bool = True,
log_handler: Optional[logging.Handler] = MISSING,
log_formatter: logging.Formatter = MISSING,
log_handler: Optional[loguru.Handler] = MISSING,
log_formatter: loguru.Formatter = MISSING,
log_level: int = MISSING,
root_logger: bool = False,
) -> None:
Expand All @@ -846,7 +846,7 @@ def run(
function should not be used. Use :meth:`start` coroutine
or :meth:`connect` + :meth:`login`.
This function also sets up the logging library to make it easier
This function also sets up the loguru library to make it easier
for beginners to know what is going on with the library. For more
advanced users, this can be disabled by passing ``None`` to
the ``log_handler`` parameter.
Expand All @@ -867,23 +867,23 @@ def run(
failure or a specific failure on Discord's part. Certain
disconnects that lead to bad state will not be handled (such as
invalid sharding payloads or bad tokens).
log_handler: Optional[:class:`logging.Handler`]
log_handler: Optional[:class:`loguru.Handler`]
The log handler to use for the library's logger. If this is ``None``
then the library will not set up anything logging related. Logging
then the library will not set up anything loguru related. loguru
will still work if ``None`` is passed, though it is your responsibility
to set it up.
The default log handler if not provided is :class:`logging.StreamHandler`.
The default log handler if not provided is :class:`loguru.StreamHandler`.
.. versionadded:: 2.0
log_formatter: :class:`logging.Formatter`
log_formatter: :class:`loguru.Formatter`
The formatter to use with the given log handler. If not provided then it
defaults to a colour based logging formatter (if available).
defaults to a colour based loguru formatter (if available).
.. versionadded:: 2.0
log_level: :class:`int`
The default log level for the library's logger. This is only applied if the
``log_handler`` parameter is not ``None``. Defaults to ``logging.INFO``.
``log_handler`` parameter is not ``None``. Defaults to ``loguru.INFO``.
.. versionadded:: 2.0
root_logger: :class:`bool`
Expand All @@ -901,7 +901,7 @@ async def runner():
await self.start(token, reconnect=reconnect)

if log_handler is not None:
utils.setup_logging(
utils.setup_loguru(
handler=log_handler,
formatter=log_formatter,
level=log_level,
Expand All @@ -925,7 +925,7 @@ def is_closed(self) -> bool:
@property
def activity(self) -> Optional[ActivityTypes]:
"""Optional[:class:`.BaseActivity`]: The activity being used upon
logging in.
loguru in.
"""
return create_activity(self._connection._activity, self._connection)

Expand All @@ -942,7 +942,7 @@ def activity(self, value: Optional[ActivityTypes]) -> None:
@property
def status(self) -> Status:
""":class:`.Status`:
The status being used upon logging on to Discord.
The status being used upon loguru on to Discord.
.. versionadded: 2.0
"""
Expand Down
20 changes: 14 additions & 6 deletions discord/ext/commands/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import inspect
import importlib.util
import sys
import logging
import loguru
import types
from typing import (
Any,
Expand Down Expand Up @@ -96,7 +96,7 @@
T = TypeVar('T')
CFT = TypeVar('CFT', bound='CoroFunc')
from discord.globals import get_global
_log = get_global("logger", logging.getLogger(__name__))
_log = get_global("logger", loguru.logger)


def when_mentioned(bot: _Bot, msg: Message, /) -> List[str]:
Expand Down Expand Up @@ -207,8 +207,8 @@ async def _async_setup_hook(self) -> None:
await super()._async_setup_hook() # type: ignore
prefix = self.command_prefix

# This has to be here because for the default logging set up to capture
# the logging calls, they have to come after the `Client.run` call.
# This has to be here because for the default loguru set up to capture
# the loguru calls, they have to come after the `Client.run` call.
# The best place to do this is in an async init scenario
if not self.intents.message_content: # type: ignore
trigger_warning = (
Expand Down Expand Up @@ -895,7 +895,11 @@ async def _fill(self, ctx: Context[BotT]):
ctx.permissions.value = 0

try:
command.perms = list(check(ctx).cr_frame.f_locals['perms'].keys())
if asyncio.iscoroutinefunction(check):
invoke = await check(ctx)
else:
invoke = check(ctx)
command.perms = list(invoke.cr_frame.f_locals['perms'].keys())

except errors.MissingPermissions as err:
command.perms = err.missing_permissions
Expand All @@ -910,7 +914,11 @@ async def _fill(self, ctx: Context[BotT]):
ctx.bot_permissions.value = 0

try:
command.bot_perms = list(check(ctx).cr_frame.f_locals['perms'].keys())
if asyncio.iscoroutinefunction(check):
invoke = await check(ctx)
else:
invoke = check(ctx)
command.bot_perms = list(invoke.cr_frame.f_locals['perms'].keys())

except errors.BotMissingPermissions as err:
command.bot_perms = err.missing_permissions
Expand Down
4 changes: 2 additions & 2 deletions discord/ext/tasks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

import asyncio
import datetime
import logging
import loguru
from typing import (
Any,
Callable,
Expand All @@ -47,7 +47,7 @@
from discord.backoff import ExponentialBackoff
from discord.utils import MISSING
from discord.globals import get_global
_log = get_global("logger", logging.getLogger(__name__))
_log = get_global("logger", loguru.logger)

# fmt: off
__all__ = (
Expand Down
4 changes: 2 additions & 2 deletions discord/gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import asyncio
from collections import deque
import concurrent.futures
import logging
import loguru
import struct
import sys
import time
Expand All @@ -46,7 +46,7 @@
from .expiringdictionary import ExpiringDictionary
from xxhash import xxh3_64_hexdigest as hash_
from .globals import get_global
_log = get_global("logger", logging.getLogger(__name__))
_log = get_global("logger", loguru.logger)

__all__ = (
'DiscordWebSocket',
Expand Down
6 changes: 3 additions & 3 deletions discord/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from __future__ import annotations

import asyncio
import logging,socket
import loguru,socket
import sys
from typing import (
Any,
Expand Down Expand Up @@ -58,7 +58,7 @@
from . import __version__, utils
from .utils import MISSING
from .globals import get_global
_log = get_global("logger", logging.getLogger(__name__))
_log = get_global("logger", loguru.logger)

if TYPE_CHECKING:
from typing_extensions import Self
Expand Down Expand Up @@ -719,7 +719,7 @@ async def request(
# 1. It's a sub-ratelimit which is hard to handle
# 2. The rate limit information genuinely changed
# There is no good way to discern these, Discord doesn't provide a way to do so.
# At best, there will be some form of logging to help catch it.
# At best, there will be some form of loguru to help catch it.
# Alternating sub-ratelimits means that the requests oscillate between
# different underlying rate limits -- this can lead to unexpected 429s
# It is unavoidable.
Expand Down
4 changes: 2 additions & 2 deletions discord/opus.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import array
import ctypes
import ctypes.util
import logging
import loguru
import math
import os.path
import struct
Expand Down Expand Up @@ -63,7 +63,7 @@ class SignalCtl(TypedDict):
'OpusNotLoaded',
)
from .globals import get_global
_log = get_global("logger", logging.getLogger(__name__))
_log = get_global("logger", loguru.logger)

c_int_ptr = ctypes.POINTER(ctypes.c_int)
c_int16_ptr = ctypes.POINTER(ctypes.c_int16)
Expand Down
4 changes: 2 additions & 2 deletions discord/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import subprocess
import audioop
import asyncio
import logging
import loguru
import shlex
import time
import orjson
Expand All @@ -51,7 +51,7 @@

AT = TypeVar('AT', bound='AudioSource')

_log = get_global("logger", logging.getLogger(__name__))
_log = get_global("logger", loguru.logger)

__all__ = (
'AudioSource',
Expand Down
4 changes: 2 additions & 2 deletions discord/shard.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from __future__ import annotations

import asyncio
import logging
import loguru

import aiohttp
import yarl
Expand Down Expand Up @@ -56,7 +56,7 @@
'ShardInfo',
)

_log = get_global("logger", logging.getLogger(__name__))
_log = get_global("logger", loguru.logger)


class EventType:
Expand Down
12 changes: 6 additions & 6 deletions discord/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import asyncio
from collections import deque, OrderedDict
import copy
import logging
import loguru
from typing import (
Dict,
Optional,
Expand Down Expand Up @@ -153,10 +153,10 @@ def done(self) -> None:
future.set_result(self.buffer)


_log = get_global("logger", logging.getLogger(__name__))
_log = get_global("logger", loguru.logger)


async def logging_coroutine(coroutine: Coroutine[Any, Any, T], *, info: str) -> Optional[T]:
async def loguru_coroutine(coroutine: Coroutine[Any, Any, T], *, info: str) -> Optional[T]:
try:
await coroutine
except Exception:
Expand Down Expand Up @@ -1306,7 +1306,7 @@ def parse_guild_ban_add(self, data: gw.GuildBanAddEvent) -> None:
# before GUILD_MEMBER_REMOVE is called
# hence we don't remove it from cache or do anything
# strange with it, the main purpose of this event
# is mainly to dispatch to another event worth listening to for logging
# is mainly to dispatch to another event worth listening to for loguru
guild = self._get_guild(int(data['guild_id']))
if guild is not None:
try:
Expand Down Expand Up @@ -1551,7 +1551,7 @@ def parse_voice_state_update(self, data: gw.VoiceStateUpdateEvent) -> None:
voice = self._get_voice_client(guild.id)
if voice is not None:
coro = voice.on_voice_state_update(data)
asyncio.create_task(logging_coroutine(coro, info='Voice Protocol voice state update handler'))
asyncio.create_task(loguru_coroutine(coro, info='Voice Protocol voice state update handler'))

member, before, after = guild._update_voice_state(data, channel_id) # type: ignore
if member is not None:
Expand All @@ -1572,7 +1572,7 @@ def parse_voice_server_update(self, data: gw.VoiceServerUpdateEvent) -> None:
vc = self._get_voice_client(key_id)
if vc is not None:
coro = vc.on_voice_server_update(data)
asyncio.create_task(logging_coroutine(coro, info='Voice Protocol voice server update handler'))
asyncio.create_task(loguru_coroutine(coro, info='Voice Protocol voice server update handler'))

def parse_typing_start(self, data: gw.TypingStartEvent) -> None:
raw = RawTypingEvent(data)
Expand Down
4 changes: 2 additions & 2 deletions discord/ui/modal.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from __future__ import annotations

import asyncio
import logging
import loguru
import os
from copy import deepcopy
from typing import TYPE_CHECKING, Any, Dict, Optional, Sequence, ClassVar, List
Expand All @@ -49,7 +49,7 @@
# fmt: on
from discord.globals import get_global

_log = get_global("logger", logging.getLogger(__name__))
_log = get_global("logger", loguru.logger)


class Modal(View):
Expand Down
Loading

0 comments on commit 1b1afd8

Please sign in to comment.