PtokaX forum

Archive => Archived 5.1 boards => Help with scripts => Topic started by: Djdirect on 20 February, 2007, 18:38:03

Title: TextCommands 1.0c help
Post by: Djdirect on 20 February, 2007, 18:38:03
Hi all   ;) I would like that this script sends only txt in pm and a the user solely i change this

Code (lua) Select
--[[

TextCommands 1.0c 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 specified 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. With this lib
we can avoid the dreaded shell pop up.

Visit http://thewildplace.dk/ for this and many other great
extensions to the PtokaX hub software.



Changes from 1.0        04/26/06
+Added send menu to specified profiles

Changes from 1.0b        04/30/06
+Use command on hub tab to send in main, or on user list to send pm to selected nick
-Removed regbot option, bot must be regged to send pm's
+Added internal read code, to allow reading by profile
+No longer for use with PtokaX inbuilt reader
***Don't use 'texts' folder if Px reader is enabled




]]

TextCfg = {
--Command Menu Name
Menu = "• La Foire Aux Questions",-- frmHub:GetHubName() or "User Commands",
--Command Submenu Name
SubMenu = "• Choisir l'aide",
--Botname
Bot = frmHub:GetHubBotName() or "Command_Bot",
--If registering, does bot have a key?
BotIsOp = 1,
--Bot description
BotDesc = "La Foire Aux Questions",
--Bot Email address
BotMail = "Faq@domain.com",
--Path To Files
Dir = "faq",
--//-- Op's nick for status/error message
OpNick = "Boss",
--//-- Display status messages to OpNick?
Verbose = "on",
-- Who may receive context menu?
Profiles  = {
[-1] = 1, --Unregistered User
[0] = 1, --Master
[1] = 1, --Operator
[2] = 1, --Vip
[3] = 1, --Registered User
[4] = 1, --Moderator
[5] = 1, --NetFounder
[6] = 1, --Owner
}
}

Main = function()
Texts = {}
local pxuv = "PxUtilities v."
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()
pxuv = pxuv..PXU.GetVersion().." for ".._VERSION.." loaded."
OnError(pxuv)
SetTimer(5 * 60000)
StartTimer()
DoList()
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

OnTimer = function()
DoList()
end

NewUserConnected = function(user)
if TextCfg.Profiles[user.iProfile] and TextCfg.Profiles[user.iProfile] == 1 then
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
end
OpConnected = NewUserConnected

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

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, TextCfg.Bot, lines)
else
local reply = "L'user "..usr.." n'est pas "..
"en ligne, vérifier le pseudo."
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
ToArrival = ChatArrival

DoCmds = function(user)
local Menu,SubMenu = TextCfg.Menu,TextCfg.SubMenu
for i,v in ipairs(Texts) do
user:SendData("$UserCommand 1 1 "..Menu.."\\"..
SubMenu.."\\"..v.."$<%[mynick]> +"..v.."&#124;")
user:SendData("$UserCommand 1 2 "..Menu.."\\"..
SubMenu.."\\"..v.."$<%[mynick]> +"..v.." %[nick]&#124;")
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


i have 4 texts to send   1 go to pm ok 1 go to main chat ?????   :)
Title: Re: TextCommands 1.0c help
Post by: bastya_elvtars on 20 February, 2007, 18:59:04
Could you please post the whole script using code tags?
(BTW the chunk you posted is... weird).
Title: Re: TextCommands 1.0c help
Post by: Djdirect on 20 February, 2007, 20:42:21
Sorry Newbie :-\
Title: Re: TextCommands 1.0c help
Post by: Djdirect on 21 February, 2007, 08:08:48
 thank you Mutor

I know  PM the bot to have the text file returned in PM
Highlight a user to send the text to that user in PM.
Use the hub tab command to send to all in main.
is ok but  i need just in pm   
other if nick have tag ex:[DJH]Djdirect   
-- Who may receive special context menu? 0=no/1=yes
Special  = {
   [DJH]Djdirect = 1,
   Rizzo = 1,
   Nick1 = 1,
   Nick2 = 1,
   Etc = 0,
   },
}
script error line 70
Title: Re: TextCommands 1.0c help
Post by: bastya_elvtars on 21 February, 2007, 11:08:47
Djdirect, a piece of advice: you should post the exact error message from px.
Title: Re: TextCommands 1.0c help
Post by: Djdirect on 21 February, 2007, 15:43:55
merci a vous ;)