Guest User

EAIML

a guest
Feb 17th, 2015
532
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. db = [[
  3.  
  4. ]]
  5.  
  6. db = db:gsub('\n','¤')
  7. bot = {}
  8. bot.brain = {}
  9.  
  10. bot.info ={
  11. name = 'Eshbot',
  12. genre = 'Male',
  13. age = '7'}
  14.  
  15. loadedBrain = false
  16.  
  17. function bot.loadBrain(database)
  18.     count = 0
  19.     for token in string.gmatch(database,'[^¤]+') do
  20.         count = count+1
  21.         bot.brain[count] = {}
  22.         pattern = string.match(token,'<pattern="[^/>]+"/>'):gsub('/>',''):gsub('"',''):gsub("'",''):gsub("<pattern=",'')
  23.         table.insert(bot.brain[count],pattern)
  24.         response = token:match('<response="(.*)"')--:gsub('/>',''):gsub('"',''):gsub("'",'')
  25.         if response:sub(0,1) == '{' then
  26.             response = response:gsub('{',''):gsub('}','')
  27.             response = string.split(response,'/')
  28.         end
  29.         table.insert(bot.brain[count],response)
  30.     end
  31.     print(string.format('[EAI] %s conversations loaded.',count))
  32. end
  33.  
  34. function string.split(str,sep)
  35.     tb = {}
  36.     for token in string.gmatch(str,'[^'..sep..']+') do
  37.         table.insert(tb,token)
  38.     end
  39.     return tb
  40. end
  41.  
  42. local tableAccents = {}
  43.     tableAccents["ý"] = "y"
  44.     tableAccents["ÿ"] = "y"
  45.     tableAccents["À"] = "A"
  46.     tableAccents["Á"] = "A"
  47.     tableAccents["Â"] = "A"
  48.     tableAccents["Ã"] = "A"
  49.     tableAccents["Ä"] = "A"
  50.     tableAccents["Ç"] = "C"
  51.     tableAccents["È"] = "E"
  52.     tableAccents["É"] = "E"
  53.     tableAccents["Ê"] = "E"
  54.     tableAccents["Ë"] = "E"
  55.     tableAccents["Ì"] = "I"
  56.     tableAccents["Í"] = "I"
  57.     tableAccents["Î"] = "I"
  58.     tableAccents["Ï"] = "I"
  59.     tableAccents["Ñ"] = "N"
  60.     tableAccents["Ò"] = "O"
  61.     tableAccents["Ó"] = "O"
  62.     tableAccents["Ô"] = "O"
  63.     tableAccents["Õ"] = "O"
  64.     tableAccents["Ö"] = "O"
  65.     tableAccents["Ù"] = "U"
  66.     tableAccents["Ú"] = "U"
  67.     tableAccents["Û"] = "U"
  68.     tableAccents["Ü"] = "U"
  69.     tableAccents["Ý"] = "Y"
  70.  
  71. function string.stripAccents(str)
  72.     local normalizedString = ""
  73.     for strChar in string.gmatch(str, "([%z\1-\127\194-\244][\128-\191]*)") do
  74.         if tableAccents[strChar] ~= nil then
  75.             normalizedString = normalizedString..tableAccents[strChar]
  76.         else
  77.             normalizedString = normalizedString..strChar
  78.         end
  79.     end
  80.   return normalizedString:gsub('\W','')
  81. end
  82.  
  83. function string.title(str)
  84. return str:sub(0,1):upper()..str:sub(2):lower()
  85. end
  86.  
  87. function math.randomchoice(table)
  88. return table[math.random(#table)]
  89. end
  90.  
  91. function bot.returnStar(str,tb)
  92.     starsel = tonumber(str:match('<star=[^>]+>'):match('[0-9]+'))
  93.     response = str:gsub('<star=[^>]+>',tb[starsel])
  94.     return response
  95. end
  96.  
  97. function eventChatCommand(player,message)
  98. star = string.split(message,'%s')
  99. message = message:upper()
  100. message = string.stripAccents(message)
  101.     for index,table in pairs(bot.brain) do
  102.         pattern = table[1]:gsub('*','(.*)')
  103.         if string.find(message,pattern) then
  104.             if type(table[2]) == 'table' then
  105.                 response = math.randomchoice(table[2])
  106.             else
  107.                 response = table[2]
  108.             end
  109.             while response:find("<bot=") do
  110.                 info = bot.info
  111.                 infosel = response:match('<bot=(.*)>')
  112.                 infosel = infosel:sub(2,string.len(infosel)-1)
  113.                 response = response:gsub('<bot=(.*)>',info[infosel])
  114.             end
  115.  
  116.             if response:find('<star=') then
  117.                 response = bot.returnStar(response,star)
  118.             end
  119.             response = string.title(response)
  120.         end
  121.     end
  122. ui.addTextArea(1,string.format('<V>[%s]<N> %s',bot.info.name,response),player,5,380,nil,30,0x422E20,0x120E08,1,true)
  123. end
  124.  
  125. bot.loadBrain(db)
Advertisement
Add Comment
Please, Sign In to add comment