Scripts manager
 

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

Scripts manager

Started by achiever, 21 May, 2007, 08:26:57

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

achiever

hi,

i have just modified TEXtfile Manager  Made by Madman to script file manager and made some changes
plzz check this out  :)

script updated 24/5/2007
-- modified Textfile manager to Scripts manager by Achiever 21/05/2007
-- added right click functions also
-- also change a bit of pattern matching
-- main chat block bug fixed thks to brock for report 24/05/2007

-- TEXtfile Manager
-- Made by Madman

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

-- Commands
-- addscript NewFile [New script to add]
-- delscript DelFile
-- showtxt

HUB = frmHub:GetHubName()

sBot = "Scripts manager"

--[[function Main()
      frmHub:RegBot(sBot)
end]]--

function ChatArrival(curUser,data)
	local data = string.sub(data,1,-2)
	local s,e,prefix,cmd = data:find("%b<>%s+(%p)(%S+)")
	if curUser.iProfile ==  0 then
	if cmd then
		tCmds = {
			["addscript"] = function(curUser,data)
				local s,e,file,script = string.find(data,"%b<>%s+%S+%s+(%S+)%s+%[(.+)%]")
				if file and script then
					local txt = io.open(frmHub:GetPtokaXLocation().."/scripts/" ..file.. ".lua","w+")
					txt:write(script)
					txt:close()
					curUser:SendPM(sBot,file.. ".lua added, please reload scripts")
				else
					curUser:SendPM(sBot,"syntax: !addscript filename [script to add]")
				end
			end,
			["delscript"] = function(curUser,data)
				local s,e,file = string.find(data,"%b<>%s+%S+%s+(%S+)")
				if file then
					os.remove(file..".lua")
					curUser:SendPM(sBot,file.. ".lua removed, please reload scripts")
				end
			end,
		}
		if tCmds[cmd] then
			return tCmds[cmd](curUser,data),1
		end
	else 
		curUser:SendData(frmHub:GetHubBotName(),"Ur profile is not allowed to use this command") 
	end
	end
end

function OpConnected(user)
	if user.iProfile ==  0 then
		user:SendData("$UserCommand 1 3 "..HUB.."\\Hub Commands\\"..sBot.."\\Add script$<%[mynick]> +addscript %[line:Filename] [ %[line:Script body] ] &#124;")
		user:SendData("$UserCommand 1 3 "..HUB.."\\Hub Commands\\"..sBot.."\\Delete script$<%[mynick]> +delscript %[line:Filename]&#124;")
		user:SendData("$UserCommand 1 3 "..HUB.."\\Hub Commands\\"..sBot.."\\restart script$<%[mynick]> +restartscript %[line:Filename]&#124;")
		user:SendData("$UserCommand 1 3 "..HUB.."\\Hub Commands\\"..sBot.."\\Start script$<%[mynick]> +startscript %[line:Filename]&#124;")
		user:SendData("$UserCommand 1 3 "..HUB.."\\Hub Commands\\"..sBot.."\\Stop script$<%[mynick]> +stopscript %[line:Filename]&#124;")
		user:SendData("$UserCommand 1 3 "..HUB.."\\Hub Commands\\"..sBot.."\\Restart all scripts$<%[mynick]> +restartscripts&#124;")
		user:SendData("$UserCommand 1 3 "..HUB.."\\Hub Commands\\"..sBot.."\\Get scripts$<%[mynick]> +getscripts&#124;")
	end
end


hope it was not already done  :P
achiever
thks,
achiever.

Yahoo

nice qwork but can u add the option of edit script
"BoRN FIGhTEr"

speedX

Quote from: Yahoo on 21 May, 2007, 10:33:08
nice qwork but can u add the option of edit script

Wats tht??
Thanking You,

speedX

Yahoo

edit script will allow to make the changes in the current script which is already used in the hub
"BoRN FIGhTEr"

achiever

u can just use the add script command, b'coz thks to Madman its in overwrite mode so the old file will be replaced by new 1.
bug found and fixed.
script updated.
thks,
achiever.

sphinx_spb

This script sometimes says this in mainchat:
[04:54:20] <Hub-Security> Ur profile is not allowed to use this command

Though I do nothing during this moment.
What's the reason?

speedX

