Updates lmao
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
Julius 2024-10-17 15:50:06 +02:00
parent fca4872a73
commit 7d098f6b5d
Signed by: j00lz
GPG key ID: AF241B0AA237BBA2
5 changed files with 736 additions and 402 deletions

1
.gitignore vendored
View file

@ -1 +1,2 @@
/target
.env

1077
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -6,5 +6,10 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
serenity = { version = "0.11.2", features = ["model", "client", "gateway", "rustls_backend"], default-features = false }
tokio = { version = "1.19.2", features = ["macros", "rt-multi-thread"] }
serenity = { version = "0.12", features = [
"model",
"client",
"gateway",
"rustls_backend",
], default-features = false, git = "https://github.com/serenity-rs/serenity.git", branch = "current" }
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }

View file

@ -1,4 +1,4 @@
from rust:1.61.0-alpine as builder
FROM rust:1.61.0-alpine as builder
WORKDIR /app
@ -14,7 +14,7 @@ COPY src /app/src
RUN cargo build --release
from alpine as runtime
FROM alpine as runtime
COPY --from=builder /app/target/release/pinbot-rs /app/pinbot-rs

View file

@ -1,8 +1,9 @@
use serenity::{
all::ActivityData,
client::{Context, EventHandler},
model::{
channel::Reaction,
gateway::{Activity, Ready},
gateway::Ready,
id::{ChannelId, MessageId},
},
prelude::GatewayIntents,
@ -14,26 +15,28 @@ struct Handler;
#[serenity::async_trait]
impl EventHandler for Handler {
async fn ready(&self, c: Context, r: Ready) {
let name = r.user.name;
c.set_activity(Activity::playing("5x📌 pins a message!"))
.await;
let name = &r.user.name;
c.set_activity(Some(ActivityData::custom("5x📌 pins a message!")));
println!("{} is online!", name);
}
async fn reaction_add(&self, c: Context, r: Reaction) {
// println!("Reaction added: {:?}", r);
if let Err(e) = handle_react(c, r).await {
println!("Error: {:?}", e);
}
}
async fn reaction_remove(&self, c: Context, r: Reaction) {
// println!("Reaction removed: {:?}", r);
if let Err(e) = handle_react(c, r).await {
println!("Error: {:?}", e);
}
}
async fn reaction_remove_all(&self, c: Context, c_id: ChannelId, m_id: MessageId) {
let msg = match c.http.get_message(c_id.0, m_id.0).await {
// println!("All reactions removed from message: {:?}", m_id);
let msg = match c.http.get_message(c_id, m_id).await {
Ok(m) => m,
Err(e) => {
println!("Error: {:?}", e);
@ -49,19 +52,23 @@ impl EventHandler for Handler {
}
async fn handle_react(c: Context, r: Reaction) -> Result<(), serenity::Error> {
let emoji = r.emoji.as_data();
if emoji == "📌" {
let msg = r.message(c.http.clone()).await?;
for r in &msg.reactions {
let emoji = r.reaction_type.as_data();
if emoji == "📌" {
let count = r.count;
if count >= 5 {
msg.pin(c.http.clone()).await?;
} else if count < 3 {
msg.unpin(&c.http).await?;
}
}
println!("Handling reaction: {:?}", r);
if r.emoji.unicode_eq("📌") {
println!("Pin reaction detected!");
let msg = r.message(&c).await?;
// println!("Message: {:?}", msg);
let count = msg
.reactions
.iter()
.find(|r| r.reaction_type.unicode_eq("📌"))
.map(|r| r.count)
.unwrap_or_default();
println!("Pin count: {}", count);
if count >= 1 {
msg.pin(&c).await?;
} else if count < 3 {
msg.unpin(&c).await?;
}
}
Ok(())
@ -70,7 +77,9 @@ async fn handle_react(c: Context, r: Reaction) -> Result<(), serenity::Error> {
#[tokio::main]
async fn main() {
let token = std::env::var("DISCORD_TOKEN").expect("Where discord token?");
let intents = GatewayIntents::GUILD_MESSAGE_REACTIONS | GatewayIntents::GUILD_MESSAGES;
let intents = GatewayIntents::GUILD_MESSAGE_REACTIONS
| GatewayIntents::GUILD_MESSAGES
| GatewayIntents::GUILD_MESSAGE_REACTIONS;
let mut client = Client::builder(token, intents)
.event_handler(Handler)