Author Topic: Writing a whois to a text file  (Read 6088 times)

Lunarbunny

  • Newbie
  • *
  • Posts: 6
Writing a whois to a text file
« on: December 17, 2006, 04:14:28 PM »
I decided to tinker with scripting yesterday after having finished an intro to Java class. It took me a little bit to get used to vbscript from 3 months of Java but I mostly understand it. However, I've been having trouble figuring out how to write a whois query to a text file. What I'm trying to do is make IceChat log chosen query conversations to an FTP account I have connected via NetDrive; however, I want the whois so that I have a reference (I'm a moderator for the WarRock forums and would like to upload conversations with less-than-trustworthy people for other moderators and admins to view with minimal manual work on my part).

Just in case I'll toss on my mess of code that I have so far. Critique away. Commenting code is not my strong point either, so sorry if you don't understand something.
Code: [Select]
Dim strWasSameNick, intNumNicks, intNumNicksSession, blnAnyLogs
strWasSameNick = ""
intNumNicks = CInt(GetIniFile("Queries.ini","GENERAL","Nicks","0"))
intNumNicksSession = 0
blnAnyLogs = false

Dim vbCancel, vbYes, vbNo
vbCancel = 2
vbYes = 6
vbNo = 7


Sub ONQUERY(Message,Nickname,Host,ServerNumber)
    Dim intIsNew, intMsgAns, strMsg
    strMsg = "New query from "&Nickname&". Log this query to a public text file? Cancel rejects this query."
    intIsNew = isNew(Nickname)

    If intIsNew = 2 Then
        intNumNicks = intNumNicks + 1
        intNumNicksSession = intNumNicksSession + 1

        WriteINIFile "Queries.ini","GENERAL","Nicks",CStr(intNumNicks)
        WriteINIFile "Queries.ini","NICKLIST",CStr(intNumNicks),Nickname
        WriteINIFile "Queries.ini","SESSION",CStr(intNumNicksSession),Nickname
    ElseIf intIsNew = 1 Then
        intNumNicksSession = intNumNicksSession + 1

        WriteINIFile "Queries.ini","SESSION",CStr(intNumNicksSession),Nickname
    End If

    If intIsNew >= 1 Then
        intMsgAns = MsgBox(strMsg,4131,"New Query")
        If intMsgAns = vbCancel Then
            Dim strRejectMsg
            strRejectMsg = "/msg "&Nickname&" Sorry, but your query was rejected. Did you ask first?"
            SendCommand strRejectMsg
        ElseIf intMsgAns = vbYes Then
            Dim intSearch
            intSearch = searchNicks(Nickname)
            If Not intSearch = -1 Then
                WriteINIFile "Queries.ini","LOG",CStr(intSearch),"true"
                blnAnyLogs = true
                writeHeader(Nickname)
            End If
        ElseIf intMsgAns = vbNo Then
            Dim intSearch2
            intSearch2 = searchNicks(Nickname)
            If Not intSearch2 = -1 Then
                WriteINIFile "Queries.ini","LOG",CStr(intSearch2),"false"
            End If
        End If 
    End If

    If blnAnyLogs Then
        Dim blnSearch
        intSearch = searchNicks(Nickname)
       
        blnSearch = searchLogs(intSearch)
       
        If blnSearch Then
            writeToText(Nickname)
        End If
    End If

End Sub


Function searchNicks(Nickname)
    Dim intNickIndex, tempIniNick
    intNickIndex = -1   

    For i = 0 To intNumNicks
        tempIniNick = GetIniFile("Queries.ini","NICKLIST",CStr(i),"")
        If tempIniNick = Nickname Then
            intNickIndex = i
        End If
    Next
    searchNicks = intNickIndex
End Function


Function searchLogs(index)
    Dim intLogIndex, tempIniIndex
    intLogIndex = false   

    For i = 0 To intNumNicks
        tempIniIndex = GetIniFile("Queries.ini","LOGS",CStr(i),"")
        If tempIniIndex = true Then
            intLogIndex = true
        End If
    Next
    searchLogs = intLogIndex
End Function


Private Function isNew(Nickname)
    Dim tempIniNick, intFinal
    intFinal = 2 'Assume it's not in session or all (completely new).

    For i = 0 To intNumNicksSession
        tempIniNick = GetIniFile("QueriesSession.ini","NICKLIST",CStr(i),"")
        If tempIniNick = Nickname Then
            intFinal = 0 'It's in session (and in all) Too new to warrant any action
        End If
    Next
   
    If Not intFinal = 0 Then
        For i = 0 To intNumNicks
            tempIniNick = GetIniFile("Queries.ini","NICKLIST",CStr(i),"")
            If tempIniNick = Nickname Then
                intFinal = 1 'It's in all (but not session). New enough to enter a new Time/Date/Whois
            End If
        Next
    End If

    isNew = intFinal
End Function


Sub writeHeader()
   
End Sub


Sub writeToText()

End Sub
« Last Edit: December 17, 2006, 04:20:32 PM by Lunarbunny »

Snerf

  • Administrator
  • Hero Member
  • *****
  • Posts: 1968
    • IceChat IRC Client
Re: Writing a whois to a text file
« Reply #1 on: December 18, 2006, 08:16:45 AM »
One small thing you must realize is, is that query's are logged by default.
If you look in the Logs folder, they are seperated by Networks, and then Channels, Queries, etc.
It would just be a matter of finding the log file you want, and do what you wish with it. There is no need to make a seperate log file.
The IceChat God

Lunarbunny

  • Newbie
  • *
  • Posts: 6
Re: Writing a whois to a text file
« Reply #2 on: December 18, 2006, 01:06:42 PM »
One small thing you must realize is, is that query's are logged by default.
If you look in the Logs folder, they are seperated by Networks, and then Channels, Queries, etc.
It would just be a matter of finding the log file you want, and do what you wish with it. There is no need to make a seperate log file.
I'm aware of that. I just want it to write to the online file in real-time instead of copying the log later. That and this is some practice with scripting :P

EDIT: Alright, I'm a moron. Didn't notice the Host parameter on ONQUERY (that's really all I needed). Sorry for the trouble.
« Last Edit: December 18, 2006, 03:58:20 PM by Lunarbunny »

Snerf

  • Administrator
  • Hero Member
  • *****
  • Posts: 1968
    • IceChat IRC Client
Re: Writing a whois to a text file
« Reply #3 on: December 18, 2006, 04:18:03 PM »
Well, if your good, we can move on :)
The IceChat God