简体   繁体   中英

My python twisted irc bot responding to commands

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 ..

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()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM