Skip to content

Releases: serenity-rs/serenity

v0.3.0

24 Jun 16:55
Compare
Choose a tag to compare

This release contains a number of added methods, fixes, deprecations, and
documentation improvements. It brings a module restructure and an upgrade to
rust-websocket v0.20, hyper v0.10, and switching to native-tls, meaning
using an up-to-date rust-openssl v0.9 on Linux, schannel on Windows, and
Secure Transport on Mac. The long-standing issue #56 was closed.

Thanks to the following for their contributions this release:

Upgrade Path

Invite retrieval functions now accept a stats argument. If you don't need
stats, just pass false.

ChannelId::create_permission and GuildChannel::create_permission now accept
a reference, as they do not need to own the overwrite.

The deprecated GuildChannel methods (get_invites, get_message,
get_messages, get_reaction_users, get_webhooks) have been removed. Use
their equivalents without the get_ prefix.

The send_file functions have been deprecated. Use send_files instead by
passing a Vec.

CurrentUser::distinct and User::distinct have been deprecated. Instead use
CurrentUser::tag and User::tag.

User::get has been deprecated. Instead, use UserId::get.

Role::edit_role has been deprecated, renaming it to Role::edit.

time has been removed as a direct dependency, moving to chrono.
Public-facing fields that return time::Timespec or were a String in ISO-3339
format are now chrono::DateTime<UTC>s. Instead use its methods for what was
being done with the Timespecs or strings.

User::direct_message and User::dm now accept a builder to allow for more
complete, yet simple use out of the methods. Instead of passing a &str, use
the provided builder:

// old
user.dm("hello")?;

// new
user.dm(|m| m.content("hello"))?;

Client::login has been deprecated. Instead use Client::new:

use serenity::Client;
use std::env;

// old
let client = Client::login(&env::var("DISCORD_TOKEN")?);

// new
let client = Client::new(&env::var("DISCORD_TOKEN")?);

Member::guild_id is now no longer an Option<GuildId> -- just a GuildId.
Since this is now always present, Member::find_guild has been deprecated since
the cache now never searches the cache for the guild ID.

The deprecated GuildChannel methods get_invites, get_message,
get_messages, get_reaction_users, and get_webhooks have been removed. Use
their alternatives, such as GuildChannel::invites, instead.

Added

  • Add support for retrieving invites with counts (@hsiW) [c:302d771]
  • Handle message type 7 (@fwrs) [c:8f88c6b]
  • Add GuildChannel::permissions_for [c:6502ded]
  • Add Invite::url(), RichInvite::url() [c:3062981]
  • Reasonable derive Debug on all items [c:9dae9e6]
  • Add more examples and improve others [c:8c0aeac]
  • Support adding reactions when creating message (@acdenisSK) [c:77b5b48]
  • Add VerificationLevel::Higher [c:7dbae6b]
  • Add CurrentUser::invite_url (@Roughsketch, @Flat) [c:e033ff3],
    c:0b95db9
  • impl From<char> for ReactionType [c:2afab7c]
  • Implement multiple attachments (@Flat) [c:46b79dd]
  • Add _line + _line_safe methods to MessageBuilder (@Roughsketch)
    [c:543b604]
  • Add docs for CurrentUser (@Roughsketch) [c:921f7f4]
  • Add cache docs (@Roughsketch) [c:d367a70]
  • Add docs and tests for framework (@Roughsketch) [c:4267bdb]
  • Add Content for MessageBuilder (@eLunate) c:060b06e
  • Include more info on ratelimiting debugs [c:d37461b]
  • Add User::refresh [c:8c04d31]
  • Add some model docs (@Roughsketch) [c:c00f349]
  • Add Message::channel() c:063a52f
  • Add CurrentUser::default_avatar_url [c:2d09152]
  • Add CurrentUser::face(), User::face() [c:d033909]
  • Deserialize embed footers [c:e92b667]
  • Add Member::permissions [c:39a28d3] (@acdenisSK)
  • Add wait parameter to http::execute_webhook [c:dc73d1a]

