ArtBot 2.3 Lua 5.1 [API2]
 

ArtBot 2.3 Lua 5.1 [API2]

Started by ATAG, 13 October, 2008, 20:07:14

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

ATAG

Script requires PxLuafilesystem (or liblua5.1-filesystem on linux).
Bugreports are welcomed :)

---Artbot Version 2.3
---made by [NL]MrBuitenhuizen
---used code from ![AscIIArtBot]!? v:1.0 made by [ES]Latinmusic
---added some functions
---added some art
---added cfg file
---thnx Troubadour for the support with the GUI

--Artbot 1.0 made by: [NL]MrBuitenhuizen
--Artbot has most of the scripting lines from > :
-->ShowInfo v1.0 by latinmusic == poweroperator 18/04/2003
-->Based on TrickerBot 2 by ?Ptaczek?
-->Based on a few lines of DirtyBot made by Dirty Finger)
--nov 2003 = start empty rule idea by Plop
--thnx to the people who made the Art txt files

----===Don't change under this line if you don't know what you're doing
---====Settings are done in the ArtbotSettings cfg file inside Artbot-data

--//-- Converted to LUA 5 by Mutor 3/17/05

-- +9/11/05 Changes from 2.0 3/17/05
-- +Bugfix in function Show & ChatArrival
-- +string.find change in starttimer
-- +Added context menu
-- +9/14/05 Changes from  v2.1 (9/11/05)
-- +Corrected poor file handling
-- +Added response for 'file not found'
-- +Added function to show specific file
-- +Changed/updated responses.
-- +4/4/06 Changes from  v2.1 (9/14/05)
-- +Converted to LUA 5.1 by Mutor
---+10/13/08 Changes from  v2.1b
---+Converted to API2 by ATAG
---+Added missing file:close() functions
---+Added luafilesystem modul for better performance

artdir = "Artbot-Art"
Mins = 15    --Default value for autotimer (in minutes)
ErrorMsg = "You do not have enough privileges to execute this command."
scriptInfo = "Artbot V:2.0 LUA v5 by [NL]MrBuitenhuizen"
ArtMenu = "" -- Menu name pulled from hub, uses hub name for menu -> leave it empty for hubname
ArtSubMenu ="Art Bot" -- Custom submenu
TimerStatus = 1	-- start timer on script startup? 1/0

require "pxlfs"

function dir()
	local DirArray = {}
	lfs.chdir(path..artdir)
	for line in lfs.dir(lfs.currentdir()) do
		if lfs.attributes(line, "mode") == "file" then
			table.insert(DirArray,line)
		end
	end
	return DirArray
end

function OnStartup()
	path = Core.GetPtokaXPath().."scripts/"
	ArtMenu = (ArtMenu ~= "") and ArtMenu or SetMan.GetString(0)
	local version = scriptInfo.." "
	botname = botname or SetMan.GetString(21)
	if not lfs.attributes(path..artdir) then
		lfs.mkdir(path..artdir)
	end
	Core.SendToAll("<"..botname.."> Script restarted.\r\n  "..version..os.date(" launched at day: %d/%m/%Y. Local Hub Time: %X."))
	Core.SendToAll("<"..botname.."> The 'Art files list' has been generated.")
	if TimerStatus == 1 then
    	CommandStatus = 0
    	tmr = TmrMan.AddTimer(Mins*60000)
    end
    dirarray = dir()
end

function UserConnected(user, data)
	ArtCommands(user)
	Core.SendToUser(user, "<"..Bot.."> Art Bot 2.1b commands enabled. Right click hub tab or user list for command menu.")
end

OpConnected = UserConnected
RegConnected = UserConnected

