motivation/commands.py
def schneier(client, event, channel, nick, rest):
    'schneier "facts"'
    rcpt = rest.strip() or channel
    if rest.strip():
        Karma.store.change(rcpt, 2)

    url = 'https://www.schneierfacts.com/'
    d = requests.get(url).text
    start_tag = re.escape('<p class="fact">')
    end_tag = re.escape('</p>')
    p = re.compile(
        start_tag + '(.*?)' + end_tag,
        flags=re.DOTALL | re.MULTILINE)
    match = p.search(d)

    if not match:
        return "Sorry, no facts found (check your crypto anyway)."
    phrase = match.group(1).replace('\n', ' ').strip()
    if rcpt != channel:
        phrase = re.sub('(Bruce ?)?Schneier', rcpt, phrase, flags=re.I)
        phrase = re.sub('Bruce', rcpt, phrase, flags=re.I)

    # unescape HTML
    h = html.parser.HTMLParser()
    phrase = h.unescape(phrase)

    # Correct improperly-encoded strings
    phrase = ftfy.fix_encoding(phrase)

    return phrase
def schneier(client, event, channel, nick, rest):
    'schneier "facts"'
    rcpt = rest.strip() or channel
    if rest.strip():
        Karma.store.change(rcpt, 2)

    url = 'https://www.schneierfacts.com/'
    d = requests.get(url).text
    start_tag = re.escape('<p class="fact">')
    end_tag = re.escape('</p>')
    p = re.compile(
        start_tag + '(.*?)' + end_tag,
        flags=re.DOTALL | re.MULTILINE)
    match = p.search(d)

    if not match:
        return "Sorry, no facts found (check your crypto anyway)."
    phrase = match.group(1).replace('\n', ' ').strip()
    if rcpt != channel:
        phrase = re.sub('(Bruce ?)?Schneier', rcpt, phrase, flags=re.I)
        phrase = re.sub('Bruce', rcpt, phrase, flags=re.I)

    # unescape HTML
    h = html.parser.HTMLParser()
    phrase = h.unescape(phrase)

    # Correct improperly-encoded strings
    phrase = ftfy.fix_encoding(phrase)

    return phrase
def schneier ( client , event , channel , nick , rest ) : rcpt = rest . strip ( ) or channel if rest . strip ( ) : Karma . store . change ( rcpt , 2 ) url = 'https://www.schneierfacts.com/' d = requests . get ( url ) . text start_tag = re . escape ( '<p class="fact">' ) end_tag = re . escape ( '</p>' ) p = re . compile ( start_tag + '(.*?)' + end_tag , flags = re . DOTALL | re . MULTILINE ) match = p . search ( d ) if not match : return "Sorry, no facts found (check your crypto anyway)." phrase = match . group ( 1 ) . replace ( '\n' , ' ' ) . strip ( ) if rcpt != channel : phrase = re . sub ( '(Bruce ?)?Schneier' , rcpt , phrase , flags = re . I ) phrase = re . sub ( 'Bruce' , rcpt , phrase , flags = re . I ) # unescape HTML h = html . parser . HTMLParser ( ) phrase = h . unescape ( phrase ) # Correct improperly-encoded strings phrase = ftfy . fix_encoding ( phrase ) return phrase
schneier "facts"
schneier facts