Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
66163b7
My awesome changes
hiimjasmine00 Jan 15, 2025
46559a2
These are probably the last ones
hiimjasmine00 Jan 15, 2025
c018573
Fix a few bugs
hiimjasmine00 Jan 15, 2025
af6122c
improved three lines
hiimjasmine00 Jan 15, 2025
72169fc
add empty checks
hiimjasmine00 Jan 16, 2025
65a6fa1
Merge branch 'main' into index-forums
hiimjasmine00 Jan 17, 2025
4bc4062
fix a bit more
hiimjasmine00 Jan 17, 2025
4452dd9
Merge branch 'main' of https://github.com/geode-sdk/server into index…
hiimjasmine00 Jan 18, 2025
1bb6fe4
clone things before refactoring
hiimjasmine00 Jan 18, 2025
03d2914
Merge branch 'main' of https://github.com/geode-sdk/server into index…
hiimjasmine00 Jan 18, 2025
71be8fa
Okay, maybe I'll test these
hiimjasmine00 Jan 18, 2025
12f7ee6
Merge branch 'main' of https://github.com/geode-sdk/server into index…
hiimjasmine00 Jan 18, 2025
e5dab29
Merge branch 'main' of https://github.com/geode-sdk/server into index…
hiimjasmine00 Jan 20, 2025
4b31786
I think this should be it
hiimjasmine00 Jan 20, 2025
9fe2160
remove refs
hiimjasmine00 Jan 20, 2025
419e69a
Simplify parameters
hiimjasmine00 Jan 20, 2025
8e955e0
clean up code
hiimjasmine00 Jan 21, 2025
eed95c0
Merge branch 'main' of https://github.com/geode-sdk/server into index…
hiimjasmine00 Jan 23, 2025
dfe36bd
Merge branch 'main' of https://github.com/geode-sdk/server into index…
hiimjasmine00 Jan 27, 2025
ee4e75e
create pending threads from oldest to newest
hiimjasmine00 Jan 27, 2025
f0d934b
change button ids
hiimjasmine00 Jan 27, 2025
9557b48
Merge branch 'main' of https://github.com/geode-sdk/server into index…
hiimjasmine00 Nov 13, 2025
8d2f024
Get back up to speed
hiimjasmine00 Nov 13, 2025
3d27a4c
Clean up a little
hiimjasmine00 Nov 13, 2025
5aa5a52
Clean up messages
hiimjasmine00 Nov 13, 2025
b3e4e38
Replace with helper
hiimjasmine00 Nov 13, 2025
8ad8dad
Forgot these
hiimjasmine00 Nov 13, 2025
ba3db91
This is probably how it should go
hiimjasmine00 Nov 13, 2025
81e0d70
Zero deletions!
hiimjasmine00 Nov 13, 2025
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
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ GITHUB_CLIENT_SECRET=
# Discord

DISCORD_WEBHOOK_URL=
DISCORD_BOT_TOKEN=
DISCORD_GUILD_ID=
DISCORD_CHANNEL_ID=

# Config

