Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
570 changes: 96 additions & 474 deletions Cargo.lock

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ serde_json = "1.0.149"
tracing = "0.1.44"
tracing-subscriber = "0.3.23"
rand = "0.10.1"
oai_rs = "0.1.3"
scraper = "0.26.0"
rusqlite = { version = "0.39.0", features = ["bundled"] }
openssl = { version = "0.10.77", features = ["vendored"] } # Required for cross-compilation
async-trait = "0.1.89"
derive_more = { version = "2.1.1", features = ["display", "from"] }

# Reduce Docker Image Size

Expand Down
5 changes: 0 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ services:
- DATABASE_PATH=${DATABASE_PATH:-/data/}
- DISCORD_TOKEN=${DISCORD_TOKEN}
- RAPID_API_KEY=${RAPID_API_KEY}
- OPENAI_API_KEY=${OPENAI_API_KEY}
- LOG_LEVEL=${LOG_LEVEL:-info}
- TZ=${TZ:-UTC}
volumes:
Expand All @@ -53,10 +52,6 @@ This should contain a Discord Bot token and can be registered [here](https://dis

This should contain a Rapid API key and can be registered [here](https://rapidapi.com/). This is used for the joke plugin.

#### `OPENAI_API_KEY`

This should contain an OpenAI API key and can be registered [here](https://platform.openai.com/). This is used for the AI plugin.

#### `DATABASE_PATH`

This should contain the path to the database file. The default is `/data/` and it will be created if it does not exist.
Expand Down
1 change: 0 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ services:
- DATABASE_PATH=${DATABASE_PATH:-/data/}
- DISCORD_TOKEN=${DISCORD_TOKEN}
- RAPID_API_KEY=${RAPID_API_KEY}
- OPENAI_API_KEY=${OPENAI_API_KEY}
- LOG_LEVEL=${LOG_LEVEL:-info}
- TZ=${TZ:-UTC}
volumes:
Expand Down
52 changes: 52 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
use derive_more::{Display, From};

use crate::{plugin, storage};

pub type Result<T, E = Error> = std::result::Result<T, E>;

#[derive(Debug, From, Display)]
#[non_exhaustive]
pub enum Error {
/// An error indicating that a plugin failed to send an event due to an
/// issue with the Serenity context or API.
#[display("Failed to send event: {}", err)]
FailedToSendEvent {
/// The error that occurred during sending the event
err: serenity::Error,
},

// -- Internal
/// An error related to storage operations, such as database interactions.
#[from]
Storage(storage::StorageError),
/// An error related to plugin operations.
#[from]
Plugin(plugin::PluginError),

// -- Plugin errors
/// A plugin encountered an error that doesn't fit into any of the other
/// predefined categories, allowing plugins to return custom error messages
/// or types that can be displayed or logged without needing to define a new
/// variant in the main `Error` enum for every possible plugin error
/// scenario.
Custom(Box<dyn std::error::Error + Send + Sync>),

// -- External
/// An error related to the Serenity library, such as issues with the
/// Discord API.
#[from]
Serenity(serenity::Error),

/// An error related to the reqwest library, such as issues with making
/// HTTP requests.
#[from]
Reqwest(reqwest::Error),
}

impl From<rusqlite::Error> for Error {
fn from(e: rusqlite::Error) -> Self {
Self::Storage(storage::StorageError::from(e))
}
}

Comment on lines +46 to +51

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already defined in Storage Error enum, unecessary duplication

impl std::error::Error for Error {}
Loading