class PostResultMessage(Base):
    """Post result message class"""

    __tablename__ = "post_result_message"

    id = Id()
    tournament_id = Id()
    bracket_id = Id()
    referee_id = bytes()
    message_id = int()  # TODO maybe use for update ?
    preview_message_id = int()
    setup_message_id = int()
    step = int(1)
    match_id = str()
    score_team1 = int(-1)
    score_team2 = int(-1)
    best_of = int(-1)
    roll_team1 = int(-1)
    roll_team2 = int(-1)
    n_warmup = int(0)
    mp_links = str("")
    bans_team1 = str("")
    bans_team2 = str("")
    tb_bans_team1 = str("")
    tb_bans_team2 = str("")
    created_at = int()
class QualifiersResultsMessage(Base):
    """Qualifiers results message class"""

    __tablename__ = "qualifiers_results_message"

    id = Id()
    tournament_id = Id()
    bracket_id = Id()
    message_id = int()
    channel_id = str()
class AllowedReschedule(Base):
    """AllowedReschedule class"""

    __tablename__ = "allowed_reschedule"

    id = Id()
    tournament_id = Id()
    match_id = str()
    allowed_hours = int(24)
    created_at = int()
Beispiel #4
0
class MatchNotification(BaseLockMessage):
    """MatchNotification class"""

    __tablename__ = "match_notification"

    tournament_id = Id()
    bracket_id = Id()
    message_id_int = int()
    match_id = str()
    teams_mentions = str()
    team1_mention = str()
    team2_mention = str()
    date_info = str()
    notification_type = int()
class StaffRescheduleMessage(Base):
    """Staff reschedule message class"""

    __tablename__ = "staff_reschedule_message"

    id = Id()
    tournament_id = Id()
    bracket_id = Id()
    message_id = bytes()
    match_id = str()
    new_date = str()
    staff_id = int()
    in_use = bool()
    created_at = int()
class RescheduleMessage(BaseLockMessage):
    """Reschedule message class"""

    __tablename__ = "reschedule_message"

    tournament_id = Id()
    bracket_id = Id()
    previous_date = str()
    new_date = str()
    match_id = str()
    match_id_hash = bytes()
    ally_user_id = str()
    ally_team_role_id = str()
    opponent_user_id = str()
Beispiel #7
0
class StaffRescheduleMessage(BaseLockMessage):
    """Staff reschedule message class"""

    __tablename__ = "staff_reschedule_message"

    tournament_id = Id()
    bracket_id = Id()
    match_id = str()
    team1 = str()
    team2 = str()
    previous_date = str()
    new_date = str()
    referees_id = str()
    streamers_id = str()
    commentators_id = str()
Beispiel #8
0
class Bracket(Base):
    """Bracket class"""

    __tablename__ = "bracket"

    def __init__(self, session=None, *args, **kwargs):
        super().__init__(session, *args, **kwargs)
        self._players_spreadsheet = None
        self._schedules_spreadsheet = None
        self._challonge_tournament = None

    id = Id()
    tournament_id = Id()
    name = str()
    role_id = int()
    challonge = str()
    players_spreadsheet_id = Id(-1)
    schedules_spreadsheet_id = Id(-1)
    post_result_channel_id = int()
    current_round = str()
    # TODO set_all_post_result_channel

    @property
    def players_spreadsheet(self):
        if self._players_spreadsheet is None:
            self._players_spreadsheet = (
                self._session.query(PlayersSpreadsheet).where(
                    PlayersSpreadsheet.id ==
                    self.players_spreadsheet_id).first())
        return self._players_spreadsheet

    @property
    def schedules_spreadsheet(self):
        if self._schedules_spreadsheet is None:
            self._schedules_spreadsheet = (
                self._session.query(SchedulesSpreadsheet).where(
                    SchedulesSpreadsheet.id ==
                    self.schedules_spreadsheet_id).first())
        return self._schedules_spreadsheet

    @property
    def challonge_tournament(self):
        if self._challonge_tournament is None:
            self._challonge_tournament = challonge.get_tournament(
                self.challonge)
        return self._challonge_tournament
Beispiel #9
0
class EndTournamentMessage(Base):
    """End tournament message class"""

    __tablename__ = "end_tournament_message"

    id = Id()
    message_id = bytes()
    created_at = int()
class RescheduleMessage(Base):
    """Reschedule message class"""

    __tablename__ = "reschedule_message"

    id = Id()
    tournament_id = Id()
    bracket_id = Id()
    message_id = bytes()
    previous_date = str()
    new_date = str()
    match_id = str()
    ally_user_id = int()
    ally_team_role_id = int()
    opponent_user_id = int()
    in_use = bool()
    created_at = int()
