github serenity-rs/serenity v0.2.0
Module rewrites, optimizations, bugfixes, & more

latest releases: v0.12.1, v0.12.0, v0.12.0-rc2...
6 years ago

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 for the long list of details.

Group calls and guild sync have also been removed. 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

Fixed

Changed

Misc.

Don't miss a new serenity release

NewReleases is sending notifications on new releases.