Skip to content

Commit

Permalink
modular deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
SkohTV committed Feb 16, 2025
1 parent d6f427a commit 3dbe19d
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 88 deletions.
27 changes: 0 additions & 27 deletions Cargo.lock

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

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ version = "5.3.0"
edition = "2021"

[dependencies]
const_format = "0.2.34"
dotenv = "0.15.0"
libsql = "0.6.0"
poise = { version = "0.6.1", features = ["cache"] }
Expand Down
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ COPY --from=builder /quantum/target/release/quantum /quantum/bin

RUN apt-get update && apt-get install -y ca-certificates

ENV RELEASE=1
ENTRYPOINT ["/quantum/bin"]
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Quantum

## Build

```sh
# Using branch 'release'
git clone -b release https://github.com/SkohTV/quantum

git reset --hard && git pull
docker kill quantum && docker rm quantum
docker build . -t quantum && docker run --name=quantum -t quantum -d
```

---

### Commands
Expand Down
19 changes: 13 additions & 6 deletions src/consts.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
use const_format::concatcp;
pub const MAJOR: u8 = 5;
pub const MINOR: u8 = 4;

const MAJOR: u8 = 5;
const MINOR: u8 = 4;
pub fn mode() -> &'static str {
let val = std::env::var("RELEASE");

pub const MODE: &str = "dev";
// pub const MODE: &str = "release";
if val.is_ok() && val.unwrap() == "1" {
"release"
} else {
"dev"
}
}

pub const VERSION: &str = concatcp!(MAJOR, ".", MINOR, "-", MODE);
pub fn version() -> String {
format!("{}.{}-{}", MAJOR, MINOR, mode())
}
32 changes: 9 additions & 23 deletions src/discord/app.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
use poise::serenity_prelude as serenity;
use crate::consts;
use crate::discord::{commands, framework, Data, ids, Handler};


use crate::discord::{commands, framework, ids, Data, Handler};
use poise::serenity_prelude as serenity;

