By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,629 Members | 1,222 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,629 IT Pros & Developers. It's quick & easy.

Assigning and recalling a value in hellobot

P: 1
Hello all.
First of all, I'm new to this forum and pretty new to python.
I found most things about Python on the web, but now I've ran into a challenge I dont seem to be able to solve.

I've downloaded an Irc bot called “Hellobot” to learn more python.
Think I found it here > <.
Got it to give some random replies and do some calculations etc.

But now my puzzle I don't seem to get solved:
I want my bot to remember some stuff, assign some values and recall them later.
But when I assigh values with “ if message.startswith(something): “, my bot seems to forget the values when I try to recall them with another “if message.startswith(sometingelse)”.

Example to make my story a bit more clear:

Expand|Select|Wrap|Line Numbers
  1. import ircbot
  3. class HelloBot(ircbot.IRCBot):
  4.   def messageFromChannel(self, channel, user, message):
  5.     if message.startswith("hello"):
  6.       self.sendMessageToChannel(channel, "Hello to you too " + user + "!")
  7.       hello = user      
  9.    elif message.startswith(“list”):
  10.      self.sendMessageToChannel(channel, hello + “just told me hello ”)
  12.   else:
  13.     pass
  15. bot = HelloBot("Hellobot", "", ["#channel"])
  16. bot.execute()
  17. bot.close()
How can I make my bot remember what was put in in an if statement and let it recall that something in an other if statement?

Thanks in advance.
Mar 29 '08 #1
Share this Question
Share on Google+
1 Reply

P: 56
You are assigning the value to a local namespace, which is deleted once the function has been completed. To keep the value around, change "hello" to "self.hello".

For more information on namespace's, go here:
Mar 30 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.