How to use sopel - 10 common examples

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 dasu / syrup-sopel-modules / testmods.py View on Github external
@sopel.module.commands('hostm')
def hostm(bot,trigger):
    bot.say(trigger.host)
github dasu / syrup-sopel-modules / mal.py View on Github external
@sopel.module.rule('.*(https?:\/\/myanimelist.net\/anime\/(\d+).*((?=[\s])|$))')
def malirc(bot, trigger, match=None):
    match = match or trigger
    id = match.group(2)
    url = 'https://myanimelist.net/includes/ajax.inc.php?t=64&id={}-id'.format(id)
    bs, x = connect(url)
    if bs.text == 'No such series found.':
        return
    if "... (" in (bs.find_all('a', {'class':'hovertitle'})[0].text):
        name =  bs.find_all('a', {'class':'hovertitle'})[0].text.split("...")[0].strip()
        year =  bs.find_all('a', {'class':'hovertitle'})[0].text.split("...")[1].strip()[1:-1]
    else:
        split = bs.find_all('a', {'class':'hovertitle'})[0].text.split(' (')
        name = split[0]
        year = split[1][0:-1]
    status = bs.findAll('span',text='Status:')[0].nextSibling.strip()
    episodes = bs.findAll('span',text='Episodes:')[0].nextSibling.strip()
github dasu / syrup-sopel-modules / gelbooru.py View on Github external
@sopel.module.example('.gelbooru search_term or .gelbooru safe search_term')
def gel(bot, trigger):
    if not trigger.group(2):
        return bot.say("Enter a search term.")
    search_term = trigger.split(' ')
    search_term.pop(0)
    bs, tags = get_gel_data(search_term)
    if not bs:
        return
    if bs.find_all('posts')[0].get('count') == '0':
        return bot.say('Nothing but us chickens!')
    else:
        total = bs.findAll('posts')[0].get('count')
        bot.say('[{0} found] http://gelbooru.com/index.php?page=post&s=list&tags={1}'.format(total, tags))
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 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 openshift / openshift-tools / openshift_tools / ircbot / openshift_sre / openshift_sre.py View on Github external
@module.require_admin('You must be a bot admin to use this command')
def say_admin_list(bot, trigger):
    """Sends privmsg of all current admins.
    Will only respond to bot admins."""
    bot.say('Check your PM')
    bot.say('Current bot owner: ' + bot.config.core.owner, trigger.nick)
    admins = bot.config.core.admins
    if len(admins) > 0:
        bot.say('Current bot admins:', trigger.nick)
        for admin in admins.split(','):
            bot.say('\t' + admin, trigger.nick)
    else:
        bot.say('No configured admins', trigger.nick)
    bot.say('New admins can be added by creating a PR against '
            'https://github.com/openshift/openshift-ansible-ops/tree/prod/playbooks/adhoc/ircbot', trigger.nick)
github sopel-irc / sopel-extras / oblique.py View on Github external
def mappings(uri):
    result = {}
    bytes = web.get(uri)
    for item in r_item.findall(bytes):
        item = r_tag.sub('', item).strip(' \t\r\n')
        if not ' ' in item:
            continue

        command, template = item.split(' ', 1)
        if not command.isalnum():
            continue
        if not template.startswith('http://'):
            continue
        result[command] = template.replace('&', '&')
    return result
github dasu / syrup-sopel-modules / url2.py View on Github external
except UnicodeDecodeError:
        return  # Fail silently when data can't be decoded
    finally:
        # need to close the connexion because we have not read all the data
        response.close()

    # Some cleanup that I don't really grok, but was in the original, so
    # we'll keep it (with the compiled regexes made global) for now.
    content = title_tag_data.sub(r'<\1title>', content)
    content = quoted_title.sub('', content)

    start = content.find('<title>')
    end = content.find('</title>')
    if start == -1 or end == -1:
        return
    title = web.decode(content[start + 7:end])
    title = title.strip()[:200]

    title = ' '.join(title.split())  # cleanly remove multiple spaces

    # More cryptic regex substitutions. This one looks to be myano's invention.
    title = re_dcc.sub('', title)
    title = title.replace("[apos]","'")
    return title or None
github sopel-irc / sopel-extras / dicelog.py View on Github external
@priority('medium')
def dicelog(bot, trigger):
    """
    .dice [logfile]   - Rolls dice using the XdY format, also does
    basic math and drop lowest (XdYvZ). Saves result in logfile if given.
    """
    if not trigger.group(2):
        return bot.reply('You have to specify the dice you wanna roll.')

    # extract campaign
    if trigger.group(2).startswith('['):
        campaign, rollStr = trigger.group(2)[1:].split(']')
    else:
        campaign = ''
        rollStr = trigger.group(2).strip()
    campaign = campaign.strip()
    rollStr = rollStr.strip()