Fixed

  • Don't skip @everyone role when checking channel overwrites (@Roughsketch)
    [c:b468cbf]
  • Allow unreachable_code lint in command! macro (@Flat) [c:eb43b9c]
  • Fix incorrect attempted send_file deserialization c:0102706
  • Fix ratelimits causing 429s in certain situations [c:f695174]
  • Check last heartbeat acknowledged in heartbeater [c:ec9b1c7]
  • Make client join shards and return [c:175d3a3]
  • Make client starts return an error [c:858bbf2]
  • Ws read/write timeout after 90s to avoid infinite blocking [c:1700a4a]
  • Fix negative nonces failing to deserialize [c:d0b64cd]
  • Use HTTPS Connector with remaining HTTP functions c:0d218e0 (@Roughsketch)

Changed

  • Restructure modules [c:9969be6]
  • Change create_permission to take a reference [c:aea9885]
  • Remove deprecated GuildChannel methods [c:ab7f113]
  • Guild::create_channel doesn't require mutability [c:494cc50]
  • Deprecate *User::distinct, add *User::tag [c:6579b1f]
  • Deprecate User::get [c:afc571f]
  • Deprecate Role::edit_role, add Role::edit [c:c00f349]
  • Switch to chrono [c:990e611]
  • Make User::direct_message/User::dm accept a builder c:11a02db
  • Deprecate Client::login, add Client::new [c:7990381]
  • Make Member::guild_id non-optional [c:b4bd771]
  • Remove Context::channel_id and Context::queue [c:8b504ad]
  • Make the framework's dynamic_prefix accept an &Message [c:2845681]
  • Deprecate Channel::delete_messages, Channel::delete_permission [c:7fc49d8]
  • Make Message::nonce a serde_json::Value [c:c832009]

Misc.

  • Remove deprecated login_bot usage from docs (@hsiW) [c:ae395f4]
  • Fix call to VoiceManager::join in example 06 (@barzamin) [c:6853daf]
  • Sort default help by group/command names (@Roughsketch) [c:93416cd]
  • Move CreateGroup docs to the struct [c:71f3dbb]
  • Don't create group in help if no commands to show (@Roughsketch) [c:4f5fbb5]
  • Move user avatar method logic out [c:8360f32]
  • Upgrade rust-websocket and hyper, switch to native-tls [c:8f8a059]
  • Fix broken links in README [c:51c15d0]
  • Remove unused cookie dependency [c:92f4ec2]
  • Switch from #[doc(hidden)] to pub(crate) [c:32e07e4] (@acdenisSK)
  • Re-export all errors from the prelude [c:db0f025]
  • Rework shard logic and shard handling [c:601704a]
Read more

Module rewrites, optimizations, bugfixes, & more

13 May 21:53
Compare
Choose a tag to compare

This is a very large release with a number of rewritten components. The cache
has been rewritten to make use of memory more efficiently, the models directory
has been re-organized, structures are now deserialized via serde and
serde_derive - instead of the custom decoding build script we had - with a
number of bugfixes and other various changes and additions.

Thanks to the following for their contributions this release:

Upgrade Path

Replace uses of ext::cache::ChannelRef with model::Channel.

The following ext::cache::Cache method signatures are now encased in
Arc<RwLock>s and should be handled appropriately:

  • call
  • channel
  • guild
  • guild_channel
  • group
  • member
  • role
  • user

Additionally, GuildId::find and UserId::find now return
Option<Arc<RwLock>>s.

Member::display_name now returns a Cow<String> instead of a &str.

client::Context has had most of its methods removed. The methods were mostly
a copy of those on ChannelId. Upgrade by instead calling methods on
ChannelId:

command!(foo(ctx) {
    let _ = ctx.say("hello");
});

// is now written as:

command!(bar(_ctx, msg) {
    let _ = msg.channel_id.say("hello");
});

CreateMessage::nonce has been removed. Instead, simply do not provide a nonce.

ChannelId::edit_message now has an argument signature of:

&self, message_id: M, f: F
where F: FnOnce(CreateMessage) -> CreateMessage, M: Into<MessageId>

instead of

&self, message_id: M, text: &str, f: F
where F: FnOnce(CreateEmbed) -> CreateEmbed, M: Into<MessageId>

To account for this change, modify code like so:

channel_id.edit_message(message_id, "new content", |e| e);

// now:

channel_id.edit_message(message_id, |m| m.content("new content"));

Message::edit has also had an argument signature updated to:

&mut self, f: F where F: FnOnce(CreateMessage) -> CreateMessage

from:

&mut self, new_content: &str, embed: F where F: FnOnce(CreateEmbed) -> CreateEmbed

To account for this change, modify code like so:

message.edit("new content", |e| e.description("test"));

// now:

message.edit(|m| m.content("new content").embed(|e| e.description("test")));

client::rest::accept_invite, Invite::accept, and RichInvite::accept have
been removed. Instead, do not attempt this, as they were userbot functions.

Selfbot support has been completely removed. Review the
[commit message][c:d9118c0] for the long list of details.

Group calls and guild sync have [also been removed][c:c74cc15]. Read the commit
message for all the details.

Instead of defining multiple separate error messages for command framework
message dispatches, match the dispatch error in a single method:

// old code:
client.with_framework(|f| f
    .configure(|c| c
        .command_disabled_message("The command `%command%` was disabled")
        .blocked_guild_message("The owner of this guild has been blocked")
        .invalid_permission_message("You don't have permission to use this command")));

// new code:
client.with_framework(|f| f.on_dispatch_error(|_, msg, err| {
    match err {
        DispatchError::CommandDisabled(command_name) => {
            let _ = msg.channel_id.say(&format!("The command `{}` was disabled", command_name));
        },
        DispatchError::BlockedGuild => {
            // this change also allows for more intelligent error messages:
            if let Some(guild) = msg.guild() {
                let owner_id = guild.read().unwrap().owner_id;

                if let Some(user) = CACHE.read().unwrap().user(owner_id) {
                    let c = format!("The owner - {} - has been blocked", user.name);
                    let _ = msg.channel_id.say(&c);

                    return;
                }
            }

            let _ = msg.channel_id.say("The owner of this guild has been blocked");
        },
        DispatchError::LackOfPermissions(_) => {
            let _ = msg.channel_id.say("You don't have permission to use this command");
        },
    }
}));

All functions prefixed with get_ have had the prefix removed. For example,
Guild::get_webhooks() is now Guild::webhooks().

Instead of using model::permissions::general(), model::permissions::text(),
and model::permissions::voice(), use
model::permissions::{PRESET_GENERAL, PRESET_TEXT, PRESET_VOICE}.

Added

  • Add say method to Group, GuildChannel, PrivateChannel [c:a0bb306]
  • Add missing send_file/send_message impls [c:bad9ac3]
  • Add Message::guild [c:9ef5522]
  • Add Shard Id helpers c:1561f9e
  • Implement From<&str> for ReactionType [c:e7110ad]
  • Check for embed lengths on message sends [c:e1079e9]
  • Add is_nsfw check to channels [c:9268f9c]
  • Add missing Member::kick helper [c:83b1d96]
  • Derive Eq, Hash, PartialEq on ReactionType [c:86a4e00] (@acdenisSK)

Fixed

  • Handle unsuccessful responses before decoding [c:7e254c5]
  • Uniquely ratelimit message deletions c:01f6872
  • Fix Member methods due to variant joined_at values [c:cd914f5]
  • Fix deadlock on channel create event for DMs [c:6b0b9b2] (@sschroe)
  • Default to using [0, 1] shards [c:f0d1157]
  • Fix ratelimiting for Route::None routes [c:5bf6c2d]
  • Fix guild leaving result [c:ae352ea]
  • Fix permissions when sending to DMs or groups c:404a089 (@acdenisSK)
  • Check if message starts with dynamic_prefix result [c:9ec05e7] (@Roughsketch)
  • Trim content before parsing framework args [c:e6712c9] (@Roughsketch)

