Merge pull request #4 from rakiru/master

Tildebot Improvements from ~deltawitch
This commit is contained in:
Russell 2018-07-18 15:43:41 -04:00 committed by GitHub
commit ff4faec314
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 123 additions and 10 deletions

85
Code/irc/badwords.txt Normal file
View File

@ -0,0 +1,85 @@
Note: This list is probably missing a lot of stuff, but I didn't want to just ram 50 random lists from the internet together. Feel free to replace. - ~deltawitch
== Potentially unwelcome words ==
racist
racists
racism
sexist
sexists
sexism
xenophobe
xenophobia
== Slurs/Insults ==
faggot
faggots
dyke
dykes
chink
chinks
bitch
bitches
bastard
bastards
whore
whores
== Violence/Sexual ==
rape
rapes
raping
rapist
rapists
grope
gropes
semen
bestiality
incest
sadism
domination
sodomy
fingering
pegging
bondage
bareback
humping
sex
sexy
anal
anus
anuses
genitals
vagina
vaginas
clitoris
pussy
pussies
penis
penises
cock
cocks
ass
asses
butt
butts
tit
tits
breast
breasts
cumming
ejaculation
orgasm
orgy
erotic
intercourse
kinky
nipple
nipples
panty
panties
pornography
prostitute
prostitutes
prostitution
rectum
rimming
smut
spunk
undressing

View File

@ -4,9 +4,19 @@ import inflect
p = inflect.engine()
dictionary = "/usr/share/dict/american-english-small"
BAD_WORDS_FILE = "badwords.txt"
def get_wordlist():
# I feel weird calling this "get_wordlist" when it's a generator without calling out that I do in fact realise it's weird - ~deltawitch
with open(BAD_WORDS_FILE, "r") as fp:
bad_words = set(fp)
for word in open(dictionary).readlines():
if "'" not in word and word not in bad_words:
yield word.rstrip()
def get_puzzle():
dict_words = [word.rstrip() for word in open(dictionary).readlines() if "'" not in word]
dict_words = list(get_wordlist())
words = random.sample(dict_words, 3)
key = random.randrange(0,3) #get values 1-3
puzzle = "When alphebetized, what is the " + p.ordinal(p.number_to_words(key+1)) + " in " + ", ".join(words)
@ -15,11 +25,22 @@ def get_puzzle():
return [answer, puzzle]
def get_anagram(maxlen = 6):
dict_words = [word.rstrip() for word in open(dictionary).readlines() if "'" not in word and len(word) > 2 and len(word) <= maxlen+1]
dict_words = [word for word in get_wordlist() if len(word) > 2 and len(word) <= maxlen+1]
word = random.choice(dict_words)
while True:
anagram = ''.join(random.sample(word, len(word)))
if anagram != word:
break
puzzle = "Unscramble the following word: '" + anagram + "'"
return [word, puzzle]
# Anagrams can have multiple answers, so we provide a check function that accepts all possibilities
def answer_checker(guess):
# Check for exact match
if guess == word:
return True
# Bail out early if they didn't even use all the same letters
if sorted(guess) != sorted(word):
return False
# Ok, gotta actually check if it's a word now
return any(guess == item for item in get_wordlist())
return [answer_checker, puzzle]

View File

@ -10,6 +10,7 @@ fuzz_amount = 3
def make_puzzle(obfuscate=True):
answer = 0
bonus = 0
puzzle = random.choice(["Prove you're not a robot: ", "Are you a robot?: ", "Anti-bot check: ", "Counter-cndorphant measures: ", "Cosnok countermeasures: ", "Anti-tildethief precautions: "])
puzzle += random.choice(["What is", "How many is", "What do you get from", "What do you get with", "What is the value of", "Can you answer", "Can you tell me"])
puzzle += " "
@ -43,7 +44,13 @@ def make_puzzle(obfuscate=True):
elif roll == 5:
p1 = random.choice(primes)
p2 = random.choice(primes)
answer = str(min(p1,p2)) + ',' + str(max(p1,p2))
def answer(guess):
# Check the the numbers entered are correct, regardless of order
# or surrounding whitespace.
attempt = sorted(word.strip() for word in guess.split(","))
correct = sorted([str(p1), str(p2)])
return attempt == correct
bonus = 1
puzzle += p.number_to_words(p1 * p2) + " when factored into its two primes (answer in the form of the two primes with a comma between)"
elif roll == 6:
prime = random.choice(primes)
@ -82,4 +89,4 @@ def make_puzzle(obfuscate=True):
for _ in range(fuzz_amount):
idx = random.randrange(len(puzzle)-1) #get between 0 and string length
puzzle = ''.join([puzzle[0:idx], chr(random.randint(33,126)), puzzle[idx+1:]])
return [answer, puzzle]
return [puzzle, answer, bonus]

View File

@ -138,15 +138,15 @@ def challenge(channel, user, name, time):
return
global challenges;
challenge = puzzle.make_puzzle();
challenges[user] = challenge[0]; #challenges[USER] = ANSWER
ircsock.send("PRIVMSG " + channel + " :" + name + ": " + challenge[1] + "\n");
challenges[user] = challenge[1:]; #challenges[USER] = [ANSWER, BONUS]
ircsock.send("PRIVMSG " + channel + " :" + name + ": " + challenge[0] + "\n")
def challenge_response(channel, user, name, time, msg):
global challenges
print(msg);
if(challenges.has_key(user)):
bonus = 1 if str(challenges[user]).find(',') != -1 else 0 #give a bonus for prime factoring
if(msg.lower() == str(challenges[user]).lower() or msg == p.number_to_words(challenges[user])):
answer, bonus = challenges[user]
if((callable(answer) and answer(msg.lower())) or (msg.lower() == str(answer).lower() or msg == p.number_to_words(answer))):
give_tilde(channel, user, name, time, True, bonus);
else:
give_tilde(channel, user, name, time, False, 0);
@ -203,7 +203,7 @@ def listen():
show_tildescore(channel, user, name)
elif msg.find(":!tilde") != -1 and not challenges.has_key(user):
challenge(channel, user, name, iTime)
elif challenges.has_key(user):
elif challenges.has_key(user) and (channel == "#bots" or DEBUG):
challenge_response(channel, user, name, iTime, messageText)
#give_tilde(channel, user, name, iTime)