Advertisement
PersonsadminTeam

Emoji-Chat

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