Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- SUA DATABASE DENTRO DOS [[ ]]
- db = [[
- ]]
- --
- db = db:gsub('\n','¤')
- bot = {}
- bot.brain = {}
- bot.info ={
- name = 'Eshbot',
- genre = 'Male',
- age = '7'}
- loadedBrain = false
- function bot.loadBrain(database)
- count = 0
- for token in string.gmatch(database,'[^¤]+') do
- count = count+1
- bot.brain[count] = {}
- pattern = string.match(token,'<pattern="[^/>]+"/>'):gsub('/>',''):gsub('"',''):gsub("'",''):gsub("<pattern=",'')
- table.insert(bot.brain[count],pattern)
- response = token:match('<response="(.*)"')--:gsub('/>',''):gsub('"',''):gsub("'",'')
- if response:sub(0,1) == '{' then
- response = response:gsub('{',''):gsub('}','')
- response = string.split(response,'/')
- end
- table.insert(bot.brain[count],response)
- end
- print(string.format('[EAI] %s conversations loaded.',count))
- end
- function string.split(str,sep)
- tb = {}
- for token in string.gmatch(str,'[^'..sep..']+') do
- table.insert(tb,token)
- end
- return tb
- end
- accents = {
- ['À'] = 'A', ['Á'] = 'A', ['Â'] = 'A', ['Ã'] = 'A',
- ['Ç'] = 'C',
- ['È'] = 'E', ['É'] = 'E', ['Ê'] = 'E',
- ['Ì'] = 'I', ['Í'] = 'I', ['Î'] = 'I',
- ['Ñ'] = 'N',
- ['Ò'] = 'O', ['Ó'] = 'O', ['Ô'] = 'O', ['Õ'] = 'O',
- ['Ù'] = 'U', ['Ú'] = 'U', ['Û'] = 'U', ['Ü'] = 'U',
- ['&'] = ' E ',
- }
- function string.stripAccents(str)
- str = string.upper(str)
- return accents[str] or str
- end
- function string.removeAccents(str)
- str = string.gsub(str, "(.)", string.stripAccents)
- return str
- end
- function string.title(str)
- return str:sub(0,1):upper()..str:sub(2):lower()
- end
- function math.randomchoice(table)
- return table[math.random(#table)]
- end
- function bot.returnStar(str,tb)
- starsel = tonumber(str:match('<star=[^>]+>'):match('[0-9]+'))
- response = str:gsub('<star=[^>]+>',tb[starsel])
- return response
- end
- function eventChatCommand(player,message)
- star = string.split(message,'%s')
- message = string.removeAccents(message)
- print(message)
- for index,table in pairs(bot.brain) do
- pattern = table[1]:gsub('*','(.*)')
- if string.find(message,pattern) then
- if type(table[2]) == 'table' then
- response = math.randomchoice(table[2])
- else
- response = table[2]
- end
- while response:find("<bot=") do
- info = bot.info
- infosel = response:match('<bot=(.*)>')
- infosel = infosel:sub(2,string.len(infosel)-1)
- response = response:gsub('<bot=(.*)>',info[infosel])
- end
- if response:find('<star=') then
- response = bot.returnStar(response,star)
- end
- response = string.title(response)
- end
- end
- ui.addTextArea(1,string.format('<V>[%s]<N> %s',bot.info.name,response),player,5,380,nil,30,0x422E20,0x120E08,1,true)
- end
- bot.loadBrain(db)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement