Plugin teamspeak3[Lua]

posted on 10 Jul 2013 05:44 by s4m3l0 in Code directory Tech, Knowledge, Diary
local function onTextMessageEvent(serverConnectionHandlerID, targetMode, toID, fromID, fromName, fromUniqueIdentifier, message, ffIgnored)
  if ((message:match('http')) or (message:match('www'))) then
    if message:match('youtube.com') or message:match('youtu.be') then
      url = message:match("v=([0-9a-zA-Z_-]+)")
      if not url then
        url = message:match("youtu\.be\/([0-9a-zA-Z_-]+)")
      end
      id_url = url:sub(0,11)
      handle = io.popen("curl 'https://www.googleapis.com/youtube/v3/videos?id='".. id_url .."'&key=yourkey&fields=items%28snippet%28title%29%29&part=snippet'")
      content = handle:read("*a")
      handle:close()
      title = content:match("\"title\":%s\"(.*)\"")
      if title then
        ts3.requestSendChannelTextMsg(serverConnectionHandlerID,"[b][color=red][Title] => [\/color][\/b][color=green]".. title .."[\/color]",1)
      end
    elseif message:match('facebook.com') then
      check = message:match('Read more')
      if not check then
        url = message:match("fbid=(%d+)")
        if not url then
          url = message:match('\.akamaihd\.net\/[a-z0-9A-Z-]-\/%d-_(%d+)_%d-_n\.jpg')
          if not url then
            url = message:match("v=(%d+)")
          end
        end
        if message:match('v=%d+') then
          handle = io.popen("\/usr\/bin\/printf \"$(curl 'https://graph.facebook.com/".. url .."?access_token=youtoken&fields=name,from,description')\"")
        else
          handle = io.popen("\/usr\/bin\/printf \"$(curl 'https://graph.facebook.com/".. url .."?access_token=youtoken&fields=name,from')\"")
        end
        content = handle:read("*a")
        handle:close()
        title = content:match("\"name\":\"(.+)\",\"from\"")
        desc = content:match("\"description\":\"(.+)\",\"id")
        if title then
          if title:len() >= 200 then
            title = title:sub(0,200)
            page = content:match("\"id\":\"%d-\",\"category\":\".-\",\"name\":\"(.+)\"%},\"id")
            ts3.requestSendChannelTextMsg(serverConnectionHandlerID,"[b][color=red][Page - ".. page .."] => [\/color][\/b][color=green]".. title .."[url=https://www.facebook.com/photo.php?fbid=".. url .."][Read more][\/url][\/color]",1)
          else
            page = content:match("\"id\":\"%d-\",\"category\":\".-\",\"name\":\"(.-)\"%},\"id")
            ts3.requestSendChannelTextMsg(serverConnectionHandlerID,"[b][color=red][Page - ".. page .."] => [\/color][\/b][color=green]".. title .."[\/color]",1)
          end
        elseif desc then
          if desc:len() >= 200 then
            desc = desc:sub(0,200)
            page = content:match("\"id\":\"%d-\",\"category\":\".-\",\"name\":\"(.+)\"%},\"description")
            ts3.requestSendChannelTextMsg(serverConnectionHandlerID,"[b][color=red][Page - ".. page .."] => [\/color][\/b][color=green]".. desc .."[url=https://www.facebook.com/photo.php?fbid=".. url .."][Read more][\/url][\/color]",1)
          else
            page = content:match("\"id\":\"%d-\",\"category\":\".-\",\"name\":\"(.+)\"%},\"description")
            ts3.requestSendChannelTextMsg(serverConnectionHandlerID,"[b][color=red][Page - ".. page .."] => [\/color][\/b][color=green]".. desc .."[\/color]",1)
          end
        else
          page = content:match("\"id\":\"%d-\",\"category\":\".-\",\"name\":\"(.-)\"")
          ts3.requestSendChannelTextMsg(serverConnectionHandlerID,"[b][color=red][Page - ".. page .."] [\/color][\/b]",1)
        end
      end
    elseif message:match('pantip.com') then
      url = message:match("\/topic\/(%d+)")
      id_url = url:sub(0,8)
      handle = io.popen("curl 'http://pantip.com/topic/".. id_url .."'")
      content = handle:read("*a")
      handle:close()
      title = content:match("(.-)%s%-%sPantip<\/title>")
      if title then
        title = unescape(title)
        ts3.requestSendChannelTextMsg(serverConnectionHandlerID,"[b][color=red][Title] => [\/color][\/b][color=green]".. title .."[\/color]",1)
      end
    elseif message:match('mediafire.com') then
      url = message:match("\/download\/%??([a-z0-9]+)")
      id_url = url:sub(0,15)
      handle = io.popen("curl 'http://www.mediafire.com/download/".. id_url .."'")
      content = handle:read("*a")
      handle:close()
      title = content:match("(.*)<\/title>")
      if title then
        ts3.requestSendChannelTextMsg(serverConnectionHandlerID,"[b][color=red][Title] => [\/color][\/b][color=green]".. title .."[\/color]",1)
      end
    end
  end
  return
end
เป็น script plugin สำหรับ ts3 ครับ เอาไว้โชว์ title ของเวบใน ts3 ครับ

edit @ 15 Jul 2013 03:09:32 by s4m3l0

Comment

Comment:

Tweet