Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ---- FindNick 1.2 made by FlipFlop
- ----
- ---- Use '/findnick nickname' to search for a nickname (or part of it) in connected hubs.
- ----
- ---- 1.2 changelog:
- ---- - added CID support, use /findcid <CID> (requested by Toast)
- ---- 1.1 changelog:
- ---- - added ADC support
- ---- - displays clickable hubaddy to jump to the desired hub (thx en_dator)
- -- SETTINGS:
- NicksToMain = 1 -- display searchresult in mainchat of current hub
- NicksToHubs = 1 -- display searchresults in the hubs where the nicks are found
- NicksToPM = 1 -- display searchresult in pm
- -- SETTINGS END
- currenthub = false
- dcpp:setListener("ownChatOut", "FindNick",
- function(hub, msg )
- local s,e,cmd = string.find(msg, "^%p(%w+)")
- if cmd and NickCmds[cmd] then
- return 1,NickCmds[cmd](hub,msg)
- else
- return
- end
- end
- )
- function MainOutput (hub, msg)
- if hub:getProtocol() == "adc" then
- hub:addLine(msg)
- --DC():PrintDebug("ADC Message"..msg) -- for debugging
- else
- hub:injectChat(msg)
- end
- end
- function PmOutput (hub, msg)
- if hub:getProtocol() == "adc" then
- hub:injectPrivMsg(hub:getOwnSid(),hub:getOwnSid(),AdcEscape(msg))
- else
- hub:injectPrivMsgFmt(hub:getOwnNick(), hub:getOwnNick(), msg)
- end
- end
- function NickOutput (username, hub)
- _,_,hubname = string.find(hub:getHubName(), "%((%S*)%)$")
- if not hubname then hubname = hub:getHubName() end
- if hub:getProtocol() == "nmdc" then
- hubname = "dchub://"..string.gsub(hubname,"dchub://","")
- end
- if NicksToMain == 1 then MainOutput(currenthub, "*** User " ..username.. " found in: " ..hubname) end
- if NicksToPM == 1 then PmOutput(currenthub, "*** User " ..username.. " found in: " ..hubname) end
- if NicksToHubs == 1 then MainOutput(hub, "*** User " ..username.. " found in here.") end
- end
- NickCmds = {
- sui = function(hub, msg) -- Show userinfo
- local _,_,nick = string.find(msg, "%S+ (%S+)")
- local currenthub = hub
- if nick then
- if hub._users and hub._users[nick] then
- user = hub._users[nick]
- MainOutput(currenthub, "*** User info for: "..nick..":"..
- "\n\tDescription: "..user.getDesc()..
- "\n\tTag: "..user.getTag()..
- "\n\tConnection: "..user.getConn()..
- "\n\tFlag: "..user.getFlag()..
- "\n\tEmail: "..user.getFlag()..
- "\n\tShare: "..user.getShare()
- )
- else
- DC():PrintDebug("Nick not found in this hub")
- end
- else
- DC():PrintDebug("No nick specified")
- end
- end,
- findshare = function(hub, msg)
- if string.lower(string.sub(msg, 1, 10)) == "/findshare" then
- currenthub = hub
- DC():PrintDebug("Find Share started........")
- local _,_,share = string.find(msg, "%S+ (%S+)")
- share = string.gsub(share, "[%.%sB]", "")
- if tonumber(share) then
- MainOutput(currenthub, "*** Searching for a sharesize of '" ..share.. "' in all connected hubs...")
- counter = 0
- for _,hub in pairs(dcpp:getHubs()) do
- DC():PrintDebug("*Hub: " ..hub:getAddress().. " is being checked...")
- for k,l in pairs(hub._users) do
- if hub._users[k]._share and hub._users[k]._share == share then
- NickOutput(hub._users[k]._nick, hub)
- counter = counter + 1
- elseif type(k) == "table" then
- for i,m in pairs(k) do
- if hub.users[i]._share and hub._users[i]._share == share then
- NickOutput(i, hub)
- counter = counter + 1
- end
- end
- end
- end
- end
- MainOutput(currenthub, "*** Found " ..counter.. " users with a sharesize of: '" ..share.. "'")
- if NicksToMain == 0 then MainOutput(currenthub, "*** Check pm or hubs for results") end
- if NicksToPM == 1 then PmOutput(currenthub, "*** Found " ..counter.. " users containing: '" ..share.. "'") end
- DC():PrintDebug("Find sharesize finished.")
- else
- MainOutput(currenthub, "*** Wrong sharesize, use a number")
- end
- end
- end,
- findnick = function(hub, msg)
- if string.lower(string.sub(msg, 1, 9)) == "/findnick" then
- currenthub = hub
- DC():PrintDebug("Find Nick started........")
- nick = string.lower(string.sub (msg, 11))
- MainOutput(currenthub, "*** Searching for '" ..nick.. "' in all connected hubs...")
- counter = 0
- for _,hub in pairs(dcpp:getHubs()) do
- DC():PrintDebug("*Hub: " ..hub:getAddress().. " is being checked...")
- for k,l in pairs(hub._users) do
- if string.find(string.lower(hub._users[k]._nick), string.lower(nick)) then -- if ADC-hub
- NickOutput(hub._users[k]._nick, hub)
- counter = counter + 1
- elseif type(k) == "string" then
- if string.find(string.lower(k), string.lower(nick)) then
- NickOutput(k, hub)
- counter = counter + 1
- end
- elseif type(k) == "table" then
- for i,m in pairs(k) do
- if string.find(string.lower(i), string.lower(nick)) then
- NickOutput(i, hub)
- counter = counter + 1
- end
- end
- end
- end
- end
- MainOutput(currenthub, "*** Found " ..counter.. " users containing: '" ..nick.. "'")
- if NicksToMain == 0 then MainOutput(currenthub, "*** Check pm or hubs for results") end
- if NicksToPM == 1 then PmOutput(currenthub, "*** Found " ..counter.. " users containing: '" ..nick.. "'") end
- DC():PrintDebug("Find Nick finished.")
- end
- end,
- findcid = function(hub, msg)
- if string.lower(string.sub(msg, 1, 8)) == "/findcid" then
- DC():PrintDebug("Find CID started........")
- currenthub = hub
- local cid = string.sub (msg, 10)
- local counter = 0
- MainOutput(currenthub, "*** Searching for CID: " ..cid.. " in all connected hubs...")
- for _,hub in pairs(dcpp:getHubs()) do
- if hub:getProtocol() == "adc" then
- DC():PrintDebug("*Hub: " ..hub:getAddress().. " is being checked...")
- for sid,user in pairs(hub._users) do
- if user:getCid() == cid then
- NickOutput(user:getNick(), hub)
- counter = counter + 1
- end
- end
- end
- end
- MainOutput(currenthub, "*** Found " ..counter.. " users containing: '" ..cid.. "'")
- if NicksToMain == 0 then MainOutput(currenthub, "*** Check pm or hubs for results") end
- if NicksToPM == 1 then PmOutput(currenthub, "*** Found " ..counter.. " users with CID: " ..cid.. "'") end
- DC():PrintDebug("Find CID finished.")
- end
- end,
- }
- AdcEscape = function(msg, inverse)
- msg = string.gsub(msg, "\r", "")
- local ret = ""
- if inverse then
- local replacetable = {}
- replacetable["\\\\"] = [[\]]
- replacetable["\\s"] = [[ ]]
- replacetable["\\n"] = "\n"
- local skip = false
- for k = 1, string.len(msg) do
- if skip then
- skip = false
- else
- local c = string.sub( msg, k, k + 1)
- if replacetable[c] then
- ret = ret .. replacetable[c]
- skip = true
- else
- ret = ret .. string.sub(c, 1, 1)
- end
- end
- end
- else
- local replacetable = {}
- replacetable["\\"] = [[\\]]
- replacetable[" "] = [[\s]]
- replacetable["\n"] = [[\n]]
- for k = 1, string.len(msg) do
- local c = string.sub( msg, k, k)
- if replacetable[c] then
- ret = ret .. replacetable[c]
- else
- ret = ret .. c
- end
- end
- end
- return ret
- end
- DC():PrintDebug( " ** Loaded findnick.lua by FlipFlop **")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement