Update template with changes
This commit is contained in:
parent
5cc3b5c8a1
commit
99e43404e3
@ -1,5 +1,6 @@
|
|||||||
.vscode
|
.vscode
|
||||||
target
|
target/debug
|
||||||
|
target/release
|
||||||
.gitignore
|
.gitignore
|
||||||
docker-compose.yml
|
docker-compose.yml
|
||||||
Dockerfile
|
Dockerfile
|
||||||
|
4
.gitignore
vendored
4
.gitignore
vendored
@ -1 +1,5 @@
|
|||||||
target
|
target
|
||||||
|
.env*
|
||||||
|
|
||||||
|
# Local version of GHA
|
||||||
|
act
|
||||||
|
@ -12,14 +12,14 @@ use {
|
|||||||
Ready
|
Ready
|
||||||
},
|
},
|
||||||
rustbot_lib::{
|
rustbot_lib::{
|
||||||
|
RustbotFwCtx,
|
||||||
|
RustbotResult,
|
||||||
config::BINARY_PROPERTIES,
|
config::BINARY_PROPERTIES,
|
||||||
utils::{
|
utils::{
|
||||||
BOT_VERSION,
|
BOT_VERSION,
|
||||||
GIT_COMMIT_BRANCH,
|
GIT_COMMIT_BRANCH,
|
||||||
GIT_COMMIT_HASH
|
GIT_COMMIT_HASH
|
||||||
},
|
}
|
||||||
RustbotFwCtx,
|
|
||||||
RustbotResult
|
|
||||||
},
|
},
|
||||||
std::sync::atomic::{
|
std::sync::atomic::{
|
||||||
AtomicBool,
|
AtomicBool,
|
||||||
|
@ -8,8 +8,8 @@ use {
|
|||||||
tokio::{
|
tokio::{
|
||||||
task,
|
task,
|
||||||
time::{
|
time::{
|
||||||
interval,
|
Duration,
|
||||||
Duration
|
interval
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -20,7 +20,7 @@ impl ConfigMeta {
|
|||||||
embed_color: 0xF1D63C,
|
embed_color: 0xF1D63C,
|
||||||
rustbot_logs: 1311282815601741844,
|
rustbot_logs: 1311282815601741844,
|
||||||
developers: vec![
|
developers: vec![
|
||||||
190407856527376384, // toast.ts
|
190407856527376384, // nwero.sama
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ mod data;
|
|||||||
pub use data::RustbotData;
|
pub use data::RustbotData;
|
||||||
pub mod utils;
|
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 RustbotContext<'a> = poise::Context<'a, RustbotData, RustbotError>;
|
||||||
pub type RustbotFwCtx<'a> = poise::FrameworkContext<'a, RustbotData, RustbotError>;
|
pub type RustbotFwCtx<'a> = poise::FrameworkContext<'a, RustbotData, RustbotError>;
|
||||||
pub type RustbotResult<T> = Result<T, 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() {
|
if mentions.is_empty() { None } else { Some(mentions.join(", ")) }
|
||||||
None
|
|
||||||
} else {
|
|
||||||
Some(mentions.join(", "))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_guild_name(ctx: super::RustbotContext<'_>) -> String {
|
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;
|
mod shutdown;
|
||||||
// https://cdn.toast-server.net/RustFSHiearchy.png
|
// https://cdn.toast-server.net/RustFSHiearchy.png
|
||||||
// Using the new filesystem hierarchy
|
// Using the new filesystem hierarchy
|
||||||
|
|
||||||
use {
|
use {
|
||||||
poise::serenity_prelude::{
|
poise::serenity_prelude::{
|
||||||
builder::CreateAllowedMentions,
|
|
||||||
ActivityData,
|
ActivityData,
|
||||||
ClientBuilder,
|
ClientBuilder,
|
||||||
GatewayIntents
|
GatewayIntents,
|
||||||
|
builder::CreateAllowedMentions
|
||||||
},
|
},
|
||||||
rustbot_cmds::collect,
|
rustbot_cmds::collect,
|
||||||
rustbot_events::events::processor,
|
rustbot_events::events::processor,
|
||||||
rustbot_lib::{
|
rustbot_lib::{
|
||||||
|
RustbotData,
|
||||||
config::BINARY_PROPERTIES,
|
config::BINARY_PROPERTIES,
|
||||||
utils::{
|
utils::get_guild_name
|
||||||
get_guild_name,
|
|
||||||
mention_dev
|
|
||||||
},
|
|
||||||
RustbotData
|
|
||||||
},
|
},
|
||||||
rustbot_tokens::discord_token,
|
rustbot_tokens::discord_token,
|
||||||
std::{
|
std::{
|
||||||
@ -65,69 +63,7 @@ async fn main() {
|
|||||||
execute_self_messages: false,
|
execute_self_messages: false,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
on_error: |error| {
|
on_error: |error| Box::pin(async move { errors::fw_errors(error).await }),
|
||||||
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}")
|
|
||||||
}
|
|
||||||
})
|
|
||||||
},
|
|
||||||
allowed_mentions: Some(CreateAllowedMentions::default().empty_users()),
|
allowed_mentions: Some(CreateAllowedMentions::default().empty_users()),
|
||||||
initialize_owners: true,
|
initialize_owners: true,
|
||||||
skip_checks_for_owners: true,
|
skip_checks_for_owners: true,
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
use tokio::{
|
use tokio::{
|
||||||
select,
|
select,
|
||||||
signal::unix::{
|
signal::unix::{
|
||||||
signal,
|
SignalKind,
|
||||||
SignalKind
|
signal
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user