-
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!: new DisCatSharp.ApplicationCommands Attributes
- Added ApplicationCommandRequireTeamMember - Added ApplicationCommandRequireTeamReadOnly - Added ApplicationCommandRequireTeamDeveloper - Added ApplicationCommandRequireTeamAdmin - Added ApplicationCommandRequireTeamOwner - Added ApplicationCommandRequireGuildOwner - Deprecated ApplicationCommandRequireOwner - Deprecated ApplicationCommandRequireOwnerOrId
- Loading branch information
Showing
8 changed files
with
330 additions
and
9 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
DisCatSharp.ApplicationCommands/Attributes/RequireGuildOwnerAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// This file is part of the DisCatSharp project. | ||
// | ||
// Copyright (c) 2021-2023 AITSYS | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in all | ||
// copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
// SOFTWARE. | ||
|
||
using System; | ||
using System.Threading.Tasks; | ||
|
||
using DisCatSharp.ApplicationCommands.Context; | ||
|
||
namespace DisCatSharp.ApplicationCommands.Attributes; | ||
|
||
/// <summary> | ||
/// Defines that this application command is only usable within a guild by its owner. | ||
/// </summary> | ||
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, Inherited = false)] | ||
public sealed class ApplicationCommandRequireGuildOwnerAttributeAttribute : ApplicationCommandCheckBaseAttribute | ||
{ | ||
/// <summary> | ||
/// Defines that this command is only usable within a guild by its owner. | ||
/// </summary> | ||
public ApplicationCommandRequireGuildOwnerAttributeAttribute() | ||
{ } | ||
|
||
/// <summary> | ||
/// Runs checks. | ||
/// </summary> | ||
public override Task<bool> ExecuteChecksAsync(BaseContext ctx) | ||
=> Task.FromResult(ctx.Guild is not null && ctx.Guild.OwnerId == ctx.User.Id); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
DisCatSharp.ApplicationCommands/Attributes/RequireTeamAdmin.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// This file is part of the DisCatSharp project. | ||
// | ||
// Copyright (c) 2021-2023 AITSYS | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in all | ||
// copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
// SOFTWARE. | ||
|
||
using System; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
|
||
using DisCatSharp.ApplicationCommands.Context; | ||
|
||
namespace DisCatSharp.ApplicationCommands.Attributes; | ||
|
||
/// <summary> | ||
/// Defines that this application command is restricted to team members of the bot with admin role or higher. | ||
/// </summary> | ||
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, Inherited = false)] | ||
public sealed class ApplicationCommandRequireTeamAdminAttribute : ApplicationCommandCheckBaseAttribute | ||
{ | ||
/// <summary> | ||
/// Defines that this application command is restricted to team members of the bot with admin role or higher. | ||
/// </summary> | ||
public ApplicationCommandRequireTeamAdminAttribute() | ||
{ } | ||
|
||
/// <summary> | ||
/// Runs checks. | ||
/// </summary> | ||
public override Task<bool> ExecuteChecksAsync(BaseContext ctx) | ||
{ | ||
var app = ctx.Client.CurrentApplication!; | ||
if (app.Team is null) | ||
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 "admin" or "owner"); | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
DisCatSharp.ApplicationCommands/Attributes/RequireTeamDeveloper.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// This file is part of the DisCatSharp project. | ||
// | ||
// Copyright (c) 2021-2023 AITSYS | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in all | ||
// copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
// SOFTWARE. | ||
|
||
using System; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
|
||
using DisCatSharp.ApplicationCommands.Context; | ||
|
||
namespace DisCatSharp.ApplicationCommands.Attributes; | ||
|
||
/// <summary> | ||
/// Defines that this application command is restricted to team members of the bot with developer role or higher. | ||
/// </summary> | ||
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, Inherited = false)] | ||
public sealed class ApplicationCommandRequireTeamDeveloperAttribute : ApplicationCommandCheckBaseAttribute | ||
{ | ||
/// <summary> | ||
/// Defines that this application command is restricted to team members of the bot with developer role or higher. | ||
/// </summary> | ||
public ApplicationCommandRequireTeamDeveloperAttribute() | ||
{ } | ||
|
||
/// <summary> | ||
/// Runs checks. | ||
/// </summary> | ||
public override Task<bool> ExecuteChecksAsync(BaseContext ctx) | ||
{ | ||
var app = ctx.Client.CurrentApplication!; | ||
if (app.Team is null) | ||
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"); | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
DisCatSharp.ApplicationCommands/Attributes/RequireTeamMember.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// This file is part of the DisCatSharp project. | ||
// | ||
// Copyright (c) 2021-2023 AITSYS | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in all | ||
// copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
// SOFTWARE. | ||
|
||
using System; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
|
||
using DisCatSharp.ApplicationCommands.Context; | ||
|
||
namespace DisCatSharp.ApplicationCommands.Attributes; | ||
|
||
/// <summary> | ||
/// Defines that this application command is restricted to the team members of the bot. | ||
/// </summary> | ||
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, Inherited = false)] | ||
public sealed class ApplicationCommandRequireTeamMemberAttribute : ApplicationCommandCheckBaseAttribute | ||
{ | ||
/// <summary> | ||
/// Defines that this application command is restricted to the team members of the bot. | ||
/// </summary> | ||
public ApplicationCommandRequireTeamMemberAttribute() | ||
{ } | ||
|
||
/// <summary> | ||
/// Runs checks. | ||
/// </summary> | ||
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)); | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
DisCatSharp.ApplicationCommands/Attributes/RequireTeamOwner.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// This file is part of the DisCatSharp project. | ||
// | ||
// Copyright (c) 2021-2023 AITSYS | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in all | ||
// copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
// SOFTWARE. | ||
|
||
using System; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
|
||
using DisCatSharp.ApplicationCommands.Context; | ||
|
||
namespace DisCatSharp.ApplicationCommands.Attributes; | ||
|
||
/// <summary> | ||
/// Defines that this application command is restricted to team members of the bot with owner role. | ||
/// </summary> | ||
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, Inherited = false)] | ||
public sealed class ApplicationCommandRequireTeamOwnerAttribute : ApplicationCommandCheckBaseAttribute | ||
{ | ||
/// <summary> | ||
/// Defines that this application command is restricted to team members of the bot with owner role. | ||
/// </summary> | ||
public ApplicationCommandRequireTeamOwnerAttribute() | ||
{ } | ||
|
||
/// <summary> | ||
/// Runs checks. | ||
/// </summary> | ||
public override Task<bool> ExecuteChecksAsync(BaseContext ctx) | ||
{ | ||
var app = ctx.Client.CurrentApplication!; | ||
if (app.Team is null) | ||
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 "owner"); | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
DisCatSharp.ApplicationCommands/Attributes/RequireTeamReadOnly.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// This file is part of the DisCatSharp project. | ||
// | ||
// Copyright (c) 2021-2023 AITSYS | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in all | ||
// copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
// SOFTWARE. | ||
|
||
using System; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
|
||
using DisCatSharp.ApplicationCommands.Context; | ||
|
||
namespace DisCatSharp.ApplicationCommands.Attributes; | ||
|
||
/// <summary> | ||
/// Defines that this application command is restricted to team members of the bot with read-only role or higher. | ||
/// </summary> | ||
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, Inherited = false)] | ||
public sealed class ApplicationCommandRequireTeamReadOnlyAttribute : ApplicationCommandCheckBaseAttribute | ||
{ | ||
/// <summary> | ||
/// Defines that this application command is restricted to team members of the bot with read-only role or higher. | ||
/// </summary> | ||
public ApplicationCommandRequireTeamReadOnlyAttribute() | ||
{ } | ||
|
||
/// <summary> | ||
/// Runs checks. | ||
/// </summary> | ||
public override Task<bool> ExecuteChecksAsync(BaseContext ctx) | ||
{ | ||
var app = ctx.Client.CurrentApplication!; | ||
if (app.Team is null) | ||
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 "read-only" or "developer" or "admin" or "owner"); | ||
} | ||
} |