class GuildVerifyMessage(Base):
    """Guild verify message class"""

    __tablename__ = "guild_verify_message"

    id = Id()
    message_id = bytes()
    guild_id = bytes()
    created_at = int()
Beispiel #12
0
class Guild(Base):
    """Guild class"""

    __tablename__ = "guild"

    id = Id()
    guild_id = bytes()
    verified_role_id = int()
    admin_role_id = int()
    last_notification_date = str()
class StaffRescheduleMessage(Base):
    """Staff reschedule message class"""

    __tablename__ = "staff_reschedule_message"

    id = Id()
    tournament_id = Id()
    bracket_id = Id()
    message_id = bytes()
    match_id = str()
    team1 = str()
    team2 = str()
    previous_date = str()
    new_date = str()
    staff_id = int()
    referees_id = str()
    streamers_id = str()
    commentators_id = str()
    in_use = bool()
    created_at = int()
Beispiel #14
0
class User(Base):
    """User class"""

    __tablename__ = "user"

    id = Id()
    discord_id = bytes()
    osu_id = str()
    verified = bool()
    code = str()
    osu_name = str()
    osu_previous_name = str()
class PostResultMessage(BaseAuthorLockMessage):
    """Post result message class"""

    __tablename__ = "post_result_message"

    tournament_id = Id()
    bracket_id = Id()
    preview_message_id = int()
    setup_message_id = int()
    step = int(1)
    match_id = str()
    score_team1 = int(0)
    score_team2 = int(0)
    best_of = int(0)
    roll_team1 = int(0)
    roll_team2 = int(0)
    n_warmup = int(0)
    mp_links = str("")
    bans_team1 = str("")
    bans_team2 = str("")
    tb_bans_team1 = str("")
    tb_bans_team2 = str("")
Beispiel #16
0
class Guild(Base):
    """Guild class"""

    __tablename__ = "guild"

    id = Id()
    guild_id = bytes()
    guild_id_snowflake = str()
    verified_role_id = str()
    admin_role_id = str()
    last_notification_date = str()
    language = str()
    created_at = int()
    updated_at = int()
Beispiel #17
0
class Token(Base):
    """Token class"""

    __tablename__ = "token"

    id = Id()
    session_token = bytes()
    discord_user_id = str()
    access_token = str()
    token_type = str()
    access_token_expiry_date = int()
    refresh_token = str()
    scope = str()
    expiry_date = int()
Beispiel #18
0
 def __init_subclass__(cls):
     super().__init_subclass__()
     cls.id = Id()
     cls.message_id = bytes()
     cls.created_at = int()
     cls.updated_at = int()
class EndTournamentMessage(BaseAuthorLockMessage):
    """End tournament message class"""

    __tablename__ = "end_tournament_message"

    tournament_id = Id()