Hello Mutor,
in ur script I am not able to add any of my scripts, I always get this error
Quote
[14:23] Private message from Scripts-Manager: <Scripts-Manager> syntax: !addscript filename [script to add]

Achievers script is running gd but it keeps a line space after each line in the script wich is added...
Thanking You,

speedX

speedX

Thx Mutor,
It works gr8 ;)
Congo!!!!
Thanking You,

speedX

achiever

hi,

mutor i got 1 bug in this script
when a script with right clicker is added thru this script it shows the right click in written form in main chat and not in right click.

thks,
achiever
thks,
achiever.

bastya_elvtars

Quote from: achiever on 19 June, 2007, 20:07:13
hi,

mutor i got 1 bug in this script
when a script with right clicker is added thru this script it shows the right click in written form in main chat and not in right click.

thks,
achiever

DC++ converts the line-ending HTML entities to endpipes. IMO there is no way to get past this.
Everything could have been anything else and it would have just as much meaning.

achiever

well then most of the scripts cant be added or at least right clicks cant be added thru this script.

thanks,
achiever
thks,
achiever.

bastya_elvtars

Quote from: achiever on 19 June, 2007, 20:59:38
well then most of the scripts cant be added or at least right clicks cant be added thru this script.

Let me think it over... you add it to DC++ then it passes it to PtokaX. No, cannot be added. Although we can file a feature request in the DC++ tracker - if there were any. :-)
Everything could have been anything else and it would have just as much meaning.

achiever

can  we get to it in other way if not directly like the script 1st saves it as text file and then renames it as .lua file.

lol this should work, but should be boring long way, isnt it?
thks,
achiever.

bastya_elvtars

I think I have a solution. You need to base64-encode the data and the script can decode it serverside. I can add such a feature. For encoding, here is an online encoder.
I'll come up with a modded script soon.
Everything could have been anything else and it would have just as much meaning.

bastya_elvtars

#14
Here you go.
I had to relicense it, see the notes.
Code: lua
-- modified Textfile manager to Scripts manager by Achiever 21/05/2007
-- added right click functions also
-- also change a bit of pattern matching
-- main chat block bug fixed thks to brock for report 24/05/2007

-- TEXtfile Manager
-- Made by Madman

-- Fixed: small path bug
-- Added: Syntax error to addscript
-- Changed: better pattern matching, thanks bastya
-- Revision by Mutor [ mod by achiever as 'Scripts Mgr.']

-- Commands
-- addscript NewFile [New script to add]
-- delscript DelFile
-- showtxt

-- Added base64 decoding of text by bastya_elvtars
-- This way, DC++ will not fuck up your scripts.

-- !!! IMPORTANT: !!!
-- You _have_ _to_ base64-encode the required file.
-- This can be achieved by using an online base64-encoder:

-- http://makcoder.sourceforge.net/demo/base64.php

-- LEGAL STUFF:

-- As the base64 code is licensed under the GNU LGPL,
-- the full script has to be relicensed under it.
-- Since the script is public domain, this should mean
-- no problem, although I do not like viral licenses.
-- Here is the LGPL:
-- http://www.gnu.org/licenses/lgpl.html

-- If the original authors disagree, the base64 code needs
-- to be removed or replaced to one under a more permissive
-- license.

-- Oh, and please do not blame me, I just obeyed the rules.

local HUB = frmHub:GetHubName()
local sBot = "[Scripts-Manager]"

function Main()
	frmHub:RegBot(sBot)
end

local tCmds = {
	["addscript"] = function(curUser,data)
		local method = "added"
		local _,_,flag = data:lower():find("%b<> %p%a+ %S+ (%-o)")
		local _,_,file,script = data:find("%b<> %p%a+ (%S+) [%-o ]*(.+)")
		--SendToAll("Flag: "..flag)
		if file and script then
			file = file:gsub("%.lua","")..".lua"
			local r,e = os.rename(file,file)
			if r then
				if not flag then
					return curUser:SendPM(sBot,file.." exists, syntax: !addscript"..
					" filename script [filename -o script  to overwrite])")
				else
					method = "updated"
				end
			else
				SendToAll(sBot,e)
			end
			local txt = io.open(file,"w+")
			txt:write(decode(script))
			txt:flush()
			txt:close()
			curUser:SendPM(sBot,file.." "..method..", please reload scripts")
		else
			curUser:SendPM(sBot,"syntax: !addscript filename [script to add]")
		end
	end,
	["delscript"] = function(curUser,data)
		local s,e,file = data:find("%b<>%s+%S+%s+(%w+)%.*.*")
		if file then
			os.remove(file..".lua")
			curUser:SendPM(sBot,file.. ".lua removed, please reload scripts")
		end
	end,
	}
	
