summaryrefslogtreecommitdiff
path: root/src/commands/general
diff options
context:
space:
mode:
Diffstat (limited to 'src/commands/general')
-rw-r--r--src/commands/general/ask.rs7
-rw-r--r--src/commands/general/bing.rs4
-rw-r--r--src/commands/general/config.rs124
-rw-r--r--src/commands/general/convert.rs12
-rw-r--r--src/commands/general/mod.rs28
-rw-r--r--src/commands/general/random.rs27
-rw-r--r--src/commands/general/version.rs18
7 files changed, 107 insertions, 113 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()