refactor!: use poise 0.6.1
This commit is contained in:
parent
203ba111cc
commit
7252ced3cb
16 changed files with 700 additions and 512 deletions
|
@ -3,8 +3,8 @@ use crate::Data;
|
|||
|
||||
use color_eyre::eyre::Report;
|
||||
use log::*;
|
||||
use poise::serenity_prelude::Timestamp;
|
||||
use poise::FrameworkError;
|
||||
use poise::serenity_prelude::{CreateEmbed, Timestamp};
|
||||
use poise::{CreateReply, FrameworkError};
|
||||
|
||||
pub async fn handle(error: FrameworkError<'_, Data, Report>) {
|
||||
match error {
|
||||
|
@ -12,23 +12,23 @@ pub async fn handle(error: FrameworkError<'_, Data, Report>) {
|
|||
error, framework, ..
|
||||
} => {
|
||||
error!("Error setting up client! Bailing out");
|
||||
framework.shard_manager().lock().await.shutdown_all().await;
|
||||
framework.shard_manager().shutdown_all().await;
|
||||
|
||||
panic!("{error}")
|
||||
}
|
||||
|
||||
FrameworkError::Command { error, ctx } => {
|
||||
FrameworkError::Command { error, ctx, .. } => {
|
||||
error!("Error in command {}:\n{error:?}", ctx.command().name);
|
||||
ctx.send(|c| {
|
||||
c.embed(|e| {
|
||||
e.title("Something went wrong!")
|
||||
.description("oopsie")
|
||||
.timestamp(Timestamp::now())
|
||||
.color(COLORS["red"])
|
||||
})
|
||||
})
|
||||
.await
|
||||
.ok();
|
||||
|
||||
let embed = CreateEmbed::new()
|
||||
.title("Something went wrong!")
|
||||
.description("oopsie")
|
||||
.timestamp(Timestamp::now())
|
||||
.color(COLORS["red"]);
|
||||
|
||||
let reply = CreateReply::default().embed(embed);
|
||||
|
||||
ctx.send(reply).await.ok();
|
||||
}
|
||||
|
||||
FrameworkError::EventHandler {
|
||||
|
@ -36,13 +36,17 @@ pub async fn handle(error: FrameworkError<'_, Data, Report>) {
|
|||
ctx: _,
|
||||
event,
|
||||
framework: _,
|
||||
..
|
||||
} => {
|
||||
error!("Error while handling event {}:\n{error:?}", event.name());
|
||||
error!(
|
||||
"Error while handling event {}:\n{error:?}",
|
||||
event.snake_case_name()
|
||||
);
|
||||
}
|
||||
|
||||
error => {
|
||||
if let Err(e) = poise::builtins::on_error(error).await {
|
||||
error!("Unhandled error occured:\n{e:#?}");
|
||||
error!("Unhandled error occurred:\n{e:#?}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,9 @@ use crate::Data;
|
|||
|
||||
use color_eyre::eyre::Result;
|
||||
use log::*;
|
||||
use poise::serenity_prelude::{Context, Message};
|
||||
use poise::serenity_prelude::{
|
||||
Context, CreateAllowedMentions, CreateEmbed, CreateMessage, Message,
|
||||
};
|
||||
|
||||
mod issues;
|
||||
mod providers;
|
||||
|
@ -17,16 +19,16 @@ pub async fn handle(ctx: &Context, message: &Message, data: &Data) -> Result<()>
|
|||
let log = find_log(message).await;
|
||||
|
||||
if log.is_err() {
|
||||
channel
|
||||
.send_message(ctx, |m| {
|
||||
m.reference_message(message)
|
||||
.allowed_mentions(|am| am.replied_user(true))
|
||||
.embed(|e| {
|
||||
e.title("Analyze failed!")
|
||||
.description("Couldn't download log")
|
||||
})
|
||||
})
|
||||
.await?;
|
||||
let embed = CreateEmbed::new()
|
||||
.title("Analyze failed!")
|
||||
.description("Couldn't download log");
|
||||
let allowed_mentions = CreateAllowedMentions::new().replied_user(true);
|
||||
let our_message = CreateMessage::new()
|
||||
.reference_message(message)
|
||||
.allowed_mentions(allowed_mentions)
|
||||
.embed(embed);
|
||||
|
||||
channel.send_message(ctx, our_message).await?;
|
||||
|
||||
return Ok(());
|
||||
}
|
||||
|
@ -38,31 +40,32 @@ pub async fn handle(ctx: &Context, message: &Message, data: &Data) -> Result<()>
|
|||
|
||||
let issues = find_issues(&log, data).await?;
|
||||
|
||||
channel
|
||||
.send_message(ctx, |m| {
|
||||
m.reference_message(message)
|
||||
.allowed_mentions(|am| am.replied_user(true))
|
||||
.embed(|e| {
|
||||
e.title("Log analysis");
|
||||
let embed = {
|
||||
let mut e = CreateEmbed::new().title("Log analysis");
|
||||
|
||||
if issues.is_empty() {
|
||||
e.color(COLORS["green"]).field(
|
||||
"Analyze failed!",
|
||||
"No issues found automatically",
|
||||
false,
|
||||
);
|
||||
} else {
|
||||
e.color(COLORS["red"]);
|
||||
if issues.is_empty() {
|
||||
e = e.color(COLORS["green"]).field(
|
||||
"Analyze failed!",
|
||||
"No issues found automatically",
|
||||
false,
|
||||
);
|
||||
} else {
|
||||
e = e.color(COLORS["red"]);
|
||||
|
||||
for (title, description) in issues {
|
||||
e.field(title, description, false);
|
||||
}
|
||||
}
|
||||
for (title, description) in issues {
|
||||
e = e.field(title, description, false);
|
||||
}
|
||||
}
|
||||
|
||||
e
|
||||
})
|
||||
})
|
||||
.await?;
|
||||
e
|
||||
};
|
||||
|
||||
let allowed_mentions = CreateAllowedMentions::new().replied_user(true);
|
||||
let message = CreateMessage::new()
|
||||
.allowed_mentions(allowed_mentions)
|
||||
.embed(embed);
|
||||
|
||||
channel.send_message(ctx, message).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ pub async fn handle(ctx: &Context, reaction: &Reaction) -> Result<()> {
|
|||
.wrap_err_with(|| "Couldn't fetch message from reaction!")?;
|
||||
|
||||
if let Some(interaction) = &message.interaction {
|
||||
if interaction.kind == InteractionType::ApplicationCommand
|
||||
if interaction.kind == InteractionType::Command
|
||||
&& interaction.user == user
|
||||
&& reaction.emoji.unicode_eq("❌")
|
||||
{
|
||||
|
|
|
@ -1,27 +1,20 @@
|
|||
use color_eyre::eyre::{eyre, Context as _, Result};
|
||||
use poise::serenity_prelude::{Context, Message};
|
||||
use color_eyre::eyre::Result;
|
||||
use poise::serenity_prelude::{Context, CreateAllowedMentions, CreateMessage, Message};
|
||||
|
||||
use crate::utils;
|
||||
|
||||
pub async fn handle(ctx: &Context, message: &Message) -> Result<()> {
|
||||
let embeds = utils::resolve_message(ctx, message).await?;
|
||||
|
||||
// TOOD getchoo: actually reply to user
|
||||
// TODO getchoo: actually reply to user
|
||||
// ...not sure why Message doesn't give me a builder in reply() or equivalents
|
||||
let our_channel = message
|
||||
.channel(ctx)
|
||||
.await
|
||||
.wrap_err_with(|| "Couldn't get channel from message!")?
|
||||
.guild()
|
||||
.ok_or_else(|| eyre!("Couldn't convert to GuildChannel!"))?;
|
||||
|
||||
if !embeds.is_empty() {
|
||||
our_channel
|
||||
.send_message(ctx, |m| {
|
||||
m.set_embeds(embeds)
|
||||
.allowed_mentions(|am| am.replied_user(false))
|
||||
})
|
||||
.await?;
|
||||
let allowed_mentions = CreateAllowedMentions::new().replied_user(false);
|
||||
let reply = CreateMessage::new()
|
||||
.embeds(embeds)
|
||||
.allowed_mentions(allowed_mentions);
|
||||
|
||||
message.channel_id.send_message(ctx, reply).await?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
|
|
@ -2,8 +2,8 @@ use crate::{api, Data};
|
|||
|
||||
use color_eyre::eyre::{Report, Result};
|
||||
use log::*;
|
||||
use poise::serenity_prelude::{Activity, Context, OnlineStatus};
|
||||
use poise::{Event, FrameworkContext};
|
||||
use poise::serenity_prelude::{ActivityData, Context, FullEvent, OnlineStatus};
|
||||
use poise::FrameworkContext;
|
||||
|
||||
mod analyze_logs;
|
||||
mod delete_on_reaction;
|
||||
|
@ -14,22 +14,22 @@ mod support_onboard;
|
|||
|
||||
pub async fn handle(
|
||||
ctx: &Context,
|
||||
event: &Event<'_>,
|
||||
event: &FullEvent,
|
||||
_framework: FrameworkContext<'_, Data, Report>,
|
||||
data: &Data,
|
||||
) -> Result<()> {
|
||||
match event {
|
||||
Event::Ready { data_about_bot } => {
|
||||
FullEvent::Ready { data_about_bot } => {
|
||||
info!("Logged in as {}!", data_about_bot.user.name);
|
||||
|
||||
let latest_minecraft_version = api::prism_meta::get_latest_minecraft_version().await?;
|
||||
let activity = Activity::playing(format!("Minecraft {}", latest_minecraft_version));
|
||||
let activity = ActivityData::playing(format!("Minecraft {}", latest_minecraft_version));
|
||||
|
||||
info!("Setting presence to activity {activity:#?}");
|
||||
ctx.set_presence(Some(activity), OnlineStatus::Online).await;
|
||||
ctx.set_presence(Some(activity), OnlineStatus::Online);
|
||||
}
|
||||
|
||||
Event::Message { new_message } => {
|
||||
FullEvent::Message { new_message } => {
|
||||
// ignore new messages from bots
|
||||
// NOTE: the webhook_id check allows us to still respond to PK users
|
||||
if new_message.author.bot && new_message.webhook_id.is_none() {
|
||||
|
@ -52,11 +52,13 @@ pub async fn handle(
|
|||
analyze_logs::handle(ctx, new_message, data).await?;
|
||||
}
|
||||
|
||||
Event::ReactionAdd { add_reaction } => {
|
||||
delete_on_reaction::handle(ctx, add_reaction).await?
|
||||
FullEvent::ReactionAdd { add_reaction } => {
|
||||
delete_on_reaction::handle(ctx, add_reaction).await?;
|
||||
}
|
||||
|
||||
Event::ThreadCreate { thread } => support_onboard::handle(ctx, thread).await?,
|
||||
FullEvent::ThreadCreate { thread } => {
|
||||
support_onboard::handle(ctx, thread).await?;
|
||||
}
|
||||
|
||||
_ => {}
|
||||
}
|
||||
|
|
|
@ -1,22 +1,23 @@
|
|||
use color_eyre::eyre::{eyre, Result};
|
||||
use log::*;
|
||||
use poise::serenity_prelude::{ChannelType, Context, GuildChannel};
|
||||
use poise::serenity_prelude::{
|
||||
ChannelType, Context, CreateAllowedMentions, CreateMessage, GuildChannel,
|
||||
};
|
||||
|
||||
pub async fn handle(ctx: &Context, thread: &GuildChannel) -> Result<()> {
|
||||
if thread.kind != ChannelType::PublicThread {
|
||||
debug!("Not doing support onboard in non-thread channel");
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let parent_id = thread
|
||||
if thread
|
||||
.parent_id
|
||||
.ok_or_else(|| eyre!("Couldn't get parent ID from thread {}!", thread.name))?;
|
||||
|
||||
let parent_channel = ctx
|
||||
.cache
|
||||
.guild_channel(parent_id)
|
||||
.ok_or_else(|| eyre!("Couldn't get GuildChannel {}!", parent_id))?;
|
||||
|
||||
if parent_channel.name != "support" {
|
||||
.ok_or_else(|| eyre!("Couldn't get parent ID from thread {}!", thread.name))?
|
||||
.name(ctx)
|
||||
.await
|
||||
.unwrap_or("".to_string())
|
||||
!= "support"
|
||||
{
|
||||
debug!("Not posting onboarding message to threads outside of support");
|
||||
return Ok(());
|
||||
}
|
||||
|
@ -32,12 +33,15 @@ pub async fn handle(ctx: &Context, thread: &GuildChannel) -> Result<()> {
|
|||
"Please don't ping people for support questions, unless you have their permission."
|
||||
);
|
||||
|
||||
thread
|
||||
.send_message(ctx, |m| {
|
||||
m.content(msg)
|
||||
.allowed_mentions(|am| am.replied_user(true).users(Vec::from([owner])))
|
||||
})
|
||||
.await?;
|
||||
let allowed_mentions = CreateAllowedMentions::new()
|
||||
.replied_user(true)
|
||||
.users(Vec::from([owner]));
|
||||
|
||||
let message = CreateMessage::new()
|
||||
.content(msg)
|
||||
.allowed_mentions(allowed_mentions);
|
||||
|
||||
thread.send_message(ctx, message).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue