function savefile(table,file)
writeto(file)
for a,b in table do
write(a.."\n")
end
writeto()
end
-- to load:
function maketable(file)
local table={}
readfrom(file)
while 1 do
local line = read()
if line == nil then
readfrom()
break
end
table[line] = 1
end
readfrom()
return table
end
-- this has 2 be called for i. e. with
linktable=maketable("links.txt")
BotName = "weblink"
function Main()
frmHub:RegBot(sBot)
end
function DataArrival(user, data)
if (strsub(data, 1, 1) == "<" ) then
data=strsub(data,1,strlen(data)-1)
_,_,cmd=strfind(data, "%b<>%s+(%S+)")
s,e,arg = strfind(data,"%b<>%s+%S+%s+(%S+)")
if cmd=="addlink" then
AddLink(user, data, cmd)
elseif cmd=="links" then
ShowLinks(user, data, cmd)
end
end
end
-------------------------------------------------------------------------------------------------------------------------------------------------
function ShowLinks(user, data, cmd)
local rules = ""
readfrom("txt/weblinks.txt")
while 1 do
local line = read()
if (line == nil) then
break
else
rules = rules.." "..line.."\r\n"
end
end
user:SendPM(BotName, "\r\n\r\n".." Websites posted by Users".."\r\n\r\n"..rules)
readfrom()
end
function AddLink(user, data, cmd)
s,e,cmd,homePage,desc = strfind( data, "%b<>%s+(%S+)%s+(%S+)%s+(.+)" )
if desc == nil then
desc = "*** No description specified!"
s,e,homePage = strfind( data, "%b<>%s+%S+%s+(.+)" )
end
if homePage == nil then
user:SendData(BotName, "*** You must enter the addres of the website you would like to post!")
else
WriteHomepage(user.sName.." - "..homePage.."\r\n".."Description: "..desc.."\r\n")
SendToAll(BotName, "The user <"..user.sName.."> has added the homepage "..homePage.." to the linkdatabase!")
end
end
function WriteHomepage(what)
appendto("txt/weblinks.txt")
write(what.."\n")
writeto()
end
--## LINK POSTER BOT
--## Request by Themaster
--## Made by nErBoS
--## Commands:
--## +addlink - Adds a Link to the Link List
--## +dellink - Removes a Linf from the Link List (ONLY FOR OPs)
--## +linklist - Showes the Link List
sBot = "LP-Bot"
arrLink = {}
fLink = "link.dat"
--## Configuration ##--
uLaterPtokax = 0 -- Choose 0 if you are using a Ptokax Version 0.3.3.0 or higher
-- Choose 1 if you are using a Ptokax Version lower then 0.3.3.0
--## END ##--
function Main()
frmHub:RegBot(sBot)
LoadFromFile(fLink)
end
function OnExit()
SaveToFile(fLink , arrLink , "arrLink")
end
function DataArrival(user, data)
if (strsub(data,1,1) == "<" or strsub(data,1,5+strlen(sBot)) == "$To: "..sBot) then
data = strsub(data,1,strlen(data)-1)
local s,e,cmd = strfind(data, "%b<>%s+(%S+)")
if (cmd == "+addlink") then
local s,e,sLink = strfind(data, "%b<>%s+%S+%s+(.+)")
if (sLink == nil) then
user:SendPM(sBot, "Syntax Error, +addlink , you must write a link.")
elseif (arrLink[strlower(sLink)] ~= nil) then
user:SendPM(sBot, "The Link "..sLink.." is already in our Link List.")
else
arrLink[strlower(sLink)] = user.sName
user:SendPM(sBot, "The Link "..sLink.." has been added to our Link List, thank you.")
if (uLaterPtokax == 1) then
OnExit()
end
end
return 1
elseif (user.bOperator and cmd == "+dellink") then
local s,e,sLink = strfind(data, "%b<>%s+%S+%s+(.+)")
if (sLink == nil) then
user:SendPM(sBot, "Syntax Error, +dellink , you must write a link.")
elseif (arrLink[strlower(sLink)] == nil) then
user:SendPM(sBot, "The Link "..sLink.."isn't in our Link List.")
else
arrLink[strlower(sLink)] = nil
user:SendPM(sBot, "The Link "..sLink.." has been removed from our Link List.")
if (uLaterPtokax == 1) then
OnExit()
end
end
return 1
elseif (cmd == "+linklist") then
local sLink,sPoster,sTmp = "The Link List of our HUB:\r\n\r\n"
for sLink, sPoster in arrLink do
sTmp = sTmp.."LINK: "..sLink.." POSTED BY: "..sPoster.."\r\n"
end
user:SendPM(sBot, sTmp)
return 1
end
end
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
sTmp = sTmp..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
Syntax error: attempt to concat local `sTmp' (a nil value)
stack traceback:
1: function `Commands' at line 69 [file `blade/Commands.lua']
2: function `DataArrival' at line 120 [file `...Themaster\Skrivebord\Hub\scripts\Blade? 1.0.lua']
-- Link-Poster
-- made by Kepp (N?ttan)
--
-- To use create a folder in 'scripts' directory called Link-Poster.
-- The use notepad or your favorite text-editor and create a file called
-- 'Lankar.tbl'
--
-- Write this 'Links = {}' in the file! Save it, run the script, report bugs
----------------------------------------------------------------------------------------------
sBot = "Link-Poster";
sFile = "Link-Poster/Lankar.tbl";
----------------------------------------------------------------------------------------------
assert(dofile(sFile),sFile.." cannot be found.");
function Main()
frmHub:RegBot(sBot);
end
function DataArrival(user,data)
local data = strsub(data,1,-2);
if (strsub(data,1,1) == "<") then
local s,e,sCmd = strfind(data,"^%b<>%s+(%S+)");
if (Commands[strlower(sCmd)]) then
SendToAll(Commands[strlower(sCmd)](user,data));
end
if (rc == 1) then return 1 end
end
end
function WriteFile(table, tablename, file)
local handle = openfile(file, "w")
Serialize(table, tablename, handle)
closefile(handle)
end
function Serialize(tTable, sTableName, hFile, sTab)
sTab = sTab or "";
write(hFile, 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, hFile, sTab.."\t");
else
local sValue = (type(value) == "string") and format("%q",value) or tostring(value);
write(hFile, sTab.."\t"..sKey.." = "..sValue);
end
write(hFile, ",\n");
end
write(hFile, sTab.."}");
end
Commands = {
["+addtable"] =
function(user,data)
if (user.iProfile == 0 or user.iProfile == 1) then
local s,e,Header = strfind(data,"^%b<>%s+%S+%s+(.+)");
if (Header == "") then
user:SendData(sBot,"Please write a a description to be used for links!");
rc = 1;
else
local Exists = 0;
for i,v in Links do
if strlower(i) == strlower(Header) then
Exists = 1;
break
end
end
if (Exists == 1) then
user:SendData(sBot,"The table \""..Header.."\" is allready in file!");
rc = 1;
else
Links[Header] = {};
WriteFile(Links,"Links",sFile);
user:SendData(sBot,"\""..Header.."\" table is now registered in the file as a tile for diferent links!");
rc = 1;
end
end
else
user:SendData(sBot,"You are not allowed to use this command!");
rc = 1;
end
end,
["+addlink"] =
function(user,data)
if (user.iProfile == 0 or user.iProfile == 1) then
local s,e,Lank,sHeader = strfind(data,"^%b<>%s+%S+%s+(%S+)%s*(.*)");
if Lank then
if (sHeader == "") then
user:SendData(sBot,"Please write the table were the link shall be under!");
rc = 1;
else
local iMode = 0;
local Header = "";
for i,v in Links do
if strlower(i) == strlower(sHeader) then
iMode = 1;
Header = i;
break
end
end
if (iMode == 1) then
Links[Header][Lank] = 1;
WriteFile(Links,"Links",sFile);
user:SendData(sBot,"The link \""..Lank.."\" is now registered under \""..Header.."\" table!");
rc = 1;
else
user:SendData(sBot,"The \""..Header.."\" table dosen't exist, be kind enough to create it first!");
rc = 1;
end
end
else
user:SendData(sBot,"Please provide the link!");
rc = 1;
end
else
user:SendData(sBot,"You are not allowed to use this command!");
rc = 1;
end
end,
["+links"] =
function(user,data)
local sMsg = "";
for i,v in Links do
sMsg = sMsg.."\r\n( "..i.." )\r\n"
for i,v in Links[i] do
sMsg = sMsg..i.."\r\n";
end
end
user:SendPM(sBot,sMsg);
rc = 1;
end
};
elseif (cmd == "+linklist") then
local sLink,sPoster,sTmp = "The Link List of our HUB:\r\n\r\n"
for sLink, sPoster in arrLink do
sTmp = sTmp.."LINK: "..sLink.." POSTED BY: "..sPoster.."\r\n"
end
user:SendPM(sBot, sTmp)
return 1
end
elseif (cmd == "+linklist") then
local sLink,sPoster,sTmp = "The Link List of our HUB:\r\n\r\n",nil,""
for sLink, sPoster in arrLink do
sTmp = sTmp.."LINK: "..sLink.." POSTED BY: "..sPoster.."\r\n"
end
user:SendPM(sBot, sTmp)
return 1
end
local sTmp,sLink,sPoster = "The Link List of our HUB:\r\n\r\n"
--## LINK POSTER BOT
--## Request by Themaster
--## Made by nErBoS
--## Commands:
--## +addlink - Adds a Link to the Link List
--## +dellink - Removes a Linf from the Link List (ONLY FOR OPs)
--## +linklist - Showes the Link List
sBot = "LP-Bot"
arrLink = {}
fLink = "link.dat"
--## Configuration ##--
uLaterPtokax = 0 -- Choose 0 if you are using a Ptokax Version 0.3.3.0 or higher
-- Choose 1 if you are using a Ptokax Version lower then 0.3.3.0
--## END ##--
function Main()
frmHub:RegBot(sBot)
LoadFromFile(fLink)
end
function OnExit()
SaveToFile(fLink , arrLink , "arrLink")
end
function DataArrival(user, data)
if (strsub(data,1,1) == "<" or strsub(data,1,5+strlen(sBot)) == "$To: "..sBot) then
data = strsub(data,1,strlen(data)-1)
local s,e,cmd = strfind(data, "%b<>%s+(%S+)")
if cmd == "addlink" then
local s,e,sLink = strfind(data, "%b<>%s+%S+%s+(.+)")
if (sLink == nil) then
user:SendPM(BotName, "Syntax Error, +addlink , you must write a link.")
elseif (arrLink[strlower(sLink)] ~= nil) then
user:SendPM(BotName, "The Link "..sLink.." is already in our Link List.")
else
arrLink[strlower(sLink)] = user.sName
user:SendPM(BotName, "The Link "..sLink.." has been added to our Link List, thank you.")
if (uLaterPtokax == 1) then
OnExit()
end
end
return 1
elseif user.bOperator and cmd == "dellink" then
local s,e,sLink = strfind(data, "%b<>%s+%S+%s+(.+)")
if (sLink == nil) then
user:SendPM(BotName, "Syntax Error, +dellink , you must write a link.")
elseif (arrLink[strlower(sLink)] == nil) then
user:SendPM(BotName, "The Link "..sLink.."isn't in our Link List.")
else
arrLink[strlower(sLink)] = nil
user:SendPM(BotName, "The Link "..sLink.." has been removed from our Link List.")
if (uLaterPtokax == 1) then
OnExit()
end
end
return 1
elseif cmd == "showlink" then
local sLink,sPoster,sTmp = "The Link List of our HUB:\r\n\r\n",nil,""
for sLink, sPoster in arrLink do
sTmp = sTmp.."LINK: "..sLink.." POSTED BY: "..sPoster.."\r\n"
end
user:SendPM(BotName, sTmp)
return 1
end
end
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
sTmp = sTmp..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
That code work ...--## LINK POSTER BOT 1.0
--## Request by Themaster
--## Added description to the Links
--## Made by nErBoS
--## Commands:
--## +addlink - Adds a Link to the Link List
--## +dellink - Removes a Linf from the Link List (ONLY FOR OPs)
--## +linklist - Showes the Link List
sBot = "LP-Bot"
arrLink = {}
fLink = "link.dat"
--## Configuration ##--
uLaterPtokax = 0 -- Choose 0 if you are using a Ptokax Version 0.3.3.0 or higher
-- Choose 1 if you are using a Ptokax Version lower then 0.3.3.0
--## END ##--
function Main()
frmHub:RegBot(sBot)
LoadFromFile(fLink)
end
function OnExit()
SaveToFile(fLink , arrLink , "arrLink")
end
function DataArrival(user, data)
if (strsub(data,1,1) == "<" or strsub(data,1,5+strlen(sBot)) == "$To: "..sBot) then
data = strsub(data,1,strlen(data)-1)
local s,e,cmd = strfind(data, "%b<>%s+(%S+)")
if cmd == "+addlink" then
local s,e,sLink,sDesc = strfind(data, "%b<>%s+%S+%s+(%S+)%s+(.+)")
if (sLink == nil or sDesc == nil) then
user:SendPM(BotName, "Syntax Error, +addlink , you must write a link and a description.")
elseif (arrLink[strlower(sLink)] ~= nil) then
user:SendPM(BotName, "The Link "..sLink.." is already in our Link List.")
else
arrLink[strlower(sLink)] = {["BY"] = user.sName, ["DESC"] = sDesc}
user:SendPM(BotName, "The Link "..sLink.." has been added to our Link List, thank you.")
if (uLaterPtokax == 1) then
OnExit()
end
end
return 1
elseif user.bOperator and cmd == "+dellink" then
local s,e,sLink = strfind(data, "%b<>%s+%S+%s+(.+)")
if (sLink == nil) then
user:SendPM(BotName, "Syntax Error, +dellink , you must write a link.")
elseif (arrLink[strlower(sLink)] == nil) then
user:SendPM(BotName, "The Link "..sLink.."isn't in our Link List.")
else
arrLink[strlower(sLink)] = nil
user:SendPM(BotName, "The Link "..sLink.." has been removed from our Link List.")
if (uLaterPtokax == 1) then
OnExit()
end
end
return 1
elseif cmd == "+showlink" then
local sTmp,sLink,arrTable = "The Link List of our HUB:\r\n\r\n"
for sLink, arrTable in arrLink do
sTmp = sTmp.."LINK: "..sLink.." POSTED BY: "..arrTable["BY"].." DESCRIPTION: "..arrTable["DESC"].."\r\n"
end
user:SendPM(BotName, sTmp)
return 1
end
end
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
sTmp = sTmp..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