-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathirc-send-freenode.py
executable file
·81 lines (54 loc) · 1.43 KB
/
irc-send-freenode.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env python
## Written by MDrights, at July 12, 2017.
## Changelog
# 2019.06.30 revised.
import socket
import sys
content_file = sys.argv[1]
# Create a Socket
try:
irc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
except socket.error:
print 'Failed to create socket'
sys.exit()
print 'Socket Created.'
host = ''
port = 6667
remote_ip = '94.125.182.252'
# Connect to the freenode
try:
irc.connect((remote_ip, port))
except socket.error, msg:
print 'Failed to connect: ' + str(msg[0]) + ', Saying: ' + msg[1]
sys.exit()
print 'Socket connected to ' + remote_ip
# Associating:
channel = "#digitalrightscn"
botnick = "CSObot"
gecos = 'A bot helping Civil Society Organisations in China.'
command = ''
irc.send("NICK " + botnick + "\n")
irc.send("USER " + gecos + "* 8 :" + gecos + "\n")
irc.send("JOIN " + channel + "\n")
#irc.send("PRIVMSG" + channel + " " + command + " " + "\n")
# Send message from files
#data = open('/tmp/bot-final.md', 'rU')
data = open(content_file, 'rU')
#try:
# message = data.read()
#finally:
# data.close()
# Receive data
while True:
reply = irc.recv(4096)
# print reply
code = reply.split()
# print code[1]
if code[1] == '353':
for message in data:
print 'Sending: ' + message
irc.send("PRIVMSG" + " " + channel + " :" + message + "\r\n")
#print 'Message sent.'
break
irc.close()
print 'Done!'