OpChat Plus
 

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

OpChat Plus

Started by jiten, 06 July, 2006, 19:56:49

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

jiten

--[[

	OpChat Plus v2.01 - LUA 5.0/5.1 by jiten

	Based on: OpChat++ by nErBoS

	FEATURES:

	- List, Invite, Remove and members to/from OpChat
	- OpChat log while offline

	CHANGELOG:

	- Added: Chat history saved for offline members - requested by zvamp;
	- Added: Missing custom message (8/21/2006)

]]--

tOpChat = {
	-- Bot Name
	sName = "OpChat",
	-- Database
	fFile = "tOpChat.tbl",
	-- Send message to invited users on hub/script restart (true = on, false = off)
	bSend = true,
		-- Message sent (true = on, false = off)
		sMsg = "You are currently invited to OpChat",
	-- Commands
	sMembers = "members", sInvite = "invite", sRemove = "remove", sLog = "talklog"
}

tMembers = {}

Main = function()
	-- If OpChat Plus' BotName is the same as hub's
	if frmHub:GetOpChatName() == tOpChat.sName then
		-- Rename hub's and disable
		frmHub:SetOpChatName(tOpChat.sName.."_"); frmHub:SetOpChat(0)
	end;
	-- Register OpChat Plus's BotName
	frmHub:RegBot(tOpChat.sName)
	-- Load database content
	if loadfile(tOpChat.fFile) then dofile(tOpChat.fFile) end
	-- Populate database
	for i, v in ipairs(frmHub:GetOperators()) do
		tMembers[string.lower(v.sNick)] = (tMembers[string.lower(v.sNick)] or 1)
	end
	-- Send custom message
	if tOpChat.bSend then
		-- For each member
		for nick, v in pairs(tMembers) do
			-- Send message
			SendToNick(nick, "$To: "..nick.." From: "..tOpChat.sName.." $<"..
			tOpChat.sName.."> "..tOpChat.sMsg)
		end
	end
end

ToArrival = function(user, data)
	-- Parse to and msg
	local _,_, to, msg = string.find(data, "^$To:%s+(%S+)%s+From:%s+%S+%s+$%b<>%s+(.*)|$")
	-- Message sent to OpChat Plus's Bot
	if string.lower(to) == string.lower(tOpChat.sName) then
		-- If command
		local _,_, cmd = string.find(msg, "^%!(%a+)")
		-- If table contains it
		if cmd and tCommands[string.lower(cmd)] then
			-- Process
			return tCommands[cmd].tFunc(user, msg), 1
		end
		-- If member or operator
		if tMembers[string.lower(user.sName)] or user.bOperator then
			-- Set as member
			tMembers[string.lower(user.sName)] = tMembers[string.lower(user.sName)] or 1
			-- Send message
			PM(msg, user.sName)
		else
			-- Report
			user:SendPM(tOpChat.sName, "*** You're not a member here!")
		end
		return 1
	end
end

NewUserConnected = function(user)
	-- Supports UserCommands
	if user.bUserCommand then
		-- For each entry in table
		for i,v in pairs(tCommands) do
			-- If member
			if tMembers[string.lower(user.sName)] then
				-- Send
				user:SendData("$UserCommand 1 3 OpChat Plus\\"..v.tRC[1].."$$To: "..
				tOpChat.sName.." From: %[mynick] $<%[mynick]> !"..i..v.tRC[2].."|")
			end
		end
	end
	local tmp = tMembers[string.lower(user.sName)]
	-- If member and history
	if tmp and tmp ~= 1 then
		-- Send
		user:SendPM(tOpChat.sName, "*** There was chat while you were offline. Type !"..
		tOpChat.sLog.." for more details!")
	end
end

OpConnected = NewUserConnected

OnExit = function()
	local hFile = io.open(tOpChat.fFile, "w+"); Serialize(tMembers, "tMembers", hFile); hFile:close()
end

