async def color(self, ctx, *args): c = await self.get_context(ctx, args) color = get_color(clean_args(args)[0] if clean_args(args) else '') try: await asyncio.wait_for(c.role.edit(color=color), timeout=3.0) except asyncio.TimeoutError: return await ctx.send(c.settings.get_text('rate_limited')) c.room.update('color', color.value) return await ctx.send(c.settings.get_text('updated_field_to').format(c.settings.get_text('color'), color, c.player.display_name, c.room.activity))
async def color(self, ctx, *args): c = self.get_context(ctx, args) color = get_color( remove_mentions(args)[0] if remove_mentions(args) else '') try: await asyncio.wait_for(c.role.edit(color=color), timeout=3.0) except asyncio.TimeoutError: return await ctx.send(c.settings.get_text('rate_limited')) c.room.update('color', color.value) return await ctx.send( c.settings.get_text('updated_field').format( c.settings.get_text('color'), color, c.player.display_name, c.channel.mention))
async def create(cls, member, ctx=None, **flags): player = member guild = member.guild settings = Settings.get_for(guild.id) def flag(key): return cls.unpack_value( flags[key], cls.props[key] ) if key in settings.allowed_host_commands and key in flags and len( flags[key]) > 0 else None if not guild.me.guild_permissions.manage_channels or not guild.me.guild_permissions.manage_roles: raise discord.ext.commands.errors.CommandInvokeError( "Missing Permissons") # check if able to make room if not settings.allow_multiple_rooms and cls.player_is_in_any( player.id, guild.id): if ctx: await ctx.send(settings.get_text('already_in_room')) return # activity (room name) name = player.display_name top = player.top_role.name bottom = player.roles[1].name if len(player.roles) > 1 else top activity = flag('activity') or choice(settings.default_names).format( name, top, bottom) activity = activity[0:90].strip() # color if flag('color'): color = get_color(flag('color')) elif settings.use_role_color and player.top_role.color != discord.Color.default( ): color = player.top_role.color else: color = discord.Color(int(choice(settings.default_colors))) # role role = await guild.create_role(name="({}) {}".format( settings.get_text('room'), activity), color=color, hoist=True, mentionable=True) # overwrites accessors_ids = settings.access_all_rooms_role accessors = [] for accessor_id in accessors_ids: accessor_player = guild.get_member(accessor_id) accessor_role = guild.get_role(accessor_id) if accessor_player: accessors.append(accessor_player) elif accessor_role: accessors.append(accessor_role) if len(accessors) < 1: accessors = list(filter(lambda m: m.bot, guild.members)) overwrites = { guild.default_role: discord.PermissionOverwrite(read_messages=False), guild.me: discord.PermissionOverwrite(read_messages=True, manage_channels=True), role: discord.PermissionOverwrite(read_messages=True) } for accessor in accessors: overwrites[accessor] = discord.PermissionOverwrite( read_messages=True) # channel category = await get_rooms_category(guild, settings) o = category.overwrites o.update(overwrites) overwrites = o channel = await category.create_text_channel(name=activity, position=0, overwrites=overwrites) voice_channel = None if settings.default_voice_channel: voice_channel = await guild.create_voice_channel( name=activity, bitrate=settings.bitrate * 1000, category=category, position=0, overwrites=overwrites) # new room room = Room(role_id=role.id, channel_id=channel.id, voice_channel_id=voice_channel.id if voice_channel else 0, guild=guild.id, birth_channel=ctx.message.channel.id if ctx else 0, host=player.id, players=[player.id], activity=activity, color=color, lock=flag('lock') or settings.default_lock, nsfw=flag('nsfw') or settings.default_nsfw, description=flag('description') or choice(settings.default_descriptions), size=flag('size') or settings.default_size, timeout=flag('timeout') or settings.default_timeout, created=now(), last_active=now()) await player.add_roles(role) await channel.edit(topic="({}/{}) {}".format(len(room.players), room.size, room.description), nsfw=room.nsfw) await channel.send( choice(settings.join_messages).format(player.display_name)) if ctx: await RoomEmbed(ctx, room, 'new_room', settings).send()
def set(self, ctx, field, value): result = (True, None) parsed_value = value if field not in self.defaults.keys(): return (False, self.get_text('require_flags')) default = self.defaults[field] if field in ['voice_creation_channel', 'creation_channel']: parsed_value = 0 channels = ctx.guild.voice_channels for c in channels: if len(value) > 1 and value in c.name or value == str(c.id): parsed_value = c.id elif is_number(default): try: parsed_value = int(value) except ValueError: parsed_value = -1 if field in ['size', 'default_size']: parsed_value = clamp(parsed_value, 2, 999) elif field == 'bitrate': parsed_value = clamp(parsed_value, 8, int(ctx.guild.bitrate_limit/1000)) elif field == 'timeout': parsed_value = clamp(parsed_value, -1, 999) elif isinstance(default, bool): parsed_value = text_to_bool(value) elif isinstance(default, list): if field in ['role_restriction', 'access_all_rooms_role']: roles = [] for word in re.split('[,\s]+', value): try: r = re.search(r'\d+', word) if r: role_id = int(r.group()) roles.append(role_id) except ValueError: result = (False, self.get_text('should_use_mentions')) parsed_value = ids_to_str(roles) elif field == 'default_colors': colors = [] for s in re.split('[,\s]+', value): color = get_color(s, return_default=False) if color: colors.append(str(color.value)) parsed_value = ','.join(colors) elif field == 'allowed_host_commands': commands = [] for c in re.split('[,\s]+', value): if c in default and c not in commands: commands.append(c) if commands == []: commands = default parsed_value = ','.join(commands) else: messages = [] for s in re.split('[,]+', value): m = s.strip().replace('__', '{0}') if len(m) > 0: messages.append(m) parsed_value = ','.join(messages) elif isinstance(default, str): if field == 'prefix': max_char_length = 5 if len(value) > max_char_length: result = (False, self.get_text('prefix_too_long').format(max_char_length)) elif field == 'language': parsed_value = value[:2].lower() if parsed_value not in langs: result = (False, self.get_text('language_not_exist').format(parsed_value)) elif field == 'category_name': parsed_value = value[:99] (success, message) = result if (success): is_string = isinstance(parsed_value, str) text_value = parsed_value if not is_string or (is_string and len(parsed_value) > 0) else 'None' self.update(field, parsed_value) result = (True, self.get_text('set_value').format(field, text_value)) return result