aboutsummaryrefslogtreecommitdiff
path: root/examples
Commit message (Collapse)AuthorAgeFilesLines
* Release v0.1.0v0.1.0Austin Hellyer2016-11-307-7/+7
|
* Re-order example Cargo.toml'sAustin Hellyer2016-11-307-14/+14
|
* Add documentation for examplesAustin Hellyer2016-11-2911-24/+177
| | | | | | | | The examples include a README located in `examples/README.md`, which contains instructions for running these examples. They act as a simple form of tutorial to the library, without getting into too many details.
* Clean up the codebaseAustin Hellyer2016-11-2914-37/+77
|
* Add initial audio supportAustin Hellyer2016-11-291-29/+127
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Audio can be played with support by passing one of the following into the `Handler::play` method: `serenity::ext::voice::{ffmpeg, pcm, ytdl}` functions, where - `ffmpeg` accepts a path (such as a `File`); - `pcm` accepts a raw reader source; - `ytdl` accepts a URI, which works with everything youtube-dl supports: <https://github.com/rg3/youtube-dl/blob/master/docs/supportedsites.md> The source can be stopped via [`Handler::stop`]. Receive is supported through [`Handler::listen`], which accepts a `serenity::ext::voice::AudioReceiver` implementation. An example is provided in the form of the file located at `./examples/07_voice.rs`, which can be run by cloning the repo and performing the command `cargo run --example 07_voice`. Prior to running the command, set a bot token as the value of the env variable `DISCORD_TOKEN`. The example supports: - `deafen`: deafens the bot; - `join`: joins a voice channel by ID. The example is a primitive implementation, and requires the ID of the channel to be passed to the bot as a command of `~join 131937933270712320`; - `leave`: leaves the current voice channel, if in one; - `mute`: mutes the bot and will continue to play source audio; - `play`: plays source audio from a URI, through a command like `~play https://www.youtube.com/watch?v=5KJjBRm0ElA`; - `ping`: responds with "Pong!" to ensure the bot is working properly; - `undeafen`: undeafens the bot, if that's actually a word; - `unmute`: unmutes the bot. Documentation for audio can be found at: <https://serenity.zey.moe/serenity/ext/voice/index.html>
* Optimize for cached, non-method compilesAustin Hellyer2016-11-282-0/+19
|
* Update example 07 with framework changesAustin Hellyer2016-11-281-5/+5
|
* Add before/after framework command hooksIllia K2016-11-281-8/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | These hooks will each be run prior to or after the command, and will finish execution before executing the command. These can be configured in a Framework via: ```rs client.with_framework(|f| f .before(|_context, message, _command_name| { println!("Got command '{}'", command_name); }) .after(|_context, _message, command_name| { println!("Finished command '{}'", command_name); })); ``` This does introduce a backwards compatibility break, by requiring commands' Context/Message to be borrowed Upgrade path: If not using the `command!` macro, modify command signatures from: ```rs fn some_command(context: Context, message: Message, args: Vec<String>) ``` to ```rs fn some_command(context: &Context, message: &Message, args: Vec<String>) ```
* Voice example no longer requires 'extras'Austin Hellyer2016-11-261-6/+6
|
* Add no-named-argument command macro matchAustin Hellyer2016-11-261-2/+2
|
* Add Cache::get_guild_channelAustin Hellyer2016-11-261-40/+20
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is an 'extras'-enabled function to get a guild's channel. This will allow a simple Option pattern match over the result, rather than working with an Option<Channel<T>>. Example of old code vs. new code, in the context of an event handler: Old: ```rs use serenity::cache::CACHE; use serenity::model::Channel; let cache = CACHE.read().unwrap(); let channel = match cache.get_channel(channel_id) { Some(Channel::Guild(channel)) => channel, Some(Channel::Private(_)) => { context.say("Groups and DMs not supported") .map_err(|x| println!("Err sending message: {:?}", why); return; }, None => { context.say("Could not find channel") .map_err(|x| println!("Err sending message: {:?}", x); return; }, } ``` New: ```rs use serenity::cache::CACHE; let cache = CACHE.read().unwrap(); let channel = match cache.get_guild_channel(channel_id) { Some(channel) => channel, None => { context.say("Could not find channel") .map_err(|x| println!("Err sending message: {:?}", x)); return; }, }; ```
* Rename PublicChannel to GuildChannelAustin Hellyer2016-11-251-4/+4
|
* Change the CACHE to be an RwLockAustin Hellyer2016-11-221-4/+4
| | | | | | | | | | | | | | | | | | The global Cache used to be an Arc<Mutex>, however the issue is that it could only be opened for reading or writing once at a time. With an RwLock, multiple readers can access the Cache at once, while only one Writer may at once. This will allow users to be able to have multiple Readers open at once, which should ease some of the pains with working with the Cache. Upgrade path: Modify all uses of the CACHE from: `CACHE.lock().unwrap()` to `CACHE.read().unwrap()` if reading from the Cache (most use cases), or `CACHE.write().unwrap()` to write to it.
* Rename the State to CacheAustin Hellyer2016-11-222-8/+8
|
* Don't unnecessarily borrow some if-letsAustin Hellyer2016-11-211-1/+1
|
* Re-organize the client moduleAustin Hellyer2016-11-212-11/+11
| | | | | | | | | | | | | | | | | | Re-organize the client module, creating a `gateway` submodule, and splitting the connection into separate files in it. The connection was a conglomeration of a number of purposes, most of which are actually used elsewhere in the library and/or exposed to the user. Thus, it makes sense to separate each item in a gateway-specific module. By splitting the client module further, this is a re-organization for preliminary RPC support WRT the Client. Additionally, rename the Connection struct to a Shard. The Connection itself was not the actual connection, and was a higher-level interface to the real connection logic. A Shard is a more accurate representation of what it actually is.
* Add framework command named argumentsAustin Hellyer2016-11-211-0/+10
|
* Fix voice example for state method renamingsAustin Hellyer2016-11-201-4/+4
|
* Allow Id/u64 equality comparisonsAustin Hellyer2016-11-171-1/+1
| | | | | | | | | | | | | | This will allow comparing, for example, a `ChannelId` with a `u64` directly, bypassing the need to do something like: ```rust let channel_id = ChannelId(7); assert!(channel_id.0 == 7); // can now be replaced with: assert!(channel_id == 7); ```
* Feature-gate voice exampleAustin Hellyer2016-11-151-0/+14
| | | | | | When building without enabling the 'voice' feature, the voice example would fail. Instead, feature-gate it off so that it at least compiles with a "Voice not enabled" message.
* Travis: Pass feature flag 'voice'Austin Hellyer2016-11-141-0/+2
|
* Add voice connection supportAustin Hellyer2016-11-141-0/+168
|
* Framework: fix command arg positioningAustin Hellyer2016-11-081-1/+1
| | | | | | | | | | The command system assumed that prefixes were only one character long, so count the total length of the prefix. In addition, the `allow_whitespace` configuration added some difficulty in deciding where to count as the initial position to start splitting for arguments. Instead of fixing that, rewrite the framework to make these types of changes easier in the future.
* Add arguments to framework commandsAustin Hellyer2016-11-071-6/+6
|
* Add an 'allow_whitespace' framework configAustin Hellyer2016-11-061-0/+1
| | | | | | | | | | | | | | The option allows whitespace to be optional between a mention and a command. Setting it to true will allow the following scenario to occur, while false will not: ``` <@BOT_ID>about // bot process and executes the "about" command if it exists ```
* Fix typo in example 06Austin Hellyer2016-11-061-1/+1
|
* Initial commitAustin Hellyer2016-10-186-0/+221