├── .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 argList, IEnumerable paramList, IServiceProvider services) 26 | => Command.ExecuteAsync(context, argList, paramList, services); 27 | public Task ExecuteAsync(CommandContext context, ParseResult parseResult, IServiceProvider services) 28 | => Command.ExecuteAsync(context, parseResult, services); 29 | } -------------------------------------------------------------------------------- /RevoltSharp.Commands/CommandServiceConfig.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace RevoltSharp.Commands; 4 | 5 | 6 | /// 7 | /// Represents a configuration class for . 8 | /// 9 | public class CommandServiceConfig 10 | { 11 | /// 12 | /// Gets or sets the that separates an argument with another. 13 | /// 14 | public char SeparatorChar { get; set; } = ' '; 15 | 16 | /// 17 | /// Gets or sets whether commands should be case-sensitive. 18 | /// 19 | public bool CaseSensitiveCommands { get; set; } = false; 20 | 21 | /// 22 | /// Collection of aliases for matching pairs of string delimiters. 23 | /// The dictionary stores the opening delimiter as a key, and the matching closing delimiter as the value. 24 | /// If no value is supplied will be used, which contains 25 | /// many regional equivalents. 26 | /// Only values that are specified in this map will be used as string delimiters, so if " is removed then 27 | /// it won't be used. 28 | /// If this map is set to null or empty, the default delimiter of " will be used. 29 | /// 30 | /// 31 | /// 32 | /// QuotationMarkAliasMap = new Dictionary<char, char>() 33 | /// { 34 | /// {'\"', '\"' }, 35 | /// {'“', '”' }, 36 | /// {'「', '」' }, 37 | /// } 38 | /// 39 | /// 40 | public Dictionary QuotationMarkAliasMap { get; set; } = QuotationAliasUtils.GetDefaultAliasMap; 41 | 42 | /// 43 | /// Gets or sets a value that indicates whether extra parameters should be ignored. 44 | /// 45 | public bool IgnoreExtraArgs { get; set; } = false; 46 | } 47 | -------------------------------------------------------------------------------- /RevoltSharp.Commands/EmptyServiceProvider.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace RevoltSharp.Commands; 4 | 5 | 6 | internal class EmptyServiceProvider : IServiceProvider 7 | { 8 | public static readonly EmptyServiceProvider Instance = new EmptyServiceProvider(); 9 | 10 | public object? GetService(Type serviceType) => null; 11 | } -------------------------------------------------------------------------------- /RevoltSharp.Commands/Extensions/IEnumerableExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace RevoltSharp.Commands; 5 | 6 | 7 | public static class IEnumerableExtensions 8 | { 9 | public static IEnumerable Permutate( 10 | this IEnumerable set, 11 | IEnumerable others, 12 | Func func) 13 | { 14 | foreach (TFirst elem in set) 15 | { 16 | foreach (TSecond elem2 in others) 17 | { 18 | yield return func(elem, elem2); 19 | } 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /RevoltSharp.Commands/Extensions/MessageExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace RevoltSharp.Commands; 4 | 5 | 6 | /// 7 | /// Provides extension methods for that relates to commands. 8 | /// 9 | public static class MessageExtensions 10 | { 11 | /// 12 | /// Gets whether the message starts with the provided character. 13 | /// 14 | /// The message to check against. 15 | /// The char prefix. 16 | /// References where the command starts. 17 | /// 18 | /// true if the message begins with the char ; otherwise false. 19 | /// 20 | public static bool HasCharPrefix(this UserMessage msg, char c, ref int argPos) 21 | { 22 | string text = msg.Content; 23 | if (!string.IsNullOrEmpty(text) && text[0] == c) 24 | { 25 | argPos = 1; 26 | return true; 27 | } 28 | return false; 29 | } 30 | /// 31 | /// Gets whether the message starts with the provided string. 32 | /// 33 | public static bool HasStringPrefix(this UserMessage msg, string str, ref int argPos, StringComparison comparisonType = StringComparison.Ordinal) 34 | { 35 | string text = msg.Content; 36 | if (!string.IsNullOrEmpty(text) && text.StartsWith(str, comparisonType)) 37 | { 38 | argPos = str.Length; 39 | return true; 40 | } 41 | return false; 42 | } 43 | /// 44 | /// Gets whether the message starts with the user's mention string. 45 | /// 46 | public static bool HasMentionPrefix(this UserMessage msg, SelfUser user, ref int argPos) 47 | { 48 | if (user == null) 49 | return false; 50 | string text = msg.Content; 51 | if (string.IsNullOrEmpty(text) || text.Length <= 3 || text[0] != '<' || text[1] != '@') return false; 52 | 53 | int endPos = text.IndexOf('>'); 54 | if (endPos == -1) return false; 55 | if (text.Length < endPos + 2 || text[endPos + 1] != ' ') 56 | return false; //Must end in "> " 57 | 58 | string userId = text.Substring(0, endPos + 1); 59 | if (userId == user.Id) 60 | { 61 | argPos = endPos + 2; 62 | return true; 63 | } 64 | return false; 65 | } 66 | } -------------------------------------------------------------------------------- /RevoltSharp.Commands/IModuleBase.cs: -------------------------------------------------------------------------------- 1 | using RevoltSharp.Commands.Builders; 2 | 3 | namespace RevoltSharp.Commands; 4 | 5 | 6 | internal interface IModuleBase 7 | { 8 | void SetContext(CommandContext context); 9 | 10 | void BeforeExecute(CommandInfo command); 11 | 12 | void AfterExecute(CommandInfo command); 13 | 14 | void OnModuleBuilding(CommandService commandService, ModuleBuilder builder); 15 | } 16 | -------------------------------------------------------------------------------- /RevoltSharp.Commands/Map/CommandMap.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace RevoltSharp.Commands; 4 | 5 | 6 | internal class CommandMap 7 | { 8 | private readonly CommandService _service; 9 | private readonly CommandMapNode _root; 10 | private static readonly string[] BlankAliases = { "" }; 11 | 12 | public CommandMap(CommandService service) 13 | { 14 | _service = service; 15 | _root = new CommandMapNode(""); 16 | } 17 | 18 | public void AddCommand(CommandInfo command) 19 | { 20 | foreach (string text in command.Aliases) 21 | _root.AddCommand(_service, text, 0, command); 22 | } 23 | public void RemoveCommand(CommandInfo command) 24 | { 25 | foreach (string text in command.Aliases) 26 | _root.RemoveCommand(_service, text, 0, command); 27 | } 28 | 29 | public IEnumerable GetCommands(string text) 30 | { 31 | return _root.GetCommands(_service, text, 0, text != ""); 32 | } 33 | } -------------------------------------------------------------------------------- /RevoltSharp.Commands/MultiMatchHandling.cs: -------------------------------------------------------------------------------- 1 | namespace RevoltSharp.Commands; 2 | 3 | 4 | /// 5 | /// Specifies the behavior when multiple matches are found during the command parsing stage. 6 | /// 7 | public enum MultiMatchHandling 8 | { 9 | /// Indicates that when multiple results are found, an exception should be thrown. 10 | Exception, 11 | /// Indicates that when multiple results are found, the best result should be chosen. 12 | Best 13 | } -------------------------------------------------------------------------------- /RevoltSharp.Commands/PackageIcon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FluxpointDev/RevoltSharp/133b03e27c8e61ac7472b081ca826124554eabcf/RevoltSharp.Commands/PackageIcon.png -------------------------------------------------------------------------------- /RevoltSharp.Commands/PrimitiveParsers.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Collections.Immutable; 4 | 5 | namespace RevoltSharp.Commands; 6 | 7 | 8 | internal delegate bool TryParseDelegate(string str, out T value); 9 | 10 | internal static class PrimitiveParsers 11 | { 12 | private static readonly Lazy> Parsers = new Lazy>(CreateParsers); 13 | 14 | public static IEnumerable SupportedTypes = Parsers.Value.Keys; 15 | 16 | static IReadOnlyDictionary CreateParsers() 17 | { 18 | ImmutableDictionary.Builder parserBuilder = ImmutableDictionary.CreateBuilder(); 19 | parserBuilder[typeof(bool)] = (TryParseDelegate)bool.TryParse; 20 | parserBuilder[typeof(sbyte)] = (TryParseDelegate)sbyte.TryParse; 21 | parserBuilder[typeof(byte)] = (TryParseDelegate)byte.TryParse; 22 | parserBuilder[typeof(short)] = (TryParseDelegate)short.TryParse; 23 | parserBuilder[typeof(ushort)] = (TryParseDelegate)ushort.TryParse; 24 | parserBuilder[typeof(int)] = (TryParseDelegate)int.TryParse; 25 | parserBuilder[typeof(uint)] = (TryParseDelegate)uint.TryParse; 26 | parserBuilder[typeof(long)] = (TryParseDelegate)long.TryParse; 27 | parserBuilder[typeof(ulong)] = (TryParseDelegate)ulong.TryParse; 28 | parserBuilder[typeof(float)] = (TryParseDelegate)float.TryParse; 29 | parserBuilder[typeof(double)] = (TryParseDelegate)double.TryParse; 30 | parserBuilder[typeof(decimal)] = (TryParseDelegate)decimal.TryParse; 31 | parserBuilder[typeof(DateTime)] = (TryParseDelegate)DateTime.TryParse; 32 | parserBuilder[typeof(DateTimeOffset)] = (TryParseDelegate)DateTimeOffset.TryParse; 33 | //parserBuilder[typeof(TimeSpan)] = (TryParseDelegate)TimeSpan.TryParse; 34 | parserBuilder[typeof(char)] = (TryParseDelegate)char.TryParse; 35 | return parserBuilder.ToImmutable(); 36 | } 37 | 38 | public static TryParseDelegate Get() => (TryParseDelegate)Parsers.Value[typeof(T)]; 39 | public static Delegate Get(Type type) => Parsers.Value[type]; 40 | } -------------------------------------------------------------------------------- /RevoltSharp.Commands/Readers/NullableTypeReader.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using System.Reflection; 4 | using System.Threading.Tasks; 5 | 6 | namespace RevoltSharp.Commands; 7 | 8 | 9 | internal static class NullableTypeReader 10 | { 11 | public static TypeReader Create(Type type, TypeReader reader) 12 | { 13 | ConstructorInfo constructor = typeof(NullableTypeReader<>).MakeGenericType(type).GetTypeInfo().DeclaredConstructors.First(); 14 | return (TypeReader)constructor.Invoke(new object[] { reader }); 15 | } 16 | } 17 | 18 | internal class NullableTypeReader : TypeReader 19 | where T : struct 20 | { 21 | private readonly TypeReader _baseTypeReader; 22 | 23 | public NullableTypeReader(TypeReader baseTypeReader) 24 | { 25 | _baseTypeReader = baseTypeReader; 26 | } 27 | 28 | /// 29 | public override async Task ReadAsync(CommandContext context, string input, IServiceProvider services) 30 | { 31 | if (string.Equals(input, "null", StringComparison.OrdinalIgnoreCase) || string.Equals(input, "nothing", StringComparison.OrdinalIgnoreCase)) 32 | return TypeReaderResult.FromSuccess(new T?()); 33 | return await _baseTypeReader.ReadAsync(context, input, services).ConfigureAwait(false); 34 | } 35 | } -------------------------------------------------------------------------------- /RevoltSharp.Commands/Readers/PrimitiveTypeReader.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading.Tasks; 3 | 4 | namespace RevoltSharp.Commands; 5 | 6 | 7 | internal static class PrimitiveTypeReader 8 | { 9 | public static TypeReader Create(Type type) 10 | { 11 | type = typeof(PrimitiveTypeReader<>).MakeGenericType(type); 12 | return (Activator.CreateInstance(type) as TypeReader)!; 13 | } 14 | } 15 | 16 | internal class PrimitiveTypeReader : TypeReader 17 | { 18 | private readonly TryParseDelegate _tryParse; 19 | private readonly float _score; 20 | 21 | /// must be within the range [0, 1]. 22 | public PrimitiveTypeReader() 23 | : this(PrimitiveParsers.Get(), 1) 24 | { } 25 | 26 | /// must be within the range [0, 1]. 27 | public PrimitiveTypeReader(TryParseDelegate tryParse, float score) 28 | { 29 | if (score < 0 || score > 1) 30 | throw new ArgumentOutOfRangeException(nameof(score), score, "Scores must be within the range [0, 1]."); 31 | 32 | _tryParse = tryParse; 33 | _score = score; 34 | } 35 | 36 | public override Task ReadAsync(CommandContext context, string input, IServiceProvider services) 37 | { 38 | if (_tryParse(input, out T value)) 39 | return Task.FromResult(TypeReaderResult.FromSuccess(new TypeReaderValue(value, _score))); 40 | return Task.FromResult(TypeReaderResult.FromError(CommandError.ParseFailed, $"Failed to parse {typeof(T).Name}.")); 41 | } 42 | } -------------------------------------------------------------------------------- /RevoltSharp.Commands/Readers/TimeSpanTypeReader.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Globalization; 3 | using System.Threading.Tasks; 4 | 5 | namespace RevoltSharp.Commands; 6 | 7 | 8 | internal class TimeSpanTypeReader : TypeReader 9 | { 10 | private static readonly string[] Formats = { 11 | "%d'd'%h'h'%m'm'%s's'", //4d3h2m1s 12 | "%d'd'%h'h'%m'm'", //4d3h2m 13 | "%d'd'%h'h'%s's'", //4d3h 1s 14 | "%d'd'%h'h'", //4d3h 15 | "%d'd'%m'm'%s's'", //4d 2m1s 16 | "%d'd'%m'm'", //4d 2m 17 | "%d'd'%s's'", //4d 1s 18 | "%d'd'", //4d 19 | "%h'h'%m'm'%s's'", // 3h2m1s 20 | "%h'h'%m'm'", // 3h2m 21 | "%h'h'%s's'", // 3h 1s 22 | "%h'h'", // 3h 23 | "%m'm'%s's'", // 2m1s 24 | "%m'm'", // 2m 25 | "%s's'", // 1s 26 | }; 27 | 28 | /// 29 | public override Task ReadAsync(CommandContext context, string input, IServiceProvider services) 30 | { 31 | if (string.IsNullOrEmpty(input)) 32 | throw new ArgumentException(message: $"{nameof(input)} must not be null or empty.", paramName: nameof(input)); 33 | 34 | bool isNegative = input[0] == '-'; // Char for CultureInfo.InvariantCulture.NumberFormat.NegativeSign 35 | if (isNegative) 36 | { 37 | input = input.Substring(1); 38 | } 39 | 40 | if (TimeSpan.TryParseExact(input.ToLowerInvariant(), Formats, CultureInfo.InvariantCulture, out TimeSpan timeSpan)) 41 | { 42 | return isNegative 43 | ? Task.FromResult(TypeReaderResult.FromSuccess(-timeSpan)) 44 | : Task.FromResult(TypeReaderResult.FromSuccess(timeSpan)); 45 | } 46 | else 47 | { 48 | return Task.FromResult(TypeReaderResult.FromError(CommandError.ParseFailed, "Failed to parse TimeSpan")); 49 | } 50 | } 51 | } -------------------------------------------------------------------------------- /RevoltSharp.Commands/Readers/TypeReader.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading.Tasks; 3 | 4 | namespace RevoltSharp.Commands; 5 | 6 | 7 | /// 8 | /// Defines a reader class that parses user input into a specified type. 9 | /// 10 | public abstract class TypeReader 11 | { 12 | /// 13 | /// Attempts to parse the into the desired type. 14 | /// 15 | /// The context of the command. 16 | /// The raw input of the command. 17 | /// The service collection used for dependency injection. 18 | /// 19 | /// A task that represents the asynchronous parsing operation. The task result contains the parsing result. 20 | /// 21 | public abstract Task ReadAsync(CommandContext context, string input, IServiceProvider services); 22 | } -------------------------------------------------------------------------------- /RevoltSharp.Commands/Results/IResult.cs: -------------------------------------------------------------------------------- 1 | namespace RevoltSharp.Commands; 2 | 3 | 4 | /// 5 | /// Contains information of the result related to a command. 6 | /// 7 | public interface IResult 8 | { 9 | /// 10 | /// Describes the error type that may have occurred during the operation. 11 | /// 12 | /// 13 | /// A indicating the type of error that may have occurred during the operation; 14 | /// null if the operation was successful. 15 | /// 16 | CommandError? Error { get; } 17 | /// 18 | /// Describes the reason for the error. 19 | /// 20 | /// 21 | /// A string containing the error reason. 22 | /// 23 | string ErrorReason { get; } 24 | /// 25 | /// Indicates whether the operation was successful or not. 26 | /// 27 | /// 28 | /// true if the result is positive; otherwise false. 29 | /// 30 | bool IsSuccess { get; } 31 | } -------------------------------------------------------------------------------- /RevoltSharp.Commands/Results/PreconditionGroupResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics; 4 | using System.Linq; 5 | 6 | namespace RevoltSharp.Commands; 7 | 8 | 9 | [DebuggerDisplay(@"{DebuggerDisplay,nq}")] 10 | public class PreconditionGroupResult : PreconditionResult 11 | { 12 | public IReadOnlyCollection PreconditionResults { get; } 13 | 14 | protected PreconditionGroupResult(CommandError? error, string errorReason, ICollection preconditions) 15 | : base(error, errorReason) 16 | { 17 | PreconditionResults = (preconditions ?? new List(0)).ToArray(); 18 | } 19 | 20 | public new static PreconditionGroupResult FromSuccess() 21 | => new PreconditionGroupResult(null, null, null); 22 | public static PreconditionGroupResult FromError(string reason, ICollection preconditions) 23 | => new PreconditionGroupResult(CommandError.UnmetPrecondition, reason, preconditions); 24 | public static new PreconditionGroupResult FromError(Exception ex) 25 | => new PreconditionGroupResult(CommandError.Exception, ex.Message, null); 26 | public static new PreconditionGroupResult FromError(IResult result) //needed? 27 | => new PreconditionGroupResult(result.Error, result.ErrorReason, null); 28 | 29 | public override string ToString() => IsSuccess ? "Success" : $"{Error}: {ErrorReason}"; 30 | private string DebuggerDisplay => IsSuccess ? "Success" : $"{Error}: {ErrorReason}"; 31 | } -------------------------------------------------------------------------------- /RevoltSharp.Commands/Results/PreconditionResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | 4 | namespace RevoltSharp.Commands; 5 | 6 | 7 | /// 8 | /// Represents a result type for command preconditions. 9 | /// 10 | [DebuggerDisplay(@"{DebuggerDisplay,nq}")] 11 | public class PreconditionResult : IResult 12 | { 13 | /// 14 | public CommandError? Error { get; } 15 | /// 16 | public string ErrorReason { get; } 17 | 18 | /// 19 | public bool IsSuccess => !Error.HasValue; 20 | 21 | /// 22 | /// Initializes a new class with the command type 23 | /// and reason. 24 | /// 25 | /// The type of failure. 26 | /// The reason of failure. 27 | protected PreconditionResult(CommandError? error, string errorReason) 28 | { 29 | Error = error; 30 | ErrorReason = errorReason; 31 | } 32 | 33 | /// 34 | /// Returns a with no errors. 35 | /// 36 | public static PreconditionResult FromSuccess() 37 | => new PreconditionResult(null, null); 38 | /// 39 | /// Returns a with and the 40 | /// specified reason. 41 | /// 42 | /// The reason of failure. 43 | public static PreconditionResult FromError(string reason) 44 | => new PreconditionResult(CommandError.UnmetPrecondition, reason); 45 | public static PreconditionResult FromError(Exception ex) 46 | => new PreconditionResult(CommandError.Exception, ex.Message); 47 | /// 48 | /// Returns a with the specified type. 49 | /// 50 | /// The result of failure. 51 | public static PreconditionResult FromError(IResult result) 52 | => new PreconditionResult(result.Error, result.ErrorReason); 53 | 54 | /// 55 | /// Returns a string indicating whether the is successful. 56 | /// 57 | public override string ToString() => IsSuccess ? "Success" : $"{Error}: {ErrorReason}"; 58 | private string DebuggerDisplay => IsSuccess ? "Success" : $"{Error}: {ErrorReason}"; 59 | } -------------------------------------------------------------------------------- /RevoltSharp.Commands/Results/RuntimeResult.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics; 2 | 3 | namespace RevoltSharp.Commands; 4 | 5 | 6 | [DebuggerDisplay(@"{DebuggerDisplay,nq}")] 7 | public abstract class RuntimeResult : IResult 8 | { 9 | /// 10 | /// Initializes a new class with the type of error and reason. 11 | /// 12 | /// The type of failure, or null if none. 13 | /// The reason of failure. 14 | protected RuntimeResult(CommandError? error, string reason) 15 | { 16 | Error = error; 17 | Reason = reason; 18 | } 19 | 20 | /// 21 | public CommandError? Error { get; } 22 | /// Describes the execution reason or result. 23 | public string Reason { get; } 24 | 25 | /// 26 | public bool IsSuccess => !Error.HasValue; 27 | 28 | /// 29 | string IResult.ErrorReason => Reason; 30 | 31 | public override string ToString() => Reason ?? (IsSuccess ? "Successful" : "Unsuccessful"); 32 | private string DebuggerDisplay => IsSuccess ? $"Success: {Reason ?? "No Reason"}" : $"{Error}: {Reason}"; 33 | } -------------------------------------------------------------------------------- /RevoltSharp.Commands/Results/SearchResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics; 4 | 5 | namespace RevoltSharp.Commands; 6 | 7 | 8 | [DebuggerDisplay(@"{DebuggerDisplay,nq}")] 9 | public struct SearchResult : IResult 10 | { 11 | public string Text { get; } 12 | public IReadOnlyList Commands { get; } 13 | 14 | /// 15 | public CommandError? Error { get; } 16 | /// 17 | public string ErrorReason { get; } 18 | 19 | /// 20 | public bool IsSuccess => !Error.HasValue; 21 | 22 | private SearchResult(string text, IReadOnlyList commands, CommandError? error, string errorReason) 23 | { 24 | Text = text; 25 | Commands = commands; 26 | Error = error; 27 | ErrorReason = errorReason; 28 | } 29 | 30 | public static SearchResult FromSuccess(string text, IReadOnlyList commands) 31 | => new SearchResult(text, commands, null, null); 32 | public static SearchResult FromError(CommandError error, string reason) 33 | => new SearchResult(null, null, error, reason); 34 | public static SearchResult FromError(Exception ex) 35 | => FromError(CommandError.Exception, ex.Message); 36 | public static SearchResult FromError(IResult result) 37 | => new SearchResult(null, null, result.Error, result.ErrorReason); 38 | 39 | public override string ToString() => IsSuccess ? "Success" : $"{Error}: {ErrorReason}"; 40 | private string DebuggerDisplay => IsSuccess ? $"Success ({Commands.Count} Results)" : $"{Error}: {ErrorReason}"; 41 | } -------------------------------------------------------------------------------- /RevoltSharp.Commands/RevoltSharp.Commands.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net6.0 5 | disable 6 | enable 7 | 8 | 1.2.1 9 | Builderb (Fluxpoint Development) 10 | Fluxpoint Development 11 | RevoltSharp.Commands 12 | A command handler for RevoltSharp with easy to use structure and parsing. 13 | https://docs.fluxpoint.dev/revoltsharp 14 | PackageIcon.png 15 | https://github.com/FluxpointDev/RevoltSharp 16 | revolt, revolt bot, bot, revoltsharp, revolt c# 17 | See changelog https://docs.fluxpoint.dev/revoltsharp/changelog 18 | 19 | True 20 | RevoltSharp.Commands.xml 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | True 30 | \ 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /RevoltSharp.InstanceAdmin/AdminConditions.cs: -------------------------------------------------------------------------------- 1 | namespace RevoltSharp; 2 | internal class AdminConditions 3 | { 4 | internal static void CheckIsPrivileged(RevoltClient client, string request) 5 | { 6 | if (!client.CurrentUser.IsPrivileged) 7 | throw new RevoltRestException($"The current user/bot account is not privileged to use the admin endpoints for the {request} request.", 400, RevoltErrorType.NotPrivileged); 8 | } 9 | 10 | internal static void ReportIdLength(string id, string request) 11 | { 12 | if (string.IsNullOrEmpty(id)) 13 | throw new RevoltArgumentException($"Report id can't be empty for the {request} request."); 14 | 15 | if (id.Length > Const.All_MaxIdLength) 16 | throw new RevoltArgumentException($"Report id length can't be more than {Const.All_MaxIdLength} characters for the {request} request."); 17 | } 18 | 19 | internal static void ReportReasonLength(string reason, string request) 20 | { 21 | if (string.IsNullOrEmpty(reason)) 22 | throw new RevoltArgumentException($"Report reason can't be empty for the {request} request."); 23 | 24 | } 25 | 26 | internal static void StrikeIdLength(string id, string request) 27 | { 28 | if (string.IsNullOrEmpty(id)) 29 | throw new RevoltArgumentException($"Strike id can't be empty for the {request} request."); 30 | 31 | if (id.Length > Const.All_MaxIdLength) 32 | throw new RevoltArgumentException($"Strike id length can't be more than {Const.All_MaxIdLength} characters for the {request} request."); 33 | } 34 | 35 | internal static void StrikeReasonLength(string reason, string request) 36 | { 37 | if (string.IsNullOrEmpty(reason)) 38 | throw new RevoltArgumentException($"Strike reason can't be empty for the {request} request."); 39 | 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /RevoltSharp.InstanceAdmin/Core/SafetyReport.cs: -------------------------------------------------------------------------------- 1 | namespace RevoltSharp; 2 | public class SafetyReport : CreatedEntity 3 | { 4 | internal SafetyReport(RevoltClient client, SafetyReportJson model) : base(client, model.Id) 5 | { 6 | Status = model.Status.ToEnum(); 7 | AuthorId = model.AuthorId!; 8 | AdditionalContext = model.AdditionalContext; 9 | Note = model.Note; 10 | Type = model.Content.Type.ToEnum(); 11 | ReportedContent = ISafetyReportContent.Create(client, Type, model.Content)!; 12 | } 13 | 14 | public SafetyReportStatus Status { get; internal set; } 15 | 16 | public string AuthorId { get; internal set; } 17 | 18 | public string? AdditionalContext { get; internal set; } 19 | 20 | public string? Note { get; internal set; } 21 | 22 | public SafetyReportType Type { get; internal set; } 23 | 24 | public ISafetyReportContent ReportedContent { get; internal set; } 25 | } 26 | 27 | public enum SafetyReportStatus 28 | { 29 | Created, Rejected, Resolved 30 | } 31 | public enum SafetyReportType 32 | { 33 | Message, User, Server 34 | } -------------------------------------------------------------------------------- /RevoltSharp.InstanceAdmin/Core/SafetyReportJson.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using Optionals; 3 | using System; 4 | 5 | namespace RevoltSharp; 6 | 7 | internal class SafetyReportJson 8 | { 9 | [JsonProperty("_id")] 10 | public string? Id; 11 | 12 | [JsonProperty("status")] 13 | public string? Status; 14 | 15 | [JsonProperty("author_id")] 16 | public string? AuthorId; 17 | 18 | [JsonProperty("content")] 19 | public SafetyReportedContentJson? Content; 20 | 21 | [JsonProperty("additional_context")] 22 | public string? AdditionalContext; 23 | 24 | [JsonProperty("notes")] 25 | public string? Note; 26 | 27 | [JsonProperty("rejection_reason")] 28 | public string? RejectionReason; 29 | 30 | [JsonProperty("closed_at")] 31 | public DateTime ClosedAt; 32 | } 33 | internal class SafetyReportedContentJson 34 | { 35 | [JsonProperty("type")] 36 | public string? Type { get; set; } 37 | 38 | [JsonProperty("id")] 39 | public string? Id { get; set; } 40 | 41 | [JsonProperty("message_id")] 42 | public Optional MessageId { get; set; } 43 | 44 | [JsonProperty("report_reason")] 45 | public string? Reason { get; set; } 46 | } 47 | -------------------------------------------------------------------------------- /RevoltSharp.InstanceAdmin/Core/SafetyUserStrike.cs: -------------------------------------------------------------------------------- 1 | namespace RevoltSharp; 2 | public class SafetyUserStrike : CreatedEntity 3 | { 4 | internal SafetyUserStrike(RevoltClient client, SafetyUserStrikeJson model) : base(client, model.Id) 5 | { 6 | UserId = model.Id; 7 | Reason = model.Reason; 8 | } 9 | 10 | public string UserId { get; internal set; } 11 | 12 | public string Reason { get; internal set; } 13 | } 14 | -------------------------------------------------------------------------------- /RevoltSharp.InstanceAdmin/Core/SafetyUserStrikeJson.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace RevoltSharp; 4 | 5 | internal class SafetyUserStrikeJson 6 | { 7 | [JsonProperty("_id")] 8 | public string? Id; 9 | 10 | [JsonProperty("user_id")] 11 | public string? UserId; 12 | 13 | [JsonProperty("reason")] 14 | public string? Reason; 15 | } 16 | -------------------------------------------------------------------------------- /RevoltSharp.InstanceAdmin/PackageIcon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FluxpointDev/RevoltSharp/133b03e27c8e61ac7472b081ca826124554eabcf/RevoltSharp.InstanceAdmin/PackageIcon.png -------------------------------------------------------------------------------- /RevoltSharp.InstanceAdmin/Requests/AdminGetMessagesRequest.cs: -------------------------------------------------------------------------------- 1 | using Optionals; 2 | using RevoltSharp.Rest; 3 | 4 | namespace RevoltSharp.Requests; 5 | internal class AdminGetMessagesRequest : IRevoltRequest 6 | { 7 | public Optional nearby { get; set; } 8 | 9 | public Optional before { get; set; } 10 | 11 | public Optional after { get; set; } 12 | 13 | public Optional sort { get; set; } 14 | 15 | public int limit { get; set; } 16 | 17 | public Optional channel { get; set; } 18 | 19 | public Optional author { get; set; } 20 | 21 | public Optional query { get; set; } 22 | } 23 | -------------------------------------------------------------------------------- /RevoltSharp.InstanceAdmin/Requests/AdminMessagesDataJson.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace RevoltSharp.Requests; 4 | internal class AdminMessagesDataJson 5 | { 6 | [JsonProperty("messages")] 7 | public MessageJson[]? Messages; 8 | 9 | [JsonProperty("users")] 10 | public UserJson[]? Users; 11 | } 12 | -------------------------------------------------------------------------------- /RevoltSharp.InstanceAdmin/Requests/AdminReportModifyRequest.cs: -------------------------------------------------------------------------------- 1 | using Optionals; 2 | using RevoltSharp.Rest; 3 | using System; 4 | 5 | namespace RevoltSharp.Requests; 6 | internal class AdminReportModifyRequest : IRevoltRequest 7 | { 8 | public AdminReportModifyStatusRequest? status; 9 | 10 | public Optional notes; 11 | } 12 | internal class AdminReportModifyStatusRequest 13 | { 14 | public string? status; 15 | public Optional rejection_reason; 16 | public Optional closed_at; 17 | } -------------------------------------------------------------------------------- /RevoltSharp.InstanceAdmin/Requests/AdminStrikeCreateRequest.cs: -------------------------------------------------------------------------------- 1 | using RevoltSharp.Rest; 2 | 3 | namespace RevoltSharp.Requests; 4 | internal class AdminStrikeCreateRequest : IRevoltRequest 5 | { 6 | public string? user_id; 7 | public string? reason; 8 | } 9 | -------------------------------------------------------------------------------- /RevoltSharp.InstanceAdmin/Requests/AdminStrikeModifyRequest.cs: -------------------------------------------------------------------------------- 1 | using RevoltSharp.Rest; 2 | 3 | namespace RevoltSharp.Requests; 4 | internal class AdminStrikeModifyRequest : IRevoltRequest 5 | { 6 | public string? reason; 7 | } 8 | -------------------------------------------------------------------------------- /RevoltSharp.InstanceAdmin/Requests/ReportContentRequest.cs: -------------------------------------------------------------------------------- 1 | using Optionals; 2 | using RevoltSharp.Rest; 3 | 4 | namespace RevoltSharp.Requests; 5 | internal class ReportContentRequest : IRevoltRequest 6 | { 7 | public SafetyReportedContentJson content { get; set; } = null!; 8 | public Optional additional_context { get; set; } 9 | } 10 | -------------------------------------------------------------------------------- /RevoltSharp.InstanceAdmin/Rest/AdminHelper.cs: -------------------------------------------------------------------------------- 1 | using Optionals; 2 | using RevoltSharp.Requests; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Collections.Immutable; 6 | using System.Linq; 7 | using System.Threading.Tasks; 8 | 9 | namespace RevoltSharp; 10 | public static class AdminHelper 11 | { 12 | public static async Task> GetMessagesAsync(this AdminClient admin, string channelId = null, string userId = null, string query = null, int messageCount = 100, bool includeAuthor = false, string nearbyMessageId = null, string beforeMessageId = null, string afterMessageId = null) 13 | { 14 | AdminConditions.CheckIsPrivileged(admin.Client, nameof(GetMessagesAsync)); 15 | Conditions.ChannelIdLength(channelId, nameof(GetMessagesAsync)); 16 | Conditions.MessageSearchCount(messageCount, nameof(GetMessagesAsync)); 17 | 18 | AdminGetMessagesRequest Req = new AdminGetMessagesRequest 19 | { 20 | limit = messageCount 21 | }; 22 | if (!string.IsNullOrEmpty(channelId)) 23 | Req.channel = Optional.Some(channelId); 24 | 25 | if (!string.IsNullOrEmpty(userId)) 26 | Req.author = Optional.Some(userId); 27 | 28 | if (!string.IsNullOrEmpty(query)) 29 | Req.query = Optional.Some(query); 30 | 31 | if (!string.IsNullOrEmpty(query)) 32 | Req.query = Optional.Some(query); 33 | 34 | if (!string.IsNullOrEmpty(nearbyMessageId)) 35 | Req.nearby = Optional.Some(nearbyMessageId); 36 | 37 | if (!string.IsNullOrEmpty(beforeMessageId)) 38 | Req.before = Optional.Some(beforeMessageId); 39 | 40 | if (!string.IsNullOrEmpty(afterMessageId)) 41 | Req.after = Optional.Some(afterMessageId); 42 | 43 | AdminMessagesDataJson Data = null; 44 | try 45 | { 46 | Data = await admin.Client.Rest.PostAsync($"admin/messages", Req); 47 | } 48 | catch 49 | { 50 | return Array.Empty(); 51 | } 52 | Dictionary Authors = includeAuthor ? Data.Users.ToDictionary(x => x.Id, x => new User(admin.Client, x)) : new Dictionary(); 53 | 54 | return Data.Messages.Select(x => new UserMessage(admin.Client, x) { Author = Authors.GetValueOrDefault(x.AuthorId) }).ToImmutableArray(); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /RevoltSharp.InstanceAdmin/RevoltSharp.InstanceAdmin.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0 5 | disable 6 | enable 7 | RevoltSharp 8 | False 9 | 10 | 1.0.1 11 | Builderb (Fluxpoint Development) 12 | Fluxpoint Development 13 | RevoltSharp.InstanceAdmin 14 | Methods and extensions for managing your own self-hosted Revolt instance. 15 | https://docs.fluxpoint.dev/revoltsharp 16 | PackageIcon.png 17 | https://github.com/FluxpointDev/RevoltSharp 18 | revolt, revolt bot, bot, revoltsharp, revolt c# 19 | See changelog https://docs.fluxpoint.dev/revoltsharp/changelog 20 | 21 | True 22 | RevoltSharp.InstanceAdmin.xml 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | \ 32 | True 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /RevoltSharp.InstanceAdmin/RevoltSharp.InstanceAdmin.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | RevoltSharp.InstanceAdmin 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /RevoltSharp.Voice/PackageIcon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FluxpointDev/RevoltSharp/133b03e27c8e61ac7472b081ca826124554eabcf/RevoltSharp.Voice/PackageIcon.png -------------------------------------------------------------------------------- /RevoltSharp.Voice/Requests/AuthenticateRequest.cs: -------------------------------------------------------------------------------- 1 | namespace RevoltSharp; 2 | 3 | 4 | internal class AuthenticateRequest 5 | { 6 | internal AuthenticateRequest(string channelId, string token) 7 | { 8 | data = new AuthDataRequest 9 | { 10 | roomId = channelId, 11 | token = token 12 | }; 13 | } 14 | public int id = 3; 15 | public string type = "Authenticate"; 16 | public AuthDataRequest data; 17 | } 18 | internal class AuthDataRequest 19 | { 20 | public string roomId = null!; 21 | public string token = null!; 22 | } 23 | internal class RoomInfoRequest 24 | { 25 | public int id = 13; 26 | public string type = "RoomInfo"; 27 | } -------------------------------------------------------------------------------- /RevoltSharp.Voice/RevoltSharp.Voice.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0 5 | enable 6 | RevoltSharp 7 | disable 8 | 9 | 1.0.0 10 | Builderb (Fluxpoint Development) 11 | Fluxpoint Development 12 | RevoltSharp.Voice 13 | A command handler for RevoltSharp with easy to use structure and parsing. 14 | https://docs.fluxpoint.dev/revoltsharp 15 | PackageIcon.png 16 | https://github.com/FluxpointDev/RevoltSharp 17 | revolt, revolt bot, bot, revoltsharp, revolt c# 18 | See changelog https://docs.fluxpoint.dev/revoltsharp/changelog 19 | 20 | True 21 | RevoltSharp.Voice.xml 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | \ 31 | True 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /RevoltSharp.Voice/RevoltSharp.Voice.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | RevoltSharp.Voice 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /RevoltSharp.Voice/RevoltVoiceClient.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Concurrent; 2 | using System.Threading.Tasks; 3 | 4 | namespace RevoltSharp; 5 | 6 | public class RevoltVoiceClient : IVoiceClient 7 | { 8 | public RevoltVoiceClient(RevoltClient client) 9 | { 10 | Client = client; 11 | } 12 | 13 | internal RevoltClient Client; 14 | 15 | public ConcurrentDictionary Channels { get; internal set; } = new ConcurrentDictionary(); 16 | 17 | public async Task StartAsync() 18 | { 19 | Client.Logger.LogMessage("Connecting to Voice Server", RevoltLogSeverity.Info); 20 | 21 | var Req = await Client.Rest.SendRequestAsync(Rest.RequestType.Get, Client.Config.Debug.VoiceServerUrl); 22 | if (Req.IsSuccessStatusCode) 23 | Client.Logger.LogMessage("Connected to Voice Server!", RevoltLogSeverity.Info); 24 | else 25 | Client.Logger.LogMessage("Failed to connect to Voice Server", RevoltLogSeverity.Warn); 26 | 27 | 28 | 29 | } 30 | 31 | public async Task StopAsync() 32 | { 33 | Client.Logger.LogMessage("Disconnecting from Voice Server", RevoltLogSeverity.Info); 34 | 35 | foreach (VoiceState s in Channels.Values) 36 | { 37 | await s.StopAsync(); 38 | Channels.TryRemove(s.Channel.Id, out _); 39 | } 40 | } 41 | } -------------------------------------------------------------------------------- /RevoltSharp.Voice/VoiceHelper.cs: -------------------------------------------------------------------------------- 1 | using System.Threading.Tasks; 2 | 3 | namespace RevoltSharp; 4 | 5 | 6 | public static class VoiceHelper 7 | { 8 | public static async Task JoinChannelAsync(this VoiceChannel channel) 9 | { 10 | VoiceRequestJson json = await channel.Client.Rest.PostAsync($"/channels/{channel.Id}/join_call"); 11 | VoiceState State = new VoiceState(channel, new VoiceSocketClient(channel.Client, channel.Id, json.token)); 12 | _ = State.ConnectAsync(); 13 | 14 | 15 | return State; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /RevoltSharp.Voice/VoiceRequestJson.cs: -------------------------------------------------------------------------------- 1 | namespace RevoltSharp; 2 | 3 | internal class VoiceRequestJson 4 | { 5 | public string? token; 6 | } -------------------------------------------------------------------------------- /RevoltSharp.Voice/VoiceState.cs: -------------------------------------------------------------------------------- 1 | using System.Threading.Tasks; 2 | 3 | namespace RevoltSharp; 4 | 5 | 6 | public class VoiceState 7 | { 8 | internal VoiceState(VoiceChannel channel, VoiceSocketClient con) 9 | { 10 | Connection = con; 11 | Channel = channel; 12 | } 13 | 14 | internal VoiceSocketClient Connection; 15 | public VoiceChannel Channel { get; internal set; } 16 | 17 | public async Task ConnectAsync() 18 | { 19 | await Connection.InternalConnectAsync(); 20 | } 21 | 22 | #pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously 23 | public async Task StopAsync() 24 | #pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously 25 | { 26 | Connection.StopWebSocket = true; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /RevoltSharp/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.CompilerServices; 2 | 3 | [assembly: InternalsVisibleTo("RevoltSharp.Rest")] 4 | [assembly: InternalsVisibleTo("RevoltSharp.Websocket")] 5 | [assembly: InternalsVisibleTo("RevoltSharp.Commands")] 6 | [assembly: InternalsVisibleTo("RevoltSharp.Voice")] 7 | [assembly: InternalsVisibleTo("RevoltSharp.InstanceAdmin")] -------------------------------------------------------------------------------- /RevoltSharp/Client/LoginResponseType.cs: -------------------------------------------------------------------------------- 1 | namespace RevoltSharp; 2 | 3 | public enum LoginResponseType 4 | { 5 | Success, MFARequired, Disabled, OnboardingRequired, Failed 6 | } 7 | -------------------------------------------------------------------------------- /RevoltSharp/Client/RevoltException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace RevoltSharp; 4 | 5 | 6 | /// 7 | /// Custom exception for the Revolt client. 8 | /// 9 | public class RevoltException : Exception 10 | { 11 | internal RevoltException(string message, int code = 0) : base(message) 12 | { 13 | Code = code; 14 | } 15 | 16 | /// 17 | /// The status code error for this exception if thrown by the rest client. 18 | /// 19 | public int Code { get; internal set; } 20 | } 21 | 22 | /// 23 | /// Custom exception for the Revolt rest client with code. 24 | /// 25 | public class RevoltRestException : RevoltException 26 | { 27 | internal RevoltRestException(string message, int code, RevoltErrorType type) : base(message, code) 28 | { 29 | Type = type; 30 | } 31 | 32 | /// 33 | /// The type of rest error triggered. 34 | /// 35 | public RevoltErrorType Type { get; internal set; } = RevoltErrorType.Unknown; 36 | 37 | /// 38 | /// The permission require for the error or 39 | /// 40 | public string? Permission { get; internal set; } 41 | } 42 | 43 | /// 44 | /// Custom exception for the Revolt rest client for permission issues. 45 | /// 46 | public class RevoltPermissionException : RevoltRestException 47 | { 48 | internal RevoltPermissionException(string permission, int code, bool userPerm) : base( 49 | userPerm ? $"Request failed due to other user missing permission {permission}" : $"Request failed due to missing permission {permission}", 50 | code, userPerm ? RevoltErrorType.MissingUserPermission : RevoltErrorType.MissingPermission) 51 | { 52 | base.Permission = permission; 53 | } 54 | 55 | /// 56 | public new string Permission => base.Permission!; 57 | } 58 | 59 | /// 60 | /// Custom exception for the Revolt client when user enters a missing or wrong argument. 61 | /// 62 | public class RevoltArgumentException : RevoltException 63 | { 64 | internal RevoltArgumentException(string message) : base(message, 400) 65 | { 66 | 67 | } 68 | } -------------------------------------------------------------------------------- /RevoltSharp/Core/Account/AccountInfo.cs: -------------------------------------------------------------------------------- 1 | namespace RevoltSharp; 2 | 3 | public class AccountInfo : CreatedEntity 4 | { 5 | internal AccountInfo(RevoltClient client, AccountInfoJson json) : base(client, json._id) 6 | { 7 | Email = json.email; 8 | } 9 | 10 | public string Email { get; internal set; } 11 | } 12 | -------------------------------------------------------------------------------- /RevoltSharp/Core/Account/AccountInfoJson.cs: -------------------------------------------------------------------------------- 1 |  2 | 3 | namespace RevoltSharp; 4 | internal class AccountInfoJson 5 | { 6 | public string _id { get; set; } 7 | public string email { get; set; } 8 | } 9 | -------------------------------------------------------------------------------- /RevoltSharp/Core/Account/AccountLogin.cs: -------------------------------------------------------------------------------- 1 | namespace RevoltSharp; 2 | 3 | public class AccountLogin 4 | { 5 | internal AccountLogin(AccountLoginJson json) 6 | { 7 | if (json == null) 8 | return; 9 | 10 | switch (json.Result) 11 | { 12 | case "Success": 13 | ResponseType = LoginResponseType.Success; 14 | break; 15 | case "MFA": 16 | ResponseType = LoginResponseType.MFARequired; 17 | break; 18 | case "Disabled": 19 | ResponseType = LoginResponseType.Disabled; 20 | break; 21 | default: 22 | ResponseType = LoginResponseType.Failed; 23 | break; 24 | } 25 | 26 | Id = json.Id; 27 | UserId = json.UserId; 28 | Token = json.Token; 29 | SessionName = json.Name; 30 | MFATicket = json.Ticket; 31 | MFAMethods = json.AllowedMethods; 32 | } 33 | 34 | public LoginResponseType ResponseType { get; set; } 35 | public string? Id { get; set; } 36 | public string? UserId { get; set; } 37 | public string? Token { get; set; } 38 | public string? SessionName { get; set; } 39 | public string? MFATicket { get; set; } 40 | public string[]? MFAMethods { get; set; } 41 | } 42 | -------------------------------------------------------------------------------- /RevoltSharp/Core/Account/AccountLoginJson.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace RevoltSharp; 4 | 5 | internal class AccountLoginJson 6 | { 7 | [JsonProperty("result")] 8 | public string Result { get; set; } 9 | 10 | [JsonProperty("_id")] 11 | public string Id { get; set; } 12 | 13 | [JsonProperty("user_id")] 14 | public string UserId { get; set; } 15 | 16 | [JsonProperty("token")] 17 | public string Token { get; set; } 18 | 19 | [JsonProperty("name")] 20 | public string Name { get; set; } 21 | 22 | [JsonProperty("ticket")] 23 | public string Ticket { get; set; } 24 | 25 | [JsonProperty("allowed_methods")] 26 | public string[] AllowedMethods { get; set; } 27 | } 28 | -------------------------------------------------------------------------------- /RevoltSharp/Core/Account/AccountMFA.cs: -------------------------------------------------------------------------------- 1 | namespace RevoltSharp; 2 | 3 | public class AccountMFA 4 | { 5 | internal AccountMFA(AccountMFAJson json) 6 | { 7 | EmailOTP = json.email_otp; 8 | TrustedHandover = json.trusted_handover; 9 | EmailMFA = json.email_mfa; 10 | TotpMFA = json.totp_mfa; 11 | SecurityKeyMFA = json.security_key_mfa; 12 | RecoveryActive = json.recovery_active; 13 | } 14 | 15 | public bool EmailOTP; 16 | public bool TrustedHandover; 17 | public bool EmailMFA; 18 | public bool TotpMFA; 19 | public bool SecurityKeyMFA; 20 | public bool RecoveryActive; 21 | } 22 | -------------------------------------------------------------------------------- /RevoltSharp/Core/Account/AccountMFAJson.cs: -------------------------------------------------------------------------------- 1 | namespace RevoltSharp; 2 | 3 | internal class AccountMFAJson 4 | { 5 | public bool email_otp { get; set; } 6 | public bool trusted_handover { get; set; } 7 | public bool email_mfa { get; set; } 8 | public bool totp_mfa { get; set; } 9 | public bool security_key_mfa { get; set; } 10 | public bool recovery_active { get; set; } 11 | } 12 | -------------------------------------------------------------------------------- /RevoltSharp/Core/Account/AccountSession.cs: -------------------------------------------------------------------------------- 1 | namespace RevoltSharp; 2 | 3 | public class AccountSession : CreatedEntity 4 | { 5 | public AccountSession(AccountSessionJson session, RevoltClient client) : base(client, session.Id) 6 | { 7 | Id = session.Id; 8 | Name = session.Name; 9 | } 10 | 11 | public string Id { get; internal set; } 12 | 13 | public string Name { get; internal set; } 14 | } 15 | -------------------------------------------------------------------------------- /RevoltSharp/Core/Account/AccountSessionJson.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace RevoltSharp; 4 | public class AccountSessionJson 5 | { 6 | [JsonProperty("_id")] 7 | public string Id { get; set; } 8 | 9 | [JsonProperty("name")] 10 | public string Name { get; set; } 11 | } 12 | -------------------------------------------------------------------------------- /RevoltSharp/Core/Account/AccountType.cs: -------------------------------------------------------------------------------- 1 | namespace RevoltSharp; 2 | public enum AccountType 3 | { 4 | User, Bot 5 | } 6 | -------------------------------------------------------------------------------- /RevoltSharp/Core/Account/ChannelReadState.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace RevoltSharp; 4 | public class ChannelReadState 5 | { 6 | internal ChannelReadState(ChannelReadStateJson json) 7 | { 8 | ChannelId = json._id.channel; 9 | LastMessageId = json.last_id; 10 | Mentions = json.mentions != null ? json.mentions : Array.Empty(); 11 | } 12 | 13 | public string ChannelId { get; internal set; } 14 | public string? LastMessageId { get; internal set; } 15 | public string[] Mentions { get; internal set; } 16 | } 17 | -------------------------------------------------------------------------------- /RevoltSharp/Core/Account/ChannelReadStateJson.cs: -------------------------------------------------------------------------------- 1 | namespace RevoltSharp; 2 | internal class ChannelReadStateJson 3 | { 4 | public ChannelReadStateIdsJson _id; 5 | public string last_id; 6 | public string[] mentions; 7 | } 8 | internal class ChannelReadStateIdsJson 9 | { 10 | public string channel; 11 | } 12 | -------------------------------------------------------------------------------- /RevoltSharp/Core/Account/MFAType.cs: -------------------------------------------------------------------------------- 1 | namespace RevoltSharp; 2 | public enum MFAType 3 | { 4 | Totp, Recovery 5 | } 6 | -------------------------------------------------------------------------------- /RevoltSharp/Core/Account/OnboardStatus.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace RevoltSharp; 4 | public class OnboardStatus 5 | { 6 | [JsonProperty("onboarding")] 7 | public bool IsOnboardingRequired { get; set; } 8 | } 9 | -------------------------------------------------------------------------------- /RevoltSharp/Core/Bots/PublicBot.cs: -------------------------------------------------------------------------------- 1 | namespace RevoltSharp; 2 | 3 | /// 4 | /// Info about a public bot on Revolt. 5 | /// 6 | public class PublicBot : CreatedEntity 7 | { 8 | internal PublicBot(RevoltClient client, PublicBotJson model) : base(client, model.Id) 9 | { 10 | Username = model.Username!; 11 | AvatarId = model.AvatarId; 12 | Description = model.Description; 13 | } 14 | 15 | /// 16 | /// The username of the bot. 17 | /// 18 | public string Username { get; internal set; } 19 | 20 | /// 21 | /// The avatar id of the bot. 22 | /// 23 | public string? AvatarId { get; internal set; } 24 | 25 | /// 26 | /// Gets the bot's avatar. 27 | /// 28 | /// Which avatar to return. 29 | /// URL of the image 30 | public string? GetAvatarUrl(AvatarSources which = AvatarSources.Any) 31 | { 32 | if (!string.IsNullOrEmpty(AvatarId) && (which | AvatarSources.User) != 0) 33 | { 34 | return $"{Client.Config.Debug.UploadUrl}avatars/{Id}/{AvatarId}"; 35 | } 36 | 37 | if ((which | AvatarSources.Default) != 0) 38 | { 39 | return $"{Client.Config.ApiUrl}users/{Id}/default_avatar"; 40 | } 41 | 42 | return null; 43 | } 44 | 45 | /// 46 | /// The description of the bot. 47 | /// 48 | public string? Description { get; internal set; } 49 | 50 | /// Returns a string that represents the current object. 51 | /// Bot username 52 | public override string ToString() 53 | { 54 | return Username; 55 | } 56 | } -------------------------------------------------------------------------------- /RevoltSharp/Core/Bots/PublicBotJson.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace RevoltSharp; 4 | 5 | internal class PublicBotJson 6 | { 7 | [JsonProperty("_id")] 8 | public string? Id { get; set; } 9 | 10 | [JsonProperty("username")] 11 | public string? Username { get; set; } 12 | 13 | [JsonProperty("avatar")] 14 | public string? AvatarId { get; set; } 15 | 16 | [JsonProperty("description")] 17 | public string? Description { get; set; } 18 | } -------------------------------------------------------------------------------- /RevoltSharp/Core/Channels/Channel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace RevoltSharp; 4 | 5 | /// 6 | /// Revolt channel that can be casted to types , , or 7 | /// 8 | public abstract class Channel : CreatedEntity 9 | { 10 | /// 11 | /// Id of the channel. 12 | /// 13 | public new string Id => base.Id; 14 | 15 | /// 16 | /// Date of when the channel was created. 17 | /// 18 | public new DateTimeOffset CreatedAt => base.CreatedAt; 19 | 20 | /// 21 | /// The channel type to cast to. 22 | /// 23 | public ChannelType Type { get; internal set; } 24 | 25 | internal Channel(RevoltClient client, ChannelJson model) 26 | : base(client, model?.Id) 27 | { } 28 | 29 | internal abstract void Update(PartialChannelJson json); 30 | 31 | internal Channel Clone() 32 | { 33 | return (Channel)this.MemberwiseClone(); 34 | } 35 | 36 | internal static Channel Create(RevoltClient client, ChannelJson model) 37 | { 38 | switch (model.ChannelType) 39 | { 40 | case ChannelType.SavedMessages: 41 | return new SavedMessagesChannel(client, model); 42 | case ChannelType.DM: 43 | return new DMChannel(client, model); 44 | case ChannelType.Group: 45 | return new GroupChannel(client, model); 46 | case ChannelType.Text: 47 | return new TextChannel(client, model); 48 | case ChannelType.Voice: 49 | return new VoiceChannel(client, model); 50 | default: 51 | { 52 | if (!string.IsNullOrEmpty(model.ServerId)) 53 | { 54 | return new UnknownServerChannel(client, model); 55 | } 56 | 57 | return new UnknownChannel(client, model); 58 | } 59 | } 60 | } 61 | 62 | /// Returns a string that represents the current object. 63 | /// Channel 64 | public override string ToString() 65 | { 66 | return Type.ToString(); 67 | } 68 | } -------------------------------------------------------------------------------- /RevoltSharp/Core/Channels/ChannelJson.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using System.Collections.Generic; 3 | 4 | namespace RevoltSharp; 5 | 6 | 7 | internal class ChannelJson 8 | { 9 | [JsonProperty("_id")] 10 | public string Id { get; set; } 11 | 12 | [JsonProperty("channel_type")] 13 | public ChannelType ChannelType { get; set; } 14 | 15 | [JsonProperty("nonce")] 16 | public string? Nonce { get; set; } 17 | 18 | [JsonProperty("user")] 19 | public string? UserId { get; set; } 20 | 21 | [JsonProperty("active")] 22 | public bool Active { get; set; } 23 | 24 | [JsonProperty("recipients")] 25 | public string[]? Recipients { get; set; } 26 | 27 | [JsonProperty("last_message_id")] 28 | public string? LastMessageId { get; set; } 29 | 30 | [JsonProperty("icon")] 31 | public AttachmentJson? Icon { get; set; } 32 | 33 | [JsonProperty("description")] 34 | public string? Description { get; set; } 35 | 36 | [JsonProperty("name")] 37 | public string? Name { get; set; } 38 | 39 | [JsonProperty("owner")] 40 | public string? OwnerId { get; set; } 41 | 42 | [JsonProperty("permissions")] 43 | public ulong Permissions { get; set; } 44 | 45 | [JsonProperty("default_permissions")] 46 | public PermissionsJson? DefaultPermissions { get; set; } 47 | 48 | [JsonProperty("role_permissions")] 49 | public Dictionary? RolePermissions { get; set; } 50 | 51 | [JsonProperty("server")] 52 | public string? ServerId { get; set; } 53 | 54 | [JsonProperty("nsfw")] 55 | public bool IsNsfw { get; set; } 56 | } -------------------------------------------------------------------------------- /RevoltSharp/Core/Channels/DmChannel.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | 3 | namespace RevoltSharp; 4 | 5 | 6 | /// 7 | /// A channel between the current user/bot account and another user. 8 | /// 9 | public class DMChannel : Channel 10 | { 11 | internal DMChannel(RevoltClient client, ChannelJson model) : base(client, model) 12 | { 13 | Type = ChannelType.DM; 14 | Active = model.Active; 15 | UserId = model.Recipients.First(x => x != client.CurrentUser.Id); 16 | LastMessageId = model.LastMessageId; 17 | } 18 | 19 | /// 20 | /// If the channel is still open for both users. 21 | /// 22 | public bool Active { get; internal set; } 23 | 24 | /// 25 | /// The user id for this DM channel. 26 | /// 27 | public string UserId { get; internal set; } 28 | 29 | /// 30 | /// The user for this DM channel. 31 | /// 32 | public User? User => Client.GetUser(UserId); 33 | 34 | /// 35 | /// The last message id sent in this DM channel. 36 | /// 37 | public string? LastMessageId { get; internal set; } 38 | 39 | internal override void Update(PartialChannelJson json) 40 | { 41 | if (json.Active.HasValue) 42 | Active = json.Active.Value; 43 | } 44 | 45 | /// Returns a string that represents the current object. 46 | /// User#0001 or Unknown User 47 | public override string ToString() 48 | { 49 | return User != null ? User.Tag : "Unknown User"; 50 | } 51 | } -------------------------------------------------------------------------------- /RevoltSharp/Core/Channels/PartialChannelJson.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using Optionals; 3 | using System.Collections.Generic; 4 | 5 | namespace RevoltSharp; 6 | 7 | 8 | internal class PartialChannelJson 9 | { 10 | [JsonProperty("active")] 11 | public Optional Active { get; set; } 12 | 13 | [JsonProperty("name")] 14 | public Optional Name { get; set; } 15 | 16 | [JsonProperty("icon")] 17 | public Optional Icon { get; set; } 18 | 19 | [JsonProperty("description")] 20 | public Optional Description { get; set; } 21 | 22 | [JsonProperty("default_permissions")] 23 | public Optional DefaultPermissions { get; set; } 24 | 25 | [JsonProperty("permissions")] 26 | public Optional Permissions { get; set; } 27 | 28 | [JsonProperty("role_permissions")] 29 | public Optional> RolePermissions { get; set; } 30 | 31 | [JsonProperty("nsfw")] 32 | public Optional IsNsfw { get; set; } 33 | 34 | [JsonProperty("owner")] 35 | public Optional OwnerId { get; set; } 36 | } -------------------------------------------------------------------------------- /RevoltSharp/Core/Channels/SavedMessagesChannel.cs: -------------------------------------------------------------------------------- 1 | namespace RevoltSharp; 2 | 3 | /// 4 | /// A private notes channel for the current user. 5 | /// 6 | public class SavedMessagesChannel : Channel 7 | { 8 | internal SavedMessagesChannel(RevoltClient client, ChannelJson model) : base(client, model) 9 | { 10 | Type = ChannelType.SavedMessages; 11 | LastMessageId = model.LastMessageId; 12 | } 13 | 14 | /// 15 | /// The last message id sent in this DM channel. 16 | /// 17 | public string? LastMessageId { get; internal set; } 18 | 19 | internal override void Update(PartialChannelJson json) 20 | { 21 | 22 | } 23 | 24 | /// Returns a string that represents the current object. 25 | /// CurrentUser#0001 26 | public override string ToString() 27 | { 28 | return Client.CurrentUser.Tag; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /RevoltSharp/Core/Channels/TextChannel.cs: -------------------------------------------------------------------------------- 1 | namespace RevoltSharp; 2 | 3 | 4 | /// 5 | /// Server text channel that members can talk in. 6 | /// 7 | public class TextChannel : ServerChannel 8 | { 9 | internal TextChannel(RevoltClient client, ChannelJson model) : base(client, model) 10 | { 11 | Type = ChannelType.Text; 12 | LastMessageId = model.LastMessageId; 13 | IsNsfw = model.IsNsfw; 14 | } 15 | 16 | /// 17 | /// The last message id sent in this Text channel. 18 | /// 19 | public string? LastMessageId { get; internal set; } 20 | 21 | /// 22 | /// Channel has nsfw content. 23 | /// 24 | public bool IsNsfw { get; internal set; } 25 | 26 | internal override void Update(PartialChannelJson json) 27 | { 28 | if (json.IsNsfw.HasValue) 29 | IsNsfw = json.IsNsfw.Value; 30 | base.Update(json); 31 | } 32 | } -------------------------------------------------------------------------------- /RevoltSharp/Core/Channels/UnknownChannel.cs: -------------------------------------------------------------------------------- 1 | namespace RevoltSharp; 2 | 3 | 4 | /// 5 | /// Channel is an unknown type that can't be fully used 6 | /// 7 | public class UnknownChannel : Channel 8 | { 9 | internal UnknownChannel(RevoltClient client, ChannelJson model) : base(client, model) 10 | { 11 | Type = ChannelType.Unknown; 12 | } 13 | 14 | internal override void Update(PartialChannelJson json) 15 | { 16 | } 17 | 18 | /// Returns a string that represents the current object. 19 | /// Unknown Channel 20 | public override string ToString() 21 | { 22 | return "Unknown Channel"; 23 | } 24 | } 25 | 26 | /// 27 | /// Channel is an unknown type that can't be fully used 28 | /// 29 | public class UnknownServerChannel : ServerChannel 30 | { 31 | internal UnknownServerChannel(RevoltClient client, ChannelJson model) : base(client, model) 32 | { 33 | Type = ChannelType.Unknown; 34 | } 35 | } -------------------------------------------------------------------------------- /RevoltSharp/Core/Channels/VoiceChannel.cs: -------------------------------------------------------------------------------- 1 | namespace RevoltSharp; 2 | 3 | 4 | /// 5 | /// Channel that members can speak in to other members 6 | /// 7 | public class VoiceChannel : ServerChannel 8 | { 9 | internal VoiceChannel(RevoltClient client, ChannelJson model) 10 | : base(client, model) 11 | { 12 | Type = ChannelType.Voice; 13 | } 14 | } -------------------------------------------------------------------------------- /RevoltSharp/Core/Client/Query.cs: -------------------------------------------------------------------------------- 1 | namespace RevoltSharp; 2 | 3 | /// 4 | /// Query information about the connected Revolt instance. 5 | /// 6 | public class Query 7 | { 8 | #pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring as nullable. 9 | internal Query(QueryJson json) 10 | #pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring as nullable. 11 | { 12 | RevoltVersion = json.RevoltVersion; 13 | AppUrl = json.AppUrl; 14 | WebsocketUrl = json.WebsocketUrl; 15 | CaptchaEnabled = json.ServerFeatures.captcha.enabled; 16 | EmailEnabled = json.ServerFeatures.email; 17 | InviteOnly = json.ServerFeatures.invite_only; 18 | ImageServerUrl = json.ServerFeatures.ImageServer.url; 19 | if (!ImageServerUrl.EndsWith("/")) 20 | ImageServerUrl += "/"; 21 | 22 | JanuaryServerUrl = json.ServerFeatures.JanuaryServer.url; 23 | if (!JanuaryServerUrl.EndsWith("/")) 24 | JanuaryServerUrl += "/"; 25 | 26 | VoiceApiUrl = json.ServerFeatures.VoiceServer.url; 27 | if (!VoiceApiUrl.EndsWith("/")) 28 | VoiceApiUrl += "/"; 29 | 30 | VoiceWebsocketUrl = json.ServerFeatures.VoiceServer.ws; 31 | } 32 | 33 | #pragma warning disable CS1591 // Missing XML comment for publicly visible type or member 34 | 35 | public string RevoltVersion { get; internal set; } 36 | 37 | public string AppUrl { get; internal set; } 38 | 39 | public string WebsocketUrl { get; internal set; } 40 | 41 | public bool CaptchaEnabled { get; internal set; } 42 | 43 | public bool EmailEnabled { get; internal set; } 44 | 45 | public bool InviteOnly { get; internal set; } 46 | 47 | public string ImageServerUrl { get; internal set; } 48 | 49 | public string JanuaryServerUrl { get; internal set; } 50 | 51 | public string VoiceApiUrl { get; internal set; } 52 | 53 | public string VoiceWebsocketUrl { get; internal set; } 54 | 55 | #pragma warning restore CS1591 // Missing XML comment for publicly visible type or member 56 | } 57 | -------------------------------------------------------------------------------- /RevoltSharp/Core/Client/QueryJson.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace RevoltSharp; 4 | 5 | 6 | internal class QueryJson 7 | { 8 | [JsonProperty("revolt")] 9 | public string? RevoltVersion { get; set; } 10 | 11 | [JsonProperty("features")] 12 | public QueryFeaturesJson? ServerFeatures { get; set; } 13 | 14 | [JsonProperty("ws")] 15 | public string? WebsocketUrl { get; set; } 16 | 17 | [JsonProperty("app")] 18 | public string? AppUrl { get; set; } 19 | } 20 | internal class QueryFeaturesJson 21 | { 22 | [JsonProperty("autumn")] 23 | public QueryAutumnJson? ImageServer { get; set; } 24 | 25 | [JsonProperty("january")] 26 | public QueryJanuaryJson? JanuaryServer { get; set; } 27 | 28 | [JsonProperty("voso")] 29 | public QueryVosoJson? VoiceServer { get; set; } 30 | 31 | public QueryCaptchaJson? captcha { get; set; } 32 | 33 | public bool email { get; set; } 34 | public bool invite_only { get; set; } 35 | } 36 | internal class QueryCaptchaJson 37 | { 38 | public bool enabled { get; set; } 39 | } 40 | internal class QueryAutumnJson 41 | { 42 | public string? url { get; set; } 43 | } 44 | internal class QueryJanuaryJson 45 | { 46 | public string? url { get; set; } 47 | } 48 | internal class QueryVosoJson 49 | { 50 | public string? url { get; set; } 51 | public string? ws { get; set; } 52 | } -------------------------------------------------------------------------------- /RevoltSharp/Core/Emotes/EmojiJson.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace RevoltSharp; 4 | 5 | #pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring as nullable. 6 | internal class EmojiJson 7 | { 8 | [JsonProperty("_id")] 9 | public string Id { get; set; } 10 | 11 | [JsonProperty("name")] 12 | public string Name { get; set; } 13 | 14 | [JsonProperty("parent")] 15 | public EmojiParentJson Parent { get; set; } 16 | 17 | [JsonProperty("creator_id")] 18 | public string CreatorId { get; set; } 19 | 20 | [JsonProperty("animated")] 21 | public bool Animated { get; set; } 22 | 23 | [JsonProperty("nsfw")] 24 | public bool Nsfw { get; set; } 25 | } 26 | internal class EmojiParentJson 27 | { 28 | [JsonProperty("id")] 29 | public string ServerId { get; set; } 30 | } 31 | #pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring as nullable. -------------------------------------------------------------------------------- /RevoltSharp/Core/Entity.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using System; 3 | 4 | namespace RevoltSharp; 5 | 6 | /// 7 | /// A Revolt object entity that has the client attached. 8 | /// 9 | public abstract class Entity 10 | { 11 | [JsonIgnore] 12 | internal RevoltClient Client { get; } 13 | 14 | internal Entity(RevoltClient client) 15 | { 16 | Client = client; 17 | } 18 | } 19 | 20 | /// 21 | /// A Revolt object entity that has an ID, Created date and Client. 22 | /// 23 | public abstract class CreatedEntity : Entity 24 | { 25 | internal CreatedEntity(RevoltClient client, string id) : base(client) 26 | { 27 | Id = id; 28 | if (Id.Length > 3 && Ulid.TryParse(Id, out Ulid UID)) 29 | CreatedAt = UID.Time; 30 | } 31 | 32 | /// 33 | /// Id of the object. 34 | /// 35 | public string Id { get; set; } 36 | 37 | /// 38 | /// Date of when the object was created. 39 | /// 40 | public DateTimeOffset CreatedAt { get; set; } 41 | } -------------------------------------------------------------------------------- /RevoltSharp/Core/Enums/ChannelPermission.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace RevoltSharp; 4 | 5 | 6 | /// 7 | /// List of channel permissions. 8 | /// 9 | [Flags] 10 | public enum ChannelPermission : ulong 11 | { 12 | /// 13 | /// Can edit the channel info, icon, description or delete the channel. 14 | /// 15 | ManageChannel = 1L << 0, 16 | /// 17 | /// Can change the permissions of the channel. 18 | /// 19 | ManagePermissions = 1L << 2, 20 | /// 21 | /// Can view the channel and messages. 22 | /// 23 | ViewChannel = 1L << 20, 24 | /// 25 | /// Can send messages in the channel. 26 | /// 27 | SendMessages = 1L << 22, 28 | /// 29 | /// Can moderate messages in the channel by deleting them or removing reactions. 30 | /// 31 | ManageMessages = 1L << 23, 32 | /// 33 | /// Can create, edit and delete external webhooks. 34 | /// 35 | ManageWebhooks = 1L << 24, 36 | /// 37 | /// Can create server invites for the channel. 38 | /// 39 | CreateInvites = 1L << 25, 40 | /// 41 | /// Can send embed messages in the channel. 42 | /// 43 | SendEmbeds = 1L << 26, 44 | /// 45 | /// Can upload files and images in the channel. 46 | /// 47 | UploadFiles = 1L << 27, 48 | /// 49 | /// Can send fake author messages in the channel for use with bridged chats from other platforms. 50 | /// 51 | Masquerade = 1L << 28, 52 | /// 53 | /// Can add reactions to messages in the channel. 54 | /// 55 | AddReactions = 1L << 29, 56 | /// 57 | /// Can connect to the voice channel. 58 | /// 59 | VoiceConnect = 1L << 30, 60 | /// 61 | /// Can speak in the voice channel. 62 | /// 63 | VoiceSpeak = 1L << 31, 64 | /// 65 | /// Can use video in the voice channel. 66 | /// 67 | VoiceVideo = 1L << 32, 68 | /// 69 | /// Can mute other members in the voice channel. 70 | /// 71 | VoiceMuteMembers = 1L << 33, 72 | /// 73 | /// Can deafen other members in the voice channel. 74 | /// 75 | VoiceDeafenMembers = 1L << 34, 76 | /// 77 | /// Can move other members in the voice channel to other voice channels. 78 | /// 79 | VoiceMoveMembers = 1L << 35 80 | } -------------------------------------------------------------------------------- /RevoltSharp/Core/Enums/ChannelType.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using Newtonsoft.Json.Converters; 3 | using System.Runtime.Serialization; 4 | 5 | namespace RevoltSharp; 6 | 7 | 8 | /// 9 | /// Type of channel that is , , , or 10 | /// 11 | [JsonConverter(typeof(StringEnumConverter))] 12 | public enum ChannelType 13 | { 14 | /// 15 | /// Unknown channel type that could not be parsed. 16 | /// 17 | Unknown, 18 | /// 19 | /// A Text channel that can send and recieve messages. 20 | /// 21 | [EnumMember(Value = "TextChannel")] 22 | Text, 23 | /// 24 | /// A Voice channel that can be used to talk or show video calls with others. 25 | /// 26 | [EnumMember(Value = "VoiceChannel")] 27 | Voice, 28 | /// 29 | /// A private notes channels for the current user. 30 | /// 31 | SavedMessages, 32 | /// 33 | /// A private group of users. 34 | /// 35 | Group, 36 | /// 37 | /// A private channel between another user. 38 | /// 39 | [EnumMember(Value = "DirectMessage")] 40 | DM 41 | } -------------------------------------------------------------------------------- /RevoltSharp/Core/Enums/MessageFlag.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace RevoltSharp; 4 | 5 | /// 6 | /// List of message flags. 7 | /// 8 | [Flags] 9 | public enum MessageFlag : ulong 10 | { 11 | /// 12 | /// Message has no flags. 13 | /// 14 | None = 0, 15 | /// 16 | /// Message has supressed notifications for other users. 17 | /// 18 | SupressNotifications = 1L << 0 19 | } 20 | -------------------------------------------------------------------------------- /RevoltSharp/Core/IVoiceClient.cs: -------------------------------------------------------------------------------- 1 | using System.Threading.Tasks; 2 | 3 | namespace RevoltSharp; 4 | 5 | public interface IVoiceClient 6 | { 7 | Task StartAsync(); 8 | 9 | Task StopAsync(); 10 | } -------------------------------------------------------------------------------- /RevoltSharp/Core/Messages/AttachmentJson.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace RevoltSharp; 4 | 5 | 6 | internal class AttachmentJson 7 | { 8 | [JsonProperty("_id")] 9 | public string Id { get; set; } = null!; 10 | 11 | [JsonProperty("tag")] 12 | public string Tag { get; set; } = null!; 13 | 14 | [JsonProperty("filename")] 15 | public string Filename { get; set; } = null!; 16 | 17 | [JsonProperty("metadata")] 18 | public AttachmentMetaJson? Metadata { get; set; } = null!; 19 | 20 | [JsonProperty("content_type")] 21 | public string ContentType { get; set; } = null!; 22 | 23 | [JsonProperty("size")] 24 | public int FileSize { get; set; } 25 | 26 | [JsonProperty("deleted")] 27 | public bool? Deleted { get; set; } 28 | 29 | [JsonProperty("reported")] 30 | public bool? Reported { get; set; } 31 | } 32 | internal class AttachmentMetaJson 33 | { 34 | [JsonProperty("type")] 35 | public string Type { get; set; } = null!; 36 | 37 | [JsonProperty("width")] 38 | public int? Width { get; set; } 39 | 40 | [JsonProperty("height")] 41 | public int? Height { get; set; } 42 | } -------------------------------------------------------------------------------- /RevoltSharp/Core/Messages/BulkMessagesJson.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace RevoltSharp; 4 | 5 | internal class BulkMessagesJson 6 | { 7 | [JsonProperty("messages")] 8 | public MessageJson[] Messages { get; set; } 9 | 10 | [JsonProperty("users")] 11 | public UserJson[] Users { get; set; } 12 | 13 | [JsonProperty("members")] 14 | public ServerMemberJson[] Members { get; set; } 15 | } 16 | -------------------------------------------------------------------------------- /RevoltSharp/Core/Messages/EmbedJson.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using Newtonsoft.Json.Converters; 3 | using Optionals; 4 | 5 | namespace RevoltSharp; 6 | 7 | 8 | internal class EmbedJson 9 | { 10 | [JsonConverter(typeof(StringEnumConverter))] 11 | public EmbedType type { get; set; } 12 | public int width { get; set; } 13 | public int height { get; set; } 14 | public string? icon_url { get; set; } 15 | public string? url { get; set; } 16 | public string? title { get; set; } 17 | public string? site_name { get; set; } 18 | public string? description { get; set; } 19 | public EmbedMediaJson? image { get; set; } 20 | public object? media { get; set; } 21 | public EmbedMediaJson? video { get; set; } 22 | public Optional colour { get; set; } 23 | public EmbedSpecialJson? special { get; set; } 24 | } 25 | internal class EmbedSpecialJson 26 | { 27 | [JsonConverter(typeof(StringEnumConverter)), JsonProperty("type")] 28 | public EmbedProviderType Type { get; set; } 29 | } 30 | internal class EmbedMediaJson 31 | { 32 | [JsonProperty("url")] 33 | public string Url { get; set; } = null!; 34 | 35 | [JsonProperty("width")] 36 | public int Width { get; set; } 37 | 38 | [JsonProperty("height")] 39 | public int Height { get; set; } 40 | } -------------------------------------------------------------------------------- /RevoltSharp/Core/Messages/FileAttachment.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace RevoltSharp; 4 | 5 | 6 | /// 7 | /// Uploaded file attachment that can be used in other requests such as CreateEmojiAsync 8 | /// 9 | public class FileAttachment : CreatedEntity 10 | { 11 | public FileAttachment(RevoltClient client, string id) : base(client, id) 12 | { 13 | 14 | } 15 | 16 | /// 17 | /// Id of the attachment. 18 | /// 19 | public new string Id => base.Id; 20 | 21 | /// 22 | /// Date of when the attachment was created. 23 | /// 24 | public new DateTimeOffset CreatedAt => base.CreatedAt; 25 | } -------------------------------------------------------------------------------- /RevoltSharp/Core/Messages/FileAttachmentJson.cs: -------------------------------------------------------------------------------- 1 | namespace RevoltSharp; 2 | 3 | 4 | internal class FileAttachmentJson 5 | { 6 | public string? id { get; set; } 7 | } -------------------------------------------------------------------------------- /RevoltSharp/Core/Messages/MessageInteractions.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | 3 | namespace RevoltSharp; 4 | 5 | 6 | public class MessageInteractions 7 | { 8 | public MessageInteractions(Emoji[] reactions, bool restricted = false) 9 | { 10 | Reactions = reactions; 11 | RestrictReactions = restricted; 12 | } 13 | public Emoji[] Reactions { get; } 14 | public bool RestrictReactions { get; } 15 | 16 | internal MessageInteractionsJson ToJson() 17 | { 18 | return new MessageInteractionsJson 19 | { 20 | reactions = Reactions.Select(x => x.Name).ToArray(), 21 | restrict_reactions = RestrictReactions 22 | }; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /RevoltSharp/Core/Messages/MessageInteractionsJson.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace RevoltSharp; 3 | 4 | 5 | internal class MessageInteractionsJson 6 | { 7 | public string[]? reactions { get; set; } 8 | public bool restrict_reactions { get; set; } 9 | } -------------------------------------------------------------------------------- /RevoltSharp/Core/Messages/MessageJson.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using Optionals; 3 | using System; 4 | using System.Collections.Generic; 5 | 6 | namespace RevoltSharp; 7 | 8 | 9 | internal class MessageJson 10 | { 11 | [JsonProperty("_id")] 12 | public string MessageId { get; set; } = null!; 13 | 14 | [JsonProperty("type")] 15 | public string? MessageType { get; set; } 16 | 17 | [JsonProperty("nonce")] 18 | public string? Nonce { get; set; } 19 | 20 | [JsonProperty("channel")] 21 | public string ChannelId { get; set; } = null!; 22 | 23 | [JsonProperty("author")] 24 | public string AuthorId { get; set; } = null!; 25 | 26 | [JsonProperty("content")] 27 | public string? Content { get; set; } 28 | 29 | [JsonProperty("attachments")] 30 | public AttachmentJson[]? Attachments { get; set; } 31 | 32 | [JsonProperty("mentions")] 33 | public string[]? Mentions { get; set; } 34 | 35 | [JsonProperty("replies")] 36 | public string[]? Replies { get; set; } 37 | 38 | [JsonProperty("embeds")] 39 | public EmbedJson[]? Embeds { get; set; } 40 | 41 | [JsonProperty("system")] 42 | public MessageSystemJson? System { get; set; } 43 | 44 | [JsonProperty("webhook")] 45 | public MessageWebhookJson? Webhook { get; set; } 46 | 47 | [JsonProperty("edited")] 48 | public Optional EditedAt { get; set; } 49 | 50 | [JsonProperty("reactions")] 51 | public Optional> Reactions { get; set; } 52 | 53 | [JsonProperty("masquerade")] 54 | public MessageMasqueradeJson? Masquerade { get; set; } 55 | 56 | [JsonProperty("flags")] 57 | public MessageFlag Flags { get; set; } 58 | } 59 | internal class MessageMasqueradeJson 60 | { 61 | [JsonProperty("name")] 62 | public string? Name { get; set; } 63 | 64 | [JsonProperty("avatar")] 65 | public string? AvatarUrl { get; set; } 66 | 67 | [JsonProperty("colour")] 68 | public Optional Color { get; set; } 69 | } 70 | internal class MessageSystemJson 71 | { 72 | [JsonProperty("type")] 73 | public string? SystemType { get; set; } 74 | 75 | [JsonProperty("id")] 76 | public string? Id { get; set; } 77 | 78 | [JsonProperty("by")] 79 | public string? By { get; set; } 80 | 81 | [JsonProperty("name")] 82 | public string? Name { get; set; } 83 | 84 | [JsonProperty("from")] 85 | public string? From { get; set; } 86 | 87 | [JsonProperty("to")] 88 | public string? To { get; set; } 89 | 90 | [JsonProperty("content")] 91 | public string? Content { get; set; } 92 | } -------------------------------------------------------------------------------- /RevoltSharp/Core/Messages/MessageMasquerade.cs: -------------------------------------------------------------------------------- 1 | using Optionals; 2 | 3 | namespace RevoltSharp; 4 | 5 | 6 | public class MessageMasquerade 7 | { 8 | public MessageMasquerade(string name, string avatar = "", RevoltColor color = null) 9 | { 10 | Name = name; 11 | AvatarUrl = avatar; 12 | Color = color == null ? new RevoltColor("") : color; 13 | } 14 | private MessageMasquerade(MessageMasqueradeJson model) 15 | { 16 | Name = model.Name; 17 | AvatarUrl = model.AvatarUrl; 18 | if (model.Color.HasValue) 19 | Color = new RevoltColor(model.Color.Value); 20 | else 21 | Color = new RevoltColor(""); 22 | } 23 | 24 | internal static MessageMasquerade? Create(MessageMasqueradeJson model) 25 | { 26 | if (model != null) 27 | return new MessageMasquerade(model); 28 | return null; 29 | } 30 | 31 | public string? Name { get; } 32 | public string? AvatarUrl { get; } 33 | public RevoltColor Color { get; } 34 | 35 | internal MessageMasqueradeJson ToJson() 36 | { 37 | MessageMasqueradeJson Json = new MessageMasqueradeJson(); 38 | if (!string.IsNullOrEmpty(Name)) 39 | Json.Name = Name; 40 | 41 | if (!string.IsNullOrEmpty(AvatarUrl)) 42 | Json.AvatarUrl = AvatarUrl; 43 | 44 | if (Color != null && Color.HasValue) 45 | Json.Color = Optional.Some(Color.Hex); 46 | 47 | return Json; 48 | } 49 | 50 | /// Returns a string that represents the current object. 51 | /// Masquerade name 52 | public override string ToString() 53 | { 54 | return Name ?? "Masquerade name"; 55 | } 56 | } -------------------------------------------------------------------------------- /RevoltSharp/Core/Messages/MessageReply.cs: -------------------------------------------------------------------------------- 1 | namespace RevoltSharp; 2 | 3 | 4 | public class MessageReply 5 | { 6 | public MessageReply(string messageId, bool isMention) 7 | { 8 | MessageId = messageId; 9 | IsMention = isMention; 10 | } 11 | 12 | public string MessageId { get; internal set; } 13 | public bool IsMention { get; internal set; } 14 | 15 | internal MessageReplyJson ToJson() 16 | { 17 | return new MessageReplyJson 18 | { 19 | messageId = MessageId, 20 | isMention = IsMention 21 | }; 22 | } 23 | } -------------------------------------------------------------------------------- /RevoltSharp/Core/Messages/MessageReplyJson.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace RevoltSharp; 4 | 5 | 6 | internal class MessageReplyJson 7 | { 8 | [JsonProperty("id")] 9 | public string? messageId { get; set; } 10 | 11 | [JsonProperty("mention")] 12 | public bool isMention { get; set; } 13 | } -------------------------------------------------------------------------------- /RevoltSharp/Core/Messages/MessageSortType.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace RevoltSharp; 8 | 9 | public enum MessageSortType 10 | { 11 | Latest, Oldest, Relevance 12 | } 13 | -------------------------------------------------------------------------------- /RevoltSharp/Core/Messages/MessageWebhook.cs: -------------------------------------------------------------------------------- 1 | namespace RevoltSharp; 2 | 3 | public class MessageWebhook : CreatedEntity 4 | { 5 | internal MessageWebhook(RevoltClient client, MessageWebhookJson model) : base(client, model.Id) 6 | { 7 | Name = model.Name; 8 | Avatar = Attachment.Create(client, model.Avatar); 9 | } 10 | 11 | public new string Id => base.Id; 12 | 13 | public string Name; 14 | 15 | public Attachment? Avatar; 16 | } -------------------------------------------------------------------------------- /RevoltSharp/Core/Messages/MessageWebhookJson.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace RevoltSharp; 4 | 5 | 6 | internal class MessageWebhookJson 7 | { 8 | [JsonProperty("id")] 9 | public string Id { get; set; } = null!; 10 | 11 | [JsonProperty("name")] 12 | public string Name { get; set; } = null!; 13 | 14 | [JsonProperty("avatar")] 15 | public AttachmentJson? Avatar { get; set; } 16 | } -------------------------------------------------------------------------------- /RevoltSharp/Core/Messages/SystemMessage.cs: -------------------------------------------------------------------------------- 1 | namespace RevoltSharp; 2 | 3 | 4 | /// 5 | /// System messages sent by Revolt for information/changes. 6 | /// 7 | /// 8 | public class SystemMessage : Message where Type : SystemData 9 | { 10 | /// 11 | /// The content data of this system message. 12 | /// 13 | public Type Data { get; internal set; } 14 | 15 | /// 16 | /// The type of system message this is. 17 | /// 18 | public SystemType SystemType { get; internal set; } 19 | 20 | internal SystemMessage(RevoltClient client, MessageJson model, Type type, SystemType systemType) 21 | : base(client, model) 22 | { 23 | base.Type = MessageType.System; 24 | SystemType = systemType; 25 | Data = type; 26 | Data.BaseId = model.System.Id; 27 | Data.BaseBy = model.System.By; 28 | Data.BaseName = model.System.Name; 29 | Data.BaseFrom = model.System.From; 30 | Data.BaseTo = model.System.To; 31 | Data.BaseText = model.System.Content; 32 | } 33 | 34 | /// Returns a string that represents the current object. 35 | public override string ToString() 36 | { 37 | return SystemType.ToString(); 38 | } 39 | } -------------------------------------------------------------------------------- /RevoltSharp/Core/Messages/SystemType.cs: -------------------------------------------------------------------------------- 1 | namespace RevoltSharp; 2 | 3 | public enum SystemType 4 | { 5 | /// 6 | /// Unknown system message type. 7 | /// 8 | Unknown, 9 | 10 | /// 11 | /// System message with text. 12 | /// 13 | Text, 14 | 15 | /// 16 | /// User has been added to the group. 17 | /// 18 | GroupUserAdded, 19 | 20 | /// 21 | /// User has been removed from the group. 22 | /// 23 | GroupUserRemoved, 24 | 25 | /// 26 | /// User has joined the server. 27 | /// 28 | ServerUserJoined, 29 | 30 | /// 31 | /// User has left the server. 32 | /// 33 | ServerUserLeft, 34 | 35 | /// 36 | /// User has been kicked from the server. 37 | /// 38 | ServerUserKicked, 39 | 40 | /// 41 | /// User has been banned from the server. 42 | /// 43 | ServerUserBanned, 44 | 45 | /// 46 | /// Group channel name has been changed. 47 | /// 48 | GroupNameChanged, 49 | 50 | /// 51 | /// Group channel description has been changed. 52 | /// 53 | GroupDescriptionChanged, 54 | 55 | /// 56 | /// Group channel icon has been changed. 57 | /// 58 | GroupIconChanged, 59 | 60 | /// 61 | /// Group channel owner has been changed. 62 | /// 63 | GroupOwnerChanged 64 | } 65 | -------------------------------------------------------------------------------- /RevoltSharp/Core/RetryRequest.cs: -------------------------------------------------------------------------------- 1 | namespace RevoltSharp; 2 | 3 | 4 | internal class RetryRequest 5 | { 6 | public int retry_after; 7 | } -------------------------------------------------------------------------------- /RevoltSharp/Core/Servers/Category.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using System.Collections.Generic; 3 | 4 | namespace RevoltSharp; 5 | 6 | public class ServerCategory : CreatedEntity 7 | { 8 | internal ServerCategory(RevoltClient client, string serverId, CategoryJson model, int position) : base(client, model.id) 9 | { 10 | Name = model.title; 11 | ChannelIds = model.channels; 12 | ServerId = serverId; 13 | Position = position; 14 | } 15 | 16 | public string Name { get; internal set; } 17 | 18 | public string[] ChannelIds { get; internal set; } 19 | 20 | public string ServerId { get; internal set; } 21 | 22 | public int Position { get; internal set; } 23 | 24 | [JsonIgnore] 25 | public Server? Server => Client.GetServer(ServerId); 26 | 27 | [JsonIgnore] 28 | public IReadOnlyList Channels { get; internal set; } = new List(); 29 | 30 | internal void Update(RevoltClient client, CategoryJson model, int position) 31 | { 32 | Name = model.title; 33 | ChannelIds = model.channels; 34 | Position = position; 35 | UpdateChannels(client); 36 | } 37 | 38 | internal void UpdateChannels(RevoltClient client) 39 | { 40 | if (client.WebSocket != null) 41 | { 42 | List channels = new List(); 43 | foreach (var channel in ChannelIds) 44 | { 45 | if (client.TryGetChannel(channel, out var chan)) 46 | channels.Add(chan as ServerChannel); 47 | } 48 | Channels = channels; 49 | } 50 | } 51 | 52 | internal CategoryJson ToJson() 53 | { 54 | return new CategoryJson 55 | { 56 | id = Id, 57 | title = Name, 58 | channels = ChannelIds, 59 | }; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /RevoltSharp/Core/Servers/CategoryJson.cs: -------------------------------------------------------------------------------- 1 | namespace RevoltSharp; 2 | 3 | 4 | internal class CategoryJson 5 | { 6 | public string? id { get; set; } 7 | public string? title { get; set; } 8 | public string[]? channels { get; set; } 9 | } -------------------------------------------------------------------------------- /RevoltSharp/Core/Servers/Invite.cs: -------------------------------------------------------------------------------- 1 | namespace RevoltSharp; 2 | 3 | 4 | /// 5 | /// Server invite 6 | /// 7 | public class Invite : Entity 8 | { 9 | internal Invite(RevoltClient client, InviteJson model) : base(client) 10 | { 11 | Code = model.Code; 12 | ChannelId = model.ChannelId; 13 | ChannelName = model.ChannelName; 14 | ChannelDescription = model.ChannelDescription; 15 | CreatorName = model.CreatorName; 16 | CreatorAvatar = Attachment.Create(client, model.CreatorAvatar); 17 | if (model.ChannelType == "Server") 18 | IsServer = true; 19 | else if (model.ChannelType == "Group") 20 | IsGroup = true; 21 | } 22 | public string Code { get; internal set; } 23 | public string ChannelId { get; internal set; } 24 | 25 | public Channel? Channel => Client.GetChannel(ChannelId); 26 | 27 | public string ChannelName { get; internal set; } 28 | public string? ChannelDescription { get; internal set; } 29 | public string CreatorName { get; internal set; } 30 | public Attachment? CreatorAvatar { get; internal set; } 31 | public bool IsServer { get; internal set; } 32 | public bool IsGroup { get; internal set; } 33 | 34 | /// Returns a string that represents the current object. 35 | /// Channel name invite 36 | public override string ToString() 37 | { 38 | return ChannelName + " invite"; 39 | } 40 | } 41 | 42 | public class CreatedInvite : Entity 43 | { 44 | internal CreatedInvite(RevoltClient client, CreateInviteJson model) : base(client) 45 | { 46 | Code = model.Code; 47 | CreatorId = model.CreatorId; 48 | ChannelId = model.ChannelId; 49 | if (model.ChannelType == "Server") 50 | IsServer = true; 51 | else if (model.ChannelType == "Group") 52 | IsGroup = true; 53 | } 54 | 55 | public string Code { get; internal set; } 56 | public string CreatorId { get; internal set; } 57 | 58 | public User? Creator => Client.GetUser(CreatorId); 59 | public string ChannelId { get; internal set; } 60 | public Channel? Channel => Client.GetChannel(ChannelId); 61 | public bool IsServer { get; internal set; } 62 | public bool IsGroup { get; internal set; } 63 | } -------------------------------------------------------------------------------- /RevoltSharp/Core/Servers/InviteJson.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace RevoltSharp; 4 | 5 | 6 | internal class CreateInviteJson 7 | { 8 | [JsonProperty("_id")] 9 | public string Code { get; set; } = null!; 10 | 11 | [JsonProperty("creator")] 12 | public string CreatorId { get; set; } = null!; 13 | 14 | [JsonProperty("channel")] 15 | public string ChannelId { get; set; } = null!; 16 | 17 | [JsonProperty("type")] 18 | public string ChannelType { get; set; } = null!; 19 | } 20 | internal class InviteJson 21 | { 22 | [JsonProperty("code")] 23 | public string Code { get; set; } = null!; 24 | 25 | [JsonProperty("channel_id")] 26 | public string ChannelId { get; set; } = null!; 27 | 28 | [JsonProperty("channel_name")] 29 | public string ChannelName { get; set; } = null!; 30 | 31 | [JsonProperty("channel_description")] 32 | public string? ChannelDescription { get; set; } 33 | 34 | [JsonProperty("user_name")] 35 | public string CreatorName { get; set; } = null!; 36 | 37 | [JsonProperty("user_avatar")] 38 | public AttachmentJson? CreatorAvatar { get; set; } 39 | 40 | [JsonProperty("type")] 41 | public string? ChannelType { get; set; } 42 | } -------------------------------------------------------------------------------- /RevoltSharp/Core/Servers/MembersListJson.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace RevoltSharp; 4 | 5 | 6 | internal class MembersListJson 7 | { 8 | [JsonProperty("members")] 9 | public ServerMemberJson[]? Members { get; set; } 10 | 11 | [JsonProperty("users")] 12 | public UserJson[]? Users { get; set; } 13 | } 14 | -------------------------------------------------------------------------------- /RevoltSharp/Core/Servers/PartialRoleJson.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using Optionals; 3 | using System.Numerics; 4 | 5 | namespace RevoltSharp; 6 | 7 | 8 | internal class PartialRoleJson 9 | { 10 | [JsonProperty("name")] 11 | public Optional Name { get; set; } 12 | 13 | [JsonProperty("permissions")] 14 | public Optional Permissions { get; set; } 15 | 16 | [JsonProperty("hoist")] 17 | public Optional Hoist { get; set; } 18 | 19 | [JsonProperty("rank")] 20 | public Optional Rank { get; set; } 21 | 22 | [JsonProperty("colour")] 23 | public Optional Colour { get; set; } 24 | } -------------------------------------------------------------------------------- /RevoltSharp/Core/Servers/PartialServerJson.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using Optionals; 3 | 4 | namespace RevoltSharp; 5 | 6 | 7 | internal class PartialServerJson 8 | { 9 | [JsonProperty("name")] 10 | public Optional Name { get; set; } 11 | 12 | [JsonProperty("icon")] 13 | public Optional Icon { get; set; } 14 | 15 | [JsonProperty("banner")] 16 | public Optional Banner { get; set; } 17 | 18 | [JsonProperty("description")] 19 | public Optional Description { get; set; } 20 | 21 | [JsonProperty("default_permissions")] 22 | public Optional DefaultPermissions { get; set; } 23 | 24 | [JsonProperty("analytics")] 25 | public Optional Analytics { get; set; } 26 | 27 | [JsonProperty("discoverable")] 28 | public Optional Discoverable { get; set; } 29 | 30 | [JsonProperty("nsfw")] 31 | public Optional Nsfw { get; set; } 32 | 33 | [JsonProperty("owner")] 34 | public Optional Owner { get; set; } 35 | 36 | [JsonProperty("system_messages")] 37 | public Optional SystemMessages { get; set; } 38 | 39 | [JsonProperty("categories")] 40 | public Optional Categories { get; set; } 41 | } -------------------------------------------------------------------------------- /RevoltSharp/Core/Servers/PartialServerMemberJson.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using Optionals; 3 | using System; 4 | 5 | namespace RevoltSharp; 6 | 7 | 8 | internal class PartialServerMemberJson 9 | { 10 | [JsonProperty("nickname")] 11 | public Optional Nickname { get; set; } 12 | 13 | [JsonProperty("avatar")] 14 | public Optional Avatar { get; set; } 15 | 16 | [JsonProperty("roles")] 17 | public Optional Roles { get; set; } 18 | 19 | [JsonProperty("timeout")] 20 | public Optional Timeout { get; set; } 21 | 22 | public bool ClearTimeout { get; set; } 23 | } -------------------------------------------------------------------------------- /RevoltSharp/Core/Servers/RoleJson.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using System.Numerics; 3 | 4 | namespace RevoltSharp; 5 | 6 | 7 | internal class RoleJson 8 | { 9 | [JsonProperty("id")] 10 | public string? Id { get; set; } 11 | 12 | [JsonProperty("name")] 13 | public string Name { get; set; } = null!; 14 | 15 | [JsonProperty("permissions")] 16 | public PermissionsJson Permissions { get; set; } = null!; 17 | 18 | [JsonProperty("hoist")] 19 | public bool Hoist { get; set; } 20 | 21 | [JsonProperty("rank")] 22 | public BigInteger Rank { get; set; } 23 | 24 | [JsonProperty("colour")] 25 | public string? Colour { get; set; } 26 | } 27 | internal class PermissionsJson 28 | { 29 | [JsonProperty("a")] 30 | public ulong Allowed { get; set; } 31 | 32 | [JsonProperty("d")] 33 | public ulong Denied { get; set; } 34 | } -------------------------------------------------------------------------------- /RevoltSharp/Core/Servers/ServerBan.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace RevoltSharp; 4 | 5 | 6 | public class ServerBanInfo : CreatedEntity 7 | { 8 | internal ServerBanInfo(RevoltClient client, ServerBanInfoJson jsonInfo) : base(client, jsonInfo.Id.UserId) 9 | { 10 | UserId = jsonInfo.Id.UserId; 11 | Reason = jsonInfo.Reason; 12 | } 13 | 14 | public string UserId { get; internal set; } 15 | public string? Reason { get; internal set; } 16 | } 17 | public class ServerBan : CreatedEntity 18 | { 19 | internal ServerBan(RevoltClient client, ServerBanUserJson json, ServerBanInfoJson jsonInfo) : base(client, json.Id) 20 | { 21 | Username = json.Username; 22 | Discriminator = json.Discriminator; 23 | Reason = jsonInfo.Reason; 24 | Avatar = Attachment.Create(client, json.Avatar); 25 | } 26 | 27 | /// 28 | /// Id of the ban. 29 | /// 30 | public new string Id => base.Id; 31 | 32 | /// 33 | /// Date of when the ban occured. 34 | /// 35 | public new DateTimeOffset CreatedAt => base.CreatedAt; 36 | 37 | /// 38 | /// Username of the banned user. 39 | /// 40 | public string Username { get; } 41 | 42 | /// 43 | /// Unique identity number of the banned user. 44 | /// 45 | private string Discriminator { get; set; } 46 | 47 | /// 48 | /// Reason for ban creation. 49 | /// 50 | public string? Reason { get; internal set; } 51 | 52 | public Attachment? Avatar { get; } 53 | 54 | /// 55 | /// Get the username and discriminator of the user. 56 | /// 57 | public string Tag 58 | => $"{Username}#{Discriminator}"; 59 | 60 | /// 61 | /// Gets the user's avatar. 62 | /// 63 | /// Which avatar to return. 64 | /// 65 | /// URL of the image 66 | public string? GetAvatarUrl(AvatarSources which = AvatarSources.Any) 67 | { 68 | if (Avatar != null && (which | AvatarSources.User) != 0) 69 | return Avatar.GetUrl(); 70 | 71 | if ((which | AvatarSources.Default) != 0) 72 | { 73 | return $"{Client.Config.ApiUrl}users/{Id}/default_avatar"; 74 | } 75 | 76 | return null; 77 | } 78 | 79 | /// Returns a string that represents the current object. 80 | /// Name#0001 ban 81 | public override string ToString() 82 | { 83 | return Username + "#" + Discriminator + " ban"; 84 | } 85 | } -------------------------------------------------------------------------------- /RevoltSharp/Core/Servers/ServerBansJson.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace RevoltSharp; 4 | 5 | 6 | internal class ServerBansJson 7 | { 8 | [JsonProperty("users")] 9 | public ServerBanUserJson[] Users { get; set; } = null!; 10 | 11 | [JsonProperty("bans")] 12 | public ServerBanInfoJson[] Bans { get; set; } = null!; 13 | } 14 | internal class ServerBanUserJson 15 | { 16 | [JsonProperty("_id")] 17 | public string Id { get; set; } = null!; 18 | 19 | [JsonProperty("username")] 20 | public string Username { get; set; } = null!; 21 | 22 | [JsonProperty("avatar")] 23 | public AttachmentJson? Avatar { get; set; } 24 | 25 | [JsonProperty("discriminator")] 26 | public string Discriminator { get; set; } = null!; 27 | } 28 | 29 | internal class ServerBanInfoJson 30 | { 31 | [JsonProperty("reason")] 32 | public string? Reason { get; set; } 33 | 34 | [JsonProperty("_id")] 35 | public ServerBanIdJson Id { get; set; } = null!; 36 | } 37 | internal class ServerBanIdJson 38 | { 39 | [JsonProperty("user")] 40 | public string UserId { get; set; } = null!; 41 | } -------------------------------------------------------------------------------- /RevoltSharp/Core/Servers/ServerJson.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using Optionals; 3 | using System.Collections.Generic; 4 | 5 | namespace RevoltSharp; 6 | 7 | 8 | internal class ServerJson 9 | { 10 | [JsonProperty("_id")] 11 | public string Id { get; set; } = null!; 12 | 13 | [JsonProperty("owner")] 14 | public string Owner { get; set; } = null!; 15 | 16 | [JsonProperty("name")] 17 | public string Name { get; set; } = null!; 18 | 19 | [JsonProperty("description")] 20 | public string? Description { get; set; } 21 | 22 | [JsonProperty("channels")] 23 | public string[] Channels { get; set; } = null!; 24 | 25 | [JsonProperty("categories")] 26 | public CategoryJson[]? Categories { get; set; } 27 | 28 | [JsonProperty("system_messages")] 29 | public ServerSystemMessagesJson? SystemMessages { get; set; } 30 | 31 | [JsonProperty("roles")] 32 | public Dictionary? Roles { get; set; } 33 | 34 | [JsonProperty("default_permissions")] 35 | public ulong DefaultPermissions { get; set; } 36 | 37 | [JsonProperty("icon")] 38 | public AttachmentJson? Icon { get; set; } 39 | 40 | [JsonProperty("banner")] 41 | public AttachmentJson? Banner { get; set; } 42 | 43 | [JsonProperty("analytics")] 44 | public bool Analytics { get; set; } 45 | 46 | [JsonProperty("discoverable")] 47 | public bool Discoverable { get; set; } 48 | 49 | [JsonProperty("nsfw")] 50 | public bool Nsfw { get; set; } 51 | } 52 | 53 | internal class ServerSystemMessagesJson 54 | { 55 | [JsonProperty("user_joined")] 56 | public Optional UserJoined { get; set; } 57 | 58 | [JsonProperty("user_left")] 59 | public Optional UserLeft { get; set; } 60 | 61 | [JsonProperty("user_kicked")] 62 | public Optional UserKicked { get; set; } 63 | 64 | [JsonProperty("user_banned")] 65 | public Optional UserBanned { get; set; } 66 | } -------------------------------------------------------------------------------- /RevoltSharp/Core/Servers/ServerMemberJson.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using Optionals; 3 | using System; 4 | 5 | namespace RevoltSharp; 6 | 7 | 8 | internal class ServerMemberJson 9 | { 10 | [JsonProperty("_id")] 11 | public ServerMemberIdsJson Id { get; set; } = null!; 12 | 13 | [JsonProperty("nickname")] 14 | public string Nickname { get; set; } = null!; 15 | 16 | [JsonProperty("avatar")] 17 | public AttachmentJson? Avatar { get; set; } 18 | 19 | [JsonProperty("roles")] 20 | public string[]? Roles { get; set; } 21 | 22 | [JsonProperty("joined_at")] 23 | public DateTime JoinedAt { get; set; } 24 | 25 | [JsonProperty("timeout")] 26 | public Optional Timeout { get; set; } 27 | } 28 | internal class ServerMemberIdsJson 29 | { 30 | [JsonProperty("server")] 31 | public string Server { get; set; } = null!; 32 | 33 | [JsonProperty("user")] 34 | public string User { get; set; } = null!; 35 | } -------------------------------------------------------------------------------- /RevoltSharp/Core/Servers/ServerSystemMessages.cs: -------------------------------------------------------------------------------- 1 | using Optionals; 2 | 3 | namespace RevoltSharp; 4 | 5 | 6 | public class ServerSystemMessages : Entity 7 | { 8 | internal ServerSystemMessages(RevoltClient client, ServerSystemMessagesJson json) : base(client) 9 | { 10 | if (json == null) 11 | return; 12 | 13 | UserJoinedChannelId = json.UserJoined; 14 | UserLeftChannelId = json.UserLeft; 15 | UserKickedChannelId = json.UserKicked; 16 | UserBannedChannelId = json.UserBanned; 17 | 18 | } 19 | 20 | public Optional UserJoinedChannelId { get; set; } 21 | 22 | public TextChannel? UserJoinedChannel => Client.GetTextChannel(UserJoinedChannelId); 23 | public Optional UserLeftChannelId { get; set; } 24 | public TextChannel? UserLeftChannel => Client.GetTextChannel(UserLeftChannelId); 25 | public Optional UserKickedChannelId { get; set; } 26 | public TextChannel? UserKickedChannel => Client.GetTextChannel(UserKickedChannelId); 27 | public Optional UserBannedChannelId { get; set; } 28 | public TextChannel? UserBannedChannel => Client.GetTextChannel(UserBannedChannelId); 29 | } -------------------------------------------------------------------------------- /RevoltSharp/Core/SocketError.cs: -------------------------------------------------------------------------------- 1 | namespace RevoltSharp; 2 | 3 | 4 | public class SocketError 5 | { 6 | public string? Message { get; internal set; } 7 | public RevoltErrorType Type { get; internal set; } 8 | } -------------------------------------------------------------------------------- /RevoltSharp/Core/Updated/ChannelUpdatedProperties.cs: -------------------------------------------------------------------------------- 1 | using Optionals; 2 | using System.Collections.Generic; 3 | 4 | namespace RevoltSharp; 5 | 6 | 7 | public class ChannelUpdatedProperties 8 | { 9 | internal ChannelUpdatedProperties(Channel channel, PartialChannelJson json) 10 | { 11 | Name = json.Name; 12 | Active = json.Active; 13 | if (json.Icon.HasValue) 14 | Icon = Optional.Some(Attachment.Create(channel.Client, json.Icon.Value)); 15 | 16 | Description = json.Description; 17 | 18 | if (channel is ServerChannel SC) 19 | { 20 | if (json.DefaultPermissions.HasValue) 21 | DefaultPermissions = Optional.Some(SC.DefaultPermissions); 22 | 23 | if (json.RolePermissions.HasValue) 24 | RolePermissions = Optional.Some(SC.InternalRolePermissions); 25 | } 26 | 27 | Nsfw = json.IsNsfw; 28 | OwnerId = json.OwnerId; 29 | } 30 | 31 | public Optional Name { get; private set; } 32 | public Optional Active { get; private set; } 33 | public Optional Icon { get; private set; } 34 | public Optional Description { get; private set; } 35 | public Optional DefaultPermissions { get; private set; } 36 | public Optional> RolePermissions { get; private set; } 37 | public Optional Nsfw { get; private set; } 38 | public Optional OwnerId { get; private set; } 39 | } -------------------------------------------------------------------------------- /RevoltSharp/Core/Updated/MessageUpdatedProperties.cs: -------------------------------------------------------------------------------- 1 | using Optionals; 2 | using RevoltSharp.WebSocket; 3 | using System; 4 | using System.Linq; 5 | 6 | namespace RevoltSharp; 7 | 8 | 9 | public class MessageUpdatedProperties : CreatedEntity 10 | { 11 | internal MessageUpdatedProperties(RevoltClient client, MessageUpdateEventJson json) : base(client, json.MessageId) 12 | { 13 | Content = json.Data.Content; 14 | EditedAt = json.Data.EditedAt; 15 | ChannelId = json.ChannelId; 16 | Embeds = json.Data.Embeds.HasValue ? Optional.Some(json.Data.Embeds.Value.Select(x => MessageEmbed.Create(client, x)!).ToArray()) : Optional.None(); 17 | if (Channel is ServerChannel SC) 18 | ServerId = SC.ServerId; 19 | } 20 | 21 | /// 22 | /// Id of the message. 23 | /// 24 | public new string Id => base.Id; 25 | 26 | /// 27 | /// Date of when the message was created. 28 | /// 29 | public new DateTimeOffset CreatedAt => base.CreatedAt; 30 | 31 | public Optional Content { get; private set; } 32 | 33 | public Optional Embeds { get; private set; } 34 | 35 | public DateTime EditedAt { get; private set; } 36 | 37 | public string ChannelId { get; private set; } 38 | 39 | public Channel? Channel => Client.GetChannel(ChannelId); 40 | 41 | public string? ServerId { get; private set; } 42 | 43 | public Server? Server => Client.GetServer(ServerId); 44 | 45 | } -------------------------------------------------------------------------------- /RevoltSharp/Core/Updated/RoleUpdatedProperties.cs: -------------------------------------------------------------------------------- 1 | using Optionals; 2 | using System; 3 | using System.Numerics; 4 | 5 | namespace RevoltSharp; 6 | 7 | 8 | public class RoleUpdatedProperties : CreatedEntity 9 | { 10 | internal RoleUpdatedProperties(RevoltClient client, Role role, PartialRoleJson json) : base(client, role.Id) 11 | { 12 | Name = json.Name; 13 | if (json.Permissions.HasValue) 14 | Permissions = Optional.Some(new ServerPermissions(role.Server, json.Permissions.Value.Allowed)); 15 | 16 | Hoist = json.Hoist; 17 | Rank = json.Rank; 18 | if (json.Colour.HasValue) 19 | Color = Optional.Some(new RevoltColor(json.Colour.Value)); 20 | } 21 | 22 | /// 23 | /// Id of the role. 24 | /// 25 | public new string Id => base.Id; 26 | 27 | /// 28 | /// Date of when the role was created. 29 | /// 30 | public new DateTimeOffset CreatedAt => base.CreatedAt; 31 | 32 | public Optional Name { get; private set; } 33 | 34 | public Optional Permissions { get; private set; } 35 | 36 | public Optional Hoist { get; private set; } 37 | 38 | public Optional Rank { get; private set; } 39 | 40 | public Optional Color { get; private set; } 41 | } -------------------------------------------------------------------------------- /RevoltSharp/Core/Updated/SelfUserUpdatedProperties.cs: -------------------------------------------------------------------------------- 1 | using Optionals; 2 | 3 | namespace RevoltSharp; 4 | 5 | public class SelfUserUpdatedProperties : UserUpdatedProperties 6 | { 7 | internal SelfUserUpdatedProperties(RevoltClient client, PartialUserJson json) : base(client, json) 8 | { 9 | if (json.Profile.HasValue) 10 | ProfileContent = json.Profile.Value.Content; 11 | 12 | if (json.Profile.HasValue && 13 | json.Profile.Value.Background.HasValue) 14 | ProfileBackground = Optional.Some(Attachment.Create(client, json.Profile.Value.Background.Value)); 15 | } 16 | 17 | public Optional ProfileContent; 18 | 19 | public Optional ProfileBackground; 20 | } 21 | -------------------------------------------------------------------------------- /RevoltSharp/Core/Updated/ServerUpdatedProperties.cs: -------------------------------------------------------------------------------- 1 | using Optionals; 2 | 3 | namespace RevoltSharp; 4 | 5 | 6 | public class ServerUpdatedProperties 7 | { 8 | internal ServerUpdatedProperties(Server server, PartialServerJson json) 9 | { 10 | Name = json.Name; 11 | if (json.Icon.HasValue) 12 | Icon = Optional.Some(server.Icon); 13 | if (json.Banner.HasValue) 14 | Banner = Optional.Some(server.Banner); 15 | Description = json.Description; 16 | DefaultPermissions = json.DefaultPermissions; 17 | Analytics = json.Analytics; 18 | Discoverable = json.Discoverable; 19 | Nsfw = json.Nsfw; 20 | Owner = json.Owner; 21 | SystemMessages = Optional.Some(server.SystemMessages); 22 | } 23 | 24 | public Optional Name { get; set; } 25 | public Optional Icon { get; set; } 26 | public Optional Banner { get; set; } 27 | public Optional Description { get; set; } 28 | public Optional DefaultPermissions { get; set; } 29 | public Optional Analytics { get; private set; } 30 | public Optional Discoverable { get; private set; } 31 | public Optional Nsfw { get; private set; } 32 | public Optional Owner { get; private set; } 33 | public Optional SystemMessages { get; private set; } 34 | } -------------------------------------------------------------------------------- /RevoltSharp/Core/Updated/UserUpdatedProperties.cs: -------------------------------------------------------------------------------- 1 | using Optionals; 2 | 3 | namespace RevoltSharp; 4 | 5 | /// 6 | /// Properties that have been updated for the user. 7 | /// 8 | public class UserUpdatedProperties 9 | { 10 | internal UserUpdatedProperties(RevoltClient client, PartialUserJson json) 11 | { 12 | if (json.Status.HasValue && json.Status.Value.Text != null) 13 | StatusText = Optional.Some(json.Status.Value.Text!); 14 | 15 | Avatar = json.Avatar.ToModel(client); 16 | Online = json.Online; 17 | Privileged = json.Privileged; 18 | Username = json.Username; 19 | Discriminator = json.Discriminator; 20 | DisplayName = json.DisplayName; 21 | Badges = json.Badges; 22 | Flags = json.Flags; 23 | } 24 | 25 | /// 26 | /// Status text that has been updated. 27 | /// 28 | public Optional StatusText { get; internal set; } 29 | 30 | /// 31 | /// Avatar that has been updated or if removed. 32 | /// 33 | public Optional Avatar { get; internal set; } 34 | 35 | /// 36 | /// User online status has been updated. 37 | /// 38 | public Optional Online { get; internal set; } 39 | 40 | /// 41 | /// User instance privileged has been updated. 42 | /// 43 | public Optional Privileged { get; internal set; } 44 | 45 | /// 46 | /// Username that has been updated. 47 | /// 48 | public Optional Username { get; internal set; } 49 | 50 | /// 51 | /// Discriminator that has been updated. 52 | /// 53 | public Optional Discriminator { get; internal set; } 54 | 55 | /// 56 | /// Display name that has been updated. 57 | /// 58 | public Optional DisplayName { get; internal set; } 59 | 60 | /// 61 | /// Badges that have been updated. 62 | /// 63 | public Optional Badges { get; internal set; } 64 | 65 | /// 66 | /// User flags that have been updated. 67 | /// 68 | public Optional Flags { get; internal set; } 69 | } -------------------------------------------------------------------------------- /RevoltSharp/Core/Users/AvatarSources.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace RevoltSharp; 4 | 5 | 6 | [Flags] 7 | public enum AvatarSources 8 | { 9 | /// 10 | /// Default Revolt avatar given to the user. 11 | /// 12 | Default = 1, 13 | 14 | /// 15 | /// The user's own avatar set. 16 | /// 17 | User = 2, 18 | 19 | /// 20 | /// The user's own server avatar set. 21 | /// 22 | Server = 4, 23 | 24 | /// 25 | /// The user's own avatar or fallback to default avatar. 26 | /// 27 | UserOrDefault = Default | User, 28 | 29 | /// 30 | /// The user's own server avatar or fallback to user avatar. 31 | /// 32 | ServerOrUser = User | Server, 33 | 34 | /// 35 | /// Use any of the server avatar, user avatar or default avatar. 36 | /// 37 | Any = Server | User | Default, 38 | } -------------------------------------------------------------------------------- /RevoltSharp/Core/Users/PartialUserJson.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using Optionals; 3 | 4 | namespace RevoltSharp; 5 | 6 | 7 | internal class PartialUserJson 8 | { 9 | 10 | [JsonProperty("username")] 11 | public Optional Username { get; set; } 12 | 13 | [JsonProperty("discriminator")] 14 | public Optional Discriminator { get; set; } 15 | 16 | [JsonProperty("display_name")] 17 | public Optional DisplayName { get; set; } 18 | 19 | [JsonProperty("profile")] 20 | public Optional Profile { get; set; } 21 | 22 | [JsonProperty("status")] 23 | public Optional Status { get; set; } 24 | 25 | [JsonProperty("avatar")] 26 | public Optional Avatar { get; set; } 27 | 28 | [JsonProperty("online")] 29 | public Optional Online { get; set; } 30 | 31 | [JsonProperty("privileged")] 32 | public Optional Privileged { get; set; } 33 | 34 | [JsonProperty("badges")] 35 | public Optional Badges { get; set; } 36 | 37 | [JsonProperty("flags")] 38 | public Optional Flags { get; set; } 39 | } -------------------------------------------------------------------------------- /RevoltSharp/Core/Users/Profile.cs: -------------------------------------------------------------------------------- 1 | namespace RevoltSharp; 2 | 3 | 4 | public class Profile : Entity 5 | { 6 | internal Profile(RevoltClient client, ProfileJson model) : base(client) 7 | { 8 | Bio = model.Content.Value; 9 | Background = Attachment.Create(client, model.Background.Value); 10 | } 11 | 12 | public string? Bio { get; internal set; } 13 | public Attachment? Background { get; internal set; } 14 | } -------------------------------------------------------------------------------- /RevoltSharp/Core/Users/ProfileJson.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using Optionals; 3 | 4 | namespace RevoltSharp; 5 | 6 | 7 | internal class ProfileJson 8 | { 9 | [JsonProperty("content")] 10 | public Optional Content { get; set; } 11 | 12 | [JsonProperty("background")] 13 | public Optional Background { get; set; } 14 | } -------------------------------------------------------------------------------- /RevoltSharp/Core/Users/SelfUser.cs: -------------------------------------------------------------------------------- 1 | namespace RevoltSharp; 2 | 3 | 4 | public class SelfUser : User 5 | { 6 | public string OwnerId => BotData.OwnerId; 7 | 8 | /// 9 | /// Get the Owner user of the bot. 10 | /// 11 | /// 12 | /// Will be if using . 13 | /// 14 | public User? Owner 15 | => Client.GetUser(OwnerId); 16 | 17 | public string? ProfileBio { get; internal set; } 18 | 19 | public Attachment? Background { get; internal set; } 20 | 21 | internal SelfUser(RevoltClient client, UserJson model) 22 | : base(client, model) 23 | { 24 | if (model.Profile == null) 25 | return; 26 | 27 | ProfileBio = model.Profile.Content; 28 | Background = Attachment.Create(client, model.Profile.Background); 29 | } 30 | 31 | 32 | internal new SelfUser Clone() 33 | { 34 | return (SelfUser)this.MemberwiseClone(); 35 | } 36 | } -------------------------------------------------------------------------------- /RevoltSharp/Core/Users/UserBadges.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace RevoltSharp; 4 | 5 | 6 | /// 7 | /// Cool badges the user has. 8 | /// 9 | public class UserBadges 10 | { 11 | internal UserBadges(ulong value) 12 | { 13 | Raw = value; 14 | Types = (UserBadgeType)Raw; 15 | } 16 | 17 | /// 18 | /// Not recommended to use, use instead. 19 | /// 20 | public ulong Raw { get; internal set; } 21 | 22 | /// 23 | /// Check if a user has a badge. 24 | /// 25 | /// The type of badge to check 26 | /// if user has this badge otherwise 27 | public bool Has(UserBadgeType type) => Types.HasFlag(type); 28 | 29 | internal UserBadgeType Types; 30 | } 31 | 32 | /// 33 | /// Cool badges for users :) 34 | /// 35 | [Flags] 36 | public enum UserBadgeType 37 | { 38 | /// 39 | /// User is a Revolt developer that works on Revolt magic 40 | /// 41 | Developer = 1, 42 | 43 | /// 44 | /// User has helped translate Revolt or other Revolt related stuff. 45 | /// 46 | Translator = 2, 47 | 48 | /// 49 | /// User has supported the project by donating. 50 | /// 51 | Supporter = 4, 52 | 53 | /// 54 | /// User has disclosed a major bug or security issue. 55 | /// 56 | ResponsibleDisclosure = 8, 57 | 58 | /// 59 | /// Hi insert :) 60 | /// 61 | Founder = 16, 62 | 63 | /// 64 | /// User has the power to moderate the Revolt instance. 65 | /// 66 | PlatformModeration = 32, 67 | 68 | /// 69 | /// Active support for the Revolt project. 70 | /// 71 | ActiveSupporter = 64, 72 | 73 | /// 74 | /// OwO 75 | /// 76 | Paw = 128, 77 | 78 | /// 79 | /// User was an early member/tester of the Revolt project. 80 | /// 81 | EarlyAdopter = 256, 82 | 83 | /// 84 | /// Haha funny 85 | /// 86 | ReservedRelevantJokeBadge1 = 512, 87 | 88 | /// 89 | /// Haha memes 90 | /// 91 | ReservedRelevantJokeBadge2 = 1024 92 | } -------------------------------------------------------------------------------- /RevoltSharp/Core/Users/UserFlags.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace RevoltSharp; 4 | 5 | 6 | /// 7 | /// System flags set for the user. 8 | /// 9 | public class UserFlags 10 | { 11 | internal UserFlags(ulong value) 12 | { 13 | Raw = value; 14 | Types = (UserFlagType)Raw; 15 | } 16 | 17 | /// 18 | /// Not recommended to use, use instead. 19 | /// 20 | public ulong Raw { get; internal set; } 21 | 22 | /// 23 | /// Check if the user has a flag. 24 | /// 25 | /// The type of system flag to check 26 | /// if user has the flag otherwise 27 | public bool Has(UserFlagType type) => Types.HasFlag(type); 28 | 29 | internal UserFlagType Types; 30 | } 31 | 32 | /// 33 | /// System flags for the Revolt instance. 34 | /// 35 | [Flags] 36 | public enum UserFlagType 37 | { 38 | /// 39 | /// User has been suspended from using the Revolt instance. 40 | /// 41 | Suspended = 1, 42 | 43 | /// 44 | /// User has deleted their account on the Revolt instance. 45 | /// 46 | Deleted = 2, 47 | 48 | /// 49 | /// User has been banned from the Revolt instance. 50 | /// 51 | Banned = 4, 52 | 53 | /// 54 | /// User has been banned for spam from the Revolt instance. 55 | /// 56 | Spam = 8 57 | } -------------------------------------------------------------------------------- /RevoltSharp/Core/Users/UserJson.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace RevoltSharp; 4 | 5 | 6 | internal class UserJson 7 | { 8 | [JsonProperty("_id")] 9 | public string Id { get; set; } = null!; 10 | 11 | [JsonProperty("username")] 12 | public string Username { get; set; } = null!; 13 | 14 | [JsonProperty("display_name")] 15 | public string? DisplayName { get; set; } 16 | 17 | [JsonProperty("discriminator")] 18 | public string Discriminator { get; set; } = null!; 19 | 20 | [JsonProperty("avatar")] 21 | public AttachmentJson? Avatar { get; set; } 22 | 23 | [JsonProperty("badges")] 24 | public ulong Badges { get; set; } 25 | 26 | [JsonProperty("status")] 27 | public UserStatusJson? Status { get; set; } 28 | 29 | [JsonProperty("profile")] 30 | public UserProfileJson? Profile { get; set; } 31 | 32 | [JsonProperty("bot")] 33 | public UserBotJson? Bot { get; set; } 34 | 35 | [JsonProperty("relationship")] 36 | public string? Relationship { get; set; } 37 | 38 | [JsonProperty("online")] 39 | public bool Online { get; set; } 40 | 41 | [JsonProperty("privileged")] 42 | public bool Privileged { get; set; } 43 | 44 | [JsonProperty("flags")] 45 | public ulong Flags { get; set; } 46 | } 47 | internal class UserStatusJson 48 | { 49 | [JsonProperty("text")] 50 | public string? Text { get; set; } 51 | 52 | [JsonProperty("presence")] 53 | public string? Presence { get; set; } 54 | } 55 | internal class UserBotJson 56 | { 57 | [JsonProperty("owner")] 58 | public string Owner { get; set; } = null!; 59 | } 60 | internal class UserProfileJson 61 | { 62 | [JsonProperty("content")] 63 | public string? Content { get; set; } 64 | 65 | [JsonProperty("background")] 66 | public AttachmentJson? Background { get; set; } 67 | } -------------------------------------------------------------------------------- /RevoltSharp/Core/Users/UserMutuals.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace RevoltSharp; 5 | 6 | public class UserMutuals 7 | { 8 | internal UserMutuals(UserMutualsJson? json) 9 | { 10 | if (json == null || json.users == null) 11 | Users = Array.Empty(); 12 | else 13 | Users = json.users; 14 | 15 | if (json == null || json.servers == null) 16 | Servers = Array.Empty(); 17 | else 18 | Servers = json.servers; 19 | } 20 | 21 | public IReadOnlyCollection Users { get; internal set; } 22 | public IReadOnlyCollection Servers { get; internal set; } 23 | } 24 | -------------------------------------------------------------------------------- /RevoltSharp/Core/Users/UserMutualsJson.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace RevoltSharp; 4 | 5 | internal class UserMutualsJson 6 | { 7 | public HashSet users { get; set; } 8 | public HashSet servers { get; set; } 9 | } 10 | -------------------------------------------------------------------------------- /RevoltSharp/Core/Users/UserStatus.cs: -------------------------------------------------------------------------------- 1 | using Optionals; 2 | using System; 3 | 4 | namespace RevoltSharp; 5 | 6 | 7 | /// 8 | /// User status mode and presence text. 9 | /// 10 | public class UserStatus 11 | { 12 | internal UserStatus(UserJson? json) 13 | { 14 | if (json == null) 15 | return; 16 | Update(Optional.Some(json.Online), json.Status == null ? Optional.None() : Optional.Some(json.Status)); 17 | } 18 | 19 | internal void Update(PartialUserJson json) 20 | { 21 | Update(json.Online, json.Status); 22 | } 23 | 24 | internal void Update(Optional online, Optional status) 25 | { 26 | if (!status.HasValue) 27 | { 28 | Type = UserStatusType.Offline; 29 | Text = null; 30 | return; 31 | } 32 | 33 | Text = status.Value.Text; 34 | if (Enum.TryParse(status.Value.Presence, ignoreCase: true, out UserStatusType ST)) 35 | Type = ST; 36 | else 37 | if (online.HasValue) 38 | Type = online.Value ? UserStatusType.Online : UserStatusType.Offline; 39 | } 40 | 41 | /// 42 | /// Custom text status for the user. 43 | /// 44 | public string? Text { get; internal set; } 45 | 46 | /// 47 | /// Status mode for the user. 48 | /// 49 | public UserStatusType Type { get; internal set; } 50 | } 51 | 52 | /// 53 | /// Status mode for the user. 54 | /// 55 | public enum UserStatusType 56 | { 57 | /// 58 | /// User is not online on Revolt. 59 | /// 60 | Offline, 61 | 62 | /// 63 | /// User is online and using Revolt. 64 | /// 65 | Online, 66 | 67 | /// 68 | /// User is away from their computer. 69 | /// 70 | Idle, 71 | 72 | /// 73 | /// User is focused on a task but is available. 74 | /// 75 | Focus, 76 | 77 | /// 78 | /// Do not FK WITH THIS USER. 79 | /// 80 | Busy, 81 | 82 | /// 83 | /// Who you gonna call? Ghost busters! 84 | /// 85 | Invisible 86 | } -------------------------------------------------------------------------------- /RevoltSharp/Core/Webhooks/Webhook.cs: -------------------------------------------------------------------------------- 1 | namespace RevoltSharp; 2 | 3 | /// 4 | /// Revolt channel webhook to use with 3rd party services and APIs. 5 | /// 6 | public class Webhook : CreatedEntity 7 | { 8 | internal Webhook(RevoltClient client, WebhookJson model) : base(client, model.Id) 9 | { 10 | Name = model.Name!; 11 | Avatar = Attachment.Create(Client, model.Avatar); 12 | ChannelId = model.ChannelId!; 13 | Permissions = new WebhookPermissions(model.Permissions ?? 0); 14 | Token = model.Token; 15 | } 16 | 17 | /// 18 | /// Name of the webhook. 19 | /// 20 | public string Name { get; internal set; } 21 | 22 | /// 23 | /// Avatar attachment of the webhook. 24 | /// 25 | public Attachment? Avatar { get; internal set; } 26 | 27 | /// 28 | /// Channel id of the webhook. 29 | /// 30 | public string ChannelId { get; internal set; } 31 | 32 | /// 33 | /// Channel of the webhook. 34 | /// 35 | /// 36 | /// Will be if using . 37 | /// 38 | public Channel? Channel => Client.GetChannel(ChannelId); 39 | 40 | /// 41 | /// Permissions the webhook can use. 42 | /// 43 | public WebhookPermissions Permissions { get; internal set; } 44 | 45 | /// 46 | /// The token used when sending messages as the webhook. 47 | /// 48 | public string? Token { get; internal set; } 49 | 50 | /// 51 | /// If the webhook object is authorized to use the token for requests. 52 | /// 53 | public bool HasToken => !string.IsNullOrEmpty(Token); 54 | 55 | /// Returns a string that represents the current object. 56 | /// Webhook name 57 | public override string ToString() 58 | { 59 | return Name; 60 | } 61 | } -------------------------------------------------------------------------------- /RevoltSharp/Core/Webhooks/WebhookJson.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace RevoltSharp; 4 | 5 | 6 | internal class WebhookJson 7 | { 8 | [JsonProperty("id")] 9 | public string? Id { get; set; } 10 | 11 | [JsonProperty("name")] 12 | public string? Name { get; set; } 13 | 14 | [JsonProperty("avatar")] 15 | public AttachmentJson? Avatar { get; set; } 16 | 17 | [JsonProperty("channel_id")] 18 | public string? ChannelId { get; set; } 19 | 20 | [JsonProperty("permissions")] 21 | public ulong? Permissions { get; set; } 22 | 23 | [JsonProperty("token")] 24 | public string? Token { get; set; } 25 | } -------------------------------------------------------------------------------- /RevoltSharp/Core/Webhooks/WebhookPermission.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace RevoltSharp; 4 | 5 | /// 6 | /// List of webhook permissions. 7 | /// 8 | [Flags] 9 | public enum WebhookPermission : ulong 10 | { 11 | /// 12 | /// Send messages permission. 13 | /// 14 | SendMessages = 1L << 22, 15 | /// 16 | /// Send embeds permission. 17 | /// 18 | SendEmbeds = 1L << 26, 19 | /// 20 | /// Masquerade messages permission. 21 | /// 22 | Masquerade = 1L << 28, 23 | /// 24 | /// Add reactions to messages permission. 25 | /// 26 | AddReactions = 1L << 29, 27 | } 28 | -------------------------------------------------------------------------------- /RevoltSharp/Core/Webhooks/WebhookPermissions.cs: -------------------------------------------------------------------------------- 1 | namespace RevoltSharp; 2 | 3 | /// 4 | /// Permissions for the webhook that can be used. 5 | /// 6 | public class WebhookPermissions 7 | { 8 | internal WebhookPermissions(ulong rawPermission) 9 | { 10 | Raw = rawPermission; 11 | } 12 | 13 | /// 14 | /// Raw permissions number for the webhook. 15 | /// 16 | public ulong Raw { get; internal set; } 17 | 18 | /// 19 | /// The webhook can send messages. 20 | /// 21 | public bool SendMessages => Has(WebhookPermission.SendMessages); 22 | 23 | /// 24 | /// The webhook can send embeds. 25 | /// 26 | public bool SendEmbeds => Has(WebhookPermission.SendEmbeds); 27 | 28 | /// 29 | /// The webhook can modify the message author and avatar sending the message. 30 | /// 31 | public bool Masquerade => Has(WebhookPermission.Masquerade); 32 | 33 | /// 34 | /// The webhook can add reactions to its own messages. 35 | /// 36 | public bool AddReactions => Has(WebhookPermission.AddReactions); 37 | 38 | /// 39 | /// Check if the webhook has a specific permission. 40 | /// 41 | /// 42 | public bool Has(WebhookPermission permission) 43 | { 44 | ulong Flag = (ulong)permission; 45 | return (Raw & Flag) == Flag; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /RevoltSharp/Extensions/Const.cs: -------------------------------------------------------------------------------- 1 | namespace RevoltSharp; 2 | 3 | public static class Const 4 | { 5 | public const int All_MaxIdLength = 128; 6 | public const int All_MaxNameLength = 32; 7 | public const int All_MaxUrlLength = 256; 8 | public const int Color_MaxLength = 128; 9 | 10 | // Most descriptions and reasons will use this. 11 | public const int All_MaxDescriptionLength = 1024; 12 | 13 | public const int User_MinNameLength = 2; 14 | public const int User_MaxStatusTextLength = 128; 15 | public const int User_ProfileBioLength = 2000; 16 | 17 | public const int Group_MaxUserIdsListCount = 49; 18 | 19 | public const int Message_MaxSearchListCount = 100; 20 | public const int Message_MaxDeleteListCount = 100; 21 | public const int Message_MaxEmbedsListCount = 10; 22 | public const int Message_MaxContentLength = 2000; 23 | public const int Message_EmbedTitleMaxLength = 100; 24 | 25 | public const int Message_ReactionsMaxCount = 20; 26 | } -------------------------------------------------------------------------------- /RevoltSharp/Extensions/Downloadable.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading.Tasks; 3 | 4 | namespace RevoltSharp; 5 | 6 | 7 | /// 8 | /// Cached object or downloadable from the Revolt instance API. 9 | /// 10 | public class Downloadable 11 | { 12 | private readonly Func> _downloader; 13 | 14 | public TId Id { get; } 15 | 16 | internal Downloadable(TId id, Func> downloader) 17 | { 18 | Id = id; 19 | _downloader = downloader; 20 | } 21 | 22 | /// 23 | /// Get the object from cache or download it from the Revolt instance API if not cached. 24 | /// 25 | public Task GetOrDownloadAsync() 26 | { 27 | return _downloader(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /RevoltSharp/Extensions/Format.cs: -------------------------------------------------------------------------------- 1 | namespace RevoltSharp; 2 | 3 | 4 | public static class Format 5 | { 6 | /// 7 | /// Format the text in bold. 8 | /// 9 | public static string Bold(string s) 10 | => $"**{s}**"; 11 | 12 | /// 13 | /// Format the text in italics. 14 | /// 15 | public static string Italic(string s) 16 | => $"*{s}*"; 17 | 18 | 19 | /// 20 | /// Format the text in bold and italics. 21 | /// 22 | public static string BoldItalic(string s) 23 | => $"***{s}***"; 24 | 25 | /// 26 | /// Format the text with a strikethrough. 27 | /// 28 | public static string Strikethrough(string s) 29 | => $"~{s}~"; 30 | 31 | /// 32 | /// Format the text in a quote block. 33 | /// 34 | public static string Quote(string s) 35 | => $"> {s}"; 36 | 37 | /// 38 | /// Format the text in a spoiler block 39 | /// 40 | public static string Spoiler(string s) 41 | => $"!!{s}!!"; 42 | 43 | /// 44 | /// Format the text as a link. 45 | /// 46 | public static string Link(string title, string url) 47 | => $"[{title}]({url})"; 48 | 49 | /// 50 | /// Format the text as a heading title. 51 | /// 52 | public static string Heading(string s, HeadingFormat headingFormat = HeadingFormat.H1) 53 | => $"{new string('#', (int)headingFormat)} {s}"; 54 | 55 | /// 56 | /// Format the text in a code line. 57 | /// 58 | public static string Code(string s) 59 | => $"`{s}`"; 60 | 61 | /// 62 | /// Format the text in code block. 63 | /// 64 | public static string CodeBlock(string code, string language = null) 65 | => language is null ? $"```\n{code}\n```" : $"```{language}\n{code}\n```"; 66 | } 67 | public enum HeadingFormat 68 | { 69 | H1 = 1, 70 | 71 | H2 = 2, 72 | 73 | H3 = 3, 74 | 75 | H4 = 4, 76 | 77 | H5 = 5, 78 | 79 | H6 = 6 80 | } -------------------------------------------------------------------------------- /RevoltSharp/Extensions/Option.cs: -------------------------------------------------------------------------------- 1 | namespace RevoltSharp; 2 | 3 | 4 | public class Option 5 | { 6 | public Option(TValue value) 7 | { 8 | Value = value; 9 | } 10 | public readonly TValue Value; 11 | } -------------------------------------------------------------------------------- /RevoltSharp/Extensions/Optional/Option.cs: -------------------------------------------------------------------------------- 1 | namespace Optionals; 2 | 3 | 4 | /// 5 | /// Provides a set of functions for creating optional values. 6 | /// 7 | public static class Optional 8 | { 9 | /// 10 | /// Wraps an existing value in an Option<T> instance. 11 | /// 12 | /// The value to be wrapped. 13 | /// An optional containing the specified value. 14 | public static Optional Some(T value) => new Optional(value, true); 15 | 16 | 17 | /// 18 | /// Creates an empty Option<T> instance. 19 | /// 20 | /// An empty optional. 21 | public static Optional None() => new Optional(default(T), false); 22 | 23 | } -------------------------------------------------------------------------------- /RevoltSharp/Extensions/Optional/Option_Maybe.cs: -------------------------------------------------------------------------------- 1 | namespace Optionals; 2 | 3 | 4 | /// 5 | /// Represents an optional value. 6 | /// 7 | public struct Optional 8 | { 9 | private readonly bool hasValue; 10 | private readonly T value; 11 | 12 | /// 13 | /// Checks if a value is present. 14 | /// 15 | public bool HasValue => hasValue; 16 | 17 | public T Value => value; 18 | 19 | internal Optional(T value, bool hasValue) 20 | { 21 | this.value = value; 22 | this.hasValue = hasValue; 23 | } 24 | 25 | /// 26 | /// Returns the existing value if present, and otherwise an alternative value. 27 | /// 28 | /// The alternative value. 29 | /// The existing or alternative value. 30 | public T ValueOr(T alternative) => hasValue ? value : alternative; 31 | 32 | } -------------------------------------------------------------------------------- /RevoltSharp/Extensions/Optional/OptionalSerializerConverter.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using Optionals; 3 | using System; 4 | 5 | namespace RevoltSharp; 6 | 7 | 8 | internal class OptionalSerializerConverter : JsonConverter 9 | { 10 | private readonly JsonConverter _innerConverter; 11 | 12 | public override bool CanConvert(Type objectType) => true; 13 | public override bool CanRead => true; 14 | public override bool CanWrite => true; 15 | 16 | public OptionalSerializerConverter(JsonConverter innerConverter) 17 | { 18 | _innerConverter = innerConverter; 19 | } 20 | 21 | public override object? ReadJson(JsonReader reader, Type objectType, object? existingValue, JsonSerializer serializer) 22 | { 23 | T obj; 24 | if (_innerConverter != null) 25 | { 26 | object o = _innerConverter.ReadJson(reader, typeof(T), null, serializer); 27 | if (o is Optional) 28 | return o; 29 | 30 | obj = (T)o; 31 | } 32 | else 33 | obj = serializer.Deserialize(reader); 34 | 35 | return Optional.Some(obj); 36 | } 37 | 38 | public override void WriteJson(JsonWriter writer, object? value, JsonSerializer serializer) 39 | { 40 | value = ((Optional)value!).Value; 41 | if (_innerConverter != null) 42 | _innerConverter.WriteJson(writer, value, serializer); 43 | else 44 | serializer.Serialize(writer, value, typeof(T)); 45 | } 46 | } -------------------------------------------------------------------------------- /RevoltSharp/Extensions/QueryBuilder.cs: -------------------------------------------------------------------------------- 1 | using System.Text; 2 | 3 | namespace RevoltSharp; 4 | 5 | public class QueryBuilder 6 | { 7 | private readonly StringBuilder sb = new StringBuilder(); 8 | 9 | public QueryBuilder Add(string key, string value) 10 | { 11 | if (sb.Length == 0) 12 | sb.Append($"?{key}={value}"); 13 | else 14 | sb.Append($"&{key}={value}"); 15 | 16 | return this; 17 | } 18 | 19 | public QueryBuilder AddIf(bool match, string key, string value) 20 | { 21 | if (match) 22 | Add(key, value); 23 | 24 | return this; 25 | } 26 | 27 | public QueryBuilder Add(string key, int value) 28 | { 29 | if (sb.Length == 0) 30 | sb.Append($"?{key}={value}"); 31 | else 32 | sb.Append($"&{key}={value}"); 33 | 34 | return this; 35 | } 36 | 37 | public QueryBuilder AddIf(bool match, string key, int value) 38 | { 39 | if (match) 40 | Add(key, value); 41 | 42 | return this; 43 | } 44 | 45 | public QueryBuilder Add(string key, bool value) 46 | { 47 | if (sb.Length == 0) 48 | sb.Append($"?{key}={value}"); 49 | else 50 | sb.Append($"&{key}={value}"); 51 | 52 | return this; 53 | } 54 | 55 | public QueryBuilder AddIf(bool match, string key, bool value) 56 | { 57 | if (match) 58 | Add(key, value); 59 | 60 | return this; 61 | } 62 | 63 | public string GetQuery() 64 | { 65 | if (sb.Length == 0) 66 | return string.Empty; 67 | 68 | return sb.ToString(); 69 | } 70 | 71 | public override string ToString() 72 | => GetQuery(); 73 | } -------------------------------------------------------------------------------- /RevoltSharp/Extensions/StringExtensions.cs: -------------------------------------------------------------------------------- 1 | using System.Buffers; 2 | 3 | namespace RevoltSharp; 4 | internal static class StringExtensions 5 | { 6 | public static string Create(int length, TState state, SpanAction action) 7 | { 8 | return string.Create(length, state, action); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /RevoltSharp/Extensions/TimestampExtension.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace RevoltSharp; 4 | internal static class TimestampExtension 5 | { 6 | internal static long ToTimestamp(this DateTime date) 7 | { 8 | long epoch = (date.Ticks - 621355968000000000) / 10000000; 9 | return epoch; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /RevoltSharp/Extensions/UlidTimestampHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.CompilerServices; 3 | 4 | namespace RevoltSharp; 5 | internal readonly struct UlidTimestampHelper 6 | { 7 | private const long TIMESTAMP_MASK_0 = 255; 8 | private const long TIMESTAMP_MASK_1 = 65280; 9 | private const long TIMESTAMP_MASK_2 = 16711680; 10 | private const long TIMESTAMP_MASK_3 = 4278190080; 11 | private const long TIMESTAMP_MASK_4 = 1095216660480; 12 | private const long TIMESTAMP_MASK_5 = 280375465082880; 13 | 14 | public UlidTimestampHelper(long timeStamp) 15 | { 16 | TimeStamp_0 = (byte)((timeStamp & TIMESTAMP_MASK_5) >> 40); 17 | TimeStamp_1 = (byte)((timeStamp & TIMESTAMP_MASK_4) >> 32); 18 | TimeStamp_2 = (byte)((timeStamp & TIMESTAMP_MASK_3) >> 24); 19 | TimeStamp_3 = (byte)((timeStamp & TIMESTAMP_MASK_2) >> 16); 20 | TimeStamp_4 = (byte)((timeStamp & TIMESTAMP_MASK_1) >> 8); 21 | TimeStamp_5 = (byte)((timeStamp & TIMESTAMP_MASK_0) >> 0); 22 | } 23 | 24 | public UlidTimestampHelper(ReadOnlySpan timestamp) 25 | { 26 | if (timestamp.Length != 6) 27 | { 28 | throw new ArgumentException($"Expected a length of {6}, received {timestamp.Length}", nameof(timestamp)); 29 | } 30 | 31 | TimeStamp_0 = timestamp[0]; 32 | TimeStamp_1 = timestamp[1]; 33 | TimeStamp_2 = timestamp[2]; 34 | TimeStamp_3 = timestamp[3]; 35 | TimeStamp_4 = timestamp[4]; 36 | TimeStamp_5 = timestamp[5]; 37 | } 38 | 39 | public byte TimeStamp_0 { get; } 40 | public byte TimeStamp_1 { get; } 41 | public byte TimeStamp_2 { get; } 42 | public byte TimeStamp_3 { get; } 43 | public byte TimeStamp_4 { get; } 44 | public byte TimeStamp_5 { get; } 45 | 46 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 47 | internal Ulid Create(ReadOnlySpan randomness) => new Ulid 48 | { 49 | TimeStamp_0 = TimeStamp_0, 50 | TimeStamp_1 = TimeStamp_1, 51 | TimeStamp_2 = TimeStamp_2, 52 | TimeStamp_3 = TimeStamp_3, 53 | TimeStamp_4 = TimeStamp_4, 54 | TimeStamp_5 = TimeStamp_5, 55 | Randomness_0 = randomness[0], 56 | Randomness_1 = randomness[1], 57 | Randomness_2 = randomness[2], 58 | Randomness_3 = randomness[3], 59 | Randomness_4 = randomness[4], 60 | Randomness_5 = randomness[5], 61 | Randomness_6 = randomness[6], 62 | Randomness_7 = randomness[7], 63 | Randomness_8 = randomness[8], 64 | Randomness_9 = randomness[9], 65 | }; 66 | } 67 | -------------------------------------------------------------------------------- /RevoltSharp/Internal/AdminClient.cs: -------------------------------------------------------------------------------- 1 | namespace RevoltSharp; 2 | 3 | public class AdminClient 4 | { 5 | internal AdminClient(RevoltClient client) 6 | { 7 | Client = client; 8 | } 9 | internal RevoltClient Client; 10 | } 11 | -------------------------------------------------------------------------------- /RevoltSharp/Internal/DisableConsoleQuickEdit.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace RevoltSharp; 5 | 6 | 7 | internal class DisableConsoleQuickEdit 8 | { 9 | const uint ENABLE_QUICK_EDIT = 0x0040; 10 | const int STD_INPUT_HANDLE = -10; 11 | 12 | [DllImport("kernel32.dll", SetLastError = true)] 13 | static extern IntPtr GetStdHandle(int nStdHandle); 14 | [DllImport("kernel32.dll")] 15 | static extern bool GetConsoleMode(IntPtr hConsoleHandle, out uint lpMode); 16 | [DllImport("kernel32.dll")] 17 | static extern bool SetConsoleMode(IntPtr hConsoleHandle, uint dwMode); 18 | 19 | /// 20 | /// Fix the console from freezing the bot due to checking for readinput in the console 21 | /// 22 | internal static bool Go() 23 | { 24 | IntPtr consoleHandle = GetStdHandle(STD_INPUT_HANDLE); 25 | if (!GetConsoleMode(consoleHandle, out uint consoleMode)) return false; 26 | consoleMode &= ~ENABLE_QUICK_EDIT; 27 | if (!SetConsoleMode(consoleHandle, consoleMode)) return false; 28 | return true; 29 | } 30 | } -------------------------------------------------------------------------------- /RevoltSharp/Internal/GlobalExtensions.cs: -------------------------------------------------------------------------------- 1 | using System.Numerics; 2 | 3 | namespace RevoltSharp; 4 | 5 | public static class GlobalExtensions 6 | { 7 | public static int ToInt(this BigInteger bint) 8 | { 9 | if (int.TryParse(bint.ToString(), out int number)) 10 | return number; 11 | 12 | if (bint > 0) 13 | throw new RevoltArgumentException($"Failed to parse big int because it's bigger than Int.MaxValue ({int.MaxValue})"); 14 | 15 | throw new RevoltArgumentException($"Failed to parse big int becasue it's less than Int.Minvalue ({int.MinValue})"); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /RevoltSharp/Internal/ModelExtensions.cs: -------------------------------------------------------------------------------- 1 | using Optionals; 2 | using System; 3 | 4 | namespace RevoltSharp; 5 | 6 | 7 | internal static class ModelExtensions 8 | { 9 | internal static T ToEnum(this string value, bool ignoreCase = true) 10 | { 11 | return (T)Enum.Parse(typeof(T), value, ignoreCase); 12 | } 13 | internal static Optional ToModel(this Optional json, RevoltClient client) 14 | { 15 | if (!json.HasValue) 16 | return Optional.None(); 17 | 18 | return Optional.Some(json.Value.ToModel(client)); 19 | } 20 | 21 | internal static Attachment? ToModel(this AttachmentJson json, RevoltClient client) 22 | { 23 | if (json == null) 24 | return null; 25 | 26 | return Attachment.Create(client, json); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /RevoltSharp/PackageIcon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FluxpointDev/RevoltSharp/133b03e27c8e61ac7472b081ca826124554eabcf/RevoltSharp/PackageIcon.png -------------------------------------------------------------------------------- /RevoltSharp/Rest/IRevoltRequest.cs: -------------------------------------------------------------------------------- 1 | namespace RevoltSharp.Rest; 2 | 3 | 4 | /// 5 | /// Send a custom json body request to the Revolt instance API

6 | /// Use or 7 | ///
8 | public interface IRevoltRequest { } -------------------------------------------------------------------------------- /RevoltSharp/Rest/Requests/Account/AccountChangeEmailRequest.cs: -------------------------------------------------------------------------------- 1 | using RevoltSharp.Rest; 2 | 3 | namespace RevoltSharp; 4 | 5 | internal class AccountChangeEmailRequest : IRevoltRequest 6 | { 7 | public string email { get; set; } 8 | public string current_password { get; set; } 9 | } 10 | -------------------------------------------------------------------------------- /RevoltSharp/Rest/Requests/Account/AccountChangePasswordRequest.cs: -------------------------------------------------------------------------------- 1 | using RevoltSharp.Rest; 2 | 3 | namespace RevoltSharp; 4 | 5 | internal class AccountChangePasswordRequest : IRevoltRequest 6 | { 7 | public string password { get; set; } 8 | public string current_password { get; set; } 9 | } 10 | -------------------------------------------------------------------------------- /RevoltSharp/Rest/Requests/Account/AccountConfirmDeletionRequest.cs: -------------------------------------------------------------------------------- 1 | using RevoltSharp.Rest; 2 | 3 | namespace RevoltSharp; 4 | 5 | internal class AccountConfirmDeletionRequest : IRevoltRequest 6 | { 7 | public string token { get; set; } 8 | } 9 | -------------------------------------------------------------------------------- /RevoltSharp/Rest/Requests/Account/AccountFetchSettingsRequest.cs: -------------------------------------------------------------------------------- 1 | using RevoltSharp.Rest; 2 | 3 | namespace RevoltSharp; 4 | internal class AccountFetchSettingsRequest : IRevoltRequest 5 | { 6 | public string[] keys { get; set; } 7 | } 8 | -------------------------------------------------------------------------------- /RevoltSharp/Rest/Requests/Account/AccountLoginMFARequest.cs: -------------------------------------------------------------------------------- 1 | namespace RevoltSharp.Rest.Requests; 2 | internal class AccountLoginMFARequest : IRevoltRequest 3 | { 4 | public string mfa_ticket { get; set; } 5 | public string friendly_name { get; set; } 6 | public AccountLoginMFAResponseRequest mfa_response { get; set; } = new AccountLoginMFAResponseRequest(); 7 | } 8 | internal class AccountLoginMFAResponseRequest 9 | { 10 | public string recovery_code { get; set; } 11 | public string totp_code { get; set; } 12 | } 13 | -------------------------------------------------------------------------------- /RevoltSharp/Rest/Requests/Account/AccountLoginRequest.cs: -------------------------------------------------------------------------------- 1 | namespace RevoltSharp.Rest.Requests; 2 | 3 | internal class AccountLoginRequest : IRevoltRequest 4 | { 5 | public string email { get; set; } 6 | public string password { get; set; } 7 | public string friendly_name { get; set; } 8 | } 9 | -------------------------------------------------------------------------------- /RevoltSharp/Rest/Requests/Account/AccountOnboardingRequest.cs: -------------------------------------------------------------------------------- 1 | using RevoltSharp.Rest; 2 | 3 | namespace RevoltSharp; 4 | internal class AccountOnboardingRequest : IRevoltRequest 5 | { 6 | public string username { get; set; } 7 | } 8 | -------------------------------------------------------------------------------- /RevoltSharp/Rest/Requests/Account/AccountPasswordResetRequest.cs: -------------------------------------------------------------------------------- 1 | using RevoltSharp.Rest; 2 | 3 | namespace RevoltSharp; 4 | 5 | internal class AccountPasswordResetRequest : IRevoltRequest 6 | { 7 | public string token { get; set; } 8 | public string password { get; set; } 9 | public bool remove_sessions { get; set; } 10 | } 11 | -------------------------------------------------------------------------------- /RevoltSharp/Rest/Requests/Account/AccountVerificationRequest.cs: -------------------------------------------------------------------------------- 1 | using RevoltSharp.Rest; 2 | 3 | namespace RevoltSharp; 4 | 5 | internal class AccountVerificationRequest : IRevoltRequest 6 | { 7 | public string email { get; set; } 8 | public string captcha { get; set; } 9 | } 10 | -------------------------------------------------------------------------------- /RevoltSharp/Rest/Requests/Account/ModifyAccountSessionRequest.cs: -------------------------------------------------------------------------------- 1 | using RevoltSharp.Rest; 2 | 3 | namespace RevoltSharp; 4 | internal class ModifyAccountSessionRequest : IRevoltRequest 5 | { 6 | public string friendly_name { get; set; } 7 | } 8 | -------------------------------------------------------------------------------- /RevoltSharp/Rest/Requests/Channel/BulkDeleteMessagesRequest.cs: -------------------------------------------------------------------------------- 1 | namespace RevoltSharp.Rest.Requests; 2 | 3 | 4 | internal class BulkDeleteMessagesRequest : IRevoltRequest 5 | { 6 | public string[]? ids { get; set; } 7 | } -------------------------------------------------------------------------------- /RevoltSharp/Rest/Requests/Channel/SendMessageRequest.cs: -------------------------------------------------------------------------------- 1 | using Optionals; 2 | 3 | namespace RevoltSharp.Rest.Requests; 4 | 5 | 6 | internal class SendMessageRequest : IRevoltRequest 7 | { 8 | public Optional content { get; set; } 9 | public string? nonce { get; set; } 10 | public Optional attachments { get; set; } 11 | public Optional embeds { get; set; } 12 | public Optional masquerade { get; set; } 13 | public Optional interactions { get; set; } 14 | public Optional replies { get; set; } 15 | public Optional flags { get; set; } 16 | } -------------------------------------------------------------------------------- /RevoltSharp/Rest/Requests/Client/CreateAccountRequest.cs: -------------------------------------------------------------------------------- 1 | using RevoltSharp.Rest; 2 | 3 | namespace RevoltSharp; 4 | 5 | internal class CreateAccountRequest : IRevoltRequest 6 | { 7 | public string email { get; set; } 8 | public string password { get; set; } 9 | public string? invite { get; set; } 10 | public string? captcha { get; set; } 11 | } 12 | -------------------------------------------------------------------------------- /RevoltSharp/Rest/Requests/Client/PasswordResetRequest.cs: -------------------------------------------------------------------------------- 1 | using RevoltSharp.Rest; 2 | 3 | namespace RevoltSharp; 4 | 5 | internal class PasswordResetRequest : IRevoltRequest 6 | { 7 | public string email { get; set; } 8 | public string captcha { get; set; } 9 | } 10 | -------------------------------------------------------------------------------- /RevoltSharp/Rest/Requests/Server/CreateChannelRequest.cs: -------------------------------------------------------------------------------- 1 | using Optionals; 2 | 3 | namespace RevoltSharp.Rest.Requests; 4 | 5 | 6 | internal class CreateChannelRequest : IRevoltRequest 7 | { 8 | public string? name { get; set; } 9 | public Optional type { get; set; } 10 | public Optional description { get; set; } 11 | public Optional users { get; set; } 12 | public Optional nsfw { get; set; } 13 | 14 | } -------------------------------------------------------------------------------- /RevoltSharp/Rest/Requests/Server/CreateEmojiRequest.cs: -------------------------------------------------------------------------------- 1 | namespace RevoltSharp.Rest.Requests; 2 | 3 | 4 | internal class CreateEmojiRequest : IRevoltRequest 5 | { 6 | public string? name { get; set; } 7 | public CreateEmojiParent? parent { get; set; } 8 | public bool nsfw { get; set; } 9 | } 10 | internal class CreateEmojiParent 11 | { 12 | public string type { get; set; } = "Server"; 13 | public string? id { get; set; } 14 | } 15 | -------------------------------------------------------------------------------- /RevoltSharp/Rest/Requests/Server/CreateRoleRequest.cs: -------------------------------------------------------------------------------- 1 | using Optionals; 2 | 3 | namespace RevoltSharp.Rest.Requests; 4 | 5 | 6 | internal class CreateRoleRequest : IRevoltRequest 7 | { 8 | public string? name { get; set; } 9 | public Optional rank { get; set; } 10 | } -------------------------------------------------------------------------------- /RevoltSharp/Rest/Requests/Server/CreateWebhookRequest.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using Optionals; 3 | 4 | namespace RevoltSharp.Rest.Requests; 5 | 6 | internal class CreateWebhookRequest : IRevoltRequest 7 | { 8 | [JsonProperty("name")] 9 | public string Name { get; set; } = null!; 10 | 11 | [JsonProperty("avatar")] 12 | public Optional Avatar { get; set; } 13 | } -------------------------------------------------------------------------------- /RevoltSharp/Rest/Requests/Server/EditMemberRequest.cs: -------------------------------------------------------------------------------- 1 | using Optionals; 2 | using System; 3 | using System.Collections.Generic; 4 | 5 | namespace RevoltSharp.Rest.Requests; 6 | 7 | 8 | internal class EditMemberRequest : IRevoltRequest 9 | { 10 | public Optional roles { get; set; } 11 | public Optional nickname { get; set; } 12 | public Optional avatar { get; set; } 13 | public Optional timeout { get; set; } 14 | public Optional> remove { get; set; } 15 | 16 | public void RemoveValue(string value) 17 | { 18 | if (!remove.HasValue) 19 | remove = Optional.Some(new List()); 20 | 21 | remove.Value.Add(value); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /RevoltSharp/Rest/Requests/Server/ModifyChannelRequest.cs: -------------------------------------------------------------------------------- 1 | using Optionals; 2 | using System.Collections.Generic; 3 | 4 | namespace RevoltSharp.Rest.Requests; 5 | 6 | 7 | internal class ModifyChannelRequest : IRevoltRequest 8 | { 9 | public Optional name { get; set; } 10 | public Optional description { get; set; } 11 | public Optional icon { get; set; } 12 | public Optional nsfw { get; set; } 13 | public Optional> remove { get; set; } 14 | public Optional owner { get; set; } 15 | 16 | 17 | 18 | public void RemoveValue(string value) 19 | { 20 | if (!remove.HasValue) 21 | remove = Optional.Some(new List()); 22 | 23 | remove.Value.Add(value); 24 | } 25 | } -------------------------------------------------------------------------------- /RevoltSharp/Rest/Requests/Server/ModifyDefaultPermissionsRequest.cs: -------------------------------------------------------------------------------- 1 | namespace RevoltSharp.Rest.Requests; 2 | 3 | internal class ModifyDefaultPermissionsRequest : IRevoltRequest 4 | { 5 | public ulong permissions { get; set; } 6 | } 7 | -------------------------------------------------------------------------------- /RevoltSharp/Rest/Requests/Server/ModifyRoleRequest.cs: -------------------------------------------------------------------------------- 1 | using Optionals; 2 | using System.Collections.Generic; 3 | 4 | namespace RevoltSharp.Rest.Requests; 5 | 6 | 7 | internal class ModifyRoleRequest : IRevoltRequest 8 | { 9 | public Optional name { get; set; } 10 | public Optional colour { get; set; } 11 | public Optional hoist { get; set; } 12 | public Optional rank { get; set; } 13 | public Optional> remove { get; set; } 14 | 15 | public void RemoveValue(string value) 16 | { 17 | if (!remove.HasValue) 18 | remove = Optional.Some(new List()); 19 | 20 | remove.Value.Add(value); 21 | } 22 | } -------------------------------------------------------------------------------- /RevoltSharp/Rest/Requests/Server/ModifyServerRequest.cs: -------------------------------------------------------------------------------- 1 | using Optionals; 2 | using System.Collections.Generic; 3 | 4 | namespace RevoltSharp.Rest.Requests; 5 | internal class ModifyServerRequest : IRevoltRequest 6 | { 7 | public Optional name { get; set; } 8 | 9 | public Optional description { get; set; } 10 | 11 | public Optional icon { get; set; } 12 | 13 | public Optional banner { get; set; } 14 | 15 | public Optional> categories { get; set; } 16 | 17 | public Optional system_messages { get; set; } 18 | 19 | public Optional> remove { get; set; } 20 | 21 | public void RemoveValue(string value) 22 | { 23 | if (!remove.HasValue) 24 | remove = Optional.Some(new List()); 25 | 26 | remove.Value.Add(value); 27 | } 28 | } 29 | internal class ModifyServerSystemChannels 30 | { 31 | public Optional user_joined { get; set; } 32 | public Optional user_left { get; set; } 33 | public Optional user_kicked { get; set; } 34 | public Optional user_banned { get; set; } 35 | } 36 | -------------------------------------------------------------------------------- /RevoltSharp/Rest/Requests/Server/ReasonRequest.cs: -------------------------------------------------------------------------------- 1 | using Optionals; 2 | 3 | namespace RevoltSharp.Rest.Requests; 4 | 5 | 6 | internal class ReasonRequest : IRevoltRequest 7 | { 8 | public Optional reason { get; set; } 9 | 10 | } -------------------------------------------------------------------------------- /RevoltSharp/Rest/RestError.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace RevoltSharp.Rest; 4 | 5 | internal class RestError 6 | { 7 | [JsonProperty("type")] 8 | public RevoltErrorType Type = RevoltErrorType.Unknown; 9 | 10 | [JsonProperty("permission")] 11 | public string? Permission; 12 | } -------------------------------------------------------------------------------- /RevoltSharp/RevoltSharp.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net6.0 5 | disable 6 | 8.1.2 7 | Builderb (Fluxpoint Development) 8 | Fluxpoint Development 9 | A C# lib for using the revolt chat API and connecting to the gateway with a user or bot account. 10 | RevoltSharp 11 | https://docs.fluxpoint.dev/revoltsharp 12 | https://github.com/FluxpointDev/RevoltSharp 13 | revolt, revolt bot, bot, revoltsharp, revolt c# 14 | See changelog https://docs.fluxpoint.dev/revoltsharp/changelog 15 | enable 16 | PackageIcon.png 17 | 18 | True 19 | RevoltSharp.xml 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | True 33 | \ 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /RevoltSharp/WebSocket/AuthenticateSocketRequest.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace RevoltSharp.WebSocket; 4 | internal class AuthenticateSocketRequest 5 | { 6 | internal AuthenticateSocketRequest(string token) 7 | { 8 | Token = token; 9 | } 10 | 11 | [JsonProperty("type")] 12 | public string Type = "Authenticate"; 13 | 14 | [JsonProperty("token")] 15 | public string Token; 16 | } 17 | -------------------------------------------------------------------------------- /RevoltSharp/WebSocket/BeginTypingSocketRequest.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace RevoltSharp.WebSocket; 4 | 5 | internal class BeginTypingSocketRequest 6 | { 7 | internal BeginTypingSocketRequest(string channelId) 8 | { 9 | ChannelId = channelId; 10 | } 11 | 12 | [JsonProperty("type")] 13 | public string Type = "BeginTyping"; 14 | 15 | [JsonProperty("channel")] 16 | public string ChannelId; 17 | } -------------------------------------------------------------------------------- /RevoltSharp/WebSocket/EndTypingSocketRequest.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace RevoltSharp.WebSocket; 4 | 5 | internal class EndTypingSocketRequest 6 | { 7 | internal EndTypingSocketRequest(string channelId) 8 | { 9 | ChannelId = channelId; 10 | } 11 | 12 | [JsonProperty("type")] 13 | public string Type = "BeginTyping"; 14 | 15 | [JsonProperty("channel")] 16 | public string ChannelId; 17 | } -------------------------------------------------------------------------------- /RevoltSharp/WebSocket/Events/BulkEventsJson.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace RevoltSharp.WebSocket.Events; 4 | 5 | internal class BulkEventsJson 6 | { 7 | [JsonProperty("v")] 8 | public dynamic[]? Events; 9 | } -------------------------------------------------------------------------------- /RevoltSharp/WebSocket/Events/ChannelEventsJson.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using Optionals; 3 | 4 | namespace RevoltSharp.WebSocket; 5 | 6 | 7 | internal class ChannelEventJson : ChannelJson 8 | { 9 | } 10 | internal class ChannelDeleteEventJson 11 | { 12 | [JsonProperty("id")] 13 | public string? ChannelId; 14 | } 15 | internal class ChannelUpdateEventJson 16 | { 17 | [JsonProperty("id")] 18 | public string? ChannelId; 19 | 20 | [JsonProperty("data")] 21 | public PartialChannelJson? Data; 22 | 23 | [JsonProperty("clear")] 24 | public Optional Clear; 25 | } -------------------------------------------------------------------------------- /RevoltSharp/WebSocket/Events/ChannelGroupEventsJson.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace RevoltSharp.WebSocket; 4 | 5 | 6 | internal class ChannelGroupJoinEventJson 7 | { 8 | [JsonProperty("id")] 9 | public string? ChannelId; 10 | 11 | [JsonProperty("user")] 12 | public string? UserId; 13 | } 14 | internal class ChannelGroupLeaveEventJson 15 | { 16 | [JsonProperty("id")] 17 | public string? ChannelId; 18 | 19 | [JsonProperty("user")] 20 | public string? UserId; 21 | } -------------------------------------------------------------------------------- /RevoltSharp/WebSocket/Events/ErrorEventJson.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace RevoltSharp.WebSocket.Events; 4 | 5 | 6 | internal class ErrorEventJson 7 | { 8 | [JsonProperty("error")] 9 | public RevoltErrorType Error { get; set; } 10 | 11 | [JsonProperty("msg")] 12 | public string? Message { get; set; } 13 | } -------------------------------------------------------------------------------- /RevoltSharp/WebSocket/Events/MessageEventsJson.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using Optionals; 3 | using System; 4 | 5 | namespace RevoltSharp.WebSocket; 6 | 7 | 8 | internal class MessageEventJson : MessageJson 9 | { 10 | [JsonProperty("user")] 11 | public UserJson? User { get; set; } 12 | 13 | [JsonProperty("member")] 14 | public ServerMemberJson? Member { get; set; } 15 | } 16 | internal class MessageDeleteEventJson 17 | { 18 | [JsonProperty("id")] 19 | public string? MessageId; 20 | 21 | [JsonProperty("ids")] 22 | public string[]? MessageIds; 23 | 24 | [JsonProperty("channel")] 25 | public string? ChannelId; 26 | } 27 | internal class MessageUpdateEventJson 28 | { 29 | [JsonProperty("id")] 30 | public string MessageId = null!; 31 | 32 | [JsonProperty("channel")] 33 | public string ChannelId = null!; 34 | 35 | [JsonProperty("data")] 36 | public MessageUpdateDataJson Data = null!; 37 | } 38 | internal class MessageUpdateDataJson 39 | { 40 | [JsonProperty("content")] 41 | public Optional Content; 42 | 43 | [JsonProperty("embeds")] 44 | public Optional Embeds; 45 | 46 | [JsonProperty("edited")] 47 | public DateTime EditedAt; 48 | } -------------------------------------------------------------------------------- /RevoltSharp/WebSocket/Events/ReactionEventsJson.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace RevoltSharp.WebSocket; 4 | 5 | 6 | internal class ReactionAddedEventJson 7 | { 8 | [JsonProperty("id")] 9 | public string? MessageId; 10 | 11 | [JsonProperty("channel_id")] 12 | public string? ChannelId; 13 | 14 | [JsonProperty("user_id")] 15 | public string? UserId; 16 | 17 | [JsonProperty("emoji_id")] 18 | public string? EmojiId; 19 | } 20 | internal class ReactionRemovedEventJson 21 | { 22 | [JsonProperty("id")] 23 | public string? MessageId; 24 | 25 | [JsonProperty("channel_id")] 26 | public string? ChannelId; 27 | 28 | [JsonProperty("user_id")] 29 | public string? UserId; 30 | 31 | [JsonProperty("emoji_id")] 32 | public string? EmojiId; 33 | } -------------------------------------------------------------------------------- /RevoltSharp/WebSocket/Events/ReadyEventJson.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace RevoltSharp.WebSocket.Events; 4 | 5 | 6 | internal class ReadyEventJson 7 | { 8 | [JsonProperty("users")] 9 | public UserJson[]? Users; 10 | 11 | [JsonProperty("servers")] 12 | public ServerJson[]? Servers; 13 | 14 | [JsonProperty("channels")] 15 | public ChannelJson[]? Channels; 16 | 17 | [JsonProperty("members")] 18 | public ServerMemberJson[]? Members; 19 | 20 | [JsonProperty("emojis")] 21 | public EmojiJson[]? Emojis; 22 | } -------------------------------------------------------------------------------- /RevoltSharp/WebSocket/Events/ServerEmojiEventsJson.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace RevoltSharp.WebSocket; 4 | 5 | 6 | internal class ServerEmojiCreatedEventJson : EmojiJson 7 | { 8 | 9 | } 10 | internal class ServerEmojiDeleteEventJson 11 | { 12 | [JsonProperty("id")] 13 | public string? EmojiId; 14 | } -------------------------------------------------------------------------------- /RevoltSharp/WebSocket/Events/ServerEventsJson.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using Optionals; 3 | 4 | namespace RevoltSharp.WebSocket; 5 | 6 | 7 | internal class ServerJoinEventJson 8 | { 9 | [JsonProperty("id")] 10 | public string? ServerId; 11 | 12 | [JsonProperty("server")] 13 | public ServerJson? ServerJson; 14 | 15 | [JsonProperty("channels")] 16 | public ChannelJson[]? ChannelsJson; 17 | } 18 | internal class ServerDeleteEventJson 19 | { 20 | [JsonProperty("id")] 21 | public string? ServerId; 22 | } 23 | internal class ServerUpdateEventJson 24 | { 25 | [JsonProperty("id")] 26 | public string? ServerId; 27 | 28 | [JsonProperty("data")] 29 | public PartialServerJson? Data; 30 | 31 | [JsonProperty("clear")] 32 | public Optional Clear; 33 | } -------------------------------------------------------------------------------- /RevoltSharp/WebSocket/Events/ServerMemberEventsJson.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using Optionals; 3 | 4 | namespace RevoltSharp.WebSocket; 5 | 6 | 7 | internal class ServerMemberJoinEventJson 8 | { 9 | [JsonProperty("id")] 10 | public string? ServerId; 11 | 12 | [JsonProperty("user")] 13 | public string? UserId; 14 | } 15 | internal class ServerMemberLeaveEventJson 16 | { 17 | [JsonProperty("id")] 18 | public string? ServerId; 19 | 20 | [JsonProperty("user")] 21 | public string? UserId; 22 | } 23 | internal class ServerMemberUpdateEventJson 24 | { 25 | [JsonProperty("id")] 26 | public ServerMemberIdsJson? Id; 27 | 28 | [JsonProperty("data")] 29 | public PartialServerMemberJson? Data; 30 | 31 | [JsonProperty("clear")] 32 | public Optional Clear; 33 | } -------------------------------------------------------------------------------- /RevoltSharp/WebSocket/Events/ServerRoleEventsJson.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace RevoltSharp.WebSocket; 4 | 5 | 6 | internal class ServerRoleEventsJson 7 | { 8 | [JsonProperty("id")] 9 | public string? Id; 10 | 11 | [JsonProperty("role_id")] 12 | public string? RoleId; 13 | } 14 | internal class ServerRoleUpdateEventJson 15 | { 16 | [JsonProperty("id")] 17 | public string? ServerId; 18 | 19 | [JsonProperty("role_id")] 20 | public string? RoleId; 21 | 22 | [JsonProperty("data")] 23 | public PartialRoleJson? Data; 24 | } -------------------------------------------------------------------------------- /RevoltSharp/WebSocket/Events/UserEventsJson.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using Optionals; 3 | 4 | namespace RevoltSharp.WebSocket; 5 | 6 | 7 | internal class UserUpdateEventJson 8 | { 9 | [JsonProperty("id")] 10 | public string? Id; 11 | 12 | [JsonProperty("data")] 13 | public PartialUserJson? Data; 14 | 15 | [JsonProperty("clear")] 16 | public Optional Clear; 17 | } 18 | internal class UserRelationshipEventJson 19 | { 20 | [JsonProperty("id")] 21 | public string? Id; 22 | 23 | [JsonProperty("user")] 24 | public UserJson? User; 25 | 26 | [JsonProperty("status")] 27 | public string? Status; 28 | } 29 | internal class UserPlatformWipedEventJson 30 | { 31 | [JsonProperty("user_id")] 32 | public string UserId = null!; 33 | 34 | [JsonProperty("flags")] 35 | public ulong Flags; 36 | } -------------------------------------------------------------------------------- /RevoltSharp/WebSocket/Events/WebhookCreateEventJson.cs: -------------------------------------------------------------------------------- 1 | namespace RevoltSharp.WebSocket; 2 | internal class WebhookCreateEventJson : WebhookJson 3 | { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /RevoltSharp/WebSocket/HeartbeatSocketRequest.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace RevoltSharp.WebSocket; 4 | 5 | internal class HeartbeatSocketRequest 6 | { 7 | [JsonProperty("type")] 8 | public string Type = "Ping"; 9 | 10 | [JsonProperty("data")] 11 | public int Data = 20000; 12 | } 13 | -------------------------------------------------------------------------------- /RevoltSharp/WebSocket/TypingNotifier.cs: -------------------------------------------------------------------------------- 1 | using RevoltSharp.Rest; 2 | using System; 3 | using System.Threading; 4 | using System.Threading.Tasks; 5 | 6 | namespace RevoltSharp.WebSocket; 7 | 8 | public class TypingNotifier : IDisposable 9 | { 10 | private readonly RevoltRestClient _client; 11 | private readonly CancellationTokenSource _cancelToken; 12 | private readonly string _channel; 13 | 14 | internal TypingNotifier(RevoltRestClient rest, string channel) 15 | { 16 | _client = rest; 17 | _cancelToken = new CancellationTokenSource(); 18 | _channel = channel; 19 | _ = RunAsync(); 20 | } 21 | 22 | internal async Task RunAsync() 23 | { 24 | _client.Client.WebSocket.TypingChannels.TryAdd(_channel, this); 25 | try 26 | { 27 | CancellationToken token = _cancelToken.Token; 28 | while (!_cancelToken.IsCancellationRequested) 29 | { 30 | try 31 | { 32 | await _client.TriggerTypingChannelAsync(_channel); 33 | } 34 | catch { } 35 | 36 | await Task.Delay(2500, token); 37 | } 38 | } 39 | catch { } 40 | Dispose(); 41 | } 42 | 43 | public void Stop() 44 | { 45 | _cancelToken.Cancel(); 46 | } 47 | 48 | public void Dispose() 49 | { 50 | _client.Client.WebSocket.TypingChannels.TryRemove(_channel, out _); 51 | _ = _client.StopTypingChannelAsync(_channel); 52 | _cancelToken.Cancel(); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /TestBot/TestBot.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net6.0 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | --------------------------------------------------------------------------------