Setup small HTTP server to display scores
This commit is contained in:
		@@ -3,6 +3,7 @@ from disnake import CategoryChannel, PermissionOverwrite, TextChannel
 | 
				
			|||||||
from disnake.ext import commands
 | 
					from disnake.ext import commands
 | 
				
			||||||
import logging
 | 
					import logging
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					from orochi import http
 | 
				
			||||||
from orochi.config import Config
 | 
					from orochi.config import Config
 | 
				
			||||||
from orochi.models import Game
 | 
					from orochi.models import Game
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -221,6 +222,8 @@ class Confirm(disnake.ui.View):
 | 
				
			|||||||
def run():
 | 
					def run():
 | 
				
			||||||
    config = Config.load()
 | 
					    config = Config.load()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    http.run_web_server()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    logger = logging.getLogger('discord')
 | 
					    logger = logging.getLogger('discord')
 | 
				
			||||||
    logger.setLevel(logging.DEBUG)
 | 
					    logger.setLevel(logging.DEBUG)
 | 
				
			||||||
    handler = logging.FileHandler(filename='../discord.log', encoding='utf-8', mode='w')
 | 
					    handler = logging.FileHandler(filename='../discord.log', encoding='utf-8', mode='w')
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										23
									
								
								orochi/http.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								orochi/http.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,23 @@
 | 
				
			|||||||
 | 
					from threading import Thread
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					from flask import Flask, render_template
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					from orochi.models import Game
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					app = Flask(__name__)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@app.route('/')
 | 
				
			||||||
 | 
					def index():
 | 
				
			||||||
 | 
					    game = Game.INSTANCE
 | 
				
			||||||
 | 
					    return render_template('list.html', game=game)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@app.route('/admin')
 | 
				
			||||||
 | 
					def admin():
 | 
				
			||||||
 | 
					    game = Game.INSTANCE
 | 
				
			||||||
 | 
					    return render_template('list.html', game=game, admin=True)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def run_web_server():
 | 
				
			||||||
 | 
					    Thread(target=lambda: app.run(debug=True, use_reloader=False)).start()
 | 
				
			||||||
@@ -68,7 +68,7 @@ class RoundVote:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    @property
 | 
					    @property
 | 
				
			||||||
    def room(self):
 | 
					    def room(self):
 | 
				
			||||||
        for r in Game.rounds:
 | 
					        for r in Game.INSTANCE.rounds:
 | 
				
			||||||
            for room in r.rooms:
 | 
					            for room in r.rooms:
 | 
				
			||||||
                if self in room.votes:
 | 
					                if self in room.votes:
 | 
				
			||||||
                    return room
 | 
					                    return room
 | 
				
			||||||
