Chatrooms v3 (tezlo) LUA 5
 

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

Chatrooms v3 (tezlo) LUA 5

Started by jiten, 02 March, 2005, 19:58:55

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

jiten

Chatrooms v4c

Lua 5 version by jiten and Dessamator
Based on: Chatrooms v3 by tezlo

Changelog:


  • Changed: Profile permissions (requested by GeceBekcisi);
  • Rewritten: Significant code and loops; code is more presentable;
  • Added: Status for each chatroom;
  • Changed: MyINFO handling to avoid flooding;
  • Changed: Other small mods.

Grab it HERE.

dragos_sto

why when i reboot my server the statistic it lost .. :((

jiten

QuoteOriginally posted by dragos_sto
why when i reboot my server the statistic it lost .. :((

Are u sure u're talking about this script?
Maybe it's this  one.

Cheers

dragos_sto

i run PtokaX 0.3.3.0 build 16.09 server on windows xp whit sp2
and yes, i copy the script from here ,(little above whit 3 post)

jiten

QuoteOriginally posted by dragos_sto
why when i reboot my server the statistic it lost .. :((

What do u mean by statistic?
Can u explain it better?

dragos_sto

#5
mean the Top Chatters will be reset (the save data in chatstats.tbl whill be lost) when i reboot the server or the scripts

jiten

Guess that u posted in the wrong thread  :D
This one a chatroom based script.
That's why I asked u if it wasn't this one.

jiten

#7
Anyway, here it goes:

-- ChatStats v3 Made By Optimus
-- Based on Tezlo chats
-- Added Send Commands By TiMeTrAVelleR
-- Madman fixed some in commands
-- Converted to lua5 by Madman with very little help by Jelf
-- with some help by ?
-- fixed stats saving on exit by jiten

sBot = "Chatstats"		-- Name of Bot
SendComm = 1 			-- Send UserCommands 1 = On  0 = Off
pMenu = "-=( ChatStats )=-" 	-- Name of Menu

Chatstats = {}

Sortstats = 2	-- 1=words / 2=posts

ChatStatsFile = "chatstats.tbl"

EnableChatStats = {
	[0] = 1, -- Master
	[1] = 1, -- Operators
	[2] = 1, -- Vips
	[3] = 1, -- Regs
	[4] = 1, -- Moderators
	[5] = 1, -- NetFounders
	[-1] = 1, -- Users (UnRegged)
}

AllowedProfiles = { 
[0] = 1,   -- Masters
[1] = 0,   -- Operators
[4] = 0,   -- Moderator
[5] = 0,   -- NetFounder
}

function Main()
	frmHub:RegBot(sBot)
	dofile(ChatStatsFile)
end

function NewUserConnected(user)
	if SendComm == 1 and EnableChatStats[user.iProfile] == 1 then
		if Chatstats[user.sName] then
			user:SendData(sBot, "---===[ Your Chat Stats:  You Made "..Chatstats[user.sName]["post"].." Posts In Main Used "..Chatstats[user.sName]["chars"].."  Characters, And "..Chatstats[user.sName]["words"].." Words ]===---")
		end
		user:SendData("$UserCommand 1 3 "..pMenu.."\\TopChatters$<%[mynick]> !topchatters||")
		user:SendData("$UserCommand 1 3 "..pMenu.."\\My Chat Stat$<%[mynick]> !mychatstat||")
		if AllowedProfiles[user.iProfile] == 1 then
			user:SendData("$UserCommand 1 3 "..pMenu.."\\Del Chatter$<%[mynick]> !delchatter %[line:Nick]||")
			user:SendData("$UserCommand 1 3 "..pMenu.."\\Clear Chat Stats$<%[mynick]> !clearchatstats||")
		end
	end
end

OpConnected = NewUserConnected

function OnExit()
	if isEmpty(Chatstats) then
	else
		saveTableToFile(ChatStatsFile, Chatstats, "Chatstats")
	end
end

function ChatArrival(user, data)
	if (string.sub(data, 1, 1) == "<" ) then
		if EnableChatStats[user.iProfile] == 1 then
			local s,e,str = string.find(data, "^%b<> (.*)%|$")
			updStats(user.sName, str)
		end
		data=string.sub(data,1,string.len(data)-1) 
		s,e,cmd=string.find(data, "%b<>%s+(%S+)")
		if (cmd == "!mychatstat") then
			if Chatstats[user.sName] then
				user:SendData(sBot, "---===[ Your Chat Stats:  You Made "..Chatstats[user.sName]["post"].." Posts In Main Used "..Chatstats[user.sName]["chars"].."  Characters, And "..Chatstats[user.sName]["words"].." Words ]===---")
				return 1
			else
				user:SendData(sBot, "*** No chat statics found!") 
				return 1
			end
		elseif (cmd=="!topchatters") then
			TCopy={}
			if Chatstats then
				for i,v in Chatstats do
					table.insert(TCopy,{i,v.post,v.chars,v.words})
				end
				table.sort(TCopy,function(a,b) return (a[Sortstats] > b[Sortstats]) end)
				local chat = "Current Top Chatters:\r\n\r\n"
				chat = chat.."\t ------------------------------------------------------------------------\r\n"
				chat = chat.."\t Nr.\tPosts:\tChars:\tWords:\tName:\r\n"
				chat = chat.."\t ------------------------------------------------------------------------\r\n"
				for i = 1,25 do 
					if TCopy[i] then
--											Nr:			Posts:				Chars:				Words:				Name:
						chat = chat.."\t "..i..".\t "..TCopy[i][2].."\t "..TCopy[i][3].."\t "..TCopy[i][4].."\t"..TCopy[i][1].."\r\n"
					end
				end
				user:SendData(sBot, chat)
				TCopy={}
			end
			return 1
		elseif (cmd == "!delchatter") and AllowedProfiles[user.iProfile] == 1 then
			local s,e,cmd,name = string.find( data, "%b<>%s+(%S+)%s+(%S+)" )
			if name then
				if Chatstats[name] then
					Chatstats[name] = nil
					user:SendData(sBot, "Chatstats from user "..name.." are now removed!")
					saveTableToFile(ChatStatsFile, Chatstats, "Chatstats")
				else
					user:SendData(sBot, "*** Chatstats from user "..name.." not found!")
				end
			else
				user:SendData(sBot, "*** Usage: !delchatter ")
			end
			return 1
		elseif (cmd == "!clearchatstats") and AllowedProfiles[user.iProfile] == 1 then
			Chatstats = {}
			saveTableToFile(ChatStatsFile, Chatstats, "Chatstats")
			user:SendData(sBot, "Chatstats are cleared by "..user.sName)
			return 1
		end
	end
end

function updStats(nick, str)
	local tmp = Chatstats[nick] or {["post"]=0, ["chars"]=0, ["words"]=0, ["time"]=os.date("%x")}
	tmp["post"], tmp["chars"], tmp["words"], tmp["time"] = tmp["post"]+1, tmp["chars"]+string.len(str), tmp["words"]+cntargs(str,"(%a+)"), os.date("%x")
	Chatstats[nick] = tmp
--	saveTableToFile(ChatStatsFile, Chatstats, "Chatstats")
end

function cntargs(str, rule)
	local s,n = string.gsub(str, rule, "")
	return n
end

----------------------------------------------
-- load & save Tables
----------------------------------------------
function Serialize(tTable, sTableName, sTab)
        assert(tTable, "tTable equals nil");
        assert(sTableName, "sTableName equals nil");

        assert(type(tTable) == "table", "tTable must be a table!");
        assert(type(sTableName) == "string", "sTableName must be a string!");

        sTab = sTab or "";
        sTmp = ""

        sTmp = sTmp..sTab..sTableName.." = {\n"

        for key, value in tTable do
                local sKey = (type(key) == "string") and string.format("[%q]",key) or string.format("[%d]",key);

                if(type(value) == "table") then
                        sTmp = sTmp..Serialize(value, sKey, sTab.."\t");
                else
                        local sValue = (type(value) == "string") and string.format("%q",value) or tostring(value);
                        sTmp = sTmp..sTab.."\t"..sKey.." = "..sValue
                end

                sTmp = sTmp..",\n"
        end

        sTmp = sTmp..sTab.."}"
        return sTmp
end

-----------------------------------------------------------
function saveTableToFile(file, table, tablename)
	local handle = io.open(file,"w+")
	handle:write(Serialize(table, tablename))
	handle:flush()
	handle:close()
end
-----------------------------------------------------------
function loadTableFromFile(file)
	local handle = io.open(file,"r")
	if (handle ~= nil) then
		loadstring(handle:read("*all"))
		handle:flush()
		handle:close()
	end
end

-------------table checker by herodes
--- for an associative table, like ["smth"] = "smth else",
function isEmpty(t)
	for i,v in t do
		return false;
	end
	return true;
end;


Cheers

dragos_sto

ahammm .. i dont read the whole post , now i  understand why ... sorry for my insensitiveness ... :D

and sorry for my english .. i will try my best english to romanian

jiten

QuoteOriginally posted by dragos_sto
ahammm .. i dont read the whole post , now i  understand why ... sorry for my insensitiveness ... :D

and sorry for my english .. i will try my best english to romanian

No problem m8. You're welcome  :]

kunal

[16:16] Syntax logs/chatrooms.dat:2: unexpected symbol near `'
get this error
pls help someone

jiten

QuoteOriginally posted by kunal
[16:16] Syntax logs/chatrooms.dat:2: unexpected symbol near `'
get this error
pls help someone
1. Copy the last script I posted and replace it with the one you got;
2. Go to your /logs folder and delete that "chatrooms.dat" file;
3. Restart your scripts.

That error should be gone then.

Cheers

kash?

Can u make commands editable please
also can rooms be shown below all the users
with prefiix "zz" [so that it will be shown below all
the users] instead above near op

Regards

jiten

QuoteOriginally posted by kash?
Can u make commands editable please
Sure ;)
Quotealso can rooms be shown below all the users
with prefiix "zz" [so that it will be shown below all
the users] instead above near op
I'm going to think about this. Btw, why do you want to "hide" the bot?

Cheers

kunal

thanx m8.the script worked fine.can u pls remove the key coming besides the chatrooms and add right click cmds for the script

jiten

Last script updated with all requests.

Best regards

kash?

#16
thx jiten
gr8 work !!!
Can u add help command to show
commands available for users
and all users should be able to
create chat room instead of only ops

jiten

QuoteOriginally posted by kash?
Can u add help command to show
commands available for users
and all users should be able to
create chat room instead of only ops
Well, I guess that there's no need to create a command just to show all available commands to users, as there's the rightclick.

Btw, for all users to be able to create a chatroom, delete the red selection in this code:
ChatArrival = function(user, data)
	local s, e, cmd, args = string.find(data, "^%b<> %!(%a+)%s*(.*)|$")
	if cmd == tCmds.MakeChat [COLOR=red]and user.bOperator[/COLOR] then
		local s, e, name, profiles = string.find(args, "(%S+)%s*(.*)")
		if not s then
			user:SendData(">> Syntax: !mkchat  [groups]")
		elseif chatrooms.items[name] then	
			user:SendData(">> "..name.." is already a Chatroom.")
		elseif GetItemByName(name) then
			user:SendData(">> There is a user with that name")
		else
			frmHub:RegBot(name,0,"","")
			local tmp = chatrooms:new(name, user.sName)
			string.gsub(profiles, "(%S+)", function(profile)
				profile = tonumber(profile) or GetProfileIdx(profile)
				if GetProfileName(profile) then tmp.groups[profile] = 1 end
			end); tmp:chat("Hello", name)
			chatrooms:save()
			return 1
		end
	end
end

Cheers


jiten

QuoteOriginally posted by kunal
hey the invite cmd doesnt work
pls help
Fixed :]

kunal

hey jiten
the script works fine
but can u add a cmd so that users can join the room on their own
1 more request probably the last one

jiten

QuoteOriginally posted by kunal
hey jiten
the script works fine
but can u add a cmd so that users can join the room on their own
1 more request probably the last one
Well, this script has an option to create a chatroom for an entire profile. Something like: !mkchat . So, if the "invited" user feels like chatting, he just needs to type something in the chatroom and he'll be automatically logged in.

kunal

wouldnt the chatroom window  open in every reg user 's dc++ if someone is chatting in the chatroom and the chatroom is enabled for the profile reg users

jiten

QuoteOriginally posted by kunal
wouldnt the chatroom window  open in every reg user 's dc++ if someone is chatting in the chatroom and the chatroom is enabled for the profile reg users
If it's enabled for REG profile, and someone is chatting, the window only pops up to those that have "logged in" by typing something previously in that chatroom.

kunal

thanx m8
no request now. ;)
perfect script.

SMF spam blocked by CleanTalk