Live Web Chat written in Skript

  • Welcome to skUnity!

    Welcome to skUnity! This is a forum where members of the Skript community can communicate and interact. Skript Resource Creators can post their Resources for all to see and use.

    If you haven't done so already, feel free to join our official Discord server to expand your level of interaction with the comminuty!

    Now, what are you waiting for? Join the community now!

Pikachu

Supporter
Addon Developer
Jan 25, 2017
870
144
43
USA
code_language.skript:
function htmlEsc(html: string) :: string:
  return "%{HtmlEscapers}.htmlEscaper().escape({_html})%"
on script load:
  start web server on port 80 if not already started
  import "com.google.common.html.HtmlEscapers"
function getList(string: string) :: string:
  return "<li style=""list-style-type: none;"">%{_string}%</li>"
on web request:
  if requested path is "/" or "/action_page.php":
    send back header "Content-type" with value "text/html"
    !! <center><b>Skript Chat Room</b></center>
    !! <form action="/action_page.php">
    !! Username: <br>
    !! <input type="text" name="author" placeholder="Anon"><br>
    !! <input type="text" name="message" placeholder="Message"><br>
    !! <input type="submit" value="Send">
    !! </form>
    !! <iframe id="chat" src="/chat" width="100%%" height="100%%"></iframe>
    !! <script>setInterval(function(){document.getElementById('chat').contentWindow.location.reload(true);}, 2000)</script>
    send back multiline string
    stop request
on web request with path "/chat":
  send back header "Content-type" with value "text/html"
  send back join "<ul style=""list-style-type: none;"">", {chat::*} and "</ul>" with ""
  stop request
on web request:
  set {_post::*} to post vars
  if {_post::*} is set:
    if {_post::message} is set:
      add getList("<li style=""list-style-type: none;"">%join ""<"" and ""b>"" with """"%%check [{_post::author} is """"] ? ""Anon"" : htmlEsc({_post::author})%:</b> %htmlEsc({_post::message})%<br>") to {chat::*}
 
Last edited by a moderator:
Error:
[05:03:49 INFO]: [Skript] Reloading login.sk...
[05:03:49 ERROR]: Can't understand this condition/effect: start web server on port 80 if not already started (login.sk, line 705: start web server on port 80 if not already started')
[05:03:49 ERROR]: can't understand this event: 'on web request' (login.sk, line 709: on web request:')
[05:03:49 ERROR]: can't understand this event: 'on web request with path "/chat"' (login.sk, line 723: on web request with path "/chat":')
[05:03:49 ERROR]: can't understand this event: 'on web request' (login.sk, line 727: on web request:')
[05:03:49 INFO]: [Skript] Encountered 4 errors while reloading login.sk!
 
Error:
[05:03:49 INFO]: [Skript] Reloading login.sk...
[05:03:49 ERROR]: Can't understand this condition/effect: start web server on port 80 if not already started (login.sk, line 705: start web server on port 80 if not already started')
[05:03:49 ERROR]: can't understand this event: 'on web request' (login.sk, line 709: on web request:')
[05:03:49 ERROR]: can't understand this event: 'on web request with path "/chat"' (login.sk, line 723: on web request with path "/chat":')
[05:03:49 ERROR]: can't understand this event: 'on web request' (login.sk, line 727: on web request:')
[05:03:49 INFO]: [Skript] Encountered 4 errors while reloading login.sk!
You didn't install umbacess correctly