Skip to content

Commit

Permalink
✨ Added gotosocial
Browse files Browse the repository at this point in the history
  • Loading branch information
Miggi committed Dec 1, 2023
1 parent d4e9f59 commit f392690
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/handler/new_room_msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub async fn on_room_message(event: OriginalSyncRoomMessageEvent, room: Room) {
if text_content.body.contains("!ping") {
let content = RoomMessageEventContent::text_plain("Hi 🥹 It's me!");
println!("sending");
room.send(content, None).await.unwrap();
room.send(content).await.unwrap();
println!("message sent");
}

Expand All @@ -22,7 +22,7 @@ pub async fn on_room_message(event: OriginalSyncRoomMessageEvent, room: Room) {
let config = ConfBuilder::new().build();
let healthy_content = build_health_message(&config.services).await;
let content = RoomMessageEventContent::text_plain(healthy_content.content);
if let Err(e) = room.send(content, None).await {
if let Err(e) = room.send(content).await {
eprintln!("Failed to send message! {}", e);
}
});
Expand Down
4 changes: 2 additions & 2 deletions src/handler/send_startup_msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub async fn on_startup_message(client: &Client) {

tokio::spawn(async move {
let content = RoomMessageEventContent::text_plain("Bot is up and running! 👟");
if let Err(e) = room.send(content, None).await {
if let Err(e) = room.send(content).await {
eprintln!("Failed to send message! {}", e);
}

Expand Down Expand Up @@ -68,7 +68,7 @@ pub async fn on_startup_message(client: &Client) {
code = healthy_content.code;
println!("{} Found accessible update!", date);

if let Err(e) = room.send(content, None).await {
if let Err(e) = room.send(content).await {
eprintln!("Failed to send message! {}", e);
}
}
Expand Down
1 change: 1 addition & 0 deletions src/status_checker/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub enum ServiceType {
Keycloak,
Bitwarden,
Wordpress,
Gotosocial,
}

impl fmt::Display for ServiceType {
Expand Down
14 changes: 13 additions & 1 deletion src/status_checker/services.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use reqwest::header::USER_AGENT;

use crate::status_checker::ServiceType;

pub struct Service {
Expand All @@ -23,7 +25,13 @@ impl Service {

pub async fn is_okay(&self) -> bool {
let full_url = self.get_url() + self.get_endpoint().as_str();
let response = reqwest::get(full_url).await;
let client = reqwest::Client::new();
let agent = format!("Ghost-Bot {}", env!("CARGO_PKG_VERSION"));
let response = client
.get(full_url)
.header(USER_AGENT, agent)
.send()
.await;

if let Ok(r) = response {
if !r.status().is_success() {
Expand All @@ -48,6 +56,7 @@ impl Service {
ServiceType::Keycloak => { String::from("/health") }
ServiceType::Bitwarden => { String::from("/alive") }
ServiceType::Wordpress => { String::from("/robots.txt") }
ServiceType::Gotosocial => { String::from("/nodeinfo/2.0") }
}
}

Expand All @@ -74,6 +83,9 @@ impl Service {
ServiceType::Wordpress => {
!body.is_empty()
}
ServiceType::Gotosocial => {
body.contains("name\":\"gotosocial")
}
}
}
}

0 comments on commit f392690

Please sign in to comment.