Commit Graph

430 Commits

Author SHA1 Message Date
Paulo
b8fa464125 fix: Stop TaskCanceledException from bubbling up (#1580) 2020-07-10 00:13:01 -04:00
Paulo
dc8c95931e fix: Incomplete Ready, DownloadUsersAsync, and optimize AlwaysDownloadUsers (#1548)
* Fix Ready and AlwaysDownloadUsers

Ready could fire before downloading all guild data and downloading guild users one guild per time without gateway intents is a waste of a gateway request that can support up to 1000.

* Reduce batchSize and fix count

* Fix typo

* Split xml docs line

Co-authored-by: Christopher Felegy <cfelegy@riseup.net>
2020-06-18 00:00:10 -04:00
Paulo
ab32607bcc (ifcbrk) fix: Add AllowedMentions to SendFileAsync (#1531)
* Add AllowedMentions to SendFileAsync

* Update xml reference and mocked channels
2020-06-17 23:51:50 -04:00
Paulo
f2130f8513 feature: Add Direction.Around to GetMessagesAsync (#1526)
* Add Direction.Around to GetMessagesAsync

* Reuse the method

* Reuse GetMany

* Fix limit when getting from cache without message id

* Fix limit when getting from rest without message id

* Change cache return

It will return in a similar way to REST
2020-06-17 23:48:45 -04:00
moiph
d5d10d32cf feature: Support Gateway Intents (#1566)
* Support Gateway Intents

Allows supplying gateway intents through DiscordSocketConfig which will be passed through the IDENTIFY payload, in order to choose what gateway events you want to receive.

* Fixing enum casing

* Feedback

* Updating comment for GuildSubscriptions

* Comment update
2020-06-17 23:40:10 -04:00
Paulo
a89f0761f4 feature: Add MESSAGE_REACTION_REMOVE_EMOJI and RemoveAllReactionsForEmoteAsync (#1544)
* Add event and method

* Simplify convert to IEmote
2020-06-15 00:04:34 -04:00
Paulo
bd4672ae21 fix: InvalidOperationException at MESSAGE_CREATE (#1555)
## Summary

If PartyId isn't present, Discord.Net will throw an InvalidOperationException and not raise `MessageReceived`.
Got this a few times with my bot, stacktrace:
```
System.InvalidOperationException: This property has no value set.
   at Discord.Optional`1.get_Value() in ...\Discord.Net\src\Discord.Net.Core\Utils\Optional.cs:line 20
   at Discord.WebSocket.SocketMessage.Update(ClientState state, Message model) in ...\Discord.Net\src\Discord.Net.WebSocket\Entities\Messages\SocketMessage.cs:line 157
   at Discord.WebSocket.SocketUserMessage.Update(ClientState state, Message model) in ...\Discord.Net\src\Discord.Net.WebSocket\Entities\Messages\SocketUserMessage.cs:line 58
   at Discord.WebSocket.SocketUserMessage.Create(DiscordSocketClient discord, ClientState state, SocketUser author, ISocketMessageChannel channel, Message model) in ...\Discord.Net\src\Discord.Net.WebSocket\Entities\Messages\SocketUserMessage.cs:line 53
   at Discord.WebSocket.DiscordSocketClient.ProcessMessageAsync(GatewayOpCode opCode, Nullable`1 seq, String type, Object payload) in ...\Discord.Net\src\Discord.Net.WebSocket\DiscordSocketClient.cs:line 1210
```

After looking all properties, this is the only one that could be blamed and was already fixed for `RestMessage`s, see #1337 

## Changes

- `Value` to `GetValueOrDefault()` for `PartyId`
2020-06-15 00:02:51 -04:00
Paulo
57880de5b8 (ifcbrk) Add SearchUsersAsync (#1556) 2020-06-15 00:02:23 -04:00
Paulo
323a6775ee misc: MutualGuilds optimization (#1545)
* Check Dictionary

Check Dictionary instead of creating a new IReadOnlyCollection and looping in it

* Add Remark to MutualGuilds
2020-05-24 23:38:25 -04:00
Paulo
30b5a833d2 feature: Add GetUsersAsync to SocketGuild (#1549)
* Add GetUsersAsync to SocketGuild

* Fix IGuild return

* Do not download unless needed
2020-05-24 23:37:21 -04:00
Matt Smith
a6c1e4c23f (ifcbrk) feature: news channel publishing (#1530)
* Added PublishAsync to Messages.

* Added missing implementation.

* 1. Aligned with naming standards
2. Clarified xml docs
3. Properly threw exceptions instead of failing silently.

* Additional documentation included.

* Removed un-needed comments.

Co-authored-by: Matt Smith <v-matsm@microsoft.com>
2020-05-20 17:28:23 -04:00
Paulo
91b270a0ce fix: handle GUILD_DELETE behavior correctly (#1542) 2020-05-20 17:25:49 -04:00
TheKingEagle
03af8e0bb4 fix: Call GuildAvailableAsync for dispatch(GUILD_CREATE) case (#1473)
* Fix for Issue #1471

This change will allow `GuildAvailable` to fire when the client joins a new guild, as well as properly update `IsConnected`.

* Removed unnecessary statement;
2020-05-07 09:19:15 -04:00
Joe4evr
c68cc85895 feature: Add cache purging methods (#1478) 2020-05-07 09:16:57 -04:00
Chris Johnston
89b6b7e1a5 feature: Include allowed mentions payload on message creation (#1455)
* Feature: Allowed mentions object on msg create (interface breaking)

This change implements the AllowedMentions object for the payload of message creation. By default, the mentions behavior remains unchanged, the message content is parsed for all mentionable entities and they are all notified. If this payload is not null, it will use the content of the allowed_mentions field to determine if a role is notified, or just displayed.

This change is interface breaking. This follows the conventions of keeping RequestOptions as the last argument, but could break some users who specify each of these arguments without using named arguments.

* lint: remove commented-out code

This change removes the commented-out code which was added during testing from the previous commit.

* fix interface break: reorder allowedMentions arg so that it's after options

This change modifies the order of the AllowedMentions argument of SendMessageAsync so that this addition shouldn't be interface breaking. The downside to this change is that it breaks the convention followed by other methods, where the RequestOptions argument is normally last.

* docs: fix typo in allowedMentions arg doc

* fix interface break arg from IRestMessageChannel

* docs: update xmldoc for allowedMentions args

* fix interface breaking arg order for ISocketMessageChannel

* fix mocked classes that weren't updated

* fix: RestDMChannel#SendMessageAsync bug, allowed mentions always null

This change fixes a bug that was introduced while testing changes to the interface of the SendMessageAsync method to try and retain interface compatibility

* docs: update xmldoc for AllowedMentions type

* docs: reword xmldoc of AllowedMentionTypes type

* docs: fix typo

* fix: validate that User/Role flags and UserIds/RoleIds lists are mutually exclusive

This change adds validation to SendMessageAsync which checks that the User flag is mutually exclusive with the list of UserIds, and that the Role flag is also mutually exclusive with the list of RoleIds

* docs: reword summaries for AllowedMentions type

* Add util properties for specifying all or no mentions

Adds read only properties which specify that all mentions or no mentions will notify users. These settings might be more common than others, so this would make them easier to use.

* docs: Resolve PR comments for documentation issues/typos
2020-05-07 09:13:57 -04:00
Monica S
ed869bd78b [apibrk] change: Specify WebSocket close code (#1500)
* API breaking change: Specify WebSocket close code

Should fix #1479 and help overall with resuming sessions.

* Also try to resume on missed heartbeats
2020-04-25 12:12:57 +01:00
Min
1f01a2d1fa fix: nullcheck _shards before iterating (#1493) 2020-04-22 02:02:22 -04:00
Chris Johnston
a4846516fb fix: false-positive detection of CustomStatusGame based on Id property (#1416)
This change fixes a bug that was introduced in PR #1406. Games were falsely detected to be CustomStatusGames, based on the Id property being included in the model payload.

This fixes the false detection of Games as CustomStatusGame. An activity will only be considered a CustomStatusGame if the Id has a value of "custom".

This change has been tested by listening to the GuildMemberUpdated event, and opening/closing games with a custom status set.
2019-11-29 22:13:08 -05:00
Saulius Šaltenis
2bba324143 feature: add StartedAt, EndsAt, Elapsed and Remaining to SpotifyGame. (#1414)
* Fixed GetUsersAsync to use MaxUsersPerBatch const as limit instead of MaxMessagesPerBatch.

Requests are now returning up to 1000 guild user entities instead of the previous 100.

* Added StartedAt and EndsAt timespans for SpotifyGame.
They make it possible to expose track's Elapsed and Remaining properties.

* Moved Duration to be initialized within model construction.

* Updated StartedAt and EndsAt comments.
2019-11-29 22:11:48 -05:00
Chris Johnston
e627f0780a change: fix #1415 Re-add support for overwrite permissions for news channels (#1417)
This change updates the NewsChannel classes so that the overwrite permission-related properties no longer throw an Exception when they are used.
These properties were not initially supported by News/Announcement channels when the feature was first released, but now they are.
2019-11-29 22:07:43 -05:00
Chris Johnston
1c63fd479d (ifcbrk)fix: #1335 Add isMentionable parameter to CreateRoleAsync in non-breaking manner (#1418)
* Fix #1335 Add isMentionable parameter to CreateRoleAsync in non-breaking manner

This PR adds the isMentionable parameter to the CreateRoleAsync method
in a way that prevents it from being interface-breaking. This has been done
by adding it as an optional parameter at the end of publicly-exposed
methods.

This parameter determines if the newly created role can be mentioned as it is
created.

* Overload CreateRoleAsync methods
2019-11-29 21:59:11 -05:00
Chris Johnston
3ff4e3d506 fix: #1421 (in a better way) Return empty set when ActiveClients is null (#1422)
This change ensures that SocketUser.ActiveClients will not return null, but instead an empty set by default. This can happen if the client has not recieved a presence update for a user, or if the user is not cached.
2019-11-23 12:58:13 -05:00
Chris Johnston
79a0ea9de3 Feature: CustomStatusGame Activity (#1406)
* Implement CustomStatusGame activity

Adds the CustomStatusGame class, which is the activity corresponding to the custom status feature.

* Remove unused import from Game.cs
2019-11-09 13:41:10 -05:00
Neuheit
f86c39de6a feature: Implemented Message Reference Property (#1413)
* Added support for Message References

* Removed unused usings, added debugger display, updated ToString override

* Changed snowflakes to be wrapped in an optional instead of a nullable.
2019-11-09 13:12:29 -05:00
JT
d199d93ae4 meta: Fix .NET Core 3.0 compatibility + Drop NS1.3 (#1382)
* Update all dependencies and deal with warning/errors

* Add updated AsyncEnumerable implementation

* Fix broken target

* Cleanup

* Remove obsolete message

* typo

* Update azure pipelines

* Update samples to .NET Core 3.0

* Pull out test change

* Install the .net core 3 SDK on the ubuntu image for the time being

* Target net core 3 for the unit tests because pipelines
2019-10-22 22:50:12 -04:00
Chris Johnston
a61adb07e0 feature: #1381 Guild PreferredLocale support (#1387)
* Fix #1381 Guild PreferredLocale support

Adds support for getting and modifying a guild's preferred_locale. This is a language tag in IETF BCP 47 format, which works with the built-in CultureInfo.

While Discord only supports a number of cultures, I think that this restriction should be handled at the API and not by the wrapper. (Also easier on our end)

* Add PreferredCulture to IGuild

This property was defined in RestGuild and SocketGuild, so it only makes sense to make it part of IGuild as well.
2019-10-22 22:46:41 -04:00
Kieran Boyle
0d54207a27 feature: support guild subscription opt-out (#1386) 2019-10-01 15:51:02 -04:00
Still Hsu
fd3810e9fe docs: September 2019 Documentation Update (#1379)
* docs: adjust wording of ActivityType.Watching enum

Adjusts the xmldoc summary wording of the ActivityType.Watching enum to
fix a wording issue.

* Add D.NET Logo to Open Graph meta tags

* Update DescriptionGenerator
...And update color to suit the logo better

* Disable smooth scrolling due to user complaints

* Remove unnecessary spacing in sideaffix

* Update footer version

* Remove featherlight plugin

As it is unnecessary and can break image tags

* Adjust wordings regarding safe-handling of secrets

* Fix formatting for first bot token sample

* Add badges to homepage

* Minor wording fixes on terminal

* Update to higher quality PNG

* Add Discord.Net.Example in sln for build validation

* Clarify all instances of IAsnycEnumerable

* Clarify overridden props in SocketNewsChannel

* Add returns and params docs for SyncPermissionsAsync

* Remove/fix invalid XMLdoc strings

* Remove AppVeyor and add GitHub badge
2019-09-22 19:06:57 -04:00
Christopher F
7b9029dd91 feature: support X-RateLimit-Reset-After (#1372)
* feature: support X-RateLimit-Reset-After

Users may now optionally disable using the system clock to calculate
the ratelimit duration. This may be overrided globally, via
DiscordConfig, or per RequestOptions.

This change has been built and tested via the integrated test suite,
but has not been tested in the real world. Please verify this does not
break any of the edge-case ratelimits.

* patch: wire new config properties to ApiClient

* patch: update Reset-After parsing precision

This patch applies the changes made to parsing precision in 606dac3.
2019-09-21 09:24:37 -04:00
Chris Johnston
68eb71c175 (binbrk)feature: Support filtering audit log entries on user, action type, and before entry id (#1377)
* Support filtering audit log entries on user, type, and before id

Adds support for filtering audit log entires with GetAuditLogsAsync. Adds the ability to specify a userId and ActionType to filter. Exposes the beforeId filter which was already implemented, yet unused (even when requesting > 100 entries)?

Was thinking that this could expose overloads of GetAuditLogAsync that accepts a IUser and IAuditLogEntry, but dealing with all the combinations of these types may be excessive.

* use only stringbuilder for args instead of string interpolation
2019-09-20 18:36:02 -04:00
Chris Johnston
606dac3e1a fix: Use double precision for X-Reset-After, set CultureInfo when parsing numeric types (#1375)
* Parse double for X-Reset-After instead of float, needs more precision

Float did not contain enough precision to store the millisecond unix
time value, which resulted in the second and millisecond values being
slightly off.

This can be easily tested using:

```cs
> DateTimeOffset.FromUnixTimeMilliseconds((long)(1470173022.123f *
1000)).Millisecond
160 // wrong

> DateTimeOffset.FromUnixTimeMilliseconds((long)(1470173022.123 *
1000)).Millisecond
123 // correct
```

* Parse RateLimit-Reset using an IFormatProvider

* State NumberStyle and use CultureInfo.InvariantCulture for any parsing

This updates most occurances in the code where a Parse or TryParse method was used to explicitly state the NumberStyle, and to use CultureInfo.InvariantCulture.
CultureInfo was used over NumberInfo, as it also works on DateTime parsing too.

* Use default format spec in Commands
2019-09-14 16:38:26 +00:00
Chris Johnston
9482204bcf feature: Add support for setting X-RateLimit-Precision (#1354)
* support X-RateLimit-Reset sending integer or float values

This changes the way that the X-RateLimit-Request header is parsed, so that it will work with both integer seconds and float values with seconds and milliseconds

* Add RateLimitPrecision enum, set X-RateLimit-Precision

Adds the RateLimitPrecision enum, with Second and Millisecond values. (Do we want to use an extension method to convert it into a string, or is ToString().ToLower() fine?)
Adds RateLimitPrecision as a parameter to DiscordRestApiClient, and to DiscordConfig so that it can set the X-RateLimit-Precision header.
2019-09-08 15:21:10 +00:00
Chris Johnston
07f4d5f353 [abibrk] change: Update ISystemMessage interface to allow reactions (#1368)
* Move reaction methods of IUserMessage to IReactionMessage

Moves the reaction-related methods contained in IUserMessage to the IReactionMessage type. Updates the type of ISystemMessage so that it implements IReactionMessage.

* Move rest reaction implementation to RestReactionMessage

Copies the reaction implementation from RestUserMessage to RestReactionMessage. Updates RestUserMessage and RestSystemMessage to be derived from RestReactionMessage instead of RestMessage.

* Move WS reaction implementation to SocketReactionMessage

Copies the reaction implementation from SocketUserMessage into SocketReactionMessage. Updates SocketSystemMessage and SocketUserMessage to use SocketReactionMessage as the base class.

* docs: update summary for ReactionMessage classes

* Remove ReactionMessage types, move reaction impl to IMessage

Removes the IReactionMessage and derived types, which was unnecessary since all classes derived from IReactionMessage were IMessage.

Moves the reaction implementation to IMessage and derived types.
2019-09-08 15:18:52 +00:00
Christopher Felegy
dcd9cdd13e lint: rename IsStream to IsStreaming
While it might be more proper to refer to a voice state as composing
a stream (i.e., the IVoiceState is a Stream), this property is ported
up most often to actual user entities. It makes more sense to
communicate that the user is streaming, rather than stating that the
user itself is a stream.

This is also more gramatically consistent with the other voice state
properties (e.g., IsMuted). Movement from noun-form to participle-form
remains inline with the past-participle form used on the other
properties.
2019-09-07 22:19:26 +00:00
Chris Johnston
9bb08c9ba4 feature: Add SelfStream voice state property (#1369)
* Add self_stream voice state property

Adds the self_stream property which is set true when a user is streaming a video to a voice channel

* use flags for selfstream state instead of its own prop
2019-09-08 02:08:40 +00:00
Chris Johnston
c977f2ec9c fix: #1314 Don't parse tags within code blocks (#1318)
* implement a fix for tags being found in code blocks

still needs polish, consider this a rough draft

* refactor to reuse a local function

uses CheckWrappedInCode to check that there are no code blocks that surround the tag being parsed

* Add more test coverage of MessageHelper.ParseTags

* reset indexes for @ here mention

* add a test case to catch error fixed from prev commit

* wip commit of most test cases working

* fix the Enclosed in block util method

* code cleanup

* lint whitespace

* lint brackets for single line if blocks

* move messagehelpertests to the new unit test dir

* expose internals to the unit test project

this seems to have been breaking the build, since CI would build the merged branch, where rest wasn't exposed to the unit tests
2019-08-25 13:28:05 +00:00
moiph
52565ed0de docs: Fixing GatewayEncoding comment (#1359)
Const, not a property
2019-08-25 13:09:55 +00:00
Chris Johnston
9da11b4184 [ifcbrk] feature: Implement Client Status Support (#1247)
* Implement Client Status Support

Adds support for using the client_status as sent as part of the Presence model. This value can be used to determine if a user is active on the native desktop app, the mobile app, or the website.

* lint: whitespace in IPresence

* Remove breaking change to IPresence interface with a note for 2.1

* update comment to not reference 2.1

* re-add interface break to IPresence

* add example payload for client_status

* use inline declaration for Enum.TryParse
2019-06-22 23:46:20 -04:00
Christopher Felegy
c870e672a2 debug: temporary sanity checking in SocketGuild 2019-06-22 17:03:59 -04:00
Casino Boyale
c88b1dada7 [ifcbrk] feature: id overload for RemoveReactionAsync (#1310)
* Added id overload for RemoveReactionAsync

* Fixed the docs strings
2019-06-21 17:35:40 -04:00
Chris Johnston
faf23dee35 [ifcbrk] feature: BOOST (#1319)
* add new MessageTypes

* Add new properties to the updated models

* add the SystemChannelMessageDeny

unsure if there would be a better name for this enum, given it's inverted nature, open for suggestions

* add PremiumTier flag, add Guild description property

* add method for getting vanity image from CDN

* make the size of GetGuildVanityUrl optional

* lint: remove commented out code from prev commit

* add a None flag to SystemChannelMessage enum

* implement the new modify guild params

* implement additional model properties in IGuild types

* implement GuildMember PremiumSince

* docs: reword size param explanation

* add extension methods that make it easier to check the SystemChannelMessage flags for end users

because the flag is inverted, this ideally should make it easier for the user. it may also be useful to do something similar for modifying this property

* docs: correct typo from copy-paste

* add the premium_subscription_count property

* fix vanity url code and banner switchup

a mistake was made somewhere, that's all I know for sure

* clarify remark on inverted logic for system channel flags

* fix PremiumSubscriptionCount optional value

* add another example to the systemchannelflags xmldoc remark

* docs: fix typos, clarify wording

* use DateTimeOffset for PremiumSince, follow conventions from other prop
2019-06-21 17:34:45 -04:00
Still Hsu
363d1c6da6 docs: Fix invalid cref values in docs (#1329)
Signed-off-by: Still Hsu <341464@gmail.com>
2019-06-21 17:23:02 -04:00
Casino Boyale
9fede346d3 feature: Added a Rest property to DiscordShardedClient (#1326)
* Added a Rest property to DiscordShardedClient

* Moved the rest client onto the BaseSocketClient
2019-06-21 17:22:32 -04:00
Passive
c864f48c3b lint: Fix spelling mistake in ExclusiveBulkDelete warning (#1330) 2019-06-21 17:21:22 -04:00
Christopher Felegy
cd288923c3 [ifcbrk] feature: suppress messages
yeah man I support the first amendment
2019-06-21 17:18:29 -04:00
Chris Johnston
40844b9e13 feature(binbrk): Add properties missing from User and Activity models (#1237)
* WIP commit, update IActivity and IUser with missing types

* incomplete implementation of interfaces

* Add implementation of activity flags, and extension method to check flag

* remove usings that were not required

* clean up files and add documentation where missing

* remove unused usings

* Add remark saying that premium_type info may be inaccessible to bots

it seems that this information can not be accessed by any user,
and may require the identity oauth scope

* Add locale property to the user model

adds the locale property to the user model, which appears not to be
specified for bots

* rename ActivityFlags

* Add incomplete xmldoc to ActivityFlag

Added xmldoc to the ActivityFlag type, excluded flags that i was unsure about

* rename the UserFlags file

* Add incomplete xmldoc to UserFlag enum

* Remove unnecessary extension methods and use built-in functionality

* use <c> tag for xmldoc 'null's

* Add xmldoc for JoinRequest ActivityFlag

* improve the PremiumType xmldoc

* Add zero activityflag

* Add summary tag verbs, example of IUser locale

* Rename Flag enum types to use Properties suffix

* Expose the details field in the Game model

* update Activity extension methods to support Details field

* Use inherited Details implementation in RichGame

* lint: remove commented out code from debugging

* Fix issue in previous commit

* Move oauth-only user fields to SelfUser classes

Moves the implementation of the Flags, PremiumType, and Locale user fields to ISelfUser classes. In testing, it seemed that normal bot accounts did not have this information supplied to them. When tested with a Bearer token in the Rest client, these fields are set.

* remove old HypeSquadEvents flag that appears to have been replaced with the new HypeSquad flags
2019-06-12 16:00:30 -04:00
Casino Boyale
1cc5d7321b fix: fixed optionals having IsSpecified true when objects weren't in cache (#1323)
* Fixed optionals having IsSpecified true when objects weren't in cache

* Removed double null check
2019-06-06 16:22:34 -04:00
Christopher Felegy
c78a6790b1 fix: don't raise REST log events twice
The DiscordSocketClient and DiscordSocketRestClient share the same
backing API client, so the Log events on both clients will be raised
from the same API calls. Proxying log events from the
DiscordSocketRestClient then means that the Log event the user hooks
into will be raised twice for a single log message.

Thanks to @TheCasino for noticing this.
2019-05-19 12:16:37 -04:00
Christopher Felegy
f6e320053b fix: ensure that exceptions will be logged
Resolves #1238.

I'm not sure where this bug came from, a git blame revealed no change to
the timed event handler code since it was initiall written two years
ago.

I've found that when the event handler times out, the handler task will
be manually completed (as opposed to within Task.WhenAny), which then
bubbles the exception and allows the error to be logged.

Ensuring that the handler is completed individually, regardless of
whether or not the timeout task completed, seems to fix this problem.
2019-05-18 09:42:37 -04:00
Christopher Felegy
a44c13af78 fix: call OnLogin/OnLogout on DiscordSocketRestClient
Resolves #1277.
2019-05-18 09:32:49 -04:00