RulesBot
 

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

RulesBot

Started by dvxjunkie, 20 October, 2003, 07:15:47

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

dvxjunkie

with this little script the user can mistype the rules command in your hub and still recieve the hub rules.
I recommend entering you own  hub rules in this one :P

rulzbot by dvxjunkie

botname = "Rulezbot"
trigs = {["+rules"]=1,["!rules"]=2,["#rules"]=3}

function Main()
frmHub:RegBot(botname)
end


function DataArrival(Curuser, data)
 
if (( strsub(data, 1, 1) == "<" ) or ( strsub(data, 1, 4) == "$To:" )) then
for key,a in trigs do
if( strfind( strlower(data), strlower(key),1,1) ) then

 
Curuser:SendPM(botname, " Welcome to our hub and Thank you for checking the rules.  share all your personal home movies. give your social security number to ops upon entry and give us your first born child.")

end
end
end
end

 

pHaTTy

good but on the other hand you cud just use

Bot = "Keiko"


function DataArrival(user,data)
if strfind(data, "rules",1,1) then
	readfrom("rules.txt")
	while 1 do 
		line = read() 
		if line == nil then break end 
		user:SendData(Bot,line) 
		end 
	readfrom() 
	end
end

l8rr,,

-phatty
Resistance is futile!

servaks

This one send rules in PM...

botname = "Rulesbot"

function Main() 
frmHub:RegBot(botname) 
end

function DataArrival(user,data)
if strfind(data, "rules",1,1) then
	readfrom("rules.txt")
	while 1 do 
		line = read() 
		if line == nil then break end 
		user:SendPM(botname,line) 
		end 
	readfrom() 
	end
end

/shipis
My hub is back! (yeeeeeey)

hub.servaks.com


pHaTTy

lol no difference all done is changed the user:SendData to user:SendPM lol

might as well have just stated the line ;)

l8rr,,

-phatty
Resistance is futile!

servaks

Yep...
But he is a NOOB, he maby dont know LUA  :D

/shipis
My hub is back! (yeeeeeey)

hub.servaks.com


servaks

#5
botname = "Rulesbot"
file = "rules.txt"
trigger = "rules"

function Main() 
frmHub:RegBot(botname) 
end

function DataArrival(user,data)
if strfind(data, trigger,1,1) then
	readfrom(file)
	while 1 do 
		line = read() 
		if line == nil then break end 
		user:SendPM(botname,line) 
		end 
	readfrom() 
	end
end
My hub is back! (yeeeeeey)

hub.servaks.com


Skrollster

#6
i have to say

1.
if strfind(data, "rules",1,1) then

can make life hard to regulars in the hub

if they say any thing with rules in it they will get the rules.

2.

why do you use 'while' here??

if you use while you need to use 'break' as well

suggestion:

sBotName = "Rulesbot"
sRulesFileName = "rules.txt"

function Main() 
	frmHub:RegBot(sBotName) 
end

function DataArrival(user,data)
	-- remove end pipe
	data=strsub(data,1,strlen(data)-1)
	--extract command
	_,_,cmd=strfind(data, "%b<>%s+(%S+)")
	--check if cmd exist
	if not cmd then cmd = "0" end
	-- make the cmd caseinsensitive
	cmd = strlower(cmd)

	if cmd = "!rules" then
		readfrom(sRulesFileName)
		local sLine = read() 
		local sFileContent = ""
		if sLine then 
			sFileContent = sLine
			while 1 do 
				sLine = read() 
				if not sLine then 
					break
				else
				sFileContent = sFileContent..sLine.."\r\n"
				end
			end
			readfrom()	-- close filehandle
			user:SendPM(sBotName,sFileContent) 
			return 1
		else
			user:SendPM(sBotName,"Nothing in \"rules.txt\" or no \"rules.txt\"")
			return 1
		end 
		readfrom() 
	end
end

*edit*
there might also be an idea to check if it realy is a chat message first before doing any thing else

servaks

My hub is back! (yeeeeeey)

hub.servaks.com


Skrollster

ok an even better solution would be this:

sBotName = "Rulesbot"
sRulesFileName = "rules.txt"

function Main() 
	frmHub:RegBot(sBotName) 
end

function DataArrival(user,data)
	if (strsub(data, 1, 1) == "<" ) then 
		-- remove end pipe
		data=strsub(data,1,strlen(data)-1)
		--extract command
		_,_,cmd=strfind(data, "%b<>%s+(%S+)")
		--check if cmd exist
		if not cmd then cmd = "0" end
		-- make the cmd caseinsensitive
		cmd = strlower(cmd)

		if cmd = "!rules" then
			fFileHandle, sError = readfrom(sRulesFileName)
			local sLine = read() 
			local sFileContent = ""
			if sLine then 
				sFileContent = sLine
				while 1 do 
					sLine = read() 
					if not sLine then 
						break
					else
					sFileContent = sFileContent..sLine.."\r\n"
					end
				end
				readfrom()	-- close filehandle
				user:SendPM(sBotName,sFileContent) 
				return 1
			elseif fFileHandle
				user:SendPM(sBotName,"Nothing found in "..sRulesFileName)
				return 1
			else
				user:SendPM(sBotName,"Error "..sError)
			end 
			readfrom() 
		end
	end
