Skip to content

Commit

Permalink
Merge branch '0.0.1-staging-changes' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
paninizer authored May 13, 2024
2 parents 0deecba + fb09e50 commit ec8fb33
Show file tree
Hide file tree
Showing 37 changed files with 699 additions and 250 deletions.
27 changes: 26 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,33 @@ name = "bismarck"
version = "0.0.1"
edition = "2021"

[workspace]
members = [
"bismarck_commands",
"bismarck_core",
"bismarck_events",
"bismarck_utilities"
]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
dotenv = { workspace = true }
poise = { workspace = true }
serenity = { workspace = true }
sqlx = { workspace = true }
dashmap = { workspace = true }
reqwest = { workspace = true }
tokio = { workspace = true }
tracing = { workspace = true }
tracing-subscriber = { workspace = true }

bismarck_commands = { path = "bismarck_commands" }
bismarck_core = { path = "bismarck_core" }
bismarck_events = { path = "bismarck_events" }
bismarck_utilities = { path = "bismarck_utilities" }

[workspace.dependencies]
poise = { git = "https://github.com/serenity-rs/poise/", branch = "current", features = ["cache"] }
serenity = { version = "^0.12.1", default-features = false, features = ["rustls_backend", "chrono", "gateway"] }
serde = "^1.0.197"
Expand Down Expand Up @@ -34,11 +58,12 @@ dashmap = "^5.5.3"
uuid = { version = "1.7.0", features = ["v4"] }
duration-str = "0.10.0"


rand = "0.8"


[profile.release]
opt-level = 3

[build]
rustflags = ["-Z", "threads=8", "target-cpu=native"]
rustflags = ["-Z", "threads=8", "-C", "target-cpu=native"]
24 changes: 24 additions & 0 deletions bismarck_commands/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[package]
name = "bismarck_commands"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]

chrono = { workspace = true }
duration-str = { workspace = true }
poise = { workspace = true }
serenity = { workspace = true }
serde_json = { workspace = true }
sqlx = { workspace = true }
git2 = { workspace = true }
reqwest = { workspace = true }
sysinfo = { workspace = true }
tracing = { workspace = true }

rand = { workspace = true }

bismarck_utilities = { path = "../bismarck_utilities" }
bismarck_core = { path = "../bismarck_core" }
4 changes: 2 additions & 2 deletions src/commands/info.rs → bismarck_commands/src/info.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::sync::atomic::Ordering;

use crate::utilities::git::{get_current_branch, get_head_revision};
use crate::{Context, Error};
use bismarck_core::{context::Context, error::Error};
use bismarck_utilities::git::{get_current_branch, get_head_revision};
use git2::Repository;
use poise::{serenity_prelude as serenity, CreateReply};

Expand Down
2 changes: 0 additions & 2 deletions src/commands/mod.rs → bismarck_commands/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
pub mod info;
pub mod math;
pub mod moderation;
pub mod neko;
pub mod owner;
pub mod settings;
pub mod setup;
pub mod utilities;
pub mod wiki;
Expand Down
51 changes: 22 additions & 29 deletions src/commands/moderation.rs → bismarck_commands/src/moderation.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
use std::time::Duration;

use crate::{
utilities::{
self,
embeds::warnings_command_embed,
messages, models,
modlog::{self, ensure_user, ModType},
},
Context, Error,
};
use bismarck_core::{context::Context, error::Error};
use bismarck_utilities::{embeds::warnings_command_embed, messages, models, modlog::*, paginate};

