spacemaniac / discord-rs Goto Github PK
View Code? Open in Web Editor NEWRust library for the Discord chat client API
License: MIT License
Rust library for the Discord chat client API
License: MIT License
Right now the only way to poll events from a Connection is to use recv_event, which is a blocking operation. As a result, it's impossible right now to implement a bot that listens on external events and produces Discord commands based on those events.
To fix this, there should be either a non-blocking alternative to recv_event, or a Future/Stream interface for streaming the events.
Guild sharding, described here, has been deployed: discord/discord-api-docs#17
The library should expose this functionality.
Mark Event::__Nonexhaustive
as unstable to prevent matching against it in stable code. This is also done in std::io::Error
.
It's a little awkward right now and too much of the internal code needs to be copy-pasted if any customization in the queuing is desired. Consider something modelled after discord.py.
{"tutorial":null}
{"emojis":[],"features":[],"splash":null}
{"deaf":false,"mute":false}
Decode("Expected string", null)
Looks like this is coming from https://github.com/SpaceManiac/discord-rs/blob/master/src/connection.rs#L54
a recent discord api update added support for specifying custom embeds in the input of the create message
endpoint: https://discordapp.com/developers/docs/resources/channel#create-message
it would be nice to have this, though i don't know the best way to implement it atm
so when I try to call
client.logout().expect("logout failed");
I get this for some reason
thread '<main>' panicked at 'logout failed: Status(Unauthorized, Some({"code":0,"message":"401: Unauthorized"}))', src/libcore/result.rs:785
I am playing with one of the example projects but I changed the login to use Discord::new_cache
so I could pass in my login details.
could this have broken it?
When I tried to get this lib, cargo crashed on fetching dependencies with:
Compiling libsodium-sys v0.0.9
Build failed, waiting for other jobs to finish...
error: failed to run custom build command for `libsodium-sys v0.0.9`
Process didn't exit successfully: `/Users/marqin/repo/slapbot/target/debug/build/libsodium-sys-4773428f8ea4b5cb/build-script-build` (exit code: 101)
--- stderr
thread '<main>' panicked at 'called `Result::unwrap()` on an `Err` value: "`\"pkg-config\" \"--libs\" \"--cflags\" \"libsodium\"` did not exit successfully: exit code: 1\n--- stdout\nPackage libsodium was not found in the pkg-config search path.\nPerhaps you should add the directory containing `libsodium.pc\'\nto the PKG_CONFIG_PATH environment variable\nNo package \'libsodium\' found\n"', src/libcore/result.rs:746
note: Run with `RUST_BACKTRACE=1` for a backtrace.
It looks like libsodium
( system one, not just rust lib ) is needed as dependency of this package, but it's not documented.
When I try to compile the example from here as it is I have a lot of errors:
main.rs:30:17: 30:51 error: no associated item named `Closed` found for type `discord::error::Error` in the current scope
main.rs:30 Err(discord::Error::Closed(code, body)) => {
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
main.rs:30:46: 30:50 error: the trait `core::marker::Sized` is not implemented for the type `[u8]` [E0277]
main.rs:30 Err(discord::Error::Closed(code, body)) => {
^~~~
main.rs:30:46: 30:50 help: run `rustc --explain E0277` to see a detailed explanation
main.rs:30:46: 30:50 note: `[u8]` does not have a constant size known at compile-time
main.rs:30:46: 30:50 note: all local variables must have a statically known size
error: aborting due to 2 previous errors
Is there something wrong with the example code?
P.S. I am learning rust yet.
Apparently it can't decode the LiveServer at all and says that all of the keys (at least name and owner_id, but I presume most others, if not all, as well) are absent.
Update: Apparently a Live Server can also have this format:
{"id":"169421923531358208","unavailable":true}
Looks like this is a duplicate of #8
Hi, discord-rs wizard(s)!
I'm using the connect_sharded
now because the bot have reached the 2500 limit.
With two shards it works fine!
But if I try to start three or four shards I get the "Expected Ready during handshake" error.
The code looks like this
let total_shards = 3;
for shard_id in 0 .. total_shards {
std::thread::Builder::new().name (fomat! ("shard " (shard_id) ", dice_thread"))
.spawn (move || dice::dice_thread (shard_id, total_shards)) .expect ("!spawn");
}
pub fn dice_thread (shard_id: u8, total_shards: u8) {
...
let (mut dc, ready_ev) = bot.connect_sharded (shard_id, total_shards) .expect ("!connect");
And the log is:
DEBUG:discord::connection: Unexpected event: InvalidateSession
thread 'shard 0, dice_thread' panicked at '!connect: Protocol("Expected Ready during handshake")', /buildslave/rust-bui
note: Run with `RUST_BACKTRACE=1` for a backtrace.
I wonder what the InvalidateSession
event tells us?
At the very least it might be better to handle it in order to panic with a better error message or something.
Any possibility you could implement the Serializable interface in all the models:: things? I want to encode a guild to JSON, but right now I have to write every single key with every single value... It's a pain.
I have 2 users on the server.
When I invite 3rd and he comes, the following code is executed:
Event::ServerMemberAdd(server_id, member) => {
if let Some(s) = self.state.servers().iter().find(|srv| srv.id == server_id) {
info!("New user joined the server({}): {:?}", s.name, member.user);
self.messenger().send_message(s.channels[0].id,
&format!("Everyone say hello to {}, our new member! We are {} already!",
member.user.id.mention(),
markdown::bold(&s.member_count.to_string())),
false);
info!("Users are: {:?}", s.members);
}
However, when the new user comes it prints We are 4 already
while it should be 3 users only.
So I decided to look s.members
(what is LiveServer::members
):
[2017-03-28][17:09:41.065212848][INFO] in (discord_pickupbot::pickupbot::bot) at src/pickupbot/bot.rs:796 Users are: [Member { user: User { id: UserId(183254040266670080), name: "PAPA_LOX", discriminator: 7986, avatar: Some("633012bc9cdd1dda5e5ae83a74e3ef90"), bot: false }, roles: [RoleId(246283517795762176)], nick: None, joined_at: "2016-09-24T11:18:36.863000+00:00", mute: false, deaf: false }, Member { user: User { id: UserId(184244497650024448), name: "pickupbottester", discriminator: 8476, avatar: Some("63d00ee0e74973ca8fefad5a5494b35b"), bot: true }, roles: [RoleId(229551034421346304)], nick: None, joined_at: "2016-09-24T16:58:42.060000+00:00", mute: false, deaf: false }, Member { user: User { id: UserId(138948472849170432), name: "Danmer", discriminator: 4805, avatar: Some("d84f4c80cdbf3fdbecbb3a9b3c0aeae3"), bot: false }, roles: [], nick: None, joined_at: "2017-03-28T14:09:40.791304+00:00", mute: false, deaf: false }, Member { user: User { id: UserId(138948472849170432), name: "Danmer", discriminator: 4805, avatar: Some("d84f4c80cdbf3fdbecbb3a9b3c0aeae3"), bot: false }, roles: [], nick: None, joined_at: "2017-03-28T14:09:40.791304+00:00", mute: false, deaf: false }]
The new user's name is Danmer
. Why is he listed twice?
P.S. I have also been able to reproduce the error on another server where 400+ members are: each new user increments members_count
by 2 instead of 1.
Hi, I tried the dj.rs example and I can't stream on a voice channel.
The bot join the correct voice channel, so the stream is correct. But voice.play(stream) doesn't stream anything and I don't see any error.
I tried to copy the code in my bot, but I've got ERROR:discord::voice: Error connecting to voice: Protocol("First voice event was not Handshake")
The voice module should support:
plain
mode)Voice receive improvements to be made (based on suggestions by #q):
stereo: bool
explicitly to AudioReceiver::voice_packet
decoder_map
if they haven't been used for some timespeaking_update
for anything but the ssrc
mappingHey!
So I'm using fn send_embed
to send some information to the users.
Later I want to update that information.
There is fn edit_message
, but it only changes the text before the embed.
Embed stays the same, it isn't even removed.
Please please please add fn edit_embed
or by some other means allow the bots to update their embeds!
P.S. Do you have a Patreon page?
When using Discord::get_message
, no matter what channel and message are passed to the function, the same error is always given:
Json(
ErrorImpl {
code: Message(
"missing field `nonce`"
),
line: 1,
column: 680
}
)
Seems like the best way to fix this would be to add #[serde(default)]
to the nonce
field.
Edit: Can confirm that adding #[serde(default)]
fixes this.
Don't get me wrong, taking mut self
definitely the ideal approach. However, it sadly comes with a price. It assumes you own the instance, and therefor cannot be used easily in functions. Especially since the lack of Clone (which is a good thing. You cannot clone a connection - that'd just be misleading and weird).
I am stupid, I didn't know about mem::replace
.
So, do consider changing it to take a &mut self
. Maybe even implement the drop trait π
Memory footprint and ergonomics can be improved by using u64
s for IDs instead of Strings
. Additionally, IDs have meaning as a number, where 1420070400 + (id >> 22) / 1000
is the creation timestamp of the referenced item. In this change, a generic Id<T>
(for T in User, Server, Channel. Message, Role) should probably be introduced.
Pending Discord release of gateway v6, which will affect how this will work.
Discord does not provide full member lists on connect for servers where this list is large. In some situations it even limits the provided member lists to users you have a private channel with. State
currently offers download_online_members
and download_all_members
as stopgaps in case this information is necessary, but a more robust solution is needed.
I've tried to implement this myself but I can't figure out how to get ffmpeg to pause. Sending ffmpeg STOP and CONT signals pauses and resumes playback but it doesn't pick up where it left off.
Discord is pushing for libs to support rate limits natively rather than leaving that responsibility to users, so there needs to be some handling for that: discord/discord-api-docs#108
Hopefully there'll eventually be some way to get this info programatically, but here's the current state of rate limits:
REST:
bot:msg:dm | 5/5s | account-wide
bot:msg:server | 5/5s | guild-wide
bot:msg:global | 50/10s | account-wide except DMs
dmsg | 5/1s | guild-wide
bdmsg | 1/1s | guild-wide
guild_member | 10/10s | guild-wide
guild_member_nick | 1/1s | guild-wide
|Username| | 2/3600s | account-wide
WS Send:
|Presence Update| | 5/60s
|Global| | 120/60s
Corresponds directly to the "Notifcation Settings" dialog, is shaped like:
{
"channel_overrides":[
{
"channel_id":"...",
"message_notifications":3,
"muted":true
},
{
"channel_id":"...",
"message_notifications":3,
"muted":true
}
],
"guild_id":"...",
"message_notifications":1,
"mobile_push":true,
"muted":false,
"suppress_everyone":false
}
Despite having a keepalive, I'm encountering issues where the Discord WebSocket gets disconnected. The issue gets logged as a warning, but no other action is taken by the library to fix the problem.
When the connection goes down, I start seeing this message in the log at regular intervals:
WARN:discord::connection: Error sending gateway keeaplive: WebSocket(IoError(Error { repr: Os { code: 32, message: "Broken pipe" } }))
When the connection goes down and I try to send my own message to the Discord server, this message is logged:
WARN:discord::connection: Error sending gateway message: WebSocket(IoError(Error { repr: Os { code: 32, message: "Broken pipe" } }))
Since this error isn't propagated up, I can't even take action on it myself (even if that action is just letting the process die so I can restart it).
This is a tracking issue for adding Travis CI support to the project.
I'll probably be implementing this myself.
I've spent the last few days trying to figure out what on earth I was doing wrong with this library, turns out that when I was using include_str! to import my bot key from a file that the file had a trailing new line, which causes the library to randomly return HTTP 400 errors. So that no one falls into the same trap I did I recommend one of two changes:
1: Run a trim() on the input inside from_bot_token
2: Return an error in from_bot_token stating that a key cannot contain whitespace.
The current HEAD contains some new features that would be rather nice to have (like Discord::get_server_channels()
, for example).
Would a release with them in be plausible in the near future?
In a few places - such as get_messages
, the use of u64 is pointless. Even a u16 is enough.
Discord devs recommend use of the Erlang external term format for websocket (and REST?) communications. There's already a crate for ETF manipulation. The main changes would be adding &format=etf
when connecting to the gateway and using ETF when decoding events and encoding actions.
The Rust crate OpenSSL 0.7.4 (which is what discord-rs transitively resolves to) fails to build with openssl 1.1.0, which is what is on Arch Linux right now. This makes discord-rs completely unusable.
This issue can be resolved by upgrading all dependencies such that a higher version of the Rust openssl crate is used (the current version is 0.9.12). However, in local testing, cloning discord-rs and doing a simple upgrade of everything to their most recent versions, causes many incompatibilities - mostly around websocket, I believe related to #99.
Here's the build log:
Compiling openssl v0.7.14
Compiling openssl-sys-extras v0.7.14
error: failed to run custom build command for `openssl v0.7.14`
process didn't exit successfully: `/home/khyperia/me/weechat-discord/target/debug/build/openssl-f2d87cfdc2e2aa2f/build-script-build` (exit code: 101)
--- stdout
TARGET = Some("x86_64-unknown-linux-gnu")
OPT_LEVEL = Some("0")
TARGET = Some("x86_64-unknown-linux-gnu")
HOST = Some("x86_64-unknown-linux-gnu")
TARGET = Some("x86_64-unknown-linux-gnu")
TARGET = Some("x86_64-unknown-linux-gnu")
HOST = Some("x86_64-unknown-linux-gnu")
CC_x86_64-unknown-linux-gnu = None
CC_x86_64_unknown_linux_gnu = None
HOST_CC = None
CC = None
HOST = Some("x86_64-unknown-linux-gnu")
TARGET = Some("x86_64-unknown-linux-gnu")
HOST = Some("x86_64-unknown-linux-gnu")
CFLAGS_x86_64-unknown-linux-gnu = None
CFLAGS_x86_64_unknown_linux_gnu = None
HOST_CFLAGS = None
CFLAGS = None
PROFILE = Some("debug")
running: "cc" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-m64" "-o" "/home/khyperia/me/weechat-discord/target/debug/build/openssl-1d3ea894fa03cc5a/out/src/c_helpers.o" "-c" "src/c_helpers.c"
cargo:warning=src/c_helpers.c: In function βrust_SSL_cloneβ:
cargo:warning=src/c_helpers.c:4:5: warning: implicit declaration of function βCRYPTO_addβ [-Wimplicit-function-declaration]
cargo:warning= CRYPTO_add(&ssl->references, 1, CRYPTO_LOCK_SSL);
cargo:warning= ^~~~~~~~~~
cargo:warning=src/c_helpers.c:4:20: error: dereferencing pointer to incomplete type βSSL {aka struct ssl_st}β
cargo:warning= CRYPTO_add(&ssl->references, 1, CRYPTO_LOCK_SSL);
cargo:warning= ^~
cargo:warning=src/c_helpers.c:4:37: error: βCRYPTO_LOCK_SSLβ undeclared (first use in this function)
cargo:warning= CRYPTO_add(&ssl->references, 1, CRYPTO_LOCK_SSL);
cargo:warning= ^~~~~~~~~~~~~~~
cargo:warning=src/c_helpers.c:4:37: note: each undeclared identifier is reported only once for each function it appears in
cargo:warning=src/c_helpers.c: In function βrust_SSL_CTX_cloneβ:
cargo:warning=src/c_helpers.c:8:20: error: dereferencing pointer to incomplete type βSSL_CTX {aka struct ssl_ctx_st}β
cargo:warning= CRYPTO_add(&ctx->references,1,CRYPTO_LOCK_SSL_CTX);
cargo:warning= ^~
cargo:warning=src/c_helpers.c:8:35: error: βCRYPTO_LOCK_SSL_CTXβ undeclared (first use in this function)
cargo:warning= CRYPTO_add(&ctx->references,1,CRYPTO_LOCK_SSL_CTX);
cargo:warning= ^~~~~~~~~~~~~~~~~~~
cargo:warning=src/c_helpers.c: In function βrust_X509_cloneβ:
cargo:warning=src/c_helpers.c:12:21: error: dereferencing pointer to incomplete type βX509 {aka struct x509_st}β
cargo:warning= CRYPTO_add(&x509->references,1,CRYPTO_LOCK_X509);
cargo:warning= ^~
cargo:warning=src/c_helpers.c:12:36: error: βCRYPTO_LOCK_X509β undeclared (first use in this function)
cargo:warning= CRYPTO_add(&x509->references,1,CRYPTO_LOCK_X509);
cargo:warning= ^~~~~~~~~~~~~~~~
exit code: 1
command did not execute successfully, got: exit code: 1
--- stderr
thread 'main' panicked at 'explicit panic', /home/khyperia/data/cargo/registry/src/github.com-1ecc6299db9ec823/gcc-0.3.49/src/lib.rs:1210
note: Run with `RUST_BACKTRACE=1` for a backtrace.
Build failed, waiting for other jobs to finish...
error: build failed
Incomplete list pending Discord's release of these features.
{"type":"text"}
{"is_private":false}
(only sometimes){"type":0}
{"type":0}
Error propagation is mostly fine right now, but some of the errors generated by discord-rs
itself are non-specific/poorly worded/don't include enough information.
In particular, specific error cases should be included for common Discord API failure modes, such as rate limiting.
Right now, the docs for model::Event
are very hard to decipher: https://docs.rs/discord/0.7.0/discord/model/enum.Event.html
It'd be a bit easier if each part of the enum were factored into its own struct, at least for the large ones, so that the docs were a bit more readable.
See this question and comment.
Apparently it's near impossible to use recv_event concurrently, with for example user input. Any chance to make it take an immutable reference, or is this a problem with an upstream repository?
The 0000
through 9999
range used for discriminators should fit comfortably in a u16. No need for a whole String
.
As I was implementing a struct to buffer the Youtube stream I realized that the AudioSource
s created by the predefined functions don't return None
when finished, only Some(0)
.
https://github.com/SpaceManiac/discord-rs/blob/master/src/voice.rs#L265
I think it should rather return None
, since the docs say:
If
Some(0)
is returned, no audio will be sent this frame, but the audio source will remain active. IfNone
is returned, the audio source is considered to have ended, andread_frame
will not be called again.
Right now all of the timestamps are listed as strings, but it'd be nice if they were all parsed using the chrono
crate so that they could be directly read and compared.
Login tokens are currently not cached. The library should provide some mechanism for this.
Hey,
Im running the dj example as a music bot, however for some reason the ffmpeg children are never wait
'ed for. Heres a ps aux | grep ffmpeg
As you can see the bot has been running for several days.
and heres a pstree -ap `pidof dj`
:
dj,6136
ββ(ffmpeg,6143)
ββ(ffmpeg,10478)
ββ(ffmpeg,14032)
ββ(ffmpeg,14217)
ββ(ffmpeg,14356)
ββ(ffmpeg,14526)
ββ(ffmpeg,14538)
ββ(ffmpeg,14607)
ββ(ffmpeg,14649)
ββ(ffmpeg,14655)
ββ(ffmpeg,17050)
ββ(ffmpeg,17058)
ββ(ffmpeg,17662)
ββ(ffmpeg,17675)
ββ(ffmpeg,17806)
ββ(ffmpeg,19675)
ββ(ffmpeg,19689)
ββ(ffmpeg,20665)
ββ(ffmpeg,22583)
ββ(ffmpeg,22850)
ββ(ffmpeg,23164)
ββ(ffmpeg,23170)
ββ(ffmpeg,23513)
ββ(ffmpeg,23756)
ββ(ffmpeg,23799)
ββ(ffmpeg,23810)
ββ(ffmpeg,24047)
ββ(ffmpeg,26051)
ββ(ffmpeg,26301)
ββffmpeg,26392 -i...
ββ{Discord Keepali},26288
ββ{discord voice (},10480
ββ{discord voice (},14034
ββ{discord voice (},14358
ββ{discord voice (},14528
ββ{discord voice (},14609
ββ{discord voice (},17052
ββ{discord voice (},17060
ββ{discord voice (},17664
ββ{discord voice (},19677
ββ{discord voice (},20667
ββ{discord voice (},22585
ββ{discord voice (},22852
ββ{discord voice (},23515
ββ{discord voice (},26053
ββ{discord voice (},26294
ββ{discord voice (},26303
ββ{discord voice (},26394
Honestly im not sure if this is a discord-rs or an actual bug within the rust stdlib, however the amount of
active threads makes me assume discord-rs never joins those and thus the ffmpeg process memory is not destructed and thus the ffmpeg processes not joined?
Im running rust stable (installed via rustup) on Debian 8 jessie:
$ rustc --version
rustc 1.15.1 (021bd294c 2017-02-08)
$ uname -a
Linux v22015123214830522 3.16.0-4-amd64 #1 SMP Debian 3.16.36-1+deb8u2 (2016-10-19) x86_64 GNU/Linux
$ lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description: Debian GNU/Linux 8.7 (jessie)
Release: 8.7
Codename: jessie
Tell me if you need any more information etc.
PublicChannel
has new field {"last_pin_timestamp":"2016-06-26T09:15:51.148000+00:00"}
.
New event CHANNEL_PINS_UPDATE
: {"channel_id": "194586744417550336", "last_pin_timestamp": "2016-07-11T22:30:01.152752+00:00"}
.
Details: discord/discord-api-docs#151
I'll do this one Soon:tm:
I seem to be getting this when doing RUST_BACKTRACE=1 cargo run --verbose
. I've created a new project, everything seems to be OK in regards to the structure of the project and the configuration. If I don't include the Discord crate it'll compile fine. I'm using the code from the example (https://github.com/SpaceManiac/discord-rs/blob/master/examples/basic_chatbot.rs). It's compiling fine, its just when I run it it throws the panic.
This is my stack-trace:
`
Running target/debug/discord_bot
thread 'main' panicked at 'Expected token: NotPresent', /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libcore/result.rs:837
stack backtrace:
1: 0x556ed6643e6a - std::sys::imp::backtrace::tracing::imp::write::h3188f035833a2635
at /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:42
2: 0x556ed664707f - std::panicking::default_hook::{{closure}}::h6385b6959a2dd25b
at /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libstd/panicking.rs:349
3: 0x556ed6646c7e - std::panicking::default_hook::he4f3b61755d7fa95
at /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libstd/panicking.rs:365
4: 0x556ed6647527 - std::panicking::rust_panic_with_hook::hf00b8130f73095ec
at /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libstd/panicking.rs:553
5: 0x556ed6647364 - std::panicking::begin_panic::h6227f62cb2cdaeb4
at /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libstd/panicking.rs:515
6: 0x556ed66472d9 - std::panicking::begin_panic_fmt::h173eadd80ae64bec
at /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libstd/panicking.rs:499
7: 0x556ed6647267 - rust_begin_unwind
at /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libstd/panicking.rs:475
8: 0x556ed666e27d - core::panicking::panic_fmt::h3b2d1e30090844ff
at /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libcore/panicking.rs:69
9: 0x556ed6295604 - core::result::unwrap_failed::h7badae956541c245
at /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libcore/macros.rs:29
10: 0x556ed628d61d - <core::result::Result<T, E>>::expect::hf25aa47c10d0d94e
at /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libcore/result.rs:761
11: 0x556ed62a6dee - discord_bot::main::h03a45e76d75fb610
at /home/god/Documents/Rust/discord_bot/src/main.rs:10
12: 0x556ed664e51a - __rust_maybe_catch_panic
at /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libpanic_unwind/lib.rs:98
13: 0x556ed6647c66 - std::rt::lang_start::h65647f6e36cffdae
at /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libstd/panicking.rs:434
at /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libstd/panic.rs:351
at /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libstd/rt.rs:57
14: 0x556ed62a79c2 - main
15: 0x7f5d3f5f482f - __libc_start_main
16: 0x556ed6281468 - _start
17: 0x0 -
`
I'm having a feeling this is something to do with package versions clashing?
Currently it takes "&[&RoleId]" as a list of roles but it is impossible to create such structure (slice of references) or needs 'hacky-like' code to be written.
Currently it looks as:
/// Edit the list of roles assigned to a member of a server.
pub fn edit_member_roles(&self, server: &ServerId, user: &UserId, roles: &[&RoleId]) -> Result<()> {
let map = ObjectBuilder::new()
.insert_array("roles", |ab| roles.iter().fold(ab, |ab, id| ab.push(id.0)))
.unwrap();
let body = try!(serde_json::to_string(&map));
try!(self.request(|| self.client.patch(
&format!("{}/guilds/{}/members/{}", API_BASE, server.0, user.0)).body(&body)));
Ok(())
}
Consider to change roles: &[&RoleId]
to something usable from the outside.
Servers can, under some conditions (which?), be marked "unavailable": true
in the JSON data in the Ready, ServerCreate, and ServerDelete events. This should be represented in the model.
Either the library doesn't have get_user
implemented, or I made a colossal oversight when searching for it. Is it missing on purpose?
See the method reference.
In many cases we need to store State
object inside the structure to access it from different places. But we unable to do that because it needs to be constructed with ReadyEvent
but we may not have it in our struct's constructor yet.
Currently to store it we have to create a fake ReadyEvent
:
// TODO remove when discord::State will have default ctor
fn get_fake_ready_event() -> ReadyEvent {
ReadyEvent {
version: 0,
user: CurrentUser {
id: UserId(0),
username: String::default(),
discriminator: String::default(),
avatar: None,
email: None,
verified: false,
bot: false,
mfa_enabled: false
},
session_id: String::default(),
heartbeat_interval: 0,
user_settings: None,
read_state: None,
private_channels: Vec::default(),
presences: Vec::default(),
relationships: Vec::default(),
servers: Vec::default(),
user_server_settings: None,
tutorial: None,
trace: Vec::default(),
}
}
This is not good.
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.