function ChatArrival(curUser,data)
	if curUser.iProfile == 0 then
		data = data:sub(1,-2)
		local s,e,cmd = data:find("%b<> %p(%S+)")
		if cmd and tCmds[cmd] then
			return tCmds[cmd](curUser,data),1
		end
	end
end
ToArrival = ChatArrival

function OpConnected(user)
	if user.iProfile == 0 then
		user:SendData("$UserCommand 1 3 "..HUB.."\\Script Commands\\"..sBot.."\\Add Script$<%[mynick]> +addscript %[line:Filename (filename -o  to overwrite))] %[line:Script body]&#124;")
		user:SendData("$UserCommand 1 3 "..HUB.."\\Script Commands\\"..sBot.."\\Delete Script$<%[mynick]> +delscript %[line:Filename]&#124;")
		user:SendData("$UserCommand 1 3 "..HUB.."\\Script Commands\\"..sBot.."\\Restart Script$<%[mynick]> +restartscript %[line:Filename]&#124;")
		user:SendData("$UserCommand 1 3 "..HUB.."\\Script Commands\\"..sBot.."\\Start Script$<%[mynick]> +startscript %[line:Filename]&#124;")
		user:SendData("$UserCommand 1 3 "..HUB.."\\Script Commands\\"..sBot.."\\Stop Script$<%[mynick]> +stopscript %[line:Filename]&#124;")
		user:SendData("$UserCommand 1 3 "..HUB.."\\Script Commands\\"..sBot.."\\Restart All Scripts$ <%[mynick]> +restartscripts&#124;")
		user:SendData("$UserCommand 1 3 "..HUB.."\\Script Commands\\"..sBot.."\\Get Scripts$<%[mynick]> +getscripts&#124;")
	end
end

-- improved lua base64 codec (c) 2006-2007 by Alex Kloss
-- compatible with lua 5.1
-- http://www.it-rfc.de
-- licensed under the terms of the LGPL2

-- encryption table
local base64chars = {[0]='A',[1]='B',[2]='C',[3]='D',[4]='E',[5]='F',[6]='G',[7]='H',[8]='I',[9]='J',[10]='K',[11]='L',[12]='M',[13]='N',[14]='O',[15]='P',[16]='Q',
   [17]='R',[18]='S',[19]='T',[20]='U',[21]='V',[22]='W',[23]='X',[24]='Y',[25]='Z',[26]='a',[27]='b',[28]='c',[29]='d',[30]='e',[31]='f',[32]='g',
   [33]='h',[34]='i',[35]='j',[36]='k',[37]='l',[38]='m',[39]='n',[40]='o',[41]='p',[42]='q',[43]='r',[44]='s',[45]='t',[46]='u',[47]='v',[48]='w',
   [49]='x',[50]='y',[51]='z',[52]='0',[53]='1',[54]='2',[55]='3',[56]='4',[57]='5',[58]='6',[59]='7',[60]='8',[61]='9',[62]='-',[63]='_'}

-- function encode
-- encodes input string to base64.
function encode(data)
	local bytes = {}
	local result = ""
	for spos=0,string.len(data)-1,3 do
		for byte=1,3 do bytes[byte] = string.byte(string.sub(data,(spos+byte))) or 0 end
		result = string.format('%s%s%s%s%s',result,base64chars[math.floor(bytes[1]/4)] or "=",
                        base64chars[(bytes[1] % 4) * 16 + math.floor(bytes[2] / 16)] or "=",
                        ({[true]=base64chars[(bytes[2] % 16) * 4 + math.floor(bytes[3] / 64)] or "=",[false]="="})[(string.len(data)-spos) > 1],
                        ({[true]=base64chars[(bytes[3] % 64)] or "=",[false]="="})[(string.len(data)-spos) > 2])
	end
	return result
end

-- decryption table
local base64bytes = {['A']=0,['B']=1,['C']=2,['D']=3,['E']=4,['F']=5,['G']=6,['H']=7,['I']=8,['J']=9,['K']=10,['L']=11,['M']=12,['N']=13,['O']=14,['P']=15,['Q']=16,
   ['R']=17,['S']=18,['T']=19,['U']=20,['V']=21,['W']=22,['X']=23,['Y']=24,['Z']=25,['a']=26,['b']=27,['c']=28,['d']=29,['e']=30,['f']=31,['g']=32,
   ['h']=33,['i']=34,['j']=35,['k']=36,['l']=37,['m']=38,['n']=39,['o']=40,['p']=41,['q']=42,['r']=43,['s']=44,['t']=45,['u']=46,['v']=47,['w']=48,
   ['x']=49,['y']=50,['z']=51,['0']=52,['1']=53,['2']=54,['3']=55,['4']=56,['5']=57,['6']=58,['7']=59,['8']=60,['9']=61,['-']=62,['_']=63,['=']=nil}

-- function decode
-- decode base64 input to string
function decode(data)
	local chars = {}
	local result=""
	for dpos=0,string.len(data)-1,4 do
		for char=1,4 do chars[char] = base64bytes[(string.sub(data,(dpos+char),(dpos+char)) or "=")] end
		result = string.format('%s%s%s%s',result,string.char(chars[1]*4 + math.floor(chars[2]/16)),
                        ({[true]=string.char(((chars[2] or 0) % 16)*16 + math.floor((chars[3] or 0)/4)),[false]=""})[chars[3] ~= nil],
                        ({[true]=string.char(((chars[3] or 0)%4) * 64 + (chars[4] or 0)),[false]=""})[chars[4] ~= nil])
	end
	return result
end

Quote from: Mutor on 20 June, 2007, 02:22:41
We should be able to gsub the ascii code back in before saving to file.
The pattern will need to assure it is indeed a UC, otherwise I don't see a problem.

I am not sure about DC++'s handling of such things. BTW it is pure idiotism from them to parse chatlines containing HTML entities.
Everything could have been anything else and it would have just as much meaning.

bastya_elvtars

Quote from: Mutor on 20 June, 2007, 02:37:48
I suspect we will only find this problem with clients that support text formatting.

No, because we are talking about the & #124; thing.
And is DC++ supposed to do this entity - pipe conversion on OUTGOING protocol commands?
Everything could have been anything else and it would have just as much meaning.

bastya_elvtars

Did some more testing and I found that this does not occur in CZDC++. Anyway the script I posted should help with this issue and also eliminates a lot of potential issues. There is more hassle, but hey, replacing scripts is not something that you do 23 times a day.
Everything could have been anything else and it would have just as much meaning.

achiever

got 1 error

[09:25] Syntax ...oads\0.3.5.2[Fusion Hub]\scripts\scripts maneger.lua:149: attempt to perform arithmetic on field '?' (a nil value)
okk
i got it i did not encode it b4.
bastya i think there is a problem with the encoder thing as when the script decodes it it adds / before every "
plzz check.

achiever
thks,
achiever.

achiever

wow the script is working gr8

good work mutor thanks,
achiever.
umm.. if any script with 1st line as comment is added then -- is deleted and the scripts gives error(i mean the script added).
plzz check.
thks,
achiever.

speedX

Quote from: achiever on 20 June, 2007, 07:55:17
umm.. if any script with 1st line as comment is added then -- is deleted and the scripts gives error(i mean the script added).
plzz check.

Yes, tht's y u have to copy only the main script part.
Thanking You,

speedX

achiever

but adding just the main part of the script will delete all the notes, i dont think its good to be done, is it?
thks,
achiever.

bastya_elvtars

http://www.motobit.com/util/base64-decoder-encoder.asp

That online encoder in the comments is flawed. This one works.
Everything could have been anything else and it would have just as much meaning.

achiever

mutor the overwrite part seems not to be working it keeps on giving the same syntax thing even with /o as overwite
but new script is added without prob and works good.

bastya ur scripts giving error
[20:33] Syntax E:\Downloads\0.3.5.2[Fusion Hub]\scripts\testing.lua:149: attempt to perform arithmetic on field '?' (a nil value) on posting the enoded data from new link
thks,
achiever.

achiever

working good now,
thanks.
thks,
achiever.

SMF spam blocked by CleanTalk