summaryrefslogtreecommitdiff
path: root/src/commands
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
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')
-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
-rw-r--r--src/commands/mod.rs31
-rw-r--r--src/commands/moderation/clear_messages.rs5
-rw-r--r--src/commands/optional/copypasta.rs73
-rw-r--r--src/commands/optional/mod.rs1
-rw-r--r--src/commands/optional/teawiespam.rs5
-rw-r--r--src/commands/optional/uwurandom.rs4
14 files changed, 52 insertions, 132 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/{})",
diff --git a/src/commands/mod.rs b/src/commands/mod.rs
index e8cac33..b8d0381 100644
--- a/src/commands/mod.rs
+++ b/src/commands/mod.rs
@@ -1,4 +1,4 @@
-use crate::{Data, Error};
+use crate::client::{Data, Error};
mod general;
mod moderation;
@@ -17,24 +17,13 @@ macro_rules! cmd {
};
}
-pub fn to_vec() -> Vec<Command> {
- vec![
- cmd!(general, ask),
- cmd!(general, bing),
- cmd!(general, config),
- cmd!(general, convert),
- cmd!(general, emoji),
- cmd!(general, pfp),
- cmd!(general, random),
- cmd!(general, version),
- cmd!(moderation, clear_messages),
- cmd!(optional, copypasta),
- cmd!(optional, teawiespam),
- cmd!(optional, uwurandom),
- ]
+pub fn all() -> Vec<Command> {
+ let mut all_commands = global();
+ all_commands.append(&mut optional());
+ all_commands
}
-pub fn to_vec_global() -> Vec<Command> {
+pub fn global() -> Vec<Command> {
vec![
cmd!(general, ask),
cmd!(general, bing),
@@ -48,10 +37,6 @@ pub fn to_vec_global() -> Vec<Command> {
]
}
-pub fn to_vec_optional() -> Vec<Command> {
- vec![
- cmd!(optional, copypasta),
- cmd!(optional, teawiespam),
- cmd!(optional, uwurandom),
- ]
+pub fn optional() -> Vec<Command> {
+ vec![cmd!(optional, teawiespam), cmd!(optional, uwurandom)]
}
diff --git a/src/commands/moderation/clear_messages.rs b/src/commands/moderation/clear_messages.rs
index 8761bcb..65a30be 100644
--- a/src/commands/moderation/clear_messages.rs
+++ b/src/commands/moderation/clear_messages.rs
@@ -1,5 +1,6 @@
-use crate::{Context, Error};
+use crate::client::Context;
+use eyre::Result;
use log::debug;
use poise::serenity_prelude::GetMessages;
@@ -13,7 +14,7 @@ use poise::serenity_prelude::GetMessages;
pub async fn clear_messages(
ctx: Context<'_>,
#[description = "How many messages to delete"] num_messages: u8,
-) -> Result<(), Error> {
+) -> Result<()> {
ctx.defer_ephemeral().await?;
let channel = ctx.channel_id();
diff --git a/src/commands/optional/copypasta.rs b/src/commands/optional/copypasta.rs
deleted file mode 100644
index 06440b1..0000000
--- a/src/commands/optional/copypasta.rs
+++ /dev/null
@@ -1,73 +0,0 @@
-use crate::{Context, Error};
-
-use include_dir::{include_dir, Dir};
-use log::debug;
-
-const COPYPASTAS: Dir = include_dir!("src/copypastas");
-
-#[derive(Debug, poise::ChoiceParameter)]
-pub enum Copypasta {
- Astral,
- Dvd,
- Egrill,
- HappyMeal,
- Sus,
- TickTock,
- 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()
- }
-}
-
-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())
- }
-}
-
-/// ask teawie to send funni copypasta
-#[poise::command(slash_command)]
-pub async fn copypasta(
- ctx: Context<'_>,
- #[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?;
-
- 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");
- }
-
- 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 95c39bd..a3d1bd2 100644
--- a/src/commands/optional/mod.rs
+++ b/src/commands/optional/mod.rs
@@ -1,3 +1,2 @@
-pub mod copypasta;
pub mod teawiespam;
pub mod uwurandom;
diff --git a/src/commands/optional/teawiespam.rs b/src/commands/optional/teawiespam.rs
index 3a9a387..bfac852 100644
--- a/src/commands/optional/teawiespam.rs
+++ b/src/commands/optional/teawiespam.rs
@@ -1,10 +1,11 @@
-use crate::{Context, Error};
+use crate::client::Context;
+use eyre::Result;
use log::debug;
/// teawie will spam you.
#[poise::command(slash_command)]
-pub async fn teawiespam(ctx: Context<'_>) -> Result<(), Error> {
+pub async fn teawiespam(ctx: Context<'_>) -> Result<()> {
if let Some(guild_id) = ctx.guild_id() {
if let Some(storage) = &ctx.data().storage {
let settings = storage.get_guild_settings(&guild_id).await?;
diff --git a/src/commands/optional/uwurandom.rs b/src/commands/optional/uwurandom.rs
index e717d5e..c952dee 100644
--- a/src/commands/optional/uwurandom.rs
+++ b/src/commands/optional/uwurandom.rs
@@ -1,4 +1,4 @@
-use crate::{Context, Error};
+use crate::client::Context;
use eyre::Result;
use log::debug;
@@ -12,7 +12,7 @@ pub async fn uwurandom(
#[min = 1]
#[max = 2000]
length: Option<u16>,
-) -> Result<(), Error> {
+) -> Result<()> {
if let Some(guild_id) = ctx.guild_id() {
if let Some(storage) = &ctx.data().storage {
let settings = storage.get_guild_settings(&guild_id).await?;