Compare commits

..

No commits in common. "main" and "1.0.0" have entirely different histories.
main ... 1.0.0

3 changed files with 15 additions and 38 deletions

2
Cargo.lock generated
View file

@ -133,7 +133,7 @@ dependencies = [
[[package]]
name = "ets2newscord"
version = "1.0.1"
version = "1.0.0"
dependencies = [
"chrono",
"serde",

View file

@ -1,6 +1,6 @@
[package]
name = "ets2newscord"
version = "1.0.1"
version = "1.0.0"
edition = "2021"
[profile.release]

View file

@ -8,10 +8,7 @@ use std::{
io::{self, Read, Seek, Write},
};
const APPID: &str = "227300"; // ETS2: 227300, AssettoCorsa: 244210
const CLANIMGURLBASE: &str =
"https://cdn.akamai.steamstatic.com/steamcommunity/public/images/clans/";
const LOGOURL: &str = "https://eurotrucksimulator2.com/images/logo.png";
const APPID: &str = "227300";
#[derive(Deserialize)]
struct SUResp {
@ -91,44 +88,32 @@ fn main() {
.split("[img]{STEAM_CLAN_IMAGE}")
.collect();
let imgurl = if tmptext.len() > 1 {
let splitend: Vec<&str> = tmptext[1].split("[/img]").collect();
format!("{}{}", CLANIMGURLBASE, splitend[0])
} else {
LOGOURL.to_string()
};
let tmptext2: Vec<&str> = tmptext[1].split("[/img]").collect();
let imgurl = &tmptext2[0];
let whreq: String = format!(
r#"
{{
"username": "ETS2 Updates",
"avatar_url": "{}",
"avatar_url": "https://eurotrucksimulator2.com/images/logo.png",
"content": "",
"embeds": [{{
"title": "{}",
"description": "{}",
"url": "{}",
"timestamp": "{}",
"thumbnail": {{"url": "{}"}}
"thumbnail": {{"url": "https://cdn.akamai.steamstatic.com/steamcommunity/public/images/clans/{}"}}
}}]
}}
"#,
LOGOURL,
body.appnews.newsitems.post0.title,
if body.appnews.newsitems.post0.contents.len() > 250 {
format!(
"{} ...",
body.appnews.newsitems.post0.contents[..250]
.to_string()
.replace("\n", " ")
body.appnews.newsitems.post0.contents[..250].to_string()
)
} else {
body.appnews
.newsitems
.post0
.contents
.to_string()
.replace("\n", " ")
body.appnews.newsitems.post0.contents.to_string()
},
body.appnews.newsitems.post0.url,
t_str,
@ -138,23 +123,15 @@ fn main() {
let resp = ureq::post(&webhook)
.set("Content-Type", "application/json;charset=utf-8")
.send_string(&whreq);
match resp {
Ok(_) => {
println!("Successfully updated webhook");
f.set_len(0).expect("Cannot empty the file");
f.seek(io::SeekFrom::Start(0))
.expect("Cannot seek to file beginning");
write!(f, "{}", body.appnews.newsitems.post0.date).expect("Can't write file");
}
Err(e) => {
println!("Error updating webhook:\n{}\nRequest JSON:\n{}", e, &whreq);
}
}
resp.expect("Error sending Discord webhook");
fdt = body.appnews.newsitems.post0.date;
}
f.set_len(0).expect("Cannot empty the file");
f.seek(io::SeekFrom::Start(0))
.expect("Cannot seek to file beginning");
write!(f, "{}", body.appnews.newsitems.post0.date).expect("Can't write file");
println!("{}: Sleeping...", chrono::offset::Utc::now());
thread::sleep(time::Duration::from_secs(60 * 15));
}