Coder Social home page Coder Social logo

discord-rs's Introduction

discord-rs

This project is only maintained occasionally. If you're having problems, open a pull request or check the network graph for up-to-date forks.

discord-rs is a Rust client library for the Discord chat client's API.

The Discord API can be divided into three main components: the RESTful API to which calls can be made to take actions, a websocket-based permanent connection over which state updates are received, and the voice calling system.

Log in to Discord with Discord::new, new_cache, or from_bot_token as appropriate. The resulting value can be used to make REST API calls to post messages and manipulate Discord state. Calling connect() will open a websocket connection, through which events can be received. These two channels are enough to write a simple chatbot which can read and respond to messages.

For more in-depth tracking of Discord state, a State can be seeded with the ReadyEvent obtained when opening a Connection and kept updated with the events received over it.

To join voice servers, call Connection::voice to get a VoiceConnection and use connect to join a channel, then play and stop to control playback. Manipulating deaf/mute state and receiving audio are also possible.

For further details, browse the source or read the documentation. For examples, browse the examples directory.

Installation

On Windows, discord-rs currently requires a GNU-like environment. For details, read the installation guide.

On all platforms, discord-rs has several system dependencies, which should be installed as appropriate:

  • pkg-config
  • openssl
  • libsodium (if using voice)
  • opus (if using voice)
  • ffmpeg (if using ffmpeg features)
  • youtube-dl (if using youtube-dl features)

discord-rs's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

discord-rs's Issues

Change IDs to be numeric

Memory footprint and ergonomics can be improved by using u64s 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.

Predefined AudioSource implementations never return None

As I was implementing a struct to buffer the Youtube stream I realized that the AudioSources 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. If None is returned, the audio source is considered to have ended, and read_frame will not be called again.

Missing get_user

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.

Handle unavailable servers

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.

Whitespace after bot key causes random failure

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.

Release?

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?

Unhandled keys in the model

  • Event::Ready has {"tutorial":null}
  • LiveServer has {"emojis":[],"features":[],"splash":null}
  • Event::ServerMemberAdd has {"deaf":false,"mute":false}

Logout unauthorized

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?

No way to implement external events due to blocking recv_event

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.

undocumented system dependency

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.

Event: USER_GUILD_SETTINGS_UPDATE

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
}

Improve error handling

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.

Errors when connecting to Discord

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

Fails to build on Arch Linux due to system openssl 1.1.0

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

Parse timestamps using chrono crate

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.

Handle `InvalidateSession` in `connect_sharded`?

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.

Add pause function to dj

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.

Dj not working?

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")

Use ETF rather than JSON

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.

Better rate limiting

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

Unecessary use of `u64`

In a few places - such as get_messages, the use of u64 is pointless. Even a u16 is enough.

Easier JSON encoding?

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.

More complete solution to guild streaming

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.

Make `Struct discord::State` be default-constructed

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.

Consider making connection's shutdown() take a reference

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 👍

Add remaining API endpoints

  • post message with attachment
  • get bans
  • add ban
  • remove ban
  • create invite
  • get member list
  • get member
  • edit member
  • kick member
  • create role
  • edit role
  • reorder roles
  • delete roles
  • create role permission
  • delete permission
  • edit profile
  • get voice regions
  • move member voice
  • get servers
  • edit server

Add Travis CI Support

This is a tracking issue for adding Travis CI support to the project.

I'll probably be implementing this myself.

Improve voice controller structure

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.

Simple example can't be compiled

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.

New pinning-related fields

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"}.

User token can receive messages but not send

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?

No Attempt is Made to Reconnect Broken WebSocket

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).

Change Discord::edit_member_roles method to accept something usable

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.

edit_embed

Hey!

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?

Discord::get_message always fails due to missing `nonce` field

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.

Incorrect LiveServer::members_count and LiveServer::members vector

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.

Enhanced voice support: receive, stereo, encryption

The voice module should support:

  • the opus crate instead of internal bindings
  • receiving voice
  • stereo transmission, in addition to mono
  • encrypted voice (non-plain mode)
  • multii-server voice

Voice receive improvements to be made (based on suggestions by #q):

  • Supply stereo: bool explicitly to AudioReceiver::voice_packet
  • Handle receiving opus packets larger than 20ms (960 samples)
  • Destroy entries in the decoder_map if they haven't been used for some time
  • Document the unreliability of speaking_update for anything but the ssrc mapping
  • Deal with UDP connection timeout if nothing is received for a while

Login token caching system

Login tokens are currently not cached. The library should provide some mechanism for this.

  • Some file (user-provided?) should be used to store a mapping from emails to login tokens.
  • Before a login attempt, a token is attempted to be found for the provided email.
  • A request to the login endpoint is made with both email/password and this token provided in the normal way.
  • Either that same token if it is valid at all or a new token for the logged-in user will be returned.
  • The returned token will be used for further requests and stored back to the mapping file.

ffmpeg children are not joined and remain as zombies

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.