コード例 #1
0
ファイル: tournament.py プロジェクト: ianfab/pychess-variants
 def create_discord_msg(self):
     tc = time_control_str(self.base, self.inc, self.byoyomi_period)
     tail960 = "960" if self.chess960 else ""
     return "%s: **%s%s** %s tournament starts at UTC %s, duration will be **%s** minutes" % (
         self.created_by,
         self.variant,
         tail960,
         tc,
         self.starts_at.strftime("%Y.%m.%d %H:%M"),
         self.minutes,
     )
コード例 #2
0
    def __init__(self,
                 user,
                 variant,
                 fen="",
                 color="r",
                 base=5,
                 inc=3,
                 byoyomi_period=0,
                 level=6,
                 rated=False,
                 chess960=False,
                 alternate_start="",
                 target="",
                 ws=None,
                 game_id=None):
        self.user = user
        self.variant = variant
        self.color = color
        self.fen = "" if fen is None else fen
        self.rated = rated
        self.rating = int(round(user.get_rating(variant, chess960).mu, 0))
        self.base = base
        self.inc = inc
        self.byoyomi_period = byoyomi_period
        self.level = 0 if user.username == "Random-Mover" else level
        self.chess960 = chess960
        self.alternate_start = alternate_start
        self.target = target
        self.ws = ws

        Seek.gen_id += 1
        self.id = self.gen_id
        self.game_id = game_id

        self.as_json = {
            "seekID": self.id,
            "user": self.user.username,
            "bot": self.user.bot,
            "title": self.user.title,
            "variant": self.variant,
            "chess960": self.chess960,
            "alternateStart": self.alternate_start,
            "target": self.target,
            "fen": self.fen,
            "color": self.color,
            "rated": self.rated,
            "rating": self.rating,
            "tc": time_control_str(self.base, self.inc, self.byoyomi_period),
            "gameId": self.game_id if self.game_id is not None else "",
        }
コード例 #3
0
ファイル: tournament.py プロジェクト: ianfab/pychess-variants
 def notify_discord_msg(self, minutes):
     tc = time_control_str(self.base, self.inc, self.byoyomi_period)
     tail960 = "960" if self.chess960 else ""
     url = "https://www.pychess.org/tournament/%s" % self.id
     if minutes >= 60:
         time = int(minutes / 60)
         time_text = "hours"
     else:
         time = minutes
         time_text = "minutes"
     return "**%s%s** %s tournament starts in **%s** %s! %s" % (
         self.variant,
         tail960,
         tc,
         time,
         time_text,
         url,
     )
コード例 #4
0
def upcoming_tournaments_msgs(tournaments):
    to_date = datetime.now().date()
    tourney_msgs = []

    for _id, tourney in sorted(tournaments.items(),
                               key=lambda item: item[1].starts_at):
        if tourney.status == T_CREATED and tourney.starts_at.date() <= to_date:
            tc = time_control_str(tourney.base, tourney.inc,
                                  tourney.byoyomi_period)
            at = tourney.starts_at.strftime("%H:%M")
            url = "https://www.pychess.org/tournament/%s" % _id
            tourney_msgs.append("%s %s starts at today UTC %s\n%s" %
                                (tc, tourney.name, at, url))

    tourney_msgs.append(
        "If you want more notifications (10 min before start) join our Discord https://discord.gg/aPs8RKr and use #self-roles! Thx."
    )

    return "\n\n".join(tourney_msgs)
コード例 #5
0
async def get_games(request):
    games = request.app["games"]
    # TODO: filter last 10 by variant
    return web.json_response([{
        "gameId":
        game.id,
        "variant":
        game.variant,
        "fen":
        game.board.fen,
        "w":
        game.wplayer.username,
        "b":
        game.bplayer.username,
        "chess960":
        game.chess960,
        "tc":
        time_control_str(game.base, game.inc, game.byoyomi_period)
    } for game in games.values() if game.status == STARTED][-20:])
コード例 #6
0
ファイル: seek.py プロジェクト: makcyd/pychess-variants
 def discord_msg(self):
     tc = time_control_str(self.base, self.inc, self.byoyomi_period)
     tail960 = "960" if self.chess960 else ""
     return "%s: **%s%s** %s" % (self.user.username, self.variant, tail960, tc)
コード例 #7
0
async def create_or_update_tournament(app, username, form, tournament=None):
    variant = form["variant"]
    variant960 = variant.endswith("960")
    variant_name = variant[:-3] if variant960 else variant
    rated = form.get("rated", "") == "1" and form["position"] == ""
    base = float(form["clockTime"])
    inc = int(form["clockIncrement"])
    bp = int(form["byoyomiPeriod"])
    frequency = SHIELD if form["shield"] == "true" else ""

    if form["startDate"]:
        start_date = datetime.fromisoformat(form["startDate"].rstrip("Z")).replace(tzinfo=timezone.utc)
    else:
        start_date = None

    name = form["name"]
    # Create meningful tournament name in case we forget to change it :)
    if name in ADMINS:
        name = "%s %s Arena" % (variant_display_name(variant).title(), time_control_str(base, inc, bp))

    if frequency == SHIELD:
        name = "%s Shield Arena" % variant_display_name(variant).title()
        description = """
This Shield trophy is unique.
The winner keeps it for one month,
then must defend it during the next %s Shield tournament!
""" % variant_display_name(variant).title()
    else:
        description = form["description"]

    data = {
        "name": name,
        "createdBy": username,
        "rated": rated,
        "variant": variant_name,
        "chess960": variant960,
        "base": base,
        "inc": inc,
        "bp": bp,
        "system": ARENA,
        "beforeStart": int(form["waitMinutes"]),
        "startDate": start_date,
        "frequency": frequency,
        "minutes": int(form["minutes"]),
        "fen": form["position"],
        "description": description,
    }
    if tournament is None:
        tournament = await new_tournament(app, data)
    else:
        # We want to update some data of the tournament created by new_tournament() befor
        # upsert=True will do this update at the end of upsert_tournament_to_db()
        await upsert_tournament_to_db(tournament, app)

    await tournament.broadcast_spotlight()

    # Send msg to discord-relay BOT
    try:
        lobby_sockets = app["lobbysockets"]
        msg = tournament.discord_msg
        for dr_ws in lobby_sockets["Discord-Relay"]:
            await dr_ws.send_json({"type": "create_tournament", "message": msg})
            break
    except (KeyError, ConnectionResetError):
        # BOT disconnected
        log.error("--- Discord-Relay disconnected!")