Advertisement
CFDatabase

ChatBot - 12GaugeNick

Jul 26th, 2016
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.04 KB | None | 0 0
  1. --[[
  2.     This script was coded by 12GaugeNick - ROBLOX.
  3.     Anyone who wants to try fixing this. Go for it.
  4.    
  5.     I never could get this fully functioning correctly, if you figure it out; please let me know. I would like to understand how you fixed it.
  6.     It was fun coding this. (Only a couple hours)
  7.     I wish you call luck and have fun!
  8.    
  9.     vvvvvvvvvvvvvvvv
  10.     [Error-Message]:  Check to make sure the hash was encoded correctly with your apiSecret.
  11.     ^^^^^^^^^^^^^^^^  
  12.    
  13.     PHP doc used for the 'web_host'
  14.    
  15.     <html>
  16.         <?php
  17.             $apiSecret = $_GET['key'];
  18.             $message = array(
  19.                 'message' => array(
  20.                     'message' => $_GET['usermessage'],
  21.                     'chatBotID' => $_GET['botid'],
  22.                     'timestamp' => $_GET['timestamp'],
  23.                 ),
  24.                 'user' => array(
  25.                     'firstName' => $_GET['fname'],
  26.                     'lastName' => $_GET['lname'],
  27.                     'gender' => $_GET['gender'], // m or f
  28.                     'externalID' => $_GET['externalid']
  29.                 )
  30.             );
  31.             $messageJSON = json_encode($message);
  32.             $hash = hash_hmac('sha256', $messageJSON, $apiSecret);
  33.             echo $hash
  34.         ?>
  35.     </html>
  36. --]]
  37.  
  38. local api_host      = "http://www.personalityforge.com/api/chat/"
  39. local web_host      = "" -- Removed by 12GaugeNick
  40.  
  41. local Players       = game:GetService("Players")
  42. local Http          = game:GetService("HttpService")
  43. local UrlEncode     = function(...) return Http:UrlEncode(...) end
  44. local JSONEncode    = function(...) return Http:JSONEncode(...) end
  45. local JSONDecode    = function(...) return Http:JSONDecode(...) end
  46. local _GET          = function(...) return Http:GetAsync(...) end
  47. local _POST         = function(...) return Http:PostAsync(...) end
  48.  
  49. local BotId         = 0 -- Removed by 12GaugeNick
  50. local apiKey        = "" -- Removed by 12GaugeNick
  51. local botSecret     = "" -- Removed by 12GaugeNick
  52. local FirstName     = "N" -- Removed by 12GaugeNick
  53. local LastName      = "M"
  54. local Gender        = "m"
  55.  
  56. local UserKeys      = {
  57.     ['12gaugenick'] = "A1";
  58.     ['MessorAdmin'] = "A2";
  59.     ['Player1'] = "A3";
  60.     ['Player'] = "A4";
  61. }
  62.  
  63. local Hash = function(Message, externalId)
  64.     local Url = "?key="..botSecret.."&usermessage="..Message.."&botid="..BotId.."&timestamp="..os.time().."&fname="..FirstName.."&lname="..LastName.."&gender="..Gender.."&externalid="..externalId
  65.     local WebsiteResult = _GET(web_host..Url):sub(10)
  66.     local SubFinder = WebsiteResult:find("</html>")
  67.     local Subbed = WebsiteResult:sub(1,tonumber(SubFinder)-1)
  68.     print(Subbed)
  69.     return Subbed
  70. end
  71.  
  72. ---------------------------------------------------------------------------------
  73. ---------------------------------------------------------------------------------
  74. ---------------------------------------------------------------------------------
  75.  
  76. local CreateMessageJSON = function(BotSpeechRequest, PlayerNameChatted)
  77.     if UserKeys[tostring(PlayerNameChatted)] == nil then
  78.         return false
  79.     end
  80.     local Table = {
  81.         ['message'] = {
  82.             ['message']         = BotSpeechRequest,
  83.             ['chatBotID']       = BotId,
  84.             ['timestamp']       = os.time()
  85.         },
  86.         ['user'] = {
  87.             ['firstName']       = FirstName,
  88.             ['lastName']        = LastName,
  89.             ['gender']          = Gender,
  90.             ['externalID']      = UserKeys[tostring(PlayerNameChatted)]
  91.         }
  92.     }
  93.     return Table
  94. end
  95.  
  96. local Update = function(UserName, Message)
  97.     local ResponceStart = tick()
  98.     local messageJSON = CreateMessageJSON(Message, UserName)
  99.      local message = messageJSON.message['message']
  100.      local chatbotID = messageJSON.message['chatBotID']
  101.      local timestamp = messageJSON.message['timestamp']
  102.      local externalID = messageJSON.user['externalID']
  103.      local firstName = messageJSON.user['firstName']
  104.      local lastName = messageJSON.user['lastName']
  105.      local gender = messageJSON.user['gender']
  106.     local messageJSON = JSONEncode(messageJSON)
  107.      local msgJSON = UrlEncode(messageJSON)
  108.     local HashKey = Hash(message, externalID)
  109.     local Url = api_host.."?apiKey="..apiKey.."&hash="..tostring(HashKey).."&message="..msgJSON
  110.     local Result = JSONDecode( _GET(Url) )
  111.     warn("[Error-Message]: ", Result.errorMessage)
  112.     print("Website responded in "..tostring(ResponceStart-tick()):sub(2,5).." seconds")
  113. end
  114.  
  115. Players.PlayerAdded:connect(function(p)
  116.     p.Chatted:connect(function(m)
  117.         Update(p.Name, m)
  118.     end)
  119. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement