├── .editorconfig
├── .gitattributes
├── .github
└── FUNDING.yml
├── .gitignore
├── LICENSE
├── README.md
├── RevoltSharp.Challenge
├── Class1.cs
├── PackageIcon.png
└── RevoltSharp.Challenge.csproj
├── RevoltSharp.Commands
├── Attributes
│ ├── AliasAttribute.cs
│ ├── CommandAttribute.cs
│ ├── DontAutoLoadAttribute.cs
│ ├── DontInjectAttribute.cs
│ ├── GroupAttribute.cs
│ ├── NameAttribute.cs
│ ├── NamedArgumentTypeAttribute.cs
│ ├── OverrideTypeReaderAttribute.cs
│ ├── ParameterPreconditionAttribute.cs
│ ├── PreconditionAttribute.cs
│ ├── Preconditions
│ │ ├── RequireBotPermissionAttribute.cs
│ │ ├── RequireContextAttribute.cs
│ │ ├── RequireDMAttribute.cs
│ │ ├── RequireGroupAttribute.cs
│ │ ├── RequireGroupOwnerAttribute.cs
│ │ ├── RequireOwnerAttribute.cs
│ │ ├── RequireServerAttribute.cs
│ │ ├── RequireServerOwnerAttribute.cs
│ │ ├── RequireUserPermissionAttribute.cs
│ │ └── TemplateAttribute.cs
│ ├── PriorityAttribute.cs
│ ├── RemainderAttribute.cs
│ ├── RemarksAttribute.cs
│ └── SummaryAttribute.cs
├── Builders
│ ├── CommandBuilder.cs
│ ├── ModuleBuilder.cs
│ ├── ModuleClassBuilder.cs
│ └── ParameterBuilder.cs
├── CommandContext.cs
├── CommandError.cs
├── CommandException.cs
├── CommandMatch.cs
├── CommandParser.cs
├── CommandService.cs
├── CommandServiceConfig.cs
├── EmptyServiceProvider.cs
├── Extensions
│ ├── CommandServiceExtensions.cs
│ ├── IEnumerableExtensions.cs
│ └── MessageExtensions.cs
├── IModuleBase.cs
├── Info
│ ├── CommandInfo.cs
│ ├── ModuleInfo.cs
│ └── ParameterInfo.cs
├── Map
│ ├── CommandMap.cs
│ └── CommandMapNode.cs
├── ModuleBase.cs
├── MultiMatchHandling.cs
├── PackageIcon.png
├── PrimitiveParsers.cs
├── Readers
│ ├── EnumTypeReader.cs
│ ├── NamedArgumentTypeReader.cs
│ ├── NullableTypeReader.cs
│ ├── PrimitiveTypeReader.cs
│ ├── TimeSpanTypeReader.cs
│ └── TypeReader.cs
├── Results
│ ├── ExecuteResult.cs
│ ├── IResult.cs
│ ├── ParseResult.cs
│ ├── PreconditionGroupResult.cs
│ ├── PreconditionResult.cs
│ ├── RuntimeResult.cs
│ ├── SearchResult.cs
│ └── TypeReaderResult.cs
├── RevoltSharp.Commands.csproj
├── RevoltSharp.Commands.xml
└── Utilities
│ ├── QuotationAliasUtils.cs
│ └── ReflectionUtils.cs
├── RevoltSharp.InstanceAdmin
├── AdminConditions.cs
├── Core
│ ├── SafetyReport.cs
│ ├── SafetyReportContent.cs
│ ├── SafetyReportJson.cs
│ ├── SafetyUserStrike.cs
│ └── SafetyUserStrikeJson.cs
├── PackageIcon.png
├── Requests
│ ├── AdminGetMessagesRequest.cs
│ ├── AdminMessagesDataJson.cs
│ ├── AdminReportModifyRequest.cs
│ ├── AdminStrikeCreateRequest.cs
│ ├── AdminStrikeModifyRequest.cs
│ └── ReportContentRequest.cs
├── Rest
│ ├── AdminHelper.cs
│ └── SafetyHelper.cs
├── RevoltSharp.InstanceAdmin.csproj
└── RevoltSharp.InstanceAdmin.xml
├── RevoltSharp.Voice
├── PackageIcon.png
├── Requests
│ ├── AuthenticateRequest.cs
│ └── InitilizeTransportRequest.cs
├── RevoltSharp.Voice.csproj
├── RevoltSharp.Voice.xml
├── RevoltVoiceClient.cs
├── VoiceHelper.cs
├── VoiceRequestJson.cs
├── VoiceSocketClient.cs
└── VoiceState.cs
├── RevoltSharp.sln
├── RevoltSharp
├── AssemblyInfo.cs
├── Client
│ ├── ClientConfig.cs
│ ├── ClientEvents.cs
│ ├── LoginResponseType.cs
│ ├── RevoltClient.cs
│ ├── RevoltClientHelper.cs
│ ├── RevoltException.cs
│ └── RevoltLogger.cs
├── Core
│ ├── Account
│ │ ├── AccountInfo.cs
│ │ ├── AccountInfoJson.cs
│ │ ├── AccountLogin.cs
│ │ ├── AccountLoginJson.cs
│ │ ├── AccountMFA.cs
│ │ ├── AccountMFAJson.cs
│ │ ├── AccountSession.cs
│ │ ├── AccountSessionJson.cs
│ │ ├── AccountType.cs
│ │ ├── ChannelReadState.cs
│ │ ├── ChannelReadStateJson.cs
│ │ ├── MFAType.cs
│ │ └── OnboardStatus.cs
│ ├── Bots
│ │ ├── PublicBot.cs
│ │ └── PublicBotJson.cs
│ ├── Channels
│ │ ├── Channel.cs
│ │ ├── ChannelJson.cs
│ │ ├── DmChannel.cs
│ │ ├── GroupChannel.cs
│ │ ├── PartialChannelJson.cs
│ │ ├── SavedMessagesChannel.cs
│ │ ├── ServerChannel.cs
│ │ ├── TextChannel.cs
│ │ ├── UnknownChannel.cs
│ │ └── VoiceChannel.cs
│ ├── Client
│ │ ├── Query.cs
│ │ └── QueryJson.cs
│ ├── Emotes
│ │ ├── Emoji.cs
│ │ └── EmojiJson.cs
│ ├── Entity.cs
│ ├── Enums
│ │ ├── ChannelPermission.cs
│ │ ├── ChannelPermissions.cs
│ │ ├── ChannelType.cs
│ │ ├── MessageFlag.cs
│ │ ├── RevoltErrorType.cs
│ │ ├── ServerPermission.cs
│ │ └── ServerPermissions.cs
│ ├── IVoiceClient.cs
│ ├── Messages
│ │ ├── Attachment.cs
│ │ ├── AttachmentJson.cs
│ │ ├── BulkMessagesJson.cs
│ │ ├── Embed.cs
│ │ ├── EmbedJson.cs
│ │ ├── FileAttachment.cs
│ │ ├── FileAttachmentJson.cs
│ │ ├── Message.cs
│ │ ├── MessageInteractions.cs
│ │ ├── MessageInteractionsJson.cs
│ │ ├── MessageJson.cs
│ │ ├── MessageMasquerade.cs
│ │ ├── MessageReply.cs
│ │ ├── MessageReplyJson.cs
│ │ ├── MessageSortType.cs
│ │ ├── MessageWebhook.cs
│ │ ├── MessageWebhookJson.cs
│ │ ├── SystemData.cs
│ │ ├── SystemMessage.cs
│ │ ├── SystemType.cs
│ │ └── UserMessage.cs
│ ├── RetryRequest.cs
│ ├── RevoltColor.cs
│ ├── Servers
│ │ ├── Category.cs
│ │ ├── CategoryJson.cs
│ │ ├── Invite.cs
│ │ ├── InviteJson.cs
│ │ ├── MembersListJson.cs
│ │ ├── PartialRoleJson.cs
│ │ ├── PartialServerJson.cs
│ │ ├── PartialServerMemberJson.cs
│ │ ├── Role.cs
│ │ ├── RoleJson.cs
│ │ ├── Server.cs
│ │ ├── ServerBan.cs
│ │ ├── ServerBansJson.cs
│ │ ├── ServerJson.cs
│ │ ├── ServerMember.cs
│ │ ├── ServerMemberJson.cs
│ │ └── ServerSystemMessages.cs
│ ├── SocketError.cs
│ ├── Updated
│ │ ├── ChannelUpdatedProperties.cs
│ │ ├── MessageUpdatedProperties.cs
│ │ ├── RoleUpdatedProperties.cs
│ │ ├── SelfUserUpdatedProperties.cs
│ │ ├── ServerUpdatedProperties.cs
│ │ └── UserUpdatedProperties.cs
│ ├── Users
│ │ ├── AvatarSources.cs
│ │ ├── PartialUserJson.cs
│ │ ├── Profile.cs
│ │ ├── ProfileJson.cs
│ │ ├── SelfUser.cs
│ │ ├── User.cs
│ │ ├── UserBadges.cs
│ │ ├── UserFlags.cs
│ │ ├── UserJson.cs
│ │ ├── UserMutuals.cs
│ │ ├── UserMutualsJson.cs
│ │ └── UserStatus.cs
│ └── Webhooks
│ │ ├── Webhook.cs
│ │ ├── WebhookJson.cs
│ │ ├── WebhookPermission.cs
│ │ └── WebhookPermissions.cs
├── Extensions
│ ├── Conditions.cs
│ ├── Const.cs
│ ├── Downloadable.cs
│ ├── EmojiList.cs
│ ├── Format.cs
│ ├── Option.cs
│ ├── Optional
│ │ ├── Option.cs
│ │ ├── Option_Maybe.cs
│ │ ├── OptionalDeserializerConverter.cs
│ │ ├── OptionalSerializerConverter.cs
│ │ └── RevoltContractResolver.cs
│ ├── QueryBuilder.cs
│ ├── StringExtensions.cs
│ ├── TimestampExtension.cs
│ ├── Ulid.cs
│ ├── UlidStringHelper.cs
│ └── UlidTimestampHelper.cs
├── Internal
│ ├── AdminClient.cs
│ ├── DisableConsoleQuickEdit.cs
│ ├── GlobalExtensions.cs
│ └── ModelExtensions.cs
├── PackageIcon.png
├── Rest
│ ├── Helpers
│ │ ├── Account
│ │ │ └── AccountHelper.cs
│ │ ├── Bot
│ │ │ ├── BotHelper.cs
│ │ │ ├── SelfUserHelper.cs
│ │ │ └── UserHelper.cs
│ │ ├── Messages
│ │ │ ├── ChannelHelper.cs
│ │ │ ├── GroupChannelHelper.cs
│ │ │ ├── MessageHelper.cs
│ │ │ ├── ReactionHelpers.cs
│ │ │ └── WebhookHelper.cs
│ │ └── Servers
│ │ │ ├── CategoryHelper.cs
│ │ │ ├── EmojiHelper.cs
│ │ │ ├── InviteHelper.cs
│ │ │ ├── MemberHelper.cs
│ │ │ ├── RoleHelper.cs
│ │ │ ├── ServerHelper.cs
│ │ │ ├── TextChannelHelper.cs
│ │ │ └── VoiceChannelHelper.cs
│ ├── IRevoltRequest.cs
│ ├── Requests
│ │ ├── Account
│ │ │ ├── AccountChangeEmailRequest.cs
│ │ │ ├── AccountChangePasswordRequest.cs
│ │ │ ├── AccountConfirmDeletionRequest.cs
│ │ │ ├── AccountFetchSettingsRequest.cs
│ │ │ ├── AccountLoginMFARequest.cs
│ │ │ ├── AccountLoginRequest.cs
│ │ │ ├── AccountOnboardingRequest.cs
│ │ │ ├── AccountPasswordResetRequest.cs
│ │ │ ├── AccountVerificationRequest.cs
│ │ │ └── ModifyAccountSessionRequest.cs
│ │ ├── Channel
│ │ │ ├── BulkDeleteMessagesRequest.cs
│ │ │ └── SendMessageRequest.cs
│ │ ├── Client
│ │ │ ├── CreateAccountRequest.cs
│ │ │ └── PasswordResetRequest.cs
│ │ ├── ModifyUserRequest.cs
│ │ └── Server
│ │ │ ├── CreateChannelRequest.cs
│ │ │ ├── CreateEmojiRequest.cs
│ │ │ ├── CreateRoleRequest.cs
│ │ │ ├── CreateWebhookRequest.cs
│ │ │ ├── EditMemberRequest.cs
│ │ │ ├── ModifyChannelRequest.cs
│ │ │ ├── ModifyDefaultPermissionsRequest.cs
│ │ │ ├── ModifyRoleRequest.cs
│ │ │ ├── ModifyServerRequest.cs
│ │ │ └── ReasonRequest.cs
│ ├── RestError.cs
│ └── RevoltRestClient.cs
├── RevoltSharp.csproj
├── RevoltSharp.xml
└── WebSocket
│ ├── AuthenticateSocketRequest.cs
│ ├── BeginTypingSocketRequest.cs
│ ├── EndTypingSocketRequest.cs
│ ├── Events
│ ├── BulkEventsJson.cs
│ ├── ChannelEventsJson.cs
│ ├── ChannelGroupEventsJson.cs
│ ├── ErrorEventJson.cs
│ ├── MessageEventsJson.cs
│ ├── ReactionEventsJson.cs
│ ├── ReadyEventJson.cs
│ ├── ServerEmojiEventsJson.cs
│ ├── ServerEventsJson.cs
│ ├── ServerMemberEventsJson.cs
│ ├── ServerRoleEventsJson.cs
│ ├── UserEventsJson.cs
│ └── WebhookCreateEventJson.cs
│ ├── HeartbeatSocketRequest.cs
│ ├── RevoltSocketClient.cs
│ └── TypingNotifier.cs
└── TestBot
├── Commands
└── CmdTest.cs
├── EventTests.cs
├── Program.cs
└── TestBot.csproj
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | patreon: fluxpointdev
2 | custom: https://fluxpoint.dev/donate
3 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2021 Builderb
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/RevoltSharp.Challenge/Class1.cs:
--------------------------------------------------------------------------------
1 | namespace RevoltSharp.Challenge;
2 |
3 | public class Class1
4 | {
5 | /// Todo add cloudflare challenge stuff
6 | }
--------------------------------------------------------------------------------
/RevoltSharp.Challenge/PackageIcon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FluxpointDev/RevoltSharp/133b03e27c8e61ac7472b081ca826124554eabcf/RevoltSharp.Challenge/PackageIcon.png
--------------------------------------------------------------------------------
/RevoltSharp.Challenge/RevoltSharp.Challenge.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net6.0
5 | disable
6 | enable
7 | False
8 | False
9 | 1.0.0
10 | PackageIcon.png
11 |
12 |
13 |
14 |
15 | \
16 | True
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/RevoltSharp.Commands/Attributes/AliasAttribute.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace RevoltSharp.Commands;
4 |
5 | ///
6 | /// Marks the aliases for a command.
7 | ///
8 | ///
9 | /// This attribute allows a command to have one or multiple aliases. In other words, the base command can have
10 | /// multiple aliases when triggering the command itself, giving the end-user more freedom of choices when giving
11 | /// hot-words to trigger the desired command. See the example for a better illustration.
12 | ///
13 | ///
14 | /// In the following example, the command can be triggered with the base name, "stats", or either "stat" or
15 | /// "info".
16 | ///
17 | /// [Command("stats")]
18 | /// [Alias("stat", "info")]
19 | /// public async Task GetStatsAsync(IUser user)
20 | /// {
21 | /// // ...pull stats
22 | /// }
23 | ///
24 | ///
25 | [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
26 | public class AliasAttribute : Attribute
27 | {
28 | ///
29 | /// Gets the aliases which have been defined for the command.
30 | ///
31 | public string[] Aliases { get; }
32 |
33 | ///
34 | /// Creates a new with the given aliases.
35 | ///
36 | public AliasAttribute(params string[] aliases)
37 | {
38 | Aliases = aliases;
39 | }
40 | }
--------------------------------------------------------------------------------
/RevoltSharp.Commands/Attributes/CommandAttribute.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace RevoltSharp.Commands;
4 |
5 | ///
6 | /// Marks the execution information for a command.
7 | ///
8 | [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
9 | public class CommandAttribute : Attribute
10 | {
11 | ///
12 | /// Gets the text that has been set to be recognized as a command.
13 | ///
14 | public string Text { get; }
15 |
16 | ///
17 | /// Ignore extra arguments passed instead of erroring.
18 | ///
19 | public bool? IgnoreExtraArgs { get; }
20 |
21 | ///
22 | /// Initializes a new attribute with the specified name.
23 | ///
24 | public CommandAttribute()
25 | {
26 | Text = string.Empty;
27 | }
28 |
29 | ///
30 | /// Initializes a new attribute with the specified name.
31 | ///
32 | /// The name of the command.
33 | public CommandAttribute(string text)
34 | {
35 | Text = text;
36 | }
37 |
38 | ///
39 | /// Initializes a new attribute with the specified name.
40 | ///
41 | /// The name of the command.
42 | /// Ignore extra arguments passed.
43 | public CommandAttribute(string text, bool ignoreExtraArgs)
44 | {
45 | Text = text;
46 | IgnoreExtraArgs = ignoreExtraArgs;
47 | }
48 | }
--------------------------------------------------------------------------------
/RevoltSharp.Commands/Attributes/DontAutoLoadAttribute.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace RevoltSharp.Commands;
4 |
5 | ///
6 | /// Prevents the marked module from being loaded automatically.
7 | ///
8 | ///
9 | /// This attribute tells to ignore the marked module from being loaded
10 | /// automatically (e.g. the method). If a non-public module marked
11 | /// with this attribute is attempted to be loaded manually, the loading process will also fail.
12 | ///
13 | [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)]
14 | public class DontAutoLoadAttribute : Attribute
15 | {
16 | }
17 |
--------------------------------------------------------------------------------
/RevoltSharp.Commands/Attributes/DontInjectAttribute.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace RevoltSharp.Commands;
4 |
5 | ///
6 | /// Prevents the marked property from being injected into a module.
7 | ///
8 | ///
9 | /// This attribute prevents the marked member from being injected into its parent module. Useful when you have a
10 | /// public property that you do not wish to invoke the library's dependency injection service.
11 | ///
12 | ///
13 | /// In the following example, DatabaseService will not be automatically injected into the module and will
14 | /// not throw an error message if the dependency fails to be resolved.
15 | ///
16 | /// public class MyModule : ModuleBase
17 | /// {
18 | /// [DontInject]
19 | /// public DatabaseService DatabaseService;
20 | /// public MyModule()
21 | /// {
22 | /// DatabaseService = DatabaseFactory.Generate();
23 | /// }
24 | /// }
25 | ///
26 | ///
27 | [AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = true)]
28 | public class DontInjectAttribute : Attribute
29 | {
30 | }
--------------------------------------------------------------------------------
/RevoltSharp.Commands/Attributes/GroupAttribute.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace RevoltSharp.Commands;
4 |
5 | ///
6 | /// Marks the module as a command group.
7 | ///
8 | [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)]
9 | public class GroupAttribute : Attribute
10 | {
11 | ///
12 | /// Gets the prefix set for the module.
13 | ///
14 | public string? Prefix { get; }
15 |
16 | ///
17 | public GroupAttribute()
18 | {
19 | Prefix = null;
20 | }
21 | ///
22 | /// Initializes a new with the provided prefix.
23 | ///
24 | /// The prefix of the module group.
25 | public GroupAttribute(string prefix)
26 | {
27 | Prefix = prefix;
28 | }
29 | }
--------------------------------------------------------------------------------
/RevoltSharp.Commands/Attributes/NameAttribute.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace RevoltSharp.Commands;
4 |
5 | // Override public name of command/module
6 | ///
7 | /// Marks the public name of a command, module, or parameter.
8 | ///
9 | [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class | AttributeTargets.Parameter, AllowMultiple = false, Inherited = true)]
10 | public class NameAttribute : Attribute
11 | {
12 | ///
13 | /// Gets the name of the command.
14 | ///
15 | public string Text { get; }
16 |
17 | ///
18 | /// Marks the public name of a command, module, or parameter with the provided name.
19 | ///
20 | /// The public name of the object.
21 | public NameAttribute(string text)
22 | {
23 | Text = text;
24 | }
25 | }
--------------------------------------------------------------------------------
/RevoltSharp.Commands/Attributes/NamedArgumentTypeAttribute.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace RevoltSharp.Commands;
4 |
5 | ///
6 | /// Instructs the command system to treat command parameters of this type
7 | /// as a collection of named arguments matching to its properties.
8 | ///
9 | [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)]
10 | public sealed class NamedArgumentTypeAttribute : Attribute { }
--------------------------------------------------------------------------------
/RevoltSharp.Commands/Attributes/OverrideTypeReaderAttribute.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Reflection;
3 |
4 | namespace RevoltSharp.Commands;
5 |
6 | ///
7 | /// Marks the to be read by the specified .
8 | ///
9 | ///
10 | /// This attribute will override the to be used when parsing for the
11 | /// desired type in the command. This is useful when one wishes to use a particular
12 | /// without affecting other commands that are using the same target
13 | /// type.
14 | ///
15 | /// If the given type reader does not inherit from , an
16 | /// will be thrown.
17 | ///
18 | ///
19 | ///
20 | /// In this example, the will be read by a custom
21 | /// , FriendlyTimeSpanTypeReader, instead of the
22 | /// .
23 | ///
24 | /// [Command("time")]
25 | /// public Task GetTimeAsync([OverrideTypeReader(typeof(FriendlyTimeSpanTypeReader))]TimeSpan time)
26 | /// => ReplyAsync(time);
27 | ///
28 | ///
29 | [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Property, AllowMultiple = false, Inherited = true)]
30 | public sealed class OverrideTypeReaderAttribute : Attribute
31 | {
32 | private static readonly TypeInfo TypeReaderTypeInfo = typeof(TypeReader).GetTypeInfo();
33 |
34 | ///
35 | /// Gets the specified of the parameter.
36 | ///
37 | public Type TypeReader { get; }
38 |
39 | ///
40 | /// The to be used with the parameter.
41 | /// The given does not inherit from .
42 | public OverrideTypeReaderAttribute(Type overridenTypeReader)
43 | {
44 | if (!TypeReaderTypeInfo.IsAssignableFrom(overridenTypeReader.GetTypeInfo()))
45 | throw new ArgumentException($"{nameof(overridenTypeReader)} must inherit from {nameof(TypeReader)}.");
46 |
47 | TypeReader = overridenTypeReader;
48 | }
49 | }
--------------------------------------------------------------------------------
/RevoltSharp.Commands/Attributes/ParameterPreconditionAttribute.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Threading.Tasks;
3 |
4 | namespace RevoltSharp.Commands;
5 |
6 | ///
7 | /// Requires the parameter to pass the specified precondition before execution can begin.
8 | ///
9 | ///
10 | [AttributeUsage(AttributeTargets.Parameter, AllowMultiple = true, Inherited = true)]
11 | public abstract class ParameterPreconditionAttribute : Attribute
12 | {
13 | ///
14 | /// Checks whether the condition is met before execution of the command.
15 | ///
16 | /// The context of the command.
17 | /// The parameter of the command being checked against.
18 | /// The raw value of the parameter.
19 | /// The service collection used for dependency injection.
20 | public abstract Task CheckPermissionsAsync(CommandContext context, ParameterInfo parameter, object value, IServiceProvider services);
21 | }
--------------------------------------------------------------------------------
/RevoltSharp.Commands/Attributes/PreconditionAttribute.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Threading.Tasks;
3 |
4 | namespace RevoltSharp.Commands;
5 |
6 | ///
7 | /// Requires the module or class to pass the specified precondition before execution can begin.
8 | ///
9 | ///
10 | [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, AllowMultiple = true, Inherited = true)]
11 | public abstract class PreconditionAttribute : Attribute
12 | {
13 | ///
14 | /// Specifies a group that this precondition belongs to.
15 | ///
16 | ///
17 | /// of the same group require only one of the preconditions to pass in order to
18 | /// be successful (A || B). Specifying = null or not at all will
19 | /// require *all* preconditions to pass, just like normal (A && B).
20 | ///
21 | public string Group { get; set; } = null;
22 |
23 | ///
24 | /// When overridden in a derived class, uses the supplied string
25 | /// as the error message if the precondition doesn't pass.
26 | /// Setting this for a class that doesn't override
27 | /// this property is a no-op.
28 | ///
29 | public virtual string? ErrorMessage { get { return null; } set { } }
30 |
31 | ///
32 | /// Checks if the has the sufficient permission to be executed.
33 | ///
34 | /// The context of the command.
35 | /// The command being executed.
36 | /// The service collection used for dependency injection.
37 | public abstract Task CheckPermissionsAsync(CommandContext context, CommandInfo command, IServiceProvider services);
38 | }
--------------------------------------------------------------------------------
/RevoltSharp.Commands/Attributes/Preconditions/RequireContextAttribute.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Threading.Tasks;
3 |
4 | namespace RevoltSharp.Commands;
5 |
6 | [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
7 | public class RequireContextAttribute : PreconditionAttribute
8 | {
9 | public RequireContextAttribute(ContextType contextTypes)
10 | {
11 | Contexts = contextTypes;
12 | }
13 |
14 | ///
15 | /// Gets the context required to execute the command.
16 | ///
17 | public ContextType Contexts { get; }
18 |
19 | ///
20 | public override Task CheckPermissionsAsync(CommandContext context, CommandInfo command, IServiceProvider services)
21 | {
22 | bool isValid = false;
23 |
24 | if ((Contexts & ContextType.Server) != 0)
25 | isValid = context.Channel is ServerChannel;
26 | if ((Contexts & ContextType.DM) != 0)
27 | isValid = isValid || context.Channel is DMChannel;
28 | if ((Contexts & ContextType.Group) != 0)
29 | isValid = isValid || context.Channel is GroupChannel;
30 |
31 | if (isValid)
32 | return Task.FromResult(PreconditionResult.FromSuccess());
33 |
34 | return Task.FromResult(PreconditionResult.FromError($"Invalid channel context for command, require contexts are {Contexts}"));
35 | }
36 | }
37 |
38 | [Flags]
39 | public enum ContextType
40 | {
41 | DM = 0x01,
42 | Group = 0x02,
43 | Server = 0x03
44 | }
--------------------------------------------------------------------------------
/RevoltSharp.Commands/Attributes/Preconditions/RequireDMAttribute.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Threading.Tasks;
3 |
4 | namespace RevoltSharp.Commands;
5 |
6 | [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
7 | public class RequireDMttribute : PreconditionAttribute
8 | {
9 | ///
10 | public override Task CheckPermissionsAsync(CommandContext context, CommandInfo command, IServiceProvider services)
11 | {
12 | if (context.Server == null)
13 | return Task.FromResult(PreconditionResult.FromError("You need to run this command in a DM/Private channel."));
14 |
15 | return Task.FromResult(PreconditionResult.FromSuccess());
16 | }
17 | }
--------------------------------------------------------------------------------
/RevoltSharp.Commands/Attributes/Preconditions/RequireGroupAttribute.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Threading.Tasks;
3 |
4 | namespace RevoltSharp.Commands;
5 |
6 | [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
7 | public class RequireGroupAttribute : PreconditionAttribute
8 | {
9 | ///
10 | public override Task CheckPermissionsAsync(CommandContext context, CommandInfo command, IServiceProvider services)
11 | {
12 | if (context.Channel.Type != ChannelType.Group)
13 | return Task.FromResult(PreconditionResult.FromError("You need to run this command in a group channel."));
14 |
15 | return Task.FromResult(PreconditionResult.FromSuccess());
16 | }
17 | }
--------------------------------------------------------------------------------
/RevoltSharp.Commands/Attributes/Preconditions/RequireGroupOwnerAttribute.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Threading.Tasks;
3 |
4 | namespace RevoltSharp.Commands;
5 |
6 | [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
7 | public class RequireGroupOwnerAttribute : PreconditionAttribute
8 | {
9 | ///
10 | public override Task CheckPermissionsAsync(CommandContext context, CommandInfo command, IServiceProvider services)
11 | {
12 | if (context.Channel.Type != ChannelType.Group)
13 | return Task.FromResult(PreconditionResult.FromError("You need to run this command in a group channel."));
14 |
15 | if (context.User.Id == (context.Channel as GroupChannel).OwnerId)
16 | return Task.FromResult(PreconditionResult.FromSuccess());
17 |
18 | return Task.FromResult(PreconditionResult.FromError("Command can only be run by the group owner."));
19 | }
20 | }
--------------------------------------------------------------------------------
/RevoltSharp.Commands/Attributes/Preconditions/RequireOwnerAttribute.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Linq;
3 | using System.Threading.Tasks;
4 |
5 | namespace RevoltSharp.Commands;
6 |
7 | ///
8 | /// Requires the command to be invoked by the owner of the bot.
9 | ///
10 | ///
11 | /// This precondition will restrict the access of the command or module to the owner of the RevoltSharp bot.
12 | /// If the precondition fails to be met, an erroneous will be returned with the
13 | /// message "Command can only be run by the owner of the bot."
14 | ///
15 | ///
16 | /// The following example restricts the command to a set of sensitive commands that only the owner of the bot
17 | /// application should be able to access.
18 | ///
19 | /// [RequireOwner]
20 | /// [Group("admin")]
21 | /// public class AdminModule : ModuleBase
22 | /// {
23 | /// [Command("exit")]
24 | /// public async Task ExitAsync()
25 | /// {
26 | /// Environment.Exit(0);
27 | /// }
28 | /// }
29 | ///
30 | ///
31 | [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
32 | public class RequireOwnerAttribute : PreconditionAttribute
33 | {
34 | ///
35 | #pragma warning disable CS1998
36 | public override async Task CheckPermissionsAsync(CommandContext context, CommandInfo command, IServiceProvider services)
37 | #pragma warning restore CS1998
38 | {
39 | if (context.Client.CurrentUser.OwnerId == context.User.Id || (context.Client.Config.Owners != null && context.Client.Config.Owners.Any(x => x == context.User.Id)))
40 | return PreconditionResult.FromSuccess();
41 | return PreconditionResult.FromError("Command can only be run by the owner of the bot.");
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/RevoltSharp.Commands/Attributes/Preconditions/RequireServerAttribute.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Threading.Tasks;
3 |
4 | namespace RevoltSharp.Commands;
5 |
6 | [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
7 | public class RequireServerAttribute : PreconditionAttribute
8 | {
9 | ///
10 | public override Task CheckPermissionsAsync(CommandContext context, CommandInfo command, IServiceProvider services)
11 | {
12 | if (context.Server == null)
13 | return Task.FromResult(PreconditionResult.FromError("You need to run this command in a Revolt server."));
14 |
15 | return Task.FromResult(PreconditionResult.FromSuccess());
16 | }
17 | }
--------------------------------------------------------------------------------
/RevoltSharp.Commands/Attributes/Preconditions/RequireServerOwnerAttribute.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Threading.Tasks;
3 |
4 | namespace RevoltSharp.Commands;
5 |
6 | [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
7 | public class RequireServerOwnerAttribute : PreconditionAttribute
8 | {
9 | ///
10 | public override Task CheckPermissionsAsync(CommandContext context, CommandInfo command, IServiceProvider services)
11 | {
12 | if (context.Server == null)
13 | return Task.FromResult(PreconditionResult.FromError("You need to run this command in a Revolt server."));
14 |
15 | if (context.User.Id == context.Server.OwnerId)
16 | return Task.FromResult(PreconditionResult.FromSuccess());
17 |
18 | return Task.FromResult(PreconditionResult.FromError("Command can only be run by the server owner."));
19 | }
20 | }
--------------------------------------------------------------------------------
/RevoltSharp.Commands/Attributes/Preconditions/TemplateAttribute.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Threading.Tasks;
3 |
4 | namespace RevoltSharp.Commands;
5 |
6 | [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true, Inherited = true)]
7 | internal class TemplateAttribute : PreconditionAttribute
8 | {
9 | ///
10 | public override Task CheckPermissionsAsync(CommandContext context, CommandInfo command, IServiceProvider services)
11 | {
12 | if (context.Client.CurrentUser.OwnerId == context.User.Id)
13 | return Task.FromResult(PreconditionResult.FromSuccess());
14 |
15 | return Task.FromResult(PreconditionResult.FromError("Command can only be run by the owner of the bot."));
16 | }
17 | }
--------------------------------------------------------------------------------
/RevoltSharp.Commands/Attributes/PriorityAttribute.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace RevoltSharp.Commands;
4 |
5 | ///
6 | /// Sets priority of commands.
7 | ///
8 | [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
9 | public class PriorityAttribute : Attribute
10 | {
11 | ///
12 | /// Gets the priority which has been set for the command.
13 | ///
14 | public int Priority { get; }
15 |
16 | ///
17 | /// Initializes a new attribute with the given priority.
18 | ///
19 | public PriorityAttribute(int priority)
20 | {
21 | Priority = priority;
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/RevoltSharp.Commands/Attributes/RemainderAttribute.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace RevoltSharp.Commands;
4 |
5 | ///
6 | /// Marks the input to not be parsed by the parser.
7 | ///
8 | [AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = true)]
9 | public class RemainderAttribute : Attribute
10 | {
11 | }
--------------------------------------------------------------------------------
/RevoltSharp.Commands/Attributes/RemarksAttribute.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace RevoltSharp.Commands;
4 |
5 | // Extension of the Cosmetic Summary, for Groups, Commands, and Parameters
6 | ///
7 | /// Attaches remarks to your commands.
8 | ///
9 | [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, AllowMultiple = false, Inherited = true)]
10 | public class RemarksAttribute : Attribute
11 | {
12 | public string Text { get; }
13 |
14 | public RemarksAttribute(string text)
15 | {
16 | Text = text;
17 | }
18 | }
--------------------------------------------------------------------------------
/RevoltSharp.Commands/Attributes/SummaryAttribute.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace RevoltSharp.Commands;
4 |
5 | // Cosmetic Summary, for Groups and Commands
6 | ///
7 | /// Attaches a summary to your command.
8 | ///
9 | [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class | AttributeTargets.Parameter, AllowMultiple = false, Inherited = true)]
10 | public class SummaryAttribute : Attribute
11 | {
12 | public string Text { get; }
13 |
14 | public SummaryAttribute(string text)
15 | {
16 | Text = text;
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/RevoltSharp.Commands/CommandContext.cs:
--------------------------------------------------------------------------------
1 | namespace RevoltSharp.Commands;
2 |
3 |
4 | /// The context of a command which may contain the client, user, guild, channel, and message.
5 | public class CommandContext
6 | {
7 | ///
8 | public RevoltClient Client { get; }
9 | ///
10 | public Server? Server { get; }
11 | ///
12 | public Channel Channel { get; }
13 | ///
14 | public User? User { get; }
15 | ///
16 | public ServerMember? Member { get; }
17 | ///
18 | public UserMessage Message { get; }
19 |
20 | public CommandInfo? Command { get; set; }
21 |
22 | public string? Prefix { get; set; }
23 |
24 | /// Indicates whether the channel that the command is executed in is a private channel.
25 | public bool IsPrivate => Channel is DMChannel;
26 |
27 | ///
28 | /// Initializes a new class with the provided client and message.
29 | ///
30 | /// The underlying client.
31 | /// The underlying message.
32 | public CommandContext(RevoltClient client, UserMessage msg)
33 | {
34 | Client = client;
35 | Channel = msg.Channel!;
36 | User = msg.Author;
37 | Message = msg;
38 | if (Channel is TextChannel channel)
39 | {
40 | Server = channel.Server;
41 | if (Server.InternalMembers.TryGetValue(msg.AuthorId, out ServerMember MB))
42 | Member = MB;
43 | }
44 | }
45 |
46 | }
--------------------------------------------------------------------------------
/RevoltSharp.Commands/CommandError.cs:
--------------------------------------------------------------------------------
1 | namespace RevoltSharp.Commands;
2 |
3 |
4 | /// Defines the type of error a command can throw.
5 | public enum CommandError
6 | {
7 | //Search
8 | ///
9 | /// Thrown when the command is unknown.
10 | ///
11 | UnknownCommand = 1,
12 |
13 | //Parse
14 | ///
15 | /// Thrown when the command fails to be parsed.
16 | ///
17 | ParseFailed,
18 | ///
19 | /// Thrown when the input text has too few or too many arguments.
20 | ///
21 | BadArgCount,
22 |
23 | //Parse (Type Reader)
24 | //CastFailed,
25 | ///
26 | /// Thrown when the object cannot be found by the .
27 | ///
28 | ObjectNotFound,
29 | ///
30 | /// Thrown when more than one object is matched by .
31 | ///
32 | MultipleMatches,
33 |
34 | //Preconditions
35 | ///
36 | /// Thrown when the command fails to meet a 's conditions.
37 | ///
38 | UnmetPrecondition,
39 |
40 | //Execute
41 | ///
42 | /// Thrown when an exception occurs mid-command execution.
43 | ///
44 | Exception,
45 |
46 | //Runtime
47 | ///
48 | /// Thrown when the command is not successfully executed on runtime.
49 | ///
50 | Unsuccessful
51 | }
--------------------------------------------------------------------------------
/RevoltSharp.Commands/CommandException.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace RevoltSharp.Commands;
4 |
5 |
6 | ///
7 | /// The exception that is thrown if another exception occurs during a command execution.
8 | ///
9 | public class CommandException : Exception
10 | {
11 | /// Gets the command that caused the exception.
12 | public CommandInfo Command { get; }
13 | /// Gets the command context of the exception.
14 | public CommandContext Context { get; }
15 |
16 | ///
17 | /// Initializes a new instance of the class using a
18 | /// information, a context, and the exception that
19 | /// interrupted the execution.
20 | ///
21 | /// The command information.
22 | /// The context of the command.
23 | /// The exception that interrupted the command execution.
24 | public CommandException(CommandInfo command, CommandContext context, Exception ex)
25 | : base($"Error occurred executing {command.GetLogText(context)}.", ex)
26 | {
27 | Command = command;
28 | Context = context;
29 | }
30 | }
--------------------------------------------------------------------------------
/RevoltSharp.Commands/CommandMatch.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Threading.Tasks;
4 |
5 | namespace RevoltSharp.Commands;
6 |
7 |
8 | public struct CommandMatch
9 | {
10 | /// The command that matches the search result.
11 | public CommandInfo Command { get; }
12 | /// The alias of the command.
13 | public string Alias { get; }
14 |
15 | public CommandMatch(CommandInfo command, string alias)
16 | {
17 | Command = command;
18 | Alias = alias;
19 | }
20 |
21 | public Task CheckPreconditionsAsync(CommandContext context, IServiceProvider services = null)
22 | => Command.CheckPreconditionsAsync(context, services);
23 | public Task ParseAsync(CommandContext context, SearchResult searchResult, PreconditionResult preconditionResult = null, IServiceProvider services = null)
24 | => Command.ParseAsync(context, Alias.Length, searchResult, preconditionResult, services);
25 | public Task ExecuteAsync(CommandContext context, IEnumerable