0
votes

Hello People I'm building an irc bot using python twisted, everything is built but the bot doesn't respond to commands like i want it to. For example if i want to call a bot command on the irc channel i want to be able to call it like this $time and have the bot reply what time it is, i am able to get it to work like this -> crazybot $time and it prints the time but i don't want to have to type the name every time...How do i get the the bot to run the commands without calling the name first ? Here is the update -> everything connects .......

def privmsg(self, user, channel, msg):
    user = user.split('!', 1)[0]

   if not msg.startswith('#'): # not a trigger command
        return # do nothing
    command, sep, rest = msg.lstrip('#').partition(' ')
    func = getattr(self, 'command_' + command, None)

def command_time(self, *args):
    return time.asctime()

.... When i type !time there is no error and no output ..

1
Are you starting off using an existing project? or did you write this from scratch? - sberry
sscce.org or you're not going to get a useful answer. - Jean-Paul Calderone

1 Answers

0
votes

You could modify MyFirstIrcBot:

Replace ! by $ in:

if not message.startswith('!'): # not a trigger command
   return # do nothing
command, sep, rest = message.lstrip('!').partition(' ')

Add:

from datetime import datetime

# ...
def command_time(self, rest):
    return  datetime.utcnow().isoformat()