Skip to content

Commit 23de8bd

Browse files
committed
initial commit; currently errors out on bangs (!)
0 parents  commit 23de8bd

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed

bot.py

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#!/usr/bin/env python
2+
3+
import sys
4+
import socket
5+
import string
6+
import os
7+
import datetime
8+
from time import strftime
9+
from collections import defaultdict
10+
11+
CONF=`os.environ['HOME'] + '.pybotrc'`
12+
HOST='localhost'
13+
PORT=6667
14+
NICK='ohai'
15+
IDENT='mypy'
16+
REALNAME='s1ash'
17+
OWNER='hlmtre'
18+
CHANNELINIT='#hhorg'
19+
readbuffer=''
20+
21+
kcount = defaultdict(int)
22+
23+
def parsemsg(line):
24+
value = 0
25+
user=line[1:].split('!')
26+
username=user[0]
27+
phrase=user[1:]
28+
p=phrase[-1]
29+
q=p.split(':')
30+
p=q[-1]
31+
c=p[0]
32+
if c == ">":
33+
if username not in kcount:
34+
kcount[username] = 1
35+
else:
36+
kcount[username] += 1
37+
if kcount[username] % 3 == 0:
38+
value=1
39+
else:
40+
value=0
41+
# end of case/switch
42+
43+
44+
# logging stuff
45+
logfile=open("./logfile.txt","a")
46+
date=str(strftime("%Y-%m-%d %H:%M:%S")+'\n')
47+
logfile.write(date)
48+
logfile.write("example string\n")#(str(kcount)+'\n')
49+
logfile.close()
50+
return (value,username)
51+
52+
# end of parsemsg
53+
54+
55+
# connect to server
56+
s=socket.socket()
57+
s.connect((HOST, PORT))
58+
s.send('NICK '+NICK+'\n')
59+
s.send('USER '+IDENT+ ' 8 ' + ' bla : '+REALNAME+'\n')
60+
61+
# infinite loop to keep parsing lines
62+
63+
while 1:
64+
line=s.recv(500)
65+
if line.find('PRIVMSG') != -1:
66+
print line
67+
s.send('JOIN '+CHANNELINIT+'\n')
68+
line=line.rstrip()
69+
mybool=parsemsg(line)
70+
code=mybool[0]
71+
myusername=mybool[1]
72+
c = int(code)
73+
if c > 0:
74+
s.send('PRIVMSG ' + CHANNELINIT + ' ' + myusername + ' :>implying you\'re greentexting' +'\n')
75+
line=line.split()
76+
if (line[0] == 'PING'):
77+
s.send('PONG' + line[1] + '\n')
78+

0 commit comments

Comments
 (0)