Skip to content

Instantly share code, notes, and snippets.

@joao141141
Created February 22, 2024 03:53
Show Gist options
  • Save joao141141/018dda693954ca26193cb4b8bac7baf2 to your computer and use it in GitHub Desktop.
Save joao141141/018dda693954ca26193cb4b8bac7baf2 to your computer and use it in GitHub Desktop.
stuck in this
import re
import random
class AlienBot:
def __init__(self):
self.name = None
self.alienbabble = {
'describe_planet_intent': r'.*(how|tell.*about|interest.*in).*your.*planet',
'answer_why_intent': r'why are you.*(here|asking me?\s?so?\s?many questions)\??',
'cubed_intent': r'can.*you.*cube.*number (\d+)?',
'alien_interest_intent': r'what.*about.*you\??'
}
self.responses = {
'describe_planet_intent': [
"My planet is a utopia of diverse organisms and species.",
"I am from Opidipus, the capital of the Wayward Galaxies."
],
'answer_why_intent': [
"I come in peace.",
"I am here to collect data on your planet and its inhabitants.",
"I heard the coffee is good."
],
'alien_interest_intent': [
"I don't like talking about myself",
"I'd like to keep that to me.",
"Sorry, you are asking for too much information."
]
}
def greet(self):
self.name = input("Hello stranger, what is your name? ").lower()
will_help = input(f"Hi {self.name}, I'm Etcetera. I'm not from this planet. Will you help me learn about this planet? ").lower()
if will help in self.negative_responses:
print("Ok, have a nice Earth day!")
else:
self.chat()
def make_exit(self, reply):
for exit_command in self.exit_commands:
if exit_command in reply:
print("Ok, have a nice day!")
return True
return False
def chat(self):
reply = input(random.choice(self.random_questions)).lower()
while not self.make_exit(reply):
reply = input(self.match_reply(reply)).lower()
def match_reply(self, reply):
for intent, regex_pattern in self.alienbabble.items():
found_match = re.match(regex_pattern, reply)
if found_match:
return random.choice(self.responses.get(intent, self.no_match_intent()))
return self.no_match_intent()
def describe_planet_intent(self):
responses = self.responses['describe_planet_intent']
return random.choice(responses)
def answer_why_intent(self):
responses = self.responses['answer_why_intent']
return random.choice(responses)
def cubed_intent(self, number):
number = int(number)
return f"The cube of {number} is {number**3}. Isn't that cool?"
def no_match_intent(self):
responses = ["Please, tell me more.", "Tell me more!", "Why do you say that?"]
return random.choice(responses)
def alien_interest_intent(self):
responses = self.responses['alien_interest_intent']
return random.choice(responses)
# Create an instance of AlienBot
Alienbot = AlienBot()
Alienbot.greet()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment