KamaeliaNuts & Bolts | Components | Tools | Cookbook | Systems
wiki:( guest738168, Dev Console, Index, Recent, Edit )
class Spammer(component):
def main(self):
"""spams channel #kamtest"""
self.send(("NICK", "TheKamaeliaBot"))
self.send(("USER", "KamaeliaIRC", "stuff", "stuff", "Kamaelia IRC tester"))
self.send(("JOIN", "#kamtest"))
for _ in range(10):
self.send(("PRIVMSG", "#kamtest", "Hello world"))
yield 1
Pipeline(Spammer(), SimpleIRCClientPrefab()).run()
from Kamaelia.File.Writing import SimpleFileWriter
from Kamaelia.Chassis.Graphline import Graphline
from Axon.Component import component
import IRCClient
class BasicLogger(component):
Outboxes = {"irc" : "to IRC, for user responses and login",
"outbox" : "What we're interested in, the traffic over the channel",
"signal" : "Shutdown handling in the future",
}
def __init__(self, channel, name, formatter=IRCClient.outformat):
super(BasicLogger, self).__init__()
self.channel = channel
self.format = formatter
self.name = name
def login(self):
"""registers with the IRC server"""
self.send(("NICK", self.name), "irc")
self.send(("USER", self.name, self.name, self.name, self.name), "irc")
self.send(("JOIN", self.channel), "irc")
def main(self):
"Main loop"
self.login()
while True:
yield 1
while self.dataReady("inbox"):
data = self.recv("inbox")
formatted_data = self.format(data)
if formatted_data:
self.send(formatted_data, "outbox")
self.respondToPings(data)
def respondToPings(self, msg):
if msg[0] == 'PING':
self.send(('PONG', msg[1]), 'irc')
self.send("Sent PONG to %s \n" % msg[1], "outbox")
#now define a prefab to wire everything up
def Logger(channel, name, server='irc.freenode.net'):
return Graphline(irc = IRCClient.SimpleIRCClientPrefab(server),
logger = BasicLogger(channel, name),
log = SimpleFileWriter("%s_log.txt" % channel.lstrip('#')),
linkages = {("logger", "irc") : ("irc", "inbox"),
("irc", "outbox") : ("logger", "inbox"),
("logger", "outbox") : ("log", "inbox"),
}
)
Logger('#test', 'coolLoggerDude').run() #we're assuming that no other user has this nickname! There's no error checking otherwise.
Versions: current , 1 , 2 , 3 , 4
(C) 2005 Kamaelia Contributors, including the British Broadcasting Corporation, All Rights Reserved,
This is an ongoing community based development site. As a result the
contents of this page is the opinions of the contributors of the pages
involved not the organisations involved. Specificially, this page
may contain personal views which are not the views of the BBC.