Delete guilds that no longer exist
This commit is contained in:
parent
6f71e41b71
commit
c4cc584c29
25
src/main.rs
25
src/main.rs
@ -42,25 +42,34 @@ fn main() {
|
|||||||
if let Ok(guild_list) = wynncraft::guild_list() {
|
if let Ok(guild_list) = wynncraft::guild_list() {
|
||||||
let conn = establish_connection();
|
let conn = establish_connection();
|
||||||
|
|
||||||
|
let mut guilds = vec![];
|
||||||
|
|
||||||
guild_list.into_iter().for_each(|name| {
|
guild_list.into_iter().for_each(|name| {
|
||||||
thread::sleep_ms(2500);
|
thread::sleep_ms(2500);
|
||||||
println!("Getting {:?}", name);
|
println!("Getting {:?}", name);
|
||||||
if let Ok(Some(prefix)) = wynncraft::guild(&name).map(|x| x.map(|x| x.prefix)) {
|
if let Ok(Some(prefix)) = wynncraft::guild(&name).map(|x| x.map(|x| x.prefix)) {
|
||||||
let guild = Guild { prefix: prefix.trim().to_owned(), name };
|
let guild = Guild { prefix: prefix.trim().to_owned(), name };
|
||||||
if let Ok(_) = diesel::insert_into(guilds::table)
|
guilds.push(guild);
|
||||||
.values(&guild)
|
|
||||||
.on_conflict(guilds::prefix)
|
|
||||||
.do_nothing()
|
|
||||||
.execute(&conn) {
|
|
||||||
let _ = reqwest::get("https://wynnapi.herokuapp.com/").unwrap();
|
let _ = reqwest::get("https://wynnapi.herokuapp.com/").unwrap();
|
||||||
} else {
|
} else {
|
||||||
println!("Fail!");
|
println!("Fail!");
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
println!("Fail!");
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if let Err(e) = diesel::delete(guilds::table).execute(&conn) {
|
||||||
|
println!("Mysterious error from DB: {:?}", e);
|
||||||
|
}
|
||||||
|
println!("Inserting guilds...");
|
||||||
|
for guild in &guilds {
|
||||||
|
if let Err(e) = diesel::insert_into(guilds::table)
|
||||||
|
.values(guild)
|
||||||
|
.on_conflict(guilds::prefix)
|
||||||
|
.do_nothing()
|
||||||
|
.execute(&conn) {
|
||||||
|
println!("Mysterious error from DB: {:?}", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
println!("Guilds updated!");
|
println!("Guilds updated!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user