Author Topic: Requesting "!seen" script  (Read 33586 times)

James Revan

  • Newbie
  • *
  • Posts: 32
Re: Requesting "!seen" script
« Reply #15 on: January 23, 2008, 12:25:08 AM »
Really big thank you for the script, i already set it up, and no problems so far. To bad you have to run the /scan command every time you start icechat, but i just used the autoperform list. If anything will be not as it supposed to be i'll PM you.

Morio

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 256
Re: Requesting "!seen" script
« Reply #16 on: January 23, 2008, 03:01:59 AM »
The thig is the /scan command must be run after you have joined all channels, so autoperform isn't a very good option for that. This script is more designed for people that never shut down icechat. There will be some problems with people that have parted while you were offline, because the script will still think they are online, I think I could make a small change to the scan sub to fix that.

Another thing, the script won't work very well (at all?) for channels with '[' or ']' in the channelname.

I will make the updates and post them as soon as possible.
"I don't know what World War 3 will be fought with, but I know World War 4 with be fought with sticks and stones." - Albert Einstein

James Revan

  • Newbie
  • *
  • Posts: 32
Re: Requesting "!seen" script
« Reply #17 on: January 23, 2008, 04:28:01 AM »
Well i ment that i use the autoperform list manually, its much easier for me, cause i sit on about 20-30 channels, and writing /scan #channel for every one of them every time i turn on IC would take too long.

Morio

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 256
Re: Requesting "!seen" script
« Reply #18 on: January 23, 2008, 07:02:16 AM »
ok, as long as the /scan command is run after you have joined all channels it's ok.

Anyway, here's the script with the updates/fixes

Code: [Select]
Sub ONJOIN(Nickname,Host,Channel,ServerNumber)
  writeinifile "seen.ini",Channel,"join:" & Nickname,GetIdentifier("$day") & "." & GetIdentifier("$monthnum") & "." & GetIdentifier("$year") & " at " & GetIdentifier("$time")
  writeinifile "seen.ini",Channel,"part:" & Nickname,""
End Sub


Sub ONPART(Nickname,Host,Channel,Reason,ServerNumber)
  writeinifile "seen.ini",Channel,"part:" & Nickname,GetIdentifier("$day") & "." & GetIdentifier("$monthnum") & "." & GetIdentifier("$year") & " at " & GetIdentifier("$time")
  writeinifile "seen.ini",Channel,"join:" & Nickname,""
End Sub

Sub ONQUIT(Nickname,Host,Reason,ServerNumber)

if FileExists(getidentifier("$scriptdir")+"seen.ini") then
  channels = sections(getidentifier("$scriptdir") + "seen.ini")
    for c=lbound(channels) to ubound(channels)-1
      channel = channels(c)
      If Len(channel) > 0 then
      keys = options(getidentifier("$scriptdir") + "seen.ini",channel)
      for k=lbound(keys) to ubound(keys)
        key = keys(k)
        If instr(key,Nickname) then
          Writeinifile "seen.ini",channel,"part:" + Nickname,GetIdentifier("$day") & "." & GetIdentifier("$monthnum") & "." & GetIdentifier("$year") & " at " & GetIdentifier("$time")
          Writeinifile "seen.ini",channel,"join:" + Nickname,""
        End if
      next
    End If
    next
End If
End Sub

Sub ONKICK(Nickname,Host,Channel,WhoKicked,Reason,ServerNumber)
  writeinifile "seen.ini",Channel,"part:" & Nickname,GetIdentifier("$day") & "." & GetIdentifier("$monthnum") & "." & GetIdentifier("$year") & " at " & GetIdentifier("$time")
  writeinifile "seen.ini",Channel,"join:" & Nickname,""
End Sub

Sub ONNICK(NewNick,OldNick,ServerNumber)
if FileExists(getidentifier("$scriptdir")+"seen.ini") then
  channels = sections(getidentifier("$scriptdir") + "seen.ini")
    for c=lbound(channels) to ubound(channels)-1
      channel = channels(c)
      If Len(channel) > 0 then
      keys = options(getidentifier("$scriptdir") + "seen.ini",channel)
      for k=lbound(keys) to ubound(keys)
        key = keys(k)
        If instr(key,OldNick) then
          Writeinifile "seen.ini",channel,"join:" + OldNick,""
          Writeinifile "seen.ini",channel,"part:" + OldNick,""
          Writeinifile "seen.ini",channel,"join:" + NewNick,""
          Writeinifile "seen.ini",channel,"part:" + NewNick,""
          Writeinifile "seen.ini",channel,"join:" + NewNick,GetIdentifier("$day") & "." & GetIdentifier("$monthnum") & "." & GetIdentifier("$year") & " at " & GetIdentifier("$time")
          Writeinifile "seen.ini",channel,"part:" + OldNick,GetIdentifier("$day") & "." & GetIdentifier("$monthnum") & "." & GetIdentifier("$year") & " at " & GetIdentifier("$time")
        End if
      next
    End If
    next
End If
End Sub


Sub ONTEXT(Message,Channel,Nickname,Host,ServerNumber)
if len(message) > 6 then
  if left(Message,5) = "!seen" then

    Who = Mid(Message,7)
    When = getinifile("seen.ini",Channel,"join:" & Who,"")
   
      If Len(When) > 0 then
        SendCommand "/msg " & Channel & " " & Who & " is in this channel right now",ServerNumber
      End If

      If Len(When) = 0 then

        When = getinifile("seen.ini",Channel,"part:" & Who,"")

        If Len(When) > 0 and Not When = "pwo" then
          SendCommand "/msg " & Channel & " " & Who & " was last seen on " & When,ServerNumber
        End If

        If Len(When) = 0 then
          SendCommand "/msg " & Channel & " " & Who & " has never been seen on this channel",ServerNumber
        End If

        If When = "pwo" then
          SendCommand "/msg " & Channel & " " & Who & " seems to have left the channel or changed his nick while I was offline",ServerNumber
        End If
      End If
     

  end if
end if
End sub

Sub scan(s_channel)
if FileExists(getidentifier("$scriptdir")+"seen.ini") then
  dim objFSo, objFile
  Set objFSO = CreateObject("Scripting.FileSystemObject")
  Set objFile = objFSO.OpenTextFile(getidentifier("$scriptdir")+"seen.ini",1)
  sText = objFile.ReadAll
  sText = Left(sText,InStr(sText,"[End]")-2)
  If s_channel = "$1" then
    arr = Split(Stext,vbCrLf)
      Text = ""
      For i = LBound(arr) to UBound(arr)
        if Len(arr(i)) > 4 and Left(arr(i),4) = "join" then
          arr(i) = "part" & Mid(arr(i),InStr(arr(i),":"))
          arr(i) = Left(arr(i),InStr(arr(i),"=")) & "pwo"
        End If
        If Not Text = "" then
          Text = Text & vbCrLf & arr(i)
        End If
        If Text = "" then
          Text = arr(i)
        End If
      Next
    End If

  Set objFSO = CreateObject("Scripting.FileSystemObject")
  Set objFile = objFSO.OpenTextFile(getidentifier("$scriptdir")+"seen.ini",2)
  objFile.writeLine(Text)
  objFile.close




End If


NickCount = 0
ChanCount = 0

If s_channel = "$1" then


  for i = 1 to GetIdentifier("$totalservers")

    Chanlist = GetIdentifier("$channels",i)

      channels = Split(Chanlist," ")

      for j = 0 to Ubound(channels)
        ChanCount = ChanCount + 1
        channel = channels(j)

        Nicknames = Nicks(channel,i)
        Nicknames = Split(Nicknames," ")

        for k = 0 to UBound(Nicknames)
        NickCount = NickCount + 1
        Nick = Nicknames(k)
        writeinifile "seen.ini",Channel,"join:" & Nick,""
        writeinifile "seen.ini",Channel,"part:" & Nick,""
        writeinifile "seen.ini",Channel,"join:" & Nick,GetIdentifier("$day") & "." & GetIdentifier("$monthnum") & "." & GetIdentifier("$year") & " at " & GetIdentifier("$time")
        next
      next

  next

  SendCommand "/echo -a A Total of " & NickCount & " Nicknames found on " & ChanCount & " channels, on " & GetIdentifier("$totalservers") & " networks"

End If

