Away messages
 

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

Away messages

Started by Powerpuffan, 12 October, 2008, 17:48:05

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Powerpuffan

Hello!

I am wondering if there is a possibility that someone can do a script where we get the opportunity to leave a message in main, which also appears in pm for everyone that is writing to me?

What I mean is for ex. type

"+away" in main and this will appear i main

- [2007-11-12 15:34] <-=N?rd=-> Master Powerpuffan went away at 15:34:43 - Message: Not here right now...

Every time someone writes to me in pm they will get that message so they know that I?m not there so they would know directly that they will not get any help or so at that moment.

And also if it?s possible to write like

+away And a own reason like for ex. "+away Work. Be home by 18.00"

This is the message in main

- [2007-11-13 07:28] <-=N?rd=-> Master Powerpuffan went away at 07:29:09 - Message: Work. Be home by 18.00

I maybe also have to say that the opportunity to do away mess in the hub would be for everyone regardless of profile.


Request 2:

Is it also possible to get a possibility to write like "+getaways" for Masters and operators and it will show all away messages in the hub?

It can look like this:

[12:okt]  [17:42:40] <-=N?rd=->  Current Stored Away's:

   ??????????????????????????????????????????
     Nr.   Name:      Message:
   ??????????????????????????????????????????
     1.   D@vine           Not here right now...
          2.    Priest                Sleeping

     Total Nr: 2

Respectfully

PowerPuffan

Powerpuffan

Sorry i forgotten one thing

When the person who is away comes back they either have to write "+back" in main or just type something in main and it would look like this

[12:okt]  [10:20:05] <-=N?rd=-> Master Powerpuffan returned at 10:20:04
Respectfully

PowerPuffan

Madman

#2
I been busy, so it took some time.
But this script should fit all your requests, and more ;p

-- Awayer 1.2
-- Made by Madman
-- Requested by Powerpuffan

-- Allows a users to set away mode with an message
-- Message can be Optional with/without an default message
-- Message can be forced without default message
-- Sends a message that user is away if pm is recived
-- Away user can be listed
-- Return user on back command or chat in main
-- Users can update there away message
-- Informs how long user been away upon return
-- Sends rightclick to userlist and hubtab

-- Version 1.1
-- Fixed: File error in updateaway, reported by PowerPuffan
-- Fixed: Missing botname in update away
-- Added: Notify user about updated message

-- Version 1.2
-- Fixed bug in RC, reported by PowerPuffan

tConfig = {
	Bot = SetMan.GetString(21), -- Bots name
	SaveToFile = true, -- Save Away table to a file
	File = "Away.msg", -- The file to save to
	ForceMsg = false, -- User must enter an away message, UseDefaultMsg can not be true if this is
	UseDefaultMsg = true, -- Use DefaultMsg if user don't enter a message
	DefaultMsg = "[Default Message] I'm not here right now...", -- The default msg
	SilentUpdate = true, -- Set to false if script should tell all that user updated his/hers message
	Menu = "Awayer", -- Name of the RightClick menu
	HubOwner = "Madman",
	GetAways = { -- What profiles are allowed to list the away users
		[0] = true, -- Master
		[1] = true, -- Op
		[2] = false, -- Vip
		[3] = false, -- Reg
		[-1] = false, -- Unreg
	}
}

Path = Core.GetPtokaXPath().."scripts/"

function OnStartup()
	if tConfig.SaveToFile then
		local file = io.open(Path..tConfig.File)
		if file then
			file:close()
		else
			local file = io.open(Path..tConfig.File,"w+")
			file:write("Away = {\n}")
			file:close()
		end
		LoadFromFile(Path..tConfig.File)
	else
		Away = {}
	end
	if tConfig.ForceMsg and tConfig.UseDefaultMsg then
		GoOff = math.random(1,2)
		Off = { "ForceMsg","UseDefaultMsg"}
		tConfig[(Off[GoOff])] = false
		Msg = "<" ..tConfig.Bot.. "> ForceMsg and UseDefaultMsg is bot true in Awayer's Config. Only one of thoose can be on. " ..Off[GoOff].. " was randomly choose to be disabled."
		if Core.GetUser(tConfig.HubOwner) then
			Core.SendToNick(tConfig.HubOwner,Msg.." Please fix this error as soon as posible.")
		else
			Core.SendToOps(Msg.." Please inform the the HubOwner about this as as soon as posible.")
		end
	end
end

function UserConnected(user)
	Core.GetUserData(user,12)
	if user.bUserCommand then
		RightClick(user)
	end
end

RegConnected = UserConnected
OpConnected = UserConnected

function RightClick(user)
	local tRC = {
		["away"] = {"Go Away","%[line:Message]"},
		["back"] = {"Return from away",""},
		["getaways"] = {"List away users",""},
		["updateaway"] = {"Updated your away message","%[line:Message]"},
	}
	for cmd,cd in pairs(tRC) do
		Core.SendToUser(user,"$UserCommand 1 3 " ..tConfig.Menu.."\\"..cd[1].." $<%[mynick]> !"..cmd.." " ..cd[2].."&#124;|")
	end
end

function ChatArrival(user,data)
	local data = data:sub(1,-2)
	local s,e,cmd = data:find("%b<>%s+%p(%S+)")
	if cmd then
		tCmds = {
			["away"] = function(user,data)
				local s,e,msg = data:find("%b<>%s+%S+%s+(.*)")
				if Away[user.sNick] then
					Core.SendToUser(user,"<" ..tConfig.Bot.. "> You allready are away")
				else
					Away[user.sNick] = {}
					Away[user.sNick]["Time"] = os.date("*t") -- Add time to table
					if not msg then -- If we don't have msg
						if tConfig.ForceMsg then -- Check if we must have
							Core.SendToUser(user,"<" ..tConfig.Bot.. "> An away msg is requierd")
							Away[user.sNick] = nil -- Clear table
							return true
						elseif tConfig.UseDefaultMsg then -- If we don't need msg and script should add it 
							Away[user.sNick]["Msg"] = tConfig.DefaultMsg -- Add default msg to table
							msg = " and left the following message: " ..tConfig.DefaultMsg
						end
					else -- if we got msg
						Away[user.sNick]["Msg"] = msg -- Add msg to table
						msg = " and left the following message: " ..msg
					end
					if tConfig.SaveToFile then
						SaveToFile(Path..tConfig.File,Away,"Away")
					end
					Core.SendToAll("<" ..tConfig.Bot.. "> " ..user.sNick.. " went away at " ..os.date("%X")..(msg or "!"))
				end
			end,
			["updateaway"] = function(user,data)
				if Away[user.sNick] then
					local s,e,msg = data:find("%b<>%s+%S+%s+(.*)")
					if msg then
						Away[user.sNick]["Msg"] = msg
						if not tConfig.SilentUpdate then
							Core.SendToAll("<" ..tConfig.Bot.. "> " ..user.sNick.. " just updated his/hers awy message to "..msg)
						end
						if tConfig.SaveToFile then
							SaveToFile(Path..tConfig.File,Away,"Away")
						end
						Core.SendToUser(user,"<" ..tConfig.Bot.. "> Message updated to " ..Away[user.sNick]["Msg"])
					else
						Core.SendToUser(user,"<" ..tConfig.Bot.. "> You need to enter a message to update your away status")
					end
				else
					Core.SendToUser(user,"You are not away")
				end
			end,
			["back"] = function(user,data)
				if Away[user.sNick] then
					Return(user)
				else
					Core.SendToUser(user,"<" ..tConfig.Bot.. "> You are not away")
				end
			end,
			["getaways"] = function(user,data)
				if tConfig.GetAways[user.iProfile] then
					Msg = "\r\n\t" ..string.rep("-",50).. " Away Users " ..string.rep("-",50).."\r\n"
					Msg = Msg.."\tNr\tUser\t\tTime away\t\tMessage\r\n"
					Msg = Msg.."\t"..string.rep("-",121).."\r\n"
					c = 0
					for sNick,_ in pairs(Away) do
						c = c + 1
						Time = TimeConvert(os.time(Away[sNick]["Time"]))
						Msg = Msg.. "\t" ..c..".\t" ..sNick.. "\t\t" ..Time.. "\t" ..(Away[sNick]["Msg"] or "").. "\r\n"
					end
					Msg = Msg.."\r\n\tTotalt users away: "..c
					Core.SendToUser(user,"<" ..tConfig.Bot.. "> "..Msg)
				else
					Core.SendToUser(user,"<" ..tConfig.Bot.. "> This command is offlimit for you")
				end
			end,
		}
		if tCmds[cmd] then
			return tCmds[cmd](user,data),true
		end
	end
	if Away[user.sNick] then
		Return(user)
	end
end

function ToArrival(user,data)
	local data = data:sub(1,-2)
	local s,e,To = data:find("$To:%s+(%S+)")
	if Away[To] then
		if Away[To]["Msg"] then
			msg = ", and left the following message: " ..Away[To]["Msg"]
		end
		Core.SendPmToUser(user,To,"Automated Message: " ..To.." is currently in away mode" ..(msg or "."))
	end
end

function Return(user)
	Time = TimeConvert(os.time(Away[user.sNick]["Time"]))
	Away[user.sNick] = nil
	if tConfig.SaveToFile then
		SaveToFile(Path..tConfig.File,Away,"Away")
	end
	Core.SendToAll("<" ..tConfig.Bot.. "> " ..user.sNick.. " returned at " ..os.date("%X").. " after beeing away for " ..Time)
end

Serialize = function(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 pairs(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

SaveToFile = function(file , table , tablename)
	local handle = io.open(file,"w+")
	handle:write(Serialize(table, tablename))
	handle:flush()
	handle:close()
end

LoadFromFile = function(filename)
	local f = io.open(filename)
	if f then
		local r = f:read("*a")
		f:flush()
		f:close()
		local func,err = loadstring(r)
		if func then x,err = pcall(func) end
	end
end

function TimeConvert(time)
	-- Code by Mutor
	-- EventBot 1.0b LUA 5.11 [Strict][API 2]
	if time then
		local s,x,n = "",0,os.time()
		local tab = {{31556926,"year"},{2592000,"month"},{604800,"week"},
		{86400,"day"},{3600,"hour"},{60,"minute"},{1,"second"}}
		if time > 0 then
			if time < 2145876659 then
				if n > time then
					time = n - time
				elseif n < time then
					time = time - n
				end
				for i,v in ipairs(tab) do
					if time > v[1] then
						x = math.floor(time/v[1])
						if x > 1 then v[2] = v[2].."s" end
						if x > 0 then
							s = s..x.." "..v[2]..", "
							time = time-x*v[1]
						end
					end
				end
				collectgarbage("collect")
				return s:sub(1,-3)
			else
				return "Invalid date or time supplied. [must be pre 12/31/2037]"
			end
		else
			return "Invalid date or time supplied. [must be post 01/01/1970]"
		end
	else
		return "Invalid date or time supplied."
	end
end
We suffer in silence, we lurk in the shadows, we kill in the night
Site currently down, ETA of returning online is 2099 ;p

Snooze

I fail to see the usage of scripts like these, as almost all clients cover this. Ex. Dc++ by "/away 'message'"

I would love to hear the reasoning behing this is I keep getting requests list this.

/Snooze

Madman

I don't know, and i don't really care =)
I just do scripts ;p
We suffer in silence, we lurk in the shadows, we kill in the night
Site currently down, ETA of returning online is 2099 ;p

Powerpuffan

Thanks Madman for a wonderfull script that works great :-*
Respectfully

PowerPuffan

Powerpuffan

Hey Snooze!

You wanted an explanation to why we want an ?away message? script, so therefore you get it here?. J

The reason we want an ?away message? is that the ?away msg? who is built-in the clients does not work the way we want it.

Among other things, nothing is displayed in main when you make the command as we want it to be.

Madman did a phenomenal job with the script and also gave us the opportunity to further refinements are just great. 

All users and masters thank Madman so much.

Respectfully

PowerPuffan

Powerpuffan

#7
Hello!

Update your away message does not work at all.

The only thing that happens is that the actual command appears in main like this

[2008-11-05 00:34] <XXX> !updateaaway Sleeping :)

Respectfully

PowerPuffan

?StIfFLEr??

yep.. its true plz if sum1 can make some correction

Madman

Fixed that error, and some more i found...
Script updated
We suffer in silence, we lurk in the shadows, we kill in the night
Site currently down, ETA of returning online is 2099 ;p

Powerpuffan

Hi

There is a fault in the script in line 84. The command is

["updateaaway"] = {"Updated your away message","%[line:Message]"},

But it doesn?t work because of the spelling. It should be one A in updateaway  :)
Respectfully

PowerPuffan

Madman

Indeed there was, fixed and post updated...
We suffer in silence, we lurk in the shadows, we kill in the night
Site currently down, ETA of returning online is 2099 ;p

SMF spam blocked by CleanTalk