new attempr

This commit is contained in:
iDutchy 2021-07-13 19:53:19 -05:00
parent d7a0b0af04
commit 3056c6f0f4
4 changed files with 58 additions and 58 deletions

View File

@ -24,36 +24,35 @@ DEALINGS IN THE SOFTWARE.
import asyncio import asyncio
import logging import logging
import os
import re
import signal import signal
import sys import sys
import traceback import traceback
import os
import re
import aiohttp import aiohttp
from .user import User
from .invite import Invite
from .template import Template
from .widget import Widget
from .guild import Guild
from .channel import _channel_factory
from .enums import ChannelType
from .mentions import AllowedMentions
from .errors import *
from .enums import Status, VoiceRegion
from .gateway import *
from .activity import BaseActivity, create_activity
from .voice_client import VoiceClient
from .http import HTTPClient
from .state import ConnectionState
from . import utils from . import utils
from .object import Object from .activity import BaseActivity, create_activity
from .backoff import ExponentialBackoff
from .webhook import Webhook
from .iterators import GuildIterator
from .appinfo import AppInfo from .appinfo import AppInfo
from .backoff import ExponentialBackoff
from .channel import _channel_factory
from .colour import Color, Colour from .colour import Color, Colour
from .enums import ChannelType, Status, VoiceRegion
from .errors import *
from .gateway import *
from .guild import Guild
from .http import HTTPClient
from .invite import Invite
from .iterators import GuildIterator
from .mentions import AllowedMentions
from .object import Object
from .state import ConnectionState
from .template import Template
from .user import User
from .voice_client import VoiceClient
from .webhook import Webhook
from .widget import Widget
__all__ = ( __all__ = (
'Client', 'Client',
@ -250,6 +249,7 @@ class Client:
self._connection = self._get_state(**options) self._connection = self._get_state(**options)
self._connection.shard_count = self.shard_count self._connection.shard_count = self.shard_count
self._connection.shortcuts = {}
self._closed = False self._closed = False
self._ready = asyncio.Event() self._ready = asyncio.Event()
self._connection._get_websocket = self._get_websocket self._connection._get_websocket = self._get_websocket
@ -259,6 +259,24 @@ class Client:
VoiceClient.warn_nacl = False VoiceClient.warn_nacl = False
log.warning("PyNaCl is not installed, voice will NOT be supported") log.warning("PyNaCl is not installed, voice will NOT be supported")
def add_guild_shortcut(self, name, config_dict):
"""Add a shortcut attribute to context.guild
.. versionadded:: 1.7.3.8
Parameters
-----------
name: :class:`str`
The name of the shortcut you want to add to context.guild
config_dict: :class:`dict`
The dict of {guild.id: other_data} where context.guild.<shortcut> will get the data from
"""
if not isinstance(name, str):
raise ValueError("Name must be a string")
if not isinstance(config_dict, dict):
raise ValueError("config_dict must be a dict")
self._connection.shortcuts[name] = config_dict
# internals # internals
def get_message(self, id): def get_message(self, id):

View File

@ -107,7 +107,6 @@ class BotBase(GroupMixin):
self.extra_events = {} self.extra_events = {}
self.__cogs = {} self.__cogs = {}
self.__extensions = {} self.__extensions = {}
self._shortcuts = {}
self._checks = [] self._checks = []
self._check_once = [] self._check_once = []
self._before_invoke = None self._before_invoke = None
@ -134,22 +133,6 @@ class BotBase(GroupMixin):
else: else:
self.help_command = help_command self.help_command = help_command
def add_guild_shortcut(self, name, config_dict):
"""Add a shortcut attribute to context.guild
Parameters
-----------
name: :class:`str`
The name of the shortcut you want to add to context.guild
config_dict: :class:`dict`
The dict of {guild.id: other_data} where context.guild.<shortcut> will get the data from
"""
if not isinstance(name, str):
raise ValueError("Name must be a string")
if not isinstance(config_dict, dict):
raise ValueError("config_dict must be a dict")
self._shortcuts[name] = config_dict
@property @property
def owner(self): def owner(self):
""":class:`discord.User`: The owner, retrieved from owner_id. In case of improper caching, this can return None """:class:`discord.User`: The owner, retrieved from owner_id. In case of improper caching, this can return None

View File

@ -227,11 +227,7 @@ class Context(discord.abc.Messageable):
@discord.utils.cached_property @discord.utils.cached_property
def guild(self): def guild(self):
"""Optional[:class:`.Guild`]: Returns the guild associated with this context's command. None if not available.""" """Optional[:class:`.Guild`]: Returns the guild associated with this context's command. None if not available."""
guild = self.message.guild return self.message.guild
if self.bot._shortcuts:
for name, config in self.bot._shortcuts.items():
setattr(guild, name, config.get(guild.id))
return guild
@discord.utils.cached_property @discord.utils.cached_property
def channel(self): def channel(self):

View File

@ -26,23 +26,23 @@ import copy
from collections import namedtuple from collections import namedtuple
from . import utils from . import utils
from .role import Role
from .member import Member, VoiceState
from .emoji import Emoji
from .errors import InvalidData
from .permissions import PermissionOverwrite
from .colour import Colour
from .errors import InvalidArgument, ClientException
from .channel import *
from .enums import VoiceRegion, ChannelType, try_enum, VerificationLevel, ContentFilter, NotificationLevel
from .mixins import Hashable
from .user import User
from .invite import Invite
from .iterators import AuditLogIterator, MemberIterator
from .widget import Widget
from .asset import Asset from .asset import Asset
from .channel import *
from .colour import Colour
from .emoji import Emoji
from .enums import (ChannelType, ContentFilter, NotificationLevel,
VerificationLevel, VoiceRegion, try_enum)
from .errors import ClientException, InvalidArgument, InvalidData
from .flags import SystemChannelFlags from .flags import SystemChannelFlags
from .integrations import Integration from .integrations import Integration
from .invite import Invite
from .iterators import AuditLogIterator, MemberIterator
from .member import Member, VoiceState
from .mixins import Hashable
from .permissions import PermissionOverwrite
from .role import Role
from .user import User
from .widget import Widget
__all__ = ( __all__ = (
'Guild', 'Guild',
@ -189,6 +189,9 @@ class Guild(Hashable):
self._voice_states = {} self._voice_states = {}
self._state = state self._state = state
self._from_data(data) self._from_data(data)
if state.shortcuts:
for name, config in state.shortcuts.items():
setattr(self, name, config.get(self.id))
def _add_channel(self, channel): def _add_channel(self, channel):
self._channels[channel.id] = channel self._channels[channel.id] = channel