Textfile manager for PtokaX
 

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

Textfile manager for PtokaX

Started by achiever, 18 May, 2007, 13:13:53

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

achiever

Quote from: bastya_elvtars on 18 May, 2007, 00:24:10
I am not sure how !addtxt should work, though.
bastya i think it would be the same as changetxt,
!addtxt <name> <body>

i kno this is not the forum for script requests but, can some 1 plzz make a script for this.

thks,


thks bastya  ;)
thks,
achiever.

Madman

#1
If the changetxt and addtxt gonna have same syntax, why have changetxt at all?
addtxt overwrites the old txt file.

Tested some, but should work...

Code: lua
-- Textfile Manager
-- Made by Madman

-- Fixed: small path bug
-- Added: Syntax error to addtxt
-- Changed: better pattern matching, thanks basta

-- Commands
-- addtxt NewFile [New text to add]
-- deltxt DelFile
-- showtxt

function ChatArrival(curUser,data)
	local data = string.sub(data,1,-2)
	local s,e,cmd = string.find(data,"%b<>%s+[%!%#](%S+)")
	if cmd then
		tCmds = {
			["addtxt"] = function(curUser,data)
				local s,e,file,text = string.find(data,"%b<>%s+%S+%s+(%S+)%s+%[(.+)%]")
				if file and text then
					local txt = io.open(frmHub:GetPtokaXLocation().."/texts/" ..file.. ".txt","w+")
					txt:write(text)
					txt:close()
					curUser:SendData(frmHub:GetHubBotName(),file.. ".txt added, please reload text files")
				else
					curUser:SendData(frmHub:GetHubBotName(),"syntax: !addtxt filename [text to add]")
				end
			end,
			["deltxt"] = function(curUser,data)
				local s,e,file = string.find(data,"%b<>%s+%S+%s+(%S+)")
				if file then
					os.remove(file..".txt")
					curUser:SendData(frmHub:GetHubBotName(),file.. ".txt removed, please reload text files")
				end
			end,
			["showtxt"] = function(curUser,data)
				os.execute("dir /b ..\\texts > tmp.txt")
				local file = io.open("tmp.txt")
				local line = string.gsub(file:read("*a"), "\n", "\r\n") 
				curUser:SendPM(frmHub:GetHubBotName(),"\r\n\r\ncurrent text files\r\n\r\n"..line)
				file:close()
				os.remove("tmp.txt")
			end,
		}
		if tCmds[cmd] then
			return tCmds[cmd](curUser,data),1
		end
	end
end
We suffer in silence, we lurk in the shadows, we kill in the night
Site currently down, ETA of returning online is 2099 ;p

achiever

i m getting 1 error
[20:09] Syntax ...ads\MY Hub\scripts\textfile maneger.lua:16: bad argument #1 to 'gsub' (string expected, got nil)
thks,
achiever.

Madman

You are useing wrong syntax, it's !addtext filename [new text]

Script updated, to show when using wrong syntax
We suffer in silence, we lurk in the shadows, we kill in the night
Site currently down, ETA of returning online is 2099 ;p

bastya_elvtars

Why not use %[(.+)%] for capturing instead?
Everything could have been anything else and it would have just as much meaning.

Madman

Beacuse i didn't think of it ;)

Script updated once again
We suffer in silence, we lurk in the shadows, we kill in the night
Site currently down, ETA of returning online is 2099 ;p

SMF spam blocked by CleanTalk