Beispiel #20
0
class Tournament(Base):
    """Tournament class"""

    __tablename__ = "tournament"

    def __init__(self, session=None, *args, **kwargs):
        super().__init__(session, *args, **kwargs)
        self._current_bracket = None
        self._brackets = None

    id = Id()
    guild_id = bytes()
    guild_id_snowflake = str()
    acronym = str()
    name = str()
    staff_channel_id = str()
    match_notification_channel_id = str()
    referee_role_id = str()
    streamer_role_id = str()
    commentator_role_id = str()
    player_role_id = str()
    team_captain_role_id = str()
    post_result_message = str()
    post_result_message_team1_with_score = str()
    post_result_message_team2_with_score = str()
    post_result_message_mp_link = str()
    post_result_message_rolls = str()
    post_result_message_bans = str()
    post_result_message_tb_bans = str()
    reschedule_deadline_hours_before_current_time = int(6)
    reschedule_deadline_hours_before_new_time = int(24)
    reschedule_deadline_end = str()
    reschedule_before_date = str()
    reschedule_ping_team = bool(True)
    current_bracket_id = Id()
    matches_to_ignore = str()
    notify_no_staff_reschedule = bool(True)
    utc = str()
    template_code = str()
    registration_phase = bool(False)
    game_mode = int(0)
    registration_background_update = bool(False)
    created_at = int()
    updated_at = int()
    date_format = str()

    @property
    def current_bracket(self):
        if self._current_bracket is None:
            for bracket in self.brackets:
                if bracket.id == self.current_bracket_id:
                    self._current_bracket = bracket
                    break
        return self._current_bracket

    @property
    def brackets(self):
        return self._brackets

    def get_bracket_from_id(self, bracket_id):
        return next(
            (bracket for bracket in self.brackets if bracket.id == bracket_id),
            None)

    def get_role_id(self, role_name):
        field = role_name.lower().replace(" ", "_") + "_role_id"
        try:
            return vars(self)[field]
        except KeyError:
            return None

    def parse_date(
            self,
            date,
            date_formats=[],
            prefer_dates_from="current_period",
            relative_base=datetime.datetime.now(),
    ):
        if self.date_format:
            date_formats.append(self.date_format)
        elif not date_formats:
            date_formats.append("%d %B")
        if self.utc:
            return dateparser.parse(
                date,
                date_formats=date_formats,
                settings={
                    "PREFER_DATES_FROM": prefer_dates_from,
                    "RELATIVE_BASE": relative_base,
                    "TIMEZONE": self.utc,
                    "RETURN_AS_TIMEZONE_AWARE": True,
                    "DATE_ORDER": "DMY",
                },
            )
        else:
            return dateparser.parse(
                date,
                date_formats=date_formats,
                settings={
                    "PREFER_DATES_FROM": prefer_dates_from,
                    "RELATIVE_BASE": relative_base,
                    "TIMEZONE": "+00:00",
                    "RETURN_AS_TIMEZONE_AWARE": True,
                    "DATE_ORDER": "DMY",
                },
            )

    def create_date_from_week_times(self, week_time_begin, week_time_end,
                                    date):
        if not week_time_begin or not week_time_end:
            return date, date
        day_name, time = week_time_begin.split(" ")
        hours, minutes = time.split(":")
        weekday = self.get_weekday_from_day_name(day_name)
        date_week_begin = date - datetime.timedelta(
            days=(date.weekday() - weekday) % 7)
        date_week_begin = date_week_begin.replace(hour=int(hours),
                                                  minute=int(minutes))
        day_name, time = week_time_end.split(" ")
        hours, minutes = time.split(":")
        weekday = self.get_weekday_from_day_name(day_name)
        date_week_end = date + datetime.timedelta(
            days=(date_week_begin.weekday() - weekday) % 7)
        date_week_end = date_week_end.replace(hour=int(hours),
                                              minute=int(minutes))
        return date_week_begin, date_week_end

    def get_weekday_from_day_name(self, day_name):
        days = [
            "monday",
            "tuesday",
            "wednesday",
            "thursday",
            "friday",
            "saturday",
            "sunday",
        ]
        return days.index(day_name)
Beispiel #21
0
class Bracket(Base):
    """Bracket class"""

    __tablename__ = "bracket"

    def __init__(self, session=None, *args, **kwargs):
        super().__init__(session, *args, **kwargs)
        self._players_spreadsheet = None
        self._schedules_spreadsheet = None
        self._challonge_tournament = None

    id = Id()
    tournament_id = Id()
    name = str()
    role_id = int()
    challonge = str()
    players_spreadsheet_id = Id(-1)
    schedules_spreadsheet_id = Id(-1)
    post_result_channel_id = int()
    current_round = str()
    # TODO set_all_post_result_channel

    def get_spreadsheet_from_type(self, spreadsheet_type):
        return getattr(self, spreadsheet_type + "_spreadsheet")

    def create_spreadsheet_from_type(self, bot, spreadsheet_type):
        spreadsheet_types = Bracket.get_spreadsheet_types()
        if spreadsheet_type in spreadsheet_types:
            spreadsheet = spreadsheet_types[spreadsheet_type]()
            bot.session.add(spreadsheet)
            setattr(self, spreadsheet_type + "_spreadsheet_id", spreadsheet.id)
            bot.session.update(self)
            return spreadsheet
        return None

    @classmethod
    def get_spreadsheet_types(cls):
        return {"players": PlayersSpreadsheet, "schedules": SchedulesSpreadsheet}

    @property
    def players_spreadsheet(self):
        if self._players_spreadsheet is None:
            self._players_spreadsheet = (
                self._session.query(PlayersSpreadsheet)
                .where(PlayersSpreadsheet.id == self.players_spreadsheet_id)
                .first()
            )
        return self._players_spreadsheet

    @property
    def schedules_spreadsheet(self):
        if self._schedules_spreadsheet is None:
            self._schedules_spreadsheet = (
                self._session.query(SchedulesSpreadsheet)
                .where(SchedulesSpreadsheet.id == self.schedules_spreadsheet_id)
                .first()
            )
        return self._schedules_spreadsheet

    @property
    def challonge_tournament(self):
        if self._challonge_tournament is None:
            self._challonge_tournament = challonge.get_tournament(self.challonge)
        return self._challonge_tournament
Beispiel #22
0
 def __init_subclass__(cls):
     super().__init_subclass__()
     cls.id = Id()
     cls.spreadsheet_id = str()
     cls.sheet_name = str("")