summaryrefslogtreecommitdiff
path: root/src/commands/general
diff options
context:
space:
mode:
authorseth <[email protected]>2024-08-09 23:35:41 -0400
committerGitHub <[email protected]>2024-08-09 23:35:41 -0400
commitb643a6a235b0c1c9902b97421f24eff2b0d0a5ac (patch)
tree350794c0e9330fb77367838313bc6bb97278a0aa /src/commands/general
parent372780546b508684839916e5ad54c9e90456a94f (diff)
tree-wide: end of summer cleanup (#214)
* api: refactor & rename module to http * client: split from main.rs * tree-wide: use eyre::Report as error * nix: alejandra -> nixfmt * nix: start using treefmt-nix * nix: simplify flake * nix: refactor derivation & docker image * nix: remove overlay * ci: update & cleanup workflows * commands: assign all commands automatically * commands/copypasta: remove * http/teawie: update response struct for upstream rust rewrite * handlers: rename modules to events; flatten * crates: rename self to teawie-bot * nix: fenix -> rust-overlay i want a specific rust version grrrrrrr * ci: pin rust to 1.79 this is what our nix dev shell uses and what we can compile on. it seems the time crate doesn't like v1.80 of the compiler :( * ci: always run release gates * nix: fix static toolchain * nix: rust-overlay -> nixpkgs * ci: adopt actions-rust-lang actions * nix: use docker arch names for containers * crates/time: 0.3.30 -> 0.3.36 fixes building on rust 1.80.0
Diffstat (limited to 'src/commands/general')
-rw-r--r--src/commands/general/ask.rs6
-rw-r--r--src/commands/general/bing.rs6
-rw-r--r--src/commands/general/config.rs8
-rw-r--r--src/commands/general/convert.rs12
-rw-r--r--src/commands/general/emoji.rs5
-rw-r--r--src/commands/general/pfp.rs7
-rw-r--r--src/commands/general/random.rs16
-rw-r--r--src/commands/general/version.rs5
8 files changed, 36 insertions, 29 deletions
diff --git a/src/commands/general/ask.rs b/src/commands/general/ask.rs
index c715e3a..1300e97 100644
--- a/src/commands/general/ask.rs
+++ b/src/commands/general/ask.rs
@@ -1,6 +1,6 @@
-use crate::{consts, utils, Context, Error};
+use crate::{client::Context, consts, utils};
-use eyre::Context as _;
+use eyre::{Context as _, Result};
/// Ask teawie a question!
#[poise::command(prefix_command, slash_command)]
@@ -10,7 +10,7 @@ pub async fn ask(
#[rename = "question"]
#[description = "The question you want to ask teawie"]
_question: String,
-) -> Result<(), Error> {
+) -> Result<()> {
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 54ee0dc..28fdf0d 100644
--- a/src/commands/general/bing.rs
+++ b/src/commands/general/bing.rs
@@ -1,8 +1,10 @@
-use crate::{Context, Error};
+use crate::client::Context;
+
+use eyre::Result;
/// Make sure the wie is alive
#[poise::command(prefix_command)]
-pub async fn bing(ctx: Context<'_>) -> Result<(), Error> {
+pub async fn bing(ctx: Context<'_>) -> Result<()> {
ctx.say("bong!").await?;
Ok(())
}
diff --git a/src/commands/general/config.rs b/src/commands/general/config.rs
index 456e791..6adb78b 100644
--- a/src/commands/general/config.rs
+++ b/src/commands/general/config.rs
@@ -1,5 +1,5 @@
+use crate::client::Context;
use crate::storage::settings::{Properties, Settings};
-use crate::{Context, Error};
use std::str::FromStr;
@@ -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(_: Context<'_>) -> Result<(), Error> {
+pub async fn config(_: Context<'_>) -> Result<()> {
Ok(())
}
@@ -72,7 +72,7 @@ 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<(), Error> {
+) -> Result<()> {
if let Some(storage) = &ctx.data().storage {
let gid = ctx.guild_id().unwrap_or_default();
let mut settings = storage.get_guild_settings(&gid).await?;
@@ -149,7 +149,7 @@ pub async fn set(
pub async fn get(
ctx: Context<'_>,
#[description = "The setting you want to get"] setting: Properties,
-) -> Result<(), Error> {
+) -> Result<()> {
let gid = &ctx
.guild_id()
.ok_or_eyre("Failed to get GuildId from context!")?;
diff --git a/src/commands/general/convert.rs b/src/commands/general/convert.rs
index 4d38eb2..b5e7018 100644
--- a/src/commands/general/convert.rs
+++ b/src/commands/general/convert.rs
@@ -1,4 +1,4 @@
-use crate::{Context, Error};
+use crate::client::Context;
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(_: Context<'_>) -> Result<(), Error> {
+pub async fn convert(_: Context<'_>) -> Result<()> {
Ok(())
}
@@ -18,7 +18,7 @@ pub async fn convert(_: Context<'_>) -> Result<(), Error> {
pub async fn to_celsius(
ctx: Context<'_>,
#[description = "What teawie will convert"] degrees_fahrenheit: f32,
-) -> Result<(), Error> {
+) -> Result<()> {
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<(), Error> {
+) -> Result<()> {
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<(), Error> {
+) -> Result<()> {
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<(), Error> {
+) -> Result<()> {
let resp: String;
if let Ok(decoded) = bottom::decode_string(&message.clone()) {
diff --git a/src/commands/general/emoji.rs b/src/commands/general/emoji.rs
index 81cd9a3..bbae0b5 100644
--- a/src/commands/general/emoji.rs
+++ b/src/commands/general/emoji.rs
@@ -1,5 +1,6 @@
-use crate::{consts::Colors, Context, Error};
+use crate::{client::Context, consts::Colors};
+use eyre::Result;
use poise::{
serenity_prelude::{CreateEmbed, Emoji},
CreateReply,
@@ -7,7 +8,7 @@ use poise::{
/// Get the URL for an emoji
#[poise::command(slash_command)]
-pub async fn emoji(ctx: Context<'_>, emoji: Emoji) -> Result<(), Error> {
+pub async fn emoji(ctx: Context<'_>, emoji: Emoji) -> Result<()> {
let url = emoji.url();
let embed = CreateEmbed::new()
.title(emoji.name)
diff --git a/src/commands/general/pfp.rs b/src/commands/general/pfp.rs
index 2ad062b..34ae795 100644
--- a/src/commands/general/pfp.rs
+++ b/src/commands/general/pfp.rs
@@ -1,13 +1,14 @@
+use crate::{client::Context, consts::Colors};
+
+use eyre::Result;
use poise::{
serenity_prelude::{CreateEmbed, User},
CreateReply,
};
-use crate::{consts::Colors, Context, Error};
-
/// Get someone's profile pic
#[poise::command(context_menu_command = "Get profile picture", slash_command)]
-pub async fn pfp(ctx: Context<'_>, user: User) -> Result<(), Error> {
+pub async fn pfp(ctx: Context<'_>, user: User) -> Result<()> {
let url = user
.avatar_url()
.unwrap_or_else(|| user.default_avatar_url());
diff --git a/src/commands/general/random.rs b/src/commands/general/random.rs
index 92e9188..094123b 100644
--- a/src/commands/general/random.rs
+++ b/src/commands/general/random.rs
@@ -1,14 +1,16 @@
-use crate::{api, consts, utils, Context, Error};
+use crate::{client::Context, consts, http, utils};
+
+use eyre::Result;
#[poise::command(slash_command, subcommands("lore", "teawie", "shiggy"))]
#[allow(clippy::unused_async)]
-pub async fn random(_: Context<'_>) -> Result<(), Error> {
+pub async fn random(_: Context<'_>) -> Result<()> {
Ok(())
}
/// Get a random piece of teawie lore!
#[poise::command(prefix_command, slash_command)]
-pub async fn lore(ctx: Context<'_>) -> Result<(), Error> {
+pub async fn lore(ctx: Context<'_>) -> Result<()> {
let resp = utils::random_choice(consts::LORE)?;
ctx.say(resp).await?;
@@ -17,8 +19,8 @@ pub async fn lore(ctx: Context<'_>) -> Result<(), Error> {
/// Get a random teawie
#[poise::command(prefix_command, slash_command)]
-pub async fn teawie(ctx: Context<'_>) -> Result<(), Error> {
- let url = api::guzzle::random_teawie().await?;
+pub async fn teawie(ctx: Context<'_>) -> Result<()> {
+ let url = http::teawie::random(&ctx.data().http_client).await?;
utils::send_url_as_embed(ctx, url).await?;
Ok(())
@@ -26,8 +28,8 @@ pub async fn teawie(ctx: Context<'_>) -> Result<(), Error> {
/// Get a random shiggy
#[poise::command(prefix_command, slash_command)]
-pub async fn shiggy(ctx: Context<'_>) -> Result<(), Error> {
- let url = api::shiggy::random_shiggy().await?;
+pub async fn shiggy(ctx: Context<'_>) -> Result<()> {
+ let url = http::shiggy::random(&ctx.data().http_client).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 5f8eac9..bdf6805 100644
--- a/src/commands/general/version.rs
+++ b/src/commands/general/version.rs
@@ -1,12 +1,13 @@
-use crate::{consts::Colors, Context, Error};
+use crate::{client::Context, consts::Colors};
use std::env::consts::{ARCH, OS};
+use eyre::Result;
use poise::{serenity_prelude::CreateEmbed, CreateReply};
/// Get version info
#[poise::command(slash_command)]
-pub async fn version(ctx: Context<'_>) -> Result<(), Error> {
+pub async fn version(ctx: Context<'_>) -> Result<()> {
let sha = option_env!("GIT_SHA").unwrap_or("main");
let revision_url = format!(
"[{}]({}/tree/{})",