Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.77 KB | None | 0 0
  1. ---- FindNick 1.2 made by FlipFlop
  2. ----
  3. ---- Use '/findnick nickname' to search for a nickname (or part of it) in connected hubs.
  4. ----
  5. ---- 1.2 changelog:
  6. ----        - added CID support, use /findcid <CID> (requested by Toast)
  7. ---- 1.1 changelog:
  8. ----        - added ADC support
  9. ----        - displays clickable hubaddy to jump to the desired hub (thx en_dator)
  10.  
  11.  
  12.  
  13. -- SETTINGS:
  14. NicksToMain = 1     -- display searchresult in mainchat of current hub
  15. NicksToHubs = 1     -- display searchresults in the hubs where the nicks are found
  16. NicksToPM = 1   -- display searchresult in pm
  17. -- SETTINGS END
  18.  
  19. currenthub = false
  20.  
  21. dcpp:setListener("ownChatOut", "FindNick",
  22.    function(hub, msg )
  23.        local s,e,cmd = string.find(msg, "^%p(%w+)")
  24.        if cmd and NickCmds[cmd] then
  25.           return 1,NickCmds[cmd](hub,msg)
  26.        else
  27.           return
  28.        end
  29.     end
  30. )
  31.  
  32. function MainOutput (hub, msg)
  33.     if hub:getProtocol() == "adc" then
  34.         hub:addLine(msg)
  35.         --DC():PrintDebug("ADC Message"..msg) -- for debugging
  36.     else
  37.         hub:injectChat(msg)
  38.     end
  39. end
  40.  
  41. function PmOutput (hub, msg)
  42.     if hub:getProtocol() == "adc" then
  43.         hub:injectPrivMsg(hub:getOwnSid(),hub:getOwnSid(),AdcEscape(msg))
  44.     else
  45.         hub:injectPrivMsgFmt(hub:getOwnNick(), hub:getOwnNick(), msg)
  46.     end
  47. end
  48.  
  49. function NickOutput (username, hub)
  50.     _,_,hubname = string.find(hub:getHubName(), "%((%S*)%)$")
  51.     if not hubname then hubname = hub:getHubName() end
  52.     if hub:getProtocol() == "nmdc" then
  53.         hubname = "dchub://"..string.gsub(hubname,"dchub://","")
  54.     end
  55.     if NicksToMain == 1 then MainOutput(currenthub, "*** User " ..username.. " found in: " ..hubname) end
  56.     if NicksToPM == 1 then PmOutput(currenthub, "*** User " ..username.. " found in: " ..hubname) end
  57.     if NicksToHubs == 1 then MainOutput(hub, "*** User " ..username.. " found in here.") end
  58. end
  59.  
  60. NickCmds = {
  61.     sui = function(hub, msg)        -- Show userinfo
  62.         local _,_,nick = string.find(msg, "%S+ (%S+)")
  63.         local currenthub = hub
  64.         if nick then
  65.             if hub._users and hub._users[nick] then
  66.                 user = hub._users[nick]
  67.                 MainOutput(currenthub, "*** User info for: "..nick..":"..
  68.                     "\n\tDescription: "..user.getDesc()..
  69.                     "\n\tTag: "..user.getTag()..
  70.                     "\n\tConnection: "..user.getConn()..
  71.                     "\n\tFlag: "..user.getFlag()..
  72.                     "\n\tEmail: "..user.getFlag()..
  73.                     "\n\tShare: "..user.getShare()
  74.                 )
  75.             else
  76.                 DC():PrintDebug("Nick not found in this hub")
  77.             end
  78.         else
  79.             DC():PrintDebug("No nick specified")
  80.         end
  81.     end,
  82.     findshare = function(hub, msg)
  83.         if string.lower(string.sub(msg, 1, 10)) == "/findshare" then
  84.             currenthub = hub
  85.             DC():PrintDebug("Find Share started........")
  86.             local _,_,share = string.find(msg, "%S+ (%S+)")
  87.             share = string.gsub(share, "[%.%sB]", "")
  88.             if tonumber(share) then
  89.                 MainOutput(currenthub, "*** Searching for a sharesize of '"  ..share.. "' in all connected hubs...")
  90.                    
  91.                 counter = 0
  92.                 for _,hub in pairs(dcpp:getHubs()) do
  93.                     DC():PrintDebug("*Hub: " ..hub:getAddress().. " is being checked...")
  94.                     for k,l in pairs(hub._users) do
  95.                         if hub._users[k]._share and hub._users[k]._share == share then
  96.                             NickOutput(hub._users[k]._nick, hub)
  97.                             counter = counter + 1
  98.                         elseif  type(k) == "table" then
  99.                             for i,m in pairs(k) do
  100.                                 if hub.users[i]._share and hub._users[i]._share == share then
  101.                                     NickOutput(i, hub)
  102.                                     counter = counter + 1
  103.                                 end
  104.                             end
  105.                         end
  106.                     end
  107.                 end
  108.  
  109.                 MainOutput(currenthub, "*** Found " ..counter.. " users with a sharesize of: '"  ..share.. "'")
  110.                 if NicksToMain == 0 then MainOutput(currenthub, "*** Check pm or hubs for results") end
  111.                 if NicksToPM == 1 then PmOutput(currenthub, "*** Found " ..counter.. " users containing: '"  ..share.. "'") end
  112.  
  113.                 DC():PrintDebug("Find sharesize finished.")
  114.             else
  115.                 MainOutput(currenthub, "*** Wrong sharesize, use a number")
  116.             end
  117.         end
  118.     end,
  119.     findnick = function(hub, msg)
  120.         if string.lower(string.sub(msg, 1, 9)) == "/findnick" then
  121.             currenthub = hub
  122.             DC():PrintDebug("Find Nick started........")
  123.  
  124.             nick = string.lower(string.sub (msg, 11))
  125.  
  126.             MainOutput(currenthub, "*** Searching for '"  ..nick.. "' in all connected hubs...")
  127.                
  128.             counter = 0
  129.             for _,hub in pairs(dcpp:getHubs()) do
  130.                 DC():PrintDebug("*Hub: " ..hub:getAddress().. " is being checked...")
  131.                 for k,l in pairs(hub._users) do
  132.                     if string.find(string.lower(hub._users[k]._nick), string.lower(nick)) then                          -- if ADC-hub
  133.                         NickOutput(hub._users[k]._nick, hub)
  134.                         counter = counter + 1
  135.                     elseif type(k) == "string" then
  136.                         if string.find(string.lower(k), string.lower(nick)) then
  137.                             NickOutput(k, hub)
  138.                             counter = counter + 1
  139.                         end
  140.                     elseif  type(k) == "table" then
  141.                         for i,m in pairs(k) do
  142.                             if string.find(string.lower(i), string.lower(nick)) then
  143.                                 NickOutput(i, hub)
  144.                                 counter = counter + 1
  145.                             end
  146.                         end
  147.                     end
  148.                 end
  149.             end
  150.  
  151.             MainOutput(currenthub, "*** Found " ..counter.. " users containing: '"  ..nick.. "'")
  152.             if NicksToMain == 0 then MainOutput(currenthub, "*** Check pm or hubs for results") end
  153.             if NicksToPM == 1 then PmOutput(currenthub, "*** Found " ..counter.. " users containing: '"  ..nick.. "'") end
  154.  
  155.             DC():PrintDebug("Find Nick finished.")
  156.         end
  157.     end,
  158.     findcid = function(hub, msg)
  159.         if string.lower(string.sub(msg, 1, 8)) == "/findcid" then
  160.             DC():PrintDebug("Find CID started........")
  161.  
  162.             currenthub = hub
  163.             local cid = string.sub (msg, 10)
  164.             local counter = 0
  165.  
  166.             MainOutput(currenthub, "*** Searching for CID: "  ..cid.. " in all connected hubs...")
  167.  
  168.             for _,hub in pairs(dcpp:getHubs()) do
  169.                 if hub:getProtocol() == "adc" then
  170.                     DC():PrintDebug("*Hub: " ..hub:getAddress().. " is being checked...")
  171.    
  172.                     for sid,user in pairs(hub._users) do
  173.                         if user:getCid() == cid then
  174.                             NickOutput(user:getNick(), hub)
  175.                             counter = counter + 1
  176.                         end
  177.                     end
  178.                 end
  179.             end
  180.  
  181.             MainOutput(currenthub, "*** Found " ..counter.. " users containing: '"  ..cid.. "'")
  182.             if NicksToMain == 0 then MainOutput(currenthub, "*** Check pm or hubs for results") end
  183.             if NicksToPM == 1 then PmOutput(currenthub, "*** Found " ..counter.. " users with CID: "  ..cid.. "'") end
  184.  
  185.             DC():PrintDebug("Find CID finished.")
  186.         end
  187.     end,
  188. }
  189.  
  190. AdcEscape = function(msg, inverse)
  191.     msg = string.gsub(msg, "\r", "")
  192.     local ret = ""
  193.     if inverse then
  194.         local replacetable = {}
  195.         replacetable["\\\\"] = [[\]]
  196.         replacetable["\\s"] = [[ ]]
  197.         replacetable["\\n"] = "\n"
  198.         local skip = false
  199.         for k = 1, string.len(msg) do
  200.             if skip then
  201.                 skip = false
  202.             else
  203.                 local c = string.sub( msg, k, k + 1)
  204.                 if replacetable[c] then
  205.                     ret = ret .. replacetable[c]
  206.                     skip = true
  207.                 else
  208.                     ret = ret .. string.sub(c, 1, 1)
  209.                 end
  210.             end
  211.         end
  212.     else
  213.         local replacetable = {}
  214.         replacetable["\\"] = [[\\]]
  215.         replacetable[" "] = [[\s]]
  216.         replacetable["\n"] = [[\n]]
  217.  
  218.         for k = 1, string.len(msg) do
  219.             local c = string.sub( msg, k, k)
  220.             if replacetable[c] then
  221.                 ret = ret .. replacetable[c]
  222.             else
  223.                 ret = ret .. c
  224.             end
  225.         end
  226.     end
  227.     return ret
  228. end
  229.  
  230. DC():PrintDebug( "  ** Loaded findnick.lua by FlipFlop **")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement