Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
- local tableAccents = {}
- tableAccents["ý"] = "y"
- tableAccents["ÿ"] = "y"
- tableAccents["À"] = "A"
- tableAccents["Á"] = "A"
- tableAccents["Â"] = "A"
- tableAccents["Ã"] = "A"
- tableAccents["Ä"] = "A"
- tableAccents["Ç"] = "C"
- tableAccents["È"] = "E"
- tableAccents["É"] = "E"
- tableAccents["Ê"] = "E"
- tableAccents["Ë"] = "E"
- tableAccents["Ì"] = "I"
- tableAccents["Í"] = "I"
- tableAccents["Î"] = "I"
- tableAccents["Ï"] = "I"
- tableAccents["Ñ"] = "N"
- tableAccents["Ò"] = "O"
- tableAccents["Ó"] = "O"
- tableAccents["Ô"] = "O"
- tableAccents["Õ"] = "O"
- tableAccents["Ö"] = "O"
- tableAccents["Ù"] = "U"
- tableAccents["Ú"] = "U"
- tableAccents["Û"] = "U"
- tableAccents["Ü"] = "U"
- tableAccents["Ý"] = "Y"
- function string.stripAccents(str)
- local normalizedString = ""
- for strChar in string.gmatch(str, "([%z\1-\127\194-\244][\128-\191]*)") do
- if tableAccents[strChar] ~= nil then
- normalizedString = normalizedString..tableAccents[strChar]
- else
- normalizedString = normalizedString..strChar
- end
- end
- return normalizedString:gsub('\W','')
- 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 = message:upper()
- message = string.stripAccents(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