aboutsummaryrefslogtreecommitdiff
path: root/src/bot.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/bot.rs')
-rw-r--r--src/bot.rs102
1 files changed, 94 insertions, 8 deletions
diff --git a/src/bot.rs b/src/bot.rs
index c8b01ab..6a2ae72 100644
--- a/src/bot.rs
+++ b/src/bot.rs
@@ -24,12 +24,14 @@ use log::{
use poise::{
BoxFuture,
FrameworkError,
+ PrefixContext,
};
use serenity::{
all::{
GuildId,
ReactionType,
},
+ builder::CreateMessage,
model::{
event::ResumedEvent,
gateway::Ready,
@@ -52,6 +54,7 @@ use tokio::sync::Mutex;
use crate::{
commands,
config::CONFIG,
+ err_msg,
util,
util::OAUTH_URL,
Error,
@@ -165,16 +168,99 @@ lazy_static! {
fn on_err(err: FrameworkError<PoiseData, anyhow::Error>) -> BoxFuture<()> {
Box::pin(async move {
- error!("error encountered: {err:?}");
+ let Some(msg) = err_msg(&err) else {
+ warn!("error handler missing poise context");
+ return;
+ };
- if let Some(ctx) = err.ctx() {
- if let Err(e) = util::react(ctx, ReactionType::Unicode("❌".to_owned())).await {
- error!("reacting to failed message: {e}");
- }
+ let ctx = err.serenity_context();
- if let Err(e) = util::reply(ctx, "BANIC").await {
- error!("sending BANIC: {e}");
+ let text = match err {
+ FrameworkError::ArgumentParse {
+ ..
}
+ | FrameworkError::SubcommandRequired {
+ ..
+ } => "format your commands right. fuck you.".to_string(),
+ FrameworkError::CooldownHit {
+ ..
+ } => "slow the fuck down bitch".to_string(),
+ FrameworkError::NotAnOwner {
+ ..
+ } => "who do you think you are?".to_string(),
+ FrameworkError::GuildOnly {
+ ..
+ } => "what in the sam hill are you smoking".to_string(),
+ FrameworkError::DmOnly {
+ ..
+ } => "take that back or i'm revoking your kitten status".to_string(),
+ FrameworkError::UnknownCommand {
+ ctx,
+ msg,
+ prefix,
+ msg_content,
+ trigger,
+ invocation_data,
+ framework,
+ ..
+ } => {
+ let command = poise::Command {
+ name: "meme".to_owned(),
+ ..Default::default()
+ };
+
+ fn noop<U, E>(
+ _ctx: PrefixContext<'_, U, E>,
+ ) -> BoxFuture<core::result::Result<(), FrameworkError<U, E>>> {
+ Box::pin(async { Ok(()) })
+ }
+
+ let ctx = PrefixContext {
+ serenity_context: ctx,
+ prefix,
+ msg,
+ command: &command,
+ trigger,
+ invocation_data,
+ parent_commands: &[],
+ data: &(),
+ invoked_command_name: "",
+ action: noop,
+ args: msg_content,
+ framework,
+
+ __non_exhaustive: (),
+ };
+
+ match util::pop_string(msg_content)
+ .map_err(anyhow::Error::from)
+ .and_then(|(_rest, s)| s.parse().map_err(anyhow::Error::from))
+ {
+ Ok(u) => {
+ if let Err(e) = commands::unrecognized(PoiseContext::Prefix(ctx), u).await {
+ error!("processing audio: {e}");
+ "BANIC".to_string()
+ } else {
+ return;
+ }
+ },
+ Err(e) => {
+ error!("processing unrecognized message: {e}");
+ "BANIC".to_string()
+ },
+ }
+ },
+ _ => "BANIC".to_string(),
+ };
+
+ error!("error encountered: {err:#?}");
+ if let Err(e) = msg.react(ctx, ReactionType::Unicode("❌".to_owned())).await {
+ error!("reacting to failed message: {e}");
+ }
+
+ let cm = CreateMessage::default().content(text).tts(msg.tts);
+ if let Err(e) = msg.channel_id.send_message(ctx, cm).await {
+ error!("sending error to chat: {e}");
}
})
}
@@ -296,7 +382,7 @@ pub async fn run() -> Result<()> {
tokio::spawn(async move {
tokio::signal::ctrl_c().await.unwrap();
- warn!("got ctrl c");
+ warn!("got ^C");
shard_manager.shutdown_all().await;
info!("shutdown");