Created
January 2, 2012 01:37
-
-
Save kmaglione/1548936 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import io | |
import os | |
from queue import * | |
import subprocess | |
import sys | |
from threading import * | |
import traceback | |
from util import * | |
nick = 'eris_prime' | |
server = 'irc.oftc.net' | |
port = '6667' | |
channels = '#pentadactyl', | |
sic = '%(HOME)s/bin/sic' % os.environ | |
fifocmd = '%(HOME)s/lib/irc_fifo_oftc_in' % os.environ | |
fifoout = '%(HOME)s/lib/irc_fifo_oftc_out' % os.environ | |
call('stty', '-echo') | |
print('Pass: ', end='', file=sys.stderr) | |
sys.stderr.flush() | |
passwd = sys.stdin.readline().rstrip('\n'); | |
print('', file=sys.stderr) | |
call('stty', 'echo'); | |
outqueue = Queue() | |
def worker(): | |
while True: | |
with open(fifoout, 'w') as outfifo: | |
print(outqueue.get(), file=outfifo) | |
thread = Thread(target=worker) | |
thread.daemon = True | |
thread.start() | |
j = 0 | |
while True: | |
j += 1 | |
sicp = subprocess.Popen(('sic', | |
'-h', server, | |
'-p', str(port), | |
'-n', '%s_%d%d' % (nick, os.getpid(), j)), | |
stdin=os.open(fifocmd, os.O_RDONLY), | |
stdout=subprocess.PIPE) | |
n = 0 | |
for line in sicp.stdout: | |
try: | |
line = line.decode('UTF-8').rstrip('\n') | |
print(line) | |
outqueue.put(line) | |
if n == 0 and ' >< 376:' in line: | |
with open(fifocmd, 'w') as cmdfifo: | |
lines = [ | |
':NickServ ghost %(nick)s %(passwd)s' % globals(), | |
':NICK %(nick)s' % globals(), | |
':NickServ identify %(passwd)s' % globals() | |
] | |
lines.extend(':j %s' % chan for chan in channels) | |
print('\n'.join(lines), file=cmdfifo) | |
except: | |
traceback.print_exc(file=sys.stderr) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment