How to use the sopel.module.example 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 openshift / openshift-tools / openshift_tools / ircbot / openshift_sre / openshift_sre.py View on Github external
@module.example('.karma', 'You have X karma')
@module.example('.karma ', ' has X karma')
def say_karma(bot, trigger):
    """List karma of yourself or a given nick"""
    if trigger.group(2):
        for nick in trigger.group(2).split():
            display_karma(bot, trigger.sender, nick)
    else:
        display_karma(bot, trigger.sender, trigger.nick)
github sopel-irc / sopel-extras / multimessage.py View on Github external
@example('.mm nick1,nick2,nick3 my amazing message')
def multimessage(bot, trigger):
    """
    .mm    - Sends the same message to multiple users
    """
    if not trigger.isop:
        return
    parts = trigger.group(2).split(' ', 1)
    nicks = parts[0].split(',')
    for nick in nicks:
        bot.msg(nick, parts[1])
    bot.reply('All messages sent!')
github dasu / syrup-sopel-modules / edict.py View on Github external
@sopel.module.example('.edict word/character')
def edict(bot, trigger):
    if not trigger.group(2):
        return bot.say("Please enter a word.")
    word = trigger.group(2)
    try:
        word.encode('ascii')
        edict_return = get_defintion(word,'1ZDJ')
        if edict_return.pre:
            return bot.say(edict_return.pre.contents[0].splitlines()[1])
        else:
            return bot.say("No matches found.")
    except:
        edict_return = get_defintion(word,'1ZIK')
        if edict_return.li:
            return bot.say(edict_return.li.contents[0])
        else:
github sopel-irc / sopel-extras / debug.py View on Github external
@example('.privs', '.privs #channel')
def privileges(bot, trigger):
    """Print the privileges of a specific channel, or the entire array."""
    if trigger.group(2):
        try:
            bot.say(str(bot.privileges[trigger.group(2)]))
        except Exception:
            bot.say("Channel not found.")
    else:
        bot.say(str(bot.privileges))
github dasu / syrup-sopel-modules / hn.py View on Github external
@sopel.module.example('.rhn url')
def rhn(bot, trigger):
    if not trigger.group(2):
        if trigger.sender not in bot.memory['last_seen_url']:
            return
        rhnurl = bot.memory['last_seen_url'][trigger.sender]
    else:
        rhnurl = trigger.group(2)
    x = requests.get("https://hn.algolia.com/api/v1/search?query={}".format(rhnurl)).json()
    try:
        return bot.say("https://news.ycombinator.com/item?id={} | {} | \U0001F4AC:{}".format(x['hits'][0]['objectID'],x['hits'][0]['title'],x['hits'][0]['num_comments']))
    except:
        return bot.say("No HN discussion found")
github dasu / syrup-sopel-modules / twitch.py View on Github external
@sopel.module.example('.twitch  or .twitch twitchusername')
def streamer_status(bot, trigger):
  streamer_name = trigger.group(2)
  query = streamers if streamer_name is None else gettwitchuserid(streamer_name)
  if query is None:
    return bot.say("Nobody is currently streaming")
  try:
    streaming = twitch_api(query)
  except Exception as  e:
    return print("There was an error reading twitch API  {0}".format(e))
  results = []
  if streaming.get("streams"):
    twitch_gen = twitch_generator(streaming)
    for streamer in twitch_gen:
      results.append("%s is playing %s [%s] (%s - %s viewer%s)" % (streamer["name"],
                                                                   streamer["game"],
                                                                   streamer["status"],
github dasu / syrup-sopel-modules / hltb.py View on Github external
@sopel.module.example('.hltb game name')
def hltb(bot,trigger):
    if not trigger.group(2):
        return bot.say("Enter a game name to search.")
    game = trigger.group(2)
    url = "https://howlongtobeat.com/search_results.php?page=1"
    payload = {"queryString":game,"t":"games","sorthead":"popular","sortd":"Normal Order","length_type":"main","detail":"0"}
    test = {'Content-type':'application/x-www-form-urlencoded', 'User-Agent':'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.97 Safari/537.36','origin':'https://howlongtobeat.com','referer':'https://howlongtobeat.com'}
    session = requests.Session()
    r = session.post(url, headers=test, data=payload)
    if len(r.content) < 250:
        return bot.say("No results.")
    bs = BeautifulSoup(r.content, "html.parser")
    first = bs.findAll("div", {"class":"search_list_details"})[0]
    name = first.a.text
    time = first.findAll('div')[3].text
    bot.say('{} - {}'.format(name, time))
github dasu / syrup-sopel-modules / urbandict.py View on Github external
@sopel.module.example('.urb word')
def urbandict(bot, trigger):
    """.urb  - Search Urban Dictionary for a definition."""

    word = trigger.group(2)
    if not word:
        return bot.say(urbandict.__doc__.strip())
    try:
        data = requests.get("http://api.urbandictionary.com/v0/define?term={0}".format(requests.utils.quote(word))).json()
    except:
        return bot.say("Error connecting to urban dictionary")

    if not data['list']:
        return bot.say("No results found for {0}".format(word))
    try:
        result = list(filter(lambda x: x['word'].lower() == word.lower(), data['list']))[0]
    except:
github dasu / syrup-sopel-modules / youtoob.py View on Github external
@example('.yt Mystery Skulls - Ghost')
def ytsearch(bot, trigger):
    """Allows users to search for YouTube videos with .yt """
    if not trigger.group(2):
        return

    # Note that web.get() quotes the query parameters, so the
    # trigger is purposely left unquoted (double-quoting breaks things)
    url = SEARCH_URL.format(get_api_key(bot), trigger.group(2))
    result = requests.get(url).json()
    if 'error' in result:
        bot.say(u'[YouTube Search] ' + result['error']['message'])
        return

    if len(result['items']) == 0:
        bot.say(u'[YouTube Search] No results for ' + trigger.group(2))
        return
github openshift / openshift-tools / openshift_tools / ircbot / openshift_sre / openshift_sre.py View on Github external
@module.example('.track')
def mark_channel_track_oncall(bot, trigger):
    """Begins tracking on-call and shift lead rotations."""
    bot.db.set_channel_value(trigger.sender, 'monitoring', True)
    bot.db.set_channel_value(trigger.sender, 'announce', True)
    bot.say(
        trigger.sender + ' is now tracking SRE on-call rotation')