summaryrefslogtreecommitdiff
path: root/build/ext_chat.py
blob: 2e7ab2d2b550ac7083b6da6cf52fb03bf46044cd (plain)
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
import tpt
import sys
import time
import socket

HOST="irc.freenode.net"
PORT=6667
NICK="doxin[tpt]"
IDENT="doxin"
REALNAME="lieuwe"
CHANNEL="#powder"
readbuffer=""

def raw(s,st):
    s.send("%s\n\r"%st)

frame=0
s=None
rec=[("connected.",255,0,0,128)]
readbuffer=""


def key(key) :
    #print "got %s"%key
    pass

def step():
    global frame,s,rec,readbuffer
    frame+=1
    if(frame==1):
        tpt.console_close()
    if(frame==2):
        tpt.draw_fillrect(0,0,612,384,0,0,0,128)
        tpt.draw_text(32,32,"opening connection\nhold on to your pants.",255,255,255)
    if(frame==3):
        s=socket.socket( )
        s.connect((HOST, PORT))
        raw(s,"NICK %s" % NICK)
        raw(s,"USER %s %s bla :%s" % (IDENT, HOST, REALNAME))
        s.settimeout(0)
    if(frame==120):
        raw(s,"JOIN %s"%CHANNEL)
        rec.append(("joined",255,0,0,255))
    if(frame>=3):
        try:
            readbuffer=readbuffer+s.recv(1024)
        except IOError:
            pass
        else:
            temp=readbuffer.split("\n")
            readbuffer=temp.pop()

            for line in temp:
                line=line.strip()
                #print line
                line=line.split()
                if(line[1]=="PRIVMSG"):
                    #:doxin!~lieuwe@unaffiliated/lieuwe PRIVMSG doxin[tpt] :some shit
                    frm=line[0][1:].partition("!")[0]
                    msg=' '.join(line[3:])[1:]
                    tmp=["<",frm,"> ",msg]
                    if(line[2]==NICK):
                        rec.append((''.join(tmp),255,255,255,255))
                    else:
                        rec.append((''.join(tmp),255,255,255,128))
                if(line[0]=="PING"):
                    raw(s,"PONG %s"%line[1])
    
        yy=32
        if(len(rec)>20):
            rec=rec[20:]
        for item in rec:
            tpt.draw_text(8,yy,item[0],item[1],item[2],item[3],item[4])
            yy+=8