Help with ReaderCommands 1.0c LUA 5.11 [Strict] [API 2]
 

Help with ReaderCommands 1.0c LUA 5.11 [Strict] [API 2]

Started by miago, 21 April, 2008, 15:58:48

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

miago

Hi, just me again.

Have had an easy rightclick lua before but wanted to test this one, so, therefor I wonder, since I have textfiles both in english and swedish in the textsfolder under ptokax, how can I separate them with this script so it looks kinda this under RC?

- hubname -//english//texten.1
                               texten.2
                //swedish//textswe.1
                               textswe.2

What I get now is:
- hubname -//textfiles//texten.1
                                texten.2
                                textswe.1
                                textswe.2

the other thing I wondered about, I got that the messages comes in main from hubtab or in pm from userlist, but, how do i change the part so it always comes in pm and not in mc at all? Ive tried 1 3 and added %nick but i cant get it to work.

DoCmds = function(user)
	local Menu,SubMenu = TextCfg.Menu,TextCfg.SubMenu
	for i,v in ipairs(Texts) do
		local x = v:gsub(TextCfg.SepChr," ")
		Core.SendToNick(user.sNick,"$UserCommand 1 1 "..Menu.."\\"..
		SubMenu.."\\"..x.."$<%[mynick]> +"..v.."&#124;|")
		Core.SendToNick(user.sNick,"$UserCommand 1 2 "..Menu.."\\"..
		SubMenu.."\\"..x.."$<%[mynick]> +"..v.." %[nick]&#124;|")
	end
	collectgarbage("collect")


Thx // Miago

--[[

	ReaderCommands 1.0c LUA 5.11 [Strict] [API 2]
	
	By Mutor        04/26/06

	-Generates a list of text files for the PtokaX inbuilt text reader [PtokaX\texts folder]
	-Sends context menus (right click) to users with profile permission bRefreshTxt enabled
	-Use command on hub tab to send in main, or on user list to send pm to selected nick
	-Use user list command  to bot to return file in pm to yourself

	**IMPORTANT NOTE: This script requires the Px extension library,PxLFS
	This script will not work without it, and it's free. With this lib we 
	can avoid the dreaded shell pop up.
	
	Download PXLuaFileSystem 1.2.1:
	http://www.PtokaX.org/files/Libs-0.4.0.0RC6/PXLuaFileSystem-1.2.1.7z
	
	+Changes from 1.0	03/17/06
		+Added support for filenames with space [sort of :P]
	
	+Changes from 1.0b	10/18/07
		~Converted to the new PtokaX API
		~Exchanged library: PxUtilities with PxLuaFileSystem
		+Added current directory var, return to current after listing.
		+Added additionional error messages for lfs extension
]]

TextCfg = {
-- Command Menu Name
Menu = "- hubname -",   --SetMan.GetString(0),
-- Command Submenu Name
SubMenu = "textfilesr",
-- Botname
Bot = SetMan.GetString(21) or "Px_Reader",
-- Should bot have a key?
BotIsOp = 1,
-- Bot description
BotDesc = "I show text files in main and send them in pm",
-- Bot Email address
BotMail = "user@domain.com",
-- Op's nick for status/error message
OpNick = "Mutor",
-- Send status messgaes to OpNick?  "on"/"off"
Verbose = "on",
-- Separater character, replace by space char in menus
SepChr = "_",
}

OnStartup = function()
	Texts = {}
	require "pxlfs"
	if lfs._VERSION then
		TextCfg.Scp = "ReaderCommands 1.0c"
		OnError(TextCfg.Scp.." running: "..lfs._VERSION.." for ".._VERSION.." loaded.")
		TextCfg.Timer = TmrMan.AddTimer(5 * 60000)
		DoList()
		if TextCfg.Bot ~= SetMan.GetString(21) or
			TextCfg.Bot == SetMan.GetString(21) and not SetMan.GetBool(17) then
			Core.RegBot(TextCfg.Bot, TextCfg.BotIsOp, TextCfg.BotDesc, TextCfg.BotMail)
		end
	else
		return OnError("Failed to load pxlfs.lua. Check path / file."), true
	end
