website/gazebot/src/main.rs

62 lines
1.8 KiB
Rust
Raw Normal View History

2024-10-30 14:00:36 +03:00
use std::env;
2024-10-30 16:33:08 +03:00
use serenity::all::ActivityData;
2024-10-30 14:00:36 +03:00
use serenity::async_trait;
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
struct Handler;
#[async_trait]
impl EventHandler for Handler {
async fn message(&self, ctx: Context, msg: Message) {
if msg.content == "!ping" {
if let Err(why) = msg.channel_id.say(&ctx.http, "Pong!").await {
println!("Error sending message: {why:?}");
}
}
}
2024-10-30 16:33:08 +03:00
async fn ready(&self, ctx: Context, ready: Ready) {
2024-10-30 14:00:36 +03:00
println!("{} is connected!", ready.user.name);
2024-10-30 16:33:08 +03:00
ctx.set_presence(Some(ActivityData::listening("messages to log")), OnlineStatus::Online);
2024-10-30 14:00:36 +03:00
}
}
2024-10-30 16:33:08 +03:00
// #[tokio::main]
// async fn main() {
// let _ = dotenvy::dotenv();
2024-10-30 14:00:36 +03:00
2024-10-30 16:33:08 +03:00
// tracing_subscriber::fmt::init();
2024-10-30 14:00:36 +03:00
2024-10-30 16:33:08 +03:00
// let token = env::var("DISCORD_TOKEN").expect("Expected a token in the environment");
// let intents = GatewayIntents::DIRECT_MESSAGES | GatewayIntents::MESSAGE_CONTENT;
2024-10-30 14:00:36 +03:00
2024-10-30 16:33:08 +03:00
// let mut client =
// Client::builder(&token, intents).event_handler(Handler).await.expect("Err creating client");
2024-10-30 14:00:36 +03:00
2024-10-30 16:33:08 +03:00
// if let Err(why) = client.start().await {
// println!("Client error: {why:?}");
// }
// }
#[shuttle_runtime::main]
async fn serenity(
#[shuttle_runtime::Secrets] secrets: SecretStore,
) -> shuttle_serenity::ShuttleSerenity {
// Get the discord token set in `Secrets.toml`
let token = secrets.get("DISCORD_TOKEN").unwrap();
// Set gateway intents, which decides what events the bot will be notified about
let intents = GatewayIntents::DIRECT_MESSAGES | GatewayIntents::MESSAGE_CONTENT;
let client = Client::builder(&token, intents)
.event_handler(Handler)
.await
.expect("Err creating client");
Ok(client.into())
2024-10-30 14:00:36 +03:00
}