<commit_before>import re
import os

from discord import game

from disco import bot, constants, redis_client


@bot.command(pass_context=True)
async def join(ctx):
    if ctx.message.author.voice_channel is None:
        return
    if bot.voice is not None:
        await bot.voice.disconnect()
    await bot.join_voice_channel(ctx.message.author.voice_channel)


@bot.command()
async def play(uri: str):
    if not bot.is_voice_connected():
        return

    after = lambda: bot.loop.create_task(bot.change_status(game=game.Game()))

    # TODO: Use regular expressions when validating each URL.
    if 'spotify' in uri:
        bot.service = constants.SPOTIFY_SERVICE
        return

    match = re.match(constants.RE_YOUTUBE_URI, uri)
    if match is not None:
        player = await bot.voice.create_ytdl_player(uri, after=after)
        if bot.play(player):
            await bot.change_status(game=game.Game(name=bot.player.title))

        return

    match = re.match(constants.RE_SOUNDCLOUD_URI, uri)
    if match is not None:
        player = bot.create_soundcloud_player(uri, after=after)
        if bot.play(player):
            await bot.change_status(game=game.Game(name=bot.player.title))

        return

    match = re.match(constants.RE_ATTACHMENT_URI, uri)
    if match is not None:
        discriminator = match.group(1)
        filename = match.group(2)

        path = os.path.join('attachments', discriminator, filename)
        if not os.path.exists(path):
            await bot.say('That attachment does not exist!')
            return

        player = bot.voice.create_ffmpeg_player(path, after=after)
        if bot.play(player):
            await bot.change_status(game=game.Game(name=filename))

        return

    await bot.say('Invalid URI.')


@bot.command()
async def stop():
    if not bot.is_voice_connected():
        return
    if bot.player is not None:
        bot.player.stop()


@bot.command()
async def pause():
    if not bot.is_voice_connected():
        return
    if bot.player is not None:
        bot.player.pause()


@bot.command()
async def resume():
    if not bot.is_voice_connected():
        return
    if bot.player is not None:
        bot.player.resume()


@bot.command(pass_context=True)
async def aliases(ctx):
    aliases = {}
    for alias in redis_client.smembers('aliases'):
        alias = alias.decode('utf-8')
        key = 'aliases:' + alias
        if redis_client.hget(key, 'discriminator') != \
                ctx.message.author.discriminator.encode('utf-8'):
            continue
        aliases[alias] = redis_client.hget(key, 'uri').decode('utf-8')

    if not aliases:
        await bot.say('No aliases found.')
    else:
        quote = ''
        for key, value in aliases.items():
            quote += '%s: %s\n' % (key, value)
        await bot.say(quote.rstrip())


@bot.command(pass_context=True)
async def bind(ctx, alias: str, uri: str):
    if alias.encode('utf-8') in redis_client.smembers('aliases'):
        await bot.say('That alias is already taken!')
        return

    redis_client.sadd('aliases', alias)
    redis_client.hmset(
        'aliases:' + alias,
        {'discriminator': ctx.message.author.discriminator, 'uri': uri})
    await bot.say('Done! The alias %s may now be used.' % alias)


@bot.command(pass_context=True)<commit_msg>disco: Make rules against some aliases<commit_after>import re
import os

from discord import game

from disco import bot, constants, redis_client


@bot.command(pass_context=True)
async def join(ctx):
    if ctx.message.author.voice_channel is None:
        return
    if bot.voice is not None:
        await bot.voice.disconnect()
    await bot.join_voice_channel(ctx.message.author.voice_channel)


@bot.command()
async def play(uri: str):
    if not bot.is_voice_connected():
        return

    after = lambda: bot.loop.create_task(bot.change_status(game=game.Game()))

    # TODO: Use regular expressions when validating each URL.
    if 'spotify' in uri:
        bot.service = constants.SPOTIFY_SERVICE
        return

    match = re.match(constants.RE_YOUTUBE_URI, uri)
    if match is not None:
        player = await bot.voice.create_ytdl_player(uri, after=after)
        if bot.play(player):
            await bot.change_status(game=game.Game(name=bot.player.title))

        return

    match = re.match(constants.RE_SOUNDCLOUD_URI, uri)
    if match is not None:
        player = bot.create_soundcloud_player(uri, after=after)
        if bot.play(player):
            await bot.change_status(game=game.Game(name=bot.player.title))

        return

    match = re.match(constants.RE_ATTACHMENT_URI, uri)
    if match is not None:
        discriminator = match.group(1)
        filename = match.group(2)

        path = os.path.join('attachments', discriminator, filename)
        if not os.path.exists(path):
            await bot.say('That attachment does not exist!')
            return

        player = bot.voice.create_ffmpeg_player(path, after=after)
        if bot.play(player):
            await bot.change_status(game=game.Game(name=filename))

        return

    await bot.say('Invalid URI.')


@bot.command()
async def stop():
    if not bot.is_voice_connected():
        return
    if bot.player is not None:
        bot.player.stop()


@bot.command()
async def pause():
    if not bot.is_voice_connected():
        return
    if bot.player is not None:
        bot.player.pause()


@bot.command()
async def resume():
    if not bot.is_voice_connected():
        return
    if bot.player is not None:
        bot.player.resume()


@bot.command(pass_context=True)
async def aliases(ctx):
    aliases = {}
    for alias in redis_client.smembers('aliases'):
        alias = alias.decode('utf-8')
        key = 'aliases:' + alias
        if redis_client.hget(key, 'discriminator') != \
                ctx.message.author.discriminator.encode('utf-8'):
            continue
        aliases[alias] = redis_client.hget(key, 'uri').decode('utf-8')

    if not aliases:
        await bot.say('No aliases found.')
    else:
        quote = ''
        for key, value in aliases.items():
            quote += '%s: %s\n' % (key, value)
        await bot.say(quote.rstrip())


@bot.command(pass_context=True)
async def bind(ctx, alias: str, uri: str):
    if not alias or ' ' in alias or alias.startswith('<@'):
        await bot.say('Invalid alias.')
        return

    if alias.encode('utf-8') in redis_client.smembers('aliases'):
        await bot.say('That alias is already taken!')
        return

    redis_client.sadd('aliases', alias)
    redis_client.hmset(
        'aliases:' + alias,
        {'discriminator': ctx.message.author.discriminator, 'uri': uri})
    await bot.say('Done! The alias %s may now be used.' % alias)


@bot.command(pass_context=True)
{'fraction_non_alphanumeric': 0.11874357845295758, 'fraction_numerical': 0.0017613386173491853, 'mean_word_length': 2.6555793991416308, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1827330', 'n_tokens_mistral': 2165, 'n_tokens_neox': 2153, 'n_words': 522}