聚會時間公告: 因應COSCUP 2011, Kalug 8月份休會一次

九月 23, 2012
» A python example for send a message from xmlrpc to irc-bot.

This is python-irclib example.
If you use debian or ubuntu, you can install python-irclib by below command.

apt-get install python-irclib

#!/usr/bin/env python
import socket, signal
from SimpleXMLRPCServer import *
from thread import start_new_thread
from ircbot import SingleServerIRCBot

class AltXMLRPCServer(SimpleXMLRPCServer):

    finished=False

    def register_signal(self, signum):
        signal.signal(signum, self.signal_handler)

    def signal_handler(self, signum, frame):
        print "Caught signal", signum
	self.abot.shutdown()
        self.shutdown()

    def sendmsg(self, s):
	#print(s.encode('utf8'))
	for chrang in self.abot.chans:
		self.abot.connection.privmsg(chrang, s.encode('utf-8'))
	return 1

    def shutdown(self):
        self.finished=True
        return 1

    def ircbot(self, bot):
	self.abot = bot

    def serve_forever(self):
        while not self.finished: server.handle_request()

class EchoBot(SingleServerIRCBot):
    def __init__(self, chans, nickname, server):
        print "*** Connecting to IRC server %s..." % server
        SingleServerIRCBot.__init__(self, [(server, 6667)], nickname, "IRC echo bot")
        self.chans = chans

    def on_nicknameinuse(self, c, e):
        c.nick(c.get_nickname() + "_")

    def on_welcome(self, c, e):
        print "*** Connected"
        for chan in self.chans:
            c.join(chan)

    def shutdown(self):
        self.disconnect()
        self.die()

hostname=socket.gethostname()
port=8000

server = AltXMLRPCServer(("10.8.0.1", port))
print "Serving on %s:%d" %("10.8.0.1", port)

chlist=[]
bot = EchoBot(["test123"], "lovemeloveme","irc.freenode.net");
server.ircbot(bot)
server.register_function(server.shutdown)
server.register_signal(signal.SIGHUP)
server.register_signal(signal.SIGINT)
server.register_function(server.sendmsg)
start_new_thread(bot.start, ())
server.serve_forever()
print "Closed"

五月 7, 2008

Yuren's Info Area
yurinfore
is about »

tag cloud

» irssi 忽略某人的對話

非常簡單。

/ignore 暱稱

support:

biggo.com.tw

A Django site.