Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Extend DisCatSharp
+ Added attribute "RequireDisCatSharpDeveloper" to DisCatSharp.CommandsNext & DisCatSharp.ApplicationCommands in SlashCommands + Added LibraryDeveloperTeam Entity to DiscordClient & DiscordShardedClient
- Loading branch information
Showing
7 changed files
with
393 additions
and
1 deletion.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
...Sharp.ApplicationCommands/Attributes/SlashCommand/RequireDisCatSharpDeveloperAttribute.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,50 @@ | ||
// This file is part of the DisCatSharp project, a fork of DSharpPlus. | ||
// | ||
// Copyright (c) 2021 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 NONINFRINGEMENT. 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; | ||
|
||
namespace DisCatSharp.ApplicationCommands.Attributes | ||
{ | ||
/// <summary> | ||
/// Defines that this application command is restricted to the owner of the bot. | ||
/// </summary> | ||
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, AllowMultiple = false, Inherited = false)] | ||
public sealed class ApplicationCommandRequireDisCatSharpDeveloperAttribute : SlashCheckBaseAttribute | ||
{ | ||
/// <summary> | ||
/// Defines that this application command is restricted to the owner of the bot. | ||
/// </summary> | ||
public ApplicationCommandRequireDisCatSharpDeveloperAttribute() | ||
{ } | ||
|
||
/// <summary> | ||
/// Runs checks. | ||
/// </summary> | ||
public override Task<bool> ExecuteChecksAsync(InteractionContext ctx) | ||
{ | ||
var team = ctx.Client.LibraryDeveloperTeam.Developers; | ||
return team != null ? Task.FromResult(team.Where(x => x.Id == ctx.User.Id).Any()) : Task.FromResult(false); | ||
} | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
DisCatSharp.CommandsNext/Attributes/RequireDisCatSharpDeveloperAttribute.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,46 @@ | ||
// This file is part of the DisCatSharp project. | ||
// | ||
// Copyright (c) 2021 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 NONINFRINGEMENT. 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; | ||
|
||
namespace DisCatSharp.CommandsNext.Attributes | ||
{ | ||
/// <summary> | ||
/// Defines that usage of this command is restricted to boosters. | ||
/// </summary> | ||
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, AllowMultiple = false, Inherited = false)] | ||
public sealed class RequireDisCatSharpDeveloperAttribute : CheckBaseAttribute | ||
{ | ||
/// <summary> | ||
/// Executes the a check. | ||
/// </summary> | ||
/// <param name="ctx">The command context.</param> | ||
/// <param name="help">If true, help - returns true.</param> | ||
public override async Task<bool> ExecuteCheckAsync(CommandContext ctx, bool help) | ||
{ | ||
var team = ctx.Client.LibraryDeveloperTeam.Developers; | ||
return team != null ? await Task.FromResult(team.Where(x => x.Id == ctx.User.Id).Any()) : await Task.FromResult(false); | ||
} | ||
} | ||
} |
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
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,123 @@ | ||
// This file is part of the DisCatSharp project, a fork of DSharpPlus. | ||
// | ||
// Copyright (c) 2021 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 NONINFRINGEMENT. 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.Collections.Generic; | ||
using System.Globalization; | ||
using DisCatSharp.Enums.Discord; | ||
using DisCatSharp.Net; | ||
|
||
namespace DisCatSharp.Entities | ||
{ | ||
/// <summary> | ||
/// The DisCatSharp team. | ||
/// </summary> | ||
public sealed class DisCatSharpTeam : SnowflakeObject | ||
{ | ||
/// <summary> | ||
/// Gets the team name. | ||
/// </summary> | ||
public string TeamName { get; internal set; } | ||
|
||
/// <summary> | ||
/// Gets the teams's icon. | ||
/// </summary> | ||
public string Icon | ||
=> !string.IsNullOrWhiteSpace(this.IconHash) ? $"{DiscordDomain.GetDomain(CoreDomain.DiscordCdn).Url}{Endpoints.TEAM_ICONS}/{this.Id.ToString(CultureInfo.InvariantCulture)}/{this.IconHash}.png?size=1024" : null; | ||
|
||
/// <summary> | ||
/// Gets the team's icon hash. | ||
/// </summary> | ||
public string IconHash { get; internal set; } | ||
|
||
/// <summary> | ||
/// Gets the teams's logo. | ||
/// </summary> | ||
public string Logo | ||
=> !string.IsNullOrWhiteSpace(this.LogoHash) ? $"{DiscordDomain.GetDomain(CoreDomain.DiscordCdn).Url}{Endpoints.ICONS}/{this.GuildId.ToString(CultureInfo.InvariantCulture)}/{this.LogoHash}.png?size=1024" : null; | ||
|
||
/// <summary> | ||
/// Gets the team's logo hash. | ||
/// </summary> | ||
public string LogoHash { get; internal set; } | ||
|
||
/// <summary> | ||
/// Gets the teams's banner. | ||
/// </summary> | ||
public string Banner | ||
=> !string.IsNullOrWhiteSpace(this.BannerHash) ? $"{DiscordDomain.GetDomain(CoreDomain.DiscordCdn).Url}{Endpoints.BANNERS}/{this.GuildId.ToString(CultureInfo.InvariantCulture)}/{this.BannerHash}.png?size=1024" : null; | ||
|
||
/// <summary> | ||
/// Gets the team's banner hash. | ||
/// </summary> | ||
public string BannerHash { get; internal set; } | ||
|
||
/// <summary> | ||
/// Gets the team's docs url. | ||
/// </summary> | ||
public string DocsUrl { get; internal set; } | ||
|
||
/// <summary> | ||
/// Gets the team's repo url. | ||
/// </summary> | ||
public string RepoUrl { get; internal set; } | ||
|
||
/// <summary> | ||
/// Gets the team's terms of service url. | ||
/// </summary> | ||
public string TermsOfServiceUrl { get; internal set; } | ||
|
||
/// <summary> | ||
/// Gets the team's privacy policy url. | ||
/// </summary> | ||
public string PrivacyPolicyUrl { get; internal set; } | ||
|
||
/// <summary> | ||
/// Get's the team's guild id | ||
/// </summary> | ||
public ulong GuildId { get; internal set; } | ||
|
||
/// <summary> | ||
/// Gets the team's developers. | ||
/// </summary> | ||
public IReadOnlyList<DisCatSharpTeamMember> Developers { get; internal set; } | ||
|
||
/// <summary> | ||
/// Gets the team's owner. | ||
/// </summary> | ||
public DisCatSharpTeamMember Owner { get; internal set; } | ||
|
||
/// <summary> | ||
/// Gets the team's guild. | ||
/// </summary> | ||
public DiscordGuild Guild { get; internal set; } | ||
|
||
/// <summary> | ||
/// Gets the team's support invite. | ||
/// </summary> | ||
public DiscordInvite SupportInvite { get; internal set; } | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="DisCatSharpTeam"/> class. | ||
/// </summary> | ||
internal DisCatSharpTeam() { } | ||
} | ||
} |
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,92 @@ | ||
// This file is part of the DisCatSharp project, a fork of DSharpPlus. | ||
// | ||
// Copyright (c) 2021 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 NONINFRINGEMENT. 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.Globalization; | ||
using DisCatSharp.Enums.Discord; | ||
using DisCatSharp.Net; | ||
using Newtonsoft.Json; | ||
|
||
namespace DisCatSharp.Entities | ||
{ | ||
/// <summary> | ||
/// Represents a DisCatSharp team member. | ||
/// </summary> | ||
public sealed class DisCatSharpTeamMember : SnowflakeObject | ||
{ | ||
/// <summary> | ||
/// Gets this user's username. | ||
/// </summary> | ||
public string Username { get; internal set; } | ||
|
||
/// <summary> | ||
/// Gets the user's 4-digit discriminator. | ||
/// </summary> | ||
public string Discriminator { get; internal set; } | ||
|
||
/// <summary> | ||
/// Gets the discriminator integer. | ||
/// </summary> | ||
internal int DiscriminatorInt | ||
=> int.Parse(this.Discriminator, NumberStyles.Integer, CultureInfo.InvariantCulture); | ||
|
||
/// <summary> | ||
/// Gets the user's banner color, if set. Mutually exclusive with <see cref="BannerHash"/>. | ||
/// </summary> | ||
public DiscordColor? BannerColor | ||
=> !this._bannerColor.HasValue ? null : new DiscordColor(this._bannerColor.Value); | ||
|
||
internal int? _bannerColor; | ||
|
||
/// <summary> | ||
/// Gets the user's banner url | ||
/// </summary> | ||
public string BannerUrl | ||
=> string.IsNullOrWhiteSpace(this.BannerHash) ? null : $"{DiscordDomain.GetDomain(CoreDomain.DiscordCdn).Url}{Endpoints.BANNERS}/{this.Id.ToString(CultureInfo.InvariantCulture)}/{this.BannerHash}.{(this.BannerHash.StartsWith("a_") ? "gif" : "png")}?size=4096"; | ||
|
||
/// <summary> | ||
/// Gets the user's profile banner hash. Mutually exclusive with <see cref="BannerColor"/>. | ||
/// </summary> | ||
public string BannerHash { get; internal set; } | ||
|
||
/// <summary> | ||
/// Gets the user's avatar hash. | ||
/// </summary> | ||
public string AvatarHash { get; internal set; } | ||
|
||
/// <summary> | ||
/// Gets the user's avatar URL. | ||
/// </summary> | ||
public string AvatarUrl | ||
=> string.IsNullOrWhiteSpace(this.AvatarHash) ? this.DefaultAvatarUrl : $"{DiscordDomain.GetDomain(CoreDomain.DiscordCdn).Url}{Endpoints.AVATARS}/{this.Id.ToString(CultureInfo.InvariantCulture)}/{this.AvatarHash}.{(this.AvatarHash.StartsWith("a_") ? "gif" : "png")}?size=1024"; | ||
|
||
/// <summary> | ||
/// Gets the URL of default avatar for this user. | ||
/// </summary> | ||
public string DefaultAvatarUrl | ||
=> $"{DiscordDomain.GetDomain(CoreDomain.DiscordCdn).Url}{Endpoints.EMBED}{Endpoints.AVATARS}/{(this.DiscriminatorInt % 5).ToString(CultureInfo.InvariantCulture)}.png?size=1024"; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="DisCatSharpTeamMember"/> class. | ||
/// </summary> | ||
internal DisCatSharpTeamMember() { } | ||
} | ||
} |
Oops, something went wrong.