예제 #1
0
async def init_channel_dbs(client):
    conn = client.bot.dbs[client.server_tag]
    db.add_column(conn, 'channels', 'disabled')
    db.add_column(conn, 'channels', 'ban')
    db.add_column(conn, 'channels', 'op')
    db.add_column(conn, 'channels', 'hop')
    db.add_column(conn, 'channels', 'vop')
예제 #2
0
async def flood_input_sieve(client, data):
    #Is for handling users who are flooding in the channel.
    conn = client.bot.dbs[data.server]
    isadmin = await user.is_admin(client, conn, data.nickname, data.mask)

    if await user.is_gadmin(client, data.server, data.mask):
        return data
    if isadmin or not data.target:
        return data
    if data.target[0] != '#':
        return data

    db.add_column(conn, 'channels', 'msgflood')
    db.add_column(conn, 'channels', 'cmdflood')
    prefix = db.get_cell(conn, 'channels', 'commandprefix', 'channel',
                         data.target)[0][0]
    msgflood = db.get_cell(conn, 'channels', 'msgflood', 'channel',
                           data.target)[0][0]
    cmdflood = db.get_cell(conn, 'channels', 'cmdflood', 'channel',
                           data.target)[0][0]
    if msgflood:
        msgflood = msgflood.split()
        asyncio.create_task(_detect_flood(client, data, msgflood, 'msg'))
    if cmdflood and data.command and prefix:
        if data.command[0] == prefix:
            if cmdflood:
                cmdflood = cmdflood.split()
                asyncio.create_task(
                    _detect_flood(client, data, cmdflood, 'cmd'))
    return data
예제 #3
0
async def lfminit(client):
    """Is used for initializing the database for this plugin"""
    conn = client.bot.dbs[client.server_tag]
    print(('Initializing lastfm column in \'users\''
           f' in /persist/db/{client.server_tag}.db...'))
    db.add_column(conn, 'users', 'lastfm')
    db.ccache()
    print('Last.fm initialization complete.')
예제 #4
0
async def location_init(client):
    """Save a user's location to be used for localized weather info"""
    conn = client.bot.dbs[client.server_tag]
    print(('Initializing location column in \'users\''
           f' in /persist/db/{client.server_tag}.db...'))
    db.add_column(conn, 'users', location_column)
    db.ccache()
    print('Location initialization complete.')
예제 #5
0
async def introinit(client):
    """Is used for initializing the database for this plugin"""
    conn = client.bot.dbs[client.server_tag]
    print(('Initializing intro column in \'users\''
           f' in /persist/db/{client.server_tag}.db...'))
    db.add_column(conn, 'users', intro_name)
    db.ccache()
    print('User intro initialization complete.')
예제 #6
0
async def statinit(client):
    """Is used for initializing the database for this plugin"""
    conn = client.bot.dbs[client.server_tag]
    print(('Initializing stat columns in \'users\''
           f' in /persist/db/{client.server_tag}.db...'))
    for attr in usr_attributes:
        db.add_column(conn, 'users', attr)
    db.ccache()
    print('User stat initialization complete.')
예제 #7
0
async def is_ignored(client: Any, conn: Connection, target: str,
                     mask: str) -> bool:
    """Is used to check if a mask is ignored in a channel."""
    db.add_column(conn, 'channels', 'ignored')
    ignores = db.get_cell(conn, 'channels', 'ignored', 'channel', target)
    if ignores:
        nignores: Optional[str] = ignores[0][0]
        if nignores:
            if mask in nignores:
                return True
    return False
예제 #8
0
async def is_admin(client: Any, conn: Connection, nick: str,
                   mask: str) -> bool:
    """Is used to check if a mask is an admin in the channel."""
    db.add_column(conn, 'channels', 'admins')
    admins = db.get_cell(conn, 'channels', 'admins', 'channel', nick)
    if admins:
        nadmins: Optional[str] = admins[0][0]
        if nadmins:
            if mask in nadmins.split():
                return True
    return False
예제 #9
0
async def badwords_input_sieve(client, data):
    """Is used to return block inputs from users using bad words."""
    admin = await user.is_admin(client, client.bot.dbs[data.server],
                                data.nickname, data.mask)
    gadmin = await user.is_gadmin(client, data.server, data.mask)
    db.add_column(client.bot.dbs[data.server], 'channels', 'kickwords')
    db.add_column(client.bot.dbs[data.server], 'channels', 'banwords')

    if not data.target or data.target[0] != '#' or gadmin or admin:
        return data

    db_prefix = db.get_cell(client.bot.dbs[data.server], 'channels',
                            'commandprefix', 'channel', data.target)[0][0]
    if data.command[0] != db_prefix:
        return data

    kickwords = db.get_cell(client.bot.dbs[data.server], 'channels',
                            'kickwords', 'channel', data.target)
    banwords = db.get_cell(client.bot.dbs[data.server], 'channels', 'banwords',
                           'channel', data.target)
    if kickwords:
        kickwords = kickwords[0][0]
        for word in kickwords.split(' '):
            if word in data.message:
                asyncio.create_task(
                    client.notice(data.nickname, (f'I cannot say {word} in'
                                                  f'{data.target}')))
    if banwords:
        banwords = banwords[0][0]
        for word in banwords.split(' '):
            word = ' '.join(word.split(':')[0:-1])
            if word in data.message:
                asyncio.create_task(
                    client.notice(data.nickname, (f'I cannot say {word} in'
                                                  f'{data.target}')))
    return data