tCommands = {
	[tOpChat.sMembers] = {
		tFunc = function(user)
			-- Member
			if tMembers[string.lower(user.sName)] then
				-- Header
				local tMsg = "\r\n\r\n\t"..string.rep("=", 20).."\r\n\t        Member List:\r\n\t"..
				string.rep("-", 40).."\r\n"
				-- Populate
				for v,i in pairs (tMembers) do 
					tMsg = tMsg.."\t ? "..v.."\r\n"
				end
				-- Send
				user:SendPM(tOpChat.sName, tMsg)
			end
		end,
		tRC = { "Member List", "" }
	},
	[tOpChat.sInvite] = {
		tFunc = function(user, data)
			-- Get nick
			local _,_, nick = string.find(data, "^%S+%s(%S+)$")
			-- Exists
			if nick then
				-- If member
				if tMembers[string.lower(nick)] then
					-- Already
					user:SendPM(tOpChat.sName, "*** Error: "..nick.." has already been invited to "..tOpChat.sName)
				else
					-- Send Message
					PM("*** "..nick.." has been invited to this room!", tOpChat.sName)
					-- Set member
					tMembers[string.lower(nick)] = 1
					-- Inform invited
					if GetItemByName(nick) then
						GetItemByName(nick):SendPM(tOpChat.sName, "*** You have been invited to "..
						tOpChat.sName.." by "..user.sName)
					end
					-- Save to DB
					OnExit()
				end
			else
				user:SendPM(tOpChat.sName, "*** Error: You must type a nick!")
			end
		end,
		tRC = { "Invite User", " %[line:User]" }
	},
	[tOpChat.sRemove] = {	
		tFunc = function(user, data)
			-- Get nick
			local _,_, nick = string.find(data, "^%S+%s(%S+)$")
			-- Nick found
			if nick then
				-- If member
				if tMembers[string.lower(nick)] then
					-- Remove
					tMembers[string.lower(nick)] = nil
					-- Report to online nick
					if GetItemByName(nick) then
						GetItemByName(nick):SendPM(tOpChat.sName, "*** You have been removed from "..
						tOpChat.sName.." by "..user.sName)
					end
					-- Inform other members
					PM("*** "..nick.." has been removed from this room!", tOpChat.sName)
					-- Save
					OnExit()
				else
					user:SendPM(tOpChat.sName, "*** Error: "..nick.." isn't a member of "..tOpChat.sName)
				end
			else
				user:SendPM(tOpChat.sName, "*** Error: You must type a nick!")
			end
		end,
		tRC = { "Remove User", " %[line:User]" }
	},
	[tOpChat.sLog] = {	
		tFunc = function(user)
			local tmp = tMembers[string.lower(user.sName)]
			-- If member
			if tmp then
				-- No history
				if tmp == 1 then
					-- Send report
					user:SendPM(tOpChat.sName, "*** Error: No history available. You were always online!")
				else
					-- Remove preceding 1
					local sMessage = string.sub(tmp, 2, string.len(tmp))
					-- Send history
					user:SendPM(tOpChat.sName, "*** Current history:\r\n\r\n"..sMessage)
					-- Reset history and save
					tMembers[string.lower(user.sName)] = 1; OnExit()
					-- Send history
					user:SendPM(tOpChat.sName, "*** Your history log has been purged!")
				end
			else
				user:SendPM(tOpChat.sName, "*** Error: You aren't a member of "..tOpChat.sName.."!")
			end
		end,
		tRC = { "Show History", "" }
	},}

PM = function(msg, from)
	-- For each member
	for nick, id in pairs(tMembers) do
		-- User is online
		if GetItemByName(nick) then
			-- For everyone except sender
			if nick ~= string.lower(from) then
				-- Send
				SendToNick(nick, "$To: "..nick.." From: "..tOpChat.sName.." $<"..from.."> "..msg)
			end
		else
			-- Log history
			tMembers[nick] = tMembers[nick].."<"..from.."> "..msg.."\r\n"
		end
	end
end

Serialize = function(tTable,sTableName,hFile,sTab)
	sTab = sTab or "";
	hFile:write(sTab..sTableName.." = {\n");
	for key,value in pairs(tTable) do
		if (type(value) ~= "function") then
			local sKey = (type(key) == "string") and string.format("[%q]",key) or string.format("[%d]",key);
			if(type(value) == "table") then
				Serialize(value,sKey,hFile,sTab.."\t");
			else
				local sValue = (type(value) == "string") and string.format("%q",value) or tostring(value);
				hFile:write(sTab.."\t"..sKey.." = "..sValue);
			end
			hFile:write(",\n");
		end
	end
	hFile:write(sTab.."}");
end

MetalPrincess

Ok I think this is working no OPs online to test it with, but when I entered the command this time it came back with the command I entered 2 times in the window as if the other person would be entering the chat.

MP

jiten

Quote from: MetalPrincess on 08 July, 2006, 12:16:34
Ok I think this is working no OPs online to test it with, but when I entered the command this time it came back with the command I entered 2 times in the window as if the other person would be entering the chat.

I'm glad to know that it's working.

By the way, you can invite yourself [with other nick] to the room, to know whether it's working as expected.
I suppose that you've already done that.

zvamp

+talklog would be very nice! can this be done?

jiten

Quote from: zvamp on 20 August, 2006, 13:33:22
+talklog would be very nice! can this be done?

Yes, it can be done and will be added to the code as soon as possible.

jiten

First post has been updated with some additions to the code.

zvamp

very very nice!!! thank you jiten!!!

But how do I change the trigger command? We would like to use "+" instead of "!"

jiten

Quote from: zvamp on 22 August, 2006, 15:38:17
But how do I change the trigger command? We would like to use "+" instead of "!"

In your ToArrival function, change this:

local _,_, cmd = string.find(msg, "^%!(%a+)")


to:

local _,_, cmd = string.find(msg, "^%+(%a+)")


zvamp

Wonderful Jiten :) Thanks from all OPs on our hub ;)

Keep up the good work!!

speedX

hey guys...i want a master chat script.....not similar to this coz in this script any one can enter tht room.......i want only the masters of the hub to enter tht room....and also don want tht invite, list and remove commands...only a simple master chat.....thank u....
Thanking You,

speedX

JueLz

Yes jiten script works fine :))
I am owner of the MzDistortion? Empire
the addy to my hub is mzdistortion.no-ip.org
____________________________________________
--=                        [HT 500]                          =--

jiten

Quote from: speedX on 24 August, 2006, 19:17:29
hey guys...i want a master chat script.....not similar to this coz in this script any one can enter tht room.......i want only the masters of the hub to enter tht room....and also don want tht invite, list and remove commands...only a simple master chat.....thank u....

Search the forum for Chatrooms 4.12 then.

tekclon

#12
hi brothers

i have probs whit the script !!!
i cant open the memberslist and the history`s
or open 1/2h laters

help me please


jiten

Quote from: tekclon on 04 September, 2006, 19:44:37
i cant open the memberslist and the history`s
or open 1/2h laters

Can you give me more details?

In other words, do you have permission to use those commands?
How does it happen? Do you get any syntax error?

This would be helpful to know whether it's really a bug, and if it is, it will surely be fixed.

SMF spam blocked by CleanTalk