Skip to content

Commit

Permalink
feat: hybrid commands
Browse files Browse the repository at this point in the history
  • Loading branch information
TheXorog authored and Lulalaby committed Jul 5, 2023
1 parent fc2839f commit f8975b2
Show file tree
Hide file tree
Showing 18 changed files with 1,890 additions and 0 deletions.
14 changes: 14 additions & 0 deletions DisCatSharp.HybridCommands/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Remove the line below if you want to inherit .editorconfig settings from higher directories
root = false

#### Core EditorConfig Options ####

# All files
[*]

# General
charset = utf-8
trim_trailing_whitespace = true

[*.cs]
file_header_template = This file is part of the DisCatSharp project.\n\nCopyright (c) 2023 AITSYS\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the "Software"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.
110 changes: 110 additions & 0 deletions DisCatSharp.HybridCommands/Attributes/HybridCommandAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
// This file is part of the DisCatSharp project, based off DSharpPlus.
//
// Copyright (c) 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 DisCatSharp.Enums;

namespace DisCatSharp.HybridCommands.Attributes;

/// <summary>
/// Marks this method as a hybrid command
/// </summary>
[AttributeUsage(AttributeTargets.Method)]
public class HybridCommandAttribute : Attribute
{
/// <summary>
/// Gets the name of this command
/// </summary>
public string Name { get; set; }

/// <summary>
/// Gets the description of this command
/// </summary>
public string Description { get; set; }

/// <summary>
/// Gets the needed permission of this command
/// </summary>
public Permissions? DefaultMemberPermissions { get; set; }

/// <summary>
/// Gets the dm permission of this command
/// </summary>
public bool? DmPermission { get; set; }

/// <summary>
/// Gets whether this command is marked as NSFW
/// </summary>
public bool IsNsfw { get; set; }

/// <summary>
/// Marks this method as hybrid command.
/// </summary>
/// <param name="name">The name of this hybrid command.</param>
/// <param name="description">The description of this hybrid command.</param>
/// <param name="defaultMemberPermissions">
/// <para>The default permissions required for execution.</para>
/// <para>This can be overriden by a guild and is not enforced via prefix commands.</para>
/// </param>
/// <param name="dmPermission">Whether this command should be available in direct messages.</param>
/// <param name="isNsfw">
/// <para>Whether this command should be marked as nsfw.</para>
/// <para>Does not protect this command from being ran as prefix command from users under 18.</para>
/// </param>
public HybridCommandAttribute(string name, string description, Permissions? defaultMemberPermissions = null, bool dmPermission = true, bool isNsfw = false)
{
this.Name = name;
this.Description = description;
this.DefaultMemberPermissions = defaultMemberPermissions;
this.DmPermission = dmPermission;
this.IsNsfw = isNsfw;
}

/// <summary>
/// Marks this method as hybrid command.
/// </summary>
/// <param name="name">The name of this hybrid command.</param>
/// <param name="description">The description of this hybrid command.</param>
/// <param name="dmPermission">Whether this command should be available in direct messages.</param>
/// <param name="isNsfw">
/// <para>Whether this command should be marked as nsfw.</para>
/// <para>Does not protect this command from being ran as prefix command from users under 18.</para>
/// </param>
public HybridCommandAttribute(string name, string description, bool dmPermission, bool isNsfw = false)
{
this.Name = name;
this.Description = description;
this.DmPermission = dmPermission;
this.IsNsfw = isNsfw;
}

/// <summary>
/// Marks this method as hybrid command.
/// </summary>
/// <param name="name">The name of this hybrid command.</param>
/// <param name="description">The description of this hybrid command.</param>
public HybridCommandAttribute(string name, string description)
{
this.Name = name;
this.Description = description;
}
}
58 changes: 58 additions & 0 deletions DisCatSharp.HybridCommands/Attributes/OptionAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// This file is part of the DisCatSharp project, based off DSharpPlus.
//
// Copyright (c) 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;

namespace DisCatSharp.HybridCommands.Attributes;

/// <summary>
/// Marks this parameter as an option for a hybrid command
/// </summary>
[AttributeUsage(AttributeTargets.Parameter)]
public class OptionAttribute : Attribute
{
/// <summary>
/// Gets the name of this option.
/// </summary>
public string Name;

/// <summary>
/// Gets the description of this option.
/// </summary>
public string Description;

/// <summary>
/// Initializes a new instance of the <see cref="OptionAttribute"/> class.
/// </summary>
/// <param name="name">The name.</param>
/// <param name="description">The description.</param>
public OptionAttribute(string name, string description)
{
if (name.Length > 32)
throw new ArgumentException("Hybrid command option names cannot go over 32 characters.");
else if (description.Length > 100)
throw new ArgumentException("Hybrid command option descriptions cannot go over 100 characters.");

this.Name = name.ToLower();
this.Description = description;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// This file is part of the DisCatSharp project, based off DSharpPlus.
//
// Copyright (c) 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 DisCatSharp.HybridCommands.Enums;

namespace DisCatSharp.HybridCommands.Attributes;

/// <summary>
/// Restricts a hybrid command to be only executable by certain execution types.
/// </summary>
[AttributeUsage(AttributeTargets.Method)]
public class RestrictedExecutionTypesAttribute : Attribute
{
/// <summary>
/// Gets which execution types are allowed for this hybrid command.
/// </summary>
public HybridExecutionType[] Types { get; set; }

/// <summary>
/// Restricts a hybrid command to be only executable by certain execution types.
/// </summary>
/// <param name="allowedTypes">The types of execution that are allowed.</param>
public RestrictedExecutionTypesAttribute(params HybridExecutionType[] allowedTypes)
{
this.Types = allowedTypes;
}
}
Loading

0 comments on commit f8975b2

Please sign in to comment.