PtokaX forum

Archive => Archived 4.0 boards => Request for Lua 4 scripts => Topic started by: Skimoney22 on 05 February, 2004, 04:06:59

Title: I need help converting a script
Post by: Skimoney22 on 05 February, 2004, 04:06:59
I used a script in my old NMDC hub that was called Helper bot , is there any way someone could make a script like this for me in Ptokax? I see that there are         !network and !rules in Robocop, but I would like to add quite a few more. Probaly around 300-400 textfiles with commands.


' This script finds and reads a specific .txt file
'      And displays the content as a private message
'           Works great in addition to general bot
'
' add as many commands as nessesary just make sure the .txt file exists
' and that "(sTheText, 6)))" is correct (number of letters in the command
' Make sure the loggpath is correct
'
'   Made by: Gadget and  Manic_Depresiv_Santa
'
Dim sBotName, LoggPath

Sub Main()
sBotName="[HELPER]"           '<---- The HelperBots name
LoggPath = "C:\Programmer\dchub1500\Scripts\"           '<---- Path to the .txt files
End Sub

Sub DataArival(curUser, sCurData)
If (Left(sCurdata, 1) = "<") Then

lPos = InStr(1, sCurData, "> ")
sTheText = Mid(sCurData, lPos + 2)

'------------------Users and OPs can use these commands-------------------------
if (lcase(Left(sTheText, 6))) = "+rules" then
curUser.PrivateMessage cstr(sBotName), cstr(Read("rules.txt"))
End If

if (lcase(Left(sTheText, 8))) = "+network" then
curUser.PrivateMessage cstr(sBotName), cstr(Read("network.txt"))
End If

'------------------Only OPs can use these commands-------------------------------
if (lcase(Left(sTheText, 8))) = "+oprules" and curUser.bOperator = true then
curUser.PrivateMessage cstr(sBotName), cstr(Read("oprules.txt"))
End If

End If
End Sub

Function Read(TextFile)
Dim temp
Set fs = CreateObject("Scripting.FileSystemObject")
Set a = fs.OpenTextFile(LoggPath & TextFile, 1, false)
temp = a.ReadAll
a.Close
Set a = nothing
Set fs = nothing
Read = temp
End Function

Title:
Post by: plop on 05 February, 2004, 12:58:28
small question: could you next time try a search 1st, the next script posted a couple times allready.
-- texter bot by plop
-- thx 2 chilla for the faster routine for opening the files
-- shows text files from a folder named text.
-- doesn't mather what prefix it used.
-- if the file excist it shows.

Bot = "something"
FDFolder = "text"

function Main()
   frmHub:RegBot(Bot)
end

function DataArrival(user, data)
   data=strsub(data,1,strlen(data)-1)
   if( strsub(data, 1, 1) == "<" ) then
      s,e,cmd = strfind(data,"%b<>%s+(%S+)")
      cmd = strsub(cmd, 2,strlen(cmd))
      if readfrom(FDFolder.."/"..cmd..".txt") then
         showtext(user, cmd)
         return 1
      end
   elseif(strsub(data, 1, 4) == "$To:") then
      s,e,cmd = strfind(data,"$To:%s+%S+%s+From:%s+%S+%s+$%b<>%s+(%S+)")
      cmd = strsub(cmd, 2,strlen(cmd))
      if readfrom(FDFolder.."/"..cmd..".txt") then
         showtext(user, cmd)
         return 1
      end
   end
end

function showtext(user, file)
local handle = openfile(FDFolder.."/"..file..".txt", "r")
local contents = gsub(read(handle, "*a"),strchar(10), "\r\n")
closefile (handle)
user:SendPM(Bot, "\r\n"..contents.."\r\n|")
end

plop