Ejemplo n.º 1
0
def setup(bot):
    if not getattr(bot.config, "chanlogs", None):
        raise ConfigurationError("Channel logs are not configured")
    if not getattr(bot.config.chanlogs, "dir", None):
        raise ConfigurationError("Channel log storage directory is not defined")

    # ensure log directory exists
    basedir = os.path.expanduser(bot.config.chanlogs.dir)
    if not os.path.exists(basedir):
        os.makedirs(basedir)

    # locks for log files
    if not bot.memory.contains('chanlog_locks'):
        bot.memory['chanlog_locks'] = willie.tools.WillieMemoryWithDefault(threading.Lock)
Ejemplo n.º 2
0
def setup(bot):
    bot.memory['rss_manager'] = RSSManager(bot)

    if not bot.db:
        raise ConfigurationError("Database not set up, or unavailable.")
    conn = bot.db.connect()
    c = conn.cursor()

    # if new table doesn't exist, create it and try importing from old tables
    # The rss_feeds table was added on 2013-07-17.
    try:
        c.execute('SELECT * FROM rss_feeds')
    except StandardError:
        create_table(bot, c)
        migrate_from_old_tables(bot, c)

        # These tables are no longer used, but lets not delete them right away.
        # c.execute('DROP TABLE IF EXISTS rss')
        # c.execute('DROP TABLE IF EXISTS recent')

        conn.commit()

    # The modified column was added on 2013-07-21.
    try:
        c.execute('SELECT modified FROM rss_feeds')
    except StandardError:
        c.execute('ALTER TABLE rss_feeds ADD modified TEXT')
        conn.commit()

    conn.close()
Ejemplo n.º 3
0
def setup(bot):
    if not bot.config.has_option('bitly', 'access_token'):
        raise ConfigurationError(
            'bitly needs the access token in order to use the Bitly API'
        )
    if not bot.config.has_option('bitly', 'max_length'):
        bot.config.bitly.max_length = 79
    else:
        try:
            bot.config.bitly.max_length = int(bot.config.bitly.max_length)
        except ValueError:  # Back to the default value
            bot.config.bitly.max_length = 79

    regex = re.compile(RE_HAS_URL)
    if not bot.memory.contains(u'url_callbacks'):
        bot.memory[u'url_callbacks'] = {regex, bitly_url}
    else:
        exclude = bot.memory[u'url_callbacks']
        exclude[regex] = bitly_url
        bot.memory[u'url_callbacks'] = exclude

    if not bot.memory.contains(u'bitly_client'):
        bot.memory[u'bitly_client'] = bitly_api.Connection(
            access_token=bot.config.bitly.access_token
        )
Ejemplo n.º 4
0
def setup(willie):
    try:
        auth = tweepy.OAuthHandler(willie.config.twitter.consumer_key, willie.config.twitter.consumer_secret)
        auth.set_access_token(willie.config.twitter.access_token, willie.config.twitter.access_token_secret)
        api = tweepy.API(auth)
    except:
        raise ConfigurationError('Could not authenticate with Twitter. Are the'
                                 ' API keys configured properly?')
Ejemplo n.º 5
0
def setup(bot=None):
    if not bot:
        return

    if (bot.config.has_option('help', 'threshold') and not
            bot.config.help.threshold.isdecimal()):  # non-negative integer
        from willie.config import ConfigurationError
        raise ConfigurationError("Attribute threshold of section [help] must be a nonnegative integer")
Ejemplo n.º 6
0
def setup(willie):
    try:
        auth = tweepy.OAuthHandler(willie.config.twitter.consumer_key, willie.config.twitter.consumer_secret)
        auth.set_access_token(willie.config.twitter.access_token, willie.config.twitter.access_token_secret)
        api = tweepy.API(auth)
    except:
        raise ConfigurationError('Could not authenticate with Twitter. Are the'
                                 ' API keys configured properly?')
    regex = re.compile('twitter.com\/(\S*)\/status\/([\d]+)')
    if not willie.memory.contains('url_callbacks'):
        willie.memory['url_callbacks'] = tools.WillieMemory()
    willie.memory['url_callbacks'][regex] = gettweet
