How to use the sopel.module.rule function in sopel

To help you get started, we’ve selected a few sopel examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sopel-irc / sopel-extras / twit.py View on Github external
@rule('.*twitter.com\/(\S*)\/status\/([\d]+).*')
def gettweet(sopel, trigger, found_match=None):
    """Show the last tweet by the given user"""
    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)

        if found_match:
            status = api.get_status(found_match.group(2), tweet_mode='extended')
        else:
            parts = trigger.group(2).split()
            if parts[0].isdigit():
                status = api.get_status(parts[0], tweet_mode='extended')
            else:
                twituser = parts[0]
                twituser = str(twituser)
github anqxyr / jarvis / jarvis / modules / jarvis_irc.py View on Github external
@sopel.module.rule('.*')
def dispatcher(bot, tr):
    inp = jarvis.core.Inp(
        tr.group(0), tr.nick, tr.sender,
        functools.partial(send, bot),
        functools.partial(privileges, bot, tr.nick),
        bot.write)
    jarvis.core.dispatcher(inp)
github dasu / syrup-sopel-modules / heh.py View on Github external
@sopel.module.rule(r'(^|.+ )alot( .+|$)')
def alot(bot, trigger):
   bot.say("%s LEARN TO SPELL: %s" % (trigger.nick, choice(alotImages)))
github dasu / syrup-sopel-modules / twitch.py View on Github external
@sopel.module.rule('.*(?:https?:\/\/clips\.twitch.tv\/(.*?)\/?(?:(?=[\s])|$))|.*(?:https?:\/\/(?:www)?\.twitch\.tv\/.*?\/clip\/(.*?)\/?(?:(?=[\s])|$))')
def twitchclipsirc(bot,trigger, match = None):
  match = match or trigger
  slug = match.group(1) or match.group(2)
  clips = requests.get("https://api.twitch.tv/kraken/clips/{}".format(slug), headers={"Client-ID":twitchclientid,"Accept":"application/vnd.twitchtv.v5+json"}).json()
  name = clips['broadcaster']['display_name']
  title = clips['title']
  game = clips['game']
  views = clips['views']
  bot.say("{} [{}] | {} | {} views".format(title, game, name, tsep(views)))
github dasu / syrup-sopel-modules / url2.py View on Github external
@rule('(?u).*(https?://\S+).*')
def title_auto(bot, trigger):
    """
    Automatically show titles for URLs. For shortened URLs/redirects, find
    where the URL redirects to and show the title for that (or call a function
    from another module to give more information).
    """
    if re.match(bot.config.core.prefix + 'title', trigger):
        return

    # Avoid fetching known malicious links
    if 'safety_cache' in bot.memory and trigger in bot.memory['safety_cache']:
        if bot.memory['safety_cache'][trigger]['positives'] > 1:
            return

    urls = re.findall(url_finder, trigger)
    if len(urls) == 0:
github anqxyr / jarvis / jarvis / modules / notes.py View on Github external
@sopel.module.rule(r'^\?([\w\d-]+)$')
def get_rem(bot, tr):
    channel = channel_quotes_enabled(bot, tr)
    if channel:
        bot.send(jarvis.notes.recall_user(tr.group(1), channel))
github dasu / syrup-sopel-modules / twitter.py View on Github external
@sopel.module.rule("(https?:\/\/twitter\.com\/(?:#!\/)?(\w+)\/status(es)?\/(\d+))")
def twatterirc(bot,trigger):
  url = "https://publish.twitter.com/oembed?url={}".format(trigger.group(1))
  x = requests.get(url)
  user = x.json()['author_name']
  bs = BeautifulSoup(x.json()['html'], "html.parser")
  for a_tag in bs.find_all('a'):
    if((a_tag.text.startswith("#")) or (a_tag.text.startswith("@"))):
      continue
    a_tag.string = a_tag.get('href')
  bot.say("[Twitter] {}: {}".format(user, bs.p.text))
github anqxyr / jarvis / jarvis / modules / autoban.py View on Github external
@sopel.module.rule('.*')
def join_event(bot, tr):
    bad_words = [
        'bitch', 'fuck', 'asshole', 'penis', 'vagina', 'nigger', 'retard',
        'faggot', 'chink', 'shit', 'hitler', 'douche']
    for word in bad_words:
        if word in tr.nick.lower():
            ban_user(bot, tr)
    for ban in bot.memory['bans']:
        if tr.nick.lower() in ban.names:
            ban_user(bot, tr, ban)
        if tr.host in ban.hosts:
            ban_user(bot, tr, ban)
github dasu / syrup-sopel-modules / steam.py View on Github external
@sopel.module.rule('.*https?:\/\/store\.steampowered\.com\/app\/(.*?\/)(?:.*?\/)?(?:.*)((?=[\s])|$)')
def steamirc(bot,trigger, match=None):
    match = match or trigger
    appid = match.group(1)[:-1]
    gameinfo = getgameinfo(appid)
    averageplayers = getaverageplayers24h(appid)
    rating = getreviewdata(appid)
    lowestdate, lowestprice, lowestdiscount = getlowestprice(appid)
    bot.say("[{0}]{1}{2}{3}{4}{5}".format(gameinfo['name'],
                                            " Rating: {} ({}) |".format(rating['reviewsummary'], rating['reviewpercentage']) if rating['reviewsummary'] else '',
                                            " Peak Players 24H: {} |".format(averageplayers) if averageplayers else '',
                                            " Price: {}{} |".format(gameinfo['price'], " (-{}%)".format(gameinfo['discount']) if gameinfo['discount'] else '') if gameinfo['price'] else '',
                                            " Lowest Price: {} (-{}) on {} ".format(lowestprice, lowestdiscount, lowestdate.strftime("%m-%Y")) if lowestprice else '',
                                            " Coming soon: {} ".format(gameinfo['release']) if gameinfo['release'] else ''))
github anqxyr / jarvis / jarvis / modules / tools.py View on Github external
@sopel.module.rule(r'(?i)(^(?:[+-]?[0-9]*d(?:[0-9]+|f))+(?:[+-][0-9]+)?$)')
@sopel.module.commands('roll', 'dice')
def dice(bot, tr):
    inp = tr.groups()[0] if len(tr.groups()) == 1 else tr.groups()[1]
    bot.send(jarvis.tools.roll_dice(inp))