1. 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!

Dismiss Notice
This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Live Web Chat written in Skript

Discussion in 'Snippets' started by Pikachu, Sep 30, 2017.

  1. Pikachu

    Moderator Supporter Addon Developer

    Joined:
    Jan 25, 2017
    Messages:
    871
    Likes Received:
    139
    Medals:
    Code (Skript):
    1. function htmlEsc(html: string) :: string:
    2.   return "%{HtmlEscapers}.htmlEscaper().escape({_html})%"
    3. on script load:
    4.   start web server on port 80 if not already started
    5.   import "com.google.common.html.HtmlEscapers"
    6. function getList(string: string) :: string:
    7.   return "<li style=""list-style-type: none;"">%{_string}%</li>"
    8. on web request:
    9.   if requested path is "/" or "/action_page.php":
    10.     send back header "Content-type" with value "text/html"
    11.     !! <center><b>Skript Chat Room</b></center>
    12.     !! <form action="/action_page.php">
    13.     !! Username: <br>
    14.     !! <input type="text" name="author" placeholder="Anon"><br>
    15.     !! <input type="text" name="message" placeholder="Message"><br>
    16.     !! <input type="submit" value="Send">
    17.     !! </form>
    18.     !! <iframe id="chat" src="/chat" width="100%%" height="100%%"></iframe>
    19.     !! <script>setInterval(function(){document.getElementById('chat').contentWindow.location.reload(true);}, 2000)</script>
    20.     send back multiline string
    21.     stop request
    22. on web request with path "/chat":
    23.   send back header "Content-type" with value "text/html"
    24.   send back join "<ul style=""list-style-type: none;"">", {chat::*} and "</ul>" with ""
    25.   stop request
    26. on web request:
    27.   set {_post::*} to post vars
    28.   if {_post::*} is set:
    29.     if {_post::message} is set:
    30.       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::*}
    See it in action:
    https://gfycat.com/SecondhandEarlyChafer
     
    • Friendly Friendly x 1
  2. GrimEpp

    GrimEpp Member

    Joined:
    Feb 12, 2017
    Messages:
    39
    Likes Received:
    3
  3. medivh

    medivh Member

    Joined:
    Jan 28, 2017
    Messages:
    43
    Likes Received:
    0
    What requeriments?
     
  4. Pikachu

    Moderator Supporter Addon Developer

    Joined:
    Jan 25, 2017
    Messages:
    871
    Likes Received:
    139
    Medals:
    iirc skript-mirror, umbaska 3 and umbaccess
     
  5. medivh

    medivh Member

    Joined:
    Jan 28, 2017
    Messages:
    43
    Likes Received:
    0
    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!
     
  6. Pikachu

    Moderator Supporter Addon Developer

    Joined:
    Jan 25, 2017
    Messages:
    871
    Likes Received:
    139
    Medals:
    You didn't install umbacess correctly
     

Share This Page

Loading...