PtokaX forum

Archive => Archived 5.0 boards => Request for scripts => Topic started by: tassen on 19 October, 2005, 23:43:48

Title: Text in PM not Main!
Post by: tassen on 19 October, 2005, 23:43:48
I want this going to user at PM instaead of message in Main.

Regards tassen



-- texter bot by plop

-- thx 2 chilla for the faster routine for opening the files

-- shows text files from a folder named text.

-- doesn't mather what prefix it used.

-- if the file exist it shows.

--

-- Converted to LUA 5 by Mutor 2/28/05

--



Bot = "#[Bot]TexT"

FDFolder = "textmain"



function Main()

   frmHub:RegBot(Bot)

end



function ChatArrival(user, data)

   data=string.sub(data,1,string.len(data)-1)

   if( string.sub(data, 1, 1) == "<" ) then

      s,e,cmd = string.find(data,"%b<>%s+(%S+)")

      cmd = string.sub(cmd, 2,string.len(cmd))

      if io.open(FDFolder.."/"..cmd..".txt",r) ~= nil then

         showtext(user, cmd)

         return 1

      end

   end

end



function ToArrival(user, data)

    if(string.sub(data, 1, 4)) == "$To:" and (string.sub(data, 6,string.len(Bot)+5))== Bot then

        s,e,cmd = string.find(data,"^$To:%s+%S+%s+From:%s+%S+%s+%$%b<>%s+(%S+)|$")

        cmd = string.sub(cmd, 2,string.len(cmd))

            if io.open(FDFolder.."/"..cmd..".txt",r) ~= nil then

                showtext(user, cmd)

                return 1

            end

   end

end



function showtext(user, file)

local contents ="\r\n\r\n"

for line in io.lines(FDFolder.."/"..file..".txt") do

    contents = contents..line.."\r\n"

    end

SendToAll(Bot, contents.."\r\n|")

end



function showtextold(user, cmd)

local lines="\r\n\r\n"

    for line in io.lines(file) do

        lines = lines..line.."\r\n"

    end

    user:SendData(Bot, lines.." |")

end



Title:
Post by: Rincewind on 19 October, 2005, 23:52:58
Change;

function showtext(user, file)

  local contents ="\r\n\r\n"
  for line in io.lines(FDFolder.."/"..file..".txt") do
      contents = contents..line.."\r\n"
  end
[COLOR=royalblue]  SendToAll(Bot, contents.."\r\n|")[/COLOR]

end

to;

function showtext(user, file)

  local contents ="\r\n\r\n"
  for line in io.lines(FDFolder.."/"..file..".txt") do
      contents = contents..line.."\r\n"
  end
[COLOR=red]  user:SendPM(Bot, contents.."\r\n|")[/COLOR]

end
Title:
Post by: Herman on 20 October, 2005, 22:53:11
Is it possible to make it so it can use different prefix if i want it to send to PM or to mainchat? (! for pm and + for mainchat), or put in a PM or MC after the command?
Title:
Post by: bastya_elvtars on 20 October, 2005, 23:33:47
Is this what you want? :)

-- texter bot by plop
-- thx 2 chilla for the faster routine for opening the files
-- shows text files from a folder named text.
-- doesn't mather what prefix it used.
-- if the file exist it shows.

--

-- Converted to LUA 5 by Mutor 2/28/05
--

-- some bugs, addons and optimizations by bastya_elvtars
-- bugs fixed by bastya_elvtars
-- commented out the 'does not exist' part

-- bot's data
Bot =
  {
  name="#[Bot]TexT",
  desc="texter",
  email="text@hub"
  }


FDFolder = "textmain" -- folder inside scripts folder!!!
PMPref="+" -- with this prefix, text shown in PM
MainPref="-" -- with this prefix, text shown in main

function Main()
  frmHub:RegBot(Bot.name,1,Bot.desc,Bot.email)
  prf="([%"..PMPref.."%"..MainPref.."])"
end

