Creating a script
1. Add the header
Section titled “1. Add the header”Comment lines at the top of a script describe it:
--! name: Display name--! description: One line--! api: 1--! permissions: send, channelsnameanddescriptionare shown in the Script Manager.apiis the SwizzScript API version the script was written for. A script written for a newer API than your build is refused with a clear message.permissionslists what the script needs: any ofsend,channels,notify,storage,aliases.
2. Write handlers
Section titled “2. Write handlers”--! name: Hello--! api: 1--! permissions: sendswizzin.on("message", function(e) if e.text == "!hello" then swizzin.send(e.target, "Hello, " .. e.nick .. "!") endend)3. Save, enable and approve
Section titled “3. Save, enable and approve”- Open Scripts, choose New…, and paste or write your script.
- Save, then turn the script On.
- Read the permissions the panel lists and choose Approve and allow.
- Check the Console for errors.
Keeping data between runs
Section titled “Keeping data between runs”With the storage permission:
local n = (swizzin.data.get("count") or 0) + 1swizzin.data.set("count", n)swizzin.log("run number", n)Values are strings, numbers or booleans. Each script has its own file and cannot read another script’s data. Limits: 64 keys, values up to 4096 characters, 64 KB per script.
Rules to remember
Section titled “Rules to remember”- The top level of a script must finish within 1 second; do work in handlers.
- Each callback must finish within 250 ms.
- A script is stopped after 10 failures in a row.
- Text you send must be a single line of 1 to 2000 characters, and text that looks like an authentication command is refused.