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 size(self, ctx, *args): c = self.get_context(ctx, args) try: new_size = clamp(int(remove_mentions(args)[0]), 2, 999) if remove_mentions(args) else None if len(c.room.players) > new_size: return await ctx.send(c.settings.get_text('size_too_small')) c.room.size = new_size c.room.update('size', new_size) return await ctx.send( c.settings.get_text('updated_field').format( c.settings.get_text('size'), new_size, c.player.display_name, c.channel.mention)) except ValueError: return await ctx.send(c.settings.get_text('need_integer'))
def get_room(cls, ctx, args): settings = Settings.get_for(ctx.guild.id) player = ctx.message.author rooms = Room.get_player_rooms(player.id, ctx.guild.id) room = None if len(rooms) > 1: role_mention_filter = ctx.message.role_mentions[ 0].id if ctx.message.role_mentions and ctx.message.role_mentions[ 0] else None string = ' '.join(args).lower() rx = re.search(r'\((.*?)\)', string) text_filter = rx.group(1) if rx else remove_mentions(string) for r in rooms: match_channel = ctx.channel.id == r.channel_id if ctx.channel else False match_text = text_filter and text_filter in r.activity.lower() match_role = role_mention_filter == r.role_id if match_channel or match_text or match_role: room = r break if not room: return (None, settings.get_text('in_multiple_rooms')) elif len(rooms) == 1: room = rooms[0] else: return (None, settings.get_text('not_in_room')) return (room, None)
async def timeout(self, ctx, *args): c = self.get_context(ctx, args) new_timeout = remove_mentions(args)[0] if remove_mentions( args) else False try: new_timeout = min(int(new_timeout), 999) if (new_timeout < 0): raise ValueError except ValueError: new_timeout = -1 c.room.timeout = new_timeout c.room.update('timeout', new_timeout) return await ctx.send( c.settings.get_text('updated_field').format( c.settings.get_text('timeout'), new_timeout, c.player.display_name, c.channel.mention))
async def lock(self, ctx, *args): c = self.get_context(ctx, args) first_arg = remove_mentions(args)[0] new_lock = text_to_bool( first_arg) if len(first_arg) > 0 else not c.room.lock c.room.update('lock', new_lock) return await ctx.send( c.settings.get_text('lock_room') if new_lock else c.settings. get_text('unlock_room'))
async def description(self, ctx, *args): c = self.get_context(ctx, args) new_description = remove_mentions(' '.join(args)) topic = "({}/{}) {}".format(len(c.room.players), c.room.size, c.room.description) try: await asyncio.wait_for(c.channel.edit(topic=topic), timeout=3.0) except asyncio.TimeoutError: return await ctx.send(c.settings.get_text('rate_limited')) c.room.description = new_description c.room.update('description', new_description) return await ctx.send( c.settings.get_text('updated_field').format( c.settings.get_text('description'), new_description, c.player.display_name, c.channel.mention))
async def activity(self, ctx, *args): c = self.get_context(ctx, args) new_activity = remove_mentions(' '.join(args)) player_name = c.player.display_name if len(new_activity) < 1: new_activity = choice(c.settings.default_names).format(player_name) try: await asyncio.wait_for(c.channel.edit(name=new_activity), timeout=3.0) except asyncio.TimeoutError: return await ctx.send(c.settings.get_text('rate_limited')) await c.role.edit( name="({}) {}".format(c.settings.get_text('room'), new_activity)) if c.voice_channel: await c.voice_channel.edit(name=new_activity) c.room.activity = new_activity c.room.update('activity', new_activity) return await ctx.send( c.settings.get_text('updated_field').format( c.settings.get_text('activity'), new_activity, player_name, c.channel.mention))