Update things, delete things, add things

This commit is contained in:
RussellChamp committed 2019-03-15 10:20:44 -04:00
1 parent 772995c0ff
commit a8b397a44f
31 files changed
+347 -803

No files matched your search

+8
View File
@@ -0,0 +1,8 @@
#!/usr/bin/python3
import requests
from bs4 import BeautifulSoup
def getWisdom():
url = "http://www.wisdomofchopra.com/iframe.php"
html = BeautifulSoup(requests.get(url).content, "html.parser")
return html.find("td", { "id": "quote" }).text
+8
View File
@@ -0,0 +1,8 @@
#!/usr/bin/python3
import requests
from bs4 import BeautifulSoup
def getDuo():
url = "https://www.theyfightcrime.org/"
html = BeautifulSoup(requests.get(url).content, "html.parser")
return html.findAll('p')[1].text
+8
View File
@@ -0,0 +1,8 @@
#!/usr/bin/python3
import requests
from bs4 import BeautifulSoup
def ReionizeElectrons():
url = "http://sebpearce.com/bullshit/"
html = BeautifulSoup(requests.get(url).content, "html.parser")
return html.findAll('p')[1].text
+14 -4
View File
@@ -6,22 +6,32 @@ import random
import re
quotefile = "/home/karlen/irc/quotes.txt"
wordsfile = "/usr/share/dict/words"
chuckfile = "/home/krowbar/Code/irc/data/chuck.txt"
chuckApi = "https://api.icndb.com/jokes/random"
def get_quote():
quotes = open(quotefile, "r").read().split("---")
quote, attr = random.choice(quotes).strip().splitlines()
attempt = 10
dict_words = open(wordsfile).read().split()
while True:
good_words = [w for w in quote.split() if w in dict_words and len(w) > 2]
if len(good_words) > 3 or attempt is 0:
break #either we got a good one or we gave up
quote, attr = random.choice(quotes).strip().splitlines()
attempt = attempt - 1
quote = quote[:200] # get only the first 200 chars
word = random.choice([q for q in quote.split(" ") if len(q) > 1])
word = random.choice([q for q in quote.split() if len(q) > 2 and q in dict_words] or [q for q in quote.split() if len(q) > 1])
quote = quote.replace(word, re.sub(r"[a-zA-Z]", "_", word))
return [word, 'Fill in the blank: "' + quote + '" ' + attr]
return [word, 'Fill in the blank: "{}" {}'.format(quote, attr)]
def get_chuck():
#chucks = open(chuckfile, "r").readlines()
#chuck = random.choice(chucks).rstrip()[:200] # get only the first 200 chars
# ha ha! let's see if we can confus login
# ha ha! let's see if we can confuse login
chuck = json.loads(requests.get(chuckApi).content.decode())['value']['joke'][:200]
word = random.choice([w for w in chuck.split(" ") if len(w) > 1 and w.lower() != "chuck" and w.lower() != "norris"])
chuck = chuck.replace(word, re.sub(r"[a-zA-Z]", "_", word)).replace(""", "\"")
return [word, 'Fill in the blank: "{}"'.format(chuck)]
return [word, 'Fill in the blank: "{}"'.format(chuck)]
+34
View File
@@ -0,0 +1,34 @@
#!/usr/bin/python3
import json
import random
import requests
def getRandom(query = "randomlists"):
query = query.lower().replace(' ', '-')
message = ""
request = requests.get("https://www.randomlists.com/data/{}.json".format(query))
if request.status_code == 404:
request = requests.get("https://www.randomlists.com/data/random-{}.json".format(query))
if request.status_code == 404:
message = "No results found. Try"
request = requests.get("https://www.randomlists.com/data/randomlists.json")
jdata = json.loads(request.content)
items = list()
if 'RandL' in jdata:
items = list(jdata['RandL']['items'])
elif 'data' in jdata:
items = list(jdata['data'])
item = random.choice(items)
if 'name' in item:
message += " " + item['name']
if 'detail' in item:
message += ": " + item['detail']
if 'subtle' in item:
message += " (" + item['subtle'] + ")"
if message == "":
message = item
return message.strip()
+37 -7
View File
@@ -2,6 +2,7 @@
# Import some necessary libraries.
import random
import re
import inflect
import util.puzzle
@@ -58,7 +59,13 @@ def get_negative():
"Not quite",
"Not even close",
"Not for you",
"I think not"
"I think not",
"Wait... uh maybe?",
"It could have been",
"It should have been",
"Whoops",
"SegFault: Insufficient Tildes",
"Wait, what did you guess?"
]
)
@@ -83,6 +90,8 @@ def get_superlative(score):
"worth twice their weight in gold",
"the hero we need",
"no ordinary townie",
"the bot whisperer",
"probably predicting rng",
]
)
elif score > 2:
@@ -95,13 +104,18 @@ def get_superlative(score):
"radical",
"intense",
"pretty lucky",
"knows the territory",
"has what it takes",
"has mad skillz",
#"knows the territory",
#"has what it takes",
#"has mad skillz",
"going the distance",
"a hard worker",
"my sunshine",
"ready to rumble",
"better than sliced bread",
"main protagonist material",
"right as rain",
"a puzzle prophet",
"a counter-captcha expert",
]
)
else:
@@ -120,6 +134,13 @@ def get_superlative(score):
"probably not a robot",
"valuable to the team",
"now trending",
"on your way up",
"credit to team",
"a net positive",
"groovy",
"competent",
"not wrong",
"on the right track",
]
)
@@ -167,6 +188,7 @@ def get_bad_thing():
"actually answered the last question",
"has their pants on backwards",
"forgot their own name",
"got me really confused"
]
)
@@ -264,6 +286,16 @@ def challenge(channel, user, time):
challenges[user] = challenge[1:]
return "{}: {}".format(user, challenge[0])
def valid_answer(answer, guess):
guess = guess.lower();
if callable(answer):
return answer(guess)
else:
# convert the guess and answer to just alphanumeric values. some
# "answers" acidentally have punctuation or other things in them
guess = re.sub(r'\W+', '', guess)
answer = re.sub(r'\w+', '', str(answer).lower())
return (msg == answer or msg == p.number_to_words(answer))
def challenge_response(user, time, msg):
global challenges
@@ -271,9 +303,7 @@ def challenge_response(user, time, msg):
response = ""
if user in challenges:
answer, bonus = challenges[user]
if (callable(answer) and answer(msg.lower())) or (
msg.lower() == str(answer).lower() or msg == p.number_to_words(answer)
):
if valid_answer(answer, msg):
response = give_tilde(user, time, True, bonus)
else:
response = give_tilde(user, time, False, 0)
+15
View File
@@ -0,0 +1,15 @@
#!/usr/bin/python3
import requests
from bs4 import BeautifulSoup
# These seem to get the same result each time we run them. I think TVTropes
# has some anti-scraping mechanism
def getTrope():
url = "https://tvtropes.org"
html = BeautifulSoup(requests.get(url).content, "html.parser")
return url + html.find('a', { 'class': 'button-random-trope' })['href']
def getMedia():
url = "https://tvtropes.org"
html = BeautifulSoup(requests.get(url).content, "html.parser")
return url + html.find('a', { 'class': 'button-random-media' })['href']