Javascript support in milliways
Changes to mwscript
- all places that accept a mwscript function name now also accept a javascript one, e.g. bind, event, alias, etc.
- all file load functions support jscript files with a .js extention
- all file load functions support http/https urls
Language extensions
Properties
- whoami - contains your username
Methods
- print(string) - output text to the user
- exec(string) - execute a talker command
- say(string) - send text to the channel
- dbquery(filename, query) - execute sql statement query on sqlite database file filename
- wholist() - returns array of who data
- beep(n) - beeps n times (or 1 if n is not specified)
- input(prompt) - requests a line of input from the user. If prompt is not specified then the default prompt of > is used
- bind(bind, function_name) - allows you to set up a script bind
- unbind(bind, function_name) - deletes specified script bind if it existed
- termsize() - returns an object with properties width and height specifying the dimensions of the users terminal.
- ipc(user, message) - sends an ipc message to user
- rpc(user, type, message) - sends an rpc message to user
- urlget(uri) - makes a http GET request to the given uri and returns the body as a string
Database
The dbquery function takes the filename of an sqlite database to access, and an sql query to execute. it returns ab object with the following properties:
- db_error - if an error occured opening/creating the database then this will be non-zero
- query_error - if an error occured with your database query then this will be non-zero
- error_string - a string describing the error that occured or "No Error" if no error occured
- column_names - an array of strings with the column name for each column in the query result
- data - an array containing one array for each row of result, with those arrays containing the columns in order
who list
The wholist() function returns an array with one entry per user, the entry is an object with the following properties
- username - the users username
- room - the users current room number
- idle - the users idle time in seconds
- chatmodes - a string defining the users current chatmodes
- protection_level - how heavily the user is currently protected
- protection_power - which level of protected users the user can attack
- chatprivs - a string defining the users current chatprivs
Events
When a function is called as the result of an event handler then the functions arguments are:
- event type
- user that caused the event
- full text
- text without preamble
If any function bound to handle an event returns 'false' then you get the equivalent of 'output off' in mwscript (the default output of mw is supressed allowing your scripts to produce their own output to events)
If a function was called from the command line then the arguments are those given on the command line
References
See also