PtokaX forum

Archive => Archived 4.0 boards => Request for Lua 4 scripts => Topic started by: Snooze on 22 March, 2004, 16:05:53

Title: [Request] Away script
Post by: Snooze on 22 March, 2004, 16:05:53
Looking for a simple standalone away script ... or a few hints on howto make one :)




*Snooze
Title:
Post by: Corayzon on 22 March, 2004, 16:31:30
-- cSlave 0.2.1 :: away.lua :: writin by Corayzon
-------------------------------------------------------------------------------------
awayList = {}

function saveAwayList()
   appendto(sysPath.."data/tempsettings.lua")
   local sOut = "--Away List Table\r\n"
   if awayList ~= nil then
      for user, setting in awayList do
         sOut = sOut.."awayList[\""..user.."\"] = \""..setting.."\"\r\n"
      end
   end
   write(sOut.."\r\n")
   writeto()
end

function doAwayCommand(user, data, cmd)
   if cmd == cmdaway then
      setAway(user, data)
      return 1

   elseif cmd == cmdback then
      setBack(user, data)
      return 1

   elseif cmd == cmdawaylist then
      getAwayList(user)
      return 0
   end
end

function setAway(user, data)
   _,_,cmd,reason = strfind(data, "%b<>%s+(%S+)%s+(.+)")
   if (reason==nil) then
      reason = "none"
      SendToAll(sBot, awaymsg1..user.sName..awaymsg2)
      awayList[user.sName] = reason
   else
      SendToAll(sBot, awaymsg1..user.sName..awaymsg3..reason)
      awayList[user.sName] = reason
   end
end

function setBack(user, data)
   _,_,cmd,reason = strfind(data, "%b<>%s+(%S+)%s+(.+)")
   if (reason==nil) then
      if awayList[user.sName] ~= nil then
         SendToAll(sBot, backmsg1..user.sName..backmsg2)
         awayList[user.sName] = nil
      end
   else
      if awayList[user.sName] ~= nil then
         SendToAll(sBot, backmsg1..user.sName..backmsg2..reason)
         awayList[user.sName] = nil
      end
   end
end

function getAwayList(user)
   local sOut = msgawaylist
   for username, suspects in awayList do
      sOut = sOut.."\t\t"..username.." ["..awayList[username].."]\r\n"
   end
   user:SendPM(sBot, sOut.."\r\n")
end


------------------------------------------------------------------

This is for the cSlave system...but u should get the idea... ;)
Title:
Post by: Snooze on 22 March, 2004, 16:50:22
Thanks Corayzon :)

Thats just what i had in mind :))


**Snooze
Title:
Post by: Snooze on 22 March, 2004, 18:35:41
Umm.. two problems i cant seam to fix :(

function setBack(user, data)
_,_,cmd,reason = strfind(data, "%b<>%s+(%S+)%s+(.+)")
if (reason==nil) then
if awayList[user.sName] ~= nil then
SendToAll(Bot, user.sName.." no longer set to 'Away'")  
awayList[user.sName] = nil
end
else
if awayList[user.sName] ~= nil then
SendToAll(Bot, user.sName.."is no longer away with the reason:"..reason)
awayList[user.sName] = nil
end
end
end

function getAwayList(user)
local sOut = msgawaylist
for username, suspects in awayList do
sOut = sOut.."\t\t"..username.." ["..awayList[username].."]\r\n"
end
user:SendPM(Bot, sOut.."\r\n")
end

- when calling the back setBack(user, data)  function i cant get it to go behind the first reponce ..

- and i cant get it to read the awaylist :( - reason


Please advise..


**Snooze
Title:
Post by: Corayzon on 23 March, 2004, 02:43:48
oh...wops...this is part of cSlave and u need some settings for the above to work correctly...i sujest u just download it and use the references u need...

Title:
Post by: Corayzon on 23 March, 2004, 03:20:50
local sOut = msgawaylist

msgawaylist == nil!
Title:
Post by: Corayzon on 23 March, 2004, 03:24:03
this is what ur missing...tri starting again and editing these settings and not the script itself

-- Away\Back Options
awaymsg1 = ""
awaymsg2 = " is now away"
awaymsg3 = " is now away because: "
backmsg1 = ""
backmsg2 = " is now back "
msgawaylist = "\r\n\r\n\tA w a y   L i s t\r\n\r\n"

by the way...how do i make it go

code
---------------------
and then show the tab marks n shit in the quote???
Title:
Post by: Snooze on 23 March, 2004, 09:51:49
thanks

[code*] [/code*]

with no *'s
Title:
Post by: Snooze on 23 March, 2004, 18:25:08
Um... Any chance of you helping me add so if a user sends a PM to a user in the awayList = {} he/she will recieve the away msg ? :))



