Add hyperlink to video game in start.gg

This commit is contained in:
Kiana Sheibani 2023-11-26 00:22:48 -05:00
parent faf0f30d36
commit 3836ccfb9f
Signed by: toki
GPG key ID: 6CB106C25E86A9F7
3 changed files with 27 additions and 21 deletions

View file

@ -11,6 +11,7 @@ pub struct DatasetMetadata {
pub game_id: VideogameId, pub game_id: VideogameId,
pub game_name: String, pub game_name: String,
pub game_slug: String,
pub country: Option<String>, pub country: Option<String>,
pub state: Option<String>, pub state: Option<String>,
@ -47,6 +48,7 @@ CREATE TABLE IF NOT EXISTS datasets (
last_sync INTEGER NOT NULL, last_sync INTEGER NOT NULL,
game_id INTEGER NOT NULL, game_id INTEGER NOT NULL,
game_name TEXT NOT NULL, game_name TEXT NOT NULL,
game_slug TEXT NOT NULL,
country TEXT, country TEXT,
state TEXT, state TEXT,
set_limit INTEGER NOT NULL, set_limit INTEGER NOT NULL,
@ -87,6 +89,7 @@ pub fn list_datasets(connection: &Connection) -> sqlite::Result<Vec<(String, Dat
last_sync: Timestamp(r_.read::<i64, _>("last_sync") as u64), last_sync: Timestamp(r_.read::<i64, _>("last_sync") as u64),
game_id: VideogameId(r_.read::<i64, _>("game_id") as u64), game_id: VideogameId(r_.read::<i64, _>("game_id") as u64),
game_name: r_.read::<&str, _>("game_name").to_owned(), game_name: r_.read::<&str, _>("game_name").to_owned(),
game_slug: r_.read::<&str, _>("game_slug").to_owned(),
country: r_.read::<Option<&str>, _>("country").map(String::from), country: r_.read::<Option<&str>, _>("country").map(String::from),
state: r_.read::<Option<&str>, _>("state").map(String::from), state: r_.read::<Option<&str>, _>("state").map(String::from),
set_limit: r_.read::<i64, _>("set_limit") as u64, set_limit: r_.read::<i64, _>("set_limit") as u64,
@ -117,7 +120,7 @@ pub fn new_dataset(
dataset: &str, dataset: &str,
metadata: DatasetMetadata, metadata: DatasetMetadata,
) -> sqlite::Result<()> { ) -> sqlite::Result<()> {
let query1 = r#"INSERT INTO datasets VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"#; let query1 = r#"INSERT INTO datasets VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"#;
let query2 = format!( let query2 = format!(
r#"CREATE TABLE "{0}_players" ( r#"CREATE TABLE "{0}_players" (
id INTEGER PRIMARY KEY, id INTEGER PRIMARY KEY,
@ -176,13 +179,14 @@ CREATE VIEW "{0}_view"
.bind((2, metadata.last_sync.0 as i64))? .bind((2, metadata.last_sync.0 as i64))?
.bind((3, metadata.game_id.0 as i64))? .bind((3, metadata.game_id.0 as i64))?
.bind((4, &metadata.game_name[..]))? .bind((4, &metadata.game_name[..]))?
.bind((5, metadata.country.as_deref()))? .bind((5, &metadata.game_slug[..]))?
.bind((6, metadata.state.as_deref()))? .bind((6, metadata.country.as_deref()))?
.bind((7, metadata.set_limit as i64))? .bind((7, metadata.state.as_deref()))?
.bind((8, metadata.decay_rate))? .bind((8, metadata.set_limit as i64))?
.bind((9, metadata.adj_decay_rate))? .bind((9, metadata.decay_rate))?
.bind((10, metadata.period))? .bind((10, metadata.adj_decay_rate))?
.bind((11, metadata.tau))? .bind((11, metadata.period))?
.bind((12, metadata.tau))?
.try_for_each(|x| x.map(|_| ()))?; .try_for_each(|x| x.map(|_| ()))?;
connection.execute(query2) connection.execute(query2)
@ -205,6 +209,7 @@ pub fn get_metadata(
last_sync: Timestamp(r_.read::<i64, _>("last_sync") as u64), last_sync: Timestamp(r_.read::<i64, _>("last_sync") as u64),
game_id: VideogameId(r_.read::<i64, _>("game_id") as u64), game_id: VideogameId(r_.read::<i64, _>("game_id") as u64),
game_name: r_.read::<&str, _>("game_name").to_owned(), game_name: r_.read::<&str, _>("game_name").to_owned(),
game_slug: r_.read::<&str, _>("game_slug").to_owned(),
country: r_.read::<Option<&str>, _>("country").map(String::from), country: r_.read::<Option<&str>, _>("country").map(String::from),
state: r_.read::<Option<&str>, _>("state").map(String::from), state: r_.read::<Option<&str>, _>("state").map(String::from),
set_limit: r_.read::<i64, _>("set_limit") as u64, set_limit: r_.read::<i64, _>("set_limit") as u64,
@ -579,6 +584,7 @@ CREATE TABLE IF NOT EXISTS datasets (
last_sync: Timestamp(1), last_sync: Timestamp(1),
game_id: VideogameId(0), game_id: VideogameId(0),
game_name: String::from("Test Game"), game_name: String::from("Test Game"),
game_slug: String::from("test"),
country: None, country: None,
state: None, state: None,
set_limit: 0, set_limit: 0,

View file

@ -115,25 +115,20 @@ fn dataset_list() {
let datasets = list_datasets(&connection).expect("Error communicating with SQLite"); let datasets = list_datasets(&connection).expect("Error communicating with SQLite");
for (name, metadata) in datasets { for (name, metadata) in datasets {
println!(); print!(
"\n\x1b[1m\x1b[4m{}\x1b[0m - \
\x1b]8;;https://www.start.gg/{}\x1b\\{}\x1b]8;;\x1b\\ ",
name, metadata.game_slug, metadata.game_name
);
if let Some(country) = metadata.country { if let Some(country) = metadata.country {
if let Some(state) = metadata.state { if let Some(state) = metadata.state {
println!( println!("(in {}, {})", country, state);
"\x1b[1m\x1b[4m{}\x1b[0m - {} (in {}, {})",
name, metadata.game_name, country, state
);
} else { } else {
println!( println!("(in {})", country);
"\x1b[1m\x1b[4m{}\x1b[0m - {} (in {})",
name, metadata.game_name, country
);
} }
} else { } else {
println!( println!("(Global)");
"\x1b[1m\x1b[4m{}\x1b[0m - {} (Global)",
name, metadata.game_name
);
} }
let current_time = SystemTime::now() let current_time = SystemTime::now()
@ -222,6 +217,7 @@ fn dataset_new(name: Option<String>, auth_token: Option<String>) {
let VideogameData { let VideogameData {
id: game_id, id: game_id,
name: game_name, name: game_name,
slug: game_slug,
} = games[index].clone(); } = games[index].clone();
// Location // Location
@ -407,6 +403,7 @@ Tau constant (default 0.4): "
last_sync: Timestamp(1), last_sync: Timestamp(1),
game_id, game_id,
game_name, game_name,
game_slug,
country, country,
state, state,
set_limit, set_limit,

View file

@ -28,6 +28,7 @@ struct VideogameConnection {
struct Videogame { struct Videogame {
id: Option<VideogameId>, id: Option<VideogameId>,
name: Option<String>, name: Option<String>,
slug: Option<String>,
} }
// Unwrapping // Unwrapping
@ -36,6 +37,7 @@ struct Videogame {
pub struct VideogameData { pub struct VideogameData {
pub id: VideogameId, pub id: VideogameId,
pub name: String, pub name: String,
pub slug: String,
} }
impl<'a> QueryUnwrap<VideogameSearchVars<'a>> for VideogameSearch { impl<'a> QueryUnwrap<VideogameSearchVars<'a>> for VideogameSearch {
@ -52,6 +54,7 @@ impl<'a> QueryUnwrap<VideogameSearchVars<'a>> for VideogameSearch {
Some(VideogameData { Some(VideogameData {
id: game.id?, id: game.id?,
name: game.name?, name: game.name?,
slug: game.slug?,
}) })
}) })
.collect(), .collect(),