Ejemplo n.º 7
0
def setup(bot):
    global url_finder, exclusion_char, api_url, api_key, api_user, api_private

    if bot.config.bookie.api_url:
        try:
            # say we have "https://example.com/prefix/api/v1/admin/account?api_key=XXXXXX"
            p = urlparse(bot.config.bookie.api_url)
            # "https://example.com"
            api_url = p.scheme + '://' + p.netloc
            # "/prefix"
            prefix = p.path.split(api_suffix)[0]
            if prefix:
                api_url += prefix
            # "/api/v1/"
            api_url += api_suffix
            # the path element after api_suffix
            # that is, "admin"
            api_user = p.path.split(api_suffix)[1].split('/')[0]
            # "XXXXXX"
            api_key = p.query.split('=')[1]
        except Exception as e:
            raise ConfigurationError('Bookie api_url badly formatted: %s' %
                                     str(e))
    else:
        raise ConfigurationError('Bookie module not configured')

    api_private = validate_private(bot.config.bookie.private)
    if bot.config.has_option('url', 'exclusion_char'):
        exclusion_char = bot.config.url.exclusion_char

    url_finder = re.compile(
        r'(?u)(.*?)\s*(%s?(?:http|https|ftp)(?:://\S+)\s*(.*?))' %
        (exclusion_char))
    if bot.config.bookie.auto:
        if not bot.memory.contains('url_callbacks'):
            bot.memory['url_callbacks'] = tools.WillieMemory()
        bot.memory['url_callbacks'][re.compile('.*')] = bmark
Ejemplo n.º 8
0
def setup(bot):
   
    if not bot.db:
        raise ConfigurationError("Database not set up, or unavailable.")
    
    # connect bot's database
    conn = bot.db.connect()
    
    with conn:
        c = conn.cursor()
        
        # create needed tables, if not already existing
        # this tosses warnings, maybe not the best way to do this
        create_bots_table(c)
        create_packs_table(c)
        conn.commit()
Ejemplo n.º 9
0
def setup(bot):
    if not bot.config.has_section('safety'):
        raise ConfigurationError("Safety module not configured")
    bot.memory['safety_cache'] = willie.tools.WillieMemory()
    for item in bot.config.safety.get_list('known_good'):
        known_good.append(re.compile(item, re.I))

    loc = os.path.join(bot.config.homedir, 'malwaredomains.txt')
    if os.path.isfile(loc):
        if os.path.getmtime(loc) < time.time() - 24 * 60 * 60 * 7:
            # File exists but older than one week, update
            _download_malwaredomains_db(loc)
    else:
        _download_malwaredomains_db(loc)
    with open(loc, 'r') as f:
        for line in f:
            malware_domains.append(unicode(line).strip().lower())
Ejemplo n.º 10
0
def setup(bot):
    """
    Tests the validity of the client ID given in the configuration.
    If it is not, initializes willie's memory callbacks for imgur URLs,
    and uses them as the trigger for the link parsing function.
    """
    try:
        client = ImgurClient(bot.config.imgur.client_id)
        client.request('gallery.json')
    except HTTPError:
        raise ConfigurationError(
            'Could not validate the client ID with Imgur. \
                                 Are you sure you set it up correctly?')
    imgur_regex = re.compile('(?:https?://)?(?:i\.)?imgur\.com/(.*)$')
    if not bot.memory.contains('url_callbacks'):
        bot.memory['url_callbacks'] = tools.WillieMemory()
    bot.memory['url_callbacks'][imgur_regex] = imgur
Ejemplo n.º 11
0
def setup(bot):
    if not irccat_config(bot):
        raise ConfigurationError('irccat module not configured')