function ChatArrival(user, data)
	local s,e,msg = string.find(data, "%b<>%s+(.+)")
	local s,e,cmd = string.find(data, "^%b<>%s+(%p%a+)")
	local s,e,arg = string.find(data, "^%b<>%s+%p%a+%s+(%S+)|")
	if msg and not cmd then
		msg = string.lower(msg)
		for i, fname in ipairs(dirarray) do
			if string.find(msg, fname) then
				Core.SendToAll(data)
				local display = ShowText(fname)
				if display then
					Core.SendToAll(display)
				end
				return true
			end
		end
	elseif cmd and cmd == "!show" and arg then
		if CommandStatus == 1 then
			for i, fname in ipairs(DirArray) do
				if fname == arg then
					local result = Show(arg)
					Core.SendToAll("<"..botname.."> "..result)
					return true
				end
			end
			Core.SendToUser(user, "<"..botname.."> "..arg.." not found.")
			return true
		else
			Core.SendToUser(user, "<"..botname.."> ".."The command '"..cmd.."' is temporarily deactivated. "..
				"Type '!stoptimer' to use "..cmd.." again.")
		end
		return true
	elseif cmd and cmd == "!reloadart" then
		if (user.iProfile ~= 0) then Core.SendToUser(user, "<"..botname.."> "..ErrorMsg) return true end
		dirarray = dir()
		Core.SendToAll("<"..botname.."> The 'Art files list' has been updated.\r\n")
		return true
	elseif cmd and cmd == "!showart" then
		if CommandStatus == 1 then
			local DirArray = dir()
			if next(DirArray) then
				local variable = DirArray[math.random(1,table.getn(DirArray))]
				local result = Show(variable)
				Core.SendToUser(user, "<"..botname.."> "..result)
			else
				Core.SendToUser(user, "<"..botname.."> Artlist is empty, sorry")
			end
		else
			Core.SendToUser(user, "<"..botname.."> ".."The command '"..cmd.."' is temporarily deactivated. "..
				"Type '!stoptimer' to use "..cmd.." again.")
		end
		return true
	elseif cmd == "!showhelp" then
			local HelpMsg = "List of the commands available for "..botname.."\r\n\r\n"..
			"\t-=======<>Artbot Commands<>=======-\r\n"..
			" !startimer <min>\t\t-\t\tStart the timer with time set in minutes\r\n"..
			" !stoptimer\t\t-\t\tStop the timer\r\n"..
			" !showart\t\t\t-\t\tDisplay Art files ramdomly on user request\r\n"..
			" !show <file.ext>\t\t-\t\tDisplay specific file to all.\r\n"..
			" !showhelp\t\t-\t\tDisplay this help\r\n"..
			" !showartlist\t\t-\t\tshow list of art avaible\r\n\r\n"
			Core.SendToUser(user, "<"..botname.."> "..HelpMsg)
			return true
	elseif cmd and cmd == "!starttimer" then
		if not Core.GetUserValue(user, 11) then Core.SendToUser(user, "<"..botname.."> "..ErrorMsg) return true end
		if TimerStatus == 0 then
			local s,e,minutes = string.find( data, "%b<>%s+%S+%s+(%d+)%|$")
			if not s then Core.SendToUser(user, "<"..botname.."> ".."Syntax: !starttimer <TimeInMinutes>") return true end
			TimerStatus = 1
			CommandStatus = 0
			TmrMan.AddTimer(minutes*60000)
			Core.SendToUser(user, "<"..botname.."> ".."The 'Timer' function has been activated. The first 'Art File' will be displayed in "..minutes.." minute(s) from now.")
			Core.SendToAll("<"..botname.."> ".."The Art Timer has been started. The commands '!show' & '!showart' are disabled when timer is active.")
		else
            Core.SendToUser(user, "<"..botname.."> ".."The 'Timer' function is already active.")
		end
		return true
	elseif cmd and cmd == "!stoptimer" then
		if not Core.GetUserValue(user, 11) then Core.SendToUser(user, "<"..botname.."> "..ErrorMsg) return true end
		if TimerStatus == 1 then
			TimerStatus = 0
			CommandStatus = 1
			TmrMan.RemoveTimer(tmr)
			Core.SendToUser(user, "<"..botname.."> ".."The 'Timer' function has been deactivated.")
			Core.SendToAll("<"..botname.."> ".."The Art Timer has been stopped. The commands '!show' & '!showart' are now enabled.")
		else
			Core.SendToUser(user, "<"..botname.."> ".."The 'Timer' function is already deactivated.")
		end
		return true
	elseif cmd and cmd == "!showartlist" then
		OpenFile(user, botname)
		return true
	end
end

function ShowText(TheFile)
	local text, err = Show(TheFile)
	Core.SendToAll("<"..botname.."> ".. text or err)
end

function Show(TheFile)
	local f,e = io.open(path..artdir.."/"..TheFile, "r")
	if f then
		local art = "\r\n\r\n"..f:read("*a").."\r\n"
	    f:close()
		return art
	else
		return nil, "\r\n"..artdir.."/"..TheFile.." was not found.\r\n"
	end
end

function OnTimer(tmr)
	local DirArray = dir()
	if next(DirArray) then
		local variable = DirArray[math.random(#DirArray)]
		local result = Show(variable)
		if result then
			Core.SendToAll("<"..botname.."> "..result)
		end
	end
	dirarray = dir()
end

function OpenFile(user, bot)
	local FileList = "\r\n\--<> List of all the art files that are avaible <"..
    		"> type the name of the file to display <>--\r\n"
	Core.SendToUser(user, "<"..bot.."> "..FileList..table.concat(dir(),"\r\n").."\r\n")
end

function ArtCommands(user)
	--Core.SendToUser(user, "$UserCommand 255 3 "..ArtMenu.."\\"..ArtSubMenu.."|") --clear the menu first
	Core.SendToUser(user,"$UserCommand 1 3 "..ArtMenu.."\\"..ArtSubMenu.."\\Display Random Art $<%[mynick]> !showart&#124;|"..
	"$UserCommand 1 3 "..ArtMenu.."\\"..ArtSubMenu.."\\Display Art File $<%[mynick]> !show %[line:Filename With Extension]&#124;|"..
	"$UserCommand 1 3 "..ArtMenu.."\\"..ArtSubMenu.."\\Reload Art $<%[mynick]> !reloadart&#124;|"..
	"$UserCommand 1 3 "..ArtMenu.."\\"..ArtSubMenu.."\\Start Art Timer $<%[mynick]> !starttimer %[line:Timer Interval In Minutes]&#124;|"..
	"$UserCommand 1 3 "..ArtMenu.."\\"..ArtSubMenu.."\\Stop Art Timer $<%[mynick]> !stoptimer&#124;|"..
	"$UserCommand 1 3 "..ArtMenu.."\\"..ArtSubMenu.."\\List Art Files $<%[mynick]> !showartlist&#124;|"..
	"$UserCommand 1 3 "..ArtMenu.."\\"..ArtSubMenu.."\\Show Art Help $<%[mynick]> !showhelp&#124;|")
end

P_pan


ATAG

Ok, its done. I looked for API2 version in the search box but not found, sorry :(

SMF spam blocked by CleanTalk