Text in PM not Main!
 

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

Text in PM not Main!

Started by tassen, 19 October, 2005, 23:43:48

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

tassen

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

Rincewind

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

Herman

#2
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?
Owner of PcGamers4Ever

bastya_elvtars

#3
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
Everything could have been anything else and it would have just as much meaning.

Herman

Probably, but now i cant write any text....i get a message saying the file "robably dont exist" when i wrote probably in mainchat
Owner of PcGamers4Ever

bastya_elvtars

Sorry, I am dumb. Edited my post above.

BTW is that an archon's face in your avatar? ;)
Everything could have been anything else and it would have just as much meaning.

Herman

Yes it is archon :)
Owner of PcGamers4Ever

bastya_elvtars

QuoteOriginally posted by Herman
Yes it is archon :)

I like Zerg better. Guardian/Defiler combo forever!  :D
Everything could have been anything else and it would have just as much meaning.

Herman

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
Owner of PcGamers4Ever

Dessamator

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.
Ignorance is Bliss.

bastya_elvtars

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. :)
Everything could have been anything else and it would have just as much meaning.

Herman

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
Owner of PcGamers4Ever

Herman

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)
Owner of PcGamers4Ever

[UK]Madman

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.

Herman

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?
Owner of PcGamers4Ever

Herman

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 )
Owner of PcGamers4Ever

Herman

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.
Owner of PcGamers4Ever

Herman

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
Owner of PcGamers4Ever

Herman

#18
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
Owner of PcGamers4Ever

IVANNOFKE

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.
~~???$?m???k?~~House?Hub

insomniakhousehub.no-ip.info

Member of --??RAW INC.??-- network

Live_Life_At_Ur_Max_Next_Day_Can_Be_ur_Last

Herman

#20
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
Owner of PcGamers4Ever

SMF spam blocked by CleanTalk