region optional

This commit is contained in:
Robin Appelman 2025-04-14 20:20:43 +02:00
commit dc0f3e9f0f
11 changed files with 36 additions and 15 deletions

4
api-server/Cargo.lock generated
View file

@ -1964,7 +1964,7 @@ dependencies = [
[[package]] [[package]]
name = "ugc-scraper" name = "ugc-scraper"
version = "0.5.0" version = "0.5.0"
source = "git+https://github.com/icewind1991/ugc-scaper#f79c02a010ee5ec572901b4eb5b14067b5ab45a9" source = "git+https://github.com/icewind1991/ugc-scaper#b290e2f83db161e2a7bcf4e199400226d56a2076"
dependencies = [ dependencies = [
"regex", "regex",
"reqwest", "reqwest",
@ -1979,7 +1979,7 @@ dependencies = [
[[package]] [[package]]
name = "ugc-scraper-types" name = "ugc-scraper-types"
version = "0.2.0" version = "0.2.0"
source = "git+https://github.com/icewind1991/ugc-scaper#f79c02a010ee5ec572901b4eb5b14067b5ab45a9" source = "git+https://github.com/icewind1991/ugc-scaper#b290e2f83db161e2a7bcf4e199400226d56a2076"
dependencies = [ dependencies = [
"serde", "serde",
"steamid-ng", "steamid-ng",

View file

@ -0,0 +1,19 @@
CREATE TYPE region AS ENUM ('europe', 'north-america', 'south-america', 'asia', 'australia');
CREATE TYPE game_mode AS ENUM ('highlander', 'sixes', 'fours', 'ultiduo');
CREATE TABLE teams
(
id INTEGER NOT NULL,
name VARCHAR NOT NULL,
image VARCHAR NOT NULL,
form
);
CREATE UNIQUE INDEX matches_id_idx
ON matches USING BTREE (id);
CREATE INDEX matches_home_idx
ON matches USING BTREE (team_home);
CREATE INDEX matches_away_idx
ON matches USING BTREE (team_away);

View file

@ -181,11 +181,7 @@ impl Parser for TeamParser {
let region = division let region = division
.split(' ') .split(' ')
.find_map(|part| Region::from_str(part).ok()) .find_map(|part| Region::from_str(part).ok())
.or_else(|| Region::from_str(&division).ok()) .or_else(|| Region::from_str(&division).ok());
.ok_or_else(|| ParseError::InvalidText {
text: division.clone(),
role: "team region",
})?;
let timezone = select_text(root, &self.selector_team_timezone).map(String::from); let timezone = select_text(root, &self.selector_team_timezone).map(String::from);

View file

@ -7,7 +7,7 @@ expression: parsed
"tag": "Melting Pot", "tag": "Melting Pot",
"image": "https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/f7/f75809d7774c917be9883370d772d3099bfe457d_full.jpg", "image": "https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/f7/f75809d7774c917be9883370d772d3099bfe457d_full.jpg",
"format": "9v9", "format": "9v9",
"region": "Europe", "region": "europe",
"timezone": "West-Euro", "timezone": "West-Euro",
"steam_group": "http://steamcommunity.com/groups/Melintongpotsss", "steam_group": "http://steamcommunity.com/groups/Melintongpotsss",
"division": "Euro Platinum", "division": "Euro Platinum",

View file

@ -7,7 +7,7 @@ expression: parsed
"tag": "Europe", "tag": "Europe",
"image": "https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/09/096a30b1025c586f9d41c686077129f6e86998d0_full.jpg", "image": "https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/09/096a30b1025c586f9d41c686077129f6e86998d0_full.jpg",
"format": "6v6", "format": "6v6",
"region": "Europe", "region": "europe",
"timezone": "West-Euro", "timezone": "West-Euro",
"steam_group": null, "steam_group": null,
"division": "Europe", "division": "Europe",

View file

@ -7,7 +7,7 @@ expression: parsed
"tag": "PNKTSU", "tag": "PNKTSU",
"image": "clan_avatars/32437_thumbnail.jpg", "image": "clan_avatars/32437_thumbnail.jpg",
"format": "9v9", "format": "9v9",
"region": "NorthAmerica", "region": "north-america",
"timezone": null, "timezone": null,
"steam_group": "https://steamcommunity.com/groups/xyxxx-", "steam_group": "https://steamcommunity.com/groups/xyxxx-",
"division": "North America", "division": "North America",

View file

@ -7,7 +7,7 @@ expression: parsed
"tag": "-Xe-", "tag": "-Xe-",
"image": "https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/db/dbabbd8bab7ccf6d27a9d4ca2e73a76e085bb201_full.jpg", "image": "https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/db/dbabbd8bab7ccf6d27a9d4ca2e73a76e085bb201_full.jpg",
"format": "9v9", "format": "9v9",
"region": "Europe", "region": "europe",
"timezone": "West-Euro", "timezone": "West-Euro",
"steam_group": "https://steamcommunity.com/groups/XenonxTF2", "steam_group": "https://steamcommunity.com/groups/XenonxTF2",
"division": "Euro Platinum", "division": "Euro Platinum",

View file

@ -7,7 +7,7 @@ expression: parsed
"tag": "-BB-", "tag": "-BB-",
"image": "https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/4c/4c75e24cd642d648ae3105fc9e66580e6064e393_full.jpg", "image": "https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/4c/4c75e24cd642d648ae3105fc9e66580e6064e393_full.jpg",
"format": "4v4", "format": "4v4",
"region": "NorthAmerica", "region": "north-america",
"timezone": "East", "timezone": "East",
"steam_group": "http://steamcommunity.com/groups/banananana_boat", "steam_group": "http://steamcommunity.com/groups/banananana_boat",
"division": "Gold N.Amer", "division": "Gold N.Amer",

View file

@ -7,7 +7,7 @@ expression: parsed
"tag": "#1TF2Team", "tag": "#1TF2Team",
"image": "https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/b9/b9cc1e4949f5e6d0364f9ee59a13cc931fd3aab1_full.jpg", "image": "https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/b9/b9cc1e4949f5e6d0364f9ee59a13cc931fd3aab1_full.jpg",
"format": "9v9", "format": "9v9",
"region": "NorthAmerica", "region": "north-america",
"timezone": "East", "timezone": "East",
"steam_group": "http://steamcommunity.com/groups/NumberOneTF2Team", "steam_group": "http://steamcommunity.com/groups/NumberOneTF2Team",
"division": "Main NA", "division": "Main NA",

View file

@ -7,7 +7,7 @@ expression: parsed
"tag": "Grand Meister", "tag": "Grand Meister",
"image": "https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/d7/d71ff4e1e2635c3d7c1be8d96bc40b499c665aad_full.jpg", "image": "https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/d7/d71ff4e1e2635c3d7c1be8d96bc40b499c665aad_full.jpg",
"format": "9v9", "format": "9v9",
"region": "NorthAmerica", "region": "north-america",
"timezone": null, "timezone": null,
"steam_group": "http://steamcommunity.com/groups/BARNEYANDTHEGANKS", "steam_group": "http://steamcommunity.com/groups/BARNEYANDTHEGANKS",
"division": "NA Platinum", "division": "NA Platinum",

View file

@ -115,7 +115,7 @@ pub struct Team {
pub tag: String, pub tag: String,
pub image: String, pub image: String,
pub format: GameMode, pub format: GameMode,
pub region: Region, pub region: Option<Region>,
pub timezone: Option<String>, pub timezone: Option<String>,
pub steam_group: Option<String>, pub steam_group: Option<String>,
pub division: String, pub division: String,
@ -280,6 +280,7 @@ pub struct InvalidGameMode {
#[derive(Debug, Clone, Copy)] #[derive(Debug, Clone, Copy)]
pub enum GameMode { pub enum GameMode {
Highlander, Highlander,
Eights,
Sixes, Sixes,
Fours, Fours,
Ultiduo, Ultiduo,
@ -291,11 +292,13 @@ impl FromStr for GameMode {
fn from_str(s: &str) -> Result<Self, Self::Err> { fn from_str(s: &str) -> Result<Self, Self::Err> {
match s { match s {
"9v9" => Ok(GameMode::Highlander), "9v9" => Ok(GameMode::Highlander),
"8v8" => Ok(GameMode::Eights),
"6v6" => Ok(GameMode::Sixes), "6v6" => Ok(GameMode::Sixes),
"4v4" => Ok(GameMode::Fours), "4v4" => Ok(GameMode::Fours),
"2v2" => Ok(GameMode::Ultiduo), "2v2" => Ok(GameMode::Ultiduo),
"TF2 Highlander" => Ok(GameMode::Highlander), "TF2 Highlander" => Ok(GameMode::Highlander),
"ASIA TF2-H" => Ok(GameMode::Highlander), "ASIA TF2-H" => Ok(GameMode::Highlander),
"TF2 8vs8" => Ok(GameMode::Eights),
"TF2 6vs6" => Ok(GameMode::Sixes), "TF2 6vs6" => Ok(GameMode::Sixes),
"TF2 4vs4" => Ok(GameMode::Fours), "TF2 4vs4" => Ok(GameMode::Fours),
"TF2 2vs2" => Ok(GameMode::Ultiduo), "TF2 2vs2" => Ok(GameMode::Ultiduo),
@ -310,6 +313,7 @@ impl GameMode {
pub fn letter(&self) -> char { pub fn letter(&self) -> char {
match self { match self {
GameMode::Highlander => 'h', GameMode::Highlander => 'h',
GameMode::Eights => '8',
GameMode::Sixes => '6', GameMode::Sixes => '6',
GameMode::Fours => '4', GameMode::Fours => '4',
GameMode::Ultiduo => '2', GameMode::Ultiduo => '2',
@ -319,6 +323,7 @@ impl GameMode {
fn as_str(&self) -> &'static str { fn as_str(&self) -> &'static str {
match self { match self {
GameMode::Highlander => "9v9", GameMode::Highlander => "9v9",
GameMode::Eights => "8v8",
GameMode::Sixes => "6v6", GameMode::Sixes => "6v6",
GameMode::Fours => "4v4", GameMode::Fours => "4v4",
GameMode::Ultiduo => "2v2", GameMode::Ultiduo => "2v2",
@ -358,6 +363,7 @@ pub struct InvalidRegion {
} }
#[derive(Serialize, Deserialize, Copy, Clone, Debug)] #[derive(Serialize, Deserialize, Copy, Clone, Debug)]
#[serde(rename_all = "kebab-case")]
pub enum Region { pub enum Region {
Europe, Europe,
NorthAmerica, NorthAmerica,