Release Bot - Page 2
 

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

Release Bot

Started by witch, 10 August, 2004, 00:51:26

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Herodes

#25
yep ... try using instead of the last (%S+) --- that says all non space characters ...
(.*) --- that says all characters ...
this is in plop's pattern matching tutorial ;)

imby

only catches the artist rather*

and thanks, hehe did have a look through it. is gonna take multiple reads. as you can see, am not that advanced, that first line of code i wrote took me like an hr to do. but i did write it all by myself. :) and btw, am using Ptokax 0330 15.25. gonna have a look at trying what you said and understanding more later.

imby

Finished:

-- Verry simple release script nothing fancy
-- Make a file called releases.txt in \Scripts Folder
-- Made By Optimus

sBot = "=ReleaseBot="

timedate = date()
file = "releases.txt"

display1 = "Item"
display2 = "Description"
display3 = "Releases"

function Main()
	frmHub:RegBot(sBot)
end

function DataArrival(user, data)
	if (strsub(data, 1, 1) == "<" ) then
		data=strsub(data,1,strlen(data)-1) 
			_,_,cmd=strfind(data, "%b<>%s+(%S+)")

		if (cmd=="!read") then
	SendToAll("<"..user.sName.."> !read")
	ReadRelease(user, data, cmd)
	return 1



		elseif (cmd=="!write") then
						s,e,cmd,release = strfind( data, "%b<>%s+(%S+)%s+(.*)" )
						SendToAll( data )
				
				
				end
				if release == nil then
					user:SendData(sBot, "*** No "..display1.." specified!")
					return 1
				end

				News("By: "..user.sName.."\t Date: "..timedate.."   "..display1..": "..release.." ")
				SendToAll(sBot, "New "..display3.." Added....By <"..user.sName.."> Type !read in Main-Chat to show "..display1..".")
				return 1
					
		
		end
	end


function ReadRelease(user, data, cmd)
	local release = ""
	readfrom(file)
	while 1 do
	local line = read()
	if (line == nil) then 
	break
	else
	release = release.."	"..line.."\r\n"
	end
	end
	user:SendPM(sBot, "\r\n\r\n".."       "..display3.." posted by users: ".."\r\n\r\n"..release)
	readfrom()
end

function News(what)
	appendto(file) 
		write(what.."\n")
	writeto() 
end

works exactly how i want it. anyway to optimise it or clean it up a bit? i'm sure i've done it messy.

if (cmd=="!read") then
	-- SendToAll("<"..user.sName.."> !read")
	ReadRelease(user, data, cmd)
	-- return 1
end

didn't work at all, must of done soemthing wrong. nor can i work out why you'd comment out the bits you need anyway? i think it was just a thing for TD4

imby

never mind it messed up. worked the first few times, then when a user just typed out letters with no commands in main chat it said:

"[17:51] <=ReleaseBot=> New Releases Added....By Type !read in Main-Chat to show Item."

for everything

how can i fix this?

Herodes

Watch how the if-then>elseif-then>else-end sequence is going ... and what it is doing ...
... I think you really need to understand this so I will not post the corrections .. ;) trial and error ... not only it reveals how it should be but also how it works .. :D

Typhoon

well, i bet your are learning a lot from Herodes, but i coulden't help my self so i post this so you can compare your postet version to this one....

sometimes its easyer to see the bugs like that ..

Only made a short test and it worked..

-- Verry simple release script nothing fancy
-- Make a file called releases.txt in \Scripts Folder
-- Made By Optimus

sBot = "=ReleaseBot="

timedate = date()
file = "releases.txt"

display1 = "Item"
display2 = "Description"
display3 = "Releases"

function Main()
	frmHub:RegBot(sBot)
end

function DataArrival(user, data)
      if (strsub(data, 1, 1) == "<" ) then
         local data=strsub(data,1,strlen(data)-1) 
         local s,e,cmd=strfind(data, "%b<>%s+(%S+)")
         if (cmd=="!read") then
            ReadRelease(user, data, cmd)
            return 1
         elseif (cmd=="!write") then
            local s,e,cmd,release = strfind( data, "%b<>%s+(%S+)%s+(.*)" )
               if release == nil then
                  user:SendData(sBot, "*** No "..display1.." specified!")
                  user:SendData(sBot, "*** Use "..display1.." - "..display2.." to specify your release! ")
               else
                  News("By: "..user.sName.."\t Date: "..timedate.."   "..display1..": "..release.." ")
                  SendToAll(sBot, "New "..display3.." Added....By <"..user.sName.."> Type !read in Main-Chat to show "..display1..".")
                  return 1
               end
         end
      end
end

function ReadRelease(user, data, cmd)
	local release = ""
	readfrom(file)
	while 1 do
      local line = read()
      if (line == nil) then 
         break
      else
         release = release.."	"..line.."\r\n"
      end
	end
      user:SendPM(sBot, "\r\n\r\n".."       "..display3.." posted by users: ".."\r\n\r\n"..release)
      readfrom()
end

function News(what)
	appendto(file) 
		write(what.."\n")
	writeto() 
end

*** Typhoon?



Herodes

grrr typ ... lol

Lets hope he/she can see the mistake by comparing it at least ... ;)

imby

thanks, i played a game of spot the difference and saw it, :) will take a few more reads to understand it all. thanks for all your help Typhoon?, nErBoS and especially Herodes, this script was for a friend. Herodes it doesn't matter if i do understand that one part or not, my level is still very basic. would say i only understand 20% of it all. so it's not like i can do much myself. i've not read any guides, just picked this little understanding up through looking through scripts. i guess i need some beginners guide or something, but as i said the one on the lua site is written for programmers.

Typhoon? -  i just pasted the sendtoall lines from my script into yours, that's ok right? don't need to add anything else to them? wanted them there. it seems to work now.

Typhoon

sorry , des ..

and your welcome imby , But ...

why have the SendToAll()  ?? , if you want users to see the commands just remove  return 1 ... then it will show in main chat

*** Typhoon?



imby

thanks, tried that and above we commented it out, which is the equivalent but didn't seem to work. think it works on testdrive but not on 0330 but not sure.

Herodes

QuoteOriginally posted by imby
thanks, tried that and above we commented it out, which is the equivalent but didn't seem to work. think it works on testdrive but not on 0330 but not sure.
Yep chat msgs starting with the prefix in 033 are not send to the main ... td4 should do it with the ' return 1 '

SMF spam blocked by CleanTalk