Advertisement
Guest User

Untitled

a guest
Mar 24th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. -- set up json array for emojis
  2. local dat = game:HttpGet('https://raw.githubusercontent.com/iamcal/emoji-data/master/emoji.json')
  3. local json = game:getService'HttpService':JSONDecode(dat)
  4.  
  5. -- set variables for hooking
  6. local mt = getrawmetatable(game)
  7. local oldNameCall = mt.__namecall
  8. local oldFireServer = Instance.new('RemoteEvent').FireServer
  9.  
  10. -- return the emoji unicode from a string
  11. function parseEmoji(emoji)
  12. for _,v in next, json do
  13. if (emoji:lower() == v['short_name']) then
  14. return utf8.char(tonumber(v['unified'], 16))
  15. end
  16. end
  17. end
  18.  
  19. -- Lua doesn't have string.split
  20. function split(self, sep)
  21. local sep, fields = sep or ":", {}
  22. local pattern = string.format("([^%s]+)", sep)
  23. self:gsub(pattern, function(c) fields[#fields+1] = c end)
  24. return fields
  25. end
  26.  
  27. -- detect if :emoji: exists
  28. function detectEmoji(str)
  29. for i=1, #str do
  30. if (str:sub(i,i) == ':') then
  31. local substr = str:sub(i+1, #str)
  32. local pos = substr:find(':')
  33. if (pos) then
  34. return pos
  35. end
  36. end
  37. end
  38. return nil
  39. end
  40.  
  41. -- return a new string that formats a string with emojis =D
  42. function parseSemicolon(rawStr)
  43. local tbl = split(rawStr, " ")
  44. local newtbl = {}
  45.  
  46. for i,token in next, tbl do
  47. local pos = detectEmoji(token)
  48. if (pos) then
  49. token = token:sub(2, pos)
  50. token = parseEmoji(token)
  51. end
  52. newtbl[i] = token
  53. end
  54.  
  55. return table.concat(newtbl, ' ')
  56. end
  57.  
  58. -- hook SayMessageRequest to parse emojis =D
  59. mt.__namecall = function(...)
  60. local tbl = {...}
  61. local key = tbl[#tbl]
  62. local obj = tbl[1]
  63.  
  64. if (key == 'FireServer') then
  65. if (tostring(obj) == 'SayMessageRequest') then
  66. -- fireServer(self, message, channel)
  67. return oldFireServer(tbl[1], parseSemicolon(tbl[2]), tbl[3])
  68. end
  69. end
  70. return oldNameCall(...)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement