Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def setup(sopel):
try:
auth = tweepy.OAuthHandler(sopel.config.twitter.consumer_key, willie.config.twitter.consumer_secret)
auth.set_access_token(sopel.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 sopel.memory.contains('url_callbacks'):
sopel.memory['url_callbacks'] = tools.SopelMemory()
sopel.memory['url_callbacks'][regex] = gettweet
def setup(bot):
"""
Tests the validity of the client ID given in the configuration.
If it is not, initializes sopel'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.SopelMemory()
bot.memory['url_callbacks'][imgur_regex] = imgur
# callbacks list because 1, it's easier to deal with modules that are still
# using this list, and not the newer callbacks list and 2, having a lambda
# just to pass is kinda ugly.
if not bot.memory.contains('url_exclude'):
bot.memory['url_exclude'] = regexes
else:
exclude = bot.memory['url_exclude']
if regexes:
exclude.extend(regexes)
bot.memory['url_exclude'] = exclude
# Ensure that url_callbacks and last_seen_url are in memory
if not bot.memory.contains('url_callbacks'):
bot.memory['url_callbacks'] = tools.SopelMemory()
if not bot.memory.contains('last_seen_url'):
bot.memory['last_seen_url'] = tools.SopelMemory()
url_finder = re.compile(r'(?u)(%s?(?:http|https|ftp)(?:://\S+))' %
(bot.config.url.exclusion_char), re.IGNORECASE)
def setup(bot):
if not bot.memory.contains('url_callbacks'):
bot.memory['url_callbacks'] = tools.SopelMemory()
bot.memory['url_callbacks'][URL_REGEX] = youtube_info
# We're keeping these in their own list, rather than putting then in the
# callbacks list because 1, it's easier to deal with modules that are still
# using this list, and not the newer callbacks list and 2, having a lambda
# just to pass is kinda ugly.
if not bot.memory.contains('url_exclude'):
bot.memory['url_exclude'] = regexes
else:
exclude = bot.memory['url_exclude']
if regexes:
exclude.extend(regexes)
bot.memory['url_exclude'] = exclude
# Ensure that url_callbacks and last_seen_url are in memory
if not bot.memory.contains('url_callbacks'):
bot.memory['url_callbacks'] = tools.SopelMemory()
if not bot.memory.contains('last_seen_url'):
bot.memory['last_seen_url'] = tools.SopelMemory()
url_finder = re.compile(r'(?u)(%s?(?:http|https|ftp)(?:://\S+))' %
(bot.config.url.exclusion_char), re.IGNORECASE)