PtokaX forum

Archive => Archived 5.0 boards => Finished Scripts => Topic started by: Thor on 30 August, 2006, 15:34:25

Title: Profile-related MOTD
Post by: Thor on 30 August, 2006, 15:34:25
This is a profile-related MOTD sender script, requested by HappyTheMan
Usage: the script will do first time the files into the scripts/MOTD folder, then you can modify them as you want. You should turn off the inbuild MOTD-sending
The commands are:
!modmotd <filename.txt> <new_content> - To modify the contents of the given file. It can be multiline.
!listmotd - To list all the files which are in the MOTD folder
!showmotd <filename.txt> - To show the contents of the given MOTD file.

-- Profile related MOTD by Hungarista
-- Requested by HappyTheMan
-- Ideas from Massmessager bot by me
-- 2oo6.o8.3o.

function Main()
bShowMotdInPm = true -- true - send MOTD in PM ; false - send MOTD in main.
if io.open("MOTD/Motd"..GetProfileName(0)..".txt","r") == nil then
iMaxProfiles = tonumber(table.getn(GetProfiles()))
os.execute("MD MOTD")
for i=0,(iMaxProfiles-1) do
file = io.open("MOTD/Motd"..GetProfileName(i)..".txt","w+")
file:close()
end
file = io.open("MOTD/MotdUnregistered.txt","w+")
file:close()
end
end

function ChatArrival(curUser,data)
if curUser.bOperator then
data = string.sub(data,1,-2)
local _,_,command,filename,newtext = string.find(data,"%b<>%s*%p*(%S+)%s*(%S*)%s*(.*)")
if command == "modmotd" then
if filename ~= "" then
local file = io.open("MOTD/"..filename, "w+")
if (file) then
file:write("\r\n"..newtext)
end
file:close()
curUser:SendPM(frmHub:GetHubBotName(),filename.." new content:\r\n"..newtext)
else
curUser:SendPM(frmHub:GetHubBotName(),"Usage: !modmotd <filename> <new_content> To see which files are in the MOTD folder, use the !listmotd command")
end
return 1
elseif command == "listmotd" then
os.execute("dir /B /ON "..string.gsub(frmHub:GetPtokaXLocation(),"/","\\").."scripts\\MOTD\\ > motd.txt")
local file = io.open(frmHub:GetPtokaXLocation().."scripts/motd.txt", "r")
local contents = string.gsub(file:read("*a"),string.char(10), "\r\n")
curUser:SendPM(frmHub:GetHubBotName(),"Files in the MOTD folder:\r\n"..contents)
file:close()
os.remove("motd.txt")
return 1
elseif string.lower(command) == "showmotd" then
if filename ~= "" then
local file = io.open(frmHub:GetPtokaXLocation().."scripts/MOTD/"..filename, "r")
if file then
local contents = string.gsub(file:read("*a"),string.char(10), "\r\n")
curUser:SendPM(frmHub:GetHubBotName(),filename.." contents:\r\n"..contents)
file:close()
else
curUser:SendData(frmHub:GetHubBotName(),"There is no "..filename.." file in the MOTD folder!")
end
else
curUser:SendPM(frmHub:GetHubBotName(),"Usage: !showfile <filename> The file should be in the MOTD folder")
end
return 1
end
end
end

function NewUserConnected(curUser)
if curUser.bRegistered then
file = io.open(frmHub:GetPtokaXLocation().."scripts/MOTD/Motd"..GetProfileName(curUser.iProfile)..".txt", "r")
else
file = io.open(frmHub:GetPtokaXLocation().."scripts/MOTD/MotdUnregistered.txt", "r")
end
if file then
local contents = string.gsub(file:read("*a"),string.char(10), "\r\n")
if bShowMotdInPm then
curUser:SendPM(frmHub:GetHubBotName(),contents)
else
curUser:SendData(frmHub:GetHubBotName(),contents)
end
file:close()
else
SendPmToOps(frmHub:GetOpChatName(),"Can't open MOTD file to user has profile: "..curUser.iProfile.." ("..GetProfileName(curUser.iProfile)..")")
end
end
OpConnected = NewUserConnected
Title: Re: Profile-related MOTD
Post by: HappyTheMan on 30 August, 2006, 16:53:48
WOW thank you so much!!!!!
You are very kind Hungarista
I love you  :-*  ;D
Posted on: 30 August 2006, 16:51:10
So I am testing it and when I try to !listmots i get an error:
[16:49] Syntax C:\Program Files\Ptokax\scripts\MOTD.lua:44: bad argument #1 to `lower' (string expected, got nil)

Also when i type eg:
!modmotd motdmoderator.txt
          line1
          line2

then i get this reply:
motdmoderator.txt new content:
line1
          line2

The first line of spaces is ignored. Is it easy to fix ? Else I will do otherwise
Title: Re: Profile-related MOTD
Post by: Thor on 30 August, 2006, 17:13:13
string.find pattern updated and fixed 8)
Title: Re: Profile-related MOTD
Post by: JueLz on 30 August, 2006, 19:22:03
Way to go hungarista!!!!!!!!!!!1
Title: Re: Profile-related MOTD
Post by: speedX on 30 August, 2006, 20:46:45
Can u plzz convert it to Lua 5.1 ............
Title: Re: Profile-related MOTD
Post by: Thor on 30 August, 2006, 21:03:28
Replace this:
iMaxProfiles = tonumber(table.getn(GetProfiles()))
To this:
iMaxProfiles = tonumber(table.maxn(GetProfiles()))
By the way:
http://forum.ptokax.org/index.php?topic=6254#new
Title: Re: Profile-related MOTD
Post by: speedX on 31 August, 2006, 05:52:03
hm...hey Hungarista..i would like if a master sets all the MOTD's for the particular profile....thn when a reg user comes online..thn he should get the MOTD made for regisitered users...i mean all the users of any profile should get their MOTD's on their login....thank u..
Posted on: 30 August 2006, 22:14:18
oh srry dude....i understood....i forgot to add data to the text files....nice script...
Posted on: 30 August 2006, 22:20:19
hey Hungarista....i would like if this script was operated by masters only...i don want any other op to modify the MOTD......only masters.....thank u
Title: Re: Profile-related MOTD
Post by: Thor on 31 August, 2006, 15:54:26
-- Profile related MOTD by Hungarista
-- Requested by HappyTheMan
-- Ideas from Massmessager bot by me
-- 2oo6.o8.3o.

function Main()
bShowMotdInPm = true -- true - send MOTD in PM ; false - send MOTD in main.
if io.open("MOTD/Motd"..GetProfileName(0)..".txt","r") == nil then
iMaxProfiles = tonumber(table.getn(GetProfiles()))
os.execute("MD MOTD")
for i=0,(iMaxProfiles-1) do
file = io.open("MOTD/Motd"..GetProfileName(i)..".txt","w+")
file:close()
end
file = io.open("MOTD/MotdUnregistered.txt","w+")
file:close()
end
end

function ChatArrival(curUser,data)
if curUser.bOperator then
data = string.sub(data,1,-2)
local _,_,command,filename,newtext = string.find(data,"%b<>%s*%p*(%S+)%s*(%S*)%s*(.*)")
if command == "modmotd" then
if curUser.iProfile == 0 then
if filename ~= "" then
local file = io.open("MOTD/"..filename, "w+")
if (file) then
file:write("\r\n"..newtext)
end
file:close()
curUser:SendPM(frmHub:GetHubBotName(),filename.." new content:\r\n"..newtext)
else
curUser:SendPM(frmHub:GetHubBotName(),"Usage: !modmotd <filename> <new_content> To see which files are in the MOTD folder, use the !listmotd command")
end
else
curUser:SendPM(frmHub:GetHubBotName(),"You haven't got access to use this command!")
end
return 1
elseif command == "listmotd" then
os.execute("dir /B /ON "..string.gsub(frmHub:GetPtokaXLocation(),"/","\\").."scripts\\MOTD\\ > motd.txt")
local file = io.open(frmHub:GetPtokaXLocation().."scripts/motd.txt", "r")
local contents = string.gsub(file:read("*a"),string.char(10), "\r\n")
curUser:SendPM(frmHub:GetHubBotName(),"Files in the MOTD folder:\r\n"..contents)
file:close()
os.remove("motd.txt")
return 1
elseif string.lower(command) == "showmotd" then
if filename ~= "" then
local file = io.open(frmHub:GetPtokaXLocation().."scripts/MOTD/"..filename, "r")
if file then
local contents = string.gsub(file:read("*a"),string.char(10), "\r\n")
curUser:SendPM(frmHub:GetHubBotName(),filename.." contents:\r\n"..contents)
file:close()
else
curUser:SendData(frmHub:GetHubBotName(),"There is no "..filename.." file in the MOTD folder!")
end
else
curUser:SendPM(frmHub:GetHubBotName(),"Usage: !showfile <filename> The file should be in the MOTD folder")
end
return 1
end
end
end

function NewUserConnected(curUser)
if curUser.bRegistered then
file = io.open(frmHub:GetPtokaXLocation().."scripts/MOTD/Motd"..GetProfileName(curUser.iProfile)..".txt", "r")
else
file = io.open(frmHub:GetPtokaXLocation().."scripts/MOTD/MotdUnregistered.txt", "r")
end
if file then
local contents = string.gsub(file:read("*a"),string.char(10), "\r\n")
if bShowMotdInPm then
curUser:SendPM(frmHub:GetHubBotName(),contents)
else
curUser:SendData(frmHub:GetHubBotName(),contents)
end
file:close()
else
SendPmToOps(frmHub:GetOpChatName(),"Can't open MOTD file to user has profile: "..curUser.iProfile.." ("..GetProfileName(curUser.iProfile)..")")
end
end
OpConnected = NewUserConnected
Title: Re: Profile-related MOTD
Post by: speedX on 31 August, 2006, 21:26:10
hey thx dude....
Title: Re: Profile-related MOTD
Post by: JueLz on 31 August, 2006, 21:41:00
Nice 1 hungarista i aplaud you!!! :)
Title: Re: Profile-related MOTD
Post by: HappyTheMan on 31 August, 2006, 23:01:58
Quote from: HappyTheMan on 30 August, 2006, 16:53:48
Also when i type eg:
!modmotd motdmoderator.txt
          line1
          line2

then i get this reply:
motdmoderator.txt new content:
line1
          line2
Ok i found the problem
You must change the string.find patern at line 23:
string.find(data,"%b<>%s*%p*(%S+)%s*(%S*)%s*(.*)")
to
string.find(data,"%b<>%s*%p*(%S+)%s*(%S*)%s(.*)")
Thus if you start your MOTD with a space it isn't ignored