Search This Blog

Saturday, March 25, 2017

Minecraft Chat-bot built with Python

With the pollChat() option in the rbj mod I created a chat-bot named after our assistant in the office Kate. Meet <Kate-Bot> she will go by other names when you need her help. 
She is a work in progress mainly by myself and the students that want to get involved. I have instructions on easy how to's to get started in adding to the project.

To connect to the server you need to enter the IP of our server in the () of Minecraft.connect() or leave blank to use in your game.
It was easy to watch the chat go by with:

while True:
    chat =

It would print:
ChatEvent(ChatEvent.POST, 788319, hello)

I couldn't help but want to clean the return up.

chat =
        if len(str(chat)) > 23:
            ncha1 = ncha[35:]
            ncha2 = ncha1[:-2]

We have some students that call out for 'server' to get the attention of Kate or one of us so I thought about building a response to the single string 'server'
so with the following if statement, KateBot was born.

if ncha2 == 'server'"
    mc.postToChat('Please leave a message and server will get back with you')

Since that point I wanted to make her more interactive and fun to talk to so I have a never ending job of testing and trying new responses to questions.

For instance I have a trigger word string, and a response list to choose from.
GREETING_KEYWORDS = ("hello", "hi", "greetings", "sup", "what's up",)
GREETING_RESPONSES = ["<Kate-Bot>'sup PyCrafter", "<Kate-Bot>hey", "<Kate-Bot>*nods*", "<Kate-Bot>Yay PyCraft!!!"]

Then my definition for the greeting:
def greeting():
    if ncha2.lower() in GREETING_KEYWORDS:
        return mc.postToChat(random.choice(GREETING_RESPONSES)) 

So I welcome any submission to the katebot code foundation by either suggesting a trigger and response to it or writing a definition like:

def KB():
    KB_NAMES =('kbot', '<kate-bot>', 'katebot', 'kate-bot', 'kb')
    KB_RESPONSES = ['<Kate-bot>Yo!!', '<Kate-bot>Can I help you?']
    if ncha2.lower() in KB_NAMES:
        return mc.postToChat(random.choice(KB_RESPONSES))

No comments:

Post a Comment