Joker by OpiumVolage
 

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

Joker by OpiumVolage

Started by pHaTTy, 17 October, 2003, 14:53:58

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

pHaTTy

just found this on my hdd :)


-- Joker by OpiumVolage (15 Juillet 2003)
-- done on request for a french forum.
-- the file must exist before starting the script(var fGommette)

botName  = "Joker"
fGommette = "Joker.txt"

function tokenize(inString,token)
	local _WORDS = {}
	local matcher = "([^"..token.."]+)"
	gsub(inString, matcher, function (w) tinsert(%_WORDS,w) end)
	return _WORDS
end

function FileToTable(f)
	handle = openfile(f,"r")
	assert(handle, "ReadFile("..f.."): file not found.")
	local tabRes = {}
	local table = tokenize(read(handle,"*a"),"\n")
	for id, value in table do
		local s, e, First, Last = strfind(value, "(.*)|(.*|.*)")
		if s then
			if not tabRes[First] then tabRes[First] = {} end
			tinsert(tabRes[First], Last)
		end
	end
	return tabRes
end

function Main()
	frmHub:RegBot(botName)
	tabGommette = FileToTable(fGommette)
end 

function DataArrival(user, data)
	local s,e,cmd = strfind(data,"^%b<>%s+(%S+).*|")
	if s and (cmd=="+sendjoke") then
		gommette(user, data) return 1
	elseif s and (cmd=="+listjoke") then
		listgommette(user,data) return 1
	elseif s and (cmd=="-joke") then
		effgommette(user,data) return 1
	end
end

function gommette(user,data)
	local s, e, WhoTo, Gom = strfind(data, "%b<>%s+%S+%s+(%S+)%s+(.*)|" )
	if s then
		WhoTo = strlower(WhoTo)
		if not GetItemByName(WhoTo) and not tabGommette[WhoTo] and not user.bOperator then
			user:SendData("<"..botName.."> user "..WhoTo.." isn't connected actually, and unknown by this bot, try again later.|")
		return end
		if strfind(Gom, "%c") then
			user:SendData("<"..botName.."> tab and carriage return are unsupported.|")
		return end
		if (strlen(Gom) > 3) then
			Gommette = user.sName.."|"..Gom
			if not tabGommette[WhoTo] then tabGommette[WhoTo] = {n=0} end
			tinsert(tabGommette[WhoTo], Gommette)
			local handle=openfile(fGommette,"a")
			Gommette = WhoTo.."|"..Gommette.."\n"
			write(handle, Gommette)
			SendToAll("<"..botName.."> "..WhoTo.." got a new joke in list.|")
			closefile(handle)
		else
			user:SendData("<"..botName.."> 4 chars must be a minimum for me.|")
			return
		end
	else
		user:SendData("<"..botName.."> Syntax: +sendjoke  text of the joke.|")
		return
	end
end

function listgommette(user,data)
	local _, _, who = strfind(data, "%b<>%s+%S+%s+(%S+).*|")
	if not who then who = user.sName end
	who = strlower(who)
	if not tabGommette[who] then
		user:SendData("<"..botName.."> No joke in "..who.." list.|")
		return
	end
	tmp = "Here are the jokes recorded for "..who.."\r\n\r\n"
	tmp = tmp.."From\t\tJoke\r\n"
	for id, value in tabGommette[who] do
		local _, _, By, Gom = strfind(value,"(.*)|(.*)")
		if By then tmp = tmp..By.."\t"..Gom.."\r\n" end
	end
	user:SendPM(botName, tmp)
end

function effgommette(user,data)
	local _, _, who = strfind(data, "%b<>%s+%S+%s+(%S+).*|")
	if who and user.bOperator then delete=who else delete=user.sName end
	delete = strlower(delete)
	if not tabGommette[delete] then
		user:SendData("<"..botName.."> Nothing to delete for "..delete.."|")
	return end
	user:SendData("<"..botName.."> Deleting jokes sent to "..delete.."|")
	local handle=openfile(fGommette,"w+")
	for key, value in tabGommette do
		if not (key == delete) then
			for i=1, getn(value) do
				Gommette = key.."|"..value[i]
				write(handle, Gommette.."\n")
			end
		end
	end
	closefile(handle)
	tabGommette = FileToTable(fGommette)
end


l8rr,,

-phatty
Resistance is futile!

?Tr??T_????

