Update template with changes
This commit is contained in:
parent
5cc3b5c8a1
commit
99e43404e3
@ -1,5 +1,6 @@
|
||||
.vscode
|
||||
target
|
||||
target/debug
|
||||
target/release
|
||||
.gitignore
|
||||
docker-compose.yml
|
||||
Dockerfile
|
||||
|
4
.gitignore
vendored
4
.gitignore
vendored
@ -1 +1,5 @@
|
||||
target
|
||||
.env*
|
||||
|
||||
# Local version of GHA
|
||||
act
|
||||
|
@ -12,14 +12,14 @@ use {
|
||||
Ready
|
||||
},
|
||||
rustbot_lib::{
|
||||
RustbotFwCtx,
|
||||
RustbotResult,
|
||||
config::BINARY_PROPERTIES,
|
||||
utils::{
|
||||
BOT_VERSION,
|
||||
GIT_COMMIT_BRANCH,
|
||||
GIT_COMMIT_HASH
|
||||
},
|
||||
RustbotFwCtx,
|
||||
RustbotResult
|
||||
}
|
||||
},
|
||||
std::sync::atomic::{
|
||||
AtomicBool,
|
||||
|
@ -8,8 +8,8 @@ use {
|
||||
tokio::{
|
||||
task,
|
||||
time::{
|
||||
interval,
|
||||
Duration
|
||||
Duration,
|
||||
interval
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -20,7 +20,7 @@ impl ConfigMeta {
|
||||
embed_color: 0xF1D63C,
|
||||
rustbot_logs: 1311282815601741844,
|
||||
developers: vec![
|
||||
190407856527376384, // toast.ts
|
||||
190407856527376384, // nwero.sama
|
||||
]
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ mod data;
|
||||
pub use data::RustbotData;
|
||||
pub mod utils;
|
||||
|
||||
type RustbotError = Box<dyn std::error::Error + Send + Sync>;
|
||||
pub type RustbotError = Box<dyn std::error::Error + Send + Sync>;
|
||||
pub type RustbotContext<'a> = poise::Context<'a, RustbotData, RustbotError>;
|
||||
pub type RustbotFwCtx<'a> = poise::FrameworkContext<'a, RustbotData, RustbotError>;
|
||||
pub type RustbotResult<T> = Result<T, RustbotError>;
|
||||
|
@ -33,11 +33,7 @@ pub fn mention_dev(ctx: super::RustbotContext<'_>) -> Option<String> {
|
||||
}
|
||||
}
|
||||
|
||||
if mentions.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(mentions.join(", "))
|
||||
}
|
||||
if mentions.is_empty() { None } else { Some(mentions.join(", ")) }
|
||||
}
|
||||
|
||||
pub fn get_guild_name(ctx: super::RustbotContext<'_>) -> String {
|
||||
|
74
src/errors.rs
Normal file
74
src/errors.rs
Normal file
@ -0,0 +1,74 @@
|
||||
use {
|
||||
poise::FrameworkError,
|
||||
rustbot_lib::{
|
||||
RustbotData,
|
||||
RustbotError,
|
||||
utils::mention_dev
|
||||
}
|
||||
};
|
||||
|
||||
pub async fn fw_errors(error: FrameworkError<'_, RustbotData, RustbotError>) {
|
||||
match error {
|
||||
poise::FrameworkError::Command { error, ctx, .. } => {
|
||||
println!("PoiseCommandError({}): {error}", ctx.command().qualified_name);
|
||||
ctx
|
||||
.reply(format!(
|
||||
"Encountered an error during command execution, ask {} to check console for more details!",
|
||||
mention_dev(ctx).unwrap_or_default()
|
||||
))
|
||||
.await
|
||||
.expect("Error sending message");
|
||||
},
|
||||
poise::FrameworkError::EventHandler { error, event, .. } => println!("PoiseEventHandlerError({}): {error}", event.snake_case_name()),
|
||||
poise::FrameworkError::NotAnOwner { ctx, .. } => {
|
||||
println!(
|
||||
"PoiseNotAnOwner: {} tried to execute a developer-level command ({})",
|
||||
ctx.author().name,
|
||||
ctx.command().qualified_name
|
||||
);
|
||||
ctx
|
||||
.reply("Whoa, you discovered a hidden command! Too bad, I can't allow you to execute it as you're not my creator.")
|
||||
.await
|
||||
.expect("Error sending message");
|
||||
},
|
||||
poise::FrameworkError::UnknownInteraction { interaction, .. } => println!(
|
||||
"PoiseUnknownInteractionError: {} tried to execute an unknown interaction ({})",
|
||||
interaction.user.name, interaction.data.name
|
||||
),
|
||||
poise::FrameworkError::UnknownCommand { msg, .. } => println!(
|
||||
"PoiseUnknownCommandError: {} tried to execute an unknown command ({})",
|
||||
msg.author.name, msg.content
|
||||
),
|
||||
poise::FrameworkError::ArgumentParse { ctx, error, .. } => {
|
||||
println!("PoiseArgumentParseError: {error}");
|
||||
ctx
|
||||
.reply(format!("Error parsing argument(s): {error}"))
|
||||
.await
|
||||
.expect("Error sending message");
|
||||
},
|
||||
poise::FrameworkError::CommandPanic { ctx, payload, .. } => {
|
||||
if let Some(payload) = payload.clone() {
|
||||
println!("PoiseCommandPanic: {payload}");
|
||||
ctx
|
||||
.reply(format!(
|
||||
"The command panicked, please tell my developer about this!\n**Error:**```\n{payload}\n```"
|
||||
))
|
||||
.await
|
||||
.expect("Error sending message");
|
||||
} else {
|
||||
println!("PoiseCommandPanic: No payload provided");
|
||||
ctx
|
||||
.reply(
|
||||
[
|
||||
"Well, this is concerning... Hopefully you notified my developer about this!",
|
||||
"The command panicked, but didn't leave any trace behind... Suspicious!"
|
||||
]
|
||||
.join("\n")
|
||||
)
|
||||
.await
|
||||
.expect("Error sending message");
|
||||
}
|
||||
},
|
||||
other => println!("PoiseOtherError: {other}")
|
||||
}
|
||||
}
|
76
src/main.rs
76
src/main.rs
@ -1,23 +1,21 @@
|
||||
mod errors;
|
||||
mod shutdown;
|
||||
// https://cdn.toast-server.net/RustFSHiearchy.png
|
||||
// Using the new filesystem hierarchy
|
||||
|
||||
use {
|
||||
poise::serenity_prelude::{
|
||||
builder::CreateAllowedMentions,
|
||||
ActivityData,
|
||||
ClientBuilder,
|
||||
GatewayIntents
|
||||
GatewayIntents,
|
||||
builder::CreateAllowedMentions
|
||||
},
|
||||
rustbot_cmds::collect,
|
||||
rustbot_events::events::processor,
|
||||
rustbot_lib::{
|
||||
RustbotData,
|
||||
config::BINARY_PROPERTIES,
|
||||
utils::{
|
||||
get_guild_name,
|
||||
mention_dev
|
||||
},
|
||||
RustbotData
|
||||
utils::get_guild_name
|
||||
},
|
||||
rustbot_tokens::discord_token,
|
||||
std::{
|
||||
@ -65,69 +63,7 @@ async fn main() {
|
||||
execute_self_messages: false,
|
||||
..Default::default()
|
||||
},
|
||||
on_error: |error| {
|
||||
Box::pin(async move {
|
||||
match error {
|
||||
poise::FrameworkError::Command { error, ctx, .. } => {
|
||||
println!("PoiseCommandError({}): {}", ctx.command().qualified_name, error);
|
||||
ctx
|
||||
.reply(format!(
|
||||
"Encountered an error during command execution, ask {} to check console for more details!",
|
||||
mention_dev(ctx).unwrap_or_default()
|
||||
))
|
||||
.await
|
||||
.expect("Error sending message");
|
||||
},
|
||||
poise::FrameworkError::EventHandler { error, event, .. } => println!("PoiseEventHandlerError({}): {}", event.snake_case_name(), error),
|
||||
poise::FrameworkError::NotAnOwner { ctx, .. } => {
|
||||
println!(
|
||||
"PoiseNotAnOwner: {} tried to execute a developer-level command ({})",
|
||||
ctx.author().name,
|
||||
ctx.command().qualified_name
|
||||
);
|
||||
ctx
|
||||
.reply("Whoa, you discovered a hidden command! Too bad, I can't allow you to execute it as you're not my creator.")
|
||||
.await
|
||||
.expect("Error sending message");
|
||||
},
|
||||
poise::FrameworkError::UnknownInteraction { interaction, .. } => println!(
|
||||
"PoiseUnknownInteractionError: {} tried to execute an unknown interaction ({})",
|
||||
interaction.user.name, interaction.data.name
|
||||
),
|
||||
poise::FrameworkError::UnknownCommand { msg, .. } => println!(
|
||||
"PoiseUnknownCommandError: {} tried to execute an unknown command ({})",
|
||||
msg.author.name, msg.content
|
||||
),
|
||||
poise::FrameworkError::ArgumentParse { ctx, error, .. } => {
|
||||
println!("PoiseArgumentParseError: {}", error);
|
||||
ctx
|
||||
.reply(format!("Error parsing argument(s): {error}"))
|
||||
.await
|
||||
.expect("Error sending message");
|
||||
},
|
||||
poise::FrameworkError::CommandPanic { ctx, payload, .. } => {
|
||||
if let Some(payload) = payload.clone() {
|
||||
println!("PoiseCommandPanic: {payload}");
|
||||
ctx
|
||||
.reply(format!(
|
||||
"The command panicked, please tell my developer about this!\n**Error:**```\n{payload}\n```"
|
||||
))
|
||||
.await
|
||||
.expect("Error sending message");
|
||||
} else {
|
||||
println!("PoiseCommandPanic: No payload provided");
|
||||
let uh_oh = [
|
||||
"Well, this is concerning... Hopefully you notified my developer about this!",
|
||||
"The command panicked, but didn't leave any trace behind... Suspicious!"
|
||||
]
|
||||
.join("\n");
|
||||
ctx.reply(uh_oh).await.expect("Error sending message");
|
||||
}
|
||||
},
|
||||
other => println!("PoiseOtherError: {other}")
|
||||
}
|
||||
})
|
||||
},
|
||||
on_error: |error| Box::pin(async move { errors::fw_errors(error).await }),
|
||||
allowed_mentions: Some(CreateAllowedMentions::default().empty_users()),
|
||||
initialize_owners: true,
|
||||
skip_checks_for_owners: true,
|
||||
|
@ -1,8 +1,8 @@
|
||||
use tokio::{
|
||||
select,
|
||||
signal::unix::{
|
||||
signal,
|
||||
SignalKind
|
||||
SignalKind,
|
||||
signal
|
||||
}
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user