**Snooze
Title:
Post by: raz on 23 March, 2004, 18:28:27
if u r using Dc++ den u should be able 2 do /away and /back as it is built in. If u want it 2 appear on main then u need a script!!
 :D
Title:
Post by: Snooze on 23 March, 2004, 18:30:11
Um... Any chance of you helping me add so if a user sends a PM to a user in the awayList = {} he/she will recieve the away msg ? :))



**Snooze
Title:
Post by: raz on 23 March, 2004, 18:32:47
/away and /back !! for example if i am away and u pm me u will recieve the msg i have put myself away as!! this is built into dc++.
 :D
Title:
Post by: Snooze on 23 March, 2004, 18:50:52
Thanks for the reply raz - though it were not what i were looking for ...


**Snooze
Title:
Post by: raz on 23 March, 2004, 18:56:14
What are you looking 4 ??
i don't think i understand u!!
 :D
Title:
Post by: Corayzon on 23 March, 2004, 23:22:07
um...yea dude u can...but it will interfer with dc's inbuilt one...

But if u would like to do then u would do something like the following...have no time to write up...work in 2 mins...

when a msg comes in u check the username from who its to...

then u check this against the awayList[user.sName]...

and if so then u send the pm to the sender with the away string...

but doing so will make 2 msgs come if the users dc is minimized to...

what im looking at doing is making the setBack\setAway commands update the internal dc away ;)

hope this made sense...and if u want some help...ill write up a demo for ya 2night :D

enjoy ppl!
Title:
Post by: Snooze on 24 March, 2004, 03:54:49
hey Corayzon,

I know its a already builin feature in DC++, though the users in my hub dont use the builin feature at all.

It's for a preivate hub thats been running for ages so my users are used to using the scripted version and are now asking me to bring it back ;)

A small demo on howto read the away msg in the DataArrival would be really nice :))




**Snooze
Title:
Post by: Corayzon on 24 March, 2004, 07:59:46
um here dude....im not testin this one, just writing in ere...so it might need some work before it works...

but it would be something like so...

sAwayMsg = "#u is away because: #x"

function DataArrival(user, data)
if strfind( data, "$To") then
local s, e, toUser, fromUser, sMessage = strfind(data,    "%$To:%s(%S+)%sFrom:%s(%S+)%s$(.*)$")
if awayList[toUser] then
user:SendPM(toUser, translateString(sAwayMsg, toUser, fromUser, awayList[toUser])
end
end
end

function translateString(sString, sUserName, e, x, t)
-- System Strings
sString, _ = gsub(sString, "#h", frmHub:GetHubName())

-- Input Strings
sString, _ = gsub(sString, "#u", sUserName)
sString, _ = gsub(sString, "#e", e)
sString, _ = gsub(sString, "#x", x)
if t ~= nil then sString, _ = gsub(sString, "#t", t) end
return sString
end

Ive even included info how to make great editable settings  :rolleyes:

If this dont work and u cant get to...i guess ill test it and fix it for ya  8)
Title:
Post by: Snooze on 24 March, 2004, 08:17:02
Worked perfectly :))

Thanks for taking the time to answer these newbie questions and explaning you solutions so well :))

---------------------------------
Small error - missing ) in this line:

user:SendPM(toUser, translateString(sAwayMsg, toUser, fromUser, awayList[toUser])


**Snooze
Title:
Post by: Corayzon on 24 March, 2004, 08:21:05
i allways do that...as in forget the ')' hehe...

np dude...im allways happy to help...y hide script when other ppl can use it ;)

anyways...happy to hear i help ya out...if u need anything else...ill tri my hardest to help ya =]

also dude...add my icq ;)

im allways helping ya so masse well
Title:
Post by: Corayzon on 24 March, 2004, 08:23:46
also...u guys like my translateString(sString, sUserName, e, x, t) command???
Title:
Post by: Snooze on 24 March, 2004, 08:27:13
Thanks for ICQ invite but im not running ICQ due to firewall blocking it at work :(
Title:
Post by: Corayzon on 24 March, 2004, 08:28:48
no problemo dude :D
Title:
Post by: D-J Valhala on 16 April, 2004, 18:22:00
Coraizon... hi :)
can you please post the complite script?