Changed

  • Optimize caching c:0c9ec37
  • Remove most Context methods [c:585af23]
  • Remove sending message nonces [c:9c04a19]
  • Standardize message editing methods c:3c7c575
  • Remove invite accepting [c:e4b484f]
  • Remove selfbot support [c:d9118c0] [c:c74cc15]
  • Switch to using serde for deserialization [c:f6b27eb]
  • Update the ways errors are handled in dispatch c:31aae7d (@fwrs)
  • Deprecate methods prefixed with get_ c:3f03f9a
  • Framework help commands now accept a slice of args [c:ff4437a]
  • Make User.discriminator a u16 c:0f41ffc
  • Use constants for preset permissions [c:70d4e75]

Misc.

  • Make logo more better [c:6e11a10] (@Flat)
  • Fix incorrect cache example [c:b96f85c]
  • Rework the models directory [c:9114963]
  • Change permission values to byte literals [c:c8536c1]
  • Fix example in README [c:d4fc8b6]
Read more

rustc nightly fix & optimizations

08 Feb 17:26
Compare
Choose a tag to compare

This is a release to fix broken nightly builds, due to a change in how rustc
handles lifetimes, with a few performance optimizations and other fixes.

Upgrade Path

For Group::send_message, PrivateChannel::send_message,
and GuildChannel::send_message, instead of passing in only a &str of
content, use a CreateMessage builder:

// assuming a `channel` is bound

// old signature:
channel.send_message("hello");

// new signature:
channel.send_message(|m| m.content("hello"));

Instead of calling message_id.get_reaction_users and passing in a ChannelId,
call channel_id.get_reaction_users and pass in the MessageId. Note that the
latter already existed.

// assuming `channel_id`, `message_id`, and `reaction_type` are bound

// removed method:
message_id.get_reaction_users(channel_id, reaction_type, Some(10), None);

// alternative method:
channel_id.get_reaction_users(message_id, reaction_type, Some(10), None);

Added

  • Register the status user setting for user accounts (e.g. online, invisible)
    c:0b9bf91
  • Expose and document ratelimiting structures c:eb09f2d
  • Add method to EditGuild to transfer ownership c:f00e165

Fixed

  • Fix potential unreachable pattern warning in command! macro c:97f9bd1
  • Fix value of 'browser' in shard identify c:4cf8338
  • Remove lifetime on Search builder c:6f33a35

Changed

  • Standardize methods for creating messages c:c8c6b83
  • Remove MessageId::get_reaction_users c:268f356

Misc.

  • Avoid re-requesting the gateway URL when autosharding (optimization)
    c:e891ebe
  • Avoid cloning on non-framework message create events (opt.) c:b7cbf75
  • Avoid cloning the context on event dispatches (opt.) c:5ee5fef
  • Optimize presence update for current user in cache (opt.) c:9392f61
  • Make GLOBAL ratelimit mutex a unit (opt.) c:55ccaca
  • Resume when restarting WS sender/receiver c:04cfaa9

OOP and general stuff

26 Jan 20:13
Compare
Choose a tag to compare

This is a general release for pretty much everything, from new features to
bugfixes to a switch to a more OOP style. The current minimum supported version
is rustc 1.13+.

The next release will be v0.2.0, which will feature serde codegen support along
with a rewrite of the framework. It will be a more modularized version of the
library. v0.2.0 will require rustc 1.15+, due to the stabilization of Macros
1.1.

Thanks to the following for contributions this release:

Two of the major highlights of this release are that the broken pipe issue has
been fixed, and the library is more OOP now and therefore no longer relies on
the Context to get stuff done. The methods feature flag has been removed.

