PtokaX forum

Archive => Archived 5.0 boards => Finished Scripts => Topic started by: TTB on 21 July, 2005, 17:34:39

Title: Ultimate Topic changer
Post by: TTB on 21 July, 2005, 17:34:39
Hi...

Again stripped from my new bot (in progress).

Make a file called: "topic.dat" in your scripts folder, containing the following table:TopicSettings = {
["topic"] = {
["current"] = "Topic powered by Ultimate Topic changer created by TTB",
["time"] = "[0:00:00] / [21-07-2005]",
["user"] = "TTB",
["lock"] = 1,
},
}

Here is the script:-- Ultimate Topic changer with time settings
-- by TTB 21/07/05
-- Stripped from [BOT]Vliegenmepper (still in progress)
----------------------------------------------------------------------
-- Usage:
-- #topic - Set topic, no text will give the current topic
-- #topiclock - Lock the topic for so non-OPs can't change them
-- NOTE: Type #topiclock without parameters, for the current status of the lock
----------------------------------------------------------------------
-- IMPORTANT!!!!!!!
-- YOU HAVE TO MAKE A FILE CALLED:  topic.dat  IN YOUR SCRIPTS DIRECTORY!!!!
-- It won't work without...
--
--Put this in that file (without the double -  ) >>
--
--TopicSettings = {
-- ["topic"] = {
-- ["current"] = "Topic powered by Ultimate Topic changer created by TTB",
-- ["time"] = "[0:00:00] / [21-07-2005]",
-- ["user"] = "TTB",
-- ["lock"] = 1,
-- },
--}
----------------------------------------------------------------------

-- ## SETTINGS ##--

-->> Name of the bot
bot = "-TopicChanger-"
--> Reg the bot in the userlist? 1 = yes 0 = no
regbot = 1
-->> Your commands
prefix = "#"
cmd1 = "topic"
cmd2 = "topiclock"
-->> The profiles who can control the topiclock
Profiles = {
[-1] = 0,  -- Users
[0] = 1,   -- Masters
[1] = 1,   -- OPs
[2] = 0,   -- VIPs
[3] = 0,   -- REGs
[4] = 1,   -- MODs
[5] = 1,   -- Founders
}

-- ## End of Settings ##--

file = "topic.dat"

function loadlua(file,msg)
local f = assert(loadfile(file), msg)
return f()
end

loadlua(file,file.."  for  "..bot.." not found")

function Main()
if regbot == 1 then
frmHub:RegBot(bot)
end
frmHub:SetHubTopic(TopicSettings["topic"]["current"])
end

function ChatArrival(curUser, data)
data = string.sub(data,1,string.len(data)-1)
s,e,cmd = string.find(data,"%b<>%s+(%S+)")
if (string.lower(cmd) == (prefix..cmd1)) then
TopicChange(curUser,data)
return 1
elseif (string.lower(cmd) == (prefix..cmd2)) then
TopicLock(curUser,data)
return 1
end
end

function TopicChange(curUser,data)
local s,e,cmd,topic = string.find(data,"%b<>%s+(%S+)%s+(.+)")
local mijntabel = "TopicSettings"
if topic == nil then
curUser:SendData(bot, "Topic was set by  "..TopicSettings["topic"]["user"].."  on  "..TopicSettings["topic"]["time"]..": "..TopicSettings["topic"]["current"])
else
if TopicSettings["topic"]["lock"] == 1 and Profiles[curUser.iProfile] ~= 1 then
curUser:SendData(bot,"Topic is LOCKED!")
else
SendToAll(bot, "Topic change!\r\n\r\n"..
"Old topic was set by  "..TopicSettings["topic"]["user"].."  on  "..TopicSettings["topic"]["time"]..": "..TopicSettings["topic"]["current"].."\r\n\r\n"..
"New topic set by "..curUser.sName..": "..topic.."\r\n")
TopicSettings["topic"]["current"] = topic
TopicSettings["topic"]["user"] = curUser.sName
TopicSettings["topic"]["time"] = os.date("[%X] / [%d-%y-20%y]")
frmHub:SetHubTopic(topic)
end
WriteFile(TopicSettings,mijntabel,file)
end
end

function TopicLock(curUser,data)
if Profiles[curUser.iProfile] == 1 then
local mijntabel = "TopicSettings"
local s,e,cmd,topiclock = string.find(data,"%b<>%s+(%S+)%s+(%S+)")
if topiclock == nil then
if TopicSettings["topic"]["lock"] == 1 then
curUser:SendData(bot,"TopicLock is ENABLED")
else
curUser:SendData(bot,"TopicLock is DISABLED")
end
else
if topiclock == "on" then
if TopicSettings["topic"]["lock"] == 1 then
curUser:SendData(bot, "TopicLock already enabled")
else
TopicSettings["topic"]["lock"] = 1
SendToAll(bot,"TopicLock ENABLED by: "..curUser.sName)
end
elseif topiclock == "off" then
if TopicSettings["topic"]["lock"] == 0 then
curUser:SendData(bot,"TopicLock already disabled")
else
TopicSettings["topic"]["lock"] = 0
SendToAll(bot,"TopicLock DISABLED by: "..curUser.sName)
end
else
curUser:SendData(bot,"*** Syntax Error! Please use: "..prefix..cmd2.." ")
end
end
WriteFile(TopicSettings,mijntabel,file)
end
end

function Serialize(tTable, sTableName, hFile, sTab)
sTab = sTab or "";
hFile:write(sTab..sTableName.." = {\n" );
for key, value in tTable do
local sKey = (type(key) == "string") and string.format("[%q]",key) or string.format("[%d]",key);
if(type(value) == "table") then
Serialize(value, sKey, hFile, sTab.."\t");
else
local sValue = (type(value) == "string") and string.format("%q",value) or tostring(value);
hFile:write(sTab.."\t"..sKey.." = "..sValue);
end
hFile:write(",\n");
end
hFile:write(sTab.."}");
end

function WriteFile(table, tablename, file)
local handle = io.open(file, "w")
Serialize(table, tablename, handle)
  handle:close()
end

Report errors, have fun =)
Title:
Post by: TTB on 21 July, 2005, 18:11:46
I suggest that when using this script, that you unmark all boxes in the Profile Manager in PtokaX... new topics with other commands won't be saved in the txt, and the script will be useless  ;)