Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix!: nullability & other things #341

Closed
wants to merge 122 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
122 commits
Select commit Hold shift + click to select a range
250936f
empty commit for pr
Lulalaby Jul 27, 2023
dc2e739
chore: partly re-enable warnings and information messages
Lulalaby Jul 27, 2023
4c29d04
fix: use target type new() & use pattern matching
Lulalaby Jul 28, 2023
d170f8a
fix: resharper suggestions
Lulalaby Jul 28, 2023
f2a632f
fix: suggestions
Lulalaby Jul 28, 2023
5a16a48
i have a headache
Lulalaby Jul 28, 2023
235a0cb
Update 10_4_0.md
Lulalaby Jul 28, 2023
5620b11
meow
Lulalaby Jul 28, 2023
11fb9e0
nya
Lulalaby Jul 28, 2023
fde26cd
aaaaaaaa
Lulalaby Jul 28, 2023
01535da
:bongo_cat:
Lulalaby Jul 28, 2023
f1025ad
rawr
Lulalaby Jul 28, 2023
f390be2
code cleanup! :fire:
Lulalaby Jul 28, 2023
4fdce35
rework rest & ratelimit stuff
Lulalaby Jul 28, 2023
0d790b2
aaaaaaaaaaa
Lulalaby Jul 28, 2023
1144a95
aaaaaaaaaaa x2 & brainfuck
Lulalaby Jul 28, 2023
9b31d45
fix
Lulalaby Jul 28, 2023
8a5606c
nyum
Lulalaby Jul 28, 2023
5fa1db3
boop
Lulalaby Jul 28, 2023
614c857
nyum
Lulalaby Jul 28, 2023
6e2769f
nom nom nom
Lulalaby Jul 29, 2023
5fa7f61
lalala :notes:
Lulalaby Jul 29, 2023
1ce849b
*boops you*
Lulalaby Jul 29, 2023
4b9b0a3
aaaa
Lulalaby Jul 29, 2023
b50f149
meow
Lulalaby Jul 29, 2023
cdd618c
docs: fix DiscordThreadChannelMember docs
Lulalaby Aug 4, 2023
d06cd39
feat: rework SnowflakeObject
Lulalaby Aug 4, 2023
3c5a28b
docs: DiscordJson docs fix
Lulalaby Aug 4, 2023
25c192b
docs stuff
Lulalaby Aug 4, 2023
da0dd34
fix: wrong docs scripts
Lulalaby Aug 4, 2023
6587734
fix: things
Lulalaby Aug 4, 2023
b1c23b9
fix: equality checks
Lulalaby Aug 4, 2023
f1c6ff8
Update DiscordMessageApplication.cs
Lulalaby Aug 4, 2023
48b6523
fix: equal guild and message, nullability
Lulalaby Aug 5, 2023
bf00096
docs: add last modified
NyuwBot Aug 5, 2023
3a741f8
chore(actions): remove old docs code & set verbose
NyuwBot Aug 5, 2023
5bcf181
fix(actions): fix docs pr
Lulalaby Aug 5, 2023
3a6f403
Update documentation_test.yml
Lulalaby Aug 5, 2023
f2e9990
fix: things
Lulalaby Aug 5, 2023
6d60fdd
chore: code cleanup
Lulalaby Aug 5, 2023
468f859
code cleanup
Lulalaby Aug 5, 2023
be7c190
Update DiscordConfiguration.cs
Lulalaby Aug 5, 2023
a0ca9a1
Update ContextMenuInteractionCreateEventArgs.cs
Lulalaby Aug 5, 2023
e3b5b9e
change config dependency stuff
Lulalaby Aug 6, 2023
a6409a4
fix: filename
Lulalaby Aug 6, 2023
cd34a52
fix(docs): embed
Lulalaby Aug 8, 2023
94b01ce
Merge branch 'main' into cleanup/nullability-and-other-things
Lulalaby Aug 9, 2023
293c2c1
chore: allow custom status lib-side
Lulalaby Aug 9, 2023
7e2d7b1
Update DiscordClient.Dispatch.cs
Lulalaby Aug 9, 2023
0d252ba
Merge branch 'main' into cleanup/nullability-and-other-things
Lulalaby Aug 9, 2023
caf0ce9
docs: fix code blocks
NyuwBot Aug 12, 2023
0b06c79
Merge branch 'cleanup/nullability-and-other-things' of https://github…
NyuwBot Aug 12, 2023
4d77291
Merge branch 'main' into cleanup/nullability-and-other-things
Lulalaby Aug 15, 2023
c312860
Merge branch 'main' into cleanup/nullability-and-other-things
Lulalaby Aug 31, 2023
5bc0c2f
Update _master.tmpl
Lulalaby Aug 31, 2023
96388f9
fix: stuff
Lulalaby Aug 31, 2023
5862dd7
feat: DiscordGuild IncidentsData (Security Actions)
Lulalaby Sep 1, 2023
08b45b4
Merge branch 'main' into cleanup/nullability-and-other-things
Lulalaby Sep 1, 2023
b08decf
Merge branch 'main' into cleanup/nullability-and-other-things
Lulalaby Sep 1, 2023
eb96c14
Merge branch 'main' into cleanup/nullability-and-other-things
Lulalaby Sep 1, 2023
164287e
Merge branch 'main' into cleanup/nullability-and-other-things
Lulalaby Sep 1, 2023
fdd8392
Merge branch 'main' into cleanup/nullability-and-other-things
Lulalaby Sep 4, 2023
2b55c73
nullability, code cleanup and new stuff
Lulalaby Sep 7, 2023
0ff7c89
nom
Lulalaby Sep 10, 2023
450cd37
docs~
Lulalaby Sep 10, 2023
3c7de4c
feat: PositionalSnowflakeObject
Lulalaby Sep 11, 2023
a05ba93
fix high low
Lulalaby Sep 11, 2023
2534558
some more stuff & replaced ban delete msg day with seconds
Lulalaby Sep 11, 2023
8e5257b
cleanup!
Lulalaby Sep 11, 2023
fa679ff
operators and fixed
Lulalaby Sep 11, 2023
95d140e
fix docs
Lulalaby Sep 11, 2023
82f3238
Added comparison operators for role & member [1:1 & cross]
Lulalaby Sep 11, 2023
7be689d
Update DiscordMember.cs
Lulalaby Sep 11, 2023
e1eac4a
mew
Lulalaby Sep 11, 2023
c7f3053
mew
Lulalaby Sep 11, 2023
03950c9
aaaa
Lulalaby Sep 11, 2023
bd4b57d
Merge branch 'main' into cleanup/nullability-and-other-things
Lulalaby Sep 11, 2023
5649da3
aaa
Lulalaby Sep 12, 2023
41fbac6
Merge branch 'main' into cleanup/nullability-and-other-things
Lulalaby Sep 12, 2023
067f354
skip warning about new audit log types if report missing fields off
Lulalaby Sep 12, 2023
3803257
aaaaaaaaaaaaaa
Lulalaby Sep 12, 2023
db51ae4
feat: discord signed link (experimental)
Lulalaby Sep 12, 2023
dd44178
fix: re-implementation for signed links
Lulalaby Sep 13, 2023
e3284ed
Update DiscordSignedLink.cs
Lulalaby Sep 13, 2023
14da8e7
some more cleanup / fixes
Lulalaby Sep 13, 2023
d39d83b
moar docs
Lulalaby Sep 13, 2023
638a9a4
cleanup :sparkles:
Lulalaby Sep 13, 2023
e651193
Update DiscordGuild.cs
Lulalaby Sep 13, 2023
1840345
fix!: rework attributes for app cmd
Lulalaby Sep 13, 2023
67a521f
feat: application command integration types
Lulalaby Sep 15, 2023
c52ba11
feat!: new DisCatSharp.ApplicationCommands Attributes
Lulalaby Sep 16, 2023
8485521
Merge branch 'main' into cleanup/nullability-and-other-things
Lulalaby Sep 16, 2023
742e9ec
Merge branch 'main' into cleanup/nullability-and-other-things
Lulalaby Sep 18, 2023
d1f405b
fix: pagination issues
Lulalaby Sep 19, 2023
ca599b1
Merge branch 'main' into cleanup/nullability-and-other-things
Lulalaby Sep 19, 2023
2b9c905
Merge branch 'main' into cleanup/nullability-and-other-things
Lulalaby Sep 19, 2023
745030e
feat: default values for select menus
Lulalaby Sep 20, 2023
0418658
chore(deps): bump dotnet
Lulalaby Sep 20, 2023
1e7a06c
Merge branch 'main' into cleanup/nullability-and-other-things
Lulalaby Sep 20, 2023
894167d
chore: remove file license header and fix license
Lulalaby Sep 21, 2023
046703e
Merge branch 'main' into cleanup/nullability-and-other-things
Lulalaby Sep 21, 2023
8cb67f3
Merge branch 'main' into cleanup/nullability-and-other-things
Lulalaby Sep 21, 2023
b3a0213
chore(code-style): enforce new code style
Lulalaby Sep 21, 2023
cd51930
Merge branch 'main' into cleanup/nullability-and-other-things
Lulalaby Sep 21, 2023
7092784
Merge branch 'main' into cleanup/nullability-and-other-things
Lulalaby Sep 21, 2023
cc08ec3
chore(code-style): and again.. and again.. arrrrrrgh
Lulalaby Sep 21, 2023
768272a
Update ApplicationCommandEqualityChecks.cs
Lulalaby Sep 21, 2023
fe6bff6
fix bs
Lulalaby Sep 21, 2023
ae4940c
Merge branch 'main' into cleanup/nullability-and-other-things
Lulalaby Sep 21, 2023
baf8757
?
Lulalaby Sep 21, 2023
36f2a6b
chore(code-cleanup): code cleanup for tools
Lulalaby Sep 21, 2023
ca9f0a7
Merge remote-tracking branch 'origin/main' into cleanup/nullability-a…
Lulalaby Sep 24, 2023
01a73ad
Revert "Merge remote-tracking branch 'origin/main' into cleanup/nulla…
Lulalaby Sep 24, 2023
ff34dac
fix: bad request for scheduled events
Lulalaby Sep 24, 2023
59f0d85
Merge branch 'main' into cleanup/nullability-and-other-things
Lulalaby Sep 24, 2023
fbd790d
Update RestStageInstancePayloads.cs
Lulalaby Sep 24, 2023
59e2161
Merge branch 'main' into cleanup/nullability-and-other-things
Lulalaby Sep 28, 2023
fd095b7
Update DiscordApiClient.cs
Lulalaby Sep 28, 2023
fe2ce7b
Update DiscordSignedLink.cs
Lulalaby Sep 29, 2023
40f7593
Merge branch 'main' into cleanup/nullability-and-other-things
Lulalaby Oct 13, 2023
b2d7d73
Merge branch 'main' into cleanup/nullability-and-other-things
Lulalaby Oct 21, 2023
6f80a08
fix: AvatarDecorationData
Lulalaby Oct 21, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3,993 changes: 3,831 additions & 162 deletions .editorconfig

Large diffs are not rendered by default.

4 changes: 1 addition & 3 deletions .github/workflows/documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,8 @@ jobs:
run: dotnet build -c Release --no-restore -v minimal -f net7.0 DisCatSharp.sln
timeout-minutes: 7
continue-on-error: true
#- name: Add Custom Plugins
# run: cp -R DisCatSharp.Docs/dcs/plugins/* /home/runner/.dotnet/tools/.store/docfx/2.67.0/docfx/2.67.0/tools/net7.0/any/
- name: Build Docs
run: docfx DisCatSharp.Docs/docfx.json
run: docfx DisCatSharp.Docs/docfx.json --logLevel Verbose
- name: Pack Docs
shell: pwsh
run: ./DisCatSharp.Tools/pack-docs.ps1 -DocsPath "./DisCatSharp.Docs" -OutputPath "./" -PackageName "dcs-docs"
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/documentation_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,21 @@ env:
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
DOTNET_CLI_TELEMETRY_OPTOUT: true
DOTNET_SYSTEM_GLOBALIZATION_INVARIANT: true
GH_TOKEN: ${{ github.token }}

jobs:
build:
timeout-minutes: 20
timeout-minutes: 25
runs-on: ubuntu-latest
name: Build documentation
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
token: ${{ secrets.NYUW_TOKEN_GH }}
- name: Checkout PR if nessesary
if: github.event_name == 'pull_request'
run: gh pr checkout ${{ github.event.pull_request.number }}
- name: Setup .NET
uses: actions/[email protected]
with:
Expand All @@ -32,10 +36,8 @@ jobs:
run: dotnet build -c Release -v minimal -f net7.0 --no-restore DisCatSharp.sln
timeout-minutes: 7
continue-on-error: true
#- name: Add Custom Plugins
# run: cp -R DisCatSharp.Docs/dcs/plugins/* /home/runner/.dotnet/tools/.store/docfx/2.67.0/docfx/2.67.0/tools/net7.0/any/
- name: Build Docs
run: docfx DisCatSharp.Docs/docfx.json
run: docfx DisCatSharp.Docs/docfx.json --logLevel Verbose
- name: Pack Docs
shell: pwsh
run: ./DisCatSharp.Tools/pack-docs.ps1 -DocsPath "./DisCatSharp.Docs" -OutputPath "./" -PackageName "dcs-docs-preview"
Expand Down Expand Up @@ -79,8 +81,6 @@ jobs:
run: rm dcs-docs-preview.zip
- name: Add .htaccess
run: rm -f .htaccess && wget https://gist.githubusercontent.com/Lulalaby/8a032d0ddebb9125691094edc67b6593/raw/0c4bf0423cfe334fdd5092b014d2481759dd052a/.htaccess
#- name: Add _redirects
# run: rm -f _redirects && wget https://gist.githubusercontent.com/Lulalaby/0c784680a855fd161411002e3859b4fd/raw/9708d1acfce3f647cbb8da19c2022a20198979fa/_redirects
- name: Set access rights
run: sudo chmod 777 -R .
- name: Commit changes
Expand Down
17 changes: 9 additions & 8 deletions .nuget/NuGet.config
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>

<configuration>
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
</packageSources>
<packageSourceMapping>
<packageSource key="nuget.org">
<package pattern="*" />
</packageSource>
</packageSourceMapping>
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
</packageSources>
<packageSourceMapping>
<packageSource key="nuget.org">
<package pattern="*" />
</packageSource>
</packageSourceMapping>
</configuration>
9 changes: 5 additions & 4 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>

<Project>
<ItemGroup>
<SourceRoot Include="$(MSBuildThisFileDirectory)/"/>
</ItemGroup>
<ItemGroup>
<SourceRoot Include="$(MSBuildThisFileDirectory)/" />
</ItemGroup>
<PropertyGroup>
<!--<CodeAnalysisRuleSet>$(MSBuildThisFileDirectory)/DisCatSharp.Tools/DisCatSharp.ruleset</CodeAnalysisRuleSet>-->
<AccelerateBuildsInVisualStudio>true</AccelerateBuildsInVisualStudio>
<AccelerateBuildsInVisualStudio>true</AccelerateBuildsInVisualStudio>
</PropertyGroup>
</Project>
1,649 changes: 1,024 additions & 625 deletions DisCatSharp.ApplicationCommands/ApplicationCommandsExtension.cs

Large diffs are not rendered by default.

37 changes: 22 additions & 15 deletions DisCatSharp.ApplicationCommands/ApplicationCommandsUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,40 +22,42 @@ internal static bool IsModuleCandidateType(this Type type)
/// <summary>
/// Whether this module is a candidate type.
/// </summary>
/// <param name="ti">The type info.</param>
internal static bool IsModuleCandidateType(this TypeInfo ti)
/// <param name="targetTypeInfo">The type info.</param>
internal static bool IsModuleCandidateType(this TypeInfo targetTypeInfo)
{
if (ApplicationCommandsExtension.DebugEnabled)
ApplicationCommandsExtension.Logger.LogDebug("Checking type {name}", ti.FullName);
ApplicationCommandsExtension.Logger.LogDebug("Checking type {name}", targetTypeInfo.FullName);
// check if compiler-generated
if (ti.GetCustomAttribute<CompilerGeneratedAttribute>(false) != null)
if (targetTypeInfo.GetCustomAttribute<CompilerGeneratedAttribute>(false) != null)
return false;

// check if derives from the required base class
var tmodule = typeof(ApplicationCommandsModule);
var timodule = tmodule.GetTypeInfo();
if (!timodule.IsAssignableFrom(ti))
var type = typeof(ApplicationCommandsModule);
var typeInfo = type.GetTypeInfo();
if (!typeInfo.IsAssignableFrom(targetTypeInfo))
{
if (ApplicationCommandsExtension.DebugEnabled)
ApplicationCommandsExtension.Logger.LogDebug("Not assignable from type");
return false;
}

// check if anonymous
if (ti.IsGenericType && ti.Name.Contains("AnonymousType") && (ti.Name.StartsWith("<>") || ti.Name.StartsWith("VB$")) && (ti.Attributes & TypeAttributes.NotPublic) == TypeAttributes.NotPublic)
if (targetTypeInfo.IsGenericType && targetTypeInfo.Name.Contains("AnonymousType") &&
(targetTypeInfo.Name.StartsWith("<>") || targetTypeInfo.Name.StartsWith("VB$")) &&
(targetTypeInfo.Attributes & TypeAttributes.NotPublic) == TypeAttributes.NotPublic)
{
if (ApplicationCommandsExtension.DebugEnabled)
ApplicationCommandsExtension.Logger.LogDebug("Anonymous");
return false;
}

// check if abstract, static, or not a class
if (!ti.IsClass || ti.IsAbstract)
if (!targetTypeInfo.IsClass || targetTypeInfo.IsAbstract)
return false;

// check if delegate type
var tdelegate = typeof(Delegate).GetTypeInfo();
if (tdelegate.IsAssignableFrom(ti))
var typeDelegate = typeof(Delegate).GetTypeInfo();
if (typeDelegate.IsAssignableFrom(targetTypeInfo))
{
if (ApplicationCommandsExtension.DebugEnabled)
ApplicationCommandsExtension.Logger.LogDebug("Delegated");
Expand All @@ -65,15 +67,16 @@ internal static bool IsModuleCandidateType(this TypeInfo ti)
if (ApplicationCommandsExtension.DebugEnabled)
ApplicationCommandsExtension.Logger.LogDebug("Checking qualifying methods");
// qualifies if any method or type qualifies
return ti.DeclaredMethods.Any(xmi => xmi.IsCommandCandidate(out _)) || ti.DeclaredNestedTypes.Any(xti => xti.IsModuleCandidateType());
return targetTypeInfo.DeclaredMethods.Any(xmi => xmi.IsCommandCandidate(out _)) ||
targetTypeInfo.DeclaredNestedTypes.Any(xti => xti.IsModuleCandidateType());
}

/// <summary>
/// Whether this is a command candidate.
/// </summary>
/// <param name="method">The method.</param>
/// <param name="parameters">The parameters.</param>
internal static bool IsCommandCandidate(this MethodInfo method, out ParameterInfo[] parameters)
internal static bool IsCommandCandidate(this MethodInfo? method, out ParameterInfo[]? parameters)
{
parameters = null;
// check if exists
Expand All @@ -83,6 +86,7 @@ internal static bool IsCommandCandidate(this MethodInfo method, out ParameterInf
ApplicationCommandsExtension.Logger.LogDebug("Not existent");
return false;
}

if (ApplicationCommandsExtension.DebugEnabled)
ApplicationCommandsExtension.Logger.LogDebug("Checking method {name}", method.Name);

Expand All @@ -96,10 +100,13 @@ internal static bool IsCommandCandidate(this MethodInfo method, out ParameterInf

// check if appropriate return and arguments
parameters = method.GetParameters();
if (!parameters.Any() || (parameters.First().ParameterType != typeof(ContextMenuContext) && parameters.First().ParameterType != typeof(InteractionContext)) || method.ReturnType != typeof(Task))
if (!parameters.Any() ||
(parameters.First().ParameterType != typeof(ContextMenuContext) &&
parameters.First().ParameterType != typeof(InteractionContext)) || method.ReturnType != typeof(Task))
{
if (ApplicationCommandsExtension.DebugEnabled)
ApplicationCommandsExtension.Logger.LogDebug("Missing first parameter with type ContextMenuContext or InteractionContext");
ApplicationCommandsExtension.Logger
.LogDebug("Missing first parameter with type ContextMenuContext or InteractionContext");
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ public sealed class ContextMenuAttribute : Attribute
/// <param name="isNsfw">Whether the context menu is marked as NSFW.</param>
/// <param name="allowedContexts">The allowed contexts of the context menu.</param>
/// <param name="integrationTypes">The allowed integration types of the context menu.</param>
public ContextMenuAttribute(ApplicationCommandType type, string name, bool isNsfw = false, ApplicationCommandContexts[]? allowedContexts = null, ApplicationCommandIntegrationTypes[]? integrationTypes = null)
public ContextMenuAttribute(
ApplicationCommandType type, string name, bool isNsfw = false,
ApplicationCommandContexts[]? allowedContexts = null,
ApplicationCommandIntegrationTypes[]? integrationTypes = null
)
{
if (type == ApplicationCommandType.ChatInput)
throw new ArgumentException("Context menus cannot be of type ChatInput (Slash).");
Expand All @@ -69,7 +73,6 @@ public ContextMenuAttribute(ApplicationCommandType type, string name, bool isNsf
this.IntegrationTypes = integrationTypes?.ToList();
}


/// <summary>
/// Marks this method as a context menu.
/// </summary>
Expand All @@ -79,7 +82,11 @@ public ContextMenuAttribute(ApplicationCommandType type, string name, bool isNsf
/// <param name="isNsfw">Whether the context menu is marked as NSFW.</param>
/// <param name="allowedContexts">The allowed contexts of the context menu.</param>
/// <param name="integrationTypes">The allowed integration types of the context menu.</param>
public ContextMenuAttribute(ApplicationCommandType type, string name, long defaultMemberPermissions, bool isNsfw = false, ApplicationCommandContexts[]? allowedContexts = null, ApplicationCommandIntegrationTypes[]? integrationTypes = null)
public ContextMenuAttribute(
ApplicationCommandType type, string name, long defaultMemberPermissions,
bool isNsfw = false, ApplicationCommandContexts[]? allowedContexts = null,
ApplicationCommandIntegrationTypes[]? integrationTypes = null
)
{
if (type == ApplicationCommandType.ChatInput)
throw new ArgumentException("Context menus cannot be of type ChatInput (Slash).");
Expand All @@ -93,7 +100,6 @@ public ContextMenuAttribute(ApplicationCommandType type, string name, long defau
this.IntegrationTypes = integrationTypes?.ToList();
}


/// <summary>
/// Marks this method as context menu.
/// </summary>
Expand All @@ -103,7 +109,11 @@ public ContextMenuAttribute(ApplicationCommandType type, string name, long defau
/// <param name="isNsfw">Whether the context menu is marked as NSFW.</param>
/// <param name="allowedContexts">The allowed contexts of the context menu.</param>
/// <param name="integrationTypes">The allowed integration types of the context menu.</param>
public ContextMenuAttribute(ApplicationCommandType type, string name, bool dmPermission, bool isNsfw = false, ApplicationCommandContexts[]? allowedContexts = null, ApplicationCommandIntegrationTypes[]? integrationTypes = null)
public ContextMenuAttribute(
ApplicationCommandType type, string name, bool dmPermission, bool isNsfw = false,
ApplicationCommandContexts[]? allowedContexts = null,
ApplicationCommandIntegrationTypes[]? integrationTypes = null
)
{
if (type == ApplicationCommandType.ChatInput)
throw new ArgumentException("Context menus cannot be of type ChatInput (Slash).");
Expand All @@ -127,7 +137,12 @@ public ContextMenuAttribute(ApplicationCommandType type, string name, bool dmPer
/// <param name="isNsfw">Whether the context menu is marked as NSFW.</param>
/// <param name="allowedContexts">The allowed contexts of the context menu.</param>
/// <param name="integrationTypes">The allowed integration types of the context menu.</param>
public ContextMenuAttribute(ApplicationCommandType type, string name, long defaultMemberPermissions, bool dmPermission, bool isNsfw = false, ApplicationCommandContexts[]? allowedContexts = null, ApplicationCommandIntegrationTypes[]? integrationTypes = null)
public ContextMenuAttribute(
ApplicationCommandType type, string name, long defaultMemberPermissions,
bool dmPermission, bool isNsfw = false,
ApplicationCommandContexts[]? allowedContexts = null,
ApplicationCommandIntegrationTypes[]? integrationTypes = null
)
{
if (type == ApplicationCommandType.ChatInput)
throw new ArgumentException("Context menus cannot be of type ChatInput (Slash).");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ namespace DisCatSharp.ApplicationCommands.Attributes;
/// Defines a cooldown for this command. This allows you to define how many times can users execute a specific command
/// </summary>
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, AllowMultiple = true, Inherited = false)]
public sealed class ContextMenuCooldownAttribute : ApplicationCommandCheckBaseAttribute, ICooldown<BaseContext, ContextMenuCooldownBucket>
public sealed class ContextMenuCooldownAttribute : ApplicationCommandCheckBaseAttribute,
ICooldown<BaseContext, ContextMenuCooldownBucket>
{
/// <summary>
/// Gets the maximum number of uses before this command triggers a cooldown for its bucket.
Expand Down Expand Up @@ -45,7 +46,7 @@ public ContextMenuCooldownAttribute(int maxUses, double resetAfter, CooldownBuck
this.MaxUses = maxUses;
this.Reset = TimeSpan.FromSeconds(resetAfter);
this.BucketType = bucketType;
this.Buckets = new ConcurrentDictionary<string, ContextMenuCooldownBucket>();
this.Buckets = new();
}

/// <summary>
Expand All @@ -68,7 +69,11 @@ public ContextMenuCooldownBucket GetBucket(BaseContext ctx)
public TimeSpan GetRemainingCooldown(BaseContext ctx)
{
var bucket = this.GetBucket(ctx);
return bucket == null ? TimeSpan.Zero : bucket.RemainingUses > 0 ? TimeSpan.Zero : bucket.ResetsAt - DateTimeOffset.UtcNow;
return bucket == null
? TimeSpan.Zero
: bucket.RemainingUses > 0
? TimeSpan.Zero
: bucket.ResetsAt - DateTimeOffset.UtcNow;
}

/// <summary>
Expand Down Expand Up @@ -108,7 +113,7 @@ public override async Task<bool> ExecuteChecksAsync(BaseContext ctx)
var bid = this.GetBucketId(ctx, out var usr, out var chn, out var gld);
if (!this.Buckets.TryGetValue(bid, out var bucket))
{
bucket = new ContextMenuCooldownBucket(this.MaxUses, this.Reset, usr, chn, gld);
bucket = new(this.MaxUses, this.Reset, usr, chn, gld);
this.Buckets.AddOrUpdate(bid, bucket, (k, v) => bucket);
}

Expand All @@ -121,10 +126,12 @@ public override async Task<bool> ExecuteChecksAsync(BaseContext ctx)
/// </summary>
public sealed class ContextMenuCooldownBucket : CooldownBucket
{
internal ContextMenuCooldownBucket(int maxUses, TimeSpan resetAfter, ulong userId = 0, ulong channelId = 0, ulong guildId = 0)
internal ContextMenuCooldownBucket(
int maxUses, TimeSpan resetAfter, ulong userId = 0, ulong channelId = 0,
ulong guildId = 0
)
: base(maxUses, resetAfter, userId, channelId, guildId)
{
}
{ }

/// <summary>
/// Returns a string representation of this command cooldown bucket.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ namespace DisCatSharp.ApplicationCommands.Attributes;
/// <summary>
/// Defines that this application command is restricted to the owner of the bot.
/// </summary>
[Deprecated("This is deprecated and will be remove in future in favor of RequireTeamXY"), AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, Inherited = false)]
[Deprecated("This is deprecated and will be remove in future in favor of RequireTeamXY"),
AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, Inherited = false)]
public sealed class ApplicationCommandRequireOwnerAttribute : ApplicationCommandCheckBaseAttribute
{
/// <summary>
Expand All @@ -28,6 +29,8 @@ public override Task<bool> ExecuteChecksAsync(BaseContext ctx)
var app = ctx.Client.CurrentApplication!;
var me = ctx.Client.CurrentUser!;

return app != null ? Task.FromResult(app.Members.Any(x => x.Id == ctx.User.Id)) : Task.FromResult(ctx.User.Id == me.Id);
return app != null
? Task.FromResult(app.Members.Any(x => x.Id == ctx.User.Id))
: Task.FromResult(ctx.User.Id == me.Id);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ namespace DisCatSharp.ApplicationCommands.Attributes;
/// <summary>
/// Requires ownership of the bot or a whitelisted id to execute this command.
/// </summary>
[Deprecated("This is deprecated and will be remove in future in favor of RequireTeamXY"), AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, Inherited = false)]
[Deprecated("This is deprecated and will be remove in future in favor of RequireTeamXY"),
AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, Inherited = false)]
public sealed class ApplicationCommandRequireOwnerOrIdAttribute : ApplicationCommandCheckBaseAttribute
{
/// <summary>
Expand All @@ -39,7 +40,9 @@ public override Task<bool> ExecuteChecksAsync(BaseContext ctx)
var app = ctx.Client.CurrentApplication!;
var me = ctx.Client.CurrentUser!;

var owner = app != null ? Task.FromResult(app.Members.Any(x => x.Id == ctx.User.Id)) : Task.FromResult(ctx.User.Id == me.Id);
var owner = app != null
? Task.FromResult(app.Members.Any(x => x.Id == ctx.User.Id))
: Task.FromResult(ctx.User.Id == me.Id);

var allowed = this.UserIds.Contains(ctx.User.Id);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,13 @@ public override async Task<bool> ExecuteChecksAsync(BaseContext ctx)
var usr = ctx.Member;
if (usr == null)
return false;

var pusr = ctx.Channel.PermissionsFor(usr);

var bot = await ctx.Guild.GetMemberAsync(ctx.Client.CurrentUser.Id).ConfigureAwait(false);
if (bot == null)
return false;

var pbot = ctx.Channel.PermissionsFor(bot);

var usrok = ctx.Guild.OwnerId == usr.Id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public override Task<bool> ExecuteChecksAsync(BaseContext ctx)
return Task.FromResult(app.Owner.Id == ctx.User.Id);

var teamMember = app.Team?.Members.FirstOrDefault(x => x.User.Id == ctx.User.Id);
return teamMember == null ? Task.FromResult(false) : Task.FromResult(teamMember.Role is "developer" or "admin" or "owner");
return teamMember == null
? Task.FromResult(false)
: Task.FromResult(teamMember.Role is "developer" or "admin" or "owner");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public ApplicationCommandRequireTeamMemberAttribute()
public override Task<bool> ExecuteChecksAsync(BaseContext ctx)
{
var app = ctx.Client.CurrentApplication!;
return app.Team is null ? Task.FromResult(app.Owner.Id == ctx.User.Id) : Task.FromResult(app.Members.Any(x => x.Id == ctx.User.Id));
return app.Team is null
? Task.FromResult(app.Owner.Id == ctx.User.Id)
: Task.FromResult(app.Members.Any(x => x.Id == ctx.User.Id));
}
}
Loading
Loading