Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6123943
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:04:33+00:00 2026-05-23T16:04:33+00:00

I’m relatively new to programming and a recent project I’ve started to work on

  • 0

I’m relatively new to programming and a recent project I’ve started to work on is a chatbot in python for an irc channel I frequent.
One of my goals is to have the bot able to very basically keep track of conversations it is having with users.
I presently an using conversation objects. When a user addresses the bot, it creates a new convo object and stores a log of the conversation, the current topic, etc. in that object.
When the user speaks, if their message matches the topic of the conversation, it chooses a response based on what they’ve said and the new topic.

For example, if the bot joins, and a user says: “Hello, bot.” the conversation will be created and the topic set to “greeting”.
the bot will say hello back and if the user asks: “What’s up?”, the bot will change the topic to “currentevents”, and reply with “not much” or similar.
topic have related topic, and if the bot notices a sudden change to a topic not marked as related (questions are exceptions), it will act slightly confused and taken aback.

My question is though: I feel like my method is a bit overly complicated and unnecessary. I’m sure objects aren’t the best thing to use. What would be another approach to keeping track of a conversation and it’s topic? Be it a better way or worse, I’m just looking for ideas and a little brainstorming.

Before you say this isn’t the right place, I’ve tried asking on programmers.stackexchange.com, but I didn’t receive a relevant response, just someone who misunderstood me. I’m hoping I can get some more feedback on a more active site. In a way this is code help 🙂

Here’s the code for my current approach. There are still a few bugs and I’m sure the code is far from efficient. Any tips or help on the code is welcomed.

def __init__(slef):
    self.dicti_topics = {"None":["welcomed", "ask", "badbot", "leave"],
                         "welcomed":["welcomed", "howare", "badbot", "ask", "leave"],
                         "howare":["greetfinished", "badbot", "leave"]}

    self.dicti_lines = {"hello":"welcomed", "howareyou":"howare", "goaway":"leave", "you'rebad":"badbot", "question":"asked"}
    self.dicti_responce = dicti["Arriving dicti_responce"]

def do_actions(self):
    if len(noi.recv) > 0:
        line = False
        ##set vars
        item = noi.recv.pop(0)

        #update and trim lastrecv list
        noi.lastrecv.append(item)
        if len(noi.lastrecv) > 10: noi.lastrecv = noi.lastrecv[1:10]

        args = item.split()
        channel, user = args[0], args[1].split("!")[0]
        message = " ".join(w for w in args[2:])
        print "channel:", channel
        print "User:", user
        print "Message:", message


        if re.match("noi", message):
            if not user in noi.convos.keys():
                noi.convos[user] = []
            if not noi.convos[user]:
                noi.convos[user] = Conversation(user)
                noi.convos[user].channel = channel

                line = "What?"
                send(channel, line)
        if re.match("hello|yo|hey|ohai|ello|howdy|hi", message) and (noi.jointime - time.time() < 20):
            print "hello convo created"
            if not user in noi.convos.keys():
                noi.convos[user] = []
            if not noi.convos[user]:
                noi.convos[user] = Conversation(user, "welcomed")
                noi.convos[user].channel = channel



        #if user has an active convo
        if user in noi.convos.keys():
            ##setvars
            line = None
            convo = noi.convos[user]
            topic = convo.topic


            #remove punctuation, "noi", and make lowercase
            rmsg = message.lower()
            for c in [".", ",", "?", "!", ";"]:
                rmsg = rmsg.replace(c, "")
                #print rmsg
            rlist = rmsg.split("noi")


            for rmsg in rlist:
                rmsg.strip(" ")


                #categorize message
                if rmsg in ["hello", "yo", "hey", "ohai", "ello", "howdy", "hi"]: rmsg = "hello"
                if rmsg in ["how do you do", "how are you", "sup", "what's up"]: rmsg = "howareyou"
                if rmsg in ["gtfo", "go away", "shooo", "please leave", "leave"]: rmsg = "goaway"
                if rmsg in ["you're bad", "bad bot", "stfu", "stupid bot"]: rmsg = "you'rebad"
                #if rmsg in []: rmsg = 
                #if rmsg in []: rmsg =


                #Question handling
                r = r'(when|what|who|where|how) (are|is) (.*)'
                m = re.match(r, rmsg)
                if m: 
                    rmsg = "question"
                    responce = "I don't know %s %s %s." % (m.group(1), m.group(3), m.group(2))


                #dicti_lines -> {message: new_topic}
                #if msg has an entry, get the new associated topic
                if rmsg in self.dicti_lines.keys():
                    new_topic = self.dicti_lines[rmsg]

                    #dicti_topics
                    relatedtopics = self.dicti_topics[topic]
                    #if the topic is related, change topic
                    if new_topic in relatedtopics:
                        convo.change_topic(new_topic)
                        noi.convos[user] = convo
                        #and respond
                        if new_topic == "leave": line = random.choice(dicti["Confirm"])
                        if rmsg == "question": line = responce
                        else: line = random.choice(self.dicti_responce[new_topic])

                    #otherwise it's confused
                    else:
                        line = "Huh?"


                if line:
                    line = line+", %s." % user
                    send(channel, line)

This is the do_action of a state in a state machine.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T16:04:34+00:00Added an answer on May 23, 2026 at 4:04 pm

    having clear goals is important in programming even before you set out deciding what objects and how. Unfortunately from what I’ve read above this isn’t really clear.

    So first forget the how of the program. forget about the objects, the code and what they do.

    Now Imagine someone else was going to write for you the program. someone who is such a good programmer, they don’t need you do tell them how to code. here are some questions they might ask you.

    1. What is the purpose of your program in one sentence?
    2. explain to me as simply as possible the main terms, IRC, Conversation.
    3. what must it be able do? short bullet points.
    4. explain in steps how you would use the program eg:
      • i type in
      • it then says
      • depending on weather… it gives me a list of this…

    Having done this then forget about your convo object or whatever and think in terms of 1, 2 and 4. On Pen and paper think about the main elements of your problems i,e Conversations.Don’t Just create Objects… you’ll find them.

    Now think about the relationships of those elements in terms of how they interact. i.e.

    “Bot adds message to Topic, User adds message to Topic, messages from Topic are sent to Log.”

    this will help you find what the objects are, what they must do and what information they’ll need to store.

    Having said all that, I would say your biggest problem is your taking on more than you can chew. To begin with, for a computer to recognise words and put them into topics is quite complicated and involves linguistics and/or statistics. As a new programmer I’d tend to avoid these areas because they will simply let you down and in the process kill your motivation. start small… then go BIG. try messing with GUI programming, then make a simple calculator and stuff…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.