aboutsummaryrefslogtreecommitdiff
path: root/src/model/guild.rs
Commit message (Collapse)AuthorAgeFilesLines
* Rework the models directoryZeyla Hellyer2017-03-251-2587/+0
|
* Fix Member methods due to variant joined_at valuesZeyla Hellyer2017-03-201-0/+16
| | | | | | | | | | | | | | | Fix an issue where the library would check the Id of the guild that a member is in by checking the Member's ID and joined_at value with those of the members of guilds present in the cache. Performing this check would have the issue of where a joined_at for a member received over websocket would potentially have a varying value than that of the same member retrieved over REST. To fix this, attach the relevant guild's Id to the member on creation, where the Id is available. Fixes #68.
* Pass by reference where possibleZeyla Hellyer2017-02-281-16/+16
| | | | | | | A lot of the `rest` methods took - for example a Map - by value, where they could instead take a reference. While this only prevents one clone in the library, user-land code should no longer need to clone maps when using the `rest` module.
* Update doctests for Context changesZeyla Hellyer2017-02-151-4/+6
| | | | | | | | | | | | | | | | | | | Due to the Context having many methods removed, the doctests were failing. Update the doctests to use alternative methods to accomplish the same. Example: Before: ```rust context.say("hi"); ``` After: ```rust message.channel_id.say("hi") ```
* Optimize cachingZeyla Hellyer2017-02-091-68/+86
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Improve the cache by keeping track of new maps, making other maps have `Arc<RwLock>` values, optimizing already-existing methods, and take advantage of new, more efficient retrievals (e.g. simply keying a value from a map rather than iterating over vecs or maps and then itering over another vec). Keep track of two new maps in the cache: - **channels**: a map of all guild channels that exist, so that they can be efficiently found, and so a message's guild can be efficiently found - **users**: a map of all users that exist, so that it can be shared across all members and presences Other cache fields now have `Arc<RwLock>` values: - `groups` - `guilds` - `private_channels` `Cache::unavailable_guilds` is now a `HashSet<GuildId>` instead of a `Vec<GuildId>`. This should slightly optimize removals/insertions for large bots. `ext::cache::ChannelRef` has been removed as it became equivilant in functionality to `model::Channel`. Also, `model::Channel` now has all variant data encased in `Arc<RwLock>`s. E.g., `Channel::Group(Group)` is now `Channel::Group(Arc<RwLock<Group>>)`. Some model struct fields are now wrapped in an `Arc<RwLock>`. These are: - `Group::recipients`: `HashMap<UserId, User>` -> `HashMap<UserId, Arc<RwLock<User>>>` - `Guild::channels`: `HashMap<ChannelId, GuildChannel>` -> `HashMap<ChannelId, Arc<RwLock<GuildChannel>>>` - `Member::user`: `User` -> `Arc<RwLock<User>>` - `PrivateChannel::recipient`: `User` -> `Arc<RwLock<User>>` Some (cache-enabled) event handler signatures have changed to use `Arc<RwLock>`s: - `Client::on_call_delete` - `Client::on_call_update` - `Client::on_guild_delete` - `Client::on_guild_update` Many function signatures have changed: - `Cache::get_call` now returns a `Option<Arc<RwLock<Call>>>` instead of a `Option<&Call>` - `Cache::get_channel` now returns a `Option<Channel>` instead of a `Option<ChannelRef>`. This now also retrieves directly from the `Guild::channels` instead of iterating over guilds' for a guild channel - `Cache::get_guild` now returns a `Option<Arc<RwLock<Guild>>>` instead of a `Option<&Guild>` - `Cache::get_guild_channel` now returns a `Option<Arc<RwLock<GuildChannel>>>` instead of a `Option<&GuildChannel>` - `Cache::get_group` now returns a `Option<Arc<RwLock<Group>>>` instead of a `Option<&Group>` - `Cache::get_member` now returns a `Option<Member>` instead of a `Option<&Member>`, due to guilds being behind a lock themselves - `Cache::get_role` now returns a `Option<Role>` instead of a `Option<&Role>` for the above reason - `Cache::get_user` now returns a `Option<Arc<RwLock<User>>>` instead of a `Option<&User>` - `GuildId::find` now returns a `Option<Arc<RwLock<Guild>>>` instead of a `Option<Guild>` - `UserId::find` now returns a `Option<Arc<RwLock<User>>>` instead of a `Option<User>` - `Member::display_name` now returns a `Cow<String>` instead of a `&str` A new cache method has been added, `Cache::get_private_channel`, to retrieve a `PrivateChannel`. The `Display` formatter for `Channel` has been optimized to not clone.
* Update examples for OOP updateAustin Hellyer2017-01-261-11/+4
|
* Make Guild::create_channel return a GuildChannelAustin Hellyer2017-01-251-3/+3
| | | | | | | | | | | Instead of returning a generic `Channel` enum, make the following functions return an explicit GuildChannel instead of a more "generic" Channel enum: - Guild::create_channel - GuildId::create_channel - PartialGuild::create_channel - rest::create_channel
* Fix docs linksAustin Hellyer2017-01-241-15/+16
|
* Properly drop on bindsAustin Hellyer2017-01-241-6/+6
| | | | | | | Instead of binding to `_why`, bind to `_`, dropping the value. This is pretty much just leftover from when the library was being rapidly developed before being released.
* Abstract large threshold number to a constantAustin Hellyer2017-01-241-1/+2
|
* Rename 'webhooks' methods to 'get_webhooks'Austin Hellyer2017-01-241-30/+30
|
* Use Id methods where possibleAustin Hellyer2017-01-241-34/+19
|
* Add GuildId::as_channel_id()Austin Hellyer2017-01-231-0/+6
|
* Switch to a mostly-fully OOP approachAustin Hellyer2017-01-231-236/+1482
| | | | | | The context is now strictly in relation to the context of the current channel related to the event, if any. See Context::say for a list of events that the context can be used for.
* Make a single POST on guild role createAustin Hellyer2017-01-181-4/+1
| | | | | The endpoint to create a role no longer returns an empty role which must be PATCHed, and can be completed in the initial request.
* First round of deleting useless methodsAustin Hellyer2017-01-151-20/+1
|
* Convert Colour to be a tuple structAustin Hellyer2017-01-131-1/+1
| | | | The struct only has one field (`value`) anyway.
* Fix buildIllia2017-01-111-1/+1
|
* Add Message.content_safe and fix distinct method not being included in User.Illia2017-01-111-0/+6
|
* Update icons/splashes to be WEBPAustin Hellyer2017-01-081-6/+6
|
* Alphabetize model method namesAustin Hellyer2017-01-081-40/+39
|
* Code style cleanupAustin Hellyer2017-01-081-3/+3
|
* Fix no-cache method buildsAustin Hellyer2017-01-021-1/+3
|
* Fix typoIllia2016-12-311-1/+1
|
* Add guild and channel searchAustin Hellyer2016-12-291-3/+155
|
* Use conditional blocks over macrosAustin Hellyer2016-12-291-22/+33
|
* Simplify Role's Ord implAustin Hellyer2016-12-281-11/+3
|
* (╯°□°)╯︵ ┻━┻Austin Hellyer2016-12-191-3/+10
|
* Add guild splash URL methodsAustin Hellyer2016-12-171-0/+23
|
* Add emoji URL generation methodsAustin Hellyer2016-12-121-0/+7
|
* More config for CreateCommand, add various methodsIllia2016-12-101-34/+34
| | | | | | | | | | | | | | | | | | | | | | | | | | Adds multiple configurations to the command builder, and adds methods to various structs. Context::get_current_user is a shortcut to retrieve the current user from the cache. Message::get_member retrieves the member object of the message, if sent in a guild. Message::is_private checks if the message was sent in a Group or PrivateChannel. User::member retrieves the user's member object in a guild by Id; Adds 6 configurations to the command builder: - dm_only: whether the command can only be used in direct messages; - guild_only: whether the command can only be used in guilds; - help_available: whether the command should be displayed in the help list; - max_args: specify the maximum number of arguments a command must be given; - min_args: specify the minimum number of arguments a command must be given; - required_permissions: the permissions a member must have to be able to use the command;
* Fix no-cache+method conditional compilesAustin Hellyer2016-12-101-7/+4
| | | | Additionally, flag imports behind feature flags to avoid unused imports.
* Change all try's into ?sacdenisSK2016-12-071-47/+47
| | | This breaks compatibility with < 1.13, but we didn't support that anyway.
* Improve Mentions, fix MessageBuilderIllia2016-12-061-5/+0
| | | | | Remove the obsolete Mention struct as well as related methods, improve the way mentioning works, fix the message builder, add a test for all this.
* Add documentation for modelsIllia2016-12-041-1/+1
|
* Import this import _again_Austin Hellyer2016-12-031-0/+2
|
* Make Member::colour() return an optional colourAustin Hellyer2016-12-031-18/+7
|
* Add Member::colourIllia2016-12-031-9/+34
| | | | Add a colour method to retrieve the member's top role with a unique colour, or the default colour if none can be applied.
* Add Role Eq/Ord implsAustin Hellyer2016-12-031-0/+33
| | | | | | | | | Roles can now be compared directly. This is a heirarchy check. This checks the following between two roles, A and B: - A's position is greater than B; - if not, then A's Id is greater than B; if these two conditions are false, then B is greater than A. If the two conditions are both true, then they are of equivilance.
* Add Member.colourIllia2016-12-031-0/+11
|
* Clean up the codebaseAustin Hellyer2016-11-291-10/+6
|
* Optimize for cached, non-method compilesAustin Hellyer2016-11-281-2/+2
|
* More widely support no-cache method compilesAustin Hellyer2016-11-251-58/+79
| | | | | | | Conditional compiles with the 'methods' feature enabled - but the 'cache' feature disabled - were supported, but methods would call an empty function to check if the current user has permissions. Instead, put these function calls behind macros which check for feature cfgs.
* Rename PublicChannel to GuildChannelAustin Hellyer2016-11-251-4/+4
|
* Rename the `http` module to `rest`Austin Hellyer2016-11-251-26/+26
|
* Allow compiling with only either cache or methodsAustin Hellyer2016-11-241-18/+20
| | | | | | | | | Some of the methods relied on the cache being present. Now, these methods only conditionally require the cache to be compiled and present. The cache was mainly used for checking if the current user had permission to perform operations.
* Rename guild structs to Guild and PartialGuildAustin Hellyer2016-11-241-12/+12
|
* Change the CACHE to be an RwLockAustin Hellyer2016-11-221-6/+6
| | | | | | | | | | | | | | | | | | 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-221-15/+15
|
* Add Member::roles()Austin Hellyer2016-11-201-0/+20
| | | | | | | The roles method will search through the state and find full role data for the member. This is essentially a shorthand for it. This does perform a clone of the role data, but this will be optimized in the future.