new attempr
This commit is contained in:
parent
d7a0b0af04
commit
3056c6f0f4
@ -24,36 +24,35 @@ DEALINGS IN THE SOFTWARE.
|
||||
|
||||
import asyncio
|
||||
import logging
|
||||
import os
|
||||
import re
|
||||
import signal
|
||||
import sys
|
||||
import traceback
|
||||
import os
|
||||
import re
|
||||
|
||||
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 .object import Object
|
||||
from .backoff import ExponentialBackoff
|
||||
from .webhook import Webhook
|
||||
from .iterators import GuildIterator
|
||||
from .activity import BaseActivity, create_activity
|
||||
from .appinfo import AppInfo
|
||||
from .backoff import ExponentialBackoff
|
||||
from .channel import _channel_factory
|
||||
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__ = (
|
||||
'Client',
|
||||
@ -250,6 +249,7 @@ class Client:
|
||||
|
||||
self._connection = self._get_state(**options)
|
||||
self._connection.shard_count = self.shard_count
|
||||
self._connection.shortcuts = {}
|
||||
self._closed = False
|
||||
self._ready = asyncio.Event()
|
||||
self._connection._get_websocket = self._get_websocket
|
||||
@ -259,6 +259,24 @@ class Client:
|
||||
VoiceClient.warn_nacl = False
|
||||
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
|
||||
|
||||
def get_message(self, id):
|
||||
@ -1363,7 +1381,7 @@ class Client:
|
||||
"""|coro|
|
||||
|
||||
Retrieves a :class:`~discord.User` based on their ID. This can only
|
||||
be used by bot accounts.
|
||||
be used by bot accounts.
|
||||
|
||||
.. versionadded:: 1.5.0.1
|
||||
|
||||
|
@ -107,7 +107,6 @@ class BotBase(GroupMixin):
|
||||
self.extra_events = {}
|
||||
self.__cogs = {}
|
||||
self.__extensions = {}
|
||||
self._shortcuts = {}
|
||||
self._checks = []
|
||||
self._check_once = []
|
||||
self._before_invoke = None
|
||||
@ -134,22 +133,6 @@ class BotBase(GroupMixin):
|
||||
else:
|
||||
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
|
||||
def owner(self):
|
||||
""":class:`discord.User`: The owner, retrieved from owner_id. In case of improper caching, this can return None
|
||||
|
@ -227,11 +227,7 @@ class Context(discord.abc.Messageable):
|
||||
@discord.utils.cached_property
|
||||
def guild(self):
|
||||
"""Optional[:class:`.Guild`]: Returns the guild associated with this context's command. None if not available."""
|
||||
guild = self.message.guild
|
||||
if self.bot._shortcuts:
|
||||
for name, config in self.bot._shortcuts.items():
|
||||
setattr(guild, name, config.get(guild.id))
|
||||
return guild
|
||||
return self.message.guild
|
||||
|
||||
@discord.utils.cached_property
|
||||
def channel(self):
|
||||
|
@ -26,23 +26,23 @@ import copy
|
||||
from collections import namedtuple
|
||||
|
||||
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 .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 .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__ = (
|
||||
'Guild',
|
||||
@ -189,6 +189,9 @@ class Guild(Hashable):
|
||||
self._voice_states = {}
|
||||
self._state = state
|
||||
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):
|
||||
self._channels[channel.id] = channel
|
||||
|
Loading…
x
Reference in New Issue
Block a user