| Commit message (Collapse) | Author | Age | Files | Lines |
| |
|
|
|
|
|
|
|
| |
Move the unit tests into the relevant source files. There's no need for them to
be seprate, especially when the `tests` directory is meant to be for integration
tests.
The deserialization tests that include JSON files are still in the `tests` dir,
along with the public prelude re-export tests.
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
This commit monomorphizes all functions, turning functions like:
```rust
fn foo<T: Into<Bar>>(baz: T) {
baz = baz.into();
// function here
}
```
Into functions like:
```rust
fn foo<T: Into<Bar>>(baz: T) {
_foo(baz.into())
}
fn _foo(baz: Bar) {
// function here
}
```
This avoids binary bloat and improves build times, by reducing the amount of
code duplication.
|
| | |
|
| | |
|
| |
|
|
|
|
| |
In the utils::is_nsfw function, an input of 'nsfw-' shouldn't return true.
Discord's (previous) NSFW detection classified 'nsfw' and anything starting with
'nsfw-' - but not including - as NSFW.
|
| |
|
|
|
|
|
|
|
| |
Removes string slicing on the input string, instead preferring to count chars
and work off that information.
Fixes channel names with unicode such as `général`.
Fixes #342.
|
| | |
|
| | |
|
| | |
|
| |
|
|
|
| |
This makes them easier to be found by tools like rls.
Also update struct inits to use the shorthand version for `x: x`.
|
| |
|
|
|
| |
Fix broken links caused by the `model` module changes in v0.5.0, which
split up the module into sub-modules for better organization.
|
| |
|
|
| |
This also fixes no-builder compilation
|
| | |
|
| |
|
|
|
|
| |
By negating hashing altogether.
The increase is around 1000-ish nanoseconds saved.
|
| |
|
|
|
| |
Fix clippy lints and subsequently accept references for more function
parameters.
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
The `model` module has historically been one giant module re-exporting
all of the model types, which is somewhere around 100 types. This can be
a lot to look at for a new user and somewhat overwhelming, especially
with a large number of fine-grained imports from the module.
The module is now neatly split up into submodules, mostly like it has
been internally since the early versions of the library. The submodules
are:
- application
- channel
- error
- event
- gateway
- guild
- id
- invite
- misc
- permissions
- prelude
- user
- voice
- webhook
Each submodule contains types that are "owned" by the module. For
example, the `guild` submodule contains, but not limited to, Emoji,
AuditLogsEntry, Role, and Member. `channel` contains, but not limited
to, Attachment, Embed, Message, and Reaction.
Upgrade path:
Instead of glob importing the models via `use serenity::model::*;`,
instead glob import via the prelude:
```rust
use serenity::model::prelude::*;
```
Instead of importing from the root model module:
```rust
use serenity::model::{Guild, Message, OnlineStatus, Role, User};
```
instead import from the submodules like so:
```rust
use serenity::model::channel::Message;
use serenity::model::guild::{Guild, Role};
use serenity::model::user::{OnlineStatus, User};
```
|
| | |
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Builders would keep a `serde_json::Map<String, Value>`, which would
require re-creating owned strings for the same parameter multiple times
in some cases, depending on builder defaults and keying strategies.
This commit uses a `std::collections::HashMap<&'static str, Value>`
internally, and moves over values to a `serde_json::Map<String, Value>`
when it comes time to sending them to the appropriate `http` module
function.
This saves the number of heap-allocated string creations on most
builders, with specific performance increase on `builder::CreateMessage`
and `builder::CreateEmbed` & co.
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Switch to the `parking_lot` crate's implementations of
`std::sync::Mutex` and `std::sync::RwLock`, which are more efficient.
A writeup on why `parking_lot` is more efficient can be read here:
<https://github.com/Amanieu/parking_lot>
Upgrade path:
Modify `mutex.lock().unwrap()` usage to `mutex.lock()` (not needing to
unwrap or handle a result), and
`rwlock.read().unwrap()`/`rwlock.write().unwrap()` usage to
`rwlock.read()` and `rwlock.write()`.
For example, modify:
```rust
use serenity::CACHE;
println!("{}", CACHE.read().unwrap().user.id);
```
to:
```rust
use serenity::CACHE;
println!("{}", CACHE.read().user.id);
```
|
| | |
|
| |
|
|
|
| |
This fixes compilation errors and warnings when compiling a mixture of
non-default feature targets.
|
| | |
|
| | |
|
| | |
|
| | |
|
| |
|
| |
Allow `push` and `push_safe` to use a flexible syntax for formatting.
|
| |
|
|
|
| |
Add examples to some functions, and update some of the old examples to
use the `?` operator instead of unwrapping.
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Modules are now separated into a fashion where the library can be used
for most use cases, without needing to compile the rest.
The core of serenity, with no features enabled, contains only the
struct (model) definitions, constants, and prelude. Models do not have
most functions compiled in, as that is separated into the `model`
feature.
The `client` module has been split into 3 modules: `client`, `gateway`,
and `http`.
`http` contains functions to interact with the REST API. `gateway`
contains the Shard to interact with the gateway, requiring `http` for
retrieving the gateway URL. `client` requires both of the other features
and acts as an abstracted interface over both the gateway and REST APIs,
handling the event loop.
The `builder` module has been separated from `utils`, and can now be
optionally compiled in. It and the `http` feature are required by the
`model` feature due to a large number of methods requiring access to
them.
`utils` now contains a number of utilities, such as the Colour struct, the
`MessageBuilder`, and mention parsing functions.
Each of the original `ext` modules are still featured, with `cache` not
requiring any feature to be enabled, `framework` requiring the `client`,
`model`, and `utils`, and `voice` requiring `gateway`.
In total the features and their requirements are:
- `builder`: none
- `cache`: none
- `client`: `gateway`, `http`
- `framework`: `client`, `model`, `utils`
- `gateway`: `http`
- `http`: none
- `model`: `builder`, `http`
- `utils`: none
- `voice`: `gateway`
The default features are `builder`, `cache`, `client`, `framework`,
`gateway`, `model`, `http`, and `utils`.
To help with forwards compatibility, modules have been re-exported from
their original locations.
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
A new feature in Discord is warning users about NSFW channels. This can
be useful when wanting to determine if a command can be used in a
channel or not, depending on the command content.
To help with this, provide a utility function named `utils::is_nsfw`.
This function accepts a channel name, which determines if the channel
is NSFW.
This information is not provided with data from the server. It is
determined client-side based on a few rules.
The rules for a channel being NSFW are:
- must be a guild channel
- must be a text channel
- must be named `nsfw` or be prefixed with `nsfw-`
If any of these conditions are false, then the channel is not NSFW.
Additionally, provide four helper methods:
- `GuildChannel::is_nsfw`: follows rules
- `Group::is_nsfw`: always false
- `PrivateChannel::is_nsfw`: always false
- `Channel::is_nsfw`: depends on inner channel (one of 3 above)
This check is volatile, as Discord may change requirements at any time.
The check provided by the library should not be taken as being accurate
all the time.
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Add helpers to retrieve the shard Id for guilds, and count how many
guilds are handled by a Shard.
Helpers to retrieve the shard Id of a guild have been added as:
- `Guild::shard_id`
- `GuildId::shard_id`
These are in two forms: one working with the cache feature, and one
without. The function that works with the cache will automatically
retrieve the total number of shards from the Cache, while the uncached
version requires passing in the total number of shards used.
With the cache enabled, this might look like:
```rust
guild.shard_id();
// which calls:
guild_id.shard_id();
```
Without the cache enabled, this looks like:
```rust
let shard_count = 7;
guild.shard_id(shard_count);
// which calls:
guild_id.shard_id(shard_count);
```
These two variants on `Guild` and `GuildId` are helper sugar methods
over the new function `utils::shard_id`, which accepts a `guild_id` and
a `shard_count`:
```rust
use serenity::utils;
assert_eq!(utils::shard_id(81384788765712384, 17), 7);
```
You would use `utils::shard_id` when you have the total number of shards
due to `{Guild,GuildId}::shard_id` unlocking the cache to retrieve the
total number of shards. This avoids some amount of work
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
The current build system is rudimentary, incomplete, and rigid, offering
little in the way of customizing decoding options.
To solve this, switch to using serde-derive with custom Deserialization
implementations. This allows very simple deserialization when special
logic does not need to be applied, yet allows us to implement our own
deserialization logic when required.
The problem with the build system was that it built enums and structs
from YAML files. This is not so good, because it requires creating a
custom build system (which was rudimentary), creating "special struct
configs" when logic needed to be ever so slightly extended (rigid), and
if special logic needed to be applied, a custom deserialization method
would have been needed to be made anyway (incomplete).
To solve this, switch to serde-derive and implementing Deserialize
ourselves where required. This reduces YAML definitions that might
look like:
```yaml
---
name: Group
description: >
A group channel, potentially including other users, separate from a [`Guild`].
[`Guild`]: struct.Guild.html
fields:
- name: channel_id
description: The Id of the group channel.
from: id
type: ChannelId
- name: icon
description: The optional icon of the group channel.
optional: true
type: string
- name: last_message_id
description: The Id of the last message sent.
optional: true
type: MessageId
- name: last_pin_timestamp
description: Timestamp of the latest pinned message.
optional: true
type: string
- name: name
description: The name of the group channel.
optional: true
type: string
- name: owner_id
description: The Id of the group channel creator.
type: UserId
- name: recipients
description: Group channel's members.
custom: decode_users
t: UserId, Arc<RwLock<User>>
type: hashmap
```
to:
```rs
/// A group channel - potentially including other [`User`]s - separate from a
/// [`Guild`].
///
/// [`Guild`]: struct.Guild.html
/// [`User`]: struct.User.html
pub struct Group {
/// The Id of the group channel.
#[serde(rename="id")]
pub channel_id: ChannelId,
/// The optional icon of the group channel.
pub icon: Option<String>,
/// The Id of the last message sent.
pub last_message_id: Option<MessageId>,
/// Timestamp of the latest pinned message.
pub last_pin_timestamp: Option<String>,
/// The name of the group channel.
pub name: Option<String>,
/// The Id of the group owner.
pub owner_id: UserId,
/// A map of the group's recipients.
#[serde(deserialize_with="deserialize_users")]
pub recipients: HashMap<UserId, Arc<RwLock<User>>>,
}
```
This is much simpler and does not have as much boilerplate.
There should not be any backwards incompatible changes other than the
old, public - yet undocumented (and hidden from documentation) - decode
methods being removed. Due to the nature of this commit, field names may
be incorrect, and will need to be corrected as deserialization errors
are found.
|
| | |
|
| | |
|
| |
|
|
|
| |
Add a command builder, which can take arguments such as multiple checks,
quoted arguments, and multiple prefix support, as well as dynamic
prefixes per context.
|
| |
|
| |
This breaks compatibility with < 1.13, but we didn't support that anyway.
|
| |
|
|
|
| |
Add EmojiIdentifier, allow User, UserId, Role, RoleId, EmojiIdentifier,
Channel and ChannelId to be used as arguments for commands and add more
parsing functions to utils
|
| | |
|
| |
|
|
|
| |
Add documentation for some missing methods - such as Game methods - and
add more methods to the Message Builder.
|
| |
|
|
|
|
| |
There aren't many things behind this flag (6), and it only causes
annoyances for locally-generated docs, which won't show these
mostly-useful items behind the flag.
|
| | |
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
This adds conditional compilation for the following features, in
addition to the voice conditional compilation flag:
- extras (message builder)
- framework
- methods
- state
These 4 are enabled _by default_, while the `voice` feature flag is
disabled.
Disabling the state will allow incredibly low-memory bots.
|
| | |
|
| |
|
|
|
| |
Create a general `internal` module, and move `prelude_internal` to
`internal::prelude`.
|
| |
|
|
|
|
|
|
|
| |
The builders aren't a large enough portion of the library to deserve
their own root-level module, so move them to the `utils` module.
Additionally, split them into separate files, as the library will be
receiving more builders and the single-file pattern was getting rather
large.
|
| | |
|
| | |
|
| | |
|
| |
|
|
|
|
|
| |
Users can now import all of a prelude via `use serenity::prelude::*;`,
which should provide some helpful stuff. As such, the internal
prelude is now named `serenity::prelude_internal`, and all internal uses
have been adjusted.
|
| |
|
|
|
| |
Refer to the documentation for `serenity::client::ratelimiting::Route`
on how major parameters work.
|
| |
|