@@ -126,11 +126,11 @@ class Game:
 | 
				
			|||||||
                             vote1=RoundVote(player1=self.players['Tora']),
 | 
					                             vote1=RoundVote(player1=self.players['Tora']),
 | 
				
			||||||
                             vote2=RoundVote(player1=self.players['Kamui'],
 | 
					                             vote2=RoundVote(player1=self.players['Kamui'],
 | 
				
			||||||
                                             player2=self.players['Philia'])),
 | 
					                                             player2=self.players['Philia'])),
 | 
				
			||||||
            room_b=RoundRoom(room=Room.A,
 | 
					            room_b=RoundRoom(room=Room.B,
 | 
				
			||||||
                             vote1=RoundVote(player1=self.players['Dan']),
 | 
					                             vote1=RoundVote(player1=self.players['Dan']),
 | 
				
			||||||
                             vote2=RoundVote(player1=self.players['Ennea'],
 | 
					                             vote2=RoundVote(player1=self.players['Ennea'],
 | 
				
			||||||
                                             player2=self.players['Delphine'])),
 | 
					                                             player2=self.players['Delphine'])),
 | 
				
			||||||
            room_c=RoundRoom(room=Room.A,
 | 
					            room_c=RoundRoom(room=Room.C,
 | 
				
			||||||
                             vote1=RoundVote(player1=self.players['Hanabi']),
 | 
					                             vote1=RoundVote(player1=self.players['Hanabi']),
 | 
				
			||||||
                             vote2=RoundVote(player1=self.players['Nona'],
 | 
					                             vote2=RoundVote(player1=self.players['Nona'],
 | 
				
			||||||
                                             player2=self.players['Oji'])),
 | 
					                                             player2=self.players['Oji'])),
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										74
									
								
								orochi/templates/list.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										74
									
								
								orochi/templates/list.html
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,74 @@
 | 
				
			|||||||
 | 
					<!doctype html>
 | 
				
			||||||
 | 
					<html lang="fr">
 | 
				
			||||||
 | 
					<head>
 | 
				
			||||||
 | 
					    <title>Zero Escape: Radical Outcome</title>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    <style>
 | 
				
			||||||
 | 
					        table {
 | 
				
			||||||
 | 
					            border-collapse: collapse;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        th, td {
 | 
				
			||||||
 | 
					            border: 1px solid black;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    </style>
 | 
				
			||||||
 | 
					</head>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<body>
 | 
				
			||||||
 | 
					    <h1>Scores Nonary Game: Ambidex Edition</h1>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    <h2>Tableau des scores</h2>
 | 
				
			||||||
 | 
					    <table>
 | 
				
			||||||
 | 
					        <thead>
 | 
				
			||||||
 | 
					        <tr>
 | 
				
			||||||
 | 
					            <th>Joueur</th>
 | 
				
			||||||
 | 
					            <th>Score</th>
 | 
				
			||||||
 | 
					        </tr>
 | 
				
			||||||
 | 
					        </thead>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        <tbody>
 | 
				
			||||||
 | 
					        {% for player in game.players.values() %}
 | 
				
			||||||
 | 
					            <tr>
 | 
				
			||||||
 | 
					                <td>{{ player.name }}</td>
 | 
				
			||||||
 | 
					                <td>{{ player.score }}</td>
 | 
				
			||||||
 | 
					            </tr>
 | 
				
			||||||
 | 
					        {% endfor %}
 | 
				
			||||||
 | 
					        </tbody>
 | 
				
			||||||
 | 
					    </table>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    <h2>Récapitulatif par tour</h2>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    {% for round in game.rounds %}
 | 
				
			||||||
 | 
					        <h3>Tour n°{{ round.round }}</h3>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        <table>
 | 
				
			||||||
 | 
					            <thead>
 | 
				
			||||||
 | 
					            <tr>
 | 
				
			||||||
 | 
					                <th>Salle</th>
 | 
				
			||||||
 | 
					                <th>Équipes</th>
 | 
				
			||||||
 | 
					                <th>Vote</th>
 | 
				
			||||||
 | 
					            </tr>
 | 
				
			||||||
 | 
					            </thead>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            <tbody>
 | 
				
			||||||
 | 
					            {% for room in round.rooms %}
 | 
				
			||||||
 | 
					                {% for vote in room.votes %}
 | 
				
			||||||
 | 
					                <tr>
 | 
				
			||||||
 | 
					                    {% if loop.index0 == 0 %}
 | 
				
			||||||
 | 
					                        <td rowspan="2">{{ room.room.value }}</td>
 | 
				
			||||||
 | 
					                    {% endif %}
 | 
				
			||||||
 | 
					                    <td>{{ vote.player1.name }}{% if vote.player2 %}, {{ vote.player2.name }}{% endif %}</td>
 | 
				
			||||||
 | 
					                    {% if round.round != game.rounds|length or admin %}
 | 
				
			||||||
 | 
					                        <td>{{ room.vote1.vote.value|default('Pas de vote') }}</td>
 | 
				
			||||||
 | 
					                    {% else %}
 | 
				
			||||||
 | 
					                        <td><em>Vote en cours ...</em></td>
 | 
				
			||||||
 | 
					                    {% endif %}
 | 
				
			||||||
 | 
					                </tr>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                {% endfor %}
 | 
				
			||||||
 | 
					            {% endfor %}
 | 
				
			||||||
 | 
					            </tbody>
 | 
				
			||||||
 | 
					        </table>
 | 
				
			||||||
 | 
					    {% endfor %}
 | 
				
			||||||
 | 
					</body>
 | 
				
			||||||
 | 
					</html>
 | 
				
			||||||
@@ -1,2 +1,3 @@
 | 
				
			|||||||
disnake
 | 
					disnake
 | 
				
			||||||
 | 
					flask
 | 
				
			||||||
pyyaml
 | 
					pyyaml
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user