-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
70 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
use crate::{auth::Token, discord, element::Element, Result}; | ||
use deadpool_sqlite::Pool; | ||
use jsonrpc_v2::{Data, Params}; | ||
use rusqlite::Connection; | ||
use serde::Deserialize; | ||
use serde_json::Value; | ||
use std::sync::Arc; | ||
use time::{format_description::well_known::Iso8601, Duration, OffsetDateTime}; | ||
use tracing::info; | ||
|
||
#[derive(Deserialize)] | ||
pub struct Args { | ||
pub token: String, | ||
pub id: String, | ||
pub days: i64, | ||
} | ||
|
||
pub async fn run(Params(args): Params<Args>, pool: Data<Arc<Pool>>) -> Result<Element> { | ||
let token = pool | ||
.get() | ||
.await? | ||
.interact(move |conn| Token::select_by_secret(&args.token, conn)) | ||
.await?? | ||
.unwrap(); | ||
let element = pool | ||
.get() | ||
.await? | ||
.interact(move |conn| _boost(&args.id, args.days, conn)) | ||
.await??; | ||
let log_message = format!( | ||
"{} boosted element {} https://api.btcmap.org/v3/elements/{} for {} days", | ||
token.owner, | ||
element.name(), | ||
element.id, | ||
args.days, | ||
); | ||
info!(log_message); | ||
discord::send_message_to_channel(&log_message, discord::CHANNEL_API).await; | ||
Ok(element) | ||
} | ||
|
||
fn _boost(id_or_osm_id: &str, days: i64, conn: &Connection) -> Result<Element> { | ||
let element = Element::select_by_id_or_osm_id(id_or_osm_id, conn)?.unwrap(); | ||
let boost_expires = element.tag("boost:expires"); | ||
let boost_expires = match boost_expires { | ||
Value::String(v) => { | ||
OffsetDateTime::parse(v, &Iso8601::DEFAULT).unwrap_or(OffsetDateTime::now_utc()) | ||
} | ||
_ => OffsetDateTime::now_utc(), | ||
}; | ||
let boost_expires = if boost_expires < OffsetDateTime::now_utc() { | ||
OffsetDateTime::now_utc() | ||
} else { | ||
boost_expires | ||
}; | ||
let boost_expires = boost_expires.checked_add(Duration::days(days)).unwrap(); | ||
let element = Element::set_tag( | ||
element.id, | ||
"boost:expires", | ||
&Value::String(boost_expires.format(&Iso8601::DEFAULT)?), | ||
&conn, | ||
)?; | ||
Ok(element) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
pub mod generate_element_issues; | ||
pub mod boost_element; | ||
pub mod generate_element_issues; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters