PtokaX forum

Archive => Archived 4.0 boards => Request for Lua 4 scripts => Topic started by: Themaster on 11 November, 2004, 17:42:53

Title: link needed
Post by: Themaster on 11 November, 2004, 17:42:53
Hey PPL i need a script to the link...like +addlink //www.google.com or other.
so it will save to in a txt file....

plz needed that script *S*
Title:
Post by: bastya_elvtars on 11 November, 2004, 19:11:16
how should the text file look like?
Title:
Post by: Themaster on 11 November, 2004, 19:29:38
like a rule..or somethin like that i just want to have a script that show where they can fine som stuff on the //www.. if you understand what i mean. and the user's can add a link
Title:
Post by: bastya_elvtars on 11 November, 2004, 21:09:07
hints: use a table to store the links


like table{["www.google.com"]=1,["www.lmfao.xyz"]=1}

with this you can see whether link is added already

and use the following:

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")

Title:
Post by: Themaster on 11 November, 2004, 21:30:30
i also need a command on it....i have try to make some....but i don't work
Title:
Post by: Themaster on 12 November, 2004, 19:15:45
I still need they +prefix code to that function with the link i want to made
Title:
Post by: Themaster on 12 November, 2004, 21:15:17
thx. for that script i got in PM....and here it is

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





Thx a lot i 2 happy for it
Title:
Post by: Themaster on 12 November, 2004, 21:54:37
need 2 stuff more to that function..

nr 1
Remeve one link if it not work that link there are being add..

nr 2.
A Clearfunction

 8)
Title:
Post by: Themaster on 14 November, 2004, 19:51:38
Still need help with this script

PLZ PLL
Title:
Post by: nErBoS on 15 November, 2004, 01:31:05
Hi,

Try out this one...

--## 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

Best regards, nErBoS
Title:
Post by: Themaster on 15 November, 2004, 17:35:43
Thx nerbos...but it got a error on linklist

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']

Title:
Post by: Themaster on 15 November, 2004, 20:09:43
i miss 2 thing on that command here...

1. I can't get linklist to work

2. need a Description off what that like are...like //www.google.com  Desc = is a search site
Title:
Post by: kepp on 15 November, 2004, 22:40:02
It's funny that you mention it..
I made this a few days ago to another hub

all i had to do was translating it :)

-- 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
};
Title:
Post by: Themaster on 16 November, 2004, 16:16:27
It still is the same problem i get
Title:
Post by: kepp on 16 November, 2004, 17:10:23
Which is...??
Title:
Post by: Themaster on 16 November, 2004, 17:29:36
when i use linklist

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
Title:
Post by: bastya_elvtars on 16 November, 2004, 20:12:42
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
Title:
Post by: Themaster on 16 November, 2004, 20:55:56
thx bastya that work  :]
Title:
Post by: nErBoS on 17 November, 2004, 00:59:25
Hi,

Correct away...

local sTmp,sLink,sPoster = "The Link List of our HUB:\r\n\r\n"
Best regards, nErBoS
Title:
Post by: Themaster on 17 November, 2004, 16:08:13
thx PPL.. I have the correct code now and it work great

--## 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 ...

Peace PPL....
Title:
Post by: Themaster on 19 November, 2004, 12:31:33
One thin more 2 this script..Need a Description on what the link is about

LINK: http://www.portforward.com/ POSTED BY: Themaster? and what on that link.. so all can see what that link is !
Title:
Post by: Themaster on 20 November, 2004, 16:26:36
plz PPL i can't get it on
Title:
Post by: nErBoS on 20 November, 2004, 22:15:47
Hi,

Here you have...

--## 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

NOTE: You must delete the "link.dat" before you can use this script (by doing that you will lose all your links). To delete that file you have to shutdown the ptokax.

Best regards, nErBoS