Upgrade to our commercial service Bot Libre for Business for only $4.99 per month
FAQ

What classes are supported in Self

by admin posted Nov 11 2016, 13:29

Bot Libre's scripting language Self emulates JavaScript, with a few extra enhancements such as states, patterns, and templates.

Self includes several class for useful operations that you can use in your scripts.

For an updated list of class and functions see, User Manual - Self

Some of Self's classes and functions include:

  • Object
    • add(element) - add the element to an array or set
    • add(relationship, object) - add the relationship to the object
    • toString() - convert the object to a string
    • getId() - return the object's id
  • String
    • charAt(index) - return the character at the index (starting at 0)
    • concat(left, right) - concatenate the two string together
    • endsWith(suffix) - returns true if the string has the suffix
    • startsWith(prefix) - returns true if the string has the prefix
    • includes(substring) - returns true if the string contains the other string
    • indexOf(substring) - returns the index of the substring (starting at 0)
    • lastIndexOf(substring) - returns the last index of the substring (starting at 0)
    • length() - returns the size of the string
    • size() - returns the size of the string
    • replace(old, new) - replace the old substring with the new substring
    • substring(start, end) - returns the substring (starting at 0)
    • toLowerCase() - returns the string as lower case
    • toUpperCase() - returns the string as upper case
    • toNumber() - converts the string to a number or null
    • toSymbol() - converts the string to a unique symbol
    • trim() - removes whitespace from the start and end of the string
  • Utils
    • denormalize(text)
    • normalize(text)
    • explode(text)
    • gender(text)
    • person(text)
    • person2(text)
    • program()
    • size()
    • version()
    • id()
  • Date
    • date() - current Date object
    • date(text) - convert the text or Timestamp to a Date
    • time() - current Time object
    • time(text) - convert the text or Timestamp to a Time
    • timestamp() - current Timestamp object
    • timestamp(text) - convert the text or Date to a Timestamp
    • any(text) - parse any date/time format
    • add(date, part, time) - add the date value
    • get(date, part) - return the date part
    • set(date, part, value) - set the date part
    • interval(style, from, to) - computer the date/time interval
    • interval(style, from, to, format) - computer the date/time interval
    • getTimeZone() - return the default time zone
    • getTimeZone(zone) - return the time zone object based on its timezone code i.e. "GMT", "GMT-5", "PST", "America/Los_Angeles"
    • setTimeZone(date, timezone) - set the dates time zone using a timezone code i.e. "GMT", "GMT-5", "PST", "America/Los_Angeles"
    • printAIMLDate(date, format) - print the date using the AIML format
    • printDate(date, format) - print the date using Java SimpleDateFormat format
  • Math
    • add(x, y)
    • subtract(x, y)
    • multiply(x, y)
    • divide(x, y)
    • abs(x)
    • floor(x)
    • ceil(x)
    • power(x, y)
    • power(x, y)
    • power(x, y)
    • round(x, y)
    • log(x)
    • ln(x)
    • sin(x)
    • asin(x)
    • cos(x)
    • acos(x)
    • tan(x)
    • tanh(x)
    • min(x, y)
    • max(x, y)
  • Http
    • toJSON(object) - convert an object to JSON text
    • toXML(object) - convert an object to XML text
    • encode(text) - URL encode the text
    • requestJSON(url) - fetch the JSON response
    • requestJSON(attribute, url) - fetch the JSON response
    • requestJSON(attribute, url, headers) - fetch the JSON response, passing custom headers as JSON object
    • requestJSONAuth(attribute, url, user, password) - call authenticated API and fetch the JSON response
    • requestXML(url) - fetch the XML response
    • requestXML(url, xpath) - fetch the XML response
    • requestXML(url, xpath, headers) - fetch the XML response, passing custom headers as JSON object
    • requestXMLAuth(url, user, password, xpath) - call authenticated API and fetch the XML response
    • requestHTML(url, xpath) - scrape the HTML page
    • requestHTML(url, xpath, format) - scrape the HTML page, return #text, #array, #html, or #object
    • requestHTML(url, xpath, format, subformat) - scrape the HTML page, return #array of #text, #html, or #object
    • requestCSV(url) - parse the CSV file
    • requestText(url) - return the raw text data
    • requestText(url, headers) - return the raw text data, passing custom headers as JSON object
    • rss(url) - fetch the last RSS feed
    • rssFeed(url) - fetch the entire RSS feed
    • postJSON(url, object) - post the JSON object to the URL
    • postJSONAuth(url, user, password, object) - post the JSON object to the URL
    • postXML(url, object) - POST the XML object to the URL
    • postXML(url, object, xpath) - POST the XML object to the URL
    • postXML(url, user, password, object, xpath) - post the XML object to the URL
    • postHTML(url, params, xpath) - post the HTML form parameters to the URL
    • putJSON(object) - PUT the JSON object to the URL
    • delete(url) - send an HTTP DELETE to the URL
  • JSON
    • parse(text) - parse an object from JSON text
    • stringify(object) - convert an object to JSON text
  • Language
    • word(word...) - create a new compound word from the words
    • sentence(word...) - create a new sentence from the words
    • define(word, meaning) - define to word means the object
    • details(object) - print a detailed bullet text for an object
    • learn(question, response) - learn the new response
    • learn(question, response, topic) - learn the new response
    • synthesize() - create an new sentence using the bot's grammar
    • synthesize(sentence) - create an new sentence modeled after the sentence using the bot's grammar
    • randomSynthesize() - create an new sentence using the bot's grammar
    • randomSynthesize(sentence) - create an new sentence modeled after the sentence using the bot's grammar
    • getLastInput(conversation, speaker) - get the last input from the conversation for the speaker
    • getLastInput(conversation, speaker, index) - get the last nth input from the conversation for the speaker
    • getLastInput(conversation, speaker, index, part) - get the last nth input from the conversation for the speaker
    • allowCorrection(speaker) - return if this user is an admin or allowed to correct the bot
  • Facebook
    • post(message) - post to the bot's Facebook page
    • postComment(comment, postid) - post to the bot's Facebook page
    • sendMessage(message, userid) - send a message to a user
  • Twitter
    • tweet(message) - tweet to the bot's Twitter account
    • sendMessage(message, userid) - send a direct message to a user
  • Telegram
    • post(message) - post to the bot's Telegram channel
    • sendMessage(message, userid) - send a message to a user
  • Slack
  • Email
    • email(address, subject, message)
  • Twilio
    • sms(number, message)
  • WikiData
    • define(word)
    • details(word)
    • discover(word)
    • search(filter, word)
  • Wiktionary
    • define(word)
  • GoogleCalendar
    • deleteEvent(event)
    • deleteEvent(calendar, event)
    • getEvents(from, to)
    • getEvents(calendar, from, to)
    • insertEvent(event)
    • insertEvent(calendar, event)
  • Vision
    • loadImage(url) - load the image into the bot's memory
    • matchImage(url, tag, error) - search for the closest matching image for the tag
  • Context
    • push(object) - push the object to the current context stack
    • top() - return the top of the context stack
    • top(index) - return the nth top of the context stack
    • search(match) - search the context stack for a matching object
  • Avatar
    • setAction(action) - set the avatar's action
    • setPose(pose) - set the avatar's pose
    • setCommand(command) - set a JSON command object
  • Mind
  • Memory
  • find(id) - find the object by its id
  • findInstances(class) - return all instances of a class
  • findInstances(class, date) - return all instances of a class created after the date
  • findReferences(object) - return all objects that have a relationship to the object
  • findReferencesBy(object, relationship) - return all objects that have the relationship to the object
  • Mood
    • setEmotion(emotion, value) - set the value of the emotion (between -1.0 and +1.0)
  • Awareness

For an updated list of class and functions see, User Manual - Self


Id: 14527502
Tags: scripting, self, faq, classes
Posted: Nov 11 2016, 13:29
Updated: Sep 6 2018, 15:27
Replies: 0
Views: 9889, today: 3, week: 6, month: 134
0 0 0.0/5