irccat plugin for supybot

  • 8 September, 2010

Like irccat but for when you are already running a Supybot instance.

import supybot

from twisted.internet import reactor, protocol
from twisted.protocols import basic

class IRCCatProtocol(basic.LineOnlyReceiver):
    delimiter = '\n'

    def lineReceived(self, text):
        irc = self.factory.irc
        for channel in irc.state.channels:
            irc.queueMsg(supybot.ircmsgs.notice(channel, text))

class IRCCat(supybot.callbacks.Plugin):
    def __init__(self, irc):
        super(IRCCat, self).__init__(irc)

        factory = protocol.Factory()
        factory.protocol = IRCCatProtocol
        factory.irc = irc

        self.server = reactor.listenTCP(12345, factory)

    def die(self):
        self.server.stopListening()

Class = IRCCat

You can then post messages with:

$ echo hai2u | nc -q0 hostname 12345

Comments (1)

Thank you, This works great

Just one thing, I'm not sure which OS you are running that nc has a -q flag. I was not able to find it in Ubuntu, centos nor macos.

The flag in those OSes seems to be -w (timeout) as in number of seconds to wait ? or perhaps you mean -i (interval) as in delay between lines being send.

Dec. 13, 2010, 3:12 p.m. #
> -q seconds: "after EOF on stdin, wait the specified number of seconds and then quit. If seconds is negative, wait forever." This is from "netcat-traditional" in Debian squeeze.