Advertisement
Eshkation-

EAIML 0.2

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