2024-10-30 17:48:58 +03:00
|
|
|
use reqwest::header::AUTHORIZATION;
|
2024-10-30 16:33:08 +03:00
|
|
|
use serenity::all::ActivityData;
|
2024-10-30 14:00:36 +03:00
|
|
|
use serenity::async_trait;
|
2024-10-30 17:48:58 +03:00
|
|
|
use serenity::json::json;
|
2024-10-30 14:00:36 +03:00
|
|
|
use serenity::model::channel::Message;
|
|
|
|
use serenity::model::prelude::*;
|
|
|
|
use serenity::prelude::*;
|
2024-10-30 16:33:08 +03:00
|
|
|
use shuttle_runtime::SecretStore;
|
2024-10-30 14:00:36 +03:00
|
|
|
|
2024-10-30 17:48:58 +03:00
|
|
|
struct Handler {
|
|
|
|
http: reqwest::Client,
|
|
|
|
secrets: SecretStore,
|
|
|
|
}
|
2024-10-30 14:00:36 +03:00
|
|
|
|
|
|
|
#[async_trait]
|
|
|
|
impl EventHandler for Handler {
|
2024-10-30 17:48:58 +03:00
|
|
|
async fn message(&self, _: Context, msg: Message) {
|
|
|
|
if msg.content.starts_with("do ") {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let mut note_content = msg.content.clone();
|
|
|
|
|
|
|
|
const BSKY_TAG: &str = ".nobsky";
|
2024-10-30 18:12:43 +03:00
|
|
|
let no_bsky_posse = note_content.contains(BSKY_TAG);
|
|
|
|
if no_bsky_posse {
|
2024-10-30 17:48:58 +03:00
|
|
|
note_content = note_content.replace(BSKY_TAG, "");
|
|
|
|
}
|
|
|
|
|
2024-10-30 18:12:43 +03:00
|
|
|
let note_data = json!({"content": note_content.trim(), "bskyPosse": !no_bsky_posse});
|
2024-10-30 17:48:58 +03:00
|
|
|
let resp = self
|
|
|
|
.http
|
|
|
|
.post("https://gaze.systems/log/create")
|
|
|
|
.header(AUTHORIZATION, self.secrets.get("DISCORD_TOKEN").unwrap())
|
|
|
|
.json(¬e_data)
|
|
|
|
.send()
|
|
|
|
.await
|
|
|
|
.and_then(|resp| resp.error_for_status());
|
|
|
|
|
|
|
|
if let Err(why) = resp {
|
|
|
|
tracing::error!("could not create note: {why}");
|
2024-10-30 14:00:36 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-10-30 16:33:08 +03:00
|
|
|
async fn ready(&self, ctx: Context, ready: Ready) {
|
2024-10-30 17:48:58 +03:00
|
|
|
tracing::info!("{} is connected!", ready.user.name);
|
2024-10-30 16:33:08 +03:00
|
|
|
|
2024-10-30 17:48:58 +03:00
|
|
|
ctx.set_presence(
|
|
|
|
Some(ActivityData::listening("messages")),
|
|
|
|
OnlineStatus::Online,
|
|
|
|
);
|
2024-10-30 14:00:36 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-10-30 16:33:08 +03:00
|
|
|
#[shuttle_runtime::main]
|
|
|
|
async fn serenity(
|
|
|
|
#[shuttle_runtime::Secrets] secrets: SecretStore,
|
|
|
|
) -> shuttle_serenity::ShuttleSerenity {
|
|
|
|
let token = secrets.get("DISCORD_TOKEN").unwrap();
|
|
|
|
|
|
|
|
let intents = GatewayIntents::DIRECT_MESSAGES | GatewayIntents::MESSAGE_CONTENT;
|
|
|
|
|
|
|
|
let client = Client::builder(&token, intents)
|
2024-10-30 17:48:58 +03:00
|
|
|
.event_handler(Handler {
|
|
|
|
http: reqwest::Client::new(),
|
|
|
|
secrets,
|
|
|
|
})
|
2024-10-30 16:33:08 +03:00
|
|
|
.await
|
|
|
|
.expect("Err creating client");
|
|
|
|
|
|
|
|
Ok(client.into())
|
2024-10-30 17:48:58 +03:00
|
|
|
}
|