PtokaX forum

Archive => Archived 4.0 boards => Request for Lua 4 scripts => Topic started by: (!(Tys?kan)=) on 20 April, 2004, 14:44:58

Title: One help
Post by: (!(Tys?kan)=) on 20 April, 2004, 14:44:58
Hi, that's my idea:
When user connecting to hub in first time, the bot showing the help file with description to the newbie...then his nickname is writing to the file
On next joing to the hub, the scrip reading file and search his nickname and don't showing anything...


--Ty--
Title:
Post by: nErBoS on 21 April, 2004, 00:16:11
Hi,

Hope it helps...

--Requested by (!(Tys?kan)=)
--Made by nErboS

sBot = "NewUser-HELPER"

helptxt = "help.txt" --This file must be created in the script folder
usertxt = "user.txt" --this file will be created in script folder
sHelp = ""

nonnew = {}

function Main()
frmHub:RegBot(sBot)
end

function OnExit()
SaveToFile(usertxt , nonnew , "nonnew")
end

function NewUserConnected(user, data)
if (CheckUser(user) == 0) then
if (readfrom(helptxt) ~= nil) then
if (sHelp == "") then
ReadText(user)
else
user:SendPM(sBot, sHelp)
end
end
end
end

function CheckUser(user)
local pos = 0
local accept = 0
if (nonnew[1] == nil) then
LoadFromFile(usertxt)
end
for i=1, getn(nonnew) do
if (nonnew[i] == user.sName) then
accept = 1
end
pos = i
end
if (accept == 0) then
nonnew[pos+1] = user.sName
end
return accept
end

function ReadText(user)
readfrom(helptxt)
while 1 do
local line = read()
if (line == nil) then
break
else
sHelp = sHelp..line.."\r\n"
end
end
readfrom()
user:SendData(sBot, sHelp)
end

function Serialize(tTable, sTableName, sTab)
assert(tTable, "tTable equals nil");
assert(sTableName, "sTableName equals nil");

assert(type(tTable) == "table", "tTable must be a table!");
assert(type(sTableName) == "string", "sTableName must be a string!");

sTab = sTab or "";
sTmp = ""

sTmp = sTmp..sTab..sTableName.." = {\n"

for key, value in tTable do
local sKey = (type(key) == "string") and format("[%q]",key) or format("[%d]",key);

if(type(value) == "table") then
Serialize(value, sKey, sTab.."\t");
else
local sValue = (type(value) == "string") and format("%q",value) or tostring(value);
sTmp = sTmp..sTab.."\t"..sKey.." = "..sValue
end

sTmp = sTmp..",\n"
end

sTmp = sTmp..sTab.."}"
return sTmp
end

function SaveToFile(file , table , tablename)
writeto(file)
write(Serialize(table, tablename))
writeto()
end

function LoadFromFile(file)
if (readfrom(file) ~= nil) then
readfrom(file)
dostring(read("*all"))
readfrom()
end
end

Best regards, nErBoS
Title:
Post by: (!(Tys?kan)=) on 21 April, 2004, 17:43:46
Don't working...Don't saving nick's to file and don't writing errors...Just 0b file...
Title:
Post by: nErBoS on 22 April, 2004, 02:03:09
Hi,

Same problem as the other, going to see that.

Best regards, nErBoS
Title:
Post by: nErBoS on 24 April, 2004, 15:47:41
Hi,

Smae bug as the other, try this..

--Requested by (!(Tys?kan)=)
--Made by nErboS

sBot = "NewUser-HELPER"

helptxt = "help.txt" --This file must be created in the script folder
usertxt = "user.txt" --this file will be created in script folder
sHelp = ""

nonnew = {}

function Main()
frmHub:RegBot(sBot)
end

function OnExit()
if (nonnew == nil and reafrom(usertxt) ~= nil) then
LoadFromFile(usertxt)
end
SaveToFile(usertxt , nonnew , "nonnew")
end

function NewUserConnected(user, data)
if (CheckUser(user) == 0) then
if (readfrom(helptxt) ~= nil) then
if (sHelp == "") then
ReadText(user)
else
user:SendPM(sBot, sHelp)
end
end
end
end

