-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathxCombsBot.py
More file actions
executable file
·90 lines (69 loc) · 2.54 KB
/
xCombsBot.py
File metadata and controls
executable file
·90 lines (69 loc) · 2.54 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
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
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/python
import sys, socket, string, re, random, subprocess, ssl
def main():
HOST="iss.cat.pdx.edu"
PORT=6697
NICK="CombsBot"
IDENT="CombsBot"
REALNAME="Whopper's Bot. Uses Wicker's CombsDB as backend"
CHAN="#whopper"
readbuffer=""
#Random Variables _________________________________________
SerErrorCheck = 0
s = socket.socket ( socket.AF_INET, socket.SOCK_STREAM )
s = ssl.wrap_socket(s,
cert_reqs=ssl.CERT_NONE,
do_handshake_on_connect=True)
s.connect((HOST, PORT))
s.send("NICK %s\r\n" % NICK)
s.send("USER %s %s bla :%s\r\n" % (IDENT, HOST, REALNAME))
s.send("NICK %s\r\n" % NICK)
s.send("USER %s %s bla :%s\r\n" % (IDENT, HOST, REALNAME))
s.send("JOIN %s :%s\r\n" % (CHAN, "#####"))
# _________________________________________________________
while 1:
readbuffer=readbuffer+s.recv(4096)
temp=string.split(readbuffer, "\n")
readbuffer=temp.pop( )
for line in temp:
line=string.rstrip(line)
line=string.split(line)
print line
# Lengthtemp is used throughout the script, mainly to check to syntax errors in input
lengthtemp = len(line)
if lengthtemp >= 4: # only parse lines if there are at least 3 words
# _______________________________OPTIONS ________________________________________
if line[3] == ':&help':
s.send("PRIVMSG %s :%s\r\n" % (CHAN, "Options: &host <host/IP>, &owner <username> "))
if line[3] == ':&host' in line:
subprocess.call(['echo %s > queryresult' % line[4]], shell=True)
subprocess.call(["/home/whopper/CombsBot/AskDB.py host"], shell=True)
FileWriter(s, CHAN)
if line[3] == ':&owner' in line:
subprocess.call(['echo %s > queryresult' % line[4]], shell=True)
subprocess.call(["/home/whopper/CombsBot/AskDB.py owner"], shell=True)
FileWriter(s, CHAN)
# Keeps bot alive
if(line[0]=="PING"):
s.send("PONG %s\r\n" % line[1])
def FileWriter(s, CHAN):
tempfile = open("/home/whopper/CombsBot/queryresult")
i = 0
k = 0
tlist1 = []
tlist2 = []
tlist2 = tempfile.readlines()
tlist2length = len(tlist2)
for each in tlist2:
tlist1.append(each.rstrip('\r\n'))
i = i + 1
if i > 1:
for each in tlist2:
while k < tlist2length:
s.send("PRIVMSG %s :%s\r\n" % (CHAN, "%s" % tlist2[k]))
k = k + 1
else:
s.send("PRIVMSG %s :%s\r\n" % (CHAN, "%s" % tlist1[0]))
subprocess.call(['rm /home/whopper/CombsBot/queryresult'], shell=True)
if __name__ == '__main__':
main()