-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIRC.py
54 lines (43 loc) · 1.04 KB
/
IRC.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
import irc.client
import sys
class IRCCat(irc.client.SimpleIRCClient):
def __init__(self, target):
irc.client.SimpleIRCClient.__init__(self)
self.target = target
def on_welcome(self, connection, event):
if irc.client.is_channel(self.target):
connection.join(self.target)
else:
self.send_it()
def on_join(self, connection, event):
self.send_it()
def on_disconnect(self, connection, event):
sys.exit(0)
def send_it(self):
while 1:
line = sys.stdin.readline().strip()
if not line:
break
self.connection.privmsg(self.target, line)
self.connection.quit("Using irc.client.py")
def main():
server, nickname, target = 'irc.rizon.net', 'william68435138', '#subplease'
s = server.split(":", 1)
server = s[0]
if len(s) == 2:
try:
port = int(s[1])
except ValueError:
print("Error: Erroneous port.")
sys.exit(1)
else:
port = 6667
c = IRCCat(target)
try:
c.connect(server, port, nickname)
except irc.client.ServerConnectionError as x:
print(x)
sys.exit(1)
c.start()
if __name__ == "__main__":
main()