aboutsummaryrefslogtreecommitdiff
path: root/src/lib.rs
blob: 337bee85a83dc856b7ad52f02a8837ee20458740 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
//! Serenity is an ergonomic and high-level Rust library for the Discord API.
//!
//! View the [examples] on how to make and structure a bot.
//!
//! Serenity supports both bot and user login via the use of [`Client::login_bot`]
//! and [`Client::login_user`].
//!
//! You may also check your tokens prior to login via the use of
//! [`validate_token`].
//!
//! Once logged in, you may add handlers to your client to dispatch [`Event`]s,
//! such as [`Client::on_message`]. This will cause your handler to be called
//! when a [`Event::MessageCreate`] is received. Each handler is given a
//! [`Context`], giving information about the event. See the
//! [client's module-level documentation].
//!
//! The [`Connection`] is transparently handled by the library, removing
//! unnecessary complexity. Sharded connections are automatically handled for
//! you. See the [Connection's documentation][`Connection`] for more
//! information.
//!
//! A [`State`] is also provided for you. This will be updated automatically for
//! you as data is received from the Discord API via events. When calling a
//! method on a [`Context`], the state will first be searched for relevant data
//! to avoid unnecessary HTTP requests to the Discord API. For more information,
//! see the [state's module-level documentation][state docs].
//!
//! Note that - although this documentation will try to be as up-to-date and
//! accurate as possible - Discord hosts [official documentation][docs]. If you
//! need to be sure that some information piece is accurate, refer to their
//! docs.
//!
//! # Dependencies
//!
//! Serenity requires the following dependencies:
//!
//! - openssl
//!
//! # Example Bot
//!
//! A basic ping-pong bot looks like:
//!
//! ```rust,ignore
//! extern crate serenity;
//!
//! use serenity::Client;
//!
//! fn main() {
//!     // Login with a bot token from the environment
//!     let client = Client::login_bot(env::var("DISCORD_TOKEN").expect("token"));
//!     client.with_framework(|f| f
//!         .configure(|c| c.prefix("~")) // set the bot's prefix to "~"
//!         .prefix("~")
//!         .on("ping", |_context, message| drop(message.reply("Pong!"))));
//!
//!     let _ = client.start(); // start listening for events by starting a connection
//! }
//! ```
//!
//! [`Client::login_bot`]: client/struct.Client.html#method.login_bot
//! [`Client::login_user`]: client/struct.Client.html#method.login_user
//! [`Client::on_message`]: client/struct.Client.html#method.on_message
//! [`validate_token`]: client/fn.validate_token.html
//! [`Connection`]: client/struct.Connection.html
//! [`Context`]: client/struct.Context.html
//! [`Event`]: model/enum.Event.html
//! [`Event::MessageCreate`]: model/enum.Event.html#variant.MessageCreate
//! [`State`]: ext/state/struct.State.html
//! [client's module-level documentation]: client/index.html
//! [docs]: https://discordapp.com/developers/docs/intro
//! [examples]: https://github.com/zeyla/serenity.rs/tree/master/examples
//! [state docs]: ext/state/index.html
#![allow(doc_markdown, unknown_lints)]
#![allow(dead_code)]

#[macro_use]
extern crate bitflags;
#[macro_use]
extern crate lazy_static;
#[macro_use]
extern crate log;

extern crate base64;
extern crate byteorder;
extern crate flate2;
extern crate hyper;
extern crate multipart;
extern crate serde_json;
extern crate time;
extern crate websocket;

#[macro_use]
pub mod utils;

pub mod builder;
pub mod client;
pub mod ext;
pub mod model;

mod constants;
mod error;
mod prelude;

pub use client::Client;
pub use error::{Error, Result};