docs update + add case_insensitive_prefix

This commit is contained in:
iDutchy 2021-01-05 18:20:23 -06:00
parent b50b8e903f
commit db9dd93ad4
4 changed files with 31 additions and 4 deletions

View File

@ -15,7 +15,7 @@ __title__ = 'discord'
__author__ = 'Rapptz' __author__ = 'Rapptz'
__license__ = 'MIT' __license__ = 'MIT'
__copyright__ = 'Copyright 2015-2020 Rapptz' __copyright__ = 'Copyright 2015-2020 Rapptz'
__version__ = '1.6.0.6' __version__ = '1.6.0.7'
__path__ = __import__('pkgutil').extend_path(__path__, __name__) __path__ = __import__('pkgutil').extend_path(__path__, __name__)

View File

@ -28,6 +28,7 @@ import asyncio
import collections import collections
import inspect import inspect
import importlib.util import importlib.util
import itertools
import sys import sys
import traceback import traceback
import types import types
@ -94,9 +95,10 @@ class _DefaultRepr:
_default = _DefaultRepr() _default = _DefaultRepr()
class BotBase(GroupMixin): class BotBase(GroupMixin):
def __init__(self, command_prefix, help_command=_default, description=None, **options): def __init__(self, command_prefix, case_insensitive_prefix=False, help_command=_default, description=None, **options):
super().__init__(**options) super().__init__(**options)
self.command_prefix = command_prefix self.command_prefix = command_prefix
self.case_insensitive_prefix = case_insensitive_prefix
self.extra_events = {} self.extra_events = {}
self.__cogs = {} self.__cogs = {}
self.__extensions = {} self.__extensions = {}
@ -828,7 +830,13 @@ class BotBase(GroupMixin):
if not isinstance(ret, str): if not isinstance(ret, str):
try: try:
ret = list(ret) if self.case_insensitive_prefix:
temp = []
for pre in ret:
temp += list(map(''.join, itertools.product(*((c.upper(), c.lower()) for c in ret))))
ret = temp
else:
ret = list(ret)
except TypeError: except TypeError:
# It's possible that a generator raised this exception. Don't # It's possible that a generator raised this exception. Don't
# replace it with our own error if that's the case. # replace it with our own error if that's the case.
@ -841,6 +849,8 @@ class BotBase(GroupMixin):
if not ret: if not ret:
raise ValueError("Iterable command_prefix must contain at least one prefix") raise ValueError("Iterable command_prefix must contain at least one prefix")
if self.case_insensitive_prefix:
return list(map(''.join, itertools.product(*((c.upper(), c.lower()) for c in ret))))
return ret return ret
async def get_context(self, message, *, cls=Context): async def get_context(self, message, *, cls=Context):
@ -1012,6 +1022,10 @@ class Bot(BotBase, discord.Client):
matches messages starting with ``!?``. This is especially important matches messages starting with ``!?``. This is especially important
when passing an empty string, it should always be last as no prefix when passing an empty string, it should always be last as no prefix
after it will be matched. after it will be matched.
case_insensitive_prefix: :class:`bool`
Wheter the provided command_prefix should be case insensitive or not
.. versionadded:: 1.6.0.7
case_insensitive: :class:`bool` case_insensitive: :class:`bool`
Whether the commands should be case insensitive. Defaults to ``False``. This Whether the commands should be case insensitive. Defaults to ``False``. This
attribute does not carry over to groups. You must set it to every group if attribute does not carry over to groups. You must set it to every group if

View File

@ -27,4 +27,6 @@ Here are the custom features listed that have been added to enhanced-dpy. You ca
- Added ``Guild.try_member`` - Added ``Guild.try_member``
- Added ``Context.clean_prefix`` - Added ``Context.clean_prefix``
- Added ``Color.nitro_booster`` - Added ``Color.nitro_booster``
- Added ``Permissions.admin`` as alias to ``Permissions.administrator`` - Added ``Permissions.admin`` as alias to ``Permissions.administrator``
- Added ``Cog.aliases``
- Added ``Bot.case_insensitive_prefix``

View File

@ -11,6 +11,17 @@ Changelog
This page keeps a detailed human friendly rendering of what's new and changed This page keeps a detailed human friendly rendering of what's new and changed
in specific versions. in specific versions.
.. _vp1p6p0p7:
v1.6.0.7
--------
New Features
~~~~~~~~~~~~~~
- Add :attr:`Cog.aliases`
- Add :attr:`Bot.case_insensitive_prefix`
.. _vp1p5p1p6: .. _vp1p5p1p6:
v1.5.1.6 v1.5.1.6