serenity-rs / serenity Goto Github PK
View Code? Open in Web Editor NEWA Rust library for the Discord API.
Home Page: https://discord.gg/serenity-rs
License: ISC License
A Rust library for the Discord API.
Home Page: https://discord.gg/serenity-rs
License: ISC License
with_data
will allow users to pass arbitrary data prior to starting the client, which should be able to be accessed across all contexts.
After typing a prefix it seems that any amount of whitespace is cut out while checking for the command to invoke. However, when parsing arguments the whitespace still remains and the command is cut up.
For example, given the following command:
command!(cmd(_ctx, msg, args) {
if args.len() == 1 {
println!("Got argument '{}'", args[0]);
} else {
println!("No arguments.");
}
});
I get the following behavior, assuming a prefix of + (With _ being spaces because I don't know how to make spaces not compact)
+cmd
=> "No arguments"
+_cmd
=> "No arguments"
+__cmd
=> "Got argument 'd'"
+___cmd
=> "Got argument 'md'"
etc.
Determine what is more difficult to accomplish than other parts of the library, or what is needlessly complex.
Starters:
There is a typo in the word "equivalent" in example 06 here. It might also occur in other locations.
It's gotten to be a mess in a lot of areas, especially Framework::dispatch
. Over time checks and other stuff have been added but not in a clean way. There's generally a lot of duplicate code as well.
Summary:
Specific items:
Mock: fake the data that we expect to be returned; tested by Travis
Integration: actual requests to the API, which have #[ignore]
attributes so they are run locally only; not tested by Travis
Modules should be split into entirely separate conditionally compiled components, e.g.:
::models
and ::internal
) (required)::client::gateway
)::client::rest
)::client
)::utils
)So, WS/REST should not be under Client's module.
It would be nice if there were a built-in way to directly play correctly pre-encoded Opus, to avoid having to spawn and involve ffmpeg unnecessarily.
This was also requested of discord-rs and someone filed a PR but it was never merged, in case its code may be useful.
Already supported for webhooks, so it should be a fairly easy addition.
The method will fire when all GuildCreate
s have been received.
Questions:
mention
functionTake out the trash and use something good.
Webhook support
Add conditional compilation for:
Message::edit
, Channel::delete
, etc.) (enabled by default)Finish up the work on the serde
branch, which mostly involves writing a few custom deserializers: https://github.com/zeyla/serenity/tree/serde
Mainly, users should be detached from the member, and should be stored separately in the state.
Add a reactions
method to CreateMessage
to configure reactions to place on the message after being sent.
I've been prototyping a bot in first Javascript, then Go, then Rust with Discord.rs and now Serenity and all prior libraries I used allowed me to cleanly, explicitly shutdown/disconnect the connection(s), which I did for example when the application received a SIGINT or whenever else I felt it to be useful.
As far as I know this library doesn't currently have the ability to do this, which means that when I terminate the application I still see the bot in my server for a while until it times out.
edit: Only in places where Arc
s aren't used.
Going here and compiling 0.9.5 succeeds, however this older version doesn't seem to work. Any way to update the dependencies so that it has this newer version?
Error:
Build failed, waiting for other jobs to finish...
error: failed to run custom build command for `openssl v0.7.14`
process didn't exit successfully: `C:\Users\ngupton\Desktop\serenity\target\debug\build\openssl-5464f8f6e728c35a\build-script-build` (exit code: 101)
--- stdout
TARGET = Some("x86_64-pc-windows-msvc")
OPT_LEVEL = Some("0")
PROFILE = Some("debug")
TARGET = Some("x86_64-pc-windows-msvc")
debug=true opt-level=0
HOST = Some("x86_64-pc-windows-msvc")
TARGET = Some("x86_64-pc-windows-msvc")
TARGET = Some("x86_64-pc-windows-msvc")
HOST = Some("x86_64-pc-windows-msvc")
CC_x86_64-pc-windows-msvc = None
CC_x86_64_pc_windows_msvc = None
HOST_CC = None
CC = None
TARGET = Some("x86_64-pc-windows-msvc")
HOST = Some("x86_64-pc-windows-msvc")
CFLAGS_x86_64-pc-windows-msvc = None
CFLAGS_x86_64_pc_windows_msvc = None
HOST_CFLAGS = None
CFLAGS = None
running: "C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\bin\\amd64\\cl.exe" "/nologo" "/MD" "/Z7" "/I" "C:\\OpenSSL-Win64\\include\\" "/FoC:\\Users\\ngupton\\Desktop\\serenity\\target\\debug\\build\\openssl-5464f8f6e728c35a\\out\\src\\c_helpers.o" "/c" "src/c_helpers.c"
c_helpers.c
C:\OpenSSL-Win64\include\openssl/lhash.h(198): warning C4090: 'function': different 'const' qualifiers
src/c_helpers.c(4): error C2037: left of 'references' specifies undefined struct/union 'ssl_st'
src/c_helpers.c(4): error C2065: 'CRYPTO_LOCK_SSL': undeclared identifier
src/c_helpers.c(8): error C2037: left of 'references' specifies undefined struct/union 'ssl_ctx_st'
src/c_helpers.c(8): error C2065: 'CRYPTO_LOCK_SSL_CTX': undeclared identifier
src/c_helpers.c(12): error C2037: left of 'references' specifies undefined struct/union 'x509_st'
src/c_helpers.c(12): error C2065: 'CRYPTO_LOCK_X509': undeclared identifier
ExitStatus(ExitStatus(2))
command did not execute successfully, got: exit code: 2
--- stderr
thread 'main' panicked at 'explicit panic', C:\Users\ngupton\.cargo\registry\src\github.com-1ecc6299db9ec823\gcc-0.3.41\src\lib.rs:1018
note: Run with `RUST_BACKTRACE=1` for a backtrace.
Examples are fundamental to good documentation, and so far most methods don't have proper examples.
Examples should at least compile and no_run
where necessary (for example, where the example would normally hit the REST API or instantiate a client). Examples that assert should run as part of our doctests.
Here's an example of a simple doctest:
/// ```rust
/// use serenity::utils;
///
/// let url = "discord.gg/0cDvIgU2voY8RSYL";
///
/// assert_eq!(utils::parse_invite(url), "0cDvIgU2voY8RSYL");
/// ```
It's not good to unwrap options or results in examples, as users can copy the code directly and end up with problems. An example of a more complex doctest surrounded in a try_main to entice usage of the ?
operator looks like:
/// ```rust,no_run
/// # use serenity::model::GuildId;
/// # use std::error::Error;
/// #
/// # fn try_main() -> Result<(), Box<Error>> {
/// # let mut guild = GuildId(0).get()?;
/// use serenity::utils;
///
/// // assuming a `guild` has already been bound
///
/// let base64_icon = utils::read_image("./guild_icon.png")?;
///
/// guild.edit(|g| g.icon(Some(&base64_icon)))?;
/// # Ok(())
/// # }
/// #
/// # fn main() {
/// # try_main().unwrap();
/// # }
/// ```
In this example, we surround the code visible to the user in try_main
, so that we can make use of ?
. Documentation example lines starting with #
hides that line from the generated documentation. See the Rust API Guidelines for more info.
If you'd like to claim one or more sections leave a comment with what ones or mention it in the serenity channel in Discord API.
The following is a list that still needs examples:
cache
(the cache module docs need an example as well)
Cache
(#103)
guild
group
private_channel
role
user
framework
(#101)
help_commands::{plain, with_embeds}
Configuration
(others optional)
blocked_guilds
blocked_users
disabled_commands
owners
prefix
prefixes
Framework
bucket
simple_bucket
on
group
on_dispatch_error
before
after
model
permissions
Permissions
can use a struct-level examplePRESET_GENERAL
PRESET_TEXT
Attachment
dimensions
Ban
can use a struct-level example of when you'd use itChannelId
broadcast_typing
can use a more thorough examplecreate_permission
create_reaction
delete
delete_message
delete_messages
delete_permission
delete_reaction
edit
can use a more thorough exampleedit_message
message
messages
pin
reaction_users
say
send_message
unpin
CurrentUser
(#104)
avatar_url
distinct
static_avatar_url
invite_url
Embed
(#105)
fake
Emoji
(#105)
delete
edit
find_guild_id
url
can use a doctest with an assertionGame
(method examples preferably show interacting with Shard methods) (#105)
playing
streaming
Group
(others optional)
add_recipient
broadcast_typing
shows an example when say, sending a file, to indicate work is being donecreate_reaction
delete_messages
delete_permission
delete_reaction
edit_message
icon_url
message
reaction_users
remove_recipient
say
send_files
send_message
unpin
Guild
(others optional)
bans
channels
create_channel
could use a better example in a framework commandcreate_emoji
create_integration
create_role
could use a second, complex exampledelete_emoji
delete_integration
delete_role
edit_emoji
edit_nickname
edit_emoji
is_large
example on when to use it, such as requesting member chunks on guild createkick
member
member_named
move_member
start_prune
showing a framework command exampleunban
utils
builder
(see CreateInvite
or ExecuteWebhook
for examples)
CreateEmbed
CreateEmbedAuthor
CreateEmbedField
CreateEmbedFooter
CreateMessage
EditChannel
EditGuild
EditMember
EditProfile
EditRole
GetMessages
Your SSL cert expired, so the logo in the top left corner doesn't work.
Store functions to call when specific reactions are made (and removed?) on messages.
Design on a userland and internals level still mostly undeveloped.
This would be accomplished via a Framework
trait that would simply look like this:
trait Framework {
fn dispatch(&mut self, Context, Message, &tokio_core::reactor::Handle);
}
Regarding the tokio Handle
there, its usage is simply meant to be: handle.spawn_fn(|| command(); Ok())
; or something similiar, as to keep things running smoothly in their's and serenity's code.
You can now send up to 10 attachments with a message.
If the voice feature is not enabled, it fails to compile with the message:
error[E0463]: can't find crate for `byteorder`
--> ~/.cargo/git/checkouts/serenity-3ee4e93465cd5f21/6a1c257/src/lib.rs:102:1
|
102 | extern crate byteorder;
| ^^^^^^^^^^^^^^^^^^^^^^^ can't find crate
Workaround for now: enable voice feature.
Exposing the ability to create a voice connection independent of a discord instance would allow users to connect to discord in another thread/instance/server/lib and spawn voice connections from a completely different program by simply transferring basic information back and forth.
Right now it's mostly a command parser (https://raw.githubusercontent.com/zeyla/serenity.rs/feb2ee1eddc92cf02fc9e64534030ae0d374418b/examples/06_command_framework.rs), but a full framework is the end goal.
Basically an issue for tracking ideas.
Current function signature: fn weather(context: Context, message: Message, arguments: Vec<String>)
Status: Done ✓
Rather than the current signature, allow fn weather(context: Context, message: Message, location: String, action: Option<String>)
Status: Done in a good enough fashion ✓ #36
Possibly something like
#[derive(Deserialize)]
struct WeatherArguments {
pub action: Option<String>,
pub location: String,
}
fn weather(context: Context, message: Message, arguments: WeatherArguments)
Status: Done ✓ #13
Closures that can run before or after command execution (not specific to a command). Idea courtesy @fwrs
Status: Done ✓ #40
Status: Done ✓ #38
edit: Also switch to hyper ^0.11
These could definitely use some struct-level docs:
The rest could use some work but aren't as important
Channel types for GuildChannels, Groups, and PrivateChannels are incorrectly reported.
Guild Channels will always be Groups for example. This is because the build script is incorrectly making channel type numbers correspond to a different ChannelType
.
It just feels right to return rust data structures instead of raw data.
not sure if we really need latter 3.
Make sure Discord sends you the A OK before you try to read a book with words you don't know 😄
Decode("Unexpected absent key", "id")
I'm creating a bot that needs to make sure that the calling user has specific Permissions
. How would one do this in a command? I haven't found a related field on the User
struct and can't find documentation on how to do so.
It seems like you could call something like .ban_members()
with the Permissions
struct after getting permissions, however the User does not seem to contain permission data.
Thanks.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.