B1uscr34m

TS3 - Teamspeak - MSGRedirect - init.lua

May 27th, 2015
91
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. require("ts3init")
  2. require("ts3defs")
  3. require("ts3events")
  4. local MSGRedirect = {
  5.     info = {
  6.         MODULE = "MSG Redirect Module",
  7.         MODULESHORT = "MSGR",
  8.         MODULEFOLDER = "MSGRedirect",
  9.         MODULEFILE = "init",
  10.         MODULEEXT = "lua",
  11.         MODULEVERSION = "1.0",
  12.         MODULEAUTHOR = "Bluscream",
  13.         DEBUG = true,
  14.     },
  15.     var = {
  16.         guestChannelGroup = "14",
  17.         ENABLED = false,
  18.         LAST = "0",
  19.     },
  20. }
  21. BadWordArray = { 'hurensohn', 'ddos', 'wichser', 'egal', 'lizard', 'asshole', 'arschloch', 'fick', 'anus', 'scheide', 'vagina', 'fotze', 'schlampe', 'hitler', 'adolf', 'sieg', 'heil' }
  22. LinkArray = { '%://', 'www%.', '%.net', '%.de', '%.com', '%.me', '%.tk' }
  23. oldMSG = ""
  24.  
  25. local function ScriptLog(logMSG)
  26.     if MSGRedirect.info.DEBUG == true then
  27.         local tsCol = { 'Green', 'Black', 'Red', 'Blue' }
  28.         local RANDCOL = ( tsCol[ math.random( #tsCol ) ] )
  29.         local scriptTimestamp = os.date("%x %X")
  30.         ts3.printMessageToCurrentTab("[color=Black][[/color][color="..RANDCOL.."]"..scriptTimestamp.."[/color][color=Black]][/color]> "..MSGRedirect.info.MODULESHORT..": "..logMSG)
  31.         -- ts3.logMessage(logMSG, 4, 0x0002, 1)
  32.         -- debugPrint(logMSG)
  33.         print(logMSG)
  34.     end
  35. end
  36. local function isempty(s)
  37.   return s == nil or s == ''
  38. end
  39. local function urlencode(str)
  40.    if (str) then
  41.       str = string.gsub (str, "\n", "\r\n")
  42.       str = string.gsub (str, "([^%w ])",
  43.          function (c) return string.format ("%%%02X", string.byte(c)) end)
  44.       str = string.gsub (str, " ", "+")
  45.    end
  46.    return str    
  47. end
  48.  
  49. function msgredirect(serverConnectionHandlerID)
  50.     if MSGRedirect.var.ENABLED == true then
  51.         MSGRedirect.var.ENABLED = false
  52.         ts3.printMessageToCurrentTab("MSGRedirect set to \"FALSE\"")
  53.     else
  54.         MSGRedirect.var.ENABLED = true
  55.         ts3.printMessageToCurrentTab("MSGRedirect set to \"TRUE\"")
  56.     end
  57. end
  58.  
  59. function onClientMoveEvent(serverConnectionHandlerID, clientID, oldChannelID, newChannelID, visibility, moveMessage)
  60.     if MSGRedirect.var.ENABLED == true and MSGRedirect.var.LAST ~= clientID then
  61.         local ownID = ts3.getClientID(serverConnectionHandlerID)
  62.         local ownChannelID = ts3.getChannelOfClient(serverConnectionHandlerID, ownID)
  63.         if newChannelID == ownChannelID and clientID ~= ownID then
  64.             local clientServerGroups = ts3.getClientVariableAsString(serverConnectionHandlerID,clientID,34)
  65.             if string.find(clientServerGroups, MSGRedirect.var.guestChannelGroup) then
  66.                 MSGRedirect.var.LAST = clientID
  67.                 local clientName = ts3.getClientVariableAsString(serverConnectionHandlerID,clientID,ts3defs.ClientProperties.CLIENT_NICKNAME)
  68.                 ts3.requestSendPrivateTextMsg(serverConnectionHandlerID, "\n\nHallo [color=green]" .. clientName .. "[/color], du bist hier [color=red]Gast[/color] aber moechtest trozdem im Channel mitschreiben?\n\nDann schreib mir einfach zurueck und ich werde die Nachricht an den Channel weiterleiten.\n\n[color=red]INFO: SPAM ODER SONSTIGER ABUSE WIRD MIT SOFORTIGEM CHANNELBAN UND BLOCK BESTRAFT![/color]", clientID)
  69.             end
  70.         end
  71.     end
  72. end
  73.  
  74. function onTextMessageEvent(serverConnectionHandlerID, targetMode, toID, fromID, fromName, fromUniqueIdentifier, message, ffIgnored)
  75.     local ownID = ts3.getClientID(serverConnectionHandlerID)
  76.     local ownChannelID = ts3.getChannelOfClient(serverConnectionHandlerID, ownID)
  77.     local clientChannelID = ts3.getChannelOfClient(serverConnectionHandlerID, fromID)
  78.     local clientServerGroups = ts3.getClientVariableAsString(serverConnectionHandlerID,fromID,34)
  79.     if MSGRedirect.var.ENABLED == true and ffIgnored == 0 and toID == ownID and clientChannelID == ownChannelID and string.find(clientServerGroups, MSGRedirect.var.guestChannelGroup) then
  80.         lowMessage = string.lower(message)
  81.         if lowMessage ~= oldMSG and string.len(lowMessage) > 1 and string.len(lowMessage) < 850 then
  82.             local clientName = ts3.getClientVariableAsString(serverConnectionHandlerID,fromID,ts3defs.ClientProperties.CLIENT_NICKNAME)
  83.             if string.find (lowMessage, "ts3server:" ) ~= nil then
  84.                 ScriptLog(clientName .. " hat versucht einen TS3Server Link zu versenden.")
  85.             elseif string.find (lowMessage, '%d+%.%d+%.%d+%.%d') ~= nil or string.find (lowMessage, '%w%w%w%w::%w%w%w%w::%w%w%w%w::%w%w%w%w') ~= nil or string.find (lowMessage, '%w%w%w%w:%w%w%w%w:%w%w%w%w:%w%w%w%w:%w%w%w%w:%w%w%w%w:%w%w%w%w:%w%w%w%w') ~= nil then
  86.                 ScriptLog(clientName .. " hat versucht eine IP zu versenden.")
  87.             -- elseif then
  88.                 -- ScriptLog(clientName .. " hat versucht eine IP zu versenden.")
  89.             else
  90.                 local uniqueID = ts3.getClientVariableAsString(serverConnectionHandlerID,fromID,ts3defs.ClientProperties.CLIENT_UNIQUE_IDENTIFIER)
  91.                 local nickNameEncoded = urlencode(clientName)
  92.                 ts3.requestSendChannelTextMsg(serverConnectionHandlerID, "Weitergeleitete Nachricht von [URL=client://" .. fromID .. "/" .. uniqueID .. "~" .. nickNameEncoded .. "]\"" .. clientName .. "\"[/url]: " .. message, clientChannelID)
  93.                 oldMSG = lowMessage
  94.             end
  95.         end
  96.     end
  97. end
  98.  
  99.  
  100.  
  101. local registeredMSGREvents = {
  102.  
  103.         onClientMoveEvent = onClientMoveEvent,
  104.         onTextMessageEvent = onTextMessageEvent
  105.        
  106. }
  107.  
  108. ts3RegisterModule(MSGRedirect.info.MODULE, registeredMSGREvents)
  109. ScriptLog("Loaded "..MSGRedirect.info.MODULE.." v"..MSGRedirect.info.MODULEVERSION.." by "..MSGRedirect.info.MODULEAUTHOR.." from "..ts3.getPluginPath().."lua_plugin/"..MSGRedirect.info.MODULEFOLDER.."/"..MSGRedirect.info.MODULEFILE.."."..MSGRedirect.info.MODULEEXT)
RAW Paste Data