from importlib.util import module_from_spec from threading import current_thread from time import sleep as blocking_sleep from scarletio import CancelledError, Task, WaitTillAll, include, sleep from scarletio.tools.asynchronous_interactive_console import ( create_banner, create_exit_message, run_asynchronous_interactive_console) from ... import __package__ as PACKAGE_NAME from ..core import CLIENTS, KOKORO from ..permission import Permission from ..permission.utils import PERMISSION_KEY PACKAGE = __import__(PACKAGE_NAME) Client = include('Client') def start_clients(): """ Starts up all the not running clients. Can be called from any thread. """ for client in CLIENTS.values(): if client.running: continue Task(client.connect(), KOKORO) if (current_thread() is not KOKORO):
import re, sys, warnings from difflib import get_close_matches from types import (BuiltinFunctionType, BuiltinMethodType, FunctionType, GetSetDescriptorType, MemberDescriptorType, MethodType) from scarletio import BaseMethodType, MethodLike, cached_property, include, module_property, weak_method from ...discord.bases import IconSlot from .builder_html import html_serialize_docs from .builder_text import generate_preview_for, serialize_docs, serialize_docs_embed_sized, serialize_docs_source_text from .parser import DocString from .qualpath import QualPath html_serialize_docs_extended = include('html_serialize_docs_extended') WrapperDescriptorType = object.__eq__.__class__ MethodDescriptorType = int.bit_length.__class__ SlotWrapperType = object.__lt__.__class__ METHOD_TYPES = { GetSetDescriptorType, BuiltinMethodType, MethodType, WrapperDescriptorType, MethodDescriptorType, MethodLike, BaseMethodType, weak_method, }
from scarletio import copy_docs, export, include from ..bases import ICON_TYPE_NONE, Icon, instance_or_id_to_instance from ..core import USERS from ..exceptions import DiscordException, ERROR_CODES from ..http import urls as module_urls from ..http.urls import WEBHOOK_URL_PATTERN from ..preconverters import preconvert_preinstanced_type, preconvert_snowflake, preconvert_str from ..user import ClientUserBase, User, UserBase, ZEROUSER from .preinstanced import WebhookType from .webhook_base import WebhookBase from .webhook_sources import WebhookSourceChannel, WebhookSourceGuild create_partial_webhook_from_id = include('create_partial_webhook_from_id') create_partial_channel_from_id = include('create_partial_channel_from_id') ChannelText = include('ChannelText') Client = include('Client') @export class Webhook(WebhookBase): """ Represents a Discord webhook. At some cases it might be used as webhook's user representation. Attributes ---------- id : `int` The webhook's unique identifier number. name : str
__all__ = ('WebhookSourceChannel', 'WebhookSourceGuild', ) from scarletio import include from ..bases import DiscordEntity, IconSlot from ..http import urls as module_urls create_partial_channel_from_id = include('create_partial_channel_from_id') create_partial_guild_from_id = include('create_partial_guild_from_id',) class WebhookSourceGuild(DiscordEntity): """ Entity representing a server type ``Webhook``'s guild. Attributes ---------- id : `int` The unique identifier number of the guild. name : `str` The name of the guild. icon_hash : `int` The guild's icon's hash in `uint128`. icon_type : ``IconType`` The guild's icon's type. """ __slots__ = ('name',) icon = IconSlot( 'icon',
from scarletio import include from ...emoji import Emoji from .constants import ( COMPONENT_CUSTOM_ID_LENGTH_MAX, COMPONENT_LABEL_LENGTH_MAX, COMPONENT_MAX_LENGTH_MAX, COMPONENT_MAX_LENGTH_MIN, COMPONENT_MIN_LENGTH_MAX, COMPONENT_MIN_LENGTH_MIN, COMPONENT_OPTION_LENGTH_MAX, COMPONENT_OPTION_LENGTH_MIN, COMPONENT_OPTION_MAX_VALUES_MAX, COMPONENT_OPTION_MAX_VALUES_MIN, COMPONENT_OPTION_MIN_VALUES_MAX, COMPONENT_OPTION_MIN_VALUES_MIN, COMPONENT_SUB_COMPONENT_LIMIT, COMPONENT_TITLE_LENGTH_MAX, COMPONENT_TITLE_LENGTH_MIN) from .preinstanced import ComponentType ComponentSelectOption = include('ComponentSelectOption') ComponentBase = include('ComponentBase') COMPONENT_TYPE_ROW = ComponentType.row def _debug_component_components(components): """ Checks whether given `component.components` value is correct. Parameters ---------- components : `None` or (`list`, `tuple`) of ``ComponentBase`` Sub-components. Raises
__all__ = ('ComponentSelect', ) import reprlib from scarletio import copy_docs, include from .component_base import ComponentBase from .component_select_option import ComponentSelectOption from .debug import (_debug_component_custom_id, _debug_component_enabled, _debug_component_max_values, _debug_component_min_values, _debug_component_options, _debug_component_placeholder) from .preinstanced import ComponentType create_auto_custom_id = include('create_auto_custom_id') class ComponentSelect(ComponentBase): """ Select component. Attributes ---------- custom_id : `str` Custom identifier to detect which component was used by the user. enabled : `bool` Whether the component is enabled. options : `None`, `tuple` of ``ComponentSelectOption`` Options of the select. placeholder : `str` Placeholder text of the select. max_values : `int
__all__ = ('ComponentRow', ) from scarletio import copy_docs, export, include from .component_base import ComponentBase from .debug import _debug_component_components from .preinstanced import ComponentType create_component = include('create_component') @export class ComponentRow(ComponentBase): """ Action row component. Attributes ---------- components : `None`, `tuple` of ``ComponentBase``s Stored components. Class Attributes ---------------- custom_id : `NoneType` = `None` `custom_id` is not applicable for component rows. type : ``ComponentType`` = `ComponentType.row` The component's type. """ type = ComponentType.row __slots__ = ('components', )
__all__ = ('ActivityCustom',) from scarletio import include from ..utils import DISCORD_EPOCH_START, datetime_to_unix_time, unix_time_to_datetime from . import activity_types as ACTIVITY_TYPES from .activity_base import ActivityBase create_partial_emoji_from_data = include('create_partial_emoji_from_data') class ActivityCustom(ActivityBase): """ Represents a Discord custom activity. Attributes ---------- created : `int` When the status was created as Unix time in milliseconds. Defaults to `0`. emoji : `None`, ``Emoji`` The emoji of the activity. If it has no emoji, then set as `None`. state : `None`, `str` The activity's text under it's emoji. Defaults to `None`. Class Attributes ---------------- id : `int` = `0` The activity's id. type : `int` = `4`
__all__ = ('ComponentTextInput', ) import reprlib from scarletio import copy_docs, include from ...preconverters import preconvert_preinstanced_type from .component_base import ComponentBase from .debug import (_debug_component_custom_id, _debug_component_label, _debug_component_max_length, _debug_component_min_length, _debug_component_placeholder, _debug_component_required, _debug_component_text_input_value) from .preinstanced import ComponentType, TextInputStyle create_identifier_custom_id_from_name = include( 'create_identifier_custom_id_from_name') class ComponentTextInput(ComponentBase): """ Text input component. Attributes ---------- custom_id : `None`, `str` Custom identifier to detect which text input was clicked by the user. label : `None`, `str` Label of the component. max_length : `int`
__all__ = ('MessageRepr', ) from scarletio import include from ..bases import DiscordEntity from ..core import CHANNELS, GUILDS Message = include('Message') class MessageRepr(DiscordEntity): """ Represents an uncached message. The class is used, when `HATA_ALLOW_DEAD_EVENTS` env variable is set as `True`. Attributes ---------- id : `int` The unique identifier number of the represented message. channel_id : `int` The respective message's channel's identifier. guild_id : `int` The respective message's guild's identifier. Defaults to `0`. """ __slots__ = ( 'channel_id', 'guild_id', )
from . import channel_types as CHANNEL_TYPES from .channel_base import ChannelBase from .channel_guild_base import ChannelGuildBase from .channel_guild_category import ChannelCategory from .channel_guild_directory import ChannelDirectory from .channel_guild_forum import ChannelForum from .channel_guild_store import ChannelStore from .channel_guild_text import ChannelText from .channel_guild_undefined import ChannelGuildUndefined from .channel_guild_voice import ChannelStage, ChannelVoice, ChannelVoiceBase from .channel_private import ChannelGroup, ChannelPrivate from .channel_thread import AUTO_ARCHIVE_OPTIONS from .channel_thread import ChannelThread from .preinstanced import VideoQualityMode VoiceRegion = include('VoiceRegion') Guild = include('Guild') CHANNEL_TYPE_MAP = { CHANNEL_TYPES.guild_text: ChannelText, CHANNEL_TYPES.private: ChannelPrivate, CHANNEL_TYPES.guild_voice: ChannelVoice, CHANNEL_TYPES.private_group: ChannelGroup, CHANNEL_TYPES.guild_category: ChannelCategory, CHANNEL_TYPES.guild_announcements: ChannelText, CHANNEL_TYPES.guild_store: ChannelStore, CHANNEL_TYPES.guild_thread_announcements: ChannelThread, CHANNEL_TYPES.guild_thread_public: ChannelThread, CHANNEL_TYPES.guild_thread_private: ChannelThread, CHANNEL_TYPES.guild_stage: ChannelStage, CHANNEL_TYPES.guild_directory: ChannelDirectory,
__all__ = ('MessageInteraction', ) from scarletio import include from ..bases import DiscordEntity from ..user import User InteractionType = include('InteractionType') class MessageInteraction(DiscordEntity): """ Sent with a ``Message``, when the it is a response to an ``InteractionEvent``. Attributes ---------- id : `int` The interaction's identifier. name : `str` The invoked interaction's name. type : ``InteractionType`` The interaction's type. user : ``ClientUserBase`` Who invoked the interaction. """ __slots__ = ('name', 'type', 'user') def __new__(cls, data): """ Creates a new ``MessageInteraction`` from the received data.
__all__ = () from functools import partial as partial_func from re import (I as re_ignore_case, M as re_multi_line, S as re_dotall, compile as re_compile, escape as re_escape, match as re_match) from types import FunctionType from scarletio import CallableAnalyzer, include from ...discord.permission.permission import PERMISSION_CAN_SEND_MESSAGES_ALL from .exceptions import CommandCheckError, CommandProcessingError from .utils import raw_name_to_display CheckBase = include('CheckBase') CommandCheckWrapper = include('CommandCheckWrapper') SUB_COMMAND_NAME_RP = re_compile('([a-zA-Z0-9_\-]+)\s*') COMMAND_NAME_RP = re_compile('\s*([^\s]*)\s*', re_multi_line | re_dotall) async def run_checks(checks, command_context): """ Runs the checks. This function is coroutine. Parameters ---------- checks : `GeneratorType` A generator yielding checks.
from math import floor from random import random from re import I as re_ignore_case, U as re_unicode, compile as re_compile from time import time as time_now from scarletio import IS_UNIX, LOOP_TIME, export, include, modulize, set_docs from .bases import DiscordEntity from .core import CHANNELS, ROLES, USERS try: from dateutil.relativedelta import relativedelta except ImportError: relativedelta = None MESSAGE_JUMP_URL_RP = include('MESSAGE_JUMP_URL_RP') create_partial_user_from_id = include('create_partial_user_from_id') RelationshipType = include('RelationshipType') DATETIME_FORMAT_CODE = '%Y-%m-%d %H:%M:%S' def endswith_xFFxD9(data): """ Checks whether the given data endswith `b'\xD9\xFF'` ignoring empty bytes at the end of it. Parameters ---------- data : `bytes-like` Returns
__all__ = ('PermissionOverwrite', ) from scarletio import include from ..permission import Permission from .preinstanced import PermissionOverwriteTargetType from .utils import PERMISSION_ALLOW_KEY, PERMISSION_DENY_KEY, get_permission_overwrite_key_value create_partial_role_from_id = include('create_partial_role_from_id') create_partial_user_from_id = include('create_partial_user_from_id') Role = include('Role') PERMISSION_OVERWRITE_TYPE_ROLE = PermissionOverwriteTargetType.role PERMISSION_OVERWRITE_TYPE_USER = PermissionOverwriteTargetType.user class PermissionOverwrite: """ Represents a permission overwrite of a guild channel. Attributes ---------- allow : ``Permission`` The allowed permissions by the overwrite. deny : ``Permission`` The denied permission by the overwrite. target_id : `int` The permission overwrites target's identifier. target_type : ``PermissionOverwriteTargetType`` The permission overwrite's target's type.
__all__ = ('Category', ) from scarletio import WeakReferer, include from ...discord.events.handling_helpers import Router, _EventHandlerManager from .command_helpers import test_error_handler, validate_checks from .utils import normalize_description, raw_name_to_display Command = include('Command') class Category: """ Category of commands. Parameters ---------- _checks : `None`, `tuple` of ``CheckBase`` The checks of the category. _command_processor_reference : `None`, ``WeakReferer`` to ``CommandProcessor``. Weak reference to the category's command processor. _error_handlers : `None`, `list` of `FunctionType` Error handlers bind to the category. _self_reference : `None`, ``WeakReferer`` to ``Category`` Reference to the command processor itself. command_instances : `set` of ``Command`` The registered commands to the category. display_name : `str` The category's display name. description : `Any`
__all__ = ('get_permission_overwrite_key_value', 'cr_p_permission_overwrite_object', ) from scarletio import include from ...env import API_VERSION from .preinstanced import PermissionOverwriteTargetType Role = include('Role') if API_VERSION in (6, 7): PERMISSION_KEY = 'permissions_new' PERMISSION_ALLOW_KEY = 'allow_new' PERMISSION_DENY_KEY = 'deny_new' def get_permission_overwrite_key_value(data): """ Returns the permission overwrite's type's value. Parameters ---------- data : `dict` of (`str`, `Any`) items Received permission overwrite data. Returns ------- type_value : `str` """ return data['type'] else:
__all__ = ('VoiceState', ) from scarletio import include from ..core import CHANNELS, GUILDS from ..utils import timestamp_to_datetime from .utils import create_partial_user_from_id create_partial_role_from_id = include('create_partial_role_from_id') class VoiceState: """ Represents a user at a ``ChannelVoice``. Attributes ---------- _cache_user : ``ClientUserBase`` The voice state's respective user. channel_id : `int` The channel's identifier to where the user is connected to. deaf : `bool` Whether the user is deafen. guild_id : `int` The guild's identifier where the user is connected to. is_speaker : `bool` Whether the user is suppressed inside of the voice channel. If the channel is a ``ChannelVoice``, it is always `False`, meanwhile it ``ChannelStage`` it can vary.
__all__ = ('Stage', ) import reprlib from scarletio import export, include from ..bases import DiscordEntity from ..channel import ChannelStage, create_partial_channel_from_id from ..core import STAGES from ..scheduled_event import PrivacyLevel Guild = include('Guild') create_partial_guild_from_id = include('create_partial_guild_from_id') @export class Stage(DiscordEntity): """ Represents an active stage instance of a stage channel. Attributes ---------- id : `int` The stage instance's identifier. channel : ``ChannelStage`` The stage channel where the stage is active. discoverable : `bool` Whether the stage is discoverable. guild : ``Guild`` The guild of the stage channel. invite_code : `None`, `str`
__all__ = ('ThreadProfile', 'thread_user_create', 'thread_user_delete', 'thread_user_pop', 'thread_user_update') from datetime import datetime from scarletio import include from ..utils import timestamp_to_datetime from .flags import ThreadProfileFlag create_partial_role_from_id = include('create_partial_role_from_id') Client = include('Client') def thread_user_create(thread_channel, user, thread_user_data): """ Resolves the given thread user data. Parameters ---------- thread_channel : ``ChannelThread`` The respective thread. user : ``ClientUserBase`` The respective user to add or update in the thread. thread_user_data : `dict` of (`str`, `Any`) items Received thread user data. Returns ------- created : `bool`
__all__ = ('InteractionForm', ) import reprlib from scarletio import copy_docs, include from .component_base import ComponentBase from .component_row import ComponentRow from .debug import _debug_component_components, _debug_component_custom_id, _debug_component_title create_auto_custom_id = include('create_auto_custom_id') create_component = include('create_component') class InteractionForm(ComponentBase): """ Form component. Attributes ---------- components : `None`, `tuple` of ``ComponentBase`` Stored components. custom_id : `None`, `str` Custom identifier to match the form data when receiving it's interaction back. title : `None`, `str` The form's title. Class Attributes ---------------- type : ``ComponentType`` = `ComponentType.none` The component's type.
__all__ = ('ChannelGuildUndefined', ) from scarletio import copy_docs, export, include from ..core import CHANNELS from ..permission import Permission from ..permission.permission import PERMISSION_MASK_VIEW_CHANNEL, PERMISSION_NONE from ..preconverters import preconvert_int, preconvert_snowflake, preconvert_str from .channel_base import ChannelBase from .channel_guild_base import ChannelGuildMainBase parse_permission_overwrites = include('parse_permission_overwrites') @export class ChannelGuildUndefined(ChannelGuildMainBase): """ Represents an undefined ``Guild`` channel. This class is a place-holder for future classes. Expectedly for channel type `7` and `8`. Attributes ---------- id : `int` Unique identifier of the channel. _permission_cache : `None`, `dict` of (`int`, ``Permission``) items A `user_id` to ``Permission`` relation mapping for caching permissions. Defaults to `None`. parent_id : `int` The channel's parent's identifier. guild_id : `int` The channel's guild's identifier.
__all__ = ('UnknownCrossMention', ) from scarletio import include from ..bases import DiscordEntity from ..core import CHANNELS from ..utils import DATETIME_FORMAT_CODE ChannelBase = include('ChannelBase') class UnknownCrossMention(DiscordEntity): """ Represents an unknown channel mentioned by a cross guild mention. These mentions are stored at ``Message``'s `.cross_mentions` attribute. Attributes ---------- id : `int` The unique identifier number of the respective channel. guild_id : `int` The unique identifier number of the respective channel's guild. name : `str` The name of the respective channel. type : `int` The channel type value of the respective channel. """ __slots__ = ('guild_id', 'name', 'type',) def __new__(cls, data):
from ..bases import DiscordEntity, ICON_TYPE_NONE, IconSlot from ..color import Color from ..core import GUILDS, ROLES from ..http import urls as module_urls from ..permission.permission import PERMISSION_NONE, Permission from ..permission.utils import PERMISSION_KEY from ..preconverters import (preconvert_bool, preconvert_color, preconvert_flag, preconvert_int, preconvert_snowflake, preconvert_str) from ..user import create_partial_user_from_id from ..utils import DATETIME_FORMAT_CODE from .preinstanced import RoleManagerType create_partial_integration_from_id = include( 'create_partial_integration_from_id') create_unicode_emoji = include('create_unicode_emoji') Emoji = include('Emoji') ROLE_MANAGER_TYPE_NONE = RoleManagerType.none ROLE_MANAGER_TYPE_UNSET = RoleManagerType.unset ROLE_MANAGER_TYPE_UNKNOWN = RoleManagerType.unknown ROLE_MANAGER_TYPE_BOT = RoleManagerType.bot ROLE_MANAGER_TYPE_BOOSTER = RoleManagerType.booster ROLE_MANAGER_TYPE_INTEGRATION = RoleManagerType.integration @export class Role(DiscordEntity, immortal=True): """ Represents a Discord guild's role.
__all__ = ('RateLimitProxy', ) from threading import current_thread from scarletio import Future, LOOP_TIME, WeakReferer, include from .rate_limit import ( LIMITER_CHANNEL, LIMITER_GLOBAL, LIMITER_GUILD, LIMITER_INTERACTION, LIMITER_UNLIMITED, LIMITER_WEBHOOK, RateLimitGroup, RateLimitHandler, UNLIMITED_SIZE_VALUE ) ChannelBase = include('ChannelBase') ChannelGuildBase = include('ChannelGuildBase') Message = include('Message') Role = include('Role') Webhook = include('Webhook') WebhookRepr = include('WebhookRepr') Guild = include('Guild') InteractionEvent = include('InteractionEvent') class RateLimitProxy: """ A proxy towards a rate limit. Attributes ---------- _handler : None` or (`WeakReferer` to ``RateLimitHandler``) Reference to the actual rate limit handler of the `client` with the specified `group` and `limiter`. _key : ``RateLimitHandler``
__all__ = ('SlasherCommandError', 'SlasherApplicationCommandParameterConversionError') from random import choice from scarletio import CallableAnalyzer, include from scarletio import copy_docs from ...discord.exceptions import DiscordException, ERROR_CODES from ...discord.interaction import InteractionType SlasherApplicationCommand = include('SlasherApplicationCommand') Slasher = include('Slasher') class SlasherCommandError(Exception): """ Base class for slash command internal errors. """ pass @property def pretty_repr(self): """ Returns the pretty representation of the exception. Returns ------- representation : `str` """ return ''
from ..core import CHANNELS, GUILDS from ..permission import Permission, PermissionOverwriteTargetType from ..permission.permission import (PERMISSION_ALL, PERMISSION_MASK_ADMINISTRATOR, PERMISSION_MASK_VIEW_CHANNEL, PERMISSION_NONE) from ..permission.utils import PERMISSION_ALLOW_KEY, PERMISSION_DENY_KEY from ..user import ClientUserBase PERMISSION_OVERWRITE_TYPE_ROLE = PermissionOverwriteTargetType.role PERMISSION_OVERWRITE_TYPE_USER = PermissionOverwriteTargetType.user from .channel_base import ChannelBase Client = include('Client') create_partial_guild_from_id = include('create_partial_guild_from_id') @export class ChannelGuildBase(ChannelBase): """ Base class for guild channels. Attributes ---------- id : `int` Unique identifier of the channel. _permission_cache : `None`, `dict` of (`int`, ``Permission``) items A `user_id` to ``Permission`` relation mapping for caching permissions. Defaults to `None`. parent_id : `int`
__all__ = ('Emoji', ) from scarletio import export, include from ..bases import DiscordEntity, id_sort_key from ..bases import instance_or_id_to_instance, instance_or_id_to_snowflake, iterable_of_instance_or_id_to_snowflakes from ..core import BUILTIN_EMOJIS, EMOJIS, GUILDS, UNICODE_TO_EMOJI from ..http import urls as module_urls from ..preconverters import preconvert_bool, preconvert_snowflake, preconvert_str from ..role import Role, create_partial_role_from_id from ..user import User, ZEROUSER from ..utils import DATETIME_FORMAT_CODE, DISCORD_EPOCH_START, id_to_datetime Client = include('Client') Guild = include('Guild') UNICODE_EMOJI_LIMIT = 1 << 21 @export class Emoji(DiscordEntity, immortal=True): """ Represents a Discord emoji. It can be custom or builtin (unicode) emoji as well. Builtin emojis are loaded when the module is imported and they are stores at `BUILTIN_EMOJIS` dictionary. At `BUILTIN_EMOJIS` the keys are the emoji's names, so it is easy to access any Discord unicode emoji like that. Custom emojis are loaded with ``Guild``-s on startup, but new partial custom emojis can be created later as well, when a ``Message`` receives any reaction. Attributes ----------
__all__ = ('EXTENSIONS', ) import sys from importlib import reload as reload_module from importlib.util import find_spec, module_from_spec, spec_from_file_location from py_compile import compile as compile_module from scarletio import HybridValueDictionary, WeakValueDictionary, include from .exceptions import DoNotLoadExtension from .snapshot import calculate_snapshot_difference, revert_snapshot, take_snapshot from .utils import PROTECTED_NAMES, _get_path_extension_name, _validate_entry_or_exit EXTENSION_LOADER = include('EXTENSION_LOADER') EXTENSIONS = WeakValueDictionary() EXTENSION_STATE_UNDEFINED = 0 EXTENSION_STATE_LOADED = 1 EXTENSION_STATE_UNLOADED = 2 EXTENSION_STATE_UNSATISFIED = 3 EXTENSION_STATE_VALUE_TO_NAME = { EXTENSION_STATE_UNDEFINED: 'undefined', EXTENSION_STATE_LOADED: 'loaded', EXTENSION_STATE_UNLOADED: 'unloaded', EXTENSION_STATE_UNSATISFIED: 'unsatisfied', } class Extension: