Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: dependency fixes #49

Merged
merged 4 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ version = "0.1.0"
rustflags = ["--cfg", "tokio_unstable"]

[dependencies]
serenity = {version="0.12.0"}
serenity = { version = "0.12.0" }
lazy_static = "1.4"
reqwest = { version = "0.11", features = ["json"] }
reqwest = { version = "0.12", features = ["json"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
serde_repr = "0.1"
Expand All @@ -27,8 +27,8 @@ regex = "1.10"
num_cpus = "1.16"
threadpool = "1.8"
tokio = { version = "1.36.0", features = ["full", "tracing"] }
mongodb = "2.8"
mongodb = "3.0"
futures = "0.3"
itertools = "0.12.0"
itertools = "0.13.0"
http = "1.0.0"
serde_regex = "1.1.0"
16 changes: 3 additions & 13 deletions okto_framework/src/handler.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
use std::collections::HashMap;

use serenity::{
client::Context,
framework::standard::CommandResult,
http::Http,
model::application::Interaction,
Result,
};
use serenity::{client::Context, http::Http, model::application::Interaction, Result};

use crate::structs::{
Command,
DiscordCommandDetails,
};
use crate::structs::{Command, CommandResult, DiscordCommandDetails};

#[derive(Clone)]
pub struct Handler {
Expand Down Expand Up @@ -90,8 +81,7 @@ impl Handler {

pub async fn upload_commands(&self, http: impl AsRef<Http>) -> Result<()> {
let body = serde_json::to_value(
self
.cmds
self.cmds
.values()
.map(|c| {
c.options
Expand Down
18 changes: 7 additions & 11 deletions okto_framework/src/structs.rs
Original file line number Diff line number Diff line change
@@ -1,29 +1,25 @@
use std::fmt;
use std::{error::Error as StdError, fmt};

use futures::future::BoxFuture;
use serde::Serialize;
use serde_repr::Serialize_repr;
use serenity::{
client::Context,
framework::standard::CommandResult,
model::{
application::CommandInteraction,
channel::ChannelType,
Permissions,
},
model::{application::CommandInteraction, channel::ChannelType, Permissions},
};

pub type CommandError = Box<dyn StdError + Send + Sync>;
pub type CommandResult<T = ()> = std::result::Result<T, CommandError>;

#[derive(Clone)]
pub struct Command {
pub options: &'static CommandDetails,
pub func: CommandFunc,
pub info: &'static CommandInfo,
}

pub type CommandFunc = for<'fut> fn(
&'fut Context,
&'fut CommandInteraction,
) -> BoxFuture<'fut, CommandResult>;
pub type CommandFunc =
for<'fut> fn(&'fut Context, &'fut CommandInteraction) -> BoxFuture<'fut, CommandResult>;

#[derive(Debug, Clone)]
pub struct CommandDetails {
Expand Down
76 changes: 40 additions & 36 deletions src/commands/general.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,19 @@ use std::collections::HashMap;

use chrono::Utc;
use itertools::Itertools;
use okto_framework::macros::command;
use okto_framework::{macros::command, structs::CommandResult};
use rand::seq::SliceRandom;
use serde::{
Deserialize,
Serialize,
};
use serde::{Deserialize, Serialize};
use serenity::{
builder::{
CreateEmbed,
CreateEmbedAuthor,
CreateEmbedFooter,
CreateInteractionResponse,
CreateInteractionResponseMessage,
EditInteractionResponse,
},
framework::standard::CommandResult,
model::{
application::CommandInteraction,
Colour,
CreateEmbed, CreateEmbedAuthor, CreateEmbedFooter, CreateInteractionResponse,
CreateInteractionResponseMessage, EditInteractionResponse,
},
model::{application::CommandInteraction, Colour},
prelude::Context,
};

use crate::{
models::caches::PictureCacheKey,
utils::constants::*,
};
use crate::{models::caches::PictureCacheKey, utils::constants::*};

#[command]
/// Get the ping of the bot
Expand Down Expand Up @@ -76,25 +62,49 @@ async fn info(ctx: &Context, interaction: &CommandInteraction) -> CommandResult
.cache
.current_user()
.id;

let mut stats = String::new();
if OWNER_ID
== interaction
.user
.id
{
stats = format!(
"**Approx total members:** {}\n",
ctx.cache
.guilds()
.into_iter()
.map(|id| ctx
.cache
.guild(id)
.map_or(0, |g| {
match g.approximate_member_count {
Some(0..=1) | None => g.member_count,
Some(n) => n,
}
}))
.sum::<u64>()
);
}

interaction.create_response(&ctx.http, CreateInteractionResponse::Message(CreateInteractionResponseMessage::new().embed(CreateEmbed::new()
.title("OKTO")
.description(
format!(
"This is a bot to show upcoming launches and provide additional information on everything to do with spaceflight\n\
**Author:** Calli#3141\n\
**Author:** callieve\n\
**Version:** `4.0` \"slash-commands\"\n\
**Source Code:** [GitHub link](https://github.com/callieve/okto)\n\
**Library:** [Serenity](https://github.com/serenity-rs/serenity)\n\
**Total servers:** {}\n\
**Total servers:** {}\n{}\
<:RustRainbow:752508751675654204>\n\
\n<:discord:314003252830011395>\n\
[**Support Server**](https://discord.gg/dXPHfPJ)\n\
[**The Space Devs**](https://discord.gg/p7ntkNA)\n\
[**Rocket Watch server**](https://discord.gg/Hyd4umg)\n\
\n<:botTag:230105988211015680>\n\
If you want OKTO on your server, click [**here**](https://discord.com/api/oauth2/authorize?client_id={}&permissions=388160&scope=bot%20applications.commands)\n\
If you like OKTO, please [**vote**](https://discordbots.org/bot/429306620439166977/vote) ^-^",
ctx.cache.guild_count(), user_id
ctx.cache.guild_count(), stats, user_id
)
)
.author(CreateEmbedAuthor::new("Bot Information")
Expand Down Expand Up @@ -512,12 +522,10 @@ async fn get_star(
**Stellar Density:** {}",
star.get_age(),
star.st_spectype
.as_ref()
.cloned()
.clone()
.unwrap_or_else(|| "unknown".to_owned()),
star.hd_name
.as_ref()
.cloned()
.clone()
.unwrap_or_else(|| "unknown".to_owned()),
star.get_rad(),
star.get_mass(),
Expand Down Expand Up @@ -672,8 +680,7 @@ async fn get_planet(
),
planet
.hostname
.as_ref()
.cloned()
.clone()
.unwrap_or_else(|| "unknown".to_owned()),
),
false,
Expand All @@ -693,18 +700,15 @@ async fn get_planet(
),
planet
.discoverymethod
.as_ref()
.cloned()
.clone()
.unwrap_or_else(|| "unknown".to_owned()),
planet
.disc_locale
.as_ref()
.cloned()
.clone()
.unwrap_or_else(|| "unknown".to_owned()),
planet
.disc_telescope
.as_ref()
.cloned()
.clone()
.unwrap_or_else(|| "unknown".to_owned()),
),
false,
Expand Down
69 changes: 13 additions & 56 deletions src/commands/help.rs
Original file line number Diff line number Diff line change
@@ -1,71 +1,31 @@
use std::{
fmt::Write,
sync::Arc,
};
use std::{fmt::Write, sync::Arc};

use itertools::Itertools;
use mongodb::bson::{
doc,
document::Document,
from_bson,
};
use mongodb::bson::{doc, document::Document, from_bson};
use okto_framework::{
macros::command,
structs::Command,
structs::{Command, CommandError, CommandResult},
};
use serenity::{
builder::{
CreateEmbed,
CreateEmbedAuthor,
EditInteractionResponse,
},
framework::standard::{
macros::hook,
CommandError,
CommandResult,
},
builder::{CreateEmbed, CreateEmbedAuthor, EditInteractionResponse},
framework::standard::macros::hook,
model::{
application::{
ButtonStyle,
CommandInteraction,
},
prelude::{
Channel,
Message,
MessageType,
ReactionType,
},
application::{ButtonStyle, CommandInteraction},
prelude::{Channel, Message, MessageType, ReactionType},
Permissions,
},
prelude::{
Context,
RwLock,
},
prelude::{Context, RwLock},
};

use crate::{
events::statefulembed::{
ButtonType,
EmbedSession,
StatefulEmbed,
},
events::statefulembed::{ButtonType, EmbedSession, StatefulEmbed},
models::{
caches::{
CommandListKey,
DatabaseKey,
},
caches::{CommandListKey, DatabaseKey},
settings::GuildSettings,
},
utils::{
capitalize,
constants::{
BACK_EMOJI,
DEFAULT_COLOR,
DEFAULT_ICON,
EXIT_EMOJI,
NUMBER_EMOJIS,
OWNERS,
},
constants::{BACK_EMOJI, DEFAULT_COLOR, DEFAULT_ICON, EXIT_EMOJI, NUMBER_EMOJIS, OWNERS},
},
};

Expand Down Expand Up @@ -183,7 +143,7 @@ fn help_menu(
c.info
.file
})
.group_by(|c| {
.chunk_by(|c| {
c.info
.file
})
Expand Down Expand Up @@ -475,10 +435,7 @@ pub async fn calc_prefix(ctx: &Context, msg: &Message) -> String {

let res = db
.collection::<Document>("general_settings")
.find_one(
doc! { "guild": msg.guild_id.unwrap().get() as i64 },
None,
)
.find_one(doc! { "guild": msg.guild_id.unwrap().get() as i64 })
.await;

if res.is_err() {
Expand Down
Loading
Loading