This repository has been archived by the owner on Jul 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 31
Module HOWTO
lepinkainen edited this page Feb 27, 2013
·
4 revisions
Commands start with a cmdchar, which is . by default (for example try as an admin .ping). You can write a command handle by defining a new function command_mycommand. As a result message .mycommand would call the function.
A normal module listens to a specific trigger and responds to it:
def command_helloworld(bot, user, channel, args):
nick = getNick(user) # parses nick from nick!user@host
if channel == "#hellochannel":
bot.say(channel, "%s: Hello, World!" % nick)
You can write a handler for all irc-input (privmsg). This handler will receive all messages typed by irc users, in both queries and in channels.
import logging
log = logging.getlogger("myprivmsghandler")
def handle_privmsg(bot, user, channel, msg):
log.info("I received a message: %s" % msg)
There is also handler for urls:
import logging
log = logging.getlogger("myurlhandler")
def handle_url(bot, user, channel, msg):
log.info("I received a url: %s" % msg)
Call a method or function consecutively:
import logging
from twisted.internet import reactor
log = logging.getlogger("motionmachine")
def init(bot):
"""Called when the bot is loaded and on rehash"""
perpetual_motion_machine(60)
def perpetual_motion_machine(delay):
"""
This will execute itself every five seconds
"""
log.info('Hello World!')
reactor.callLater(delay, perpetual_motion_machine, delay)
perpetual_motion_machine(5)
Anything missing or wrong? Complain at #pyfibot @ irc.nerv.fi