use chrono::{Days, NaiveDateTime, Utc};
use duration_str::parse;
Expand Down Expand Up @@ -88,7 +81,7 @@ pub async fn ban(

let created_at = Utc::now().naive_utc();

let mut user_mod_history = modlog::select_modlog_from_users(&user_id, database).await?;
let mut user_mod_history = select_modlog_from_users(&user_id, database).await?;

let message = messages::info_message(format!(
"You've been banned from {guild_name} by {moderator_mention} for {reason}.",
Expand All @@ -101,7 +94,7 @@ pub async fn ban(

match guild_id.ban_with_reason(context, user_id, 0, &reason).await {
Ok(_) => {
modlog::insert_modlog(
insert_modlog(
ModType::Ban,
&guild_id,
&user_id,
Expand All @@ -114,7 +107,7 @@ pub async fn ban(

user_mod_history += 1;

modlog::update_users_set_modlog(&user_id, user_mod_history, database).await?;
update_users_set_modlog(&user_id, user_mod_history, database).await?;

info!("@{moderator_name} banned @{user_name} from {guild_name}: {reason}");
Ok(format!("{user_mention} has been banned."))
Expand Down Expand Up @@ -209,7 +202,7 @@ pub async fn kick(

let created_at = Utc::now().naive_utc();

let mut user_mod_history = modlog::select_modlog_from_users(&user_id, database).await?;
let mut user_mod_history = select_modlog_from_users(&user_id, database).await?;

let message = messages::info_message(format!(
"You've been kicked from {guild_name} by {moderator_mention} for {reason}.",
Expand All @@ -222,7 +215,7 @@ pub async fn kick(

match guild_id.kick_with_reason(context, user_id, &reason).await {
Ok(_) => {
modlog::insert_modlog(
insert_modlog(
ModType::Kick,
&guild_id,
&user_id,
Expand All @@ -235,7 +228,7 @@ pub async fn kick(

user_mod_history += 1;

modlog::update_users_set_modlog(&user_id, user_mod_history, database).await?;
update_users_set_modlog(&user_id, user_mod_history, database).await?;

info!("@{moderator_name} kicked @{user_name} from {guild_name}: {reason}");
Ok(format!("{user_mention} has been kicked."))
Expand Down Expand Up @@ -330,11 +323,11 @@ pub async fn unban(

let created_at = Utc::now().naive_utc();

let mut user_mod_history = modlog::select_modlog_from_users(&user_id, database).await?;
let mut user_mod_history = select_modlog_from_users(&user_id, database).await?;

match guild_id.unban(context, user_id).await {
Ok(_) => {
modlog::insert_modlog(
insert_modlog(
ModType::Unban,
&guild_id,
&user_id,
Expand All @@ -347,7 +340,7 @@ pub async fn unban(

user_mod_history += 1;

modlog::update_users_set_modlog(&user_id, user_mod_history, database).await?;
update_users_set_modlog(&user_id, user_mod_history, database).await?;

info!("@{moderator_name} unbanned @{user_name} from {guild_name}: {reason}");
Ok(format!("{user_mention} has been unbanned."))
Expand Down Expand Up @@ -468,14 +461,14 @@ pub async fn timeout(

let created_at = Utc::now().naive_utc();

let mut user_mod_history = modlog::select_modlog_from_users(&user_id, database).await?;
let mut user_mod_history = select_modlog_from_users(&user_id, database).await?;

match member
.disable_communication_until_datetime(context, time)
.await
{
Ok(_) => {
modlog::insert_modlog(
insert_modlog(
ModType::Timeout,
&guild_id,
&user_id,
Expand All @@ -488,7 +481,7 @@ pub async fn timeout(

user_mod_history += 1;

modlog::update_users_set_modlog(&user_id, user_mod_history, database).await?;
update_users_set_modlog(&user_id, user_mod_history, database).await?;

info!("@{moderator_name} timed out @{user_name} from {guild_name}: {reason}");
Ok(format!("{user_mention} has been timed out."))
Expand Down Expand Up @@ -562,11 +555,11 @@ pub async fn untimeout(

let created_at = Utc::now().naive_utc();

let mut user_mod_history = modlog::select_modlog_from_users(&user_id, database).await?;
let mut user_mod_history = select_modlog_from_users(&user_id, database).await?;

match member.enable_communication(context).await {
Ok(_) => {
modlog::insert_modlog(
insert_modlog(
ModType::Untimeout,
&guild_id,
&user_id,
Expand All @@ -579,7 +572,7 @@ pub async fn untimeout(

user_mod_history += 1;

modlog::update_users_set_modlog(&user_id, user_mod_history, database).await?;
update_users_set_modlog(&user_id, user_mod_history, database).await?;

info!("@{moderator_id} untimed out @{user_name} from {guild_name}");
Ok(format!("{user_mention} has been untimed out."))
Expand Down Expand Up @@ -652,9 +645,9 @@ pub async fn warn(

let created_at = Utc::now().naive_utc();

let mut user_mod_history = modlog::select_modlog_from_users(&user_id, database).await?;
let mut user_mod_history = select_modlog_from_users(&user_id, database).await?;

match modlog::insert_modlog(
match insert_modlog(
ModType::Warn,
&guild_id,
&user_id,
Expand All @@ -668,7 +661,7 @@ pub async fn warn(
Ok(_) => {
user_mod_history += 1;

modlog::update_users_set_modlog(&user_id, user_mod_history, database).await?;
update_users_set_modlog(&user_id, user_mod_history, database).await?;

info!("@{moderator_id} warned @{user_name} from {guild_name}");
Ok(format!("{user_mention} has been warned."))
Expand Down Expand Up @@ -733,7 +726,7 @@ pub async fn warnings(
let guild_id = context.guild_id().unwrap();

let user_mod_history =
match modlog::select_modlog(ModType::Warn, &user_id, &guild_id, database).await {
match select_modlog(ModType::Warn, &user_id, &guild_id, database).await {
Ok(user_mod_history) => user_mod_history,
Err(why) => {
error!("Couldn't select warnings from infractions: {why:?}");
Expand Down Expand Up @@ -789,7 +782,7 @@ pub async fn warnings(
));
});

match utilities::paginate::paginate(context, embeds).await {
match paginate::paginate(context, embeds).await {
Ok(_) => {
let author = context.author().id;
info!("@{author} requested @{user_name}'s warnings");
Expand Down
2 changes: 1 addition & 1 deletion src/commands/neko.rs → bismarck_commands/src/neko.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use poise::CreateReply;
use serenity::all::{CreateEmbed, CreateEmbedFooter};

use crate::{utilities::types::Items, Context, Error};
use bismarck_core::{context::Context, error::Error, types::Items};

/// Sends a random Neko image.
#[poise::command(
Expand Down
18 changes: 18 additions & 0 deletions bismarck_commands/src/owner.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use bismarck_core::{context::Context, error::Error};
use poise;

/// Shuts down the bot gracefully
#[poise::command(prefix_command, owners_only, hide_in_help)]
pub async fn shutdown(ctx: Context<'_>) -> Result<(), Error> {
ctx.framework().shard_manager().shutdown_all().await;
Ok(())
}

/// Utility for global application commands for owner of bot
#[poise::command(prefix_command, owners_only, hide_in_help)]
pub async fn register(ctx: Context<'_>) -> Result<(), Error> {
poise::builtins::register_application_commands_buttons(ctx)
.await
.unwrap();
Ok(())
}
File renamed without changes.
2 changes: 1 addition & 1 deletion src/commands/setup.rs → bismarck_commands/src/setup.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{utilities::types::GuildSettings, Context, Error};
use bismarck_core::{context::Context, error::Error, types::GuildSettings};
use poise::{serenity_prelude as serenity, CreateReply};
use serenity::{CreateEmbed, CreateEmbedFooter};
use tracing::info;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{Context, Error};
use bismarck_core::{context::Context, error::Error};
use chrono::Duration;
use chrono::Utc;
use poise::builtins::PrettyHelpConfiguration;
Expand Down
Loading

0 comments on commit ec8fb33

Please sign in to comment.