Code:
'Erstellt mit [ABP]AVS 1.0.7
'An'===============================
GelBot Visual Scripting
'Visit us online @ http://www.angelbot-portal.de/
'===============================
'Programmiert von Anonymous
'===============================
'Change to True to enable search of terms in the db.
Const AllowStringSearch = False
'Your db file
Const QuoteFile = "quotes.txt"
Dim LastLine
Sub Init()
Script "Quote Script 1.0c by Sp33d"
Hook "Chan_Msg"
End Sub
Sub Chan_Msg(Chan, Nick, RegUser, Line)
Dim CalcLine, CurrentLine, vLines, SearchTag, FoundLines, Dummy, FNum, Found
If LCase(Param(Line, 1)) = "!addquote" Then
If MatchFlags(GetUserChanFlags(RegUser, Chan), "+m") Then
If GetRest(Line, 2) <> "" Then
FNum = FileOpen(QuoteFile, FA_Append)
If FNum Then
FileWriteLn FNum, GetRest(Line, 2)
SendLine "NOTICE " & Nick & " :Quote added", 3
Else
SendLine "NOTICE " & Nick & " :File Error. Couldn't add quote", 3
End If
FileClose FNum
End If
Else
SendLine "NOTICE " & Nick & " :You are not authorized to use this command", 3
End If
ElseIf LCase(Param(Line, 1)) = "!delquote" Then
If MatchFlags(GetUserChanFlags(RegUser, Chan), "+m") Then
If IsNumeric(Param(Line, 2)) Then
FNum = FileOpen(QuoteFile, FA_Binary)
If FNum Then
FileGet FNum, FileLoF(FNum), Dummy
Dummy = Split(Dummy, vbCrLf)
If CInt(Param(Line, 2)) - 1 > UBound(Dummy) Or CInt(Param(Line, 2)) - 1 < LBound(Dummy) Then
SendLine "NOTICE " & Nick & " :Error. Couldn't delete quote. No that much/less lines.", 3
FileClose FNum
Exit Sub
Else
Dummy(Param(Line, 2) - 1) = ""
End If
Else
SendLine "NOTICE " & Nick & " :Error. Couldn't delete quote. Not a numeric.", 3
FileClose FNum
Exit Sub
End If
FileClose FNum
FNum = FileOpen(QuoteFile, FA_Write)
If FNum Then
For i = LBound(Dummy) To UBound(Dummy)
If Dummy(i) <> "" Then FileWriteLn FNum, Dummy(i)
Next
SendLine "NOTICE " & Nick & " :Quote " & Param(Line, 2) & " deleted", 3
Else
SendLine "NOTICE " & Nick & " :Error. Couldn't delete quote. File access error.", 3
FileClose FNum
Exit Sub
End If
FileClose FNum
End If
Else
SendLine "NOTICE " & Nick & " :You are not authorized to use this command", 3
End If
ElseIf LCase(Param(Line, 1)) = "!quote" Then
If Param(Line, 2) = "" Then
Randomize
vLines = Lines(QuoteFile) + 1
Do While CalcLine = 0 Or CalcLine = LastLine
CalcLine = Int(Rnd * vLines)
Loop
LastLine = CalcLine
FNum = FileOpen(QuoteFile, FA_Read)
If FNum <> 0 And vLines > 0 Then
Do While CurrentLine < CalcLine And Not FileEoF(FNum)
Dummy = FileReadLn(FNum)
CurrentLine = CurrentLine + 1
Loop
SendLine "PRIVMSG " & Chan & " :Quote " & CurrentLine & ": " & Dummy, 3
Else
SendLine "NOTICE " & Nick & " :Sry, but the Quotefile seems to be empty. Add with !addquote <quote>", 3
End If
FileClose FNum
Else
If IsNumeric(Param(Line, 2)) Then
FNum = FileOpen(QuoteFile, FA_Read)
If FNum <> 0 Then
Do While CurrentLine < Int(Param(Line, 2)) And Not FileEoF(FNum)
Dummy = FileReadLn(FNum)
CurrentLine = CurrentLine + 1
Loop
SendLine "PRIVMSG " & Chan & " :Quote " & CurrentLine & ": " & Dummy, 3
Else
SendLine "NOTICE " & Nick & " :Sry, but the Quotefile seems to be empty. Add with !addquote <quote>", 3
End If
FileClose FNum
Else
If AllowStringSearch Then
SearchTag = LCase(Left(Param(Line, 2), 10))
FNum = FileOpen(QuoteFile, FA_Read)
Do While Not FileEoF(FNum)
CurrentLine = CurrentLine + 1
Dummy = FileReadLn(FNum)
If Instr(1, LCase(Dummy), LCase(SearchTag)) > 0 Then
If FoundLines <> "" Then
FoundLines = FoundLines & ", " & CurrentLine
Else
FoundLines = CurrentLine
End If
End If
Loop
FileClose FNum
If FoundLines <> "" Then
SendLine "PRIVMSG " & Chan & " :Lines found (" & SearchTag & "): " & FoundLines, 3
Else
SendLine "PRIVMSG " & Chan & " :Sry, no quotes found matching your query (" & SearchTag & ").", 3
End If
End If
End If
End If
End If
End Sub
Function Lines(vFile)
Dim Dummy
vFileNumber = FileOpen(vFile, FA_Binary)
If vFileNumber Then
FileGet vFileNumber, FileLoF(vFileNumber), Dummy
End If
FileClose vFileNumber
Dummy = Split(Dummy, VbCrLf)
Lines = UBound(Dummy)
End Function