Ultimate Topic changer
 

News:

29 December 2022 - PtokaX 0.5.3.0 (20th anniversary edition) released...
11 April 2017 - PtokaX 0.5.2.2 released...
8 April 2015 Anti child and anti pedo pr0n scripts are not allowed anymore on this board!
28 September 2015 - PtokaX 0.5.2.1 for Windows 10 IoT released...
3 September 2015 - PtokaX 0.5.2.1 released...
16 August 2015 - PtokaX 0.5.2.0 released...
1 August 2015 - Crowdfunding for ADC protocol support in PtokaX ended. Clearly nobody want ADC support...
30 June 2015 - PtokaX 0.5.1.0 released...
30 April 2015 Crowdfunding for ADC protocol support in PtokaX
26 April 2015 New support hub!
20 February 2015 - PtokaX 0.5.0.3 released...
13 April 2014 - PtokaX 0.5.0.2 released...
23 March 2014 - PtokaX testing version 0.5.0.1 build 454 is available.
04 March 2014 - PtokaX.org sites were temporary down because of DDOS attacks and issues with hosting service provider.

Main Menu

Ultimate Topic changer

Started by TTB, 21 July, 2005, 17:34:39

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

TTB

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 =)
TTB

(? ?.??.-> Admin @ Surfnet hubs <-.??.???)

TTB

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  ;)
TTB

(? ?.??.-> Admin @ Surfnet hubs <-.??.???)

SMF spam blocked by CleanTalk