Skip to content

Commit

Permalink
add custom map (#82)
Browse files Browse the repository at this point in the history
Co-authored-by: velizhanin_ie <[email protected]>
  • Loading branch information
MaHryCT3 and velizhanin_ie authored Nov 18, 2024
1 parent 187dda2 commit 9a5ed0e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
3 changes: 2 additions & 1 deletion bot/apps/server_status/select_buttons.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,9 @@ def _get_default_options(cls, _locale: LocaleEnum):
discord.SelectOption(label='-', value=EmptyEnum.EMPTY),
discord.SelectOption(label=Maps.PRECEDURAL_PLUS),
discord.SelectOption(label=Maps.BARREN_PLUS),
discord.SelectOption(label=Maps.CUSTOM),
]
return options

def on_value_changed(self, value: str | None):
self.filter_view.map = value
self.filter_view.map_type = value
12 changes: 6 additions & 6 deletions bot/apps/server_status/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
MapSelect,
WipeDaySelect,
)
from core.api_clients.magic_rust import FullServerData, MagicRustServerDataAPI
from core.api_clients.magic_rust import FullServerData, MagicRustServerDataAPI, Maps
from core.localization import LocaleEnum


Expand Down Expand Up @@ -47,7 +47,7 @@ def __init__(self, locale: LocaleEnum):
self.gm: str | None = None
self.limit: int | None = None
self.wipeday: int | None = None
self.map: str | None = None
self.map_type: Maps | None = None

async def update(self, interaction: discord.Interaction):
servers_data = await MagicRustServerDataAPI().get_combined_servers_data()
Expand Down Expand Up @@ -84,7 +84,7 @@ async def update(self, interaction: discord.Interaction):
if self._is_server_satisfying_filter(server_data, exclude=self.FilterFields.WIPEDAY)
}
self.availible_maps = {
server_data.map
server_data.map_type
for server_data in servers_data
if self._is_server_satisfying_filter(server_data, exclude=self.FilterFields.MAP)
}
Expand All @@ -96,7 +96,7 @@ def _is_server_satisfying_filter(self, server_data: FullServerData, exclude: Fil
(self.gm in (None, server_data.gm) or exclude == self.FilterFields.GM)
and (self.limit in (None, server_data.limit) or exclude == self.FilterFields.LIMIT)
and (self.wipeday in (None, server_data.wipeday) or exclude == self.FilterFields.WIPEDAY)
and (self.map in (None, server_data.map) or exclude == self.FilterFields.MAP)
and (self.map_type in (None, server_data.map_type) or exclude == self.FilterFields.MAP)
)

def _set_availible_selects(self):
Expand All @@ -110,6 +110,6 @@ def _set_availible_selects(self):
if len(self.availible_wipedays) > 1 or self.wipeday is not None:
self.wipeday_select.set_availible_options(self.availible_wipedays, default=str(self.wipeday))
self.add_item(self.wipeday_select)
if len(self.availible_maps) > 1 or self.map is not None:
self.map_select.set_availible_options(self.availible_maps, default=self.map)
if len(self.availible_maps) > 1 or self.map_type is not None:
self.map_select.set_availible_options(self.availible_maps, default=self.map_type)
self.add_item(self.map_select)
11 changes: 10 additions & 1 deletion core/api_clients/magic_rust/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def get_label(self) -> str:
class Maps(StrEnum):
PRECEDURAL_PLUS = 'Procedural Plus'
BARREN_PLUS = 'Barren Plus'
CUSTOM = 'Custom'


class GameModeTypes(StrEnum):
Expand All @@ -35,7 +36,8 @@ class ServerTypes(StrEnum):

class FullServerData(BaseModel):
ip: str
map: Maps
map: str
map_type: Maps = Field(validation_alias='map')
players: int
sleepers: int
maxplayers: int
Expand All @@ -56,6 +58,13 @@ def set_default_0(cls, value, _) -> int:
return 0
return value

@field_validator('map_type', mode='before')
@classmethod
def set_default_map_type_custom(cls, value, _) -> str:
if value not in Maps:
return Maps.CUSTOM
return value


class MonitoringServerData(BaseModel):
ip: str
Expand Down

0 comments on commit 9a5ed0e

Please sign in to comment.