Got this script and i want a right click in it just trying everything but cant do it
-------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------
-- Command bot
-- Just sends the text in the text files in pm to the user who asked for it
-- Made by Donald_Duck
---------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------
sConf = {
sBot = frmHub:GetHubBotName(),
sFile1 = "active.txt",
sFile2 = "active-router.txt",
sFile3 = "hublist.txt",
sFile4 = "news.txt",
sFile5 = "reghelp.txt",
sFile6 = "windows2.txt",
sFile7 = "vip3.txt",
sFile8 = "private.txt",
sFile9 = "special.txt",
sFolder = "helping" -- folder where the file is stored
}
function Main()
frmHub:RegBot(sConf.sBot)
end
function ChatArrival(user,data)
local data = string.sub(data,1,-2)
local s,e,cmd = string.find (data, "%b<>%s+[%!%?%+%#](%S+)" )
if cmd then
local tCmds = {
["active"] = function(user,data)
user:SendPM(sConf.sBot,ReadFile(sConf.sFile1))
end,
["active-router"] = function(user,data)
user:SendPM(sConf.sBot,ReadFile(sConf.sFile2))
end,
["hublist"] = function(user,data)
user:SendPM(sConf.sBot,ReadFile(sConf.sFile3))
end,
["news"] = function(user,data)
user:SendPM(sConf.sBot,ReadFile(sConf.sFile4))
end,
["reghelp"] = function(user,data)
user:SendPM(sConf.sBot,ReadFile(sConf.sFile5))
end,
["windows"] = function(user,data)
user:SendPM(sConf.sBot,ReadFile(sConf.sFile6))
end,
["vip"] = function(user,data)
user:SendPM(sConf.sBot,ReadFile(sConf.sFile7))
end,
["private"] = function(user,data)
user:SendPM(sConf.sBot,ReadFile(sConf.sFile8))
end,
["special"] = function(user,data)
user:SendPM(sConf.sBot,ReadFile(sConf.sFile9))
end,
}
if tCmds[cmd] then
return tCmds[cmd](user,data), 1
end
end
end
function ReadFile(file)
local fFile = io.open(sConf.sFolder.."/"..file)
if fFile then
local message = fFile:read("*all");
fFile:close();
return message;
else
return file.." not found!"
end
end
Can somebody build me in a rightclick
Its for all profiles they got all the same commands
sMenu = "..::TEXT FILES::.."
function NewUserConnected(curUser)
curUser:SendData("$UserCommand 0 3 |")
curUser:SendData("$UserCommand 1 3 "..sMenu.."\\How to be active?$<%[mynick]> +active||")
curUser:SendData("$UserCommand 1 3 "..sMenu.."\\How to be active wirh router?$<%[mynick]> +active-router||")
curUser:SendData("$UserCommand 1 3 "..sMenu.."\\Hublists$<%[mynick]> +hublist||")
curUser:SendData("$UserCommand 1 3 "..sMenu.."\\News$<%[mynick]> +news||")
curUser:SendData("$UserCommand 1 3 "..sMenu.."\\How to register?$<%[mynick]> +reghelp||")
curUser:SendData("$UserCommand 1 3 "..sMenu.."\\windows2$<%[mynick]> +windows2||")
curUser:SendData("$UserCommand 1 3 "..sMenu.."\\vip3$<%[mynick]> +vip3||")
curUser:SendData("$UserCommand 1 3 "..sMenu.."\\private$<%[mynick]> +private||")
curUser:SendData("$UserCommand 1 3 "..sMenu.."\\special$<%[mynick]> +special||")
end
OpConnected=NewUserConnected
And copy text files to PtokaX\texts folder. It's easier.
Quote from: Hungarista on 23 April, 2006, 21:59:59
sMenu = "..::TEXT FILES::.."
function NewUserConnected(curUser)
curUser:SendData("$UserCommand 0 3 |")
curUser:SendData("$UserCommand 1 3 "..sMenu.."\\How to be active?$<%[mynick]> +active||")
curUser:SendData("$UserCommand 1 3 "..sMenu.."\\How to be active wirh router?$<%[mynick]> +active-router||")
curUser:SendData("$UserCommand 1 3 "..sMenu.."\\Hublists$<%[mynick]> +hublist||")
curUser:SendData("$UserCommand 1 3 "..sMenu.."\\News$<%[mynick]> +news||")
curUser:SendData("$UserCommand 1 3 "..sMenu.."\\How to register?$<%[mynick]> +reghelp||")
curUser:SendData("$UserCommand 1 3 "..sMenu.."\\windows2$<%[mynick]> +windows2||")
curUser:SendData("$UserCommand 1 3 "..sMenu.."\\vip3$<%[mynick]> +vip3||")
curUser:SendData("$UserCommand 1 3 "..sMenu.."\\private$<%[mynick]> +private||")
curUser:SendData("$UserCommand 1 3 "..sMenu.."\\special$<%[mynick]> +special||")
end
OpConnected=NewUserConnected
And copy text files to PtokaX\texts folder. It's easier.
Argh! The table method was more elegant! Please make another with that! :P
Thx Hungarista
Almost had it myself only forgot a few little things like:
function NewUserConnected(curUser)
I had:
function NewUserConnected(user)
And forgot this one:
OpConnected=NewUserConnected
Quote from: Mutor on 23 April, 2006, 23:18:05
This script is redundant to the inbuilt PtokaX Text reader, although the right click is not.
As bastya says the table is the way to go.
suggest you use bluebears pxutilities extension lib to populate that table,
with using os.execute and shell popups.
Example:
--[[
TextCommands 1.0 LUA 5.0/5.1
By Mutor 04/23/06
Generates a list of text files in the specified folder
Sends context menus (right click) to all users.
**IMPORTANT NOTE: This script requires bluebear's Px extension
library, PxUtilities. It's available for both Lua 5.0.2 & Lua 5.1
This script will not work without it, and it's free.
Visit http://thewildplace.dk/ for this and many other great
extensions to the PtokaX hub software.
]]
TextCfg = {
--Command Menu Name
Menu = frmHub:GetHubName() or "User Commands",
--Command Submenu Name
SubMenu = "Text Reader",
--Botname
Bot = frmHub:GetHubBotName() or "Command_Bot",
--Register the bot? [show in user list]
RegBot = "yes",
--If registering, does bot have a key?
BotIsOp = 1,
--Bot description
BotDesc = "I send user commands",
--Bot Email address
BotMail = "user@domain.com",
--Path To Files
Dir = "C:\\PtokaX+\\texts",
--//-- Op's nick for status/error message
OpNick = "Mutor",
--//-- Display status messages to OpNick?
Verbose = "on",
}
Main = function()
Texts = {}
if _VERSION == "Lua 5.1" then --Both paths reflect the root of Px per LUA version
libinit = package.loadlib("PxUtilities_l51.dll", "_libinit")
gc = "collect"
else
libinit = loadlib("../PxUtilities.dll", "_libinit")
gc = nil
end
libinit()
SetTimer(5 * 60000)
StartTimer()
DoList()
if TextCfg.RegBot == "yes" then
if TextCfg.Bot ~= frmHub:GetHubBotName() or
TextCfg.Bot == frmHub:GetHubBotName() and not frmHub:GetHubBot() then
frmHub:RegBot(TextCfg.Bot, TextCfg.BotIsOp, TextCfg.BotDesc, TextCfg.BotMail)
end
end
end
OnTimer = function()
DoList()
end
NewUserConnected = function(user)
local Prof = GetProfileName(user.iProfile) or "Unregistered User"
user:SendData(TextCfg.Bot, "Welcome "..user.sName..", "..Prof.."'s text commands "..
"enabled. Right click hub tab or user list for menu.")
DoCmds(user)
end
OpConnected = NewUserConnected
OnError = function(msg)
if TextCfg.Verbose == "on" then
SendToNick(TextCfg.OpNick,msg)
end
end
DoCmds = function(user)
local Menu,SubMenu = TextCfg.Menu,TextCfg.SubMenu
for i,v in ipairs(Texts) do
user:SendData("$UserCommand 1 3 "..Menu.."\\"..
SubMenu.."\\"..v.."$<%[mynick]> +"..v.."|")
end
collectgarbage(gc)
end
DoList = function()
Texts = {}
local FileSize,FileCount = 0,0
local result = PXU.FindFirstFile(TextCfg.Dir.."\\*.*")
if result == 0 then
OnError(TextCfg.Dir.." = "..PXU.GetErrorString(PXU.GetLastError()))
return 1
else
while result ~= 0 do
result = PXU.FindNextFile()
if result ~= 0 then
local FileName = ""
FileName = FileInfo.cFileName() or FileInfo.cAltFileName()
if not FileInfo.IsDirectory() then
if string.find(FileName,"(%.txt)$") then
FileName = string.gsub(FileName,"(%.txt)$","")
table.insert(Texts,FileName)
end
end
end
end
PXU.CloseFind()
collectgarbage(gc)
end
end
[ Get the PxUtilities extension library (http://thewildplace.dk/#PxUtilities) ]
Hi Mutor!
How could I change that instead of sending the text to main send it to the bot's PM?
I want to avoid spamming in main and if they want to show it in main they have
to copy from the bots PM and paste it in the main.
Hope you understand what I'm asking for :)
Thanks in advance!
Ok, I changed the text that is Red.
ChatArrival = function(user, data)
if TextCfg.Profiles[user.iProfile] and TextCfg.Profiles[user.iProfile] == 1 then
local s,e,to = string.find(data,"^$To:%s(%S+)%s+From:")
local s,e,cmd = string.find( data, "%b<>%s%p(%w+)")
local s,e,usr = string.find( data, "%b<>%s%p%w+%s(%S+)|$")
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(TextCfg.Dir.."\\"..v..".txt") do
lines = lines..line.."\r\n"
end
if usr then
local nick = GetItemByName(usr)
if nick then
SendPmToNick(nick.sName, user.sName, lines)
else
local reply = "The user "..usr.." is not "..
"online, check your spelling."
if to and to == TextCfg.Bot then
user:SendPM(TextCfg.Bot,reply)
else
user:SendData(TextCfg.Bot,reply)
end
end
return 1
else
user:SendPM(TextCfg.Bot, lines)
return 1
end
end
end
end
end
end
First the Ascii to a User Responds with My nick instead of the Bots nick.
Second ALL Ascii goes to PM :)
Thanks for this Great script Mutor.