diff options
Diffstat (limited to 'src/commands')
| -rw-r--r-- | src/commands/general/ask.rs | 7 | ||||
| -rw-r--r-- | src/commands/general/bing.rs | 4 | ||||
| -rw-r--r-- | src/commands/general/config.rs | 124 | ||||
| -rw-r--r-- | src/commands/general/convert.rs | 12 | ||||
| -rw-r--r-- | src/commands/general/mod.rs | 28 | ||||
| -rw-r--r-- | src/commands/general/random.rs | 27 | ||||
| -rw-r--r-- | src/commands/general/version.rs | 18 | ||||
| -rw-r--r-- | src/commands/mod.rs | 53 | ||||
| -rw-r--r-- | src/commands/moderation/clear.rs | 39 | ||||
| -rw-r--r-- | src/commands/moderation/clear_messages.rs | 30 | ||||
| -rw-r--r-- | src/commands/moderation/mod.rs | 11 | ||||
| -rw-r--r-- | src/commands/optional/copypasta.rs | 94 | ||||
| -rw-r--r-- | src/commands/optional/mod.rs | 19 | ||||
| -rw-r--r-- | src/commands/optional/teawiespam.rs | 26 | ||||
| -rw-r--r-- | src/commands/optional/uwurandom.rs | 24 |
15 files changed, 260 insertions, 256 deletions
diff --git a/src/commands/general/ask.rs b/src/commands/general/ask.rs index 75560e0..c715e3a 100644 --- a/src/commands/general/ask.rs +++ b/src/commands/general/ask.rs @@ -1,15 +1,16 @@ -use crate::{consts, utils, Context}; +use crate::{consts, utils, Context, Error}; -use eyre::{Context as _, Result}; +use eyre::Context as _; /// Ask teawie a question! #[poise::command(prefix_command, slash_command)] +#[allow(clippy::no_effect_underscore_binding)] pub async fn ask( ctx: Context<'_>, #[rename = "question"] #[description = "The question you want to ask teawie"] _question: String, -) -> Result<()> { +) -> Result<(), Error> { let resp = utils::random_choice(consts::RESPONSES) .wrap_err("Couldn't choose from random responses!")?; diff --git a/src/commands/general/bing.rs b/src/commands/general/bing.rs index d55d8ee..d58404e 100644 --- a/src/commands/general/bing.rs +++ b/src/commands/general/bing.rs @@ -1,10 +1,10 @@ -use crate::Context; +use crate::{Context, Error}; use eyre::Result; /// Make sure the wie is alive #[poise::command(prefix_command)] -pub async fn bing(ctx: Context<'_>) -> Result<()> { +pub async fn bing(ctx: Context<'_>) -> Result<(), Error> { ctx.say("bong!").await?; Ok(()) } diff --git a/src/commands/general/config.rs b/src/commands/general/config.rs index ddc5cda..456e791 100644 --- a/src/commands/general/config.rs +++ b/src/commands/general/config.rs @@ -1,7 +1,7 @@ -use std::str::FromStr; +use crate::storage::settings::{Properties, Settings}; +use crate::{Context, Error}; -use crate::{storage, Context}; -use storage::{Properties, Settings}; +use std::str::FromStr; use eyre::{OptionExt as _, Result}; use log::debug; @@ -41,7 +41,7 @@ fn prop_to_val(setting: &Properties, settings: &Settings) -> String { required_permissions = "MANAGE_GUILD", default_member_permissions = "MANAGE_GUILD" )] -pub async fn config(_ctx: Context<'_>) -> Result<()> { +pub async fn config(_: Context<'_>) -> Result<(), Error> { Ok(()) } @@ -72,63 +72,67 @@ pub async fn set( #[description = "Toggle ReactBoard"] reactboard_enabled: Option<bool>, #[description = "Enables 'extra' commands like teawiespam and copypasta. Defaults to false."] optional_commands_enabled: Option<bool>, -) -> Result<()> { - let storage = &ctx.data().storage; - let gid = ctx.guild_id().unwrap_or_default(); - let mut settings = storage.get_guild_settings(&gid).await?; - let previous_settings = settings.clone(); - - if let Some(channel) = pinboard_channel { - debug!("Setting pinboard_channel to {channel} for {gid}"); - settings.pinboard_channel = Some(channel.id); - } +) -> Result<(), Error> { + if let Some(storage) = &ctx.data().storage { + let gid = ctx.guild_id().unwrap_or_default(); + let mut settings = storage.get_guild_settings(&gid).await?; + let previous_settings = settings.clone(); + + if let Some(channel) = pinboard_channel { + debug!("Setting pinboard_channel to {channel} for {gid}"); + settings.pinboard_channel = Some(channel.id); + } - if let Some(watch) = pinboard_watch { - let channels = split_argument(&watch); - settings.pinboard_watch = (!channels.is_empty()).then_some(channels); - } + if let Some(watch) = pinboard_watch { + let channels = split_argument(&watch); + settings.pinboard_watch = (!channels.is_empty()).then_some(channels); + } - if let Some(enabled) = pinboard_enabled { - debug!("Setting pinboard_enabled to {enabled} for {gid}"); - settings.pinboard_enabled = enabled; - } + if let Some(enabled) = pinboard_enabled { + debug!("Setting pinboard_enabled to {enabled} for {gid}"); + settings.pinboard_enabled = enabled; + } - if let Some(channel) = reactboard_channel { - debug!("Setting reactboard_channel to {channel} for {gid}"); - settings.reactboard_channel = Some(channel.id); - } + if let Some(channel) = reactboard_channel { + debug!("Setting reactboard_channel to {channel} for {gid}"); + settings.reactboard_channel = Some(channel.id); + } - if let Some(requirement) = reactboard_requirement { - debug!("Setting reactboard_requirement to {requirement} for {gid}"); - settings.reactboard_requirement = Some(requirement); - } + if let Some(requirement) = reactboard_requirement { + debug!("Setting reactboard_requirement to {requirement} for {gid}"); + settings.reactboard_requirement = Some(requirement); + } - if let Some(reaction) = reactboard_reaction { - let emojis: Vec<ReactionType> = - reaction.split(',').filter_map(|r| r.parse().ok()).collect(); - debug!("Setting reactboard_reactions to {emojis:#?} for {gid}"); + if let Some(reaction) = reactboard_reaction { + let emojis: Vec<ReactionType> = + reaction.split(',').filter_map(|r| r.parse().ok()).collect(); + debug!("Setting reactboard_reactions to {emojis:#?} for {gid}"); - settings.reactboard_reactions = Some(emojis); - } + settings.reactboard_reactions = Some(emojis); + } - if let Some(enabled) = reactboard_enabled { - debug!("Setting reactboard_enabled to {enabled} for {gid}"); - settings.reactboard_enabled = enabled; - } + if let Some(enabled) = reactboard_enabled { + debug!("Setting reactboard_enabled to {enabled} for {gid}"); + settings.reactboard_enabled = enabled; + } - if let Some(enabled) = optional_commands_enabled { - debug!("Setting optional_commands_enabled to {enabled} for {}", gid); - settings.optional_commands_enabled = enabled; - } + if let Some(enabled) = optional_commands_enabled { + debug!("Setting optional_commands_enabled to {enabled} for {}", gid); + settings.optional_commands_enabled = enabled; + } - if previous_settings == settings { - debug!("Not updating settings key for {gid} since no changes were made"); - ctx.reply("No changes made, so i'm not updating anything") - .await?; + if previous_settings == settings { + debug!("Not updating settings key for {gid} since no changes were made"); + ctx.reply("No changes made, so i'm not updating anything") + .await?; + } else { + debug!("Updating settings key for {gid}"); + storage.create_guild_settings(settings).await?; + ctx.reply("Configuration updated!").await?; + } } else { - debug!("Updating settings key for {gid}"); - storage.create_guild_settings(settings).await?; - ctx.reply("Configuration updated!").await?; + ctx.reply("I have no storage backend right now, so I can't set settings :(") + .await?; } Ok(()) @@ -145,18 +149,22 @@ pub async fn set( pub async fn get( ctx: Context<'_>, #[description = "The setting you want to get"] setting: Properties, -) -> Result<()> { +) -> Result<(), Error> { let gid = &ctx .guild_id() .ok_or_eyre("Failed to get GuildId from context!")?; - let settings = ctx.data().storage.get_guild_settings(gid).await?; - let value = prop_to_val(&setting, &settings); - - let embed = CreateEmbed::new().field(setting.name(), value, false); - let message = CreateReply::default().embed(embed); + if let Some(storage) = &ctx.data().storage { + let settings = storage.get_guild_settings(gid).await?; + let value = prop_to_val(&setting, &settings); - ctx.send(message).await?; + let embed = CreateEmbed::new().field(setting.name(), value, false); + let message = CreateReply::default().embed(embed); + ctx.send(message).await?; + } else { + ctx.reply("I have no storage backend right now, so I can't fetch settings :(") + .await?; + } Ok(()) } diff --git a/src/commands/general/convert.rs b/src/commands/general/convert.rs index 5e14175..4d38eb2 100644 --- a/src/commands/general/convert.rs +++ b/src/commands/general/convert.rs @@ -1,4 +1,4 @@ -use crate::Context; +use crate::{Context, Error}; use bottomify::bottom; use eyre::Result; @@ -9,7 +9,7 @@ use poise::serenity_prelude::constants::MESSAGE_CODE_LIMIT; slash_command, subcommands("to_fahrenheit", "to_celsius", "to_bottom", "from_bottom") )] -pub async fn convert(_ctx: Context<'_>) -> Result<()> { +pub async fn convert(_: Context<'_>) -> Result<(), Error> { Ok(()) } @@ -18,7 +18,7 @@ pub async fn convert(_ctx: Context<'_>) -> Result<()> { pub async fn to_celsius( ctx: Context<'_>, #[description = "What teawie will convert"] degrees_fahrenheit: f32, -) -> Result<()> { +) -> Result<(), Error> { let temp = (degrees_fahrenheit - 32.0) * (5.0 / 9.0); ctx.say(temp.to_string()).await?; Ok(()) @@ -29,7 +29,7 @@ pub async fn to_celsius( pub async fn to_fahrenheit( ctx: Context<'_>, #[description = "What teawie will convert"] degrees_celsius: f32, -) -> Result<()> { +) -> Result<(), Error> { let temp = (degrees_celsius * (9.0 / 5.0)) + 32.0; ctx.say(temp.to_string()).await?; Ok(()) @@ -40,7 +40,7 @@ pub async fn to_fahrenheit( pub async fn to_bottom( ctx: Context<'_>, #[description = "What teawie will translate into bottom"] message: String, -) -> Result<()> { +) -> Result<(), Error> { let encoded = bottom::encode_string(&message); ctx.say(encoded).await?; Ok(()) @@ -51,7 +51,7 @@ pub async fn to_bottom( pub async fn from_bottom( ctx: Context<'_>, #[description = "What teawie will translate from bottom"] message: String, -) -> Result<()> { +) -> Result<(), Error> { let resp: String; if let Ok(decoded) = bottom::decode_string(&message.clone()) { diff --git a/src/commands/general/mod.rs b/src/commands/general/mod.rs index c872272..82af4d2 100644 --- a/src/commands/general/mod.rs +++ b/src/commands/general/mod.rs @@ -1,22 +1,6 @@ -use crate::Data; - -use eyre::Report; -use poise::Command; - -mod ask; -mod bing; -mod config; -mod convert; -mod random; -mod version; - -pub fn to_comands() -> Vec<Command<Data, Report>> { - vec![ - ask::ask(), - bing::bing(), - config::config(), - convert::convert(), - random::random(), - version::version(), - ] -} +pub mod ask; +pub mod bing; +pub mod config; +pub mod convert; +pub mod random; +pub mod version; diff --git a/src/commands/general/random.rs b/src/commands/general/random.rs index 7c7ceff..92e9188 100644 --- a/src/commands/general/random.rs +++ b/src/commands/general/random.rs @@ -1,31 +1,34 @@ -use crate::{api, consts, utils, Context}; +use crate::{api, consts, utils, Context, Error}; -use eyre::Result; - -#[allow(clippy::unused_async)] #[poise::command(slash_command, subcommands("lore", "teawie", "shiggy"))] -pub async fn random(_ctx: Context<'_>) -> Result<()> { +#[allow(clippy::unused_async)] +pub async fn random(_: Context<'_>) -> Result<(), Error> { Ok(()) } /// Get a random piece of teawie lore! #[poise::command(prefix_command, slash_command)] -pub async fn lore(ctx: Context<'_>) -> Result<()> { +pub async fn lore(ctx: Context<'_>) -> Result<(), Error> { let resp = utils::random_choice(consts::LORE)?; ctx.say(resp).await?; + Ok(()) } /// Get a random teawie #[poise::command(prefix_command, slash_command)] -pub async fn teawie(ctx: Context<'_>) -> Result<()> { - let url = api::guzzle::get_random_teawie().await?; - utils::send_url_as_embed(ctx, url).await +pub async fn teawie(ctx: Context<'_>) -> Result<(), Error> { + let url = api::guzzle::random_teawie().await?; + utils::send_url_as_embed(ctx, url).await?; + + Ok(()) } /// Get a random shiggy #[poise::command(prefix_command, slash_command)] -pub async fn shiggy(ctx: Context<'_>) -> Result<()> { - let url = api::shiggy::get_random_shiggy().await?; - utils::send_url_as_embed(ctx, url).await +pub async fn shiggy(ctx: Context<'_>) -> Result<(), Error> { + let url = api::shiggy::random_shiggy().await?; + utils::send_url_as_embed(ctx, url).await?; + + Ok(()) } diff --git a/src/commands/general/version.rs b/src/commands/general/version.rs index e392903..5f8eac9 100644 --- a/src/commands/general/version.rs +++ b/src/commands/general/version.rs @@ -1,16 +1,13 @@ -use crate::colors::Colors; -use crate::Context; +use crate::{consts::Colors, Context, Error}; -use eyre::Result; -use poise::serenity_prelude::CreateEmbed; -use poise::CreateReply; +use std::env::consts::{ARCH, OS}; + +use poise::{serenity_prelude::CreateEmbed, CreateReply}; /// Get version info #[poise::command(slash_command)] -pub async fn version(ctx: Context<'_>) -> Result<()> { +pub async fn version(ctx: Context<'_>) -> Result<(), Error> { let sha = option_env!("GIT_SHA").unwrap_or("main"); - let target = option_env!("TARGET").unwrap_or("Unknown"); - let revision_url = format!( "[{}]({}/tree/{})", sha, @@ -18,15 +15,16 @@ pub async fn version(ctx: Context<'_>) -> Result<()> { sha, ); + let os_info = format!("{ARCH}-{OS}"); + let fields = [ ( "Version:", option_env!("CARGO_PKG_VERSION").unwrap_or("not found"), false, ), - ("Target:", target, false), + ("OS:", &os_info, false), ("Revision:", &revision_url, false), - ("User Agent:", &crate::api::USER_AGENT, false), ]; let embed = CreateEmbed::new() diff --git a/src/commands/mod.rs b/src/commands/mod.rs index 88a47b3..e55419b 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -1,20 +1,53 @@ -use crate::Data; - -use eyre::Report; -use poise::Command; +use crate::{Data, Error}; mod general; mod moderation; mod optional; -pub fn global() -> Vec<Command<Data, Report>> { - general::to_comands() +type Command = poise::Command<Data, Error>; + +#[macro_export] +macro_rules! cmd { + ($module: ident, $name: ident) => { + $module::$name::$name() + }; + + ($module: ident, $name: ident, $func: ident) => { + $module::$name::$func() + }; +} + +pub fn to_vec() -> Vec<Command> { + vec![ + cmd!(general, ask), + cmd!(general, bing), + cmd!(general, config), + cmd!(general, convert), + cmd!(general, random), + cmd!(general, version), + cmd!(moderation, clear_messages), + cmd!(optional, copypasta), + cmd!(optional, teawiespam), + cmd!(optional, uwurandom), + ] } -pub fn optional() -> Vec<Command<Data, Report>> { - optional::to_commands() +pub fn to_vec_global() -> Vec<Command> { + vec![ + cmd!(general, ask), + cmd!(general, bing), + cmd!(general, config), + cmd!(general, convert), + cmd!(general, random), + cmd!(general, version), + cmd!(moderation, clear_messages), + ] } -pub fn moderation() -> Vec<Command<Data, Report>> { - moderation::to_commands() +pub fn to_vec_optional() -> Vec<Command> { + vec![ + cmd!(optional, copypasta), + cmd!(optional, teawiespam), + cmd!(optional, uwurandom), + ] } diff --git a/src/commands/moderation/clear.rs b/src/commands/moderation/clear.rs deleted file mode 100644 index bfc9c38..0000000 --- a/src/commands/moderation/clear.rs +++ /dev/null @@ -1,39 +0,0 @@ -use crate::Context; - -use eyre::{Context as _, Result}; -use log::debug; -use poise::serenity_prelude::futures::{StreamExt, TryStreamExt}; - -#[poise::command( - slash_command, - ephemeral, - required_permissions = "MANAGE_MESSAGES", - default_member_permissions = "MANAGE_MESSAGES" -)] -pub async fn clear_messages( - ctx: Context<'_>, - #[description = "How many messages to delete"] num_messages: usize, -) -> Result<()> { - ctx.defer_ephemeral().await?; - - let channel = ctx.channel_id(); - let messages = channel - .messages_iter(ctx) - .take(num_messages) - .try_fold(Vec::new(), |mut acc, msg| async move { - acc.push(msg); - Ok(acc) - }) - .await - .wrap_err_with(|| { - format!("Couldn't collect {num_messages} messages from channel {channel}") - })?; - - debug!("Clearing {num_messages} messages from channel {channel}!"); - channel.delete_messages(ctx, messages).await?; - - ctx.reply(format!("Deleted {num_messages} message(s)")) - .await?; - - Ok(()) -} diff --git a/src/commands/moderation/clear_messages.rs b/src/commands/moderation/clear_messages.rs new file mode 100644 index 0000000..8761bcb --- /dev/null +++ b/src/commands/moderation/clear_messages.rs @@ -0,0 +1,30 @@ +use crate::{Context, Error}; + +use log::debug; +use poise::serenity_prelude::GetMessages; + +#[poise::command( + slash_command, + guild_only, + ephemeral, + required_permissions = "MANAGE_MESSAGES", + default_member_permissions = "MANAGE_MESSAGES" +)] +pub async fn clear_messages( + ctx: Context<'_>, + #[description = "How many messages to delete"] num_messages: u8, +) -> Result<(), Error> { + ctx.defer_ephemeral().await?; + + let channel = ctx.channel_id(); + let to_get = GetMessages::new().limit(num_messages); + let messages = channel.messages(ctx, to_get).await?; + + debug!("Clearing {num_messages} messages from channel {channel}!"); + channel.delete_messages(ctx, messages).await?; + + ctx.reply(format!("Deleted {num_messages} message(s)")) + .await?; + + Ok(()) +} diff --git a/src/commands/moderation/mod.rs b/src/commands/moderation/mod.rs index 5a8cd08..ed6a7c6 100644 --- a/src/commands/moderation/mod.rs +++ b/src/commands/moderation/mod.rs @@ -1,10 +1 @@ -use crate::Data; - -use eyre::Report; -use poise::Command; - -mod clear; - -pub fn to_commands() -> Vec<Command<Data, Report>> { - vec![clear::clear_messages()] -} +pub mod clear_messages; diff --git a/src/commands/optional/copypasta.rs b/src/commands/optional/copypasta.rs index 15171f8..06440b1 100644 --- a/src/commands/optional/copypasta.rs +++ b/src/commands/optional/copypasta.rs @@ -1,18 +1,14 @@ -use crate::Context; +use crate::{Context, Error}; -use std::collections::HashMap; - -use eyre::{eyre, OptionExt, Result}; use include_dir::{include_dir, Dir}; use log::debug; -const FILES: Dir = include_dir!("src/copypastas"); +const COPYPASTAS: Dir = include_dir!("src/copypastas"); -#[allow(clippy::upper_case_acronyms)] #[derive(Debug, poise::ChoiceParameter)] -pub enum Copypastas { +pub enum Copypasta { Astral, - DVD, + Dvd, Egrill, HappyMeal, Sus, @@ -20,43 +16,27 @@ pub enum Copypastas { Twitter, } -impl Copypastas { - fn as_str(&self) -> &str { - match self { - Copypastas::Astral => "astral", - Copypastas::DVD => "dvd", - Copypastas::Egrill => "egrill", - Copypastas::HappyMeal => "happymeal", - Copypastas::Sus => "sus", - Copypastas::TickTock => "ticktock", - Copypastas::Twitter => "twitter", - } +impl ToString for Copypasta { + fn to_string(&self) -> String { + let str = match self { + Self::Astral => "astral", + Self::Dvd => "dvd", + Self::Egrill => "egrill", + Self::HappyMeal => "happymeal", + Self::Sus => "sus", + Self::TickTock => "ticktock", + Self::Twitter => "twitter", + }; + str.to_string() } } -fn get_copypasta(name: &Copypastas) -> Result<String> { - let mut files: HashMap<&str, &str> = HashMap::new(); - - for file in FILES.files() { - let name = file - .path() - .file_stem() - .ok_or_else(|| eyre!("Couldn't get file stem from {file:#?}"))? - .to_str() - .ok_or_eyre("Couldn't convert file stem to str!")?; - - let contents = file - .contents_utf8() - .ok_or_eyre("Couldnt get contents from copypasta!")?; - - // refer to files by their name w/o extension - files.insert(name, contents); - } - - if files.contains_key(name.as_str()) { - Ok(files[name.as_str()].to_string()) - } else { - Err(eyre!("Couldnt find copypasta {}!", name.as_str())) +impl Copypasta { + fn contents(&self) -> Option<&str> { + let file_name = format!("{}.txt", self.to_string()); + COPYPASTAS + .get_file(file_name) + .and_then(|file| file.contents_utf8()) } } @@ -64,18 +44,30 @@ fn get_copypasta(name: &Copypastas) -> Result<String> { #[poise::command(slash_command)] pub async fn copypasta( ctx: Context<'_>, - #[description = "the copypasta you want to send"] copypasta: Copypastas, -) -> Result<()> { - let gid = ctx.guild_id().unwrap_or_default(); - let settings = ctx.data().storage.get_guild_settings(&gid).await?; + #[description = "the copypasta you want to send"] copypasta: Copypasta, +) -> Result<(), Error> { + if let Some(guild_id) = ctx.guild_id() { + if let Some(storage) = &ctx.data().storage { + let settings = storage.get_guild_settings(&guild_id).await?; + + if !settings.optional_commands_enabled { + debug!("Not running command in {guild_id} since it's disabled"); + ctx.reply("I'm not allowed to do that here").await?; - if !settings.optional_commands_enabled { - debug!("Exited copypasta command in {gid} since it's disabled"); - ctx.say("I'm not allowed to do that here").await?; - return Ok(()); + return Ok(()); + } + } else { + debug!("Ignoring restrictions on command; no storage backend is attached!"); + } + } else { + debug!("Ignoring restrictions on command; we're not in a guild"); } - ctx.say(get_copypasta(©pasta)?).await?; + if let Some(contents) = copypasta.contents() { + ctx.say(contents).await?; + } else { + ctx.reply("I couldn't find that copypasta :(").await?; + } Ok(()) } diff --git a/src/commands/optional/mod.rs b/src/commands/optional/mod.rs index 39abdcb..95c39bd 100644 --- a/src/commands/optional/mod.rs +++ b/src/commands/optional/mod.rs @@ -1,16 +1,3 @@ -use crate::Data; - -use eyre::Report; -use poise::Command; - -mod copypasta; -mod teawiespam; -mod uwurandom; - -pub fn to_commands() -> Vec<Command<Data, Report>> { - vec![ - copypasta::copypasta(), - teawiespam::teawiespam(), - uwurandom::uwurandom(), - ] -} +pub mod copypasta; +pub mod teawiespam; +pub mod uwurandom; diff --git a/src/commands/optional/teawiespam.rs b/src/commands/optional/teawiespam.rs index 7f7ba79..3a9a387 100644 --- a/src/commands/optional/teawiespam.rs +++ b/src/commands/optional/teawiespam.rs @@ -1,21 +1,29 @@ -use crate::Context; +use crate::{Context, Error}; -use eyre::Result; use log::debug; /// teawie will spam you. #[poise::command(slash_command)] -pub async fn teawiespam(ctx: Context<'_>) -> Result<()> { - let gid = ctx.guild_id().unwrap_or_default(); - let settings = ctx.data().storage.get_guild_settings(&gid).await?; +pub async fn teawiespam(ctx: Context<'_>) -> Result<(), Error> { + if let Some(guild_id) = ctx.guild_id() { + if let Some(storage) = &ctx.data().storage { + let settings = storage.get_guild_settings(&guild_id).await?; - if !settings.optional_commands_enabled { - debug!("Not running teawiespam in {gid} since it's disabled"); - ctx.say("I'm not allowed to do that here").await?; - return Ok(()); + if !settings.optional_commands_enabled { + debug!("Not running command in {guild_id} since it's disabled"); + ctx.say("I'm not allowed to do that here").await?; + + return Ok(()); + } + } else { + debug!("Ignoring restrictions on command; no storage backend is attached!"); + } + } else { + debug!("Ignoring restrictions on command; we're not in a guild."); } let wies = "<:teawiesmile:1056438046440042546>".repeat(50); ctx.say(wies).await?; + Ok(()) } diff --git a/src/commands/optional/uwurandom.rs b/src/commands/optional/uwurandom.rs index 312e54f..e717d5e 100644 --- a/src/commands/optional/uwurandom.rs +++ b/src/commands/optional/uwurandom.rs @@ -1,4 +1,4 @@ -use crate::Context; +use crate::{Context, Error}; use eyre::Result; use log::debug; @@ -12,14 +12,22 @@ pub async fn uwurandom( #[min = 1] #[max = 2000] length: Option<u16>, -) -> Result<()> { - let gid = ctx.guild_id().unwrap_or_default(); - let settings = ctx.data().storage.get_guild_settings(&gid).await?; +) -> Result<(), Error> { + if let Some(guild_id) = ctx.guild_id() { + if let Some(storage) = &ctx.data().storage { + let settings = storage.get_guild_settings(&guild_id).await?; - if !settings.optional_commands_enabled { - debug!("Not running uwurandom in {gid} since it's disabled"); - ctx.say("I'm not allowed to do that here").await?; - return Ok(()); + if !settings.optional_commands_enabled { + debug!("Not running command in {guild_id} since it's disabled"); + ctx.say("I'm not allowed to do that here").await?; + + return Ok(()); + } + } else { + debug!("Ignoring restrictions on command; no storage backend is attached!"); + } + } else { + debug!("Ignoring restrictions on command; we're not in a guild"); } let length = length.unwrap_or(rand::thread_rng().gen_range(1..50)); |
