greet bot help
 

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

greet bot help

Started by Leun, 07 October, 2005, 09:11:20

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Leun

Hi,

I would try make a own script that can greet.
This is the first version:

-- Simple Greet BOT
-- Made: 25-9-2005
-- Version: 1.0

bot = "[BOT]Nieuwslezer"
prefix = "+"
PM = 1 -- Send message also by PM or only MAIN chat? 1 = on, 0 = off. 

cmd1 = "morning"
cmd2 = "reboot"
function Main()
frmHub:RegBot(bot)

end



function ChatArrival(user, data)  
	data = string.sub(data,1,string.len(data)-1) 
	s,e,cmd = string.find(data,"%b<>%s+(%S+)") 
	if cmd and cmd == (prefix..cmd1) then 
		SendToAll(bot,""..user.sName.." wishes everyone a good morning") 
		return 1	 
	elseif
		cmd and cmd == (prefix..cmd2) then
		SendToAll(bot,"\r\n\r\n'The hub wil close in some minutes,\t it will be online a few minutes later'\r\n")
			if PM == "1" then 
			SendPmToAll(bot,"\r\n\r\n'The hub wil close in some minutes,\t it will be online a few minutes later'\r\n")
			end
		return 1	
	end

end

But if I add more options there will be a lot of "elseif"
So I want make this in a table.

this is the result :

-- Simple Greet BOT
-- Made: 5-10-2005
-- version: 1.1
--
-- 
--
-- Commands:
-- !morning            		- Wish people a good morning
--
-- VARIABLES --
sBot = "[BOT]Nieuwslezer"	-- name of the bot.
sPrefix = "!";			-- Command Prefix
--
--    END    --



function Main()
	frmHub:RegBot(sBot);
end

function ChatArrival(curUser, data)  
	local data = string.sub(data,-1) 
	local s,e,cmd = string.find(data,"%b<>%s+(%S+)") 
	if cmd then 
		local tCmds = { 

["morning"] = function(user,data)
		
	local s,e,arg = string.find(data,"%b<>%s+(%S+)") 
	if not arg then		
    		SendToAll(sbot,""..user.sName.." wishes everyone a good morning")                                                                                          
    		return 1
	end
end, 
		} 
		if tCmds[cmd] then 
			return tCmds[cmd](curUser, data) 
		end 
	end 
end

But it won't work......

Can anybody say whate I do wrong??

6Marilyn6Manson6

In you script I read

sPrefix = "!";			-- Command Prefix

but you not use it in you ChatArrival function. Why?

Typhoon

here's a nice and small standard template, easy to build on..
added option for multi prefix also

Typhoon?

-- Simple Greet BOT
-- Made: 5-10-2005
-- version: 1.1
-- Quickie template by Typhoon?  , easy to add commands this way and still keep a very readable script
-- Commands:
-- !showip		-- shows the victims ip

-- VARIABLES --
tSetup = {
sBot = "[BOT]Nieuwslezer",	-- name of the bot.
sPrefix = {
		["-"] = 1,
		["+"] = 1,
		["/"] = 1,
		["!"] = 1,
	},
}
--    END    --

-- globale table for commands
local tCmds = {}

function Main()
	frmHub:RegBot(tSetup.sBot)
end



function ChatArrival(user,data)  
	local _,_,Arg = string.find(data, "%b<>%s+(.*)%|")
	local _,_,prefix,cmd,arg = string.find(Arg, "(%S)(%S+)%s*(.*)")
	if prefix and cmd and tSetup.sPrefix[prefix] then
		if tCmds[string.lower(cmd)] then
			return tCmds[string.lower(cmd)](user,arg,data) 
		else
			user:SendData(tSetup.sBot, "*** Command don't exist!")
			return 1
		end
	end 
end 

-- commands table
tCmds["showip"] = function(user,Arg,data)
	local s,e,Name = string.find(Arg, "(.+)" )
	local victim = GetItemByName(Name)
   if victim ~= nil then
		user:SendData(tSetup.sBot, "The user "..victim.sName.." has the IP: "..victim.sIP)
   else
      user:SendData(tSetup.sBot,"*** No such nick in the userlist !! ***")
   end
   return 1
end



6Marilyn6Manson6

Very good Typ very nice script :)

Leun

Thnx a lot !!! you all :D

This is what i need !!!!

SMF spam blocked by CleanTalk