{% extends "base.html" %}

{% block title %}{% if is_new %}new script{% else %}{{ script_name }}{% endif %} - irc.bot{% endblock %}

{% block content %}
<div class="content">
  <h1>{% if is_new %}new script{% else %}edit: {{ script_name }}{% endif %}</h1>
  <form method="post" action="{% if is_new %}/{{ bot_id }}/scripts/create{% else %}/{{ bot_id }}/scripts/{{ script_id }}/update{% endif %}" class="bot-form">
    <label>name</label>
    <input type="text" name="name" value="{{ script_name }}" class="input" required>

    {% if !is_new %}
    <label class="checkbox-label">
      <input type="checkbox" name="enabled" {% if enabled %}checked{% endif %}> enabled
    </label>
    {% endif %}

    <label>lua source</label>
    <textarea name="source" class="editor" rows="25" spellcheck="false">{{ source }}</textarea>

    <div class="form-actions">
      <button type="submit" class="btn-fill">{% if is_new %}create script{% else %}save script{% endif %}</button>
      <a href="/{{ bot_id }}" class="btn-outline">back</a>
    </div>
  </form>

  <div class="api-ref">
    <h3>api reference</h3>
    <pre>
irc.send(channel, text)  -- send a message
irc.join(channel)        -- join a channel
irc.part(channel)        -- leave a channel
irc.nick(new_nick)       -- change nick

kv.get(key)              -- get a stored value
kv.set(key, value)       -- store a value
kv.delete(key)           -- delete a value
kv.list()                -- list all key-value pairs

log.info(msg)            -- log info message
log.warn(msg)            -- log warning
log.error(msg)           -- log error

http.get(url)            -- HTTP GET (10 req/min limit)

-- event handlers:
function on_message(nick, channel, text) end
function on_join(nick, channel) end
function on_part(nick, channel, reason) end
function on_kick(nick, channel, target, reason) end
function on_nick(old_nick, new_nick) end
function on_notice(nick, target, text) end</pre>
  </div>
</div>
{% endblock %}