end

OnTimer = function(Id)
	if Id == TextCfg.Timer then
		DoList()
	end
end

UserConnected = function(user)
	if user.iProfile ~= -1 and ProfMan.GetProfilePermissions(user.iProfile).bRefreshTxt then
		local Prof
		if user.iProfile ~= -1 then
			Prof = ProfMan.GetProfile(user.iProfile).sProfileName
		else
			Prof = "Unregistered User"
		end
		Core.SendToNick(user.sNick,"<"..TextCfg.Bot.."> Welcome "..user.sNick..", "..
		Prof.."'s PtokaX inbuilt text commands ".."enabled. Right click hub tab or user list for menu.|")
		DoCmds(user)
	end
end
OpConnected,RegConnected = UserConnected,UserConnected

OnError = function(msg)
	if TextCfg.Verbose == "on" and Core.GetUser(TextCfg.OpNick) then 
		Core.SendToNick(TextCfg.OpNick,"<"..TextCfg.Bot.."> "..msg.."|")
	end
end

ChatArrival = function(user, data)
	if user.iProfile ~= -1 and ProfMan.GetProfilePermissions(user.iProfile).bRefreshTxt then
		local _,_,cmd = data:find( "%b<> %p([%w"..TextCfg.SepChr.."]+)")
		local _,_,usr = data:find( "%b<> %p%w+ (%S+)|$")
		local _,_,to = data:find("^$To: (%S+) From:")
		if cmd then
			for i,v in ipairs(Texts) do
				if cmd == v then
					local lines="\r\n\r\n"
					for line in io.lines("..\\texts\\"..v..".txt") do
						lines = lines..line.."\r\n"
					end
					if usr then
						local nick = Core.GetUser(usr)
						if nick then
							return Core.SendPmToNick(nick.sNick, TextCfg.Bot, lines),true
						else
							if usr == TextCfg.Bot then
								return Core.SendPmToNick(user.sNick,TextCfg.Bot,lines),true
							end
						end
					else
						if to and to == TextCfg.Bot then
							return Core.SendPmToNick(user.sNick,TextCfg.Bot,lines),true
						else
							return Core.SendToAll("<"..TextCfg.Bot.."> "..lines),true
						end
					end
				end
			end
		end
	end
end
ToArrival = ChatArrival

DoCmds = function(user)
	local Menu,SubMenu = TextCfg.Menu,TextCfg.SubMenu
	for i,v in ipairs(Texts) do
		local x = v:gsub(TextCfg.SepChr," ")
		Core.SendToNick(user.sNick,"$UserCommand 1 1 "..Menu.."\\"..
		SubMenu.."\\"..x.."$<%[mynick]> +"..v.."&#124;|")
		Core.SendToNick(user.sNick,"$UserCommand 1 2 "..Menu.."\\"..
		SubMenu.."\\"..x.."$<%[mynick]> +"..v.." %[nick]&#124;|")
	end
	collectgarbage("collect")
end

DoList = function()
	Texts = {}
	local Path = Core.GetPtokaXPath().."texts"
	local cd,err = lfs.currentdir()
	local f,e = lfs.chdir(Path)
	if f then
		for item in lfs.dir(Path) do
			if item:find("%.txt$") then
				local x = lfs.attributes(item)
				if x and x.mode ~= "directory" then
					os.rename(Path.."/"..item,Path.."/"..item:gsub("%s",TextCfg.SepChr))
					local file = item:gsub("%.txt$","")
					table.insert(Texts,file)
				end
			end
		end
		if cd then
			local _,cderr = lfs.chdir(cd)
			if cderr then
				OnError(cderr:gsub("%s"," "))
			end
		else
			OnError(err:gsub("%s"," "))
		end
		collectgarbage("collect")
	else
		OnError(e:gsub("%s"," "))
	end
	--OnError ("File listing refreshed, there are "..#Texts.." file(s) available.")
end



Edit1: For the part to separate english from swedish in the RC-menu, I just did so that I renamed the files so the start with English-bla blab or Svenska-Bla albalala so don't put down any work on that. It'll do this way :D
so the part remaining is about getting all msg in pm....sry for making u read all I write, but hopefully we'll all get happy in the end   ;)
Being a biatch aint easy ;)

