PtokaX forum

Archive => Archived 4.0 boards => Finished Lua 4 scripts => Topic started by: FleetCommand on 31 January, 2004, 08:23:30

Title: Notepad script for BCDC
Post by: FleetCommand on 31 January, 2004, 08:23:30
I's a simple try (my first working usable lua script for bcdc (and my first lua script at all), but  it works :P :)

Allows users to write message into a text file and read it back (you can commenct the corresponding lines if don't want to let them read back it, or can be good on ophub to send message each other etc)

You can store your help file in help.txt

[B]Replacement of hub.onPrivateMessage function of Startup.lua[/B]
hub.onPrivateMessage = function( this, user, to, prefix, text )
-- DC():PrintDebug( this:getHubName().."> Priv msg: "..user:getNick().." -> "..to.." = "..text )
-- FleetCommand NotePad Script
-- BLua 0.1 - molnihun at netscape.net
local s = string.lower( text )
local subszoveg=string.sub(s,1,6)
local fajlnev=""
if subszoveg == "-radd " or subszoveg== "-madd " then
if subszoveg== "-radd " then fajlnev="report.txt"
else fajlnev="message.txt"
end
local ownNick = this:getOwnNick()
local fajl=io.open (fajlnev, "a")
fajl:write(" :: "..os.date("%Y. %m. %d - %H:%M") .. " :: " ..user:getNick() .. " :: " .. string.sub(text,7, string.len(text)).."\n")
fajl:close()
user:sendPrivMsgFmt( "OK ("..fajlnev..")" )
elseif subszoveg == "-rread" or subszoveg=="-mread" then
if subszoveg== "-rread" then fajlnev="report.txt"
else fajlnev="message.txt"
end
user:sendPrivMsgFmt( "Listing " .. fajlnev.. ":" )
local fajl=io.open(fajlnev,"r")
local szoveg=""
szoveg=fajl:read("*l")
repeat
    user:sendPrivMsgFmt( szoveg )
    szoveg=fajl:read()
until (szoveg == nil)
fajl:close()
user:sendPrivMsgFmt( "OK" )
elseif string.sub(s, 1,5) == "-help" or string.sub(s, 1,2)== "-?" then
local fajl=io.open("help.txt","r")
local szoveg=""
szoveg=fajl:read("*l")
repeat
    user:sendPrivMsgFmt( szoveg )
    szoveg=fajl:read()
until (szoveg == nil)
fajl:close()
end
end

[B]Replacement of hub.onChatMessage function of Startup.lua[/B]

hub.onChatMessage = function( this, user, text )
DC():PrintDebug( this:getHubName().."> Chat from "..user:getNick()..": "..text )

local s = string.lower( text )
if string.sub(s, 1,2) == "-?" or string.sub(s,1,5) == "-help" then
local ownNick = this:getOwnNick()
local fajl=io.open("help.txt","r")
local szoveg=""
szoveg=fajl:read("*l")
repeat
  this:sendPrivMsgTo( user:getNick(), "<" ..ownNick.. "> "..szoveg.."|" )
  szoveg=fajl:read()
until (szoveg == nil)
fajl:close()
end

end

[B]a sample help.txt - put this in the working directory[/B]
          --------------------------------------------------------------------------------------
          Help                                                                 BLua 0.1
          --------------------------------------------------------------------------------------
         
          -?                                                                           Help
          -help                                                                      Help
          -radd                                                  Report user to OPs
          -rread                                                           Read reports
          -madd                                           Send comment to OPs
          -mread                                                    Read comments
          --------------------------------------------------------------------------------------