function CheckUser(user)
local pos = 0
local accept = 0
if (nonnew[1] == nil) then
LoadFromFile(usertxt)
end
for i=1, getn(nonnew) do
if (nonnew[i] == user.sName) then
accept = 1
end
pos = i
end
if (accept == 0) then
nonnew[pos+1] = user.sName
end
return accept
end

function ReadText(user)
readfrom(helptxt)
while 1 do
local line = read()
if (line == nil) then
break
else
sHelp = sHelp..line.."\r\n"
end
end
readfrom()
user:SendData(sBot, sHelp)
end

function Serialize(tTable, sTableName, sTab)
assert(tTable, "tTable equals nil");
assert(sTableName, "sTableName equals nil");

assert(type(tTable) == "table", "tTable must be a table!");
assert(type(sTableName) == "string", "sTableName must be a string!");

sTab = sTab or "";
sTmp = ""

sTmp = sTmp..sTab..sTableName.." = {\n"

for key, value in tTable do
local sKey = (type(key) == "string") and format("[%q]",key) or format("[%d]",key);

if(type(value) == "table") then
Serialize(value, sKey, sTab.."\t");
else
local sValue = (type(value) == "string") and format("%q",value) or tostring(value);
sTmp = sTmp..sTab.."\t"..sKey.." = "..sValue
end

sTmp = sTmp..",\n"
end

sTmp = sTmp..sTab.."}"
return sTmp
end

function SaveToFile(file , table , tablename)
writeto(file)
write(Serialize(table, tablename))
writeto()
end

function LoadFromFile(file)
if (readfrom(file) ~= nil) then
readfrom(file)
dostring(read("*all"))
readfrom()
end
end

Best regards, nErBoS
Title:
Post by: tERBO on 25 April, 2004, 08:41:14
Hi
2nErBoS:
I have tasted this script on Ptocax 0.3.2.6 td4 and it still not saving nick's to file. After scripts restart user against receives help message :( With "(ip)::(nick)" same problem - don't saving nick's to file too...
Is this script works only with Ptocax 0.3.3.0? If it so - where we can get it? Its only for beta-testers...

2(!(Tys?kan)=):
Sorry, it is your topic, but i can't wait the answer more longer...

P.S. Excuse me for my bad English =)
Title:
Post by: (!(Tys?kan)=) on 25 April, 2004, 09:28:21
He there!
I'm have little modofications, and start up this script on PtorkaX 0.3.3.0, all working, greets!

2TerBo:
???, ????? ???-???? ???????????????????..

Sorry for non-english word's...
Title:
Post by: nErBoS on 25 April, 2004, 17:21:32
Hi,

Like i said this script will work 100% in ptokax 0.3.3.0, wait little more, because ptzacek is about to release a beta version to all.

