diff --git a/db.py b/db.py index a0e75220..ef4fb1a7 100644 --- a/db.py +++ b/db.py @@ -6,7 +6,7 @@ from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.orm import sessionmaker, relationship from sqlalchemy.ext.hybrid import hybrid_property from sqlalchemy import Column, BigInteger, Integer, String, DateTime, ForeignKey, Float, Enum, create_engine, \ - UniqueConstraint, PrimaryKeyConstraint, Boolean, LargeBinary, Text, Date, func + UniqueConstraint, PrimaryKeyConstraint, Boolean, LargeBinary, Text, Date from sqlalchemy.inspection import inspect import requests import errors @@ -14,11 +14,13 @@ from errors import NotFoundError, AlreadyExistingError, PrivateError import re import enum import loldata -from dirty import Dirty, DirtyDelta +from utils.dirty import Dirty, DirtyDelta import sql_queries from flask import escape import configparser import typing +from utils import MatchmakingStatus +import strings if typing.TYPE_CHECKING: # noinspection PyPackageRequirements from discord import User as DiscordUser @@ -1250,19 +1252,10 @@ class Match(Base): plist = f"Giocatori{minimum}:\n" ignore_count = 0 for player in player_list: - if player.status == MatchmakingStatus.READY: - icon = "πŸ”΅" - elif player.status == MatchmakingStatus.WAIT_FOR_ME: - icon = "πŸ•’" - elif player.status == MatchmakingStatus.MAYBE: - icon = "❔" - elif player.status == MatchmakingStatus.SOMEONE_ELSE: - icon = "πŸ’¬" - elif player.status == MatchmakingStatus.IGNORED: + icon = strings.MATCHMAKING.ENUM_TO_EMOJIS[player.status] + if player.status == MatchmakingStatus.IGNORED: ignore_count += 1 continue - else: - continue plist += f"{icon} {player.user.royal.username}\n" if ignore_count: ignored = f"❌ {ignore_count} persone non sono interessate.\n" @@ -1298,14 +1291,6 @@ class Match(Base): } -class MatchmakingStatus(enum.IntEnum): - WAIT_FOR_ME = 1 - READY = 2 - MAYBE = 3 - SOMEONE_ELSE = 4 - IGNORED = -1 - - class MatchPartecipation(Base): __tablename__ = "matchpartecipations" __table_args__ = (PrimaryKeyConstraint("user_id", "match_id"),) diff --git a/statsupdate.py b/statsupdate.py index 3073b184..160c9803 100644 --- a/statsupdate.py +++ b/statsupdate.py @@ -11,7 +11,7 @@ import telegram import sys import coloredlogs import requests -from dirty import Dirty, DirtyDelta +from utils import Dirty, DirtyDelta from sentry_sdk import configure_scope logging.getLogger().disabled = True diff --git a/strings.py b/strings.py index 1b4a7302..c289fba8 100644 --- a/strings.py +++ b/strings.py @@ -1,4 +1,4 @@ -from db import MatchmakingStatus +import utils import dice import typing @@ -118,28 +118,44 @@ class MARKOV: # Matchmaking service strings class MATCHMAKING: - TICKER_TEXT = { - "match_ready": "πŸ”΅ Hai detto che sei pronto per giocare!", - "match_wait_for_me": "πŸ•’ Hai chiesto agli altri di aspettarti.", - "match_maybe": "❓ Hai detto che forse ci sarai.", - "match_ignore": "❌ Non hai intenzione di partecipare.", - "match_close": "🚩 Hai notificato tutti che la partita sta iniziando.", - "match_cancel": "πŸ—‘ Hai annullato la partita." + EMOJIS = { + "ready": "πŸ”΅", + "wait_for_me": "πŸ•’", + "maybe": "❓", + "ignore": "❌", + "close": "🚩", + "cancel": "πŸ—‘" } - GAME_START = { - MatchmakingStatus.READY: "πŸ”΅ Che {match_title} abbia inizio!", - MatchmakingStatus.WAIT_FOR_ME: "πŸ•’ Sbrigati! {match_title} sta per iniziare!", - MatchmakingStatus.MAYBE: "❓ {match_title} sta iniziando. Se vuoi partecipare, fai in fretta!", + ENUM_TO_EMOJIS = { + utils.MatchmakingStatus.READY: EMOJIS["ready"], + utils.MatchmakingStatus.WAIT_FOR_ME: EMOJIS["wait_for_me"], + utils.MatchmakingStatus.MAYBE: EMOJIS["maybe"], + utils.MatchmakingStatus.IGNORED: EMOJIS["ignore"], } BUTTONS = { - "match_ready": "πŸ”΅ Sono pronto per iniziare!", - "match_wait_for_me": "πŸ•’ Ci sarΓ², aspettatemi!", - "match_maybe": "❓ Forse vengo, se non ci sono fate senza di me.", - "match_ignore": "❌ Non ci sarΓ².", - "match_close": "🚩 ADMIN: Avvia la partita", - "match_cancel": "πŸ—‘ ADMIN: Annulla la partita" + "match_ready": f"{EMOJIS['ready']} Sono pronto per iniziare!", + "match_wait_for_me": f"{EMOJIS['wait_for_me']} Ci sarΓ², aspettatemi!", + "match_maybe": f"{EMOJIS['maybe']} Forse vengo, se non ci sono fate senza di me.", + "match_ignore": f"{EMOJIS['ignore']} Non ci sarΓ².", + "match_close": f"{EMOJIS['close']} ADMIN: Avvia la partita", + "match_cancel": f"{EMOJIS['cancel']} ADMIN: Annulla la partita" + } + + TICKER_TEXT = { + "match_ready": f"{EMOJIS['ready']} Hai detto che sei pronto per giocare!", + "match_wait_for_me": f"{EMOJIS['wait_for_me']} Hai chiesto agli altri di aspettarti.", + "match_maybe": f"{EMOJIS['maybe']} Hai detto che forse ci sarai.", + "match_ignore": f"{EMOJIS['ignore']} Non hai intenzione di partecipare.", + "match_close": f"{EMOJIS['close']} Hai notificato tutti che la partita sta iniziando.", + "match_cancel": f"{EMOJIS['cancel']} Hai annullato la partita." + } + + GAME_START = { + utils.MatchmakingStatus.READY: "πŸ”΅ Che {match_title} abbia inizio!", + utils.MatchmakingStatus.WAIT_FOR_ME: "πŸ•’ Sbrigati! {match_title} sta per iniziare!", + utils.MatchmakingStatus.MAYBE: "❓ {match_title} sta iniziando. Se vuoi partecipare, fai in fretta!", } class ERRORS: diff --git a/utils/__init__.py b/utils/__init__.py new file mode 100644 index 00000000..68a491f2 --- /dev/null +++ b/utils/__init__.py @@ -0,0 +1,4 @@ +from .dirty import Dirty, DirtyDelta +from .mmstatus import MatchmakingStatus + +__all__ = ["Dirty", "DirtyDelta", "MatchmakingStatus"] diff --git a/dirty.py b/utils/dirty.py similarity index 100% rename from dirty.py rename to utils/dirty.py diff --git a/utils/mmstatus.py b/utils/mmstatus.py new file mode 100644 index 00000000..8a308605 --- /dev/null +++ b/utils/mmstatus.py @@ -0,0 +1,9 @@ +import enum + + +class MatchmakingStatus(enum.IntEnum): + WAIT_FOR_ME = 1 + READY = 2 + MAYBE = 3 + SOMEONE_ELSE = 4 + IGNORED = -1