added irc client extension, it only listens for now.
This commit is contained in:
parent
d6d661c434
commit
11a7be5c68
75
build/ext_chat.py
Normal file
75
build/ext_chat.py
Normal file
@ -0,0 +1,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
|
||||||
|
|
File diff suppressed because one or more lines are too long
@ -1855,10 +1855,10 @@ static PyMethodDef EmbMethods[] = { //WARNING! don't forget to register your fun
|
|||||||
{"set_vy", emb_set_vy, METH_VARARGS|METH_KEYWORDS, "sets vy of a specified particle."},
|
{"set_vy", emb_set_vy, METH_VARARGS|METH_KEYWORDS, "sets vy of a specified particle."},
|
||||||
{"pause", emb_pause, METH_VARARGS, "pause the game."},
|
{"pause", emb_pause, METH_VARARGS, "pause the game."},
|
||||||
{"unpause", emb_unpause, METH_VARARGS, "unpause the game."},
|
{"unpause", emb_unpause, METH_VARARGS, "unpause the game."},
|
||||||
{"toggle_pause", emb_toggle_pause, METH_VARARGS, "toggle game pause."},
|
{"pause_toggle", emb_toggle_pause, METH_VARARGS, "toggle game pause."},
|
||||||
{"open_console", emb_open_console, METH_VARARGS, "open the game console."},
|
{"console_open", emb_open_console, METH_VARARGS, "open the game console."},
|
||||||
{"close_console", emb_close_console, METH_VARARGS, "close the game console."},
|
{"console_close", emb_close_console, METH_VARARGS, "close the game console."},
|
||||||
{"toggle_console", emb_toggle_console, METH_VARARGS, "toggle the game console."},
|
{"console_toggle", emb_toggle_console, METH_VARARGS, "toggle the game console."},
|
||||||
{"console_more", emb_console_more, METH_VARARGS, "turns the more indicator on."},
|
{"console_more", emb_console_more, METH_VARARGS, "turns the more indicator on."},
|
||||||
{"console_less", emb_console_less, METH_VARARGS, "turns the more indicator off."},
|
{"console_less", emb_console_less, METH_VARARGS, "turns the more indicator off."},
|
||||||
{"get_pmap", emb_get_pmap, METH_VARARGS, "get the pmap value."},
|
{"get_pmap", emb_get_pmap, METH_VARARGS, "get the pmap value."},
|
||||||
|
@ -75,49 +75,21 @@ def _handle(txt):
|
|||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
error(ex)
|
error(ex)
|
||||||
|
|
||||||
#optional key handler:
|
|
||||||
"""def keypress(key):
|
|
||||||
try:
|
|
||||||
_key(key)
|
|
||||||
except Exception as ex:
|
|
||||||
error(ex)"""
|
|
||||||
def _key(key):
|
|
||||||
print "key %s"%key
|
|
||||||
#optional step handler:
|
|
||||||
|
|
||||||
"""
|
_extensions=[]
|
||||||
|
def loadext(fname):
|
||||||
|
_extensions.append(__import__(fname))
|
||||||
|
|
||||||
|
def keypress(key):
|
||||||
|
try:
|
||||||
|
for item in _extensions:
|
||||||
|
item.key(key)
|
||||||
|
except Exception as ex:
|
||||||
|
error(ex)
|
||||||
|
|
||||||
def step():
|
def step():
|
||||||
try:
|
try:
|
||||||
a=handle.glob
|
for item in _extensions:
|
||||||
except:
|
item.step()
|
||||||
clean()
|
|
||||||
try:
|
|
||||||
_step()
|
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
error(ex)"""
|
error(ex)
|
||||||
|
|
||||||
def _step():
|
|
||||||
try:
|
|
||||||
a=step.i
|
|
||||||
a=step.txt
|
|
||||||
except:
|
|
||||||
step.i=0
|
|
||||||
step.txt="!FUCK YEAH!"
|
|
||||||
#toggle_pause()
|
|
||||||
mouse=tpt.get_mouse()
|
|
||||||
step.txt=repr(mouse)
|
|
||||||
xx=50+abs(25-(step.i%50))
|
|
||||||
w=tpt.get_width(step.txt)+16
|
|
||||||
r=0
|
|
||||||
g=0
|
|
||||||
b=0
|
|
||||||
if(mouse[0]>xx-8 and mouse[0]<xx+w-8 and mouse[1]>92 and mouse[1]<92+32):
|
|
||||||
r=255
|
|
||||||
if(mouse[2][0]):
|
|
||||||
g=255
|
|
||||||
if(mouse[2][2]):
|
|
||||||
b=255
|
|
||||||
tpt.draw_fillrect(xx-8,92,w,32,r,g,b,128)
|
|
||||||
tpt.draw_rect(xx-8,92,w,32,255,255,255)
|
|
||||||
tpt.draw_text(xx,100,step.txt,255,255,255)
|
|
||||||
step.i+=1
|
|
||||||
|
Reference in New Issue
Block a user