Example #1
0
def convert_tags(bot, guild):
    if not data.get(bot, 'tags.py', 'tags', guild_id=guild.id):
        logger.warn("Guild %s (%s) already had tags converted", guild.name, guild.id)
        return

    tags = data.get(bot, 'tags.py', 'tags', guild_id=guild.id, default={})
    add_tag = bot.plugins['tags.py']._add_tag
    #key,value,length,volume,name,flags,author,hits,created,last_used,last_used_by,complex,extra
    for key, tag in tags.items():
        to_insert = [
            key,                        # key
            tag['value'],               # value
            tag['length'],              # length
            tag['volume'],              # volume
            tag['name'],                # name
            tag['flags'],               # flags
            int(tag['author']),         # author
            tag['hits'],                # hits
            int(tag['created']),        # created
            int(tag['last_used']),      # last_used
            None,                       # last_used_by
            {},                         # complex
            {}                          # extra
        ]
        add_tag(bot, to_insert, guild.id)
    data.remove(bot, 'tags.py', 'tags', guild_id=guild.id, safe=True)
Example #2
0
async def commission_configure(bot, context):
    """Configures the channel and cooldown for the commission channel rules."""
    rules = data.get(bot,
                     __name__,
                     'rules',
                     guild_id=context.guild.id,
                     default={})
    default_cooldown = configurations.get(bot, __name__, 'default_cooldown')
    replace_channel = context.options.get('channel', rules.get('channel'))
    replace_cooldown = context.options.get(
        'cooldown', rules.get('cooldown', default_cooldown))
    if not replace_channel:
        raise CBException("No commission channel configured.")

    # Reset advertisement data
    rules = {'channel': replace_channel, 'cooldown': replace_cooldown}
    data.add(bot, __name__, 'rules', rules, guild_id=context.guild.id)
    data.remove(bot,
                __name__,
                'advertisements',
                guild_id=context.guild.id,
                volatile=True,
                safe=True)
    await _get_advertisement_data(bot, context.guild)

    description = 'Channel: {0.mention}\nCooldown: {1}'.format(
        data.get_channel(bot, replace_channel),
        utilities.get_time_string(replace_cooldown, text=True, full=True))
    embed = discord.Embed(title='Commission channel configuration:',
                          description=description)
    return Response(embed=embed)
Example #3
0
def convert_core(bot, guild):
    if data.get(bot, 'core', None, guild_id=guild.id):
        logger.warn("Guild %s (%s) already had core converted", guild.name,
                    guild.id)
        return
    base_data = data.get(bot, 'base', None, guild_id=guild.id, default={})
    if 'disabled' in base_data:
        # TODO: Iterate through toggled commands
        pass
    if 'blocked' in base_data:
        replacement = []
        for entry in base_data['blocked']:
            replacement.append(int(entry))
        base_data['blocked'] = replacement
    if 'muted_channels' in base_data:
        replacement = []
        for entry in base_data['muted_channels']:
            replacement.append(int(entry))
        base_data['muted_channels'] = replacement
    if 'moderators' in base_data:
        del base_data['moderators']
    if base_data:
        for key, value in base_data.items():
            data.add(bot, 'core', key, value, guild_id=guild.id)
        data.remove(bot, 'base', None, guild_id=guild.id)
Example #4
0
async def translate_default(bot, context):
    """Sets the default translation language."""
    language = context.arguments[0]
    if language:
        data.add(bot, __name__, 'default', language, guild_id=context.guild.id)
    else:
        data.remove(bot, __name__, 'default', guild_id=context.guild.id)
    return Response(
        content='Default language set to {}.'.format(language if language else 'English'))
Example #5
0
async def _clear_webhook(bot, webhook_id):
    """Clears the webhook from volatile data."""
    logger.debug("Removing webhook: %s", webhook_id)
    utilities.remove_schedule_entries(bot, __name__, search=str(webhook_id))
    owner = data.remove(bot, __name__, 'owner', user_id=webhook_id, safe=True, volatile=True)
    data.remove(bot, __name__, 'stage', user_id=webhook_id, safe=True, volatile=True)
    if not owner:
        return False
    webhook = data.remove(bot, __name__, 'tracker', user_id=owner.id, volatile=True)
    try:
        await webhook.delete()
        return True
    except Exception as e:
        logger.warn("Failed to delete webhook after data checking failure.")
        return False
Example #6
0
def convert_core(bot, guild):
    if data.get(bot, 'core', None, guild_id=guild.id):
        logger.warn("Guild %s (%s) already had core converted", guild.name, guild.id)
        return
    base_data = data.get(bot, 'base', None, guild_id=guild.id, default={})
    if 'disabled' in base_data:
        # TODO: Iterate through toggled commands
        pass
    if 'blocked' in base_data:
        replacement = []
        for entry in base_data['blocked']:
            replacement.append(int(entry))
        base_data['blocked'] = replacement
    if 'muted_channels' in base_data:
        replacement = []
        for entry in base_data['muted_channels']:
            replacement.append(int(entry))
        base_data['muted_channels'] = replacement
    if 'moderators' in base_data:
        del base_data['moderators']
    if base_data:
        for key, value in base_data.items():
            data.add(bot, 'core', key, value, guild_id=guild.id)
        data.remove(bot, 'base', None, guild_id=guild.id)
Example #7
0
async def _delete_session(bot, guild):
    """Deletes the session for the given guild."""
    session_data = data.remove(bot, __name__, 'data', guild_id=guild.id, safe=True)
    if not session_data:
        raise CBException("Session does not exist.")
    channel_id, webhook_id = session_data['channel'], session_data['webhook']
    channel = data.get_channel(bot, channel_id, safe=True)
    webhooks = await channel.webhooks()
    for webhook in webhooks:
        if webhook.id == webhook_id:
            await webhook.delete()
            break
    else:
        logger.warn('Webhook to delete (%s) not found!', webhook_id)
    try:
        WEBHOOK_SET.remove(webhook_id)
    except KeyError:
        logger.warn("Webhook not found in WEBHOOK_SET")
    data.list_data_remove(bot, __name__, 'webhooks', value=webhook_id, safe=True)

    if guild.voice_client and guild.voice_client.channel.id == session_data['voice_channel']:
        await utilities.stop_audio(bot, guild)