From dcbf3d174e7621c76611a9cc8bb2b6b5df777bba Mon Sep 17 00:00:00 2001 From: rakiru Date: Mon, 16 Jul 2018 21:43:26 +0100 Subject: [PATCH 1/5] tildebot | Only listen for answers in bot channel --- Code/irc/tildebot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Code/irc/tildebot.py b/Code/irc/tildebot.py index 540a6bf..66ff85e 100755 --- a/Code/irc/tildebot.py +++ b/Code/irc/tildebot.py @@ -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) From 58432b5cdf84bad9d1e8486194675f73d71fd669 Mon Sep 17 00:00:00 2001 From: rakiru Date: Mon, 16 Jul 2018 21:55:22 +0100 Subject: [PATCH 2/5] tildebot | Move bonus points to puzzle file It seemed like the more logical place to be, and the way it was detecting might've accidentally given bonuses to future questions. It also means the bonus could be adjusted per question type now, if so desired. --- Code/irc/puzzle.py | 4 +++- Code/irc/tildebot.py | 8 ++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Code/irc/puzzle.py b/Code/irc/puzzle.py index 198ecd9..ad43d87 100644 --- a/Code/irc/puzzle.py +++ b/Code/irc/puzzle.py @@ -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 += " " @@ -44,6 +45,7 @@ def make_puzzle(obfuscate=True): p1 = random.choice(primes) p2 = random.choice(primes) answer = str(min(p1,p2)) + ',' + str(max(p1,p2)) + 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 +84,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] diff --git a/Code/irc/tildebot.py b/Code/irc/tildebot.py index 66ff85e..fea86a1 100755 --- a/Code/irc/tildebot.py +++ b/Code/irc/tildebot.py @@ -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(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); From f883cda857b7b13c644feb8bef277504fd27e9b9 Mon Sep 17 00:00:00 2001 From: rakiru Date: Mon, 16 Jul 2018 21:59:35 +0100 Subject: [PATCH 3/5] tildebot | Add badword filter to word-based puzzles The list isn't "complete" in any sense, and it may seem somewhat arbitrary, but I didn't want to just dump a massive file I found online into it. It should work perfectly if you want to do that though. --- Code/irc/badwords.txt | 85 +++++++++++++++++++++++++++++++++++++++++ Code/irc/dict_puzzle.py | 14 ++++++- 2 files changed, 97 insertions(+), 2 deletions(-) create mode 100644 Code/irc/badwords.txt diff --git a/Code/irc/badwords.txt b/Code/irc/badwords.txt new file mode 100644 index 0000000..714b9d3 --- /dev/null +++ b/Code/irc/badwords.txt @@ -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 diff --git a/Code/irc/dict_puzzle.py b/Code/irc/dict_puzzle.py index fb38163..1185d50 100644 --- a/Code/irc/dict_puzzle.py +++ b/Code/irc/dict_puzzle.py @@ -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,7 +25,7 @@ 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))) From 888b3e871a87abd85a93c099a722c2f658094219 Mon Sep 17 00:00:00 2001 From: rakiru Date: Mon, 16 Jul 2018 22:01:36 +0100 Subject: [PATCH 4/5] tildebot | Accept alternative correct anagrams Since this means there's multiple possible answers, I made it so that the answer can now be a function, and that gets run with the guess. This may open the door to other puzzle ideas that have been ignored due to having more than one correct answer. --- Code/irc/dict_puzzle.py | 13 ++++++++++++- Code/irc/tildebot.py | 2 +- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/Code/irc/dict_puzzle.py b/Code/irc/dict_puzzle.py index 1185d50..1d9c443 100644 --- a/Code/irc/dict_puzzle.py +++ b/Code/irc/dict_puzzle.py @@ -32,4 +32,15 @@ def get_anagram(maxlen = 6): 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] diff --git a/Code/irc/tildebot.py b/Code/irc/tildebot.py index fea86a1..6bbe838 100755 --- a/Code/irc/tildebot.py +++ b/Code/irc/tildebot.py @@ -146,7 +146,7 @@ def challenge_response(channel, user, name, time, msg): print(msg); if(challenges.has_key(user)): answer, bonus = challenges[user] - if(msg.lower() == str(answer).lower() or msg == p.number_to_words(answer)): + 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); From 3d2af2a72d765969c51f4e7f8b4d3ce209357527 Mon Sep 17 00:00:00 2001 From: rakiru Date: Tue, 17 Jul 2018 22:47:52 +0100 Subject: [PATCH 5/5] tildebot | Accept either order of prime factors --- Code/irc/puzzle.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Code/irc/puzzle.py b/Code/irc/puzzle.py index ad43d87..aa63c60 100644 --- a/Code/irc/puzzle.py +++ b/Code/irc/puzzle.py @@ -44,7 +44,12 @@ 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: