Skip to content

Commit

Permalink
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
Lulalaby committed Sep 17, 2021
1 parent 6831126 commit e9d7aef
Show file tree
Hide file tree
Showing 7 changed files with 393 additions and 1 deletion.
@@ -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);
}
}
}
@@ -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);
}
}
}
8 changes: 7 additions & 1 deletion DisCatSharp/Clients/BaseDiscordClient.cs
Expand Up @@ -54,7 +54,7 @@ public abstract class BaseDiscordClient : IDisposable
public ILogger<BaseDiscordClient> Logger { get; }

/// <summary>
/// Gets the string representing the version of lib.
/// Gets the string representing the version of bot lib.
/// </summary>
public string VersionString { get; }

Expand All @@ -63,6 +63,12 @@ public abstract class BaseDiscordClient : IDisposable
/// </summary>
public string BotLibrary { get; }

/// <summary>
/// Gets the library team.
/// </summary>
public DisCatSharpTeam LibraryDeveloperTeam
=> this.ApiClient.GetDisCatSharpTeamAsync().Result;

/// <summary>
/// Gets the current user.
/// </summary>
Expand Down
6 changes: 6 additions & 0 deletions DisCatSharp/Clients/DiscordShardedClient.cs
Expand Up @@ -72,6 +72,12 @@ public sealed partial class DiscordShardedClient
/// </summary>
public DiscordApplication CurrentApplication { get; private set; }

/// <summary>
/// Gets the library team.
/// </summary>
public DisCatSharpTeam LibraryDeveloperTeam
=> this.GetShard(0).LibraryDeveloperTeam;

/// <summary>
/// Gets the list of available voice regions. Note that this property will not contain VIP voice regions.
/// </summary>
Expand Down
123 changes: 123 additions & 0 deletions DisCatSharp/Entities/DCS/DisCatSharpTeam.cs
@@ -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() { }
}
}
92 changes: 92 additions & 0 deletions DisCatSharp/Entities/DCS/DisCatSharpTeamMember.cs
@@ -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() { }
}
}

0 comments on commit e9d7aef

Please sign in to comment.