Exemplo n.º 1
0
import discord

from botbase.core import checks, modlog, commands
from botbase.core.bot import Red
from botbase.core.i18n import Translator, cog_i18n
from botbase.core.utils.chat_formatting import box

_ = Translator("ModLog", __file__)


@cog_i18n(_)
class ModLog:
    """Log for mod actions"""
    def __init__(self, bot: Red):
        self.bot = bot

    @commands.group()
    @checks.guildowner_or_permissions(administrator=True)
    async def modlogset(self, ctx: commands.Context):
        """Settings for the mod log"""
        pass

    @modlogset.command()
    @commands.guild_only()
    async def modlog(self,
                     ctx: commands.Context,
                     channel: discord.TextChannel = None):
        """Sets a channel as mod log

        Leaving the channel parameter empty will deactivate it"""
        guild = ctx.guild
Exemplo n.º 2
0
import discord

from botbase.core import checks, Config, modlog, commands
from botbase.core.bot import Red
from botbase.core.i18n import Translator, cog_i18n
from botbase.core.utils.chat_formatting import pagify
from botbase.core.utils.mod import is_mod_or_superior

_ = Translator("Filter", __file__)


@cog_i18n(_)
class Filter:
    """Filter-related commands"""

    def __init__(self, bot: Red):
        self.bot = bot
        self.settings = Config.get_conf(self, 4766951341)
        default_guild_settings = {
            "filter": [],
            "filterban_count": 0,
            "filterban_time": 0,
            "filter_names": False,
            "filter_default_name": "John Doe",
        }
        default_member_settings = {"filter_count": 0, "next_reset_time": 0}
        self.settings.register_guild(**default_guild_settings)
        self.settings.register_member(**default_member_settings)
        self.register_task = self.bot.loop.create_task(self.register_filterban())

    def __unload(self):
Exemplo n.º 3
0
    APIError,
    InvalidYoutubeCredentials,
    CommunityNotFound,
    OfflineCommunity,
    StreamsError,
    InvalidTwitchCredentials,
)
from . import streamtypes as StreamClasses
from collections import defaultdict
import asyncio
import re
from typing import Optional, List

CHECK_DELAY = 60

_ = Translator("Streams", __file__)


@cog_i18n(_)
class Streams:

    global_defaults = {"tokens": {}, "streams": [], "communities": []}

    guild_defaults = {
        "autodelete": False,
        "mention_everyone": False,
        "mention_here": False
    }

    role_defaults = {"mention": False}
Exemplo n.º 4
0
import logging
import random
from collections import defaultdict, deque
from enum import Enum

import discord

from botbase.cogs.bank import check_global_setting_guildowner, check_global_setting_admin
from botbase.core import Config, bank, commands
from botbase.core.i18n import Translator, cog_i18n
from botbase.core.utils.chat_formatting import box
from botbase.core.utils.menus import menu, DEFAULT_CONTROLS

from botbase.core.bot import Red

_ = Translator("Economy", __file__)

logger = logging.getLogger("red.economy")

NUM_ENC = "\N{COMBINING ENCLOSING KEYCAP}"


class SMReel(Enum):
    cherries = "\N{CHERRIES}"
    cookie = "\N{COOKIE}"
    two = "\N{DIGIT TWO}" + NUM_ENC
    flc = "\N{FOUR LEAF CLOVER}"
    cyclone = "\N{CYCLONE}"
    sunflower = "\N{SUNFLOWER}"
    six = "\N{DIGIT SIX}" + NUM_ENC
    mushroom = "\N{MUSHROOM}"
Exemplo n.º 5
0
from copy import copy
import asyncio
import inspect
import discord

from botbase.core import Config, checks, commands
from botbase.core.i18n import Translator

_ = Translator("Warnings", __file__)


async def warning_points_add_check(
    config: Config, ctx: commands.Context, user: discord.Member, points: int
):
    """Handles any action that needs to be taken or not based on the points"""
    guild = ctx.guild
    guild_settings = config.guild(guild)
    act = {}
    async with guild_settings.actions() as registered_actions:
        for a in registered_actions:
            if points >= a["points"]:
                act = a
            else:
                break
    if act and act["exceed_command"] is not None:  # some action needs to be taken
        await create_and_invoke_context(ctx, act["exceed_command"], user)


async def warning_points_remove_check(
    config: Config, ctx: commands.Context, user: discord.Member, points: int
):
Exemplo n.º 6
0
import discord
from botbase.core.utils.chat_formatting import box

from botbase.core import checks, bank, commands
from botbase.core.i18n import Translator, cog_i18n

from botbase.core.bot import Red  # Only used for type hints

_ = Translator("Bank", __file__)


def check_global_setting_guildowner():
    """
    Command decorator. If the bank is not global, it checks if the author is
     either the guildowner or has the administrator permission.
    """
    async def pred(ctx: commands.Context):
        author = ctx.author
        if not await bank.is_global():
            if not isinstance(ctx.channel, discord.abc.GuildChannel):
                return False
            if await ctx.bot.is_owner(author):
                return True
            permissions = ctx.channel.permissions_for(author)
            return author == ctx.guild.owner or permissions.administrator
        else:
            return await ctx.bot.is_owner(author)

    return commands.check(pred)

Exemplo n.º 7
0
from random import shuffle

import aiohttp

from botbase.core.i18n import Translator, cog_i18n
from botbase.core import checks, Config, commands

_ = Translator("Image", __file__)

GIPHY_API_KEY = "dc6zaTOxFJmzC"


@cog_i18n(_)
class Image:
    """Image related commands."""

    default_global = {"imgur_client_id": None}

    def __init__(self, bot):
        self.bot = bot
        self.settings = Config.get_conf(self,
                                        identifier=2652104208,
                                        force_registration=True)
        self.settings.register_global(**self.default_global)
        self.session = aiohttp.ClientSession()
        self.imgur_base_url = "https://api.imgur.com/3/"

    def __unload(self):
        self.session.detach()

    @commands.group(name="imgur")
Exemplo n.º 8
0
import asyncio
from typing import Union
from datetime import timedelta
from copy import copy
import contextlib
import discord

from botbase.core import Config, checks, commands
from botbase.core.utils.chat_formatting import pagify, box
from botbase.core.utils.antispam import AntiSpam
from botbase.core.bot import Red
from botbase.core.i18n import Translator, cog_i18n
from botbase.core.utils.tunnel import Tunnel


_ = Translator("Reports", __file__)

log = logging.getLogger("red.reports")


@cog_i18n(_)
class Reports:

    default_guild_settings = {"output_channel": None, "active": False, "next_ticket": 1}

    default_report = {"report": {}}

    # This can be made configureable later if it
    # becomes an issue.
    # Intervals should be a list of tuples in the form
    # (period: timedelta, max_frequency: int)
Exemplo n.º 9
0
from botbase.core import Config
from botbase.core import checks
from botbase.core.data_manager import cog_data_path
from botbase.core.i18n import Translator, cog_i18n
from botbase.core.utils.chat_formatting import box, pagify
from botbase.core import commands

from botbase.core.bot import Red
from .checks import do_install_agreement
from .converters import InstalledCog
from .errors import CloningError, ExistingGitRepo
from .installable import Installable
from .log import log
from .repo_manager import RepoManager, Repo

_ = Translator("Downloader", __file__)


@cog_i18n(_)
class Downloader:
    def __init__(self, bot: Red):
        self.bot = bot

        self.conf = Config.get_conf(self,
                                    identifier=998240343,
                                    force_registration=True)

        self.conf.register_global(installed=[])

        self.already_agreed = False
Exemplo n.º 10
0
import datetime
import time
from enum import Enum
from random import randint, choice
from urllib.parse import quote_plus
import aiohttp
import discord
from botbase.core import commands
from botbase.core.i18n import Translator, cog_i18n
from botbase.core.utils.menus import menu, DEFAULT_CONTROLS
from botbase.core.utils.chat_formatting import escape, italics, pagify

_ = Translator("General", __file__)


class RPS(Enum):
    rock = "\N{MOYAI}"
    paper = "\N{PAGE FACING UP}"
    scissors = "\N{BLACK SCISSORS}"


class RPSParser:
    def __init__(self, argument):
        argument = argument.lower()
        if argument == "rock":
            self.choice = RPS.rock
        elif argument == "paper":
            self.choice = RPS.paper
        elif argument == "scissors":
            self.choice = RPS.scissors
        else:
Exemplo n.º 11
0
import discord
from botbase.core import commands
from botbase.core.bot import Red
from botbase.core import checks
from botbase.core.config import Config
from botbase.core.i18n import Translator, cog_i18n
from botbase.core.utils.caching import LRUDict

from .resolvers import val_if_check_is_valid, resolve_models, entries_from_ctx
from .yaml_handler import yamlset_acl, yamlget_acl
from .converters import CogOrCommand, RuleType, ClearableRuleType
from .mass_resolution import mass_resolve

_models = ["owner", "guildowner", "admin", "mod", "all"]

_ = Translator("Permissions", __file__)

REACTS = {"\N{WHITE HEAVY CHECK MARK}": True, "\N{NEGATIVE SQUARED CROSS MARK}": False}
Y_OR_N = {"y": True, "yes": True, "n": False, "no": False}


@cog_i18n(_)
class Permissions:
    """
    A high level permission model
    """

    # Not sure if we will use admin or mod models in core red
    # but they are explicitly supported
    resolution_order = {k: _models[:i] for i, k in enumerate(_models, 1)}
Exemplo n.º 12
0
import re

import discord

from botbase.core import checks, commands
from botbase.core.bot import Red
from botbase.core.i18n import Translator, cog_i18n
from botbase.core.utils.mod import slow_deletion, mass_purge
from botbase.cogs.mod.log import log

_ = Translator("Cleanup", __file__)


@cog_i18n(_)
class Cleanup:
    """Commands for cleaning messages"""

    def __init__(self, bot: Red):
        self.bot = bot

    @staticmethod
    async def check_100_plus(ctx: commands.Context, number: int) -> bool:
        """
        Called when trying to delete more than 100 messages at once.

        Prompts the user to choose whether they want to continue or not.

        Tries its best to cleanup after itself if the response is positive.
        """

        def author_check(message):
Exemplo n.º 13
0
from copy import copy
from re import search
from typing import Generator, Tuple, Iterable

import discord
from botbase.core import Config, commands, checks
from botbase.core.i18n import Translator, cog_i18n
from botbase.core.utils.chat_formatting import box

from botbase.core.bot import Red
from .alias_entry import AliasEntry

_ = Translator("Alias", __file__)


@cog_i18n(_)
class Alias:
    """
    Alias
    
    Aliases are per server shortcuts for commands. They
        can act as both a lambda (storing arguments for repeated use)
        or as simply a shortcut to saying "x y z".
    
    When run, aliases will accept any additional arguments
        and append them to the stored alias
    """

    default_global_settings = {"entries": []}

    default_guild_settings = {
Exemplo n.º 14
0
import os
import re
import random
from datetime import datetime

import discord

from botbase.core import Config, checks, commands
from botbase.core.utils.chat_formatting import box, pagify
from botbase.core.i18n import Translator, cog_i18n

_ = Translator("CustomCommands", __file__)


class CCError(Exception):
    pass


class NotFound(CCError):
    pass


class AlreadyExists(CCError):
    pass


class CommandObj:
    def __init__(self, **kwargs):
        config = kwargs.get("config")
        self.bot = kwargs.get("bot")
        self.db = config.guild
Exemplo n.º 15
0
from pathlib import Path
import asyncio

from botbase.core import checks, commands
from botbase.core.bot import Red
from botbase.core.i18n import Translator, cog_i18n
from botbase.cogs.dataconverter.core_specs import SpecResolver
from botbase.core.utils.chat_formatting import box

_ = Translator("DataConverter", __file__)


@cog_i18n(_)
class DataConverter:
    """
    Cog for importing Red v2 Data
    """
    def __init__(self, bot: Red):
        self.bot = bot

    @checks.is_owner()
    @commands.command(name="convertdata")
    async def dataconversioncommand(self, ctx: commands.Context, v2path: str):
        """
        Interactive prompt for importing data from Red v2

        Takes the path where the v2 install is

        Overwrites values which have entries in both v2 and v3,
        use with caution.
        """