Best regards, nErBoS
Title:
Post by: (!(Tys?kan)=) on 26 April, 2004, 09:47:52
I'm already having 0.3.3.0 version of ptokax...But script don't working to ;( Don't saving user's to file, when i'm handly writing a table and do some text such:
nonnew = {
[1] = "(!(Tys?kan)=)"
}
On restarting this gone to
nonnew = {
}
When new user is joining the hub - help don't posting to him...
Title:
Post by: nErBoS on 26 April, 2004, 12:23:45
Hi,

Little Bug, try this one...

--Requested by (!(Tys?kan)=)
--Made by nErboS

sBot = "NewUser-HELPER"

helptxt = "help.txt" --This file must be created in the script folder
usertxt = "user.txt" --this file will be created in script folder
sHelp = ""

nonnew = {}

function Main()
frmHub:RegBot(sBot)
end

function OnExit()
if (nonnew[1] == nil and reafrom(usertxt) ~= nil) then
LoadFromFile(usertxt)
end
SaveToFile(usertxt , nonnew , "nonnew")
end

function NewUserConnected(user, data)
if (CheckUser(user) == 0) then
if (readfrom(helptxt) ~= nil) then
if (sHelp == "") then
ReadText(user)
else
user:SendPM(sBot, sHelp)
end
end
end
end

function CheckUser(user)
local pos = 0
local accept = 0
if (nonnew[1] == nil) then
LoadFromFile(usertxt)
end
for i=1, getn(nonnew) do
if (nonnew[i] == user.sName) then
accept = 1
end
pos = i
end
if (accept == 0) then
nonnew[pos+1] = user.sName
end
return accept
end

function ReadText(user)
readfrom(helptxt)
while 1 do
local line = read()
if (line == nil) then
break
else
sHelp = sHelp..line.."\r\n"
end
end
readfrom()
user:SendData(sBot, sHelp)
end

function Serialize(tTable, sTableName, sTab)
assert(tTable, "tTable equals nil");
assert(sTableName, "sTableName equals nil");

assert(type(tTable) == "table", "tTable must be a table!");
assert(type(sTableName) == "string", "sTableName must be a string!");

sTab = sTab or "";
sTmp = ""

sTmp = sTmp..sTab..sTableName.." = {\n"

for key, value in tTable do
local sKey = (type(key) == "string") and format("[%q]",key) or format("[%d]",key);

if(type(value) == "table") then
Serialize(value, sKey, sTab.."\t");
else
local sValue = (type(value) == "string") and format("%q",value) or tostring(value);
sTmp = sTmp..sTab.."\t"..sKey.." = "..sValue
end

sTmp = sTmp..",\n"
end

sTmp = sTmp..sTab.."}"
return sTmp
end

function SaveToFile(file , table , tablename)
writeto(file)
write(Serialize(table, tablename))
writeto()
end

function LoadFromFile(file)
if (readfrom(file) ~= nil) then
readfrom(file)
dostring(read("*all"))
readfrom()
end
end

Best regards, nErBoS
Title:
Post by: (!(Tys?kan)=) on 26 April, 2004, 17:32:39
Hey, and in this moment script is don't working...build 15.25
Title:
Post by: nErBoS on 26 April, 2004, 23:38:35
Hi,

Sorry a espeling mistake, fixed and tested...

--Requested by (!(Tys?kan)=)
--Made by nErboS

sBot = "NewUser-HELPER"

helptxt = "help.txt" --This file must be created in the script folder
usertxt = "user.txt" --this file will be created in script folder
sHelp = ""

nonnew = {}

function Main()
frmHub:RegBot(sBot)
end

function OnExit()
if (nonnew[1] == nil and readfrom(usertxt) ~= nil) then
LoadFromFile(usertxt)
end
SaveToFile(usertxt , nonnew , "nonnew")
end

function NewUserConnected(user, data)
if (CheckUser(user) == 0) then
if (readfrom(helptxt) ~= nil) then
if (sHelp == "") then
ReadText(user)
else
user:SendPM(sBot, sHelp)
end
end
end
end

OpConnected = NewUserConnected

function CheckUser(user)
local pos = 0
local accept = 0
if (nonnew[1] == nil and readfrom(usertxt) ~= nil) then
LoadFromFile(usertxt)
end
for i=1, getn(nonnew) do
if (nonnew[i] == user.sName) then
accept = 1
end
pos = i
end
if (accept == 0) then
nonnew[pos+1] = user.sName
end
return accept
end

function ReadText(user)
readfrom(helptxt)
while 1 do
local line = read()
if (line == nil) then
break
else
sHelp = sHelp..line.."\r\n"
end
end
readfrom()
user:SendData(sBot, sHelp)
end

function Serialize(tTable, sTableName, sTab)
assert(tTable, "tTable equals nil");
assert(sTableName, "sTableName equals nil");

assert(type(tTable) == "table", "tTable must be a table!");
assert(type(sTableName) == "string", "sTableName must be a string!");

sTab = sTab or "";
sTmp = ""

sTmp = sTmp..sTab..sTableName.." = {\n"

for key, value in tTable do
local sKey = (type(key) == "string") and format("[%q]",key) or format("[%d]",key);

if(type(value) == "table") then
Serialize(value, sKey, sTab.."\t");
else
local sValue = (type(value) == "string") and format("%q",value) or tostring(value);
sTmp = sTmp..sTab.."\t"..sKey.." = "..sValue
end

sTmp = sTmp..",\n"
end

sTmp = sTmp..sTab.."}"
return sTmp
end

function SaveToFile(file , table , tablename)
writeto(file)
write(Serialize(table, tablename))
writeto()
end

function LoadFromFile(file)
if (readfrom(file) ~= nil) then
readfrom(file)
dostring(read("*all"))
readfrom()
end
end

Best regards, nErBoS
Title:
Post by: (!(Tys?kan)=) on 27 April, 2004, 08:36:43
OK, this is working, thanks :D