--// Announcer Bot v1.4a ---------------------------------------------------- -- by: gg3k -- file: announcer.lua -- Thanks to: Ptaczek for making the great hubsoft, all the people at the lua forum for helping out when needed. :) -- // Configure below -- -- Enter the name of the announcer here. Set to nil for alternate (***) layout. -- ex. BotName = "Hub-hostess" BotName = "×××" HubOwner = "type_owner_here" HubCoOwner = "type_coowner_here" --// Timer related configuration ------ -- The number of minutes between each sent timer message. MessageDelay = 15 -- Use the Timed message feature (0 = no, 1 = yes) UseTimer = 1 -- How to send the private onjoin messages -- "pm" = Send in PM. -- "main" = Send in main (privately). privatemode = "main" -- These values will prevent users from getting flooded with repeated messages over time. -- all numbers refers to number of events that has to have taken place since the last message -- round before the bot sends the messages from start. Either of the two events will trigger a resending. -- (0 = disable) MinChat = 30 -- minimum number of chatlines+announced. MinUserConnect = 40 -- minimum number of new user connections (unannounced+announced). -- Enter the profile name of any profile that should invoke a message, and the message to be sent below. -- If you don't want a message, simply don't add one for that particular profile. :) -- Example: ["profile name"] = "message", -- -- You can send a private onjoin message to users in a specific profile by putting ! before the profile name. -- Example: ["!master"] = "Hi [user], your ip is [userip], there are [usercount] users online.", -- -- To set a connection/disconnection message for a specific user put a $ before the nickname. -- Example: ["$user"] = "The amazing [user] has entered the hub.", -- -- To disable connection/disconnection message for a specific user, set the message to @. -- Example: ["$user"] = "@", -- -- To send a custom message to the connecting user (privately), put $pm$ before the nickname. -- Example: ["$pm$user"] = "Hi [user], Your IP is [userip]", -- -- These only work on connect/disconnect messages. -- [user] = the name of connecting user. (this will not work on the time messages) -- [userdesc] = Description of connecting user. -- [userspeed] = Speed of the connecting user. -- [useremail] = E-mail of connecting user. -- [usershare] = Share of connecting user. -- [userip] = IP of connecting user. -- -- These work on both connect/disconnect and times messages. -- [hubname] = name of the hub. -- [hubowner] = owner of the hub. -- [usercount] = current number of users. -- [totalshare] = total amount of share. (TB) -- [minshare] = minimum share in hub. (GB) -- [maxusers] = maximum number of users. -- [crlf] = new line. -- Connecting users/profiles. iprofiles = { ["!Master"] = "Hi [user], your ip is [userip], there are [usercount] users online.", ["$"..HubOwner] = "Hub owner [user] has entered [hubname]", ["$pm$"..HubOwner] = "Hello [user], announcer bot works like a charm.", ["$"..HubCoOwner] = "Hub co-owner [user] has entered [hubname]", ["Master"] = "Hub super-op [user] has entered [hubname].", ["Operator"] = "Operator [user] has entered [hubname].", ["VIP"] = "VIP user [user] has entered [hubname].", ["Reg"] = "Registered user [user] has entered [hubname].", } -- Disconnecting users/profiles. oprofiles = { ["$"..HubOwner] = "Hub owner [user] has left [hubname]", ["$"..HubCoOwner] = "Hub co-owner [user] has left [hubname]", ["Master"] = "Hub super-op [user] has left [hubname].", ["Operator"] = "Operator [user] has left [hubname].", ["VIP"] = "VIP user [user] has left [hubname].", ["Reg"] = "Registered user [user] has left [hubname].", } -- Timed messages, add as many as you want, it will rotate in sequence. -- To read from a file type file: as message. Example: [1] = "file:message.txt", -- The filename is case sensitive, so take care when typing. Files are relative to the scripts dir. -- The [] replacements works on the contents of the text file too. tmessages = { [1] = "-×- Users: [usercount]/[maxusers] -×-", [2] = "-×- Minimum share is: [minshare] GB. 2 Slots minimum. -×-", } -- End of configuration profileNr = { } count = { chat = 0, connected = 0, startdate = date(), } --// This function is fired at the serving start function Main() setlocale("swe") if BotName == nil then layout = "*** " else layout = "<"..BotName.."> " end SetTimer(MessageDelay*60000) if UseTimer == 1 then StartTimer() end end --// This function is fired when a new data arrives function DataArrival(curUser, sData) if strsub(sData, 1, 1) == "<" then count.chat = count.chat + 1 end end --// This function is fired when a new user finishes the login function NewUserConnected(curUser) getmessages(curUser, "in") end --// This function is fired when an operator enters the hub function OpConnected(curUser) getmessages(curUser, "in") end --// This function is fired when an user disconnects function UserDisconnected(curUser) getmessages(curUser, "out") end --// This function is fired when an operator disconnects function OpDisconnected(curUser) getmessages(curUser, "out") end function OnTimer() if timetag == nil then timetag = 0 count.chat = MinChat count.connected = MinUserConnect end timetag = timetag + 1 if timetag == 1 then if MinChat > 0 then if count.chat < MinChat then timetag = 0 local reset = 0 else count.chat = 0 count.connected = 0 local reset = 1 end end if MinUserConnect > 0 and reset == 0 then if count.connected < MinUserConnect then timetag = 0 else count.chat = 0 count.connected = 0 end end end if tmessages[timetag] then message = tmessages[timetag] if strsub(message, 1, 5)=="file:" then local filename = strsub(message, 6, strlen(message)) readfrom(filename) local message = "" while 1 do local line = read() if line == nil then break else message = message..line.."\r\n" end end announce(BotName, message) readfrom() else announce(BotName, message) end else timetag = 0 end end --// Help functions ---------------------------------------------------- function announce(user, string) local arrTmp = substitute(user, string) SendToAll(layout..arrTmp) end function pm(user, string) local arrTmp = substitute(user, string) if privatemode == "pm" then user:SendPM(BotName, arrTmp) elseif privatemode == "main" then user:SendData(layout..arrTmp) end end function substitute(user, string) local arrTmp = gsub(string, "%[usercount%]", frmHub:GetUsersCount()) arrTmp = gsub(arrTmp, "%[maxusers%]", frmHub:GetMaxUsers()) arrTmp = gsub(arrTmp, "%[totalshare%]", format("%.2f", frmHub:GetCurrentShareAmount()/1024^4)) arrTmp = gsub(arrTmp, "%[minshare%]", frmHub:GetMinShare()/1024) arrTmp = gsub(arrTmp, "%[hubname%]", frmHub:GetHubName()) arrTmp = gsub(arrTmp, "%[hubowner%]", HubOwner) arrTmp = gsub(arrTmp, "%[crlf%]", "\r\n") if type(user) == "table" then local myinfo = user.sMyInfoString local _,_,desc,speed,email,sharesize = strfind(myinfo, "[$]+[^$]+[$]+ALL%s+%S+%s+([^$]+)".. "[$]+[^$]+[$]+([^$]+)[$]+([^$]+)[$]+([^$]+)[$]") if desc == nil then desc = "none" end if speed == nil then speed = "none" end if email == nil then email = "none" end if sharesize == nil then sharesize = 0 end arrTmp = gsub(arrTmp, "%[user%]", user.sName) arrTmp = gsub(arrTmp, "%[userdesc%]", desc) arrTmp = gsub(arrTmp, "%[userspeed%]", strsub(speed, 1, strlen(speed)-1)) arrTmp = gsub(arrTmp, "%[useremail%]", email) arrTmp = gsub(arrTmp, "%[usershare%]", format("%.2f", sharesize/1024)) arrTmp = gsub(arrTmp, "%[userip%]", user.sIP) end return arrTmp end function getmessages(user, io) local userprofile = GetProfileName(user.iProfile) if userprofile == nil then userprofile = "qwertyuiopasdfghjkl" end if io == "in" then if iprofiles["$"..user.sName] then if iprofiles["$"..user.sName] ~= "@" then announce(user, iprofiles["$"..user.sName]) count.chat = count.chat + 1 else count.connected = count.connected + 1 end elseif iprofiles[userprofile] and userprofile ~= -1 then announce(user, iprofiles[userprofile]) count.chat = count.chat + 1 else count.connected = count.connected + 1 end if iprofiles["$pm$"..user.sName] then pm(user, iprofiles["$pm$"..user.sName]) end if iprofiles["!"..userprofile] then pm(user, iprofiles["!"..userprofile]) end else if oprofiles["$"..user.sName] then if oprofiles["$"..user.sName] ~= "@" then announce(user, oprofiles["$"..user.sName]) count.chat = count.chat + 1 end elseif oprofiles[userprofile] and userprofile ~= -1 then announce(user, oprofiles[userprofile]) count.chat = count.chat + 1 end end end