def setup(bot: Red): if not bot._cli_flags.dev: raise CogLoadError("This cog requires the `--dev` CLI flag.") if getattr(bot.get_cog("Dev"), "sessions", None): raise CogLoadError("End your REPL session(s) first.") bot.remove_cog("Dev") bot.add_cog(Dev())
async def setup(bot): if discord.version_info <= (1, 4): raise CogLoadError("This cog requires d.py 1.4+ to work.") uinfo = Userinfo(bot) if "Mod" not in bot.cogs: raise CogLoadError("This cog requires the Mod cog to be loaded.") global _old_userinfo _old_userinfo = bot.get_command("userinfo") if _old_userinfo: bot.remove_command(_old_userinfo.name) bot.add_cog(uinfo)
def setup(bot: Red): if not bot._cli_flags.dev: raise CogLoadError("This cog requires the `--dev` CLI flag.") core_dev = bot.get_cog("Dev") if sessions := getattr(core_dev, "sessions", None): s = "s" if len(sessions) > 1 else "" is_private = bot._connection._private_channels.__contains__ raise CogLoadError( f"End your REPL session{s} first: " + humanize_list([ "Private channel" if is_private(id) else f"<#{id}>" for id in sessions ]))
async def setup(bot): expected = "0.0.1b7" if sans.version_info != type(sans.version_info)(expected): raise CogLoadError(f"This cog requires sans version {expected}.") await bot.wait_until_ready() if bot.user.id not in (743870009826083017, 488781401567526915, 256505473807679488): raise CogLoadError( "I don't know how you found this cog, but it isn't meant for your bot." ) cog = Citizenship(bot) await cog.initialize() bot.add_cog(cog)
def red_version(min_ver: str = None, max_ver: str = None) -> None: """Runtime Red version check This may be preferable if you'd like to check the bot's version independently of Downloader. Example ------- >>> def setup(bot): ... # If Red is on 3.1.0 or 3.1.1, this will raise a CogLoadError. ... # Otherwise, this is comparable to a no-op. ... # The above isn't applicable on 3.0.x, as simply importing swift_libs will raise ... # a variety of import errors. ... red_version("3.1.2") ... # ... Parameters ----------- min_ver: :class:`str` Minimum expected bot version max_ver: :class:`str` Maximum expected bot version; you shouldn't need to use this in most cases Raises ------ CogLoadError """ if not min_ver and not max_ver: raise RuntimeError("Neither minimum nor maximum versions were passed") if min_ver: min_ver = VersionInfo.from_str(min_ver) if max_ver: max_ver = VersionInfo.from_str(max_ver) if min_ver and max_ver and min_ver > max_ver: raise RuntimeError( "Minimum version is greater than the maximum version") err = translate.lazy( "checks", (("red_outdated_or_new" if min_ver != max_ver else "red_not_exact") if min_ver and max_ver else "red_outdated" if min_ver else "red_too_new"), min=min_ver, max=max_ver, current=_red_ver, ) if min_ver and min_ver > _red_ver: raise CogLoadError(str(err)) if max_ver and max_ver < _red_ver: raise CogLoadError(str(err))
async def setup(bot): if "Leveler" not in bot.cogs: raise CogLoadError( "A mongodb instance and leveler by fixator/aikaterna is **REQUIRED** for this cog to function." ) cog = SimLeague(bot) bot.add_cog(cog)
async def setup(bot: Red) -> None: if version_info < VersionInfo.from_str("3.1.3"): raise CogLoadError( "This cog requires at least Red 3.1.3.\n" "Go update, it's a straight improvement from previously supported versions." ) bot.add_cog(VoiceTools())
def setup(bot: Red) -> None: cog = bot.get_cog("CustomCommands") if cog: raise CogLoadError( "This cog conflicts with CustomCommands and cannot be loaded with both at the same time." ) bot.add_cog(Tags(bot))
def setup(bot): if not HAS_APSW: raise CogLoadError("This cog requires `apsw-wheels`.") else: from .modnotes import ModNotes bot.add_cog(ModNotes(bot))
async def setup(bot): uinfo = Userinfo(bot) if "Mod" not in bot.cogs: raise CogLoadError("This cog requires the Mod cog to be loaded.") global _old_userinfo if _old_userinfo := bot.get_command("userinfo"): bot.remove_command(_old_userinfo.name)
def sl_version(min_ver: str, cog: str = None): """Check if the version of swift_libs loaded matches the requested version Example ------- >>> def setup(bot): ... # On 1.0.x, this will raise a CogLoadError explaining how ... # the bot owner can update their loaded swift_libs version. ... sl_version("1.1.0") ... # ... Arguments ---------- min_ver: str The minimum swift_libs version your cog requires to load cog: Optional[str] Your cog's package name. If this is provided, your cog will be offered to be reloaded if ``[p]swiftlibs reload`` is invoked. """ if VersionInfo.from_str(min_ver) > _sl_ver: if cog: # noinspection PyProtectedMember from .setup import require_update require_update.add(cog) raise CogLoadError( translate("checks.sl_outdated", current=_sl_ver, expected=min_ver))
def try_import(*imports: str, extra: str = None) -> None: """Try to import required modules and raise an exception if any fail to import Keyword Arguments ----------------- extra: str If this is provided, this will be logged as extra information alongside any import failures in the bot's logging. Raises ------- CogLoadError Raised if one or more given imports fail to import """ failed: List[str] = [] for import_ in imports: try: importlib.import_module(import_) except Exception as e: # pylint:disable=broad-except log.exception("Failed to import required library %r", import_, exc_info=e) failed.append(import_) if failed: if extra: log.warning( "Extra information provided for the above import failures: %s", extra) raise CogLoadError( translate("checks.import_failed", libs=Humanize([inline(x) for x in failed]), n=len(failed)))
def setup(bot: Red) -> None: cog = bot.get_cog("CustomCommands") if cog: raise CogLoadError( "This cog conflicts with CustomCommands and both cannot be loaded at the same time. " "After unloading `customcom`, you can migrate custom commands to tags with `[p]migratecustomcom`." ) bot.add_cog(Tags(bot))
def setup(bot): try: import feedparser except ImportError: raise CogLoadError( "You need `feedparser` for this. Downloader *should* have handled this for you." ) try: import discordtextsanitizer except ImportError: raise CogLoadError( "You need `discord-text-sanitizer` for this. Downloader *should* have handled this for you." ) from .core import RSS bot.add_cog(RSS(bot))
def setup(bot): if import_failed or sans.version_info < type(sans.version_info)("0.0.1b6"): raise CogLoadError( "The sans library is out of date or not installed.\n" "Run this command to update it: [p]pipinstall sans\n" "You may have to [p]restart your bot to have the new version take effect." ) from import_failed bot.add_cog(NationStates(bot))
def setup(bot: Red) -> None: for cog_name, module_name, tag_name in conflicting_cogs: if bot.get_cog(cog_name): raise CogLoadError( f"This cog conflicts with {cog_name} and both cannot be loaded at the same time. " f"After unloading `{module_name}`, you can migrate {tag_name} to tags with `[p]migrate{module_name}`." ) bot.add_cog(Tags(bot))
async def setup(bot): if version_info < VersionInfo.from_str("3.1.2"): raise CogLoadError( "Hey, this now depends on changes in Red 3.1.2." "\nGo update, it's a straight improvement from previously supported versions." ) discord.TextChannel.delete_messages = replacement_delete_messages bot.add_cog(Scheduler(bot))
def setup(bot): try: from .core import RSS except ImportError: raise CogLoadError( "You need `feedparser` for this. Downloader *should* have handled this for you." ) else: bot.add_cog(RSS(bot))
async def setup(bot: Red): try: cog = Crossbar(bot) await cog.initialize() except ImportError: raise CogLoadError( "You need `crossbar`: https://pypi.org/project/crossbar") else: bot.add_cog(cog)
async def setup(bot: Red): try: setup_cog(bot, "TimedMute", require_version="0.0.2a0") except TypeError: raise CogLoadError( "Your bot is running an outdated version of the shared library this" " cog depends on. You can resolve this issue by either running" "`[p]swiftlibs reload`, or by restarting your bot." ) try_import("babel") from timedmute.shared import translate if "TimedRole" not in bot.cogs: raise CogLoadError(translate("requires_timedrole")) from timedmute.timedmute import TimedMute bot.add_cog(TimedMute(bot))
async def setup(bot: Red): for cog in INCOMPATIBLE_COGS: if cog in bot.cogs: raise CogLoadError(f"Cog {cog} is incompatible with this cog.") cog = CaseInsensitive(bot) await out_of_date_check("caseinsensitive", cog.__version__) cog.plug_core() cog.plug_alias() bot.add_cog(cog)
async def setup(bot: Red) -> None: await validate_tagscriptengine(bot, tse_version) for cog_name, module_name, tag_name in conflicting_cogs: if bot.get_cog(cog_name): raise CogLoadError( f"This cog conflicts with {cog_name} and both cannot be loaded at the same time. " f"After unloading `{module_name}`, you can migrate {tag_name} to tags with `[p]migrate{module_name}`." ) tags = Tags(bot) bot.add_cog(tags)
async def setup(bot: Red): try: setup_cog(bot, "Quotes", require_version="0.0.2a0") except TypeError: from redbot.core.errors import CogLoadError raise CogLoadError( "Your bot is running an outdated version of the shared library this" " cog depends on. You can resolve this issue by either running" "`[p]swiftlibs reload`, or by restarting your bot.") from quotes.quotes import Quotes bot.add_cog(Quotes(bot))
async def validate_tagscriptengine(bot: Red, tse_version: str, *, reloaded: bool = False): try: import TagScriptEngine as tse except ImportError as exc: raise CogLoadError( "The SlashTags cog failed to install TagScriptEngine. Reinstall the cog and restart your " "bot. If it continues to fail to load, contact the cog author." ) from exc commands = [ "`pip(3) uninstall -y TagScriptEngine`", "`pip(3) uninstall -y TagScript`", f"`pip(3) install TagScript=={tse_version}`", ] commands = "\n".join(commands) message = ( "The SlashTags cog attempted to install TagScriptEngine, but the version installed " "is outdated. Shut down your bot, then in shell in your venv, run the following " f"commands:\n{commands}\nAfter running these commands, restart your bot and reload " "SlashTags. If it continues to fail to load, contact the cog author.") if not hasattr(tse, "VersionInfo"): if not reloaded: reload(tse) await validate_tagscriptengine(bot, tse_version, reloaded=True) return await bot.send_to_owners(message) raise CogLoadError(message) if tse.version_info < tse.VersionInfo.from_str(tse_version): await bot.send_to_owners(message) raise CogLoadError(message)
async def setup(bot: Red): try: setup_cog(bot, "RNDActivity", require_version="0.0.3a0") except TypeError: from redbot.core.errors import CogLoadError raise CogLoadError( "Your bot is running an outdated version of the shared library this" " cog depends on. You can resolve this issue by either running" "`[p]swiftlibs reload`, or by restarting your bot.") try_import("babel") from rndactivity.rndactivity import RNDActivity bot.add_cog(RNDActivity(bot))
async def setup(bot): try: setup_cog(bot, "RemindMe", require_version="0.0.2a0") except TypeError: from redbot.core.errors import CogLoadError raise CogLoadError( "Your bot is running an outdated version of the shared library this" " cog depends on. You can resolve this issue by either running" "`[p]swiftlibs reload`, or by restarting your bot." ) try_import("babel", "tzlocal") from .remindme import RemindMe bot.add_cog(RemindMe(bot))
async def setup(bot): await bot.send_to_owners( "This cog still functions, but I suggest you leave and stop using Red. " "I was removed from Red for not wanting my work misrepresented by the " "organization, and stating what I would do *if* that continued. " 'For how much Red and it\'s members go after people who " take credit" ' "for their work, they sure were quick to dismiss mine. " "The cog will recieve no further updates, nor is anyone legally allowed to fork to update." ) if bot.user.id != 275047522026913793: raise CogLoadError( "Hey, stop that. " "This was listed as WIP *and* hidden, " "*and* warned you about *liabilities.* " "Last warning, stop it. Stop trying to " "log messages without understanding how badly this can go.") cog = MLog(bot) bot.add_cog(cog) cog.init()
async def setup(bot: Red): try: setup_cog(bot, "MiscTools", require_version="0.0.3a0") except TypeError: from redbot.core.errors import CogLoadError raise CogLoadError( "Your bot is running an outdated version of the shared library this" " cog depends on. You can resolve this issue by either running" "`[p]swiftlibs reload`, or by restarting your bot.") try_import("babel", "tzlocal") from misctools.misctools import MiscTools cog = MiscTools(bot) bot.add_cog(cog) try: await cog.bootstrap() except Exception: bot.remove_cog("MiscTools") raise
import contextlib import importlib import json from pathlib import Path import discord from redbot.core import VersionInfo from redbot.core.bot import Red from redbot.core.errors import CogLoadError from . import vexutils from .vexutils.meta import out_of_date_check if discord.__version__.startswith("1"): raise CogLoadError( "This cog requires discord.py 2.x, which is currently incompatible with Red and most " "other cogs. This cog is marked as hidden for a reason.") from .buttonopll import ButtonPoll with open(Path(__file__).parent / "info.json") as fp: __red_end_user_data_statement__ = json.load(fp)["end_user_data_statement"] async def setup(bot: Red): cog = ButtonPoll(bot) await cog.async_init() await out_of_date_check("buttonpoll", cog.__version__) bot.add_cog(cog)
from collections import defaultdict from datetime import datetime, timedelta from typing import Iterator, List, Tuple, Union import discord from redbot.core import Config, checks, commands, data_manager, modlog from redbot.core.bot import Red from redbot.core.errors import CogLoadError from redbot.core.i18n import Translator from redbot.core.utils.chat_formatting import box, pagify try: from tabulate import tabulate except ImportError: raise CogLoadError( "tabulate is not installed. Please install it with the following command, then " "try loading this cog again:\n```\n[p]pipinstall tabulate[widechars]\n```\n" "This command requires the `downloader` cog to be loaded.") UNIQUE_ID = 0x134087DE _CASETYPE = { "name": "strike", "default_setting": True, "image": "\N{BOWLING}", "case_str": "Strike", } _ = Translator(":blobducklurk:", __file__) class Strikes(commands.Cog):