Skip to content

Commit

Permalink
feat: revamp db, autorole add, autorole toggle
Browse files Browse the repository at this point in the history
  • Loading branch information
newtykip committed Jul 23, 2023
1 parent e9202a0 commit 7194318
Show file tree
Hide file tree
Showing 41 changed files with 1,049 additions and 594 deletions.
50 changes: 25 additions & 25 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,45 +10,45 @@ jobs:
matrix:
# the database driver to compile with
db: [
# postgres,
# mysql,
postgres,
mysql,
sqlite
]
# the feature combinations to compile - should be all combinations of modules
features: [
# [moderation], [image],
[moderation], [image],
[moderation, image]
]
# whether the tui feature flag should be enabled or not
tui: [
true,
# false
false
]
platform:
# x86_64
# - os_name: linux-x86_64
# os: ubuntu-latest
# target: x86_64-unknown-linux-gnu
# bin: johnny
# name: johnny-linux-x86_64-gnu.tar.gz
# cross: false
# cargo_command: cargo
- os_name: linux-x86_64
os: ubuntu-latest
target: x86_64-unknown-linux-gnu
bin: johnny
name: johnny-linux-x86_64-gnu.tar.gz
cross: false
cargo_command: cargo

# - os_name: windows-x86_64
# os: windows-latest
# target: x86_64-pc-windows-msvc
# bin: johnny.exe
# name: johnny-windows-x86_64.zip
# cross: false
# cargo_command: cargo
- os_name: windows-x86_64
os: windows-latest
target: x86_64-pc-windows-msvc
bin: johnny.exe
name: johnny-windows-x86_64.zip
cross: false
cargo_command: cargo

# - os_name: macos-x86_64
# os: macos-latest
# target: x86_64-apple-darwin
# bin: johnny
# name: johnny-darwin-x86_64.tar.gz
# cross: false
# cargo_command: cargo
- os_name: macos-x86_64
os: macos-latest
target: x86_64-apple-darwin
bin: johnny
name: johnny-darwin-x86_64.tar.gz
cross: false
cargo_command: cargo

# arm64
- os_name: linux-aarch64
Expand Down
16 changes: 16 additions & 0 deletions .vscode/command.code-snippets
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"generate": {
"description": "Generate a command function",
"scope": "rust",
"prefix": "cmd",
"body": [
"use johnny::preludes::command::*;",
"",
"/// $3",
"#[command(slash_command, category = \"$2\")]",
"pub async fn $1(ctx: Context<'_>) -> Result<()> {",
" Ok(())",
"}"
]
}
}
4 changes: 3 additions & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"recommendations": [
"rust-lang.rust-analyzer"
"rust-lang.rust-analyzer",
"github.vscode-github-actions",
"aaron-bond.better-comments"
]
}
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ dev = ["dep:dotenvy_macro"] # never enable this in production

[dependencies]
async-trait = { version = "0.1.71", optional = true }
cfg-if = "1.0.0"
chrono = "0.4.26"
color-eyre = "0.6.2"
crossterm = { version = "0.26.1", optional = true }
Expand Down
10 changes: 9 additions & 1 deletion migration/src/m20230712_192057_autorole.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,15 @@ create_migration!(
.on_delete(ForeignKeyAction::Cascade),
)
// role snowflake
.col(ColumnDef::new(Autorole::RoleId).text().not_null()),
.col(ColumnDef::new(Autorole::RoleId).text().not_null())
// guild and role id must both be unique
.index(
Index::create()
.name("autorole_guild_id_role_id_idx")
.col(Autorole::GuildId)
.col(Autorole::RoleId)
.unique()
),
GuildId,
RoleId,
);
8 changes: 8 additions & 0 deletions migration/src/m20230716_231443_member.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ create_migration!(
.to_tbl(User::Table)
.to_col(User::Id)
.on_delete(ForeignKeyAction::Cascade)
)
// guild and user id must both be unique
.index(
Index::create()
.name("member_guild_id_user_id_idx")
.col(Member::GuildId)
.col(Member::UserId)
.unique()
),
GuildId,
UserId,
Expand Down
64 changes: 35 additions & 29 deletions src/commands/general/ping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ async fn run(ctx: Context<'_>) -> Result<()> {
#[cfg(not(johnny))]
ctx.defer_ephemeral().await?;

let base_embed = generate_base_embed(ctx.author(), ctx.author_member().await);
let base_embed = generate_embed(ctx.author(), ctx.author_member().await, None);

// if the johnny feature is enabled, add a random johnny image
#[cfg(johnny)]
Expand All @@ -23,14 +23,16 @@ async fn run(ctx: Context<'_>) -> Result<()> {
msg.embed(|embed| {
embed.clone_from(&base_embed);

#[cfg(johnny)]
return embed
.title("meow!")
.image(&johnny_image)
.footer(|footer| footer.text(&footer_text));

#[cfg(not(johnny))]
embed.title("ping!")
cfg_if! {
if #[cfg(johnny)] {
embed
.title("meow!")
.image(&johnny_image)
.footer(|footer| footer.text(&footer_text))
} else {
embed.title("ping!")
}
}
})
})
.await?;
Expand All @@ -45,31 +47,35 @@ async fn run(ctx: Context<'_>) -> Result<()> {
msg.embed(|embed| {
embed.clone_from(&base_embed);

#[cfg(johnny)]
return embed
.title(format!("meow! ({} ms)", ping))
.image(johnny_image)
.footer(|footer| footer.text(footer_text));

#[cfg(not(johnny))]
embed.title(format!("ping! ({} ms)", ping))
cfg_if! {
if #[cfg(johnny)] {
embed
.title(format!("meow! ({} ms)", ping))
.image(&johnny_image)
.footer(|footer| footer.text(&footer_text))
} else {
embed.title(format!("ping! ({} ms)", ping))
}
}
})
})
.await?;

Ok(())
}

/// checks ping
#[cfg(not(johnny))]
#[command(slash_command)]
pub async fn ping(ctx: Context<'_>) -> Result<()> {
run(ctx).await
}

/// meow! (checks ping)
#[cfg(johnny)]
#[command(slash_command, rename = "meow")]
pub async fn ping(ctx: Context<'_>) -> Result<()> {
run(ctx).await
cfg_if! {
if #[cfg(johnny)] {
/// meow! (checks ping)
#[command(slash_command, rename = "meow")]
pub async fn ping(ctx: Context<'_>) -> Result<()> {
run(ctx).await
}
} else {
/// checks ping
#[command(slash_command)]
pub async fn ping(ctx: Context<'_>) -> Result<()> {
run(ctx).await
}
}
}
2 changes: 1 addition & 1 deletion src/commands/image/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
use johnny::load_command;

load_command!(pride, pride);
load_command!(pride | pride);
125 changes: 0 additions & 125 deletions src/commands/image/pride.rs

This file was deleted.

38 changes: 38 additions & 0 deletions src/commands/image/pride/circle.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
use super::{fetch_image, flag_autocomplete};
use johnny::preludes::command::*;
use pride_overlay::{circle as circle_pride, Flags};
use std::{borrow::Cow, io::Cursor, str::FromStr};

/// Draw a circle with the colours of a pride flag around an image
#[command(slash_command)]
pub async fn circle(
ctx: Context<'_>,
#[description = "The flag to use"]
#[autocomplete = "flag_autocomplete"]
flag: String,
#[description = "The file to apply the effect to"] attachment: Option<Attachment>,
#[description = "The thickness of the ring"] thickness: Option<u8>,
) -> Result<()> {
ctx.defer().await?;

let flag = Flags::from_str(&flag)?;
let image = circle_pride(
&mut fetch_image(&ctx, attachment).await?,
flag.into(),
thickness,
);

let mut bytes = vec![];
image.write_to(&mut Cursor::new(&mut bytes), image::ImageOutputFormat::Png)?;

// send the image
ctx.send(|msg| {
msg.attachment(AttachmentType::Bytes {
data: Cow::Borrowed(bytes.as_slice()),
filename: "pride.png".into(),
})
})
.await?;

Ok(())
}
Loading

0 comments on commit 7194318

Please sign in to comment.