import discord from babel.dates import format_timedelta, format_datetime from redbot.core import checks from redbot.core.utils import deduplicate_iterables from redbot.core.utils.chat_formatting import warning, pagify, error, escape from tzlocal import get_localzone from cog_shared.swift_libs.checks import is_dev from cog_shared.swift_libs.helpers import flatten from misctools import commands from misctools.shared import translate as translate_, log from misctools.toolset import Toolset from swift_i18n import Humanize translate = translate_.group("dev") class Dev(Toolset, i18n=translate): # This command is taken from jishaku: # https://github.com/Gorialis/jishaku/blob/fc7c479/jishaku/cog.py#L346-L359 # noinspection PyProtectedMember @commands.command() @checks.is_owner() @is_dev() @translate.command("help.sudo") async def sudo(self, ctx: commands.Context, *, command: str): alt_message: discord.Message = copy.copy(ctx.message) # pylint:disable=protected-access if discord.version_info >= (1, 2, 0): alt_message._update({"content": ctx.prefix + command})
from math import ceil from typing import Dict, List, Union, Optional import discord from cog_shared.swift_libs.formatting import mention from cog_shared.swift_libs.helpers import chunks from cog_shared.swift_libs.menus import PaginatedMenu from cog_shared.swift_libs.permissions import format_permission from misctools import commands from misctools.shared import translate as translate_ from misctools.toolset import Toolset from swift_i18n import Humanize translate = translate_.group("permbd") perm_channel_types = { discord.TextChannel: ( # read_messages isn't included here as voice channels use it as the view channel permission "add_reactions", "send_messages", "send_tts_messages", "manage_messages", "embed_links", "attach_files", "read_message_history", "mention_everyone", "external_emojis", ), discord.VoiceChannel: ( "connect", "speak",
import aiohttp import discord from redbot.core import checks from redbot.core.utils.chat_formatting import error from cog_shared.swift_libs.helpers import TimeCache, runtime_data from misctools import commands from misctools.shared import translate as translate_, log from misctools.toolset import Toolset from swift_i18n import Humanize BASE_URL = "https://www.xkcd.com" BASE_IMG_URL = "https://imgs.xkcd.com/comics/" EXPLAINXKCD_BASE_URL = "https://www.explainxkcd.com/wiki/index.php" translate = translate_.group("xkcd") preserved_data = runtime_data("MiscTools") if "xkcd" not in preserved_data or isinstance(preserved_data.get("xkcd"), list): preserved_data["xkcd"] = TimeCache(ttl=timedelta(minutes=30)) COMIC_CACHE: MutableMapping[Union[str, int], "Comic"] = preserved_data["xkcd"] class NoComic(Exception): pass class XKCD(Toolset, i18n=translate): @staticmethod async def __build_xkcd_embed(ctx: commands.Context, comic: "Comic"): return ( discord.Embed(
from typing import Optional, Tuple import discord from redbot.core.utils.chat_formatting import escape from cog_shared.swift_libs.formatting import message_link from misctools import commands from misctools.shared import translate as translate_ from misctools.toolset import Toolset translate = translate_.group("messagequote") class CrossGuildMessageConverter(commands.Converter): # noinspection PyRedundantParentheses async def convert( self, ctx: commands.Context, argument: str) -> Tuple[Optional[discord.TextChannel], int]: if argument.isnumeric(): return (None, int(argument)) arg = argument.split("-") if len(arg) != 2 or not all(x.isnumeric() for x in arg): raise commands.BadArgument( translate("invalid_id", mid=escape(argument, mass_mentions=True, formatting=True))) cid, mid = tuple(int(x) for x in arg) channel: discord.TextChannel = ctx.bot.get_channel(cid)
from argparse import Namespace from typing import Sequence from typing import Union, Dict, Optional from redbot.core import checks from redbot.core.utils.chat_formatting import escape, pagify from redbot.core.utils.chat_formatting import warning, info from cog_shared.swift_libs.formatting import tick from cog_shared.swift_libs.helpers import DefaultDict from cog_shared.swift_libs.menus import Menu, action from misctools import commands from misctools.shared import Arguments, log, translate as translate_ from misctools.toolset import Toolset translate = translate_.group("maintenance") manager: Optional[MaintenanceManager] = None # pylint:disable=used-before-assignment class MaintenanceEnabled(commands.CheckFailure): pass class MaintenanceManager: __slots__ = ("_bot", "cogs") def __init__(self): self._bot = False self.cogs: Dict[str, Union[bool, str]] = DefaultDict(False) @property
from typing import Union, Optional import discord from babel.lists import format_list from redbot.core import checks from redbot.core.utils.chat_formatting import escape, bold from redbot.core.utils.common_filters import filter_invites from tzlocal import get_localzone from cog_shared.swift_libs.formatting import mention from misctools import commands from misctools.shared import translate as translate_ from misctools.toolset import Toolset from swift_i18n import Humanize translate = translate_.group("uinfo") DATETIME_FORMAT = "MMM dd, yyyy" class UInfo(Toolset, i18n=translate): async def get_names_and_nicks(self, member: Union[discord.Member, discord.User]): try: mod = self.bot.cogs["Mod"] except KeyError: return [], [] names = await mod.settings.user(member).past_names() nicks = ( await mod.settings.member(member).past_nicks() if isinstance(member, discord.Member) else []
from babel.units import format_unit from redbot.core.bot import Red from misctools import commands from misctools.shared import translate as translate_ from misctools.toolset import Toolset from swift_i18n import Humanize translate = translate_.group("ping") class PingTime(Toolset, i18n=translate): bot: Red conflict_ok = ["ping"] # noinspection PyAttributeOutsideInit def toolset_before_setup(self): # unmentioned breaking changes in a patch release <angry grumbling> self.orig_ping = self.bot.get_command("ping") # pylint:disable=W0201 if self.orig_ping: self.bot.remove_command(self.orig_ping.qualified_name) def toolset_cleanup(self): if self.orig_ping: self.bot.add_command(self.orig_ping) else: self.bot.add_command(self.bot.get_cog("Core").ping) @commands.command(aliases=["pingtime"]) @translate.command("help") async def ping(self, ctx: commands.Context):
import discord from babel.dates import format_timedelta from redbot.core.bot import Red from redbot.core.utils.chat_formatting import bold from misctools import commands from misctools.shared import translate as translate_, log from misctools.toolset import Toolset from cog_shared.swift_libs.setup import get_instance try: import psutil except ImportError: psutil = None translate = translate_.group("stats") class Stats(Toolset, i18n=translate): bot: Red def toolset_before_setup(self): if psutil is None: log.warning( "psutil is not available; the statistics toolset will not display" " host system resource utilization. This can be resolved by" " using `[p]pipinstall psutil` in any channel I can access.") @staticmethod def __sys_info() -> dict: if psutil is None: