def __init__(self, bot: Red): super().__init__() self.config = Config.get_conf(self, identifier=5757575755) self.config.register_guild(**self.default_guild) self.config.register_member(**self.default_member) self.bot = bot self.registration_task = self.bot.loop.create_task( self.register_warningtype())
def __init__(self, bot): super().__init__() self.bot = bot self.key = 414589031223512 self.config = Config.get_conf(self, self.key) self.config.register_guild(commands={}) self.commandobj = CommandObj(config=self.config, bot=self.bot) self.cooldowns = {}
def __init__(self, bot): super().__init__() self.bot = bot self.config = Config.get_conf(self, identifier=2652104208, force_registration=True) self.config.register_global(**self.default_global) self.session = aiohttp.ClientSession() self.imgur_base_url = "https://api.imgur.com/3/"
def __init__(self, bot: Red): super().__init__() self.bot = bot self.config = Config.get_conf(self, 78631113035100160, force_registration=True) self.config.register_guild(**self.default_guild_settings) self.config.init_custom("REPORT", 2) self.config.register_custom("REPORT", **self.default_report) self.antispam = {} self.user_cache = [] self.tunnel_store = {}
def __init__(self, bot: Red): super().__init__() self.bot = bot self.config = Config.get_conf(self, 1256844281) self.config.register_guild(**self.default_guild_settings) self.config.register_global(**self.default_global_settings) self.config.register_member(**self.default_member_settings) self.config.register_user(**self.default_user_settings) self.config.register_role(**self.default_role_settings) self.slot_register = defaultdict(dict)
def __init__(self, bot: Red): super().__init__() self.bot = bot self.config = Config.get_conf(self, 8927348724) self.config.register_global(entries=[], handled_string_creator=False) self.config.register_guild(entries=[]) self._aliases: AliasCache = AliasCache(config=self.config, cache_enabled=True) self._ready_event = asyncio.Event()
def config_fr(driver): """ Mocked config object with force_register enabled. """ config_module._config_cache = weakref.WeakValueDictionary() conf = Config( cog_name="PyTest", unique_identifier=driver.unique_cog_identifier, driver=driver, force_registration=True, ) yield conf
async def warning_points_remove_check( config: Config, ctx: commands.Context, user: discord.Member, points: int ): 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["drop_command"] is not None: # some action needs to be taken await create_and_invoke_context(ctx, act["drop_command"], user)
def __init__(self): self.config = Config.get_conf(self, 8237492837454039, force_registration=True) self.config.register_global(serverlocked=False, schema_version=0) self.config.register_guild( announce_channel=None, # Integer ID selfroles=[], # List of integer ID's ) self.__current_announcer = None self._ready = asyncio.Event() asyncio.create_task(self.handle_migrations())
def __init__(self, bot: Red): super().__init__() self.bot = bot self.config = 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} default_channel_settings = {"filter": []} self.config.register_guild(**default_guild_settings) self.config.register_member(**default_member_settings) self.config.register_channel(**default_channel_settings) self.pattern_cache = {}
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: # Actions are sorted in decreasing order of points. # The first action we find where the user is above the threshold will be the # highest action we can take. if points >= a["points"]: act = a 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)
def __init__(self, bot: Red): super().__init__() self.bot = bot self.config = Config.get_conf(self, 4961522000, force_registration=True) self.config.register_global(**self.default_global_settings) self.config.register_guild(**self.default_guild_settings) self.config.register_channel(**self.default_channel_settings) self.config.register_member(**self.default_member_settings) self.config.register_user(**self.default_user_settings) self.cache: dict = {} self.tban_expiry_task = self.bot.loop.create_task( self.check_tempban_expirations()) self.last_case: dict = defaultdict(dict) self._ready = asyncio.Event()
def __init__(self): super().__init__() self.trivia_sessions = [] self.config = Config.get_conf(self, identifier=UNIQUE_ID, force_registration=True) self.config.register_guild( max_score=10, timeout=120.0, delay=15.0, bot_plays=False, reveal_answer=True, payout_multiplier=0.0, allow_override=True, ) self.config.register_member(wins=0, games=0, total_score=0)
def __init__(self, bot: Red): super().__init__() self.config: Config = Config.get_conf(self, 26262626) self.ttv_bearer_cache: dict = {} self.config.register_global(**self.global_defaults) self.config.register_guild(**self.guild_defaults) self.config.register_role(**self.role_defaults) self.bot: Red = bot self.streams: List[Stream] = [] self.task: Optional[asyncio.Task] = None self.yt_cid_pattern = re.compile("^UC[-_A-Za-z0-9]{21}[AQgw]$") self._ready_event: asyncio.Event = asyncio.Event() self._init_task: asyncio.Task = self.bot.loop.create_task( self.initialize())
def config(driver): config_module._config_cache = weakref.WeakValueDictionary() conf = Config(cog_name="PyTest", unique_identifier=driver.unique_cog_identifier, driver=driver) yield conf
async def _init(bot: Red): global _config global _bot_ref _bot_ref = bot _config = Config.get_conf(None, 1354799444, cog_name="ModLog") _config.register_global(schema_version=1) _config.register_guild(mod_log=None, casetypes={}, latest_case_number=0) _config.init_custom(_CASETYPES, 1) _config.init_custom(_CASES, 2) _config.register_custom(_CASETYPES) _config.register_custom(_CASES) await _migrate_config(from_version=await _config.schema_version(), to_version=_SCHEMA_VERSION) await register_casetypes(all_generics) async def on_member_ban(guild: discord.Guild, member: discord.Member): if not guild.me.guild_permissions.view_audit_log: return try: await get_modlog_channel(guild) except RuntimeError: return # No modlog channel so no point in continuing when = datetime.utcnow() before = when + timedelta(minutes=1) after = when - timedelta(minutes=1) await asyncio.sleep(10) # prevent small delays from causing a 5 minute delay on entry attempts = 0 # wait up to an hour to find a matching case while attempts < 12 and guild.me.guild_permissions.view_audit_log: attempts += 1 try: entry = await guild.audit_logs( action=discord.AuditLogAction.ban, before=before, after=after ).find(lambda e: e.target.id == member.id and after < e.created_at < before) except discord.Forbidden: break except discord.HTTPException: pass else: if entry: if entry.user.id != guild.me.id: # Don't create modlog entires for the bot's own bans, cogs do this. mod, reason = entry.user, entry.reason date = entry.created_at.replace(tzinfo=timezone.utc) await create_case(_bot_ref, guild, date, "ban", member, mod, reason) return await asyncio.sleep(300) async def on_member_unban(guild: discord.Guild, user: discord.User): if not guild.me.guild_permissions.view_audit_log: return try: await get_modlog_channel(guild) except RuntimeError: return # No modlog channel so no point in continuing when = datetime.utcnow() before = when + timedelta(minutes=1) after = when - timedelta(minutes=1) await asyncio.sleep(10) # prevent small delays from causing a 5 minute delay on entry attempts = 0 # wait up to an hour to find a matching case while attempts < 12 and guild.me.guild_permissions.view_audit_log: attempts += 1 try: entry = await guild.audit_logs( action=discord.AuditLogAction.unban, before=before, after=after ).find(lambda e: e.target.id == user.id and after < e.created_at < before) except discord.Forbidden: break except discord.HTTPException: pass else: if entry: if entry.user.id != guild.me.id: # Don't create modlog entires for the bot's own unbans, cogs do this. mod, reason = entry.user, entry.reason date = entry.created_at.replace(tzinfo=timezone.utc) await create_case(_bot_ref, guild, date, "unban", user, mod, reason) return await asyncio.sleep(300) bot.add_listener(on_member_ban) bot.add_listener(on_member_unban)
def __init__(self) -> None: self._repos: Dict[str, Repo] = {} self.config = Config.get_conf(self, identifier=170708480, force_registration=True) self.config.register_global(repos={})
def __init__(self, bot: Red): super().__init__() self.bot = bot self.config = Config.get_conf(self, 2711759130, force_registration=True) self.api_interface = None self.player_manager = None self.playlist_api = None self.local_folder_current_path = None self.db_conn = None self._error_counter = Counter() self._error_timer = {} self._disconnected_players = {} self._daily_playlist_cache = {} self._daily_global_playlist_cache = {} self._persist_queue_cache = {} self._dj_status_cache = {} self._dj_role_cache = {} self.skip_votes = {} self.play_lock = {} self.lavalink_connect_task = None self._restore_task = None self.player_automated_timer_task = None self.cog_cleaned_up = False self.lavalink_connection_aborted = False self.permission_cache = discord.Permissions( embed_links=True, read_messages=True, send_messages=True, read_message_history=True, add_reactions=True, ) self.session = aiohttp.ClientSession(json_serialize=json.dumps) self.cog_ready_event = asyncio.Event() self.cog_init_task = None self.global_api_user = { "fetched": False, "can_read": False, "can_post": False, "can_delete": False, } self._ll_guild_updates = set() self._last_ll_update = datetime.datetime.now(datetime.timezone.utc) default_global = dict( schema_version=1, owner_notification=0, cache_level=0, cache_age=365, daily_playlists=False, global_db_enabled=False, global_db_get_timeout=5, status=False, use_external_lavalink=False, restrict=True, localpath=str(cog_data_path(raw_name="Audio")), url_keyword_blacklist=[], url_keyword_whitelist=[], java_exc_path="java", **self._default_lavalink_settings, ) default_guild = dict( auto_play=False, auto_deafen=True, autoplaylist={ "enabled": False, "id": None, "name": None, "scope": None }, persist_queue=True, disconnect=False, dj_enabled=False, dj_role=None, daily_playlists=False, emptydc_enabled=False, emptydc_timer=0, emptypause_enabled=False, emptypause_timer=0, jukebox=False, jukebox_price=0, maxlength=0, notify=False, prefer_lyrics=False, repeat=False, shuffle=False, shuffle_bumped=True, thumbnail=False, volume=100, vote_enabled=False, vote_percent=0, room_lock=None, url_keyword_blacklist=[], url_keyword_whitelist=[], country_code="US", ) _playlist: Mapping = dict(id=None, author=None, name=None, playlist_url=None, tracks=[]) self.config.init_custom("EQUALIZER", 1) self.config.register_custom("EQUALIZER", eq_bands=[], eq_presets={}) self.config.init_custom(PlaylistScope.GLOBAL.value, 1) self.config.register_custom(PlaylistScope.GLOBAL.value, **_playlist) self.config.init_custom(PlaylistScope.GUILD.value, 2) self.config.register_custom(PlaylistScope.GUILD.value, **_playlist) self.config.init_custom(PlaylistScope.USER.value, 2) self.config.register_custom(PlaylistScope.USER.value, **_playlist) self.config.register_guild(**default_guild) self.config.register_global(**default_global) self.config.register_user(country_code=None)