stoat/lib.rs
1//! # Stoat API Wrapper
2//!
3//! A high-level Stoat API wrapper.
4//!
5//! ## Getting Started
6//!
7//! This crate requires some boilerplate to ensure errors are handled from the crate and your bot seemlessly
8//! along with defining your event callbacks.
9//!
10//! ### Defining Your Error Type
11//! Almost every event, command and callback uses your error type to allow you to propagate custom errors and
12//! stoat-rs errors throughout your code.
13//!
14//! It is reconmended to use [`thiserror`](https://docs.rs/thiserror/latest/thiserror/) to define your error
15//! however a manual implemenation is also possible if you prefer manually implementing [`From`].
16//!
17//! Your error must implement `From<stoat::Error>`, [`Debug`], [`Clone`], [`Send`], [`Sync`] and be `'static`.
18//!
19//! ```rust
20//! #[derive(Debug, Clone, thiserror::Error)]
21//! pub enum Error {
22//! #[error("Stoat Error: {0}")]
23//! StoatError(#[from] stoat::Error),
24//! }
25//! ```
26//!
27//! ### Setting Up Events
28//! All events are implemented as a function in the [`EventHandler`] trait.
29//!
30//! Every event's first parameter is [`Context`] which contains the current bot state, this is given to you
31//! in-place of your [`Client`].
32//!
33//! ```rust
34//! use stoat::{async_trait, EventHandler, Context};
35//!
36//! #[derive(Debug, Clone)]
37//! struct Events;
38//!
39//! #[async_trait]
40//! impl EventHandler for Events {
41//! type Error = Error; // Your error type defined above
42//!
43//! async fn ready(&self, context: Context) -> Result<(), Self::Error> {
44//! println!("Ready!");
45//!
46//! Ok(())
47//! }
48//! }
49//! ```
50//!
51//! ### Running The Bot
52//! Once you define your events you can create your [`Client`] which will be the root entry for running your bot.
53//!
54//! For customizing your client's config see the [`Client`] documentation.
55//!
56//! ```rust
57//! #[tokio::main]
58//! async fn main() -> Result<(), Error> {
59//! Client::new(Events).await?.run("BOT TOKEN").await
60//! }
61//! ```
62//!
63//! ## Commands
64//!
65//! See the [`commands`] module documentation for setting up commands.
66//!
67//! ## Logging
68//! This crate makes use of the [`log`](https://docs.rs/log/latest/log/) crate to relay information and errors to you.
69//!
70//! Ensure you have a log implementation setup to see the logs.
71
72#![doc(html_root_url = "https://docs.rs/stoat-rs/")]
73
74pub mod builders;
75pub mod cache;
76pub mod client;
77pub mod commands;
78pub mod context;
79pub mod error;
80pub mod events;
81pub mod ext;
82pub mod file;
83pub mod http;
84pub mod notifiers;
85pub mod permissions;
86pub mod types;
87pub mod ulid;
88pub mod utils;
89#[cfg(feature = "voice")]
90pub mod voice;
91pub mod websocket;
92
93pub use cache::{CacheConfig, GlobalCache};
94pub use client::Client;
95pub use context::Context;
96pub use error::{Error, Result};
97pub use events::EventHandler;
98pub use ext::*;
99pub use file::LocalFile;
100pub use http::HttpClient;
101pub use ulid::Ulid;
102pub use utils::*;
103#[cfg(feature = "voice")]
104pub use voice::*;
105
106pub use async_trait::async_trait;
107
108#[cfg(feature = "either")]
109pub use either;