i get this
 [12:44] Syntax ...ings\Administrator\My Documents\Azim (Business)\Ptokax\scripts\joker.lua:21: unexpected symbol near `%'

[12:45] Syntax [string "-- Joker by OpiumVolage (15 Juillet 2003)
..."]:21: unexpected symbol near `%'

TiMeTrAVelleR

Its in lua 4 you need lua 5 for youre hub

greetzzz TT

TiMeTrAVelleR

-- Joker by OpiumVolage (15 Juillet 2003)
-- done on request for a french forum.
-- the file must exist before starting the script(var fGommette)

botName  = "Joker"
fGommette = "Joker.txt"

function tokenize(inString,token)
	local _WORDS = {}
	local matcher = "([^"..token.."]+)"
	string.gsub(inString, matcher, function (w) table.insert(WORDS,w) end)
	return _WORDS
end

function FileToTable(f)
	handle = io.open(f,"r")
	assert(handle, "ReadFile("..f.."): file not found.")
	local tabRes = {}

	for id, value in table do
		local s, e, First, Last = string.find(value, "(.*)|(.*|.*)")
		if s then
			if not tabRes[First] then tabRes[First] = {} end
			table.insert(tabRes[First], Last)
		end
	end
	return tabRes
end

function Main()
	frmHub:RegBot(botName)
	tabGommette = FileToTable(fGommette)
end 

function ChatArrival(user, data)
	local s,e,cmd = string.find(data,"^%b<>%s+(%S+).*|")
	if s and (cmd=="+sendjoke") then
		gommette(user, data) return 1
	elseif s and (cmd=="+listjoke") then
		listgommette(user,data) return 1
	elseif s and (cmd=="-joke") then
		effgommette(user,data) return 1
	end
end

function gommette(user,data)
	local s, e, WhoTo, Gom = string.find(data, "%b<>%s+%S+%s+(%S+)%s+(.*)|" )
	if s then
		WhoTo = string.lower(WhoTo)
		if not GetItemByName(WhoTo) and not tabGommette[WhoTo] and not user.bOperator then
			user:SendData("<"..botName.."> user "..WhoTo.." isn't connected actually, and unknown by this bot, try again later.|")
		return end
		if string.find(Gom, "%c") then
			user:SendData("<"..botName.."> tab and carriage return are unsupported.|")
		return end
		if (string.len(Gom) > 3) then
			Gommette = user.sName.."|"..Gom
			if not tabGommette[WhoTo] then tabGommette[WhoTo] = {n=0} end
			table.insert(tabGommette[WhoTo], Gommette)
			local handle=io.open(fGommette,"a")
			Gommette = WhoTo.."|"..Gommette.."\n"
			write(handle, Gommette)
			SendToAll("<"..botName.."> "..WhoTo.." got a new joke in list.|")
			io.close(handle)
		else
			user:SendData("<"..botName.."> 4 chars must be a minimum for me.|")
			return
		end
	else
		user:SendData("<"..botName.."> Syntax: +sendjoke  text of the joke.|")
		return
	end
end

function listgommette(user,data)
	local _, _, who = string.find(data, "%b<>%s+%S+%s+(%S+).*|")
	if not who then who = user.sName end
	who = string.lower(who)
	if not tabGommette[who] then
		user:SendData("<"..botName.."> No joke in "..who.." list.|")
		return
	end
	tmp = "Here are the jokes recorded for "..who.."\r\n\r\n"
	tmp = tmp.."From\t\tJoke\r\n"
	for id, value in tabGommette[who] do
		local _, _, By, Gom = string.find(value,"(.*)|(.*)")
		if By then tmp = tmp..By.."\t"..Gom.."\r\n" end
	end
	user:SendPM(botName, tmp)
end

function effgommette(user,data)
	local _, _, who = string.find(data, "%b<>%s+%S+%s+(%S+).*|")
	if who and user.bOperator then delete=who else delete=user.sName end
	delete = string.lower(delete)
	if not tabGommette[delete] then
		user:SendData("<"..botName.."> Nothing to delete for "..delete.."|")
	return end
	user:SendData("<"..botName.."> Deleting jokes sent to "..delete.."|")
	local handle=io.open(fGommette,"w+")
	for key, value in tabGommette do
		if not (key == delete) then
			for i=1, table.getn(value) do
				Gommette = key.."|"..value[i]
				write(handle, Gommette.."\n")
			end
		end
	end
	io.close(handle)
	tabGommette = FileToTable(fGommette)
end

not tested dont have the txt file whit jokes on it


greetz  TT

?Tr??T_????


SMF spam blocked by CleanTalk