If Not s_channel = "$1" then
  Nicknames = Nicks(s_channel,GetIdentifier("$currentservernumber"))
  Nicknames = Split(Nicknames," ")

  for i = 0 to UBound(Nicknames)
    NickCount = NickCount + 1
    Nick = Nicknames(i)
    writeinifile "seen.ini",s_channel,"join:" & Nick,GetIdentifier("$day") & "." & GetIdentifier("$monthnum") & "." & GetIdentifier("$year") & " at " & GetIdentifier("$time")
  next

  SendCommand "/echo -a " & NickCount & " Nicknames found on channel " & s_channel

End If


  WriteIniFile "seen.ini","End","end","end"
  WriteIniFile "seen.ini","End","end",""

End Sub


Function sections(fname)
  dim objFSo, objFile
  Set objFSO = CreateObject("Scripting.FileSystemObject")
  Set objFile = objFSO.OpenTextFile(fname,1)
  sText = objFile.ReadAll
  If Len(sText) > 0 then
    arr = split(sText,vbCrLf)
    text = ""
    for i=lbound(arr) to ubound(arr)
      if left(arr(i),1)="[" then
        if len(text)>0 then
          text = text & vbCrLf & mid(arr(i),2,len(arr(i))-2)
        else
          text = mid(arr(i),2,len(arr(i))-2)
        end if
      end if
    next
    sections = split(text,vbCrLf)
  End If
End Function
 
Function options(fname,section)
  dim objFSo, objFile
  Set objFSO = CreateObject("Scripting.FileSystemObject")
  Set objFile = objFSO.OpenTextFile(fname,1)
  sText = objFile.ReadAll
  If Len(sText) > 0 then
    arr = split(sText,vbCrLf)
    text = ""
    cur = 0
    for i=lbound(arr) to ubound(arr)
      if left(arr(i),1)="[" then
        cur = (mid(arr(i),2,len(arr(i))-2)=section)
      else
        if cur then
          if len(text)>0 then
            text = text & vbCrLf & split(arr(i),"=")(0)
          else
            text = split(arr(i),"=")(0)
          end if
        end if
      end if
    next
    options = split(text,vbCrLf)
  End If
End Function

Function FileExists(fname)
Set fso = CreateObject("Scripting.FileSystemObject")
FileExists = fso.FileExists(fname)
End Function

If you join a channel that you have never been on before it's ok to use the '/scan #channelname" command, but if it isn't a new channel for you and you have been there before, you need to scan through the entire channel list with the '/scan' command ('/scan #channelname' won't work properly)