end

MrZ

Hia :))

Nice script and nice to have ya back too Skrollster :))

Any shance we have nback the nice trad about Glory ??

Z ya
Always remember that you are unique... just like everyone else :-D

Skrollster

glory isn't any priority right now, at least not for me..

but i can start a new thread and release a beta of 1.9 i want to implement a few other things before the final 1.9 release, but if ppl want bug fixes for 1.8.3 then it can be aranged

c h i l l a

why not use this instead of read from line.

local handle = openfile(sRulesFileName, "r")
if handle then
	local contents = gsub(read(handle, "*a"), strchar(10), "\r\n")
	closefile (handle)
	user:SendPM(sBotName,contents)
end

Skrollster

because i didn't remember the exact syntax for read all
read("*a")...

pHaTTy

rules, if you read back up we were talkinfg about if they mistype rules ;)
Resistance is futile!

servaks

nice scripts :)
/shipis
My hub is back! (yeeeeeey)

hub.servaks.com


pHaTTy

yep yep still nice script skrollker :o)
Resistance is futile!

Skrollster

QuoteOriginally posted by (uk-kingdom)pH?tt?
rules, if you read back up we were talkinfg about if they mistype rules ;)

sorry missed that part, here you go:

sBotName = "Rulesbot"
sRulesFileName = "rules.txt"

function Main() 
	frmHub:RegBot(sBotName) 
end

function DataArrival(user,data)
	if (strsub(data, 1, 1) == "<" ) then 
		-- remove end pipe
		data=strsub(data,1,strlen(data)-1)
		--extract command
		_,_,cmd=strfind(data, "%b<>%s+(%S+)")
		--check if cmd exist
		if not cmd then cmd = "0" end
		-- make the cmd caseinsensitive
		cmd = strlower(cmd)
		-- get the command prefix
		cmdprefix = strsub(cmd, 1,1)
		-- check if the cmd prefix is !,+,# or ?
		if cmdprefix == "!" or cmdprefix == "+" or cmdprefix == "#" or cmdprefix == "?" then
			-- Remove the prefix and check the command
			cmd = strsub(cmd, 2,strlen(cmd))
			if cmd = "rules" then
				fFileHandle, sError = readfrom(sRulesFileName)
				local sLine = read() 
				local sFileContent = ""
				if sLine then 
					sFileContent = sLine
					while 1 do 
						sLine = read() 
						if not sLine then 
							break
						else
							sFileContent = sFileContent..sLine.."\r\n"
						end
					end
					readfrom()	-- close filehandle
					user:SendPM(sBotName,sFileContent) 
					return 1
				elseif fFileHandle
					user:SendPM(sBotName,"Nothing found in "..sRulesFileName)
					return 1
				else
					user:SendPM(sBotName,"Error "..sError)
				end 
				readfrom() 
			end
		end
	end
end

i haven't tested it and not 100% sure about the strlen()
but i think it should work

pHaTTy

hehehe thats great ;)
Resistance is futile!

Mulciber

#18
forgive the n00b, I just started to get in to this scripting tonight. Is there any way to insert this script (barrowed from servaks) in to Channel_Bot 4.3? I changed it a little to suit my needs, which is a configureable help file.

trigger = "?help"
helper = "helper.txt"

function HelpRequest(user,data)
if strfind(data, trigger,1,1) then
	readfrom(helper)
	while 1 do 
		line = read() 
		if line == nil then break end 
		user:SendPM(botname,line) 
		end 
	readfrom() 
	end
end

dvxjunkie

#19
Nice goin skrollster I've been away but as I read thru the thread i was waiting for somone to notice that part about the mistyping thing. (prefix) I like the additional common prefix's you added too as well as the case insensitivity thing :)
  I was wondering though, why the change? is there  an efficiency issue the way i had it or possibly a memory waste I had going on there? Frankly I was already wondering if it might be more resouce intensive than it needed to be but I'm only so far in my lua journey.. :P

 

Snooze

When checking syntax on the script by Skrollster im getting this error

Syntax Error: `then' expected;
  last token read: `=' at line 24 in string "sBotName = "Rulesbot"
..."

No what am i doing wrong

Please advice..

/Snooze

SMF spam blocked by CleanTalk