Profile-related MOTD
 

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

Profile-related MOTD

Started by Thor, 30 August, 2006, 15:34:25

Previous topic - Next topic

0 Members and 2 Guests are viewing this topic.

Thor

This is a profile-related MOTD sender script, requested by HappyTheMan
Usage: the script will do first time the files into the scripts/MOTD folder, then you can modify them as you want. You should turn off the inbuild MOTD-sending
The commands are:
!modmotd <filename.txt> <new_content> - To modify the contents of the given file. It can be multiline.
!listmotd - To list all the files which are in the MOTD folder
!showmotd <filename.txt> - To show the contents of the given MOTD file.

-- Profile related MOTD by Hungarista
-- Requested by HappyTheMan
-- Ideas from Massmessager bot by me
-- 2oo6.o8.3o.

function Main()
	bShowMotdInPm = true -- true - send MOTD in PM ; false - send MOTD in main.
	if io.open("MOTD/Motd"..GetProfileName(0)..".txt","r") == nil then
		iMaxProfiles = tonumber(table.getn(GetProfiles()))
		os.execute("MD MOTD")
		for i=0,(iMaxProfiles-1) do
			file = io.open("MOTD/Motd"..GetProfileName(i)..".txt","w+")
			file:close()
		end
		file = io.open("MOTD/MotdUnregistered.txt","w+")
		file:close()
	end
end

function ChatArrival(curUser,data)
	if curUser.bOperator then
		data = string.sub(data,1,-2)
		local _,_,command,filename,newtext = string.find(data,"%b<>%s*%p*(%S+)%s*(%S*)%s*(.*)")
		if command == "modmotd" then
			if filename ~= "" then
				local file = io.open("MOTD/"..filename, "w+")
				if (file) then
					file:write("\r\n"..newtext)
				end
				file:close()
				curUser:SendPM(frmHub:GetHubBotName(),filename.." new content:\r\n"..newtext)
			else
				curUser:SendPM(frmHub:GetHubBotName(),"Usage: !modmotd <filename> <new_content> To see which files are in the MOTD folder, use the !listmotd command")
			end
			return 1
		elseif command == "listmotd" then
			os.execute("dir /B /ON "..string.gsub(frmHub:GetPtokaXLocation(),"/","\\").."scripts\\MOTD\\ > motd.txt")
			local file = io.open(frmHub:GetPtokaXLocation().."scripts/motd.txt", "r")
			local contents = string.gsub(file:read("*a"),string.char(10), "\r\n")
			curUser:SendPM(frmHub:GetHubBotName(),"Files in the MOTD folder:\r\n"..contents)
			file:close()
			os.remove("motd.txt")
			return 1
		elseif string.lower(command) == "showmotd" then
			if filename ~= "" then
				local file = io.open(frmHub:GetPtokaXLocation().."scripts/MOTD/"..filename, "r")
				if file then
					local contents = string.gsub(file:read("*a"),string.char(10), "\r\n")
					curUser:SendPM(frmHub:GetHubBotName(),filename.." contents:\r\n"..contents)
					file:close()
				else
					curUser:SendData(frmHub:GetHubBotName(),"There is no "..filename.." file in the MOTD folder!")
				end
			else
				curUser:SendPM(frmHub:GetHubBotName(),"Usage: !showfile <filename> The file should be in the MOTD folder")
			end
			return 1
		end
	end
end

function NewUserConnected(curUser)
	if curUser.bRegistered then
		file = io.open(frmHub:GetPtokaXLocation().."scripts/MOTD/Motd"..GetProfileName(curUser.iProfile)..".txt", "r")
	else
		file = io.open(frmHub:GetPtokaXLocation().."scripts/MOTD/MotdUnregistered.txt", "r")
	end
	if file then
		local contents = string.gsub(file:read("*a"),string.char(10), "\r\n")
		if bShowMotdInPm then
			curUser:SendPM(frmHub:GetHubBotName(),contents)
		else
			curUser:SendData(frmHub:GetHubBotName(),contents)
		end
		file:close()
	else
		SendPmToOps(frmHub:GetOpChatName(),"Can't open MOTD file to user has profile: "..curUser.iProfile.." ("..GetProfileName(curUser.iProfile)..")")
	end
end
OpConnected = NewUserConnected

HappyTheMan

#1
WOW thank you so much!!!!!
You are very kind Hungarista
I love you  :-*  ;D
Posted on: 30 August 2006, 16:51:10
So I am testing it and when I try to !listmots i get an error:
[16:49] Syntax C:\Program Files\Ptokax\scripts\MOTD.lua:44: bad argument #1 to `lower' (string expected, got nil)

Also when i type eg:
!modmotd motdmoderator.txt
          line1
          line2

then i get this reply:
motdmoderator.txt new content:
line1
          line2

The first line of spaces is ignored. Is it easy to fix ? Else I will do otherwise

Thor

string.find pattern updated and fixed 8)

JueLz

Way to go hungarista!!!!!!!!!!!1
I am owner of the MzDistortion? Empire
the addy to my hub is mzdistortion.no-ip.org
____________________________________________
--=                        [HT 500]                          =--

speedX

Can u plzz convert it to Lua 5.1 ............
Thanking You,

speedX

Thor

Replace this:
iMaxProfiles = tonumber(table.getn(GetProfiles()))

To this:
iMaxProfiles = tonumber(table.maxn(GetProfiles()))

By the way:
http://forum.ptokax.org/index.php?topic=6254#new

speedX

hm...hey Hungarista..i would like if a master sets all the MOTD's for the particular profile....thn when a reg user comes online..thn he should get the MOTD made for regisitered users...i mean all the users of any profile should get their MOTD's on their login....thank u..
Posted on: 30 August 2006, 22:14:18
oh srry dude....i understood....i forgot to add data to the text files....nice script...
Posted on: 30 August 2006, 22:20:19
hey Hungarista....i would like if this script was operated by masters only...i don want any other op to modify the MOTD......only masters.....thank u
Thanking You,

speedX

Thor

-- Profile related MOTD by Hungarista
-- Requested by HappyTheMan
-- Ideas from Massmessager bot by me
-- 2oo6.o8.3o.

function Main()
	bShowMotdInPm = true -- true - send MOTD in PM ; false - send MOTD in main.
	if io.open("MOTD/Motd"..GetProfileName(0)..".txt","r") == nil then
		iMaxProfiles = tonumber(table.getn(GetProfiles()))
		os.execute("MD MOTD")
		for i=0,(iMaxProfiles-1) do
			file = io.open("MOTD/Motd"..GetProfileName(i)..".txt","w+")
			file:close()
		end
		file = io.open("MOTD/MotdUnregistered.txt","w+")
		file:close()
	end
end

function ChatArrival(curUser,data)
	if curUser.bOperator then
		data = string.sub(data,1,-2)
		local _,_,command,filename,newtext = string.find(data,"%b<>%s*%p*(%S+)%s*(%S*)%s*(.*)")
		if command == "modmotd" then
			if curUser.iProfile == 0 then
				if filename ~= "" then
					local file = io.open("MOTD/"..filename, "w+")
					if (file) then
						file:write("\r\n"..newtext)
					end
					file:close()
					curUser:SendPM(frmHub:GetHubBotName(),filename.." new content:\r\n"..newtext)
				else
					curUser:SendPM(frmHub:GetHubBotName(),"Usage: !modmotd <filename> <new_content> To see which files are in the MOTD folder, use the !listmotd command")
				end
			else
				curUser:SendPM(frmHub:GetHubBotName(),"You haven't got access to use this command!")
			end
			return 1
		elseif command == "listmotd" then
			os.execute("dir /B /ON "..string.gsub(frmHub:GetPtokaXLocation(),"/","\\").."scripts\\MOTD\\ > motd.txt")
			local file = io.open(frmHub:GetPtokaXLocation().."scripts/motd.txt", "r")
			local contents = string.gsub(file:read("*a"),string.char(10), "\r\n")
			curUser:SendPM(frmHub:GetHubBotName(),"Files in the MOTD folder:\r\n"..contents)
			file:close()
			os.remove("motd.txt")
			return 1
		elseif string.lower(command) == "showmotd" then
			if filename ~= "" then
				local file = io.open(frmHub:GetPtokaXLocation().."scripts/MOTD/"..filename, "r")
				if file then
					local contents = string.gsub(file:read("*a"),string.char(10), "\r\n")
					curUser:SendPM(frmHub:GetHubBotName(),filename.." contents:\r\n"..contents)
					file:close()
				else
					curUser:SendData(frmHub:GetHubBotName(),"There is no "..filename.." file in the MOTD folder!")
				end
			else
				curUser:SendPM(frmHub:GetHubBotName(),"Usage: !showfile <filename> The file should be in the MOTD folder")
			end
			return 1
		end
	end
end

function NewUserConnected(curUser)
	if curUser.bRegistered then
		file = io.open(frmHub:GetPtokaXLocation().."scripts/MOTD/Motd"..GetProfileName(curUser.iProfile)..".txt", "r")
	else
		file = io.open(frmHub:GetPtokaXLocation().."scripts/MOTD/MotdUnregistered.txt", "r")
	end
	if file then
		local contents = string.gsub(file:read("*a"),string.char(10), "\r\n")
		if bShowMotdInPm then
			curUser:SendPM(frmHub:GetHubBotName(),contents)
		else
			curUser:SendData(frmHub:GetHubBotName(),contents)
		end
		file:close()
	else
		SendPmToOps(frmHub:GetOpChatName(),"Can't open MOTD file to user has profile: "..curUser.iProfile.." ("..GetProfileName(curUser.iProfile)..")")
	end
end
OpConnected = NewUserConnected

speedX

Thanking You,

speedX

JueLz

Nice 1 hungarista i aplaud you!!! :)
I am owner of the MzDistortion? Empire
the addy to my hub is mzdistortion.no-ip.org
____________________________________________
--=                        [HT 500]                          =--

HappyTheMan

#10
Quote from: HappyTheMan on 30 August, 2006, 16:53:48
Also when i type eg:
!modmotd motdmoderator.txt
          line1
          line2

then i get this reply:
motdmoderator.txt new content:
line1
          line2
Ok i found the problem
You must change the string.find patern at line 23:
string.find(data,"%b<>%s*%p*(%S+)%s*(%S*)%s*(.*)")
to
string.find(data,"%b<>%s*%p*(%S+)%s*(%S*)%s(.*)")
Thus if you start your MOTD with a space it isn't ignored

SMF spam blocked by CleanTalk