-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbrobot.py
executable file
·59 lines (47 loc) · 1.59 KB
/
brobot.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
#!/usr/bin/python
import os
import nerdreply
from telnetlib import Telnet
import sys
import codecs
sys.stdout = codecs.getwriter('utf8')(sys.stdout)
# Configuration
channel = "&bitlebee"
nickname = os.environ["NICKNAME"]
username = os.environ["USER"]
realname = os.environ["REALNAME"]
regpass = os.environ["IRCPASSWORD"]
fbchan = os.environ["FBCHAN"]
dskey = os.environ["DARKSKYKEY"]
def sendMsg(tn, msg):
if not msg:
return
print "DEBUG: Sending msg=" + msg
tn.write(("PRIVMSG " + fbchan + " :" + msg + "\n").encode('utf-8'))
def cleanup(msg):
return msg.split("PRIVMSG " + fbchan + " :")[1]
def telnetMain():
print "DEBUG: Opening telnet handle"
tn = Telnet("localhost", 6667)
tn.set_debuglevel(5)
tn.read_until("BitlBee-IRCd initialized, please go on")
tn.write("NICK " + nickname +"\n")
tn.write("USER " + username + " 8 *: " + realname + "\n")
tn.read_until("identify yourself", 3)
print "DEBUG: Joining bitlbee"
tn.write("JOIN &bitlbee\n")
tn.write("PRIVMSG &bitlbee :identify " + regpass + "\n")
tn.read_until("facebook - Logging in: Logged in", 3)
print "DEBUG: Joining channel"
tn.write("JOIN " + fbchan + "\n")
print "DEBUG: Telnetmain finished"
regexes = nerdreply.regexes()
while True:
(idx, match, output) = tn.expect(regexes)
print "DEBUG: idx=" + str(idx)
print "DEBUG: match=" + match.group(0)
cleaned = cleanup(match.group(0))
print "DEBUG: cleanedUp=" + cleaned
sendMsg(tn, nerdreply.processRequest(idx, cleaned))
if __name__ == '__main__':
telnetMain()