~foss/ablebot

48e6705881b170f28edde675202d987cbd641ac3 — Foss 2 years ago d2ff3eb
Always keep track of which comment is parsed
1 files changed, 9 insertions(+), 4 deletions(-)

M src/main.rs
M src/main.rs => src/main.rs +9 -4
@@ 43,12 43,14 @@ fn main() {

    let mut client = Client::new("https://raddle.me").unwrap();

    fs::write("last_time.txt", Utc::now().to_rfc3339()).unwrap();
    let mut login = false;

    // Get all the newest comments
    client.comments_until(last_time).unwrap()
        // Turn the vector into an iterator
        .iter()
        // Order the comments by last one first
        .rev()
        // Get the body text as lowercase
        .map(|comment| (comment.body.to_lowercase(), comment))
        // Check if the body text contains slur by making a big list of all the comments in


@@ 60,13 62,16 @@ fn main() {
        .for_each(|((_, comment), (slur, alternative))| {
            println!("Comment {}", comment.id);

            fs::write("last_time.txt", comment.date.to_rfc3339()).unwrap();

            // Login
            client.login("LanguageBot", include_str!("../password.txt").trim()).unwrap();
            if !login {
                client.login("LanguageBot", include_str!("../password.txt").trim()).unwrap();
                login = true;
            }

            // Send a reply comment
            let msg = format!("I've noticed you used the ableist word [\"{}\"](https://www.autistichoya.com/p/ableist-words-and-terms-to-avoid.html) in your comment, please refrain from doing so.  \n_Consider instead: {}_\n###### _Discussion about the words [here](https://raddle.me/f/Ability/55653/languagebot-list-of-ableist-words), stop this message from being posted by quoting the word: \"{}\"_", slur, alternative, slur);
            client.reply_comment(comment.submission_id, comment.id, &*msg).unwrap();
        });

    fs::write("last_time.txt", Utc::now().to_rfc3339()).unwrap();
}