Пример #1
0
 def from_message(cls, message):
     for field in message.embeds[0].fields:
         if field.name in get_all_text('channel'):
             channel_id = field.value[2:-1]  # removes mention
             room_data = cls.find_one(channel_id=channel_id)
             if room_data:
                 return cls.from_query(room_data)
Пример #2
0
async def set_permissions(c, grant):
    perms = ['read_messages', 'send_messages', 'connect', 'speak']
    (perm_args, target_args) = pop_flags(c.args)
    perm_dict = {}
    for (i, perm_arg) in enumerate(perm_args):
        for perm in perms:
            if perm_arg in get_all_text(perm):
                perm_dict[perm] = re.split('[,\s]+', target_args[i])
                break
    if not perm_dict:
        return await c.ctx.send(c.settings.get_text('require_flags'))
    overwrites = {}
    for (perm, target_args) in perm_dict.items():
        for t in target_args:
            target = get_target(c.ctx.guild, t)
            if target:
                if target in overwrites:
                    overwrites[target].update(**{perm:grant})
                else:
                    overwrites[target] = discord.PermissionOverwrite(**{perm:True})
    await c.channel.edit(overwrites=overwrites)
    if c.voice_channel:
        await c.voice_channel.edit(overwrites=overwrites)
    await c.ctx.send(c.settings.get_text('updated_field').format(
        c.settings.get_text('permissions'),
        c.ctx.author.display_name,
        c.room.activity
    ))
Пример #3
0
def get_color(color, return_default=True):
    hex_match = re.search('[0-9a-fA-F]{6}', color)
    if hex_match and hex_match.group():
        return discord.Color(int(hex_match.group(), 16))
    elif color in get_all_text('red'):
        return discord.Color.red()
    elif color in get_all_text('orange'):
        return discord.Color.orange()
    elif color in get_all_text('yellow'):
        return discord.Color.gold()
    elif color in get_all_text('green'):
        return discord.Color.green()
    elif color in get_all_text('teal'):
        return discord.Color.teal()
    elif color in get_all_text('blue'):
        return discord.Color.blue()
    elif color in get_all_text('purple'):
        return discord.Color.purple()
    elif color in get_all_text('pink'):
        return discord.Color.magenta()
    elif return_default:
        return discord.Color(some_color())
    else:
        return None