diff options
Diffstat (limited to 'web')
| -rw-r--r-- | web/Gemfile | 9 | ||||
| -rw-r--r-- | web/Gemfile.lock | 48 | ||||
| -rw-r--r-- | web/config.ru | 2 | ||||
| -rw-r--r-- | web/public/header.png | bin | 0 -> 1213722 bytes | |||
| -rw-r--r-- | web/views/index.haml | 24 | ||||
| -rw-r--r-- | web/views/style.scss | 55 | ||||
| -rw-r--r-- | web/web.rb | 44 |
7 files changed, 182 insertions, 0 deletions
| diff --git a/web/Gemfile b/web/Gemfile new file mode 100644 index 0000000..c56bd91 --- /dev/null +++ b/web/Gemfile | |||
| @@ -0,0 +1,9 @@ | |||
| 1 | source "https://rubygems.org" | ||
| 2 | |||
| 3 | gem "haml" | ||
| 4 | gem "puma" | ||
| 5 | gem "rack-cache" | ||
| 6 | gem "sassc" | ||
| 7 | gem "sequel" | ||
| 8 | gem "sinatra" | ||
| 9 | gem "sqlite3" | ||
| diff --git a/web/Gemfile.lock b/web/Gemfile.lock new file mode 100644 index 0000000..9869d49 --- /dev/null +++ b/web/Gemfile.lock | |||
| @@ -0,0 +1,48 @@ | |||
| 1 | GEM | ||
| 2 | remote: https://rubygems.org/ | ||
| 3 | specs: | ||
| 4 | bigdecimal (3.1.4) | ||
| 5 | ffi (1.16.3) | ||
| 6 | haml (6.2.3) | ||
| 7 | temple (>= 0.8.2) | ||
| 8 | thor | ||
| 9 | tilt | ||
| 10 | mustermann (3.0.0) | ||
| 11 | ruby2_keywords (~> 0.0.1) | ||
| 12 | nio4r (2.6.1) | ||
| 13 | puma (6.4.0) | ||
| 14 | nio4r (~> 2.0) | ||
| 15 | rack (2.2.8) | ||
| 16 | rack-cache (1.14.0) | ||
| 17 | rack (>= 0.4) | ||
| 18 | rack-protection (3.1.0) | ||
| 19 | rack (~> 2.2, >= 2.2.4) | ||
| 20 | ruby2_keywords (0.0.5) | ||
| 21 | sassc (2.4.0) | ||
| 22 | ffi (~> 1.9) | ||
| 23 | sequel (5.74.0) | ||
| 24 | bigdecimal | ||
| 25 | sinatra (3.1.0) | ||
| 26 | mustermann (~> 3.0) | ||
| 27 | rack (~> 2.2, >= 2.2.4) | ||
| 28 | rack-protection (= 3.1.0) | ||
| 29 | tilt (~> 2.0) | ||
| 30 | sqlite3 (1.6.9-x86_64-darwin) | ||
| 31 | temple (0.10.3) | ||
| 32 | thor (1.3.0) | ||
| 33 | tilt (2.3.0) | ||
| 34 | |||
| 35 | PLATFORMS | ||
| 36 | x86_64-darwin-22 | ||
| 37 | |||
| 38 | DEPENDENCIES | ||
| 39 | haml | ||
| 40 | puma | ||
| 41 | rack-cache | ||
| 42 | sassc | ||
| 43 | sequel | ||
| 44 | sinatra | ||
| 45 | sqlite3 | ||
| 46 | |||
| 47 | BUNDLED WITH | ||
| 48 | 2.4.21 | ||
| diff --git a/web/config.ru b/web/config.ru new file mode 100644 index 0000000..9dd12d3 --- /dev/null +++ b/web/config.ru | |||
| @@ -0,0 +1,2 @@ | |||
| 1 | require './web' | ||
| 2 | run Sinatra::Application | ||
| diff --git a/web/public/header.png b/web/public/header.png new file mode 100644 index 0000000..9384865 --- /dev/null +++ b/web/public/header.png | |||
| Binary files differ | |||
| diff --git a/web/views/index.haml b/web/views/index.haml new file mode 100644 index 0000000..186dd40 --- /dev/null +++ b/web/views/index.haml | |||
| @@ -0,0 +1,24 @@ | |||
| 1 | !!! 5 | ||
| 2 | %html | ||
| 3 | %head | ||
| 4 | %title LINGO Bot Scoreboard | ||
| 5 | %link{ rel: "stylesheet", href: "style.css", type: "text/css"} | ||
| 6 | %body | ||
| 7 | #header | ||
| 8 | %img{ src: "header.png" } | ||
| 9 | #content | ||
| 10 | %h2 Bot Puzzles Scoreboard | ||
| 11 | %table#scores | ||
| 12 | %tr.scores-header | ||
| 13 | %th | ||
| 14 | %th{colspan: 2} Player | ||
| 15 | %th Score | ||
| 16 | - row_cycle = ["even", "odd"].cycle | ||
| 17 | - @scores.each_with_index do |score,index| | ||
| 18 | %tr{class: row_cycle.next} | ||
| 19 | %td.score-index #{index+1}. | ||
| 20 | %td.score-pfp | ||
| 21 | - if !score.avatar_url.nil? | ||
| 22 | %img{ src: score.avatar_url } | ||
| 23 | %td.score-name= score.username | ||
| 24 | %td.score-value= score.score | ||
| diff --git a/web/views/style.scss b/web/views/style.scss new file mode 100644 index 0000000..a65cd94 --- /dev/null +++ b/web/views/style.scss | |||
| @@ -0,0 +1,55 @@ | |||
| 1 | body { | ||
| 2 | background-color: black; | ||
| 3 | color: white; | ||
| 4 | font-family: sans-serif; | ||
| 5 | } | ||
| 6 | |||
| 7 | #header { | ||
| 8 | width: 100%; | ||
| 9 | |||
| 10 | img { | ||
| 11 | max-width: 80%; | ||
| 12 | margin: 0 auto; | ||
| 13 | display: block; | ||
| 14 | } | ||
| 15 | } | ||
| 16 | |||
| 17 | h2 { | ||
| 18 | text-align: center; | ||
| 19 | } | ||
| 20 | |||
| 21 | #scores { | ||
| 22 | margin: 0 auto; | ||
| 23 | border-spacing: 0px; | ||
| 24 | tr { | ||
| 25 | &.even { | ||
| 26 | background-color: gray; | ||
| 27 | } | ||
| 28 | &.odd { | ||
| 29 | background-color: purple; | ||
| 30 | } | ||
| 31 | th { | ||
| 32 | text-align: left; | ||
| 33 | padding-left: 0.5em; | ||
| 34 | padding-bottom: 0.5em; | ||
| 35 | } | ||
| 36 | td { | ||
| 37 | padding-right: 1em; | ||
| 38 | padding-top: 0.5em; | ||
| 39 | padding-bottom: 0.5em; | ||
| 40 | border-collapse: collapse; | ||
| 41 | &:first-child { | ||
| 42 | padding-left: 1em; | ||
| 43 | } | ||
| 44 | img { | ||
| 45 | width: 2em; | ||
| 46 | } | ||
| 47 | &.score-pfp { | ||
| 48 | width: 2em; | ||
| 49 | } | ||
| 50 | &.score-value { | ||
| 51 | text-align: center; | ||
| 52 | } | ||
| 53 | } | ||
| 54 | } | ||
| 55 | } \ No newline at end of file | ||
| diff --git a/web/web.rb b/web/web.rb new file mode 100644 index 0000000..15c088e --- /dev/null +++ b/web/web.rb | |||
| @@ -0,0 +1,44 @@ | |||
| 1 | require 'rack/cache' | ||
| 2 | require 'yaml' | ||
| 3 | |||
| 4 | require 'rubygems' | ||
| 5 | require 'bundler/setup' | ||
| 6 | Bundler.require :default | ||
| 7 | |||
| 8 | use Rack::Cache | ||
| 9 | |||
| 10 | config = YAML.load(open("config.yml")) | ||
| 11 | db = Sequel.connect("sqlite://#{config["database"]}") | ||
| 12 | |||
| 13 | class LingoScore < Sequel::Model | ||
| 14 | end | ||
| 15 | |||
| 16 | get '/' do | ||
| 17 | @scores = LingoScore.reverse_order(:score) | ||
| 18 | |||
| 19 | haml :index | ||
| 20 | end | ||
| 21 | |||
| 22 | post '/update' do | ||
| 23 | if params[:secret_code] != config["secret_code"] then | ||
| 24 | 403 | ||
| 25 | else | ||
| 26 | if LingoScore.where(user_id: params[:user_id]).count == 0 | ||
| 27 | score = LingoScore.new(score: 0) | ||
| 28 | else | ||
| 29 | score = LingoScore.first(user_id: params[:user_id]) | ||
| 30 | end | ||
| 31 | score.username = params[:username] | ||
| 32 | score.avatar_url = CGI.unescape(params[:avatar_url]) | ||
| 33 | score.score += 1 | ||
| 34 | score.save | ||
| 35 | |||
| 36 | 201 | ||
| 37 | end | ||
| 38 | end | ||
| 39 | |||
| 40 | get '/style.css' do | ||
| 41 | cache_control :public, :max_age => 36000 | ||
| 42 | |||
| 43 | scss :style | ||
| 44 | end | ||
