mirror of
https://framagit.org/veretcle/oolatoocs.git
synced 2025-07-20 20:41:17 +02:00
Compare commits
9 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
f7e2aafa7b | ||
![]() |
6e9bb6b42c | ||
![]() |
88edb1b2e1 | ||
![]() |
bf9d27df61 | ||
![]() |
496dde60d6 | ||
![]() |
567dfae7ab | ||
![]() |
eeaea52e80 | ||
![]() |
4a0dbb06af | ||
![]() |
5c17ea6989 |
808
Cargo.lock
generated
808
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -1,12 +1,12 @@
|
||||
[package]
|
||||
name = "oolatoocs"
|
||||
version = "2.0.0"
|
||||
version = "2.0.4"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
chrono = "0.4.31"
|
||||
chrono = "^0.4"
|
||||
clap = "^4"
|
||||
env_logger = "^0.10"
|
||||
futures = "^0.3"
|
||||
|
@@ -118,14 +118,15 @@ pub async fn delete_tweet(config: &TwitterConfig, id: u64) -> Result<(), Box<dyn
|
||||
debug!("Deleting Tweet {}", id);
|
||||
let empty_request = EmptyRequest {}; // Why? Because fuck you, that’s why!
|
||||
let token = get_token(config);
|
||||
let delete_uri = format!("{}/{}", TWITTER_API_TWEET_URL, id);
|
||||
|
||||
let client = Client::new();
|
||||
let res = client
|
||||
.delete(format!("{}/{}", TWITTER_API_TWEET_URL, id))
|
||||
.delete(&delete_uri)
|
||||
.header(
|
||||
"Authorization",
|
||||
oauth1_request::delete(
|
||||
format!("{}/{}", TWITTER_API_TWEET_URL, id),
|
||||
&delete_uri,
|
||||
&empty_request,
|
||||
&token,
|
||||
oauth1_request::HMAC_SHA1,
|
||||
@@ -463,7 +464,11 @@ pub fn transform_poll(p: &Poll) -> TweetPoll {
|
||||
let diff = poll_end_datetime.signed_duration_since(now);
|
||||
|
||||
TweetPoll {
|
||||
options: p.options.iter().map(|i| i.title.clone()).collect(),
|
||||
options: p
|
||||
.options
|
||||
.iter()
|
||||
.map(|i| i.title.chars().take(25).collect::<String>())
|
||||
.collect(),
|
||||
duration_minutes: diff.num_minutes().try_into().unwrap(), // safe here, number is positive
|
||||
// and can’t be over 21600
|
||||
}
|
||||
@@ -511,3 +516,41 @@ pub async fn post_tweet(
|
||||
|
||||
Ok(res.data.id.parse::<u64>().unwrap())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use megalodon::entities::PollOption;
|
||||
|
||||
#[test]
|
||||
fn test_transform_poll() {
|
||||
let poll = Poll {
|
||||
id: "youpi".to_string(),
|
||||
expires_at: Some(Utc::now()),
|
||||
expired: false,
|
||||
multiple: false,
|
||||
votes_count: 0,
|
||||
voters_count: None,
|
||||
options: vec![
|
||||
PollOption {
|
||||
title: "Je suis beaucoup trop long comme option, tronque-moi !".to_string(),
|
||||
votes_count: None,
|
||||
},
|
||||
PollOption {
|
||||
title: "nope".to_string(),
|
||||
votes_count: None,
|
||||
},
|
||||
],
|
||||
voted: None,
|
||||
emojis: vec![],
|
||||
};
|
||||
|
||||
let tweet_poll_res = transform_poll(&poll);
|
||||
let tweet_pool_expected = TweetPoll {
|
||||
duration_minutes: 0,
|
||||
options: vec!["Je suis beaucoup trop lon".to_string(), "nope".to_string()],
|
||||
};
|
||||
|
||||
assert_eq!(tweet_poll_res.options, tweet_pool_expected.options);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user