Skip to content

Instantly share code, notes, and snippets.

@maestrith
Created July 29, 2014 09:52
Show Gist options
  • Save maestrith/d1f254b12863e7d70889 to your computer and use it in GitHub Desktop.
Save maestrith/d1f254b12863e7d70889 to your computer and use it in GitHub Desktop.
Posted using AHK Studio
class s{
static ctrl:=[],lc:="",main:=[]
__New(window,info){
static int
if !init
DllCall("LoadLibrary","str","scilexer.dll"),init:=1
win:=window?window:1
static count=1
pos:=info.pos?info.pos:"x0 y0"
if info.hide
pos.=" Hide"
notify:=info.label?info.label:"notify"
Gui,%win%:Add,custom,classScintilla hwndss w500 h400 %pos% +1387331584 g%notify%
this.sc:=ss,s.ctrl[ss]:=this,t:=[]
for a,b in {fn:2184,ptr:2185}
this[a]:=DllCall("SendMessageA","UInt",ss,"int",b,int,0,int,0)
this.2171(1),this.2268(3),width:=this.2276(32,"[00:00:00]")
this.2242(1,width),this.2240(1,4),this.2056(32,"Consolas"),this.2050,this.2037(65001)
this.2077(0,"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ|_+`0123456789")
this.2106(45),this.2118(0),this.2110(0)
return this
}
delete(x*){
if s.main.MaxIndex()=1
return m("Can not delete the last control")
this:=x.1
for a,b in s.main{
if (b.sc=this.sc)
s.main.remove(a)
}
DllCall("DestroyWindow",uptr,this.sc)
}
__Delete(x*){
m("should not happen")
}
__Get(x*){
return DllCall(this.fn,"Ptr",this.ptr,"UInt",x.1,int,0,int,0,"Cdecl")
}
__Call(code,lparam=0,wparam=0){
if (code="getseltext"){
VarSetCapacity(text,this.2161),length:=this.2161(0,&text)
return StrGet(&text,length,"cp0")
}
if (code="textrange"){
VarSetCapacity(text,abs(lparam-wparam)),VarSetCapacity(textrange,12,0),NumPut(lparam,textrange,0),NumPut(wparam,textrange,4),NumPut(&text,textrange,8)
this.2162(0,&textrange)
return strget(&text,"","cp0")
}
if (code="getline"){
length:=this.2350(lparam)
cap:=VarSetCapacity(text,length,0),this.2153(lparam,&text)
return StrGet(&text,length,"cp0")
}
if (code="gettext"){
cap:=VarSetCapacity(text,vv:=this.2182),this.2182(vv,&text),t:=strget(&text,vv,"cp0")
return t
}
if (code="getuni"){
cap:=VarSetCapacity(text,vv:=this.2182),this.2182(vv,&text),t:=StrGet(&text,vv,"utf-8")
return t
}
if wparam is number
info:=DllCall(this.fn,"Ptr",this.ptr,"UInt",code,"int",lparam,int,wparam,"Cdecl")
Else{
VarSetCapacity(buffer,length:=StrPut(wparam,"utf-8")),StrPut(wparam,&buffer,"utf-8")
info:=DllCall(this.fn,"Ptr",this.ptr,"UInt",code,"int",lparam,uptr,&buffer,"Cdecl")
}
return info
}
show(){
GuiControl,+Show,% this.sc
}
}
class Socket{ ;socket
static EventMsg:=0x9987,msg:=[],sockets:=[],pos:=[],TreeView:=[]
__New(info){
static init
if (!init){
DllCall("LoadLibrary","str","ws2_32","ptr"),VarSetCapacity(wsadata,394+A_PtrSize)
DllCall("ws2_32\WSAStartup","ushort",0x0000,"ptr",&wsadata),DllCall("ws2_32\WSAStartup","ushort",NumGet(wsadata,2,"ushort"),"ptr",&wsadata)
OnMessage(Socket.EventMsg,"SocketEvent"),init:=1
}
this.socket:=-1,this.users:=[]
for a,b in info
this[a]:=b
this.port:=info.port?info.port:6667
this.connect()
Sleep,200
if this.Password
this.Send("PASS " this.password)
this.Send("NICK " this.username),this.Send("USER " this.username " 0 * :" this.username)
socket.TreeView["|" this.tv:=TV_Add(this.host,0,"Focus Select Vis")]:=this,this.sc:=sc.2375,sc.2358(0,this.sc),socket.sockets.Insert(this),sc.2051(1,0xff0000),sc.2409(1,1)
for a,b in {modes:"",log:"",channels:"",autojoin:"",nicklist:""}{
this[b]:=[]
for c,d in b
this[b,d]:=[]
}
this.channels[1,"tv"]:=this.tv,this.channels[1,"sc"]:=this.sc
}
current(){
tv:=ei:=TV_GetSelection()
if !sock:=socket.TreeView["|" ei]
while,tv:=TV_GetParent(tv)
if sock:=socket.TreeView["|" tv]
break
return sock
}
nick(old,new){
for a,b in this.users[old]{
this.channels[a].users[new]:=this.channels[a].users[old],this.channels[a].users.Remove(old)
TV_Modify(b.tv,"",b.pre new),this.users[new,a]:={tv:b.tv,pre:b.pre},TV_Modify(TV_GetParent(b.tv),"Sort")
}
this.users.Remove(old)
if (old=this.username)
TV_Modify(this.tv,"",this.host " - " new),this.username:=new
}
quit(nick){
if (nick=this.username)
this.disconnect()
Else{
for a,b in this.users[nick]
this.Count(TV_GetParent(b.tv),a),TV_Delete(b.tv),this.channels[a].users.Remove(nick)
this.users.Remove(nick)
}
}
part(info){
part:=this.users[info.nick,info.chan]
if (info.nick=this.username&&part.tv)
TV_Delete(TV_GetParent(part.tv)),sc.2377(0,this.channels[info.chan].sc),this.channels.Remove(info.chan)
Else if(part.tv)
TV_Delete(part.tv),this.channels[info.chan].users.Remove(info.nick)
}
user(info){
if (info.chan&&info.user){
info.user:=RegExReplace(info.user,"A):"),obj:=this.channel({chan:info.chan})
pre:=this.modes[SubStr(info.user,1,1)]?SubStr(info.user,1,1):"",name:=pre?SubStr(info.user,2):info.user
user:=obj.users[name]:=[],tv:=TV_Add(pre name,obj.tv,"Sort")
nick:=this.users[name,info.chan]:=[]
nick.tv:=tv,nick.pre:=pre
user.tv:=tv,user.pre:=pre
GuiControl,+Redraw,SysTreeView321
}
}
channel(info){
if !obj:=this.channels[info.chan]{
obj:=this.channels[info.chan]:=[],obj.topic:=[]
obj.tv:=TV_Add(info.chan,this.tv,"Vis Sort"),obj.sc:=sc.2375
if InStr(info.chan,"#")
TV_Modify(obj.tv,"Select Vis Focus")
}
return obj
}
connect(){
next:=this.addrinfo(this.host,this.port)
sockaddrlen:=NumGet(next+0,16,"uint"),sockaddr:=NumGet(next+0,16+(2*A_PtrSize),"ptr")
if !(sockaddrlen||sockaddr)
return m("Something happened")
this.socket:=DllCall("ws2_32\socket","int",NumGet(next+0,4,"int"),"int",1,"int",6,"ptr")
if((r:=DllCall("ws2_32\WSAConnect","ptr",this.socket,uptr,sockaddr,int,sockaddrlen,"ptr",0,"ptr",0,"ptr",0,"ptr",0,"int"))=0){
DllCall("ws2_32\freeaddrinfo",uptr,next)
return Socket.Register(this,0x21)
}
this.disconnect()
}
AddrInfo(host,port){
VarSetCapacity(hints,8*A_PtrSize,0)
for a,b in {6:8,1:12}
NumPut(a,hints,b)
DllCall("ws2_32\getaddrinfo",astr,host,astr,port,"uptr",hints,"ptr*",results)
return results
}
send(msg){
msg.="`r`n"
VarSetCapacity(buffer,length:=StrPut(msg,"utf-8")),StrPut(msg,&buffer,"utf-8")
return:=DllCall("ws2_32\send","ptr",this.socket,"ptr",&buffer,"int",length-1,"int",0,"int")
}
Register(obj,msg){
a:=SocketEvent([1]),a["|" obj.socket]:=obj
return (DllCall("ws2_32\WSAAsyncSelect","ptr",obj.socket,"ptr",A_ScriptHwnd,"uint",Socket.EventMsg,"uint",msg)=0)?1:0
}
__Delete(){
this.disconnect()
}
recv(){
Critical
VarSetCapacity(buffer,1)
while,(ret:=DllCall("ws2_32\recv",ptr,this.socket,ptr,&buffer,int,1,int,0)>0)
msg.=StrGet(&buffer,1,"cp0")
VarSetCapacity(buffer,length:=StrPut(msg,"cp0")),StrPut(msg,&buffer,"cp0")
if (msg:=StrGet(&buffer,"utf-8")){
FileAppend,% msg,messages.txt
socket.msg.Insert({sock:this,msg:msg})
SetTimer,Process,10
}
}
disconnect(msg="I have to go"){
this.Send("QUIT :" msg),TV_Delete(this.tv)a:=SocketEvent([1]),a.remove("|" this.socket),this:=""
DllCall("ws2_32\WSAAsyncSelect","ptr",this.socket,"ptr",A_ScriptHwnd,"uint",0,"uint",0)=0
DllCall("ws2_32\closesocket","ptr",this.socket,"int")
this.socket:=-1
return 1
}
} ;Class Socket
display(info){
type:="msg",channel:=info.sock.channels[info.chan],nick:=info.nick?"<" info.nick "> ":"",sock:=info.sock
GuiControl,-Redraw,% sc.sc
if (channel.sc!=sc.2357){
msg:=nick info[type]
if TV_GetParent(channel.tv)
TV_Modify(channel.tv,"bold")
if !log:=sock.Log["|" channel.tv]
log:=sock.Log["|" channel.tv]:=[]
VarSetCapacity(buffer,length:=StrPut(msg,"cp0")),StrPut(msg,&buffer,"cp0")
log.Insert({time:"[" A_Hour ":" A_Min ":" A_Sec "]",msg:StrGet(&buffer,"utf-8")})
}Else{
start:=sc.2006
msg:=sc.2006?"`n" nick info[type]:nick info[type]
sc.2171(0),sc.2003(sc.2006,msg),sc.2171(1)
if msg contains http:,https:,ftp:,.com,.net,.gov,.org,www
for a,b in StrSplit(msg," "){
if b contains http:,https:,ftp:,.com,.net,.gov,.org,www
sc.2032(start+InStr(msg,b)-1),sc.2033(StrLen(Trim(b,"`t")),1)
}
line:=sc.2166(sc.2006)
sc.2530(line,"[" A_Hour ":" A_Min ":" A_Sec "]")
}
if (info.chan!=1&&InStr(info.chan,"#"))
if !sock.users[info.nick,info.chan]
sock.user({chan:info.chan,user:info.nick})
ControlGetFocus,Focus,% hwnd([1])
if (Focus!="Scintilla1")
SetTimer,End,100
Else
GuiControl,+Redraw,% sc.sc
return
end:
SetTimer,End,Off
sc.2318()
GuiControl,+Redraw,% sc.sc
return
}
editserver(){
Gui,2:Default
Gui,Margin,2,2
Gui,+Owner1
Gui,Font,,Consolas
Gui,Add,ListView,w510 r8 Grid ReadOnly,Server Name|Address (/s irc.freenode.net [username password #channel1 #channel2])
Gui,Add,Button,gadd Default,Add
Gui,Add,Button,x+10 gedit Default,Edit
Gui,Add,Button,x+10 gdelete,Delete
gosub,populate
Gui,Show,,Server List
return
populate:
serv:=settings.sn("//networks/*"),LV_Delete()
Gui,2:Default
while,ss:=serv.item[A_Index-1]
LV_Add("",ssn(ss,"@name").text,ss.text)
Loop,2
LV_ModifyCol(A_Index,"AutoHDR")
LV_Modify(1,"Select Vis Focus")
return
add:
InputBox,server,Server Nickname,Input a name to associate with this server,,275,150
if (ErrorLevel||server="")
return
InputBox,string,Server String,eg. /s irc.freenode.net [username password #channel1 #channel2...],,450,150
if (ErrorLevel||server="")
return
settings.add({path:"networks/network",att:{name:server},text:string,dup:1})
goto,populate
return
2GuiEscape:
2GuiClose:
settings.save(1)
Gui,2:Destroy
return
edit:
LV_GetText(value,LV_GetNext(),2),LV_GetText(server,LV_GetNext())
InputBox,newval,Edit The Server Value,New Value,,600,100,,,,,%value%
if (ErrorLevel||server="")
return
settings.ssn("//network[@name='" server "']").text:=newval
goto populate
return
Delete:
MsgBox,308,Are you sure?,Can not be undone!
IfMsgBox,No
return
while,next:=LV_GetNext()
LV_GetText(rem,next),rem:=settings.ssn("//network[@name='" rem "']"),rem.ParentNode.RemoveChild(rem),LV_Delete(next)
return
}
gui(){
Gui,+hwndhwnd +Resize
Gui,Margin,2,2
Gui,Add,TreeView,w150 h500 gtv +0x20
sc:=new s(1,{pos:"x+2 w500 h500"}),edit:=new s(1,{pos:"xm w652 h23 y+2"}),OnMessage(5,"Resize"),edit.2242(1,0)
edit.2171(0),Edit.2400,Edit.2013
Edit.2037(65001)
Edit.2115(1),Edit.2634(1),Edit.2660(2),edit.2110(1)
sc.2171(0),sc.2181(0,"Help:`n`tType / and then things happen."),sc.2171(1)
Edit.2112(0,":")
Hotkey,IfWinActive,% hwnd(1,hwnd)
Hotkey,Escape,Escape,On
Hotkey,Enter,Enter,On
Hotkey,Tab,Tab,On
ControlGetPos,,,,h,,ahk_id%status%
OnExit,GuiClose
Gui,Show,% settings.ssn("//gui").text,IRC
GuiControl,+Redraw,edit.sc
Resize()
return
Escape:
if Edit.2102
return Edit.2101
tv:=0,found:=0
while,tv:=TV_GetNext(tv,"F")
if TV_Get(tv,"bold"){
TV_Modify(tv,"Select Vis Focus"),found:=1
Break
}
if !(found){
Loop,2
{
tv:=A_Index=1?TV_GetSelection():0
while,tv:=TV_GetNext(tv,"F")
if (TV_GetParent(tv)!=0&&TV_GetParent(TV_GetParent(tv))=0){
TV_Modify(tv,"Select Vis Focus")
Break 2
}
}
}
return
GuiEscape:
GuiClose:
for a,b in socket.sockets
b.sendtext("QUIT :Gotta Go")
Resize("Save")
settings.save(1)
ExitApp
return
}
hwnd(win,hwnd=""){
static window:=[]
if (win.rem){
Gui,% win.rem ":Destroy"
window.remove[win.rem]
}
if IsObject(win)
return "ahk_id" window[win.1]
if !hwnd
return window[win]
window[win]:=hwnd
return % "ahk_id" hwnd
}
m(x*){
for a,b in x
list.=b "`n"
msgbox %list%
}
t(x*){
for a,b in x
list.=b "`n"
ToolTip,%list%
}
tab:
name:=Edit.textrange(start:=Edit.2266(Edit.2008,0),end:=Edit.2267(Edit.2008,0))
name:=end!=Edit.2008?SubStr(name,1,Edit.2008):name
TV_GetText(chan,TV_GetSelection())
sock:=socket.current(),list:=""
for a in sock.channels[chan].users{
if RegExMatch(a,"Ai)" name)||name=""
list.=a "-"
}
if list
Edit.2100(Edit.2008-start,Trim(list,"-"))
return
notify(){
static lastword,lastnick,lasttv,lastlines,modelist:={op:"-@",msg:"",voice:"-@,-+"}
notify:
if !IsObject(fn)
fn:=[]
for a,b in {0:"Obj",2:"Code",3:"position",4:"ch",5:"mod",6:"modType",7:"text",8:"length",9:"linesadded",10:"msg",11:"wparam",12:"lparam",13:"line",14:"fold",22:"updated"}
fn[b]:=NumGet(A_EventInfo+(A_PtrSize*a))
if(fn.code=2027){
start:=end:=sc.2008
while,sc.2010(start)=1
start--
while,sc.2010(end)=1
end++
url:=sc.textrange(start+1,end)
Run,% url
}
if(fn.code=2004)
Edit.2400
if(fn.code=2001){
info:=Edit.gettext(),start:=edit.2266(edit.2008,0)
lastword:=Trim(SubStr(info,start+1,Edit.2008))
}
if(fn.code=2022){
text:=StrGet(fn.text,"utf-8"),net:=settings.ssn("//networks/network[@name='" text "']").text
TV_GetText(channel,TV_GetSelection())
if(net)
edit.2101(),Edit.2181(0,net),Send()
Else if text in bow,count
edit.2101(),edit.2181(0,"/" text),Send()
Else if(text="help")
edit.2101(),Edit.2004(),m("Coming....eventually")
Else if(text="server")
SetTimer,showservers,1
Else if(text="edit server list")
edit.2004(),editserver()
Else if(text="exit")
SetTimer,GuiClose,1
Else if(modelist.haskey(text))
userlist(modelist[text])
Else if(socket.current().channels[channel].users[text].tv){
tt:=edit.gettext(),info:=StrSplit(tt," ").1
if info in /op,/deop,/voice,/devoice
SetTimer,send,10
}
Else
SetTimer,addspace,10
}
if(fn.code=2025){
if(edit.2103=edit.2008){
text:=Trim(SubStr(edit.gettext(),2))
if(modelist.haskey(text))
userlist(modelist[text],0)
}
return
}
if(fn.code=2008){
lines:=Edit.2154,total:=0
Loop,%Lines%
total+=Edit.2235(A_Index-1)
if(total!=lastlines)
Resize()
lastlines:=total,text:=edit.gettext()
if(SubStr(text,1,7)="/server"&&Edit.2008=1)
SetTimer,showservers,1
}
if(fn.code=2001){
text:=edit.gettext(),count:=""
if(edit.2007(edit.2008-1)=46&&edit.2007(edit.2008-2)=47)
return Edit.2645(edit.2008-2,2),edit.2100(0,"¯\_(ツ)_/¯-( ̄ー ̄)-( ͡° ͜ʖ ͡°)-彡(_°)> BAWK!-ლ(ಠ_ಠლ)")
if(SubStr(text,1,1)!="/"||InStr(text," ")!=0)
return
tt:=StrSplit(text,"/").2
cmds:="Server-afk-me-msg-Join-Op-Voice-DeOp-DeVoice-Topic-Nick-Help-Edit Server List-Exit-bow-Count"
for a,b in StrSplit(cmds,"-")
if(SubStr(b,1,StrLen(tt))=tt)
count.=b "-"
if !Count
return
if Edit.2102=0
Edit.2181(0,"/"),Edit.2025(1),Edit.2100(0,cmds)
RegExReplace(count,"-","",cc)
if(cc=1){
edit.2108(0,Trim(count,"-"))
if net:=settings.ssn("//network[@name='" Trim(count,"-") "']").text
Edit.2181(0,net),Send()
edit.2104
}
}
return
addspace:
SetTimer,addspace,Off
Edit.2003(edit.2006," ")
edit.2025(edit.2006)
return
}
Process(){
process:
info:=socket.msg.1,sock:=info.sock,channel:=1
for a,b in StrSplit(info.msg,"`r`n"){
if !b
Continue
message:=SubStr(b,InStr(b," :")+2),info:=StrSplit(b," "),RegExMatch(b,"OU):(.*)!",nick)
if (info.2="005"){
if InStr(b,"prefix"){
RegExMatch(b,"OU)PREFIX=\((.*) ",prefix),vv:=StrSplit(prefix.value(1),")"),value:=StrSplit(vv.2)
for a,c in StrSplit(vv.1)
sock.modes[c]:=value[A_Index],sock.modes[value[A_Index]]:=c
order:=sock.modes.order:=[]
for a,c in StrSplit(vv.1)
order[c]:=StrSplit(vv.2)[A_Index]
}
}
if (info.2="mode"){
;mode=4 chan=3 user=5 nick.value(1)=who gave it.
for a,b in StrSplit(info.4){
if b in +,-
operation:=b
Else{
user:=sock.channels[info.3].users[info.5]
if (operation="+")
user.pre.=sock.modes[b]
Else
user.pre:=RegExReplace(user.pre,"i)" sock.modes[b])
sock.users[info.5,info.3].pre:=sock.modes[b]
}
}
pre:=user.pre
if (StrLen(pre)>1){
for a,b in sock.modes.order
if InStr(pre,b){
pre:=b
break
}
}
TV_Modify(user.tv,"",pre info.5)
TV_Modify(TV_GetParent(user.tv),"Sort")
}
if (info.2=433)
sock.send("NICK " sock.username A_MSec)
if (info.2="nick"){
info.3:=RegExReplace(info.3,"A):")
if check is not number
sock.nick(nick.value(1),info.3)
}
if (info.2="part")
sock.part({nick:nick.value(1),chan:info.3})
if (info.2="kick")
sock.part({nick:info.4,chan:info.3})
if (info.2=1)
TV_Modify(sock.tv,"",sock.host " - " sock.username:=info.3)
/*
if (info.2=366){
t(b)
}
*/
if (info.2=353){
for a,user in StrSplit(message," ")
if user
sock.user({chan:info.5,user:user})
}
if (info.2="quit"){
sock.quit(nick.value(1))
}
if (info.2="join")
if (nick.value(1)!=sock.username)
sock.user({chan:RegExReplace(info.3,"A):"),user:nick.value(1)})
if (info.2="topic"){
topic:=sock.channels[info.3].topic:=message
TV_GetText(cc,TV_GetSelection())
if (cc=info.3)
WinSetTitle,% hwnd([1]),,% "IRC - " cc " : " topic
}
if (info.2=332)
obj:=sock.channel({chan:info.4}).topic:=message
if (info.2=376)
for a,b in sock.autojoin
sock.send("JOIN " b)
if (info.1="ping")
sock.Send("PONG :" message)
if (info.2="privmsg"){
channel:=info.3
if !InStr(channel,"#")
sock.channel({chan:channel:=nick.value(1)})
}
display({msg:message,chan:channel,sock:sock,nick:nick.value(1)})
}
socket.msg.Remove(1)
if !(socket.msg.1.msg)
SetTimer,Process,Off
return
}
resize(a="",b=""){
static width,height,sizes:=[]
if (a="save"){
WinGetPos,x,y,,,% hwnd([1])
return settings.Add({path:"gui",text:"x" x " y" y " w" width "h" height})
}
if (A_Gui!=1&&a!="")
return
if b&0xffff
width:=b&0xffff,height:=b>>16
hh:=Edit.2279(32),lines:=Edit.2154,total:=0
Loop,%Lines%
total+=Edit.2235(A_Index-1)
editheight:=hh*total+3,editheight:=height-50<editheight?height-50:editheight
socket.pos.width:=width,socket.pos.height:=height
ControlMove,SysTreeView321,,,,% height-Editheight-6,% hwnd([1])
ControlMove,,,,width-156,% height-Editheight-6,% "ahk_id" sc.sc
ControlMove,Scintilla2,,% height-editheight+29,width-4,%editheight%,% hwnd([1])
GuiControl,+Redraw,% sc.sc
}
send(){
Enter:
ControlGetFocus,Focus,% hwnd([1])
if (Focus="Scintilla2"){
if !Edit.2102
Goto Send
Else
Edit.2104
}
Return
static rainbow:=[4,7,8,3,2,13]
send:
SetTimer,Send,Off
text:=Edit.gettext(),tv:=TV_GetSelection(),Resize(),TV_GetText(channel,TV_GetSelection()),info:=StrSplit(text," "),uni:=edit.getuni()
edit.2004
if !text
return
if (info.1="/s"){
info:=StrSplit(text," ")
username:=info.3&&InStr(host1.1,"#")=0?info.3:"Guest"
password:=info.4&&InStr(host1.1,"#")=0?info.4:""
host1:=StrSplit(info.2,":")
host:=host1.1&&InStr(host1.1,"#")=0?host1.1:"localhost",port:=host.2&&InStr(host1.1,"#")=0?host.2:6667
sock:=new socket({host:host,password:password,username:username,port:port})
sock.autojoin:=[]
for a,b in info
if (SubStr(b,1,1)="#")
sock.autojoin.Insert(b)
Return
}
tv:=ei:=TV_GetSelection()
if !sock:=socket.TreeView["|" ei]
while,tv:=TV_GetParent(tv)
if sock:=socket.TreeView["|" tv]
break
if ((chan:=sock.channels[channel])&&SubStr(text,1,1)!="/"){
display({nick:sock.username,chan:channel,sock:sock,msg:uni})
return sock.send("PRIVMSG " channel " :" uni )
}Else if (info.1="/op"){
return sock.Send("MODE " channel " +o " info.2)
}Else if (info.1="/voice"){
return sock.Send("MODE " channel " +v " info.2)
}Else if(info.1="/bow"){
display({nick:sock.username,chan:channel,sock:sock,msg:"***" sock.username " bows"})
pre:="PRIVMSG " channel " :"
text:=chr(1) "ACTION bows" chr(1)
sock.send(pre text)
}Else if(info.1="/me"){
display({nick:sock.username,chan:channel,sock:sock,msg:uni})
pre:="PRIVMSG " channel " :"
text:=chr(1) "ACTION " message(info,1) chr(1)
sock.send(pre text)
}Else if (info.1="/afk"){
if pos:=InStr(sock.username,"_",0,0){
nick:=SubStr(sock.username,1,pos-1)
new:=info.2?"_" info.2:""
return sock.send("NICK " nick new)
}
new:=info.2?"_" info.2:"_afk"
return sock.send("NICK " sock.username new)
}Else if (info.1="/msg"){
sock.channel({chan:info.2})
display({nick:sock.username,chan:info.2,sock:sock,msg:message(info)})
return sock.send("PRIVMSG " info.2 " :" message(info))
}Else if (info.1="/topic"){
sock.send("TOPIC " channel " :" message(info,1))
}Else if (TV_GetParent(TV_GetSelection())=0&&SubStr(text,1,1)!="/"){
display({sock:sock,msg:text})
return sock.send(text)
}Else if (text="/p"){
return sock.send("PART " channel)
}Else if (SubStr(text,1,1)="/"){
if (info.1="/count"){
count:=1,tv:=TV_GetChild(TV_GetSelection())
while,tv:=TV_GetNext(tv)
count++
m("There are currently " count " users in the channel")
}
if (info.1="/nick")
return sock.send("NICK " info.2)
if ((info.1="/Join"||info.1="/j")){
for a,b in info
if (A_Index>1&&b!="")
sock.send("JOIN " _:=InStr(b,"#")?b:"#" b)
return
}Else
return sock.Send(SubStr(uni,2))
}
return
}
message(info,count=2){
while,text:=info[A_Index]
if A_Index>%count%
msg.=text " "
return msg
}
showservers(){
showservers:
SetTimer,showservers,Off
list:=settings.sn("//networks/*"),servers:=""
while,ll:=List.item[A_Index-1]
servers.=ssn(ll,"@name").text "-"
Edit.2004
if Edit.2008=0
Edit.2100(0,Trim(servers,"-"))
return
}
SocketEvent(info*){
Critical
static a:=[]
if info.1.1
return a
if (info.3=socket.EventMsg){
if (info.2&0xFFFF=1){
a["|" info.1].recv()
/*
if msg:=a["|" info.1].recv(){
a[info.1].msg.Insert(msg)
SetTimer,process,10
}
*/
return
}
if (info.2&0xFFFF=32)
return a["|" info.1].disconnect()
}
}
#SingleInstance,Force
if (A_PtrSize=8&&A_IsCompiled=""){
SplitPath,A_AhkPath,,dir
correct:=dir "\AutoHotkeyU32.exe"
if !FileExist(correct){
m("Requires AutoHotkey 1.1 to run")
ExitApp
}
run,"%correct%" "%A_ScriptName%",%A_ScriptDir%
ExitApp
return
}
if !FileExist("scilexer.dll")
URLDownloadToFile,http://files.maestrith.com/alpha/Studio/SciLexer.dll,Scilexer.dll
global edit,sc,settings
settings:=new xml("settings")
Gui()
#Include class scintilla.ahk
#Include class socket.ahk
#Include display.ahk
#Include editservers.ahk
#Include gui.ahk
#Include hwnd.ahk
#Include msgbox.ahk
#Include notify.ahk
#Include onrecv.ahk
#Include resize.ahk
#Include send.ahk
#Include showservers.ahk
#Include socket event.ahk
#Include tv.ahk
#Include userlist.ahk
#Include xml.ahk
#Include class scintilla.ahk
#Include class socket.ahk
#Include display.ahk
#Include editservers.ahk
#Include gui.ahk
#Include hwnd.ahk
#Include msgbox.ahk
#Include notify.ahk
#Include onrecv.ahk
#Include resize.ahk
#Include send.ahk
#Include showservers.ahk
#Include socket event.ahk
#Include tv.ahk
#Include userlist.ahk
#Include xml.ahk
tv(){
tv:
if (A_GuiEvent!="s")
return
tv:=TV_GetSelection(),ei:=A_EventInfo,TV_GetText(channel,ei),TV_Modify(ei,"-bold")
sock:=socket.current()
GuiControl,-Redraw,% sc.sc
channel:=TV_GetParent(ei)?channel:1
channel:=sock.channels[channel]
if (channel.sc){
sc.2358(0,channel.sc)
Sleep,100
sc.2051(1,0xff0000),sc.2409(1,1)
while,(b:=sock.Log["|" ei].1){
msg:=sc.2006?"`n" b.msg:b.msg
sc.2171(0),sc.2003(sc.2006,msg),sc.2171(1),line:=sc.2166(sc.2006),sc.2530(line,b.time)
sock.Log["|" A_EventInfo].Remove(1)
}
}
if !sc.2137
sc.2037(65001)
SetTimer,end,10
Edit.2400(),TV_GetText(channel,ei),topic:=sock.channels[channel].topic
if (InStr(channel,"#")&&TV_GetParent(ei)){
topic:=Trim(topic)?" : " topic:""
WinSetTitle,% hwnd([1]),,% "IRC - " channel topic
}
Else if InStr(channel,"#")
WinSetTitle,% hwnd([1]),,IRC - %channel%
Else
WinSetTitle,% hwnd([1]),,% "IRC - " sock.host
return
}
userlist(pre="",space=1){
static prefix
prefix:=pre
if space
SetTimer,addspace,10
SetTimer,userlist,100
return
userlist:
SetTimer,userlist,Off
sock:=socket.current()
TV_GetText(channel,TV_GetSelection()),userlist:=""
search:=StrSplit(prefix),list:=[]
for a,b in sock.channels[channel].users{
if (prefix){
for c,d in StrSplit(prefix,","){
info:=StrSplit(d)
if ((InStr(b.pre,info.2)&&info.1="-")||(InStr(b.pre,info.2)=0&&info.1="+"))
goto nope
}
userlist.=a "-"
nope:
}
Else
userlist.=a "-"
}
if (list:=Trim(userlist,"-"))
Edit.2100(0,list),userlist:=""
return
}
class xml{
keep:=[]
__New(param*){
if !FileExist(A_ScriptDir "\lib")
FileCreateDir,%A_ScriptDir%\lib
root:=param.1,file:=param.2
file:=file?file:root ".xml"
temp:=ComObjCreate("MSXML2.DOMDocument"),temp.setProperty("SelectionLanguage","XPath")
this.xml:=temp
ifexist %file%
temp.load(file),this.xml:=temp
else
this.xml:=this.CreateElement(temp,root)
this.file:=file
xml.keep[root]:=this
}
CreateElement(doc,root){
return doc.AppendChild(this.xml.CreateElement(root)).parentnode
}
search(node,find,return=""){
found:=this.xml.SelectNodes(node "[contains(.,'" RegExReplace(find,"&","')][contains(.,'") "')]")
while,ff:=found.item(a_index-1)
if (ff.text=find){
if return
return ff.SelectSingleNode("../" return)
return ff.SelectSingleNode("..")
}
}
lang(info){
info:=info=""?"XPath":"XSLPattern"
this.xml.temp.setProperty("SelectionLanguage",info)
}
unique(info){
if (info.check&&info.text)
return
if info.under{
if info.check
find:=info.under.SelectSingleNode("*[@" info.check "='" info.att[info.check] "']")
if info.Text
find:=this.cssn(info.under,"*[text()='" info.text "']")
if !find
find:=this.under({under:info.under,att:info.att,node:info.path})
for a,b in info.att
find.SetAttribute(a,b)
}
else
{
if info.check
find:=this.ssn("//" info.path "[@" info.check "='" info.att[info.check] "']")
else if info.text
find:=this.ssn("//" info.path "[text()='" info.text "']")
if !find
find:=this.add({path:info.path,att:info.att,dup:1})
for a,b in info.att
find.SetAttribute(a,b)
}
if info.text
find.text:=info.text
return find
}
add(info){
path:=info.path,p:="/",dup:=this.ssn("//" path)?1:0
if next:=this.ssn("//" path)?this.ssn("//" path):this.ssn("//*")
Loop,Parse,path,/
last:=A_LoopField,p.="/" last,next:=this.ssn(p)?this.ssn(p):next.appendchild(this.xml.CreateElement(last))
if (info.dup&&dup)
next:=next.parentnode.appendchild(this.xml.CreateElement(last))
for a,b in info.att
next.SetAttribute(a,b)
if info.text!=""
next.text:=info.text
return next
}
find(info){
if info.att.1&&info.text
return m("You can only search by either the attribut or the text, not both")
search:=info.path?"//" info.path:"//*"
for a,b in info.att
search.="[@" a "='" b "']"
if info.text
search.="[text()='" info.text "']"
current:=this.ssn(search)
return current
}
under(info){
new:=info.under.appendchild(this.xml.createelement(info.node))
for a,b in info.att
new.SetAttribute(a,b)
new.text:=info.text
return new
}
ssn(node){
return this.xml.SelectSingleNode(node)
}
sn(node){
return this.xml.SelectNodes(node)
}
__Get(x=""){
return this.xml.xml
}
Get(path,Default){
return value:=this.ssn(path).text!=""?this.ssn(path).text:Default
}
transform(){
static
if !IsObject(xsl){
xsl:=ComObjCreate("MSXML2.DOMDocument")
style=
(
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes" encoding="UTF-8"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
<xsl:for-each select="@*">
<xsl:text></xsl:text>
</xsl:for-each>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
)
xsl.loadXML(style),style:=null
}
this.xml.transformNodeToObject(xsl,this.xml)
}
save(x*){
if x.1=1
this.Transform()
filename:=this.file?this.file:x.1.1
file:=fileopen(filename,"rw")
file.seek(0)
file.write(this[])
file.length(file.position)
}
remove(rem){
if !IsObject(rem)
rem:=this.ssn(rem)
rem.ParentNode.RemoveChild(rem)
}
ea(path){
list:=[]
if nodes:=path.nodename
nodes:=path.SelectNodes("@*")
else if path.text
nodes:=this.sn("//*[text()='" path.text "']/@*")
else if !IsObject(path)
nodes:=this.sn(path "/@*")
else
for a,b in path
nodes:=this.sn("//*[@" a "='" b "']/@*")
while,n:=nodes.item(A_Index-1)
list[n.nodename]:=n.text
return list
}
}
ssn(node,path){
return node.selectsinglenode(path)
}
sn(node,path){
return node.selectnodes(path)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment