-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathirccat.py
executable file
·60 lines (44 loc) · 1.31 KB
/
irccat.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env python
"""
tell.py - Phenny irccat Module
Copyright 2009, Ziling Zhao
"""
import threading
from twisted.internet.protocol import Protocol, Factory
from twisted.internet import reactor
import irc
class Relay(Protocol):
def dataReceived(self, data):
"""
Given data, relay to phenny for processing, and then lose connection
"""
bot = self.factory.phenny
channel = bot.config.channels[0]
origin = irc.Origin(bot, channel, "")
event = "PRIVMSG"
user = bot.config.admins[0]
if data.startswith("MSG: "):
data = data[5:]
origin.sender = user
else:
origin.sender = channel
bytes = data
origin.nick = user
origin.user = user
origin.host = "localhost"
self.factory.phenny.dispatch(origin, (bytes, event, channel))
self.transport.loseConnection()
class RelayFactory(Factory):
protocol = Relay
def __init__(self, phenny):
self.phenny = phenny
def startcat(phenny, input):
factory = RelayFactory(phenny)
reactor.listenTCP(8123, factory, interface="localhost")
reactor.run()
startcat.event = '366'
startcat.rule = r'(.*)'
startcat.thread = True
startcat.priority = 'low'
if __name__ == '__main__':
print __doc__.strip()