function ChatArrival(user, data)
  data=string.sub(data,1,string.len(data)-1)
  if( string.sub(data, 1, 1) == "<" ) then
    local s,e,pref,cmd = string.find(data,"%b<>%s+"..prf.."(%S+)")
    if cmd then return showtext(user,cmd,pref) end
  end
end

function ToArrival(user, data)
  if string.sub(data, 1, 4) == "$To:" and string.sub(data, 6,string.len(Bot)+5)== Bot then
    local s,e,pref,cmd = string.find(data,"^$To:%s+%S+%s+From:%s+%S+%s+%$%b<>%s+"..prf.."(%S+)|$")
    if cmd then return showtext(user,cmd,pref) end
  end
end

function showtext(user,file,pref)
  local f=io.open(FDFolder.."/"..file..".txt","r")
  if f then
    local contents = string.gsub(f:read("*a"),string.char(10), "\r\n")
    if pref==PMPref then
      user:SendPM(Bot.name,"\r\n"..contents.."\r\n")
    else
      user:SendData(Bot.name,"\r\n"..contents.."\r\n")
    end
    f:close()
--   else
--     if pref==PMPref then
--       user:SendPM(Bot.name,"The file \""..file.."\"does not exist.")
--     else
--       user:SendData(Bot.name,"The file \""..file.."\"does not exist.")
--     end
  end
end
Title:
Post by: Herman on 21 October, 2005, 11:23:47
Probably, but now i cant write any text....i get a message saying the file "robably dont exist" when i wrote probably in mainchat
Title:
Post by: bastya_elvtars on 21 October, 2005, 12:09:49
Sorry, I am dumb. Edited my post above.

BTW is that an archon's face in your avatar? ;)
Title:
Post by: Herman on 21 October, 2005, 12:15:38
Yes it is archon :)
Title:
Post by: bastya_elvtars on 21 October, 2005, 12:21:14
QuoteOriginally posted by Herman
Yes it is archon :)

I like Zerg better. Guardian/Defiler combo forever!  :D
Title:
Post by: Herman on 21 October, 2005, 14:20:11
I slightly modded the script to suit my needs


-- texter bot by plop
-- thx 2 chilla for the faster routine for opening the files
-- shows text files from a folder named text.
-- doesn't mather what prefix it used.
-- if the file exist it shows.
--
-- Converted to LUA 5 by Mutor 2/28/05
--

-- some bugs, addons and optimizations by bastya_elvtars
-- bugs fixed by bastya_elvtars
-- commented out the 'does not exist' part
-- slightly modded by Herman


-- bot's data

-- Settings
Bot =

  {
  name="?Texter?",
  desc="texter",
  email="text@hub"
  }


FDFolder = "textmain" -- folder inside scripts folder!!!
PMPref="-" -- with this prefix, text shown in PM
MainPref="+" -- with this prefix, text shown in main
-- /Settings


function Main()
  frmHub:RegBot(Bot.name,1,Bot.desc,Bot.email)
  prf="([%"..PMPref.."%"..MainPref.."])"
end

function ChatArrival(user, data)
  data=string.sub(data,1,string.len(data)-1)
  if( string.sub(data, 1, 1) == "<" ) then
    local s,e,pref,cmd = string.find(data,"%b<>%s+"..prf.."(%S+)")
    if cmd then return showtext(user,cmd,pref) end
  end
end

function ToArrival(user, data)
  if string.sub(data, 1, 4) == "$To:" and string.sub(data, 6,string.len(Bot)+5)== Bot then
    local s,e,pref,cmd = string.find(data,"^$To:%s+%S+%s+From:%s+%S+%s+%$%b<>%s+"..prf.."(%S+)|$")
    if cmd then return showtext(user,cmd,pref) end
  end
end

function showtext(user,file,pref)
  local f=io.open(FDFolder.."/"..file..".txt","r")
  if f then
    local contents = string.gsub(f:read("*a"),string.char(10), "\r\n")
    if pref==PMPref then
      SendPmToAll(Bot.name,"\r\n"..contents.."\r\n")
    else
      SendToAll(Bot.name,"\r\n"..contents.."\r\n")
    end
    f:close()
--   else
--     if pref==PMPref then
--       user:SendPMToAll(Bot.name,"The file \""..file.."\"does not exist.")
--     else
--       user:SendData(Bot.name,"The file \""..file.."\"does not exist.")
--     end
  end
end


This script will post the textfiles in mainchat for all to see...and mass message it to all if using the - tag
Title:
Post by: Dessamator on 22 October, 2005, 15:41:18
QuoteOriginally posted by bastya_elvtars
QuoteOriginally posted by Herman
Yes it is archon :)

I like Zerg better. Guardian/Defiler combo forever!  :D

Zerg are weak,  protoss carriers and/or high templar or dragoons clean that combo easily.
:D
anyways back to the topic, nicely done herman, although u dont need this line :
 if( string.sub(data, 1, 1) == "<" ) then

and the corresponding "end" should also be omitted.
Title:
Post by: bastya_elvtars on 22 October, 2005, 17:58:06
QuoteOriginally posted by Dessamator
Zerg are weak,  protoss carriers and/or high templar or dragoons clean that combo easily.
:D

Looks like it's time for a game... mail me the details, if interested. :)
Title:
Post by: Herman on 27 October, 2005, 01:25:19
I discovered that the above script allowed anyone to use the mass message commands....so i added so that only operators can use it

-- texter bot by plop
-- thx 2 chilla for the faster routine for opening the files
-- shows text files from a folder named text.
-- doesn't mather what prefix it used.
-- if the file exist it shows.
--
-- Converted to LUA 5 by Mutor 2/28/05
--

-- some bugs, addons and optimizations by bastya_elvtars
-- bugs fixed by bastya_elvtars
-- commented out the 'does not exist' part
-- slightly modded by Herman


-- bot's data

-- Settings
Bot =

  {
  name="?Robocop?",
  desc="",
  email=""
  }


FDFolder = "textmain" -- folder inside scripts folder!!!
PMPref="-" -- with this prefix, text shown in PM
MainPref="+" -- with this prefix, text shown in main
-- /Settings


function Main()
  frmHub:RegBot(Bot.name,1,Bot.desc,Bot.email)
  prf="([%"..PMPref.."%"..MainPref.."])"
end

function ChatArrival(user, data)
  data=string.sub(data,1,string.len(data)-1)
  if( string.sub(data, 1, 1) == "<" ) then
    local s,e,pref,cmd = string.find(data,"%b<>%s+"..prf.."(%S+)")
    if cmd and user.bOperator then return showtext(user,cmd,pref) else end
  end
end

function ToArrival(user, data)
  if string.sub(data, 1, 4) == "$To:" and string.sub(data, 6,string.len(Bot)+5)== Bot then
    local s,e,pref,cmd = string.find(data,"^$To:%s+%S+%s+From:%s+%S+%s+%$%b<>%s+"..prf.."(%S+)|$")
    if cmd then return showtext(user,cmd,pref) end
  end
end

function showtext(user,file,pref)
  local f=io.open(FDFolder.."/"..file..".txt","r")
  if f then
    local contents = string.gsub(f:read("*a"),string.char(10), "\r\n")
    if pref==PMPref then
      SendPmToAll(Bot.name,"\r\n"..contents.."\r\n")
    else
      SendToAll(Bot.name,"\r\n"..contents.."\r\n")
    end
    f:close()
--   else
--     if pref==PMPref then
--       user:SendPMToAll(Bot.name,"The file \""..file.."\"does not exist.")
--     else
--       user:SendData(Bot.name,"The file \""..file.."\"does not exist.")
--     end
  end
end


If you see any errors just post it
Title:
Post by: Herman on 28 October, 2005, 11:59:41
Im getting a errormessage from the script...could anyone see if they figure it out?

Syntax C:\PtokaX\scripts\texter.lua:48: bad argument #1 to `len' (string expected, got table)
Title:
Post by: [UK]Madman on 28 October, 2005, 15:01:39
This line

if string.sub(data, 1, 4) == "$To:" and string.sub(data, 6,string.len(Bot)+5)== Bot then

Needs to be changed to

