All pastes #1678063 Raw Edit

KnowledgeBot IbLib example

public python v1 · immutable
#1678063 ·published 2009-11-19 18:14 UTC
rendered paste body
#!/usr/bin/env python# -*- coding: utf-8 -*-'''	Copyright (C) 2009 by Keith Morrow	    IbLib is free software: you can redistribute it and/or modify    it under the terms of the GNU General Public License as published by    the Free Software Foundation, either version 3 of the License, or    (at your option) any later version.    IbLib is distributed in the hope that it will be useful,    but WITHOUT ANY WARRANTY; without even the implied warranty of    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    GNU General Public License for more details.    You should have received a copy of the GNU General Public License    along with IbLib.  If not, see <http://www.gnu.org/licenses/>.'''# KnowledgeBot, also iblib demoimport iblibclass Knowledge():	def ping(self, *args):		#executed when !ping is called		print "The args we got are " + str(args) + " and the sender is " + iblib.request.nick		return "The args we got are " + str(args) + " and the sender is " + iblib.request.nick	def superping(self, *args):		#this will output multiple lines		return "This is\na bot."	def pingto(self,dest):		iblib.response.destination = dest		return "Hello, " + iblib.request.nick + " has requested me to ping you."config = {	"server": "irc.rizon.net", #required	"port": 6667, #optional - 6667 is default	"channels": ['#SRL'], #optional - can join channels at any time		"nick": "KnowledgeBot", #optional - default is the name of the Root class	"user": "python", #optional - default is iblib	"real": "KnowledgeBot by NxTitle", #optional - default is the Root class followed by " in iblib"	"prefix": "!", #optional - default is "!" - note that putting an empty string will parse all messages as commands	"flooddelay": 3, #optional - default is 0 - putting 0 will make the program automatically use floodcontrol	"floodtimeout": 5000, #optional - default is 0 - time it takes until the flooddelay is reset	"floodcontrol": 1000, #optional - default is 0 - putting 0 will make the program not wait between each message		"debug": True #prints out debugging messages	}def onInit():	for i in iblib.config['channels']:		iblib.privmsg(i,"Currently executing 'afterinit' hook")iblib.hook['afterinit'].append(onInit)def onKick():	if iblib.request.dest == iblib.config["nick"]:		iblib.join(iblib.request.channel)		print "Bot was kicked from %s. Joining..." % iblib.request.channeliblib.hook['kick'].append(onKick)def onQuit():	for i in iblib.config['channels']:		iblib.privmsg(i,"Currently executing 'beforedc' hook")iblib.hook['beforedc'].append(onQuit)if __name__ == "__main__":	iblib.start(Knowledge(), config)