pub async fn app() {
let token = std::env::var(format!("DISCORD_TOKEN_{}", consts::MODE.to_uppercase()))
let token = std::env::var(format!("DISCORD_TOKEN_{}", consts::mode().to_uppercase()))
.expect("missing or wrong DISCORD_TOKEN_???");

let intents = serenity::GatewayIntents::GUILD_MEMBERS |
serenity::GatewayIntents::GUILDS;
let intents = serenity::GatewayIntents::GUILD_MEMBERS | serenity::GatewayIntents::GUILDS;

let status = serenity::OnlineStatus::Online;
let activity = serenity::ActivityData::playing(consts::VERSION);

let activity = serenity::ActivityData::playing(consts::version());

let options = poise::FrameworkOptions {

commands: vec![
commands::ping::cmd(),
commands::embed::cmd(),
Expand All @@ -33,7 +28,6 @@ pub async fn app() {
..Default::default()
};


let framework = poise::Framework::builder()
.options(options)
.setup(|ctx, _ready, framework| {
Expand All @@ -46,28 +40,20 @@ pub async fn app() {
// main_guild.delete_command(ctx, cmd.id).await.unwrap();
// }

poise::builtins::register_in_guild(
ctx,
&framework.options().commands,
main_guild
).await?;
poise::builtins::register_in_guild(ctx, &framework.options().commands, main_guild)
.await?;

Ok(Data { })
Ok(Data {})
})
})
.build();


let client = serenity::ClientBuilder::new(token, intents)
.framework(framework)
.status(status)
.activity(activity)
.event_handler(Handler)
.await;

client
.unwrap()
.start()
.await
.unwrap();
client.unwrap().start().await.unwrap();
}
13 changes: 4 additions & 9 deletions src/discord/default.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
use crate::consts;
use poise::serenity_prelude as serenity;



pub fn embed() -> serenity::CreateEmbed {

let (name, pfp) = match consts::MODE {
let (name, pfp) = match consts::mode() {
"dev" => ("Quantum Dev", "https://cdn.discordapp.com/avatars/1042497340352770142/17aa48868280edeb5edda826a0e49e48?size=1024"),
"release" => ("Quantum", "https://cdn.discordapp.com/avatars/1033842126334742659/5235b0f44210455555f1685cac3580b9?size=1024"),
err => panic!("Incorrect bot mode (not 'release' or 'dev') => {}", err)
};


let author = serenity::CreateEmbedAuthor::new(name)
.url("https://github.com/SkohTV/quantum/")
.icon_url(pfp);

let footer = serenity::CreateEmbedFooter::new(format!(
"Running on version {}", consts::VERSION
));

let footer =
serenity::CreateEmbedFooter::new(format!("Running on version {}", consts::version()));

serenity::CreateEmbed::default()
.author(author)
Expand Down
50 changes: 28 additions & 22 deletions src/discord/framework.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
use poise::serenity_prelude as serenity;
use crate::discord::{Data, Context, Error, logging, ids};
use crate::consts;


use crate::discord::{ids, logging, Context, Data, Error};
use poise::serenity_prelude as serenity;

pub async fn on_error(error: poise::FrameworkError<'_, Data, Error>) {

match error {
poise::FrameworkError::Setup { error, .. } => panic!("Failed to start bot: {:?}", error),
poise::FrameworkError::Command { error, ctx, .. } => {
Expand All @@ -18,11 +15,14 @@ pub async fn on_error(error: poise::FrameworkError<'_, Data, Error>) {
);

logging::log_to_discord(&ctx, msg, logging::LogRole::Error).await;
let _ = ctx.send(poise::CreateReply::default()
.content(format!("An error happened\n```{}```", error))
.ephemeral(true)
).await;
},
let _ = ctx
.send(
poise::CreateReply::default()
.content(format!("An error happened\n```{}```", error))
.ephemeral(true),
)
.await;
}
error => {
if let Err(e) = poise::builtins::on_error(error).await {
println!("Error while handling error: {}", e)
Expand All @@ -31,8 +31,6 @@ pub async fn on_error(error: poise::FrameworkError<'_, Data, Error>) {
}
}



pub async fn post_command(ctx: Context<'_>) {
let msg = format!(
"{} in <#{}>\n➜ `/{}`\nSuccess",
Expand All @@ -44,13 +42,13 @@ pub async fn post_command(ctx: Context<'_>) {
logging::log_to_discord(&ctx, msg, logging::LogRole::Success).await;
}



pub async fn command_check(ctx: Context<'_>) -> Result<bool, Box<dyn std::error::Error + Send + Sync>> {
pub async fn command_check(
ctx: Context<'_>,
) -> Result<bool, Box<dyn std::error::Error + Send + Sync>> {
// Channel check
let channels = match consts::MODE {
"dev" => vec!(ids::PRIVATE_BOT_CHANNEL),
"release" => vec!(ids::PUBLIC_BOT_CHANNEL, ids::PRIVATE_BOT_CHANNEL),
let channels = match consts::mode() {
"dev" => vec![ids::PRIVATE_BOT_CHANNEL],
"release" => vec![ids::PUBLIC_BOT_CHANNEL, ids::PRIVATE_BOT_CHANNEL],
_ => panic!("Invalid MODE"),
};

Expand All @@ -60,18 +58,26 @@ pub async fn command_check(ctx: Context<'_>) -> Result<bool, Box<dyn std::error:
.collect::<Vec<_>>();

if !channels.contains(&ctx.channel_id()) {

let msg = poise::CreateReply::default()
.content(format!("You can't use commands here, try in <#{}>", ids::PUBLIC_BOT_CHANNEL))
.content(format!(
"You can't use commands here, try in <#{}>",
ids::PUBLIC_BOT_CHANNEL
))
.ephemeral(true);

ctx.send(msg).await?;

logging::log_to_discord(
ctx,
format!("{} tried to run `/{}` in <#{}>", ctx.author(), ctx.command().name, ctx.channel_id()),
format!(
"{} tried to run `/{}` in <#{}>",
ctx.author(),
ctx.command().name,
ctx.channel_id()
),
logging::LogRole::Error,
).await;
)
.await;

return Ok(false);
}
Expand Down

0 comments on commit 3dbe19d

Please sign in to comment.