Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
DISCORD_TOKEN=

GITHUB_TOKEN=

REDIS_URL=redis://default:password@localhost:6379/0

DATABASE_URL=postgres://vaffelbot:vaffelbot@localhost:5432/vaffelbot
Expand Down
96 changes: 96 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ chrono = { version = "0.4", features = ["serde"] }
dotenv = "0.15.0"
poise = "0.6.1"
redis = { version = "0.30.0", features = ["tokio-comp", "connection-manager"] }
reqwest = { version = "0.12", features = ["json"] }
serde = { version = "1.0.228", features = ["derive"] }
serde_json = "1.0.149"
serenity = "0.12.5"
Expand Down
65 changes: 65 additions & 0 deletions src/adapters/discord/commands/feedback.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
use poise::CreateReply;
use serde_json::json;

use crate::adapters::discord::{Context, Error};

/// Send inn tilbakemelding til vaffelbot
#[tracing::instrument(name = "feedback", skip(ctx))]
#[poise::command(slash_command, prefix_command, rename = "tilbakemelding")]
pub async fn feedback(
ctx: Context<'_>,
#[description = "Tilbakemeldingen din"] message: String,
) -> Result<(), Error> {
let github_token = match &ctx.data().github_token {
Some(token) => token.clone(),
None => {
ctx.send(
CreateReply::default()
.content("❌ Tilbakemelding er ikke konfigurert.")
.ephemeral(true),
)
.await?;
return Ok(());
}
};

let author = ctx.author();
let title = "Tilbakemelding fra Discord".to_string();
let body = format!(
"**Tilbakemelding fra Discord-bruker:** {}\n\n---\n\n{}",
author.name, message
);

let client = reqwest::Client::new();
let response = client
.post("https://api.github.com/repos/echo-webkom/vaffelbot/issues")
.header("Accept", "application/vnd.github+json")
.header("Authorization", format!("Bearer {}", github_token))
.header("X-GitHub-Api-Version", "2026-03-10")
.header("User-Agent", "vaffelbot")
.json(&json!({
"title": title,
"body": body,
"labels": ["feedback"]
}))
.send()
.await?;

if response.status().is_success() {
ctx.send(
CreateReply::default()
.content("✅ Takk for tilbakemeldingen! Den er sendt inn.")
.ephemeral(true),
)
.await?;
} else {
ctx.send(
CreateReply::default()
.content("❌ Noe gikk galt. Prøv igjen senere.")
.ephemeral(true),
)
.await?;
}

Ok(())
}
1 change: 1 addition & 0 deletions src/adapters/discord/commands/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pub mod bake;
pub mod close;
pub mod feedback;
pub mod github;
pub mod open;
pub mod ping;
Expand Down
6 changes: 6 additions & 0 deletions src/adapters/discord/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,28 @@ pub type Context<'a> = poise::Context<'a, Data, Error>;
pub struct Data {
pub queue: Arc<dyn QueueRepository>,
pub orders: Arc<dyn OrderRepository>,
pub github_token: Option<String>,
}

pub struct DiscordAdapter {
token: String,
queue: Arc<dyn QueueRepository>,
orders: Arc<dyn OrderRepository>,
github_token: Option<String>,
}

impl DiscordAdapter {
pub fn new(
token: String,
queue: Arc<dyn QueueRepository>,
orders: Arc<dyn OrderRepository>,
github_token: Option<String>,
) -> Self {
Self {
token,
queue,
orders,
github_token,
}
}

Expand All @@ -43,6 +47,7 @@ impl DiscordAdapter {
commands::bake::bake(),
commands::close::close(),
commands::github::github(),
commands::feedback::feedback(),
commands::open::open(),
commands::ping::ping(),
commands::queue_size::queue(),
Expand All @@ -62,6 +67,7 @@ impl DiscordAdapter {
Ok(Data {
queue: self.queue.clone(),
orders: self.orders.clone(),
github_token: self.github_token.clone(),
})
})
})
Expand Down
3 changes: 3 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ pub struct Config {
pub redis_url: String,
pub discord_token: String,
pub database_url: String,
pub github_token: Option<String>,
}

impl Config {
Expand All @@ -13,11 +14,13 @@ impl Config {
std::env::var("DISCORD_TOKEN").expect("Expected a token in the environment");
let database_url =
std::env::var("DATABASE_URL").expect("Expected DATABASE_URL in environment");
let github_token = std::env::var("GITHUB_TOKEN").ok();

Self {
redis_url,
discord_token,
database_url,
github_token,
}
}
}
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ impl VaffelBot {
self.config.discord_token.clone(),
queue.clone(),
orders.clone(),
self.config.github_token.clone(),
);

let http_adapter = HttpAdapter::new(queue.clone(), orders.clone());
Expand Down