/
ircd.py
43 lines (34 loc) · 1.01 KB
/
ircd.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import re
# Third-party
from oyoyo.client import IRCClient
from oyoyo.cmdhandler import DefaultCommandHandler
from oyoyo import helpers
import Pyro.core
# Initialize Oyoyo
HOST = 'irc.freenode.net'
PORT = 6667
NICK = 'ieeebot'
CHANNEL = '##utkieee'
class MyHandler(DefaultCommandHandler):
def privmsg(self, nick, chan, msg):
helpers.msg(self.client, chan, "Somebody privmsged me!!")
def connect_cb(cli):
helpers.join(cli, CHANNEL)
cli = IRCClient(MyHandler, host=HOST, port=PORT, nick=NICK,
connect_cb=connect_cb)
conn = cli.connect()
# Initialize Pyro
class SendMsg(Pyro.core.ObjBase):
def __init__(self):
Pyro.core.ObjBase.__init__(self)
def send(self, message):
helpers.msg(cli, CHANNEL, message)
Pyro.core.initServer()
daemon=Pyro.core.Daemon()
uri=daemon.connect(SendMsg(),"sendmsg")
print "The daemon runs on port:",daemon.port
print "The object's uri is:",uri
# Enter main loop
while True:
conn.next()
daemon.handleRequests()