0% found this document useful (0 votes)
2 views

SweetBot,py

Uploaded by

Tia
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

SweetBot,py

Uploaded by

Tia
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

import re

from chatterbot import ChatBot


from chatterbot.trainers import ChatterBotCorpusTrainer

# Example list of adult content-related words (you can expand this list)
adult_keywords = ["explicit", "porn", "adult", "sexual", "nudity", "swearword1",
"swearword2"]

# Function to authenticate user and assign role


def authenticate_user():
print("Welcome to SweetBot! Please enter your role.")
role = input("Enter your role (admin/user): ").lower()

# Only 'admin' users will have access to adult content


if role == "admin":
return "admin"
elif role == "user":
return "user"
else:
print("Invalid role. Please enter 'admin' or 'user'.")
return authenticate_user()

# Function to check if the input contains adult content


def contains_adult_content(text):
# Checking for adult keywords in the user's input
for word in adult_keywords:
if word in text.lower():
return True
return False

# Create the chatbot instance with SweetBot as the name


sweetbot = ChatBot('SweetBot')

# Set up the training method


trainer = ChatterBotCorpusTrainer(sweetbot)
trainer.train('chatterbot.corpus.english')

# Main chatbot function with role-based filtering


def chat():
print("Hello! Type 'quit' to end the chat.")

# Authenticate user and assign role


user_role = authenticate_user()

while True:
user_input = input("You: ")

if user_input.lower() == 'quit':
break

# Check if the input contains adult content based on the user role
if user_role == "user" and contains_adult_content(user_input):
print("SweetBot: I'm sorry, I can't respond to that. Adult content is
restricted.")
else:
response = sweetbot.get_response(user_input)
print(f"SweetBot: {response}")

if __name__ == "__main__":
chat()

You might also like