when using the '/scan' command ('/scan #channelname' won't work), the people who were on the channel when you left but aren't there now, will get a "pwo" tag (parted while offline) and when someone tries to check when they have been seen, they get the message 'Nickname seems to have left the channel or changed his nick while I was offline"
"I don't know what World War 3 will be fought with, but I know World War 4 with be fought with sticks and stones." - Albert Einstein

James Revan

  • Newbie
  • *
  • Posts: 32
Re: Requesting "!seen" script
« Reply #19 on: January 23, 2008, 07:13:30 AM »
Could you change the script so it would be automaticly updated? As it is right now it says the nick someone is looking for is on the channel when it quited, and i have to run the scan command again.

Is this how it should work? Or am I doing something wrong?

Morio

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 256
Re: Requesting "!seen" script
« Reply #20 on: January 23, 2008, 07:24:33 AM »
when you quit you have to scan again after connecting. That's just the way it'll have to be, since there's now way of knowing what happens in the channel while you are offline.
"I don't know what World War 3 will be fought with, but I know World War 4 with be fought with sticks and stones." - Albert Einstein

Morio

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 256
Re: Requesting "!seen" script
« Reply #21 on: January 23, 2008, 07:33:13 AM »
And also my script works pretty much in the same way as the one you sent me (I think) if you look at the seen .ini it will look something like:
[#channel]
join:somenick=somedate and sometime
part:someothernick=somedate = sometime
.
.
.


when someone types !seen somenick the script returns the value after the '=' it first checks for joins, if it finds a line with 'join:somenick' in the correct section for that channel it will say that the person is online, because he hasn't been seen leaving or changing his nick. If it doesn't find a line starting with that it will search for a line starting with 'part:somenick' again in the correct section, if that like is found and the stuff after the '0' isn't 'pwo' it will return the time fo the part, and if the text after the '=' is 'pwo' it will tell that the nick has disappeared while you were offline.

when a person changes his nick it will record it as the old nick parting and the new one joining.
"I don't know what World War 3 will be fought with, but I know World War 4 with be fought with sticks and stones." - Albert Einstein

James Revan

  • Newbie
  • *
  • Posts: 32
Re: Requesting "!seen" script
« Reply #22 on: January 23, 2008, 07:34:27 AM »
I didn't quit..
There was a guy, lets say his nick was "dude". I recorded his nick when he was on the channel, then he quitted. I asked my friend to type !seen dude and the script was telling that "dude" is still on the channel when he quitted 5 minutes earlier.

Morio

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 256
Re: Requesting "!seen" script
« Reply #23 on: January 23, 2008, 07:43:04 AM »
hmm, that's weird, I've been testing the script, and I see now problems with recording the quits and it does remove the join from the file too.

The channel doesn't happen to have '[' or ']' in the name, does it?
"I don't know what World War 3 will be fought with, but I know World War 4 with be fought with sticks and stones." - Albert Einstein

James Revan

  • Newbie
  • *
  • Posts: 32
Re: Requesting "!seen" script
« Reply #24 on: January 23, 2008, 07:51:14 AM »
Nope, it has a "." if that changes anything

Morio

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 256
Re: Requesting "!seen" script
« Reply #25 on: January 23, 2008, 09:10:54 AM »
The '.' should make no difference.

Have you tried checking the seen.ini file? There should be a line like part:dude=... and no line like join:dude=... in the section for that channel, and the section should appear only once.
"I don't know what World War 3 will be fought with, but I know World War 4 with be fought with sticks and stones." - Albert Einstein

James Revan

  • Newbie
  • *
  • Posts: 32
Re: Requesting "!seen" script
« Reply #26 on: January 23, 2008, 10:29:43 AM »
Well checked that now, rather strange. Got only one channel when it should be 23

Morio

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 256
Re: Requesting "!seen" script
« Reply #27 on: January 23, 2008, 11:11:59 AM »
what message do you get when you run the '/scan' command? It should be something like 'x nicknames found on y channels, on z servers'
"I don't know what World War 3 will be fought with, but I know World War 4 with be fought with sticks and stones." - Albert Einstein

James Revan

  • Newbie
  • *
  • Posts: 32
Re: Requesting "!seen" script
« Reply #28 on: January 23, 2008, 02:10:34 PM »
what message do you get when you run the '/scan' command? It should be something like 'x nicknames found on y channels, on z servers'
Yeah, it is like this.

Morio

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 256
Re: Requesting "!seen" script
« Reply #29 on: January 24, 2008, 03:33:46 AM »
Could you tell me the exact numbers in the message?

Also did you check the seen.in i throughly?

Also I made a security update to the script, as it could be abused, now it won't respond to messages where the nickname part starts with '!', '+', '.' or if it contains epmty spaces (this could be abused by typing '!seen !somecommand' then the reply would be '!somecommand has never been seen on this channel') And afaik, no nicknames can contain those characters.

Code: [Select]
Sub ONJOIN(Nickname,Host,Channel,ServerNumber)
  writeinifile "seen.ini",Channel,"join:" & Nickname,GetIdentifier("$day") & "." & GetIdentifier("$monthnum") & "." & GetIdentifier("$year") & " at " & GetIdentifier("$time")
  writeinifile "seen.ini",Channel,"part:" & Nickname,""
End Sub


Sub ONPART(Nickname,Host,Channel,Reason,ServerNumber)
  writeinifile "seen.ini",Channel,"part:" & Nickname,GetIdentifier("$day") & "." & GetIdentifier("$monthnum") & "." & GetIdentifier("$year") & " at " & GetIdentifier("$time")
  writeinifile "seen.ini",Channel,"join:" & Nickname,""
End Sub

Sub ONQUIT(Nickname,Host,Reason,ServerNumber)

if FileExists(getidentifier("$scriptdir")+"seen.ini") then
  channels = sections(getidentifier("$scriptdir") + "seen.ini")
    for c=lbound(channels) to ubound(channels)-1
      channel = channels(c)
      If Len(channel) > 0 then
      keys = options(getidentifier("$scriptdir") + "seen.ini",channel)
      for k=lbound(keys) to ubound(keys)
        key = keys(k)
        If instr(key,Nickname) then
          Writeinifile "seen.ini",channel,"part:" + Nickname,GetIdentifier("$day") & "." & GetIdentifier("$monthnum") & "." & GetIdentifier("$year") & " at " & GetIdentifier("$time")
          Writeinifile "seen.ini",channel,"join:" + Nickname,""
        End if
      next
    End If
    next
End If
End Sub

Sub ONKICK(Nickname,Host,Channel,WhoKicked,Reason,ServerNumber)
  writeinifile "seen.ini",Channel,"part:" & Nickname,GetIdentifier("$day") & "." & GetIdentifier("$monthnum") & "." & GetIdentifier("$year") & " at " & GetIdentifier("$time")
  writeinifile "seen.ini",Channel,"join:" & Nickname,""
End Sub

Sub ONNICK(NewNick,OldNick,ServerNumber)
if FileExists(getidentifier("$scriptdir")+"seen.ini") then
  channels = sections(getidentifier("$scriptdir") + "seen.ini")
    for c=lbound(channels) to ubound(channels)-1
      channel = channels(c)
      If Len(channel) > 0 then
      keys = options(getidentifier("$scriptdir") + "seen.ini",channel)
      for k=lbound(keys) to ubound(keys)
        key = keys(k)
        If instr(key,OldNick) then
          Writeinifile "seen.ini",channel,"join:" + OldNick,""
          Writeinifile "seen.ini",channel,"part:" + OldNick,""
          Writeinifile "seen.ini",channel,"join:" + NewNick,""
          Writeinifile "seen.ini",channel,"part:" + NewNick,""
          Writeinifile "seen.ini",channel,"join:" + NewNick,GetIdentifier("$day") & "." & GetIdentifier("$monthnum") & "." & GetIdentifier("$year") & " at " & GetIdentifier("$time")
          Writeinifile "seen.ini",channel,"part:" + OldNick,GetIdentifier("$day") & "." & GetIdentifier("$monthnum") & "." & GetIdentifier("$year") & " at " & GetIdentifier("$time")
        End if
      next
    End If
    next
End If
End Sub


Sub ONTEXT(Message,Channel,Nickname,Host,ServerNumber)
if len(message) > 6 then
  if left(Message,5) = "!seen" then

    Who = Mid(Message,7)
    When = getinifile("seen.ini",Channel,"join:" & Who,"")
    If Not (Left(Who,1) = "!" or Left(Who,1) = "+" or Left(Who,1) = "." or InStr(Who," ") > 0)then
   
      If Len(When) > 0 then
        SendCommand "/msg " & Channel & " " & Who & " is in this channel right now",ServerNumber
      End If

      If Len(When) = 0 then

        When = getinifile("seen.ini",Channel,"part:" & Who,"")

        If Len(When) > 0 and Not When = "pwo" then
          SendCommand "/msg " & Channel & " " & Who & " was last seen on " & When,ServerNumber
        End If

        If Len(When) = 0 then
          SendCommand "/msg " & Channel & " " & Who & " has never been seen on this channel",ServerNumber
        End If

        If When = "pwo" then
          SendCommand "/msg " & Channel & " " & Who & " seems to have left the channel or changed his nick while I was offline",ServerNumber
        End If
      End If
     
    End If
  End if
End if
End sub

Sub scan(s_channel)
if FileExists(getidentifier("$scriptdir")+"seen.ini") then
  dim objFSo, objFile
  Set objFSO = CreateObject("Scripting.FileSystemObject")
  Set objFile = objFSO.OpenTextFile(getidentifier("$scriptdir")+"seen.ini",1)
  sText = objFile.ReadAll
  sText = Left(sText,InStr(sText,"[End]")-2)
  If s_channel = "$1" then
    arr = Split(Stext,vbCrLf)
      Text = ""
      For i = LBound(arr) to UBound(arr)
        if Len(arr(i)) > 4 and Left(arr(i),4) = "join" then
          arr(i) = "part" & Mid(arr(i),InStr(arr(i),":"))
          arr(i) = Left(arr(i),InStr(arr(i),"=")) & "pwo"
        End If
        If Not Text = "" then
          Text = Text & vbCrLf & arr(i)
        End If
        If Text = "" then
          Text = arr(i)
        End If
      Next
    End If

  Set objFSO = CreateObject("Scripting.FileSystemObject")
  Set objFile = objFSO.OpenTextFile(getidentifier("$scriptdir")+"seen.ini",2)
  objFile.writeLine(Text)
  objFile.close




End If


NickCount = 0
ChanCount = 0

If s_channel = "$1" then


  for i = 1 to GetIdentifier("$totalservers")

    Chanlist = GetIdentifier("$channels",i)

      channels = Split(Chanlist," ")

      for j = 0 to Ubound(channels)
        ChanCount = ChanCount + 1
        channel = channels(j)

        Nicknames = Nicks(channel,i)
        Nicknames = Split(Nicknames," ")

        for k = 0 to UBound(Nicknames)
        NickCount = NickCount + 1
        Nick = Nicknames(k)
        writeinifile "seen.ini",Channel,"join:" & Nick,""
        writeinifile "seen.ini",Channel,"part:" & Nick,""
        writeinifile "seen.ini",Channel,"join:" & Nick,GetIdentifier("$day") & "." & GetIdentifier("$monthnum") & "." & GetIdentifier("$year") & " at " & GetIdentifier("$time")
        next
      next

  next

  SendCommand "/echo -a A Total of " & NickCount & " Nicknames found on " & ChanCount & " channels, on " & GetIdentifier("$totalservers") & " networks"

End If

If Not s_channel = "$1" then
  Nicknames = Nicks(s_channel,GetIdentifier("$currentservernumber"))
  Nicknames = Split(Nicknames," ")

  for i = 0 to UBound(Nicknames)
    NickCount = NickCount + 1
    Nick = Nicknames(i)
    writeinifile "seen.ini",s_channel,"join:" & Nick,GetIdentifier("$day") & "." & GetIdentifier("$monthnum") & "." & GetIdentifier("$year") & " at " & GetIdentifier("$time")
  next

  SendCommand "/echo -a " & NickCount & " Nicknames found on channel " & s_channel

End If


  WriteIniFile "seen.ini","End","end","end"
  WriteIniFile "seen.ini","End","end",""

End Sub


Function sections(fname)
  dim objFSo, objFile
  Set objFSO = CreateObject("Scripting.FileSystemObject")
  Set objFile = objFSO.OpenTextFile(fname,1)
  sText = objFile.ReadAll
  If Len(sText) > 0 then
    arr = split(sText,vbCrLf)
    text = ""
    for i=lbound(arr) to ubound(arr)
      if left(arr(i),1)="[" then
        if len(text)>0 then
          text = text & vbCrLf & mid(arr(i),2,len(arr(i))-2)
        else
          text = mid(arr(i),2,len(arr(i))-2)
        end if
      end if
    next
    sections = split(text,vbCrLf)
  End If
End Function
 
Function options(fname,section)
  dim objFSo, objFile
  Set objFSO = CreateObject("Scripting.FileSystemObject")
  Set objFile = objFSO.OpenTextFile(fname,1)
  sText = objFile.ReadAll
  If Len(sText) > 0 then
    arr = split(sText,vbCrLf)
    text = ""
    cur = 0
    for i=lbound(arr) to ubound(arr)
      if left(arr(i),1)="[" then
        cur = (mid(arr(i),2,len(arr(i))-2)=section)
      else
        if cur then
          if len(text)>0 then
            text = text & vbCrLf & split(arr(i),"=")(0)
          else
            text = split(arr(i),"=")(0)
          end if
        end if
      end if
    next
    options = split(text,vbCrLf)
  End If
End Function

Function FileExists(fname)
Set fso = CreateObject("Scripting.FileSystemObject")
FileExists = fso.FileExists(fname)
End Function
"I don't know what World War 3 will be fought with, but I know World War 4 with be fought with sticks and stones." - Albert Einstein