miago

.. yep I think i've understood that, but sry for being
annoying, but i dont get how to make it work...have tried all variations (I think)
and can't get the info to come just in pm's to your nick from the bot, nor from the hubtab or from the userlist.
Would be greatful for an instruction on where to change numbers or info in the file for that to happen.
"Dummies for lua-ptokax-file" to sell could maybe be a project for U good guys :) ;)
Sincerly
miago
:hugs:

Edit1: I tried to write the q i got under the right thread, and here I just rly need some help to make it work, not change the script =D.
Being a biatch aint easy ;)

miago

 ;D
sure i get it =) but this is what I get when doing that, rightclicking in userslist and choosing a file under the submenu (as master)
[2008-04-22-01:43:56] <PCadm> +English-RegisterAfriend PCadm


The file is named: English-RegisterAFriend.txt in the textsfolder
Doing the same on the hubtab gets the filetext in main without problem.

The ordinary user, same result when trying in userslist and "it" also sees my earlier attempt in mc:
[01:43:56] <PCadm> +English-RegisterAfriend PCadm
[01:47:34] <[10mbit]test> +English-RegisterAfriend [10Mbit]test

for the ordinary user it works from the hubtab also

and this is how it looks in script
DoCmds = function(user)
	local Menu,SubMenu = TextCfg.Menu,TextCfg.SubMenu
	for i,v in ipairs(Texts) do
		local x = v:gsub(TextCfg.SepChr," ")
		Core.SendToNick(user.sNick,"$UserCommand 1 1 "..Menu.."\\"..
		SubMenu.."\\"..x.."$<%[mynick]> +"..v.."&#124;|")
		Core.SendToNick(user.sNick,"$UserCommand 1 2 "..Menu.."\\"..
		SubMenu.."\\"..x.."$<%[mynick]> +"..v.."%[nick]&#124;|")
	end
	collectgarbage("collect")
end

Being a biatch aint easy ;)

miago

Good morning.

Deleted the script I got, copied the script from ur site and did only change the menu name, submenu and opnick in the file.
I still get the same result when trying from users list. Testing on 3 clients, apexdc++ 1.0.1, fuldc 6.78 and airdc++ 1.08

[08:02:44] <PCadm> +English-RegisterAfriend -HubBot-
[08:02:51] <[VIP]test> +Svenska-F?rkortningar -HubBot-
[08:03:07] <[ONLINE]test> +English-Slotrules -HubBot-

Have restarted all clients, restarted ptokax and reloaded all textfiles and the opnick doesnt get any error messages.
Gonna lay this aside for a while, feels like my head is cracking apart, and gonna test the other scripts U've fixed instead.
Regards
miago
Being a biatch aint easy ;)

miago

Hi.

Still having same problem, only changed the opnick in the file. (Std hubname, skriptname and the bot registers)
When rightclicking on userslist I still get this =(

[2008-04-23-11:48:59] <PCadm> +Svenska-Regler [TextReader]

So I tried this (red text what I added), and yes, the problem reaccured.

      Core.SendToNick(user.sNick,"$UserCommand 1 1 "..Menu.."\\"..
      SubMenu.."\\"..x.."$<%[mynick]> +"..v.." %[nick]&#124;|")
      Core.SendToNick(user.sNick,"$UserCommand 1 2 "..Menu.."\\"..
      SubMenu.."\\"..x.."$<%[mynick]> +"..v.." %[nick]&#124;|")

When rightclicking on hubtab same thing happend now:

[2008-04-23-11:50:39] <PCadm> +Svenska-SlotRegler

Regards
miago
PS Didnt know if I should write here or in the finished script part, so I did it here for this time.
Being a biatch aint easy ;)

SMF spam blocked by CleanTalk