if string.sub(data, 6,string.len(Bot.name)+5)== Bot.name then

The first string.sub can be removed as this is to check if the data is a PM, and thats the only data sent through the ToArrival.

The error was caused by trying to find the string length of the table Bot, and not the bots name.
Title:
Post by: Herman on 03 November, 2005, 00:20:14
I need some help with the script....i dont want it to return the command in mainchat (the +filename command) How do i remove it?
Title:
Post by: Herman on 03 November, 2005, 16:34:04
Thnx mate, worked like a charm.
But could you explain what the difference between the two ChatArrival functions? (Trying to learn something, so i dont have to ask next time  :D )
Title:
Post by: Herman on 07 November, 2005, 19:36:20
Would like it to make the posting a little more.....nice looking.

example:
Message from [Sender]
-------------------------------------
Join the hub Forum blah blah blah
-------------------------------------

Something like that.
Title:
Post by: Herman on 08 November, 2005, 17:40:21
Managed to change it myself....(yes im very proud of it...very very proud  :D )
-- texter bot by plop
-- thx 2 chilla for the faster routine for opening the files
-- shows text files from a folder named text.
-- doesn't mather what prefix it used.
-- if the file exist it shows.
--
-- Converted to LUA 5 by Mutor 2/28/05
--

-- some bugs, addons and optimizations by bastya_elvtars
-- bugs fixed by bastya_elvtars
-- commented out the 'does not exist' part
-- slightly modded by Herman


-- bot's data

-- Settings
Bot =

  {
  name=frmHub:GetHubBotName()
  }


FDFolder = "textmain" -- folder inside scripts folder!!!
PMPref="-" -- with this prefix, text shown in PM
MainPref="+" -- with this prefix, text shown in main
-- /Settings


function Main()
  frmHub:RegBot(Bot.name,1,Bot.desc,Bot.email)
  prf="([%"..PMPref.."%"..MainPref.."])"
end

function ChatArrival(user, data)
data=string.sub(data,1,string.len(data)-1)
if( string.sub(data, 1, 1) == "<" ) then
local s,e,pref,cmd = string.find(data,"%b<>%s+"..prf.."(%S+)")
if cmd and user.bOperator then
showtext(user,cmd,pref)
return 1
end
end
end

function ToArrival(user, data)
  if string.sub(data, 6,string.len(Bot.name)+5)== Bot.name then
    local s,e,pref,cmd = string.find(data,"^$To:%s+%S+%s+From:%s+%S+%s+%$%b<>%s+"..prf.."(%S+)|$")
    if cmd then return showtext(user,cmd,pref) end
  end
end

function showtext(user,file,pref)
  local f=io.open(FDFolder.."/"..file..".txt","r")
  if f then
    local contents = string.gsub(f:read("*a"),string.char(10), "\r\n")
    if pref==PMPref then
      SendPmToAll(Bot.name,"Message from:  "..user.sName.."\r\n\r\n----------------------------------------------------------------------------------------------\r\n"..contents.."\r\n----------------------------------------------------------------------------------------------\r\n")
    else
      SendToAll(Bot.name,"Message from:  "..user.sName.."\r\n\r\n----------------------------------------------------------------------------------------------\r\n"..contents.."\r\n----------------------------------------------------------------------------------------------\r\n")
    end
    f:close()
--   else
--     if pref==PMPref then
--       user:SendPMToAll(Bot.name,"The file \""..file.."\"does not exist.")
--     else
--       user:SendData(Bot.name,"The file \""..file.."\"does not exist.")
--     end
  end
end
Title:
Post by: Herman on 09 November, 2005, 08:11:53
Cool, thnx for your help Mutor

Couldnt get the string.rep("-",150) command to work. dunno what i did wrong tho...but here is the final addition of the script. (added two things)

-- texter bot by plop
-- thx 2 chilla for the faster routine for opening the files
-- shows text files from a folder named text.
-- doesn't mather what prefix it used.
-- if the file exist it shows.
--
-- Converted to LUA 5 by Mutor 2/28/05
--

-- some bugs, addons and optimizations by bastya_elvtars
-- bugs fixed by bastya_elvtars
-- commented out the 'does not exist' part
-- slightly modded by Herman
-- Added: Change of header text option in settings
-- Added: Shows who sent the mass message
--

-- bot's data

-- Settings
Bot =

  {
  name=frmHub:GetHubBotName()
  }

header = "PcGamers4Ever"  -- Name or text to show in the header (over and under the contents of the text file)
FDFolder = "textmain" -- folder inside scripts folder!!!
PMPref="-" -- with this prefix, text shown in PM
MainPref="+" -- with this prefix, text shown in main
-- /Settings


function Main()
  frmHub:RegBot(Bot.name,1,Bot.desc,Bot.email)
  prf="([%"..PMPref.."%"..MainPref.."])"
end

function ChatArrival(user, data)
data=string.sub(data,1,string.len(data)-1)
if( string.sub(data, 1, 1) == "<" ) then
local s,e,pref,cmd = string.find(data,"%b<>%s+"..prf.."(%S+)")
if cmd and user.bOperator then
showtext(user,cmd,pref)
return 1
end
end
end

function ToArrival(user, data)
  if string.sub(data, 6,string.len(Bot.name)+5)== Bot.name then
    local s,e,pref,cmd = string.find(data,"^$To:%s+%S+%s+From:%s+%S+%s+%$%b<>%s+"..prf.."(%S+)|$")
    if cmd then return showtext(user,cmd,pref) end
  end
end

function showtext(user,file,pref)
  local f=io.open(FDFolder.."/"..file..".txt","r")
  if f then
    local contents = string.gsub(f:read("*a"),string.char(10), "\r\n")
    if pref==PMPref then
      SendPmToAll(Bot.name,"Message from:  "..user.sName.."\r\n\r\n?????? ?? ?? ???????? ?? ?????? ?? ?? ????????"
                                                        ..header
                                                        .."?? ?????? ?? ?? ???????? ?? ??????? ?? ?? ???????? ?? ??????\r\n\r\n"
                                                        ..contents
                                                        .."\r\n\r\n?????? ?? ?? ???????? ?? ?????? ?? ?? ????????"
                                                        ..header
                                                        .."?? ?????? ?? ?? ???????? ?? ??????? ?? ?? ???????? ?? ??????")
    else
      SendToAll(Bot.name,"Message from:  "..user.sName.."\r\n\r\n?????? ?? ?? ???????? ?? ?????? ?? ?? ????????"
                                                        ..header
                                                        .."?? ?????? ?? ?? ???????? ?? ??????? ?? ?? ???????? ?? ??????\r\n\r\n"
                                                        ..contents
                                                        .."\r\n\r\n?????? ?? ?? ???????? ?? ?????? ?? ?? ????????"
                                                        ..header
                                                        .."?? ?????? ?? ?? ???????? ?? ??????? ?? ?? ???????? ?? ??????")
    end
    f:close()
--   else
--     if pref==PMPref then
--       user:SendPMToAll(Bot.name,"The file \""..file.."\"does not exist.")
--     else
--       user:SendData(Bot.name,"The file \""..file.."\"does not exist.")
--     end
  end
end
Title:
Post by: IVANNOFKE on 15 November, 2005, 18:00:05
Hello Herman,

I still using ur texter bot  wich allows every user to use command, I like it that way LOL.

But still got a question.
Is it possible to send the textfile in PM to the user who typed command and to nobody else?
Cause now when somebody use comand -textfilename all users get the textfile in PM like mass msg.
And i only want the users wich use command get PM.

Hope u can help me.
Title:
Post by: Herman on 16 November, 2005, 00:32:59
The latest version we made only lets Operators use the commands. But Ptokax have text commands thing built in, so if you put the text files in the Ptokax/texts folder you can use the inbuilt commands. Example: !active (instead of +active and -active)
Im only using this bot as a aid for the Operators with standarized messages.

Hope this helps

Greetings

Herman

Ps! The latest version is much better i think. Get it  Here  (http://pg4e.no-ip.org/forum/dload.php?action=file&file_id=9)