Expand Down
44 changes: 44 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pub struct AppData {
front_url: String,
github: GitHubClientData,
webhook_url: String,
discord: DiscordForumData,
disable_downloads: bool,
max_download_mb: u32,
port: u16,
Expand All @@ -17,6 +18,13 @@ pub struct GitHubClientData {
client_secret: String,
}

#[derive(Clone)]
pub struct DiscordForumData {
guild_id: u64,
channel_id: u64,
bot_token: String,
}

pub async fn build_config() -> anyhow::Result<AppData> {
let env_url = dotenvy::var("DATABASE_URL")?;

Expand All @@ -31,6 +39,15 @@ pub async fn build_config() -> anyhow::Result<AppData> {
let github_client = dotenvy::var("GITHUB_CLIENT_ID").unwrap_or("".to_string());
let github_secret = dotenvy::var("GITHUB_CLIENT_SECRET").unwrap_or("".to_string());
let webhook_url = dotenvy::var("DISCORD_WEBHOOK_URL").unwrap_or("".to_string());
let guild_id = dotenvy::var("DISCORD_GUILD_ID")
.unwrap_or("0".to_string())
.parse::<u64>()
.unwrap_or(0);
let channel_id = dotenvy::var("DISCORD_CHANNEL_ID")
.unwrap_or("0".to_string())
.parse::<u64>()
.unwrap_or(0);
let bot_token = dotenvy::var("DISCORD_BOT_TOKEN").unwrap_or("".to_string());
let disable_downloads =
dotenvy::var("DISABLE_DOWNLOAD_COUNTS").unwrap_or("0".to_string()) == "1";
let max_download_mb = dotenvy::var("MAX_MOD_FILESIZE_MB")
Expand All @@ -47,6 +64,11 @@ pub async fn build_config() -> anyhow::Result<AppData> {
client_secret: github_secret,
},
webhook_url,
discord: DiscordForumData {
guild_id,
channel_id,
bot_token,
},
disable_downloads,
max_download_mb,
port,
Expand All @@ -64,6 +86,24 @@ impl GitHubClientData {
}
}

impl DiscordForumData {
pub fn is_valid(&self) -> bool {
self.guild_id != 0 && self.channel_id != 0 && !self.bot_token.is_empty()
}

pub fn guild_id(&self) -> u64 {
self.guild_id
}

pub fn channel_id(&self) -> u64 {
self.channel_id
}

pub fn bot_auth(&self) -> String {
format!("Bot {}", self.bot_token)
}
}

impl AppData {
pub fn db(&self) -> &sqlx::postgres::PgPool {
&self.db
Expand All @@ -85,6 +125,10 @@ impl AppData {
&self.webhook_url
}

pub fn discord(&self) -> &DiscordForumData {
&self.discord
}

pub fn disable_downloads(&self) -> bool {
self.disable_downloads
}
Expand Down
27 changes: 27 additions & 0 deletions src/endpoints/mod_versions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use crate::types::models;
use crate::webhook::discord::DiscordWebhook;
use crate::{
extractors::auth::Auth,
forum,
types::{
api::ApiResponse,
mod_json::{split_version_and_compare, ModJson},
Expand Down Expand Up @@ -355,6 +356,8 @@ pub async fn create_version(
.collect(),
);

let json_version = json.version.clone();

if make_accepted {
if let Some(links) = json.links.clone() {
mod_links::upsert(
Expand Down Expand Up @@ -397,6 +400,17 @@ pub async fn create_version(

version.modify_metadata(data.app_url(), false);

if !make_accepted {
forum::discord::create_or_update_thread(
data.discord().clone(),
id,
json_version,
"".to_string(),
data.app_url().to_string(),
pool,
);
}

Ok(HttpResponse::Created().json(ApiResponse {
error: "".into(),
payload: version,
Expand Down Expand Up @@ -497,6 +511,8 @@ pub async fn update_version(

tx.commit().await?;

let display_name = dev.display_name.clone();

if payload.status == ModVersionStatusEnum::Accepted {
let is_update = approved_count > 0;

Expand Down Expand Up @@ -531,5 +547,16 @@ pub async fn update_version(
}
}

if payload.status == ModVersionStatusEnum::Accepted || payload.status == ModVersionStatusEnum::Rejected {
forum::discord::create_or_update_thread(
data.discord().clone(),
path.id.clone(),
path.version.clone(),
display_name,
data.app_url().to_string(),
pool
);
}

Ok(HttpResponse::NoContent())
}
10 changes: 10 additions & 0 deletions src/endpoints/mods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use crate::database::repository::mods;
use crate::endpoints::ApiError;
use crate::events::mod_feature::ModFeaturedEvent;
use crate::extractors::auth::Auth;
use crate::forum;
use crate::mod_zip;
use crate::types::api::{create_download_link, ApiResponse};
use crate::types::mod_json::ModJson;
Expand Down Expand Up @@ -220,6 +221,15 @@ pub async fn create(
i.modify_metadata(data.app_url(), false);
}

forum::discord::create_or_update_thread(
data.discord().clone(),
json.id,
json.version,
"".to_string(),
data.app_url().to_string(),
pool
);

Ok(HttpResponse::Created().json(ApiResponse {
error: "".into(),
payload: the_mod,
Expand Down
Loading