diff --git a/DisCatSharp.ApplicationCommands/Attributes/ApplicationCommandModuleLifespanAttribute.cs b/DisCatSharp.ApplicationCommands/Attributes/ApplicationCommandModuleLifespanAttribute.cs deleted file mode 100644 index 11bbe81b8..000000000 --- a/DisCatSharp.ApplicationCommands/Attributes/ApplicationCommandModuleLifespanAttribute.cs +++ /dev/null @@ -1,69 +0,0 @@ -// 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; - -namespace DisCatSharp.ApplicationCommands -{ - - /// - /// Defines this application command module's lifespan. Module lifespans are transient by default. - /// - [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)] - public class ApplicationCommandModuleLifespanAttribute : Attribute - { - /// - /// Gets the lifespan. - /// - public ApplicationCommandModuleLifespan Lifespan { get; } - - /// - /// Defines this application command module's lifespan. - /// - /// The lifespan of the module. Module lifespans are transient by default. - public ApplicationCommandModuleLifespanAttribute(ApplicationCommandModuleLifespan lifespan) - { - this.Lifespan = lifespan; - } - } - - /// - /// Represents a application command module lifespan. - /// - public enum ApplicationCommandModuleLifespan - { - /// - /// Whether this module should be initiated every time a command is run, with dependencies injected from a scope. - /// - Scoped, - - /// - /// Whether this module should be initiated every time a command is run. - /// - Transient, - - /// - /// Whether this module should be initiated at startup. - /// - Singleton - } -} diff --git a/DisCatSharp.ApplicationCommands/Attributes/ContextMenu/ContextMenuAttribute.cs b/DisCatSharp.ApplicationCommands/Attributes/ContextMenu/ContextMenuAttribute.cs deleted file mode 100644 index 4c7b5d335..000000000 --- a/DisCatSharp.ApplicationCommands/Attributes/ContextMenu/ContextMenuAttribute.cs +++ /dev/null @@ -1,66 +0,0 @@ -// 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 DisCatSharp.Enums; - -namespace DisCatSharp.ApplicationCommands -{ - - /// - /// Marks this method as a context menu. - /// - [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] - public sealed class ContextMenuAttribute : Attribute - { - /// - /// Gets the name of this context menu. - /// - public string Name { get; internal set; } - - /// - /// Gets the type of this context menu. - /// - public ApplicationCommandType Type { get; internal set; } - - /// - /// Gets whether this command is enabled by default. - /// - public bool DefaultPermission { get; internal set;} - - /// - /// Marks this method as a context menu. - /// - /// The type of the context menu. - /// The name of the context menu. - /// The default permission of the context menu. - public ContextMenuAttribute(ApplicationCommandType type, string name, bool defaultPermission = true) - { - if (type == ApplicationCommandType.ChatInput) - throw new ArgumentException("Context menus cannot be of type ChatInput (Slash)."); - - this.Type = type; - this.Name = name; - this.DefaultPermission = defaultPermission; - } - } -} diff --git a/DisCatSharp.ApplicationCommands/Attributes/ContextMenu/ContextMenuCheckBaseAttribute.cs b/DisCatSharp.ApplicationCommands/Attributes/ContextMenu/ContextMenuCheckBaseAttribute.cs deleted file mode 100644 index bc977bc40..000000000 --- a/DisCatSharp.ApplicationCommands/Attributes/ContextMenu/ContextMenuCheckBaseAttribute.cs +++ /dev/null @@ -1,40 +0,0 @@ -// 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.Threading.Tasks; - -namespace DisCatSharp.ApplicationCommands -{ - /// - /// The base class for a pre-execution check for a context menu. - /// - public abstract class ContextMenuCheckBaseAttribute : Attribute - { - /// - /// Checks whether this command can be executed within the current context. - /// - /// The context. - /// Whether the checks passed. - public abstract Task ExecuteChecksAsync(ContextMenuContext ctx); - } -} diff --git a/DisCatSharp.ApplicationCommands/Attributes/DontInjectAttribute.cs b/DisCatSharp.ApplicationCommands/Attributes/DontInjectAttribute.cs deleted file mode 100644 index bcdbf9ab9..000000000 --- a/DisCatSharp.ApplicationCommands/Attributes/DontInjectAttribute.cs +++ /dev/null @@ -1,33 +0,0 @@ -// 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; - -namespace DisCatSharp.ApplicationCommands -{ - /// - /// Prevents this field or property from having its value injected by dependency injection. - /// - [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false, Inherited = true)] - public class DontInjectAttribute : Attribute - { } -} diff --git a/DisCatSharp.ApplicationCommands/Attributes/SlashCommand/AutocompleteAttribute.cs b/DisCatSharp.ApplicationCommands/Attributes/SlashCommand/AutocompleteAttribute.cs deleted file mode 100644 index 010c78fd3..000000000 --- a/DisCatSharp.ApplicationCommands/Attributes/SlashCommand/AutocompleteAttribute.cs +++ /dev/null @@ -1,48 +0,0 @@ -// 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; - -namespace DisCatSharp.ApplicationCommands.Attributes -{ - - /// - /// The autocomplete attribute. - /// - [AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false)] - public class AutocompleteAttribute : Attribute - { - /// - /// The type of the provider. - /// - public Type ProviderType { get; } - - /// - /// Adds an autocomplete provider to this command option. - /// - /// The type of the provider. - public AutocompleteAttribute(Type providerType) - { - this.ProviderType = providerType; - } - } -} diff --git a/DisCatSharp.ApplicationCommands/Attributes/SlashCommand/ChannelTypesAttribute.cs b/DisCatSharp.ApplicationCommands/Attributes/SlashCommand/ChannelTypesAttribute.cs deleted file mode 100644 index 5d57a3586..000000000 --- a/DisCatSharp.ApplicationCommands/Attributes/SlashCommand/ChannelTypesAttribute.cs +++ /dev/null @@ -1,48 +0,0 @@ -// 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.Collections.Generic; - -namespace DisCatSharp.ApplicationCommands.Attributes -{ - /// - /// Defines allowed channel types for a channel parameter. - /// - [AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false)] - public class ChannelTypesAttribute : Attribute - { - /// - /// Allowed channel types. - /// - public IEnumerable ChannelTypes { get; } - - /// - /// Defines allowed channel types for a channel parameter. - /// - /// The channel types to allow. - public ChannelTypesAttribute(params ChannelType[] channelTypes) - { - this.ChannelTypes = channelTypes; - } - } -} diff --git a/DisCatSharp.ApplicationCommands/Attributes/SlashCommand/ChoiceAttribute.cs b/DisCatSharp.ApplicationCommands/Attributes/SlashCommand/ChoiceAttribute.cs deleted file mode 100644 index a6322a23b..000000000 --- a/DisCatSharp.ApplicationCommands/Attributes/SlashCommand/ChoiceAttribute.cs +++ /dev/null @@ -1,87 +0,0 @@ -// 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; - -namespace DisCatSharp.ApplicationCommands -{ - /// - /// Adds a choice for this slash command option - /// - [AttributeUsage(AttributeTargets.Parameter, AllowMultiple = true)] - public class ChoiceAttribute : Attribute - { - /// - /// Gets the name of the choice - /// - public string Name { get; } - - /// - /// Gets the value of the choice - /// - public object Value { get; } - - /// - /// Adds a choice to the slash command option - /// - /// The name of the choice - /// The value of the choice - public ChoiceAttribute(string name, string value) - { - this.Name = name; - this.Value = value; - } - - /// - /// Adds a choice to the slash command option - /// - /// The name of the choice - /// The value of the choice - public ChoiceAttribute(string name, long value) - { - this.Name = name; - this.Value = value; - } - - /// - /// Adds a choice to the slash command option - /// - /// The name of the choice - /// The value of the choice - public ChoiceAttribute(string name, int value) - { - this.Name = name; - this.Value = value; - } - - /// - /// Adds a choice to the slash command option - /// - /// The name of the choice - /// The value of the choice - public ChoiceAttribute(string name, double value) - { - this.Name = name; - this.Value = value; - } - } -} diff --git a/DisCatSharp.ApplicationCommands/Attributes/SlashCommand/ChoiceNameAttribute.cs b/DisCatSharp.ApplicationCommands/Attributes/SlashCommand/ChoiceNameAttribute.cs deleted file mode 100644 index fc417c8b3..000000000 --- a/DisCatSharp.ApplicationCommands/Attributes/SlashCommand/ChoiceNameAttribute.cs +++ /dev/null @@ -1,47 +0,0 @@ -// 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; - -namespace DisCatSharp.ApplicationCommands -{ - /// - /// Sets the name for this enum choice. - /// - [AttributeUsage(AttributeTargets.All, AllowMultiple = false)] - public class ChoiceNameAttribute : Attribute - { - /// - /// The name. - /// - public string Name { get; set; } - - /// - /// Sets the name for this enum choice. - /// - /// The name for this enum choice. - public ChoiceNameAttribute(string name) - { - this.Name = name; - } - } -} diff --git a/DisCatSharp.ApplicationCommands/Attributes/SlashCommand/ChoiceProvider.cs b/DisCatSharp.ApplicationCommands/Attributes/SlashCommand/ChoiceProvider.cs deleted file mode 100644 index a54a3a6bb..000000000 --- a/DisCatSharp.ApplicationCommands/Attributes/SlashCommand/ChoiceProvider.cs +++ /dev/null @@ -1,50 +0,0 @@ -// 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.Collections.Generic; -using System.Threading.Tasks; -using DisCatSharp.Entities; - -namespace DisCatSharp.ApplicationCommands -{ - /// - /// Implementation of with access to service collection. - /// - public abstract class ChoiceProvider : IChoiceProvider - { - /// - /// Sets the choices for the slash command. - /// - public abstract Task> Provider(); - - /// - /// Sets the service provider. - /// - public IServiceProvider Services { get; set; } - - /// - /// The optional ID of the Guild the command got registered for. - /// - public ulong? GuildId { get; set; } - } -} diff --git a/DisCatSharp.ApplicationCommands/Attributes/SlashCommand/ChoiceProviderAttribute.cs b/DisCatSharp.ApplicationCommands/Attributes/SlashCommand/ChoiceProviderAttribute.cs deleted file mode 100644 index 3b588bd85..000000000 --- a/DisCatSharp.ApplicationCommands/Attributes/SlashCommand/ChoiceProviderAttribute.cs +++ /dev/null @@ -1,49 +0,0 @@ -// 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; - -namespace DisCatSharp.ApplicationCommands -{ - /// - /// Sets a IChoiceProvider for a command options. ChoiceProviders can be used to provide - /// DiscordApplicationCommandOptionChoice from external sources such as a database. - /// - [AttributeUsage(AttributeTargets.Parameter, AllowMultiple = true)] - public class ChoiceProviderAttribute : Attribute - { - - /// - /// The type of the provider. - /// - public Type ProviderType { get; } - - /// - /// Adds a choice provider to this command. - /// - /// The type of the provider. - public ChoiceProviderAttribute(Type providerType) - { - this.ProviderType = providerType; - } - } -} diff --git a/DisCatSharp.ApplicationCommands/Attributes/SlashCommand/IAutocompleteProvider.cs b/DisCatSharp.ApplicationCommands/Attributes/SlashCommand/IAutocompleteProvider.cs deleted file mode 100644 index e23a1069b..000000000 --- a/DisCatSharp.ApplicationCommands/Attributes/SlashCommand/IAutocompleteProvider.cs +++ /dev/null @@ -1,40 +0,0 @@ -// 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.Threading.Tasks; -using DisCatSharp.Entities; - -namespace DisCatSharp.ApplicationCommands.Attributes -{ - /// - /// The autocomplete provider. - /// - public interface IAutocompleteProvider - { - /// - /// Provider the autocompletion. - /// - /// The context. - Task> Provider(AutocompleteContext context); - } -} diff --git a/DisCatSharp.ApplicationCommands/Attributes/SlashCommand/IChoiceProvider.cs b/DisCatSharp.ApplicationCommands/Attributes/SlashCommand/IChoiceProvider.cs deleted file mode 100644 index 8360aa2d3..000000000 --- a/DisCatSharp.ApplicationCommands/Attributes/SlashCommand/IChoiceProvider.cs +++ /dev/null @@ -1,39 +0,0 @@ -// 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.Collections.Generic; -using System.Threading.Tasks; -using DisCatSharp.Entities; - -namespace DisCatSharp.ApplicationCommands -{ - /// - /// All choice providers must inherit from this interface - /// - public interface IChoiceProvider - { - /// - /// Sets the choices for the slash command - /// - Task> Provider(); - } -} diff --git a/DisCatSharp.ApplicationCommands/Attributes/SlashCommand/OptionAttribute.cs b/DisCatSharp.ApplicationCommands/Attributes/SlashCommand/OptionAttribute.cs deleted file mode 100644 index 110b2683d..000000000 --- a/DisCatSharp.ApplicationCommands/Attributes/SlashCommand/OptionAttribute.cs +++ /dev/null @@ -1,69 +0,0 @@ -// 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.Collections.Generic; -using System.Collections.ObjectModel; -using System.Linq; - -namespace DisCatSharp.ApplicationCommands -{ - /// - /// Marks this parameter as an option for a slash command - /// - [AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false)] - public class OptionAttribute : Attribute - { - /// - /// Gets the name of this option. - /// - public string Name; - - /// - /// Gets the description of this option. - /// - public string Description; - - /// - /// Whether to autocomplete this option. - /// - public bool Autocomplete; - - /// - /// Initializes a new instance of the class. - /// - /// The name. - /// The description. - /// If true, autocomplete. - public OptionAttribute(string name, string description, bool autocomplete = false) - { - if (name.Length > 32) - throw new ArgumentException("Slash command option names cannot go over 32 characters."); - else if (description.Length > 100) - throw new ArgumentException("Slash command option descriptions cannot go over 100 characters."); - - Name = name.ToLower(); - Description = description; - Autocomplete = autocomplete; - } - } -} diff --git a/DisCatSharp.ApplicationCommands/Attributes/SlashCommand/RequireBotPermissionsAttribute.cs b/DisCatSharp.ApplicationCommands/Attributes/SlashCommand/RequireBotPermissionsAttribute.cs deleted file mode 100644 index 755c7a419..000000000 --- a/DisCatSharp.ApplicationCommands/Attributes/SlashCommand/RequireBotPermissionsAttribute.cs +++ /dev/null @@ -1,75 +0,0 @@ -// 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.Threading.Tasks; - -namespace DisCatSharp.ApplicationCommands.Attributes -{ - /// - /// Defines that usage of this application command is only possible when the bot is granted a specific permission. - /// - [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, AllowMultiple = false, Inherited = false)] - public sealed class ApplicationCommandRequireBotPermissionsAttribute : SlashCheckBaseAttribute - { - /// - /// Gets the permissions required by this attribute. - /// - public Permissions Permissions { get; } - - /// - /// Gets or sets this check's behaviour in DMs. True means the check will always pass in DMs, whereas false means that it will always fail. - /// - public bool IgnoreDms { get; } = true; - - /// - /// Defines that usage of this application command is only possible when the bot is granted a specific permission. - /// - /// Permissions required to execute this command. - /// Sets this check's behaviour in DMs. True means the check will always pass in DMs, whereas false means that it will always fail. - public ApplicationCommandRequireBotPermissionsAttribute(Permissions permissions, bool ignoreDms = true) - { - this.Permissions = permissions; - this.IgnoreDms = ignoreDms; - } - - /// - /// Runs checks. - /// - public override async Task ExecuteChecksAsync(InteractionContext ctx) - { - if (ctx.Guild == null) - return this.IgnoreDms; - - var bot = await ctx.Guild.GetMemberAsync(ctx.Client.CurrentUser.Id).ConfigureAwait(false); - if (bot == null) - return false; - - if (bot.Id == ctx.Guild.OwnerId) - return true; - - var pbot = ctx.Channel.PermissionsFor(bot); - - return (pbot & Permissions.Administrator) != 0 || (pbot & this.Permissions) == this.Permissions; - } - } -} diff --git a/DisCatSharp.ApplicationCommands/Attributes/SlashCommand/RequireDirectMessageAttribute.cs b/DisCatSharp.ApplicationCommands/Attributes/SlashCommand/RequireDirectMessageAttribute.cs deleted file mode 100644 index 7c069f2ea..000000000 --- a/DisCatSharp.ApplicationCommands/Attributes/SlashCommand/RequireDirectMessageAttribute.cs +++ /dev/null @@ -1,47 +0,0 @@ -// 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.Threading.Tasks; -using DisCatSharp.Entities; - -namespace DisCatSharp.ApplicationCommands.Attributes -{ - /// - /// Defines that this application command is only usable within a direct message channel. - /// - [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, AllowMultiple = false, Inherited = false)] - public sealed class ApplicationCommandRequireDirectMessageAttribute : SlashCheckBaseAttribute - { - /// - /// Defines that this command is only usable within a direct message channel. - /// - public ApplicationCommandRequireDirectMessageAttribute() - { } - - /// - /// Runs checks. - /// - public override Task ExecuteChecksAsync(InteractionContext ctx) - => Task.FromResult(ctx.Channel is DiscordDmChannel); - } -} diff --git a/DisCatSharp.ApplicationCommands/Attributes/SlashCommand/RequireDisCatSharpDeveloperAttribute.cs b/DisCatSharp.ApplicationCommands/Attributes/SlashCommand/RequireDisCatSharpDeveloperAttribute.cs deleted file mode 100644 index 568a5abc4..000000000 --- a/DisCatSharp.ApplicationCommands/Attributes/SlashCommand/RequireDisCatSharpDeveloperAttribute.cs +++ /dev/null @@ -1,50 +0,0 @@ -// 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 -{ - /// - /// Defines that this application command is restricted to the owner of the bot. - /// - [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, AllowMultiple = false, Inherited = false)] - public sealed class ApplicationCommandRequireDisCatSharpDeveloperAttribute : SlashCheckBaseAttribute - { - /// - /// Defines that this application command is restricted to the owner of the bot. - /// - public ApplicationCommandRequireDisCatSharpDeveloperAttribute() - { } - - /// - /// Runs checks. - /// - public override Task 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); - } - } -} diff --git a/DisCatSharp.ApplicationCommands/Attributes/SlashCommand/RequireGuildAttribute.cs b/DisCatSharp.ApplicationCommands/Attributes/SlashCommand/RequireGuildAttribute.cs deleted file mode 100644 index b1395fa6a..000000000 --- a/DisCatSharp.ApplicationCommands/Attributes/SlashCommand/RequireGuildAttribute.cs +++ /dev/null @@ -1,46 +0,0 @@ -// 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.Threading.Tasks; - -namespace DisCatSharp.ApplicationCommands.Attributes -{ - /// - /// Defines that this application command is only usable within a guild. - /// - [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, AllowMultiple = false, Inherited = false)] - public sealed class ApplicationCommandRequireGuildAttribute : SlashCheckBaseAttribute - { - /// - /// Defines that this command is only usable within a guild. - /// - public ApplicationCommandRequireGuildAttribute() - { } - - /// - /// Runs checks. - /// - public override Task ExecuteChecksAsync(InteractionContext ctx) - => Task.FromResult(ctx.Guild != null); - } -} diff --git a/DisCatSharp.ApplicationCommands/Attributes/SlashCommand/RequireOwnerAttribute.cs b/DisCatSharp.ApplicationCommands/Attributes/SlashCommand/RequireOwnerAttribute.cs deleted file mode 100644 index e73d196d2..000000000 --- a/DisCatSharp.ApplicationCommands/Attributes/SlashCommand/RequireOwnerAttribute.cs +++ /dev/null @@ -1,52 +0,0 @@ -// 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 -{ - /// - /// Defines that this application command is restricted to the owner of the bot. - /// - [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, AllowMultiple = false, Inherited = false)] - public sealed class ApplicationCommandRequireOwnerAttribute : SlashCheckBaseAttribute - { - /// - /// Defines that this application command is restricted to the owner of the bot. - /// - public ApplicationCommandRequireOwnerAttribute() - { } - - /// - /// Runs checks. - /// - public override Task ExecuteChecksAsync(InteractionContext ctx) - { - var app = ctx.Client.CurrentApplication; - var me = ctx.Client.CurrentUser; - - return app != null ? Task.FromResult(app.Owners.Any(x => x.Id == ctx.User.Id)) : Task.FromResult(ctx.User.Id == me.Id); - } - } -} diff --git a/DisCatSharp.ApplicationCommands/Attributes/SlashCommand/RequireOwnerOrIdAttribute.cs b/DisCatSharp.ApplicationCommands/Attributes/SlashCommand/RequireOwnerOrIdAttribute.cs deleted file mode 100644 index ac6ecf9f0..000000000 --- a/DisCatSharp.ApplicationCommands/Attributes/SlashCommand/RequireOwnerOrIdAttribute.cs +++ /dev/null @@ -1,67 +0,0 @@ -// 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.Collections.Generic; -using System.Collections.ObjectModel; -using System.Linq; -using System.Threading.Tasks; - -namespace DisCatSharp.ApplicationCommands.Attributes -{ - /// - /// Requires ownership of the bot or a whitelisted id to execute this command. - /// - [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, AllowMultiple = false, Inherited = false)] - public sealed class ApplicationCommandRequireOwnerOrIdAttribute : SlashCheckBaseAttribute - { - /// - /// Allowed user ids - /// - public IReadOnlyList UserIds { get; } - - /// - /// Defines that usage of this command is restricted to the owner or whitelisted ids of the bot. - /// - /// List of allowed user ids - public ApplicationCommandRequireOwnerOrIdAttribute(params ulong[] user_ids) - { - this.UserIds = new ReadOnlyCollection(user_ids); - } - - /// - /// Executes the a check. - /// - /// The command context.s - public override Task ExecuteChecksAsync(InteractionContext ctx) - { - var app = ctx.Client.CurrentApplication; - var me = ctx.Client.CurrentUser; - - var owner = app != null ? Task.FromResult(app.Owners.Any(x => x.Id == ctx.User.Id)) : Task.FromResult(ctx.User.Id == me.Id); - - var allowed = this.UserIds.Contains(ctx.User.Id); - - return allowed ? Task.FromResult(true) : owner; - } - } -} diff --git a/DisCatSharp.ApplicationCommands/Attributes/SlashCommand/RequirePermissionsAttribute.cs b/DisCatSharp.ApplicationCommands/Attributes/SlashCommand/RequirePermissionsAttribute.cs deleted file mode 100644 index 938c7656a..000000000 --- a/DisCatSharp.ApplicationCommands/Attributes/SlashCommand/RequirePermissionsAttribute.cs +++ /dev/null @@ -1,85 +0,0 @@ -// 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.Threading.Tasks; - -namespace DisCatSharp.ApplicationCommands.Attributes -{ - /// - /// Defines that usage of this application command is restricted to members with specified permissions. This check also verifies that the bot has the same permissions. - /// - [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, AllowMultiple = false, Inherited = false)] - public sealed class ApplicationCommandRequirePermissionsAttribute : SlashCheckBaseAttribute - { - /// - /// Gets the permissions required by this attribute. - /// - public Permissions Permissions { get; } - - /// - /// Gets or sets this check's behaviour in DMs. True means the check will always pass in DMs, whereas false means that it will always fail. - /// - public bool IgnoreDms { get; } = true; - - /// - /// Defines that usage of this command is restricted to members with specified permissions. This check also verifies that the bot has the same permissions. - /// - /// Permissions required to execute this command. - /// Sets this check's behaviour in DMs. True means the check will always pass in DMs, whereas false means that it will always fail. - public ApplicationCommandRequirePermissionsAttribute(Permissions permissions, bool ignoreDms = true) - { - this.Permissions = permissions; - this.IgnoreDms = ignoreDms; - } - - /// - /// Runs checks. - /// - public override async Task ExecuteChecksAsync(InteractionContext ctx) - { - if (ctx.Guild == null) - return this.IgnoreDms; - - 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; - var botok = ctx.Guild.OwnerId == bot.Id; - - if (!usrok) - usrok = (pusr & Permissions.Administrator) != 0 || (pusr & this.Permissions) == this.Permissions; - - if (!botok) - botok = (pbot & Permissions.Administrator) != 0 || (pbot & this.Permissions) == this.Permissions; - - return usrok && botok; - } - } -} diff --git a/DisCatSharp.ApplicationCommands/Attributes/SlashCommand/RequireUserPermissionsAttribute.cs b/DisCatSharp.ApplicationCommands/Attributes/SlashCommand/RequireUserPermissionsAttribute.cs deleted file mode 100644 index a44ad9d13..000000000 --- a/DisCatSharp.ApplicationCommands/Attributes/SlashCommand/RequireUserPermissionsAttribute.cs +++ /dev/null @@ -1,77 +0,0 @@ -// 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.Threading.Tasks; - -namespace DisCatSharp.ApplicationCommands.Attributes -{ - /// - /// Defines that usage of this application command is restricted to members with specified permissions. - /// - [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, AllowMultiple = false, Inherited = false)] - public sealed class ApplicationCommandRequireUserPermissionsAttribute : SlashCheckBaseAttribute - { - /// - /// Gets the permissions required by this attribute. - /// - public Permissions Permissions { get; } - - /// - /// Gets or sets this check's behaviour in DMs. True means the check will always pass in DMs, whereas false means that it will always fail. - /// - public bool IgnoreDms { get; } = true; - - /// - /// Defines that usage of this command is restricted to members with specified permissions. - /// - /// Permissions required to execute this command. - /// Sets this check's behaviour in DMs. True means the check will always pass in DMs, whereas false means that it will always fail. - public ApplicationCommandRequireUserPermissionsAttribute(Permissions permissions, bool ignoreDms = true) - { - this.Permissions = permissions; - this.IgnoreDms = ignoreDms; - } - - /// - /// Runs checks. - /// - public override Task ExecuteChecksAsync(InteractionContext ctx) - { - if (ctx.Guild == null) - return Task.FromResult(this.IgnoreDms); - - var usr = ctx.Member; - if (usr == null) - return Task.FromResult(false); - - if (usr.Id == ctx.Guild.OwnerId) - return Task.FromResult(true); - - var pusr = ctx.Channel.PermissionsFor(usr); - - return (pusr & Permissions.Administrator) != 0 - ? Task.FromResult(true) - : (pusr & this.Permissions) == this.Permissions ? Task.FromResult(true) : Task.FromResult(false); - } - } -} diff --git a/DisCatSharp.ApplicationCommands/Attributes/SlashCommand/SlashCheckBaseAttribute.cs b/DisCatSharp.ApplicationCommands/Attributes/SlashCommand/SlashCheckBaseAttribute.cs deleted file mode 100644 index 9a8dfcf84..000000000 --- a/DisCatSharp.ApplicationCommands/Attributes/SlashCommand/SlashCheckBaseAttribute.cs +++ /dev/null @@ -1,40 +0,0 @@ -// 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.Threading.Tasks; - -namespace DisCatSharp.ApplicationCommands -{ - /// - /// The base class for a pre-execution check for a application command. - /// - public abstract class SlashCheckBaseAttribute : Attribute - { - /// - /// Checks whether this command can be executed within the current context. - /// - /// The context. - /// Whether the checks passed. - public abstract Task ExecuteChecksAsync(InteractionContext ctx); - } -} diff --git a/DisCatSharp.ApplicationCommands/Attributes/SlashCommand/SlashCommandAttribute.cs b/DisCatSharp.ApplicationCommands/Attributes/SlashCommand/SlashCommandAttribute.cs deleted file mode 100644 index 7a26cb93c..000000000 --- a/DisCatSharp.ApplicationCommands/Attributes/SlashCommand/SlashCommandAttribute.cs +++ /dev/null @@ -1,61 +0,0 @@ -// 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; - -namespace DisCatSharp.ApplicationCommands -{ - /// - /// Marks this method as a slash command - /// - [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] - public class SlashCommandAttribute : Attribute - { - /// - /// Gets the name of this command - /// - public string Name { get; } - - /// - /// Gets the description of this command - /// - public string Description { get; } - - /// - /// Gets the default permission of this command - /// - public bool DefaultPermission { get; set; } - - /// - /// Marks this method as a slash command - /// - /// The name of this slash command - /// The description of this slash command - /// Whether everyone can execute this command. - public SlashCommandAttribute(string name, string description, bool default_permission = true) - { - this.Name = name.ToLower(); - this.Description = description; - this.DefaultPermission = default_permission; - } - } -} diff --git a/DisCatSharp.ApplicationCommands/Attributes/SlashCommand/SlashCommandGroupAttribute.cs b/DisCatSharp.ApplicationCommands/Attributes/SlashCommand/SlashCommandGroupAttribute.cs deleted file mode 100644 index 9b3231830..000000000 --- a/DisCatSharp.ApplicationCommands/Attributes/SlashCommand/SlashCommandGroupAttribute.cs +++ /dev/null @@ -1,61 +0,0 @@ -// 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; - -namespace DisCatSharp.ApplicationCommands -{ - /// - /// Marks this class a slash command group - /// - [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)] - public class SlashCommandGroupAttribute : Attribute - { - /// - /// Gets the name of this slash command group - /// - public string Name { get; set; } - - /// - /// Gets the description of this slash command group - /// - public string Description { get; set; } - - /// - /// Gets the default permission of this slash command group - /// - public bool DefaultPermission { get; set; } - - /// - /// Marks this class as a slash command group - /// - /// The name of this slash command group - /// The description of this slash command group - /// Whether everyone can execute this command. - public SlashCommandGroupAttribute(string name, string description, bool default_permission = true) - { - this.Name = name.ToLower(); - this.Description = description; - this.DefaultPermission = default_permission; - } - } -}