diff --git a/DisCatSharp.ApplicationCommands/Attributes/ApplicationCommandModuleLifespanAttribute.cs b/DisCatSharp.ApplicationCommands/Attributes/ApplicationCommandModuleLifespanAttribute.cs index 410ebaa32..4035c74d8 100644 --- a/DisCatSharp.ApplicationCommands/Attributes/ApplicationCommandModuleLifespanAttribute.cs +++ b/DisCatSharp.ApplicationCommands/Attributes/ApplicationCommandModuleLifespanAttribute.cs @@ -1,69 +1,69 @@ // This file is part of the DisCatSharp project, based off 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)] + [AttributeUsage(AttributeTargets.Class)] 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 index 09ccf3358..5e18b90d6 100644 --- a/DisCatSharp.ApplicationCommands/Attributes/ContextMenu/ContextMenuAttribute.cs +++ b/DisCatSharp.ApplicationCommands/Attributes/ContextMenu/ContextMenuAttribute.cs @@ -1,66 +1,66 @@ // This file is part of the DisCatSharp project, based off 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 DisCatSharp.Enums; namespace DisCatSharp.ApplicationCommands { /// /// Marks this method as a context menu. /// - [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] + [AttributeUsage(AttributeTargets.Method)] 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/DontInjectAttribute.cs b/DisCatSharp.ApplicationCommands/Attributes/DontInjectAttribute.cs index 0f2c3f4e2..d0d2eaed5 100644 --- a/DisCatSharp.ApplicationCommands/Attributes/DontInjectAttribute.cs +++ b/DisCatSharp.ApplicationCommands/Attributes/DontInjectAttribute.cs @@ -1,33 +1,33 @@ // This file is part of the DisCatSharp project, based off 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 { /// /// Prevents this field or property from having its value injected by dependency injection. /// - [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false, Inherited = true)] + [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)] public class DontInjectAttribute : Attribute { } } diff --git a/DisCatSharp.ApplicationCommands/Attributes/SlashCommand/AutocompleteAttribute.cs b/DisCatSharp.ApplicationCommands/Attributes/SlashCommand/AutocompleteAttribute.cs index b75cfc1ac..68a03dce0 100644 --- a/DisCatSharp.ApplicationCommands/Attributes/SlashCommand/AutocompleteAttribute.cs +++ b/DisCatSharp.ApplicationCommands/Attributes/SlashCommand/AutocompleteAttribute.cs @@ -1,48 +1,48 @@ // This file is part of the DisCatSharp project, based off 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)] + [AttributeUsage(AttributeTargets.Parameter)] 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 index b63f43db3..085c8a5c3 100644 --- a/DisCatSharp.ApplicationCommands/Attributes/SlashCommand/ChannelTypesAttribute.cs +++ b/DisCatSharp.ApplicationCommands/Attributes/SlashCommand/ChannelTypesAttribute.cs @@ -1,48 +1,48 @@ // This file is part of the DisCatSharp project, based off 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)] + [AttributeUsage(AttributeTargets.Parameter)] 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/ChoiceNameAttribute.cs b/DisCatSharp.ApplicationCommands/Attributes/SlashCommand/ChoiceNameAttribute.cs index a8535a892..cfab34804 100644 --- a/DisCatSharp.ApplicationCommands/Attributes/SlashCommand/ChoiceNameAttribute.cs +++ b/DisCatSharp.ApplicationCommands/Attributes/SlashCommand/ChoiceNameAttribute.cs @@ -1,47 +1,47 @@ // This file is part of the DisCatSharp project, based off 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 { /// /// Sets the name for this enum choice. /// - [AttributeUsage(AttributeTargets.All, AllowMultiple = false)] + [AttributeUsage(AttributeTargets.All)] 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/MinimumMaximumAttribute.cs b/DisCatSharp.ApplicationCommands/Attributes/SlashCommand/MinimumMaximumAttribute.cs index c5c433dd6..c8799912f 100644 --- a/DisCatSharp.ApplicationCommands/Attributes/SlashCommand/MinimumMaximumAttribute.cs +++ b/DisCatSharp.ApplicationCommands/Attributes/SlashCommand/MinimumMaximumAttribute.cs @@ -1,98 +1,98 @@ // This file is part of the DisCatSharp project, based off 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 { /// /// Sets a minimum value for this slash command option. Only valid for , or parameters. /// - [AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false)] + [AttributeUsage(AttributeTargets.Parameter)] public class MinimumAttribute : Attribute { /// /// The value. /// public object Value { get; internal set; } /// /// Sets a minimum value for this slash command option. Only valid for , or parameters. /// public MinimumAttribute(int value) { this.Value = value; } /// /// Sets a minimum value for this slash command option. Only valid for , or parameters. /// public MinimumAttribute(long value) { this.Value = value; } /// /// Sets a minimum value for this slash command option. Only valid for , or parameters. /// public MinimumAttribute(double value) { this.Value = value; } } /// /// Sets a maximum value for this slash command option. Only valid for , or parameters. /// - [AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false)] + [AttributeUsage(AttributeTargets.Parameter)] public class MaximumAttribute : Attribute { /// /// The value. /// public object Value { get; internal set; } /// /// Sets a maximum value for this slash command option. Only valid for , or parameters. /// public MaximumAttribute(int value) { this.Value = value; } /// /// Sets a maximum value for this slash command option. Only valid for , or parameters. /// public MaximumAttribute(long value) { this.Value = value; } /// /// Sets a maximum value for this slash command option. Only valid for , or parameters. /// public MaximumAttribute(double value) { this.Value = value; } } } diff --git a/DisCatSharp.ApplicationCommands/Attributes/SlashCommand/OptionAttribute.cs b/DisCatSharp.ApplicationCommands/Attributes/SlashCommand/OptionAttribute.cs index 8f31b6cbd..f07347edc 100644 --- a/DisCatSharp.ApplicationCommands/Attributes/SlashCommand/OptionAttribute.cs +++ b/DisCatSharp.ApplicationCommands/Attributes/SlashCommand/OptionAttribute.cs @@ -1,66 +1,66 @@ // This file is part of the DisCatSharp project, based off 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 { /// /// Marks this parameter as an option for a slash command /// - [AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false)] + [AttributeUsage(AttributeTargets.Parameter)] 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 index 26429a335..766de81b5 100644 --- a/DisCatSharp.ApplicationCommands/Attributes/SlashCommand/RequireBotPermissionsAttribute.cs +++ b/DisCatSharp.ApplicationCommands/Attributes/SlashCommand/RequireBotPermissionsAttribute.cs @@ -1,75 +1,75 @@ // This file is part of the DisCatSharp project, based off 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)] + [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, 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 index c85e5cea9..01c5d5b20 100644 --- a/DisCatSharp.ApplicationCommands/Attributes/SlashCommand/RequireDirectMessageAttribute.cs +++ b/DisCatSharp.ApplicationCommands/Attributes/SlashCommand/RequireDirectMessageAttribute.cs @@ -1,47 +1,47 @@ // This file is part of the DisCatSharp project, based off 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)] + [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, 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 index 8c3a3cc09..35b75dab1 100644 --- a/DisCatSharp.ApplicationCommands/Attributes/SlashCommand/RequireDisCatSharpDeveloperAttribute.cs +++ b/DisCatSharp.ApplicationCommands/Attributes/SlashCommand/RequireDisCatSharpDeveloperAttribute.cs @@ -1,50 +1,50 @@ // This file is part of the DisCatSharp project, based off 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)] + [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, 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 index 0f8dee194..84d0e153a 100644 --- a/DisCatSharp.ApplicationCommands/Attributes/SlashCommand/RequireGuildAttribute.cs +++ b/DisCatSharp.ApplicationCommands/Attributes/SlashCommand/RequireGuildAttribute.cs @@ -1,46 +1,46 @@ // This file is part of the DisCatSharp project, based off 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)] + [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, 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/RequireNsfwAttribute.cs b/DisCatSharp.ApplicationCommands/Attributes/SlashCommand/RequireNsfwAttribute.cs index 873572f37..f034fff3f 100644 --- a/DisCatSharp.ApplicationCommands/Attributes/SlashCommand/RequireNsfwAttribute.cs +++ b/DisCatSharp.ApplicationCommands/Attributes/SlashCommand/RequireNsfwAttribute.cs @@ -1,46 +1,46 @@ // This file is part of the DisCatSharp project, based off 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)] + [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, Inherited = false)] public sealed class ApplicationCommandRequireNsfwAttribute : SlashCheckBaseAttribute { /// /// Defines that this command is only usable within a guild. /// public ApplicationCommandRequireNsfwAttribute() { } /// /// Runs checks. /// public override Task ExecuteChecksAsync(InteractionContext ctx) => Task.FromResult(ctx.Channel.Guild == null || ctx.Channel.IsNsfw); } } diff --git a/DisCatSharp.ApplicationCommands/Attributes/SlashCommand/RequireOwnerAttribute.cs b/DisCatSharp.ApplicationCommands/Attributes/SlashCommand/RequireOwnerAttribute.cs index 11e53cc0b..6fc96109c 100644 --- a/DisCatSharp.ApplicationCommands/Attributes/SlashCommand/RequireOwnerAttribute.cs +++ b/DisCatSharp.ApplicationCommands/Attributes/SlashCommand/RequireOwnerAttribute.cs @@ -1,52 +1,52 @@ // This file is part of the DisCatSharp project, based off 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)] + [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, 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 index abab60174..c5c5ab135 100644 --- a/DisCatSharp.ApplicationCommands/Attributes/SlashCommand/RequireOwnerOrIdAttribute.cs +++ b/DisCatSharp.ApplicationCommands/Attributes/SlashCommand/RequireOwnerOrIdAttribute.cs @@ -1,67 +1,67 @@ // This file is part of the DisCatSharp project, based off 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.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)] + [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, 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[] userIds) { this.UserIds = new ReadOnlyCollection(userIds); } /// /// 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 index 249149a72..e8928b6a4 100644 --- a/DisCatSharp.ApplicationCommands/Attributes/SlashCommand/RequirePermissionsAttribute.cs +++ b/DisCatSharp.ApplicationCommands/Attributes/SlashCommand/RequirePermissionsAttribute.cs @@ -1,85 +1,85 @@ // This file is part of the DisCatSharp project, based off 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)] + [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, 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 index 5bee967b3..ecba6b05e 100644 --- a/DisCatSharp.ApplicationCommands/Attributes/SlashCommand/RequireUserPermissionsAttribute.cs +++ b/DisCatSharp.ApplicationCommands/Attributes/SlashCommand/RequireUserPermissionsAttribute.cs @@ -1,77 +1,77 @@ // This file is part of the DisCatSharp project, based off 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)] + [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, 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/SlashCommandAttribute.cs b/DisCatSharp.ApplicationCommands/Attributes/SlashCommand/SlashCommandAttribute.cs index 1669b570f..ef3095ba0 100644 --- a/DisCatSharp.ApplicationCommands/Attributes/SlashCommand/SlashCommandAttribute.cs +++ b/DisCatSharp.ApplicationCommands/Attributes/SlashCommand/SlashCommandAttribute.cs @@ -1,71 +1,71 @@ // This file is part of the DisCatSharp project, based off 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 { /// /// Marks this method as a slash command /// - [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] + [AttributeUsage(AttributeTargets.Method)] public class SlashCommandAttribute : Attribute { /// /// Gets the name of this command /// public string Name { get; set; } /// /// Gets the description of this command /// public string Description { get; set; } /// /// Gets the default permission of this command /// public bool DefaultPermission { get; } /// /// Gets the needed permission of this command /// public Permissions? Permission { get; set; } /// /// Gets the dm permission of this command /// public bool? DmPermission { 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 defaultPermission = true) { this.Name = name.ToLower(); this.Description = description; this.DefaultPermission = defaultPermission; } } } diff --git a/DisCatSharp.ApplicationCommands/Attributes/SlashCommand/SlashCommandGroupAttribute.cs b/DisCatSharp.ApplicationCommands/Attributes/SlashCommand/SlashCommandGroupAttribute.cs index cbf9d13d8..54a047edf 100644 --- a/DisCatSharp.ApplicationCommands/Attributes/SlashCommand/SlashCommandGroupAttribute.cs +++ b/DisCatSharp.ApplicationCommands/Attributes/SlashCommand/SlashCommandGroupAttribute.cs @@ -1,71 +1,71 @@ // This file is part of the DisCatSharp project, based off 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 { /// /// Marks this class a slash command group /// - [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)] + [AttributeUsage(AttributeTargets.Class)] 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; } /// /// Gets the needed permission of this slash command group /// public Permissions? Permission { get; set; } /// /// Gets the dm permission of this slash command group /// public bool? DmPermission { 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 defaultPermission = true) { this.Name = name.ToLower(); this.Description = description; this.DefaultPermission = defaultPermission; } } } diff --git a/DisCatSharp.CommandsNext/Attributes/AliasesAttribute.cs b/DisCatSharp.CommandsNext/Attributes/AliasesAttribute.cs index 49928ba9e..d62e90c55 100644 --- a/DisCatSharp.CommandsNext/Attributes/AliasesAttribute.cs +++ b/DisCatSharp.CommandsNext/Attributes/AliasesAttribute.cs @@ -1,53 +1,53 @@ // This file is part of the DisCatSharp project, based off 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.Collections.ObjectModel; using System.Linq; namespace DisCatSharp.CommandsNext.Attributes { /// /// Adds aliases to this command or group. /// - [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, AllowMultiple = false)] + [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class)] public sealed class AliasesAttribute : Attribute { /// /// Gets this group's aliases. /// public IReadOnlyList Aliases { get; } /// /// Adds aliases to this command or group. /// /// Aliases to add to this command or group. public AliasesAttribute(params string[] aliases) { if (aliases.Any(xa => xa == null || xa.Any(xc => char.IsWhiteSpace(xc)))) throw new ArgumentException("Aliases cannot contain whitespace characters or null strings.", nameof(aliases)); this.Aliases = new ReadOnlyCollection(aliases); } } } diff --git a/DisCatSharp.CommandsNext/Attributes/CheckBaseAttribute.cs b/DisCatSharp.CommandsNext/Attributes/CheckBaseAttribute.cs index efe534474..920808853 100644 --- a/DisCatSharp.CommandsNext/Attributes/CheckBaseAttribute.cs +++ b/DisCatSharp.CommandsNext/Attributes/CheckBaseAttribute.cs @@ -1,42 +1,42 @@ // This file is part of the DisCatSharp project, based off 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.CommandsNext.Attributes { /// /// Represents a base for all command pre-execution check attributes. /// - [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true, Inherited = true)] + [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true)] public abstract class CheckBaseAttribute : Attribute { /// /// Asynchronously checks whether this command can be executed within given context. /// /// Context to check execution ability for. /// Whether this check is being executed from help or not. This can be used to probe whether command can be run without setting off certain fail conditions (such as cooldowns). /// Whether the command can be executed in given context. public abstract Task ExecuteCheckAsync(CommandContext ctx, bool help); } } diff --git a/DisCatSharp.CommandsNext/Attributes/CommandAttribute.cs b/DisCatSharp.CommandsNext/Attributes/CommandAttribute.cs index 3552f0992..749d6e82e 100644 --- a/DisCatSharp.CommandsNext/Attributes/CommandAttribute.cs +++ b/DisCatSharp.CommandsNext/Attributes/CommandAttribute.cs @@ -1,75 +1,75 @@ // This file is part of the DisCatSharp project, based off 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; namespace DisCatSharp.CommandsNext.Attributes { /// /// Marks this method as a command. /// - [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] + [AttributeUsage(AttributeTargets.Method)] public sealed class CommandAttribute : Attribute { /// /// Gets the name of this command. /// public string Name { get; } /// /// Marks this method as a command, using the method's name as command name. /// public CommandAttribute() { this.Name = null; } /// /// Marks this method as a command with specified name. /// /// Name of this command. public CommandAttribute(string name) { if (string.IsNullOrWhiteSpace(name)) throw new ArgumentNullException(nameof(name), "Command names cannot be null, empty, or all-whitespace."); if (name.Any(xc => char.IsWhiteSpace(xc))) throw new ArgumentException("Command names cannot contain whitespace characters.", nameof(name)); this.Name = name; } } /// /// Marks this method as a group command. /// - [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] + [AttributeUsage(AttributeTargets.Method)] public sealed class GroupCommandAttribute : Attribute { /// /// Marks this method as a group command. /// public GroupCommandAttribute() { } } } diff --git a/DisCatSharp.CommandsNext/Attributes/DescriptionAttribute.cs b/DisCatSharp.CommandsNext/Attributes/DescriptionAttribute.cs index 6b4d14516..30ee2815f 100644 --- a/DisCatSharp.CommandsNext/Attributes/DescriptionAttribute.cs +++ b/DisCatSharp.CommandsNext/Attributes/DescriptionAttribute.cs @@ -1,47 +1,47 @@ // This file is part of the DisCatSharp project, based off 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.CommandsNext.Attributes { /// /// Gives this command, group, or argument a description, which is used when listing help. /// - [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class | AttributeTargets.Parameter, AllowMultiple = false)] + [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class | AttributeTargets.Parameter)] public sealed class DescriptionAttribute : Attribute { /// /// Gets the description for this command, group, or argument. /// public string Description { get; } /// /// Gives this command, group, or argument a description, which is used when listing help. /// /// public DescriptionAttribute(string description) { this.Description = description; } } } diff --git a/DisCatSharp.CommandsNext/Attributes/DontInjectAttribute.cs b/DisCatSharp.CommandsNext/Attributes/DontInjectAttribute.cs index fbf11f1d8..0dca0f9fd 100644 --- a/DisCatSharp.CommandsNext/Attributes/DontInjectAttribute.cs +++ b/DisCatSharp.CommandsNext/Attributes/DontInjectAttribute.cs @@ -1,33 +1,33 @@ // This file is part of the DisCatSharp project, based off 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.CommandsNext.Attributes { /// /// Prevents this field or property from having its value injected by dependency injection. /// - [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false, Inherited = true)] + [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)] public class DontInjectAttribute : Attribute { } } diff --git a/DisCatSharp.CommandsNext/Attributes/GroupAttribute.cs b/DisCatSharp.CommandsNext/Attributes/GroupAttribute.cs index a23588eac..fd6eb5c61 100644 --- a/DisCatSharp.CommandsNext/Attributes/GroupAttribute.cs +++ b/DisCatSharp.CommandsNext/Attributes/GroupAttribute.cs @@ -1,62 +1,62 @@ // This file is part of the DisCatSharp project, based off 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; namespace DisCatSharp.CommandsNext.Attributes { /// /// Marks this class as a command group. /// - [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)] + [AttributeUsage(AttributeTargets.Class)] public sealed class GroupAttribute : Attribute { /// /// Gets the name of this group. /// public string Name { get; } /// /// Marks this class as a command group, using the class' name as group name. /// public GroupAttribute() { this.Name = null; } /// /// Marks this class as a command group with specified name. /// /// Name of this group. public GroupAttribute(string name) { if (string.IsNullOrWhiteSpace(name)) throw new ArgumentNullException(nameof(name), "Group names cannot be null, empty, or all-whitespace."); if (name.Any(xc => char.IsWhiteSpace(xc))) throw new ArgumentException("Group names cannot contain whitespace characters.", nameof(name)); this.Name = name; } } } diff --git a/DisCatSharp.CommandsNext/Attributes/HiddenAttribute.cs b/DisCatSharp.CommandsNext/Attributes/HiddenAttribute.cs index 421a1fb1a..42144da33 100644 --- a/DisCatSharp.CommandsNext/Attributes/HiddenAttribute.cs +++ b/DisCatSharp.CommandsNext/Attributes/HiddenAttribute.cs @@ -1,33 +1,33 @@ // This file is part of the DisCatSharp project, based off 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.CommandsNext.Attributes { /// /// Marks this command or group as hidden. /// - [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, AllowMultiple = false)] + [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class)] public sealed class HiddenAttribute : Attribute { } } diff --git a/DisCatSharp.CommandsNext/Attributes/ModuleLifespanAttribute.cs b/DisCatSharp.CommandsNext/Attributes/ModuleLifespanAttribute.cs index 95f710575..2204d1cea 100644 --- a/DisCatSharp.CommandsNext/Attributes/ModuleLifespanAttribute.cs +++ b/DisCatSharp.CommandsNext/Attributes/ModuleLifespanAttribute.cs @@ -1,63 +1,63 @@ // This file is part of the DisCatSharp project, based off 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.CommandsNext.Attributes { /// /// Defines a lifespan for this command module. /// - [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)] + [AttributeUsage(AttributeTargets.Class, Inherited = false)] public class ModuleLifespanAttribute : Attribute { /// /// Gets the lifespan defined for this module. /// public ModuleLifespan Lifespan { get; } /// /// Defines a lifespan for this command module. /// /// Lifespan for this module. public ModuleLifespanAttribute(ModuleLifespan lifespan) { this.Lifespan = lifespan; } } /// /// Defines lifespan of a command module. /// public enum ModuleLifespan : int { /// /// Defines that this module will be instantiated once. /// Singleton = 0, /// /// Defines that this module will be instantiated every time a containing command is called. /// Transient = 1 } } diff --git a/DisCatSharp.CommandsNext/Attributes/PriorityAttribute.cs b/DisCatSharp.CommandsNext/Attributes/PriorityAttribute.cs index fdc6aef43..1b4b42028 100644 --- a/DisCatSharp.CommandsNext/Attributes/PriorityAttribute.cs +++ b/DisCatSharp.CommandsNext/Attributes/PriorityAttribute.cs @@ -1,47 +1,47 @@ // This file is part of the DisCatSharp project, based off 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.CommandsNext.Attributes { /// /// Defines this command overload's priority. This determines the order in which overloads will be attempted to be called. Commands will be attempted in order of priority, in descending order. /// - [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)] + [AttributeUsage(AttributeTargets.Method, Inherited = false)] public sealed class PriorityAttribute : Attribute { /// /// Gets the priority of this command overload. /// public int Priority { get; } /// /// Defines this command overload's priority. This determines the order in which overloads will be attempted to be called. Commands will be attempted in order of priority, in descending order. /// /// Priority of this command overload. public PriorityAttribute(int priority) { this.Priority = priority; } } } diff --git a/DisCatSharp.CommandsNext/Attributes/RemainingTextAttribute.cs b/DisCatSharp.CommandsNext/Attributes/RemainingTextAttribute.cs index b0ddb2e1e..0f2f87ef7 100644 --- a/DisCatSharp.CommandsNext/Attributes/RemainingTextAttribute.cs +++ b/DisCatSharp.CommandsNext/Attributes/RemainingTextAttribute.cs @@ -1,33 +1,33 @@ // This file is part of the DisCatSharp project, based off 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.CommandsNext.Attributes { /// /// Indicates that the command argument takes the rest of the input without parsing. /// - [AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false)] + [AttributeUsage(AttributeTargets.Parameter)] public class RemainingTextAttribute : Attribute { } } diff --git a/DisCatSharp.CommandsNext/Attributes/RequireBoostingAttribute.cs b/DisCatSharp.CommandsNext/Attributes/RequireBoostingAttribute.cs index ef6ffd340..a09b37f02 100644 --- a/DisCatSharp.CommandsNext/Attributes/RequireBoostingAttribute.cs +++ b/DisCatSharp.CommandsNext/Attributes/RequireBoostingAttribute.cs @@ -1,84 +1,84 @@ // This file is part of the DisCatSharp project, based off 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.CommandsNext.Attributes { /// /// Defines that usage of this command is restricted to boosters. /// - [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, AllowMultiple = false, Inherited = false)] + [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, Inherited = false)] public sealed class RequireBoostingAttribute : CheckBaseAttribute { /// /// Gets the required boost time. /// public int Since { get; } /// /// Gets the required guild. /// public ulong GuildId { get; } /// /// Initializes a new instance of the class. /// /// Boosting since days. public RequireBoostingAttribute(int days = 0) { this.GuildId = 0; this.Since = days; } /// /// Initializes a new instance of the class. /// /// Target guild id. /// Boosting since days. public RequireBoostingAttribute(ulong guildId, int days = 0) { this.GuildId = guildId; this.Since = days; } /// /// Executes the a check. /// /// The command context. /// If true, help - returns true. public override async Task ExecuteCheckAsync(CommandContext ctx, bool help) { if (this.GuildId != 0) { var guild = await ctx.Client.GetGuildAsync(this.GuildId); var member = await guild.GetMemberAsync(ctx.User.Id); return member != null && member.PremiumSince.HasValue ? await Task.FromResult(member.PremiumSince.Value.UtcDateTime.Date < DateTime.UtcNow.Date.AddDays(-this.Since)) : await Task.FromResult(false); } else { return ctx.Member != null && ctx.Member.PremiumSince.HasValue ? await Task.FromResult(ctx.Member.PremiumSince.Value.UtcDateTime.Date < DateTime.UtcNow.Date.AddDays(-this.Since)) : await Task.FromResult(false); } } } } diff --git a/DisCatSharp.CommandsNext/Attributes/RequireBotPermissionsAttribute.cs b/DisCatSharp.CommandsNext/Attributes/RequireBotPermissionsAttribute.cs index e40c5b103..ced05439a 100644 --- a/DisCatSharp.CommandsNext/Attributes/RequireBotPermissionsAttribute.cs +++ b/DisCatSharp.CommandsNext/Attributes/RequireBotPermissionsAttribute.cs @@ -1,77 +1,77 @@ // This file is part of the DisCatSharp project, based off 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.CommandsNext.Attributes { /// /// Defines that usage of this command is only possible when the bot is granted a specific permission. /// - [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, AllowMultiple = false, Inherited = false)] + [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, Inherited = false)] public sealed class RequireBotPermissionsAttribute : CheckBaseAttribute { /// /// 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 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 RequireBotPermissionsAttribute(Permissions permissions, bool ignoreDms = true) { this.Permissions = permissions; this.IgnoreDms = ignoreDms; } /// /// Executes the a check. /// /// The command context. /// If true, help - returns true. public override async Task ExecuteCheckAsync(CommandContext ctx, bool help) { 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.CommandsNext/Attributes/RequireCertifiedModeratorAttribute.cs b/DisCatSharp.CommandsNext/Attributes/RequireCertifiedModeratorAttribute.cs index 8dd7d25e1..ff4d4eab8 100644 --- a/DisCatSharp.CommandsNext/Attributes/RequireCertifiedModeratorAttribute.cs +++ b/DisCatSharp.CommandsNext/Attributes/RequireCertifiedModeratorAttribute.cs @@ -1,41 +1,41 @@ // This file is part of the DisCatSharp project, based off 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.CommandsNext.Attributes { /// /// Defines that usage of this command is restricted to discord certified moderators. /// - [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, AllowMultiple = false, Inherited = false)] + [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, Inherited = false)] public sealed class RequireCertifiedModeratorAttribute : CheckBaseAttribute { /// /// Executes the a check. /// /// The command context. /// If true, help - returns true. public override Task ExecuteCheckAsync(CommandContext ctx, bool help) => ctx.User.Flags.HasValue ? Task.FromResult(ctx.User.Flags.Value.HasFlag(UserFlags.CertifiedModerator)) : Task.FromResult(false); } } diff --git a/DisCatSharp.CommandsNext/Attributes/RequireCommunityAttribute.cs b/DisCatSharp.CommandsNext/Attributes/RequireCommunityAttribute.cs index 2aac0345d..ef836d1c7 100644 --- a/DisCatSharp.CommandsNext/Attributes/RequireCommunityAttribute.cs +++ b/DisCatSharp.CommandsNext/Attributes/RequireCommunityAttribute.cs @@ -1,48 +1,48 @@ // This file is part of the DisCatSharp project, based off 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.CommandsNext.Attributes { /// /// Defines that a command is only usable within a community-enabled guild. /// /// - [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, AllowMultiple = false, Inherited = false)] + [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, Inherited = false)] public sealed class RequireCommunityAttribute : CheckBaseAttribute { /// /// Defines that this command is only usable within a community-enabled guild. /// public RequireCommunityAttribute() { } /// /// Executes the a check. /// /// The command context. /// If true, help - returns true. public override Task ExecuteCheckAsync(CommandContext ctx, bool help) => Task.FromResult(ctx.Guild != null && ctx.Guild.IsCommunity); } } diff --git a/DisCatSharp.CommandsNext/Attributes/RequireDirectMessageAttribute.cs b/DisCatSharp.CommandsNext/Attributes/RequireDirectMessageAttribute.cs index 01048f8b9..1edb3a99a 100644 --- a/DisCatSharp.CommandsNext/Attributes/RequireDirectMessageAttribute.cs +++ b/DisCatSharp.CommandsNext/Attributes/RequireDirectMessageAttribute.cs @@ -1,50 +1,50 @@ // This file is part of the DisCatSharp project, based off 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.CommandsNext.Attributes { /// /// Defines that a command is only usable within a direct message channel. /// - [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, AllowMultiple = false, Inherited = false)] + [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, Inherited = false)] public sealed class RequireDirectMessageAttribute : CheckBaseAttribute { /// /// Defines that this command is only usable within a direct message channel. /// public RequireDirectMessageAttribute() { } /// /// Executes the a check. /// /// The command context. /// If true, help - returns true. public override Task ExecuteCheckAsync(CommandContext ctx, bool help) => Task.FromResult(ctx.Channel is DiscordDmChannel); } } diff --git a/DisCatSharp.CommandsNext/Attributes/RequireDisCatSharpDeveloperAttribute.cs b/DisCatSharp.CommandsNext/Attributes/RequireDisCatSharpDeveloperAttribute.cs index 1cccee85b..44d0d5743 100644 --- a/DisCatSharp.CommandsNext/Attributes/RequireDisCatSharpDeveloperAttribute.cs +++ b/DisCatSharp.CommandsNext/Attributes/RequireDisCatSharpDeveloperAttribute.cs @@ -1,46 +1,46 @@ // This file is part of the DisCatSharp project, based off 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.CommandsNext.Attributes { /// /// Defines that usage of this command is restricted to boosters. /// - [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, AllowMultiple = false, Inherited = false)] + [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, Inherited = false)] public sealed class RequireDisCatSharpDeveloperAttribute : CheckBaseAttribute { /// /// Executes the a check. /// /// The command context. /// If true, help - returns true. public override async Task 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); } } } diff --git a/DisCatSharp.CommandsNext/Attributes/RequireGuildOwnerAttribute.cs b/DisCatSharp.CommandsNext/Attributes/RequireGuildOwnerAttribute.cs index 1a940c7f0..a24471247 100644 --- a/DisCatSharp.CommandsNext/Attributes/RequireGuildOwnerAttribute.cs +++ b/DisCatSharp.CommandsNext/Attributes/RequireGuildOwnerAttribute.cs @@ -1,54 +1,54 @@ // This file is part of the DisCatSharp project, based off 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.CommandsNext.Attributes { /// /// Defines that usage of this command is restricted to the guild owner. /// - [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, AllowMultiple = false, Inherited = false)] + [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, Inherited = false)] public sealed class RequireGuildOwnerAttribute : CheckBaseAttribute { /// /// Executes the a check. /// /// The command context. /// If true, help - returns true. public override async Task ExecuteCheckAsync(CommandContext ctx, bool help) { var guild = await Task.FromResult(ctx.Guild != null); if (guild) { var owner = await Task.FromResult(ctx.Member == ctx.Guild.Owner); return owner; } else { return false; } } } } diff --git a/DisCatSharp.CommandsNext/Attributes/RequireNsfwAttribute.cs b/DisCatSharp.CommandsNext/Attributes/RequireNsfwAttribute.cs index c192a495c..49547b030 100644 --- a/DisCatSharp.CommandsNext/Attributes/RequireNsfwAttribute.cs +++ b/DisCatSharp.CommandsNext/Attributes/RequireNsfwAttribute.cs @@ -1,42 +1,42 @@ // This file is part of the DisCatSharp project, based off 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.CommandsNext.Attributes { /// /// Defines that usage of this command is restricted to NSFW channels. /// - [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, AllowMultiple = false, Inherited = false)] + [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, Inherited = false)] public sealed class RequireNsfwAttribute : CheckBaseAttribute { /// /// Executes the a check. /// /// The command context. /// If true, help - returns true. public override Task ExecuteCheckAsync(CommandContext ctx, bool help) => Task.FromResult(ctx.Channel.Guild == null || ctx.Channel.IsNsfw); } } diff --git a/DisCatSharp.CommandsNext/Attributes/RequireOwnerAttribute.cs b/DisCatSharp.CommandsNext/Attributes/RequireOwnerAttribute.cs index 5ffa0df22..d12ebe34e 100644 --- a/DisCatSharp.CommandsNext/Attributes/RequireOwnerAttribute.cs +++ b/DisCatSharp.CommandsNext/Attributes/RequireOwnerAttribute.cs @@ -1,48 +1,48 @@ // This file is part of the DisCatSharp project, based off 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.CommandsNext.Attributes { /// /// Defines that usage of this command is restricted to the owner of the bot. /// - [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, AllowMultiple = false, Inherited = false)] + [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, Inherited = false)] public sealed class RequireOwnerAttribute : CheckBaseAttribute { /// /// Executes the a check. /// /// The command context. /// If true, help - returns true. public override Task ExecuteCheckAsync(CommandContext ctx, bool help) { 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.CommandsNext/Attributes/RequireOwnerOrIdAttribute.cs b/DisCatSharp.CommandsNext/Attributes/RequireOwnerOrIdAttribute.cs index 8ac2ec966..ac87c979b 100644 --- a/DisCatSharp.CommandsNext/Attributes/RequireOwnerOrIdAttribute.cs +++ b/DisCatSharp.CommandsNext/Attributes/RequireOwnerOrIdAttribute.cs @@ -1,69 +1,69 @@ // This file is part of the DisCatSharp project, based off 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.Collections.ObjectModel; using System.Linq; using System.Threading.Tasks; namespace DisCatSharp.CommandsNext.Attributes { /// /// Requires ownership of the bot or a whitelisted id to execute this command. /// - [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, AllowMultiple = false, Inherited = false)] + [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, Inherited = false)] public sealed class RequireOwnerOrIdAttribute : CheckBaseAttribute { /// /// 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 RequireOwnerOrIdAttribute(params ulong[] userIds) { this.UserIds = new ReadOnlyCollection(userIds); } /// /// Executes the a check. /// /// The command context. /// If true, help - returns true. public override async Task ExecuteCheckAsync(CommandContext ctx, bool help) { var app = ctx.Client.CurrentApplication; var me = ctx.Client.CurrentUser; var owner = app != null ? await Task.FromResult(app.Owners.Any(x => x.Id == ctx.User.Id)) : await Task.FromResult(ctx.User.Id == me.Id); var allowed = this.UserIds.Contains(ctx.User.Id); return owner || allowed; } } } diff --git a/DisCatSharp.CommandsNext/Attributes/RequirePermissionsAttribute.cs b/DisCatSharp.CommandsNext/Attributes/RequirePermissionsAttribute.cs index 603567c64..902b620ca 100644 --- a/DisCatSharp.CommandsNext/Attributes/RequirePermissionsAttribute.cs +++ b/DisCatSharp.CommandsNext/Attributes/RequirePermissionsAttribute.cs @@ -1,87 +1,87 @@ // This file is part of the DisCatSharp project, based off 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.CommandsNext.Attributes { /// /// Defines that usage of this 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)] + [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, Inherited = false)] public sealed class RequirePermissionsAttribute : CheckBaseAttribute { /// /// 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 RequirePermissionsAttribute(Permissions permissions, bool ignoreDms = true) { this.Permissions = permissions; this.IgnoreDms = ignoreDms; } /// /// Executes the a check. /// /// The command context. /// If true, help - returns true. public override async Task ExecuteCheckAsync(CommandContext ctx, bool help) { 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.CommandsNext/Attributes/RequirePrefixesAttribute.cs b/DisCatSharp.CommandsNext/Attributes/RequirePrefixesAttribute.cs index 82e192b62..a3518a5ec 100644 --- a/DisCatSharp.CommandsNext/Attributes/RequirePrefixesAttribute.cs +++ b/DisCatSharp.CommandsNext/Attributes/RequirePrefixesAttribute.cs @@ -1,66 +1,66 @@ // This file is part of the DisCatSharp project, based off 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.CommandsNext.Attributes { /// /// Defines that usage of this command is only allowed with specific prefixes. /// - [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = false)] + [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, Inherited = false)] public sealed class RequirePrefixesAttribute : CheckBaseAttribute { /// /// Gets the array of prefixes with which execution of this command is allowed. /// public string[] Prefixes { get; } /// /// Gets or sets default help behaviour for this check. When this is enabled, invoking help without matching prefix will show the commands. /// Defaults to false. /// public bool ShowInHelp { get; set; } = false; /// /// Defines that usage of this command is only allowed with specific prefixes. /// /// Prefixes with which the execution of this command is allowed. public RequirePrefixesAttribute(params string[] prefixes) { if (prefixes?.Any() != true) throw new ArgumentNullException(nameof(prefixes), "The allowed prefix collection cannot be null or empty."); this.Prefixes = prefixes; } /// /// Executes the a check. /// /// The command context. /// If true, help - returns true. public override Task ExecuteCheckAsync(CommandContext ctx, bool help) => Task.FromResult((help && this.ShowInHelp) || this.Prefixes.Contains(ctx.Prefix, ctx.CommandsNext.GetStringComparer())); } } diff --git a/DisCatSharp.CommandsNext/Attributes/RequireRolesAttribute.cs b/DisCatSharp.CommandsNext/Attributes/RequireRolesAttribute.cs index bcb84b136..31a3edd45 100644 --- a/DisCatSharp.CommandsNext/Attributes/RequireRolesAttribute.cs +++ b/DisCatSharp.CommandsNext/Attributes/RequireRolesAttribute.cs @@ -1,108 +1,108 @@ // This file is part of the DisCatSharp project, based off 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.Collections.ObjectModel; using System.Linq; using System.Threading.Tasks; namespace DisCatSharp.CommandsNext.Attributes { /// /// Defines that usage of this command is restricted to members with specified role. Note that it's much preferred to restrict access using . /// - [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, AllowMultiple = false, Inherited = false)] + [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, Inherited = false)] public sealed class RequireRolesAttribute : CheckBaseAttribute { /// /// Gets the name of the role required to execute this command. /// public IReadOnlyList RoleNames { get; } /// /// Gets the role checking mode. Refer to for more information. /// public RoleCheckMode CheckMode { get; } /// /// Defines that usage of this command is restricted to members with specified role. Note that it's much preferred to restrict access using . /// /// Role checking mode. /// Names of the role to be verified by this check. public RequireRolesAttribute(RoleCheckMode checkMode, params string[] roleNames) { this.CheckMode = checkMode; this.RoleNames = new ReadOnlyCollection(roleNames); } /// /// Executes the a check. /// /// The command context. /// If true, help - returns true. public override Task ExecuteCheckAsync(CommandContext ctx, bool help) { if (ctx.Guild == null || ctx.Member == null) return Task.FromResult(false); var rns = ctx.Member.Roles.Select(xr => xr.Name); var rnc = rns.Count(); var ins = rns.Intersect(this.RoleNames, ctx.CommandsNext.GetStringComparer()); var inc = ins.Count(); return this.CheckMode switch { RoleCheckMode.All => Task.FromResult(this.RoleNames.Count == inc), RoleCheckMode.SpecifiedOnly => Task.FromResult(rnc == inc), RoleCheckMode.None => Task.FromResult(inc == 0), _ => Task.FromResult(inc > 0), }; } } /// /// Specifies how does check for roles. /// public enum RoleCheckMode { /// /// Member is required to have any of the specified roles. /// Any, /// /// Member is required to have all of the specified roles. /// All, /// /// Member is required to have exactly the same roles as specified; no extra roles may be present. /// SpecifiedOnly, /// /// Member is required to have none of the specified roles. /// None } } diff --git a/DisCatSharp.CommandsNext/Attributes/RequireStaffAttribute.cs b/DisCatSharp.CommandsNext/Attributes/RequireStaffAttribute.cs index 315197161..415f98e2d 100644 --- a/DisCatSharp.CommandsNext/Attributes/RequireStaffAttribute.cs +++ b/DisCatSharp.CommandsNext/Attributes/RequireStaffAttribute.cs @@ -1,41 +1,41 @@ // This file is part of the DisCatSharp project, based off 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.CommandsNext.Attributes { /// /// Defines that usage of this command is restricted to discord employees. /// - [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, AllowMultiple = false, Inherited = false)] + [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, Inherited = false)] public sealed class RequireStaffAttribute : CheckBaseAttribute { /// /// Executes the a check. /// /// The command context. /// If true, help - returns true. public override Task ExecuteCheckAsync(CommandContext ctx, bool help) => ctx.User.Flags.HasValue ? Task.FromResult(ctx.User.Flags.Value.HasFlag(UserFlags.Staff)) : Task.FromResult(false); } } diff --git a/DisCatSharp.CommandsNext/Attributes/RequireUserPermissionsAttribute.cs b/DisCatSharp.CommandsNext/Attributes/RequireUserPermissionsAttribute.cs index 419e606b0..d5f57fd26 100644 --- a/DisCatSharp.CommandsNext/Attributes/RequireUserPermissionsAttribute.cs +++ b/DisCatSharp.CommandsNext/Attributes/RequireUserPermissionsAttribute.cs @@ -1,81 +1,81 @@ // This file is part of the DisCatSharp project, based off 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.CommandsNext.Attributes { /// /// Defines that usage of this command is restricted to members with specified permissions. /// - [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, AllowMultiple = false, Inherited = false)] + [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, Inherited = false)] public sealed class RequireUserPermissionsAttribute : CheckBaseAttribute { /// /// 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 RequireUserPermissionsAttribute(Permissions permissions, bool ignoreDms = true) { this.Permissions = permissions; this.IgnoreDms = ignoreDms; } /// /// Executes the a check. /// /// The command context. /// If true, help - returns true. public override Task ExecuteCheckAsync(CommandContext ctx, bool help) { 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); if ((pusr & Permissions.Administrator) != 0) return Task.FromResult(true); return (pusr & this.Permissions) == this.Permissions ? Task.FromResult(true) : Task.FromResult(false); } } } diff --git a/DisCatSharp.CommandsNext/Attributes/RequireWelcomeScreenAttribute.cs b/DisCatSharp.CommandsNext/Attributes/RequireWelcomeScreenAttribute.cs index 5c3c8ac04..8f308717e 100644 --- a/DisCatSharp.CommandsNext/Attributes/RequireWelcomeScreenAttribute.cs +++ b/DisCatSharp.CommandsNext/Attributes/RequireWelcomeScreenAttribute.cs @@ -1,47 +1,47 @@ // This file is part of the DisCatSharp project, based off 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.CommandsNext.Attributes { /// /// Defines that a command is only usable within a guild which has enabled the welcome screen. /// - [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, AllowMultiple = false, Inherited = false)] + [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, Inherited = false)] public sealed class RequireWelcomeScreenAttribute : CheckBaseAttribute { /// /// Defines that this command is only usable within a guild which has enabled the welcome screen. /// public RequireWelcomeScreenAttribute() { } /// /// Executes a check. /// /// The command context. /// If true, help - returns true. public override Task ExecuteCheckAsync(CommandContext ctx, bool help) => Task.FromResult(ctx.Guild != null && ctx.Guild.HasWelcomeScreen); } } diff --git a/DisCatSharp.Common/Attributes/DateTimeFormatAttribute.cs b/DisCatSharp.Common/Attributes/DateTimeFormatAttribute.cs index 9ffb98507..4b24cee6e 100644 --- a/DisCatSharp.Common/Attributes/DateTimeFormatAttribute.cs +++ b/DisCatSharp.Common/Attributes/DateTimeFormatAttribute.cs @@ -1,133 +1,133 @@ // This file is part of the DisCatSharp project, based off 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; // ReSharper disable InconsistentNaming namespace DisCatSharp.Common.Serialization { /// /// Defines the format for string-serialized and objects. /// - [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false, Inherited = true)] + [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)] public sealed class DateTimeFormatAttribute : SerializationAttribute { /// /// Gets the ISO 8601 format string of "yyyy-MM-ddTHH:mm:ss.fffzzz". /// public const string FORMAT_ISO_8601 = "yyyy-MM-ddTHH:mm:ss.fffzzz"; /// /// Gets the RFC 1123 format string of "R". /// public const string FORMAT_RFC_1123 = "R"; /// /// Gets the general long format. /// public const string FORMAT_LONG = "G"; /// /// Gets the general short format. /// public const string FORMAT_SHORT = "g"; /// /// Gets the custom datetime format string to use. /// public string Format { get; } /// /// Gets the predefined datetime format kind. /// public DateTimeFormatKind Kind { get; } /// /// Specifies a predefined format to use. /// /// Predefined format kind to use. public DateTimeFormatAttribute(DateTimeFormatKind kind) { if (kind < 0 || kind > DateTimeFormatKind.InvariantLocaleShort) throw new ArgumentOutOfRangeException(nameof(kind), "Specified format kind is not legal or supported."); this.Kind = kind; this.Format = null; } /// /// Specifies a custom format to use. /// See https://docs.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings for more details. /// /// Custom format string to use. public DateTimeFormatAttribute(string format) { if (string.IsNullOrWhiteSpace(format)) throw new ArgumentNullException(nameof(format), "Specified format cannot be null or empty."); this.Kind = DateTimeFormatKind.Custom; this.Format = format; } } /// /// Defines which built-in format to use for for and serialization. /// See https://docs.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings and https://docs.microsoft.com/en-us/dotnet/standard/base-types/standard-date-and-time-format-strings for more details. /// public enum DateTimeFormatKind : int { /// /// Specifies ISO 8601 format, which is equivalent to .NET format string of "yyyy-MM-ddTHH:mm:ss.fffzzz". /// ISO8601 = 0, /// /// Specifies RFC 1123 format, which is equivalent to .NET format string of "R". /// RFC1123 = 1, /// /// Specifies a format defined by , with a format string of "G". This format is not recommended for portability reasons. /// CurrentLocaleLong = 2, /// /// Specifies a format defined by , with a format string of "g". This format is not recommended for portability reasons. /// CurrentLocaleShort = 3, /// /// Specifies a format defined by , with a format string of "G". /// InvariantLocaleLong = 4, /// /// Specifies a format defined by , with a format string of "g". /// InvariantLocaleShort = 5, /// /// Specifies a custom format. This value is not usable directly. /// Custom = int.MaxValue } } diff --git a/DisCatSharp.Common/Attributes/DecomposerAttribute.cs b/DisCatSharp.Common/Attributes/DecomposerAttribute.cs index 9a775de28..76ef89b13 100644 --- a/DisCatSharp.Common/Attributes/DecomposerAttribute.cs +++ b/DisCatSharp.Common/Attributes/DecomposerAttribute.cs @@ -1,50 +1,50 @@ // This file is part of the DisCatSharp project, based off 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.Common.Serialization { /// /// Specifies a decomposer for a given type or property. /// - [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false, Inherited = true)] + [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Property | AttributeTargets.Field)] public sealed class DecomposerAttribute : SerializationAttribute { /// /// Gets the type of the decomposer. /// public Type DecomposerType { get; } /// /// Specifies a decomposer for given type or property. /// /// Type of decomposer to use. public DecomposerAttribute(Type type) { if (!typeof(IDecomposer).IsAssignableFrom(type) || !type.IsClass || type.IsAbstract) // abstract covers static - static = abstract + sealed throw new ArgumentException("Invalid type specified. Must be a non-abstract class which implements DisCatSharp.Common.Serialization.IDecomposer interface.", nameof(type)); this.DecomposerType = type; } } } diff --git a/DisCatSharp.Common/Attributes/EnumAttributes.cs b/DisCatSharp.Common/Attributes/EnumAttributes.cs index 603e73d0b..a754e83b4 100644 --- a/DisCatSharp.Common/Attributes/EnumAttributes.cs +++ b/DisCatSharp.Common/Attributes/EnumAttributes.cs @@ -1,42 +1,42 @@ // This file is part of the DisCatSharp project, based off 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.Common.Serialization { /// /// Specifies that this enum should be serialized and deserialized as its underlying numeric type. /// This is used to change the behaviour of enum serialization. /// - [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false, Inherited = true)] + [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)] public sealed class NumericEnumAttribute : SerializationAttribute { } /// /// Specifies that this enum should be serialized and deserialized as its string representation. /// This is used to change the behaviour of enum serialization. /// - [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false, Inherited = true)] + [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)] public sealed class StringEnumAttribute : SerializationAttribute { } } diff --git a/DisCatSharp.Common/Attributes/IncludeNullAttribute.cs b/DisCatSharp.Common/Attributes/IncludeNullAttribute.cs index 2b1ff2781..45473c1cd 100644 --- a/DisCatSharp.Common/Attributes/IncludeNullAttribute.cs +++ b/DisCatSharp.Common/Attributes/IncludeNullAttribute.cs @@ -1,35 +1,35 @@ // This file is part of the DisCatSharp project, based off 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.Common.Serialization { /// /// Specifies that if the value of the field or property is null, it should be included in the serialized data. /// This alters the default behaviour of ignoring nulls. /// [Obsolete("Use [DataMember] with EmitDefaultValue = true.")] - [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false, Inherited = true)] + [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)] public sealed class IncludeNullAttribute : SerializationAttribute { } } diff --git a/DisCatSharp.Common/Attributes/Int53Attribute.cs b/DisCatSharp.Common/Attributes/Int53Attribute.cs index 1c040d878..503c3e1dd 100644 --- a/DisCatSharp.Common/Attributes/Int53Attribute.cs +++ b/DisCatSharp.Common/Attributes/Int53Attribute.cs @@ -1,46 +1,46 @@ // This file is part of the DisCatSharp project, based off 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.Common.Serialization { /// /// Specifies that this 64-bit integer uses no more than 53 bits to represent its value. /// This is used to indicate that large numbers are safe for direct serialization into formats which do support 64-bit integers natively (such as JSON). /// - [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false, Inherited = true)] + [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)] public sealed class Int53Attribute : SerializationAttribute { /// /// Gets the maximum safe value representable as an integer by a IEEE754 64-bit binary floating point value. /// This value equals to 9007199254740991. /// public const long MAX_VALUE = (1L << 53) - 1; /// /// Gets the minimum safe value representable as an integer by a IEEE754 64-bit binary floating point value. /// This value equals to -9007199254740991. /// public const long MIN_VALUE = -MAX_VALUE; } } diff --git a/DisCatSharp.Common/Attributes/SerializedNameAttribute.cs b/DisCatSharp.Common/Attributes/SerializedNameAttribute.cs index f85f70c4b..9e28d4489 100644 --- a/DisCatSharp.Common/Attributes/SerializedNameAttribute.cs +++ b/DisCatSharp.Common/Attributes/SerializedNameAttribute.cs @@ -1,48 +1,48 @@ // This file is part of the DisCatSharp project, based off 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.Common.Serialization { /// /// Declares name of a property in serialized data. This is used for mapping serialized data to object properties and fields. /// [Obsolete("Use [DataMember] with set Name instead.")] - [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false, Inherited = true)] + [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)] public sealed class SerializedNameAttribute : SerializationAttribute { /// /// Gets the serialized name of the field or property. /// public string Name { get; } /// /// Declares name of a property in serialized data. This is used for mapping serialized data to object properties and fields. /// /// Name of the field or property in serialized data. public SerializedNameAttribute(string name) { this.Name = name; } } } diff --git a/DisCatSharp.Common/Attributes/TimeSpanAttributes.cs b/DisCatSharp.Common/Attributes/TimeSpanAttributes.cs index 7ac844dcc..0de246a7a 100644 --- a/DisCatSharp.Common/Attributes/TimeSpanAttributes.cs +++ b/DisCatSharp.Common/Attributes/TimeSpanAttributes.cs @@ -1,42 +1,42 @@ // This file is part of the DisCatSharp project, based off 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.Common.Serialization { /// /// Specifies that this will be serialized as a number of whole seconds. /// This value will always be serialized as a number. /// - [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false, Inherited = true)] + [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)] public sealed class TimeSpanSecondsAttribute : SerializationAttribute { } /// /// Specifies that this will be serialized as a number of whole milliseconds. /// This value will always be serialized as a number. /// - [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false, Inherited = true)] + [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)] public sealed class TimeSpanMillisecondsAttribute : SerializationAttribute { } } diff --git a/DisCatSharp.Common/Attributes/TimeSpanFormatAttribute.cs b/DisCatSharp.Common/Attributes/TimeSpanFormatAttribute.cs index b46d57755..0eacd42ad 100644 --- a/DisCatSharp.Common/Attributes/TimeSpanFormatAttribute.cs +++ b/DisCatSharp.Common/Attributes/TimeSpanFormatAttribute.cs @@ -1,133 +1,133 @@ // This file is part of the DisCatSharp project, based off 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; // ReSharper disable InconsistentNaming namespace DisCatSharp.Common.Serialization { /// /// Defines the format for string-serialized objects. /// - [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false, Inherited = true)] + [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)] public sealed class TimeSpanFormatAttribute : SerializationAttribute { /// /// Gets the ISO 8601 format string of @"ddThh\:mm\:ss\.fff". /// public const string FORMAT_ISO_8601 = @"ddThh\:mm\:ss\.fff"; /// /// Gets the constant format. /// public const string FORMAT_CONSTANT = "c"; /// /// Gets the general long format. /// public const string FORMAT_LONG = "G"; /// /// Gets the general short format. /// public const string FORMAT_SHORT = "g"; /// /// Gets the custom datetime format string to use. /// public string Format { get; } /// /// Gets the predefined datetime format kind. /// public TimeSpanFormatKind Kind { get; } /// /// Specifies a predefined format to use. /// /// Predefined format kind to use. public TimeSpanFormatAttribute(TimeSpanFormatKind kind) { if (kind < 0 || kind > TimeSpanFormatKind.InvariantLocaleShort) throw new ArgumentOutOfRangeException(nameof(kind), "Specified format kind is not legal or supported."); this.Kind = kind; this.Format = null; } /// /// Specifies a custom format to use. /// See https://docs.microsoft.com/en-us/dotnet/standard/base-types/custom-timespan-format-strings for more details. /// /// Custom format string to use. public TimeSpanFormatAttribute(string format) { if (string.IsNullOrWhiteSpace(format)) throw new ArgumentNullException(nameof(format), "Specified format cannot be null or empty."); this.Kind = TimeSpanFormatKind.Custom; this.Format = format; } } /// /// Defines which built-in format to use for serialization. /// See https://docs.microsoft.com/en-us/dotnet/standard/base-types/standard-timespan-format-strings and https://docs.microsoft.com/en-us/dotnet/standard/base-types/custom-timespan-format-strings for more details. /// public enum TimeSpanFormatKind : int { /// /// Specifies ISO 8601-like time format, which is equivalent to .NET format string of @"ddThh\:mm\:ss\.fff". /// ISO8601 = 0, /// /// Specifies a format defined by , with a format string of "c". /// InvariantConstant = 1, /// /// Specifies a format defined by , with a format string of "G". This format is not recommended for portability reasons. /// CurrentLocaleLong = 2, /// /// Specifies a format defined by , with a format string of "g". This format is not recommended for portability reasons. /// CurrentLocaleShort = 3, /// /// Specifies a format defined by , with a format string of "G". This format is not recommended for portability reasons. /// InvariantLocaleLong = 4, /// /// Specifies a format defined by , with a format string of "g". This format is not recommended for portability reasons. /// InvariantLocaleShort = 5, /// /// Specifies a custom format. This value is not usable directly. /// Custom = int.MaxValue } } diff --git a/DisCatSharp.Common/Attributes/UnixTimestampAttributes.cs b/DisCatSharp.Common/Attributes/UnixTimestampAttributes.cs index b4abd7af7..236b07f35 100644 --- a/DisCatSharp.Common/Attributes/UnixTimestampAttributes.cs +++ b/DisCatSharp.Common/Attributes/UnixTimestampAttributes.cs @@ -1,42 +1,42 @@ // This file is part of the DisCatSharp project, based off 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.Common.Serialization { /// /// Specifies that this or will be serialized as Unix timestamp seconds. /// This value will always be serialized as a number. /// - [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false, Inherited = true)] + [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)] public sealed class UnixSecondsAttribute : SerializationAttribute { } /// /// Specifies that this or will be serialized as Unix timestamp milliseconds. /// This value will always be serialized as a number. /// - [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false, Inherited = true)] + [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)] public sealed class UnixMillisecondsAttribute : SerializationAttribute { } } diff --git a/DisCatSharp/Enums/Discord/DiscordDomain.cs b/DisCatSharp/Enums/Discord/DiscordDomain.cs index 104e22fad..367e4fd38 100644 --- a/DisCatSharp/Enums/Discord/DiscordDomain.cs +++ b/DisCatSharp/Enums/Discord/DiscordDomain.cs @@ -1,269 +1,269 @@ // This file is part of the DisCatSharp project, based off 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; namespace DisCatSharp.Enums { /// /// Core Domains /// public enum CoreDomain { /// /// dis.gd /// [DomainHelp("Marketing URL shortner", "dis.gd")] DiscordMarketing = 1, /// /// discord.co /// [DomainHelp("Admin panel, internal tools", "discord.co")] DiscordAdmin = 2, /// /// discord.com /// [DomainHelp("New app, marketing website, API host", "discord.com")] Discord = 3, /// /// discord.design /// [DomainHelp("Dribbble profile shortlink", "discord.design")] DiscordDesign = 4, /// /// discord.dev /// [DomainHelp("Developer site shortlinks", "discord.dev")] DiscordDev = 5, /// /// discord.gg /// [DomainHelp("Invite shortlinks", "discord.gg")] DiscordShortlink = 6, /// /// discord.gift /// [DomainHelp("Gift shortlinks", "discord.gift")] DiscordGift = 7, /// /// discord.media /// [DomainHelp("Voice servers", "discord.media")] DiscordMedia = 8, /// /// discord.new /// [DomainHelp("Template shortlinks", "discord.new")] DiscordTemplate = 9, /// /// discord.store /// [DomainHelp("Merch store", "discord.store")] DiscordMerch = 10, /// /// discord.tools /// [DomainHelp("Internal tools", "discord.tools")] DiscordTools = 11, /// /// discordapp.com /// [DomainHelp("Old app, marketing website, and API; CDN", "discordapp.com")] DiscordAppOld = 12, /// /// discordapp.net /// [DomainHelp("Media Proxy", "discordapp.net")] DiscordAppMediaProxy = 13, /// /// discordmerch.com /// [DomainHelp("Merch store", "discordmerch.com")] DiscordMerchOld = 14, /// /// discordpartygames.com /// [DomainHelp("Voice channel activity API host", "discordpartygames.com")] DiscordActivityAlt = 15, /// /// discord-activities.com /// [DomainHelp("Voice channel activity API host", "discord-activities.com")] DiscordActivityAlt2 = 16, /// /// discordsays.com /// [DomainHelp("Voice channel activity host", "discordsays.com")] DiscordActivity = 17, /// /// discordstatus.com /// [DomainHelp("Status page", "discordstatus.com")] DiscordStatus = 18, /// /// cdn.discordapp.com /// [DomainHelp("CDN", "cdn.discordapp.com")] DiscordCdn = 19, } /// /// Other Domains /// public enum OtherDomain { /// /// airhorn.solutions /// [DomainHelp("API implementation example", "airhorn.solutions")] Airhorn = 1, /// /// airhornbot.com /// [DomainHelp("API implementation example", "airhornbot.com")] AirhornAlt = 2, /// /// bigbeans.solutions /// [DomainHelp("April Fools 2017", "bigbeans.solutions")] AprilFools = 3, /// /// watchanimeattheoffice.com /// [DomainHelp("HypeSquad form placeholder/meme", "watchanimeattheoffice.com")] HypeSquadMeme = 4 } /// /// Core Domains /// public enum UnusedDomain { /// /// discordapp.io /// [Obsolete("Not in use", false)] [DomainHelp("IO domain for discord", "discordapp.io")] DiscordAppIo = 1, /// /// discordcdn.com /// [Obsolete("Not in use", false)] [DomainHelp("Alternative CDN domain", "discordcdn.com")] DiscordCdnCom = 2 } /// /// Represents a discord domain. /// public static class DiscordDomain { /// /// Gets a domain. /// Valid types: , and . /// /// The domain type. /// A DomainHelpAttribute. public static DomainHelpAttribute GetDomain(Enum domainEnum) { if (domainEnum is not CoreDomain && domainEnum is not OtherDomain && domainEnum is not UnusedDomain) throw new NotSupportedException($"Invalid type. Found: {domainEnum.GetType()} Expected: CoreDomain or OtherDomain or UnusedDomain"); if (domainEnum is CoreDomain domain && (domain == CoreDomain.DiscordAdmin || domain == CoreDomain.DiscordTools)) throw new UnauthorizedAccessException("You don't have access to this domains"); var memberInfo = domainEnum.GetType().GetMember(domainEnum.ToString()).FirstOrDefault(); if (memberInfo != null) { var attribute = (DomainHelpAttribute)memberInfo.GetCustomAttributes(typeof(DomainHelpAttribute), false).FirstOrDefault(); return attribute; } return null; } } /// /// Defines a description and url for this domain. /// - [AttributeUsage(AttributeTargets.All, AllowMultiple = false)] + [AttributeUsage(AttributeTargets.All)] public class DomainHelpAttribute : Attribute { /// /// Gets the Description for this domain. /// public string Description { get; } /// /// Gets the Uri for this domain. /// public Uri Uri { get; } /// /// Gets the Domain for this domain. /// public string Domain { get; } /// /// Gets the Url for this domain. /// public string Url { get; } /// /// Defines a description and URIs for this domain. /// /// Description for this domain. /// Url for this domain. public DomainHelpAttribute(string desc, string domain) { this.Description = desc; this.Domain = domain; var url = $"https://{domain}"; this.Url = url; this.Uri = new Uri(url); } } } diff --git a/DisCatSharp/Enums/Permission.cs b/DisCatSharp/Enums/Permission.cs index 852bdeb45..51a5d383e 100644 --- a/DisCatSharp/Enums/Permission.cs +++ b/DisCatSharp/Enums/Permission.cs @@ -1,363 +1,363 @@ // This file is part of the DisCatSharp project, based off 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 { /// /// Represents permission methods. /// public static class PermissionMethods { /// /// Gets the full permissions enum (long). /// internal static Permissions FullPerms { get; } = (Permissions)2199023255551L; /// /// Calculates whether this permission set contains the given permission. /// /// The permissions to calculate from /// permission you want to check /// public static bool HasPermission(this Permissions p, Permissions permission) => p.HasFlag(Permissions.Administrator) || (p & permission) == permission; /// /// Grants permissions. /// /// The permissions to add to. /// Permission to add. /// public static Permissions Grant(this Permissions p, Permissions grant) => p | grant; /// /// Revokes permissions. /// /// The permissions to take from. /// Permission to take. /// public static Permissions Revoke(this Permissions p, Permissions revoke) => p & ~revoke; } /// /// Whether a permission is allowed, denied or unset /// public enum PermissionLevel { /// /// Said permission is Allowed /// Allowed, /// /// Said permission is Denied /// Denied, /// /// Said permission is Unset /// Unset } /// /// Bitwise permission flags. /// [Flags] public enum Permissions : long { /// /// Indicates no permissions given. /// [PermissionString("No permissions")] None = 0x0000000000000000, /// /// Indicates all permissions are granted /// [PermissionString("All permissions")] All = 2199023255551, /// /// Allows creation of instant channel invites. /// [PermissionString("Create instant invites")] CreateInstantInvite = 0x0000000000000001, /// /// Allows kicking members. /// [PermissionString("Kick members")] KickMembers = 0x0000000000000002, /// /// Allows banning and unbanning members. /// [PermissionString("Ban members")] BanMembers = 0x0000000000000004, /// /// Enables full access on a given guild. This also overrides other permissions. /// [PermissionString("Administrator")] Administrator = 0x0000000000000008, /// /// Allows managing channels. /// [PermissionString("Manage channels")] ManageChannels = 0x0000000000000010, /// /// Allows managing the guild. /// [PermissionString("Manage guild")] ManageGuild = 0x0000000000000020, /// /// Allows adding reactions to messages. /// [PermissionString("Add reactions")] AddReactions = 0x0000000000000040, /// /// Allows viewing audit log entries. /// [PermissionString("View audit log")] ViewAuditLog = 0x0000000000000080, /// /// Allows the use of priority speaker. /// [PermissionString("Use priority speaker")] PrioritySpeaker = 0x0000000000000100, /// /// Allows accessing text and voice channels. Disabling this permission hides channels. /// [PermissionString("Read messages")] AccessChannels = 0x0000000000000400, /// /// Allows sending messages (does not allow sending messages in threads). /// [PermissionString("Send messages")] SendMessages = 0x0000000000000800, /// /// Allows sending text-to-speech messages. /// [PermissionString("Send TTS messages")] SendTtsMessages = 0x0000000000001000, /// /// Allows managing messages of other users. /// [PermissionString("Manage messages")] ManageMessages = 0x0000000000002000, /// /// Allows embedding content in messages. /// [PermissionString("Use embeds")] EmbedLinks = 0x0000000000004000, /// /// Allows uploading files. /// [PermissionString("Attach files")] AttachFiles = 0x0000000000008000, /// /// Allows reading message history. /// [PermissionString("Read message history")] ReadMessageHistory = 0x0000000000010000, /// /// Allows using @everyone and @here mentions. /// [PermissionString("Mention everyone")] MentionEveryone = 0x0000000000020000, /// /// Allows using emojis from external servers, such as twitch or nitro emojis. /// [PermissionString("Use external emojis")] UseExternalEmojis = 0x0000000000040000, /// /// Allows connecting to voice chat. /// [PermissionString("Use voice chat")] UseVoice = 0x0000000000100000, /// /// Allows speaking in voice chat. /// [PermissionString("Speak")] Speak = 0x0000000000200000, /// /// Allows muting other members in voice chat. /// [PermissionString("Mute voice chat members")] MuteMembers = 0x0000000000400000, /// /// Allows deafening other members in voice chat. /// [PermissionString("Deafen voice chat members")] DeafenMembers = 0x0000000000800000, /// /// Allows moving voice chat members. /// [PermissionString("Move voice chat members")] MoveMembers = 0x0000000001000000, /// /// Allows using voice activation in voice chat. Revoking this will usage of push-to-talk. /// [PermissionString("Use voice activity detection")] UseVoiceDetection = 0x0000000002000000, /// /// Allows changing of own nickname. /// [PermissionString("Change own nickname")] ChangeNickname = 0x0000000004000000, /// /// Allows managing nicknames of other members. /// [PermissionString("Manage nicknames")] ManageNicknames = 0x0000000008000000, /// /// Allows managing roles in a guild. /// [PermissionString("Manage roles")] ManageRoles = 0x0000000010000000, /// /// Allows managing webhooks in a guild. /// [PermissionString("Manage webhooks")] ManageWebhooks = 0x0000000020000000, /// /// Allows managing guild emojis and stickers. /// [PermissionString("Manage emojis & stickers")] ManageEmojisAndStickers = 0x0000000040000000, /// /// Allows the user to go live. /// [PermissionString("Allow stream")] Stream = 0x0000000000000200, /// /// Allows the user to use slash commands. /// [PermissionString("Use application commands")] UseApplicationCommands = 0x0000000080000000, /// /// Allows for requesting to speak in stage channels. /// [PermissionString("Request to speak")] RequestToSpeak = 0x0000000100000000, /// /// Allows managing guild events. /// [PermissionString("Manage Events")] ManageEvents = 0x0000000200000000, /// /// Allows for deleting and archiving threads, and viewing all private threads. /// [PermissionString("Manage Threads")] ManageThreads = 0x0000000400000000, /// /// Allows for creating threads. /// [PermissionString("Create Public Threads")] CreatePublicThreads = 0x0000000800000000, /// /// Allows for creating private threads. /// [PermissionString("Create Private Threads")] CreatePrivateThreads = 0x0000001000000000, /// /// Allows the usage of custom stickers from other servers. /// [PermissionString("Use external Stickers")] UseExternalStickers = 0x0000002000000000, /// /// Allows for sending messages in threads. /// [PermissionString("Send messages in Threads")] SendMessagesInThreads = 0x0000004000000000, /// /// Allows for launching activities (applications with the `EMBEDDED` flag) in a voice channel. /// [PermissionString("Start Embedded Activities")] StartEmbeddedActivities = 0x0000008000000000, /// /// Allows to perform limited moderation actions (timeout). /// [PermissionString("Moderate Members")] ModerateMembers = 0x0000010000000000 } /// /// Defines a readable name for this permission. /// - [AttributeUsage(AttributeTargets.Field, AllowMultiple = false)] + [AttributeUsage(AttributeTargets.Field)] public sealed class PermissionStringAttribute : Attribute { /// /// Gets the readable name for this permission. /// public string String { get; } /// /// Defines a readable name for this permission. /// /// Readable name for this permission. public PermissionStringAttribute(string str) { this.String = str; } } }