Added

  • the voice feature no longer requires the cache feature to be enabled
    c:7b45f16
  • the framework feature no longer requires the cache feature to be enabled
    c:86cd00f
  • Guild, InviteGuild, and PartialGuild now have splash_url methods
    c:d58c544
  • Expose Message::webhook_id for messages sent via webhooks (@fwrs)
    c:a2cbeb6
  • Framework: add option to ignore webhooks or DMs (@fwrs) c:8e2c052
  • Added documentation for creating embed timestamps (@foxbot) c:66546d3
  • Allow time::Tm to be passed into the embed timestamp field, in addition to
    a direct string c:b001234
  • Add Client::on_message() example (@indiv0) c:bcb70e8
  • Support webp/gif avatars/icons in URL methods c:ab778f8
  • Update current user presence in cache on set c:5b275fc
  • Add CurrentUser/User::static_avatar_url() methods to generate webp URLs
    c:c36841d
  • Command (batch) alias support (@fwrs) c:f96b6cc
  • Command example field for help command (@fwrs) c:f96b6cc
  • Added "Meibi Pink" to the Colour struct (@hsiW) c:2cb607d
  • Register support for 4011 code (too many shards) (@SunDwarf) c:93f3c60
  • Added "Rohrkatze Blue" to the Colour struct (@bippum) c:345e140
  • Add User::default_avatar_url() c:e85e901
  • Add Message::content_safe() to avoid @everyone/@heres (@fwrs)
    c:e5a83dd
  • Add Member::distinct(), User::distinct() (@fwrs) c:e5a83dd
  • Document that messages can't be older than 14 days when bulk deleting
    (@fwrs) c:0a2f5ab
  • Add shard latency tracking (stolen borrowed from brayzure/Eris)
    c:096b0f5
  • Add guild chunking c:3ca7ad9

Fixes

  • User::avatar_url no longer mentions the user in the generated URL
    c:0708ccf
  • Framework: owners_only check now functions only if the author of a message
    is an owner (@fwrs) c:6355288
  • Framework: fix command cooldown timer (would always say to wait i64::MAX
    seconds) c:fafa363
  • Framework: the before closure is now properly run when a message is sent by
    the owner c:760a47a
  • CurrentApplicationInfo now properly decodes due to flags no longer being
    sent c:2a743ce
  • Fix Message::delete() permission check c:4229034
  • Framework: properly split messages on character boundary limits; aka thanks
    Unicode c:c01f238
  • Remove need to import Context/Message in command macros (@acdenisSK)
    c:abd22d2
  • Fix a ton of gateway stuff [c:94fc85b], c:f894cfd, c:f894cfd
  • Specify command! macro signature as returning std::result::Result
    c:e9aae9c
  • Fix dependency description in example 06 (@DeltaEvo) c:92309b2
  • Return a User from rest::get_user -- not a CurrentUser c:f57a187
  • Fix shards always booting at index 0 c:83b29d5
  • Wait 5 seconds between shard boots to avoid session invalidations c:fb4d411
  • Use CDN for default avatars c:69ec62a
  • Fix Resumed event payload decoding c:c2e8b69
  • Fix CurrentApplicationInfo decoding without rpc_origins c:38db32e
  • Reboot shard on broken pipe; fixes a lot of gateway problems c:76f9095
  • Make rest::execute_webhook be a POST c:c050c59

Changed

  • Framework: argument number is now displayed on parsing error (@fwrs)
    c:fb07751
  • Id display formatters use the direct u64 instead of mentioning;
    format!("{}", UserId(7)) will format into "7" instead of "<@7>"
    c:933ee89
  • Default the framework's use_quotes for quote parsing to false (was true)
    c:38a484d
  • The CreateEmbed builder now has direct image and thumbnail methods
    instead of one-method builders c:68c473d
  • Accept u64 shard counts to allow using more than 255 shards (instead of
    u8s) c:ada07fa
  • Remove user logout endpoint c:70bf22a
  • Don't abuse unicode for message content sanitization (@fwrs) c:2b237e7
  • Change Colour struct to be a tuplestruct c:a8acd61
  • Make a single POST on guild role create c:147cf01
  • Switch to a mostly-fully OOP approach c:651c618
  • Rename webhooks methods to get_webhooks
    (eg: GuildChannel::webhooks() --> GuildChannel::get_webhooks())
    [c:e8a9086](e8a9086...
Read more