Skip to content

Commit

Permalink
Merge pull request #33 from Panini-Devs/0.0.1-staging-changes
Browse files Browse the repository at this point in the history
small reworks
  • Loading branch information
paninizer authored Mar 19, 2024
2 parents 35f04d9 + 0bb587c commit ebeed92
Show file tree
Hide file tree
Showing 14 changed files with 364 additions and 48 deletions.
22 changes: 11 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
poise = { version = "0.6.1", features = ["cache"] }
serenity = { version = "0.12.0", default-features = false,features = ["rustls_backend", "chrono", "framework"]}
serde = "1.0.195"
serde_json = "1.0.111"
tracing = "0.1.40"
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"
serde_json = "^1.0.114"
tracing = "^0.1.40"
tracing-subscriber = "^0.3"
dotenv = "^0.15.0"
chrono = "0.4.31"
git2 = "0.18.1"
tokio = { version = "1.35.1", features = ["macros", "signal", "rt-multi-thread"] }
rustrict = "0.7.20"
sqlx = { version = "0.7.3", "features" = [
chrono = "^0.4.34"
git2 = "^0.18.2"
tokio = { version = "^1.36.0", features = ["macros", "signal", "rt-multi-thread"] }
rustrict = "^0.7.21"
sqlx = { version = "^0.7.3", "features" = [
"macros",
"migrate",
"chrono",
Expand All @@ -26,7 +26,7 @@ sqlx = { version = "0.7.3", "features" = [
"sqlite",
"sqlx-sqlite",
] }
reqwest = { version = "0.11.23", features = ["json"] }
reqwest = { version = "0.11.24", features = ["json"] }
lazy_static = "1.4.0"
dashmap = "^5.5.3"
uuid = { version = "1.7.0", features = ["v4"] }
Expand Down
11 changes: 11 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM rust:latest

COPY ./ ./

RUN apt-get update && apt-get install -y cmake && apt-get clean

# install sqlx-cli and run "sqlx database setup" in project directory before running the docker image or the following steps will not compile and will result in error

RUN cargo build --release

CMD ["./target/release/bismarck"]
19 changes: 15 additions & 4 deletions migrations/0_initial.sql
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,27 @@ CREATE TABLE guild_logged_channel (
);

CREATE TABLE user_guild (
user_id BIGINT,
guild_id BIGINT,
user_id BIGINT NOT NULL,
guild_id BIGINT NOT NULL,
join_date TEXT NOT NULL,
first_join_date TEXT NOT NULL,
infractions INT NOT NULL DEFAULT 0,
PRIMARY KEY (user_id, guild_id),
FOREIGN KEY (user_id) REFERENCES user(id) ON DELETE CASCADE,
FOREIGN KEY (guild_id) REFERENCES guild(id) ON DELETE CASCADE
);

CREATE TABLE guild_log (
uuid TEXT NOT NULL,
guild_id BIGINT,
user_id BIGINT,
moderator_id BIGINT,
action_type TEXT NOT NULL,
reason TEXT NOT NULL,
time_created TIMESTAMP NOT NULL,
PRIMARY KEY (uuid),
FOREIGN KEY (guild_id) REFERENCES guild(id) ON DELETE CASCADE,
FOREIGN KEY (moderator_id) REFERENCES user(id)
);

CREATE TABLE item (
id INT PRIMARY KEY,
name TEXT NOT NULL,
Expand Down
7 changes: 5 additions & 2 deletions src/commands/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,12 @@ pub async fn user_avatars(
)]
pub async fn bot_stat(context: Context<'_>) -> Result<(), Error> {
let guild = context.guild().unwrap().id;
let guildid = guild.get();

let commands_ran = context.data().commands_ran.get(&guild.get()).unwrap();
let songs_played = context.data().songs_played.get(&guild.get()).unwrap();
let data = context.data();

let commands_ran = data.commands_ran.get(&guildid).unwrap();
let songs_played = data.songs_played.get(&guildid).unwrap();

let embed = CreateEmbed::new()
.title("**Stats**")
Expand Down
10 changes: 5 additions & 5 deletions src/commands/math.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub async fn add(
Ok(())
}

/// Subtracts two numbers.
/// Divides two numbers.
#[poise::command(
prefix_command,
slash_command,
Expand All @@ -57,11 +57,11 @@ pub async fn add(
)]
pub async fn divide(
context: Context<'_>,
#[description = "Number to be divided"] dividend: Option<f64>,
#[description = "A number to divide One"] divisor: Option<f64>,
#[description = "Number to be divided"] dividend: f64,
#[description = "A number to divide One"] divisor: f64,
) -> Result<(), Error> {
let one = dividend.unwrap_or(1.0);
let two = divisor.unwrap_or(1.0);
let one = dividend;
let two = divisor;

if two == 0.0 {
let _ = context.say("Divisor cannot be 0!").await;
Expand Down
1 change: 1 addition & 0 deletions src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ pub mod owner;
pub mod settings;
pub mod setup;
pub mod utilities;
pub mod wiki;
99 changes: 98 additions & 1 deletion src/commands/moderation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::{
self,
embeds::warnings_command_embed,
messages, models,
modlog::{self, ModType},
modlog::{self, ensure_user, ModType},
},
Context, Error,
};
Expand All @@ -16,6 +16,7 @@ use poise::serenity_prelude::UserId;
use serenity::model::Timestamp;
use tracing::{error, info};

/// Bans a user.
#[poise::command(
prefix_command,
slash_command,
Expand All @@ -38,6 +39,15 @@ pub async fn ban(

let user = models::user(context, user_id).await?;

let member = models::member(context, context.guild_id().unwrap(), user_id).await?;

let ensure = ensure_user(&member, &user_id, &context.guild_id().unwrap(), database).await;

if let Err(why) = ensure {
let _ = messages::error_response(why.to_string(), true).await;
return Ok(());
}

let moderator = context.author();
let moderator_id = moderator.id;

Expand Down Expand Up @@ -119,11 +129,15 @@ pub async fn ban(
if let Err(why) = result {
let reply = messages::error_reply(&why, true);
context.send(reply).await?;
} else {
let reply = messages::info_reply(result.unwrap(), true);
context.send(reply).await?;
}

Ok(())
}

/// Kicks a user.
#[poise::command(
prefix_command,
slash_command,
Expand All @@ -146,6 +160,15 @@ pub async fn kick(

let user = models::user(context, user_id).await?;

let member = models::member(context, context.guild_id().unwrap(), user_id).await?;

let ensure = ensure_user(&member, &user_id, &context.guild_id().unwrap(), database).await;

if let Err(why) = ensure {
let _ = messages::error_response(why.to_string(), true).await;
return Ok(());
}

let moderator = context.author();
let moderator_id = moderator.id;

Expand Down Expand Up @@ -226,12 +249,17 @@ pub async fn kick(

if let Err(why) = result {
let reply = messages::error_reply(&why, true);
context.send(reply).await?;
} else {
let reply = messages::info_reply(result.unwrap(), true);

context.send(reply).await?;
}

Ok(())
}

/// Unbans a user.
#[poise::command(
prefix_command,
slash_command,
Expand All @@ -254,6 +282,15 @@ pub async fn unban(

let user = models::user(context, user_id).await?;

let member = models::member(context, context.guild_id().unwrap(), user_id).await?;

let ensure = ensure_user(&member, &user_id, &context.guild_id().unwrap(), database).await;

if let Err(why) = ensure {
let _ = messages::error_response(why.to_string(), true).await;
return Ok(());
}

let moderator = context.author();
let moderator_id = moderator.id;

Expand Down Expand Up @@ -324,12 +361,17 @@ pub async fn unban(

if let Err(why) = result {
let reply = messages::error_reply(&why, true);
context.send(reply).await?;
} else {
let reply = messages::info_reply(result.unwrap(), true);

context.send(reply).await?;
}

Ok(())
}

/// Times out a user.
#[poise::command(
prefix_command,
slash_command,
Expand Down Expand Up @@ -369,6 +411,15 @@ pub async fn timeout(
return Ok(());
}

let member = models::member(context, context.guild_id().unwrap(), user_id).await?;

let ensure = ensure_user(&member, &user_id, &context.guild_id().unwrap(), database).await;

if let Err(why) = ensure {
let _ = messages::error_response(why.to_string(), true).await;
return Ok(());
}

let reason = reason.unwrap_or_else(|| "No reason provided.".to_string());

let reason_char_count = reason.chars().count();
Expand Down Expand Up @@ -451,12 +502,17 @@ pub async fn timeout(

if let Err(why) = result {
let reply = messages::error_reply(&why, true);
context.send(reply).await?;
} else {
let reply = messages::info_reply(result.unwrap(), true);

context.send(reply).await?;
}

Ok(())
}

/// Un-times out a user.
#[poise::command(
prefix_command,
slash_command,
Expand All @@ -482,6 +538,15 @@ pub async fn untimeout(
return Ok(());
}

let member = models::member(context, context.guild_id().unwrap(), user_id).await?;

let ensure = ensure_user(&member, &user_id, &context.guild_id().unwrap(), database).await;

if let Err(why) = ensure {
let _ = messages::error_response(why.to_string(), true).await;
return Ok(());
}

let result = {
let (user_name, user_mention) = (&user.name, models::user_mention(context, user_id).await?);

Expand Down Expand Up @@ -528,12 +593,17 @@ pub async fn untimeout(

if let Err(why) = result {
let reply = messages::error_reply(&why, true);
context.send(reply).await?;
} else {
let reply = messages::info_reply(result.unwrap(), true);

context.send(reply).await?;
}

Ok(())
}

/// Warns a user.
#[poise::command(
prefix_command,
slash_command,
Expand All @@ -554,6 +624,15 @@ pub async fn warn(

let user = models::user(context, user_id).await?;

let member = models::member(context, context.guild_id().unwrap(), user_id).await?;

let ensure = ensure_user(&member, &user_id, &context.guild_id().unwrap(), database).await;

if let Err(why) = ensure {
let _ = messages::error_response(why.to_string(), true).await;
return Ok(());
}

if user.system {
let reply = messages::error_reply("Cannot warn a system user.", false);
context.send(reply).await?;
Expand Down Expand Up @@ -604,12 +683,17 @@ pub async fn warn(

if let Err(why) = result {
let reply = messages::error_reply(&why, true);
context.send(reply).await?;
} else {
let reply = messages::info_reply(result.unwrap(), true);

context.send(reply).await?;
}

Ok(())
}

/// Gets a user's warnings.
#[poise::command(
prefix_command,
slash_command,
Expand All @@ -628,6 +712,15 @@ pub async fn warnings(

let user = models::user(context, user_id).await?;

let member = models::member(context, context.guild_id().unwrap(), user_id).await?;

let ensure = ensure_user(&member, &user_id, &context.guild_id().unwrap(), database).await;

if let Err(why) = ensure {
let _ = messages::error_response(why.to_string(), true).await;
return Ok(());
}

if user.system {
let reply = messages::error_reply("Cannot get warnings for a system user.", false);
context.send(reply).await?;
Expand Down Expand Up @@ -711,6 +804,10 @@ pub async fn warnings(

if let Err(why) = result {
let reply = messages::error_reply(&why, true);
context.send(reply).await?;
} else {
let reply = messages::info_reply(result.unwrap(), true);

context.send(reply).await?;
}

Expand Down
Loading

0 comments on commit ebeed92

Please sign in to comment.