This repository was archived by the owner on Nov 17, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathudpserver.py
More file actions
51 lines (41 loc) · 1.61 KB
/
udpserver.py
File metadata and controls
51 lines (41 loc) · 1.61 KB
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
"""
Recent Changes IRC Bot
Gets recent changes through UDP server defined in LocalSettings
Outputs to IRC server/channel as defined
Based on https://www.mediawiki.org/wiki/User:Thrasher6670/IRC_RC_Bot
"""
from twisted.internet.protocol import DatagramProtocol
from twisted.internet import reactor
from twisted.words.protocols import irc
from twisted.internet import protocol
import sys
recver = None
class RCBot(irc.IRCClient):
nickname = raw_input("Nickname: ")
channel = raw_input("Channel: ")
def signedOn(self):
global recver
self.join(self.channel)
print "Signed on as %s." % (self.nickname,)
recver = self
identify = raw_input("Identify to services? Enter password: ")
self.msg("NickServ","IDENTIFY %s " % (identify,))
def joined(self, channel):
print "Joined %s." % (channel,)
def gotUDP(self, broadcast):
self.msg(self.channel, broadcast)
class RCFactory(protocol.ClientFactory):
protocol = RCBot
def clientConnectionLost(self, connector, reason):
print "Lost connection (%s), reconnecting." % (reason,)
connector.connect()
def clientConnectionFailed(self, connector, reason):
print "Could not connect: %s" % (reason,)
class Echo(DatagramProtocol):
def datagramReceived(self, data, (host, port)):
global recver
recver.gotUDP(data)
udpportnumber = raw_input("Listen to UDP port: ") # Port numbers are available at http://meta.brickimedia.org/wiki/IRC
reactor.listenUDP(int(udpportnumber), Echo())
reactor.connectTCP("irc.freenode.net", 6667, RCFactory())
reactor.run()