From 063bc4e8f53cff4306e3d166548d1b9d31e102b9 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Wed, 24 May 2023 22:03:51 +0200 Subject: [PATCH 001/323] initial commit of v6 --- .editorconfig | 193 +++++++++++++++++++ .git-hooks/pre-commit.sh | 16 ++ .gitconfig | 2 + .gitignore | 407 +++++++++++++++++++++++++++++++++++++++ DSharpPlus.sln | 14 ++ Directory.Build.props | 28 +++ Directory.Build.targets | 32 +++ Directory.Packages.props | 5 + DiscordSharp.LICENSE | 21 ++ LICENSE | 373 +++++++++++++++++++++++++++++++++++ LICENSE-OLD | 22 +++ readme.md | 14 ++ 12 files changed, 1127 insertions(+) create mode 100644 .editorconfig create mode 100644 .git-hooks/pre-commit.sh create mode 100644 .gitconfig create mode 100644 .gitignore create mode 100644 DSharpPlus.sln create mode 100644 Directory.Build.props create mode 100644 Directory.Build.targets create mode 100644 Directory.Packages.props create mode 100644 DiscordSharp.LICENSE create mode 100644 LICENSE create mode 100644 LICENSE-OLD create mode 100644 readme.md diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000000..39b654635e --- /dev/null +++ b/.editorconfig @@ -0,0 +1,193 @@ +############################### +# Core EditorConfig Options # +############################### +root = true + +# All files +[*] +indent_style = space + +# XML project files +[*.{csproj,vbproj,vcxproj,vcxproj.filters,proj,projitems,shproj}] +indent_size = 2 + +# XML config files +[*.{props,targets,ruleset,config,nuspec,resx,vsixmanifest,vsct}] +indent_size = 2 + +# util shell scripts +[*.sh] +end_of_line = lf + +[*.{cmd,bat}] +end_of_line = crlf + +# Code files +[*.cs] +indent_size = 4 +insert_final_newline = true +charset = utf-8 + +############################### +# .NET Coding Conventions # +############################### +[*.{cs,vb}] + +# MPL file header +file_header_template = This Source Code form is subject to the terms of the Mozilla Public\nLicense, v. 2.0. If a copy of the MPL was not distributed with this\nfile, You can obtain one at https://mozilla.org/MPL/2.0/. + +# Organize usings +dotnet_sort_system_directives_first = true:error +dotnet_separate_import_directive_groups = true:error +csharp_qualified_using_at_nested_scope = true:error +# usings before namespace +dotnet_diagnostic.IDE0064.severity = none +# Using directive is unnecessary. +dotnet_diagnostic.IDE0005.severity = error + +# Yell at people when they don't include the file header template +dotnet_diagnostic.IDE0073.severity = error + +# this. preferences +dotnet_style_qualification_for_field = true:silent +dotnet_style_qualification_for_property = true:silent +dotnet_style_qualification_for_method = true:silent +dotnet_style_qualification_for_event = true:silent + +# Language keywords vs BCL types preferences +dotnet_style_predefined_type_for_locals_parameters_members = true:error +dotnet_style_predefined_type_for_member_access = true:error + +# Parentheses preferences +dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity:error +dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:error +dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:error +dotnet_style_parentheses_in_other_operators = never_if_unnecessary:error + +# Modifier preferences +dotnet_style_require_accessibility_modifiers = true:error +dotnet_style_readonly_field = true:error + +# Expression-level preferences +dotnet_style_object_initializer = true:error +dotnet_style_collection_initializer = true:error +dotnet_style_explicit_tuple_names = true:error +dotnet_style_null_propagation = true:error +dotnet_style_coalesce_expression = true:error +dotnet_style_prefer_is_null_check_over_reference_equality_method = true:error +dotnet_style_prefer_inferred_tuple_names = true:error +dotnet_style_prefer_inferred_anonymous_type_member_names = true:error +dotnet_style_prefer_auto_properties = true:error +dotnet_style_prefer_conditional_expression_over_assignment = true:error +dotnet_style_prefer_conditional_expression_over_return = true:error + +############################### +# Naming Conventions # +############################### + +# Style Definitions +dotnet_naming_style.pascal_case_style.capitalization = pascal_case + +# Use PascalCase for constant fields +dotnet_naming_rule.constant_fields_should_be_pascal_case.severity = error +dotnet_naming_rule.constant_fields_should_be_pascal_case.symbols = constant_fields +dotnet_naming_rule.constant_fields_should_be_pascal_case.style = pascal_case_style +dotnet_naming_symbols.constant_fields.applicable_kinds = field +dotnet_naming_symbols.constant_fields.applicable_accessibilities = * +dotnet_naming_symbols.constant_fields.required_modifiers = const + +# Interfaces should start with I +dotnet_naming_rule.interface_should_be_begins_with_i.severity = error +dotnet_naming_rule.interface_should_be_begins_with_i.symbols = interface +dotnet_naming_rule.interface_should_be_begins_with_i.style = begins_with_i +dotnet_naming_style.begins_with_i.required_prefix = I +dotnet_naming_style.begins_with_i.capitalization = pascal_case +dotnet_naming_symbols.interface.applicable_kinds = interface + +# Async Methods should end with Async +dotnet_naming_rule.async_methods_should_be_async_suffix.severity = error +dotnet_naming_rule.async_methods_should_be_async_suffix.symbols = async_methods +dotnet_naming_rule.async_methods_should_be_async_suffix.style = async_suffix +dotnet_naming_style.async_suffix.required_suffix = Async +dotnet_naming_style.async_suffix.capitalization = pascal_case +dotnet_naming_symbols.async_methods.applicable_kinds = method +dotnet_naming_symbols.async_methods.required_modifiers = async + +# Force namespaces to match their folder names +# We'll override this later in folders where we don't want this +dotnet_diagnostic.IDE0130.severity = none + +############################### +# C# Coding Conventions # +############################### +[*.cs] + +# File-scoped namespaces +csharp_style_namespace_declarations = file_scoped:error + +# var preferences +csharp_style_var_for_built_in_types = false:error +csharp_style_var_when_type_is_apparent = false:error +csharp_style_var_elsewhere = false:error + +# Expression-bodied members +csharp_style_expression_bodied_methods = when_on_single_line:error +csharp_style_expression_bodied_constructors = when_on_single_line:error +csharp_style_expression_bodied_operators = when_on_single_line:error +csharp_style_expression_bodied_properties = when_on_single_line:error +csharp_style_expression_bodied_indexers = when_on_single_line:error +csharp_style_expression_bodied_accessors = when_on_single_line:error +csharp_style_expression_bodied_lambdas = when_on_single_line:warning + +# Pattern matching preferences +csharp_style_pattern_matching_over_is_with_cast_check = true:error +csharp_style_pattern_matching_over_as_with_null_check = true:error + +# Null-checking preferences +csharp_style_throw_expression = true:error +csharp_style_conditional_delegate_call = true:error + +# Modifier preferences +csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async:error + +# Expression-level preferences +csharp_prefer_braces = true:error +csharp_style_deconstructed_variable_declaration = true:error +csharp_prefer_simple_default_expression = true:error +csharp_style_pattern_local_over_anonymous_function = true:error +csharp_style_inlined_variable_declaration = true:error + +############################### +# C# Formatting Rules # +############################### + +# New line preferences +csharp_new_line_before_open_brace = all +csharp_new_line_before_else = true +csharp_new_line_before_catch = true +csharp_new_line_before_finally = true +csharp_new_line_before_members_in_object_initializers = true +csharp_new_line_before_members_in_anonymous_types = true +csharp_new_line_between_query_expression_clauses = true + +# Indentation preferences +csharp_indent_case_contents = true +csharp_indent_switch_labels = true +csharp_indent_labels = flush_left + +# Space preferences +csharp_space_after_cast = false +csharp_space_after_keywords_in_control_flow_statements = true +csharp_space_between_method_call_parameter_list_parentheses = false +csharp_space_between_method_declaration_parameter_list_parentheses = false +csharp_space_between_parentheses = false +csharp_space_before_colon_in_inheritance_clause = true +csharp_space_after_colon_in_inheritance_clause = true +csharp_space_around_binary_operators = before_and_after +csharp_space_between_method_declaration_empty_parameter_list_parentheses = false +csharp_space_between_method_call_name_and_opening_parenthesis = false +csharp_space_between_method_call_empty_parameter_list_parentheses = false + +# Wrapping preferences +csharp_preserve_single_line_statements = true +csharp_preserve_single_line_blocks = true diff --git a/.git-hooks/pre-commit.sh b/.git-hooks/pre-commit.sh new file mode 100644 index 0000000000..45668cdf20 --- /dev/null +++ b/.git-hooks/pre-commit.sh @@ -0,0 +1,16 @@ +#!/bin/sh +# https://gist.github.com/EtherZa/581d9276336353838b2c939f9554d479 + +LC_ALL=C + +# Select files to format +FILES=$(git diff --cached --name-only --diff-filter=ACM "*.cs" | sed 's| |\\ |g') +[ -z "$FILES" ] && exit 0 + +# Format all selected files +echo "$FILES" | cat | xargs | sed -e 's/ /,/g' | xargs dotnet format --include + +# Add back the modified files to staging +echo "$FILES" | xargs git add + +exit 0 \ No newline at end of file diff --git a/.gitconfig b/.gitconfig new file mode 100644 index 0000000000..c9ba6ad618 --- /dev/null +++ b/.gitconfig @@ -0,0 +1,2 @@ +[core] + hooksPath = .git-hooks diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000..b54f76e6b9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,407 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore + +# User-specific files +*.rsuser +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Mono auto generated files +mono_crash.* + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +[Ww][Ii][Nn]32/ +[Aa][Rr][Mm]/ +[Aa][Rr][Mm]64/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ +[Ll]ogs/ + +# Visual Studio 2015/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUnit +*.VisualState.xml +TestResult.xml +nunit-*.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ + +# ASP.NET Scaffolding +ScaffoldingReadMe.txt + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_h.h +*.ilk +*.meta +*.obj +*.iobj +*.pch +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*_wpftmp.csproj +*.log +*.tlog +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Coverlet is a free, cross platform Code Coverage Tool +coverage*.json +coverage*.xml +coverage*.info + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# NuGet Symbol Packages +*.snupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx +*.appxbundle +*.appxupload + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!?*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser +*- [Bb]ackup.rdl +*- [Bb]ackup ([0-9]).rdl +*- [Bb]ackup ([0-9][0-9]).rdl + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio 6 auto-generated project file (contains which files were open etc.) +*.vbp + +# Visual Studio 6 workspace and project file (working project files containing files to include in project) +*.dsw +*.dsp + +# Visual Studio 6 technical files +*.ncb +*.aps + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# CodeRush personal settings +.cr/personal + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ + +# Local History for Visual Studio +.localhistory/ + +# Visual Studio History (VSHistory) files +.vshistory/ + +# BeatPulse healthcheck temp database +healthchecksdb + +# Backup folder for Package Reference Convert tool in Visual Studio 2017 +MigrationBackup/ + +# Ionide (cross platform F# VS Code tools) working folder +.ionide/ + +# Fody - auto-generated XML schema +FodyWeavers.xsd + +# VS Code files for those working on multiple tools +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +*.code-workspace + +# Local History for Visual Studio Code +.history/ + +# Windows Installer files from build outputs +*.cab +*.msi +*.msix +*.msm +*.msp + +# JetBrains Rider +*.sln.iml + +# Credentials for the DSharpPlus.Test bot +DSharpPlus.Test/config.json + +# Github Codespaces configuration file +.devcontainer/devcontainer.json + +# Docfx +docs/_site diff --git a/DSharpPlus.sln b/DSharpPlus.sln new file mode 100644 index 0000000000..58ea566644 --- /dev/null +++ b/DSharpPlus.sln @@ -0,0 +1,14 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.0.31903.59 +MinimumVisualStudioVersion = 10.0.40219.1 +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/Directory.Build.props b/Directory.Build.props new file mode 100644 index 0000000000..ba8d4306cd --- /dev/null +++ b/Directory.Build.props @@ -0,0 +1,28 @@ + + + net8.0 + enable + 11 + Naamloos, afroraydude, DrCreo, Death, TiaqoY0, Axiom, Emzi0767, IDoEverything, Velvet, OoLunar, akiraveliara, DSharpPlus contributors + DSharpPlus Contributors + https://github.com/DSharpPlus/DSharpPlus + https://github.com/DSharpPlus/DSharpPlus + Git + MPL + dsharpplus.png + https://raw.githubusercontent.com/DSharpPlus/DSharpPlus/master/logo/dsharpplus.png + True + CS1591 + True + + + True + true + + + true + true + true + snupkg + + \ No newline at end of file diff --git a/Directory.Build.targets b/Directory.Build.targets new file mode 100644 index 0000000000..db9ece642b --- /dev/null +++ b/Directory.Build.targets @@ -0,0 +1,32 @@ + + + + + + <_ProjectReferenceWithExplicitPackageVersion + Include="@(ProjectReference->'%(FullPath)')" + Condition="'%(ProjectReference.PackageVersion)' != ''" /> + + <_ProjectReferenceWithExactPackageVersion + Include="@(ProjectReference->'%(FullPath)')" + Condition="'%(ProjectReference.ExactVersion)' == 'true'" /> + + <_ProjectReferenceWithReassignedVersion + Include="@(_ProjectReferencesWithVersions)" + Condition="'%(Identity)' != '' And '@(_ProjectReferencesWithVersions)' == '@(_ProjectReferenceWithExplicitPackageVersion)'"> + + @(_ProjectReferenceWithExplicitPackageVersion->'%(PackageVersion)') + + + <_ProjectReferenceWithReassignedVersion + Include="@(_ProjectReferencesWithVersions)" + Condition="'%(Identity)' != '' And '@(_ProjectReferencesWithVersions)' == '@(_ProjectReferenceWithExactPackageVersion)'"> + + [@(_ProjectReferencesWithVersions->'%(ProjectVersion)')] + + + <_ProjectReferencesWithVersions Remove="@(_ProjectReferenceWithReassignedVersion)" /> + <_ProjectReferencesWithVersions Include="@(_ProjectReferenceWithReassignedVersion)" /> + + + \ No newline at end of file diff --git a/Directory.Packages.props b/Directory.Packages.props new file mode 100644 index 0000000000..c8cf792a02 --- /dev/null +++ b/Directory.Packages.props @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/DiscordSharp.LICENSE b/DiscordSharp.LICENSE new file mode 100644 index 0000000000..1c9a25bc6d --- /dev/null +++ b/DiscordSharp.LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2015 Mike Santiago + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000000..dbdb0fa8e5 --- /dev/null +++ b/LICENSE @@ -0,0 +1,373 @@ +Mozilla Public License Version 2.0 +================================== + +1. Definitions +-------------- + +1.1. "Contributor" + means each individual or legal entity that creates, contributes to + the creation of, or owns Covered Software. + +1.2. "Contributor Version" + means the combination of the Contributions of others (if any) used + by a Contributor and that particular Contributor's Contribution. + +1.3. "Contribution" + means Covered Software of a particular Contributor. + +1.4. "Covered Software" + means Source Code Form to which the initial Contributor has attached + the notice in Exhibit A, the Executable Form of such Source Code + Form, and Modifications of such Source Code Form, in each case + including portions thereof. + +1.5. "Incompatible With Secondary Licenses" + means + + (a) that the initial Contributor has attached the notice described + in Exhibit B to the Covered Software; or + + (b) that the Covered Software was made available under the terms of + version 1.1 or earlier of the License, but not also under the + terms of a Secondary License. + +1.6. "Executable Form" + means any form of the work other than Source Code Form. + +1.7. "Larger Work" + means a work that combines Covered Software with other material, in + a separate file or files, that is not Covered Software. + +1.8. "License" + means this document. + +1.9. "Licensable" + means having the right to grant, to the maximum extent possible, + whether at the time of the initial grant or subsequently, any and + all of the rights conveyed by this License. + +1.10. "Modifications" + means any of the following: + + (a) any file in Source Code Form that results from an addition to, + deletion from, or modification of the contents of Covered + Software; or + + (b) any new file in Source Code Form that contains any Covered + Software. + +1.11. "Patent Claims" of a Contributor + means any patent claim(s), including without limitation, method, + process, and apparatus claims, in any patent Licensable by such + Contributor that would be infringed, but for the grant of the + License, by the making, using, selling, offering for sale, having + made, import, or transfer of either its Contributions or its + Contributor Version. + +1.12. "Secondary License" + means either the GNU General Public License, Version 2.0, the GNU + Lesser General Public License, Version 2.1, the GNU Affero General + Public License, Version 3.0, or any later versions of those + licenses. + +1.13. "Source Code Form" + means the form of the work preferred for making modifications. + +1.14. "You" (or "Your") + means an individual or a legal entity exercising rights under this + License. For legal entities, "You" includes any entity that + controls, is controlled by, or is under common control with You. For + purposes of this definition, "control" means (a) the power, direct + or indirect, to cause the direction or management of such entity, + whether by contract or otherwise, or (b) ownership of more than + fifty percent (50%) of the outstanding shares or beneficial + ownership of such entity. + +2. License Grants and Conditions +-------------------------------- + +2.1. Grants + +Each Contributor hereby grants You a world-wide, royalty-free, +non-exclusive license: + +(a) under intellectual property rights (other than patent or trademark) + Licensable by such Contributor to use, reproduce, make available, + modify, display, perform, distribute, and otherwise exploit its + Contributions, either on an unmodified basis, with Modifications, or + as part of a Larger Work; and + +(b) under Patent Claims of such Contributor to make, use, sell, offer + for sale, have made, import, and otherwise transfer either its + Contributions or its Contributor Version. + +2.2. Effective Date + +The licenses granted in Section 2.1 with respect to any Contribution +become effective for each Contribution on the date the Contributor first +distributes such Contribution. + +2.3. Limitations on Grant Scope + +The licenses granted in this Section 2 are the only rights granted under +this License. No additional rights or licenses will be implied from the +distribution or licensing of Covered Software under this License. +Notwithstanding Section 2.1(b) above, no patent license is granted by a +Contributor: + +(a) for any code that a Contributor has removed from Covered Software; + or + +(b) for infringements caused by: (i) Your and any other third party's + modifications of Covered Software, or (ii) the combination of its + Contributions with other software (except as part of its Contributor + Version); or + +(c) under Patent Claims infringed by Covered Software in the absence of + its Contributions. + +This License does not grant any rights in the trademarks, service marks, +or logos of any Contributor (except as may be necessary to comply with +the notice requirements in Section 3.4). + +2.4. Subsequent Licenses + +No Contributor makes additional grants as a result of Your choice to +distribute the Covered Software under a subsequent version of this +License (see Section 10.2) or under the terms of a Secondary License (if +permitted under the terms of Section 3.3). + +2.5. Representation + +Each Contributor represents that the Contributor believes its +Contributions are its original creation(s) or it has sufficient rights +to grant the rights to its Contributions conveyed by this License. + +2.6. Fair Use + +This License is not intended to limit any rights You have under +applicable copyright doctrines of fair use, fair dealing, or other +equivalents. + +2.7. Conditions + +Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted +in Section 2.1. + +3. Responsibilities +------------------- + +3.1. Distribution of Source Form + +All distribution of Covered Software in Source Code Form, including any +Modifications that You create or to which You contribute, must be under +the terms of this License. You must inform recipients that the Source +Code Form of the Covered Software is governed by the terms of this +License, and how they can obtain a copy of this License. You may not +attempt to alter or restrict the recipients' rights in the Source Code +Form. + +3.2. Distribution of Executable Form + +If You distribute Covered Software in Executable Form then: + +(a) such Covered Software must also be made available in Source Code + Form, as described in Section 3.1, and You must inform recipients of + the Executable Form how they can obtain a copy of such Source Code + Form by reasonable means in a timely manner, at a charge no more + than the cost of distribution to the recipient; and + +(b) You may distribute such Executable Form under the terms of this + License, or sublicense it under different terms, provided that the + license for the Executable Form does not attempt to limit or alter + the recipients' rights in the Source Code Form under this License. + +3.3. Distribution of a Larger Work + +You may create and distribute a Larger Work under terms of Your choice, +provided that You also comply with the requirements of this License for +the Covered Software. If the Larger Work is a combination of Covered +Software with a work governed by one or more Secondary Licenses, and the +Covered Software is not Incompatible With Secondary Licenses, this +License permits You to additionally distribute such Covered Software +under the terms of such Secondary License(s), so that the recipient of +the Larger Work may, at their option, further distribute the Covered +Software under the terms of either this License or such Secondary +License(s). + +3.4. Notices + +You may not remove or alter the substance of any license notices +(including copyright notices, patent notices, disclaimers of warranty, +or limitations of liability) contained within the Source Code Form of +the Covered Software, except that You may alter any license notices to +the extent required to remedy known factual inaccuracies. + +3.5. Application of Additional Terms + +You may choose to offer, and to charge a fee for, warranty, support, +indemnity or liability obligations to one or more recipients of Covered +Software. However, You may do so only on Your own behalf, and not on +behalf of any Contributor. You must make it absolutely clear that any +such warranty, support, indemnity, or liability obligation is offered by +You alone, and You hereby agree to indemnify every Contributor for any +liability incurred by such Contributor as a result of warranty, support, +indemnity or liability terms You offer. You may include additional +disclaimers of warranty and limitations of liability specific to any +jurisdiction. + +4. Inability to Comply Due to Statute or Regulation +--------------------------------------------------- + +If it is impossible for You to comply with any of the terms of this +License with respect to some or all of the Covered Software due to +statute, judicial order, or regulation then You must: (a) comply with +the terms of this License to the maximum extent possible; and (b) +describe the limitations and the code they affect. Such description must +be placed in a text file included with all distributions of the Covered +Software under this License. Except to the extent prohibited by statute +or regulation, such description must be sufficiently detailed for a +recipient of ordinary skill to be able to understand it. + +5. Termination +-------------- + +5.1. The rights granted under this License will terminate automatically +if You fail to comply with any of its terms. However, if You become +compliant, then the rights granted under this License from a particular +Contributor are reinstated (a) provisionally, unless and until such +Contributor explicitly and finally terminates Your grants, and (b) on an +ongoing basis, if such Contributor fails to notify You of the +non-compliance by some reasonable means prior to 60 days after You have +come back into compliance. Moreover, Your grants from a particular +Contributor are reinstated on an ongoing basis if such Contributor +notifies You of the non-compliance by some reasonable means, this is the +first time You have received notice of non-compliance with this License +from such Contributor, and You become compliant prior to 30 days after +Your receipt of the notice. + +5.2. If You initiate litigation against any entity by asserting a patent +infringement claim (excluding declaratory judgment actions, +counter-claims, and cross-claims) alleging that a Contributor Version +directly or indirectly infringes any patent, then the rights granted to +You by any and all Contributors for the Covered Software under Section +2.1 of this License shall terminate. + +5.3. In the event of termination under Sections 5.1 or 5.2 above, all +end user license agreements (excluding distributors and resellers) which +have been validly granted by You or Your distributors under this License +prior to termination shall survive termination. + +************************************************************************ +* * +* 6. Disclaimer of Warranty * +* ------------------------- * +* * +* Covered Software is provided under this License on an "as is" * +* basis, without warranty of any kind, either expressed, implied, or * +* statutory, including, without limitation, warranties that the * +* Covered Software is free of defects, merchantable, fit for a * +* particular purpose or non-infringing. The entire risk as to the * +* quality and performance of the Covered Software is with You. * +* Should any Covered Software prove defective in any respect, You * +* (not any Contributor) assume the cost of any necessary servicing, * +* repair, or correction. This disclaimer of warranty constitutes an * +* essential part of this License. No use of any Covered Software is * +* authorized under this License except under this disclaimer. * +* * +************************************************************************ + +************************************************************************ +* * +* 7. Limitation of Liability * +* -------------------------- * +* * +* Under no circumstances and under no legal theory, whether tort * +* (including negligence), contract, or otherwise, shall any * +* Contributor, or anyone who distributes Covered Software as * +* permitted above, be liable to You for any direct, indirect, * +* special, incidental, or consequential damages of any character * +* including, without limitation, damages for lost profits, loss of * +* goodwill, work stoppage, computer failure or malfunction, or any * +* and all other commercial damages or losses, even if such party * +* shall have been informed of the possibility of such damages. This * +* limitation of liability shall not apply to liability for death or * +* personal injury resulting from such party's negligence to the * +* extent applicable law prohibits such limitation. Some * +* jurisdictions do not allow the exclusion or limitation of * +* incidental or consequential damages, so this exclusion and * +* limitation may not apply to You. * +* * +************************************************************************ + +8. Litigation +------------- + +Any litigation relating to this License may be brought only in the +courts of a jurisdiction where the defendant maintains its principal +place of business and such litigation shall be governed by laws of that +jurisdiction, without reference to its conflict-of-law provisions. +Nothing in this Section shall prevent a party's ability to bring +cross-claims or counter-claims. + +9. Miscellaneous +---------------- + +This License represents the complete agreement concerning the subject +matter hereof. If any provision of this License is held to be +unenforceable, such provision shall be reformed only to the extent +necessary to make it enforceable. Any law or regulation which provides +that the language of a contract shall be construed against the drafter +shall not be used to construe this License against a Contributor. + +10. Versions of the License +--------------------------- + +10.1. New Versions + +Mozilla Foundation is the license steward. Except as provided in Section +10.3, no one other than the license steward has the right to modify or +publish new versions of this License. Each version will be given a +distinguishing version number. + +10.2. Effect of New Versions + +You may distribute the Covered Software under the terms of the version +of the License under which You originally received the Covered Software, +or under the terms of any subsequent version published by the license +steward. + +10.3. Modified Versions + +If you create software not governed by this License, and you want to +create a new license for such software, you may create and use a +modified version of this License if you rename the license and remove +any references to the name of the license steward (except to note that +such modified license differs from this License). + +10.4. Distributing Source Code Form that is Incompatible With Secondary +Licenses + +If You choose to distribute Source Code Form that is Incompatible With +Secondary Licenses under the terms of this version of the License, the +notice described in Exhibit B of this License must be attached. + +Exhibit A - Source Code Form License Notice +------------------------------------------- + + This Source Code Form is subject to the terms of the Mozilla Public + License, v. 2.0. If a copy of the MPL was not distributed with this + file, You can obtain one at https://mozilla.org/MPL/2.0/. + +If it is not possible or desirable to put the notice in a particular +file, then You may include the notice in a location (such as a LICENSE +file in a relevant directory) where a recipient would be likely to look +for such a notice. + +You may add additional accurate notices of copyright ownership. + +Exhibit B - "Incompatible With Secondary Licenses" Notice +--------------------------------------------------------- + + This Source Code Form is "Incompatible With Secondary Licenses", as + defined by the Mozilla Public License, v. 2.0. \ No newline at end of file diff --git a/LICENSE-OLD b/LICENSE-OLD new file mode 100644 index 0000000000..d584925892 --- /dev/null +++ b/LICENSE-OLD @@ -0,0 +1,22 @@ +The MIT License (MIT) + +Copyright (c) 2015 Mike Santiago +Copyright (c) 2016-2023 DSharpPlus Development Team + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/readme.md b/readme.md new file mode 100644 index 0000000000..b375d28828 --- /dev/null +++ b/readme.md @@ -0,0 +1,14 @@ +# DSharpPlus, version 6 + +DSharpPlus v6 is a ground-up rewrite of the library, focused on performance, modernity, maintainability and correctness. +Development of this version is occurring simultaneously with development of DSharpPlus v5, and is tracked on this branch, +while DSharpPlus v5 is tracked on the master branch. + +## Licensing + +DSharpPlus is based off DiscordSharp, whose license can be found [here](./DiscordSharp.LICENSE). + +DSharpPlus, up to version 5.x, uses the MIT License, which can be found [here](./LICENSE-OLD) + +DSharpPlus, starting with version 6.x, uses the Mozilla Public License, v2.0, which can be found [here](./LICENSE). +This version does not contain any code from previous versions, and is built from ground up. \ No newline at end of file From 39b9b314e03548207efe748dc984fb90ca6ed21d Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Thu, 25 May 2023 11:37:30 +0200 Subject: [PATCH 002/323] codeowners --- .github/CODEOWNERS | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .github/CODEOWNERS diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 0000000000..5447741989 --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1,2 @@ +# for the time being, i want to be notified of every PR to v6 +/ akiraveliara \ No newline at end of file From dd4b8153710188f48f6efa452b25aeb013ba2c34 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Thu, 25 May 2023 18:20:29 +0200 Subject: [PATCH 003/323] fix pre-commit naming and fix codeowners --- .git-hooks/{pre-commit.sh => pre-commit} | 0 .github/CODEOWNERS | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename .git-hooks/{pre-commit.sh => pre-commit} (100%) diff --git a/.git-hooks/pre-commit.sh b/.git-hooks/pre-commit similarity index 100% rename from .git-hooks/pre-commit.sh rename to .git-hooks/pre-commit diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 5447741989..05cce13f4c 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1,2 +1,2 @@ # for the time being, i want to be notified of every PR to v6 -/ akiraveliara \ No newline at end of file +* @akiraveliara \ No newline at end of file From 46654746ec9a174fdf2ab76210a487f207c83663 Mon Sep 17 00:00:00 2001 From: Lunar Starstrum Date: Thu, 25 May 2023 14:38:36 -0500 Subject: [PATCH 004/323] Fix the poor XML that Aki butchered (#1562) * Fix the poor XML that Aki butchered * Resolve PR comments --- .gitignore | 3 ++ LICENSE-OLD => DSharpPlus.Old.License | 0 Directory.Build.props | 24 +++++++-------- Directory.Build.targets | 43 +++++++++++---------------- 4 files changed, 33 insertions(+), 37 deletions(-) rename LICENSE-OLD => DSharpPlus.Old.License (100%) diff --git a/.gitignore b/.gitignore index b54f76e6b9..2521118b54 100644 --- a/.gitignore +++ b/.gitignore @@ -405,3 +405,6 @@ DSharpPlus.Test/config.json # Docfx docs/_site + +# .NET 8 UseArtifactsOutput +.artifacts/ \ No newline at end of file diff --git a/LICENSE-OLD b/DSharpPlus.Old.License similarity index 100% rename from LICENSE-OLD rename to DSharpPlus.Old.License diff --git a/Directory.Build.props b/Directory.Build.props index ba8d4306cd..5cb52ef8dd 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -3,26 +3,26 @@ net8.0 enable 11 - Naamloos, afroraydude, DrCreo, Death, TiaqoY0, Axiom, Emzi0767, IDoEverything, Velvet, OoLunar, akiraveliara, DSharpPlus contributors - DSharpPlus Contributors - https://github.com/DSharpPlus/DSharpPlus - https://github.com/DSharpPlus/DSharpPlus - Git - MPL - dsharpplus.png - https://raw.githubusercontent.com/DSharpPlus/DSharpPlus/master/logo/dsharpplus.png True - CS1591 True - True true - - + true true true snupkg + + + Naamloos, afroraydude, DrCreo, Death, TiaqoY0, Axiom, Emzi0767, IDoEverything, Velvet, OoLunar, akiraveliara, DSharpPlus contributors + DSharpPlus Contributors + https://github.com/DSharpPlus/DSharpPlus + https://github.com/DSharpPlus/DSharpPlus + Git + MPL + dsharpplus.png + https://raw.githubusercontent.com/DSharpPlus/DSharpPlus/master/logo/dsharpplus.png + \ No newline at end of file diff --git a/Directory.Build.targets b/Directory.Build.targets index db9ece642b..554dde0eec 100644 --- a/Directory.Build.targets +++ b/Directory.Build.targets @@ -1,32 +1,25 @@ - - - + + + - <_ProjectReferenceWithExplicitPackageVersion - Include="@(ProjectReference->'%(FullPath)')" - Condition="'%(ProjectReference.PackageVersion)' != ''" /> - - <_ProjectReferenceWithExactPackageVersion - Include="@(ProjectReference->'%(FullPath)')" - Condition="'%(ProjectReference.ExactVersion)' == 'true'" /> - - <_ProjectReferenceWithReassignedVersion + <_ProjectReferenceWithExplicitPackageVersion + Condition="'%(ProjectReference.PackageVersion)' != ''" + Include="@(ProjectReference->'%(FullPath)')" /> + <_ProjectReferenceWithExactPackageVersion + Condition="'%(ProjectReference.ExactVersion)' == 'true'" + Include="@(ProjectReference->'%(FullPath)')" /> + <_ProjectReferenceWithReassignedVersion + Condition="'%(Identity)' != '' And '@(_ProjectReferencesWithVersions)' == '@(_ProjectReferenceWithExplicitPackageVersion)'" Include="@(_ProjectReferencesWithVersions)" - Condition="'%(Identity)' != '' And '@(_ProjectReferencesWithVersions)' == '@(_ProjectReferenceWithExplicitPackageVersion)'"> - - @(_ProjectReferenceWithExplicitPackageVersion->'%(PackageVersion)') - - - <_ProjectReferenceWithReassignedVersion + ProjectVersion="@(_ProjectReferenceWithExplicitPackageVersion->'%(PackageVersion)')" /> + <_ProjectReferenceWithReassignedVersion + Condition="'%(Identity)' != '' And '@(_ProjectReferencesWithVersions)' == '@(_ProjectReferenceWithExactPackageVersion)'" Include="@(_ProjectReferencesWithVersions)" - Condition="'%(Identity)' != '' And '@(_ProjectReferencesWithVersions)' == '@(_ProjectReferenceWithExactPackageVersion)'"> - - [@(_ProjectReferencesWithVersions->'%(ProjectVersion)')] - - - <_ProjectReferencesWithVersions Remove="@(_ProjectReferenceWithReassignedVersion)" /> - <_ProjectReferencesWithVersions Include="@(_ProjectReferenceWithReassignedVersion)" /> + ProjectVersion="@(_ProjectReferencesWithVersions->'%(ProjectVersion)')" /> + <_ProjectReferencesWithVersions + Include="@(_ProjectReferenceWithReassignedVersion)" + Remove="@(_ProjectReferenceWithReassignedVersion)" /> \ No newline at end of file From fbd607a79155086761ebb4887ccc0a580664e2a5 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Fri, 26 May 2023 13:18:39 +0200 Subject: [PATCH 005/323] readme works - add licensing notice for single-file publishing to the readme, as per #lib-development - add src/core readme detailing the contents of that directory - add DSharpPlus.Core.Models project --- DSharpPlus.sln | 8 ++++++++ readme.md | 7 ++++++- .../DSharpPlus.Core.Models.csproj | 8 ++++++++ src/core/readme.md | 13 +++++++++++++ 4 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 src/core/DSharpPlus.Core.Models/DSharpPlus.Core.Models.csproj create mode 100644 src/core/readme.md diff --git a/DSharpPlus.sln b/DSharpPlus.sln index 58ea566644..86e9d74f00 100644 --- a/DSharpPlus.sln +++ b/DSharpPlus.sln @@ -3,11 +3,19 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.0.31903.59 MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DSharpPlus.Core.Models", "src\core\DSharpPlus.Core.Models\DSharpPlus.Core.Models.csproj", "{FBCCE5A7-0E07-4FCF-B9BB-B913F5A17FB2}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU Release|Any CPU = Release|Any CPU EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {FBCCE5A7-0E07-4FCF-B9BB-B913F5A17FB2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FBCCE5A7-0E07-4FCF-B9BB-B913F5A17FB2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FBCCE5A7-0E07-4FCF-B9BB-B913F5A17FB2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FBCCE5A7-0E07-4FCF-B9BB-B913F5A17FB2}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection diff --git a/readme.md b/readme.md index b375d28828..47fd699aaa 100644 --- a/readme.md +++ b/readme.md @@ -11,4 +11,9 @@ DSharpPlus is based off DiscordSharp, whose license can be found [here](./Discor DSharpPlus, up to version 5.x, uses the MIT License, which can be found [here](./LICENSE-OLD) DSharpPlus, starting with version 6.x, uses the Mozilla Public License, v2.0, which can be found [here](./LICENSE). -This version does not contain any code from previous versions, and is built from ground up. \ No newline at end of file +This version does not contain any code from previous versions, and is built from ground up. + +Additionally, because DSharpPlus references LGPL libraries, single-file published distributions of applications using +DSharpPlus must in turn be licensed compatibly with LGPL. This is not applicable for undistributed applications or +applications distributed with multiple files, because only a single-file distribution is statically linked to LGPL +software and thus falls under the LGPL requirement of compatible licensing for statically linking code. diff --git a/src/core/DSharpPlus.Core.Models/DSharpPlus.Core.Models.csproj b/src/core/DSharpPlus.Core.Models/DSharpPlus.Core.Models.csproj new file mode 100644 index 0000000000..b506070ea0 --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/DSharpPlus.Core.Models.csproj @@ -0,0 +1,8 @@ + + + + 0.1.0 + $(Description) This package implements the serialization models mirroring the Discord API. + + + diff --git a/src/core/readme.md b/src/core/readme.md new file mode 100644 index 0000000000..dcffa6eebd --- /dev/null +++ b/src/core/readme.md @@ -0,0 +1,13 @@ +# DSharpPlus Core Library + +This directory is home to everything needed to build the DSharpPlus core library, that is, the user-facing +convenience library without extension libraries. This includes the serialization models, the REST abstractions +and implementation, the Gateway abstractions and implementation, as well as the libraries and tools needed to +wrap these components into a well-curated, convenient library for end users. + +These components are generally included privately in the main library. If end users wish to consume these libraries +directly, they must reference them directly, not transiently through our main library. + +Because it is impossible to type-forward from a privately included library, some libraries must be included +publicly. These libraries are, therefore, versioned with the main library, and they contain a notice mentioning +this fact. From a928c3edd6744fd02f6d00f7b7177e11fc140869 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Fri, 26 May 2023 16:52:45 +0200 Subject: [PATCH 006/323] add shared and model abstraction projects --- DSharpPlus.sln | 15 +++++++ Directory.Build.props | 9 ++++ Directory.Build.targets | 44 ++++++++++++------- ...DSharpPlus.Core.Abstractions.Models.csproj | 13 ++++++ .../DSharpPlus.Core.Models.csproj | 1 + .../DSharpPlus.Shared.csproj | 11 +++++ 6 files changed, 78 insertions(+), 15 deletions(-) create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/DSharpPlus.Core.Abstractions.Models.csproj create mode 100644 src/core/DSharpPlus.Shared/DSharpPlus.Shared.csproj diff --git a/DSharpPlus.sln b/DSharpPlus.sln index 86e9d74f00..6a78b23084 100644 --- a/DSharpPlus.sln +++ b/DSharpPlus.sln @@ -5,6 +5,10 @@ VisualStudioVersion = 17.0.31903.59 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DSharpPlus.Core.Models", "src\core\DSharpPlus.Core.Models\DSharpPlus.Core.Models.csproj", "{FBCCE5A7-0E07-4FCF-B9BB-B913F5A17FB2}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DSharpPlus.Shared", "src\core\DSharpPlus.Shared\DSharpPlus.Shared.csproj", "{964AD252-F077-4AB5-8D92-6C594D08F078}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DSharpPlus.Core.Abstractions.Models", "src\core\DSharpPlus.Core.Abstractions.Models\DSharpPlus.Core.Abstractions.Models.csproj", "{E14B0AE9-FE71-4DE4-BEB1-4A8E139DB84C}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -15,8 +19,19 @@ Global {FBCCE5A7-0E07-4FCF-B9BB-B913F5A17FB2}.Debug|Any CPU.Build.0 = Debug|Any CPU {FBCCE5A7-0E07-4FCF-B9BB-B913F5A17FB2}.Release|Any CPU.ActiveCfg = Release|Any CPU {FBCCE5A7-0E07-4FCF-B9BB-B913F5A17FB2}.Release|Any CPU.Build.0 = Release|Any CPU + {964AD252-F077-4AB5-8D92-6C594D08F078}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {964AD252-F077-4AB5-8D92-6C594D08F078}.Debug|Any CPU.Build.0 = Debug|Any CPU + {964AD252-F077-4AB5-8D92-6C594D08F078}.Release|Any CPU.ActiveCfg = Release|Any CPU + {964AD252-F077-4AB5-8D92-6C594D08F078}.Release|Any CPU.Build.0 = Release|Any CPU + {E14B0AE9-FE71-4DE4-BEB1-4A8E139DB84C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E14B0AE9-FE71-4DE4-BEB1-4A8E139DB84C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E14B0AE9-FE71-4DE4-BEB1-4A8E139DB84C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E14B0AE9-FE71-4DE4-BEB1-4A8E139DB84C}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {55CDA684-8900-479B-9DAE-BA3BE09B337B} + EndGlobalSection EndGlobal diff --git a/Directory.Build.props b/Directory.Build.props index 5cb52ef8dd..b17a3dee8b 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,22 +1,30 @@ + + net8.0 enable 11 True True + True true + + <_DSharpPlusReleaseVersion>6.0.0 + true true true snupkg + Naamloos, afroraydude, DrCreo, Death, TiaqoY0, Axiom, Emzi0767, IDoEverything, Velvet, OoLunar, akiraveliara, DSharpPlus contributors + A C# API for Discord based off DiscordSharp. DSharpPlus Contributors https://github.com/DSharpPlus/DSharpPlus https://github.com/DSharpPlus/DSharpPlus @@ -25,4 +33,5 @@ dsharpplus.png https://raw.githubusercontent.com/DSharpPlus/DSharpPlus/master/logo/dsharpplus.png + \ No newline at end of file diff --git a/Directory.Build.targets b/Directory.Build.targets index 554dde0eec..506d42e753 100644 --- a/Directory.Build.targets +++ b/Directory.Build.targets @@ -1,25 +1,39 @@ + - <_ProjectReferenceWithExplicitPackageVersion - Condition="'%(ProjectReference.PackageVersion)' != ''" - Include="@(ProjectReference->'%(FullPath)')" /> - <_ProjectReferenceWithExactPackageVersion - Condition="'%(ProjectReference.ExactVersion)' == 'true'" - Include="@(ProjectReference->'%(FullPath)')" /> - <_ProjectReferenceWithReassignedVersion - Condition="'%(Identity)' != '' And '@(_ProjectReferencesWithVersions)' == '@(_ProjectReferenceWithExplicitPackageVersion)'" + <_ProjectReferenceWithExplicitPackageVersion + Include="@(ProjectReference->'%(FullPath)')" + Condition="'%(ProjectReference.PackageVersion)' != ''" /> + + <_ProjectReferenceWithExactPackageVersion + Include="@(ProjectReference->'%(FullPath)')" + Condition="'%(ProjectReference.ExactVersion)' == 'true'" /> + + <_ProjectReferenceWithReassignedVersion Include="@(_ProjectReferencesWithVersions)" - ProjectVersion="@(_ProjectReferenceWithExplicitPackageVersion->'%(PackageVersion)')" /> - <_ProjectReferenceWithReassignedVersion - Condition="'%(Identity)' != '' And '@(_ProjectReferencesWithVersions)' == '@(_ProjectReferenceWithExactPackageVersion)'" + Condition="'%(Identity)' != '' And '@(_ProjectReferencesWithVersions)' == '@(_ProjectReferenceWithExplicitPackageVersion)'"> + + @(_ProjectReferenceWithExplicitPackageVersion->'%(PackageVersion)') + + + <_ProjectReferenceWithReassignedVersion Include="@(_ProjectReferencesWithVersions)" - ProjectVersion="@(_ProjectReferencesWithVersions->'%(ProjectVersion)')" /> - <_ProjectReferencesWithVersions - Include="@(_ProjectReferenceWithReassignedVersion)" - Remove="@(_ProjectReferenceWithReassignedVersion)" /> + Condition="'%(Identity)' != '' And '@(_ProjectReferencesWithVersions)' == '@(_ProjectReferenceWithExactPackageVersion)'"> + + [@(_ProjectReferencesWithVersions->'%(ProjectVersion)')] + + + <_ProjectReferencesWithVersions Remove="@(_ProjectReferenceWithReassignedVersion)" /> + <_ProjectReferencesWithVersions Include="@(_ProjectReferenceWithReassignedVersion)" /> + + + + $(_DSharpPlusReleaseVersion) + + \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/DSharpPlus.Core.Abstractions.Models.csproj b/src/core/DSharpPlus.Core.Abstractions.Models/DSharpPlus.Core.Abstractions.Models.csproj new file mode 100644 index 0000000000..ccfcffdf60 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/DSharpPlus.Core.Abstractions.Models.csproj @@ -0,0 +1,13 @@ + + + + 0.1.0 + $(Description) This package specifies a contract for the serialization models to implement. This definition is library-agnostic. + Library + + + + + + + diff --git a/src/core/DSharpPlus.Core.Models/DSharpPlus.Core.Models.csproj b/src/core/DSharpPlus.Core.Models/DSharpPlus.Core.Models.csproj index b506070ea0..9408be00b4 100644 --- a/src/core/DSharpPlus.Core.Models/DSharpPlus.Core.Models.csproj +++ b/src/core/DSharpPlus.Core.Models/DSharpPlus.Core.Models.csproj @@ -3,6 +3,7 @@ 0.1.0 $(Description) This package implements the serialization models mirroring the Discord API. + Library diff --git a/src/core/DSharpPlus.Shared/DSharpPlus.Shared.csproj b/src/core/DSharpPlus.Shared/DSharpPlus.Shared.csproj new file mode 100644 index 0000000000..4e6043f397 --- /dev/null +++ b/src/core/DSharpPlus.Shared/DSharpPlus.Shared.csproj @@ -0,0 +1,11 @@ + + + + true + $(Description) This package contains shared types between public-facing and internal implementation packages. + Library + + DSharpPlus + + + From 351d9d1d9c6e5f84095c288abee0213502b43d21 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Fri, 26 May 2023 19:19:46 +0200 Subject: [PATCH 007/323] IApplicationCommand and required types --- .editorconfig | 4 +- Directory.Build.props | 1 + Directory.Packages.props | 2 +- .../.editorconfig | 2 + .../IApplicationCommand.cs | 86 +++++++ .../IApplicationCommandOption.cs | 100 ++++++++ .../IApplicationCommandOptionChoice.cs | 30 +++ ...DSharpPlus.Core.Abstractions.Models.csproj | 4 + src/core/DSharpPlus.Shared/.editorconfig | 2 + .../DiscordApplicationCommandOptionType.cs | 51 ++++ .../DiscordApplicationCommandType.cs | 26 ++ .../Enums/Channels/DiscordChannelType.cs | 71 ++++++ .../Enums/DiscordPermissions.cs | 239 ++++++++++++++++++ src/core/DSharpPlus.Shared/Enums/readme.md | 2 + 14 files changed, 617 insertions(+), 3 deletions(-) create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/.editorconfig create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/ApplicationCommands/IApplicationCommand.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/ApplicationCommands/IApplicationCommandOption.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/ApplicationCommands/IApplicationCommandOptionChoice.cs create mode 100644 src/core/DSharpPlus.Shared/.editorconfig create mode 100644 src/core/DSharpPlus.Shared/Enums/ApplicationCommands/DiscordApplicationCommandOptionType.cs create mode 100644 src/core/DSharpPlus.Shared/Enums/ApplicationCommands/DiscordApplicationCommandType.cs create mode 100644 src/core/DSharpPlus.Shared/Enums/Channels/DiscordChannelType.cs create mode 100644 src/core/DSharpPlus.Shared/Enums/DiscordPermissions.cs create mode 100644 src/core/DSharpPlus.Shared/Enums/readme.md diff --git a/.editorconfig b/.editorconfig index 39b654635e..b292ee2172 100644 --- a/.editorconfig +++ b/.editorconfig @@ -41,7 +41,7 @@ dotnet_sort_system_directives_first = true:error dotnet_separate_import_directive_groups = true:error csharp_qualified_using_at_nested_scope = true:error # usings before namespace -dotnet_diagnostic.IDE0064.severity = none +csharp_using_directive_placement = outside_namespace:error # Using directive is unnecessary. dotnet_diagnostic.IDE0005.severity = error @@ -115,7 +115,7 @@ dotnet_naming_symbols.async_methods.required_modifiers = async # Force namespaces to match their folder names # We'll override this later in folders where we don't want this -dotnet_diagnostic.IDE0130.severity = none +dotnet_style_namespace_match_folder = true:error ############################### # C# Coding Conventions # diff --git a/Directory.Build.props b/Directory.Build.props index b17a3dee8b..f3069e897b 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -7,6 +7,7 @@ 11 True True + $(NoWarn);CS1591 True diff --git a/Directory.Packages.props b/Directory.Packages.props index c8cf792a02..82d79969d6 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -1,5 +1,5 @@ - + \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/.editorconfig b/src/core/DSharpPlus.Core.Abstractions.Models/.editorconfig new file mode 100644 index 0000000000..3e37f7b31f --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/.editorconfig @@ -0,0 +1,2 @@ +# don't force namespaces matching folder paths +dotnet_style_namespace_match_folder = false \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/ApplicationCommands/IApplicationCommand.cs b/src/core/DSharpPlus.Core.Abstractions.Models/ApplicationCommands/IApplicationCommand.cs new file mode 100644 index 0000000000..255fcd882e --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/ApplicationCommands/IApplicationCommand.cs @@ -0,0 +1,86 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Entities; + +using Remora.Rest.Core; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Represents an application command, either as a chat input, a message context menu or an user context +/// menu command. +/// +public interface IApplicationCommand +{ + /// + /// The snowflake identifier of this command. + /// + public Snowflake Id { get; } + + /// + /// The type of this command, default: . + /// + public Optional Type { get; } + + /// + /// The snowflake identifier of the application owning this command. + /// + public Snowflake ApplicationId { get; } + + /// + /// If this command is a guild command, the snowflake identifier of its home guild. + /// + public Optional GuildId { get; } + + /// + /// The name of this command, between 1 and 32 characters. + /// + public string Name { get; } + + /// + /// A localization dictionary for , with the keys being locales. + /// + public Optional?> NameLocalizations { get; } + + /// + /// If this command is a command, the + /// description of this command, between 1 and 100 characters. This is an empty string for all + /// other command types. + /// + public string Description { get; } + + /// + /// A localization dictionary for , with the keys being locales. + /// + public Optional?> DescriptionLocalizations { get; } + + /// + /// The parameters of this (chat input) command, up to 25. + /// + public Optional> Options { get; } + + /// + /// The permissions needed to gain default access to this command. + /// + public DiscordPermissions? DefaultMemberPermissions { get; } + + /// + /// Indicates whether this command is available in DMs with the app. This is only applicable + /// to globally-scoped commands. + /// + public Optional DmPermission { get; } + + /// + /// Indicates whether this command is age-restricted. + /// + public Optional Nsfw { get; } + + /// + /// An autoincrementing version identifier updated during substantial changes. + /// + public Snowflake Version { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/ApplicationCommands/IApplicationCommandOption.cs b/src/core/DSharpPlus.Core.Abstractions.Models/ApplicationCommands/IApplicationCommandOption.cs new file mode 100644 index 0000000000..d3b52758c1 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/ApplicationCommands/IApplicationCommandOption.cs @@ -0,0 +1,100 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Entities; + +using Remora.Rest.Core; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Represents a single option for a chat input application command. +/// +public interface IApplicationCommandOption +{ + /// + /// Signifies the type of this option. + /// + public DiscordApplicationCommandOptionType Type { get; } + + /// + /// The name of this option or subcommand, between 1 and 32 characters. + /// + public string Name { get; } + + /// + /// A localization dictionary for , with the keys being locales. + /// + public Optional?> NameLocalizations { get; } + + /// + /// The description of this option or subcommand, between 1 and 100 characters. + /// + public string Description { get; } + + /// + /// A localization dictionary for , with the keys being locales. + /// + public Optional?> DescriptionLocalizations { get; } + + /// + /// Specifies whether this parameter is required or optional, default: optional. + /// + public Optional Required { get; } + + /// + /// If this application command option is of , + /// or + /// , up to 25 options to choose from. + /// These options will be the only valid options for this command. + /// + public Optional> Choices { get; } + + /// + /// If this option is of or + /// , these options will be the + /// parameters (or subcommands if this is a subcommand group). + /// + public Optional> Options { get; } + + /// + /// If this option is of , shown + /// channels will be restricted to these types. + /// + public Optional> ChannelTypes { get; } + + /// + /// If this option is of or + /// , the minimum value permitted. + /// This is represented as a double here to avoid boxing when representing as object. + /// + public Optional MinValue { get; } + + /// + /// If this option is of or + /// , the maximum value permitted. + /// This is represented as a double here to avoid boxing when representing as object. + /// + public Optional MaxValue { get; } + + /// + /// If this option is of , the minimum + /// length permitted, between 0 and 6000. + /// + public Optional MinLength { get; } + + /// + /// If this option is of , the maximum + /// length permitted, between 1 and 6000. + /// + public Optional MaxLength { get; } + + /// + /// Indicates whether this option is subject to autocomplete. This is mutually exclusive with + /// being defined. + /// + public Optional Autocomplete { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/ApplicationCommands/IApplicationCommandOptionChoice.cs b/src/core/DSharpPlus.Core.Abstractions.Models/ApplicationCommands/IApplicationCommandOptionChoice.cs new file mode 100644 index 0000000000..50eaf67ceb --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/ApplicationCommands/IApplicationCommandOptionChoice.cs @@ -0,0 +1,30 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using Remora.Rest.Core; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Specifies one choice for a . +/// +public interface IApplicationCommandOptionChoice +{ + /// + /// The name of this choice, 1 to 100 characters. + /// + public string Name { get; } + + /// + /// A localization dictionary for , with the keys being locales. + /// + public Optional?> NameLocalizations { get; } + + /// + /// The value of this choice, up to 100 characters if this is a string. + /// + public object Value { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/DSharpPlus.Core.Abstractions.Models.csproj b/src/core/DSharpPlus.Core.Abstractions.Models/DSharpPlus.Core.Abstractions.Models.csproj index ccfcffdf60..8e5caf8e62 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/DSharpPlus.Core.Abstractions.Models.csproj +++ b/src/core/DSharpPlus.Core.Abstractions.Models/DSharpPlus.Core.Abstractions.Models.csproj @@ -6,6 +6,10 @@ Library + + + + diff --git a/src/core/DSharpPlus.Shared/.editorconfig b/src/core/DSharpPlus.Shared/.editorconfig new file mode 100644 index 0000000000..3e37f7b31f --- /dev/null +++ b/src/core/DSharpPlus.Shared/.editorconfig @@ -0,0 +1,2 @@ +# don't force namespaces matching folder paths +dotnet_style_namespace_match_folder = false \ No newline at end of file diff --git a/src/core/DSharpPlus.Shared/Enums/ApplicationCommands/DiscordApplicationCommandOptionType.cs b/src/core/DSharpPlus.Shared/Enums/ApplicationCommands/DiscordApplicationCommandOptionType.cs new file mode 100644 index 0000000000..ead585cccc --- /dev/null +++ b/src/core/DSharpPlus.Shared/Enums/ApplicationCommands/DiscordApplicationCommandOptionType.cs @@ -0,0 +1,51 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Entities; + +/// +/// Enumerates the valid types of an application command option. +/// +public enum DiscordApplicationCommandOptionType +{ + /// + /// This option signifies a subcommand of the parent command. + /// + SubCommand = 1, + + /// + /// This option signifies a group of subcommands of the parent command. + /// + SubCommandGroup, + + String, + + /// + /// Any integer between -2^53 and +2^53. + /// + Integer, + + Boolean, + + User, + + /// + /// By default, this includes all channel types + categories. + /// + Channel, + + Role, + + /// + /// This includes roles and users. + /// + Mentionable, + + /// + /// Any double-precision floating-point number between -2^53 and +2^53. + /// + Number, + + Attachment +} diff --git a/src/core/DSharpPlus.Shared/Enums/ApplicationCommands/DiscordApplicationCommandType.cs b/src/core/DSharpPlus.Shared/Enums/ApplicationCommands/DiscordApplicationCommandType.cs new file mode 100644 index 0000000000..e3ab0c0520 --- /dev/null +++ b/src/core/DSharpPlus.Shared/Enums/ApplicationCommands/DiscordApplicationCommandType.cs @@ -0,0 +1,26 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Entities; + +/// +/// Enumerates the possible application command types. +/// +public enum DiscordApplicationCommandType +{ + /// + /// Slash commands, text based commands that show up in the chat box. + /// + ChatInput = 1, + + /// + /// User context menu based commands. + /// + User, + + /// + /// Message context menu based commands. + /// + Message +} diff --git a/src/core/DSharpPlus.Shared/Enums/Channels/DiscordChannelType.cs b/src/core/DSharpPlus.Shared/Enums/Channels/DiscordChannelType.cs new file mode 100644 index 0000000000..3fc2739a57 --- /dev/null +++ b/src/core/DSharpPlus.Shared/Enums/Channels/DiscordChannelType.cs @@ -0,0 +1,71 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Entities; + +/// +/// Enumerates the valid types for a channel. +/// +public enum DiscordChannelType +{ + /// + /// A text channel within a guild. + /// + GuildText, + + /// + /// A direct message between users. + /// + Dm, + + /// + /// A voice channel within a guild. + /// + GuildVoice, + + /// + /// A direct message between multiple users. + /// + GroupDm, + + /// + /// A category channel within a guild that contains up to 50 channels. + /// + GuildCategory, + + /// + /// A channel that users can follow and crosspost into their own guilds. + /// + GuildAnnouncement, + + /// + /// A thread channel within an announcement channel. + /// + AnnouncementThread = 10, + + /// + /// A public thread channel in a text or forum channel. + /// + PublicThread, + + /// + /// A private thread channel in a text channel. + /// + PrivateThread, + + /// + /// A stage channel. + /// + GuildStageVoice, + + /// + /// A list of servers in a hub. + /// + GuildDirectory, + + /// + /// A channel that can only contain public threads. + /// + GuildForum +} diff --git a/src/core/DSharpPlus.Shared/Enums/DiscordPermissions.cs b/src/core/DSharpPlus.Shared/Enums/DiscordPermissions.cs new file mode 100644 index 0000000000..6b7ae4d84b --- /dev/null +++ b/src/core/DSharpPlus.Shared/Enums/DiscordPermissions.cs @@ -0,0 +1,239 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; + +namespace DSharpPlus.Entities; + +/// +/// Represents discord permissions - role permission, channel overwrites. +/// +[Flags] +public enum DiscordPermissions : ulong +{ + /// + /// No permissions. + /// + None = 0, + + /// + /// Allows members to create invites. + /// + CreateInvite = 1 << 0, + + /// + /// Allows members to kick others, limited by role hierarchy. + /// + KickMembers = 1 << 1, + + /// + /// Allows members to ban others, limited by role hierarchy. + /// + BanMembers = 1 << 2, + + /// + /// Administrator permission. Overrides every other permission, allows bypassing channel-specific restrictions. + /// + Administrator = 1 << 3, + + /// + /// Allows members to create, edit and delete channels. + /// + ManageChannels = 1 << 4, + + /// + /// Allows members to change (most) guild settings. + /// + ManageGuild = 1 << 5, + + /// + /// Allows members to add a reaction to a message. + /// + AddReactions = 1 << 6, + + /// + /// Allows members to access the guild's audit logs. + /// + ViewAuditLog = 1 << 7, + + /// + /// Allows members to use Priority Speaker functionality. + /// + PrioritySpeaker = 1 << 8, + + /// + /// Allows members to go live in voice channels. + /// + Stream = 1 << 9, + + /// + /// Allows members to view (read) channels. + /// + ViewChannel = 1 << 10, + + /// + /// Allows members to send messages in channels and to create threads in a forum channel. + /// + SendMessages = 1 << 11, + + /// + /// Allows members to send text-to-speech messages. + /// + SendTTSMessages = 1 << 12, + + /// + /// Allows members to delete other's messages. + /// + ManageMessages = 1 << 13, + + /// + /// Allows members' messages to embed sent links. + /// + EmbedLinks = 1 << 14, + + /// + /// Allows members to attach files. + /// + AttachFiles = 1 << 15, + + /// + /// Allows members to read a channels' message history. + /// + ReadMessageHistory = 1 << 16, + + /// + /// Allows members to mention @everyone, @here and all roles. + /// + MentionEveryone = 1 << 17, + + /// + /// Allows members to use emojis from other guilds. + /// + UseExternalEmojis = 1 << 18, + + /// + /// Allows members to access and view the Guild Insights menu. + /// + ViewGuildInsights = 1 << 19, + + /// + /// Allows members to connect to voice channels. + /// + Connect = 1 << 20, + + /// + /// Allows members to speak in voice channels. + /// + Speak = 1 << 21, + + /// + /// Allows members to mute others in voice channels. + /// + MuteMembers = 1 << 22, + + /// + /// Allows members to deafen others in voice channels. + /// + DeafenMembers = 1 << 23, + + /// + /// Allows members to move others between voice channels they have access to. + /// + MoveMembers = 1 << 24, + + /// + /// Allows members to use voice activity detection instead of push-to-talk. + /// + UseVoiceActivity = 1 << 25, + + /// + /// Allows members to change their own nickname. + /// + ChangeNickname = 1 << 26, + + /// + /// Allows members to change and remove other's nicknames. + /// + ManageNicknames = 1 << 27, + + /// + /// Allows members to create, change and grant roles lower than their highest role. + /// + ManageRoles = 1 << 28, + + /// + /// Allows members to create and delete webhooks. + /// + ManageWebhooks = 1 << 29, + + /// + /// Allows members to manage guild emojis and stickers. + /// + ManageEmojisStickers = 1 << 30, + + /// + /// Allows members to use slash and right-click commands. + /// + UseApplicationCommands = 1L << 31, + + /// + /// Allows members to request to speak in stage channels. + /// + RequestToSpeak = 1L << 32, + + /// + /// Allows members to create, edit and delete events. + /// + ManageEvents = 1L << 33, + + /// + /// Allows members to manage threads. + /// + ManageThreads = 1L << 34, + + /// + /// Allows members to create public threads. + /// + CreatePublicThreads = 1L << 35, + + /// + /// Allows members to create private threads. + /// + CreatePrivateThreads = 1L << 36, + + /// + /// Allows members to use stickers from other guilds. + /// + UseExternalStickers = 1L << 37, + + /// + /// Allows members to send messages in threads. + /// + SendThreadMessages = 1L << 38, + + /// + /// Allows members to start embedded activities. + /// + StartEmbeddedActivities = 1L << 39, + + /// + /// Allows members to time out other members. + /// + ModerateMembers = 1L << 40, + + /// + /// Allows members to view role subscription insights. + /// + ViewCreatorMonetizationAnalytics = 1L << 41, + + /// + /// Allows members to use the soundboard in a voice channel. + /// + UseSoundboard = 1L << 42, + + /// + /// Allows members to send voice messages. + /// + SendVoiceMessages = 1L << 46 +} diff --git a/src/core/DSharpPlus.Shared/Enums/readme.md b/src/core/DSharpPlus.Shared/Enums/readme.md new file mode 100644 index 0000000000..bf2ec7b8f0 --- /dev/null +++ b/src/core/DSharpPlus.Shared/Enums/readme.md @@ -0,0 +1,2 @@ +Enums located here live in the namespace DSharpPlus.Entities. This is because we reuse them later +in the public-facing library for our entities, and want to keep them in the same namespace. \ No newline at end of file From 413193bd3c8c2ec34b9ca0a8311d1f37ef01f1c2 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Fri, 26 May 2023 19:41:46 +0200 Subject: [PATCH 008/323] application commands and related objects --- .../IApplicationCommandPermission.cs | 34 ++++++++++++++++++ .../IApplicationCommandPermissions.cs | 35 +++++++++++++++++++ ...DiscordApplicationCommandPermissionType.cs | 15 ++++++++ 3 files changed, 84 insertions(+) create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/ApplicationCommands/IApplicationCommandPermission.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/ApplicationCommands/IApplicationCommandPermissions.cs create mode 100644 src/core/DSharpPlus.Shared/Enums/ApplicationCommands/DiscordApplicationCommandPermissionType.cs diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/ApplicationCommands/IApplicationCommandPermission.cs b/src/core/DSharpPlus.Core.Abstractions.Models/ApplicationCommands/IApplicationCommandPermission.cs new file mode 100644 index 0000000000..616c8ade57 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/ApplicationCommands/IApplicationCommandPermission.cs @@ -0,0 +1,34 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Entities; + +using Remora.Rest.Core; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Represents a single permission override for an application command inside a guild. +/// +public interface IApplicationCommandPermission +{ + /// + /// The snowflake identifier of the target of this override, or a permission constant. + /// + /// + /// The snowflake identifier of the current guild targets the @everyone role, the + /// snowflake identifier - 1 targets all channels in the guild. + /// + public Snowflake Id { get; } + + /// + /// The type of the entity this override targets. + /// + public DiscordApplicationCommandPermissionType Type { get; } + + /// + /// Indicates whether this command is allowed or not. + /// + public bool Permission { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/ApplicationCommands/IApplicationCommandPermissions.cs b/src/core/DSharpPlus.Core.Abstractions.Models/ApplicationCommands/IApplicationCommandPermissions.cs new file mode 100644 index 0000000000..6bcefbe084 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/ApplicationCommands/IApplicationCommandPermissions.cs @@ -0,0 +1,35 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using Remora.Rest.Core; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Represents a collection of permissions for an application command in a guild +/// +public interface IApplicationCommandPermissions +{ + /// + /// The snowflake identifier of this command. + /// + public Snowflake Id { get; } + + /// + /// The snowflake identifier of the application this command belongs to. + /// + public Snowflake ApplicationId { get; } + + /// + /// The snowflake identifier of the guild to which these permissions apply. + /// + public Snowflake GuildId { get; } + + /// + /// The permission overrides for this command in this guild. + /// + public IReadOnlyList Permissions { get; } +} diff --git a/src/core/DSharpPlus.Shared/Enums/ApplicationCommands/DiscordApplicationCommandPermissionType.cs b/src/core/DSharpPlus.Shared/Enums/ApplicationCommands/DiscordApplicationCommandPermissionType.cs new file mode 100644 index 0000000000..30f1dad338 --- /dev/null +++ b/src/core/DSharpPlus.Shared/Enums/ApplicationCommands/DiscordApplicationCommandPermissionType.cs @@ -0,0 +1,15 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Entities; + +/// +/// Lists the different targets for an application command permission override. +/// +public enum DiscordApplicationCommandPermissionType +{ + Role = 1, + User, + Channel +} From a8e3391e65d83cde31b08469f5a9cb3c9f5a1f19 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Fri, 26 May 2023 22:20:11 +0200 Subject: [PATCH 009/323] action rows and buttons --- .../Emojis/IPartialEmoji.cs | 56 +++++++++++ .../MessageComponents/IActionRowComponent.cs | 25 +++++ .../MessageComponents/IButtonComponent.cs | 46 +++++++++ .../IInteractiveComponent.cs | 18 ++++ .../Users/IUser.cs | 90 ++++++++++++++++++ .../MessageComponents/DiscordButtonStyle.cs | 36 +++++++ .../MessageComponents/DiscordComponentType.cs | 51 ++++++++++ .../Enums/Users/DiscordPremiumType.cs | 16 ++++ .../Enums/Users/DiscordUserFlags.cs | 95 +++++++++++++++++++ 9 files changed, 433 insertions(+) create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/Emojis/IPartialEmoji.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IActionRowComponent.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IButtonComponent.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IInteractiveComponent.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/Users/IUser.cs create mode 100644 src/core/DSharpPlus.Shared/Enums/MessageComponents/DiscordButtonStyle.cs create mode 100644 src/core/DSharpPlus.Shared/Enums/MessageComponents/DiscordComponentType.cs create mode 100644 src/core/DSharpPlus.Shared/Enums/Users/DiscordPremiumType.cs create mode 100644 src/core/DSharpPlus.Shared/Enums/Users/DiscordUserFlags.cs diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Emojis/IPartialEmoji.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Emojis/IPartialEmoji.cs new file mode 100644 index 0000000000..d762b9ee0f --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Emojis/IPartialEmoji.cs @@ -0,0 +1,56 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using Remora.Rest.Core; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Represents a partial emoji object, where any or all properties may be missing. +/// +public interface IPartialEmoji +{ + /// + /// The snowflake identifier of this emoji, if it belongs to a guild. + /// + public Optional Id { get; } + + /// + /// The name of this emoji. + /// + public Optional Name { get; } + + /// + /// A list of roles allowed to use this emoji, if applicable. + /// + public Optional> Roles { get; } + + /// + /// The user who created this emoji. + /// + public Optional User { get; } + + /// + /// Indicates whether this emoji requires to be wrapped in colons. + /// + public Optional RequireColons { get; } + + /// + /// Indicates whether this emoji is managed by an app. + /// + public Optional Managed { get; } + + /// + /// Indicates whether this emoji is an animated emoji. Animated emojis have an a prefix in text form. + /// + public Optional Animated { get; } + + /// + /// Indicates whether this emoji is currently available for use. This may be false when losing server + /// boosts. + /// + public Optional Available { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IActionRowComponent.cs b/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IActionRowComponent.cs new file mode 100644 index 0000000000..1f26dfbfe8 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IActionRowComponent.cs @@ -0,0 +1,25 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Entities; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Represents a container component for other components. +/// +public interface IActionRowComponent +{ + /// + /// + /// + public DiscordComponentType Type { get; } + + /// + /// The child components of this action row: up to five buttons, or one non-button component. + /// + public IReadOnlyList Components { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IButtonComponent.cs b/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IButtonComponent.cs new file mode 100644 index 0000000000..8c5ed2244f --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IButtonComponent.cs @@ -0,0 +1,46 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Entities; + +using Remora.Rest.Core; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Represents a button attached to a message. +/// +public interface IButtonComponent : IInteractiveComponent +{ + /// + /// The visual style of this button. + /// + public DiscordButtonStyle Style { get; } + + /// + /// The text to render on this button, up to 80 characters. + /// + public Optional Label { get; } + + /// + /// The emoji to render on this button, if any. + /// + public Optional Emoji { get; } + + /// + /// A developer-defined identifier for this button, up to 100 characters. This is mutually + /// exclusive with . + /// + public Optional CustomId { get; } + + /// + /// An URL for link-style buttons. This is mutually exclusive with . + /// + public Optional Url { get; } + + /// + /// Indicates whether this button is disabled, default false. + /// + public Optional Disabled { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IInteractiveComponent.cs b/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IInteractiveComponent.cs new file mode 100644 index 0000000000..bbdef8a132 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IInteractiveComponent.cs @@ -0,0 +1,18 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Entities; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Represents a message component that users can interact with. +/// +public interface IInteractiveComponent +{ + /// + /// The type of this component. + /// + public DiscordComponentType Type { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Users/IUser.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Users/IUser.cs new file mode 100644 index 0000000000..3cbdb213a8 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Users/IUser.cs @@ -0,0 +1,90 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Entities; + +using Remora.Rest.Core; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Represents an user object. +/// +public interface IUser +{ + /// + /// The snowflake identifier of this user. + /// + public Snowflake Id { get; } + + /// + /// The username of this user, unique across the platform. + /// + public string Username { get; } + + /// + /// The global display name of this user. + /// + public string? GlobalName { get; } + + /// + /// The user's avatar hash. + /// + public string? Avatar { get; } + + /// + /// Indicates whether this user is a bot user. + /// + public Optional Bot { get; } + + /// + /// Indicates whether this user is part of Discords urgent message system. + /// + public Optional System { get; } + + /// + /// Indicates whether this user has multi-factor authentication enabled on their account. + /// + public Optional MfaEnabled { get; } + + /// + /// The user's banner hash. + /// + public Optional Banner { get; } + + /// + /// The user's banner color code. + /// + public Optional AccentColor { get; } + + /// + /// The user's chosen language option. + /// + public Optional Locale { get; } + + /// + /// Indicates whether the email address linked to this user account has been verified. + /// + public Optional Verified { get; } + + /// + /// The user's email address. + /// + public Optional Email { get; } + + /// + /// The flags on this user's account. + /// + public Optional Flags { get; } + + /// + /// The level of nitro subscription on this user's account. + /// + public Optional PremiumType { get; } + + /// + /// The publicly visible flags on this user's account. + /// + public Optional PublicFlags { get; } +} diff --git a/src/core/DSharpPlus.Shared/Enums/MessageComponents/DiscordButtonStyle.cs b/src/core/DSharpPlus.Shared/Enums/MessageComponents/DiscordButtonStyle.cs new file mode 100644 index 0000000000..9fd09778b8 --- /dev/null +++ b/src/core/DSharpPlus.Shared/Enums/MessageComponents/DiscordButtonStyle.cs @@ -0,0 +1,36 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Entities; + +/// +/// Enumerates different display styles for buttons. +/// +public enum DiscordButtonStyle +{ + /// + /// A discord-blurple button. + /// + Primary = 1, + + /// + /// A gray button. + /// + Secondary, + + /// + /// A green button. + /// + Success, + + /// + /// A red button. + /// + Danger, + + /// + /// A gray button, navigating to an URL. + /// + Link +} diff --git a/src/core/DSharpPlus.Shared/Enums/MessageComponents/DiscordComponentType.cs b/src/core/DSharpPlus.Shared/Enums/MessageComponents/DiscordComponentType.cs new file mode 100644 index 0000000000..a749efe70b --- /dev/null +++ b/src/core/DSharpPlus.Shared/Enums/MessageComponents/DiscordComponentType.cs @@ -0,0 +1,51 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Entities; + +/// +/// Enumerates the different types of message components. +/// +public enum DiscordComponentType +{ + /// + /// A container for other components: up to five button or one non-button component. + /// + ActionRow = 1, + + /// + /// A clickable button component. + /// + Button, + + /// + /// A select menu for picking from application-defined text options. + /// + StringSelect, + + /// + /// A text input field. + /// + TextInput, + + /// + /// A select menu for picking from users. + /// + UserSelect, + + /// + /// A select menu for picking from roles. + /// + RoleSelect, + + /// + /// A select menu for picking from mentionable entities (users and roles). + /// + MentionableSelect, + + /// + /// A select menu for picking from channels. + /// + ChannelSelect +} diff --git a/src/core/DSharpPlus.Shared/Enums/Users/DiscordPremiumType.cs b/src/core/DSharpPlus.Shared/Enums/Users/DiscordPremiumType.cs new file mode 100644 index 0000000000..407d0055f4 --- /dev/null +++ b/src/core/DSharpPlus.Shared/Enums/Users/DiscordPremiumType.cs @@ -0,0 +1,16 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Entities; + +/// +/// Enumerates the valid nitro levels an user has. +/// +public enum DiscordPremiumType +{ + None, + NitroClassic, + Nitro, + NitroBasic +} diff --git a/src/core/DSharpPlus.Shared/Enums/Users/DiscordUserFlags.cs b/src/core/DSharpPlus.Shared/Enums/Users/DiscordUserFlags.cs new file mode 100644 index 0000000000..1fe56566c8 --- /dev/null +++ b/src/core/DSharpPlus.Shared/Enums/Users/DiscordUserFlags.cs @@ -0,0 +1,95 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; + +namespace DSharpPlus.Entities; + +/// +/// Enumerates all exposed and documented user flags. +/// +[Flags] +public enum DiscordUserFlags +{ + /// + /// None. + /// + None = 0, + + /// + /// Profile badge indicating this user is a Discord employee. + /// + DiscordEmployee = 1 << 0, + + /// + /// Profile badge indicating this user owns a Partnered server. + /// + PartneredServerOwner = 1 << 1, + + /// + /// Profile badge indicating this user has attended a real-world HypeSquad event. + /// + HypeSquadEvents = 1 << 2, + + /// + /// First of two badges for bug hunters. Discord doesn't tell us any further information. + /// + BugHunterLevel1 = 1 << 3, + + /// + /// Profile badge indicating this user is a member of the HypeSquad House of Bravery. + /// + HouseBravery = 1 << 6, + + /// + /// Profile badge indicating this user is a member of the Hypesquad House of Brilliance. + /// + HouseBrilliance = 1 << 7, + + /// + /// Profile badge indicating this user is a member of the HypeSquad House of Balance. + /// + HouseBalance = 1 << 8, + + /// + /// Profile badge indicating this user has purchased Nitro before 10/10/2018. + /// + EarlySupporter = 1 << 9, + + /// + /// Profile badge indicating... what, exactly? Discord doesn't tell us. + /// + TeamUser = 1 << 10, + + /// + /// Bug hunter badge, Level 2 + /// + BugHunterLevel2 = 1 << 14, + + /// + /// Profile badge indicating this bot is a verified bot. + /// + VerifiedBot = 1 << 16, + + /// + /// Profile badge indicating this user has developed a bot which obtained verification before Discord + /// stopped giving out the badge. + /// + EarlyVerifiedBotDeveloper = 1 << 17, + + /// + /// Profile badge indicating this user has passed Discord's Moderator Exam. + /// + DiscordCertifiedModerator = 1 << 18, + + /// + /// Bot that uses only HTTP interactions and is thus shown in the online member list. + /// + BotHttpInteractions = 1 << 19, + + /// + /// Profile badge indicating that this user meets the requirements for Discord's active developer badge. + /// + ActiveDeveloper = 1 << 22 +} From ccbfb3875dc977db8f460fdd5bb129308ad2765b Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Tue, 30 May 2023 17:21:15 +0200 Subject: [PATCH 010/323] select menus --- .../IChannelSelectComponent.cs | 48 +++++++++++++++++++ .../IMentionableSelectComponent.cs | 38 +++++++++++++++ .../MessageComponents/IRoleSelectComponent.cs | 38 +++++++++++++++ .../MessageComponents/ISelectOption.cs | 38 +++++++++++++++ .../IStringSelectComponent.cs | 45 +++++++++++++++++ .../MessageComponents/IUserSelectComponent.cs | 38 +++++++++++++++ 6 files changed, 245 insertions(+) create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IChannelSelectComponent.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IMentionableSelectComponent.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IRoleSelectComponent.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/ISelectOption.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IStringSelectComponent.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IUserSelectComponent.cs diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IChannelSelectComponent.cs b/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IChannelSelectComponent.cs new file mode 100644 index 0000000000..0dc5c40ef3 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IChannelSelectComponent.cs @@ -0,0 +1,48 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Entities; + +using Remora.Rest.Core; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Represents a dropdown menu from where users can select discord-supplied channels, +/// optionally restricted by channel type. +/// +public interface IChannelSelectComponent : IInteractiveComponent +{ + /// + /// The developer-defined ID for this select menu, up to 100 characters. + /// + public string CustomId { get; } + + /// + /// The channel types by which to filter listed channels. + /// + public IReadOnlyList ChannelTypes { get; } + + /// + /// Placeholder text if nothing is selected, up to 150 characters. + /// + public Optional Placeholder { get; } + + /// + /// The minimum number of items that must be chosen, between 0 and 25. + /// + public Optional MinValues { get; } + + /// + /// The maximum number of items that can be chosen, between 1 and 25. + /// + public Optional MaxValues { get; } + + /// + /// Indicates whether this select menu is disabled. + /// + public Optional Disabled { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IMentionableSelectComponent.cs b/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IMentionableSelectComponent.cs new file mode 100644 index 0000000000..c8ee8c8e42 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IMentionableSelectComponent.cs @@ -0,0 +1,38 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using Remora.Rest.Core; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Represents a dropdown menu from where users can select discord-supplied users and roles. +/// +public interface IMentionableSelectComponent : IInteractiveComponent +{ + /// + /// The developer-defined ID for this select menu, up to 100 characters. + /// + public string CustomId { get; } + + /// + /// Placeholder text if nothing is selected, up to 150 characters. + /// + public Optional Placeholder { get; } + + /// + /// The minimum number of items that must be chosen, between 0 and 25. + /// + public Optional MinValues { get; } + + /// + /// The maximum number of items that can be chosen, between 1 and 25. + /// + public Optional MaxValues { get; } + + /// + /// Indicates whether this select menu is disabled. + /// + public Optional Disabled { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IRoleSelectComponent.cs b/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IRoleSelectComponent.cs new file mode 100644 index 0000000000..b51055cdcd --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IRoleSelectComponent.cs @@ -0,0 +1,38 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using Remora.Rest.Core; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Represents a dropdown menu from where users can select discord-supplied roles. +/// +public interface IRoleSelectComponent : IInteractiveComponent +{ + /// + /// The developer-defined ID for this select menu, up to 100 characters. + /// + public string CustomId { get; } + + /// + /// Placeholder text if nothing is selected, up to 150 characters. + /// + public Optional Placeholder { get; } + + /// + /// The minimum number of items that must be chosen, between 0 and 25. + /// + public Optional MinValues { get; } + + /// + /// The maximum number of items that can be chosen, between 1 and 25. + /// + public Optional MaxValues { get; } + + /// + /// Indicates whether this select menu is disabled. + /// + public Optional Disabled { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/ISelectOption.cs b/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/ISelectOption.cs new file mode 100644 index 0000000000..3c8c0d162e --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/ISelectOption.cs @@ -0,0 +1,38 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using Remora.Rest.Core; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Represents a single text option in a . +/// +public interface ISelectOption +{ + /// + /// The user-facing name of this option, up to 100 characters. + /// + public string Label { get; } + + /// + /// The developer-defined value of this option, up to 100 characters. + /// + public string Value { get; } + + /// + /// An additional description of this option, up to 100 characters. + /// + public Optional Description { get; } + + /// + /// The emoji to render with this option + /// + public Optional Emoji { get; } + + /// + /// Indicates whether this option will be selected by default. + /// + public Optional Default { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IStringSelectComponent.cs b/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IStringSelectComponent.cs new file mode 100644 index 0000000000..5d60b1caf7 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IStringSelectComponent.cs @@ -0,0 +1,45 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using Remora.Rest.Core; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Represents a dropdown menu from where users can select dev-supplied strings. +/// +public interface IStringSelectComponent : IInteractiveComponent +{ + /// + /// The developer-defined ID for this select menu, up to 100 characters. + /// + public string CustomId { get; } + + /// + /// Up to 25 specified choices for this select menu. + /// + public IReadOnlyList Options { get; } + + /// + /// Placeholder text if nothing is selected, up to 150 characters. + /// + public Optional Placeholder { get; } + + /// + /// The minimum number of items that must be chosen, between 0 and 25. + /// + public Optional MinValues { get; } + + /// + /// The maximum number of items that can be chosen, between 1 and 25. + /// + public Optional MaxValues { get; } + + /// + /// Indicates whether this select menu is disabled. + /// + public Optional Disabled { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IUserSelectComponent.cs b/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IUserSelectComponent.cs new file mode 100644 index 0000000000..2279ad8b28 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IUserSelectComponent.cs @@ -0,0 +1,38 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using Remora.Rest.Core; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Represents a dropdown menu from where users can select discord-supplied users. +/// +public interface IUserSelectComponent : IInteractiveComponent +{ + /// + /// The developer-defined ID for this select menu, up to 100 characters. + /// + public string CustomId { get; } + + /// + /// Placeholder text if nothing is selected, up to 150 characters. + /// + public Optional Placeholder { get; } + + /// + /// The minimum number of items that must be chosen, between 0 and 25. + /// + public Optional MinValues { get; } + + /// + /// The maximum number of items that can be chosen, between 1 and 25. + /// + public Optional MaxValues { get; } + + /// + /// Indicates whether this select menu is disabled. + /// + public Optional Disabled { get; } +} From 3be09edcbd882f30d0546f5956c4be0527621ff9 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Tue, 30 May 2023 17:34:06 +0200 Subject: [PATCH 011/323] text input fields --- .../MessageComponents/ITextInputComponent.cs | 55 +++++++++++++++++++ .../DiscordTextInputStyle.cs | 21 +++++++ 2 files changed, 76 insertions(+) create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/ITextInputComponent.cs create mode 100644 src/core/DSharpPlus.Shared/Enums/MessageComponents/DiscordTextInputStyle.cs diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/ITextInputComponent.cs b/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/ITextInputComponent.cs new file mode 100644 index 0000000000..52a64ff159 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/ITextInputComponent.cs @@ -0,0 +1,55 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Entities; + +using Remora.Rest.Core; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Represents a text input field in a modal. +/// +public interface ITextInputComponent : IInteractiveComponent +{ + /// + /// The identifier of this input field, up to 100 characters. + /// + public string CustomId { get; } + + /// + /// Indicates whether this input field requests short-form or long-form input. + /// + public DiscordTextInputStyle Style { get; } + + /// + /// The label of this input field, up to 45 charcters. + /// + public string Label { get; } + + /// + /// The minimum length for a text input, between 0 and 4000 characters. + /// + public Optional MinLength { get; } + + /// + /// The maximum length for a text input, between 1 and 4000 characters. + /// + public Optional MaxLength { get; } + + /// + /// Indicates whether this text input field is required to be filled, defaults to true. + /// + public Optional Required { get; } + + /// + /// A pre-filled value for this component, up to 4000 characters. + /// + public Optional Value { get; } + + /// + /// A custom placeholder if the input field is empty, up to 100 characters. + /// + public Optional Placeholder { get; } +} diff --git a/src/core/DSharpPlus.Shared/Enums/MessageComponents/DiscordTextInputStyle.cs b/src/core/DSharpPlus.Shared/Enums/MessageComponents/DiscordTextInputStyle.cs new file mode 100644 index 0000000000..759fb7c5d2 --- /dev/null +++ b/src/core/DSharpPlus.Shared/Enums/MessageComponents/DiscordTextInputStyle.cs @@ -0,0 +1,21 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Entities; + +/// +/// Represents input styles for text input fields. +/// +public enum DiscordTextInputStyle +{ + /// + /// Single-line input. + /// + Short = 1, + + /// + /// Multi-line input. + /// + Paragraph +} From 23a65d49d4757b3503361b35e923a260958567d9 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sun, 4 Jun 2023 18:18:38 +0200 Subject: [PATCH 012/323] the main interaction object and all types required to implement it --- Directory.Build.props | 2 +- Directory.Packages.props | 1 + .../IApplicationCommandOption.cs | 10 +- .../IApplicationCommandOptionChoice.cs | 6 +- .../Applications/IInstallParameters.cs | 25 +++ .../Applications/IPartialApplication.cs | 125 +++++++++++ .../Channels/IAttachment.cs | 45 ++++ .../Channels/IChannelMention.cs | 35 +++ .../Channels/IChannelOverwrite.cs | 35 +++ .../Channels/IDefaultReaction.cs | 25 +++ .../Channels/IEmbed.cs | 81 +++++++ .../Channels/IEmbedAuthor.cs | 33 +++ .../Channels/IEmbedField.cs | 28 +++ .../Channels/IEmbedFooter.cs | 28 +++ .../Channels/IEmbedImage.cs | 33 +++ .../Channels/IEmbedProvider.cs | 23 ++ .../Channels/IEmbedThumbnail.cs | 33 +++ .../Channels/IEmbedVideo.cs | 33 +++ .../Channels/IForumTag.cs | 40 ++++ .../Channels/IMessage.cs | 104 +++++++++ .../Channels/IMessageActivity.cs | 25 +++ .../Channels/IMessageReference.cs | 35 +++ .../Channels/IPartialAttachment.cs | 75 +++++++ .../Channels/IPartialChannel.cs | 200 ++++++++++++++++++ .../Channels/IPartialMessage.cs | 174 +++++++++++++++ .../Channels/IReaction.cs | 26 +++ .../Channels/IRoleSubscriptionData.cs | 33 +++ .../Channels/IThreadMember.cs | 40 ++++ .../Channels/IThreadMetadata.cs | 47 ++++ ...DSharpPlus.Core.Abstractions.Models.csproj | 1 + .../Guilds/IGuildMember.cs | 50 +++++ .../Guilds/IPartialGuildMember.cs | 80 +++++++ .../Guilds/IRole.cs | 70 ++++++ .../Guilds/IRoleTags.cs | 43 ++++ .../IApplicationCommandInteractionData.cs | 53 +++++ ...ApplicationCommandInteractionDataOption.cs | 40 ++++ .../IAutocompleteInteractionData.cs | 48 +++++ .../IAutocompleteInteractionDataOption.cs | 19 ++ .../Interactions/IInteraction.cs | 95 +++++++++ .../Interactions/IInteractionData.cs | 12 ++ .../IMessageComponentInteractionData.cs | 32 +++ .../Interactions/IMessageInteraction.cs | 40 ++++ .../Interactions/IModalInteractionData.cs | 23 ++ .../Interactions/IResolvedData.cs | 45 ++++ .../MessageComponents/IActionRowComponent.cs | 4 +- .../IInteractiveComponent.cs | 2 +- .../Stickers/IStickerItem.cs | 30 +++ .../Teams/ITeam.cs | 41 ++++ .../Teams/ITeamMember.cs | 37 ++++ .../Users/IPartialUser.cs | 89 ++++++++ .../Users/IUser.cs | 87 ++------ .../Applications/DiscordApplicationFlags.cs | 64 ++++++ .../Enums/Channels/DiscordChannelFlags.cs | 27 +++ .../Channels/DiscordChannelOverwriteType.cs | 14 ++ .../Enums/Channels/DiscordForumLayoutType.cs | 15 ++ .../Enums/Channels/DiscordForumSortOrder.cs | 14 ++ .../Channels/DiscordMessageActivityType.cs | 16 ++ .../Enums/Channels/DiscordMessageFlags.cs | 71 +++++++ .../Enums/Channels/DiscordMessageType.cs | 40 ++++ .../Enums/Channels/DiscordVideoQualityMode.cs | 21 ++ .../Enums/Guilds/DiscordGuildMemberFlags.cs | 37 ++++ .../Interactions/DiscordInteractionType.cs | 17 ++ ...Type.cs => DiscordMessageComponentType.cs} | 2 +- .../Stickers/DiscordStickerFormatType.cs | 16 ++ .../Enums/Teams/DiscordTeamMembershipState.cs | 14 ++ 65 files changed, 2628 insertions(+), 81 deletions(-) create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/Applications/IInstallParameters.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/Applications/IPartialApplication.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/Channels/IAttachment.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/Channels/IChannelMention.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/Channels/IChannelOverwrite.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/Channels/IDefaultReaction.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/Channels/IEmbed.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/Channels/IEmbedAuthor.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/Channels/IEmbedField.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/Channels/IEmbedFooter.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/Channels/IEmbedImage.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/Channels/IEmbedProvider.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/Channels/IEmbedThumbnail.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/Channels/IEmbedVideo.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/Channels/IForumTag.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/Channels/IMessage.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/Channels/IMessageActivity.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/Channels/IMessageReference.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/Channels/IPartialAttachment.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/Channels/IPartialChannel.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/Channels/IPartialMessage.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/Channels/IReaction.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/Channels/IRoleSubscriptionData.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/Channels/IThreadMember.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/Channels/IThreadMetadata.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IGuildMember.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IPartialGuildMember.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IRole.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IRoleTags.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IApplicationCommandInteractionData.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IApplicationCommandInteractionDataOption.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IAutocompleteInteractionData.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IAutocompleteInteractionDataOption.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IInteraction.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IInteractionData.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IMessageComponentInteractionData.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IMessageInteraction.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IModalInteractionData.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IResolvedData.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/Stickers/IStickerItem.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/Teams/ITeam.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/Teams/ITeamMember.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/Users/IPartialUser.cs create mode 100644 src/core/DSharpPlus.Shared/Enums/Applications/DiscordApplicationFlags.cs create mode 100644 src/core/DSharpPlus.Shared/Enums/Channels/DiscordChannelFlags.cs create mode 100644 src/core/DSharpPlus.Shared/Enums/Channels/DiscordChannelOverwriteType.cs create mode 100644 src/core/DSharpPlus.Shared/Enums/Channels/DiscordForumLayoutType.cs create mode 100644 src/core/DSharpPlus.Shared/Enums/Channels/DiscordForumSortOrder.cs create mode 100644 src/core/DSharpPlus.Shared/Enums/Channels/DiscordMessageActivityType.cs create mode 100644 src/core/DSharpPlus.Shared/Enums/Channels/DiscordMessageFlags.cs create mode 100644 src/core/DSharpPlus.Shared/Enums/Channels/DiscordMessageType.cs create mode 100644 src/core/DSharpPlus.Shared/Enums/Channels/DiscordVideoQualityMode.cs create mode 100644 src/core/DSharpPlus.Shared/Enums/Guilds/DiscordGuildMemberFlags.cs create mode 100644 src/core/DSharpPlus.Shared/Enums/Interactions/DiscordInteractionType.cs rename src/core/DSharpPlus.Shared/Enums/MessageComponents/{DiscordComponentType.cs => DiscordMessageComponentType.cs} (96%) create mode 100644 src/core/DSharpPlus.Shared/Enums/Stickers/DiscordStickerFormatType.cs create mode 100644 src/core/DSharpPlus.Shared/Enums/Teams/DiscordTeamMembershipState.cs diff --git a/Directory.Build.props b/Directory.Build.props index f3069e897b..861517eed1 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -4,7 +4,7 @@ net8.0 enable - 11 + preview True True $(NoWarn);CS1591 diff --git a/Directory.Packages.props b/Directory.Packages.props index 82d79969d6..16d135ccd2 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -1,5 +1,6 @@ + \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/ApplicationCommands/IApplicationCommandOption.cs b/src/core/DSharpPlus.Core.Abstractions.Models/ApplicationCommands/IApplicationCommandOption.cs index d3b52758c1..8d1fe47bdf 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/ApplicationCommands/IApplicationCommandOption.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/ApplicationCommands/IApplicationCommandOption.cs @@ -1,4 +1,4 @@ -// This Source Code form is subject to the terms of the Mozilla Public +// This Source Code form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. @@ -6,6 +6,8 @@ using DSharpPlus.Entities; +using OneOf; + using Remora.Rest.Core; namespace DSharpPlus.Core.Abstractions.Models; @@ -69,16 +71,14 @@ public interface IApplicationCommandOption /// /// If this option is of or /// , the minimum value permitted. - /// This is represented as a double here to avoid boxing when representing as object. /// - public Optional MinValue { get; } + public Optional> MinValue { get; } /// /// If this option is of or /// , the maximum value permitted. - /// This is represented as a double here to avoid boxing when representing as object. /// - public Optional MaxValue { get; } + public Optional> MaxValue { get; } /// /// If this option is of , the minimum diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/ApplicationCommands/IApplicationCommandOptionChoice.cs b/src/core/DSharpPlus.Core.Abstractions.Models/ApplicationCommands/IApplicationCommandOptionChoice.cs index 50eaf67ceb..9c30f25624 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/ApplicationCommands/IApplicationCommandOptionChoice.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/ApplicationCommands/IApplicationCommandOptionChoice.cs @@ -1,9 +1,11 @@ -// This Source Code form is subject to the terms of the Mozilla Public +// This Source Code form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. using System.Collections.Generic; +using OneOf; + using Remora.Rest.Core; namespace DSharpPlus.Core.Abstractions.Models; @@ -26,5 +28,5 @@ public interface IApplicationCommandOptionChoice /// /// The value of this choice, up to 100 characters if this is a string. /// - public object Value { get; } + public OneOf Value { get; } } diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Applications/IInstallParameters.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Applications/IInstallParameters.cs new file mode 100644 index 0000000000..9ed55f4354 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Applications/IInstallParameters.cs @@ -0,0 +1,25 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Entities; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Stores metadata about the installation process for an application. +/// +public interface IInstallParameters +{ + /// + /// The OAuth2 scopes to add the application to the server with. + /// + public IReadOnlyList Scopes { get; } + + /// + /// The permissions to request for the bot role. + /// + public DiscordPermissions Permissions { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Applications/IPartialApplication.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Applications/IPartialApplication.cs new file mode 100644 index 0000000000..8fa2fb61a0 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Applications/IPartialApplication.cs @@ -0,0 +1,125 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Entities; + +using Remora.Rest.Core; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Represents a partially populated application object. +/// +public interface IPartialApplication +{ + /// + /// The snowflake identifier of this application. + /// + public Optional Id { get; } + + /// + /// The name of this application. + /// + public Optional Name { get; } + + /// + /// The icon hash of this application. + /// + public Optional Icon { get; } + + /// + /// The description of this application. This doubles as the associated bot's about me section. + /// + public Optional Description { get; } + + /// + /// An array of RPC origin urls, if RPC is enabled. + /// + public Optional> RpcOrigins { get; } + + /// + /// Indicates whether this application's bot is publicly invitable. + /// + public Optional BotPublic { get; } + + /// + /// Indicates whether the bot will require completion of the OAuth2 code grant flow to join. + /// + public Optional BotRequireCodeGrant { get; } + + /// + /// The URL to this application's terms of service. + /// + public Optional TermsOfServiceUrl { get; } + + /// + /// The URL to this application's privacy policy. + /// + public Optional PrivacyPolicyUrl { get; } + + /// + /// A partial user object containing information on the owner of the application. + /// + public Optional Owner { get; } + + /// + /// The verification key for interactions and GameSDK functions. + /// + public Optional VerifyKey { get; } + + /// + /// The team owning this application. + /// + public Optional Team { get; } + + /// + /// If this application is a game sold on discord, this is the snowflake identifier of the guild + /// to which it has been linked. + /// + public Optional GuildId { get; } + + /// + /// If this application is a game sold on discord, this is the snowflake identifier of the + /// game SKU created, if it exists. + /// + public Optional PrimarySkuId { get; } + + /// + /// If this application is a game sold on discord, this is the URL slug that links to the store page. + /// + public Optional Slug { get; } + + /// + /// The image hash of this application's default rich presence invite cover image. + /// + public Optional CoverImage { get; } + + /// + /// The public flags for this application. + /// + public Optional Flags { get; } + + /// + /// Up to five tags describing content and functionality of the application. + /// + public Optional> Tags { get; } + + /// + /// The installation parameters for this app. + /// + public Optional InstallParams { get; } + + /// + /// The default custom authorization link for this application, if enabled. + /// + public Optional CustomInstallUrl { get; } + + /// + /// This application's role connection verification entry point; which, when configured, will render + /// the application as a verification method in the guild role verification configuration. + /// + public Optional RoleConnectionsVerificationUrl { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IAttachment.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IAttachment.cs new file mode 100644 index 0000000000..b574f00960 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IAttachment.cs @@ -0,0 +1,45 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using Remora.Rest.Core; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Represents an attachment to a message. +/// +public interface IAttachment : IPartialAttachment +{ + /// + public new Snowflake Id { get; } + + /// + public new string Filename { get; } + + /// + public new int Size { get; } + + /// + public new string Url { get; } + + /// + public new string ProxyUrl { get; } + + // partial access routing + + /// + Optional IPartialAttachment.Id => this.Id; + + /// + Optional IPartialAttachment.Filename => this.Filename; + + /// + Optional IPartialAttachment.Size => this.Size; + + /// + Optional IPartialAttachment.Url => this.Url; + + /// + Optional IPartialAttachment.ProxyUrl => this.ProxyUrl; +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IChannelMention.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IChannelMention.cs new file mode 100644 index 0000000000..80ffeef308 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IChannelMention.cs @@ -0,0 +1,35 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Entities; + +using Remora.Rest.Core; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Represents a mention of a guild channel. +/// +public interface IChannelMention +{ + /// + /// The snowflake identifier of this channel. + /// + public Snowflake Id { get; } + + /// + /// The snowflake identifier of the guild containing this channel. + /// + public Snowflake GuildId { get; } + + /// + /// The type of this channel. + /// + public DiscordChannelType Type { get; } + + /// + /// The name of this channel. + /// + public string Name { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IChannelOverwrite.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IChannelOverwrite.cs new file mode 100644 index 0000000000..fea4aaa1e0 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IChannelOverwrite.cs @@ -0,0 +1,35 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Entities; + +using Remora.Rest.Core; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Represents a permission overwrite on a channel. +/// +public interface IChannelOverwrite +{ + /// + /// The snowflake identifier of the role or user this overwrite targtes. + /// + public Snowflake Id { get; } + + /// + /// Specifies what kind of entity this overwrite targets. + /// + public DiscordChannelOverwriteType Type { get; } + + /// + /// The permissions explicitly granted by this overwrite. + /// + public DiscordPermissions Allow { get; } + + /// + /// The permissions explicitly denied by this overwrite. + /// + public DiscordPermissions Deny { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IDefaultReaction.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IDefaultReaction.cs new file mode 100644 index 0000000000..81633bf8c8 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IDefaultReaction.cs @@ -0,0 +1,25 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using Remora.Rest.Core; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Indicates the default emoji to react to a forum post with. +/// +public interface IDefaultReaction +{ + /// + /// The snowflake identifier of a custom emoji to react with. Mutually exclusive with + /// . + /// + public Snowflake? EmojiId { get; } + + /// + /// The unicode representation of a default emoji to react with. Mutually exclusive with + /// . + /// + public string? EmojiName { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IEmbed.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IEmbed.cs new file mode 100644 index 0000000000..ee8fdbf147 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IEmbed.cs @@ -0,0 +1,81 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; +using System.Collections.Generic; + +using Remora.Rest.Core; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Represents embedded content in a message. +/// +public interface IEmbed +{ + /// + /// The title of this embed. + /// + public Optional Title { get; } + + /// + /// The type of this embed, always rich for bot/webhook embeds. + /// + public Optional Type { get; } + + /// + /// The main content field of this embed. + /// + public Optional Description { get; } + + /// + /// The url of this embed. + /// + public Optional Url { get; } + + /// + /// The timestamp of this embed content. + /// + public Optional Timestamp { get; } + + /// + /// The color code for the event sidebar. + /// + public Optional Color { get; } + + /// + /// The embed footer. + /// + public Optional Footer { get; } + + /// + /// The embed image. + /// + public Optional Image { get; } + + /// + /// The embed thumbnail. + /// + public Optional Thumbnail { get; } + + /// + /// The embed video. + /// + public Optional Video { get; } + + /// + /// The embed provider. + /// + public Optional Provider { get; } + + /// + /// The embed author. + /// + public Optional Author { get; } + + /// + /// Up to 25 embed fields. + /// + public Optional> Fields { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IEmbedAuthor.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IEmbedAuthor.cs new file mode 100644 index 0000000000..c36bc63462 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IEmbedAuthor.cs @@ -0,0 +1,33 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using Remora.Rest.Core; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Represents an embed author object. +/// +public interface IEmbedAuthor +{ + /// + /// The name of the author. + /// + public string Name { get; } + + /// + /// The URL of the author, only supports http(s). + /// + public Optional Url { get; } + + /// + /// The URL of the author icon. + /// + public Optional IconUrl { get; } + + /// + /// The proxied URL of the author icon. + /// + public Optional ProxyIconUrl { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IEmbedField.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IEmbedField.cs new file mode 100644 index 0000000000..0175ce621c --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IEmbedField.cs @@ -0,0 +1,28 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using Remora.Rest.Core; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Represents an embed field. +/// +public interface IEmbedField +{ + /// + /// The name of the field. This does not support markdown. + /// + public string Name { get; } + + /// + /// The value of this field. + /// + public string Value { get; } + + /// + /// Indicates whether this field is rendered inline. + /// + public Optional Inline { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IEmbedFooter.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IEmbedFooter.cs new file mode 100644 index 0000000000..fd1b2ec182 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IEmbedFooter.cs @@ -0,0 +1,28 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using Remora.Rest.Core; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Represents an embed footer object. +/// +public interface IEmbedFooter +{ + /// + /// The footer text. + /// + public string Text { get; } + + /// + /// The URL of the footer icon. + /// + public Optional IconUrl { get; } + + /// + /// The proxied URL of the footer icon. + /// + public Optional ProxyIconUrl { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IEmbedImage.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IEmbedImage.cs new file mode 100644 index 0000000000..cdb25a0d9e --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IEmbedImage.cs @@ -0,0 +1,33 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using Remora.Rest.Core; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Represents an embedded image. +/// +public interface IEmbedImage +{ + /// + /// The source URL of this image. + /// + public string Url { get; } + + /// + /// The proxied URL of this image. + /// + public Optional ProxyUrl { get; } + + /// + /// The height of the image. + /// + public Optional Height { get; } + + /// + /// The width of the image. + /// + public Optional Width { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IEmbedProvider.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IEmbedProvider.cs new file mode 100644 index 0000000000..697a84eb31 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IEmbedProvider.cs @@ -0,0 +1,23 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using Remora.Rest.Core; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Represents an embed provider. +/// +public interface IEmbedProvider +{ + /// + /// The name of this provider. + /// + public Optional Name { get; } + + /// + /// The URL of this provider. + /// + public Optional Url { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IEmbedThumbnail.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IEmbedThumbnail.cs new file mode 100644 index 0000000000..f60a317cd6 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IEmbedThumbnail.cs @@ -0,0 +1,33 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using Remora.Rest.Core; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Represents a thumbnail in an embed. +/// +public interface IEmbedThumbnail +{ + /// + /// The source URL of this thumbnail. + /// + public string Url { get; } + + /// + /// The proxied URL of this thumbnail. + /// + public Optional ProxyUrl { get; } + + /// + /// The height of the thumbnail. + /// + public Optional Height { get; } + + /// + /// The width of the thumbnail. + /// + public Optional Width { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IEmbedVideo.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IEmbedVideo.cs new file mode 100644 index 0000000000..aab8091d58 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IEmbedVideo.cs @@ -0,0 +1,33 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using Remora.Rest.Core; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Represents an embedded video. +/// +public interface IEmbedVideo +{ + /// + /// The source URL of this video. + /// + public Optional Url { get; } + + /// + /// The proxied URL of this video. + /// + public Optional ProxyUrl { get; } + + /// + /// The height of the video. + /// + public Optional Height { get; } + + /// + /// The width of the video. + /// + public Optional Width { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IForumTag.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IForumTag.cs new file mode 100644 index 0000000000..8d96789e9e --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IForumTag.cs @@ -0,0 +1,40 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using Remora.Rest.Core; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Represents a single forum tag, applicable to forum posts. +/// +public interface IForumTag +{ + /// + /// The snowflake identifier of this tag. + /// + public Snowflake Id { get; } + + /// + /// The name of this tag, up to 20 characters. + /// + public string Name { get; } + + /// + /// Indicates whether this tag can only be added or removed by a member with the manage threads permission. + /// + public bool Moderated { get; } + + /// + /// The snowflake identifier of a custom emoji to be applied to this tag. Mutually exclusive with + /// . + /// + public Snowflake? EmojiId { get; } + + /// + /// The unicode representation of a default emoji to be applied to this tag. Mutually exclusive with + /// . + /// + public string? EmojiName { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IMessage.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IMessage.cs new file mode 100644 index 0000000000..260694a79a --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IMessage.cs @@ -0,0 +1,104 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; +using System.Collections.Generic; + +using DSharpPlus.Entities; + +using Remora.Rest.Core; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Represents a complete message object. +/// +public interface IMessage : IPartialMessage +{ + /// + public new Snowflake Id { get; } + + /// + public new Snowflake ChannelId { get; } + + /// + public new IUser Author { get; } + + /// + public new string Content { get; } + + /// + public new DateTimeOffset Timestamp { get; } + + /// + public new DateTimeOffset? EditedTimestamp { get; } + + /// + public new bool Tts { get; } + + /// + public new bool MentionEveryone { get; } + + /// + public new IReadOnlyList Mentions { get; } + + /// + public new IReadOnlyList MentionRoles { get; } + + /// + public new IReadOnlyList Attachments { get; } + + /// + public new IReadOnlyList Embeds { get; } + + /// + public new bool Pinned { get; } + + /// + public new DiscordMessageType Type { get; } + + // explicit routes for partial access + + /// + Optional IPartialMessage.Id => this.Id; + + /// + Optional IPartialMessage.ChannelId => this.ChannelId; + + /// + Optional IPartialMessage.Author => new(this.Author); + + /// + Optional IPartialMessage.Content => this.Content; + + /// + Optional IPartialMessage.Timestamp => this.Timestamp; + + /// + Optional IPartialMessage.EditedTimestamp => this.EditedTimestamp; + + /// + Optional IPartialMessage.Tts => this.Tts; + + /// + Optional IPartialMessage.MentionEveryone => this.MentionEveryone; + + /// + Optional> IPartialMessage.Mentions => new(this.Mentions); + + /// + Optional> IPartialMessage.MentionRoles => new(this.MentionRoles); + + /// + Optional> IPartialMessage.Attachments => new(this.Attachments); + + /// + Optional> IPartialMessage.Embeds => new(this.Embeds); + + /// + Optional IPartialMessage.Pinned => this.Pinned; + + /// + Optional IPartialMessage.Type => this.Type; +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IMessageActivity.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IMessageActivity.cs new file mode 100644 index 0000000000..0e0e4e0354 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IMessageActivity.cs @@ -0,0 +1,25 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Entities; + +using Remora.Rest.Core; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Represents activity data encoded in a message. +/// +public interface IMessageActivity +{ + /// + /// The type of this activity. + /// + public DiscordMessageActivityType Type { get; } + + /// + /// The party ID from a rich presence event. + /// + public Optional PartyId { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IMessageReference.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IMessageReference.cs new file mode 100644 index 0000000000..ecc43dfa3c --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IMessageReference.cs @@ -0,0 +1,35 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using Remora.Rest.Core; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Represents a message reference, used for replies, crossposts, pins, thread created and thread +/// starter messages, and channel following messages. +/// +public interface IMessageReference +{ + /// + /// The snowflake identifier of the originating message. + /// + public Optional MessageId { get; } + + /// + /// The snowflake identifier of the originating message's parent channel. + /// + public Optional ChannelId { get; } + + /// + /// The snowflake identifier of the originating message's parent guild. + /// + public Optional GuildId { get; } + + /// + /// Indicates whether this reference will be checked for validity when sending the message; and + /// whether failing this check should result in this message not sending. + /// + public Optional FailIfNotExists { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IPartialAttachment.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IPartialAttachment.cs new file mode 100644 index 0000000000..732cf890db --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IPartialAttachment.cs @@ -0,0 +1,75 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; + +using Remora.Rest.Core; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Represents a partially populated message attachment. +/// +public interface IPartialAttachment +{ + /// + /// The snowflake identifier of this attachment. + /// + public Optional Id { get; } + + /// + /// The attachment's filename. + /// + public Optional Filename { get; } + + /// + /// The file description, up to 1024 characters. + /// + public Optional Description { get; } + + /// + /// This attachment's media type. + /// + public Optional ContentType { get; } + + /// + /// The file size in bytes. + /// + public Optional Size { get; } + + /// + /// The source URL of this file. + /// + public Optional Url { get; } + + /// + /// A proxied URL of this file. + /// + public Optional ProxyUrl { get; } + + /// + /// The height of this file, if this is an image. + /// + public Optional Height { get; } + + /// + /// The width of this file, if this is an image. + /// + public Optional Width { get; } + + /// + /// Indicates whether this is an ephemeral attachment. + /// + public Optional Ephemeral { get; } + + /// + /// The duration of this voice message in seconds. + /// + public Optional DurationSecs { get; } + + /// + /// base64-encoded byte array representing a sampled waveform for this voice message. + /// + public Optional> Waveform { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IPartialChannel.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IPartialChannel.cs new file mode 100644 index 0000000000..277cb287ca --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IPartialChannel.cs @@ -0,0 +1,200 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; +using System.Collections.Generic; + +using DSharpPlus.Entities; + +using Remora.Rest.Core; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Represents a partial channel of any given type. +/// +public interface IPartialChannel +{ + /// + /// The snowflake identifier of this channel. + /// + public Optional Id { get; } + + /// + /// The type of this channel. + /// + public Optional Type { get; } + + /// + /// The snowflake identifier of the guild this channel belongs to, if it is a guild channel. + /// + public Optional GuildId { get; } + + /// + /// The sorting position in the guild channel list of this channel, if it is a guild channel. + /// + public Optional Position { get; } + + /// + /// A collection of explicit permission overwrites for members and roles. + /// + public Optional> PermissionOverwrites { get; } + + /// + /// The name of this channel, 1 to 100 characters. + /// + public Optional Name { get; } + + /// + /// The channel topic/description. For up to 4096 + /// characters are allowed, for all other types up to 1024 characters. + /// + public Optional Topic { get; } + + /// + /// Indicates whether the channel is considered a NSFW channel. + /// + public Optional Nsfw { get; } + + /// + /// The snowflake identifier of the last message sent in this channel. This is a thread for forum + /// channels, and may not point to an existing or valid message or thread. + /// + public Optional LastMessageId { get; } + + /// + /// The bitrate of this channel, if it is a voice channel. + /// + public Optional Bitrate { get; } + + /// + /// The user limit of this channel, if it is a voice channel. + /// + public Optional UserLimit { get; } + + /// + /// The slowmode of the current channel in seconds, between 0 and 21600. Bots, as well as users + /// with manage messages or manage channel permissions, are unaffected. + /// + public Optional RateLimitPerUser { get; } + + /// + /// The recipients of this DM channel. + /// + public Optional> Recipients { get; } + + /// + /// The icon hash of this group DM channel. + /// + public Optional Icon { get; } + + /// + /// The snowflake identifier of the creator of this group DM or thread channel. + /// + public Optional OwnerId { get; } + + /// + /// The snowflake identifier of the application that created this group DM, if it was created by a bot. + /// + public Optional ApplicationId { get; } + + /// + /// Indicates whether this channel is managed by an application via OAuth2. + /// + public Optional Managed { get; } + + /// + /// The parent channel of the current channel; either the containing category if this is a standalone + /// guild channel, or the containing text channel if this is a thread channel. + /// + public Optional ParentId { get; } + + /// + /// The timestamp at which the last message was pinned. + /// + public Optional LastPinTimestamp { get; } + + /// + /// The voice region ID of this voice channel, automatic when set to null. + /// + public Optional RtcRegion { get; } + + /// + /// The camera video quality mode of this voice channel, automatic when not present. + /// + public Optional VideoQualityMode { get; } + + /// + /// The number of messages, excluding the original message and deleted messages, in a thread. + /// + public Optional MessageCount { get; } + + /// + /// The approximate amount of users in this thread, stops counting at 50. + /// + public Optional MemberCount { get; } + + /// + /// A thread-specific metadata object containing data not needed by other channel types. + /// + public Optional ThreadMetadata { get; } + + /// + /// A thread member object for the current user, if they have joined this thread. + /// + public Optional Member { get; } + + /// + /// The default thread archive duration in minutes, applied to all threads created within this channel + /// where the default was not overridden on creation. + /// + public Optional DefaultAutoArchiveDuration { get; } + + /// + /// Computed permissions for the invoking user in this channel, including permission overwrites. This + /// is only sent as part of application command resolved data. + /// + public Optional Permissions { get; } + + /// + /// Additional flags for this channel. + /// + public Optional Flags { get; } + + /// + /// The total number of messages sent in this thread, including deleted messages. + /// + public Optional TotalMessageSent { get; } + + /// + /// The set of tags that can be used in this forum channel. + /// + public Optional> AvailableTags { get; } + + /// + /// The snowflake identifiers of the set of tags that have been applied to this forum thread channel. + /// + public Optional> AppliedTags { get; } + + /// + /// The default emoji to show in the add reaction button on a thread in this forum channel. + /// + public Optional DefaultReactionEmoji { get; } + + /// + /// The initial slowmode to set on newly created threads in this channel. This is populated at creation + /// time and does not sync. + /// + public Optional DefaultThreadRateLimitPerUser { get; } + + /// + /// The default sort order for posts in this forum channel. + /// + public Optional DefaultSortOrder { get; } + + /// + /// The default layout view used to display posts in this forum channel. + /// + public Optional DefaultForumLayout { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IPartialMessage.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IPartialMessage.cs new file mode 100644 index 0000000000..1bd6fd6c1c --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IPartialMessage.cs @@ -0,0 +1,174 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; +using System.Collections.Generic; + +using DSharpPlus.Entities; + +using Remora.Rest.Core; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Represents a partially populated message object. +/// +public interface IPartialMessage +{ + /// + /// The snowflake identifier of this message. + /// + public Optional Id { get; } + + /// + /// The snowflake identifier of the channel this message was sent in. + /// + public Optional ChannelId { get; } + + /// + /// The author of this message. This is not guaranteed to be a valid user; if this message was sent + /// by a webhook it will contain webhook metadata instead. Check to see + /// whether this message was generated by a webhook. + /// + public Optional Author { get; } + + /// + /// The text contents of this message. This will be empty if your application does not have the + /// message content intent. + /// + public Optional Content { get; } + + /// + /// The timestamp at which this message was sent. + /// + public Optional Timestamp { get; } + + /// + /// The timestamp at which this message was last edited. + /// + public Optional EditedTimestamp { get; } + + /// + /// Indicates whether this is a text-to-speech message. + /// + public Optional Tts { get; } + + /// + /// Indicates whether this message mentions everyone. + /// + public Optional MentionEveryone { get; } + + /// + /// The users specifically mentioned in this message. + /// + public Optional> Mentions { get; } + + /// + /// The roles specifically mentioned in this message. + /// + public Optional> MentionRoles { get; } + + /// + /// The channels specifically mentioned in this message. + /// + public Optional> MentionChannels { get; } + + /// + /// The files attached to this message. + /// + public Optional> Attachments { get; } + + /// + /// The embeds added to this message. + /// + public Optional> Embeds { get; } + + /// + /// The reactions added to this message. + /// + public Optional> Reactions { get; } + + /// + /// Used for validating whether a message was sent. + /// + public Optional Nonce { get; } + + /// + /// Indicates whether this message is pinned. + /// + public Optional Pinned { get; } + + /// + /// The snowflake identifier of the webhook that generated this message. + /// + public Optional WebhookId { get; } + + /// + /// The type of this message. + /// + public Optional Type { get; } + + /// + /// Sent with rich-presence related chat embeds, encodes an activity. + /// + public Optional Activity { get; } + + /// + /// Sent with rich-presence related chat embeds, encodes an associated application. + /// + public Optional Application { get; } + + /// + /// If this message is an interaction-owned or application-owned webhook, this is the snowflake + /// identifier of its parent application. + /// + public Optional ApplicationId { get; } + + /// + /// A message reference showing the source of a crosspost, channel follow, pin, reply or thread + /// creation/start message. + /// + public Optional MessageReference { get; } + + /// + /// Additional flags for this message. + /// + public Optional Flags { get; } + + /// + /// The message associated with the . + /// + public Optional ReferencedMessage { get; } + + /// + /// Additional metadata if this message is the original response to an interaction. + /// + public Optional Interaction { get; } + + /// + /// The thread that was started from this message. + /// + public Optional Thread { get; } + + /// + /// The components attached to this message. + /// + public Optional> Components { get; } + + /// + /// The stickers sent along with this message. + /// + public Optional StickerItems { get; } + + /// + /// An approximate position of this message in a thread. This can be used to estimate the relative + /// position of this message in its parent thread. + /// + public Optional Position { get; } + + /// + /// Metadata for the role subscription purchase or renewal that prompted this message. + /// + public Optional RoleSubscriptionData { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IReaction.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IReaction.cs new file mode 100644 index 0000000000..47c16bfbca --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IReaction.cs @@ -0,0 +1,26 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Represents a reaction to a message. +/// +public interface IReaction +{ + /// + /// The amount of times this emoji has been reacted with. + /// + public int Count { get; } + + /// + /// Indicates whether the current user has reacted using this emoji. + /// + public bool Me { get; } + + /// + /// The emoji that is being reacted with. + /// + public IPartialEmoji Emoji { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IRoleSubscriptionData.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IRoleSubscriptionData.cs new file mode 100644 index 0000000000..73d7f112b4 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IRoleSubscriptionData.cs @@ -0,0 +1,33 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using Remora.Rest.Core; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Contains metadata about a role subscription. +/// +public interface IRoleSubscriptionData +{ + /// + /// The snowflake identifier of the SKU and listing that the user is subscribed to. + /// + public Snowflake RoleSubscriptionListingId { get; } + + /// + /// The name of the tier that the user is subscribed to. + /// + public string TierName { get; } + + /// + /// The cumulative number of months that the user has been subscribed for. + /// + public int TotalMonthsSubscribed { get; } + + /// + /// Indicates whether this notification is for a renewal, rather than a new purchase. + /// + public bool IsRenewal { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IThreadMember.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IThreadMember.cs new file mode 100644 index 0000000000..5a2bf5df80 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IThreadMember.cs @@ -0,0 +1,40 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; + +using Remora.Rest.Core; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Includes additional metadata about a member's presence inside a thread. +/// +public interface IThreadMember +{ + /// + /// The snowflake identifier of the thread this object belongs to. + /// + public Optional Id { get; } + + /// + /// The snowflake identifier of the user this object belongs to. + /// + public Optional UserId { get; } + + /// + /// The timestamp at which this user last joined the thread. + /// + public DateTimeOffset JoinTimestamp { get; } + + /// + /// User thread settings used for notifications. + /// + public int Flags { get; } + + /// + /// Additional information about this thread member. + /// + public Optional Member { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IThreadMetadata.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IThreadMetadata.cs new file mode 100644 index 0000000000..17e6f81a6b --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IThreadMetadata.cs @@ -0,0 +1,47 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; + +using Remora.Rest.Core; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Contains additional metadata about thread channels. +/// +public interface IThreadMetadata +{ + /// + /// Indicates whether this thread is considered archived. + /// + public bool Archived { get; } + + /// + /// The time in minutes of inactivity before this thread stops showing in the channel list. + /// Legal values are 60, 1440, 4320 and 10080. + /// + public int AutoArchiveDuration { get; } + + /// + /// The timestamp at which this thread's archive status was last changed. + /// + public DateTimeOffset ArchiveTimestamp { get; } + + /// + /// Indicates whether this thread is locked, if it is, only users with the manage threads permission + /// can unlock it. + /// + public bool Locked { get; } + + /// + /// Indicates whether non-moderators can add other non-moderators to this thread. + /// + public Optional Invitable { get; } + + /// + /// The timestamp at which this thread was created. + /// + public Optional CreateTimestamp { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/DSharpPlus.Core.Abstractions.Models.csproj b/src/core/DSharpPlus.Core.Abstractions.Models/DSharpPlus.Core.Abstractions.Models.csproj index 8e5caf8e62..a43488257e 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/DSharpPlus.Core.Abstractions.Models.csproj +++ b/src/core/DSharpPlus.Core.Abstractions.Models/DSharpPlus.Core.Abstractions.Models.csproj @@ -7,6 +7,7 @@ + diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IGuildMember.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IGuildMember.cs new file mode 100644 index 0000000000..8450d25596 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IGuildMember.cs @@ -0,0 +1,50 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; +using System.Collections.Generic; + +using DSharpPlus.Entities; + +using Remora.Rest.Core; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Represents a fully populated guild member object. +/// +public interface IGuildMember : IPartialGuildMember +{ + /// + public new IReadOnlyList Roles { get; } + + /// + public new DateTimeOffset JoinedAt { get; } + + /// + public new bool Deaf { get; } + + /// + public new bool Mute { get; } + + /// + public new DiscordGuildMemberFlags Flags { get; } + + // explicit routes for partial guild member access + + /// + Optional> IPartialGuildMember.Roles => new(this.Roles); + + /// + Optional IPartialGuildMember.JoinedAt => this.JoinedAt; + + /// + Optional IPartialGuildMember.Deaf => this.Deaf; + + /// + Optional IPartialGuildMember.Mute => this.Mute; + + /// + Optional IPartialGuildMember.Flags => this.Flags; +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IPartialGuildMember.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IPartialGuildMember.cs new file mode 100644 index 0000000000..bb822862e5 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IPartialGuildMember.cs @@ -0,0 +1,80 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; +using System.Collections.Generic; + +using DSharpPlus.Entities; + +using Remora.Rest.Core; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Represents a single member of a guild. +/// +public interface IPartialGuildMember +{ + /// + /// The underlying user account. + /// + public Optional User { get; } + + /// + /// This user's guild nickname. + /// + public Optional Nick { get; } + + /// + /// The user's guild avatar hash. + /// + public Optional Avatar { get; } + + /// + /// This user's list of roles. + /// + public Optional> Roles { get; } + + /// + /// Stores when this user last joined this guild. + /// + public Optional JoinedAt { get; } + + /// + /// Stores when this user started boosting this guild. + /// + public Optional PremiumSince { get; } + + /// + /// Indicates whether this user is server deafened. + /// + public Optional Deaf { get; } + + /// + /// Indicates whether this user is server muted. + /// + public Optional Mute { get; } + + /// + /// Additional flags for this guild member. + /// + public Optional Flags { get; } + + /// + /// Indicates whether the user is in the process of passing the guild membership + /// screening requirements. + /// + public Optional Pending { get; } + + /// + /// Total permissions of this guild member including channel overwrites. This is only set in + /// interaction-related objects. + /// + public Optional Permissions { get; } + + /// + /// The timestamp at which this user's timeout expires. + /// + public Optional CommunicationDisabledUntil { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IRole.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IRole.cs new file mode 100644 index 0000000000..ce276a8495 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IRole.cs @@ -0,0 +1,70 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Entities; + +using Remora.Rest.Core; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Represents a role within a guild. +/// +public interface IRole +{ + /// + /// The snowflake identifier of this role. + /// + public Snowflake Id { get; } + + /// + /// The name of this role. + /// + public string Name { get; } + + /// + /// The RGB color code of this role, #000000 represents a transparent role. + /// + public int Color { get; } + + /// + /// Indicates whether users with this role are hoisted in the member list. + /// + public bool Hoist { get; } + + /// + /// This role's role icon hash, if applicable. + /// + public Optional Hash { get; } + + /// + /// The unicode emoji serving as this role's role icon, if applicable. + /// + public Optional UnicodeEmoji { get; } + + /// + /// The position of this role in the role list. + /// + public int Position { get; } + + /// + /// The permissions associated with this role. + /// + public DiscordPermissions Permissions { get; } + + /// + /// Indicates whether this role is managed by an integration. + /// + public bool Managed { get; } + + /// + /// Indicates whether this role can be mentioned by users without the permission. + /// + public bool Mentionable { get; } + + /// + /// Additional tags added to this role. + /// + public Optional Tags { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IRoleTags.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IRoleTags.cs new file mode 100644 index 0000000000..e7ce227bc7 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IRoleTags.cs @@ -0,0 +1,43 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using Remora.Rest.Core; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Contains additional tags associated with a given role. +/// +public interface IRoleTags +{ + /// + /// The snowflake identifier of the bot this role belongs to. + /// + public Optional BotId { get; } + + /// + /// The snowflake identifier of the integration this role belongs to. + /// + public Optional IntegrationId { get; } + + /// + /// Indicates whether this is the guild's booster role. + /// + public bool PremiumSubscriber { get; } + + /// + /// The snowflake identifier of this role's subscription SKU and listing. + /// + public Optional SubscriptionListingId { get; } + + /// + /// Indicates whether this role is available for purchase. + /// + public bool AvailableForPurchase { get; } + + /// + /// Indicates whether this role is a linked role. + /// + public bool GuildConnections { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IApplicationCommandInteractionData.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IApplicationCommandInteractionData.cs new file mode 100644 index 0000000000..4e80aee19f --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IApplicationCommandInteractionData.cs @@ -0,0 +1,53 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Entities; + +using Remora.Rest.Core; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Contains the interaction metadata for application commands. +/// +public interface IApplicationCommandInteractionData : IInteractionData +{ + /// + /// The snowflake identifier of the invoked command. + /// + public Snowflake Id { get; } + + /// + /// The name of the invoked command. + /// + public string Name { get; } + + /// + /// The type of the invoked command. + /// + public DiscordApplicationCommandType Type { get; } + + /// + /// Contains resolved users, guild members, roles, channels, messages and attachments related to this + /// interaction. + /// + public Optional Resolved { get; } + + /// + /// The parameters and passed values from the user. + /// + public Optional> Options { get; } + + /// + /// The snowflake identifier of the guild this command is being registered to. + /// + public Optional GuildId { get; } + + /// + /// The snowflake identifier of the user or message targeted by this user/message command. + /// + public Optional TargetId { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IApplicationCommandInteractionDataOption.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IApplicationCommandInteractionDataOption.cs new file mode 100644 index 0000000000..e5d3a0ba47 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IApplicationCommandInteractionDataOption.cs @@ -0,0 +1,40 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Entities; + +using OneOf; + +using Remora.Rest.Core; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Represents submitted data for a single application command option. +/// +public interface IApplicationCommandInteractionDataOption +{ + /// + /// The name of the option. + /// + public string Name { get; } + + /// + /// The type of this option. + /// + public DiscordApplicationCommandOptionType Type { get; } + + /// + /// The value passed to this option by the user. + /// + public Optional> Value { get; } + + /// + /// If this is a subcommand, the values passed to its parameters. If this is a subcommand group, + /// its subcommands. + /// + public Optional> Options { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IAutocompleteInteractionData.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IAutocompleteInteractionData.cs new file mode 100644 index 0000000000..6ec90dee1e --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IAutocompleteInteractionData.cs @@ -0,0 +1,48 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Entities; + +using Remora.Rest.Core; + +using System.Collections.Generic; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Contains the interaction metadata for application commands during the autocomplete process. +/// +public interface IAutocompleteInteractionData : IInteractionData +{ + /// + /// The snowflake identifier of the invoked command. + /// + public Snowflake Id { get; } + + /// + /// The name of the invoked command. + /// + public string Name { get; } + + /// + /// The type of the invoked command. + /// + public DiscordApplicationCommandType Type { get; } + + /// + /// Contains resolved users, guild members, roles, channels, messages and attachments related to this + /// interaction. + /// + public Optional Resolved { get; } + + /// + /// The parameters and passed values from the user. + /// + public Optional> Options { get; } + + /// + /// The snowflake identifier of the guild this command is being registered to. + /// + public Optional GuildId { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IAutocompleteInteractionDataOption.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IAutocompleteInteractionDataOption.cs new file mode 100644 index 0000000000..22f3aed111 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IAutocompleteInteractionDataOption.cs @@ -0,0 +1,19 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using Remora.Rest.Core; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Represents submitted data for a single application command data option during the autocomplete +/// process. +/// +public interface IAutocompleteInteractionDataOption : IApplicationCommandInteractionDataOption +{ + /// + /// Indicates whether this option is currently focused for autocomplete. + /// + public Optional Focused { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IInteraction.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IInteraction.cs new file mode 100644 index 0000000000..b5ffd64cc9 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IInteraction.cs @@ -0,0 +1,95 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Entities; + +using Remora.Rest.Core; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Represents an incoming interaction, received when an user submits an application command +/// or uses a message component.
+/// For application commands, it includes the submitted options;
+/// For context menu commands it includes the context;
+/// For message components it includes information about the component as well as metadata +/// about how the interaction was triggered. +///
+public interface IInteraction +{ + /// + /// The snowflake identifier of this interaction. + /// + public Snowflake Id { get; } + + /// + /// The snowflake identifier of the application this interaction is sent to. + /// + public Snowflake ApplicationId { get; } + + /// + /// The type of this interaction. + /// + public DiscordInteractionType Type { get; } + + /// + /// The data payload, depending on the . + /// + public Optional Data { get; } + + /// + /// The snowflake identifier of the guild this interaction was sent from, if applicable. + /// + public Optional GuildId { get; } + + /// + /// The channel this interaction was sent from. + /// + public Optional Channel { get; } + + /// + /// The snowflake identifier of the channel this interaction was sent from, if applicable. + /// + public Optional ChannelId { get; } + + /// + /// The guild member object for the invoking user, if applicable. + /// + public Optional Member { get; } + + /// + /// The user object for the invokign user, if invoked in a DM. + /// + public Optional User { get; } + + /// + /// The continuation token for responding to this interaction. + /// + public string Token { get; } + + /// + /// Always 1. + /// + public int Version { get; } + + /// + /// For components, the message they were attached to. + /// + public Optional Message { get; } + + /// + /// The permissions the application has within the channel the interaction was sent from. + /// + public Optional AppPermissions { get; } + + /// + /// The selected locale of the invoking user. + /// + public Optional Locale { get; } + + /// + /// The preferred locale of the guild, if invoked in a guild. + /// + public Optional GuildLocale { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IInteractionData.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IInteractionData.cs new file mode 100644 index 0000000000..4de47c9e8a --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IInteractionData.cs @@ -0,0 +1,12 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Represents metadata attached to an interaction. +/// +// This interface, by itself, does nothing. Type has to be resolved based on IInteraction.Type +// and casted appropriately to one of the derived interface types. +public interface IInteractionData; diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IMessageComponentInteractionData.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IMessageComponentInteractionData.cs new file mode 100644 index 0000000000..6f26d7fc13 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IMessageComponentInteractionData.cs @@ -0,0 +1,32 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Entities; + +using Remora.Rest.Core; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Represents metadata for a message component interaction. +/// +public interface IMessageComponentInteractionData : IInteractionData +{ + /// + /// The developer-defined ID of the component. + /// + public string CustomId { get; } + + /// + /// The type of this component. + /// + public DiscordMessageComponentType ComponentType { get; } + + /// + /// The values selected in the associated select menu, if applicable. + /// + public Optional> Values { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IMessageInteraction.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IMessageInteraction.cs new file mode 100644 index 0000000000..aae3a77086 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IMessageInteraction.cs @@ -0,0 +1,40 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Entities; + +using Remora.Rest.Core; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Represents metadata on a message when the message is an original response to an interaction. +/// +public interface IMessageInteraction +{ + /// + /// The snowflake identifier of the interaction. + /// + public Snowflake Id { get; } + + /// + /// The type of this interaction. + /// + public DiscordInteractionType Type { get; } + + /// + /// The name of the application command invoked, including subcommands and subcommand groups. + /// + public string Name { get; } + + /// + /// The user who invoked this interaction. + /// + public IUser User { get; } + + /// + /// The guild member who invoked this interaction. + /// + public Optional Member { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IModalInteractionData.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IModalInteractionData.cs new file mode 100644 index 0000000000..19a98f9d71 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IModalInteractionData.cs @@ -0,0 +1,23 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Contains metadata for a modal submission interaction. +/// +public interface IModalInteractionData : IInteractionData +{ + /// + /// The developer-defined ID of this modal. + /// + public string CustomId { get; } + + /// + /// The values submitted by the user. + /// + public IReadOnlyList Components { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IResolvedData.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IResolvedData.cs new file mode 100644 index 0000000000..25ae24b6aa --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IResolvedData.cs @@ -0,0 +1,45 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using Remora.Rest.Core; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Represents data resolved by Discord from s. +/// +public interface IResolvedData +{ + /// + /// Maps snowflakes to resolved user objects. + /// + public Optional> Users { get; } + + /// + /// Maps snowflakes to resolved guild member objects. + /// + public Optional> Members { get; } + + /// + /// Maps snowflakes to role objects. + /// + public Optional> Roles { get; } + + /// + /// Maps snowflakes to channel objects. + /// + public Optional> Channels { get; } + + /// + /// Maps snowflakes to message objects. + /// + public Optional> Messages { get; } + + /// + /// Maps snowflakes to attachment objects. + /// + public Optional> Attachments { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IActionRowComponent.cs b/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IActionRowComponent.cs index 1f26dfbfe8..9deb0e964e 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IActionRowComponent.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IActionRowComponent.cs @@ -14,9 +14,9 @@ namespace DSharpPlus.Core.Abstractions.Models; public interface IActionRowComponent { /// - /// + /// /// - public DiscordComponentType Type { get; } + public DiscordMessageComponentType Type { get; } /// /// The child components of this action row: up to five buttons, or one non-button component. diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IInteractiveComponent.cs b/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IInteractiveComponent.cs index bbdef8a132..5e4acf3d43 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IInteractiveComponent.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IInteractiveComponent.cs @@ -14,5 +14,5 @@ public interface IInteractiveComponent /// /// The type of this component. /// - public DiscordComponentType Type { get; } + public DiscordMessageComponentType Type { get; } } diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Stickers/IStickerItem.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Stickers/IStickerItem.cs new file mode 100644 index 0000000000..10edcbb79c --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Stickers/IStickerItem.cs @@ -0,0 +1,30 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Entities; + +using Remora.Rest.Core; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Contains the information needed to render a sticker. +/// +public interface IStickerItem +{ + /// + /// The snowflake identifier of the sticker + /// + public Snowflake Id { get; } + + /// + /// The name of this sticker. + /// + public string Name { get; } + + /// + /// The file format of this sticker. + /// + public DiscordStickerFormatType FormatType { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Teams/ITeam.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Teams/ITeam.cs new file mode 100644 index 0000000000..d59e95481c --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Teams/ITeam.cs @@ -0,0 +1,41 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using Remora.Rest.Core; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Represents a developer team on Discord. Teams can collectively own applications +/// and thereby bots. +/// +public interface ITeam +{ + /// + /// The icon hash for this team. + /// + public string? Icon { get; } + + /// + /// The snowflake identifier of this team. + /// + public Snowflake Id { get; } + + /// + /// The members of this team. + /// + public IReadOnlyList Members { get; } + + /// + /// The name of this team. + /// + public string Name { get; } + + /// + /// The user ID of the current team owner. + /// + public Snowflake OwnerUserId { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Teams/ITeamMember.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Teams/ITeamMember.cs new file mode 100644 index 0000000000..b19c9e166f --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Teams/ITeamMember.cs @@ -0,0 +1,37 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Entities; + +using Remora.Rest.Core; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Represents a single member of a . +/// +public interface ITeamMember +{ + /// + /// This user's membership state on the team. + /// + public DiscordTeamMembershipState MembershipState { get; } + + /// + /// This will always be a single string; "*". + /// + public IReadOnlyList Permissions { get; } + + /// + /// The snowflake identifier of the parent team. + /// + public Snowflake TeamId { get; } + + /// + /// The snowflake identifier, username and avatar of this user's discord account. + /// + public IPartialUser User { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Users/IPartialUser.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Users/IPartialUser.cs new file mode 100644 index 0000000000..e523648627 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Users/IPartialUser.cs @@ -0,0 +1,89 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Entities; +using Remora.Rest.Core; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Represents a partially populated user object. +/// +public interface IPartialUser +{ + /// + /// The snowflake identifier of this user. + /// + public Optional Id { get; } + + /// + /// The username of this user, unique across the platform. + /// + public Optional Username { get; } + + /// + /// The global display name of this user. + /// + public Optional GlobalName { get; } + + /// + /// The user's avatar hash. + /// + public Optional Avatar { get; } + + /// + /// Indicates whether this user is a bot user. + /// + public Optional Bot { get; } + + /// + /// Indicates whether this user is part of Discords urgent message system. + /// + public Optional System { get; } + + /// + /// Indicates whether this user has multi-factor authentication enabled on their account. + /// + public Optional MfaEnabled { get; } + + /// + /// The user's banner hash. + /// + public Optional Banner { get; } + + /// + /// The user's banner color code. + /// + public Optional AccentColor { get; } + + /// + /// The user's chosen language option. + /// + public Optional Locale { get; } + + /// + /// Indicates whether the email address linked to this user account has been verified. + /// + public Optional Verified { get; } + + /// + /// The user's email address. + /// + public Optional Email { get; } + + /// + /// The flags on this user's account. + /// + public Optional Flags { get; } + + /// + /// The level of nitro subscription on this user's account. + /// + public Optional PremiumType { get; } + + /// + /// The publicly visible flags on this user's account. + /// + public Optional PublicFlags { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Users/IUser.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Users/IUser.cs index 3cbdb213a8..79bd0c66a9 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Users/IUser.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Users/IUser.cs @@ -2,8 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Entities; - using Remora.Rest.Core; namespace DSharpPlus.Core.Abstractions.Models; @@ -11,80 +9,31 @@ namespace DSharpPlus.Core.Abstractions.Models; /// /// Represents an user object. /// -public interface IUser +public interface IUser : IPartialUser { - /// - /// The snowflake identifier of this user. - /// - public Snowflake Id { get; } - - /// - /// The username of this user, unique across the platform. - /// - public string Username { get; } - - /// - /// The global display name of this user. - /// - public string? GlobalName { get; } - - /// - /// The user's avatar hash. - /// - public string? Avatar { get; } - - /// - /// Indicates whether this user is a bot user. - /// - public Optional Bot { get; } - - /// - /// Indicates whether this user is part of Discords urgent message system. - /// - public Optional System { get; } - - /// - /// Indicates whether this user has multi-factor authentication enabled on their account. - /// - public Optional MfaEnabled { get; } + /// + public new Snowflake Id { get; } - /// - /// The user's banner hash. - /// - public Optional Banner { get; } + /// + public new string Username { get; } - /// - /// The user's banner color code. - /// - public Optional AccentColor { get; } + /// + public new string? GlobalName { get; } - /// - /// The user's chosen language option. - /// - public Optional Locale { get; } + /// + public new string? Avatar { get; } - /// - /// Indicates whether the email address linked to this user account has been verified. - /// - public Optional Verified { get; } + // explicit routes for partial user access - /// - /// The user's email address. - /// - public Optional Email { get; } + /// + Optional IPartialUser.Id => this.Id; - /// - /// The flags on this user's account. - /// - public Optional Flags { get; } + /// + Optional IPartialUser.Username => this.Username; - /// - /// The level of nitro subscription on this user's account. - /// - public Optional PremiumType { get; } + /// + Optional IPartialUser.GlobalName => this.GlobalName; - /// - /// The publicly visible flags on this user's account. - /// - public Optional PublicFlags { get; } + /// + Optional IPartialUser.Avatar => this.Avatar; } diff --git a/src/core/DSharpPlus.Shared/Enums/Applications/DiscordApplicationFlags.cs b/src/core/DSharpPlus.Shared/Enums/Applications/DiscordApplicationFlags.cs new file mode 100644 index 0000000000..594fef888e --- /dev/null +++ b/src/core/DSharpPlus.Shared/Enums/Applications/DiscordApplicationFlags.cs @@ -0,0 +1,64 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Entities; + +/// +/// Enumerates flags for applications and thereby bots. +/// +public enum DiscordApplicationFlags +{ + /// + /// Indicates whether an application uses the auto moderation API. + /// + ApplicationAutoModerationRuleCreateBadge = 1 << 6, + + /// + /// The intent required for bots in 100 or more servers to receive presence update events. + /// + GatewayPresence = 1 << 12, + + /// + /// The intent required for bots in less than 100 servers to receive presence update events. + /// Unlike , this does not require staff approval. + /// + GatewayPresenceLimited = 1 << 13, + + /// + /// The intent required for bots in 100 or more servers to receive guild member related events. + /// + GatewayGuildMembers = 1 << 14, + + /// + /// The intent required for bots in less than 100 servers to receive guild member related events. + /// Unlike , this does not require staff approval. + /// + GatewayGuildMembersLimited = 1 << 15, + + /// + /// Indicates unusual growth of an app that prevents verification. + /// + VerificationPendingGuildLimit = 1 << 16, + + /// + /// Indicates whether this app is embedded into the Discord client. + /// + Embedded = 1 << 17, + + /// + /// The intent required for bots in 100 or more servers to receive message content. + /// + GatewayMessageContent = 1 << 18, + + /// + /// The intent required for bots in less than 100 servers to receive message content. + /// Unlike , this does not require staff approval. + /// + GatewayMessageContentLimited = 1 << 19, + + /// + /// Indicates whether this application has registered global application commands. + /// + ApplicationCommandBadge = 1 << 23 +} diff --git a/src/core/DSharpPlus.Shared/Enums/Channels/DiscordChannelFlags.cs b/src/core/DSharpPlus.Shared/Enums/Channels/DiscordChannelFlags.cs new file mode 100644 index 0000000000..a3b21c5b63 --- /dev/null +++ b/src/core/DSharpPlus.Shared/Enums/Channels/DiscordChannelFlags.cs @@ -0,0 +1,27 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; + +namespace DSharpPlus.Entities; + +/// +/// Channel flags applied to the containing channel as bit fields. +/// +[Flags] +public enum DiscordChannelFlags +{ + None, + + /// + /// Indicates whether this is a thread channel pinned to the top of its parent forum channel. + /// + Pinned = 1 << 1, + + /// + /// Indicates whether this is a forum channel which requires tags to be specified when creating + /// a thread inside. + /// + RequireTag = 1 << 4 +} diff --git a/src/core/DSharpPlus.Shared/Enums/Channels/DiscordChannelOverwriteType.cs b/src/core/DSharpPlus.Shared/Enums/Channels/DiscordChannelOverwriteType.cs new file mode 100644 index 0000000000..cd3403519c --- /dev/null +++ b/src/core/DSharpPlus.Shared/Enums/Channels/DiscordChannelOverwriteType.cs @@ -0,0 +1,14 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Entities; + +/// +/// Enumerates different targets for channel overwrites. +/// +public enum DiscordChannelOverwriteType +{ + Role, + User +} diff --git a/src/core/DSharpPlus.Shared/Enums/Channels/DiscordForumLayoutType.cs b/src/core/DSharpPlus.Shared/Enums/Channels/DiscordForumLayoutType.cs new file mode 100644 index 0000000000..6bbef8339c --- /dev/null +++ b/src/core/DSharpPlus.Shared/Enums/Channels/DiscordForumLayoutType.cs @@ -0,0 +1,15 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Entities; + +/// +/// Enumerates the different forum layouts permitted. +/// +public enum DiscordForumLayoutType +{ + NotSet, + ListView, + GalleryView +} diff --git a/src/core/DSharpPlus.Shared/Enums/Channels/DiscordForumSortOrder.cs b/src/core/DSharpPlus.Shared/Enums/Channels/DiscordForumSortOrder.cs new file mode 100644 index 0000000000..111060b3a7 --- /dev/null +++ b/src/core/DSharpPlus.Shared/Enums/Channels/DiscordForumSortOrder.cs @@ -0,0 +1,14 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Entities; + +/// +/// Enumerates the different sorting orders for forum posts. +/// +public enum DiscordForumSortOrder +{ + LatestActivity, + CreationDate +} diff --git a/src/core/DSharpPlus.Shared/Enums/Channels/DiscordMessageActivityType.cs b/src/core/DSharpPlus.Shared/Enums/Channels/DiscordMessageActivityType.cs new file mode 100644 index 0000000000..548517c5ea --- /dev/null +++ b/src/core/DSharpPlus.Shared/Enums/Channels/DiscordMessageActivityType.cs @@ -0,0 +1,16 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Entities; + +/// +/// Enumerates valid activity kinds to be encoded in a message. +/// +public enum DiscordMessageActivityType +{ + Join = 1, + Spectate, + Listen, + JoinRequest = 5 +} diff --git a/src/core/DSharpPlus.Shared/Enums/Channels/DiscordMessageFlags.cs b/src/core/DSharpPlus.Shared/Enums/Channels/DiscordMessageFlags.cs new file mode 100644 index 0000000000..dff7961cda --- /dev/null +++ b/src/core/DSharpPlus.Shared/Enums/Channels/DiscordMessageFlags.cs @@ -0,0 +1,71 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; + +namespace DSharpPlus.Entities; + +/// +/// Enumerates additional flags applied to messages. +/// +[Flags] +public enum DiscordMessageFlags +{ + None = 0, + + /// + /// This message has been published to following channels. + /// + Crossposted = 1 << 0, + + /// + /// This message originated from a message in another channel this channel is following. + /// + IsCrosspost = 1 << 1, + + /// + /// Indicates whether embeds on this message are to be displayed or not. + /// + SuppressEmbeds = 1 << 2, + + /// + /// Indicates that this is a crossposted message whose source has been deleted. + /// + SourceMessageDeleted = 1 << 3, + + /// + /// Indicates that this is a message originating from the urgent messaging system. + /// + Urgent = 1 << 4, + + /// + /// Indicates that this message has an associated thread with the same identifier as this message. + /// + HasThread = 1 << 5, + + /// + /// Indicates that this message is only visible to the user who invoked the interaction. + /// + Ephemeral = 1 << 6, + + /// + /// Indicates that this message is an interaction response and that the bot is 'thinking'. + /// + Loading = 1 << 7, + + /// + /// This message failed to mention some roles and add their members to the thread. + /// + FailedToEnforceSomeRolesInThread = 1 << 8, + + /// + /// This message will not trigger push and desktop notifications. + /// + SuppressNotifications = 1 << 12, + + /// + /// This message is a voice message. + /// + IsVoiceMessage = 1 << 13 +} diff --git a/src/core/DSharpPlus.Shared/Enums/Channels/DiscordMessageType.cs b/src/core/DSharpPlus.Shared/Enums/Channels/DiscordMessageType.cs new file mode 100644 index 0000000000..80e025c804 --- /dev/null +++ b/src/core/DSharpPlus.Shared/Enums/Channels/DiscordMessageType.cs @@ -0,0 +1,40 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Entities; + +public enum DiscordMessageType +{ + Default, + RecipientAdd, + RecipientRemove, + Call, + ChannelNameChange, + ChannelIconChange, + ChannelPinnedMessage, + UserJoin, + GuildBoost, + GuildBoostTier1, + GuildBoostTier2, + GuildBoostTier3, + ChannelFollowAdd, + GuildDiscoveryDisqualified = 14, + GuildDiscoveryRequalified, + GuildDiscoveryGracePeriodInitialWarning, + GuildDiscoveryGracePeriodFinalWarning, + ThreadCreated, + Reply, + ChatInputCommand, + ThreadStarterMessage, + GuildInviteReminder, + ContextMenuCommand, + AutoModerationAction, + RoleSubscriptionPurchase, + InteractionPremiumUpsell, + StageStart, + StageEnd, + StageSpeaker, + StageTopic = 31, + GuildApplicationPremiumSubscription +} diff --git a/src/core/DSharpPlus.Shared/Enums/Channels/DiscordVideoQualityMode.cs b/src/core/DSharpPlus.Shared/Enums/Channels/DiscordVideoQualityMode.cs new file mode 100644 index 0000000000..a673a66e7b --- /dev/null +++ b/src/core/DSharpPlus.Shared/Enums/Channels/DiscordVideoQualityMode.cs @@ -0,0 +1,21 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Entities; + +/// +/// Lists different video quality modes +/// +public enum DiscordVideoQualityMode +{ + /// + /// Discord chooses the quality for optimal performance. + /// + Auto = 1, + + /// + /// 720p + /// + Full +} diff --git a/src/core/DSharpPlus.Shared/Enums/Guilds/DiscordGuildMemberFlags.cs b/src/core/DSharpPlus.Shared/Enums/Guilds/DiscordGuildMemberFlags.cs new file mode 100644 index 0000000000..5eeebffb4a --- /dev/null +++ b/src/core/DSharpPlus.Shared/Enums/Guilds/DiscordGuildMemberFlags.cs @@ -0,0 +1,37 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; + +namespace DSharpPlus.Entities; + +/// +/// Represents bitwise guild member flags. +/// +[Flags] +public enum DiscordGuildMemberFlags +{ + None = 0, + + /// + /// Indicates that this member has left and rejoined this guild. + /// + DidRejoin = 1 << 0, + + /// + /// Indicates that this member has completed guild onboarding. + /// + CompletedOnboarding = 1 << 1, + + /// + /// Indicates that this member is exempt from verification requirements. This flag can be set + /// by bots. + /// + BypassesVerification = 1 << 2, + + /// + /// Indicates that this member has started the guild onboarding process. + /// + StartedOnboarding = 1 << 3 +} diff --git a/src/core/DSharpPlus.Shared/Enums/Interactions/DiscordInteractionType.cs b/src/core/DSharpPlus.Shared/Enums/Interactions/DiscordInteractionType.cs new file mode 100644 index 0000000000..e2b1e311a8 --- /dev/null +++ b/src/core/DSharpPlus.Shared/Enums/Interactions/DiscordInteractionType.cs @@ -0,0 +1,17 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Entities; + +/// +/// Enumerates the types of inbound interactions. +/// +public enum DiscordInteractionType +{ + Ping = 1, + ApplicationCommand, + MessageComponent, + ApplicationCommandAutocomplete, + ModalSubmit +} diff --git a/src/core/DSharpPlus.Shared/Enums/MessageComponents/DiscordComponentType.cs b/src/core/DSharpPlus.Shared/Enums/MessageComponents/DiscordMessageComponentType.cs similarity index 96% rename from src/core/DSharpPlus.Shared/Enums/MessageComponents/DiscordComponentType.cs rename to src/core/DSharpPlus.Shared/Enums/MessageComponents/DiscordMessageComponentType.cs index a749efe70b..7596ae388d 100644 --- a/src/core/DSharpPlus.Shared/Enums/MessageComponents/DiscordComponentType.cs +++ b/src/core/DSharpPlus.Shared/Enums/MessageComponents/DiscordMessageComponentType.cs @@ -7,7 +7,7 @@ namespace DSharpPlus.Entities; /// /// Enumerates the different types of message components. /// -public enum DiscordComponentType +public enum DiscordMessageComponentType { /// /// A container for other components: up to five button or one non-button component. diff --git a/src/core/DSharpPlus.Shared/Enums/Stickers/DiscordStickerFormatType.cs b/src/core/DSharpPlus.Shared/Enums/Stickers/DiscordStickerFormatType.cs new file mode 100644 index 0000000000..a843b5a422 --- /dev/null +++ b/src/core/DSharpPlus.Shared/Enums/Stickers/DiscordStickerFormatType.cs @@ -0,0 +1,16 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Entities; + +/// +/// Enumerates different sticker file format types. +/// +public enum DiscordStickerFormatType +{ + Png = 1, + Apng, + Lottie, + Gif +} diff --git a/src/core/DSharpPlus.Shared/Enums/Teams/DiscordTeamMembershipState.cs b/src/core/DSharpPlus.Shared/Enums/Teams/DiscordTeamMembershipState.cs new file mode 100644 index 0000000000..4466fa7e02 --- /dev/null +++ b/src/core/DSharpPlus.Shared/Enums/Teams/DiscordTeamMembershipState.cs @@ -0,0 +1,14 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Entities; + +/// +/// Specifies the membership state of an user in a team. +/// +public enum DiscordTeamMembershipState +{ + Invited = 1, + Accepted +} From 44342c119376ce2d32b39827284d3e2e55a1ddb9 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sun, 4 Jun 2023 18:21:53 +0200 Subject: [PATCH 013/323] centralize internal version numbers too --- Directory.Build.props | 8 ++++++++ .../DSharpPlus.Core.Abstractions.Models.csproj | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Directory.Build.props b/Directory.Build.props index 861517eed1..a0fcf92879 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -35,4 +35,12 @@ https://raw.githubusercontent.com/DSharpPlus/DSharpPlus/master/logo/dsharpplus.png + + + + <_DSharpPlusReleaseVersion>6.0.0 + + <_DSharpPlusCoreAbstractionsModelsVersion>0.1.0 + + \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/DSharpPlus.Core.Abstractions.Models.csproj b/src/core/DSharpPlus.Core.Abstractions.Models/DSharpPlus.Core.Abstractions.Models.csproj index a43488257e..cf8ef52bde 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/DSharpPlus.Core.Abstractions.Models.csproj +++ b/src/core/DSharpPlus.Core.Abstractions.Models/DSharpPlus.Core.Abstractions.Models.csproj @@ -1,7 +1,7 @@  - 0.1.0 + $(_DSharpPlusCoreAbstractionsModelsVersion) $(Description) This package specifies a contract for the serialization models to implement. This definition is library-agnostic. Library From 1c6df91ab1496ebd7e3c41874958b11c3515ccb2 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sun, 4 Jun 2023 18:42:37 +0200 Subject: [PATCH 014/323] maybe don't do this twice --- Directory.Build.props | 2 -- 1 file changed, 2 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index a0fcf92879..8af4c2613f 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -12,8 +12,6 @@ True true - - <_DSharpPlusReleaseVersion>6.0.0 true From f02e9c8fc1356918d619a613ed77846371710cd4 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sun, 4 Jun 2023 21:27:00 +0200 Subject: [PATCH 015/323] add interaction response callback data objects --- .../Channels/IAllowedMentions.cs | 40 ++++++++++++++ .../Interactions/IAutocompleteCallbackData.cs | 18 +++++++ .../Interactions/IInteractionCallbackData.cs | 10 ++++ .../Interactions/IInteractionResponse.cs | 25 +++++++++ .../Interactions/IMessageCallbackData.cs | 52 +++++++++++++++++++ .../Interactions/IModalCallbackData.cs | 28 ++++++++++ .../DiscordInteractionCallbackType.cs | 49 +++++++++++++++++ 7 files changed, 222 insertions(+) create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/Channels/IAllowedMentions.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IAutocompleteCallbackData.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IInteractionCallbackData.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IInteractionResponse.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IMessageCallbackData.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IModalCallbackData.cs create mode 100644 src/core/DSharpPlus.Shared/Enums/Interactions/DiscordInteractionCallbackType.cs diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IAllowedMentions.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IAllowedMentions.cs new file mode 100644 index 0000000000..bb41ed4f52 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IAllowedMentions.cs @@ -0,0 +1,40 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using Remora.Rest.Core; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Stores information about what mentions should be allowed and which ones should be +/// ignored when handling read states and notifications. Refer to +/// +/// the Discord docs for further information. +/// +public interface IAllowedMentions +{ + /// + /// An array of allowed mention types to parse from the message content. This may contain + /// "roles" for parsing role mentions, "users" for parsing user mentions and + /// "everyone" for parsing @everyone and @here mentions. + /// + public IReadOnlyList Parse { get; } + + /// + /// An array of role IDs to mention, up to 100. + /// + public Optional> Roles { get; } + + /// + /// An array of user IDs to mention, up to 100. + /// + public Optional> Users { get; } + + /// + /// For replies, this controls whether to mention the author of the replied message. + /// + public Optional RepliedUser { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IAutocompleteCallbackData.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IAutocompleteCallbackData.cs new file mode 100644 index 0000000000..540b846b6b --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IAutocompleteCallbackData.cs @@ -0,0 +1,18 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Represents callback data for responding to an autocomplete interaction. +/// +public interface IAutocompleteCallbackData +{ + /// + /// Up to 25 choices for the end user to choose from. + /// + public IReadOnlyList Choices { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IInteractionCallbackData.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IInteractionCallbackData.cs new file mode 100644 index 0000000000..4e9e8f56a9 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IInteractionCallbackData.cs @@ -0,0 +1,10 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Represents a response message to an interaction. +/// +public interface IInteractionCallbackData; diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IInteractionResponse.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IInteractionResponse.cs new file mode 100644 index 0000000000..2f94fb23bf --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IInteractionResponse.cs @@ -0,0 +1,25 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Entities; + +using Remora.Rest.Core; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Represents an outgoing response to an interaction. +/// +public interface IInteractionResponse +{ + /// + /// The type of this response. + /// + public DiscordInteractionCallbackType Type { get; } + + /// + /// An additional response message for this interaction. + /// + public Optional Data { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IMessageCallbackData.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IMessageCallbackData.cs new file mode 100644 index 0000000000..9c440bcd78 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IMessageCallbackData.cs @@ -0,0 +1,52 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Entities; + +using Remora.Rest.Core; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Represents a response payload for creating or updating a message. +/// +public interface IMessageCallbackData : IInteractionCallbackData +{ + /// + /// Indicates whether the response is a TTS message. + /// + public Optional Tts { get; } + + /// + /// The message content. + /// + public Optional Content { get; } + + /// + /// An array of up to 10 embeds to be attached to the message. + /// + public Optional> Embeds { get; } + + /// + /// An allowed mentions object controlling mention behaviour for this method. + /// + public Optional AllowedMentions { get; } + + /// + /// Message flags for this message; only SuppressEmbeds and Ephemeral can be set. + /// + public Optional Flags { get; } + + /// + /// Up to five action rows of components to attach to this message. + /// + public Optional> Components { get; } + + /// + /// Attachments to this message. + /// + public Optional> Attachments { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IModalCallbackData.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IModalCallbackData.cs new file mode 100644 index 0000000000..1c830e0118 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IModalCallbackData.cs @@ -0,0 +1,28 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Represents callback data for creating a modal. +/// +public interface IModalCallbackData +{ + /// + /// The developer-defined custom identifier for this modal, up to 100 characters. + /// + public string CustomId { get; } + + /// + /// The title of the modal, up to 45 characters. + /// + public string Title { get; } + + /// + /// Between 1 and 5 action rows containing each one text input component. + /// + public IReadOnlyList Components { get; } +} diff --git a/src/core/DSharpPlus.Shared/Enums/Interactions/DiscordInteractionCallbackType.cs b/src/core/DSharpPlus.Shared/Enums/Interactions/DiscordInteractionCallbackType.cs new file mode 100644 index 0000000000..f21bd55dd9 --- /dev/null +++ b/src/core/DSharpPlus.Shared/Enums/Interactions/DiscordInteractionCallbackType.cs @@ -0,0 +1,49 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Entities; + +/// +/// Represents the different ways of responding to different interactions. +/// +public enum DiscordInteractionCallbackType +{ + /// + /// Acknowledges a . + /// + Pong = 1, + + /// + /// Responds to an interaction by sending a message. + /// + ChannelMessageWithSource = 4, + + /// + /// Acknowledges an interaction and allows the bot to edit a response in later; the user + /// sees a loading state. + /// + DeferredChannelMessageWithSource, + + /// + /// Acknowledges a component interaction and allows the bot to edit a response in later; + /// the user does not see a loading state. + /// + DeferredUpdateMessage, + + /// + /// Responds to a component interaction by editing the message the component was attached to. + /// + UpdateMessage, + + /// + /// Responds to an autocomplete interaction by suggesting choices. + /// + ApplicationCommandAutocompleteResult, + + /// + /// Responds to an interaction with a pop-up modal. This cannot be sent in response to a modal + /// submission or a ping. + /// + Modal +} From 23fb1c899c3b190b725f67b467d2bacdf461ab25 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sun, 4 Jun 2023 21:48:39 +0200 Subject: [PATCH 016/323] fully-populated application object --- .../Applications/IApplication.cs | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/Applications/IApplication.cs diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Applications/IApplication.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Applications/IApplication.cs new file mode 100644 index 0000000000..dcc80f6a10 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Applications/IApplication.cs @@ -0,0 +1,57 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using Remora.Rest.Core; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Represents an application, such as a bot, on Discord. +/// +public interface IApplication : IPartialApplication +{ + /// + public new Snowflake Id { get; } + + /// + public new string Name { get; } + + /// + public new string? Icon { get; } + + /// + public new bool BotPublic { get; } + + /// + public new bool BotRequireCodeGrant { get; } + + /// + public new string VerifyKey { get; } + + /// + public new ITeam? Team { get; } + + // explicit routes for partial application access + + /// + Optional IPartialApplication.Id => this.Id; + + /// + Optional IPartialApplication.Name => this.Name; + + /// + Optional IPartialApplication.Icon => this.Icon; + + /// + Optional IPartialApplication.BotPublic => this.BotPublic; + + /// + Optional IPartialApplication.BotRequireCodeGrant => this.BotRequireCodeGrant; + + /// + Optional IPartialApplication.VerifyKey => this.VerifyKey; + + /// + Optional IPartialApplication.Team => new(this.Team); +} From cdf0815d96c7c3a4f5aefee1dc8be4bab60ad88e Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Mon, 5 Jun 2023 18:52:21 +0200 Subject: [PATCH 017/323] role connection metadata --- .../IRoleConnectionMetadata.cs | 47 +++++++++++++++++ .../DiscordRoleConnectionMetadataType.cs | 51 +++++++++++++++++++ 2 files changed, 98 insertions(+) create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/RoleConnections/IRoleConnectionMetadata.cs create mode 100644 src/core/DSharpPlus.Shared/Enums/RoleConnections/DiscordRoleConnectionMetadataType.cs diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/RoleConnections/IRoleConnectionMetadata.cs b/src/core/DSharpPlus.Core.Abstractions.Models/RoleConnections/IRoleConnectionMetadata.cs new file mode 100644 index 0000000000..00cbc6d1b4 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/RoleConnections/IRoleConnectionMetadata.cs @@ -0,0 +1,47 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Entities; + +using Remora.Rest.Core; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Contains role connection metadata for an application. +/// +public interface IRoleConnectionMetadata +{ + /// + /// The type and comparison type of the metadata value. + /// + public DiscordRoleConnectionMetadataType Type { get; } + + /// + /// The dictionary key for the metadata field, between 1 and 50 characters. + /// + public string Key { get; } + + /// + /// The name of this metadata field, between 1 and 100 characters. + /// + public string Name { get; } + + /// + /// A localization dictionary for , with the keys being locales. + /// + public Optional?> NameLocalizations { get; } + + /// + /// A description for this metadata field, between 1 and 200 characters. + /// + public string Description { get; } + + /// + /// A localization dictionary for , with the keys being locales. + /// + public Optional?> DescriptionLocalizations { get; } +} diff --git a/src/core/DSharpPlus.Shared/Enums/RoleConnections/DiscordRoleConnectionMetadataType.cs b/src/core/DSharpPlus.Shared/Enums/RoleConnections/DiscordRoleConnectionMetadataType.cs new file mode 100644 index 0000000000..7a545b5ec7 --- /dev/null +++ b/src/core/DSharpPlus.Shared/Enums/RoleConnections/DiscordRoleConnectionMetadataType.cs @@ -0,0 +1,51 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Entities; + +/// +/// The specific kinds of metadata comparisons that can be made. +/// +public enum DiscordRoleConnectionMetadataType +{ + /// + /// The metadata integer is less than or equal to the guild's configured value. + /// + IntegerLessThanOrEqual = 1, + + /// + /// The metadata integer is greater than or equal to the guild's configured value. + /// + IntegerGreaterThanOrEqual, + + /// + /// The metadata integer is equal to the guild's configured value. + /// + IntegerEqual, + + /// + /// The metadata integer is not equal to the guild's configured value. + /// + IntegerNotEqual, + + /// + /// The metadata date/time object is less than or equal to the guild's configured value. + /// + DateTimeLessThanOrEqual, + + /// + /// The metadata date/time object is greater than or equal to the guild's configured value. + /// + DateTimeGreaterThanOrEqual, + + /// + /// The metadata boolean is equal to the guild's configured value. + /// + BooleanEqual, + + /// + /// The metadata boolean is not equal to the guild's configured value. + /// + BooleanNotEqual +} From a3940d91aaa88af9d7490f36ba770bc3ab3c56d5 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Fri, 9 Jun 2023 13:23:22 +0200 Subject: [PATCH 018/323] bots dont get pomelo'd yet --- .../Users/IPartialUser.cs | 5 +++++ src/core/DSharpPlus.Core.Abstractions.Models/Users/IUser.cs | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Users/IPartialUser.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Users/IPartialUser.cs index e523648627..3134c3fef2 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Users/IPartialUser.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Users/IPartialUser.cs @@ -22,6 +22,11 @@ public interface IPartialUser /// public Optional Username { get; } + /// + /// The four-digit discriminator of this user if it is a bot; "0" if this is an user account. + /// + public Optional Discriminator { get; } + /// /// The global display name of this user. /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Users/IUser.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Users/IUser.cs index 79bd0c66a9..ef353c6cb3 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Users/IUser.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Users/IUser.cs @@ -17,6 +17,9 @@ public interface IUser : IPartialUser /// public new string Username { get; } + /// + public new string Discriminator { get; } + /// public new string? GlobalName { get; } @@ -31,6 +34,9 @@ public interface IUser : IPartialUser /// Optional IPartialUser.Username => this.Username; + /// + Optional IPartialUser.Discriminator => this.Discriminator; + /// Optional IPartialUser.GlobalName => this.GlobalName; From 8365964159d1ebfd70e0b19157fd32687ef85e0f Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Fri, 16 Jun 2023 12:48:53 +0200 Subject: [PATCH 019/323] define guild objects --- Directory.Build.props | 2 + .../Emojis/IEmoji.cs | 27 ++ .../Guilds/IGuild.cs | 187 ++++++++++++++ .../Guilds/IPartialGuild.cs | 230 ++++++++++++++++++ .../Guilds/IWelcomeScreen.cs | 23 ++ .../Guilds/IWelcomeScreenChannel.cs | 34 +++ .../Stickers/ISticker.cs | 74 ++++++ .../DSharpPlus.Shared.csproj | 3 + .../DiscordExplicitContentFilterLevel.cs | 26 ++ .../Guilds/DiscordMessageNotificationLevel.cs | 21 ++ .../Enums/Guilds/DiscordMfaLevel.cs | 21 ++ .../Enums/Guilds/DiscordNsfwLevel.cs | 16 ++ .../Enums/Guilds/DiscordSystemChannelFlags.cs | 43 ++++ .../Enums/Guilds/DiscordVerificationLevel.cs | 36 +++ .../Enums/Stickers/DiscordStickerType.cs | 22 ++ 15 files changed, 765 insertions(+) create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/Emojis/IEmoji.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IGuild.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IPartialGuild.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IWelcomeScreen.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IWelcomeScreenChannel.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/Stickers/ISticker.cs create mode 100644 src/core/DSharpPlus.Shared/Enums/Guilds/DiscordExplicitContentFilterLevel.cs create mode 100644 src/core/DSharpPlus.Shared/Enums/Guilds/DiscordMessageNotificationLevel.cs create mode 100644 src/core/DSharpPlus.Shared/Enums/Guilds/DiscordMfaLevel.cs create mode 100644 src/core/DSharpPlus.Shared/Enums/Guilds/DiscordNsfwLevel.cs create mode 100644 src/core/DSharpPlus.Shared/Enums/Guilds/DiscordSystemChannelFlags.cs create mode 100644 src/core/DSharpPlus.Shared/Enums/Guilds/DiscordVerificationLevel.cs create mode 100644 src/core/DSharpPlus.Shared/Enums/Stickers/DiscordStickerType.cs diff --git a/Directory.Build.props b/Directory.Build.props index 8af4c2613f..85819ac53f 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -12,6 +12,7 @@ True true + true true @@ -38,6 +39,7 @@ <_DSharpPlusReleaseVersion>6.0.0 + <_DSharpPlusCoreAbstractionsModelsVersion>0.1.0 diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Emojis/IEmoji.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Emojis/IEmoji.cs new file mode 100644 index 0000000000..3c57432300 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Emojis/IEmoji.cs @@ -0,0 +1,27 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using Remora.Rest.Core; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Represents a fully populated emoji object. +/// +public interface IEmoji : IPartialEmoji +{ + /// + public new Snowflake? Id { get; } + + /// + public new string? Name { get; } + + // direct partial access routes + + /// + Optional IPartialEmoji.Id => this.Id; + + /// + Optional IPartialEmoji.Name => this.Name; +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IGuild.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IGuild.cs new file mode 100644 index 0000000000..58b8928ac6 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IGuild.cs @@ -0,0 +1,187 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Entities; + +using Remora.Rest.Core; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Represents a fully populated guild object. +/// +public interface IGuild : IPartialGuild +{ + /// + public new Snowflake Id { get; } + + /// + public new string Name { get; } + + /// + public new string? Icon { get; } + + /// + public new string? Splash { get; } + + /// + public new string? DiscoverySplash { get; } + + /// + public new Snowflake OwnerId { get; } + + /// + public new Snowflake? AfkChannelId { get; } + + /// + public new int AfkTimeout { get; } + + /// + public new DiscordVerificationLevel VerificationLevel { get; } + + /// + public new DiscordMessageNotificationLevel DefaultMessageNotifications { get; } + + /// + public new DiscordExplicitContentFilterLevel ExplicitContentFilter { get; } + + /// + public new IReadOnlyList Roles { get; } + + /// + public new IReadOnlyList Emojis { get; } + + /// + public new IReadOnlyList Features { get; } + + /// + public new DiscordMfaLevel MfaLevel { get; } + + /// + public new Snowflake? ApplicationId { get; } + + /// + public new Snowflake? SystemChannelId { get; } + + /// + public new DiscordSystemChannelFlags SystemChannelFlags { get; } + + /// + public new Snowflake? RulesChannelId { get; } + + /// + public new string? VanityUrlCode { get; } + + /// + public new string? Description { get; } + + /// + public new string? Banner { get; } + + /// + public new int PremiumTier { get; } + + /// + public new string PreferredLocale { get; } + + /// + public new Snowflake? PublicUpdatesChannelId { get; } + + /// + public new DiscordNsfwLevel NsfwLevel { get; } + + /// + public new bool PremiumProgressBarEnabled { get; } + + /// + public new Snowflake? SafetyAlertsChannelId { get; } + + // routes for partial access + + /// + Optional IPartialGuild.Id => this.Id; + + /// + Optional IPartialGuild.Name => this.Name; + + /// + Optional IPartialGuild.Icon => this.Icon; + + /// + Optional IPartialGuild.Splash => this.Splash; + + /// + Optional IPartialGuild.DiscoverySplash => this.DiscoverySplash; + + /// + Optional IPartialGuild.OwnerId => this.OwnerId; + + /// + Optional IPartialGuild.AfkChannelId => this.AfkChannelId; + + /// + Optional IPartialGuild.AfkTimeout => this.AfkTimeout; + + /// + Optional IPartialGuild.VerificationLevel => this.VerificationLevel; + + /// + Optional IPartialGuild.DefaultMessageNotifications => this.DefaultMessageNotifications; + + /// + Optional IPartialGuild.ExplicitContentFilter => this.ExplicitContentFilter; + + /// + Optional> IPartialGuild.Roles => new(this.Roles); + + /// + Optional> IPartialGuild.Emojis => new(this.Emojis); + + /// + Optional> IPartialGuild.Features => new(this.Features); + + /// + Optional IPartialGuild.MfaLevel => this.MfaLevel; + + /// + Optional IPartialGuild.ApplicationId => this.ApplicationId; + + /// + Optional IPartialGuild.SystemChannelId => this.SystemChannelId; + + /// + Optional IPartialGuild.SystemChannelFlags => this.SystemChannelFlags; + + /// + Optional IPartialGuild.RulesChannelId => this.RulesChannelId; + + /// + Optional IPartialGuild.VanityUrlCode => this.VanityUrlCode; + + /// + Optional IPartialGuild.Description => this.Description; + + /// + Optional IPartialGuild.Banner => this.Banner; + + /// + Optional IPartialGuild.PremiumTier => this.PremiumTier; + + /// + Optional IPartialGuild.PreferredLocale => this.PreferredLocale; + + /// + Optional IPartialGuild.PublicUpdatesChannelId => this.PublicUpdatesChannelId; + + /// + Optional IPartialGuild.NsfwLevel => this.NsfwLevel; + + /// + Optional IPartialGuild.PremiumProgressBarEnabled => this.PremiumProgressBarEnabled; + + /// + Optional IPartialGuild.SafetyAlertsChannelId => this.SafetyAlertsChannelId; +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IPartialGuild.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IPartialGuild.cs new file mode 100644 index 0000000000..35358448bc --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IPartialGuild.cs @@ -0,0 +1,230 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Entities; + +using Remora.Rest.Core; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Represents a partially populated guild object. +/// +public interface IPartialGuild +{ + /// + /// The snowflake identifier of this guild. + /// + public Optional Id { get; } + + /// + /// The name of this guild, between 2 and 100 characters. + /// + public Optional Name { get; } + + /// + /// The icon hash for this guild. + /// + public Optional Icon { get; } + + /// + /// The icon hash for this guild. This field, unlike , is only sent when a part of + /// the guild template object. + /// + public Optional IconHash { get; } + + /// + /// The splash hash for this guild. + /// + public Optional Splash { get; } + + /// + /// The discovery splash hash for this guild, only present for discoverable guilds. + /// + public Optional DiscoverySplash { get; } + + /// + /// Indicates whether the current user owns this guild. + /// + public Optional Owner { get; } + + /// + /// The snowflake identifier of the user owning this guild. + /// + public Optional OwnerId { get; } + + /// + /// The permissions for the current user, excluding overwrites. + /// + public Optional Permissions { get; } + + /// + /// The snowflake identifier of the afk voice channel. + /// + public Optional AfkChannelId { get; } + + /// + /// The voice afk timeout in seconds. + /// + public Optional AfkTimeout { get; } + + /// + /// Indicates whether the guild widget is enabled. + /// + public Optional WidgetEnabled { get; } + + /// + /// The snowflake identifier of the channel that the guild widget will generate an invite to. + /// + public Optional WidgetChannelId { get; } + + /// + /// Indicates the verification level required to chat in this guild. + /// + public Optional VerificationLevel { get; } + + /// + /// Indicates the default message notification setting. + /// + public Optional DefaultMessageNotifications { get; } + + /// + /// Indicates the default severity level of the explicit content filter. + /// + public Optional ExplicitContentFilter { get; } + + /// + /// The roles within this guild. + /// + public Optional> Roles { get; } + + /// + /// The custom guild emojis for this guild. + /// + public Optional> Emojis { get; } + + /// + /// The enabled guild feature identifiers for this guild. + /// + public Optional> Features { get; } + + /// + /// The required MFA level for moderation actions in this guild. + /// + public Optional MfaLevel { get; } + + /// + /// The snowflake identifier of the application that created this guild, if it was created by a bot. + /// + public Optional ApplicationId { get; } + + /// + /// The snowflake identifier of the channel where guild notices such as welcome messages and boost + /// messages are sent. + /// + public Optional SystemChannelId { get; } + + /// + /// Additional settings for the system channel in this guild, represented as flags. + /// + public Optional SystemChannelFlags { get; } + + /// + /// The snowflake identifier of the channel where community servers display rules and guidelines. + /// + public Optional RulesChannelId { get; } + + /// + /// The maximum number of presences for this guild. This will nearly always be , + /// except for the largest guilds. + /// + public Optional MaxPresences { get; } + + /// + /// The member limit for this guild. + /// + public Optional MaxMembers { get; } + + /// + /// The vanity invite code for this guild. + /// + public Optional VanityUrlCode { get; } + + /// + /// The description of this guild. + /// + public Optional Description { get; } + + /// + /// The banner image hash for this guild. + /// + public Optional Banner { get; } + + /// + /// The server boost level for this guild. + /// + public Optional PremiumTier { get; } + + /// + /// The amount of server boosts this guild has. + /// + public Optional PremiumSubscriptionCount { get; } + + /// + /// The preferred locale of a community guild, defaults to "en-US". + /// + public Optional PreferredLocale { get; } + + /// + /// The snowflake identifier of the channel where official notices from Discord are sent to. + /// + public Optional PublicUpdatesChannelId { get; } + + /// + /// The maximum amount of users in a video channel. + /// + public Optional MaxVideoChannelUsers { get; } + + /// + /// The maximum amount of users in a stage video channel. + /// + public Optional MaxStageVideoChannelUsers { get; } + + /// + /// The approximate number of members in this guild. + /// + public Optional ApproximateMemberCount { get; } + + /// + /// The approximate number of non-offline members in this guild. + /// + public Optional ApproximatePresenceCount { get; } + + /// + /// The welcome screen of a community guild, shown to new members. + /// + public Optional WelcomeScreen { get; } + + /// + /// The NSFW level of this guild. + /// + public Optional NsfwLevel { get; } + + /// + /// The custom guild stickers. + /// + public Optional> Stickers { get; } + + /// + /// Indicates whether this guild has the boost progress bar enabled. + /// + public Optional PremiumProgressBarEnabled { get; } + + /// + /// The snowflake identifier of the channel where community servers receive safety alerts. + /// + public Optional SafetyAlertsChannelId { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IWelcomeScreen.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IWelcomeScreen.cs new file mode 100644 index 0000000000..54ba6e94e4 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IWelcomeScreen.cs @@ -0,0 +1,23 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Represents a guild welcome screen, showing the user a brief description and a few channels to check out. +/// +public interface IWelcomeScreen +{ + /// + /// The server description as shown in the welcome screen. + /// + public string? Description { get; } + + /// + /// The channels shown in the welcome screen, up to five. + /// + public IReadOnlyList WelcomeChannels { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IWelcomeScreenChannel.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IWelcomeScreenChannel.cs new file mode 100644 index 0000000000..59a215e89d --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IWelcomeScreenChannel.cs @@ -0,0 +1,34 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using Remora.Rest.Core; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Represents a single shown in the welcome screen. +/// +public interface IWelcomeScreenChannel +{ + /// + /// The snowflake identifier of the channel. + /// + public Snowflake ChannelId { get; } + + /// + /// The description shown for this channel. + /// + public string Description { get; } + + /// + /// The snowflake identifier of the associated emoji, if this is a custom emoji. + /// + public Snowflake? EmojiId { get; } + + /// + /// The emoji name of the associated emoji if this is a custom emoji; the unicode character if this is + /// a default emoji, or if no emoji is set. + /// + public string? EmojiName { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Stickers/ISticker.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Stickers/ISticker.cs new file mode 100644 index 0000000000..7e03c7cea5 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Stickers/ISticker.cs @@ -0,0 +1,74 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Entities; + +using Remora.Rest.Core; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Represents a discord sticker that can be sent in messages. +/// +public interface ISticker +{ + /// + /// The snowflake identifier of this sticker. + /// + public Snowflake Id { get; } + + /// + /// For standard stickers, the snowflake identifier of the pack the sticker is from. + /// + public Optional PackId { get; } + + /// + /// The name of this sticker. + /// + public string Name { get; } + + /// + /// The description of this sticker. + /// + public string? Description { get; } + + /// + /// Autocomplete/suggestion tags for this sticker, up to 200 characters. + /// + /// + /// For standard stickers, this is a comma separated list of keywords. When creating or modifying a guild + /// sticker, the client will always use a name generated from an emoji here. + /// + public string Tags { get; } + + /// + /// The type of this sticker. + /// + public DiscordStickerType Type { get; } + + /// + /// The type of this sticker file format. + /// + public DiscordStickerFormatType FormatType { get; } + + /// + /// Indicates whether this sticker can be used. + /// + public Optional Available { get; } + + /// + /// The snowflake identifier of the guild that owns this object. + /// + public Optional GuildId { get; } + + /// + /// The user that uploaded this sticker. + /// + public Optional User { get; } + + /// + /// If this is a standard sticker, the sort order within its pack. + /// + public Optional SortValue { get; } +} diff --git a/src/core/DSharpPlus.Shared/DSharpPlus.Shared.csproj b/src/core/DSharpPlus.Shared/DSharpPlus.Shared.csproj index 4e6043f397..376b8fdc37 100644 --- a/src/core/DSharpPlus.Shared/DSharpPlus.Shared.csproj +++ b/src/core/DSharpPlus.Shared/DSharpPlus.Shared.csproj @@ -1,6 +1,9 @@  + + netstandard2.0;$(TargetFramework) + true $(Description) This package contains shared types between public-facing and internal implementation packages. Library diff --git a/src/core/DSharpPlus.Shared/Enums/Guilds/DiscordExplicitContentFilterLevel.cs b/src/core/DSharpPlus.Shared/Enums/Guilds/DiscordExplicitContentFilterLevel.cs new file mode 100644 index 0000000000..3f1143f4f8 --- /dev/null +++ b/src/core/DSharpPlus.Shared/Enums/Guilds/DiscordExplicitContentFilterLevel.cs @@ -0,0 +1,26 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Entities; + +/// +/// Specifies the severity of the explicit content filter in the given guild. +/// +public enum DiscordExplicitContentFilterLevel +{ + /// + /// Media content will not be scanned. + /// + Disabled, + + /// + /// Media content sent by members without roles will be scanned. + /// + MembersWithoutRoles, + + /// + /// Media content sent by all members will be scanned. + /// + AllMembers +} diff --git a/src/core/DSharpPlus.Shared/Enums/Guilds/DiscordMessageNotificationLevel.cs b/src/core/DSharpPlus.Shared/Enums/Guilds/DiscordMessageNotificationLevel.cs new file mode 100644 index 0000000000..8805e6e85e --- /dev/null +++ b/src/core/DSharpPlus.Shared/Enums/Guilds/DiscordMessageNotificationLevel.cs @@ -0,0 +1,21 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Entities; + +/// +/// The default notification settings for a guild. +/// +public enum DiscordMessageNotificationLevel +{ + /// + /// Members will, by default, receive notifications for all messages. + /// + AllMessages, + + /// + /// Members will, by default, receive notifications only for messages mentioning them specifically. + /// + OnlyMentions +} diff --git a/src/core/DSharpPlus.Shared/Enums/Guilds/DiscordMfaLevel.cs b/src/core/DSharpPlus.Shared/Enums/Guilds/DiscordMfaLevel.cs new file mode 100644 index 0000000000..a588fc0fd3 --- /dev/null +++ b/src/core/DSharpPlus.Shared/Enums/Guilds/DiscordMfaLevel.cs @@ -0,0 +1,21 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Entities; + +/// +/// Indicates multi-factor-auth (MFA) requirements for moderation actions. +/// +public enum DiscordMfaLevel +{ + /// + /// This guild has no MFA requirement for moderation actions. + /// + None, + + /// + /// This guild has a 2FA requirement for moderation actions. + /// + Elevated +} diff --git a/src/core/DSharpPlus.Shared/Enums/Guilds/DiscordNsfwLevel.cs b/src/core/DSharpPlus.Shared/Enums/Guilds/DiscordNsfwLevel.cs new file mode 100644 index 0000000000..1f2ba0b876 --- /dev/null +++ b/src/core/DSharpPlus.Shared/Enums/Guilds/DiscordNsfwLevel.cs @@ -0,0 +1,16 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Entities; + +/// +/// Enumerates NSFW levels for a certain guild. +/// +public enum DiscordNsfwLevel +{ + Default, + Explicit, + Safe, + AgeRestricted +} diff --git a/src/core/DSharpPlus.Shared/Enums/Guilds/DiscordSystemChannelFlags.cs b/src/core/DSharpPlus.Shared/Enums/Guilds/DiscordSystemChannelFlags.cs new file mode 100644 index 0000000000..d79b1414a1 --- /dev/null +++ b/src/core/DSharpPlus.Shared/Enums/Guilds/DiscordSystemChannelFlags.cs @@ -0,0 +1,43 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Entities; + +/// +/// Represents additional settings for system channels. +/// +public enum DiscordSystemChannelFlags +{ + None = 0, + + /// + /// Disables member join messages in this channel. + /// + SuppressJoinNotifications = 1 << 0, + + /// + /// Disables server boost notifications in this channel. + /// + SuppressPremiumSubscriptions = 1 << 1, + + /// + /// Disables server setup tips in this channnel. + /// + SuppressGuildReminderNotifications = 1 << 2, + + /// + /// Disables the sticker reply buttons on member join messages. + /// + SuppressJoinNotificationReplies = 1 << 3, + + /// + /// Disables role subscription purchase and renewal notifications in this channel. + /// + SuppressRoleSubscriptionPurchaseNotifications = 1 << 4, + + /// + /// Disables the sticker reply buttons on role subscription purchase and renewal messages. + /// + SuppressRoleSubscriptionPurchaseNotificationReplies = 1 << 5 +} diff --git a/src/core/DSharpPlus.Shared/Enums/Guilds/DiscordVerificationLevel.cs b/src/core/DSharpPlus.Shared/Enums/Guilds/DiscordVerificationLevel.cs new file mode 100644 index 0000000000..e5700df29f --- /dev/null +++ b/src/core/DSharpPlus.Shared/Enums/Guilds/DiscordVerificationLevel.cs @@ -0,0 +1,36 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Entities; + +/// +/// Enumerates the levels of verification restriction required to speak in a guild. +/// +public enum DiscordVerificationLevel +{ + /// + /// Unrestricted. + /// + None, + + /// + /// The user must have a verified email. + /// + Low, + + /// + /// This user must be registered on Discord for longer than five minutes. + /// + Medium, + + /// + /// This user must have been a member of this server for longer than ten minutes. + /// + High, + + /// + /// This user must have a verified phone number. + /// + VeryHigh +} diff --git a/src/core/DSharpPlus.Shared/Enums/Stickers/DiscordStickerType.cs b/src/core/DSharpPlus.Shared/Enums/Stickers/DiscordStickerType.cs new file mode 100644 index 0000000000..e48f1282f7 --- /dev/null +++ b/src/core/DSharpPlus.Shared/Enums/Stickers/DiscordStickerType.cs @@ -0,0 +1,22 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Entities; + +/// +/// Specifies whether the given sticker belongs to a guild or is a default sticker. +/// +public enum DiscordStickerType +{ + /// + /// Indicates an official sticker in a sticker pack; a nitro sticker or a part of + /// a removed purchasable pack. + /// + Standard = 1, + + /// + /// Indicates a sticker uploaded to a guild. + /// + Guild +} From 83f78abdb68601601925f158697ac7bda03faa08 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sat, 24 Jun 2023 16:50:15 +0200 Subject: [PATCH 020/323] model automod --- .../AutoModeration/IAutoModerationAction.cs | 25 +++++++ .../IAutoModerationActionMetadata.cs | 11 +++ .../AutoModeration/IAutoModerationRule.cs | 72 +++++++++++++++++++ .../IAutoModerationTriggerMetadata.cs | 53 ++++++++++++++ .../IBlockMessageActionMetadata.cs | 21 ++++++ .../ISendAlertMessageActionMetadata.cs | 21 ++++++ .../AutoModeration/ITimeoutActionMetadata.cs | 19 +++++ .../DiscordAutoModerationActionType.cs | 29 ++++++++ .../DiscordAutoModerationEventType.cs | 16 +++++ .../DiscordAutoModerationPresetType.cs | 27 +++++++ .../DiscordAutoModerationTriggerType.cs | 32 +++++++++ 11 files changed, 326 insertions(+) create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/AutoModeration/IAutoModerationAction.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/AutoModeration/IAutoModerationActionMetadata.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/AutoModeration/IAutoModerationRule.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/AutoModeration/IAutoModerationTriggerMetadata.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/AutoModeration/IBlockMessageActionMetadata.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/AutoModeration/ISendAlertMessageActionMetadata.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/AutoModeration/ITimeoutActionMetadata.cs create mode 100644 src/core/DSharpPlus.Shared/Enums/AutoModeration/DiscordAutoModerationActionType.cs create mode 100644 src/core/DSharpPlus.Shared/Enums/AutoModeration/DiscordAutoModerationEventType.cs create mode 100644 src/core/DSharpPlus.Shared/Enums/AutoModeration/DiscordAutoModerationPresetType.cs create mode 100644 src/core/DSharpPlus.Shared/Enums/AutoModeration/DiscordAutoModerationTriggerType.cs diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/AutoModeration/IAutoModerationAction.cs b/src/core/DSharpPlus.Core.Abstractions.Models/AutoModeration/IAutoModerationAction.cs new file mode 100644 index 0000000000..5ac15fc5f1 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/AutoModeration/IAutoModerationAction.cs @@ -0,0 +1,25 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Entities; + +using Remora.Rest.Core; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Represents an action which will execute whenever a rule is triggered. +/// +public interface IAutoModerationAction +{ + /// + /// The type of this action. + /// + public DiscordAutoModerationActionType Type { get; } + + /// + /// Additional metadata for executing this action. + /// + public Optional Metadata { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/AutoModeration/IAutoModerationActionMetadata.cs b/src/core/DSharpPlus.Core.Abstractions.Models/AutoModeration/IAutoModerationActionMetadata.cs new file mode 100644 index 0000000000..03edaba270 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/AutoModeration/IAutoModerationActionMetadata.cs @@ -0,0 +1,11 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Represents additional metadata provided to automod actions. Cast to a specialized interface to +/// retrieve this metadata. +/// +public interface IAutoModerationActionMetadata; diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/AutoModeration/IAutoModerationRule.cs b/src/core/DSharpPlus.Core.Abstractions.Models/AutoModeration/IAutoModerationRule.cs new file mode 100644 index 0000000000..6758fbab40 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/AutoModeration/IAutoModerationRule.cs @@ -0,0 +1,72 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Entities; + +using Remora.Rest.Core; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Represents an auto moderation rule within a guild. +/// +public interface IAutoModerationRule +{ + /// + /// The snowflake identifier of this rule. + /// + public Snowflake Id { get; } + + /// + /// The snowflake identifier of the guild this rule belongs to. + /// + public Snowflake GuildId { get; } + + /// + /// The display name of this rule. + /// + public string Name { get; } + + /// + /// The snowflake identifier of the user who created this rule. + /// + public Snowflake CreatorId { get; } + + /// + /// The type of event that causes this rule to fire. + /// + public DiscordAutoModerationEventType EventType { get; } + + /// + /// The trigger type of this rule. + /// + public DiscordAutoModerationTriggerType TriggerType { get; } + + /// + /// Additional metadata for this rule trigger. + /// + public IAutoModerationTriggerMetadata TriggerMetadata { get; } + + /// + /// The actions which wille xecute when this rule is triggered. + /// + public IReadOnlyList Actions { get; } + + /// + /// Indicates whether this rule should be enabled. + /// + public bool Enabled { get; } + + /// + /// Up to 20 role IDs that should be exempted from this rule. + /// + public IReadOnlyList ExemptRoles { get; } + + /// + /// Up to 50 channel IDs that should be exempted from this rule. + /// + public IReadOnlyList ExemptChannels { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/AutoModeration/IAutoModerationTriggerMetadata.cs b/src/core/DSharpPlus.Core.Abstractions.Models/AutoModeration/IAutoModerationTriggerMetadata.cs new file mode 100644 index 0000000000..e1be63116f --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/AutoModeration/IAutoModerationTriggerMetadata.cs @@ -0,0 +1,53 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Entities; + +using Remora.Rest.Core; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Represents additional rule metadata, based on the configured trigger. +/// +/// +/// Which fields may be meaningful depends on the trigger type of the parent rule, see +/// +/// the documentation for additional information. +/// +public interface IAutoModerationTriggerMetadata +{ + /// + /// Substrings which the automod will search for in message content, up to 1000. + /// + public Optional> KeywordFilter { get; } + + /// + /// Rust-flavoured regex patterns which will be matched against message content, up to 10. + /// + public Optional> RegexPatterns { get; } + + /// + /// The pre-defined wordsets that will be searched for in message content. + /// + public Optional> Presets { get; } + + /// + /// Substrings which will not trigger the rule, even if otherwise filtered out. The maximum + /// depends on the parent trigger type. + /// + public Optional> AllowList { get; } + + /// + /// The total number of unique role and user mentions allowed per message, up to 50. + /// + public Optional MentionTotalLimit { get; } + + /// + /// Indicates whether mention raid detection is enabled. + /// + public Optional MentionRaidProtectionEnabled { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/AutoModeration/IBlockMessageActionMetadata.cs b/src/core/DSharpPlus.Core.Abstractions.Models/AutoModeration/IBlockMessageActionMetadata.cs new file mode 100644 index 0000000000..5ce77215a8 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/AutoModeration/IBlockMessageActionMetadata.cs @@ -0,0 +1,21 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Entities; + +using Remora.Rest.Core; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Represents metadata for auto moderation actions of type +/// . +/// +public interface IBlockMessageActionMetadata : IAutoModerationActionMetadata +{ + /// + /// An explanation that will be shown to members whenever their message is blocked, up to 150 characters. + /// + public Optional CustomMessage { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/AutoModeration/ISendAlertMessageActionMetadata.cs b/src/core/DSharpPlus.Core.Abstractions.Models/AutoModeration/ISendAlertMessageActionMetadata.cs new file mode 100644 index 0000000000..f045bdac72 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/AutoModeration/ISendAlertMessageActionMetadata.cs @@ -0,0 +1,21 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Entities; + +using Remora.Rest.Core; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Represents metadata for auto moderation actions of type +/// . +/// +public interface ISendAlertMessageActionMetadata +{ + /// + /// The snowflake identifier of the channel to which content should be logged. + /// + public Snowflake ChannelId { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/AutoModeration/ITimeoutActionMetadata.cs b/src/core/DSharpPlus.Core.Abstractions.Models/AutoModeration/ITimeoutActionMetadata.cs new file mode 100644 index 0000000000..93929505e1 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/AutoModeration/ITimeoutActionMetadata.cs @@ -0,0 +1,19 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Entities; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Represents metadata for auto moderation actions of type +/// . +/// +public interface ITimeoutActionMetadata : IAutoModerationActionMetadata +{ + /// + /// The timeout duration in seconds, up to 2419200 seconds, or 28 days. + /// + public int DurationSeconds { get; } +} diff --git a/src/core/DSharpPlus.Shared/Enums/AutoModeration/DiscordAutoModerationActionType.cs b/src/core/DSharpPlus.Shared/Enums/AutoModeration/DiscordAutoModerationActionType.cs new file mode 100644 index 0000000000..ce85376e7a --- /dev/null +++ b/src/core/DSharpPlus.Shared/Enums/AutoModeration/DiscordAutoModerationActionType.cs @@ -0,0 +1,29 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Entities; + +/// +/// Enumerates different actions to take when a message is filtered by the automod. +/// +public enum DiscordAutoModerationActionType +{ + /// + /// Prevents the message from being sent. An explanation as to why it was blocked may be specified + /// and shown to members whenever their message is blocked. + /// + BlockMessage = 1, + + /// + /// Logs the message to a specified channel. + /// + SendAlertMessage, + + /// + /// Causes an user to be timed out for a specified duration. This can only be applied to rules of types + /// and + /// . + /// + Timeout +} diff --git a/src/core/DSharpPlus.Shared/Enums/AutoModeration/DiscordAutoModerationEventType.cs b/src/core/DSharpPlus.Shared/Enums/AutoModeration/DiscordAutoModerationEventType.cs new file mode 100644 index 0000000000..a65856ea1d --- /dev/null +++ b/src/core/DSharpPlus.Shared/Enums/AutoModeration/DiscordAutoModerationEventType.cs @@ -0,0 +1,16 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Entities; + +/// +/// Indicates on what events a rule should be checked. +/// +public enum DiscordAutoModerationEventType +{ + /// + /// Fired when a member sends or edits a message. + /// + MessageSend = 1 +} diff --git a/src/core/DSharpPlus.Shared/Enums/AutoModeration/DiscordAutoModerationPresetType.cs b/src/core/DSharpPlus.Shared/Enums/AutoModeration/DiscordAutoModerationPresetType.cs new file mode 100644 index 0000000000..018e0a6ce0 --- /dev/null +++ b/src/core/DSharpPlus.Shared/Enums/AutoModeration/DiscordAutoModerationPresetType.cs @@ -0,0 +1,27 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Entities; + +/// +/// Specifies the internal keyword presets for auto-moderation rules of type +/// . +/// +public enum DiscordAutoModerationPresetType +{ + /// + /// Contains words that may be considered swearing, cursing or other profanity. + /// + Profanity = 1, + + /// + /// Contains words that may refer to sexually explicit behaviour or activity. + /// + SexualContent, + + /// + /// Contains words that may be considered hate speech. + /// + Slurs +} diff --git a/src/core/DSharpPlus.Shared/Enums/AutoModeration/DiscordAutoModerationTriggerType.cs b/src/core/DSharpPlus.Shared/Enums/AutoModeration/DiscordAutoModerationTriggerType.cs new file mode 100644 index 0000000000..d1068c0851 --- /dev/null +++ b/src/core/DSharpPlus.Shared/Enums/AutoModeration/DiscordAutoModerationTriggerType.cs @@ -0,0 +1,32 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Entities; + +/// +/// Represents different automod triggers. +/// +public enum DiscordAutoModerationTriggerType +{ + /// + /// Check whether the message content contains words from a user-defined list of keywords. + /// There can be up to six such rules in a guild. + /// + Keyword = 1, + + /// + /// Check whether the message content represents generic spam. + /// + Spam = 3, + + /// + /// Check whether the message content contains words from internally defined wordsets. + /// + KeywordPreset, + + /// + /// Check whether the message content contains more unique mentions than allowed. + /// + MentionSpam +} From 2f424298dd0d37ef24b3ec4520740f20c8b95171 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Fri, 30 Jun 2023 13:35:33 +0200 Subject: [PATCH 021/323] fix the DSP.Shared build; remove the JSImport generator --- Directory.Build.props | 4 +++- Directory.Build.targets | 20 ++++++++++++++++ ...dSharp.LICENSE => DiscordSharp.Old.License | 0 .../DSharpPlus.Shared.csproj | 23 ++++++++++++++++--- 4 files changed, 43 insertions(+), 4 deletions(-) rename DiscordSharp.LICENSE => DiscordSharp.Old.License (100%) diff --git a/Directory.Build.props b/Directory.Build.props index 85819ac53f..49faed871b 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -23,7 +23,9 @@ - Naamloos, afroraydude, DrCreo, Death, TiaqoY0, Axiom, Emzi0767, IDoEverything, Velvet, OoLunar, akiraveliara, DSharpPlus contributors + + Naamloos, afroraydude, DrCreo, Death, TiaqoY0, Axiom, Emzi0767, IDoEverything, Velvet, OoLunar, akiraveliara, DSharpPlus contributors + A C# API for Discord based off DiscordSharp. DSharpPlus Contributors https://github.com/DSharpPlus/DSharpPlus diff --git a/Directory.Build.targets b/Directory.Build.targets index 506d42e753..9b81f5d160 100644 --- a/Directory.Build.targets +++ b/Directory.Build.targets @@ -31,6 +31,26 @@ + + + + + + + + $(CoreCompileDependsOn);_DisableAnalyzers + + + + + <_RemoveAnalyzer>%(RemoveAnalyzer.Identity) + + + + + + + $(_DSharpPlusReleaseVersion) diff --git a/DiscordSharp.LICENSE b/DiscordSharp.Old.License similarity index 100% rename from DiscordSharp.LICENSE rename to DiscordSharp.Old.License diff --git a/src/core/DSharpPlus.Shared/DSharpPlus.Shared.csproj b/src/core/DSharpPlus.Shared/DSharpPlus.Shared.csproj index 376b8fdc37..dd730920e4 100644 --- a/src/core/DSharpPlus.Shared/DSharpPlus.Shared.csproj +++ b/src/core/DSharpPlus.Shared/DSharpPlus.Shared.csproj @@ -1,14 +1,31 @@  - - netstandard2.0;$(TargetFramework) - true $(Description) This package contains shared types between public-facing and internal implementation packages. Library DSharpPlus + + + + + + + + + netstandard2.0;$(TargetFramework) + + + + + false + false + + + + + From 9030490c4b87d5816c384f14a1fbd084146651f7 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sat, 1 Jul 2023 11:37:36 +0200 Subject: [PATCH 022/323] sadly, my favourite atrocity is no longer needed it just works without this in .NET 8 P5 --- src/core/DSharpPlus.Shared/DSharpPlus.Shared.csproj | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/src/core/DSharpPlus.Shared/DSharpPlus.Shared.csproj b/src/core/DSharpPlus.Shared/DSharpPlus.Shared.csproj index dd730920e4..d03a9bf085 100644 --- a/src/core/DSharpPlus.Shared/DSharpPlus.Shared.csproj +++ b/src/core/DSharpPlus.Shared/DSharpPlus.Shared.csproj @@ -6,22 +6,12 @@ Library DSharpPlus - - - - - - - - - netstandard2.0;$(TargetFramework) - + false - false From 8833b0c9db5ccc2e5303782597b6d542c76d64e9 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sat, 1 Jul 2023 14:06:31 +0200 Subject: [PATCH 023/323] add scheduled events --- .../ScheduledEvents/IScheduledEvent.cs | 90 +++++++++++++++++++ .../DiscordScheduledEventPrivacyLevel.cs | 16 ++++ .../DiscordScheduledEventStatus.cs | 20 +++++ .../DiscordScheduledEventType.cs | 15 ++++ 4 files changed, 141 insertions(+) create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/ScheduledEvents/IScheduledEvent.cs create mode 100644 src/core/DSharpPlus.Shared/Enums/ScheduledEvents/DiscordScheduledEventPrivacyLevel.cs create mode 100644 src/core/DSharpPlus.Shared/Enums/ScheduledEvents/DiscordScheduledEventStatus.cs create mode 100644 src/core/DSharpPlus.Shared/Enums/ScheduledEvents/DiscordScheduledEventType.cs diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/ScheduledEvents/IScheduledEvent.cs b/src/core/DSharpPlus.Core.Abstractions.Models/ScheduledEvents/IScheduledEvent.cs new file mode 100644 index 0000000000..d075f71eaa --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/ScheduledEvents/IScheduledEvent.cs @@ -0,0 +1,90 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; + +using DSharpPlus.Entities; + +using Remora.Rest.Core; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Represents a guild scheduled event. +/// + +// we deliberately ignore some fields listed in the documentation, because the documentation is outdated. +// it still documents data for external events (status: 2023-07-01) despite having been removed a long +// time ago... +// the following changes are thereby made from the documentation: +// - remove entity_metadata +// - remove scheduled_end_time +// - change channel_id to non-nullable +public interface IScheduledEvent +{ + /// + /// The snowflake identifier of the scheduled event. + /// + public Snowflake Id { get; } + + /// + /// The snowflake identifier of the guild this event belongs to. + /// + public Snowflake GuildId { get; } + + /// + /// The snowflake identifier of the channel in which this event will be hosted. + /// + public Snowflake ChannelId { get; } + + /// + /// The snowflake identifier of the user that created this event. + /// + public Optional CreatorId { get; } + + /// + /// The name of this event, 1 to 100 characters. + /// + public string Name { get; } + + /// + /// The description of this event, 1 to 1000 characters. + /// + public Optional Description { get; } + + /// + /// The time at which this scheduled event will start. + /// + public DateTimeOffset ScheduledStartTime { get; } + + /// + /// The privacy level of this event. + /// + public DiscordScheduledEventPrivacyLevel PrivacyLevel { get; } + + /// + /// The status of this scheduled event. + /// + public DiscordScheduledEventStatus Status { get; } + + /// + /// The type of this scheduled event. + /// + public DiscordScheduledEventType EntityType { get; } + + /// + /// The user that created this event. + /// + public Optional Creator { get; } + + /// + /// The number of users subscribed to this event. + /// + public Optional UserCount { get; } + + /// + /// The cover image hash of this event. + /// + public Optional Image { get; } +} diff --git a/src/core/DSharpPlus.Shared/Enums/ScheduledEvents/DiscordScheduledEventPrivacyLevel.cs b/src/core/DSharpPlus.Shared/Enums/ScheduledEvents/DiscordScheduledEventPrivacyLevel.cs new file mode 100644 index 0000000000..f7a9de9c43 --- /dev/null +++ b/src/core/DSharpPlus.Shared/Enums/ScheduledEvents/DiscordScheduledEventPrivacyLevel.cs @@ -0,0 +1,16 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Entities; + +/// +/// Specifies who this event is accessible to. +/// +public enum DiscordScheduledEventPrivacyLevel +{ + /// + /// This event is only accessible to guild members. + /// + GuildOnly = 2 +} diff --git a/src/core/DSharpPlus.Shared/Enums/ScheduledEvents/DiscordScheduledEventStatus.cs b/src/core/DSharpPlus.Shared/Enums/ScheduledEvents/DiscordScheduledEventStatus.cs new file mode 100644 index 0000000000..c78519dd85 --- /dev/null +++ b/src/core/DSharpPlus.Shared/Enums/ScheduledEvents/DiscordScheduledEventStatus.cs @@ -0,0 +1,20 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Entities; + +/// +/// Specifies the valid states of a scheduled event. +/// +/// +/// Once the status is set to or , it can no longer +/// be updated. +/// +public enum DiscordScheduledEventStatus +{ + Scheduled = 1, + Active, + Completed, + Canceled +} diff --git a/src/core/DSharpPlus.Shared/Enums/ScheduledEvents/DiscordScheduledEventType.cs b/src/core/DSharpPlus.Shared/Enums/ScheduledEvents/DiscordScheduledEventType.cs new file mode 100644 index 0000000000..6dca6c706f --- /dev/null +++ b/src/core/DSharpPlus.Shared/Enums/ScheduledEvents/DiscordScheduledEventType.cs @@ -0,0 +1,15 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Entities; + +/// +/// Specifies the different entity types for events; influencing what fields are present on the parent +/// object. +/// +public enum DiscordScheduledEventType +{ + StageInstance = 1, + Voice +} From 6c16df4512ccb2dbb3f5d13fe54eb6225b69422c Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sat, 1 Jul 2023 14:09:46 +0200 Subject: [PATCH 024/323] rename enums to entities --- .../ApplicationCommands/DiscordApplicationCommandOptionType.cs | 0 .../DiscordApplicationCommandPermissionType.cs | 0 .../ApplicationCommands/DiscordApplicationCommandType.cs | 0 .../{Enums => Entities}/Applications/DiscordApplicationFlags.cs | 0 .../AutoModeration/DiscordAutoModerationActionType.cs | 0 .../AutoModeration/DiscordAutoModerationEventType.cs | 0 .../AutoModeration/DiscordAutoModerationPresetType.cs | 0 .../AutoModeration/DiscordAutoModerationTriggerType.cs | 0 .../{Enums => Entities}/Channels/DiscordChannelFlags.cs | 0 .../{Enums => Entities}/Channels/DiscordChannelOverwriteType.cs | 0 .../{Enums => Entities}/Channels/DiscordChannelType.cs | 0 .../{Enums => Entities}/Channels/DiscordForumLayoutType.cs | 0 .../{Enums => Entities}/Channels/DiscordForumSortOrder.cs | 0 .../{Enums => Entities}/Channels/DiscordMessageActivityType.cs | 0 .../{Enums => Entities}/Channels/DiscordMessageFlags.cs | 0 .../{Enums => Entities}/Channels/DiscordMessageType.cs | 0 .../{Enums => Entities}/Channels/DiscordVideoQualityMode.cs | 0 .../DSharpPlus.Shared/{Enums => Entities}/DiscordPermissions.cs | 0 .../Guilds/DiscordExplicitContentFilterLevel.cs | 0 .../{Enums => Entities}/Guilds/DiscordGuildMemberFlags.cs | 0 .../{Enums => Entities}/Guilds/DiscordMessageNotificationLevel.cs | 0 .../{Enums => Entities}/Guilds/DiscordMfaLevel.cs | 0 .../{Enums => Entities}/Guilds/DiscordNsfwLevel.cs | 0 .../{Enums => Entities}/Guilds/DiscordSystemChannelFlags.cs | 0 .../{Enums => Entities}/Guilds/DiscordVerificationLevel.cs | 0 .../Interactions/DiscordInteractionCallbackType.cs | 0 .../{Enums => Entities}/Interactions/DiscordInteractionType.cs | 0 .../{Enums => Entities}/MessageComponents/DiscordButtonStyle.cs | 0 .../MessageComponents/DiscordMessageComponentType.cs | 0 .../MessageComponents/DiscordTextInputStyle.cs | 0 .../RoleConnections/DiscordRoleConnectionMetadataType.cs | 0 .../ScheduledEvents/DiscordScheduledEventPrivacyLevel.cs | 0 .../ScheduledEvents/DiscordScheduledEventStatus.cs | 0 .../ScheduledEvents/DiscordScheduledEventType.cs | 0 .../{Enums => Entities}/Stickers/DiscordStickerFormatType.cs | 0 .../{Enums => Entities}/Stickers/DiscordStickerType.cs | 0 .../{Enums => Entities}/Teams/DiscordTeamMembershipState.cs | 0 .../{Enums => Entities}/Users/DiscordPremiumType.cs | 0 .../{Enums => Entities}/Users/DiscordUserFlags.cs | 0 src/core/DSharpPlus.Shared/{Enums => Entities}/readme.md | 0 40 files changed, 0 insertions(+), 0 deletions(-) rename src/core/DSharpPlus.Shared/{Enums => Entities}/ApplicationCommands/DiscordApplicationCommandOptionType.cs (100%) rename src/core/DSharpPlus.Shared/{Enums => Entities}/ApplicationCommands/DiscordApplicationCommandPermissionType.cs (100%) rename src/core/DSharpPlus.Shared/{Enums => Entities}/ApplicationCommands/DiscordApplicationCommandType.cs (100%) rename src/core/DSharpPlus.Shared/{Enums => Entities}/Applications/DiscordApplicationFlags.cs (100%) rename src/core/DSharpPlus.Shared/{Enums => Entities}/AutoModeration/DiscordAutoModerationActionType.cs (100%) rename src/core/DSharpPlus.Shared/{Enums => Entities}/AutoModeration/DiscordAutoModerationEventType.cs (100%) rename src/core/DSharpPlus.Shared/{Enums => Entities}/AutoModeration/DiscordAutoModerationPresetType.cs (100%) rename src/core/DSharpPlus.Shared/{Enums => Entities}/AutoModeration/DiscordAutoModerationTriggerType.cs (100%) rename src/core/DSharpPlus.Shared/{Enums => Entities}/Channels/DiscordChannelFlags.cs (100%) rename src/core/DSharpPlus.Shared/{Enums => Entities}/Channels/DiscordChannelOverwriteType.cs (100%) rename src/core/DSharpPlus.Shared/{Enums => Entities}/Channels/DiscordChannelType.cs (100%) rename src/core/DSharpPlus.Shared/{Enums => Entities}/Channels/DiscordForumLayoutType.cs (100%) rename src/core/DSharpPlus.Shared/{Enums => Entities}/Channels/DiscordForumSortOrder.cs (100%) rename src/core/DSharpPlus.Shared/{Enums => Entities}/Channels/DiscordMessageActivityType.cs (100%) rename src/core/DSharpPlus.Shared/{Enums => Entities}/Channels/DiscordMessageFlags.cs (100%) rename src/core/DSharpPlus.Shared/{Enums => Entities}/Channels/DiscordMessageType.cs (100%) rename src/core/DSharpPlus.Shared/{Enums => Entities}/Channels/DiscordVideoQualityMode.cs (100%) rename src/core/DSharpPlus.Shared/{Enums => Entities}/DiscordPermissions.cs (100%) rename src/core/DSharpPlus.Shared/{Enums => Entities}/Guilds/DiscordExplicitContentFilterLevel.cs (100%) rename src/core/DSharpPlus.Shared/{Enums => Entities}/Guilds/DiscordGuildMemberFlags.cs (100%) rename src/core/DSharpPlus.Shared/{Enums => Entities}/Guilds/DiscordMessageNotificationLevel.cs (100%) rename src/core/DSharpPlus.Shared/{Enums => Entities}/Guilds/DiscordMfaLevel.cs (100%) rename src/core/DSharpPlus.Shared/{Enums => Entities}/Guilds/DiscordNsfwLevel.cs (100%) rename src/core/DSharpPlus.Shared/{Enums => Entities}/Guilds/DiscordSystemChannelFlags.cs (100%) rename src/core/DSharpPlus.Shared/{Enums => Entities}/Guilds/DiscordVerificationLevel.cs (100%) rename src/core/DSharpPlus.Shared/{Enums => Entities}/Interactions/DiscordInteractionCallbackType.cs (100%) rename src/core/DSharpPlus.Shared/{Enums => Entities}/Interactions/DiscordInteractionType.cs (100%) rename src/core/DSharpPlus.Shared/{Enums => Entities}/MessageComponents/DiscordButtonStyle.cs (100%) rename src/core/DSharpPlus.Shared/{Enums => Entities}/MessageComponents/DiscordMessageComponentType.cs (100%) rename src/core/DSharpPlus.Shared/{Enums => Entities}/MessageComponents/DiscordTextInputStyle.cs (100%) rename src/core/DSharpPlus.Shared/{Enums => Entities}/RoleConnections/DiscordRoleConnectionMetadataType.cs (100%) rename src/core/DSharpPlus.Shared/{Enums => Entities}/ScheduledEvents/DiscordScheduledEventPrivacyLevel.cs (100%) rename src/core/DSharpPlus.Shared/{Enums => Entities}/ScheduledEvents/DiscordScheduledEventStatus.cs (100%) rename src/core/DSharpPlus.Shared/{Enums => Entities}/ScheduledEvents/DiscordScheduledEventType.cs (100%) rename src/core/DSharpPlus.Shared/{Enums => Entities}/Stickers/DiscordStickerFormatType.cs (100%) rename src/core/DSharpPlus.Shared/{Enums => Entities}/Stickers/DiscordStickerType.cs (100%) rename src/core/DSharpPlus.Shared/{Enums => Entities}/Teams/DiscordTeamMembershipState.cs (100%) rename src/core/DSharpPlus.Shared/{Enums => Entities}/Users/DiscordPremiumType.cs (100%) rename src/core/DSharpPlus.Shared/{Enums => Entities}/Users/DiscordUserFlags.cs (100%) rename src/core/DSharpPlus.Shared/{Enums => Entities}/readme.md (100%) diff --git a/src/core/DSharpPlus.Shared/Enums/ApplicationCommands/DiscordApplicationCommandOptionType.cs b/src/core/DSharpPlus.Shared/Entities/ApplicationCommands/DiscordApplicationCommandOptionType.cs similarity index 100% rename from src/core/DSharpPlus.Shared/Enums/ApplicationCommands/DiscordApplicationCommandOptionType.cs rename to src/core/DSharpPlus.Shared/Entities/ApplicationCommands/DiscordApplicationCommandOptionType.cs diff --git a/src/core/DSharpPlus.Shared/Enums/ApplicationCommands/DiscordApplicationCommandPermissionType.cs b/src/core/DSharpPlus.Shared/Entities/ApplicationCommands/DiscordApplicationCommandPermissionType.cs similarity index 100% rename from src/core/DSharpPlus.Shared/Enums/ApplicationCommands/DiscordApplicationCommandPermissionType.cs rename to src/core/DSharpPlus.Shared/Entities/ApplicationCommands/DiscordApplicationCommandPermissionType.cs diff --git a/src/core/DSharpPlus.Shared/Enums/ApplicationCommands/DiscordApplicationCommandType.cs b/src/core/DSharpPlus.Shared/Entities/ApplicationCommands/DiscordApplicationCommandType.cs similarity index 100% rename from src/core/DSharpPlus.Shared/Enums/ApplicationCommands/DiscordApplicationCommandType.cs rename to src/core/DSharpPlus.Shared/Entities/ApplicationCommands/DiscordApplicationCommandType.cs diff --git a/src/core/DSharpPlus.Shared/Enums/Applications/DiscordApplicationFlags.cs b/src/core/DSharpPlus.Shared/Entities/Applications/DiscordApplicationFlags.cs similarity index 100% rename from src/core/DSharpPlus.Shared/Enums/Applications/DiscordApplicationFlags.cs rename to src/core/DSharpPlus.Shared/Entities/Applications/DiscordApplicationFlags.cs diff --git a/src/core/DSharpPlus.Shared/Enums/AutoModeration/DiscordAutoModerationActionType.cs b/src/core/DSharpPlus.Shared/Entities/AutoModeration/DiscordAutoModerationActionType.cs similarity index 100% rename from src/core/DSharpPlus.Shared/Enums/AutoModeration/DiscordAutoModerationActionType.cs rename to src/core/DSharpPlus.Shared/Entities/AutoModeration/DiscordAutoModerationActionType.cs diff --git a/src/core/DSharpPlus.Shared/Enums/AutoModeration/DiscordAutoModerationEventType.cs b/src/core/DSharpPlus.Shared/Entities/AutoModeration/DiscordAutoModerationEventType.cs similarity index 100% rename from src/core/DSharpPlus.Shared/Enums/AutoModeration/DiscordAutoModerationEventType.cs rename to src/core/DSharpPlus.Shared/Entities/AutoModeration/DiscordAutoModerationEventType.cs diff --git a/src/core/DSharpPlus.Shared/Enums/AutoModeration/DiscordAutoModerationPresetType.cs b/src/core/DSharpPlus.Shared/Entities/AutoModeration/DiscordAutoModerationPresetType.cs similarity index 100% rename from src/core/DSharpPlus.Shared/Enums/AutoModeration/DiscordAutoModerationPresetType.cs rename to src/core/DSharpPlus.Shared/Entities/AutoModeration/DiscordAutoModerationPresetType.cs diff --git a/src/core/DSharpPlus.Shared/Enums/AutoModeration/DiscordAutoModerationTriggerType.cs b/src/core/DSharpPlus.Shared/Entities/AutoModeration/DiscordAutoModerationTriggerType.cs similarity index 100% rename from src/core/DSharpPlus.Shared/Enums/AutoModeration/DiscordAutoModerationTriggerType.cs rename to src/core/DSharpPlus.Shared/Entities/AutoModeration/DiscordAutoModerationTriggerType.cs diff --git a/src/core/DSharpPlus.Shared/Enums/Channels/DiscordChannelFlags.cs b/src/core/DSharpPlus.Shared/Entities/Channels/DiscordChannelFlags.cs similarity index 100% rename from src/core/DSharpPlus.Shared/Enums/Channels/DiscordChannelFlags.cs rename to src/core/DSharpPlus.Shared/Entities/Channels/DiscordChannelFlags.cs diff --git a/src/core/DSharpPlus.Shared/Enums/Channels/DiscordChannelOverwriteType.cs b/src/core/DSharpPlus.Shared/Entities/Channels/DiscordChannelOverwriteType.cs similarity index 100% rename from src/core/DSharpPlus.Shared/Enums/Channels/DiscordChannelOverwriteType.cs rename to src/core/DSharpPlus.Shared/Entities/Channels/DiscordChannelOverwriteType.cs diff --git a/src/core/DSharpPlus.Shared/Enums/Channels/DiscordChannelType.cs b/src/core/DSharpPlus.Shared/Entities/Channels/DiscordChannelType.cs similarity index 100% rename from src/core/DSharpPlus.Shared/Enums/Channels/DiscordChannelType.cs rename to src/core/DSharpPlus.Shared/Entities/Channels/DiscordChannelType.cs diff --git a/src/core/DSharpPlus.Shared/Enums/Channels/DiscordForumLayoutType.cs b/src/core/DSharpPlus.Shared/Entities/Channels/DiscordForumLayoutType.cs similarity index 100% rename from src/core/DSharpPlus.Shared/Enums/Channels/DiscordForumLayoutType.cs rename to src/core/DSharpPlus.Shared/Entities/Channels/DiscordForumLayoutType.cs diff --git a/src/core/DSharpPlus.Shared/Enums/Channels/DiscordForumSortOrder.cs b/src/core/DSharpPlus.Shared/Entities/Channels/DiscordForumSortOrder.cs similarity index 100% rename from src/core/DSharpPlus.Shared/Enums/Channels/DiscordForumSortOrder.cs rename to src/core/DSharpPlus.Shared/Entities/Channels/DiscordForumSortOrder.cs diff --git a/src/core/DSharpPlus.Shared/Enums/Channels/DiscordMessageActivityType.cs b/src/core/DSharpPlus.Shared/Entities/Channels/DiscordMessageActivityType.cs similarity index 100% rename from src/core/DSharpPlus.Shared/Enums/Channels/DiscordMessageActivityType.cs rename to src/core/DSharpPlus.Shared/Entities/Channels/DiscordMessageActivityType.cs diff --git a/src/core/DSharpPlus.Shared/Enums/Channels/DiscordMessageFlags.cs b/src/core/DSharpPlus.Shared/Entities/Channels/DiscordMessageFlags.cs similarity index 100% rename from src/core/DSharpPlus.Shared/Enums/Channels/DiscordMessageFlags.cs rename to src/core/DSharpPlus.Shared/Entities/Channels/DiscordMessageFlags.cs diff --git a/src/core/DSharpPlus.Shared/Enums/Channels/DiscordMessageType.cs b/src/core/DSharpPlus.Shared/Entities/Channels/DiscordMessageType.cs similarity index 100% rename from src/core/DSharpPlus.Shared/Enums/Channels/DiscordMessageType.cs rename to src/core/DSharpPlus.Shared/Entities/Channels/DiscordMessageType.cs diff --git a/src/core/DSharpPlus.Shared/Enums/Channels/DiscordVideoQualityMode.cs b/src/core/DSharpPlus.Shared/Entities/Channels/DiscordVideoQualityMode.cs similarity index 100% rename from src/core/DSharpPlus.Shared/Enums/Channels/DiscordVideoQualityMode.cs rename to src/core/DSharpPlus.Shared/Entities/Channels/DiscordVideoQualityMode.cs diff --git a/src/core/DSharpPlus.Shared/Enums/DiscordPermissions.cs b/src/core/DSharpPlus.Shared/Entities/DiscordPermissions.cs similarity index 100% rename from src/core/DSharpPlus.Shared/Enums/DiscordPermissions.cs rename to src/core/DSharpPlus.Shared/Entities/DiscordPermissions.cs diff --git a/src/core/DSharpPlus.Shared/Enums/Guilds/DiscordExplicitContentFilterLevel.cs b/src/core/DSharpPlus.Shared/Entities/Guilds/DiscordExplicitContentFilterLevel.cs similarity index 100% rename from src/core/DSharpPlus.Shared/Enums/Guilds/DiscordExplicitContentFilterLevel.cs rename to src/core/DSharpPlus.Shared/Entities/Guilds/DiscordExplicitContentFilterLevel.cs diff --git a/src/core/DSharpPlus.Shared/Enums/Guilds/DiscordGuildMemberFlags.cs b/src/core/DSharpPlus.Shared/Entities/Guilds/DiscordGuildMemberFlags.cs similarity index 100% rename from src/core/DSharpPlus.Shared/Enums/Guilds/DiscordGuildMemberFlags.cs rename to src/core/DSharpPlus.Shared/Entities/Guilds/DiscordGuildMemberFlags.cs diff --git a/src/core/DSharpPlus.Shared/Enums/Guilds/DiscordMessageNotificationLevel.cs b/src/core/DSharpPlus.Shared/Entities/Guilds/DiscordMessageNotificationLevel.cs similarity index 100% rename from src/core/DSharpPlus.Shared/Enums/Guilds/DiscordMessageNotificationLevel.cs rename to src/core/DSharpPlus.Shared/Entities/Guilds/DiscordMessageNotificationLevel.cs diff --git a/src/core/DSharpPlus.Shared/Enums/Guilds/DiscordMfaLevel.cs b/src/core/DSharpPlus.Shared/Entities/Guilds/DiscordMfaLevel.cs similarity index 100% rename from src/core/DSharpPlus.Shared/Enums/Guilds/DiscordMfaLevel.cs rename to src/core/DSharpPlus.Shared/Entities/Guilds/DiscordMfaLevel.cs diff --git a/src/core/DSharpPlus.Shared/Enums/Guilds/DiscordNsfwLevel.cs b/src/core/DSharpPlus.Shared/Entities/Guilds/DiscordNsfwLevel.cs similarity index 100% rename from src/core/DSharpPlus.Shared/Enums/Guilds/DiscordNsfwLevel.cs rename to src/core/DSharpPlus.Shared/Entities/Guilds/DiscordNsfwLevel.cs diff --git a/src/core/DSharpPlus.Shared/Enums/Guilds/DiscordSystemChannelFlags.cs b/src/core/DSharpPlus.Shared/Entities/Guilds/DiscordSystemChannelFlags.cs similarity index 100% rename from src/core/DSharpPlus.Shared/Enums/Guilds/DiscordSystemChannelFlags.cs rename to src/core/DSharpPlus.Shared/Entities/Guilds/DiscordSystemChannelFlags.cs diff --git a/src/core/DSharpPlus.Shared/Enums/Guilds/DiscordVerificationLevel.cs b/src/core/DSharpPlus.Shared/Entities/Guilds/DiscordVerificationLevel.cs similarity index 100% rename from src/core/DSharpPlus.Shared/Enums/Guilds/DiscordVerificationLevel.cs rename to src/core/DSharpPlus.Shared/Entities/Guilds/DiscordVerificationLevel.cs diff --git a/src/core/DSharpPlus.Shared/Enums/Interactions/DiscordInteractionCallbackType.cs b/src/core/DSharpPlus.Shared/Entities/Interactions/DiscordInteractionCallbackType.cs similarity index 100% rename from src/core/DSharpPlus.Shared/Enums/Interactions/DiscordInteractionCallbackType.cs rename to src/core/DSharpPlus.Shared/Entities/Interactions/DiscordInteractionCallbackType.cs diff --git a/src/core/DSharpPlus.Shared/Enums/Interactions/DiscordInteractionType.cs b/src/core/DSharpPlus.Shared/Entities/Interactions/DiscordInteractionType.cs similarity index 100% rename from src/core/DSharpPlus.Shared/Enums/Interactions/DiscordInteractionType.cs rename to src/core/DSharpPlus.Shared/Entities/Interactions/DiscordInteractionType.cs diff --git a/src/core/DSharpPlus.Shared/Enums/MessageComponents/DiscordButtonStyle.cs b/src/core/DSharpPlus.Shared/Entities/MessageComponents/DiscordButtonStyle.cs similarity index 100% rename from src/core/DSharpPlus.Shared/Enums/MessageComponents/DiscordButtonStyle.cs rename to src/core/DSharpPlus.Shared/Entities/MessageComponents/DiscordButtonStyle.cs diff --git a/src/core/DSharpPlus.Shared/Enums/MessageComponents/DiscordMessageComponentType.cs b/src/core/DSharpPlus.Shared/Entities/MessageComponents/DiscordMessageComponentType.cs similarity index 100% rename from src/core/DSharpPlus.Shared/Enums/MessageComponents/DiscordMessageComponentType.cs rename to src/core/DSharpPlus.Shared/Entities/MessageComponents/DiscordMessageComponentType.cs diff --git a/src/core/DSharpPlus.Shared/Enums/MessageComponents/DiscordTextInputStyle.cs b/src/core/DSharpPlus.Shared/Entities/MessageComponents/DiscordTextInputStyle.cs similarity index 100% rename from src/core/DSharpPlus.Shared/Enums/MessageComponents/DiscordTextInputStyle.cs rename to src/core/DSharpPlus.Shared/Entities/MessageComponents/DiscordTextInputStyle.cs diff --git a/src/core/DSharpPlus.Shared/Enums/RoleConnections/DiscordRoleConnectionMetadataType.cs b/src/core/DSharpPlus.Shared/Entities/RoleConnections/DiscordRoleConnectionMetadataType.cs similarity index 100% rename from src/core/DSharpPlus.Shared/Enums/RoleConnections/DiscordRoleConnectionMetadataType.cs rename to src/core/DSharpPlus.Shared/Entities/RoleConnections/DiscordRoleConnectionMetadataType.cs diff --git a/src/core/DSharpPlus.Shared/Enums/ScheduledEvents/DiscordScheduledEventPrivacyLevel.cs b/src/core/DSharpPlus.Shared/Entities/ScheduledEvents/DiscordScheduledEventPrivacyLevel.cs similarity index 100% rename from src/core/DSharpPlus.Shared/Enums/ScheduledEvents/DiscordScheduledEventPrivacyLevel.cs rename to src/core/DSharpPlus.Shared/Entities/ScheduledEvents/DiscordScheduledEventPrivacyLevel.cs diff --git a/src/core/DSharpPlus.Shared/Enums/ScheduledEvents/DiscordScheduledEventStatus.cs b/src/core/DSharpPlus.Shared/Entities/ScheduledEvents/DiscordScheduledEventStatus.cs similarity index 100% rename from src/core/DSharpPlus.Shared/Enums/ScheduledEvents/DiscordScheduledEventStatus.cs rename to src/core/DSharpPlus.Shared/Entities/ScheduledEvents/DiscordScheduledEventStatus.cs diff --git a/src/core/DSharpPlus.Shared/Enums/ScheduledEvents/DiscordScheduledEventType.cs b/src/core/DSharpPlus.Shared/Entities/ScheduledEvents/DiscordScheduledEventType.cs similarity index 100% rename from src/core/DSharpPlus.Shared/Enums/ScheduledEvents/DiscordScheduledEventType.cs rename to src/core/DSharpPlus.Shared/Entities/ScheduledEvents/DiscordScheduledEventType.cs diff --git a/src/core/DSharpPlus.Shared/Enums/Stickers/DiscordStickerFormatType.cs b/src/core/DSharpPlus.Shared/Entities/Stickers/DiscordStickerFormatType.cs similarity index 100% rename from src/core/DSharpPlus.Shared/Enums/Stickers/DiscordStickerFormatType.cs rename to src/core/DSharpPlus.Shared/Entities/Stickers/DiscordStickerFormatType.cs diff --git a/src/core/DSharpPlus.Shared/Enums/Stickers/DiscordStickerType.cs b/src/core/DSharpPlus.Shared/Entities/Stickers/DiscordStickerType.cs similarity index 100% rename from src/core/DSharpPlus.Shared/Enums/Stickers/DiscordStickerType.cs rename to src/core/DSharpPlus.Shared/Entities/Stickers/DiscordStickerType.cs diff --git a/src/core/DSharpPlus.Shared/Enums/Teams/DiscordTeamMembershipState.cs b/src/core/DSharpPlus.Shared/Entities/Teams/DiscordTeamMembershipState.cs similarity index 100% rename from src/core/DSharpPlus.Shared/Enums/Teams/DiscordTeamMembershipState.cs rename to src/core/DSharpPlus.Shared/Entities/Teams/DiscordTeamMembershipState.cs diff --git a/src/core/DSharpPlus.Shared/Enums/Users/DiscordPremiumType.cs b/src/core/DSharpPlus.Shared/Entities/Users/DiscordPremiumType.cs similarity index 100% rename from src/core/DSharpPlus.Shared/Enums/Users/DiscordPremiumType.cs rename to src/core/DSharpPlus.Shared/Entities/Users/DiscordPremiumType.cs diff --git a/src/core/DSharpPlus.Shared/Enums/Users/DiscordUserFlags.cs b/src/core/DSharpPlus.Shared/Entities/Users/DiscordUserFlags.cs similarity index 100% rename from src/core/DSharpPlus.Shared/Enums/Users/DiscordUserFlags.cs rename to src/core/DSharpPlus.Shared/Entities/Users/DiscordUserFlags.cs diff --git a/src/core/DSharpPlus.Shared/Enums/readme.md b/src/core/DSharpPlus.Shared/Entities/readme.md similarity index 100% rename from src/core/DSharpPlus.Shared/Enums/readme.md rename to src/core/DSharpPlus.Shared/Entities/readme.md From 4a34c10db6b0d08dc0574e3a2a7e742651518fc2 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sat, 1 Jul 2023 14:24:53 +0200 Subject: [PATCH 025/323] add integrations --- .../Guilds/IIntegration.cs | 99 +++++++++++++++++++ .../Guilds/IIntegrationAccount.cs | 21 ++++ .../Guilds/IIntegrationApplication.cs | 38 +++++++ .../DiscordIntegrationExpirationBehaviour.cs | 14 +++ 4 files changed, 172 insertions(+) create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IIntegration.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IIntegrationAccount.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IIntegrationApplication.cs create mode 100644 src/core/DSharpPlus.Shared/Entities/Guilds/DiscordIntegrationExpirationBehaviour.cs diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IIntegration.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IIntegration.cs new file mode 100644 index 0000000000..f30dff911b --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IIntegration.cs @@ -0,0 +1,99 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; +using System.Collections.Generic; + +using DSharpPlus.Entities; + +using Remora.Rest.Core; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Represents an integration between an external service and a guild. +/// +public interface IIntegration +{ + /// + /// The snowflake identifier of the integration. + /// + public Snowflake Id { get; } + + /// + /// The name of this integration. + /// + public string Name { get; } + + /// + /// The type of this integration; twitch, youtube, discord or guild_subscription. + /// + public string Type { get; } + + /// + /// Indicates whether this integration is enabled. + /// + public bool Enabled { get; } + + /// + /// Indicates whether this integration is synchronizing. + /// + public Optional Syncing { get; } + + /// + /// The snowflake identifier of the role that this integration uses for "subscribers". + /// + public Optional RoleId { get; } + + /// + /// Indicates whether emoticons should be synced for this integration. This is currently only + /// applicable to twitch. + /// + public Optional EnableEmoticons { get; } + + /// + /// Indicates how this integration should behave when a subscription expires. + /// + public Optional ExpireBehaviour { get; } + + /// + /// The grace period, in days, before expiring subscribers. + /// + public Optional ExpireGracePeriod { get; } + + /// + /// The user for this integration. + /// + public Optional User { get; } + + /// + /// Contains additional integration account metadata. + /// + public IIntegrationAccount Account { get; } + + /// + /// Indicates when this integration was last synced. + /// + public Optional SyncedAt { get; } + + /// + /// The amount of subscribers this integration has. + /// + public Optional SubscriberCount { get; } + + /// + /// Indicates whether this integration has been revoked. + /// + public Optional Revoked { get; } + + /// + /// The bot/oauth2 application for discord integrations. + /// + public Optional Application { get; } + + /// + /// The OAuth2 scopes this application has been authorized for. + /// + public Optional> Scopes { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IIntegrationAccount.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IIntegrationAccount.cs new file mode 100644 index 0000000000..207d8e9cb2 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IIntegrationAccount.cs @@ -0,0 +1,21 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Contains additional information about integration accounts. +/// +public interface IIntegrationAccount +{ + /// + /// The ID of this account. + /// + public string Id { get; } + + /// + /// The name of this account. + /// + public string Name { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IIntegrationApplication.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IIntegrationApplication.cs new file mode 100644 index 0000000000..a6e4d08b3c --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IIntegrationApplication.cs @@ -0,0 +1,38 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using Remora.Rest.Core; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Represents application-specific metadata for an integration. +/// +public interface IIntegrationApplication +{ + /// + /// The snowflake identifier of this application. + /// + public Snowflake Id { get; } + + /// + /// The name of this application. + /// + public string Name { get; } + + /// + /// The icon hash of this application. + /// + public string? Icon { get; } + + /// + /// The description of this application. + /// + public string Description { get; } + + /// + /// The bot user associated with this application. + /// + public Optional Bot { get; } +} diff --git a/src/core/DSharpPlus.Shared/Entities/Guilds/DiscordIntegrationExpirationBehaviour.cs b/src/core/DSharpPlus.Shared/Entities/Guilds/DiscordIntegrationExpirationBehaviour.cs new file mode 100644 index 0000000000..e97b1a15ce --- /dev/null +++ b/src/core/DSharpPlus.Shared/Entities/Guilds/DiscordIntegrationExpirationBehaviour.cs @@ -0,0 +1,14 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Entities; + +/// +/// Specifies how an integration should act in the event of a subscription expiring. +/// +public enum DiscordIntegrationExpirationBehaviour +{ + RemoveRole, + Kick +} From a2633d9cee23f0d89c35a632123ae18263a9a360 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sat, 1 Jul 2023 14:30:28 +0200 Subject: [PATCH 026/323] add partial integrations --- .../Guilds/IIntegration.cs | 98 +++++------------- .../Guilds/IPartialIntegration.cs | 99 +++++++++++++++++++ 2 files changed, 121 insertions(+), 76 deletions(-) create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IPartialIntegration.cs diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IIntegration.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IIntegration.cs index f30dff911b..d117bead83 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IIntegration.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IIntegration.cs @@ -2,11 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using System; -using System.Collections.Generic; - -using DSharpPlus.Entities; - using Remora.Rest.Core; namespace DSharpPlus.Core.Abstractions.Models; @@ -14,86 +9,37 @@ namespace DSharpPlus.Core.Abstractions.Models; /// /// Represents an integration between an external service and a guild. /// -public interface IIntegration +public interface IIntegration : IPartialIntegration { - /// - /// The snowflake identifier of the integration. - /// - public Snowflake Id { get; } - - /// - /// The name of this integration. - /// - public string Name { get; } - - /// - /// The type of this integration; twitch, youtube, discord or guild_subscription. - /// - public string Type { get; } - - /// - /// Indicates whether this integration is enabled. - /// - public bool Enabled { get; } - - /// - /// Indicates whether this integration is synchronizing. - /// - public Optional Syncing { get; } - - /// - /// The snowflake identifier of the role that this integration uses for "subscribers". - /// - public Optional RoleId { get; } + /// + public new Snowflake Id { get; } - /// - /// Indicates whether emoticons should be synced for this integration. This is currently only - /// applicable to twitch. - /// - public Optional EnableEmoticons { get; } + /// + public new string Name { get; } - /// - /// Indicates how this integration should behave when a subscription expires. - /// - public Optional ExpireBehaviour { get; } + /// + public new string Type { get; } - /// - /// The grace period, in days, before expiring subscribers. - /// - public Optional ExpireGracePeriod { get; } + /// + public new bool Enabled { get; } - /// - /// The user for this integration. - /// - public Optional User { get; } + /// + public new IIntegrationAccount Account { get; } - /// - /// Contains additional integration account metadata. - /// - public IIntegrationAccount Account { get; } + // partial access routes - /// - /// Indicates when this integration was last synced. - /// - public Optional SyncedAt { get; } + /// + Optional IPartialIntegration.Id => this.Id; - /// - /// The amount of subscribers this integration has. - /// - public Optional SubscriberCount { get; } + /// + Optional IPartialIntegration.Name => this.Name; - /// - /// Indicates whether this integration has been revoked. - /// - public Optional Revoked { get; } + /// + Optional IPartialIntegration.Type => this.Type; - /// - /// The bot/oauth2 application for discord integrations. - /// - public Optional Application { get; } + /// + Optional IPartialIntegration.Enabled => this.Enabled; - /// - /// The OAuth2 scopes this application has been authorized for. - /// - public Optional> Scopes { get; } + /// + Optional IPartialIntegration.Account => new(this.Account); } diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IPartialIntegration.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IPartialIntegration.cs new file mode 100644 index 0000000000..acd3a0ca8d --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IPartialIntegration.cs @@ -0,0 +1,99 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; +using System.Collections.Generic; + +using DSharpPlus.Entities; + +using Remora.Rest.Core; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Represents a partially populated integration object. +/// +public interface IPartialIntegration +{ + /// + /// The snowflake identifier of the integration. + /// + public Optional Id { get; } + + /// + /// The name of this integration. + /// + public Optional Name { get; } + + /// + /// The type of this integration; twitch, youtube, discord or guild_subscription. + /// + public Optional Type { get; } + + /// + /// Indicates whether this integration is enabled. + /// + public Optional Enabled { get; } + + /// + /// Indicates whether this integration is synchronizing. + /// + public Optional Syncing { get; } + + /// + /// The snowflake identifier of the role that this integration uses for "subscribers". + /// + public Optional RoleId { get; } + + /// + /// Indicates whether emoticons should be synced for this integration. This is currently only + /// applicable to twitch. + /// + public Optional EnableEmoticons { get; } + + /// + /// Indicates how this integration should behave when a subscription expires. + /// + public Optional ExpireBehaviour { get; } + + /// + /// The grace period, in days, before expiring subscribers. + /// + public Optional ExpireGracePeriod { get; } + + /// + /// The user for this integration. + /// + public Optional User { get; } + + /// + /// Contains additional integration account metadata. + /// + public Optional Account { get; } + + /// + /// Indicates when this integration was last synced. + /// + public Optional SyncedAt { get; } + + /// + /// The amount of subscribers this integration has. + /// + public Optional SubscriberCount { get; } + + /// + /// Indicates whether this integration has been revoked. + /// + public Optional Revoked { get; } + + /// + /// The bot/oauth2 application for discord integrations. + /// + public Optional Application { get; } + + /// + /// The OAuth2 scopes this application has been authorized for. + /// + public Optional> Scopes { get; } +} From 9ccd5494c340c7ffb226072610b6af5cb6dcc47b Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sat, 1 Jul 2023 14:33:26 +0200 Subject: [PATCH 027/323] add non-partial channels --- .../Channels/IChannel.cs | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/Channels/IChannel.cs diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IChannel.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IChannel.cs new file mode 100644 index 0000000000..82f3a7bde1 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IChannel.cs @@ -0,0 +1,29 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Entities; + +using Remora.Rest.Core; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Represents a fully populated channel object. +/// +public interface IChannel : IPartialChannel +{ + /// + public new Snowflake Id { get; } + + /// + public new DiscordChannelType Type { get; } + + // partial access routes + + /// + Optional IPartialChannel.Id => this.Id; + + /// + Optional IPartialChannel.Type => this.Type; +} From aa4fc5c6f7d6746cbaac07944f3606579e6a44d1 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sat, 1 Jul 2023 14:49:30 +0200 Subject: [PATCH 028/323] add webhooks --- .../Webhooks/IWebhook.cs | 75 +++++++++++++++++++ .../Entities/Webhooks/DiscordWebhookType.cs | 26 +++++++ 2 files changed, 101 insertions(+) create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/Webhooks/IWebhook.cs create mode 100644 src/core/DSharpPlus.Shared/Entities/Webhooks/DiscordWebhookType.cs diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Webhooks/IWebhook.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Webhooks/IWebhook.cs new file mode 100644 index 0000000000..cc5b9d2711 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Webhooks/IWebhook.cs @@ -0,0 +1,75 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Entities; + +using Remora.Rest.Core; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Represents a discord webhook. +/// +public interface IWebhook +{ + /// + /// The snowflake identifier of this webhook. + /// + public Snowflake Id { get; } + + /// + /// The type of this webhook. + /// + public DiscordWebhookType Type { get; } + + /// + /// The snowflake identifier of the guild this webhook is for, if any. + /// + public Optional GuildId { get; } + + /// + /// The snowflake identifier of the channel this webhook is for, if any. + /// + public Snowflake? ChannelId { get; } + + /// + /// The user who created this webhook. + /// + public Optional User { get; } + + /// + /// The default name of this webhook. + /// + public string? Name { get; } + + /// + /// The default avatar hash of this webhook. + /// + public string? Avatar { get; } + + /// + /// The secure token of this webhook. + /// + public Optional Token { get; } + + /// + /// The snowflake identifier of the bot/oauth2 application which created this webhook. + /// + public Snowflake? ApplicationId { get; } + + /// + /// The guild containing the channel that this webhook is following. + /// + public Optional SourceGuild { get; } + + /// + /// The channel that this webhook is following. + /// + public Optional SourceChannel { get; } + + /// + /// The url used to execute this webhook. + /// + public Optional Url { get; } +} diff --git a/src/core/DSharpPlus.Shared/Entities/Webhooks/DiscordWebhookType.cs b/src/core/DSharpPlus.Shared/Entities/Webhooks/DiscordWebhookType.cs new file mode 100644 index 0000000000..8ecf45c79b --- /dev/null +++ b/src/core/DSharpPlus.Shared/Entities/Webhooks/DiscordWebhookType.cs @@ -0,0 +1,26 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Entities; + +/// +/// Specifies the different types of webhooks. +/// +public enum DiscordWebhookType +{ + /// + /// Incoming webhooks can post messages to channels with a generated token. + /// + Incoming = 1, + + /// + /// Channel Follower webhooks are internal webhooks used with channel following to cross-post messages. + /// + ChannelFollower, + + /// + /// Application webhooks are webhooks used with interactions. + /// + Application +} From dab3de4e550febd84fd89daf3a600db0d031d9a5 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sat, 1 Jul 2023 14:49:58 +0200 Subject: [PATCH 029/323] add audit logs --- .../AuditLogs/IAuditLog.cs | 53 +++ .../AuditLogs/IAuditLogChange.cs | 30 ++ .../AuditLogs/IAuditLogEntry.cs | 54 +++ .../AuditLogs/IAuditLogEntryInfo.cs | 74 +++ .../AuditLogs/DiscordAuditLogEvent.cs | 443 ++++++++++++++++++ 5 files changed, 654 insertions(+) create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/AuditLogs/IAuditLog.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/AuditLogs/IAuditLogChange.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/AuditLogs/IAuditLogEntry.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/AuditLogs/IAuditLogEntryInfo.cs create mode 100644 src/core/DSharpPlus.Shared/Entities/AuditLogs/DiscordAuditLogEvent.cs diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/AuditLogs/IAuditLog.cs b/src/core/DSharpPlus.Core.Abstractions.Models/AuditLogs/IAuditLog.cs new file mode 100644 index 0000000000..b218fed863 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/AuditLogs/IAuditLog.cs @@ -0,0 +1,53 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Represents the guild audit log. +/// +public interface IAuditLog +{ + /// + /// The application commands referenced in the audit log. + /// + public IReadOnlyList ApplicationCommands { get; } + + /// + /// The audit log entires, sorted from most recent to last recent. + /// + public IReadOnlyList AuditLogEntries { get; } + + /// + /// The auto moderation rules referenced in the audit log. + /// + public IReadOnlyList AutoModerationRules { get; } + + /// + /// The scheduled events referenced in the audit log. + /// + public IReadOnlyList GuildScheduledEvents { get; } + + /// + /// The integrations referenced in the audit log. + /// + public IReadOnlyList Integrations { get; } + + /// + /// The threads referenced in the audit log. + /// + public IReadOnlyList Threads { get; } + + /// + /// The users referenced in the audit log. + /// + public IReadOnlyList Users { get; } + + /// + /// The webhooks referenced in the audit log. + /// + public IReadOnlyList Webhooks { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/AuditLogs/IAuditLogChange.cs b/src/core/DSharpPlus.Core.Abstractions.Models/AuditLogs/IAuditLogChange.cs new file mode 100644 index 0000000000..9466d124c9 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/AuditLogs/IAuditLogChange.cs @@ -0,0 +1,30 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Text.Json; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Represents a single logged change made to an entity. Cast to a more specific type to access the changes made. +/// +public interface IAuditLogChange +{ + /// + /// The new value of this field. + /// + public JsonElement NewValue { get; } + + /// + /// The old value of this field. + /// + public JsonElement OldValue { get; } + + /// + /// The name of the changed field, with a few exceptions: see + /// + /// the documentation. + /// + public string Key { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/AuditLogs/IAuditLogEntry.cs b/src/core/DSharpPlus.Core.Abstractions.Models/AuditLogs/IAuditLogEntry.cs new file mode 100644 index 0000000000..270f4956f0 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/AuditLogs/IAuditLogEntry.cs @@ -0,0 +1,54 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Entities; + +using OneOf; + +using Remora.Rest.Core; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Represents a single entry within the audit log. +/// +public interface IAuditLogEntry +{ + /// + /// The identifier of the affected entity. + /// + public OneOf? TargetId { get; } + + /// + /// The changes made to the affected entity. + /// + public Optional> Changes { get; } + + /// + /// The user or application that made these changes. + /// + public Snowflake? UserId { get; } + + /// + /// The snowflake identifier of this entry. + /// + public Snowflake Id { get; } + + /// + /// The type of the action that occurred. + /// + public DiscordAuditLogEvent ActionType { get; } + + /// + /// Additional information sent for certain event types. + /// + public Optional Options { get; } + + /// + /// The reason for this change. + /// + public Optional Reason { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/AuditLogs/IAuditLogEntryInfo.cs b/src/core/DSharpPlus.Core.Abstractions.Models/AuditLogs/IAuditLogEntryInfo.cs new file mode 100644 index 0000000000..18c0edd7ac --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/AuditLogs/IAuditLogEntryInfo.cs @@ -0,0 +1,74 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using Remora.Rest.Core; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Contains additional metadata for an audit log entry. +/// +/// +/// Presence of a field is dictated by its parent . When deciding +/// what to access, refer to the +/// +/// Event Types section in the docs. +/// +public interface IAuditLogEntryInfo +{ + /// + /// The snowflake identifier of the application whose permissions were targeted. + /// + public Optional ApplicationId { get; } + + /// + /// The name of the auto moderation rule that was triggered. + /// + public Optional AutoModerationRuleName { get; } + + /// + /// The trigger type of the auto moderation rule that was triggered. + /// + public Optional AutoModerationRuleTriggerType { get; } + + /// + /// The snowflake identifier of the channel in which entities were targeted. + /// + public Optional ChannelId { get; } + + /// + /// The amount of entities that were targeted. + /// + public Optional Count { get; } + + /// + /// The amount of days after which inactive members were kicked. + /// + public Optional DeleteMemberDays { get; } + + /// + /// The snowflake identifier of the overwritten entry. + /// + public Optional Id { get; } + + /// + /// The amount of members removed by the server prune. + /// + public Optional MembersRemoved { get; } + + /// + /// The snowflake identifier of the message that was targeted. + /// + public Optional MessageId { get; } + + /// + /// The name of the targeted role. + /// + public Optional RoleName { get; } + + /// + /// The type of the overwritten entity. + /// + public Optional Type { get; } +} diff --git a/src/core/DSharpPlus.Shared/Entities/AuditLogs/DiscordAuditLogEvent.cs b/src/core/DSharpPlus.Shared/Entities/AuditLogs/DiscordAuditLogEvent.cs new file mode 100644 index 0000000000..b9ebed3e82 --- /dev/null +++ b/src/core/DSharpPlus.Shared/Entities/AuditLogs/DiscordAuditLogEvent.cs @@ -0,0 +1,443 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Entities; + +/// +/// Enumerates the visible types of audit log events; and lists the metadata provided to each event. +/// +public enum DiscordAuditLogEvent +{ + /// + /// The server settings were updated. + /// + /// + /// Metadata is provided for a guild object. + /// + GuildUpdated = 1, + + /// + /// A channel was created. + /// + /// + /// Metadata is provided for a channel object. + /// + ChannelCreated = 10, + + /// + /// A channel was updated. + /// + /// + /// Metadata is provided for a channel object. + /// + ChannelUpdated = 11, + + /// + /// A channel was deleted. + /// + /// + /// Metadata is provided for a channel object. + /// + ChannelDeleted = 12, + + /// + /// A permission overwrite was added to a channel. + /// + /// + /// Metadata is provided for a channel overwrite object. + /// + ChannelOverwriteCreated = 13, + + /// + /// A permission overwrite in a channel was updated. + /// + /// + /// Metadata is provided for a channel overwrite object. + /// + ChannelOverwriteUpdated = 14, + + /// + /// A permission overwrite in a channel was deleted. + /// + /// + /// Metadata is provided for a channel overwrite object. + /// + ChannelOverwriteDeleted = 15, + + /// + /// A member was kicked from the server. + /// + /// + /// No metadata is provided. + /// + MemberKicked = 20, + + /// + /// Members were pruned from the server. + /// + /// + /// No metadata is provided. + /// + MemberPruned = 21, + + /// + /// A member was banned from the server. + /// + /// + /// No metadata is provided. + /// + MemberBanned = 22, + + /// + /// A member was unbanned from the server. + /// + /// + /// No metadata is provided. + /// + MemberUnbanned = 23, + + /// + /// A server member was updated. + /// + /// + /// Metadata is provided for a member object. + /// + MemberUpdated = 24, + + /// + /// A role was granted to or removed from a server member. + /// + /// + /// Metadata is provided for a role object. + /// + MemberRoleUpdated = 25, + + /// + /// A server member was moved to a different voice channel. + /// + /// + /// No metadata is provided. + /// + MemberMoved = 26, + + /// + /// A server member was disconnected from a voice channel. + /// + /// + /// No metadata is provided. + /// + MemberDisconnected = 27, + + /// + /// A bot user was added to the server. + /// + /// + /// No metadata is provided. + /// + BotAdded = 28, + + /// + /// A role was created. + /// + /// + /// Metadata is provided for a role object. + /// + RoleCreated = 30, + + /// + /// A role was updated. + /// + /// + /// Metadata is provided for a role object. + /// + RoleUpdated = 31, + + /// + /// A role was deleted. + /// + /// + /// Metadata is provided for a role object. + /// + RoleDeleted = 32, + + /// + /// An invite was created. + /// + /// + /// Metadata is provided for an invite object. + /// + InviteCreated = 40, + + /// + /// An invite was updated. + /// + /// + /// Metadata is provided for an invite object. + /// + InviteUpdated = 41, + + /// + /// An invite was deleted. + /// + /// + /// Metadata is provided for an invite object. + /// + InviteDeleted = 42, + + /// + /// A webhook was created. + /// + /// + /// Metadata is provided for a webhook object. + /// + WebhookCreated = 50, + + /// + /// A webhook was updated. + /// + /// + /// Metadata is provided for a webhook object. + /// + WebhookUpdated = 51, + + /// + /// A webhook was deleted. + /// + /// + /// Metadata is provided for a webhook object. + /// + WebhookDeleted = 52, + + /// + /// An emoji was created. + /// + /// + /// Metadata is provided for an emoji object. + /// + EmojiCreated = 60, + + /// + /// An emoji was updated. + /// + /// + /// Metadata is provided for an emoji object. + /// + EmojiUpdated = 61, + + /// + /// An emoji was deleted. + /// + /// + /// Metadata is provided for an emoji object. + /// + EmojiDeleted = 62, + + /// + /// A message was deleted. + /// + /// + /// No metadata is provided. + /// + MessageDeleted = 72, + + /// + /// Multiple messages were bulk-deleted. + /// + /// + /// No metadata is provided. + /// + MessageBulkDeleted = 73, + + /// + /// A message was pinned to a channel. + /// + /// + /// No metadata is provided. + /// + MessagePinned = 74, + + /// + /// A message was unpinned from a channel. + /// + /// + /// No metadata is provided. + /// + MessageUnpinned = 75, + + /// + /// An integration was added to a server. + /// + /// + /// Metadata is provided for an integration object. + /// + IntegrationCreated = 80, + + /// + /// An integration within a server was updated. + /// + /// + /// Metadata is provided for an integration object. + /// + IntegrationUpdated = 81, + + /// + /// An integration was deleted from a server. + /// + /// + /// Metadata is provided for an integration object. + /// + IntegrationDeleted = 82, + + /// + /// A stage channel went live. + /// + /// + /// Metadata is provided for a stage instance object. + /// + StageInstanceCreated = 83, + + /// + /// A live stage channel was updated. + /// + /// + /// Metadata is provided for a stage instance object. + /// + StageInstanceUpdated = 84, + + /// + /// A stage instance ended. + /// + /// + /// Metadata is provided for a stage instance object. + /// + StageInstanceDeleted = 85, + + /// + /// A sticker was created. + /// + /// + /// Metadata is provided for a sticker object. + /// + StickerCreated = 90, + + /// + /// A sticker was updated. + /// + /// + /// Metadata is provided for a sticker object. + /// + StickerUpdated = 91, + + /// + /// A sticker was deleted. + /// + /// + /// Metadata is provided for a sticker object. + /// + StickerDeleted = 92, + + /// + /// A scheduled event was created. + /// + /// + /// Metadata is provided for a scheduled event object. + /// + ScheduledEventCreated = 100, + + /// + /// A scheduled event was updated. + /// + /// + /// Metadata is provided for a scheduled event object. + /// + ScheduledEventUpdated = 101, + + /// + /// A scheduled event was cancelled. + /// + /// + /// Metadata is provided for a scheduled event object. + /// + ScheduledEventDeleted = 102, + + /// + /// A thread was created in a channel. + /// + /// + /// Metadata is provided for a channel object. + /// + ThreadCreated = 110, + + /// + /// A thread was updated. + /// + /// + /// Metadata is provided for a channel object. + /// + ThreadUpdated = 111, + + /// + /// A thread was deleted. + /// + /// + /// Metadata is provided for a channel object. + /// + ThreadDeleted = 112, + + /// + /// An application command's permissions were updated. + /// + /// + /// Metadata is provided for an application command permissions object. + /// + ApplicationCommandPermissionsUpdated = 121, + + /// + /// An auto moderation rule was created. + /// + /// + /// Metadata is provided for an auto moderation rule object. + /// + AutoModerationRuleCreated = 140, + + /// + /// An auto moderation rule was updated. + /// + /// + /// Metadata is provided for an auto moderation rule object. + /// + AutoModerationRuleUpdated = 141, + + /// + /// An auto moderation rule was deleted. + /// + /// + /// Metadata is provided for an auto moderation rule object. + /// + AutoModerationRuleDeleted = 142, + + /// + /// A message was blocked by the discord automod. + /// + /// + /// No metadata is provided. + /// + AutoModerationMessageBlocked = 143, + + /// + /// A message was flagged and alerted to by the discord automod. + /// + /// + /// No metadata is provided. + /// + AutoModerationFlaggedToChannel = 144, + + /// + /// A member was timed out by the discord automod. + /// + /// + /// No metadata is provided. + /// + AutoModerationUserCommunicationDisabled = 145 +} From d96a5f4a99d94cc88d446b921fdc4919e90f7cf8 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sat, 1 Jul 2023 15:38:44 +0200 Subject: [PATCH 030/323] add partial channel overwrites --- .../Channels/IChannelOverwrite.cs | 46 +++++++++++-------- .../Channels/IPartialChannelOverwrite.cs | 35 ++++++++++++++ 2 files changed, 61 insertions(+), 20 deletions(-) create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/Channels/IPartialChannelOverwrite.cs diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IChannelOverwrite.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IChannelOverwrite.cs index fea4aaa1e0..fb5a665014 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IChannelOverwrite.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IChannelOverwrite.cs @@ -11,25 +11,31 @@ namespace DSharpPlus.Core.Abstractions.Models; /// /// Represents a permission overwrite on a channel. /// -public interface IChannelOverwrite +public interface IChannelOverwrite : IPartialChannelOverwrite { - /// - /// The snowflake identifier of the role or user this overwrite targtes. - /// - public Snowflake Id { get; } - - /// - /// Specifies what kind of entity this overwrite targets. - /// - public DiscordChannelOverwriteType Type { get; } - - /// - /// The permissions explicitly granted by this overwrite. - /// - public DiscordPermissions Allow { get; } - - /// - /// The permissions explicitly denied by this overwrite. - /// - public DiscordPermissions Deny { get; } + /// + public new Snowflake Id { get; } + + /// + public new DiscordChannelOverwriteType Type { get; } + + /// + public new DiscordPermissions Allow { get; } + + /// + public new DiscordPermissions Deny { get; } + + // partial access routes + + /// + Optional IPartialChannelOverwrite.Id => this.Id; + + /// + Optional IPartialChannelOverwrite.Type => this.Type; + + /// + Optional IPartialChannelOverwrite.Allow => this.Allow; + + /// + Optional IPartialChannelOverwrite.Deny => this.Deny; } diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IPartialChannelOverwrite.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IPartialChannelOverwrite.cs new file mode 100644 index 0000000000..aa010bedab --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IPartialChannelOverwrite.cs @@ -0,0 +1,35 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Entities; + +using Remora.Rest.Core; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Represents a partially populated channel overwrite. +/// +public interface IPartialChannelOverwrite +{ + /// + /// The snowflake identifier of the role or user this overwrite targtes. + /// + public Optional Id { get; } + + /// + /// Specifies what kind of entity this overwrite targets. + /// + public Optional Type { get; } + + /// + /// The permissions explicitly granted by this overwrite. + /// + public Optional Allow { get; } + + /// + /// The permissions explicitly denied by this overwrite. + /// + public Optional Deny { get; } +} From f747ace9ec57e90c75406c920b9372f1df1daaaf Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sat, 1 Jul 2023 15:43:54 +0200 Subject: [PATCH 031/323] add partial roles --- .../Guilds/IPartialRole.cs | 70 ++++++++++++ .../Guilds/IRole.cs | 105 +++++++++--------- 2 files changed, 120 insertions(+), 55 deletions(-) create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IPartialRole.cs diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IPartialRole.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IPartialRole.cs new file mode 100644 index 0000000000..397723b45a --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IPartialRole.cs @@ -0,0 +1,70 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Entities; + +using Remora.Rest.Core; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Represents a partially populated role object. +/// +public interface IPartialRole +{ + /// + /// The snowflake identifier of this role. + /// + public Optional Id { get; } + + /// + /// The name of this role. + /// + public Optional Name { get; } + + /// + /// The RGB color code of this role, #000000 represents a transparent role. + /// + public Optional Color { get; } + + /// + /// Indicates whether users with this role are hoisted in the member list. + /// + public Optional Hoist { get; } + + /// + /// This role's role icon hash, if applicable. + /// + public Optional Hash { get; } + + /// + /// The unicode emoji serving as this role's role icon, if applicable. + /// + public Optional UnicodeEmoji { get; } + + /// + /// The position of this role in the role list. + /// + public Optional Position { get; } + + /// + /// The permissions associated with this role. + /// + public Optional Permissions { get; } + + /// + /// Indicates whether this role is managed by an integration. + /// + public Optional Managed { get; } + + /// + /// Indicates whether this role can be mentioned by users without the permission. + /// + public Optional Mentionable { get; } + + /// + /// Additional tags added to this role. + /// + public Optional Tags { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IRole.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IRole.cs index ce276a8495..2d1bc1cfcf 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IRole.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IRole.cs @@ -11,60 +11,55 @@ namespace DSharpPlus.Core.Abstractions.Models; /// /// Represents a role within a guild. /// -public interface IRole +public interface IRole : IPartialRole { - /// - /// The snowflake identifier of this role. - /// - public Snowflake Id { get; } - - /// - /// The name of this role. - /// - public string Name { get; } - - /// - /// The RGB color code of this role, #000000 represents a transparent role. - /// - public int Color { get; } - - /// - /// Indicates whether users with this role are hoisted in the member list. - /// - public bool Hoist { get; } - - /// - /// This role's role icon hash, if applicable. - /// - public Optional Hash { get; } - - /// - /// The unicode emoji serving as this role's role icon, if applicable. - /// - public Optional UnicodeEmoji { get; } - - /// - /// The position of this role in the role list. - /// - public int Position { get; } - - /// - /// The permissions associated with this role. - /// - public DiscordPermissions Permissions { get; } - - /// - /// Indicates whether this role is managed by an integration. - /// - public bool Managed { get; } - - /// - /// Indicates whether this role can be mentioned by users without the permission. - /// - public bool Mentionable { get; } - - /// - /// Additional tags added to this role. - /// - public Optional Tags { get; } + /// + public new Snowflake Id { get; } + + /// + public new string Name { get; } + + /// + public new int Color { get; } + + /// + public new bool Hoist { get; } + + /// + public new int Position { get; } + + /// + public new DiscordPermissions Permissions { get; } + + /// + public new bool Managed { get; } + + /// + public new bool Mentionable { get; } + + // partial access routes + + /// + Optional IPartialRole.Id => this.Id; + + /// + Optional IPartialRole.Name => this.Name; + + /// + Optional IPartialRole.Color => this.Color; + + /// + Optional IPartialRole.Hoist => this.Hoist; + + /// + Optional IPartialRole.Position => this.Position; + + /// + Optional IPartialRole.Permissions => this.Permissions; + + /// + Optional IPartialRole.Managed => this.Managed; + + /// + Optional IPartialRole.Mentionable => this.Mentionable; } From 309204d9cc554693821b88ffe8549ae07b5d065d Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sat, 1 Jul 2023 19:38:23 +0200 Subject: [PATCH 032/323] add invites --- .../Invites/IInvite.cs | 27 ++++++ .../Invites/IPartialInvite.cs | 97 +++++++++++++++++++ .../Invites/DiscordInviteTargetType.cs | 14 +++ 3 files changed, 138 insertions(+) create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/Invites/IInvite.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/Invites/IPartialInvite.cs create mode 100644 src/core/DSharpPlus.Shared/Entities/Invites/DiscordInviteTargetType.cs diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Invites/IInvite.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Invites/IInvite.cs new file mode 100644 index 0000000000..0469df4ff1 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Invites/IInvite.cs @@ -0,0 +1,27 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using Remora.Rest.Core; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Represents a discord invite object. +/// +public interface IInvite : IPartialInvite +{ + /// + public new string Code { get; } + + /// + public new IPartialChannel? Channel { get; } + + // partial access routes + + /// + Optional IPartialInvite.Code => this.Code; + + /// + Optional IPartialInvite.Channel => new(this.Channel); +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Invites/IPartialInvite.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Invites/IPartialInvite.cs new file mode 100644 index 0000000000..7f1afd3b6e --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Invites/IPartialInvite.cs @@ -0,0 +1,97 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; + +using DSharpPlus.Entities; + +using Remora.Rest.Core; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Represents a partially populated invite object. +/// +public interface IPartialInvite +{ + /// + /// The unique invite code. + /// + public Optional Code { get; } + + /// + /// The guild this invite points to. + /// + public Optional Guild { get; } + + /// + /// The channel this invite points to. + /// + public Optional Channel { get; } + + /// + /// The user who created this invite. + /// + public Optional Inviter { get; } + + /// + /// The target type of this voice channel invite. + /// + public Optional TargetType { get; } + + /// + /// The user whose stream to display for this stream invite. + /// + public Optional TargetUser { get; } + + /// + /// The embedded application to open for this embedded application invite. + /// + public Optional TargetApplication { get; } + + /// + /// The approximate count of online members for this guild. + /// + public Optional ApproximatePresenceCount { get; } + + /// + /// The approximate count of total members in this guild. + /// + public Optional ApproximateMemberCount { get; } + + /// + /// The expiration date of this invite. + /// + public Optional ExpiresAt { get; } + + /// + /// Guild scheduled event data for the guild this invite points to. + /// + public Optional GuildScheduledEvent { get; } + + /// + /// The number of times this invite has been used. + /// + public Optional Uses { get; } + + /// + /// The number of times this invite can be used. + /// + public Optional MaxUses { get; } + + /// + /// The duration in seconds after which this invite expires. + /// + public Optional MaxAge { get; } + + /// + /// Indicates whether this invite only grants temporary membership. + /// + public Optional Temporary { get; } + + /// + /// Indicates when this invite was created. + /// + public Optional CreatedAt { get; } +} diff --git a/src/core/DSharpPlus.Shared/Entities/Invites/DiscordInviteTargetType.cs b/src/core/DSharpPlus.Shared/Entities/Invites/DiscordInviteTargetType.cs new file mode 100644 index 0000000000..2264428fd8 --- /dev/null +++ b/src/core/DSharpPlus.Shared/Entities/Invites/DiscordInviteTargetType.cs @@ -0,0 +1,14 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Entities; + +/// +/// Specifies where this invite points to, if not a channel. +/// +public enum DiscordInviteTargetType +{ + Stream = 1, + EmbeddedApplication +} From 22b05f14b1fc23679228955ce0bd7076ea105046 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sat, 1 Jul 2023 19:43:08 +0200 Subject: [PATCH 033/323] add partial webhooks --- .../Webhooks/IPartialWebhook.cs | 75 ++++++++++++++ .../Webhooks/IWebhook.cs | 98 +++++++------------ 2 files changed, 113 insertions(+), 60 deletions(-) create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/Webhooks/IPartialWebhook.cs diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Webhooks/IPartialWebhook.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Webhooks/IPartialWebhook.cs new file mode 100644 index 0000000000..cc8de859d5 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Webhooks/IPartialWebhook.cs @@ -0,0 +1,75 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Entities; + +using Remora.Rest.Core; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Represents a partially populated webhook object. +/// +public interface IPartialWebhook +{ + /// + /// The snowflake identifier of this webhook. + /// + public Optional Id { get; } + + /// + /// The type of this webhook. + /// + public Optional Type { get; } + + /// + /// The snowflake identifier of the guild this webhook is for, if any. + /// + public Optional GuildId { get; } + + /// + /// The snowflake identifier of the channel this webhook is for, if any. + /// + public Optional ChannelId { get; } + + /// + /// The user who created this webhook. + /// + public Optional User { get; } + + /// + /// The default name of this webhook. + /// + public Optional Name { get; } + + /// + /// The default avatar hash of this webhook. + /// + public Optional Avatar { get; } + + /// + /// The secure token of this webhook. + /// + public Optional Token { get; } + + /// + /// The snowflake identifier of the bot/oauth2 application which created this webhook. + /// + public Optional ApplicationId { get; } + + /// + /// The guild containing the channel that this webhook is following. + /// + public Optional SourceGuild { get; } + + /// + /// The channel that this webhook is following. + /// + public Optional SourceChannel { get; } + + /// + /// The url used to execute this webhook. + /// + public Optional Url { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Webhooks/IWebhook.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Webhooks/IWebhook.cs index cc5b9d2711..e447808508 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Webhooks/IWebhook.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Webhooks/IWebhook.cs @@ -11,65 +11,43 @@ namespace DSharpPlus.Core.Abstractions.Models; /// /// Represents a discord webhook. /// -public interface IWebhook +public interface IWebhook : IPartialWebhook { - /// - /// The snowflake identifier of this webhook. - /// - public Snowflake Id { get; } - - /// - /// The type of this webhook. - /// - public DiscordWebhookType Type { get; } - - /// - /// The snowflake identifier of the guild this webhook is for, if any. - /// - public Optional GuildId { get; } - - /// - /// The snowflake identifier of the channel this webhook is for, if any. - /// - public Snowflake? ChannelId { get; } - - /// - /// The user who created this webhook. - /// - public Optional User { get; } - - /// - /// The default name of this webhook. - /// - public string? Name { get; } - - /// - /// The default avatar hash of this webhook. - /// - public string? Avatar { get; } - - /// - /// The secure token of this webhook. - /// - public Optional Token { get; } - - /// - /// The snowflake identifier of the bot/oauth2 application which created this webhook. - /// - public Snowflake? ApplicationId { get; } - - /// - /// The guild containing the channel that this webhook is following. - /// - public Optional SourceGuild { get; } - - /// - /// The channel that this webhook is following. - /// - public Optional SourceChannel { get; } - - /// - /// The url used to execute this webhook. - /// - public Optional Url { get; } + /// + public new Snowflake Id { get; } + + /// + public new DiscordWebhookType Type { get; } + + /// + public new Snowflake? ChannelId { get; } + + /// + public new string? Name { get; } + + /// + public new string? Avatar { get; } + + /// + public new Snowflake? ApplicationId { get; } + + // partial access routes + + /// + Optional IPartialWebhook.Id => this.Id; + + /// + Optional IPartialWebhook.Type => this.Type; + + /// + Optional IPartialWebhook.ChannelId => this.ChannelId; + + /// + Optional IPartialWebhook.Name => this.Name; + + /// + Optional IPartialWebhook.Avatar => this.Avatar; + + /// + Optional IPartialWebhook.ApplicationId => this.ApplicationId; } From 8ccdf14d425c282df64da0163760659edf05edc7 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sat, 1 Jul 2023 19:59:06 +0200 Subject: [PATCH 034/323] add stage instances --- .../StageInstances/IPartialStageInstance.cs | 45 ++++++++++++++++ .../StageInstances/IStageInstance.cs | 52 +++++++++++++++++++ .../DiscordStagePrivacyLevel.cs | 16 ++++++ 3 files changed, 113 insertions(+) create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/StageInstances/IPartialStageInstance.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/StageInstances/IStageInstance.cs create mode 100644 src/core/DSharpPlus.Shared/Entities/StageInstances/DiscordStagePrivacyLevel.cs diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/StageInstances/IPartialStageInstance.cs b/src/core/DSharpPlus.Core.Abstractions.Models/StageInstances/IPartialStageInstance.cs new file mode 100644 index 0000000000..d0e88138da --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/StageInstances/IPartialStageInstance.cs @@ -0,0 +1,45 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Entities; + +using Remora.Rest.Core; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Represents a partial stage instance. +/// +public interface IPartialStageInstance +{ + /// + /// The snowflake identifier of this stage instance. + /// + public Optional Id { get; } + + /// + /// The snowflake identifier of the guild this stage instance is held in. + /// + public Optional GuildId { get; } + + /// + /// The snowflake identifier of the associated stage channel. + /// + public Optional ChannelId { get; } + + /// + /// The topic of this stage instance, 1 to 120 characters. + /// + public Optional Topic { get; } + + /// + /// The privacy level of this stage instance. + /// + public Optional PrivacyLevel { get; } + + /// + /// The snowflake identifier of the scheduled event for this stage instance. + /// + public Optional GuildScheduledEventId { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/StageInstances/IStageInstance.cs b/src/core/DSharpPlus.Core.Abstractions.Models/StageInstances/IStageInstance.cs new file mode 100644 index 0000000000..8837b52c80 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/StageInstances/IStageInstance.cs @@ -0,0 +1,52 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Entities; +using Remora.Rest.Core; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Represents a live stage channel. +/// +public interface IStageInstance : IPartialStageInstance +{ + /// + public new Snowflake Id { get; } + + /// + public new Snowflake GuildId { get; } + + /// + public new Snowflake ChannelId { get; } + + /// + public new string Topic { get; } + + /// + public new DiscordStagePrivacyLevel PrivacyLevel { get; } + + /// + public new Snowflake? GuildScheduledEventId { get; } + + // partial access routes + + /// + Optional IPartialStageInstance.Id => this.Id; + + /// + Optional IPartialStageInstance.GuildId => this.GuildId; + + /// + Optional IPartialStageInstance.ChannelId => this.ChannelId; + + /// + Optional IPartialStageInstance.Topic => this.Topic; + + /// + Optional IPartialStageInstance.PrivacyLevel => this.PrivacyLevel; + + /// + Optional IPartialStageInstance.GuildScheduledEventId => this.GuildScheduledEventId; +} diff --git a/src/core/DSharpPlus.Shared/Entities/StageInstances/DiscordStagePrivacyLevel.cs b/src/core/DSharpPlus.Shared/Entities/StageInstances/DiscordStagePrivacyLevel.cs new file mode 100644 index 0000000000..92693c647a --- /dev/null +++ b/src/core/DSharpPlus.Shared/Entities/StageInstances/DiscordStagePrivacyLevel.cs @@ -0,0 +1,16 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Entities; + +/// +/// Indicates to whom this stage instance is visible. +/// +public enum DiscordStagePrivacyLevel +{ + /// + /// This stage instance is only visible to guild members. + /// + GuildOnly = 2 +} From 3e9b700f652260c44d688d44afb9ce1b157a2e23 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sat, 1 Jul 2023 20:26:49 +0200 Subject: [PATCH 035/323] add partial stickers --- .../Stickers/IPartialSticker.cs | 74 ++++++++++++++ .../Stickers/ISticker.cs | 97 ++++++++----------- 2 files changed, 112 insertions(+), 59 deletions(-) create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/Stickers/IPartialSticker.cs diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Stickers/IPartialSticker.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Stickers/IPartialSticker.cs new file mode 100644 index 0000000000..9c41e4f7b1 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Stickers/IPartialSticker.cs @@ -0,0 +1,74 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Entities; + +using Remora.Rest.Core; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Represents a partially populated sticker object. +/// +public interface IPartialSticker +{ + /// + /// The snowflake identifier of this sticker. + /// + public Optional Id { get; } + + /// + /// For standard stickers, the snowflake identifier of the pack the sticker is from. + /// + public Optional PackId { get; } + + /// + /// The name of this sticker. + /// + public Optional Name { get; } + + /// + /// The description of this sticker. + /// + public Optional Description { get; } + + /// + /// Autocomplete/suggestion tags for this sticker, up to 200 characters. + /// + /// + /// For standard stickers, this is a comma separated list of keywords. When creating or modifying a guild + /// sticker, the client will always use a name generated from an emoji here. + /// + public Optional Tags { get; } + + /// + /// The type of this sticker. + /// + public Optional Type { get; } + + /// + /// The type of this sticker file format. + /// + public Optional FormatType { get; } + + /// + /// Indicates whether this sticker can be used. + /// + public Optional Available { get; } + + /// + /// The snowflake identifier of the guild that owns this object. + /// + public Optional GuildId { get; } + + /// + /// The user that uploaded this sticker. + /// + public Optional User { get; } + + /// + /// If this is a standard sticker, the sort order within its pack. + /// + public Optional SortValue { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Stickers/ISticker.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Stickers/ISticker.cs index 7e03c7cea5..6e55532956 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Stickers/ISticker.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Stickers/ISticker.cs @@ -11,64 +11,43 @@ namespace DSharpPlus.Core.Abstractions.Models; /// /// Represents a discord sticker that can be sent in messages. /// -public interface ISticker +public interface ISticker : IPartialSticker { - /// - /// The snowflake identifier of this sticker. - /// - public Snowflake Id { get; } - - /// - /// For standard stickers, the snowflake identifier of the pack the sticker is from. - /// - public Optional PackId { get; } - - /// - /// The name of this sticker. - /// - public string Name { get; } - - /// - /// The description of this sticker. - /// - public string? Description { get; } - - /// - /// Autocomplete/suggestion tags for this sticker, up to 200 characters. - /// - /// - /// For standard stickers, this is a comma separated list of keywords. When creating or modifying a guild - /// sticker, the client will always use a name generated from an emoji here. - /// - public string Tags { get; } - - /// - /// The type of this sticker. - /// - public DiscordStickerType Type { get; } - - /// - /// The type of this sticker file format. - /// - public DiscordStickerFormatType FormatType { get; } - - /// - /// Indicates whether this sticker can be used. - /// - public Optional Available { get; } - - /// - /// The snowflake identifier of the guild that owns this object. - /// - public Optional GuildId { get; } - - /// - /// The user that uploaded this sticker. - /// - public Optional User { get; } - - /// - /// If this is a standard sticker, the sort order within its pack. - /// - public Optional SortValue { get; } + /// + public new Snowflake Id { get; } + + /// + public new string Name { get; } + + /// + public new string? Description { get; } + + /// + public new string Tags { get; } + + /// + public new DiscordStickerType Type { get; } + + /// + public new DiscordStickerFormatType FormatType { get; } + + // partial access routes + + /// + Optional IPartialSticker.Id => this.Id; + + /// + Optional IPartialSticker.Name => this.Name; + + /// + Optional IPartialSticker.Description => this.Description; + + /// + Optional IPartialSticker.Tags => this.Tags; + + /// + Optional IPartialSticker.Type => this.Type; + + /// + Optional IPartialSticker.FormatType => this.FormatType; } From 171ac2cc41833336a2828a1a4a47e61072d77d22 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sat, 1 Jul 2023 20:56:12 +0200 Subject: [PATCH 036/323] add partial scheduled events --- .../ScheduledEvents/IPartialScheduledEvent.cs | 89 +++++++++++++ .../ScheduledEvents/IScheduledEvent.cs | 123 +++++++----------- 2 files changed, 139 insertions(+), 73 deletions(-) create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/ScheduledEvents/IPartialScheduledEvent.cs diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/ScheduledEvents/IPartialScheduledEvent.cs b/src/core/DSharpPlus.Core.Abstractions.Models/ScheduledEvents/IPartialScheduledEvent.cs new file mode 100644 index 0000000000..f1b4952ab5 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/ScheduledEvents/IPartialScheduledEvent.cs @@ -0,0 +1,89 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Entities; + +using Remora.Rest.Core; +using System; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Represents a partially populated scheduled event. +/// + +// we deliberately ignore some fields listed in the documentation, because the documentation is outdated. +// it still documents data for external events (status: 2023-07-01) despite having been removed a long +// time ago... +// the following changes are thereby made from the documentation: +// - remove entity_metadata +// - remove scheduled_end_time +// - change channel_id to non-nullable +public interface IPartialScheduledEvent +{ + /// + /// The snowflake identifier of the scheduled event. + /// + public Optional Id { get; } + + /// + /// The snowflake identifier of the guild this event belongs to. + /// + public Optional GuildId { get; } + + /// + /// The snowflake identifier of the channel in which this event will be hosted. + /// + public Optional ChannelId { get; } + + /// + /// The snowflake identifier of the user that created this event. + /// + public Optional CreatorId { get; } + + /// + /// The name of this event, 1 to 100 characters. + /// + public Optional Name { get; } + + /// + /// The description of this event, 1 to 1000 characters. + /// + public Optional Description { get; } + + /// + /// The time at which this scheduled event will start. + /// + public Optional ScheduledStartTime { get; } + + /// + /// The privacy level of this event. + /// + public Optional PrivacyLevel { get; } + + /// + /// The status of this scheduled event. + /// + public Optional Status { get; } + + /// + /// The type of this scheduled event. + /// + public Optional EntityType { get; } + + /// + /// The user that created this event. + /// + public Optional Creator { get; } + + /// + /// The number of users subscribed to this event. + /// + public Optional UserCount { get; } + + /// + /// The cover image hash of this event. + /// + public Optional Image { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/ScheduledEvents/IScheduledEvent.cs b/src/core/DSharpPlus.Core.Abstractions.Models/ScheduledEvents/IScheduledEvent.cs index d075f71eaa..380b601c7f 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/ScheduledEvents/IScheduledEvent.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/ScheduledEvents/IScheduledEvent.cs @@ -13,78 +13,55 @@ namespace DSharpPlus.Core.Abstractions.Models; /// /// Represents a guild scheduled event. /// - -// we deliberately ignore some fields listed in the documentation, because the documentation is outdated. -// it still documents data for external events (status: 2023-07-01) despite having been removed a long -// time ago... -// the following changes are thereby made from the documentation: -// - remove entity_metadata -// - remove scheduled_end_time -// - change channel_id to non-nullable -public interface IScheduledEvent +public interface IScheduledEvent : IPartialScheduledEvent { - /// - /// The snowflake identifier of the scheduled event. - /// - public Snowflake Id { get; } - - /// - /// The snowflake identifier of the guild this event belongs to. - /// - public Snowflake GuildId { get; } - - /// - /// The snowflake identifier of the channel in which this event will be hosted. - /// - public Snowflake ChannelId { get; } - - /// - /// The snowflake identifier of the user that created this event. - /// - public Optional CreatorId { get; } - - /// - /// The name of this event, 1 to 100 characters. - /// - public string Name { get; } - - /// - /// The description of this event, 1 to 1000 characters. - /// - public Optional Description { get; } - - /// - /// The time at which this scheduled event will start. - /// - public DateTimeOffset ScheduledStartTime { get; } - - /// - /// The privacy level of this event. - /// - public DiscordScheduledEventPrivacyLevel PrivacyLevel { get; } - - /// - /// The status of this scheduled event. - /// - public DiscordScheduledEventStatus Status { get; } - - /// - /// The type of this scheduled event. - /// - public DiscordScheduledEventType EntityType { get; } - - /// - /// The user that created this event. - /// - public Optional Creator { get; } - - /// - /// The number of users subscribed to this event. - /// - public Optional UserCount { get; } - - /// - /// The cover image hash of this event. - /// - public Optional Image { get; } + /// + public new Snowflake Id { get; } + + /// + public new Snowflake GuildId { get; } + + /// + public new Snowflake ChannelId { get; } + + /// + public new string Name { get; } + + /// + public new DateTimeOffset ScheduledStartTime { get; } + + /// + public new DiscordScheduledEventPrivacyLevel PrivacyLevel { get; } + + /// + public new DiscordScheduledEventStatus Status { get; } + + /// + public new DiscordScheduledEventType EntityType { get; } + + // partial access routes + + /// + Optional IPartialScheduledEvent.Id => this.Id; + + /// + Optional IPartialScheduledEvent.GuildId => this.GuildId; + + /// + Optional IPartialScheduledEvent.ChannelId => this.ChannelId; + + /// + Optional IPartialScheduledEvent.Name => this.Name; + + /// + Optional IPartialScheduledEvent.ScheduledStartTime => this.ScheduledStartTime; + + /// + Optional IPartialScheduledEvent.PrivacyLevel => this.PrivacyLevel; + + /// + Optional IPartialScheduledEvent.Status => this.Status; + + /// + Optional IPartialScheduledEvent.EntityType => this.EntityType; } From 6f8884e79765a25a16fbc85f0afc873b4de0c5c4 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sat, 1 Jul 2023 20:59:44 +0200 Subject: [PATCH 037/323] add partial applicatioon command permissions --- .../IApplicationCommandPermissions.cs | 48 +++++++++++-------- .../IPartialApplicationCommandPermissions.cs | 35 ++++++++++++++ 2 files changed, 62 insertions(+), 21 deletions(-) create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/ApplicationCommands/IPartialApplicationCommandPermissions.cs diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/ApplicationCommands/IApplicationCommandPermissions.cs b/src/core/DSharpPlus.Core.Abstractions.Models/ApplicationCommands/IApplicationCommandPermissions.cs index 6bcefbe084..bb6c38fba3 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/ApplicationCommands/IApplicationCommandPermissions.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/ApplicationCommands/IApplicationCommandPermissions.cs @@ -1,4 +1,4 @@ -// This Source Code form is subject to the terms of the Mozilla Public +// This Source Code form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. @@ -11,25 +11,31 @@ namespace DSharpPlus.Core.Abstractions.Models; /// /// Represents a collection of permissions for an application command in a guild /// -public interface IApplicationCommandPermissions +public interface IApplicationCommandPermissions : IPartialApplicationCommandPermissions { - /// - /// The snowflake identifier of this command. - /// - public Snowflake Id { get; } - - /// - /// The snowflake identifier of the application this command belongs to. - /// - public Snowflake ApplicationId { get; } - - /// - /// The snowflake identifier of the guild to which these permissions apply. - /// - public Snowflake GuildId { get; } - - /// - /// The permission overrides for this command in this guild. - /// - public IReadOnlyList Permissions { get; } + /// + public new Snowflake Id { get; } + + /// + public new Snowflake ApplicationId { get; } + + /// + public new Snowflake GuildId { get; } + + /// + public new IReadOnlyList Permissions { get; } + + // partial access routes + + /// + Optional IPartialApplicationCommandPermissions.Id => this.Id; + + /// + Optional IPartialApplicationCommandPermissions.ApplicationId => this.ApplicationId; + + /// + Optional IPartialApplicationCommandPermissions.GuildId => this.GuildId; + + /// + Optional> IPartialApplicationCommandPermissions.Permissions => new(this.Permissions); } diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/ApplicationCommands/IPartialApplicationCommandPermissions.cs b/src/core/DSharpPlus.Core.Abstractions.Models/ApplicationCommands/IPartialApplicationCommandPermissions.cs new file mode 100644 index 0000000000..432dd00289 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/ApplicationCommands/IPartialApplicationCommandPermissions.cs @@ -0,0 +1,35 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using Remora.Rest.Core; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Represents a partial set of application command permissions. +/// +public interface IPartialApplicationCommandPermissions +{ + /// + /// The snowflake identifier of this command. + /// + public Optional Id { get; } + + /// + /// The snowflake identifier of the application this command belongs to. + /// + public Optional ApplicationId { get; } + + /// + /// The snowflake identifier of the guild to which these permissions apply. + /// + public Optional GuildId { get; } + + /// + /// The permission overrides for this command in this guild. + /// + public Optional> Permissions { get; } +} From d233af5d44893f3c71f155a806f5baba9302f17e Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sat, 1 Jul 2023 21:13:14 +0200 Subject: [PATCH 038/323] add partial auto mod rules --- .../AutoModeration/IAutoModerationRule.cs | 123 ++++++++++-------- .../IPartialAutoModerationRule.cs | 72 ++++++++++ 2 files changed, 140 insertions(+), 55 deletions(-) create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/AutoModeration/IPartialAutoModerationRule.cs diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/AutoModeration/IAutoModerationRule.cs b/src/core/DSharpPlus.Core.Abstractions.Models/AutoModeration/IAutoModerationRule.cs index 6758fbab40..c96793442d 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/AutoModeration/IAutoModerationRule.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/AutoModeration/IAutoModerationRule.cs @@ -13,60 +13,73 @@ namespace DSharpPlus.Core.Abstractions.Models; /// /// Represents an auto moderation rule within a guild. /// -public interface IAutoModerationRule +public interface IAutoModerationRule : IPartialAutoModerationRule { - /// - /// The snowflake identifier of this rule. - /// - public Snowflake Id { get; } - - /// - /// The snowflake identifier of the guild this rule belongs to. - /// - public Snowflake GuildId { get; } - - /// - /// The display name of this rule. - /// - public string Name { get; } - - /// - /// The snowflake identifier of the user who created this rule. - /// - public Snowflake CreatorId { get; } - - /// - /// The type of event that causes this rule to fire. - /// - public DiscordAutoModerationEventType EventType { get; } - - /// - /// The trigger type of this rule. - /// - public DiscordAutoModerationTriggerType TriggerType { get; } - - /// - /// Additional metadata for this rule trigger. - /// - public IAutoModerationTriggerMetadata TriggerMetadata { get; } - - /// - /// The actions which wille xecute when this rule is triggered. - /// - public IReadOnlyList Actions { get; } - - /// - /// Indicates whether this rule should be enabled. - /// - public bool Enabled { get; } - - /// - /// Up to 20 role IDs that should be exempted from this rule. - /// - public IReadOnlyList ExemptRoles { get; } - - /// - /// Up to 50 channel IDs that should be exempted from this rule. - /// - public IReadOnlyList ExemptChannels { get; } + /// + public new Snowflake Id { get; } + + /// + public new Snowflake GuildId { get; } + + /// + public new string Name { get; } + + /// + public new Snowflake CreatorId { get; } + + /// + public new DiscordAutoModerationEventType EventType { get; } + + /// + public new DiscordAutoModerationTriggerType TriggerType { get; } + + /// + public new IAutoModerationTriggerMetadata TriggerMetadata { get; } + + /// + public new IReadOnlyList Actions { get; } + + /// + public new bool Enabled { get; } + + /// + public new IReadOnlyList ExemptRoles { get; } + + /// + public new IReadOnlyList ExemptChannels { get; } + + // partial access routes + + /// + Optional IPartialAutoModerationRule.Id => this.Id; + + /// + Optional IPartialAutoModerationRule.GuildId => this.GuildId; + + /// + Optional IPartialAutoModerationRule.Name => this.Name; + + /// + Optional IPartialAutoModerationRule.CreatorId => this.CreatorId; + + /// + Optional IPartialAutoModerationRule.EventType => this.EventType; + + /// + Optional IPartialAutoModerationRule.TriggerType => this.TriggerType; + + /// + Optional IPartialAutoModerationRule.TriggerMetadata => new(this.TriggerMetadata); + + /// + Optional> IPartialAutoModerationRule.Actions => new(this.Actions); + + /// + Optional IPartialAutoModerationRule.Enabled => this.Enabled; + + /// + Optional> IPartialAutoModerationRule.ExemptRoles => new(this.ExemptRoles); + + /// + Optional> IPartialAutoModerationRule.ExemptChannels => new(this.ExemptChannels); } diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/AutoModeration/IPartialAutoModerationRule.cs b/src/core/DSharpPlus.Core.Abstractions.Models/AutoModeration/IPartialAutoModerationRule.cs new file mode 100644 index 0000000000..e12c5a31d3 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/AutoModeration/IPartialAutoModerationRule.cs @@ -0,0 +1,72 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Entities; + +using Remora.Rest.Core; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Represents a partial auto-moderation rule. +/// +public interface IPartialAutoModerationRule +{ + /// + /// The snowflake identifier of this rule. + /// + public Optional Id { get; } + + /// + /// The snowflake identifier of the guild this rule belongs to. + /// + public Optional GuildId { get; } + + /// + /// The display name of this rule. + /// + public Optional Name { get; } + + /// + /// The snowflake identifier of the user who created this rule. + /// + public Optional CreatorId { get; } + + /// + /// The type of event that causes this rule to fire. + /// + public Optional EventType { get; } + + /// + /// The trigger type of this rule. + /// + public Optional TriggerType { get; } + + /// + /// Additional metadata for this rule trigger. + /// + public Optional TriggerMetadata { get; } + + /// + /// The actions which wille xecute when this rule is triggered. + /// + public Optional> Actions { get; } + + /// + /// Indicates whether this rule should be enabled. + /// + public Optional Enabled { get; } + + /// + /// Up to 20 role IDs that should be exempted from this rule. + /// + public Optional> ExemptRoles { get; } + + /// + /// Up to 50 channel IDs that should be exempted from this rule. + /// + public Optional> ExemptChannels { get; } +} From 04a4a3ff084fea87452d2d785d6eb44c6d4967af Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sat, 1 Jul 2023 21:15:37 +0200 Subject: [PATCH 039/323] add followed channels --- .../Channels/IFollowedChannel.cs | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/Channels/IFollowedChannel.cs diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IFollowedChannel.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IFollowedChannel.cs new file mode 100644 index 0000000000..72af6008fb --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IFollowedChannel.cs @@ -0,0 +1,23 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using Remora.Rest.Core; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Represents a followed channel, whose messages will be crossposted. +/// +public interface IFollowedChannel +{ + /// + /// The snowflake identifier of the source channel. + /// + public Snowflake ChannelId { get; } + + /// + /// The snowflake identifier of the crossposting webhook. + /// + public Snowflake WebhookId { get; } +} From d00294222e979b9e89d73cfd05562516dfb4b903 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sat, 1 Jul 2023 22:55:15 +0200 Subject: [PATCH 040/323] add guild previews --- .../Guilds/IGuildPreview.cs | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IGuildPreview.cs diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IGuildPreview.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IGuildPreview.cs new file mode 100644 index 0000000000..c50fb8234f --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IGuildPreview.cs @@ -0,0 +1,70 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using Remora.Rest.Core; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Represents a guild preview object. +/// +public interface IGuildPreview +{ + /// + /// The snowflake identifier of the guild this preview belongs to. + /// + public Snowflake Id { get; } + + /// + /// The name of this guild, between 2 and 100 characters. + /// + public string Name { get; } + + /// + /// The icon hash for this guild. + /// + public string? Icon { get; } + + /// + /// The splash hash for this guild. + /// + public string? Splash { get; } + + /// + /// The discovery splash hash for this guild. + /// + public string? DiscoverySplash { get; } + + /// + /// The custom emojis in this guild. + /// + public IReadOnlyList Emojis { get; } + + /// + /// The enabled guild features. + /// + public IReadOnlyList Features { get; } + + /// + /// The approximate amount of members in this guild. + /// + public int ApproximateMemberCount { get; } + + /// + /// The approximate amount of online members in this guild. + /// + public int ApproximatePresenceCount { get; } + + /// + /// The description of this guild. + /// + public string? Description { get; } + + /// + /// The custom stickers in this guild. + /// + public IReadOnlyList Stickers { get; } +} From 2b290422b44861e655109b5e87edc40a919fd6b2 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sun, 2 Jul 2023 11:06:47 +0200 Subject: [PATCH 041/323] add guild widgets --- .../Guilds/IGuildWidget.cs | 45 +++++++++++++++++++ .../Guilds/IGuildWidgetSettings.cs | 23 ++++++++++ 2 files changed, 68 insertions(+) create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IGuildWidget.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IGuildWidgetSettings.cs diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IGuildWidget.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IGuildWidget.cs new file mode 100644 index 0000000000..28b0257c19 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IGuildWidget.cs @@ -0,0 +1,45 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using Remora.Rest.Core; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Represents a guild's widget object. +/// +public interface IGuildWidget +{ + /// + /// The snowflake identifier of the guild this widget belongs to. + /// + public Snowflake Id { get; } + + /// + /// The name of the guild, 2 to 100 characters. + /// + public string Name { get; } + + /// + /// An instant invite code for the guild's specified widget invite channel. + /// + public string? InstantInvite { get; } + + /// + /// Voice and stage channels accessible by everyone. + /// + public IReadOnlyList Channels { get; } + + /// + /// Up to 100 users including their presences. + /// + public IReadOnlyList Members { get; } + + /// + /// The number of online members in this guild. + /// + public int PresenceCount { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IGuildWidgetSettings.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IGuildWidgetSettings.cs new file mode 100644 index 0000000000..4c8eb04da3 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IGuildWidgetSettings.cs @@ -0,0 +1,23 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using Remora.Rest.Core; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Contains settings for this guild's widget. +/// +public interface IGuildWidgetSettings +{ + /// + /// Indicates whether the widget is enabled. + /// + public bool Enabled { get; } + + /// + /// The snowflake identifier of the widget channel. + /// + public Snowflake? ChannelId { get; } +} From 1247df1362b8f5b23c26afb9f4391952b0cae5a5 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sun, 2 Jul 2023 11:08:04 +0200 Subject: [PATCH 042/323] add ban --- .../Guilds/IBan.cs | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IBan.cs diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IBan.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IBan.cs new file mode 100644 index 0000000000..9cbc5a659b --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IBan.cs @@ -0,0 +1,21 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Represents information about a ban from a guild. +/// +public interface IBan +{ + /// + /// The ban reason. + /// + public string? Reason { get; } + + /// + /// The banned user. + /// + public IUser User { get; } +} From b11cab3b2fc34665e8fa6e68c0e601d00c39696e Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Mon, 3 Jul 2023 15:35:50 +0200 Subject: [PATCH 043/323] add onboarding --- .../Guilds/IOnboarding.cs | 35 ++++++++++++ .../Guilds/IOnboardingPrompt.cs | 53 +++++++++++++++++++ .../Guilds/IOnboardingPromptOption.cs | 45 ++++++++++++++++ .../DiscordGuildOnboardingPromptType.cs | 14 +++++ 4 files changed, 147 insertions(+) create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IOnboarding.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IOnboardingPrompt.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IOnboardingPromptOption.cs create mode 100644 src/core/DSharpPlus.Shared/Entities/Guilds/DiscordGuildOnboardingPromptType.cs diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IOnboarding.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IOnboarding.cs new file mode 100644 index 0000000000..83cc0f20c0 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IOnboarding.cs @@ -0,0 +1,35 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using Remora.Rest.Core; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Represents the guild onboarding flow for the given guild. +/// +public interface IOnboarding +{ + /// + /// The snowflake identifier of the guild this onboarding is part of. + /// + public Snowflake GuildId { get; } + + /// + /// Prompts shown during onboarding and in Customize Community + /// + public IReadOnlyList Prompts { get; } + + /// + /// Snowflake identifiers of channels that members are "opted into" automatically. + /// + public IReadOnlyList DefaultChannelIds { get; } + + /// + /// Indicates whether onboarding is enabled in the guild. + /// + public bool Enabled { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IOnboardingPrompt.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IOnboardingPrompt.cs new file mode 100644 index 0000000000..9976f6cf90 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IOnboardingPrompt.cs @@ -0,0 +1,53 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Entities; + +using Remora.Rest.Core; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Represents an user prompt during the onboarding flow. +/// +public interface IOnboardingPrompt +{ + /// + /// The snowflake identifier of the prompt option. + /// + public Snowflake Id { get; } + + /// + /// The type of this prompt. + /// + public DiscordGuildOnboardingPromptType Type { get; } + + /// + /// The options available within this prompt. + /// + public IReadOnlyList Options { get; } + + /// + /// The title of this prompt. + /// + public string Title { get; } + + /// + /// Indicates whether users are limited to selecting only one of the . + /// + public bool SingleSelect { get; } + + /// + /// Indicates whether this prompt is required to be completed before the user can complete the onboarding flow. + /// + public bool Required { get; } + + /// + /// Indicates whether this prompt is present in the onboarding flow. If , the + /// prompt will only appear in Customize Community. + /// + public bool InOnboarding { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IOnboardingPromptOption.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IOnboardingPromptOption.cs new file mode 100644 index 0000000000..312750eae3 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IOnboardingPromptOption.cs @@ -0,0 +1,45 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using Remora.Rest.Core; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Represents an option for a guild onboarding prompt. +/// +public interface IOnboardingPromptOption +{ + /// + /// The snowflake identifier of the prompt option. + /// + public Snowflake Id { get; } + + /// + /// The snowflake identifiers for channels a member is added to when this option is selected. + /// + public IReadOnlyList ChannelIds { get; } + + /// + /// The snowflake identifiers for roles assigned to a member when this option is selected. + /// + public IReadOnlyList RoleIds { get; } + + /// + /// The emoji for this option. + /// + public IEmoji Emoji { get; } + + /// + /// The title of this option. + /// + public string Title { get; } + + /// + /// The description of this option. + /// + public string? Description { get; } +} diff --git a/src/core/DSharpPlus.Shared/Entities/Guilds/DiscordGuildOnboardingPromptType.cs b/src/core/DSharpPlus.Shared/Entities/Guilds/DiscordGuildOnboardingPromptType.cs new file mode 100644 index 0000000000..eeac34104a --- /dev/null +++ b/src/core/DSharpPlus.Shared/Entities/Guilds/DiscordGuildOnboardingPromptType.cs @@ -0,0 +1,14 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Entities; + +/// +/// Represents the type of a guild onboarding prompt +/// +public enum DiscordGuildOnboardingPromptType +{ + MultipleChoice, + Dropdown +} From aa573f221da7f464a874a2d2f88792da3263ed0a Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Mon, 3 Jul 2023 15:40:33 +0200 Subject: [PATCH 044/323] add scheduled event users --- .../ScheduledEvents/IScheduledEventUser.cs | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/ScheduledEvents/IScheduledEventUser.cs diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/ScheduledEvents/IScheduledEventUser.cs b/src/core/DSharpPlus.Core.Abstractions.Models/ScheduledEvents/IScheduledEventUser.cs new file mode 100644 index 0000000000..20e4d86c2f --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/ScheduledEvents/IScheduledEventUser.cs @@ -0,0 +1,28 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using Remora.Rest.Core; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Serves as a container object for users and the scheduled event they have subscribed to. +/// +public interface IScheduledEventUser +{ + /// + /// The snowflake identifier of the event this user has subscribed to. + /// + public Snowflake GuildScheduledEventId { get; } + + /// + /// The user which subscribed to the event. + /// + public IUser User { get; } + + /// + /// Guild member data for this user for the guild which this event belongs to. + /// + public Optional Member { get; } +} From 9b678175f3a4e5f11c78607ff2ec5f7ccc35d000 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Mon, 3 Jul 2023 16:02:09 +0200 Subject: [PATCH 045/323] add guild templates --- .../GuildTemplates/ITemplate.cs | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/GuildTemplates/ITemplate.cs diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/GuildTemplates/ITemplate.cs b/src/core/DSharpPlus.Core.Abstractions.Models/GuildTemplates/ITemplate.cs new file mode 100644 index 0000000000..f91b91c6e0 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/GuildTemplates/ITemplate.cs @@ -0,0 +1,71 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; + +using Remora.Rest.Core; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Represents a guild template that, when used, creates a guild with default settings taken from +/// a snapshot of an existing guild. +/// +public interface ITemplate +{ + /// + /// The unique template code. + /// + public string Code { get; } + + /// + /// The name of this template. + /// + public string Name { get; } + + /// + /// The description for this template. + /// + public string? Description { get; } + + /// + /// The amount of times this template has been used. + /// + public int UsageCount { get; } + + /// + /// The snowflake identifier of the user who created this template. + /// + public Snowflake CreatorId { get; } + + /// + /// The user who created this template. + /// + public IUser Creator { get; } + + /// + /// Indicates when this template was created. + /// + public DateTimeOffset CreatedAt { get; } + + /// + /// Indicates when this template was last synced to the source guild. + /// + public DateTimeOffset UpdatedAt { get; } + + /// + /// The snowflake identifier of the guild this template is based on. + /// + public Snowflake SourceGuildId { get; } + + /// + /// The guild snapshot this template contains. + /// + public IPartialGuild SerializedSourceGuild { get; } + + /// + /// Indicates whether this template has unsynced changes. + /// + public bool? IsDirty { get; } +} From 7485a6d5ac4d0ef6fb3ab6b4f8832a38a39c6f90 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Mon, 3 Jul 2023 16:24:19 +0200 Subject: [PATCH 046/323] add sticker packs --- .../Stickers/IStickerPack.cs | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/Stickers/IStickerPack.cs diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Stickers/IStickerPack.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Stickers/IStickerPack.cs new file mode 100644 index 0000000000..3cbf9eb904 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Stickers/IStickerPack.cs @@ -0,0 +1,50 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using Remora.Rest.Core; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Represents a pack of standard stickers. +/// +public interface IStickerPack +{ + /// + /// The snowflake identifier of this sticker pack. + /// + public Snowflake Id { get; } + + /// + /// The stickers in this pack. + /// + public IReadOnlyList Stickers { get; } + + /// + /// The name of this sticker pack. + /// + public string Name { get; } + + /// + /// The snowflake identifier of the pack's SKU. + /// + public Snowflake SkuId { get; } + + /// + /// The snowflake of the sticker shown as the pack's icon. + /// + public Optional CoverStickerId { get; } + + /// + /// The description of this sticker pack. + /// + public string Description { get; } + + /// + /// The snowflake identifier of this pack's banner image. + /// + public Optional BannerAssetId { get; } +} From 7be5fbdbe4f4b143c21f5d62c80d7f050f46b67a Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Mon, 3 Jul 2023 17:14:19 +0200 Subject: [PATCH 047/323] add user connections --- .../Users/IConnection.cs | 67 +++++++++++++++++++ .../Users/DiscordConnectionVisibility.cs | 21 ++++++ 2 files changed, 88 insertions(+) create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/Users/IConnection.cs create mode 100644 src/core/DSharpPlus.Shared/Entities/Users/DiscordConnectionVisibility.cs diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Users/IConnection.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Users/IConnection.cs new file mode 100644 index 0000000000..e3b9b17508 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Users/IConnection.cs @@ -0,0 +1,67 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Entities; + +using Remora.Rest.Core; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Represents an account connection on an user. +/// +public interface IConnection +{ + /// + /// The identifier of the connection account. + /// + public string Id { get; } + + /// + /// The name of the connection acount. + /// + public string Name { get; } + + /// + /// The service for this connection. + /// + public string Type { get; } + + /// + /// Indicates whether this connection has been revoked. + /// + public Optional Revoked { get; } + + /// + /// Corresponding partial integrations. + /// + public Optional> Integrations { get; } + + /// + /// Indicates whether this connection is verified. + /// + public bool Verified { get; } + + /// + /// Indicates whether friend sync is enabled for this connection. + /// + public bool FriendSync { get; } + + /// + /// Indicates whether activities related to this connection will be shown in presences. + /// + public bool ShowActivity { get; } + + /// + /// Indicates whether this connection has a corresponding third-party OAuth2 token. + /// + public bool TwoWayLink { get; } + + /// + /// The visibility of this connection. + /// + public DiscordConnectionVisibility Visibility { get; } +} diff --git a/src/core/DSharpPlus.Shared/Entities/Users/DiscordConnectionVisibility.cs b/src/core/DSharpPlus.Shared/Entities/Users/DiscordConnectionVisibility.cs new file mode 100644 index 0000000000..fb8326cea0 --- /dev/null +++ b/src/core/DSharpPlus.Shared/Entities/Users/DiscordConnectionVisibility.cs @@ -0,0 +1,21 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Entities; + +/// +/// Represents the visibility of a user profile connection. +/// +public enum DiscordConnectionVisibility +{ + /// + /// Visible to only the user themself. + /// + None, + + /// + /// Visible to everyone. + /// + Everyone +} From ea333c5182f69cbaca80709506b6be0faf46b5b3 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Mon, 3 Jul 2023 17:19:07 +0200 Subject: [PATCH 048/323] add role connections --- .../Users/IApplicationRoleConnection.cs | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/Users/IApplicationRoleConnection.cs diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Users/IApplicationRoleConnection.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Users/IApplicationRoleConnection.cs new file mode 100644 index 0000000000..490918f30d --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Users/IApplicationRoleConnection.cs @@ -0,0 +1,28 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Represents a role connection object that an application has attached to a user. +/// +public interface IApplicationRoleConnection +{ + /// + /// The vanity name of the platform the application has connected, up to 50 characters. + /// + public string? PlatformName { get; } + + /// + /// The username of this user on the platform the application has connected, up to 100 characters. + /// + public string? PlatformUsername { get; } + + /// + /// The metadata keys and values for this user on the given platform. + /// + public IReadOnlyDictionary Metadata { get; } +} From 68842da29733031f8ff0940d196c2ce33213a565 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Mon, 3 Jul 2023 17:32:41 +0200 Subject: [PATCH 049/323] voice objects --- .../Voice/IVoiceRegion.cs | 36 +++++++++ .../Voice/IVoiceState.cs | 80 +++++++++++++++++++ 2 files changed, 116 insertions(+) create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/Voice/IVoiceRegion.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/Voice/IVoiceState.cs diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Voice/IVoiceRegion.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Voice/IVoiceRegion.cs new file mode 100644 index 0000000000..88e47c0177 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Voice/IVoiceRegion.cs @@ -0,0 +1,36 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Represents metadata about a voice region. +/// +public interface IVoiceRegion +{ + /// + /// The unique identifier of this region. + /// + public string Id { get; } + + /// + /// The name of this region. + /// + public string Name { get; } + + /// + /// Indicates whether this is the closest server to the current user's client. + /// + public bool Optimal { get; } + + /// + /// Indicates whether this is a deprecated voice region. + /// + public bool Deprecated { get; } + + /// + /// Indicates whether this is a custom voice region, used for official events etc. + /// + public bool Custom { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Voice/IVoiceState.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Voice/IVoiceState.cs new file mode 100644 index 0000000000..4cad827b14 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Voice/IVoiceState.cs @@ -0,0 +1,80 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; + +using Remora.Rest.Core; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Represents a user's voice connection status. +/// +public interface IVoiceState +{ + /// + /// The snowflake identifier of the guild this voice state is for. + /// + public Optional GuildId { get; } + + /// + /// The snowflake identifier of the channel this user is connected to, if none. + /// + public Snowflake? ChannelId { get; } + + /// + /// The snowflake identifier of the user this voice state is for. + /// + public Snowflake UserId { get; } + + /// + /// The guild member this voice state is for. + /// + public Optional Member { get; } + + /// + /// The session identifier for this voice state. + /// + public string SessionId { get; } + + /// + /// Indicates whether this user is deafened by the server. + /// + public bool Deaf { get; } + + /// + /// Indicates whether this user is muted by the server. + /// + public bool Mute { get; } + + /// + /// Indicates whether this user has deafened themselves. + /// + public bool SelfDeaf { get; } + + /// + /// Indicates whether this user has muted themselves. + /// + public bool SelfMute { get; } + + /// + /// Indicates whether this user is streaming in the voice channel. + /// + public Optional SelfStream { get; } + + /// + /// Indicates whether this user's camera is enabled. + /// + public bool SelfVideo { get; } + + /// + /// Indicates whether this user's permission to speak is denied. + /// + public bool Suppress { get; } + + /// + /// The time at which this user requested to speak. + /// + public DateTimeOffset? RequestToSpeakTimestamp { get; } +} From 3e7d5d9521ccd1648e34fcff05cd4a97c727796d Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Wed, 5 Jul 2023 17:31:09 +0200 Subject: [PATCH 050/323] sacrifice my sanity for a later date adds a huge powershell script controlling the build process --- .gitignore | 5 +- DSharpPlus.sln | 16 + dsharpplus.ps1 | 182 +++++++ script-functions.ps1 | 486 ++++++++++++++++++ src/core/DSharpPlus.Core.sln | 45 ++ tools/Directory.Build.props | 18 + .../Program.cs | 5 + ....Generators.GenerateConcreteObjects.csproj | 7 + 8 files changed, 762 insertions(+), 2 deletions(-) create mode 100644 dsharpplus.ps1 create mode 100644 script-functions.ps1 create mode 100644 src/core/DSharpPlus.Core.sln create mode 100644 tools/Directory.Build.props create mode 100644 tools/generators/Tools.Generators.GenerateConcreteObjects/Program.cs create mode 100644 tools/generators/Tools.Generators.GenerateConcreteObjects/Tools.Generators.GenerateConcreteObjects.csproj diff --git a/.gitignore b/.gitignore index 2521118b54..6578864066 100644 --- a/.gitignore +++ b/.gitignore @@ -406,5 +406,6 @@ DSharpPlus.Test/config.json # Docfx docs/_site -# .NET 8 UseArtifactsOutput -.artifacts/ \ No newline at end of file +# tool test environment +.testenv +.testenvhost \ No newline at end of file diff --git a/DSharpPlus.sln b/DSharpPlus.sln index 6a78b23084..29c5e1ed70 100644 --- a/DSharpPlus.sln +++ b/DSharpPlus.sln @@ -9,6 +9,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DSharpPlus.Shared", "src\co EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DSharpPlus.Core.Abstractions.Models", "src\core\DSharpPlus.Core.Abstractions.Models\DSharpPlus.Core.Abstractions.Models.csproj", "{E14B0AE9-FE71-4DE4-BEB1-4A8E139DB84C}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Core", "Core", "{BC8D8750-48A4-49EF-9D1F-BE4DBA5B500E}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tools", "Tools", "{EAC2F7ED-0965-4607-ACE0-829885A612C5}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tools.Generators.GenerateConcreteObjects", "tools\generators\Tools.Generators.GenerateConcreteObjects\Tools.Generators.GenerateConcreteObjects.csproj", "{DF07A6C6-4689-44DC-80B0-479CA7C6AAF6}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -27,10 +33,20 @@ Global {E14B0AE9-FE71-4DE4-BEB1-4A8E139DB84C}.Debug|Any CPU.Build.0 = Debug|Any CPU {E14B0AE9-FE71-4DE4-BEB1-4A8E139DB84C}.Release|Any CPU.ActiveCfg = Release|Any CPU {E14B0AE9-FE71-4DE4-BEB1-4A8E139DB84C}.Release|Any CPU.Build.0 = Release|Any CPU + {DF07A6C6-4689-44DC-80B0-479CA7C6AAF6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {DF07A6C6-4689-44DC-80B0-479CA7C6AAF6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DF07A6C6-4689-44DC-80B0-479CA7C6AAF6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {DF07A6C6-4689-44DC-80B0-479CA7C6AAF6}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {FBCCE5A7-0E07-4FCF-B9BB-B913F5A17FB2} = {BC8D8750-48A4-49EF-9D1F-BE4DBA5B500E} + {964AD252-F077-4AB5-8D92-6C594D08F078} = {BC8D8750-48A4-49EF-9D1F-BE4DBA5B500E} + {E14B0AE9-FE71-4DE4-BEB1-4A8E139DB84C} = {BC8D8750-48A4-49EF-9D1F-BE4DBA5B500E} + {DF07A6C6-4689-44DC-80B0-479CA7C6AAF6} = {EAC2F7ED-0965-4607-ACE0-829885A612C5} + EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {55CDA684-8900-479B-9DAE-BA3BE09B337B} EndGlobalSection diff --git a/dsharpplus.ps1 b/dsharpplus.ps1 new file mode 100644 index 0000000000..f81036c757 --- /dev/null +++ b/dsharpplus.ps1 @@ -0,0 +1,182 @@ +<################################################################################################## + +This script serves as the main entrypoint for the DSharpPlus build tooling. It should, at all +times, be targeted towards windows and linux simultaneously; which means keeping the script OS- +agnostic where possible and special-casing certain points as needed. + +It is tasked with the following aims: + +- run all or only a selection of tools, under `run tools` + - run all or only a selection of generating tools, under `run generators` + - run all or only a selection of analyzing tools, under `run analyzers` +- build all or only a selection of tools without running, under `build tools` +- test all or only a selection of tools, under `test tools` + +- publish specific 'areas', under `publish -subset ` + +##################################################################################################> + +#requires -Version 6 + +<# +.PARAMETER Help + Indicates whether to display the help output. + +.PARAMETER Action + The primary action to perform. + +.PARAMETER ToolGroup + The group of tools to execute this action on. + +.PARAMETER Subset + The subset of libraries or tools to execute this action on. + +.PARAMETER Names + The granular names of tools to execute this action on. +#> + +param ( + [Alias('h')] + [Alias('?')] + [switch]$Help, + + [Parameter(Position = 0)] + [ValidateSet("run", "build", "test", "publish")] + [string]$Action, + + [Parameter(Position = 1)] + [ValidateSet("tools", "generators", "analyzers")] + [string]$ToolGroup, + + [Alias('s')] + [ValidateSet("core")] + [string[]]$Subset, + + [Alias('n')] + [string[]]$Names +) + +$ErrorActionPreference = 'Stop' + +. "$PSScriptRoot/script-functions.ps1" + +if ($Help) { + Get-ScriptHelp + exit 0 +} + +if($Names.Count -gt 0) { + switch ($Action) { + "run" { + Invoke-Tools -Tools $Names + } + "build" { + Build-Tools -Tools $Names + } + "test" { + Test-Tools -Tools $Names + } + } + + exit 0 +} + +if ((![System.String]::IsNullOrWhiteSpace($ToolGroup)) -and ($Subset.Count -le 0)) { + [string[]]$ToolsToExecute = @() + + switch ($ToolGroup) { + "tools" { + # this must be in order, as analyzers can operate on generated code + $ToolsToExecute = $Generators + $Analyzers + } + "generators" { + $ToolsToExecute = $Generators + } + "analyzers" { + $ToolsToExecute = $Analyzers + } + } + + switch ($Action) { + "run" { + Invoke-Tools -Tools $ToolsToExecute + } + "build" { + Build-Tools -Tools $ToolsToExecute + } + "test" { + Test-Tools -Tools $ToolsToExecute + } + } + + exit 0 +} + +[string[]]$SubsetsToExecute = @() + +if ($Subset.Count -gt 0) { + $SubsetsToExecute = $Subset +} +else { + $SubsetsToExecute = $AllSubsets +} + +if ($Action -eq "publish") { + foreach($Target in $SubsetsToExecute) { + Publish-Subset $Target + } + + exit 0 +} + +[string[]]$ToolsToExecute = @() + +# construct the list of tools we want to execute +# this looks a little scuffed, so, explanation: +# +# firstly, we filter by tool group. +# then, the tool group dictating what tools to add, +# we foreach over the supplied subsets to add the +# tools +switch ($ToolGroup) { + "tools" { + foreach ($Target in $SubsetsToExecute) { + switch ($Target) { + "core" { + $ToolsToExecute += $CoreGenerators + $ToolsToExecute += $CoreAnalyzers + } + } + } + } + "generators" { + foreach ($Target in $SubsetsToExecute) { + switch ($Target) { + "core" { + $ToolsToExecute += $CoreGenerators + } + } + } + } + "analyzers" { + foreach ($Target in $SubsetsToExecute) { + switch ($Target) { + "core" { + $ToolsToExecute += $CoreAnalyzers + } + } + } + } +} + +switch ($Action) { + "run" { + Invoke-Tools -Tools $ToolsToExecute + } + "build" { + Build-Tools -Tools $ToolsToExecute + } + "test" { + Test-Tools -Tools $ToolsToExecute + } +} diff --git a/script-functions.ps1 b/script-functions.ps1 new file mode 100644 index 0000000000..01405ce8a5 --- /dev/null +++ b/script-functions.ps1 @@ -0,0 +1,486 @@ +<################################################################################################## + +This section of the script contains miscellaneous types for later use. Refer to the individual +documentation of each type. + +##################################################################################################> + +<# +.SYNOPSIS + Enumerates known kinds of tools; for use in a variety of commands. +#> +enum ToolType { + Generator + Analyzer +} + +<################################################################################################## + +This section of the script contains hashtables and arrays for later use. When adding, removing or +renaming tools, this section must be kept up to date. + +##################################################################################################> + +[string[]]$CoreGenerators = @( + "generate-concrete-objects" +) + +[string[]]$CoreAnalyzers = @() + +[string[]] $Generators = $CoreGenerators + +[string[]] $Analyzers = $CoreAnalyzers + +[hashtable]$CoreGeneratorTable = [ordered]@{ + "generate-concrete-objects" = "Tools.Generators.GenerateConcreteObjects" +} + +# word of warning: don't rely on GeneratorTable and AnalyzerTable to be ordered correctly +[hashtable]$GeneratorTable = $CoreGeneratorTable + +[hashtable]$AnalyzerTable = @{} + +[string[]]$AllSubsets = @( + "core" +) + +<################################################################################################## + +This section of the script contains functions, to be used and re-used so as to keep the code +more readable. Refer to the individual documentation of each function. + +##################################################################################################> + +function Get-ScriptHelp { + Write-Host "This is the primary script controlling the DSharpPlus build." + Write-Host "" + Write-Host "Usage: dsharpplus [action] " + Write-Host "" + Write-Host "Actions:" + Write-Host " run Runs the given tools or subset of tools." + Write-Host " build Builds the given tools or subset of tools." + Write-Host " test Tests the given tools or subset of tools." + Write-Host " publish Publishes the given subset of the library." + Write-Host "" + Write-Host "Groups:" + Write-Host "Note that groups are only valid when operating on tools" -ForegroundColor Gray + Write-Host "" + Write-Host " tools Indiscriminately operates on all kinds of tools." + Write-Host " generators Operates on tools intended to generate code or metadata." + Write-Host " analyzers Operates on tools intended to analyze and communicate the validity" + + "of existing code or metadata" + Write-Host "" + Write-Host "Options:" + Write-Host "" + Write-Host " -s|-subset Specifies one or more subsets to operate on" + Write-Host " -n|-names Specifies the individual names of tools to operate on." + Write-Host "" + Write-Host "Examples:" + Write-Host "" + Write-Host "The following command will run all core tools:" + Write-Host "dsharpplus run tools -subset core" -ForegroundColor Gray + Write-Host "" + Write-Host "The following command will run all core generators:" + Write-Host "dsharpplus run generators -subset core" -ForegroundColor Gray + Write-Host "" + Write-Host "The following command will only run a single tool, generate-concrete-objects:" + Write-Host "dsharpplus run tools -name generate-concrete-objects" -ForegroundColor Gray + Write-Host "" + Write-Host "The following command will build the core library as well as the caching logic:" + Write-Host "dsharpplus publish -subset core,cache" + Write-Host "" +} + +function Publish-Subset { + <# + .SYNOPSIS + Publishes and packs a subset of the library, ready to be used. + + .PARAMETER Subset + The identifier of the subset. + + .INPUTS + This function accepts the subset from the pipeline. + #> + + param ( + [Parameter(Position = 0, Mandatory = $true, ValueFromPipeline = $true)] + [string]$Subset + ) + + dotnet pack "$PSScriptRoot/src/$Subset" --tl +} + +function Build-Tools { + <# + .SYNOPSIS + Builds all tools in a given list, in order of specification. + + .NOTES + This function will optionally only rebuild tools that haven't been built yet. This can + speed up development iteration, but may cause side-effects. + + .PARAMETER Tools + The table of tools to build. This may be any basic collection or a composite. + + .PARAMETER BuildMissing + If this switch is set, this function will only build tools that aren't present in the + tool directory. + #> + + param ( + [Parameter(Position = 0, Mandatory = $true)] + [string[]]$Tools, + + [switch]$BuildMissing = $false + ) + + foreach ($Key in $Tools) { + if ($BuildMissing -and (Test-ToolBuilt -Name $Key)) { + continue + } + + if ($Generators.Contains($Key)) { + Build-Tool -Type Generator -CSProjectName $GeneratorTable[$Key] -OutputName $Key + } + elseif ($Analyzers.Contains($Key)) { + Build-Tool -Type Analyzer -CSProjectName $AnalyzerTable[$Key] -OutputName $Key + } + else { + Write-Error "The tool $Key could not be found." + continue + } + } +} + +function Test-Tools { + <# + .SYNOPSIS + Tests all tools in a given list, in order of specification. + + .NOTES + This function relies on Test-Tool to do the heavy lifting, and therefore exhibits all of + its behavioural side effects. + + .PARAMETER Tools + The table of tools to test. This may be any basic collection or a composite. + #> + + param ( + [Parameter(Position = 0, Mandatory = $true)] + [string[]]$Tools + ) + + process { + [int]$Passed = 0 + [int]$Failed = 0 + [int]$Skipped = 0 + [int]$Count = $Tools.Count + + foreach ($Key in $Tools) { + [bool]$Result = $false + + # runs the tool and keeps track of the result, so we can later print it + if ($Generators.Contains($Key)) { + $Result = Test-Tool -Type Generator -CSProjectName $GeneratorTable[$Key] -OutputName $Key + } + elseif ($Analyzers.Contains($Key)) { + $Result = Test-Tool -Type Analyzer -CSProjectName $AnalyzerTable[$Key] -OutputName $Key + } + else { + Write-Error "The tool $Key could not be found." + $Skipped++ + continue + } + + if ($Result) { + $Passed++ + } + else { + $Failed++ + } + } + } + + end { + Write-Host "-------------------------------------------------------------------------" + Write-Host "" + Write-Host "Tool Test Results for $Count tests:" + Write-Host "$Passed passed" -ForegroundColor Green + Write-Host "$Failed failed" -ForegroundColor Red + Write-Host "$Skipped skipped" -ForegroundColor Yellow + Write-Host "" + Write-Host "-------------------------------------------------------------------------" + } +} + +function Invoke-Tools { + <# + .SYNOPSIS + Invokes all tools in a given list, in order of specification. + + .NOTES + This function is incapable of passing additional arguments to tools. If you need to + invoke a tool with additional arguments, you must invoke it directly via Invoke-Tool. + + Because of its reliance on Invoke-Tool, it will similarly build all tools not built yet. + + .PARAMETER Tools + The table of tools to execute. This may be any basic collection or a composite. + #> + + param ( + [Parameter(Position = 0, Mandatory = $true)] + [string[]]$Tools + ) + + foreach($Key in $Tools) { + Invoke-Tool -ToolName $Key + } +} + +function Invoke-Tool { + <# + .SYNOPSIS + Runs the specified tool, building if it not yet built. + + .PARAMETER ToolName + The common name of this tool. + + .PARAMETER Arguments + Additional CLI arguments to be passed to the tool, if applicable. + + .INPUTS + This function accepts the tool name from the pipeline. + #> + + param ( + [Parameter(Position = 0, ValueFromPipeline = $true, Mandatory = $true)] + [string]$ToolName, + + [Parameter(Position = 1, ValueFromRemainingArguments = $true)] + [string]$Arguments + ) + + if (!(Test-ToolBuilt -Name $ToolName)) { + if ($Generators.Contains($ToolName)) { + Write-Verbose "The generator $ToolName was not built, attempting to build..." + Build-Tool -Type Generator -CSProjectName $GeneratorTable[$ToolName] -OutputName $ToolName + } + elseif ($Analyzers.Contains($ToolName)) { + Write-Verbose "The analyzer $ToolName was not built, attempting to build..." + Build-Tool -Type Analyzer -CSProjectName $AnalyzerTable[$ToolName] -OutputName $ToolName + } + else { + Write-Error "The specified tool does not exist." + exit + } + } + + Invoke-Expression "$PSScriptRoot/tools/bin/$ToolName $Arguments" +} + +function Test-Tool { + <# + .SYNOPSIS + Runs the specified test project for a given tool + + .NOTES + Since tools may choose to take input from the main codebase, but we do not want to operate on + the main codebase, we allow their test projects to simulate a test environment in the testing + folder. This call may have unexpected side-effects, and each tool should specify side-effects + and assumptions by itself. + + Test project names are assumed to be `ToolName.Tests`, for a given tool `ToolName`. + + Because of powershell limitations, all tests must contain a class `Test.Entrypoint` with the + following static parameterless methods: + - bool Prepare + - bool Execute + + It utilizes /tools/.testenv to run the tests; and /tools/.testenvhost to hold the test + assemblies. /tools/.testenv is cleared after every run. + + .PARAMETER Type + The type of the tool to test. + + .PARAMETER CSProjectName + The name of the C# project holding the source code for this tool. + + .PARAMETER OutputName + The 'common' name of this tool; and the name by which it is passed to the test. + + .INPUTS + This tool accepts the C# project name from the pipeline. + #> + + [OutputType(bool)] + param ( + [Parameter(Position = 0, Mandatory = $true)] + [ToolType]$Type, + + [Parameter(Position = 1, ValueFromPipeline = $true, Mandatory = $true)] + [string]$CSProjectName, + + [Parameter(Position = 2, Mandatory = $true)] + [string]$OutputName + ) + + begin { + # set up the testing environment and prepare the environment + if (!(Test-Path -Path "$PSScriptRoot/tools/.testenv")) { + New-Item -ItemType Directory -Path "$PSScriptRoot/tools/.testenv" + } + else { + Remove-Item -Path "$PSScriptRoot/tools/.testenv/*" -Force -Recurse + + Write-Verbose "Cleared the testenv folder of leftover files." + } + + dotnet build "$PSScriptRoot/tools/tests/$CSProjectName.Tests/$CSProjectName.Tests.csproj" -p:PublishAot=false + + Copy-Item -Path "$PSScriptRoot/tools/artifacts/bin/$CSProjectName.Tests/debug/$CSProjectName.Tests.dll" ` + -Destination "$PSScriptRoot/tools/.testenvhost/" + + Add-Type -Path "$PSScriptRoot/tools/.testenvhost/$CSProjectName.Tests.dll" + + [System.Environment]::CurrentDirectory = "$PSScriptRoot/tools/.testenv/" + + Write-Verbose "Prepared the testing environment; ready to build and test tooling." + + $env:DATA_DIRECTORY = "$PSScriptRoot/tools/.testenv/data" + $env:SRC_DIRECTORY = "$PSScriptRoot/tools/.testenv/src" + $env:OUT_DIRECTORY = "$PSScriptRoot/tools/.testenv/out" + + # this should be the last statement in begin, we don't want to ignore prelude errors + $ErrorActionPreference = 'Continue' + } + + process { + if (!([Test.Entrypoint]::Prepare())) { + Write-Verbose "Preparation failed, the test $CSProjectName.Tests will not be executed." + + return $false + } + + Build-Tool -Type $Type -CSProjectName $CSProjectName -OutputName $OutputName + + if ($IsWindows) { + Copy-Item -Path "$PSScriptRoot/tools/bin/$OutputName.exe" -Destination "$PSScriptRoot/tools/.testenv/$OutputName.exe" + } + else { + Copy-Item -Path "$PSScriptRoot/tools/bin/$OutputName" -Destination "$PSScriptRoot/tools/.testenv/$OutputName" + } + + if (!([Test.Entrypoint]::Execute())) { + Write-Verbose "The test $CSProjectName failed." + + return $false + } + + Write-Verbose "The test $CSProjectName passed." + } + + end { + # this should be the first statement in end, we don't want to ignore cleanup errors + $ErrorActionPreference = 'Stop' + + [System.Environment]::CurrentDirectory = "$PSScriptRoot" + + Remove-Item -Path "$PSScriptRoot/tools/.testenv/*" -Force -Recurse + + Write-Verbose "Cleaned up the testing environment." + + return $true + } +} + +function Build-Tool { + <# + .SYNOPSIS + Builds a certain tool and prepares it for use, either manually or by the script. + + .PARAMETER Type + Specifies the type of this tool. + + .PARAMETER CSProjectName + The name of the C# project holding the source code for this tool. + + .PARAMETER OutputName + The 'common' name of this tool, by which it is to be referred to in further use. + + .INPUTS + This function accepts the C# project name from the pipeline. + + .NOTES + This function will automatically create potentially missing directories. + #> + + param ( + [Parameter(Position = 0, Mandatory = $true)] + [ToolType]$Type, + + [Parameter(Position = 1, ValueFromPipeline = $true, Mandatory = $true)] + [string]$CSProjectName, + + [Parameter(Position = 2, Mandatory = $true)] + [string]$OutputName + ) + + process { + if (!(Test-Path -Path "$PSScriptRoot/tools/bin")) { + New-Item -ItemType Directory -Path "$PSScriptRoot/tools/bin" + } + + switch ($Type) { + Generator { + # --ucr == use current runtime; that is, build natively for this system + dotnet publish "$PSScriptRoot/tools/generators/$CSProjectName/$CSProjectName.csproj" --ucr --tl + } + Analyzer { + dotnet publish "$PSScriptRoot/tools/analyzers/$CSProjectName/$CSProjectName.csproj" --ucr --tl + } + } + + if($IsWindows) { + Copy-Item -Path "$PSScriptRoot/tools/artifacts/publish/$CSProjectName/release/$CSProjectName.exe" ` + -Destination "$PSScriptRoot/tools/bin/$OutputName.exe" + } + else { + Copy-Item -Path "$PSScriptRoot/tools/artifacts/publish/$CSProjectName/release/$CSProjectName" ` + -Destination "$PSScriptRoot/tools/bin/$OutputName" + } + } + + end { + Write-Debug "The tool $OutputName was successfully built from $CSProjectName." + Write-Verbose "Successfully built tool $OutputName." + } +} + + +function Test-ToolBuilt { + <# + .SYNOPSIS + Tests whether a certain tool has been built and is ready to run. + + .PARAMETER Name + The 'common' name of this tool, and simultaneously its file name in /tools/bin. + + .INPUTS + This function accepts the tool name from the pipeline. + + .OUTPUTS + A boolean indicating whether the tool has been built or not. + #> + + [OutputType([bool])] + param ( + [Parameter(Position = 0, ValueFromPipeline = $true, Mandatory = $true)] + [string]$Name + ) + + process { + return Test-Path -Path "$PSScriptRoot/tools/bin/$Name" + } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.sln b/src/core/DSharpPlus.Core.sln new file mode 100644 index 0000000000..bf81137b8a --- /dev/null +++ b/src/core/DSharpPlus.Core.sln @@ -0,0 +1,45 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.0.31903.59 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DSharpPlus.Core.Abstractions.Models", "DSharpPlus.Core.Abstractions.Models\DSharpPlus.Core.Abstractions.Models.csproj", "{AF8283F9-AC6C-46AB-A4FC-D331C64BFFC9}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DSharpPlus.Core.Models", "DSharpPlus.Core.Models\DSharpPlus.Core.Models.csproj", "{9699C432-CC00-48D3-8534-D949C77C6B87}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DSharpPlus.Shared", "DSharpPlus.Shared\DSharpPlus.Shared.csproj", "{E9B2D26F-5E11-4198-8E00-A7780572C480}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tools", "Tools", "{FB4D812B-0FD8-4335-BF0A-CFBA8C856E04}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tools.Generators.GenerateConcreteObjects", "..\..\tools\generators\Tools.Generators.GenerateConcreteObjects\Tools.Generators.GenerateConcreteObjects.csproj", "{F214E901-6928-4488-9F65-E684AD12F0CE}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {AF8283F9-AC6C-46AB-A4FC-D331C64BFFC9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {AF8283F9-AC6C-46AB-A4FC-D331C64BFFC9}.Debug|Any CPU.Build.0 = Debug|Any CPU + {AF8283F9-AC6C-46AB-A4FC-D331C64BFFC9}.Release|Any CPU.ActiveCfg = Release|Any CPU + {AF8283F9-AC6C-46AB-A4FC-D331C64BFFC9}.Release|Any CPU.Build.0 = Release|Any CPU + {9699C432-CC00-48D3-8534-D949C77C6B87}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9699C432-CC00-48D3-8534-D949C77C6B87}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9699C432-CC00-48D3-8534-D949C77C6B87}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9699C432-CC00-48D3-8534-D949C77C6B87}.Release|Any CPU.Build.0 = Release|Any CPU + {E9B2D26F-5E11-4198-8E00-A7780572C480}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E9B2D26F-5E11-4198-8E00-A7780572C480}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E9B2D26F-5E11-4198-8E00-A7780572C480}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E9B2D26F-5E11-4198-8E00-A7780572C480}.Release|Any CPU.Build.0 = Release|Any CPU + {F214E901-6928-4488-9F65-E684AD12F0CE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F214E901-6928-4488-9F65-E684AD12F0CE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F214E901-6928-4488-9F65-E684AD12F0CE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F214E901-6928-4488-9F65-E684AD12F0CE}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {F214E901-6928-4488-9F65-E684AD12F0CE} = {FB4D812B-0FD8-4335-BF0A-CFBA8C856E04} + EndGlobalSection +EndGlobal diff --git a/tools/Directory.Build.props b/tools/Directory.Build.props new file mode 100644 index 0000000000..1c19ad1e12 --- /dev/null +++ b/tools/Directory.Build.props @@ -0,0 +1,18 @@ + + + + + net8.0 + enable + preview + True + $(NoWarn);CS1591 + + + True + true + true + true + + + \ No newline at end of file diff --git a/tools/generators/Tools.Generators.GenerateConcreteObjects/Program.cs b/tools/generators/Tools.Generators.GenerateConcreteObjects/Program.cs new file mode 100644 index 0000000000..ba00a72c4b --- /dev/null +++ b/tools/generators/Tools.Generators.GenerateConcreteObjects/Program.cs @@ -0,0 +1,5 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +System.Console.WriteLine("Hello, World!"); diff --git a/tools/generators/Tools.Generators.GenerateConcreteObjects/Tools.Generators.GenerateConcreteObjects.csproj b/tools/generators/Tools.Generators.GenerateConcreteObjects/Tools.Generators.GenerateConcreteObjects.csproj new file mode 100644 index 0000000000..6a70a1ab38 --- /dev/null +++ b/tools/generators/Tools.Generators.GenerateConcreteObjects/Tools.Generators.GenerateConcreteObjects.csproj @@ -0,0 +1,7 @@ + + + + Exe + + + From 7204fdda82fa6484f1c256cb5ec5b874549d77df Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Thu, 6 Jul 2023 11:50:17 +0200 Subject: [PATCH 051/323] fix the powershell scripts --- dsharpplus.ps1 | 1 + script-functions.ps1 | 12 ++++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/dsharpplus.ps1 b/dsharpplus.ps1 index f81036c757..7162ed01f6 100644 --- a/dsharpplus.ps1 +++ b/dsharpplus.ps1 @@ -123,6 +123,7 @@ else { if ($Action -eq "publish") { foreach($Target in $SubsetsToExecute) { + Write-Host "Publishing library subset '$Target'" Publish-Subset $Target } diff --git a/script-functions.ps1 b/script-functions.ps1 index 01405ce8a5..f24bec6fa2 100644 --- a/script-functions.ps1 +++ b/script-functions.ps1 @@ -293,8 +293,8 @@ function Test-Tool { Test project names are assumed to be `ToolName.Tests`, for a given tool `ToolName`. - Because of powershell limitations, all tests must contain a class `Test.Entrypoint` with the - following static parameterless methods: + Because of powershell limitations, all tests must contain a class `ToolName.Tests.Main` with + the following static parameterless methods: - bool Prepare - bool Execute @@ -357,7 +357,9 @@ function Test-Tool { } process { - if (!([Test.Entrypoint]::Prepare())) { + [bool]$Success = Invoke-Expression "[$CSProjectName.Tests.Main]::Prepare()" + + if (!($Success)) { Write-Verbose "Preparation failed, the test $CSProjectName.Tests will not be executed." return $false @@ -372,7 +374,9 @@ function Test-Tool { Copy-Item -Path "$PSScriptRoot/tools/bin/$OutputName" -Destination "$PSScriptRoot/tools/.testenv/$OutputName" } - if (!([Test.Entrypoint]::Execute())) { + [bool]$Success = Invoke-Expression "[$CSProjectName.Tests.Main]::Execute()" + + if (!($Success)) { Write-Verbose "The test $CSProjectName failed." return $false From 8eb2472303afbd964770e6ceb8767a393e1fa45c Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Thu, 13 Jul 2023 19:22:36 +0200 Subject: [PATCH 052/323] initial DictionarySlim port from dotnet/corefxlab --- .../Collections/DictionarySlim.cs | 506 ++++++++++++++++++ .../Collections/DictionarySlimDebugView.cs | 45 ++ .../Collections/ThrowHelper.cs | 27 + .../DSharpPlus.Shared.csproj | 10 +- 4 files changed, 586 insertions(+), 2 deletions(-) create mode 100644 src/core/DSharpPlus.Shared/Collections/DictionarySlim.cs create mode 100644 src/core/DSharpPlus.Shared/Collections/DictionarySlimDebugView.cs create mode 100644 src/core/DSharpPlus.Shared/Collections/ThrowHelper.cs diff --git a/src/core/DSharpPlus.Shared/Collections/DictionarySlim.cs b/src/core/DSharpPlus.Shared/Collections/DictionarySlim.cs new file mode 100644 index 0000000000..4a9a11a42b --- /dev/null +++ b/src/core/DSharpPlus.Shared/Collections/DictionarySlim.cs @@ -0,0 +1,506 @@ +#pragma warning disable IDE0073 // don't insert our license header here + +// This source file is loosely adapted after the following dotnet/corefxlab file, and is therefore licensed +// under the MIT License: +// https://github.com/dotnet/corefxlab/blob/archive/src/Microsoft.Experimental.Collections/Microsoft/Collections/Extensions/DictionarySlim.cs +// +// Copyright (c) .NET Foundation and Contributors +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +using System; +using System.Collections; +using System.Collections.Generic; +using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; +using System.Runtime.CompilerServices; + +namespace DSharpPlus.Collections; + +/// +/// A lightweight dictionary with three principal differences compared to . +///

+/// 1. It is possible to get or add in a single lookup. For values that are value types, this also +/// saves a copy of the value.
+/// 2. It assumes it is cheap to equate values.
+/// 3. It assumes the keys implement and that they are cheap and sufficient. +///
+/// +/// This avoids having to do separate lookups for get-or-add scenarios; it can save space by not +/// storing hash codes, save time by skipping potentially expensive hash code calculations for certain types +/// of common keys, as well as avoid storing a comparer and avoid the - likely virtual - call to a comparer. +/// Additionally, this class is a sealed class, making it trivial to devirtualize calls to it. +/// +[DebuggerDisplay("Count = {Count}")] +[DebuggerTypeProxy(typeof(DictionarySlimDebugView<,>))] +#if !NETSTANDARD +[SkipLocalsInit] +#endif +public sealed class DictionarySlim : IReadOnlyCollection> + where TKey : IEquatable +{ + // using this static initialization allows us to initialize further dictionaries without + // any initial allocations. instead, we allocate once per monomorphized generic instantiation, + // plus one time for the canonicalized reference type generic instantiation + // DSharpPlus.Collections.DictionarySlim. + // The first addition will cause a resize, replacing this with a real array. + private static readonly DictionaryEntry[] initialEntries = new DictionaryEntry[1]; + + private static readonly int[] sizeOneIntArray = new int[1]; + + // zero-based index into entries towards the head of the free chain, -1 means empty + private int freeList = -1; + + // one-based index into entries, 0 means empty. + private int[] buckets; + private DictionaryEntry[] entries; + + /// + public int Count { get; private set; } + + /// + /// Represents an entry to this dictionary, replacing KeyValuePairs. + /// + [DebuggerDisplay("({key}, {value})->{next}")] + private struct DictionaryEntry + { + public TKey key; + public TValue value; + + // zero-based index of the next entry in this chain; -1 signifies the end of the chain. + // this also encodes whether this entry is part of the free list by changing the sign and + // subtracting 3; so, -2 means the end of the free list, -3 means index 0 on the free list, + // -4 means index 1 on the free list et cetera + public int next; + } + + /// + /// Constructs a new slim dictionary with default capacity. + /// + public DictionarySlim() + { + this.buckets = sizeOneIntArray; + this.entries = initialEntries; + } + + /// + /// Constructs a new dictionary with at least the specified capacity for entries. + /// + /// + /// This constructor will round the capacity up to the nearest power of two. + /// + /// + /// Thrown if capacity was less than 0. + /// + public DictionarySlim + ( + int capacity + ) + { + if (capacity < 0) + { + throw new ArgumentOutOfRangeException + ( + nameof(capacity), + "The initial capacity for this dictionary was too small." + ); + } + + // ensure a capacity of at least two; because 1 would mean the dummy array. + if (capacity < 2) + { + capacity = 2; + } + + // round up to the nearest power of two + int roundedCapacity = 2; + + while (roundedCapacity < capacity) + { + roundedCapacity <<= 1; + } + + this.buckets = new int[roundedCapacity]; + this.entries = new DictionaryEntry[roundedCapacity]; + } + + /// + /// Clears this dictionary, invalidating any active references and enumerators. + /// + public void Clear() + { + this.Count = 0; + this.freeList = -1; + this.buckets = sizeOneIntArray; + this.entries = initialEntries; + } + + /// + /// Looks for the specified key in the dictionary, returning whether it exists. + /// + public bool ContainsKey + ( + TKey key + ) + { +#if !NETSTANDARD + ArgumentNullException.ThrowIfNull(key); +#else + if (key is null) + { + throw new ArgumentNullException("The supplied key was null."); + } +#endif + DictionaryEntry[] entries = this.entries; + int collisions = 0; + + for + ( + int i = buckets[key.GetHashCode() & (buckets.Length - 1)] - 1; + (uint)i < (uint)entries.Length; + i = entries[i].next + ) + { + if (key.Equals(entries[i].key)) + { + return true; + } + + if(collisions == entries.Length) + { + ThrowHelper.ThrowConcurrentOperationsNotSupported(); + } + + collisions++; + } + + return false; + } + + /// + /// Gets the value if one is present for the given key. + /// + /// The key to look for. + /// The value if one was found, otherwise default(TValue). + /// Whether the key was found. + public bool TryGetValue + ( + TKey key, + + [MaybeNullWhen(false)] + out TValue value + ) + { +#if !NETSTANDARD + ArgumentNullException.ThrowIfNull(key); +#else + if (key is null) + { + throw new ArgumentNullException("The supplied key was null."); + } +#endif + + DictionaryEntry[] entries = this.entries; + int collisions = 0; + + for + ( + int i = buckets[key.GetHashCode() & (buckets.Length - 1)] - 1; + (uint)i < (uint)entries.Length; + i = entries[i].next + ) + { + if (key.Equals(entries[i].key)) + { + value = entries[i].value; + return true; + } + + if (collisions == entries.Length) + { + ThrowHelper.ThrowConcurrentOperationsNotSupported(); + } + + collisions++; + } + + value = default; + return false; + } + + /// + /// Removes the entry with the specified key, if one was present. + /// + /// true if the key was present and an entry was removed. + public bool Remove + ( + TKey key + ) + { +#if !NETSTANDARD + ArgumentNullException.ThrowIfNull(key); +#else + if (key is null) + { + throw new ArgumentNullException("The supplied key was null."); + } +#endif + + DictionaryEntry[] entries = this.entries; + int bucketIndex = key.GetHashCode() & (buckets.Length - 1); + int entryIndex = buckets[bucketIndex] - 1; + + int lastIndex = -1; + int collisions = 0; + + while (entryIndex != -1) + { + DictionaryEntry candidate = entries[entryIndex]; + if (candidate.key.Equals(key)) + { + if (lastIndex != -1) + { + // fix the preceding element in the chain to point to the correct next element, if any + entries[lastIndex].next = candidate.next; + } + else + { + // fix the bucket to the new head, if any + buckets[bucketIndex] = candidate.next + 1; + } + + entries[entryIndex] = default; + + // this is the new head of the free list + entries[entryIndex].next = -3 - freeList; + freeList = entryIndex; + + Count--; + return true; + } + + lastIndex = entryIndex; + entryIndex = candidate.next; + + if (collisions == entries.Length) + { + // The chain of entries forms a loop; which means a concurrent update has happened. + // Break out of the loop and throw, rather than looping forever. + ThrowHelper.ThrowConcurrentOperationsNotSupported(); + } + + collisions++; + } + + return false; + } + + // Not safe for concurrent _reads_ (at least, if either of them add) + // For concurrent reads, prefer TryGetValue(key, out value) + /// + /// Gets the value for the specified key, or, if the key is not present, + /// adds an entry and returns the value by ref. This makes it possible to + /// add or update a value in a single look up operation. + /// + /// The key to look for. + /// A reference to the new or existing value. + public ref TValue GetOrAddValueRef(TKey key) + { +#if !NETSTANDARD + ArgumentNullException.ThrowIfNull(key); +#else + if (key is null) + { + throw new ArgumentNullException("The supplied key was null."); + } +#endif + + DictionaryEntry[] entries = this.entries; + + int collisions = 0; + int bucketIndex = key.GetHashCode() & (this.buckets.Length - 1); + + for + ( + int i = this.buckets[bucketIndex] - 1; + (uint)i < (uint)entries.Length; + i = entries[i].next + ) + { + if (key.Equals(entries[i].key)) + { + return ref entries[i].value; + } + + if (collisions == entries.Length) + { + // The chain of entries forms a loop; which means a concurrent update has happened. + // Break out of the loop and throw, rather than looping forever. + ThrowHelper.ThrowConcurrentOperationsNotSupported(); + } + + collisions++; + } + + return ref AddKey(key, bucketIndex); + } + + [MethodImpl(MethodImplOptions.NoInlining)] + private ref TValue AddKey(TKey key, int bucketIndex) + { + DictionaryEntry[] entries = this.entries; + + int entryIndex; + + if (this.freeList != -1) + { + entryIndex = this.freeList; + this.freeList = -3 - entries[this.freeList].next; + } + else + { + if (this.Count == entries.Length || entries.Length == 1) + { + entries = this.Resize(); + bucketIndex = key.GetHashCode() & (this.buckets.Length - 1); + // entry indexes were not changed by Resize + } + + entryIndex = this.Count; + } + + entries[entryIndex].key = key; + entries[entryIndex].next = this.buckets[bucketIndex] - 1; + this.buckets[bucketIndex] = entryIndex + 1; + + this.Count++; + + return ref entries[entryIndex].value; + } + + private DictionaryEntry[] Resize() + { + // We only copy _count, so if it's longer we will miss some + // the comparison with 1 is made to catch the initial array + Debug.Assert(this.entries.Length == this.Count || this.entries.Length == 1); + + int count = this.Count; + + // for net8.0 targets we could consider implementing this for different resize strategies + // a linearly increasing slim dictionary would be useful. + int newSize = this.entries.Length * 2; + + if ((uint)newSize > int.MaxValue) + { + ThrowHelper.ThrowCapacityIntMaxValueExceeded(); + } + + DictionaryEntry[] entries = new DictionaryEntry[newSize]; + Array.Copy(this.entries, 0, entries, 0, count); + + int[] newBuckets = new int[entries.Length]; + + while (count-- > 0) + { + int bucketIndex = entries[count].key.GetHashCode() & (newBuckets.Length - 1); + entries[count].next = newBuckets[bucketIndex] - 1; + newBuckets[bucketIndex] = count + 1; + } + + this.buckets = newBuckets; + this.entries = entries; + + return entries; + } + + IEnumerator> IEnumerable>.GetEnumerator() + => new Enumerator(this); + + IEnumerator IEnumerable.GetEnumerator() + => new Enumerator(this); + + // avoid boxing enumerators if not necessary + public Enumerator GetEnumerator() => new(this); + + /// + /// The enumerator struct for this dictionary type. + /// + public struct Enumerator : IEnumerator> + { + private readonly DictionarySlim dictionary; + private int index; + private int count; + private KeyValuePair current; + + internal Enumerator + ( + DictionarySlim dictionary + ) + { + this.dictionary = dictionary; + this.index = 0; + this.count = dictionary.Count; + this.current = default; + } + + /// + public bool MoveNext() + { + if (this.count == 0) + { + this.current = default; + return false; + } + + this.count--; + + while (this.dictionary.entries[this.index].next < -1) + { + this.index++; + } + + this.current = new KeyValuePair + ( + this.dictionary.entries[this.index].key, + this.dictionary.entries[this.index++].value + ); + + return true; + } + + /// + /// Get current value + /// + public readonly KeyValuePair Current => this.current; + + readonly object IEnumerator.Current => this.current; + + void IEnumerator.Reset() + { + this.index = 0; + this.count = this.dictionary.Count; + this.current = default; + } + + /// + /// Dispose the enumerator + /// + public readonly void Dispose() { } + } +} diff --git a/src/core/DSharpPlus.Shared/Collections/DictionarySlimDebugView.cs b/src/core/DSharpPlus.Shared/Collections/DictionarySlimDebugView.cs new file mode 100644 index 0000000000..b23bc1ac84 --- /dev/null +++ b/src/core/DSharpPlus.Shared/Collections/DictionarySlimDebugView.cs @@ -0,0 +1,45 @@ +#pragma warning disable IDE0073 + +// This source file is loosely adapted after the following dotnet/corefxlab file, and is therefore licensed +// under the MIT License: +// https://github.com/dotnet/corefxlab/blob/archive/src/Microsoft.Experimental.Collections/Microsoft/Collections/Extensions/DictionarySlim.cs +// +// Copyright (c) .NET Foundation and Contributors +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +using System; +using System.Collections.Generic; +using System.Diagnostics; + +namespace DSharpPlus.Collections; + +/// +/// The debugger view for +/// +internal sealed class DictionarySlimDebugView +( + DictionarySlim dictionary +) + where K : IEquatable +{ + + [DebuggerBrowsable(DebuggerBrowsableState.RootHidden)] + public KeyValuePair[] Items => dictionary.ToArray(); +} diff --git a/src/core/DSharpPlus.Shared/Collections/ThrowHelper.cs b/src/core/DSharpPlus.Shared/Collections/ThrowHelper.cs new file mode 100644 index 0000000000..d71030ced4 --- /dev/null +++ b/src/core/DSharpPlus.Shared/Collections/ThrowHelper.cs @@ -0,0 +1,27 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; +using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; + +namespace DSharpPlus.Collections; + +/// +/// Contains utilities for throwing exceptions out of hot code paths. +/// +internal static class ThrowHelper +{ + [DoesNotReturn] + [DebuggerHidden] + [StackTraceHidden] + internal static void ThrowConcurrentOperationsNotSupported() + => throw new InvalidOperationException("Concurrent modifications to this collection type are not supported."); + + [DoesNotReturn] + [DebuggerHidden] + [StackTraceHidden] + internal static void ThrowCapacityIntMaxValueExceeded() + => throw new InvalidOperationException($"This type's maximum capacity of {int.MaxValue} was exceeded."); +} diff --git a/src/core/DSharpPlus.Shared/DSharpPlus.Shared.csproj b/src/core/DSharpPlus.Shared/DSharpPlus.Shared.csproj index d03a9bf085..89596a6429 100644 --- a/src/core/DSharpPlus.Shared/DSharpPlus.Shared.csproj +++ b/src/core/DSharpPlus.Shared/DSharpPlus.Shared.csproj @@ -4,18 +4,24 @@ true $(Description) This package contains shared types between public-facing and internal implementation packages. Library + true DSharpPlus +
+ + netstandard2.0;$(TargetFramework) - false + false - + + +
From 9d80a4d4bf3d9809fc5ed0db91526fea2f7dab09 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Thu, 13 Jul 2023 19:28:31 +0200 Subject: [PATCH 053/323] add value accessor --- .../Collections/DictionarySlim.cs | 43 +++++++++++++++++++ .../Collections/ThrowHelper.cs | 6 +++ 2 files changed, 49 insertions(+) diff --git a/src/core/DSharpPlus.Shared/Collections/DictionarySlim.cs b/src/core/DSharpPlus.Shared/Collections/DictionarySlim.cs index 4a9a11a42b..05ad60259a 100644 --- a/src/core/DSharpPlus.Shared/Collections/DictionarySlim.cs +++ b/src/core/DSharpPlus.Shared/Collections/DictionarySlim.cs @@ -244,6 +244,49 @@ out TValue value return false; } + public ref TValue this[TKey key] + { + get + { +#if !NETSTANDARD + ArgumentNullException.ThrowIfNull(key); +#else + if (key is null) + { + throw new ArgumentNullException("The supplied key was null."); + } +#endif + + DictionaryEntry[] entries = this.entries; + int collisions = 0; + + for + ( + int i = buckets[key.GetHashCode() & (buckets.Length - 1)] - 1; + (uint)i < (uint)entries.Length; + i = entries[i].next + ) + { + if (key.Equals(entries[i].key)) + { + return ref entries[i].value; + } + + if (collisions == entries.Length) + { + ThrowHelper.ThrowConcurrentOperationsNotSupported(); + } + + collisions++; + } + + ThrowHelper.ThrowValueNotFound(); + + // this is unreachable, but roslyn disagrees; so we need to have a dummy return + return ref Unsafe.NullRef(); + } + } + /// /// Removes the entry with the specified key, if one was present. /// diff --git a/src/core/DSharpPlus.Shared/Collections/ThrowHelper.cs b/src/core/DSharpPlus.Shared/Collections/ThrowHelper.cs index d71030ced4..6ba79c5d45 100644 --- a/src/core/DSharpPlus.Shared/Collections/ThrowHelper.cs +++ b/src/core/DSharpPlus.Shared/Collections/ThrowHelper.cs @@ -24,4 +24,10 @@ internal static void ThrowConcurrentOperationsNotSupported() [StackTraceHidden] internal static void ThrowCapacityIntMaxValueExceeded() => throw new InvalidOperationException($"This type's maximum capacity of {int.MaxValue} was exceeded."); + + [DoesNotReturn] + [DebuggerHidden] + [StackTraceHidden] + internal static void ThrowValueNotFound() + => throw new ArgumentException("There was no value corresponding to the given key."); } From b1dbc3558271eeeb7a07bcbacfad74bd0be6ea09 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Thu, 13 Jul 2023 19:29:01 +0200 Subject: [PATCH 054/323] add a core solution for the build tool --- src/core/DSharpPlus.Core.sln | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/src/core/DSharpPlus.Core.sln b/src/core/DSharpPlus.Core.sln index bf81137b8a..de1ce25ce1 100644 --- a/src/core/DSharpPlus.Core.sln +++ b/src/core/DSharpPlus.Core.sln @@ -9,10 +9,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DSharpPlus.Core.Models", "D EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DSharpPlus.Shared", "DSharpPlus.Shared\DSharpPlus.Shared.csproj", "{E9B2D26F-5E11-4198-8E00-A7780572C480}" EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tools", "Tools", "{FB4D812B-0FD8-4335-BF0A-CFBA8C856E04}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tools.Generators.GenerateConcreteObjects", "..\..\tools\generators\Tools.Generators.GenerateConcreteObjects\Tools.Generators.GenerateConcreteObjects.csproj", "{F214E901-6928-4488-9F65-E684AD12F0CE}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -31,15 +27,8 @@ Global {E9B2D26F-5E11-4198-8E00-A7780572C480}.Debug|Any CPU.Build.0 = Debug|Any CPU {E9B2D26F-5E11-4198-8E00-A7780572C480}.Release|Any CPU.ActiveCfg = Release|Any CPU {E9B2D26F-5E11-4198-8E00-A7780572C480}.Release|Any CPU.Build.0 = Release|Any CPU - {F214E901-6928-4488-9F65-E684AD12F0CE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {F214E901-6928-4488-9F65-E684AD12F0CE}.Debug|Any CPU.Build.0 = Debug|Any CPU - {F214E901-6928-4488-9F65-E684AD12F0CE}.Release|Any CPU.ActiveCfg = Release|Any CPU - {F214E901-6928-4488-9F65-E684AD12F0CE}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection - GlobalSection(NestedProjects) = preSolution - {F214E901-6928-4488-9F65-E684AD12F0CE} = {FB4D812B-0FD8-4335-BF0A-CFBA8C856E04} - EndGlobalSection EndGlobal From 0025bf3f90e6488256c901b8645e6ccdaaf27eb1 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Thu, 13 Jul 2023 23:26:46 +0200 Subject: [PATCH 055/323] fix the netstandard2.0 build --- .../Collections/DictionarySlim.cs | 22 ++++++++++++++----- .../Collections/ThrowHelper.cs | 14 +++++++++--- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/src/core/DSharpPlus.Shared/Collections/DictionarySlim.cs b/src/core/DSharpPlus.Shared/Collections/DictionarySlim.cs index 05ad60259a..2434c4ebdf 100644 --- a/src/core/DSharpPlus.Shared/Collections/DictionarySlim.cs +++ b/src/core/DSharpPlus.Shared/Collections/DictionarySlim.cs @@ -28,7 +28,9 @@ using System.Collections; using System.Collections.Generic; using System.Diagnostics; +#if !NETSTANDARD using System.Diagnostics.CodeAnalysis; +#endif using System.Runtime.CompilerServices; namespace DSharpPlus.Collections; @@ -203,7 +205,9 @@ public bool TryGetValue ( TKey key, +#if !NETSTANDARD [MaybeNullWhen(false)] +#endif out TValue value ) { @@ -240,7 +244,7 @@ out TValue value collisions++; } - value = default; + value = default!; return false; } @@ -251,10 +255,10 @@ public ref TValue this[TKey key] #if !NETSTANDARD ArgumentNullException.ThrowIfNull(key); #else - if (key is null) - { - throw new ArgumentNullException("The supplied key was null."); - } + if (key is null) + { + throw new ArgumentNullException("The supplied key was null."); + } #endif DictionaryEntry[] entries = this.entries; @@ -283,7 +287,13 @@ public ref TValue this[TKey key] ThrowHelper.ThrowValueNotFound(); // this is unreachable, but roslyn disagrees; so we need to have a dummy return - return ref Unsafe.NullRef(); + // thanks to netstandard being netstandard, this can't become Unsafe.NullRef(); + unsafe + { +#pragma warning disable CS8500 + return ref *(TValue*)null; +#pragma warning restore CS8500 + } } } diff --git a/src/core/DSharpPlus.Shared/Collections/ThrowHelper.cs b/src/core/DSharpPlus.Shared/Collections/ThrowHelper.cs index 6ba79c5d45..e496b6d076 100644 --- a/src/core/DSharpPlus.Shared/Collections/ThrowHelper.cs +++ b/src/core/DSharpPlus.Shared/Collections/ThrowHelper.cs @@ -4,7 +4,9 @@ using System; using System.Diagnostics; +#if !NETSTANDARD using System.Diagnostics.CodeAnalysis; +#endif namespace DSharpPlus.Collections; @@ -13,21 +15,27 @@ namespace DSharpPlus.Collections; ///
internal static class ThrowHelper { - [DoesNotReturn] [DebuggerHidden] +#if !NETSTANDARD + [DoesNotReturn] [StackTraceHidden] +#endif internal static void ThrowConcurrentOperationsNotSupported() => throw new InvalidOperationException("Concurrent modifications to this collection type are not supported."); - [DoesNotReturn] [DebuggerHidden] +#if !NETSTANDARD + [DoesNotReturn] [StackTraceHidden] +#endif internal static void ThrowCapacityIntMaxValueExceeded() => throw new InvalidOperationException($"This type's maximum capacity of {int.MaxValue} was exceeded."); - [DoesNotReturn] [DebuggerHidden] +#if !NETSTANDARD + [DoesNotReturn] [StackTraceHidden] +#endif internal static void ThrowValueNotFound() => throw new ArgumentException("There was no value corresponding to the given key."); } From cce621dc8342ac8850b4f38537c57b5f37abd362 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Thu, 13 Jul 2023 23:26:58 +0200 Subject: [PATCH 056/323] add missing using --- .../DSharpPlus.Shared/Collections/DictionarySlimDebugView.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/core/DSharpPlus.Shared/Collections/DictionarySlimDebugView.cs b/src/core/DSharpPlus.Shared/Collections/DictionarySlimDebugView.cs index b23bc1ac84..47ddfe4656 100644 --- a/src/core/DSharpPlus.Shared/Collections/DictionarySlimDebugView.cs +++ b/src/core/DSharpPlus.Shared/Collections/DictionarySlimDebugView.cs @@ -27,6 +27,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; +using System.Linq; namespace DSharpPlus.Collections; @@ -39,7 +40,8 @@ DictionarySlim dictionary ) where K : IEquatable { - +#pragma warning disable CA1822 [DebuggerBrowsable(DebuggerBrowsableState.RootHidden)] public KeyValuePair[] Items => dictionary.ToArray(); +#pragma warning restore CA1822 } From 903236cbb4b5ea39877c6984bb6605f2f44b2ed8 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Thu, 13 Jul 2023 23:27:10 +0200 Subject: [PATCH 057/323] fix the msbuild fuckery for ns2.0 --- src/core/DSharpPlus.Shared/DSharpPlus.Shared.csproj | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/core/DSharpPlus.Shared/DSharpPlus.Shared.csproj b/src/core/DSharpPlus.Shared/DSharpPlus.Shared.csproj index 89596a6429..2a753b65e8 100644 --- a/src/core/DSharpPlus.Shared/DSharpPlus.Shared.csproj +++ b/src/core/DSharpPlus.Shared/DSharpPlus.Shared.csproj @@ -11,14 +11,17 @@ netstandard2.0;$(TargetFramework) + + + - + false - + From b6fe5a5c6b3122256df670035c18ca1b9760ddc7 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sun, 16 Jul 2023 02:03:47 +0200 Subject: [PATCH 058/323] add dictionaryslim json conversion the reflection part needs to be cached, aside from that, tested and works --- DSharpPlus.sln | 19 +++ Directory.Packages.props | 8 ++ .../Converters/DictionarySlimJsonConverter.cs | 109 ++++++++++++++++++ .../DictionarySlimJsonConverterFactory.cs | 73 ++++++++++++ ...DictionarySlimStringStringJsonConverter.cs | 75 ++++++++++++ .../DSharpPlus.Shared.csproj | 1 + .../Converters/DictionarySlimGeneric.cs | 92 +++++++++++++++ .../Converters/DictionarySlimStringString.cs | 60 ++++++++++ .../DSharpPlus.Shared.Tests.csproj | 30 +++++ .../Tools.IncrementalUtility.csproj | 16 +++ 10 files changed, 483 insertions(+) create mode 100644 src/core/DSharpPlus.Shared/Converters/DictionarySlimJsonConverter.cs create mode 100644 src/core/DSharpPlus.Shared/Converters/DictionarySlimJsonConverterFactory.cs create mode 100644 src/core/DSharpPlus.Shared/Converters/DictionarySlimStringStringJsonConverter.cs create mode 100644 tests/core/DSharpPlus.Shared.Tests/Converters/DictionarySlimGeneric.cs create mode 100644 tests/core/DSharpPlus.Shared.Tests/Converters/DictionarySlimStringString.cs create mode 100644 tests/core/DSharpPlus.Shared.Tests/DSharpPlus.Shared.Tests.csproj create mode 100644 tools/Tools.IncrementalUtility/Tools.IncrementalUtility.csproj diff --git a/DSharpPlus.sln b/DSharpPlus.sln index 29c5e1ed70..722c099393 100644 --- a/DSharpPlus.sln +++ b/DSharpPlus.sln @@ -15,6 +15,14 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tools", "Tools", "{EAC2F7ED EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tools.Generators.GenerateConcreteObjects", "tools\generators\Tools.Generators.GenerateConcreteObjects\Tools.Generators.GenerateConcreteObjects.csproj", "{DF07A6C6-4689-44DC-80B0-479CA7C6AAF6}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tools.IncrementalUtility", "tools\Tools.IncrementalUtility\Tools.IncrementalUtility.csproj", "{9199CD3F-AD85-453E-9BA5-2B4ACC2576EC}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{EAE89CF5-AA91-4A22-9949-A46FAE1BF0D0}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Core", "Core", "{21927A64-7345-4D90-9EE2-7FA4B1973AAC}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DSharpPlus.Shared.Tests", "tests\core\DSharpPlus.Shared.Tests\DSharpPlus.Shared.Tests.csproj", "{84A68CF6-8FCF-4813-8BA8-9649A553F4C4}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -37,6 +45,14 @@ Global {DF07A6C6-4689-44DC-80B0-479CA7C6AAF6}.Debug|Any CPU.Build.0 = Debug|Any CPU {DF07A6C6-4689-44DC-80B0-479CA7C6AAF6}.Release|Any CPU.ActiveCfg = Release|Any CPU {DF07A6C6-4689-44DC-80B0-479CA7C6AAF6}.Release|Any CPU.Build.0 = Release|Any CPU + {9199CD3F-AD85-453E-9BA5-2B4ACC2576EC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9199CD3F-AD85-453E-9BA5-2B4ACC2576EC}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9199CD3F-AD85-453E-9BA5-2B4ACC2576EC}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9199CD3F-AD85-453E-9BA5-2B4ACC2576EC}.Release|Any CPU.Build.0 = Release|Any CPU + {84A68CF6-8FCF-4813-8BA8-9649A553F4C4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {84A68CF6-8FCF-4813-8BA8-9649A553F4C4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {84A68CF6-8FCF-4813-8BA8-9649A553F4C4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {84A68CF6-8FCF-4813-8BA8-9649A553F4C4}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -46,6 +62,9 @@ Global {964AD252-F077-4AB5-8D92-6C594D08F078} = {BC8D8750-48A4-49EF-9D1F-BE4DBA5B500E} {E14B0AE9-FE71-4DE4-BEB1-4A8E139DB84C} = {BC8D8750-48A4-49EF-9D1F-BE4DBA5B500E} {DF07A6C6-4689-44DC-80B0-479CA7C6AAF6} = {EAC2F7ED-0965-4607-ACE0-829885A612C5} + {9199CD3F-AD85-453E-9BA5-2B4ACC2576EC} = {EAC2F7ED-0965-4607-ACE0-829885A612C5} + {21927A64-7345-4D90-9EE2-7FA4B1973AAC} = {EAE89CF5-AA91-4A22-9949-A46FAE1BF0D0} + {84A68CF6-8FCF-4813-8BA8-9649A553F4C4} = {21927A64-7345-4D90-9EE2-7FA4B1973AAC} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {55CDA684-8900-479B-9DAE-BA3BE09B337B} diff --git a/Directory.Packages.props b/Directory.Packages.props index 16d135ccd2..57d5b1c7df 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -1,6 +1,14 @@ + + + + + + + + \ No newline at end of file diff --git a/src/core/DSharpPlus.Shared/Converters/DictionarySlimJsonConverter.cs b/src/core/DSharpPlus.Shared/Converters/DictionarySlimJsonConverter.cs new file mode 100644 index 0000000000..9d2034cc96 --- /dev/null +++ b/src/core/DSharpPlus.Shared/Converters/DictionarySlimJsonConverter.cs @@ -0,0 +1,109 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +#if !NETSTANDARD + +using System; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using System.Reflection; +using System.Text.Json; +using System.Text.Json.Serialization; + +using DSharpPlus.Collections; + +namespace DSharpPlus.Converters; + +[RequiresUnreferencedCode("JSON serialization and deserialization might require types that cannot be statically analyzed.")] +[RequiresDynamicCode("JSON serialization and deserialization might need runtime code generation. Use the source generator instead.")] +public class DictionarySlimJsonConverter : JsonConverter> + where TKey : IEquatable +{ + /// + public override DictionarySlim? Read + ( + ref Utf8JsonReader reader, + Type typeToConvert, + JsonSerializerOptions options + ) + { + if (reader.TokenType != JsonTokenType.StartObject) + { + throw new JsonException("The provided dictionary start token was not an object."); + } + + DictionarySlim result = new(); + + while (reader.Read()) + { + if (reader.TokenType == JsonTokenType.EndObject) + { + return result; + } + + string propertyNameRaw = reader.GetString()!; + + TKey propertyName; + + // TKey is a string, return a string + if (typeof(TKey) == typeof(string)) + { + propertyName = (TKey)(object)propertyNameRaw; + } + else if (typeof(TKey).IsAssignableTo(typeof(IParsable<>))) + { + // TODO: cache these + object parsed = typeof(TKey).GetMethod + ( + "Parse", + BindingFlags.Public | BindingFlags.Static + )! + .Invoke + ( + null, + new object?[] + { + propertyNameRaw, + null + } + )!; + + propertyName = (TKey)parsed; + } + else + { + propertyName = JsonSerializer.Deserialize(propertyNameRaw)!; + } + + reader.Read(); + + ref TValue propertyValue = ref result.GetOrAddValueRef(propertyName); + + propertyValue = JsonSerializer.Deserialize(ref reader, options)!; + } + + return result; + } + + /// + public override void Write + ( + Utf8JsonWriter writer, + DictionarySlim value, + JsonSerializerOptions options + ) + { + writer.WriteStartObject(); + + foreach (KeyValuePair element in value) + { + writer.WritePropertyName(element.Key.ToString()!); + writer.WriteRawValue(JsonSerializer.SerializeToUtf8Bytes(element.Value, options)); + } + + writer.WriteEndObject(); + } +} + +#endif diff --git a/src/core/DSharpPlus.Shared/Converters/DictionarySlimJsonConverterFactory.cs b/src/core/DSharpPlus.Shared/Converters/DictionarySlimJsonConverterFactory.cs new file mode 100644 index 0000000000..9a9d09634c --- /dev/null +++ b/src/core/DSharpPlus.Shared/Converters/DictionarySlimJsonConverterFactory.cs @@ -0,0 +1,73 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +#if !NETSTANDARD + +using System; +using System.Diagnostics.CodeAnalysis; +using System.Linq; +using System.Text.Json; +using System.Text.Json.Serialization; +using System.Text.Json.Serialization.Metadata; + +using DSharpPlus.Collections; + +namespace DSharpPlus.Converters; + +/// +/// Provides JSON serialization with the appropriate converters for slim dictionaries. +/// +[RequiresDynamicCode("Monomorphized generic instantiations of DictionarySlim might have been trimmed.")] +[RequiresUnreferencedCode("JSON serialization and deserialization might require static analysis of trimmed types.")] +public class DictionarySlimJsonConverterFactory : JsonConverterFactory +{ + /// + public override bool CanConvert + ( + Type typeToConvert + ) + { + if (!typeToConvert.IsGenericType) + { + return false; + } + + if (typeToConvert.GetGenericTypeDefinition() != typeof(DictionarySlim<,>)) + { + return false; + } + + Type[] generics = typeToConvert.GetGenericArguments(); + + return VerifyKeyTypeValidity(generics[0]); + } + + /// + public override JsonConverter? CreateConverter + ( + Type typeToConvert, + JsonSerializerOptions options + ) + { + Type[] generics = typeToConvert.GetGenericArguments(); + + if(generics.All(type => type == typeof(string))) + { + return new DictionarySlimStringStringJsonConverter(); + } + + Type converter = typeof(DictionarySlimJsonConverter<,>) + .MakeGenericType(generics); + + return (JsonConverter?)Activator.CreateInstance(converter); + } + + private static bool VerifyKeyTypeValidity + ( + Type type + ) + => JsonSerializerOptions.Default.GetTypeInfo(type).Kind == JsonTypeInfoKind.None; +} + +#endif diff --git a/src/core/DSharpPlus.Shared/Converters/DictionarySlimStringStringJsonConverter.cs b/src/core/DSharpPlus.Shared/Converters/DictionarySlimStringStringJsonConverter.cs new file mode 100644 index 0000000000..73b7f0bb8d --- /dev/null +++ b/src/core/DSharpPlus.Shared/Converters/DictionarySlimStringStringJsonConverter.cs @@ -0,0 +1,75 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +#if !NETSTANDARD + +using System; +using System.Collections.Generic; +using System.Text.Json; +using System.Text.Json.Serialization; + +using DSharpPlus.Collections; + +namespace DSharpPlus.Converters; + +/// +/// Represents a specialized converter for string-to-string slim dictionaries. This converter is AOT-friendly. +/// +public class DictionarySlimStringStringJsonConverter : JsonConverter> +{ + /// + public override DictionarySlim? Read + ( + ref Utf8JsonReader reader, + Type typeToConvert, + JsonSerializerOptions options + ) + { + if (reader.TokenType != JsonTokenType.StartObject) + { + throw new JsonException("The provided dictionary start token was not an object."); + } + + DictionarySlim result = new(); + + while (reader.Read()) + { + if (reader.TokenType == JsonTokenType.EndObject) + { + return result; + } + + string propertyName = reader.GetString()!; + + reader.Read(); + + ref string propertyValue = ref result.GetOrAddValueRef(propertyName); + + propertyValue = reader.GetString()!; + } + + return result; + } + + /// + public override void Write + ( + Utf8JsonWriter writer, + DictionarySlim value, + JsonSerializerOptions options + ) + { + writer.WriteStartObject(); + + foreach (KeyValuePair element in value) + { + writer.WritePropertyName(element.Key); + writer.WriteStringValue(element.Value); + } + + writer.WriteEndObject(); + } +} + +#endif diff --git a/src/core/DSharpPlus.Shared/DSharpPlus.Shared.csproj b/src/core/DSharpPlus.Shared/DSharpPlus.Shared.csproj index 2a753b65e8..d07b46bb7c 100644 --- a/src/core/DSharpPlus.Shared/DSharpPlus.Shared.csproj +++ b/src/core/DSharpPlus.Shared/DSharpPlus.Shared.csproj @@ -5,6 +5,7 @@ $(Description) This package contains shared types between public-facing and internal implementation packages. Library true + true DSharpPlus diff --git a/tests/core/DSharpPlus.Shared.Tests/Converters/DictionarySlimGeneric.cs b/tests/core/DSharpPlus.Shared.Tests/Converters/DictionarySlimGeneric.cs new file mode 100644 index 0000000000..115c169a22 --- /dev/null +++ b/tests/core/DSharpPlus.Shared.Tests/Converters/DictionarySlimGeneric.cs @@ -0,0 +1,92 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; +using System.Text.Json; + +using DSharpPlus.Collections; +using DSharpPlus.Converters; + +using Xunit; + +namespace DSharpPlus.Shared.Tests.Converters; + +/// +/// Contains generic tests for de/serialization. +/// +public class DictionarySlimGeneric +{ + [Fact] + public void InvalidKeyType() + { + DictionarySlim invalid = new(); + + ref string value = ref invalid.GetOrAddValueRef + ( + new() + { + First = 7, + Second = 8 + } + ); + + value = "test"; + + try + { + JsonSerializerOptions options = new(); + options.Converters.Add(new DictionarySlimJsonConverterFactory()); + + string? serialized = JsonSerializer.Serialize(invalid, options); + + Assert.Null(serialized); + } + catch + { + Assert.True(true); + } + } + + [Fact] + public void Serialize() + { + JsonSerializerOptions options = new(); + options.Converters.Add(new DictionarySlimJsonConverterFactory()); + + DictionarySlim dict = new(); + ref int value = ref dict.GetOrAddValueRef("test"); + + value = 7; + + string serialized = JsonSerializer.Serialize(dict, options); + + Assert.Equal + ( + "{\"test\":7}", + serialized + ); + } + + [Fact] + public void Deserialize() + { + JsonSerializerOptions options = new(); + options.Converters.Add(new DictionarySlimJsonConverterFactory()); + + string serialized = "{\"8\":\"test\"}"; + + DictionarySlim dict = JsonSerializer.Deserialize>(serialized, options)!; + + Assert.Equal("test", dict[8]); + } +} + +readonly file struct ComplexType : IEquatable +{ + public int First { get; init; } + public int Second { get; init; } + + public bool Equals(ComplexType other) + => this.First == other.First && this.Second == other.Second; +} diff --git a/tests/core/DSharpPlus.Shared.Tests/Converters/DictionarySlimStringString.cs b/tests/core/DSharpPlus.Shared.Tests/Converters/DictionarySlimStringString.cs new file mode 100644 index 0000000000..06c9f306f7 --- /dev/null +++ b/tests/core/DSharpPlus.Shared.Tests/Converters/DictionarySlimStringString.cs @@ -0,0 +1,60 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Text.Json; + +using DSharpPlus.Collections; +using DSharpPlus.Converters; + +using Xunit; + +namespace DSharpPlus.Shared.Tests.Converters; + +/// +/// Tests serialization for string, string. +/// +public class DictionarySlimStringString +{ + [Fact] + public void TestDeserialization() + { + JsonSerializerOptions options = new(); + options.Converters.Add(new DictionarySlimStringStringJsonConverter()); + + string test = """ + { + "key": "value", + "other_key": "other_value" + } + """; + + DictionarySlim dict = JsonSerializer.Deserialize>(test, options)!; + + Assert.True(dict["other_key"] == "other_value"); + Assert.True(dict["key"] == "value"); + } + + [Fact] + public void TestSerialization() + { + JsonSerializerOptions options = new(); + options.Converters.Add(new DictionarySlimStringStringJsonConverter()); + + DictionarySlim dict = new(); + + ref string value = ref dict.GetOrAddValueRef("key"); + value = "value"; + + ref string otherValue = ref dict.GetOrAddValueRef("other_key"); + otherValue = "other_value"; + + string serialized = JsonSerializer.Serialize(dict, options); + + Assert.Equal + ( + "{\"key\":\"value\",\"other_key\":\"other_value\"}", + serialized + ); + } +} diff --git a/tests/core/DSharpPlus.Shared.Tests/DSharpPlus.Shared.Tests.csproj b/tests/core/DSharpPlus.Shared.Tests/DSharpPlus.Shared.Tests.csproj new file mode 100644 index 0000000000..2b1cfee613 --- /dev/null +++ b/tests/core/DSharpPlus.Shared.Tests/DSharpPlus.Shared.Tests.csproj @@ -0,0 +1,30 @@ + + + + net8.0 + enable + + false + true + + + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + + + + + diff --git a/tools/Tools.IncrementalUtility/Tools.IncrementalUtility.csproj b/tools/Tools.IncrementalUtility/Tools.IncrementalUtility.csproj new file mode 100644 index 0000000000..f34ee93ec2 --- /dev/null +++ b/tools/Tools.IncrementalUtility/Tools.IncrementalUtility.csproj @@ -0,0 +1,16 @@ + + + + true + + + + + + + + + + + + From 206bfcea1f916426004a4bd2920a47f156f9ae69 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sun, 16 Jul 2023 14:37:07 +0200 Subject: [PATCH 059/323] update dependencies --- Directory.Packages.props | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index 57d5b1c7df..ae2d34a4dd 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -1,14 +1,14 @@ - - + + - - + + - - + + \ No newline at end of file From 7df6bb576fb68f3a14fe3e7a8ac14a16657ab371 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sun, 16 Jul 2023 14:38:29 +0200 Subject: [PATCH 060/323] add incremental file tooling --- tools/Tools.IncrementalUtility/Changes.cs | 19 ++ .../MetadataCollection.cs | 180 ++++++++++++++++++ tools/Tools.IncrementalUtility/SourceFile.cs | 56 ++++++ 3 files changed, 255 insertions(+) create mode 100644 tools/Tools.IncrementalUtility/Changes.cs create mode 100644 tools/Tools.IncrementalUtility/MetadataCollection.cs create mode 100644 tools/Tools.IncrementalUtility/SourceFile.cs diff --git a/tools/Tools.IncrementalUtility/Changes.cs b/tools/Tools.IncrementalUtility/Changes.cs new file mode 100644 index 0000000000..2d5c85870b --- /dev/null +++ b/tools/Tools.IncrementalUtility/Changes.cs @@ -0,0 +1,19 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +namespace Tools.IncrementalUtility; + +/// +/// Contains the changes made to files since the last hashing. +/// +public sealed record Changes +{ + public required IEnumerable Modified { get; init; } + + public required IEnumerable Added { get; init; } + + public required IEnumerable Removed { get; init; } +} diff --git a/tools/Tools.IncrementalUtility/MetadataCollection.cs b/tools/Tools.IncrementalUtility/MetadataCollection.cs new file mode 100644 index 0000000000..3c21533060 --- /dev/null +++ b/tools/Tools.IncrementalUtility/MetadataCollection.cs @@ -0,0 +1,180 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; +using System.Collections; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using System.IO; +using System.Linq; +using System.Text.Json; + +using DSharpPlus.Collections; +using DSharpPlus.Converters; + +namespace Tools.IncrementalUtility; + +/// +/// Represents a collection of current file hashes, with support for listing changed files, added files and +/// removed files. +/// +/// The name of the parent tool invoking this functionality. +public sealed class MetadataCollection +( + string name +) + : IReadOnlyDictionary +{ + private readonly DictionarySlim hashes = new(); + + private static readonly JsonSerializerOptions options = new(); + + static MetadataCollection() => options.Converters.Add(new DictionarySlimStringStringJsonConverter()); + + /// + /// Calculates the current hashes of files, updates the cache and + /// + /// + /// + public Changes CalculateDifferences + ( + params string[] files + ) + { + // load and deserialize the current hashes + // DictionarySlim is really the only DictionarySlim we can do ahead of time + + if (!Directory.Exists("./artifacts/hashes")) + { + Directory.CreateDirectory("./artifacts/hashes"); + } + + // the file does not exist, go back to start and calculate all hashes + if (!File.Exists($"./artifacts/hashes/{name}.json")) + { + File.Create($"./artifacts/hashes/{name}.json").Close(); + this.CalculateAndSaveHashes(files); + + return new Changes + { + Added = files, + Removed = Array.Empty(), + Modified = Array.Empty() + }; + } + + // load the saved hashes + StreamReader reader = new($"./artifacts/hashes/{name}.json"); + +#pragma warning disable IL3050 // we know these are fine, all involved types are statically linked to in this file. +#pragma warning disable IL2026 + DictionarySlim oldHashes = JsonSerializer.Deserialize> + ( + reader.ReadToEnd(), + options + )!; +#pragma warning restore IL2026 +#pragma warning restore IL3050 + + reader.Close(); + + // calculate the differences + + this.CalculateAndSaveHashes(files); + + IEnumerable added = files.Where + ( + name => !oldHashes.ContainsKey(name) + ); + + IEnumerable removed = files.Where + ( + name => oldHashes.ContainsKey(name) && !this.hashes.ContainsKey(name) + ); + + IEnumerable modified = files.Where + ( + name => oldHashes[name] != this.hashes[name] + ); + + return new Changes + { + Added = added, + Removed = removed, + Modified = modified + }; + } + + private void CalculateAndSaveHashes + ( + string[] files + ) + { + // note to future, we might want to somewhat parallelize this + // the infrastructure is there, source files can be constructed without doing the much more + // expensive load, but... + foreach (string file in files) + { + SourceFile sourceFile = new(file); + sourceFile.Load(); + + ref string hash = ref this.hashes.GetOrAddValueRef(file); + hash = sourceFile.Hash.ToString(); + } + + using StreamWriter writer = new($"./artifacts/hashes/{name}.json"); + + writer.Write + ( +#pragma warning disable IL3050 // we know these are fine, all involved types are statically linked to in this file. +#pragma warning disable IL2026 + JsonSerializer.Serialize(this.hashes, options) +#pragma warning restore IL2026 +#pragma warning restore IL3050 + ); + } + + /// + public string this[string key] => this.hashes[key]; + + /// + public IEnumerable Keys => this.hashes.Select(pair => pair.Key); + + /// + public IEnumerable Values => this.hashes.Select(pair => pair.Value); + + /// + public int Count => this.hashes.Count; + + /// + public bool ContainsKey + ( + string key + ) + => this.hashes.ContainsKey(key); + + /// + public IEnumerator> GetEnumerator() + => this.hashes.GetEnumerator(); + + /// + public bool TryGetValue + ( + string key, + + [MaybeNullWhen(false)] + out string value + ) + { + return this.hashes.TryGetValue + ( + key, + out value + ); + } + + /// + IEnumerator IEnumerable.GetEnumerator() + => this.GetEnumerator(); +} diff --git a/tools/Tools.IncrementalUtility/SourceFile.cs b/tools/Tools.IncrementalUtility/SourceFile.cs new file mode 100644 index 0000000000..b9ddecff05 --- /dev/null +++ b/tools/Tools.IncrementalUtility/SourceFile.cs @@ -0,0 +1,56 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Buffers; +using System.IO; +using System.IO.Hashing; +using System.IO.Pipelines; + +namespace Tools.IncrementalUtility; + +/// +/// Represents source file information and a hash indicating whether it has changed. +/// +/// The path to this file. +public sealed class SourceFile +( + string path +) +{ + /// + /// Gets the current hash of this file. + /// + public ulong Hash { get; private set; } = 0; + + /// + /// Loads the file and calculates its current hash. This may be called multiple times. + /// + public void Load() + { + XxHash3 hash = new(); + + using FileStream file = new(path, FileMode.Open, FileAccess.Read); + PipeReader pipe = PipeReader.Create(file); + + while (true) + { + if (!pipe.TryRead(out ReadResult result)) + { + break; + } + + ReadOnlySequence buffer = result.Buffer; + SequenceReader reader = new(buffer); + + // read line by line, because that guarantees that the returned sequence is in one piece. + // if we called .FirstSpan on the buffer we might risk missing data for large files + while (reader.TryReadTo(out ReadOnlySequence sequence, 0x0a)) + { + hash.Append(sequence.FirstSpan); + } + } + + this.Hash = hash.GetCurrentHashAsUInt64(); + } +} From 39cbae39764f135f472fec068704bce390bc14e4 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sun, 16 Jul 2023 14:43:05 +0200 Subject: [PATCH 061/323] change the DSharpPlus.Shared ns2.0 logic functionally it does the same thing, but building from within VS works this way --- src/core/DSharpPlus.Shared/DSharpPlus.Shared.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/DSharpPlus.Shared/DSharpPlus.Shared.csproj b/src/core/DSharpPlus.Shared/DSharpPlus.Shared.csproj index d07b46bb7c..da1f99d6cc 100644 --- a/src/core/DSharpPlus.Shared/DSharpPlus.Shared.csproj +++ b/src/core/DSharpPlus.Shared/DSharpPlus.Shared.csproj @@ -10,7 +10,7 @@ DSharpPlus - + netstandard2.0;$(TargetFramework) From c2144add522fdb88b1a14d760916c6cbd2fc30aa Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Tue, 18 Jul 2023 00:50:05 +0200 Subject: [PATCH 062/323] remove reflection from the CLR DictionarySlim serializer --- ... => DictionarySlimGenericJsonConverter.cs} | 36 +---- ...tionarySlimIParsableTValueJsonConverter.cs | 82 ++++++++++ .../DictionarySlimJsonConverterFactory.cs | 45 +++++- ...DictionarySlimStringTValueJsonConverter.cs | 78 ++++++++++ .../Converters/DictionarySlimCLR.Floats.cs | 54 +++++++ .../Converters/DictionarySlimCLR.General.cs | 142 ++++++++++++++++++ .../Converters/DictionarySlimCLR.Guid.cs | 54 +++++++ .../Converters/DictionarySlimCLR.Integers.cs | 90 +++++++++++ .../Converters/DictionarySlimCLR.String.cs | 53 +++++++ .../Converters/DictionarySlimGeneric.cs | 92 ------------ 10 files changed, 594 insertions(+), 132 deletions(-) rename src/core/DSharpPlus.Shared/Converters/{DictionarySlimJsonConverter.cs => DictionarySlimGenericJsonConverter.cs} (66%) create mode 100644 src/core/DSharpPlus.Shared/Converters/DictionarySlimIParsableTValueJsonConverter.cs create mode 100644 src/core/DSharpPlus.Shared/Converters/DictionarySlimStringTValueJsonConverter.cs create mode 100644 tests/core/DSharpPlus.Shared.Tests/Converters/DictionarySlimCLR.Floats.cs create mode 100644 tests/core/DSharpPlus.Shared.Tests/Converters/DictionarySlimCLR.General.cs create mode 100644 tests/core/DSharpPlus.Shared.Tests/Converters/DictionarySlimCLR.Guid.cs create mode 100644 tests/core/DSharpPlus.Shared.Tests/Converters/DictionarySlimCLR.Integers.cs create mode 100644 tests/core/DSharpPlus.Shared.Tests/Converters/DictionarySlimCLR.String.cs delete mode 100644 tests/core/DSharpPlus.Shared.Tests/Converters/DictionarySlimGeneric.cs diff --git a/src/core/DSharpPlus.Shared/Converters/DictionarySlimJsonConverter.cs b/src/core/DSharpPlus.Shared/Converters/DictionarySlimGenericJsonConverter.cs similarity index 66% rename from src/core/DSharpPlus.Shared/Converters/DictionarySlimJsonConverter.cs rename to src/core/DSharpPlus.Shared/Converters/DictionarySlimGenericJsonConverter.cs index 9d2034cc96..b6d5845838 100644 --- a/src/core/DSharpPlus.Shared/Converters/DictionarySlimJsonConverter.cs +++ b/src/core/DSharpPlus.Shared/Converters/DictionarySlimGenericJsonConverter.cs @@ -7,7 +7,6 @@ using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; -using System.Reflection; using System.Text.Json; using System.Text.Json.Serialization; @@ -17,7 +16,7 @@ namespace DSharpPlus.Converters; [RequiresUnreferencedCode("JSON serialization and deserialization might require types that cannot be statically analyzed.")] [RequiresDynamicCode("JSON serialization and deserialization might need runtime code generation. Use the source generator instead.")] -public class DictionarySlimJsonConverter : JsonConverter> +public class DictionarySlimGenericJsonConverter : JsonConverter> where TKey : IEquatable { /// @@ -43,38 +42,7 @@ JsonSerializerOptions options } string propertyNameRaw = reader.GetString()!; - - TKey propertyName; - - // TKey is a string, return a string - if (typeof(TKey) == typeof(string)) - { - propertyName = (TKey)(object)propertyNameRaw; - } - else if (typeof(TKey).IsAssignableTo(typeof(IParsable<>))) - { - // TODO: cache these - object parsed = typeof(TKey).GetMethod - ( - "Parse", - BindingFlags.Public | BindingFlags.Static - )! - .Invoke - ( - null, - new object?[] - { - propertyNameRaw, - null - } - )!; - - propertyName = (TKey)parsed; - } - else - { - propertyName = JsonSerializer.Deserialize(propertyNameRaw)!; - } + TKey propertyName = JsonSerializer.Deserialize(propertyNameRaw)!; reader.Read(); diff --git a/src/core/DSharpPlus.Shared/Converters/DictionarySlimIParsableTValueJsonConverter.cs b/src/core/DSharpPlus.Shared/Converters/DictionarySlimIParsableTValueJsonConverter.cs new file mode 100644 index 0000000000..4026b92e06 --- /dev/null +++ b/src/core/DSharpPlus.Shared/Converters/DictionarySlimIParsableTValueJsonConverter.cs @@ -0,0 +1,82 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using System.Text.Json; +using System.Text.Json.Serialization; + +using DSharpPlus.Collections; + +namespace DSharpPlus.Converters; + +/// +/// Provides JSON conversion logic for with +/// keys. It is assumed that there is a correct roundtrip between and +/// . +/// +[RequiresUnreferencedCode("JSON serialization and deserialization might require types that cannot be statically analyzed.")] +[RequiresDynamicCode("JSON serialization and deserialization might need runtime code generation. Use the source generator instead.")] +public class DictionarySlimIParsableTValueJsonConverter : JsonConverter> + where TKey : IEquatable, IParsable +{ + /// + public override DictionarySlim? Read + ( + ref Utf8JsonReader reader, + Type typeToConvert, + JsonSerializerOptions options + ) + { + if (reader.TokenType != JsonTokenType.StartObject) + { + throw new JsonException("The provided dictionary start token was not an object."); + } + + DictionarySlim result = new(); + + while (reader.Read()) + { + if (reader.TokenType == JsonTokenType.EndObject) + { + return result; + } + + string propertyNameRaw = reader.GetString()!; + + if(!TKey.TryParse(propertyNameRaw, null, out TKey? propertyName)) + { + throw new ArgumentException($"The key {propertyNameRaw} could not be parsed as {typeof(TKey)}."); + } + + reader.Read(); + + ref TValue propertyValue = ref result.GetOrAddValueRef(propertyName!); + + propertyValue = JsonSerializer.Deserialize(ref reader, options)!; + } + + return result; + } + + /// + public override void Write + ( + Utf8JsonWriter writer, + DictionarySlim value, + JsonSerializerOptions options + ) + { + writer.WriteStartObject(); + + foreach (KeyValuePair element in value) + { + writer.WritePropertyName(element.Key.ToString()!); + writer.WriteRawValue(JsonSerializer.SerializeToUtf8Bytes(element.Value, options)); + } + + writer.WriteEndObject(); + } +} diff --git a/src/core/DSharpPlus.Shared/Converters/DictionarySlimJsonConverterFactory.cs b/src/core/DSharpPlus.Shared/Converters/DictionarySlimJsonConverterFactory.cs index 9a9d09634c..ecfe68ea64 100644 --- a/src/core/DSharpPlus.Shared/Converters/DictionarySlimJsonConverterFactory.cs +++ b/src/core/DSharpPlus.Shared/Converters/DictionarySlimJsonConverterFactory.cs @@ -9,7 +9,6 @@ using System.Linq; using System.Text.Json; using System.Text.Json.Serialization; -using System.Text.Json.Serialization.Metadata; using DSharpPlus.Collections; @@ -52,22 +51,56 @@ JsonSerializerOptions options { Type[] generics = typeToConvert.GetGenericArguments(); - if(generics.All(type => type == typeof(string))) + // we can add more specialized converters here for more AOT-designed, specialized converters here, + // though only if they add new key types or specialize TValue to a meaningful degree. specializing + // on TKey where TKey : IParsable makes little sense, for the CLR implementation. + if (generics[0] == typeof(string) && generics[1] == typeof(string)) { return new DictionarySlimStringStringJsonConverter(); } + else if (generics[0] == typeof(string)) + { + Type converter = typeof(DictionarySlimStringTValueJsonConverter<>) + .MakeGenericType(generics[1]); + + return (JsonConverter?)Activator.CreateInstance(converter); + } + else if + ( + generics[0].GetInterfaces() + .Any + ( + candidate => candidate.IsGenericType + && candidate.GetGenericTypeDefinition() == typeof(IParsable<>) + ) + ) + { + Type converter = typeof(DictionarySlimIParsableTValueJsonConverter<,>) + .MakeGenericType(generics); - Type converter = typeof(DictionarySlimJsonConverter<,>) - .MakeGenericType(generics); + return (JsonConverter?)Activator.CreateInstance(converter); + } + else + { + Type converter = typeof(DictionarySlimGenericJsonConverter<,>) + .MakeGenericType(generics); - return (JsonConverter?)Activator.CreateInstance(converter); + return (JsonConverter?)Activator.CreateInstance(converter); + } } private static bool VerifyKeyTypeValidity ( Type type ) - => JsonSerializerOptions.Default.GetTypeInfo(type).Kind == JsonTypeInfoKind.None; + { + return type == typeof(string) || type.GetInterfaces() + .Any + ( + candidate => candidate.IsGenericType + && candidate.GetGenericTypeDefinition() == typeof(IParsable<>) + ); + } } #endif diff --git a/src/core/DSharpPlus.Shared/Converters/DictionarySlimStringTValueJsonConverter.cs b/src/core/DSharpPlus.Shared/Converters/DictionarySlimStringTValueJsonConverter.cs new file mode 100644 index 0000000000..da0731228c --- /dev/null +++ b/src/core/DSharpPlus.Shared/Converters/DictionarySlimStringTValueJsonConverter.cs @@ -0,0 +1,78 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +#if !NETSTANDARD + +using System; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using System.Text.Json; +using System.Text.Json.Serialization; + +using DSharpPlus.Collections; + +namespace DSharpPlus.Converters; + +/// +/// Provides JSON conversion logic for with keys. +/// +[RequiresUnreferencedCode("JSON serialization and deserialization might require types that cannot be statically analyzed.")] +[RequiresDynamicCode("JSON serialization and deserialization might need runtime code generation. Use the source generator instead.")] +public class DictionarySlimStringTValueJsonConverter : JsonConverter> +{ + /// + public override DictionarySlim? Read + ( + ref Utf8JsonReader reader, + Type typeToConvert, + JsonSerializerOptions options + ) + { + if (reader.TokenType != JsonTokenType.StartObject) + { + throw new JsonException("The provided dictionary start token was not an object."); + } + + DictionarySlim result = new(); + + while (reader.Read()) + { + if (reader.TokenType == JsonTokenType.EndObject) + { + return result; + } + + string propertyName = reader.GetString()!; + + reader.Read(); + + ref TValue propertyValue = ref result.GetOrAddValueRef(propertyName); + + propertyValue = JsonSerializer.Deserialize(ref reader, options)!; + } + + return result; + } + + /// + public override void Write + ( + Utf8JsonWriter writer, + DictionarySlim value, + JsonSerializerOptions options + ) + { + writer.WriteStartObject(); + + foreach (KeyValuePair element in value) + { + writer.WritePropertyName(element.Key); + writer.WriteRawValue(JsonSerializer.SerializeToUtf8Bytes(element.Value, options)); + } + + writer.WriteEndObject(); + } +} + +#endif diff --git a/tests/core/DSharpPlus.Shared.Tests/Converters/DictionarySlimCLR.Floats.cs b/tests/core/DSharpPlus.Shared.Tests/Converters/DictionarySlimCLR.Floats.cs new file mode 100644 index 0000000000..81ccdb2763 --- /dev/null +++ b/tests/core/DSharpPlus.Shared.Tests/Converters/DictionarySlimCLR.Floats.cs @@ -0,0 +1,54 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; +using System.Text.Json; + +using DSharpPlus.Collections; +using DSharpPlus.Converters; + +using Xunit; + +namespace DSharpPlus.Shared.Tests.Converters; + +// here we deal with whether floating-point keys, positive and negative, are handled correctly +public partial class DictionarySlimCLR +{ + [Fact] + public void Serialize_Float() + { + JsonSerializerOptions options = new(); + options.Converters.Add(new DictionarySlimJsonConverterFactory()); + + DictionarySlim dict = new(); + ref int value = ref dict.GetOrAddValueRef((Half)(-3.2)); + + value = 7; + + string serialized = JsonSerializer.Serialize(dict, options); + + Assert.Equal + ( + "{\"-3.2\":7}", + serialized + ); + } + + [Fact] + public void Deserialize_Float() + { + JsonSerializerOptions options = new(); + options.Converters.Add(new DictionarySlimJsonConverterFactory()); + + string serialized = "{\"11.1\":\"test\"}"; + + DictionarySlim dict = JsonSerializer.Deserialize> + ( + serialized, + options + )!; + + Assert.Equal("test", dict[11.1f]); + } +} diff --git a/tests/core/DSharpPlus.Shared.Tests/Converters/DictionarySlimCLR.General.cs b/tests/core/DSharpPlus.Shared.Tests/Converters/DictionarySlimCLR.General.cs new file mode 100644 index 0000000000..726f8be6b5 --- /dev/null +++ b/tests/core/DSharpPlus.Shared.Tests/Converters/DictionarySlimCLR.General.cs @@ -0,0 +1,142 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; +using System.Text.Json; + +using DSharpPlus.Collections; +using DSharpPlus.Converters; + +using Xunit; + +namespace DSharpPlus.Shared.Tests.Converters; + +/// +/// Contains generic tests for de/serialization. +/// +// in this file, we look at whether we correctly evaluate CanConvert +public partial class DictionarySlimCLR +{ + [Fact] + public void InvalidKeyType() + { + DictionarySlim invalid = new(); + + ref string value = ref invalid.GetOrAddValueRef + ( + new() + { + First = 7, + Second = 8 + } + ); + + value = "test"; + + try + { + JsonSerializerOptions options = new(); + options.Converters.Add(new DictionarySlimJsonConverterFactory()); + + string? serialized = JsonSerializer.Serialize(invalid, options); + + Assert.Null(serialized); + } + catch + { + Assert.True(true); + } + } + + [Fact] + public void ValidKeyType_String() + { + DictionarySlim valid = new(); + + ref string value = ref valid.GetOrAddValueRef + ( + "testificate" + ); + + value = "test"; + + try + { + JsonSerializerOptions options = new(); + options.Converters.Add(new DictionarySlimJsonConverterFactory()); + + string? serialized = JsonSerializer.Serialize(valid, options); + + Assert.NotNull(serialized); + } + catch + { + Assert.True(false); + } + } + + [Fact] + public void ValidKeyType_Guid() + { + DictionarySlim valid = new(); + + ref string value = ref valid.GetOrAddValueRef + ( + Guid.NewGuid() + ); + + value = "test"; + + try + { + JsonSerializerOptions options = new(); + options.Converters.Add(new DictionarySlimJsonConverterFactory()); + + string? serialized = JsonSerializer.Serialize(valid, options); + + Assert.NotNull(serialized); + } + catch + { + Assert.True(false); + } + } + + [Fact] + public void ValidKeyType_UInt128() + { + DictionarySlim valid = new(); + + ref string value = ref valid.GetOrAddValueRef + ( + (UInt128)ulong.MaxValue + 2 + ); + + value = "test"; + + try + { + JsonSerializerOptions options = new(); + options.Converters.Add(new DictionarySlimJsonConverterFactory()); + + string? serialized = JsonSerializer.Serialize(valid, options); + + Assert.NotNull(serialized); + } + catch + { + Assert.True(false); + } + } +} + +#pragma warning disable CA1067 // we don't care about implementing Object.Equals here, it's a test type +readonly file struct ComplexType : IEquatable +{ + public int First { get; init; } + public int Second { get; init; } + + public bool Equals(ComplexType other) + => this.First == other.First && this.Second == other.Second; +} diff --git a/tests/core/DSharpPlus.Shared.Tests/Converters/DictionarySlimCLR.Guid.cs b/tests/core/DSharpPlus.Shared.Tests/Converters/DictionarySlimCLR.Guid.cs new file mode 100644 index 0000000000..d8d7743b97 --- /dev/null +++ b/tests/core/DSharpPlus.Shared.Tests/Converters/DictionarySlimCLR.Guid.cs @@ -0,0 +1,54 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; +using System.Text.Json; + +using DSharpPlus.Collections; +using DSharpPlus.Converters; + +using Xunit; + +namespace DSharpPlus.Shared.Tests.Converters; + +// here we deal with whether guid keys are handled correctly +public partial class DictionarySlimCLR +{ + [Fact] + public void Serialize_Guid() + { + JsonSerializerOptions options = new(); + options.Converters.Add(new DictionarySlimJsonConverterFactory()); + + DictionarySlim dict = new(); + ref int value = ref dict.GetOrAddValueRef(Guid.Parse("20aa0594-1579-42b5-af9c-3295705239dd")); + + value = 7; + + string serialized = JsonSerializer.Serialize(dict, options); + + Assert.Equal + ( + "{\"20aa0594-1579-42b5-af9c-3295705239dd\":7}", + serialized + ); + } + + [Fact] + public void Deserialize_Guid() + { + JsonSerializerOptions options = new(); + options.Converters.Add(new DictionarySlimJsonConverterFactory()); + + string serialized = "{\"1107720a-fa7d-437d-8347-b96986589d6e\":\"test\"}"; + + DictionarySlim dict = JsonSerializer.Deserialize> + ( + serialized, + options + )!; + + Assert.Equal("test", dict[Guid.Parse("1107720a-fa7d-437d-8347-b96986589d6e")]); + } +} diff --git a/tests/core/DSharpPlus.Shared.Tests/Converters/DictionarySlimCLR.Integers.cs b/tests/core/DSharpPlus.Shared.Tests/Converters/DictionarySlimCLR.Integers.cs new file mode 100644 index 0000000000..7b20c73b14 --- /dev/null +++ b/tests/core/DSharpPlus.Shared.Tests/Converters/DictionarySlimCLR.Integers.cs @@ -0,0 +1,90 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Text.Json; + +using DSharpPlus.Collections; +using DSharpPlus.Converters; + +using Xunit; + +namespace DSharpPlus.Shared.Tests.Converters; + +// here we deal with whether integer keys, positive and negative, are handled correctly +public partial class DictionarySlimCLR +{ + [Fact] + public void Serialize_PositiveInteger() + { + JsonSerializerOptions options = new(); + options.Converters.Add(new DictionarySlimJsonConverterFactory()); + + DictionarySlim dict = new(); + ref int value = ref dict.GetOrAddValueRef(3); + + value = 7; + + string serialized = JsonSerializer.Serialize(dict, options); + + Assert.Equal + ( + "{\"3\":7}", + serialized + ); + } + + [Fact] + public void Deserialize_PositiveInteger() + { + JsonSerializerOptions options = new(); + options.Converters.Add(new DictionarySlimJsonConverterFactory()); + + string serialized = "{\"11\":\"test\"}"; + + DictionarySlim dict = JsonSerializer.Deserialize> + ( + serialized, + options + )!; + + Assert.Equal("test", dict[11]); + } + + [Fact] + public void Serialize_NegativeInteger() + { + JsonSerializerOptions options = new(); + options.Converters.Add(new DictionarySlimJsonConverterFactory()); + + DictionarySlim dict = new(); + ref int value = ref dict.GetOrAddValueRef(-9); + + value = 7; + + string serialized = JsonSerializer.Serialize(dict, options); + + Assert.Equal + ( + "{\"-9\":7}", + serialized + ); + } + + [Fact] + public void Deserialize_NegativeInteger() + { + JsonSerializerOptions options = new(); + options.Converters.Add(new DictionarySlimJsonConverterFactory()); + + string serialized = "{\"-11\":\"test\"}"; + + DictionarySlim dict = JsonSerializer.Deserialize> + ( + serialized, + options + )!; + + Assert.Equal("test", dict[-11]); + } +} diff --git a/tests/core/DSharpPlus.Shared.Tests/Converters/DictionarySlimCLR.String.cs b/tests/core/DSharpPlus.Shared.Tests/Converters/DictionarySlimCLR.String.cs new file mode 100644 index 0000000000..6821062c05 --- /dev/null +++ b/tests/core/DSharpPlus.Shared.Tests/Converters/DictionarySlimCLR.String.cs @@ -0,0 +1,53 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Text.Json; + +using DSharpPlus.Collections; +using DSharpPlus.Converters; + +using Xunit; + +namespace DSharpPlus.Shared.Tests.Converters; + +// here we deal with whether string keys are handled correctly +public partial class DictionarySlimCLR +{ + [Fact] + public void Serialize_String() + { + JsonSerializerOptions options = new(); + options.Converters.Add(new DictionarySlimJsonConverterFactory()); + + DictionarySlim dict = new(); + ref int value = ref dict.GetOrAddValueRef("test"); + + value = 7; + + string serialized = JsonSerializer.Serialize(dict, options); + + Assert.Equal + ( + "{\"test\":7}", + serialized + ); + } + + [Fact] + public void Deserialize_String() + { + JsonSerializerOptions options = new(); + options.Converters.Add(new DictionarySlimJsonConverterFactory()); + + string serialized = "{\"test\":8}"; + + DictionarySlim dict = JsonSerializer.Deserialize> + ( + serialized, + options + )!; + + Assert.Equal(8, dict["test"]); + } +} diff --git a/tests/core/DSharpPlus.Shared.Tests/Converters/DictionarySlimGeneric.cs b/tests/core/DSharpPlus.Shared.Tests/Converters/DictionarySlimGeneric.cs deleted file mode 100644 index 115c169a22..0000000000 --- a/tests/core/DSharpPlus.Shared.Tests/Converters/DictionarySlimGeneric.cs +++ /dev/null @@ -1,92 +0,0 @@ -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -using System; -using System.Text.Json; - -using DSharpPlus.Collections; -using DSharpPlus.Converters; - -using Xunit; - -namespace DSharpPlus.Shared.Tests.Converters; - -/// -/// Contains generic tests for de/serialization. -/// -public class DictionarySlimGeneric -{ - [Fact] - public void InvalidKeyType() - { - DictionarySlim invalid = new(); - - ref string value = ref invalid.GetOrAddValueRef - ( - new() - { - First = 7, - Second = 8 - } - ); - - value = "test"; - - try - { - JsonSerializerOptions options = new(); - options.Converters.Add(new DictionarySlimJsonConverterFactory()); - - string? serialized = JsonSerializer.Serialize(invalid, options); - - Assert.Null(serialized); - } - catch - { - Assert.True(true); - } - } - - [Fact] - public void Serialize() - { - JsonSerializerOptions options = new(); - options.Converters.Add(new DictionarySlimJsonConverterFactory()); - - DictionarySlim dict = new(); - ref int value = ref dict.GetOrAddValueRef("test"); - - value = 7; - - string serialized = JsonSerializer.Serialize(dict, options); - - Assert.Equal - ( - "{\"test\":7}", - serialized - ); - } - - [Fact] - public void Deserialize() - { - JsonSerializerOptions options = new(); - options.Converters.Add(new DictionarySlimJsonConverterFactory()); - - string serialized = "{\"8\":\"test\"}"; - - DictionarySlim dict = JsonSerializer.Deserialize>(serialized, options)!; - - Assert.Equal("test", dict[8]); - } -} - -readonly file struct ComplexType : IEquatable -{ - public int First { get; init; } - public int Second { get; init; } - - public bool Equals(ComplexType other) - => this.First == other.First && this.Second == other.Second; -} From 14ea49a8edee13613976b2aaabad6c8dec0bd310 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Tue, 18 Jul 2023 12:34:31 +0200 Subject: [PATCH 063/323] fix hash intersection logic previously, it would try to get the hashes for files that have been added/removed --- tools/Tools.IncrementalUtility/MetadataCollection.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tools/Tools.IncrementalUtility/MetadataCollection.cs b/tools/Tools.IncrementalUtility/MetadataCollection.cs index 3c21533060..0bddb40af1 100644 --- a/tools/Tools.IncrementalUtility/MetadataCollection.cs +++ b/tools/Tools.IncrementalUtility/MetadataCollection.cs @@ -95,7 +95,12 @@ params string[] files IEnumerable modified = files.Where ( - name => oldHashes[name] != this.hashes[name] + name => + { + return oldHashes.TryGetValue(name, out string? oldHash) + && this.hashes.TryGetValue(name, out string? newHash) + && oldHash != newHash; + } ); return new Changes From 7f1ef730b0fee1be2c1a8a6d25689d01baa04867 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sun, 23 Jul 2023 19:54:42 +0200 Subject: [PATCH 064/323] i missed a windows conditional --- script-functions.ps1 | 3 +++ 1 file changed, 3 insertions(+) diff --git a/script-functions.ps1 b/script-functions.ps1 index f24bec6fa2..301122d285 100644 --- a/script-functions.ps1 +++ b/script-functions.ps1 @@ -485,6 +485,9 @@ function Test-ToolBuilt { ) process { + if ($IsWindows) { + return Test-Path -Path "$PSScriptRoot/tools/bin/$Name.exe" + } return Test-Path -Path "$PSScriptRoot/tools/bin/$Name" } } \ No newline at end of file From b79a8e6ef0d5a1178c3eb5f720f163c3db06c47d Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Tue, 1 Aug 2023 17:59:04 +0200 Subject: [PATCH 065/323] fix the incremental utility, add bundles as a submodule --- .gitignore | 3 +- .gitmodules | 3 + DSharpPlus.sln | 14 ++++- Directory.Packages.props | 7 ++- .../DSharpPlus.SourceGenerators.Common.csproj | 13 +++++ gen/common/Extensions/TypeSymbolExtensions.cs | 57 +++++++++++++++++++ lib/bundles | 1 + tools/Tools.IncrementalUtility/Hashes.cs | 25 ++++++++ .../MetadataCollection.cs | 30 ++++------ tools/Tools.IncrementalUtility/SourceFile.cs | 23 +------- .../Tools.IncrementalUtility.csproj | 4 +- 11 files changed, 135 insertions(+), 45 deletions(-) create mode 100644 .gitmodules create mode 100644 gen/common/DSharpPlus.SourceGenerators.Common.csproj create mode 100644 gen/common/Extensions/TypeSymbolExtensions.cs create mode 160000 lib/bundles create mode 100644 tools/Tools.IncrementalUtility/Hashes.cs diff --git a/.gitignore b/.gitignore index 6578864066..a6f497d62c 100644 --- a/.gitignore +++ b/.gitignore @@ -408,4 +408,5 @@ docs/_site # tool test environment .testenv -.testenvhost \ No newline at end of file +.testenvhost +/.vscode/settings.json diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000000..3ca45de881 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "bundles"] + path = lib/bundles + url = https://github.com/dsharpplus/bundles.git diff --git a/DSharpPlus.sln b/DSharpPlus.sln index 722c099393..755a009d35 100644 --- a/DSharpPlus.sln +++ b/DSharpPlus.sln @@ -14,6 +14,9 @@ EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tools", "Tools", "{EAC2F7ED-0965-4607-ACE0-829885A612C5}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tools.Generators.GenerateConcreteObjects", "tools\generators\Tools.Generators.GenerateConcreteObjects\Tools.Generators.GenerateConcreteObjects.csproj", "{DF07A6C6-4689-44DC-80B0-479CA7C6AAF6}" + ProjectSection(ProjectDependencies) = postProject + {9199CD3F-AD85-453E-9BA5-2B4ACC2576EC} = {9199CD3F-AD85-453E-9BA5-2B4ACC2576EC} + EndProjectSection EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tools.IncrementalUtility", "tools\Tools.IncrementalUtility\Tools.IncrementalUtility.csproj", "{9199CD3F-AD85-453E-9BA5-2B4ACC2576EC}" EndProject @@ -21,7 +24,11 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{EAE89CF5 EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Core", "Core", "{21927A64-7345-4D90-9EE2-7FA4B1973AAC}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DSharpPlus.Shared.Tests", "tests\core\DSharpPlus.Shared.Tests\DSharpPlus.Shared.Tests.csproj", "{84A68CF6-8FCF-4813-8BA8-9649A553F4C4}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DSharpPlus.Shared.Tests", "tests\core\DSharpPlus.Shared.Tests\DSharpPlus.Shared.Tests.csproj", "{84A68CF6-8FCF-4813-8BA8-9649A553F4C4}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Generators", "Generators", "{5FBB4590-56B0-453B-A87B-08A17C599B5C}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DSharpPlus.SourceGenerators.Common", "gen\common\DSharpPlus.SourceGenerators.Common.csproj", "{98D2C52C-E3BA-4564-919C-750775B7BA9C}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -53,6 +60,10 @@ Global {84A68CF6-8FCF-4813-8BA8-9649A553F4C4}.Debug|Any CPU.Build.0 = Debug|Any CPU {84A68CF6-8FCF-4813-8BA8-9649A553F4C4}.Release|Any CPU.ActiveCfg = Release|Any CPU {84A68CF6-8FCF-4813-8BA8-9649A553F4C4}.Release|Any CPU.Build.0 = Release|Any CPU + {98D2C52C-E3BA-4564-919C-750775B7BA9C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {98D2C52C-E3BA-4564-919C-750775B7BA9C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {98D2C52C-E3BA-4564-919C-750775B7BA9C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {98D2C52C-E3BA-4564-919C-750775B7BA9C}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -65,6 +76,7 @@ Global {9199CD3F-AD85-453E-9BA5-2B4ACC2576EC} = {EAC2F7ED-0965-4607-ACE0-829885A612C5} {21927A64-7345-4D90-9EE2-7FA4B1973AAC} = {EAE89CF5-AA91-4A22-9949-A46FAE1BF0D0} {84A68CF6-8FCF-4813-8BA8-9649A553F4C4} = {21927A64-7345-4D90-9EE2-7FA4B1973AAC} + {98D2C52C-E3BA-4564-919C-750775B7BA9C} = {5FBB4590-56B0-453B-A87B-08A17C599B5C} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {55CDA684-8900-479B-9DAE-BA3BE09B337B} diff --git a/Directory.Packages.props b/Directory.Packages.props index ae2d34a4dd..ee2aa01ff5 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -1,11 +1,16 @@ + + + + + + - diff --git a/gen/common/DSharpPlus.SourceGenerators.Common.csproj b/gen/common/DSharpPlus.SourceGenerators.Common.csproj new file mode 100644 index 0000000000..543498f19b --- /dev/null +++ b/gen/common/DSharpPlus.SourceGenerators.Common.csproj @@ -0,0 +1,13 @@ + + + + netstandard2.0 + enable + enable + + + + + + + diff --git a/gen/common/Extensions/TypeSymbolExtensions.cs b/gen/common/Extensions/TypeSymbolExtensions.cs new file mode 100644 index 0000000000..526e47febb --- /dev/null +++ b/gen/common/Extensions/TypeSymbolExtensions.cs @@ -0,0 +1,57 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using Microsoft.CodeAnalysis; + +namespace DSharpPlus.SourceGenerators.Common.Extensions; + +/// +/// Contains convenience extensions on ITypeSymbol +/// +public static class TypeSymbolExtensions +{ + /// + /// Returns all public properties of a type, including those inherited from base types. If this type is an + /// interface, this returns all public properties of any base interfaces. + /// + /// + /// WARNING: This method comes with a drastic performance penalty. + /// + public static IEnumerable GetPublicProperties + ( + this ITypeSymbol type + ) + { + IEnumerable symbols = type.GetMembers() + .Where + ( + xm => xm is IPropertySymbol + { + DeclaredAccessibility: Accessibility.Public + } + ) + .Cast(); + + if (type.BaseType is not null) + { + symbols = symbols.Concat + ( + type.BaseType.GetPublicProperties() + ); + } + + if (type is { TypeKind: TypeKind.Interface, Interfaces: not { IsDefaultOrEmpty: true } }) + { + foreach (INamedTypeSymbol baseInterface in type.Interfaces) + { + symbols = symbols.Concat + ( + baseInterface.GetPublicProperties() + ); + } + } + + return symbols.Distinct(SymbolEqualityComparer.IncludeNullability).Cast(); + } +} diff --git a/lib/bundles b/lib/bundles new file mode 160000 index 0000000000..1235e0ad2a --- /dev/null +++ b/lib/bundles @@ -0,0 +1 @@ +Subproject commit 1235e0ad2a766492bf3dcdea09256e71a62fdebd diff --git a/tools/Tools.IncrementalUtility/Hashes.cs b/tools/Tools.IncrementalUtility/Hashes.cs new file mode 100644 index 0000000000..878663fd88 --- /dev/null +++ b/tools/Tools.IncrementalUtility/Hashes.cs @@ -0,0 +1,25 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Text.Json.Serialization; + +using Bundles; +using Bundles.Converters; + +namespace Tools.IncrementalUtility; + +/// +/// Represents a serialization model for the hashes. +/// +public partial record Hashes +{ + [JsonConverter(typeof(DictionarySlimStringStringJsonConverter))] + public required DictionarySlim Values { get; init; } +} + +[JsonSerializable(typeof(Hashes))] +internal partial class SerializationContext : JsonSerializerContext +{ + +} diff --git a/tools/Tools.IncrementalUtility/MetadataCollection.cs b/tools/Tools.IncrementalUtility/MetadataCollection.cs index 0bddb40af1..3b09aff56d 100644 --- a/tools/Tools.IncrementalUtility/MetadataCollection.cs +++ b/tools/Tools.IncrementalUtility/MetadataCollection.cs @@ -10,8 +10,7 @@ using System.Linq; using System.Text.Json; -using DSharpPlus.Collections; -using DSharpPlus.Converters; +using Bundles; namespace Tools.IncrementalUtility; @@ -28,10 +27,6 @@ string name { private readonly DictionarySlim hashes = new(); - private static readonly JsonSerializerOptions options = new(); - - static MetadataCollection() => options.Converters.Add(new DictionarySlimStringStringJsonConverter()); - /// /// Calculates the current hashes of files, updates the cache and /// @@ -67,15 +62,11 @@ params string[] files // load the saved hashes StreamReader reader = new($"./artifacts/hashes/{name}.json"); -#pragma warning disable IL3050 // we know these are fine, all involved types are statically linked to in this file. -#pragma warning disable IL2026 - DictionarySlim oldHashes = JsonSerializer.Deserialize> + DictionarySlim oldHashes = JsonSerializer.Deserialize ( reader.ReadToEnd(), - options - )!; -#pragma warning restore IL2026 -#pragma warning restore IL3050 + SerializationContext.Default.Hashes + )!.Values; reader.Close(); @@ -132,11 +123,14 @@ string[] files writer.Write ( -#pragma warning disable IL3050 // we know these are fine, all involved types are statically linked to in this file. -#pragma warning disable IL2026 - JsonSerializer.Serialize(this.hashes, options) -#pragma warning restore IL2026 -#pragma warning restore IL3050 + JsonSerializer.Serialize + ( + new Hashes + { + Values = this.hashes + }, + SerializationContext.Default.Hashes + ) ); } diff --git a/tools/Tools.IncrementalUtility/SourceFile.cs b/tools/Tools.IncrementalUtility/SourceFile.cs index b9ddecff05..71111e9304 100644 --- a/tools/Tools.IncrementalUtility/SourceFile.cs +++ b/tools/Tools.IncrementalUtility/SourceFile.cs @@ -2,10 +2,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using System.Buffers; using System.IO; using System.IO.Hashing; -using System.IO.Pipelines; namespace Tools.IncrementalUtility; @@ -30,26 +28,7 @@ public void Load() { XxHash3 hash = new(); - using FileStream file = new(path, FileMode.Open, FileAccess.Read); - PipeReader pipe = PipeReader.Create(file); - - while (true) - { - if (!pipe.TryRead(out ReadResult result)) - { - break; - } - - ReadOnlySequence buffer = result.Buffer; - SequenceReader reader = new(buffer); - - // read line by line, because that guarantees that the returned sequence is in one piece. - // if we called .FirstSpan on the buffer we might risk missing data for large files - while (reader.TryReadTo(out ReadOnlySequence sequence, 0x0a)) - { - hash.Append(sequence.FirstSpan); - } - } + hash.Append(File.ReadAllBytes(path)); this.Hash = hash.GetCurrentHashAsUInt64(); } diff --git a/tools/Tools.IncrementalUtility/Tools.IncrementalUtility.csproj b/tools/Tools.IncrementalUtility/Tools.IncrementalUtility.csproj index f34ee93ec2..d4d2653612 100644 --- a/tools/Tools.IncrementalUtility/Tools.IncrementalUtility.csproj +++ b/tools/Tools.IncrementalUtility/Tools.IncrementalUtility.csproj @@ -1,16 +1,16 @@  + 0.1.0 true - - + From 0513fd40e6493159039b35da8566ddf025272cb6 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sat, 5 Aug 2023 12:55:44 +0200 Subject: [PATCH 066/323] delete a potential change tracking file on rebuild when rebuilding a tool, chances are the tracking file will be invalid anyways because we made changes to how the tool works --- script-functions.ps1 | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/script-functions.ps1 b/script-functions.ps1 index 301122d285..7c0547f62c 100644 --- a/script-functions.ps1 +++ b/script-functions.ps1 @@ -446,7 +446,7 @@ function Build-Tool { } } - if($IsWindows) { + if ($IsWindows) { Copy-Item -Path "$PSScriptRoot/tools/artifacts/publish/$CSProjectName/release/$CSProjectName.exe" ` -Destination "$PSScriptRoot/tools/bin/$OutputName.exe" } @@ -459,6 +459,10 @@ function Build-Tool { end { Write-Debug "The tool $OutputName was successfully built from $CSProjectName." Write-Verbose "Successfully built tool $OutputName." + + if (Test-Path "$PSScriptRoot/artifacts/hashes/$OutputName.json") { + Remove-Item -Path "$PSScriptRoot/artifacts/hashes/$OutputName.json" + } } } From a1af0e76299be155e393d85ca8248d137f07a7b3 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sat, 5 Aug 2023 12:56:10 +0200 Subject: [PATCH 067/323] codify newline requirements into the editorconfig --- .editorconfig | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.editorconfig b/.editorconfig index b292ee2172..97ee1117f7 100644 --- a/.editorconfig +++ b/.editorconfig @@ -45,6 +45,10 @@ csharp_using_directive_placement = outside_namespace:error # Using directive is unnecessary. dotnet_diagnostic.IDE0005.severity = error +# don't do double newlines or pointless newlines +dotnet_diagnostic.IDE2000.severity = error +dotnet_diagnostic.IDE2002.severity = error + # Yell at people when they don't include the file header template dotnet_diagnostic.IDE0073.severity = error From 174032040ec02155a3796b8c18ef7b115b113bd9 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sat, 5 Aug 2023 12:56:46 +0200 Subject: [PATCH 068/323] generate-concrete-objects tool --- DSharpPlus.sln | 2 +- Directory.Packages.props | 1 + .../Emitter.cs | 49 +++ .../Extractor.cs | 62 +++ .../Program.cs | 392 +++++++++++++++++- ....Generators.GenerateConcreteObjects.csproj | 11 + 6 files changed, 515 insertions(+), 2 deletions(-) create mode 100644 tools/generators/Tools.Generators.GenerateConcreteObjects/Emitter.cs create mode 100644 tools/generators/Tools.Generators.GenerateConcreteObjects/Extractor.cs diff --git a/DSharpPlus.sln b/DSharpPlus.sln index 755a009d35..2ff9e4c19f 100644 --- a/DSharpPlus.sln +++ b/DSharpPlus.sln @@ -28,7 +28,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DSharpPlus.Shared.Tests", " EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Generators", "Generators", "{5FBB4590-56B0-453B-A87B-08A17C599B5C}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DSharpPlus.SourceGenerators.Common", "gen\common\DSharpPlus.SourceGenerators.Common.csproj", "{98D2C52C-E3BA-4564-919C-750775B7BA9C}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DSharpPlus.SourceGenerators.Common", "gen\common\DSharpPlus.SourceGenerators.Common.csproj", "{98D2C52C-E3BA-4564-919C-750775B7BA9C}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/Directory.Packages.props b/Directory.Packages.props index ee2aa01ff5..638ed34b04 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -11,6 +11,7 @@ + diff --git a/tools/generators/Tools.Generators.GenerateConcreteObjects/Emitter.cs b/tools/generators/Tools.Generators.GenerateConcreteObjects/Emitter.cs new file mode 100644 index 0000000000..86ada480ac --- /dev/null +++ b/tools/generators/Tools.Generators.GenerateConcreteObjects/Emitter.cs @@ -0,0 +1,49 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; + +namespace Tools.Generators.GenerateConcreteObjects; + +public static class Emitter +{ + public static void Emit + ( + StreamWriter writer, + IReadOnlyList<(string, string)> properties, + IReadOnlyList? overwrites = null + ) + { + foreach((string, string) property in properties) + { + bool required = false; + + string type = property.Item1; + + if (!type.StartsWith("Optional") && !type.EndsWith("?")) + { + required = true; + } + + if (overwrites is not null && overwrites.Contains(property.Item2)) + { + type = type.EndsWith('?') ? $"{type[9..^2]}?" : type[9..^1]; + required = true; + } + + writer.Write + ( +$$""" + /// + public {{(required ? "required " : "")}}{{type}} {{property.Item2}} { get; init; } + + +""" + ); + } + } +} diff --git a/tools/generators/Tools.Generators.GenerateConcreteObjects/Extractor.cs b/tools/generators/Tools.Generators.GenerateConcreteObjects/Extractor.cs new file mode 100644 index 0000000000..c27d6377ef --- /dev/null +++ b/tools/generators/Tools.Generators.GenerateConcreteObjects/Extractor.cs @@ -0,0 +1,62 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; +using System.Linq; + +using Microsoft.CodeAnalysis.CSharp; +using Microsoft.CodeAnalysis.CSharp.Syntax; + +namespace Tools.Generators.GenerateConcreteObjects; + +/// +/// Provides a method to extract data from an interface declaration syntax +/// +internal static class Extractor +{ + public static IReadOnlyList<(string, string)> ExtractDefault + ( + InterfaceDeclarationSyntax declaration + ) + { + List<(string, string)> properties = new(); + + foreach (MemberDeclarationSyntax member in declaration.Members) + { + if (member is not PropertyDeclarationSyntax property) + { + continue; + } + + properties.Add((property.Type.ToString(), property.Identifier.ToString())); + } + + return properties; + } + + public static IReadOnlyList ExtractOverwrites + ( + InterfaceDeclarationSyntax declaration + ) + { + List overwrites = new(); + + foreach (MemberDeclarationSyntax member in declaration.Members) + { + if (member is not PropertyDeclarationSyntax property) + { + continue; + } + + if (!property.ChildTokens().Any(token => token.RawKind == (int)SyntaxKind.NewKeyword)) + { + continue; + } + + overwrites.Add(property.Identifier.ToString()); + } + + return overwrites; + } +} diff --git a/tools/generators/Tools.Generators.GenerateConcreteObjects/Program.cs b/tools/generators/Tools.Generators.GenerateConcreteObjects/Program.cs index ba00a72c4b..3d1bed6762 100644 --- a/tools/generators/Tools.Generators.GenerateConcreteObjects/Program.cs +++ b/tools/generators/Tools.Generators.GenerateConcreteObjects/Program.cs @@ -2,4 +2,394 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -System.Console.WriteLine("Hello, World!"); +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.Linq; + +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp; +using Microsoft.CodeAnalysis.CSharp.Syntax; + +using Spectre.Console; + +using Tools.IncrementalUtility; + +namespace Tools.Generators.GenerateConcreteObjects; + +public static class Program +{ + // SYNTAX: + // generate-concrete-objects [abstraction path] [output path] + // it is important to pass the path to the abstraction ROOT, not to the directories containing + // the abstractions files directly + public static int Main(string[] args) + { + // primitive help command + if (args is ["-h" or "--help" or "-?"]) + { + AnsiConsole.MarkupLine + ( + """ + DSharpPlus Concrete API Object Generator, v0.1.0 + + [plum1]Usage: generate-concrete-objects path/to/abstractions/root output/path[/] + """ + ); + + return 0; + } + + string input, output; + + // there are no args passed, proceed with default args: + // args[0] = src/core/DSharpPlus.Core.Abstractions.Models + // args[1] = src/core/DSharpPlus.Core.Models + if (args.Length == 0) + { + input = "src/core/DSharpPlus.Core.Abstractions.Models"; + output = "src/core/DSharpPlus.Core.Models"; + } + // there are args passed, which override the given instructions + // validate the passed arguments are correct + else if (args.Any(path => !Directory.Exists(path))) + { + AnsiConsole.MarkupLine + ( + """ + [red]The paths provided could not be found on the file system.[/] + """ + ); + + return 1; + } + // all args are fine + else + { + input = args[0]; + output = args[1]; + } + + MetadataCollection collection = new("generate-concrete-objects"); + + string[] files = Directory.GetFiles(input, "I*.cs", SearchOption.AllDirectories); + + Changes changes = collection.CalculateDifferences(files); + + if (!changes.Added.Any() && !changes.Modified.Any() && !changes.Removed.Any()) + { + AnsiConsole.MarkupLine + ( + """ + [darkseagreen1_1]There were no changes to the interface definitions, exiting generator.[/] + """ + ); + + return 0; + } + else + { + AnsiConsole.MarkupLine + ( + $""" + {changes.Added.Count()} added, {changes.Modified.Count()} modified, {changes.Removed.Count()} removed. + Generating concrete objects... + """ + ); + } + + AnsiConsole.MarkupLine + ( + """ + Deleting counterparts to removed files... + """ + ); + + foreach (string path in changes.Removed) + { + string deletePath = string.Concat(output, path.AsSpan(input.Length)); + + AnsiConsole.MarkupLine + ( + $""" + Deleting '{deletePath.Replace('\\', '/')}' + """ + ); + + if (File.Exists(deletePath)) + { + File.Delete(deletePath); + } + } + + AnsiConsole.MarkupLine + ( + """ + Generating objects for modified/new definitions... + """ + ); + + IEnumerable added = changes.Added.Select + ( + file => + { + FileInfo info = new(file); + return info.FullName.Replace('\\', '/'); + } + ); + + IEnumerable modified = changes.Modified.Select + ( + file => + { + FileInfo info = new(file); + return info.FullName.Replace('\\', '/'); + } + ); + + List emittedFiles = new(); + + foreach (string path in added.Concat(modified)) + { + CompilationUnitSyntax root = SyntaxFactory.ParseCompilationUnit + ( + File.ReadAllText(path) + ); + + int index = path.LastIndexOf("/"); + string outPath = path.Remove(index + 1, 1).Replace(input, output); + + // ensure the directory at least exists + FileInfo outInfo = new(outPath); + if (!Directory.Exists(outInfo.DirectoryName!)) + { + Directory.CreateDirectory(outInfo.DirectoryName!); + } + + StreamWriter writer = File.Exists(outPath) + ? new(outPath) + : new(File.Create(outPath)); + + AnsiConsole.MarkupLine + ( + $""" + Generating {outPath} + """ + ); + + /*writer.WriteLine + ( +""" +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +""" + );*/ + + foreach (UsingDirectiveSyntax @using in root.Usings) + { + writer.Write(@using.ToFullString()); + } + + writer.Write + ( +""" + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + + +""" + ); + + if + ( + root.Members.First() is not FileScopedNamespaceDeclarationSyntax fileScopedNamespace || + fileScopedNamespace.Members.First() is not InterfaceDeclarationSyntax interfaceSyntax + ) + { + writer.Close(); + File.Delete(outPath); + AnsiConsole.MarkupLine + ( + $""" + No interface detected, abandoning generation. + """ + ); + + continue; + } + + IEnumerable tokens = interfaceSyntax.ChildTokens(); + SyntaxToken name = default; + bool found = false; + bool marker = false; + + foreach (SyntaxToken token in tokens) + { + if (token is { RawKind: (int)SyntaxKind.IdentifierToken }) + { + name = token; + found = true; + } + + // detect a marker + if (found && token is { RawKind: (int)SyntaxKind.SemicolonToken }) + { + AnsiConsole.MarkupLine + ( + $""" + Marker interface detected, abandoning generation. + """ + ); + marker = true; + } + } + + if (marker) + { + writer.Close(); + File.Delete(outPath); + continue; + } + + writer.WriteLine + ( +$$""" +/// +public sealed record {{name.Text[1..]}} : {{name.Text}} +{ +""" + ); + + BaseListSyntax? interfaceList = (BaseListSyntax?)interfaceSyntax.ChildNodes() + .FirstOrDefault + ( + node => node is BaseListSyntax + ); + + if (interfaceList is not null) + { + string? partialCandidate = interfaceList.ChildNodes() + .Where + ( + node => + { + if (node is not SimpleBaseTypeSyntax candidate) + { + return false; + } + + if (node.ChildNodes().First() is not IdentifierNameSyntax identifier) + { + return false; + } + + foreach (SyntaxToken token in identifier.ChildTokens()) + { + if (token is { RawKind: (int)SyntaxKind.IdentifierToken }) + { + if (token.Text.StartsWith("IPartial")) + { + return true; + } + } + } + + return false; + } + ) + .Select + ( + node => + { + foreach (SyntaxToken token in node.ChildNodes().First().ChildTokens()) + { + if (token is { RawKind: (int)SyntaxKind.IdentifierToken }) + { + if (token.Text.StartsWith("IPartial")) + { + return token.Text; + } + } + } + + // unreachable + return null!; + } + ) + .FirstOrDefault(); + + Console.WriteLine($" Partial candidate: {partialCandidate ?? "none"}"); + + if (partialCandidate is not null) + { + // we're dealing with a partial-extending here + string partialPath = path.Replace(interfaceSyntax.Identifier.Text, partialCandidate); + CompilationUnitSyntax partialRoot = SyntaxFactory.ParseCompilationUnit + ( + File.ReadAllText(partialPath) + ); + + if + ( + partialRoot.Members.First() is not FileScopedNamespaceDeclarationSyntax partialFileScopedNamespace || + partialFileScopedNamespace.Members.First() is not InterfaceDeclarationSyntax partialInterfaceSyntax + ) + { + writer.Close(); + File.Delete(outPath); + AnsiConsole.MarkupLine + ( + $""" + No partial base interface detected, abandoning generation. + """ + ); + + continue; + } + + Emitter.Emit + ( + writer, + Extractor.ExtractDefault(partialInterfaceSyntax), + Extractor.ExtractOverwrites(interfaceSyntax) + ); + } + else + { + Emitter.Emit + ( + writer, + Extractor.ExtractDefault(interfaceSyntax) + ); + } + } + else + { + Emitter.Emit + ( + writer, + Extractor.ExtractDefault(interfaceSyntax) + ); + } + + writer.Write("}"); + writer.Flush(); + writer.Dispose(); + + emittedFiles.Add(outPath); + } + + Process.Start("dotnet", $"format --no-restore --severity info --include { + string.Join(' ', emittedFiles.Select + ( + path => $".{path[Environment.CurrentDirectory.Length..]}" + ))}"); + + return 0; + } +} diff --git a/tools/generators/Tools.Generators.GenerateConcreteObjects/Tools.Generators.GenerateConcreteObjects.csproj b/tools/generators/Tools.Generators.GenerateConcreteObjects/Tools.Generators.GenerateConcreteObjects.csproj index 6a70a1ab38..65291d465f 100644 --- a/tools/generators/Tools.Generators.GenerateConcreteObjects/Tools.Generators.GenerateConcreteObjects.csproj +++ b/tools/generators/Tools.Generators.GenerateConcreteObjects/Tools.Generators.GenerateConcreteObjects.csproj @@ -1,7 +1,18 @@  + 0.1.0 Exe + + + + + + + + + + From d2edaeacbd3308deb28c6d1083b653424654f7d2 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sat, 5 Aug 2023 18:38:16 +0200 Subject: [PATCH 069/323] add package reference to abstractions --- src/core/DSharpPlus.Core.Models/DSharpPlus.Core.Models.csproj | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/core/DSharpPlus.Core.Models/DSharpPlus.Core.Models.csproj b/src/core/DSharpPlus.Core.Models/DSharpPlus.Core.Models.csproj index 9408be00b4..ac4bf37d14 100644 --- a/src/core/DSharpPlus.Core.Models/DSharpPlus.Core.Models.csproj +++ b/src/core/DSharpPlus.Core.Models/DSharpPlus.Core.Models.csproj @@ -6,4 +6,8 @@ Library + + + + From b4db96c5f7ae6c6c8e94b873b55730b787f694dc Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sat, 5 Aug 2023 20:01:13 +0200 Subject: [PATCH 070/323] pick a bone with windows on windows, removing the extra newline at the end has to be removing CRLF, not just LF. "If you truly want something to happen, you cannot wish for it. You must do it." --- .../Emitter.cs | 8 +-- .../Program.cs | 54 +++++++++---------- 2 files changed, 28 insertions(+), 34 deletions(-) diff --git a/tools/generators/Tools.Generators.GenerateConcreteObjects/Emitter.cs b/tools/generators/Tools.Generators.GenerateConcreteObjects/Emitter.cs index 86ada480ac..78829c96c7 100644 --- a/tools/generators/Tools.Generators.GenerateConcreteObjects/Emitter.cs +++ b/tools/generators/Tools.Generators.GenerateConcreteObjects/Emitter.cs @@ -4,8 +4,8 @@ using System; using System.Collections.Generic; -using System.IO; using System.Linq; +using System.Text; namespace Tools.Generators.GenerateConcreteObjects; @@ -13,12 +13,12 @@ public static class Emitter { public static void Emit ( - StreamWriter writer, + StringBuilder writer, IReadOnlyList<(string, string)> properties, IReadOnlyList? overwrites = null ) { - foreach((string, string) property in properties) + foreach ((string, string) property in properties) { bool required = false; @@ -35,7 +35,7 @@ public static void Emit required = true; } - writer.Write + writer.Append ( $$""" /// diff --git a/tools/generators/Tools.Generators.GenerateConcreteObjects/Program.cs b/tools/generators/Tools.Generators.GenerateConcreteObjects/Program.cs index 3d1bed6762..c2aad4295a 100644 --- a/tools/generators/Tools.Generators.GenerateConcreteObjects/Program.cs +++ b/tools/generators/Tools.Generators.GenerateConcreteObjects/Program.cs @@ -4,9 +4,9 @@ using System; using System.Collections.Generic; -using System.Diagnostics; using System.IO; using System.Linq; +using System.Text; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; @@ -160,16 +160,7 @@ Deleting counterparts to removed files... int index = path.LastIndexOf("/"); string outPath = path.Remove(index + 1, 1).Replace(input, output); - // ensure the directory at least exists - FileInfo outInfo = new(outPath); - if (!Directory.Exists(outInfo.DirectoryName!)) - { - Directory.CreateDirectory(outInfo.DirectoryName!); - } - - StreamWriter writer = File.Exists(outPath) - ? new(outPath) - : new(File.Create(outPath)); + StringBuilder writer = new(); AnsiConsole.MarkupLine ( @@ -190,10 +181,10 @@ Deleting counterparts to removed files... foreach (UsingDirectiveSyntax @using in root.Usings) { - writer.Write(@using.ToFullString()); + writer.Append(@using.ToFullString()); } - writer.Write + writer.Append ( """ @@ -205,14 +196,12 @@ namespace DSharpPlus.Core.Models; """ ); - if + if ( root.Members.First() is not FileScopedNamespaceDeclarationSyntax fileScopedNamespace || fileScopedNamespace.Members.First() is not InterfaceDeclarationSyntax interfaceSyntax ) { - writer.Close(); - File.Delete(outPath); AnsiConsole.MarkupLine ( $""" @@ -251,12 +240,10 @@ namespace DSharpPlus.Core.Models; if (marker) { - writer.Close(); - File.Delete(outPath); continue; } - writer.WriteLine + writer.AppendLine ( $$""" /// @@ -340,8 +327,6 @@ public sealed record {{name.Text[1..]}} : {{name.Text}} partialFileScopedNamespace.Members.First() is not InterfaceDeclarationSyntax partialInterfaceSyntax ) { - writer.Close(); - File.Delete(outPath); AnsiConsole.MarkupLine ( $""" @@ -377,19 +362,28 @@ public sealed record {{name.Text[1..]}} : {{name.Text}} ); } - writer.Write("}"); - writer.Flush(); - writer.Dispose(); + writer.Append('}'); + + // ensure the directory at least exists + FileInfo outInfo = new(outPath); + if (!Directory.Exists(outInfo.DirectoryName!)) + { + Directory.CreateDirectory(outInfo.DirectoryName!); + } + + string code = writer.ToString(); + + // remove the last newline before the final } + // the windows conditional is because of CRLF taking up two characters, vs LF taking up one + code = Environment.NewLine == "\r\n" + ? code.Remove(code.Length - 3, 2) + : code.Remove(code.Length - 2, 1); + + File.WriteAllText(outPath, code); emittedFiles.Add(outPath); } - Process.Start("dotnet", $"format --no-restore --severity info --include { - string.Join(' ', emittedFiles.Select - ( - path => $".{path[Environment.CurrentDirectory.Length..]}" - ))}"); - return 0; } } From 52b4b58e5581aaa49779f497db840291195af52a Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sat, 5 Aug 2023 20:02:49 +0200 Subject: [PATCH 071/323] the grand finale: all entities, status today --- .../ApplicationCommands/ApplicationCommand.cs | 56 +++++++ .../ApplicationCommandOption.cs | 61 ++++++++ .../ApplicationCommandOptionChoice.cs | 26 ++++ .../ApplicationCommandPermission.cs | 24 +++ .../ApplicationCommandPermissions.cs | 27 ++++ .../PartialApplicationCommandPermissions.cs | 27 ++++ .../Applications/Application.cs | 76 ++++++++++ .../Applications/InstallParameters.cs | 21 +++ .../Applications/PartialApplication.cs | 80 ++++++++++ .../AuditLogs/AuditLog.cs | 37 +++++ .../AuditLogs/AuditLogChange.cs | 22 +++ .../AuditLogs/AuditLogEntry.cs | 40 +++++ .../AuditLogs/AuditLogEntryInfo.cs | 46 ++++++ .../AutoModeration/AutoModerationAction.cs | 21 +++ .../AutoModeration/AutoModerationRule.cs | 50 ++++++ .../AutoModerationTriggerMetadata.cs | 35 +++++ .../BlockMessageActionMetadata.cs | 18 +++ .../PartialAutoModerationRule.cs | 50 ++++++ .../SendAlertMessageActionMetadata.cs | 18 +++ .../AutoModeration/TimeoutActionMetadata.cs | 16 ++ .../Channels/AllowedMentions.cs | 27 ++++ .../Channels/Attachment.cs | 49 ++++++ .../Channels/Channel.cs | 120 +++++++++++++++ .../Channels/ChannelMention.cs | 27 ++++ .../Channels/ChannelOverwrite.cs | 27 ++++ .../Channels/DefaultReaction.cs | 19 +++ .../DSharpPlus.Core.Models/Channels/Embed.cs | 55 +++++++ .../Channels/EmbedAuthor.cs | 25 +++ .../Channels/EmbedField.cs | 22 +++ .../Channels/EmbedFooter.cs | 22 +++ .../Channels/EmbedImage.cs | 25 +++ .../Channels/EmbedProvider.cs | 19 +++ .../Channels/EmbedThumbnail.cs | 25 +++ .../Channels/EmbedVideo.cs | 25 +++ .../Channels/FollowedChannel.cs | 19 +++ .../Channels/ForumTag.cs | 28 ++++ .../Channels/Message.cs | 108 +++++++++++++ .../Channels/MessageActivity.cs | 21 +++ .../Channels/MessageReference.cs | 25 +++ .../Channels/PartialAttachment.cs | 51 +++++++ .../Channels/PartialChannel.cs | 123 +++++++++++++++ .../Channels/PartialChannelOverwrite.cs | 27 ++++ .../Channels/PartialMessage.cs | 108 +++++++++++++ .../Channels/Reaction.cs | 17 +++ .../Channels/RoleSubscriptionData.cs | 25 +++ .../Channels/ThreadMember.cs | 30 ++++ .../Channels/ThreadMetadata.cs | 33 ++++ .../DSharpPlus.Core.Models/Emojis/Emoji.cs | 37 +++++ .../Emojis/PartialEmoji.cs | 39 +++++ .../GuildTemplates/Template.cs | 48 ++++++ src/core/DSharpPlus.Core.Models/Guilds/Ban.cs | 14 ++ .../DSharpPlus.Core.Models/Guilds/Guild.cs | 143 ++++++++++++++++++ .../Guilds/GuildMember.cs | 54 +++++++ .../Guilds/GuildPreview.cs | 48 ++++++ .../Guilds/GuildWidget.cs | 33 ++++ .../Guilds/GuildWidgetSettings.cs | 19 +++ .../Guilds/Integration.cs | 61 ++++++++ .../Guilds/IntegrationAccount.cs | 14 ++ .../Guilds/IntegrationApplication.cs | 28 ++++ .../Guilds/Onboarding.cs | 27 ++++ .../Guilds/OnboardingPrompt.cs | 38 +++++ .../Guilds/OnboardingPromptOption.cs | 33 ++++ .../Guilds/PartialGuild.cs | 143 ++++++++++++++++++ .../Guilds/PartialGuildMember.cs | 54 +++++++ .../Guilds/PartialIntegration.cs | 66 ++++++++ .../Guilds/PartialRole.cs | 48 ++++++ .../DSharpPlus.Core.Models/Guilds/Role.cs | 48 ++++++ .../DSharpPlus.Core.Models/Guilds/RoleTags.cs | 31 ++++ .../Guilds/WelcomeScreen.cs | 19 +++ .../Guilds/WelcomeScreenChannel.cs | 25 +++ .../ApplicationCommandInteractionData.cs | 38 +++++ ...ApplicationCommandInteractionDataOption.cs | 31 ++++ .../Interactions/AutocompleteCallbackData.cs | 16 ++ .../AutocompleteInteractionData.cs | 35 +++++ .../AutocompleteInteractionDataOption.cs | 16 ++ .../Interactions/Interaction.cs | 60 ++++++++ .../Interactions/InteractionResponse.cs | 21 +++ .../Interactions/MessageCallbackData.cs | 38 +++++ .../MessageComponentInteractionData.cs | 26 ++++ .../Interactions/MessageInteraction.cs | 30 ++++ .../Interactions/ModalCallbackData.cs | 22 +++ .../Interactions/ModalInteractionData.cs | 19 +++ .../Interactions/ResolvedData.cs | 33 ++++ .../DSharpPlus.Core.Models/Invites/Invite.cs | 61 ++++++++ .../Invites/PartialInvite.cs | 65 ++++++++ .../MessageComponents/ActionRowComponent.cs | 21 +++ .../MessageComponents/ButtonComponent.cs | 33 ++++ .../ChannelSelectComponent.cs | 35 +++++ .../MessageComponents/InteractiveComponent.cs | 16 ++ .../MentionableSelectComponent.cs | 28 ++++ .../MessageComponents/RoleSelectComponent.cs | 28 ++++ .../MessageComponents/SelectOption.cs | 28 ++++ .../StringSelectComponent.cs | 33 ++++ .../MessageComponents/TextInputComponent.cs | 39 +++++ .../MessageComponents/UserSelectComponent.cs | 28 ++++ .../RoleConnections/RoleConnectionMetadata.cs | 35 +++++ .../ScheduledEvents/PartialScheduledEvent.cs | 55 +++++++ .../ScheduledEvents/ScheduledEvent.cs | 56 +++++++ .../ScheduledEvents/ScheduledEventUser.cs | 22 +++ .../StageInstances/PartialStageInstance.cs | 33 ++++ .../StageInstances/StageInstance.cs | 32 ++++ .../Stickers/PartialSticker.cs | 48 ++++++ .../Stickers/Sticker.cs | 48 ++++++ .../Stickers/StickerItem.cs | 24 +++ .../Stickers/StickerPack.cs | 36 +++++ src/core/DSharpPlus.Core.Models/Teams/Team.cs | 30 ++++ .../Teams/TeamMember.cs | 29 ++++ .../Users/ApplicationRoleConnection.cs | 22 +++ .../Users/Connection.cs | 47 ++++++ .../Users/PartialUser.cs | 62 ++++++++ src/core/DSharpPlus.Core.Models/Users/User.cs | 61 ++++++++ .../Voice/VoiceRegion.cs | 23 +++ .../Voice/VoiceState.cs | 54 +++++++ .../Webhooks/PartialWebhook.cs | 51 +++++++ .../Webhooks/Webhook.cs | 51 +++++++ 115 files changed, 4542 insertions(+) create mode 100644 src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommand.cs create mode 100644 src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommandOption.cs create mode 100644 src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommandOptionChoice.cs create mode 100644 src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommandPermission.cs create mode 100644 src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommandPermissions.cs create mode 100644 src/core/DSharpPlus.Core.Models/ApplicationCommands/PartialApplicationCommandPermissions.cs create mode 100644 src/core/DSharpPlus.Core.Models/Applications/Application.cs create mode 100644 src/core/DSharpPlus.Core.Models/Applications/InstallParameters.cs create mode 100644 src/core/DSharpPlus.Core.Models/Applications/PartialApplication.cs create mode 100644 src/core/DSharpPlus.Core.Models/AuditLogs/AuditLog.cs create mode 100644 src/core/DSharpPlus.Core.Models/AuditLogs/AuditLogChange.cs create mode 100644 src/core/DSharpPlus.Core.Models/AuditLogs/AuditLogEntry.cs create mode 100644 src/core/DSharpPlus.Core.Models/AuditLogs/AuditLogEntryInfo.cs create mode 100644 src/core/DSharpPlus.Core.Models/AutoModeration/AutoModerationAction.cs create mode 100644 src/core/DSharpPlus.Core.Models/AutoModeration/AutoModerationRule.cs create mode 100644 src/core/DSharpPlus.Core.Models/AutoModeration/AutoModerationTriggerMetadata.cs create mode 100644 src/core/DSharpPlus.Core.Models/AutoModeration/BlockMessageActionMetadata.cs create mode 100644 src/core/DSharpPlus.Core.Models/AutoModeration/PartialAutoModerationRule.cs create mode 100644 src/core/DSharpPlus.Core.Models/AutoModeration/SendAlertMessageActionMetadata.cs create mode 100644 src/core/DSharpPlus.Core.Models/AutoModeration/TimeoutActionMetadata.cs create mode 100644 src/core/DSharpPlus.Core.Models/Channels/AllowedMentions.cs create mode 100644 src/core/DSharpPlus.Core.Models/Channels/Attachment.cs create mode 100644 src/core/DSharpPlus.Core.Models/Channels/Channel.cs create mode 100644 src/core/DSharpPlus.Core.Models/Channels/ChannelMention.cs create mode 100644 src/core/DSharpPlus.Core.Models/Channels/ChannelOverwrite.cs create mode 100644 src/core/DSharpPlus.Core.Models/Channels/DefaultReaction.cs create mode 100644 src/core/DSharpPlus.Core.Models/Channels/Embed.cs create mode 100644 src/core/DSharpPlus.Core.Models/Channels/EmbedAuthor.cs create mode 100644 src/core/DSharpPlus.Core.Models/Channels/EmbedField.cs create mode 100644 src/core/DSharpPlus.Core.Models/Channels/EmbedFooter.cs create mode 100644 src/core/DSharpPlus.Core.Models/Channels/EmbedImage.cs create mode 100644 src/core/DSharpPlus.Core.Models/Channels/EmbedProvider.cs create mode 100644 src/core/DSharpPlus.Core.Models/Channels/EmbedThumbnail.cs create mode 100644 src/core/DSharpPlus.Core.Models/Channels/EmbedVideo.cs create mode 100644 src/core/DSharpPlus.Core.Models/Channels/FollowedChannel.cs create mode 100644 src/core/DSharpPlus.Core.Models/Channels/ForumTag.cs create mode 100644 src/core/DSharpPlus.Core.Models/Channels/Message.cs create mode 100644 src/core/DSharpPlus.Core.Models/Channels/MessageActivity.cs create mode 100644 src/core/DSharpPlus.Core.Models/Channels/MessageReference.cs create mode 100644 src/core/DSharpPlus.Core.Models/Channels/PartialAttachment.cs create mode 100644 src/core/DSharpPlus.Core.Models/Channels/PartialChannel.cs create mode 100644 src/core/DSharpPlus.Core.Models/Channels/PartialChannelOverwrite.cs create mode 100644 src/core/DSharpPlus.Core.Models/Channels/PartialMessage.cs create mode 100644 src/core/DSharpPlus.Core.Models/Channels/Reaction.cs create mode 100644 src/core/DSharpPlus.Core.Models/Channels/RoleSubscriptionData.cs create mode 100644 src/core/DSharpPlus.Core.Models/Channels/ThreadMember.cs create mode 100644 src/core/DSharpPlus.Core.Models/Channels/ThreadMetadata.cs create mode 100644 src/core/DSharpPlus.Core.Models/Emojis/Emoji.cs create mode 100644 src/core/DSharpPlus.Core.Models/Emojis/PartialEmoji.cs create mode 100644 src/core/DSharpPlus.Core.Models/GuildTemplates/Template.cs create mode 100644 src/core/DSharpPlus.Core.Models/Guilds/Ban.cs create mode 100644 src/core/DSharpPlus.Core.Models/Guilds/Guild.cs create mode 100644 src/core/DSharpPlus.Core.Models/Guilds/GuildMember.cs create mode 100644 src/core/DSharpPlus.Core.Models/Guilds/GuildPreview.cs create mode 100644 src/core/DSharpPlus.Core.Models/Guilds/GuildWidget.cs create mode 100644 src/core/DSharpPlus.Core.Models/Guilds/GuildWidgetSettings.cs create mode 100644 src/core/DSharpPlus.Core.Models/Guilds/Integration.cs create mode 100644 src/core/DSharpPlus.Core.Models/Guilds/IntegrationAccount.cs create mode 100644 src/core/DSharpPlus.Core.Models/Guilds/IntegrationApplication.cs create mode 100644 src/core/DSharpPlus.Core.Models/Guilds/Onboarding.cs create mode 100644 src/core/DSharpPlus.Core.Models/Guilds/OnboardingPrompt.cs create mode 100644 src/core/DSharpPlus.Core.Models/Guilds/OnboardingPromptOption.cs create mode 100644 src/core/DSharpPlus.Core.Models/Guilds/PartialGuild.cs create mode 100644 src/core/DSharpPlus.Core.Models/Guilds/PartialGuildMember.cs create mode 100644 src/core/DSharpPlus.Core.Models/Guilds/PartialIntegration.cs create mode 100644 src/core/DSharpPlus.Core.Models/Guilds/PartialRole.cs create mode 100644 src/core/DSharpPlus.Core.Models/Guilds/Role.cs create mode 100644 src/core/DSharpPlus.Core.Models/Guilds/RoleTags.cs create mode 100644 src/core/DSharpPlus.Core.Models/Guilds/WelcomeScreen.cs create mode 100644 src/core/DSharpPlus.Core.Models/Guilds/WelcomeScreenChannel.cs create mode 100644 src/core/DSharpPlus.Core.Models/Interactions/ApplicationCommandInteractionData.cs create mode 100644 src/core/DSharpPlus.Core.Models/Interactions/ApplicationCommandInteractionDataOption.cs create mode 100644 src/core/DSharpPlus.Core.Models/Interactions/AutocompleteCallbackData.cs create mode 100644 src/core/DSharpPlus.Core.Models/Interactions/AutocompleteInteractionData.cs create mode 100644 src/core/DSharpPlus.Core.Models/Interactions/AutocompleteInteractionDataOption.cs create mode 100644 src/core/DSharpPlus.Core.Models/Interactions/Interaction.cs create mode 100644 src/core/DSharpPlus.Core.Models/Interactions/InteractionResponse.cs create mode 100644 src/core/DSharpPlus.Core.Models/Interactions/MessageCallbackData.cs create mode 100644 src/core/DSharpPlus.Core.Models/Interactions/MessageComponentInteractionData.cs create mode 100644 src/core/DSharpPlus.Core.Models/Interactions/MessageInteraction.cs create mode 100644 src/core/DSharpPlus.Core.Models/Interactions/ModalCallbackData.cs create mode 100644 src/core/DSharpPlus.Core.Models/Interactions/ModalInteractionData.cs create mode 100644 src/core/DSharpPlus.Core.Models/Interactions/ResolvedData.cs create mode 100644 src/core/DSharpPlus.Core.Models/Invites/Invite.cs create mode 100644 src/core/DSharpPlus.Core.Models/Invites/PartialInvite.cs create mode 100644 src/core/DSharpPlus.Core.Models/MessageComponents/ActionRowComponent.cs create mode 100644 src/core/DSharpPlus.Core.Models/MessageComponents/ButtonComponent.cs create mode 100644 src/core/DSharpPlus.Core.Models/MessageComponents/ChannelSelectComponent.cs create mode 100644 src/core/DSharpPlus.Core.Models/MessageComponents/InteractiveComponent.cs create mode 100644 src/core/DSharpPlus.Core.Models/MessageComponents/MentionableSelectComponent.cs create mode 100644 src/core/DSharpPlus.Core.Models/MessageComponents/RoleSelectComponent.cs create mode 100644 src/core/DSharpPlus.Core.Models/MessageComponents/SelectOption.cs create mode 100644 src/core/DSharpPlus.Core.Models/MessageComponents/StringSelectComponent.cs create mode 100644 src/core/DSharpPlus.Core.Models/MessageComponents/TextInputComponent.cs create mode 100644 src/core/DSharpPlus.Core.Models/MessageComponents/UserSelectComponent.cs create mode 100644 src/core/DSharpPlus.Core.Models/RoleConnections/RoleConnectionMetadata.cs create mode 100644 src/core/DSharpPlus.Core.Models/ScheduledEvents/PartialScheduledEvent.cs create mode 100644 src/core/DSharpPlus.Core.Models/ScheduledEvents/ScheduledEvent.cs create mode 100644 src/core/DSharpPlus.Core.Models/ScheduledEvents/ScheduledEventUser.cs create mode 100644 src/core/DSharpPlus.Core.Models/StageInstances/PartialStageInstance.cs create mode 100644 src/core/DSharpPlus.Core.Models/StageInstances/StageInstance.cs create mode 100644 src/core/DSharpPlus.Core.Models/Stickers/PartialSticker.cs create mode 100644 src/core/DSharpPlus.Core.Models/Stickers/Sticker.cs create mode 100644 src/core/DSharpPlus.Core.Models/Stickers/StickerItem.cs create mode 100644 src/core/DSharpPlus.Core.Models/Stickers/StickerPack.cs create mode 100644 src/core/DSharpPlus.Core.Models/Teams/Team.cs create mode 100644 src/core/DSharpPlus.Core.Models/Teams/TeamMember.cs create mode 100644 src/core/DSharpPlus.Core.Models/Users/ApplicationRoleConnection.cs create mode 100644 src/core/DSharpPlus.Core.Models/Users/Connection.cs create mode 100644 src/core/DSharpPlus.Core.Models/Users/PartialUser.cs create mode 100644 src/core/DSharpPlus.Core.Models/Users/User.cs create mode 100644 src/core/DSharpPlus.Core.Models/Voice/VoiceRegion.cs create mode 100644 src/core/DSharpPlus.Core.Models/Voice/VoiceState.cs create mode 100644 src/core/DSharpPlus.Core.Models/Webhooks/PartialWebhook.cs create mode 100644 src/core/DSharpPlus.Core.Models/Webhooks/Webhook.cs diff --git a/src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommand.cs b/src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommand.cs new file mode 100644 index 0000000000..029bef2ffa --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommand.cs @@ -0,0 +1,56 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Entities; + +using Remora.Rest.Core; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record ApplicationCommand : IApplicationCommand +{ + /// + public required Snowflake Id { get; init; } + + /// + public Optional Type { get; init; } + + /// + public required Snowflake ApplicationId { get; init; } + + /// + public Optional GuildId { get; init; } + + /// + public required string Name { get; init; } + + /// + public Optional?> NameLocalizations { get; init; } + + /// + public required string Description { get; init; } + + /// + public Optional?> DescriptionLocalizations { get; init; } + + /// + public Optional> Options { get; init; } + + /// + public DiscordPermissions? DefaultMemberPermissions { get; init; } + + /// + public Optional DmPermission { get; init; } + + /// + public Optional Nsfw { get; init; } + + /// + public required Snowflake Version { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommandOption.cs b/src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommandOption.cs new file mode 100644 index 0000000000..37bdf31919 --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommandOption.cs @@ -0,0 +1,61 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Entities; + +using OneOf; + +using Remora.Rest.Core; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record ApplicationCommandOption : IApplicationCommandOption +{ + /// + public required DiscordApplicationCommandOptionType Type { get; init; } + + /// + public required string Name { get; init; } + + /// + public Optional?> NameLocalizations { get; init; } + + /// + public required string Description { get; init; } + + /// + public Optional?> DescriptionLocalizations { get; init; } + + /// + public Optional Required { get; init; } + + /// + public Optional> Choices { get; init; } + + /// + public Optional> Options { get; init; } + + /// + public Optional> ChannelTypes { get; init; } + + /// + public Optional> MinValue { get; init; } + + /// + public Optional> MaxValue { get; init; } + + /// + public Optional MinLength { get; init; } + + /// + public Optional MaxLength { get; init; } + + /// + public Optional Autocomplete { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommandOptionChoice.cs b/src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommandOptionChoice.cs new file mode 100644 index 0000000000..3e4949a191 --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommandOptionChoice.cs @@ -0,0 +1,26 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using OneOf; + +using Remora.Rest.Core; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record ApplicationCommandOptionChoice : IApplicationCommandOptionChoice +{ + /// + public required string Name { get; init; } + + /// + public Optional?> NameLocalizations { get; init; } + + /// + public required OneOf Value { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommandPermission.cs b/src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommandPermission.cs new file mode 100644 index 0000000000..202320f918 --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommandPermission.cs @@ -0,0 +1,24 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Entities; + +using Remora.Rest.Core; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record ApplicationCommandPermission : IApplicationCommandPermission +{ + /// + public required Snowflake Id { get; init; } + + /// + public required DiscordApplicationCommandPermissionType Type { get; init; } + + /// + public required bool Permission { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommandPermissions.cs b/src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommandPermissions.cs new file mode 100644 index 0000000000..741e912e59 --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommandPermissions.cs @@ -0,0 +1,27 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using Remora.Rest.Core; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record ApplicationCommandPermissions : IApplicationCommandPermissions +{ + /// + public required Snowflake Id { get; init; } + + /// + public required Snowflake ApplicationId { get; init; } + + /// + public required Snowflake GuildId { get; init; } + + /// + public required IReadOnlyList Permissions { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/ApplicationCommands/PartialApplicationCommandPermissions.cs b/src/core/DSharpPlus.Core.Models/ApplicationCommands/PartialApplicationCommandPermissions.cs new file mode 100644 index 0000000000..b31912ad32 --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/ApplicationCommands/PartialApplicationCommandPermissions.cs @@ -0,0 +1,27 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using Remora.Rest.Core; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record PartialApplicationCommandPermissions : IPartialApplicationCommandPermissions +{ + /// + public Optional Id { get; init; } + + /// + public Optional ApplicationId { get; init; } + + /// + public Optional GuildId { get; init; } + + /// + public Optional> Permissions { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/Applications/Application.cs b/src/core/DSharpPlus.Core.Models/Applications/Application.cs new file mode 100644 index 0000000000..c7ac0a45b3 --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/Applications/Application.cs @@ -0,0 +1,76 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using Remora.Rest.Core; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record Application : IApplication +{ + /// + public required Snowflake Id { get; init; } + + /// + public required string Name { get; init; } + + /// + public required string? Icon { get; init; } + + /// + public Optional Description { get; init; } + + /// + public Optional> RpcOrigins { get; init; } + + /// + public required bool BotPublic { get; init; } + + /// + public required bool BotRequireCodeGrant { get; init; } + + /// + public Optional TermsOfServiceUrl { get; init; } + + /// + public Optional PrivacyPolicyUrl { get; init; } + + /// + public Optional Owner { get; init; } + + /// + public required string VerifyKey { get; init; } + + /// + public required ITeam? Team { get; init; } + + /// + public Optional GuildId { get; init; } + + /// + public Optional PrimarySkuId { get; init; } + + /// + public Optional Slug { get; init; } + + /// + public Optional CoverImage { get; init; } + + /// + public Optional Flags { get; init; } + + /// + public Optional> Tags { get; init; } + + /// + public Optional InstallParams { get; init; } + + /// + public Optional CustomInstallUrl { get; init; } + + /// + public Optional RoleConnectionsVerificationUrl { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/Applications/InstallParameters.cs b/src/core/DSharpPlus.Core.Models/Applications/InstallParameters.cs new file mode 100644 index 0000000000..5a3c749450 --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/Applications/InstallParameters.cs @@ -0,0 +1,21 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Entities; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record InstallParameters : IInstallParameters +{ + /// + public required IReadOnlyList Scopes { get; init; } + + /// + public required DiscordPermissions Permissions { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/Applications/PartialApplication.cs b/src/core/DSharpPlus.Core.Models/Applications/PartialApplication.cs new file mode 100644 index 0000000000..31da2904e6 --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/Applications/PartialApplication.cs @@ -0,0 +1,80 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Entities; + +using Remora.Rest.Core; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record PartialApplication : IPartialApplication +{ + /// + public Optional Id { get; init; } + + /// + public Optional Name { get; init; } + + /// + public Optional Icon { get; init; } + + /// + public Optional Description { get; init; } + + /// + public Optional> RpcOrigins { get; init; } + + /// + public Optional BotPublic { get; init; } + + /// + public Optional BotRequireCodeGrant { get; init; } + + /// + public Optional TermsOfServiceUrl { get; init; } + + /// + public Optional PrivacyPolicyUrl { get; init; } + + /// + public Optional Owner { get; init; } + + /// + public Optional VerifyKey { get; init; } + + /// + public Optional Team { get; init; } + + /// + public Optional GuildId { get; init; } + + /// + public Optional PrimarySkuId { get; init; } + + /// + public Optional Slug { get; init; } + + /// + public Optional CoverImage { get; init; } + + /// + public Optional Flags { get; init; } + + /// + public Optional> Tags { get; init; } + + /// + public Optional InstallParams { get; init; } + + /// + public Optional CustomInstallUrl { get; init; } + + /// + public Optional RoleConnectionsVerificationUrl { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/AuditLogs/AuditLog.cs b/src/core/DSharpPlus.Core.Models/AuditLogs/AuditLog.cs new file mode 100644 index 0000000000..66d207a78f --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/AuditLogs/AuditLog.cs @@ -0,0 +1,37 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record AuditLog : IAuditLog +{ + /// + public required IReadOnlyList ApplicationCommands { get; init; } + + /// + public required IReadOnlyList AuditLogEntries { get; init; } + + /// + public required IReadOnlyList AutoModerationRules { get; init; } + + /// + public required IReadOnlyList GuildScheduledEvents { get; init; } + + /// + public required IReadOnlyList Integrations { get; init; } + + /// + public required IReadOnlyList Threads { get; init; } + + /// + public required IReadOnlyList Users { get; init; } + + /// + public required IReadOnlyList Webhooks { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/AuditLogs/AuditLogChange.cs b/src/core/DSharpPlus.Core.Models/AuditLogs/AuditLogChange.cs new file mode 100644 index 0000000000..a2b1c1de3d --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/AuditLogs/AuditLogChange.cs @@ -0,0 +1,22 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Text.Json; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record AuditLogChange : IAuditLogChange +{ + /// + public required JsonElement NewValue { get; init; } + + /// + public required JsonElement OldValue { get; init; } + + /// + public required string Key { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/AuditLogs/AuditLogEntry.cs b/src/core/DSharpPlus.Core.Models/AuditLogs/AuditLogEntry.cs new file mode 100644 index 0000000000..15b68aec2e --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/AuditLogs/AuditLogEntry.cs @@ -0,0 +1,40 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Entities; + +using OneOf; + +using Remora.Rest.Core; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record AuditLogEntry : IAuditLogEntry +{ + /// + public OneOf? TargetId { get; init; } + + /// + public Optional> Changes { get; init; } + + /// + public Snowflake? UserId { get; init; } + + /// + public required Snowflake Id { get; init; } + + /// + public required DiscordAuditLogEvent ActionType { get; init; } + + /// + public Optional Options { get; init; } + + /// + public Optional Reason { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/AuditLogs/AuditLogEntryInfo.cs b/src/core/DSharpPlus.Core.Models/AuditLogs/AuditLogEntryInfo.cs new file mode 100644 index 0000000000..6bada1ff4a --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/AuditLogs/AuditLogEntryInfo.cs @@ -0,0 +1,46 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using Remora.Rest.Core; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record AuditLogEntryInfo : IAuditLogEntryInfo +{ + /// + public Optional ApplicationId { get; init; } + + /// + public Optional AutoModerationRuleName { get; init; } + + /// + public Optional AutoModerationRuleTriggerType { get; init; } + + /// + public Optional ChannelId { get; init; } + + /// + public Optional Count { get; init; } + + /// + public Optional DeleteMemberDays { get; init; } + + /// + public Optional Id { get; init; } + + /// + public Optional MembersRemoved { get; init; } + + /// + public Optional MessageId { get; init; } + + /// + public Optional RoleName { get; init; } + + /// + public Optional Type { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/AutoModeration/AutoModerationAction.cs b/src/core/DSharpPlus.Core.Models/AutoModeration/AutoModerationAction.cs new file mode 100644 index 0000000000..28f154bbee --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/AutoModeration/AutoModerationAction.cs @@ -0,0 +1,21 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Entities; + +using Remora.Rest.Core; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record AutoModerationAction : IAutoModerationAction +{ + /// + public required DiscordAutoModerationActionType Type { get; init; } + + /// + public Optional Metadata { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/AutoModeration/AutoModerationRule.cs b/src/core/DSharpPlus.Core.Models/AutoModeration/AutoModerationRule.cs new file mode 100644 index 0000000000..0753b48ae8 --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/AutoModeration/AutoModerationRule.cs @@ -0,0 +1,50 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Entities; + +using Remora.Rest.Core; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record AutoModerationRule : IAutoModerationRule +{ + /// + public required Snowflake Id { get; init; } + + /// + public required Snowflake GuildId { get; init; } + + /// + public required string Name { get; init; } + + /// + public required Snowflake CreatorId { get; init; } + + /// + public required DiscordAutoModerationEventType EventType { get; init; } + + /// + public required DiscordAutoModerationTriggerType TriggerType { get; init; } + + /// + public required IAutoModerationTriggerMetadata TriggerMetadata { get; init; } + + /// + public required IReadOnlyList Actions { get; init; } + + /// + public required bool Enabled { get; init; } + + /// + public required IReadOnlyList ExemptRoles { get; init; } + + /// + public required IReadOnlyList ExemptChannels { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/AutoModeration/AutoModerationTriggerMetadata.cs b/src/core/DSharpPlus.Core.Models/AutoModeration/AutoModerationTriggerMetadata.cs new file mode 100644 index 0000000000..42091ead2d --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/AutoModeration/AutoModerationTriggerMetadata.cs @@ -0,0 +1,35 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Entities; + +using Remora.Rest.Core; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record AutoModerationTriggerMetadata : IAutoModerationTriggerMetadata +{ + /// + public Optional> KeywordFilter { get; init; } + + /// + public Optional> RegexPatterns { get; init; } + + /// + public Optional> Presets { get; init; } + + /// + public Optional> AllowList { get; init; } + + /// + public Optional MentionTotalLimit { get; init; } + + /// + public Optional MentionRaidProtectionEnabled { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/AutoModeration/BlockMessageActionMetadata.cs b/src/core/DSharpPlus.Core.Models/AutoModeration/BlockMessageActionMetadata.cs new file mode 100644 index 0000000000..233718f266 --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/AutoModeration/BlockMessageActionMetadata.cs @@ -0,0 +1,18 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Entities; + +using Remora.Rest.Core; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record BlockMessageActionMetadata : IBlockMessageActionMetadata +{ + /// + public Optional CustomMessage { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/AutoModeration/PartialAutoModerationRule.cs b/src/core/DSharpPlus.Core.Models/AutoModeration/PartialAutoModerationRule.cs new file mode 100644 index 0000000000..ab5fec2dc6 --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/AutoModeration/PartialAutoModerationRule.cs @@ -0,0 +1,50 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Entities; + +using Remora.Rest.Core; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record PartialAutoModerationRule : IPartialAutoModerationRule +{ + /// + public Optional Id { get; init; } + + /// + public Optional GuildId { get; init; } + + /// + public Optional Name { get; init; } + + /// + public Optional CreatorId { get; init; } + + /// + public Optional EventType { get; init; } + + /// + public Optional TriggerType { get; init; } + + /// + public Optional TriggerMetadata { get; init; } + + /// + public Optional> Actions { get; init; } + + /// + public Optional Enabled { get; init; } + + /// + public Optional> ExemptRoles { get; init; } + + /// + public Optional> ExemptChannels { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/AutoModeration/SendAlertMessageActionMetadata.cs b/src/core/DSharpPlus.Core.Models/AutoModeration/SendAlertMessageActionMetadata.cs new file mode 100644 index 0000000000..dc64b4655b --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/AutoModeration/SendAlertMessageActionMetadata.cs @@ -0,0 +1,18 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Entities; + +using Remora.Rest.Core; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record SendAlertMessageActionMetadata : ISendAlertMessageActionMetadata +{ + /// + public required Snowflake ChannelId { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/AutoModeration/TimeoutActionMetadata.cs b/src/core/DSharpPlus.Core.Models/AutoModeration/TimeoutActionMetadata.cs new file mode 100644 index 0000000000..83daac471f --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/AutoModeration/TimeoutActionMetadata.cs @@ -0,0 +1,16 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Entities; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record TimeoutActionMetadata : ITimeoutActionMetadata +{ + /// + public required int DurationSeconds { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/Channels/AllowedMentions.cs b/src/core/DSharpPlus.Core.Models/Channels/AllowedMentions.cs new file mode 100644 index 0000000000..2a4426f0ac --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/Channels/AllowedMentions.cs @@ -0,0 +1,27 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using Remora.Rest.Core; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record AllowedMentions : IAllowedMentions +{ + /// + public required IReadOnlyList Parse { get; init; } + + /// + public Optional> Roles { get; init; } + + /// + public Optional> Users { get; init; } + + /// + public Optional RepliedUser { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/Channels/Attachment.cs b/src/core/DSharpPlus.Core.Models/Channels/Attachment.cs new file mode 100644 index 0000000000..b326754371 --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/Channels/Attachment.cs @@ -0,0 +1,49 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using Remora.Rest.Core; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record Attachment : IAttachment +{ + /// + public required Snowflake Id { get; init; } + + /// + public required string Filename { get; init; } + + /// + public Optional Description { get; init; } + + /// + public Optional ContentType { get; init; } + + /// + public required int Size { get; init; } + + /// + public required string Url { get; init; } + + /// + public required string ProxyUrl { get; init; } + + /// + public Optional Height { get; init; } + + /// + public Optional Width { get; init; } + + /// + public Optional Ephemeral { get; init; } + + /// + public Optional DurationSecs { get; init; } + + /// + public Optional> Waveform { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/Channels/Channel.cs b/src/core/DSharpPlus.Core.Models/Channels/Channel.cs new file mode 100644 index 0000000000..60ee678bd6 --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/Channels/Channel.cs @@ -0,0 +1,120 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Entities; + +using Remora.Rest.Core; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record Channel : IChannel +{ + /// + public required Snowflake Id { get; init; } + + /// + public required DiscordChannelType Type { get; init; } + + /// + public Optional GuildId { get; init; } + + /// + public Optional Position { get; init; } + + /// + public Optional> PermissionOverwrites { get; init; } + + /// + public Optional Name { get; init; } + + /// + public Optional Topic { get; init; } + + /// + public Optional Nsfw { get; init; } + + /// + public Optional LastMessageId { get; init; } + + /// + public Optional Bitrate { get; init; } + + /// + public Optional UserLimit { get; init; } + + /// + public Optional RateLimitPerUser { get; init; } + + /// + public Optional> Recipients { get; init; } + + /// + public Optional Icon { get; init; } + + /// + public Optional OwnerId { get; init; } + + /// + public Optional ApplicationId { get; init; } + + /// + public Optional Managed { get; init; } + + /// + public Optional ParentId { get; init; } + + /// + public Optional LastPinTimestamp { get; init; } + + /// + public Optional RtcRegion { get; init; } + + /// + public Optional VideoQualityMode { get; init; } + + /// + public Optional MessageCount { get; init; } + + /// + public Optional MemberCount { get; init; } + + /// + public Optional ThreadMetadata { get; init; } + + /// + public Optional Member { get; init; } + + /// + public Optional DefaultAutoArchiveDuration { get; init; } + + /// + public Optional Permissions { get; init; } + + /// + public Optional Flags { get; init; } + + /// + public Optional TotalMessageSent { get; init; } + + /// + public Optional> AvailableTags { get; init; } + + /// + public Optional> AppliedTags { get; init; } + + /// + public Optional DefaultReactionEmoji { get; init; } + + /// + public Optional DefaultThreadRateLimitPerUser { get; init; } + + /// + public Optional DefaultSortOrder { get; init; } + + /// + public Optional DefaultForumLayout { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/Channels/ChannelMention.cs b/src/core/DSharpPlus.Core.Models/Channels/ChannelMention.cs new file mode 100644 index 0000000000..f76cb15ca6 --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/Channels/ChannelMention.cs @@ -0,0 +1,27 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Entities; + +using Remora.Rest.Core; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record ChannelMention : IChannelMention +{ + /// + public required Snowflake Id { get; init; } + + /// + public required Snowflake GuildId { get; init; } + + /// + public required DiscordChannelType Type { get; init; } + + /// + public required string Name { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/Channels/ChannelOverwrite.cs b/src/core/DSharpPlus.Core.Models/Channels/ChannelOverwrite.cs new file mode 100644 index 0000000000..6db39029c0 --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/Channels/ChannelOverwrite.cs @@ -0,0 +1,27 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Entities; + +using Remora.Rest.Core; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record ChannelOverwrite : IChannelOverwrite +{ + /// + public required Snowflake Id { get; init; } + + /// + public required DiscordChannelOverwriteType Type { get; init; } + + /// + public required DiscordPermissions Allow { get; init; } + + /// + public required DiscordPermissions Deny { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/Channels/DefaultReaction.cs b/src/core/DSharpPlus.Core.Models/Channels/DefaultReaction.cs new file mode 100644 index 0000000000..9bb3f40cc7 --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/Channels/DefaultReaction.cs @@ -0,0 +1,19 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using Remora.Rest.Core; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record DefaultReaction : IDefaultReaction +{ + /// + public Snowflake? EmojiId { get; init; } + + /// + public string? EmojiName { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/Channels/Embed.cs b/src/core/DSharpPlus.Core.Models/Channels/Embed.cs new file mode 100644 index 0000000000..08adc47ee0 --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/Channels/Embed.cs @@ -0,0 +1,55 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; +using System.Collections.Generic; + +using Remora.Rest.Core; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record Embed : IEmbed +{ + /// + public Optional Title { get; init; } + + /// + public Optional Type { get; init; } + + /// + public Optional Description { get; init; } + + /// + public Optional Url { get; init; } + + /// + public Optional Timestamp { get; init; } + + /// + public Optional Color { get; init; } + + /// + public Optional Footer { get; init; } + + /// + public Optional Image { get; init; } + + /// + public Optional Thumbnail { get; init; } + + /// + public Optional Video { get; init; } + + /// + public Optional Provider { get; init; } + + /// + public Optional Author { get; init; } + + /// + public Optional> Fields { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/Channels/EmbedAuthor.cs b/src/core/DSharpPlus.Core.Models/Channels/EmbedAuthor.cs new file mode 100644 index 0000000000..6877059b30 --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/Channels/EmbedAuthor.cs @@ -0,0 +1,25 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using Remora.Rest.Core; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record EmbedAuthor : IEmbedAuthor +{ + /// + public required string Name { get; init; } + + /// + public Optional Url { get; init; } + + /// + public Optional IconUrl { get; init; } + + /// + public Optional ProxyIconUrl { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/Channels/EmbedField.cs b/src/core/DSharpPlus.Core.Models/Channels/EmbedField.cs new file mode 100644 index 0000000000..a9765807b2 --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/Channels/EmbedField.cs @@ -0,0 +1,22 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using Remora.Rest.Core; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record EmbedField : IEmbedField +{ + /// + public required string Name { get; init; } + + /// + public required string Value { get; init; } + + /// + public Optional Inline { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/Channels/EmbedFooter.cs b/src/core/DSharpPlus.Core.Models/Channels/EmbedFooter.cs new file mode 100644 index 0000000000..d526de5394 --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/Channels/EmbedFooter.cs @@ -0,0 +1,22 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using Remora.Rest.Core; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record EmbedFooter : IEmbedFooter +{ + /// + public required string Text { get; init; } + + /// + public Optional IconUrl { get; init; } + + /// + public Optional ProxyIconUrl { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/Channels/EmbedImage.cs b/src/core/DSharpPlus.Core.Models/Channels/EmbedImage.cs new file mode 100644 index 0000000000..83f118fa60 --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/Channels/EmbedImage.cs @@ -0,0 +1,25 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using Remora.Rest.Core; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record EmbedImage : IEmbedImage +{ + /// + public required string Url { get; init; } + + /// + public Optional ProxyUrl { get; init; } + + /// + public Optional Height { get; init; } + + /// + public Optional Width { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/Channels/EmbedProvider.cs b/src/core/DSharpPlus.Core.Models/Channels/EmbedProvider.cs new file mode 100644 index 0000000000..9596ffb0a9 --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/Channels/EmbedProvider.cs @@ -0,0 +1,19 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using Remora.Rest.Core; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record EmbedProvider : IEmbedProvider +{ + /// + public Optional Name { get; init; } + + /// + public Optional Url { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/Channels/EmbedThumbnail.cs b/src/core/DSharpPlus.Core.Models/Channels/EmbedThumbnail.cs new file mode 100644 index 0000000000..ebe009eeb1 --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/Channels/EmbedThumbnail.cs @@ -0,0 +1,25 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using Remora.Rest.Core; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record EmbedThumbnail : IEmbedThumbnail +{ + /// + public required string Url { get; init; } + + /// + public Optional ProxyUrl { get; init; } + + /// + public Optional Height { get; init; } + + /// + public Optional Width { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/Channels/EmbedVideo.cs b/src/core/DSharpPlus.Core.Models/Channels/EmbedVideo.cs new file mode 100644 index 0000000000..b614ca542b --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/Channels/EmbedVideo.cs @@ -0,0 +1,25 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using Remora.Rest.Core; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record EmbedVideo : IEmbedVideo +{ + /// + public Optional Url { get; init; } + + /// + public Optional ProxyUrl { get; init; } + + /// + public Optional Height { get; init; } + + /// + public Optional Width { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/Channels/FollowedChannel.cs b/src/core/DSharpPlus.Core.Models/Channels/FollowedChannel.cs new file mode 100644 index 0000000000..998f0a717c --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/Channels/FollowedChannel.cs @@ -0,0 +1,19 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using Remora.Rest.Core; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record FollowedChannel : IFollowedChannel +{ + /// + public required Snowflake ChannelId { get; init; } + + /// + public required Snowflake WebhookId { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/Channels/ForumTag.cs b/src/core/DSharpPlus.Core.Models/Channels/ForumTag.cs new file mode 100644 index 0000000000..c43364b8a3 --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/Channels/ForumTag.cs @@ -0,0 +1,28 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using Remora.Rest.Core; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record ForumTag : IForumTag +{ + /// + public required Snowflake Id { get; init; } + + /// + public required string Name { get; init; } + + /// + public required bool Moderated { get; init; } + + /// + public Snowflake? EmojiId { get; init; } + + /// + public string? EmojiName { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/Channels/Message.cs b/src/core/DSharpPlus.Core.Models/Channels/Message.cs new file mode 100644 index 0000000000..85af238df4 --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/Channels/Message.cs @@ -0,0 +1,108 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; +using System.Collections.Generic; + +using DSharpPlus.Entities; + +using Remora.Rest.Core; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record Message : IMessage +{ + /// + public required Snowflake Id { get; init; } + + /// + public required Snowflake ChannelId { get; init; } + + /// + public required IUser Author { get; init; } + + /// + public required string Content { get; init; } + + /// + public required DateTimeOffset Timestamp { get; init; } + + /// + public required DateTimeOffset? EditedTimestamp { get; init; } + + /// + public required bool Tts { get; init; } + + /// + public required bool MentionEveryone { get; init; } + + /// + public required IReadOnlyList Mentions { get; init; } + + /// + public required IReadOnlyList MentionRoles { get; init; } + + /// + public Optional> MentionChannels { get; init; } + + /// + public required IReadOnlyList Attachments { get; init; } + + /// + public required IReadOnlyList Embeds { get; init; } + + /// + public Optional> Reactions { get; init; } + + /// + public Optional Nonce { get; init; } + + /// + public required bool Pinned { get; init; } + + /// + public Optional WebhookId { get; init; } + + /// + public required DiscordMessageType Type { get; init; } + + /// + public Optional Activity { get; init; } + + /// + public Optional Application { get; init; } + + /// + public Optional ApplicationId { get; init; } + + /// + public Optional MessageReference { get; init; } + + /// + public Optional Flags { get; init; } + + /// + public Optional ReferencedMessage { get; init; } + + /// + public Optional Interaction { get; init; } + + /// + public Optional Thread { get; init; } + + /// + public Optional> Components { get; init; } + + /// + public Optional StickerItems { get; init; } + + /// + public Optional Position { get; init; } + + /// + public Optional RoleSubscriptionData { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/Channels/MessageActivity.cs b/src/core/DSharpPlus.Core.Models/Channels/MessageActivity.cs new file mode 100644 index 0000000000..f3ca1b0608 --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/Channels/MessageActivity.cs @@ -0,0 +1,21 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Entities; + +using Remora.Rest.Core; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record MessageActivity : IMessageActivity +{ + /// + public required DiscordMessageActivityType Type { get; init; } + + /// + public Optional PartyId { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/Channels/MessageReference.cs b/src/core/DSharpPlus.Core.Models/Channels/MessageReference.cs new file mode 100644 index 0000000000..0dd81b06c7 --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/Channels/MessageReference.cs @@ -0,0 +1,25 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using Remora.Rest.Core; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record MessageReference : IMessageReference +{ + /// + public Optional MessageId { get; init; } + + /// + public Optional ChannelId { get; init; } + + /// + public Optional GuildId { get; init; } + + /// + public Optional FailIfNotExists { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/Channels/PartialAttachment.cs b/src/core/DSharpPlus.Core.Models/Channels/PartialAttachment.cs new file mode 100644 index 0000000000..e65125e1ed --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/Channels/PartialAttachment.cs @@ -0,0 +1,51 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; + +using Remora.Rest.Core; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record PartialAttachment : IPartialAttachment +{ + /// + public Optional Id { get; init; } + + /// + public Optional Filename { get; init; } + + /// + public Optional Description { get; init; } + + /// + public Optional ContentType { get; init; } + + /// + public Optional Size { get; init; } + + /// + public Optional Url { get; init; } + + /// + public Optional ProxyUrl { get; init; } + + /// + public Optional Height { get; init; } + + /// + public Optional Width { get; init; } + + /// + public Optional Ephemeral { get; init; } + + /// + public Optional DurationSecs { get; init; } + + /// + public Optional> Waveform { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/Channels/PartialChannel.cs b/src/core/DSharpPlus.Core.Models/Channels/PartialChannel.cs new file mode 100644 index 0000000000..e5c81682b5 --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/Channels/PartialChannel.cs @@ -0,0 +1,123 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; +using System.Collections.Generic; + +using DSharpPlus.Entities; + +using Remora.Rest.Core; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record PartialChannel : IPartialChannel +{ + /// + public Optional Id { get; init; } + + /// + public Optional Type { get; init; } + + /// + public Optional GuildId { get; init; } + + /// + public Optional Position { get; init; } + + /// + public Optional> PermissionOverwrites { get; init; } + + /// + public Optional Name { get; init; } + + /// + public Optional Topic { get; init; } + + /// + public Optional Nsfw { get; init; } + + /// + public Optional LastMessageId { get; init; } + + /// + public Optional Bitrate { get; init; } + + /// + public Optional UserLimit { get; init; } + + /// + public Optional RateLimitPerUser { get; init; } + + /// + public Optional> Recipients { get; init; } + + /// + public Optional Icon { get; init; } + + /// + public Optional OwnerId { get; init; } + + /// + public Optional ApplicationId { get; init; } + + /// + public Optional Managed { get; init; } + + /// + public Optional ParentId { get; init; } + + /// + public Optional LastPinTimestamp { get; init; } + + /// + public Optional RtcRegion { get; init; } + + /// + public Optional VideoQualityMode { get; init; } + + /// + public Optional MessageCount { get; init; } + + /// + public Optional MemberCount { get; init; } + + /// + public Optional ThreadMetadata { get; init; } + + /// + public Optional Member { get; init; } + + /// + public Optional DefaultAutoArchiveDuration { get; init; } + + /// + public Optional Permissions { get; init; } + + /// + public Optional Flags { get; init; } + + /// + public Optional TotalMessageSent { get; init; } + + /// + public Optional> AvailableTags { get; init; } + + /// + public Optional> AppliedTags { get; init; } + + /// + public Optional DefaultReactionEmoji { get; init; } + + /// + public Optional DefaultThreadRateLimitPerUser { get; init; } + + /// + public Optional DefaultSortOrder { get; init; } + + /// + public Optional DefaultForumLayout { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/Channels/PartialChannelOverwrite.cs b/src/core/DSharpPlus.Core.Models/Channels/PartialChannelOverwrite.cs new file mode 100644 index 0000000000..ccc2892b10 --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/Channels/PartialChannelOverwrite.cs @@ -0,0 +1,27 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Entities; + +using Remora.Rest.Core; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record PartialChannelOverwrite : IPartialChannelOverwrite +{ + /// + public Optional Id { get; init; } + + /// + public Optional Type { get; init; } + + /// + public Optional Allow { get; init; } + + /// + public Optional Deny { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/Channels/PartialMessage.cs b/src/core/DSharpPlus.Core.Models/Channels/PartialMessage.cs new file mode 100644 index 0000000000..6dc583ddfa --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/Channels/PartialMessage.cs @@ -0,0 +1,108 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; +using System.Collections.Generic; + +using DSharpPlus.Entities; + +using Remora.Rest.Core; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record PartialMessage : IPartialMessage +{ + /// + public Optional Id { get; init; } + + /// + public Optional ChannelId { get; init; } + + /// + public Optional Author { get; init; } + + /// + public Optional Content { get; init; } + + /// + public Optional Timestamp { get; init; } + + /// + public Optional EditedTimestamp { get; init; } + + /// + public Optional Tts { get; init; } + + /// + public Optional MentionEveryone { get; init; } + + /// + public Optional> Mentions { get; init; } + + /// + public Optional> MentionRoles { get; init; } + + /// + public Optional> MentionChannels { get; init; } + + /// + public Optional> Attachments { get; init; } + + /// + public Optional> Embeds { get; init; } + + /// + public Optional> Reactions { get; init; } + + /// + public Optional Nonce { get; init; } + + /// + public Optional Pinned { get; init; } + + /// + public Optional WebhookId { get; init; } + + /// + public Optional Type { get; init; } + + /// + public Optional Activity { get; init; } + + /// + public Optional Application { get; init; } + + /// + public Optional ApplicationId { get; init; } + + /// + public Optional MessageReference { get; init; } + + /// + public Optional Flags { get; init; } + + /// + public Optional ReferencedMessage { get; init; } + + /// + public Optional Interaction { get; init; } + + /// + public Optional Thread { get; init; } + + /// + public Optional> Components { get; init; } + + /// + public Optional StickerItems { get; init; } + + /// + public Optional Position { get; init; } + + /// + public Optional RoleSubscriptionData { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/Channels/Reaction.cs b/src/core/DSharpPlus.Core.Models/Channels/Reaction.cs new file mode 100644 index 0000000000..7801178096 --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/Channels/Reaction.cs @@ -0,0 +1,17 @@ + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record Reaction : IReaction +{ + /// + public required int Count { get; init; } + + /// + public required bool Me { get; init; } + + /// + public required IPartialEmoji Emoji { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/Channels/RoleSubscriptionData.cs b/src/core/DSharpPlus.Core.Models/Channels/RoleSubscriptionData.cs new file mode 100644 index 0000000000..3f84822729 --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/Channels/RoleSubscriptionData.cs @@ -0,0 +1,25 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using Remora.Rest.Core; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record RoleSubscriptionData : IRoleSubscriptionData +{ + /// + public required Snowflake RoleSubscriptionListingId { get; init; } + + /// + public required string TierName { get; init; } + + /// + public required int TotalMonthsSubscribed { get; init; } + + /// + public required bool IsRenewal { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/Channels/ThreadMember.cs b/src/core/DSharpPlus.Core.Models/Channels/ThreadMember.cs new file mode 100644 index 0000000000..5b91c94f72 --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/Channels/ThreadMember.cs @@ -0,0 +1,30 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; + +using Remora.Rest.Core; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record ThreadMember : IThreadMember +{ + /// + public Optional Id { get; init; } + + /// + public Optional UserId { get; init; } + + /// + public required DateTimeOffset JoinTimestamp { get; init; } + + /// + public required int Flags { get; init; } + + /// + public Optional Member { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/Channels/ThreadMetadata.cs b/src/core/DSharpPlus.Core.Models/Channels/ThreadMetadata.cs new file mode 100644 index 0000000000..5447aef135 --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/Channels/ThreadMetadata.cs @@ -0,0 +1,33 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; + +using Remora.Rest.Core; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record ThreadMetadata : IThreadMetadata +{ + /// + public required bool Archived { get; init; } + + /// + public required int AutoArchiveDuration { get; init; } + + /// + public required DateTimeOffset ArchiveTimestamp { get; init; } + + /// + public required bool Locked { get; init; } + + /// + public Optional Invitable { get; init; } + + /// + public Optional CreateTimestamp { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/Emojis/Emoji.cs b/src/core/DSharpPlus.Core.Models/Emojis/Emoji.cs new file mode 100644 index 0000000000..30760612f6 --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/Emojis/Emoji.cs @@ -0,0 +1,37 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using Remora.Rest.Core; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record Emoji : IEmoji +{ + /// + public required Snowflake? Id { get; init; } + + /// + public required string? Name { get; init; } + + /// + public Optional> Roles { get; init; } + + /// + public Optional User { get; init; } + + /// + public Optional RequireColons { get; init; } + + /// + public Optional Managed { get; init; } + + /// + public Optional Animated { get; init; } + + /// + public Optional Available { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/Emojis/PartialEmoji.cs b/src/core/DSharpPlus.Core.Models/Emojis/PartialEmoji.cs new file mode 100644 index 0000000000..bc110d00ac --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/Emojis/PartialEmoji.cs @@ -0,0 +1,39 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using Remora.Rest.Core; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record PartialEmoji : IPartialEmoji +{ + /// + public Optional Id { get; init; } + + /// + public Optional Name { get; init; } + + /// + public Optional> Roles { get; init; } + + /// + public Optional User { get; init; } + + /// + public Optional RequireColons { get; init; } + + /// + public Optional Managed { get; init; } + + /// + public Optional Animated { get; init; } + + /// + public Optional Available { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/GuildTemplates/Template.cs b/src/core/DSharpPlus.Core.Models/GuildTemplates/Template.cs new file mode 100644 index 0000000000..1354066d7e --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/GuildTemplates/Template.cs @@ -0,0 +1,48 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; + +using Remora.Rest.Core; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record Template : ITemplate +{ + /// + public required string Code { get; init; } + + /// + public required string Name { get; init; } + + /// + public string? Description { get; init; } + + /// + public required int UsageCount { get; init; } + + /// + public required Snowflake CreatorId { get; init; } + + /// + public required IUser Creator { get; init; } + + /// + public required DateTimeOffset CreatedAt { get; init; } + + /// + public required DateTimeOffset UpdatedAt { get; init; } + + /// + public required Snowflake SourceGuildId { get; init; } + + /// + public required IPartialGuild SerializedSourceGuild { get; init; } + + /// + public bool? IsDirty { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/Guilds/Ban.cs b/src/core/DSharpPlus.Core.Models/Guilds/Ban.cs new file mode 100644 index 0000000000..be2077d9c1 --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/Guilds/Ban.cs @@ -0,0 +1,14 @@ + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record Ban : IBan +{ + /// + public string? Reason { get; init; } + + /// + public required IUser User { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/Guilds/Guild.cs b/src/core/DSharpPlus.Core.Models/Guilds/Guild.cs new file mode 100644 index 0000000000..eccf04b916 --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/Guilds/Guild.cs @@ -0,0 +1,143 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Entities; + +using Remora.Rest.Core; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record Guild : IGuild +{ + /// + public required Snowflake Id { get; init; } + + /// + public required string Name { get; init; } + + /// + public required string? Icon { get; init; } + + /// + public Optional IconHash { get; init; } + + /// + public required string? Splash { get; init; } + + /// + public required string? DiscoverySplash { get; init; } + + /// + public Optional Owner { get; init; } + + /// + public required Snowflake OwnerId { get; init; } + + /// + public Optional Permissions { get; init; } + + /// + public required Snowflake? AfkChannelId { get; init; } + + /// + public required int AfkTimeout { get; init; } + + /// + public Optional WidgetEnabled { get; init; } + + /// + public Optional WidgetChannelId { get; init; } + + /// + public required DiscordVerificationLevel VerificationLevel { get; init; } + + /// + public required DiscordMessageNotificationLevel DefaultMessageNotifications { get; init; } + + /// + public required DiscordExplicitContentFilterLevel ExplicitContentFilter { get; init; } + + /// + public required IReadOnlyList Roles { get; init; } + + /// + public required IReadOnlyList Emojis { get; init; } + + /// + public required IReadOnlyList Features { get; init; } + + /// + public required DiscordMfaLevel MfaLevel { get; init; } + + /// + public required Snowflake? ApplicationId { get; init; } + + /// + public required Snowflake? SystemChannelId { get; init; } + + /// + public required DiscordSystemChannelFlags SystemChannelFlags { get; init; } + + /// + public required Snowflake? RulesChannelId { get; init; } + + /// + public Optional MaxPresences { get; init; } + + /// + public Optional MaxMembers { get; init; } + + /// + public required string? VanityUrlCode { get; init; } + + /// + public required string? Description { get; init; } + + /// + public required string? Banner { get; init; } + + /// + public required int PremiumTier { get; init; } + + /// + public Optional PremiumSubscriptionCount { get; init; } + + /// + public required string PreferredLocale { get; init; } + + /// + public required Snowflake? PublicUpdatesChannelId { get; init; } + + /// + public Optional MaxVideoChannelUsers { get; init; } + + /// + public Optional MaxStageVideoChannelUsers { get; init; } + + /// + public Optional ApproximateMemberCount { get; init; } + + /// + public Optional ApproximatePresenceCount { get; init; } + + /// + public Optional WelcomeScreen { get; init; } + + /// + public required DiscordNsfwLevel NsfwLevel { get; init; } + + /// + public Optional> Stickers { get; init; } + + /// + public required bool PremiumProgressBarEnabled { get; init; } + + /// + public required Snowflake? SafetyAlertsChannelId { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/Guilds/GuildMember.cs b/src/core/DSharpPlus.Core.Models/Guilds/GuildMember.cs new file mode 100644 index 0000000000..395c7abfee --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/Guilds/GuildMember.cs @@ -0,0 +1,54 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; +using System.Collections.Generic; + +using DSharpPlus.Entities; + +using Remora.Rest.Core; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record GuildMember : IGuildMember +{ + /// + public Optional User { get; init; } + + /// + public Optional Nick { get; init; } + + /// + public Optional Avatar { get; init; } + + /// + public required IReadOnlyList Roles { get; init; } + + /// + public required DateTimeOffset JoinedAt { get; init; } + + /// + public Optional PremiumSince { get; init; } + + /// + public required bool Deaf { get; init; } + + /// + public required bool Mute { get; init; } + + /// + public required DiscordGuildMemberFlags Flags { get; init; } + + /// + public Optional Pending { get; init; } + + /// + public Optional Permissions { get; init; } + + /// + public Optional CommunicationDisabledUntil { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/Guilds/GuildPreview.cs b/src/core/DSharpPlus.Core.Models/Guilds/GuildPreview.cs new file mode 100644 index 0000000000..94a10010c3 --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/Guilds/GuildPreview.cs @@ -0,0 +1,48 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using Remora.Rest.Core; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record GuildPreview : IGuildPreview +{ + /// + public required Snowflake Id { get; init; } + + /// + public required string Name { get; init; } + + /// + public string? Icon { get; init; } + + /// + public string? Splash { get; init; } + + /// + public string? DiscoverySplash { get; init; } + + /// + public required IReadOnlyList Emojis { get; init; } + + /// + public required IReadOnlyList Features { get; init; } + + /// + public required int ApproximateMemberCount { get; init; } + + /// + public required int ApproximatePresenceCount { get; init; } + + /// + public string? Description { get; init; } + + /// + public required IReadOnlyList Stickers { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/Guilds/GuildWidget.cs b/src/core/DSharpPlus.Core.Models/Guilds/GuildWidget.cs new file mode 100644 index 0000000000..fa3c5fe0e8 --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/Guilds/GuildWidget.cs @@ -0,0 +1,33 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using Remora.Rest.Core; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record GuildWidget : IGuildWidget +{ + /// + public required Snowflake Id { get; init; } + + /// + public required string Name { get; init; } + + /// + public string? InstantInvite { get; init; } + + /// + public required IReadOnlyList Channels { get; init; } + + /// + public required IReadOnlyList Members { get; init; } + + /// + public required int PresenceCount { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/Guilds/GuildWidgetSettings.cs b/src/core/DSharpPlus.Core.Models/Guilds/GuildWidgetSettings.cs new file mode 100644 index 0000000000..d90548f0db --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/Guilds/GuildWidgetSettings.cs @@ -0,0 +1,19 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using Remora.Rest.Core; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record GuildWidgetSettings : IGuildWidgetSettings +{ + /// + public required bool Enabled { get; init; } + + /// + public Snowflake? ChannelId { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/Guilds/Integration.cs b/src/core/DSharpPlus.Core.Models/Guilds/Integration.cs new file mode 100644 index 0000000000..45fc42a203 --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/Guilds/Integration.cs @@ -0,0 +1,61 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using Remora.Rest.Core; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record Integration : IIntegration +{ + /// + public required Snowflake Id { get; init; } + + /// + public required string Name { get; init; } + + /// + public required string Type { get; init; } + + /// + public required bool Enabled { get; init; } + + /// + public Optional Syncing { get; init; } + + /// + public Optional RoleId { get; init; } + + /// + public Optional EnableEmoticons { get; init; } + + /// + public Optional ExpireBehaviour { get; init; } + + /// + public Optional ExpireGracePeriod { get; init; } + + /// + public Optional User { get; init; } + + /// + public required IIntegrationAccount Account { get; init; } + + /// + public Optional SyncedAt { get; init; } + + /// + public Optional SubscriberCount { get; init; } + + /// + public Optional Revoked { get; init; } + + /// + public Optional Application { get; init; } + + /// + public Optional> Scopes { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/Guilds/IntegrationAccount.cs b/src/core/DSharpPlus.Core.Models/Guilds/IntegrationAccount.cs new file mode 100644 index 0000000000..d102f4a521 --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/Guilds/IntegrationAccount.cs @@ -0,0 +1,14 @@ + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record IntegrationAccount : IIntegrationAccount +{ + /// + public required string Id { get; init; } + + /// + public required string Name { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/Guilds/IntegrationApplication.cs b/src/core/DSharpPlus.Core.Models/Guilds/IntegrationApplication.cs new file mode 100644 index 0000000000..cf03ea40eb --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/Guilds/IntegrationApplication.cs @@ -0,0 +1,28 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using Remora.Rest.Core; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record IntegrationApplication : IIntegrationApplication +{ + /// + public required Snowflake Id { get; init; } + + /// + public required string Name { get; init; } + + /// + public string? Icon { get; init; } + + /// + public required string Description { get; init; } + + /// + public Optional Bot { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/Guilds/Onboarding.cs b/src/core/DSharpPlus.Core.Models/Guilds/Onboarding.cs new file mode 100644 index 0000000000..691bae28f4 --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/Guilds/Onboarding.cs @@ -0,0 +1,27 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using Remora.Rest.Core; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record Onboarding : IOnboarding +{ + /// + public required Snowflake GuildId { get; init; } + + /// + public required IReadOnlyList Prompts { get; init; } + + /// + public required IReadOnlyList DefaultChannelIds { get; init; } + + /// + public required bool Enabled { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/Guilds/OnboardingPrompt.cs b/src/core/DSharpPlus.Core.Models/Guilds/OnboardingPrompt.cs new file mode 100644 index 0000000000..75c30610b9 --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/Guilds/OnboardingPrompt.cs @@ -0,0 +1,38 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Entities; + +using Remora.Rest.Core; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record OnboardingPrompt : IOnboardingPrompt +{ + /// + public required Snowflake Id { get; init; } + + /// + public required DiscordGuildOnboardingPromptType Type { get; init; } + + /// + public required IReadOnlyList Options { get; init; } + + /// + public required string Title { get; init; } + + /// + public required bool SingleSelect { get; init; } + + /// + public required bool Required { get; init; } + + /// + public required bool InOnboarding { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/Guilds/OnboardingPromptOption.cs b/src/core/DSharpPlus.Core.Models/Guilds/OnboardingPromptOption.cs new file mode 100644 index 0000000000..c3055ac3d1 --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/Guilds/OnboardingPromptOption.cs @@ -0,0 +1,33 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using Remora.Rest.Core; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record OnboardingPromptOption : IOnboardingPromptOption +{ + /// + public required Snowflake Id { get; init; } + + /// + public required IReadOnlyList ChannelIds { get; init; } + + /// + public required IReadOnlyList RoleIds { get; init; } + + /// + public required IEmoji Emoji { get; init; } + + /// + public required string Title { get; init; } + + /// + public string? Description { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/Guilds/PartialGuild.cs b/src/core/DSharpPlus.Core.Models/Guilds/PartialGuild.cs new file mode 100644 index 0000000000..31a612146e --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/Guilds/PartialGuild.cs @@ -0,0 +1,143 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Entities; + +using Remora.Rest.Core; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record PartialGuild : IPartialGuild +{ + /// + public Optional Id { get; init; } + + /// + public Optional Name { get; init; } + + /// + public Optional Icon { get; init; } + + /// + public Optional IconHash { get; init; } + + /// + public Optional Splash { get; init; } + + /// + public Optional DiscoverySplash { get; init; } + + /// + public Optional Owner { get; init; } + + /// + public Optional OwnerId { get; init; } + + /// + public Optional Permissions { get; init; } + + /// + public Optional AfkChannelId { get; init; } + + /// + public Optional AfkTimeout { get; init; } + + /// + public Optional WidgetEnabled { get; init; } + + /// + public Optional WidgetChannelId { get; init; } + + /// + public Optional VerificationLevel { get; init; } + + /// + public Optional DefaultMessageNotifications { get; init; } + + /// + public Optional ExplicitContentFilter { get; init; } + + /// + public Optional> Roles { get; init; } + + /// + public Optional> Emojis { get; init; } + + /// + public Optional> Features { get; init; } + + /// + public Optional MfaLevel { get; init; } + + /// + public Optional ApplicationId { get; init; } + + /// + public Optional SystemChannelId { get; init; } + + /// + public Optional SystemChannelFlags { get; init; } + + /// + public Optional RulesChannelId { get; init; } + + /// + public Optional MaxPresences { get; init; } + + /// + public Optional MaxMembers { get; init; } + + /// + public Optional VanityUrlCode { get; init; } + + /// + public Optional Description { get; init; } + + /// + public Optional Banner { get; init; } + + /// + public Optional PremiumTier { get; init; } + + /// + public Optional PremiumSubscriptionCount { get; init; } + + /// + public Optional PreferredLocale { get; init; } + + /// + public Optional PublicUpdatesChannelId { get; init; } + + /// + public Optional MaxVideoChannelUsers { get; init; } + + /// + public Optional MaxStageVideoChannelUsers { get; init; } + + /// + public Optional ApproximateMemberCount { get; init; } + + /// + public Optional ApproximatePresenceCount { get; init; } + + /// + public Optional WelcomeScreen { get; init; } + + /// + public Optional NsfwLevel { get; init; } + + /// + public Optional> Stickers { get; init; } + + /// + public Optional PremiumProgressBarEnabled { get; init; } + + /// + public Optional SafetyAlertsChannelId { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/Guilds/PartialGuildMember.cs b/src/core/DSharpPlus.Core.Models/Guilds/PartialGuildMember.cs new file mode 100644 index 0000000000..35a850a610 --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/Guilds/PartialGuildMember.cs @@ -0,0 +1,54 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; +using System.Collections.Generic; + +using DSharpPlus.Entities; + +using Remora.Rest.Core; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record PartialGuildMember : IPartialGuildMember +{ + /// + public Optional User { get; init; } + + /// + public Optional Nick { get; init; } + + /// + public Optional Avatar { get; init; } + + /// + public Optional> Roles { get; init; } + + /// + public Optional JoinedAt { get; init; } + + /// + public Optional PremiumSince { get; init; } + + /// + public Optional Deaf { get; init; } + + /// + public Optional Mute { get; init; } + + /// + public Optional Flags { get; init; } + + /// + public Optional Pending { get; init; } + + /// + public Optional Permissions { get; init; } + + /// + public Optional CommunicationDisabledUntil { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/Guilds/PartialIntegration.cs b/src/core/DSharpPlus.Core.Models/Guilds/PartialIntegration.cs new file mode 100644 index 0000000000..fcc4cafa91 --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/Guilds/PartialIntegration.cs @@ -0,0 +1,66 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; +using System.Collections.Generic; + +using DSharpPlus.Entities; + +using Remora.Rest.Core; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record PartialIntegration : IPartialIntegration +{ + /// + public Optional Id { get; init; } + + /// + public Optional Name { get; init; } + + /// + public Optional Type { get; init; } + + /// + public Optional Enabled { get; init; } + + /// + public Optional Syncing { get; init; } + + /// + public Optional RoleId { get; init; } + + /// + public Optional EnableEmoticons { get; init; } + + /// + public Optional ExpireBehaviour { get; init; } + + /// + public Optional ExpireGracePeriod { get; init; } + + /// + public Optional User { get; init; } + + /// + public Optional Account { get; init; } + + /// + public Optional SyncedAt { get; init; } + + /// + public Optional SubscriberCount { get; init; } + + /// + public Optional Revoked { get; init; } + + /// + public Optional Application { get; init; } + + /// + public Optional> Scopes { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/Guilds/PartialRole.cs b/src/core/DSharpPlus.Core.Models/Guilds/PartialRole.cs new file mode 100644 index 0000000000..530499f73c --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/Guilds/PartialRole.cs @@ -0,0 +1,48 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Entities; + +using Remora.Rest.Core; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record PartialRole : IPartialRole +{ + /// + public Optional Id { get; init; } + + /// + public Optional Name { get; init; } + + /// + public Optional Color { get; init; } + + /// + public Optional Hoist { get; init; } + + /// + public Optional Hash { get; init; } + + /// + public Optional UnicodeEmoji { get; init; } + + /// + public Optional Position { get; init; } + + /// + public Optional Permissions { get; init; } + + /// + public Optional Managed { get; init; } + + /// + public Optional Mentionable { get; init; } + + /// + public Optional Tags { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/Guilds/Role.cs b/src/core/DSharpPlus.Core.Models/Guilds/Role.cs new file mode 100644 index 0000000000..76c0ddbab1 --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/Guilds/Role.cs @@ -0,0 +1,48 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Entities; + +using Remora.Rest.Core; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record Role : IRole +{ + /// + public required Snowflake Id { get; init; } + + /// + public required string Name { get; init; } + + /// + public required int Color { get; init; } + + /// + public required bool Hoist { get; init; } + + /// + public Optional Hash { get; init; } + + /// + public Optional UnicodeEmoji { get; init; } + + /// + public required int Position { get; init; } + + /// + public required DiscordPermissions Permissions { get; init; } + + /// + public required bool Managed { get; init; } + + /// + public required bool Mentionable { get; init; } + + /// + public Optional Tags { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/Guilds/RoleTags.cs b/src/core/DSharpPlus.Core.Models/Guilds/RoleTags.cs new file mode 100644 index 0000000000..06d01b142b --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/Guilds/RoleTags.cs @@ -0,0 +1,31 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using Remora.Rest.Core; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record RoleTags : IRoleTags +{ + /// + public Optional BotId { get; init; } + + /// + public Optional IntegrationId { get; init; } + + /// + public required bool PremiumSubscriber { get; init; } + + /// + public Optional SubscriptionListingId { get; init; } + + /// + public required bool AvailableForPurchase { get; init; } + + /// + public required bool GuildConnections { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/Guilds/WelcomeScreen.cs b/src/core/DSharpPlus.Core.Models/Guilds/WelcomeScreen.cs new file mode 100644 index 0000000000..f60fcb346a --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/Guilds/WelcomeScreen.cs @@ -0,0 +1,19 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record WelcomeScreen : IWelcomeScreen +{ + /// + public string? Description { get; init; } + + /// + public required IReadOnlyList WelcomeChannels { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/Guilds/WelcomeScreenChannel.cs b/src/core/DSharpPlus.Core.Models/Guilds/WelcomeScreenChannel.cs new file mode 100644 index 0000000000..9cd1a33236 --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/Guilds/WelcomeScreenChannel.cs @@ -0,0 +1,25 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using Remora.Rest.Core; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record WelcomeScreenChannel : IWelcomeScreenChannel +{ + /// + public required Snowflake ChannelId { get; init; } + + /// + public required string Description { get; init; } + + /// + public Snowflake? EmojiId { get; init; } + + /// + public string? EmojiName { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/Interactions/ApplicationCommandInteractionData.cs b/src/core/DSharpPlus.Core.Models/Interactions/ApplicationCommandInteractionData.cs new file mode 100644 index 0000000000..2dd94fccf5 --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/Interactions/ApplicationCommandInteractionData.cs @@ -0,0 +1,38 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Entities; + +using Remora.Rest.Core; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record ApplicationCommandInteractionData : IApplicationCommandInteractionData +{ + /// + public required Snowflake Id { get; init; } + + /// + public required string Name { get; init; } + + /// + public required DiscordApplicationCommandType Type { get; init; } + + /// + public Optional Resolved { get; init; } + + /// + public Optional> Options { get; init; } + + /// + public Optional GuildId { get; init; } + + /// + public Optional TargetId { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/Interactions/ApplicationCommandInteractionDataOption.cs b/src/core/DSharpPlus.Core.Models/Interactions/ApplicationCommandInteractionDataOption.cs new file mode 100644 index 0000000000..b5282cc35b --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/Interactions/ApplicationCommandInteractionDataOption.cs @@ -0,0 +1,31 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Entities; + +using OneOf; + +using Remora.Rest.Core; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record ApplicationCommandInteractionDataOption : IApplicationCommandInteractionDataOption +{ + /// + public required string Name { get; init; } + + /// + public required DiscordApplicationCommandOptionType Type { get; init; } + + /// + public Optional> Value { get; init; } + + /// + public Optional> Options { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/Interactions/AutocompleteCallbackData.cs b/src/core/DSharpPlus.Core.Models/Interactions/AutocompleteCallbackData.cs new file mode 100644 index 0000000000..9c825386c6 --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/Interactions/AutocompleteCallbackData.cs @@ -0,0 +1,16 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record AutocompleteCallbackData : IAutocompleteCallbackData +{ + /// + public required IReadOnlyList Choices { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/Interactions/AutocompleteInteractionData.cs b/src/core/DSharpPlus.Core.Models/Interactions/AutocompleteInteractionData.cs new file mode 100644 index 0000000000..af22013362 --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/Interactions/AutocompleteInteractionData.cs @@ -0,0 +1,35 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Entities; + +using Remora.Rest.Core; + +using System.Collections.Generic; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record AutocompleteInteractionData : IAutocompleteInteractionData +{ + /// + public required Snowflake Id { get; init; } + + /// + public required string Name { get; init; } + + /// + public required DiscordApplicationCommandType Type { get; init; } + + /// + public Optional Resolved { get; init; } + + /// + public Optional> Options { get; init; } + + /// + public Optional GuildId { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/Interactions/AutocompleteInteractionDataOption.cs b/src/core/DSharpPlus.Core.Models/Interactions/AutocompleteInteractionDataOption.cs new file mode 100644 index 0000000000..a993616d5e --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/Interactions/AutocompleteInteractionDataOption.cs @@ -0,0 +1,16 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using Remora.Rest.Core; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record AutocompleteInteractionDataOption : IAutocompleteInteractionDataOption +{ + /// + public Optional Focused { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/Interactions/Interaction.cs b/src/core/DSharpPlus.Core.Models/Interactions/Interaction.cs new file mode 100644 index 0000000000..56f17fe5b7 --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/Interactions/Interaction.cs @@ -0,0 +1,60 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Entities; + +using Remora.Rest.Core; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record Interaction : IInteraction +{ + /// + public required Snowflake Id { get; init; } + + /// + public required Snowflake ApplicationId { get; init; } + + /// + public required DiscordInteractionType Type { get; init; } + + /// + public Optional Data { get; init; } + + /// + public Optional GuildId { get; init; } + + /// + public Optional Channel { get; init; } + + /// + public Optional ChannelId { get; init; } + + /// + public Optional Member { get; init; } + + /// + public Optional User { get; init; } + + /// + public required string Token { get; init; } + + /// + public required int Version { get; init; } + + /// + public Optional Message { get; init; } + + /// + public Optional AppPermissions { get; init; } + + /// + public Optional Locale { get; init; } + + /// + public Optional GuildLocale { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/Interactions/InteractionResponse.cs b/src/core/DSharpPlus.Core.Models/Interactions/InteractionResponse.cs new file mode 100644 index 0000000000..8575b0d28d --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/Interactions/InteractionResponse.cs @@ -0,0 +1,21 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Entities; + +using Remora.Rest.Core; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record InteractionResponse : IInteractionResponse +{ + /// + public required DiscordInteractionCallbackType Type { get; init; } + + /// + public Optional Data { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/Interactions/MessageCallbackData.cs b/src/core/DSharpPlus.Core.Models/Interactions/MessageCallbackData.cs new file mode 100644 index 0000000000..82fd583813 --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/Interactions/MessageCallbackData.cs @@ -0,0 +1,38 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Entities; + +using Remora.Rest.Core; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record MessageCallbackData : IMessageCallbackData +{ + /// + public Optional Tts { get; init; } + + /// + public Optional Content { get; init; } + + /// + public Optional> Embeds { get; init; } + + /// + public Optional AllowedMentions { get; init; } + + /// + public Optional Flags { get; init; } + + /// + public Optional> Components { get; init; } + + /// + public Optional> Attachments { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/Interactions/MessageComponentInteractionData.cs b/src/core/DSharpPlus.Core.Models/Interactions/MessageComponentInteractionData.cs new file mode 100644 index 0000000000..96f9208bb2 --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/Interactions/MessageComponentInteractionData.cs @@ -0,0 +1,26 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Entities; + +using Remora.Rest.Core; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record MessageComponentInteractionData : IMessageComponentInteractionData +{ + /// + public required string CustomId { get; init; } + + /// + public required DiscordMessageComponentType ComponentType { get; init; } + + /// + public Optional> Values { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/Interactions/MessageInteraction.cs b/src/core/DSharpPlus.Core.Models/Interactions/MessageInteraction.cs new file mode 100644 index 0000000000..421a523b9b --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/Interactions/MessageInteraction.cs @@ -0,0 +1,30 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Entities; + +using Remora.Rest.Core; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record MessageInteraction : IMessageInteraction +{ + /// + public required Snowflake Id { get; init; } + + /// + public required DiscordInteractionType Type { get; init; } + + /// + public required string Name { get; init; } + + /// + public required IUser User { get; init; } + + /// + public Optional Member { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/Interactions/ModalCallbackData.cs b/src/core/DSharpPlus.Core.Models/Interactions/ModalCallbackData.cs new file mode 100644 index 0000000000..f3624aa537 --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/Interactions/ModalCallbackData.cs @@ -0,0 +1,22 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record ModalCallbackData : IModalCallbackData +{ + /// + public required string CustomId { get; init; } + + /// + public required string Title { get; init; } + + /// + public required IReadOnlyList Components { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/Interactions/ModalInteractionData.cs b/src/core/DSharpPlus.Core.Models/Interactions/ModalInteractionData.cs new file mode 100644 index 0000000000..6095abdc12 --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/Interactions/ModalInteractionData.cs @@ -0,0 +1,19 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record ModalInteractionData : IModalInteractionData +{ + /// + public required string CustomId { get; init; } + + /// + public required IReadOnlyList Components { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/Interactions/ResolvedData.cs b/src/core/DSharpPlus.Core.Models/Interactions/ResolvedData.cs new file mode 100644 index 0000000000..ba856a6bf9 --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/Interactions/ResolvedData.cs @@ -0,0 +1,33 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using Remora.Rest.Core; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record ResolvedData : IResolvedData +{ + /// + public Optional> Users { get; init; } + + /// + public Optional> Members { get; init; } + + /// + public Optional> Roles { get; init; } + + /// + public Optional> Channels { get; init; } + + /// + public Optional> Messages { get; init; } + + /// + public Optional> Attachments { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/Invites/Invite.cs b/src/core/DSharpPlus.Core.Models/Invites/Invite.cs new file mode 100644 index 0000000000..cf48f0d1fc --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/Invites/Invite.cs @@ -0,0 +1,61 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using Remora.Rest.Core; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record Invite : IInvite +{ + /// + public required string Code { get; init; } + + /// + public Optional Guild { get; init; } + + /// + public required IPartialChannel? Channel { get; init; } + + /// + public Optional Inviter { get; init; } + + /// + public Optional TargetType { get; init; } + + /// + public Optional TargetUser { get; init; } + + /// + public Optional TargetApplication { get; init; } + + /// + public Optional ApproximatePresenceCount { get; init; } + + /// + public Optional ApproximateMemberCount { get; init; } + + /// + public Optional ExpiresAt { get; init; } + + /// + public Optional GuildScheduledEvent { get; init; } + + /// + public Optional Uses { get; init; } + + /// + public Optional MaxUses { get; init; } + + /// + public Optional MaxAge { get; init; } + + /// + public Optional Temporary { get; init; } + + /// + public Optional CreatedAt { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/Invites/PartialInvite.cs b/src/core/DSharpPlus.Core.Models/Invites/PartialInvite.cs new file mode 100644 index 0000000000..8aa0dceb34 --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/Invites/PartialInvite.cs @@ -0,0 +1,65 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; + +using DSharpPlus.Entities; + +using Remora.Rest.Core; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record PartialInvite : IPartialInvite +{ + /// + public Optional Code { get; init; } + + /// + public Optional Guild { get; init; } + + /// + public Optional Channel { get; init; } + + /// + public Optional Inviter { get; init; } + + /// + public Optional TargetType { get; init; } + + /// + public Optional TargetUser { get; init; } + + /// + public Optional TargetApplication { get; init; } + + /// + public Optional ApproximatePresenceCount { get; init; } + + /// + public Optional ApproximateMemberCount { get; init; } + + /// + public Optional ExpiresAt { get; init; } + + /// + public Optional GuildScheduledEvent { get; init; } + + /// + public Optional Uses { get; init; } + + /// + public Optional MaxUses { get; init; } + + /// + public Optional MaxAge { get; init; } + + /// + public Optional Temporary { get; init; } + + /// + public Optional CreatedAt { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/MessageComponents/ActionRowComponent.cs b/src/core/DSharpPlus.Core.Models/MessageComponents/ActionRowComponent.cs new file mode 100644 index 0000000000..0dcaa0a843 --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/MessageComponents/ActionRowComponent.cs @@ -0,0 +1,21 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Entities; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record ActionRowComponent : IActionRowComponent +{ + /// + public required DiscordMessageComponentType Type { get; init; } + + /// + public required IReadOnlyList Components { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/MessageComponents/ButtonComponent.cs b/src/core/DSharpPlus.Core.Models/MessageComponents/ButtonComponent.cs new file mode 100644 index 0000000000..f061b42780 --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/MessageComponents/ButtonComponent.cs @@ -0,0 +1,33 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Entities; + +using Remora.Rest.Core; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record ButtonComponent : IButtonComponent +{ + /// + public required DiscordButtonStyle Style { get; init; } + + /// + public Optional Label { get; init; } + + /// + public Optional Emoji { get; init; } + + /// + public Optional CustomId { get; init; } + + /// + public Optional Url { get; init; } + + /// + public Optional Disabled { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/MessageComponents/ChannelSelectComponent.cs b/src/core/DSharpPlus.Core.Models/MessageComponents/ChannelSelectComponent.cs new file mode 100644 index 0000000000..9e5c81e3b8 --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/MessageComponents/ChannelSelectComponent.cs @@ -0,0 +1,35 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Entities; + +using Remora.Rest.Core; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record ChannelSelectComponent : IChannelSelectComponent +{ + /// + public required string CustomId { get; init; } + + /// + public required IReadOnlyList ChannelTypes { get; init; } + + /// + public Optional Placeholder { get; init; } + + /// + public Optional MinValues { get; init; } + + /// + public Optional MaxValues { get; init; } + + /// + public Optional Disabled { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/MessageComponents/InteractiveComponent.cs b/src/core/DSharpPlus.Core.Models/MessageComponents/InteractiveComponent.cs new file mode 100644 index 0000000000..ae322b3d51 --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/MessageComponents/InteractiveComponent.cs @@ -0,0 +1,16 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Entities; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record InteractiveComponent : IInteractiveComponent +{ + /// + public required DiscordMessageComponentType Type { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/MessageComponents/MentionableSelectComponent.cs b/src/core/DSharpPlus.Core.Models/MessageComponents/MentionableSelectComponent.cs new file mode 100644 index 0000000000..11781c3990 --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/MessageComponents/MentionableSelectComponent.cs @@ -0,0 +1,28 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using Remora.Rest.Core; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record MentionableSelectComponent : IMentionableSelectComponent +{ + /// + public required string CustomId { get; init; } + + /// + public Optional Placeholder { get; init; } + + /// + public Optional MinValues { get; init; } + + /// + public Optional MaxValues { get; init; } + + /// + public Optional Disabled { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/MessageComponents/RoleSelectComponent.cs b/src/core/DSharpPlus.Core.Models/MessageComponents/RoleSelectComponent.cs new file mode 100644 index 0000000000..4f1ca413b4 --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/MessageComponents/RoleSelectComponent.cs @@ -0,0 +1,28 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using Remora.Rest.Core; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record RoleSelectComponent : IRoleSelectComponent +{ + /// + public required string CustomId { get; init; } + + /// + public Optional Placeholder { get; init; } + + /// + public Optional MinValues { get; init; } + + /// + public Optional MaxValues { get; init; } + + /// + public Optional Disabled { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/MessageComponents/SelectOption.cs b/src/core/DSharpPlus.Core.Models/MessageComponents/SelectOption.cs new file mode 100644 index 0000000000..4c2d46b891 --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/MessageComponents/SelectOption.cs @@ -0,0 +1,28 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using Remora.Rest.Core; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record SelectOption : ISelectOption +{ + /// + public required string Label { get; init; } + + /// + public required string Value { get; init; } + + /// + public Optional Description { get; init; } + + /// + public Optional Emoji { get; init; } + + /// + public Optional Default { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/MessageComponents/StringSelectComponent.cs b/src/core/DSharpPlus.Core.Models/MessageComponents/StringSelectComponent.cs new file mode 100644 index 0000000000..beedba4a20 --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/MessageComponents/StringSelectComponent.cs @@ -0,0 +1,33 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using Remora.Rest.Core; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record StringSelectComponent : IStringSelectComponent +{ + /// + public required string CustomId { get; init; } + + /// + public required IReadOnlyList Options { get; init; } + + /// + public Optional Placeholder { get; init; } + + /// + public Optional MinValues { get; init; } + + /// + public Optional MaxValues { get; init; } + + /// + public Optional Disabled { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/MessageComponents/TextInputComponent.cs b/src/core/DSharpPlus.Core.Models/MessageComponents/TextInputComponent.cs new file mode 100644 index 0000000000..cc3bedee2d --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/MessageComponents/TextInputComponent.cs @@ -0,0 +1,39 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Entities; + +using Remora.Rest.Core; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record TextInputComponent : ITextInputComponent +{ + /// + public required string CustomId { get; init; } + + /// + public required DiscordTextInputStyle Style { get; init; } + + /// + public required string Label { get; init; } + + /// + public Optional MinLength { get; init; } + + /// + public Optional MaxLength { get; init; } + + /// + public Optional Required { get; init; } + + /// + public Optional Value { get; init; } + + /// + public Optional Placeholder { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/MessageComponents/UserSelectComponent.cs b/src/core/DSharpPlus.Core.Models/MessageComponents/UserSelectComponent.cs new file mode 100644 index 0000000000..09206e6bbe --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/MessageComponents/UserSelectComponent.cs @@ -0,0 +1,28 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using Remora.Rest.Core; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record UserSelectComponent : IUserSelectComponent +{ + /// + public required string CustomId { get; init; } + + /// + public Optional Placeholder { get; init; } + + /// + public Optional MinValues { get; init; } + + /// + public Optional MaxValues { get; init; } + + /// + public Optional Disabled { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/RoleConnections/RoleConnectionMetadata.cs b/src/core/DSharpPlus.Core.Models/RoleConnections/RoleConnectionMetadata.cs new file mode 100644 index 0000000000..77dfb0f6e8 --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/RoleConnections/RoleConnectionMetadata.cs @@ -0,0 +1,35 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Entities; + +using Remora.Rest.Core; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record RoleConnectionMetadata : IRoleConnectionMetadata +{ + /// + public required DiscordRoleConnectionMetadataType Type { get; init; } + + /// + public required string Key { get; init; } + + /// + public required string Name { get; init; } + + /// + public Optional?> NameLocalizations { get; init; } + + /// + public required string Description { get; init; } + + /// + public Optional?> DescriptionLocalizations { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/ScheduledEvents/PartialScheduledEvent.cs b/src/core/DSharpPlus.Core.Models/ScheduledEvents/PartialScheduledEvent.cs new file mode 100644 index 0000000000..4504773bf4 --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/ScheduledEvents/PartialScheduledEvent.cs @@ -0,0 +1,55 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Entities; + +using Remora.Rest.Core; +using System; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record PartialScheduledEvent : IPartialScheduledEvent +{ + /// + public Optional Id { get; init; } + + /// + public Optional GuildId { get; init; } + + /// + public Optional ChannelId { get; init; } + + /// + public Optional CreatorId { get; init; } + + /// + public Optional Name { get; init; } + + /// + public Optional Description { get; init; } + + /// + public Optional ScheduledStartTime { get; init; } + + /// + public Optional PrivacyLevel { get; init; } + + /// + public Optional Status { get; init; } + + /// + public Optional EntityType { get; init; } + + /// + public Optional Creator { get; init; } + + /// + public Optional UserCount { get; init; } + + /// + public Optional Image { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/ScheduledEvents/ScheduledEvent.cs b/src/core/DSharpPlus.Core.Models/ScheduledEvents/ScheduledEvent.cs new file mode 100644 index 0000000000..96083d6e71 --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/ScheduledEvents/ScheduledEvent.cs @@ -0,0 +1,56 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; + +using DSharpPlus.Entities; + +using Remora.Rest.Core; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record ScheduledEvent : IScheduledEvent +{ + /// + public required Snowflake Id { get; init; } + + /// + public required Snowflake GuildId { get; init; } + + /// + public required Snowflake ChannelId { get; init; } + + /// + public Optional CreatorId { get; init; } + + /// + public required string Name { get; init; } + + /// + public Optional Description { get; init; } + + /// + public required DateTimeOffset ScheduledStartTime { get; init; } + + /// + public required DiscordScheduledEventPrivacyLevel PrivacyLevel { get; init; } + + /// + public required DiscordScheduledEventStatus Status { get; init; } + + /// + public required DiscordScheduledEventType EntityType { get; init; } + + /// + public Optional Creator { get; init; } + + /// + public Optional UserCount { get; init; } + + /// + public Optional Image { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/ScheduledEvents/ScheduledEventUser.cs b/src/core/DSharpPlus.Core.Models/ScheduledEvents/ScheduledEventUser.cs new file mode 100644 index 0000000000..ee2dff1986 --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/ScheduledEvents/ScheduledEventUser.cs @@ -0,0 +1,22 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using Remora.Rest.Core; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record ScheduledEventUser : IScheduledEventUser +{ + /// + public required Snowflake GuildScheduledEventId { get; init; } + + /// + public required IUser User { get; init; } + + /// + public Optional Member { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/StageInstances/PartialStageInstance.cs b/src/core/DSharpPlus.Core.Models/StageInstances/PartialStageInstance.cs new file mode 100644 index 0000000000..34545c5252 --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/StageInstances/PartialStageInstance.cs @@ -0,0 +1,33 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Entities; + +using Remora.Rest.Core; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record PartialStageInstance : IPartialStageInstance +{ + /// + public Optional Id { get; init; } + + /// + public Optional GuildId { get; init; } + + /// + public Optional ChannelId { get; init; } + + /// + public Optional Topic { get; init; } + + /// + public Optional PrivacyLevel { get; init; } + + /// + public Optional GuildScheduledEventId { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/StageInstances/StageInstance.cs b/src/core/DSharpPlus.Core.Models/StageInstances/StageInstance.cs new file mode 100644 index 0000000000..bdeb7c1de1 --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/StageInstances/StageInstance.cs @@ -0,0 +1,32 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Entities; +using Remora.Rest.Core; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record StageInstance : IStageInstance +{ + /// + public required Snowflake Id { get; init; } + + /// + public required Snowflake GuildId { get; init; } + + /// + public required Snowflake ChannelId { get; init; } + + /// + public required string Topic { get; init; } + + /// + public required DiscordStagePrivacyLevel PrivacyLevel { get; init; } + + /// + public required Snowflake? GuildScheduledEventId { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/Stickers/PartialSticker.cs b/src/core/DSharpPlus.Core.Models/Stickers/PartialSticker.cs new file mode 100644 index 0000000000..f8aac809fb --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/Stickers/PartialSticker.cs @@ -0,0 +1,48 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Entities; + +using Remora.Rest.Core; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record PartialSticker : IPartialSticker +{ + /// + public Optional Id { get; init; } + + /// + public Optional PackId { get; init; } + + /// + public Optional Name { get; init; } + + /// + public Optional Description { get; init; } + + /// + public Optional Tags { get; init; } + + /// + public Optional Type { get; init; } + + /// + public Optional FormatType { get; init; } + + /// + public Optional Available { get; init; } + + /// + public Optional GuildId { get; init; } + + /// + public Optional User { get; init; } + + /// + public Optional SortValue { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/Stickers/Sticker.cs b/src/core/DSharpPlus.Core.Models/Stickers/Sticker.cs new file mode 100644 index 0000000000..120ef599cb --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/Stickers/Sticker.cs @@ -0,0 +1,48 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Entities; + +using Remora.Rest.Core; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record Sticker : ISticker +{ + /// + public required Snowflake Id { get; init; } + + /// + public Optional PackId { get; init; } + + /// + public required string Name { get; init; } + + /// + public required string? Description { get; init; } + + /// + public required string Tags { get; init; } + + /// + public required DiscordStickerType Type { get; init; } + + /// + public required DiscordStickerFormatType FormatType { get; init; } + + /// + public Optional Available { get; init; } + + /// + public Optional GuildId { get; init; } + + /// + public Optional User { get; init; } + + /// + public Optional SortValue { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/Stickers/StickerItem.cs b/src/core/DSharpPlus.Core.Models/Stickers/StickerItem.cs new file mode 100644 index 0000000000..1c02604de5 --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/Stickers/StickerItem.cs @@ -0,0 +1,24 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Entities; + +using Remora.Rest.Core; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record StickerItem : IStickerItem +{ + /// + public required Snowflake Id { get; init; } + + /// + public required string Name { get; init; } + + /// + public required DiscordStickerFormatType FormatType { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/Stickers/StickerPack.cs b/src/core/DSharpPlus.Core.Models/Stickers/StickerPack.cs new file mode 100644 index 0000000000..d83f1c4b86 --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/Stickers/StickerPack.cs @@ -0,0 +1,36 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using Remora.Rest.Core; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record StickerPack : IStickerPack +{ + /// + public required Snowflake Id { get; init; } + + /// + public required IReadOnlyList Stickers { get; init; } + + /// + public required string Name { get; init; } + + /// + public required Snowflake SkuId { get; init; } + + /// + public Optional CoverStickerId { get; init; } + + /// + public required string Description { get; init; } + + /// + public Optional BannerAssetId { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/Teams/Team.cs b/src/core/DSharpPlus.Core.Models/Teams/Team.cs new file mode 100644 index 0000000000..4e22073993 --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/Teams/Team.cs @@ -0,0 +1,30 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using Remora.Rest.Core; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record Team : ITeam +{ + /// + public string? Icon { get; init; } + + /// + public required Snowflake Id { get; init; } + + /// + public required IReadOnlyList Members { get; init; } + + /// + public required string Name { get; init; } + + /// + public required Snowflake OwnerUserId { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/Teams/TeamMember.cs b/src/core/DSharpPlus.Core.Models/Teams/TeamMember.cs new file mode 100644 index 0000000000..c9bf06785c --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/Teams/TeamMember.cs @@ -0,0 +1,29 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Entities; + +using Remora.Rest.Core; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record TeamMember : ITeamMember +{ + /// + public required DiscordTeamMembershipState MembershipState { get; init; } + + /// + public required IReadOnlyList Permissions { get; init; } + + /// + public required Snowflake TeamId { get; init; } + + /// + public required IPartialUser User { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/Users/ApplicationRoleConnection.cs b/src/core/DSharpPlus.Core.Models/Users/ApplicationRoleConnection.cs new file mode 100644 index 0000000000..8676778956 --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/Users/ApplicationRoleConnection.cs @@ -0,0 +1,22 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record ApplicationRoleConnection : IApplicationRoleConnection +{ + /// + public string? PlatformName { get; init; } + + /// + public string? PlatformUsername { get; init; } + + /// + public required IReadOnlyDictionary Metadata { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/Users/Connection.cs b/src/core/DSharpPlus.Core.Models/Users/Connection.cs new file mode 100644 index 0000000000..93cf9d26f9 --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/Users/Connection.cs @@ -0,0 +1,47 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Entities; + +using Remora.Rest.Core; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record Connection : IConnection +{ + /// + public required string Id { get; init; } + + /// + public required string Name { get; init; } + + /// + public required string Type { get; init; } + + /// + public Optional Revoked { get; init; } + + /// + public Optional> Integrations { get; init; } + + /// + public required bool Verified { get; init; } + + /// + public required bool FriendSync { get; init; } + + /// + public required bool ShowActivity { get; init; } + + /// + public required bool TwoWayLink { get; init; } + + /// + public required DiscordConnectionVisibility Visibility { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/Users/PartialUser.cs b/src/core/DSharpPlus.Core.Models/Users/PartialUser.cs new file mode 100644 index 0000000000..aa95ea81fd --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/Users/PartialUser.cs @@ -0,0 +1,62 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Entities; +using Remora.Rest.Core; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record PartialUser : IPartialUser +{ + /// + public Optional Id { get; init; } + + /// + public Optional Username { get; init; } + + /// + public Optional Discriminator { get; init; } + + /// + public Optional GlobalName { get; init; } + + /// + public Optional Avatar { get; init; } + + /// + public Optional Bot { get; init; } + + /// + public Optional System { get; init; } + + /// + public Optional MfaEnabled { get; init; } + + /// + public Optional Banner { get; init; } + + /// + public Optional AccentColor { get; init; } + + /// + public Optional Locale { get; init; } + + /// + public Optional Verified { get; init; } + + /// + public Optional Email { get; init; } + + /// + public Optional Flags { get; init; } + + /// + public Optional PremiumType { get; init; } + + /// + public Optional PublicFlags { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/Users/User.cs b/src/core/DSharpPlus.Core.Models/Users/User.cs new file mode 100644 index 0000000000..0a0e7c108a --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/Users/User.cs @@ -0,0 +1,61 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using Remora.Rest.Core; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record User : IUser +{ + /// + public required Snowflake Id { get; init; } + + /// + public required string Username { get; init; } + + /// + public required string Discriminator { get; init; } + + /// + public required string? GlobalName { get; init; } + + /// + public required string? Avatar { get; init; } + + /// + public Optional Bot { get; init; } + + /// + public Optional System { get; init; } + + /// + public Optional MfaEnabled { get; init; } + + /// + public Optional Banner { get; init; } + + /// + public Optional AccentColor { get; init; } + + /// + public Optional Locale { get; init; } + + /// + public Optional Verified { get; init; } + + /// + public Optional Email { get; init; } + + /// + public Optional Flags { get; init; } + + /// + public Optional PremiumType { get; init; } + + /// + public Optional PublicFlags { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/Voice/VoiceRegion.cs b/src/core/DSharpPlus.Core.Models/Voice/VoiceRegion.cs new file mode 100644 index 0000000000..6fd9c671e0 --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/Voice/VoiceRegion.cs @@ -0,0 +1,23 @@ + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record VoiceRegion : IVoiceRegion +{ + /// + public required string Id { get; init; } + + /// + public required string Name { get; init; } + + /// + public required bool Optimal { get; init; } + + /// + public required bool Deprecated { get; init; } + + /// + public required bool Custom { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/Voice/VoiceState.cs b/src/core/DSharpPlus.Core.Models/Voice/VoiceState.cs new file mode 100644 index 0000000000..b66a70f416 --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/Voice/VoiceState.cs @@ -0,0 +1,54 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; + +using Remora.Rest.Core; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record VoiceState : IVoiceState +{ + /// + public Optional GuildId { get; init; } + + /// + public Snowflake? ChannelId { get; init; } + + /// + public required Snowflake UserId { get; init; } + + /// + public Optional Member { get; init; } + + /// + public required string SessionId { get; init; } + + /// + public required bool Deaf { get; init; } + + /// + public required bool Mute { get; init; } + + /// + public required bool SelfDeaf { get; init; } + + /// + public required bool SelfMute { get; init; } + + /// + public Optional SelfStream { get; init; } + + /// + public required bool SelfVideo { get; init; } + + /// + public required bool Suppress { get; init; } + + /// + public DateTimeOffset? RequestToSpeakTimestamp { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/Webhooks/PartialWebhook.cs b/src/core/DSharpPlus.Core.Models/Webhooks/PartialWebhook.cs new file mode 100644 index 0000000000..4c6d5558bb --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/Webhooks/PartialWebhook.cs @@ -0,0 +1,51 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Entities; + +using Remora.Rest.Core; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record PartialWebhook : IPartialWebhook +{ + /// + public Optional Id { get; init; } + + /// + public Optional Type { get; init; } + + /// + public Optional GuildId { get; init; } + + /// + public Optional ChannelId { get; init; } + + /// + public Optional User { get; init; } + + /// + public Optional Name { get; init; } + + /// + public Optional Avatar { get; init; } + + /// + public Optional Token { get; init; } + + /// + public Optional ApplicationId { get; init; } + + /// + public Optional SourceGuild { get; init; } + + /// + public Optional SourceChannel { get; init; } + + /// + public Optional Url { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/Webhooks/Webhook.cs b/src/core/DSharpPlus.Core.Models/Webhooks/Webhook.cs new file mode 100644 index 0000000000..f9cf3aea5f --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/Webhooks/Webhook.cs @@ -0,0 +1,51 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Entities; + +using Remora.Rest.Core; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record Webhook : IWebhook +{ + /// + public required Snowflake Id { get; init; } + + /// + public required DiscordWebhookType Type { get; init; } + + /// + public Optional GuildId { get; init; } + + /// + public required Snowflake? ChannelId { get; init; } + + /// + public Optional User { get; init; } + + /// + public required string? Name { get; init; } + + /// + public required string? Avatar { get; init; } + + /// + public Optional Token { get; init; } + + /// + public required Snowflake? ApplicationId { get; init; } + + /// + public Optional SourceGuild { get; init; } + + /// + public Optional SourceChannel { get; init; } + + /// + public Optional Url { get; init; } +} \ No newline at end of file From 654ca88ac28f0d91fe38d86ffc4218d2848220e0 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sat, 5 Aug 2023 20:16:24 +0200 Subject: [PATCH 072/323] add role flags --- .../Guilds/IPartialRole.cs | 5 +++++ .../Guilds/IRole.cs | 6 ++++++ .../Guilds/PartialRole.cs | 3 +++ .../DSharpPlus.Core.Models/Guilds/Role.cs | 3 +++ .../Entities/Guilds/DiscordRoleFlags.cs | 19 +++++++++++++++++++ 5 files changed, 36 insertions(+) create mode 100644 src/core/DSharpPlus.Shared/Entities/Guilds/DiscordRoleFlags.cs diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IPartialRole.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IPartialRole.cs index 397723b45a..76fc372028 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IPartialRole.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IPartialRole.cs @@ -67,4 +67,9 @@ public interface IPartialRole /// Additional tags added to this role. /// public Optional Tags { get; } + + /// + /// Flags for this role, combined as a bitfield. + /// + public Optional Flags { get; } } diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IRole.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IRole.cs index 2d1bc1cfcf..0489f97f57 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IRole.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IRole.cs @@ -37,6 +37,9 @@ public interface IRole : IPartialRole /// public new bool Mentionable { get; } + /// + public new DiscordRoleFlags Flags { get; } + // partial access routes /// @@ -62,4 +65,7 @@ public interface IRole : IPartialRole /// Optional IPartialRole.Mentionable => this.Mentionable; + + /// + Optional IPartialRole.Flags => this.Flags; } diff --git a/src/core/DSharpPlus.Core.Models/Guilds/PartialRole.cs b/src/core/DSharpPlus.Core.Models/Guilds/PartialRole.cs index 530499f73c..c94ccb5841 100644 --- a/src/core/DSharpPlus.Core.Models/Guilds/PartialRole.cs +++ b/src/core/DSharpPlus.Core.Models/Guilds/PartialRole.cs @@ -45,4 +45,7 @@ public sealed record PartialRole : IPartialRole /// public Optional Tags { get; init; } + + /// + public Optional Flags { get; init; } } \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/Guilds/Role.cs b/src/core/DSharpPlus.Core.Models/Guilds/Role.cs index 76c0ddbab1..3a6b9df0c6 100644 --- a/src/core/DSharpPlus.Core.Models/Guilds/Role.cs +++ b/src/core/DSharpPlus.Core.Models/Guilds/Role.cs @@ -45,4 +45,7 @@ public sealed record Role : IRole /// public Optional Tags { get; init; } + + /// + public required DiscordRoleFlags Flags { get; init; } } \ No newline at end of file diff --git a/src/core/DSharpPlus.Shared/Entities/Guilds/DiscordRoleFlags.cs b/src/core/DSharpPlus.Shared/Entities/Guilds/DiscordRoleFlags.cs new file mode 100644 index 0000000000..f9788c4e1f --- /dev/null +++ b/src/core/DSharpPlus.Shared/Entities/Guilds/DiscordRoleFlags.cs @@ -0,0 +1,19 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; + +namespace DSharpPlus.Entities; + +/// +/// Represents flags for a role. +/// +[Flags] +public enum DiscordRoleFlags +{ + /// + /// Indicates that this role can be selected by members in an onboarding prompt. + /// + InPrompt = 1 << 0 +} From 5bc0c114c826dfbc3d8c087f7af752f38978b6c1 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sat, 5 Aug 2023 20:19:55 +0200 Subject: [PATCH 073/323] add attachment flags --- .../Channels/IPartialAttachment.cs | 7 +++++++ .../Channels/Attachment.cs | 3 +++ .../Channels/PartialAttachment.cs | 5 +++++ .../Channels/DiscordAttachmentFlags.cs | 19 +++++++++++++++++++ 4 files changed, 34 insertions(+) create mode 100644 src/core/DSharpPlus.Shared/Entities/Channels/DiscordAttachmentFlags.cs diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IPartialAttachment.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IPartialAttachment.cs index 732cf890db..29823751da 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IPartialAttachment.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IPartialAttachment.cs @@ -4,6 +4,8 @@ using System; +using DSharpPlus.Entities; + using Remora.Rest.Core; namespace DSharpPlus.Core.Abstractions.Models; @@ -72,4 +74,9 @@ public interface IPartialAttachment /// base64-encoded byte array representing a sampled waveform for this voice message. /// public Optional> Waveform { get; } + + /// + /// Additional flags for this attachment. + /// + public Optional Flags { get; } } diff --git a/src/core/DSharpPlus.Core.Models/Channels/Attachment.cs b/src/core/DSharpPlus.Core.Models/Channels/Attachment.cs index b326754371..e97fbe4cda 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/Attachment.cs +++ b/src/core/DSharpPlus.Core.Models/Channels/Attachment.cs @@ -46,4 +46,7 @@ public sealed record Attachment : IAttachment /// public Optional> Waveform { get; init; } + + /// + public Optional Flags { get; init; } } \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/Channels/PartialAttachment.cs b/src/core/DSharpPlus.Core.Models/Channels/PartialAttachment.cs index e65125e1ed..d9ffcb00eb 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/PartialAttachment.cs +++ b/src/core/DSharpPlus.Core.Models/Channels/PartialAttachment.cs @@ -4,6 +4,8 @@ using System; +using DSharpPlus.Entities; + using Remora.Rest.Core; using DSharpPlus.Core.Abstractions.Models; @@ -48,4 +50,7 @@ public sealed record PartialAttachment : IPartialAttachment /// public Optional> Waveform { get; init; } + + /// + public Optional Flags { get; init; } } \ No newline at end of file diff --git a/src/core/DSharpPlus.Shared/Entities/Channels/DiscordAttachmentFlags.cs b/src/core/DSharpPlus.Shared/Entities/Channels/DiscordAttachmentFlags.cs new file mode 100644 index 0000000000..f9f925c5c2 --- /dev/null +++ b/src/core/DSharpPlus.Shared/Entities/Channels/DiscordAttachmentFlags.cs @@ -0,0 +1,19 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; + +namespace DSharpPlus.Entities; + +/// +/// Represents flags for an attachment. +/// +[Flags] +public enum DiscordAttachmentFlags +{ + /// + /// Indicates that this attachment has been edited using the remix feature on mobile. + /// + IsRemix = 1 << 2 +} From 6e850610a92f2df7a226418f797db823e1d6b856 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sat, 5 Aug 2023 20:22:39 +0200 Subject: [PATCH 074/323] add onboarding modes --- .../Guilds/IOnboarding.cs | 7 ++++++ .../Guilds/Onboarding.cs | 5 ++++ .../Guilds/DiscordGuildOnboardingMode.cs | 24 +++++++++++++++++++ 3 files changed, 36 insertions(+) create mode 100644 src/core/DSharpPlus.Shared/Entities/Guilds/DiscordGuildOnboardingMode.cs diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IOnboarding.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IOnboarding.cs index 83cc0f20c0..782b1ca47c 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IOnboarding.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IOnboarding.cs @@ -4,6 +4,8 @@ using System.Collections.Generic; +using DSharpPlus.Entities; + using Remora.Rest.Core; namespace DSharpPlus.Core.Abstractions.Models; @@ -32,4 +34,9 @@ public interface IOnboarding /// Indicates whether onboarding is enabled in the guild. /// public bool Enabled { get; } + + /// + /// The current onboarding mode. + /// + public DiscordGuildOnboardingPromptType Mode { get; } } diff --git a/src/core/DSharpPlus.Core.Models/Guilds/Onboarding.cs b/src/core/DSharpPlus.Core.Models/Guilds/Onboarding.cs index 691bae28f4..11eab8a957 100644 --- a/src/core/DSharpPlus.Core.Models/Guilds/Onboarding.cs +++ b/src/core/DSharpPlus.Core.Models/Guilds/Onboarding.cs @@ -4,6 +4,8 @@ using System.Collections.Generic; +using DSharpPlus.Entities; + using Remora.Rest.Core; using DSharpPlus.Core.Abstractions.Models; @@ -24,4 +26,7 @@ public sealed record Onboarding : IOnboarding /// public required bool Enabled { get; init; } + + /// + public required DiscordGuildOnboardingPromptType Mode { get; init; } } \ No newline at end of file diff --git a/src/core/DSharpPlus.Shared/Entities/Guilds/DiscordGuildOnboardingMode.cs b/src/core/DSharpPlus.Shared/Entities/Guilds/DiscordGuildOnboardingMode.cs new file mode 100644 index 0000000000..fa19a9dbea --- /dev/null +++ b/src/core/DSharpPlus.Shared/Entities/Guilds/DiscordGuildOnboardingMode.cs @@ -0,0 +1,24 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; + +namespace DSharpPlus.Entities; + +/// +/// Defines the criteria used to satisfy Onboarding constraints required for enabling. +/// +[Flags] +public enum DiscordGuildOnboardingMode +{ + /// + /// Counts only default channels towards constraints. + /// + OnboardingDefault, + + /// + /// Counts default channels and questions towards constraints. + /// + OnboardingAdvanced +} From ac4dfafaf44e3eb0b7989d18386da89bd716b322 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sat, 5 Aug 2023 20:28:29 +0200 Subject: [PATCH 075/323] add approximate guild count to applications --- .../Applications/IPartialApplication.cs | 13 +++++++++++-- .../Applications/Application.cs | 6 ++++++ .../Applications/PartialApplication.cs | 6 ++++++ .../Program.cs | 15 ++++++++++++++- 4 files changed, 37 insertions(+), 3 deletions(-) diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Applications/IPartialApplication.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Applications/IPartialApplication.cs index 8fa2fb61a0..88d0a58cc7 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Applications/IPartialApplication.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Applications/IPartialApplication.cs @@ -76,11 +76,15 @@ public interface IPartialApplication public Optional Team { get; } /// - /// If this application is a game sold on discord, this is the snowflake identifier of the guild - /// to which it has been linked. + /// The snowflake identifier of the guild associated with this app, for instance, its support server. /// public Optional GuildId { get; } + /// + /// A partial object of the associated guild. + /// + public Optional Guild { get; } + /// /// If this application is a game sold on discord, this is the snowflake identifier of the /// game SKU created, if it exists. @@ -102,6 +106,11 @@ public interface IPartialApplication /// public Optional Flags { get; } + /// + /// An approximate count of this application's guild membership. + /// + public Optional ApproximateGuildCount { get; } + /// /// Up to five tags describing content and functionality of the application. /// diff --git a/src/core/DSharpPlus.Core.Models/Applications/Application.cs b/src/core/DSharpPlus.Core.Models/Applications/Application.cs index c7ac0a45b3..5681c98e66 100644 --- a/src/core/DSharpPlus.Core.Models/Applications/Application.cs +++ b/src/core/DSharpPlus.Core.Models/Applications/Application.cs @@ -50,6 +50,9 @@ public sealed record Application : IApplication /// public Optional GuildId { get; init; } + /// + public Optional Guild { get; init; } + /// public Optional PrimarySkuId { get; init; } @@ -62,6 +65,9 @@ public sealed record Application : IApplication /// public Optional Flags { get; init; } + /// + public Optional ApproximateGuildCount { get; init; } + /// public Optional> Tags { get; init; } diff --git a/src/core/DSharpPlus.Core.Models/Applications/PartialApplication.cs b/src/core/DSharpPlus.Core.Models/Applications/PartialApplication.cs index 31da2904e6..a93a2f5ebd 100644 --- a/src/core/DSharpPlus.Core.Models/Applications/PartialApplication.cs +++ b/src/core/DSharpPlus.Core.Models/Applications/PartialApplication.cs @@ -54,6 +54,9 @@ public sealed record PartialApplication : IPartialApplication /// public Optional GuildId { get; init; } + /// + public Optional Guild { get; init; } + /// public Optional PrimarySkuId { get; init; } @@ -66,6 +69,9 @@ public sealed record PartialApplication : IPartialApplication /// public Optional Flags { get; init; } + /// + public Optional ApproximateGuildCount { get; init; } + /// public Optional> Tags { get; init; } diff --git a/tools/generators/Tools.Generators.GenerateConcreteObjects/Program.cs b/tools/generators/Tools.Generators.GenerateConcreteObjects/Program.cs index c2aad4295a..acfca639e4 100644 --- a/tools/generators/Tools.Generators.GenerateConcreteObjects/Program.cs +++ b/tools/generators/Tools.Generators.GenerateConcreteObjects/Program.cs @@ -149,9 +149,12 @@ Deleting counterparts to removed files... ); List emittedFiles = new(); + List editedFiles = added.Concat(modified).ToList(); - foreach (string path in added.Concat(modified)) + for(int i = 0; i < editedFiles.Count; i++) { + string path = editedFiles[i]; + CompilationUnitSyntax root = SyntaxFactory.ParseCompilationUnit ( File.ReadAllText(path) @@ -243,6 +246,16 @@ namespace DSharpPlus.Core.Models; continue; } + // make sure partial-inheriting interfaces get updated too + if (interfaceSyntax.Identifier.ToString().StartsWith("IPartial")) + { + string fullCandidate = path.Replace("IPartial", "I"); + if (!editedFiles.Contains(fullCandidate)) + { + editedFiles.Add(fullCandidate); + } + } + writer.AppendLine ( $$""" From 5d8af58b9ae019fdc9d3790bf27759ee912be902 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sat, 5 Aug 2023 20:30:21 +0200 Subject: [PATCH 076/323] add avatar decorations --- .../Users/IPartialUser.cs | 5 +++++ src/core/DSharpPlus.Core.Models/Users/PartialUser.cs | 3 +++ src/core/DSharpPlus.Core.Models/Users/User.cs | 3 +++ 3 files changed, 11 insertions(+) diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Users/IPartialUser.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Users/IPartialUser.cs index 3134c3fef2..93ec675960 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Users/IPartialUser.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Users/IPartialUser.cs @@ -91,4 +91,9 @@ public interface IPartialUser /// The publicly visible flags on this user's account. /// public Optional PublicFlags { get; } + + /// + /// The user's avatar decoration hash. + /// + public Optional AvatarDecoration { get; } } diff --git a/src/core/DSharpPlus.Core.Models/Users/PartialUser.cs b/src/core/DSharpPlus.Core.Models/Users/PartialUser.cs index aa95ea81fd..07dda803e3 100644 --- a/src/core/DSharpPlus.Core.Models/Users/PartialUser.cs +++ b/src/core/DSharpPlus.Core.Models/Users/PartialUser.cs @@ -59,4 +59,7 @@ public sealed record PartialUser : IPartialUser /// public Optional PublicFlags { get; init; } + + /// + public Optional AvatarDecoration { get; init; } } \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/Users/User.cs b/src/core/DSharpPlus.Core.Models/Users/User.cs index 0a0e7c108a..b6f72d315f 100644 --- a/src/core/DSharpPlus.Core.Models/Users/User.cs +++ b/src/core/DSharpPlus.Core.Models/Users/User.cs @@ -58,4 +58,7 @@ public sealed record User : IUser /// public Optional PublicFlags { get; init; } + + /// + public Optional AvatarDecoration { get; init; } } \ No newline at end of file From ffe5112580cbaebb2d8f92ed04de33dbe213645e Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sat, 5 Aug 2023 20:36:30 +0200 Subject: [PATCH 077/323] add media channels --- .../Channels/IForumTag.cs | 2 +- .../Channels/IPartialChannel.cs | 15 ++++++++------- .../Entities/Channels/DiscordChannelFlags.cs | 8 +++++++- .../Entities/Channels/DiscordChannelType.cs | 7 ++++++- 4 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IForumTag.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IForumTag.cs index 8d96789e9e..90ac428250 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IForumTag.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IForumTag.cs @@ -7,7 +7,7 @@ namespace DSharpPlus.Core.Abstractions.Models; /// -/// Represents a single forum tag, applicable to forum posts. +/// Represents a single forum tag, applicable to forum or media channel posts. /// public interface IForumTag { diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IPartialChannel.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IPartialChannel.cs index 277cb287ca..e6a9494678 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IPartialChannel.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IPartialChannel.cs @@ -47,8 +47,9 @@ public interface IPartialChannel public Optional Name { get; } /// - /// The channel topic/description. For up to 4096 - /// characters are allowed, for all other types up to 1024 characters. + /// The channel topic/description. For and + /// , up to 4096 characters are allowed, for all other + /// types up to 1024 characters. /// public Optional Topic { get; } @@ -58,7 +59,7 @@ public interface IPartialChannel public Optional Nsfw { get; } /// - /// The snowflake identifier of the last message sent in this channel. This is a thread for forum + /// The snowflake identifier of the last message sent in this channel. This is a thread for forum and media /// channels, and may not point to an existing or valid message or thread. /// public Optional LastMessageId { get; } @@ -168,17 +169,17 @@ public interface IPartialChannel public Optional TotalMessageSent { get; } /// - /// The set of tags that can be used in this forum channel. + /// The set of tags that can be used in this forum or media channel. /// public Optional> AvailableTags { get; } /// - /// The snowflake identifiers of the set of tags that have been applied to this forum thread channel. + /// The snowflake identifiers of the set of tags that have been applied to this forum or media thread channel. /// public Optional> AppliedTags { get; } /// - /// The default emoji to show in the add reaction button on a thread in this forum channel. + /// The default emoji to show in the add reaction button on a thread in this forum or media channel. /// public Optional DefaultReactionEmoji { get; } @@ -189,7 +190,7 @@ public interface IPartialChannel public Optional DefaultThreadRateLimitPerUser { get; } /// - /// The default sort order for posts in this forum channel. + /// The default sort order for posts in this forum or media channel. /// public Optional DefaultSortOrder { get; } diff --git a/src/core/DSharpPlus.Shared/Entities/Channels/DiscordChannelFlags.cs b/src/core/DSharpPlus.Shared/Entities/Channels/DiscordChannelFlags.cs index a3b21c5b63..8e7a94ca83 100644 --- a/src/core/DSharpPlus.Shared/Entities/Channels/DiscordChannelFlags.cs +++ b/src/core/DSharpPlus.Shared/Entities/Channels/DiscordChannelFlags.cs @@ -23,5 +23,11 @@ public enum DiscordChannelFlags /// Indicates whether this is a forum channel which requires tags to be specified when creating /// a thread inside. /// - RequireTag = 1 << 4 + RequireTag = 1 << 4, + + /// + /// Indicates to the client to hide the embedded media download options. This is available only for + /// media channels. + /// + HideMediaDownloadOptions = 1 << 15 } diff --git a/src/core/DSharpPlus.Shared/Entities/Channels/DiscordChannelType.cs b/src/core/DSharpPlus.Shared/Entities/Channels/DiscordChannelType.cs index 3fc2739a57..8e34b5b851 100644 --- a/src/core/DSharpPlus.Shared/Entities/Channels/DiscordChannelType.cs +++ b/src/core/DSharpPlus.Shared/Entities/Channels/DiscordChannelType.cs @@ -67,5 +67,10 @@ public enum DiscordChannelType /// /// A channel that can only contain public threads. /// - GuildForum + GuildForum, + + /// + /// A channel that can only contain threads, similar to . + /// + GuildMedia } From df05567a160fd755a52e051246b96156196b2fd7 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sun, 6 Aug 2023 13:06:04 +0200 Subject: [PATCH 078/323] represent message components in a handleable way --- .../MessageComponents/IButtonComponent.cs | 5 +++++ .../MessageComponents/IChannelSelectComponent.cs | 5 +++++ .../MessageComponents/IInteractiveComponent.cs | 10 +--------- .../MessageComponents/IMentionableSelectComponent.cs | 7 +++++++ .../MessageComponents/IRoleSelectComponent.cs | 7 +++++++ .../MessageComponents/IStringSelectComponent.cs | 7 +++++++ .../MessageComponents/ITextInputComponent.cs | 5 +++++ .../MessageComponents/IUserSelectComponent.cs | 7 +++++++ .../MessageComponents/ButtonComponent.cs | 3 +++ .../MessageComponents/ChannelSelectComponent.cs | 3 +++ .../MessageComponents/MentionableSelectComponent.cs | 5 +++++ .../MessageComponents/RoleSelectComponent.cs | 5 +++++ .../MessageComponents/StringSelectComponent.cs | 5 +++++ .../MessageComponents/TextInputComponent.cs | 3 +++ .../MessageComponents/UserSelectComponent.cs | 5 +++++ 15 files changed, 73 insertions(+), 9 deletions(-) diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IButtonComponent.cs b/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IButtonComponent.cs index 8c5ed2244f..e0696b21cf 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IButtonComponent.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IButtonComponent.cs @@ -13,6 +13,11 @@ namespace DSharpPlus.Core.Abstractions.Models; /// public interface IButtonComponent : IInteractiveComponent { + /// + /// The type of this component. + /// + public DiscordMessageComponentType Type { get; } + /// /// The visual style of this button. /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IChannelSelectComponent.cs b/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IChannelSelectComponent.cs index 0dc5c40ef3..377590f202 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IChannelSelectComponent.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IChannelSelectComponent.cs @@ -16,6 +16,11 @@ namespace DSharpPlus.Core.Abstractions.Models; /// public interface IChannelSelectComponent : IInteractiveComponent { + /// + /// The type of this component. + /// + public DiscordMessageComponentType Type { get; } + /// /// The developer-defined ID for this select menu, up to 100 characters. /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IInteractiveComponent.cs b/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IInteractiveComponent.cs index 5e4acf3d43..616e867e68 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IInteractiveComponent.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IInteractiveComponent.cs @@ -2,17 +2,9 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Entities; - namespace DSharpPlus.Core.Abstractions.Models; /// /// Represents a message component that users can interact with. /// -public interface IInteractiveComponent -{ - /// - /// The type of this component. - /// - public DiscordMessageComponentType Type { get; } -} +public interface IInteractiveComponent; diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IMentionableSelectComponent.cs b/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IMentionableSelectComponent.cs index c8ee8c8e42..1da6e010a5 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IMentionableSelectComponent.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IMentionableSelectComponent.cs @@ -2,6 +2,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +using DSharpPlus.Entities; + using Remora.Rest.Core; namespace DSharpPlus.Core.Abstractions.Models; @@ -11,6 +13,11 @@ namespace DSharpPlus.Core.Abstractions.Models; /// public interface IMentionableSelectComponent : IInteractiveComponent { + /// + /// The type of this component. + /// + public DiscordMessageComponentType Type { get; } + /// /// The developer-defined ID for this select menu, up to 100 characters. /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IRoleSelectComponent.cs b/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IRoleSelectComponent.cs index b51055cdcd..b14a6b6ba0 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IRoleSelectComponent.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IRoleSelectComponent.cs @@ -2,6 +2,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +using DSharpPlus.Entities; + using Remora.Rest.Core; namespace DSharpPlus.Core.Abstractions.Models; @@ -11,6 +13,11 @@ namespace DSharpPlus.Core.Abstractions.Models; /// public interface IRoleSelectComponent : IInteractiveComponent { + /// + /// The type of this component. + /// + public DiscordMessageComponentType Type { get; } + /// /// The developer-defined ID for this select menu, up to 100 characters. /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IStringSelectComponent.cs b/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IStringSelectComponent.cs index 5d60b1caf7..48a3886877 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IStringSelectComponent.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IStringSelectComponent.cs @@ -4,6 +4,8 @@ using System.Collections.Generic; +using DSharpPlus.Entities; + using Remora.Rest.Core; namespace DSharpPlus.Core.Abstractions.Models; @@ -13,6 +15,11 @@ namespace DSharpPlus.Core.Abstractions.Models; /// public interface IStringSelectComponent : IInteractiveComponent { + /// + /// The type of this component. + /// + public DiscordMessageComponentType Type { get; } + /// /// The developer-defined ID for this select menu, up to 100 characters. /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/ITextInputComponent.cs b/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/ITextInputComponent.cs index 52a64ff159..9591d41383 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/ITextInputComponent.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/ITextInputComponent.cs @@ -13,6 +13,11 @@ namespace DSharpPlus.Core.Abstractions.Models; /// public interface ITextInputComponent : IInteractiveComponent { + /// + /// The type of this component. + /// + public DiscordMessageComponentType Type { get; } + /// /// The identifier of this input field, up to 100 characters. /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IUserSelectComponent.cs b/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IUserSelectComponent.cs index 2279ad8b28..1fbfd1e39a 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IUserSelectComponent.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IUserSelectComponent.cs @@ -2,6 +2,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +using DSharpPlus.Entities; + using Remora.Rest.Core; namespace DSharpPlus.Core.Abstractions.Models; @@ -11,6 +13,11 @@ namespace DSharpPlus.Core.Abstractions.Models; /// public interface IUserSelectComponent : IInteractiveComponent { + /// + /// The type of this component. + /// + public DiscordMessageComponentType Type { get; } + /// /// The developer-defined ID for this select menu, up to 100 characters. /// diff --git a/src/core/DSharpPlus.Core.Models/MessageComponents/ButtonComponent.cs b/src/core/DSharpPlus.Core.Models/MessageComponents/ButtonComponent.cs index f061b42780..c5cd2ad628 100644 --- a/src/core/DSharpPlus.Core.Models/MessageComponents/ButtonComponent.cs +++ b/src/core/DSharpPlus.Core.Models/MessageComponents/ButtonComponent.cs @@ -13,6 +13,9 @@ namespace DSharpPlus.Core.Models; /// public sealed record ButtonComponent : IButtonComponent { + /// + public required DiscordMessageComponentType Type { get; init; } + /// public required DiscordButtonStyle Style { get; init; } diff --git a/src/core/DSharpPlus.Core.Models/MessageComponents/ChannelSelectComponent.cs b/src/core/DSharpPlus.Core.Models/MessageComponents/ChannelSelectComponent.cs index 9e5c81e3b8..5eced6e93b 100644 --- a/src/core/DSharpPlus.Core.Models/MessageComponents/ChannelSelectComponent.cs +++ b/src/core/DSharpPlus.Core.Models/MessageComponents/ChannelSelectComponent.cs @@ -15,6 +15,9 @@ namespace DSharpPlus.Core.Models; /// public sealed record ChannelSelectComponent : IChannelSelectComponent { + /// + public required DiscordMessageComponentType Type { get; init; } + /// public required string CustomId { get; init; } diff --git a/src/core/DSharpPlus.Core.Models/MessageComponents/MentionableSelectComponent.cs b/src/core/DSharpPlus.Core.Models/MessageComponents/MentionableSelectComponent.cs index 11781c3990..dbcca4a9d2 100644 --- a/src/core/DSharpPlus.Core.Models/MessageComponents/MentionableSelectComponent.cs +++ b/src/core/DSharpPlus.Core.Models/MessageComponents/MentionableSelectComponent.cs @@ -2,6 +2,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +using DSharpPlus.Entities; + using Remora.Rest.Core; using DSharpPlus.Core.Abstractions.Models; @@ -11,6 +13,9 @@ namespace DSharpPlus.Core.Models; /// public sealed record MentionableSelectComponent : IMentionableSelectComponent { + /// + public required DiscordMessageComponentType Type { get; init; } + /// public required string CustomId { get; init; } diff --git a/src/core/DSharpPlus.Core.Models/MessageComponents/RoleSelectComponent.cs b/src/core/DSharpPlus.Core.Models/MessageComponents/RoleSelectComponent.cs index 4f1ca413b4..dd98a0c8d9 100644 --- a/src/core/DSharpPlus.Core.Models/MessageComponents/RoleSelectComponent.cs +++ b/src/core/DSharpPlus.Core.Models/MessageComponents/RoleSelectComponent.cs @@ -2,6 +2,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +using DSharpPlus.Entities; + using Remora.Rest.Core; using DSharpPlus.Core.Abstractions.Models; @@ -11,6 +13,9 @@ namespace DSharpPlus.Core.Models; /// public sealed record RoleSelectComponent : IRoleSelectComponent { + /// + public required DiscordMessageComponentType Type { get; init; } + /// public required string CustomId { get; init; } diff --git a/src/core/DSharpPlus.Core.Models/MessageComponents/StringSelectComponent.cs b/src/core/DSharpPlus.Core.Models/MessageComponents/StringSelectComponent.cs index beedba4a20..b2660b2dca 100644 --- a/src/core/DSharpPlus.Core.Models/MessageComponents/StringSelectComponent.cs +++ b/src/core/DSharpPlus.Core.Models/MessageComponents/StringSelectComponent.cs @@ -4,6 +4,8 @@ using System.Collections.Generic; +using DSharpPlus.Entities; + using Remora.Rest.Core; using DSharpPlus.Core.Abstractions.Models; @@ -13,6 +15,9 @@ namespace DSharpPlus.Core.Models; /// public sealed record StringSelectComponent : IStringSelectComponent { + /// + public required DiscordMessageComponentType Type { get; init; } + /// public required string CustomId { get; init; } diff --git a/src/core/DSharpPlus.Core.Models/MessageComponents/TextInputComponent.cs b/src/core/DSharpPlus.Core.Models/MessageComponents/TextInputComponent.cs index cc3bedee2d..3a1e9efd7d 100644 --- a/src/core/DSharpPlus.Core.Models/MessageComponents/TextInputComponent.cs +++ b/src/core/DSharpPlus.Core.Models/MessageComponents/TextInputComponent.cs @@ -13,6 +13,9 @@ namespace DSharpPlus.Core.Models; /// public sealed record TextInputComponent : ITextInputComponent { + /// + public required DiscordMessageComponentType Type { get; init; } + /// public required string CustomId { get; init; } diff --git a/src/core/DSharpPlus.Core.Models/MessageComponents/UserSelectComponent.cs b/src/core/DSharpPlus.Core.Models/MessageComponents/UserSelectComponent.cs index 09206e6bbe..25c283fcee 100644 --- a/src/core/DSharpPlus.Core.Models/MessageComponents/UserSelectComponent.cs +++ b/src/core/DSharpPlus.Core.Models/MessageComponents/UserSelectComponent.cs @@ -2,6 +2,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +using DSharpPlus.Entities; + using Remora.Rest.Core; using DSharpPlus.Core.Abstractions.Models; @@ -11,6 +13,9 @@ namespace DSharpPlus.Core.Models; /// public sealed record UserSelectComponent : IUserSelectComponent { + /// + public required DiscordMessageComponentType Type { get; init; } + /// public required string CustomId { get; init; } From 8f3642ea1f7ff3a3ed96b5e2020bdc94841ba743 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sun, 6 Aug 2023 16:29:28 +0200 Subject: [PATCH 079/323] message component converter --- .../Converters/MessageComponentConverter.cs | 116 ++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 src/core/DSharpPlus.Core.Models/Converters/MessageComponentConverter.cs diff --git a/src/core/DSharpPlus.Core.Models/Converters/MessageComponentConverter.cs b/src/core/DSharpPlus.Core.Models/Converters/MessageComponentConverter.cs new file mode 100644 index 0000000000..140f61b572 --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/Converters/MessageComponentConverter.cs @@ -0,0 +1,116 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; +using System.Text.Json; +using System.Text.Json.Serialization; + +using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Entities; + +namespace DSharpPlus.Core.Models.Converters; + +/// +/// Converts between message components and JSON. +/// +public class MessageComponentConverter : JsonConverter +{ + /// + public override IInteractiveComponent? Read + ( + ref Utf8JsonReader reader, + Type typeToConvert, + JsonSerializerOptions options + ) + { + if (reader.TokenType != JsonTokenType.StartObject) + { + throw new JsonException("There was no JSON object found."); + } + +#pragma warning disable IDE0046 // we don't want this to become a 40 line ternary. + if + ( + !JsonDocument.TryParseValue(ref reader, out JsonDocument? document) + || document.RootElement.TryGetProperty("type", out JsonElement property) + || !property.TryGetInt32(out int type) + ) + { + throw new JsonException("The provided JSON object was malformed."); + } + + return (DiscordMessageComponentType)type switch + { + DiscordMessageComponentType.ActionRow + => throw new JsonException("Invalid JSON structure: expected an interactive component, not an action row."), + + DiscordMessageComponentType.Button + => JsonSerializer.Deserialize(document, options), + + DiscordMessageComponentType.StringSelect + => JsonSerializer.Deserialize(document, options), + + DiscordMessageComponentType.TextInput + => JsonSerializer.Deserialize(document, options), + + DiscordMessageComponentType.UserSelect + => JsonSerializer.Deserialize(document, options), + + DiscordMessageComponentType.RoleSelect + => JsonSerializer.Deserialize(document, options), + + DiscordMessageComponentType.MentionableSelect + => JsonSerializer.Deserialize(document, options), + + DiscordMessageComponentType.ChannelSelect + => JsonSerializer.Deserialize(document, options), + + _ => throw new JsonException("Unknown component type.") + }; +#pragma warning restore IDE0046 + } + + /// + public override void Write + ( + Utf8JsonWriter writer, + IInteractiveComponent value, + JsonSerializerOptions options + ) + { + switch (value) + { + case IButtonComponent button: + JsonSerializer.Serialize(writer, button, options); + break; + + case IStringSelectComponent stringSelect: + JsonSerializer.Serialize(writer, stringSelect, options); + break; + + case ITextInputComponent text: + JsonSerializer.Serialize(writer, text, options); + break; + + case IUserSelectComponent user: + JsonSerializer.Serialize(writer, user, options); + break; + + case IRoleSelectComponent role: + JsonSerializer.Serialize(writer, role, options); + break; + + case IMentionableSelectComponent mentionable: + JsonSerializer.Serialize(writer, mentionable, options); + break; + + case IChannelSelectComponent channel: + JsonSerializer.Serialize(writer, channel, options); + break; + + default: + throw new InvalidOperationException($"The component {value} could not be serialized."); + } + } +} From ba4cf107c9160f369a36910f85905a6831b8a417 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sun, 6 Aug 2023 16:47:17 +0200 Subject: [PATCH 080/323] correctly copy usings --- .../IAutocompleteInteractionDataOption.cs | 29 ++++++++++++++++++- .../ApplicationCommands/ApplicationCommand.cs | 4 +++ .../ApplicationCommandOption.cs | 4 +++ .../ApplicationCommandOptionChoice.cs | 4 +++ .../ApplicationCommandPermission.cs | 4 +++ .../ApplicationCommandPermissions.cs | 4 +++ .../PartialApplicationCommandPermissions.cs | 4 +++ .../Applications/Application.cs | 8 +++++ .../Applications/InstallParameters.cs | 4 +++ .../Applications/PartialApplication.cs | 4 +++ .../AuditLogs/AuditLog.cs | 4 +++ .../AuditLogs/AuditLogChange.cs | 4 +++ .../AuditLogs/AuditLogEntry.cs | 4 +++ .../AuditLogs/AuditLogEntryInfo.cs | 4 +++ .../AutoModeration/AutoModerationAction.cs | 4 +++ .../AutoModeration/AutoModerationRule.cs | 4 +++ .../AutoModerationTriggerMetadata.cs | 4 +++ .../BlockMessageActionMetadata.cs | 4 +++ .../PartialAutoModerationRule.cs | 4 +++ .../SendAlertMessageActionMetadata.cs | 4 +++ .../AutoModeration/TimeoutActionMetadata.cs | 4 +++ .../Channels/AllowedMentions.cs | 4 +++ .../Channels/Attachment.cs | 8 +++++ .../Channels/Channel.cs | 7 +++++ .../Channels/ChannelMention.cs | 4 +++ .../Channels/ChannelOverwrite.cs | 4 +++ .../Channels/DefaultReaction.cs | 4 +++ .../DSharpPlus.Core.Models/Channels/Embed.cs | 4 +++ .../Channels/EmbedAuthor.cs | 4 +++ .../Channels/EmbedField.cs | 4 +++ .../Channels/EmbedFooter.cs | 4 +++ .../Channels/EmbedImage.cs | 4 +++ .../Channels/EmbedProvider.cs | 4 +++ .../Channels/EmbedThumbnail.cs | 4 +++ .../Channels/EmbedVideo.cs | 4 +++ .../Channels/FollowedChannel.cs | 4 +++ .../Channels/ForumTag.cs | 4 +++ .../Channels/Message.cs | 4 +++ .../Channels/MessageActivity.cs | 4 +++ .../Channels/MessageReference.cs | 4 +++ .../Channels/PartialAttachment.cs | 4 +++ .../Channels/PartialChannel.cs | 4 +++ .../Channels/PartialChannelOverwrite.cs | 4 +++ .../Channels/PartialMessage.cs | 4 +++ .../Channels/Reaction.cs | 4 +++ .../Channels/RoleSubscriptionData.cs | 4 +++ .../Channels/ThreadMember.cs | 4 +++ .../Channels/ThreadMetadata.cs | 4 +++ .../DSharpPlus.Core.Models/Emojis/Emoji.cs | 6 ++++ .../Emojis/PartialEmoji.cs | 4 +++ .../GuildTemplates/Template.cs | 4 +++ src/core/DSharpPlus.Core.Models/Guilds/Ban.cs | 4 +++ .../DSharpPlus.Core.Models/Guilds/Guild.cs | 4 +++ .../Guilds/GuildMember.cs | 4 +++ .../Guilds/GuildPreview.cs | 4 +++ .../Guilds/GuildWidget.cs | 4 +++ .../Guilds/GuildWidgetSettings.cs | 4 +++ .../Guilds/Integration.cs | 9 ++++++ .../Guilds/IntegrationAccount.cs | 4 +++ .../Guilds/IntegrationApplication.cs | 4 +++ .../Guilds/Onboarding.cs | 4 +++ .../Guilds/OnboardingPrompt.cs | 4 +++ .../Guilds/OnboardingPromptOption.cs | 4 +++ .../Guilds/PartialGuild.cs | 4 +++ .../Guilds/PartialGuildMember.cs | 4 +++ .../Guilds/PartialIntegration.cs | 4 +++ .../Guilds/PartialRole.cs | 4 +++ .../DSharpPlus.Core.Models/Guilds/Role.cs | 4 +++ .../DSharpPlus.Core.Models/Guilds/RoleTags.cs | 4 +++ .../Guilds/WelcomeScreen.cs | 4 +++ .../Guilds/WelcomeScreenChannel.cs | 4 +++ .../ApplicationCommandInteractionData.cs | 4 +++ ...ApplicationCommandInteractionDataOption.cs | 4 +++ .../Interactions/AutocompleteCallbackData.cs | 4 +++ .../AutocompleteInteractionData.cs | 4 +++ .../AutocompleteInteractionDataOption.cs | 22 ++++++++++++++ .../Interactions/Interaction.cs | 4 +++ .../Interactions/InteractionResponse.cs | 4 +++ .../Interactions/MessageCallbackData.cs | 4 +++ .../MessageComponentInteractionData.cs | 4 +++ .../Interactions/MessageInteraction.cs | 4 +++ .../Interactions/ModalCallbackData.cs | 4 +++ .../Interactions/ModalInteractionData.cs | 4 +++ .../Interactions/ResolvedData.cs | 4 +++ .../DSharpPlus.Core.Models/Invites/Invite.cs | 8 +++++ .../Invites/PartialInvite.cs | 4 +++ .../MessageComponents/ActionRowComponent.cs | 4 +++ .../MessageComponents/ButtonComponent.cs | 4 +++ .../ChannelSelectComponent.cs | 4 +++ .../MessageComponents/InteractiveComponent.cs | 16 ---------- .../MentionableSelectComponent.cs | 4 +++ .../MessageComponents/RoleSelectComponent.cs | 4 +++ .../MessageComponents/SelectOption.cs | 4 +++ .../StringSelectComponent.cs | 4 +++ .../MessageComponents/TextInputComponent.cs | 4 +++ .../MessageComponents/UserSelectComponent.cs | 4 +++ .../RoleConnections/RoleConnectionMetadata.cs | 4 +++ .../ScheduledEvents/PartialScheduledEvent.cs | 4 +++ .../ScheduledEvents/ScheduledEvent.cs | 5 +++- .../ScheduledEvents/ScheduledEventUser.cs | 4 +++ .../StageInstances/PartialStageInstance.cs | 4 +++ .../StageInstances/StageInstance.cs | 5 ++++ .../Stickers/PartialSticker.cs | 4 +++ .../Stickers/Sticker.cs | 4 +++ .../Stickers/StickerItem.cs | 4 +++ .../Stickers/StickerPack.cs | 4 +++ src/core/DSharpPlus.Core.Models/Teams/Team.cs | 4 +++ .../Teams/TeamMember.cs | 4 +++ .../Users/ApplicationRoleConnection.cs | 4 +++ .../Users/Connection.cs | 4 +++ .../Users/PartialUser.cs | 4 +++ src/core/DSharpPlus.Core.Models/Users/User.cs | 5 ++++ .../Voice/VoiceRegion.cs | 4 +++ .../Voice/VoiceState.cs | 4 +++ .../Webhooks/PartialWebhook.cs | 4 +++ .../Webhooks/Webhook.cs | 4 +++ .../Program.cs | 26 ++++++++++++++--- 117 files changed, 548 insertions(+), 22 deletions(-) delete mode 100644 src/core/DSharpPlus.Core.Models/MessageComponents/InteractiveComponent.cs diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IAutocompleteInteractionDataOption.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IAutocompleteInteractionDataOption.cs index 22f3aed111..5d803fe362 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IAutocompleteInteractionDataOption.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IAutocompleteInteractionDataOption.cs @@ -2,6 +2,12 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +using System.Collections.Generic; + +using DSharpPlus.Entities; + +using OneOf; + using Remora.Rest.Core; namespace DSharpPlus.Core.Abstractions.Models; @@ -10,8 +16,29 @@ namespace DSharpPlus.Core.Abstractions.Models; /// Represents submitted data for a single application command data option during the autocomplete /// process. /// -public interface IAutocompleteInteractionDataOption : IApplicationCommandInteractionDataOption +public interface IAutocompleteInteractionDataOption { + /// + /// The name of the option. + /// + public string Name { get; } + + /// + /// The type of this option. + /// + public DiscordApplicationCommandOptionType Type { get; } + + /// + /// The value passed to this option by the user. + /// + public Optional> Value { get; } + + /// + /// If this is a subcommand, the values passed to its parameters. If this is a subcommand group, + /// its subcommands. + /// + public Optional> Options { get; } + /// /// Indicates whether this option is currently focused for autocomplete. /// diff --git a/src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommand.cs b/src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommand.cs index 029bef2ffa..22a18c332c 100644 --- a/src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommand.cs +++ b/src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommand.cs @@ -2,6 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + using System.Collections.Generic; using DSharpPlus.Entities; diff --git a/src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommandOption.cs b/src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommandOption.cs index 37bdf31919..d3874743c9 100644 --- a/src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommandOption.cs +++ b/src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommandOption.cs @@ -2,6 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + using System.Collections.Generic; using DSharpPlus.Entities; diff --git a/src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommandOptionChoice.cs b/src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommandOptionChoice.cs index 3e4949a191..30bceaa3b1 100644 --- a/src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommandOptionChoice.cs +++ b/src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommandOptionChoice.cs @@ -2,6 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + using System.Collections.Generic; using OneOf; diff --git a/src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommandPermission.cs b/src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommandPermission.cs index 202320f918..8cc249b5cf 100644 --- a/src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommandPermission.cs +++ b/src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommandPermission.cs @@ -2,6 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + using DSharpPlus.Entities; using Remora.Rest.Core; diff --git a/src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommandPermissions.cs b/src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommandPermissions.cs index 741e912e59..414a0d882d 100644 --- a/src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommandPermissions.cs +++ b/src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommandPermissions.cs @@ -2,6 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + using System.Collections.Generic; using Remora.Rest.Core; diff --git a/src/core/DSharpPlus.Core.Models/ApplicationCommands/PartialApplicationCommandPermissions.cs b/src/core/DSharpPlus.Core.Models/ApplicationCommands/PartialApplicationCommandPermissions.cs index b31912ad32..f171b4dd3c 100644 --- a/src/core/DSharpPlus.Core.Models/ApplicationCommands/PartialApplicationCommandPermissions.cs +++ b/src/core/DSharpPlus.Core.Models/ApplicationCommands/PartialApplicationCommandPermissions.cs @@ -2,6 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + using System.Collections.Generic; using Remora.Rest.Core; diff --git a/src/core/DSharpPlus.Core.Models/Applications/Application.cs b/src/core/DSharpPlus.Core.Models/Applications/Application.cs index 5681c98e66..c68b21acdd 100644 --- a/src/core/DSharpPlus.Core.Models/Applications/Application.cs +++ b/src/core/DSharpPlus.Core.Models/Applications/Application.cs @@ -2,6 +2,14 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Entities; + using Remora.Rest.Core; using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/Applications/InstallParameters.cs b/src/core/DSharpPlus.Core.Models/Applications/InstallParameters.cs index 5a3c749450..92f430997a 100644 --- a/src/core/DSharpPlus.Core.Models/Applications/InstallParameters.cs +++ b/src/core/DSharpPlus.Core.Models/Applications/InstallParameters.cs @@ -2,6 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + using System.Collections.Generic; using DSharpPlus.Entities; diff --git a/src/core/DSharpPlus.Core.Models/Applications/PartialApplication.cs b/src/core/DSharpPlus.Core.Models/Applications/PartialApplication.cs index a93a2f5ebd..3a1c137c64 100644 --- a/src/core/DSharpPlus.Core.Models/Applications/PartialApplication.cs +++ b/src/core/DSharpPlus.Core.Models/Applications/PartialApplication.cs @@ -2,6 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + using System.Collections.Generic; using DSharpPlus.Entities; diff --git a/src/core/DSharpPlus.Core.Models/AuditLogs/AuditLog.cs b/src/core/DSharpPlus.Core.Models/AuditLogs/AuditLog.cs index 66d207a78f..557b209bf0 100644 --- a/src/core/DSharpPlus.Core.Models/AuditLogs/AuditLog.cs +++ b/src/core/DSharpPlus.Core.Models/AuditLogs/AuditLog.cs @@ -2,6 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + using System.Collections.Generic; using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/AuditLogs/AuditLogChange.cs b/src/core/DSharpPlus.Core.Models/AuditLogs/AuditLogChange.cs index a2b1c1de3d..5140489daa 100644 --- a/src/core/DSharpPlus.Core.Models/AuditLogs/AuditLogChange.cs +++ b/src/core/DSharpPlus.Core.Models/AuditLogs/AuditLogChange.cs @@ -2,6 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + using System.Text.Json; using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/AuditLogs/AuditLogEntry.cs b/src/core/DSharpPlus.Core.Models/AuditLogs/AuditLogEntry.cs index 15b68aec2e..8d8b284198 100644 --- a/src/core/DSharpPlus.Core.Models/AuditLogs/AuditLogEntry.cs +++ b/src/core/DSharpPlus.Core.Models/AuditLogs/AuditLogEntry.cs @@ -2,6 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + using System.Collections.Generic; using DSharpPlus.Entities; diff --git a/src/core/DSharpPlus.Core.Models/AuditLogs/AuditLogEntryInfo.cs b/src/core/DSharpPlus.Core.Models/AuditLogs/AuditLogEntryInfo.cs index 6bada1ff4a..9584035679 100644 --- a/src/core/DSharpPlus.Core.Models/AuditLogs/AuditLogEntryInfo.cs +++ b/src/core/DSharpPlus.Core.Models/AuditLogs/AuditLogEntryInfo.cs @@ -2,6 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + using Remora.Rest.Core; using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/AutoModeration/AutoModerationAction.cs b/src/core/DSharpPlus.Core.Models/AutoModeration/AutoModerationAction.cs index 28f154bbee..0f16ece311 100644 --- a/src/core/DSharpPlus.Core.Models/AutoModeration/AutoModerationAction.cs +++ b/src/core/DSharpPlus.Core.Models/AutoModeration/AutoModerationAction.cs @@ -2,6 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + using DSharpPlus.Entities; using Remora.Rest.Core; diff --git a/src/core/DSharpPlus.Core.Models/AutoModeration/AutoModerationRule.cs b/src/core/DSharpPlus.Core.Models/AutoModeration/AutoModerationRule.cs index 0753b48ae8..caa84b4687 100644 --- a/src/core/DSharpPlus.Core.Models/AutoModeration/AutoModerationRule.cs +++ b/src/core/DSharpPlus.Core.Models/AutoModeration/AutoModerationRule.cs @@ -2,6 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + using System.Collections.Generic; using DSharpPlus.Entities; diff --git a/src/core/DSharpPlus.Core.Models/AutoModeration/AutoModerationTriggerMetadata.cs b/src/core/DSharpPlus.Core.Models/AutoModeration/AutoModerationTriggerMetadata.cs index 42091ead2d..3a3e13728b 100644 --- a/src/core/DSharpPlus.Core.Models/AutoModeration/AutoModerationTriggerMetadata.cs +++ b/src/core/DSharpPlus.Core.Models/AutoModeration/AutoModerationTriggerMetadata.cs @@ -2,6 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + using System.Collections.Generic; using DSharpPlus.Entities; diff --git a/src/core/DSharpPlus.Core.Models/AutoModeration/BlockMessageActionMetadata.cs b/src/core/DSharpPlus.Core.Models/AutoModeration/BlockMessageActionMetadata.cs index 233718f266..9aaecaa0ad 100644 --- a/src/core/DSharpPlus.Core.Models/AutoModeration/BlockMessageActionMetadata.cs +++ b/src/core/DSharpPlus.Core.Models/AutoModeration/BlockMessageActionMetadata.cs @@ -2,6 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + using DSharpPlus.Entities; using Remora.Rest.Core; diff --git a/src/core/DSharpPlus.Core.Models/AutoModeration/PartialAutoModerationRule.cs b/src/core/DSharpPlus.Core.Models/AutoModeration/PartialAutoModerationRule.cs index ab5fec2dc6..d1dd62fe5d 100644 --- a/src/core/DSharpPlus.Core.Models/AutoModeration/PartialAutoModerationRule.cs +++ b/src/core/DSharpPlus.Core.Models/AutoModeration/PartialAutoModerationRule.cs @@ -2,6 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + using System.Collections.Generic; using DSharpPlus.Entities; diff --git a/src/core/DSharpPlus.Core.Models/AutoModeration/SendAlertMessageActionMetadata.cs b/src/core/DSharpPlus.Core.Models/AutoModeration/SendAlertMessageActionMetadata.cs index dc64b4655b..6b4a071646 100644 --- a/src/core/DSharpPlus.Core.Models/AutoModeration/SendAlertMessageActionMetadata.cs +++ b/src/core/DSharpPlus.Core.Models/AutoModeration/SendAlertMessageActionMetadata.cs @@ -2,6 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + using DSharpPlus.Entities; using Remora.Rest.Core; diff --git a/src/core/DSharpPlus.Core.Models/AutoModeration/TimeoutActionMetadata.cs b/src/core/DSharpPlus.Core.Models/AutoModeration/TimeoutActionMetadata.cs index 83daac471f..edf6e39bfc 100644 --- a/src/core/DSharpPlus.Core.Models/AutoModeration/TimeoutActionMetadata.cs +++ b/src/core/DSharpPlus.Core.Models/AutoModeration/TimeoutActionMetadata.cs @@ -2,6 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + using DSharpPlus.Entities; using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/Channels/AllowedMentions.cs b/src/core/DSharpPlus.Core.Models/Channels/AllowedMentions.cs index 2a4426f0ac..25562c0e0b 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/AllowedMentions.cs +++ b/src/core/DSharpPlus.Core.Models/Channels/AllowedMentions.cs @@ -2,6 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + using System.Collections.Generic; using Remora.Rest.Core; diff --git a/src/core/DSharpPlus.Core.Models/Channels/Attachment.cs b/src/core/DSharpPlus.Core.Models/Channels/Attachment.cs index e97fbe4cda..e95a8e8d36 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/Attachment.cs +++ b/src/core/DSharpPlus.Core.Models/Channels/Attachment.cs @@ -2,6 +2,14 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; + +using DSharpPlus.Entities; + using Remora.Rest.Core; using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/Channels/Channel.cs b/src/core/DSharpPlus.Core.Models/Channels/Channel.cs index 60ee678bd6..da991f9859 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/Channel.cs +++ b/src/core/DSharpPlus.Core.Models/Channels/Channel.cs @@ -2,6 +2,13 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; +using System.Collections.Generic; + using DSharpPlus.Entities; using Remora.Rest.Core; diff --git a/src/core/DSharpPlus.Core.Models/Channels/ChannelMention.cs b/src/core/DSharpPlus.Core.Models/Channels/ChannelMention.cs index f76cb15ca6..894116db53 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/ChannelMention.cs +++ b/src/core/DSharpPlus.Core.Models/Channels/ChannelMention.cs @@ -2,6 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + using DSharpPlus.Entities; using Remora.Rest.Core; diff --git a/src/core/DSharpPlus.Core.Models/Channels/ChannelOverwrite.cs b/src/core/DSharpPlus.Core.Models/Channels/ChannelOverwrite.cs index 6db39029c0..d004c54b81 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/ChannelOverwrite.cs +++ b/src/core/DSharpPlus.Core.Models/Channels/ChannelOverwrite.cs @@ -2,6 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + using DSharpPlus.Entities; using Remora.Rest.Core; diff --git a/src/core/DSharpPlus.Core.Models/Channels/DefaultReaction.cs b/src/core/DSharpPlus.Core.Models/Channels/DefaultReaction.cs index 9bb3f40cc7..a9844a2b25 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/DefaultReaction.cs +++ b/src/core/DSharpPlus.Core.Models/Channels/DefaultReaction.cs @@ -2,6 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + using Remora.Rest.Core; using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/Channels/Embed.cs b/src/core/DSharpPlus.Core.Models/Channels/Embed.cs index 08adc47ee0..cbbbd4e9d6 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/Embed.cs +++ b/src/core/DSharpPlus.Core.Models/Channels/Embed.cs @@ -2,6 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + using System; using System.Collections.Generic; diff --git a/src/core/DSharpPlus.Core.Models/Channels/EmbedAuthor.cs b/src/core/DSharpPlus.Core.Models/Channels/EmbedAuthor.cs index 6877059b30..3a35428421 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/EmbedAuthor.cs +++ b/src/core/DSharpPlus.Core.Models/Channels/EmbedAuthor.cs @@ -2,6 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + using Remora.Rest.Core; using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/Channels/EmbedField.cs b/src/core/DSharpPlus.Core.Models/Channels/EmbedField.cs index a9765807b2..aa94d3c3f2 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/EmbedField.cs +++ b/src/core/DSharpPlus.Core.Models/Channels/EmbedField.cs @@ -2,6 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + using Remora.Rest.Core; using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/Channels/EmbedFooter.cs b/src/core/DSharpPlus.Core.Models/Channels/EmbedFooter.cs index d526de5394..8b59b65617 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/EmbedFooter.cs +++ b/src/core/DSharpPlus.Core.Models/Channels/EmbedFooter.cs @@ -2,6 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + using Remora.Rest.Core; using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/Channels/EmbedImage.cs b/src/core/DSharpPlus.Core.Models/Channels/EmbedImage.cs index 83f118fa60..c6ae510dec 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/EmbedImage.cs +++ b/src/core/DSharpPlus.Core.Models/Channels/EmbedImage.cs @@ -2,6 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + using Remora.Rest.Core; using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/Channels/EmbedProvider.cs b/src/core/DSharpPlus.Core.Models/Channels/EmbedProvider.cs index 9596ffb0a9..7c2543fd6c 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/EmbedProvider.cs +++ b/src/core/DSharpPlus.Core.Models/Channels/EmbedProvider.cs @@ -2,6 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + using Remora.Rest.Core; using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/Channels/EmbedThumbnail.cs b/src/core/DSharpPlus.Core.Models/Channels/EmbedThumbnail.cs index ebe009eeb1..3dfc7a3419 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/EmbedThumbnail.cs +++ b/src/core/DSharpPlus.Core.Models/Channels/EmbedThumbnail.cs @@ -2,6 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + using Remora.Rest.Core; using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/Channels/EmbedVideo.cs b/src/core/DSharpPlus.Core.Models/Channels/EmbedVideo.cs index b614ca542b..72a6e67ed2 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/EmbedVideo.cs +++ b/src/core/DSharpPlus.Core.Models/Channels/EmbedVideo.cs @@ -2,6 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + using Remora.Rest.Core; using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/Channels/FollowedChannel.cs b/src/core/DSharpPlus.Core.Models/Channels/FollowedChannel.cs index 998f0a717c..38d20b3886 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/FollowedChannel.cs +++ b/src/core/DSharpPlus.Core.Models/Channels/FollowedChannel.cs @@ -2,6 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + using Remora.Rest.Core; using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/Channels/ForumTag.cs b/src/core/DSharpPlus.Core.Models/Channels/ForumTag.cs index c43364b8a3..93fd84c8b2 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/ForumTag.cs +++ b/src/core/DSharpPlus.Core.Models/Channels/ForumTag.cs @@ -2,6 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + using Remora.Rest.Core; using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/Channels/Message.cs b/src/core/DSharpPlus.Core.Models/Channels/Message.cs index 85af238df4..49b44d4e4c 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/Message.cs +++ b/src/core/DSharpPlus.Core.Models/Channels/Message.cs @@ -2,6 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + using System; using System.Collections.Generic; diff --git a/src/core/DSharpPlus.Core.Models/Channels/MessageActivity.cs b/src/core/DSharpPlus.Core.Models/Channels/MessageActivity.cs index f3ca1b0608..be28dd0b09 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/MessageActivity.cs +++ b/src/core/DSharpPlus.Core.Models/Channels/MessageActivity.cs @@ -2,6 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + using DSharpPlus.Entities; using Remora.Rest.Core; diff --git a/src/core/DSharpPlus.Core.Models/Channels/MessageReference.cs b/src/core/DSharpPlus.Core.Models/Channels/MessageReference.cs index 0dd81b06c7..5a832236d7 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/MessageReference.cs +++ b/src/core/DSharpPlus.Core.Models/Channels/MessageReference.cs @@ -2,6 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + using Remora.Rest.Core; using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/Channels/PartialAttachment.cs b/src/core/DSharpPlus.Core.Models/Channels/PartialAttachment.cs index d9ffcb00eb..7f869cda18 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/PartialAttachment.cs +++ b/src/core/DSharpPlus.Core.Models/Channels/PartialAttachment.cs @@ -2,6 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + using System; using DSharpPlus.Entities; diff --git a/src/core/DSharpPlus.Core.Models/Channels/PartialChannel.cs b/src/core/DSharpPlus.Core.Models/Channels/PartialChannel.cs index e5c81682b5..c0716d2381 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/PartialChannel.cs +++ b/src/core/DSharpPlus.Core.Models/Channels/PartialChannel.cs @@ -2,6 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + using System; using System.Collections.Generic; diff --git a/src/core/DSharpPlus.Core.Models/Channels/PartialChannelOverwrite.cs b/src/core/DSharpPlus.Core.Models/Channels/PartialChannelOverwrite.cs index ccc2892b10..1298bcf6e4 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/PartialChannelOverwrite.cs +++ b/src/core/DSharpPlus.Core.Models/Channels/PartialChannelOverwrite.cs @@ -2,6 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + using DSharpPlus.Entities; using Remora.Rest.Core; diff --git a/src/core/DSharpPlus.Core.Models/Channels/PartialMessage.cs b/src/core/DSharpPlus.Core.Models/Channels/PartialMessage.cs index 6dc583ddfa..edc9346de1 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/PartialMessage.cs +++ b/src/core/DSharpPlus.Core.Models/Channels/PartialMessage.cs @@ -2,6 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + using System; using System.Collections.Generic; diff --git a/src/core/DSharpPlus.Core.Models/Channels/Reaction.cs b/src/core/DSharpPlus.Core.Models/Channels/Reaction.cs index 7801178096..493cb2219a 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/Reaction.cs +++ b/src/core/DSharpPlus.Core.Models/Channels/Reaction.cs @@ -1,3 +1,7 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/Channels/RoleSubscriptionData.cs b/src/core/DSharpPlus.Core.Models/Channels/RoleSubscriptionData.cs index 3f84822729..bdf7c8fde2 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/RoleSubscriptionData.cs +++ b/src/core/DSharpPlus.Core.Models/Channels/RoleSubscriptionData.cs @@ -2,6 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + using Remora.Rest.Core; using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/Channels/ThreadMember.cs b/src/core/DSharpPlus.Core.Models/Channels/ThreadMember.cs index 5b91c94f72..4c2548b3fe 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/ThreadMember.cs +++ b/src/core/DSharpPlus.Core.Models/Channels/ThreadMember.cs @@ -2,6 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + using System; using Remora.Rest.Core; diff --git a/src/core/DSharpPlus.Core.Models/Channels/ThreadMetadata.cs b/src/core/DSharpPlus.Core.Models/Channels/ThreadMetadata.cs index 5447aef135..eb40ca60a4 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/ThreadMetadata.cs +++ b/src/core/DSharpPlus.Core.Models/Channels/ThreadMetadata.cs @@ -2,6 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + using System; using Remora.Rest.Core; diff --git a/src/core/DSharpPlus.Core.Models/Emojis/Emoji.cs b/src/core/DSharpPlus.Core.Models/Emojis/Emoji.cs index 30760612f6..6b84f2feac 100644 --- a/src/core/DSharpPlus.Core.Models/Emojis/Emoji.cs +++ b/src/core/DSharpPlus.Core.Models/Emojis/Emoji.cs @@ -2,6 +2,12 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + using Remora.Rest.Core; using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/Emojis/PartialEmoji.cs b/src/core/DSharpPlus.Core.Models/Emojis/PartialEmoji.cs index bc110d00ac..fa5a8fbfe9 100644 --- a/src/core/DSharpPlus.Core.Models/Emojis/PartialEmoji.cs +++ b/src/core/DSharpPlus.Core.Models/Emojis/PartialEmoji.cs @@ -2,6 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + using System.Collections.Generic; using Remora.Rest.Core; diff --git a/src/core/DSharpPlus.Core.Models/GuildTemplates/Template.cs b/src/core/DSharpPlus.Core.Models/GuildTemplates/Template.cs index 1354066d7e..69b4b9653b 100644 --- a/src/core/DSharpPlus.Core.Models/GuildTemplates/Template.cs +++ b/src/core/DSharpPlus.Core.Models/GuildTemplates/Template.cs @@ -2,6 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + using System; using Remora.Rest.Core; diff --git a/src/core/DSharpPlus.Core.Models/Guilds/Ban.cs b/src/core/DSharpPlus.Core.Models/Guilds/Ban.cs index be2077d9c1..80ba39301c 100644 --- a/src/core/DSharpPlus.Core.Models/Guilds/Ban.cs +++ b/src/core/DSharpPlus.Core.Models/Guilds/Ban.cs @@ -1,3 +1,7 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/Guilds/Guild.cs b/src/core/DSharpPlus.Core.Models/Guilds/Guild.cs index eccf04b916..06ec8f68cd 100644 --- a/src/core/DSharpPlus.Core.Models/Guilds/Guild.cs +++ b/src/core/DSharpPlus.Core.Models/Guilds/Guild.cs @@ -2,6 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + using System.Collections.Generic; using DSharpPlus.Entities; diff --git a/src/core/DSharpPlus.Core.Models/Guilds/GuildMember.cs b/src/core/DSharpPlus.Core.Models/Guilds/GuildMember.cs index 395c7abfee..2dea0e5e75 100644 --- a/src/core/DSharpPlus.Core.Models/Guilds/GuildMember.cs +++ b/src/core/DSharpPlus.Core.Models/Guilds/GuildMember.cs @@ -2,6 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + using System; using System.Collections.Generic; diff --git a/src/core/DSharpPlus.Core.Models/Guilds/GuildPreview.cs b/src/core/DSharpPlus.Core.Models/Guilds/GuildPreview.cs index 94a10010c3..e92b392fa7 100644 --- a/src/core/DSharpPlus.Core.Models/Guilds/GuildPreview.cs +++ b/src/core/DSharpPlus.Core.Models/Guilds/GuildPreview.cs @@ -2,6 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + using System.Collections.Generic; using Remora.Rest.Core; diff --git a/src/core/DSharpPlus.Core.Models/Guilds/GuildWidget.cs b/src/core/DSharpPlus.Core.Models/Guilds/GuildWidget.cs index fa3c5fe0e8..38b2f3b83a 100644 --- a/src/core/DSharpPlus.Core.Models/Guilds/GuildWidget.cs +++ b/src/core/DSharpPlus.Core.Models/Guilds/GuildWidget.cs @@ -2,6 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + using System.Collections.Generic; using Remora.Rest.Core; diff --git a/src/core/DSharpPlus.Core.Models/Guilds/GuildWidgetSettings.cs b/src/core/DSharpPlus.Core.Models/Guilds/GuildWidgetSettings.cs index d90548f0db..44db8ade04 100644 --- a/src/core/DSharpPlus.Core.Models/Guilds/GuildWidgetSettings.cs +++ b/src/core/DSharpPlus.Core.Models/Guilds/GuildWidgetSettings.cs @@ -2,6 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + using Remora.Rest.Core; using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/Guilds/Integration.cs b/src/core/DSharpPlus.Core.Models/Guilds/Integration.cs index 45fc42a203..3c66947133 100644 --- a/src/core/DSharpPlus.Core.Models/Guilds/Integration.cs +++ b/src/core/DSharpPlus.Core.Models/Guilds/Integration.cs @@ -2,6 +2,15 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; +using System.Collections.Generic; + +using DSharpPlus.Entities; + using Remora.Rest.Core; using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/Guilds/IntegrationAccount.cs b/src/core/DSharpPlus.Core.Models/Guilds/IntegrationAccount.cs index d102f4a521..e52285e1a4 100644 --- a/src/core/DSharpPlus.Core.Models/Guilds/IntegrationAccount.cs +++ b/src/core/DSharpPlus.Core.Models/Guilds/IntegrationAccount.cs @@ -1,3 +1,7 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/Guilds/IntegrationApplication.cs b/src/core/DSharpPlus.Core.Models/Guilds/IntegrationApplication.cs index cf03ea40eb..a0ad3ce446 100644 --- a/src/core/DSharpPlus.Core.Models/Guilds/IntegrationApplication.cs +++ b/src/core/DSharpPlus.Core.Models/Guilds/IntegrationApplication.cs @@ -2,6 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + using Remora.Rest.Core; using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/Guilds/Onboarding.cs b/src/core/DSharpPlus.Core.Models/Guilds/Onboarding.cs index 11eab8a957..06ca4e8bbf 100644 --- a/src/core/DSharpPlus.Core.Models/Guilds/Onboarding.cs +++ b/src/core/DSharpPlus.Core.Models/Guilds/Onboarding.cs @@ -2,6 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + using System.Collections.Generic; using DSharpPlus.Entities; diff --git a/src/core/DSharpPlus.Core.Models/Guilds/OnboardingPrompt.cs b/src/core/DSharpPlus.Core.Models/Guilds/OnboardingPrompt.cs index 75c30610b9..f270d3135d 100644 --- a/src/core/DSharpPlus.Core.Models/Guilds/OnboardingPrompt.cs +++ b/src/core/DSharpPlus.Core.Models/Guilds/OnboardingPrompt.cs @@ -2,6 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + using System.Collections.Generic; using DSharpPlus.Entities; diff --git a/src/core/DSharpPlus.Core.Models/Guilds/OnboardingPromptOption.cs b/src/core/DSharpPlus.Core.Models/Guilds/OnboardingPromptOption.cs index c3055ac3d1..ad5fc98b9f 100644 --- a/src/core/DSharpPlus.Core.Models/Guilds/OnboardingPromptOption.cs +++ b/src/core/DSharpPlus.Core.Models/Guilds/OnboardingPromptOption.cs @@ -2,6 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + using System.Collections.Generic; using Remora.Rest.Core; diff --git a/src/core/DSharpPlus.Core.Models/Guilds/PartialGuild.cs b/src/core/DSharpPlus.Core.Models/Guilds/PartialGuild.cs index 31a612146e..322b529116 100644 --- a/src/core/DSharpPlus.Core.Models/Guilds/PartialGuild.cs +++ b/src/core/DSharpPlus.Core.Models/Guilds/PartialGuild.cs @@ -2,6 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + using System.Collections.Generic; using DSharpPlus.Entities; diff --git a/src/core/DSharpPlus.Core.Models/Guilds/PartialGuildMember.cs b/src/core/DSharpPlus.Core.Models/Guilds/PartialGuildMember.cs index 35a850a610..ca080e4a0f 100644 --- a/src/core/DSharpPlus.Core.Models/Guilds/PartialGuildMember.cs +++ b/src/core/DSharpPlus.Core.Models/Guilds/PartialGuildMember.cs @@ -2,6 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + using System; using System.Collections.Generic; diff --git a/src/core/DSharpPlus.Core.Models/Guilds/PartialIntegration.cs b/src/core/DSharpPlus.Core.Models/Guilds/PartialIntegration.cs index fcc4cafa91..1658d30df5 100644 --- a/src/core/DSharpPlus.Core.Models/Guilds/PartialIntegration.cs +++ b/src/core/DSharpPlus.Core.Models/Guilds/PartialIntegration.cs @@ -2,6 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + using System; using System.Collections.Generic; diff --git a/src/core/DSharpPlus.Core.Models/Guilds/PartialRole.cs b/src/core/DSharpPlus.Core.Models/Guilds/PartialRole.cs index c94ccb5841..95919a83ed 100644 --- a/src/core/DSharpPlus.Core.Models/Guilds/PartialRole.cs +++ b/src/core/DSharpPlus.Core.Models/Guilds/PartialRole.cs @@ -2,6 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + using DSharpPlus.Entities; using Remora.Rest.Core; diff --git a/src/core/DSharpPlus.Core.Models/Guilds/Role.cs b/src/core/DSharpPlus.Core.Models/Guilds/Role.cs index 3a6b9df0c6..10a205b426 100644 --- a/src/core/DSharpPlus.Core.Models/Guilds/Role.cs +++ b/src/core/DSharpPlus.Core.Models/Guilds/Role.cs @@ -2,6 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + using DSharpPlus.Entities; using Remora.Rest.Core; diff --git a/src/core/DSharpPlus.Core.Models/Guilds/RoleTags.cs b/src/core/DSharpPlus.Core.Models/Guilds/RoleTags.cs index 06d01b142b..7856193b55 100644 --- a/src/core/DSharpPlus.Core.Models/Guilds/RoleTags.cs +++ b/src/core/DSharpPlus.Core.Models/Guilds/RoleTags.cs @@ -2,6 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + using Remora.Rest.Core; using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/Guilds/WelcomeScreen.cs b/src/core/DSharpPlus.Core.Models/Guilds/WelcomeScreen.cs index f60fcb346a..7f19c23e69 100644 --- a/src/core/DSharpPlus.Core.Models/Guilds/WelcomeScreen.cs +++ b/src/core/DSharpPlus.Core.Models/Guilds/WelcomeScreen.cs @@ -2,6 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + using System.Collections.Generic; using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/Guilds/WelcomeScreenChannel.cs b/src/core/DSharpPlus.Core.Models/Guilds/WelcomeScreenChannel.cs index 9cd1a33236..041098b0b6 100644 --- a/src/core/DSharpPlus.Core.Models/Guilds/WelcomeScreenChannel.cs +++ b/src/core/DSharpPlus.Core.Models/Guilds/WelcomeScreenChannel.cs @@ -2,6 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + using Remora.Rest.Core; using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/Interactions/ApplicationCommandInteractionData.cs b/src/core/DSharpPlus.Core.Models/Interactions/ApplicationCommandInteractionData.cs index 2dd94fccf5..f5b1f5bd9f 100644 --- a/src/core/DSharpPlus.Core.Models/Interactions/ApplicationCommandInteractionData.cs +++ b/src/core/DSharpPlus.Core.Models/Interactions/ApplicationCommandInteractionData.cs @@ -2,6 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + using System.Collections.Generic; using DSharpPlus.Entities; diff --git a/src/core/DSharpPlus.Core.Models/Interactions/ApplicationCommandInteractionDataOption.cs b/src/core/DSharpPlus.Core.Models/Interactions/ApplicationCommandInteractionDataOption.cs index b5282cc35b..54be18fe4e 100644 --- a/src/core/DSharpPlus.Core.Models/Interactions/ApplicationCommandInteractionDataOption.cs +++ b/src/core/DSharpPlus.Core.Models/Interactions/ApplicationCommandInteractionDataOption.cs @@ -2,6 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + using System.Collections.Generic; using DSharpPlus.Entities; diff --git a/src/core/DSharpPlus.Core.Models/Interactions/AutocompleteCallbackData.cs b/src/core/DSharpPlus.Core.Models/Interactions/AutocompleteCallbackData.cs index 9c825386c6..0b7a539730 100644 --- a/src/core/DSharpPlus.Core.Models/Interactions/AutocompleteCallbackData.cs +++ b/src/core/DSharpPlus.Core.Models/Interactions/AutocompleteCallbackData.cs @@ -2,6 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + using System.Collections.Generic; using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/Interactions/AutocompleteInteractionData.cs b/src/core/DSharpPlus.Core.Models/Interactions/AutocompleteInteractionData.cs index af22013362..bbaa9daeb8 100644 --- a/src/core/DSharpPlus.Core.Models/Interactions/AutocompleteInteractionData.cs +++ b/src/core/DSharpPlus.Core.Models/Interactions/AutocompleteInteractionData.cs @@ -2,6 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + using DSharpPlus.Entities; using Remora.Rest.Core; diff --git a/src/core/DSharpPlus.Core.Models/Interactions/AutocompleteInteractionDataOption.cs b/src/core/DSharpPlus.Core.Models/Interactions/AutocompleteInteractionDataOption.cs index a993616d5e..1927349e6f 100644 --- a/src/core/DSharpPlus.Core.Models/Interactions/AutocompleteInteractionDataOption.cs +++ b/src/core/DSharpPlus.Core.Models/Interactions/AutocompleteInteractionDataOption.cs @@ -2,6 +2,16 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Entities; + +using OneOf; + using Remora.Rest.Core; using DSharpPlus.Core.Abstractions.Models; @@ -11,6 +21,18 @@ namespace DSharpPlus.Core.Models; /// public sealed record AutocompleteInteractionDataOption : IAutocompleteInteractionDataOption { + /// + public required string Name { get; init; } + + /// + public required DiscordApplicationCommandOptionType Type { get; init; } + + /// + public Optional> Value { get; init; } + + /// + public Optional> Options { get; init; } + /// public Optional Focused { get; init; } } \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/Interactions/Interaction.cs b/src/core/DSharpPlus.Core.Models/Interactions/Interaction.cs index 56f17fe5b7..ceb5e7f4bd 100644 --- a/src/core/DSharpPlus.Core.Models/Interactions/Interaction.cs +++ b/src/core/DSharpPlus.Core.Models/Interactions/Interaction.cs @@ -2,6 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + using DSharpPlus.Entities; using Remora.Rest.Core; diff --git a/src/core/DSharpPlus.Core.Models/Interactions/InteractionResponse.cs b/src/core/DSharpPlus.Core.Models/Interactions/InteractionResponse.cs index 8575b0d28d..2522474d48 100644 --- a/src/core/DSharpPlus.Core.Models/Interactions/InteractionResponse.cs +++ b/src/core/DSharpPlus.Core.Models/Interactions/InteractionResponse.cs @@ -2,6 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + using DSharpPlus.Entities; using Remora.Rest.Core; diff --git a/src/core/DSharpPlus.Core.Models/Interactions/MessageCallbackData.cs b/src/core/DSharpPlus.Core.Models/Interactions/MessageCallbackData.cs index 82fd583813..a0cd61d65f 100644 --- a/src/core/DSharpPlus.Core.Models/Interactions/MessageCallbackData.cs +++ b/src/core/DSharpPlus.Core.Models/Interactions/MessageCallbackData.cs @@ -2,6 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + using System.Collections.Generic; using DSharpPlus.Entities; diff --git a/src/core/DSharpPlus.Core.Models/Interactions/MessageComponentInteractionData.cs b/src/core/DSharpPlus.Core.Models/Interactions/MessageComponentInteractionData.cs index 96f9208bb2..45a6f8d1c2 100644 --- a/src/core/DSharpPlus.Core.Models/Interactions/MessageComponentInteractionData.cs +++ b/src/core/DSharpPlus.Core.Models/Interactions/MessageComponentInteractionData.cs @@ -2,6 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + using System.Collections.Generic; using DSharpPlus.Entities; diff --git a/src/core/DSharpPlus.Core.Models/Interactions/MessageInteraction.cs b/src/core/DSharpPlus.Core.Models/Interactions/MessageInteraction.cs index 421a523b9b..287be0e7d0 100644 --- a/src/core/DSharpPlus.Core.Models/Interactions/MessageInteraction.cs +++ b/src/core/DSharpPlus.Core.Models/Interactions/MessageInteraction.cs @@ -2,6 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + using DSharpPlus.Entities; using Remora.Rest.Core; diff --git a/src/core/DSharpPlus.Core.Models/Interactions/ModalCallbackData.cs b/src/core/DSharpPlus.Core.Models/Interactions/ModalCallbackData.cs index f3624aa537..862118391d 100644 --- a/src/core/DSharpPlus.Core.Models/Interactions/ModalCallbackData.cs +++ b/src/core/DSharpPlus.Core.Models/Interactions/ModalCallbackData.cs @@ -2,6 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + using System.Collections.Generic; using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/Interactions/ModalInteractionData.cs b/src/core/DSharpPlus.Core.Models/Interactions/ModalInteractionData.cs index 6095abdc12..4be549559c 100644 --- a/src/core/DSharpPlus.Core.Models/Interactions/ModalInteractionData.cs +++ b/src/core/DSharpPlus.Core.Models/Interactions/ModalInteractionData.cs @@ -2,6 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + using System.Collections.Generic; using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/Interactions/ResolvedData.cs b/src/core/DSharpPlus.Core.Models/Interactions/ResolvedData.cs index ba856a6bf9..03e7c5c97c 100644 --- a/src/core/DSharpPlus.Core.Models/Interactions/ResolvedData.cs +++ b/src/core/DSharpPlus.Core.Models/Interactions/ResolvedData.cs @@ -2,6 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + using System.Collections.Generic; using Remora.Rest.Core; diff --git a/src/core/DSharpPlus.Core.Models/Invites/Invite.cs b/src/core/DSharpPlus.Core.Models/Invites/Invite.cs index cf48f0d1fc..fe27da2968 100644 --- a/src/core/DSharpPlus.Core.Models/Invites/Invite.cs +++ b/src/core/DSharpPlus.Core.Models/Invites/Invite.cs @@ -2,6 +2,14 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; + +using DSharpPlus.Entities; + using Remora.Rest.Core; using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/Invites/PartialInvite.cs b/src/core/DSharpPlus.Core.Models/Invites/PartialInvite.cs index 8aa0dceb34..35cec101d2 100644 --- a/src/core/DSharpPlus.Core.Models/Invites/PartialInvite.cs +++ b/src/core/DSharpPlus.Core.Models/Invites/PartialInvite.cs @@ -2,6 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + using System; using DSharpPlus.Entities; diff --git a/src/core/DSharpPlus.Core.Models/MessageComponents/ActionRowComponent.cs b/src/core/DSharpPlus.Core.Models/MessageComponents/ActionRowComponent.cs index 0dcaa0a843..a4ef14f74b 100644 --- a/src/core/DSharpPlus.Core.Models/MessageComponents/ActionRowComponent.cs +++ b/src/core/DSharpPlus.Core.Models/MessageComponents/ActionRowComponent.cs @@ -2,6 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + using System.Collections.Generic; using DSharpPlus.Entities; diff --git a/src/core/DSharpPlus.Core.Models/MessageComponents/ButtonComponent.cs b/src/core/DSharpPlus.Core.Models/MessageComponents/ButtonComponent.cs index c5cd2ad628..35fabd6eea 100644 --- a/src/core/DSharpPlus.Core.Models/MessageComponents/ButtonComponent.cs +++ b/src/core/DSharpPlus.Core.Models/MessageComponents/ButtonComponent.cs @@ -2,6 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + using DSharpPlus.Entities; using Remora.Rest.Core; diff --git a/src/core/DSharpPlus.Core.Models/MessageComponents/ChannelSelectComponent.cs b/src/core/DSharpPlus.Core.Models/MessageComponents/ChannelSelectComponent.cs index 5eced6e93b..8e90d8474d 100644 --- a/src/core/DSharpPlus.Core.Models/MessageComponents/ChannelSelectComponent.cs +++ b/src/core/DSharpPlus.Core.Models/MessageComponents/ChannelSelectComponent.cs @@ -2,6 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + using System.Collections.Generic; using DSharpPlus.Entities; diff --git a/src/core/DSharpPlus.Core.Models/MessageComponents/InteractiveComponent.cs b/src/core/DSharpPlus.Core.Models/MessageComponents/InteractiveComponent.cs deleted file mode 100644 index ae322b3d51..0000000000 --- a/src/core/DSharpPlus.Core.Models/MessageComponents/InteractiveComponent.cs +++ /dev/null @@ -1,16 +0,0 @@ -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -using DSharpPlus.Entities; - -using DSharpPlus.Core.Abstractions.Models; - -namespace DSharpPlus.Core.Models; - -/// -public sealed record InteractiveComponent : IInteractiveComponent -{ - /// - public required DiscordMessageComponentType Type { get; init; } -} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/MessageComponents/MentionableSelectComponent.cs b/src/core/DSharpPlus.Core.Models/MessageComponents/MentionableSelectComponent.cs index dbcca4a9d2..00a119dbac 100644 --- a/src/core/DSharpPlus.Core.Models/MessageComponents/MentionableSelectComponent.cs +++ b/src/core/DSharpPlus.Core.Models/MessageComponents/MentionableSelectComponent.cs @@ -2,6 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + using DSharpPlus.Entities; using Remora.Rest.Core; diff --git a/src/core/DSharpPlus.Core.Models/MessageComponents/RoleSelectComponent.cs b/src/core/DSharpPlus.Core.Models/MessageComponents/RoleSelectComponent.cs index dd98a0c8d9..be6c6a0f03 100644 --- a/src/core/DSharpPlus.Core.Models/MessageComponents/RoleSelectComponent.cs +++ b/src/core/DSharpPlus.Core.Models/MessageComponents/RoleSelectComponent.cs @@ -2,6 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + using DSharpPlus.Entities; using Remora.Rest.Core; diff --git a/src/core/DSharpPlus.Core.Models/MessageComponents/SelectOption.cs b/src/core/DSharpPlus.Core.Models/MessageComponents/SelectOption.cs index 4c2d46b891..aa7d9cdb31 100644 --- a/src/core/DSharpPlus.Core.Models/MessageComponents/SelectOption.cs +++ b/src/core/DSharpPlus.Core.Models/MessageComponents/SelectOption.cs @@ -2,6 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + using Remora.Rest.Core; using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/MessageComponents/StringSelectComponent.cs b/src/core/DSharpPlus.Core.Models/MessageComponents/StringSelectComponent.cs index b2660b2dca..e3884b8758 100644 --- a/src/core/DSharpPlus.Core.Models/MessageComponents/StringSelectComponent.cs +++ b/src/core/DSharpPlus.Core.Models/MessageComponents/StringSelectComponent.cs @@ -2,6 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + using System.Collections.Generic; using DSharpPlus.Entities; diff --git a/src/core/DSharpPlus.Core.Models/MessageComponents/TextInputComponent.cs b/src/core/DSharpPlus.Core.Models/MessageComponents/TextInputComponent.cs index 3a1e9efd7d..014ebb96d1 100644 --- a/src/core/DSharpPlus.Core.Models/MessageComponents/TextInputComponent.cs +++ b/src/core/DSharpPlus.Core.Models/MessageComponents/TextInputComponent.cs @@ -2,6 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + using DSharpPlus.Entities; using Remora.Rest.Core; diff --git a/src/core/DSharpPlus.Core.Models/MessageComponents/UserSelectComponent.cs b/src/core/DSharpPlus.Core.Models/MessageComponents/UserSelectComponent.cs index 25c283fcee..c6361deffe 100644 --- a/src/core/DSharpPlus.Core.Models/MessageComponents/UserSelectComponent.cs +++ b/src/core/DSharpPlus.Core.Models/MessageComponents/UserSelectComponent.cs @@ -2,6 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + using DSharpPlus.Entities; using Remora.Rest.Core; diff --git a/src/core/DSharpPlus.Core.Models/RoleConnections/RoleConnectionMetadata.cs b/src/core/DSharpPlus.Core.Models/RoleConnections/RoleConnectionMetadata.cs index 77dfb0f6e8..557f83e499 100644 --- a/src/core/DSharpPlus.Core.Models/RoleConnections/RoleConnectionMetadata.cs +++ b/src/core/DSharpPlus.Core.Models/RoleConnections/RoleConnectionMetadata.cs @@ -2,6 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + using System.Collections.Generic; using DSharpPlus.Entities; diff --git a/src/core/DSharpPlus.Core.Models/ScheduledEvents/PartialScheduledEvent.cs b/src/core/DSharpPlus.Core.Models/ScheduledEvents/PartialScheduledEvent.cs index 4504773bf4..5bf578641d 100644 --- a/src/core/DSharpPlus.Core.Models/ScheduledEvents/PartialScheduledEvent.cs +++ b/src/core/DSharpPlus.Core.Models/ScheduledEvents/PartialScheduledEvent.cs @@ -2,6 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + using DSharpPlus.Entities; using Remora.Rest.Core; diff --git a/src/core/DSharpPlus.Core.Models/ScheduledEvents/ScheduledEvent.cs b/src/core/DSharpPlus.Core.Models/ScheduledEvents/ScheduledEvent.cs index 96083d6e71..751cf6fa6f 100644 --- a/src/core/DSharpPlus.Core.Models/ScheduledEvents/ScheduledEvent.cs +++ b/src/core/DSharpPlus.Core.Models/ScheduledEvents/ScheduledEvent.cs @@ -2,11 +2,14 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using System; +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. using DSharpPlus.Entities; using Remora.Rest.Core; +using System; using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/ScheduledEvents/ScheduledEventUser.cs b/src/core/DSharpPlus.Core.Models/ScheduledEvents/ScheduledEventUser.cs index ee2dff1986..9e1312c668 100644 --- a/src/core/DSharpPlus.Core.Models/ScheduledEvents/ScheduledEventUser.cs +++ b/src/core/DSharpPlus.Core.Models/ScheduledEvents/ScheduledEventUser.cs @@ -2,6 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + using Remora.Rest.Core; using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/StageInstances/PartialStageInstance.cs b/src/core/DSharpPlus.Core.Models/StageInstances/PartialStageInstance.cs index 34545c5252..d1e210e907 100644 --- a/src/core/DSharpPlus.Core.Models/StageInstances/PartialStageInstance.cs +++ b/src/core/DSharpPlus.Core.Models/StageInstances/PartialStageInstance.cs @@ -2,6 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + using DSharpPlus.Entities; using Remora.Rest.Core; diff --git a/src/core/DSharpPlus.Core.Models/StageInstances/StageInstance.cs b/src/core/DSharpPlus.Core.Models/StageInstances/StageInstance.cs index bdeb7c1de1..dd0c1d6dac 100644 --- a/src/core/DSharpPlus.Core.Models/StageInstances/StageInstance.cs +++ b/src/core/DSharpPlus.Core.Models/StageInstances/StageInstance.cs @@ -2,7 +2,12 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + using DSharpPlus.Entities; + using Remora.Rest.Core; using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/Stickers/PartialSticker.cs b/src/core/DSharpPlus.Core.Models/Stickers/PartialSticker.cs index f8aac809fb..a106ad6563 100644 --- a/src/core/DSharpPlus.Core.Models/Stickers/PartialSticker.cs +++ b/src/core/DSharpPlus.Core.Models/Stickers/PartialSticker.cs @@ -2,6 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + using DSharpPlus.Entities; using Remora.Rest.Core; diff --git a/src/core/DSharpPlus.Core.Models/Stickers/Sticker.cs b/src/core/DSharpPlus.Core.Models/Stickers/Sticker.cs index 120ef599cb..a29c6552c4 100644 --- a/src/core/DSharpPlus.Core.Models/Stickers/Sticker.cs +++ b/src/core/DSharpPlus.Core.Models/Stickers/Sticker.cs @@ -2,6 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + using DSharpPlus.Entities; using Remora.Rest.Core; diff --git a/src/core/DSharpPlus.Core.Models/Stickers/StickerItem.cs b/src/core/DSharpPlus.Core.Models/Stickers/StickerItem.cs index 1c02604de5..3cc8f6d00d 100644 --- a/src/core/DSharpPlus.Core.Models/Stickers/StickerItem.cs +++ b/src/core/DSharpPlus.Core.Models/Stickers/StickerItem.cs @@ -2,6 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + using DSharpPlus.Entities; using Remora.Rest.Core; diff --git a/src/core/DSharpPlus.Core.Models/Stickers/StickerPack.cs b/src/core/DSharpPlus.Core.Models/Stickers/StickerPack.cs index d83f1c4b86..494f61fe73 100644 --- a/src/core/DSharpPlus.Core.Models/Stickers/StickerPack.cs +++ b/src/core/DSharpPlus.Core.Models/Stickers/StickerPack.cs @@ -2,6 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + using System.Collections.Generic; using Remora.Rest.Core; diff --git a/src/core/DSharpPlus.Core.Models/Teams/Team.cs b/src/core/DSharpPlus.Core.Models/Teams/Team.cs index 4e22073993..8589c3ae3c 100644 --- a/src/core/DSharpPlus.Core.Models/Teams/Team.cs +++ b/src/core/DSharpPlus.Core.Models/Teams/Team.cs @@ -2,6 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + using System.Collections.Generic; using Remora.Rest.Core; diff --git a/src/core/DSharpPlus.Core.Models/Teams/TeamMember.cs b/src/core/DSharpPlus.Core.Models/Teams/TeamMember.cs index c9bf06785c..324f02b558 100644 --- a/src/core/DSharpPlus.Core.Models/Teams/TeamMember.cs +++ b/src/core/DSharpPlus.Core.Models/Teams/TeamMember.cs @@ -2,6 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + using System.Collections.Generic; using DSharpPlus.Entities; diff --git a/src/core/DSharpPlus.Core.Models/Users/ApplicationRoleConnection.cs b/src/core/DSharpPlus.Core.Models/Users/ApplicationRoleConnection.cs index 8676778956..90a9c84f73 100644 --- a/src/core/DSharpPlus.Core.Models/Users/ApplicationRoleConnection.cs +++ b/src/core/DSharpPlus.Core.Models/Users/ApplicationRoleConnection.cs @@ -2,6 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + using System.Collections.Generic; using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/Users/Connection.cs b/src/core/DSharpPlus.Core.Models/Users/Connection.cs index 93cf9d26f9..5b63b970ba 100644 --- a/src/core/DSharpPlus.Core.Models/Users/Connection.cs +++ b/src/core/DSharpPlus.Core.Models/Users/Connection.cs @@ -2,6 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + using System.Collections.Generic; using DSharpPlus.Entities; diff --git a/src/core/DSharpPlus.Core.Models/Users/PartialUser.cs b/src/core/DSharpPlus.Core.Models/Users/PartialUser.cs index 07dda803e3..0c5181dedc 100644 --- a/src/core/DSharpPlus.Core.Models/Users/PartialUser.cs +++ b/src/core/DSharpPlus.Core.Models/Users/PartialUser.cs @@ -2,6 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + using DSharpPlus.Entities; using Remora.Rest.Core; diff --git a/src/core/DSharpPlus.Core.Models/Users/User.cs b/src/core/DSharpPlus.Core.Models/Users/User.cs index b6f72d315f..2b703470b4 100644 --- a/src/core/DSharpPlus.Core.Models/Users/User.cs +++ b/src/core/DSharpPlus.Core.Models/Users/User.cs @@ -2,6 +2,11 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Entities; using Remora.Rest.Core; using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/Voice/VoiceRegion.cs b/src/core/DSharpPlus.Core.Models/Voice/VoiceRegion.cs index 6fd9c671e0..0057c2d802 100644 --- a/src/core/DSharpPlus.Core.Models/Voice/VoiceRegion.cs +++ b/src/core/DSharpPlus.Core.Models/Voice/VoiceRegion.cs @@ -1,3 +1,7 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/Voice/VoiceState.cs b/src/core/DSharpPlus.Core.Models/Voice/VoiceState.cs index b66a70f416..5efe9edc52 100644 --- a/src/core/DSharpPlus.Core.Models/Voice/VoiceState.cs +++ b/src/core/DSharpPlus.Core.Models/Voice/VoiceState.cs @@ -2,6 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + using System; using Remora.Rest.Core; diff --git a/src/core/DSharpPlus.Core.Models/Webhooks/PartialWebhook.cs b/src/core/DSharpPlus.Core.Models/Webhooks/PartialWebhook.cs index 4c6d5558bb..13df3d4fc3 100644 --- a/src/core/DSharpPlus.Core.Models/Webhooks/PartialWebhook.cs +++ b/src/core/DSharpPlus.Core.Models/Webhooks/PartialWebhook.cs @@ -2,6 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + using DSharpPlus.Entities; using Remora.Rest.Core; diff --git a/src/core/DSharpPlus.Core.Models/Webhooks/Webhook.cs b/src/core/DSharpPlus.Core.Models/Webhooks/Webhook.cs index f9cf3aea5f..25a7b6f055 100644 --- a/src/core/DSharpPlus.Core.Models/Webhooks/Webhook.cs +++ b/src/core/DSharpPlus.Core.Models/Webhooks/Webhook.cs @@ -2,6 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + using DSharpPlus.Entities; using Remora.Rest.Core; diff --git a/tools/generators/Tools.Generators.GenerateConcreteObjects/Program.cs b/tools/generators/Tools.Generators.GenerateConcreteObjects/Program.cs index acfca639e4..538e369d92 100644 --- a/tools/generators/Tools.Generators.GenerateConcreteObjects/Program.cs +++ b/tools/generators/Tools.Generators.GenerateConcreteObjects/Program.cs @@ -164,6 +164,7 @@ Deleting counterparts to removed files... string outPath = path.Remove(index + 1, 1).Replace(input, output); StringBuilder writer = new(); + StringBuilder usings = new(); AnsiConsole.MarkupLine ( @@ -172,7 +173,7 @@ Deleting counterparts to removed files... """ ); - /*writer.WriteLine + usings.AppendLine ( """ // This Source Code form is subject to the terms of the Mozilla Public @@ -180,11 +181,11 @@ Deleting counterparts to removed files... // file, You can obtain one at https://mozilla.org/MPL/2.0/. """ - );*/ + ); foreach (UsingDirectiveSyntax @using in root.Usings) { - writer.Append(@using.ToFullString()); + usings.Append(@using.ToFullString()); } writer.Append @@ -350,6 +351,23 @@ public sealed record {{name.Text[1..]}} : {{name.Text}} continue; } + usings.Clear(); + + usings.AppendLine + ( +""" +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +""" + ); + + foreach (UsingDirectiveSyntax @using in partialRoot.Usings) + { + usings.Append(@using.ToFullString()); + } + Emitter.Emit ( writer, @@ -384,7 +402,7 @@ public sealed record {{name.Text[1..]}} : {{name.Text}} Directory.CreateDirectory(outInfo.DirectoryName!); } - string code = writer.ToString(); + string code = usings.Append(writer).ToString(); // remove the last newline before the final } // the windows conditional is because of CRLF taking up two characters, vs LF taking up one From e821c0d8a1558962bcdf690506e0239424cb75d4 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sun, 6 Aug 2023 17:00:22 +0200 Subject: [PATCH 081/323] remove the double license headers --- .../ApplicationCommands/ApplicationCommand.cs | 4 ---- .../ApplicationCommands/ApplicationCommandOption.cs | 4 ---- .../ApplicationCommands/ApplicationCommandOptionChoice.cs | 4 ---- .../ApplicationCommands/ApplicationCommandPermission.cs | 4 ---- .../ApplicationCommands/ApplicationCommandPermissions.cs | 4 ---- .../PartialApplicationCommandPermissions.cs | 4 ---- .../DSharpPlus.Core.Models/Applications/Application.cs | 4 ---- .../Applications/InstallParameters.cs | 4 ---- .../Applications/PartialApplication.cs | 4 ---- src/core/DSharpPlus.Core.Models/AuditLogs/AuditLog.cs | 4 ---- .../DSharpPlus.Core.Models/AuditLogs/AuditLogChange.cs | 4 ---- .../DSharpPlus.Core.Models/AuditLogs/AuditLogEntry.cs | 4 ---- .../DSharpPlus.Core.Models/AuditLogs/AuditLogEntryInfo.cs | 4 ---- .../AutoModeration/AutoModerationAction.cs | 4 ---- .../AutoModeration/AutoModerationRule.cs | 4 ---- .../AutoModeration/AutoModerationTriggerMetadata.cs | 4 ---- .../AutoModeration/BlockMessageActionMetadata.cs | 4 ---- .../AutoModeration/PartialAutoModerationRule.cs | 4 ---- .../AutoModeration/SendAlertMessageActionMetadata.cs | 4 ---- .../AutoModeration/TimeoutActionMetadata.cs | 4 ---- .../DSharpPlus.Core.Models/Channels/AllowedMentions.cs | 4 ---- src/core/DSharpPlus.Core.Models/Channels/Attachment.cs | 4 ---- src/core/DSharpPlus.Core.Models/Channels/Channel.cs | 4 ---- .../DSharpPlus.Core.Models/Channels/ChannelMention.cs | 4 ---- .../DSharpPlus.Core.Models/Channels/ChannelOverwrite.cs | 4 ---- .../DSharpPlus.Core.Models/Channels/DefaultReaction.cs | 4 ---- src/core/DSharpPlus.Core.Models/Channels/Embed.cs | 4 ---- src/core/DSharpPlus.Core.Models/Channels/EmbedAuthor.cs | 4 ---- src/core/DSharpPlus.Core.Models/Channels/EmbedField.cs | 4 ---- src/core/DSharpPlus.Core.Models/Channels/EmbedFooter.cs | 4 ---- src/core/DSharpPlus.Core.Models/Channels/EmbedImage.cs | 4 ---- src/core/DSharpPlus.Core.Models/Channels/EmbedProvider.cs | 4 ---- .../DSharpPlus.Core.Models/Channels/EmbedThumbnail.cs | 4 ---- src/core/DSharpPlus.Core.Models/Channels/EmbedVideo.cs | 4 ---- .../DSharpPlus.Core.Models/Channels/FollowedChannel.cs | 4 ---- src/core/DSharpPlus.Core.Models/Channels/ForumTag.cs | 4 ---- src/core/DSharpPlus.Core.Models/Channels/Message.cs | 4 ---- .../DSharpPlus.Core.Models/Channels/MessageActivity.cs | 4 ---- .../DSharpPlus.Core.Models/Channels/MessageReference.cs | 4 ---- .../DSharpPlus.Core.Models/Channels/PartialAttachment.cs | 4 ---- .../DSharpPlus.Core.Models/Channels/PartialChannel.cs | 4 ---- .../Channels/PartialChannelOverwrite.cs | 4 ---- .../DSharpPlus.Core.Models/Channels/PartialMessage.cs | 4 ---- src/core/DSharpPlus.Core.Models/Channels/Reaction.cs | 4 ---- .../Channels/RoleSubscriptionData.cs | 4 ---- src/core/DSharpPlus.Core.Models/Channels/ThreadMember.cs | 4 ---- .../DSharpPlus.Core.Models/Channels/ThreadMetadata.cs | 4 ---- src/core/DSharpPlus.Core.Models/Emojis/Emoji.cs | 4 ---- src/core/DSharpPlus.Core.Models/Emojis/PartialEmoji.cs | 4 ---- .../DSharpPlus.Core.Models/GuildTemplates/Template.cs | 4 ---- src/core/DSharpPlus.Core.Models/Guilds/Ban.cs | 4 ---- src/core/DSharpPlus.Core.Models/Guilds/Guild.cs | 4 ---- src/core/DSharpPlus.Core.Models/Guilds/GuildMember.cs | 4 ---- src/core/DSharpPlus.Core.Models/Guilds/GuildPreview.cs | 4 ---- src/core/DSharpPlus.Core.Models/Guilds/GuildWidget.cs | 4 ---- .../DSharpPlus.Core.Models/Guilds/GuildWidgetSettings.cs | 4 ---- src/core/DSharpPlus.Core.Models/Guilds/Integration.cs | 4 ---- .../DSharpPlus.Core.Models/Guilds/IntegrationAccount.cs | 4 ---- .../Guilds/IntegrationApplication.cs | 4 ---- src/core/DSharpPlus.Core.Models/Guilds/Onboarding.cs | 4 ---- .../DSharpPlus.Core.Models/Guilds/OnboardingPrompt.cs | 4 ---- .../Guilds/OnboardingPromptOption.cs | 4 ---- src/core/DSharpPlus.Core.Models/Guilds/PartialGuild.cs | 4 ---- .../DSharpPlus.Core.Models/Guilds/PartialGuildMember.cs | 4 ---- .../DSharpPlus.Core.Models/Guilds/PartialIntegration.cs | 4 ---- src/core/DSharpPlus.Core.Models/Guilds/PartialRole.cs | 4 ---- src/core/DSharpPlus.Core.Models/Guilds/Role.cs | 4 ---- src/core/DSharpPlus.Core.Models/Guilds/RoleTags.cs | 4 ---- src/core/DSharpPlus.Core.Models/Guilds/WelcomeScreen.cs | 4 ---- .../DSharpPlus.Core.Models/Guilds/WelcomeScreenChannel.cs | 4 ---- .../Interactions/ApplicationCommandInteractionData.cs | 4 ---- .../ApplicationCommandInteractionDataOption.cs | 4 ---- .../Interactions/AutocompleteCallbackData.cs | 4 ---- .../Interactions/AutocompleteInteractionData.cs | 4 ---- .../Interactions/AutocompleteInteractionDataOption.cs | 4 ---- .../DSharpPlus.Core.Models/Interactions/Interaction.cs | 4 ---- .../Interactions/InteractionResponse.cs | 4 ---- .../Interactions/MessageCallbackData.cs | 4 ---- .../Interactions/MessageComponentInteractionData.cs | 4 ---- .../Interactions/MessageInteraction.cs | 4 ---- .../Interactions/ModalCallbackData.cs | 4 ---- .../Interactions/ModalInteractionData.cs | 4 ---- .../DSharpPlus.Core.Models/Interactions/ResolvedData.cs | 4 ---- src/core/DSharpPlus.Core.Models/Invites/Invite.cs | 4 ---- src/core/DSharpPlus.Core.Models/Invites/PartialInvite.cs | 4 ---- .../MessageComponents/ActionRowComponent.cs | 4 ---- .../MessageComponents/ButtonComponent.cs | 4 ---- .../MessageComponents/ChannelSelectComponent.cs | 4 ---- .../MessageComponents/MentionableSelectComponent.cs | 4 ---- .../MessageComponents/RoleSelectComponent.cs | 4 ---- .../MessageComponents/SelectOption.cs | 4 ---- .../MessageComponents/StringSelectComponent.cs | 4 ---- .../MessageComponents/TextInputComponent.cs | 4 ---- .../MessageComponents/UserSelectComponent.cs | 4 ---- .../RoleConnections/RoleConnectionMetadata.cs | 4 ---- .../ScheduledEvents/PartialScheduledEvent.cs | 4 ---- .../ScheduledEvents/ScheduledEvent.cs | 4 ---- .../ScheduledEvents/ScheduledEventUser.cs | 4 ---- .../StageInstances/PartialStageInstance.cs | 4 ---- .../StageInstances/StageInstance.cs | 4 ---- .../DSharpPlus.Core.Models/Stickers/PartialSticker.cs | 4 ---- src/core/DSharpPlus.Core.Models/Stickers/Sticker.cs | 4 ---- src/core/DSharpPlus.Core.Models/Stickers/StickerItem.cs | 4 ---- src/core/DSharpPlus.Core.Models/Stickers/StickerPack.cs | 4 ---- src/core/DSharpPlus.Core.Models/Teams/Team.cs | 4 ---- src/core/DSharpPlus.Core.Models/Teams/TeamMember.cs | 4 ---- .../Users/ApplicationRoleConnection.cs | 4 ---- src/core/DSharpPlus.Core.Models/Users/Connection.cs | 4 ---- src/core/DSharpPlus.Core.Models/Users/PartialUser.cs | 4 ---- src/core/DSharpPlus.Core.Models/Users/User.cs | 4 ---- src/core/DSharpPlus.Core.Models/Voice/VoiceRegion.cs | 4 ---- src/core/DSharpPlus.Core.Models/Voice/VoiceState.cs | 4 ---- .../DSharpPlus.Core.Models/Webhooks/PartialWebhook.cs | 4 ---- src/core/DSharpPlus.Core.Models/Webhooks/Webhook.cs | 4 ---- .../Tools.Generators.GenerateConcreteObjects/Program.cs | 8 ++++---- 115 files changed, 4 insertions(+), 460 deletions(-) diff --git a/src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommand.cs b/src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommand.cs index 22a18c332c..029bef2ffa 100644 --- a/src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommand.cs +++ b/src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommand.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using System.Collections.Generic; using DSharpPlus.Entities; diff --git a/src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommandOption.cs b/src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommandOption.cs index d3874743c9..37bdf31919 100644 --- a/src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommandOption.cs +++ b/src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommandOption.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using System.Collections.Generic; using DSharpPlus.Entities; diff --git a/src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommandOptionChoice.cs b/src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommandOptionChoice.cs index 30bceaa3b1..3e4949a191 100644 --- a/src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommandOptionChoice.cs +++ b/src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommandOptionChoice.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using System.Collections.Generic; using OneOf; diff --git a/src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommandPermission.cs b/src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommandPermission.cs index 8cc249b5cf..202320f918 100644 --- a/src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommandPermission.cs +++ b/src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommandPermission.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using DSharpPlus.Entities; using Remora.Rest.Core; diff --git a/src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommandPermissions.cs b/src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommandPermissions.cs index 414a0d882d..741e912e59 100644 --- a/src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommandPermissions.cs +++ b/src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommandPermissions.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using System.Collections.Generic; using Remora.Rest.Core; diff --git a/src/core/DSharpPlus.Core.Models/ApplicationCommands/PartialApplicationCommandPermissions.cs b/src/core/DSharpPlus.Core.Models/ApplicationCommands/PartialApplicationCommandPermissions.cs index f171b4dd3c..b31912ad32 100644 --- a/src/core/DSharpPlus.Core.Models/ApplicationCommands/PartialApplicationCommandPermissions.cs +++ b/src/core/DSharpPlus.Core.Models/ApplicationCommands/PartialApplicationCommandPermissions.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using System.Collections.Generic; using Remora.Rest.Core; diff --git a/src/core/DSharpPlus.Core.Models/Applications/Application.cs b/src/core/DSharpPlus.Core.Models/Applications/Application.cs index c68b21acdd..7db9aa4919 100644 --- a/src/core/DSharpPlus.Core.Models/Applications/Application.cs +++ b/src/core/DSharpPlus.Core.Models/Applications/Application.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using System.Collections.Generic; using DSharpPlus.Entities; diff --git a/src/core/DSharpPlus.Core.Models/Applications/InstallParameters.cs b/src/core/DSharpPlus.Core.Models/Applications/InstallParameters.cs index 92f430997a..5a3c749450 100644 --- a/src/core/DSharpPlus.Core.Models/Applications/InstallParameters.cs +++ b/src/core/DSharpPlus.Core.Models/Applications/InstallParameters.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using System.Collections.Generic; using DSharpPlus.Entities; diff --git a/src/core/DSharpPlus.Core.Models/Applications/PartialApplication.cs b/src/core/DSharpPlus.Core.Models/Applications/PartialApplication.cs index 3a1c137c64..a93a2f5ebd 100644 --- a/src/core/DSharpPlus.Core.Models/Applications/PartialApplication.cs +++ b/src/core/DSharpPlus.Core.Models/Applications/PartialApplication.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using System.Collections.Generic; using DSharpPlus.Entities; diff --git a/src/core/DSharpPlus.Core.Models/AuditLogs/AuditLog.cs b/src/core/DSharpPlus.Core.Models/AuditLogs/AuditLog.cs index 557b209bf0..66d207a78f 100644 --- a/src/core/DSharpPlus.Core.Models/AuditLogs/AuditLog.cs +++ b/src/core/DSharpPlus.Core.Models/AuditLogs/AuditLog.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using System.Collections.Generic; using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/AuditLogs/AuditLogChange.cs b/src/core/DSharpPlus.Core.Models/AuditLogs/AuditLogChange.cs index 5140489daa..a2b1c1de3d 100644 --- a/src/core/DSharpPlus.Core.Models/AuditLogs/AuditLogChange.cs +++ b/src/core/DSharpPlus.Core.Models/AuditLogs/AuditLogChange.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using System.Text.Json; using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/AuditLogs/AuditLogEntry.cs b/src/core/DSharpPlus.Core.Models/AuditLogs/AuditLogEntry.cs index 8d8b284198..15b68aec2e 100644 --- a/src/core/DSharpPlus.Core.Models/AuditLogs/AuditLogEntry.cs +++ b/src/core/DSharpPlus.Core.Models/AuditLogs/AuditLogEntry.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using System.Collections.Generic; using DSharpPlus.Entities; diff --git a/src/core/DSharpPlus.Core.Models/AuditLogs/AuditLogEntryInfo.cs b/src/core/DSharpPlus.Core.Models/AuditLogs/AuditLogEntryInfo.cs index 9584035679..6bada1ff4a 100644 --- a/src/core/DSharpPlus.Core.Models/AuditLogs/AuditLogEntryInfo.cs +++ b/src/core/DSharpPlus.Core.Models/AuditLogs/AuditLogEntryInfo.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using Remora.Rest.Core; using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/AutoModeration/AutoModerationAction.cs b/src/core/DSharpPlus.Core.Models/AutoModeration/AutoModerationAction.cs index 0f16ece311..28f154bbee 100644 --- a/src/core/DSharpPlus.Core.Models/AutoModeration/AutoModerationAction.cs +++ b/src/core/DSharpPlus.Core.Models/AutoModeration/AutoModerationAction.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using DSharpPlus.Entities; using Remora.Rest.Core; diff --git a/src/core/DSharpPlus.Core.Models/AutoModeration/AutoModerationRule.cs b/src/core/DSharpPlus.Core.Models/AutoModeration/AutoModerationRule.cs index caa84b4687..0753b48ae8 100644 --- a/src/core/DSharpPlus.Core.Models/AutoModeration/AutoModerationRule.cs +++ b/src/core/DSharpPlus.Core.Models/AutoModeration/AutoModerationRule.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using System.Collections.Generic; using DSharpPlus.Entities; diff --git a/src/core/DSharpPlus.Core.Models/AutoModeration/AutoModerationTriggerMetadata.cs b/src/core/DSharpPlus.Core.Models/AutoModeration/AutoModerationTriggerMetadata.cs index 3a3e13728b..42091ead2d 100644 --- a/src/core/DSharpPlus.Core.Models/AutoModeration/AutoModerationTriggerMetadata.cs +++ b/src/core/DSharpPlus.Core.Models/AutoModeration/AutoModerationTriggerMetadata.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using System.Collections.Generic; using DSharpPlus.Entities; diff --git a/src/core/DSharpPlus.Core.Models/AutoModeration/BlockMessageActionMetadata.cs b/src/core/DSharpPlus.Core.Models/AutoModeration/BlockMessageActionMetadata.cs index 9aaecaa0ad..233718f266 100644 --- a/src/core/DSharpPlus.Core.Models/AutoModeration/BlockMessageActionMetadata.cs +++ b/src/core/DSharpPlus.Core.Models/AutoModeration/BlockMessageActionMetadata.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using DSharpPlus.Entities; using Remora.Rest.Core; diff --git a/src/core/DSharpPlus.Core.Models/AutoModeration/PartialAutoModerationRule.cs b/src/core/DSharpPlus.Core.Models/AutoModeration/PartialAutoModerationRule.cs index d1dd62fe5d..ab5fec2dc6 100644 --- a/src/core/DSharpPlus.Core.Models/AutoModeration/PartialAutoModerationRule.cs +++ b/src/core/DSharpPlus.Core.Models/AutoModeration/PartialAutoModerationRule.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using System.Collections.Generic; using DSharpPlus.Entities; diff --git a/src/core/DSharpPlus.Core.Models/AutoModeration/SendAlertMessageActionMetadata.cs b/src/core/DSharpPlus.Core.Models/AutoModeration/SendAlertMessageActionMetadata.cs index 6b4a071646..dc64b4655b 100644 --- a/src/core/DSharpPlus.Core.Models/AutoModeration/SendAlertMessageActionMetadata.cs +++ b/src/core/DSharpPlus.Core.Models/AutoModeration/SendAlertMessageActionMetadata.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using DSharpPlus.Entities; using Remora.Rest.Core; diff --git a/src/core/DSharpPlus.Core.Models/AutoModeration/TimeoutActionMetadata.cs b/src/core/DSharpPlus.Core.Models/AutoModeration/TimeoutActionMetadata.cs index edf6e39bfc..83daac471f 100644 --- a/src/core/DSharpPlus.Core.Models/AutoModeration/TimeoutActionMetadata.cs +++ b/src/core/DSharpPlus.Core.Models/AutoModeration/TimeoutActionMetadata.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using DSharpPlus.Entities; using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/Channels/AllowedMentions.cs b/src/core/DSharpPlus.Core.Models/Channels/AllowedMentions.cs index 25562c0e0b..2a4426f0ac 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/AllowedMentions.cs +++ b/src/core/DSharpPlus.Core.Models/Channels/AllowedMentions.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using System.Collections.Generic; using Remora.Rest.Core; diff --git a/src/core/DSharpPlus.Core.Models/Channels/Attachment.cs b/src/core/DSharpPlus.Core.Models/Channels/Attachment.cs index e95a8e8d36..54e651754b 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/Attachment.cs +++ b/src/core/DSharpPlus.Core.Models/Channels/Attachment.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using System; using DSharpPlus.Entities; diff --git a/src/core/DSharpPlus.Core.Models/Channels/Channel.cs b/src/core/DSharpPlus.Core.Models/Channels/Channel.cs index da991f9859..91dcf5d571 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/Channel.cs +++ b/src/core/DSharpPlus.Core.Models/Channels/Channel.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using System; using System.Collections.Generic; diff --git a/src/core/DSharpPlus.Core.Models/Channels/ChannelMention.cs b/src/core/DSharpPlus.Core.Models/Channels/ChannelMention.cs index 894116db53..f76cb15ca6 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/ChannelMention.cs +++ b/src/core/DSharpPlus.Core.Models/Channels/ChannelMention.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using DSharpPlus.Entities; using Remora.Rest.Core; diff --git a/src/core/DSharpPlus.Core.Models/Channels/ChannelOverwrite.cs b/src/core/DSharpPlus.Core.Models/Channels/ChannelOverwrite.cs index d004c54b81..6db39029c0 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/ChannelOverwrite.cs +++ b/src/core/DSharpPlus.Core.Models/Channels/ChannelOverwrite.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using DSharpPlus.Entities; using Remora.Rest.Core; diff --git a/src/core/DSharpPlus.Core.Models/Channels/DefaultReaction.cs b/src/core/DSharpPlus.Core.Models/Channels/DefaultReaction.cs index a9844a2b25..9bb3f40cc7 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/DefaultReaction.cs +++ b/src/core/DSharpPlus.Core.Models/Channels/DefaultReaction.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using Remora.Rest.Core; using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/Channels/Embed.cs b/src/core/DSharpPlus.Core.Models/Channels/Embed.cs index cbbbd4e9d6..08adc47ee0 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/Embed.cs +++ b/src/core/DSharpPlus.Core.Models/Channels/Embed.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using System; using System.Collections.Generic; diff --git a/src/core/DSharpPlus.Core.Models/Channels/EmbedAuthor.cs b/src/core/DSharpPlus.Core.Models/Channels/EmbedAuthor.cs index 3a35428421..6877059b30 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/EmbedAuthor.cs +++ b/src/core/DSharpPlus.Core.Models/Channels/EmbedAuthor.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using Remora.Rest.Core; using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/Channels/EmbedField.cs b/src/core/DSharpPlus.Core.Models/Channels/EmbedField.cs index aa94d3c3f2..a9765807b2 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/EmbedField.cs +++ b/src/core/DSharpPlus.Core.Models/Channels/EmbedField.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using Remora.Rest.Core; using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/Channels/EmbedFooter.cs b/src/core/DSharpPlus.Core.Models/Channels/EmbedFooter.cs index 8b59b65617..d526de5394 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/EmbedFooter.cs +++ b/src/core/DSharpPlus.Core.Models/Channels/EmbedFooter.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using Remora.Rest.Core; using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/Channels/EmbedImage.cs b/src/core/DSharpPlus.Core.Models/Channels/EmbedImage.cs index c6ae510dec..83f118fa60 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/EmbedImage.cs +++ b/src/core/DSharpPlus.Core.Models/Channels/EmbedImage.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using Remora.Rest.Core; using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/Channels/EmbedProvider.cs b/src/core/DSharpPlus.Core.Models/Channels/EmbedProvider.cs index 7c2543fd6c..9596ffb0a9 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/EmbedProvider.cs +++ b/src/core/DSharpPlus.Core.Models/Channels/EmbedProvider.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using Remora.Rest.Core; using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/Channels/EmbedThumbnail.cs b/src/core/DSharpPlus.Core.Models/Channels/EmbedThumbnail.cs index 3dfc7a3419..ebe009eeb1 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/EmbedThumbnail.cs +++ b/src/core/DSharpPlus.Core.Models/Channels/EmbedThumbnail.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using Remora.Rest.Core; using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/Channels/EmbedVideo.cs b/src/core/DSharpPlus.Core.Models/Channels/EmbedVideo.cs index 72a6e67ed2..b614ca542b 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/EmbedVideo.cs +++ b/src/core/DSharpPlus.Core.Models/Channels/EmbedVideo.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using Remora.Rest.Core; using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/Channels/FollowedChannel.cs b/src/core/DSharpPlus.Core.Models/Channels/FollowedChannel.cs index 38d20b3886..998f0a717c 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/FollowedChannel.cs +++ b/src/core/DSharpPlus.Core.Models/Channels/FollowedChannel.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using Remora.Rest.Core; using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/Channels/ForumTag.cs b/src/core/DSharpPlus.Core.Models/Channels/ForumTag.cs index 93fd84c8b2..c43364b8a3 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/ForumTag.cs +++ b/src/core/DSharpPlus.Core.Models/Channels/ForumTag.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using Remora.Rest.Core; using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/Channels/Message.cs b/src/core/DSharpPlus.Core.Models/Channels/Message.cs index 49b44d4e4c..85af238df4 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/Message.cs +++ b/src/core/DSharpPlus.Core.Models/Channels/Message.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using System; using System.Collections.Generic; diff --git a/src/core/DSharpPlus.Core.Models/Channels/MessageActivity.cs b/src/core/DSharpPlus.Core.Models/Channels/MessageActivity.cs index be28dd0b09..f3ca1b0608 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/MessageActivity.cs +++ b/src/core/DSharpPlus.Core.Models/Channels/MessageActivity.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using DSharpPlus.Entities; using Remora.Rest.Core; diff --git a/src/core/DSharpPlus.Core.Models/Channels/MessageReference.cs b/src/core/DSharpPlus.Core.Models/Channels/MessageReference.cs index 5a832236d7..0dd81b06c7 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/MessageReference.cs +++ b/src/core/DSharpPlus.Core.Models/Channels/MessageReference.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using Remora.Rest.Core; using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/Channels/PartialAttachment.cs b/src/core/DSharpPlus.Core.Models/Channels/PartialAttachment.cs index 7f869cda18..d9ffcb00eb 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/PartialAttachment.cs +++ b/src/core/DSharpPlus.Core.Models/Channels/PartialAttachment.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using System; using DSharpPlus.Entities; diff --git a/src/core/DSharpPlus.Core.Models/Channels/PartialChannel.cs b/src/core/DSharpPlus.Core.Models/Channels/PartialChannel.cs index c0716d2381..e5c81682b5 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/PartialChannel.cs +++ b/src/core/DSharpPlus.Core.Models/Channels/PartialChannel.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using System; using System.Collections.Generic; diff --git a/src/core/DSharpPlus.Core.Models/Channels/PartialChannelOverwrite.cs b/src/core/DSharpPlus.Core.Models/Channels/PartialChannelOverwrite.cs index 1298bcf6e4..ccc2892b10 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/PartialChannelOverwrite.cs +++ b/src/core/DSharpPlus.Core.Models/Channels/PartialChannelOverwrite.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using DSharpPlus.Entities; using Remora.Rest.Core; diff --git a/src/core/DSharpPlus.Core.Models/Channels/PartialMessage.cs b/src/core/DSharpPlus.Core.Models/Channels/PartialMessage.cs index edc9346de1..6dc583ddfa 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/PartialMessage.cs +++ b/src/core/DSharpPlus.Core.Models/Channels/PartialMessage.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using System; using System.Collections.Generic; diff --git a/src/core/DSharpPlus.Core.Models/Channels/Reaction.cs b/src/core/DSharpPlus.Core.Models/Channels/Reaction.cs index 493cb2219a..7801178096 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/Reaction.cs +++ b/src/core/DSharpPlus.Core.Models/Channels/Reaction.cs @@ -1,7 +1,3 @@ -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/Channels/RoleSubscriptionData.cs b/src/core/DSharpPlus.Core.Models/Channels/RoleSubscriptionData.cs index bdf7c8fde2..3f84822729 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/RoleSubscriptionData.cs +++ b/src/core/DSharpPlus.Core.Models/Channels/RoleSubscriptionData.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using Remora.Rest.Core; using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/Channels/ThreadMember.cs b/src/core/DSharpPlus.Core.Models/Channels/ThreadMember.cs index 4c2548b3fe..5b91c94f72 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/ThreadMember.cs +++ b/src/core/DSharpPlus.Core.Models/Channels/ThreadMember.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using System; using Remora.Rest.Core; diff --git a/src/core/DSharpPlus.Core.Models/Channels/ThreadMetadata.cs b/src/core/DSharpPlus.Core.Models/Channels/ThreadMetadata.cs index eb40ca60a4..5447aef135 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/ThreadMetadata.cs +++ b/src/core/DSharpPlus.Core.Models/Channels/ThreadMetadata.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using System; using Remora.Rest.Core; diff --git a/src/core/DSharpPlus.Core.Models/Emojis/Emoji.cs b/src/core/DSharpPlus.Core.Models/Emojis/Emoji.cs index 6b84f2feac..1f0f618d25 100644 --- a/src/core/DSharpPlus.Core.Models/Emojis/Emoji.cs +++ b/src/core/DSharpPlus.Core.Models/Emojis/Emoji.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using System.Collections.Generic; using Remora.Rest.Core; diff --git a/src/core/DSharpPlus.Core.Models/Emojis/PartialEmoji.cs b/src/core/DSharpPlus.Core.Models/Emojis/PartialEmoji.cs index fa5a8fbfe9..bc110d00ac 100644 --- a/src/core/DSharpPlus.Core.Models/Emojis/PartialEmoji.cs +++ b/src/core/DSharpPlus.Core.Models/Emojis/PartialEmoji.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using System.Collections.Generic; using Remora.Rest.Core; diff --git a/src/core/DSharpPlus.Core.Models/GuildTemplates/Template.cs b/src/core/DSharpPlus.Core.Models/GuildTemplates/Template.cs index 69b4b9653b..1354066d7e 100644 --- a/src/core/DSharpPlus.Core.Models/GuildTemplates/Template.cs +++ b/src/core/DSharpPlus.Core.Models/GuildTemplates/Template.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using System; using Remora.Rest.Core; diff --git a/src/core/DSharpPlus.Core.Models/Guilds/Ban.cs b/src/core/DSharpPlus.Core.Models/Guilds/Ban.cs index 80ba39301c..be2077d9c1 100644 --- a/src/core/DSharpPlus.Core.Models/Guilds/Ban.cs +++ b/src/core/DSharpPlus.Core.Models/Guilds/Ban.cs @@ -1,7 +1,3 @@ -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/Guilds/Guild.cs b/src/core/DSharpPlus.Core.Models/Guilds/Guild.cs index 06ec8f68cd..eccf04b916 100644 --- a/src/core/DSharpPlus.Core.Models/Guilds/Guild.cs +++ b/src/core/DSharpPlus.Core.Models/Guilds/Guild.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using System.Collections.Generic; using DSharpPlus.Entities; diff --git a/src/core/DSharpPlus.Core.Models/Guilds/GuildMember.cs b/src/core/DSharpPlus.Core.Models/Guilds/GuildMember.cs index 2dea0e5e75..395c7abfee 100644 --- a/src/core/DSharpPlus.Core.Models/Guilds/GuildMember.cs +++ b/src/core/DSharpPlus.Core.Models/Guilds/GuildMember.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using System; using System.Collections.Generic; diff --git a/src/core/DSharpPlus.Core.Models/Guilds/GuildPreview.cs b/src/core/DSharpPlus.Core.Models/Guilds/GuildPreview.cs index e92b392fa7..94a10010c3 100644 --- a/src/core/DSharpPlus.Core.Models/Guilds/GuildPreview.cs +++ b/src/core/DSharpPlus.Core.Models/Guilds/GuildPreview.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using System.Collections.Generic; using Remora.Rest.Core; diff --git a/src/core/DSharpPlus.Core.Models/Guilds/GuildWidget.cs b/src/core/DSharpPlus.Core.Models/Guilds/GuildWidget.cs index 38b2f3b83a..fa3c5fe0e8 100644 --- a/src/core/DSharpPlus.Core.Models/Guilds/GuildWidget.cs +++ b/src/core/DSharpPlus.Core.Models/Guilds/GuildWidget.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using System.Collections.Generic; using Remora.Rest.Core; diff --git a/src/core/DSharpPlus.Core.Models/Guilds/GuildWidgetSettings.cs b/src/core/DSharpPlus.Core.Models/Guilds/GuildWidgetSettings.cs index 44db8ade04..d90548f0db 100644 --- a/src/core/DSharpPlus.Core.Models/Guilds/GuildWidgetSettings.cs +++ b/src/core/DSharpPlus.Core.Models/Guilds/GuildWidgetSettings.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using Remora.Rest.Core; using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/Guilds/Integration.cs b/src/core/DSharpPlus.Core.Models/Guilds/Integration.cs index 3c66947133..b8ca79ce32 100644 --- a/src/core/DSharpPlus.Core.Models/Guilds/Integration.cs +++ b/src/core/DSharpPlus.Core.Models/Guilds/Integration.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using System; using System.Collections.Generic; diff --git a/src/core/DSharpPlus.Core.Models/Guilds/IntegrationAccount.cs b/src/core/DSharpPlus.Core.Models/Guilds/IntegrationAccount.cs index e52285e1a4..d102f4a521 100644 --- a/src/core/DSharpPlus.Core.Models/Guilds/IntegrationAccount.cs +++ b/src/core/DSharpPlus.Core.Models/Guilds/IntegrationAccount.cs @@ -1,7 +1,3 @@ -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/Guilds/IntegrationApplication.cs b/src/core/DSharpPlus.Core.Models/Guilds/IntegrationApplication.cs index a0ad3ce446..cf03ea40eb 100644 --- a/src/core/DSharpPlus.Core.Models/Guilds/IntegrationApplication.cs +++ b/src/core/DSharpPlus.Core.Models/Guilds/IntegrationApplication.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using Remora.Rest.Core; using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/Guilds/Onboarding.cs b/src/core/DSharpPlus.Core.Models/Guilds/Onboarding.cs index 06ca4e8bbf..11eab8a957 100644 --- a/src/core/DSharpPlus.Core.Models/Guilds/Onboarding.cs +++ b/src/core/DSharpPlus.Core.Models/Guilds/Onboarding.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using System.Collections.Generic; using DSharpPlus.Entities; diff --git a/src/core/DSharpPlus.Core.Models/Guilds/OnboardingPrompt.cs b/src/core/DSharpPlus.Core.Models/Guilds/OnboardingPrompt.cs index f270d3135d..75c30610b9 100644 --- a/src/core/DSharpPlus.Core.Models/Guilds/OnboardingPrompt.cs +++ b/src/core/DSharpPlus.Core.Models/Guilds/OnboardingPrompt.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using System.Collections.Generic; using DSharpPlus.Entities; diff --git a/src/core/DSharpPlus.Core.Models/Guilds/OnboardingPromptOption.cs b/src/core/DSharpPlus.Core.Models/Guilds/OnboardingPromptOption.cs index ad5fc98b9f..c3055ac3d1 100644 --- a/src/core/DSharpPlus.Core.Models/Guilds/OnboardingPromptOption.cs +++ b/src/core/DSharpPlus.Core.Models/Guilds/OnboardingPromptOption.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using System.Collections.Generic; using Remora.Rest.Core; diff --git a/src/core/DSharpPlus.Core.Models/Guilds/PartialGuild.cs b/src/core/DSharpPlus.Core.Models/Guilds/PartialGuild.cs index 322b529116..31a612146e 100644 --- a/src/core/DSharpPlus.Core.Models/Guilds/PartialGuild.cs +++ b/src/core/DSharpPlus.Core.Models/Guilds/PartialGuild.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using System.Collections.Generic; using DSharpPlus.Entities; diff --git a/src/core/DSharpPlus.Core.Models/Guilds/PartialGuildMember.cs b/src/core/DSharpPlus.Core.Models/Guilds/PartialGuildMember.cs index ca080e4a0f..35a850a610 100644 --- a/src/core/DSharpPlus.Core.Models/Guilds/PartialGuildMember.cs +++ b/src/core/DSharpPlus.Core.Models/Guilds/PartialGuildMember.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using System; using System.Collections.Generic; diff --git a/src/core/DSharpPlus.Core.Models/Guilds/PartialIntegration.cs b/src/core/DSharpPlus.Core.Models/Guilds/PartialIntegration.cs index 1658d30df5..fcc4cafa91 100644 --- a/src/core/DSharpPlus.Core.Models/Guilds/PartialIntegration.cs +++ b/src/core/DSharpPlus.Core.Models/Guilds/PartialIntegration.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using System; using System.Collections.Generic; diff --git a/src/core/DSharpPlus.Core.Models/Guilds/PartialRole.cs b/src/core/DSharpPlus.Core.Models/Guilds/PartialRole.cs index 95919a83ed..c94ccb5841 100644 --- a/src/core/DSharpPlus.Core.Models/Guilds/PartialRole.cs +++ b/src/core/DSharpPlus.Core.Models/Guilds/PartialRole.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using DSharpPlus.Entities; using Remora.Rest.Core; diff --git a/src/core/DSharpPlus.Core.Models/Guilds/Role.cs b/src/core/DSharpPlus.Core.Models/Guilds/Role.cs index 10a205b426..3a6b9df0c6 100644 --- a/src/core/DSharpPlus.Core.Models/Guilds/Role.cs +++ b/src/core/DSharpPlus.Core.Models/Guilds/Role.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using DSharpPlus.Entities; using Remora.Rest.Core; diff --git a/src/core/DSharpPlus.Core.Models/Guilds/RoleTags.cs b/src/core/DSharpPlus.Core.Models/Guilds/RoleTags.cs index 7856193b55..06d01b142b 100644 --- a/src/core/DSharpPlus.Core.Models/Guilds/RoleTags.cs +++ b/src/core/DSharpPlus.Core.Models/Guilds/RoleTags.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using Remora.Rest.Core; using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/Guilds/WelcomeScreen.cs b/src/core/DSharpPlus.Core.Models/Guilds/WelcomeScreen.cs index 7f19c23e69..f60fcb346a 100644 --- a/src/core/DSharpPlus.Core.Models/Guilds/WelcomeScreen.cs +++ b/src/core/DSharpPlus.Core.Models/Guilds/WelcomeScreen.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using System.Collections.Generic; using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/Guilds/WelcomeScreenChannel.cs b/src/core/DSharpPlus.Core.Models/Guilds/WelcomeScreenChannel.cs index 041098b0b6..9cd1a33236 100644 --- a/src/core/DSharpPlus.Core.Models/Guilds/WelcomeScreenChannel.cs +++ b/src/core/DSharpPlus.Core.Models/Guilds/WelcomeScreenChannel.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using Remora.Rest.Core; using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/Interactions/ApplicationCommandInteractionData.cs b/src/core/DSharpPlus.Core.Models/Interactions/ApplicationCommandInteractionData.cs index f5b1f5bd9f..2dd94fccf5 100644 --- a/src/core/DSharpPlus.Core.Models/Interactions/ApplicationCommandInteractionData.cs +++ b/src/core/DSharpPlus.Core.Models/Interactions/ApplicationCommandInteractionData.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using System.Collections.Generic; using DSharpPlus.Entities; diff --git a/src/core/DSharpPlus.Core.Models/Interactions/ApplicationCommandInteractionDataOption.cs b/src/core/DSharpPlus.Core.Models/Interactions/ApplicationCommandInteractionDataOption.cs index 54be18fe4e..b5282cc35b 100644 --- a/src/core/DSharpPlus.Core.Models/Interactions/ApplicationCommandInteractionDataOption.cs +++ b/src/core/DSharpPlus.Core.Models/Interactions/ApplicationCommandInteractionDataOption.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using System.Collections.Generic; using DSharpPlus.Entities; diff --git a/src/core/DSharpPlus.Core.Models/Interactions/AutocompleteCallbackData.cs b/src/core/DSharpPlus.Core.Models/Interactions/AutocompleteCallbackData.cs index 0b7a539730..9c825386c6 100644 --- a/src/core/DSharpPlus.Core.Models/Interactions/AutocompleteCallbackData.cs +++ b/src/core/DSharpPlus.Core.Models/Interactions/AutocompleteCallbackData.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using System.Collections.Generic; using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/Interactions/AutocompleteInteractionData.cs b/src/core/DSharpPlus.Core.Models/Interactions/AutocompleteInteractionData.cs index bbaa9daeb8..af22013362 100644 --- a/src/core/DSharpPlus.Core.Models/Interactions/AutocompleteInteractionData.cs +++ b/src/core/DSharpPlus.Core.Models/Interactions/AutocompleteInteractionData.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using DSharpPlus.Entities; using Remora.Rest.Core; diff --git a/src/core/DSharpPlus.Core.Models/Interactions/AutocompleteInteractionDataOption.cs b/src/core/DSharpPlus.Core.Models/Interactions/AutocompleteInteractionDataOption.cs index 1927349e6f..08f4756479 100644 --- a/src/core/DSharpPlus.Core.Models/Interactions/AutocompleteInteractionDataOption.cs +++ b/src/core/DSharpPlus.Core.Models/Interactions/AutocompleteInteractionDataOption.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using System.Collections.Generic; using DSharpPlus.Entities; diff --git a/src/core/DSharpPlus.Core.Models/Interactions/Interaction.cs b/src/core/DSharpPlus.Core.Models/Interactions/Interaction.cs index ceb5e7f4bd..56f17fe5b7 100644 --- a/src/core/DSharpPlus.Core.Models/Interactions/Interaction.cs +++ b/src/core/DSharpPlus.Core.Models/Interactions/Interaction.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using DSharpPlus.Entities; using Remora.Rest.Core; diff --git a/src/core/DSharpPlus.Core.Models/Interactions/InteractionResponse.cs b/src/core/DSharpPlus.Core.Models/Interactions/InteractionResponse.cs index 2522474d48..8575b0d28d 100644 --- a/src/core/DSharpPlus.Core.Models/Interactions/InteractionResponse.cs +++ b/src/core/DSharpPlus.Core.Models/Interactions/InteractionResponse.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using DSharpPlus.Entities; using Remora.Rest.Core; diff --git a/src/core/DSharpPlus.Core.Models/Interactions/MessageCallbackData.cs b/src/core/DSharpPlus.Core.Models/Interactions/MessageCallbackData.cs index a0cd61d65f..82fd583813 100644 --- a/src/core/DSharpPlus.Core.Models/Interactions/MessageCallbackData.cs +++ b/src/core/DSharpPlus.Core.Models/Interactions/MessageCallbackData.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using System.Collections.Generic; using DSharpPlus.Entities; diff --git a/src/core/DSharpPlus.Core.Models/Interactions/MessageComponentInteractionData.cs b/src/core/DSharpPlus.Core.Models/Interactions/MessageComponentInteractionData.cs index 45a6f8d1c2..96f9208bb2 100644 --- a/src/core/DSharpPlus.Core.Models/Interactions/MessageComponentInteractionData.cs +++ b/src/core/DSharpPlus.Core.Models/Interactions/MessageComponentInteractionData.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using System.Collections.Generic; using DSharpPlus.Entities; diff --git a/src/core/DSharpPlus.Core.Models/Interactions/MessageInteraction.cs b/src/core/DSharpPlus.Core.Models/Interactions/MessageInteraction.cs index 287be0e7d0..421a523b9b 100644 --- a/src/core/DSharpPlus.Core.Models/Interactions/MessageInteraction.cs +++ b/src/core/DSharpPlus.Core.Models/Interactions/MessageInteraction.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using DSharpPlus.Entities; using Remora.Rest.Core; diff --git a/src/core/DSharpPlus.Core.Models/Interactions/ModalCallbackData.cs b/src/core/DSharpPlus.Core.Models/Interactions/ModalCallbackData.cs index 862118391d..f3624aa537 100644 --- a/src/core/DSharpPlus.Core.Models/Interactions/ModalCallbackData.cs +++ b/src/core/DSharpPlus.Core.Models/Interactions/ModalCallbackData.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using System.Collections.Generic; using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/Interactions/ModalInteractionData.cs b/src/core/DSharpPlus.Core.Models/Interactions/ModalInteractionData.cs index 4be549559c..6095abdc12 100644 --- a/src/core/DSharpPlus.Core.Models/Interactions/ModalInteractionData.cs +++ b/src/core/DSharpPlus.Core.Models/Interactions/ModalInteractionData.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using System.Collections.Generic; using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/Interactions/ResolvedData.cs b/src/core/DSharpPlus.Core.Models/Interactions/ResolvedData.cs index 03e7c5c97c..ba856a6bf9 100644 --- a/src/core/DSharpPlus.Core.Models/Interactions/ResolvedData.cs +++ b/src/core/DSharpPlus.Core.Models/Interactions/ResolvedData.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using System.Collections.Generic; using Remora.Rest.Core; diff --git a/src/core/DSharpPlus.Core.Models/Invites/Invite.cs b/src/core/DSharpPlus.Core.Models/Invites/Invite.cs index fe27da2968..a39d87fcce 100644 --- a/src/core/DSharpPlus.Core.Models/Invites/Invite.cs +++ b/src/core/DSharpPlus.Core.Models/Invites/Invite.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using System; using DSharpPlus.Entities; diff --git a/src/core/DSharpPlus.Core.Models/Invites/PartialInvite.cs b/src/core/DSharpPlus.Core.Models/Invites/PartialInvite.cs index 35cec101d2..8aa0dceb34 100644 --- a/src/core/DSharpPlus.Core.Models/Invites/PartialInvite.cs +++ b/src/core/DSharpPlus.Core.Models/Invites/PartialInvite.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using System; using DSharpPlus.Entities; diff --git a/src/core/DSharpPlus.Core.Models/MessageComponents/ActionRowComponent.cs b/src/core/DSharpPlus.Core.Models/MessageComponents/ActionRowComponent.cs index a4ef14f74b..0dcaa0a843 100644 --- a/src/core/DSharpPlus.Core.Models/MessageComponents/ActionRowComponent.cs +++ b/src/core/DSharpPlus.Core.Models/MessageComponents/ActionRowComponent.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using System.Collections.Generic; using DSharpPlus.Entities; diff --git a/src/core/DSharpPlus.Core.Models/MessageComponents/ButtonComponent.cs b/src/core/DSharpPlus.Core.Models/MessageComponents/ButtonComponent.cs index 35fabd6eea..c5cd2ad628 100644 --- a/src/core/DSharpPlus.Core.Models/MessageComponents/ButtonComponent.cs +++ b/src/core/DSharpPlus.Core.Models/MessageComponents/ButtonComponent.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using DSharpPlus.Entities; using Remora.Rest.Core; diff --git a/src/core/DSharpPlus.Core.Models/MessageComponents/ChannelSelectComponent.cs b/src/core/DSharpPlus.Core.Models/MessageComponents/ChannelSelectComponent.cs index 8e90d8474d..5eced6e93b 100644 --- a/src/core/DSharpPlus.Core.Models/MessageComponents/ChannelSelectComponent.cs +++ b/src/core/DSharpPlus.Core.Models/MessageComponents/ChannelSelectComponent.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using System.Collections.Generic; using DSharpPlus.Entities; diff --git a/src/core/DSharpPlus.Core.Models/MessageComponents/MentionableSelectComponent.cs b/src/core/DSharpPlus.Core.Models/MessageComponents/MentionableSelectComponent.cs index 00a119dbac..dbcca4a9d2 100644 --- a/src/core/DSharpPlus.Core.Models/MessageComponents/MentionableSelectComponent.cs +++ b/src/core/DSharpPlus.Core.Models/MessageComponents/MentionableSelectComponent.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using DSharpPlus.Entities; using Remora.Rest.Core; diff --git a/src/core/DSharpPlus.Core.Models/MessageComponents/RoleSelectComponent.cs b/src/core/DSharpPlus.Core.Models/MessageComponents/RoleSelectComponent.cs index be6c6a0f03..dd98a0c8d9 100644 --- a/src/core/DSharpPlus.Core.Models/MessageComponents/RoleSelectComponent.cs +++ b/src/core/DSharpPlus.Core.Models/MessageComponents/RoleSelectComponent.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using DSharpPlus.Entities; using Remora.Rest.Core; diff --git a/src/core/DSharpPlus.Core.Models/MessageComponents/SelectOption.cs b/src/core/DSharpPlus.Core.Models/MessageComponents/SelectOption.cs index aa7d9cdb31..4c2d46b891 100644 --- a/src/core/DSharpPlus.Core.Models/MessageComponents/SelectOption.cs +++ b/src/core/DSharpPlus.Core.Models/MessageComponents/SelectOption.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using Remora.Rest.Core; using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/MessageComponents/StringSelectComponent.cs b/src/core/DSharpPlus.Core.Models/MessageComponents/StringSelectComponent.cs index e3884b8758..b2660b2dca 100644 --- a/src/core/DSharpPlus.Core.Models/MessageComponents/StringSelectComponent.cs +++ b/src/core/DSharpPlus.Core.Models/MessageComponents/StringSelectComponent.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using System.Collections.Generic; using DSharpPlus.Entities; diff --git a/src/core/DSharpPlus.Core.Models/MessageComponents/TextInputComponent.cs b/src/core/DSharpPlus.Core.Models/MessageComponents/TextInputComponent.cs index 014ebb96d1..3a1e9efd7d 100644 --- a/src/core/DSharpPlus.Core.Models/MessageComponents/TextInputComponent.cs +++ b/src/core/DSharpPlus.Core.Models/MessageComponents/TextInputComponent.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using DSharpPlus.Entities; using Remora.Rest.Core; diff --git a/src/core/DSharpPlus.Core.Models/MessageComponents/UserSelectComponent.cs b/src/core/DSharpPlus.Core.Models/MessageComponents/UserSelectComponent.cs index c6361deffe..25c283fcee 100644 --- a/src/core/DSharpPlus.Core.Models/MessageComponents/UserSelectComponent.cs +++ b/src/core/DSharpPlus.Core.Models/MessageComponents/UserSelectComponent.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using DSharpPlus.Entities; using Remora.Rest.Core; diff --git a/src/core/DSharpPlus.Core.Models/RoleConnections/RoleConnectionMetadata.cs b/src/core/DSharpPlus.Core.Models/RoleConnections/RoleConnectionMetadata.cs index 557f83e499..77dfb0f6e8 100644 --- a/src/core/DSharpPlus.Core.Models/RoleConnections/RoleConnectionMetadata.cs +++ b/src/core/DSharpPlus.Core.Models/RoleConnections/RoleConnectionMetadata.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using System.Collections.Generic; using DSharpPlus.Entities; diff --git a/src/core/DSharpPlus.Core.Models/ScheduledEvents/PartialScheduledEvent.cs b/src/core/DSharpPlus.Core.Models/ScheduledEvents/PartialScheduledEvent.cs index 5bf578641d..4504773bf4 100644 --- a/src/core/DSharpPlus.Core.Models/ScheduledEvents/PartialScheduledEvent.cs +++ b/src/core/DSharpPlus.Core.Models/ScheduledEvents/PartialScheduledEvent.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using DSharpPlus.Entities; using Remora.Rest.Core; diff --git a/src/core/DSharpPlus.Core.Models/ScheduledEvents/ScheduledEvent.cs b/src/core/DSharpPlus.Core.Models/ScheduledEvents/ScheduledEvent.cs index 751cf6fa6f..842759b4a0 100644 --- a/src/core/DSharpPlus.Core.Models/ScheduledEvents/ScheduledEvent.cs +++ b/src/core/DSharpPlus.Core.Models/ScheduledEvents/ScheduledEvent.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using DSharpPlus.Entities; using Remora.Rest.Core; diff --git a/src/core/DSharpPlus.Core.Models/ScheduledEvents/ScheduledEventUser.cs b/src/core/DSharpPlus.Core.Models/ScheduledEvents/ScheduledEventUser.cs index 9e1312c668..ee2dff1986 100644 --- a/src/core/DSharpPlus.Core.Models/ScheduledEvents/ScheduledEventUser.cs +++ b/src/core/DSharpPlus.Core.Models/ScheduledEvents/ScheduledEventUser.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using Remora.Rest.Core; using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/StageInstances/PartialStageInstance.cs b/src/core/DSharpPlus.Core.Models/StageInstances/PartialStageInstance.cs index d1e210e907..34545c5252 100644 --- a/src/core/DSharpPlus.Core.Models/StageInstances/PartialStageInstance.cs +++ b/src/core/DSharpPlus.Core.Models/StageInstances/PartialStageInstance.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using DSharpPlus.Entities; using Remora.Rest.Core; diff --git a/src/core/DSharpPlus.Core.Models/StageInstances/StageInstance.cs b/src/core/DSharpPlus.Core.Models/StageInstances/StageInstance.cs index dd0c1d6dac..2366f05ee3 100644 --- a/src/core/DSharpPlus.Core.Models/StageInstances/StageInstance.cs +++ b/src/core/DSharpPlus.Core.Models/StageInstances/StageInstance.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using DSharpPlus.Entities; using Remora.Rest.Core; diff --git a/src/core/DSharpPlus.Core.Models/Stickers/PartialSticker.cs b/src/core/DSharpPlus.Core.Models/Stickers/PartialSticker.cs index a106ad6563..f8aac809fb 100644 --- a/src/core/DSharpPlus.Core.Models/Stickers/PartialSticker.cs +++ b/src/core/DSharpPlus.Core.Models/Stickers/PartialSticker.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using DSharpPlus.Entities; using Remora.Rest.Core; diff --git a/src/core/DSharpPlus.Core.Models/Stickers/Sticker.cs b/src/core/DSharpPlus.Core.Models/Stickers/Sticker.cs index a29c6552c4..120ef599cb 100644 --- a/src/core/DSharpPlus.Core.Models/Stickers/Sticker.cs +++ b/src/core/DSharpPlus.Core.Models/Stickers/Sticker.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using DSharpPlus.Entities; using Remora.Rest.Core; diff --git a/src/core/DSharpPlus.Core.Models/Stickers/StickerItem.cs b/src/core/DSharpPlus.Core.Models/Stickers/StickerItem.cs index 3cc8f6d00d..1c02604de5 100644 --- a/src/core/DSharpPlus.Core.Models/Stickers/StickerItem.cs +++ b/src/core/DSharpPlus.Core.Models/Stickers/StickerItem.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using DSharpPlus.Entities; using Remora.Rest.Core; diff --git a/src/core/DSharpPlus.Core.Models/Stickers/StickerPack.cs b/src/core/DSharpPlus.Core.Models/Stickers/StickerPack.cs index 494f61fe73..d83f1c4b86 100644 --- a/src/core/DSharpPlus.Core.Models/Stickers/StickerPack.cs +++ b/src/core/DSharpPlus.Core.Models/Stickers/StickerPack.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using System.Collections.Generic; using Remora.Rest.Core; diff --git a/src/core/DSharpPlus.Core.Models/Teams/Team.cs b/src/core/DSharpPlus.Core.Models/Teams/Team.cs index 8589c3ae3c..4e22073993 100644 --- a/src/core/DSharpPlus.Core.Models/Teams/Team.cs +++ b/src/core/DSharpPlus.Core.Models/Teams/Team.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using System.Collections.Generic; using Remora.Rest.Core; diff --git a/src/core/DSharpPlus.Core.Models/Teams/TeamMember.cs b/src/core/DSharpPlus.Core.Models/Teams/TeamMember.cs index 324f02b558..c9bf06785c 100644 --- a/src/core/DSharpPlus.Core.Models/Teams/TeamMember.cs +++ b/src/core/DSharpPlus.Core.Models/Teams/TeamMember.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using System.Collections.Generic; using DSharpPlus.Entities; diff --git a/src/core/DSharpPlus.Core.Models/Users/ApplicationRoleConnection.cs b/src/core/DSharpPlus.Core.Models/Users/ApplicationRoleConnection.cs index 90a9c84f73..8676778956 100644 --- a/src/core/DSharpPlus.Core.Models/Users/ApplicationRoleConnection.cs +++ b/src/core/DSharpPlus.Core.Models/Users/ApplicationRoleConnection.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using System.Collections.Generic; using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/Users/Connection.cs b/src/core/DSharpPlus.Core.Models/Users/Connection.cs index 5b63b970ba..93cf9d26f9 100644 --- a/src/core/DSharpPlus.Core.Models/Users/Connection.cs +++ b/src/core/DSharpPlus.Core.Models/Users/Connection.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using System.Collections.Generic; using DSharpPlus.Entities; diff --git a/src/core/DSharpPlus.Core.Models/Users/PartialUser.cs b/src/core/DSharpPlus.Core.Models/Users/PartialUser.cs index 0c5181dedc..07dda803e3 100644 --- a/src/core/DSharpPlus.Core.Models/Users/PartialUser.cs +++ b/src/core/DSharpPlus.Core.Models/Users/PartialUser.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using DSharpPlus.Entities; using Remora.Rest.Core; diff --git a/src/core/DSharpPlus.Core.Models/Users/User.cs b/src/core/DSharpPlus.Core.Models/Users/User.cs index 2b703470b4..65d134b1d7 100644 --- a/src/core/DSharpPlus.Core.Models/Users/User.cs +++ b/src/core/DSharpPlus.Core.Models/Users/User.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using DSharpPlus.Entities; using Remora.Rest.Core; diff --git a/src/core/DSharpPlus.Core.Models/Voice/VoiceRegion.cs b/src/core/DSharpPlus.Core.Models/Voice/VoiceRegion.cs index 0057c2d802..6fd9c671e0 100644 --- a/src/core/DSharpPlus.Core.Models/Voice/VoiceRegion.cs +++ b/src/core/DSharpPlus.Core.Models/Voice/VoiceRegion.cs @@ -1,7 +1,3 @@ -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/Voice/VoiceState.cs b/src/core/DSharpPlus.Core.Models/Voice/VoiceState.cs index 5efe9edc52..b66a70f416 100644 --- a/src/core/DSharpPlus.Core.Models/Voice/VoiceState.cs +++ b/src/core/DSharpPlus.Core.Models/Voice/VoiceState.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using System; using Remora.Rest.Core; diff --git a/src/core/DSharpPlus.Core.Models/Webhooks/PartialWebhook.cs b/src/core/DSharpPlus.Core.Models/Webhooks/PartialWebhook.cs index 13df3d4fc3..4c6d5558bb 100644 --- a/src/core/DSharpPlus.Core.Models/Webhooks/PartialWebhook.cs +++ b/src/core/DSharpPlus.Core.Models/Webhooks/PartialWebhook.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using DSharpPlus.Entities; using Remora.Rest.Core; diff --git a/src/core/DSharpPlus.Core.Models/Webhooks/Webhook.cs b/src/core/DSharpPlus.Core.Models/Webhooks/Webhook.cs index 25a7b6f055..f9cf3aea5f 100644 --- a/src/core/DSharpPlus.Core.Models/Webhooks/Webhook.cs +++ b/src/core/DSharpPlus.Core.Models/Webhooks/Webhook.cs @@ -2,10 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - using DSharpPlus.Entities; using Remora.Rest.Core; diff --git a/tools/generators/Tools.Generators.GenerateConcreteObjects/Program.cs b/tools/generators/Tools.Generators.GenerateConcreteObjects/Program.cs index 538e369d92..2b81886d92 100644 --- a/tools/generators/Tools.Generators.GenerateConcreteObjects/Program.cs +++ b/tools/generators/Tools.Generators.GenerateConcreteObjects/Program.cs @@ -173,7 +173,7 @@ Deleting counterparts to removed files... """ ); - usings.AppendLine + /*usings.AppendLine ( """ // This Source Code form is subject to the terms of the Mozilla Public @@ -181,7 +181,7 @@ Deleting counterparts to removed files... // file, You can obtain one at https://mozilla.org/MPL/2.0/. """ - ); + );*/ foreach (UsingDirectiveSyntax @using in root.Usings) { @@ -353,7 +353,7 @@ public sealed record {{name.Text[1..]}} : {{name.Text}} usings.Clear(); - usings.AppendLine + /*usings.AppendLine ( """ // This Source Code form is subject to the terms of the Mozilla Public @@ -361,7 +361,7 @@ public sealed record {{name.Text[1..]}} : {{name.Text}} // file, You can obtain one at https://mozilla.org/MPL/2.0/. """ - ); + );*/ foreach (UsingDirectiveSyntax @using in partialRoot.Usings) { From cf292df85b40b4f60ff52f78c85421652a2b796b Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Wed, 9 Aug 2023 18:56:38 +0200 Subject: [PATCH 082/323] emit placeholder impls for markers --- .../AutoModerationActionMetadata.cs | 12 +++++ .../Interactions/InteractionCallbackData.cs | 12 +++++ .../Interactions/InteractionData.cs | 12 +++++ .../MessageComponents/InteractiveComponent.cs | 12 +++++ .../Program.cs | 45 +++++++++++++++---- 5 files changed, 85 insertions(+), 8 deletions(-) create mode 100644 src/core/DSharpPlus.Core.Models/AutoModeration/AutoModerationActionMetadata.cs create mode 100644 src/core/DSharpPlus.Core.Models/Interactions/InteractionCallbackData.cs create mode 100644 src/core/DSharpPlus.Core.Models/Interactions/InteractionData.cs create mode 100644 src/core/DSharpPlus.Core.Models/MessageComponents/InteractiveComponent.cs diff --git a/src/core/DSharpPlus.Core.Models/AutoModeration/AutoModerationActionMetadata.cs b/src/core/DSharpPlus.Core.Models/AutoModeration/AutoModerationActionMetadata.cs new file mode 100644 index 0000000000..af60807425 --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/AutoModeration/AutoModerationActionMetadata.cs @@ -0,0 +1,12 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +/// Placeholder implementation for serialization purposes. Please report spotting this to library developers. +/// +internal sealed record AutoModerationActionMetadata : IAutoModerationActionMetadata; diff --git a/src/core/DSharpPlus.Core.Models/Interactions/InteractionCallbackData.cs b/src/core/DSharpPlus.Core.Models/Interactions/InteractionCallbackData.cs new file mode 100644 index 0000000000..2b9da32823 --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/Interactions/InteractionCallbackData.cs @@ -0,0 +1,12 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +/// Placeholder implementation for serialization purposes. Please report spotting this to library developers. +/// +internal sealed record InteractionCallbackData : IInteractionCallbackData; diff --git a/src/core/DSharpPlus.Core.Models/Interactions/InteractionData.cs b/src/core/DSharpPlus.Core.Models/Interactions/InteractionData.cs new file mode 100644 index 0000000000..a9a5874d3d --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/Interactions/InteractionData.cs @@ -0,0 +1,12 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +/// Placeholder implementation for serialization purposes. Please report spotting this to library developers. +/// +internal sealed record InteractionData : IInteractionData; diff --git a/src/core/DSharpPlus.Core.Models/MessageComponents/InteractiveComponent.cs b/src/core/DSharpPlus.Core.Models/MessageComponents/InteractiveComponent.cs new file mode 100644 index 0000000000..3457bf385c --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/MessageComponents/InteractiveComponent.cs @@ -0,0 +1,12 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +/// Placeholder implementation for serialization purposes. Please report spotting this to library developers. +/// +internal sealed record InteractiveComponent : IInteractiveComponent; diff --git a/tools/generators/Tools.Generators.GenerateConcreteObjects/Program.cs b/tools/generators/Tools.Generators.GenerateConcreteObjects/Program.cs index 2b81886d92..b1a68a4f5f 100644 --- a/tools/generators/Tools.Generators.GenerateConcreteObjects/Program.cs +++ b/tools/generators/Tools.Generators.GenerateConcreteObjects/Program.cs @@ -82,7 +82,7 @@ [red]The paths provided could not be found on the file system.[/] AnsiConsole.MarkupLine ( """ - [darkseagreen1_1]There were no changes to the interface definitions, exiting generator.[/] + [darkseagreen1_1]There were no changes to the interface definitions, exiting generate-concrete-objects.[/] """ ); @@ -235,18 +235,13 @@ namespace DSharpPlus.Core.Models; AnsiConsole.MarkupLine ( $""" - Marker interface detected, abandoning generation. + Marker interface detected, generating empty implementation. """ ); marker = true; } } - if (marker) - { - continue; - } - // make sure partial-inheriting interfaces get updated too if (interfaceSyntax.Identifier.ToString().StartsWith("IPartial")) { @@ -257,6 +252,41 @@ namespace DSharpPlus.Core.Models; } } + FileInfo outInfo = new(outPath); + + if (marker) + { + writer.Clear(); + + writer.AppendLine + ( +$$""" +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +/// Placeholder implementation for serialization purposes. Please report spotting this to library developers. +/// +internal sealed record {{name.Text[1..]}} : {{name.Text}}; +""" + ); + if (!Directory.Exists(outInfo.DirectoryName!)) + { + Directory.CreateDirectory(outInfo.DirectoryName!); + } + + File.WriteAllText(outPath, writer.ToString()); + + emittedFiles.Add(outPath); + + continue; + } + writer.AppendLine ( $$""" @@ -396,7 +426,6 @@ public sealed record {{name.Text[1..]}} : {{name.Text}} writer.Append('}'); // ensure the directory at least exists - FileInfo outInfo = new(outPath); if (!Directory.Exists(outInfo.DirectoryName!)) { Directory.CreateDirectory(outInfo.DirectoryName!); From 7058a73918b0e94d32bd0f637affd5e772e3f099 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Wed, 9 Aug 2023 21:05:39 +0200 Subject: [PATCH 083/323] audit log change converter --- .../Converters/AuditLogChangeConverter.cs | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 src/core/DSharpPlus.Core.Models/Converters/AuditLogChangeConverter.cs diff --git a/src/core/DSharpPlus.Core.Models/Converters/AuditLogChangeConverter.cs b/src/core/DSharpPlus.Core.Models/Converters/AuditLogChangeConverter.cs new file mode 100644 index 0000000000..8eb6414e1e --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/Converters/AuditLogChangeConverter.cs @@ -0,0 +1,73 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; +using System.Text.Json; +using System.Text.Json.Serialization; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models.Converters; + +/// +/// Provides conversion for s. +/// +public class AuditLogChangeConverter : JsonConverter +{ + /// + public override IAuditLogChange? Read + ( + ref Utf8JsonReader reader, + Type typeToConvert, + JsonSerializerOptions options + ) + { + if (reader.TokenType != JsonTokenType.StartObject) + { + throw new JsonException("There was no JSON object found."); + } + + if + ( + !JsonDocument.TryParseValue(ref reader, out JsonDocument? document) + || document.RootElement.TryGetProperty("key", out JsonElement propertyKey) + || document.RootElement.TryGetProperty("new_value", out JsonElement newProperty) + || document.RootElement.TryGetProperty("old_value", out JsonElement oldProperty) + ) + { + throw new JsonException("The provided JSON object was malformed."); + } + + string key = propertyKey.GetString()!; + + return new AuditLogChange + { + Key = key, + NewValue = newProperty, + OldValue = oldProperty + }; + } + + /// + public override void Write + ( + Utf8JsonWriter writer, + IAuditLogChange value, + JsonSerializerOptions options + ) + { + writer.WriteStartObject(); + + writer.WritePropertyName("key"); + writer.WriteStringValue(value.Key); + + writer.WritePropertyName("new_value"); + value.NewValue.WriteTo(writer); + + writer.WritePropertyName("old_value"); + value.OldValue.WriteTo(writer); + + writer.WriteEndObject(); + } +} From 6a52bffc3de9eb214db72a8e6c028360b537a612 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Wed, 9 Aug 2023 21:14:31 +0200 Subject: [PATCH 084/323] permission converter --- .../Converters/DiscordPermissionConverter.cs | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/core/DSharpPlus.Core.Models/Converters/DiscordPermissionConverter.cs diff --git a/src/core/DSharpPlus.Core.Models/Converters/DiscordPermissionConverter.cs b/src/core/DSharpPlus.Core.Models/Converters/DiscordPermissionConverter.cs new file mode 100644 index 0000000000..a97918938b --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/Converters/DiscordPermissionConverter.cs @@ -0,0 +1,46 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; +using System.Text.Json; +using System.Text.Json.Serialization; + +using DSharpPlus.Entities; + +namespace DSharpPlus.Core.Models.Converters; + +/// +/// Enables serializing and deserializing Discord permissions. +/// +public class DiscordPermissionConverter : JsonConverter +{ + /// + public override DiscordPermissions Read + ( + ref Utf8JsonReader reader, + Type typeToConvert, + JsonSerializerOptions options + ) + { + if (reader.TokenType is not JsonTokenType.String or JsonTokenType.Number) + { + throw new JsonException("The provided permission value was provided in an unrecognized format."); + } + + string raw = reader.GetString()!; + + return !ulong.TryParse(raw, out ulong permissions) + ? throw new JsonException("The provided permission value could not be parsed.") + : (DiscordPermissions)permissions; + } + + /// + public override void Write + ( + Utf8JsonWriter writer, + DiscordPermissions value, + JsonSerializerOptions options + ) + => writer.WriteStringValue(((ulong)value).ToString()); +} From ce1c58ae9f9b33d6e544671bee3c2ca45432fe04 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Wed, 9 Aug 2023 21:58:10 +0200 Subject: [PATCH 085/323] auto moderation action converter --- .../ISendAlertMessageActionMetadata.cs | 2 +- .../AutoModerationActionConverter.cs | 101 ++++++++++++++++++ 2 files changed, 102 insertions(+), 1 deletion(-) create mode 100644 src/core/DSharpPlus.Core.Models/Converters/AutoModerationActionConverter.cs diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/AutoModeration/ISendAlertMessageActionMetadata.cs b/src/core/DSharpPlus.Core.Abstractions.Models/AutoModeration/ISendAlertMessageActionMetadata.cs index f045bdac72..d99774cb4e 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/AutoModeration/ISendAlertMessageActionMetadata.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/AutoModeration/ISendAlertMessageActionMetadata.cs @@ -12,7 +12,7 @@ namespace DSharpPlus.Core.Abstractions.Models; /// Represents metadata for auto moderation actions of type /// . /// -public interface ISendAlertMessageActionMetadata +public interface ISendAlertMessageActionMetadata : IAutoModerationActionMetadata { /// /// The snowflake identifier of the channel to which content should be logged. diff --git a/src/core/DSharpPlus.Core.Models/Converters/AutoModerationActionConverter.cs b/src/core/DSharpPlus.Core.Models/Converters/AutoModerationActionConverter.cs new file mode 100644 index 0000000000..96407177c9 --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/Converters/AutoModerationActionConverter.cs @@ -0,0 +1,101 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; +using System.Text.Json; +using System.Text.Json.Serialization; + +using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Entities; + +using Remora.Rest.Core; + +namespace DSharpPlus.Core.Models.Converters; + +/// +/// Provides conversion for . +/// +public class AutoModerationActionConverter : JsonConverter +{ + /// + public override IAutoModerationAction? Read + ( + ref Utf8JsonReader reader, + Type typeToConvert, + JsonSerializerOptions options + ) + { + if (reader.TokenType != JsonTokenType.StartObject) + { + throw new JsonException("There was no JSON object found."); + } + + if + ( + !JsonDocument.TryParseValue(ref reader, out JsonDocument? document) + || document.RootElement.TryGetProperty("type", out JsonElement property) + || !property.TryGetInt32(out int type) + || document.RootElement.TryGetProperty("metadata", out JsonElement metadata) + ) + { + throw new JsonException("The provided JSON object was malformed."); + } + + Optional data = (DiscordAutoModerationActionType)type switch + { + DiscordAutoModerationActionType.BlockMessage + => new(JsonSerializer.Deserialize(metadata, options)!), + DiscordAutoModerationActionType.SendAlertMessage + => new(JsonSerializer.Deserialize(metadata, options)!), + DiscordAutoModerationActionType.Timeout + => new(JsonSerializer.Deserialize(metadata, options)!), + _ => new() + }; + + return new AutoModerationAction + { + Type = (DiscordAutoModerationActionType)type, + Metadata = data + }; + } + + /// + public override void Write + ( + Utf8JsonWriter writer, + IAutoModerationAction value, + JsonSerializerOptions options + ) + { + writer.WriteStartObject(); + + writer.WritePropertyName("type"); + writer.WriteNumberValue((int)value.Type); + + if (!value.Metadata.IsDefined(out IAutoModerationActionMetadata? metadata)) + { + writer.WriteEndObject(); + return; + } + + writer.WritePropertyName("metadata"); + + switch (metadata) + { + case IBlockMessageActionMetadata block: + JsonSerializer.Serialize(writer, block, options); + break; + + case ISendAlertMessageActionMetadata alert: + JsonSerializer.Serialize(writer, alert, options); + break; + + case ITimeoutActionMetadata timeout: + JsonSerializer.Serialize(writer, timeout, options); + break; + } + + writer.WriteEndObject(); + } +} From 3e7c84ebf01748a4aab796b4dfea93eb87ae2908 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Fri, 11 Aug 2023 22:11:07 +0200 Subject: [PATCH 086/323] encode interaction data and callback data in a serializable format --- .../IApplicationCommandInteractionData.cs | 2 +- ...ApplicationCommandInteractionDataOption.cs | 5 ++ .../IAutocompleteInteractionData.cs | 48 ------------------- .../IAutocompleteInteractionDataOption.cs | 46 ------------------ .../Interactions/IInteraction.cs | 4 +- .../Interactions/IInteractionCallbackData.cs | 10 ---- .../Interactions/IInteractionData.cs | 12 ----- .../Interactions/IInteractionResponse.cs | 4 +- .../Interactions/IMessageCallbackData.cs | 2 +- .../IMessageComponentInteractionData.cs | 2 +- .../Interactions/IModalInteractionData.cs | 2 +- ...ApplicationCommandInteractionDataOption.cs | 3 ++ .../Interactions/Interaction.cs | 4 +- .../Interactions/InteractionCallbackData.cs | 12 ----- .../Interactions/InteractionData.cs | 12 ----- .../Interactions/InteractionResponse.cs | 4 +- 16 files changed, 24 insertions(+), 148 deletions(-) delete mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IAutocompleteInteractionData.cs delete mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IAutocompleteInteractionDataOption.cs delete mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IInteractionCallbackData.cs delete mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IInteractionData.cs delete mode 100644 src/core/DSharpPlus.Core.Models/Interactions/InteractionCallbackData.cs delete mode 100644 src/core/DSharpPlus.Core.Models/Interactions/InteractionData.cs diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IApplicationCommandInteractionData.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IApplicationCommandInteractionData.cs index 4e80aee19f..5f5cb60abb 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IApplicationCommandInteractionData.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IApplicationCommandInteractionData.cs @@ -13,7 +13,7 @@ namespace DSharpPlus.Core.Abstractions.Models; /// /// Contains the interaction metadata for application commands. /// -public interface IApplicationCommandInteractionData : IInteractionData +public interface IApplicationCommandInteractionData { /// /// The snowflake identifier of the invoked command. diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IApplicationCommandInteractionDataOption.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IApplicationCommandInteractionDataOption.cs index e5d3a0ba47..98a927682a 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IApplicationCommandInteractionDataOption.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IApplicationCommandInteractionDataOption.cs @@ -37,4 +37,9 @@ public interface IApplicationCommandInteractionDataOption /// its subcommands. /// public Optional> Options { get; } + + /// + /// Indicates whether this option is currently focused for autocomplete. + /// + public Optional Focused { get; } } diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IAutocompleteInteractionData.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IAutocompleteInteractionData.cs deleted file mode 100644 index 6ec90dee1e..0000000000 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IAutocompleteInteractionData.cs +++ /dev/null @@ -1,48 +0,0 @@ -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -using DSharpPlus.Entities; - -using Remora.Rest.Core; - -using System.Collections.Generic; - -namespace DSharpPlus.Core.Abstractions.Models; - -/// -/// Contains the interaction metadata for application commands during the autocomplete process. -/// -public interface IAutocompleteInteractionData : IInteractionData -{ - /// - /// The snowflake identifier of the invoked command. - /// - public Snowflake Id { get; } - - /// - /// The name of the invoked command. - /// - public string Name { get; } - - /// - /// The type of the invoked command. - /// - public DiscordApplicationCommandType Type { get; } - - /// - /// Contains resolved users, guild members, roles, channels, messages and attachments related to this - /// interaction. - /// - public Optional Resolved { get; } - - /// - /// The parameters and passed values from the user. - /// - public Optional> Options { get; } - - /// - /// The snowflake identifier of the guild this command is being registered to. - /// - public Optional GuildId { get; } -} diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IAutocompleteInteractionDataOption.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IAutocompleteInteractionDataOption.cs deleted file mode 100644 index 5d803fe362..0000000000 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IAutocompleteInteractionDataOption.cs +++ /dev/null @@ -1,46 +0,0 @@ -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -using System.Collections.Generic; - -using DSharpPlus.Entities; - -using OneOf; - -using Remora.Rest.Core; - -namespace DSharpPlus.Core.Abstractions.Models; - -/// -/// Represents submitted data for a single application command data option during the autocomplete -/// process. -/// -public interface IAutocompleteInteractionDataOption -{ - /// - /// The name of the option. - /// - public string Name { get; } - - /// - /// The type of this option. - /// - public DiscordApplicationCommandOptionType Type { get; } - - /// - /// The value passed to this option by the user. - /// - public Optional> Value { get; } - - /// - /// If this is a subcommand, the values passed to its parameters. If this is a subcommand group, - /// its subcommands. - /// - public Optional> Options { get; } - - /// - /// Indicates whether this option is currently focused for autocomplete. - /// - public Optional Focused { get; } -} diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IInteraction.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IInteraction.cs index b5ffd64cc9..ecb4044b73 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IInteraction.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IInteraction.cs @@ -4,6 +4,8 @@ using DSharpPlus.Entities; +using OneOf; + using Remora.Rest.Core; namespace DSharpPlus.Core.Abstractions.Models; @@ -36,7 +38,7 @@ public interface IInteraction /// /// The data payload, depending on the . /// - public Optional Data { get; } + public Optional> Data { get; } /// /// The snowflake identifier of the guild this interaction was sent from, if applicable. diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IInteractionCallbackData.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IInteractionCallbackData.cs deleted file mode 100644 index 4e9e8f56a9..0000000000 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IInteractionCallbackData.cs +++ /dev/null @@ -1,10 +0,0 @@ -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -namespace DSharpPlus.Core.Abstractions.Models; - -/// -/// Represents a response message to an interaction. -/// -public interface IInteractionCallbackData; diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IInteractionData.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IInteractionData.cs deleted file mode 100644 index 4de47c9e8a..0000000000 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IInteractionData.cs +++ /dev/null @@ -1,12 +0,0 @@ -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -namespace DSharpPlus.Core.Abstractions.Models; - -/// -/// Represents metadata attached to an interaction. -/// -// This interface, by itself, does nothing. Type has to be resolved based on IInteraction.Type -// and casted appropriately to one of the derived interface types. -public interface IInteractionData; diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IInteractionResponse.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IInteractionResponse.cs index 2f94fb23bf..45ca5942dc 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IInteractionResponse.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IInteractionResponse.cs @@ -4,6 +4,8 @@ using DSharpPlus.Entities; +using OneOf; + using Remora.Rest.Core; namespace DSharpPlus.Core.Abstractions.Models; @@ -21,5 +23,5 @@ public interface IInteractionResponse /// /// An additional response message for this interaction. /// - public Optional Data { get; } + public Optional> Data { get; } } diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IMessageCallbackData.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IMessageCallbackData.cs index 9c440bcd78..82eb2ca64c 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IMessageCallbackData.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IMessageCallbackData.cs @@ -13,7 +13,7 @@ namespace DSharpPlus.Core.Abstractions.Models; /// /// Represents a response payload for creating or updating a message. /// -public interface IMessageCallbackData : IInteractionCallbackData +public interface IMessageCallbackData { /// /// Indicates whether the response is a TTS message. diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IMessageComponentInteractionData.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IMessageComponentInteractionData.cs index 6f26d7fc13..ba5e157e10 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IMessageComponentInteractionData.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IMessageComponentInteractionData.cs @@ -13,7 +13,7 @@ namespace DSharpPlus.Core.Abstractions.Models; /// /// Represents metadata for a message component interaction. /// -public interface IMessageComponentInteractionData : IInteractionData +public interface IMessageComponentInteractionData { /// /// The developer-defined ID of the component. diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IModalInteractionData.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IModalInteractionData.cs index 19a98f9d71..3c3310dd64 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IModalInteractionData.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IModalInteractionData.cs @@ -9,7 +9,7 @@ namespace DSharpPlus.Core.Abstractions.Models; /// /// Contains metadata for a modal submission interaction. /// -public interface IModalInteractionData : IInteractionData +public interface IModalInteractionData { /// /// The developer-defined ID of this modal. diff --git a/src/core/DSharpPlus.Core.Models/Interactions/ApplicationCommandInteractionDataOption.cs b/src/core/DSharpPlus.Core.Models/Interactions/ApplicationCommandInteractionDataOption.cs index b5282cc35b..9d7a13ee1a 100644 --- a/src/core/DSharpPlus.Core.Models/Interactions/ApplicationCommandInteractionDataOption.cs +++ b/src/core/DSharpPlus.Core.Models/Interactions/ApplicationCommandInteractionDataOption.cs @@ -28,4 +28,7 @@ public sealed record ApplicationCommandInteractionDataOption : IApplicationComma /// public Optional> Options { get; init; } + + /// + public Optional Focused { get; init; } } \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/Interactions/Interaction.cs b/src/core/DSharpPlus.Core.Models/Interactions/Interaction.cs index 56f17fe5b7..631314c7cd 100644 --- a/src/core/DSharpPlus.Core.Models/Interactions/Interaction.cs +++ b/src/core/DSharpPlus.Core.Models/Interactions/Interaction.cs @@ -4,6 +4,8 @@ using DSharpPlus.Entities; +using OneOf; + using Remora.Rest.Core; using DSharpPlus.Core.Abstractions.Models; @@ -23,7 +25,7 @@ public sealed record Interaction : IInteraction public required DiscordInteractionType Type { get; init; } /// - public Optional Data { get; init; } + public Optional> Data { get; init; } /// public Optional GuildId { get; init; } diff --git a/src/core/DSharpPlus.Core.Models/Interactions/InteractionCallbackData.cs b/src/core/DSharpPlus.Core.Models/Interactions/InteractionCallbackData.cs deleted file mode 100644 index 2b9da32823..0000000000 --- a/src/core/DSharpPlus.Core.Models/Interactions/InteractionCallbackData.cs +++ /dev/null @@ -1,12 +0,0 @@ -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -using DSharpPlus.Core.Abstractions.Models; - -namespace DSharpPlus.Core.Models; - -/// -/// Placeholder implementation for serialization purposes. Please report spotting this to library developers. -/// -internal sealed record InteractionCallbackData : IInteractionCallbackData; diff --git a/src/core/DSharpPlus.Core.Models/Interactions/InteractionData.cs b/src/core/DSharpPlus.Core.Models/Interactions/InteractionData.cs deleted file mode 100644 index a9a5874d3d..0000000000 --- a/src/core/DSharpPlus.Core.Models/Interactions/InteractionData.cs +++ /dev/null @@ -1,12 +0,0 @@ -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -using DSharpPlus.Core.Abstractions.Models; - -namespace DSharpPlus.Core.Models; - -/// -/// Placeholder implementation for serialization purposes. Please report spotting this to library developers. -/// -internal sealed record InteractionData : IInteractionData; diff --git a/src/core/DSharpPlus.Core.Models/Interactions/InteractionResponse.cs b/src/core/DSharpPlus.Core.Models/Interactions/InteractionResponse.cs index 8575b0d28d..b2ea703f5e 100644 --- a/src/core/DSharpPlus.Core.Models/Interactions/InteractionResponse.cs +++ b/src/core/DSharpPlus.Core.Models/Interactions/InteractionResponse.cs @@ -4,6 +4,8 @@ using DSharpPlus.Entities; +using OneOf; + using Remora.Rest.Core; using DSharpPlus.Core.Abstractions.Models; @@ -17,5 +19,5 @@ public sealed record InteractionResponse : IInteractionResponse public required DiscordInteractionCallbackType Type { get; init; } /// - public Optional Data { get; init; } + public Optional> Data { get; init; } } \ No newline at end of file From 00f9ef5ad6ff5bbf4a2ad215bcc126365be139bd Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sat, 12 Aug 2023 13:40:54 +0200 Subject: [PATCH 087/323] fix file removing in the generator --- .../MetadataCollection.cs | 8 ++- .../Program.cs | 50 ++++++++++++------- 2 files changed, 39 insertions(+), 19 deletions(-) diff --git a/tools/Tools.IncrementalUtility/MetadataCollection.cs b/tools/Tools.IncrementalUtility/MetadataCollection.cs index 3b09aff56d..eb8168262c 100644 --- a/tools/Tools.IncrementalUtility/MetadataCollection.cs +++ b/tools/Tools.IncrementalUtility/MetadataCollection.cs @@ -79,9 +79,13 @@ params string[] files name => !oldHashes.ContainsKey(name) ); - IEnumerable removed = files.Where + IEnumerable removed = oldHashes.Where ( - name => oldHashes.ContainsKey(name) && !this.hashes.ContainsKey(name) + candidate => !this.hashes.ContainsKey(candidate.Key) + ) + .Select + ( + kvp => kvp.Key ); IEnumerable modified = files.Where diff --git a/tools/generators/Tools.Generators.GenerateConcreteObjects/Program.cs b/tools/generators/Tools.Generators.GenerateConcreteObjects/Program.cs index b1a68a4f5f..5a2a7957d3 100644 --- a/tools/generators/Tools.Generators.GenerateConcreteObjects/Program.cs +++ b/tools/generators/Tools.Generators.GenerateConcreteObjects/Program.cs @@ -32,15 +32,22 @@ public static int Main(string[] args) AnsiConsole.MarkupLine ( """ - DSharpPlus Concrete API Object Generator, v0.1.0 + [plum1]DSharpPlus Concrete API Object Generator, v0.1.0[/] - [plum1]Usage: generate-concrete-objects path/to/abstractions/root output/path[/] + Usage: generate-concrete-objects path/to/abstractions/root output/path """ ); return 0; } + AnsiConsole.MarkupLine + ( + """ + [plum1]DSharpPlus Concrete API Object Generator, v0.1.0[/] + """ + ); + string input, output; // there are no args passed, proceed with default args: @@ -94,26 +101,32 @@ [red]The paths provided could not be found on the file system.[/] ( $""" {changes.Added.Count()} added, {changes.Modified.Count()} modified, {changes.Removed.Count()} removed. - Generating concrete objects... """ ); } - AnsiConsole.MarkupLine - ( - """ - Deleting counterparts to removed files... - """ - ); + if (changes.Removed.Any()) + { + AnsiConsole.MarkupLine + ( + """ + Deleting counterparts to removed files... + """ + ); + } foreach (string path in changes.Removed) { - string deletePath = string.Concat(output, path.AsSpan(input.Length)); + FileInfo file = new(path); + string fullPath = file.FullName.Replace('\\', '/'); + + int index = fullPath.LastIndexOf("/"); + string deletePath = fullPath.Remove(index + 1, 1).Replace(input, output); AnsiConsole.MarkupLine ( $""" - Deleting '{deletePath.Replace('\\', '/')}' + Deleting '{deletePath}' """ ); @@ -123,12 +136,15 @@ Deleting counterparts to removed files... } } - AnsiConsole.MarkupLine - ( - """ - Generating objects for modified/new definitions... - """ - ); + if (changes.Added.Any() || changes.Modified.Any()) + { + AnsiConsole.MarkupLine + ( + """ + Generating objects for modified/new definitions... + """ + ); + } IEnumerable added = changes.Added.Select ( From 5dde1f475cc089adfda692e979c64058e66c58df Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sun, 13 Aug 2023 17:28:30 +0200 Subject: [PATCH 088/323] null boolean converter for role tags --- .../Converters/NullBooleanConverter.cs | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/core/DSharpPlus.Core.Models/Converters/NullBooleanConverter.cs diff --git a/src/core/DSharpPlus.Core.Models/Converters/NullBooleanConverter.cs b/src/core/DSharpPlus.Core.Models/Converters/NullBooleanConverter.cs new file mode 100644 index 0000000000..b930cf00de --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/Converters/NullBooleanConverter.cs @@ -0,0 +1,45 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; +using System.Text.Json; +using System.Text.Json.Serialization; + +namespace DSharpPlus.Core.Models.Converters; + +/// +/// Provides serialization for discord's optional null booleans, see +/// . +/// +/// +/// This needs to be applied to every null boolean property individually. +/// +public class NullBooleanJsonConverter : JsonConverter +{ + // if the token type is False or True we have an actual boolean on our hands and should read it + // appropriately. if not, we judge by the existence of the token (which is what discord sends). + public override bool Read + ( + ref Utf8JsonReader reader, + Type typeToConvert, + JsonSerializerOptions options + ) + { + bool? value = JsonSerializer.Deserialize(ref reader, options); + + // null is a 'true' value. + return value != false; + } + + // slightly off, but since we can't ever actually send this to discord we don't need to deal + // with any of this. we'll serialize it as a correct boolean so it can be read correctly if the + // end user uses our models for serialization. + public override void Write + ( + Utf8JsonWriter writer, + bool value, + JsonSerializerOptions options + ) + => writer.WriteBooleanValue(value); +} From 5a3c9ddedcd5b97dca28eb66875a5338cc51197d Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Fri, 18 Aug 2023 15:54:46 +0200 Subject: [PATCH 089/323] register all converters --- Directory.Packages.props | 5 +- .../DSharpPlus.Core.Models.csproj | 5 + .../JsonSerializerOptionsExtensions.cs | 357 ++++++++++++++++++ .../Extensions/ServiceCollectionExtensions.cs | 72 ++++ 4 files changed, 437 insertions(+), 2 deletions(-) create mode 100644 src/core/DSharpPlus.Core.Models/Extensions/JsonSerializerOptionsExtensions.cs create mode 100644 src/core/DSharpPlus.Core.Models/Extensions/ServiceCollectionExtensions.cs diff --git a/Directory.Packages.props b/Directory.Packages.props index 638ed34b04..c19df031cc 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -5,13 +5,14 @@ + + - - + diff --git a/src/core/DSharpPlus.Core.Models/DSharpPlus.Core.Models.csproj b/src/core/DSharpPlus.Core.Models/DSharpPlus.Core.Models.csproj index ac4bf37d14..a3df296268 100644 --- a/src/core/DSharpPlus.Core.Models/DSharpPlus.Core.Models.csproj +++ b/src/core/DSharpPlus.Core.Models/DSharpPlus.Core.Models.csproj @@ -6,6 +6,11 @@ Library + + + + + diff --git a/src/core/DSharpPlus.Core.Models/Extensions/JsonSerializerOptionsExtensions.cs b/src/core/DSharpPlus.Core.Models/Extensions/JsonSerializerOptionsExtensions.cs new file mode 100644 index 0000000000..2cf5a4f3f5 --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/Extensions/JsonSerializerOptionsExtensions.cs @@ -0,0 +1,357 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Text.Json; +using System.Text.Json.Serialization.Metadata; + +using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Core.Models.Converters; + +using Remora.Rest.Extensions; + +namespace DSharpPlus.Core.Models.Extensions; + +/// +/// Provides segmented registration for Discord API object serialization. +/// +internal static class JsonSerializerOptionsExtensions +{ + /// + /// Registers object converters for application commands. + /// + public static void RegisterApplicationCommands + ( + this JsonSerializerOptions options + ) + { + options.AddDataObjectConverter(); + options.AddDataObjectConverter(); + options.AddDataObjectConverter(); + options.AddDataObjectConverter(); + options.AddDataObjectConverter(); + options.AddDataObjectConverter(); + } + + /// + /// Registers object converters for applications. + /// + public static void RegisterApplications + ( + this JsonSerializerOptions options + ) + { + options.AddDataObjectConverter(); + options.AddDataObjectConverter(); + options.AddDataObjectConverter(); + } + + /// + /// Registers object converters for audit logs. + /// + public static void RegisterAuditLogs + ( + this JsonSerializerOptions options + ) + { + options.AddDataObjectConverter(); + options.AddDataObjectConverter(); + options.AddDataObjectConverter(); + } + + /// + /// Registers object converters for auto moderation. + /// + public static void RegisterAutoModeration + ( + this JsonSerializerOptions options + ) + { + options.AddDataObjectConverter(); + options.AddDataObjectConverter(); + options.AddDataObjectConverter(); + options.AddDataObjectConverter(); + options.AddDataObjectConverter(); + options.AddDataObjectConverter(); + options.AddDataObjectConverter(); + } + + /// + /// Registers object converters for channels. + /// + public static void RegisterChannels + ( + this JsonSerializerOptions options + ) + { + options.AddDataObjectConverter(); + options.AddDataObjectConverter(); + options.AddDataObjectConverter(); + options.AddDataObjectConverter(); + options.AddDataObjectConverter(); + options.AddDataObjectConverter(); + options.AddDataObjectConverter(); + options.AddDataObjectConverter(); + options.AddDataObjectConverter(); + options.AddDataObjectConverter(); + options.AddDataObjectConverter(); + options.AddDataObjectConverter(); + options.AddDataObjectConverter(); + options.AddDataObjectConverter(); + options.AddDataObjectConverter(); + options.AddDataObjectConverter(); + options.AddDataObjectConverter(); + options.AddDataObjectConverter(); + options.AddDataObjectConverter(); + options.AddDataObjectConverter(); + options.AddDataObjectConverter(); + options.AddDataObjectConverter(); + options.AddDataObjectConverter(); + options.AddDataObjectConverter(); + options.AddDataObjectConverter(); + options.AddDataObjectConverter(); + options.AddDataObjectConverter(); + } + + /// + /// Registers object converters for emojis. + /// + public static void RegisterEmojis + ( + this JsonSerializerOptions options + ) + { + options.AddDataObjectConverter(); + options.AddDataObjectConverter(); + } + + /// + /// Registers object converters for guilds. + /// + public static void RegisterGuilds + ( + this JsonSerializerOptions options + ) + { + options.AddDataObjectConverter(); + options.AddDataObjectConverter(); + options.AddDataObjectConverter(); + options.AddDataObjectConverter(); + options.AddDataObjectConverter(); + options.AddDataObjectConverter(); + options.AddDataObjectConverter(); + options.AddDataObjectConverter(); + options.AddDataObjectConverter(); + options.AddDataObjectConverter(); + options.AddDataObjectConverter(); + options.AddDataObjectConverter(); + options.AddDataObjectConverter(); + options.AddDataObjectConverter(); + options.AddDataObjectConverter(); + options.AddDataObjectConverter(); + + options.AddDataObjectConverter() + .WithPropertyConverter + ( + o => o.AvailableForPurchase, + new NullBooleanJsonConverter() + ) + .WithPropertyConverter + ( + o => o.GuildConnections, + new NullBooleanJsonConverter() + ) + .WithPropertyConverter + ( + o => o.PremiumSubscriber, + new NullBooleanJsonConverter() + ); + + options.TypeInfoResolverChain.Add + ( + new DefaultJsonTypeInfoResolver + { + Modifiers = + { + (JsonTypeInfo type) => + { + if (type.Type != typeof(RoleTags)) + { + return; + } + + foreach (JsonPropertyInfo property in type.Properties) + { + if (property.PropertyType == typeof(bool)) + { + property.IsRequired = false; + } + } + } + } + } + ); + + options.AddDataObjectConverter(); + options.AddDataObjectConverter(); + } + + /// + /// Registers object converters for guild templates. + /// + public static void RegisterGuildTemplates + ( + this JsonSerializerOptions options + ) + => options.AddDataObjectConverter(); + + /// + /// Registers object converters for interactions. + /// + public static void RegisterInteractions + ( + this JsonSerializerOptions options + ) + { + options.AddDataObjectConverter(); + options.AddDataObjectConverter(); + options.AddDataObjectConverter(); + options.AddDataObjectConverter(); + options.AddDataObjectConverter(); + options.AddDataObjectConverter(); + options.AddDataObjectConverter(); + options.AddDataObjectConverter(); + options.AddDataObjectConverter(); + options.AddDataObjectConverter(); + options.AddDataObjectConverter(); + } + + /// + /// Registers object converters for invites. + /// + public static void RegisterInvites + ( + this JsonSerializerOptions options + ) + { + options.AddDataObjectConverter(); + options.AddDataObjectConverter(); + } + + /// + /// Registers object converters for message components. + /// + public static void RegisterMessageComponents + ( + this JsonSerializerOptions options + ) + { + options.AddDataObjectConverter(); + options.AddDataObjectConverter(); + options.AddDataObjectConverter(); + options.AddDataObjectConverter(); + options.AddDataObjectConverter(); + options.AddDataObjectConverter(); + options.AddDataObjectConverter(); + options.AddDataObjectConverter(); + options.AddDataObjectConverter(); + } + + /// + /// Registers object converters for role connections. + /// + public static void RegisterRoleConnections + ( + this JsonSerializerOptions options + ) + => options.AddDataObjectConverter(); + + /// + /// Registers object converters for scheduled events. + /// + public static void RegisterScheduledEvents + ( + this JsonSerializerOptions options + ) + { + options.AddDataObjectConverter(); + options.AddDataObjectConverter(); + options.AddDataObjectConverter(); + } + + /// + /// Registers object converters for stage instances. + /// + public static void RegisterStageInstances + ( + this JsonSerializerOptions options + ) + { + options.AddDataObjectConverter(); + options.AddDataObjectConverter(); + } + + /// + /// Registers object converters for stickers. + /// + public static void RegisterStickers + ( + this JsonSerializerOptions options + ) + { + options.AddDataObjectConverter(); + options.AddDataObjectConverter(); + options.AddDataObjectConverter(); + options.AddDataObjectConverter(); + } + + /// + /// Registers object converters for teams. + /// + public static void RegisterTeams + ( + this JsonSerializerOptions options + ) + { + options.AddDataObjectConverter(); + options.AddDataObjectConverter(); + } + + /// + /// Registers object converters for users. + /// + public static void RegisterUsers + ( + this JsonSerializerOptions options + ) + { + options.AddDataObjectConverter(); + options.AddDataObjectConverter(); + options.AddDataObjectConverter(); + options.AddDataObjectConverter(); + } + + /// + /// Registers object converters for voice. + /// + public static void RegisterVoice + ( + this JsonSerializerOptions options + ) + { + options.AddDataObjectConverter(); + options.AddDataObjectConverter(); + } + + /// + /// Registers object converters for webhooks. + /// + public static void RegisterWebhooks + ( + this JsonSerializerOptions options + ) + { + options.AddDataObjectConverter(); + options.AddDataObjectConverter(); + } +} diff --git a/src/core/DSharpPlus.Core.Models/Extensions/ServiceCollectionExtensions.cs b/src/core/DSharpPlus.Core.Models/Extensions/ServiceCollectionExtensions.cs new file mode 100644 index 0000000000..97ea24502e --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/Extensions/ServiceCollectionExtensions.cs @@ -0,0 +1,72 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Text.Json; + +using DSharpPlus.Core.Models.Converters; + +using Microsoft.Extensions.DependencyInjection; + +using Remora.Rest.Json; + +namespace DSharpPlus.Core.Models.Extensions; + +/// +/// Provides extensions on IServiceCollection to register our JSON serialization of Discord models. +/// +public static class ServiceCollectionExtensions +{ + const ulong DiscordEpoch = 1420070400000ul; + + /// + /// Registers converters for Discord's API models. + /// + /// The service collection to register into. + /// The name under which the serialization options should be accessible. + /// The same service collection for chaining. + public static IServiceCollection RegisterDiscordModelSerialization + ( + this IServiceCollection services, + string? name = "DSharpPlus" + ) + { + services.Configure + ( + name, + options => + { + options.PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower; + + options.Converters.Add(new AuditLogChangeConverter()); + options.Converters.Add(new AutoModerationActionConverter()); + options.Converters.Add(new DiscordPermissionConverter()); + options.Converters.Add(new MessageComponentConverter()); + + options.RegisterApplicationCommands(); + options.RegisterApplications(); + options.RegisterAuditLogs(); + options.RegisterAutoModeration(); + options.RegisterChannels(); + options.RegisterEmojis(); + options.RegisterGuilds(); + options.RegisterGuildTemplates(); + options.RegisterInteractions(); + options.RegisterInvites(); + options.RegisterMessageComponents(); + options.RegisterRoleConnections(); + options.RegisterScheduledEvents(); + options.RegisterStageInstances(); + options.RegisterStickers(); + options.RegisterTeams(); + options.RegisterUsers(); + options.RegisterVoice(); + options.RegisterWebhooks(); + + options.Converters.Insert(0, new SnowflakeConverter(DiscordEpoch)); + } + ); + + return services; + } +} From c6acf29fd130b24d239b0d17ecc154f1be7f0d90 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Fri, 18 Aug 2023 16:07:40 +0200 Subject: [PATCH 090/323] remove System.Drawing.Common --- Directory.Packages.props | 1 - .../Tools.Generators.GenerateConcreteObjects.csproj | 1 - 2 files changed, 2 deletions(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index c19df031cc..19b5dbfd7a 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -11,7 +11,6 @@ - diff --git a/tools/generators/Tools.Generators.GenerateConcreteObjects/Tools.Generators.GenerateConcreteObjects.csproj b/tools/generators/Tools.Generators.GenerateConcreteObjects/Tools.Generators.GenerateConcreteObjects.csproj index 65291d465f..79798b83ac 100644 --- a/tools/generators/Tools.Generators.GenerateConcreteObjects/Tools.Generators.GenerateConcreteObjects.csproj +++ b/tools/generators/Tools.Generators.GenerateConcreteObjects/Tools.Generators.GenerateConcreteObjects.csproj @@ -8,7 +8,6 @@ - From 4a918fbbfd08ff8ee082ad12c3e535098567107c Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Fri, 18 Aug 2023 16:10:58 +0200 Subject: [PATCH 091/323] remove DictionarySlim from DSharpPlus in favor of Bundles --- DSharpPlus.sln | 7 - .../Collections/DictionarySlim.cs | 559 ------------------ .../Collections/DictionarySlimDebugView.cs | 47 -- .../Collections/ThrowHelper.cs | 41 -- .../DictionarySlimGenericJsonConverter.cs | 77 --- ...tionarySlimIParsableTValueJsonConverter.cs | 82 --- .../DictionarySlimJsonConverterFactory.cs | 106 ---- ...DictionarySlimStringStringJsonConverter.cs | 75 --- ...DictionarySlimStringTValueJsonConverter.cs | 78 --- .../Converters/DictionarySlimCLR.Floats.cs | 54 -- .../Converters/DictionarySlimCLR.General.cs | 142 ----- .../Converters/DictionarySlimCLR.Guid.cs | 54 -- .../Converters/DictionarySlimCLR.Integers.cs | 90 --- .../Converters/DictionarySlimCLR.String.cs | 53 -- .../Converters/DictionarySlimStringString.cs | 60 -- .../DSharpPlus.Shared.Tests.csproj | 30 - 16 files changed, 1555 deletions(-) delete mode 100644 src/core/DSharpPlus.Shared/Collections/DictionarySlim.cs delete mode 100644 src/core/DSharpPlus.Shared/Collections/DictionarySlimDebugView.cs delete mode 100644 src/core/DSharpPlus.Shared/Collections/ThrowHelper.cs delete mode 100644 src/core/DSharpPlus.Shared/Converters/DictionarySlimGenericJsonConverter.cs delete mode 100644 src/core/DSharpPlus.Shared/Converters/DictionarySlimIParsableTValueJsonConverter.cs delete mode 100644 src/core/DSharpPlus.Shared/Converters/DictionarySlimJsonConverterFactory.cs delete mode 100644 src/core/DSharpPlus.Shared/Converters/DictionarySlimStringStringJsonConverter.cs delete mode 100644 src/core/DSharpPlus.Shared/Converters/DictionarySlimStringTValueJsonConverter.cs delete mode 100644 tests/core/DSharpPlus.Shared.Tests/Converters/DictionarySlimCLR.Floats.cs delete mode 100644 tests/core/DSharpPlus.Shared.Tests/Converters/DictionarySlimCLR.General.cs delete mode 100644 tests/core/DSharpPlus.Shared.Tests/Converters/DictionarySlimCLR.Guid.cs delete mode 100644 tests/core/DSharpPlus.Shared.Tests/Converters/DictionarySlimCLR.Integers.cs delete mode 100644 tests/core/DSharpPlus.Shared.Tests/Converters/DictionarySlimCLR.String.cs delete mode 100644 tests/core/DSharpPlus.Shared.Tests/Converters/DictionarySlimStringString.cs delete mode 100644 tests/core/DSharpPlus.Shared.Tests/DSharpPlus.Shared.Tests.csproj diff --git a/DSharpPlus.sln b/DSharpPlus.sln index 2ff9e4c19f..b87a35f862 100644 --- a/DSharpPlus.sln +++ b/DSharpPlus.sln @@ -24,8 +24,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{EAE89CF5 EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Core", "Core", "{21927A64-7345-4D90-9EE2-7FA4B1973AAC}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DSharpPlus.Shared.Tests", "tests\core\DSharpPlus.Shared.Tests\DSharpPlus.Shared.Tests.csproj", "{84A68CF6-8FCF-4813-8BA8-9649A553F4C4}" -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Generators", "Generators", "{5FBB4590-56B0-453B-A87B-08A17C599B5C}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DSharpPlus.SourceGenerators.Common", "gen\common\DSharpPlus.SourceGenerators.Common.csproj", "{98D2C52C-E3BA-4564-919C-750775B7BA9C}" @@ -56,10 +54,6 @@ Global {9199CD3F-AD85-453E-9BA5-2B4ACC2576EC}.Debug|Any CPU.Build.0 = Debug|Any CPU {9199CD3F-AD85-453E-9BA5-2B4ACC2576EC}.Release|Any CPU.ActiveCfg = Release|Any CPU {9199CD3F-AD85-453E-9BA5-2B4ACC2576EC}.Release|Any CPU.Build.0 = Release|Any CPU - {84A68CF6-8FCF-4813-8BA8-9649A553F4C4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {84A68CF6-8FCF-4813-8BA8-9649A553F4C4}.Debug|Any CPU.Build.0 = Debug|Any CPU - {84A68CF6-8FCF-4813-8BA8-9649A553F4C4}.Release|Any CPU.ActiveCfg = Release|Any CPU - {84A68CF6-8FCF-4813-8BA8-9649A553F4C4}.Release|Any CPU.Build.0 = Release|Any CPU {98D2C52C-E3BA-4564-919C-750775B7BA9C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {98D2C52C-E3BA-4564-919C-750775B7BA9C}.Debug|Any CPU.Build.0 = Debug|Any CPU {98D2C52C-E3BA-4564-919C-750775B7BA9C}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -75,7 +69,6 @@ Global {DF07A6C6-4689-44DC-80B0-479CA7C6AAF6} = {EAC2F7ED-0965-4607-ACE0-829885A612C5} {9199CD3F-AD85-453E-9BA5-2B4ACC2576EC} = {EAC2F7ED-0965-4607-ACE0-829885A612C5} {21927A64-7345-4D90-9EE2-7FA4B1973AAC} = {EAE89CF5-AA91-4A22-9949-A46FAE1BF0D0} - {84A68CF6-8FCF-4813-8BA8-9649A553F4C4} = {21927A64-7345-4D90-9EE2-7FA4B1973AAC} {98D2C52C-E3BA-4564-919C-750775B7BA9C} = {5FBB4590-56B0-453B-A87B-08A17C599B5C} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution diff --git a/src/core/DSharpPlus.Shared/Collections/DictionarySlim.cs b/src/core/DSharpPlus.Shared/Collections/DictionarySlim.cs deleted file mode 100644 index 2434c4ebdf..0000000000 --- a/src/core/DSharpPlus.Shared/Collections/DictionarySlim.cs +++ /dev/null @@ -1,559 +0,0 @@ -#pragma warning disable IDE0073 // don't insert our license header here - -// This source file is loosely adapted after the following dotnet/corefxlab file, and is therefore licensed -// under the MIT License: -// https://github.com/dotnet/corefxlab/blob/archive/src/Microsoft.Experimental.Collections/Microsoft/Collections/Extensions/DictionarySlim.cs -// -// Copyright (c) .NET Foundation and Contributors -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. - -using System; -using System.Collections; -using System.Collections.Generic; -using System.Diagnostics; -#if !NETSTANDARD -using System.Diagnostics.CodeAnalysis; -#endif -using System.Runtime.CompilerServices; - -namespace DSharpPlus.Collections; - -/// -/// A lightweight dictionary with three principal differences compared to . -///

-/// 1. It is possible to get or add in a single lookup. For values that are value types, this also -/// saves a copy of the value.
-/// 2. It assumes it is cheap to equate values.
-/// 3. It assumes the keys implement and that they are cheap and sufficient. -///
-/// -/// This avoids having to do separate lookups for get-or-add scenarios; it can save space by not -/// storing hash codes, save time by skipping potentially expensive hash code calculations for certain types -/// of common keys, as well as avoid storing a comparer and avoid the - likely virtual - call to a comparer. -/// Additionally, this class is a sealed class, making it trivial to devirtualize calls to it. -/// -[DebuggerDisplay("Count = {Count}")] -[DebuggerTypeProxy(typeof(DictionarySlimDebugView<,>))] -#if !NETSTANDARD -[SkipLocalsInit] -#endif -public sealed class DictionarySlim : IReadOnlyCollection> - where TKey : IEquatable -{ - // using this static initialization allows us to initialize further dictionaries without - // any initial allocations. instead, we allocate once per monomorphized generic instantiation, - // plus one time for the canonicalized reference type generic instantiation - // DSharpPlus.Collections.DictionarySlim. - // The first addition will cause a resize, replacing this with a real array. - private static readonly DictionaryEntry[] initialEntries = new DictionaryEntry[1]; - - private static readonly int[] sizeOneIntArray = new int[1]; - - // zero-based index into entries towards the head of the free chain, -1 means empty - private int freeList = -1; - - // one-based index into entries, 0 means empty. - private int[] buckets; - private DictionaryEntry[] entries; - - /// - public int Count { get; private set; } - - /// - /// Represents an entry to this dictionary, replacing KeyValuePairs. - /// - [DebuggerDisplay("({key}, {value})->{next}")] - private struct DictionaryEntry - { - public TKey key; - public TValue value; - - // zero-based index of the next entry in this chain; -1 signifies the end of the chain. - // this also encodes whether this entry is part of the free list by changing the sign and - // subtracting 3; so, -2 means the end of the free list, -3 means index 0 on the free list, - // -4 means index 1 on the free list et cetera - public int next; - } - - /// - /// Constructs a new slim dictionary with default capacity. - /// - public DictionarySlim() - { - this.buckets = sizeOneIntArray; - this.entries = initialEntries; - } - - /// - /// Constructs a new dictionary with at least the specified capacity for entries. - /// - /// - /// This constructor will round the capacity up to the nearest power of two. - /// - /// - /// Thrown if capacity was less than 0. - /// - public DictionarySlim - ( - int capacity - ) - { - if (capacity < 0) - { - throw new ArgumentOutOfRangeException - ( - nameof(capacity), - "The initial capacity for this dictionary was too small." - ); - } - - // ensure a capacity of at least two; because 1 would mean the dummy array. - if (capacity < 2) - { - capacity = 2; - } - - // round up to the nearest power of two - int roundedCapacity = 2; - - while (roundedCapacity < capacity) - { - roundedCapacity <<= 1; - } - - this.buckets = new int[roundedCapacity]; - this.entries = new DictionaryEntry[roundedCapacity]; - } - - /// - /// Clears this dictionary, invalidating any active references and enumerators. - /// - public void Clear() - { - this.Count = 0; - this.freeList = -1; - this.buckets = sizeOneIntArray; - this.entries = initialEntries; - } - - /// - /// Looks for the specified key in the dictionary, returning whether it exists. - /// - public bool ContainsKey - ( - TKey key - ) - { -#if !NETSTANDARD - ArgumentNullException.ThrowIfNull(key); -#else - if (key is null) - { - throw new ArgumentNullException("The supplied key was null."); - } -#endif - DictionaryEntry[] entries = this.entries; - int collisions = 0; - - for - ( - int i = buckets[key.GetHashCode() & (buckets.Length - 1)] - 1; - (uint)i < (uint)entries.Length; - i = entries[i].next - ) - { - if (key.Equals(entries[i].key)) - { - return true; - } - - if(collisions == entries.Length) - { - ThrowHelper.ThrowConcurrentOperationsNotSupported(); - } - - collisions++; - } - - return false; - } - - /// - /// Gets the value if one is present for the given key. - /// - /// The key to look for. - /// The value if one was found, otherwise default(TValue). - /// Whether the key was found. - public bool TryGetValue - ( - TKey key, - -#if !NETSTANDARD - [MaybeNullWhen(false)] -#endif - out TValue value - ) - { -#if !NETSTANDARD - ArgumentNullException.ThrowIfNull(key); -#else - if (key is null) - { - throw new ArgumentNullException("The supplied key was null."); - } -#endif - - DictionaryEntry[] entries = this.entries; - int collisions = 0; - - for - ( - int i = buckets[key.GetHashCode() & (buckets.Length - 1)] - 1; - (uint)i < (uint)entries.Length; - i = entries[i].next - ) - { - if (key.Equals(entries[i].key)) - { - value = entries[i].value; - return true; - } - - if (collisions == entries.Length) - { - ThrowHelper.ThrowConcurrentOperationsNotSupported(); - } - - collisions++; - } - - value = default!; - return false; - } - - public ref TValue this[TKey key] - { - get - { -#if !NETSTANDARD - ArgumentNullException.ThrowIfNull(key); -#else - if (key is null) - { - throw new ArgumentNullException("The supplied key was null."); - } -#endif - - DictionaryEntry[] entries = this.entries; - int collisions = 0; - - for - ( - int i = buckets[key.GetHashCode() & (buckets.Length - 1)] - 1; - (uint)i < (uint)entries.Length; - i = entries[i].next - ) - { - if (key.Equals(entries[i].key)) - { - return ref entries[i].value; - } - - if (collisions == entries.Length) - { - ThrowHelper.ThrowConcurrentOperationsNotSupported(); - } - - collisions++; - } - - ThrowHelper.ThrowValueNotFound(); - - // this is unreachable, but roslyn disagrees; so we need to have a dummy return - // thanks to netstandard being netstandard, this can't become Unsafe.NullRef(); - unsafe - { -#pragma warning disable CS8500 - return ref *(TValue*)null; -#pragma warning restore CS8500 - } - } - } - - /// - /// Removes the entry with the specified key, if one was present. - /// - /// true if the key was present and an entry was removed. - public bool Remove - ( - TKey key - ) - { -#if !NETSTANDARD - ArgumentNullException.ThrowIfNull(key); -#else - if (key is null) - { - throw new ArgumentNullException("The supplied key was null."); - } -#endif - - DictionaryEntry[] entries = this.entries; - int bucketIndex = key.GetHashCode() & (buckets.Length - 1); - int entryIndex = buckets[bucketIndex] - 1; - - int lastIndex = -1; - int collisions = 0; - - while (entryIndex != -1) - { - DictionaryEntry candidate = entries[entryIndex]; - if (candidate.key.Equals(key)) - { - if (lastIndex != -1) - { - // fix the preceding element in the chain to point to the correct next element, if any - entries[lastIndex].next = candidate.next; - } - else - { - // fix the bucket to the new head, if any - buckets[bucketIndex] = candidate.next + 1; - } - - entries[entryIndex] = default; - - // this is the new head of the free list - entries[entryIndex].next = -3 - freeList; - freeList = entryIndex; - - Count--; - return true; - } - - lastIndex = entryIndex; - entryIndex = candidate.next; - - if (collisions == entries.Length) - { - // The chain of entries forms a loop; which means a concurrent update has happened. - // Break out of the loop and throw, rather than looping forever. - ThrowHelper.ThrowConcurrentOperationsNotSupported(); - } - - collisions++; - } - - return false; - } - - // Not safe for concurrent _reads_ (at least, if either of them add) - // For concurrent reads, prefer TryGetValue(key, out value) - /// - /// Gets the value for the specified key, or, if the key is not present, - /// adds an entry and returns the value by ref. This makes it possible to - /// add or update a value in a single look up operation. - /// - /// The key to look for. - /// A reference to the new or existing value. - public ref TValue GetOrAddValueRef(TKey key) - { -#if !NETSTANDARD - ArgumentNullException.ThrowIfNull(key); -#else - if (key is null) - { - throw new ArgumentNullException("The supplied key was null."); - } -#endif - - DictionaryEntry[] entries = this.entries; - - int collisions = 0; - int bucketIndex = key.GetHashCode() & (this.buckets.Length - 1); - - for - ( - int i = this.buckets[bucketIndex] - 1; - (uint)i < (uint)entries.Length; - i = entries[i].next - ) - { - if (key.Equals(entries[i].key)) - { - return ref entries[i].value; - } - - if (collisions == entries.Length) - { - // The chain of entries forms a loop; which means a concurrent update has happened. - // Break out of the loop and throw, rather than looping forever. - ThrowHelper.ThrowConcurrentOperationsNotSupported(); - } - - collisions++; - } - - return ref AddKey(key, bucketIndex); - } - - [MethodImpl(MethodImplOptions.NoInlining)] - private ref TValue AddKey(TKey key, int bucketIndex) - { - DictionaryEntry[] entries = this.entries; - - int entryIndex; - - if (this.freeList != -1) - { - entryIndex = this.freeList; - this.freeList = -3 - entries[this.freeList].next; - } - else - { - if (this.Count == entries.Length || entries.Length == 1) - { - entries = this.Resize(); - bucketIndex = key.GetHashCode() & (this.buckets.Length - 1); - // entry indexes were not changed by Resize - } - - entryIndex = this.Count; - } - - entries[entryIndex].key = key; - entries[entryIndex].next = this.buckets[bucketIndex] - 1; - this.buckets[bucketIndex] = entryIndex + 1; - - this.Count++; - - return ref entries[entryIndex].value; - } - - private DictionaryEntry[] Resize() - { - // We only copy _count, so if it's longer we will miss some - // the comparison with 1 is made to catch the initial array - Debug.Assert(this.entries.Length == this.Count || this.entries.Length == 1); - - int count = this.Count; - - // for net8.0 targets we could consider implementing this for different resize strategies - // a linearly increasing slim dictionary would be useful. - int newSize = this.entries.Length * 2; - - if ((uint)newSize > int.MaxValue) - { - ThrowHelper.ThrowCapacityIntMaxValueExceeded(); - } - - DictionaryEntry[] entries = new DictionaryEntry[newSize]; - Array.Copy(this.entries, 0, entries, 0, count); - - int[] newBuckets = new int[entries.Length]; - - while (count-- > 0) - { - int bucketIndex = entries[count].key.GetHashCode() & (newBuckets.Length - 1); - entries[count].next = newBuckets[bucketIndex] - 1; - newBuckets[bucketIndex] = count + 1; - } - - this.buckets = newBuckets; - this.entries = entries; - - return entries; - } - - IEnumerator> IEnumerable>.GetEnumerator() - => new Enumerator(this); - - IEnumerator IEnumerable.GetEnumerator() - => new Enumerator(this); - - // avoid boxing enumerators if not necessary - public Enumerator GetEnumerator() => new(this); - - /// - /// The enumerator struct for this dictionary type. - /// - public struct Enumerator : IEnumerator> - { - private readonly DictionarySlim dictionary; - private int index; - private int count; - private KeyValuePair current; - - internal Enumerator - ( - DictionarySlim dictionary - ) - { - this.dictionary = dictionary; - this.index = 0; - this.count = dictionary.Count; - this.current = default; - } - - /// - public bool MoveNext() - { - if (this.count == 0) - { - this.current = default; - return false; - } - - this.count--; - - while (this.dictionary.entries[this.index].next < -1) - { - this.index++; - } - - this.current = new KeyValuePair - ( - this.dictionary.entries[this.index].key, - this.dictionary.entries[this.index++].value - ); - - return true; - } - - /// - /// Get current value - /// - public readonly KeyValuePair Current => this.current; - - readonly object IEnumerator.Current => this.current; - - void IEnumerator.Reset() - { - this.index = 0; - this.count = this.dictionary.Count; - this.current = default; - } - - /// - /// Dispose the enumerator - /// - public readonly void Dispose() { } - } -} diff --git a/src/core/DSharpPlus.Shared/Collections/DictionarySlimDebugView.cs b/src/core/DSharpPlus.Shared/Collections/DictionarySlimDebugView.cs deleted file mode 100644 index 47ddfe4656..0000000000 --- a/src/core/DSharpPlus.Shared/Collections/DictionarySlimDebugView.cs +++ /dev/null @@ -1,47 +0,0 @@ -#pragma warning disable IDE0073 - -// This source file is loosely adapted after the following dotnet/corefxlab file, and is therefore licensed -// under the MIT License: -// https://github.com/dotnet/corefxlab/blob/archive/src/Microsoft.Experimental.Collections/Microsoft/Collections/Extensions/DictionarySlim.cs -// -// Copyright (c) .NET Foundation and Contributors -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. - -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Linq; - -namespace DSharpPlus.Collections; - -/// -/// The debugger view for -/// -internal sealed class DictionarySlimDebugView -( - DictionarySlim dictionary -) - where K : IEquatable -{ -#pragma warning disable CA1822 - [DebuggerBrowsable(DebuggerBrowsableState.RootHidden)] - public KeyValuePair[] Items => dictionary.ToArray(); -#pragma warning restore CA1822 -} diff --git a/src/core/DSharpPlus.Shared/Collections/ThrowHelper.cs b/src/core/DSharpPlus.Shared/Collections/ThrowHelper.cs deleted file mode 100644 index e496b6d076..0000000000 --- a/src/core/DSharpPlus.Shared/Collections/ThrowHelper.cs +++ /dev/null @@ -1,41 +0,0 @@ -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -using System; -using System.Diagnostics; -#if !NETSTANDARD -using System.Diagnostics.CodeAnalysis; -#endif - -namespace DSharpPlus.Collections; - -/// -/// Contains utilities for throwing exceptions out of hot code paths. -/// -internal static class ThrowHelper -{ - [DebuggerHidden] -#if !NETSTANDARD - [DoesNotReturn] - [StackTraceHidden] -#endif - internal static void ThrowConcurrentOperationsNotSupported() - => throw new InvalidOperationException("Concurrent modifications to this collection type are not supported."); - - [DebuggerHidden] -#if !NETSTANDARD - [DoesNotReturn] - [StackTraceHidden] -#endif - internal static void ThrowCapacityIntMaxValueExceeded() - => throw new InvalidOperationException($"This type's maximum capacity of {int.MaxValue} was exceeded."); - - [DebuggerHidden] -#if !NETSTANDARD - [DoesNotReturn] - [StackTraceHidden] -#endif - internal static void ThrowValueNotFound() - => throw new ArgumentException("There was no value corresponding to the given key."); -} diff --git a/src/core/DSharpPlus.Shared/Converters/DictionarySlimGenericJsonConverter.cs b/src/core/DSharpPlus.Shared/Converters/DictionarySlimGenericJsonConverter.cs deleted file mode 100644 index b6d5845838..0000000000 --- a/src/core/DSharpPlus.Shared/Converters/DictionarySlimGenericJsonConverter.cs +++ /dev/null @@ -1,77 +0,0 @@ -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -#if !NETSTANDARD - -using System; -using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; -using System.Text.Json; -using System.Text.Json.Serialization; - -using DSharpPlus.Collections; - -namespace DSharpPlus.Converters; - -[RequiresUnreferencedCode("JSON serialization and deserialization might require types that cannot be statically analyzed.")] -[RequiresDynamicCode("JSON serialization and deserialization might need runtime code generation. Use the source generator instead.")] -public class DictionarySlimGenericJsonConverter : JsonConverter> - where TKey : IEquatable -{ - /// - public override DictionarySlim? Read - ( - ref Utf8JsonReader reader, - Type typeToConvert, - JsonSerializerOptions options - ) - { - if (reader.TokenType != JsonTokenType.StartObject) - { - throw new JsonException("The provided dictionary start token was not an object."); - } - - DictionarySlim result = new(); - - while (reader.Read()) - { - if (reader.TokenType == JsonTokenType.EndObject) - { - return result; - } - - string propertyNameRaw = reader.GetString()!; - TKey propertyName = JsonSerializer.Deserialize(propertyNameRaw)!; - - reader.Read(); - - ref TValue propertyValue = ref result.GetOrAddValueRef(propertyName); - - propertyValue = JsonSerializer.Deserialize(ref reader, options)!; - } - - return result; - } - - /// - public override void Write - ( - Utf8JsonWriter writer, - DictionarySlim value, - JsonSerializerOptions options - ) - { - writer.WriteStartObject(); - - foreach (KeyValuePair element in value) - { - writer.WritePropertyName(element.Key.ToString()!); - writer.WriteRawValue(JsonSerializer.SerializeToUtf8Bytes(element.Value, options)); - } - - writer.WriteEndObject(); - } -} - -#endif diff --git a/src/core/DSharpPlus.Shared/Converters/DictionarySlimIParsableTValueJsonConverter.cs b/src/core/DSharpPlus.Shared/Converters/DictionarySlimIParsableTValueJsonConverter.cs deleted file mode 100644 index 4026b92e06..0000000000 --- a/src/core/DSharpPlus.Shared/Converters/DictionarySlimIParsableTValueJsonConverter.cs +++ /dev/null @@ -1,82 +0,0 @@ -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -using System; -using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; -using System.Text.Json; -using System.Text.Json.Serialization; - -using DSharpPlus.Collections; - -namespace DSharpPlus.Converters; - -/// -/// Provides JSON conversion logic for with -/// keys. It is assumed that there is a correct roundtrip between and -/// . -/// -[RequiresUnreferencedCode("JSON serialization and deserialization might require types that cannot be statically analyzed.")] -[RequiresDynamicCode("JSON serialization and deserialization might need runtime code generation. Use the source generator instead.")] -public class DictionarySlimIParsableTValueJsonConverter : JsonConverter> - where TKey : IEquatable, IParsable -{ - /// - public override DictionarySlim? Read - ( - ref Utf8JsonReader reader, - Type typeToConvert, - JsonSerializerOptions options - ) - { - if (reader.TokenType != JsonTokenType.StartObject) - { - throw new JsonException("The provided dictionary start token was not an object."); - } - - DictionarySlim result = new(); - - while (reader.Read()) - { - if (reader.TokenType == JsonTokenType.EndObject) - { - return result; - } - - string propertyNameRaw = reader.GetString()!; - - if(!TKey.TryParse(propertyNameRaw, null, out TKey? propertyName)) - { - throw new ArgumentException($"The key {propertyNameRaw} could not be parsed as {typeof(TKey)}."); - } - - reader.Read(); - - ref TValue propertyValue = ref result.GetOrAddValueRef(propertyName!); - - propertyValue = JsonSerializer.Deserialize(ref reader, options)!; - } - - return result; - } - - /// - public override void Write - ( - Utf8JsonWriter writer, - DictionarySlim value, - JsonSerializerOptions options - ) - { - writer.WriteStartObject(); - - foreach (KeyValuePair element in value) - { - writer.WritePropertyName(element.Key.ToString()!); - writer.WriteRawValue(JsonSerializer.SerializeToUtf8Bytes(element.Value, options)); - } - - writer.WriteEndObject(); - } -} diff --git a/src/core/DSharpPlus.Shared/Converters/DictionarySlimJsonConverterFactory.cs b/src/core/DSharpPlus.Shared/Converters/DictionarySlimJsonConverterFactory.cs deleted file mode 100644 index ecfe68ea64..0000000000 --- a/src/core/DSharpPlus.Shared/Converters/DictionarySlimJsonConverterFactory.cs +++ /dev/null @@ -1,106 +0,0 @@ -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -#if !NETSTANDARD - -using System; -using System.Diagnostics.CodeAnalysis; -using System.Linq; -using System.Text.Json; -using System.Text.Json.Serialization; - -using DSharpPlus.Collections; - -namespace DSharpPlus.Converters; - -/// -/// Provides JSON serialization with the appropriate converters for slim dictionaries. -/// -[RequiresDynamicCode("Monomorphized generic instantiations of DictionarySlim might have been trimmed.")] -[RequiresUnreferencedCode("JSON serialization and deserialization might require static analysis of trimmed types.")] -public class DictionarySlimJsonConverterFactory : JsonConverterFactory -{ - /// - public override bool CanConvert - ( - Type typeToConvert - ) - { - if (!typeToConvert.IsGenericType) - { - return false; - } - - if (typeToConvert.GetGenericTypeDefinition() != typeof(DictionarySlim<,>)) - { - return false; - } - - Type[] generics = typeToConvert.GetGenericArguments(); - - return VerifyKeyTypeValidity(generics[0]); - } - - /// - public override JsonConverter? CreateConverter - ( - Type typeToConvert, - JsonSerializerOptions options - ) - { - Type[] generics = typeToConvert.GetGenericArguments(); - - // we can add more specialized converters here for more AOT-designed, specialized converters here, - // though only if they add new key types or specialize TValue to a meaningful degree. specializing - // on TKey where TKey : IParsable makes little sense, for the CLR implementation. - if (generics[0] == typeof(string) && generics[1] == typeof(string)) - { - return new DictionarySlimStringStringJsonConverter(); - } - else if (generics[0] == typeof(string)) - { - Type converter = typeof(DictionarySlimStringTValueJsonConverter<>) - .MakeGenericType(generics[1]); - - return (JsonConverter?)Activator.CreateInstance(converter); - } - else if - ( - generics[0].GetInterfaces() - .Any - ( - candidate => candidate.IsGenericType - && candidate.GetGenericTypeDefinition() == typeof(IParsable<>) - ) - ) - { - Type converter = typeof(DictionarySlimIParsableTValueJsonConverter<,>) - .MakeGenericType(generics); - - return (JsonConverter?)Activator.CreateInstance(converter); - } - else - { - Type converter = typeof(DictionarySlimGenericJsonConverter<,>) - .MakeGenericType(generics); - - return (JsonConverter?)Activator.CreateInstance(converter); - } - } - - private static bool VerifyKeyTypeValidity - ( - Type type - ) - { - return type == typeof(string) || type.GetInterfaces() - .Any - ( - candidate => candidate.IsGenericType - && candidate.GetGenericTypeDefinition() == typeof(IParsable<>) - ); - } -} - -#endif diff --git a/src/core/DSharpPlus.Shared/Converters/DictionarySlimStringStringJsonConverter.cs b/src/core/DSharpPlus.Shared/Converters/DictionarySlimStringStringJsonConverter.cs deleted file mode 100644 index 73b7f0bb8d..0000000000 --- a/src/core/DSharpPlus.Shared/Converters/DictionarySlimStringStringJsonConverter.cs +++ /dev/null @@ -1,75 +0,0 @@ -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -#if !NETSTANDARD - -using System; -using System.Collections.Generic; -using System.Text.Json; -using System.Text.Json.Serialization; - -using DSharpPlus.Collections; - -namespace DSharpPlus.Converters; - -/// -/// Represents a specialized converter for string-to-string slim dictionaries. This converter is AOT-friendly. -/// -public class DictionarySlimStringStringJsonConverter : JsonConverter> -{ - /// - public override DictionarySlim? Read - ( - ref Utf8JsonReader reader, - Type typeToConvert, - JsonSerializerOptions options - ) - { - if (reader.TokenType != JsonTokenType.StartObject) - { - throw new JsonException("The provided dictionary start token was not an object."); - } - - DictionarySlim result = new(); - - while (reader.Read()) - { - if (reader.TokenType == JsonTokenType.EndObject) - { - return result; - } - - string propertyName = reader.GetString()!; - - reader.Read(); - - ref string propertyValue = ref result.GetOrAddValueRef(propertyName); - - propertyValue = reader.GetString()!; - } - - return result; - } - - /// - public override void Write - ( - Utf8JsonWriter writer, - DictionarySlim value, - JsonSerializerOptions options - ) - { - writer.WriteStartObject(); - - foreach (KeyValuePair element in value) - { - writer.WritePropertyName(element.Key); - writer.WriteStringValue(element.Value); - } - - writer.WriteEndObject(); - } -} - -#endif diff --git a/src/core/DSharpPlus.Shared/Converters/DictionarySlimStringTValueJsonConverter.cs b/src/core/DSharpPlus.Shared/Converters/DictionarySlimStringTValueJsonConverter.cs deleted file mode 100644 index da0731228c..0000000000 --- a/src/core/DSharpPlus.Shared/Converters/DictionarySlimStringTValueJsonConverter.cs +++ /dev/null @@ -1,78 +0,0 @@ -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -#if !NETSTANDARD - -using System; -using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; -using System.Text.Json; -using System.Text.Json.Serialization; - -using DSharpPlus.Collections; - -namespace DSharpPlus.Converters; - -/// -/// Provides JSON conversion logic for with keys. -/// -[RequiresUnreferencedCode("JSON serialization and deserialization might require types that cannot be statically analyzed.")] -[RequiresDynamicCode("JSON serialization and deserialization might need runtime code generation. Use the source generator instead.")] -public class DictionarySlimStringTValueJsonConverter : JsonConverter> -{ - /// - public override DictionarySlim? Read - ( - ref Utf8JsonReader reader, - Type typeToConvert, - JsonSerializerOptions options - ) - { - if (reader.TokenType != JsonTokenType.StartObject) - { - throw new JsonException("The provided dictionary start token was not an object."); - } - - DictionarySlim result = new(); - - while (reader.Read()) - { - if (reader.TokenType == JsonTokenType.EndObject) - { - return result; - } - - string propertyName = reader.GetString()!; - - reader.Read(); - - ref TValue propertyValue = ref result.GetOrAddValueRef(propertyName); - - propertyValue = JsonSerializer.Deserialize(ref reader, options)!; - } - - return result; - } - - /// - public override void Write - ( - Utf8JsonWriter writer, - DictionarySlim value, - JsonSerializerOptions options - ) - { - writer.WriteStartObject(); - - foreach (KeyValuePair element in value) - { - writer.WritePropertyName(element.Key); - writer.WriteRawValue(JsonSerializer.SerializeToUtf8Bytes(element.Value, options)); - } - - writer.WriteEndObject(); - } -} - -#endif diff --git a/tests/core/DSharpPlus.Shared.Tests/Converters/DictionarySlimCLR.Floats.cs b/tests/core/DSharpPlus.Shared.Tests/Converters/DictionarySlimCLR.Floats.cs deleted file mode 100644 index 81ccdb2763..0000000000 --- a/tests/core/DSharpPlus.Shared.Tests/Converters/DictionarySlimCLR.Floats.cs +++ /dev/null @@ -1,54 +0,0 @@ -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -using System; -using System.Text.Json; - -using DSharpPlus.Collections; -using DSharpPlus.Converters; - -using Xunit; - -namespace DSharpPlus.Shared.Tests.Converters; - -// here we deal with whether floating-point keys, positive and negative, are handled correctly -public partial class DictionarySlimCLR -{ - [Fact] - public void Serialize_Float() - { - JsonSerializerOptions options = new(); - options.Converters.Add(new DictionarySlimJsonConverterFactory()); - - DictionarySlim dict = new(); - ref int value = ref dict.GetOrAddValueRef((Half)(-3.2)); - - value = 7; - - string serialized = JsonSerializer.Serialize(dict, options); - - Assert.Equal - ( - "{\"-3.2\":7}", - serialized - ); - } - - [Fact] - public void Deserialize_Float() - { - JsonSerializerOptions options = new(); - options.Converters.Add(new DictionarySlimJsonConverterFactory()); - - string serialized = "{\"11.1\":\"test\"}"; - - DictionarySlim dict = JsonSerializer.Deserialize> - ( - serialized, - options - )!; - - Assert.Equal("test", dict[11.1f]); - } -} diff --git a/tests/core/DSharpPlus.Shared.Tests/Converters/DictionarySlimCLR.General.cs b/tests/core/DSharpPlus.Shared.Tests/Converters/DictionarySlimCLR.General.cs deleted file mode 100644 index 726f8be6b5..0000000000 --- a/tests/core/DSharpPlus.Shared.Tests/Converters/DictionarySlimCLR.General.cs +++ /dev/null @@ -1,142 +0,0 @@ -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -using System; -using System.Text.Json; - -using DSharpPlus.Collections; -using DSharpPlus.Converters; - -using Xunit; - -namespace DSharpPlus.Shared.Tests.Converters; - -/// -/// Contains generic tests for de/serialization. -/// -// in this file, we look at whether we correctly evaluate CanConvert -public partial class DictionarySlimCLR -{ - [Fact] - public void InvalidKeyType() - { - DictionarySlim invalid = new(); - - ref string value = ref invalid.GetOrAddValueRef - ( - new() - { - First = 7, - Second = 8 - } - ); - - value = "test"; - - try - { - JsonSerializerOptions options = new(); - options.Converters.Add(new DictionarySlimJsonConverterFactory()); - - string? serialized = JsonSerializer.Serialize(invalid, options); - - Assert.Null(serialized); - } - catch - { - Assert.True(true); - } - } - - [Fact] - public void ValidKeyType_String() - { - DictionarySlim valid = new(); - - ref string value = ref valid.GetOrAddValueRef - ( - "testificate" - ); - - value = "test"; - - try - { - JsonSerializerOptions options = new(); - options.Converters.Add(new DictionarySlimJsonConverterFactory()); - - string? serialized = JsonSerializer.Serialize(valid, options); - - Assert.NotNull(serialized); - } - catch - { - Assert.True(false); - } - } - - [Fact] - public void ValidKeyType_Guid() - { - DictionarySlim valid = new(); - - ref string value = ref valid.GetOrAddValueRef - ( - Guid.NewGuid() - ); - - value = "test"; - - try - { - JsonSerializerOptions options = new(); - options.Converters.Add(new DictionarySlimJsonConverterFactory()); - - string? serialized = JsonSerializer.Serialize(valid, options); - - Assert.NotNull(serialized); - } - catch - { - Assert.True(false); - } - } - - [Fact] - public void ValidKeyType_UInt128() - { - DictionarySlim valid = new(); - - ref string value = ref valid.GetOrAddValueRef - ( - (UInt128)ulong.MaxValue + 2 - ); - - value = "test"; - - try - { - JsonSerializerOptions options = new(); - options.Converters.Add(new DictionarySlimJsonConverterFactory()); - - string? serialized = JsonSerializer.Serialize(valid, options); - - Assert.NotNull(serialized); - } - catch - { - Assert.True(false); - } - } -} - -#pragma warning disable CA1067 // we don't care about implementing Object.Equals here, it's a test type -readonly file struct ComplexType : IEquatable -{ - public int First { get; init; } - public int Second { get; init; } - - public bool Equals(ComplexType other) - => this.First == other.First && this.Second == other.Second; -} diff --git a/tests/core/DSharpPlus.Shared.Tests/Converters/DictionarySlimCLR.Guid.cs b/tests/core/DSharpPlus.Shared.Tests/Converters/DictionarySlimCLR.Guid.cs deleted file mode 100644 index d8d7743b97..0000000000 --- a/tests/core/DSharpPlus.Shared.Tests/Converters/DictionarySlimCLR.Guid.cs +++ /dev/null @@ -1,54 +0,0 @@ -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -using System; -using System.Text.Json; - -using DSharpPlus.Collections; -using DSharpPlus.Converters; - -using Xunit; - -namespace DSharpPlus.Shared.Tests.Converters; - -// here we deal with whether guid keys are handled correctly -public partial class DictionarySlimCLR -{ - [Fact] - public void Serialize_Guid() - { - JsonSerializerOptions options = new(); - options.Converters.Add(new DictionarySlimJsonConverterFactory()); - - DictionarySlim dict = new(); - ref int value = ref dict.GetOrAddValueRef(Guid.Parse("20aa0594-1579-42b5-af9c-3295705239dd")); - - value = 7; - - string serialized = JsonSerializer.Serialize(dict, options); - - Assert.Equal - ( - "{\"20aa0594-1579-42b5-af9c-3295705239dd\":7}", - serialized - ); - } - - [Fact] - public void Deserialize_Guid() - { - JsonSerializerOptions options = new(); - options.Converters.Add(new DictionarySlimJsonConverterFactory()); - - string serialized = "{\"1107720a-fa7d-437d-8347-b96986589d6e\":\"test\"}"; - - DictionarySlim dict = JsonSerializer.Deserialize> - ( - serialized, - options - )!; - - Assert.Equal("test", dict[Guid.Parse("1107720a-fa7d-437d-8347-b96986589d6e")]); - } -} diff --git a/tests/core/DSharpPlus.Shared.Tests/Converters/DictionarySlimCLR.Integers.cs b/tests/core/DSharpPlus.Shared.Tests/Converters/DictionarySlimCLR.Integers.cs deleted file mode 100644 index 7b20c73b14..0000000000 --- a/tests/core/DSharpPlus.Shared.Tests/Converters/DictionarySlimCLR.Integers.cs +++ /dev/null @@ -1,90 +0,0 @@ -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -using System.Text.Json; - -using DSharpPlus.Collections; -using DSharpPlus.Converters; - -using Xunit; - -namespace DSharpPlus.Shared.Tests.Converters; - -// here we deal with whether integer keys, positive and negative, are handled correctly -public partial class DictionarySlimCLR -{ - [Fact] - public void Serialize_PositiveInteger() - { - JsonSerializerOptions options = new(); - options.Converters.Add(new DictionarySlimJsonConverterFactory()); - - DictionarySlim dict = new(); - ref int value = ref dict.GetOrAddValueRef(3); - - value = 7; - - string serialized = JsonSerializer.Serialize(dict, options); - - Assert.Equal - ( - "{\"3\":7}", - serialized - ); - } - - [Fact] - public void Deserialize_PositiveInteger() - { - JsonSerializerOptions options = new(); - options.Converters.Add(new DictionarySlimJsonConverterFactory()); - - string serialized = "{\"11\":\"test\"}"; - - DictionarySlim dict = JsonSerializer.Deserialize> - ( - serialized, - options - )!; - - Assert.Equal("test", dict[11]); - } - - [Fact] - public void Serialize_NegativeInteger() - { - JsonSerializerOptions options = new(); - options.Converters.Add(new DictionarySlimJsonConverterFactory()); - - DictionarySlim dict = new(); - ref int value = ref dict.GetOrAddValueRef(-9); - - value = 7; - - string serialized = JsonSerializer.Serialize(dict, options); - - Assert.Equal - ( - "{\"-9\":7}", - serialized - ); - } - - [Fact] - public void Deserialize_NegativeInteger() - { - JsonSerializerOptions options = new(); - options.Converters.Add(new DictionarySlimJsonConverterFactory()); - - string serialized = "{\"-11\":\"test\"}"; - - DictionarySlim dict = JsonSerializer.Deserialize> - ( - serialized, - options - )!; - - Assert.Equal("test", dict[-11]); - } -} diff --git a/tests/core/DSharpPlus.Shared.Tests/Converters/DictionarySlimCLR.String.cs b/tests/core/DSharpPlus.Shared.Tests/Converters/DictionarySlimCLR.String.cs deleted file mode 100644 index 6821062c05..0000000000 --- a/tests/core/DSharpPlus.Shared.Tests/Converters/DictionarySlimCLR.String.cs +++ /dev/null @@ -1,53 +0,0 @@ -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -using System.Text.Json; - -using DSharpPlus.Collections; -using DSharpPlus.Converters; - -using Xunit; - -namespace DSharpPlus.Shared.Tests.Converters; - -// here we deal with whether string keys are handled correctly -public partial class DictionarySlimCLR -{ - [Fact] - public void Serialize_String() - { - JsonSerializerOptions options = new(); - options.Converters.Add(new DictionarySlimJsonConverterFactory()); - - DictionarySlim dict = new(); - ref int value = ref dict.GetOrAddValueRef("test"); - - value = 7; - - string serialized = JsonSerializer.Serialize(dict, options); - - Assert.Equal - ( - "{\"test\":7}", - serialized - ); - } - - [Fact] - public void Deserialize_String() - { - JsonSerializerOptions options = new(); - options.Converters.Add(new DictionarySlimJsonConverterFactory()); - - string serialized = "{\"test\":8}"; - - DictionarySlim dict = JsonSerializer.Deserialize> - ( - serialized, - options - )!; - - Assert.Equal(8, dict["test"]); - } -} diff --git a/tests/core/DSharpPlus.Shared.Tests/Converters/DictionarySlimStringString.cs b/tests/core/DSharpPlus.Shared.Tests/Converters/DictionarySlimStringString.cs deleted file mode 100644 index 06c9f306f7..0000000000 --- a/tests/core/DSharpPlus.Shared.Tests/Converters/DictionarySlimStringString.cs +++ /dev/null @@ -1,60 +0,0 @@ -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -using System.Text.Json; - -using DSharpPlus.Collections; -using DSharpPlus.Converters; - -using Xunit; - -namespace DSharpPlus.Shared.Tests.Converters; - -/// -/// Tests serialization for string, string. -/// -public class DictionarySlimStringString -{ - [Fact] - public void TestDeserialization() - { - JsonSerializerOptions options = new(); - options.Converters.Add(new DictionarySlimStringStringJsonConverter()); - - string test = """ - { - "key": "value", - "other_key": "other_value" - } - """; - - DictionarySlim dict = JsonSerializer.Deserialize>(test, options)!; - - Assert.True(dict["other_key"] == "other_value"); - Assert.True(dict["key"] == "value"); - } - - [Fact] - public void TestSerialization() - { - JsonSerializerOptions options = new(); - options.Converters.Add(new DictionarySlimStringStringJsonConverter()); - - DictionarySlim dict = new(); - - ref string value = ref dict.GetOrAddValueRef("key"); - value = "value"; - - ref string otherValue = ref dict.GetOrAddValueRef("other_key"); - otherValue = "other_value"; - - string serialized = JsonSerializer.Serialize(dict, options); - - Assert.Equal - ( - "{\"key\":\"value\",\"other_key\":\"other_value\"}", - serialized - ); - } -} diff --git a/tests/core/DSharpPlus.Shared.Tests/DSharpPlus.Shared.Tests.csproj b/tests/core/DSharpPlus.Shared.Tests/DSharpPlus.Shared.Tests.csproj deleted file mode 100644 index 2b1cfee613..0000000000 --- a/tests/core/DSharpPlus.Shared.Tests/DSharpPlus.Shared.Tests.csproj +++ /dev/null @@ -1,30 +0,0 @@ - - - - net8.0 - enable - - false - true - - - - - - - - - runtime; build; native; contentfiles; analyzers; buildtransitive - all - - - runtime; build; native; contentfiles; analyzers; buildtransitive - all - - - - - - - - From 0c9c8ab039a1c1628bddf3b61deb797711e015bb Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Fri, 18 Aug 2023 16:32:52 +0200 Subject: [PATCH 092/323] correct audit log change value optionality --- .../AuditLogs/IAuditLogChange.cs | 6 +++-- .../AuditLogs/AuditLogChange.cs | 6 +++-- .../Converters/AuditLogChangeConverter.cs | 26 ++++++++++++++----- 3 files changed, 28 insertions(+), 10 deletions(-) diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/AuditLogs/IAuditLogChange.cs b/src/core/DSharpPlus.Core.Abstractions.Models/AuditLogs/IAuditLogChange.cs index 9466d124c9..e8b41d3946 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/AuditLogs/IAuditLogChange.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/AuditLogs/IAuditLogChange.cs @@ -4,6 +4,8 @@ using System.Text.Json; +using Remora.Rest.Core; + namespace DSharpPlus.Core.Abstractions.Models; /// @@ -14,12 +16,12 @@ public interface IAuditLogChange /// /// The new value of this field. /// - public JsonElement NewValue { get; } + public Optional NewValue { get; } /// /// The old value of this field. /// - public JsonElement OldValue { get; } + public Optional OldValue { get; } /// /// The name of the changed field, with a few exceptions: see diff --git a/src/core/DSharpPlus.Core.Models/AuditLogs/AuditLogChange.cs b/src/core/DSharpPlus.Core.Models/AuditLogs/AuditLogChange.cs index a2b1c1de3d..65d8c4462b 100644 --- a/src/core/DSharpPlus.Core.Models/AuditLogs/AuditLogChange.cs +++ b/src/core/DSharpPlus.Core.Models/AuditLogs/AuditLogChange.cs @@ -4,6 +4,8 @@ using System.Text.Json; +using Remora.Rest.Core; + using DSharpPlus.Core.Abstractions.Models; namespace DSharpPlus.Core.Models; @@ -12,10 +14,10 @@ namespace DSharpPlus.Core.Models; public sealed record AuditLogChange : IAuditLogChange { /// - public required JsonElement NewValue { get; init; } + public Optional NewValue { get; init; } /// - public required JsonElement OldValue { get; init; } + public Optional OldValue { get; init; } /// public required string Key { get; init; } diff --git a/src/core/DSharpPlus.Core.Models/Converters/AuditLogChangeConverter.cs b/src/core/DSharpPlus.Core.Models/Converters/AuditLogChangeConverter.cs index 8eb6414e1e..5d498af6e8 100644 --- a/src/core/DSharpPlus.Core.Models/Converters/AuditLogChangeConverter.cs +++ b/src/core/DSharpPlus.Core.Models/Converters/AuditLogChangeConverter.cs @@ -8,6 +8,8 @@ using DSharpPlus.Core.Abstractions.Models; +using Remora.Rest.Core; + namespace DSharpPlus.Core.Models.Converters; /// @@ -32,8 +34,6 @@ JsonSerializerOptions options ( !JsonDocument.TryParseValue(ref reader, out JsonDocument? document) || document.RootElement.TryGetProperty("key", out JsonElement propertyKey) - || document.RootElement.TryGetProperty("new_value", out JsonElement newProperty) - || document.RootElement.TryGetProperty("old_value", out JsonElement oldProperty) ) { throw new JsonException("The provided JSON object was malformed."); @@ -41,6 +41,14 @@ JsonSerializerOptions options string key = propertyKey.GetString()!; + Optional newProperty = document.RootElement.TryGetProperty("new_value", out JsonElement value) + ? value + : new Optional(); + + Optional oldProperty = document.RootElement.TryGetProperty("old_value", out JsonElement oldValue) + ? oldValue + : new Optional(); + return new AuditLogChange { Key = key, @@ -62,11 +70,17 @@ JsonSerializerOptions options writer.WritePropertyName("key"); writer.WriteStringValue(value.Key); - writer.WritePropertyName("new_value"); - value.NewValue.WriteTo(writer); + if (value.NewValue.IsDefined(out JsonElement newValue)) + { + writer.WritePropertyName("new_value"); + newValue.WriteTo(writer); + } - writer.WritePropertyName("old_value"); - value.OldValue.WriteTo(writer); + if (value.OldValue.IsDefined(out JsonElement oldValue)) + { + writer.WritePropertyName("old_value"); + oldValue.WriteTo(writer); + } writer.WriteEndObject(); } From 73b34194da6127cb305251fc20ddbaef85653a76 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Fri, 18 Aug 2023 16:40:12 +0200 Subject: [PATCH 093/323] remove concrete types for removed interfaces --- .../AutocompleteInteractionData.cs | 35 ------------------- .../AutocompleteInteractionDataOption.cs | 34 ------------------ 2 files changed, 69 deletions(-) delete mode 100644 src/core/DSharpPlus.Core.Models/Interactions/AutocompleteInteractionData.cs delete mode 100644 src/core/DSharpPlus.Core.Models/Interactions/AutocompleteInteractionDataOption.cs diff --git a/src/core/DSharpPlus.Core.Models/Interactions/AutocompleteInteractionData.cs b/src/core/DSharpPlus.Core.Models/Interactions/AutocompleteInteractionData.cs deleted file mode 100644 index af22013362..0000000000 --- a/src/core/DSharpPlus.Core.Models/Interactions/AutocompleteInteractionData.cs +++ /dev/null @@ -1,35 +0,0 @@ -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -using DSharpPlus.Entities; - -using Remora.Rest.Core; - -using System.Collections.Generic; - -using DSharpPlus.Core.Abstractions.Models; - -namespace DSharpPlus.Core.Models; - -/// -public sealed record AutocompleteInteractionData : IAutocompleteInteractionData -{ - /// - public required Snowflake Id { get; init; } - - /// - public required string Name { get; init; } - - /// - public required DiscordApplicationCommandType Type { get; init; } - - /// - public Optional Resolved { get; init; } - - /// - public Optional> Options { get; init; } - - /// - public Optional GuildId { get; init; } -} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/Interactions/AutocompleteInteractionDataOption.cs b/src/core/DSharpPlus.Core.Models/Interactions/AutocompleteInteractionDataOption.cs deleted file mode 100644 index 08f4756479..0000000000 --- a/src/core/DSharpPlus.Core.Models/Interactions/AutocompleteInteractionDataOption.cs +++ /dev/null @@ -1,34 +0,0 @@ -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -using System.Collections.Generic; - -using DSharpPlus.Entities; - -using OneOf; - -using Remora.Rest.Core; - -using DSharpPlus.Core.Abstractions.Models; - -namespace DSharpPlus.Core.Models; - -/// -public sealed record AutocompleteInteractionDataOption : IAutocompleteInteractionDataOption -{ - /// - public required string Name { get; init; } - - /// - public required DiscordApplicationCommandOptionType Type { get; init; } - - /// - public Optional> Value { get; init; } - - /// - public Optional> Options { get; init; } - - /// - public Optional Focused { get; init; } -} \ No newline at end of file From 995fdd3ee336d84dd6bddbfa57e059e7b4decdbe Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Fri, 18 Aug 2023 16:58:17 +0200 Subject: [PATCH 094/323] use TryGet over IsDefined --- Directory.Packages.props | 2 +- .../Converters/AuditLogChangeConverter.cs | 4 ++-- src/core/DSharpPlus.Core.Models/DSharpPlus.Core.Models.csproj | 1 + 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index 19b5dbfd7a..3b2fdce9a0 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -1,6 +1,5 @@ - @@ -10,6 +9,7 @@ + diff --git a/src/core/DSharpPlus.Core.Models/Converters/AuditLogChangeConverter.cs b/src/core/DSharpPlus.Core.Models/Converters/AuditLogChangeConverter.cs index 5d498af6e8..06c0b9ef1f 100644 --- a/src/core/DSharpPlus.Core.Models/Converters/AuditLogChangeConverter.cs +++ b/src/core/DSharpPlus.Core.Models/Converters/AuditLogChangeConverter.cs @@ -70,13 +70,13 @@ JsonSerializerOptions options writer.WritePropertyName("key"); writer.WriteStringValue(value.Key); - if (value.NewValue.IsDefined(out JsonElement newValue)) + if (value.NewValue.TryGet(out JsonElement newValue)) { writer.WritePropertyName("new_value"); newValue.WriteTo(writer); } - if (value.OldValue.IsDefined(out JsonElement oldValue)) + if (value.OldValue.TryGet(out JsonElement oldValue)) { writer.WritePropertyName("old_value"); oldValue.WriteTo(writer); diff --git a/src/core/DSharpPlus.Core.Models/DSharpPlus.Core.Models.csproj b/src/core/DSharpPlus.Core.Models/DSharpPlus.Core.Models.csproj index a3df296268..8c0b6b256e 100644 --- a/src/core/DSharpPlus.Core.Models/DSharpPlus.Core.Models.csproj +++ b/src/core/DSharpPlus.Core.Models/DSharpPlus.Core.Models.csproj @@ -9,6 +9,7 @@ + From 2d35db5753e3d43af78ab157b03ec85325197185 Mon Sep 17 00:00:00 2001 From: Lunar Starstrum Date: Tue, 22 Aug 2023 16:47:14 -0500 Subject: [PATCH 095/323] Add sourcelink --- Directory.Packages.props | 1 + 1 file changed, 1 insertion(+) diff --git a/Directory.Packages.props b/Directory.Packages.props index 3b2fdce9a0..a5493d26f7 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -6,6 +6,7 @@ + From 064a16fc8f1df7ab546cad74918c4bb139b1bf21 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Thu, 7 Sep 2023 20:41:21 +0200 Subject: [PATCH 096/323] tremens factus sum specify ETF token types --- DSharpPlus.sln | 16 ++ src/etf/DSharpPlus.ETF/DSharpPlus.ETF.csproj | 9 + src/etf/DSharpPlus.ETF/TokenType.cs | 174 +++++++++++++++++++ 3 files changed, 199 insertions(+) create mode 100644 src/etf/DSharpPlus.ETF/DSharpPlus.ETF.csproj create mode 100644 src/etf/DSharpPlus.ETF/TokenType.cs diff --git a/DSharpPlus.sln b/DSharpPlus.sln index b87a35f862..574d68ebeb 100644 --- a/DSharpPlus.sln +++ b/DSharpPlus.sln @@ -28,6 +28,12 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Generators", "Generators", EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DSharpPlus.SourceGenerators.Common", "gen\common\DSharpPlus.SourceGenerators.Common.csproj", "{98D2C52C-E3BA-4564-919C-750775B7BA9C}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DSharpPlus.Core.Models.Tests", "tests\core\DSharpPlus.Core.Models.Tests\DSharpPlus.Core.Models.Tests.csproj", "{9F25D892-3CB0-4D47-B67D-D3FFFADC03E0}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ETF", "ETF", "{0BB713D0-63CC-4373-9C76-3C80611EFFA6}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DSharpPlus.ETF", "src\etf\DSharpPlus.ETF\DSharpPlus.ETF.csproj", "{96B95EF1-14FC-440F-B924-05E41929AA33}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -58,6 +64,14 @@ Global {98D2C52C-E3BA-4564-919C-750775B7BA9C}.Debug|Any CPU.Build.0 = Debug|Any CPU {98D2C52C-E3BA-4564-919C-750775B7BA9C}.Release|Any CPU.ActiveCfg = Release|Any CPU {98D2C52C-E3BA-4564-919C-750775B7BA9C}.Release|Any CPU.Build.0 = Release|Any CPU + {9F25D892-3CB0-4D47-B67D-D3FFFADC03E0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9F25D892-3CB0-4D47-B67D-D3FFFADC03E0}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9F25D892-3CB0-4D47-B67D-D3FFFADC03E0}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9F25D892-3CB0-4D47-B67D-D3FFFADC03E0}.Release|Any CPU.Build.0 = Release|Any CPU + {96B95EF1-14FC-440F-B924-05E41929AA33}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {96B95EF1-14FC-440F-B924-05E41929AA33}.Debug|Any CPU.Build.0 = Debug|Any CPU + {96B95EF1-14FC-440F-B924-05E41929AA33}.Release|Any CPU.ActiveCfg = Release|Any CPU + {96B95EF1-14FC-440F-B924-05E41929AA33}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -70,6 +84,8 @@ Global {9199CD3F-AD85-453E-9BA5-2B4ACC2576EC} = {EAC2F7ED-0965-4607-ACE0-829885A612C5} {21927A64-7345-4D90-9EE2-7FA4B1973AAC} = {EAE89CF5-AA91-4A22-9949-A46FAE1BF0D0} {98D2C52C-E3BA-4564-919C-750775B7BA9C} = {5FBB4590-56B0-453B-A87B-08A17C599B5C} + {9F25D892-3CB0-4D47-B67D-D3FFFADC03E0} = {21927A64-7345-4D90-9EE2-7FA4B1973AAC} + {96B95EF1-14FC-440F-B924-05E41929AA33} = {0BB713D0-63CC-4373-9C76-3C80611EFFA6} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {55CDA684-8900-479B-9DAE-BA3BE09B337B} diff --git a/src/etf/DSharpPlus.ETF/DSharpPlus.ETF.csproj b/src/etf/DSharpPlus.ETF/DSharpPlus.ETF.csproj new file mode 100644 index 0000000000..fa71b7ae6a --- /dev/null +++ b/src/etf/DSharpPlus.ETF/DSharpPlus.ETF.csproj @@ -0,0 +1,9 @@ + + + + net8.0 + enable + enable + + + diff --git a/src/etf/DSharpPlus.ETF/TokenType.cs b/src/etf/DSharpPlus.ETF/TokenType.cs new file mode 100644 index 0000000000..4812217ef5 --- /dev/null +++ b/src/etf/DSharpPlus.ETF/TokenType.cs @@ -0,0 +1,174 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.ETF; + +/// +/// Specifies the token type prefixes for each type, according to ERTS 14.0.2. +/// +public enum TokenType : byte +{ + /// + /// erl_ext_dist 4 + /// + AtomCache = 82, + + /// + /// erl_ext_dist 5 + /// + SmallInteger = 97, + + /// + /// erl_ext_dist 6 + /// + Integer = 98, + + /// + /// erl_ext_dist 7 + /// + Float = 99, + + /// + /// erl_ext_dist 8 + /// + Port = 102, + + /// + /// erl_ext_dist 9 + /// + NewPort = 89, + + /// + /// erl_ext_dist 10 + /// + V4Port = 120, + + /// + /// erl_ext_dist 11 + /// + Pid = 103, + + /// + /// erl_ext_dist 12 + /// + NewPid = 88, + + /// + /// erl_ext_dist 13 + /// + SmallTuple = 104, + + /// + /// erl_ext_dist 14 + /// + LargeTuple = 105, + + /// + /// erl_ext_dist 15 + /// + Map = 116, + + /// + /// erl_ext_dist 16 + /// + Nil = 106, + + /// + /// erl_ext_dist 17 + /// + String = 107, + + /// + /// erl_ext_dist 18 + /// + List = 108, + + /// + /// erl_ext_dist 19 + /// + Binary = 109, + + /// + /// erl_ext_dist 20 + /// + SmallBig = 110, + + /// + /// erl_ext_dist 21 + /// + LargeBig = 111, + + // deprecated + // + // /// + // /// erl_ext_dist 22 + // /// + // Reference = 101, + + /// + /// erl_ext_dist 23 + /// + NewReference = 114, + + /// + /// erl_ext_dist 24 + /// + NewerReference = 90, + + // removed + // + // /// + // /// erl_ext_dist 25 + // /// + // Fun = 117, + + /// + /// erl_ext_dist 26 + /// + NewFun = 112, + + /// + /// erl_ext_dist 27 + /// + Export = 113, + + /// + /// erl_ext_dist 28 + /// + BitBinary = 77, + + /// + /// erl_ext_dist 29 + /// + NewFloat = 70, + + /// + /// erl_ext_dist 30 + /// + AtomUtf8 = 118, + + /// + /// erl_ext_dist 31 + /// + SmallAtomUtf8 = 119, + + // deprecated + // + // /// + // /// erl_ext_dist 32 + // /// + // Atom = 100, + // + // deprecated + // + // /// + // /// erl_ext_dist 33 + // /// + // SmallAtom = 115, + + /// + /// erl_ext_dist 34 + /// + Local = 121, +} From b0436fc9f5c39e5975a4b776e07225e7ac671260 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Thu, 14 Sep 2023 15:50:49 +0200 Subject: [PATCH 097/323] libera me, domine, de mortem aeternam we can now fully understand the structure of any given ETF document. next up: understanding the contents --- .editorconfig | 2 +- DSharpPlus.sln | 6 +- Directory.Build.props | 3 +- Directory.Packages.props | 1 + dsharpplus.ps1 | 2 +- lib/bundles | 2 +- src/etf/DSharpPlus.ETF/DSharpPlus.ETF.csproj | 8 +- src/etf/DSharpPlus.Etf.sln | 22 + src/etf/DSharpPlus.Etf/EtfTokenType.cs | 44 ++ .../Serialization/EtfReader.Lexing.cs | 741 ++++++++++++++++++ .../DSharpPlus.Etf/Serialization/EtfReader.cs | 205 +++++ .../TermType.cs} | 20 +- 12 files changed, 1038 insertions(+), 18 deletions(-) create mode 100644 src/etf/DSharpPlus.Etf.sln create mode 100644 src/etf/DSharpPlus.Etf/EtfTokenType.cs create mode 100644 src/etf/DSharpPlus.Etf/Serialization/EtfReader.Lexing.cs create mode 100644 src/etf/DSharpPlus.Etf/Serialization/EtfReader.cs rename src/etf/{DSharpPlus.ETF/TokenType.cs => DSharpPlus.Etf/TermType.cs} (89%) diff --git a/.editorconfig b/.editorconfig index 97ee1117f7..b676699d66 100644 --- a/.editorconfig +++ b/.editorconfig @@ -53,7 +53,7 @@ dotnet_diagnostic.IDE2002.severity = error dotnet_diagnostic.IDE0073.severity = error # this. preferences -dotnet_style_qualification_for_field = true:silent +dotnet_style_qualification_for_field = true:error dotnet_style_qualification_for_property = true:silent dotnet_style_qualification_for_method = true:silent dotnet_style_qualification_for_event = true:silent diff --git a/DSharpPlus.sln b/DSharpPlus.sln index 574d68ebeb..bef5d5edd1 100644 --- a/DSharpPlus.sln +++ b/DSharpPlus.sln @@ -28,11 +28,11 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Generators", "Generators", EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DSharpPlus.SourceGenerators.Common", "gen\common\DSharpPlus.SourceGenerators.Common.csproj", "{98D2C52C-E3BA-4564-919C-750775B7BA9C}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DSharpPlus.Core.Models.Tests", "tests\core\DSharpPlus.Core.Models.Tests\DSharpPlus.Core.Models.Tests.csproj", "{9F25D892-3CB0-4D47-B67D-D3FFFADC03E0}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DSharpPlus.Core.Models.Tests", "tests\core\DSharpPlus.Core.Models.Tests\DSharpPlus.Core.Models.Tests.csproj", "{9F25D892-3CB0-4D47-B67D-D3FFFADC03E0}" EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ETF", "ETF", "{0BB713D0-63CC-4373-9C76-3C80611EFFA6}" +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Etf", "Etf", "{0BB713D0-63CC-4373-9C76-3C80611EFFA6}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DSharpPlus.ETF", "src\etf\DSharpPlus.ETF\DSharpPlus.ETF.csproj", "{96B95EF1-14FC-440F-B924-05E41929AA33}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DSharpPlus.Etf", "src\etf\DSharpPlus.ETF\DSharpPlus.Etf.csproj", "{96B95EF1-14FC-440F-B924-05E41929AA33}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/Directory.Build.props b/Directory.Build.props index 49faed871b..b837b69c1f 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -7,7 +7,8 @@ preview True True - $(NoWarn);CS1591 + All + $(NoWarn);CS1591;CA1028;CA1720;CA2007 True diff --git a/Directory.Packages.props b/Directory.Packages.props index a5493d26f7..b96ba0779a 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -13,6 +13,7 @@ + diff --git a/dsharpplus.ps1 b/dsharpplus.ps1 index 7162ed01f6..6277d03308 100644 --- a/dsharpplus.ps1 +++ b/dsharpplus.ps1 @@ -49,7 +49,7 @@ param ( [string]$ToolGroup, [Alias('s')] - [ValidateSet("core")] + [ValidateSet("core", "etf")] [string[]]$Subset, [Alias('n')] diff --git a/lib/bundles b/lib/bundles index 1235e0ad2a..e02be6dcd8 160000 --- a/lib/bundles +++ b/lib/bundles @@ -1 +1 @@ -Subproject commit 1235e0ad2a766492bf3dcdea09256e71a62fdebd +Subproject commit e02be6dcd817312ed97d8cc0a2ada3b21e4a4db8 diff --git a/src/etf/DSharpPlus.ETF/DSharpPlus.ETF.csproj b/src/etf/DSharpPlus.ETF/DSharpPlus.ETF.csproj index fa71b7ae6a..e4e8726228 100644 --- a/src/etf/DSharpPlus.ETF/DSharpPlus.ETF.csproj +++ b/src/etf/DSharpPlus.ETF/DSharpPlus.ETF.csproj @@ -1,9 +1,11 @@  - net8.0 - enable - enable + true + + + + diff --git a/src/etf/DSharpPlus.Etf.sln b/src/etf/DSharpPlus.Etf.sln new file mode 100644 index 0000000000..a73e281c85 --- /dev/null +++ b/src/etf/DSharpPlus.Etf.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.0.31903.59 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DSharpPlus.Etf", "DSharpPlus.Etf\DSharpPlus.Etf.csproj", "{4739EC8E-C952-427B-8771-12645BF14997}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {4739EC8E-C952-427B-8771-12645BF14997}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4739EC8E-C952-427B-8771-12645BF14997}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4739EC8E-C952-427B-8771-12645BF14997}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4739EC8E-C952-427B-8771-12645BF14997}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/src/etf/DSharpPlus.Etf/EtfTokenType.cs b/src/etf/DSharpPlus.Etf/EtfTokenType.cs new file mode 100644 index 0000000000..dd07d4c515 --- /dev/null +++ b/src/etf/DSharpPlus.Etf/EtfTokenType.cs @@ -0,0 +1,44 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Etf; + +public enum EtfTokenType : byte +{ + + /// + /// A map token is started. + /// + StartMap, + + /// + /// A list token is started. + /// + StartList, + + /// + /// A tuple of any size is started. + /// + StartTuple, + + /// + /// Any term containing data. + /// + Term, + + /// + /// A map token is ended. + /// + EndMap, + + /// + /// A list token is ended. + /// + EndList, + + /// + /// A tuple of any size is ended. + /// + EndTuple +} diff --git a/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Lexing.cs b/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Lexing.cs new file mode 100644 index 0000000000..ec5b1314c2 --- /dev/null +++ b/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Lexing.cs @@ -0,0 +1,741 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; +using System.Buffers.Binary; + +namespace DSharpPlus.Etf.Serialization; + +/******************************************************************************************************* +* here, we deal with preliminary lexing and length decoding of the next term ahead +* +* the pattern for all methods here is `int LexName(out bool success);` returning the length looked at +* and writing whether the procedure was successful to an out parameter. this enables somewhat cleaner +* aggregation in EtfReader.Read while not producing slower assembly, despite breaking convention of +* `bool TryLexName(out int length);` +* +* furthermore, in methods where there are only very few if statements with short bodies, the success +* path should be inside the first if tree, never branching to an - explicit or implicit - else. +* this is specifically designed to make branch predictors happy; from RyuJIT to the predictors in most +* CPUs, branch predictors usually expect the 'hottest'/most common path to be in the first if tree. +* this especially matters on apple silicon, where prediction failures are extremely expensive, and on +* intel x86 CPUs. +* in T1, the JIT generally picks up on it, but there's a throwhelper call associated with ROS.Slice that +* still causes marginal losses in T1, and much less marginal losses in the failure branch. +*******************************************************************************************************/ + +partial struct EtfReader +{ + /// + /// Lexes an atom-cache term, as per erl_ext_dist 4. + /// + /// Indicates whether the term was read successfully. + /// The amount of bytes processed. + private int LexAtomCache + ( + out bool success + ) + { + if (this.index + 1 < this.data.Length) + { + this.rawTerm = this.data.Slice(this.index, 1); + + success = true; + return 1; + } + + success = false; + return 0; + } + + /// + /// Lexes an atom-utf8 term, as per erl_ext_dist 30. + /// + /// Indicates whether the term was read successfully. + /// The amount of bytes processed. + private int LexAtomUtf8 + ( + out bool success + ) + { + if (this.index + 2 < this.data.Length) + { + ReadOnlySpan lengthSlice = this.data.Slice(this.index, 2); + ushort length = BinaryPrimitives.ReadUInt16BigEndian(lengthSlice); + + if (this.index + 2 + length < this.data.Length) + { + this.rawTerm = this.data.Slice(this.index + 2, length); + + success = true; + return length + 2; + } + } + + success = false; + return 0; + } + + /// + /// Lexes a binary term, as per erl_ext_dist 19. + /// + /// Indicates whether the term was read successfully. + /// The amount of bytes processed. + private int LexBinary + ( + out bool success + ) + { + if (this.index + 4 < this.data.Length) + { + ReadOnlySpan lengthSlice = this.data.Slice(this.index, 4); + uint length = BinaryPrimitives.ReadUInt32BigEndian(lengthSlice); + + if (this.index + 4 + length < this.data.Length) + { + this.rawTerm = this.data.Slice(this.index + 4, (int)length); + + success = true; + return (int)length + 4; + } + } + + success = false; + return 0; + } + + /// + /// Lexes a bit-binary term, as per erl_ext_dist 28. + /// + /// Indicates whether the term was read successfully. + /// The amount of bytes processed. + private int LexBitBinary + ( + out bool success + ) + { + if (this.index + 4 < this.data.Length) + { + ReadOnlySpan lengthSlice = this.data.Slice(this.index, 4); + uint length = BinaryPrimitives.ReadUInt32BigEndian(lengthSlice); + + // we do this by simply prepending the raw span with the amount of valid bits in the last byte + if (this.index + 5 + length < this.data.Length) + { + this.rawTerm = this.data.Slice(this.index + 4, (int)length + 1); + + success = true; + return (int)length + 5; + } + } + + success = false; + return 0; + } + + /// + /// Lexes an export term, as per erl_ext_dist 27. + /// + /// Indicates whether the term was read successfully. + /// The amount of bytes processed. + private int LexExport + ( + out bool success + ) + { + // first atom: module name + if (this.index + 2 < this.data.Length) + { + int accumulatedLength = 2; + + ReadOnlySpan lengthSlice = this.data.Slice(this.index, 2); + ushort length = BinaryPrimitives.ReadUInt16BigEndian(lengthSlice); + + accumulatedLength += length; + + // second atom: function name + if (this.index + accumulatedLength + 2 < this.data.Length) + { + lengthSlice = this.data.Slice(this.index + accumulatedLength, 2); + length = BinaryPrimitives.ReadUInt16BigEndian(lengthSlice); + + accumulatedLength += 2 + length; + + // one byte for arity + if (this.index + ++accumulatedLength < this.data.Length) + { + this.rawTerm = this.data.Slice(this.index, accumulatedLength); + + success = true; + return accumulatedLength; + } + } + } + + success = false; + return 0; + } + + /// + /// Lexes a float term, as per erl_ext_dist 7. + /// + /// Indicates whether the term was read successfully. + /// The amount of bytes processed. + private int LexFloat + ( + out bool success + ) + { + if (this.index + 31 < this.data.Length) + { + this.rawTerm = this.data.Slice(this.index, 31); + + success = true; + return 31; + } + + success = false; + return 0; + } + + /// + /// Lexes an integer term, as per erl_ext_dist 6. + /// + /// Indicates whether the term was read successfully. + /// The amount of bytes processed. + private int LexInteger + ( + out bool success + ) + { + if (this.index + 4 < this.data.Length) + { + this.rawTerm = this.data.Slice(this.index, 4); + + success = true; + return 4; + } + + success = false; + return 0; + } + + /// + /// Lexes a large big-integer term, as per erl_ext_dist 21. + /// + /// Indicates whether the term was read successfully. + /// The amount of bytes processed. + private int LexLargeBigInteger + ( + out bool success + ) + { + if (this.index + 4 < this.data.Length) + { + ReadOnlySpan lengthSlice = this.data.Slice(this.index, 4); + uint length = BinaryPrimitives.ReadUInt32BigEndian(lengthSlice); + + // the first byte here carries the sign + if (this.index + 5 + length < this.data.Length) + { + this.rawTerm = this.data.Slice(this.index + 4, (int)length + 1); + + success = true; + return (int)length + 5; + } + } + + success = false; + return 0; + } + + /// + /// Lexes a large tuple term, as per erl_ext_dist 14. + /// + /// Indicates whether the term was read successfully. + /// The amount of bytes processed. + private readonly int LexLargeTuple + ( + out bool success + ) + { + if (this.index + 4 < this.data.Length) + { + ReadOnlySpan lengthSlice = this.data.Slice(this.index, 4); + uint length = BinaryPrimitives.ReadUInt32BigEndian(lengthSlice); + + this.complexObjects.Push(TermType.LargeTuple); + this.remainingLengths.Push(length); + + success = true; + return 4; + } + + success = false; + return 0; + } + + /// + /// Lexes a list term, as per erl_ext_dist 18. + /// + /// Indicates whether the term was read successfully. + /// The amount of bytes processed. + private readonly int LexList + ( + out bool success + ) + { + if (this.index + 4 < this.data.Length) + { + ReadOnlySpan lengthSlice = this.data.Slice(this.index, 4); + uint length = BinaryPrimitives.ReadUInt32BigEndian(lengthSlice); + + this.complexObjects.Push(TermType.LargeTuple); + + // account for the null-terminator-that-may-not-actually-be-null-at-all + this.remainingLengths.Push(length + 1); + + success = true; + return 4; + } + + success = false; + return 0; + } + + /// + /// Lexes a local term, as per erl_ext_dist 34. + /// + /// Indicates whether the term was read successfully. + /// The amount of bytes processed. + private static int LexLocal + ( + out bool success + ) + { + success = true; + return 0; + } + + /// + /// Lexes a map term, as per erl_ext_dist 15. + /// + /// Indicates whether the term was read successfully. + /// The amount of bytes processed. + private readonly int LexMap + ( + out bool success + ) + { + if (this.index + 4 < this.data.Length) + { + ReadOnlySpan lengthSlice = this.data.Slice(this.index, 4); + uint length = BinaryPrimitives.ReadUInt32BigEndian(lengthSlice); + + this.complexObjects.Push(TermType.LargeTuple); + this.remainingLengths.Push(length * 2); + + success = true; + return 4; + } + + success = false; + return 0; + } + + /// + /// Lexes a newer-reference term, as per erl_ext_dist 24. + /// + /// Indicates whether the term was read successfully. + /// The amount of bytes processed. + private int LexNewerReference + ( + out bool success + ) + { + if (this.index + 2 < this.data.Length) + { + ReadOnlySpan lengthSlice = this.data.Slice(this.index, 2); + ushort idLength = BinaryPrimitives.ReadUInt16BigEndian(lengthSlice); + + // decode the atom node name + if (this.index + 4 < this.data.Length) + { + lengthSlice = this.data.Slice(this.index + 2, 2); + ushort nodeLength = BinaryPrimitives.ReadUInt16BigEndian(lengthSlice); + + int accumulatedLength = (idLength * 4) + nodeLength + 8; + + if (this.index + accumulatedLength < this.data.Length) + { + this.rawTerm = this.data.Slice(this.index, accumulatedLength); + + success = true; + return accumulatedLength; + } + } + } + + success = false; + return 0; + } + + /// + /// Lexes a new-float term, as per erl_ext_dist 29. + /// + /// Indicates whether the term was read successfully. + /// The amount of bytes processed. + private int LexNewFloat + ( + out bool success + ) + { + if (this.index + 8 < this.data.Length) + { + this.rawTerm = this.data.Slice(this.index, 8); + + success = true; + return 8; + } + + success = false; + return 0; + } + + /// + /// Lexes a new-PID term, as per erl_ext_dist 12. + /// + /// Indicates whether the term was read successfully. + /// The amount of bytes processed. + private int LexNewPid + ( + out bool success + ) + { + if (this.index + 2 < this.data.Length) + { + + ReadOnlySpan lengthSlice = this.data.Slice(this.index, 2); + int length = BinaryPrimitives.ReadUInt16BigEndian(lengthSlice); + + length += 14; + + if (this.index + length < this.data.Length) + { + this.rawTerm = this.data.Slice(this.index, length); + + success = true; + return length; + } + } + + success = false; + return 0; + } + + /// + /// Lexes a new-port term, as per erl_ext_dist 9. + /// + /// Indicates whether the term was read successfully. + /// The amount of bytes processed. + private int LexNewPort + ( + out bool success + ) + { + if (this.index + 2 < this.data.Length) + { + + ReadOnlySpan lengthSlice = this.data.Slice(this.index, 2); + int length = BinaryPrimitives.ReadUInt16BigEndian(lengthSlice); + + length += 10; + + if (this.index + length < this.data.Length) + { + this.rawTerm = this.data.Slice(this.index, length); + + success = true; + return length; + } + } + + success = false; + return 0; + } + + /// + /// Lexes a new-reference term, as per erl_ext_dist 23. + /// + /// Indicates whether the term was read successfully. + /// The amount of bytes processed. + private int LexNewReference + ( + out bool success + ) + { + if (this.index + 2 < this.data.Length) + { + ReadOnlySpan lengthSlice = this.data.Slice(this.index, 2); + ushort idLength = BinaryPrimitives.ReadUInt16BigEndian(lengthSlice); + + // decode the atom node name + if (this.index + 4 < this.data.Length) + { + lengthSlice = this.data.Slice(this.index + 2, 2); + ushort nodeLength = BinaryPrimitives.ReadUInt16BigEndian(lengthSlice); + + int accumulatedLength = (idLength * 4) + nodeLength + 5; + + if (this.index + accumulatedLength < this.data.Length) + { + this.rawTerm = this.data.Slice(this.index, accumulatedLength); + + success = true; + return accumulatedLength; + } + } + } + + success = false; + return 0; + } + + /// + /// Lexes a nil term, as per erl_ext_dist 16. + /// + /// Indicates whether the term was read successfully. + /// The amount of bytes processed. + private static int LexNil + ( + out bool success + ) + { + success = true; + return 0; + } + + /// + /// Lexes a PID term, as per erl_ext_dist 11. + /// + /// Indicates whether the term was read successfully. + /// The amount of bytes processed. + private int LexPid + ( + out bool success + ) + { + if (this.index + 2 < this.data.Length) + { + + ReadOnlySpan lengthSlice = this.data.Slice(this.index, 2); + int length = BinaryPrimitives.ReadUInt16BigEndian(lengthSlice); + + length += 11; + + if (this.index + length < this.data.Length) + { + this.rawTerm = this.data.Slice(this.index, length); + + success = true; + return length; + } + } + + success = false; + return 0; + } + + /// + /// Lexes a port term, as per erl_ext_dist 8. + /// + /// Indicates whether the term was read successfully. + /// The amount of bytes processed. + private int LexPort + ( + out bool success + ) + { + if (this.index + 2 < this.data.Length) + { + + ReadOnlySpan lengthSlice = this.data.Slice(this.index, 2); + int length = BinaryPrimitives.ReadUInt16BigEndian(lengthSlice); + + length += 7; + + if (this.index + length < this.data.Length) + { + this.rawTerm = this.data.Slice(this.index, length); + + success = true; + return length; + } + } + + success = false; + return 0; + } + + /// + /// Lexes an atom-utf8 term, as per erl_ext_dist 30. + /// + /// Indicates whether the term was read successfully. + /// The amount of bytes processed. + private int LexSmallAtomUtf8 + ( + out bool success + ) + { + if (this.index + 1 < this.data.Length) + { + byte length = this.data[this.index + 1]; + + if (this.index + 1 + length < this.data.Length) + { + this.rawTerm = this.data.Slice(this.index + 1, length); + + success = true; + return length + 1; + } + } + + success = false; + return 0; + } + + /// + /// Lexes a small big-integer term, as per erl_ext_dist 21. + /// + /// Indicates whether the term was read successfully. + /// The amount of bytes processed. + private int LexSmallBigInteger + ( + out bool success + ) + { + if (this.index + 1 < this.data.Length) + { + byte length = this.data[this.index]; + + // the first byte here carries the sign + if (this.index + 2 + length < this.data.Length) + { + this.rawTerm = this.data.Slice(this.index + 1, (int)length + 1); + + success = true; + return (int)length + 5; + } + } + + success = false; + return 0; + } + + /// + /// Lexes a small integer term, as per erl_ext_dist 5. + /// + /// Indicates whether the term was read successfully. + /// The amount of bytes processed. + private int LexSmallInteger + ( + out bool success + ) + { + if (this.index + 1 < this.data.Length) + { + this.rawTerm = this.data.Slice(this.index, 1); + + success = true; + return 1; + } + + success = false; + return 0; + } + + /// + /// Lexes a small tuple term, as per erl_ext_dist 13. + /// + /// Indicates whether the term was read successfully. + /// The amount of bytes processed. + private readonly int LexSmallTuple + ( + out bool success + ) + { + if (this.index + 1 < this.data.Length) + { + byte length = this.data[this.index]; + + this.complexObjects.Push(TermType.SmallTuple); + this.remainingLengths.Push(length); + + success = true; + return 1; + } + + success = false; + return 0; + } + + /// + /// Lexes a string term, as per erl_ext_dist 17. + /// + /// Indicates whether the term was read successfully. + /// The amount of bytes processed. + private int LexString + ( + out bool success + ) + { + if (this.index + 2 < this.data.Length) + { + ReadOnlySpan lengthSlice = this.data.Slice(this.index, 2); + ushort length = BinaryPrimitives.ReadUInt16BigEndian(lengthSlice); + + if (this.index + 2 + length < this.data.Length) + { + this.rawTerm = this.data.Slice(this.index + 2, length); + + success = true; + return length + 2; + } + } + + success = false; + return 0; + } + + /// + /// Lexes a v4 port term, as per erl_ext_dist 10. + /// + /// Indicates whether the term was read successfully. + /// The amount of bytes processed. + private int LexV4Port + ( + out bool success + ) + { + if (this.index + 2 < this.data.Length) + { + + ReadOnlySpan lengthSlice = this.data.Slice(this.index, 2); + int length = BinaryPrimitives.ReadUInt16BigEndian(lengthSlice); + + length += 14; + + if (this.index + length < this.data.Length) + { + this.rawTerm = this.data.Slice(this.index, length); + + success = true; + return length; + } + } + + success = false; + return 0; + } +} diff --git a/src/etf/DSharpPlus.Etf/Serialization/EtfReader.cs b/src/etf/DSharpPlus.Etf/Serialization/EtfReader.cs new file mode 100644 index 0000000000..b788143cb0 --- /dev/null +++ b/src/etf/DSharpPlus.Etf/Serialization/EtfReader.cs @@ -0,0 +1,205 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; + +using Bundles.ValueCollections; + +namespace DSharpPlus.Etf.Serialization; + +/// +/// Provides a high-performance, low-allocation API for forward-only, read-only access to Erlang External +/// Term Format, version 131, encoded data. It processes binary data sequentially with no caching and +/// without support for non-standard data or older format versions, according to the specification at +/// . +/// This type does not support asynchronous reading nor reentrancy. +/// +/// +/// This type expects provided data to be uncompressed, that is, to not start with 0x8350. +/// +public ref partial struct EtfReader +{ + /*************************************************************************************************** + * do not change field order without accounting for struct layout -- this is an unmanaged struct; + * layout is explicit here! + * + * the current layout is putting the ValueStacks first, which are 24b each; then the spans, which + * are 16b each, then an integer and several byte-sized fields. this leads to 87 bytes used and 1 + * byte padding required on 8-byte-aligned ABIs, 9 bytes padding on higher alignment. + * + * copying this struct will always split at least one cache line, so passing by ref is advised + * where possible - which should be most cases. + ***************************************************************************************************/ + + private readonly ValueStack remainingLengths; + private readonly ValueStack complexObjects; + + private readonly ReadOnlySpan data; + private ReadOnlySpan rawTerm; + + private int index; + private TermType currentTerm; + private EtfTokenType previousToken; + private EtfTokenType currentToken; + + /// + /// Constructs a new with a maximum depth of 256. + /// + /// The span containing the binary ETF to process. + public EtfReader + ( + ReadOnlySpan data + ) + : this(data, 256) + { + + } + + /// + /// Constructs a new with the specified maximum depth. + /// + /// The span containing the binary ETF to process. + /// The maximum nesting depth for maps and lists. + /// Thrown if the root term was compressed. + public EtfReader + ( + ReadOnlySpan data, + int maxDepth + ) + : this + ( + data, + new(new uint[maxDepth]), + new(new TermType[maxDepth]) + ) + { + + } + + /// + /// Constructs a new , using the specified buffers to store temporary metadata. + /// + /// + /// It is legal for call-sites to pass stackallocated ValueStack instances here, thereby eliminating two + /// array allocations. This is, however, illegal if the EtfReader is then passed down the stack, in which + /// case memory it depends on will be destroyed as part of the stack frame. + /// + /// The span containing the binary ETF to process. + /// A stack-buffer for remaining object lengths. + /// A stack-buffer for all complex objects. + /// + /// Thrown if the capacities of the two buffers do not match, or if the root term was compressed. + /// + public EtfReader + ( + ReadOnlySpan data, + ValueStack lengths, + ValueStack objects + ) + { + if (lengths.Capacity != objects.Capacity) + { + throw new ArgumentException("Inconsistent maximum depth between object lengths and object types."); + } + + if (this.data[0] != 0x83) + { + throw new ArgumentException("The data was provided in a wrong format or format version."); + } + + if (this.data[1] == 0x50) + { + throw new ArgumentException("Compressed data cannot be processed."); + } + + this.data = data; + this.remainingLengths = lengths; + this.complexObjects = objects; + this.index = 1; + } + + /// + /// Reads the next ETF term from the input source. + /// + /// True if the term was read successfully. + public bool Read() + { + if (this.index + 1 == this.data.Length) + { + return false; + } + + // ugly ETF hacks :3 + // because ETF doesn't have end tokens (luckily!), we synthesize them here to be able to expose + // an acceptable API without performance sacrifices + // we also, importantly, do this BEFORE decoding the next term. + if (this.remainingLengths.Count != 0 && this.remainingLengths.Peek() == 0) + { + this.currentToken = this.complexObjects.Pop() switch + { + TermType.Map => EtfTokenType.EndMap, + TermType.List => EtfTokenType.EndList, + TermType.SmallTuple or TermType.LargeTuple => EtfTokenType.EndTuple, + _ => EtfTokenType.Term + }; + + this.remainingLengths.Pop(); + return true; + } + + TermType term = (TermType)this.data[this.index++]; + + this.currentTerm = term; + this.previousToken = this.currentToken; + this.currentToken = term switch + { + TermType.Map => EtfTokenType.StartMap, + TermType.List => EtfTokenType.StartList, + TermType.SmallTuple or TermType.LargeTuple => EtfTokenType.StartTuple, + _ => EtfTokenType.Term + }; + + bool success = false; + + // decrease lengths before potentially pushing a new length + if (this.complexObjects.Count != 0) + { + scoped ref uint currentLength = ref this.remainingLengths.PeekRef(); + currentLength--; + } + + this.index += term switch + { + TermType.AtomCache => LexAtomCache(out success), + TermType.AtomUtf8 => LexAtomUtf8(out success), + TermType.Binary => LexBinary(out success), + TermType.BitBinary => LexBitBinary(out success), + TermType.Export => LexExport(out success), + TermType.Float => LexFloat(out success), + TermType.Integer => LexInteger(out success), + TermType.LargeBig => LexLargeBigInteger(out success), + TermType.LargeTuple => LexLargeTuple(out success), + TermType.List => LexList(out success), + TermType.Local => LexLocal(out success), + TermType.Map => LexMap(out success), + TermType.NewerReference => LexNewerReference(out success), + TermType.NewFloat => LexNewFloat(out success), + TermType.NewPid => LexNewPid(out success), + TermType.NewPort => LexNewPort(out success), + TermType.NewReference => LexNewReference(out success), + TermType.Nil => LexNil(out success), + TermType.Pid => LexPid(out success), + TermType.Port => LexPort(out success), + TermType.SmallAtomUtf8 => LexSmallAtomUtf8(out success), + TermType.SmallBig => LexSmallBigInteger(out success), + TermType.SmallInteger => LexSmallInteger(out success), + TermType.SmallTuple => LexSmallTuple(out success), + TermType.String => LexString(out success), + TermType.V4Port => LexV4Port(out success), + _ => 0 + }; + + return success; + } +} diff --git a/src/etf/DSharpPlus.ETF/TokenType.cs b/src/etf/DSharpPlus.Etf/TermType.cs similarity index 89% rename from src/etf/DSharpPlus.ETF/TokenType.cs rename to src/etf/DSharpPlus.Etf/TermType.cs index 4812217ef5..07ceb5e297 100644 --- a/src/etf/DSharpPlus.ETF/TokenType.cs +++ b/src/etf/DSharpPlus.Etf/TermType.cs @@ -2,12 +2,14 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -namespace DSharpPlus.ETF; +namespace DSharpPlus.Etf; /// -/// Specifies the token type prefixes for each type, according to ERTS 14.0.2. +/// Specifies the token type prefixes for each type, according to ERTS 14.0.2, format version 131. /// -public enum TokenType : byte +#pragma warning disable CA1008 // Enums should have zero value, the "none" value is 108 +public enum TermType : byte +#pragma warning restore CA1008 { /// /// erl_ext_dist 4 @@ -122,11 +124,13 @@ public enum TokenType : byte // /// erl_ext_dist 25 // /// // Fun = 117, - - /// - /// erl_ext_dist 26 - /// - NewFun = 112, + // + // unsupported + // + // /// + // /// erl_ext_dist 26 + // /// + // NewFun = 112, /// /// erl_ext_dist 27 From e27b95101451ff006aa0a9ff7529f3020499e2e8 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Thu, 14 Sep 2023 16:03:10 +0200 Subject: [PATCH 098/323] expose necessary data for reading --- .../Serialization/EtfReader.Lexing.cs | 40 +++++++++---------- .../DSharpPlus.Etf/Serialization/EtfReader.cs | 32 ++++++++++----- 2 files changed, 42 insertions(+), 30 deletions(-) diff --git a/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Lexing.cs b/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Lexing.cs index ec5b1314c2..5d8a13b26f 100644 --- a/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Lexing.cs +++ b/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Lexing.cs @@ -39,7 +39,7 @@ out bool success { if (this.index + 1 < this.data.Length) { - this.rawTerm = this.data.Slice(this.index, 1); + this.CurrentTermContents = this.data.Slice(this.index, 1); success = true; return 1; @@ -66,7 +66,7 @@ out bool success if (this.index + 2 + length < this.data.Length) { - this.rawTerm = this.data.Slice(this.index + 2, length); + this.CurrentTermContents = this.data.Slice(this.index + 2, length); success = true; return length + 2; @@ -94,7 +94,7 @@ out bool success if (this.index + 4 + length < this.data.Length) { - this.rawTerm = this.data.Slice(this.index + 4, (int)length); + this.CurrentTermContents = this.data.Slice(this.index + 4, (int)length); success = true; return (int)length + 4; @@ -123,7 +123,7 @@ out bool success // we do this by simply prepending the raw span with the amount of valid bits in the last byte if (this.index + 5 + length < this.data.Length) { - this.rawTerm = this.data.Slice(this.index + 4, (int)length + 1); + this.CurrentTermContents = this.data.Slice(this.index + 4, (int)length + 1); success = true; return (int)length + 5; @@ -165,7 +165,7 @@ out bool success // one byte for arity if (this.index + ++accumulatedLength < this.data.Length) { - this.rawTerm = this.data.Slice(this.index, accumulatedLength); + this.CurrentTermContents = this.data.Slice(this.index, accumulatedLength); success = true; return accumulatedLength; @@ -189,7 +189,7 @@ out bool success { if (this.index + 31 < this.data.Length) { - this.rawTerm = this.data.Slice(this.index, 31); + this.CurrentTermContents = this.data.Slice(this.index, 31); success = true; return 31; @@ -211,7 +211,7 @@ out bool success { if (this.index + 4 < this.data.Length) { - this.rawTerm = this.data.Slice(this.index, 4); + this.CurrentTermContents = this.data.Slice(this.index, 4); success = true; return 4; @@ -239,7 +239,7 @@ out bool success // the first byte here carries the sign if (this.index + 5 + length < this.data.Length) { - this.rawTerm = this.data.Slice(this.index + 4, (int)length + 1); + this.CurrentTermContents = this.data.Slice(this.index + 4, (int)length + 1); success = true; return (int)length + 5; @@ -369,7 +369,7 @@ out bool success if (this.index + accumulatedLength < this.data.Length) { - this.rawTerm = this.data.Slice(this.index, accumulatedLength); + this.CurrentTermContents = this.data.Slice(this.index, accumulatedLength); success = true; return accumulatedLength; @@ -393,7 +393,7 @@ out bool success { if (this.index + 8 < this.data.Length) { - this.rawTerm = this.data.Slice(this.index, 8); + this.CurrentTermContents = this.data.Slice(this.index, 8); success = true; return 8; @@ -423,7 +423,7 @@ out bool success if (this.index + length < this.data.Length) { - this.rawTerm = this.data.Slice(this.index, length); + this.CurrentTermContents = this.data.Slice(this.index, length); success = true; return length; @@ -454,7 +454,7 @@ out bool success if (this.index + length < this.data.Length) { - this.rawTerm = this.data.Slice(this.index, length); + this.CurrentTermContents = this.data.Slice(this.index, length); success = true; return length; @@ -490,7 +490,7 @@ out bool success if (this.index + accumulatedLength < this.data.Length) { - this.rawTerm = this.data.Slice(this.index, accumulatedLength); + this.CurrentTermContents = this.data.Slice(this.index, accumulatedLength); success = true; return accumulatedLength; @@ -536,7 +536,7 @@ out bool success if (this.index + length < this.data.Length) { - this.rawTerm = this.data.Slice(this.index, length); + this.CurrentTermContents = this.data.Slice(this.index, length); success = true; return length; @@ -567,7 +567,7 @@ out bool success if (this.index + length < this.data.Length) { - this.rawTerm = this.data.Slice(this.index, length); + this.CurrentTermContents = this.data.Slice(this.index, length); success = true; return length; @@ -594,7 +594,7 @@ out bool success if (this.index + 1 + length < this.data.Length) { - this.rawTerm = this.data.Slice(this.index + 1, length); + this.CurrentTermContents = this.data.Slice(this.index + 1, length); success = true; return length + 1; @@ -622,7 +622,7 @@ out bool success // the first byte here carries the sign if (this.index + 2 + length < this.data.Length) { - this.rawTerm = this.data.Slice(this.index + 1, (int)length + 1); + this.CurrentTermContents = this.data.Slice(this.index + 1, (int)length + 1); success = true; return (int)length + 5; @@ -645,7 +645,7 @@ out bool success { if (this.index + 1 < this.data.Length) { - this.rawTerm = this.data.Slice(this.index, 1); + this.CurrentTermContents = this.data.Slice(this.index, 1); success = true; return 1; @@ -697,7 +697,7 @@ out bool success if (this.index + 2 + length < this.data.Length) { - this.rawTerm = this.data.Slice(this.index + 2, length); + this.CurrentTermContents = this.data.Slice(this.index + 2, length); success = true; return length + 2; @@ -728,7 +728,7 @@ out bool success if (this.index + length < this.data.Length) { - this.rawTerm = this.data.Slice(this.index, length); + this.CurrentTermContents = this.data.Slice(this.index, length); success = true; return length; diff --git a/src/etf/DSharpPlus.Etf/Serialization/EtfReader.cs b/src/etf/DSharpPlus.Etf/Serialization/EtfReader.cs index b788143cb0..790380c4a8 100644 --- a/src/etf/DSharpPlus.Etf/Serialization/EtfReader.cs +++ b/src/etf/DSharpPlus.Etf/Serialization/EtfReader.cs @@ -25,8 +25,8 @@ public ref partial struct EtfReader * layout is explicit here! * * the current layout is putting the ValueStacks first, which are 24b each; then the spans, which - * are 16b each, then an integer and several byte-sized fields. this leads to 87 bytes used and 1 - * byte padding required on 8-byte-aligned ABIs, 9 bytes padding on higher alignment. + * are 16b each, then an integer and several byte-sized fields. this leads to 86 bytes used and 2 + * bytes padding required on 8-byte-aligned ABIs, 10 bytes padding on higher alignment. * * copying this struct will always split at least one cache line, so passing by ref is advised * where possible - which should be most cases. @@ -36,12 +36,25 @@ public ref partial struct EtfReader private readonly ValueStack complexObjects; private readonly ReadOnlySpan data; - private ReadOnlySpan rawTerm; + /// + /// Gets the contents of the current term. Correctly interpreting this varies based on + /// , and may be invalid for terms that do not declare a body. + /// + public ReadOnlySpan CurrentTermContents { readonly get; private set; } + + // the weird ordering here is to keep struct layout intact private int index; - private TermType currentTerm; - private EtfTokenType previousToken; - private EtfTokenType currentToken; + + /// + /// Gets the type of the last read term. + /// + public TermType TermType { get; private set; } + + /// + /// Gets the type of the last token, which includes synthesized end tokens for all control structures. + /// + public EtfTokenType TokenType { get; private set; } /// /// Constructs a new with a maximum depth of 256. @@ -136,7 +149,7 @@ public bool Read() // we also, importantly, do this BEFORE decoding the next term. if (this.remainingLengths.Count != 0 && this.remainingLengths.Peek() == 0) { - this.currentToken = this.complexObjects.Pop() switch + this.TokenType = this.complexObjects.Pop() switch { TermType.Map => EtfTokenType.EndMap, TermType.List => EtfTokenType.EndList, @@ -150,9 +163,8 @@ public bool Read() TermType term = (TermType)this.data[this.index++]; - this.currentTerm = term; - this.previousToken = this.currentToken; - this.currentToken = term switch + this.TermType = term; + this.TokenType = term switch { TermType.Map => EtfTokenType.StartMap, TermType.List => EtfTokenType.StartList, From 201c386140c053ef85e05fef6eea8b4e5b5db08e Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Thu, 14 Sep 2023 16:34:24 +0200 Subject: [PATCH 099/323] mark enums as flags, dispose JsonDocuments --- Directory.Build.props | 2 +- Directory.Packages.props | 6 ++--- .../AuditLogs/IAuditLogChange.cs | 6 ++--- ...DSharpPlus.Core.Abstractions.Models.csproj | 2 ++ .../AuditLogs/AuditLogChange.cs | 6 ++--- .../Converters/AuditLogChangeConverter.cs | 22 ++++++++++--------- .../AutoModerationActionConverter.cs | 4 +++- .../Converters/DiscordPermissionConverter.cs | 3 ++- .../Converters/MessageComponentConverter.cs | 7 +++--- .../DSharpPlus.Core.Models.csproj | 2 ++ .../DSharpPlus.Shared.csproj | 1 + .../Applications/DiscordApplicationFlags.cs | 3 +++ .../Entities/Channels/DiscordMessageType.cs | 2 ++ .../Guilds/DiscordSystemChannelFlags.cs | 3 +++ 14 files changed, 42 insertions(+), 27 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index b837b69c1f..8dc6a12a5e 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -8,7 +8,7 @@ True True All - $(NoWarn);CS1591;CA1028;CA1720;CA2007 + $(NoWarn);CS1591;CA1028;CA1062;CA1711;CA1716;CA1720;CA2007 True diff --git a/Directory.Packages.props b/Directory.Packages.props index b96ba0779a..de17aa0926 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -4,13 +4,13 @@ - + - + - + diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/AuditLogs/IAuditLogChange.cs b/src/core/DSharpPlus.Core.Abstractions.Models/AuditLogs/IAuditLogChange.cs index e8b41d3946..101c6201a8 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/AuditLogs/IAuditLogChange.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/AuditLogs/IAuditLogChange.cs @@ -2,8 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using System.Text.Json; - using Remora.Rest.Core; namespace DSharpPlus.Core.Abstractions.Models; @@ -16,12 +14,12 @@ public interface IAuditLogChange /// /// The new value of this field. /// - public Optional NewValue { get; } + public Optional NewValue { get; } /// /// The old value of this field. /// - public Optional OldValue { get; } + public Optional OldValue { get; } /// /// The name of the changed field, with a few exceptions: see diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/DSharpPlus.Core.Abstractions.Models.csproj b/src/core/DSharpPlus.Core.Abstractions.Models/DSharpPlus.Core.Abstractions.Models.csproj index cf8ef52bde..17f901fa6b 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/DSharpPlus.Core.Abstractions.Models.csproj +++ b/src/core/DSharpPlus.Core.Abstractions.Models/DSharpPlus.Core.Abstractions.Models.csproj @@ -4,6 +4,8 @@ $(_DSharpPlusCoreAbstractionsModelsVersion) $(Description) This package specifies a contract for the serialization models to implement. This definition is library-agnostic. Library + + $(NoWarn);CA1040;CA1056 diff --git a/src/core/DSharpPlus.Core.Models/AuditLogs/AuditLogChange.cs b/src/core/DSharpPlus.Core.Models/AuditLogs/AuditLogChange.cs index 65d8c4462b..0f804c4cd9 100644 --- a/src/core/DSharpPlus.Core.Models/AuditLogs/AuditLogChange.cs +++ b/src/core/DSharpPlus.Core.Models/AuditLogs/AuditLogChange.cs @@ -2,8 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using System.Text.Json; - using Remora.Rest.Core; using DSharpPlus.Core.Abstractions.Models; @@ -14,10 +12,10 @@ namespace DSharpPlus.Core.Models; public sealed record AuditLogChange : IAuditLogChange { /// - public Optional NewValue { get; init; } + public Optional NewValue { get; init; } /// - public Optional OldValue { get; init; } + public Optional OldValue { get; init; } /// public required string Key { get; init; } diff --git a/src/core/DSharpPlus.Core.Models/Converters/AuditLogChangeConverter.cs b/src/core/DSharpPlus.Core.Models/Converters/AuditLogChangeConverter.cs index 06c0b9ef1f..7c0e04efcc 100644 --- a/src/core/DSharpPlus.Core.Models/Converters/AuditLogChangeConverter.cs +++ b/src/core/DSharpPlus.Core.Models/Converters/AuditLogChangeConverter.cs @@ -41,13 +41,15 @@ JsonSerializerOptions options string key = propertyKey.GetString()!; - Optional newProperty = document.RootElement.TryGetProperty("new_value", out JsonElement value) - ? value - : new Optional(); + Optional newProperty = document.RootElement.TryGetProperty("new_value", out JsonElement value) + ? JsonSerializer.Serialize(value, options) + : new Optional(); - Optional oldProperty = document.RootElement.TryGetProperty("old_value", out JsonElement oldValue) - ? oldValue - : new Optional(); + Optional oldProperty = document.RootElement.TryGetProperty("old_value", out JsonElement oldValue) + ? JsonSerializer.Serialize(oldValue, options) + : new Optional(); + + document.Dispose(); return new AuditLogChange { @@ -70,16 +72,16 @@ JsonSerializerOptions options writer.WritePropertyName("key"); writer.WriteStringValue(value.Key); - if (value.NewValue.TryGet(out JsonElement newValue)) + if (value.NewValue.TryGet(out string? newValue)) { writer.WritePropertyName("new_value"); - newValue.WriteTo(writer); + writer.WriteStringValue(newValue); } - if (value.OldValue.TryGet(out JsonElement oldValue)) + if (value.OldValue.TryGet(out string? oldValue)) { writer.WritePropertyName("old_value"); - oldValue.WriteTo(writer); + writer.WriteStringValue(oldValue); } writer.WriteEndObject(); diff --git a/src/core/DSharpPlus.Core.Models/Converters/AutoModerationActionConverter.cs b/src/core/DSharpPlus.Core.Models/Converters/AutoModerationActionConverter.cs index 96407177c9..31cab897fc 100644 --- a/src/core/DSharpPlus.Core.Models/Converters/AutoModerationActionConverter.cs +++ b/src/core/DSharpPlus.Core.Models/Converters/AutoModerationActionConverter.cs @@ -53,6 +53,8 @@ JsonSerializerOptions options _ => new() }; + document.Dispose(); + return new AutoModerationAction { Type = (DiscordAutoModerationActionType)type, @@ -73,7 +75,7 @@ JsonSerializerOptions options writer.WritePropertyName("type"); writer.WriteNumberValue((int)value.Type); - if (!value.Metadata.IsDefined(out IAutoModerationActionMetadata? metadata)) + if (!value.Metadata.TryGet(out IAutoModerationActionMetadata? metadata)) { writer.WriteEndObject(); return; diff --git a/src/core/DSharpPlus.Core.Models/Converters/DiscordPermissionConverter.cs b/src/core/DSharpPlus.Core.Models/Converters/DiscordPermissionConverter.cs index a97918938b..7fe6172e8e 100644 --- a/src/core/DSharpPlus.Core.Models/Converters/DiscordPermissionConverter.cs +++ b/src/core/DSharpPlus.Core.Models/Converters/DiscordPermissionConverter.cs @@ -3,6 +3,7 @@ // file, You can obtain one at https://mozilla.org/MPL/2.0/. using System; +using System.Globalization; using System.Text.Json; using System.Text.Json.Serialization; @@ -42,5 +43,5 @@ public override void Write DiscordPermissions value, JsonSerializerOptions options ) - => writer.WriteStringValue(((ulong)value).ToString()); + => writer.WriteStringValue(((ulong)value).ToString(CultureInfo.InvariantCulture)); } diff --git a/src/core/DSharpPlus.Core.Models/Converters/MessageComponentConverter.cs b/src/core/DSharpPlus.Core.Models/Converters/MessageComponentConverter.cs index 140f61b572..a98115aeae 100644 --- a/src/core/DSharpPlus.Core.Models/Converters/MessageComponentConverter.cs +++ b/src/core/DSharpPlus.Core.Models/Converters/MessageComponentConverter.cs @@ -29,7 +29,6 @@ JsonSerializerOptions options throw new JsonException("There was no JSON object found."); } -#pragma warning disable IDE0046 // we don't want this to become a 40 line ternary. if ( !JsonDocument.TryParseValue(ref reader, out JsonDocument? document) @@ -40,7 +39,7 @@ JsonSerializerOptions options throw new JsonException("The provided JSON object was malformed."); } - return (DiscordMessageComponentType)type switch + IInteractiveComponent? component = (DiscordMessageComponentType)type switch { DiscordMessageComponentType.ActionRow => throw new JsonException("Invalid JSON structure: expected an interactive component, not an action row."), @@ -68,7 +67,9 @@ JsonSerializerOptions options _ => throw new JsonException("Unknown component type.") }; -#pragma warning restore IDE0046 + + document.Dispose(); + return component; } /// diff --git a/src/core/DSharpPlus.Core.Models/DSharpPlus.Core.Models.csproj b/src/core/DSharpPlus.Core.Models/DSharpPlus.Core.Models.csproj index 8c0b6b256e..9ce3fca012 100644 --- a/src/core/DSharpPlus.Core.Models/DSharpPlus.Core.Models.csproj +++ b/src/core/DSharpPlus.Core.Models/DSharpPlus.Core.Models.csproj @@ -4,6 +4,8 @@ 0.1.0 $(Description) This package implements the serialization models mirroring the Discord API. Library + + $(NoWarn);CA1812 diff --git a/src/core/DSharpPlus.Shared/DSharpPlus.Shared.csproj b/src/core/DSharpPlus.Shared/DSharpPlus.Shared.csproj index da1f99d6cc..8977420281 100644 --- a/src/core/DSharpPlus.Shared/DSharpPlus.Shared.csproj +++ b/src/core/DSharpPlus.Shared/DSharpPlus.Shared.csproj @@ -6,6 +6,7 @@ Library true true + $(NoWarn);CA1008 DSharpPlus diff --git a/src/core/DSharpPlus.Shared/Entities/Applications/DiscordApplicationFlags.cs b/src/core/DSharpPlus.Shared/Entities/Applications/DiscordApplicationFlags.cs index 594fef888e..351f5eaa4f 100644 --- a/src/core/DSharpPlus.Shared/Entities/Applications/DiscordApplicationFlags.cs +++ b/src/core/DSharpPlus.Shared/Entities/Applications/DiscordApplicationFlags.cs @@ -2,11 +2,14 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +using System; + namespace DSharpPlus.Entities; /// /// Enumerates flags for applications and thereby bots. /// +[Flags] public enum DiscordApplicationFlags { /// diff --git a/src/core/DSharpPlus.Shared/Entities/Channels/DiscordMessageType.cs b/src/core/DSharpPlus.Shared/Entities/Channels/DiscordMessageType.cs index 80e025c804..c291911227 100644 --- a/src/core/DSharpPlus.Shared/Entities/Channels/DiscordMessageType.cs +++ b/src/core/DSharpPlus.Shared/Entities/Channels/DiscordMessageType.cs @@ -4,7 +4,9 @@ namespace DSharpPlus.Entities; +#pragma warning disable CA1027 // this is not a flags enum. public enum DiscordMessageType +#pragma warning restore CA1027 { Default, RecipientAdd, diff --git a/src/core/DSharpPlus.Shared/Entities/Guilds/DiscordSystemChannelFlags.cs b/src/core/DSharpPlus.Shared/Entities/Guilds/DiscordSystemChannelFlags.cs index d79b1414a1..b8667afa7b 100644 --- a/src/core/DSharpPlus.Shared/Entities/Guilds/DiscordSystemChannelFlags.cs +++ b/src/core/DSharpPlus.Shared/Entities/Guilds/DiscordSystemChannelFlags.cs @@ -2,11 +2,14 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +using System; + namespace DSharpPlus.Entities; /// /// Represents additional settings for system channels. /// +[Flags] public enum DiscordSystemChannelFlags { None = 0, From b5a60b02a1f7a949466659acbe6c0d0eb6340fbd Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Thu, 14 Sep 2023 16:39:28 +0200 Subject: [PATCH 100/323] it would appear that i missed an exclamation mark --- .../Converters/AuditLogChangeConverter.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/DSharpPlus.Core.Models/Converters/AuditLogChangeConverter.cs b/src/core/DSharpPlus.Core.Models/Converters/AuditLogChangeConverter.cs index 7c0e04efcc..421db05575 100644 --- a/src/core/DSharpPlus.Core.Models/Converters/AuditLogChangeConverter.cs +++ b/src/core/DSharpPlus.Core.Models/Converters/AuditLogChangeConverter.cs @@ -33,7 +33,7 @@ JsonSerializerOptions options if ( !JsonDocument.TryParseValue(ref reader, out JsonDocument? document) - || document.RootElement.TryGetProperty("key", out JsonElement propertyKey) + || !document.RootElement.TryGetProperty("key", out JsonElement propertyKey) ) { throw new JsonException("The provided JSON object was malformed."); From f7217157d58226df3ec7aa0897d0be9c0e23c0a9 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Thu, 14 Sep 2023 16:45:51 +0200 Subject: [PATCH 101/323] add tests for the audit log change converter --- .../Converters/AuditLogChangeTests.cs | 108 ++++++++++++++++++ .../DSharpPlus.Core.Models.Tests.csproj | 26 +++++ 2 files changed, 134 insertions(+) create mode 100644 tests/core/DSharpPlus.Core.Models.Tests/Converters/AuditLogChangeTests.cs create mode 100644 tests/core/DSharpPlus.Core.Models.Tests/DSharpPlus.Core.Models.Tests.csproj diff --git a/tests/core/DSharpPlus.Core.Models.Tests/Converters/AuditLogChangeTests.cs b/tests/core/DSharpPlus.Core.Models.Tests/Converters/AuditLogChangeTests.cs new file mode 100644 index 0000000000..d3a172a310 --- /dev/null +++ b/tests/core/DSharpPlus.Core.Models.Tests/Converters/AuditLogChangeTests.cs @@ -0,0 +1,108 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; +using System.Text.Json; + +using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Core.Models.Extensions; + +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Options; + +using Xunit; + +namespace DSharpPlus.Core.Models.Tests.Converters; + +public class AuditLogChangeTests +{ + private readonly JsonSerializerOptions options; + + public AuditLogChangeTests() + { + IServiceCollection services = new ServiceCollection(); + services.RegisterDiscordModelSerialization(); + + IServiceProvider provider = services.BuildServiceProvider(); + this.options = provider.GetRequiredService>().Get("DSharpPlus"); + } + + private const string IntPayload = + """ + { + "key": "$test", + "new_value": 17, + "old_value": 83 + } + """; + + private const string StringPayload = + """ + { + "key": "$test", + "new_value": "this is the new value", + "old_value": "this was the old value" + } + """; + + private const string NewValueMissingPayload = + """ + { + "key": "$test", + "old_value": "this was the old value" + } + """; + + private const string OldValueMissingPayload = + """ + { + "key": "$test", + "new_value": "this is the new value" + } + """; + + [Fact] + public void TestIntegerPayload() + { + IAuditLogChange change = JsonSerializer.Deserialize(IntPayload, this.options)!; + + Assert.True(change.NewValue.HasValue); + Assert.True(change.OldValue.HasValue); + + Assert.Equal("17", change.NewValue.Value); + } + + [Fact] + public void TestStringPayload() + { + IAuditLogChange change = JsonSerializer.Deserialize(StringPayload, this.options)!; + + Assert.True(change.NewValue.HasValue); + Assert.True(change.OldValue.HasValue); + + Assert.Equal("\"this was the old value\"", change.OldValue.Value); + } + + [Fact] + public void TestNewValueMissing() + { + IAuditLogChange change = JsonSerializer.Deserialize(NewValueMissingPayload, this.options)!; + + Assert.False(change.NewValue.HasValue); + Assert.True(change.OldValue.HasValue); + + Assert.Equal("\"this was the old value\"", change.OldValue.Value); + } + + [Fact] + public void TestOldValueMissing() + { + IAuditLogChange change = JsonSerializer.Deserialize(OldValueMissingPayload, this.options)!; + + Assert.True(change.NewValue.HasValue); + Assert.False(change.OldValue.HasValue); + + Assert.Equal("\"this is the new value\"", change.NewValue.Value); + } +} diff --git a/tests/core/DSharpPlus.Core.Models.Tests/DSharpPlus.Core.Models.Tests.csproj b/tests/core/DSharpPlus.Core.Models.Tests/DSharpPlus.Core.Models.Tests.csproj new file mode 100644 index 0000000000..57aed8b89a --- /dev/null +++ b/tests/core/DSharpPlus.Core.Models.Tests/DSharpPlus.Core.Models.Tests.csproj @@ -0,0 +1,26 @@ + + + + net8.0 + enable + + false + true + + + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + + + + + From a5963ff892d2b3cc0efd7118b9a165d9d86e7cbf Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Thu, 14 Sep 2023 16:56:35 +0200 Subject: [PATCH 102/323] centralize versioning --- Directory.Build.props | 6 ++++++ .../DSharpPlus.Core.Models/DSharpPlus.Core.Models.csproj | 6 ++++-- src/etf/DSharpPlus.ETF/DSharpPlus.ETF.csproj | 1 + 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index 8dc6a12a5e..1336ad6393 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -44,6 +44,12 @@ <_DSharpPlusCoreAbstractionsModelsVersion>0.1.0 + + + <_DSharpPlusCoreModelsVersion>0.1.0 + + + <_DSharpPlusEtfVersion>0.1.0 \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/DSharpPlus.Core.Models.csproj b/src/core/DSharpPlus.Core.Models/DSharpPlus.Core.Models.csproj index 9ce3fca012..f71b43ad75 100644 --- a/src/core/DSharpPlus.Core.Models/DSharpPlus.Core.Models.csproj +++ b/src/core/DSharpPlus.Core.Models/DSharpPlus.Core.Models.csproj @@ -1,7 +1,7 @@  - 0.1.0 + $(_DSharpPlusCoreModelsVersion) $(Description) This package implements the serialization models mirroring the Discord API. Library @@ -15,7 +15,9 @@ - + diff --git a/src/etf/DSharpPlus.ETF/DSharpPlus.ETF.csproj b/src/etf/DSharpPlus.ETF/DSharpPlus.ETF.csproj index e4e8726228..4022bc2e06 100644 --- a/src/etf/DSharpPlus.ETF/DSharpPlus.ETF.csproj +++ b/src/etf/DSharpPlus.ETF/DSharpPlus.ETF.csproj @@ -2,6 +2,7 @@ true + $(_DSharpPlusEtfVersion) From e1287c6ad9c3bc49c083342c563becaacc1ea4e5 Mon Sep 17 00:00:00 2001 From: Livia Silvercrown <61018569+akiraveliara@users.noreply.github.com> Date: Fri, 15 Sep 2023 13:03:58 +0200 Subject: [PATCH 103/323] fix capitalization on unix --- .../DSharpPlus.Etf.csproj} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/etf/{DSharpPlus.ETF/DSharpPlus.ETF.csproj => DSharpPlus.Etf/DSharpPlus.Etf.csproj} (100%) diff --git a/src/etf/DSharpPlus.ETF/DSharpPlus.ETF.csproj b/src/etf/DSharpPlus.Etf/DSharpPlus.Etf.csproj similarity index 100% rename from src/etf/DSharpPlus.ETF/DSharpPlus.ETF.csproj rename to src/etf/DSharpPlus.Etf/DSharpPlus.Etf.csproj From 3d353484ea7214d05d595cae47a6494ffc39b108 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Mon, 18 Sep 2023 21:35:53 +0200 Subject: [PATCH 104/323] cursed:tm: biginteger handling for small values --- .../Extensions/TermTypeExtensions.cs | 48 +++++ .../Serialization/EtfReader.Integers.cs | 177 ++++++++++++++++++ .../Serialization/ThrowHelper.cs | 24 +++ 3 files changed, 249 insertions(+) create mode 100644 src/etf/DSharpPlus.Etf/Extensions/TermTypeExtensions.cs create mode 100644 src/etf/DSharpPlus.Etf/Serialization/EtfReader.Integers.cs create mode 100644 src/etf/DSharpPlus.Etf/Serialization/ThrowHelper.cs diff --git a/src/etf/DSharpPlus.Etf/Extensions/TermTypeExtensions.cs b/src/etf/DSharpPlus.Etf/Extensions/TermTypeExtensions.cs new file mode 100644 index 0000000000..05719cdd5d --- /dev/null +++ b/src/etf/DSharpPlus.Etf/Extensions/TermTypeExtensions.cs @@ -0,0 +1,48 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Etf.Extensions; + +/// +/// Contains extensions on to reason about the .NET representation +/// of a given term. +/// +public static class TermTypeExtensions +{ + /// + /// Determines whether this term can be represented in .NET as a string. + /// + public static bool IsString + ( + this TermType term + ) + => term is TermType.AtomUtf8 or TermType.SmallAtomUtf8 or TermType.String; + + /// + /// Determines whether this term can be represented in .NET as an int or higher. + /// + public static bool IsInteger + ( + this TermType term + ) + => term is TermType.SmallInteger or TermType.Integer; + + /// + /// Determines whether this term can be represented in .NET as a BigInteger. + /// + public static bool IsBigInteger + ( + this TermType term + ) + => term is TermType.SmallBig or TermType.LargeBig or TermType.SmallInteger or TermType.Integer; + + /// + /// Determines whether this term is a tuple. + /// + public static bool IsTuple + ( + this TermType term + ) + => term is TermType.SmallTuple or TermType.LargeTuple; +} diff --git a/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Integers.cs b/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Integers.cs new file mode 100644 index 0000000000..38f2b14eb2 --- /dev/null +++ b/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Integers.cs @@ -0,0 +1,177 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Numerics; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +namespace DSharpPlus.Etf.Serialization; + +/******************************************************************************************************* +* here, we deal with parsing the ETF representation of integers into something .NET can use. +* +* in general, we want to offer methods to convert terms to all sane .NET representations, both in Try- +* and throwing variants; and for integers specifically we want to both offer truncating and checked +* methods for slimming an integer down. +* +* We want to define our Try- methods first and then implement throwing variants in the following form: +* +* public readonly Thing GetThing() +* { +* if (this.TryGetThing(out Thing thing)) +* { +* return thing; +* } +* +* ThrowHelper.ThrowInvalidDecode(typeof(Thing)); +* return default!; +* } +* +* the last return doesn't actually matter, it is never invoked, roslyn just doesn't see through +* ThrowHelper calls always throwing and thinks this code is reachable. +*******************************************************************************************************/ + +partial struct EtfReader +{ + /// + /// Provides the implementation for reading either a or a + /// into a BigInteger. + /// + private readonly BigInteger ReadBigIntegerCore() + { + BigInteger value = new(this.CurrentTermContents[1..]); + + return MemoryMarshal.GetReference(this.CurrentTermContents) == 0 ? value : -value; + } + + /// + /// Provides the implementation for reading a 64-bit unsigned integer from a currently provided + /// BigInteger term, ignoring the sign byte. + /// + private readonly ulong ReadUInt64FromBigInteger() + { + return Unsafe.ReadUnaligned + ( + ref Unsafe.Add + ( + ref MemoryMarshal.GetReference(this.CurrentTermContents), + elementOffset: 1 + ) + ); + } + + /// + /// Provides the implementation for reading a 64-bit signed integer from a currently provided + /// BigInteger term. + /// + private readonly long ReadInt64FromBigInteger() + { + long value = Unsafe.ReadUnaligned + ( + ref Unsafe.Add + ( + ref MemoryMarshal.GetReference(this.CurrentTermContents), + elementOffset: 1 + ) + ); + + return MemoryMarshal.GetReference(this.CurrentTermContents) == 0 ? value : -value; + } + + /// + /// Provides the implementation for reading a 32-bit unsigned integer from a currently provided + /// BigInteger term, ignoring the sign byte. + /// + private readonly uint ReadUInt32FromBigInteger() + { + return Unsafe.ReadUnaligned + ( + ref Unsafe.Add + ( + ref MemoryMarshal.GetReference(this.CurrentTermContents), + elementOffset: 1 + ) + ); + } + + /// + /// Provides the implementation for reading a 32-bit signed integer from a currently provided + /// BigInteger term. + /// + private readonly int ReadInt32FromBigInteger() + { + int value = Unsafe.ReadUnaligned + ( + ref Unsafe.Add + ( + ref MemoryMarshal.GetReference(this.CurrentTermContents), + elementOffset: 1 + ) + ); + + return MemoryMarshal.GetReference(this.CurrentTermContents) == 0 ? value : -value; + } + + /// + /// Provides the implementation for reading a 16-bit unsigned integer from a currently provided + /// BigInteger term, ignoring the sign byte. + /// + private readonly ushort ReadUInt16FromBigInteger() + { + return Unsafe.ReadUnaligned + ( + ref Unsafe.Add + ( + ref MemoryMarshal.GetReference(this.CurrentTermContents), + elementOffset: 1 + ) + ); + } + + /// + /// Provides the implementation for reading a 16-bit signed integer from a currently provided + /// BigInteger term. + /// + private readonly short ReadInt16FromBigInteger() + { + short value = Unsafe.ReadUnaligned + ( + ref Unsafe.Add + ( + ref MemoryMarshal.GetReference(this.CurrentTermContents), + elementOffset: 1 + ) + ); + + return MemoryMarshal.GetReference(this.CurrentTermContents) == 0 ? value : (short)-value; + } + + /// + /// Provides the implementation for reading an 8-bit unsigned integer from a currently provided + /// BigInteger term, ignoring the sign byte. + /// + private readonly byte ReadByteFromBigInteger() + { + return Unsafe.Add + ( + ref MemoryMarshal.GetReference(this.CurrentTermContents), + elementOffset: 1 + ); + } + + /// + /// Provides the implementation for reading an 8-bit signed integer from a currently provided + /// BigInteger term. + /// + private readonly sbyte ReadSByteFromBigInteger() + { + sbyte value = (sbyte)Unsafe.Add + ( + ref MemoryMarshal.GetReference(this.CurrentTermContents), + elementOffset: 1 + ); + + return MemoryMarshal.GetReference(this.CurrentTermContents) == 0 ? value : (sbyte)-value; + } +} diff --git a/src/etf/DSharpPlus.Etf/Serialization/ThrowHelper.cs b/src/etf/DSharpPlus.Etf/Serialization/ThrowHelper.cs new file mode 100644 index 0000000000..fafe462a66 --- /dev/null +++ b/src/etf/DSharpPlus.Etf/Serialization/ThrowHelper.cs @@ -0,0 +1,24 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; +using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; + +namespace DSharpPlus.Etf.Serialization; + +/// +/// Provides methods to relegate s to, to work around inlining limitations in the JIT. +/// +internal static class ThrowHelper +{ + [DoesNotReturn] + [DebuggerHidden] + [StackTraceHidden] + public static void ThrowInvalidDecode + ( + Type target + ) + => throw new InvalidOperationException($"Failed to decode the current term into an object of type {target}."); +} From c1c1aa3e5b82083896d1f6dc3a39198c2a9ecc67 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Tue, 19 Sep 2023 20:12:06 +0200 Subject: [PATCH 105/323] fix some edge cases and use generic math --- .../Serialization/EtfReader.Integers.cs | 183 ++++++++---------- 1 file changed, 84 insertions(+), 99 deletions(-) diff --git a/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Integers.cs b/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Integers.cs index 38f2b14eb2..11a1e948c4 100644 --- a/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Integers.cs +++ b/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Integers.cs @@ -45,13 +45,91 @@ private readonly BigInteger ReadBigIntegerCore() return MemoryMarshal.GetReference(this.CurrentTermContents) == 0 ? value : -value; } + /*************************************************************************************************** + * in the following section, we deal with handling BigInteger terms into primitive .NET + * representations. this is implemented using two very safe generic math methods that totally + * abstain from all cursed-ness... + * + * big integers are LITTLE ENDIAN, as opposed to everything else in the entire format, and we will + * make use of that. this code is written under the (reasonable) assumption that big endian machines + * are dead and that it will only run on little endian systems. + * + * there are rationales for all decisions, however scuffed they might look: + * + * 1. by using Unsafe.Add we elide a slice; and the following code is illegal under current ref + * safety rules, so we can't simplify it: + * TNumber value = Unsafe.ReadUnaligned(ref this.CurrentTermContents[1]); + * + * 2. using Unsafe.ReadUnaligned over TNumber.ReadLittleEndian is done for the same reason: + * avoiding the slice associated with starting at byte 1 rather than byte 0 + * + * 3. in the signed implementation we use MemoryMarshal.GetReference(this.CurrentTermContents) over + * just this.CurrentTermContents[0], which elides a range check that at this point we know to be + * unnecessary but that still poses a branch the branch predictor has to deal with. oddly, + * removing that branch also causes the JIT to optimize the ternary operator to a conditional + * move, which actually makes this code entirely branchless. + * + **************************************************************************************************** + * + * one note for the following section: the exact registers and moves may differ; the assembly here + * is taken from an (U)Int64 implementation + * + **************************************************************************************************** + * + * on x86, the emitted assembly output should look as follows for unsigned methods: + * + * mov rax, bword ptr [rcx+0x40] | load the length of the current term as the reference passed + * | to Unsafe.Add + * ------------------------------|------------------------------------------------------------------- + * mov rax, qword ptr [rax+0x01] | implicitly add and load the value at this address into rax, the + * | return register + * + **************************************************************************************************** + * + * and for signed methods: + * + * mov rax, bword ptr [rcx+0x40] | load the length of the current term as the reference passed + * | to Unsafe.Add, but also as the reference we will use later to + * | determine the sign + * ------------------------------|------------------------------------------------------------------- + * mov rcx, rax | move our work to rcx (or just any register that's currently + * | free, it doesn't really matter) to keep the reference in rax + * | intact + * ------------------------------|------------------------------------------------------------------- + * mov rdx, 0x7FFFFFFFFFFFFFFF | set the maximum value up to ensure we don't break if the sign + * | bit is already set + * ------------------------------|------------------------------------------------------------------- + * and rdx, qword ptr [rcx+0x01] | implicitly and and load the integer into rdx, the address + * | incremented as Unsafe.Add instructed it to + * ------------------------------|------------------------------------------------------------------- + * mov rcx, rdx | copy the value into rcx to work there + * ------------------------------|------------------------------------------------------------------- + * neg rcx | negate the value in rcx, effectively `rcx = -rcx`. the JIT thinks + * | rightly that it is faster to always negate than to take the + * | branch, which hurts us by even existing + * ------------------------------|------------------------------------------------------------------- + * cmp byte ptr [rax], 0 | see whether the sign byte, with the reference stored in rax from + * | the very beginning, equals zero + * ------------------------------|------------------------------------------------------------------- + * mov rax, rcx | move the negated value into rax to set up for evaluating the + * | condition + * ------------------------------|------------------------------------------------------------------- + * cmove rax, rdx | if the sign byte from earlier was zero, move the positive value + * | into rax, if not, keep the negative value + * + * if the JIT insists on changing cmp byte ptr [rax], 0 to test byte ptr [rax], that's fine, any + * other changes should absolutely be analyzed for performance. + * + ***************************************************************************************************/ + /// /// Provides the implementation for reading a 64-bit unsigned integer from a currently provided /// BigInteger term, ignoring the sign byte. /// - private readonly ulong ReadUInt64FromBigInteger() + private readonly TNumber ReadUnsignedIntegerFromBigInteger() + where TNumber : IUnsignedNumber, IBinaryInteger { - return Unsafe.ReadUnaligned + return Unsafe.ReadUnaligned ( ref Unsafe.Add ( @@ -65,27 +143,10 @@ ref MemoryMarshal.GetReference(this.CurrentTermContents), /// Provides the implementation for reading a 64-bit signed integer from a currently provided /// BigInteger term. /// - private readonly long ReadInt64FromBigInteger() - { - long value = Unsafe.ReadUnaligned - ( - ref Unsafe.Add - ( - ref MemoryMarshal.GetReference(this.CurrentTermContents), - elementOffset: 1 - ) - ); - - return MemoryMarshal.GetReference(this.CurrentTermContents) == 0 ? value : -value; - } - - /// - /// Provides the implementation for reading a 32-bit unsigned integer from a currently provided - /// BigInteger term, ignoring the sign byte. - /// - private readonly uint ReadUInt32FromBigInteger() + private readonly TNumber ReadSignedIntegerFromBigInteger() + where TNumber : IBinaryInteger, IMinMaxValue, ISignedNumber { - return Unsafe.ReadUnaligned + TNumber value = Unsafe.ReadUnaligned ( ref Unsafe.Add ( @@ -93,85 +154,9 @@ ref MemoryMarshal.GetReference(this.CurrentTermContents), elementOffset: 1 ) ); - } - /// - /// Provides the implementation for reading a 32-bit signed integer from a currently provided - /// BigInteger term. - /// - private readonly int ReadInt32FromBigInteger() - { - int value = Unsafe.ReadUnaligned - ( - ref Unsafe.Add - ( - ref MemoryMarshal.GetReference(this.CurrentTermContents), - elementOffset: 1 - ) - ); + value &= TNumber.MaxValue; return MemoryMarshal.GetReference(this.CurrentTermContents) == 0 ? value : -value; } - - /// - /// Provides the implementation for reading a 16-bit unsigned integer from a currently provided - /// BigInteger term, ignoring the sign byte. - /// - private readonly ushort ReadUInt16FromBigInteger() - { - return Unsafe.ReadUnaligned - ( - ref Unsafe.Add - ( - ref MemoryMarshal.GetReference(this.CurrentTermContents), - elementOffset: 1 - ) - ); - } - - /// - /// Provides the implementation for reading a 16-bit signed integer from a currently provided - /// BigInteger term. - /// - private readonly short ReadInt16FromBigInteger() - { - short value = Unsafe.ReadUnaligned - ( - ref Unsafe.Add - ( - ref MemoryMarshal.GetReference(this.CurrentTermContents), - elementOffset: 1 - ) - ); - - return MemoryMarshal.GetReference(this.CurrentTermContents) == 0 ? value : (short)-value; - } - - /// - /// Provides the implementation for reading an 8-bit unsigned integer from a currently provided - /// BigInteger term, ignoring the sign byte. - /// - private readonly byte ReadByteFromBigInteger() - { - return Unsafe.Add - ( - ref MemoryMarshal.GetReference(this.CurrentTermContents), - elementOffset: 1 - ); - } - - /// - /// Provides the implementation for reading an 8-bit signed integer from a currently provided - /// BigInteger term. - /// - private readonly sbyte ReadSByteFromBigInteger() - { - sbyte value = (sbyte)Unsafe.Add - ( - ref MemoryMarshal.GetReference(this.CurrentTermContents), - elementOffset: 1 - ); - - return MemoryMarshal.GetReference(this.CurrentTermContents) == 0 ? value : (sbyte)-value; - } } From 8936f6825e90ac3a8ad55f40a7f496a1038380a2 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Tue, 19 Sep 2023 20:18:29 +0200 Subject: [PATCH 106/323] make TermTypeExtensions not suck --- .../Extensions/TermTypeExtensions.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/etf/DSharpPlus.Etf/Extensions/TermTypeExtensions.cs b/src/etf/DSharpPlus.Etf/Extensions/TermTypeExtensions.cs index 05719cdd5d..389ec2ad41 100644 --- a/src/etf/DSharpPlus.Etf/Extensions/TermTypeExtensions.cs +++ b/src/etf/DSharpPlus.Etf/Extensions/TermTypeExtensions.cs @@ -20,29 +20,29 @@ this TermType term => term is TermType.AtomUtf8 or TermType.SmallAtomUtf8 or TermType.String; /// - /// Determines whether this term can be represented in .NET as an int or higher. + /// Determines whether this term is an integer. /// public static bool IsInteger ( this TermType term ) - => term is TermType.SmallInteger or TermType.Integer; + => term is TermType.SmallBig or TermType.LargeBig or TermType.SmallInteger or TermType.Integer; /// - /// Determines whether this term can be represented in .NET as a BigInteger. + /// Determines whether this term is a tuple. /// - public static bool IsBigInteger + public static bool IsTuple ( this TermType term ) - => term is TermType.SmallBig or TermType.LargeBig or TermType.SmallInteger or TermType.Integer; + => term is TermType.SmallTuple or TermType.LargeTuple; /// - /// Determines whether this term is a tuple. + /// Determines whether this term is a float. /// - public static bool IsTuple + public static bool IsFloat ( this TermType term ) - => term is TermType.SmallTuple or TermType.LargeTuple; + => term is TermType.Float or TermType.NewFloat; } From bf17a08fec7c39449eec763982d4e3af0cf631a6 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Tue, 19 Sep 2023 20:43:57 +0200 Subject: [PATCH 107/323] support reading from actual integer terms --- .../Serialization/EtfReader.Integers.cs | 59 ++++++++++++++++++- 1 file changed, 57 insertions(+), 2 deletions(-) diff --git a/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Integers.cs b/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Integers.cs index 11a1e948c4..9827ccbddd 100644 --- a/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Integers.cs +++ b/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Integers.cs @@ -2,6 +2,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +using System.Buffers.Binary; using System.Numerics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -123,7 +124,7 @@ private readonly BigInteger ReadBigIntegerCore() ***************************************************************************************************/ /// - /// Provides the implementation for reading a 64-bit unsigned integer from a currently provided + /// Provides the implementation for reading a unsigned integer from a currently provided /// BigInteger term, ignoring the sign byte. /// private readonly TNumber ReadUnsignedIntegerFromBigInteger() @@ -140,7 +141,7 @@ ref MemoryMarshal.GetReference(this.CurrentTermContents), } /// - /// Provides the implementation for reading a 64-bit signed integer from a currently provided + /// Provides the implementation for reading a signed integer from a currently provided /// BigInteger term. /// private readonly TNumber ReadSignedIntegerFromBigInteger() @@ -159,4 +160,58 @@ ref MemoryMarshal.GetReference(this.CurrentTermContents), return MemoryMarshal.GetReference(this.CurrentTermContents) == 0 ? value : -value; } + + /// + /// Provides the implementation for performing a truncating read from an integer term. + /// + private readonly TNumber ReadFromIntegerTruncating() + where TNumber : IBinaryInteger + { + int value = BinaryPrimitives.ReadInt32BigEndian(this.CurrentTermContents); + + return TNumber.CreateTruncating(value); + } + + /// + /// Provides the implementation for performing a saturating read from an integer term. + /// + private readonly TNumber ReadFromIntegerSaturating() + where TNumber : IBinaryInteger + { + int value = BinaryPrimitives.ReadInt32BigEndian(this.CurrentTermContents); + + return TNumber.CreateSaturating(value); + } + + /// + /// Provides the implementation for performing a checked read from an integer term. + /// + private readonly TNumber ReadFromIntegerChecked() + where TNumber : IBinaryInteger + { + int value = BinaryPrimitives.ReadInt32BigEndian(this.CurrentTermContents); + + return TNumber.CreateChecked(value); + } + + /// + /// Provides the implementation for performing a truncating read from a small-integer term. + /// + private readonly TNumber ReadFromByteTruncating() + where TNumber : IBinaryInteger + => TNumber.CreateTruncating(MemoryMarshal.GetReference(this.CurrentTermContents)); + + /// + /// Provides the implementation for performing a saturating read from a small-integer term. + /// + private readonly TNumber ReadFromByteSaturating() + where TNumber : IBinaryInteger + => TNumber.CreateSaturating(MemoryMarshal.GetReference(this.CurrentTermContents)); + + /// + /// Provides the implementation for performing a checked read from a small-integer term. + /// + private readonly TNumber ReadFromByteChecked() + where TNumber : IBinaryInteger + => TNumber.CreateChecked(MemoryMarshal.GetReference(this.CurrentTermContents)); } From 5ded7740bc09eccf82e266fe956b20bae6274c60 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Tue, 19 Sep 2023 21:34:54 +0200 Subject: [PATCH 108/323] implement the public API for reading integers --- .../Extensions/TermTypeExtensions.cs | 9 + .../Serialization/EtfReader.Integers.cs | 412 ++++++++++++++++-- 2 files changed, 394 insertions(+), 27 deletions(-) diff --git a/src/etf/DSharpPlus.Etf/Extensions/TermTypeExtensions.cs b/src/etf/DSharpPlus.Etf/Extensions/TermTypeExtensions.cs index 389ec2ad41..bc5f72269c 100644 --- a/src/etf/DSharpPlus.Etf/Extensions/TermTypeExtensions.cs +++ b/src/etf/DSharpPlus.Etf/Extensions/TermTypeExtensions.cs @@ -28,6 +28,15 @@ this TermType term ) => term is TermType.SmallBig or TermType.LargeBig or TermType.SmallInteger or TermType.Integer; + /// + /// Determines whether this term is a big integer. + /// + public static bool IsBigInteger + ( + this TermType term + ) + => term is TermType.SmallBig or TermType.LargeBig; + /// /// Determines whether this term is a tuple. /// diff --git a/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Integers.cs b/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Integers.cs index 9827ccbddd..3223525208 100644 --- a/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Integers.cs +++ b/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Integers.cs @@ -7,6 +7,8 @@ using System.Runtime.CompilerServices; using System.Runtime.InteropServices; +using DSharpPlus.Etf.Extensions; + namespace DSharpPlus.Etf.Serialization; /******************************************************************************************************* @@ -18,9 +20,9 @@ namespace DSharpPlus.Etf.Serialization; * * We want to define our Try- methods first and then implement throwing variants in the following form: * -* public readonly Thing GetThing() +* public readonly Thing ReadThing() * { -* if (this.TryGetThing(out Thing thing)) +* if (this.TryReadThing(out Thing thing)) * { * return thing; * } @@ -161,57 +163,413 @@ ref MemoryMarshal.GetReference(this.CurrentTermContents), return MemoryMarshal.GetReference(this.CurrentTermContents) == 0 ? value : -value; } +#pragma warning disable CS8509 // switch expressions should handle every option; this one shouldn't + /// /// Provides the implementation for performing a truncating read from an integer term. /// - private readonly TNumber ReadFromIntegerTruncating() + private readonly TNumber ReadInteger() where TNumber : IBinaryInteger { - int value = BinaryPrimitives.ReadInt32BigEndian(this.CurrentTermContents); + return this.TermType switch + { + TermType.Integer => + TNumber.CreateTruncating(BinaryPrimitives.ReadInt32BigEndian(this.CurrentTermContents)), - return TNumber.CreateTruncating(value); + TermType.SmallInteger => + TNumber.CreateTruncating(MemoryMarshal.GetReference(this.CurrentTermContents)) + }; } +#pragma warning restore CS8509 + /// - /// Provides the implementation for performing a saturating read from an integer term. + /// Reads the current term as a signed byte. /// - private readonly TNumber ReadFromIntegerSaturating() - where TNumber : IBinaryInteger + /// True if successful, false if unsuccessful. + public readonly bool TryReadSByte + ( + out sbyte value + ) { - int value = BinaryPrimitives.ReadInt32BigEndian(this.CurrentTermContents); + if (this.TermType.IsInteger()) + { + if (this.TermType.IsBigInteger()) + { + if (this.CurrentTermContents.Length >= 2) + { + value = this.ReadSignedIntegerFromBigInteger(); + return true; + } + } + else + { + value = this.ReadInteger(); + return true; + } + } - return TNumber.CreateSaturating(value); + value = default; + return false; } /// - /// Provides the implementation for performing a checked read from an integer term. + /// Reads the current term as an unsigned byte. /// - private readonly TNumber ReadFromIntegerChecked() - where TNumber : IBinaryInteger + /// True if successful, false if unsuccessful. + public readonly bool TryReadByte + ( + out byte value + ) + { + if (this.TermType.IsInteger()) + { + if (this.TermType.IsBigInteger()) + { + if (this.CurrentTermContents.Length >= 2) + { + value = this.ReadUnsignedIntegerFromBigInteger(); + return true; + } + } + else + { + value = this.ReadInteger(); + return true; + } + } + + value = default; + return false; + } + + /// + /// Reads the current term as a short. + /// + /// True if successful, false if unsuccessful. + public readonly bool TryReadInt16 + ( + out short value + ) + { + if (this.TermType.IsInteger()) + { + if (this.TermType.IsBigInteger()) + { + if (this.CurrentTermContents.Length >= 3) + { + value = this.ReadSignedIntegerFromBigInteger(); + return true; + } + } + else + { + value = this.ReadInteger(); + return true; + } + } + + value = default; + return false; + } + + /// + /// Reads the current term as a ushort. + /// + /// True if successful, false if unsuccessful. + public readonly bool TryReadUInt16 + ( + out ushort value + ) + { + if (this.TermType.IsInteger()) + { + if (this.TermType.IsBigInteger()) + { + if (this.CurrentTermContents.Length >= 3) + { + value = this.ReadUnsignedIntegerFromBigInteger(); + return true; + } + } + else + { + value = this.ReadInteger(); + return true; + } + } + + value = default; + return false; + } + + /// + /// Reads the current term as an int. + /// + /// True if successful, false if unsuccessful. + public readonly bool TryReadInt32 + ( + out int value + ) + { + if (this.TermType.IsInteger()) + { + if (this.TermType.IsBigInteger()) + { + if (this.CurrentTermContents.Length >= 5) + { + value = this.ReadSignedIntegerFromBigInteger(); + return true; + } + } + else + { + value = this.ReadInteger(); + return true; + } + } + + value = default; + return false; + } + + /// + /// Reads the current term as a uint. + /// + /// True if successful, false if unsuccessful. + public readonly bool TryReadUInt32 + ( + out uint value + ) + { + if (this.TermType.IsInteger()) + { + if (this.TermType.IsBigInteger()) + { + if (this.CurrentTermContents.Length >= 5) + { + value = this.ReadUnsignedIntegerFromBigInteger(); + return true; + } + } + else + { + value = this.ReadInteger(); + return true; + } + } + + value = default; + return false; + } + + /// + /// Reads the current term as a long. + /// + /// True if successful, false if unsuccessful. + public readonly bool TryReadInt64 + ( + out long value + ) + { + if (this.TermType.IsInteger()) + { + if (this.TermType.IsBigInteger()) + { + if (this.CurrentTermContents.Length >= 9) + { + value = this.ReadSignedIntegerFromBigInteger(); + return true; + } + } + else + { + value = this.ReadInteger(); + return true; + } + } + + value = default; + return false; + } + + /// + /// Reads the current term as a ulong. + /// + /// True if successful, false if unsuccessful. + public readonly bool TryReadUInt64 + ( + out ulong value + ) + { + if (this.TermType.IsInteger()) + { + if (this.TermType.IsBigInteger()) + { + if (this.CurrentTermContents.Length >= 9) + { + value = this.ReadUnsignedIntegerFromBigInteger(); + return true; + } + } + else + { + value = this.ReadInteger(); + return true; + } + } + + value = default; + return false; + } + + /// + /// Reads the current term as a BigInteger. + /// + /// True if successful, false if unsuccessful. + public readonly bool TryReadBigInteger + ( + out BigInteger value + ) + { + if (this.TermType.IsBigInteger()) + { + value = this.ReadBigIntegerCore(); + return true; + } + else if (this.TermType.IsInteger()) + { + value = new BigInteger(this.ReadInteger()); + return true; + } + + value = default; + return false; + } + + /// + /// Reads the current term as an sbyte. + /// + public readonly sbyte ReadSByte() + { + if (this.TryReadSByte(out sbyte value)) + { + return value; + } + + ThrowHelper.ThrowInvalidDecode(typeof(sbyte)); + return default; + } + + /// + /// Reads the current term as a byte. + /// + public readonly byte ReadByte() + { + if (this.TryReadByte(out byte value)) + { + return value; + } + + ThrowHelper.ThrowInvalidDecode(typeof(byte)); + return default; + } + + /// + /// Reads the current term as a short. + /// + public readonly short ReadInt16() + { + if (this.TryReadInt16(out short value)) + { + return value; + } + + ThrowHelper.ThrowInvalidDecode(typeof(short)); + return default; + } + + /// + /// Reads the current term as a ushort. + /// + public readonly ushort ReadUInt16() { - int value = BinaryPrimitives.ReadInt32BigEndian(this.CurrentTermContents); + if (this.TryReadUInt16(out ushort value)) + { + return value; + } - return TNumber.CreateChecked(value); + ThrowHelper.ThrowInvalidDecode(typeof(ushort)); + return default; } /// - /// Provides the implementation for performing a truncating read from a small-integer term. + /// Reads the current term as an int. /// - private readonly TNumber ReadFromByteTruncating() - where TNumber : IBinaryInteger - => TNumber.CreateTruncating(MemoryMarshal.GetReference(this.CurrentTermContents)); + public readonly int ReadInt32() + { + if (this.TryReadInt32(out int value)) + { + return value; + } + + ThrowHelper.ThrowInvalidDecode(typeof(int)); + return default; + } /// - /// Provides the implementation for performing a saturating read from a small-integer term. + /// Reads the current term as a uint. /// - private readonly TNumber ReadFromByteSaturating() - where TNumber : IBinaryInteger - => TNumber.CreateSaturating(MemoryMarshal.GetReference(this.CurrentTermContents)); + public readonly uint ReadUInt32() + { + if (this.TryReadUInt32(out uint value)) + { + return value; + } + + ThrowHelper.ThrowInvalidDecode(typeof(uint)); + return default; + } /// - /// Provides the implementation for performing a checked read from a small-integer term. + /// Reads the current term as a long. /// - private readonly TNumber ReadFromByteChecked() - where TNumber : IBinaryInteger - => TNumber.CreateChecked(MemoryMarshal.GetReference(this.CurrentTermContents)); + public readonly long ReadInt64() + { + if (this.TryReadInt64(out long value)) + { + return value; + } + + ThrowHelper.ThrowInvalidDecode(typeof(long)); + return default; + } + + /// + /// Reads the current term as a ulong. + /// + public readonly ulong ReadUInt64() + { + if (this.TryReadUInt64(out ulong value)) + { + return value; + } + + ThrowHelper.ThrowInvalidDecode(typeof(ulong)); + return default; + } + + /// + /// Reads the current term as a BigInteger. + /// + public readonly BigInteger ReadBigInteger() + { + if (this.TryReadBigInteger(out BigInteger value)) + { + return value; + } + + ThrowHelper.ThrowInvalidDecode(typeof(BigInteger)); + return default; + } } From 019028f06494ef67eabff82f5cd895456ad25f9f Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Tue, 19 Sep 2023 22:08:34 +0200 Subject: [PATCH 109/323] implement float API surface --- .../Serialization/EtfReader.Floats.cs | 108 ++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 src/etf/DSharpPlus.Etf/Serialization/EtfReader.Floats.cs diff --git a/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Floats.cs b/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Floats.cs new file mode 100644 index 0000000000..5f4bb7e41f --- /dev/null +++ b/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Floats.cs @@ -0,0 +1,108 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; +using System.Buffers.Binary; +using System.Globalization; + +namespace DSharpPlus.Etf.Serialization; + +partial struct EtfReader +{ + /// + /// Reads the current term as a double. + /// + /// True if successful, false if unsuccessful. + public readonly bool TryReadDouble + ( + out double value + ) + { + switch (this.TermType) + { + case TermType.Float: + return double.TryParse(this.CurrentTermContents, CultureInfo.InvariantCulture, out value); + + case TermType.NewFloat: + value = BinaryPrimitives.ReadDoubleBigEndian(this.CurrentTermContents); + return true; + + default: + value = default; + return false; + } + } + + /// + /// Reads the current term as a float. + /// + /// True if successful, false if unsuccessful. + public readonly bool TryReadSingle + ( + out float value + ) + { + bool success = this.TryReadDouble(out double result); + + value = (float)result; + return success; + } + + /// + /// Reads the current term as a half. + /// + /// True if successful, false if unsuccessful. + public readonly bool TryReadHalf + ( + out Half value + ) + { + bool success = this.TryReadDouble(out double result); + + value = (Half)result; + return success; + } + + /// + /// Reads the current term as a double. + /// + public readonly double ReadDouble() + { + if (this.TryReadDouble(out double value)) + { + return value; + } + + ThrowHelper.ThrowInvalidDecode(typeof(double)); + return default; + } + + /// + /// Reads the current term as a float. + /// + public readonly float ReadSingle() + { + if (this.TryReadSingle(out float value)) + { + return value; + } + + ThrowHelper.ThrowInvalidDecode(typeof(float)); + return default; + } + + /// + /// Reads the current term as a half. + /// + public readonly Half ReadHalf() + { + if (this.TryReadHalf(out Half value)) + { + return value; + } + + ThrowHelper.ThrowInvalidDecode(typeof(Half)); + return default; + } +} From f6665a509531d753370617a3a65cab24977fa47d Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Wed, 20 Sep 2023 22:22:04 +0200 Subject: [PATCH 110/323] expose reading strings --- .../Serialization/EtfReader.Strings.cs | 74 +++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 src/etf/DSharpPlus.Etf/Serialization/EtfReader.Strings.cs diff --git a/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Strings.cs b/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Strings.cs new file mode 100644 index 0000000000..91b5cc35e2 --- /dev/null +++ b/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Strings.cs @@ -0,0 +1,74 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; +using System.Diagnostics.CodeAnalysis; +using System.Text; + +using DSharpPlus.Etf.Extensions; + +namespace DSharpPlus.Etf.Serialization; + +partial struct EtfReader +{ + /// + /// Reads the current term as a string. + /// + /// True if reading was successful, false if unsuccessful. + public readonly bool TryReadString + ( + [NotNullWhen(true)] + out string? value + ) + { + if (this.TermType.IsString()) + { + value = Encoding.Unicode.GetString(this.CurrentTermContents); + return true; + } + + value = default; + return false; + } + + /// + /// Copies the current term to a Span as UTF-8 string. + /// + /// True if successful, false if unsuccessful. + public readonly bool TryReadUtf8String + ( + Span buffer + ) + => this.TermType.IsString() && this.CurrentTermContents.TryCopyTo(buffer); + + /// + /// Reads the current term as a string. + /// + public readonly string ReadString() + { + if (this.TryReadString(out string? value)) + { + return value; + } + + ThrowHelper.ThrowInvalidDecode(typeof(string)); + return default!; + } + + /// + /// Copies the current term to a Span as UTF-8 string. + /// + public readonly void ReadUtf8String + ( + Span buffer + ) + { + if (this.TryReadUtf8String(buffer)) + { + return; + } + + ThrowHelper.ThrowInvalidDecode(typeof(string)); + } +} From 695b4f70e56bc6bf189bc63973f05fdc0aa2d44e Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Wed, 20 Sep 2023 22:25:48 +0200 Subject: [PATCH 111/323] expose a means to get raw memory --- .../DSharpPlus.Etf/Serialization/EtfReader.cs | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/src/etf/DSharpPlus.Etf/Serialization/EtfReader.cs b/src/etf/DSharpPlus.Etf/Serialization/EtfReader.cs index 790380c4a8..39a0de33cf 100644 --- a/src/etf/DSharpPlus.Etf/Serialization/EtfReader.cs +++ b/src/etf/DSharpPlus.Etf/Serialization/EtfReader.cs @@ -214,4 +214,58 @@ public bool Read() return success; } + + // expose ways to just get raw memory + + /// + /// Copies the current term as raw memory. + /// + /// True if successful, false if unsuccessful. + public readonly bool TryReadMemory + ( + Span buffer + ) + => this.CurrentTermContents.TryCopyTo(buffer); + + /// + /// Copies the current term as raw memory. + /// + /// True if successful, false if unsuccessful. + public readonly bool TryReadMemory + ( + byte[] buffer + ) + => this.CurrentTermContents.TryCopyTo(buffer); + + /// + /// Copies the current term as raw memory. + /// + public readonly void ReadMemory + ( + Span buffer + ) + { + if (this.TryReadMemory(buffer)) + { + return; + } + + ThrowHelper.ThrowInvalidDecode(typeof(Span)); + } + + /// + /// Copies the current term as raw memory. + /// + public readonly void ReadMemory + ( + byte[] buffer + ) + { + if (this.TryReadMemory(buffer)) + { + return; + } + + ThrowHelper.ThrowInvalidDecode(typeof(byte[])); + } } From bab71cb425b94b9efc5c2fab82a8ffde4e77ed41 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Thu, 21 Sep 2023 10:12:05 +0200 Subject: [PATCH 112/323] allow reading from shorter BigIntegers --- .../Serialization/EtfReader.Integers.cs | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Integers.cs b/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Integers.cs index 3223525208..11836235a7 100644 --- a/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Integers.cs +++ b/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Integers.cs @@ -261,6 +261,10 @@ out short value value = this.ReadSignedIntegerFromBigInteger(); return true; } + + BigInteger intermediary = this.ReadBigIntegerCore(); + value = (short)intermediary; + return true; } else { @@ -291,6 +295,10 @@ out ushort value value = this.ReadUnsignedIntegerFromBigInteger(); return true; } + + BigInteger intermediary = this.ReadBigIntegerCore(); + value = (ushort)intermediary; + return true; } else { @@ -321,6 +329,10 @@ out int value value = this.ReadSignedIntegerFromBigInteger(); return true; } + + BigInteger intermediary = this.ReadBigIntegerCore(); + value = (int)intermediary; + return true; } else { @@ -351,6 +363,10 @@ out uint value value = this.ReadUnsignedIntegerFromBigInteger(); return true; } + + BigInteger intermediary = this.ReadBigIntegerCore(); + value = (uint)intermediary; + return true; } else { @@ -381,6 +397,10 @@ out long value value = this.ReadSignedIntegerFromBigInteger(); return true; } + + BigInteger intermediary = this.ReadBigIntegerCore(); + value = (long)intermediary; + return true; } else { @@ -411,6 +431,10 @@ out ulong value value = this.ReadUnsignedIntegerFromBigInteger(); return true; } + + BigInteger intermediary = this.ReadBigIntegerCore(); + value = (ulong)intermediary; + return true; } else { From 1f9d4b23c02522dd3bde52eb6a00e8bd1602994d Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Thu, 21 Sep 2023 13:40:07 +0200 Subject: [PATCH 113/323] get lengths --- src/etf/DSharpPlus.Etf/Serialization/EtfReader.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/etf/DSharpPlus.Etf/Serialization/EtfReader.cs b/src/etf/DSharpPlus.Etf/Serialization/EtfReader.cs index 39a0de33cf..9fc7c852ff 100644 --- a/src/etf/DSharpPlus.Etf/Serialization/EtfReader.cs +++ b/src/etf/DSharpPlus.Etf/Serialization/EtfReader.cs @@ -268,4 +268,10 @@ byte[] buffer ThrowHelper.ThrowInvalidDecode(typeof(byte[])); } + + /// + /// Gets the remaining length of the current complex structure. + /// + public readonly uint GetCurrentRemainingLength() + => this.remainingLengths.Peek(); } From 03fcce183f26d98816e7f0d6589ed3318cc0f179 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Thu, 21 Sep 2023 20:37:50 +0200 Subject: [PATCH 114/323] safe code who? --- .../Serialization/EtfReader.Integers.cs | 122 +++++------------- 1 file changed, 32 insertions(+), 90 deletions(-) diff --git a/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Integers.cs b/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Integers.cs index 11836235a7..5052cefc5f 100644 --- a/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Integers.cs +++ b/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Integers.cs @@ -71,93 +71,59 @@ private readonly BigInteger ReadBigIntegerCore() * unnecessary but that still poses a branch the branch predictor has to deal with. oddly, * removing that branch also causes the JIT to optimize the ternary operator to a conditional * move, which actually makes this code entirely branchless. - * - **************************************************************************************************** - * - * one note for the following section: the exact registers and moves may differ; the assembly here - * is taken from an (U)Int64 implementation - * - **************************************************************************************************** - * - * on x86, the emitted assembly output should look as follows for unsigned methods: - * - * mov rax, bword ptr [rcx+0x40] | load the length of the current term as the reference passed - * | to Unsafe.Add - * ------------------------------|------------------------------------------------------------------- - * mov rax, qword ptr [rax+0x01] | implicitly add and load the value at this address into rax, the - * | return register - * - **************************************************************************************************** - * - * and for signed methods: - * - * mov rax, bword ptr [rcx+0x40] | load the length of the current term as the reference passed - * | to Unsafe.Add, but also as the reference we will use later to - * | determine the sign - * ------------------------------|------------------------------------------------------------------- - * mov rcx, rax | move our work to rcx (or just any register that's currently - * | free, it doesn't really matter) to keep the reference in rax - * | intact - * ------------------------------|------------------------------------------------------------------- - * mov rdx, 0x7FFFFFFFFFFFFFFF | set the maximum value up to ensure we don't break if the sign - * | bit is already set - * ------------------------------|------------------------------------------------------------------- - * and rdx, qword ptr [rcx+0x01] | implicitly and and load the integer into rdx, the address - * | incremented as Unsafe.Add instructed it to - * ------------------------------|------------------------------------------------------------------- - * mov rcx, rdx | copy the value into rcx to work there - * ------------------------------|------------------------------------------------------------------- - * neg rcx | negate the value in rcx, effectively `rcx = -rcx`. the JIT thinks - * | rightly that it is faster to always negate than to take the - * | branch, which hurts us by even existing - * ------------------------------|------------------------------------------------------------------- - * cmp byte ptr [rax], 0 | see whether the sign byte, with the reference stored in rax from - * | the very beginning, equals zero - * ------------------------------|------------------------------------------------------------------- - * mov rax, rcx | move the negated value into rax to set up for evaluating the - * | condition - * ------------------------------|------------------------------------------------------------------- - * cmove rax, rdx | if the sign byte from earlier was zero, move the positive value - * | into rax, if not, keep the negative value - * - * if the JIT insists on changing cmp byte ptr [rax], 0 to test byte ptr [rax], that's fine, any - * other changes should absolutely be analyzed for performance. - * ***************************************************************************************************/ /// /// Provides the implementation for reading a unsigned integer from a currently provided /// BigInteger term, ignoring the sign byte. /// - private readonly TNumber ReadUnsignedIntegerFromBigInteger() - where TNumber : IUnsignedNumber, IBinaryInteger + private readonly unsafe TNumber ReadUnsignedIntegerFromBigInteger() + where TNumber : unmanaged, IUnsignedNumber, IBinaryInteger { - return Unsafe.ReadUnaligned + void* copy = stackalloc ulong[1]; + + Unsafe.CopyBlockUnaligned ( - ref Unsafe.Add + destination: copy, + source: Unsafe.AsPointer ( - ref MemoryMarshal.GetReference(this.CurrentTermContents), - elementOffset: 1 - ) + ref Unsafe.Add + ( + source: ref MemoryMarshal.GetReference(this.CurrentTermContents), + elementOffset: 1 + ) + ), + byteCount: (uint)this.CurrentTermContents.Length - 1 ); + + return Unsafe.Read(copy); } /// /// Provides the implementation for reading a signed integer from a currently provided /// BigInteger term. /// - private readonly TNumber ReadSignedIntegerFromBigInteger() - where TNumber : IBinaryInteger, IMinMaxValue, ISignedNumber + private readonly unsafe TNumber ReadSignedIntegerFromBigInteger() + where TNumber : unmanaged, IBinaryInteger, IMinMaxValue, ISignedNumber { - TNumber value = Unsafe.ReadUnaligned + void* copy = stackalloc ulong[1]; + + Unsafe.CopyBlockUnaligned ( - ref Unsafe.Add + destination: copy, + source: Unsafe.AsPointer ( - ref MemoryMarshal.GetReference(this.CurrentTermContents), - elementOffset: 1 - ) + ref Unsafe.Add + ( + source: ref MemoryMarshal.GetReference(this.CurrentTermContents), + elementOffset: 1 + ) + ), + byteCount: (uint)this.CurrentTermContents.Length - 1 ); + TNumber value = Unsafe.Read(copy); + value &= TNumber.MaxValue; return MemoryMarshal.GetReference(this.CurrentTermContents) == 0 ? value : -value; @@ -261,10 +227,6 @@ out short value value = this.ReadSignedIntegerFromBigInteger(); return true; } - - BigInteger intermediary = this.ReadBigIntegerCore(); - value = (short)intermediary; - return true; } else { @@ -295,10 +257,6 @@ out ushort value value = this.ReadUnsignedIntegerFromBigInteger(); return true; } - - BigInteger intermediary = this.ReadBigIntegerCore(); - value = (ushort)intermediary; - return true; } else { @@ -329,10 +287,6 @@ out int value value = this.ReadSignedIntegerFromBigInteger(); return true; } - - BigInteger intermediary = this.ReadBigIntegerCore(); - value = (int)intermediary; - return true; } else { @@ -363,10 +317,6 @@ out uint value value = this.ReadUnsignedIntegerFromBigInteger(); return true; } - - BigInteger intermediary = this.ReadBigIntegerCore(); - value = (uint)intermediary; - return true; } else { @@ -397,10 +347,6 @@ out long value value = this.ReadSignedIntegerFromBigInteger(); return true; } - - BigInteger intermediary = this.ReadBigIntegerCore(); - value = (long)intermediary; - return true; } else { @@ -431,10 +377,6 @@ out ulong value value = this.ReadUnsignedIntegerFromBigInteger(); return true; } - - BigInteger intermediary = this.ReadBigIntegerCore(); - value = (ulong)intermediary; - return true; } else { From 14431ce98143c7a219e92c75fb2f71e397e1d8d0 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Fri, 22 Sep 2023 20:18:13 +0200 Subject: [PATCH 115/323] save about 0.1-0.2 nanoseconds for good measure --- .../Serialization/EtfReader.Integers.cs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Integers.cs b/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Integers.cs index 5052cefc5f..3ab6da8041 100644 --- a/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Integers.cs +++ b/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Integers.cs @@ -80,11 +80,11 @@ private readonly BigInteger ReadBigIntegerCore() private readonly unsafe TNumber ReadUnsignedIntegerFromBigInteger() where TNumber : unmanaged, IUnsignedNumber, IBinaryInteger { - void* copy = stackalloc ulong[1]; + TNumber value = TNumber.Zero; Unsafe.CopyBlockUnaligned ( - destination: copy, + destination: &value, source: Unsafe.AsPointer ( ref Unsafe.Add @@ -96,7 +96,7 @@ ref Unsafe.Add byteCount: (uint)this.CurrentTermContents.Length - 1 ); - return Unsafe.Read(copy); + return value; } /// @@ -106,11 +106,11 @@ ref Unsafe.Add private readonly unsafe TNumber ReadSignedIntegerFromBigInteger() where TNumber : unmanaged, IBinaryInteger, IMinMaxValue, ISignedNumber { - void* copy = stackalloc ulong[1]; + TNumber value = TNumber.Zero; Unsafe.CopyBlockUnaligned ( - destination: copy, + destination: &value, source: Unsafe.AsPointer ( ref Unsafe.Add @@ -122,8 +122,6 @@ ref Unsafe.Add byteCount: (uint)this.CurrentTermContents.Length - 1 ); - TNumber value = Unsafe.Read(copy); - value &= TNumber.MaxValue; return MemoryMarshal.GetReference(this.CurrentTermContents) == 0 ? value : -value; From 4c37c2ce4d0a1f9127508e36522564a4dcff269e Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Fri, 22 Sep 2023 22:36:01 +0200 Subject: [PATCH 116/323] implement port terms --- src/etf/DSharpPlus.Etf/Objects/PortTerm.cs | 26 ++++++ .../Serialization/EtfReader.Erlang.cs | 85 +++++++++++++++++++ 2 files changed, 111 insertions(+) create mode 100644 src/etf/DSharpPlus.Etf/Objects/PortTerm.cs create mode 100644 src/etf/DSharpPlus.Etf/Serialization/EtfReader.Erlang.cs diff --git a/src/etf/DSharpPlus.Etf/Objects/PortTerm.cs b/src/etf/DSharpPlus.Etf/Objects/PortTerm.cs new file mode 100644 index 0000000000..ebe08c3fc0 --- /dev/null +++ b/src/etf/DSharpPlus.Etf/Objects/PortTerm.cs @@ -0,0 +1,26 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Etf.Objects; + +/// +/// Represents a port in Erlang parlance. +/// +public readonly record struct PortTerm +{ + /// + /// The originating node. + /// + public required string Node { get; init; } + + /// + /// The relevant ID. + /// + public required uint Id { get; init; } + + /// + /// An identifier indicating the incarnation of a node. + /// + public required byte Creation { get; init; } +} diff --git a/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Erlang.cs b/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Erlang.cs new file mode 100644 index 0000000000..5fb1d55bbc --- /dev/null +++ b/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Erlang.cs @@ -0,0 +1,85 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Buffers.Binary; +using System.Diagnostics.CodeAnalysis; +using System.Text; + +using DSharpPlus.Etf.Objects; + +namespace DSharpPlus.Etf.Serialization; + +// here we deal with reading erlang-specific objects +// this doesn't need to be fast or anything, we just provide this for completeness +partial struct EtfReader +{ + /// + /// Convenience utility to read atom terms from the current term at the given offset. + /// + /// The offset to start at. This value will contain the final offset upon exit. + /// The read atom as string. + /// Whether the operation was successful. + private readonly bool TryReadAtom + ( + ref int offset, + + [NotNullWhen(true)] + out string? text + ) + { + if (this.CurrentTermContents.Length < offset + 2) + { + text = null; + return false; + } + + ushort length = BinaryPrimitives.ReadUInt16BigEndian(this.CurrentTermContents[offset..2]); + + text = Encoding.UTF8.GetString(this.CurrentTermContents[(offset + 2)..length]); + offset = length + 2; + return true; + } + + /// + /// Reads the current term as a port term. + /// + /// True if successful, false if unsuccessful. + public readonly bool TryReadPortTerm + ( + out PortTerm term + ) + { + int offset = 0; + + if (this.TermType != TermType.Port) + { + term = default; + return false; + } + + if (!this.TryReadAtom(ref offset, out string? node)) + { + term = default; + return false; + } + + if (this.CurrentTermContents.Length < offset + 5) + { + term = default; + return false; + } + + uint id = BinaryPrimitives.ReadUInt32BigEndian(this.CurrentTermContents[offset..4]); + byte creation = this.CurrentTermContents[^1]; + + term = new() + { + Node = node, + Id = id, + Creation = creation + }; + + return true; + } +} From 5c08c8bbb8c1402896af660d3cd6b82a3d8f7e57 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sat, 23 Sep 2023 15:36:11 +0200 Subject: [PATCH 117/323] support new-port terms --- src/etf/DSharpPlus.Etf/Objects/NewPortTerm.cs | 26 ++++++++++++ .../Serialization/EtfReader.Erlang.cs | 42 +++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 src/etf/DSharpPlus.Etf/Objects/NewPortTerm.cs diff --git a/src/etf/DSharpPlus.Etf/Objects/NewPortTerm.cs b/src/etf/DSharpPlus.Etf/Objects/NewPortTerm.cs new file mode 100644 index 0000000000..187edc3353 --- /dev/null +++ b/src/etf/DSharpPlus.Etf/Objects/NewPortTerm.cs @@ -0,0 +1,26 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Etf.Objects; + +/// +/// Represents a new port in Erlang parlance. +/// +public readonly record struct NewPortTerm +{ + /// + /// The originating node. + /// + public required string Node { get; init; } + + /// + /// The relevant ID. + /// + public required uint Id { get; init; } + + /// + /// An identifier indicating the incarnation of a node. + /// + public required uint Creation { get; init; } +} diff --git a/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Erlang.cs b/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Erlang.cs index 5fb1d55bbc..5a22c59391 100644 --- a/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Erlang.cs +++ b/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Erlang.cs @@ -82,4 +82,46 @@ out PortTerm term return true; } + + /// + /// Reads the current term as a new-port term. + /// + /// True if successful, false if unsuccessful. + public readonly bool TryReadNewPortTerm + ( + out NewPortTerm term + ) + { + int offset = 0; + + if (this.TermType != TermType.NewPort) + { + term = default; + return false; + } + + if (!this.TryReadAtom(ref offset, out string? node)) + { + term = default; + return false; + } + + if (this.CurrentTermContents.Length < offset + 8) + { + term = default; + return false; + } + + uint id = BinaryPrimitives.ReadUInt32BigEndian(this.CurrentTermContents[offset..4]); + uint creation = BinaryPrimitives.ReadUInt32BigEndian(this.CurrentTermContents[(offset + 4)..4]); + + term = new() + { + Node = node, + Id = id, + Creation = creation + }; + + return true; + } } From 3a55e2a7fe3d3f7151652e2b8f36c1312bd792be Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sat, 23 Sep 2023 15:38:33 +0200 Subject: [PATCH 118/323] as well as v4 ports --- src/etf/DSharpPlus.Etf/Objects/V4PortTerm.cs | 26 ++++++++++++ .../Serialization/EtfReader.Erlang.cs | 42 +++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 src/etf/DSharpPlus.Etf/Objects/V4PortTerm.cs diff --git a/src/etf/DSharpPlus.Etf/Objects/V4PortTerm.cs b/src/etf/DSharpPlus.Etf/Objects/V4PortTerm.cs new file mode 100644 index 0000000000..bb87285e07 --- /dev/null +++ b/src/etf/DSharpPlus.Etf/Objects/V4PortTerm.cs @@ -0,0 +1,26 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Etf.Objects; + +/// +/// Represents a new port in Erlang parlance. +/// +public readonly record struct V4PortTerm +{ + /// + /// The originating node. + /// + public required string Node { get; init; } + + /// + /// The relevant ID. + /// + public required ulong Id { get; init; } + + /// + /// An identifier indicating the incarnation of a node. + /// + public required uint Creation { get; init; } +} diff --git a/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Erlang.cs b/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Erlang.cs index 5a22c59391..97da3bd91f 100644 --- a/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Erlang.cs +++ b/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Erlang.cs @@ -124,4 +124,46 @@ out NewPortTerm term return true; } + + /// + /// Reads the current term as a v4-port term. + /// + /// True if successful, false if unsuccessful. + public readonly bool TryReadV4PortTerm + ( + out V4PortTerm term + ) + { + int offset = 0; + + if (this.TermType != TermType.NewPort) + { + term = default; + return false; + } + + if (!this.TryReadAtom(ref offset, out string? node)) + { + term = default; + return false; + } + + if (this.CurrentTermContents.Length < offset + 12) + { + term = default; + return false; + } + + ulong id = BinaryPrimitives.ReadUInt64BigEndian(this.CurrentTermContents[offset..8]); + uint creation = BinaryPrimitives.ReadUInt32BigEndian(this.CurrentTermContents[(offset + 8)..4]); + + term = new() + { + Node = node, + Id = id, + Creation = creation + }; + + return true; + } } From 85edd02a0adc1b54ecb69aee04bdba90020b8384 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sat, 23 Sep 2023 15:43:01 +0200 Subject: [PATCH 119/323] support PID terms --- src/etf/DSharpPlus.Etf/Objects/PidTerm.cs | 31 +++++++++++++ .../Serialization/EtfReader.Erlang.cs | 46 ++++++++++++++++++- 2 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 src/etf/DSharpPlus.Etf/Objects/PidTerm.cs diff --git a/src/etf/DSharpPlus.Etf/Objects/PidTerm.cs b/src/etf/DSharpPlus.Etf/Objects/PidTerm.cs new file mode 100644 index 0000000000..547764042b --- /dev/null +++ b/src/etf/DSharpPlus.Etf/Objects/PidTerm.cs @@ -0,0 +1,31 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Etf.Objects; + +/// +/// Represents an Erland process identifier object. +/// +public readonly record struct PidTerm +{ + /// + /// The originating node. + /// + public required string Node { get; init; } + + /// + /// The relevant ID. + /// + public required uint Id { get; init; } + + /// + /// The relevant serial number. + /// + public required uint Serial { get; init; } + + /// + /// An identifier indicating the incarnation of a node. + /// + public required byte Creation { get; init; } +} diff --git a/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Erlang.cs b/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Erlang.cs index 97da3bd91f..6d01f97294 100644 --- a/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Erlang.cs +++ b/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Erlang.cs @@ -136,7 +136,7 @@ out V4PortTerm term { int offset = 0; - if (this.TermType != TermType.NewPort) + if (this.TermType != TermType.V4Port) { term = default; return false; @@ -166,4 +166,48 @@ out V4PortTerm term return true; } + + /// + /// Reads the current term as a PID term. + /// + /// True if successful, false if unsuccessful. + public readonly bool TryReadPidTerm + ( + out PidTerm term + ) + { + int offset = 0; + + if (this.TermType != TermType.Pid) + { + term = default; + return false; + } + + if (!this.TryReadAtom(ref offset, out string? node)) + { + term = default; + return false; + } + + if (this.CurrentTermContents.Length < offset + 9) + { + term = default; + return false; + } + + uint id = BinaryPrimitives.ReadUInt32BigEndian(this.CurrentTermContents[offset..4]); + uint serial = BinaryPrimitives.ReadUInt32BigEndian(this.CurrentTermContents[(offset + 4)..4]); + byte creation = this.CurrentTermContents[^1]; + + term = new() + { + Node = node, + Id = id, + Serial = serial, + Creation = creation + }; + + return true; + } } From a9c5fa2b6ec52174653c96d07d4935672824b425 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sat, 23 Sep 2023 15:45:29 +0200 Subject: [PATCH 120/323] support new PIDs --- src/etf/DSharpPlus.Etf/Objects/NewPidTerm.cs | 31 +++++++++++++ .../Serialization/EtfReader.Erlang.cs | 44 +++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 src/etf/DSharpPlus.Etf/Objects/NewPidTerm.cs diff --git a/src/etf/DSharpPlus.Etf/Objects/NewPidTerm.cs b/src/etf/DSharpPlus.Etf/Objects/NewPidTerm.cs new file mode 100644 index 0000000000..0200882a0d --- /dev/null +++ b/src/etf/DSharpPlus.Etf/Objects/NewPidTerm.cs @@ -0,0 +1,31 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Etf.Objects; + +/// +/// Represents a new Erland process identifier object. +/// +public readonly record struct NewPidTerm +{ + /// + /// The originating node. + /// + public required string Node { get; init; } + + /// + /// The relevant ID. + /// + public required uint Id { get; init; } + + /// + /// The relevant serial number. + /// + public required uint Serial { get; init; } + + /// + /// An identifier indicating the incarnation of a node. + /// + public required uint Creation { get; init; } +} diff --git a/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Erlang.cs b/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Erlang.cs index 6d01f97294..94e33a23a7 100644 --- a/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Erlang.cs +++ b/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Erlang.cs @@ -210,4 +210,48 @@ out PidTerm term return true; } + + /// + /// Reads the current term as a PID term. + /// + /// True if successful, false if unsuccessful. + public readonly bool TryReadNewPidTerm + ( + out NewPidTerm term + ) + { + int offset = 0; + + if (this.TermType != TermType.NewPid) + { + term = default; + return false; + } + + if (!this.TryReadAtom(ref offset, out string? node)) + { + term = default; + return false; + } + + if (this.CurrentTermContents.Length < offset + 9) + { + term = default; + return false; + } + + uint id = BinaryPrimitives.ReadUInt32BigEndian(this.CurrentTermContents[offset..4]); + uint serial = BinaryPrimitives.ReadUInt32BigEndian(this.CurrentTermContents[(offset + 4)..4]); + uint creation = BinaryPrimitives.ReadUInt32BigEndian(this.CurrentTermContents[(offset + 8)..4]); + + term = new() + { + Node = node, + Id = id, + Serial = serial, + Creation = creation + }; + + return true; + } } From 9c1746f285e9acf63fddd73d9c80cb6ebec44fa5 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sat, 23 Sep 2023 15:52:44 +0200 Subject: [PATCH 121/323] add new reference terms --- src/etf/DSharpPlus.Etf/Objects/NewPidTerm.cs | 2 +- .../Objects/NewReferenceTerm.cs | 28 ++++++++++ src/etf/DSharpPlus.Etf/Objects/PidTerm.cs | 2 +- .../Serialization/EtfReader.Erlang.cs | 52 +++++++++++++++++++ 4 files changed, 82 insertions(+), 2 deletions(-) create mode 100644 src/etf/DSharpPlus.Etf/Objects/NewReferenceTerm.cs diff --git a/src/etf/DSharpPlus.Etf/Objects/NewPidTerm.cs b/src/etf/DSharpPlus.Etf/Objects/NewPidTerm.cs index 0200882a0d..588aed6fd6 100644 --- a/src/etf/DSharpPlus.Etf/Objects/NewPidTerm.cs +++ b/src/etf/DSharpPlus.Etf/Objects/NewPidTerm.cs @@ -5,7 +5,7 @@ namespace DSharpPlus.Etf.Objects; /// -/// Represents a new Erland process identifier object. +/// Represents a new Erlang process identifier object. /// public readonly record struct NewPidTerm { diff --git a/src/etf/DSharpPlus.Etf/Objects/NewReferenceTerm.cs b/src/etf/DSharpPlus.Etf/Objects/NewReferenceTerm.cs new file mode 100644 index 0000000000..b889a86787 --- /dev/null +++ b/src/etf/DSharpPlus.Etf/Objects/NewReferenceTerm.cs @@ -0,0 +1,28 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +namespace DSharpPlus.Etf.Objects; + +/// +/// Represents a new Erlang reference term. +/// +public readonly record struct NewReferenceTerm +{ + /// + /// The originating node. + /// + public required string Node { get; init; } + + /// + /// An identifier indicating the incarnation of a node. + /// + public required byte Creation { get; init; } + + /// + /// The relevant ID, to be regarded as uninterpreted data. + /// + public required IReadOnlyList Id { get; init; } +} diff --git a/src/etf/DSharpPlus.Etf/Objects/PidTerm.cs b/src/etf/DSharpPlus.Etf/Objects/PidTerm.cs index 547764042b..f4d698ae51 100644 --- a/src/etf/DSharpPlus.Etf/Objects/PidTerm.cs +++ b/src/etf/DSharpPlus.Etf/Objects/PidTerm.cs @@ -5,7 +5,7 @@ namespace DSharpPlus.Etf.Objects; /// -/// Represents an Erland process identifier object. +/// Represents an Erlang process identifier object. /// public readonly record struct PidTerm { diff --git a/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Erlang.cs b/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Erlang.cs index 94e33a23a7..a59efee04a 100644 --- a/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Erlang.cs +++ b/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Erlang.cs @@ -3,6 +3,7 @@ // file, You can obtain one at https://mozilla.org/MPL/2.0/. using System.Buffers.Binary; +using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Text; @@ -254,4 +255,55 @@ out NewPidTerm term return true; } + + /// + /// Reads the current term as a Reference term. + /// + /// True if successful, false if unsuccessful. + public readonly bool TryReadNewReferenceTerm + ( + out NewReferenceTerm term + ) + { + int offset = 2; + + if (this.TermType != TermType.NewReference) + { + term = default; + return false; + } + + ushort length = BinaryPrimitives.ReadUInt16BigEndian(this.CurrentTermContents[..2]); + + if (!this.TryReadAtom(ref offset, out string? node)) + { + term = default; + return false; + } + + if (this.CurrentTermContents.Length < offset + (length * 4) + 1) + { + term = default; + return false; + } + + byte creation = this.CurrentTermContents[offset++]; + + List id = new(length); + + for (int i = 0; i < length; i++) + { + id.Add(BinaryPrimitives.ReadUInt32BigEndian(this.CurrentTermContents[offset..4])); + offset += 4; + } + + term = new() + { + Node = node, + Creation = creation, + Id = id + }; + + return true; + } } From 10cbc6a74e6e24c7d8fdc9d30a59ad3b71a12e6c Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sat, 23 Sep 2023 15:54:51 +0200 Subject: [PATCH 122/323] add support for newer reference terms --- .../Objects/NewerReferenceTerm.cs | 28 ++++++++++ .../Serialization/EtfReader.Erlang.cs | 54 ++++++++++++++++++- 2 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 src/etf/DSharpPlus.Etf/Objects/NewerReferenceTerm.cs diff --git a/src/etf/DSharpPlus.Etf/Objects/NewerReferenceTerm.cs b/src/etf/DSharpPlus.Etf/Objects/NewerReferenceTerm.cs new file mode 100644 index 0000000000..83a16446bc --- /dev/null +++ b/src/etf/DSharpPlus.Etf/Objects/NewerReferenceTerm.cs @@ -0,0 +1,28 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +namespace DSharpPlus.Etf.Objects; + +/// +/// Represents a newer Erlang reference term. +/// +public readonly record struct NewerReferenceTerm +{ + /// + /// The originating node. + /// + public required string Node { get; init; } + + /// + /// An identifier indicating the incarnation of a node. + /// + public required uint Creation { get; init; } + + /// + /// The relevant ID, to be regarded as uninterpreted data. + /// + public required IReadOnlyList Id { get; init; } +} diff --git a/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Erlang.cs b/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Erlang.cs index a59efee04a..06e69afbb1 100644 --- a/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Erlang.cs +++ b/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Erlang.cs @@ -257,7 +257,7 @@ out NewPidTerm term } /// - /// Reads the current term as a Reference term. + /// Reads the current term as a new reference term. /// /// True if successful, false if unsuccessful. public readonly bool TryReadNewReferenceTerm @@ -306,4 +306,56 @@ out NewReferenceTerm term return true; } + + /// + /// Reads the current term as a newer reference term. + /// + /// True if successful, false if unsuccessful. + public readonly bool TryReadNewerReferenceTerm + ( + out NewerReferenceTerm term + ) + { + int offset = 2; + + if (this.TermType != TermType.NewReference) + { + term = default; + return false; + } + + ushort length = BinaryPrimitives.ReadUInt16BigEndian(this.CurrentTermContents[..2]); + + if (!this.TryReadAtom(ref offset, out string? node)) + { + term = default; + return false; + } + + if (this.CurrentTermContents.Length < offset + (length * 4) + 4) + { + term = default; + return false; + } + + uint creation = BinaryPrimitives.ReadUInt32BigEndian(this.CurrentTermContents[offset..4]); + offset += 4; + + List id = new(length); + + for (int i = 0; i < length; i++) + { + id.Add(BinaryPrimitives.ReadUInt32BigEndian(this.CurrentTermContents[offset..4])); + offset += 4; + } + + term = new() + { + Node = node, + Creation = creation, + Id = id + }; + + return true; + } } From 07cb15061c236d1b8e3d20082cb7bf103c9bab03 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sat, 23 Sep 2023 16:41:12 +0200 Subject: [PATCH 123/323] add throwing variants --- .../Serialization/EtfReader.Erlang.cs | 98 +++++++++++++++++++ 1 file changed, 98 insertions(+) diff --git a/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Erlang.cs b/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Erlang.cs index 06e69afbb1..0a39474979 100644 --- a/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Erlang.cs +++ b/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Erlang.cs @@ -358,4 +358,102 @@ out NewerReferenceTerm term return true; } + + /// + /// Reads the current term as port term. + /// + public readonly PortTerm ReadPortTerm() + { + if (this.TryReadPortTerm(out PortTerm term)) + { + return term; + } + + ThrowHelper.ThrowInvalidDecode(typeof(PortTerm)); + return default; + } + + /// + /// Reads the current term as new port term. + /// + public readonly NewPortTerm ReadNewPortTerm() + { + if (this.TryReadNewPortTerm(out NewPortTerm term)) + { + return term; + } + + ThrowHelper.ThrowInvalidDecode(typeof(NewPortTerm)); + return default; + } + + /// + /// Reads the current term as v4 port term. + /// + public readonly V4PortTerm ReadV4PortTerm() + { + if (this.TryReadV4PortTerm(out V4PortTerm term)) + { + return term; + } + + ThrowHelper.ThrowInvalidDecode(typeof(V4PortTerm)); + return default; + } + + /// + /// Reads the current term as PID term. + /// + public readonly PidTerm ReadPidTerm() + { + if (this.TryReadPidTerm(out PidTerm term)) + { + return term; + } + + ThrowHelper.ThrowInvalidDecode(typeof(PidTerm)); + return default; + } + + /// + /// Reads the current term as new PID term. + /// + public readonly NewPidTerm ReadNewPidTerm() + { + if (this.TryReadNewPidTerm(out NewPidTerm term)) + { + return term; + } + + ThrowHelper.ThrowInvalidDecode(typeof(NewPidTerm)); + return default; + } + + /// + /// Reads the current term as new reference term. + /// + public readonly NewReferenceTerm ReadNewReferenceTerm() + { + if (this.TryReadNewReferenceTerm(out NewReferenceTerm term)) + { + return term; + } + + ThrowHelper.ThrowInvalidDecode(typeof(NewReferenceTerm)); + return default; + } + + /// + /// Reads the current term as newer reference term. + /// + public readonly NewerReferenceTerm ReadNewerReferenceTerm() + { + if (this.TryReadNewerReferenceTerm(out NewerReferenceTerm term)) + { + return term; + } + + ThrowHelper.ThrowInvalidDecode(typeof(NewerReferenceTerm)); + return default; + } } From 377451bbbafd4fdc5f95bd6a8b60402b3627948e Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sat, 23 Sep 2023 22:29:20 +0200 Subject: [PATCH 124/323] consider actually rangechecking correctly ft. tests --- DSharpPlus.sln | 10 +++ .../Serialization/EtfReader.Integers.cs | 2 +- .../Serialization/EtfReader.Lexing.cs | 84 +++++++++---------- .../DSharpPlus.Etf/Serialization/EtfReader.cs | 4 +- .../DSharpPlus.Etf.Tests.csproj | 24 ++++++ .../EtfReaderTests/IntegerPrimitives.cs | 78 +++++++++++++++++ 6 files changed, 157 insertions(+), 45 deletions(-) create mode 100644 tests/etf/DSharpPlus.Etf.Tests/DSharpPlus.Etf.Tests.csproj create mode 100644 tests/etf/DSharpPlus.Etf.Tests/Serialization/EtfReaderTests/IntegerPrimitives.cs diff --git a/DSharpPlus.sln b/DSharpPlus.sln index bef5d5edd1..d1e47d3183 100644 --- a/DSharpPlus.sln +++ b/DSharpPlus.sln @@ -34,6 +34,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Etf", "Etf", "{0BB713D0-63C EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DSharpPlus.Etf", "src\etf\DSharpPlus.ETF\DSharpPlus.Etf.csproj", "{96B95EF1-14FC-440F-B924-05E41929AA33}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Etf", "Etf", "{A4B153D7-B6D0-481B-843C-F5FD45A58697}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DSharpPlus.Etf.Tests", "tests\etf\DSharpPlus.Etf.Tests\DSharpPlus.Etf.Tests.csproj", "{82C085F7-EFFE-4252-9E66-43F4385AA706}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -72,6 +76,10 @@ Global {96B95EF1-14FC-440F-B924-05E41929AA33}.Debug|Any CPU.Build.0 = Debug|Any CPU {96B95EF1-14FC-440F-B924-05E41929AA33}.Release|Any CPU.ActiveCfg = Release|Any CPU {96B95EF1-14FC-440F-B924-05E41929AA33}.Release|Any CPU.Build.0 = Release|Any CPU + {82C085F7-EFFE-4252-9E66-43F4385AA706}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {82C085F7-EFFE-4252-9E66-43F4385AA706}.Debug|Any CPU.Build.0 = Debug|Any CPU + {82C085F7-EFFE-4252-9E66-43F4385AA706}.Release|Any CPU.ActiveCfg = Release|Any CPU + {82C085F7-EFFE-4252-9E66-43F4385AA706}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -86,6 +94,8 @@ Global {98D2C52C-E3BA-4564-919C-750775B7BA9C} = {5FBB4590-56B0-453B-A87B-08A17C599B5C} {9F25D892-3CB0-4D47-B67D-D3FFFADC03E0} = {21927A64-7345-4D90-9EE2-7FA4B1973AAC} {96B95EF1-14FC-440F-B924-05E41929AA33} = {0BB713D0-63CC-4373-9C76-3C80611EFFA6} + {A4B153D7-B6D0-481B-843C-F5FD45A58697} = {EAE89CF5-AA91-4A22-9949-A46FAE1BF0D0} + {82C085F7-EFFE-4252-9E66-43F4385AA706} = {A4B153D7-B6D0-481B-843C-F5FD45A58697} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {55CDA684-8900-479B-9DAE-BA3BE09B337B} diff --git a/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Integers.cs b/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Integers.cs index 3ab6da8041..db1460d4a7 100644 --- a/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Integers.cs +++ b/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Integers.cs @@ -141,7 +141,7 @@ private readonly TNumber ReadInteger() TNumber.CreateTruncating(BinaryPrimitives.ReadInt32BigEndian(this.CurrentTermContents)), TermType.SmallInteger => - TNumber.CreateTruncating(MemoryMarshal.GetReference(this.CurrentTermContents)) + TNumber.CreateTruncating((sbyte)MemoryMarshal.GetReference(this.CurrentTermContents)) }; } diff --git a/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Lexing.cs b/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Lexing.cs index 5d8a13b26f..d9f09d938f 100644 --- a/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Lexing.cs +++ b/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Lexing.cs @@ -37,7 +37,7 @@ private int LexAtomCache out bool success ) { - if (this.index + 1 < this.data.Length) + if (this.index + 1 <= this.data.Length) { this.CurrentTermContents = this.data.Slice(this.index, 1); @@ -59,12 +59,12 @@ private int LexAtomUtf8 out bool success ) { - if (this.index + 2 < this.data.Length) + if (this.index + 2 <= this.data.Length) { ReadOnlySpan lengthSlice = this.data.Slice(this.index, 2); ushort length = BinaryPrimitives.ReadUInt16BigEndian(lengthSlice); - if (this.index + 2 + length < this.data.Length) + if (this.index + 2 + length <= this.data.Length) { this.CurrentTermContents = this.data.Slice(this.index + 2, length); @@ -87,12 +87,12 @@ private int LexBinary out bool success ) { - if (this.index + 4 < this.data.Length) + if (this.index + 4 <= this.data.Length) { ReadOnlySpan lengthSlice = this.data.Slice(this.index, 4); uint length = BinaryPrimitives.ReadUInt32BigEndian(lengthSlice); - if (this.index + 4 + length < this.data.Length) + if (this.index + 4 + length <= this.data.Length) { this.CurrentTermContents = this.data.Slice(this.index + 4, (int)length); @@ -115,13 +115,13 @@ private int LexBitBinary out bool success ) { - if (this.index + 4 < this.data.Length) + if (this.index + 4 <= this.data.Length) { ReadOnlySpan lengthSlice = this.data.Slice(this.index, 4); uint length = BinaryPrimitives.ReadUInt32BigEndian(lengthSlice); // we do this by simply prepending the raw span with the amount of valid bits in the last byte - if (this.index + 5 + length < this.data.Length) + if (this.index + 5 + length <= this.data.Length) { this.CurrentTermContents = this.data.Slice(this.index + 4, (int)length + 1); @@ -145,7 +145,7 @@ out bool success ) { // first atom: module name - if (this.index + 2 < this.data.Length) + if (this.index + 2 <= this.data.Length) { int accumulatedLength = 2; @@ -155,7 +155,7 @@ out bool success accumulatedLength += length; // second atom: function name - if (this.index + accumulatedLength + 2 < this.data.Length) + if (this.index + accumulatedLength + 2 <= this.data.Length) { lengthSlice = this.data.Slice(this.index + accumulatedLength, 2); length = BinaryPrimitives.ReadUInt16BigEndian(lengthSlice); @@ -163,7 +163,7 @@ out bool success accumulatedLength += 2 + length; // one byte for arity - if (this.index + ++accumulatedLength < this.data.Length) + if (this.index + ++accumulatedLength <= this.data.Length) { this.CurrentTermContents = this.data.Slice(this.index, accumulatedLength); @@ -187,7 +187,7 @@ private int LexFloat out bool success ) { - if (this.index + 31 < this.data.Length) + if (this.index + 31 <= this.data.Length) { this.CurrentTermContents = this.data.Slice(this.index, 31); @@ -209,7 +209,7 @@ private int LexInteger out bool success ) { - if (this.index + 4 < this.data.Length) + if (this.index + 4 <= this.data.Length) { this.CurrentTermContents = this.data.Slice(this.index, 4); @@ -231,13 +231,13 @@ private int LexLargeBigInteger out bool success ) { - if (this.index + 4 < this.data.Length) + if (this.index + 4 <= this.data.Length) { ReadOnlySpan lengthSlice = this.data.Slice(this.index, 4); uint length = BinaryPrimitives.ReadUInt32BigEndian(lengthSlice); // the first byte here carries the sign - if (this.index + 5 + length < this.data.Length) + if (this.index + 5 + length <= this.data.Length) { this.CurrentTermContents = this.data.Slice(this.index + 4, (int)length + 1); @@ -260,7 +260,7 @@ private readonly int LexLargeTuple out bool success ) { - if (this.index + 4 < this.data.Length) + if (this.index + 4 <= this.data.Length) { ReadOnlySpan lengthSlice = this.data.Slice(this.index, 4); uint length = BinaryPrimitives.ReadUInt32BigEndian(lengthSlice); @@ -286,7 +286,7 @@ private readonly int LexList out bool success ) { - if (this.index + 4 < this.data.Length) + if (this.index + 4 <= this.data.Length) { ReadOnlySpan lengthSlice = this.data.Slice(this.index, 4); uint length = BinaryPrimitives.ReadUInt32BigEndian(lengthSlice); @@ -328,7 +328,7 @@ private readonly int LexMap out bool success ) { - if (this.index + 4 < this.data.Length) + if (this.index + 4 <= this.data.Length) { ReadOnlySpan lengthSlice = this.data.Slice(this.index, 4); uint length = BinaryPrimitives.ReadUInt32BigEndian(lengthSlice); @@ -354,20 +354,20 @@ private int LexNewerReference out bool success ) { - if (this.index + 2 < this.data.Length) + if (this.index + 2 <= this.data.Length) { ReadOnlySpan lengthSlice = this.data.Slice(this.index, 2); ushort idLength = BinaryPrimitives.ReadUInt16BigEndian(lengthSlice); // decode the atom node name - if (this.index + 4 < this.data.Length) + if (this.index + 4 <= this.data.Length) { lengthSlice = this.data.Slice(this.index + 2, 2); ushort nodeLength = BinaryPrimitives.ReadUInt16BigEndian(lengthSlice); int accumulatedLength = (idLength * 4) + nodeLength + 8; - if (this.index + accumulatedLength < this.data.Length) + if (this.index + accumulatedLength <= this.data.Length) { this.CurrentTermContents = this.data.Slice(this.index, accumulatedLength); @@ -391,7 +391,7 @@ private int LexNewFloat out bool success ) { - if (this.index + 8 < this.data.Length) + if (this.index + 8 <= this.data.Length) { this.CurrentTermContents = this.data.Slice(this.index, 8); @@ -413,7 +413,7 @@ private int LexNewPid out bool success ) { - if (this.index + 2 < this.data.Length) + if (this.index + 2 <= this.data.Length) { ReadOnlySpan lengthSlice = this.data.Slice(this.index, 2); @@ -421,7 +421,7 @@ out bool success length += 14; - if (this.index + length < this.data.Length) + if (this.index + length <= this.data.Length) { this.CurrentTermContents = this.data.Slice(this.index, length); @@ -444,7 +444,7 @@ private int LexNewPort out bool success ) { - if (this.index + 2 < this.data.Length) + if (this.index + 2 <= this.data.Length) { ReadOnlySpan lengthSlice = this.data.Slice(this.index, 2); @@ -452,7 +452,7 @@ out bool success length += 10; - if (this.index + length < this.data.Length) + if (this.index + length <= this.data.Length) { this.CurrentTermContents = this.data.Slice(this.index, length); @@ -475,20 +475,20 @@ private int LexNewReference out bool success ) { - if (this.index + 2 < this.data.Length) + if (this.index + 2 <= this.data.Length) { ReadOnlySpan lengthSlice = this.data.Slice(this.index, 2); ushort idLength = BinaryPrimitives.ReadUInt16BigEndian(lengthSlice); // decode the atom node name - if (this.index + 4 < this.data.Length) + if (this.index + 4 <= this.data.Length) { lengthSlice = this.data.Slice(this.index + 2, 2); ushort nodeLength = BinaryPrimitives.ReadUInt16BigEndian(lengthSlice); int accumulatedLength = (idLength * 4) + nodeLength + 5; - if (this.index + accumulatedLength < this.data.Length) + if (this.index + accumulatedLength <= this.data.Length) { this.CurrentTermContents = this.data.Slice(this.index, accumulatedLength); @@ -526,7 +526,7 @@ private int LexPid out bool success ) { - if (this.index + 2 < this.data.Length) + if (this.index + 2 <= this.data.Length) { ReadOnlySpan lengthSlice = this.data.Slice(this.index, 2); @@ -534,7 +534,7 @@ out bool success length += 11; - if (this.index + length < this.data.Length) + if (this.index + length <= this.data.Length) { this.CurrentTermContents = this.data.Slice(this.index, length); @@ -557,7 +557,7 @@ private int LexPort out bool success ) { - if (this.index + 2 < this.data.Length) + if (this.index + 2 <= this.data.Length) { ReadOnlySpan lengthSlice = this.data.Slice(this.index, 2); @@ -565,7 +565,7 @@ out bool success length += 7; - if (this.index + length < this.data.Length) + if (this.index + length <= this.data.Length) { this.CurrentTermContents = this.data.Slice(this.index, length); @@ -588,11 +588,11 @@ private int LexSmallAtomUtf8 out bool success ) { - if (this.index + 1 < this.data.Length) + if (this.index + 1 <= this.data.Length) { byte length = this.data[this.index + 1]; - if (this.index + 1 + length < this.data.Length) + if (this.index + 1 + length <= this.data.Length) { this.CurrentTermContents = this.data.Slice(this.index + 1, length); @@ -615,12 +615,12 @@ private int LexSmallBigInteger out bool success ) { - if (this.index + 1 < this.data.Length) + if (this.index + 1 <= this.data.Length) { byte length = this.data[this.index]; // the first byte here carries the sign - if (this.index + 2 + length < this.data.Length) + if (this.index + 2 + length <= this.data.Length) { this.CurrentTermContents = this.data.Slice(this.index + 1, (int)length + 1); @@ -643,7 +643,7 @@ private int LexSmallInteger out bool success ) { - if (this.index + 1 < this.data.Length) + if (this.index + 1 <= this.data.Length) { this.CurrentTermContents = this.data.Slice(this.index, 1); @@ -665,7 +665,7 @@ private readonly int LexSmallTuple out bool success ) { - if (this.index + 1 < this.data.Length) + if (this.index + 1 <= this.data.Length) { byte length = this.data[this.index]; @@ -690,12 +690,12 @@ private int LexString out bool success ) { - if (this.index + 2 < this.data.Length) + if (this.index + 2 <= this.data.Length) { ReadOnlySpan lengthSlice = this.data.Slice(this.index, 2); ushort length = BinaryPrimitives.ReadUInt16BigEndian(lengthSlice); - if (this.index + 2 + length < this.data.Length) + if (this.index + 2 + length <= this.data.Length) { this.CurrentTermContents = this.data.Slice(this.index + 2, length); @@ -718,7 +718,7 @@ private int LexV4Port out bool success ) { - if (this.index + 2 < this.data.Length) + if (this.index + 2 <= this.data.Length) { ReadOnlySpan lengthSlice = this.data.Slice(this.index, 2); @@ -726,7 +726,7 @@ out bool success length += 14; - if (this.index + length < this.data.Length) + if (this.index + length <= this.data.Length) { this.CurrentTermContents = this.data.Slice(this.index, length); diff --git a/src/etf/DSharpPlus.Etf/Serialization/EtfReader.cs b/src/etf/DSharpPlus.Etf/Serialization/EtfReader.cs index 9fc7c852ff..0eeee41160 100644 --- a/src/etf/DSharpPlus.Etf/Serialization/EtfReader.cs +++ b/src/etf/DSharpPlus.Etf/Serialization/EtfReader.cs @@ -116,12 +116,12 @@ ValueStack objects throw new ArgumentException("Inconsistent maximum depth between object lengths and object types."); } - if (this.data[0] != 0x83) + if (data[0] != 0x83) { throw new ArgumentException("The data was provided in a wrong format or format version."); } - if (this.data[1] == 0x50) + if (data[1] == 0x50) { throw new ArgumentException("Compressed data cannot be processed."); } diff --git a/tests/etf/DSharpPlus.Etf.Tests/DSharpPlus.Etf.Tests.csproj b/tests/etf/DSharpPlus.Etf.Tests/DSharpPlus.Etf.Tests.csproj new file mode 100644 index 0000000000..3203956e96 --- /dev/null +++ b/tests/etf/DSharpPlus.Etf.Tests/DSharpPlus.Etf.Tests.csproj @@ -0,0 +1,24 @@ + + + + net8.0 + enable + + false + true + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + + + + + diff --git a/tests/etf/DSharpPlus.Etf.Tests/Serialization/EtfReaderTests/IntegerPrimitives.cs b/tests/etf/DSharpPlus.Etf.Tests/Serialization/EtfReaderTests/IntegerPrimitives.cs new file mode 100644 index 0000000000..4c41968e7f --- /dev/null +++ b/tests/etf/DSharpPlus.Etf.Tests/Serialization/EtfReaderTests/IntegerPrimitives.cs @@ -0,0 +1,78 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; + +using DSharpPlus.Etf.Serialization; + +using Xunit; + +namespace DSharpPlus.Etf.Tests.Serialization.EtfReaderTests; + +/// +/// Contains tests for the two integer primitives and reading them as other integer types. +/// +public class IntegerPrimitives +{ + private static readonly byte[] payload = + [ + // ETF version header + 0x83, + + // 32-bit integer + 0x62, 0x00, 0x00, 0x00, 0x04, + + // 8-bit integer + 0x61, 0x07 + ]; + + /// + /// Tests reading the first 32-bit integer. + /// + [Fact] + public void TestReadingInt32() + { + ReadOnlySpan span = [.. payload]; + EtfReader reader = new + ( + span, + stackalloc uint[1], + stackalloc TermType[1] + ); + + Assert.True(reader.Read()); + Assert.Equal(TermType.Integer, reader.TermType); + Assert.Equal(4, reader.ReadInt32()); + Assert.Equal(4, reader.ReadInt64()); + Assert.Equal(4, reader.ReadInt16()); + Assert.Equal(4UL, reader.ReadUInt64()); + + Assert.True(reader.Read()); + } + + /// + /// Tests reading the second 8-bit integer. + /// + [Fact] + public void TestReadingByte() + { + ReadOnlySpan span = [.. payload]; + EtfReader reader = new + ( + span, + stackalloc uint[1], + stackalloc TermType[1] + ); + + // discard the first term + _ = reader.Read(); + + Assert.True(reader.Read()); + Assert.Equal(TermType.SmallInteger, reader.TermType); + Assert.Equal(7, reader.ReadInt32()); + Assert.Equal(7, reader.ReadByte()); + Assert.Equal(7, reader.ReadInt16()); + Assert.Equal(7, reader.ReadSByte()); + } +} From bf9b4b7f55c11faa87e9389cd0ea1d3e9b1effe3 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sat, 23 Sep 2023 22:35:45 +0200 Subject: [PATCH 125/323] update the comment to reflect the current implementation --- .../DSharpPlus.Etf/Serialization/EtfReader.Integers.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Integers.cs b/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Integers.cs index db1460d4a7..85f54f1d81 100644 --- a/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Integers.cs +++ b/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Integers.cs @@ -63,14 +63,16 @@ private readonly BigInteger ReadBigIntegerCore() * safety rules, so we can't simplify it: * TNumber value = Unsafe.ReadUnaligned(ref this.CurrentTermContents[1]); * - * 2. using Unsafe.ReadUnaligned over TNumber.ReadLittleEndian is done for the same reason: - * avoiding the slice associated with starting at byte 1 rather than byte 0 + * 2. using Unsafe.CopyBlockUnaligned into the on-stack value versus doing literally anything + * else is done to avoid a copy and allocating an extra 8 bytes on the stack; even though + * stack-allocs are cheap they're not free. * * 3. in the signed implementation we use MemoryMarshal.GetReference(this.CurrentTermContents) over * just this.CurrentTermContents[0], which elides a range check that at this point we know to be * unnecessary but that still poses a branch the branch predictor has to deal with. oddly, * removing that branch also causes the JIT to optimize the ternary operator to a conditional - * move, which actually makes this code entirely branchless. + * move, reducing this code to only one branch from a CopyBlockUnaligned-induced check that we + * can't get rid of, to my knowledge. ***************************************************************************************************/ /// From 32f94e3de182586ab6f378bc802c98a5584e8318 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sun, 24 Sep 2023 12:12:21 +0200 Subject: [PATCH 126/323] remove leftovers from when fast-path BigInteger reading was restricted to full-length payloads --- .../Serialization/EtfReader.Integers.cs | 56 ++++++------------- 1 file changed, 16 insertions(+), 40 deletions(-) diff --git a/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Integers.cs b/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Integers.cs index 85f54f1d81..0f70ede347 100644 --- a/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Integers.cs +++ b/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Integers.cs @@ -162,11 +162,8 @@ out sbyte value { if (this.TermType.IsBigInteger()) { - if (this.CurrentTermContents.Length >= 2) - { - value = this.ReadSignedIntegerFromBigInteger(); - return true; - } + value = this.ReadSignedIntegerFromBigInteger(); + return true; } else { @@ -192,11 +189,8 @@ out byte value { if (this.TermType.IsBigInteger()) { - if (this.CurrentTermContents.Length >= 2) - { - value = this.ReadUnsignedIntegerFromBigInteger(); - return true; - } + value = this.ReadUnsignedIntegerFromBigInteger(); + return true; } else { @@ -222,11 +216,8 @@ out short value { if (this.TermType.IsBigInteger()) { - if (this.CurrentTermContents.Length >= 3) - { - value = this.ReadSignedIntegerFromBigInteger(); - return true; - } + value = this.ReadSignedIntegerFromBigInteger(); + return true; } else { @@ -252,11 +243,8 @@ out ushort value { if (this.TermType.IsBigInteger()) { - if (this.CurrentTermContents.Length >= 3) - { - value = this.ReadUnsignedIntegerFromBigInteger(); - return true; - } + value = this.ReadUnsignedIntegerFromBigInteger(); + return true; } else { @@ -282,11 +270,8 @@ out int value { if (this.TermType.IsBigInteger()) { - if (this.CurrentTermContents.Length >= 5) - { - value = this.ReadSignedIntegerFromBigInteger(); - return true; - } + value = this.ReadSignedIntegerFromBigInteger(); + return true; } else { @@ -312,11 +297,8 @@ out uint value { if (this.TermType.IsBigInteger()) { - if (this.CurrentTermContents.Length >= 5) - { - value = this.ReadUnsignedIntegerFromBigInteger(); - return true; - } + value = this.ReadUnsignedIntegerFromBigInteger(); + return true; } else { @@ -342,11 +324,8 @@ out long value { if (this.TermType.IsBigInteger()) { - if (this.CurrentTermContents.Length >= 9) - { - value = this.ReadSignedIntegerFromBigInteger(); - return true; - } + value = this.ReadSignedIntegerFromBigInteger(); + return true; } else { @@ -372,11 +351,8 @@ out ulong value { if (this.TermType.IsBigInteger()) { - if (this.CurrentTermContents.Length >= 9) - { - value = this.ReadUnsignedIntegerFromBigInteger(); - return true; - } + value = this.ReadUnsignedIntegerFromBigInteger(); + return true; } else { From 893b5cc74ea464fe9d0444096bacf5b0fbd7c71b Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sun, 24 Sep 2023 13:54:47 +0200 Subject: [PATCH 127/323] fix a wrong byte number --- .../Serialization/EtfReader.Lexing.cs | 4 +- .../EtfReaderTests/BigIntegers.cs | 68 +++++++++++++++++++ 2 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 tests/etf/DSharpPlus.Etf.Tests/Serialization/EtfReaderTests/BigIntegers.cs diff --git a/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Lexing.cs b/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Lexing.cs index d9f09d938f..bcec2449fe 100644 --- a/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Lexing.cs +++ b/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Lexing.cs @@ -622,10 +622,10 @@ out bool success // the first byte here carries the sign if (this.index + 2 + length <= this.data.Length) { - this.CurrentTermContents = this.data.Slice(this.index + 1, (int)length + 1); + this.CurrentTermContents = this.data.Slice(this.index + 1, length + 1); success = true; - return (int)length + 5; + return length + 2; } } diff --git a/tests/etf/DSharpPlus.Etf.Tests/Serialization/EtfReaderTests/BigIntegers.cs b/tests/etf/DSharpPlus.Etf.Tests/Serialization/EtfReaderTests/BigIntegers.cs new file mode 100644 index 0000000000..ece32c5d67 --- /dev/null +++ b/tests/etf/DSharpPlus.Etf.Tests/Serialization/EtfReaderTests/BigIntegers.cs @@ -0,0 +1,68 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; +using System.Numerics; + +using DSharpPlus.Etf.Serialization; + +using Xunit; + +namespace DSharpPlus.Etf.Tests.Serialization.EtfReaderTests; + +/// +/// Contains tests for big integers and reading them as other integer types. +/// +public class BigIntegers +{ + private static readonly byte[] payload = + [ + // ETF version header + 0x83, + + // small big integer + 0x6E, 0x02, 0x00, 0x01, 0x01, + + // big big integer + 0x6F, 0x00, 0x00, 0x00, 0x02, 0x01, 0x01, 0x01 + ]; + + [Fact] + public void TestSmallBigInteger() + { + ReadOnlySpan span = [.. payload]; + EtfReader reader = new + ( + span, + stackalloc uint[1], + stackalloc TermType[1] + ); + + Assert.True(reader.Read()); + + Assert.Equal(TermType.SmallBig, reader.TermType); + Assert.Equal(new BigInteger(257), reader.ReadBigInteger()); + Assert.Equal(257UL, reader.ReadUInt64()); + } + + [Fact] + public void TestLargeBigInteger() + { + ReadOnlySpan span = [.. payload]; + EtfReader reader = new + ( + span, + stackalloc uint[1], + stackalloc TermType[1] + ); + + _ = reader.Read(); + + Assert.True(reader.Read()); + + Assert.Equal(TermType.LargeBig, reader.TermType); + Assert.Equal(new BigInteger(-257), reader.ReadBigInteger()); + Assert.Equal(-257L, reader.ReadInt64()); + } +} From 9a74ab0ec7c28550e4b3b7a50df0a66e4d6ebd9e Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sun, 24 Sep 2023 21:12:37 +0200 Subject: [PATCH 128/323] add a test for floats --- .../Serialization/EtfReaderTests/Floats.cs | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 tests/etf/DSharpPlus.Etf.Tests/Serialization/EtfReaderTests/Floats.cs diff --git a/tests/etf/DSharpPlus.Etf.Tests/Serialization/EtfReaderTests/Floats.cs b/tests/etf/DSharpPlus.Etf.Tests/Serialization/EtfReaderTests/Floats.cs new file mode 100644 index 0000000000..4cb5cd4d72 --- /dev/null +++ b/tests/etf/DSharpPlus.Etf.Tests/Serialization/EtfReaderTests/Floats.cs @@ -0,0 +1,72 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; + +using DSharpPlus.Etf.Serialization; + +using Xunit; + +namespace DSharpPlus.Etf.Tests.Serialization.EtfReaderTests; + +/// +/// Contains tests for the two float primitives. +/// +public class Floats +{ + private static readonly byte[] payload = + [ + // etf version header + 0x83, + + // new float term + 0x46, 0x40, 0x09, 0x21, 0xCA, 0xC0, 0x83, 0x12, 0x6F, + + // old float term + 0x63, 0x33, 0x2E, 0x31, 0x34, 0x31, 0x35, 0x39, 0x32, 0x36, 0x35, 0x33, 0x35, 0x38, 0x39, 0x37, + 0x39, 0x33, 0x32, 0x33, 0x38, 0x34, 0x36, 0x32, 0x36, 0x34, 0x33, 0x33, 0x38, 0x33, 0x32, 0x37 + ]; + + /// + /// Tests whether reading a new float works correctly. + /// + [Fact] + public void TestReadingNewFloat() + { + ReadOnlySpan span = [.. payload]; + EtfReader reader = new + ( + span, + stackalloc uint[1], + stackalloc TermType[1] + ); + + Assert.True(reader.Read()); + + Assert.Equal(3.1415, reader.ReadDouble(), 0.0001); + Assert.True(reader.TryReadHalf(out Half result)); + } + + /// + /// Tests whether reading an old float works correctly. + /// + [Fact] + public void TestReadingOldFloat() + { + ReadOnlySpan span = [.. payload]; + EtfReader reader = new + ( + span, + stackalloc uint[1], + stackalloc TermType[1] + ); + + _ = reader.Read(); + + Assert.True(reader.Read()); + + Assert.Equal(3.14159265358979323846264338327, reader.ReadDouble(), 0.0001); + Assert.True(reader.TryReadSingle(out float result)); + } +} From 6ca5dbbaee5781d5b88567ad7af479620c07493a Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Mon, 25 Sep 2023 11:31:04 +0200 Subject: [PATCH 129/323] rename the existing tests --- .../{BigIntegers.cs => PrimitiveTests.BigIntegers.cs} | 11 ++++------- .../{Floats.cs => PrimitiveTests.Floats.cs} | 11 ++++------- ...ntegerPrimitives.cs => PrimitiveTests.Integers.cs} | 10 +++++----- 3 files changed, 13 insertions(+), 19 deletions(-) rename tests/etf/DSharpPlus.Etf.Tests/Serialization/EtfReaderTests/{BigIntegers.cs => PrimitiveTests.BigIntegers.cs} (83%) rename tests/etf/DSharpPlus.Etf.Tests/Serialization/EtfReaderTests/{Floats.cs => PrimitiveTests.Floats.cs} (87%) rename tests/etf/DSharpPlus.Etf.Tests/Serialization/EtfReaderTests/{IntegerPrimitives.cs => PrimitiveTests.Integers.cs} (86%) diff --git a/tests/etf/DSharpPlus.Etf.Tests/Serialization/EtfReaderTests/BigIntegers.cs b/tests/etf/DSharpPlus.Etf.Tests/Serialization/EtfReaderTests/PrimitiveTests.BigIntegers.cs similarity index 83% rename from tests/etf/DSharpPlus.Etf.Tests/Serialization/EtfReaderTests/BigIntegers.cs rename to tests/etf/DSharpPlus.Etf.Tests/Serialization/EtfReaderTests/PrimitiveTests.BigIntegers.cs index ece32c5d67..48a6cb13e4 100644 --- a/tests/etf/DSharpPlus.Etf.Tests/Serialization/EtfReaderTests/BigIntegers.cs +++ b/tests/etf/DSharpPlus.Etf.Tests/Serialization/EtfReaderTests/PrimitiveTests.BigIntegers.cs @@ -11,12 +11,9 @@ namespace DSharpPlus.Etf.Tests.Serialization.EtfReaderTests; -/// -/// Contains tests for big integers and reading them as other integer types. -/// -public class BigIntegers +partial class PrimitiveTests { - private static readonly byte[] payload = + private static readonly byte[] bigIntegerPayload = [ // ETF version header 0x83, @@ -31,7 +28,7 @@ public class BigIntegers [Fact] public void TestSmallBigInteger() { - ReadOnlySpan span = [.. payload]; + ReadOnlySpan span = [.. bigIntegerPayload]; EtfReader reader = new ( span, @@ -49,7 +46,7 @@ stackalloc TermType[1] [Fact] public void TestLargeBigInteger() { - ReadOnlySpan span = [.. payload]; + ReadOnlySpan span = [.. bigIntegerPayload]; EtfReader reader = new ( span, diff --git a/tests/etf/DSharpPlus.Etf.Tests/Serialization/EtfReaderTests/Floats.cs b/tests/etf/DSharpPlus.Etf.Tests/Serialization/EtfReaderTests/PrimitiveTests.Floats.cs similarity index 87% rename from tests/etf/DSharpPlus.Etf.Tests/Serialization/EtfReaderTests/Floats.cs rename to tests/etf/DSharpPlus.Etf.Tests/Serialization/EtfReaderTests/PrimitiveTests.Floats.cs index 4cb5cd4d72..e97b6886bf 100644 --- a/tests/etf/DSharpPlus.Etf.Tests/Serialization/EtfReaderTests/Floats.cs +++ b/tests/etf/DSharpPlus.Etf.Tests/Serialization/EtfReaderTests/PrimitiveTests.Floats.cs @@ -10,12 +10,9 @@ namespace DSharpPlus.Etf.Tests.Serialization.EtfReaderTests; -/// -/// Contains tests for the two float primitives. -/// -public class Floats +partial class PrimitiveTests { - private static readonly byte[] payload = + private static readonly byte[] floatPayload = [ // etf version header 0x83, @@ -34,7 +31,7 @@ public class Floats [Fact] public void TestReadingNewFloat() { - ReadOnlySpan span = [.. payload]; + ReadOnlySpan span = [.. floatPayload]; EtfReader reader = new ( span, @@ -54,7 +51,7 @@ stackalloc TermType[1] [Fact] public void TestReadingOldFloat() { - ReadOnlySpan span = [.. payload]; + ReadOnlySpan span = [.. floatPayload]; EtfReader reader = new ( span, diff --git a/tests/etf/DSharpPlus.Etf.Tests/Serialization/EtfReaderTests/IntegerPrimitives.cs b/tests/etf/DSharpPlus.Etf.Tests/Serialization/EtfReaderTests/PrimitiveTests.Integers.cs similarity index 86% rename from tests/etf/DSharpPlus.Etf.Tests/Serialization/EtfReaderTests/IntegerPrimitives.cs rename to tests/etf/DSharpPlus.Etf.Tests/Serialization/EtfReaderTests/PrimitiveTests.Integers.cs index 4c41968e7f..856fd10555 100644 --- a/tests/etf/DSharpPlus.Etf.Tests/Serialization/EtfReaderTests/IntegerPrimitives.cs +++ b/tests/etf/DSharpPlus.Etf.Tests/Serialization/EtfReaderTests/PrimitiveTests.Integers.cs @@ -11,11 +11,11 @@ namespace DSharpPlus.Etf.Tests.Serialization.EtfReaderTests; /// -/// Contains tests for the two integer primitives and reading them as other integer types. +/// Contains tests for reading primitive types. /// -public class IntegerPrimitives +public partial class PrimitiveTests { - private static readonly byte[] payload = + private static readonly byte[] integerPayload = [ // ETF version header 0x83, @@ -33,7 +33,7 @@ public class IntegerPrimitives [Fact] public void TestReadingInt32() { - ReadOnlySpan span = [.. payload]; + ReadOnlySpan span = [.. integerPayload]; EtfReader reader = new ( span, @@ -57,7 +57,7 @@ stackalloc TermType[1] [Fact] public void TestReadingByte() { - ReadOnlySpan span = [.. payload]; + ReadOnlySpan span = [.. integerPayload]; EtfReader reader = new ( span, From 48235ca2843aaccd9b49453bfbf97248843964ad Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Mon, 25 Sep 2023 11:52:12 +0200 Subject: [PATCH 130/323] fix erroneous UTF-16 interpretation and add string tests --- .../Serialization/EtfReader.Lexing.cs | 2 +- .../Serialization/EtfReader.Strings.cs | 2 +- .../EtfReaderTests/PrimitiveTests.Strings.cs | 102 ++++++++++++++++++ 3 files changed, 104 insertions(+), 2 deletions(-) create mode 100644 tests/etf/DSharpPlus.Etf.Tests/Serialization/EtfReaderTests/PrimitiveTests.Strings.cs diff --git a/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Lexing.cs b/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Lexing.cs index bcec2449fe..6a603b3f4f 100644 --- a/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Lexing.cs +++ b/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Lexing.cs @@ -590,7 +590,7 @@ out bool success { if (this.index + 1 <= this.data.Length) { - byte length = this.data[this.index + 1]; + byte length = this.data[this.index]; if (this.index + 1 + length <= this.data.Length) { diff --git a/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Strings.cs b/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Strings.cs index 91b5cc35e2..7a48b519c1 100644 --- a/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Strings.cs +++ b/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Strings.cs @@ -24,7 +24,7 @@ out string? value { if (this.TermType.IsString()) { - value = Encoding.Unicode.GetString(this.CurrentTermContents); + value = Encoding.UTF8.GetString(this.CurrentTermContents); return true; } diff --git a/tests/etf/DSharpPlus.Etf.Tests/Serialization/EtfReaderTests/PrimitiveTests.Strings.cs b/tests/etf/DSharpPlus.Etf.Tests/Serialization/EtfReaderTests/PrimitiveTests.Strings.cs new file mode 100644 index 0000000000..4639d7f544 --- /dev/null +++ b/tests/etf/DSharpPlus.Etf.Tests/Serialization/EtfReaderTests/PrimitiveTests.Strings.cs @@ -0,0 +1,102 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; + +using DSharpPlus.Etf.Serialization; + +using Xunit; + +namespace DSharpPlus.Etf.Tests.Serialization.EtfReaderTests; + +partial class PrimitiveTests +{ + private static readonly byte[] stringPayload = + [ + // ETF version header + 0x83, + + // small utf8 atom + 0x77, 0x0C, 0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x57, 0x6F, 0x72, 0x6C, 0x64, 0x21, + + // large utf8 atom + 0x76, 0x00, 0x0C, 0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x57, 0x6F, 0x72, 0x6C, 0x64, 0x21, + + // string + 0x6B, 0x00, 0x0C, 0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x57, 0x6F, 0x72, 0x6C, 0x64, 0x21 + ]; + + /// + /// Tests deserialization of a small UTF8 atom. + /// + [Fact] + public void TestSmallUtf8Atom() + { + ReadOnlySpan span = [.. stringPayload]; + EtfReader reader = new + ( + span, + stackalloc uint[1], + stackalloc TermType[1] + ); + + Assert.True(reader.Read()); + + Assert.Equal("Hello World!", reader.ReadString()); + + Span buffer = stackalloc byte[12]; + reader.ReadUtf8String(buffer); + + Assert.True("Hello World!"u8.SequenceEqual(buffer)); + } + + /// + /// Tests deserialization of a large UTF8 atom. + /// + [Fact] + public void TestLargeUtf8Atom() + { + ReadOnlySpan span = [.. stringPayload]; + EtfReader reader = new + ( + span, + stackalloc uint[1], + stackalloc TermType[1] + ); + + _ = reader.Read(); + + Assert.True(reader.Read()); + + Assert.Equal("Hello World!", reader.ReadString()); + + Span buffer = stackalloc byte[12]; + reader.ReadUtf8String(buffer); + + Assert.True("Hello World!"u8.SequenceEqual(buffer)); + } + + /// + /// Tests deserialization of a string. + /// + [Fact] + public void TestString() + { + ReadOnlySpan span = [.. stringPayload]; + EtfReader reader = new + ( + span, + stackalloc uint[1], + stackalloc TermType[1] + ); + + _ = reader.Read(); + _ = reader.Read(); + + Assert.True(reader.Read()); + + Assert.Equal(TermType.String, reader.TermType); + Assert.Equal("Hello World!", reader.ReadString()); + } +} From df93fc624acb8d6b9b307d677d008ddaa33c9934 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Mon, 25 Sep 2023 21:35:42 +0200 Subject: [PATCH 131/323] fix a bunch of issues with regards to reading complex objects and lists in specific --- lib/bundles | 2 +- .../Serialization/EtfReader.Lexing.cs | 12 +-- .../DSharpPlus.Etf/Serialization/EtfReader.cs | 4 +- .../EtfReaderTests/StructureTests.Lists.cs | 78 +++++++++++++++++++ 4 files changed, 87 insertions(+), 9 deletions(-) create mode 100644 tests/etf/DSharpPlus.Etf.Tests/Serialization/EtfReaderTests/StructureTests.Lists.cs diff --git a/lib/bundles b/lib/bundles index e02be6dcd8..c8add31634 160000 --- a/lib/bundles +++ b/lib/bundles @@ -1 +1 @@ -Subproject commit e02be6dcd817312ed97d8cc0a2ada3b21e4a4db8 +Subproject commit c8add31634cc6b947f69976fd873895da393312c diff --git a/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Lexing.cs b/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Lexing.cs index 6a603b3f4f..004dcabfe0 100644 --- a/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Lexing.cs +++ b/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Lexing.cs @@ -255,7 +255,7 @@ out bool success /// /// Indicates whether the term was read successfully. /// The amount of bytes processed. - private readonly int LexLargeTuple + private int LexLargeTuple ( out bool success ) @@ -281,7 +281,7 @@ out bool success /// /// Indicates whether the term was read successfully. /// The amount of bytes processed. - private readonly int LexList + private int LexList ( out bool success ) @@ -291,7 +291,7 @@ out bool success ReadOnlySpan lengthSlice = this.data.Slice(this.index, 4); uint length = BinaryPrimitives.ReadUInt32BigEndian(lengthSlice); - this.complexObjects.Push(TermType.LargeTuple); + this.complexObjects.Push(TermType.List); // account for the null-terminator-that-may-not-actually-be-null-at-all this.remainingLengths.Push(length + 1); @@ -323,7 +323,7 @@ out bool success /// /// Indicates whether the term was read successfully. /// The amount of bytes processed. - private readonly int LexMap + private int LexMap ( out bool success ) @@ -333,7 +333,7 @@ out bool success ReadOnlySpan lengthSlice = this.data.Slice(this.index, 4); uint length = BinaryPrimitives.ReadUInt32BigEndian(lengthSlice); - this.complexObjects.Push(TermType.LargeTuple); + this.complexObjects.Push(TermType.Map); this.remainingLengths.Push(length * 2); success = true; @@ -660,7 +660,7 @@ out bool success /// /// Indicates whether the term was read successfully. /// The amount of bytes processed. - private readonly int LexSmallTuple + private int LexSmallTuple ( out bool success ) diff --git a/src/etf/DSharpPlus.Etf/Serialization/EtfReader.cs b/src/etf/DSharpPlus.Etf/Serialization/EtfReader.cs index 0eeee41160..fb0125e958 100644 --- a/src/etf/DSharpPlus.Etf/Serialization/EtfReader.cs +++ b/src/etf/DSharpPlus.Etf/Serialization/EtfReader.cs @@ -32,8 +32,8 @@ public ref partial struct EtfReader * where possible - which should be most cases. ***************************************************************************************************/ - private readonly ValueStack remainingLengths; - private readonly ValueStack complexObjects; + private ValueStack remainingLengths; + private ValueStack complexObjects; private readonly ReadOnlySpan data; diff --git a/tests/etf/DSharpPlus.Etf.Tests/Serialization/EtfReaderTests/StructureTests.Lists.cs b/tests/etf/DSharpPlus.Etf.Tests/Serialization/EtfReaderTests/StructureTests.Lists.cs new file mode 100644 index 0000000000..aa126da1c5 --- /dev/null +++ b/tests/etf/DSharpPlus.Etf.Tests/Serialization/EtfReaderTests/StructureTests.Lists.cs @@ -0,0 +1,78 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; + +using DSharpPlus.Etf.Serialization; + +using Xunit; + +namespace DSharpPlus.Etf.Tests.Serialization.EtfReaderTests; + +/// +/// Contains tests for correctly reading control structures. +/// +public partial class StructureTests +{ + private static readonly byte[] listPayload = + [ + // ETF version header + 0x83, + + // list introduction + 0x6C, 0x00, 0x00, 0x00, 0x02, + + // first child etf term + 0x62, 0x00, 0x00, 0x01, 0x00, + + // second child etf term + 0x62, 0x00, 0x00, 0x00, 0xFF, + + // null terminator + 0x6A, + + // term that isn't a child term + 0x61, 0x07 + ]; + + [Fact] + public void TestReadingList() + { + ReadOnlySpan span = [.. listPayload]; + EtfReader reader = new + ( + span, + stackalloc uint[1], + stackalloc TermType[1] + ); + + Assert.True(reader.Read()); + Assert.Equal(TermType.List, reader.TermType); + Assert.Equal(EtfTokenType.StartList, reader.TokenType); + + // the expected length here is 3: two items and the null terminator + // the null terminator doesn't actually need to be null, either, as per the specification, soo... + // https://www.erlang.org/doc/apps/erts/erl_ext_dist#list_ext + Assert.Equal((uint)3, reader.GetCurrentRemainingLength()); + + // test whether we correctly revert back to EtfTokenType.Term + Assert.True(reader.Read()); + Assert.Equal(EtfTokenType.Term, reader.TokenType); + + _ = reader.Read(); + + // are we null terminating correctly? + Assert.True(reader.Read()); + Assert.Equal(TermType.Nil, reader.TermType); + Assert.Equal((uint)0, reader.GetCurrentRemainingLength()); + + // are we synthesizing reads correctly + Assert.True(reader.Read()); + Assert.Equal(EtfTokenType.EndList, reader.TokenType); + + // are we reading the final term correctly? + Assert.True(reader.Read()); + Assert.Equal(TermType.SmallInteger, reader.TermType); + } +} From d71c16088a32400adddd90c4849b7c3ddfc2ac8f Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Mon, 25 Sep 2023 21:52:24 +0200 Subject: [PATCH 132/323] add a test for tuples --- .../EtfReaderTests/StructureTests.Tuples.cs | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 tests/etf/DSharpPlus.Etf.Tests/Serialization/EtfReaderTests/StructureTests.Tuples.cs diff --git a/tests/etf/DSharpPlus.Etf.Tests/Serialization/EtfReaderTests/StructureTests.Tuples.cs b/tests/etf/DSharpPlus.Etf.Tests/Serialization/EtfReaderTests/StructureTests.Tuples.cs new file mode 100644 index 0000000000..96c5317779 --- /dev/null +++ b/tests/etf/DSharpPlus.Etf.Tests/Serialization/EtfReaderTests/StructureTests.Tuples.cs @@ -0,0 +1,54 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; + +using DSharpPlus.Etf.Serialization; + +using Xunit; + +namespace DSharpPlus.Etf.Tests.Serialization.EtfReaderTests; + +partial class StructureTests +{ + private static readonly byte[] tuplePayload = + [ + // ETF version header + 0x83, + + // tuple + 0x68, 0x02, + + // first child term + 0x62, 0x00, 0x00, 0x00, 0x07, + + // second child term + 0x61, 0x7F + ]; + + [Fact] + public void TestReadingTuple() + { + ReadOnlySpan span = [.. tuplePayload]; + EtfReader reader = new + ( + span, + stackalloc uint[1], + stackalloc TermType[1] + ); + + Assert.True(reader.Read()); + Assert.Equal(TermType.SmallTuple, reader.TermType); + Assert.Equal(EtfTokenType.StartTuple, reader.TokenType); + + Assert.True(reader.Read()); + Assert.Equal((uint)1, reader.GetCurrentRemainingLength()); + + _ = reader.Read(); + + // are we correctly synthesizing the last end token, even if there is no actual data left? + Assert.True(reader.Read()); + Assert.Equal(EtfTokenType.EndTuple, reader.TokenType); + } +} From 2539b50a150c5567a56bd5ddcad9d340404cef75 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Mon, 25 Sep 2023 22:07:32 +0200 Subject: [PATCH 133/323] add a test for reading maps --- .../DSharpPlus.Etf/Serialization/EtfReader.cs | 11 ++-- .../EtfReaderTests/StructureTests.Maps.cs | 56 +++++++++++++++++++ 2 files changed, 62 insertions(+), 5 deletions(-) create mode 100644 tests/etf/DSharpPlus.Etf.Tests/Serialization/EtfReaderTests/StructureTests.Maps.cs diff --git a/src/etf/DSharpPlus.Etf/Serialization/EtfReader.cs b/src/etf/DSharpPlus.Etf/Serialization/EtfReader.cs index fb0125e958..51d4594665 100644 --- a/src/etf/DSharpPlus.Etf/Serialization/EtfReader.cs +++ b/src/etf/DSharpPlus.Etf/Serialization/EtfReader.cs @@ -138,11 +138,6 @@ ValueStack objects /// True if the term was read successfully. public bool Read() { - if (this.index + 1 == this.data.Length) - { - return false; - } - // ugly ETF hacks :3 // because ETF doesn't have end tokens (luckily!), we synthesize them here to be able to expose // an acceptable API without performance sacrifices @@ -161,6 +156,12 @@ public bool Read() return true; } + // now that we've handled synthesizing, check whether we can read a term + if (this.index + 1 == this.data.Length) + { + return false; + } + TermType term = (TermType)this.data[this.index++]; this.TermType = term; diff --git a/tests/etf/DSharpPlus.Etf.Tests/Serialization/EtfReaderTests/StructureTests.Maps.cs b/tests/etf/DSharpPlus.Etf.Tests/Serialization/EtfReaderTests/StructureTests.Maps.cs new file mode 100644 index 0000000000..1c11524b64 --- /dev/null +++ b/tests/etf/DSharpPlus.Etf.Tests/Serialization/EtfReaderTests/StructureTests.Maps.cs @@ -0,0 +1,56 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; + +using DSharpPlus.Etf.Serialization; + +using Xunit; + +namespace DSharpPlus.Etf.Tests.Serialization.EtfReaderTests; + +partial class StructureTests +{ + private static readonly byte[] mapPayload = + [ + // ETF version header + 0x83, + + // map header + 0x74, 0x00, 0x00, 0x00, 0x01, + + // key + 0x61, 0x07, + + // value + 0x61, 0x08 + ]; + + [Fact] + public void TestReadingMap() + { + ReadOnlySpan span = [.. mapPayload]; + EtfReader reader = new + ( + span, + stackalloc uint[1], + stackalloc TermType[1] + ); + + Assert.True(reader.Read()); + Assert.Equal(TermType.Map, reader.TermType); + Assert.Equal(EtfTokenType.StartMap, reader.TokenType); + + // key + Assert.True(reader.Read()); + Assert.Equal((uint)1, reader.GetCurrentRemainingLength()); + + // value + _ = reader.Read(); + + // are we correctly synthesizing the last end token, even if there is no actual data left? + Assert.True(reader.Read()); + Assert.Equal(EtfTokenType.EndMap, reader.TokenType); + } +} From 9b5009bfe89ed5b5d803abd34c4cb5cefbf50934 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Tue, 26 Sep 2023 12:41:07 +0200 Subject: [PATCH 134/323] test whether we fail on compressed root term --- .../DSharpPlus.Etf/Serialization/EtfReader.cs | 10 ++-- .../DSharpPlus.Etf.Tests.csproj | 1 + .../EtfReaderTests/ValidationTests.cs | 46 +++++++++++++++++++ 3 files changed, 52 insertions(+), 5 deletions(-) create mode 100644 tests/etf/DSharpPlus.Etf.Tests/Serialization/EtfReaderTests/ValidationTests.cs diff --git a/src/etf/DSharpPlus.Etf/Serialization/EtfReader.cs b/src/etf/DSharpPlus.Etf/Serialization/EtfReader.cs index 51d4594665..43651662ff 100644 --- a/src/etf/DSharpPlus.Etf/Serialization/EtfReader.cs +++ b/src/etf/DSharpPlus.Etf/Serialization/EtfReader.cs @@ -3,6 +3,7 @@ // file, You can obtain one at https://mozilla.org/MPL/2.0/. using System; +using System.IO; using Bundles.ValueCollections; @@ -74,7 +75,7 @@ ReadOnlySpan data /// /// The span containing the binary ETF to process. /// The maximum nesting depth for maps and lists. - /// Thrown if the root term was compressed. + /// Thrown if the root term was compressed. public EtfReader ( ReadOnlySpan data, @@ -101,9 +102,8 @@ int maxDepth /// The span containing the binary ETF to process. /// A stack-buffer for remaining object lengths. /// A stack-buffer for all complex objects. - /// - /// Thrown if the capacities of the two buffers do not match, or if the root term was compressed. - /// + /// Thrown if the capacities of the two buffers do not match. + /// Thrown if the root term was compressed. public EtfReader ( ReadOnlySpan data, @@ -123,7 +123,7 @@ ValueStack objects if (data[1] == 0x50) { - throw new ArgumentException("Compressed data cannot be processed."); + throw new InvalidDataException("Compressed data cannot be processed."); } this.data = data; diff --git a/tests/etf/DSharpPlus.Etf.Tests/DSharpPlus.Etf.Tests.csproj b/tests/etf/DSharpPlus.Etf.Tests/DSharpPlus.Etf.Tests.csproj index 3203956e96..3e6f76fad6 100644 --- a/tests/etf/DSharpPlus.Etf.Tests/DSharpPlus.Etf.Tests.csproj +++ b/tests/etf/DSharpPlus.Etf.Tests/DSharpPlus.Etf.Tests.csproj @@ -6,6 +6,7 @@ false true + $(NoWarn);CA1031 diff --git a/tests/etf/DSharpPlus.Etf.Tests/Serialization/EtfReaderTests/ValidationTests.cs b/tests/etf/DSharpPlus.Etf.Tests/Serialization/EtfReaderTests/ValidationTests.cs new file mode 100644 index 0000000000..b6e46f48a4 --- /dev/null +++ b/tests/etf/DSharpPlus.Etf.Tests/Serialization/EtfReaderTests/ValidationTests.cs @@ -0,0 +1,46 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; +using System.IO; + +using DSharpPlus.Etf.Serialization; + +using Xunit; + +namespace DSharpPlus.Etf.Tests.Serialization.EtfReaderTests; + +/// +/// Contains tests to see whether we complain correctly upon invalid data. +/// +public class ValidationTests +{ + private static readonly byte[] compressedPayload = [0x83, 0x50]; + + /// + /// Verifies whether the EtfReader correctly rejects a compressed term payload. + /// + [Fact] + public void TestFailingToReadCompressedPayload() + { + try + { + ReadOnlySpan span = [.. compressedPayload]; + EtfReader reader = new(span); + + // this should be unreachable + Assert.True(false); + } + catch (InvalidDataException) + { + // correct exception thrown + Assert.True(true); + } + catch + { + // specifically only that exception should be thrown + Assert.True(false); + } + } +} From 262e214c252ac97b416d1186b6479983df2bed56 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Tue, 26 Sep 2023 12:51:02 +0200 Subject: [PATCH 135/323] test failing on wrong versions and mismatched stacks --- .../DSharpPlus.Etf/Serialization/EtfReader.cs | 4 +- .../EtfReaderTests/ValidationTests.cs | 63 +++++++++++++++++++ 2 files changed, 65 insertions(+), 2 deletions(-) diff --git a/src/etf/DSharpPlus.Etf/Serialization/EtfReader.cs b/src/etf/DSharpPlus.Etf/Serialization/EtfReader.cs index 43651662ff..a4725ec268 100644 --- a/src/etf/DSharpPlus.Etf/Serialization/EtfReader.cs +++ b/src/etf/DSharpPlus.Etf/Serialization/EtfReader.cs @@ -103,7 +103,7 @@ int maxDepth /// A stack-buffer for remaining object lengths. /// A stack-buffer for all complex objects. /// Thrown if the capacities of the two buffers do not match. - /// Thrown if the root term was compressed. + /// Thrown if the root term was compressed or not correctly versioned. public EtfReader ( ReadOnlySpan data, @@ -118,7 +118,7 @@ ValueStack objects if (data[0] != 0x83) { - throw new ArgumentException("The data was provided in a wrong format or format version."); + throw new InvalidDataException("The data was provided in a wrong format or format version."); } if (data[1] == 0x50) diff --git a/tests/etf/DSharpPlus.Etf.Tests/Serialization/EtfReaderTests/ValidationTests.cs b/tests/etf/DSharpPlus.Etf.Tests/Serialization/EtfReaderTests/ValidationTests.cs index b6e46f48a4..53ec0ab973 100644 --- a/tests/etf/DSharpPlus.Etf.Tests/Serialization/EtfReaderTests/ValidationTests.cs +++ b/tests/etf/DSharpPlus.Etf.Tests/Serialization/EtfReaderTests/ValidationTests.cs @@ -43,4 +43,67 @@ public void TestFailingToReadCompressedPayload() Assert.True(false); } } + + /// + /// Presently, the only supported format version is 131 or 0x83 + /// + [Theory] + [InlineData(7)] + [InlineData(11)] + [InlineData(71)] + [InlineData(83)] + [InlineData(130)] + [InlineData(132)] + [InlineData(222)] +#pragma warning disable xUnit1026 // the analyzer isn't picking up on the collection expression + public void TestFailingOnInvalidVersion(byte version) +#pragma warning restore xUnit1026 + { + try + { + ReadOnlySpan span = [version]; + EtfReader reader = new(span); + + // this should be unreachable + Assert.True(false); + } + catch (InvalidDataException) + { + // correct exception thrown + Assert.True(true); + } + catch + { + // specifically only that exception should be thrown + Assert.True(false); + } + } + + [Fact] + public void TestFailingOnMismatchedStacks() + { + try + { + ReadOnlySpan span = [0x83]; + EtfReader reader = new + ( + span, + stackalloc uint[2], + stackalloc TermType[1] + ); + + // this should be unreachable + Assert.True(false); + } + catch (ArgumentException) + { + // correct exception thrown + Assert.True(true); + } + catch + { + // specifically only that exception should be thrown + Assert.True(false); + } + } } From 9c655e79d6f063993ea9709bcd86757adc455c4b Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Fri, 29 Sep 2023 16:17:58 +0200 Subject: [PATCH 136/323] rip out ETF in favor of the shared etf repo --- .gitmodules | 3 + DSharpPlus.sln | 19 - Directory.Build.props | 3 - lib/etf | 1 + src/etf/DSharpPlus.Etf.sln | 22 - src/etf/DSharpPlus.Etf/DSharpPlus.Etf.csproj | 12 - src/etf/DSharpPlus.Etf/EtfTokenType.cs | 44 -- .../Extensions/TermTypeExtensions.cs | 57 -- src/etf/DSharpPlus.Etf/Objects/NewPidTerm.cs | 31 - src/etf/DSharpPlus.Etf/Objects/NewPortTerm.cs | 26 - .../Objects/NewReferenceTerm.cs | 28 - .../Objects/NewerReferenceTerm.cs | 28 - src/etf/DSharpPlus.Etf/Objects/PidTerm.cs | 31 - src/etf/DSharpPlus.Etf/Objects/PortTerm.cs | 26 - src/etf/DSharpPlus.Etf/Objects/V4PortTerm.cs | 26 - .../Serialization/EtfReader.Erlang.cs | 459 ----------- .../Serialization/EtfReader.Floats.cs | 108 --- .../Serialization/EtfReader.Integers.cs | 517 ------------ .../Serialization/EtfReader.Lexing.cs | 741 ------------------ .../Serialization/EtfReader.Strings.cs | 74 -- .../DSharpPlus.Etf/Serialization/EtfReader.cs | 278 ------- .../Serialization/ThrowHelper.cs | 24 - src/etf/DSharpPlus.Etf/TermType.cs | 178 ----- .../DSharpPlus.Etf.Tests.csproj | 25 - .../PrimitiveTests.BigIntegers.cs | 65 -- .../EtfReaderTests/PrimitiveTests.Floats.cs | 69 -- .../EtfReaderTests/PrimitiveTests.Integers.cs | 78 -- .../EtfReaderTests/PrimitiveTests.Strings.cs | 102 --- .../EtfReaderTests/StructureTests.Lists.cs | 78 -- .../EtfReaderTests/StructureTests.Maps.cs | 56 -- .../EtfReaderTests/StructureTests.Tuples.cs | 54 -- .../EtfReaderTests/ValidationTests.cs | 109 --- 32 files changed, 4 insertions(+), 3368 deletions(-) create mode 160000 lib/etf delete mode 100644 src/etf/DSharpPlus.Etf.sln delete mode 100644 src/etf/DSharpPlus.Etf/DSharpPlus.Etf.csproj delete mode 100644 src/etf/DSharpPlus.Etf/EtfTokenType.cs delete mode 100644 src/etf/DSharpPlus.Etf/Extensions/TermTypeExtensions.cs delete mode 100644 src/etf/DSharpPlus.Etf/Objects/NewPidTerm.cs delete mode 100644 src/etf/DSharpPlus.Etf/Objects/NewPortTerm.cs delete mode 100644 src/etf/DSharpPlus.Etf/Objects/NewReferenceTerm.cs delete mode 100644 src/etf/DSharpPlus.Etf/Objects/NewerReferenceTerm.cs delete mode 100644 src/etf/DSharpPlus.Etf/Objects/PidTerm.cs delete mode 100644 src/etf/DSharpPlus.Etf/Objects/PortTerm.cs delete mode 100644 src/etf/DSharpPlus.Etf/Objects/V4PortTerm.cs delete mode 100644 src/etf/DSharpPlus.Etf/Serialization/EtfReader.Erlang.cs delete mode 100644 src/etf/DSharpPlus.Etf/Serialization/EtfReader.Floats.cs delete mode 100644 src/etf/DSharpPlus.Etf/Serialization/EtfReader.Integers.cs delete mode 100644 src/etf/DSharpPlus.Etf/Serialization/EtfReader.Lexing.cs delete mode 100644 src/etf/DSharpPlus.Etf/Serialization/EtfReader.Strings.cs delete mode 100644 src/etf/DSharpPlus.Etf/Serialization/EtfReader.cs delete mode 100644 src/etf/DSharpPlus.Etf/Serialization/ThrowHelper.cs delete mode 100644 src/etf/DSharpPlus.Etf/TermType.cs delete mode 100644 tests/etf/DSharpPlus.Etf.Tests/DSharpPlus.Etf.Tests.csproj delete mode 100644 tests/etf/DSharpPlus.Etf.Tests/Serialization/EtfReaderTests/PrimitiveTests.BigIntegers.cs delete mode 100644 tests/etf/DSharpPlus.Etf.Tests/Serialization/EtfReaderTests/PrimitiveTests.Floats.cs delete mode 100644 tests/etf/DSharpPlus.Etf.Tests/Serialization/EtfReaderTests/PrimitiveTests.Integers.cs delete mode 100644 tests/etf/DSharpPlus.Etf.Tests/Serialization/EtfReaderTests/PrimitiveTests.Strings.cs delete mode 100644 tests/etf/DSharpPlus.Etf.Tests/Serialization/EtfReaderTests/StructureTests.Lists.cs delete mode 100644 tests/etf/DSharpPlus.Etf.Tests/Serialization/EtfReaderTests/StructureTests.Maps.cs delete mode 100644 tests/etf/DSharpPlus.Etf.Tests/Serialization/EtfReaderTests/StructureTests.Tuples.cs delete mode 100644 tests/etf/DSharpPlus.Etf.Tests/Serialization/EtfReaderTests/ValidationTests.cs diff --git a/.gitmodules b/.gitmodules index 3ca45de881..8776756586 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "bundles"] path = lib/bundles url = https://github.com/dsharpplus/bundles.git +[submodule "etf"] + path = lib/etf + url = https://github.com/discord-lib-common/etfkit.git diff --git a/DSharpPlus.sln b/DSharpPlus.sln index d1e47d3183..e120012b89 100644 --- a/DSharpPlus.sln +++ b/DSharpPlus.sln @@ -30,14 +30,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DSharpPlus.SourceGenerators EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DSharpPlus.Core.Models.Tests", "tests\core\DSharpPlus.Core.Models.Tests\DSharpPlus.Core.Models.Tests.csproj", "{9F25D892-3CB0-4D47-B67D-D3FFFADC03E0}" EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Etf", "Etf", "{0BB713D0-63CC-4373-9C76-3C80611EFFA6}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DSharpPlus.Etf", "src\etf\DSharpPlus.ETF\DSharpPlus.Etf.csproj", "{96B95EF1-14FC-440F-B924-05E41929AA33}" -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Etf", "Etf", "{A4B153D7-B6D0-481B-843C-F5FD45A58697}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DSharpPlus.Etf.Tests", "tests\etf\DSharpPlus.Etf.Tests\DSharpPlus.Etf.Tests.csproj", "{82C085F7-EFFE-4252-9E66-43F4385AA706}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -72,14 +64,6 @@ Global {9F25D892-3CB0-4D47-B67D-D3FFFADC03E0}.Debug|Any CPU.Build.0 = Debug|Any CPU {9F25D892-3CB0-4D47-B67D-D3FFFADC03E0}.Release|Any CPU.ActiveCfg = Release|Any CPU {9F25D892-3CB0-4D47-B67D-D3FFFADC03E0}.Release|Any CPU.Build.0 = Release|Any CPU - {96B95EF1-14FC-440F-B924-05E41929AA33}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {96B95EF1-14FC-440F-B924-05E41929AA33}.Debug|Any CPU.Build.0 = Debug|Any CPU - {96B95EF1-14FC-440F-B924-05E41929AA33}.Release|Any CPU.ActiveCfg = Release|Any CPU - {96B95EF1-14FC-440F-B924-05E41929AA33}.Release|Any CPU.Build.0 = Release|Any CPU - {82C085F7-EFFE-4252-9E66-43F4385AA706}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {82C085F7-EFFE-4252-9E66-43F4385AA706}.Debug|Any CPU.Build.0 = Debug|Any CPU - {82C085F7-EFFE-4252-9E66-43F4385AA706}.Release|Any CPU.ActiveCfg = Release|Any CPU - {82C085F7-EFFE-4252-9E66-43F4385AA706}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -93,9 +77,6 @@ Global {21927A64-7345-4D90-9EE2-7FA4B1973AAC} = {EAE89CF5-AA91-4A22-9949-A46FAE1BF0D0} {98D2C52C-E3BA-4564-919C-750775B7BA9C} = {5FBB4590-56B0-453B-A87B-08A17C599B5C} {9F25D892-3CB0-4D47-B67D-D3FFFADC03E0} = {21927A64-7345-4D90-9EE2-7FA4B1973AAC} - {96B95EF1-14FC-440F-B924-05E41929AA33} = {0BB713D0-63CC-4373-9C76-3C80611EFFA6} - {A4B153D7-B6D0-481B-843C-F5FD45A58697} = {EAE89CF5-AA91-4A22-9949-A46FAE1BF0D0} - {82C085F7-EFFE-4252-9E66-43F4385AA706} = {A4B153D7-B6D0-481B-843C-F5FD45A58697} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {55CDA684-8900-479B-9DAE-BA3BE09B337B} diff --git a/Directory.Build.props b/Directory.Build.props index 1336ad6393..31a3a9a279 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -47,9 +47,6 @@ <_DSharpPlusCoreModelsVersion>0.1.0 - - - <_DSharpPlusEtfVersion>0.1.0 \ No newline at end of file diff --git a/lib/etf b/lib/etf new file mode 160000 index 0000000000..811229da20 --- /dev/null +++ b/lib/etf @@ -0,0 +1 @@ +Subproject commit 811229da20fd78ec9b6bbb2eb2c734a7c5f27132 diff --git a/src/etf/DSharpPlus.Etf.sln b/src/etf/DSharpPlus.Etf.sln deleted file mode 100644 index a73e281c85..0000000000 --- a/src/etf/DSharpPlus.Etf.sln +++ /dev/null @@ -1,22 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 17 -VisualStudioVersion = 17.0.31903.59 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DSharpPlus.Etf", "DSharpPlus.Etf\DSharpPlus.Etf.csproj", "{4739EC8E-C952-427B-8771-12645BF14997}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {4739EC8E-C952-427B-8771-12645BF14997}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {4739EC8E-C952-427B-8771-12645BF14997}.Debug|Any CPU.Build.0 = Debug|Any CPU - {4739EC8E-C952-427B-8771-12645BF14997}.Release|Any CPU.ActiveCfg = Release|Any CPU - {4739EC8E-C952-427B-8771-12645BF14997}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection -EndGlobal diff --git a/src/etf/DSharpPlus.Etf/DSharpPlus.Etf.csproj b/src/etf/DSharpPlus.Etf/DSharpPlus.Etf.csproj deleted file mode 100644 index 4022bc2e06..0000000000 --- a/src/etf/DSharpPlus.Etf/DSharpPlus.Etf.csproj +++ /dev/null @@ -1,12 +0,0 @@ - - - - true - $(_DSharpPlusEtfVersion) - - - - - - - diff --git a/src/etf/DSharpPlus.Etf/EtfTokenType.cs b/src/etf/DSharpPlus.Etf/EtfTokenType.cs deleted file mode 100644 index dd07d4c515..0000000000 --- a/src/etf/DSharpPlus.Etf/EtfTokenType.cs +++ /dev/null @@ -1,44 +0,0 @@ -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -namespace DSharpPlus.Etf; - -public enum EtfTokenType : byte -{ - - /// - /// A map token is started. - /// - StartMap, - - /// - /// A list token is started. - /// - StartList, - - /// - /// A tuple of any size is started. - /// - StartTuple, - - /// - /// Any term containing data. - /// - Term, - - /// - /// A map token is ended. - /// - EndMap, - - /// - /// A list token is ended. - /// - EndList, - - /// - /// A tuple of any size is ended. - /// - EndTuple -} diff --git a/src/etf/DSharpPlus.Etf/Extensions/TermTypeExtensions.cs b/src/etf/DSharpPlus.Etf/Extensions/TermTypeExtensions.cs deleted file mode 100644 index bc5f72269c..0000000000 --- a/src/etf/DSharpPlus.Etf/Extensions/TermTypeExtensions.cs +++ /dev/null @@ -1,57 +0,0 @@ -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -namespace DSharpPlus.Etf.Extensions; - -/// -/// Contains extensions on to reason about the .NET representation -/// of a given term. -/// -public static class TermTypeExtensions -{ - /// - /// Determines whether this term can be represented in .NET as a string. - /// - public static bool IsString - ( - this TermType term - ) - => term is TermType.AtomUtf8 or TermType.SmallAtomUtf8 or TermType.String; - - /// - /// Determines whether this term is an integer. - /// - public static bool IsInteger - ( - this TermType term - ) - => term is TermType.SmallBig or TermType.LargeBig or TermType.SmallInteger or TermType.Integer; - - /// - /// Determines whether this term is a big integer. - /// - public static bool IsBigInteger - ( - this TermType term - ) - => term is TermType.SmallBig or TermType.LargeBig; - - /// - /// Determines whether this term is a tuple. - /// - public static bool IsTuple - ( - this TermType term - ) - => term is TermType.SmallTuple or TermType.LargeTuple; - - /// - /// Determines whether this term is a float. - /// - public static bool IsFloat - ( - this TermType term - ) - => term is TermType.Float or TermType.NewFloat; -} diff --git a/src/etf/DSharpPlus.Etf/Objects/NewPidTerm.cs b/src/etf/DSharpPlus.Etf/Objects/NewPidTerm.cs deleted file mode 100644 index 588aed6fd6..0000000000 --- a/src/etf/DSharpPlus.Etf/Objects/NewPidTerm.cs +++ /dev/null @@ -1,31 +0,0 @@ -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -namespace DSharpPlus.Etf.Objects; - -/// -/// Represents a new Erlang process identifier object. -/// -public readonly record struct NewPidTerm -{ - /// - /// The originating node. - /// - public required string Node { get; init; } - - /// - /// The relevant ID. - /// - public required uint Id { get; init; } - - /// - /// The relevant serial number. - /// - public required uint Serial { get; init; } - - /// - /// An identifier indicating the incarnation of a node. - /// - public required uint Creation { get; init; } -} diff --git a/src/etf/DSharpPlus.Etf/Objects/NewPortTerm.cs b/src/etf/DSharpPlus.Etf/Objects/NewPortTerm.cs deleted file mode 100644 index 187edc3353..0000000000 --- a/src/etf/DSharpPlus.Etf/Objects/NewPortTerm.cs +++ /dev/null @@ -1,26 +0,0 @@ -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -namespace DSharpPlus.Etf.Objects; - -/// -/// Represents a new port in Erlang parlance. -/// -public readonly record struct NewPortTerm -{ - /// - /// The originating node. - /// - public required string Node { get; init; } - - /// - /// The relevant ID. - /// - public required uint Id { get; init; } - - /// - /// An identifier indicating the incarnation of a node. - /// - public required uint Creation { get; init; } -} diff --git a/src/etf/DSharpPlus.Etf/Objects/NewReferenceTerm.cs b/src/etf/DSharpPlus.Etf/Objects/NewReferenceTerm.cs deleted file mode 100644 index b889a86787..0000000000 --- a/src/etf/DSharpPlus.Etf/Objects/NewReferenceTerm.cs +++ /dev/null @@ -1,28 +0,0 @@ -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -using System.Collections.Generic; - -namespace DSharpPlus.Etf.Objects; - -/// -/// Represents a new Erlang reference term. -/// -public readonly record struct NewReferenceTerm -{ - /// - /// The originating node. - /// - public required string Node { get; init; } - - /// - /// An identifier indicating the incarnation of a node. - /// - public required byte Creation { get; init; } - - /// - /// The relevant ID, to be regarded as uninterpreted data. - /// - public required IReadOnlyList Id { get; init; } -} diff --git a/src/etf/DSharpPlus.Etf/Objects/NewerReferenceTerm.cs b/src/etf/DSharpPlus.Etf/Objects/NewerReferenceTerm.cs deleted file mode 100644 index 83a16446bc..0000000000 --- a/src/etf/DSharpPlus.Etf/Objects/NewerReferenceTerm.cs +++ /dev/null @@ -1,28 +0,0 @@ -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -using System.Collections.Generic; - -namespace DSharpPlus.Etf.Objects; - -/// -/// Represents a newer Erlang reference term. -/// -public readonly record struct NewerReferenceTerm -{ - /// - /// The originating node. - /// - public required string Node { get; init; } - - /// - /// An identifier indicating the incarnation of a node. - /// - public required uint Creation { get; init; } - - /// - /// The relevant ID, to be regarded as uninterpreted data. - /// - public required IReadOnlyList Id { get; init; } -} diff --git a/src/etf/DSharpPlus.Etf/Objects/PidTerm.cs b/src/etf/DSharpPlus.Etf/Objects/PidTerm.cs deleted file mode 100644 index f4d698ae51..0000000000 --- a/src/etf/DSharpPlus.Etf/Objects/PidTerm.cs +++ /dev/null @@ -1,31 +0,0 @@ -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -namespace DSharpPlus.Etf.Objects; - -/// -/// Represents an Erlang process identifier object. -/// -public readonly record struct PidTerm -{ - /// - /// The originating node. - /// - public required string Node { get; init; } - - /// - /// The relevant ID. - /// - public required uint Id { get; init; } - - /// - /// The relevant serial number. - /// - public required uint Serial { get; init; } - - /// - /// An identifier indicating the incarnation of a node. - /// - public required byte Creation { get; init; } -} diff --git a/src/etf/DSharpPlus.Etf/Objects/PortTerm.cs b/src/etf/DSharpPlus.Etf/Objects/PortTerm.cs deleted file mode 100644 index ebe08c3fc0..0000000000 --- a/src/etf/DSharpPlus.Etf/Objects/PortTerm.cs +++ /dev/null @@ -1,26 +0,0 @@ -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -namespace DSharpPlus.Etf.Objects; - -/// -/// Represents a port in Erlang parlance. -/// -public readonly record struct PortTerm -{ - /// - /// The originating node. - /// - public required string Node { get; init; } - - /// - /// The relevant ID. - /// - public required uint Id { get; init; } - - /// - /// An identifier indicating the incarnation of a node. - /// - public required byte Creation { get; init; } -} diff --git a/src/etf/DSharpPlus.Etf/Objects/V4PortTerm.cs b/src/etf/DSharpPlus.Etf/Objects/V4PortTerm.cs deleted file mode 100644 index bb87285e07..0000000000 --- a/src/etf/DSharpPlus.Etf/Objects/V4PortTerm.cs +++ /dev/null @@ -1,26 +0,0 @@ -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -namespace DSharpPlus.Etf.Objects; - -/// -/// Represents a new port in Erlang parlance. -/// -public readonly record struct V4PortTerm -{ - /// - /// The originating node. - /// - public required string Node { get; init; } - - /// - /// The relevant ID. - /// - public required ulong Id { get; init; } - - /// - /// An identifier indicating the incarnation of a node. - /// - public required uint Creation { get; init; } -} diff --git a/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Erlang.cs b/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Erlang.cs deleted file mode 100644 index 0a39474979..0000000000 --- a/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Erlang.cs +++ /dev/null @@ -1,459 +0,0 @@ -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -using System.Buffers.Binary; -using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; -using System.Text; - -using DSharpPlus.Etf.Objects; - -namespace DSharpPlus.Etf.Serialization; - -// here we deal with reading erlang-specific objects -// this doesn't need to be fast or anything, we just provide this for completeness -partial struct EtfReader -{ - /// - /// Convenience utility to read atom terms from the current term at the given offset. - /// - /// The offset to start at. This value will contain the final offset upon exit. - /// The read atom as string. - /// Whether the operation was successful. - private readonly bool TryReadAtom - ( - ref int offset, - - [NotNullWhen(true)] - out string? text - ) - { - if (this.CurrentTermContents.Length < offset + 2) - { - text = null; - return false; - } - - ushort length = BinaryPrimitives.ReadUInt16BigEndian(this.CurrentTermContents[offset..2]); - - text = Encoding.UTF8.GetString(this.CurrentTermContents[(offset + 2)..length]); - offset = length + 2; - return true; - } - - /// - /// Reads the current term as a port term. - /// - /// True if successful, false if unsuccessful. - public readonly bool TryReadPortTerm - ( - out PortTerm term - ) - { - int offset = 0; - - if (this.TermType != TermType.Port) - { - term = default; - return false; - } - - if (!this.TryReadAtom(ref offset, out string? node)) - { - term = default; - return false; - } - - if (this.CurrentTermContents.Length < offset + 5) - { - term = default; - return false; - } - - uint id = BinaryPrimitives.ReadUInt32BigEndian(this.CurrentTermContents[offset..4]); - byte creation = this.CurrentTermContents[^1]; - - term = new() - { - Node = node, - Id = id, - Creation = creation - }; - - return true; - } - - /// - /// Reads the current term as a new-port term. - /// - /// True if successful, false if unsuccessful. - public readonly bool TryReadNewPortTerm - ( - out NewPortTerm term - ) - { - int offset = 0; - - if (this.TermType != TermType.NewPort) - { - term = default; - return false; - } - - if (!this.TryReadAtom(ref offset, out string? node)) - { - term = default; - return false; - } - - if (this.CurrentTermContents.Length < offset + 8) - { - term = default; - return false; - } - - uint id = BinaryPrimitives.ReadUInt32BigEndian(this.CurrentTermContents[offset..4]); - uint creation = BinaryPrimitives.ReadUInt32BigEndian(this.CurrentTermContents[(offset + 4)..4]); - - term = new() - { - Node = node, - Id = id, - Creation = creation - }; - - return true; - } - - /// - /// Reads the current term as a v4-port term. - /// - /// True if successful, false if unsuccessful. - public readonly bool TryReadV4PortTerm - ( - out V4PortTerm term - ) - { - int offset = 0; - - if (this.TermType != TermType.V4Port) - { - term = default; - return false; - } - - if (!this.TryReadAtom(ref offset, out string? node)) - { - term = default; - return false; - } - - if (this.CurrentTermContents.Length < offset + 12) - { - term = default; - return false; - } - - ulong id = BinaryPrimitives.ReadUInt64BigEndian(this.CurrentTermContents[offset..8]); - uint creation = BinaryPrimitives.ReadUInt32BigEndian(this.CurrentTermContents[(offset + 8)..4]); - - term = new() - { - Node = node, - Id = id, - Creation = creation - }; - - return true; - } - - /// - /// Reads the current term as a PID term. - /// - /// True if successful, false if unsuccessful. - public readonly bool TryReadPidTerm - ( - out PidTerm term - ) - { - int offset = 0; - - if (this.TermType != TermType.Pid) - { - term = default; - return false; - } - - if (!this.TryReadAtom(ref offset, out string? node)) - { - term = default; - return false; - } - - if (this.CurrentTermContents.Length < offset + 9) - { - term = default; - return false; - } - - uint id = BinaryPrimitives.ReadUInt32BigEndian(this.CurrentTermContents[offset..4]); - uint serial = BinaryPrimitives.ReadUInt32BigEndian(this.CurrentTermContents[(offset + 4)..4]); - byte creation = this.CurrentTermContents[^1]; - - term = new() - { - Node = node, - Id = id, - Serial = serial, - Creation = creation - }; - - return true; - } - - /// - /// Reads the current term as a PID term. - /// - /// True if successful, false if unsuccessful. - public readonly bool TryReadNewPidTerm - ( - out NewPidTerm term - ) - { - int offset = 0; - - if (this.TermType != TermType.NewPid) - { - term = default; - return false; - } - - if (!this.TryReadAtom(ref offset, out string? node)) - { - term = default; - return false; - } - - if (this.CurrentTermContents.Length < offset + 9) - { - term = default; - return false; - } - - uint id = BinaryPrimitives.ReadUInt32BigEndian(this.CurrentTermContents[offset..4]); - uint serial = BinaryPrimitives.ReadUInt32BigEndian(this.CurrentTermContents[(offset + 4)..4]); - uint creation = BinaryPrimitives.ReadUInt32BigEndian(this.CurrentTermContents[(offset + 8)..4]); - - term = new() - { - Node = node, - Id = id, - Serial = serial, - Creation = creation - }; - - return true; - } - - /// - /// Reads the current term as a new reference term. - /// - /// True if successful, false if unsuccessful. - public readonly bool TryReadNewReferenceTerm - ( - out NewReferenceTerm term - ) - { - int offset = 2; - - if (this.TermType != TermType.NewReference) - { - term = default; - return false; - } - - ushort length = BinaryPrimitives.ReadUInt16BigEndian(this.CurrentTermContents[..2]); - - if (!this.TryReadAtom(ref offset, out string? node)) - { - term = default; - return false; - } - - if (this.CurrentTermContents.Length < offset + (length * 4) + 1) - { - term = default; - return false; - } - - byte creation = this.CurrentTermContents[offset++]; - - List id = new(length); - - for (int i = 0; i < length; i++) - { - id.Add(BinaryPrimitives.ReadUInt32BigEndian(this.CurrentTermContents[offset..4])); - offset += 4; - } - - term = new() - { - Node = node, - Creation = creation, - Id = id - }; - - return true; - } - - /// - /// Reads the current term as a newer reference term. - /// - /// True if successful, false if unsuccessful. - public readonly bool TryReadNewerReferenceTerm - ( - out NewerReferenceTerm term - ) - { - int offset = 2; - - if (this.TermType != TermType.NewReference) - { - term = default; - return false; - } - - ushort length = BinaryPrimitives.ReadUInt16BigEndian(this.CurrentTermContents[..2]); - - if (!this.TryReadAtom(ref offset, out string? node)) - { - term = default; - return false; - } - - if (this.CurrentTermContents.Length < offset + (length * 4) + 4) - { - term = default; - return false; - } - - uint creation = BinaryPrimitives.ReadUInt32BigEndian(this.CurrentTermContents[offset..4]); - offset += 4; - - List id = new(length); - - for (int i = 0; i < length; i++) - { - id.Add(BinaryPrimitives.ReadUInt32BigEndian(this.CurrentTermContents[offset..4])); - offset += 4; - } - - term = new() - { - Node = node, - Creation = creation, - Id = id - }; - - return true; - } - - /// - /// Reads the current term as port term. - /// - public readonly PortTerm ReadPortTerm() - { - if (this.TryReadPortTerm(out PortTerm term)) - { - return term; - } - - ThrowHelper.ThrowInvalidDecode(typeof(PortTerm)); - return default; - } - - /// - /// Reads the current term as new port term. - /// - public readonly NewPortTerm ReadNewPortTerm() - { - if (this.TryReadNewPortTerm(out NewPortTerm term)) - { - return term; - } - - ThrowHelper.ThrowInvalidDecode(typeof(NewPortTerm)); - return default; - } - - /// - /// Reads the current term as v4 port term. - /// - public readonly V4PortTerm ReadV4PortTerm() - { - if (this.TryReadV4PortTerm(out V4PortTerm term)) - { - return term; - } - - ThrowHelper.ThrowInvalidDecode(typeof(V4PortTerm)); - return default; - } - - /// - /// Reads the current term as PID term. - /// - public readonly PidTerm ReadPidTerm() - { - if (this.TryReadPidTerm(out PidTerm term)) - { - return term; - } - - ThrowHelper.ThrowInvalidDecode(typeof(PidTerm)); - return default; - } - - /// - /// Reads the current term as new PID term. - /// - public readonly NewPidTerm ReadNewPidTerm() - { - if (this.TryReadNewPidTerm(out NewPidTerm term)) - { - return term; - } - - ThrowHelper.ThrowInvalidDecode(typeof(NewPidTerm)); - return default; - } - - /// - /// Reads the current term as new reference term. - /// - public readonly NewReferenceTerm ReadNewReferenceTerm() - { - if (this.TryReadNewReferenceTerm(out NewReferenceTerm term)) - { - return term; - } - - ThrowHelper.ThrowInvalidDecode(typeof(NewReferenceTerm)); - return default; - } - - /// - /// Reads the current term as newer reference term. - /// - public readonly NewerReferenceTerm ReadNewerReferenceTerm() - { - if (this.TryReadNewerReferenceTerm(out NewerReferenceTerm term)) - { - return term; - } - - ThrowHelper.ThrowInvalidDecode(typeof(NewerReferenceTerm)); - return default; - } -} diff --git a/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Floats.cs b/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Floats.cs deleted file mode 100644 index 5f4bb7e41f..0000000000 --- a/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Floats.cs +++ /dev/null @@ -1,108 +0,0 @@ -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -using System; -using System.Buffers.Binary; -using System.Globalization; - -namespace DSharpPlus.Etf.Serialization; - -partial struct EtfReader -{ - /// - /// Reads the current term as a double. - /// - /// True if successful, false if unsuccessful. - public readonly bool TryReadDouble - ( - out double value - ) - { - switch (this.TermType) - { - case TermType.Float: - return double.TryParse(this.CurrentTermContents, CultureInfo.InvariantCulture, out value); - - case TermType.NewFloat: - value = BinaryPrimitives.ReadDoubleBigEndian(this.CurrentTermContents); - return true; - - default: - value = default; - return false; - } - } - - /// - /// Reads the current term as a float. - /// - /// True if successful, false if unsuccessful. - public readonly bool TryReadSingle - ( - out float value - ) - { - bool success = this.TryReadDouble(out double result); - - value = (float)result; - return success; - } - - /// - /// Reads the current term as a half. - /// - /// True if successful, false if unsuccessful. - public readonly bool TryReadHalf - ( - out Half value - ) - { - bool success = this.TryReadDouble(out double result); - - value = (Half)result; - return success; - } - - /// - /// Reads the current term as a double. - /// - public readonly double ReadDouble() - { - if (this.TryReadDouble(out double value)) - { - return value; - } - - ThrowHelper.ThrowInvalidDecode(typeof(double)); - return default; - } - - /// - /// Reads the current term as a float. - /// - public readonly float ReadSingle() - { - if (this.TryReadSingle(out float value)) - { - return value; - } - - ThrowHelper.ThrowInvalidDecode(typeof(float)); - return default; - } - - /// - /// Reads the current term as a half. - /// - public readonly Half ReadHalf() - { - if (this.TryReadHalf(out Half value)) - { - return value; - } - - ThrowHelper.ThrowInvalidDecode(typeof(Half)); - return default; - } -} diff --git a/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Integers.cs b/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Integers.cs deleted file mode 100644 index 0f70ede347..0000000000 --- a/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Integers.cs +++ /dev/null @@ -1,517 +0,0 @@ -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -using System.Buffers.Binary; -using System.Numerics; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -using DSharpPlus.Etf.Extensions; - -namespace DSharpPlus.Etf.Serialization; - -/******************************************************************************************************* -* here, we deal with parsing the ETF representation of integers into something .NET can use. -* -* in general, we want to offer methods to convert terms to all sane .NET representations, both in Try- -* and throwing variants; and for integers specifically we want to both offer truncating and checked -* methods for slimming an integer down. -* -* We want to define our Try- methods first and then implement throwing variants in the following form: -* -* public readonly Thing ReadThing() -* { -* if (this.TryReadThing(out Thing thing)) -* { -* return thing; -* } -* -* ThrowHelper.ThrowInvalidDecode(typeof(Thing)); -* return default!; -* } -* -* the last return doesn't actually matter, it is never invoked, roslyn just doesn't see through -* ThrowHelper calls always throwing and thinks this code is reachable. -*******************************************************************************************************/ - -partial struct EtfReader -{ - /// - /// Provides the implementation for reading either a or a - /// into a BigInteger. - /// - private readonly BigInteger ReadBigIntegerCore() - { - BigInteger value = new(this.CurrentTermContents[1..]); - - return MemoryMarshal.GetReference(this.CurrentTermContents) == 0 ? value : -value; - } - - /*************************************************************************************************** - * in the following section, we deal with handling BigInteger terms into primitive .NET - * representations. this is implemented using two very safe generic math methods that totally - * abstain from all cursed-ness... - * - * big integers are LITTLE ENDIAN, as opposed to everything else in the entire format, and we will - * make use of that. this code is written under the (reasonable) assumption that big endian machines - * are dead and that it will only run on little endian systems. - * - * there are rationales for all decisions, however scuffed they might look: - * - * 1. by using Unsafe.Add we elide a slice; and the following code is illegal under current ref - * safety rules, so we can't simplify it: - * TNumber value = Unsafe.ReadUnaligned(ref this.CurrentTermContents[1]); - * - * 2. using Unsafe.CopyBlockUnaligned into the on-stack value versus doing literally anything - * else is done to avoid a copy and allocating an extra 8 bytes on the stack; even though - * stack-allocs are cheap they're not free. - * - * 3. in the signed implementation we use MemoryMarshal.GetReference(this.CurrentTermContents) over - * just this.CurrentTermContents[0], which elides a range check that at this point we know to be - * unnecessary but that still poses a branch the branch predictor has to deal with. oddly, - * removing that branch also causes the JIT to optimize the ternary operator to a conditional - * move, reducing this code to only one branch from a CopyBlockUnaligned-induced check that we - * can't get rid of, to my knowledge. - ***************************************************************************************************/ - - /// - /// Provides the implementation for reading a unsigned integer from a currently provided - /// BigInteger term, ignoring the sign byte. - /// - private readonly unsafe TNumber ReadUnsignedIntegerFromBigInteger() - where TNumber : unmanaged, IUnsignedNumber, IBinaryInteger - { - TNumber value = TNumber.Zero; - - Unsafe.CopyBlockUnaligned - ( - destination: &value, - source: Unsafe.AsPointer - ( - ref Unsafe.Add - ( - source: ref MemoryMarshal.GetReference(this.CurrentTermContents), - elementOffset: 1 - ) - ), - byteCount: (uint)this.CurrentTermContents.Length - 1 - ); - - return value; - } - - /// - /// Provides the implementation for reading a signed integer from a currently provided - /// BigInteger term. - /// - private readonly unsafe TNumber ReadSignedIntegerFromBigInteger() - where TNumber : unmanaged, IBinaryInteger, IMinMaxValue, ISignedNumber - { - TNumber value = TNumber.Zero; - - Unsafe.CopyBlockUnaligned - ( - destination: &value, - source: Unsafe.AsPointer - ( - ref Unsafe.Add - ( - source: ref MemoryMarshal.GetReference(this.CurrentTermContents), - elementOffset: 1 - ) - ), - byteCount: (uint)this.CurrentTermContents.Length - 1 - ); - - value &= TNumber.MaxValue; - - return MemoryMarshal.GetReference(this.CurrentTermContents) == 0 ? value : -value; - } - -#pragma warning disable CS8509 // switch expressions should handle every option; this one shouldn't - - /// - /// Provides the implementation for performing a truncating read from an integer term. - /// - private readonly TNumber ReadInteger() - where TNumber : IBinaryInteger - { - return this.TermType switch - { - TermType.Integer => - TNumber.CreateTruncating(BinaryPrimitives.ReadInt32BigEndian(this.CurrentTermContents)), - - TermType.SmallInteger => - TNumber.CreateTruncating((sbyte)MemoryMarshal.GetReference(this.CurrentTermContents)) - }; - } - -#pragma warning restore CS8509 - - /// - /// Reads the current term as a signed byte. - /// - /// True if successful, false if unsuccessful. - public readonly bool TryReadSByte - ( - out sbyte value - ) - { - if (this.TermType.IsInteger()) - { - if (this.TermType.IsBigInteger()) - { - value = this.ReadSignedIntegerFromBigInteger(); - return true; - } - else - { - value = this.ReadInteger(); - return true; - } - } - - value = default; - return false; - } - - /// - /// Reads the current term as an unsigned byte. - /// - /// True if successful, false if unsuccessful. - public readonly bool TryReadByte - ( - out byte value - ) - { - if (this.TermType.IsInteger()) - { - if (this.TermType.IsBigInteger()) - { - value = this.ReadUnsignedIntegerFromBigInteger(); - return true; - } - else - { - value = this.ReadInteger(); - return true; - } - } - - value = default; - return false; - } - - /// - /// Reads the current term as a short. - /// - /// True if successful, false if unsuccessful. - public readonly bool TryReadInt16 - ( - out short value - ) - { - if (this.TermType.IsInteger()) - { - if (this.TermType.IsBigInteger()) - { - value = this.ReadSignedIntegerFromBigInteger(); - return true; - } - else - { - value = this.ReadInteger(); - return true; - } - } - - value = default; - return false; - } - - /// - /// Reads the current term as a ushort. - /// - /// True if successful, false if unsuccessful. - public readonly bool TryReadUInt16 - ( - out ushort value - ) - { - if (this.TermType.IsInteger()) - { - if (this.TermType.IsBigInteger()) - { - value = this.ReadUnsignedIntegerFromBigInteger(); - return true; - } - else - { - value = this.ReadInteger(); - return true; - } - } - - value = default; - return false; - } - - /// - /// Reads the current term as an int. - /// - /// True if successful, false if unsuccessful. - public readonly bool TryReadInt32 - ( - out int value - ) - { - if (this.TermType.IsInteger()) - { - if (this.TermType.IsBigInteger()) - { - value = this.ReadSignedIntegerFromBigInteger(); - return true; - } - else - { - value = this.ReadInteger(); - return true; - } - } - - value = default; - return false; - } - - /// - /// Reads the current term as a uint. - /// - /// True if successful, false if unsuccessful. - public readonly bool TryReadUInt32 - ( - out uint value - ) - { - if (this.TermType.IsInteger()) - { - if (this.TermType.IsBigInteger()) - { - value = this.ReadUnsignedIntegerFromBigInteger(); - return true; - } - else - { - value = this.ReadInteger(); - return true; - } - } - - value = default; - return false; - } - - /// - /// Reads the current term as a long. - /// - /// True if successful, false if unsuccessful. - public readonly bool TryReadInt64 - ( - out long value - ) - { - if (this.TermType.IsInteger()) - { - if (this.TermType.IsBigInteger()) - { - value = this.ReadSignedIntegerFromBigInteger(); - return true; - } - else - { - value = this.ReadInteger(); - return true; - } - } - - value = default; - return false; - } - - /// - /// Reads the current term as a ulong. - /// - /// True if successful, false if unsuccessful. - public readonly bool TryReadUInt64 - ( - out ulong value - ) - { - if (this.TermType.IsInteger()) - { - if (this.TermType.IsBigInteger()) - { - value = this.ReadUnsignedIntegerFromBigInteger(); - return true; - } - else - { - value = this.ReadInteger(); - return true; - } - } - - value = default; - return false; - } - - /// - /// Reads the current term as a BigInteger. - /// - /// True if successful, false if unsuccessful. - public readonly bool TryReadBigInteger - ( - out BigInteger value - ) - { - if (this.TermType.IsBigInteger()) - { - value = this.ReadBigIntegerCore(); - return true; - } - else if (this.TermType.IsInteger()) - { - value = new BigInteger(this.ReadInteger()); - return true; - } - - value = default; - return false; - } - - /// - /// Reads the current term as an sbyte. - /// - public readonly sbyte ReadSByte() - { - if (this.TryReadSByte(out sbyte value)) - { - return value; - } - - ThrowHelper.ThrowInvalidDecode(typeof(sbyte)); - return default; - } - - /// - /// Reads the current term as a byte. - /// - public readonly byte ReadByte() - { - if (this.TryReadByte(out byte value)) - { - return value; - } - - ThrowHelper.ThrowInvalidDecode(typeof(byte)); - return default; - } - - /// - /// Reads the current term as a short. - /// - public readonly short ReadInt16() - { - if (this.TryReadInt16(out short value)) - { - return value; - } - - ThrowHelper.ThrowInvalidDecode(typeof(short)); - return default; - } - - /// - /// Reads the current term as a ushort. - /// - public readonly ushort ReadUInt16() - { - if (this.TryReadUInt16(out ushort value)) - { - return value; - } - - ThrowHelper.ThrowInvalidDecode(typeof(ushort)); - return default; - } - - /// - /// Reads the current term as an int. - /// - public readonly int ReadInt32() - { - if (this.TryReadInt32(out int value)) - { - return value; - } - - ThrowHelper.ThrowInvalidDecode(typeof(int)); - return default; - } - - /// - /// Reads the current term as a uint. - /// - public readonly uint ReadUInt32() - { - if (this.TryReadUInt32(out uint value)) - { - return value; - } - - ThrowHelper.ThrowInvalidDecode(typeof(uint)); - return default; - } - - /// - /// Reads the current term as a long. - /// - public readonly long ReadInt64() - { - if (this.TryReadInt64(out long value)) - { - return value; - } - - ThrowHelper.ThrowInvalidDecode(typeof(long)); - return default; - } - - /// - /// Reads the current term as a ulong. - /// - public readonly ulong ReadUInt64() - { - if (this.TryReadUInt64(out ulong value)) - { - return value; - } - - ThrowHelper.ThrowInvalidDecode(typeof(ulong)); - return default; - } - - /// - /// Reads the current term as a BigInteger. - /// - public readonly BigInteger ReadBigInteger() - { - if (this.TryReadBigInteger(out BigInteger value)) - { - return value; - } - - ThrowHelper.ThrowInvalidDecode(typeof(BigInteger)); - return default; - } -} diff --git a/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Lexing.cs b/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Lexing.cs deleted file mode 100644 index 004dcabfe0..0000000000 --- a/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Lexing.cs +++ /dev/null @@ -1,741 +0,0 @@ -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -using System; -using System.Buffers.Binary; - -namespace DSharpPlus.Etf.Serialization; - -/******************************************************************************************************* -* here, we deal with preliminary lexing and length decoding of the next term ahead -* -* the pattern for all methods here is `int LexName(out bool success);` returning the length looked at -* and writing whether the procedure was successful to an out parameter. this enables somewhat cleaner -* aggregation in EtfReader.Read while not producing slower assembly, despite breaking convention of -* `bool TryLexName(out int length);` -* -* furthermore, in methods where there are only very few if statements with short bodies, the success -* path should be inside the first if tree, never branching to an - explicit or implicit - else. -* this is specifically designed to make branch predictors happy; from RyuJIT to the predictors in most -* CPUs, branch predictors usually expect the 'hottest'/most common path to be in the first if tree. -* this especially matters on apple silicon, where prediction failures are extremely expensive, and on -* intel x86 CPUs. -* in T1, the JIT generally picks up on it, but there's a throwhelper call associated with ROS.Slice that -* still causes marginal losses in T1, and much less marginal losses in the failure branch. -*******************************************************************************************************/ - -partial struct EtfReader -{ - /// - /// Lexes an atom-cache term, as per erl_ext_dist 4. - /// - /// Indicates whether the term was read successfully. - /// The amount of bytes processed. - private int LexAtomCache - ( - out bool success - ) - { - if (this.index + 1 <= this.data.Length) - { - this.CurrentTermContents = this.data.Slice(this.index, 1); - - success = true; - return 1; - } - - success = false; - return 0; - } - - /// - /// Lexes an atom-utf8 term, as per erl_ext_dist 30. - /// - /// Indicates whether the term was read successfully. - /// The amount of bytes processed. - private int LexAtomUtf8 - ( - out bool success - ) - { - if (this.index + 2 <= this.data.Length) - { - ReadOnlySpan lengthSlice = this.data.Slice(this.index, 2); - ushort length = BinaryPrimitives.ReadUInt16BigEndian(lengthSlice); - - if (this.index + 2 + length <= this.data.Length) - { - this.CurrentTermContents = this.data.Slice(this.index + 2, length); - - success = true; - return length + 2; - } - } - - success = false; - return 0; - } - - /// - /// Lexes a binary term, as per erl_ext_dist 19. - /// - /// Indicates whether the term was read successfully. - /// The amount of bytes processed. - private int LexBinary - ( - out bool success - ) - { - if (this.index + 4 <= this.data.Length) - { - ReadOnlySpan lengthSlice = this.data.Slice(this.index, 4); - uint length = BinaryPrimitives.ReadUInt32BigEndian(lengthSlice); - - if (this.index + 4 + length <= this.data.Length) - { - this.CurrentTermContents = this.data.Slice(this.index + 4, (int)length); - - success = true; - return (int)length + 4; - } - } - - success = false; - return 0; - } - - /// - /// Lexes a bit-binary term, as per erl_ext_dist 28. - /// - /// Indicates whether the term was read successfully. - /// The amount of bytes processed. - private int LexBitBinary - ( - out bool success - ) - { - if (this.index + 4 <= this.data.Length) - { - ReadOnlySpan lengthSlice = this.data.Slice(this.index, 4); - uint length = BinaryPrimitives.ReadUInt32BigEndian(lengthSlice); - - // we do this by simply prepending the raw span with the amount of valid bits in the last byte - if (this.index + 5 + length <= this.data.Length) - { - this.CurrentTermContents = this.data.Slice(this.index + 4, (int)length + 1); - - success = true; - return (int)length + 5; - } - } - - success = false; - return 0; - } - - /// - /// Lexes an export term, as per erl_ext_dist 27. - /// - /// Indicates whether the term was read successfully. - /// The amount of bytes processed. - private int LexExport - ( - out bool success - ) - { - // first atom: module name - if (this.index + 2 <= this.data.Length) - { - int accumulatedLength = 2; - - ReadOnlySpan lengthSlice = this.data.Slice(this.index, 2); - ushort length = BinaryPrimitives.ReadUInt16BigEndian(lengthSlice); - - accumulatedLength += length; - - // second atom: function name - if (this.index + accumulatedLength + 2 <= this.data.Length) - { - lengthSlice = this.data.Slice(this.index + accumulatedLength, 2); - length = BinaryPrimitives.ReadUInt16BigEndian(lengthSlice); - - accumulatedLength += 2 + length; - - // one byte for arity - if (this.index + ++accumulatedLength <= this.data.Length) - { - this.CurrentTermContents = this.data.Slice(this.index, accumulatedLength); - - success = true; - return accumulatedLength; - } - } - } - - success = false; - return 0; - } - - /// - /// Lexes a float term, as per erl_ext_dist 7. - /// - /// Indicates whether the term was read successfully. - /// The amount of bytes processed. - private int LexFloat - ( - out bool success - ) - { - if (this.index + 31 <= this.data.Length) - { - this.CurrentTermContents = this.data.Slice(this.index, 31); - - success = true; - return 31; - } - - success = false; - return 0; - } - - /// - /// Lexes an integer term, as per erl_ext_dist 6. - /// - /// Indicates whether the term was read successfully. - /// The amount of bytes processed. - private int LexInteger - ( - out bool success - ) - { - if (this.index + 4 <= this.data.Length) - { - this.CurrentTermContents = this.data.Slice(this.index, 4); - - success = true; - return 4; - } - - success = false; - return 0; - } - - /// - /// Lexes a large big-integer term, as per erl_ext_dist 21. - /// - /// Indicates whether the term was read successfully. - /// The amount of bytes processed. - private int LexLargeBigInteger - ( - out bool success - ) - { - if (this.index + 4 <= this.data.Length) - { - ReadOnlySpan lengthSlice = this.data.Slice(this.index, 4); - uint length = BinaryPrimitives.ReadUInt32BigEndian(lengthSlice); - - // the first byte here carries the sign - if (this.index + 5 + length <= this.data.Length) - { - this.CurrentTermContents = this.data.Slice(this.index + 4, (int)length + 1); - - success = true; - return (int)length + 5; - } - } - - success = false; - return 0; - } - - /// - /// Lexes a large tuple term, as per erl_ext_dist 14. - /// - /// Indicates whether the term was read successfully. - /// The amount of bytes processed. - private int LexLargeTuple - ( - out bool success - ) - { - if (this.index + 4 <= this.data.Length) - { - ReadOnlySpan lengthSlice = this.data.Slice(this.index, 4); - uint length = BinaryPrimitives.ReadUInt32BigEndian(lengthSlice); - - this.complexObjects.Push(TermType.LargeTuple); - this.remainingLengths.Push(length); - - success = true; - return 4; - } - - success = false; - return 0; - } - - /// - /// Lexes a list term, as per erl_ext_dist 18. - /// - /// Indicates whether the term was read successfully. - /// The amount of bytes processed. - private int LexList - ( - out bool success - ) - { - if (this.index + 4 <= this.data.Length) - { - ReadOnlySpan lengthSlice = this.data.Slice(this.index, 4); - uint length = BinaryPrimitives.ReadUInt32BigEndian(lengthSlice); - - this.complexObjects.Push(TermType.List); - - // account for the null-terminator-that-may-not-actually-be-null-at-all - this.remainingLengths.Push(length + 1); - - success = true; - return 4; - } - - success = false; - return 0; - } - - /// - /// Lexes a local term, as per erl_ext_dist 34. - /// - /// Indicates whether the term was read successfully. - /// The amount of bytes processed. - private static int LexLocal - ( - out bool success - ) - { - success = true; - return 0; - } - - /// - /// Lexes a map term, as per erl_ext_dist 15. - /// - /// Indicates whether the term was read successfully. - /// The amount of bytes processed. - private int LexMap - ( - out bool success - ) - { - if (this.index + 4 <= this.data.Length) - { - ReadOnlySpan lengthSlice = this.data.Slice(this.index, 4); - uint length = BinaryPrimitives.ReadUInt32BigEndian(lengthSlice); - - this.complexObjects.Push(TermType.Map); - this.remainingLengths.Push(length * 2); - - success = true; - return 4; - } - - success = false; - return 0; - } - - /// - /// Lexes a newer-reference term, as per erl_ext_dist 24. - /// - /// Indicates whether the term was read successfully. - /// The amount of bytes processed. - private int LexNewerReference - ( - out bool success - ) - { - if (this.index + 2 <= this.data.Length) - { - ReadOnlySpan lengthSlice = this.data.Slice(this.index, 2); - ushort idLength = BinaryPrimitives.ReadUInt16BigEndian(lengthSlice); - - // decode the atom node name - if (this.index + 4 <= this.data.Length) - { - lengthSlice = this.data.Slice(this.index + 2, 2); - ushort nodeLength = BinaryPrimitives.ReadUInt16BigEndian(lengthSlice); - - int accumulatedLength = (idLength * 4) + nodeLength + 8; - - if (this.index + accumulatedLength <= this.data.Length) - { - this.CurrentTermContents = this.data.Slice(this.index, accumulatedLength); - - success = true; - return accumulatedLength; - } - } - } - - success = false; - return 0; - } - - /// - /// Lexes a new-float term, as per erl_ext_dist 29. - /// - /// Indicates whether the term was read successfully. - /// The amount of bytes processed. - private int LexNewFloat - ( - out bool success - ) - { - if (this.index + 8 <= this.data.Length) - { - this.CurrentTermContents = this.data.Slice(this.index, 8); - - success = true; - return 8; - } - - success = false; - return 0; - } - - /// - /// Lexes a new-PID term, as per erl_ext_dist 12. - /// - /// Indicates whether the term was read successfully. - /// The amount of bytes processed. - private int LexNewPid - ( - out bool success - ) - { - if (this.index + 2 <= this.data.Length) - { - - ReadOnlySpan lengthSlice = this.data.Slice(this.index, 2); - int length = BinaryPrimitives.ReadUInt16BigEndian(lengthSlice); - - length += 14; - - if (this.index + length <= this.data.Length) - { - this.CurrentTermContents = this.data.Slice(this.index, length); - - success = true; - return length; - } - } - - success = false; - return 0; - } - - /// - /// Lexes a new-port term, as per erl_ext_dist 9. - /// - /// Indicates whether the term was read successfully. - /// The amount of bytes processed. - private int LexNewPort - ( - out bool success - ) - { - if (this.index + 2 <= this.data.Length) - { - - ReadOnlySpan lengthSlice = this.data.Slice(this.index, 2); - int length = BinaryPrimitives.ReadUInt16BigEndian(lengthSlice); - - length += 10; - - if (this.index + length <= this.data.Length) - { - this.CurrentTermContents = this.data.Slice(this.index, length); - - success = true; - return length; - } - } - - success = false; - return 0; - } - - /// - /// Lexes a new-reference term, as per erl_ext_dist 23. - /// - /// Indicates whether the term was read successfully. - /// The amount of bytes processed. - private int LexNewReference - ( - out bool success - ) - { - if (this.index + 2 <= this.data.Length) - { - ReadOnlySpan lengthSlice = this.data.Slice(this.index, 2); - ushort idLength = BinaryPrimitives.ReadUInt16BigEndian(lengthSlice); - - // decode the atom node name - if (this.index + 4 <= this.data.Length) - { - lengthSlice = this.data.Slice(this.index + 2, 2); - ushort nodeLength = BinaryPrimitives.ReadUInt16BigEndian(lengthSlice); - - int accumulatedLength = (idLength * 4) + nodeLength + 5; - - if (this.index + accumulatedLength <= this.data.Length) - { - this.CurrentTermContents = this.data.Slice(this.index, accumulatedLength); - - success = true; - return accumulatedLength; - } - } - } - - success = false; - return 0; - } - - /// - /// Lexes a nil term, as per erl_ext_dist 16. - /// - /// Indicates whether the term was read successfully. - /// The amount of bytes processed. - private static int LexNil - ( - out bool success - ) - { - success = true; - return 0; - } - - /// - /// Lexes a PID term, as per erl_ext_dist 11. - /// - /// Indicates whether the term was read successfully. - /// The amount of bytes processed. - private int LexPid - ( - out bool success - ) - { - if (this.index + 2 <= this.data.Length) - { - - ReadOnlySpan lengthSlice = this.data.Slice(this.index, 2); - int length = BinaryPrimitives.ReadUInt16BigEndian(lengthSlice); - - length += 11; - - if (this.index + length <= this.data.Length) - { - this.CurrentTermContents = this.data.Slice(this.index, length); - - success = true; - return length; - } - } - - success = false; - return 0; - } - - /// - /// Lexes a port term, as per erl_ext_dist 8. - /// - /// Indicates whether the term was read successfully. - /// The amount of bytes processed. - private int LexPort - ( - out bool success - ) - { - if (this.index + 2 <= this.data.Length) - { - - ReadOnlySpan lengthSlice = this.data.Slice(this.index, 2); - int length = BinaryPrimitives.ReadUInt16BigEndian(lengthSlice); - - length += 7; - - if (this.index + length <= this.data.Length) - { - this.CurrentTermContents = this.data.Slice(this.index, length); - - success = true; - return length; - } - } - - success = false; - return 0; - } - - /// - /// Lexes an atom-utf8 term, as per erl_ext_dist 30. - /// - /// Indicates whether the term was read successfully. - /// The amount of bytes processed. - private int LexSmallAtomUtf8 - ( - out bool success - ) - { - if (this.index + 1 <= this.data.Length) - { - byte length = this.data[this.index]; - - if (this.index + 1 + length <= this.data.Length) - { - this.CurrentTermContents = this.data.Slice(this.index + 1, length); - - success = true; - return length + 1; - } - } - - success = false; - return 0; - } - - /// - /// Lexes a small big-integer term, as per erl_ext_dist 21. - /// - /// Indicates whether the term was read successfully. - /// The amount of bytes processed. - private int LexSmallBigInteger - ( - out bool success - ) - { - if (this.index + 1 <= this.data.Length) - { - byte length = this.data[this.index]; - - // the first byte here carries the sign - if (this.index + 2 + length <= this.data.Length) - { - this.CurrentTermContents = this.data.Slice(this.index + 1, length + 1); - - success = true; - return length + 2; - } - } - - success = false; - return 0; - } - - /// - /// Lexes a small integer term, as per erl_ext_dist 5. - /// - /// Indicates whether the term was read successfully. - /// The amount of bytes processed. - private int LexSmallInteger - ( - out bool success - ) - { - if (this.index + 1 <= this.data.Length) - { - this.CurrentTermContents = this.data.Slice(this.index, 1); - - success = true; - return 1; - } - - success = false; - return 0; - } - - /// - /// Lexes a small tuple term, as per erl_ext_dist 13. - /// - /// Indicates whether the term was read successfully. - /// The amount of bytes processed. - private int LexSmallTuple - ( - out bool success - ) - { - if (this.index + 1 <= this.data.Length) - { - byte length = this.data[this.index]; - - this.complexObjects.Push(TermType.SmallTuple); - this.remainingLengths.Push(length); - - success = true; - return 1; - } - - success = false; - return 0; - } - - /// - /// Lexes a string term, as per erl_ext_dist 17. - /// - /// Indicates whether the term was read successfully. - /// The amount of bytes processed. - private int LexString - ( - out bool success - ) - { - if (this.index + 2 <= this.data.Length) - { - ReadOnlySpan lengthSlice = this.data.Slice(this.index, 2); - ushort length = BinaryPrimitives.ReadUInt16BigEndian(lengthSlice); - - if (this.index + 2 + length <= this.data.Length) - { - this.CurrentTermContents = this.data.Slice(this.index + 2, length); - - success = true; - return length + 2; - } - } - - success = false; - return 0; - } - - /// - /// Lexes a v4 port term, as per erl_ext_dist 10. - /// - /// Indicates whether the term was read successfully. - /// The amount of bytes processed. - private int LexV4Port - ( - out bool success - ) - { - if (this.index + 2 <= this.data.Length) - { - - ReadOnlySpan lengthSlice = this.data.Slice(this.index, 2); - int length = BinaryPrimitives.ReadUInt16BigEndian(lengthSlice); - - length += 14; - - if (this.index + length <= this.data.Length) - { - this.CurrentTermContents = this.data.Slice(this.index, length); - - success = true; - return length; - } - } - - success = false; - return 0; - } -} diff --git a/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Strings.cs b/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Strings.cs deleted file mode 100644 index 7a48b519c1..0000000000 --- a/src/etf/DSharpPlus.Etf/Serialization/EtfReader.Strings.cs +++ /dev/null @@ -1,74 +0,0 @@ -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -using System; -using System.Diagnostics.CodeAnalysis; -using System.Text; - -using DSharpPlus.Etf.Extensions; - -namespace DSharpPlus.Etf.Serialization; - -partial struct EtfReader -{ - /// - /// Reads the current term as a string. - /// - /// True if reading was successful, false if unsuccessful. - public readonly bool TryReadString - ( - [NotNullWhen(true)] - out string? value - ) - { - if (this.TermType.IsString()) - { - value = Encoding.UTF8.GetString(this.CurrentTermContents); - return true; - } - - value = default; - return false; - } - - /// - /// Copies the current term to a Span as UTF-8 string. - /// - /// True if successful, false if unsuccessful. - public readonly bool TryReadUtf8String - ( - Span buffer - ) - => this.TermType.IsString() && this.CurrentTermContents.TryCopyTo(buffer); - - /// - /// Reads the current term as a string. - /// - public readonly string ReadString() - { - if (this.TryReadString(out string? value)) - { - return value; - } - - ThrowHelper.ThrowInvalidDecode(typeof(string)); - return default!; - } - - /// - /// Copies the current term to a Span as UTF-8 string. - /// - public readonly void ReadUtf8String - ( - Span buffer - ) - { - if (this.TryReadUtf8String(buffer)) - { - return; - } - - ThrowHelper.ThrowInvalidDecode(typeof(string)); - } -} diff --git a/src/etf/DSharpPlus.Etf/Serialization/EtfReader.cs b/src/etf/DSharpPlus.Etf/Serialization/EtfReader.cs deleted file mode 100644 index a4725ec268..0000000000 --- a/src/etf/DSharpPlus.Etf/Serialization/EtfReader.cs +++ /dev/null @@ -1,278 +0,0 @@ -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -using System; -using System.IO; - -using Bundles.ValueCollections; - -namespace DSharpPlus.Etf.Serialization; - -/// -/// Provides a high-performance, low-allocation API for forward-only, read-only access to Erlang External -/// Term Format, version 131, encoded data. It processes binary data sequentially with no caching and -/// without support for non-standard data or older format versions, according to the specification at -/// . -/// This type does not support asynchronous reading nor reentrancy. -/// -/// -/// This type expects provided data to be uncompressed, that is, to not start with 0x8350. -/// -public ref partial struct EtfReader -{ - /*************************************************************************************************** - * do not change field order without accounting for struct layout -- this is an unmanaged struct; - * layout is explicit here! - * - * the current layout is putting the ValueStacks first, which are 24b each; then the spans, which - * are 16b each, then an integer and several byte-sized fields. this leads to 86 bytes used and 2 - * bytes padding required on 8-byte-aligned ABIs, 10 bytes padding on higher alignment. - * - * copying this struct will always split at least one cache line, so passing by ref is advised - * where possible - which should be most cases. - ***************************************************************************************************/ - - private ValueStack remainingLengths; - private ValueStack complexObjects; - - private readonly ReadOnlySpan data; - - /// - /// Gets the contents of the current term. Correctly interpreting this varies based on - /// , and may be invalid for terms that do not declare a body. - /// - public ReadOnlySpan CurrentTermContents { readonly get; private set; } - - // the weird ordering here is to keep struct layout intact - private int index; - - /// - /// Gets the type of the last read term. - /// - public TermType TermType { get; private set; } - - /// - /// Gets the type of the last token, which includes synthesized end tokens for all control structures. - /// - public EtfTokenType TokenType { get; private set; } - - /// - /// Constructs a new with a maximum depth of 256. - /// - /// The span containing the binary ETF to process. - public EtfReader - ( - ReadOnlySpan data - ) - : this(data, 256) - { - - } - - /// - /// Constructs a new with the specified maximum depth. - /// - /// The span containing the binary ETF to process. - /// The maximum nesting depth for maps and lists. - /// Thrown if the root term was compressed. - public EtfReader - ( - ReadOnlySpan data, - int maxDepth - ) - : this - ( - data, - new(new uint[maxDepth]), - new(new TermType[maxDepth]) - ) - { - - } - - /// - /// Constructs a new , using the specified buffers to store temporary metadata. - /// - /// - /// It is legal for call-sites to pass stackallocated ValueStack instances here, thereby eliminating two - /// array allocations. This is, however, illegal if the EtfReader is then passed down the stack, in which - /// case memory it depends on will be destroyed as part of the stack frame. - /// - /// The span containing the binary ETF to process. - /// A stack-buffer for remaining object lengths. - /// A stack-buffer for all complex objects. - /// Thrown if the capacities of the two buffers do not match. - /// Thrown if the root term was compressed or not correctly versioned. - public EtfReader - ( - ReadOnlySpan data, - ValueStack lengths, - ValueStack objects - ) - { - if (lengths.Capacity != objects.Capacity) - { - throw new ArgumentException("Inconsistent maximum depth between object lengths and object types."); - } - - if (data[0] != 0x83) - { - throw new InvalidDataException("The data was provided in a wrong format or format version."); - } - - if (data[1] == 0x50) - { - throw new InvalidDataException("Compressed data cannot be processed."); - } - - this.data = data; - this.remainingLengths = lengths; - this.complexObjects = objects; - this.index = 1; - } - - /// - /// Reads the next ETF term from the input source. - /// - /// True if the term was read successfully. - public bool Read() - { - // ugly ETF hacks :3 - // because ETF doesn't have end tokens (luckily!), we synthesize them here to be able to expose - // an acceptable API without performance sacrifices - // we also, importantly, do this BEFORE decoding the next term. - if (this.remainingLengths.Count != 0 && this.remainingLengths.Peek() == 0) - { - this.TokenType = this.complexObjects.Pop() switch - { - TermType.Map => EtfTokenType.EndMap, - TermType.List => EtfTokenType.EndList, - TermType.SmallTuple or TermType.LargeTuple => EtfTokenType.EndTuple, - _ => EtfTokenType.Term - }; - - this.remainingLengths.Pop(); - return true; - } - - // now that we've handled synthesizing, check whether we can read a term - if (this.index + 1 == this.data.Length) - { - return false; - } - - TermType term = (TermType)this.data[this.index++]; - - this.TermType = term; - this.TokenType = term switch - { - TermType.Map => EtfTokenType.StartMap, - TermType.List => EtfTokenType.StartList, - TermType.SmallTuple or TermType.LargeTuple => EtfTokenType.StartTuple, - _ => EtfTokenType.Term - }; - - bool success = false; - - // decrease lengths before potentially pushing a new length - if (this.complexObjects.Count != 0) - { - scoped ref uint currentLength = ref this.remainingLengths.PeekRef(); - currentLength--; - } - - this.index += term switch - { - TermType.AtomCache => LexAtomCache(out success), - TermType.AtomUtf8 => LexAtomUtf8(out success), - TermType.Binary => LexBinary(out success), - TermType.BitBinary => LexBitBinary(out success), - TermType.Export => LexExport(out success), - TermType.Float => LexFloat(out success), - TermType.Integer => LexInteger(out success), - TermType.LargeBig => LexLargeBigInteger(out success), - TermType.LargeTuple => LexLargeTuple(out success), - TermType.List => LexList(out success), - TermType.Local => LexLocal(out success), - TermType.Map => LexMap(out success), - TermType.NewerReference => LexNewerReference(out success), - TermType.NewFloat => LexNewFloat(out success), - TermType.NewPid => LexNewPid(out success), - TermType.NewPort => LexNewPort(out success), - TermType.NewReference => LexNewReference(out success), - TermType.Nil => LexNil(out success), - TermType.Pid => LexPid(out success), - TermType.Port => LexPort(out success), - TermType.SmallAtomUtf8 => LexSmallAtomUtf8(out success), - TermType.SmallBig => LexSmallBigInteger(out success), - TermType.SmallInteger => LexSmallInteger(out success), - TermType.SmallTuple => LexSmallTuple(out success), - TermType.String => LexString(out success), - TermType.V4Port => LexV4Port(out success), - _ => 0 - }; - - return success; - } - - // expose ways to just get raw memory - - /// - /// Copies the current term as raw memory. - /// - /// True if successful, false if unsuccessful. - public readonly bool TryReadMemory - ( - Span buffer - ) - => this.CurrentTermContents.TryCopyTo(buffer); - - /// - /// Copies the current term as raw memory. - /// - /// True if successful, false if unsuccessful. - public readonly bool TryReadMemory - ( - byte[] buffer - ) - => this.CurrentTermContents.TryCopyTo(buffer); - - /// - /// Copies the current term as raw memory. - /// - public readonly void ReadMemory - ( - Span buffer - ) - { - if (this.TryReadMemory(buffer)) - { - return; - } - - ThrowHelper.ThrowInvalidDecode(typeof(Span)); - } - - /// - /// Copies the current term as raw memory. - /// - public readonly void ReadMemory - ( - byte[] buffer - ) - { - if (this.TryReadMemory(buffer)) - { - return; - } - - ThrowHelper.ThrowInvalidDecode(typeof(byte[])); - } - - /// - /// Gets the remaining length of the current complex structure. - /// - public readonly uint GetCurrentRemainingLength() - => this.remainingLengths.Peek(); -} diff --git a/src/etf/DSharpPlus.Etf/Serialization/ThrowHelper.cs b/src/etf/DSharpPlus.Etf/Serialization/ThrowHelper.cs deleted file mode 100644 index fafe462a66..0000000000 --- a/src/etf/DSharpPlus.Etf/Serialization/ThrowHelper.cs +++ /dev/null @@ -1,24 +0,0 @@ -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; - -namespace DSharpPlus.Etf.Serialization; - -/// -/// Provides methods to relegate s to, to work around inlining limitations in the JIT. -/// -internal static class ThrowHelper -{ - [DoesNotReturn] - [DebuggerHidden] - [StackTraceHidden] - public static void ThrowInvalidDecode - ( - Type target - ) - => throw new InvalidOperationException($"Failed to decode the current term into an object of type {target}."); -} diff --git a/src/etf/DSharpPlus.Etf/TermType.cs b/src/etf/DSharpPlus.Etf/TermType.cs deleted file mode 100644 index 07ceb5e297..0000000000 --- a/src/etf/DSharpPlus.Etf/TermType.cs +++ /dev/null @@ -1,178 +0,0 @@ -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -namespace DSharpPlus.Etf; - -/// -/// Specifies the token type prefixes for each type, according to ERTS 14.0.2, format version 131. -/// -#pragma warning disable CA1008 // Enums should have zero value, the "none" value is 108 -public enum TermType : byte -#pragma warning restore CA1008 -{ - /// - /// erl_ext_dist 4 - /// - AtomCache = 82, - - /// - /// erl_ext_dist 5 - /// - SmallInteger = 97, - - /// - /// erl_ext_dist 6 - /// - Integer = 98, - - /// - /// erl_ext_dist 7 - /// - Float = 99, - - /// - /// erl_ext_dist 8 - /// - Port = 102, - - /// - /// erl_ext_dist 9 - /// - NewPort = 89, - - /// - /// erl_ext_dist 10 - /// - V4Port = 120, - - /// - /// erl_ext_dist 11 - /// - Pid = 103, - - /// - /// erl_ext_dist 12 - /// - NewPid = 88, - - /// - /// erl_ext_dist 13 - /// - SmallTuple = 104, - - /// - /// erl_ext_dist 14 - /// - LargeTuple = 105, - - /// - /// erl_ext_dist 15 - /// - Map = 116, - - /// - /// erl_ext_dist 16 - /// - Nil = 106, - - /// - /// erl_ext_dist 17 - /// - String = 107, - - /// - /// erl_ext_dist 18 - /// - List = 108, - - /// - /// erl_ext_dist 19 - /// - Binary = 109, - - /// - /// erl_ext_dist 20 - /// - SmallBig = 110, - - /// - /// erl_ext_dist 21 - /// - LargeBig = 111, - - // deprecated - // - // /// - // /// erl_ext_dist 22 - // /// - // Reference = 101, - - /// - /// erl_ext_dist 23 - /// - NewReference = 114, - - /// - /// erl_ext_dist 24 - /// - NewerReference = 90, - - // removed - // - // /// - // /// erl_ext_dist 25 - // /// - // Fun = 117, - // - // unsupported - // - // /// - // /// erl_ext_dist 26 - // /// - // NewFun = 112, - - /// - /// erl_ext_dist 27 - /// - Export = 113, - - /// - /// erl_ext_dist 28 - /// - BitBinary = 77, - - /// - /// erl_ext_dist 29 - /// - NewFloat = 70, - - /// - /// erl_ext_dist 30 - /// - AtomUtf8 = 118, - - /// - /// erl_ext_dist 31 - /// - SmallAtomUtf8 = 119, - - // deprecated - // - // /// - // /// erl_ext_dist 32 - // /// - // Atom = 100, - // - // deprecated - // - // /// - // /// erl_ext_dist 33 - // /// - // SmallAtom = 115, - - /// - /// erl_ext_dist 34 - /// - Local = 121, -} diff --git a/tests/etf/DSharpPlus.Etf.Tests/DSharpPlus.Etf.Tests.csproj b/tests/etf/DSharpPlus.Etf.Tests/DSharpPlus.Etf.Tests.csproj deleted file mode 100644 index 3e6f76fad6..0000000000 --- a/tests/etf/DSharpPlus.Etf.Tests/DSharpPlus.Etf.Tests.csproj +++ /dev/null @@ -1,25 +0,0 @@ - - - - net8.0 - enable - - false - true - $(NoWarn);CA1031 - - - - - - - runtime; build; native; contentfiles; analyzers; buildtransitive - all - - - - - - - - diff --git a/tests/etf/DSharpPlus.Etf.Tests/Serialization/EtfReaderTests/PrimitiveTests.BigIntegers.cs b/tests/etf/DSharpPlus.Etf.Tests/Serialization/EtfReaderTests/PrimitiveTests.BigIntegers.cs deleted file mode 100644 index 48a6cb13e4..0000000000 --- a/tests/etf/DSharpPlus.Etf.Tests/Serialization/EtfReaderTests/PrimitiveTests.BigIntegers.cs +++ /dev/null @@ -1,65 +0,0 @@ -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -using System; -using System.Numerics; - -using DSharpPlus.Etf.Serialization; - -using Xunit; - -namespace DSharpPlus.Etf.Tests.Serialization.EtfReaderTests; - -partial class PrimitiveTests -{ - private static readonly byte[] bigIntegerPayload = - [ - // ETF version header - 0x83, - - // small big integer - 0x6E, 0x02, 0x00, 0x01, 0x01, - - // big big integer - 0x6F, 0x00, 0x00, 0x00, 0x02, 0x01, 0x01, 0x01 - ]; - - [Fact] - public void TestSmallBigInteger() - { - ReadOnlySpan span = [.. bigIntegerPayload]; - EtfReader reader = new - ( - span, - stackalloc uint[1], - stackalloc TermType[1] - ); - - Assert.True(reader.Read()); - - Assert.Equal(TermType.SmallBig, reader.TermType); - Assert.Equal(new BigInteger(257), reader.ReadBigInteger()); - Assert.Equal(257UL, reader.ReadUInt64()); - } - - [Fact] - public void TestLargeBigInteger() - { - ReadOnlySpan span = [.. bigIntegerPayload]; - EtfReader reader = new - ( - span, - stackalloc uint[1], - stackalloc TermType[1] - ); - - _ = reader.Read(); - - Assert.True(reader.Read()); - - Assert.Equal(TermType.LargeBig, reader.TermType); - Assert.Equal(new BigInteger(-257), reader.ReadBigInteger()); - Assert.Equal(-257L, reader.ReadInt64()); - } -} diff --git a/tests/etf/DSharpPlus.Etf.Tests/Serialization/EtfReaderTests/PrimitiveTests.Floats.cs b/tests/etf/DSharpPlus.Etf.Tests/Serialization/EtfReaderTests/PrimitiveTests.Floats.cs deleted file mode 100644 index e97b6886bf..0000000000 --- a/tests/etf/DSharpPlus.Etf.Tests/Serialization/EtfReaderTests/PrimitiveTests.Floats.cs +++ /dev/null @@ -1,69 +0,0 @@ -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -using System; - -using DSharpPlus.Etf.Serialization; - -using Xunit; - -namespace DSharpPlus.Etf.Tests.Serialization.EtfReaderTests; - -partial class PrimitiveTests -{ - private static readonly byte[] floatPayload = - [ - // etf version header - 0x83, - - // new float term - 0x46, 0x40, 0x09, 0x21, 0xCA, 0xC0, 0x83, 0x12, 0x6F, - - // old float term - 0x63, 0x33, 0x2E, 0x31, 0x34, 0x31, 0x35, 0x39, 0x32, 0x36, 0x35, 0x33, 0x35, 0x38, 0x39, 0x37, - 0x39, 0x33, 0x32, 0x33, 0x38, 0x34, 0x36, 0x32, 0x36, 0x34, 0x33, 0x33, 0x38, 0x33, 0x32, 0x37 - ]; - - /// - /// Tests whether reading a new float works correctly. - /// - [Fact] - public void TestReadingNewFloat() - { - ReadOnlySpan span = [.. floatPayload]; - EtfReader reader = new - ( - span, - stackalloc uint[1], - stackalloc TermType[1] - ); - - Assert.True(reader.Read()); - - Assert.Equal(3.1415, reader.ReadDouble(), 0.0001); - Assert.True(reader.TryReadHalf(out Half result)); - } - - /// - /// Tests whether reading an old float works correctly. - /// - [Fact] - public void TestReadingOldFloat() - { - ReadOnlySpan span = [.. floatPayload]; - EtfReader reader = new - ( - span, - stackalloc uint[1], - stackalloc TermType[1] - ); - - _ = reader.Read(); - - Assert.True(reader.Read()); - - Assert.Equal(3.14159265358979323846264338327, reader.ReadDouble(), 0.0001); - Assert.True(reader.TryReadSingle(out float result)); - } -} diff --git a/tests/etf/DSharpPlus.Etf.Tests/Serialization/EtfReaderTests/PrimitiveTests.Integers.cs b/tests/etf/DSharpPlus.Etf.Tests/Serialization/EtfReaderTests/PrimitiveTests.Integers.cs deleted file mode 100644 index 856fd10555..0000000000 --- a/tests/etf/DSharpPlus.Etf.Tests/Serialization/EtfReaderTests/PrimitiveTests.Integers.cs +++ /dev/null @@ -1,78 +0,0 @@ -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -using System; - -using DSharpPlus.Etf.Serialization; - -using Xunit; - -namespace DSharpPlus.Etf.Tests.Serialization.EtfReaderTests; - -/// -/// Contains tests for reading primitive types. -/// -public partial class PrimitiveTests -{ - private static readonly byte[] integerPayload = - [ - // ETF version header - 0x83, - - // 32-bit integer - 0x62, 0x00, 0x00, 0x00, 0x04, - - // 8-bit integer - 0x61, 0x07 - ]; - - /// - /// Tests reading the first 32-bit integer. - /// - [Fact] - public void TestReadingInt32() - { - ReadOnlySpan span = [.. integerPayload]; - EtfReader reader = new - ( - span, - stackalloc uint[1], - stackalloc TermType[1] - ); - - Assert.True(reader.Read()); - Assert.Equal(TermType.Integer, reader.TermType); - Assert.Equal(4, reader.ReadInt32()); - Assert.Equal(4, reader.ReadInt64()); - Assert.Equal(4, reader.ReadInt16()); - Assert.Equal(4UL, reader.ReadUInt64()); - - Assert.True(reader.Read()); - } - - /// - /// Tests reading the second 8-bit integer. - /// - [Fact] - public void TestReadingByte() - { - ReadOnlySpan span = [.. integerPayload]; - EtfReader reader = new - ( - span, - stackalloc uint[1], - stackalloc TermType[1] - ); - - // discard the first term - _ = reader.Read(); - - Assert.True(reader.Read()); - Assert.Equal(TermType.SmallInteger, reader.TermType); - Assert.Equal(7, reader.ReadInt32()); - Assert.Equal(7, reader.ReadByte()); - Assert.Equal(7, reader.ReadInt16()); - Assert.Equal(7, reader.ReadSByte()); - } -} diff --git a/tests/etf/DSharpPlus.Etf.Tests/Serialization/EtfReaderTests/PrimitiveTests.Strings.cs b/tests/etf/DSharpPlus.Etf.Tests/Serialization/EtfReaderTests/PrimitiveTests.Strings.cs deleted file mode 100644 index 4639d7f544..0000000000 --- a/tests/etf/DSharpPlus.Etf.Tests/Serialization/EtfReaderTests/PrimitiveTests.Strings.cs +++ /dev/null @@ -1,102 +0,0 @@ -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -using System; - -using DSharpPlus.Etf.Serialization; - -using Xunit; - -namespace DSharpPlus.Etf.Tests.Serialization.EtfReaderTests; - -partial class PrimitiveTests -{ - private static readonly byte[] stringPayload = - [ - // ETF version header - 0x83, - - // small utf8 atom - 0x77, 0x0C, 0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x57, 0x6F, 0x72, 0x6C, 0x64, 0x21, - - // large utf8 atom - 0x76, 0x00, 0x0C, 0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x57, 0x6F, 0x72, 0x6C, 0x64, 0x21, - - // string - 0x6B, 0x00, 0x0C, 0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x57, 0x6F, 0x72, 0x6C, 0x64, 0x21 - ]; - - /// - /// Tests deserialization of a small UTF8 atom. - /// - [Fact] - public void TestSmallUtf8Atom() - { - ReadOnlySpan span = [.. stringPayload]; - EtfReader reader = new - ( - span, - stackalloc uint[1], - stackalloc TermType[1] - ); - - Assert.True(reader.Read()); - - Assert.Equal("Hello World!", reader.ReadString()); - - Span buffer = stackalloc byte[12]; - reader.ReadUtf8String(buffer); - - Assert.True("Hello World!"u8.SequenceEqual(buffer)); - } - - /// - /// Tests deserialization of a large UTF8 atom. - /// - [Fact] - public void TestLargeUtf8Atom() - { - ReadOnlySpan span = [.. stringPayload]; - EtfReader reader = new - ( - span, - stackalloc uint[1], - stackalloc TermType[1] - ); - - _ = reader.Read(); - - Assert.True(reader.Read()); - - Assert.Equal("Hello World!", reader.ReadString()); - - Span buffer = stackalloc byte[12]; - reader.ReadUtf8String(buffer); - - Assert.True("Hello World!"u8.SequenceEqual(buffer)); - } - - /// - /// Tests deserialization of a string. - /// - [Fact] - public void TestString() - { - ReadOnlySpan span = [.. stringPayload]; - EtfReader reader = new - ( - span, - stackalloc uint[1], - stackalloc TermType[1] - ); - - _ = reader.Read(); - _ = reader.Read(); - - Assert.True(reader.Read()); - - Assert.Equal(TermType.String, reader.TermType); - Assert.Equal("Hello World!", reader.ReadString()); - } -} diff --git a/tests/etf/DSharpPlus.Etf.Tests/Serialization/EtfReaderTests/StructureTests.Lists.cs b/tests/etf/DSharpPlus.Etf.Tests/Serialization/EtfReaderTests/StructureTests.Lists.cs deleted file mode 100644 index aa126da1c5..0000000000 --- a/tests/etf/DSharpPlus.Etf.Tests/Serialization/EtfReaderTests/StructureTests.Lists.cs +++ /dev/null @@ -1,78 +0,0 @@ -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -using System; - -using DSharpPlus.Etf.Serialization; - -using Xunit; - -namespace DSharpPlus.Etf.Tests.Serialization.EtfReaderTests; - -/// -/// Contains tests for correctly reading control structures. -/// -public partial class StructureTests -{ - private static readonly byte[] listPayload = - [ - // ETF version header - 0x83, - - // list introduction - 0x6C, 0x00, 0x00, 0x00, 0x02, - - // first child etf term - 0x62, 0x00, 0x00, 0x01, 0x00, - - // second child etf term - 0x62, 0x00, 0x00, 0x00, 0xFF, - - // null terminator - 0x6A, - - // term that isn't a child term - 0x61, 0x07 - ]; - - [Fact] - public void TestReadingList() - { - ReadOnlySpan span = [.. listPayload]; - EtfReader reader = new - ( - span, - stackalloc uint[1], - stackalloc TermType[1] - ); - - Assert.True(reader.Read()); - Assert.Equal(TermType.List, reader.TermType); - Assert.Equal(EtfTokenType.StartList, reader.TokenType); - - // the expected length here is 3: two items and the null terminator - // the null terminator doesn't actually need to be null, either, as per the specification, soo... - // https://www.erlang.org/doc/apps/erts/erl_ext_dist#list_ext - Assert.Equal((uint)3, reader.GetCurrentRemainingLength()); - - // test whether we correctly revert back to EtfTokenType.Term - Assert.True(reader.Read()); - Assert.Equal(EtfTokenType.Term, reader.TokenType); - - _ = reader.Read(); - - // are we null terminating correctly? - Assert.True(reader.Read()); - Assert.Equal(TermType.Nil, reader.TermType); - Assert.Equal((uint)0, reader.GetCurrentRemainingLength()); - - // are we synthesizing reads correctly - Assert.True(reader.Read()); - Assert.Equal(EtfTokenType.EndList, reader.TokenType); - - // are we reading the final term correctly? - Assert.True(reader.Read()); - Assert.Equal(TermType.SmallInteger, reader.TermType); - } -} diff --git a/tests/etf/DSharpPlus.Etf.Tests/Serialization/EtfReaderTests/StructureTests.Maps.cs b/tests/etf/DSharpPlus.Etf.Tests/Serialization/EtfReaderTests/StructureTests.Maps.cs deleted file mode 100644 index 1c11524b64..0000000000 --- a/tests/etf/DSharpPlus.Etf.Tests/Serialization/EtfReaderTests/StructureTests.Maps.cs +++ /dev/null @@ -1,56 +0,0 @@ -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -using System; - -using DSharpPlus.Etf.Serialization; - -using Xunit; - -namespace DSharpPlus.Etf.Tests.Serialization.EtfReaderTests; - -partial class StructureTests -{ - private static readonly byte[] mapPayload = - [ - // ETF version header - 0x83, - - // map header - 0x74, 0x00, 0x00, 0x00, 0x01, - - // key - 0x61, 0x07, - - // value - 0x61, 0x08 - ]; - - [Fact] - public void TestReadingMap() - { - ReadOnlySpan span = [.. mapPayload]; - EtfReader reader = new - ( - span, - stackalloc uint[1], - stackalloc TermType[1] - ); - - Assert.True(reader.Read()); - Assert.Equal(TermType.Map, reader.TermType); - Assert.Equal(EtfTokenType.StartMap, reader.TokenType); - - // key - Assert.True(reader.Read()); - Assert.Equal((uint)1, reader.GetCurrentRemainingLength()); - - // value - _ = reader.Read(); - - // are we correctly synthesizing the last end token, even if there is no actual data left? - Assert.True(reader.Read()); - Assert.Equal(EtfTokenType.EndMap, reader.TokenType); - } -} diff --git a/tests/etf/DSharpPlus.Etf.Tests/Serialization/EtfReaderTests/StructureTests.Tuples.cs b/tests/etf/DSharpPlus.Etf.Tests/Serialization/EtfReaderTests/StructureTests.Tuples.cs deleted file mode 100644 index 96c5317779..0000000000 --- a/tests/etf/DSharpPlus.Etf.Tests/Serialization/EtfReaderTests/StructureTests.Tuples.cs +++ /dev/null @@ -1,54 +0,0 @@ -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -using System; - -using DSharpPlus.Etf.Serialization; - -using Xunit; - -namespace DSharpPlus.Etf.Tests.Serialization.EtfReaderTests; - -partial class StructureTests -{ - private static readonly byte[] tuplePayload = - [ - // ETF version header - 0x83, - - // tuple - 0x68, 0x02, - - // first child term - 0x62, 0x00, 0x00, 0x00, 0x07, - - // second child term - 0x61, 0x7F - ]; - - [Fact] - public void TestReadingTuple() - { - ReadOnlySpan span = [.. tuplePayload]; - EtfReader reader = new - ( - span, - stackalloc uint[1], - stackalloc TermType[1] - ); - - Assert.True(reader.Read()); - Assert.Equal(TermType.SmallTuple, reader.TermType); - Assert.Equal(EtfTokenType.StartTuple, reader.TokenType); - - Assert.True(reader.Read()); - Assert.Equal((uint)1, reader.GetCurrentRemainingLength()); - - _ = reader.Read(); - - // are we correctly synthesizing the last end token, even if there is no actual data left? - Assert.True(reader.Read()); - Assert.Equal(EtfTokenType.EndTuple, reader.TokenType); - } -} diff --git a/tests/etf/DSharpPlus.Etf.Tests/Serialization/EtfReaderTests/ValidationTests.cs b/tests/etf/DSharpPlus.Etf.Tests/Serialization/EtfReaderTests/ValidationTests.cs deleted file mode 100644 index 53ec0ab973..0000000000 --- a/tests/etf/DSharpPlus.Etf.Tests/Serialization/EtfReaderTests/ValidationTests.cs +++ /dev/null @@ -1,109 +0,0 @@ -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -using System; -using System.IO; - -using DSharpPlus.Etf.Serialization; - -using Xunit; - -namespace DSharpPlus.Etf.Tests.Serialization.EtfReaderTests; - -/// -/// Contains tests to see whether we complain correctly upon invalid data. -/// -public class ValidationTests -{ - private static readonly byte[] compressedPayload = [0x83, 0x50]; - - /// - /// Verifies whether the EtfReader correctly rejects a compressed term payload. - /// - [Fact] - public void TestFailingToReadCompressedPayload() - { - try - { - ReadOnlySpan span = [.. compressedPayload]; - EtfReader reader = new(span); - - // this should be unreachable - Assert.True(false); - } - catch (InvalidDataException) - { - // correct exception thrown - Assert.True(true); - } - catch - { - // specifically only that exception should be thrown - Assert.True(false); - } - } - - /// - /// Presently, the only supported format version is 131 or 0x83 - /// - [Theory] - [InlineData(7)] - [InlineData(11)] - [InlineData(71)] - [InlineData(83)] - [InlineData(130)] - [InlineData(132)] - [InlineData(222)] -#pragma warning disable xUnit1026 // the analyzer isn't picking up on the collection expression - public void TestFailingOnInvalidVersion(byte version) -#pragma warning restore xUnit1026 - { - try - { - ReadOnlySpan span = [version]; - EtfReader reader = new(span); - - // this should be unreachable - Assert.True(false); - } - catch (InvalidDataException) - { - // correct exception thrown - Assert.True(true); - } - catch - { - // specifically only that exception should be thrown - Assert.True(false); - } - } - - [Fact] - public void TestFailingOnMismatchedStacks() - { - try - { - ReadOnlySpan span = [0x83]; - EtfReader reader = new - ( - span, - stackalloc uint[2], - stackalloc TermType[1] - ); - - // this should be unreachable - Assert.True(false); - } - catch (ArgumentException) - { - // correct exception thrown - Assert.True(true); - } - catch - { - // specifically only that exception should be thrown - Assert.True(false); - } - } -} From 884b1bd07d33b44914597c53d2f7fb265c3e34b3 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sat, 30 Sep 2023 15:31:33 +0200 Subject: [PATCH 137/323] support default values for auto-populated selects --- .../IChannelSelectComponent.cs | 6 +++++ .../MessageComponents/IDefaultSelectValue.cs | 23 +++++++++++++++++++ .../IMentionableSelectComponent.cs | 8 +++++++ .../MessageComponents/IRoleSelectComponent.cs | 8 +++++++ .../MessageComponents/IUserSelectComponent.cs | 8 +++++++ .../ChannelSelectComponent.cs | 3 +++ .../MessageComponents/DefaultSelectValue.cs | 19 +++++++++++++++ .../MentionableSelectComponent.cs | 5 ++++ .../MessageComponents/RoleSelectComponent.cs | 5 ++++ .../MessageComponents/UserSelectComponent.cs | 5 ++++ 10 files changed, 90 insertions(+) create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IDefaultSelectValue.cs create mode 100644 src/core/DSharpPlus.Core.Models/MessageComponents/DefaultSelectValue.cs diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IChannelSelectComponent.cs b/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IChannelSelectComponent.cs index 377590f202..01fdd56346 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IChannelSelectComponent.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IChannelSelectComponent.cs @@ -36,6 +36,12 @@ public interface IChannelSelectComponent : IInteractiveComponent /// public Optional Placeholder { get; } + /// + /// A list of default values for this select; the number of default values must be within the range defined by + /// and . + /// + public Optional> DefaultValues { get; } + /// /// The minimum number of items that must be chosen, between 0 and 25. /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IDefaultSelectValue.cs b/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IDefaultSelectValue.cs new file mode 100644 index 0000000000..3701219f25 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IDefaultSelectValue.cs @@ -0,0 +1,23 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using Remora.Rest.Core; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Represents a default value for an auto-populated select menu. +/// +public interface IDefaultSelectValue +{ + /// + /// The snowflake identifier of a user, role or channel. + /// + public Snowflake Id { get; } + + /// + /// The type of the value represented by ; either "user", "role" or "channel". + /// + public string Type { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IMentionableSelectComponent.cs b/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IMentionableSelectComponent.cs index 1da6e010a5..db75c456bb 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IMentionableSelectComponent.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IMentionableSelectComponent.cs @@ -2,6 +2,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +using System.Collections.Generic; + using DSharpPlus.Entities; using Remora.Rest.Core; @@ -28,6 +30,12 @@ public interface IMentionableSelectComponent : IInteractiveComponent /// public Optional Placeholder { get; } + /// + /// A list of default values for this select; the number of default values must be within the range defined by + /// and . + /// + public Optional> DefaultValues { get; } + /// /// The minimum number of items that must be chosen, between 0 and 25. /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IRoleSelectComponent.cs b/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IRoleSelectComponent.cs index b14a6b6ba0..792ece4dd0 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IRoleSelectComponent.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IRoleSelectComponent.cs @@ -2,6 +2,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +using System.Collections.Generic; + using DSharpPlus.Entities; using Remora.Rest.Core; @@ -28,6 +30,12 @@ public interface IRoleSelectComponent : IInteractiveComponent /// public Optional Placeholder { get; } + /// + /// A list of default values for this select; the number of default values must be within the range defined by + /// and . + /// + public Optional> DefaultValues { get; } + /// /// The minimum number of items that must be chosen, between 0 and 25. /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IUserSelectComponent.cs b/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IUserSelectComponent.cs index 1fbfd1e39a..f9099d8e4c 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IUserSelectComponent.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IUserSelectComponent.cs @@ -2,6 +2,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +using System.Collections.Generic; + using DSharpPlus.Entities; using Remora.Rest.Core; @@ -28,6 +30,12 @@ public interface IUserSelectComponent : IInteractiveComponent ///
public Optional Placeholder { get; } + /// + /// A list of default values for this select; the number of default values must be within the range defined by + /// and . + /// + public Optional> DefaultValues { get; } + /// /// The minimum number of items that must be chosen, between 0 and 25. /// diff --git a/src/core/DSharpPlus.Core.Models/MessageComponents/ChannelSelectComponent.cs b/src/core/DSharpPlus.Core.Models/MessageComponents/ChannelSelectComponent.cs index 5eced6e93b..0d4b45d409 100644 --- a/src/core/DSharpPlus.Core.Models/MessageComponents/ChannelSelectComponent.cs +++ b/src/core/DSharpPlus.Core.Models/MessageComponents/ChannelSelectComponent.cs @@ -27,6 +27,9 @@ public sealed record ChannelSelectComponent : IChannelSelectComponent /// public Optional Placeholder { get; init; } + /// + public Optional> DefaultValues { get; init; } + /// public Optional MinValues { get; init; } diff --git a/src/core/DSharpPlus.Core.Models/MessageComponents/DefaultSelectValue.cs b/src/core/DSharpPlus.Core.Models/MessageComponents/DefaultSelectValue.cs new file mode 100644 index 0000000000..f6ea445a4b --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/MessageComponents/DefaultSelectValue.cs @@ -0,0 +1,19 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using Remora.Rest.Core; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record DefaultSelectValue : IDefaultSelectValue +{ + /// + public required Snowflake Id { get; init; } + + /// + public required string Type { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/MessageComponents/MentionableSelectComponent.cs b/src/core/DSharpPlus.Core.Models/MessageComponents/MentionableSelectComponent.cs index dbcca4a9d2..0450e9b8ed 100644 --- a/src/core/DSharpPlus.Core.Models/MessageComponents/MentionableSelectComponent.cs +++ b/src/core/DSharpPlus.Core.Models/MessageComponents/MentionableSelectComponent.cs @@ -2,6 +2,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +using System.Collections.Generic; + using DSharpPlus.Entities; using Remora.Rest.Core; @@ -22,6 +24,9 @@ public sealed record MentionableSelectComponent : IMentionableSelectComponent /// public Optional Placeholder { get; init; } + /// + public Optional> DefaultValues { get; init; } + /// public Optional MinValues { get; init; } diff --git a/src/core/DSharpPlus.Core.Models/MessageComponents/RoleSelectComponent.cs b/src/core/DSharpPlus.Core.Models/MessageComponents/RoleSelectComponent.cs index dd98a0c8d9..4d058a5887 100644 --- a/src/core/DSharpPlus.Core.Models/MessageComponents/RoleSelectComponent.cs +++ b/src/core/DSharpPlus.Core.Models/MessageComponents/RoleSelectComponent.cs @@ -2,6 +2,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +using System.Collections.Generic; + using DSharpPlus.Entities; using Remora.Rest.Core; @@ -22,6 +24,9 @@ public sealed record RoleSelectComponent : IRoleSelectComponent /// public Optional Placeholder { get; init; } + /// + public Optional> DefaultValues { get; init; } + /// public Optional MinValues { get; init; } diff --git a/src/core/DSharpPlus.Core.Models/MessageComponents/UserSelectComponent.cs b/src/core/DSharpPlus.Core.Models/MessageComponents/UserSelectComponent.cs index 25c283fcee..4567c7a66d 100644 --- a/src/core/DSharpPlus.Core.Models/MessageComponents/UserSelectComponent.cs +++ b/src/core/DSharpPlus.Core.Models/MessageComponents/UserSelectComponent.cs @@ -2,6 +2,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +using System.Collections.Generic; + using DSharpPlus.Entities; using Remora.Rest.Core; @@ -22,6 +24,9 @@ public sealed record UserSelectComponent : IUserSelectComponent /// public Optional Placeholder { get; init; } + /// + public Optional> DefaultValues { get; init; } + /// public Optional MinValues { get; init; } From 22fad5f4c19fe14d9a1c0b9455cc226ae9e0216c Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sat, 30 Sep 2023 15:45:34 +0200 Subject: [PATCH 138/323] add entitlement objects --- .../Entitlements/IEntitlement.cs | 62 +++++++++++++++++++ .../Interactions/IInteraction.cs | 7 +++ .../Skus/ISku.cs | 40 ++++++++++++ .../Entitlements/Entitlement.cs | 44 +++++++++++++ .../Interactions/Interaction.cs | 5 ++ src/core/DSharpPlus.Core.Models/Skus/Sku.cs | 30 +++++++++ .../Entities/Entitlements/EntitlementType.cs | 13 ++++ .../Entities/Skus/SkuType.cs | 21 +++++++ 8 files changed, 222 insertions(+) create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/Entitlements/IEntitlement.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/Skus/ISku.cs create mode 100644 src/core/DSharpPlus.Core.Models/Entitlements/Entitlement.cs create mode 100644 src/core/DSharpPlus.Core.Models/Skus/Sku.cs create mode 100644 src/core/DSharpPlus.Shared/Entities/Entitlements/EntitlementType.cs create mode 100644 src/core/DSharpPlus.Shared/Entities/Skus/SkuType.cs diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Entitlements/IEntitlement.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Entitlements/IEntitlement.cs new file mode 100644 index 0000000000..71d07eeaed --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Entitlements/IEntitlement.cs @@ -0,0 +1,62 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; + +using DSharpPlus.Entities; + +using Remora.Rest.Core; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Represents an entitlement to a premium offering in an application. +/// +public interface IEntitlement +{ + /// + /// The snowflake identifier of this entitlement. + /// + public Snowflake Id { get; } + + /// + /// The snowflake identifier of the SKU. + /// + public Snowflake SkuId { get; } + + /// + /// The snowflake identifier of the user that is granted access to the entitlement's SKU. + /// + public Optional UserId { get; } + + /// + /// The snowflake identifier of the guild that is granted access to the entitlement's SKU. + /// + public Optional GuildId { get; } + + /// + /// The snowflake identifier of the parent application. + /// + public Snowflake ApplicationId { get; } + + /// + /// The type of this entitlement. + /// + public EntitlementType Type { get; } + + /// + /// false. + /// + public bool Consumed { get; } + + /// + /// The starting date at which this entitlement is valid. Not present when using test entitlements. + /// + public Optional StartsAt { get; } + + /// + /// The date at which this entitlement is no longer valid. Not present when using test entitlements. + /// + public Optional EndsAt { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IInteraction.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IInteraction.cs index ecb4044b73..75af03d7be 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IInteraction.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IInteraction.cs @@ -2,6 +2,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +using System.Collections.Generic; + using DSharpPlus.Entities; using OneOf; @@ -94,4 +96,9 @@ public interface IInteraction /// The preferred locale of the guild, if invoked in a guild. ///
public Optional GuildLocale { get; } + + /// + /// For monetized apps, any entitlements for the invoking user. + /// + public Optional> Entitlements { get; } } diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Skus/ISku.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Skus/ISku.cs new file mode 100644 index 0000000000..86191b1a4c --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Skus/ISku.cs @@ -0,0 +1,40 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Entities; + +using Remora.Rest.Core; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Represents a premium offering that can be made available to your application's users or guilds. +/// +public interface ISku +{ + /// + /// The identifier of this SKU. + /// + public object Id { get; } + + /// + /// The type of this SKU. + /// + public SkuType Type { get; } + + /// + /// The snowflake identifier of the parent application. + /// + public Snowflake ApplicationId { get; } + + /// + /// The user-facing name of the offering. + /// + public string Name { get; } + + /// + /// A system-generated URL slug based on the SKU's name. + /// + public string Slug { get; } +} diff --git a/src/core/DSharpPlus.Core.Models/Entitlements/Entitlement.cs b/src/core/DSharpPlus.Core.Models/Entitlements/Entitlement.cs new file mode 100644 index 0000000000..5e0ec89a19 --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/Entitlements/Entitlement.cs @@ -0,0 +1,44 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; + +using DSharpPlus.Entities; + +using Remora.Rest.Core; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record Entitlement : IEntitlement +{ + /// + public required Snowflake Id { get; init; } + + /// + public required Snowflake SkuId { get; init; } + + /// + public Optional UserId { get; init; } + + /// + public Optional GuildId { get; init; } + + /// + public required Snowflake ApplicationId { get; init; } + + /// + public required EntitlementType Type { get; init; } + + /// + public required bool Consumed { get; init; } + + /// + public Optional StartsAt { get; init; } + + /// + public Optional EndsAt { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/Interactions/Interaction.cs b/src/core/DSharpPlus.Core.Models/Interactions/Interaction.cs index 631314c7cd..383cc1ed13 100644 --- a/src/core/DSharpPlus.Core.Models/Interactions/Interaction.cs +++ b/src/core/DSharpPlus.Core.Models/Interactions/Interaction.cs @@ -2,6 +2,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +using System.Collections.Generic; + using DSharpPlus.Entities; using OneOf; @@ -59,4 +61,7 @@ public sealed record Interaction : IInteraction /// public Optional GuildLocale { get; init; } + + /// + public Optional> Entitlements { get; init; } } \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/Skus/Sku.cs b/src/core/DSharpPlus.Core.Models/Skus/Sku.cs new file mode 100644 index 0000000000..5ea4b984ac --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/Skus/Sku.cs @@ -0,0 +1,30 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Entities; + +using Remora.Rest.Core; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record Sku : ISku +{ + /// + public required object Id { get; init; } + + /// + public required SkuType Type { get; init; } + + /// + public required Snowflake ApplicationId { get; init; } + + /// + public required string Name { get; init; } + + /// + public required string Slug { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Shared/Entities/Entitlements/EntitlementType.cs b/src/core/DSharpPlus.Shared/Entities/Entitlements/EntitlementType.cs new file mode 100644 index 0000000000..f03cf41f40 --- /dev/null +++ b/src/core/DSharpPlus.Shared/Entities/Entitlements/EntitlementType.cs @@ -0,0 +1,13 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Entities; + +public enum EntitlementType +{ + /// + /// This entitlement was purchased as an app subscription. + /// + ApplicationSubscription = 8 +} diff --git a/src/core/DSharpPlus.Shared/Entities/Skus/SkuType.cs b/src/core/DSharpPlus.Shared/Entities/Skus/SkuType.cs new file mode 100644 index 0000000000..2c42d73afb --- /dev/null +++ b/src/core/DSharpPlus.Shared/Entities/Skus/SkuType.cs @@ -0,0 +1,21 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Entities; + +/// +/// Represents the type of a given SKU. +/// +public enum SkuType +{ + /// + /// Represents a recurring subscription. + /// + Subscription = 5, + + /// + /// A system-generated group for each subscription SKU created. + /// + SubscriptionGroup = 6 +} From d1c0c84adcdb01003c8bb8b4503add8ebbb770e6 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sat, 30 Sep 2023 15:46:51 +0200 Subject: [PATCH 139/323] add resolved data to message component interaction data --- .../Interactions/IMessageComponentInteractionData.cs | 5 +++++ .../Interactions/MessageComponentInteractionData.cs | 3 +++ 2 files changed, 8 insertions(+) diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IMessageComponentInteractionData.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IMessageComponentInteractionData.cs index ba5e157e10..f4961cfb6a 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IMessageComponentInteractionData.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IMessageComponentInteractionData.cs @@ -29,4 +29,9 @@ public interface IMessageComponentInteractionData /// The values selected in the associated select menu, if applicable. ///
public Optional> Values { get; } + + /// + /// Resolved entities from the selected options. + /// + public Optional Resolved { get; } } diff --git a/src/core/DSharpPlus.Core.Models/Interactions/MessageComponentInteractionData.cs b/src/core/DSharpPlus.Core.Models/Interactions/MessageComponentInteractionData.cs index 96f9208bb2..92997d8a9a 100644 --- a/src/core/DSharpPlus.Core.Models/Interactions/MessageComponentInteractionData.cs +++ b/src/core/DSharpPlus.Core.Models/Interactions/MessageComponentInteractionData.cs @@ -23,4 +23,7 @@ public sealed record MessageComponentInteractionData : IMessageComponentInteract /// public Optional> Values { get; init; } + + /// + public Optional Resolved { get; init; } } \ No newline at end of file From 0e7d62a24ba8c413bac70bbd73d69f1bdcd01be2 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sat, 30 Sep 2023 16:04:00 +0200 Subject: [PATCH 140/323] update application objects --- .../Applications/IPartialApplication.cs | 27 ++++++++++++++----- .../Applications/Application.cs | 15 ++++++++--- .../Applications/PartialApplication.cs | 15 ++++++++--- 3 files changed, 45 insertions(+), 12 deletions(-) diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Applications/IPartialApplication.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Applications/IPartialApplication.cs index 88d0a58cc7..de8ab10b9f 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Applications/IPartialApplication.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Applications/IPartialApplication.cs @@ -50,6 +50,11 @@ public interface IPartialApplication ///
public Optional BotRequireCodeGrant { get; } + /// + /// A partial user object for the bot user associated with this app. + /// + public Optional Bot { get; } + /// /// The URL to this application's terms of service. /// @@ -111,6 +116,22 @@ public interface IPartialApplication ///
public Optional ApproximateGuildCount { get; } + /// + /// An array of redirect URIs for this application. + /// + public Optional> RedirectUris { get; } + + /// + /// The interactions endpoint url for this app, if it uses HTTP interactions. + /// + public Optional InteractionsEndpointUrl { get; } + + /// + /// This application's role connection verification entry point; which, when configured, will render + /// the application as a verification method in the guild role verification configuration. + /// + public Optional RoleConnectionsVerificationUrl { get; } + /// /// Up to five tags describing content and functionality of the application. /// @@ -125,10 +146,4 @@ public interface IPartialApplication /// The default custom authorization link for this application, if enabled. /// public Optional CustomInstallUrl { get; } - - /// - /// This application's role connection verification entry point; which, when configured, will render - /// the application as a verification method in the guild role verification configuration. - /// - public Optional RoleConnectionsVerificationUrl { get; } } diff --git a/src/core/DSharpPlus.Core.Models/Applications/Application.cs b/src/core/DSharpPlus.Core.Models/Applications/Application.cs index 7db9aa4919..acc30dee0a 100644 --- a/src/core/DSharpPlus.Core.Models/Applications/Application.cs +++ b/src/core/DSharpPlus.Core.Models/Applications/Application.cs @@ -36,6 +36,9 @@ public sealed record Application : IApplication /// public required bool BotRequireCodeGrant { get; init; } + /// + public Optional Bot { get; init; } + /// public Optional TermsOfServiceUrl { get; init; } @@ -72,6 +75,15 @@ public sealed record Application : IApplication /// public Optional ApproximateGuildCount { get; init; } + /// + public Optional> RedirectUris { get; init; } + + /// + public Optional InteractionsEndpointUrl { get; init; } + + /// + public Optional RoleConnectionsVerificationUrl { get; init; } + /// public Optional> Tags { get; init; } @@ -80,7 +92,4 @@ public sealed record Application : IApplication /// public Optional CustomInstallUrl { get; init; } - - /// - public Optional RoleConnectionsVerificationUrl { get; init; } } \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/Applications/PartialApplication.cs b/src/core/DSharpPlus.Core.Models/Applications/PartialApplication.cs index a93a2f5ebd..fd7a0a3fac 100644 --- a/src/core/DSharpPlus.Core.Models/Applications/PartialApplication.cs +++ b/src/core/DSharpPlus.Core.Models/Applications/PartialApplication.cs @@ -36,6 +36,9 @@ public sealed record PartialApplication : IPartialApplication /// public Optional BotRequireCodeGrant { get; init; } + /// + public Optional Bot { get; init; } + /// public Optional TermsOfServiceUrl { get; init; } @@ -72,6 +75,15 @@ public sealed record PartialApplication : IPartialApplication /// public Optional ApproximateGuildCount { get; init; } + /// + public Optional> RedirectUris { get; init; } + + /// + public Optional InteractionsEndpointUrl { get; init; } + + /// + public Optional RoleConnectionsVerificationUrl { get; init; } + /// public Optional> Tags { get; init; } @@ -80,7 +92,4 @@ public sealed record PartialApplication : IPartialApplication /// public Optional CustomInstallUrl { get; init; } - - /// - public Optional RoleConnectionsVerificationUrl { get; init; } } \ No newline at end of file From 88973adf7b80f830449c7fb741e2c88240b84296 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sat, 30 Sep 2023 16:07:13 +0200 Subject: [PATCH 141/323] update sku modeling based on a newer docs commit --- .../Skus/ISku.cs | 7 +++++- src/core/DSharpPlus.Core.Models/Skus/Sku.cs | 5 +++- .../Entities/Skus/SkuFlags.cs | 25 +++++++++++++++++++ 3 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 src/core/DSharpPlus.Shared/Entities/Skus/SkuFlags.cs diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Skus/ISku.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Skus/ISku.cs index 86191b1a4c..d4b2fed6a8 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Skus/ISku.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Skus/ISku.cs @@ -16,7 +16,7 @@ public interface ISku /// /// The identifier of this SKU. /// - public object Id { get; } + public Snowflake Id { get; } /// /// The type of this SKU. @@ -37,4 +37,9 @@ public interface ISku /// A system-generated URL slug based on the SKU's name. /// public string Slug { get; } + + /// + /// Additional flags for this SKU. + /// + public SkuFlags Flags { get; } } diff --git a/src/core/DSharpPlus.Core.Models/Skus/Sku.cs b/src/core/DSharpPlus.Core.Models/Skus/Sku.cs index 5ea4b984ac..06f4b9bcdc 100644 --- a/src/core/DSharpPlus.Core.Models/Skus/Sku.cs +++ b/src/core/DSharpPlus.Core.Models/Skus/Sku.cs @@ -14,7 +14,7 @@ namespace DSharpPlus.Core.Models; public sealed record Sku : ISku { /// - public required object Id { get; init; } + public required Snowflake Id { get; init; } /// public required SkuType Type { get; init; } @@ -27,4 +27,7 @@ public sealed record Sku : ISku /// public required string Slug { get; init; } + + /// + public required SkuFlags Flags { get; init; } } \ No newline at end of file diff --git a/src/core/DSharpPlus.Shared/Entities/Skus/SkuFlags.cs b/src/core/DSharpPlus.Shared/Entities/Skus/SkuFlags.cs new file mode 100644 index 0000000000..6832c859bc --- /dev/null +++ b/src/core/DSharpPlus.Shared/Entities/Skus/SkuFlags.cs @@ -0,0 +1,25 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; + +namespace DSharpPlus.Entities; + +/// +/// Represents additional flags for a given SKU. +/// +[Flags] +public enum SkuFlags +{ + /// + /// A subscription purchased by a user and applied to a single server. Everyone in that server gets access + /// to the given SKU. + /// + GuildSubscription = 1 << 7, + + /// + /// A subscription purchased by a user for themselves. They get access to the given SKU in every server. + /// + UserSubscription = 1 << 8 +} From 578c45dba242ac1b24b9ef860509c59c129605e0 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Tue, 3 Oct 2023 14:10:51 +0200 Subject: [PATCH 142/323] remove netstandard build stuff from DSharpPlus.Shared --- .../DSharpPlus.Shared/DSharpPlus.Shared.csproj | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/src/core/DSharpPlus.Shared/DSharpPlus.Shared.csproj b/src/core/DSharpPlus.Shared/DSharpPlus.Shared.csproj index 8977420281..66dc4739b4 100644 --- a/src/core/DSharpPlus.Shared/DSharpPlus.Shared.csproj +++ b/src/core/DSharpPlus.Shared/DSharpPlus.Shared.csproj @@ -11,22 +11,4 @@ DSharpPlus - - netstandard2.0;$(TargetFramework) - - - - - - - - false - - - - - - - - From 856888affed3401d94263fe8b1de6ca7e4e2c7a4 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Tue, 3 Oct 2023 15:09:29 +0200 Subject: [PATCH 143/323] add rest projects --- DSharpPlus.sln | 14 ++++++++++++++ Directory.Build.props | 6 ++++++ .../DSharpPlus.Core.Abstractions.Rest.csproj | 13 +++++++++++++ .../DSharpPlus.Core.Rest.csproj | 7 +++++++ src/core/DSharpPlus.Core.sln | 12 ++++++++++++ 5 files changed, 52 insertions(+) create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/DSharpPlus.Core.Abstractions.Rest.csproj create mode 100644 src/core/DSharpPlus.Core.Rest/DSharpPlus.Core.Rest.csproj diff --git a/DSharpPlus.sln b/DSharpPlus.sln index e120012b89..f563b2d3de 100644 --- a/DSharpPlus.sln +++ b/DSharpPlus.sln @@ -30,6 +30,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DSharpPlus.SourceGenerators EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DSharpPlus.Core.Models.Tests", "tests\core\DSharpPlus.Core.Models.Tests\DSharpPlus.Core.Models.Tests.csproj", "{9F25D892-3CB0-4D47-B67D-D3FFFADC03E0}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DSharpPlus.Core.Abstractions.Rest", "src\core\DSharpPlus.Core.Abstractions.Rest\DSharpPlus.Core.Abstractions.Rest.csproj", "{CD440954-E19A-4E94-A217-CCC1DC4AF095}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DSharpPlus.Core.Rest", "src\core\DSharpPlus.Core.Rest\DSharpPlus.Core.Rest.csproj", "{9CEC3D27-9014-48B6-910F-D25233BF8C44}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -64,6 +68,14 @@ Global {9F25D892-3CB0-4D47-B67D-D3FFFADC03E0}.Debug|Any CPU.Build.0 = Debug|Any CPU {9F25D892-3CB0-4D47-B67D-D3FFFADC03E0}.Release|Any CPU.ActiveCfg = Release|Any CPU {9F25D892-3CB0-4D47-B67D-D3FFFADC03E0}.Release|Any CPU.Build.0 = Release|Any CPU + {CD440954-E19A-4E94-A217-CCC1DC4AF095}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {CD440954-E19A-4E94-A217-CCC1DC4AF095}.Debug|Any CPU.Build.0 = Debug|Any CPU + {CD440954-E19A-4E94-A217-CCC1DC4AF095}.Release|Any CPU.ActiveCfg = Release|Any CPU + {CD440954-E19A-4E94-A217-CCC1DC4AF095}.Release|Any CPU.Build.0 = Release|Any CPU + {9CEC3D27-9014-48B6-910F-D25233BF8C44}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9CEC3D27-9014-48B6-910F-D25233BF8C44}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9CEC3D27-9014-48B6-910F-D25233BF8C44}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9CEC3D27-9014-48B6-910F-D25233BF8C44}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -77,6 +89,8 @@ Global {21927A64-7345-4D90-9EE2-7FA4B1973AAC} = {EAE89CF5-AA91-4A22-9949-A46FAE1BF0D0} {98D2C52C-E3BA-4564-919C-750775B7BA9C} = {5FBB4590-56B0-453B-A87B-08A17C599B5C} {9F25D892-3CB0-4D47-B67D-D3FFFADC03E0} = {21927A64-7345-4D90-9EE2-7FA4B1973AAC} + {CD440954-E19A-4E94-A217-CCC1DC4AF095} = {BC8D8750-48A4-49EF-9D1F-BE4DBA5B500E} + {9CEC3D27-9014-48B6-910F-D25233BF8C44} = {BC8D8750-48A4-49EF-9D1F-BE4DBA5B500E} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {55CDA684-8900-479B-9DAE-BA3BE09B337B} diff --git a/Directory.Build.props b/Directory.Build.props index 31a3a9a279..6b2d4a30d7 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -47,6 +47,12 @@ <_DSharpPlusCoreModelsVersion>0.1.0 + + + <_DSharpPlusCoreAbstractionsRestVersion>0.1.0 + + + <_DSharpPlusCoreRestVersion>0.1.0 \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/DSharpPlus.Core.Abstractions.Rest.csproj b/src/core/DSharpPlus.Core.Abstractions.Rest/DSharpPlus.Core.Abstractions.Rest.csproj new file mode 100644 index 0000000000..ca4f8cf3ba --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/DSharpPlus.Core.Abstractions.Rest.csproj @@ -0,0 +1,13 @@ + + + + $(_DSharpPlusCoreAbstractionsRestVersion) + + + + + + + diff --git a/src/core/DSharpPlus.Core.Rest/DSharpPlus.Core.Rest.csproj b/src/core/DSharpPlus.Core.Rest/DSharpPlus.Core.Rest.csproj new file mode 100644 index 0000000000..3c46fcea0f --- /dev/null +++ b/src/core/DSharpPlus.Core.Rest/DSharpPlus.Core.Rest.csproj @@ -0,0 +1,7 @@ + + + + $(_DSharpPlusCoreRestVersion) + + + diff --git a/src/core/DSharpPlus.Core.sln b/src/core/DSharpPlus.Core.sln index de1ce25ce1..7a84a3e456 100644 --- a/src/core/DSharpPlus.Core.sln +++ b/src/core/DSharpPlus.Core.sln @@ -9,6 +9,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DSharpPlus.Core.Models", "D EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DSharpPlus.Shared", "DSharpPlus.Shared\DSharpPlus.Shared.csproj", "{E9B2D26F-5E11-4198-8E00-A7780572C480}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DSharpPlus.Core.Abstractions.Rest", "DSharpPlus.Core.Abstractions.Rest\DSharpPlus.Core.Abstractions.Rest.csproj", "{16EFED50-A695-48C3-8B05-C52381C13C9B}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DSharpPlus.Core.Rest", "DSharpPlus.Core.Rest\DSharpPlus.Core.Rest.csproj", "{4ECD4676-81FD-4E16-B025-D6AE11638E02}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -27,6 +31,14 @@ Global {E9B2D26F-5E11-4198-8E00-A7780572C480}.Debug|Any CPU.Build.0 = Debug|Any CPU {E9B2D26F-5E11-4198-8E00-A7780572C480}.Release|Any CPU.ActiveCfg = Release|Any CPU {E9B2D26F-5E11-4198-8E00-A7780572C480}.Release|Any CPU.Build.0 = Release|Any CPU + {16EFED50-A695-48C3-8B05-C52381C13C9B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {16EFED50-A695-48C3-8B05-C52381C13C9B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {16EFED50-A695-48C3-8B05-C52381C13C9B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {16EFED50-A695-48C3-8B05-C52381C13C9B}.Release|Any CPU.Build.0 = Release|Any CPU + {4ECD4676-81FD-4E16-B025-D6AE11638E02}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4ECD4676-81FD-4E16-B025-D6AE11638E02}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4ECD4676-81FD-4E16-B025-D6AE11638E02}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4ECD4676-81FD-4E16-B025-D6AE11638E02}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE From 301524cb1711382902deb810fa44cb8fb899a472 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sat, 7 Oct 2023 18:56:03 +0200 Subject: [PATCH 144/323] it is optional time --- src/core/DSharpPlus.Shared/IOptional.cs | 16 +++ src/core/DSharpPlus.Shared/Optional`1.cs | 155 ++++++++++++++++++++++ src/core/DSharpPlus.Shared/ThrowHelper.cs | 30 +++++ 3 files changed, 201 insertions(+) create mode 100644 src/core/DSharpPlus.Shared/IOptional.cs create mode 100644 src/core/DSharpPlus.Shared/Optional`1.cs create mode 100644 src/core/DSharpPlus.Shared/ThrowHelper.cs diff --git a/src/core/DSharpPlus.Shared/IOptional.cs b/src/core/DSharpPlus.Shared/IOptional.cs new file mode 100644 index 0000000000..9e71fa30a6 --- /dev/null +++ b/src/core/DSharpPlus.Shared/IOptional.cs @@ -0,0 +1,16 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus; + +/// +/// Defines the principal working of an Optional type. +/// +public interface IOptional +{ + /// + /// Indicates whether this optional is logically defined. + /// + public bool HasValue { get; } +} diff --git a/src/core/DSharpPlus.Shared/Optional`1.cs b/src/core/DSharpPlus.Shared/Optional`1.cs new file mode 100644 index 0000000000..e95d19e109 --- /dev/null +++ b/src/core/DSharpPlus.Shared/Optional`1.cs @@ -0,0 +1,155 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; +using System.Diagnostics.CodeAnalysis; + +namespace DSharpPlus; + +/// +/// Represents a logical container for the presence of a value in the context of Discord's REST API. +/// +/// The type of the enclosed value. +public readonly record struct Optional : IOptional +{ + private readonly T value; + + /// + public bool HasValue { get; } + + /// + /// Retrieves the underlying value, if present. + /// + public T Value + { + get + { + if (!this.HasValue) + { + ThrowHelper.ThrowOptionalNoValuePresent(); + } + + return this.value; + } + } + + public Optional + ( + T value + ) + { + this.HasValue = true; + this.value = value; + } + + /// + /// Returns the contained value if one is present, or throws the given exception if none is present. + /// + public readonly T Expect + ( + Func exception + ) + { + if (!this.HasValue) + { + ThrowHelper.ThrowFunc(exception); + } + + return this.value; + } + + /// + /// Returns the contained value if present, or the provided value if not present. + /// + public readonly T Or + ( + T value + ) + => this.HasValue ? this.value : value; + + /// + /// Returns the contained value if present, or the default value for this type if not present. + /// + public readonly T? OrDefault() + => this.HasValue ? this.value : default; + + /// + /// Transforms the given optional to an optional of if it has a value, + /// returning an empty optional if there was no value present. + /// + public readonly Optional Map + ( + Func transformation + ) + { + return this.HasValue + ? new Optional(transformation(this.value)) + : new Optional(); + } + + /// + /// Transforms the value of the given optional to , returning + /// if there was no value present. + /// + public readonly TOther MapOr + ( + Func transformation, + TOther value + ) + { + return this.HasValue + ? transformation(this.value) + : value; + } + + /// + /// Returns a value indicating whether is set. + /// + /// The value of this optional. This may still be null if the set value was null. + public readonly bool TryGetValue + ( + out T? value + ) + { + if (this.HasValue) + { + value = this.value; + return true; + } + + value = default; + return false; + } + + /// + /// Returns a value indicating whether is set and not null. + /// + /// The value of this optional. + [MemberNotNullWhen(true, nameof(value))] + public readonly bool TryGetNonNullValue + ( + [NotNullWhen(true)] + out T? value + ) + { + if (this.HasValue && this.value is not null) + { + value = this.value; + return true; + } + + value = default; + return false; + } + + /// + /// Returns a string representing the present optional instance. + /// + public override string ToString() + { + return this.HasValue + ? $"Optional {{ {this.value} }}" + : "Optional { no value }"; + } +} diff --git a/src/core/DSharpPlus.Shared/ThrowHelper.cs b/src/core/DSharpPlus.Shared/ThrowHelper.cs new file mode 100644 index 0000000000..ddda4d03bc --- /dev/null +++ b/src/core/DSharpPlus.Shared/ThrowHelper.cs @@ -0,0 +1,30 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; +using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; + +namespace DSharpPlus; + +/// +/// Contains methods relegating to throw statements. +/// +internal static class ThrowHelper +{ + [DoesNotReturn] + [DebuggerHidden] + [StackTraceHidden] + public static void ThrowOptionalNoValuePresent() + => throw new InvalidOperationException("This optional did not have a value specified."); + + [DoesNotReturn] + [DebuggerHidden] + [StackTraceHidden] + public static void ThrowFunc + ( + Func func + ) + => throw func(); +} From e234cd71eb2eb99eb0cb1bf94f05dee37d7f5048 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sat, 7 Oct 2023 19:10:43 +0200 Subject: [PATCH 145/323] largest snowflake impl known to humanity --- Directory.Build.props | 2 +- .../Snowflake.GenericMath.cs | 1223 +++++++++++++++++ .../Snowflake.TimeOperations.cs | 126 ++ src/core/DSharpPlus.Shared/Snowflake.cs | 108 ++ 4 files changed, 1458 insertions(+), 1 deletion(-) create mode 100644 src/core/DSharpPlus.Shared/Snowflake.GenericMath.cs create mode 100644 src/core/DSharpPlus.Shared/Snowflake.TimeOperations.cs create mode 100644 src/core/DSharpPlus.Shared/Snowflake.cs diff --git a/Directory.Build.props b/Directory.Build.props index 6b2d4a30d7..30986dc7d1 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -8,7 +8,7 @@ True True All - $(NoWarn);CS1591;CA1028;CA1062;CA1711;CA1716;CA1720;CA2007 + $(NoWarn);CS1591;CA1028;CA1062;CA1711;CA1716;CA1720;CA2007;CA2225 True diff --git a/src/core/DSharpPlus.Shared/Snowflake.GenericMath.cs b/src/core/DSharpPlus.Shared/Snowflake.GenericMath.cs new file mode 100644 index 0000000000..f8cd865713 --- /dev/null +++ b/src/core/DSharpPlus.Shared/Snowflake.GenericMath.cs @@ -0,0 +1,1223 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +#pragma warning disable CA1031 + +using System; +using System.Numerics; +using System.Globalization; +using System.Diagnostics.CodeAnalysis; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Buffers.Binary; + +namespace DSharpPlus; + +public readonly partial record struct Snowflake : + IBinaryInteger, + IMinMaxValue, + IParsable, + ISpanFormattable, + ISpanParsable, + IIncrementOperators, + IDecrementOperators +{ + /// + public static Snowflake One => 1; + + /// + public static Snowflake Zero => 0; + + /// + public static Snowflake MaxValue => long.MaxValue; + + /// + public static Snowflake MinValue => new + ( + DiscordEpoch, + 0, + 0, + 0 + ); + + /// + static int INumberBase.Radix => 2; + + /// + static Snowflake IAdditiveIdentity.AdditiveIdentity { get; } = 0; + + /// + static Snowflake IMultiplicativeIdentity.MultiplicativeIdentity { get; } = 1; + + /// + public static Snowflake Parse + ( + ReadOnlySpan s, + NumberStyles style = NumberStyles.Integer | NumberStyles.AllowLeadingWhite, + IFormatProvider? provider = null + ) + { + return long.Parse + ( + s, + style, + provider + ); + } + + /// + public static Snowflake Parse + ( + string s, + NumberStyles style = NumberStyles.Integer | NumberStyles.AllowLeadingWhite, + IFormatProvider? provider = null + ) + { + return long.Parse + ( + s, + style, + provider + ); + } + + /// + public static Snowflake Parse + ( + ReadOnlySpan s, + IFormatProvider? provider = null + ) + { + return long.Parse + ( + s, + provider + ); + } + + /// + public static Snowflake Parse + ( + string s, + IFormatProvider? provider = null + ) + { + return long.Parse + ( + s, + provider + ); + } + + /// + public static bool TryParse + ( + ReadOnlySpan s, + NumberStyles style, + IFormatProvider? provider, + + [MaybeNullWhen(false)] + out Snowflake result + ) + { + bool success = long.TryParse + ( + s, + style, + provider, + out long value + ); + + result = success ? value : default; + + return success; + } + + /// + public static bool TryParse + ( + [NotNullWhen(true)] + string? s, + + NumberStyles style, + IFormatProvider? provider, + + [MaybeNullWhen(false)] + out Snowflake result + ) + { + bool success = long.TryParse + ( + s, + style, + provider, + out long value + ); + + result = success ? value : default; + + return success; + } + + /// + public static bool TryParse + ( + ReadOnlySpan s, + IFormatProvider? provider, + + [MaybeNullWhen(false)] + out Snowflake result + ) + { + bool success = long.TryParse + ( + s, + provider, + out long value + ); + + result = success ? value : default; + + return success; + } + + /// + public static bool TryParse + ( + [NotNullWhen(true)] + string? s, + + IFormatProvider? provider, + + [MaybeNullWhen(false)] + out Snowflake result + ) + { + bool success = long.TryParse + ( + s, + provider, + out long value + ); + + result = success ? value : default; + + return success; + } + + /// + static Snowflake INumberBase.Abs + ( + Snowflake value + ) + => long.Abs(value); + + /// + static bool INumberBase.IsCanonical + ( + Snowflake value + ) + => true; + + /// + static bool INumberBase.IsComplexNumber + ( + Snowflake value + ) + => false; + + /// + static bool INumberBase.IsEvenInteger + ( + Snowflake value + ) + => long.IsEvenInteger(value); + + /// + static bool INumberBase.IsFinite + ( + Snowflake value + ) + => true; + + /// + static bool INumberBase.IsImaginaryNumber + ( + Snowflake value + ) + => false; + + /// + static bool INumberBase.IsInfinity + ( + Snowflake value + ) + => false; + + /// + static bool INumberBase.IsInteger + ( + Snowflake value + ) + => true; + + /// + static bool INumberBase.IsNaN + ( + Snowflake value + ) + => false; + + /// + static bool INumberBase.IsNegative + ( + Snowflake value + ) + => long.IsNegative(value); + + /// + static bool INumberBase.IsNegativeInfinity + ( + Snowflake value + ) + => false; + + /// + static bool INumberBase.IsNormal + ( + Snowflake value + ) + => false; + + /// + static bool INumberBase.IsOddInteger + ( + Snowflake value + ) + => long.IsOddInteger(value); + + /// + static bool INumberBase.IsPositive + ( + Snowflake value + ) + => long.IsPositive(value); + + /// + static bool INumberBase.IsPositiveInfinity + ( + Snowflake value + ) + => false; + + /// + static bool IBinaryNumber.IsPow2 + ( + Snowflake value + ) + => long.IsPow2(value); + + /// + static bool INumberBase.IsRealNumber + ( + Snowflake value + ) + => true; + + /// + static bool INumberBase.IsSubnormal + ( + Snowflake value + ) + => false; + + /// + static bool INumberBase.IsZero + ( + Snowflake value + ) + => value == 0; + + /// + static Snowflake IBinaryNumber.Log2 + ( + Snowflake value + ) + => long.Log2(value); + + /// + static Snowflake INumberBase.MaxMagnitude + ( + Snowflake x, + Snowflake y + ) + => long.MaxMagnitude(x, y); + + /// + static Snowflake INumberBase.MaxMagnitudeNumber + ( + Snowflake x, + Snowflake y + ) + => long.MaxMagnitude(x, y); + + /// + static Snowflake INumberBase.MinMagnitude + ( + Snowflake x, + Snowflake y + ) + => long.MinMagnitude(x, y); + + /// + static Snowflake INumberBase.MinMagnitudeNumber + ( + Snowflake x, + Snowflake y + ) + => long.MinMagnitude(x, y); + + /// + static Snowflake INumberBase.Parse + ( + ReadOnlySpan s, + NumberStyles style, + IFormatProvider? provider + ) + { + return long.Parse + ( + s, + style, + provider + ); + } + + /// + static Snowflake INumberBase.Parse + ( + string s, + NumberStyles style, + IFormatProvider? provider + ) + { + return long.Parse + ( + s, + style, + provider + ); + } + + /// + static Snowflake ISpanParsable.Parse + ( + ReadOnlySpan s, + IFormatProvider? provider + ) + { + return long.Parse + ( + s, + provider + ); + } + + /// + static Snowflake IParsable.Parse + ( + string s, + IFormatProvider? provider + ) + { + return long.Parse + ( + s, + provider + ); + } + + /// + static Snowflake IBinaryInteger.PopCount + ( + Snowflake value + ) + => long.PopCount(value); + + /// + static Snowflake IBinaryInteger.TrailingZeroCount + ( + Snowflake value + ) + => long.TrailingZeroCount(value); + + /// + static bool INumberBase.TryConvertFromChecked + ( + TOther value, + out Snowflake result + ) + { + try + { + result = long.CreateChecked + ( + value + ); + + return true; + } + catch + { + result = default; + return false; + } + } + + /// + static bool INumberBase.TryConvertFromSaturating + ( + TOther value, + out Snowflake result + ) + { + try + { + result = long.CreateSaturating + ( + value + ); + + return true; + } + catch + { + result = default; + return false; + } + } + + /// + static bool INumberBase.TryConvertFromTruncating + ( + TOther value, + out Snowflake result + ) + { + try + { + result = long.CreateTruncating + ( + value + ); + + return true; + } + catch + { + result = default; + return false; + } + } + +#pragma warning disable CS8500 // we statically prove this is fine + /// + static unsafe bool INumberBase.TryConvertToChecked + ( + Snowflake value, + + [NotNullWhen(true)] + out TOther result + ) + { + if (typeof(TOther) == typeof(byte)) + { + byte actualResult = checked((byte)value); + result = *(TOther*)&actualResult; + return true; + } + else if (typeof(TOther) == typeof(char)) + { + char actualResult = checked((char)value); + result = *(TOther*)&actualResult; + return true; + } + else if (typeof(TOther) == typeof(decimal)) + { + decimal actualResult = value; + result = *(TOther*)&actualResult; + return true; + } + else if (typeof(TOther) == typeof(ushort)) + { + ulong actualResult = checked((ushort)value); + result = *(TOther*)&actualResult; + return true; + } + else if (typeof(TOther) == typeof(uint)) + { + ulong actualResult = checked((uint)value); + result = *(TOther*)&actualResult; + return true; + } + else if (typeof(TOther) == typeof(ulong)) + { + ulong actualResult = checked((ulong)value.Value); + result = *(TOther*)&actualResult; + return true; + } + else if (typeof(TOther) == typeof(UInt128)) + { + UInt128 actualResult = checked((UInt128)value.Value); + result = *(TOther*)&actualResult; + return true; + } + else if (typeof(TOther) == typeof(UIntPtr)) + { + UIntPtr actualResult = checked((UIntPtr)value.Value); + result = *(TOther*)&actualResult; + return true; + } + else + { + result = default!; + return false; + } + } + + /// + static unsafe bool INumberBase.TryConvertToSaturating + ( + Snowflake value, + + [MaybeNullWhen(false)] + out TOther result + ) + { + if (typeof(TOther) == typeof(byte)) + { + byte actualResult = value >= byte.MaxValue + ? byte.MaxValue + : value <= byte.MinValue + ? byte.MinValue + : (byte)value; + + result = *(TOther*)&actualResult; + return true; + } + else if (typeof(TOther) == typeof(char)) + { + char actualResult = value >= char.MaxValue + ? char.MaxValue + : value <= char.MinValue + ? char.MinValue + : (char)value; + + result = *(TOther*)&actualResult; + return true; + } + else if (typeof(TOther) == typeof(decimal)) + { + decimal actualResult = value; + result = *(TOther*)&actualResult; + return true; + } + else if (typeof(TOther) == typeof(ushort)) + { + ushort actualResult = value >= ushort.MaxValue + ? ushort.MaxValue + : value <= ushort.MinValue + ? ushort.MinValue + : (ushort)value; + + result = *(TOther*)&actualResult; + return true; + } + else if (typeof(TOther) == typeof(uint)) + { + uint actualResult = value >= uint.MaxValue + ? uint.MaxValue + : value <= uint.MinValue + ? uint.MinValue + : (uint)value; + + result = *(TOther*)&actualResult; + return true; + } + else if (typeof(TOther) == typeof(ulong)) + { + ulong actualResult = value <= 0 ? ulong.MinValue : (ulong)value.Value; + result = *(TOther*)&actualResult; + return true; + } + else if (typeof(TOther) == typeof(UInt128)) + { + UInt128 actualResult = (value <= 0) ? UInt128.MinValue : (UInt128)value.Value; + result = *(TOther*)&actualResult; + return true; + } + else if (typeof(TOther) == typeof(UIntPtr)) + { + UIntPtr actualResult = (value <= 0) ? 0 : (UIntPtr)value.Value; + result = *(TOther*)&actualResult; + return true; + } + else + { + result = default!; + return false; + } + } + + /// + static unsafe bool INumberBase.TryConvertToTruncating + ( + Snowflake value, + + [MaybeNullWhen(false)] + out TOther result + ) + { + if (typeof(TOther) == typeof(byte)) + { + byte actualResult = (byte)value; + result = *(TOther*)&actualResult; + return true; + } + else if (typeof(TOther) == typeof(char)) + { + char actualResult = (char)value; + result = *(TOther*)&actualResult; + return true; + } + else if (typeof(TOther) == typeof(decimal)) + { + decimal actualResult = value; + result = *(TOther*)&actualResult; + return true; + } + else if (typeof(TOther) == typeof(ushort)) + { + ushort actualResult = (ushort)value; + result = *(TOther*)&actualResult; + return true; + } + else if (typeof(TOther) == typeof(uint)) + { + uint actualResult = (uint)value; + result = *(TOther*)&actualResult; + return true; + } + else if (typeof(TOther) == typeof(ulong)) + { + ulong actualResult = (ulong)value.Value; + result = *(TOther*)&actualResult; + return true; + } + else if (typeof(TOther) == typeof(UInt128)) + { + UInt128 actualResult = (UInt128)value.Value; + result = *(TOther*)&actualResult; + return true; + } + else if (typeof(TOther) == typeof(UIntPtr)) + { + UIntPtr actualResult = (UIntPtr)value.Value; + result = *(TOther*)&actualResult; + return true; + } + else + { + result = default; + return false; + } + } +#pragma warning restore CS8500 + + /// + static bool INumberBase.TryParse + ( + ReadOnlySpan s, + NumberStyles style, + IFormatProvider? provider, + out Snowflake result + ) + { + bool success = long.TryParse + ( + s, + style, + provider, + out long value + ); + + result = success ? value : default; + + return success; + } + + /// + static bool INumberBase.TryParse + ( + [NotNullWhen(true)] + string? s, + + NumberStyles style, + IFormatProvider? provider, + out Snowflake result + ) + { + bool success = long.TryParse + ( + s, + style, + provider, + out long value + ); + + result = success ? value : default; + + return success; + } + + /// + static bool ISpanParsable.TryParse + ( + ReadOnlySpan s, + IFormatProvider? provider, + out Snowflake result + ) + { + bool success = long.TryParse + ( + s, + provider, + out long value + ); + + result = success ? value : default; + + return success; + } + + /// + static bool IParsable.TryParse + ( + string? s, + IFormatProvider? provider, + out Snowflake result + ) + { + bool success = long.TryParse + ( + s, + provider, + out long value + ); + + result = success ? value : default; + + return success; + } + + /// + static bool IBinaryInteger.TryReadBigEndian + ( + ReadOnlySpan source, + bool isUnsigned, + out Snowflake value + ) + { + if (source.Length < 8) + { + value = default; + return false; + } + + long result = Unsafe.ReadUnaligned + ( + ref MemoryMarshal.GetReference(source) + ); + + value = BitConverter.IsLittleEndian + ? BinaryPrimitives.ReverseEndianness(result) + : result; + + return true; + } + + /// + static bool IBinaryInteger.TryReadLittleEndian + ( + ReadOnlySpan source, + bool isUnsigned, + out Snowflake value + ) + { + if (source.Length < 8) + { + value = default; + return false; + } + + long result = Unsafe.ReadUnaligned + ( + ref MemoryMarshal.GetReference(source) + ); + + value = BitConverter.IsLittleEndian + ? result + : BinaryPrimitives.ReverseEndianness(result); + + return true; + } + + /// + public int CompareTo + ( + object? obj + ) + => this.Value.CompareTo(obj); + + /// + public string ToString + ( + string? format, + IFormatProvider? formatProvider = null + ) + => this.Value.ToString(format, formatProvider); + + /// + public bool TryFormat + ( + Span destination, + out int charsWritten, + ReadOnlySpan format, + IFormatProvider? provider = null + ) + { + return this.Value.TryFormat + ( + destination, + out charsWritten, + format, + provider + ); + } + + /// + int IComparable.CompareTo + ( + object? obj + ) + => this.Value.CompareTo(obj); + + /// + int IComparable.CompareTo + ( + Snowflake other + ) + => this.Value.CompareTo(other); + + /// + bool IEquatable.Equals + ( + Snowflake other + ) + => this.Value.Equals(other); + + /// + int IBinaryInteger.GetByteCount() + => 8; + + /// + int IBinaryInteger.GetShortestBitLength() + => 64 - BitOperations.LeadingZeroCount((ulong)this.Value); + + /// + string IFormattable.ToString + ( + string? format, + IFormatProvider? formatProvider + ) + { + return this.ToString + ( + format, + formatProvider + ); + } + + /// + bool ISpanFormattable.TryFormat + ( + Span destination, + out int charsWritten, + ReadOnlySpan format, + IFormatProvider? provider + ) + { + return this.TryFormat + ( + destination, + out charsWritten, + format, + provider + ); + } + + /// + bool IBinaryInteger.TryWriteBigEndian + ( + Span destination, + out int bytesWritten + ) + { + if (destination.Length < 8) + { + bytesWritten = 0; + return false; + } + + long value = BitConverter.IsLittleEndian + ? BinaryPrimitives.ReverseEndianness(this.Value) + : this.Value; + + Unsafe.WriteUnaligned + ( + ref MemoryMarshal.GetReference(destination), + value + ); + + bytesWritten = 8; + return true; + } + + /// + bool IBinaryInteger.TryWriteLittleEndian + ( + Span destination, + out int bytesWritten + ) + { + if (destination.Length < 8) + { + bytesWritten = 0; + return false; + } + + long value = !BitConverter.IsLittleEndian + ? BinaryPrimitives.ReverseEndianness(this.Value) + : this.Value; + + Unsafe.WriteUnaligned + ( + ref MemoryMarshal.GetReference(destination), + value + ); + + bytesWritten = 8; + return true; + } + + /// + static Snowflake IUnaryPlusOperators.operator + + ( + Snowflake value + ) + => +value.Value; + + /// + public static Snowflake operator + + ( + Snowflake left, + Snowflake right + ) + => left.Value + right.Value; + + /// + static Snowflake IAdditionOperators.operator + + ( + Snowflake left, + Snowflake right + ) + => left.Value + right.Value; + + static Snowflake IUnaryNegationOperators.operator - + ( + Snowflake value + ) + => -value.Value; + + /// + public static Snowflake operator - + ( + Snowflake left, + Snowflake right + ) + => left.Value - right.Value; + + /// + static Snowflake ISubtractionOperators.operator - + ( + Snowflake left, + Snowflake right + ) + => left.Value - right.Value; + + /// + static Snowflake IBitwiseOperators.operator ~ + ( + Snowflake value + ) + => ~value.Value; + + /// + public static Snowflake operator ++ + ( + Snowflake value + ) + => value.Value + 1; + + /// + static Snowflake IIncrementOperators.operator ++ + ( + Snowflake value + ) + => value.Value + 1; + + /// + public static Snowflake operator -- + ( + Snowflake value + ) + => value.Value - 1; + + /// + static Snowflake IDecrementOperators.operator -- + ( + Snowflake value + ) + => value.Value - 1; + + /// + static Snowflake IMultiplyOperators.operator * + ( + Snowflake left, + Snowflake right + ) + => left.Value * right.Value; + + /// + static Snowflake IDivisionOperators.operator / + ( + Snowflake left, + Snowflake right + ) + => left.Value / right.Value; + + /// + static Snowflake IModulusOperators.operator % + ( + Snowflake left, + Snowflake right + ) + => left.Value % right.Value; + + /// + static Snowflake IBitwiseOperators.operator & + ( + Snowflake left, + Snowflake right + ) + => left.Value & right.Value; + + /// + static Snowflake IBitwiseOperators.operator | + ( + Snowflake left, + Snowflake right + ) + => left.Value | right.Value; + + /// + static Snowflake IBitwiseOperators.operator ^ + ( + Snowflake left, + Snowflake right + ) + => left.Value ^ right.Value; + + /// + static Snowflake IShiftOperators.operator << + ( + Snowflake value, + int shiftAmount + ) + => value.Value << shiftAmount; + + /// + static Snowflake IShiftOperators.operator >> + ( + Snowflake value, + int shiftAmount + ) + => value.Value >> shiftAmount; + + /// + static bool IEqualityOperators.operator == + ( + Snowflake left, + Snowflake right + ) + => left.Value == right.Value; + + /// + static bool IEqualityOperators.operator != + ( + Snowflake left, + Snowflake right + ) + => left.Value != right.Value; + + /// + static bool IComparisonOperators.operator < + ( + Snowflake left, + Snowflake right + ) + => left.Value < right.Value; + + /// + static bool IComparisonOperators.operator > + ( + Snowflake left, + Snowflake right + ) + => left.Value > right.Value; + + /// + static bool IComparisonOperators.operator <= + ( + Snowflake left, + Snowflake right + ) + => left.Value <= right.Value; + + /// + static bool IComparisonOperators.operator >= + ( + Snowflake left, + Snowflake right + ) + => left.Value >= right.Value; + + /// + static Snowflake IShiftOperators.operator >>> + ( + Snowflake value, + int shiftAmount + ) + => value.Value >>> shiftAmount; +} diff --git a/src/core/DSharpPlus.Shared/Snowflake.TimeOperations.cs b/src/core/DSharpPlus.Shared/Snowflake.TimeOperations.cs new file mode 100644 index 0000000000..415b72fabe --- /dev/null +++ b/src/core/DSharpPlus.Shared/Snowflake.TimeOperations.cs @@ -0,0 +1,126 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; + +namespace DSharpPlus; + +public readonly partial record struct Snowflake +{ + public static Snowflake operator + + ( + Snowflake left, + TimeSpan right + ) + { + long time = (long)right.TotalMilliseconds << 22; + return left.Value + time; + } + + public static Snowflake operator - + ( + Snowflake left, + TimeSpan right + ) + { + long time = (long)right.TotalMilliseconds << 22; + return left.Value - time; + } + + public static bool operator == + ( + Snowflake left, + DateTimeOffset right + ) + => left.Timestamp == right; + + public static bool operator != + ( + Snowflake left, + DateTimeOffset right + ) + => left.Timestamp != right; + + public static bool operator < + ( + Snowflake left, + DateTimeOffset right + ) + => left.Timestamp < right; + + public static bool operator <= + ( + Snowflake left, + DateTimeOffset right + ) + => left.Timestamp <= right; + + public static bool operator > + ( + Snowflake left, + DateTimeOffset right + ) + => left.Timestamp > right; + + public static bool operator >= + ( + Snowflake left, + DateTimeOffset right + ) + => left.Timestamp >= right; + + /// + /// Returns the absolute difference in time between the two snowflakes. + /// + public static TimeSpan GetAbsoluteTimeDifference + ( + Snowflake first, + Snowflake second + ) + { + long absolute = long.Abs + ( + first - second + ); + + return new + ( + (absolute >> 22) * 10_000 + ); + } + + /// + /// Creates a new snowflake from an offset into the future. + /// + public static Snowflake FromFuture + ( + TimeSpan offset + ) + { + return new + ( + DateTimeOffset.UtcNow + offset, + 0, + 0, + 0 + ); + } + + /// + /// Creates a new snowflake from an offset into the past. + /// + public static Snowflake FromPast + ( + TimeSpan offset + ) + { + return new + ( + DateTimeOffset.UtcNow - offset, + 0, + 0, + 0 + ); + } +} diff --git a/src/core/DSharpPlus.Shared/Snowflake.cs b/src/core/DSharpPlus.Shared/Snowflake.cs new file mode 100644 index 0000000000..dc3a50c679 --- /dev/null +++ b/src/core/DSharpPlus.Shared/Snowflake.cs @@ -0,0 +1,108 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +#pragma warning disable CA5394 + +using System; + +namespace DSharpPlus; + +/// +/// Represents a discord snowflake; the type discord uses for IDs first and foremost. +/// +public readonly partial record struct Snowflake : + IComparable +{ + /// + /// The discord epoch; the start of 2015. All snowflakes are based upon this time. + /// + public static readonly DateTimeOffset DiscordEpoch = new(2015, 1, 1, 0, 0, 0, TimeSpan.Zero); + + /// + /// The snowflake's underlying value. + /// + public long Value { get; } + + /// + /// The time when this snowflake was created. + /// + public DateTimeOffset Timestamp => DiscordEpoch.AddMilliseconds + ( + this.Value >> 22 + ); + + /// + /// The internal worker's ID that was used to generate the snowflake. + /// + public byte InternalWorkerId => (byte)((this.Value & 0x3E0000) >> 17); + + /// + /// The internal process' ID that was used to generate the snowflake. + /// + public byte InternalProcessId => (byte)((this.Value & 0x1F000) >> 12); + + /// + /// The internal worker-specific and process-specific increment. + /// + public ulong InternalIncrement => (ulong)(this.Value & 0xFFF); + + /// + /// Creates a new snowflake from a given integer. + /// + /// The numerical representation to translate from. + public Snowflake(long value) + => this.Value = value; + + /// + /// Creates a fake snowflake from scratch. If no parameters are provided, returns a newly generated snowflake. + /// + /// + /// If a value larger than allowed is supplied for the three numerical parameters, it will be cut off at + /// the maximum allowed value. + /// + /// + /// The date when the snowflake was created. If null, this defaults to the current time. + /// + /// + /// A 5 bit worker id that was used to create the snowflake. If null, generates a random number between 0 and 31. + /// + /// + /// A 5 bit process id that was used to create the snowflake. If null, generates a random number between 0 and 31. + /// + /// + /// A 12 bit integer which represents the number of previously generated snowflakes in the given context. + /// If null, generates a random number between 0 and 4,095. + /// + public Snowflake + ( + DateTimeOffset? timestamp = null, + byte? workerId = null, + byte? processId = null, + ushort? increment = null + ) + { + timestamp ??= DateTimeOffset.Now; + workerId ??= (byte)Random.Shared.Next(0, 32); + processId ??= (byte)Random.Shared.Next(0, 32); + increment ??= (ushort)Random.Shared.Next(0, 4095); + + this.Value = ((long)timestamp.Value.Subtract(DiscordEpoch).TotalMilliseconds << 22) + | ((long)workerId.Value << 17) + | ((long)processId.Value << 12) + | increment.Value; + } + + public int CompareTo + ( + Snowflake other + ) + => this.Value.CompareTo(other.Value); + + public static bool operator <(Snowflake left, Snowflake right) => left.Value < right.Value; + public static bool operator <=(Snowflake left, Snowflake right) => left.Value <= right.Value; + public static bool operator >(Snowflake left, Snowflake right) => left.Value > right.Value; + public static bool operator >=(Snowflake left, Snowflake right) => left.Value >= right.Value; + public static implicit operator long(Snowflake snowflake) => snowflake.Value; + public static implicit operator Snowflake(long value) => value; +} From f295ffbcfbb28f9e8dfcdcaedab0d4706300533d Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Mon, 9 Oct 2023 16:34:22 +0200 Subject: [PATCH 146/323] no allman for expression bodies --- .../Snowflake.GenericMath.cs | 309 ++++-------------- .../Snowflake.TimeOperations.cs | 36 +- 2 files changed, 63 insertions(+), 282 deletions(-) diff --git a/src/core/DSharpPlus.Shared/Snowflake.GenericMath.cs b/src/core/DSharpPlus.Shared/Snowflake.GenericMath.cs index f8cd865713..5c4f102e91 100644 --- a/src/core/DSharpPlus.Shared/Snowflake.GenericMath.cs +++ b/src/core/DSharpPlus.Shared/Snowflake.GenericMath.cs @@ -207,175 +207,99 @@ out long value } /// - static Snowflake INumberBase.Abs - ( - Snowflake value - ) + static Snowflake INumberBase.Abs(Snowflake value) => long.Abs(value); /// - static bool INumberBase.IsCanonical - ( - Snowflake value - ) + static bool INumberBase.IsCanonical(Snowflake value) => true; /// - static bool INumberBase.IsComplexNumber - ( - Snowflake value - ) + static bool INumberBase.IsComplexNumber(Snowflake value) => false; /// - static bool INumberBase.IsEvenInteger - ( - Snowflake value - ) + static bool INumberBase.IsEvenInteger(Snowflake value) => long.IsEvenInteger(value); /// - static bool INumberBase.IsFinite - ( - Snowflake value - ) + static bool INumberBase.IsFinite(Snowflake value) => true; /// - static bool INumberBase.IsImaginaryNumber - ( - Snowflake value - ) + static bool INumberBase.IsImaginaryNumber(Snowflake value) => false; /// - static bool INumberBase.IsInfinity - ( - Snowflake value - ) + static bool INumberBase.IsInfinity(Snowflake value) => false; /// - static bool INumberBase.IsInteger - ( - Snowflake value - ) + static bool INumberBase.IsInteger(Snowflake value) => true; /// - static bool INumberBase.IsNaN - ( - Snowflake value - ) + static bool INumberBase.IsNaN(Snowflake value) => false; /// - static bool INumberBase.IsNegative - ( - Snowflake value - ) + static bool INumberBase.IsNegative(Snowflake value) => long.IsNegative(value); /// - static bool INumberBase.IsNegativeInfinity - ( - Snowflake value - ) + static bool INumberBase.IsNegativeInfinity(Snowflake value) => false; /// - static bool INumberBase.IsNormal - ( - Snowflake value - ) + static bool INumberBase.IsNormal(Snowflake value) => false; /// - static bool INumberBase.IsOddInteger - ( - Snowflake value - ) + static bool INumberBase.IsOddInteger(Snowflake value) => long.IsOddInteger(value); /// - static bool INumberBase.IsPositive - ( - Snowflake value - ) + static bool INumberBase.IsPositive(Snowflake value) => long.IsPositive(value); /// - static bool INumberBase.IsPositiveInfinity - ( - Snowflake value - ) + static bool INumberBase.IsPositiveInfinity(Snowflake value) => false; /// - static bool IBinaryNumber.IsPow2 - ( - Snowflake value - ) + static bool IBinaryNumber.IsPow2(Snowflake value) => long.IsPow2(value); /// - static bool INumberBase.IsRealNumber - ( - Snowflake value - ) + static bool INumberBase.IsRealNumber(Snowflake value) => true; /// - static bool INumberBase.IsSubnormal - ( - Snowflake value - ) + static bool INumberBase.IsSubnormal(Snowflake value) => false; /// - static bool INumberBase.IsZero - ( - Snowflake value - ) + static bool INumberBase.IsZero(Snowflake value) => value == 0; /// - static Snowflake IBinaryNumber.Log2 - ( - Snowflake value - ) + static Snowflake IBinaryNumber.Log2(Snowflake value) => long.Log2(value); /// - static Snowflake INumberBase.MaxMagnitude - ( - Snowflake x, - Snowflake y - ) + static Snowflake INumberBase.MaxMagnitude(Snowflake x, Snowflake y) => long.MaxMagnitude(x, y); /// - static Snowflake INumberBase.MaxMagnitudeNumber - ( - Snowflake x, - Snowflake y - ) + static Snowflake INumberBase.MaxMagnitudeNumber(Snowflake x, Snowflake y) => long.MaxMagnitude(x, y); /// - static Snowflake INumberBase.MinMagnitude - ( - Snowflake x, - Snowflake y - ) + static Snowflake INumberBase.MinMagnitude(Snowflake x, Snowflake y) => long.MinMagnitude(x, y); /// - static Snowflake INumberBase.MinMagnitudeNumber - ( - Snowflake x, - Snowflake y - ) + static Snowflake INumberBase.MinMagnitudeNumber(Snowflake x, Snowflake y) => long.MinMagnitude(x, y); /// @@ -439,17 +363,11 @@ static Snowflake IParsable.Parse } /// - static Snowflake IBinaryInteger.PopCount - ( - Snowflake value - ) + static Snowflake IBinaryInteger.PopCount(Snowflake value) => long.PopCount(value); /// - static Snowflake IBinaryInteger.TrailingZeroCount - ( - Snowflake value - ) + static Snowflake IBinaryInteger.TrailingZeroCount(Snowflake value) => long.TrailingZeroCount(value); /// @@ -874,18 +792,11 @@ ref MemoryMarshal.GetReference(source) } /// - public int CompareTo - ( - object? obj - ) + public int CompareTo(object? obj) => this.Value.CompareTo(obj); /// - public string ToString - ( - string? format, - IFormatProvider? formatProvider = null - ) + public string ToString(string? format, IFormatProvider? formatProvider = null) => this.Value.ToString(format, formatProvider); /// @@ -907,24 +818,15 @@ public bool TryFormat } /// - int IComparable.CompareTo - ( - object? obj - ) + int IComparable.CompareTo(object? obj) => this.Value.CompareTo(obj); /// - int IComparable.CompareTo - ( - Snowflake other - ) + int IComparable.CompareTo(Snowflake other) => this.Value.CompareTo(other); /// - bool IEquatable.Equals - ( - Snowflake other - ) + bool IEquatable.Equals(Snowflake other) => this.Value.Equals(other); /// @@ -1022,202 +924,105 @@ ref MemoryMarshal.GetReference(destination), } /// - static Snowflake IUnaryPlusOperators.operator + - ( - Snowflake value - ) + static Snowflake IUnaryPlusOperators.operator +(Snowflake value) => +value.Value; /// - public static Snowflake operator + - ( - Snowflake left, - Snowflake right - ) + public static Snowflake operator +(Snowflake left, Snowflake right) => left.Value + right.Value; /// - static Snowflake IAdditionOperators.operator + - ( - Snowflake left, - Snowflake right - ) + static Snowflake IAdditionOperators.operator +(Snowflake left, Snowflake right) => left.Value + right.Value; - static Snowflake IUnaryNegationOperators.operator - - ( - Snowflake value - ) + static Snowflake IUnaryNegationOperators.operator -(Snowflake value) => -value.Value; /// - public static Snowflake operator - - ( - Snowflake left, - Snowflake right - ) + public static Snowflake operator -(Snowflake left,Snowflake right) => left.Value - right.Value; /// - static Snowflake ISubtractionOperators.operator - - ( - Snowflake left, - Snowflake right - ) + static Snowflake ISubtractionOperators.operator -(Snowflake left, Snowflake right) => left.Value - right.Value; /// - static Snowflake IBitwiseOperators.operator ~ - ( - Snowflake value - ) + static Snowflake IBitwiseOperators.operator ~(Snowflake value) => ~value.Value; /// - public static Snowflake operator ++ - ( - Snowflake value - ) + public static Snowflake operator ++(Snowflake value) => value.Value + 1; /// - static Snowflake IIncrementOperators.operator ++ - ( - Snowflake value - ) + static Snowflake IIncrementOperators.operator ++(Snowflake value) => value.Value + 1; /// - public static Snowflake operator -- - ( - Snowflake value - ) + public static Snowflake operator --(Snowflake value) => value.Value - 1; /// - static Snowflake IDecrementOperators.operator -- - ( - Snowflake value - ) + static Snowflake IDecrementOperators.operator --(Snowflake value) => value.Value - 1; /// - static Snowflake IMultiplyOperators.operator * - ( - Snowflake left, - Snowflake right - ) + static Snowflake IMultiplyOperators.operator *(Snowflake left, Snowflake right) => left.Value * right.Value; /// - static Snowflake IDivisionOperators.operator / - ( - Snowflake left, - Snowflake right - ) + static Snowflake IDivisionOperators.operator /(Snowflake left, Snowflake right) => left.Value / right.Value; /// - static Snowflake IModulusOperators.operator % - ( - Snowflake left, - Snowflake right - ) + static Snowflake IModulusOperators.operator %(Snowflake left, Snowflake right) => left.Value % right.Value; /// - static Snowflake IBitwiseOperators.operator & - ( - Snowflake left, - Snowflake right - ) + static Snowflake IBitwiseOperators.operator &(Snowflake left, Snowflake right) => left.Value & right.Value; /// - static Snowflake IBitwiseOperators.operator | - ( - Snowflake left, - Snowflake right - ) + static Snowflake IBitwiseOperators.operator |(Snowflake left, Snowflake right) => left.Value | right.Value; /// - static Snowflake IBitwiseOperators.operator ^ - ( - Snowflake left, - Snowflake right - ) + static Snowflake IBitwiseOperators.operator ^(Snowflake left, Snowflake right) => left.Value ^ right.Value; /// - static Snowflake IShiftOperators.operator << - ( - Snowflake value, - int shiftAmount - ) + static Snowflake IShiftOperators.operator <<(Snowflake value, int shiftAmount) => value.Value << shiftAmount; /// - static Snowflake IShiftOperators.operator >> - ( - Snowflake value, - int shiftAmount - ) + static Snowflake IShiftOperators.operator >>(Snowflake value, int shiftAmount) => value.Value >> shiftAmount; /// - static bool IEqualityOperators.operator == - ( - Snowflake left, - Snowflake right - ) + static bool IEqualityOperators.operator ==(Snowflake left, Snowflake right) => left.Value == right.Value; /// - static bool IEqualityOperators.operator != - ( - Snowflake left, - Snowflake right - ) + static bool IEqualityOperators.operator !=(Snowflake left, Snowflake right) => left.Value != right.Value; /// - static bool IComparisonOperators.operator < - ( - Snowflake left, - Snowflake right - ) + static bool IComparisonOperators.operator <(Snowflake left, Snowflake right) => left.Value < right.Value; /// - static bool IComparisonOperators.operator > - ( - Snowflake left, - Snowflake right - ) + static bool IComparisonOperators.operator >(Snowflake left, Snowflake right) => left.Value > right.Value; /// - static bool IComparisonOperators.operator <= - ( - Snowflake left, - Snowflake right - ) + static bool IComparisonOperators.operator <=(Snowflake left, Snowflake right) => left.Value <= right.Value; /// - static bool IComparisonOperators.operator >= - ( - Snowflake left, - Snowflake right - ) + static bool IComparisonOperators.operator >=(Snowflake left, Snowflake right) => left.Value >= right.Value; /// - static Snowflake IShiftOperators.operator >>> - ( - Snowflake value, - int shiftAmount - ) + static Snowflake IShiftOperators.operator >>>(Snowflake value, int shiftAmount) => value.Value >>> shiftAmount; } diff --git a/src/core/DSharpPlus.Shared/Snowflake.TimeOperations.cs b/src/core/DSharpPlus.Shared/Snowflake.TimeOperations.cs index 415b72fabe..b47ac49b3b 100644 --- a/src/core/DSharpPlus.Shared/Snowflake.TimeOperations.cs +++ b/src/core/DSharpPlus.Shared/Snowflake.TimeOperations.cs @@ -28,46 +28,22 @@ TimeSpan right return left.Value - time; } - public static bool operator == - ( - Snowflake left, - DateTimeOffset right - ) + public static bool operator ==(Snowflake left, DateTimeOffset right) => left.Timestamp == right; - public static bool operator != - ( - Snowflake left, - DateTimeOffset right - ) + public static bool operator !=(Snowflake left, DateTimeOffset right) => left.Timestamp != right; - public static bool operator < - ( - Snowflake left, - DateTimeOffset right - ) + public static bool operator <(Snowflake left, DateTimeOffset right) => left.Timestamp < right; - public static bool operator <= - ( - Snowflake left, - DateTimeOffset right - ) + public static bool operator <=(Snowflake left, DateTimeOffset right) => left.Timestamp <= right; - public static bool operator > - ( - Snowflake left, - DateTimeOffset right - ) + public static bool operator >(Snowflake left, DateTimeOffset right) => left.Timestamp > right; - public static bool operator >= - ( - Snowflake left, - DateTimeOffset right - ) + public static bool operator >=(Snowflake left, DateTimeOffset right) => left.Timestamp >= right; /// From 12006143c28042cec51fc60ff8bbcadec0ea0b06 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Mon, 9 Oct 2023 17:42:22 +0200 Subject: [PATCH 147/323] missed one spot with parameter style --- src/core/DSharpPlus.Shared/Optional`1.cs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/core/DSharpPlus.Shared/Optional`1.cs b/src/core/DSharpPlus.Shared/Optional`1.cs index e95d19e109..12c4220595 100644 --- a/src/core/DSharpPlus.Shared/Optional`1.cs +++ b/src/core/DSharpPlus.Shared/Optional`1.cs @@ -62,10 +62,7 @@ Func exception /// /// Returns the contained value if present, or the provided value if not present. /// - public readonly T Or - ( - T value - ) + public readonly T Or(T value) => this.HasValue ? this.value : value; /// From 5a348fc2f2128830bd716b578c100cdc3b2fbe2b Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Mon, 9 Oct 2023 18:42:04 +0200 Subject: [PATCH 148/323] use our own optionals and snowflakes --- Directory.Packages.props | 3 --- .../ApplicationCommands/IApplicationCommand.cs | 4 +--- .../ApplicationCommands/IApplicationCommandOption.cs | 2 -- .../ApplicationCommands/IApplicationCommandOptionChoice.cs | 2 -- .../ApplicationCommands/IApplicationCommandPermission.cs | 4 +--- .../ApplicationCommands/IApplicationCommandPermissions.cs | 2 -- .../IPartialApplicationCommandPermissions.cs | 2 -- .../Applications/IApplication.cs | 2 -- .../Applications/IPartialApplication.cs | 2 -- .../AuditLogs/IAuditLogChange.cs | 2 -- .../AuditLogs/IAuditLogEntry.cs | 2 -- .../AuditLogs/IAuditLogEntryInfo.cs | 2 -- .../AutoModeration/IAutoModerationAction.cs | 2 -- .../AutoModeration/IAutoModerationRule.cs | 2 -- .../AutoModeration/IAutoModerationTriggerMetadata.cs | 2 -- .../AutoModeration/IBlockMessageActionMetadata.cs | 2 -- .../AutoModeration/IPartialAutoModerationRule.cs | 2 -- .../AutoModeration/ISendAlertMessageActionMetadata.cs | 2 -- .../Channels/IAllowedMentions.cs | 2 -- .../Channels/IAttachment.cs | 2 -- .../DSharpPlus.Core.Abstractions.Models/Channels/IChannel.cs | 2 -- .../Channels/IChannelMention.cs | 2 -- .../Channels/IChannelOverwrite.cs | 2 -- .../Channels/IDefaultReaction.cs | 2 -- .../DSharpPlus.Core.Abstractions.Models/Channels/IEmbed.cs | 2 -- .../Channels/IEmbedAuthor.cs | 2 -- .../Channels/IEmbedField.cs | 2 -- .../Channels/IEmbedFooter.cs | 2 -- .../Channels/IEmbedImage.cs | 2 -- .../Channels/IEmbedProvider.cs | 2 -- .../Channels/IEmbedThumbnail.cs | 2 -- .../Channels/IEmbedVideo.cs | 2 -- .../Channels/IFollowedChannel.cs | 2 -- .../Channels/IForumTag.cs | 2 -- .../DSharpPlus.Core.Abstractions.Models/Channels/IMessage.cs | 2 -- .../Channels/IMessageActivity.cs | 2 -- .../Channels/IMessageReference.cs | 2 -- .../Channels/IPartialAttachment.cs | 2 -- .../Channels/IPartialChannel.cs | 2 -- .../Channels/IPartialChannelOverwrite.cs | 2 -- .../Channels/IPartialMessage.cs | 2 -- .../Channels/IRoleSubscriptionData.cs | 2 -- .../Channels/IThreadMember.cs | 2 -- .../Channels/IThreadMetadata.cs | 2 -- .../DSharpPlus.Core.Abstractions.Models.csproj | 1 - .../DSharpPlus.Core.Abstractions.Models/Emojis/IEmoji.cs | 2 -- .../Emojis/IPartialEmoji.cs | 2 -- .../Entitlements/IEntitlement.cs | 2 -- .../GuildTemplates/ITemplate.cs | 2 -- .../DSharpPlus.Core.Abstractions.Models/Guilds/IGuild.cs | 2 -- .../Guilds/IGuildMember.cs | 2 -- .../Guilds/IGuildPreview.cs | 2 -- .../Guilds/IGuildWidget.cs | 2 -- .../Guilds/IGuildWidgetSettings.cs | 2 -- .../Guilds/IIntegration.cs | 2 -- .../Guilds/IIntegrationApplication.cs | 2 -- .../Guilds/IOnboarding.cs | 2 -- .../Guilds/IOnboardingPrompt.cs | 2 -- .../Guilds/IOnboardingPromptOption.cs | 2 -- .../Guilds/IPartialGuild.cs | 2 -- .../Guilds/IPartialGuildMember.cs | 2 -- .../Guilds/IPartialIntegration.cs | 2 -- .../Guilds/IPartialRole.cs | 2 -- src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IRole.cs | 2 -- .../DSharpPlus.Core.Abstractions.Models/Guilds/IRoleTags.cs | 2 -- .../Guilds/IWelcomeScreenChannel.cs | 2 -- .../Interactions/IApplicationCommandInteractionData.cs | 2 -- .../Interactions/IApplicationCommandInteractionDataOption.cs | 2 -- .../Interactions/IInteraction.cs | 2 -- .../Interactions/IInteractionResponse.cs | 2 -- .../Interactions/IMessageCallbackData.cs | 2 -- .../Interactions/IMessageComponentInteractionData.cs | 2 -- .../Interactions/IMessageInteraction.cs | 2 -- .../Interactions/IResolvedData.cs | 2 -- .../DSharpPlus.Core.Abstractions.Models/Invites/IInvite.cs | 2 -- .../Invites/IPartialInvite.cs | 2 -- .../MessageComponents/IButtonComponent.cs | 2 -- .../MessageComponents/IChannelSelectComponent.cs | 2 -- .../MessageComponents/IDefaultSelectValue.cs | 2 -- .../MessageComponents/IMentionableSelectComponent.cs | 2 -- .../MessageComponents/IRoleSelectComponent.cs | 2 -- .../MessageComponents/ISelectOption.cs | 2 -- .../MessageComponents/IStringSelectComponent.cs | 2 -- .../MessageComponents/ITextInputComponent.cs | 2 -- .../MessageComponents/IUserSelectComponent.cs | 2 -- .../RoleConnections/IRoleConnectionMetadata.cs | 2 -- .../ScheduledEvents/IPartialScheduledEvent.cs | 5 ++--- .../ScheduledEvents/IScheduledEvent.cs | 2 -- .../ScheduledEvents/IScheduledEventUser.cs | 2 -- src/core/DSharpPlus.Core.Abstractions.Models/Skus/ISku.cs | 2 -- .../StageInstances/IPartialStageInstance.cs | 2 -- .../StageInstances/IStageInstance.cs | 1 - .../Stickers/IPartialSticker.cs | 2 -- .../DSharpPlus.Core.Abstractions.Models/Stickers/ISticker.cs | 2 -- .../Stickers/IStickerItem.cs | 2 -- .../Stickers/IStickerPack.cs | 2 -- src/core/DSharpPlus.Core.Abstractions.Models/Teams/ITeam.cs | 2 -- .../DSharpPlus.Core.Abstractions.Models/Teams/ITeamMember.cs | 2 -- .../DSharpPlus.Core.Abstractions.Models/Users/IConnection.cs | 2 -- .../Users/IPartialUser.cs | 1 - src/core/DSharpPlus.Core.Abstractions.Models/Users/IUser.cs | 2 -- .../DSharpPlus.Core.Abstractions.Models/Voice/IVoiceState.cs | 2 -- .../Webhooks/IPartialWebhook.cs | 2 -- .../DSharpPlus.Core.Abstractions.Models/Webhooks/IWebhook.cs | 2 -- .../ApplicationCommands/ApplicationCommand.cs | 2 -- .../ApplicationCommands/ApplicationCommandOption.cs | 2 -- .../ApplicationCommands/ApplicationCommandOptionChoice.cs | 2 -- .../ApplicationCommands/ApplicationCommandPermission.cs | 2 -- .../ApplicationCommands/ApplicationCommandPermissions.cs | 2 -- .../PartialApplicationCommandPermissions.cs | 2 -- src/core/DSharpPlus.Core.Models/Applications/Application.cs | 2 -- .../Applications/PartialApplication.cs | 2 -- src/core/DSharpPlus.Core.Models/AuditLogs/AuditLogChange.cs | 5 ----- src/core/DSharpPlus.Core.Models/AuditLogs/AuditLogEntry.cs | 2 -- .../DSharpPlus.Core.Models/AuditLogs/AuditLogEntryInfo.cs | 5 ----- .../AutoModeration/AutoModerationAction.cs | 2 -- .../AutoModeration/AutoModerationRule.cs | 2 -- .../AutoModeration/AutoModerationTriggerMetadata.cs | 2 -- .../AutoModeration/BlockMessageActionMetadata.cs | 2 -- .../AutoModeration/PartialAutoModerationRule.cs | 2 -- .../AutoModeration/SendAlertMessageActionMetadata.cs | 2 -- src/core/DSharpPlus.Core.Models/Channels/AllowedMentions.cs | 2 -- src/core/DSharpPlus.Core.Models/Channels/Attachment.cs | 2 -- src/core/DSharpPlus.Core.Models/Channels/Channel.cs | 2 -- src/core/DSharpPlus.Core.Models/Channels/ChannelMention.cs | 2 -- src/core/DSharpPlus.Core.Models/Channels/ChannelOverwrite.cs | 2 -- src/core/DSharpPlus.Core.Models/Channels/DefaultReaction.cs | 5 ----- src/core/DSharpPlus.Core.Models/Channels/Embed.cs | 2 -- src/core/DSharpPlus.Core.Models/Channels/EmbedAuthor.cs | 5 ----- src/core/DSharpPlus.Core.Models/Channels/EmbedField.cs | 5 ----- src/core/DSharpPlus.Core.Models/Channels/EmbedFooter.cs | 5 ----- src/core/DSharpPlus.Core.Models/Channels/EmbedImage.cs | 5 ----- src/core/DSharpPlus.Core.Models/Channels/EmbedProvider.cs | 5 ----- src/core/DSharpPlus.Core.Models/Channels/EmbedThumbnail.cs | 5 ----- src/core/DSharpPlus.Core.Models/Channels/EmbedVideo.cs | 5 ----- src/core/DSharpPlus.Core.Models/Channels/FollowedChannel.cs | 5 ----- src/core/DSharpPlus.Core.Models/Channels/ForumTag.cs | 5 ----- src/core/DSharpPlus.Core.Models/Channels/Message.cs | 2 -- src/core/DSharpPlus.Core.Models/Channels/MessageActivity.cs | 2 -- src/core/DSharpPlus.Core.Models/Channels/MessageReference.cs | 5 ----- .../DSharpPlus.Core.Models/Channels/PartialAttachment.cs | 2 -- src/core/DSharpPlus.Core.Models/Channels/PartialChannel.cs | 2 -- .../Channels/PartialChannelOverwrite.cs | 2 -- src/core/DSharpPlus.Core.Models/Channels/PartialMessage.cs | 2 -- .../DSharpPlus.Core.Models/Channels/RoleSubscriptionData.cs | 5 ----- src/core/DSharpPlus.Core.Models/Channels/ThreadMember.cs | 2 -- src/core/DSharpPlus.Core.Models/Channels/ThreadMetadata.cs | 2 -- src/core/DSharpPlus.Core.Models/Emojis/Emoji.cs | 2 -- src/core/DSharpPlus.Core.Models/Emojis/PartialEmoji.cs | 2 -- src/core/DSharpPlus.Core.Models/Entitlements/Entitlement.cs | 2 -- src/core/DSharpPlus.Core.Models/GuildTemplates/Template.cs | 2 -- src/core/DSharpPlus.Core.Models/Guilds/Guild.cs | 2 -- src/core/DSharpPlus.Core.Models/Guilds/GuildMember.cs | 2 -- src/core/DSharpPlus.Core.Models/Guilds/GuildPreview.cs | 2 -- src/core/DSharpPlus.Core.Models/Guilds/GuildWidget.cs | 2 -- .../DSharpPlus.Core.Models/Guilds/GuildWidgetSettings.cs | 5 ----- src/core/DSharpPlus.Core.Models/Guilds/Integration.cs | 2 -- .../DSharpPlus.Core.Models/Guilds/IntegrationApplication.cs | 5 ----- src/core/DSharpPlus.Core.Models/Guilds/Onboarding.cs | 2 -- src/core/DSharpPlus.Core.Models/Guilds/OnboardingPrompt.cs | 2 -- .../DSharpPlus.Core.Models/Guilds/OnboardingPromptOption.cs | 2 -- src/core/DSharpPlus.Core.Models/Guilds/PartialGuild.cs | 2 -- src/core/DSharpPlus.Core.Models/Guilds/PartialGuildMember.cs | 2 -- src/core/DSharpPlus.Core.Models/Guilds/PartialIntegration.cs | 2 -- src/core/DSharpPlus.Core.Models/Guilds/PartialRole.cs | 2 -- src/core/DSharpPlus.Core.Models/Guilds/Role.cs | 2 -- src/core/DSharpPlus.Core.Models/Guilds/RoleTags.cs | 5 ----- .../DSharpPlus.Core.Models/Guilds/WelcomeScreenChannel.cs | 5 ----- .../Interactions/ApplicationCommandInteractionData.cs | 2 -- .../Interactions/ApplicationCommandInteractionDataOption.cs | 2 -- src/core/DSharpPlus.Core.Models/Interactions/Interaction.cs | 2 -- .../Interactions/InteractionResponse.cs | 2 -- .../Interactions/MessageCallbackData.cs | 2 -- .../Interactions/MessageComponentInteractionData.cs | 2 -- .../Interactions/MessageInteraction.cs | 2 -- src/core/DSharpPlus.Core.Models/Interactions/ResolvedData.cs | 2 -- src/core/DSharpPlus.Core.Models/Invites/Invite.cs | 2 -- src/core/DSharpPlus.Core.Models/Invites/PartialInvite.cs | 2 -- .../MessageComponents/ButtonComponent.cs | 2 -- .../MessageComponents/ChannelSelectComponent.cs | 2 -- .../MessageComponents/DefaultSelectValue.cs | 5 ----- .../MessageComponents/MentionableSelectComponent.cs | 2 -- .../MessageComponents/RoleSelectComponent.cs | 2 -- .../DSharpPlus.Core.Models/MessageComponents/SelectOption.cs | 5 ----- .../MessageComponents/StringSelectComponent.cs | 2 -- .../MessageComponents/TextInputComponent.cs | 2 -- .../MessageComponents/UserSelectComponent.cs | 2 -- .../RoleConnections/RoleConnectionMetadata.cs | 2 -- .../ScheduledEvents/PartialScheduledEvent.cs | 5 ++--- .../DSharpPlus.Core.Models/ScheduledEvents/ScheduledEvent.cs | 5 ++--- .../ScheduledEvents/ScheduledEventUser.cs | 5 ----- src/core/DSharpPlus.Core.Models/Skus/Sku.cs | 2 -- .../StageInstances/PartialStageInstance.cs | 2 -- .../DSharpPlus.Core.Models/StageInstances/StageInstance.cs | 2 -- src/core/DSharpPlus.Core.Models/Stickers/PartialSticker.cs | 2 -- src/core/DSharpPlus.Core.Models/Stickers/Sticker.cs | 2 -- src/core/DSharpPlus.Core.Models/Stickers/StickerItem.cs | 2 -- src/core/DSharpPlus.Core.Models/Stickers/StickerPack.cs | 2 -- src/core/DSharpPlus.Core.Models/Teams/Team.cs | 2 -- src/core/DSharpPlus.Core.Models/Teams/TeamMember.cs | 2 -- src/core/DSharpPlus.Core.Models/Users/Connection.cs | 2 -- src/core/DSharpPlus.Core.Models/Users/PartialUser.cs | 1 - src/core/DSharpPlus.Core.Models/Users/User.cs | 1 - src/core/DSharpPlus.Core.Models/Voice/VoiceState.cs | 2 -- src/core/DSharpPlus.Core.Models/Webhooks/PartialWebhook.cs | 2 -- src/core/DSharpPlus.Core.Models/Webhooks/Webhook.cs | 2 -- src/core/DSharpPlus.Shared/Optional`1.cs | 3 +++ src/core/DSharpPlus.Shared/Snowflake.cs | 5 +---- 208 files changed, 12 insertions(+), 480 deletions(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index de17aa0926..cffe35174e 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -8,9 +8,6 @@ - - - diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/ApplicationCommands/IApplicationCommand.cs b/src/core/DSharpPlus.Core.Abstractions.Models/ApplicationCommands/IApplicationCommand.cs index 255fcd882e..11b8ee11b1 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/ApplicationCommands/IApplicationCommand.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/ApplicationCommands/IApplicationCommand.cs @@ -1,4 +1,4 @@ -// This Source Code form is subject to the terms of the Mozilla Public +// This Source Code form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. @@ -6,8 +6,6 @@ using DSharpPlus.Entities; -using Remora.Rest.Core; - namespace DSharpPlus.Core.Abstractions.Models; /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/ApplicationCommands/IApplicationCommandOption.cs b/src/core/DSharpPlus.Core.Abstractions.Models/ApplicationCommands/IApplicationCommandOption.cs index 8d1fe47bdf..8c749764da 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/ApplicationCommands/IApplicationCommandOption.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/ApplicationCommands/IApplicationCommandOption.cs @@ -8,8 +8,6 @@ using OneOf; -using Remora.Rest.Core; - namespace DSharpPlus.Core.Abstractions.Models; /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/ApplicationCommands/IApplicationCommandOptionChoice.cs b/src/core/DSharpPlus.Core.Abstractions.Models/ApplicationCommands/IApplicationCommandOptionChoice.cs index 9c30f25624..12c6e0a6e3 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/ApplicationCommands/IApplicationCommandOptionChoice.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/ApplicationCommands/IApplicationCommandOptionChoice.cs @@ -6,8 +6,6 @@ using OneOf; -using Remora.Rest.Core; - namespace DSharpPlus.Core.Abstractions.Models; /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/ApplicationCommands/IApplicationCommandPermission.cs b/src/core/DSharpPlus.Core.Abstractions.Models/ApplicationCommands/IApplicationCommandPermission.cs index 616c8ade57..64472d5390 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/ApplicationCommands/IApplicationCommandPermission.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/ApplicationCommands/IApplicationCommandPermission.cs @@ -1,11 +1,9 @@ -// This Source Code form is subject to the terms of the Mozilla Public +// This Source Code form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. using DSharpPlus.Entities; -using Remora.Rest.Core; - namespace DSharpPlus.Core.Abstractions.Models; /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/ApplicationCommands/IApplicationCommandPermissions.cs b/src/core/DSharpPlus.Core.Abstractions.Models/ApplicationCommands/IApplicationCommandPermissions.cs index bb6c38fba3..bc17c26ee4 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/ApplicationCommands/IApplicationCommandPermissions.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/ApplicationCommands/IApplicationCommandPermissions.cs @@ -4,8 +4,6 @@ using System.Collections.Generic; -using Remora.Rest.Core; - namespace DSharpPlus.Core.Abstractions.Models; /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/ApplicationCommands/IPartialApplicationCommandPermissions.cs b/src/core/DSharpPlus.Core.Abstractions.Models/ApplicationCommands/IPartialApplicationCommandPermissions.cs index 432dd00289..376a257ba3 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/ApplicationCommands/IPartialApplicationCommandPermissions.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/ApplicationCommands/IPartialApplicationCommandPermissions.cs @@ -4,8 +4,6 @@ using System.Collections.Generic; -using Remora.Rest.Core; - namespace DSharpPlus.Core.Abstractions.Models; /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Applications/IApplication.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Applications/IApplication.cs index dcc80f6a10..b1ca293301 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Applications/IApplication.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Applications/IApplication.cs @@ -2,8 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using Remora.Rest.Core; - namespace DSharpPlus.Core.Abstractions.Models; /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Applications/IPartialApplication.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Applications/IPartialApplication.cs index de8ab10b9f..db4655e717 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Applications/IPartialApplication.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Applications/IPartialApplication.cs @@ -6,8 +6,6 @@ using DSharpPlus.Entities; -using Remora.Rest.Core; - namespace DSharpPlus.Core.Abstractions.Models; /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/AuditLogs/IAuditLogChange.cs b/src/core/DSharpPlus.Core.Abstractions.Models/AuditLogs/IAuditLogChange.cs index 101c6201a8..b20e9ca75e 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/AuditLogs/IAuditLogChange.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/AuditLogs/IAuditLogChange.cs @@ -2,8 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using Remora.Rest.Core; - namespace DSharpPlus.Core.Abstractions.Models; /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/AuditLogs/IAuditLogEntry.cs b/src/core/DSharpPlus.Core.Abstractions.Models/AuditLogs/IAuditLogEntry.cs index 270f4956f0..5d112d5780 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/AuditLogs/IAuditLogEntry.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/AuditLogs/IAuditLogEntry.cs @@ -8,8 +8,6 @@ using OneOf; -using Remora.Rest.Core; - namespace DSharpPlus.Core.Abstractions.Models; /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/AuditLogs/IAuditLogEntryInfo.cs b/src/core/DSharpPlus.Core.Abstractions.Models/AuditLogs/IAuditLogEntryInfo.cs index 18c0edd7ac..ff01aff5b8 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/AuditLogs/IAuditLogEntryInfo.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/AuditLogs/IAuditLogEntryInfo.cs @@ -2,8 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using Remora.Rest.Core; - namespace DSharpPlus.Core.Abstractions.Models; /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/AutoModeration/IAutoModerationAction.cs b/src/core/DSharpPlus.Core.Abstractions.Models/AutoModeration/IAutoModerationAction.cs index 5ac15fc5f1..2adad473a3 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/AutoModeration/IAutoModerationAction.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/AutoModeration/IAutoModerationAction.cs @@ -4,8 +4,6 @@ using DSharpPlus.Entities; -using Remora.Rest.Core; - namespace DSharpPlus.Core.Abstractions.Models; /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/AutoModeration/IAutoModerationRule.cs b/src/core/DSharpPlus.Core.Abstractions.Models/AutoModeration/IAutoModerationRule.cs index c96793442d..c279a0df3b 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/AutoModeration/IAutoModerationRule.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/AutoModeration/IAutoModerationRule.cs @@ -6,8 +6,6 @@ using DSharpPlus.Entities; -using Remora.Rest.Core; - namespace DSharpPlus.Core.Abstractions.Models; /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/AutoModeration/IAutoModerationTriggerMetadata.cs b/src/core/DSharpPlus.Core.Abstractions.Models/AutoModeration/IAutoModerationTriggerMetadata.cs index e1be63116f..a8de339380 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/AutoModeration/IAutoModerationTriggerMetadata.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/AutoModeration/IAutoModerationTriggerMetadata.cs @@ -6,8 +6,6 @@ using DSharpPlus.Entities; -using Remora.Rest.Core; - namespace DSharpPlus.Core.Abstractions.Models; /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/AutoModeration/IBlockMessageActionMetadata.cs b/src/core/DSharpPlus.Core.Abstractions.Models/AutoModeration/IBlockMessageActionMetadata.cs index 5ce77215a8..bc526df96e 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/AutoModeration/IBlockMessageActionMetadata.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/AutoModeration/IBlockMessageActionMetadata.cs @@ -4,8 +4,6 @@ using DSharpPlus.Entities; -using Remora.Rest.Core; - namespace DSharpPlus.Core.Abstractions.Models; /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/AutoModeration/IPartialAutoModerationRule.cs b/src/core/DSharpPlus.Core.Abstractions.Models/AutoModeration/IPartialAutoModerationRule.cs index e12c5a31d3..fa4b462292 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/AutoModeration/IPartialAutoModerationRule.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/AutoModeration/IPartialAutoModerationRule.cs @@ -6,8 +6,6 @@ using DSharpPlus.Entities; -using Remora.Rest.Core; - namespace DSharpPlus.Core.Abstractions.Models; /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/AutoModeration/ISendAlertMessageActionMetadata.cs b/src/core/DSharpPlus.Core.Abstractions.Models/AutoModeration/ISendAlertMessageActionMetadata.cs index d99774cb4e..7efca57889 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/AutoModeration/ISendAlertMessageActionMetadata.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/AutoModeration/ISendAlertMessageActionMetadata.cs @@ -4,8 +4,6 @@ using DSharpPlus.Entities; -using Remora.Rest.Core; - namespace DSharpPlus.Core.Abstractions.Models; /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IAllowedMentions.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IAllowedMentions.cs index bb41ed4f52..2bf464b7d3 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IAllowedMentions.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IAllowedMentions.cs @@ -4,8 +4,6 @@ using System.Collections.Generic; -using Remora.Rest.Core; - namespace DSharpPlus.Core.Abstractions.Models; /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IAttachment.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IAttachment.cs index b574f00960..5026f0e62f 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IAttachment.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IAttachment.cs @@ -2,8 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using Remora.Rest.Core; - namespace DSharpPlus.Core.Abstractions.Models; /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IChannel.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IChannel.cs index 82f3a7bde1..51cf209051 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IChannel.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IChannel.cs @@ -4,8 +4,6 @@ using DSharpPlus.Entities; -using Remora.Rest.Core; - namespace DSharpPlus.Core.Abstractions.Models; /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IChannelMention.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IChannelMention.cs index 80ffeef308..2207e9d5e4 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IChannelMention.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IChannelMention.cs @@ -4,8 +4,6 @@ using DSharpPlus.Entities; -using Remora.Rest.Core; - namespace DSharpPlus.Core.Abstractions.Models; /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IChannelOverwrite.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IChannelOverwrite.cs index fb5a665014..2703b0987b 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IChannelOverwrite.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IChannelOverwrite.cs @@ -4,8 +4,6 @@ using DSharpPlus.Entities; -using Remora.Rest.Core; - namespace DSharpPlus.Core.Abstractions.Models; /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IDefaultReaction.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IDefaultReaction.cs index 81633bf8c8..62c217e3cc 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IDefaultReaction.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IDefaultReaction.cs @@ -2,8 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using Remora.Rest.Core; - namespace DSharpPlus.Core.Abstractions.Models; /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IEmbed.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IEmbed.cs index ee8fdbf147..96c32ba9b9 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IEmbed.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IEmbed.cs @@ -5,8 +5,6 @@ using System; using System.Collections.Generic; -using Remora.Rest.Core; - namespace DSharpPlus.Core.Abstractions.Models; /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IEmbedAuthor.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IEmbedAuthor.cs index c36bc63462..a7278398d5 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IEmbedAuthor.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IEmbedAuthor.cs @@ -2,8 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using Remora.Rest.Core; - namespace DSharpPlus.Core.Abstractions.Models; /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IEmbedField.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IEmbedField.cs index 0175ce621c..9a7fea8d80 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IEmbedField.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IEmbedField.cs @@ -2,8 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using Remora.Rest.Core; - namespace DSharpPlus.Core.Abstractions.Models; /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IEmbedFooter.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IEmbedFooter.cs index fd1b2ec182..90ba783f49 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IEmbedFooter.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IEmbedFooter.cs @@ -2,8 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using Remora.Rest.Core; - namespace DSharpPlus.Core.Abstractions.Models; /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IEmbedImage.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IEmbedImage.cs index cdb25a0d9e..bb951e9071 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IEmbedImage.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IEmbedImage.cs @@ -2,8 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using Remora.Rest.Core; - namespace DSharpPlus.Core.Abstractions.Models; /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IEmbedProvider.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IEmbedProvider.cs index 697a84eb31..66f5299a6d 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IEmbedProvider.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IEmbedProvider.cs @@ -2,8 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using Remora.Rest.Core; - namespace DSharpPlus.Core.Abstractions.Models; /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IEmbedThumbnail.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IEmbedThumbnail.cs index f60a317cd6..7609adcbf7 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IEmbedThumbnail.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IEmbedThumbnail.cs @@ -2,8 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using Remora.Rest.Core; - namespace DSharpPlus.Core.Abstractions.Models; /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IEmbedVideo.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IEmbedVideo.cs index aab8091d58..a500dabe09 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IEmbedVideo.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IEmbedVideo.cs @@ -2,8 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using Remora.Rest.Core; - namespace DSharpPlus.Core.Abstractions.Models; /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IFollowedChannel.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IFollowedChannel.cs index 72af6008fb..ec5bc7c851 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IFollowedChannel.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IFollowedChannel.cs @@ -2,8 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using Remora.Rest.Core; - namespace DSharpPlus.Core.Abstractions.Models; /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IForumTag.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IForumTag.cs index 90ac428250..1743431b64 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IForumTag.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IForumTag.cs @@ -2,8 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using Remora.Rest.Core; - namespace DSharpPlus.Core.Abstractions.Models; /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IMessage.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IMessage.cs index 260694a79a..a9a0e7cf28 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IMessage.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IMessage.cs @@ -7,8 +7,6 @@ using DSharpPlus.Entities; -using Remora.Rest.Core; - namespace DSharpPlus.Core.Abstractions.Models; /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IMessageActivity.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IMessageActivity.cs index 0e0e4e0354..fc9cd9fb60 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IMessageActivity.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IMessageActivity.cs @@ -4,8 +4,6 @@ using DSharpPlus.Entities; -using Remora.Rest.Core; - namespace DSharpPlus.Core.Abstractions.Models; /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IMessageReference.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IMessageReference.cs index ecc43dfa3c..adf3d504d8 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IMessageReference.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IMessageReference.cs @@ -2,8 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using Remora.Rest.Core; - namespace DSharpPlus.Core.Abstractions.Models; /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IPartialAttachment.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IPartialAttachment.cs index 29823751da..f19f477774 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IPartialAttachment.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IPartialAttachment.cs @@ -6,8 +6,6 @@ using DSharpPlus.Entities; -using Remora.Rest.Core; - namespace DSharpPlus.Core.Abstractions.Models; /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IPartialChannel.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IPartialChannel.cs index e6a9494678..0ec8dea83e 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IPartialChannel.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IPartialChannel.cs @@ -7,8 +7,6 @@ using DSharpPlus.Entities; -using Remora.Rest.Core; - namespace DSharpPlus.Core.Abstractions.Models; /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IPartialChannelOverwrite.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IPartialChannelOverwrite.cs index aa010bedab..88243d4957 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IPartialChannelOverwrite.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IPartialChannelOverwrite.cs @@ -4,8 +4,6 @@ using DSharpPlus.Entities; -using Remora.Rest.Core; - namespace DSharpPlus.Core.Abstractions.Models; /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IPartialMessage.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IPartialMessage.cs index 1bd6fd6c1c..b8cbc6b1e4 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IPartialMessage.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IPartialMessage.cs @@ -7,8 +7,6 @@ using DSharpPlus.Entities; -using Remora.Rest.Core; - namespace DSharpPlus.Core.Abstractions.Models; /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IRoleSubscriptionData.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IRoleSubscriptionData.cs index 73d7f112b4..bfebd41054 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IRoleSubscriptionData.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IRoleSubscriptionData.cs @@ -2,8 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using Remora.Rest.Core; - namespace DSharpPlus.Core.Abstractions.Models; /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IThreadMember.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IThreadMember.cs index 5a2bf5df80..9447f7c274 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IThreadMember.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IThreadMember.cs @@ -4,8 +4,6 @@ using System; -using Remora.Rest.Core; - namespace DSharpPlus.Core.Abstractions.Models; /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IThreadMetadata.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IThreadMetadata.cs index 17e6f81a6b..8e59990892 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IThreadMetadata.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IThreadMetadata.cs @@ -4,8 +4,6 @@ using System; -using Remora.Rest.Core; - namespace DSharpPlus.Core.Abstractions.Models; /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/DSharpPlus.Core.Abstractions.Models.csproj b/src/core/DSharpPlus.Core.Abstractions.Models/DSharpPlus.Core.Abstractions.Models.csproj index 17f901fa6b..f935e9d971 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/DSharpPlus.Core.Abstractions.Models.csproj +++ b/src/core/DSharpPlus.Core.Abstractions.Models/DSharpPlus.Core.Abstractions.Models.csproj @@ -10,7 +10,6 @@ - diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Emojis/IEmoji.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Emojis/IEmoji.cs index 3c57432300..ab519ef77a 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Emojis/IEmoji.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Emojis/IEmoji.cs @@ -2,8 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using Remora.Rest.Core; - namespace DSharpPlus.Core.Abstractions.Models; /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Emojis/IPartialEmoji.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Emojis/IPartialEmoji.cs index d762b9ee0f..19fce4b920 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Emojis/IPartialEmoji.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Emojis/IPartialEmoji.cs @@ -4,8 +4,6 @@ using System.Collections.Generic; -using Remora.Rest.Core; - namespace DSharpPlus.Core.Abstractions.Models; /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Entitlements/IEntitlement.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Entitlements/IEntitlement.cs index 71d07eeaed..5e2fee5247 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Entitlements/IEntitlement.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Entitlements/IEntitlement.cs @@ -6,8 +6,6 @@ using DSharpPlus.Entities; -using Remora.Rest.Core; - namespace DSharpPlus.Core.Abstractions.Models; /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/GuildTemplates/ITemplate.cs b/src/core/DSharpPlus.Core.Abstractions.Models/GuildTemplates/ITemplate.cs index f91b91c6e0..5b8807cab7 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/GuildTemplates/ITemplate.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/GuildTemplates/ITemplate.cs @@ -4,8 +4,6 @@ using System; -using Remora.Rest.Core; - namespace DSharpPlus.Core.Abstractions.Models; /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IGuild.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IGuild.cs index 58b8928ac6..02714a0ee5 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IGuild.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IGuild.cs @@ -6,8 +6,6 @@ using DSharpPlus.Entities; -using Remora.Rest.Core; - namespace DSharpPlus.Core.Abstractions.Models; /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IGuildMember.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IGuildMember.cs index 8450d25596..8915d84b4f 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IGuildMember.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IGuildMember.cs @@ -7,8 +7,6 @@ using DSharpPlus.Entities; -using Remora.Rest.Core; - namespace DSharpPlus.Core.Abstractions.Models; /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IGuildPreview.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IGuildPreview.cs index c50fb8234f..668d93039c 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IGuildPreview.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IGuildPreview.cs @@ -4,8 +4,6 @@ using System.Collections.Generic; -using Remora.Rest.Core; - namespace DSharpPlus.Core.Abstractions.Models; /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IGuildWidget.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IGuildWidget.cs index 28b0257c19..29378e58ff 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IGuildWidget.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IGuildWidget.cs @@ -4,8 +4,6 @@ using System.Collections.Generic; -using Remora.Rest.Core; - namespace DSharpPlus.Core.Abstractions.Models; /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IGuildWidgetSettings.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IGuildWidgetSettings.cs index 4c8eb04da3..50e72e34e7 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IGuildWidgetSettings.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IGuildWidgetSettings.cs @@ -2,8 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using Remora.Rest.Core; - namespace DSharpPlus.Core.Abstractions.Models; /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IIntegration.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IIntegration.cs index d117bead83..bbd881f12a 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IIntegration.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IIntegration.cs @@ -2,8 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using Remora.Rest.Core; - namespace DSharpPlus.Core.Abstractions.Models; /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IIntegrationApplication.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IIntegrationApplication.cs index a6e4d08b3c..a4e4007efb 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IIntegrationApplication.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IIntegrationApplication.cs @@ -2,8 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using Remora.Rest.Core; - namespace DSharpPlus.Core.Abstractions.Models; /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IOnboarding.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IOnboarding.cs index 782b1ca47c..070674fe38 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IOnboarding.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IOnboarding.cs @@ -6,8 +6,6 @@ using DSharpPlus.Entities; -using Remora.Rest.Core; - namespace DSharpPlus.Core.Abstractions.Models; /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IOnboardingPrompt.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IOnboardingPrompt.cs index 9976f6cf90..7f5a3bd6a5 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IOnboardingPrompt.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IOnboardingPrompt.cs @@ -6,8 +6,6 @@ using DSharpPlus.Entities; -using Remora.Rest.Core; - namespace DSharpPlus.Core.Abstractions.Models; /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IOnboardingPromptOption.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IOnboardingPromptOption.cs index 312750eae3..122f530d7e 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IOnboardingPromptOption.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IOnboardingPromptOption.cs @@ -4,8 +4,6 @@ using System.Collections.Generic; -using Remora.Rest.Core; - namespace DSharpPlus.Core.Abstractions.Models; /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IPartialGuild.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IPartialGuild.cs index 35358448bc..3322890e68 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IPartialGuild.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IPartialGuild.cs @@ -6,8 +6,6 @@ using DSharpPlus.Entities; -using Remora.Rest.Core; - namespace DSharpPlus.Core.Abstractions.Models; /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IPartialGuildMember.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IPartialGuildMember.cs index bb822862e5..6320436922 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IPartialGuildMember.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IPartialGuildMember.cs @@ -7,8 +7,6 @@ using DSharpPlus.Entities; -using Remora.Rest.Core; - namespace DSharpPlus.Core.Abstractions.Models; /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IPartialIntegration.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IPartialIntegration.cs index acd3a0ca8d..a106a83ebf 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IPartialIntegration.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IPartialIntegration.cs @@ -7,8 +7,6 @@ using DSharpPlus.Entities; -using Remora.Rest.Core; - namespace DSharpPlus.Core.Abstractions.Models; /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IPartialRole.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IPartialRole.cs index 76fc372028..939fc6412c 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IPartialRole.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IPartialRole.cs @@ -4,8 +4,6 @@ using DSharpPlus.Entities; -using Remora.Rest.Core; - namespace DSharpPlus.Core.Abstractions.Models; /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IRole.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IRole.cs index 0489f97f57..bca8e1c0c0 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IRole.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IRole.cs @@ -4,8 +4,6 @@ using DSharpPlus.Entities; -using Remora.Rest.Core; - namespace DSharpPlus.Core.Abstractions.Models; /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IRoleTags.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IRoleTags.cs index e7ce227bc7..cef076d536 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IRoleTags.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IRoleTags.cs @@ -2,8 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using Remora.Rest.Core; - namespace DSharpPlus.Core.Abstractions.Models; /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IWelcomeScreenChannel.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IWelcomeScreenChannel.cs index 59a215e89d..ceef81f1b4 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IWelcomeScreenChannel.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IWelcomeScreenChannel.cs @@ -2,8 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using Remora.Rest.Core; - namespace DSharpPlus.Core.Abstractions.Models; /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IApplicationCommandInteractionData.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IApplicationCommandInteractionData.cs index 5f5cb60abb..11556452ad 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IApplicationCommandInteractionData.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IApplicationCommandInteractionData.cs @@ -6,8 +6,6 @@ using DSharpPlus.Entities; -using Remora.Rest.Core; - namespace DSharpPlus.Core.Abstractions.Models; /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IApplicationCommandInteractionDataOption.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IApplicationCommandInteractionDataOption.cs index 98a927682a..e167bcf281 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IApplicationCommandInteractionDataOption.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IApplicationCommandInteractionDataOption.cs @@ -8,8 +8,6 @@ using OneOf; -using Remora.Rest.Core; - namespace DSharpPlus.Core.Abstractions.Models; /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IInteraction.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IInteraction.cs index 75af03d7be..cdc5288dc8 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IInteraction.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IInteraction.cs @@ -8,8 +8,6 @@ using OneOf; -using Remora.Rest.Core; - namespace DSharpPlus.Core.Abstractions.Models; /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IInteractionResponse.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IInteractionResponse.cs index 45ca5942dc..c97ecd2284 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IInteractionResponse.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IInteractionResponse.cs @@ -6,8 +6,6 @@ using OneOf; -using Remora.Rest.Core; - namespace DSharpPlus.Core.Abstractions.Models; /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IMessageCallbackData.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IMessageCallbackData.cs index 82eb2ca64c..886211d82f 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IMessageCallbackData.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IMessageCallbackData.cs @@ -6,8 +6,6 @@ using DSharpPlus.Entities; -using Remora.Rest.Core; - namespace DSharpPlus.Core.Abstractions.Models; /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IMessageComponentInteractionData.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IMessageComponentInteractionData.cs index f4961cfb6a..1abb05a69d 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IMessageComponentInteractionData.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IMessageComponentInteractionData.cs @@ -6,8 +6,6 @@ using DSharpPlus.Entities; -using Remora.Rest.Core; - namespace DSharpPlus.Core.Abstractions.Models; /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IMessageInteraction.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IMessageInteraction.cs index aae3a77086..3eeaab7b5f 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IMessageInteraction.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IMessageInteraction.cs @@ -4,8 +4,6 @@ using DSharpPlus.Entities; -using Remora.Rest.Core; - namespace DSharpPlus.Core.Abstractions.Models; /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IResolvedData.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IResolvedData.cs index 25ae24b6aa..20d464f9f6 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IResolvedData.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IResolvedData.cs @@ -4,8 +4,6 @@ using System.Collections.Generic; -using Remora.Rest.Core; - namespace DSharpPlus.Core.Abstractions.Models; /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Invites/IInvite.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Invites/IInvite.cs index 0469df4ff1..9f6f40ed1d 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Invites/IInvite.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Invites/IInvite.cs @@ -2,8 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using Remora.Rest.Core; - namespace DSharpPlus.Core.Abstractions.Models; /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Invites/IPartialInvite.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Invites/IPartialInvite.cs index 7f1afd3b6e..5734e7d0b2 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Invites/IPartialInvite.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Invites/IPartialInvite.cs @@ -6,8 +6,6 @@ using DSharpPlus.Entities; -using Remora.Rest.Core; - namespace DSharpPlus.Core.Abstractions.Models; /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IButtonComponent.cs b/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IButtonComponent.cs index e0696b21cf..424d26c0bb 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IButtonComponent.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IButtonComponent.cs @@ -4,8 +4,6 @@ using DSharpPlus.Entities; -using Remora.Rest.Core; - namespace DSharpPlus.Core.Abstractions.Models; /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IChannelSelectComponent.cs b/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IChannelSelectComponent.cs index 01fdd56346..b8ab6bddb7 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IChannelSelectComponent.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IChannelSelectComponent.cs @@ -6,8 +6,6 @@ using DSharpPlus.Entities; -using Remora.Rest.Core; - namespace DSharpPlus.Core.Abstractions.Models; /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IDefaultSelectValue.cs b/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IDefaultSelectValue.cs index 3701219f25..a80494a828 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IDefaultSelectValue.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IDefaultSelectValue.cs @@ -2,8 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using Remora.Rest.Core; - namespace DSharpPlus.Core.Abstractions.Models; /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IMentionableSelectComponent.cs b/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IMentionableSelectComponent.cs index db75c456bb..8a8ed5a7d6 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IMentionableSelectComponent.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IMentionableSelectComponent.cs @@ -6,8 +6,6 @@ using DSharpPlus.Entities; -using Remora.Rest.Core; - namespace DSharpPlus.Core.Abstractions.Models; /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IRoleSelectComponent.cs b/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IRoleSelectComponent.cs index 792ece4dd0..fe5cd93136 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IRoleSelectComponent.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IRoleSelectComponent.cs @@ -6,8 +6,6 @@ using DSharpPlus.Entities; -using Remora.Rest.Core; - namespace DSharpPlus.Core.Abstractions.Models; /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/ISelectOption.cs b/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/ISelectOption.cs index 3c8c0d162e..a5c012882e 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/ISelectOption.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/ISelectOption.cs @@ -2,8 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using Remora.Rest.Core; - namespace DSharpPlus.Core.Abstractions.Models; /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IStringSelectComponent.cs b/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IStringSelectComponent.cs index 48a3886877..e32668932f 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IStringSelectComponent.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IStringSelectComponent.cs @@ -6,8 +6,6 @@ using DSharpPlus.Entities; -using Remora.Rest.Core; - namespace DSharpPlus.Core.Abstractions.Models; /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/ITextInputComponent.cs b/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/ITextInputComponent.cs index 9591d41383..d8b6af80f9 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/ITextInputComponent.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/ITextInputComponent.cs @@ -4,8 +4,6 @@ using DSharpPlus.Entities; -using Remora.Rest.Core; - namespace DSharpPlus.Core.Abstractions.Models; /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IUserSelectComponent.cs b/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IUserSelectComponent.cs index f9099d8e4c..b25befde2d 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IUserSelectComponent.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IUserSelectComponent.cs @@ -6,8 +6,6 @@ using DSharpPlus.Entities; -using Remora.Rest.Core; - namespace DSharpPlus.Core.Abstractions.Models; /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/RoleConnections/IRoleConnectionMetadata.cs b/src/core/DSharpPlus.Core.Abstractions.Models/RoleConnections/IRoleConnectionMetadata.cs index 00cbc6d1b4..80d64e7281 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/RoleConnections/IRoleConnectionMetadata.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/RoleConnections/IRoleConnectionMetadata.cs @@ -6,8 +6,6 @@ using DSharpPlus.Entities; -using Remora.Rest.Core; - namespace DSharpPlus.Core.Abstractions.Models; /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/ScheduledEvents/IPartialScheduledEvent.cs b/src/core/DSharpPlus.Core.Abstractions.Models/ScheduledEvents/IPartialScheduledEvent.cs index f1b4952ab5..688df24f50 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/ScheduledEvents/IPartialScheduledEvent.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/ScheduledEvents/IPartialScheduledEvent.cs @@ -2,11 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Entities; - -using Remora.Rest.Core; using System; +using DSharpPlus.Entities; + namespace DSharpPlus.Core.Abstractions.Models; /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/ScheduledEvents/IScheduledEvent.cs b/src/core/DSharpPlus.Core.Abstractions.Models/ScheduledEvents/IScheduledEvent.cs index 380b601c7f..488de7b7fd 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/ScheduledEvents/IScheduledEvent.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/ScheduledEvents/IScheduledEvent.cs @@ -6,8 +6,6 @@ using DSharpPlus.Entities; -using Remora.Rest.Core; - namespace DSharpPlus.Core.Abstractions.Models; /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/ScheduledEvents/IScheduledEventUser.cs b/src/core/DSharpPlus.Core.Abstractions.Models/ScheduledEvents/IScheduledEventUser.cs index 20e4d86c2f..ad98140da6 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/ScheduledEvents/IScheduledEventUser.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/ScheduledEvents/IScheduledEventUser.cs @@ -2,8 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using Remora.Rest.Core; - namespace DSharpPlus.Core.Abstractions.Models; /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Skus/ISku.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Skus/ISku.cs index d4b2fed6a8..5a67176ac6 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Skus/ISku.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Skus/ISku.cs @@ -4,8 +4,6 @@ using DSharpPlus.Entities; -using Remora.Rest.Core; - namespace DSharpPlus.Core.Abstractions.Models; /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/StageInstances/IPartialStageInstance.cs b/src/core/DSharpPlus.Core.Abstractions.Models/StageInstances/IPartialStageInstance.cs index d0e88138da..704db97a9c 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/StageInstances/IPartialStageInstance.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/StageInstances/IPartialStageInstance.cs @@ -4,8 +4,6 @@ using DSharpPlus.Entities; -using Remora.Rest.Core; - namespace DSharpPlus.Core.Abstractions.Models; /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/StageInstances/IStageInstance.cs b/src/core/DSharpPlus.Core.Abstractions.Models/StageInstances/IStageInstance.cs index 8837b52c80..8bd3d53670 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/StageInstances/IStageInstance.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/StageInstances/IStageInstance.cs @@ -3,7 +3,6 @@ // file, You can obtain one at https://mozilla.org/MPL/2.0/. using DSharpPlus.Entities; -using Remora.Rest.Core; namespace DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Stickers/IPartialSticker.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Stickers/IPartialSticker.cs index 9c41e4f7b1..9da7d5455f 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Stickers/IPartialSticker.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Stickers/IPartialSticker.cs @@ -4,8 +4,6 @@ using DSharpPlus.Entities; -using Remora.Rest.Core; - namespace DSharpPlus.Core.Abstractions.Models; /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Stickers/ISticker.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Stickers/ISticker.cs index 6e55532956..bc7ec2854b 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Stickers/ISticker.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Stickers/ISticker.cs @@ -4,8 +4,6 @@ using DSharpPlus.Entities; -using Remora.Rest.Core; - namespace DSharpPlus.Core.Abstractions.Models; /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Stickers/IStickerItem.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Stickers/IStickerItem.cs index 10edcbb79c..7271a73985 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Stickers/IStickerItem.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Stickers/IStickerItem.cs @@ -4,8 +4,6 @@ using DSharpPlus.Entities; -using Remora.Rest.Core; - namespace DSharpPlus.Core.Abstractions.Models; /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Stickers/IStickerPack.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Stickers/IStickerPack.cs index 3cbf9eb904..a67dfcf8c6 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Stickers/IStickerPack.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Stickers/IStickerPack.cs @@ -4,8 +4,6 @@ using System.Collections.Generic; -using Remora.Rest.Core; - namespace DSharpPlus.Core.Abstractions.Models; /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Teams/ITeam.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Teams/ITeam.cs index d59e95481c..d7c74ad003 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Teams/ITeam.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Teams/ITeam.cs @@ -4,8 +4,6 @@ using System.Collections.Generic; -using Remora.Rest.Core; - namespace DSharpPlus.Core.Abstractions.Models; /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Teams/ITeamMember.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Teams/ITeamMember.cs index b19c9e166f..38d73f70bb 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Teams/ITeamMember.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Teams/ITeamMember.cs @@ -6,8 +6,6 @@ using DSharpPlus.Entities; -using Remora.Rest.Core; - namespace DSharpPlus.Core.Abstractions.Models; /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Users/IConnection.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Users/IConnection.cs index e3b9b17508..31294843f3 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Users/IConnection.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Users/IConnection.cs @@ -6,8 +6,6 @@ using DSharpPlus.Entities; -using Remora.Rest.Core; - namespace DSharpPlus.Core.Abstractions.Models; /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Users/IPartialUser.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Users/IPartialUser.cs index 93ec675960..90aa4546d5 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Users/IPartialUser.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Users/IPartialUser.cs @@ -3,7 +3,6 @@ // file, You can obtain one at https://mozilla.org/MPL/2.0/. using DSharpPlus.Entities; -using Remora.Rest.Core; namespace DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Users/IUser.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Users/IUser.cs index ef353c6cb3..152feaf675 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Users/IUser.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Users/IUser.cs @@ -2,8 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using Remora.Rest.Core; - namespace DSharpPlus.Core.Abstractions.Models; /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Voice/IVoiceState.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Voice/IVoiceState.cs index 4cad827b14..5a217ef62a 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Voice/IVoiceState.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Voice/IVoiceState.cs @@ -4,8 +4,6 @@ using System; -using Remora.Rest.Core; - namespace DSharpPlus.Core.Abstractions.Models; /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Webhooks/IPartialWebhook.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Webhooks/IPartialWebhook.cs index cc8de859d5..bdfc2f81c1 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Webhooks/IPartialWebhook.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Webhooks/IPartialWebhook.cs @@ -4,8 +4,6 @@ using DSharpPlus.Entities; -using Remora.Rest.Core; - namespace DSharpPlus.Core.Abstractions.Models; /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Webhooks/IWebhook.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Webhooks/IWebhook.cs index e447808508..01c89c84c0 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Webhooks/IWebhook.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Webhooks/IWebhook.cs @@ -4,8 +4,6 @@ using DSharpPlus.Entities; -using Remora.Rest.Core; - namespace DSharpPlus.Core.Abstractions.Models; /// diff --git a/src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommand.cs b/src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommand.cs index 029bef2ffa..aacb40865d 100644 --- a/src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommand.cs +++ b/src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommand.cs @@ -6,8 +6,6 @@ using DSharpPlus.Entities; -using Remora.Rest.Core; - using DSharpPlus.Core.Abstractions.Models; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommandOption.cs b/src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommandOption.cs index 37bdf31919..8ba3389baf 100644 --- a/src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommandOption.cs +++ b/src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommandOption.cs @@ -8,8 +8,6 @@ using OneOf; -using Remora.Rest.Core; - using DSharpPlus.Core.Abstractions.Models; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommandOptionChoice.cs b/src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommandOptionChoice.cs index 3e4949a191..86f1c22ecd 100644 --- a/src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommandOptionChoice.cs +++ b/src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommandOptionChoice.cs @@ -6,8 +6,6 @@ using OneOf; -using Remora.Rest.Core; - using DSharpPlus.Core.Abstractions.Models; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommandPermission.cs b/src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommandPermission.cs index 202320f918..1b844e6170 100644 --- a/src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommandPermission.cs +++ b/src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommandPermission.cs @@ -4,8 +4,6 @@ using DSharpPlus.Entities; -using Remora.Rest.Core; - using DSharpPlus.Core.Abstractions.Models; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommandPermissions.cs b/src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommandPermissions.cs index 741e912e59..e129549546 100644 --- a/src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommandPermissions.cs +++ b/src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommandPermissions.cs @@ -4,8 +4,6 @@ using System.Collections.Generic; -using Remora.Rest.Core; - using DSharpPlus.Core.Abstractions.Models; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/ApplicationCommands/PartialApplicationCommandPermissions.cs b/src/core/DSharpPlus.Core.Models/ApplicationCommands/PartialApplicationCommandPermissions.cs index b31912ad32..85bc56ed75 100644 --- a/src/core/DSharpPlus.Core.Models/ApplicationCommands/PartialApplicationCommandPermissions.cs +++ b/src/core/DSharpPlus.Core.Models/ApplicationCommands/PartialApplicationCommandPermissions.cs @@ -4,8 +4,6 @@ using System.Collections.Generic; -using Remora.Rest.Core; - using DSharpPlus.Core.Abstractions.Models; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/Applications/Application.cs b/src/core/DSharpPlus.Core.Models/Applications/Application.cs index acc30dee0a..a5c283224f 100644 --- a/src/core/DSharpPlus.Core.Models/Applications/Application.cs +++ b/src/core/DSharpPlus.Core.Models/Applications/Application.cs @@ -6,8 +6,6 @@ using DSharpPlus.Entities; -using Remora.Rest.Core; - using DSharpPlus.Core.Abstractions.Models; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/Applications/PartialApplication.cs b/src/core/DSharpPlus.Core.Models/Applications/PartialApplication.cs index fd7a0a3fac..674192e2a7 100644 --- a/src/core/DSharpPlus.Core.Models/Applications/PartialApplication.cs +++ b/src/core/DSharpPlus.Core.Models/Applications/PartialApplication.cs @@ -6,8 +6,6 @@ using DSharpPlus.Entities; -using Remora.Rest.Core; - using DSharpPlus.Core.Abstractions.Models; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/AuditLogs/AuditLogChange.cs b/src/core/DSharpPlus.Core.Models/AuditLogs/AuditLogChange.cs index 0f804c4cd9..faf2d78677 100644 --- a/src/core/DSharpPlus.Core.Models/AuditLogs/AuditLogChange.cs +++ b/src/core/DSharpPlus.Core.Models/AuditLogs/AuditLogChange.cs @@ -1,8 +1,3 @@ -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -using Remora.Rest.Core; using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/AuditLogs/AuditLogEntry.cs b/src/core/DSharpPlus.Core.Models/AuditLogs/AuditLogEntry.cs index 15b68aec2e..02af553683 100644 --- a/src/core/DSharpPlus.Core.Models/AuditLogs/AuditLogEntry.cs +++ b/src/core/DSharpPlus.Core.Models/AuditLogs/AuditLogEntry.cs @@ -8,8 +8,6 @@ using OneOf; -using Remora.Rest.Core; - using DSharpPlus.Core.Abstractions.Models; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/AuditLogs/AuditLogEntryInfo.cs b/src/core/DSharpPlus.Core.Models/AuditLogs/AuditLogEntryInfo.cs index 6bada1ff4a..2dfe46b53a 100644 --- a/src/core/DSharpPlus.Core.Models/AuditLogs/AuditLogEntryInfo.cs +++ b/src/core/DSharpPlus.Core.Models/AuditLogs/AuditLogEntryInfo.cs @@ -1,8 +1,3 @@ -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -using Remora.Rest.Core; using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/AutoModeration/AutoModerationAction.cs b/src/core/DSharpPlus.Core.Models/AutoModeration/AutoModerationAction.cs index 28f154bbee..2e9a0e1933 100644 --- a/src/core/DSharpPlus.Core.Models/AutoModeration/AutoModerationAction.cs +++ b/src/core/DSharpPlus.Core.Models/AutoModeration/AutoModerationAction.cs @@ -4,8 +4,6 @@ using DSharpPlus.Entities; -using Remora.Rest.Core; - using DSharpPlus.Core.Abstractions.Models; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/AutoModeration/AutoModerationRule.cs b/src/core/DSharpPlus.Core.Models/AutoModeration/AutoModerationRule.cs index 0753b48ae8..b68d2b9610 100644 --- a/src/core/DSharpPlus.Core.Models/AutoModeration/AutoModerationRule.cs +++ b/src/core/DSharpPlus.Core.Models/AutoModeration/AutoModerationRule.cs @@ -6,8 +6,6 @@ using DSharpPlus.Entities; -using Remora.Rest.Core; - using DSharpPlus.Core.Abstractions.Models; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/AutoModeration/AutoModerationTriggerMetadata.cs b/src/core/DSharpPlus.Core.Models/AutoModeration/AutoModerationTriggerMetadata.cs index 42091ead2d..8034bfd363 100644 --- a/src/core/DSharpPlus.Core.Models/AutoModeration/AutoModerationTriggerMetadata.cs +++ b/src/core/DSharpPlus.Core.Models/AutoModeration/AutoModerationTriggerMetadata.cs @@ -6,8 +6,6 @@ using DSharpPlus.Entities; -using Remora.Rest.Core; - using DSharpPlus.Core.Abstractions.Models; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/AutoModeration/BlockMessageActionMetadata.cs b/src/core/DSharpPlus.Core.Models/AutoModeration/BlockMessageActionMetadata.cs index 233718f266..eb29e0c7d1 100644 --- a/src/core/DSharpPlus.Core.Models/AutoModeration/BlockMessageActionMetadata.cs +++ b/src/core/DSharpPlus.Core.Models/AutoModeration/BlockMessageActionMetadata.cs @@ -4,8 +4,6 @@ using DSharpPlus.Entities; -using Remora.Rest.Core; - using DSharpPlus.Core.Abstractions.Models; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/AutoModeration/PartialAutoModerationRule.cs b/src/core/DSharpPlus.Core.Models/AutoModeration/PartialAutoModerationRule.cs index ab5fec2dc6..c141364dd4 100644 --- a/src/core/DSharpPlus.Core.Models/AutoModeration/PartialAutoModerationRule.cs +++ b/src/core/DSharpPlus.Core.Models/AutoModeration/PartialAutoModerationRule.cs @@ -6,8 +6,6 @@ using DSharpPlus.Entities; -using Remora.Rest.Core; - using DSharpPlus.Core.Abstractions.Models; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/AutoModeration/SendAlertMessageActionMetadata.cs b/src/core/DSharpPlus.Core.Models/AutoModeration/SendAlertMessageActionMetadata.cs index dc64b4655b..3f2bdec659 100644 --- a/src/core/DSharpPlus.Core.Models/AutoModeration/SendAlertMessageActionMetadata.cs +++ b/src/core/DSharpPlus.Core.Models/AutoModeration/SendAlertMessageActionMetadata.cs @@ -4,8 +4,6 @@ using DSharpPlus.Entities; -using Remora.Rest.Core; - using DSharpPlus.Core.Abstractions.Models; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/Channels/AllowedMentions.cs b/src/core/DSharpPlus.Core.Models/Channels/AllowedMentions.cs index 2a4426f0ac..b8090522b9 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/AllowedMentions.cs +++ b/src/core/DSharpPlus.Core.Models/Channels/AllowedMentions.cs @@ -4,8 +4,6 @@ using System.Collections.Generic; -using Remora.Rest.Core; - using DSharpPlus.Core.Abstractions.Models; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/Channels/Attachment.cs b/src/core/DSharpPlus.Core.Models/Channels/Attachment.cs index 54e651754b..4dc1cfc94a 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/Attachment.cs +++ b/src/core/DSharpPlus.Core.Models/Channels/Attachment.cs @@ -6,8 +6,6 @@ using DSharpPlus.Entities; -using Remora.Rest.Core; - using DSharpPlus.Core.Abstractions.Models; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/Channels/Channel.cs b/src/core/DSharpPlus.Core.Models/Channels/Channel.cs index 91dcf5d571..80678f123e 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/Channel.cs +++ b/src/core/DSharpPlus.Core.Models/Channels/Channel.cs @@ -7,8 +7,6 @@ using DSharpPlus.Entities; -using Remora.Rest.Core; - using DSharpPlus.Core.Abstractions.Models; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/Channels/ChannelMention.cs b/src/core/DSharpPlus.Core.Models/Channels/ChannelMention.cs index f76cb15ca6..394996ce0d 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/ChannelMention.cs +++ b/src/core/DSharpPlus.Core.Models/Channels/ChannelMention.cs @@ -4,8 +4,6 @@ using DSharpPlus.Entities; -using Remora.Rest.Core; - using DSharpPlus.Core.Abstractions.Models; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/Channels/ChannelOverwrite.cs b/src/core/DSharpPlus.Core.Models/Channels/ChannelOverwrite.cs index 6db39029c0..fae3f1c197 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/ChannelOverwrite.cs +++ b/src/core/DSharpPlus.Core.Models/Channels/ChannelOverwrite.cs @@ -4,8 +4,6 @@ using DSharpPlus.Entities; -using Remora.Rest.Core; - using DSharpPlus.Core.Abstractions.Models; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/Channels/DefaultReaction.cs b/src/core/DSharpPlus.Core.Models/Channels/DefaultReaction.cs index 9bb3f40cc7..2525f70146 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/DefaultReaction.cs +++ b/src/core/DSharpPlus.Core.Models/Channels/DefaultReaction.cs @@ -1,8 +1,3 @@ -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -using Remora.Rest.Core; using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/Channels/Embed.cs b/src/core/DSharpPlus.Core.Models/Channels/Embed.cs index 08adc47ee0..3f5f794cce 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/Embed.cs +++ b/src/core/DSharpPlus.Core.Models/Channels/Embed.cs @@ -5,8 +5,6 @@ using System; using System.Collections.Generic; -using Remora.Rest.Core; - using DSharpPlus.Core.Abstractions.Models; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/Channels/EmbedAuthor.cs b/src/core/DSharpPlus.Core.Models/Channels/EmbedAuthor.cs index 6877059b30..fb4a03d9e3 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/EmbedAuthor.cs +++ b/src/core/DSharpPlus.Core.Models/Channels/EmbedAuthor.cs @@ -1,8 +1,3 @@ -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -using Remora.Rest.Core; using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/Channels/EmbedField.cs b/src/core/DSharpPlus.Core.Models/Channels/EmbedField.cs index a9765807b2..b99f333194 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/EmbedField.cs +++ b/src/core/DSharpPlus.Core.Models/Channels/EmbedField.cs @@ -1,8 +1,3 @@ -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -using Remora.Rest.Core; using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/Channels/EmbedFooter.cs b/src/core/DSharpPlus.Core.Models/Channels/EmbedFooter.cs index d526de5394..d34bac5a08 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/EmbedFooter.cs +++ b/src/core/DSharpPlus.Core.Models/Channels/EmbedFooter.cs @@ -1,8 +1,3 @@ -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -using Remora.Rest.Core; using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/Channels/EmbedImage.cs b/src/core/DSharpPlus.Core.Models/Channels/EmbedImage.cs index 83f118fa60..a0bcf97942 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/EmbedImage.cs +++ b/src/core/DSharpPlus.Core.Models/Channels/EmbedImage.cs @@ -1,8 +1,3 @@ -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -using Remora.Rest.Core; using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/Channels/EmbedProvider.cs b/src/core/DSharpPlus.Core.Models/Channels/EmbedProvider.cs index 9596ffb0a9..4499309728 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/EmbedProvider.cs +++ b/src/core/DSharpPlus.Core.Models/Channels/EmbedProvider.cs @@ -1,8 +1,3 @@ -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -using Remora.Rest.Core; using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/Channels/EmbedThumbnail.cs b/src/core/DSharpPlus.Core.Models/Channels/EmbedThumbnail.cs index ebe009eeb1..04c52e0727 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/EmbedThumbnail.cs +++ b/src/core/DSharpPlus.Core.Models/Channels/EmbedThumbnail.cs @@ -1,8 +1,3 @@ -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -using Remora.Rest.Core; using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/Channels/EmbedVideo.cs b/src/core/DSharpPlus.Core.Models/Channels/EmbedVideo.cs index b614ca542b..8d34b1c776 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/EmbedVideo.cs +++ b/src/core/DSharpPlus.Core.Models/Channels/EmbedVideo.cs @@ -1,8 +1,3 @@ -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -using Remora.Rest.Core; using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/Channels/FollowedChannel.cs b/src/core/DSharpPlus.Core.Models/Channels/FollowedChannel.cs index 998f0a717c..9c768a5515 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/FollowedChannel.cs +++ b/src/core/DSharpPlus.Core.Models/Channels/FollowedChannel.cs @@ -1,8 +1,3 @@ -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -using Remora.Rest.Core; using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/Channels/ForumTag.cs b/src/core/DSharpPlus.Core.Models/Channels/ForumTag.cs index c43364b8a3..f90be4ee41 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/ForumTag.cs +++ b/src/core/DSharpPlus.Core.Models/Channels/ForumTag.cs @@ -1,8 +1,3 @@ -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -using Remora.Rest.Core; using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/Channels/Message.cs b/src/core/DSharpPlus.Core.Models/Channels/Message.cs index 85af238df4..a2aeeadcd5 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/Message.cs +++ b/src/core/DSharpPlus.Core.Models/Channels/Message.cs @@ -7,8 +7,6 @@ using DSharpPlus.Entities; -using Remora.Rest.Core; - using DSharpPlus.Core.Abstractions.Models; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/Channels/MessageActivity.cs b/src/core/DSharpPlus.Core.Models/Channels/MessageActivity.cs index f3ca1b0608..6ee02824bf 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/MessageActivity.cs +++ b/src/core/DSharpPlus.Core.Models/Channels/MessageActivity.cs @@ -4,8 +4,6 @@ using DSharpPlus.Entities; -using Remora.Rest.Core; - using DSharpPlus.Core.Abstractions.Models; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/Channels/MessageReference.cs b/src/core/DSharpPlus.Core.Models/Channels/MessageReference.cs index 0dd81b06c7..eeceb73537 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/MessageReference.cs +++ b/src/core/DSharpPlus.Core.Models/Channels/MessageReference.cs @@ -1,8 +1,3 @@ -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -using Remora.Rest.Core; using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/Channels/PartialAttachment.cs b/src/core/DSharpPlus.Core.Models/Channels/PartialAttachment.cs index d9ffcb00eb..cf15028f8c 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/PartialAttachment.cs +++ b/src/core/DSharpPlus.Core.Models/Channels/PartialAttachment.cs @@ -6,8 +6,6 @@ using DSharpPlus.Entities; -using Remora.Rest.Core; - using DSharpPlus.Core.Abstractions.Models; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/Channels/PartialChannel.cs b/src/core/DSharpPlus.Core.Models/Channels/PartialChannel.cs index e5c81682b5..129c56726e 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/PartialChannel.cs +++ b/src/core/DSharpPlus.Core.Models/Channels/PartialChannel.cs @@ -7,8 +7,6 @@ using DSharpPlus.Entities; -using Remora.Rest.Core; - using DSharpPlus.Core.Abstractions.Models; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/Channels/PartialChannelOverwrite.cs b/src/core/DSharpPlus.Core.Models/Channels/PartialChannelOverwrite.cs index ccc2892b10..7f3bd018d6 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/PartialChannelOverwrite.cs +++ b/src/core/DSharpPlus.Core.Models/Channels/PartialChannelOverwrite.cs @@ -4,8 +4,6 @@ using DSharpPlus.Entities; -using Remora.Rest.Core; - using DSharpPlus.Core.Abstractions.Models; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/Channels/PartialMessage.cs b/src/core/DSharpPlus.Core.Models/Channels/PartialMessage.cs index 6dc583ddfa..41a1c94be0 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/PartialMessage.cs +++ b/src/core/DSharpPlus.Core.Models/Channels/PartialMessage.cs @@ -7,8 +7,6 @@ using DSharpPlus.Entities; -using Remora.Rest.Core; - using DSharpPlus.Core.Abstractions.Models; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/Channels/RoleSubscriptionData.cs b/src/core/DSharpPlus.Core.Models/Channels/RoleSubscriptionData.cs index 3f84822729..489b0d0734 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/RoleSubscriptionData.cs +++ b/src/core/DSharpPlus.Core.Models/Channels/RoleSubscriptionData.cs @@ -1,8 +1,3 @@ -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -using Remora.Rest.Core; using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/Channels/ThreadMember.cs b/src/core/DSharpPlus.Core.Models/Channels/ThreadMember.cs index 5b91c94f72..4139e3f355 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/ThreadMember.cs +++ b/src/core/DSharpPlus.Core.Models/Channels/ThreadMember.cs @@ -4,8 +4,6 @@ using System; -using Remora.Rest.Core; - using DSharpPlus.Core.Abstractions.Models; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/Channels/ThreadMetadata.cs b/src/core/DSharpPlus.Core.Models/Channels/ThreadMetadata.cs index 5447aef135..d9d2246160 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/ThreadMetadata.cs +++ b/src/core/DSharpPlus.Core.Models/Channels/ThreadMetadata.cs @@ -4,8 +4,6 @@ using System; -using Remora.Rest.Core; - using DSharpPlus.Core.Abstractions.Models; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/Emojis/Emoji.cs b/src/core/DSharpPlus.Core.Models/Emojis/Emoji.cs index 1f0f618d25..ce9e997df1 100644 --- a/src/core/DSharpPlus.Core.Models/Emojis/Emoji.cs +++ b/src/core/DSharpPlus.Core.Models/Emojis/Emoji.cs @@ -4,8 +4,6 @@ using System.Collections.Generic; -using Remora.Rest.Core; - using DSharpPlus.Core.Abstractions.Models; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/Emojis/PartialEmoji.cs b/src/core/DSharpPlus.Core.Models/Emojis/PartialEmoji.cs index bc110d00ac..2de09a4747 100644 --- a/src/core/DSharpPlus.Core.Models/Emojis/PartialEmoji.cs +++ b/src/core/DSharpPlus.Core.Models/Emojis/PartialEmoji.cs @@ -4,8 +4,6 @@ using System.Collections.Generic; -using Remora.Rest.Core; - using DSharpPlus.Core.Abstractions.Models; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/Entitlements/Entitlement.cs b/src/core/DSharpPlus.Core.Models/Entitlements/Entitlement.cs index 5e0ec89a19..a1bc1ca706 100644 --- a/src/core/DSharpPlus.Core.Models/Entitlements/Entitlement.cs +++ b/src/core/DSharpPlus.Core.Models/Entitlements/Entitlement.cs @@ -6,8 +6,6 @@ using DSharpPlus.Entities; -using Remora.Rest.Core; - using DSharpPlus.Core.Abstractions.Models; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/GuildTemplates/Template.cs b/src/core/DSharpPlus.Core.Models/GuildTemplates/Template.cs index 1354066d7e..d088b3b316 100644 --- a/src/core/DSharpPlus.Core.Models/GuildTemplates/Template.cs +++ b/src/core/DSharpPlus.Core.Models/GuildTemplates/Template.cs @@ -4,8 +4,6 @@ using System; -using Remora.Rest.Core; - using DSharpPlus.Core.Abstractions.Models; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/Guilds/Guild.cs b/src/core/DSharpPlus.Core.Models/Guilds/Guild.cs index eccf04b916..fcc6df9917 100644 --- a/src/core/DSharpPlus.Core.Models/Guilds/Guild.cs +++ b/src/core/DSharpPlus.Core.Models/Guilds/Guild.cs @@ -6,8 +6,6 @@ using DSharpPlus.Entities; -using Remora.Rest.Core; - using DSharpPlus.Core.Abstractions.Models; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/Guilds/GuildMember.cs b/src/core/DSharpPlus.Core.Models/Guilds/GuildMember.cs index 395c7abfee..e514ca1a3d 100644 --- a/src/core/DSharpPlus.Core.Models/Guilds/GuildMember.cs +++ b/src/core/DSharpPlus.Core.Models/Guilds/GuildMember.cs @@ -7,8 +7,6 @@ using DSharpPlus.Entities; -using Remora.Rest.Core; - using DSharpPlus.Core.Abstractions.Models; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/Guilds/GuildPreview.cs b/src/core/DSharpPlus.Core.Models/Guilds/GuildPreview.cs index 94a10010c3..6bda23806a 100644 --- a/src/core/DSharpPlus.Core.Models/Guilds/GuildPreview.cs +++ b/src/core/DSharpPlus.Core.Models/Guilds/GuildPreview.cs @@ -4,8 +4,6 @@ using System.Collections.Generic; -using Remora.Rest.Core; - using DSharpPlus.Core.Abstractions.Models; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/Guilds/GuildWidget.cs b/src/core/DSharpPlus.Core.Models/Guilds/GuildWidget.cs index fa3c5fe0e8..b790a58fe3 100644 --- a/src/core/DSharpPlus.Core.Models/Guilds/GuildWidget.cs +++ b/src/core/DSharpPlus.Core.Models/Guilds/GuildWidget.cs @@ -4,8 +4,6 @@ using System.Collections.Generic; -using Remora.Rest.Core; - using DSharpPlus.Core.Abstractions.Models; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/Guilds/GuildWidgetSettings.cs b/src/core/DSharpPlus.Core.Models/Guilds/GuildWidgetSettings.cs index d90548f0db..5e1cf383cb 100644 --- a/src/core/DSharpPlus.Core.Models/Guilds/GuildWidgetSettings.cs +++ b/src/core/DSharpPlus.Core.Models/Guilds/GuildWidgetSettings.cs @@ -1,8 +1,3 @@ -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -using Remora.Rest.Core; using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/Guilds/Integration.cs b/src/core/DSharpPlus.Core.Models/Guilds/Integration.cs index b8ca79ce32..da6e945ee4 100644 --- a/src/core/DSharpPlus.Core.Models/Guilds/Integration.cs +++ b/src/core/DSharpPlus.Core.Models/Guilds/Integration.cs @@ -7,8 +7,6 @@ using DSharpPlus.Entities; -using Remora.Rest.Core; - using DSharpPlus.Core.Abstractions.Models; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/Guilds/IntegrationApplication.cs b/src/core/DSharpPlus.Core.Models/Guilds/IntegrationApplication.cs index cf03ea40eb..e418b5bdb1 100644 --- a/src/core/DSharpPlus.Core.Models/Guilds/IntegrationApplication.cs +++ b/src/core/DSharpPlus.Core.Models/Guilds/IntegrationApplication.cs @@ -1,8 +1,3 @@ -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -using Remora.Rest.Core; using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/Guilds/Onboarding.cs b/src/core/DSharpPlus.Core.Models/Guilds/Onboarding.cs index 11eab8a957..7e92bb76f7 100644 --- a/src/core/DSharpPlus.Core.Models/Guilds/Onboarding.cs +++ b/src/core/DSharpPlus.Core.Models/Guilds/Onboarding.cs @@ -6,8 +6,6 @@ using DSharpPlus.Entities; -using Remora.Rest.Core; - using DSharpPlus.Core.Abstractions.Models; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/Guilds/OnboardingPrompt.cs b/src/core/DSharpPlus.Core.Models/Guilds/OnboardingPrompt.cs index 75c30610b9..0b8efd0f6c 100644 --- a/src/core/DSharpPlus.Core.Models/Guilds/OnboardingPrompt.cs +++ b/src/core/DSharpPlus.Core.Models/Guilds/OnboardingPrompt.cs @@ -6,8 +6,6 @@ using DSharpPlus.Entities; -using Remora.Rest.Core; - using DSharpPlus.Core.Abstractions.Models; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/Guilds/OnboardingPromptOption.cs b/src/core/DSharpPlus.Core.Models/Guilds/OnboardingPromptOption.cs index c3055ac3d1..7acd667d93 100644 --- a/src/core/DSharpPlus.Core.Models/Guilds/OnboardingPromptOption.cs +++ b/src/core/DSharpPlus.Core.Models/Guilds/OnboardingPromptOption.cs @@ -4,8 +4,6 @@ using System.Collections.Generic; -using Remora.Rest.Core; - using DSharpPlus.Core.Abstractions.Models; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/Guilds/PartialGuild.cs b/src/core/DSharpPlus.Core.Models/Guilds/PartialGuild.cs index 31a612146e..7d05390b13 100644 --- a/src/core/DSharpPlus.Core.Models/Guilds/PartialGuild.cs +++ b/src/core/DSharpPlus.Core.Models/Guilds/PartialGuild.cs @@ -6,8 +6,6 @@ using DSharpPlus.Entities; -using Remora.Rest.Core; - using DSharpPlus.Core.Abstractions.Models; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/Guilds/PartialGuildMember.cs b/src/core/DSharpPlus.Core.Models/Guilds/PartialGuildMember.cs index 35a850a610..9c0941381f 100644 --- a/src/core/DSharpPlus.Core.Models/Guilds/PartialGuildMember.cs +++ b/src/core/DSharpPlus.Core.Models/Guilds/PartialGuildMember.cs @@ -7,8 +7,6 @@ using DSharpPlus.Entities; -using Remora.Rest.Core; - using DSharpPlus.Core.Abstractions.Models; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/Guilds/PartialIntegration.cs b/src/core/DSharpPlus.Core.Models/Guilds/PartialIntegration.cs index fcc4cafa91..bf14169eef 100644 --- a/src/core/DSharpPlus.Core.Models/Guilds/PartialIntegration.cs +++ b/src/core/DSharpPlus.Core.Models/Guilds/PartialIntegration.cs @@ -7,8 +7,6 @@ using DSharpPlus.Entities; -using Remora.Rest.Core; - using DSharpPlus.Core.Abstractions.Models; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/Guilds/PartialRole.cs b/src/core/DSharpPlus.Core.Models/Guilds/PartialRole.cs index c94ccb5841..6dcc33f008 100644 --- a/src/core/DSharpPlus.Core.Models/Guilds/PartialRole.cs +++ b/src/core/DSharpPlus.Core.Models/Guilds/PartialRole.cs @@ -4,8 +4,6 @@ using DSharpPlus.Entities; -using Remora.Rest.Core; - using DSharpPlus.Core.Abstractions.Models; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/Guilds/Role.cs b/src/core/DSharpPlus.Core.Models/Guilds/Role.cs index 3a6b9df0c6..c377b9c905 100644 --- a/src/core/DSharpPlus.Core.Models/Guilds/Role.cs +++ b/src/core/DSharpPlus.Core.Models/Guilds/Role.cs @@ -4,8 +4,6 @@ using DSharpPlus.Entities; -using Remora.Rest.Core; - using DSharpPlus.Core.Abstractions.Models; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/Guilds/RoleTags.cs b/src/core/DSharpPlus.Core.Models/Guilds/RoleTags.cs index 06d01b142b..851644cb23 100644 --- a/src/core/DSharpPlus.Core.Models/Guilds/RoleTags.cs +++ b/src/core/DSharpPlus.Core.Models/Guilds/RoleTags.cs @@ -1,8 +1,3 @@ -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -using Remora.Rest.Core; using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/Guilds/WelcomeScreenChannel.cs b/src/core/DSharpPlus.Core.Models/Guilds/WelcomeScreenChannel.cs index 9cd1a33236..212198d01f 100644 --- a/src/core/DSharpPlus.Core.Models/Guilds/WelcomeScreenChannel.cs +++ b/src/core/DSharpPlus.Core.Models/Guilds/WelcomeScreenChannel.cs @@ -1,8 +1,3 @@ -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -using Remora.Rest.Core; using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/Interactions/ApplicationCommandInteractionData.cs b/src/core/DSharpPlus.Core.Models/Interactions/ApplicationCommandInteractionData.cs index 2dd94fccf5..0f90d3848e 100644 --- a/src/core/DSharpPlus.Core.Models/Interactions/ApplicationCommandInteractionData.cs +++ b/src/core/DSharpPlus.Core.Models/Interactions/ApplicationCommandInteractionData.cs @@ -6,8 +6,6 @@ using DSharpPlus.Entities; -using Remora.Rest.Core; - using DSharpPlus.Core.Abstractions.Models; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/Interactions/ApplicationCommandInteractionDataOption.cs b/src/core/DSharpPlus.Core.Models/Interactions/ApplicationCommandInteractionDataOption.cs index 9d7a13ee1a..0a9f14e718 100644 --- a/src/core/DSharpPlus.Core.Models/Interactions/ApplicationCommandInteractionDataOption.cs +++ b/src/core/DSharpPlus.Core.Models/Interactions/ApplicationCommandInteractionDataOption.cs @@ -8,8 +8,6 @@ using OneOf; -using Remora.Rest.Core; - using DSharpPlus.Core.Abstractions.Models; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/Interactions/Interaction.cs b/src/core/DSharpPlus.Core.Models/Interactions/Interaction.cs index 383cc1ed13..21883aec4b 100644 --- a/src/core/DSharpPlus.Core.Models/Interactions/Interaction.cs +++ b/src/core/DSharpPlus.Core.Models/Interactions/Interaction.cs @@ -8,8 +8,6 @@ using OneOf; -using Remora.Rest.Core; - using DSharpPlus.Core.Abstractions.Models; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/Interactions/InteractionResponse.cs b/src/core/DSharpPlus.Core.Models/Interactions/InteractionResponse.cs index b2ea703f5e..3e52903654 100644 --- a/src/core/DSharpPlus.Core.Models/Interactions/InteractionResponse.cs +++ b/src/core/DSharpPlus.Core.Models/Interactions/InteractionResponse.cs @@ -6,8 +6,6 @@ using OneOf; -using Remora.Rest.Core; - using DSharpPlus.Core.Abstractions.Models; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/Interactions/MessageCallbackData.cs b/src/core/DSharpPlus.Core.Models/Interactions/MessageCallbackData.cs index 82fd583813..22774ada86 100644 --- a/src/core/DSharpPlus.Core.Models/Interactions/MessageCallbackData.cs +++ b/src/core/DSharpPlus.Core.Models/Interactions/MessageCallbackData.cs @@ -6,8 +6,6 @@ using DSharpPlus.Entities; -using Remora.Rest.Core; - using DSharpPlus.Core.Abstractions.Models; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/Interactions/MessageComponentInteractionData.cs b/src/core/DSharpPlus.Core.Models/Interactions/MessageComponentInteractionData.cs index 92997d8a9a..de1b52dc53 100644 --- a/src/core/DSharpPlus.Core.Models/Interactions/MessageComponentInteractionData.cs +++ b/src/core/DSharpPlus.Core.Models/Interactions/MessageComponentInteractionData.cs @@ -6,8 +6,6 @@ using DSharpPlus.Entities; -using Remora.Rest.Core; - using DSharpPlus.Core.Abstractions.Models; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/Interactions/MessageInteraction.cs b/src/core/DSharpPlus.Core.Models/Interactions/MessageInteraction.cs index 421a523b9b..bc76820e4b 100644 --- a/src/core/DSharpPlus.Core.Models/Interactions/MessageInteraction.cs +++ b/src/core/DSharpPlus.Core.Models/Interactions/MessageInteraction.cs @@ -4,8 +4,6 @@ using DSharpPlus.Entities; -using Remora.Rest.Core; - using DSharpPlus.Core.Abstractions.Models; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/Interactions/ResolvedData.cs b/src/core/DSharpPlus.Core.Models/Interactions/ResolvedData.cs index ba856a6bf9..2d40808d65 100644 --- a/src/core/DSharpPlus.Core.Models/Interactions/ResolvedData.cs +++ b/src/core/DSharpPlus.Core.Models/Interactions/ResolvedData.cs @@ -4,8 +4,6 @@ using System.Collections.Generic; -using Remora.Rest.Core; - using DSharpPlus.Core.Abstractions.Models; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/Invites/Invite.cs b/src/core/DSharpPlus.Core.Models/Invites/Invite.cs index a39d87fcce..4e1664ac83 100644 --- a/src/core/DSharpPlus.Core.Models/Invites/Invite.cs +++ b/src/core/DSharpPlus.Core.Models/Invites/Invite.cs @@ -6,8 +6,6 @@ using DSharpPlus.Entities; -using Remora.Rest.Core; - using DSharpPlus.Core.Abstractions.Models; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/Invites/PartialInvite.cs b/src/core/DSharpPlus.Core.Models/Invites/PartialInvite.cs index 8aa0dceb34..8d4d4d5ec1 100644 --- a/src/core/DSharpPlus.Core.Models/Invites/PartialInvite.cs +++ b/src/core/DSharpPlus.Core.Models/Invites/PartialInvite.cs @@ -6,8 +6,6 @@ using DSharpPlus.Entities; -using Remora.Rest.Core; - using DSharpPlus.Core.Abstractions.Models; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/MessageComponents/ButtonComponent.cs b/src/core/DSharpPlus.Core.Models/MessageComponents/ButtonComponent.cs index c5cd2ad628..8576d4a6b0 100644 --- a/src/core/DSharpPlus.Core.Models/MessageComponents/ButtonComponent.cs +++ b/src/core/DSharpPlus.Core.Models/MessageComponents/ButtonComponent.cs @@ -4,8 +4,6 @@ using DSharpPlus.Entities; -using Remora.Rest.Core; - using DSharpPlus.Core.Abstractions.Models; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/MessageComponents/ChannelSelectComponent.cs b/src/core/DSharpPlus.Core.Models/MessageComponents/ChannelSelectComponent.cs index 0d4b45d409..9b1329bfee 100644 --- a/src/core/DSharpPlus.Core.Models/MessageComponents/ChannelSelectComponent.cs +++ b/src/core/DSharpPlus.Core.Models/MessageComponents/ChannelSelectComponent.cs @@ -6,8 +6,6 @@ using DSharpPlus.Entities; -using Remora.Rest.Core; - using DSharpPlus.Core.Abstractions.Models; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/MessageComponents/DefaultSelectValue.cs b/src/core/DSharpPlus.Core.Models/MessageComponents/DefaultSelectValue.cs index f6ea445a4b..595d5d07ca 100644 --- a/src/core/DSharpPlus.Core.Models/MessageComponents/DefaultSelectValue.cs +++ b/src/core/DSharpPlus.Core.Models/MessageComponents/DefaultSelectValue.cs @@ -1,8 +1,3 @@ -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -using Remora.Rest.Core; using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/MessageComponents/MentionableSelectComponent.cs b/src/core/DSharpPlus.Core.Models/MessageComponents/MentionableSelectComponent.cs index 0450e9b8ed..fdc5132ed2 100644 --- a/src/core/DSharpPlus.Core.Models/MessageComponents/MentionableSelectComponent.cs +++ b/src/core/DSharpPlus.Core.Models/MessageComponents/MentionableSelectComponent.cs @@ -6,8 +6,6 @@ using DSharpPlus.Entities; -using Remora.Rest.Core; - using DSharpPlus.Core.Abstractions.Models; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/MessageComponents/RoleSelectComponent.cs b/src/core/DSharpPlus.Core.Models/MessageComponents/RoleSelectComponent.cs index 4d058a5887..34fab0398d 100644 --- a/src/core/DSharpPlus.Core.Models/MessageComponents/RoleSelectComponent.cs +++ b/src/core/DSharpPlus.Core.Models/MessageComponents/RoleSelectComponent.cs @@ -6,8 +6,6 @@ using DSharpPlus.Entities; -using Remora.Rest.Core; - using DSharpPlus.Core.Abstractions.Models; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/MessageComponents/SelectOption.cs b/src/core/DSharpPlus.Core.Models/MessageComponents/SelectOption.cs index 4c2d46b891..ba2509044a 100644 --- a/src/core/DSharpPlus.Core.Models/MessageComponents/SelectOption.cs +++ b/src/core/DSharpPlus.Core.Models/MessageComponents/SelectOption.cs @@ -1,8 +1,3 @@ -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -using Remora.Rest.Core; using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/MessageComponents/StringSelectComponent.cs b/src/core/DSharpPlus.Core.Models/MessageComponents/StringSelectComponent.cs index b2660b2dca..c38b5dd981 100644 --- a/src/core/DSharpPlus.Core.Models/MessageComponents/StringSelectComponent.cs +++ b/src/core/DSharpPlus.Core.Models/MessageComponents/StringSelectComponent.cs @@ -6,8 +6,6 @@ using DSharpPlus.Entities; -using Remora.Rest.Core; - using DSharpPlus.Core.Abstractions.Models; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/MessageComponents/TextInputComponent.cs b/src/core/DSharpPlus.Core.Models/MessageComponents/TextInputComponent.cs index 3a1e9efd7d..bfefba0b09 100644 --- a/src/core/DSharpPlus.Core.Models/MessageComponents/TextInputComponent.cs +++ b/src/core/DSharpPlus.Core.Models/MessageComponents/TextInputComponent.cs @@ -4,8 +4,6 @@ using DSharpPlus.Entities; -using Remora.Rest.Core; - using DSharpPlus.Core.Abstractions.Models; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/MessageComponents/UserSelectComponent.cs b/src/core/DSharpPlus.Core.Models/MessageComponents/UserSelectComponent.cs index 4567c7a66d..a51b6e7eeb 100644 --- a/src/core/DSharpPlus.Core.Models/MessageComponents/UserSelectComponent.cs +++ b/src/core/DSharpPlus.Core.Models/MessageComponents/UserSelectComponent.cs @@ -6,8 +6,6 @@ using DSharpPlus.Entities; -using Remora.Rest.Core; - using DSharpPlus.Core.Abstractions.Models; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/RoleConnections/RoleConnectionMetadata.cs b/src/core/DSharpPlus.Core.Models/RoleConnections/RoleConnectionMetadata.cs index 77dfb0f6e8..df13680cce 100644 --- a/src/core/DSharpPlus.Core.Models/RoleConnections/RoleConnectionMetadata.cs +++ b/src/core/DSharpPlus.Core.Models/RoleConnections/RoleConnectionMetadata.cs @@ -6,8 +6,6 @@ using DSharpPlus.Entities; -using Remora.Rest.Core; - using DSharpPlus.Core.Abstractions.Models; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/ScheduledEvents/PartialScheduledEvent.cs b/src/core/DSharpPlus.Core.Models/ScheduledEvents/PartialScheduledEvent.cs index 4504773bf4..ab8b7f6a6e 100644 --- a/src/core/DSharpPlus.Core.Models/ScheduledEvents/PartialScheduledEvent.cs +++ b/src/core/DSharpPlus.Core.Models/ScheduledEvents/PartialScheduledEvent.cs @@ -2,11 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Entities; - -using Remora.Rest.Core; using System; +using DSharpPlus.Entities; + using DSharpPlus.Core.Abstractions.Models; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/ScheduledEvents/ScheduledEvent.cs b/src/core/DSharpPlus.Core.Models/ScheduledEvents/ScheduledEvent.cs index 842759b4a0..b94c561135 100644 --- a/src/core/DSharpPlus.Core.Models/ScheduledEvents/ScheduledEvent.cs +++ b/src/core/DSharpPlus.Core.Models/ScheduledEvents/ScheduledEvent.cs @@ -2,11 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Entities; - -using Remora.Rest.Core; using System; +using DSharpPlus.Entities; + using DSharpPlus.Core.Abstractions.Models; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/ScheduledEvents/ScheduledEventUser.cs b/src/core/DSharpPlus.Core.Models/ScheduledEvents/ScheduledEventUser.cs index ee2dff1986..28a3f2a68f 100644 --- a/src/core/DSharpPlus.Core.Models/ScheduledEvents/ScheduledEventUser.cs +++ b/src/core/DSharpPlus.Core.Models/ScheduledEvents/ScheduledEventUser.cs @@ -1,8 +1,3 @@ -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -using Remora.Rest.Core; using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/Skus/Sku.cs b/src/core/DSharpPlus.Core.Models/Skus/Sku.cs index 06f4b9bcdc..c7443ef8ab 100644 --- a/src/core/DSharpPlus.Core.Models/Skus/Sku.cs +++ b/src/core/DSharpPlus.Core.Models/Skus/Sku.cs @@ -4,8 +4,6 @@ using DSharpPlus.Entities; -using Remora.Rest.Core; - using DSharpPlus.Core.Abstractions.Models; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/StageInstances/PartialStageInstance.cs b/src/core/DSharpPlus.Core.Models/StageInstances/PartialStageInstance.cs index 34545c5252..6510a0de45 100644 --- a/src/core/DSharpPlus.Core.Models/StageInstances/PartialStageInstance.cs +++ b/src/core/DSharpPlus.Core.Models/StageInstances/PartialStageInstance.cs @@ -4,8 +4,6 @@ using DSharpPlus.Entities; -using Remora.Rest.Core; - using DSharpPlus.Core.Abstractions.Models; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/StageInstances/StageInstance.cs b/src/core/DSharpPlus.Core.Models/StageInstances/StageInstance.cs index 2366f05ee3..4d45b9c7df 100644 --- a/src/core/DSharpPlus.Core.Models/StageInstances/StageInstance.cs +++ b/src/core/DSharpPlus.Core.Models/StageInstances/StageInstance.cs @@ -4,8 +4,6 @@ using DSharpPlus.Entities; -using Remora.Rest.Core; - using DSharpPlus.Core.Abstractions.Models; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/Stickers/PartialSticker.cs b/src/core/DSharpPlus.Core.Models/Stickers/PartialSticker.cs index f8aac809fb..8a43fd20ff 100644 --- a/src/core/DSharpPlus.Core.Models/Stickers/PartialSticker.cs +++ b/src/core/DSharpPlus.Core.Models/Stickers/PartialSticker.cs @@ -4,8 +4,6 @@ using DSharpPlus.Entities; -using Remora.Rest.Core; - using DSharpPlus.Core.Abstractions.Models; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/Stickers/Sticker.cs b/src/core/DSharpPlus.Core.Models/Stickers/Sticker.cs index 120ef599cb..e7c9741b02 100644 --- a/src/core/DSharpPlus.Core.Models/Stickers/Sticker.cs +++ b/src/core/DSharpPlus.Core.Models/Stickers/Sticker.cs @@ -4,8 +4,6 @@ using DSharpPlus.Entities; -using Remora.Rest.Core; - using DSharpPlus.Core.Abstractions.Models; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/Stickers/StickerItem.cs b/src/core/DSharpPlus.Core.Models/Stickers/StickerItem.cs index 1c02604de5..aa9947182c 100644 --- a/src/core/DSharpPlus.Core.Models/Stickers/StickerItem.cs +++ b/src/core/DSharpPlus.Core.Models/Stickers/StickerItem.cs @@ -4,8 +4,6 @@ using DSharpPlus.Entities; -using Remora.Rest.Core; - using DSharpPlus.Core.Abstractions.Models; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/Stickers/StickerPack.cs b/src/core/DSharpPlus.Core.Models/Stickers/StickerPack.cs index d83f1c4b86..6bd3781051 100644 --- a/src/core/DSharpPlus.Core.Models/Stickers/StickerPack.cs +++ b/src/core/DSharpPlus.Core.Models/Stickers/StickerPack.cs @@ -4,8 +4,6 @@ using System.Collections.Generic; -using Remora.Rest.Core; - using DSharpPlus.Core.Abstractions.Models; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/Teams/Team.cs b/src/core/DSharpPlus.Core.Models/Teams/Team.cs index 4e22073993..cbc782d878 100644 --- a/src/core/DSharpPlus.Core.Models/Teams/Team.cs +++ b/src/core/DSharpPlus.Core.Models/Teams/Team.cs @@ -4,8 +4,6 @@ using System.Collections.Generic; -using Remora.Rest.Core; - using DSharpPlus.Core.Abstractions.Models; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/Teams/TeamMember.cs b/src/core/DSharpPlus.Core.Models/Teams/TeamMember.cs index c9bf06785c..ff6a22b9ee 100644 --- a/src/core/DSharpPlus.Core.Models/Teams/TeamMember.cs +++ b/src/core/DSharpPlus.Core.Models/Teams/TeamMember.cs @@ -6,8 +6,6 @@ using DSharpPlus.Entities; -using Remora.Rest.Core; - using DSharpPlus.Core.Abstractions.Models; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/Users/Connection.cs b/src/core/DSharpPlus.Core.Models/Users/Connection.cs index 93cf9d26f9..e45c3e862a 100644 --- a/src/core/DSharpPlus.Core.Models/Users/Connection.cs +++ b/src/core/DSharpPlus.Core.Models/Users/Connection.cs @@ -6,8 +6,6 @@ using DSharpPlus.Entities; -using Remora.Rest.Core; - using DSharpPlus.Core.Abstractions.Models; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/Users/PartialUser.cs b/src/core/DSharpPlus.Core.Models/Users/PartialUser.cs index 07dda803e3..d02febf3c6 100644 --- a/src/core/DSharpPlus.Core.Models/Users/PartialUser.cs +++ b/src/core/DSharpPlus.Core.Models/Users/PartialUser.cs @@ -3,7 +3,6 @@ // file, You can obtain one at https://mozilla.org/MPL/2.0/. using DSharpPlus.Entities; -using Remora.Rest.Core; using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/Users/User.cs b/src/core/DSharpPlus.Core.Models/Users/User.cs index 65d134b1d7..a60e78abdb 100644 --- a/src/core/DSharpPlus.Core.Models/Users/User.cs +++ b/src/core/DSharpPlus.Core.Models/Users/User.cs @@ -3,7 +3,6 @@ // file, You can obtain one at https://mozilla.org/MPL/2.0/. using DSharpPlus.Entities; -using Remora.Rest.Core; using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/Voice/VoiceState.cs b/src/core/DSharpPlus.Core.Models/Voice/VoiceState.cs index b66a70f416..faf08fd406 100644 --- a/src/core/DSharpPlus.Core.Models/Voice/VoiceState.cs +++ b/src/core/DSharpPlus.Core.Models/Voice/VoiceState.cs @@ -4,8 +4,6 @@ using System; -using Remora.Rest.Core; - using DSharpPlus.Core.Abstractions.Models; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/Webhooks/PartialWebhook.cs b/src/core/DSharpPlus.Core.Models/Webhooks/PartialWebhook.cs index 4c6d5558bb..2cae864712 100644 --- a/src/core/DSharpPlus.Core.Models/Webhooks/PartialWebhook.cs +++ b/src/core/DSharpPlus.Core.Models/Webhooks/PartialWebhook.cs @@ -4,8 +4,6 @@ using DSharpPlus.Entities; -using Remora.Rest.Core; - using DSharpPlus.Core.Abstractions.Models; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/Webhooks/Webhook.cs b/src/core/DSharpPlus.Core.Models/Webhooks/Webhook.cs index f9cf3aea5f..a9c33bbe35 100644 --- a/src/core/DSharpPlus.Core.Models/Webhooks/Webhook.cs +++ b/src/core/DSharpPlus.Core.Models/Webhooks/Webhook.cs @@ -4,8 +4,6 @@ using DSharpPlus.Entities; -using Remora.Rest.Core; - using DSharpPlus.Core.Abstractions.Models; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Shared/Optional`1.cs b/src/core/DSharpPlus.Shared/Optional`1.cs index 12c4220595..8cd12a9da6 100644 --- a/src/core/DSharpPlus.Shared/Optional`1.cs +++ b/src/core/DSharpPlus.Shared/Optional`1.cs @@ -149,4 +149,7 @@ public override string ToString() ? $"Optional {{ {this.value} }}" : "Optional { no value }"; } + + public static implicit operator Optional(T value) + => new(value); } diff --git a/src/core/DSharpPlus.Shared/Snowflake.cs b/src/core/DSharpPlus.Shared/Snowflake.cs index dc3a50c679..289adfe31f 100644 --- a/src/core/DSharpPlus.Shared/Snowflake.cs +++ b/src/core/DSharpPlus.Shared/Snowflake.cs @@ -93,10 +93,7 @@ public Snowflake | increment.Value; } - public int CompareTo - ( - Snowflake other - ) + public int CompareTo(Snowflake other) => this.Value.CompareTo(other.Value); public static bool operator <(Snowflake left, Snowflake right) => left.Value < right.Value; From 71f3213cda331d32f560b7c675071fb6d93a27ad Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Mon, 9 Oct 2023 18:51:42 +0200 Subject: [PATCH 149/323] move the converters over --- .../DSharpPlus.Core.Models.csproj | 6 +-- .../Converters/AuditLogChangeConverter.cs | 14 +++---- .../AutoModerationActionConverter.cs | 20 +++++----- .../Converters/DiscordPermissionConverter.cs | 8 ++-- .../Converters/MessageComponentConverter.cs | 40 +++++++++---------- .../Converters/NullBooleanConverter.cs | 2 +- 6 files changed, 41 insertions(+), 49 deletions(-) rename src/core/DSharpPlus.Core.Models/{ => Serialization}/Converters/AuditLogChangeConverter.cs (89%) rename src/core/DSharpPlus.Core.Models/{ => Serialization}/Converters/AutoModerationActionConverter.cs (81%) rename src/core/DSharpPlus.Core.Models/{ => Serialization}/Converters/DiscordPermissionConverter.cs (91%) rename src/core/DSharpPlus.Core.Models/{ => Serialization}/Converters/MessageComponentConverter.cs (77%) rename src/core/DSharpPlus.Core.Models/{ => Serialization}/Converters/NullBooleanConverter.cs (96%) diff --git a/src/core/DSharpPlus.Core.Models/DSharpPlus.Core.Models.csproj b/src/core/DSharpPlus.Core.Models/DSharpPlus.Core.Models.csproj index f71b43ad75..efd579aa26 100644 --- a/src/core/DSharpPlus.Core.Models/DSharpPlus.Core.Models.csproj +++ b/src/core/DSharpPlus.Core.Models/DSharpPlus.Core.Models.csproj @@ -10,14 +10,10 @@ - - - + diff --git a/src/core/DSharpPlus.Core.Models/Converters/AuditLogChangeConverter.cs b/src/core/DSharpPlus.Core.Models/Serialization/Converters/AuditLogChangeConverter.cs similarity index 89% rename from src/core/DSharpPlus.Core.Models/Converters/AuditLogChangeConverter.cs rename to src/core/DSharpPlus.Core.Models/Serialization/Converters/AuditLogChangeConverter.cs index 421db05575..3c77e96555 100644 --- a/src/core/DSharpPlus.Core.Models/Converters/AuditLogChangeConverter.cs +++ b/src/core/DSharpPlus.Core.Models/Serialization/Converters/AuditLogChangeConverter.cs @@ -8,9 +8,7 @@ using DSharpPlus.Core.Abstractions.Models; -using Remora.Rest.Core; - -namespace DSharpPlus.Core.Models.Converters; +namespace DSharpPlus.Core.Models.Serialization.Converters; /// /// Provides conversion for s. @@ -21,7 +19,7 @@ public class AuditLogChangeConverter : JsonConverter public override IAuditLogChange? Read ( ref Utf8JsonReader reader, - Type typeToConvert, + Type typeToConvert, JsonSerializerOptions options ) { @@ -62,8 +60,8 @@ JsonSerializerOptions options /// public override void Write ( - Utf8JsonWriter writer, - IAuditLogChange value, + Utf8JsonWriter writer, + IAuditLogChange value, JsonSerializerOptions options ) { @@ -72,13 +70,13 @@ JsonSerializerOptions options writer.WritePropertyName("key"); writer.WriteStringValue(value.Key); - if (value.NewValue.TryGet(out string? newValue)) + if (value.NewValue.TryGetValue(out string? newValue)) { writer.WritePropertyName("new_value"); writer.WriteStringValue(newValue); } - if (value.OldValue.TryGet(out string? oldValue)) + if (value.OldValue.TryGetValue(out string? oldValue)) { writer.WritePropertyName("old_value"); writer.WriteStringValue(oldValue); diff --git a/src/core/DSharpPlus.Core.Models/Converters/AutoModerationActionConverter.cs b/src/core/DSharpPlus.Core.Models/Serialization/Converters/AutoModerationActionConverter.cs similarity index 81% rename from src/core/DSharpPlus.Core.Models/Converters/AutoModerationActionConverter.cs rename to src/core/DSharpPlus.Core.Models/Serialization/Converters/AutoModerationActionConverter.cs index 31cab897fc..80be092ce9 100644 --- a/src/core/DSharpPlus.Core.Models/Converters/AutoModerationActionConverter.cs +++ b/src/core/DSharpPlus.Core.Models/Serialization/Converters/AutoModerationActionConverter.cs @@ -9,9 +9,7 @@ using DSharpPlus.Core.Abstractions.Models; using DSharpPlus.Entities; -using Remora.Rest.Core; - -namespace DSharpPlus.Core.Models.Converters; +namespace DSharpPlus.Core.Models.Serialization.Converters; /// /// Provides conversion for . @@ -21,8 +19,8 @@ public class AutoModerationActionConverter : JsonConverter public override IAutoModerationAction? Read ( - ref Utf8JsonReader reader, - Type typeToConvert, + ref Utf8JsonReader reader, + Type typeToConvert, JsonSerializerOptions options ) { @@ -45,11 +43,11 @@ JsonSerializerOptions options Optional data = (DiscordAutoModerationActionType)type switch { DiscordAutoModerationActionType.BlockMessage - => new(JsonSerializer.Deserialize(metadata, options)!), + => new(metadata.Deserialize(options)!), DiscordAutoModerationActionType.SendAlertMessage - => new(JsonSerializer.Deserialize(metadata, options)!), + => new(metadata.Deserialize(options)!), DiscordAutoModerationActionType.Timeout - => new(JsonSerializer.Deserialize(metadata, options)!), + => new(metadata.Deserialize(options)!), _ => new() }; @@ -65,8 +63,8 @@ JsonSerializerOptions options /// public override void Write ( - Utf8JsonWriter writer, - IAutoModerationAction value, + Utf8JsonWriter writer, + IAutoModerationAction value, JsonSerializerOptions options ) { @@ -75,7 +73,7 @@ JsonSerializerOptions options writer.WritePropertyName("type"); writer.WriteNumberValue((int)value.Type); - if (!value.Metadata.TryGet(out IAutoModerationActionMetadata? metadata)) + if (!value.Metadata.TryGetValue(out IAutoModerationActionMetadata? metadata)) { writer.WriteEndObject(); return; diff --git a/src/core/DSharpPlus.Core.Models/Converters/DiscordPermissionConverter.cs b/src/core/DSharpPlus.Core.Models/Serialization/Converters/DiscordPermissionConverter.cs similarity index 91% rename from src/core/DSharpPlus.Core.Models/Converters/DiscordPermissionConverter.cs rename to src/core/DSharpPlus.Core.Models/Serialization/Converters/DiscordPermissionConverter.cs index 7fe6172e8e..370191e27c 100644 --- a/src/core/DSharpPlus.Core.Models/Converters/DiscordPermissionConverter.cs +++ b/src/core/DSharpPlus.Core.Models/Serialization/Converters/DiscordPermissionConverter.cs @@ -9,7 +9,7 @@ using DSharpPlus.Entities; -namespace DSharpPlus.Core.Models.Converters; +namespace DSharpPlus.Core.Models.Serialization.Converters; /// /// Enables serializing and deserializing Discord permissions. @@ -19,8 +19,8 @@ public class DiscordPermissionConverter : JsonConverter /// public override DiscordPermissions Read ( - ref Utf8JsonReader reader, - Type typeToConvert, + ref Utf8JsonReader reader, + Type typeToConvert, JsonSerializerOptions options ) { @@ -42,6 +42,6 @@ public override void Write Utf8JsonWriter writer, DiscordPermissions value, JsonSerializerOptions options - ) + ) => writer.WriteStringValue(((ulong)value).ToString(CultureInfo.InvariantCulture)); } diff --git a/src/core/DSharpPlus.Core.Models/Converters/MessageComponentConverter.cs b/src/core/DSharpPlus.Core.Models/Serialization/Converters/MessageComponentConverter.cs similarity index 77% rename from src/core/DSharpPlus.Core.Models/Converters/MessageComponentConverter.cs rename to src/core/DSharpPlus.Core.Models/Serialization/Converters/MessageComponentConverter.cs index a98115aeae..1822521f3d 100644 --- a/src/core/DSharpPlus.Core.Models/Converters/MessageComponentConverter.cs +++ b/src/core/DSharpPlus.Core.Models/Serialization/Converters/MessageComponentConverter.cs @@ -9,7 +9,7 @@ using DSharpPlus.Core.Abstractions.Models; using DSharpPlus.Entities; -namespace DSharpPlus.Core.Models.Converters; +namespace DSharpPlus.Core.Models.Serialization.Converters; /// /// Converts between message components and JSON. @@ -19,8 +19,8 @@ public class MessageComponentConverter : JsonConverter /// public override IInteractiveComponent? Read ( - ref Utf8JsonReader reader, - Type typeToConvert, + ref Utf8JsonReader reader, + Type typeToConvert, JsonSerializerOptions options ) { @@ -43,28 +43,28 @@ JsonSerializerOptions options { DiscordMessageComponentType.ActionRow => throw new JsonException("Invalid JSON structure: expected an interactive component, not an action row."), - + DiscordMessageComponentType.Button - => JsonSerializer.Deserialize(document, options), - + => document.Deserialize(options), + DiscordMessageComponentType.StringSelect - => JsonSerializer.Deserialize(document, options), - + => document.Deserialize(options), + DiscordMessageComponentType.TextInput - => JsonSerializer.Deserialize(document, options), - + => document.Deserialize(options), + DiscordMessageComponentType.UserSelect - => JsonSerializer.Deserialize(document, options), - + => document.Deserialize(options), + DiscordMessageComponentType.RoleSelect - => JsonSerializer.Deserialize(document, options), - + => document.Deserialize(options), + DiscordMessageComponentType.MentionableSelect - => JsonSerializer.Deserialize(document, options), - + => document.Deserialize(options), + DiscordMessageComponentType.ChannelSelect - => JsonSerializer.Deserialize(document, options), - + => document.Deserialize(options), + _ => throw new JsonException("Unknown component type.") }; @@ -75,8 +75,8 @@ JsonSerializerOptions options /// public override void Write ( - Utf8JsonWriter writer, - IInteractiveComponent value, + Utf8JsonWriter writer, + IInteractiveComponent value, JsonSerializerOptions options ) { diff --git a/src/core/DSharpPlus.Core.Models/Converters/NullBooleanConverter.cs b/src/core/DSharpPlus.Core.Models/Serialization/Converters/NullBooleanConverter.cs similarity index 96% rename from src/core/DSharpPlus.Core.Models/Converters/NullBooleanConverter.cs rename to src/core/DSharpPlus.Core.Models/Serialization/Converters/NullBooleanConverter.cs index b930cf00de..1c8dd5895a 100644 --- a/src/core/DSharpPlus.Core.Models/Converters/NullBooleanConverter.cs +++ b/src/core/DSharpPlus.Core.Models/Serialization/Converters/NullBooleanConverter.cs @@ -6,7 +6,7 @@ using System.Text.Json; using System.Text.Json.Serialization; -namespace DSharpPlus.Core.Models.Converters; +namespace DSharpPlus.Core.Models.Serialization.Converters; /// /// Provides serialization for discord's optional null booleans, see From aee4c4ce195aba855ea104cb8830721e60953b52 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Wed, 11 Oct 2023 16:01:14 +0200 Subject: [PATCH 150/323] serialization abstraction --- Directory.Packages.props | 1 + .../DSharpPlus.Shared.csproj | 8 ++++ .../Serialization/ISerializationService.cs | 40 +++++++++++++++++++ 3 files changed, 49 insertions(+) create mode 100644 src/core/DSharpPlus.Shared/Serialization/ISerializationService.cs diff --git a/Directory.Packages.props b/Directory.Packages.props index cffe35174e..687433764c 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -1,5 +1,6 @@ + diff --git a/src/core/DSharpPlus.Shared/DSharpPlus.Shared.csproj b/src/core/DSharpPlus.Shared/DSharpPlus.Shared.csproj index 66dc4739b4..15504f49fc 100644 --- a/src/core/DSharpPlus.Shared/DSharpPlus.Shared.csproj +++ b/src/core/DSharpPlus.Shared/DSharpPlus.Shared.csproj @@ -11,4 +11,12 @@ DSharpPlus + + + + + + + + diff --git a/src/core/DSharpPlus.Shared/Serialization/ISerializationService.cs b/src/core/DSharpPlus.Shared/Serialization/ISerializationService.cs new file mode 100644 index 0000000000..25cd7a0a75 --- /dev/null +++ b/src/core/DSharpPlus.Shared/Serialization/ISerializationService.cs @@ -0,0 +1,40 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; + +using CommunityToolkit.HighPerformance.Buffers; + +namespace DSharpPlus.Serialization; + +/// +/// Represents an abstraction over model serialization. +/// +/// The library component a given instance is associated with. +public interface ISerializationService +{ + /// + /// Serializes a given serialization model to the given writer. + /// + /// + /// This method serializes the library data models specifically, and may not exhibit correct behaviour + /// for other types. + /// + public void SerializeModel + ( + TModel model, + ArrayPoolBufferWriter target + ) + where TModel : notnull; + + /// + /// Deserializes a serialization model from the provided data. + /// + /// + /// This method deserializes the library data models specifically, and may not exhibit correct behaviour + /// for other types. + /// + public TModel DeserializeModel(ReadOnlySpan data) + where TModel : notnull; +} From 1fb27fd67db4565579c41194b97d33216889d722 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Wed, 11 Oct 2023 16:06:34 +0200 Subject: [PATCH 151/323] optional handling --- .../Resolvers/OptionalTypeInfoResolver.cs | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 src/core/DSharpPlus.Core.Models/Serialization/Resolvers/OptionalTypeInfoResolver.cs diff --git a/src/core/DSharpPlus.Core.Models/Serialization/Resolvers/OptionalTypeInfoResolver.cs b/src/core/DSharpPlus.Core.Models/Serialization/Resolvers/OptionalTypeInfoResolver.cs new file mode 100644 index 0000000000..10faad2db1 --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/Serialization/Resolvers/OptionalTypeInfoResolver.cs @@ -0,0 +1,50 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Text.Json.Serialization.Metadata; + +namespace DSharpPlus.Core.Models.Serialization.Resolvers; + +/// +/// Provides a mechanism for resolving serialization of . +/// +public static class OptionalTypeInfoResolver +{ + public static IJsonTypeInfoResolver Default { get; } = new DefaultJsonTypeInfoResolver + { + Modifiers = + { + (type) => + { + foreach (JsonPropertyInfo property in type.Properties) + { + if (property.PropertyType.IsConstructedGenericType && + property.PropertyType.GetGenericTypeDefinition() == typeof(Optional<>)) + { + property.ShouldSerialize = Unsafe.As> + ( + typeof(OptionalTypeInfoResolver) + .GetMethod + ( + nameof(ShouldIgnoreOptional), + BindingFlags.NonPublic | BindingFlags.Static + )! + .MakeGenericMethod + ( + property.PropertyType.GetGenericArguments()[0]! + ) + .CreateDelegate(typeof(Func)) + ); + } + } + } + } + }; + + private static bool ShouldIgnoreOptional(object _, object? value) + => Unsafe.Unbox>(value!).HasValue; +} From 275f6c3ce693dd208de610102d52818f468392f4 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Wed, 11 Oct 2023 21:18:29 +0200 Subject: [PATCH 152/323] ancestral serialization horrors --- Directory.Packages.props | 2 + .../DSharpPlus.Shared.csproj | 2 + .../Serialization/ISerializationService.cs | 2 +- .../Serialization/SerializationOptions.cs | 58 ++++++ .../Serialization/SerializationService.cs | 174 ++++++++++++++++++ 5 files changed, 237 insertions(+), 1 deletion(-) create mode 100644 src/core/DSharpPlus.Shared/Serialization/SerializationOptions.cs create mode 100644 src/core/DSharpPlus.Shared/Serialization/SerializationService.cs diff --git a/Directory.Packages.props b/Directory.Packages.props index 687433764c..81be77e244 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -6,6 +6,8 @@ + + diff --git a/src/core/DSharpPlus.Shared/DSharpPlus.Shared.csproj b/src/core/DSharpPlus.Shared/DSharpPlus.Shared.csproj index 15504f49fc..fc31c2b78f 100644 --- a/src/core/DSharpPlus.Shared/DSharpPlus.Shared.csproj +++ b/src/core/DSharpPlus.Shared/DSharpPlus.Shared.csproj @@ -13,6 +13,8 @@ + + diff --git a/src/core/DSharpPlus.Shared/Serialization/ISerializationService.cs b/src/core/DSharpPlus.Shared/Serialization/ISerializationService.cs index 25cd7a0a75..d11c144fa0 100644 --- a/src/core/DSharpPlus.Shared/Serialization/ISerializationService.cs +++ b/src/core/DSharpPlus.Shared/Serialization/ISerializationService.cs @@ -12,7 +12,7 @@ namespace DSharpPlus.Serialization; /// Represents an abstraction over model serialization. /// /// The library component a given instance is associated with. -public interface ISerializationService +public interface ISerializationService { /// /// Serializes a given serialization model to the given writer. diff --git a/src/core/DSharpPlus.Shared/Serialization/SerializationOptions.cs b/src/core/DSharpPlus.Shared/Serialization/SerializationOptions.cs new file mode 100644 index 0000000000..bb1fdee251 --- /dev/null +++ b/src/core/DSharpPlus.Shared/Serialization/SerializationOptions.cs @@ -0,0 +1,58 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; +using System.Collections.Generic; + +namespace DSharpPlus.Serialization; + +/// +/// Contains information about which library component uses which serialization format and how models +/// are bound to their definitions. +/// +public sealed class SerializationOptions +{ + public const string Json = "json"; + public const string Etf = "etf"; + + /// + /// Well-known formats: + /// + /// "json", on top of System.Text.Json + /// "etf", on top of ETFKit + /// + /// + internal Dictionary Formats { get; } = new(2); + + internal Dictionary InterfacesToConcrete { get; } = new(256); + + /// + /// Specifies the concrete type used to deserialize an interface. + /// + public void AddModel() + where TInterface : notnull + where TModel : notnull, TInterface + => this.InterfacesToConcrete[typeof(TInterface)] = typeof(TModel); + + /// + /// Removes an interface to concrete type entry. + /// + public void RemoveModel() + where TInterface : notnull + => this.InterfacesToConcrete.Remove(typeof(TInterface)); + + /// + /// Specifies the format to use for a given library component. + /// + /// The interface associated with this component. + public void SetFormat(string format = "json") + => this.Formats[typeof(TComponent)] = format; + + /// + /// Clears the format associated with the given library component. + /// + /// The interface associated with this component. + public void ClearFormat() + => this.Formats.Remove(typeof(TComponent)); +} diff --git a/src/core/DSharpPlus.Shared/Serialization/SerializationService.cs b/src/core/DSharpPlus.Shared/Serialization/SerializationService.cs new file mode 100644 index 0000000000..656b37a2b3 --- /dev/null +++ b/src/core/DSharpPlus.Shared/Serialization/SerializationService.cs @@ -0,0 +1,174 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; +using System.Diagnostics.CodeAnalysis; +using System.Reflection; +using System.Reflection.Emit; +using System.Runtime.CompilerServices; +using System.Text.Json; +using System.Text.Json.Serialization.Metadata; + +using CommunityToolkit.HighPerformance.Buffers; + +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Options; + +namespace DSharpPlus.Serialization; + +/// +/// Handles serializing and deserializing models between different formats as necessary. +/// +/// The library component a given instance is associated with. +[RequiresDynamicCode("Serialization in DSharpPlus presently depends on unreferenced and dynamic code.")] +[RequiresUnreferencedCode("Serialization in DSharpPlus presently depends on unreferenced and dynamic code.")] +public sealed partial class SerializationService : ISerializationService +{ + private readonly string format; + + private readonly JsonSerializerOptions? jsonOptions; + + public SerializationService + ( + IOptions formats, + ILogger> logger, + IServiceProvider provider + ) + { + if (formats.Value.Formats.TryGetValue(typeof(T), out string? format)) + { + LogFormatSpecified(logger, format, typeof(T)); + + this.format = format; + } + else + { + LogFormatFallback(logger, typeof(T)); + + this.format = "json"; + } + + if (this.format == "json") + { + this.jsonOptions = provider.GetRequiredKeyedService("dsharpplus"); + + this.jsonOptions.TypeInfoResolverChain.Insert + ( + index: 0, + item: ConstructTypeInfoResolver(formats.Value) + ); + } + } + + /// + public TModel DeserializeModel + ( + ReadOnlySpan data + ) + where TModel : notnull + { + return this.format switch + { + "json" => JsonSerializer.Deserialize(data, this.jsonOptions)!, + _ => throw new InvalidOperationException($"The model could not be deserialized from {this.format}."), + }; + } + + /// + public void SerializeModel + ( + TModel model, + ArrayPoolBufferWriter target + ) + where TModel : notnull + { + switch (this.format) + { + case "json": + { + using Utf8JsonWriter writer = new(target); + JsonSerializer.Serialize(writer, model, this.jsonOptions!); + break; + } + default: + throw new InvalidOperationException($"The model could not be serialized to {this.format}."); + } + } + + private static IJsonTypeInfoResolver ConstructTypeInfoResolver + ( + SerializationOptions models + ) + { + DefaultJsonTypeInfoResolver resolver = new(); + + resolver.WithAddedModifier + ( + (typeinfo) => + { + if (models.InterfacesToConcrete.TryGetValue(typeinfo.Type, out Type? value)) + { + typeinfo.CreateObject = CreateObjectFactory(value); + } + } + ); + + return resolver; + } + + // for future reference, we might want to optimize the false branch. it's never hit for our own models, + // but it might hit for user-defined models and if there's a faster way of doing this we shouldn't penalize + // them + private static Func CreateObjectFactory + ( + Type type + ) + { + ConstructorInfo? ctor = type.GetConstructor(Type.EmptyTypes); + + if (ctor is not null) + { + DynamicMethod method = new + ( + name: $"factory-{type.Name}", + returnType: type, + parameterTypes: Type.EmptyTypes, + restrictedSkipVisibility: true + ); + + ILGenerator il = method.GetILGenerator(); + + il.Emit(OpCodes.Newobj, ctor); + il.Emit(OpCodes.Ret); + + return method.CreateDelegate>(); + } + else + { + return () => RuntimeHelpers.GetUninitializedObject(type); + } + } + + [LoggerMessage( + Level = LogLevel.Information, + Message = "Setting serialization format {Format} for library component {Component}." + )] + private static partial void LogFormatSpecified + ( + ILogger logger, + string format, + Type component + ); + + [LoggerMessage( + Level = LogLevel.Warning, + Message = "No serialization format for library component {Component} found, falling back to \"json\"." + )] + private static partial void LogFormatFallback + ( + ILogger logger, + Type component + ); +} From 32cd8901a4be4cf64d109d71b193a9917c5323a0 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Wed, 11 Oct 2023 21:31:05 +0200 Subject: [PATCH 153/323] update serialization registration --- .../JsonSerializerOptionsExtensions.cs | 357 ------------------ .../Extensions/ServiceCollectionExtensions.cs | 168 +++++++-- .../Resolvers/NullBooleanTypeInfoResolver.cs | 35 ++ .../Serialization/SerializationService.cs | 2 +- 4 files changed, 177 insertions(+), 385 deletions(-) delete mode 100644 src/core/DSharpPlus.Core.Models/Extensions/JsonSerializerOptionsExtensions.cs create mode 100644 src/core/DSharpPlus.Core.Models/Serialization/Resolvers/NullBooleanTypeInfoResolver.cs diff --git a/src/core/DSharpPlus.Core.Models/Extensions/JsonSerializerOptionsExtensions.cs b/src/core/DSharpPlus.Core.Models/Extensions/JsonSerializerOptionsExtensions.cs deleted file mode 100644 index 2cf5a4f3f5..0000000000 --- a/src/core/DSharpPlus.Core.Models/Extensions/JsonSerializerOptionsExtensions.cs +++ /dev/null @@ -1,357 +0,0 @@ -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -using System.Text.Json; -using System.Text.Json.Serialization.Metadata; - -using DSharpPlus.Core.Abstractions.Models; -using DSharpPlus.Core.Models.Converters; - -using Remora.Rest.Extensions; - -namespace DSharpPlus.Core.Models.Extensions; - -/// -/// Provides segmented registration for Discord API object serialization. -/// -internal static class JsonSerializerOptionsExtensions -{ - /// - /// Registers object converters for application commands. - /// - public static void RegisterApplicationCommands - ( - this JsonSerializerOptions options - ) - { - options.AddDataObjectConverter(); - options.AddDataObjectConverter(); - options.AddDataObjectConverter(); - options.AddDataObjectConverter(); - options.AddDataObjectConverter(); - options.AddDataObjectConverter(); - } - - /// - /// Registers object converters for applications. - /// - public static void RegisterApplications - ( - this JsonSerializerOptions options - ) - { - options.AddDataObjectConverter(); - options.AddDataObjectConverter(); - options.AddDataObjectConverter(); - } - - /// - /// Registers object converters for audit logs. - /// - public static void RegisterAuditLogs - ( - this JsonSerializerOptions options - ) - { - options.AddDataObjectConverter(); - options.AddDataObjectConverter(); - options.AddDataObjectConverter(); - } - - /// - /// Registers object converters for auto moderation. - /// - public static void RegisterAutoModeration - ( - this JsonSerializerOptions options - ) - { - options.AddDataObjectConverter(); - options.AddDataObjectConverter(); - options.AddDataObjectConverter(); - options.AddDataObjectConverter(); - options.AddDataObjectConverter(); - options.AddDataObjectConverter(); - options.AddDataObjectConverter(); - } - - /// - /// Registers object converters for channels. - /// - public static void RegisterChannels - ( - this JsonSerializerOptions options - ) - { - options.AddDataObjectConverter(); - options.AddDataObjectConverter(); - options.AddDataObjectConverter(); - options.AddDataObjectConverter(); - options.AddDataObjectConverter(); - options.AddDataObjectConverter(); - options.AddDataObjectConverter(); - options.AddDataObjectConverter(); - options.AddDataObjectConverter(); - options.AddDataObjectConverter(); - options.AddDataObjectConverter(); - options.AddDataObjectConverter(); - options.AddDataObjectConverter(); - options.AddDataObjectConverter(); - options.AddDataObjectConverter(); - options.AddDataObjectConverter(); - options.AddDataObjectConverter(); - options.AddDataObjectConverter(); - options.AddDataObjectConverter(); - options.AddDataObjectConverter(); - options.AddDataObjectConverter(); - options.AddDataObjectConverter(); - options.AddDataObjectConverter(); - options.AddDataObjectConverter(); - options.AddDataObjectConverter(); - options.AddDataObjectConverter(); - options.AddDataObjectConverter(); - } - - /// - /// Registers object converters for emojis. - /// - public static void RegisterEmojis - ( - this JsonSerializerOptions options - ) - { - options.AddDataObjectConverter(); - options.AddDataObjectConverter(); - } - - /// - /// Registers object converters for guilds. - /// - public static void RegisterGuilds - ( - this JsonSerializerOptions options - ) - { - options.AddDataObjectConverter(); - options.AddDataObjectConverter(); - options.AddDataObjectConverter(); - options.AddDataObjectConverter(); - options.AddDataObjectConverter(); - options.AddDataObjectConverter(); - options.AddDataObjectConverter(); - options.AddDataObjectConverter(); - options.AddDataObjectConverter(); - options.AddDataObjectConverter(); - options.AddDataObjectConverter(); - options.AddDataObjectConverter(); - options.AddDataObjectConverter(); - options.AddDataObjectConverter(); - options.AddDataObjectConverter(); - options.AddDataObjectConverter(); - - options.AddDataObjectConverter() - .WithPropertyConverter - ( - o => o.AvailableForPurchase, - new NullBooleanJsonConverter() - ) - .WithPropertyConverter - ( - o => o.GuildConnections, - new NullBooleanJsonConverter() - ) - .WithPropertyConverter - ( - o => o.PremiumSubscriber, - new NullBooleanJsonConverter() - ); - - options.TypeInfoResolverChain.Add - ( - new DefaultJsonTypeInfoResolver - { - Modifiers = - { - (JsonTypeInfo type) => - { - if (type.Type != typeof(RoleTags)) - { - return; - } - - foreach (JsonPropertyInfo property in type.Properties) - { - if (property.PropertyType == typeof(bool)) - { - property.IsRequired = false; - } - } - } - } - } - ); - - options.AddDataObjectConverter(); - options.AddDataObjectConverter(); - } - - /// - /// Registers object converters for guild templates. - /// - public static void RegisterGuildTemplates - ( - this JsonSerializerOptions options - ) - => options.AddDataObjectConverter(); - - /// - /// Registers object converters for interactions. - /// - public static void RegisterInteractions - ( - this JsonSerializerOptions options - ) - { - options.AddDataObjectConverter(); - options.AddDataObjectConverter(); - options.AddDataObjectConverter(); - options.AddDataObjectConverter(); - options.AddDataObjectConverter(); - options.AddDataObjectConverter(); - options.AddDataObjectConverter(); - options.AddDataObjectConverter(); - options.AddDataObjectConverter(); - options.AddDataObjectConverter(); - options.AddDataObjectConverter(); - } - - /// - /// Registers object converters for invites. - /// - public static void RegisterInvites - ( - this JsonSerializerOptions options - ) - { - options.AddDataObjectConverter(); - options.AddDataObjectConverter(); - } - - /// - /// Registers object converters for message components. - /// - public static void RegisterMessageComponents - ( - this JsonSerializerOptions options - ) - { - options.AddDataObjectConverter(); - options.AddDataObjectConverter(); - options.AddDataObjectConverter(); - options.AddDataObjectConverter(); - options.AddDataObjectConverter(); - options.AddDataObjectConverter(); - options.AddDataObjectConverter(); - options.AddDataObjectConverter(); - options.AddDataObjectConverter(); - } - - /// - /// Registers object converters for role connections. - /// - public static void RegisterRoleConnections - ( - this JsonSerializerOptions options - ) - => options.AddDataObjectConverter(); - - /// - /// Registers object converters for scheduled events. - /// - public static void RegisterScheduledEvents - ( - this JsonSerializerOptions options - ) - { - options.AddDataObjectConverter(); - options.AddDataObjectConverter(); - options.AddDataObjectConverter(); - } - - /// - /// Registers object converters for stage instances. - /// - public static void RegisterStageInstances - ( - this JsonSerializerOptions options - ) - { - options.AddDataObjectConverter(); - options.AddDataObjectConverter(); - } - - /// - /// Registers object converters for stickers. - /// - public static void RegisterStickers - ( - this JsonSerializerOptions options - ) - { - options.AddDataObjectConverter(); - options.AddDataObjectConverter(); - options.AddDataObjectConverter(); - options.AddDataObjectConverter(); - } - - /// - /// Registers object converters for teams. - /// - public static void RegisterTeams - ( - this JsonSerializerOptions options - ) - { - options.AddDataObjectConverter(); - options.AddDataObjectConverter(); - } - - /// - /// Registers object converters for users. - /// - public static void RegisterUsers - ( - this JsonSerializerOptions options - ) - { - options.AddDataObjectConverter(); - options.AddDataObjectConverter(); - options.AddDataObjectConverter(); - options.AddDataObjectConverter(); - } - - /// - /// Registers object converters for voice. - /// - public static void RegisterVoice - ( - this JsonSerializerOptions options - ) - { - options.AddDataObjectConverter(); - options.AddDataObjectConverter(); - } - - /// - /// Registers object converters for webhooks. - /// - public static void RegisterWebhooks - ( - this JsonSerializerOptions options - ) - { - options.AddDataObjectConverter(); - options.AddDataObjectConverter(); - } -} diff --git a/src/core/DSharpPlus.Core.Models/Extensions/ServiceCollectionExtensions.cs b/src/core/DSharpPlus.Core.Models/Extensions/ServiceCollectionExtensions.cs index 97ea24502e..f8b20da541 100644 --- a/src/core/DSharpPlus.Core.Models/Extensions/ServiceCollectionExtensions.cs +++ b/src/core/DSharpPlus.Core.Models/Extensions/ServiceCollectionExtensions.cs @@ -4,12 +4,13 @@ using System.Text.Json; -using DSharpPlus.Core.Models.Converters; +using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Core.Models.Serialization.Converters; +using DSharpPlus.Core.Models.Serialization.Resolvers; +using DSharpPlus.Serialization; using Microsoft.Extensions.DependencyInjection; -using Remora.Rest.Json; - namespace DSharpPlus.Core.Models.Extensions; /// @@ -17,8 +18,6 @@ namespace DSharpPlus.Core.Models.Extensions; /// public static class ServiceCollectionExtensions { - const ulong DiscordEpoch = 1420070400000ul; - /// /// Registers converters for Discord's API models. /// @@ -28,7 +27,7 @@ public static class ServiceCollectionExtensions public static IServiceCollection RegisterDiscordModelSerialization ( this IServiceCollection services, - string? name = "DSharpPlus" + string? name = "dsharpplus" ) { services.Configure @@ -43,27 +42,142 @@ public static IServiceCollection RegisterDiscordModelSerialization options.Converters.Add(new DiscordPermissionConverter()); options.Converters.Add(new MessageComponentConverter()); - options.RegisterApplicationCommands(); - options.RegisterApplications(); - options.RegisterAuditLogs(); - options.RegisterAutoModeration(); - options.RegisterChannels(); - options.RegisterEmojis(); - options.RegisterGuilds(); - options.RegisterGuildTemplates(); - options.RegisterInteractions(); - options.RegisterInvites(); - options.RegisterMessageComponents(); - options.RegisterRoleConnections(); - options.RegisterScheduledEvents(); - options.RegisterStageInstances(); - options.RegisterStickers(); - options.RegisterTeams(); - options.RegisterUsers(); - options.RegisterVoice(); - options.RegisterWebhooks(); - - options.Converters.Insert(0, new SnowflakeConverter(DiscordEpoch)); + options.TypeInfoResolverChain.Add(OptionalTypeInfoResolver.Default); + options.TypeInfoResolverChain.Add(NullBooleanTypeInfoResolver.Default); + } + ); + + services.Configure + ( + options => + { + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + + options.AddModel(); + options.AddModel(); + options.AddModel(); + + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + + options.AddModel(); + options.AddModel(); + + options.AddModel(); + + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + + options.AddModel(); + + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + + options.AddModel(); + options.AddModel(); + + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + + options.AddModel(); + + options.AddModel(); + options.AddModel(); + options.AddModel(); + + options.AddModel(); + + options.AddModel(); + options.AddModel(); + + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + + options.AddModel(); + options.AddModel(); + + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + + options.AddModel(); + options.AddModel(); + + options.AddModel(); + options.AddModel(); } ); diff --git a/src/core/DSharpPlus.Core.Models/Serialization/Resolvers/NullBooleanTypeInfoResolver.cs b/src/core/DSharpPlus.Core.Models/Serialization/Resolvers/NullBooleanTypeInfoResolver.cs new file mode 100644 index 0000000000..96eab10605 --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/Serialization/Resolvers/NullBooleanTypeInfoResolver.cs @@ -0,0 +1,35 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Text.Json.Serialization.Metadata; + +using DSharpPlus.Core.Models.Serialization.Converters; + +namespace DSharpPlus.Core.Models.Serialization.Resolvers; + +public static class NullBooleanTypeInfoResolver +{ + public static IJsonTypeInfoResolver Default { get; } = new DefaultJsonTypeInfoResolver + { + Modifiers = + { + (type) => + { + if (type.Type != typeof(RoleTags)) + { + return; + } + + foreach (JsonPropertyInfo property in type.Properties) + { + if (property.PropertyType == typeof(bool)) + { + property.IsRequired = false; + property.CustomConverter = new NullBooleanJsonConverter(); + } + } + } + } + }; +} diff --git a/src/core/DSharpPlus.Shared/Serialization/SerializationService.cs b/src/core/DSharpPlus.Shared/Serialization/SerializationService.cs index 656b37a2b3..49e544a7a7 100644 --- a/src/core/DSharpPlus.Shared/Serialization/SerializationService.cs +++ b/src/core/DSharpPlus.Shared/Serialization/SerializationService.cs @@ -52,7 +52,7 @@ IServiceProvider provider if (this.format == "json") { - this.jsonOptions = provider.GetRequiredKeyedService("dsharpplus"); + this.jsonOptions = provider.GetRequiredService>().Get("dsharpplus"); this.jsonOptions.TypeInfoResolverChain.Insert ( From 5e49dc8a01247331364dccec3494255643e18aca Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Fri, 13 Oct 2023 17:56:37 +0200 Subject: [PATCH 154/323] actually make everything build --- Directory.Packages.props | 19 +++++----- .../Serialization/SerializationService.cs | 2 +- .../Converters/AuditLogChangeTests.cs | 37 +++++++++++-------- .../DSharpPlus.Core.Models.Tests.csproj | 1 + 4 files changed, 33 insertions(+), 26 deletions(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index 81be77e244..c6552efb9c 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -1,22 +1,23 @@ - - + + - + + - + - - - + + + - - + + \ No newline at end of file diff --git a/src/core/DSharpPlus.Shared/Serialization/SerializationService.cs b/src/core/DSharpPlus.Shared/Serialization/SerializationService.cs index 49e544a7a7..d44f0aee71 100644 --- a/src/core/DSharpPlus.Shared/Serialization/SerializationService.cs +++ b/src/core/DSharpPlus.Shared/Serialization/SerializationService.cs @@ -97,7 +97,7 @@ ArrayPoolBufferWriter target } } - private static IJsonTypeInfoResolver ConstructTypeInfoResolver + private static DefaultJsonTypeInfoResolver ConstructTypeInfoResolver ( SerializationOptions models ) diff --git a/tests/core/DSharpPlus.Core.Models.Tests/Converters/AuditLogChangeTests.cs b/tests/core/DSharpPlus.Core.Models.Tests/Converters/AuditLogChangeTests.cs index d3a172a310..ee726ba7d6 100644 --- a/tests/core/DSharpPlus.Core.Models.Tests/Converters/AuditLogChangeTests.cs +++ b/tests/core/DSharpPlus.Core.Models.Tests/Converters/AuditLogChangeTests.cs @@ -3,13 +3,12 @@ // file, You can obtain one at https://mozilla.org/MPL/2.0/. using System; -using System.Text.Json; using DSharpPlus.Core.Abstractions.Models; using DSharpPlus.Core.Models.Extensions; +using DSharpPlus.Serialization; using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Options; using Xunit; @@ -17,55 +16,61 @@ namespace DSharpPlus.Core.Models.Tests.Converters; public class AuditLogChangeTests { - private readonly JsonSerializerOptions options; + private readonly ISerializationService serializer; public AuditLogChangeTests() { IServiceCollection services = new ServiceCollection(); services.RegisterDiscordModelSerialization(); + services.Configure + ( + options => options.SetFormat() + ); + + services.AddSingleton(typeof(ISerializationService<>), typeof(SerializationService<>)); IServiceProvider provider = services.BuildServiceProvider(); - this.options = provider.GetRequiredService>().Get("DSharpPlus"); + this.serializer = provider.GetRequiredService>(); } - private const string IntPayload = + private static readonly byte[] IntPayload = """ { "key": "$test", "new_value": 17, "old_value": 83 } - """; + """u8.ToArray(); - private const string StringPayload = + private static readonly byte[] StringPayload = """ { "key": "$test", "new_value": "this is the new value", "old_value": "this was the old value" } - """; + """u8.ToArray(); - private const string NewValueMissingPayload = + private static readonly byte[] NewValueMissingPayload = """ { "key": "$test", "old_value": "this was the old value" } - """; + """u8.ToArray(); - private const string OldValueMissingPayload = + private static readonly byte[] OldValueMissingPayload = """ { "key": "$test", "new_value": "this is the new value" } - """; + """u8.ToArray(); [Fact] public void TestIntegerPayload() { - IAuditLogChange change = JsonSerializer.Deserialize(IntPayload, this.options)!; + IAuditLogChange change = this.serializer.DeserializeModel(IntPayload); Assert.True(change.NewValue.HasValue); Assert.True(change.OldValue.HasValue); @@ -76,7 +81,7 @@ public void TestIntegerPayload() [Fact] public void TestStringPayload() { - IAuditLogChange change = JsonSerializer.Deserialize(StringPayload, this.options)!; + IAuditLogChange change = this.serializer.DeserializeModel(StringPayload); Assert.True(change.NewValue.HasValue); Assert.True(change.OldValue.HasValue); @@ -87,7 +92,7 @@ public void TestStringPayload() [Fact] public void TestNewValueMissing() { - IAuditLogChange change = JsonSerializer.Deserialize(NewValueMissingPayload, this.options)!; + IAuditLogChange change = this.serializer.DeserializeModel(NewValueMissingPayload); Assert.False(change.NewValue.HasValue); Assert.True(change.OldValue.HasValue); @@ -98,7 +103,7 @@ public void TestNewValueMissing() [Fact] public void TestOldValueMissing() { - IAuditLogChange change = JsonSerializer.Deserialize(OldValueMissingPayload, this.options)!; + IAuditLogChange change = this.serializer.DeserializeModel(OldValueMissingPayload); Assert.True(change.NewValue.HasValue); Assert.False(change.OldValue.HasValue); diff --git a/tests/core/DSharpPlus.Core.Models.Tests/DSharpPlus.Core.Models.Tests.csproj b/tests/core/DSharpPlus.Core.Models.Tests/DSharpPlus.Core.Models.Tests.csproj index 57aed8b89a..bd97500e4f 100644 --- a/tests/core/DSharpPlus.Core.Models.Tests/DSharpPlus.Core.Models.Tests.csproj +++ b/tests/core/DSharpPlus.Core.Models.Tests/DSharpPlus.Core.Models.Tests.csproj @@ -9,6 +9,7 @@ + From 45eca7bfe75b9376e2d6dff9105b77ccb40c7c13 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Fri, 13 Oct 2023 18:00:56 +0200 Subject: [PATCH 155/323] null-log in the test --- Directory.Packages.props | 1 + .../Converters/AuditLogChangeTests.cs | 7 +++++++ .../DSharpPlus.Core.Models.Tests.csproj | 1 + 3 files changed, 9 insertions(+) diff --git a/Directory.Packages.props b/Directory.Packages.props index c6552efb9c..10af9e679e 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -7,6 +7,7 @@ + diff --git a/tests/core/DSharpPlus.Core.Models.Tests/Converters/AuditLogChangeTests.cs b/tests/core/DSharpPlus.Core.Models.Tests/Converters/AuditLogChangeTests.cs index ee726ba7d6..a0e4151d3d 100644 --- a/tests/core/DSharpPlus.Core.Models.Tests/Converters/AuditLogChangeTests.cs +++ b/tests/core/DSharpPlus.Core.Models.Tests/Converters/AuditLogChangeTests.cs @@ -9,6 +9,8 @@ using DSharpPlus.Serialization; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging.Abstractions; using Xunit; @@ -27,6 +29,11 @@ public AuditLogChangeTests() options => options.SetFormat() ); + services.AddLogging + ( + builder => builder.ClearProviders().AddProvider(NullLoggerProvider.Instance) + ); + services.AddSingleton(typeof(ISerializationService<>), typeof(SerializationService<>)); IServiceProvider provider = services.BuildServiceProvider(); diff --git a/tests/core/DSharpPlus.Core.Models.Tests/DSharpPlus.Core.Models.Tests.csproj b/tests/core/DSharpPlus.Core.Models.Tests/DSharpPlus.Core.Models.Tests.csproj index bd97500e4f..0d93d3427e 100644 --- a/tests/core/DSharpPlus.Core.Models.Tests/DSharpPlus.Core.Models.Tests.csproj +++ b/tests/core/DSharpPlus.Core.Models.Tests/DSharpPlus.Core.Models.Tests.csproj @@ -10,6 +10,7 @@ + From 53d4efab82a178c638b0728624a8abf620526aee Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Fri, 13 Oct 2023 18:02:43 +0200 Subject: [PATCH 156/323] remove etf from the always-available options --- .../DSharpPlus.Shared/Serialization/SerializationOptions.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/core/DSharpPlus.Shared/Serialization/SerializationOptions.cs b/src/core/DSharpPlus.Shared/Serialization/SerializationOptions.cs index bb1fdee251..90804ba7b9 100644 --- a/src/core/DSharpPlus.Shared/Serialization/SerializationOptions.cs +++ b/src/core/DSharpPlus.Shared/Serialization/SerializationOptions.cs @@ -14,13 +14,12 @@ namespace DSharpPlus.Serialization; public sealed class SerializationOptions { public const string Json = "json"; - public const string Etf = "etf"; /// /// Well-known formats: /// - /// "json", on top of System.Text.Json - /// "etf", on top of ETFKit + /// "json", on top of System.Text.Json. + /// "etf", on top of ETFKit, not installed by default. /// /// internal Dictionary Formats { get; } = new(2); From 5b1368c67445c66b037a1bff74c7be25c460f816 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sat, 14 Oct 2023 20:24:33 +0200 Subject: [PATCH 157/323] target the correct type for null boolean resolvers --- .../Serialization/Resolvers/NullBooleanTypeInfoResolver.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/core/DSharpPlus.Core.Models/Serialization/Resolvers/NullBooleanTypeInfoResolver.cs b/src/core/DSharpPlus.Core.Models/Serialization/Resolvers/NullBooleanTypeInfoResolver.cs index 96eab10605..7bedc9bbe2 100644 --- a/src/core/DSharpPlus.Core.Models/Serialization/Resolvers/NullBooleanTypeInfoResolver.cs +++ b/src/core/DSharpPlus.Core.Models/Serialization/Resolvers/NullBooleanTypeInfoResolver.cs @@ -4,6 +4,7 @@ using System.Text.Json.Serialization.Metadata; +using DSharpPlus.Core.Abstractions.Models; using DSharpPlus.Core.Models.Serialization.Converters; namespace DSharpPlus.Core.Models.Serialization.Resolvers; @@ -16,7 +17,7 @@ public static class NullBooleanTypeInfoResolver { (type) => { - if (type.Type != typeof(RoleTags)) + if (type.Type != typeof(IRoleTags)) { return; } From 99d31a2f500b95e9c62e06bec4b818d5dbbbf5fd Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sat, 14 Oct 2023 20:39:32 +0200 Subject: [PATCH 158/323] optional converter --- .../Extensions/ServiceCollectionExtensions.cs | 1 + .../Converters/OptionalConverter.cs | 33 +++++++++++++++++++ .../Converters/OptionalConverterFactory.cs | 30 +++++++++++++++++ src/core/DSharpPlus.Shared/Optional`1.cs | 18 +++++----- 4 files changed, 73 insertions(+), 9 deletions(-) create mode 100644 src/core/DSharpPlus.Core.Models/Serialization/Converters/OptionalConverter.cs create mode 100644 src/core/DSharpPlus.Core.Models/Serialization/Converters/OptionalConverterFactory.cs diff --git a/src/core/DSharpPlus.Core.Models/Extensions/ServiceCollectionExtensions.cs b/src/core/DSharpPlus.Core.Models/Extensions/ServiceCollectionExtensions.cs index f8b20da541..8179ed44cc 100644 --- a/src/core/DSharpPlus.Core.Models/Extensions/ServiceCollectionExtensions.cs +++ b/src/core/DSharpPlus.Core.Models/Extensions/ServiceCollectionExtensions.cs @@ -37,6 +37,7 @@ public static IServiceCollection RegisterDiscordModelSerialization { options.PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower; + options.Converters.Add(new OptionalConverterFactory()); options.Converters.Add(new AuditLogChangeConverter()); options.Converters.Add(new AutoModerationActionConverter()); options.Converters.Add(new DiscordPermissionConverter()); diff --git a/src/core/DSharpPlus.Core.Models/Serialization/Converters/OptionalConverter.cs b/src/core/DSharpPlus.Core.Models/Serialization/Converters/OptionalConverter.cs new file mode 100644 index 0000000000..10ef490241 --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/Serialization/Converters/OptionalConverter.cs @@ -0,0 +1,33 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; +using System.Text.Json; +using System.Text.Json.Serialization; + +namespace DSharpPlus.Core.Models.Serialization.Converters; + +/// +/// A converter for . +/// +public sealed class OptionalConverter : JsonConverter> +{ + public override Optional Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + => new(JsonSerializer.Deserialize(ref reader, options)); + + public override void Write + ( + Utf8JsonWriter writer, + Optional value, + JsonSerializerOptions options + ) + { + if (!value.HasValue) + { + throw new ArgumentException("Serializing an empty optional is not allowed."); + } + + JsonSerializer.Serialize(writer, value.Value, options); + } +} diff --git a/src/core/DSharpPlus.Core.Models/Serialization/Converters/OptionalConverterFactory.cs b/src/core/DSharpPlus.Core.Models/Serialization/Converters/OptionalConverterFactory.cs new file mode 100644 index 0000000000..9beca654ba --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/Serialization/Converters/OptionalConverterFactory.cs @@ -0,0 +1,30 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; +using System.Text.Json; +using System.Text.Json.Serialization; + +namespace DSharpPlus.Core.Models.Serialization.Converters; + +/// +/// A converter factory for . +/// +public class OptionalConverterFactory : JsonConverterFactory +{ + public override bool CanConvert(Type typeToConvert) + => typeToConvert.IsConstructedGenericType && typeToConvert.GetGenericTypeDefinition() == typeof(Optional<>); + + public override JsonConverter? CreateConverter + ( + Type typeToConvert, + JsonSerializerOptions options + ) + { + return (JsonConverter)typeof(OptionalConverter<>) + .MakeGenericType(typeToConvert.GetGenericArguments()) + .GetConstructor(Type.EmptyTypes)! + .Invoke(null)!; + } +} diff --git a/src/core/DSharpPlus.Shared/Optional`1.cs b/src/core/DSharpPlus.Shared/Optional`1.cs index 8cd12a9da6..585355e907 100644 --- a/src/core/DSharpPlus.Shared/Optional`1.cs +++ b/src/core/DSharpPlus.Shared/Optional`1.cs @@ -13,7 +13,7 @@ namespace DSharpPlus; /// The type of the enclosed value. public readonly record struct Optional : IOptional { - private readonly T value; + private readonly T? value; /// public bool HasValue { get; } @@ -21,7 +21,7 @@ namespace DSharpPlus; /// /// Retrieves the underlying value, if present. /// - public T Value + public T? Value { get { @@ -36,7 +36,7 @@ public T Value public Optional ( - T value + T? value ) { this.HasValue = true; @@ -46,7 +46,7 @@ T value /// /// Returns the contained value if one is present, or throws the given exception if none is present. /// - public readonly T Expect + public readonly T? Expect ( Func exception ) @@ -62,7 +62,7 @@ Func exception /// /// Returns the contained value if present, or the provided value if not present. /// - public readonly T Or(T value) + public readonly T? Or(T value) => this.HasValue ? this.value : value; /// @@ -77,7 +77,7 @@ public readonly T Or(T value) /// public readonly Optional Map ( - Func transformation + Func transformation ) { return this.HasValue @@ -89,10 +89,10 @@ Func transformation /// Transforms the value of the given optional to , returning /// if there was no value present. /// - public readonly TOther MapOr + public readonly TOther? MapOr ( - Func transformation, - TOther value + Func transformation, + TOther? value ) { return this.HasValue From bc263c36701e11d20b357a272286a9ebaabcf002 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sat, 14 Oct 2023 20:42:41 +0200 Subject: [PATCH 159/323] snowflake converter --- .../Extensions/ServiceCollectionExtensions.cs | 1 + .../Converters/SnowflakeConverter.cs | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 src/core/DSharpPlus.Core.Models/Serialization/Converters/SnowflakeConverter.cs diff --git a/src/core/DSharpPlus.Core.Models/Extensions/ServiceCollectionExtensions.cs b/src/core/DSharpPlus.Core.Models/Extensions/ServiceCollectionExtensions.cs index 8179ed44cc..3c2a45addc 100644 --- a/src/core/DSharpPlus.Core.Models/Extensions/ServiceCollectionExtensions.cs +++ b/src/core/DSharpPlus.Core.Models/Extensions/ServiceCollectionExtensions.cs @@ -38,6 +38,7 @@ public static IServiceCollection RegisterDiscordModelSerialization options.PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower; options.Converters.Add(new OptionalConverterFactory()); + options.Converters.Add(new SnowflakeConverter()); options.Converters.Add(new AuditLogChangeConverter()); options.Converters.Add(new AutoModerationActionConverter()); options.Converters.Add(new DiscordPermissionConverter()); diff --git a/src/core/DSharpPlus.Core.Models/Serialization/Converters/SnowflakeConverter.cs b/src/core/DSharpPlus.Core.Models/Serialization/Converters/SnowflakeConverter.cs new file mode 100644 index 0000000000..67a554a7a7 --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/Serialization/Converters/SnowflakeConverter.cs @@ -0,0 +1,18 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; +using System.Text.Json; +using System.Text.Json.Serialization; + +namespace DSharpPlus.Core.Models.Serialization.Converters; + +public sealed class SnowflakeConverter : JsonConverter +{ + public override Snowflake Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + => new(JsonSerializer.Deserialize(ref reader, options)); + + public override void Write(Utf8JsonWriter writer, Snowflake value, JsonSerializerOptions options) + => writer.WriteNumberValue(value.Value); +} From f3c5e6d6a32c9bae531eab447209ef416d20cdd2 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Mon, 16 Oct 2023 21:16:33 +0200 Subject: [PATCH 160/323] tragically, the type info hack breaks customizability --- .../Serialization/RedirectingConverter.cs | 44 +++++++++++ .../Serialization/SerializationService.cs | 77 ++++--------------- 2 files changed, 58 insertions(+), 63 deletions(-) create mode 100644 src/core/DSharpPlus.Shared/Serialization/RedirectingConverter.cs diff --git a/src/core/DSharpPlus.Shared/Serialization/RedirectingConverter.cs b/src/core/DSharpPlus.Shared/Serialization/RedirectingConverter.cs new file mode 100644 index 0000000000..fae09d99c7 --- /dev/null +++ b/src/core/DSharpPlus.Shared/Serialization/RedirectingConverter.cs @@ -0,0 +1,44 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; +using System.Text.Json; +using System.Text.Json.Serialization; +using System.Text.Json.Serialization.Metadata; + +namespace DSharpPlus.Serialization; + +internal sealed class RedirectingConverter : JsonConverter + where TModel : TInterface +{ + public override TInterface? Read + ( + ref Utf8JsonReader reader, + Type typeToConvert, + JsonSerializerOptions options + ) + { + if (!options.TryGetTypeInfo(typeof(TModel), out JsonTypeInfo? typeInfo)) + { + typeInfo = options.GetTypeInfo(typeof(TInterface)); + } + + return (TInterface?)JsonSerializer.Deserialize(ref reader, typeInfo); + } + + public override void Write + ( + Utf8JsonWriter writer, + TInterface value, + JsonSerializerOptions options + ) + { + if (!options.TryGetTypeInfo(value!.GetType(), out JsonTypeInfo? typeInfo)) + { + typeInfo = options.GetTypeInfo(typeof(TInterface)); + } + + JsonSerializer.Serialize(writer, value, typeInfo); + } +} diff --git a/src/core/DSharpPlus.Shared/Serialization/SerializationService.cs b/src/core/DSharpPlus.Shared/Serialization/SerializationService.cs index d44f0aee71..3ce78a9e44 100644 --- a/src/core/DSharpPlus.Shared/Serialization/SerializationService.cs +++ b/src/core/DSharpPlus.Shared/Serialization/SerializationService.cs @@ -3,12 +3,10 @@ // file, You can obtain one at https://mozilla.org/MPL/2.0/. using System; +using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; -using System.Reflection; -using System.Reflection.Emit; -using System.Runtime.CompilerServices; using System.Text.Json; -using System.Text.Json.Serialization.Metadata; +using System.Text.Json.Serialization; using CommunityToolkit.HighPerformance.Buffers; @@ -54,11 +52,18 @@ IServiceProvider provider { this.jsonOptions = provider.GetRequiredService>().Get("dsharpplus"); - this.jsonOptions.TypeInfoResolverChain.Insert - ( - index: 0, - item: ConstructTypeInfoResolver(formats.Value) - ); + foreach (KeyValuePair map in formats.Value.InterfacesToConcrete) + { + this.jsonOptions.Converters.Add + ( + (JsonConverter)typeof(RedirectingConverter<,>) + .MakeGenericType(map.Key, map.Value) + .GetConstructor(Type.EmptyTypes)! + .Invoke(null)! + ); + } + + this.jsonOptions.MakeReadOnly(); } } @@ -97,60 +102,6 @@ ArrayPoolBufferWriter target } } - private static DefaultJsonTypeInfoResolver ConstructTypeInfoResolver - ( - SerializationOptions models - ) - { - DefaultJsonTypeInfoResolver resolver = new(); - - resolver.WithAddedModifier - ( - (typeinfo) => - { - if (models.InterfacesToConcrete.TryGetValue(typeinfo.Type, out Type? value)) - { - typeinfo.CreateObject = CreateObjectFactory(value); - } - } - ); - - return resolver; - } - - // for future reference, we might want to optimize the false branch. it's never hit for our own models, - // but it might hit for user-defined models and if there's a faster way of doing this we shouldn't penalize - // them - private static Func CreateObjectFactory - ( - Type type - ) - { - ConstructorInfo? ctor = type.GetConstructor(Type.EmptyTypes); - - if (ctor is not null) - { - DynamicMethod method = new - ( - name: $"factory-{type.Name}", - returnType: type, - parameterTypes: Type.EmptyTypes, - restrictedSkipVisibility: true - ); - - ILGenerator il = method.GetILGenerator(); - - il.Emit(OpCodes.Newobj, ctor); - il.Emit(OpCodes.Ret); - - return method.CreateDelegate>(); - } - else - { - return () => RuntimeHelpers.GetUninitializedObject(type); - } - } - [LoggerMessage( Level = LogLevel.Information, Message = "Setting serialization format {Format} for library component {Component}." From 8e8a4b0684f1fc07890e62d94740a71c7e4f67b3 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Fri, 20 Oct 2023 14:34:47 +0200 Subject: [PATCH 161/323] commit crimes against humanity and civilization this OneOfConverter is a direct violation of Allied Control Council Law No. 10, Article II, Section 1c --- DSharpPlus.sln | 4 +- .../Extensions/ServiceCollectionExtensions.cs | 2 + .../Converters/OneOfConverter.cs | 159 ++++++++++++++++++ .../Converters/OneOfConverterFactory.cs | 31 ++++ .../Program.cs | 6 +- 5 files changed, 197 insertions(+), 5 deletions(-) create mode 100644 src/core/DSharpPlus.Core.Models/Serialization/Converters/OneOfConverter.cs create mode 100644 src/core/DSharpPlus.Core.Models/Serialization/Converters/OneOfConverterFactory.cs diff --git a/DSharpPlus.sln b/DSharpPlus.sln index f563b2d3de..d096f56c3e 100644 --- a/DSharpPlus.sln +++ b/DSharpPlus.sln @@ -30,9 +30,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DSharpPlus.SourceGenerators EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DSharpPlus.Core.Models.Tests", "tests\core\DSharpPlus.Core.Models.Tests\DSharpPlus.Core.Models.Tests.csproj", "{9F25D892-3CB0-4D47-B67D-D3FFFADC03E0}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DSharpPlus.Core.Abstractions.Rest", "src\core\DSharpPlus.Core.Abstractions.Rest\DSharpPlus.Core.Abstractions.Rest.csproj", "{CD440954-E19A-4E94-A217-CCC1DC4AF095}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DSharpPlus.Core.Abstractions.Rest", "src\core\DSharpPlus.Core.Abstractions.Rest\DSharpPlus.Core.Abstractions.Rest.csproj", "{CD440954-E19A-4E94-A217-CCC1DC4AF095}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DSharpPlus.Core.Rest", "src\core\DSharpPlus.Core.Rest\DSharpPlus.Core.Rest.csproj", "{9CEC3D27-9014-48B6-910F-D25233BF8C44}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DSharpPlus.Core.Rest", "src\core\DSharpPlus.Core.Rest\DSharpPlus.Core.Rest.csproj", "{9CEC3D27-9014-48B6-910F-D25233BF8C44}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/src/core/DSharpPlus.Core.Models/Extensions/ServiceCollectionExtensions.cs b/src/core/DSharpPlus.Core.Models/Extensions/ServiceCollectionExtensions.cs index 3c2a45addc..e8eb0ad1f7 100644 --- a/src/core/DSharpPlus.Core.Models/Extensions/ServiceCollectionExtensions.cs +++ b/src/core/DSharpPlus.Core.Models/Extensions/ServiceCollectionExtensions.cs @@ -39,6 +39,8 @@ public static IServiceCollection RegisterDiscordModelSerialization options.Converters.Add(new OptionalConverterFactory()); options.Converters.Add(new SnowflakeConverter()); + options.Converters.Add(new OneOfConverterFactory()); + options.Converters.Add(new AuditLogChangeConverter()); options.Converters.Add(new AutoModerationActionConverter()); options.Converters.Add(new DiscordPermissionConverter()); diff --git a/src/core/DSharpPlus.Core.Models/Serialization/Converters/OneOfConverter.cs b/src/core/DSharpPlus.Core.Models/Serialization/Converters/OneOfConverter.cs new file mode 100644 index 0000000000..508ae4e68b --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/Serialization/Converters/OneOfConverter.cs @@ -0,0 +1,159 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +#pragma warning disable CA1810 + +using System; +using System.Collections; +using System.Collections.Frozen; +using System.Collections.Generic; +using System.Linq; +using System.Numerics; +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Text.Json; +using System.Text.Json.Serialization; + +using OneOf; + +namespace DSharpPlus.Core.Models.Serialization.Converters; + +/// +/// Provides a mechanicsm for serializing and deserializing objects. +/// +public sealed class OneOfConverter : JsonConverter + where TUnion : IOneOf +{ + // using type handles turns out to be marginally faster than Type, but it doesn't fundamentally matter + // and this might well change in future .NET versions, in which case this code should use Type for ease + // of reading + private static readonly FrozenDictionary> constructionMethods; + + // we cache ordered types by the jsontokentype + private static readonly FrozenDictionary> orderedUnion; + + // this cctor is *extremely* expensive and creates quite a lot of cached data. we might want to break this + // up a bit more, or use specialized converters for smaller OneOfs that don't need all this elaborate + // ordering ceremony because they only have a select few valid orders anyways. + static OneOfConverter() + { + Type[] unionTypes = typeof(TUnion).GetGenericArguments(); + + // order of type priority: + // 1. snowflake + // 2. integer primitives (is assignable to INumber but not to IFloatingPoint, is struct) + // 3. float primitives (assignable to INumber and IFloatingPoint, is struct) + // 4. other types that aren't models + // 5. models + FrozenSet baselineOrderedUnionTypes = unionTypes + .OrderByDescending(t => t == typeof(Snowflake) || t == typeof(Snowflake?)) + .ThenByDescending(t => t.IsAssignableTo(typeof(INumber<>).MakeGenericType(t)) && t.IsValueType) + .ThenBy(t => t.IsAssignableTo(typeof(IFloatingPoint<>).MakeGenericType(t))) + .ThenBy(t => t.FullName!.StartsWith("DSharpPlus", StringComparison.InvariantCulture)) + .ToFrozenSet(); + + // construction methods + Dictionary> methods = []; + + for (int i = 0; i < unionTypes.Length; i++) + { + MethodInfo? method = typeof(TUnion).GetMethod($"FromT{i}")!; + + Func @delegate = Unsafe.As>(method.CreateDelegate(unionTypes[i])); + methods.Add(unionTypes[i].TypeHandle.Value, @delegate); + } + + constructionMethods = methods.ToFrozenDictionary(); + + // priority + Dictionary> priorities = new() + { + // our baseline is already optimized for numbers + [JsonTokenType.Number] = baselineOrderedUnionTypes + }; + + // nullability + priorities.Add + ( + JsonTokenType.Null, + baselineOrderedUnionTypes.OrderByDescending + ( + type => type.GetGenericTypeDefinition() == typeof(Nullable<>) || !type.IsValueType + ) + .ToFrozenSet() + ); + + // booleans + FrozenSet booleanPriority = baselineOrderedUnionTypes.OrderByDescending + ( + type => type == typeof(bool) || type == typeof(bool?) + ) + .ToFrozenSet(); + + priorities.Add(JsonTokenType.True, booleanPriority); + priorities.Add(JsonTokenType.False, booleanPriority); + + // string + priorities.Add + ( + JsonTokenType.String, + baselineOrderedUnionTypes.OrderByDescending + ( + type => type == typeof(string) + ) + .ToFrozenSet() + ); + + // collections + priorities.Add + ( + JsonTokenType.StartArray, + // we can make our life easier here by seeing whether we're assignable to non-generic IEnumerable + baselineOrderedUnionTypes.OrderByDescending(type => type.IsAssignableTo(typeof(IEnumerable))) + .ToFrozenSet() + ); + + // start object + priorities.Add + ( + JsonTokenType.StartObject, + baselineOrderedUnionTypes.OrderByDescending(type => !type.IsPrimitive) + .ThenByDescending(type => type != typeof(Snowflake) && type != typeof(Snowflake?)) + .ThenByDescending(type => type.GetGenericTypeDefinition() != typeof(Nullable<>)) + .ToFrozenSet() + ); + + orderedUnion = priorities.ToFrozenDictionary(); + } + + public override TUnion? Read + ( + ref Utf8JsonReader reader, + Type typeToConvert, + JsonSerializerOptions options + ) + { + foreach (Type type in orderedUnion[reader.TokenType]) + { + object value; + + try + { + value = JsonSerializer.Deserialize(ref reader, type, options)!; + } + // it's tragic we have to eat an exception here, but, try again + catch (JsonException) + { + continue; + } + + return (TUnion)constructionMethods[type.TypeHandle.Value](value); + } + + throw new JsonException("The value could not be parsed into the given union."); + } + + public override void Write(Utf8JsonWriter writer, TUnion value, JsonSerializerOptions options) + => JsonSerializer.Serialize(writer, value.Value, typeof(TUnion).GetGenericArguments()[value.Index], options); +} diff --git a/src/core/DSharpPlus.Core.Models/Serialization/Converters/OneOfConverterFactory.cs b/src/core/DSharpPlus.Core.Models/Serialization/Converters/OneOfConverterFactory.cs new file mode 100644 index 0000000000..8b3915eb87 --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/Serialization/Converters/OneOfConverterFactory.cs @@ -0,0 +1,31 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; +using System.Text.Json; +using System.Text.Json.Serialization; + +using OneOf; + +namespace DSharpPlus.Core.Models.Serialization.Converters; + +/// +/// Provides a factory for OneOf converters. +/// +public sealed class OneOfConverterFactory : JsonConverterFactory +{ + public override bool CanConvert(Type typeToConvert) + => typeToConvert.IsGenericType && typeToConvert.IsAssignableTo(typeof(IOneOf)); + + public override JsonConverter? CreateConverter + ( + Type typeToConvert, + JsonSerializerOptions options + ) + { + Type concreteConverter = typeof(OneOfConverter<>).MakeGenericType(typeToConvert.GetGenericArguments()); + + return (JsonConverter)Activator.CreateInstance(concreteConverter)!; + } +} diff --git a/tools/generators/Tools.Generators.GenerateConcreteObjects/Program.cs b/tools/generators/Tools.Generators.GenerateConcreteObjects/Program.cs index 5a2a7957d3..92bf6d1f65 100644 --- a/tools/generators/Tools.Generators.GenerateConcreteObjects/Program.cs +++ b/tools/generators/Tools.Generators.GenerateConcreteObjects/Program.cs @@ -120,7 +120,7 @@ Deleting counterparts to removed files... FileInfo file = new(path); string fullPath = file.FullName.Replace('\\', '/'); - int index = fullPath.LastIndexOf("/"); + int index = fullPath.LastIndexOf('/'); string deletePath = fullPath.Remove(index + 1, 1).Replace(input, output); AnsiConsole.MarkupLine @@ -164,7 +164,7 @@ Deleting counterparts to removed files... } ); - List emittedFiles = new(); + List emittedFiles = []; List editedFiles = added.Concat(modified).ToList(); for(int i = 0; i < editedFiles.Count; i++) @@ -176,7 +176,7 @@ Deleting counterparts to removed files... File.ReadAllText(path) ); - int index = path.LastIndexOf("/"); + int index = path.LastIndexOf('/'); string outPath = path.Remove(index + 1, 1).Replace(input, output); StringBuilder writer = new(); From bddbd9b378152d1e2be7bb65cf61b1419ff203fc Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sat, 21 Oct 2023 21:12:59 +0200 Subject: [PATCH 162/323] squash some bugs and make sure we prioritize snowflakes --- .../Converters/OneOfConverter.cs | 32 +++++++------- .../Converters/OneOfConverterFactory.cs | 2 +- .../Converters/SnowflakeConverter.cs | 10 ++++- .../Serialization/RedirectingConverter.cs | 2 + .../OneOfConverterTests.Snowflakes.cs | 44 +++++++++++++++++++ 5 files changed, 71 insertions(+), 19 deletions(-) create mode 100644 tests/core/DSharpPlus.Core.Models.Tests/Converters/OneOfConverterTests.Snowflakes.cs diff --git a/src/core/DSharpPlus.Core.Models/Serialization/Converters/OneOfConverter.cs b/src/core/DSharpPlus.Core.Models/Serialization/Converters/OneOfConverter.cs index 508ae4e68b..4be8d42f59 100644 --- a/src/core/DSharpPlus.Core.Models/Serialization/Converters/OneOfConverter.cs +++ b/src/core/DSharpPlus.Core.Models/Serialization/Converters/OneOfConverter.cs @@ -11,7 +11,6 @@ using System.Linq; using System.Numerics; using System.Reflection; -using System.Runtime.CompilerServices; using System.Text.Json; using System.Text.Json.Serialization; @@ -28,7 +27,8 @@ public sealed class OneOfConverter : JsonConverter // using type handles turns out to be marginally faster than Type, but it doesn't fundamentally matter // and this might well change in future .NET versions, in which case this code should use Type for ease // of reading - private static readonly FrozenDictionary> constructionMethods; + // at some point i'd also like to kill the MethodInfo, but today is not that day + private static readonly FrozenDictionary constructionMethods; // we cache ordered types by the jsontokentype private static readonly FrozenDictionary> orderedUnion; @@ -46,22 +46,20 @@ static OneOfConverter() // 3. float primitives (assignable to INumber and IFloatingPoint, is struct) // 4. other types that aren't models // 5. models - FrozenSet baselineOrderedUnionTypes = unionTypes + IEnumerable baselineOrderedUnionTypes = unionTypes .OrderByDescending(t => t == typeof(Snowflake) || t == typeof(Snowflake?)) - .ThenByDescending(t => t.IsAssignableTo(typeof(INumber<>).MakeGenericType(t)) && t.IsValueType) - .ThenBy(t => t.IsAssignableTo(typeof(IFloatingPoint<>).MakeGenericType(t))) - .ThenBy(t => t.FullName!.StartsWith("DSharpPlus", StringComparison.InvariantCulture)) - .ToFrozenSet(); + .ThenByDescending(t => t.IsAssignableTo(typeof(INumber<>)) && t.IsValueType) + .ThenBy(t => t.IsAssignableTo(typeof(IFloatingPoint<>))) + .ThenBy(t => t.FullName!.StartsWith("DSharpPlus", StringComparison.InvariantCulture)); // construction methods - Dictionary> methods = []; + Dictionary methods = []; for (int i = 0; i < unionTypes.Length; i++) { - MethodInfo? method = typeof(TUnion).GetMethod($"FromT{i}")!; + MethodInfo method = typeof(TUnion).GetMethod($"FromT{i}")!; - Func @delegate = Unsafe.As>(method.CreateDelegate(unionTypes[i])); - methods.Add(unionTypes[i].TypeHandle.Value, @delegate); + methods.Add(unionTypes[i].TypeHandle.Value, method); } constructionMethods = methods.ToFrozenDictionary(); @@ -70,7 +68,7 @@ static OneOfConverter() Dictionary> priorities = new() { // our baseline is already optimized for numbers - [JsonTokenType.Number] = baselineOrderedUnionTypes + [JsonTokenType.Number] = baselineOrderedUnionTypes.ToFrozenSet() }; // nullability @@ -79,7 +77,7 @@ static OneOfConverter() JsonTokenType.Null, baselineOrderedUnionTypes.OrderByDescending ( - type => type.GetGenericTypeDefinition() == typeof(Nullable<>) || !type.IsValueType + type => (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>)) || !type.IsValueType ) .ToFrozenSet() ); @@ -94,13 +92,13 @@ static OneOfConverter() priorities.Add(JsonTokenType.True, booleanPriority); priorities.Add(JsonTokenType.False, booleanPriority); - // string + // string - snowflakes also use strings, so we should prioritize accordingly priorities.Add ( JsonTokenType.String, baselineOrderedUnionTypes.OrderByDescending ( - type => type == typeof(string) + type => type == typeof(string) || type == typeof(Snowflake) ) .ToFrozenSet() ); @@ -120,7 +118,7 @@ static OneOfConverter() JsonTokenType.StartObject, baselineOrderedUnionTypes.OrderByDescending(type => !type.IsPrimitive) .ThenByDescending(type => type != typeof(Snowflake) && type != typeof(Snowflake?)) - .ThenByDescending(type => type.GetGenericTypeDefinition() != typeof(Nullable<>)) + .ThenByDescending(type => type.IsGenericType && type.GetGenericTypeDefinition() != typeof(Nullable<>)) .ToFrozenSet() ); @@ -148,7 +146,7 @@ JsonSerializerOptions options continue; } - return (TUnion)constructionMethods[type.TypeHandle.Value](value); + return (TUnion)constructionMethods[type.TypeHandle.Value].Invoke(null, new object[] { value })!; } throw new JsonException("The value could not be parsed into the given union."); diff --git a/src/core/DSharpPlus.Core.Models/Serialization/Converters/OneOfConverterFactory.cs b/src/core/DSharpPlus.Core.Models/Serialization/Converters/OneOfConverterFactory.cs index 8b3915eb87..6247bb8bf4 100644 --- a/src/core/DSharpPlus.Core.Models/Serialization/Converters/OneOfConverterFactory.cs +++ b/src/core/DSharpPlus.Core.Models/Serialization/Converters/OneOfConverterFactory.cs @@ -24,7 +24,7 @@ public override JsonConverter? CreateConverter JsonSerializerOptions options ) { - Type concreteConverter = typeof(OneOfConverter<>).MakeGenericType(typeToConvert.GetGenericArguments()); + Type concreteConverter = typeof(OneOfConverter<>).MakeGenericType(typeToConvert); return (JsonConverter)Activator.CreateInstance(concreteConverter)!; } diff --git a/src/core/DSharpPlus.Core.Models/Serialization/Converters/SnowflakeConverter.cs b/src/core/DSharpPlus.Core.Models/Serialization/Converters/SnowflakeConverter.cs index 67a554a7a7..462e48cdf5 100644 --- a/src/core/DSharpPlus.Core.Models/Serialization/Converters/SnowflakeConverter.cs +++ b/src/core/DSharpPlus.Core.Models/Serialization/Converters/SnowflakeConverter.cs @@ -3,6 +3,7 @@ // file, You can obtain one at https://mozilla.org/MPL/2.0/. using System; +using System.Globalization; using System.Text.Json; using System.Text.Json.Serialization; @@ -11,7 +12,14 @@ namespace DSharpPlus.Core.Models.Serialization.Converters; public sealed class SnowflakeConverter : JsonConverter { public override Snowflake Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) - => new(JsonSerializer.Deserialize(ref reader, options)); + { + return reader.TokenType switch + { + JsonTokenType.Number => new(reader.GetInt64()), + JsonTokenType.String => new(long.Parse(reader.GetString()!, CultureInfo.InvariantCulture)), + _ => throw new JsonException("The present payload could not be parsed as a snowflake.") + }; + } public override void Write(Utf8JsonWriter writer, Snowflake value, JsonSerializerOptions options) => writer.WriteNumberValue(value.Value); diff --git a/src/core/DSharpPlus.Shared/Serialization/RedirectingConverter.cs b/src/core/DSharpPlus.Shared/Serialization/RedirectingConverter.cs index fae09d99c7..753304aaf5 100644 --- a/src/core/DSharpPlus.Shared/Serialization/RedirectingConverter.cs +++ b/src/core/DSharpPlus.Shared/Serialization/RedirectingConverter.cs @@ -2,6 +2,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +#pragma warning disable CA1812 + using System; using System.Text.Json; using System.Text.Json.Serialization; diff --git a/tests/core/DSharpPlus.Core.Models.Tests/Converters/OneOfConverterTests.Snowflakes.cs b/tests/core/DSharpPlus.Core.Models.Tests/Converters/OneOfConverterTests.Snowflakes.cs new file mode 100644 index 0000000000..2fc0b49fd9 --- /dev/null +++ b/tests/core/DSharpPlus.Core.Models.Tests/Converters/OneOfConverterTests.Snowflakes.cs @@ -0,0 +1,44 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; +using System.Text.Json; + +using DSharpPlus.Core.Models.Serialization.Converters; + +using OneOf; + +using Xunit; + +namespace DSharpPlus.Core.Models.Tests.Converters; + +// here we test whether we handle snowflake precedence correctly, with intentionally annoying unions +public partial class OneOfConverterTests +{ + private static ReadOnlySpan SnowflakeIntegerPayload => "\"983987834938\""u8; + + [Fact] + public void TestSnowflakePrecedence() + { + JsonSerializerOptions options = new(); + options.Converters.Add(new OneOfConverterFactory()); + options.Converters.Add(new SnowflakeConverter()); + + OneOf union = JsonSerializer.Deserialize> + ( + SnowflakeIntegerPayload, + options + ); + + Assert.True(union.IsT0); + + OneOf otherUnion = JsonSerializer.Deserialize> + ( + SnowflakeIntegerPayload, + options + ); + + Assert.True(otherUnion.IsT1); + } +} From 41ad3057d9b5812abf923c8e9d2be6406d2c1eac Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sun, 22 Oct 2023 20:30:18 +0200 Subject: [PATCH 163/323] correct generic math precedence checks --- .../Converters/OneOfConverter.cs | 36 ++++++- .../OneOfConverterTests.Precedence.cs | 93 +++++++++++++++++++ .../OneOfConverterTests.Snowflakes.cs | 44 --------- 3 files changed, 127 insertions(+), 46 deletions(-) create mode 100644 tests/core/DSharpPlus.Core.Models.Tests/Converters/OneOfConverterTests.Precedence.cs delete mode 100644 tests/core/DSharpPlus.Core.Models.Tests/Converters/OneOfConverterTests.Snowflakes.cs diff --git a/src/core/DSharpPlus.Core.Models/Serialization/Converters/OneOfConverter.cs b/src/core/DSharpPlus.Core.Models/Serialization/Converters/OneOfConverter.cs index 4be8d42f59..529cce62fb 100644 --- a/src/core/DSharpPlus.Core.Models/Serialization/Converters/OneOfConverter.cs +++ b/src/core/DSharpPlus.Core.Models/Serialization/Converters/OneOfConverter.cs @@ -48,8 +48,14 @@ static OneOfConverter() // 5. models IEnumerable baselineOrderedUnionTypes = unionTypes .OrderByDescending(t => t == typeof(Snowflake) || t == typeof(Snowflake?)) - .ThenByDescending(t => t.IsAssignableTo(typeof(INumber<>)) && t.IsValueType) - .ThenBy(t => t.IsAssignableTo(typeof(IFloatingPoint<>))) + .ThenByDescending + ( + t => TestAssignableToGenericMathInterface(t, typeof(INumber<>)) + ) + .ThenBy + ( + t => TestAssignableToGenericMathInterface(t, typeof(IFloatingPoint<>)) + ) .ThenBy(t => t.FullName!.StartsWith("DSharpPlus", StringComparison.InvariantCulture)); // construction methods @@ -125,6 +131,32 @@ static OneOfConverter() orderedUnion = priorities.ToFrozenDictionary(); } + private static bool TestAssignableToGenericMathInterface + ( + Type type, + Type @interface + ) + { + if (!type.IsValueType) + { + return false; + } + + try + { + if (type.IsAssignableTo(@interface.MakeGenericType(type))) + { + return true; + } + } + catch (ArgumentException) + { + return false; + } + + return false; + } + public override TUnion? Read ( ref Utf8JsonReader reader, diff --git a/tests/core/DSharpPlus.Core.Models.Tests/Converters/OneOfConverterTests.Precedence.cs b/tests/core/DSharpPlus.Core.Models.Tests/Converters/OneOfConverterTests.Precedence.cs new file mode 100644 index 0000000000..4b8b669e56 --- /dev/null +++ b/tests/core/DSharpPlus.Core.Models.Tests/Converters/OneOfConverterTests.Precedence.cs @@ -0,0 +1,93 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; +using System.Text.Json; + +using DSharpPlus.Core.Models.Serialization.Converters; + +using OneOf; + +using Xunit; + +namespace DSharpPlus.Core.Models.Tests.Converters; + +// here we test whether we handle precedence correctly, with intentionally annoying unions +public partial class OneOfConverterTests +{ + private static ReadOnlySpan SnowflakeIntegerPayload => "983987834938"u8; + private static ReadOnlySpan SnowflakeStringPayload => "\"737837872\""u8; + private static ReadOnlySpan IntegerFloatPayload => "887673"u8; + + [Fact] + public void TestSnowflakeLongPrecedence() + { + JsonSerializerOptions options = new(); + options.Converters.Add(new OneOfConverterFactory()); + options.Converters.Add(new SnowflakeConverter()); + + OneOf union = JsonSerializer.Deserialize> + ( + SnowflakeIntegerPayload, + options + ); + + Assert.True(union.IsT0); + + OneOf otherUnion = JsonSerializer.Deserialize> + ( + SnowflakeIntegerPayload, + options + ); + + Assert.True(otherUnion.IsT1); + } + + [Fact] + public void TestSnowflakeStringPrecedence() + { + JsonSerializerOptions options = new(); + options.Converters.Add(new OneOfConverterFactory()); + options.Converters.Add(new SnowflakeConverter()); + + OneOf union = JsonSerializer.Deserialize> + ( + SnowflakeStringPayload, + options + ); + + Assert.True(union.IsT0); + + OneOf otherUnion = JsonSerializer.Deserialize> + ( + SnowflakeStringPayload, + options + ); + + Assert.True(otherUnion.IsT1); + } + + [Fact] + public void TestIntegerFloatPrecedence() + { + JsonSerializerOptions options = new(); + options.Converters.Add(new OneOfConverterFactory()); + + OneOf union = JsonSerializer.Deserialize> + ( + IntegerFloatPayload, + options + ); + + Assert.True(union.IsT0); + + OneOf otherUnion = JsonSerializer.Deserialize> + ( + IntegerFloatPayload, + options + ); + + Assert.True(otherUnion.IsT1); + } +} diff --git a/tests/core/DSharpPlus.Core.Models.Tests/Converters/OneOfConverterTests.Snowflakes.cs b/tests/core/DSharpPlus.Core.Models.Tests/Converters/OneOfConverterTests.Snowflakes.cs deleted file mode 100644 index 2fc0b49fd9..0000000000 --- a/tests/core/DSharpPlus.Core.Models.Tests/Converters/OneOfConverterTests.Snowflakes.cs +++ /dev/null @@ -1,44 +0,0 @@ -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -using System; -using System.Text.Json; - -using DSharpPlus.Core.Models.Serialization.Converters; - -using OneOf; - -using Xunit; - -namespace DSharpPlus.Core.Models.Tests.Converters; - -// here we test whether we handle snowflake precedence correctly, with intentionally annoying unions -public partial class OneOfConverterTests -{ - private static ReadOnlySpan SnowflakeIntegerPayload => "\"983987834938\""u8; - - [Fact] - public void TestSnowflakePrecedence() - { - JsonSerializerOptions options = new(); - options.Converters.Add(new OneOfConverterFactory()); - options.Converters.Add(new SnowflakeConverter()); - - OneOf union = JsonSerializer.Deserialize> - ( - SnowflakeIntegerPayload, - options - ); - - Assert.True(union.IsT0); - - OneOf otherUnion = JsonSerializer.Deserialize> - ( - SnowflakeIntegerPayload, - options - ); - - Assert.True(otherUnion.IsT1); - } -} From ddebccaf05f4f2b39939de273ebb056f3e7cc289 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sun, 22 Oct 2023 21:16:47 +0200 Subject: [PATCH 164/323] test with some actual examples --- .../Converters/OneOfConverterTests.Models.cs | 89 +++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 tests/core/DSharpPlus.Core.Models.Tests/Converters/OneOfConverterTests.Models.cs diff --git a/tests/core/DSharpPlus.Core.Models.Tests/Converters/OneOfConverterTests.Models.cs b/tests/core/DSharpPlus.Core.Models.Tests/Converters/OneOfConverterTests.Models.cs new file mode 100644 index 0000000000..00bd008442 --- /dev/null +++ b/tests/core/DSharpPlus.Core.Models.Tests/Converters/OneOfConverterTests.Models.cs @@ -0,0 +1,89 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; + +using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Core.Models.Extensions; +using DSharpPlus.Serialization; + +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging.Abstractions; + +using Xunit; + +namespace DSharpPlus.Core.Models.Tests.Converters; + +// tests one-of deserialization on example payloads for actual models +partial class OneOfConverterTests +{ + private readonly ISerializationService serializer; + + public OneOfConverterTests() + { + IServiceCollection services = new ServiceCollection(); + services.RegisterDiscordModelSerialization(); + services.Configure + ( + options => options.SetFormat() + ); + + services.AddLogging + ( + builder => builder.ClearProviders().AddProvider(NullLoggerProvider.Instance) + ); + + services.AddSingleton(typeof(ISerializationService<>), typeof(SerializationService<>)); + + IServiceProvider provider = services.BuildServiceProvider(); + this.serializer = provider.GetRequiredService>(); + } + + [Fact] + public void TestApplicationCommandInteractionDataOptionUnion() + { + IApplicationCommandInteractionDataOption value = this.serializer.DeserializeModel + ( + """ + { + "name": "testificate", + "type": 1, + "options": [ + { + "name": "example", + "type": 10, + "value": 17 + } + ] + } + """u8 + ); + + Assert.Equal(17, value.Options.Value![0].Value.Value); + } + + [Fact] + public void TestInteractionResponseUnion() + { + IInteractionResponse response = this.serializer.DeserializeModel + ( + """ + { + "type": 8, + "data": { + "choices": [ + { + "name": "deimos", + "value": "thingie" + } + ] + } + } + """u8 + ); + + Assert.Equal("thingie", response.Data.Value.AsT0.Choices[0].Value); + } +} From 7fd0fa6458fb0ef71c4d222e8d33dc1ab8c27d04 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sun, 22 Oct 2023 21:28:43 +0200 Subject: [PATCH 165/323] update entitlements as per api docs changes --- .../Entitlements/IEntitlement.cs | 4 ++-- src/core/DSharpPlus.Core.Models/Entitlements/Entitlement.cs | 2 +- src/core/DSharpPlus.Shared/Entities/Skus/SkuFlags.cs | 5 +++++ 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Entitlements/IEntitlement.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Entitlements/IEntitlement.cs index 5e2fee5247..62d02165e0 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Entitlements/IEntitlement.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Entitlements/IEntitlement.cs @@ -44,9 +44,9 @@ public interface IEntitlement public EntitlementType Type { get; } /// - /// false. + /// Indicates whether this entitlement was deleted. /// - public bool Consumed { get; } + public bool Deleted { get; } /// /// The starting date at which this entitlement is valid. Not present when using test entitlements. diff --git a/src/core/DSharpPlus.Core.Models/Entitlements/Entitlement.cs b/src/core/DSharpPlus.Core.Models/Entitlements/Entitlement.cs index a1bc1ca706..f06c6e9166 100644 --- a/src/core/DSharpPlus.Core.Models/Entitlements/Entitlement.cs +++ b/src/core/DSharpPlus.Core.Models/Entitlements/Entitlement.cs @@ -32,7 +32,7 @@ public sealed record Entitlement : IEntitlement public required EntitlementType Type { get; init; } /// - public required bool Consumed { get; init; } + public required bool Deleted { get; init; } /// public Optional StartsAt { get; init; } diff --git a/src/core/DSharpPlus.Shared/Entities/Skus/SkuFlags.cs b/src/core/DSharpPlus.Shared/Entities/Skus/SkuFlags.cs index 6832c859bc..7043298f96 100644 --- a/src/core/DSharpPlus.Shared/Entities/Skus/SkuFlags.cs +++ b/src/core/DSharpPlus.Shared/Entities/Skus/SkuFlags.cs @@ -12,6 +12,11 @@ namespace DSharpPlus.Entities; [Flags] public enum SkuFlags { + /// + /// This SKU is available for purchase. + /// + Available = 1 << 2, + /// /// A subscription purchased by a user and applied to a single server. Everyone in that server gets access /// to the given SKU. From 1d97018e75190c48cea47d52f567e85ca03f595c Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Tue, 24 Oct 2023 15:50:02 +0200 Subject: [PATCH 166/323] powershell is gone :crabrave: --- dsharpplus.csx | 209 ++++++++++++++++++ dsharpplus.ps1 | 183 ---------------- script-functions.ps1 | 497 ------------------------------------------- 3 files changed, 209 insertions(+), 680 deletions(-) create mode 100644 dsharpplus.csx delete mode 100644 dsharpplus.ps1 delete mode 100644 script-functions.ps1 diff --git a/dsharpplus.csx b/dsharpplus.csx new file mode 100644 index 0000000000..9708c94220 --- /dev/null +++ b/dsharpplus.csx @@ -0,0 +1,209 @@ +#!/usr/bin/env dotnet-script + +#nullable enable + +#r "nuget:Spectre.Console, 0.47.1-preview.0.26" + +using System.Diagnostics; +using System.Linq; + +using Spectre.Console; + +enum ToolType +{ + None, + Generator, + Analyzer +} + +readonly record struct ToolMetadata +{ + public required string Name { get; init; } + + public required ToolType Type { get; init; } + + public required string Subset { get; init; } +} + +ToolMetadata[] tools = +{ + new() + { + Name = "generate-concrete-objects", + Subset = "core", + Type = ToolType.Generator + } +}; + +string[] subsets = +{ + "core" +}; + +// executes a given tool +void ExecuteTool(string tool, ToolType type) +{ + switch (type) + { + case ToolType.Generator: + Process.Start("dotnet", $"script ./tools/generators/{tool}.csx"); + break; + case ToolType.Analyzer: + Process.Start("dotnet", $"script ./tools/analyzers/{tool}.csx"); + break; + } +} + +// executes all tools belonging to a subject +void ExecuteSubset(string[] subset, ToolType type) +{ + foreach (ToolMetadata metadata in tools) + { + if (type != ToolType.None && metadata.Type != type) + { + continue; + } + + if (!subset.Contains(metadata.Subset)) + { + continue; + } + + ExecuteTool(metadata.Name, metadata.Type); + } +} + +// main entrypoint is here, at the big ass help command + +if (Args.Count == 1 && Args is ["--help"] or ["-h"] or ["-?"]) +{ + AnsiConsole.MarkupLine + ( + """ + This is the primary script controlling the DSharpPlus build. + + [lightgoldenrod2_2]Usage: dsharpplus [[action]] [/] + + [lightgoldenrod2_2]Actions:[/] + run Runs the given tools or subset of tools. + publish Publishes the given subset of the library. + + [lightgoldenrod2_2]Groups:[/] + [grey50]NOTE: Groups are only valid when operating on tools.[/] + + tools Indiscriminately operates on all kinds of tools. + generators Operates on tools intended to generate code or metadata. + analyzers Operates on tools intended to analyze and communicate the validity of existing code and metadata + + [lightgoldenrod2_2]Options:[/] + + -s|--subset Specifies one or more subsets to operate on. + -n|--name Specifies the individual name of a tools to operate on. + + [lightgoldenrod2_2]Examples:[/] + + The following command will run all core tools: + [grey50]dsharpplus run tools --subset core[/] + + The following command will run all core generators: + [grey50]dsharpplus run generators --subset core[/] + + The following command will only run a single tool, generate-concrete-objects: + [grey50]dsharpplus run --name generate-concrete-objects[/] + + The following command will build the core library as well as the caching logic: + [grey50]dsharpplus publish --subset core,cache[/] + """ + ); + + return 0; +} + +if (Args.Count >= 1 && Args[0] == "publish") +{ + if (Args[1] == "-s" || Args[1] == "--subset") + { + if (Args.Count != 3) + { + AnsiConsole.MarkupLine("[red]Expected one argument to --subset.[/]"); + return 1; + } + + string[] loadedSubsets = Args[2].Split(','); + + foreach (string s in loadedSubsets) + { + Process.Start("dotnet", $"pack ./src/{s} --tl"); + } + + return 0; + } + + Process.Start("dotnet", "pack --tl"); + + return 0; +} + +if (Args[0] != "run") +{ + AnsiConsole.MarkupLine($"[red]The only supported top-level verbs are 'run' and 'publish', found {Args[0]}.[/]"); + return 1; +} + +// we're now firmly in tooling territory + +switch (Args[1]) +{ + case "tools": + + if (Args[2] == "-s" || Args[2] == "--subset") + { + ExecuteSubset(Args[3].Split(','), ToolType.None); + } + else + { + ExecuteSubset(subsets, ToolType.None); + } + break; + + case "generators": + + if (Args[2] == "-s" || Args[2] == "--subset") + { + ExecuteSubset(Args[3].Split(','), ToolType.Generator); + } + else + { + ExecuteSubset(subsets, ToolType.Generator); + } + break; + + case "analyzers": + + if (Args[2] == "-s" || Args[2] == "--subset") + { + ExecuteSubset(Args[3].Split(','), ToolType.Analyzer); + } + else + { + ExecuteSubset(subsets, ToolType.Analyzer); + } + break; + + case "-n": + case "--name": + + ToolType type = tools.Where(t => t.Name == Args[2]).Select(t => t.Type).FirstOrDefault(); + + if (type == ToolType.None) + { + AnsiConsole.MarkupLine($"[red]The tool {Args[2]} could not be found.[/]"); + return 1; + } + + ExecuteTool(Args[2], type); + + break; +} + +return 0; diff --git a/dsharpplus.ps1 b/dsharpplus.ps1 deleted file mode 100644 index 6277d03308..0000000000 --- a/dsharpplus.ps1 +++ /dev/null @@ -1,183 +0,0 @@ -<################################################################################################## - -This script serves as the main entrypoint for the DSharpPlus build tooling. It should, at all -times, be targeted towards windows and linux simultaneously; which means keeping the script OS- -agnostic where possible and special-casing certain points as needed. - -It is tasked with the following aims: - -- run all or only a selection of tools, under `run tools` - - run all or only a selection of generating tools, under `run generators` - - run all or only a selection of analyzing tools, under `run analyzers` -- build all or only a selection of tools without running, under `build tools` -- test all or only a selection of tools, under `test tools` - -- publish specific 'areas', under `publish -subset ` - -##################################################################################################> - -#requires -Version 6 - -<# -.PARAMETER Help - Indicates whether to display the help output. - -.PARAMETER Action - The primary action to perform. - -.PARAMETER ToolGroup - The group of tools to execute this action on. - -.PARAMETER Subset - The subset of libraries or tools to execute this action on. - -.PARAMETER Names - The granular names of tools to execute this action on. -#> - -param ( - [Alias('h')] - [Alias('?')] - [switch]$Help, - - [Parameter(Position = 0)] - [ValidateSet("run", "build", "test", "publish")] - [string]$Action, - - [Parameter(Position = 1)] - [ValidateSet("tools", "generators", "analyzers")] - [string]$ToolGroup, - - [Alias('s')] - [ValidateSet("core", "etf")] - [string[]]$Subset, - - [Alias('n')] - [string[]]$Names -) - -$ErrorActionPreference = 'Stop' - -. "$PSScriptRoot/script-functions.ps1" - -if ($Help) { - Get-ScriptHelp - exit 0 -} - -if($Names.Count -gt 0) { - switch ($Action) { - "run" { - Invoke-Tools -Tools $Names - } - "build" { - Build-Tools -Tools $Names - } - "test" { - Test-Tools -Tools $Names - } - } - - exit 0 -} - -if ((![System.String]::IsNullOrWhiteSpace($ToolGroup)) -and ($Subset.Count -le 0)) { - [string[]]$ToolsToExecute = @() - - switch ($ToolGroup) { - "tools" { - # this must be in order, as analyzers can operate on generated code - $ToolsToExecute = $Generators + $Analyzers - } - "generators" { - $ToolsToExecute = $Generators - } - "analyzers" { - $ToolsToExecute = $Analyzers - } - } - - switch ($Action) { - "run" { - Invoke-Tools -Tools $ToolsToExecute - } - "build" { - Build-Tools -Tools $ToolsToExecute - } - "test" { - Test-Tools -Tools $ToolsToExecute - } - } - - exit 0 -} - -[string[]]$SubsetsToExecute = @() - -if ($Subset.Count -gt 0) { - $SubsetsToExecute = $Subset -} -else { - $SubsetsToExecute = $AllSubsets -} - -if ($Action -eq "publish") { - foreach($Target in $SubsetsToExecute) { - Write-Host "Publishing library subset '$Target'" - Publish-Subset $Target - } - - exit 0 -} - -[string[]]$ToolsToExecute = @() - -# construct the list of tools we want to execute -# this looks a little scuffed, so, explanation: -# -# firstly, we filter by tool group. -# then, the tool group dictating what tools to add, -# we foreach over the supplied subsets to add the -# tools -switch ($ToolGroup) { - "tools" { - foreach ($Target in $SubsetsToExecute) { - switch ($Target) { - "core" { - $ToolsToExecute += $CoreGenerators - $ToolsToExecute += $CoreAnalyzers - } - } - } - } - "generators" { - foreach ($Target in $SubsetsToExecute) { - switch ($Target) { - "core" { - $ToolsToExecute += $CoreGenerators - } - } - } - } - "analyzers" { - foreach ($Target in $SubsetsToExecute) { - switch ($Target) { - "core" { - $ToolsToExecute += $CoreAnalyzers - } - } - } - } -} - -switch ($Action) { - "run" { - Invoke-Tools -Tools $ToolsToExecute - } - "build" { - Build-Tools -Tools $ToolsToExecute - } - "test" { - Test-Tools -Tools $ToolsToExecute - } -} diff --git a/script-functions.ps1 b/script-functions.ps1 deleted file mode 100644 index 7c0547f62c..0000000000 --- a/script-functions.ps1 +++ /dev/null @@ -1,497 +0,0 @@ -<################################################################################################## - -This section of the script contains miscellaneous types for later use. Refer to the individual -documentation of each type. - -##################################################################################################> - -<# -.SYNOPSIS - Enumerates known kinds of tools; for use in a variety of commands. -#> -enum ToolType { - Generator - Analyzer -} - -<################################################################################################## - -This section of the script contains hashtables and arrays for later use. When adding, removing or -renaming tools, this section must be kept up to date. - -##################################################################################################> - -[string[]]$CoreGenerators = @( - "generate-concrete-objects" -) - -[string[]]$CoreAnalyzers = @() - -[string[]] $Generators = $CoreGenerators - -[string[]] $Analyzers = $CoreAnalyzers - -[hashtable]$CoreGeneratorTable = [ordered]@{ - "generate-concrete-objects" = "Tools.Generators.GenerateConcreteObjects" -} - -# word of warning: don't rely on GeneratorTable and AnalyzerTable to be ordered correctly -[hashtable]$GeneratorTable = $CoreGeneratorTable - -[hashtable]$AnalyzerTable = @{} - -[string[]]$AllSubsets = @( - "core" -) - -<################################################################################################## - -This section of the script contains functions, to be used and re-used so as to keep the code -more readable. Refer to the individual documentation of each function. - -##################################################################################################> - -function Get-ScriptHelp { - Write-Host "This is the primary script controlling the DSharpPlus build." - Write-Host "" - Write-Host "Usage: dsharpplus [action] " - Write-Host "" - Write-Host "Actions:" - Write-Host " run Runs the given tools or subset of tools." - Write-Host " build Builds the given tools or subset of tools." - Write-Host " test Tests the given tools or subset of tools." - Write-Host " publish Publishes the given subset of the library." - Write-Host "" - Write-Host "Groups:" - Write-Host "Note that groups are only valid when operating on tools" -ForegroundColor Gray - Write-Host "" - Write-Host " tools Indiscriminately operates on all kinds of tools." - Write-Host " generators Operates on tools intended to generate code or metadata." - Write-Host " analyzers Operates on tools intended to analyze and communicate the validity" + - "of existing code or metadata" - Write-Host "" - Write-Host "Options:" - Write-Host "" - Write-Host " -s|-subset Specifies one or more subsets to operate on" - Write-Host " -n|-names Specifies the individual names of tools to operate on." - Write-Host "" - Write-Host "Examples:" - Write-Host "" - Write-Host "The following command will run all core tools:" - Write-Host "dsharpplus run tools -subset core" -ForegroundColor Gray - Write-Host "" - Write-Host "The following command will run all core generators:" - Write-Host "dsharpplus run generators -subset core" -ForegroundColor Gray - Write-Host "" - Write-Host "The following command will only run a single tool, generate-concrete-objects:" - Write-Host "dsharpplus run tools -name generate-concrete-objects" -ForegroundColor Gray - Write-Host "" - Write-Host "The following command will build the core library as well as the caching logic:" - Write-Host "dsharpplus publish -subset core,cache" - Write-Host "" -} - -function Publish-Subset { - <# - .SYNOPSIS - Publishes and packs a subset of the library, ready to be used. - - .PARAMETER Subset - The identifier of the subset. - - .INPUTS - This function accepts the subset from the pipeline. - #> - - param ( - [Parameter(Position = 0, Mandatory = $true, ValueFromPipeline = $true)] - [string]$Subset - ) - - dotnet pack "$PSScriptRoot/src/$Subset" --tl -} - -function Build-Tools { - <# - .SYNOPSIS - Builds all tools in a given list, in order of specification. - - .NOTES - This function will optionally only rebuild tools that haven't been built yet. This can - speed up development iteration, but may cause side-effects. - - .PARAMETER Tools - The table of tools to build. This may be any basic collection or a composite. - - .PARAMETER BuildMissing - If this switch is set, this function will only build tools that aren't present in the - tool directory. - #> - - param ( - [Parameter(Position = 0, Mandatory = $true)] - [string[]]$Tools, - - [switch]$BuildMissing = $false - ) - - foreach ($Key in $Tools) { - if ($BuildMissing -and (Test-ToolBuilt -Name $Key)) { - continue - } - - if ($Generators.Contains($Key)) { - Build-Tool -Type Generator -CSProjectName $GeneratorTable[$Key] -OutputName $Key - } - elseif ($Analyzers.Contains($Key)) { - Build-Tool -Type Analyzer -CSProjectName $AnalyzerTable[$Key] -OutputName $Key - } - else { - Write-Error "The tool $Key could not be found." - continue - } - } -} - -function Test-Tools { - <# - .SYNOPSIS - Tests all tools in a given list, in order of specification. - - .NOTES - This function relies on Test-Tool to do the heavy lifting, and therefore exhibits all of - its behavioural side effects. - - .PARAMETER Tools - The table of tools to test. This may be any basic collection or a composite. - #> - - param ( - [Parameter(Position = 0, Mandatory = $true)] - [string[]]$Tools - ) - - process { - [int]$Passed = 0 - [int]$Failed = 0 - [int]$Skipped = 0 - [int]$Count = $Tools.Count - - foreach ($Key in $Tools) { - [bool]$Result = $false - - # runs the tool and keeps track of the result, so we can later print it - if ($Generators.Contains($Key)) { - $Result = Test-Tool -Type Generator -CSProjectName $GeneratorTable[$Key] -OutputName $Key - } - elseif ($Analyzers.Contains($Key)) { - $Result = Test-Tool -Type Analyzer -CSProjectName $AnalyzerTable[$Key] -OutputName $Key - } - else { - Write-Error "The tool $Key could not be found." - $Skipped++ - continue - } - - if ($Result) { - $Passed++ - } - else { - $Failed++ - } - } - } - - end { - Write-Host "-------------------------------------------------------------------------" - Write-Host "" - Write-Host "Tool Test Results for $Count tests:" - Write-Host "$Passed passed" -ForegroundColor Green - Write-Host "$Failed failed" -ForegroundColor Red - Write-Host "$Skipped skipped" -ForegroundColor Yellow - Write-Host "" - Write-Host "-------------------------------------------------------------------------" - } -} - -function Invoke-Tools { - <# - .SYNOPSIS - Invokes all tools in a given list, in order of specification. - - .NOTES - This function is incapable of passing additional arguments to tools. If you need to - invoke a tool with additional arguments, you must invoke it directly via Invoke-Tool. - - Because of its reliance on Invoke-Tool, it will similarly build all tools not built yet. - - .PARAMETER Tools - The table of tools to execute. This may be any basic collection or a composite. - #> - - param ( - [Parameter(Position = 0, Mandatory = $true)] - [string[]]$Tools - ) - - foreach($Key in $Tools) { - Invoke-Tool -ToolName $Key - } -} - -function Invoke-Tool { - <# - .SYNOPSIS - Runs the specified tool, building if it not yet built. - - .PARAMETER ToolName - The common name of this tool. - - .PARAMETER Arguments - Additional CLI arguments to be passed to the tool, if applicable. - - .INPUTS - This function accepts the tool name from the pipeline. - #> - - param ( - [Parameter(Position = 0, ValueFromPipeline = $true, Mandatory = $true)] - [string]$ToolName, - - [Parameter(Position = 1, ValueFromRemainingArguments = $true)] - [string]$Arguments - ) - - if (!(Test-ToolBuilt -Name $ToolName)) { - if ($Generators.Contains($ToolName)) { - Write-Verbose "The generator $ToolName was not built, attempting to build..." - Build-Tool -Type Generator -CSProjectName $GeneratorTable[$ToolName] -OutputName $ToolName - } - elseif ($Analyzers.Contains($ToolName)) { - Write-Verbose "The analyzer $ToolName was not built, attempting to build..." - Build-Tool -Type Analyzer -CSProjectName $AnalyzerTable[$ToolName] -OutputName $ToolName - } - else { - Write-Error "The specified tool does not exist." - exit - } - } - - Invoke-Expression "$PSScriptRoot/tools/bin/$ToolName $Arguments" -} - -function Test-Tool { - <# - .SYNOPSIS - Runs the specified test project for a given tool - - .NOTES - Since tools may choose to take input from the main codebase, but we do not want to operate on - the main codebase, we allow their test projects to simulate a test environment in the testing - folder. This call may have unexpected side-effects, and each tool should specify side-effects - and assumptions by itself. - - Test project names are assumed to be `ToolName.Tests`, for a given tool `ToolName`. - - Because of powershell limitations, all tests must contain a class `ToolName.Tests.Main` with - the following static parameterless methods: - - bool Prepare - - bool Execute - - It utilizes /tools/.testenv to run the tests; and /tools/.testenvhost to hold the test - assemblies. /tools/.testenv is cleared after every run. - - .PARAMETER Type - The type of the tool to test. - - .PARAMETER CSProjectName - The name of the C# project holding the source code for this tool. - - .PARAMETER OutputName - The 'common' name of this tool; and the name by which it is passed to the test. - - .INPUTS - This tool accepts the C# project name from the pipeline. - #> - - [OutputType(bool)] - param ( - [Parameter(Position = 0, Mandatory = $true)] - [ToolType]$Type, - - [Parameter(Position = 1, ValueFromPipeline = $true, Mandatory = $true)] - [string]$CSProjectName, - - [Parameter(Position = 2, Mandatory = $true)] - [string]$OutputName - ) - - begin { - # set up the testing environment and prepare the environment - if (!(Test-Path -Path "$PSScriptRoot/tools/.testenv")) { - New-Item -ItemType Directory -Path "$PSScriptRoot/tools/.testenv" - } - else { - Remove-Item -Path "$PSScriptRoot/tools/.testenv/*" -Force -Recurse - - Write-Verbose "Cleared the testenv folder of leftover files." - } - - dotnet build "$PSScriptRoot/tools/tests/$CSProjectName.Tests/$CSProjectName.Tests.csproj" -p:PublishAot=false - - Copy-Item -Path "$PSScriptRoot/tools/artifacts/bin/$CSProjectName.Tests/debug/$CSProjectName.Tests.dll" ` - -Destination "$PSScriptRoot/tools/.testenvhost/" - - Add-Type -Path "$PSScriptRoot/tools/.testenvhost/$CSProjectName.Tests.dll" - - [System.Environment]::CurrentDirectory = "$PSScriptRoot/tools/.testenv/" - - Write-Verbose "Prepared the testing environment; ready to build and test tooling." - - $env:DATA_DIRECTORY = "$PSScriptRoot/tools/.testenv/data" - $env:SRC_DIRECTORY = "$PSScriptRoot/tools/.testenv/src" - $env:OUT_DIRECTORY = "$PSScriptRoot/tools/.testenv/out" - - # this should be the last statement in begin, we don't want to ignore prelude errors - $ErrorActionPreference = 'Continue' - } - - process { - [bool]$Success = Invoke-Expression "[$CSProjectName.Tests.Main]::Prepare()" - - if (!($Success)) { - Write-Verbose "Preparation failed, the test $CSProjectName.Tests will not be executed." - - return $false - } - - Build-Tool -Type $Type -CSProjectName $CSProjectName -OutputName $OutputName - - if ($IsWindows) { - Copy-Item -Path "$PSScriptRoot/tools/bin/$OutputName.exe" -Destination "$PSScriptRoot/tools/.testenv/$OutputName.exe" - } - else { - Copy-Item -Path "$PSScriptRoot/tools/bin/$OutputName" -Destination "$PSScriptRoot/tools/.testenv/$OutputName" - } - - [bool]$Success = Invoke-Expression "[$CSProjectName.Tests.Main]::Execute()" - - if (!($Success)) { - Write-Verbose "The test $CSProjectName failed." - - return $false - } - - Write-Verbose "The test $CSProjectName passed." - } - - end { - # this should be the first statement in end, we don't want to ignore cleanup errors - $ErrorActionPreference = 'Stop' - - [System.Environment]::CurrentDirectory = "$PSScriptRoot" - - Remove-Item -Path "$PSScriptRoot/tools/.testenv/*" -Force -Recurse - - Write-Verbose "Cleaned up the testing environment." - - return $true - } -} - -function Build-Tool { - <# - .SYNOPSIS - Builds a certain tool and prepares it for use, either manually or by the script. - - .PARAMETER Type - Specifies the type of this tool. - - .PARAMETER CSProjectName - The name of the C# project holding the source code for this tool. - - .PARAMETER OutputName - The 'common' name of this tool, by which it is to be referred to in further use. - - .INPUTS - This function accepts the C# project name from the pipeline. - - .NOTES - This function will automatically create potentially missing directories. - #> - - param ( - [Parameter(Position = 0, Mandatory = $true)] - [ToolType]$Type, - - [Parameter(Position = 1, ValueFromPipeline = $true, Mandatory = $true)] - [string]$CSProjectName, - - [Parameter(Position = 2, Mandatory = $true)] - [string]$OutputName - ) - - process { - if (!(Test-Path -Path "$PSScriptRoot/tools/bin")) { - New-Item -ItemType Directory -Path "$PSScriptRoot/tools/bin" - } - - switch ($Type) { - Generator { - # --ucr == use current runtime; that is, build natively for this system - dotnet publish "$PSScriptRoot/tools/generators/$CSProjectName/$CSProjectName.csproj" --ucr --tl - } - Analyzer { - dotnet publish "$PSScriptRoot/tools/analyzers/$CSProjectName/$CSProjectName.csproj" --ucr --tl - } - } - - if ($IsWindows) { - Copy-Item -Path "$PSScriptRoot/tools/artifacts/publish/$CSProjectName/release/$CSProjectName.exe" ` - -Destination "$PSScriptRoot/tools/bin/$OutputName.exe" - } - else { - Copy-Item -Path "$PSScriptRoot/tools/artifacts/publish/$CSProjectName/release/$CSProjectName" ` - -Destination "$PSScriptRoot/tools/bin/$OutputName" - } - } - - end { - Write-Debug "The tool $OutputName was successfully built from $CSProjectName." - Write-Verbose "Successfully built tool $OutputName." - - if (Test-Path "$PSScriptRoot/artifacts/hashes/$OutputName.json") { - Remove-Item -Path "$PSScriptRoot/artifacts/hashes/$OutputName.json" - } - } -} - - -function Test-ToolBuilt { - <# - .SYNOPSIS - Tests whether a certain tool has been built and is ready to run. - - .PARAMETER Name - The 'common' name of this tool, and simultaneously its file name in /tools/bin. - - .INPUTS - This function accepts the tool name from the pipeline. - - .OUTPUTS - A boolean indicating whether the tool has been built or not. - #> - - [OutputType([bool])] - param ( - [Parameter(Position = 0, ValueFromPipeline = $true, Mandatory = $true)] - [string]$Name - ) - - process { - if ($IsWindows) { - return Test-Path -Path "$PSScriptRoot/tools/bin/$Name.exe" - } - return Test-Path -Path "$PSScriptRoot/tools/bin/$Name" - } -} \ No newline at end of file From e3d812fb563b989750e5546e43756168b95425fa Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Tue, 24 Oct 2023 16:20:25 +0200 Subject: [PATCH 167/323] make the incremental utility a csx script too --- DSharpPlus.sln | 10 - tools/Tools.IncrementalUtility/Changes.cs | 19 -- tools/Tools.IncrementalUtility/Hashes.cs | 25 --- .../MetadataCollection.cs | 183 ------------------ tools/Tools.IncrementalUtility/SourceFile.cs | 35 ---- .../Tools.IncrementalUtility.csproj | 16 -- tools/incremental-utility.csx | 107 ++++++++++ 7 files changed, 107 insertions(+), 288 deletions(-) delete mode 100644 tools/Tools.IncrementalUtility/Changes.cs delete mode 100644 tools/Tools.IncrementalUtility/Hashes.cs delete mode 100644 tools/Tools.IncrementalUtility/MetadataCollection.cs delete mode 100644 tools/Tools.IncrementalUtility/SourceFile.cs delete mode 100644 tools/Tools.IncrementalUtility/Tools.IncrementalUtility.csproj create mode 100644 tools/incremental-utility.csx diff --git a/DSharpPlus.sln b/DSharpPlus.sln index d096f56c3e..e2b510096c 100644 --- a/DSharpPlus.sln +++ b/DSharpPlus.sln @@ -14,11 +14,6 @@ EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tools", "Tools", "{EAC2F7ED-0965-4607-ACE0-829885A612C5}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tools.Generators.GenerateConcreteObjects", "tools\generators\Tools.Generators.GenerateConcreteObjects\Tools.Generators.GenerateConcreteObjects.csproj", "{DF07A6C6-4689-44DC-80B0-479CA7C6AAF6}" - ProjectSection(ProjectDependencies) = postProject - {9199CD3F-AD85-453E-9BA5-2B4ACC2576EC} = {9199CD3F-AD85-453E-9BA5-2B4ACC2576EC} - EndProjectSection -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tools.IncrementalUtility", "tools\Tools.IncrementalUtility\Tools.IncrementalUtility.csproj", "{9199CD3F-AD85-453E-9BA5-2B4ACC2576EC}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{EAE89CF5-AA91-4A22-9949-A46FAE1BF0D0}" EndProject @@ -56,10 +51,6 @@ Global {DF07A6C6-4689-44DC-80B0-479CA7C6AAF6}.Debug|Any CPU.Build.0 = Debug|Any CPU {DF07A6C6-4689-44DC-80B0-479CA7C6AAF6}.Release|Any CPU.ActiveCfg = Release|Any CPU {DF07A6C6-4689-44DC-80B0-479CA7C6AAF6}.Release|Any CPU.Build.0 = Release|Any CPU - {9199CD3F-AD85-453E-9BA5-2B4ACC2576EC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {9199CD3F-AD85-453E-9BA5-2B4ACC2576EC}.Debug|Any CPU.Build.0 = Debug|Any CPU - {9199CD3F-AD85-453E-9BA5-2B4ACC2576EC}.Release|Any CPU.ActiveCfg = Release|Any CPU - {9199CD3F-AD85-453E-9BA5-2B4ACC2576EC}.Release|Any CPU.Build.0 = Release|Any CPU {98D2C52C-E3BA-4564-919C-750775B7BA9C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {98D2C52C-E3BA-4564-919C-750775B7BA9C}.Debug|Any CPU.Build.0 = Debug|Any CPU {98D2C52C-E3BA-4564-919C-750775B7BA9C}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -85,7 +76,6 @@ Global {964AD252-F077-4AB5-8D92-6C594D08F078} = {BC8D8750-48A4-49EF-9D1F-BE4DBA5B500E} {E14B0AE9-FE71-4DE4-BEB1-4A8E139DB84C} = {BC8D8750-48A4-49EF-9D1F-BE4DBA5B500E} {DF07A6C6-4689-44DC-80B0-479CA7C6AAF6} = {EAC2F7ED-0965-4607-ACE0-829885A612C5} - {9199CD3F-AD85-453E-9BA5-2B4ACC2576EC} = {EAC2F7ED-0965-4607-ACE0-829885A612C5} {21927A64-7345-4D90-9EE2-7FA4B1973AAC} = {EAE89CF5-AA91-4A22-9949-A46FAE1BF0D0} {98D2C52C-E3BA-4564-919C-750775B7BA9C} = {5FBB4590-56B0-453B-A87B-08A17C599B5C} {9F25D892-3CB0-4D47-B67D-D3FFFADC03E0} = {21927A64-7345-4D90-9EE2-7FA4B1973AAC} diff --git a/tools/Tools.IncrementalUtility/Changes.cs b/tools/Tools.IncrementalUtility/Changes.cs deleted file mode 100644 index 2d5c85870b..0000000000 --- a/tools/Tools.IncrementalUtility/Changes.cs +++ /dev/null @@ -1,19 +0,0 @@ -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -using System.Collections.Generic; - -namespace Tools.IncrementalUtility; - -/// -/// Contains the changes made to files since the last hashing. -/// -public sealed record Changes -{ - public required IEnumerable Modified { get; init; } - - public required IEnumerable Added { get; init; } - - public required IEnumerable Removed { get; init; } -} diff --git a/tools/Tools.IncrementalUtility/Hashes.cs b/tools/Tools.IncrementalUtility/Hashes.cs deleted file mode 100644 index 878663fd88..0000000000 --- a/tools/Tools.IncrementalUtility/Hashes.cs +++ /dev/null @@ -1,25 +0,0 @@ -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -using System.Text.Json.Serialization; - -using Bundles; -using Bundles.Converters; - -namespace Tools.IncrementalUtility; - -/// -/// Represents a serialization model for the hashes. -/// -public partial record Hashes -{ - [JsonConverter(typeof(DictionarySlimStringStringJsonConverter))] - public required DictionarySlim Values { get; init; } -} - -[JsonSerializable(typeof(Hashes))] -internal partial class SerializationContext : JsonSerializerContext -{ - -} diff --git a/tools/Tools.IncrementalUtility/MetadataCollection.cs b/tools/Tools.IncrementalUtility/MetadataCollection.cs deleted file mode 100644 index eb8168262c..0000000000 --- a/tools/Tools.IncrementalUtility/MetadataCollection.cs +++ /dev/null @@ -1,183 +0,0 @@ -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -using System; -using System.Collections; -using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; -using System.IO; -using System.Linq; -using System.Text.Json; - -using Bundles; - -namespace Tools.IncrementalUtility; - -/// -/// Represents a collection of current file hashes, with support for listing changed files, added files and -/// removed files. -/// -/// The name of the parent tool invoking this functionality. -public sealed class MetadataCollection -( - string name -) - : IReadOnlyDictionary -{ - private readonly DictionarySlim hashes = new(); - - /// - /// Calculates the current hashes of files, updates the cache and - /// - /// - /// - public Changes CalculateDifferences - ( - params string[] files - ) - { - // load and deserialize the current hashes - // DictionarySlim is really the only DictionarySlim we can do ahead of time - - if (!Directory.Exists("./artifacts/hashes")) - { - Directory.CreateDirectory("./artifacts/hashes"); - } - - // the file does not exist, go back to start and calculate all hashes - if (!File.Exists($"./artifacts/hashes/{name}.json")) - { - File.Create($"./artifacts/hashes/{name}.json").Close(); - this.CalculateAndSaveHashes(files); - - return new Changes - { - Added = files, - Removed = Array.Empty(), - Modified = Array.Empty() - }; - } - - // load the saved hashes - StreamReader reader = new($"./artifacts/hashes/{name}.json"); - - DictionarySlim oldHashes = JsonSerializer.Deserialize - ( - reader.ReadToEnd(), - SerializationContext.Default.Hashes - )!.Values; - - reader.Close(); - - // calculate the differences - - this.CalculateAndSaveHashes(files); - - IEnumerable added = files.Where - ( - name => !oldHashes.ContainsKey(name) - ); - - IEnumerable removed = oldHashes.Where - ( - candidate => !this.hashes.ContainsKey(candidate.Key) - ) - .Select - ( - kvp => kvp.Key - ); - - IEnumerable modified = files.Where - ( - name => - { - return oldHashes.TryGetValue(name, out string? oldHash) - && this.hashes.TryGetValue(name, out string? newHash) - && oldHash != newHash; - } - ); - - return new Changes - { - Added = added, - Removed = removed, - Modified = modified - }; - } - - private void CalculateAndSaveHashes - ( - string[] files - ) - { - // note to future, we might want to somewhat parallelize this - // the infrastructure is there, source files can be constructed without doing the much more - // expensive load, but... - foreach (string file in files) - { - SourceFile sourceFile = new(file); - sourceFile.Load(); - - ref string hash = ref this.hashes.GetOrAddValueRef(file); - hash = sourceFile.Hash.ToString(); - } - - using StreamWriter writer = new($"./artifacts/hashes/{name}.json"); - - writer.Write - ( - JsonSerializer.Serialize - ( - new Hashes - { - Values = this.hashes - }, - SerializationContext.Default.Hashes - ) - ); - } - - /// - public string this[string key] => this.hashes[key]; - - /// - public IEnumerable Keys => this.hashes.Select(pair => pair.Key); - - /// - public IEnumerable Values => this.hashes.Select(pair => pair.Value); - - /// - public int Count => this.hashes.Count; - - /// - public bool ContainsKey - ( - string key - ) - => this.hashes.ContainsKey(key); - - /// - public IEnumerator> GetEnumerator() - => this.hashes.GetEnumerator(); - - /// - public bool TryGetValue - ( - string key, - - [MaybeNullWhen(false)] - out string value - ) - { - return this.hashes.TryGetValue - ( - key, - out value - ); - } - - /// - IEnumerator IEnumerable.GetEnumerator() - => this.GetEnumerator(); -} diff --git a/tools/Tools.IncrementalUtility/SourceFile.cs b/tools/Tools.IncrementalUtility/SourceFile.cs deleted file mode 100644 index 71111e9304..0000000000 --- a/tools/Tools.IncrementalUtility/SourceFile.cs +++ /dev/null @@ -1,35 +0,0 @@ -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -using System.IO; -using System.IO.Hashing; - -namespace Tools.IncrementalUtility; - -/// -/// Represents source file information and a hash indicating whether it has changed. -/// -/// The path to this file. -public sealed class SourceFile -( - string path -) -{ - /// - /// Gets the current hash of this file. - /// - public ulong Hash { get; private set; } = 0; - - /// - /// Loads the file and calculates its current hash. This may be called multiple times. - /// - public void Load() - { - XxHash3 hash = new(); - - hash.Append(File.ReadAllBytes(path)); - - this.Hash = hash.GetCurrentHashAsUInt64(); - } -} diff --git a/tools/Tools.IncrementalUtility/Tools.IncrementalUtility.csproj b/tools/Tools.IncrementalUtility/Tools.IncrementalUtility.csproj deleted file mode 100644 index d4d2653612..0000000000 --- a/tools/Tools.IncrementalUtility/Tools.IncrementalUtility.csproj +++ /dev/null @@ -1,16 +0,0 @@ - - - - 0.1.0 - true - - - - - - - - - - - diff --git a/tools/incremental-utility.csx b/tools/incremental-utility.csx new file mode 100644 index 0000000000..13c6705ff5 --- /dev/null +++ b/tools/incremental-utility.csx @@ -0,0 +1,107 @@ +#!/usr/bin/env dotnet-script + +#nullable enable + +#r "nuget:System.IO.Hashing, 8.0.0-rc.2.23479.6" + +using System.Collections.Generic; +using System.IO; +using System.IO.Hashing; +using System.Linq; +using System.Text.Json; + +/// +/// Contains the changes made to files since the last run of the incremental utility. +/// +public sealed record Changes +{ + /// + /// The list of files that have been modified. + /// + public required IReadOnlyList Modified { get; init; } + + /// + /// The list of files that have been added. + /// + public required IReadOnlyList Added { get; init; } + + /// + /// The list of files that have been removed. + /// + public required IReadOnlyList Removed { get; init; } +} + +/// +/// Gets the changes made to the provided files since the last run. +/// +/// The name of the parent tool invoking this functionality. +/// The files covered by the parent tool. +/// A summary of modified, added and removed file paths. +public Changes GetFileChanges(string toolName, params string[] files) +{ + // load and deserialize the current hashes + if (!Directory.Exists("./artifacts/hashes")) + { + Directory.CreateDirectory("./artifacts/hashes"); + } + + if (!File.Exists($"./artifacts/hashes/{name}.json")) + { + File.Create($"./artifacts/hashes/{name}.json").Close(); + CalculateAndSaveHashes(files, toolName); + + return new Changes + { + Added = files, + Removed = Array.Empty(), + Modified = Array.Empty() + } + } + + StreamReader reader = new($"./artifacts/hashes/{name}.json"); + + Dictionary oldHashes = JsonSerializer.Deserialize>(reader.ReadToEnd()); + + reader.Close(); + + Dictionary newHashes = CalculateAndSaveHashes(files, toolName); + + string[] added = files.Where(name => !oldHashes.ContainsKey(name)).ToArray(); + string[] removed = oldHashes.Where(candidate => !newHashes.ContainsKey(candidate.Key)).Select(kvp => kvp.Key).ToArray(); + string[] modified = files.Where + ( + name => + { + return oldHashes.TryGetValue(name, out string? oldHash) + && newHashes.TryGetValue(name, out string? newHash) + && oldHash != newHash; + } + ).ToArray(); + + return new Changes + { + Added = added, + Removed = removed, + Modified = modified + }; +} + +private Dictionary CalculateAndSaveHashes(string[] files, string name) +{ + Dictionary dictionary = new(); + + foreach (string file in files) + { + XxHash3 xxh = new(); + xxh.Append(File.ReadAllBytes(path)); + + string hash = xxh.GetCurrentHashAsUInt64().ToString(); + dictionary.Add(file, hash); + } + + using StreamWriter writer = new($"./artifacts/hashes/{name}.json"); + + writer.Write(JsonSerializer.Serialize(dictionary)); + + return dictionary; +} \ No newline at end of file From 9e88e638ebf8475d384e47852c95ec7ccb712eac Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Thu, 26 Oct 2023 14:23:51 +0200 Subject: [PATCH 168/323] rewrite the model generator tool as csx --- DSharpPlus.sln | 9 - dsharpplus.csx | 20 +- .../ApplicationCommands/ApplicationCommand.cs | 3 +- .../ApplicationCommandOption.cs | 3 +- .../ApplicationCommandOptionChoice.cs | 4 +- .../ApplicationCommandPermission.cs | 3 +- .../Applications/Application.cs | 3 +- .../Applications/InstallParameters.cs | 3 +- .../Applications/PartialApplication.cs | 3 +- .../AuditLogs/AuditLogChange.cs | 3 + .../AuditLogs/AuditLogEntry.cs | 3 +- .../AuditLogs/AuditLogEntryInfo.cs | 3 + .../AutoModeration/AutoModerationAction.cs | 3 +- .../AutoModerationActionMetadata.cs | 4 +- .../AutoModeration/AutoModerationRule.cs | 3 +- .../AutoModerationTriggerMetadata.cs | 3 +- .../BlockMessageActionMetadata.cs | 3 +- .../PartialAutoModerationRule.cs | 3 +- .../SendAlertMessageActionMetadata.cs | 3 +- .../AutoModeration/TimeoutActionMetadata.cs | 3 +- .../Channels/Attachment.cs | 3 +- .../Channels/Channel.cs | 3 +- .../Channels/ChannelMention.cs | 3 +- .../Channels/ChannelOverwrite.cs | 3 +- .../Channels/DefaultReaction.cs | 3 + .../Channels/EmbedAuthor.cs | 3 + .../Channels/EmbedField.cs | 3 + .../Channels/EmbedFooter.cs | 3 + .../Channels/EmbedImage.cs | 3 + .../Channels/EmbedProvider.cs | 3 + .../Channels/EmbedThumbnail.cs | 3 + .../Channels/EmbedVideo.cs | 3 + .../Channels/FollowedChannel.cs | 3 + .../Channels/ForumTag.cs | 3 + .../Channels/Message.cs | 3 +- .../Channels/MessageActivity.cs | 3 +- .../Channels/MessageReference.cs | 3 + .../Channels/PartialAttachment.cs | 3 +- .../Channels/PartialChannel.cs | 3 +- .../Channels/PartialChannelOverwrite.cs | 3 +- .../Channels/PartialMessage.cs | 3 +- .../Channels/Reaction.cs | 3 + .../Channels/RoleSubscriptionData.cs | 3 + .../Entitlements/Entitlement.cs | 3 +- src/core/DSharpPlus.Core.Models/Guilds/Ban.cs | 3 + .../DSharpPlus.Core.Models/Guilds/Guild.cs | 3 +- .../Guilds/GuildMember.cs | 3 +- .../Guilds/GuildWidgetSettings.cs | 3 + .../Guilds/Integration.cs | 3 +- .../Guilds/IntegrationAccount.cs | 3 + .../Guilds/IntegrationApplication.cs | 3 + .../Guilds/Onboarding.cs | 3 +- .../Guilds/OnboardingPrompt.cs | 3 +- .../Guilds/PartialGuild.cs | 3 +- .../Guilds/PartialGuildMember.cs | 3 +- .../Guilds/PartialIntegration.cs | 3 +- .../Guilds/PartialRole.cs | 3 +- .../DSharpPlus.Core.Models/Guilds/Role.cs | 3 +- .../DSharpPlus.Core.Models/Guilds/RoleTags.cs | 3 + .../Guilds/WelcomeScreenChannel.cs | 3 + .../ApplicationCommandInteractionData.cs | 3 +- ...ApplicationCommandInteractionDataOption.cs | 3 +- .../Interactions/Interaction.cs | 3 +- .../Interactions/InteractionResponse.cs | 3 +- .../Interactions/MessageCallbackData.cs | 3 +- .../MessageComponentInteractionData.cs | 3 +- .../Interactions/MessageInteraction.cs | 3 +- .../DSharpPlus.Core.Models/Invites/Invite.cs | 3 +- .../Invites/PartialInvite.cs | 3 +- .../MessageComponents/ActionRowComponent.cs | 3 +- .../MessageComponents/ButtonComponent.cs | 3 +- .../ChannelSelectComponent.cs | 3 +- .../MessageComponents/DefaultSelectValue.cs | 3 + .../MessageComponents/InteractiveComponent.cs | 4 +- .../MentionableSelectComponent.cs | 3 +- .../MessageComponents/RoleSelectComponent.cs | 3 +- .../MessageComponents/SelectOption.cs | 3 + .../StringSelectComponent.cs | 3 +- .../MessageComponents/TextInputComponent.cs | 3 +- .../MessageComponents/UserSelectComponent.cs | 3 +- .../RoleConnections/RoleConnectionMetadata.cs | 3 +- .../ScheduledEvents/PartialScheduledEvent.cs | 3 +- .../ScheduledEvents/ScheduledEvent.cs | 3 +- .../ScheduledEvents/ScheduledEventUser.cs | 3 + src/core/DSharpPlus.Core.Models/Skus/Sku.cs | 3 +- .../StageInstances/PartialStageInstance.cs | 3 +- .../StageInstances/StageInstance.cs | 3 +- .../Stickers/PartialSticker.cs | 3 +- .../Stickers/Sticker.cs | 3 +- .../Stickers/StickerItem.cs | 3 +- .../Teams/TeamMember.cs | 3 +- .../Users/Connection.cs | 3 +- .../Users/PartialUser.cs | 3 +- src/core/DSharpPlus.Core.Models/Users/User.cs | 3 +- .../Voice/VoiceRegion.cs | 3 + .../Webhooks/PartialWebhook.cs | 3 +- .../Webhooks/Webhook.cs | 3 +- .../IApplicationCommandPermissions.cs | 25 + .../Applications/IApplication.cs | 92 ++++ .../AutoModeration/IAutoModerationRule.cs | 47 ++ .../Channels/IAttachment.cs | 53 ++ .../Channels/IChannel.cs | 120 +++++ .../Channels/IChannelOverwrite.cs | 24 + .../Channels/IMessage.cs | 105 ++++ .../Emojis/IEmoji.cs | 37 ++ .../Guilds/IGuild.cs | 140 ++++++ .../Guilds/IGuildMember.cs | 51 ++ .../Guilds/IIntegration.cs | 63 +++ .../Guilds/IRole.cs | 48 ++ .../Invites/IInvite.cs | 62 +++ .../ScheduledEvents/IScheduledEvent.cs | 53 ++ .../StageInstances/IStageInstance.cs | 30 ++ .../Stickers/ISticker.cs | 45 ++ .../Users/IUser.cs | 63 +++ .../Webhooks/IWebhook.cs | 48 ++ tools/Directory.Build.props | 18 - .../Emitter.cs | 49 -- .../Extractor.cs | 62 --- .../Program.cs | 465 ------------------ ....Generators.GenerateConcreteObjects.csproj | 17 - .../generators/generate-concrete-objects.csx | 322 ++++++++++++ tools/generators/parse-interface.csx | 269 ++++++++++ tools/incremental-utility.csx | 12 +- 123 files changed, 1862 insertions(+), 775 deletions(-) create mode 100644 src/core/SharpPlus.Core.Abstractions.Models/ApplicationCommands/IApplicationCommandPermissions.cs create mode 100644 src/core/SharpPlus.Core.Abstractions.Models/Applications/IApplication.cs create mode 100644 src/core/SharpPlus.Core.Abstractions.Models/AutoModeration/IAutoModerationRule.cs create mode 100644 src/core/SharpPlus.Core.Abstractions.Models/Channels/IAttachment.cs create mode 100644 src/core/SharpPlus.Core.Abstractions.Models/Channels/IChannel.cs create mode 100644 src/core/SharpPlus.Core.Abstractions.Models/Channels/IChannelOverwrite.cs create mode 100644 src/core/SharpPlus.Core.Abstractions.Models/Channels/IMessage.cs create mode 100644 src/core/SharpPlus.Core.Abstractions.Models/Emojis/IEmoji.cs create mode 100644 src/core/SharpPlus.Core.Abstractions.Models/Guilds/IGuild.cs create mode 100644 src/core/SharpPlus.Core.Abstractions.Models/Guilds/IGuildMember.cs create mode 100644 src/core/SharpPlus.Core.Abstractions.Models/Guilds/IIntegration.cs create mode 100644 src/core/SharpPlus.Core.Abstractions.Models/Guilds/IRole.cs create mode 100644 src/core/SharpPlus.Core.Abstractions.Models/Invites/IInvite.cs create mode 100644 src/core/SharpPlus.Core.Abstractions.Models/ScheduledEvents/IScheduledEvent.cs create mode 100644 src/core/SharpPlus.Core.Abstractions.Models/StageInstances/IStageInstance.cs create mode 100644 src/core/SharpPlus.Core.Abstractions.Models/Stickers/ISticker.cs create mode 100644 src/core/SharpPlus.Core.Abstractions.Models/Users/IUser.cs create mode 100644 src/core/SharpPlus.Core.Abstractions.Models/Webhooks/IWebhook.cs delete mode 100644 tools/Directory.Build.props delete mode 100644 tools/generators/Tools.Generators.GenerateConcreteObjects/Emitter.cs delete mode 100644 tools/generators/Tools.Generators.GenerateConcreteObjects/Extractor.cs delete mode 100644 tools/generators/Tools.Generators.GenerateConcreteObjects/Program.cs delete mode 100644 tools/generators/Tools.Generators.GenerateConcreteObjects/Tools.Generators.GenerateConcreteObjects.csproj create mode 100644 tools/generators/generate-concrete-objects.csx create mode 100644 tools/generators/parse-interface.csx diff --git a/DSharpPlus.sln b/DSharpPlus.sln index e2b510096c..df0e749b98 100644 --- a/DSharpPlus.sln +++ b/DSharpPlus.sln @@ -11,10 +11,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DSharpPlus.Core.Abstraction EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Core", "Core", "{BC8D8750-48A4-49EF-9D1F-BE4DBA5B500E}" EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tools", "Tools", "{EAC2F7ED-0965-4607-ACE0-829885A612C5}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tools.Generators.GenerateConcreteObjects", "tools\generators\Tools.Generators.GenerateConcreteObjects\Tools.Generators.GenerateConcreteObjects.csproj", "{DF07A6C6-4689-44DC-80B0-479CA7C6AAF6}" -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{EAE89CF5-AA91-4A22-9949-A46FAE1BF0D0}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Core", "Core", "{21927A64-7345-4D90-9EE2-7FA4B1973AAC}" @@ -47,10 +43,6 @@ Global {E14B0AE9-FE71-4DE4-BEB1-4A8E139DB84C}.Debug|Any CPU.Build.0 = Debug|Any CPU {E14B0AE9-FE71-4DE4-BEB1-4A8E139DB84C}.Release|Any CPU.ActiveCfg = Release|Any CPU {E14B0AE9-FE71-4DE4-BEB1-4A8E139DB84C}.Release|Any CPU.Build.0 = Release|Any CPU - {DF07A6C6-4689-44DC-80B0-479CA7C6AAF6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {DF07A6C6-4689-44DC-80B0-479CA7C6AAF6}.Debug|Any CPU.Build.0 = Debug|Any CPU - {DF07A6C6-4689-44DC-80B0-479CA7C6AAF6}.Release|Any CPU.ActiveCfg = Release|Any CPU - {DF07A6C6-4689-44DC-80B0-479CA7C6AAF6}.Release|Any CPU.Build.0 = Release|Any CPU {98D2C52C-E3BA-4564-919C-750775B7BA9C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {98D2C52C-E3BA-4564-919C-750775B7BA9C}.Debug|Any CPU.Build.0 = Debug|Any CPU {98D2C52C-E3BA-4564-919C-750775B7BA9C}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -75,7 +67,6 @@ Global {FBCCE5A7-0E07-4FCF-B9BB-B913F5A17FB2} = {BC8D8750-48A4-49EF-9D1F-BE4DBA5B500E} {964AD252-F077-4AB5-8D92-6C594D08F078} = {BC8D8750-48A4-49EF-9D1F-BE4DBA5B500E} {E14B0AE9-FE71-4DE4-BEB1-4A8E139DB84C} = {BC8D8750-48A4-49EF-9D1F-BE4DBA5B500E} - {DF07A6C6-4689-44DC-80B0-479CA7C6AAF6} = {EAC2F7ED-0965-4607-ACE0-829885A612C5} {21927A64-7345-4D90-9EE2-7FA4B1973AAC} = {EAE89CF5-AA91-4A22-9949-A46FAE1BF0D0} {98D2C52C-E3BA-4564-919C-750775B7BA9C} = {5FBB4590-56B0-453B-A87B-08A17C599B5C} {9F25D892-3CB0-4D47-B67D-D3FFFADC03E0} = {21927A64-7345-4D90-9EE2-7FA4B1973AAC} diff --git a/dsharpplus.csx b/dsharpplus.csx index 9708c94220..ae8338771a 100644 --- a/dsharpplus.csx +++ b/dsharpplus.csx @@ -4,6 +4,7 @@ #r "nuget:Spectre.Console, 0.47.1-preview.0.26" +using System; using System.Diagnostics; using System.Linq; @@ -43,15 +44,16 @@ string[] subsets = // executes a given tool void ExecuteTool(string tool, ToolType type) { - switch (type) + ProcessStartInfo info = new ProcessStartInfo("dotnet"); + info.Arguments = type switch { - case ToolType.Generator: - Process.Start("dotnet", $"script ./tools/generators/{tool}.csx"); - break; - case ToolType.Analyzer: - Process.Start("dotnet", $"script ./tools/analyzers/{tool}.csx"); - break; - } + ToolType.Generator => $"script ./tools/generators/{tool}.csx -c Release", + ToolType.Analyzer => $"script ./tools/analyzers/{tool}.csx -c Release", + _ => throw new InvalidOperationException($"Expected a valid tool type, found {type}.") + }; + + Process process = Process.Start(info)!; + process.WaitForExit(); } // executes all tools belonging to a subject @@ -75,7 +77,7 @@ void ExecuteSubset(string[] subset, ToolType type) // main entrypoint is here, at the big ass help command -if (Args.Count == 1 && Args is ["--help"] or ["-h"] or ["-?"]) +if (Args.Count == 1 && Args is ["--help" or "-h" or "-?"]) { AnsiConsole.MarkupLine ( diff --git a/src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommand.cs b/src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommand.cs index aacb40865d..c57880bd2f 100644 --- a/src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommand.cs +++ b/src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommand.cs @@ -4,9 +4,8 @@ using System.Collections.Generic; -using DSharpPlus.Entities; - using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Entities; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommandOption.cs b/src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommandOption.cs index 8ba3389baf..e8f8a08e87 100644 --- a/src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommandOption.cs +++ b/src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommandOption.cs @@ -4,12 +4,11 @@ using System.Collections.Generic; +using DSharpPlus.Core.Abstractions.Models; using DSharpPlus.Entities; using OneOf; -using DSharpPlus.Core.Abstractions.Models; - namespace DSharpPlus.Core.Models; /// diff --git a/src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommandOptionChoice.cs b/src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommandOptionChoice.cs index 86f1c22ecd..2e999ced3f 100644 --- a/src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommandOptionChoice.cs +++ b/src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommandOptionChoice.cs @@ -4,10 +4,10 @@ using System.Collections.Generic; -using OneOf; - using DSharpPlus.Core.Abstractions.Models; +using OneOf; + namespace DSharpPlus.Core.Models; /// diff --git a/src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommandPermission.cs b/src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommandPermission.cs index 1b844e6170..98311d17f9 100644 --- a/src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommandPermission.cs +++ b/src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommandPermission.cs @@ -2,9 +2,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Entities; - using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Entities; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/Applications/Application.cs b/src/core/DSharpPlus.Core.Models/Applications/Application.cs index a5c283224f..a0186723bd 100644 --- a/src/core/DSharpPlus.Core.Models/Applications/Application.cs +++ b/src/core/DSharpPlus.Core.Models/Applications/Application.cs @@ -4,9 +4,8 @@ using System.Collections.Generic; -using DSharpPlus.Entities; - using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Entities; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/Applications/InstallParameters.cs b/src/core/DSharpPlus.Core.Models/Applications/InstallParameters.cs index 5a3c749450..c8864ad2bd 100644 --- a/src/core/DSharpPlus.Core.Models/Applications/InstallParameters.cs +++ b/src/core/DSharpPlus.Core.Models/Applications/InstallParameters.cs @@ -4,9 +4,8 @@ using System.Collections.Generic; -using DSharpPlus.Entities; - using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Entities; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/Applications/PartialApplication.cs b/src/core/DSharpPlus.Core.Models/Applications/PartialApplication.cs index 674192e2a7..acf645e825 100644 --- a/src/core/DSharpPlus.Core.Models/Applications/PartialApplication.cs +++ b/src/core/DSharpPlus.Core.Models/Applications/PartialApplication.cs @@ -4,9 +4,8 @@ using System.Collections.Generic; -using DSharpPlus.Entities; - using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Entities; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/AuditLogs/AuditLogChange.cs b/src/core/DSharpPlus.Core.Models/AuditLogs/AuditLogChange.cs index faf2d78677..db0702d6f2 100644 --- a/src/core/DSharpPlus.Core.Models/AuditLogs/AuditLogChange.cs +++ b/src/core/DSharpPlus.Core.Models/AuditLogs/AuditLogChange.cs @@ -1,3 +1,6 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/AuditLogs/AuditLogEntry.cs b/src/core/DSharpPlus.Core.Models/AuditLogs/AuditLogEntry.cs index 02af553683..376f91f697 100644 --- a/src/core/DSharpPlus.Core.Models/AuditLogs/AuditLogEntry.cs +++ b/src/core/DSharpPlus.Core.Models/AuditLogs/AuditLogEntry.cs @@ -4,12 +4,11 @@ using System.Collections.Generic; +using DSharpPlus.Core.Abstractions.Models; using DSharpPlus.Entities; using OneOf; -using DSharpPlus.Core.Abstractions.Models; - namespace DSharpPlus.Core.Models; /// diff --git a/src/core/DSharpPlus.Core.Models/AuditLogs/AuditLogEntryInfo.cs b/src/core/DSharpPlus.Core.Models/AuditLogs/AuditLogEntryInfo.cs index 2dfe46b53a..8778315766 100644 --- a/src/core/DSharpPlus.Core.Models/AuditLogs/AuditLogEntryInfo.cs +++ b/src/core/DSharpPlus.Core.Models/AuditLogs/AuditLogEntryInfo.cs @@ -1,3 +1,6 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/AutoModeration/AutoModerationAction.cs b/src/core/DSharpPlus.Core.Models/AutoModeration/AutoModerationAction.cs index 2e9a0e1933..66fd41db9a 100644 --- a/src/core/DSharpPlus.Core.Models/AutoModeration/AutoModerationAction.cs +++ b/src/core/DSharpPlus.Core.Models/AutoModeration/AutoModerationAction.cs @@ -2,9 +2,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Entities; - using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Entities; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/AutoModeration/AutoModerationActionMetadata.cs b/src/core/DSharpPlus.Core.Models/AutoModeration/AutoModerationActionMetadata.cs index af60807425..978cb39e49 100644 --- a/src/core/DSharpPlus.Core.Models/AutoModeration/AutoModerationActionMetadata.cs +++ b/src/core/DSharpPlus.Core.Models/AutoModeration/AutoModerationActionMetadata.cs @@ -7,6 +7,6 @@ namespace DSharpPlus.Core.Models; /// -/// Placeholder implementation for serialization purposes. Please report spotting this to library developers. +/// Placeholder implementation of a marker interface. Please report spotting this to library developers. /// -internal sealed record AutoModerationActionMetadata : IAutoModerationActionMetadata; +internal sealed record AutoModerationActionMetadata : IAutoModerationActionMetadata; \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/AutoModeration/AutoModerationRule.cs b/src/core/DSharpPlus.Core.Models/AutoModeration/AutoModerationRule.cs index b68d2b9610..80413df074 100644 --- a/src/core/DSharpPlus.Core.Models/AutoModeration/AutoModerationRule.cs +++ b/src/core/DSharpPlus.Core.Models/AutoModeration/AutoModerationRule.cs @@ -4,9 +4,8 @@ using System.Collections.Generic; -using DSharpPlus.Entities; - using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Entities; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/AutoModeration/AutoModerationTriggerMetadata.cs b/src/core/DSharpPlus.Core.Models/AutoModeration/AutoModerationTriggerMetadata.cs index 8034bfd363..08416794b5 100644 --- a/src/core/DSharpPlus.Core.Models/AutoModeration/AutoModerationTriggerMetadata.cs +++ b/src/core/DSharpPlus.Core.Models/AutoModeration/AutoModerationTriggerMetadata.cs @@ -4,9 +4,8 @@ using System.Collections.Generic; -using DSharpPlus.Entities; - using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Entities; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/AutoModeration/BlockMessageActionMetadata.cs b/src/core/DSharpPlus.Core.Models/AutoModeration/BlockMessageActionMetadata.cs index eb29e0c7d1..4309f28217 100644 --- a/src/core/DSharpPlus.Core.Models/AutoModeration/BlockMessageActionMetadata.cs +++ b/src/core/DSharpPlus.Core.Models/AutoModeration/BlockMessageActionMetadata.cs @@ -2,9 +2,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Entities; - using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Entities; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/AutoModeration/PartialAutoModerationRule.cs b/src/core/DSharpPlus.Core.Models/AutoModeration/PartialAutoModerationRule.cs index c141364dd4..e500f3eb31 100644 --- a/src/core/DSharpPlus.Core.Models/AutoModeration/PartialAutoModerationRule.cs +++ b/src/core/DSharpPlus.Core.Models/AutoModeration/PartialAutoModerationRule.cs @@ -4,9 +4,8 @@ using System.Collections.Generic; -using DSharpPlus.Entities; - using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Entities; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/AutoModeration/SendAlertMessageActionMetadata.cs b/src/core/DSharpPlus.Core.Models/AutoModeration/SendAlertMessageActionMetadata.cs index 3f2bdec659..9e5f613417 100644 --- a/src/core/DSharpPlus.Core.Models/AutoModeration/SendAlertMessageActionMetadata.cs +++ b/src/core/DSharpPlus.Core.Models/AutoModeration/SendAlertMessageActionMetadata.cs @@ -2,9 +2,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Entities; - using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Entities; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/AutoModeration/TimeoutActionMetadata.cs b/src/core/DSharpPlus.Core.Models/AutoModeration/TimeoutActionMetadata.cs index 83daac471f..0783287bfa 100644 --- a/src/core/DSharpPlus.Core.Models/AutoModeration/TimeoutActionMetadata.cs +++ b/src/core/DSharpPlus.Core.Models/AutoModeration/TimeoutActionMetadata.cs @@ -2,9 +2,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Entities; - using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Entities; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/Channels/Attachment.cs b/src/core/DSharpPlus.Core.Models/Channels/Attachment.cs index 4dc1cfc94a..f1c96bfa59 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/Attachment.cs +++ b/src/core/DSharpPlus.Core.Models/Channels/Attachment.cs @@ -4,9 +4,8 @@ using System; -using DSharpPlus.Entities; - using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Entities; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/Channels/Channel.cs b/src/core/DSharpPlus.Core.Models/Channels/Channel.cs index 80678f123e..d4997fe315 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/Channel.cs +++ b/src/core/DSharpPlus.Core.Models/Channels/Channel.cs @@ -5,9 +5,8 @@ using System; using System.Collections.Generic; -using DSharpPlus.Entities; - using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Entities; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/Channels/ChannelMention.cs b/src/core/DSharpPlus.Core.Models/Channels/ChannelMention.cs index 394996ce0d..4a13f8a031 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/ChannelMention.cs +++ b/src/core/DSharpPlus.Core.Models/Channels/ChannelMention.cs @@ -2,9 +2,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Entities; - using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Entities; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/Channels/ChannelOverwrite.cs b/src/core/DSharpPlus.Core.Models/Channels/ChannelOverwrite.cs index fae3f1c197..8332974eba 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/ChannelOverwrite.cs +++ b/src/core/DSharpPlus.Core.Models/Channels/ChannelOverwrite.cs @@ -2,9 +2,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Entities; - using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Entities; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/Channels/DefaultReaction.cs b/src/core/DSharpPlus.Core.Models/Channels/DefaultReaction.cs index 2525f70146..14a9756cc1 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/DefaultReaction.cs +++ b/src/core/DSharpPlus.Core.Models/Channels/DefaultReaction.cs @@ -1,3 +1,6 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/Channels/EmbedAuthor.cs b/src/core/DSharpPlus.Core.Models/Channels/EmbedAuthor.cs index fb4a03d9e3..5d28fbf216 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/EmbedAuthor.cs +++ b/src/core/DSharpPlus.Core.Models/Channels/EmbedAuthor.cs @@ -1,3 +1,6 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/Channels/EmbedField.cs b/src/core/DSharpPlus.Core.Models/Channels/EmbedField.cs index b99f333194..3507e24174 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/EmbedField.cs +++ b/src/core/DSharpPlus.Core.Models/Channels/EmbedField.cs @@ -1,3 +1,6 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/Channels/EmbedFooter.cs b/src/core/DSharpPlus.Core.Models/Channels/EmbedFooter.cs index d34bac5a08..0d624ea8c7 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/EmbedFooter.cs +++ b/src/core/DSharpPlus.Core.Models/Channels/EmbedFooter.cs @@ -1,3 +1,6 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/Channels/EmbedImage.cs b/src/core/DSharpPlus.Core.Models/Channels/EmbedImage.cs index a0bcf97942..f22964556b 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/EmbedImage.cs +++ b/src/core/DSharpPlus.Core.Models/Channels/EmbedImage.cs @@ -1,3 +1,6 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/Channels/EmbedProvider.cs b/src/core/DSharpPlus.Core.Models/Channels/EmbedProvider.cs index 4499309728..40aab10700 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/EmbedProvider.cs +++ b/src/core/DSharpPlus.Core.Models/Channels/EmbedProvider.cs @@ -1,3 +1,6 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/Channels/EmbedThumbnail.cs b/src/core/DSharpPlus.Core.Models/Channels/EmbedThumbnail.cs index 04c52e0727..9579e15434 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/EmbedThumbnail.cs +++ b/src/core/DSharpPlus.Core.Models/Channels/EmbedThumbnail.cs @@ -1,3 +1,6 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/Channels/EmbedVideo.cs b/src/core/DSharpPlus.Core.Models/Channels/EmbedVideo.cs index 8d34b1c776..df6b63e2c8 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/EmbedVideo.cs +++ b/src/core/DSharpPlus.Core.Models/Channels/EmbedVideo.cs @@ -1,3 +1,6 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/Channels/FollowedChannel.cs b/src/core/DSharpPlus.Core.Models/Channels/FollowedChannel.cs index 9c768a5515..98a636bcee 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/FollowedChannel.cs +++ b/src/core/DSharpPlus.Core.Models/Channels/FollowedChannel.cs @@ -1,3 +1,6 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/Channels/ForumTag.cs b/src/core/DSharpPlus.Core.Models/Channels/ForumTag.cs index f90be4ee41..fbaa76ae5e 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/ForumTag.cs +++ b/src/core/DSharpPlus.Core.Models/Channels/ForumTag.cs @@ -1,3 +1,6 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/Channels/Message.cs b/src/core/DSharpPlus.Core.Models/Channels/Message.cs index a2aeeadcd5..59b91e0600 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/Message.cs +++ b/src/core/DSharpPlus.Core.Models/Channels/Message.cs @@ -5,9 +5,8 @@ using System; using System.Collections.Generic; -using DSharpPlus.Entities; - using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Entities; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/Channels/MessageActivity.cs b/src/core/DSharpPlus.Core.Models/Channels/MessageActivity.cs index 6ee02824bf..7cd3bd67d3 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/MessageActivity.cs +++ b/src/core/DSharpPlus.Core.Models/Channels/MessageActivity.cs @@ -2,9 +2,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Entities; - using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Entities; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/Channels/MessageReference.cs b/src/core/DSharpPlus.Core.Models/Channels/MessageReference.cs index eeceb73537..64f9106e4a 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/MessageReference.cs +++ b/src/core/DSharpPlus.Core.Models/Channels/MessageReference.cs @@ -1,3 +1,6 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/Channels/PartialAttachment.cs b/src/core/DSharpPlus.Core.Models/Channels/PartialAttachment.cs index cf15028f8c..80e789f139 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/PartialAttachment.cs +++ b/src/core/DSharpPlus.Core.Models/Channels/PartialAttachment.cs @@ -4,9 +4,8 @@ using System; -using DSharpPlus.Entities; - using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Entities; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/Channels/PartialChannel.cs b/src/core/DSharpPlus.Core.Models/Channels/PartialChannel.cs index 129c56726e..cbfb226c19 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/PartialChannel.cs +++ b/src/core/DSharpPlus.Core.Models/Channels/PartialChannel.cs @@ -5,9 +5,8 @@ using System; using System.Collections.Generic; -using DSharpPlus.Entities; - using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Entities; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/Channels/PartialChannelOverwrite.cs b/src/core/DSharpPlus.Core.Models/Channels/PartialChannelOverwrite.cs index 7f3bd018d6..7317849c1d 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/PartialChannelOverwrite.cs +++ b/src/core/DSharpPlus.Core.Models/Channels/PartialChannelOverwrite.cs @@ -2,9 +2,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Entities; - using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Entities; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/Channels/PartialMessage.cs b/src/core/DSharpPlus.Core.Models/Channels/PartialMessage.cs index 41a1c94be0..287e26848c 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/PartialMessage.cs +++ b/src/core/DSharpPlus.Core.Models/Channels/PartialMessage.cs @@ -5,9 +5,8 @@ using System; using System.Collections.Generic; -using DSharpPlus.Entities; - using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Entities; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/Channels/Reaction.cs b/src/core/DSharpPlus.Core.Models/Channels/Reaction.cs index 7801178096..c572360385 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/Reaction.cs +++ b/src/core/DSharpPlus.Core.Models/Channels/Reaction.cs @@ -1,3 +1,6 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/Channels/RoleSubscriptionData.cs b/src/core/DSharpPlus.Core.Models/Channels/RoleSubscriptionData.cs index 489b0d0734..335cbcf008 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/RoleSubscriptionData.cs +++ b/src/core/DSharpPlus.Core.Models/Channels/RoleSubscriptionData.cs @@ -1,3 +1,6 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/Entitlements/Entitlement.cs b/src/core/DSharpPlus.Core.Models/Entitlements/Entitlement.cs index f06c6e9166..1e0d33f591 100644 --- a/src/core/DSharpPlus.Core.Models/Entitlements/Entitlement.cs +++ b/src/core/DSharpPlus.Core.Models/Entitlements/Entitlement.cs @@ -4,9 +4,8 @@ using System; -using DSharpPlus.Entities; - using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Entities; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/Guilds/Ban.cs b/src/core/DSharpPlus.Core.Models/Guilds/Ban.cs index be2077d9c1..59a4e90363 100644 --- a/src/core/DSharpPlus.Core.Models/Guilds/Ban.cs +++ b/src/core/DSharpPlus.Core.Models/Guilds/Ban.cs @@ -1,3 +1,6 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/Guilds/Guild.cs b/src/core/DSharpPlus.Core.Models/Guilds/Guild.cs index fcc6df9917..4e011ca0dc 100644 --- a/src/core/DSharpPlus.Core.Models/Guilds/Guild.cs +++ b/src/core/DSharpPlus.Core.Models/Guilds/Guild.cs @@ -4,9 +4,8 @@ using System.Collections.Generic; -using DSharpPlus.Entities; - using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Entities; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/Guilds/GuildMember.cs b/src/core/DSharpPlus.Core.Models/Guilds/GuildMember.cs index e514ca1a3d..6c433a9784 100644 --- a/src/core/DSharpPlus.Core.Models/Guilds/GuildMember.cs +++ b/src/core/DSharpPlus.Core.Models/Guilds/GuildMember.cs @@ -5,9 +5,8 @@ using System; using System.Collections.Generic; -using DSharpPlus.Entities; - using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Entities; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/Guilds/GuildWidgetSettings.cs b/src/core/DSharpPlus.Core.Models/Guilds/GuildWidgetSettings.cs index 5e1cf383cb..8892a812db 100644 --- a/src/core/DSharpPlus.Core.Models/Guilds/GuildWidgetSettings.cs +++ b/src/core/DSharpPlus.Core.Models/Guilds/GuildWidgetSettings.cs @@ -1,3 +1,6 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/Guilds/Integration.cs b/src/core/DSharpPlus.Core.Models/Guilds/Integration.cs index da6e945ee4..2f6c3b24d5 100644 --- a/src/core/DSharpPlus.Core.Models/Guilds/Integration.cs +++ b/src/core/DSharpPlus.Core.Models/Guilds/Integration.cs @@ -5,9 +5,8 @@ using System; using System.Collections.Generic; -using DSharpPlus.Entities; - using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Entities; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/Guilds/IntegrationAccount.cs b/src/core/DSharpPlus.Core.Models/Guilds/IntegrationAccount.cs index d102f4a521..c4b550f10f 100644 --- a/src/core/DSharpPlus.Core.Models/Guilds/IntegrationAccount.cs +++ b/src/core/DSharpPlus.Core.Models/Guilds/IntegrationAccount.cs @@ -1,3 +1,6 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/Guilds/IntegrationApplication.cs b/src/core/DSharpPlus.Core.Models/Guilds/IntegrationApplication.cs index e418b5bdb1..8ce61e64e3 100644 --- a/src/core/DSharpPlus.Core.Models/Guilds/IntegrationApplication.cs +++ b/src/core/DSharpPlus.Core.Models/Guilds/IntegrationApplication.cs @@ -1,3 +1,6 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/Guilds/Onboarding.cs b/src/core/DSharpPlus.Core.Models/Guilds/Onboarding.cs index 7e92bb76f7..4104328091 100644 --- a/src/core/DSharpPlus.Core.Models/Guilds/Onboarding.cs +++ b/src/core/DSharpPlus.Core.Models/Guilds/Onboarding.cs @@ -4,9 +4,8 @@ using System.Collections.Generic; -using DSharpPlus.Entities; - using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Entities; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/Guilds/OnboardingPrompt.cs b/src/core/DSharpPlus.Core.Models/Guilds/OnboardingPrompt.cs index 0b8efd0f6c..7af80e023a 100644 --- a/src/core/DSharpPlus.Core.Models/Guilds/OnboardingPrompt.cs +++ b/src/core/DSharpPlus.Core.Models/Guilds/OnboardingPrompt.cs @@ -4,9 +4,8 @@ using System.Collections.Generic; -using DSharpPlus.Entities; - using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Entities; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/Guilds/PartialGuild.cs b/src/core/DSharpPlus.Core.Models/Guilds/PartialGuild.cs index 7d05390b13..c4456eb8f8 100644 --- a/src/core/DSharpPlus.Core.Models/Guilds/PartialGuild.cs +++ b/src/core/DSharpPlus.Core.Models/Guilds/PartialGuild.cs @@ -4,9 +4,8 @@ using System.Collections.Generic; -using DSharpPlus.Entities; - using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Entities; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/Guilds/PartialGuildMember.cs b/src/core/DSharpPlus.Core.Models/Guilds/PartialGuildMember.cs index 9c0941381f..639e4df778 100644 --- a/src/core/DSharpPlus.Core.Models/Guilds/PartialGuildMember.cs +++ b/src/core/DSharpPlus.Core.Models/Guilds/PartialGuildMember.cs @@ -5,9 +5,8 @@ using System; using System.Collections.Generic; -using DSharpPlus.Entities; - using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Entities; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/Guilds/PartialIntegration.cs b/src/core/DSharpPlus.Core.Models/Guilds/PartialIntegration.cs index bf14169eef..bb2b1e262c 100644 --- a/src/core/DSharpPlus.Core.Models/Guilds/PartialIntegration.cs +++ b/src/core/DSharpPlus.Core.Models/Guilds/PartialIntegration.cs @@ -5,9 +5,8 @@ using System; using System.Collections.Generic; -using DSharpPlus.Entities; - using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Entities; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/Guilds/PartialRole.cs b/src/core/DSharpPlus.Core.Models/Guilds/PartialRole.cs index 6dcc33f008..95136434be 100644 --- a/src/core/DSharpPlus.Core.Models/Guilds/PartialRole.cs +++ b/src/core/DSharpPlus.Core.Models/Guilds/PartialRole.cs @@ -2,9 +2,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Entities; - using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Entities; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/Guilds/Role.cs b/src/core/DSharpPlus.Core.Models/Guilds/Role.cs index c377b9c905..3820f5599a 100644 --- a/src/core/DSharpPlus.Core.Models/Guilds/Role.cs +++ b/src/core/DSharpPlus.Core.Models/Guilds/Role.cs @@ -2,9 +2,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Entities; - using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Entities; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/Guilds/RoleTags.cs b/src/core/DSharpPlus.Core.Models/Guilds/RoleTags.cs index 851644cb23..8d2c6a8fe3 100644 --- a/src/core/DSharpPlus.Core.Models/Guilds/RoleTags.cs +++ b/src/core/DSharpPlus.Core.Models/Guilds/RoleTags.cs @@ -1,3 +1,6 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/Guilds/WelcomeScreenChannel.cs b/src/core/DSharpPlus.Core.Models/Guilds/WelcomeScreenChannel.cs index 212198d01f..5ff7e6dfcd 100644 --- a/src/core/DSharpPlus.Core.Models/Guilds/WelcomeScreenChannel.cs +++ b/src/core/DSharpPlus.Core.Models/Guilds/WelcomeScreenChannel.cs @@ -1,3 +1,6 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/Interactions/ApplicationCommandInteractionData.cs b/src/core/DSharpPlus.Core.Models/Interactions/ApplicationCommandInteractionData.cs index 0f90d3848e..2036460983 100644 --- a/src/core/DSharpPlus.Core.Models/Interactions/ApplicationCommandInteractionData.cs +++ b/src/core/DSharpPlus.Core.Models/Interactions/ApplicationCommandInteractionData.cs @@ -4,9 +4,8 @@ using System.Collections.Generic; -using DSharpPlus.Entities; - using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Entities; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/Interactions/ApplicationCommandInteractionDataOption.cs b/src/core/DSharpPlus.Core.Models/Interactions/ApplicationCommandInteractionDataOption.cs index 0a9f14e718..79c93d3770 100644 --- a/src/core/DSharpPlus.Core.Models/Interactions/ApplicationCommandInteractionDataOption.cs +++ b/src/core/DSharpPlus.Core.Models/Interactions/ApplicationCommandInteractionDataOption.cs @@ -4,12 +4,11 @@ using System.Collections.Generic; +using DSharpPlus.Core.Abstractions.Models; using DSharpPlus.Entities; using OneOf; -using DSharpPlus.Core.Abstractions.Models; - namespace DSharpPlus.Core.Models; /// diff --git a/src/core/DSharpPlus.Core.Models/Interactions/Interaction.cs b/src/core/DSharpPlus.Core.Models/Interactions/Interaction.cs index 21883aec4b..0c58fc45fa 100644 --- a/src/core/DSharpPlus.Core.Models/Interactions/Interaction.cs +++ b/src/core/DSharpPlus.Core.Models/Interactions/Interaction.cs @@ -4,12 +4,11 @@ using System.Collections.Generic; +using DSharpPlus.Core.Abstractions.Models; using DSharpPlus.Entities; using OneOf; -using DSharpPlus.Core.Abstractions.Models; - namespace DSharpPlus.Core.Models; /// diff --git a/src/core/DSharpPlus.Core.Models/Interactions/InteractionResponse.cs b/src/core/DSharpPlus.Core.Models/Interactions/InteractionResponse.cs index 3e52903654..286913311d 100644 --- a/src/core/DSharpPlus.Core.Models/Interactions/InteractionResponse.cs +++ b/src/core/DSharpPlus.Core.Models/Interactions/InteractionResponse.cs @@ -2,12 +2,11 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +using DSharpPlus.Core.Abstractions.Models; using DSharpPlus.Entities; using OneOf; -using DSharpPlus.Core.Abstractions.Models; - namespace DSharpPlus.Core.Models; /// diff --git a/src/core/DSharpPlus.Core.Models/Interactions/MessageCallbackData.cs b/src/core/DSharpPlus.Core.Models/Interactions/MessageCallbackData.cs index 22774ada86..5a4019d051 100644 --- a/src/core/DSharpPlus.Core.Models/Interactions/MessageCallbackData.cs +++ b/src/core/DSharpPlus.Core.Models/Interactions/MessageCallbackData.cs @@ -4,9 +4,8 @@ using System.Collections.Generic; -using DSharpPlus.Entities; - using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Entities; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/Interactions/MessageComponentInteractionData.cs b/src/core/DSharpPlus.Core.Models/Interactions/MessageComponentInteractionData.cs index de1b52dc53..13eab2b36b 100644 --- a/src/core/DSharpPlus.Core.Models/Interactions/MessageComponentInteractionData.cs +++ b/src/core/DSharpPlus.Core.Models/Interactions/MessageComponentInteractionData.cs @@ -4,9 +4,8 @@ using System.Collections.Generic; -using DSharpPlus.Entities; - using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Entities; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/Interactions/MessageInteraction.cs b/src/core/DSharpPlus.Core.Models/Interactions/MessageInteraction.cs index bc76820e4b..14ca9252ef 100644 --- a/src/core/DSharpPlus.Core.Models/Interactions/MessageInteraction.cs +++ b/src/core/DSharpPlus.Core.Models/Interactions/MessageInteraction.cs @@ -2,9 +2,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Entities; - using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Entities; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/Invites/Invite.cs b/src/core/DSharpPlus.Core.Models/Invites/Invite.cs index 4e1664ac83..d52fce132f 100644 --- a/src/core/DSharpPlus.Core.Models/Invites/Invite.cs +++ b/src/core/DSharpPlus.Core.Models/Invites/Invite.cs @@ -4,9 +4,8 @@ using System; -using DSharpPlus.Entities; - using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Entities; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/Invites/PartialInvite.cs b/src/core/DSharpPlus.Core.Models/Invites/PartialInvite.cs index 8d4d4d5ec1..e52268c5f4 100644 --- a/src/core/DSharpPlus.Core.Models/Invites/PartialInvite.cs +++ b/src/core/DSharpPlus.Core.Models/Invites/PartialInvite.cs @@ -4,9 +4,8 @@ using System; -using DSharpPlus.Entities; - using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Entities; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/MessageComponents/ActionRowComponent.cs b/src/core/DSharpPlus.Core.Models/MessageComponents/ActionRowComponent.cs index 0dcaa0a843..1b979d58d1 100644 --- a/src/core/DSharpPlus.Core.Models/MessageComponents/ActionRowComponent.cs +++ b/src/core/DSharpPlus.Core.Models/MessageComponents/ActionRowComponent.cs @@ -4,9 +4,8 @@ using System.Collections.Generic; -using DSharpPlus.Entities; - using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Entities; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/MessageComponents/ButtonComponent.cs b/src/core/DSharpPlus.Core.Models/MessageComponents/ButtonComponent.cs index 8576d4a6b0..7fe38e479e 100644 --- a/src/core/DSharpPlus.Core.Models/MessageComponents/ButtonComponent.cs +++ b/src/core/DSharpPlus.Core.Models/MessageComponents/ButtonComponent.cs @@ -2,9 +2,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Entities; - using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Entities; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/MessageComponents/ChannelSelectComponent.cs b/src/core/DSharpPlus.Core.Models/MessageComponents/ChannelSelectComponent.cs index 9b1329bfee..2b26dfa9a2 100644 --- a/src/core/DSharpPlus.Core.Models/MessageComponents/ChannelSelectComponent.cs +++ b/src/core/DSharpPlus.Core.Models/MessageComponents/ChannelSelectComponent.cs @@ -4,9 +4,8 @@ using System.Collections.Generic; -using DSharpPlus.Entities; - using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Entities; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/MessageComponents/DefaultSelectValue.cs b/src/core/DSharpPlus.Core.Models/MessageComponents/DefaultSelectValue.cs index 595d5d07ca..9eea134cf8 100644 --- a/src/core/DSharpPlus.Core.Models/MessageComponents/DefaultSelectValue.cs +++ b/src/core/DSharpPlus.Core.Models/MessageComponents/DefaultSelectValue.cs @@ -1,3 +1,6 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/MessageComponents/InteractiveComponent.cs b/src/core/DSharpPlus.Core.Models/MessageComponents/InteractiveComponent.cs index 3457bf385c..dcfd83e904 100644 --- a/src/core/DSharpPlus.Core.Models/MessageComponents/InteractiveComponent.cs +++ b/src/core/DSharpPlus.Core.Models/MessageComponents/InteractiveComponent.cs @@ -7,6 +7,6 @@ namespace DSharpPlus.Core.Models; /// -/// Placeholder implementation for serialization purposes. Please report spotting this to library developers. +/// Placeholder implementation of a marker interface. Please report spotting this to library developers. /// -internal sealed record InteractiveComponent : IInteractiveComponent; +internal sealed record InteractiveComponent : IInteractiveComponent; \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/MessageComponents/MentionableSelectComponent.cs b/src/core/DSharpPlus.Core.Models/MessageComponents/MentionableSelectComponent.cs index fdc5132ed2..3ee76006ae 100644 --- a/src/core/DSharpPlus.Core.Models/MessageComponents/MentionableSelectComponent.cs +++ b/src/core/DSharpPlus.Core.Models/MessageComponents/MentionableSelectComponent.cs @@ -4,9 +4,8 @@ using System.Collections.Generic; -using DSharpPlus.Entities; - using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Entities; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/MessageComponents/RoleSelectComponent.cs b/src/core/DSharpPlus.Core.Models/MessageComponents/RoleSelectComponent.cs index 34fab0398d..bd6036a5a6 100644 --- a/src/core/DSharpPlus.Core.Models/MessageComponents/RoleSelectComponent.cs +++ b/src/core/DSharpPlus.Core.Models/MessageComponents/RoleSelectComponent.cs @@ -4,9 +4,8 @@ using System.Collections.Generic; -using DSharpPlus.Entities; - using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Entities; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/MessageComponents/SelectOption.cs b/src/core/DSharpPlus.Core.Models/MessageComponents/SelectOption.cs index ba2509044a..ec910bce9a 100644 --- a/src/core/DSharpPlus.Core.Models/MessageComponents/SelectOption.cs +++ b/src/core/DSharpPlus.Core.Models/MessageComponents/SelectOption.cs @@ -1,3 +1,6 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/MessageComponents/StringSelectComponent.cs b/src/core/DSharpPlus.Core.Models/MessageComponents/StringSelectComponent.cs index c38b5dd981..9ad8d36a21 100644 --- a/src/core/DSharpPlus.Core.Models/MessageComponents/StringSelectComponent.cs +++ b/src/core/DSharpPlus.Core.Models/MessageComponents/StringSelectComponent.cs @@ -4,9 +4,8 @@ using System.Collections.Generic; -using DSharpPlus.Entities; - using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Entities; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/MessageComponents/TextInputComponent.cs b/src/core/DSharpPlus.Core.Models/MessageComponents/TextInputComponent.cs index bfefba0b09..b742f6312c 100644 --- a/src/core/DSharpPlus.Core.Models/MessageComponents/TextInputComponent.cs +++ b/src/core/DSharpPlus.Core.Models/MessageComponents/TextInputComponent.cs @@ -2,9 +2,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Entities; - using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Entities; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/MessageComponents/UserSelectComponent.cs b/src/core/DSharpPlus.Core.Models/MessageComponents/UserSelectComponent.cs index a51b6e7eeb..f618aeb7ff 100644 --- a/src/core/DSharpPlus.Core.Models/MessageComponents/UserSelectComponent.cs +++ b/src/core/DSharpPlus.Core.Models/MessageComponents/UserSelectComponent.cs @@ -4,9 +4,8 @@ using System.Collections.Generic; -using DSharpPlus.Entities; - using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Entities; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/RoleConnections/RoleConnectionMetadata.cs b/src/core/DSharpPlus.Core.Models/RoleConnections/RoleConnectionMetadata.cs index df13680cce..7d72e1391b 100644 --- a/src/core/DSharpPlus.Core.Models/RoleConnections/RoleConnectionMetadata.cs +++ b/src/core/DSharpPlus.Core.Models/RoleConnections/RoleConnectionMetadata.cs @@ -4,9 +4,8 @@ using System.Collections.Generic; -using DSharpPlus.Entities; - using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Entities; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/ScheduledEvents/PartialScheduledEvent.cs b/src/core/DSharpPlus.Core.Models/ScheduledEvents/PartialScheduledEvent.cs index ab8b7f6a6e..4deca40b39 100644 --- a/src/core/DSharpPlus.Core.Models/ScheduledEvents/PartialScheduledEvent.cs +++ b/src/core/DSharpPlus.Core.Models/ScheduledEvents/PartialScheduledEvent.cs @@ -4,9 +4,8 @@ using System; -using DSharpPlus.Entities; - using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Entities; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/ScheduledEvents/ScheduledEvent.cs b/src/core/DSharpPlus.Core.Models/ScheduledEvents/ScheduledEvent.cs index b94c561135..17d478ea07 100644 --- a/src/core/DSharpPlus.Core.Models/ScheduledEvents/ScheduledEvent.cs +++ b/src/core/DSharpPlus.Core.Models/ScheduledEvents/ScheduledEvent.cs @@ -4,9 +4,8 @@ using System; -using DSharpPlus.Entities; - using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Entities; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/ScheduledEvents/ScheduledEventUser.cs b/src/core/DSharpPlus.Core.Models/ScheduledEvents/ScheduledEventUser.cs index 28a3f2a68f..132318c91f 100644 --- a/src/core/DSharpPlus.Core.Models/ScheduledEvents/ScheduledEventUser.cs +++ b/src/core/DSharpPlus.Core.Models/ScheduledEvents/ScheduledEventUser.cs @@ -1,3 +1,6 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/Skus/Sku.cs b/src/core/DSharpPlus.Core.Models/Skus/Sku.cs index c7443ef8ab..0759cc55e4 100644 --- a/src/core/DSharpPlus.Core.Models/Skus/Sku.cs +++ b/src/core/DSharpPlus.Core.Models/Skus/Sku.cs @@ -2,9 +2,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Entities; - using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Entities; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/StageInstances/PartialStageInstance.cs b/src/core/DSharpPlus.Core.Models/StageInstances/PartialStageInstance.cs index 6510a0de45..eb28293664 100644 --- a/src/core/DSharpPlus.Core.Models/StageInstances/PartialStageInstance.cs +++ b/src/core/DSharpPlus.Core.Models/StageInstances/PartialStageInstance.cs @@ -2,9 +2,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Entities; - using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Entities; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/StageInstances/StageInstance.cs b/src/core/DSharpPlus.Core.Models/StageInstances/StageInstance.cs index 4d45b9c7df..986c53260b 100644 --- a/src/core/DSharpPlus.Core.Models/StageInstances/StageInstance.cs +++ b/src/core/DSharpPlus.Core.Models/StageInstances/StageInstance.cs @@ -2,9 +2,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Entities; - using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Entities; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/Stickers/PartialSticker.cs b/src/core/DSharpPlus.Core.Models/Stickers/PartialSticker.cs index 8a43fd20ff..ed77dc1c6b 100644 --- a/src/core/DSharpPlus.Core.Models/Stickers/PartialSticker.cs +++ b/src/core/DSharpPlus.Core.Models/Stickers/PartialSticker.cs @@ -2,9 +2,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Entities; - using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Entities; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/Stickers/Sticker.cs b/src/core/DSharpPlus.Core.Models/Stickers/Sticker.cs index e7c9741b02..e5841f421d 100644 --- a/src/core/DSharpPlus.Core.Models/Stickers/Sticker.cs +++ b/src/core/DSharpPlus.Core.Models/Stickers/Sticker.cs @@ -2,9 +2,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Entities; - using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Entities; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/Stickers/StickerItem.cs b/src/core/DSharpPlus.Core.Models/Stickers/StickerItem.cs index aa9947182c..ebf3da77ed 100644 --- a/src/core/DSharpPlus.Core.Models/Stickers/StickerItem.cs +++ b/src/core/DSharpPlus.Core.Models/Stickers/StickerItem.cs @@ -2,9 +2,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Entities; - using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Entities; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/Teams/TeamMember.cs b/src/core/DSharpPlus.Core.Models/Teams/TeamMember.cs index ff6a22b9ee..11282bd99d 100644 --- a/src/core/DSharpPlus.Core.Models/Teams/TeamMember.cs +++ b/src/core/DSharpPlus.Core.Models/Teams/TeamMember.cs @@ -4,9 +4,8 @@ using System.Collections.Generic; -using DSharpPlus.Entities; - using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Entities; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/Users/Connection.cs b/src/core/DSharpPlus.Core.Models/Users/Connection.cs index e45c3e862a..e1205bed09 100644 --- a/src/core/DSharpPlus.Core.Models/Users/Connection.cs +++ b/src/core/DSharpPlus.Core.Models/Users/Connection.cs @@ -4,9 +4,8 @@ using System.Collections.Generic; -using DSharpPlus.Entities; - using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Entities; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/Users/PartialUser.cs b/src/core/DSharpPlus.Core.Models/Users/PartialUser.cs index d02febf3c6..82ea15bfc9 100644 --- a/src/core/DSharpPlus.Core.Models/Users/PartialUser.cs +++ b/src/core/DSharpPlus.Core.Models/Users/PartialUser.cs @@ -2,9 +2,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Entities; - using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Entities; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/Users/User.cs b/src/core/DSharpPlus.Core.Models/Users/User.cs index a60e78abdb..a49a7f04b6 100644 --- a/src/core/DSharpPlus.Core.Models/Users/User.cs +++ b/src/core/DSharpPlus.Core.Models/Users/User.cs @@ -2,9 +2,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Entities; - using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Entities; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/Voice/VoiceRegion.cs b/src/core/DSharpPlus.Core.Models/Voice/VoiceRegion.cs index 6fd9c671e0..8bb2a41bc4 100644 --- a/src/core/DSharpPlus.Core.Models/Voice/VoiceRegion.cs +++ b/src/core/DSharpPlus.Core.Models/Voice/VoiceRegion.cs @@ -1,3 +1,6 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Models/Webhooks/PartialWebhook.cs b/src/core/DSharpPlus.Core.Models/Webhooks/PartialWebhook.cs index 2cae864712..2fd280354a 100644 --- a/src/core/DSharpPlus.Core.Models/Webhooks/PartialWebhook.cs +++ b/src/core/DSharpPlus.Core.Models/Webhooks/PartialWebhook.cs @@ -2,9 +2,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Entities; - using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Entities; namespace DSharpPlus.Core.Models; diff --git a/src/core/DSharpPlus.Core.Models/Webhooks/Webhook.cs b/src/core/DSharpPlus.Core.Models/Webhooks/Webhook.cs index a9c33bbe35..ad069b9052 100644 --- a/src/core/DSharpPlus.Core.Models/Webhooks/Webhook.cs +++ b/src/core/DSharpPlus.Core.Models/Webhooks/Webhook.cs @@ -2,9 +2,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Entities; - using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Entities; namespace DSharpPlus.Core.Models; diff --git a/src/core/SharpPlus.Core.Abstractions.Models/ApplicationCommands/IApplicationCommandPermissions.cs b/src/core/SharpPlus.Core.Abstractions.Models/ApplicationCommands/IApplicationCommandPermissions.cs new file mode 100644 index 0000000000..e129549546 --- /dev/null +++ b/src/core/SharpPlus.Core.Abstractions.Models/ApplicationCommands/IApplicationCommandPermissions.cs @@ -0,0 +1,25 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record ApplicationCommandPermissions : IApplicationCommandPermissions +{ + /// + public required Snowflake Id { get; init; } + + /// + public required Snowflake ApplicationId { get; init; } + + /// + public required Snowflake GuildId { get; init; } + + /// + public required IReadOnlyList Permissions { get; init; } +} \ No newline at end of file diff --git a/src/core/SharpPlus.Core.Abstractions.Models/Applications/IApplication.cs b/src/core/SharpPlus.Core.Abstractions.Models/Applications/IApplication.cs new file mode 100644 index 0000000000..a0186723bd --- /dev/null +++ b/src/core/SharpPlus.Core.Abstractions.Models/Applications/IApplication.cs @@ -0,0 +1,92 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Entities; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record Application : IApplication +{ + /// + public required Snowflake Id { get; init; } + + /// + public required string Name { get; init; } + + /// + public required string? Icon { get; init; } + + /// + public Optional Description { get; init; } + + /// + public Optional> RpcOrigins { get; init; } + + /// + public required bool BotPublic { get; init; } + + /// + public required bool BotRequireCodeGrant { get; init; } + + /// + public Optional Bot { get; init; } + + /// + public Optional TermsOfServiceUrl { get; init; } + + /// + public Optional PrivacyPolicyUrl { get; init; } + + /// + public Optional Owner { get; init; } + + /// + public required string VerifyKey { get; init; } + + /// + public required ITeam? Team { get; init; } + + /// + public Optional GuildId { get; init; } + + /// + public Optional Guild { get; init; } + + /// + public Optional PrimarySkuId { get; init; } + + /// + public Optional Slug { get; init; } + + /// + public Optional CoverImage { get; init; } + + /// + public Optional Flags { get; init; } + + /// + public Optional ApproximateGuildCount { get; init; } + + /// + public Optional> RedirectUris { get; init; } + + /// + public Optional InteractionsEndpointUrl { get; init; } + + /// + public Optional RoleConnectionsVerificationUrl { get; init; } + + /// + public Optional> Tags { get; init; } + + /// + public Optional InstallParams { get; init; } + + /// + public Optional CustomInstallUrl { get; init; } +} \ No newline at end of file diff --git a/src/core/SharpPlus.Core.Abstractions.Models/AutoModeration/IAutoModerationRule.cs b/src/core/SharpPlus.Core.Abstractions.Models/AutoModeration/IAutoModerationRule.cs new file mode 100644 index 0000000000..80413df074 --- /dev/null +++ b/src/core/SharpPlus.Core.Abstractions.Models/AutoModeration/IAutoModerationRule.cs @@ -0,0 +1,47 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Entities; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record AutoModerationRule : IAutoModerationRule +{ + /// + public required Snowflake Id { get; init; } + + /// + public required Snowflake GuildId { get; init; } + + /// + public required string Name { get; init; } + + /// + public required Snowflake CreatorId { get; init; } + + /// + public required DiscordAutoModerationEventType EventType { get; init; } + + /// + public required DiscordAutoModerationTriggerType TriggerType { get; init; } + + /// + public required IAutoModerationTriggerMetadata TriggerMetadata { get; init; } + + /// + public required IReadOnlyList Actions { get; init; } + + /// + public required bool Enabled { get; init; } + + /// + public required IReadOnlyList ExemptRoles { get; init; } + + /// + public required IReadOnlyList ExemptChannels { get; init; } +} \ No newline at end of file diff --git a/src/core/SharpPlus.Core.Abstractions.Models/Channels/IAttachment.cs b/src/core/SharpPlus.Core.Abstractions.Models/Channels/IAttachment.cs new file mode 100644 index 0000000000..f1c96bfa59 --- /dev/null +++ b/src/core/SharpPlus.Core.Abstractions.Models/Channels/IAttachment.cs @@ -0,0 +1,53 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; + +using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Entities; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record Attachment : IAttachment +{ + /// + public required Snowflake Id { get; init; } + + /// + public required string Filename { get; init; } + + /// + public Optional Description { get; init; } + + /// + public Optional ContentType { get; init; } + + /// + public required int Size { get; init; } + + /// + public required string Url { get; init; } + + /// + public required string ProxyUrl { get; init; } + + /// + public Optional Height { get; init; } + + /// + public Optional Width { get; init; } + + /// + public Optional Ephemeral { get; init; } + + /// + public Optional DurationSecs { get; init; } + + /// + public Optional> Waveform { get; init; } + + /// + public Optional Flags { get; init; } +} \ No newline at end of file diff --git a/src/core/SharpPlus.Core.Abstractions.Models/Channels/IChannel.cs b/src/core/SharpPlus.Core.Abstractions.Models/Channels/IChannel.cs new file mode 100644 index 0000000000..d4997fe315 --- /dev/null +++ b/src/core/SharpPlus.Core.Abstractions.Models/Channels/IChannel.cs @@ -0,0 +1,120 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; +using System.Collections.Generic; + +using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Entities; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record Channel : IChannel +{ + /// + public required Snowflake Id { get; init; } + + /// + public required DiscordChannelType Type { get; init; } + + /// + public Optional GuildId { get; init; } + + /// + public Optional Position { get; init; } + + /// + public Optional> PermissionOverwrites { get; init; } + + /// + public Optional Name { get; init; } + + /// + public Optional Topic { get; init; } + + /// + public Optional Nsfw { get; init; } + + /// + public Optional LastMessageId { get; init; } + + /// + public Optional Bitrate { get; init; } + + /// + public Optional UserLimit { get; init; } + + /// + public Optional RateLimitPerUser { get; init; } + + /// + public Optional> Recipients { get; init; } + + /// + public Optional Icon { get; init; } + + /// + public Optional OwnerId { get; init; } + + /// + public Optional ApplicationId { get; init; } + + /// + public Optional Managed { get; init; } + + /// + public Optional ParentId { get; init; } + + /// + public Optional LastPinTimestamp { get; init; } + + /// + public Optional RtcRegion { get; init; } + + /// + public Optional VideoQualityMode { get; init; } + + /// + public Optional MessageCount { get; init; } + + /// + public Optional MemberCount { get; init; } + + /// + public Optional ThreadMetadata { get; init; } + + /// + public Optional Member { get; init; } + + /// + public Optional DefaultAutoArchiveDuration { get; init; } + + /// + public Optional Permissions { get; init; } + + /// + public Optional Flags { get; init; } + + /// + public Optional TotalMessageSent { get; init; } + + /// + public Optional> AvailableTags { get; init; } + + /// + public Optional> AppliedTags { get; init; } + + /// + public Optional DefaultReactionEmoji { get; init; } + + /// + public Optional DefaultThreadRateLimitPerUser { get; init; } + + /// + public Optional DefaultSortOrder { get; init; } + + /// + public Optional DefaultForumLayout { get; init; } +} \ No newline at end of file diff --git a/src/core/SharpPlus.Core.Abstractions.Models/Channels/IChannelOverwrite.cs b/src/core/SharpPlus.Core.Abstractions.Models/Channels/IChannelOverwrite.cs new file mode 100644 index 0000000000..8332974eba --- /dev/null +++ b/src/core/SharpPlus.Core.Abstractions.Models/Channels/IChannelOverwrite.cs @@ -0,0 +1,24 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Entities; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record ChannelOverwrite : IChannelOverwrite +{ + /// + public required Snowflake Id { get; init; } + + /// + public required DiscordChannelOverwriteType Type { get; init; } + + /// + public required DiscordPermissions Allow { get; init; } + + /// + public required DiscordPermissions Deny { get; init; } +} \ No newline at end of file diff --git a/src/core/SharpPlus.Core.Abstractions.Models/Channels/IMessage.cs b/src/core/SharpPlus.Core.Abstractions.Models/Channels/IMessage.cs new file mode 100644 index 0000000000..59b91e0600 --- /dev/null +++ b/src/core/SharpPlus.Core.Abstractions.Models/Channels/IMessage.cs @@ -0,0 +1,105 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; +using System.Collections.Generic; + +using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Entities; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record Message : IMessage +{ + /// + public required Snowflake Id { get; init; } + + /// + public required Snowflake ChannelId { get; init; } + + /// + public required IUser Author { get; init; } + + /// + public required string Content { get; init; } + + /// + public required DateTimeOffset Timestamp { get; init; } + + /// + public required DateTimeOffset? EditedTimestamp { get; init; } + + /// + public required bool Tts { get; init; } + + /// + public required bool MentionEveryone { get; init; } + + /// + public required IReadOnlyList Mentions { get; init; } + + /// + public required IReadOnlyList MentionRoles { get; init; } + + /// + public Optional> MentionChannels { get; init; } + + /// + public required IReadOnlyList Attachments { get; init; } + + /// + public required IReadOnlyList Embeds { get; init; } + + /// + public Optional> Reactions { get; init; } + + /// + public Optional Nonce { get; init; } + + /// + public required bool Pinned { get; init; } + + /// + public Optional WebhookId { get; init; } + + /// + public required DiscordMessageType Type { get; init; } + + /// + public Optional Activity { get; init; } + + /// + public Optional Application { get; init; } + + /// + public Optional ApplicationId { get; init; } + + /// + public Optional MessageReference { get; init; } + + /// + public Optional Flags { get; init; } + + /// + public Optional ReferencedMessage { get; init; } + + /// + public Optional Interaction { get; init; } + + /// + public Optional Thread { get; init; } + + /// + public Optional> Components { get; init; } + + /// + public Optional StickerItems { get; init; } + + /// + public Optional Position { get; init; } + + /// + public Optional RoleSubscriptionData { get; init; } +} \ No newline at end of file diff --git a/src/core/SharpPlus.Core.Abstractions.Models/Emojis/IEmoji.cs b/src/core/SharpPlus.Core.Abstractions.Models/Emojis/IEmoji.cs new file mode 100644 index 0000000000..ce9e997df1 --- /dev/null +++ b/src/core/SharpPlus.Core.Abstractions.Models/Emojis/IEmoji.cs @@ -0,0 +1,37 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record Emoji : IEmoji +{ + /// + public required Snowflake? Id { get; init; } + + /// + public required string? Name { get; init; } + + /// + public Optional> Roles { get; init; } + + /// + public Optional User { get; init; } + + /// + public Optional RequireColons { get; init; } + + /// + public Optional Managed { get; init; } + + /// + public Optional Animated { get; init; } + + /// + public Optional Available { get; init; } +} \ No newline at end of file diff --git a/src/core/SharpPlus.Core.Abstractions.Models/Guilds/IGuild.cs b/src/core/SharpPlus.Core.Abstractions.Models/Guilds/IGuild.cs new file mode 100644 index 0000000000..4e011ca0dc --- /dev/null +++ b/src/core/SharpPlus.Core.Abstractions.Models/Guilds/IGuild.cs @@ -0,0 +1,140 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Entities; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record Guild : IGuild +{ + /// + public required Snowflake Id { get; init; } + + /// + public required string Name { get; init; } + + /// + public required string? Icon { get; init; } + + /// + public Optional IconHash { get; init; } + + /// + public required string? Splash { get; init; } + + /// + public required string? DiscoverySplash { get; init; } + + /// + public Optional Owner { get; init; } + + /// + public required Snowflake OwnerId { get; init; } + + /// + public Optional Permissions { get; init; } + + /// + public required Snowflake? AfkChannelId { get; init; } + + /// + public required int AfkTimeout { get; init; } + + /// + public Optional WidgetEnabled { get; init; } + + /// + public Optional WidgetChannelId { get; init; } + + /// + public required DiscordVerificationLevel VerificationLevel { get; init; } + + /// + public required DiscordMessageNotificationLevel DefaultMessageNotifications { get; init; } + + /// + public required DiscordExplicitContentFilterLevel ExplicitContentFilter { get; init; } + + /// + public required IReadOnlyList Roles { get; init; } + + /// + public required IReadOnlyList Emojis { get; init; } + + /// + public required IReadOnlyList Features { get; init; } + + /// + public required DiscordMfaLevel MfaLevel { get; init; } + + /// + public required Snowflake? ApplicationId { get; init; } + + /// + public required Snowflake? SystemChannelId { get; init; } + + /// + public required DiscordSystemChannelFlags SystemChannelFlags { get; init; } + + /// + public required Snowflake? RulesChannelId { get; init; } + + /// + public Optional MaxPresences { get; init; } + + /// + public Optional MaxMembers { get; init; } + + /// + public required string? VanityUrlCode { get; init; } + + /// + public required string? Description { get; init; } + + /// + public required string? Banner { get; init; } + + /// + public required int PremiumTier { get; init; } + + /// + public Optional PremiumSubscriptionCount { get; init; } + + /// + public required string PreferredLocale { get; init; } + + /// + public required Snowflake? PublicUpdatesChannelId { get; init; } + + /// + public Optional MaxVideoChannelUsers { get; init; } + + /// + public Optional MaxStageVideoChannelUsers { get; init; } + + /// + public Optional ApproximateMemberCount { get; init; } + + /// + public Optional ApproximatePresenceCount { get; init; } + + /// + public Optional WelcomeScreen { get; init; } + + /// + public required DiscordNsfwLevel NsfwLevel { get; init; } + + /// + public Optional> Stickers { get; init; } + + /// + public required bool PremiumProgressBarEnabled { get; init; } + + /// + public required Snowflake? SafetyAlertsChannelId { get; init; } +} \ No newline at end of file diff --git a/src/core/SharpPlus.Core.Abstractions.Models/Guilds/IGuildMember.cs b/src/core/SharpPlus.Core.Abstractions.Models/Guilds/IGuildMember.cs new file mode 100644 index 0000000000..6c433a9784 --- /dev/null +++ b/src/core/SharpPlus.Core.Abstractions.Models/Guilds/IGuildMember.cs @@ -0,0 +1,51 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; +using System.Collections.Generic; + +using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Entities; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record GuildMember : IGuildMember +{ + /// + public Optional User { get; init; } + + /// + public Optional Nick { get; init; } + + /// + public Optional Avatar { get; init; } + + /// + public required IReadOnlyList Roles { get; init; } + + /// + public required DateTimeOffset JoinedAt { get; init; } + + /// + public Optional PremiumSince { get; init; } + + /// + public required bool Deaf { get; init; } + + /// + public required bool Mute { get; init; } + + /// + public required DiscordGuildMemberFlags Flags { get; init; } + + /// + public Optional Pending { get; init; } + + /// + public Optional Permissions { get; init; } + + /// + public Optional CommunicationDisabledUntil { get; init; } +} \ No newline at end of file diff --git a/src/core/SharpPlus.Core.Abstractions.Models/Guilds/IIntegration.cs b/src/core/SharpPlus.Core.Abstractions.Models/Guilds/IIntegration.cs new file mode 100644 index 0000000000..2f6c3b24d5 --- /dev/null +++ b/src/core/SharpPlus.Core.Abstractions.Models/Guilds/IIntegration.cs @@ -0,0 +1,63 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; +using System.Collections.Generic; + +using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Entities; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record Integration : IIntegration +{ + /// + public required Snowflake Id { get; init; } + + /// + public required string Name { get; init; } + + /// + public required string Type { get; init; } + + /// + public required bool Enabled { get; init; } + + /// + public Optional Syncing { get; init; } + + /// + public Optional RoleId { get; init; } + + /// + public Optional EnableEmoticons { get; init; } + + /// + public Optional ExpireBehaviour { get; init; } + + /// + public Optional ExpireGracePeriod { get; init; } + + /// + public Optional User { get; init; } + + /// + public required IIntegrationAccount Account { get; init; } + + /// + public Optional SyncedAt { get; init; } + + /// + public Optional SubscriberCount { get; init; } + + /// + public Optional Revoked { get; init; } + + /// + public Optional Application { get; init; } + + /// + public Optional> Scopes { get; init; } +} \ No newline at end of file diff --git a/src/core/SharpPlus.Core.Abstractions.Models/Guilds/IRole.cs b/src/core/SharpPlus.Core.Abstractions.Models/Guilds/IRole.cs new file mode 100644 index 0000000000..3820f5599a --- /dev/null +++ b/src/core/SharpPlus.Core.Abstractions.Models/Guilds/IRole.cs @@ -0,0 +1,48 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Entities; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record Role : IRole +{ + /// + public required Snowflake Id { get; init; } + + /// + public required string Name { get; init; } + + /// + public required int Color { get; init; } + + /// + public required bool Hoist { get; init; } + + /// + public Optional Hash { get; init; } + + /// + public Optional UnicodeEmoji { get; init; } + + /// + public required int Position { get; init; } + + /// + public required DiscordPermissions Permissions { get; init; } + + /// + public required bool Managed { get; init; } + + /// + public required bool Mentionable { get; init; } + + /// + public Optional Tags { get; init; } + + /// + public required DiscordRoleFlags Flags { get; init; } +} \ No newline at end of file diff --git a/src/core/SharpPlus.Core.Abstractions.Models/Invites/IInvite.cs b/src/core/SharpPlus.Core.Abstractions.Models/Invites/IInvite.cs new file mode 100644 index 0000000000..d52fce132f --- /dev/null +++ b/src/core/SharpPlus.Core.Abstractions.Models/Invites/IInvite.cs @@ -0,0 +1,62 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; + +using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Entities; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record Invite : IInvite +{ + /// + public required string Code { get; init; } + + /// + public Optional Guild { get; init; } + + /// + public required IPartialChannel? Channel { get; init; } + + /// + public Optional Inviter { get; init; } + + /// + public Optional TargetType { get; init; } + + /// + public Optional TargetUser { get; init; } + + /// + public Optional TargetApplication { get; init; } + + /// + public Optional ApproximatePresenceCount { get; init; } + + /// + public Optional ApproximateMemberCount { get; init; } + + /// + public Optional ExpiresAt { get; init; } + + /// + public Optional GuildScheduledEvent { get; init; } + + /// + public Optional Uses { get; init; } + + /// + public Optional MaxUses { get; init; } + + /// + public Optional MaxAge { get; init; } + + /// + public Optional Temporary { get; init; } + + /// + public Optional CreatedAt { get; init; } +} \ No newline at end of file diff --git a/src/core/SharpPlus.Core.Abstractions.Models/ScheduledEvents/IScheduledEvent.cs b/src/core/SharpPlus.Core.Abstractions.Models/ScheduledEvents/IScheduledEvent.cs new file mode 100644 index 0000000000..17d478ea07 --- /dev/null +++ b/src/core/SharpPlus.Core.Abstractions.Models/ScheduledEvents/IScheduledEvent.cs @@ -0,0 +1,53 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; + +using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Entities; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record ScheduledEvent : IScheduledEvent +{ + /// + public required Snowflake Id { get; init; } + + /// + public required Snowflake GuildId { get; init; } + + /// + public required Snowflake ChannelId { get; init; } + + /// + public Optional CreatorId { get; init; } + + /// + public required string Name { get; init; } + + /// + public Optional Description { get; init; } + + /// + public required DateTimeOffset ScheduledStartTime { get; init; } + + /// + public required DiscordScheduledEventPrivacyLevel PrivacyLevel { get; init; } + + /// + public required DiscordScheduledEventStatus Status { get; init; } + + /// + public required DiscordScheduledEventType EntityType { get; init; } + + /// + public Optional Creator { get; init; } + + /// + public Optional UserCount { get; init; } + + /// + public Optional Image { get; init; } +} \ No newline at end of file diff --git a/src/core/SharpPlus.Core.Abstractions.Models/StageInstances/IStageInstance.cs b/src/core/SharpPlus.Core.Abstractions.Models/StageInstances/IStageInstance.cs new file mode 100644 index 0000000000..986c53260b --- /dev/null +++ b/src/core/SharpPlus.Core.Abstractions.Models/StageInstances/IStageInstance.cs @@ -0,0 +1,30 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Entities; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record StageInstance : IStageInstance +{ + /// + public required Snowflake Id { get; init; } + + /// + public required Snowflake GuildId { get; init; } + + /// + public required Snowflake ChannelId { get; init; } + + /// + public required string Topic { get; init; } + + /// + public required DiscordStagePrivacyLevel PrivacyLevel { get; init; } + + /// + public required Snowflake? GuildScheduledEventId { get; init; } +} \ No newline at end of file diff --git a/src/core/SharpPlus.Core.Abstractions.Models/Stickers/ISticker.cs b/src/core/SharpPlus.Core.Abstractions.Models/Stickers/ISticker.cs new file mode 100644 index 0000000000..e5841f421d --- /dev/null +++ b/src/core/SharpPlus.Core.Abstractions.Models/Stickers/ISticker.cs @@ -0,0 +1,45 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Entities; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record Sticker : ISticker +{ + /// + public required Snowflake Id { get; init; } + + /// + public Optional PackId { get; init; } + + /// + public required string Name { get; init; } + + /// + public required string? Description { get; init; } + + /// + public required string Tags { get; init; } + + /// + public required DiscordStickerType Type { get; init; } + + /// + public required DiscordStickerFormatType FormatType { get; init; } + + /// + public Optional Available { get; init; } + + /// + public Optional GuildId { get; init; } + + /// + public Optional User { get; init; } + + /// + public Optional SortValue { get; init; } +} \ No newline at end of file diff --git a/src/core/SharpPlus.Core.Abstractions.Models/Users/IUser.cs b/src/core/SharpPlus.Core.Abstractions.Models/Users/IUser.cs new file mode 100644 index 0000000000..a49a7f04b6 --- /dev/null +++ b/src/core/SharpPlus.Core.Abstractions.Models/Users/IUser.cs @@ -0,0 +1,63 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Entities; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record User : IUser +{ + /// + public required Snowflake Id { get; init; } + + /// + public required string Username { get; init; } + + /// + public required string Discriminator { get; init; } + + /// + public required string? GlobalName { get; init; } + + /// + public required string? Avatar { get; init; } + + /// + public Optional Bot { get; init; } + + /// + public Optional System { get; init; } + + /// + public Optional MfaEnabled { get; init; } + + /// + public Optional Banner { get; init; } + + /// + public Optional AccentColor { get; init; } + + /// + public Optional Locale { get; init; } + + /// + public Optional Verified { get; init; } + + /// + public Optional Email { get; init; } + + /// + public Optional Flags { get; init; } + + /// + public Optional PremiumType { get; init; } + + /// + public Optional PublicFlags { get; init; } + + /// + public Optional AvatarDecoration { get; init; } +} \ No newline at end of file diff --git a/src/core/SharpPlus.Core.Abstractions.Models/Webhooks/IWebhook.cs b/src/core/SharpPlus.Core.Abstractions.Models/Webhooks/IWebhook.cs new file mode 100644 index 0000000000..ad069b9052 --- /dev/null +++ b/src/core/SharpPlus.Core.Abstractions.Models/Webhooks/IWebhook.cs @@ -0,0 +1,48 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Entities; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record Webhook : IWebhook +{ + /// + public required Snowflake Id { get; init; } + + /// + public required DiscordWebhookType Type { get; init; } + + /// + public Optional GuildId { get; init; } + + /// + public required Snowflake? ChannelId { get; init; } + + /// + public Optional User { get; init; } + + /// + public required string? Name { get; init; } + + /// + public required string? Avatar { get; init; } + + /// + public Optional Token { get; init; } + + /// + public required Snowflake? ApplicationId { get; init; } + + /// + public Optional SourceGuild { get; init; } + + /// + public Optional SourceChannel { get; init; } + + /// + public Optional Url { get; init; } +} \ No newline at end of file diff --git a/tools/Directory.Build.props b/tools/Directory.Build.props deleted file mode 100644 index 1c19ad1e12..0000000000 --- a/tools/Directory.Build.props +++ /dev/null @@ -1,18 +0,0 @@ - - - - - net8.0 - enable - preview - True - $(NoWarn);CS1591 - - - True - true - true - true - - - \ No newline at end of file diff --git a/tools/generators/Tools.Generators.GenerateConcreteObjects/Emitter.cs b/tools/generators/Tools.Generators.GenerateConcreteObjects/Emitter.cs deleted file mode 100644 index 78829c96c7..0000000000 --- a/tools/generators/Tools.Generators.GenerateConcreteObjects/Emitter.cs +++ /dev/null @@ -1,49 +0,0 @@ -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace Tools.Generators.GenerateConcreteObjects; - -public static class Emitter -{ - public static void Emit - ( - StringBuilder writer, - IReadOnlyList<(string, string)> properties, - IReadOnlyList? overwrites = null - ) - { - foreach ((string, string) property in properties) - { - bool required = false; - - string type = property.Item1; - - if (!type.StartsWith("Optional") && !type.EndsWith("?")) - { - required = true; - } - - if (overwrites is not null && overwrites.Contains(property.Item2)) - { - type = type.EndsWith('?') ? $"{type[9..^2]}?" : type[9..^1]; - required = true; - } - - writer.Append - ( -$$""" - /// - public {{(required ? "required " : "")}}{{type}} {{property.Item2}} { get; init; } - - -""" - ); - } - } -} diff --git a/tools/generators/Tools.Generators.GenerateConcreteObjects/Extractor.cs b/tools/generators/Tools.Generators.GenerateConcreteObjects/Extractor.cs deleted file mode 100644 index c27d6377ef..0000000000 --- a/tools/generators/Tools.Generators.GenerateConcreteObjects/Extractor.cs +++ /dev/null @@ -1,62 +0,0 @@ -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -using System.Collections.Generic; -using System.Linq; - -using Microsoft.CodeAnalysis.CSharp; -using Microsoft.CodeAnalysis.CSharp.Syntax; - -namespace Tools.Generators.GenerateConcreteObjects; - -/// -/// Provides a method to extract data from an interface declaration syntax -/// -internal static class Extractor -{ - public static IReadOnlyList<(string, string)> ExtractDefault - ( - InterfaceDeclarationSyntax declaration - ) - { - List<(string, string)> properties = new(); - - foreach (MemberDeclarationSyntax member in declaration.Members) - { - if (member is not PropertyDeclarationSyntax property) - { - continue; - } - - properties.Add((property.Type.ToString(), property.Identifier.ToString())); - } - - return properties; - } - - public static IReadOnlyList ExtractOverwrites - ( - InterfaceDeclarationSyntax declaration - ) - { - List overwrites = new(); - - foreach (MemberDeclarationSyntax member in declaration.Members) - { - if (member is not PropertyDeclarationSyntax property) - { - continue; - } - - if (!property.ChildTokens().Any(token => token.RawKind == (int)SyntaxKind.NewKeyword)) - { - continue; - } - - overwrites.Add(property.Identifier.ToString()); - } - - return overwrites; - } -} diff --git a/tools/generators/Tools.Generators.GenerateConcreteObjects/Program.cs b/tools/generators/Tools.Generators.GenerateConcreteObjects/Program.cs deleted file mode 100644 index 92bf6d1f65..0000000000 --- a/tools/generators/Tools.Generators.GenerateConcreteObjects/Program.cs +++ /dev/null @@ -1,465 +0,0 @@ -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text; - -using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.CSharp; -using Microsoft.CodeAnalysis.CSharp.Syntax; - -using Spectre.Console; - -using Tools.IncrementalUtility; - -namespace Tools.Generators.GenerateConcreteObjects; - -public static class Program -{ - // SYNTAX: - // generate-concrete-objects [abstraction path] [output path] - // it is important to pass the path to the abstraction ROOT, not to the directories containing - // the abstractions files directly - public static int Main(string[] args) - { - // primitive help command - if (args is ["-h" or "--help" or "-?"]) - { - AnsiConsole.MarkupLine - ( - """ - [plum1]DSharpPlus Concrete API Object Generator, v0.1.0[/] - - Usage: generate-concrete-objects path/to/abstractions/root output/path - """ - ); - - return 0; - } - - AnsiConsole.MarkupLine - ( - """ - [plum1]DSharpPlus Concrete API Object Generator, v0.1.0[/] - """ - ); - - string input, output; - - // there are no args passed, proceed with default args: - // args[0] = src/core/DSharpPlus.Core.Abstractions.Models - // args[1] = src/core/DSharpPlus.Core.Models - if (args.Length == 0) - { - input = "src/core/DSharpPlus.Core.Abstractions.Models"; - output = "src/core/DSharpPlus.Core.Models"; - } - // there are args passed, which override the given instructions - // validate the passed arguments are correct - else if (args.Any(path => !Directory.Exists(path))) - { - AnsiConsole.MarkupLine - ( - """ - [red]The paths provided could not be found on the file system.[/] - """ - ); - - return 1; - } - // all args are fine - else - { - input = args[0]; - output = args[1]; - } - - MetadataCollection collection = new("generate-concrete-objects"); - - string[] files = Directory.GetFiles(input, "I*.cs", SearchOption.AllDirectories); - - Changes changes = collection.CalculateDifferences(files); - - if (!changes.Added.Any() && !changes.Modified.Any() && !changes.Removed.Any()) - { - AnsiConsole.MarkupLine - ( - """ - [darkseagreen1_1]There were no changes to the interface definitions, exiting generate-concrete-objects.[/] - """ - ); - - return 0; - } - else - { - AnsiConsole.MarkupLine - ( - $""" - {changes.Added.Count()} added, {changes.Modified.Count()} modified, {changes.Removed.Count()} removed. - """ - ); - } - - if (changes.Removed.Any()) - { - AnsiConsole.MarkupLine - ( - """ - Deleting counterparts to removed files... - """ - ); - } - - foreach (string path in changes.Removed) - { - FileInfo file = new(path); - string fullPath = file.FullName.Replace('\\', '/'); - - int index = fullPath.LastIndexOf('/'); - string deletePath = fullPath.Remove(index + 1, 1).Replace(input, output); - - AnsiConsole.MarkupLine - ( - $""" - Deleting '{deletePath}' - """ - ); - - if (File.Exists(deletePath)) - { - File.Delete(deletePath); - } - } - - if (changes.Added.Any() || changes.Modified.Any()) - { - AnsiConsole.MarkupLine - ( - """ - Generating objects for modified/new definitions... - """ - ); - } - - IEnumerable added = changes.Added.Select - ( - file => - { - FileInfo info = new(file); - return info.FullName.Replace('\\', '/'); - } - ); - - IEnumerable modified = changes.Modified.Select - ( - file => - { - FileInfo info = new(file); - return info.FullName.Replace('\\', '/'); - } - ); - - List emittedFiles = []; - List editedFiles = added.Concat(modified).ToList(); - - for(int i = 0; i < editedFiles.Count; i++) - { - string path = editedFiles[i]; - - CompilationUnitSyntax root = SyntaxFactory.ParseCompilationUnit - ( - File.ReadAllText(path) - ); - - int index = path.LastIndexOf('/'); - string outPath = path.Remove(index + 1, 1).Replace(input, output); - - StringBuilder writer = new(); - StringBuilder usings = new(); - - AnsiConsole.MarkupLine - ( - $""" - Generating {outPath} - """ - ); - - /*usings.AppendLine - ( -""" -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -""" - );*/ - - foreach (UsingDirectiveSyntax @using in root.Usings) - { - usings.Append(@using.ToFullString()); - } - - writer.Append - ( -""" - -using DSharpPlus.Core.Abstractions.Models; - -namespace DSharpPlus.Core.Models; - - -""" - ); - - if - ( - root.Members.First() is not FileScopedNamespaceDeclarationSyntax fileScopedNamespace || - fileScopedNamespace.Members.First() is not InterfaceDeclarationSyntax interfaceSyntax - ) - { - AnsiConsole.MarkupLine - ( - $""" - No interface detected, abandoning generation. - """ - ); - - continue; - } - - IEnumerable tokens = interfaceSyntax.ChildTokens(); - SyntaxToken name = default; - bool found = false; - bool marker = false; - - foreach (SyntaxToken token in tokens) - { - if (token is { RawKind: (int)SyntaxKind.IdentifierToken }) - { - name = token; - found = true; - } - - // detect a marker - if (found && token is { RawKind: (int)SyntaxKind.SemicolonToken }) - { - AnsiConsole.MarkupLine - ( - $""" - Marker interface detected, generating empty implementation. - """ - ); - marker = true; - } - } - - // make sure partial-inheriting interfaces get updated too - if (interfaceSyntax.Identifier.ToString().StartsWith("IPartial")) - { - string fullCandidate = path.Replace("IPartial", "I"); - if (!editedFiles.Contains(fullCandidate)) - { - editedFiles.Add(fullCandidate); - } - } - - FileInfo outInfo = new(outPath); - - if (marker) - { - writer.Clear(); - - writer.AppendLine - ( -$$""" -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -using DSharpPlus.Core.Abstractions.Models; - -namespace DSharpPlus.Core.Models; - -/// -/// Placeholder implementation for serialization purposes. Please report spotting this to library developers. -/// -internal sealed record {{name.Text[1..]}} : {{name.Text}}; -""" - ); - if (!Directory.Exists(outInfo.DirectoryName!)) - { - Directory.CreateDirectory(outInfo.DirectoryName!); - } - - File.WriteAllText(outPath, writer.ToString()); - - emittedFiles.Add(outPath); - - continue; - } - - writer.AppendLine - ( -$$""" -/// -public sealed record {{name.Text[1..]}} : {{name.Text}} -{ -""" - ); - - BaseListSyntax? interfaceList = (BaseListSyntax?)interfaceSyntax.ChildNodes() - .FirstOrDefault - ( - node => node is BaseListSyntax - ); - - if (interfaceList is not null) - { - string? partialCandidate = interfaceList.ChildNodes() - .Where - ( - node => - { - if (node is not SimpleBaseTypeSyntax candidate) - { - return false; - } - - if (node.ChildNodes().First() is not IdentifierNameSyntax identifier) - { - return false; - } - - foreach (SyntaxToken token in identifier.ChildTokens()) - { - if (token is { RawKind: (int)SyntaxKind.IdentifierToken }) - { - if (token.Text.StartsWith("IPartial")) - { - return true; - } - } - } - - return false; - } - ) - .Select - ( - node => - { - foreach (SyntaxToken token in node.ChildNodes().First().ChildTokens()) - { - if (token is { RawKind: (int)SyntaxKind.IdentifierToken }) - { - if (token.Text.StartsWith("IPartial")) - { - return token.Text; - } - } - } - - // unreachable - return null!; - } - ) - .FirstOrDefault(); - - Console.WriteLine($" Partial candidate: {partialCandidate ?? "none"}"); - - if (partialCandidate is not null) - { - // we're dealing with a partial-extending here - string partialPath = path.Replace(interfaceSyntax.Identifier.Text, partialCandidate); - CompilationUnitSyntax partialRoot = SyntaxFactory.ParseCompilationUnit - ( - File.ReadAllText(partialPath) - ); - - if - ( - partialRoot.Members.First() is not FileScopedNamespaceDeclarationSyntax partialFileScopedNamespace || - partialFileScopedNamespace.Members.First() is not InterfaceDeclarationSyntax partialInterfaceSyntax - ) - { - AnsiConsole.MarkupLine - ( - $""" - No partial base interface detected, abandoning generation. - """ - ); - - continue; - } - - usings.Clear(); - - /*usings.AppendLine - ( -""" -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -""" - );*/ - - foreach (UsingDirectiveSyntax @using in partialRoot.Usings) - { - usings.Append(@using.ToFullString()); - } - - Emitter.Emit - ( - writer, - Extractor.ExtractDefault(partialInterfaceSyntax), - Extractor.ExtractOverwrites(interfaceSyntax) - ); - } - else - { - Emitter.Emit - ( - writer, - Extractor.ExtractDefault(interfaceSyntax) - ); - } - } - else - { - Emitter.Emit - ( - writer, - Extractor.ExtractDefault(interfaceSyntax) - ); - } - - writer.Append('}'); - - // ensure the directory at least exists - if (!Directory.Exists(outInfo.DirectoryName!)) - { - Directory.CreateDirectory(outInfo.DirectoryName!); - } - - string code = usings.Append(writer).ToString(); - - // remove the last newline before the final } - // the windows conditional is because of CRLF taking up two characters, vs LF taking up one - code = Environment.NewLine == "\r\n" - ? code.Remove(code.Length - 3, 2) - : code.Remove(code.Length - 2, 1); - - File.WriteAllText(outPath, code); - - emittedFiles.Add(outPath); - } - - return 0; - } -} diff --git a/tools/generators/Tools.Generators.GenerateConcreteObjects/Tools.Generators.GenerateConcreteObjects.csproj b/tools/generators/Tools.Generators.GenerateConcreteObjects/Tools.Generators.GenerateConcreteObjects.csproj deleted file mode 100644 index 79798b83ac..0000000000 --- a/tools/generators/Tools.Generators.GenerateConcreteObjects/Tools.Generators.GenerateConcreteObjects.csproj +++ /dev/null @@ -1,17 +0,0 @@ - - - - 0.1.0 - Exe - - - - - - - - - - - - diff --git a/tools/generators/generate-concrete-objects.csx b/tools/generators/generate-concrete-objects.csx new file mode 100644 index 0000000000..5292916428 --- /dev/null +++ b/tools/generators/generate-concrete-objects.csx @@ -0,0 +1,322 @@ +#!/usr/bin/env dotnet-script + +#nullable enable + +#r "nuget:Microsoft.CodeAnalysis.CSharp, 4.8.0-2.final" +#r "nuget:Spectre.Console, 0.47.1-preview.0.26" + +#load "../incremental-utility.csx" +#load "./parse-interface.csx" + +using System; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading; + +using Spectre.Console; + +// Syntax: +// generate-concrete-objects [abstraction path] [output path] +if (Args is ["-h" or "--help" or "-?"]) +{ + AnsiConsole.MarkupLine + ( + """ + [plum1]DSharpPlus Concrete API Object Generator, v0.2.0[/] + + Usage: generate-concrete-objects.csx [[abstraction root path]] [[output root path]] + """ + ); + + return 0; +} + +AnsiConsole.MarkupLine +( + """ + [plum1]DSharpPlus Concrete API Object Generator, v0.1.0[/] + """ +); + +string input, output; + +// there are no args passed, proceed with default args: +// args[0] = src/core/DSharpPlus.Core.Abstractions.Models +// args[1] = src/core/DSharpPlus.Core.Models +if (Args.Count == 0) +{ + input = "src/core/DSharpPlus.Core.Abstractions.Models"; + output = "src/core/DSharpPlus.Core.Models"; +} + +// there are args passed, which override the given instructions +// validate the passed arguments are correct +else if (Args.Any(path => !Directory.Exists(path))) +{ + AnsiConsole.MarkupLine + ( + """ + [red]The paths provided could not be found on the file system.[/] + """ + ); + + return 1; +} + +// all args are fine +else +{ + input = Args[0]; + output = Args[1]; +} + +string[] files = Directory.GetFiles(input, "I*.cs", SearchOption.AllDirectories); + +files = files + .Select + ( + path => + { + FileInfo file = new(path); + return file.FullName.Replace('\\', '/'); + } + ) + .ToArray(); + +Changes changes = GetFileChanges("generate-concrete-objects", files); + +if (!changes.Added.Any() && !changes.Modified.Any() && !changes.Removed.Any()) +{ + AnsiConsole.MarkupLine + ( + """ + [darkseagreen1_1]There were no changes to the interface definitions, exiting generate-concrete-objects.[/] + """ + ); + + return 0; +} + +AnsiConsole.MarkupLine +( + $""" + {changes.Added.Count} added, {changes.Modified.Count} modified, {changes.Removed.Count} removed. + """ +); + +if (changes.Removed.Any()) +{ + AnsiConsole.MarkupLine("Deleting counterparts to removed files..."); + + Parallel.ForEach + ( + changes.Removed, + path => + { + int index = path.LastIndexOf('/'); + string deletePath = path.Remove(index + 1, 1).Replace(input, output); + + AnsiConsole.MarkupLine($" Deleting '{deletePath}'..."); + + if (File.Exists(deletePath)) + { + File.Delete(deletePath); + } + } + ); +} + +if (changes.Added.Any() || changes.Modified.Any()) +{ + AnsiConsole.MarkupLine("Generating objects for modified/new definitions..."); +} + +IEnumerable added = changes.Added.Select +( + file => + { + FileInfo info = new(file); + return info.FullName.Replace('\\', '/'); + } +); + +IEnumerable modified = changes.Modified.Select +( + file => + { + FileInfo info = new(file); + return info.FullName.Replace('\\', '/'); + } +); + +IEnumerable editedFiles = added.Concat(modified); +List collectedMetadata = editedFiles + .AsParallel() + .Select(path => ParseInterface(path, input)) + .Where(meta => meta is not null) + .Cast() + .AsEnumerable() + .ToList(); + +for (int i = 0; i < collectedMetadata.Count; i++) +{ + InterfaceMetadata metadata = collectedMetadata[i]; + + // make sure we emit the children of partials if the partial was edited + if (metadata.IsPartial) + { + if (!files.Any(candidate => candidate.EndsWith(metadata.Name.Remove(1, 7)))) + { + IEnumerable candidateFiles = Directory.GetFiles(input, $"{metadata.Name.Remove(1, 7)}.cs", SearchOption.AllDirectories); + + if (candidateFiles.Any()) + { + collectedMetadata.Add(ParseInterface(candidateFiles.First(), input)!); + } + } + } + + int index = metadata.Path.LastIndexOf('/'); + string outputPath = metadata.Path.Remove(index + 1, 1).Replace(input, output); + FileInfo info = new(outputPath); + + if (!Directory.Exists(info.DirectoryName!)) + { + Directory.CreateDirectory(info.DirectoryName!); + } + + StringBuilder writer = new(); + + AnsiConsole.MarkupLine($" Generating '{outputPath}'..."); + + // emit a marker type for marker interfaces + if (metadata.IsMarker) + { + writer.Append + ( + $""" + // This Source Code form is subject to the terms of the Mozilla Public + // License, v. 2.0. If a copy of the MPL was not distributed with this + // file, You can obtain one at https://mozilla.org/MPL/2.0/. + + using DSharpPlus.Core.Abstractions.Models; + + namespace DSharpPlus.Core.Models; + + /// + /// Placeholder implementation of a marker interface. Please report spotting this to library developers. + /// + internal sealed record {metadata.Name[1..]} : {metadata.Name}; + """ + ); + + File.WriteAllText(outputPath, writer.ToString()); + continue; + } + + writer.AppendLine + ( + """ + // This Source Code form is subject to the terms of the Mozilla Public + // License, v. 2.0. If a copy of the MPL was not distributed with this + // file, You can obtain one at https://mozilla.org/MPL/2.0/. + + """ + ); + + // we specifically want the grouping here, that's how we group usings together + // this doesn't currently handle using statics, but it doesn't need to just yet + // + // sorting system directives first is annoying, and not strictly necessary, but we want to do it anyway + // we're going to employ a hack and return "!" as the key if it's a system using, which is higher than any + // legal namespace name + IEnumerable> groupedUsings = metadata.UsingDirectives! + .Append("using DSharpPlus.Core.Abstractions.Models;") + .Distinct() + .GroupBy + ( + directive => + { + int index = directive.IndexOf('.'); + int semicolonIndex = directive.IndexOf(';'); + return directive[..(index != -1 ? index : semicolonIndex)]; + } + ) + .OrderBy + ( + group => + { + if (group.First().StartsWith("using System")) + { + return "!"; + } + else + { + string directive = group.First(); + + int index = directive.IndexOf('.'); + int semicolonIndex = directive.IndexOf(';'); + return directive[..(index != -1 ? index : semicolonIndex)]; + } + }, + StringComparer.Ordinal + ); + + foreach(IGrouping group in groupedUsings) + { + writer.AppendLine + ( + $""" + {string.Join('\n', group.OrderBy(name => name))} + + """ + ); + } + + writer.AppendLine + ( + $$""" + namespace DSharpPlus.Core.Models; + + /// + public sealed record {{metadata.Name[1..]}} : {{metadata.Name}} + { + """ + ); + + InterfaceMetadata principal = metadata.PartialParent ?? metadata; + InterfaceMetadata? overwrites = metadata.PartialParent is not null ? metadata : null; + + foreach (PropertyMetadata property in principal.Properties!) + { + bool required = !property.IsOptional && !property.IsNullable; + string type = property.Type; + + // strip optionality if we're being overwritten + if (overwrites is not null && overwrites.Properties!.Any(candidate => candidate.IsOverwrite && candidate.Name == property.Name)) + { + required = !property.IsNullable; + type = type.EndsWith('?') ? $"{type[9..^2]}?" : type[9..^1]; + } + + writer.AppendLine + ( + $$""" + /// + public {{(required ? "required " : "")}}{{type}} {{property.Name}} { get; init; } + + """ + ); + } + + writer.Append('}'); + + string code = writer.ToString(); + + code = code.Remove(code.Length - Environment.NewLine.Length - 1, Environment.NewLine.Length); + + File.WriteAllText(outputPath, code); +} + +return 0; \ No newline at end of file diff --git a/tools/generators/parse-interface.csx b/tools/generators/parse-interface.csx new file mode 100644 index 0000000000..50ac050f81 --- /dev/null +++ b/tools/generators/parse-interface.csx @@ -0,0 +1,269 @@ +#!/usr/bin/env dotnet-script + +#nullable enable + +#r "nuget:Microsoft.CodeAnalysis.CSharp, 4.8.0-2.final" +#r "nuget:Spectre.Console, 0.47.1-preview.0.26" + +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; + +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp; +using Microsoft.CodeAnalysis.CSharp.Syntax; + +using Spectre.Console; + +// this script aims to provide a quick way for all object generators to obtain metadata about the interface they're working with, +// and thus covers all use-cases of these object generators. + +/// +/// Represents metadata about an interface definition. +/// +public sealed record InterfaceMetadata +{ + /// + /// The name of this interface. + /// + public required string Name { get; init; } + + /// + /// The file path of this interface. + /// + public required string Path { get; init; } + + /// + /// Indicates whether this interface is a marker interface. + /// + public required bool IsMarker { get; init; } + + /// + /// Indicates whether this interface is a partial interface, as in, represents a partially populated discord object. + /// + public required bool IsPartial { get; init; } + + /// + /// The properties of this interface. null if is true. + /// + public IReadOnlyList? Properties { get; init; } + + /// + /// Parsed metadata about all parent interfaces, except partial parents. + /// + public IReadOnlyList? ParentInterfaces { get; init; } + + /// + /// The partial parent interface, if present. + /// + public InterfaceMetadata? PartialParent { get; init; } + + /// + /// The using directives used by these files, necessary for referencing their property types. + /// + public IReadOnlyList? UsingDirectives { get; init; } +} + +/// +/// Represents metadata about one specific property. +/// +public readonly record struct PropertyMetadata +{ + /// + /// The declared type of this property. + /// + public required string Type { get; init; } + + /// + /// The declared name of this property. + /// + public required string Name { get; init; } + + /// + /// Indicates whether this property is optional. + /// + public required bool IsOptional { get; init; } + + /// + /// Indicates whether this property is nullable. + /// + public required bool IsNullable { get; init; } + + /// + /// Indicates whether this property overwrites a property in a partial parent, using the new keyword. + /// + /// + public required bool IsOverwrite { get; init; } +} + +/// +/// Parses an interface from a specified file, returning a metadata object if an interface was present. +/// +public InterfaceMetadata? ParseInterface(string filename, string baseDirectory) +{ + CompilationUnitSyntax root = SyntaxFactory.ParseCompilationUnit(File.ReadAllText(filename)); + + List usings = new(); + + foreach (UsingDirectiveSyntax @using in root.Usings) + { + usings.Add(@using.ToString()!); + } + + if + ( + root.Members.First() is not FileScopedNamespaceDeclarationSyntax fileScopedNamespace + || fileScopedNamespace.Members.First() is not InterfaceDeclarationSyntax interfaceSyntax + ) + { + AnsiConsole.MarkupLine($" No interface detected in '{filename}', abandoning..."); + + return null; + } + + IEnumerable tokens = interfaceSyntax.ChildTokens(); + SyntaxToken name = default; + + foreach (SyntaxToken token in tokens) + { + if (token is { RawKind: (int)SyntaxKind.IdentifierToken }) + { + name = token; + } + + if (token is { RawKind: (int)SyntaxKind.SemicolonToken }) + { + AnsiConsole.MarkupLine($" Marker interface detected in '{filename}'."); + + return new() + { + Name = name.Text, + Path = filename, + IsMarker = true, + IsPartial = false + }; + } + } + + // look at parent interfaces and potential partials + BaseListSyntax? baseInterfaceList = (BaseListSyntax?)interfaceSyntax.ChildNodes().FirstOrDefault(node => node is BaseListSyntax); + + string? partialParent = null; + List parents = new(); + + if (baseInterfaceList is not null) + { + foreach (SyntaxNode node in baseInterfaceList.ChildNodes()) + { + if (node is not SimpleBaseTypeSyntax candidate) + { + continue; + } + + if (node.ChildNodes().First() is not IdentifierNameSyntax identifier) + { + continue; + } + + foreach (SyntaxToken token in identifier.ChildTokens()) + { + if (token is { RawKind: (int)SyntaxKind.IdentifierToken }) + { + if (token.Text.StartsWith("IPartial")) + { + partialParent = token.Text; + break; + } + + parents.Add(token.Text); + break; + } + } + } + } + + // start extracting properties. Nullability/optionality checks are very primitive, but they're accurate enough for our use-case + // (which is basically just understanding when to put `required` on an emitted property) + + List properties = new(); + + foreach (MemberDeclarationSyntax member in interfaceSyntax.Members) + { + if (member is not PropertyDeclarationSyntax property) + { + continue; + } + + string type = property.Type.ToString(); + + properties.Add + ( + new() + { + Type = type, + Name = property.Identifier.ToString(), + IsOptional = type.StartsWith("Optional<"), + IsNullable = type.EndsWith('?'), + IsOverwrite = property.ChildTokens().Any(token => token.RawKind == (int)SyntaxKind.NewKeyword) + } + ); + } + + List parentMetadata = new(); + + foreach (string interfaceName in parents) + { + IEnumerable path = Directory.GetFiles(baseDirectory, $"{interfaceName}.cs", SearchOption.AllDirectories); + + if (!path.Any()) + { + continue; + } + + InterfaceMetadata? potentialParent = ParseInterface(path.First(), baseDirectory); + + if (potentialParent is not null) + { + parentMetadata.Add(potentialParent); + } + } + + InterfaceMetadata? partialParentMetadata = null; + + if (partialParent is not null) + { + IEnumerable path = Directory.GetFiles(baseDirectory, $"{partialParent}.cs", SearchOption.AllDirectories); + + if (path.Any()) + { + partialParentMetadata = ParseInterface(path.First(), baseDirectory); + } + } + + // the most painful part of all: consolidate usings + if (partialParentMetadata?.UsingDirectives is not null) + { + usings.AddRange(partialParentMetadata.UsingDirectives); + } + + foreach (InterfaceMetadata i in parentMetadata) + { + if (i.UsingDirectives is not null) + { + usings.AddRange(i.UsingDirectives); + } + } + + return new() + { + Name = name.Text, + Path = filename, + IsMarker = false, + IsPartial = name.Text.StartsWith("IPartial"), + Properties = properties, + ParentInterfaces = parentMetadata, + PartialParent = partialParentMetadata, + UsingDirectives = usings.Distinct().ToArray() + }; +} diff --git a/tools/incremental-utility.csx b/tools/incremental-utility.csx index 13c6705ff5..7e431ed70b 100644 --- a/tools/incremental-utility.csx +++ b/tools/incremental-utility.csx @@ -45,9 +45,9 @@ public Changes GetFileChanges(string toolName, params string[] files) Directory.CreateDirectory("./artifacts/hashes"); } - if (!File.Exists($"./artifacts/hashes/{name}.json")) + if (!File.Exists($"./artifacts/hashes/{toolName}.json")) { - File.Create($"./artifacts/hashes/{name}.json").Close(); + File.Create($"./artifacts/hashes/{toolName}.json").Close(); CalculateAndSaveHashes(files, toolName); return new Changes @@ -55,12 +55,12 @@ public Changes GetFileChanges(string toolName, params string[] files) Added = files, Removed = Array.Empty(), Modified = Array.Empty() - } + }; } - StreamReader reader = new($"./artifacts/hashes/{name}.json"); + StreamReader reader = new($"./artifacts/hashes/{toolName}.json"); - Dictionary oldHashes = JsonSerializer.Deserialize>(reader.ReadToEnd()); + Dictionary oldHashes = JsonSerializer.Deserialize>(reader.ReadToEnd())!; reader.Close(); @@ -93,7 +93,7 @@ private Dictionary CalculateAndSaveHashes(string[] files, string foreach (string file in files) { XxHash3 xxh = new(); - xxh.Append(File.ReadAllBytes(path)); + xxh.Append(File.ReadAllBytes(file)); string hash = xxh.GetCurrentHashAsUInt64().ToString(); dictionary.Add(file, hash); From 0f4e430a09dd70085d7869233824955eea4fec34 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Mon, 30 Oct 2023 18:21:43 +0100 Subject: [PATCH 169/323] plerx' favourite API call --- Directory.Packages.props | 3 +- .../API/IAuditLogsRestAPI.cs | 43 ++++++++++++ .../AttachmentData.cs | 28 ++++++++ .../DSharpPlus.Core.Abstractions.Rest.csproj | 9 ++- .../IRatelimitCallbackInfo.cs | 53 ++++++++++++++ .../RequestInfo.cs | 44 ++++++++++++ .../RetryMode.cs | 70 +++++++++++++++++++ 7 files changed, 246 insertions(+), 4 deletions(-) create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/API/IAuditLogsRestAPI.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/AttachmentData.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/IRatelimitCallbackInfo.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/RequestInfo.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/RetryMode.cs diff --git a/Directory.Packages.props b/Directory.Packages.props index 10af9e679e..b7a07b2aa9 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -13,9 +13,10 @@ + - + diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IAuditLogsRestAPI.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IAuditLogsRestAPI.cs new file mode 100644 index 0000000000..69fe9ae2a7 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IAuditLogsRestAPI.cs @@ -0,0 +1,43 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Threading; +using System.Threading.Tasks; + +using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Entities; + +using Remora.Results; + +namespace DSharpPlus.Core.Abstractions.Rest.API; + +/// +/// Provides access to audit log related rest API calls. +/// +public interface IAuditLogsRestAPI +{ + /// + /// Lists audit log entries for a given guild. + /// + /// The snowflake identifier of the guild to list audit logs for. + /// If specified, only lists entries from this user ID. + /// If specified, only lists entries of this audit log event type. + /// If specified, only lists entries with an ID less than this ID. + /// If specified, only lists entries with an ID greater than this ID. + /// The maximum number of entries, between 1 and 100. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + /// An audit log object, containing all relevant other entities and the main audit log. + public ValueTask> ListGuildAuditLogEntriesAsync + ( + Snowflake guildId, + Snowflake? userId = null, + DiscordAuditLogEvent? actionType = null, + Snowflake? before = null, + Snowflake? after = null, + int? limit = null, + RequestInfo info = default, + CancellationToken ct = default + ); +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/AttachmentData.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/AttachmentData.cs new file mode 100644 index 0000000000..186dcf29b2 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/AttachmentData.cs @@ -0,0 +1,28 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.IO.Pipelines; + +namespace DSharpPlus.Core.Abstractions.Rest; + +/// +/// Contains the information necessary for sending an attachment to Discord. +/// +public readonly record struct AttachmentData +{ + /// + /// The filename as uploaded to Discord. + /// + public required string Name { get; init; } + + /// + /// An optional description/alt text for this file. + /// + public string? Description { get; init; } + + /// + /// A pipe with the contents of the file. + /// + public required PipeReader Content { get; init; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/DSharpPlus.Core.Abstractions.Rest.csproj b/src/core/DSharpPlus.Core.Abstractions.Rest/DSharpPlus.Core.Abstractions.Rest.csproj index ca4f8cf3ba..e950a62df5 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/DSharpPlus.Core.Abstractions.Rest.csproj +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/DSharpPlus.Core.Abstractions.Rest.csproj @@ -5,9 +5,12 @@ - + + + + + + diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/IRatelimitCallbackInfo.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/IRatelimitCallbackInfo.cs new file mode 100644 index 0000000000..1f6ce77d15 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/IRatelimitCallbackInfo.cs @@ -0,0 +1,53 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; + +namespace DSharpPlus.Core.Abstractions.Rest; + +/// +/// Represents information and operations on a callback. +/// +public interface IRatelimitCallbackInfo +{ + /// + /// Indicates whether the encountered ratelimit is a global ratelimit. + /// + public bool IsGlobalRatelimit { get; } + + /// + /// The now-exhausted limit of this bucket. + /// + public int Limit { get; } + + /// + /// The timestamp at which this ratelimit bucket will reset and be freed up. + /// + public DateTimeOffset Reset { get; } + + /// + /// The route this request sent over. + /// + public string Route { get; } + + /// + /// The hash of the encountered ratelimit bucket. + /// + public string Hash { get; } + + /// + /// Indicates whether this request can retry without user interaction. + /// + public bool MayRetry { get; } + + /// + /// Cancels all retries and forcibly ends this request's lifespan. + /// + public void CancelRetries(); + + /// + /// Forces this request to retry, even if it wouldn't have otherwise. + /// + public void Retry(); +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/RequestInfo.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/RequestInfo.cs new file mode 100644 index 0000000000..cabf719741 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/RequestInfo.cs @@ -0,0 +1,44 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; +using System.Threading.Tasks; + +namespace DSharpPlus.Core.Abstractions.Rest; + +/// +/// Contains additional instructions on how to execute a request. +/// +public readonly record struct RequestInfo +{ + /// + /// The maximum time to wait for this request, in milliseconds. + /// + /// + /// If a ratelimit is triggered for this request and it cannot be retried in time, this request will fail + /// immediately. null specifies no timeout, which is the default. + /// + public int? Timeout { get; init; } + + /// + /// The maximum amount of retries to make for this request. + /// + /// + /// null falls back to the underlying rest clients discretion. + /// + public int? MaxRetries { get; init; } + + /// + /// A set of flags to specify retrying behaviour. + /// + /// + /// null falls back to the underlying rest clients discretion. + /// + public RetryMode? RetryMode { get; init; } + + /// + /// An asynchronous callback to execute when the ratelimit fails. + /// + public Func? RatelimitCallback { get; init; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/RetryMode.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/RetryMode.cs new file mode 100644 index 0000000000..edb838f87f --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/RetryMode.cs @@ -0,0 +1,70 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; + +namespace DSharpPlus.Core.Abstractions.Rest; + +/// +/// Specifies behaviour flags to apply to retrying a request. +/// +[Flags] +public enum RetryMode +{ + /// + /// No options, behave as the rest client default. + /// + None = 0, + + /// + /// Suppresses executing a configured . + /// + SuppressCallback = 1 << 1, + + /// + /// If any error is encountered, excluding a pre-emptive ratelimit, fail immediately. + /// + AlwaysFailExcludingPreemptive = 1 << 2, + + /// + /// If any error is encountered, including a pre-emptive ratelimit, fail immediately. + /// + AlwaysFail = 1 << 3, + + /// + /// Retry on 5xx errors. + /// + Retry5xx = 1 << 4, + + /// + /// Skips retrying on preemptive ratelimits. + /// + DoNotRetryPreemptiveRatelimit = 1 << 5, + + /// + /// Retry on discord-returned ratelimits, except global ratelimits. + /// + RetryDiscordRatelimit = 1 << 6, + + /// + /// Retry on global ratelimits. + /// + RetryGlobalRatelimit = 1 << 7, + + /// + /// Skip request validation. This should be used only with the greatest care. + /// + SkipValidation = 1 << 8, + + /// + /// Convenience combination for always retrying on ratelimits and 5xx errors. + /// + AlwaysRetry = Retry5xx | RetryDiscordRatelimit | RetryGlobalRatelimit, + + /// + /// Convenience combination for always retrying on non-global ratelimits and 5xx errors, as global ratelimits + /// can take untenably long times to complete. + /// + AlwaysRetryNonGlobal = Retry5xx | RetryDiscordRatelimit +} From b5603b93e190b89c9b4ac0eed8c7fe741e2594d4 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Tue, 31 Oct 2023 20:01:25 +0100 Subject: [PATCH 170/323] add caching-related request info options --- .../DSharpPlus.Core.Abstractions.Rest/RequestInfo.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/RequestInfo.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/RequestInfo.cs index cabf719741..5261923d01 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/RequestInfo.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/RequestInfo.cs @@ -37,6 +37,16 @@ public readonly record struct RequestInfo /// public RetryMode? RetryMode { get; init; } + /// + /// Specifies whether to skip updating the cache after making a request. + /// + public bool SkipUpdatingCache { get; init; } + + /// + /// Specifies whether to skip asking cache for whether it already has the requested information. + /// + public bool SkipCache { get; init; } + /// /// An asynchronous callback to execute when the ratelimit fails. /// From 0d7ed990b755a01f40d54c101acf114152912af7 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Thu, 2 Nov 2023 17:41:48 +0100 Subject: [PATCH 171/323] standardize errors for rest impls --- .../Errors/HttpError.cs | 36 +++++++++++++++++++ .../Errors/ValidationError.cs | 23 ++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/Errors/HttpError.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/Errors/ValidationError.cs diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Errors/HttpError.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/Errors/HttpError.cs new file mode 100644 index 0000000000..eca0e331b9 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/Errors/HttpError.cs @@ -0,0 +1,36 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Net; + +using Remora.Results; + +namespace DSharpPlus.Core.Abstractions.Rest.Errors; + +/// +/// Represents a HTTP error returned by an API call. +/// +public sealed record HttpError : ResultError +{ + /// + /// The encountered status code. + /// + public required HttpStatusCode StatusCode { get; init; } + + /// + /// Initializes a new HttpError from the provided status code and message. + /// + /// The HTTP status encountered. + /// + /// The error message, either a synthesized human-readable error or the error string returned + /// by Discord, which may be parsed programmatically. + /// + public HttpError + ( + HttpStatusCode statusCode, + string? message = null + ) + : base(message ?? $"Encountered HTTP status code {(ulong)statusCode}: {statusCode}") + => this.StatusCode = statusCode; +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Errors/ValidationError.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/Errors/ValidationError.cs new file mode 100644 index 0000000000..0bf46050c9 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/Errors/ValidationError.cs @@ -0,0 +1,23 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using Remora.Results; + +namespace DSharpPlus.Core.Abstractions.Rest.Errors; + +/// +/// Represents an error encountered during parameter validation. +/// +public sealed record ValidationError : ResultError +{ + /// + /// Initializes a new validation error. + /// + /// The human-readable error message. + public ValidationError(string message) + : base(message) + { + + } +} From c44fe5e9a1bd0b9a11f16ecf846a637aadc197b2 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Thu, 2 Nov 2023 18:52:44 +0100 Subject: [PATCH 172/323] get global application command --- .../API/IApplicationCommandsRestAPI.cs | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/API/IApplicationCommandsRestAPI.cs diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IApplicationCommandsRestAPI.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IApplicationCommandsRestAPI.cs new file mode 100644 index 0000000000..d2888ea8e1 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IApplicationCommandsRestAPI.cs @@ -0,0 +1,36 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; + +using DSharpPlus.Core.Abstractions.Models; + +using Remora.Results; + +namespace DSharpPlus.Core.Abstractions.Rest.API; + +/// +/// Provides access to application commands-related API calls. +/// +// https://discord.com/developers/docs/interactions/application-commands +public interface IApplicationCommandsRestAPI +{ + /// + /// Fetches all global application commands for your application. + /// + /// The snowflake identifier of your application. + /// Indicates whether to include full localizations in the returned objects. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + /// An array of application commands. + public ValueTask>> GetGlobalApplicationCommandsAsync + ( + Snowflake applicationId, + bool? withLocalizations = null, + RequestInfo info = default, + CancellationToken ct = default + ); +} From 321b03c851bbdd933e502241204d568180f89278 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Thu, 2 Nov 2023 19:19:06 +0100 Subject: [PATCH 173/323] create global application commands --- .../API/IApplicationCommandsRestAPI.cs | 18 ++++++ .../ICreateGlobalApplicationCommandPayload.cs | 55 +++++++++++++++++++ .../CreateApplicationCommandResponse.cs | 23 ++++++++ 3 files changed, 96 insertions(+) create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/ApplicationCommands/ICreateGlobalApplicationCommandPayload.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/Responses/CreateApplicationCommandResponse.cs diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IApplicationCommandsRestAPI.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IApplicationCommandsRestAPI.cs index d2888ea8e1..3bf4f05571 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IApplicationCommandsRestAPI.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IApplicationCommandsRestAPI.cs @@ -7,6 +7,8 @@ using System.Threading.Tasks; using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Core.Abstractions.Rest.Payloads; +using DSharpPlus.Core.Abstractions.Rest.Responses; using Remora.Results; @@ -33,4 +35,20 @@ public ValueTask>> GetGlobalApplicatio RequestInfo info = default, CancellationToken ct = default ); + + /// + /// Creates a new global application command for your application. + /// + /// The snowflake identifier of your application. + /// The command you wish to create. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + /// A value indicating whether this command was newly created as well as the command object. + public ValueTask> CreateGlobalApplicationCommand + ( + Snowflake applicationId, + ICreateGlobalApplicationCommandPayload payload, + RequestInfo info = default, + CancellationToken ct = default + ); } diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/ApplicationCommands/ICreateGlobalApplicationCommandPayload.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/ApplicationCommands/ICreateGlobalApplicationCommandPayload.cs new file mode 100644 index 0000000000..80baa2d894 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/ApplicationCommands/ICreateGlobalApplicationCommandPayload.cs @@ -0,0 +1,55 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Entities; + +namespace DSharpPlus.Core.Abstractions.Rest.Payloads; + +/// +/// Represents a payload to POST /applications/:application-id/commands. +/// +public interface ICreateGlobalApplicationCommandPayload +{ + /// + /// The name of this command, between 1 and 32 characters. + /// + public string Name { get; } + + /// + /// A localization dictionary for the field. Values follow the same restrictions. + /// + public Optional?> NameLocalizations { get; } + + /// + /// The description for this chat input command, between 1 and 100 characters. + /// + public Optional Description { get; } + + /// + /// A localization dictionary for the field. Values follow the same restrictions. + /// + public Optional?> DescriptionLocalizations { get; } + + /// + /// The default permissions needed to see this command. + /// + public Optional DefaultMemberPermissions { get; } + + /// + /// Indicates whether this command is available in DMs with this app. + /// + public Optional DmPermission { get; } + + /// + /// The type of this command. + /// + public Optional Type { get; } + + /// + /// Indicates whether this command is age-restricted. + /// + public Optional Nsfw { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Responses/CreateApplicationCommandResponse.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/Responses/CreateApplicationCommandResponse.cs new file mode 100644 index 0000000000..956d83457f --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/Responses/CreateApplicationCommandResponse.cs @@ -0,0 +1,23 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Abstractions.Rest.Responses; + +/// +/// Represents the information returned by POST /applications/:application-id/commands. +/// +public readonly record struct CreateApplicationCommandResponse +{ + /// + /// Indicates whether this command was newly created or whether it already existed. + /// + public required bool IsNewlyCreated { get; init; } + + /// + /// The created command. + /// + public required IApplicationCommand CreatedCommand { get; init; } +} From b02e19ca9bedc14ec4ba88e3e19ff378eb7a3073 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Thu, 2 Nov 2023 19:22:53 +0100 Subject: [PATCH 174/323] get global application command --- .../API/IApplicationCommandsRestAPI.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IApplicationCommandsRestAPI.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IApplicationCommandsRestAPI.cs index 3bf4f05571..dcc5dc2f21 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IApplicationCommandsRestAPI.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IApplicationCommandsRestAPI.cs @@ -51,4 +51,20 @@ public ValueTask> CreateGlobalApplicati RequestInfo info = default, CancellationToken ct = default ); + + /// + /// Fetches a global application command for your application. + /// + /// The snowflake identifier of your application. + /// The snowflake identifier of the command to fetch. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + /// The requested application command. + public ValueTask> GetGlobalApplicationCommand + ( + Snowflake applicationId, + Snowflake commandId, + RequestInfo info = default, + CancellationToken ct = default + ); } From 63ab35ea4d9134e641c60d2ba22b871efeaba597 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Thu, 2 Nov 2023 19:25:51 +0100 Subject: [PATCH 175/323] edit global application commands --- .../API/IApplicationCommandsRestAPI.cs | 22 +++++++- .../IEditGlobalApplicationCommandPayload.cs | 54 +++++++++++++++++++ 2 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/ApplicationCommands/IEditGlobalApplicationCommandPayload.cs diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IApplicationCommandsRestAPI.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IApplicationCommandsRestAPI.cs index dcc5dc2f21..6c9aa8d4b3 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IApplicationCommandsRestAPI.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IApplicationCommandsRestAPI.cs @@ -44,7 +44,7 @@ public ValueTask>> GetGlobalApplicatio /// Additional instructions regarding this request. /// A cancellation token for this operation. /// A value indicating whether this command was newly created as well as the command object. - public ValueTask> CreateGlobalApplicationCommand + public ValueTask> CreateGlobalApplicationCommandAsync ( Snowflake applicationId, ICreateGlobalApplicationCommandPayload payload, @@ -60,11 +60,29 @@ public ValueTask> CreateGlobalApplicati /// Additional instructions regarding this request. /// A cancellation token for this operation. /// The requested application command. - public ValueTask> GetGlobalApplicationCommand + public ValueTask> GetGlobalApplicationCommandAsync ( Snowflake applicationId, Snowflake commandId, RequestInfo info = default, CancellationToken ct = default ); + + /// + /// Edits a global application command for your application. + /// + /// The snowflake identifier of your application. + /// The snowflake identifier of the command to edit. + /// A payload containing the fields to edit with their new values. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + /// The requested application command. + public ValueTask> EditGlobalApplicationCommandAsync + ( + Snowflake applicationId, + Snowflake commandId, + IEditGlobalApplicationCommandPayload payload, + RequestInfo info = default, + CancellationToken ct = default + ); } diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/ApplicationCommands/IEditGlobalApplicationCommandPayload.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/ApplicationCommands/IEditGlobalApplicationCommandPayload.cs new file mode 100644 index 0000000000..d2742c3501 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/ApplicationCommands/IEditGlobalApplicationCommandPayload.cs @@ -0,0 +1,54 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Entities; +using System.Collections.Generic; + +namespace DSharpPlus.Core.Abstractions.Rest.Payloads; + +/// +/// Represents a payload to PATCH /applications/:application-id/commands/:command-id. +/// +public interface IEditGlobalApplicationCommandPayload +{ + /// + /// The name of this command, between 1 and 32 characters. + /// + public Optional Name { get; } + + /// + /// A localization dictionary for the field. Values follow the same restrictions. + /// + public Optional?> NameLocalizations { get; } + + /// + /// The description for this chat input command, between 1 and 100 characters. + /// + public Optional Description { get; } + + /// + /// A localization dictionary for the field. Values follow the same restrictions. + /// + public Optional?> DescriptionLocalizations { get; } + + /// + /// The default permissions needed to see this command. + /// + public Optional DefaultMemberPermissions { get; } + + /// + /// Indicates whether this command is available in DMs with this app. + /// + public Optional DmPermission { get; } + + /// + /// The type of this command. + /// + public Optional Type { get; } + + /// + /// Indicates whether this command is age-restricted. + /// + public Optional Nsfw { get; } +} From c612fdc79f3842525852fe1ed0875369ed03c061 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Thu, 2 Nov 2023 19:27:58 +0100 Subject: [PATCH 176/323] delete global application command --- .../API/IApplicationCommandsRestAPI.cs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IApplicationCommandsRestAPI.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IApplicationCommandsRestAPI.cs index 6c9aa8d4b3..a394f959be 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IApplicationCommandsRestAPI.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IApplicationCommandsRestAPI.cs @@ -76,7 +76,7 @@ public ValueTask> GetGlobalApplicationCommandAsync /// A payload containing the fields to edit with their new values. /// Additional instructions regarding this request. /// A cancellation token for this operation. - /// The requested application command. + /// The edited application command. public ValueTask> EditGlobalApplicationCommandAsync ( Snowflake applicationId, @@ -85,4 +85,20 @@ public ValueTask> EditGlobalApplicationCommandAsync RequestInfo info = default, CancellationToken ct = default ); + + /// + /// Deletes a global application command for your application. + /// + /// The snowflake identifier of your application. + /// The snowflake identifier of the command to delete. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + /// A value indicating the success of this operation. + public ValueTask DeleteGlobalApplicationCommandAsync + ( + Snowflake applicationId, + Snowflake commandId, + RequestInfo info = default, + CancellationToken ct = default + ); } From 97b424077ac74ff0af28e70127a9c2fe09e966f4 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Thu, 2 Nov 2023 19:31:03 +0100 Subject: [PATCH 177/323] bulk overwrite global application commands --- .../API/IApplicationCommandsRestAPI.cs | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IApplicationCommandsRestAPI.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IApplicationCommandsRestAPI.cs index a394f959be..257bd909af 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IApplicationCommandsRestAPI.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IApplicationCommandsRestAPI.cs @@ -101,4 +101,25 @@ public ValueTask DeleteGlobalApplicationCommandAsync RequestInfo info = default, CancellationToken ct = default ); + + /// + /// Bulk-overwrites global application commands for your application with the provided commands. + /// + /// + /// This will overwrite all types of application commands: slash/chat input commands, user context menu + /// commands and message context menu commands. Commands that did not already exist will count towards the + /// daily application command creation limits, commands that did exist will not. + /// + /// The snowflake identifier of your application. + /// The application commands to create. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + /// The full list of application commands for your application after overwriting. + public ValueTask>> BulkOverwriteGlobalApplicationCommandsAsync + ( + Snowflake applicationId, + IReadOnlyList payload, + RequestInfo info = default, + CancellationToken ct = default + ); } From 341ae560702cff005374261dbed99c82afbe1be1 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Fri, 10 Nov 2023 14:38:31 +0100 Subject: [PATCH 178/323] update onboarding prompt options as per docs updates --- .../Guilds/IOnboardingPromptOption.cs | 20 +++++++++++++++++-- .../Guilds/OnboardingPromptOption.cs | 11 +++++++++- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IOnboardingPromptOption.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IOnboardingPromptOption.cs index 122f530d7e..739571e645 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IOnboardingPromptOption.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IOnboardingPromptOption.cs @@ -27,9 +27,25 @@ public interface IOnboardingPromptOption public IReadOnlyList RoleIds { get; } /// - /// The emoji for this option. + /// The emoji for this option. This field is only ever returned, and must not be sent when creating + /// or updating a prompt option. /// - public IEmoji Emoji { get; } + public Optional Emoji { get; } + + /// + /// The snowflake identifier of the emoji for this option. + /// + public Optional EmojiId { get; } + + /// + /// The name of the emoji for this option. + /// + public Optional EmojiName { get; } + + /// + /// Indicates whether the emoji for this option is animated. + /// + public Optional EmojiAnimated { get; } /// /// The title of this option. diff --git a/src/core/DSharpPlus.Core.Models/Guilds/OnboardingPromptOption.cs b/src/core/DSharpPlus.Core.Models/Guilds/OnboardingPromptOption.cs index 7acd667d93..2fac3933d6 100644 --- a/src/core/DSharpPlus.Core.Models/Guilds/OnboardingPromptOption.cs +++ b/src/core/DSharpPlus.Core.Models/Guilds/OnboardingPromptOption.cs @@ -21,7 +21,16 @@ public sealed record OnboardingPromptOption : IOnboardingPromptOption public required IReadOnlyList RoleIds { get; init; } /// - public required IEmoji Emoji { get; init; } + public Optional Emoji { get; init; } + + /// + public Optional EmojiId { get; init; } + + /// + public Optional EmojiName { get; init; } + + /// + public Optional EmojiAnimated { get; init; } /// public required string Title { get; init; } From 94bbfe0b1312c12be9bd5f92e4db245be72c8902 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Tue, 14 Nov 2023 21:04:16 +0100 Subject: [PATCH 179/323] get guild application commands --- .../API/IApplicationCommandsRestAPI.cs | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IApplicationCommandsRestAPI.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IApplicationCommandsRestAPI.cs index 257bd909af..f2e0dae98a 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IApplicationCommandsRestAPI.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IApplicationCommandsRestAPI.cs @@ -122,4 +122,25 @@ public ValueTask>> BulkOverwriteGlobal RequestInfo info = default, CancellationToken ct = default ); + + /// + /// Fetches application commands for the specified guild. + /// + /// + /// This does not fetch global commands accessible in the guild, only comands registered to specifically that + /// guild using the related API calls. + /// + /// The snowflake identifier of your application. + /// The snowflake identifier of the guild containing the application commands. + /// Indicates whether to include localization dictionaries with the commands. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public ValueTask>> GetGuildApplicationCommandsAsync + ( + Snowflake applicationId, + Snowflake guildId, + bool? withLocalizations = null, + RequestInfo info = default, + CancellationToken ct = default + ); } From 001e0c94b20b39110e96cb5dda82fd2c157148c1 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Tue, 14 Nov 2023 21:12:41 +0100 Subject: [PATCH 180/323] create guild application commands --- .../API/IApplicationCommandsRestAPI.cs | 26 ++++++++-- .../ICreateGuildApplicationCommandPayload.cs | 50 +++++++++++++++++++ 2 files changed, 73 insertions(+), 3 deletions(-) create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/ApplicationCommands/ICreateGuildApplicationCommandPayload.cs diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IApplicationCommandsRestAPI.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IApplicationCommandsRestAPI.cs index f2e0dae98a..b4e6708c9e 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IApplicationCommandsRestAPI.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IApplicationCommandsRestAPI.cs @@ -127,12 +127,14 @@ public ValueTask>> BulkOverwriteGlobal /// Fetches application commands for the specified guild. /// /// - /// This does not fetch global commands accessible in the guild, only comands registered to specifically that - /// guild using the related API calls. + /// This does not fetch global commands accessible in the guild, only comands registered to specifically + /// that guild using the related API calls. /// /// The snowflake identifier of your application. /// The snowflake identifier of the guild containing the application commands. - /// Indicates whether to include localization dictionaries with the commands. + /// + /// Indicates whether to include localization dictionaries with the commands. + /// /// Additional instructions regarding this request. /// A cancellation token for this operation. public ValueTask>> GetGuildApplicationCommandsAsync @@ -143,4 +145,22 @@ public ValueTask>> GetGuildApplication RequestInfo info = default, CancellationToken ct = default ); + + /// + /// Creates an application command specific to the given guild. + /// + /// The snowflake identifier of your application. + /// The snowflake identifier of the guild to own this command. + /// The command you wish to create. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + /// + public ValueTask> CreateGuildApplicationCommandAsync + ( + Snowflake applicationId, + Snowflake guildId, + ICreateGuildApplicationCommandPayload payload, + RequestInfo info = default, + CancellationToken ct = default + ); } diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/ApplicationCommands/ICreateGuildApplicationCommandPayload.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/ApplicationCommands/ICreateGuildApplicationCommandPayload.cs new file mode 100644 index 0000000000..f2c81300ee --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/ApplicationCommands/ICreateGuildApplicationCommandPayload.cs @@ -0,0 +1,50 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Entities; + +namespace DSharpPlus.Core.Abstractions.Rest.Payloads; + +/// +/// Represents a payload to POST /applications/:application-id/guilds/:guild-id/commands +/// +public interface ICreateGuildApplicationCommandPayload +{ + /// + /// The name of this command, between 1 and 32 characters. + /// + public string Name { get; } + + /// + /// A localization dictionary for the field. Values follow the same restrictions. + /// + public Optional?> NameLocalizations { get; } + + /// + /// The description for this chat input command, between 1 and 100 characters. + /// + public Optional Description { get; } + + /// + /// A localization dictionary for the field. Values follow the same restrictions. + /// + public Optional?> DescriptionLocalizations { get; } + + /// + /// The default permissions needed to see this command. + /// + public Optional DefaultMemberPermissions { get; } + + /// + /// The type of this command. + /// + public Optional Type { get; } + + /// + /// Indicates whether this command is age-restricted. + /// + public Optional Nsfw { get; } +} From cbdbc250ac37a75ca3c2702f5320a55102139d93 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Tue, 14 Nov 2023 21:18:34 +0100 Subject: [PATCH 181/323] get guild application command --- .../API/IApplicationCommandsRestAPI.cs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IApplicationCommandsRestAPI.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IApplicationCommandsRestAPI.cs index b4e6708c9e..7bc5fb7ab7 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IApplicationCommandsRestAPI.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IApplicationCommandsRestAPI.cs @@ -154,7 +154,7 @@ public ValueTask>> GetGuildApplication /// The command you wish to create. /// Additional instructions regarding this request. /// A cancellation token for this operation. - /// + /// The created application command object. public ValueTask> CreateGuildApplicationCommandAsync ( Snowflake applicationId, @@ -163,4 +163,21 @@ public ValueTask> CreateGuildApplicationCommandAsync RequestInfo info = default, CancellationToken ct = default ); + + /// + /// Fetches a guild-specific application command by snowflake. + /// + /// The snowflake identifier of your application. + /// The snowflake identifier of the guild owning this command. + /// The snowflake identifier of the command to fetch. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public ValueTask> GetGuildApplicationCommandAsync + ( + Snowflake applicationId, + Snowflake guildId, + Snowflake commandId, + RequestInfo info = default, + CancellationToken ct = default + ); } From f593f0c380b6ab36896815d56785070040c391e9 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Tue, 14 Nov 2023 21:25:47 +0100 Subject: [PATCH 182/323] edit guild application commands --- .../API/IApplicationCommandsRestAPI.cs | 20 ++++++++ .../IEditGlobalApplicationCommandPayload.cs | 3 +- .../IEditGuildApplicationCommandPayload.cs | 50 +++++++++++++++++++ 3 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/ApplicationCommands/IEditGuildApplicationCommandPayload.cs diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IApplicationCommandsRestAPI.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IApplicationCommandsRestAPI.cs index 7bc5fb7ab7..a8522889b6 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IApplicationCommandsRestAPI.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IApplicationCommandsRestAPI.cs @@ -180,4 +180,24 @@ public ValueTask> GetGuildApplicationCommandAsync RequestInfo info = default, CancellationToken ct = default ); + + /// + /// Edits a guild-specific application command. Updates will be available immediately. + /// + /// The snowflake identifier of your application. + /// The snowflake identifier of the guild owning this command. + /// The snowflake identifier of this command. + /// A payload containing new properties for this command. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + /// The edited application command object. + public ValueTask> EditGuildApplicationCommandAsync + ( + Snowflake applicationId, + Snowflake guildId, + Snowflake commandId, + IEditGuildApplicationCommandPayload payload, + RequestInfo info = default, + CancellationToken ct = default + ); } diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/ApplicationCommands/IEditGlobalApplicationCommandPayload.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/ApplicationCommands/IEditGlobalApplicationCommandPayload.cs index d2742c3501..e04b8b71d0 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/ApplicationCommands/IEditGlobalApplicationCommandPayload.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/ApplicationCommands/IEditGlobalApplicationCommandPayload.cs @@ -2,9 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Entities; using System.Collections.Generic; +using DSharpPlus.Entities; + namespace DSharpPlus.Core.Abstractions.Rest.Payloads; /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/ApplicationCommands/IEditGuildApplicationCommandPayload.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/ApplicationCommands/IEditGuildApplicationCommandPayload.cs new file mode 100644 index 0000000000..e3d6d83d1a --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/ApplicationCommands/IEditGuildApplicationCommandPayload.cs @@ -0,0 +1,50 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Entities; + +namespace DSharpPlus.Core.Abstractions.Rest.Payloads; + +/// +/// Represents a payload to PATCH /applications/:application-id/guilds/:guild-id/commands/:command-id. +/// +public interface IEditGuildApplicationCommandPayload +{ + /// + /// The name of this command, between 1 and 32 characters. + /// + public Optional Name { get; } + + /// + /// A localization dictionary for the field. Values follow the same restrictions. + /// + public Optional?> NameLocalizations { get; } + + /// + /// The description for this chat input command, between 1 and 100 characters. + /// + public Optional Description { get; } + + /// + /// A localization dictionary for the field. Values follow the same restrictions. + /// + public Optional?> DescriptionLocalizations { get; } + + /// + /// The default permissions needed to see this command. + /// + public Optional DefaultMemberPermissions { get; } + + /// + /// The type of this command. + /// + public Optional Type { get; } + + /// + /// Indicates whether this command is age-restricted. + /// + public Optional Nsfw { get; } +} From a318bcdac90c640fdbcbb10178df813a1032a5b6 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Tue, 14 Nov 2023 21:39:59 +0100 Subject: [PATCH 183/323] delete guild application command --- .../API/IApplicationCommandsRestAPI.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IApplicationCommandsRestAPI.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IApplicationCommandsRestAPI.cs index a8522889b6..e30f6a50bf 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IApplicationCommandsRestAPI.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IApplicationCommandsRestAPI.cs @@ -200,4 +200,21 @@ public ValueTask> EditGuildApplicationCommandAsync RequestInfo info = default, CancellationToken ct = default ); + + /// + /// Deletes a guild-specific application command. + /// + /// The snowflake identifier of your application. + /// The snowflake identifier of the guild owning this command. + /// The snowflake identifier of this command. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public ValueTask DeleteGuildApplicationCommandAsync + ( + Snowflake applicationId, + Snowflake guildId, + Snowflake commandId, + RequestInfo info = default, + CancellationToken ct = default + ); } From 7f7f7d6a04f5a100773490ea9e0f0fb92dc1bc79 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Tue, 14 Nov 2023 21:54:59 +0100 Subject: [PATCH 184/323] bulk overwrite guild application commands --- .../API/IApplicationCommandsRestAPI.cs | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IApplicationCommandsRestAPI.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IApplicationCommandsRestAPI.cs index e30f6a50bf..3e41c8d7ce 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IApplicationCommandsRestAPI.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IApplicationCommandsRestAPI.cs @@ -217,4 +217,27 @@ public ValueTask DeleteGuildApplicationCommandAsync RequestInfo info = default, CancellationToken ct = default ); + + /// + /// Bulk-overwrites guild-specific application commands for your application with the provided commands. + /// + /// + /// This will overwrite all types of application commands: slash/chat input commands, user context menu + /// commands and message context menu commands. Commands that did not already exist will count towards the + /// daily application command creation limits, commands that did exist will not. + /// + /// The snowflake identifier of your application. + /// The snowflake identifier of the guild to own these commands. + /// The application commands to create. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + /// The full list of application commands for your application after overwriting. + public ValueTask>> BulkOverwriteGuildApplicationCommandsAsync + ( + Snowflake applicationId, + Snowflake guildId, + IReadOnlyList payload, + RequestInfo info = default, + CancellationToken ct = default + ); } From 7d4d478d79b150867a14ef6b920850493d8ac0fb Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Tue, 14 Nov 2023 22:04:34 +0100 Subject: [PATCH 185/323] get guild application command permissions --- .../API/IApplicationCommandsRestAPI.cs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IApplicationCommandsRestAPI.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IApplicationCommandsRestAPI.cs index 3e41c8d7ce..4c6bc8b13b 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IApplicationCommandsRestAPI.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IApplicationCommandsRestAPI.cs @@ -240,4 +240,19 @@ public ValueTask>> BulkOverwriteGuildA RequestInfo info = default, CancellationToken ct = default ); + + /// + /// Fetches permissions for all guild-specific commands owned by your application in the given guild. + /// + /// The snowflake identifier of your application. + /// The snowflake identiifer of the guild owning the commands. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public ValueTask>> GetGuildApplicationCommandPermissionsAsync + ( + Snowflake applicationId, + Snowflake guildId, + RequestInfo info = default, + CancellationToken ct = default + ); } From 3317158ead1aaf73e5409ac9ca4bdb04a095420e Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Tue, 14 Nov 2023 22:09:15 +0100 Subject: [PATCH 186/323] get application command permissions --- .../API/IApplicationCommandsRestAPI.cs | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IApplicationCommandsRestAPI.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IApplicationCommandsRestAPI.cs index 4c6bc8b13b..1f4fd95adc 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IApplicationCommandsRestAPI.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IApplicationCommandsRestAPI.cs @@ -242,10 +242,10 @@ public ValueTask>> BulkOverwriteGuildA ); /// - /// Fetches permissions for all guild-specific commands owned by your application in the given guild. + /// Fetches permissions for all commands owned by your application in the given guild. /// /// The snowflake identifier of your application. - /// The snowflake identiifer of the guild owning the commands. + /// The snowflake identifier of the guild. /// Additional instructions regarding this request. /// A cancellation token for this operation. public ValueTask>> GetGuildApplicationCommandPermissionsAsync @@ -255,4 +255,21 @@ public ValueTask>> GetGuild RequestInfo info = default, CancellationToken ct = default ); + + /// + /// Fetches permissions for the given command in the given guild. + /// + /// The snowflake identifier of your application. + /// The snowflake identifier of the guild. + /// The snowflake identifier of the command. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public ValueTask> GetApplicationCommandPermissionsAsync + ( + Snowflake applicationId, + Snowflake guildId, + Snowflake commandId, + RequestInfo info = default, + CancellationToken ct = default + ); } From 411a7fa50a2adbbaf62f9b191ce1a3adc697e4b5 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Tue, 14 Nov 2023 22:23:29 +0100 Subject: [PATCH 187/323] create interaction responses --- .../API/IInteractionRestAPI.cs | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/API/IInteractionRestAPI.cs diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IInteractionRestAPI.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IInteractionRestAPI.cs new file mode 100644 index 0000000000..721037199b --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IInteractionRestAPI.cs @@ -0,0 +1,35 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Threading; +using System.Threading.Tasks; + +using DSharpPlus.Core.Abstractions.Models; + +using Remora.Results; + +namespace DSharpPlus.Core.Abstractions.Rest.API; + +/// +/// Provides access to interaction-related rest API calls. +/// +public interface IInteractionRestAPI +{ + /// + /// Creates a response to an interaction from the gateway. + /// + /// The snowflake identifier of the interaction. + /// The interaction token received with the interaction. + /// The response to this interaction. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public ValueTask CreateInteractionResponseAsync + ( + Snowflake interactionId, + string interactionToken, + IInteractionResponse payload, + RequestInfo info = default, + CancellationToken ct = default + ); +} From 8f78516484aab7db941cfab420962cdbbca66cc3 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Thu, 16 Nov 2023 11:48:17 +0100 Subject: [PATCH 188/323] get interaction response --- .../API/IInteractionRestAPI.cs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IInteractionRestAPI.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IInteractionRestAPI.cs index 721037199b..20ddc729b8 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IInteractionRestAPI.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IInteractionRestAPI.cs @@ -32,4 +32,19 @@ public ValueTask CreateInteractionResponseAsync RequestInfo info = default, CancellationToken ct = default ); + + /// + /// Gets the original response to this interaction, if it was a message. + /// + /// The snowflake identifier of your application. + /// The interaction token received with the interaction. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public ValueTask> GetInteractionResponseAsync + ( + Snowflake applicationId, + string interactionToken, + RequestInfo info = default, + CancellationToken ct = default + ); } From 6092e5801bce4f1e9c4aa68c6d72cf87ef2b5bae Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Thu, 16 Nov 2023 12:02:47 +0100 Subject: [PATCH 189/323] edit interaction response --- .../API/IInteractionRestAPI.cs | 19 ++++++++ .../IEditInteractionResponsePayload.cs | 45 +++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Interactions/IEditInteractionResponsePayload.cs diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IInteractionRestAPI.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IInteractionRestAPI.cs index 20ddc729b8..3369874a47 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IInteractionRestAPI.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IInteractionRestAPI.cs @@ -6,6 +6,7 @@ using System.Threading.Tasks; using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Core.Abstractions.Rest.Payloads; using Remora.Results; @@ -47,4 +48,22 @@ public ValueTask> GetInteractionResponseAsync RequestInfo info = default, CancellationToken ct = default ); + + /// + /// Edits the original response to this interaction, if it was a message. + /// + /// The snowflake identifier of your application. + /// The interaction token received with the interaction. + /// The message editing payload. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + /// The newly edited message. + public ValueTask> EditInteractionResponseAsync + ( + Snowflake applicationId, + string interactionToken, + IEditInteractionResponsePayload payload, + RequestInfo info = default, + CancellationToken ct = default + ); } diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Interactions/IEditInteractionResponsePayload.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Interactions/IEditInteractionResponsePayload.cs new file mode 100644 index 0000000000..4254c8c5ce --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Interactions/IEditInteractionResponsePayload.cs @@ -0,0 +1,45 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Abstractions.Rest.Payloads; + +/// +/// Represents a payload to PATCH /webhooks/:application-id/:interaction-token/messages/@original. +/// +public interface IEditInteractionResponsePayload +{ + /// + /// The message contents, up to 2000 characters. + /// + public Optional Content { get; } + + /// + /// Up to 10 embeds, subject to embed length limits. + /// + public Optional?> Embeds { get; } + + /// + /// Allowed mentions for this message. + /// + public Optional AllowedMentions { get; } + + /// + /// The components for this message. + /// + public Optional?> Components { get; } + + /// + /// Attached files to keep and possible descriptions for new files to upload. + /// + public Optional?> Attachments { get; } + + /// + /// File contents to send or edit. + /// + public Optional> Files { get; } +} From 01da6deea0c1b39b9c327744b4a8254ac07703c7 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Thu, 16 Nov 2023 12:04:46 +0100 Subject: [PATCH 190/323] delete interaction responses --- .../API/IInteractionRestAPI.cs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IInteractionRestAPI.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IInteractionRestAPI.cs index 3369874a47..a95dddcf06 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IInteractionRestAPI.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IInteractionRestAPI.cs @@ -66,4 +66,19 @@ public ValueTask> EditInteractionResponseAsync RequestInfo info = default, CancellationToken ct = default ); + + /// + /// Deletes the original response to this interaction, if it was a message. + /// + /// The snowflake identifier of your application. + /// The interaction token received with the interaction. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public ValueTask DeleteInteractionResponseAsync + ( + Snowflake applicationId, + string interactionToken, + RequestInfo info = default, + CancellationToken ct = default + ); } From 747c37e1538f0220531e8af4fd6cba5a0d7bf26e Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sun, 19 Nov 2023 18:11:15 +0100 Subject: [PATCH 191/323] create followup message --- .../API/IInteractionRestAPI.cs | 22 +++++++ .../ICreateFollowupMessagePayload.cs | 59 +++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Interactions/ICreateFollowupMessagePayload.cs diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IInteractionRestAPI.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IInteractionRestAPI.cs index a95dddcf06..6412226dd3 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IInteractionRestAPI.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IInteractionRestAPI.cs @@ -81,4 +81,26 @@ public ValueTask DeleteInteractionResponseAsync RequestInfo info = default, CancellationToken ct = default ); + + /// + /// Creates a followup message for an interaction. If this is the first followup to a deferred interaction + /// response as created by + /// , + /// ephemerality of this message will be dictated by the supplied + /// originally instead of . + /// + /// The snowflake identifier of your application. + /// The interaction token received with the interaction. + /// A payload containing data to create a message from. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + /// The newly created followup message. + public ValueTask> CreateFollowupMessageAsync + ( + Snowflake applicationId, + string interactionToken, + ICreateFollowupMessagePayload payload, + RequestInfo info = default, + CancellationToken ct = default + ); } diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Interactions/ICreateFollowupMessagePayload.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Interactions/ICreateFollowupMessagePayload.cs new file mode 100644 index 0000000000..fc8975a4bf --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Interactions/ICreateFollowupMessagePayload.cs @@ -0,0 +1,59 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Entities; + +namespace DSharpPlus.Core.Abstractions.Rest.Payloads; + +/// +/// Represents a payload to POST /webhooks/:application-id/:interaction-token. +/// +/// +/// Either , or must be set. +/// +public interface ICreateFollowupMessagePayload +{ + /// + /// The text contents for this message, up to 2000 characters. + /// + public Optional Content { get; } + + /// + /// Indicates whether this is a TTS message. + /// + public Optional Tts { get; } + + /// + /// Embeds attached to this message. + /// + public Optional> Embeds { get; } + + /// + /// An allowed mentions object for this message. + /// + public Optional AllowedMentions { get; } + + /// + /// Up to five action rows worth of components to include with this message. + /// + public Optional> Components { get; } + + /// + /// Files to upload with this message. + /// + public Optional> Files { get; } + + /// + /// Attachment metadata for files uploaded with this message. + /// + public Optional> Attachments { get; } + + /// + /// Additional message flags for this message. SuppressEmbeds and Ephemeral can be set. + /// + public Optional Flags { get; } +} From a926aa628e8edf630c0a5fc8ae2b052dd4d4fc10 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sun, 19 Nov 2023 18:14:04 +0100 Subject: [PATCH 192/323] get followup message --- .../API/IInteractionRestAPI.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IInteractionRestAPI.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IInteractionRestAPI.cs index 6412226dd3..e31fa9c200 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IInteractionRestAPI.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IInteractionRestAPI.cs @@ -103,4 +103,21 @@ public ValueTask> CreateFollowupMessageAsync RequestInfo info = default, CancellationToken ct = default ); + + /// + /// Fetches a followup message created for this interaction. + /// + /// The snowflake identifier of your application. + /// The interaction token received with the interaction. + /// The snowflake identifier of the followup message. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public ValueTask> GetFollowupMessageAsync + ( + Snowflake applicationId, + string interactionToken, + Snowflake messageId, + RequestInfo info = default, + CancellationToken ct = default + ); } From 7a5df01bd30f73c87c90c446c34da0cbaaa82c7c Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sun, 19 Nov 2023 18:15:04 +0100 Subject: [PATCH 193/323] edit followup message --- .../API/IInteractionRestAPI.cs | 20 +++++++++ .../IEditFollowupMessagePayload.cs | 45 +++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Interactions/IEditFollowupMessagePayload.cs diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IInteractionRestAPI.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IInteractionRestAPI.cs index e31fa9c200..9b94692123 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IInteractionRestAPI.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IInteractionRestAPI.cs @@ -120,4 +120,24 @@ public ValueTask> GetFollowupMessageAsync RequestInfo info = default, CancellationToken ct = default ); + + /// + /// Edits a followup message for this interaction. + /// + /// The snowflake identifier of your application. + /// The interaction token received with the interaction. + /// The snowflake identifier of the followup message. + /// A payload containing data to create a message from. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + /// The newly edited followup message. + public ValueTask> EditFollowupMessageAsync + ( + Snowflake applicationId, + string interactionToken, + Snowflake messageId, + IEditFollowupMessagePayload payload, + RequestInfo info = default, + CancellationToken ct = default + ); } diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Interactions/IEditFollowupMessagePayload.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Interactions/IEditFollowupMessagePayload.cs new file mode 100644 index 0000000000..232dd0fa0a --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Interactions/IEditFollowupMessagePayload.cs @@ -0,0 +1,45 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Abstractions.Rest.Payloads; + +/// +/// Represents a payload to PATCH /webhooks/:application-id/:interaction-token/messages/:message-id. +/// +public interface IEditFollowupMessagePayload +{ + /// + /// The message contents, up to 2000 characters. + /// + public Optional Content { get; } + + /// + /// Up to 10 embeds, subject to embed length limits. + /// + public Optional?> Embeds { get; } + + /// + /// Allowed mentions for this message. + /// + public Optional AllowedMentions { get; } + + /// + /// The components for this message. + /// + public Optional?> Components { get; } + + /// + /// Attached files to keep and possible descriptions for new files to upload. + /// + public Optional?> Attachments { get; } + + /// + /// File contents to send or edit. + /// + public Optional> Files { get; } +} From c607772756561d2f9fcea67b75173dd1e2ac3b15 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sun, 19 Nov 2023 18:18:30 +0100 Subject: [PATCH 194/323] delete followup messages --- .../API/IInteractionRestAPI.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IInteractionRestAPI.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IInteractionRestAPI.cs index 9b94692123..2d14240cf8 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IInteractionRestAPI.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IInteractionRestAPI.cs @@ -140,4 +140,21 @@ public ValueTask> EditFollowupMessageAsync RequestInfo info = default, CancellationToken ct = default ); + + /// + /// Deletes a followup message created for this interaction. + /// + /// The snowflake identifier of your application. + /// The interaction token received with the interaction. + /// The snowflake identifier of the followup message. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public ValueTask DeleteFollowupMessageAsync + ( + Snowflake applicationId, + string interactionToken, + Snowflake messageId, + RequestInfo info = default, + CancellationToken ct = default + ); } From 94262e13a39d989d1f171a06daf0f81fdc0c4a98 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sun, 19 Nov 2023 20:07:18 +0100 Subject: [PATCH 195/323] get current application --- Directory.Build.props | 2 +- .../API/IApplicationRestAPI.cs | 29 +++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/API/IApplicationRestAPI.cs diff --git a/Directory.Build.props b/Directory.Build.props index 30986dc7d1..5a2f3d3098 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -2,7 +2,7 @@ - net8.0 + net9.0 enable preview True diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IApplicationRestAPI.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IApplicationRestAPI.cs new file mode 100644 index 0000000000..851bb47a6c --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IApplicationRestAPI.cs @@ -0,0 +1,29 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Threading; +using System.Threading.Tasks; + +using DSharpPlus.Core.Abstractions.Models; + +using Remora.Results; + +namespace DSharpPlus.Core.Abstractions.Rest.API; + +/// +/// Provides access to application-related rest API calls. +/// +public interface IApplicationRestAPI +{ + /// + /// Returns the application object associated with the requesting bot user. + /// + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public ValueTask> GetCurrentApplicationAsync + ( + RequestInfo info = default, + CancellationToken ct = default + ); +} From 934161cc0bfdfb2afe38ea667b87067874c6a88d Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Wed, 22 Nov 2023 12:03:21 +0100 Subject: [PATCH 196/323] handle image data this impl suffers when writing to an ArrayPoolBufferWriter, but it's still considerably better than v5, and PipeWriter is much faster. it also pools all allocations which is cool --- Directory.Packages.props | 14 +- .../DSharpPlus.Shared.csproj | 2 +- src/core/DSharpPlus.Shared/ImageData.cs | 303 ++++++++++++++++++ src/core/DSharpPlus.Shared/ImageFormat.cs | 18 ++ 4 files changed, 329 insertions(+), 8 deletions(-) create mode 100644 src/core/DSharpPlus.Shared/ImageData.cs create mode 100644 src/core/DSharpPlus.Shared/ImageFormat.cs diff --git a/Directory.Packages.props b/Directory.Packages.props index b7a07b2aa9..d2ee51af10 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -1,22 +1,22 @@ - - + + - + - - + + - + - + diff --git a/src/core/DSharpPlus.Shared/DSharpPlus.Shared.csproj b/src/core/DSharpPlus.Shared/DSharpPlus.Shared.csproj index fc31c2b78f..904eb82ab4 100644 --- a/src/core/DSharpPlus.Shared/DSharpPlus.Shared.csproj +++ b/src/core/DSharpPlus.Shared/DSharpPlus.Shared.csproj @@ -5,7 +5,6 @@ $(Description) This package contains shared types between public-facing and internal implementation packages. Library true - true $(NoWarn);CA1008 DSharpPlus @@ -15,6 +14,7 @@ + diff --git a/src/core/DSharpPlus.Shared/ImageData.cs b/src/core/DSharpPlus.Shared/ImageData.cs new file mode 100644 index 0000000000..46b5c2e452 --- /dev/null +++ b/src/core/DSharpPlus.Shared/ImageData.cs @@ -0,0 +1,303 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; +using System.Buffers; +using System.Buffers.Text; +using System.Diagnostics; +using System.IO; +using System.IO.Pipelines; +using System.Threading.Tasks; + +using CommunityToolkit.HighPerformance.Buffers; + +namespace DSharpPlus; + +/// +/// Represents an image sent to Discord as part of JSON payloads. +/// +public readonly record struct ImageData +{ + private static ReadOnlySpan PngString => "data:image/png;base64,"u8; + private static ReadOnlySpan JpegString => "data:image/jpeg;base64,"u8; + private static ReadOnlySpan GifString => "data:image/gif;base64,"u8; + private static ReadOnlySpan WebpString => "data:image/webp;base64,"u8; + private static ReadOnlySpan AutoString => "data:image/auto;base64,"u8; + + private readonly PipeReader reader; + private readonly ImageFormat format; + + /// + /// Creates a new instance of this struct from the provided pipe. + /// + /// The PipeReader to convert to base64. + /// The format of this image. + public ImageData(PipeReader reader, ImageFormat format) + { + this.reader = reader; + this.format = format; + } + + /// + /// Creates a new instance of this struct from the provided stream. + /// + /// The stream to conver to base64. + /// The format of this image. + public ImageData(Stream stream, ImageFormat format) : this(PipeReader.Create(stream), format) + { + + } + + /// + /// Creates a new instance of this struct from the provided buffer. + /// + /// The buffer to convert to base64. + /// The format of this image. + public ImageData(ReadOnlySequence data, ImageFormat format) : this(PipeReader.Create(data), format) + { + + } + + /// + /// Writes the base64 data to the specified PipeWriter. + /// + /// + /// Thrown if a fatal memory management error occurred. This hints at data corruption and should not + /// be caught under any circumstances. + /// + public readonly async ValueTask WriteToAsync(PipeWriter writer) + { + // chosen because a StreamPipeReader buffers to 4096 + const int readSegmentLength = 4096; + const int writeSegmentLength = 5120; + + writer.Write + ( + this.format switch + { + ImageFormat.Png => PngString, + ImageFormat.Gif => GifString, + ImageFormat.Jpeg => JpegString, + ImageFormat.WebP => WebpString, + _ => AutoString + } + ); + + byte[] readBuffer = ArrayPool.Shared.Rent(readSegmentLength); + byte[] writeBuffer = ArrayPool.Shared.Rent(writeSegmentLength); + + int readRollover = 0; + + while (true) + { + ReadResult result = await this.reader.ReadAsync(); + + if (result.IsCanceled) + { + break; + } + + ProcessResult(result, this.reader); + + if (result.IsCompleted) + { + break; + } + } + + ArrayPool.Shared.Return(readBuffer); + ArrayPool.Shared.Return(writeBuffer); + + void ProcessResult(ReadResult result, PipeReader reader) + { + SequenceReader sequence = new(result.Buffer); + + scoped Span readSpan = readBuffer.AsSpan()[..readSegmentLength]; + scoped Span writeSpan = writeBuffer.AsSpan()[..writeSegmentLength]; + + while (!sequence.End) + { + if (readRollover != 0) + { + if (sequence.Remaining + readRollover >= readSegmentLength) + { + sequence.TryCopyTo(readSpan[readRollover..]); + + sequence.Advance(readSegmentLength - readRollover); + readRollover = 0; + } + else + { + sequence.TryCopyTo(readSpan.Slice(readRollover, (int)sequence.Remaining)); + + readRollover += (int)sequence.Remaining; + sequence.Advance((int)sequence.Remaining); + break; + } + } + else if (sequence.Remaining >= readSegmentLength) + { + sequence.TryCopyTo(readSpan); + + sequence.Advance(readSegmentLength); + } + else + { + sequence.TryCopyTo(readSpan[..(int)sequence.Remaining]); + + readRollover += (int)sequence.Remaining; + sequence.AdvanceToEnd(); + break; + } + + OperationStatus status = Base64.EncodeToUtf8(readSpan, writeSpan, out int consumed, out int written, false); + + Debug.Assert + ( + consumed != readSegmentLength || written != writeSegmentLength, + "Buffer management error while converting to base64. Aborting." + ); + + Debug.Assert(status == OperationStatus.Done); + + writer.Write(writeSpan[..written]); + } + + if (result.IsCompleted) + { + OperationStatus status = Base64.EncodeToUtf8(readSpan[..readRollover], writeSpan, out int _, out int written, true); + + Debug.Assert(status == OperationStatus.Done); + + writer.Write(writeSpan[..written]); + + writer.Complete(); + reader.Complete(); + return; + } + + reader.AdvanceTo(result.Buffer.End); + } + } + + /// + /// Writes the base64 data to the specified ArrayPoolBufferWriter. + /// + /// + /// Thrown if a fatal memory management error occurred. This hints at data corruption and should not + /// be caught under any circumstances. + /// + public readonly async ValueTask WriteToAsync(ArrayPoolBufferWriter writer) + { + const int readSegmentLength = 4096; + const int writeSegmentLength = 5120; + + writer.Write + ( + this.format switch + { + ImageFormat.Png => PngString, + ImageFormat.Gif => GifString, + ImageFormat.Jpeg => JpegString, + ImageFormat.WebP => WebpString, + _ => AutoString + } + ); + + byte[] readBuffer = ArrayPool.Shared.Rent(readSegmentLength); + byte[] writeBuffer = ArrayPool.Shared.Rent(writeSegmentLength); + + int readRollover = 0; + + while (true) + { + ReadResult result = await this.reader.ReadAsync(); + + if (result.IsCanceled) + { + break; + } + + ProcessResult(result, this.reader); + + if (result.IsCompleted) + { + break; + } + } + + ArrayPool.Shared.Return(readBuffer); + ArrayPool.Shared.Return(writeBuffer); + + void ProcessResult(ReadResult result, PipeReader reader) + { + SequenceReader sequence = new(result.Buffer); + + scoped Span readSpan = readBuffer.AsSpan()[..readSegmentLength]; + scoped Span writeSpan = writeBuffer.AsSpan()[..writeSegmentLength]; + + while (!sequence.End) + { + if (readRollover != 0) + { + if (sequence.Remaining + readRollover >= readSegmentLength) + { + sequence.TryCopyTo(readSpan[readRollover..]); + + sequence.Advance(readSegmentLength - readRollover); + readRollover = 0; + } + else + { + sequence.TryCopyTo(readSpan.Slice(readRollover, (int)sequence.Remaining)); + + readRollover += (int)sequence.Remaining; + sequence.Advance((int)sequence.Remaining); + break; + } + } + else if (sequence.Remaining >= readSegmentLength) + { + sequence.TryCopyTo(readSpan); + + sequence.Advance(readSegmentLength); + } + else + { + sequence.TryCopyTo(readSpan[..(int)sequence.Remaining]); + + readRollover += (int)sequence.Remaining; + sequence.AdvanceToEnd(); + break; + } + + OperationStatus status = Base64.EncodeToUtf8(readSpan, writeSpan, out int consumed, out int written, false); + + Debug.Assert + ( + consumed != readSegmentLength || written != writeSegmentLength, + "Buffer management error while converting to base64. Aborting." + ); + + Debug.Assert(status == OperationStatus.Done); + + writer.Write(writeSpan[..written]); + } + + if (result.IsCompleted) + { + OperationStatus status = Base64.EncodeToUtf8(readSpan[..readRollover], writeSpan, out int _, out int written, true); + + Debug.Assert(status == OperationStatus.Done); + + writer.Write(writeSpan[..written]); + + reader.Complete(); + return; + } + + reader.AdvanceTo(result.Buffer.End); + } + } +} diff --git a/src/core/DSharpPlus.Shared/ImageFormat.cs b/src/core/DSharpPlus.Shared/ImageFormat.cs new file mode 100644 index 0000000000..48fb4be319 --- /dev/null +++ b/src/core/DSharpPlus.Shared/ImageFormat.cs @@ -0,0 +1,18 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus; + +/// +/// Represents formats recognized and handled by . +/// +public enum ImageFormat +{ + Png, + Gif, + Jpeg, + WebP, + Auto, + Unknown, +} From b46ce78cc8b31be1deaf3bf07dc5ffcfa477a2c6 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Wed, 22 Nov 2023 12:31:55 +0100 Subject: [PATCH 197/323] image data json converter this sucks, but... oh well. --- .../Serialization/ImageDataConverter.cs | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/core/DSharpPlus.Shared/Serialization/ImageDataConverter.cs diff --git a/src/core/DSharpPlus.Shared/Serialization/ImageDataConverter.cs b/src/core/DSharpPlus.Shared/Serialization/ImageDataConverter.cs new file mode 100644 index 0000000000..8e9155ef2d --- /dev/null +++ b/src/core/DSharpPlus.Shared/Serialization/ImageDataConverter.cs @@ -0,0 +1,33 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; +using System.Text.Json; +using System.Text.Json.Serialization; + +using CommunityToolkit.HighPerformance.Buffers; + +namespace DSharpPlus.Serialization; + +public sealed class ImageDataConverter : JsonConverter +{ + /// + /// Deserializing image data is unsupported. + /// + public override ImageData Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) => throw new NotSupportedException(); + + public override void Write + ( + Utf8JsonWriter writer, + ImageData value, + JsonSerializerOptions options + ) + { + using ArrayPoolBufferWriter bufferWriter = new(65536); + + value.WriteToAsync(bufferWriter).AsTask().GetAwaiter().GetResult(); + + writer.WriteStringValue(bufferWriter.WrittenSpan); + } +} From 40705f2bbdb31e816d8353d520ab008eca65deb9 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Wed, 22 Nov 2023 12:58:20 +0100 Subject: [PATCH 198/323] edit current application --- .../API/IApplicationRestAPI.cs | 15 +++++ .../IEditCurrentApplicationPayload.cs | 62 +++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Applications/IEditCurrentApplicationPayload.cs diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IApplicationRestAPI.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IApplicationRestAPI.cs index 851bb47a6c..f1ec229e2b 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IApplicationRestAPI.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IApplicationRestAPI.cs @@ -6,6 +6,7 @@ using System.Threading.Tasks; using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Core.Abstractions.Rest.Payloads; using Remora.Results; @@ -26,4 +27,18 @@ public ValueTask> GetCurrentApplicationAsync RequestInfo info = default, CancellationToken ct = default ); + + /// + /// Edits the application associated with the requesting bot user. + /// + /// A payload object containing properties to update. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + /// The updated application object. + public ValueTask> EditCurrentApplicationAsync + ( + IEditCurrentApplicationPayload payload, + RequestInfo info = default, + CancellationToken ct = default + ); } diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Applications/IEditCurrentApplicationPayload.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Applications/IEditCurrentApplicationPayload.cs new file mode 100644 index 0000000000..f44467cc00 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Applications/IEditCurrentApplicationPayload.cs @@ -0,0 +1,62 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Entities; + +namespace DSharpPlus.Core.Abstractions.Rest.Payloads; + +/// +/// Represents a payload to PATCH /applications/@me. +/// +public interface IEditCurrentApplicationPayload +{ + /// + /// The default custom authorization URL for this application, if the feature is enabled. + /// + public Optional CustomInstallUrl { get; } + + /// + /// The description of this application. + /// + public Optional Description { get; } + + /// + /// The role connection verification URL for this application. + /// + public Optional RoleConnectionsVerificationUrl { get; } + + /// + /// Settings for this application's default in-app authorization link, if enabled. + /// + public Optional InstallParams { get; } + + /// + /// The public flags for this application. + /// + public Optional Flags { get; } + + /// + /// The icon for this application. + /// + public Optional Icon { get; } + + /// + /// The default rich presence invite cover image for this application. + /// + public Optional CoverImage { get; } + + /// + /// The interactions endpoint url for this application. + /// + public Optional InteractionsEndpointUrl { get; } + + /// + /// A list of tags describing the content and functionality of this application, with a maximum of + /// five tags and a maximum of 20 characters per tag. + /// + public Optional> Tags { get; } +} From c92083babfc99767a63dde0c079aefdbb70fedc6 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Thu, 30 Nov 2023 20:03:50 +0100 Subject: [PATCH 199/323] delete unthrown exception from xmldocs --- src/core/DSharpPlus.Shared/ImageData.cs | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/core/DSharpPlus.Shared/ImageData.cs b/src/core/DSharpPlus.Shared/ImageData.cs index 46b5c2e452..f19d45e658 100644 --- a/src/core/DSharpPlus.Shared/ImageData.cs +++ b/src/core/DSharpPlus.Shared/ImageData.cs @@ -62,10 +62,6 @@ public ImageData(ReadOnlySequence data, ImageFormat format) : this(PipeRea /// /// Writes the base64 data to the specified PipeWriter. /// - /// - /// Thrown if a fatal memory management error occurred. This hints at data corruption and should not - /// be caught under any circumstances. - /// public readonly async ValueTask WriteToAsync(PipeWriter writer) { // chosen because a StreamPipeReader buffers to 4096 @@ -184,10 +180,6 @@ void ProcessResult(ReadResult result, PipeReader reader) /// /// Writes the base64 data to the specified ArrayPoolBufferWriter. /// - /// - /// Thrown if a fatal memory management error occurred. This hints at data corruption and should not - /// be caught under any circumstances. - /// public readonly async ValueTask WriteToAsync(ArrayPoolBufferWriter writer) { const int readSegmentLength = 4096; From f57fddc7946a9163eaf7665f114947275f463d77 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sat, 2 Dec 2023 14:41:19 +0100 Subject: [PATCH 200/323] get role connections metadata --- .../API/IRoleConnectionsRestAPI.cs | 32 +++++++++++++++++++ .../DSharpPlus.Core.Models.Tests.csproj | 2 +- 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/API/IRoleConnectionsRestAPI.cs diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IRoleConnectionsRestAPI.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IRoleConnectionsRestAPI.cs new file mode 100644 index 0000000000..7edc019772 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IRoleConnectionsRestAPI.cs @@ -0,0 +1,32 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; + +using DSharpPlus.Core.Abstractions.Models; + +using Remora.Results; + +namespace DSharpPlus.Core.Abstractions.Rest.API; + +/// +/// Provides access to managing role connections via the API. +/// +public interface IRoleConnectionsRestAPI +{ + /// + /// Returns the role connection metadata records for the given application. + /// + /// The snowflake identifier of your application. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public ValueTask>> GetRoleConnectionMetadataRecordsAsync + ( + Snowflake applicationId, + RequestInfo info = default, + CancellationToken ct = default + ); +} diff --git a/tests/core/DSharpPlus.Core.Models.Tests/DSharpPlus.Core.Models.Tests.csproj b/tests/core/DSharpPlus.Core.Models.Tests/DSharpPlus.Core.Models.Tests.csproj index 0d93d3427e..a8393dce24 100644 --- a/tests/core/DSharpPlus.Core.Models.Tests/DSharpPlus.Core.Models.Tests.csproj +++ b/tests/core/DSharpPlus.Core.Models.Tests/DSharpPlus.Core.Models.Tests.csproj @@ -1,7 +1,7 @@ - net8.0 + net9.0 enable false From 145e097897f919d9ed7fe5715629f28e5ffdcb32 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sat, 2 Dec 2023 15:10:39 +0100 Subject: [PATCH 201/323] update role connections --- .../API/IRoleConnectionsRestAPI.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IRoleConnectionsRestAPI.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IRoleConnectionsRestAPI.cs index 7edc019772..1261dff0ed 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IRoleConnectionsRestAPI.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IRoleConnectionsRestAPI.cs @@ -29,4 +29,20 @@ public ValueTask>> GetRoleConnecti RequestInfo info = default, CancellationToken ct = default ); + + /// + /// Updates the role connection metadata records for the given application. + /// + /// The snowflake identifier of your application. + /// The new metadata records for this application. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + /// The newly updated metadata records. + public ValueTask>> UpdateRoleConnectionMetadataRecordsAsync + ( + Snowflake applicationId, + IReadOnlyList payload, + RequestInfo info = default, + CancellationToken ct = default + ); } From 4706d904b37c3a0e880c308faa058f42af657d00 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sun, 3 Dec 2023 19:12:37 +0100 Subject: [PATCH 202/323] get auto moderation rules --- .../API/IAutoModerationRestAPI.cs | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/API/IAutoModerationRestAPI.cs diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IAutoModerationRestAPI.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IAutoModerationRestAPI.cs new file mode 100644 index 0000000000..fd3887d9c7 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IAutoModerationRestAPI.cs @@ -0,0 +1,47 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; + +using DSharpPlus.Core.Abstractions.Models; + +using Remora.Results; + +namespace DSharpPlus.Core.Abstractions.Rest.API; + +/// +/// Provides access to managing the built-in auto moderator via the API. +/// +public interface IAutoModerationRestAPI +{ + /// + /// Fetches the auto moderation rules in the given guild. + /// + /// The snowflake identifier of the guild. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public ValueTask>> ListAutoModerationRulesAsync + ( + Snowflake guildId, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Fetches the specified auto moderation rule belonging to the specified guild. + /// + /// The snowflake identifier of the guild owning the rule. + /// The snowflake identifier of the rule to fetch. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public ValueTask> GetAutoModerationRuleAsync + ( + Snowflake guildId, + Snowflake ruleId, + RequestInfo info = default, + CancellationToken ct = default + ); +} From deb70c20c3616c08121c1cc6409b66abf7654665 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sun, 3 Dec 2023 19:30:11 +0100 Subject: [PATCH 203/323] create auto moderation rules --- .../API/IAutoModerationRestAPI.cs | 19 +++++++ .../ICreateAutoModerationRulePayload.cs | 56 +++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/AutoModeration/ICreateAutoModerationRulePayload.cs diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IAutoModerationRestAPI.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IAutoModerationRestAPI.cs index fd3887d9c7..dae9281abe 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IAutoModerationRestAPI.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IAutoModerationRestAPI.cs @@ -7,6 +7,7 @@ using System.Threading.Tasks; using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Core.Abstractions.Rest.Payloads; using Remora.Results; @@ -44,4 +45,22 @@ public ValueTask> GetAutoModerationRuleAsync RequestInfo info = default, CancellationToken ct = default ); + + /// + /// Creates a new auto moderation rule in the specified guild. + /// + /// The snowflake identifier of the guild to create the rule in. + /// A payload object containing the necessary information to create the rule. + /// An optional reason to list in the audit log. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + /// The newly created auto moderation rule. + public ValueTask> CreateAutoModerationRuleAsync + ( + Snowflake guildId, + ICreateAutoModerationRulePayload payload, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ); } diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/AutoModeration/ICreateAutoModerationRulePayload.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/AutoModeration/ICreateAutoModerationRulePayload.cs new file mode 100644 index 0000000000..6e1c0bd200 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/AutoModeration/ICreateAutoModerationRulePayload.cs @@ -0,0 +1,56 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Entities; + +namespace DSharpPlus.Core.Abstractions.Rest.Payloads; + +/// +/// Represents a payload to POST /guilds/:guild-id/auto-moderation/rules. +/// +public interface ICreateAutoModerationRulePayload +{ + /// + /// The name of this rule. + /// + public string Name { get; } + + /// + /// The type of event to trigger evaluation of this rule. + /// + public DiscordAutoModerationEventType EventType { get; } + + /// + /// The type of trigger for this rule. + /// + public DiscordAutoModerationTriggerType TriggerType { get; } + + /// + /// Additional trigger metadata for this rule. + /// + public Optional TriggerMetadata { get; } + + /// + /// The actions to execute when this rule is triggered. + /// + public IReadOnlyList Actions { get; } + + /// + /// Indicates whether the rule is enabled. Defaults to false. + /// + public Optional Enabled { get; } + + /// + /// Up to 20 snowflake identifiers of roles to exempt from this rule. + /// + public Optional> ExemptRoles { get; } + + /// + /// Up to 50 snowflake identifiers of channels to exempt from this rule. + /// + public Optional> ExemptChannels { get; } +} From 7d41968aeb54a9ad591bf8d28488684fa8b5d56d Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sun, 3 Dec 2023 19:33:31 +0100 Subject: [PATCH 204/323] modify automod rules --- .../API/IAutoModerationRestAPI.cs | 20 ++++++++ .../IModifyAutoModerationRulePayload.cs | 51 +++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/AutoModeration/IModifyAutoModerationRulePayload.cs diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IAutoModerationRestAPI.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IAutoModerationRestAPI.cs index dae9281abe..dcca08eabb 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IAutoModerationRestAPI.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IAutoModerationRestAPI.cs @@ -63,4 +63,24 @@ public ValueTask> CreateAutoModerationRuleAsync RequestInfo info = default, CancellationToken ct = default ); + + /// + /// Modifies the specified auto moderation rule. + /// + /// The snowflake identifier of the guild owning the rule to modify. + /// The snowflake identifier of the rule to modify. + /// A payload object containing the necessary information to modify the rule. + /// An optional reason to list in the audit log. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + /// The newly modified auto moderation rule. + public ValueTask> ModifyAutoModerationRuleAsync + ( + Snowflake guildId, + Snowflake ruleId, + IModifyAutoModerationRulePayload payload, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ); } diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/AutoModeration/IModifyAutoModerationRulePayload.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/AutoModeration/IModifyAutoModerationRulePayload.cs new file mode 100644 index 0000000000..9757b51903 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/AutoModeration/IModifyAutoModerationRulePayload.cs @@ -0,0 +1,51 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Entities; + +namespace DSharpPlus.Core.Abstractions.Rest.Payloads; + +/// +/// Represents a payload to PATCH /guilds/:guild-id/auto-moderation/rules/:automod-rule-id. +/// +public interface IModifyAutoModerationRulePayload +{ + /// + /// The name of this rule. + /// + public Optional Name { get; } + + /// + /// The type of event to trigger evaluation of this rule. + /// + public Optional EventType { get; } + + /// + /// Additional trigger metadata for this rule. + /// + public Optional TriggerMetadata { get; } + + /// + /// The actions to execute when this rule is triggered. + /// + public Optional> Actions { get; } + + /// + /// Indicates whether the rule is enabled. Defaults to false. + /// + public Optional Enabled { get; } + + /// + /// Up to 20 snowflake identifiers of roles to exempt from this rule. + /// + public Optional> ExemptRoles { get; } + + /// + /// Up to 50 snowflake identifiers of channels to exempt from this rule. + /// + public Optional> ExemptChannels { get; } +} From 78304c7cf2687d8ea36b3fbc4581797605de2c8c Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sun, 3 Dec 2023 19:35:21 +0100 Subject: [PATCH 205/323] delete auto moderation rules --- .../API/IAutoModerationRestAPI.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IAutoModerationRestAPI.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IAutoModerationRestAPI.cs index dcca08eabb..0858f98a38 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IAutoModerationRestAPI.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IAutoModerationRestAPI.cs @@ -83,4 +83,21 @@ public ValueTask> ModifyAutoModerationRuleAsync RequestInfo info = default, CancellationToken ct = default ); + + /// + /// Deletes the specified auto moderation rule. + /// + /// The snowflake identifier of the guild owning the rule to delete. + /// The snowflake identifier of the rule to delete. + /// An optional reason to list in the audit log. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public ValueTask DeleteAutoModerationRuleAsync + ( + Snowflake guildId, + Snowflake ruleId, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ); } From a04128ab146a45c4971a54155ec0c5a4106d53b6 Mon Sep 17 00:00:00 2001 From: Lunar Starstrum Date: Sun, 10 Dec 2023 14:18:05 -0600 Subject: [PATCH 206/323] Remove explicit SourceLink def; Update deps (#1702) * Remove sourcelink * Update deps; Remove CodeAnalysis and Spectre.Console packages --- Directory.Build.props | 6 ------ Directory.Packages.props | 20 +++++++------------- 2 files changed, 7 insertions(+), 19 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index 5a2f3d3098..55ae534343 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -14,12 +14,6 @@ True true true - - - true - true - true - snupkg diff --git a/Directory.Packages.props b/Directory.Packages.props index d2ee51af10..79ade2072c 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -1,25 +1,19 @@ - - - - - + - + - - + - - - + + - - + + \ No newline at end of file From c90d658b183121f526bcdc91640d9c60f230b298 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Mon, 18 Dec 2023 16:52:57 +0100 Subject: [PATCH 207/323] the entire channel api :3 --- .../API/IChannelRestAPI.cs | 733 ++++++++++++++++++ .../Channels/ICreateChannelInvitePayload.cs | 50 ++ .../Channels/ICreateMessagePayload.cs | 71 ++ .../IEditChannelPermissionsPayload.cs | 28 + .../Payloads/Channels/IEditMessagePayload.cs | 54 ++ .../IFollowAnnouncementChannelPayload.cs | 16 + .../Channels/IForumAndMediaThreadMessage.cs | 51 ++ .../Channels/IGroupDMAddRecipientPayload.cs | 21 + .../Channels/IModifyGroupDMPayload.cs | 21 + .../Channels/IModifyGuildChannelPayload.cs | 113 +++ .../Channels/IModifyThreadChannelPayload.cs | 55 ++ .../IStartThreadFromMessagePayload.cs | 26 + ...StartThreadInForumOrMediaChannelPayload.cs | 43 + .../IStartThreadWithoutMessagePayload.cs | 40 + .../Responses/ListArchivedThreadsResponse.cs | 30 + 15 files changed, 1352 insertions(+) create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/API/IChannelRestAPI.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Channels/ICreateChannelInvitePayload.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Channels/ICreateMessagePayload.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Channels/IEditChannelPermissionsPayload.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Channels/IEditMessagePayload.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Channels/IFollowAnnouncementChannelPayload.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Channels/IForumAndMediaThreadMessage.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Channels/IGroupDMAddRecipientPayload.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Channels/IModifyGroupDMPayload.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Channels/IModifyGuildChannelPayload.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Channels/IModifyThreadChannelPayload.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Channels/IStartThreadFromMessagePayload.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Channels/IStartThreadInForumOrMediaChannelPayload.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Channels/IStartThreadWithoutMessagePayload.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/Responses/ListArchivedThreadsResponse.cs diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IChannelRestAPI.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IChannelRestAPI.cs new file mode 100644 index 0000000000..204cf96cc4 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IChannelRestAPI.cs @@ -0,0 +1,733 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; + +using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Core.Abstractions.Rest.Payloads; +using DSharpPlus.Core.Abstractions.Rest.Responses; + +using Remora.Results; + +namespace DSharpPlus.Core.Abstractions.Rest.API; + +/// +/// Provides access to channel-related rest API calls. +/// +public interface IChannelRestAPI +{ + /// + /// Returns a channel object for the given ID. If the channel is a thread channel, a + /// object is included in the returned channel. + /// + /// The snowflake identifier of the channel in question. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public ValueTask> GetChannelAsync + ( + Snowflake channelId, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Modifies a group DM channel with the given parameters. + /// + /// The snowflake identifier of the group DM in question. + /// Payload object containing the modification parameters. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + /// The modified channel object. + public ValueTask> ModifyChannelAsync + ( + Snowflake channelId, + IModifyGroupDMPayload payload, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Modifies a guild channel with the given parameters. + /// + /// The snowflake identifier of the channel in question. + /// Payload object containing the modification parameters. + /// Optional audit log reason for the edit. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + /// The modified channel object. + public ValueTask> ModifyChannelAsync + ( + Snowflake channelId, + IModifyGuildChannelPayload payload, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Modifies a thread channel with the given parameters. + /// + /// The snowflake identifier of the channel in question. + /// Payload object containing the modification parameters. + /// Optional audit log reason for the edit. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + /// The modified channel object. + public ValueTask> ModifyChannelAsync + ( + Snowflake channelId, + IModifyThreadChannelPayload payload, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Deletes a channel. Deleting guild channels cannot be undone. DM channels, however, cannot be deleted + /// and are restored by opening a direct message channel again. + /// + /// The snowflake identifier of the channel in question. + /// Optional audit log reason if this is a guild channel. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + /// The associated channel object. + public ValueTask> DeleteChannelAsync + ( + Snowflake channelId, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Returns a set amount of messages, optionally before, after or around a certain message. + /// + /// + /// around, before and after are mutually exclusive. Only one may be passed. If multiple are passed, + /// only the first one in the parameter list is respected, independent of the order they are passed in client code. + /// + /// The snowflake identifier of the channel in question. + /// The snowflake identifier of the center message of the requested block. + /// The snowflake identifier of the first older message than the requested block. + /// The snowflake identifier of the first newer message than the requested block. + /// The maximum amount of messages to return. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public ValueTask>> GetChannelMessagesAsync + ( + Snowflake channelId, + Snowflake? around = null, + Snowflake? before = null, + Snowflake? after = null, + int? limit = null, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Gets a message by its snowflake identifier. + /// + /// The snowflake identifier of the message's parent channel. + /// The snowflake identifier of the message in question. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public ValueTask> GetChannelMessageAsync + ( + Snowflake channelId, + Snowflake messageId, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Creates a new message in a channel. + /// + /// The snowflake identifier of the message's target channel. + /// Message creation payload including potential attachment files. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + /// The newly created message object. + public ValueTask> CreateMessageAsync + ( + Snowflake channelId, + ICreateMessagePayload payload, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Publishes a message in an announcement channel to following channels. + /// + /// The origin announcement channel of this message. + /// The snowflake identifier of the message. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public ValueTask> CrosspostMessageAsync + ( + Snowflake channelId, + Snowflake messageId, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Creates a reaction with the given emoji on the specified message. + /// + /// The snowflake identifier of the message's parent channel. + /// The snowflake identifier of the message in question. + /// The string representation of the emoji. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + /// Whether the reaction was added successfully. + public ValueTask> CreateReactionAsync + ( + Snowflake channelId, + Snowflake messageId, + string emoji, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Deletes your own reaction with the specified emoji on the specified message. + /// + /// The snowflake identifier of the message's parent channel. + /// The snowflake identifier of the message in question. + /// The string representation of the emoji. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + /// Whether the reaction was removed successfully. + public ValueTask> DeleteOwnReactionAsync + ( + Snowflake channelId, + Snowflake messageId, + string emoji, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Deletes the specified user's reaction with the specified emoji on the specified message. + /// + /// The snowflake identifier of the message's parent channel. + /// The snowflake identifier of the message in question. + /// The snowflake identifier of the user in question. + /// The string representation of the emoji. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + /// Whether the reaction was removed successfully. + public ValueTask> DeleteUserReactionAsync + ( + Snowflake channelId, + Snowflake messageId, + Snowflake userId, + string emoji, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Gets a list of users that reacted with the given emoji. + /// + /// The snowflake identifier of the message's parent channel. + /// The snowflake identifier of the message in question. + /// The string representation of the queried emoji. + /// Specifies a minimum user ID to return from, to paginate queries. + /// The maximum amount of users to return. Defaults to 25. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public ValueTask>> GetReactionsAsync + ( + Snowflake channelId, + Snowflake messageId, + string emoji, + Snowflake? after = null, + int? limit = null, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Deletes all reactions on the given message. + /// + /// The snowflake identifier of the message's parent channel. + /// The snowflake identifier of the message in question. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public ValueTask DeleteAllReactionsAsync + ( + Snowflake channelId, + Snowflake messageId, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Deletes all reactions with a specific emoji from the specified message. + /// + /// The snowflake identifier of the message's parent channel. + /// The snowflake identifier of the message in question. + /// The string representation of the emoji in question. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public ValueTask DeleteAllReactionsForEmojiAsync + ( + Snowflake channelId, + Snowflake messageId, + string emoji, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Edits the given message. + /// + /// The snowflake identifier of the message's parent channel. + /// The snowflake identifier of the message in question. + /// A payload object containing information on how to edit this message. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public ValueTask> EditMessageAsync + ( + Snowflake channelId, + Snowflake messageId, + IEditMessagePayload payload, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Deletes a given message. + /// + /// The nowflake identifier of the message's parent channel. + /// The snowflake identifier of the message. + /// An optional audit log reason. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + /// Whether the message was successfully deleted. + public ValueTask> DeleteMessageAsync + ( + Snowflake channelId, + Snowflake messageId, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Bulk-deletes the provided messages. + /// + /// The snowflake identifier of the message's parent channel. + /// + /// Up to 100 message IDs to delete. If any messages older than two weeks are included, + /// or any of the IDs are duplicated, the entire request will fail. + /// + /// An optional audit log reason. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + /// Whether the messages were deleted successfully. + public ValueTask> BulkDeleteMessagesAsync + ( + Snowflake channelId, + IReadOnlyList messageIds, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Edits a permission overwrite for a guild channel. + /// + /// The snowflake identifier for the channel in question. + /// The snowflake identifier of the entity (role/user) this overwrite targets. + /// The overwrite data to apply. + /// An optional audit log reason. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + /// Whether the overwrite was successfully edited. + public ValueTask> EditChannelPermissionsAsync + ( + Snowflake channelId, + Snowflake overwriteId, + IEditChannelPermissionsPayload payload, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Returns a list of invite objects with invite metadata pointing to this channel. + /// + /// The snowflake identifier of the channel in question. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public ValueTask>> GetChannelInvitesAsync + ( + Snowflake channelId, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Creates an invite on the specified channel. + /// + /// Snowflake identifier of the channel in question. + /// A payload containing information on the invite. + /// An optional audit log reason. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + /// The newly created invite object. + public ValueTask> CreateChannelInviteAsync + ( + Snowflake channelId, + ICreateChannelInvitePayload payload, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Deletes a channel permission overwrite. + /// + /// The snowflake identifier of the channel in question. + /// The snowflake identifier of the object this overwrite points to. + /// An optional audit log reason. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + /// Whether the deletion was successful. + public ValueTask> DeleteChannelPermissionAsync + ( + Snowflake channelId, + Snowflake overwriteId, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Follows an announcement channel. + /// + /// The snowflake identifier of the news channel to follow. + /// + /// The payload, containing the snowflake identifier of the channel you want messages to be cross-posted into. + /// + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + /// The created followed channel object. + public ValueTask> FollowAnnouncementChannelAsync + ( + Snowflake channelId, + IFollowAnnouncementChannelPayload payload, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Triggers the typing indicator for the current user in the given channel. + /// + /// The snowflake identifier of the channel in question. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public ValueTask TriggerTypingIndicatorAsync + ( + Snowflake channelId, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Returns all pinned messages as message objects. + /// + /// The snowflake identifier of the messages' parent channel. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public ValueTask>> GetPinnedMessagesAsync + ( + Snowflake channelId, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Pins a message. + /// + /// The snowflake identifier of the message's parent channel. + /// The snowflake identifier of the message in question. + /// An optional audit log reason. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + /// Whether the message was successfully pinned. + public ValueTask PinMessageAsync + ( + Snowflake channelId, + Snowflake messageId, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Unpins a message. + /// + /// The snowflake identifier of the message's parent channel. + /// The snowflake identifier of the message in question. + /// An optional audit log reason. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + /// Whether the message was successfully unpinned. + public ValueTask UnpinMessageAsync + ( + Snowflake channelId, + Snowflake messageId, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Adds the given user to a specified group DM channel. + /// + /// The snowflake identifier of the group DM channel in question. + /// The snowflake identifier of the user in question. + /// Request payload, containing the access token needed. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public ValueTask GroupDMAddRecipientAsync + ( + Snowflake channelId, + Snowflake userId, + IGroupDMAddRecipientPayload payload, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Removes the given user from the given group DM channel. + /// + /// The snowflake identifier of the group DM channel in question. + /// The snowflake identifier of the user in question. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public ValueTask GroupDMRemoveRecipientAsync + ( + Snowflake channelId, + Snowflake userId, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Creates a new thread channel from the given message. + /// + /// The snowflake identifier of the thread's parent channel. + /// The snowflake identifier of the thread's parent message. + /// Request payload for this request. + /// An optional audit log reason. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + /// The newly created thread channel. + public ValueTask> StartThreadFromMessageAsync + ( + Snowflake channelId, + Snowflake messageId, + IStartThreadFromMessagePayload payload, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Creates a new thread channel without a message. + /// + /// The snowflake identifier of the thread's parent channel. + /// Request payload for this request. + /// An optional audit log reason. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + /// The newly created thread channel. + public ValueTask> StartThreadWithoutMessageAsync + ( + Snowflake channelId, + IStartThreadWithoutMessagePayload payload, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Creates a new thread with a starting message in a forum channel. + /// + /// The snowflake identifier of the parent forum channel. + /// + /// A payload object for starting a thread from a message containing a . + /// A new message is created, then a thread is started from it. + /// + /// An optional audit log reason. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + /// The newly created thread channel. + public ValueTask> StartThreadInForumOrMediaChannelAsync + ( + Snowflake channelId, + IStartThreadInForumOrMediaChannelPayload payload, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Joins the current user into a thread. + /// + /// The snowflake identifier of the thread channel to be joined. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + /// Whether the operation was successful. + public ValueTask JoinThreadAsync + ( + Snowflake threadId, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Adds another member into a thread. + /// + /// The nowflake identifier of the thread to be joined. + /// The snowflake identifier of the user to join into the thread. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + /// Whether the operation was successful. + public ValueTask AddToThreadAsync + ( + Snowflake threadId, + Snowflake userId, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Leaves a thread as the current bot. + /// + /// The snowflake identifier of the thread to be left. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + /// Whether the operation was successful. + public ValueTask LeaveThreadAsync + ( + Snowflake threadId, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Removes another user from a thread. + /// + /// The snowflake identifier of the thread to be left. + /// The snowflake identifier of the user to be removed. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + /// Whether the operation was successful. + public ValueTask RemoveFromThreadAsync + ( + Snowflake threadId, + Snowflake userId, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Returns a thread member object for the specified user. + /// + /// The snowflake identifier of the thread to obtain data from. + /// The snowflake identifier of the user to obtain data for. + /// Whether the returned thread member object should contain guild member data. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public ValueTask> GetThreadMemberAsync + ( + Snowflake threadId, + Snowflake userId, + bool? withMember = null, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Returns a list of all thread members for the specified thread. + /// + /// The snowflake identifier fo the thread to obtain data from. + /// Whether the returned thread member object should contain guild member data. + /// Gets thread members after this snowflake ID. + /// The maximum number of thread members to return. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public ValueTask>> ListThreadMembersAsync + ( + Snowflake threadId, + bool? withMember = null, + Snowflake? after = null, + int? limit = null, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Returns all public, archived threads for this channel including respective thread member objects. + /// + /// The snowflake identifier of the thread's parent channel. + /// + /// Timestamp to filter threads by: only threads archived before this timestamp will be returned. + /// + /// The maximum amount of threads to return. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public ValueTask> ListPublicArchivedThreadsAsync + ( + Snowflake channelId, + DateTimeOffset? before, + int? limit = null, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Returns all private, accessible, archived threads for this channel including respective thread member objects. + /// + /// The snowflake identifier of the thread's parent channel. + /// + /// Timestamp to filter threads by: only threads archived before this timestamp will be returned. + /// + /// The maximum amount of threads to return. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public ValueTask> ListPrivateArchivedThreadsAsync + ( + Snowflake channelId, + DateTimeOffset? before, + int? limit = null, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Returns a list of joined, private, archived threads. + /// + /// The nowflake identifier of their parent channel. + /// A timestamp to act as upper boundary for archival dates. + /// The maximum amount of threads to return from this request. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public ValueTask> ListJoinedPrivateArchivedThreadsAsync + ( + Snowflake channelId, + DateTimeOffset? before, + int? limit = null, + RequestInfo info = default, + CancellationToken ct = default + ); +} + diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Channels/ICreateChannelInvitePayload.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Channels/ICreateChannelInvitePayload.cs new file mode 100644 index 0000000000..0787ed0a21 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Channels/ICreateChannelInvitePayload.cs @@ -0,0 +1,50 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Entities; + +namespace DSharpPlus.Core.Abstractions.Rest.Payloads; + +/// +/// Represents a payload to POST /channels/:channel-id/invites. +/// +public interface ICreateChannelInvitePayload +{ + /// + /// Specifies the expiry time in seconds for this invite. Setting it to 0 means the invite never expires. + /// + public Optional MaxAge { get; init; } + + /// + /// Specifies the maximum amount of uses for this invite. Setting it to 0 means the invite can be used infinitely. + /// + public Optional MaxUses { get; init; } + + /// + /// Indicates whether this invite only grants temporary membership. + /// + public Optional Temporary { get; init; } + + /// + /// Specifies whether this invite is unique. If true, Discord will not try to reuse a similar invite. + /// + public Optional Unique { get; init; } + + /// + /// Specifies the target type of this voice channel invite. + /// + public Optional TargetType { get; init; } + + /// + /// Snowflake identifier of the invite's target user if is + /// . + /// + public Optional TargetUserId { get; init; } + + /// + /// Snowflake identifier of the invite's target embedded application if is + /// . + /// + public Optional TargetApplicationId { get; init; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Channels/ICreateMessagePayload.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Channels/ICreateMessagePayload.cs new file mode 100644 index 0000000000..b687cc5e70 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Channels/ICreateMessagePayload.cs @@ -0,0 +1,71 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Entities; + +namespace DSharpPlus.Core.Abstractions.Rest.Payloads; + +/// +/// Represents a payload to POST /channels/:channel-id/messages. +/// +public interface ICreateMessagePayload +{ + /// + /// The message content to send. + /// + public Optional Content { get; } + + /// + /// An identifier for this message. This will be sent in the MESSAGE_CREATE event. + /// + public Optional Nonce { get; } + + /// + /// Indicates whether this message is a text-to-speech message. + /// + public Optional Tts { get; } + + /// + /// Up to 10 embeds to be attached to this message. + /// + public Optional> Embeds { get; } + + /// + /// Specifies which mentions should be resolved. + /// + public Optional AllowedMentions { get; } + + /// + /// A reference to the message this message shall reply to. + /// + public Optional MessageReference { get; } + + /// + /// A list of components to include with the message. + /// + public Optional> Components { get; } + + /// + /// Up to 3 snowflake identifiers of stickers to be attached to this message. + /// + public Optional> StickerIds { get; } + + /// + /// Files to be attached to this message. + /// + public IReadOnlyList? Files { get; } + + /// + /// Attachment metadata for this message. + /// + public Optional> Attachments { get; } + + /// + /// Message flags, combined as bitfield. Only can be set. + /// + public Optional Flags { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Channels/IEditChannelPermissionsPayload.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Channels/IEditChannelPermissionsPayload.cs new file mode 100644 index 0000000000..011bc0c4d2 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Channels/IEditChannelPermissionsPayload.cs @@ -0,0 +1,28 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Entities; + +namespace DSharpPlus.Core.Abstractions.Rest.Payloads; + +/// +/// Represents a payload for PUT /channels/:channel-id/permissions/:overwrite-id. +/// +public interface IEditChannelPermissionsPayload +{ + /// + /// The overwrite type - either role or member. + /// + public DiscordChannelOverwriteType Type { get; } + + /// + /// The permissions this overwrite should grant. + /// + public Optional Allow { get; } + + /// + /// The permissions this overwrite should deny. + /// + public Optional Deny { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Channels/IEditMessagePayload.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Channels/IEditMessagePayload.cs new file mode 100644 index 0000000000..f74107b371 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Channels/IEditMessagePayload.cs @@ -0,0 +1,54 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Entities; + +namespace DSharpPlus.Core.Abstractions.Rest.Payloads; + +/// +/// Represents a payload to PATCH /channels/:channel-id/messages/:message-id. +/// +public interface IEditMessagePayload +{ + /// + /// New string content of the message, up to 2000 characters. + /// + public Optional Content { get; } + + /// + /// Up to 10 embeds for this message. + /// + public Optional?> Embeds { get; } + + /// + /// New flags for this message. Only can currently be set + /// or unset. + /// + public Optional Flags { get; } + + /// + /// Authoritative allowed mentions object for this message. Passing resets + /// the object to default. + /// + public Optional AllowedMentions { get; } + + /// + /// New components for this message. + /// + public Optional?> Components { get; } + + /// + /// Attached files to this message. This must include old attachments to be retained and new attachments, + /// if passed. + /// + public IReadOnlyList? Files { get; } + + /// + /// Attachments to this message. + /// + public Optional?> Attachments { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Channels/IFollowAnnouncementChannelPayload.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Channels/IFollowAnnouncementChannelPayload.cs new file mode 100644 index 0000000000..e4193cf65c --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Channels/IFollowAnnouncementChannelPayload.cs @@ -0,0 +1,16 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Core.Abstractions.Rest.Payloads; + +/// +/// Represents a payload to POST /channels/:channel-id/followers +/// +public interface IFollowAnnouncementChannelPayload +{ + /// + /// The snowflake identifier of the channel to cross-post messages into. + /// + public Snowflake WebhookChannelId { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Channels/IForumAndMediaThreadMessage.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Channels/IForumAndMediaThreadMessage.cs new file mode 100644 index 0000000000..25dc1a563a --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Channels/IForumAndMediaThreadMessage.cs @@ -0,0 +1,51 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Entities; + +namespace DSharpPlus.Core.Abstractions.Rest.Payloads; + +public interface IForumAndMediaThreadMessage +{ + /// + /// The message content to send. + /// + public Optional Content { get; } + + /// + /// Up to 10 embeds to be attached to this message. + /// + public Optional> Embeds { get; } + + /// + /// Specifies which mentions should be resolved. + /// + public Optional AllowedMentions { get; } + + /// + /// A list of components to include with the message. + /// + public Optional> Components { get; } + + /// + /// Up to 3 snowflake identifiers of stickers to be attached to this message. + /// + public Optional> StickerIds { get; } + + /// + /// Attachment metadata for this message. + /// + /// + /// The files have to be attached to the parent object. + /// + public Optional> Attachments { get; } + + /// + /// Message flags, combined as bitfield. Only can be set. + /// + public Optional Flags { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Channels/IGroupDMAddRecipientPayload.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Channels/IGroupDMAddRecipientPayload.cs new file mode 100644 index 0000000000..4b570be1c9 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Channels/IGroupDMAddRecipientPayload.cs @@ -0,0 +1,21 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Core.Abstractions.Rest.Payloads; + +/// +/// Represents a payload to PUT /channel/:channel-id/recipients/:user-id. +/// +public interface IGroupDMAddRecipientPayload +{ + /// + /// The access token of the user, which must have granted you the gdm.join oauth scope. + /// + public string AccessToken { get; } + + /// + /// The nickname of the user, to be given on join. + /// + public string Nick { get; init; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Channels/IModifyGroupDMPayload.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Channels/IModifyGroupDMPayload.cs new file mode 100644 index 0000000000..045769bab0 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Channels/IModifyGroupDMPayload.cs @@ -0,0 +1,21 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Core.Abstractions.Rest.Payloads; + +/// +/// Represents a payload to PATCH /channels/:channel-id. +/// +public interface IModifyGroupDMPayload +{ + /// + /// The name of this group DM channel. + /// + public Optional Name { get; } + + /// + /// The icon of this group DM channel. + /// + public Optional Icon { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Channels/IModifyGuildChannelPayload.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Channels/IModifyGuildChannelPayload.cs new file mode 100644 index 0000000000..9845e58bfa --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Channels/IModifyGuildChannelPayload.cs @@ -0,0 +1,113 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Entities; + +namespace DSharpPlus.Core.Abstractions.Rest.Payloads; + +/// +/// Represents a payload to PATCH /channels/:channel-id. +/// +public interface IModifyGuildChannelPayload +{ + /// + /// The new channel name. + /// + public Optional Name { get; } + + /// + /// The new channel type for this channel. Only converting between and + /// is supported. + /// + public Optional Type { get; } + + /// + /// The new position for this channel in the channel list. + /// + public Optional Position { get; } + + /// + /// The new channel topic. + /// + public Optional Topic { get; } + + /// + /// Indicates whether this channel permits NSFW content. + /// + public Optional Nsfw { get; } + + /// + /// The new slowmode for this channel in seconds. + /// + public Optional RateLimitPerUser { get; } + + /// + /// The new bitrate for this voice channel. + /// + public Optional Bitrate { get; } + + /// + /// The new user limit for this voice channel. 0 represents no limit, 1 - 99 represents a limit. + /// + public Optional UserLimit { get; } + + /// + /// New permission overwrites for this channel or category. + /// + public Optional?> PermissionOverwrites { get; } + + /// + /// Snowflake identifier of the new parent category channel. + /// + public Optional ParentId { get; } + + /// + /// Channel voice region ID, automatic when set to null. + /// + public Optional RtcRegion { get; } + + /// + /// The new camera video quality mode for this channel. + /// + public Optional VideoQualityMode { get; } + + /// + /// The new default auto archive duration for threads as used by the discord client. + /// + public Optional DefaultAutoArchiveDuration { get; } + + /// + /// The new channel flags. Currently only and + /// are supported. + /// + public Optional Flags { get; } + + /// + /// The set of tags that can be used in this channel. + /// + public Optional> AvailableTags { get; } + + /// + /// The default emoji to react with. + /// + public Optional DefaultReactionEmoji { get; } + + /// + /// The default slowmode in threads created from this channel. + /// + public Optional DefaultThreadRateLimitPerUser { get; } + + /// + /// The default sort order used to order posts in this channel. + /// + public Optional DefaultSortOrder { get; } + + /// + /// The default layout type used to display posts in this forum. + /// + public Optional DefaultForumLayout { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Channels/IModifyThreadChannelPayload.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Channels/IModifyThreadChannelPayload.cs new file mode 100644 index 0000000000..73e4e788a3 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Channels/IModifyThreadChannelPayload.cs @@ -0,0 +1,55 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Entities; + +namespace DSharpPlus.Core.Abstractions.Rest.Payloads; + +/// +/// Represents a payload to PATCH /channels/:channel-id. +/// +public interface IModifyThreadChannelPayload +{ + /// + /// The new name for this thread channel. + /// + public Optional Name { get; } + + /// + /// Indicates whether this thread is archived. This must either be false or be set to false. + /// + public Optional Archived { get; } + + /// + /// The new auto archive duration for this thread, in seconds. + /// + public Optional AutoArchiveDuration { get; } + + /// + /// Indicates whether this thread is locked. + /// + public Optional Locked { get; } + + /// + /// Indicates whether non-moderators can add other non-moderators to this private thread. + /// + public Optional Invitable { get; } + + /// + /// The new slowmode duration for this thread, in seconds. + /// + public Optional RateLimitPerUser { get; } + + /// + /// Flags for this thread. + /// + public Optional Flags { get; } + + /// + /// The snowflake IDs of the tags that have been applied to this thread. + /// + public Optional> AppliedTags { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Channels/IStartThreadFromMessagePayload.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Channels/IStartThreadFromMessagePayload.cs new file mode 100644 index 0000000000..39d9599891 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Channels/IStartThreadFromMessagePayload.cs @@ -0,0 +1,26 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Core.Abstractions.Rest.Payloads; + +/// +/// Represents a payload to POST /channels/:channel-id/messages/:message-id/threads. +/// +public interface IStartThreadFromMessagePayload +{ + /// + /// 1-100 characters, channel name for this thread. + /// + public string Name { get; } + + /// + /// Auto archive duration for this thread in minutes. + /// + public Optional AutoArchiveDuration { get; } + + /// + /// Slowmode for users in seconds. + /// + public Optional RateLimitPerUser { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Channels/IStartThreadInForumOrMediaChannelPayload.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Channels/IStartThreadInForumOrMediaChannelPayload.cs new file mode 100644 index 0000000000..c8e3e26728 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Channels/IStartThreadInForumOrMediaChannelPayload.cs @@ -0,0 +1,43 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +namespace DSharpPlus.Core.Abstractions.Rest.Payloads; + +/// +/// Represents a payload to POST /channels/:channel-id/threads. +/// +public interface IStartThreadInForumOrMediaChannelPayload +{ + /// + /// 1-100 characters, channel name for this thread. + /// + public string Name { get; } + + /// + /// Auto archive duration for this thread in minutes. + /// + public Optional AutoArchiveDuration { get; } + + /// + /// Slowmode for users in seconds. + /// + public Optional RateLimitPerUser { get; } + + /// + /// The first message in this forum/media thread. + /// + public IForumAndMediaThreadMessage Message { get; } + + /// + /// The snowflake identifiers of tags to apply to this thread. + /// + public Optional> AppliedTags { get; } + + /// + /// The contents of the files to send. + /// + public IReadOnlyList? Files { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Channels/IStartThreadWithoutMessagePayload.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Channels/IStartThreadWithoutMessagePayload.cs new file mode 100644 index 0000000000..a1facf651a --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Channels/IStartThreadWithoutMessagePayload.cs @@ -0,0 +1,40 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Entities; + +namespace DSharpPlus.Core.Abstractions.Rest.Payloads; + +/// +/// Represents a payload to POST /channels/:channel-id/threads. +/// +public interface IStartThreadWithoutMessagePayload +{ + /// + /// 1-100 characters, channel name for this thread. + /// + public string Name { get; } + + /// + /// Auto archive duration for this thread in minutes. + /// + public Optional AutoArchiveDuration { get; } + + /// + /// Slowmode for users in seconds. + /// + public Optional RateLimitPerUser { get; } + + /// + /// The type of thread to be created. + /// + // This field is currently technically optional as per API spec, but this behaviour is slated for removal in the future. + // Therefore, it is kept as a required field here. + public DiscordChannelType Type { get; } + + /// + /// Indicates whether non-moderators can add members to this private thread. + /// + public Optional Invitable { get; init; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Responses/ListArchivedThreadsResponse.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/Responses/ListArchivedThreadsResponse.cs new file mode 100644 index 0000000000..4050ca4a65 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/Responses/ListArchivedThreadsResponse.cs @@ -0,0 +1,30 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Abstractions.Rest.Responses; + +/// +/// Represents the response received from fetching archived threads. +/// +public readonly record struct ListArchivedThreadsResponse +{ + /// + /// The archived threads. + /// + public IReadOnlyList Threads { get; } + + /// + /// The thread member objects for each returned thread the current user has joined. + /// + public IReadOnlyList Members { get; } + + /// + /// Indicates whether there are potentially additional threads that could be returned on a subsequent call. + /// + public bool HasMore { get; } +} From 98cc1e549677b2fb61ce21e6e651307ba8e58740 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Tue, 19 Dec 2023 16:21:42 +0100 Subject: [PATCH 208/323] optimize ImageData for serialization into JSON --- src/core/DSharpPlus.Shared/ImageData.cs | 234 +++--------------- .../Serialization/ImageDataConverter.cs | 2 +- 2 files changed, 34 insertions(+), 202 deletions(-) diff --git a/src/core/DSharpPlus.Shared/ImageData.cs b/src/core/DSharpPlus.Shared/ImageData.cs index f19d45e658..cb4c2dad3c 100644 --- a/src/core/DSharpPlus.Shared/ImageData.cs +++ b/src/core/DSharpPlus.Shared/ImageData.cs @@ -8,7 +8,6 @@ using System.Diagnostics; using System.IO; using System.IO.Pipelines; -using System.Threading.Tasks; using CommunityToolkit.HighPerformance.Buffers; @@ -25,26 +24,26 @@ public readonly record struct ImageData private static ReadOnlySpan WebpString => "data:image/webp;base64,"u8; private static ReadOnlySpan AutoString => "data:image/auto;base64,"u8; - private readonly PipeReader reader; + private readonly Stream reader; private readonly ImageFormat format; /// - /// Creates a new instance of this struct from the provided pipe. + /// Creates a new instance of this struct from the provided stream. /// - /// The PipeReader to convert to base64. + /// The Stream to convert to base64. /// The format of this image. - public ImageData(PipeReader reader, ImageFormat format) + public ImageData(Stream reader, ImageFormat format) { this.reader = reader; this.format = format; } /// - /// Creates a new instance of this struct from the provided stream. + /// Creates a new instance of this struct from the provided pipe. /// - /// The stream to conver to base64. + /// The pipe to conver to base64. /// The format of this image. - public ImageData(Stream stream, ImageFormat format) : this(PipeReader.Create(stream), format) + public ImageData(PipeReader reader, ImageFormat format) : this(reader.AsStream(), format) { } @@ -60,13 +59,13 @@ public ImageData(ReadOnlySequence data, ImageFormat format) : this(PipeRea } /// - /// Writes the base64 data to the specified PipeWriter. + /// Writes the base64 data to the specified array pool buffer writer. /// - public readonly async ValueTask WriteToAsync(PipeWriter writer) + public readonly void WriteTo(ArrayPoolBufferWriter writer) { // chosen because a StreamPipeReader buffers to 4096 - const int readSegmentLength = 4096; - const int writeSegmentLength = 5120; + const int readSegmentLength = 12288; + const int writeSegmentLength = 16384; writer.Write ( @@ -83,213 +82,46 @@ public readonly async ValueTask WriteToAsync(PipeWriter writer) byte[] readBuffer = ArrayPool.Shared.Rent(readSegmentLength); byte[] writeBuffer = ArrayPool.Shared.Rent(writeSegmentLength); + scoped Span readSpan = readBuffer.AsSpan()[..readSegmentLength]; + scoped Span writeSpan = writeBuffer.AsSpan()[..writeSegmentLength]; + int readRollover = 0; while (true) { - ReadResult result = await this.reader.ReadAsync(); + int read = this.reader.Read(readSpan[readRollover..]); + int currentLength = read + readRollover; - if (result.IsCanceled) + if (read == 0) { break; } - ProcessResult(result, this.reader); - - if (result.IsCompleted) - { - break; - } - } - - ArrayPool.Shared.Return(readBuffer); - ArrayPool.Shared.Return(writeBuffer); - - void ProcessResult(ReadResult result, PipeReader reader) - { - SequenceReader sequence = new(result.Buffer); - - scoped Span readSpan = readBuffer.AsSpan()[..readSegmentLength]; - scoped Span writeSpan = writeBuffer.AsSpan()[..writeSegmentLength]; - - while (!sequence.End) - { - if (readRollover != 0) - { - if (sequence.Remaining + readRollover >= readSegmentLength) - { - sequence.TryCopyTo(readSpan[readRollover..]); - - sequence.Advance(readSegmentLength - readRollover); - readRollover = 0; - } - else - { - sequence.TryCopyTo(readSpan.Slice(readRollover, (int)sequence.Remaining)); - - readRollover += (int)sequence.Remaining; - sequence.Advance((int)sequence.Remaining); - break; - } - } - else if (sequence.Remaining >= readSegmentLength) - { - sequence.TryCopyTo(readSpan); - - sequence.Advance(readSegmentLength); - } - else - { - sequence.TryCopyTo(readSpan[..(int)sequence.Remaining]); - - readRollover += (int)sequence.Remaining; - sequence.AdvanceToEnd(); - break; - } + OperationStatus status = Base64.EncodeToUtf8 + ( + bytes: readSpan[..currentLength], + utf8: writeSpan, + bytesConsumed: out int consumed, + bytesWritten: out int written, + isFinalBlock: false + ); - OperationStatus status = Base64.EncodeToUtf8(readSpan, writeSpan, out int consumed, out int written, false); + Debug.Assert(status is OperationStatus.Done or OperationStatus.NeedMoreData); + Debug.Assert(read - consumed < 3); - Debug.Assert - ( - consumed != readSegmentLength || written != writeSegmentLength, - "Buffer management error while converting to base64. Aborting." - ); + writer.Write(writeSpan[..written]); - Debug.Assert(status == OperationStatus.Done); - - writer.Write(writeSpan[..written]); - } - - if (result.IsCompleted) - { - OperationStatus status = Base64.EncodeToUtf8(readSpan[..readRollover], writeSpan, out int _, out int written, true); - - Debug.Assert(status == OperationStatus.Done); - - writer.Write(writeSpan[..written]); - - writer.Complete(); - reader.Complete(); - return; - } - - reader.AdvanceTo(result.Buffer.End); + readSpan[consumed..currentLength].CopyTo(readSpan[0..]); + readRollover = currentLength - consumed; } - } - /// - /// Writes the base64 data to the specified ArrayPoolBufferWriter. - /// - public readonly async ValueTask WriteToAsync(ArrayPoolBufferWriter writer) - { - const int readSegmentLength = 4096; - const int writeSegmentLength = 5120; + OperationStatus lastStatus = Base64.EncodeToUtf8(readSpan[..readRollover], writeSpan, out int _, out int lastWritten); - writer.Write - ( - this.format switch - { - ImageFormat.Png => PngString, - ImageFormat.Gif => GifString, - ImageFormat.Jpeg => JpegString, - ImageFormat.WebP => WebpString, - _ => AutoString - } - ); + Debug.Assert(lastStatus == OperationStatus.Done); - byte[] readBuffer = ArrayPool.Shared.Rent(readSegmentLength); - byte[] writeBuffer = ArrayPool.Shared.Rent(writeSegmentLength); - - int readRollover = 0; - - while (true) - { - ReadResult result = await this.reader.ReadAsync(); - - if (result.IsCanceled) - { - break; - } - - ProcessResult(result, this.reader); - - if (result.IsCompleted) - { - break; - } - } + writer.Write(writeSpan[..lastWritten]); ArrayPool.Shared.Return(readBuffer); ArrayPool.Shared.Return(writeBuffer); - - void ProcessResult(ReadResult result, PipeReader reader) - { - SequenceReader sequence = new(result.Buffer); - - scoped Span readSpan = readBuffer.AsSpan()[..readSegmentLength]; - scoped Span writeSpan = writeBuffer.AsSpan()[..writeSegmentLength]; - - while (!sequence.End) - { - if (readRollover != 0) - { - if (sequence.Remaining + readRollover >= readSegmentLength) - { - sequence.TryCopyTo(readSpan[readRollover..]); - - sequence.Advance(readSegmentLength - readRollover); - readRollover = 0; - } - else - { - sequence.TryCopyTo(readSpan.Slice(readRollover, (int)sequence.Remaining)); - - readRollover += (int)sequence.Remaining; - sequence.Advance((int)sequence.Remaining); - break; - } - } - else if (sequence.Remaining >= readSegmentLength) - { - sequence.TryCopyTo(readSpan); - - sequence.Advance(readSegmentLength); - } - else - { - sequence.TryCopyTo(readSpan[..(int)sequence.Remaining]); - - readRollover += (int)sequence.Remaining; - sequence.AdvanceToEnd(); - break; - } - - OperationStatus status = Base64.EncodeToUtf8(readSpan, writeSpan, out int consumed, out int written, false); - - Debug.Assert - ( - consumed != readSegmentLength || written != writeSegmentLength, - "Buffer management error while converting to base64. Aborting." - ); - - Debug.Assert(status == OperationStatus.Done); - - writer.Write(writeSpan[..written]); - } - - if (result.IsCompleted) - { - OperationStatus status = Base64.EncodeToUtf8(readSpan[..readRollover], writeSpan, out int _, out int written, true); - - Debug.Assert(status == OperationStatus.Done); - - writer.Write(writeSpan[..written]); - - reader.Complete(); - return; - } - - reader.AdvanceTo(result.Buffer.End); - } } } diff --git a/src/core/DSharpPlus.Shared/Serialization/ImageDataConverter.cs b/src/core/DSharpPlus.Shared/Serialization/ImageDataConverter.cs index 8e9155ef2d..52ae3feee2 100644 --- a/src/core/DSharpPlus.Shared/Serialization/ImageDataConverter.cs +++ b/src/core/DSharpPlus.Shared/Serialization/ImageDataConverter.cs @@ -26,7 +26,7 @@ JsonSerializerOptions options { using ArrayPoolBufferWriter bufferWriter = new(65536); - value.WriteToAsync(bufferWriter).AsTask().GetAwaiter().GetResult(); + value.WriteTo(bufferWriter); writer.WriteStringValue(bufferWriter.WrittenSpan); } From 34dae32de7852cec9c05b9b091317c71d9896089 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Wed, 20 Dec 2023 21:16:13 +0100 Subject: [PATCH 209/323] introducing AttachmentData --- .../Channels/ICreateMessagePayload.cs | 2 +- .../Payloads/Channels/IEditMessagePayload.cs | 2 +- ...StartThreadInForumOrMediaChannelPayload.cs | 2 +- .../ICreateFollowupMessagePayload.cs | 2 +- .../IEditFollowupMessagePayload.cs | 2 +- .../IEditInteractionResponsePayload.cs | 2 +- src/core/DSharpPlus.Shared/AttachmentData.cs | 212 ++++++++++++++++++ 7 files changed, 218 insertions(+), 6 deletions(-) create mode 100644 src/core/DSharpPlus.Shared/AttachmentData.cs diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Channels/ICreateMessagePayload.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Channels/ICreateMessagePayload.cs index b687cc5e70..56c5dbdacd 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Channels/ICreateMessagePayload.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Channels/ICreateMessagePayload.cs @@ -57,7 +57,7 @@ public interface ICreateMessagePayload /// /// Files to be attached to this message. /// - public IReadOnlyList? Files { get; } + public IReadOnlyList? Files { get; } /// /// Attachment metadata for this message. diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Channels/IEditMessagePayload.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Channels/IEditMessagePayload.cs index f74107b371..006b53ec41 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Channels/IEditMessagePayload.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Channels/IEditMessagePayload.cs @@ -45,7 +45,7 @@ public interface IEditMessagePayload /// Attached files to this message. This must include old attachments to be retained and new attachments, /// if passed. /// - public IReadOnlyList? Files { get; } + public IReadOnlyList? Files { get; } /// /// Attachments to this message. diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Channels/IStartThreadInForumOrMediaChannelPayload.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Channels/IStartThreadInForumOrMediaChannelPayload.cs index c8e3e26728..4beb914d6b 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Channels/IStartThreadInForumOrMediaChannelPayload.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Channels/IStartThreadInForumOrMediaChannelPayload.cs @@ -39,5 +39,5 @@ public interface IStartThreadInForumOrMediaChannelPayload /// /// The contents of the files to send. /// - public IReadOnlyList? Files { get; } + public IReadOnlyList? Files { get; } } diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Interactions/ICreateFollowupMessagePayload.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Interactions/ICreateFollowupMessagePayload.cs index fc8975a4bf..15e7f72296 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Interactions/ICreateFollowupMessagePayload.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Interactions/ICreateFollowupMessagePayload.cs @@ -45,7 +45,7 @@ public interface ICreateFollowupMessagePayload /// /// Files to upload with this message. /// - public Optional> Files { get; } + public IReadOnlyList? Files { get; } /// /// Attachment metadata for files uploaded with this message. diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Interactions/IEditFollowupMessagePayload.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Interactions/IEditFollowupMessagePayload.cs index 232dd0fa0a..a7447d767a 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Interactions/IEditFollowupMessagePayload.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Interactions/IEditFollowupMessagePayload.cs @@ -41,5 +41,5 @@ public interface IEditFollowupMessagePayload /// /// File contents to send or edit. /// - public Optional> Files { get; } + public IReadOnlyList? Files { get; } } diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Interactions/IEditInteractionResponsePayload.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Interactions/IEditInteractionResponsePayload.cs index 4254c8c5ce..8ac4a7351a 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Interactions/IEditInteractionResponsePayload.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Interactions/IEditInteractionResponsePayload.cs @@ -41,5 +41,5 @@ public interface IEditInteractionResponsePayload /// /// File contents to send or edit. /// - public Optional> Files { get; } + public IReadOnlyList? Files { get; } } diff --git a/src/core/DSharpPlus.Shared/AttachmentData.cs b/src/core/DSharpPlus.Shared/AttachmentData.cs new file mode 100644 index 0000000000..da13a36a55 --- /dev/null +++ b/src/core/DSharpPlus.Shared/AttachmentData.cs @@ -0,0 +1,212 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Buffers; +using System.Diagnostics; +using System; +using System.IO; +using System.IO.Pipelines; +using System.Threading.Tasks; +using System.Buffers.Text; + +namespace DSharpPlus; + +/// +/// Represents a file sent to Discord as a message attachment. +/// +public readonly record struct AttachmentData +{ + private readonly Stream stream; + + /// + /// The media type of this attachment. Defaults to empty, in which case it will be interpreted according to + /// the file extension as provided by . + /// + public string? MediaType { get; init; } + + /// + /// The filename of this attachment. + /// + public required string Filename { get; init; } + + /// + /// Specifies whether to encode the attachment as base64. + /// + public bool ConvertToBase64 { get; init; } + + /// + /// Creates a new instance of this structure from the provided stream. + /// + /// A stream containing the attachment. + /// The name of this file to upload. + /// The media type of this file. + /// Whether to upload the attachment as base64. + public AttachmentData + ( + Stream stream, + string filename, + string? mediaType = null, + bool base64 = false + ) + { + this.stream = stream; + this.MediaType = mediaType; + this.Filename = filename; + this.ConvertToBase64 = base64; + } + + /// + /// Creates a new instance of this structure from the provided pipe. + /// + /// A reader to the pipe. + /// The name of this file to upload. + /// The media type of this file. + /// Whether to upload the attachment as base64. + public AttachmentData + ( + PipeReader reader, + string filename, + string? mediaType = null, + bool base64 = false + ) + : this + ( + reader.AsStream(), + filename, + mediaType, + base64 + ) + { + + } + + public async ValueTask GetStreamAsync() + { + if (this.ConvertToBase64) + { + Pipe pipe = new(); + await this.WriteToPipeAsBase64Async(pipe.Writer); + + return pipe.Reader.AsStream(); + } + + return this.stream; + } + + /// + /// Writes the base64 data to the specified PipeWriter. + /// + private readonly async ValueTask WriteToPipeAsBase64Async(PipeWriter writer) + { + const int readSegmentLength = 12288; + const int writeSegmentLength = 16384; + + PipeReader reader = PipeReader.Create + ( + this.stream, + new StreamPipeReaderOptions + ( + bufferSize: 12288, + leaveOpen: true, + useZeroByteReads: true + ) + ); + + byte[] readBuffer = ArrayPool.Shared.Rent(readSegmentLength); + byte[] writeBuffer = ArrayPool.Shared.Rent(writeSegmentLength); + + int readRollover = 0; + + while (true) + { + ReadResult result = await reader.ReadAsync(); + + if (result.IsCanceled) + { + break; + } + + ProcessResult(result, reader); + + if (result.IsCompleted) + { + break; + } + } + + ArrayPool.Shared.Return(readBuffer); + ArrayPool.Shared.Return(writeBuffer); + + void ProcessResult(ReadResult result, PipeReader reader) + { + SequenceReader sequence = new(result.Buffer); + + scoped Span readSpan = readBuffer.AsSpan()[..readSegmentLength]; + scoped Span writeSpan = writeBuffer.AsSpan()[..writeSegmentLength]; + + while (!sequence.End) + { + if (readRollover != 0) + { + if (sequence.Remaining + readRollover >= readSegmentLength) + { + sequence.TryCopyTo(readSpan[readRollover..]); + + sequence.Advance(readSegmentLength - readRollover); + readRollover = 0; + } + else + { + sequence.TryCopyTo(readSpan.Slice(readRollover, (int)sequence.Remaining)); + + readRollover += (int)sequence.Remaining; + sequence.Advance((int)sequence.Remaining); + break; + } + } + else if (sequence.Remaining >= readSegmentLength) + { + sequence.TryCopyTo(readSpan); + + sequence.Advance(readSegmentLength); + } + else + { + sequence.TryCopyTo(readSpan[..(int)sequence.Remaining]); + + readRollover += (int)sequence.Remaining; + sequence.AdvanceToEnd(); + break; + } + + OperationStatus status = Base64.EncodeToUtf8(readSpan, writeSpan, out int consumed, out int written, false); + + Debug.Assert + ( + consumed != readSegmentLength || written != writeSegmentLength, + "Buffer management error while converting to base64. Aborting." + ); + + Debug.Assert(status == OperationStatus.Done); + + writer.Write(writeSpan[..written]); + } + + if (result.IsCompleted) + { + OperationStatus status = Base64.EncodeToUtf8(readSpan[..readRollover], writeSpan, out int _, out int written, true); + + Debug.Assert(status == OperationStatus.Done); + + writer.Write(writeSpan[..written]); + + writer.Complete(); + reader.Complete(); + return; + } + + reader.AdvanceTo(result.Buffer.End); + } + } +} From e1853d979ca6070a8743aa18f002f217ee3ebb1b Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Wed, 20 Dec 2023 21:30:18 +0100 Subject: [PATCH 210/323] emoji rest api --- .../API/IEmojiRestAPI.cs | 104 ++++++++++++++++++ .../Emojis/ICreateGuildEmojiPayload.cs | 28 +++++ .../Emojis/IModifyGuildEmojiPayload.cs | 23 ++++ 3 files changed, 155 insertions(+) create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/API/IEmojiRestAPI.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Emojis/ICreateGuildEmojiPayload.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Emojis/IModifyGuildEmojiPayload.cs diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IEmojiRestAPI.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IEmojiRestAPI.cs new file mode 100644 index 0000000000..bc142dd03b --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IEmojiRestAPI.cs @@ -0,0 +1,104 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; + +using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Core.Abstractions.Rest.Payloads; + +using Remora.Results; + +namespace DSharpPlus.Core.Abstractions.Rest.API; + +/// +/// Represents a request wrapper for all request to discord's emoji rest resource. +/// +public interface IDiscordEmojiRestResource +{ + /// + /// Fetches a list of emojis for the given guild. + /// + /// The snowflake identifier of the guild in question. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public ValueTask>> ListGuildEmojisAsync + ( + Snowflake guildId, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Returns the specified emoji. + /// + /// The snowflake identifier of the guild owning the emoji. + /// The snowflake identifier of the emoji in question. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public ValueTask> GetGuildEmojiAsync + ( + Snowflake guildId, + Snowflake emojiId, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Creates a new guild emoji in the specified guild. + /// + /// The snowflake identifier of the guild in question. + /// The payload containing information on the emoji. + /// An optional audit log reason. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + /// The newly created emoji. + public ValueTask> CreateGuildEmojiAsync + ( + Snowflake guildId, + ICreateGuildEmojiPayload payload, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Modifies the given emoji. + /// + /// The snowflake identifier of the guild owning the emoji. + /// The snowflake identifier of the emoji in question. + /// A payload detailing the edit to make to this emoji. + /// An optional audit log reason. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + /// The newly updated emoji. + public ValueTask> ModifyGuildEmojiAsync + ( + Snowflake guildId, + Snowflake emojiId, + IModifyGuildEmojiPayload payload, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Deletes the given emoji. + /// + /// The snowflake identifier of the guild owning this emoji. + /// The snowflake identifier of the emoji to be deleted. + /// An optional audit log reason. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + /// Whether the deletion was successful. + public ValueTask DeleteGuildEmojiAsync + ( + Snowflake guildId, + Snowflake emojiId, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ); +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Emojis/ICreateGuildEmojiPayload.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Emojis/ICreateGuildEmojiPayload.cs new file mode 100644 index 0000000000..4a6c47362c --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Emojis/ICreateGuildEmojiPayload.cs @@ -0,0 +1,28 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +namespace DSharpPlus.Core.Abstractions.Rest.Payloads; + +/// +/// Represents a payload to POST /guilds/:guild-id/emojis. +/// +public interface ICreateGuildEmojiPayload +{ + /// + /// The name of the new emoji. + /// + public string Name { get; } + + /// + /// The 128x128 emoji image. + /// + public ImageData Image { get; } + + /// + /// The snowflake identifiers of roles allowed to use this emoji. + /// + public Optional> Roles { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Emojis/IModifyGuildEmojiPayload.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Emojis/IModifyGuildEmojiPayload.cs new file mode 100644 index 0000000000..89c242ba1a --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Emojis/IModifyGuildEmojiPayload.cs @@ -0,0 +1,23 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +namespace DSharpPlus.Core.Abstractions.Rest.Payloads; + +/// +/// Represents a payload to PATCH /guilds/:guild-id/emojis/:emoji-id. +/// +public interface IModifyGuildEmojiPayload +{ + /// + /// The new name of the emoji. + /// + public Optional Name { get; } + + /// + /// The snowflake identifiers of roles allowed to use this emoji. + /// + public Optional> Roles { get; } +} From 36a1205c063314d01254f9cfa407312085366d38 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Wed, 20 Dec 2023 21:31:13 +0100 Subject: [PATCH 211/323] results already encode success --- .../API/IChannelRestAPI.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IChannelRestAPI.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IChannelRestAPI.cs index 204cf96cc4..fd17362a3a 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IChannelRestAPI.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IChannelRestAPI.cs @@ -183,7 +183,7 @@ public ValueTask> CrosspostMessageAsync /// Additional instructions regarding this request. /// A cancellation token for this operation. /// Whether the reaction was added successfully. - public ValueTask> CreateReactionAsync + public ValueTask CreateReactionAsync ( Snowflake channelId, Snowflake messageId, @@ -201,7 +201,7 @@ public ValueTask> CreateReactionAsync /// Additional instructions regarding this request. /// A cancellation token for this operation. /// Whether the reaction was removed successfully. - public ValueTask> DeleteOwnReactionAsync + public ValueTask DeleteOwnReactionAsync ( Snowflake channelId, Snowflake messageId, @@ -220,7 +220,7 @@ public ValueTask> DeleteOwnReactionAsync /// Additional instructions regarding this request. /// A cancellation token for this operation. /// Whether the reaction was removed successfully. - public ValueTask> DeleteUserReactionAsync + public ValueTask DeleteUserReactionAsync ( Snowflake channelId, Snowflake messageId, @@ -309,7 +309,7 @@ public ValueTask> EditMessageAsync /// Additional instructions regarding this request. /// A cancellation token for this operation. /// Whether the message was successfully deleted. - public ValueTask> DeleteMessageAsync + public ValueTask DeleteMessageAsync ( Snowflake channelId, Snowflake messageId, @@ -330,7 +330,7 @@ public ValueTask> DeleteMessageAsync /// Additional instructions regarding this request. /// A cancellation token for this operation. /// Whether the messages were deleted successfully. - public ValueTask> BulkDeleteMessagesAsync + public ValueTask BulkDeleteMessagesAsync ( Snowflake channelId, IReadOnlyList messageIds, @@ -349,7 +349,7 @@ public ValueTask> BulkDeleteMessagesAsync /// Additional instructions regarding this request. /// A cancellation token for this operation. /// Whether the overwrite was successfully edited. - public ValueTask> EditChannelPermissionsAsync + public ValueTask EditChannelPermissionsAsync ( Snowflake channelId, Snowflake overwriteId, @@ -399,7 +399,7 @@ public ValueTask> CreateChannelInviteAsync /// Additional instructions regarding this request. /// A cancellation token for this operation. /// Whether the deletion was successful. - public ValueTask> DeleteChannelPermissionAsync + public ValueTask DeleteChannelPermissionAsync ( Snowflake channelId, Snowflake overwriteId, From fb0a0a38b53af8ccc8806d7e9bf5c4bdae9131ca Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sat, 23 Dec 2023 16:47:13 +0100 Subject: [PATCH 212/323] the guild api --- .../API/IEmojiRestAPI.cs | 2 +- .../API/IGuildRestAPI.cs | 771 ++++++++++++++++++ .../Payloads/Guilds/IAddGuildMemberPayload.cs | 38 + .../Guilds/ICreateGuildChannelPayload.cs | 107 +++ .../Payloads/Guilds/ICreateGuildPayload.cs | 85 ++ .../Guilds/ICreateGuildRolePayload.cs | 48 ++ .../Guilds/IModifyCurrentMemberPayload.cs | 16 + .../IModifyCurrentUserVoiceStatePayload.cs | 28 + .../IModifyGuildChannelPositionsPayload.cs | 31 + .../Guilds/IModifyGuildMemberPayload.cs | 45 + .../Guilds/IModifyGuildMfaLevelPayload.cs | 18 + .../Guilds/IModifyGuildOnboardingPayload.cs | 36 + .../Payloads/Guilds/IModifyGuildPayload.cs | 115 +++ .../Guilds/IModifyGuildRolePayload.cs | 48 ++ .../IModifyGuildRolePositionsPayload.cs | 21 + .../IModifyGuildWelcomeScreenPayload.cs | 30 + .../Guilds/IModifyUserVoiceStatePayload.cs | 21 + .../Responses/BeginGuildPruneResponse.cs | 17 + .../ListActiveGuildThreadsResponse.cs | 25 + 19 files changed, 1501 insertions(+), 1 deletion(-) create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/API/IGuildRestAPI.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Guilds/IAddGuildMemberPayload.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Guilds/ICreateGuildChannelPayload.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Guilds/ICreateGuildPayload.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Guilds/ICreateGuildRolePayload.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Guilds/IModifyCurrentMemberPayload.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Guilds/IModifyCurrentUserVoiceStatePayload.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Guilds/IModifyGuildChannelPositionsPayload.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Guilds/IModifyGuildMemberPayload.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Guilds/IModifyGuildMfaLevelPayload.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Guilds/IModifyGuildOnboardingPayload.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Guilds/IModifyGuildPayload.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Guilds/IModifyGuildRolePayload.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Guilds/IModifyGuildRolePositionsPayload.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Guilds/IModifyGuildWelcomeScreenPayload.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Guilds/IModifyUserVoiceStatePayload.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/Responses/BeginGuildPruneResponse.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/Responses/ListActiveGuildThreadsResponse.cs diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IEmojiRestAPI.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IEmojiRestAPI.cs index bc142dd03b..78a99f7ed2 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IEmojiRestAPI.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IEmojiRestAPI.cs @@ -14,7 +14,7 @@ namespace DSharpPlus.Core.Abstractions.Rest.API; /// -/// Represents a request wrapper for all request to discord's emoji rest resource. +/// Provides access to emoji-related rest API calls. /// public interface IDiscordEmojiRestResource { diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IGuildRestAPI.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IGuildRestAPI.cs new file mode 100644 index 0000000000..489c603f38 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IGuildRestAPI.cs @@ -0,0 +1,771 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; +using System.IO; +using System.Threading; +using System.Threading.Tasks; + +using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Core.Abstractions.Rest.Payloads; +using DSharpPlus.Core.Abstractions.Rest.Responses; +using DSharpPlus.Entities; + +using Remora.Results; + +namespace DSharpPlus.Core.Abstractions.Rest.API; + +/// +/// Provides access to guild-related rest API calls. +/// +public interface IGuildRestAPI +{ + /// + /// Creates a new guild with the bot user as its owner. This endpoint can only be used by bots in less than + /// 10 guilds. + /// + /// The information to create this guild with. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + /// The newly created guild. + public ValueTask> CreateGuildAsync + ( + ICreateGuildPayload payload, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Fetches a guild from its snowflake identifier. + /// + /// The snowflake identifier of the guild in question. + /// Whether or not the response should include total and online member counts. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public ValueTask> GetGuildAsync + ( + Snowflake guildId, + bool? withCounts = null, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Fetches the guild preview for the specified guild. + /// + /// The snowflake identifier of the guild in question. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public ValueTask> GetGuildPreviewAsync + ( + Snowflake guildId, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Modifies a guild. + /// + /// The snowflake identifier of the guild in question. + /// The fields of this guild to modify. + /// An optional audit log reason for the changes. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + /// The updated guild. + public ValueTask> ModifyGuildAsync + ( + Snowflake guildId, + IModifyGuildPayload payload, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Permanently deletes a guild. This user must own the guild. + /// + /// The snowflake identifier of the guild in question. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + /// Whether or not the request succeeded. + public ValueTask DeleteGuildAsync + ( + Snowflake guildId, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Requests all channels for this guild from the API. This excludes thread channels. + /// + /// The snowflake identifier of the guild in question. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public ValueTask>> GetGuildChannelsAsync + ( + Snowflake guildId, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Creates a channel in this guild. + /// + /// The snowflake identifier of the parent guild. + /// The shannel creation payload, containing all initializing data. + /// An audit log reason for this operation. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + /// The newly created channel. + public ValueTask> CreateGuildChannelAsync + ( + Snowflake guildId, + ICreateGuildChannelPayload payload, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Moves channels in a guild. + /// + /// The snowflake identifier of the parent guild. + /// Array of new channel data payloads, containing IDs and some optional data. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public ValueTask ModifyGuildChannelPositionsAsync + ( + Snowflake guildId, + IReadOnlyList payload, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Queries all active thread channels in the given guild. + /// + /// The snowflake identifier of the queried guild. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + /// + /// A response payload object containing an array of thread channels and an array of thread member information + /// for all threads the current user has joined. + /// + public ValueTask> ListActiveGuildThreadsAsync + ( + Snowflake guildId, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Returns the given users associated guild member object. + /// + /// The snowflake identifier of the queried guild. + /// The snowflake identifier of the user in question. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public ValueTask> GetGuildMemberAsync + ( + Snowflake guildId, + Snowflake userId, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Returns a list of guild member objects. + /// + /// The snowflake identifier of the guild to be queried. + /// The amount of users to query, between 1 and 1000 + /// Highest user ID to not query. Used for request pagination. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public ValueTask>> ListGuildMembersAsync + ( + Snowflake guildId, + int? limit = null, + Snowflake? after = null, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Returns a list of guild member objects whose username or nickname starts with the given string. + /// + /// The snowflake identifier of the string in question. + /// The query string to search for. + /// The maximum amount of members to return; 1 - 1000. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public ValueTask>> SearchGuildMembersAsync + ( + Snowflake guildId, + string query, + int? limit = null, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Adds a discord user to the given guild using their oauth2 access token. + /// + /// The snowflake identifier of the guild in question. + /// The snowflake identifier of the user in question. + /// A payload containing the OAuth2 token and initial information for the user. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + /// The newly created guild member, or null if the member had already joined the guild. + public ValueTask> AddGuildMemberAsync + ( + Snowflake guildId, + Snowflake userId, + IAddGuildMemberPayload payload, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Modifies a given user in the given guild. + /// + /// The snowflake identifier of the guild in question. + /// The snowflake identifier of the user in question. + /// The edits to make to this member. + /// An optional audit log reason. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + /// The modified guild member. + public ValueTask> ModifyGuildMemberAsync + ( + Snowflake guildId, + Snowflake userId, + IModifyGuildMemberPayload payload, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Modifies the current user in the given guild. Currently, only setting the nickname is supported. + /// + /// The snowflake identifier of the guild in question. + /// The payload containing the new nickname for the current user. + /// An optional audit log reason. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + /// The new current user event. + public ValueTask> ModifyCurrentMemberAsync + ( + Snowflake guildId, + IModifyCurrentMemberPayload payload, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Adds a role to a guild member in a given guild. + /// + /// The snowflake identifier of the guild in question. + /// The snowflake identifier of the user in question. + /// The snowflake identifier of the role in question. + /// An optional audit log reason. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public ValueTask AddGuildMemberRoleAsync + ( + Snowflake guildId, + Snowflake userId, + Snowflake roleId, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Removes the given role from the given member in the given guild. + /// + /// The snowflake identifier of the guild in question. + /// The snowflake identifier of the user in question. + /// The snowflake identifier of the role in question. + /// An optional audit log reason. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public ValueTask RemoveGuildMemberRoleAsync + ( + Snowflake guildId, + Snowflake userId, + Snowflake roleId, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Kicks the given user from the given guild. + /// + /// The snowflake identifier of the guild in question. + /// The snowflake identifier of the user in question. + /// An optional audit log reason. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public ValueTask RemoveGuildMemberAsync + ( + Snowflake guildId, + Snowflake userId, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Returns a list of bans from the given guild. This endpoint is paginated. + /// + /// Snowflake identifier of the guild in question. + /// The number of bans to return, up to 1000. + /// Consider only snowflakes before the given ID. + /// Consider only snowflakes after the given ID. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + /// An array of objects, representing the bans in the guild. + public ValueTask>> GetGuildBansAsync + ( + Snowflake guildId, + int? limit = null, + Snowflake? before = null, + Snowflake? after = null, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Returns the ban object for the given user. + /// + /// The snowflake identifier of the guild in question. + /// The snowflake identifier of the user in question. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public ValueTask> GetGuildBanAsync + ( + Snowflake guildId, + Snowflake userId, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Bans the given user from the given guild. + /// + /// The snowflake identifier of the guild in question. + /// The snowflake identifier of the user in question. + /// + /// Specifies how many seconds of message history from this user shall be purged, between 0 and + /// 604800, which equals 7 days. + /// + /// Specifies an audit log reason for the ban. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public ValueTask BanMemberAsync + ( + Snowflake guildId, + Snowflake userId, + int deleteMessageSeconds, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Removes a ban from the given guild for the given user. + /// + /// The snowflake identifier of the guild in question. + /// The snowflake identifier of the user in question. + /// An optional audit log reason for the ban. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public ValueTask RemoveGuildBanAsync + ( + Snowflake guildId, + Snowflake userId, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Fetches the role list of the specified guild. + /// + /// The snowflake identifier of the guild in question. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public ValueTask>> GetGuildRolesAsync + ( + Snowflake guildId, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Creates a role in a given guild. + /// + /// The snowflake identifier of the guild in question. + /// The information to initialize the role with. + /// An optional audit log reason. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + /// The newly created role. + public ValueTask> CreateGuildRoleAsync + ( + Snowflake guildId, + ICreateGuildRolePayload payload, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Modifies the positions of roles in the role list. + /// + /// The snowflake identifier of the guild in question. + /// The new positions for the roles. + /// An optional audit log reason for this action. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + /// The newly ordered list of roles for this guild. + public ValueTask>> ModifyGuildRolePositionsAsync + ( + Snowflake guildId, + IReadOnlyList payload, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Modifies the settings of a specific role. + /// + /// The snowflake identifier of the guild the role belongs to. + /// The snowflake identifier of the role in question. + /// The new role settings for this role. + /// An optional audit log reason. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + /// The modified role object. + public ValueTask> ModifyGuildRoleAsync + ( + Snowflake guildId, + Snowflake roleId, + IModifyGuildRolePayload payload, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Modifies a guild's MFA level. + /// + /// The snowflake identifier of the guild in question. + /// The new MFA level for this guild. + /// An optional audit log reason. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + /// The updated MFA level. + public ValueTask> ModifyGuildMFALevelAsync + ( + Snowflake guildId, + IModifyGuildMfaLevelPayload payload, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Deletes a role from a guild. + /// + /// The snowflake identifier of the guild the role belongs to. + /// The snowflake identifier of the role in question. + /// An optional audit log reason. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public ValueTask DeleteRoleAsync + ( + Snowflake guildId, + Snowflake roleId, + string? reason, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Queries how many users would be kicked from a given guild in a prune. + /// + /// The snowflake identifier of the guild in question. + /// Amount of inactivity days to be measured, 0 to 30. + /// Comma-separated list of role IDs to include in the prune. + /// + /// Any user with a subset of these roles will be considered for the prune. Any user with any role not listed here + /// will not be included in the count. + /// + /// + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public ValueTask> GetGuildPruneCountAsync + ( + Snowflake guildId, + int? days = null, + string? includeRoles = null, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Initiates a prune from the guild in question. + /// + /// The snowflake identifier of the guild in question. + /// The amount of inactivity days to be measured, 0 to 30. + /// Comma-separated list of role IDs to include in the prune. + /// + /// Any user with a subset of these roles will be considered for the prune. Any user with any role not listed here + /// will not be included in the count. + /// + /// + /// Whether or not the amount of users pruned should be calculated. + /// Optional audit log reason for the prune. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + /// The amount of users pruned. + public ValueTask> BeginGuildPruneAsync + ( + Snowflake guildId, + int? days = null, + string? includeRoles = null, + bool? computePruneCount = null, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Queries all available voice regions for this guild, including VIP regions. + /// + /// The snowflake identifier of the guild in question. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public ValueTask>> GetGuildVoiceRegionsAsync + ( + Snowflake guildId, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Returns a list of all active invites for this guild. + /// + /// The snowflake identifier of the guild in question. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public ValueTask>> GetGuildInvitesAsync + ( + Snowflake guildId, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Returns a list of up to 50 active integrations for this guild. If a guild has more integrations, + /// they cannot be accessed. + /// + /// The snowflake identifier of the guild in question. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public ValueTask>> GetGuildIntegrationsAsync + ( + Snowflake guildId, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Deletes an integration from the given guild. + /// + /// The snowflake identifier of the guild in question. + /// The snowflake identifier of the integration to be deleted. + /// An optional audit log reason. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public ValueTask DeleteGuildIntegrationAsync + ( + Snowflake guildId, + Snowflake integrationId, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Queries the guild widget settings for the specified guild. + /// + /// The snowflake identifier of the guild to be queried. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public ValueTask> GetGuildWidgetSettingsAsync + ( + Snowflake guildId, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Modifies the for the specified guild. + /// + /// The snowflake identifier of the guild in question. + /// The new settings for this guild widget. + /// An optional audit log reason. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + /// The new guild widget object. + public ValueTask> ModifyGuildWidgetSettingsAsync + ( + Snowflake guildId, + IGuildWidgetSettings settings, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Returns the guild widget for the specified guild. + /// + /// The snowflake identifier for the guild in question. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public ValueTask> GetGuildWidgetAsync + ( + Snowflake guildId, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Queries the vanity invite URL for this guild, if available. + /// + /// The snowflake identifier of the guild in question. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public ValueTask> GetGuildVanityUrlAsync + ( + Snowflake guildId, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Returns the guild widget image as a binary stream. + /// + /// The snowflake identifier of the guild in question. + /// The widget style, either "shield" (default) or "banner1" through "banner4". + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public ValueTask> GetGuildWidgetImageAsync + ( + Snowflake guildId, + string? style = null, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Returns the welcome screen of the given guild. + /// + /// The snowflake identifier of the guild in question. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public ValueTask> GetGuildWelcomeScreenAsync + ( + Snowflake guildId, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Modifies the welcome screen of the given guild. + /// + /// The snowflake identifier of the guild in question. + /// The information to modify the welcome screen with. + /// An optional audit log reason. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + /// The newly updated welcome screen. + public ValueTask> ModifyGuildWelcomeScreenAsync + ( + Snowflake guildId, + IModifyGuildWelcomeScreenPayload payload, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Returns the guild onboarding object for the specified guild. + /// + /// The snowflake identifier of the guild in question. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public ValueTask> GetGuildOnboardingAsync + ( + Snowflake guildId, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Modifies the onboarding configuration of the given guild. + /// + /// The snowflake identifier of the guild in question. + /// The information to modify the onboarding configuration with. + /// An optional audit log reason. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + /// The newly updated onboarding configuration. + public ValueTask> ModifyGuildOnboardingAsync + ( + Snowflake guildId, + IModifyGuildOnboardingPayload payload, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Modifies the current user's stage voice state. + /// + /// The snowflake identifier of the guild everything takes place in. + /// Information on how to update the current voice state. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public ValueTask ModifyCurrentUserVoiceStateAsync + ( + Snowflake guildId, + IModifyCurrentUserVoiceStatePayload payload, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Modifies another user's stage voice state. + /// + /// The snowflake identifier of the guild everything takes place in. + /// The snowflake identifier of the user whose voice state to modify. + /// Information on how to modify the user's voice state. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public ValueTask ModifyUserVoiceStateAsync + ( + Snowflake guildId, + Snowflake userId, + IModifyUserVoiceStatePayload payload, + RequestInfo info = default, + CancellationToken ct = default + ); +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Guilds/IAddGuildMemberPayload.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Guilds/IAddGuildMemberPayload.cs new file mode 100644 index 0000000000..6fd694c92b --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Guilds/IAddGuildMemberPayload.cs @@ -0,0 +1,38 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +namespace DSharpPlus.Core.Abstractions.Rest.Payloads; + +/// +/// Represents a payload to PUT /guilds/:guild-id/members/:user-id. +/// +public interface IAddGuildMemberPayload +{ + /// + /// An OAuth2 access token granted with the guilds.join scope. + /// + public string AccessToken { get; } + + /// + /// The nickname to initialize the user with. + /// + public Optional Nickname { get; } + + /// + /// An array of role IDs to assign immediately upon join. + /// + public Optional> Roles { get; } + + /// + /// Whether to immediately mute the user upon join. + /// + public Optional Mute { get; } + + /// + /// Whether to immediately deafen the user upon join. + /// + public Optional Deaf { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Guilds/ICreateGuildChannelPayload.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Guilds/ICreateGuildChannelPayload.cs new file mode 100644 index 0000000000..79cec71d63 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Guilds/ICreateGuildChannelPayload.cs @@ -0,0 +1,107 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Entities; + +namespace DSharpPlus.Core.Abstractions.Rest.Payloads; + +/// +/// Represents a payload to POST /guilds/:guild-id/channels. +/// +public interface ICreateGuildChannelPayload +{ + /// + /// The name of the channel to be created. + /// + public string Name { get; } + + /// + /// The channel type. + /// + public Optional Type { get; } + + /// + /// The channel topic. + /// + public Optional Topic { get; } + + /// + /// The voice channel bitrate. + /// + public Optional Bitrate { get; } + + /// + /// The voice channel user limit. + /// + public Optional UserLimit { get; } + + /// + /// The user slowmode in seconds. + /// + public Optional RateLimitPerUser { get; } + + /// + /// The sorting position in the channel list for this channel. + /// + public Optional Position { get; } + + /// + /// The permission overwrites for this channel. + /// + public Optional?> PermissionOverwrites { get; } + + /// + /// The category channel ID for this channel. + /// + public Optional ParentId { get; } + + /// + /// Indicates whether this channel is a NSFW channel. + /// + public Optional Nsfw { get; } + + /// + /// Channel voice region ID for this voice/stage channel. + /// + public Optional RtcRegion { get; } + + /// + /// Indicates the camera video quality mode of this channel. + /// + public Optional VideoQualityMode { get; } + + /// + /// The default auto archive duration clients use for newly created threads in this channel. + /// + public Optional DefaultAutoArchiveDuration { get; } + + /// + /// Default reaction for threads in this forum channel. + /// + public Optional DefaultReactionEmoji { get; } + + /// + /// The set of tags that can be used in this forum channel. + /// + public Optional?> AvailableTags { get; } + + /// + /// The default sort order for this forum channel. + /// + public Optional DefaultSortOrder { get; } + + /// + /// The default forum layout view used to display posts in this forum channel. + /// + public Optional DefaultForumLayout { get; } + + /// + /// The initial slowmode to set on newly created threads in this channel. This field is only used on creation + /// and does not live update. + /// + public Optional DefaultThreadRateLimitPerUser { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Guilds/ICreateGuildPayload.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Guilds/ICreateGuildPayload.cs new file mode 100644 index 0000000000..aec837ce32 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Guilds/ICreateGuildPayload.cs @@ -0,0 +1,85 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Entities; + +namespace DSharpPlus.Core.Abstractions.Rest.Payloads; + +/// +/// Represents a payload to POST /guilds. +/// +public interface ICreateGuildPayload +{ + /// + /// The name of the guild, from 2 to 100 characters. + /// + public string Name { get; } + + /// + /// The 128x128 icon of this guild. + /// + public Optional Icon { get; } + + /// + /// The verification level required by this guild. + /// + public Optional VerificationLevel { get; } + + /// + /// The default message notification level for this guild. + /// + public Optional DefaultMessageNotifications { get; } + + /// + /// The explicit content filter level for this guild. + /// + public Optional ExplicitContentFilter { get; } + + /// + /// The roles this guild will have. + /// + /// + /// ICreateGuildPayload.Roles[0] is used to configure the @everyone role. If you are trying + /// to bootstrap a guild with additional roles, you can set this first role to a placeholder.
+ /// The field is a placeholder to allow you to reference the role + /// elsewhere, namely when passing in default channels to and specifying + /// overwrites for them. + ///
+ public Optional> Roles { get; } + + /// + /// The channels to create this guild with. If this is set, none of the default channels will be created. + /// + /// + /// The field is ignored.
+ /// The field is a placeholder to allow creating category channels by + /// setting the field to the parents' ID. Category channels must + /// be listed before any of their children. The ID also serves for other fields to reference channels. + ///
+ public Optional> Channels { get; } + + /// + /// The identifier of the AFK voice channel, referring to a placeholder ID in . + /// + public Optional AfkChannelId { get; } + + /// + /// The AFK timeout in seconds, can be set to 60, 300, 900, 1800 or 3600. + /// + public Optional AfkTimeout { get; } + + /// + /// The identifier of the system channel where guild notices such as welcome messages are posted, referring + /// to a placeholder ID in . + /// + public Optional SystemChannelId { get; } + + /// + /// Default flags for the system channel. + /// + public Optional SystemChannelFlags { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Guilds/ICreateGuildRolePayload.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Guilds/ICreateGuildRolePayload.cs new file mode 100644 index 0000000000..e89ab80fde --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Guilds/ICreateGuildRolePayload.cs @@ -0,0 +1,48 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Entities; + +namespace DSharpPlus.Core.Abstractions.Rest.Payloads; + +/// +/// Represents a payload to POST /guilds/:guild-id/roles +/// +public interface ICreateGuildRolePayload +{ + /// + /// The name of the to-be-created role. + /// + public Optional Name { get; init; } + + /// + /// Permissions for this role. Defaults to the @everyone permissions. + /// + public Optional Permissions { get; init; } + + /// + /// RGB color value for this role. + /// + public Optional Color { get; init; } + + /// + /// Whether the role should be hoisted in the sidebar. Defaults to . + /// + public Optional Hoist { get; init; } + + /// + /// The role's icon image, if it is a custom icon. + /// + public Optional Icon { get; init; } + + /// + /// The role's unicode emoji as role icon, if applicable. + /// + public Optional UnicodeEmoji { get; init; } + + /// + /// Indicates whether the role should be mentionable by everyone. + /// + public Optional Mentionable { get; init; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Guilds/IModifyCurrentMemberPayload.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Guilds/IModifyCurrentMemberPayload.cs new file mode 100644 index 0000000000..73b8b8bc7c --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Guilds/IModifyCurrentMemberPayload.cs @@ -0,0 +1,16 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Core.Abstractions.Rest.Payloads; + +/// +/// Represents a payload to PATCH /guilds/:guild-id/members/@me. +/// +public interface IModifyCurrentMemberPayload +{ + /// + /// The nickname of the current user. + /// + public Optional Nick { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Guilds/IModifyCurrentUserVoiceStatePayload.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Guilds/IModifyCurrentUserVoiceStatePayload.cs new file mode 100644 index 0000000000..ba732cf132 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Guilds/IModifyCurrentUserVoiceStatePayload.cs @@ -0,0 +1,28 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; + +namespace DSharpPlus.Core.Abstractions.Rest.Payloads; + +/// +/// Represents a payload to PATCH /guilds/:guild-id/voice-states/@me. +/// +public interface IModifyCurrentUserVoiceStatePayload +{ + /// + /// The snowflake identifier of the channel this user is currently in. + /// + public Optional ChannelId { get; } + + /// + /// Toggles this user's suppression state. + /// + public Optional Suppress { get; } + + /// + /// Sets this user's speaking request in a stage channel. + /// + public Optional RequestToSpeakTimestamp { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Guilds/IModifyGuildChannelPositionsPayload.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Guilds/IModifyGuildChannelPositionsPayload.cs new file mode 100644 index 0000000000..3f1060652f --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Guilds/IModifyGuildChannelPositionsPayload.cs @@ -0,0 +1,31 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Core.Abstractions.Rest.Payloads; + +/// +/// Represents a payload to PATCH /guilds/:guild-id/channels. +/// +public interface IModifyGuildChannelPositionsPayload +{ + /// + /// The snowflake identifier of the channel to be moved. + /// + public Snowflake ChannelId { get; } + + /// + /// The new sorting position for this channel. + /// + public Optional Position { get; } + + /// + /// Whether this channel should sync permissions with its new parent, if moving to a new parent category. + /// + public Optional LockPermissions { get; } + + /// + /// Snowflake identifier of this channels new parent channel. + /// + public Optional ParentChannelId { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Guilds/IModifyGuildMemberPayload.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Guilds/IModifyGuildMemberPayload.cs new file mode 100644 index 0000000000..39020a01b9 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Guilds/IModifyGuildMemberPayload.cs @@ -0,0 +1,45 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; +using System.Collections.Generic; + +namespace DSharpPlus.Core.Abstractions.Rest.Payloads; + +/// +/// Represents a payload to PATCH /guilds/:guild-id/members/:user-id. +/// +public interface IModifyGuildMemberPayload +{ + /// + /// The nickname to force the user to assume. + /// + public Optional Nickname { get; } + + /// + /// An array of role IDs to assign. + /// + public Optional?> Roles { get; } + + /// + /// Whether to mute the user. + /// + public Optional Mute { get; } + + /// + /// Whether to deafen the user. + /// + public Optional Deaf { get; } + + /// + /// The voice channel ID to move the user into. + /// + public Optional ChannelId { get; } + + /// + /// The timestamp at which the user's timeout is supposed to expire. Set to null to remove the timeout. + /// Must be no more than 28 days in the future. + /// + public Optional CommunicationDisabledUntil { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Guilds/IModifyGuildMfaLevelPayload.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Guilds/IModifyGuildMfaLevelPayload.cs new file mode 100644 index 0000000000..31e91fe250 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Guilds/IModifyGuildMfaLevelPayload.cs @@ -0,0 +1,18 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Entities; + +namespace DSharpPlus.Core.Abstractions.Rest.Payloads; + +/// +/// Represents a payload to POST /guilds/:guild-id/mfa. +/// +public interface IModifyGuildMfaLevelPayload +{ + /// + /// The new MFA level for this guild. + /// + public DiscordMfaLevel Level { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Guilds/IModifyGuildOnboardingPayload.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Guilds/IModifyGuildOnboardingPayload.cs new file mode 100644 index 0000000000..48de580a0a --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Guilds/IModifyGuildOnboardingPayload.cs @@ -0,0 +1,36 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Entities; + +namespace DSharpPlus.Core.Abstractions.Rest.Payloads; + +/// +/// Represents a payload to PUT /guilds/:guild-id/onboarding. +/// +public interface IModifyGuildOnboardingPayload +{ + /// + /// Prompts shown during onboarding and in Customize Community. + /// + public IReadOnlyList Prompts { get; } + + /// + /// The snowflake identifiers of channels that members get opted into automatically. + /// + public IReadOnlyList DefaultChannelIds { get; } + + /// + /// Indicates whether onboarding is enabled in the guild. + /// + public bool Enabled { get; } + + /// + /// The current onboarding mode in this guild. + /// + public DiscordGuildOnboardingMode Mode { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Guilds/IModifyGuildPayload.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Guilds/IModifyGuildPayload.cs new file mode 100644 index 0000000000..18998e48cf --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Guilds/IModifyGuildPayload.cs @@ -0,0 +1,115 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Entities; + +namespace DSharpPlus.Core.Abstractions.Rest.Payloads; + +/// +/// Represents a payload to PATCH /guilds/:guild-id. +/// +public interface IModifyGuildPayload +{ + /// + /// The new name for this guild. + /// + public Optional Name { get; } + + /// + /// The new verification level for this guild. + /// + public Optional VerificationLevel { get; } + + /// + /// The new default message notification level for this guild. + /// + public Optional DefaultMessageNotifications { get; } + + /// + /// The new explicit content filter level for this guild. + /// + public Optional ExplicitContentFilter { get; } + + /// + /// The new snowflake identifier of the AFK channel of this guild. + /// + public Optional AfkChannelId { get; } + + /// + /// The new AFK timeout for this guild. + /// + public Optional AfkTimeout { get; } + + /// + /// The new icon for this guild. + /// + public Optional Icon { get; } + + /// + /// The snowflake identifier of this guild's new owner. Used to transfer guild ownership. + /// + public Optional OwnerId { get; } + + /// + /// The new splash for this guild. + /// + public Optional Splash { get; } + + /// + /// The new guild discovery splash for this guild. + /// + public Optional DiscoverySplash { get; } + + /// + /// The new banner for this guild. + /// + public Optional Banner { get; } + + /// + /// The snowflake identifier of the new system channel. + /// + public Optional SystemChannelId { get; } + + /// + /// The new system channel flags for this guild. + /// + public Optional SystemChannelFlags { get; } + + /// + /// The snowflake identifier of the new rules channel. + /// + public Optional RulesChannelId { get; } + + /// + /// The snowflake identifier of the new public update channel. + /// + public Optional PublicUpdatesChannelId { get; } + + /// + /// The new preferred locale for this community guild. + /// + public Optional PreferredLocale { get; } + + /// + /// The new enabled guild features for this guild. + /// + public Optional> Features { get; } + + /// + /// The new description for this guild, if it is discoverable. + /// + public Optional Description { get; } + + /// + /// Indicates whether the guild should have a boost progress bar. + /// + public Optional PremiumProgressBarEnabled { get; } + + /// + /// The snowflake identifier of the new safety alerts channel. + /// + public Optional SafetyAlertsChannelId { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Guilds/IModifyGuildRolePayload.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Guilds/IModifyGuildRolePayload.cs new file mode 100644 index 0000000000..1b6f3359e0 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Guilds/IModifyGuildRolePayload.cs @@ -0,0 +1,48 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Entities; + +namespace DSharpPlus.Core.Abstractions.Rest.Payloads; + +/// +/// Represents a payload to PATCH /guilds/:guild-id/roles/:role-id +/// +public interface IModifyGuildRolePayload +{ + /// + /// The name of the to-be-created role. + /// + public Optional Name { get; init; } + + /// + /// Permissions for this role. Defaults to the @everyone permissions. + /// + public Optional Permissions { get; init; } + + /// + /// RGB color value for this role. + /// + public Optional Color { get; init; } + + /// + /// Whether the role should be hoisted in the sidebar. Defaults to . + /// + public Optional Hoist { get; init; } + + /// + /// The role's icon image, if it is a custom icon. + /// + public Optional Icon { get; init; } + + /// + /// The role's unicode emoji as role icon, if applicable. + /// + public Optional UnicodeEmoji { get; init; } + + /// + /// Indicates whether the role should be mentionable by everyone. + /// + public Optional Mentionable { get; init; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Guilds/IModifyGuildRolePositionsPayload.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Guilds/IModifyGuildRolePositionsPayload.cs new file mode 100644 index 0000000000..0db3abd999 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Guilds/IModifyGuildRolePositionsPayload.cs @@ -0,0 +1,21 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Core.Abstractions.Rest.Payloads; + +/// +/// Represents a payload to PATCH /guilds/:guild-id/roles. +/// +public interface IModifyGuildRolePositionsPayload +{ + /// + /// The snowflake identifier of the role to move. + /// + public Snowflake Id { get; } + + /// + /// The new sorting position of the role. + /// + public Optional Position { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Guilds/IModifyGuildWelcomeScreenPayload.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Guilds/IModifyGuildWelcomeScreenPayload.cs new file mode 100644 index 0000000000..6b32d5b823 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Guilds/IModifyGuildWelcomeScreenPayload.cs @@ -0,0 +1,30 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Abstractions.Rest.Payloads; + +/// +/// Represents a payload to PATCH /guilds/:guild-id/welcome-screen. +/// +public interface IModifyGuildWelcomeScreenPayload +{ + /// + /// Indicates whether the welcome screen is enabled. + /// + public Optional Enabled { get; } + + /// + /// The channels linked in the welcome screen with their display options. + /// + public Optional?> WelcomeChannels { get; } + + /// + /// The guild description to show in the welcome screen. + /// + public Optional Description { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Guilds/IModifyUserVoiceStatePayload.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Guilds/IModifyUserVoiceStatePayload.cs new file mode 100644 index 0000000000..221574a2a4 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Guilds/IModifyUserVoiceStatePayload.cs @@ -0,0 +1,21 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Core.Abstractions.Rest.Payloads; + +/// +/// Represents a payload to PATCH /guilds/:guild-id/voice-states/:user-id. +/// +public interface IModifyUserVoiceStatePayload +{ + /// + /// The snowflake identifier of the channel this user is currently in. + /// + public Snowflake ChannelId { get; } + + /// + /// Toggles this user's suppression state. + /// + public Optional Suppress { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Responses/BeginGuildPruneResponse.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/Responses/BeginGuildPruneResponse.cs new file mode 100644 index 0000000000..6cca77aca1 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/Responses/BeginGuildPruneResponse.cs @@ -0,0 +1,17 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Core.Abstractions.Rest.Responses; + +/// +/// Represents a response from POST /guilds/:guild-id/prune +/// +public readonly record struct BeginGuildPruneResponse +{ + /// + /// The amount of pruned members, or if compute_prune_count was set to + /// . + /// + public int? Pruned { get; init; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Responses/ListActiveGuildThreadsResponse.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/Responses/ListActiveGuildThreadsResponse.cs new file mode 100644 index 0000000000..1d47ca8d1a --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/Responses/ListActiveGuildThreadsResponse.cs @@ -0,0 +1,25 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Abstractions.Rest.Responses; + +/// +/// Represents a response from GET /guilds/:guild-id/threads/active. +/// +public readonly record struct ListActiveGuildThreadsResponse +{ + /// + /// The active threads in this guild, sorted by their ID in descending order. + /// + public required IReadOnlyList Threads { get; init; } + + /// + /// The thread member objects corresponding to the thread objects. + /// + public required IReadOnlyList Members { get; init; } +} From b134e314653fb6ce1e19b9f816c0e39f616953d7 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sun, 24 Dec 2023 14:30:36 +0100 Subject: [PATCH 213/323] scheduled events as a christmas gift --- .../IScheduledEventMetadata.cs | 16 +++ .../API/IGuildScheduledEventRestAPI.cs | 119 ++++++++++++++++++ .../ICreateGuildScheduledEventPayload.cs | 61 +++++++++ .../IModifyGuildScheduledEventPayload.cs | 65 ++++++++++ .../ScheduledEvents/ScheduledEventMetadata.cs | 14 +++ 5 files changed, 275 insertions(+) create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/ScheduledEvents/IScheduledEventMetadata.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/API/IGuildScheduledEventRestAPI.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/ScheduledEvents/ICreateGuildScheduledEventPayload.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/ScheduledEvents/IModifyGuildScheduledEventPayload.cs create mode 100644 src/core/DSharpPlus.Core.Models/ScheduledEvents/ScheduledEventMetadata.cs diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/ScheduledEvents/IScheduledEventMetadata.cs b/src/core/DSharpPlus.Core.Abstractions.Models/ScheduledEvents/IScheduledEventMetadata.cs new file mode 100644 index 0000000000..90e12d8e76 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/ScheduledEvents/IScheduledEventMetadata.cs @@ -0,0 +1,16 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Represents metadata for a scheduled event. +/// +public interface IScheduledEventMetadata +{ + /// + /// The location of the event, up to 100 characters. + /// + public Optional Location { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IGuildScheduledEventRestAPI.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IGuildScheduledEventRestAPI.cs new file mode 100644 index 0000000000..f8fc957499 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IGuildScheduledEventRestAPI.cs @@ -0,0 +1,119 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; + +using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Core.Abstractions.Rest.Payloads; + +using Remora.Results; + +namespace DSharpPlus.Core.Abstractions.Rest.API; + +/// +/// Provides access to guild-scheduled-event-related rest API calls. +/// +public interface IGuildScheduledEventRestAPI +{ + /// + /// Returns a list of scheduled events taking place in this guild. + /// + /// The snowflake identifier of the guild in question. + /// Whether the answer should include user counts. + /// Cancellation token for this request. + public ValueTask>> ListScheduledEventsForGuildAsync + ( + Snowflake guildId, + bool? withUserCount = null, + CancellationToken ct = default + ); + + /// + /// Creates a new scheduled event in the specified guild. + /// + /// The snowflake identifier of the guild in question. + /// The data to intialize the event with. + /// An optional audit log reason + /// Cancellation token for this request. + /// The newly created scheduled event. + public ValueTask> CreateGuildScheduledEventAsync + ( + Snowflake guildId, + ICreateGuildScheduledEventPayload payload, + string? reason = null, + CancellationToken ct = default + ); + + /// + /// Returns the requested scheduled event. + /// + /// The snowflake identifier of the guild this scheduled event takes place in. + /// The snowflake identifier of the scheduled event in qeustion. + /// + /// Specifies whether the number of users subscribed to this event should be included. + /// + /// Cancellation token for this request. + public ValueTask> GetScheduledEventAsync + ( + Snowflake guildId, + Snowflake eventId, + bool? withUserCount = null, + CancellationToken ct = default + ); + + /// + /// Modifies the given scheduled event. + /// + /// The snowflake identifier of the guild this event takes place in. + /// The snowflake identifier of the event to be modified. + /// The new information for this event. + /// An optional audit log reason. + /// Cancellation token for this request. + /// The newly modified scheduled event. + public ValueTask> ModifyScheduledEventAsync + ( + Snowflake guildId, + Snowflake eventId, + IModifyGuildScheduledEventPayload payload, + string? reason = null, + CancellationToken ct = default + ); + + /// + /// Deletes the given scheduled event. + /// + /// The snowflake identifier of the guild this event takes place in. + /// The snowflake identifier of the event to be modified. + /// Cancellation token for this request. + /// Whether the deletion was successful. + public ValueTask DeleteScheduledEventAsync + ( + Snowflake guildId, + Snowflake eventId, + CancellationToken ct = default + ); + + /// + /// Returns objects for each participant of the given scheduled event. + /// + /// The snowflake identifier of the guild this scheduled event belongs to. + /// The snowflake identifier of the scheduled event in question. + /// Number of users to return. + /// Specifies whether the response should include guild member data. + /// Only return users before the given snowflake ID, used for pagination. + /// Only return users after the given snowflake ID, used for pagination. + /// Cancellation token for this request. + public ValueTask>> GetScheduledEventUsersAsync + ( + Snowflake guildId, + Snowflake eventId, + int? limit = null, + bool? withMember = null, + Snowflake? before = null, + Snowflake? after = null, + CancellationToken ct = default + ); +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/ScheduledEvents/ICreateGuildScheduledEventPayload.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/ScheduledEvents/ICreateGuildScheduledEventPayload.cs new file mode 100644 index 0000000000..dcb9df80fc --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/ScheduledEvents/ICreateGuildScheduledEventPayload.cs @@ -0,0 +1,61 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; + +using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Entities; + +namespace DSharpPlus.Core.Abstractions.Rest.Payloads; + +/// +/// Represents a payload to POST /guilds/:guild-id/scheduled-events. +/// +public interface ICreateGuildScheduledEventPayload +{ + /// + /// The channel ID the scheduled event will take place in. + /// + public Optional ChannelId { get; } + + /// + /// Represents metadata about the scheduled event. + /// + public Optional EntityMetadata { get; } + + /// + /// Name of the scheduled event. + /// + public string Name { get; } + + /// + /// Privacy level for this scheduled event. + /// + public DiscordScheduledEventPrivacyLevel PrivacyLevel { get;} + + /// + /// Indicates the time at which this event is scheduled to start. + /// + public DateTimeOffset ScheduledStartTime { get; } + + /// + /// Indicates the time at which this event is scheduled to end. + /// + public Optional ScheduledEndTime { get; } + + /// + /// Description for this scheduled event. + /// + public Optional Description { get; } + + /// + /// The event type of this event. + /// + public DiscordScheduledEventType EntityType { get; } + + /// + /// Image data representing the cover image of this scheduled event. + /// + public Optional Image { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/ScheduledEvents/IModifyGuildScheduledEventPayload.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/ScheduledEvents/IModifyGuildScheduledEventPayload.cs new file mode 100644 index 0000000000..e77915f3a3 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/ScheduledEvents/IModifyGuildScheduledEventPayload.cs @@ -0,0 +1,65 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Entities; +using System; + +namespace DSharpPlus.Core.Abstractions.Rest.Payloads; + +/// +/// Represents a payload to PATCH /guilds/:guild-id/scheduled-events/:event-id. +/// +public interface IModifyGuildScheduledEventPayload +{ + /// + /// The channel ID the scheduled event will take place in. + /// + public Optional ChannelId { get; } + + /// + /// Represents metadata about the scheduled event. + /// + public Optional EntityMetadata { get; } + + /// + /// Name of the scheduled event. + /// + public Optional Name { get; } + + /// + /// Privacy level for this scheduled event. + /// + public Optional PrivacyLevel { get; } + + /// + /// Indicates the time at which this event is scheduled to start. + /// + public Optional ScheduledStartTime { get; } + + /// + /// Indicates the time at which this event is scheduled to end. + /// + public Optional ScheduledEndTime { get; } + + /// + /// Description for this scheduled event. + /// + public Optional Description { get; } + + /// + /// The event type of this event. + /// + public Optional EntityType { get; } + + /// + /// The status of this scheduled event. To start or end an event, set this field to its respective state. + /// + public Optional Status { get; } + + /// + /// Image data representing the cover image of this scheduled event. + /// + public Optional Image { get; } +} diff --git a/src/core/DSharpPlus.Core.Models/ScheduledEvents/ScheduledEventMetadata.cs b/src/core/DSharpPlus.Core.Models/ScheduledEvents/ScheduledEventMetadata.cs new file mode 100644 index 0000000000..6d752044b2 --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/ScheduledEvents/ScheduledEventMetadata.cs @@ -0,0 +1,14 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record ScheduledEventMetadata : IScheduledEventMetadata +{ + /// + public Optional Location { get; init; } +} \ No newline at end of file From 4b80b1863e3b6ebb071006d4344e12c7267dc482 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sun, 24 Dec 2023 14:38:11 +0100 Subject: [PATCH 214/323] maybe add the request info parameters --- .../API/IGuildScheduledEventRestAPI.cs | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IGuildScheduledEventRestAPI.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IGuildScheduledEventRestAPI.cs index f8fc957499..efd35bc96e 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IGuildScheduledEventRestAPI.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IGuildScheduledEventRestAPI.cs @@ -23,11 +23,13 @@ public interface IGuildScheduledEventRestAPI ///
/// The snowflake identifier of the guild in question. /// Whether the answer should include user counts. - /// Cancellation token for this request. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. public ValueTask>> ListScheduledEventsForGuildAsync ( Snowflake guildId, bool? withUserCount = null, + RequestInfo info = default, CancellationToken ct = default ); @@ -37,13 +39,15 @@ public ValueTask>> ListScheduledEventsForG /// The snowflake identifier of the guild in question. /// The data to intialize the event with. /// An optional audit log reason - /// Cancellation token for this request. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. /// The newly created scheduled event. public ValueTask> CreateGuildScheduledEventAsync ( Snowflake guildId, ICreateGuildScheduledEventPayload payload, string? reason = null, + RequestInfo info = default, CancellationToken ct = default ); @@ -55,12 +59,14 @@ public ValueTask> CreateGuildScheduledEventAsync /// /// Specifies whether the number of users subscribed to this event should be included. /// - /// Cancellation token for this request. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. public ValueTask> GetScheduledEventAsync ( Snowflake guildId, Snowflake eventId, bool? withUserCount = null, + RequestInfo info = default, CancellationToken ct = default ); @@ -71,7 +77,8 @@ public ValueTask> GetScheduledEventAsync /// The snowflake identifier of the event to be modified. /// The new information for this event. /// An optional audit log reason. - /// Cancellation token for this request. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. /// The newly modified scheduled event. public ValueTask> ModifyScheduledEventAsync ( @@ -79,6 +86,7 @@ public ValueTask> ModifyScheduledEventAsync Snowflake eventId, IModifyGuildScheduledEventPayload payload, string? reason = null, + RequestInfo info = default, CancellationToken ct = default ); @@ -87,12 +95,14 @@ public ValueTask> ModifyScheduledEventAsync ///
/// The snowflake identifier of the guild this event takes place in. /// The snowflake identifier of the event to be modified. - /// Cancellation token for this request. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. /// Whether the deletion was successful. public ValueTask DeleteScheduledEventAsync ( Snowflake guildId, Snowflake eventId, + RequestInfo info = default, CancellationToken ct = default ); @@ -105,7 +115,8 @@ public ValueTask DeleteScheduledEventAsync /// Specifies whether the response should include guild member data. /// Only return users before the given snowflake ID, used for pagination. /// Only return users after the given snowflake ID, used for pagination. - /// Cancellation token for this request. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. public ValueTask>> GetScheduledEventUsersAsync ( Snowflake guildId, @@ -114,6 +125,7 @@ public ValueTask>> GetScheduledEventUs bool? withMember = null, Snowflake? before = null, Snowflake? after = null, + RequestInfo info = default, CancellationToken ct = default ); } From f58f00f1638892976d15d9e30285e3bed4bea2ad Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sun, 24 Dec 2023 14:48:31 +0100 Subject: [PATCH 215/323] guild template api too for good measure --- .../API/IGuildTemplateRestAPI.cs | 131 ++++++++++++++++++ .../ICreateGuildFromGuildTemplatePayload.cs | 21 +++ .../ICreateGuildTemplatePayload.cs | 21 +++ .../IModifyGuildTemplatePayload.cs | 21 +++ 4 files changed, 194 insertions(+) create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/API/IGuildTemplateRestAPI.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/GuildTemplates/ICreateGuildFromGuildTemplatePayload.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/GuildTemplates/ICreateGuildTemplatePayload.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/GuildTemplates/IModifyGuildTemplatePayload.cs diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IGuildTemplateRestAPI.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IGuildTemplateRestAPI.cs new file mode 100644 index 0000000000..0fc00e1b83 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IGuildTemplateRestAPI.cs @@ -0,0 +1,131 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; +using System.Threading.Tasks; +using System.Threading; + +using DSharpPlus.Core.Abstractions.Models; + +using Remora.Results; +using DSharpPlus.Core.Abstractions.Rest.Payloads; + +namespace DSharpPlus.Core.Abstractions.Rest.API; + +/// +/// Provides access to guild-template-related API calls. +/// +public interface IGuildTemplateRestAPI +{ + /// + /// Fetches the guild template object corresponding to the given template code. + /// + /// The template code in question. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public ValueTask> GetGuildTemplateAsync + ( + string templateCode, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Creates a new guild from the given guild template. + /// + /// + /// This endpoint can only be used by bots in less than 10 guilds. + /// + /// A template code to create the guild from. + /// Additional information to initialize this guild with. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + /// The newly created guild. + public ValueTask> CreateGuildFromGuildTemplateAsync + ( + string templateCode, + ICreateGuildFromGuildTemplatePayload payload, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Returns all guild templates associated with this guild. + /// + /// The snowflake identifier of the guild in question. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public ValueTask>> GetGuildTemplatesAsync + ( + Snowflake guildId, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Creates a new guild template from the given guild. + /// + /// The snowflake identifier of the guild in question. + /// The information to initialize this request with. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + /// The newly created guild template. + public ValueTask> CreateGuildTemplateAsync + ( + Snowflake guildId, + ICreateGuildTemplatePayload payload, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Syncs the given template to the given guild's current state. + /// + /// The snowflake identifier of the guild in question. + /// The code of the template in question. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + /// The newly modified guild template. + public ValueTask> SyncGuildTemplateAsync + ( + Snowflake guildId, + string templateCode, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Modifies the given guild template. + /// + /// The snowflake identifier of the guild in question. + /// Template code of the template in question. + /// The new contents of this template. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + /// The newly modified guild template. + public ValueTask> ModifyGuildTemplateAsync + ( + Snowflake guildId, + string templateCode, + IModifyGuildTemplatePayload payload, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Deletes the given guild template. + /// + /// The snowflake identifier of the guild in question. + /// The code of the template to be deleted. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + /// The deleted guild template. + public ValueTask> DeleteGuildTemplateAsync + ( + Snowflake guildId, + string templateCode, + RequestInfo info = default, + CancellationToken ct = default + ); +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/GuildTemplates/ICreateGuildFromGuildTemplatePayload.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/GuildTemplates/ICreateGuildFromGuildTemplatePayload.cs new file mode 100644 index 0000000000..1c8bfb3faa --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/GuildTemplates/ICreateGuildFromGuildTemplatePayload.cs @@ -0,0 +1,21 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Core.Abstractions.Rest.Payloads; + +/// +/// Represents a payload to POST /guilds/templates/:template-code. +/// +public interface ICreateGuildFromGuildTemplatePayload +{ + /// + /// The name of the guild, 2 to 100 characters. + /// + public string Name { get; } + + /// + /// The 128x128 icon for this guild. + /// + public Optional Icon { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/GuildTemplates/ICreateGuildTemplatePayload.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/GuildTemplates/ICreateGuildTemplatePayload.cs new file mode 100644 index 0000000000..d8233a51a2 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/GuildTemplates/ICreateGuildTemplatePayload.cs @@ -0,0 +1,21 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Core.Abstractions.Rest.Payloads; + +/// +/// Represents a payload to POST /guilds/:guild-id/templates +/// +public interface ICreateGuildTemplatePayload +{ + /// + /// The name of this template, up to 100 characters. + /// + public string Name { get; } + + /// + /// The description of this template, up to 120 characters. + /// + public Optional Description { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/GuildTemplates/IModifyGuildTemplatePayload.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/GuildTemplates/IModifyGuildTemplatePayload.cs new file mode 100644 index 0000000000..36399b2197 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/GuildTemplates/IModifyGuildTemplatePayload.cs @@ -0,0 +1,21 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Core.Abstractions.Rest.Payloads; + +/// +/// Represents a payload to POST /guilds/:guild-id/templates +/// +public interface IModifyGuildTemplatePayload +{ + /// + /// The name of this template, up to 100 characters. + /// + public Optional Name { get; } + + /// + /// The description of this template, up to 120 characters. + /// + public Optional Description { get; } +} From bc1f83dbe53ebb30213451a4252872d0fd4c7d35 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sun, 24 Dec 2023 14:54:19 +0100 Subject: [PATCH 216/323] an invite too :3 --- .../API/IGuildTemplateRestAPI.cs | 2 +- .../API/IInviteRestAPI.cs | 53 +++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/API/IInviteRestAPI.cs diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IGuildTemplateRestAPI.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IGuildTemplateRestAPI.cs index 0fc00e1b83..cfa3088059 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IGuildTemplateRestAPI.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IGuildTemplateRestAPI.cs @@ -3,8 +3,8 @@ // file, You can obtain one at https://mozilla.org/MPL/2.0/. using System.Collections.Generic; -using System.Threading.Tasks; using System.Threading; +using System.Threading.Tasks; using DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IInviteRestAPI.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IInviteRestAPI.cs new file mode 100644 index 0000000000..73bbd046a9 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IInviteRestAPI.cs @@ -0,0 +1,53 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Threading; +using System.Threading.Tasks; + +using DSharpPlus.Core.Abstractions.Models; + +using Remora.Results; + +namespace DSharpPlus.Core.Abstractions.Rest.API; + +/// +/// Provides access to invite-related API calls. +/// +public interface IInviteRestAPI +{ + /// + /// Returns the queried invite. + /// + /// Invite code identifying this invite. + /// Indicates whether the invite should contain approximate member counts. + /// Indicates whether the invite should contain the expiration time. + /// The scheduled event to include with the invite. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public ValueTask> GetInviteAsync + ( + string inviteCode, + bool? withCounts = null, + bool? withExpiration = null, + Snowflake? guildScheduledEventId = null, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Deletes the given invite. + /// + /// The code identifying the invite. + /// An optional audit log reason. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + /// The deleted invite object. + public ValueTask> DeleteInviteAsync + ( + string inviteCode, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ); +} From 454dcf593fd0b62b17a669732fa8ce8da66eaec8 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sun, 24 Dec 2023 23:20:32 +0100 Subject: [PATCH 217/323] stage instance api too, for good measure --- .../API/IStageInstanceRestAPI.cs | 81 +++++++++++++++++++ .../ICreateStageInstancePayload.cs | 38 +++++++++ .../IModifyStageInstancePayload.cs | 23 ++++++ 3 files changed, 142 insertions(+) create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/API/IStageInstanceRestAPI.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/StageInstances/ICreateStageInstancePayload.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/StageInstances/IModifyStageInstancePayload.cs diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IStageInstanceRestAPI.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IStageInstanceRestAPI.cs new file mode 100644 index 0000000000..cb1258eeae --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IStageInstanceRestAPI.cs @@ -0,0 +1,81 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Threading; +using System.Threading.Tasks; + +using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Core.Abstractions.Rest.Payloads; + +using Remora.Results; + +namespace DSharpPlus.Core.Abstractions.Rest.API; + +/// +/// Provides access to stage-instance-related API calls. +/// +public interface IStageInstanceRestAPI +{ + /// + /// Creates a new stage instance associated to a stage channel. + /// + /// The information to initialize the stage instance with. + /// An optional audit log reason. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + /// The newly created stage instance. + public ValueTask> CreateStageInstanceAsync + ( + ICreateStageInstancePayload payload, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Returns the stage instance associated with the stage channel, if one exists. + /// + /// Snowflake identifier of the associated stage channel. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public ValueTask> GetStageInstanceAsync + ( + Snowflake channelId, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Modifies the given stage instance. + /// + /// The snowflake identifier of the parent channel. + /// The updated information for this stage instance. + /// An optional audit log reason. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + /// The newly modified stage instance. + public ValueTask> ModifyStageInstanceAsync + ( + Snowflake channelId, + IModifyStageInstancePayload payload, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Deletes the given stage instance. + /// + /// The snowflake identifier of its parent channel. + /// An optional audit log reason. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public ValueTask DeleteStageInstanceAsync + ( + Snowflake channelId, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ); +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/StageInstances/ICreateStageInstancePayload.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/StageInstances/ICreateStageInstancePayload.cs new file mode 100644 index 0000000000..e379aabb08 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/StageInstances/ICreateStageInstancePayload.cs @@ -0,0 +1,38 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Entities; + +namespace DSharpPlus.Core.Abstractions.Rest.Payloads; + +/// +/// Represents a payload to POST /stage-instances. +/// +public interface ICreateStageInstancePayload +{ + /// + /// The snowflake identifier of the parent stage channel. + /// + public Snowflake ChannelId { get; } + + /// + /// The topic of the stage instance. + /// + public string Topic { get; } + + /// + /// The privacy level of the stage instance. + /// + public Optional PrivacyLevel { get; } + + /// + /// Indicates whether @everyone should be notified that a stage instance has started. + /// + public Optional SendStartNotification { get; } + + /// + /// The snowflake identifier of the scheduled event associated with this instance. + /// + public Optional GuildScheduledEventId { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/StageInstances/IModifyStageInstancePayload.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/StageInstances/IModifyStageInstancePayload.cs new file mode 100644 index 0000000000..849a2e8fba --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/StageInstances/IModifyStageInstancePayload.cs @@ -0,0 +1,23 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Entities; + +namespace DSharpPlus.Core.Abstractions.Rest.Payloads; + +/// +/// Represents a payload to PATCH /stage-instances/:channel-id. +/// +public interface IModifyStageInstancePayload +{ + /// + /// The new topic for this stage instance. + /// + public Optional Topic { get; } + + /// + /// The new privacy level of the current stage. + /// + public Optional PrivacyLevel { get; } +} From 718c511545b69690cb5ad6e4b9d2722fb0fc935f Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Mon, 25 Dec 2023 22:38:34 +0100 Subject: [PATCH 218/323] sticker api as a christmas gift to americans --- .../API/IStickerRestAPI.cs | 115 ++++++++++++++++++ .../Stickers/ICreateGuildStickerPayload.cs | 31 +++++ .../Stickers/IModifyGuildStickerPayload.cs | 26 ++++ .../Responses/ListStickerPacksResponse.cs | 20 +++ 4 files changed, 192 insertions(+) create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/API/IStickerRestAPI.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Stickers/ICreateGuildStickerPayload.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Stickers/IModifyGuildStickerPayload.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/Responses/ListStickerPacksResponse.cs diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IStickerRestAPI.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IStickerRestAPI.cs new file mode 100644 index 0000000000..a716642ba8 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IStickerRestAPI.cs @@ -0,0 +1,115 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; + +using Remora.Results; + +using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Core.Abstractions.Rest.Responses; +using DSharpPlus.Core.Abstractions.Rest.Payloads; + +namespace DSharpPlus.Core.Abstractions.Rest.API; + +/// +/// Provides access to sticker-related API calls. +/// +public interface IStickerRestAPI +{ + /// + /// Fetches a sticker by its identifier. + /// + /// The snowflake identifier of the sticker in question. + /// Cancellation token for this request. + public ValueTask> GetStickerAsync + ( + Snowflake stickerId, + CancellationToken ct = default + ); + + /// + /// Returns a list of available sticker packs. + /// + /// Cancellation token for this request. + public ValueTask> ListStickerPacksAsync + ( + CancellationToken ct = default + ); + + /// + /// Fetches the sticker objects for the given guild. + /// + /// The snowflake identifier of the guild in question. + /// Cancellation token for this request. + public ValueTask>> ListGuildStickersAsync + ( + Snowflake guildId, + CancellationToken ct = default + ); + + /// + /// Returns the specified guild sticker. + /// + /// The snowflake identifier of the guild owning this sticker. + /// The snowflake identifier of the sticker in question. + /// Cancellation token for this request. + public ValueTask> GetGuildStickerAsync + ( + Snowflake guildId, + Snowflake stickerId, + CancellationToken ct = default + ); + + /// + /// Creates a sticker in the specified guild. + /// + /// The snowflake identifier of the guild in question. + /// The information to initialize the sticker with. + /// An optional audit log reason. + /// Cancellation token for this request. + /// The newly created sticker object. + public ValueTask> CreateGuildStickerAsync + ( + Snowflake guildId, + ICreateGuildStickerPayload payload, + string? reason = null, + CancellationToken ct = default + ); + + /// + /// Modifies the given sticker. + /// + /// The snowflake identifier of the guild owning the sticker. + /// The snowflake identifier of the sticker in question. + /// The new information for this sticker. + /// An optional audit log reason. + /// Cancellation token for this request. + /// The newly updated sticker object. + public ValueTask> ModifyGuildStickerAsync + ( + Snowflake guildId, + Snowflake stickerId, + IModifyGuildStickerPayload payload, + string? reason = null, + CancellationToken ct = default + ); + + /// + /// Deletes the specified sticker. + /// + /// The snowflake identifier of the guild owning the sticker. + /// The snowflake identifier of the sticker in question. + /// An optional audit log reason. + /// Cancellation token for this request. + public ValueTask DeleteGuildStickerAsync + ( + Snowflake guildId, + Snowflake stickerId, + string? reason = null, + CancellationToken ct = default + ); +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Stickers/ICreateGuildStickerPayload.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Stickers/ICreateGuildStickerPayload.cs new file mode 100644 index 0000000000..acfed5d1dc --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Stickers/ICreateGuildStickerPayload.cs @@ -0,0 +1,31 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Core.Abstractions.Rest.Payloads; + +/// +/// Rpresents a payload to POST /guilds/:guild-id/stickers. +/// +public interface ICreateGuildStickerPayload +{ + /// + /// The name of this sticker. + /// + public string Name { get; } + + /// + /// The description for this sticker. + /// + public string Description { get; } + + /// + /// The autocomplete suggestion tags for this sticker. + /// + public string Tags { get; } + + /// + /// File contents of the sticker to upload. + /// + public AttachmentData File { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Stickers/IModifyGuildStickerPayload.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Stickers/IModifyGuildStickerPayload.cs new file mode 100644 index 0000000000..04730db50e --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Stickers/IModifyGuildStickerPayload.cs @@ -0,0 +1,26 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Core.Abstractions.Rest.Payloads; + +/// +/// Represents a payload to PATCH /guilds/:guild-id/stickers/:sticker-id. +/// +public interface IModifyGuildStickerPayload +{ + /// + /// The name of this sticker. + /// + public Optional Name { get; } + + /// + /// The description for this sticker. + /// + public Optional Description { get; } + + /// + /// The autocomplete suggestion tags for this sticker. + /// + public Optional Tags { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Responses/ListStickerPacksResponse.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/Responses/ListStickerPacksResponse.cs new file mode 100644 index 0000000000..94472616c8 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/Responses/ListStickerPacksResponse.cs @@ -0,0 +1,20 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Abstractions.Rest.Responses; + +/// +/// Represents a response from GET /sticker-packs. +/// +public readonly record struct ListStickerPacksResponse +{ + /// + /// The sticker packs returned by the call. + /// + public required IReadOnlyList StickerPacks { get; init; } +} From 425fcaf1b80d56c10475c43de5b7f55e2e7264f2 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Tue, 26 Dec 2023 18:55:10 +0100 Subject: [PATCH 219/323] enlighten stickers about RequestInfo --- .../API/IStickerRestAPI.cs | 29 ++++++++++++++----- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IStickerRestAPI.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IStickerRestAPI.cs index a716642ba8..b228b4a436 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IStickerRestAPI.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IStickerRestAPI.cs @@ -2,7 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using System; using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; @@ -24,19 +23,23 @@ public interface IStickerRestAPI /// Fetches a sticker by its identifier. ///
/// The snowflake identifier of the sticker in question. - /// Cancellation token for this request. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. public ValueTask> GetStickerAsync ( Snowflake stickerId, + RequestInfo info = default, CancellationToken ct = default ); /// /// Returns a list of available sticker packs. /// - /// Cancellation token for this request. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. public ValueTask> ListStickerPacksAsync ( + RequestInfo info = default, CancellationToken ct = default ); @@ -44,10 +47,12 @@ public ValueTask> ListStickerPacksAsync /// Fetches the sticker objects for the given guild. /// /// The snowflake identifier of the guild in question. - /// Cancellation token for this request. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. public ValueTask>> ListGuildStickersAsync ( Snowflake guildId, + RequestInfo info = default, CancellationToken ct = default ); @@ -56,11 +61,13 @@ public ValueTask>> ListGuildStickersAsync /// /// The snowflake identifier of the guild owning this sticker. /// The snowflake identifier of the sticker in question. - /// Cancellation token for this request. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. public ValueTask> GetGuildStickerAsync ( Snowflake guildId, Snowflake stickerId, + RequestInfo info = default, CancellationToken ct = default ); @@ -70,13 +77,15 @@ public ValueTask> GetGuildStickerAsync /// The snowflake identifier of the guild in question. /// The information to initialize the sticker with. /// An optional audit log reason. - /// Cancellation token for this request. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. /// The newly created sticker object. public ValueTask> CreateGuildStickerAsync ( Snowflake guildId, ICreateGuildStickerPayload payload, string? reason = null, + RequestInfo info = default, CancellationToken ct = default ); @@ -87,7 +96,8 @@ public ValueTask> CreateGuildStickerAsync /// The snowflake identifier of the sticker in question. /// The new information for this sticker. /// An optional audit log reason. - /// Cancellation token for this request. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. /// The newly updated sticker object. public ValueTask> ModifyGuildStickerAsync ( @@ -95,6 +105,7 @@ public ValueTask> ModifyGuildStickerAsync Snowflake stickerId, IModifyGuildStickerPayload payload, string? reason = null, + RequestInfo info = default, CancellationToken ct = default ); @@ -104,12 +115,14 @@ public ValueTask> ModifyGuildStickerAsync /// The snowflake identifier of the guild owning the sticker. /// The snowflake identifier of the sticker in question. /// An optional audit log reason. - /// Cancellation token for this request. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. public ValueTask DeleteGuildStickerAsync ( Snowflake guildId, Snowflake stickerId, string? reason = null, + RequestInfo info = default, CancellationToken ct = default ); } From 8f8bc3acdae4001969626e878a561a6e73bdb142 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Tue, 26 Dec 2023 20:37:17 +0100 Subject: [PATCH 220/323] user rest api --- .../API/IUserRestAPI.cs | 187 ++++++++++++++++++ .../Payloads/Users/ICreateDmPayload.cs | 16 ++ .../Payloads/Users/ICreateGroupDmPayload.cs | 23 +++ .../Users/IModifyCurrentUserPayload.cs | 23 +++ ...entUserApplicationRoleConnectionPayload.cs | 26 +++ 5 files changed, 275 insertions(+) create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/API/IUserRestAPI.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Users/ICreateDmPayload.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Users/ICreateGroupDmPayload.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Users/IModifyCurrentUserPayload.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Users/IUpdateCurrentUserApplicationRoleConnectionPayload.cs diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IUserRestAPI.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IUserRestAPI.cs new file mode 100644 index 0000000000..f59ba17199 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IUserRestAPI.cs @@ -0,0 +1,187 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; + +using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Core.Abstractions.Rest.Payloads; + +using Remora.Results; + +namespace DSharpPlus.Core.Abstractions.Rest.API; + +/// +/// Provides access to user-related API calls. +/// +public interface IUserRestAPI +{ + /// + /// Returns the current user. + /// + /// + /// For OAuth2, this requires the identify scope, which will return the object without an email, + /// and optionally the email scope, which will return the object with an email. + /// + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public ValueTask> GetCurrentUserAsync + ( + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Returns the requested user. + /// + /// The snowflake identifier of the user in question. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public ValueTask> GetUserAsync + ( + Snowflake userId, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Modifies the current user. + /// + /// The new information for the current user. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + /// The newly modified current user. + public ValueTask> ModifyCurrentUserAsync + ( + IModifyCurrentUserPayload payload, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Returns a list of partial guild objects representing the guilds the current user has joined. + /// + /// + /// defaults to 200 guilds, which is the maximum number of guilds an user account can join. + /// Pagination is therefore not needed for obtaining user guilds, but may be needed for obtaining bot guilds. + /// + /// Specifies an upper bound of snowflakes to be returned. + /// Specifies a lower bound of snowflakes to be returned. + /// Maximum number of guilds to return, ranging from 1 to 200. + /// + /// Specifies whether to include approximate member and presence counts in the returned guilds. + /// + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public ValueTask>> GetCurrentUserGuildsAsync + ( + Snowflake? before = null, + Snowflake? after = null, + int? limit = null, + bool? withCounts = null, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Returns a guild member object for the current user for the given guild. + /// + /// The snowflake identifier of the guild in question. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public ValueTask> GetCurrentUserGuildMemberAsync + ( + Snowflake guildId, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Leaves a guild as the current user. + /// + /// The snowflake identifier of the guild to be left. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + /// Whether the operation was successful. + public ValueTask LeaveGuildAsync + ( + Snowflake guildId, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Creates a new DM channel with a user. + /// + /// + /// As per Discord's documentation, you should not use this endpoint to DM everyone in a server about + /// something. DMs should generally be initiated by user action. If you open a significant amount of DMs + /// too quickly, your bot may be rate limited or blocked from opening new ones. + /// + /// The identifier of the user you want to create a DM with. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + /// The newly created channel object, or the existing DM channel if one existed. + public ValueTask> CreateDmAsync + ( + ICreateDmPayload payload, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Creates a new group DM with multiple users. This is limited to 10 active group DMs. + /// + /// The access tokens and nicks of the users to add. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + /// The newly created channel, or the existing DM channel if one existed. + public ValueTask> CreateGroupDmAsync + ( + ICreateGroupDmPayload payload, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Returns a list of connection objects for the current user. + /// + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public ValueTask>> GetCurrentUserConnectionsAsync + ( + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Returns the application role connection for the given application for the current user. + /// + /// The snowflake identifier of the application administering the connection. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public ValueTask> GetCurrentUserApplicationRoleConnectionAsync + ( + Snowflake applicationId, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Updates the application role connection for the given application for the current user. + /// + /// The snowflake identifier of the application administering the connection. + /// The new information for this role connection. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + /// The newly updated connection object. + public ValueTask> UpdateCurrentUserApplicationRoleConnectionAsync + ( + Snowflake applicationId, + IUpdateCurrentUserApplicationRoleConnectionPayload payload, + RequestInfo info = default, + CancellationToken ct = default + ); +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Users/ICreateDmPayload.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Users/ICreateDmPayload.cs new file mode 100644 index 0000000000..17bbeef971 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Users/ICreateDmPayload.cs @@ -0,0 +1,16 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Core.Abstractions.Rest.Payloads; + +/// +/// Represents a payload to POST /users/@me/channels. +/// +public interface ICreateDmPayload +{ + /// + /// The snowflake identifier of the recipient of your DM. + /// + public Snowflake RecipientId { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Users/ICreateGroupDmPayload.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Users/ICreateGroupDmPayload.cs new file mode 100644 index 0000000000..c00f67e518 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Users/ICreateGroupDmPayload.cs @@ -0,0 +1,23 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +namespace DSharpPlus.Core.Abstractions.Rest.Payloads; + +/// +/// Represents a payload to POST /users/@me/channels. +/// +public interface ICreateGroupDmPayload +{ + /// + /// The access tokens of users that have granted your app the gdm.join scope. + /// + public IReadOnlyList AccessTokens { get; } + + /// + /// The nicknames to initialize the users with. + /// + public IReadOnlyDictionary Nicks { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Users/IModifyCurrentUserPayload.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Users/IModifyCurrentUserPayload.cs new file mode 100644 index 0000000000..dec4a226d7 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Users/IModifyCurrentUserPayload.cs @@ -0,0 +1,23 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Core.Abstractions.Rest.Payloads; + +/// +/// Represents a payload to PATCH /users/@me. +/// +public interface IModifyCurrentUserPayload +{ + /// + /// The new username. If the current user is a bot user, it participates in discriminators, and + /// changing the username may cause the discriminator to be randomized if the current discriminator + /// is unavailable for the new username. + /// + public Optional Username { get; } + + /// + /// The new avatar for this user. + /// + public Optional Avatar { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Users/IUpdateCurrentUserApplicationRoleConnectionPayload.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Users/IUpdateCurrentUserApplicationRoleConnectionPayload.cs new file mode 100644 index 0000000000..65be2bffda --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Users/IUpdateCurrentUserApplicationRoleConnectionPayload.cs @@ -0,0 +1,26 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Core.Abstractions.Rest.Payloads; + +/// +/// Represents a payload to PUT /users/@me/applications/:application-id/role-connection. +/// +public interface IUpdateCurrentUserApplicationRoleConnectionPayload +{ + /// + /// The vanity name of the platform the bot is connecting. + /// + public Optional PlatformName { get; } + + /// + /// The username on the platform the bot is connecting. + /// + public Optional PlatformUsername { get; } + + /// + /// An object mapping application role connection metadata keys to their stringified value. + /// + public Optional Metadata { get; } +} From f07c71a4394b5164484823ad86422def2337072d Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Tue, 26 Dec 2023 20:39:42 +0100 Subject: [PATCH 221/323] a voice api too --- .../API/IVoiceRestAPI.cs | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/API/IVoiceRestAPI.cs diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IVoiceRestAPI.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IVoiceRestAPI.cs new file mode 100644 index 0000000000..30131875f6 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IVoiceRestAPI.cs @@ -0,0 +1,30 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; + +using DSharpPlus.Core.Abstractions.Models; + +using Remora.Results; + +namespace DSharpPlus.Core.Abstractions.Rest.API; + +/// +/// Provides access to voice-related API calls. +/// +public interface IVoiceRestAPI +{ + /// + /// Returns an array of voice region objects that can be used when setting a voice or stage channel's rtc region. + /// + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public ValueTask>> ListVoiceRegionsAsync + ( + RequestInfo info = default, + CancellationToken ct = default + ); +} From d03114128ee73682912861ccd8b3ad47dfd60030 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Tue, 26 Dec 2023 21:53:01 +0100 Subject: [PATCH 222/323] webhooks are done too --- .../API/IWebhookRestAPI.cs | 279 ++++++++++++++++++ .../Webhooks/ICreateWebhookPayload.cs | 30 ++ .../Webhooks/IEditWebhookMessagePayload.cs | 46 +++ .../Webhooks/IExecuteWebhookPayload.cs | 76 +++++ .../Webhooks/IModifyWebhookPayload.cs | 26 ++ .../IModifyWebhookWithTokenPayload.cs | 21 ++ 6 files changed, 478 insertions(+) create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/API/IWebhookRestAPI.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Webhooks/ICreateWebhookPayload.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Webhooks/IEditWebhookMessagePayload.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Webhooks/IExecuteWebhookPayload.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Webhooks/IModifyWebhookPayload.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Webhooks/IModifyWebhookWithTokenPayload.cs diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IWebhookRestAPI.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IWebhookRestAPI.cs new file mode 100644 index 0000000000..8ba854e24d --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IWebhookRestAPI.cs @@ -0,0 +1,279 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; + +using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Core.Abstractions.Rest.Payloads; + +using Remora.Results; + +namespace DSharpPlus.Core.Abstractions.Rest.API; + +/// +/// Provides access to webhook-related API calls. +/// +public interface IWebhookRestAPI +{ + /// + /// Creates a new webhook in the specified channel. + /// + /// The snowflake identifier of the channel in question. + /// Request payload. + /// An optional audit log reason. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + /// The newly created webhook object. + public ValueTask> CreateWebhookAsync + ( + Snowflake channelId, + ICreateWebhookPayload payload, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Returns a list of channel webhook objects. + /// + /// The snowflake identifier of the channel in question. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public ValueTask>> GetChannelWebhooksAsync + ( + Snowflake channelId, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Returns a list of guild webhook objects. + /// + /// The snowflake identifier of the guild in question. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public ValueTask>> GetGuildWebhooksAsync + ( + Snowflake guildId, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Returns the specified webhook object. + /// + /// The snowflake identifier of the webhook in question. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public ValueTask> GetWebhookAsync + ( + Snowflake webhookId, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Returns the specified webhook object. + /// + /// + /// This endpoint does not require authentication and is not counted to your global ratelimits. + /// + /// The snowflake identifier of the webhook in question. + /// The access token to this webhook. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public ValueTask> GetWebhookWithTokenAsync + ( + Snowflake webhookId, + string webhookToken, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Modifies the given webhook. + /// + /// The snowflake identifier of the webhook to edit. + /// The information to modify this webhook with. + /// An optional audit log reason. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + /// The updated webhook object. + public ValueTask> ModifyWebhookAsync + ( + Snowflake webhookId, + IModifyWebhookPayload payload, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Modifies the given webhook. + /// + /// + /// This endpoint does not require authentication and is not counted to your global ratelimits. + /// + /// The snowflake identifier of the webhook to edit. + /// The webhook token of the webhook to edit. + /// The information to modify this webhook with. + /// An optional audit log reason. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + /// The updated webhook object. + public ValueTask> ModifyWebhookWithTokenAsync + ( + Snowflake webhookId, + string webhookToken, + IModifyWebhookWithTokenPayload payload, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Deletes the given webhook. + /// + /// The snowflake identifier of the webhook to delete. + /// An optional audit log reason. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public ValueTask DeleteWebhookAsync + ( + Snowflake webhookId, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Deletes the given webhook. + /// + /// + /// This endpoint does not require authentication and is not counted to your global ratelimits. + /// + /// The snowflake identifier of the webhook to delete. + /// The webhook token of the webhook to delete. + /// An optional audit log reason. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public ValueTask DeleteWebhookWithTokenAsync + ( + Snowflake webhookId, + string webhookToken, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Executes the given webhook. + /// + /// The snowflake identifier of the webhook to execute. + /// The webhook token of the webhook to execute. + /// A payload of information on the message to send. + /// + /// Specifies whether to wait for server confirmation. If this is set to true, a + /// object will be returned, if not, will be returned on success instead. Defaults to + /// + /// + /// + /// Specifies a thread to send the message to rather than directly to the parent channel. If the thread is + /// archived, this will automatically unarchive it. Only threads with the same parent channel as the webhook + /// can be passed. + /// + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + /// + /// If was set to , a object.
+ /// If was set to , . + ///
+ public ValueTask> ExecuteWebhookAsync + ( + Snowflake webhookId, + string webhookToken, + IExecuteWebhookPayload payload, + bool? wait = null, + Snowflake? threadId = null, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Returns a previously-sent webhook message from the same token. + /// + /// The snowflake identifier of your webhook. + /// + /// The webhook token for your webhook. This must match the token of the original author. + /// + /// The snowflake identifier of the message in question. + /// + /// Specifies the thread to search in rather than the parent channel. Only threads with the same parent channel + /// as the webhook can be passed. + /// + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public ValueTask> GetWebhookMessageAsync + ( + Snowflake webhookId, + string webhookToken, + Snowflake messageId, + Snowflake? threadId = null, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Edits a previously-sent webhook message from the same token. + /// + /// The snowflake identifier of your webhook. + /// + /// The webhook token for your webhook. This must match the token of the original author. + /// + /// The snowflake identifier of the message in question. + /// The information to update this message with. + /// + /// Specifies the thread to search in rather than the parent channel. Only threads with the same parent channel + /// as the webhook can be passed. + /// + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + /// The newly edited message. + public ValueTask> EditWebhookMessageAsync + ( + Snowflake webhookId, + string webhookToken, + Snowflake messageId, + IEditWebhookMessagePayload payload, + Snowflake? threadId = null, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Deletes a previously-sent webhook message from the same token. + /// + /// The snowflake identifier of your webhook. + /// + /// The webhook token for your webhook. This must match the token of the original author. + /// + /// The snowflake identifier of the message in question. + /// + /// Specifies the thread to search in rather than the parent channel. Only threads with the same parent channel + /// as the webhook can be passed. + /// + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public ValueTask DeleteWebhookMessageAsync + ( + Snowflake webhookId, + string webhookToken, + Snowflake messageId, + Snowflake? threadId = null, + RequestInfo info = default, + CancellationToken ct = default + ); +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Webhooks/ICreateWebhookPayload.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Webhooks/ICreateWebhookPayload.cs new file mode 100644 index 0000000000..89ebf5d676 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Webhooks/ICreateWebhookPayload.cs @@ -0,0 +1,30 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Core.Abstractions.Rest.Payloads; + +/// +/// Represents a payload to POST /channels/:channel-id/webhooks. +/// +public interface ICreateWebhookPayload +{ + /// + /// The name of the webhook. + /// + /// + /// This follows several requirements:

+ /// + /// A webhook name can contain up to 80 characters, unlike usernames/nicknames which are limited to 32. + /// A webhook name is subject to all other requirements usernames and nicknames are subject to. + /// Webhook names cannot contain the substrings clyde and discord, case-insensitively. + /// + /// If the name does not fit all three requirements, it will be rejected and an error will be returned. + ///
+ public string Name { get; } + + /// + /// The default webhook avatar. This may be overridden by messages. + /// + public Optional Avatar { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Webhooks/IEditWebhookMessagePayload.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Webhooks/IEditWebhookMessagePayload.cs new file mode 100644 index 0000000000..080e36965a --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Webhooks/IEditWebhookMessagePayload.cs @@ -0,0 +1,46 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Abstractions.Rest.Payloads; + +/// +/// Represents a payload to PATCH /webhooks/:webhook-id/:webhook-token/messages/:message-id. +/// +public interface IEditWebhookMessagePayload +{ + /// + /// The new message contents. + /// + public Optional Content { get; } + + /// + /// Up to 10 embeds attached to the message. + /// + public Optional?> Embeds { get; } + + /// + /// The new allowed mentions object for this message. + /// + public Optional AllowedMentions { get; } + + /// + /// The new components attached to this message. + /// + public Optional?> Components { get; } + + /// + /// The new files to be sent along with the edit. Note that all used files in this message must be passed here, + /// even if they were originally present. + /// + public IReadOnlyList? Files { get; } + + /// + /// Attachment descriptor objects for this message. + /// + public Optional?> Attachments { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Webhooks/IExecuteWebhookPayload.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Webhooks/IExecuteWebhookPayload.cs new file mode 100644 index 0000000000..306d051d95 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Webhooks/IExecuteWebhookPayload.cs @@ -0,0 +1,76 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Entities; + +namespace DSharpPlus.Core.Abstractions.Rest.Payloads; + +/// +/// Represents a payload to POST /webhooks/:webhook-id/:webhook-token. +/// +public interface IExecuteWebhookPayload +{ + /// + /// Message contents. + /// + public Optional Content { get; } + + /// + /// Overrides the default username of the webhook. + /// + public Optional Username { get; } + + /// + /// Overrides the default avatar of the webhook. + /// + public Optional AvatarUrl { get; } + + /// + /// True if this is a TTS message. + /// + public Optional Tts { get; } + + /// + /// Up to 10 embeds + /// + public Optional> Embeds { get; } + + /// + /// Allowed mentions object for this message. + /// + public Optional AllowedMentions { get; } + + /// + /// Components to include with this message. + /// + public Optional> Components { get; } + + /// + /// Attachment files to include with this message. + /// + public IReadOnlyList? Files { get; } + + /// + /// Attachment descriptor objects with filename and description. + /// + public Optional> Attachments { get; } + + /// + /// Message flags for this message. Only can be set. + /// + public Optional Flags { get; } + + /// + /// The name of the thread to create, if the webhook channel is a forum channel. + /// + public Optional ThreadName { get; } + + /// + /// The snowflake identifiers of tags to apply to the thread, if applicable. + /// + public Optional> AppliedTags { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Webhooks/IModifyWebhookPayload.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Webhooks/IModifyWebhookPayload.cs new file mode 100644 index 0000000000..5fd1d657be --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Webhooks/IModifyWebhookPayload.cs @@ -0,0 +1,26 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Core.Abstractions.Rest.Payloads; + +/// +/// Represents a payload to PATCH /webhooks/:webhook-id. +/// +public interface IModifyWebhookPayload +{ + /// + /// The new default name of this webhook. + /// + public Optional Name { get; } + + /// + /// The new default webhook avatar image. + /// + public Optional Avatar { get; } + + /// + /// The snowflake identifier of the channel this webhook should be moved to. + /// + public Optional ChannelId { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Webhooks/IModifyWebhookWithTokenPayload.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Webhooks/IModifyWebhookWithTokenPayload.cs new file mode 100644 index 0000000000..d7963b45cc --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Webhooks/IModifyWebhookWithTokenPayload.cs @@ -0,0 +1,21 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Core.Abstractions.Rest.Payloads; + +/// +/// Represents a payload to PATCH /webhooks/:webhook-id/:webhook-token. +/// +public interface IModifyWebhookWithTokenPayload +{ + /// + /// The new default name of this webhook. + /// + public Optional Name { get; } + + /// + /// The new default webhook avatar image. + /// + public Optional Avatar { get; } +} From 7b56015f2b202c4b0a858a2c05c6eaed6efd1eb6 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Tue, 26 Dec 2023 21:58:17 +0100 Subject: [PATCH 223/323] monetization, part I D: --- .../Skus/ISku.cs | 4 +-- .../API/ISkusRestAPI.cs | 36 +++++++++++++++++++ src/core/DSharpPlus.Core.Models/Skus/Sku.cs | 4 +-- .../Skus/{SkuFlags.cs => DiscordSkuFlags.cs} | 2 +- .../Skus/{SkuType.cs => DiscordSkuType.cs} | 2 +- 5 files changed, 42 insertions(+), 6 deletions(-) create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/API/ISkusRestAPI.cs rename src/core/DSharpPlus.Shared/Entities/Skus/{SkuFlags.cs => DiscordSkuFlags.cs} (96%) rename src/core/DSharpPlus.Shared/Entities/Skus/{SkuType.cs => DiscordSkuType.cs} (95%) diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Skus/ISku.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Skus/ISku.cs index 5a67176ac6..6e9b0536f1 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Skus/ISku.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Skus/ISku.cs @@ -19,7 +19,7 @@ public interface ISku /// /// The type of this SKU. /// - public SkuType Type { get; } + public DiscordSkuType Type { get; } /// /// The snowflake identifier of the parent application. @@ -39,5 +39,5 @@ public interface ISku /// /// Additional flags for this SKU. /// - public SkuFlags Flags { get; } + public DiscordSkuFlags Flags { get; } } diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/API/ISkusRestAPI.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/API/ISkusRestAPI.cs new file mode 100644 index 0000000000..c0b40bf7d2 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/API/ISkusRestAPI.cs @@ -0,0 +1,36 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; + +using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Entities; + +using Remora.Results; + +namespace DSharpPlus.Core.Abstractions.Rest.API; + +/// +/// Provides access to SKUs-related API calls. +/// +public interface ISkusRestAPI +{ + /// + /// Returns all SKUs for a given applications. You will see two SKUs for your premium offering, "because of + /// how our SKU and subscription systems work" - Discord.
+ /// For integration and testing entitlements you should use the SKU with type + /// . + ///
+ /// The snowflake identifier of the parent application. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public ValueTask>> ListSkusAsync + ( + Snowflake applicationId, + RequestInfo info = default, + CancellationToken ct = default + ); +} diff --git a/src/core/DSharpPlus.Core.Models/Skus/Sku.cs b/src/core/DSharpPlus.Core.Models/Skus/Sku.cs index 0759cc55e4..d4b8130e59 100644 --- a/src/core/DSharpPlus.Core.Models/Skus/Sku.cs +++ b/src/core/DSharpPlus.Core.Models/Skus/Sku.cs @@ -14,7 +14,7 @@ public sealed record Sku : ISku public required Snowflake Id { get; init; } /// - public required SkuType Type { get; init; } + public required DiscordSkuType Type { get; init; } /// public required Snowflake ApplicationId { get; init; } @@ -26,5 +26,5 @@ public sealed record Sku : ISku public required string Slug { get; init; } /// - public required SkuFlags Flags { get; init; } + public required DiscordSkuFlags Flags { get; init; } } \ No newline at end of file diff --git a/src/core/DSharpPlus.Shared/Entities/Skus/SkuFlags.cs b/src/core/DSharpPlus.Shared/Entities/Skus/DiscordSkuFlags.cs similarity index 96% rename from src/core/DSharpPlus.Shared/Entities/Skus/SkuFlags.cs rename to src/core/DSharpPlus.Shared/Entities/Skus/DiscordSkuFlags.cs index 7043298f96..f59cede176 100644 --- a/src/core/DSharpPlus.Shared/Entities/Skus/SkuFlags.cs +++ b/src/core/DSharpPlus.Shared/Entities/Skus/DiscordSkuFlags.cs @@ -10,7 +10,7 @@ namespace DSharpPlus.Entities; /// Represents additional flags for a given SKU. ///
[Flags] -public enum SkuFlags +public enum DiscordSkuFlags { /// /// This SKU is available for purchase. diff --git a/src/core/DSharpPlus.Shared/Entities/Skus/SkuType.cs b/src/core/DSharpPlus.Shared/Entities/Skus/DiscordSkuType.cs similarity index 95% rename from src/core/DSharpPlus.Shared/Entities/Skus/SkuType.cs rename to src/core/DSharpPlus.Shared/Entities/Skus/DiscordSkuType.cs index 2c42d73afb..0ea1c1d6da 100644 --- a/src/core/DSharpPlus.Shared/Entities/Skus/SkuType.cs +++ b/src/core/DSharpPlus.Shared/Entities/Skus/DiscordSkuType.cs @@ -7,7 +7,7 @@ namespace DSharpPlus.Entities; /// /// Represents the type of a given SKU. /// -public enum SkuType +public enum DiscordSkuType { /// /// Represents a recurring subscription. From 4dc5fb9710d1a2233209ec612e3eee30abeaa427 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Tue, 26 Dec 2023 22:04:34 +0100 Subject: [PATCH 224/323] list entitlements --- .../API/IEntitlementsRestAPI.cs | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/API/IEntitlementsRestAPI.cs diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IEntitlementsRestAPI.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IEntitlementsRestAPI.cs new file mode 100644 index 0000000000..50b2ccdb78 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IEntitlementsRestAPI.cs @@ -0,0 +1,46 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; + +using DSharpPlus.Core.Abstractions.Models; + +using Remora.Results; + +namespace DSharpPlus.Core.Abstractions.Rest.API; + +/// +/// Provides access to entitlements-related API calls. +/// +public interface IEntitlementsRestAPI +{ + /// + /// Returns all entitlements for a given app, according to the query parameters. + /// + /// The snowflake identifier of the current application. + /// The snowflake identifier of the user to look up entitlements for. + /// A comma-delimited set of snowflakes of SKUs to check entitlements for. + /// Specifies an entitlement to retrieve entitlements before of, for pagination. + /// Specifies an entitlement to retrieve entitlements after of, for pagination. + /// The maximum amount of entitlements to return, up to 100. + /// The snowflake identifier of the guild to look up entitlements for. + /// Specifies whether or not to include ended entitlements. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public ValueTask>> ListEntitlementsAsync + ( + Snowflake applicationId, + Snowflake? userId = null, + string? skuIds = null, + Snowflake? before = null, + Snowflake? after = null, + int? limit = null, + Snowflake? guildId = null, + bool? excludeEnded = null, + RequestInfo info = default, + CancellationToken ct = default + ); +} From 24a0093f62b07aa12e681dcbbb697863f85d8511 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Tue, 26 Dec 2023 22:14:59 +0100 Subject: [PATCH 225/323] create test entitlements --- .../Entitlements/IEntitlement.cs | 67 ++++++------------- .../Entitlements/IPartialEntitlement.cs | 59 ++++++++++++++++ .../API/IEntitlementsRestAPI.cs | 20 ++++++ .../ICreateTestEntitlementPayload.cs | 28 ++++++++ .../Entitlements/Entitlement.cs | 2 +- .../Entitlements/PartialEntitlement.cs | 41 ++++++++++++ .../DiscordEntitlementOwnerType.cs | 14 ++++ ...ementType.cs => DiscordEntitlementType.cs} | 2 +- .../Entitlements/IEntitlement.cs | 41 ++++++++++++ 9 files changed, 227 insertions(+), 47 deletions(-) create mode 100644 src/core/DSharpPlus.Core.Abstractions.Models/Entitlements/IPartialEntitlement.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Entitlements/ICreateTestEntitlementPayload.cs create mode 100644 src/core/DSharpPlus.Core.Models/Entitlements/PartialEntitlement.cs create mode 100644 src/core/DSharpPlus.Shared/Entities/Entitlements/DiscordEntitlementOwnerType.cs rename src/core/DSharpPlus.Shared/Entities/Entitlements/{EntitlementType.cs => DiscordEntitlementType.cs} (91%) create mode 100644 src/core/SharpPlus.Core.Abstractions.Models/Entitlements/IEntitlement.cs diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Entitlements/IEntitlement.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Entitlements/IEntitlement.cs index 62d02165e0..568b96fa19 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Entitlements/IEntitlement.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Entitlements/IEntitlement.cs @@ -11,50 +11,27 @@ namespace DSharpPlus.Core.Abstractions.Models; /// /// Represents an entitlement to a premium offering in an application. /// -public interface IEntitlement +public interface IEntitlement : IPartialEntitlement { - /// - /// The snowflake identifier of this entitlement. - /// - public Snowflake Id { get; } - - /// - /// The snowflake identifier of the SKU. - /// - public Snowflake SkuId { get; } - - /// - /// The snowflake identifier of the user that is granted access to the entitlement's SKU. - /// - public Optional UserId { get; } - - /// - /// The snowflake identifier of the guild that is granted access to the entitlement's SKU. - /// - public Optional GuildId { get; } - - /// - /// The snowflake identifier of the parent application. - /// - public Snowflake ApplicationId { get; } - - /// - /// The type of this entitlement. - /// - public EntitlementType Type { get; } - - /// - /// Indicates whether this entitlement was deleted. - /// - public bool Deleted { get; } - - /// - /// The starting date at which this entitlement is valid. Not present when using test entitlements. - /// - public Optional StartsAt { get; } - - /// - /// The date at which this entitlement is no longer valid. Not present when using test entitlements. - /// - public Optional EndsAt { get; } + /// + public new Snowflake SkuId { get; } + + /// + public new Snowflake ApplicationId { get; } + + /// + public new DiscordEntitlementType Type { get; } + + /// + public new bool Deleted { get; } + + // partial access + + Optional IPartialEntitlement.SkuId => this.SkuId; + + Optional IPartialEntitlement.ApplicationId => this.ApplicationId; + + Optional IPartialEntitlement.Type => this.Type; + + Optional IPartialEntitlement.Deleted => this.Deleted; } diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Entitlements/IPartialEntitlement.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Entitlements/IPartialEntitlement.cs new file mode 100644 index 0000000000..e6967184b3 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Entitlements/IPartialEntitlement.cs @@ -0,0 +1,59 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Entities; +using System; + +namespace DSharpPlus.Core.Abstractions.Models; + +/// +/// Represents a partial entitlement object. +/// +public interface IPartialEntitlement +{ + /// + /// The snowflake identifier of this entitlement. + /// + public Snowflake Id { get; } + + /// + /// The snowflake identifier of the SKU. + /// + public Optional SkuId { get; } + + /// + /// The snowflake identifier of the user that is granted access to the entitlement's SKU. + /// + public Optional UserId { get; } + + /// + /// The snowflake identifier of the guild that is granted access to the entitlement's SKU. + /// + public Optional GuildId { get; } + + /// + /// The snowflake identifier of the parent application. + /// + public Optional ApplicationId { get; } + + /// + /// The type of this entitlement. + /// + public Optional Type { get; } + + /// + /// Indicates whether this entitlement was deleted. + /// + public Optional Deleted { get; } + + /// + /// The starting date at which this entitlement is valid. Not present when using test entitlements. + /// + public Optional StartsAt { get; } + + /// + /// The date at which this entitlement is no longer valid. Not present when using test entitlements. + /// + public Optional EndsAt { get; } +} diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IEntitlementsRestAPI.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IEntitlementsRestAPI.cs index 50b2ccdb78..edcbf53814 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IEntitlementsRestAPI.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IEntitlementsRestAPI.cs @@ -7,6 +7,7 @@ using System.Threading.Tasks; using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Core.Abstractions.Rest.Payloads; using Remora.Results; @@ -43,4 +44,23 @@ public ValueTask>> ListEntitlementsAsync RequestInfo info = default, CancellationToken ct = default ); + + /// + /// Creates a test entitlement to a given SKU for a given guild or user. Discord will act as though that user + /// or guild has entitlement to your offering.
+ /// After creating a test entitlement, you will need to reload your Discord client. After that, you will + /// have premium access. + ///
+ /// The snowflake identifier of your application. + /// The target of your test entitlement. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + /// The newly created test entitlement. + public ValueTask> CreateTestEntitlementAsync + ( + Snowflake applicationId, + ICreateTestEntitlementPayload payload, + RequestInfo info = default, + CancellationToken ct = default + ); } diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Entitlements/ICreateTestEntitlementPayload.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Entitlements/ICreateTestEntitlementPayload.cs new file mode 100644 index 0000000000..d0c640e7bd --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Entitlements/ICreateTestEntitlementPayload.cs @@ -0,0 +1,28 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Entities; + +namespace DSharpPlus.Core.Abstractions.Rest.Payloads; + +/// +/// Represents a payload to POST /applications/:application-id/entitlements. +/// +public interface ICreateTestEntitlementPayload +{ + /// + /// The identifier of the string to grant the entitlement to. + /// + public Snowflake SkuId { get; } + + /// + /// The identifier of the guild or user to grant the entitlement to. + /// + public Snowflake OwnerId { get; } + + /// + /// Specifies what kind of entity the owner is. + /// + public DiscordEntitlementOwnerType OwnerType { get; } +} diff --git a/src/core/DSharpPlus.Core.Models/Entitlements/Entitlement.cs b/src/core/DSharpPlus.Core.Models/Entitlements/Entitlement.cs index 1e0d33f591..49387253d8 100644 --- a/src/core/DSharpPlus.Core.Models/Entitlements/Entitlement.cs +++ b/src/core/DSharpPlus.Core.Models/Entitlements/Entitlement.cs @@ -28,7 +28,7 @@ public sealed record Entitlement : IEntitlement public required Snowflake ApplicationId { get; init; } /// - public required EntitlementType Type { get; init; } + public required DiscordEntitlementType Type { get; init; } /// public required bool Deleted { get; init; } diff --git a/src/core/DSharpPlus.Core.Models/Entitlements/PartialEntitlement.cs b/src/core/DSharpPlus.Core.Models/Entitlements/PartialEntitlement.cs new file mode 100644 index 0000000000..767041756f --- /dev/null +++ b/src/core/DSharpPlus.Core.Models/Entitlements/PartialEntitlement.cs @@ -0,0 +1,41 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; + +using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Entities; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record PartialEntitlement : IPartialEntitlement +{ + /// + public required Snowflake Id { get; init; } + + /// + public Optional SkuId { get; init; } + + /// + public Optional UserId { get; init; } + + /// + public Optional GuildId { get; init; } + + /// + public Optional ApplicationId { get; init; } + + /// + public Optional Type { get; init; } + + /// + public Optional Deleted { get; init; } + + /// + public Optional StartsAt { get; init; } + + /// + public Optional EndsAt { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Shared/Entities/Entitlements/DiscordEntitlementOwnerType.cs b/src/core/DSharpPlus.Shared/Entities/Entitlements/DiscordEntitlementOwnerType.cs new file mode 100644 index 0000000000..0e0b8a536c --- /dev/null +++ b/src/core/DSharpPlus.Shared/Entities/Entitlements/DiscordEntitlementOwnerType.cs @@ -0,0 +1,14 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Entities; + +/// +/// Enumerates the owners of an entitlement. +/// +public enum DiscordEntitlementOwnerType +{ + Guild = 1, + User +} diff --git a/src/core/DSharpPlus.Shared/Entities/Entitlements/EntitlementType.cs b/src/core/DSharpPlus.Shared/Entities/Entitlements/DiscordEntitlementType.cs similarity index 91% rename from src/core/DSharpPlus.Shared/Entities/Entitlements/EntitlementType.cs rename to src/core/DSharpPlus.Shared/Entities/Entitlements/DiscordEntitlementType.cs index f03cf41f40..8768f46ebb 100644 --- a/src/core/DSharpPlus.Shared/Entities/Entitlements/EntitlementType.cs +++ b/src/core/DSharpPlus.Shared/Entities/Entitlements/DiscordEntitlementType.cs @@ -4,7 +4,7 @@ namespace DSharpPlus.Entities; -public enum EntitlementType +public enum DiscordEntitlementType { /// /// This entitlement was purchased as an app subscription. diff --git a/src/core/SharpPlus.Core.Abstractions.Models/Entitlements/IEntitlement.cs b/src/core/SharpPlus.Core.Abstractions.Models/Entitlements/IEntitlement.cs new file mode 100644 index 0000000000..49387253d8 --- /dev/null +++ b/src/core/SharpPlus.Core.Abstractions.Models/Entitlements/IEntitlement.cs @@ -0,0 +1,41 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; + +using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Entities; + +namespace DSharpPlus.Core.Models; + +/// +public sealed record Entitlement : IEntitlement +{ + /// + public required Snowflake Id { get; init; } + + /// + public required Snowflake SkuId { get; init; } + + /// + public Optional UserId { get; init; } + + /// + public Optional GuildId { get; init; } + + /// + public required Snowflake ApplicationId { get; init; } + + /// + public required DiscordEntitlementType Type { get; init; } + + /// + public required bool Deleted { get; init; } + + /// + public Optional StartsAt { get; init; } + + /// + public Optional EndsAt { get; init; } +} \ No newline at end of file From 88af0c0f1c2d7636c4e3f3ba95d09d4dc86627e8 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Tue, 26 Dec 2023 22:16:43 +0100 Subject: [PATCH 226/323] delete test entitlements --- .../API/IEntitlementsRestAPI.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IEntitlementsRestAPI.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IEntitlementsRestAPI.cs index edcbf53814..0d2b36a74b 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IEntitlementsRestAPI.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IEntitlementsRestAPI.cs @@ -63,4 +63,20 @@ public ValueTask> CreateTestEntitlementAsync RequestInfo info = default, CancellationToken ct = default ); + + /// + /// Deletes a currently active test entitlement. Discord will act as though that user or guild no longer + /// has entitlement to your offering. + /// + /// The snowflake identifier of your application. + /// The snowflake identifier of the test entitlement to delete. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public ValueTask DeleteTestEntitlementAsync + ( + Snowflake applicationId, + Snowflake entitlementId, + RequestInfo info = default, + CancellationToken ct = default + ); } From 0e8de776d58b86344cfb7f74917bb1ac5ace842d Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Wed, 27 Dec 2023 15:52:09 +0100 Subject: [PATCH 227/323] fix a bug in the object generator :) because of fucking backslashes, it generated src/core/SharpPlus.Core.Abstractions.Models/... entities for every partial parent when ran on windows --- dsharpplus.csx | 15 +- .../Entitlements/IEntitlement.cs | 2 - .../IApplicationCommandPermissions.cs | 25 ---- .../Applications/IApplication.cs | 92 ------------ .../AutoModeration/IAutoModerationRule.cs | 47 ------ .../Channels/IAttachment.cs | 53 ------- .../Channels/IChannel.cs | 120 --------------- .../Channels/IChannelOverwrite.cs | 24 --- .../Channels/IMessage.cs | 105 ------------- .../Emojis/IEmoji.cs | 37 ----- .../Entitlements/IEntitlement.cs | 41 ----- .../Guilds/IGuild.cs | 140 ------------------ .../Guilds/IGuildMember.cs | 51 ------- .../Guilds/IIntegration.cs | 63 -------- .../Guilds/IRole.cs | 48 ------ .../Invites/IInvite.cs | 62 -------- .../ScheduledEvents/IScheduledEvent.cs | 53 ------- .../StageInstances/IStageInstance.cs | 30 ---- .../Stickers/ISticker.cs | 45 ------ .../Users/IUser.cs | 63 -------- .../Webhooks/IWebhook.cs | 48 ------ .../generators/generate-concrete-objects.csx | 3 +- 22 files changed, 14 insertions(+), 1153 deletions(-) delete mode 100644 src/core/SharpPlus.Core.Abstractions.Models/ApplicationCommands/IApplicationCommandPermissions.cs delete mode 100644 src/core/SharpPlus.Core.Abstractions.Models/Applications/IApplication.cs delete mode 100644 src/core/SharpPlus.Core.Abstractions.Models/AutoModeration/IAutoModerationRule.cs delete mode 100644 src/core/SharpPlus.Core.Abstractions.Models/Channels/IAttachment.cs delete mode 100644 src/core/SharpPlus.Core.Abstractions.Models/Channels/IChannel.cs delete mode 100644 src/core/SharpPlus.Core.Abstractions.Models/Channels/IChannelOverwrite.cs delete mode 100644 src/core/SharpPlus.Core.Abstractions.Models/Channels/IMessage.cs delete mode 100644 src/core/SharpPlus.Core.Abstractions.Models/Emojis/IEmoji.cs delete mode 100644 src/core/SharpPlus.Core.Abstractions.Models/Entitlements/IEntitlement.cs delete mode 100644 src/core/SharpPlus.Core.Abstractions.Models/Guilds/IGuild.cs delete mode 100644 src/core/SharpPlus.Core.Abstractions.Models/Guilds/IGuildMember.cs delete mode 100644 src/core/SharpPlus.Core.Abstractions.Models/Guilds/IIntegration.cs delete mode 100644 src/core/SharpPlus.Core.Abstractions.Models/Guilds/IRole.cs delete mode 100644 src/core/SharpPlus.Core.Abstractions.Models/Invites/IInvite.cs delete mode 100644 src/core/SharpPlus.Core.Abstractions.Models/ScheduledEvents/IScheduledEvent.cs delete mode 100644 src/core/SharpPlus.Core.Abstractions.Models/StageInstances/IStageInstance.cs delete mode 100644 src/core/SharpPlus.Core.Abstractions.Models/Stickers/ISticker.cs delete mode 100644 src/core/SharpPlus.Core.Abstractions.Models/Users/IUser.cs delete mode 100644 src/core/SharpPlus.Core.Abstractions.Models/Webhooks/IWebhook.cs diff --git a/dsharpplus.csx b/dsharpplus.csx index ae8338771a..17f6cb53af 100644 --- a/dsharpplus.csx +++ b/dsharpplus.csx @@ -7,6 +7,7 @@ using System; using System.Diagnostics; using System.Linq; +using System.IO; using Spectre.Console; @@ -121,6 +122,14 @@ if (Args.Count == 1 && Args is ["--help" or "-h" or "-?"]) return 0; } +if (Args.Count >= 1 && Args[0] == "clear") +{ + Directory.Delete("./artifacts/hashes", true); + + AnsiConsole.MarkupLine("Cleared persisting cached data."); + return 0; +} + if (Args.Count >= 1 && Args[0] == "publish") { if (Args[1] == "-s" || Args[1] == "--subset") @@ -158,7 +167,7 @@ switch (Args[1]) { case "tools": - if (Args[2] == "-s" || Args[2] == "--subset") + if (Args.Count >= 4 && (Args[2] == "-s" || Args[2] == "--subset")) { ExecuteSubset(Args[3].Split(','), ToolType.None); } @@ -170,7 +179,7 @@ switch (Args[1]) case "generators": - if (Args[2] == "-s" || Args[2] == "--subset") + if (Args.Count >= 4 && (Args[2] == "-s" || Args[2] == "--subset")) { ExecuteSubset(Args[3].Split(','), ToolType.Generator); } @@ -182,7 +191,7 @@ switch (Args[1]) case "analyzers": - if (Args[2] == "-s" || Args[2] == "--subset") + if (Args.Count >= 4 && (Args[2] == "-s" || Args[2] == "--subset")) { ExecuteSubset(Args[3].Split(','), ToolType.Analyzer); } diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Entitlements/IEntitlement.cs b/src/core/DSharpPlus.Core.Abstractions.Models/Entitlements/IEntitlement.cs index 568b96fa19..d77af2762a 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Entitlements/IEntitlement.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Models/Entitlements/IEntitlement.cs @@ -2,8 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using System; - using DSharpPlus.Entities; namespace DSharpPlus.Core.Abstractions.Models; diff --git a/src/core/SharpPlus.Core.Abstractions.Models/ApplicationCommands/IApplicationCommandPermissions.cs b/src/core/SharpPlus.Core.Abstractions.Models/ApplicationCommands/IApplicationCommandPermissions.cs deleted file mode 100644 index e129549546..0000000000 --- a/src/core/SharpPlus.Core.Abstractions.Models/ApplicationCommands/IApplicationCommandPermissions.cs +++ /dev/null @@ -1,25 +0,0 @@ -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -using System.Collections.Generic; - -using DSharpPlus.Core.Abstractions.Models; - -namespace DSharpPlus.Core.Models; - -/// -public sealed record ApplicationCommandPermissions : IApplicationCommandPermissions -{ - /// - public required Snowflake Id { get; init; } - - /// - public required Snowflake ApplicationId { get; init; } - - /// - public required Snowflake GuildId { get; init; } - - /// - public required IReadOnlyList Permissions { get; init; } -} \ No newline at end of file diff --git a/src/core/SharpPlus.Core.Abstractions.Models/Applications/IApplication.cs b/src/core/SharpPlus.Core.Abstractions.Models/Applications/IApplication.cs deleted file mode 100644 index a0186723bd..0000000000 --- a/src/core/SharpPlus.Core.Abstractions.Models/Applications/IApplication.cs +++ /dev/null @@ -1,92 +0,0 @@ -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -using System.Collections.Generic; - -using DSharpPlus.Core.Abstractions.Models; -using DSharpPlus.Entities; - -namespace DSharpPlus.Core.Models; - -/// -public sealed record Application : IApplication -{ - /// - public required Snowflake Id { get; init; } - - /// - public required string Name { get; init; } - - /// - public required string? Icon { get; init; } - - /// - public Optional Description { get; init; } - - /// - public Optional> RpcOrigins { get; init; } - - /// - public required bool BotPublic { get; init; } - - /// - public required bool BotRequireCodeGrant { get; init; } - - /// - public Optional Bot { get; init; } - - /// - public Optional TermsOfServiceUrl { get; init; } - - /// - public Optional PrivacyPolicyUrl { get; init; } - - /// - public Optional Owner { get; init; } - - /// - public required string VerifyKey { get; init; } - - /// - public required ITeam? Team { get; init; } - - /// - public Optional GuildId { get; init; } - - /// - public Optional Guild { get; init; } - - /// - public Optional PrimarySkuId { get; init; } - - /// - public Optional Slug { get; init; } - - /// - public Optional CoverImage { get; init; } - - /// - public Optional Flags { get; init; } - - /// - public Optional ApproximateGuildCount { get; init; } - - /// - public Optional> RedirectUris { get; init; } - - /// - public Optional InteractionsEndpointUrl { get; init; } - - /// - public Optional RoleConnectionsVerificationUrl { get; init; } - - /// - public Optional> Tags { get; init; } - - /// - public Optional InstallParams { get; init; } - - /// - public Optional CustomInstallUrl { get; init; } -} \ No newline at end of file diff --git a/src/core/SharpPlus.Core.Abstractions.Models/AutoModeration/IAutoModerationRule.cs b/src/core/SharpPlus.Core.Abstractions.Models/AutoModeration/IAutoModerationRule.cs deleted file mode 100644 index 80413df074..0000000000 --- a/src/core/SharpPlus.Core.Abstractions.Models/AutoModeration/IAutoModerationRule.cs +++ /dev/null @@ -1,47 +0,0 @@ -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -using System.Collections.Generic; - -using DSharpPlus.Core.Abstractions.Models; -using DSharpPlus.Entities; - -namespace DSharpPlus.Core.Models; - -/// -public sealed record AutoModerationRule : IAutoModerationRule -{ - /// - public required Snowflake Id { get; init; } - - /// - public required Snowflake GuildId { get; init; } - - /// - public required string Name { get; init; } - - /// - public required Snowflake CreatorId { get; init; } - - /// - public required DiscordAutoModerationEventType EventType { get; init; } - - /// - public required DiscordAutoModerationTriggerType TriggerType { get; init; } - - /// - public required IAutoModerationTriggerMetadata TriggerMetadata { get; init; } - - /// - public required IReadOnlyList Actions { get; init; } - - /// - public required bool Enabled { get; init; } - - /// - public required IReadOnlyList ExemptRoles { get; init; } - - /// - public required IReadOnlyList ExemptChannels { get; init; } -} \ No newline at end of file diff --git a/src/core/SharpPlus.Core.Abstractions.Models/Channels/IAttachment.cs b/src/core/SharpPlus.Core.Abstractions.Models/Channels/IAttachment.cs deleted file mode 100644 index f1c96bfa59..0000000000 --- a/src/core/SharpPlus.Core.Abstractions.Models/Channels/IAttachment.cs +++ /dev/null @@ -1,53 +0,0 @@ -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -using System; - -using DSharpPlus.Core.Abstractions.Models; -using DSharpPlus.Entities; - -namespace DSharpPlus.Core.Models; - -/// -public sealed record Attachment : IAttachment -{ - /// - public required Snowflake Id { get; init; } - - /// - public required string Filename { get; init; } - - /// - public Optional Description { get; init; } - - /// - public Optional ContentType { get; init; } - - /// - public required int Size { get; init; } - - /// - public required string Url { get; init; } - - /// - public required string ProxyUrl { get; init; } - - /// - public Optional Height { get; init; } - - /// - public Optional Width { get; init; } - - /// - public Optional Ephemeral { get; init; } - - /// - public Optional DurationSecs { get; init; } - - /// - public Optional> Waveform { get; init; } - - /// - public Optional Flags { get; init; } -} \ No newline at end of file diff --git a/src/core/SharpPlus.Core.Abstractions.Models/Channels/IChannel.cs b/src/core/SharpPlus.Core.Abstractions.Models/Channels/IChannel.cs deleted file mode 100644 index d4997fe315..0000000000 --- a/src/core/SharpPlus.Core.Abstractions.Models/Channels/IChannel.cs +++ /dev/null @@ -1,120 +0,0 @@ -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -using System; -using System.Collections.Generic; - -using DSharpPlus.Core.Abstractions.Models; -using DSharpPlus.Entities; - -namespace DSharpPlus.Core.Models; - -/// -public sealed record Channel : IChannel -{ - /// - public required Snowflake Id { get; init; } - - /// - public required DiscordChannelType Type { get; init; } - - /// - public Optional GuildId { get; init; } - - /// - public Optional Position { get; init; } - - /// - public Optional> PermissionOverwrites { get; init; } - - /// - public Optional Name { get; init; } - - /// - public Optional Topic { get; init; } - - /// - public Optional Nsfw { get; init; } - - /// - public Optional LastMessageId { get; init; } - - /// - public Optional Bitrate { get; init; } - - /// - public Optional UserLimit { get; init; } - - /// - public Optional RateLimitPerUser { get; init; } - - /// - public Optional> Recipients { get; init; } - - /// - public Optional Icon { get; init; } - - /// - public Optional OwnerId { get; init; } - - /// - public Optional ApplicationId { get; init; } - - /// - public Optional Managed { get; init; } - - /// - public Optional ParentId { get; init; } - - /// - public Optional LastPinTimestamp { get; init; } - - /// - public Optional RtcRegion { get; init; } - - /// - public Optional VideoQualityMode { get; init; } - - /// - public Optional MessageCount { get; init; } - - /// - public Optional MemberCount { get; init; } - - /// - public Optional ThreadMetadata { get; init; } - - /// - public Optional Member { get; init; } - - /// - public Optional DefaultAutoArchiveDuration { get; init; } - - /// - public Optional Permissions { get; init; } - - /// - public Optional Flags { get; init; } - - /// - public Optional TotalMessageSent { get; init; } - - /// - public Optional> AvailableTags { get; init; } - - /// - public Optional> AppliedTags { get; init; } - - /// - public Optional DefaultReactionEmoji { get; init; } - - /// - public Optional DefaultThreadRateLimitPerUser { get; init; } - - /// - public Optional DefaultSortOrder { get; init; } - - /// - public Optional DefaultForumLayout { get; init; } -} \ No newline at end of file diff --git a/src/core/SharpPlus.Core.Abstractions.Models/Channels/IChannelOverwrite.cs b/src/core/SharpPlus.Core.Abstractions.Models/Channels/IChannelOverwrite.cs deleted file mode 100644 index 8332974eba..0000000000 --- a/src/core/SharpPlus.Core.Abstractions.Models/Channels/IChannelOverwrite.cs +++ /dev/null @@ -1,24 +0,0 @@ -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -using DSharpPlus.Core.Abstractions.Models; -using DSharpPlus.Entities; - -namespace DSharpPlus.Core.Models; - -/// -public sealed record ChannelOverwrite : IChannelOverwrite -{ - /// - public required Snowflake Id { get; init; } - - /// - public required DiscordChannelOverwriteType Type { get; init; } - - /// - public required DiscordPermissions Allow { get; init; } - - /// - public required DiscordPermissions Deny { get; init; } -} \ No newline at end of file diff --git a/src/core/SharpPlus.Core.Abstractions.Models/Channels/IMessage.cs b/src/core/SharpPlus.Core.Abstractions.Models/Channels/IMessage.cs deleted file mode 100644 index 59b91e0600..0000000000 --- a/src/core/SharpPlus.Core.Abstractions.Models/Channels/IMessage.cs +++ /dev/null @@ -1,105 +0,0 @@ -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -using System; -using System.Collections.Generic; - -using DSharpPlus.Core.Abstractions.Models; -using DSharpPlus.Entities; - -namespace DSharpPlus.Core.Models; - -/// -public sealed record Message : IMessage -{ - /// - public required Snowflake Id { get; init; } - - /// - public required Snowflake ChannelId { get; init; } - - /// - public required IUser Author { get; init; } - - /// - public required string Content { get; init; } - - /// - public required DateTimeOffset Timestamp { get; init; } - - /// - public required DateTimeOffset? EditedTimestamp { get; init; } - - /// - public required bool Tts { get; init; } - - /// - public required bool MentionEveryone { get; init; } - - /// - public required IReadOnlyList Mentions { get; init; } - - /// - public required IReadOnlyList MentionRoles { get; init; } - - /// - public Optional> MentionChannels { get; init; } - - /// - public required IReadOnlyList Attachments { get; init; } - - /// - public required IReadOnlyList Embeds { get; init; } - - /// - public Optional> Reactions { get; init; } - - /// - public Optional Nonce { get; init; } - - /// - public required bool Pinned { get; init; } - - /// - public Optional WebhookId { get; init; } - - /// - public required DiscordMessageType Type { get; init; } - - /// - public Optional Activity { get; init; } - - /// - public Optional Application { get; init; } - - /// - public Optional ApplicationId { get; init; } - - /// - public Optional MessageReference { get; init; } - - /// - public Optional Flags { get; init; } - - /// - public Optional ReferencedMessage { get; init; } - - /// - public Optional Interaction { get; init; } - - /// - public Optional Thread { get; init; } - - /// - public Optional> Components { get; init; } - - /// - public Optional StickerItems { get; init; } - - /// - public Optional Position { get; init; } - - /// - public Optional RoleSubscriptionData { get; init; } -} \ No newline at end of file diff --git a/src/core/SharpPlus.Core.Abstractions.Models/Emojis/IEmoji.cs b/src/core/SharpPlus.Core.Abstractions.Models/Emojis/IEmoji.cs deleted file mode 100644 index ce9e997df1..0000000000 --- a/src/core/SharpPlus.Core.Abstractions.Models/Emojis/IEmoji.cs +++ /dev/null @@ -1,37 +0,0 @@ -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -using System.Collections.Generic; - -using DSharpPlus.Core.Abstractions.Models; - -namespace DSharpPlus.Core.Models; - -/// -public sealed record Emoji : IEmoji -{ - /// - public required Snowflake? Id { get; init; } - - /// - public required string? Name { get; init; } - - /// - public Optional> Roles { get; init; } - - /// - public Optional User { get; init; } - - /// - public Optional RequireColons { get; init; } - - /// - public Optional Managed { get; init; } - - /// - public Optional Animated { get; init; } - - /// - public Optional Available { get; init; } -} \ No newline at end of file diff --git a/src/core/SharpPlus.Core.Abstractions.Models/Entitlements/IEntitlement.cs b/src/core/SharpPlus.Core.Abstractions.Models/Entitlements/IEntitlement.cs deleted file mode 100644 index 49387253d8..0000000000 --- a/src/core/SharpPlus.Core.Abstractions.Models/Entitlements/IEntitlement.cs +++ /dev/null @@ -1,41 +0,0 @@ -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -using System; - -using DSharpPlus.Core.Abstractions.Models; -using DSharpPlus.Entities; - -namespace DSharpPlus.Core.Models; - -/// -public sealed record Entitlement : IEntitlement -{ - /// - public required Snowflake Id { get; init; } - - /// - public required Snowflake SkuId { get; init; } - - /// - public Optional UserId { get; init; } - - /// - public Optional GuildId { get; init; } - - /// - public required Snowflake ApplicationId { get; init; } - - /// - public required DiscordEntitlementType Type { get; init; } - - /// - public required bool Deleted { get; init; } - - /// - public Optional StartsAt { get; init; } - - /// - public Optional EndsAt { get; init; } -} \ No newline at end of file diff --git a/src/core/SharpPlus.Core.Abstractions.Models/Guilds/IGuild.cs b/src/core/SharpPlus.Core.Abstractions.Models/Guilds/IGuild.cs deleted file mode 100644 index 4e011ca0dc..0000000000 --- a/src/core/SharpPlus.Core.Abstractions.Models/Guilds/IGuild.cs +++ /dev/null @@ -1,140 +0,0 @@ -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -using System.Collections.Generic; - -using DSharpPlus.Core.Abstractions.Models; -using DSharpPlus.Entities; - -namespace DSharpPlus.Core.Models; - -/// -public sealed record Guild : IGuild -{ - /// - public required Snowflake Id { get; init; } - - /// - public required string Name { get; init; } - - /// - public required string? Icon { get; init; } - - /// - public Optional IconHash { get; init; } - - /// - public required string? Splash { get; init; } - - /// - public required string? DiscoverySplash { get; init; } - - /// - public Optional Owner { get; init; } - - /// - public required Snowflake OwnerId { get; init; } - - /// - public Optional Permissions { get; init; } - - /// - public required Snowflake? AfkChannelId { get; init; } - - /// - public required int AfkTimeout { get; init; } - - /// - public Optional WidgetEnabled { get; init; } - - /// - public Optional WidgetChannelId { get; init; } - - /// - public required DiscordVerificationLevel VerificationLevel { get; init; } - - /// - public required DiscordMessageNotificationLevel DefaultMessageNotifications { get; init; } - - /// - public required DiscordExplicitContentFilterLevel ExplicitContentFilter { get; init; } - - /// - public required IReadOnlyList Roles { get; init; } - - /// - public required IReadOnlyList Emojis { get; init; } - - /// - public required IReadOnlyList Features { get; init; } - - /// - public required DiscordMfaLevel MfaLevel { get; init; } - - /// - public required Snowflake? ApplicationId { get; init; } - - /// - public required Snowflake? SystemChannelId { get; init; } - - /// - public required DiscordSystemChannelFlags SystemChannelFlags { get; init; } - - /// - public required Snowflake? RulesChannelId { get; init; } - - /// - public Optional MaxPresences { get; init; } - - /// - public Optional MaxMembers { get; init; } - - /// - public required string? VanityUrlCode { get; init; } - - /// - public required string? Description { get; init; } - - /// - public required string? Banner { get; init; } - - /// - public required int PremiumTier { get; init; } - - /// - public Optional PremiumSubscriptionCount { get; init; } - - /// - public required string PreferredLocale { get; init; } - - /// - public required Snowflake? PublicUpdatesChannelId { get; init; } - - /// - public Optional MaxVideoChannelUsers { get; init; } - - /// - public Optional MaxStageVideoChannelUsers { get; init; } - - /// - public Optional ApproximateMemberCount { get; init; } - - /// - public Optional ApproximatePresenceCount { get; init; } - - /// - public Optional WelcomeScreen { get; init; } - - /// - public required DiscordNsfwLevel NsfwLevel { get; init; } - - /// - public Optional> Stickers { get; init; } - - /// - public required bool PremiumProgressBarEnabled { get; init; } - - /// - public required Snowflake? SafetyAlertsChannelId { get; init; } -} \ No newline at end of file diff --git a/src/core/SharpPlus.Core.Abstractions.Models/Guilds/IGuildMember.cs b/src/core/SharpPlus.Core.Abstractions.Models/Guilds/IGuildMember.cs deleted file mode 100644 index 6c433a9784..0000000000 --- a/src/core/SharpPlus.Core.Abstractions.Models/Guilds/IGuildMember.cs +++ /dev/null @@ -1,51 +0,0 @@ -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -using System; -using System.Collections.Generic; - -using DSharpPlus.Core.Abstractions.Models; -using DSharpPlus.Entities; - -namespace DSharpPlus.Core.Models; - -/// -public sealed record GuildMember : IGuildMember -{ - /// - public Optional User { get; init; } - - /// - public Optional Nick { get; init; } - - /// - public Optional Avatar { get; init; } - - /// - public required IReadOnlyList Roles { get; init; } - - /// - public required DateTimeOffset JoinedAt { get; init; } - - /// - public Optional PremiumSince { get; init; } - - /// - public required bool Deaf { get; init; } - - /// - public required bool Mute { get; init; } - - /// - public required DiscordGuildMemberFlags Flags { get; init; } - - /// - public Optional Pending { get; init; } - - /// - public Optional Permissions { get; init; } - - /// - public Optional CommunicationDisabledUntil { get; init; } -} \ No newline at end of file diff --git a/src/core/SharpPlus.Core.Abstractions.Models/Guilds/IIntegration.cs b/src/core/SharpPlus.Core.Abstractions.Models/Guilds/IIntegration.cs deleted file mode 100644 index 2f6c3b24d5..0000000000 --- a/src/core/SharpPlus.Core.Abstractions.Models/Guilds/IIntegration.cs +++ /dev/null @@ -1,63 +0,0 @@ -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -using System; -using System.Collections.Generic; - -using DSharpPlus.Core.Abstractions.Models; -using DSharpPlus.Entities; - -namespace DSharpPlus.Core.Models; - -/// -public sealed record Integration : IIntegration -{ - /// - public required Snowflake Id { get; init; } - - /// - public required string Name { get; init; } - - /// - public required string Type { get; init; } - - /// - public required bool Enabled { get; init; } - - /// - public Optional Syncing { get; init; } - - /// - public Optional RoleId { get; init; } - - /// - public Optional EnableEmoticons { get; init; } - - /// - public Optional ExpireBehaviour { get; init; } - - /// - public Optional ExpireGracePeriod { get; init; } - - /// - public Optional User { get; init; } - - /// - public required IIntegrationAccount Account { get; init; } - - /// - public Optional SyncedAt { get; init; } - - /// - public Optional SubscriberCount { get; init; } - - /// - public Optional Revoked { get; init; } - - /// - public Optional Application { get; init; } - - /// - public Optional> Scopes { get; init; } -} \ No newline at end of file diff --git a/src/core/SharpPlus.Core.Abstractions.Models/Guilds/IRole.cs b/src/core/SharpPlus.Core.Abstractions.Models/Guilds/IRole.cs deleted file mode 100644 index 3820f5599a..0000000000 --- a/src/core/SharpPlus.Core.Abstractions.Models/Guilds/IRole.cs +++ /dev/null @@ -1,48 +0,0 @@ -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -using DSharpPlus.Core.Abstractions.Models; -using DSharpPlus.Entities; - -namespace DSharpPlus.Core.Models; - -/// -public sealed record Role : IRole -{ - /// - public required Snowflake Id { get; init; } - - /// - public required string Name { get; init; } - - /// - public required int Color { get; init; } - - /// - public required bool Hoist { get; init; } - - /// - public Optional Hash { get; init; } - - /// - public Optional UnicodeEmoji { get; init; } - - /// - public required int Position { get; init; } - - /// - public required DiscordPermissions Permissions { get; init; } - - /// - public required bool Managed { get; init; } - - /// - public required bool Mentionable { get; init; } - - /// - public Optional Tags { get; init; } - - /// - public required DiscordRoleFlags Flags { get; init; } -} \ No newline at end of file diff --git a/src/core/SharpPlus.Core.Abstractions.Models/Invites/IInvite.cs b/src/core/SharpPlus.Core.Abstractions.Models/Invites/IInvite.cs deleted file mode 100644 index d52fce132f..0000000000 --- a/src/core/SharpPlus.Core.Abstractions.Models/Invites/IInvite.cs +++ /dev/null @@ -1,62 +0,0 @@ -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -using System; - -using DSharpPlus.Core.Abstractions.Models; -using DSharpPlus.Entities; - -namespace DSharpPlus.Core.Models; - -/// -public sealed record Invite : IInvite -{ - /// - public required string Code { get; init; } - - /// - public Optional Guild { get; init; } - - /// - public required IPartialChannel? Channel { get; init; } - - /// - public Optional Inviter { get; init; } - - /// - public Optional TargetType { get; init; } - - /// - public Optional TargetUser { get; init; } - - /// - public Optional TargetApplication { get; init; } - - /// - public Optional ApproximatePresenceCount { get; init; } - - /// - public Optional ApproximateMemberCount { get; init; } - - /// - public Optional ExpiresAt { get; init; } - - /// - public Optional GuildScheduledEvent { get; init; } - - /// - public Optional Uses { get; init; } - - /// - public Optional MaxUses { get; init; } - - /// - public Optional MaxAge { get; init; } - - /// - public Optional Temporary { get; init; } - - /// - public Optional CreatedAt { get; init; } -} \ No newline at end of file diff --git a/src/core/SharpPlus.Core.Abstractions.Models/ScheduledEvents/IScheduledEvent.cs b/src/core/SharpPlus.Core.Abstractions.Models/ScheduledEvents/IScheduledEvent.cs deleted file mode 100644 index 17d478ea07..0000000000 --- a/src/core/SharpPlus.Core.Abstractions.Models/ScheduledEvents/IScheduledEvent.cs +++ /dev/null @@ -1,53 +0,0 @@ -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -using System; - -using DSharpPlus.Core.Abstractions.Models; -using DSharpPlus.Entities; - -namespace DSharpPlus.Core.Models; - -/// -public sealed record ScheduledEvent : IScheduledEvent -{ - /// - public required Snowflake Id { get; init; } - - /// - public required Snowflake GuildId { get; init; } - - /// - public required Snowflake ChannelId { get; init; } - - /// - public Optional CreatorId { get; init; } - - /// - public required string Name { get; init; } - - /// - public Optional Description { get; init; } - - /// - public required DateTimeOffset ScheduledStartTime { get; init; } - - /// - public required DiscordScheduledEventPrivacyLevel PrivacyLevel { get; init; } - - /// - public required DiscordScheduledEventStatus Status { get; init; } - - /// - public required DiscordScheduledEventType EntityType { get; init; } - - /// - public Optional Creator { get; init; } - - /// - public Optional UserCount { get; init; } - - /// - public Optional Image { get; init; } -} \ No newline at end of file diff --git a/src/core/SharpPlus.Core.Abstractions.Models/StageInstances/IStageInstance.cs b/src/core/SharpPlus.Core.Abstractions.Models/StageInstances/IStageInstance.cs deleted file mode 100644 index 986c53260b..0000000000 --- a/src/core/SharpPlus.Core.Abstractions.Models/StageInstances/IStageInstance.cs +++ /dev/null @@ -1,30 +0,0 @@ -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -using DSharpPlus.Core.Abstractions.Models; -using DSharpPlus.Entities; - -namespace DSharpPlus.Core.Models; - -/// -public sealed record StageInstance : IStageInstance -{ - /// - public required Snowflake Id { get; init; } - - /// - public required Snowflake GuildId { get; init; } - - /// - public required Snowflake ChannelId { get; init; } - - /// - public required string Topic { get; init; } - - /// - public required DiscordStagePrivacyLevel PrivacyLevel { get; init; } - - /// - public required Snowflake? GuildScheduledEventId { get; init; } -} \ No newline at end of file diff --git a/src/core/SharpPlus.Core.Abstractions.Models/Stickers/ISticker.cs b/src/core/SharpPlus.Core.Abstractions.Models/Stickers/ISticker.cs deleted file mode 100644 index e5841f421d..0000000000 --- a/src/core/SharpPlus.Core.Abstractions.Models/Stickers/ISticker.cs +++ /dev/null @@ -1,45 +0,0 @@ -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -using DSharpPlus.Core.Abstractions.Models; -using DSharpPlus.Entities; - -namespace DSharpPlus.Core.Models; - -/// -public sealed record Sticker : ISticker -{ - /// - public required Snowflake Id { get; init; } - - /// - public Optional PackId { get; init; } - - /// - public required string Name { get; init; } - - /// - public required string? Description { get; init; } - - /// - public required string Tags { get; init; } - - /// - public required DiscordStickerType Type { get; init; } - - /// - public required DiscordStickerFormatType FormatType { get; init; } - - /// - public Optional Available { get; init; } - - /// - public Optional GuildId { get; init; } - - /// - public Optional User { get; init; } - - /// - public Optional SortValue { get; init; } -} \ No newline at end of file diff --git a/src/core/SharpPlus.Core.Abstractions.Models/Users/IUser.cs b/src/core/SharpPlus.Core.Abstractions.Models/Users/IUser.cs deleted file mode 100644 index a49a7f04b6..0000000000 --- a/src/core/SharpPlus.Core.Abstractions.Models/Users/IUser.cs +++ /dev/null @@ -1,63 +0,0 @@ -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -using DSharpPlus.Core.Abstractions.Models; -using DSharpPlus.Entities; - -namespace DSharpPlus.Core.Models; - -/// -public sealed record User : IUser -{ - /// - public required Snowflake Id { get; init; } - - /// - public required string Username { get; init; } - - /// - public required string Discriminator { get; init; } - - /// - public required string? GlobalName { get; init; } - - /// - public required string? Avatar { get; init; } - - /// - public Optional Bot { get; init; } - - /// - public Optional System { get; init; } - - /// - public Optional MfaEnabled { get; init; } - - /// - public Optional Banner { get; init; } - - /// - public Optional AccentColor { get; init; } - - /// - public Optional Locale { get; init; } - - /// - public Optional Verified { get; init; } - - /// - public Optional Email { get; init; } - - /// - public Optional Flags { get; init; } - - /// - public Optional PremiumType { get; init; } - - /// - public Optional PublicFlags { get; init; } - - /// - public Optional AvatarDecoration { get; init; } -} \ No newline at end of file diff --git a/src/core/SharpPlus.Core.Abstractions.Models/Webhooks/IWebhook.cs b/src/core/SharpPlus.Core.Abstractions.Models/Webhooks/IWebhook.cs deleted file mode 100644 index ad069b9052..0000000000 --- a/src/core/SharpPlus.Core.Abstractions.Models/Webhooks/IWebhook.cs +++ /dev/null @@ -1,48 +0,0 @@ -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -using DSharpPlus.Core.Abstractions.Models; -using DSharpPlus.Entities; - -namespace DSharpPlus.Core.Models; - -/// -public sealed record Webhook : IWebhook -{ - /// - public required Snowflake Id { get; init; } - - /// - public required DiscordWebhookType Type { get; init; } - - /// - public Optional GuildId { get; init; } - - /// - public required Snowflake? ChannelId { get; init; } - - /// - public Optional User { get; init; } - - /// - public required string? Name { get; init; } - - /// - public required string? Avatar { get; init; } - - /// - public Optional Token { get; init; } - - /// - public required Snowflake? ApplicationId { get; init; } - - /// - public Optional SourceGuild { get; init; } - - /// - public Optional SourceChannel { get; init; } - - /// - public Optional Url { get; init; } -} \ No newline at end of file diff --git a/tools/generators/generate-concrete-objects.csx b/tools/generators/generate-concrete-objects.csx index 5292916428..106a3b3b8a 100644 --- a/tools/generators/generate-concrete-objects.csx +++ b/tools/generators/generate-concrete-objects.csx @@ -172,13 +172,14 @@ for (int i = 0; i < collectedMetadata.Count; i++) if (candidateFiles.Any()) { - collectedMetadata.Add(ParseInterface(candidateFiles.First(), input)!); + collectedMetadata.Add(ParseInterface(candidateFiles.First().Replace('\\', '/'), input)!); } } } int index = metadata.Path.LastIndexOf('/'); string outputPath = metadata.Path.Remove(index + 1, 1).Replace(input, output); + FileInfo info = new(outputPath); if (!Directory.Exists(info.DirectoryName!)) From c8da2a45da0baef62e35c841099a6edea9bf4415 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Wed, 27 Dec 2023 16:16:25 +0100 Subject: [PATCH 228/323] fix a bug where optional nullables wouldn't get detected as nullable when working with partial entities --- .../Applications/Application.cs | 4 ++-- .../Channels/Message.cs | 2 +- .../DSharpPlus.Core.Models/Emojis/Emoji.cs | 4 ++-- .../DSharpPlus.Core.Models/Guilds/Guild.cs | 24 +++++++++---------- .../DSharpPlus.Core.Models/Invites/Invite.cs | 2 +- .../StageInstances/StageInstance.cs | 2 +- .../Stickers/Sticker.cs | 2 +- src/core/DSharpPlus.Core.Models/Users/User.cs | 4 ++-- .../Webhooks/Webhook.cs | 8 +++---- .../generators/generate-concrete-objects.csx | 2 +- tools/generators/parse-interface.csx | 2 +- 11 files changed, 28 insertions(+), 28 deletions(-) diff --git a/src/core/DSharpPlus.Core.Models/Applications/Application.cs b/src/core/DSharpPlus.Core.Models/Applications/Application.cs index a0186723bd..324b3f6ab4 100644 --- a/src/core/DSharpPlus.Core.Models/Applications/Application.cs +++ b/src/core/DSharpPlus.Core.Models/Applications/Application.cs @@ -19,7 +19,7 @@ public sealed record Application : IApplication public required string Name { get; init; } /// - public required string? Icon { get; init; } + public string? Icon { get; init; } /// public Optional Description { get; init; } @@ -49,7 +49,7 @@ public sealed record Application : IApplication public required string VerifyKey { get; init; } /// - public required ITeam? Team { get; init; } + public ITeam? Team { get; init; } /// public Optional GuildId { get; init; } diff --git a/src/core/DSharpPlus.Core.Models/Channels/Message.cs b/src/core/DSharpPlus.Core.Models/Channels/Message.cs index 59b91e0600..34804a4ecd 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/Message.cs +++ b/src/core/DSharpPlus.Core.Models/Channels/Message.cs @@ -29,7 +29,7 @@ public sealed record Message : IMessage public required DateTimeOffset Timestamp { get; init; } /// - public required DateTimeOffset? EditedTimestamp { get; init; } + public DateTimeOffset? EditedTimestamp { get; init; } /// public required bool Tts { get; init; } diff --git a/src/core/DSharpPlus.Core.Models/Emojis/Emoji.cs b/src/core/DSharpPlus.Core.Models/Emojis/Emoji.cs index ce9e997df1..2a0fc5e86d 100644 --- a/src/core/DSharpPlus.Core.Models/Emojis/Emoji.cs +++ b/src/core/DSharpPlus.Core.Models/Emojis/Emoji.cs @@ -12,10 +12,10 @@ namespace DSharpPlus.Core.Models; public sealed record Emoji : IEmoji { /// - public required Snowflake? Id { get; init; } + public Snowflake? Id { get; init; } /// - public required string? Name { get; init; } + public string? Name { get; init; } /// public Optional> Roles { get; init; } diff --git a/src/core/DSharpPlus.Core.Models/Guilds/Guild.cs b/src/core/DSharpPlus.Core.Models/Guilds/Guild.cs index 4e011ca0dc..8b479b8931 100644 --- a/src/core/DSharpPlus.Core.Models/Guilds/Guild.cs +++ b/src/core/DSharpPlus.Core.Models/Guilds/Guild.cs @@ -19,16 +19,16 @@ public sealed record Guild : IGuild public required string Name { get; init; } /// - public required string? Icon { get; init; } + public string? Icon { get; init; } /// public Optional IconHash { get; init; } /// - public required string? Splash { get; init; } + public string? Splash { get; init; } /// - public required string? DiscoverySplash { get; init; } + public string? DiscoverySplash { get; init; } /// public Optional Owner { get; init; } @@ -40,7 +40,7 @@ public sealed record Guild : IGuild public Optional Permissions { get; init; } /// - public required Snowflake? AfkChannelId { get; init; } + public Snowflake? AfkChannelId { get; init; } /// public required int AfkTimeout { get; init; } @@ -73,16 +73,16 @@ public sealed record Guild : IGuild public required DiscordMfaLevel MfaLevel { get; init; } /// - public required Snowflake? ApplicationId { get; init; } + public Snowflake? ApplicationId { get; init; } /// - public required Snowflake? SystemChannelId { get; init; } + public Snowflake? SystemChannelId { get; init; } /// public required DiscordSystemChannelFlags SystemChannelFlags { get; init; } /// - public required Snowflake? RulesChannelId { get; init; } + public Snowflake? RulesChannelId { get; init; } /// public Optional MaxPresences { get; init; } @@ -91,13 +91,13 @@ public sealed record Guild : IGuild public Optional MaxMembers { get; init; } /// - public required string? VanityUrlCode { get; init; } + public string? VanityUrlCode { get; init; } /// - public required string? Description { get; init; } + public string? Description { get; init; } /// - public required string? Banner { get; init; } + public string? Banner { get; init; } /// public required int PremiumTier { get; init; } @@ -109,7 +109,7 @@ public sealed record Guild : IGuild public required string PreferredLocale { get; init; } /// - public required Snowflake? PublicUpdatesChannelId { get; init; } + public Snowflake? PublicUpdatesChannelId { get; init; } /// public Optional MaxVideoChannelUsers { get; init; } @@ -136,5 +136,5 @@ public sealed record Guild : IGuild public required bool PremiumProgressBarEnabled { get; init; } /// - public required Snowflake? SafetyAlertsChannelId { get; init; } + public Snowflake? SafetyAlertsChannelId { get; init; } } \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/Invites/Invite.cs b/src/core/DSharpPlus.Core.Models/Invites/Invite.cs index d52fce132f..6c60bd58a4 100644 --- a/src/core/DSharpPlus.Core.Models/Invites/Invite.cs +++ b/src/core/DSharpPlus.Core.Models/Invites/Invite.cs @@ -19,7 +19,7 @@ public sealed record Invite : IInvite public Optional Guild { get; init; } /// - public required IPartialChannel? Channel { get; init; } + public IPartialChannel? Channel { get; init; } /// public Optional Inviter { get; init; } diff --git a/src/core/DSharpPlus.Core.Models/StageInstances/StageInstance.cs b/src/core/DSharpPlus.Core.Models/StageInstances/StageInstance.cs index 986c53260b..db335f77bd 100644 --- a/src/core/DSharpPlus.Core.Models/StageInstances/StageInstance.cs +++ b/src/core/DSharpPlus.Core.Models/StageInstances/StageInstance.cs @@ -26,5 +26,5 @@ public sealed record StageInstance : IStageInstance public required DiscordStagePrivacyLevel PrivacyLevel { get; init; } /// - public required Snowflake? GuildScheduledEventId { get; init; } + public Snowflake? GuildScheduledEventId { get; init; } } \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Models/Stickers/Sticker.cs b/src/core/DSharpPlus.Core.Models/Stickers/Sticker.cs index e5841f421d..034a80c2f5 100644 --- a/src/core/DSharpPlus.Core.Models/Stickers/Sticker.cs +++ b/src/core/DSharpPlus.Core.Models/Stickers/Sticker.cs @@ -20,7 +20,7 @@ public sealed record Sticker : ISticker public required string Name { get; init; } /// - public required string? Description { get; init; } + public string? Description { get; init; } /// public required string Tags { get; init; } diff --git a/src/core/DSharpPlus.Core.Models/Users/User.cs b/src/core/DSharpPlus.Core.Models/Users/User.cs index a49a7f04b6..77880b7692 100644 --- a/src/core/DSharpPlus.Core.Models/Users/User.cs +++ b/src/core/DSharpPlus.Core.Models/Users/User.cs @@ -20,10 +20,10 @@ public sealed record User : IUser public required string Discriminator { get; init; } /// - public required string? GlobalName { get; init; } + public string? GlobalName { get; init; } /// - public required string? Avatar { get; init; } + public string? Avatar { get; init; } /// public Optional Bot { get; init; } diff --git a/src/core/DSharpPlus.Core.Models/Webhooks/Webhook.cs b/src/core/DSharpPlus.Core.Models/Webhooks/Webhook.cs index ad069b9052..032332d354 100644 --- a/src/core/DSharpPlus.Core.Models/Webhooks/Webhook.cs +++ b/src/core/DSharpPlus.Core.Models/Webhooks/Webhook.cs @@ -20,22 +20,22 @@ public sealed record Webhook : IWebhook public Optional GuildId { get; init; } /// - public required Snowflake? ChannelId { get; init; } + public Snowflake? ChannelId { get; init; } /// public Optional User { get; init; } /// - public required string? Name { get; init; } + public string? Name { get; init; } /// - public required string? Avatar { get; init; } + public string? Avatar { get; init; } /// public Optional Token { get; init; } /// - public required Snowflake? ApplicationId { get; init; } + public Snowflake? ApplicationId { get; init; } /// public Optional SourceGuild { get; init; } diff --git a/tools/generators/generate-concrete-objects.csx b/tools/generators/generate-concrete-objects.csx index 106a3b3b8a..8c6dea4269 100644 --- a/tools/generators/generate-concrete-objects.csx +++ b/tools/generators/generate-concrete-objects.csx @@ -291,7 +291,7 @@ for (int i = 0; i < collectedMetadata.Count; i++) foreach (PropertyMetadata property in principal.Properties!) { - bool required = !property.IsOptional && !property.IsNullable; + bool required = !(property.IsOptional || property.IsNullable); string type = property.Type; // strip optionality if we're being overwritten diff --git a/tools/generators/parse-interface.csx b/tools/generators/parse-interface.csx index 50ac050f81..c159246a57 100644 --- a/tools/generators/parse-interface.csx +++ b/tools/generators/parse-interface.csx @@ -204,7 +204,7 @@ public InterfaceMetadata? ParseInterface(string filename, string baseDirectory) Type = type, Name = property.Identifier.ToString(), IsOptional = type.StartsWith("Optional<"), - IsNullable = type.EndsWith('?'), + IsNullable = type.EndsWith('?') || (type.StartsWith("Optional<") && type.EndsWith("?>")), IsOverwrite = property.ChildTokens().Any(token => token.RawKind == (int)SyntaxKind.NewKeyword) } ); From 52bfb5bb2aa6728ba6cb15a5e7021f1faa36465c Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Fri, 29 Dec 2023 17:21:31 +0100 Subject: [PATCH 229/323] wrap application commands query parameters --- .../API/IApplicationCommandsRestAPI.cs | 9 +++++---- .../Queries/LocalizationQuery.cs | 17 +++++++++++++++++ 2 files changed, 22 insertions(+), 4 deletions(-) create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/Queries/LocalizationQuery.cs diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IApplicationCommandsRestAPI.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IApplicationCommandsRestAPI.cs index 1f4fd95adc..c3ca3f5eaf 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IApplicationCommandsRestAPI.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IApplicationCommandsRestAPI.cs @@ -8,6 +8,7 @@ using DSharpPlus.Core.Abstractions.Models; using DSharpPlus.Core.Abstractions.Rest.Payloads; +using DSharpPlus.Core.Abstractions.Rest.Queries; using DSharpPlus.Core.Abstractions.Rest.Responses; using Remora.Results; @@ -24,14 +25,14 @@ public interface IApplicationCommandsRestAPI /// Fetches all global application commands for your application. /// /// The snowflake identifier of your application. - /// Indicates whether to include full localizations in the returned objects. + /// Indicates whether to include full localizations in the returned objects. /// Additional instructions regarding this request. /// A cancellation token for this operation. /// An array of application commands. public ValueTask>> GetGlobalApplicationCommandsAsync ( Snowflake applicationId, - bool? withLocalizations = null, + LocalizationQuery query = default, RequestInfo info = default, CancellationToken ct = default ); @@ -132,7 +133,7 @@ public ValueTask>> BulkOverwriteGlobal /// /// The snowflake identifier of your application. /// The snowflake identifier of the guild containing the application commands. - /// + /// /// Indicates whether to include localization dictionaries with the commands. /// /// Additional instructions regarding this request. @@ -141,7 +142,7 @@ public ValueTask>> GetGuildApplication ( Snowflake applicationId, Snowflake guildId, - bool? withLocalizations = null, + LocalizationQuery query = default, RequestInfo info = default, CancellationToken ct = default ); diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/LocalizationQuery.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/LocalizationQuery.cs new file mode 100644 index 0000000000..0b11449a0c --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/LocalizationQuery.cs @@ -0,0 +1,17 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Core.Abstractions.Rest.Queries; + +/// +/// Contains query parameters for application command endpoints that can include localizations +/// along with the command object. +/// +public readonly record struct LocalizationQuery +{ + /// + /// Indicates whether to include command localizations with the command object. + /// + public bool? WithLocalizations { get; init; } +} \ No newline at end of file From c3325b3c3e4f27127116ea672f69b6c5e53ddae8 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Fri, 29 Dec 2023 19:03:46 +0100 Subject: [PATCH 230/323] wrap audit log queries --- .../API/IAuditLogsRestAPI.cs | 17 +++------ .../Queries/IPaginationQuery.cs | 29 ++++++++++++++ .../Queries/ListGuildAuditLogEntriesQuery.cs | 38 +++++++++++++++++++ 3 files changed, 73 insertions(+), 11 deletions(-) create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/Queries/IPaginationQuery.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/Queries/ListGuildAuditLogEntriesQuery.cs diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IAuditLogsRestAPI.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IAuditLogsRestAPI.cs index 69fe9ae2a7..8fe2cb41cd 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IAuditLogsRestAPI.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IAuditLogsRestAPI.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; using DSharpPlus.Core.Abstractions.Models; -using DSharpPlus.Entities; +using DSharpPlus.Core.Abstractions.Rest.Queries; using Remora.Results; @@ -21,22 +21,17 @@ public interface IAuditLogsRestAPI /// Lists audit log entries for a given guild. /// /// The snowflake identifier of the guild to list audit logs for. - /// If specified, only lists entries from this user ID. - /// If specified, only lists entries of this audit log event type. - /// If specified, only lists entries with an ID less than this ID. - /// If specified, only lists entries with an ID greater than this ID. - /// The maximum number of entries, between 1 and 100. + /// + /// Contains the query parameters for this request, comprised of request pagination and log entry + /// filtering options. + /// /// Additional instructions regarding this request. /// A cancellation token for this operation. /// An audit log object, containing all relevant other entities and the main audit log. public ValueTask> ListGuildAuditLogEntriesAsync ( Snowflake guildId, - Snowflake? userId = null, - DiscordAuditLogEvent? actionType = null, - Snowflake? before = null, - Snowflake? after = null, - int? limit = null, + ListGuildAuditLogEntriesQuery query = default, RequestInfo info = default, CancellationToken ct = default ); diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/IPaginationQuery.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/IPaginationQuery.cs new file mode 100644 index 0000000000..e1de8b393f --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/IPaginationQuery.cs @@ -0,0 +1,29 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Core.Abstractions.Rest.Queries; + +/// +/// Represents a base interface for all snowflake-paginated queries, for user convenience. +/// +// this is here despite not being technically necessary to accurately implement queries because +// as of now, it can't go anywhere else. we'll move this once possible, using explicit extensions +// acting as interface adapters. +public interface IPaginationQuery +{ + /// + /// If specified, only request entities with an ID less than this ID. + /// + public Snowflake? Before { get; init; } + + /// + /// If specified, only request entities with an ID greater than this ID. + /// + public Snowflake? After { get; init; } + + /// + /// The maximum number of entities for this request. + /// + public int? Limit { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/ListGuildAuditLogEntriesQuery.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/ListGuildAuditLogEntriesQuery.cs new file mode 100644 index 0000000000..74eed49020 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/ListGuildAuditLogEntriesQuery.cs @@ -0,0 +1,38 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Entities; + +namespace DSharpPlus.Core.Abstractions.Rest.Queries; + +/// +/// Contains the query parameters to IAuditLogsRestAPI.ListGuildAuditLogEntriesAsync. +/// +public readonly record struct ListGuildAuditLogEntriesQuery : IPaginationQuery +{ + /// + /// If specified, only list entries from this user ID. + /// + public Snowflake? UserId { get; init; } + + /// + /// If specified, only list entries of this audit log event type. + /// + public DiscordAuditLogEvent? ActionType { get; init; } + + /// + /// If specified, only list entries with an ID less than this ID. + /// + public Snowflake? Before { get; init; } + + /// + /// If specified, only list entries with an ID greater than this ID. + /// + public Snowflake? After { get; init; } + + /// + /// The maximum number of entries, between 1 and 100. + /// + public int? Limit { get; init; } +} \ No newline at end of file From 5481ec6ab1be56462ffeb12ed2a110768902c3a4 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Fri, 29 Dec 2023 20:55:22 +0100 Subject: [PATCH 231/323] wrap channel query parameters --- .../API/IChannelRestAPI.cs | 56 +++++++------------ .../LocalizationQuery.cs | 0 .../ListGuildAuditLogEntriesQuery.cs | 0 .../Channels/GetChannelMessagesQuery.cs | 34 +++++++++++ .../Queries/Channels/GetReactionsQuery.cs | 18 ++++++ .../Queries/Channels/GetThreadMemberQuery.cs | 16 ++++++ .../Channels/ListArchivedThreadsQuery.cs | 20 +++++++ .../Channels/ListThreadMembersQuery.cs | 23 ++++++++ .../Queries/IPaginationQuery.cs | 2 +- 9 files changed, 131 insertions(+), 38 deletions(-) rename src/core/DSharpPlus.Core.Abstractions.Rest/Queries/{ => ApplicationCommands}/LocalizationQuery.cs (100%) rename src/core/DSharpPlus.Core.Abstractions.Rest/Queries/{ => AuditLogs}/ListGuildAuditLogEntriesQuery.cs (100%) create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Channels/GetChannelMessagesQuery.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Channels/GetReactionsQuery.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Channels/GetThreadMemberQuery.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Channels/ListArchivedThreadsQuery.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Channels/ListThreadMembersQuery.cs diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IChannelRestAPI.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IChannelRestAPI.cs index fd17362a3a..22ce23197e 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IChannelRestAPI.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IChannelRestAPI.cs @@ -2,13 +2,13 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using System; using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; using DSharpPlus.Core.Abstractions.Models; using DSharpPlus.Core.Abstractions.Rest.Payloads; +using DSharpPlus.Core.Abstractions.Rest.Queries; using DSharpPlus.Core.Abstractions.Rest.Responses; using Remora.Results; @@ -111,19 +111,13 @@ public ValueTask> DeleteChannelAsync /// only the first one in the parameter list is respected, independent of the order they are passed in client code. /// /// The snowflake identifier of the channel in question. - /// The snowflake identifier of the center message of the requested block. - /// The snowflake identifier of the first older message than the requested block. - /// The snowflake identifier of the first newer message than the requested block. - /// The maximum amount of messages to return. + /// Specifies where to get messages from, used for paginating. /// Additional instructions regarding this request. /// A cancellation token for this operation. public ValueTask>> GetChannelMessagesAsync ( Snowflake channelId, - Snowflake? around = null, - Snowflake? before = null, - Snowflake? after = null, - int? limit = null, + GetChannelMessagesQuery query = default, RequestInfo info = default, CancellationToken ct = default ); @@ -236,8 +230,7 @@ public ValueTask DeleteUserReactionAsync /// The snowflake identifier of the message's parent channel. /// The snowflake identifier of the message in question. /// The string representation of the queried emoji. - /// Specifies a minimum user ID to return from, to paginate queries. - /// The maximum amount of users to return. Defaults to 25. + /// Contains query information related to request pagination /// Additional instructions regarding this request. /// A cancellation token for this operation. public ValueTask>> GetReactionsAsync @@ -245,8 +238,7 @@ public ValueTask>> GetReactionsAsync Snowflake channelId, Snowflake messageId, string emoji, - Snowflake? after = null, - int? limit = null, + GetReactionsQuery query = default, RequestInfo info = default, CancellationToken ct = default ); @@ -644,14 +636,16 @@ public ValueTask RemoveFromThreadAsync /// /// The snowflake identifier of the thread to obtain data from. /// The snowflake identifier of the user to obtain data for. - /// Whether the returned thread member object should contain guild member data. + /// + /// Specifies whether the returned thread member object should contain guild member data. + /// /// Additional instructions regarding this request. /// A cancellation token for this operation. public ValueTask> GetThreadMemberAsync ( Snowflake threadId, Snowflake userId, - bool? withMember = null, + GetThreadMemberQuery query = default, RequestInfo info = default, CancellationToken ct = default ); @@ -660,17 +654,15 @@ public ValueTask> GetThreadMemberAsync /// Returns a list of all thread members for the specified thread. /// /// The snowflake identifier fo the thread to obtain data from. - /// Whether the returned thread member object should contain guild member data. - /// Gets thread members after this snowflake ID. - /// The maximum number of thread members to return. + /// + /// Specifies additional query information pertaining to pagination and optional additional data. + /// /// Additional instructions regarding this request. /// A cancellation token for this operation. public ValueTask>> ListThreadMembersAsync ( Snowflake threadId, - bool? withMember = null, - Snowflake? after = null, - int? limit = null, + ListThreadMembersQuery query = default, RequestInfo info = default, CancellationToken ct = default ); @@ -679,17 +671,13 @@ public ValueTask>> ListThreadMembersAsync /// Returns all public, archived threads for this channel including respective thread member objects. /// /// The snowflake identifier of the thread's parent channel. - /// - /// Timestamp to filter threads by: only threads archived before this timestamp will be returned. - /// - /// The maximum amount of threads to return. + /// Contains pagination information for this request. /// Additional instructions regarding this request. /// A cancellation token for this operation. public ValueTask> ListPublicArchivedThreadsAsync ( Snowflake channelId, - DateTimeOffset? before, - int? limit = null, + ListArchivedThreadsQuery query = default, RequestInfo info = default, CancellationToken ct = default ); @@ -698,17 +686,13 @@ public ValueTask> ListPublicArchivedThreadsA /// Returns all private, accessible, archived threads for this channel including respective thread member objects. /// /// The snowflake identifier of the thread's parent channel. - /// - /// Timestamp to filter threads by: only threads archived before this timestamp will be returned. - /// - /// The maximum amount of threads to return. + /// Contains pagination information for this request. /// Additional instructions regarding this request. /// A cancellation token for this operation. public ValueTask> ListPrivateArchivedThreadsAsync ( Snowflake channelId, - DateTimeOffset? before, - int? limit = null, + ListArchivedThreadsQuery query = default, RequestInfo info = default, CancellationToken ct = default ); @@ -717,15 +701,13 @@ public ValueTask> ListPrivateArchivedThreads /// Returns a list of joined, private, archived threads. /// /// The nowflake identifier of their parent channel. - /// A timestamp to act as upper boundary for archival dates. - /// The maximum amount of threads to return from this request. + /// Contains pagination information for this request. /// Additional instructions regarding this request. /// A cancellation token for this operation. public ValueTask> ListJoinedPrivateArchivedThreadsAsync ( Snowflake channelId, - DateTimeOffset? before, - int? limit = null, + ListArchivedThreadsQuery query = default, RequestInfo info = default, CancellationToken ct = default ); diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/LocalizationQuery.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/ApplicationCommands/LocalizationQuery.cs similarity index 100% rename from src/core/DSharpPlus.Core.Abstractions.Rest/Queries/LocalizationQuery.cs rename to src/core/DSharpPlus.Core.Abstractions.Rest/Queries/ApplicationCommands/LocalizationQuery.cs diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/ListGuildAuditLogEntriesQuery.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/AuditLogs/ListGuildAuditLogEntriesQuery.cs similarity index 100% rename from src/core/DSharpPlus.Core.Abstractions.Rest/Queries/ListGuildAuditLogEntriesQuery.cs rename to src/core/DSharpPlus.Core.Abstractions.Rest/Queries/AuditLogs/ListGuildAuditLogEntriesQuery.cs diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Channels/GetChannelMessagesQuery.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Channels/GetChannelMessagesQuery.cs new file mode 100644 index 0000000000..fd72ddf6e6 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Channels/GetChannelMessagesQuery.cs @@ -0,0 +1,34 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Core.Abstractions.Rest.Queries; + +/// +/// Contains query parameters for IChannelRestAPI.GetChannelMessagesAsync. +/// +public readonly record struct GetChannelMessagesQuery : IPaginationQuery +{ + /// + /// If specified, request entities around this ID. + /// + /// + /// Mutually exclusive with and . + /// + public Snowflake? Around { get; init; } + + /// + /// + /// Mutually exclusive with and . + /// + public Snowflake? Before { get; init; } + + /// + /// + /// Mutually exclusive with and . + /// + public Snowflake? After { get; init; } + + /// + public int? Limit { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Channels/GetReactionsQuery.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Channels/GetReactionsQuery.cs new file mode 100644 index 0000000000..926affc387 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Channels/GetReactionsQuery.cs @@ -0,0 +1,18 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Core.Abstractions.Rest.Queries; + +public readonly record struct GetReactionsQuery +{ + /// + /// If specified, only request reactions from users with an ID greater than this ID. + /// + public Snowflake? After { get; init; } + + /// + /// The maximum number of reactions for this request, up to 25. + /// + public int? Limit { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Channels/GetThreadMemberQuery.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Channels/GetThreadMemberQuery.cs new file mode 100644 index 0000000000..21c8ed1ddb --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Channels/GetThreadMemberQuery.cs @@ -0,0 +1,16 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Core.Abstractions.Rest.Queries; + +/// +/// Contains the query parameters for IChannelRestAPI.GetThreadMemberAsync. +/// +public readonly record struct GetThreadMemberQuery +{ + /// + /// Specifies whether the returned thread member object should contain guild member data. + /// + public bool? WithMember { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Channels/ListArchivedThreadsQuery.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Channels/ListArchivedThreadsQuery.cs new file mode 100644 index 0000000000..55259a536b --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Channels/ListArchivedThreadsQuery.cs @@ -0,0 +1,20 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; + +namespace DSharpPlus.Core.Abstractions.Rest.Queries; + +public readonly record struct ListArchivedThreadsQuery +{ + /// + /// A timestamp to filter threads by: only threads archived before this timestamp will be returned. + /// + public DateTimeOffset? Before { get; init; } + + /// + /// The maximum number of threads to return from this request. + /// + public int? Limit { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Channels/ListThreadMembersQuery.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Channels/ListThreadMembersQuery.cs new file mode 100644 index 0000000000..86205fe8ae --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Channels/ListThreadMembersQuery.cs @@ -0,0 +1,23 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Core.Abstractions.Rest.Queries; + +public readonly record struct ListThreadMembersQuery +{ + /// + /// Specifies whether the returned thread member object should contain guild member data. + /// + public bool? WithMember { get; init; } + + /// + /// If specified, only request thread members with an ID greater than this ID. + /// + public Snowflake? After { get; init; } + + /// + /// The maximum number of entities for this request. + /// + public int? Limit { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/IPaginationQuery.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/IPaginationQuery.cs index e1de8b393f..5f406c7772 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/IPaginationQuery.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/IPaginationQuery.cs @@ -23,7 +23,7 @@ public interface IPaginationQuery public Snowflake? After { get; init; } /// - /// The maximum number of entities for this request. + /// The maximum number of entities to return from this request. /// public int? Limit { get; init; } } \ No newline at end of file From 73650c95d576786c9b09e18a4d291c6a5e643e8a Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Fri, 29 Dec 2023 20:59:58 +0100 Subject: [PATCH 232/323] document the query parameter types --- .../Queries/Channels/GetReactionsQuery.cs | 3 +++ .../Queries/Channels/ListArchivedThreadsQuery.cs | 3 +++ .../Queries/Channels/ListThreadMembersQuery.cs | 3 +++ 3 files changed, 9 insertions(+) diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Channels/GetReactionsQuery.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Channels/GetReactionsQuery.cs index 926affc387..0cb95f37b2 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Channels/GetReactionsQuery.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Channels/GetReactionsQuery.cs @@ -4,6 +4,9 @@ namespace DSharpPlus.Core.Abstractions.Rest.Queries; +/// +/// Contains the query parameters for IChannelRestAPI.GetReactionsAsync. +/// public readonly record struct GetReactionsQuery { /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Channels/ListArchivedThreadsQuery.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Channels/ListArchivedThreadsQuery.cs index 55259a536b..e5b5347fc4 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Channels/ListArchivedThreadsQuery.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Channels/ListArchivedThreadsQuery.cs @@ -6,6 +6,9 @@ namespace DSharpPlus.Core.Abstractions.Rest.Queries; +/// +/// Contains the query parameters for endpoints listing archived threads. +/// public readonly record struct ListArchivedThreadsQuery { /// diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Channels/ListThreadMembersQuery.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Channels/ListThreadMembersQuery.cs index 86205fe8ae..ff867b560e 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Channels/ListThreadMembersQuery.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Channels/ListThreadMembersQuery.cs @@ -4,6 +4,9 @@ namespace DSharpPlus.Core.Abstractions.Rest.Queries; +/// +/// Contains the query parameters for IChannelRestAPI.ListThreadMembersAsync. +/// public readonly record struct ListThreadMembersQuery { /// From 78e1bff8cd0a0e0f4d353c617a061392dff50168 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Fri, 29 Dec 2023 21:08:10 +0100 Subject: [PATCH 233/323] wrap entitlement query parameters --- .../API/IEntitlementsRestAPI.cs | 18 ++------- .../Entitlements/ListEntitlementsQuery.cs | 40 +++++++++++++++++++ 2 files changed, 43 insertions(+), 15 deletions(-) create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Entitlements/ListEntitlementsQuery.cs diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IEntitlementsRestAPI.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IEntitlementsRestAPI.cs index 0d2b36a74b..d3839951b3 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IEntitlementsRestAPI.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IEntitlementsRestAPI.cs @@ -8,7 +8,7 @@ using DSharpPlus.Core.Abstractions.Models; using DSharpPlus.Core.Abstractions.Rest.Payloads; - +using DSharpPlus.Core.Abstractions.Rest.Queries; using Remora.Results; namespace DSharpPlus.Core.Abstractions.Rest.API; @@ -22,25 +22,13 @@ public interface IEntitlementsRestAPI /// Returns all entitlements for a given app, according to the query parameters. /// /// The snowflake identifier of the current application. - /// The snowflake identifier of the user to look up entitlements for. - /// A comma-delimited set of snowflakes of SKUs to check entitlements for. - /// Specifies an entitlement to retrieve entitlements before of, for pagination. - /// Specifies an entitlement to retrieve entitlements after of, for pagination. - /// The maximum amount of entitlements to return, up to 100. - /// The snowflake identifier of the guild to look up entitlements for. - /// Specifies whether or not to include ended entitlements. + /// Contains filtering and pagination options for this request. /// Additional instructions regarding this request. /// A cancellation token for this operation. public ValueTask>> ListEntitlementsAsync ( Snowflake applicationId, - Snowflake? userId = null, - string? skuIds = null, - Snowflake? before = null, - Snowflake? after = null, - int? limit = null, - Snowflake? guildId = null, - bool? excludeEnded = null, + ListEntitlementsQuery query = default, RequestInfo info = default, CancellationToken ct = default ); diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Entitlements/ListEntitlementsQuery.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Entitlements/ListEntitlementsQuery.cs new file mode 100644 index 0000000000..77bc28555f --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Entitlements/ListEntitlementsQuery.cs @@ -0,0 +1,40 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Core.Abstractions.Rest.Queries; + +/// +/// Contains the query parameters to IEntitlementsRestAPI.ListEntitlementsAsync. +/// +public readonly record struct ListEntitlementsQuery : IPaginationQuery +{ + /// + public Snowflake? Before { get; init; } + + /// + public Snowflake? After { get; init; } + + /// + public int? Limit { get; init; } + + /// + /// The snowflake identifier of the user to look up entitlements for. + /// + public Snowflake? UserId { get; init; } + + /// + /// A comma-delimited set of snowflakes of SKUs to check entitlements for. + /// + public string? SkuIds { get; init; } + + /// + /// The snowflake identifier of the guild to look up entitlements for. + /// + public Snowflake? GuildId { get; init; } + + /// + /// Specifies whether or not to include ended entitlements. + /// + public bool? ExcludeEnded { get; init; } +} \ No newline at end of file From ce8b5dc9db547e5a6d86e37860d495c2d0ebd76c Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Fri, 29 Dec 2023 21:58:00 +0100 Subject: [PATCH 234/323] wrap guild query parameters --- .../API/IChannelRestAPI.cs | 4 +- .../API/IGuildRestAPI.cs | 57 +++++++------------ .../ListGuildAuditLogEntriesQuery.cs | 2 +- .../Channels/GetChannelMessagesQuery.cs | 2 +- .../Entitlements/ListEntitlementsQuery.cs | 2 +- ...ionsQuery.cs => ForwardsPaginatedQuery.cs} | 9 +-- .../Queries/Guilds/BanMemberQuery.cs | 14 +++++ .../Queries/Guilds/BeginGuildPruneQuery.cs | 30 ++++++++++ .../Queries/Guilds/GetGuildPruneCountQuery.cs | 25 ++++++++ .../Queries/Guilds/GetGuildQuery.cs | 16 ++++++ .../Queries/Guilds/SearchGuildMembersQuery.cs | 17 ++++++ ...IPaginationQuery.cs => IPaginatedQuery.cs} | 2 +- .../Queries/PaginatedQuery.cs | 20 +++++++ 13 files changed, 150 insertions(+), 50 deletions(-) rename src/core/DSharpPlus.Core.Abstractions.Rest/Queries/{Channels/GetReactionsQuery.cs => ForwardsPaginatedQuery.cs} (56%) create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Guilds/BanMemberQuery.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Guilds/BeginGuildPruneQuery.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Guilds/GetGuildPruneCountQuery.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Guilds/GetGuildQuery.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Guilds/SearchGuildMembersQuery.cs rename src/core/DSharpPlus.Core.Abstractions.Rest/Queries/{IPaginationQuery.cs => IPaginatedQuery.cs} (96%) create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/Queries/PaginatedQuery.cs diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IChannelRestAPI.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IChannelRestAPI.cs index 22ce23197e..accef9bf93 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IChannelRestAPI.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IChannelRestAPI.cs @@ -230,7 +230,7 @@ public ValueTask DeleteUserReactionAsync /// The snowflake identifier of the message's parent channel. /// The snowflake identifier of the message in question. /// The string representation of the queried emoji. - /// Contains query information related to request pagination + /// Contains query information related to request pagination. /// Additional instructions regarding this request. /// A cancellation token for this operation. public ValueTask>> GetReactionsAsync @@ -238,7 +238,7 @@ public ValueTask>> GetReactionsAsync Snowflake channelId, Snowflake messageId, string emoji, - GetReactionsQuery query = default, + ForwardsPaginatedQuery query = default, RequestInfo info = default, CancellationToken ct = default ); diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IGuildRestAPI.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IGuildRestAPI.cs index 489c603f38..14a2f7c090 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IGuildRestAPI.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IGuildRestAPI.cs @@ -9,6 +9,7 @@ using DSharpPlus.Core.Abstractions.Models; using DSharpPlus.Core.Abstractions.Rest.Payloads; +using DSharpPlus.Core.Abstractions.Rest.Queries; using DSharpPlus.Core.Abstractions.Rest.Responses; using DSharpPlus.Entities; @@ -40,13 +41,13 @@ public ValueTask> CreateGuildAsync /// Fetches a guild from its snowflake identifier. /// /// The snowflake identifier of the guild in question. - /// Whether or not the response should include total and online member counts. + /// Specifies whether the response should include total and online member counts. /// Additional instructions regarding this request. /// A cancellation token for this operation. public ValueTask> GetGuildAsync ( Snowflake guildId, - bool? withCounts = null, + GetGuildQuery query = default, RequestInfo info = default, CancellationToken ct = default ); @@ -178,15 +179,15 @@ public ValueTask> GetGuildMemberAsync /// Returns a list of guild member objects. /// /// The snowflake identifier of the guild to be queried. - /// The amount of users to query, between 1 and 1000 - /// Highest user ID to not query. Used for request pagination. + /// + /// Contains information pertaining to request pagination. Up to 1000 users are allowed per request. + /// /// Additional instructions regarding this request. /// A cancellation token for this operation. public ValueTask>> ListGuildMembersAsync ( Snowflake guildId, - int? limit = null, - Snowflake? after = null, + ForwardsPaginatedQuery query = default, RequestInfo info = default, CancellationToken ct = default ); @@ -195,15 +196,15 @@ public ValueTask>> ListGuildMembersAsync /// Returns a list of guild member objects whose username or nickname starts with the given string. /// /// The snowflake identifier of the string in question. - /// The query string to search for. - /// The maximum amount of members to return; 1 - 1000. + /// The query string to search for. + /// The maximum amount of members to return; 1 - 1000. /// Additional instructions regarding this request. /// A cancellation token for this operation. public ValueTask>> SearchGuildMembersAsync ( Snowflake guildId, - string query, - int? limit = null, + string queryString, + SearchGuildMembersQuery query = default, RequestInfo info = default, CancellationToken ct = default ); @@ -323,18 +324,14 @@ public ValueTask RemoveGuildMemberAsync /// Returns a list of bans from the given guild. This endpoint is paginated. /// /// Snowflake identifier of the guild in question. - /// The number of bans to return, up to 1000. - /// Consider only snowflakes before the given ID. - /// Consider only snowflakes after the given ID. + /// The query parameters used for pagination. Up to 1000 bans can be returned. /// Additional instructions regarding this request. /// A cancellation token for this operation. /// An array of objects, representing the bans in the guild. public ValueTask>> GetGuildBansAsync ( Snowflake guildId, - int? limit = null, - Snowflake? before = null, - Snowflake? after = null, + PaginatedQuery query = default, RequestInfo info = default, CancellationToken ct = default ); @@ -359,7 +356,7 @@ public ValueTask> GetGuildBanAsync /// /// The snowflake identifier of the guild in question. /// The snowflake identifier of the user in question. - /// + /// /// Specifies how many seconds of message history from this user shall be purged, between 0 and /// 604800, which equals 7 days. /// @@ -370,7 +367,7 @@ public ValueTask BanMemberAsync ( Snowflake guildId, Snowflake userId, - int deleteMessageSeconds, + BanMemberQuery query = default, string? reason = null, RequestInfo info = default, CancellationToken ct = default @@ -501,20 +498,13 @@ public ValueTask DeleteRoleAsync /// Queries how many users would be kicked from a given guild in a prune. /// /// The snowflake identifier of the guild in question. - /// Amount of inactivity days to be measured, 0 to 30. - /// Comma-separated list of role IDs to include in the prune. - /// - /// Any user with a subset of these roles will be considered for the prune. Any user with any role not listed here - /// will not be included in the count. - /// - /// + /// Provides additional information on which members to count. /// Additional instructions regarding this request. /// A cancellation token for this operation. public ValueTask> GetGuildPruneCountAsync ( Snowflake guildId, - int? days = null, - string? includeRoles = null, + GetGuildPruneCountQuery query = default, RequestInfo info = default, CancellationToken ct = default ); @@ -523,14 +513,7 @@ public ValueTask> GetGuildPruneCountAsync /// Initiates a prune from the guild in question. /// /// The snowflake identifier of the guild in question. - /// The amount of inactivity days to be measured, 0 to 30. - /// Comma-separated list of role IDs to include in the prune. - /// - /// Any user with a subset of these roles will be considered for the prune. Any user with any role not listed here - /// will not be included in the count. - /// - /// - /// Whether or not the amount of users pruned should be calculated. + /// Contains additional information on which users to consider. /// Optional audit log reason for the prune. /// Additional instructions regarding this request. /// A cancellation token for this operation. @@ -538,9 +521,7 @@ public ValueTask> GetGuildPruneCountAsync public ValueTask> BeginGuildPruneAsync ( Snowflake guildId, - int? days = null, - string? includeRoles = null, - bool? computePruneCount = null, + BeginGuildPruneQuery query = default, string? reason = null, RequestInfo info = default, CancellationToken ct = default diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/AuditLogs/ListGuildAuditLogEntriesQuery.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/AuditLogs/ListGuildAuditLogEntriesQuery.cs index 74eed49020..1729ff421f 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/AuditLogs/ListGuildAuditLogEntriesQuery.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/AuditLogs/ListGuildAuditLogEntriesQuery.cs @@ -9,7 +9,7 @@ namespace DSharpPlus.Core.Abstractions.Rest.Queries; /// /// Contains the query parameters to IAuditLogsRestAPI.ListGuildAuditLogEntriesAsync. /// -public readonly record struct ListGuildAuditLogEntriesQuery : IPaginationQuery +public readonly record struct ListGuildAuditLogEntriesQuery : IPaginatedQuery { /// /// If specified, only list entries from this user ID. diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Channels/GetChannelMessagesQuery.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Channels/GetChannelMessagesQuery.cs index fd72ddf6e6..f2fb668d89 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Channels/GetChannelMessagesQuery.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Channels/GetChannelMessagesQuery.cs @@ -7,7 +7,7 @@ namespace DSharpPlus.Core.Abstractions.Rest.Queries; /// /// Contains query parameters for IChannelRestAPI.GetChannelMessagesAsync. /// -public readonly record struct GetChannelMessagesQuery : IPaginationQuery +public readonly record struct GetChannelMessagesQuery : IPaginatedQuery { /// /// If specified, request entities around this ID. diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Entitlements/ListEntitlementsQuery.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Entitlements/ListEntitlementsQuery.cs index 77bc28555f..f174e7cb6f 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Entitlements/ListEntitlementsQuery.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Entitlements/ListEntitlementsQuery.cs @@ -7,7 +7,7 @@ namespace DSharpPlus.Core.Abstractions.Rest.Queries; /// /// Contains the query parameters to IEntitlementsRestAPI.ListEntitlementsAsync. /// -public readonly record struct ListEntitlementsQuery : IPaginationQuery +public readonly record struct ListEntitlementsQuery : IPaginatedQuery { /// public Snowflake? Before { get; init; } diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Channels/GetReactionsQuery.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/ForwardsPaginatedQuery.cs similarity index 56% rename from src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Channels/GetReactionsQuery.cs rename to src/core/DSharpPlus.Core.Abstractions.Rest/Queries/ForwardsPaginatedQuery.cs index 0cb95f37b2..b390fcf748 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Channels/GetReactionsQuery.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/ForwardsPaginatedQuery.cs @@ -4,18 +4,15 @@ namespace DSharpPlus.Core.Abstractions.Rest.Queries; -/// -/// Contains the query parameters for IChannelRestAPI.GetReactionsAsync. -/// -public readonly record struct GetReactionsQuery +public readonly record struct ForwardsPaginatedQuery { /// - /// If specified, only request reactions from users with an ID greater than this ID. + /// If specified, only request entities with an ID greater than this ID. /// public Snowflake? After { get; init; } /// - /// The maximum number of reactions for this request, up to 25. + /// The maximum number of entities to return from this request. /// public int? Limit { get; init; } } \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Guilds/BanMemberQuery.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Guilds/BanMemberQuery.cs new file mode 100644 index 0000000000..6a7a4bebff --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Guilds/BanMemberQuery.cs @@ -0,0 +1,14 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Core.Abstractions.Rest.Queries; + +public readonly record struct BanMemberQuery +{ + /// + /// Specifies how many seconds worth of message history should be deleted along with this ban. + /// This allows up to 7 days, or 604800 seconds. + /// + public int? DeleteMessageSeconds { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Guilds/BeginGuildPruneQuery.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Guilds/BeginGuildPruneQuery.cs new file mode 100644 index 0000000000..11f89343bd --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Guilds/BeginGuildPruneQuery.cs @@ -0,0 +1,30 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Core.Abstractions.Rest.Queries; + +/// +/// Contains the query parameters for IGuildRestAPI.BeginGuildPruneAsync. +/// +public readonly record struct BeginGuildPruneQuery +{ + /// + /// The days of inactivity to measure, from 0 to 30. + /// + public int? Days { get; init; } + + /// + /// A comma-separated list of snowflake identifiers of roles to include in the prune. + /// + /// + /// Any user with a subset of these roles will be considered for the prune. Any user with any role + /// not listed here will not be included in the count. + /// + public string? IncludeRoles { get; init; } + + /// + /// Specifies whether the amount of users pruned should be computed and returned. + /// + public bool? ComputeCount { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Guilds/GetGuildPruneCountQuery.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Guilds/GetGuildPruneCountQuery.cs new file mode 100644 index 0000000000..f35dea5bfb --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Guilds/GetGuildPruneCountQuery.cs @@ -0,0 +1,25 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Core.Abstractions.Rest.Queries; + +/// +/// Contains the query parameters for IGuildRestAPI.GetGuildPruneCountAsync. +/// +public readonly record struct GetGuildPruneCountQuery +{ + /// + /// The days of inactivity to measure, from 0 to 30. + /// + public int? Days { get; init; } + + /// + /// A comma-separated list of snowflake identifiers of roles to include in the prune. + /// + /// + /// Any user with a subset of these roles will be considered for the prune. Any user with any role + /// not listed here will not be included in the count. + /// + public string? IncludeRoles { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Guilds/GetGuildQuery.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Guilds/GetGuildQuery.cs new file mode 100644 index 0000000000..6cea1d5e82 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Guilds/GetGuildQuery.cs @@ -0,0 +1,16 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Core.Abstractions.Rest.Queries; + +/// +/// Contains query parameters for IGuildRestAPI.GetGuildAsync. +/// +public readonly record struct GetGuildQuery +{ + /// + /// Specifies whether the response should include online member counts. + /// + public bool? WithCounts { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Guilds/SearchGuildMembersQuery.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Guilds/SearchGuildMembersQuery.cs new file mode 100644 index 0000000000..479637ecb6 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Guilds/SearchGuildMembersQuery.cs @@ -0,0 +1,17 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Core.Abstractions.Rest.Queries; + +/// +/// Contains the query parameters to IGuildRestAPI.SearchGuildMembersAsync. This request cannot +/// be paginated. +/// +public readonly record struct SearchGuildMembersQuery +{ + /// + /// The amount of guild members to return. + /// + public int? Limit { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/IPaginationQuery.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/IPaginatedQuery.cs similarity index 96% rename from src/core/DSharpPlus.Core.Abstractions.Rest/Queries/IPaginationQuery.cs rename to src/core/DSharpPlus.Core.Abstractions.Rest/Queries/IPaginatedQuery.cs index 5f406c7772..e8b0ab45f8 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/IPaginationQuery.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/IPaginatedQuery.cs @@ -10,7 +10,7 @@ namespace DSharpPlus.Core.Abstractions.Rest.Queries; // this is here despite not being technically necessary to accurately implement queries because // as of now, it can't go anywhere else. we'll move this once possible, using explicit extensions // acting as interface adapters. -public interface IPaginationQuery +public interface IPaginatedQuery { /// /// If specified, only request entities with an ID less than this ID. diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/PaginatedQuery.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/PaginatedQuery.cs new file mode 100644 index 0000000000..11d783454d --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/PaginatedQuery.cs @@ -0,0 +1,20 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Core.Abstractions.Rest.Queries; + +/// +/// Contains the query parameters for all purely snowflake-paginated requests. +/// +public readonly record struct PaginatedQuery : IPaginatedQuery +{ + /// + public Snowflake? Before { get; init; } + + /// + public Snowflake? After { get; init; } + + /// + public int? Limit { get; init; } +} \ No newline at end of file From 2218d662283fb7bd6b280af4688d13adc6dfe759 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Fri, 29 Dec 2023 22:24:30 +0100 Subject: [PATCH 235/323] wrap scheduled event query parameters --- .../API/IGuildScheduledEventRestAPI.cs | 20 +++++--------- .../GetScheduledEventUsersQuery.cs | 26 +++++++++++++++++++ .../ScheduledEvents/WithUserCountQuery.cs | 16 ++++++++++++ 3 files changed, 49 insertions(+), 13 deletions(-) create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/Queries/ScheduledEvents/GetScheduledEventUsersQuery.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/Queries/ScheduledEvents/WithUserCountQuery.cs diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IGuildScheduledEventRestAPI.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IGuildScheduledEventRestAPI.cs index efd35bc96e..f27b9c63ff 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IGuildScheduledEventRestAPI.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IGuildScheduledEventRestAPI.cs @@ -8,7 +8,7 @@ using DSharpPlus.Core.Abstractions.Models; using DSharpPlus.Core.Abstractions.Rest.Payloads; - +using DSharpPlus.Core.Abstractions.Rest.Queries; using Remora.Results; namespace DSharpPlus.Core.Abstractions.Rest.API; @@ -22,13 +22,13 @@ public interface IGuildScheduledEventRestAPI /// Returns a list of scheduled events taking place in this guild. /// /// The snowflake identifier of the guild in question. - /// Whether the answer should include user counts. + /// Specifies whether the answer should include user counts. /// Additional instructions regarding this request. /// A cancellation token for this operation. public ValueTask>> ListScheduledEventsForGuildAsync ( Snowflake guildId, - bool? withUserCount = null, + WithUserCountQuery query = default, RequestInfo info = default, CancellationToken ct = default ); @@ -56,7 +56,7 @@ public ValueTask> CreateGuildScheduledEventAsync /// /// The snowflake identifier of the guild this scheduled event takes place in. /// The snowflake identifier of the scheduled event in qeustion. - /// + /// /// Specifies whether the number of users subscribed to this event should be included. /// /// Additional instructions regarding this request. @@ -65,7 +65,7 @@ public ValueTask> GetScheduledEventAsync ( Snowflake guildId, Snowflake eventId, - bool? withUserCount = null, + WithUserCountQuery query = default, RequestInfo info = default, CancellationToken ct = default ); @@ -111,20 +111,14 @@ public ValueTask DeleteScheduledEventAsync /// /// The snowflake identifier of the guild this scheduled event belongs to. /// The snowflake identifier of the scheduled event in question. - /// Number of users to return. - /// Specifies whether the response should include guild member data. - /// Only return users before the given snowflake ID, used for pagination. - /// Only return users after the given snowflake ID, used for pagination. + /// Additional information regarding request pagination and member data in the response. /// Additional instructions regarding this request. /// A cancellation token for this operation. public ValueTask>> GetScheduledEventUsersAsync ( Snowflake guildId, Snowflake eventId, - int? limit = null, - bool? withMember = null, - Snowflake? before = null, - Snowflake? after = null, + GetScheduledEventUsersQuery query = default, RequestInfo info = default, CancellationToken ct = default ); diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/ScheduledEvents/GetScheduledEventUsersQuery.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/ScheduledEvents/GetScheduledEventUsersQuery.cs new file mode 100644 index 0000000000..70d4ad35d6 --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/ScheduledEvents/GetScheduledEventUsersQuery.cs @@ -0,0 +1,26 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + + +namespace DSharpPlus.Core.Abstractions.Rest.Queries; + +/// +/// Contains the query parameters to IGuildScheduledEventRestAPI.GetScheduledEventUsersAsync. +/// +public readonly record struct GetScheduledEventUsersQuery : IPaginatedQuery +{ + /// + public Snowflake? Before { get; init; } + + /// + public Snowflake? After { get; init; } + + /// + public int? Limit { get; init; } + + /// + /// Specifies whether the response should include guild member data. + /// + public bool? WithMember { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/ScheduledEvents/WithUserCountQuery.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/ScheduledEvents/WithUserCountQuery.cs new file mode 100644 index 0000000000..6fffea557e --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/ScheduledEvents/WithUserCountQuery.cs @@ -0,0 +1,16 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Core.Abstractions.Rest.Queries; + +/// +/// Contains the query parameters for scheduled events that may be returned with user counts. +/// +public readonly record struct WithUserCountQuery +{ + /// + /// Specifies whether to include user counts in the returned scheduled events. + /// + public bool? WithUserCount { get; init; } +} \ No newline at end of file From 329e34ad32d103b00fe1a5d6ebd86bc200cc23ca Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sat, 30 Dec 2023 15:52:55 +0100 Subject: [PATCH 236/323] wrap invite query parameters --- .../API/IInviteRestAPI.cs | 9 +++---- .../Queries/Invites/GetInviteQuery.cs | 26 +++++++++++++++++++ 2 files changed, 29 insertions(+), 6 deletions(-) create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Invites/GetInviteQuery.cs diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IInviteRestAPI.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IInviteRestAPI.cs index 73bbd046a9..9536190a30 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IInviteRestAPI.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IInviteRestAPI.cs @@ -6,6 +6,7 @@ using System.Threading.Tasks; using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Core.Abstractions.Rest.Queries; using Remora.Results; @@ -20,17 +21,13 @@ public interface IInviteRestAPI /// Returns the queried invite. /// /// Invite code identifying this invite. - /// Indicates whether the invite should contain approximate member counts. - /// Indicates whether the invite should contain the expiration time. - /// The scheduled event to include with the invite. + /// Specifies what additional information the invite object should contain. /// Additional instructions regarding this request. /// A cancellation token for this operation. public ValueTask> GetInviteAsync ( string inviteCode, - bool? withCounts = null, - bool? withExpiration = null, - Snowflake? guildScheduledEventId = null, + GetInviteQuery query = default, RequestInfo info = default, CancellationToken ct = default ); diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Invites/GetInviteQuery.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Invites/GetInviteQuery.cs new file mode 100644 index 0000000000..2a4e6b394b --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Invites/GetInviteQuery.cs @@ -0,0 +1,26 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Core.Abstractions.Rest.Queries; + +/// +/// Contains query parameters to IInviteRestAPI.GetInviteAsync. +/// +public readonly record struct GetInviteQuery +{ + /// + /// Specifies whether the returned invite object should include approximate member counts. + /// + public bool? WithCounts { get; init; } + + /// + /// Specifies whether the returned invite object should include the expiration date. + /// + public bool? WithExpiration { get; init; } + + /// + /// The snowflake identifier of the scheduled event to include with the invite. + /// + public Snowflake? GuildScheduledEventId { get; init; } +} \ No newline at end of file From e083c4bc21e01f29f31d0c8b580943de1e28a04e Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sat, 30 Dec 2023 15:57:34 +0100 Subject: [PATCH 237/323] wrap user queries --- .../API/IUserRestAPI.cs | 19 +++++--------- .../Users/GetCurrentUserGuildsQuery.cs | 26 +++++++++++++++++++ 2 files changed, 33 insertions(+), 12 deletions(-) create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Users/GetCurrentUserGuildsQuery.cs diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IUserRestAPI.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IUserRestAPI.cs index f59ba17199..2f2f9f96fa 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IUserRestAPI.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IUserRestAPI.cs @@ -8,7 +8,7 @@ using DSharpPlus.Core.Abstractions.Models; using DSharpPlus.Core.Abstractions.Rest.Payloads; - +using DSharpPlus.Core.Abstractions.Rest.Queries; using Remora.Results; namespace DSharpPlus.Core.Abstractions.Rest.API; @@ -64,23 +64,18 @@ public ValueTask> ModifyCurrentUserAsync /// Returns a list of partial guild objects representing the guilds the current user has joined. /// /// - /// defaults to 200 guilds, which is the maximum number of guilds an user account can join. - /// Pagination is therefore not needed for obtaining user guilds, but may be needed for obtaining bot guilds. + /// defaults to 200 guilds, which is the maximum + /// number of guilds an user account can join. Pagination is therefore not needed for obtaining user + /// guilds, but may be needed for obtaining bot guilds. /// - /// Specifies an upper bound of snowflakes to be returned. - /// Specifies a lower bound of snowflakes to be returned. - /// Maximum number of guilds to return, ranging from 1 to 200. - /// - /// Specifies whether to include approximate member and presence counts in the returned guilds. + /// + /// Specifies request pagination info, as well as whether guild objects should include member counts. /// /// Additional instructions regarding this request. /// A cancellation token for this operation. public ValueTask>> GetCurrentUserGuildsAsync ( - Snowflake? before = null, - Snowflake? after = null, - int? limit = null, - bool? withCounts = null, + GetCurrentUserGuildsQuery query = default, RequestInfo info = default, CancellationToken ct = default ); diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Users/GetCurrentUserGuildsQuery.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Users/GetCurrentUserGuildsQuery.cs new file mode 100644 index 0000000000..f3239ae3fa --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Users/GetCurrentUserGuildsQuery.cs @@ -0,0 +1,26 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + + +namespace DSharpPlus.Core.Abstractions.Rest.Queries; + +/// +/// Contains the query parameters to IUserRestAPI.GetCurrentUserGuildsAsync. +/// +public readonly record struct GetCurrentUserGuildsQuery : IPaginatedQuery +{ + /// + public Snowflake? Before { get; init; } + + /// + public Snowflake? After { get; init; } + + /// + public int? Limit { get; init; } + + /// + /// Specifies whether the returned guild objects should include approximate member counts. + /// + public bool? WithCounts { get; init; } +} \ No newline at end of file From 94a716345ae6bb992a1f888f88e1cb125a0bfd39 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sat, 30 Dec 2023 16:41:20 +0100 Subject: [PATCH 238/323] enlighten webhooks about wrapped query parameters --- .../API/IWebhookRestAPI.cs | 33 ++++++++----------- .../Queries/Webhooks/ExecuteWebhookQuery.cs | 27 +++++++++++++++ .../Queries/Webhooks/ThreadIdQuery.cs | 18 ++++++++++ 3 files changed, 58 insertions(+), 20 deletions(-) create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Webhooks/ExecuteWebhookQuery.cs create mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Webhooks/ThreadIdQuery.cs diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IWebhookRestAPI.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IWebhookRestAPI.cs index 8ba854e24d..519b5f0cce 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IWebhookRestAPI.cs +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/API/IWebhookRestAPI.cs @@ -8,7 +8,7 @@ using DSharpPlus.Core.Abstractions.Models; using DSharpPlus.Core.Abstractions.Rest.Payloads; - +using DSharpPlus.Core.Abstractions.Rest.Queries; using Remora.Results; namespace DSharpPlus.Core.Abstractions.Rest.API; @@ -175,29 +175,22 @@ public ValueTask DeleteWebhookWithTokenAsync /// The snowflake identifier of the webhook to execute. /// The webhook token of the webhook to execute. /// A payload of information on the message to send. - /// - /// Specifies whether to wait for server confirmation. If this is set to true, a - /// object will be returned, if not, will be returned on success instead. Defaults to - /// + /// + /// Specifies the waiting behaviour of the request as well as whether this webhook should post to a thread. /// - /// - /// Specifies a thread to send the message to rather than directly to the parent channel. If the thread is - /// archived, this will automatically unarchive it. Only threads with the same parent channel as the webhook - /// can be passed. - /// /// Additional instructions regarding this request. /// A cancellation token for this operation. /// - /// If was set to , a object.
- /// If was set to , . + /// If was set to , a + /// object. If was set to + /// , . ///
public ValueTask> ExecuteWebhookAsync ( Snowflake webhookId, string webhookToken, IExecuteWebhookPayload payload, - bool? wait = null, - Snowflake? threadId = null, + ExecuteWebhookQuery query = default, RequestInfo info = default, CancellationToken ct = default ); @@ -210,7 +203,7 @@ public ValueTask> ExecuteWebhookAsync /// The webhook token for your webhook. This must match the token of the original author. /// /// The snowflake identifier of the message in question. - /// + /// /// Specifies the thread to search in rather than the parent channel. Only threads with the same parent channel /// as the webhook can be passed. /// @@ -221,7 +214,7 @@ public ValueTask> GetWebhookMessageAsync Snowflake webhookId, string webhookToken, Snowflake messageId, - Snowflake? threadId = null, + ThreadIdQuery query = default, RequestInfo info = default, CancellationToken ct = default ); @@ -235,7 +228,7 @@ public ValueTask> GetWebhookMessageAsync /// /// The snowflake identifier of the message in question. /// The information to update this message with. - /// + /// /// Specifies the thread to search in rather than the parent channel. Only threads with the same parent channel /// as the webhook can be passed. /// @@ -248,7 +241,7 @@ public ValueTask> EditWebhookMessageAsync string webhookToken, Snowflake messageId, IEditWebhookMessagePayload payload, - Snowflake? threadId = null, + ThreadIdQuery query = default, RequestInfo info = default, CancellationToken ct = default ); @@ -261,7 +254,7 @@ public ValueTask> EditWebhookMessageAsync /// The webhook token for your webhook. This must match the token of the original author. /// /// The snowflake identifier of the message in question. - /// + /// /// Specifies the thread to search in rather than the parent channel. Only threads with the same parent channel /// as the webhook can be passed. /// @@ -272,7 +265,7 @@ public ValueTask DeleteWebhookMessageAsync Snowflake webhookId, string webhookToken, Snowflake messageId, - Snowflake? threadId = null, + ThreadIdQuery query = default, RequestInfo info = default, CancellationToken ct = default ); diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Webhooks/ExecuteWebhookQuery.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Webhooks/ExecuteWebhookQuery.cs new file mode 100644 index 0000000000..265917d2ff --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Webhooks/ExecuteWebhookQuery.cs @@ -0,0 +1,27 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Core.Abstractions.Models; + +namespace DSharpPlus.Core.Abstractions.Rest.Queries; + +/// +/// Contains the query parameters to IWebhookRestAPI.ExecuteWebhookAsync. +/// +public readonly record struct ExecuteWebhookQuery +{ + /// + /// Specifies whether to wait for server confirmation. If this is set to true, a + /// object will be returned, if not, will be returned on success instead. + /// Defaults to . + /// + public bool? Wait { get; init; } + + /// + /// Specifies a thread to send the message to rather than directly to the parent channel. If the thread + /// is archived, this will automatically unarchive it. Only threads with the same parent channel as the + /// webhook can be passed. + /// + public Snowflake? ThreadId { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Webhooks/ThreadIdQuery.cs b/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Webhooks/ThreadIdQuery.cs new file mode 100644 index 0000000000..001869af5b --- /dev/null +++ b/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Webhooks/ThreadIdQuery.cs @@ -0,0 +1,18 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Core.Abstractions.Rest.Queries; + +/// +/// Contains the ThreadId query parameter for webhook requests that can target a message in a thread. +/// +public readonly record struct ThreadIdQuery +{ + /// + /// Specifies a thread to search in rather than directly to the parent channel. If the thread is archived, + /// and this is an edit, this will automatically unarchive it. Only threads with the same parent channel + /// as the webhook can be passed. + /// + public Snowflake? ThreadId { get; init; } +} \ No newline at end of file From 65521fa84d16a5d1d11d18b43f53e987db843225 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sat, 30 Dec 2023 16:49:15 +0100 Subject: [PATCH 239/323] rename DSharpPlus.Core to DSharpPlus.Internal --- DSharpPlus.sln | 10 +++++----- Directory.Build.props | 16 ++++++++-------- Directory.Packages.props | 1 + .../DSharpPlus.Core.Abstractions.Rest.csproj | 16 ---------------- src/core/DSharpPlus.Core.sln | 8 ++++---- .../.editorconfig | 0 .../ApplicationCommands/IApplicationCommand.cs | 2 +- .../IApplicationCommandOption.cs | 2 +- .../IApplicationCommandOptionChoice.cs | 2 +- .../IApplicationCommandPermission.cs | 2 +- .../IApplicationCommandPermissions.cs | 2 +- .../IPartialApplicationCommandPermissions.cs | 2 +- .../Applications/IApplication.cs | 2 +- .../Applications/IInstallParameters.cs | 2 +- .../Applications/IPartialApplication.cs | 2 +- .../AuditLogs/IAuditLog.cs | 2 +- .../AuditLogs/IAuditLogChange.cs | 2 +- .../AuditLogs/IAuditLogEntry.cs | 2 +- .../AuditLogs/IAuditLogEntryInfo.cs | 2 +- .../AutoModeration/IAutoModerationAction.cs | 2 +- .../IAutoModerationActionMetadata.cs | 2 +- .../AutoModeration/IAutoModerationRule.cs | 2 +- .../IAutoModerationTriggerMetadata.cs | 2 +- .../IBlockMessageActionMetadata.cs | 2 +- .../AutoModeration/IPartialAutoModerationRule.cs | 2 +- .../ISendAlertMessageActionMetadata.cs | 2 +- .../AutoModeration/ITimeoutActionMetadata.cs | 2 +- .../Channels/IAllowedMentions.cs | 2 +- .../Channels/IAttachment.cs | 2 +- .../Channels/IChannel.cs | 2 +- .../Channels/IChannelMention.cs | 2 +- .../Channels/IChannelOverwrite.cs | 2 +- .../Channels/IDefaultReaction.cs | 2 +- .../Channels/IEmbed.cs | 2 +- .../Channels/IEmbedAuthor.cs | 2 +- .../Channels/IEmbedField.cs | 2 +- .../Channels/IEmbedFooter.cs | 2 +- .../Channels/IEmbedImage.cs | 2 +- .../Channels/IEmbedProvider.cs | 2 +- .../Channels/IEmbedThumbnail.cs | 2 +- .../Channels/IEmbedVideo.cs | 2 +- .../Channels/IFollowedChannel.cs | 2 +- .../Channels/IForumTag.cs | 2 +- .../Channels/IMessage.cs | 2 +- .../Channels/IMessageActivity.cs | 2 +- .../Channels/IMessageReference.cs | 2 +- .../Channels/IPartialAttachment.cs | 2 +- .../Channels/IPartialChannel.cs | 2 +- .../Channels/IPartialChannelOverwrite.cs | 2 +- .../Channels/IPartialMessage.cs | 2 +- .../Channels/IReaction.cs | 2 +- .../Channels/IRoleSubscriptionData.cs | 2 +- .../Channels/IThreadMember.cs | 2 +- .../Channels/IThreadMetadata.cs | 2 +- ...harpPlus.Internal.Abstractions.Models.csproj} | 2 +- .../Emojis/IEmoji.cs | 2 +- .../Emojis/IPartialEmoji.cs | 2 +- .../Entitlements/IEntitlement.cs | 2 +- .../Entitlements/IPartialEntitlement.cs | 2 +- .../GuildTemplates/ITemplate.cs | 2 +- .../Guilds/IBan.cs | 2 +- .../Guilds/IGuild.cs | 2 +- .../Guilds/IGuildMember.cs | 2 +- .../Guilds/IGuildPreview.cs | 2 +- .../Guilds/IGuildWidget.cs | 2 +- .../Guilds/IGuildWidgetSettings.cs | 2 +- .../Guilds/IIntegration.cs | 2 +- .../Guilds/IIntegrationAccount.cs | 2 +- .../Guilds/IIntegrationApplication.cs | 2 +- .../Guilds/IOnboarding.cs | 2 +- .../Guilds/IOnboardingPrompt.cs | 2 +- .../Guilds/IOnboardingPromptOption.cs | 2 +- .../Guilds/IPartialGuild.cs | 2 +- .../Guilds/IPartialGuildMember.cs | 2 +- .../Guilds/IPartialIntegration.cs | 2 +- .../Guilds/IPartialRole.cs | 2 +- .../Guilds/IRole.cs | 2 +- .../Guilds/IRoleTags.cs | 2 +- .../Guilds/IWelcomeScreen.cs | 2 +- .../Guilds/IWelcomeScreenChannel.cs | 2 +- .../IApplicationCommandInteractionData.cs | 2 +- .../IApplicationCommandInteractionDataOption.cs | 2 +- .../Interactions/IAutocompleteCallbackData.cs | 2 +- .../Interactions/IInteraction.cs | 2 +- .../Interactions/IInteractionResponse.cs | 2 +- .../Interactions/IMessageCallbackData.cs | 2 +- .../IMessageComponentInteractionData.cs | 2 +- .../Interactions/IMessageInteraction.cs | 2 +- .../Interactions/IModalCallbackData.cs | 2 +- .../Interactions/IModalInteractionData.cs | 2 +- .../Interactions/IResolvedData.cs | 2 +- .../Invites/IInvite.cs | 2 +- .../Invites/IPartialInvite.cs | 2 +- .../MessageComponents/IActionRowComponent.cs | 2 +- .../MessageComponents/IButtonComponent.cs | 2 +- .../MessageComponents/IChannelSelectComponent.cs | 2 +- .../MessageComponents/IDefaultSelectValue.cs | 2 +- .../MessageComponents/IInteractiveComponent.cs | 2 +- .../IMentionableSelectComponent.cs | 2 +- .../MessageComponents/IRoleSelectComponent.cs | 2 +- .../MessageComponents/ISelectOption.cs | 2 +- .../MessageComponents/IStringSelectComponent.cs | 2 +- .../MessageComponents/ITextInputComponent.cs | 2 +- .../MessageComponents/IUserSelectComponent.cs | 2 +- .../RoleConnections/IRoleConnectionMetadata.cs | 2 +- .../ScheduledEvents/IPartialScheduledEvent.cs | 2 +- .../ScheduledEvents/IScheduledEvent.cs | 2 +- .../ScheduledEvents/IScheduledEventMetadata.cs | 2 +- .../ScheduledEvents/IScheduledEventUser.cs | 2 +- .../Skus/ISku.cs | 2 +- .../StageInstances/IPartialStageInstance.cs | 2 +- .../StageInstances/IStageInstance.cs | 2 +- .../Stickers/IPartialSticker.cs | 2 +- .../Stickers/ISticker.cs | 2 +- .../Stickers/IStickerItem.cs | 2 +- .../Stickers/IStickerPack.cs | 2 +- .../Teams/ITeam.cs | 2 +- .../Teams/ITeamMember.cs | 2 +- .../Users/IApplicationRoleConnection.cs | 2 +- .../Users/IConnection.cs | 2 +- .../Users/IPartialUser.cs | 2 +- .../Users/IUser.cs | 2 +- .../Voice/IVoiceRegion.cs | 2 +- .../Voice/IVoiceState.cs | 2 +- .../Webhooks/IPartialWebhook.cs | 2 +- .../Webhooks/IWebhook.cs | 2 +- .../API/IApplicationCommandsRestAPI.cs | 10 +++++----- .../API/IApplicationRestAPI.cs | 6 +++--- .../API/IAuditLogsRestAPI.cs | 6 +++--- .../API/IAutoModerationRestAPI.cs | 6 +++--- .../API/IChannelRestAPI.cs | 10 +++++----- .../API/IEmojiRestAPI.cs | 6 +++--- .../API/IEntitlementsRestAPI.cs | 8 ++++---- .../API/IGuildRestAPI.cs | 10 +++++----- .../API/IGuildScheduledEventRestAPI.cs | 8 ++++---- .../API/IGuildTemplateRestAPI.cs | 6 +++--- .../API/IInteractionRestAPI.cs | 6 +++--- .../API/IInviteRestAPI.cs | 6 +++--- .../API/IRoleConnectionsRestAPI.cs | 4 ++-- .../API/ISkusRestAPI.cs | 4 ++-- .../API/IStageInstanceRestAPI.cs | 6 +++--- .../API/IStickerRestAPI.cs | 8 ++++---- .../API/IUserRestAPI.cs | 8 ++++---- .../API/IVoiceRestAPI.cs | 4 ++-- .../API/IWebhookRestAPI.cs | 8 ++++---- .../AttachmentData.cs | 2 +- .../DSharpPlus.Internal.Abstractions.Rest.csproj | 16 ++++++++++++++++ .../Errors/HttpError.cs | 2 +- .../Errors/ValidationError.cs | 2 +- .../IRatelimitCallbackInfo.cs | 2 +- .../ICreateGlobalApplicationCommandPayload.cs | 2 +- .../ICreateGuildApplicationCommandPayload.cs | 2 +- .../IEditGlobalApplicationCommandPayload.cs | 2 +- .../IEditGuildApplicationCommandPayload.cs | 2 +- .../IEditCurrentApplicationPayload.cs | 4 ++-- .../ICreateAutoModerationRulePayload.cs | 4 ++-- .../IModifyAutoModerationRulePayload.cs | 4 ++-- .../Channels/ICreateChannelInvitePayload.cs | 2 +- .../Payloads/Channels/ICreateMessagePayload.cs | 4 ++-- .../Channels/IEditChannelPermissionsPayload.cs | 2 +- .../Payloads/Channels/IEditMessagePayload.cs | 4 ++-- .../IFollowAnnouncementChannelPayload.cs | 2 +- .../Channels/IForumAndMediaThreadMessage.cs | 4 ++-- .../Channels/IGroupDMAddRecipientPayload.cs | 2 +- .../Payloads/Channels/IModifyGroupDMPayload.cs | 2 +- .../Channels/IModifyGuildChannelPayload.cs | 4 ++-- .../Channels/IModifyThreadChannelPayload.cs | 2 +- .../Channels/IStartThreadFromMessagePayload.cs | 2 +- .../IStartThreadInForumOrMediaChannelPayload.cs | 2 +- .../IStartThreadWithoutMessagePayload.cs | 2 +- .../Payloads/Emojis/ICreateGuildEmojiPayload.cs | 2 +- .../Payloads/Emojis/IModifyGuildEmojiPayload.cs | 2 +- .../ICreateTestEntitlementPayload.cs | 2 +- .../ICreateGuildFromGuildTemplatePayload.cs | 2 +- .../ICreateGuildTemplatePayload.cs | 2 +- .../IModifyGuildTemplatePayload.cs | 2 +- .../Payloads/Guilds/IAddGuildMemberPayload.cs | 2 +- .../Guilds/ICreateGuildChannelPayload.cs | 4 ++-- .../Payloads/Guilds/ICreateGuildPayload.cs | 4 ++-- .../Payloads/Guilds/ICreateGuildRolePayload.cs | 2 +- .../Guilds/IModifyCurrentMemberPayload.cs | 2 +- .../IModifyCurrentUserVoiceStatePayload.cs | 2 +- .../IModifyGuildChannelPositionsPayload.cs | 2 +- .../Payloads/Guilds/IModifyGuildMemberPayload.cs | 2 +- .../Guilds/IModifyGuildMfaLevelPayload.cs | 2 +- .../Guilds/IModifyGuildOnboardingPayload.cs | 4 ++-- .../Payloads/Guilds/IModifyGuildPayload.cs | 2 +- .../Payloads/Guilds/IModifyGuildRolePayload.cs | 2 +- .../Guilds/IModifyGuildRolePositionsPayload.cs | 2 +- .../Guilds/IModifyGuildWelcomeScreenPayload.cs | 4 ++-- .../Guilds/IModifyUserVoiceStatePayload.cs | 2 +- .../ICreateFollowupMessagePayload.cs | 4 ++-- .../Interactions/IEditFollowupMessagePayload.cs | 4 ++-- .../IEditInteractionResponsePayload.cs | 4 ++-- .../ICreateGuildScheduledEventPayload.cs | 4 ++-- .../IModifyGuildScheduledEventPayload.cs | 4 ++-- .../ICreateStageInstancePayload.cs | 2 +- .../IModifyStageInstancePayload.cs | 2 +- .../Stickers/ICreateGuildStickerPayload.cs | 2 +- .../Stickers/IModifyGuildStickerPayload.cs | 2 +- .../Payloads/Users/ICreateDmPayload.cs | 2 +- .../Payloads/Users/ICreateGroupDmPayload.cs | 2 +- .../Payloads/Users/IModifyCurrentUserPayload.cs | 2 +- ...urrentUserApplicationRoleConnectionPayload.cs | 2 +- .../Payloads/Webhooks/ICreateWebhookPayload.cs | 2 +- .../Webhooks/IEditWebhookMessagePayload.cs | 4 ++-- .../Payloads/Webhooks/IExecuteWebhookPayload.cs | 4 ++-- .../Payloads/Webhooks/IModifyWebhookPayload.cs | 2 +- .../Webhooks/IModifyWebhookWithTokenPayload.cs | 2 +- .../ApplicationCommands/LocalizationQuery.cs | 2 +- .../AuditLogs/ListGuildAuditLogEntriesQuery.cs | 2 +- .../Queries/Channels/GetChannelMessagesQuery.cs | 2 +- .../Queries/Channels/GetThreadMemberQuery.cs | 2 +- .../Queries/Channels/ListArchivedThreadsQuery.cs | 2 +- .../Queries/Channels/ListThreadMembersQuery.cs | 2 +- .../Entitlements/ListEntitlementsQuery.cs | 2 +- .../Queries/ForwardsPaginatedQuery.cs | 2 +- .../Queries/Guilds/BanMemberQuery.cs | 2 +- .../Queries/Guilds/BeginGuildPruneQuery.cs | 2 +- .../Queries/Guilds/GetGuildPruneCountQuery.cs | 2 +- .../Queries/Guilds/GetGuildQuery.cs | 2 +- .../Queries/Guilds/SearchGuildMembersQuery.cs | 2 +- .../Queries/IPaginatedQuery.cs | 2 +- .../Queries/Invites/GetInviteQuery.cs | 2 +- .../Queries/PaginatedQuery.cs | 2 +- .../GetScheduledEventUsersQuery.cs | 2 +- .../ScheduledEvents/WithUserCountQuery.cs | 2 +- .../Queries/Users/GetCurrentUserGuildsQuery.cs | 2 +- .../Queries/Webhooks/ExecuteWebhookQuery.cs | 4 ++-- .../Queries/Webhooks/ThreadIdQuery.cs | 2 +- .../RequestInfo.cs | 2 +- .../Responses/BeginGuildPruneResponse.cs | 2 +- .../CreateApplicationCommandResponse.cs | 4 ++-- .../Responses/ListActiveGuildThreadsResponse.cs | 4 ++-- .../Responses/ListArchivedThreadsResponse.cs | 4 ++-- .../Responses/ListStickerPacksResponse.cs | 4 ++-- .../RetryMode.cs | 2 +- .../ApplicationCommands/ApplicationCommand.cs | 4 ++-- .../ApplicationCommandOption.cs | 4 ++-- .../ApplicationCommandOptionChoice.cs | 4 ++-- .../ApplicationCommandPermission.cs | 4 ++-- .../ApplicationCommandPermissions.cs | 4 ++-- .../PartialApplicationCommandPermissions.cs | 4 ++-- .../Applications/Application.cs | 4 ++-- .../Applications/InstallParameters.cs | 4 ++-- .../Applications/PartialApplication.cs | 4 ++-- .../AuditLogs/AuditLog.cs | 4 ++-- .../AuditLogs/AuditLogChange.cs | 4 ++-- .../AuditLogs/AuditLogEntry.cs | 4 ++-- .../AuditLogs/AuditLogEntryInfo.cs | 4 ++-- .../AutoModeration/AutoModerationAction.cs | 4 ++-- .../AutoModerationActionMetadata.cs | 4 ++-- .../AutoModeration/AutoModerationRule.cs | 4 ++-- .../AutoModerationTriggerMetadata.cs | 4 ++-- .../AutoModeration/BlockMessageActionMetadata.cs | 4 ++-- .../AutoModeration/PartialAutoModerationRule.cs | 4 ++-- .../SendAlertMessageActionMetadata.cs | 4 ++-- .../AutoModeration/TimeoutActionMetadata.cs | 4 ++-- .../Channels/AllowedMentions.cs | 4 ++-- .../Channels/Attachment.cs | 4 ++-- .../Channels/Channel.cs | 4 ++-- .../Channels/ChannelMention.cs | 4 ++-- .../Channels/ChannelOverwrite.cs | 4 ++-- .../Channels/DefaultReaction.cs | 4 ++-- .../Channels/Embed.cs | 4 ++-- .../Channels/EmbedAuthor.cs | 4 ++-- .../Channels/EmbedField.cs | 4 ++-- .../Channels/EmbedFooter.cs | 4 ++-- .../Channels/EmbedImage.cs | 4 ++-- .../Channels/EmbedProvider.cs | 4 ++-- .../Channels/EmbedThumbnail.cs | 4 ++-- .../Channels/EmbedVideo.cs | 4 ++-- .../Channels/FollowedChannel.cs | 4 ++-- .../Channels/ForumTag.cs | 4 ++-- .../Channels/Message.cs | 4 ++-- .../Channels/MessageActivity.cs | 4 ++-- .../Channels/MessageReference.cs | 4 ++-- .../Channels/PartialAttachment.cs | 4 ++-- .../Channels/PartialChannel.cs | 4 ++-- .../Channels/PartialChannelOverwrite.cs | 4 ++-- .../Channels/PartialMessage.cs | 4 ++-- .../Channels/Reaction.cs | 4 ++-- .../Channels/RoleSubscriptionData.cs | 4 ++-- .../Channels/ThreadMember.cs | 4 ++-- .../Channels/ThreadMetadata.cs | 4 ++-- .../DSharpPlus.Internal.Models.csproj} | 4 ++-- .../Emojis/Emoji.cs | 4 ++-- .../Emojis/PartialEmoji.cs | 4 ++-- .../Entitlements/Entitlement.cs | 4 ++-- .../Entitlements/PartialEntitlement.cs | 4 ++-- .../Extensions/ServiceCollectionExtensions.cs | 8 ++++---- .../GuildTemplates/Template.cs | 4 ++-- .../Guilds/Ban.cs | 4 ++-- .../Guilds/Guild.cs | 4 ++-- .../Guilds/GuildMember.cs | 4 ++-- .../Guilds/GuildPreview.cs | 4 ++-- .../Guilds/GuildWidget.cs | 4 ++-- .../Guilds/GuildWidgetSettings.cs | 4 ++-- .../Guilds/Integration.cs | 4 ++-- .../Guilds/IntegrationAccount.cs | 4 ++-- .../Guilds/IntegrationApplication.cs | 4 ++-- .../Guilds/Onboarding.cs | 4 ++-- .../Guilds/OnboardingPrompt.cs | 4 ++-- .../Guilds/OnboardingPromptOption.cs | 4 ++-- .../Guilds/PartialGuild.cs | 4 ++-- .../Guilds/PartialGuildMember.cs | 4 ++-- .../Guilds/PartialIntegration.cs | 4 ++-- .../Guilds/PartialRole.cs | 4 ++-- .../Guilds/Role.cs | 4 ++-- .../Guilds/RoleTags.cs | 4 ++-- .../Guilds/WelcomeScreen.cs | 4 ++-- .../Guilds/WelcomeScreenChannel.cs | 4 ++-- .../ApplicationCommandInteractionData.cs | 4 ++-- .../ApplicationCommandInteractionDataOption.cs | 4 ++-- .../Interactions/AutocompleteCallbackData.cs | 4 ++-- .../Interactions/Interaction.cs | 4 ++-- .../Interactions/InteractionResponse.cs | 4 ++-- .../Interactions/MessageCallbackData.cs | 4 ++-- .../MessageComponentInteractionData.cs | 4 ++-- .../Interactions/MessageInteraction.cs | 4 ++-- .../Interactions/ModalCallbackData.cs | 4 ++-- .../Interactions/ModalInteractionData.cs | 4 ++-- .../Interactions/ResolvedData.cs | 4 ++-- .../Invites/Invite.cs | 4 ++-- .../Invites/PartialInvite.cs | 4 ++-- .../MessageComponents/ActionRowComponent.cs | 4 ++-- .../MessageComponents/ButtonComponent.cs | 4 ++-- .../MessageComponents/ChannelSelectComponent.cs | 4 ++-- .../MessageComponents/DefaultSelectValue.cs | 4 ++-- .../MessageComponents/InteractiveComponent.cs | 4 ++-- .../MentionableSelectComponent.cs | 4 ++-- .../MessageComponents/RoleSelectComponent.cs | 4 ++-- .../MessageComponents/SelectOption.cs | 4 ++-- .../MessageComponents/StringSelectComponent.cs | 4 ++-- .../MessageComponents/TextInputComponent.cs | 4 ++-- .../MessageComponents/UserSelectComponent.cs | 4 ++-- .../RoleConnections/RoleConnectionMetadata.cs | 4 ++-- .../ScheduledEvents/PartialScheduledEvent.cs | 4 ++-- .../ScheduledEvents/ScheduledEvent.cs | 4 ++-- .../ScheduledEvents/ScheduledEventMetadata.cs | 4 ++-- .../ScheduledEvents/ScheduledEventUser.cs | 4 ++-- .../Converters/AuditLogChangeConverter.cs | 4 ++-- .../Converters/AutoModerationActionConverter.cs | 4 ++-- .../Converters/DiscordPermissionConverter.cs | 2 +- .../Converters/MessageComponentConverter.cs | 4 ++-- .../Converters/NullBooleanConverter.cs | 2 +- .../Serialization/Converters/OneOfConverter.cs | 2 +- .../Converters/OneOfConverterFactory.cs | 2 +- .../Converters/OptionalConverter.cs | 2 +- .../Converters/OptionalConverterFactory.cs | 2 +- .../Converters/SnowflakeConverter.cs | 2 +- .../Resolvers/NullBooleanTypeInfoResolver.cs | 6 +++--- .../Resolvers/OptionalTypeInfoResolver.cs | 2 +- .../Skus/Sku.cs | 4 ++-- .../StageInstances/PartialStageInstance.cs | 4 ++-- .../StageInstances/StageInstance.cs | 4 ++-- .../Stickers/PartialSticker.cs | 4 ++-- .../Stickers/Sticker.cs | 4 ++-- .../Stickers/StickerItem.cs | 4 ++-- .../Stickers/StickerPack.cs | 4 ++-- .../Teams/Team.cs | 4 ++-- .../Teams/TeamMember.cs | 4 ++-- .../Users/ApplicationRoleConnection.cs | 4 ++-- .../Users/Connection.cs | 4 ++-- .../Users/PartialUser.cs | 4 ++-- .../Users/User.cs | 4 ++-- .../Voice/VoiceRegion.cs | 4 ++-- .../Voice/VoiceState.cs | 4 ++-- .../Webhooks/PartialWebhook.cs | 4 ++-- .../Webhooks/Webhook.cs | 4 ++-- .../DSharpPlus.Internal.Rest.csproj} | 2 +- .../Converters/AuditLogChangeTests.cs | 6 +++--- .../Converters/OneOfConverterTests.Models.cs | 6 +++--- .../Converters/OneOfConverterTests.Precedence.cs | 4 ++-- .../DSharpPlus.Internal.Models.Tests.csproj} | 2 +- tools/generators/generate-concrete-objects.csx | 16 ++++++++-------- 376 files changed, 612 insertions(+), 611 deletions(-) delete mode 100644 src/core/DSharpPlus.Core.Abstractions.Rest/DSharpPlus.Core.Abstractions.Rest.csproj rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/.editorconfig (100%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/ApplicationCommands/IApplicationCommand.cs (98%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/ApplicationCommands/IApplicationCommandOption.cs (98%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/ApplicationCommands/IApplicationCommandOptionChoice.cs (94%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/ApplicationCommands/IApplicationCommandPermission.cs (95%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/ApplicationCommands/IApplicationCommandPermissions.cs (96%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/ApplicationCommands/IPartialApplicationCommandPermissions.cs (95%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/Applications/IApplication.cs (97%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/Applications/IInstallParameters.cs (93%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/Applications/IPartialApplication.cs (98%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/AuditLogs/IAuditLog.cs (96%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/AuditLogs/IAuditLogChange.cs (94%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/AuditLogs/IAuditLogEntry.cs (96%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/AuditLogs/IAuditLogEntryInfo.cs (97%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/AutoModeration/IAutoModerationAction.cs (92%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/AutoModeration/IAutoModerationActionMetadata.cs (88%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/AutoModeration/IAutoModerationRule.cs (98%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/AutoModeration/IAutoModerationTriggerMetadata.cs (97%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/AutoModeration/IBlockMessageActionMetadata.cs (92%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/AutoModeration/IPartialAutoModerationRule.cs (97%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/AutoModeration/ISendAlertMessageActionMetadata.cs (92%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/AutoModeration/ITimeoutActionMetadata.cs (92%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/Channels/IAllowedMentions.cs (96%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/Channels/IAttachment.cs (96%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/Channels/IChannel.cs (93%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/Channels/IChannelMention.cs (94%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/Channels/IChannelOverwrite.cs (96%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/Channels/IDefaultReaction.cs (93%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/Channels/IEmbed.cs (97%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/Channels/IEmbedAuthor.cs (93%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/Channels/IEmbedField.cs (92%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/Channels/IEmbedFooter.cs (92%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/Channels/IEmbedImage.cs (93%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/Channels/IEmbedProvider.cs (91%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/Channels/IEmbedThumbnail.cs (93%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/Channels/IEmbedVideo.cs (93%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/Channels/IFollowedChannel.cs (92%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/Channels/IForumTag.cs (95%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/Channels/IMessage.cs (98%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/Channels/IMessageActivity.cs (92%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/Channels/IMessageReference.cs (95%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/Channels/IPartialAttachment.cs (97%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/Channels/IPartialChannel.cs (99%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/Channels/IPartialChannelOverwrite.cs (95%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/Channels/IPartialMessage.cs (99%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/Channels/IReaction.cs (93%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/Channels/IRoleSubscriptionData.cs (94%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/Channels/IThreadMember.cs (95%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/Channels/IThreadMetadata.cs (96%) rename src/core/{DSharpPlus.Core.Abstractions.Models/DSharpPlus.Core.Abstractions.Models.csproj => DSharpPlus.Internal.Abstractions.Models/DSharpPlus.Internal.Abstractions.Models.csproj} (87%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/Emojis/IEmoji.cs (93%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/Emojis/IPartialEmoji.cs (96%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/Entitlements/IEntitlement.cs (95%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/Entitlements/IPartialEntitlement.cs (97%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/GuildTemplates/ITemplate.cs (97%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/Guilds/IBan.cs (90%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/Guilds/IGuild.cs (99%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/Guilds/IGuildMember.cs (96%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/Guilds/IGuildPreview.cs (97%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/Guilds/IGuildWidget.cs (95%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/Guilds/IGuildWidgetSettings.cs (91%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/Guilds/IIntegration.cs (96%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/Guilds/IIntegrationAccount.cs (91%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/Guilds/IIntegrationApplication.cs (94%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/Guilds/IOnboarding.cs (95%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/Guilds/IOnboardingPrompt.cs (96%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/Guilds/IOnboardingPromptOption.cs (97%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/Guilds/IPartialGuild.cs (99%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/Guilds/IPartialGuildMember.cs (97%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/Guilds/IPartialIntegration.cs (98%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/Guilds/IPartialRole.cs (97%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/Guilds/IRole.cs (97%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/Guilds/IRoleTags.cs (96%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/Guilds/IWelcomeScreen.cs (93%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/Guilds/IWelcomeScreenChannel.cs (95%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/Interactions/IApplicationCommandInteractionData.cs (96%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/Interactions/IApplicationCommandInteractionDataOption.cs (96%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/Interactions/IAutocompleteCallbackData.cs (91%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/Interactions/IInteraction.cs (98%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/Interactions/IInteractionResponse.cs (93%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/Interactions/IMessageCallbackData.cs (96%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/Interactions/IMessageComponentInteractionData.cs (95%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/Interactions/IMessageInteraction.cs (95%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/Interactions/IModalCallbackData.cs (94%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/Interactions/IModalInteractionData.cs (92%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/Interactions/IResolvedData.cs (96%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/Invites/IInvite.cs (93%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/Invites/IPartialInvite.cs (98%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/MessageComponents/IActionRowComponent.cs (93%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/MessageComponents/IButtonComponent.cs (96%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/MessageComponents/IChannelSelectComponent.cs (97%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/MessageComponents/IDefaultSelectValue.cs (92%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/MessageComponents/IInteractiveComponent.cs (86%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/MessageComponents/IMentionableSelectComponent.cs (97%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/MessageComponents/IRoleSelectComponent.cs (96%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/MessageComponents/ISelectOption.cs (95%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/MessageComponents/IStringSelectComponent.cs (96%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/MessageComponents/ITextInputComponent.cs (97%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/MessageComponents/IUserSelectComponent.cs (96%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/RoleConnections/IRoleConnectionMetadata.cs (96%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/ScheduledEvents/IPartialScheduledEvent.cs (98%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/ScheduledEvents/IScheduledEvent.cs (97%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/ScheduledEvents/IScheduledEventMetadata.cs (90%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/ScheduledEvents/IScheduledEventUser.cs (94%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/Skus/ISku.cs (95%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/StageInstances/IPartialStageInstance.cs (96%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/StageInstances/IStageInstance.cs (96%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/Stickers/IPartialSticker.cs (97%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/Stickers/ISticker.cs (96%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/Stickers/IStickerItem.cs (93%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/Stickers/IStickerPack.cs (96%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/Teams/ITeam.cs (95%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/Teams/ITeamMember.cs (95%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/Users/IApplicationRoleConnection.cs (94%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/Users/IConnection.cs (97%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/Users/IPartialUser.cs (98%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/Users/IUser.cs (96%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/Voice/IVoiceRegion.cs (95%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/Voice/IVoiceState.cs (97%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/Webhooks/IPartialWebhook.cs (97%) rename src/core/{DSharpPlus.Core.Abstractions.Models => DSharpPlus.Internal.Abstractions.Models}/Webhooks/IWebhook.cs (96%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/API/IApplicationCommandsRestAPI.cs (98%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/API/IApplicationRestAPI.cs (90%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/API/IAuditLogsRestAPI.cs (89%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/API/IAutoModerationRestAPI.cs (96%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/API/IChannelRestAPI.cs (99%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/API/IEmojiRestAPI.cs (96%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/API/IEntitlementsRestAPI.cs (93%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/API/IGuildRestAPI.cs (99%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/API/IGuildScheduledEventRestAPI.cs (96%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/API/IGuildTemplateRestAPI.cs (97%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/API/IInteractionRestAPI.cs (97%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/API/IInviteRestAPI.cs (91%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/API/IRoleConnectionsRestAPI.cs (94%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/API/ISkusRestAPI.cs (92%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/API/IStageInstanceRestAPI.cs (95%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/API/IStickerRestAPI.cs (95%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/API/IUserRestAPI.cs (97%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/API/IVoiceRestAPI.cs (90%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/API/IWebhookRestAPI.cs (98%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/AttachmentData.cs (94%) create mode 100644 src/core/DSharpPlus.Internal.Abstractions.Rest/DSharpPlus.Internal.Abstractions.Rest.csproj rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/Errors/HttpError.cs (95%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/Errors/ValidationError.cs (91%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/IRatelimitCallbackInfo.cs (96%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/Payloads/ApplicationCommands/ICreateGlobalApplicationCommandPayload.cs (96%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/Payloads/ApplicationCommands/ICreateGuildApplicationCommandPayload.cs (96%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/Payloads/ApplicationCommands/IEditGlobalApplicationCommandPayload.cs (96%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/Payloads/ApplicationCommands/IEditGuildApplicationCommandPayload.cs (96%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/Payloads/Applications/IEditCurrentApplicationPayload.cs (94%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/Payloads/AutoModeration/ICreateAutoModerationRulePayload.cs (94%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/Payloads/AutoModeration/IModifyAutoModerationRulePayload.cs (93%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/Payloads/Channels/ICreateChannelInvitePayload.cs (96%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/Payloads/Channels/ICreateMessagePayload.cs (95%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/Payloads/Channels/IEditChannelPermissionsPayload.cs (93%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/Payloads/Channels/IEditMessagePayload.cs (94%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/Payloads/Channels/IFollowAnnouncementChannelPayload.cs (90%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/Payloads/Channels/IForumAndMediaThreadMessage.cs (93%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/Payloads/Channels/IGroupDMAddRecipientPayload.cs (91%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/Payloads/Channels/IModifyGroupDMPayload.cs (91%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/Payloads/Channels/IModifyGuildChannelPayload.cs (97%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/Payloads/Channels/IModifyThreadChannelPayload.cs (96%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/Payloads/Channels/IStartThreadFromMessagePayload.cs (93%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/Payloads/Channels/IStartThreadInForumOrMediaChannelPayload.cs (95%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/Payloads/Channels/IStartThreadWithoutMessagePayload.cs (95%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/Payloads/Emojis/ICreateGuildEmojiPayload.cs (92%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/Payloads/Emojis/IModifyGuildEmojiPayload.cs (92%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/Payloads/Entitlements/ICreateTestEntitlementPayload.cs (93%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/Payloads/GuildTemplates/ICreateGuildFromGuildTemplatePayload.cs (91%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/Payloads/GuildTemplates/ICreateGuildTemplatePayload.cs (91%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/Payloads/GuildTemplates/IModifyGuildTemplatePayload.cs (91%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/Payloads/Guilds/IAddGuildMemberPayload.cs (94%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/Payloads/Guilds/ICreateGuildChannelPayload.cs (96%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/Payloads/Guilds/ICreateGuildPayload.cs (96%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/Payloads/Guilds/ICreateGuildRolePayload.cs (96%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/Payloads/Guilds/IModifyCurrentMemberPayload.cs (89%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/Payloads/Guilds/IModifyCurrentUserVoiceStatePayload.cs (93%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/Payloads/Guilds/IModifyGuildChannelPositionsPayload.cs (94%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/Payloads/Guilds/IModifyGuildMemberPayload.cs (95%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/Payloads/Guilds/IModifyGuildMfaLevelPayload.cs (89%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/Payloads/Guilds/IModifyGuildOnboardingPayload.cs (90%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/Payloads/Guilds/IModifyGuildPayload.cs (98%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/Payloads/Guilds/IModifyGuildRolePayload.cs (96%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/Payloads/Guilds/IModifyGuildRolePositionsPayload.cs (91%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/Payloads/Guilds/IModifyGuildWelcomeScreenPayload.cs (89%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/Payloads/Guilds/IModifyUserVoiceStatePayload.cs (91%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/Payloads/Interactions/ICreateFollowupMessagePayload.cs (94%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/Payloads/Interactions/IEditFollowupMessagePayload.cs (92%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/Payloads/Interactions/IEditInteractionResponsePayload.cs (92%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/Payloads/ScheduledEvents/ICreateGuildScheduledEventPayload.cs (94%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/Payloads/ScheduledEvents/IModifyGuildScheduledEventPayload.cs (95%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/Payloads/StageInstances/ICreateStageInstancePayload.cs (95%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/Payloads/StageInstances/IModifyStageInstancePayload.cs (92%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/Payloads/Stickers/ICreateGuildStickerPayload.cs (93%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/Payloads/Stickers/IModifyGuildStickerPayload.cs (92%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/Payloads/Users/ICreateDmPayload.cs (89%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/Payloads/Users/ICreateGroupDmPayload.cs (92%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/Payloads/Users/IModifyCurrentUserPayload.cs (93%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/Payloads/Users/IUpdateCurrentUserApplicationRoleConnectionPayload.cs (93%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/Payloads/Webhooks/ICreateWebhookPayload.cs (95%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/Payloads/Webhooks/IEditWebhookMessagePayload.cs (93%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/Payloads/Webhooks/IExecuteWebhookPayload.cs (95%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/Payloads/Webhooks/IModifyWebhookPayload.cs (92%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/Payloads/Webhooks/IModifyWebhookWithTokenPayload.cs (91%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/Queries/ApplicationCommands/LocalizationQuery.cs (91%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/Queries/AuditLogs/ListGuildAuditLogEntriesQuery.cs (95%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/Queries/Channels/GetChannelMessagesQuery.cs (95%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/Queries/Channels/GetThreadMemberQuery.cs (90%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/Queries/Channels/ListArchivedThreadsQuery.cs (92%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/Queries/Channels/ListThreadMembersQuery.cs (93%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/Queries/Entitlements/ListEntitlementsQuery.cs (95%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/Queries/ForwardsPaginatedQuery.cs (90%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/Queries/Guilds/BanMemberQuery.cs (89%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/Queries/Guilds/BeginGuildPruneQuery.cs (94%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/Queries/Guilds/GetGuildPruneCountQuery.cs (93%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/Queries/Guilds/GetGuildQuery.cs (89%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/Queries/Guilds/SearchGuildMembersQuery.cs (90%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/Queries/IPaginatedQuery.cs (94%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/Queries/Invites/GetInviteQuery.cs (93%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/Queries/PaginatedQuery.cs (90%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/Queries/ScheduledEvents/GetScheduledEventUsersQuery.cs (93%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/Queries/ScheduledEvents/WithUserCountQuery.cs (90%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/Queries/Users/GetCurrentUserGuildsQuery.cs (93%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/Queries/Webhooks/ExecuteWebhookQuery.cs (90%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/Queries/Webhooks/ThreadIdQuery.cs (92%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/RequestInfo.cs (97%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/Responses/BeginGuildPruneResponse.cs (90%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/Responses/CreateApplicationCommandResponse.cs (87%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/Responses/ListActiveGuildThreadsResponse.cs (88%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/Responses/ListArchivedThreadsResponse.cs (89%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/Responses/ListStickerPacksResponse.cs (83%) rename src/core/{DSharpPlus.Core.Abstractions.Rest => DSharpPlus.Internal.Abstractions.Rest}/RetryMode.cs (97%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/ApplicationCommands/ApplicationCommand.cs (94%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/ApplicationCommands/ApplicationCommandOption.cs (95%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/ApplicationCommands/ApplicationCommandOptionChoice.cs (88%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/ApplicationCommands/ApplicationCommandPermission.cs (87%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/ApplicationCommands/ApplicationCommandPermissions.cs (89%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/ApplicationCommands/PartialApplicationCommandPermissions.cs (89%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/Applications/Application.cs (96%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/Applications/InstallParameters.cs (86%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/Applications/PartialApplication.cs (96%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/AuditLogs/AuditLog.cs (93%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/AuditLogs/AuditLogChange.cs (86%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/AuditLogs/AuditLogEntry.cs (91%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/AuditLogs/AuditLogEntryInfo.cs (93%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/AutoModeration/AutoModerationAction.cs (86%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/AutoModeration/AutoModerationActionMetadata.cs (83%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/AutoModeration/AutoModerationRule.cs (94%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/AutoModeration/AutoModerationTriggerMetadata.cs (92%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/AutoModeration/BlockMessageActionMetadata.cs (84%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/AutoModeration/PartialAutoModerationRule.cs (94%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/AutoModeration/SendAlertMessageActionMetadata.cs (84%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/AutoModeration/TimeoutActionMetadata.cs (83%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/Channels/AllowedMentions.cs (88%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/Channels/Attachment.cs (93%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/Channels/Channel.cs (97%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/Channels/ChannelMention.cs (88%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/Channels/ChannelOverwrite.cs (88%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/Channels/DefaultReaction.cs (83%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/Channels/Embed.cs (94%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/Channels/EmbedAuthor.cs (87%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/Channels/EmbedField.cs (85%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/Channels/EmbedFooter.cs (85%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/Channels/EmbedImage.cs (87%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/Channels/EmbedProvider.cs (83%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/Channels/EmbedThumbnail.cs (87%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/Channels/EmbedVideo.cs (87%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/Channels/FollowedChannel.cs (84%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/Channels/ForumTag.cs (88%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/Channels/Message.cs (97%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/Channels/MessageActivity.cs (85%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/Channels/MessageReference.cs (88%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/Channels/PartialAttachment.cs (94%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/Channels/PartialChannel.cs (97%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/Channels/PartialChannelOverwrite.cs (89%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/Channels/PartialMessage.cs (97%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/Channels/Reaction.cs (85%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/Channels/RoleSubscriptionData.cs (88%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/Channels/ThreadMember.cs (89%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/Channels/ThreadMetadata.cs (90%) rename src/core/{DSharpPlus.Core.Models/DSharpPlus.Core.Models.csproj => DSharpPlus.Internal.Models/DSharpPlus.Internal.Models.csproj} (63%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/Emojis/Emoji.cs (91%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/Emojis/PartialEmoji.cs (91%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/Entitlements/Entitlement.cs (92%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/Entitlements/PartialEntitlement.cs (92%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/Extensions/ServiceCollectionExtensions.cs (97%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/GuildTemplates/Template.cs (93%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/Guilds/Ban.cs (82%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/Guilds/Guild.cs (97%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/Guilds/GuildMember.cs (94%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/Guilds/GuildPreview.cs (93%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/Guilds/GuildWidget.cs (90%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/Guilds/GuildWidgetSettings.cs (84%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/Guilds/Integration.cs (95%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/Guilds/IntegrationAccount.cs (84%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/Guilds/IntegrationApplication.cs (88%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/Guilds/Onboarding.cs (90%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/Guilds/OnboardingPrompt.cs (91%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/Guilds/OnboardingPromptOption.cs (92%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/Guilds/PartialGuild.cs (97%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/Guilds/PartialGuildMember.cs (94%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/Guilds/PartialIntegration.cs (95%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/Guilds/PartialRole.cs (93%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/Guilds/Role.cs (93%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/Guilds/RoleTags.cs (90%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/Guilds/WelcomeScreen.cs (85%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/Guilds/WelcomeScreenChannel.cs (87%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/Interactions/ApplicationCommandInteractionData.cs (92%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/Interactions/ApplicationCommandInteractionDataOption.cs (91%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/Interactions/AutocompleteCallbackData.cs (85%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/Interactions/Interaction.cs (95%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/Interactions/InteractionResponse.cs (87%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/Interactions/MessageCallbackData.cs (92%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/Interactions/MessageComponentInteractionData.cs (90%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/Interactions/MessageInteraction.cs (89%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/Interactions/ModalCallbackData.cs (87%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/Interactions/ModalInteractionData.cs (86%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/Interactions/ResolvedData.cs (92%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/Invites/Invite.cs (94%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/Invites/PartialInvite.cs (95%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/MessageComponents/ActionRowComponent.cs (87%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/MessageComponents/ButtonComponent.cs (91%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/MessageComponents/ChannelSelectComponent.cs (92%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/MessageComponents/DefaultSelectValue.cs (84%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/MessageComponents/InteractiveComponent.cs (82%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/MessageComponents/MentionableSelectComponent.cs (91%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/MessageComponents/RoleSelectComponent.cs (91%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/MessageComponents/SelectOption.cs (88%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/MessageComponents/StringSelectComponent.cs (91%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/MessageComponents/TextInputComponent.cs (92%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/MessageComponents/UserSelectComponent.cs (91%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/RoleConnections/RoleConnectionMetadata.cs (91%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/ScheduledEvents/PartialScheduledEvent.cs (94%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/ScheduledEvents/ScheduledEvent.cs (94%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/ScheduledEvents/ScheduledEventMetadata.cs (82%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/ScheduledEvents/ScheduledEventUser.cs (86%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/Serialization/Converters/AuditLogChangeConverter.cs (95%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/Serialization/Converters/AutoModerationActionConverter.cs (96%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/Serialization/Converters/DiscordPermissionConverter.cs (95%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/Serialization/Converters/MessageComponentConverter.cs (97%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/Serialization/Converters/NullBooleanConverter.cs (96%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/Serialization/Converters/OneOfConverter.cs (99%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/Serialization/Converters/OneOfConverterFactory.cs (93%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/Serialization/Converters/OptionalConverter.cs (93%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/Serialization/Converters/OptionalConverterFactory.cs (93%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/Serialization/Converters/SnowflakeConverter.cs (93%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/Serialization/Resolvers/NullBooleanTypeInfoResolver.cs (85%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/Serialization/Resolvers/OptionalTypeInfoResolver.cs (96%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/Skus/Sku.cs (89%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/StageInstances/PartialStageInstance.cs (90%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/StageInstances/StageInstance.cs (90%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/Stickers/PartialSticker.cs (93%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/Stickers/Sticker.cs (93%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/Stickers/StickerItem.cs (86%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/Stickers/StickerPack.cs (91%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/Teams/Team.cs (88%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/Teams/TeamMember.cs (89%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/Users/ApplicationRoleConnection.cs (87%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/Users/Connection.cs (93%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/Users/PartialUser.cs (95%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/Users/User.cs (94%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/Voice/VoiceRegion.cs (88%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/Voice/VoiceState.cs (93%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/Webhooks/PartialWebhook.cs (93%) rename src/core/{DSharpPlus.Core.Models => DSharpPlus.Internal.Models}/Webhooks/Webhook.cs (93%) rename src/core/{DSharpPlus.Core.Rest/DSharpPlus.Core.Rest.csproj => DSharpPlus.Internal.Rest/DSharpPlus.Internal.Rest.csproj} (55%) rename tests/core/{DSharpPlus.Core.Models.Tests => DSharpPlus.Internal.Models.Tests}/Converters/AuditLogChangeTests.cs (95%) rename tests/core/{DSharpPlus.Core.Models.Tests => DSharpPlus.Internal.Models.Tests}/Converters/OneOfConverterTests.Models.cs (94%) rename tests/core/{DSharpPlus.Core.Models.Tests => DSharpPlus.Internal.Models.Tests}/Converters/OneOfConverterTests.Precedence.cs (95%) rename tests/core/{DSharpPlus.Core.Models.Tests/DSharpPlus.Core.Models.Tests.csproj => DSharpPlus.Internal.Models.Tests/DSharpPlus.Internal.Models.Tests.csproj} (88%) diff --git a/DSharpPlus.sln b/DSharpPlus.sln index df0e749b98..6e06391542 100644 --- a/DSharpPlus.sln +++ b/DSharpPlus.sln @@ -3,11 +3,11 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.0.31903.59 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DSharpPlus.Core.Models", "src\core\DSharpPlus.Core.Models\DSharpPlus.Core.Models.csproj", "{FBCCE5A7-0E07-4FCF-B9BB-B913F5A17FB2}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DSharpPlus.Internal.Models", "src\core\DSharpPlus.Internal.Models\DSharpPlus.Internal.Models.csproj", "{FBCCE5A7-0E07-4FCF-B9BB-B913F5A17FB2}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DSharpPlus.Shared", "src\core\DSharpPlus.Shared\DSharpPlus.Shared.csproj", "{964AD252-F077-4AB5-8D92-6C594D08F078}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DSharpPlus.Core.Abstractions.Models", "src\core\DSharpPlus.Core.Abstractions.Models\DSharpPlus.Core.Abstractions.Models.csproj", "{E14B0AE9-FE71-4DE4-BEB1-4A8E139DB84C}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DSharpPlus.Internal.Abstractions.Models", "src\core\DSharpPlus.Internal.Abstractions.Models\DSharpPlus.Internal.Abstractions.Models.csproj", "{E14B0AE9-FE71-4DE4-BEB1-4A8E139DB84C}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Core", "Core", "{BC8D8750-48A4-49EF-9D1F-BE4DBA5B500E}" EndProject @@ -19,11 +19,11 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Generators", "Generators", EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DSharpPlus.SourceGenerators.Common", "gen\common\DSharpPlus.SourceGenerators.Common.csproj", "{98D2C52C-E3BA-4564-919C-750775B7BA9C}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DSharpPlus.Core.Models.Tests", "tests\core\DSharpPlus.Core.Models.Tests\DSharpPlus.Core.Models.Tests.csproj", "{9F25D892-3CB0-4D47-B67D-D3FFFADC03E0}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DSharpPlus.Internal.Models.Tests", "tests\core\DSharpPlus.Internal.Models.Tests\DSharpPlus.Internal.Models.Tests.csproj", "{9F25D892-3CB0-4D47-B67D-D3FFFADC03E0}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DSharpPlus.Core.Abstractions.Rest", "src\core\DSharpPlus.Core.Abstractions.Rest\DSharpPlus.Core.Abstractions.Rest.csproj", "{CD440954-E19A-4E94-A217-CCC1DC4AF095}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DSharpPlus.Internal.Abstractions.Rest", "src\core\DSharpPlus.Internal.Abstractions.Rest\DSharpPlus.Internal.Abstractions.Rest.csproj", "{CD440954-E19A-4E94-A217-CCC1DC4AF095}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DSharpPlus.Core.Rest", "src\core\DSharpPlus.Core.Rest\DSharpPlus.Core.Rest.csproj", "{9CEC3D27-9014-48B6-910F-D25233BF8C44}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DSharpPlus.Internal.Rest", "src\core\DSharpPlus.Internal.Rest\DSharpPlus.Internal.Rest.csproj", "{9CEC3D27-9014-48B6-910F-D25233BF8C44}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/Directory.Build.props b/Directory.Build.props index 55ae534343..242b47ece3 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -36,17 +36,17 @@ <_DSharpPlusReleaseVersion>6.0.0 - - <_DSharpPlusCoreAbstractionsModelsVersion>0.1.0 + + <_DSharpPlusInternalAbstractionsModelsVersion>0.1.0 - - <_DSharpPlusCoreModelsVersion>0.1.0 + + <_DSharpPlusInternalModelsVersion>0.1.0 - - <_DSharpPlusCoreAbstractionsRestVersion>0.1.0 + + <_DSharpPlusInternalAbstractionsRestVersion>0.1.0 - - <_DSharpPlusCoreRestVersion>0.1.0 + + <_DSharpPlusInternalRestVersion>0.1.0 \ No newline at end of file diff --git a/Directory.Packages.props b/Directory.Packages.props index 79ade2072c..ae0311f80f 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -1,6 +1,7 @@ + diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/DSharpPlus.Core.Abstractions.Rest.csproj b/src/core/DSharpPlus.Core.Abstractions.Rest/DSharpPlus.Core.Abstractions.Rest.csproj deleted file mode 100644 index e950a62df5..0000000000 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/DSharpPlus.Core.Abstractions.Rest.csproj +++ /dev/null @@ -1,16 +0,0 @@ - - - - $(_DSharpPlusCoreAbstractionsRestVersion) - - - - - - - - - - - - diff --git a/src/core/DSharpPlus.Core.sln b/src/core/DSharpPlus.Core.sln index 7a84a3e456..ac0da204da 100644 --- a/src/core/DSharpPlus.Core.sln +++ b/src/core/DSharpPlus.Core.sln @@ -3,15 +3,15 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.0.31903.59 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DSharpPlus.Core.Abstractions.Models", "DSharpPlus.Core.Abstractions.Models\DSharpPlus.Core.Abstractions.Models.csproj", "{AF8283F9-AC6C-46AB-A4FC-D331C64BFFC9}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DSharpPlus.Internal.Abstractions.Models", "DSharpPlus.Internal.Abstractions.Models\DSharpPlus.Internal.Abstractions.Models.csproj", "{AF8283F9-AC6C-46AB-A4FC-D331C64BFFC9}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DSharpPlus.Core.Models", "DSharpPlus.Core.Models\DSharpPlus.Core.Models.csproj", "{9699C432-CC00-48D3-8534-D949C77C6B87}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DSharpPlus.Internal.Models", "DSharpPlus.Internal.Models\DSharpPlus.Internal.Models.csproj", "{9699C432-CC00-48D3-8534-D949C77C6B87}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DSharpPlus.Shared", "DSharpPlus.Shared\DSharpPlus.Shared.csproj", "{E9B2D26F-5E11-4198-8E00-A7780572C480}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DSharpPlus.Core.Abstractions.Rest", "DSharpPlus.Core.Abstractions.Rest\DSharpPlus.Core.Abstractions.Rest.csproj", "{16EFED50-A695-48C3-8B05-C52381C13C9B}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DSharpPlus.Internal.Abstractions.Rest", "DSharpPlus.Internal.Abstractions.Rest\DSharpPlus.Internal.Abstractions.Rest.csproj", "{16EFED50-A695-48C3-8B05-C52381C13C9B}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DSharpPlus.Core.Rest", "DSharpPlus.Core.Rest\DSharpPlus.Core.Rest.csproj", "{4ECD4676-81FD-4E16-B025-D6AE11638E02}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DSharpPlus.Internal.Rest", "DSharpPlus.Internal.Rest\DSharpPlus.Internal.Rest.csproj", "{4ECD4676-81FD-4E16-B025-D6AE11638E02}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/.editorconfig b/src/core/DSharpPlus.Internal.Abstractions.Models/.editorconfig similarity index 100% rename from src/core/DSharpPlus.Core.Abstractions.Models/.editorconfig rename to src/core/DSharpPlus.Internal.Abstractions.Models/.editorconfig diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/ApplicationCommands/IApplicationCommand.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/ApplicationCommands/IApplicationCommand.cs similarity index 98% rename from src/core/DSharpPlus.Core.Abstractions.Models/ApplicationCommands/IApplicationCommand.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/ApplicationCommands/IApplicationCommand.cs index 11b8ee11b1..592e3bfae3 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/ApplicationCommands/IApplicationCommand.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/ApplicationCommands/IApplicationCommand.cs @@ -6,7 +6,7 @@ using DSharpPlus.Entities; -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents an application command, either as a chat input, a message context menu or an user context diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/ApplicationCommands/IApplicationCommandOption.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/ApplicationCommands/IApplicationCommandOption.cs similarity index 98% rename from src/core/DSharpPlus.Core.Abstractions.Models/ApplicationCommands/IApplicationCommandOption.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/ApplicationCommands/IApplicationCommandOption.cs index 8c749764da..1e6a5ea852 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/ApplicationCommands/IApplicationCommandOption.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/ApplicationCommands/IApplicationCommandOption.cs @@ -8,7 +8,7 @@ using OneOf; -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents a single option for a chat input application command. diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/ApplicationCommands/IApplicationCommandOptionChoice.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/ApplicationCommands/IApplicationCommandOptionChoice.cs similarity index 94% rename from src/core/DSharpPlus.Core.Abstractions.Models/ApplicationCommands/IApplicationCommandOptionChoice.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/ApplicationCommands/IApplicationCommandOptionChoice.cs index 12c6e0a6e3..39a793e75c 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/ApplicationCommands/IApplicationCommandOptionChoice.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/ApplicationCommands/IApplicationCommandOptionChoice.cs @@ -6,7 +6,7 @@ using OneOf; -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Specifies one choice for a . diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/ApplicationCommands/IApplicationCommandPermission.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/ApplicationCommands/IApplicationCommandPermission.cs similarity index 95% rename from src/core/DSharpPlus.Core.Abstractions.Models/ApplicationCommands/IApplicationCommandPermission.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/ApplicationCommands/IApplicationCommandPermission.cs index 64472d5390..8454c429dc 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/ApplicationCommands/IApplicationCommandPermission.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/ApplicationCommands/IApplicationCommandPermission.cs @@ -4,7 +4,7 @@ using DSharpPlus.Entities; -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents a single permission override for an application command inside a guild. diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/ApplicationCommands/IApplicationCommandPermissions.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/ApplicationCommands/IApplicationCommandPermissions.cs similarity index 96% rename from src/core/DSharpPlus.Core.Abstractions.Models/ApplicationCommands/IApplicationCommandPermissions.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/ApplicationCommands/IApplicationCommandPermissions.cs index bc17c26ee4..14314093dc 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/ApplicationCommands/IApplicationCommandPermissions.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/ApplicationCommands/IApplicationCommandPermissions.cs @@ -4,7 +4,7 @@ using System.Collections.Generic; -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents a collection of permissions for an application command in a guild diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/ApplicationCommands/IPartialApplicationCommandPermissions.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/ApplicationCommands/IPartialApplicationCommandPermissions.cs similarity index 95% rename from src/core/DSharpPlus.Core.Abstractions.Models/ApplicationCommands/IPartialApplicationCommandPermissions.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/ApplicationCommands/IPartialApplicationCommandPermissions.cs index 376a257ba3..03e11454f9 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/ApplicationCommands/IPartialApplicationCommandPermissions.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/ApplicationCommands/IPartialApplicationCommandPermissions.cs @@ -4,7 +4,7 @@ using System.Collections.Generic; -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents a partial set of application command permissions. diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Applications/IApplication.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Applications/IApplication.cs similarity index 97% rename from src/core/DSharpPlus.Core.Abstractions.Models/Applications/IApplication.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Applications/IApplication.cs index b1ca293301..c3b871705c 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Applications/IApplication.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Applications/IApplication.cs @@ -2,7 +2,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents an application, such as a bot, on Discord. diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Applications/IInstallParameters.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Applications/IInstallParameters.cs similarity index 93% rename from src/core/DSharpPlus.Core.Abstractions.Models/Applications/IInstallParameters.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Applications/IInstallParameters.cs index 9ed55f4354..4e0fc19fbe 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Applications/IInstallParameters.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Applications/IInstallParameters.cs @@ -6,7 +6,7 @@ using DSharpPlus.Entities; -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Stores metadata about the installation process for an application. diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Applications/IPartialApplication.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Applications/IPartialApplication.cs similarity index 98% rename from src/core/DSharpPlus.Core.Abstractions.Models/Applications/IPartialApplication.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Applications/IPartialApplication.cs index db4655e717..1a225aef3a 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Applications/IPartialApplication.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Applications/IPartialApplication.cs @@ -6,7 +6,7 @@ using DSharpPlus.Entities; -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents a partially populated application object. diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/AuditLogs/IAuditLog.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/AuditLogs/IAuditLog.cs similarity index 96% rename from src/core/DSharpPlus.Core.Abstractions.Models/AuditLogs/IAuditLog.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/AuditLogs/IAuditLog.cs index b218fed863..64c5101f66 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/AuditLogs/IAuditLog.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/AuditLogs/IAuditLog.cs @@ -4,7 +4,7 @@ using System.Collections.Generic; -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents the guild audit log. diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/AuditLogs/IAuditLogChange.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/AuditLogs/IAuditLogChange.cs similarity index 94% rename from src/core/DSharpPlus.Core.Abstractions.Models/AuditLogs/IAuditLogChange.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/AuditLogs/IAuditLogChange.cs index b20e9ca75e..bf3aa04fa2 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/AuditLogs/IAuditLogChange.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/AuditLogs/IAuditLogChange.cs @@ -2,7 +2,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents a single logged change made to an entity. Cast to a more specific type to access the changes made. diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/AuditLogs/IAuditLogEntry.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/AuditLogs/IAuditLogEntry.cs similarity index 96% rename from src/core/DSharpPlus.Core.Abstractions.Models/AuditLogs/IAuditLogEntry.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/AuditLogs/IAuditLogEntry.cs index 5d112d5780..34b6c364c9 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/AuditLogs/IAuditLogEntry.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/AuditLogs/IAuditLogEntry.cs @@ -8,7 +8,7 @@ using OneOf; -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents a single entry within the audit log. diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/AuditLogs/IAuditLogEntryInfo.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/AuditLogs/IAuditLogEntryInfo.cs similarity index 97% rename from src/core/DSharpPlus.Core.Abstractions.Models/AuditLogs/IAuditLogEntryInfo.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/AuditLogs/IAuditLogEntryInfo.cs index ff01aff5b8..8df589af49 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/AuditLogs/IAuditLogEntryInfo.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/AuditLogs/IAuditLogEntryInfo.cs @@ -2,7 +2,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Contains additional metadata for an audit log entry. diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/AutoModeration/IAutoModerationAction.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/AutoModeration/IAutoModerationAction.cs similarity index 92% rename from src/core/DSharpPlus.Core.Abstractions.Models/AutoModeration/IAutoModerationAction.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/AutoModeration/IAutoModerationAction.cs index 2adad473a3..d31fc797f7 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/AutoModeration/IAutoModerationAction.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/AutoModeration/IAutoModerationAction.cs @@ -4,7 +4,7 @@ using DSharpPlus.Entities; -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents an action which will execute whenever a rule is triggered. diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/AutoModeration/IAutoModerationActionMetadata.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/AutoModeration/IAutoModerationActionMetadata.cs similarity index 88% rename from src/core/DSharpPlus.Core.Abstractions.Models/AutoModeration/IAutoModerationActionMetadata.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/AutoModeration/IAutoModerationActionMetadata.cs index 03edaba270..60a329f641 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/AutoModeration/IAutoModerationActionMetadata.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/AutoModeration/IAutoModerationActionMetadata.cs @@ -2,7 +2,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents additional metadata provided to automod actions. Cast to a specialized interface to diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/AutoModeration/IAutoModerationRule.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/AutoModeration/IAutoModerationRule.cs similarity index 98% rename from src/core/DSharpPlus.Core.Abstractions.Models/AutoModeration/IAutoModerationRule.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/AutoModeration/IAutoModerationRule.cs index c279a0df3b..181f276ee6 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/AutoModeration/IAutoModerationRule.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/AutoModeration/IAutoModerationRule.cs @@ -6,7 +6,7 @@ using DSharpPlus.Entities; -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents an auto moderation rule within a guild. diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/AutoModeration/IAutoModerationTriggerMetadata.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/AutoModeration/IAutoModerationTriggerMetadata.cs similarity index 97% rename from src/core/DSharpPlus.Core.Abstractions.Models/AutoModeration/IAutoModerationTriggerMetadata.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/AutoModeration/IAutoModerationTriggerMetadata.cs index a8de339380..97bbddf6ea 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/AutoModeration/IAutoModerationTriggerMetadata.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/AutoModeration/IAutoModerationTriggerMetadata.cs @@ -6,7 +6,7 @@ using DSharpPlus.Entities; -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents additional rule metadata, based on the configured trigger. diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/AutoModeration/IBlockMessageActionMetadata.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/AutoModeration/IBlockMessageActionMetadata.cs similarity index 92% rename from src/core/DSharpPlus.Core.Abstractions.Models/AutoModeration/IBlockMessageActionMetadata.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/AutoModeration/IBlockMessageActionMetadata.cs index bc526df96e..2fe8f251cb 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/AutoModeration/IBlockMessageActionMetadata.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/AutoModeration/IBlockMessageActionMetadata.cs @@ -4,7 +4,7 @@ using DSharpPlus.Entities; -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents metadata for auto moderation actions of type diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/AutoModeration/IPartialAutoModerationRule.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/AutoModeration/IPartialAutoModerationRule.cs similarity index 97% rename from src/core/DSharpPlus.Core.Abstractions.Models/AutoModeration/IPartialAutoModerationRule.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/AutoModeration/IPartialAutoModerationRule.cs index fa4b462292..5af07466d2 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/AutoModeration/IPartialAutoModerationRule.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/AutoModeration/IPartialAutoModerationRule.cs @@ -6,7 +6,7 @@ using DSharpPlus.Entities; -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents a partial auto-moderation rule. diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/AutoModeration/ISendAlertMessageActionMetadata.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/AutoModeration/ISendAlertMessageActionMetadata.cs similarity index 92% rename from src/core/DSharpPlus.Core.Abstractions.Models/AutoModeration/ISendAlertMessageActionMetadata.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/AutoModeration/ISendAlertMessageActionMetadata.cs index 7efca57889..2ef0e36214 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/AutoModeration/ISendAlertMessageActionMetadata.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/AutoModeration/ISendAlertMessageActionMetadata.cs @@ -4,7 +4,7 @@ using DSharpPlus.Entities; -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents metadata for auto moderation actions of type diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/AutoModeration/ITimeoutActionMetadata.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/AutoModeration/ITimeoutActionMetadata.cs similarity index 92% rename from src/core/DSharpPlus.Core.Abstractions.Models/AutoModeration/ITimeoutActionMetadata.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/AutoModeration/ITimeoutActionMetadata.cs index 93929505e1..2730f4b053 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/AutoModeration/ITimeoutActionMetadata.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/AutoModeration/ITimeoutActionMetadata.cs @@ -4,7 +4,7 @@ using DSharpPlus.Entities; -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents metadata for auto moderation actions of type diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IAllowedMentions.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IAllowedMentions.cs similarity index 96% rename from src/core/DSharpPlus.Core.Abstractions.Models/Channels/IAllowedMentions.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IAllowedMentions.cs index 2bf464b7d3..c859f3540e 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IAllowedMentions.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IAllowedMentions.cs @@ -4,7 +4,7 @@ using System.Collections.Generic; -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Stores information about what mentions should be allowed and which ones should be diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IAttachment.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IAttachment.cs similarity index 96% rename from src/core/DSharpPlus.Core.Abstractions.Models/Channels/IAttachment.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IAttachment.cs index 5026f0e62f..ed88efb70d 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IAttachment.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IAttachment.cs @@ -2,7 +2,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents an attachment to a message. diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IChannel.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IChannel.cs similarity index 93% rename from src/core/DSharpPlus.Core.Abstractions.Models/Channels/IChannel.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IChannel.cs index 51cf209051..83bb69a004 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IChannel.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IChannel.cs @@ -4,7 +4,7 @@ using DSharpPlus.Entities; -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents a fully populated channel object. diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IChannelMention.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IChannelMention.cs similarity index 94% rename from src/core/DSharpPlus.Core.Abstractions.Models/Channels/IChannelMention.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IChannelMention.cs index 2207e9d5e4..0f362d19e4 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IChannelMention.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IChannelMention.cs @@ -4,7 +4,7 @@ using DSharpPlus.Entities; -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents a mention of a guild channel. diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IChannelOverwrite.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IChannelOverwrite.cs similarity index 96% rename from src/core/DSharpPlus.Core.Abstractions.Models/Channels/IChannelOverwrite.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IChannelOverwrite.cs index 2703b0987b..e9115acfe2 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IChannelOverwrite.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IChannelOverwrite.cs @@ -4,7 +4,7 @@ using DSharpPlus.Entities; -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents a permission overwrite on a channel. diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IDefaultReaction.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IDefaultReaction.cs similarity index 93% rename from src/core/DSharpPlus.Core.Abstractions.Models/Channels/IDefaultReaction.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IDefaultReaction.cs index 62c217e3cc..8366668e9f 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IDefaultReaction.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IDefaultReaction.cs @@ -2,7 +2,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Indicates the default emoji to react to a forum post with. diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IEmbed.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IEmbed.cs similarity index 97% rename from src/core/DSharpPlus.Core.Abstractions.Models/Channels/IEmbed.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IEmbed.cs index 96c32ba9b9..cb0e0f1369 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IEmbed.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IEmbed.cs @@ -5,7 +5,7 @@ using System; using System.Collections.Generic; -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents embedded content in a message. diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IEmbedAuthor.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IEmbedAuthor.cs similarity index 93% rename from src/core/DSharpPlus.Core.Abstractions.Models/Channels/IEmbedAuthor.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IEmbedAuthor.cs index a7278398d5..81d0047fa9 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IEmbedAuthor.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IEmbedAuthor.cs @@ -2,7 +2,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents an embed author object. diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IEmbedField.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IEmbedField.cs similarity index 92% rename from src/core/DSharpPlus.Core.Abstractions.Models/Channels/IEmbedField.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IEmbedField.cs index 9a7fea8d80..d44dbc9e2b 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IEmbedField.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IEmbedField.cs @@ -2,7 +2,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents an embed field. diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IEmbedFooter.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IEmbedFooter.cs similarity index 92% rename from src/core/DSharpPlus.Core.Abstractions.Models/Channels/IEmbedFooter.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IEmbedFooter.cs index 90ba783f49..ae396fc249 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IEmbedFooter.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IEmbedFooter.cs @@ -2,7 +2,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents an embed footer object. diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IEmbedImage.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IEmbedImage.cs similarity index 93% rename from src/core/DSharpPlus.Core.Abstractions.Models/Channels/IEmbedImage.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IEmbedImage.cs index bb951e9071..ee938a2a66 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IEmbedImage.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IEmbedImage.cs @@ -2,7 +2,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents an embedded image. diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IEmbedProvider.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IEmbedProvider.cs similarity index 91% rename from src/core/DSharpPlus.Core.Abstractions.Models/Channels/IEmbedProvider.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IEmbedProvider.cs index 66f5299a6d..205400b76e 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IEmbedProvider.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IEmbedProvider.cs @@ -2,7 +2,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents an embed provider. diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IEmbedThumbnail.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IEmbedThumbnail.cs similarity index 93% rename from src/core/DSharpPlus.Core.Abstractions.Models/Channels/IEmbedThumbnail.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IEmbedThumbnail.cs index 7609adcbf7..778fa84b6b 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IEmbedThumbnail.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IEmbedThumbnail.cs @@ -2,7 +2,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents a thumbnail in an embed. diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IEmbedVideo.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IEmbedVideo.cs similarity index 93% rename from src/core/DSharpPlus.Core.Abstractions.Models/Channels/IEmbedVideo.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IEmbedVideo.cs index a500dabe09..7eefb0f325 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IEmbedVideo.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IEmbedVideo.cs @@ -2,7 +2,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents an embedded video. diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IFollowedChannel.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IFollowedChannel.cs similarity index 92% rename from src/core/DSharpPlus.Core.Abstractions.Models/Channels/IFollowedChannel.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IFollowedChannel.cs index ec5bc7c851..87a229dd94 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IFollowedChannel.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IFollowedChannel.cs @@ -2,7 +2,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents a followed channel, whose messages will be crossposted. diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IForumTag.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IForumTag.cs similarity index 95% rename from src/core/DSharpPlus.Core.Abstractions.Models/Channels/IForumTag.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IForumTag.cs index 1743431b64..5d2e507146 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IForumTag.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IForumTag.cs @@ -2,7 +2,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents a single forum tag, applicable to forum or media channel posts. diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IMessage.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IMessage.cs similarity index 98% rename from src/core/DSharpPlus.Core.Abstractions.Models/Channels/IMessage.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IMessage.cs index a9a0e7cf28..e0d1f7fb7b 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IMessage.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IMessage.cs @@ -7,7 +7,7 @@ using DSharpPlus.Entities; -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents a complete message object. diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IMessageActivity.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IMessageActivity.cs similarity index 92% rename from src/core/DSharpPlus.Core.Abstractions.Models/Channels/IMessageActivity.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IMessageActivity.cs index fc9cd9fb60..ead2234827 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IMessageActivity.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IMessageActivity.cs @@ -4,7 +4,7 @@ using DSharpPlus.Entities; -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents activity data encoded in a message. diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IMessageReference.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IMessageReference.cs similarity index 95% rename from src/core/DSharpPlus.Core.Abstractions.Models/Channels/IMessageReference.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IMessageReference.cs index adf3d504d8..cecdb9159d 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IMessageReference.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IMessageReference.cs @@ -2,7 +2,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents a message reference, used for replies, crossposts, pins, thread created and thread diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IPartialAttachment.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IPartialAttachment.cs similarity index 97% rename from src/core/DSharpPlus.Core.Abstractions.Models/Channels/IPartialAttachment.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IPartialAttachment.cs index f19f477774..bd2be5cbe7 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IPartialAttachment.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IPartialAttachment.cs @@ -6,7 +6,7 @@ using DSharpPlus.Entities; -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents a partially populated message attachment. diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IPartialChannel.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IPartialChannel.cs similarity index 99% rename from src/core/DSharpPlus.Core.Abstractions.Models/Channels/IPartialChannel.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IPartialChannel.cs index 0ec8dea83e..490fcf97b2 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IPartialChannel.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IPartialChannel.cs @@ -7,7 +7,7 @@ using DSharpPlus.Entities; -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents a partial channel of any given type. diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IPartialChannelOverwrite.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IPartialChannelOverwrite.cs similarity index 95% rename from src/core/DSharpPlus.Core.Abstractions.Models/Channels/IPartialChannelOverwrite.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IPartialChannelOverwrite.cs index 88243d4957..5a5b1cc308 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IPartialChannelOverwrite.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IPartialChannelOverwrite.cs @@ -4,7 +4,7 @@ using DSharpPlus.Entities; -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents a partially populated channel overwrite. diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IPartialMessage.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IPartialMessage.cs similarity index 99% rename from src/core/DSharpPlus.Core.Abstractions.Models/Channels/IPartialMessage.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IPartialMessage.cs index b8cbc6b1e4..62a8ef9552 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IPartialMessage.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IPartialMessage.cs @@ -7,7 +7,7 @@ using DSharpPlus.Entities; -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents a partially populated message object. diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IReaction.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IReaction.cs similarity index 93% rename from src/core/DSharpPlus.Core.Abstractions.Models/Channels/IReaction.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IReaction.cs index 47c16bfbca..f0254b5817 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IReaction.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IReaction.cs @@ -2,7 +2,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents a reaction to a message. diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IRoleSubscriptionData.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IRoleSubscriptionData.cs similarity index 94% rename from src/core/DSharpPlus.Core.Abstractions.Models/Channels/IRoleSubscriptionData.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IRoleSubscriptionData.cs index bfebd41054..ed0979da87 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IRoleSubscriptionData.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IRoleSubscriptionData.cs @@ -2,7 +2,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Contains metadata about a role subscription. diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IThreadMember.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IThreadMember.cs similarity index 95% rename from src/core/DSharpPlus.Core.Abstractions.Models/Channels/IThreadMember.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IThreadMember.cs index 9447f7c274..4ba3a5d03a 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IThreadMember.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IThreadMember.cs @@ -4,7 +4,7 @@ using System; -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Includes additional metadata about a member's presence inside a thread. diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IThreadMetadata.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IThreadMetadata.cs similarity index 96% rename from src/core/DSharpPlus.Core.Abstractions.Models/Channels/IThreadMetadata.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IThreadMetadata.cs index 8e59990892..42b2f2f6d9 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Channels/IThreadMetadata.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IThreadMetadata.cs @@ -4,7 +4,7 @@ using System; -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Contains additional metadata about thread channels. diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/DSharpPlus.Core.Abstractions.Models.csproj b/src/core/DSharpPlus.Internal.Abstractions.Models/DSharpPlus.Internal.Abstractions.Models.csproj similarity index 87% rename from src/core/DSharpPlus.Core.Abstractions.Models/DSharpPlus.Core.Abstractions.Models.csproj rename to src/core/DSharpPlus.Internal.Abstractions.Models/DSharpPlus.Internal.Abstractions.Models.csproj index f935e9d971..a6c52ba8cf 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/DSharpPlus.Core.Abstractions.Models.csproj +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/DSharpPlus.Internal.Abstractions.Models.csproj @@ -1,7 +1,7 @@  - $(_DSharpPlusCoreAbstractionsModelsVersion) + $(_DSharpPlusInternalAbstractionsModelsVersion) $(Description) This package specifies a contract for the serialization models to implement. This definition is library-agnostic. Library diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Emojis/IEmoji.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Emojis/IEmoji.cs similarity index 93% rename from src/core/DSharpPlus.Core.Abstractions.Models/Emojis/IEmoji.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Emojis/IEmoji.cs index ab519ef77a..d438688f7d 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Emojis/IEmoji.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Emojis/IEmoji.cs @@ -2,7 +2,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents a fully populated emoji object. diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Emojis/IPartialEmoji.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Emojis/IPartialEmoji.cs similarity index 96% rename from src/core/DSharpPlus.Core.Abstractions.Models/Emojis/IPartialEmoji.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Emojis/IPartialEmoji.cs index 19fce4b920..fd5768014f 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Emojis/IPartialEmoji.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Emojis/IPartialEmoji.cs @@ -4,7 +4,7 @@ using System.Collections.Generic; -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents a partial emoji object, where any or all properties may be missing. diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Entitlements/IEntitlement.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Entitlements/IEntitlement.cs similarity index 95% rename from src/core/DSharpPlus.Core.Abstractions.Models/Entitlements/IEntitlement.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Entitlements/IEntitlement.cs index d77af2762a..99554c78f3 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Entitlements/IEntitlement.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Entitlements/IEntitlement.cs @@ -4,7 +4,7 @@ using DSharpPlus.Entities; -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents an entitlement to a premium offering in an application. diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Entitlements/IPartialEntitlement.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Entitlements/IPartialEntitlement.cs similarity index 97% rename from src/core/DSharpPlus.Core.Abstractions.Models/Entitlements/IPartialEntitlement.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Entitlements/IPartialEntitlement.cs index e6967184b3..08dd7f5716 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Entitlements/IPartialEntitlement.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Entitlements/IPartialEntitlement.cs @@ -5,7 +5,7 @@ using DSharpPlus.Entities; using System; -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents a partial entitlement object. diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/GuildTemplates/ITemplate.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/GuildTemplates/ITemplate.cs similarity index 97% rename from src/core/DSharpPlus.Core.Abstractions.Models/GuildTemplates/ITemplate.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/GuildTemplates/ITemplate.cs index 5b8807cab7..46b808e897 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/GuildTemplates/ITemplate.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/GuildTemplates/ITemplate.cs @@ -4,7 +4,7 @@ using System; -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents a guild template that, when used, creates a guild with default settings taken from diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IBan.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Guilds/IBan.cs similarity index 90% rename from src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IBan.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Guilds/IBan.cs index 9cbc5a659b..c3999d580f 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IBan.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Guilds/IBan.cs @@ -2,7 +2,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents information about a ban from a guild. diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IGuild.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Guilds/IGuild.cs similarity index 99% rename from src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IGuild.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Guilds/IGuild.cs index 02714a0ee5..15f5c7f442 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IGuild.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Guilds/IGuild.cs @@ -6,7 +6,7 @@ using DSharpPlus.Entities; -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents a fully populated guild object. diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IGuildMember.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Guilds/IGuildMember.cs similarity index 96% rename from src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IGuildMember.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Guilds/IGuildMember.cs index 8915d84b4f..abfdc15005 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IGuildMember.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Guilds/IGuildMember.cs @@ -7,7 +7,7 @@ using DSharpPlus.Entities; -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents a fully populated guild member object. diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IGuildPreview.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Guilds/IGuildPreview.cs similarity index 97% rename from src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IGuildPreview.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Guilds/IGuildPreview.cs index 668d93039c..d050a65cc7 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IGuildPreview.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Guilds/IGuildPreview.cs @@ -4,7 +4,7 @@ using System.Collections.Generic; -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents a guild preview object. diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IGuildWidget.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Guilds/IGuildWidget.cs similarity index 95% rename from src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IGuildWidget.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Guilds/IGuildWidget.cs index 29378e58ff..dd82d213db 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IGuildWidget.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Guilds/IGuildWidget.cs @@ -4,7 +4,7 @@ using System.Collections.Generic; -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents a guild's widget object. diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IGuildWidgetSettings.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Guilds/IGuildWidgetSettings.cs similarity index 91% rename from src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IGuildWidgetSettings.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Guilds/IGuildWidgetSettings.cs index 50e72e34e7..46ddbdece8 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IGuildWidgetSettings.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Guilds/IGuildWidgetSettings.cs @@ -2,7 +2,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Contains settings for this guild's widget. diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IIntegration.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Guilds/IIntegration.cs similarity index 96% rename from src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IIntegration.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Guilds/IIntegration.cs index bbd881f12a..740e7b1fa7 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IIntegration.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Guilds/IIntegration.cs @@ -2,7 +2,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents an integration between an external service and a guild. diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IIntegrationAccount.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Guilds/IIntegrationAccount.cs similarity index 91% rename from src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IIntegrationAccount.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Guilds/IIntegrationAccount.cs index 207d8e9cb2..8035afaa67 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IIntegrationAccount.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Guilds/IIntegrationAccount.cs @@ -2,7 +2,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Contains additional information about integration accounts. diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IIntegrationApplication.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Guilds/IIntegrationApplication.cs similarity index 94% rename from src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IIntegrationApplication.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Guilds/IIntegrationApplication.cs index a4e4007efb..8543242d81 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IIntegrationApplication.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Guilds/IIntegrationApplication.cs @@ -2,7 +2,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents application-specific metadata for an integration. diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IOnboarding.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Guilds/IOnboarding.cs similarity index 95% rename from src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IOnboarding.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Guilds/IOnboarding.cs index 070674fe38..5216b7e8ee 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IOnboarding.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Guilds/IOnboarding.cs @@ -6,7 +6,7 @@ using DSharpPlus.Entities; -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents the guild onboarding flow for the given guild. diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IOnboardingPrompt.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Guilds/IOnboardingPrompt.cs similarity index 96% rename from src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IOnboardingPrompt.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Guilds/IOnboardingPrompt.cs index 7f5a3bd6a5..2e5dec4fec 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IOnboardingPrompt.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Guilds/IOnboardingPrompt.cs @@ -6,7 +6,7 @@ using DSharpPlus.Entities; -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents an user prompt during the onboarding flow. diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IOnboardingPromptOption.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Guilds/IOnboardingPromptOption.cs similarity index 97% rename from src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IOnboardingPromptOption.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Guilds/IOnboardingPromptOption.cs index 739571e645..8fa6e0a918 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IOnboardingPromptOption.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Guilds/IOnboardingPromptOption.cs @@ -4,7 +4,7 @@ using System.Collections.Generic; -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents an option for a guild onboarding prompt. diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IPartialGuild.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Guilds/IPartialGuild.cs similarity index 99% rename from src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IPartialGuild.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Guilds/IPartialGuild.cs index 3322890e68..f1d2041024 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IPartialGuild.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Guilds/IPartialGuild.cs @@ -6,7 +6,7 @@ using DSharpPlus.Entities; -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents a partially populated guild object. diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IPartialGuildMember.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Guilds/IPartialGuildMember.cs similarity index 97% rename from src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IPartialGuildMember.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Guilds/IPartialGuildMember.cs index 6320436922..2cfacc507b 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IPartialGuildMember.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Guilds/IPartialGuildMember.cs @@ -7,7 +7,7 @@ using DSharpPlus.Entities; -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents a single member of a guild. diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IPartialIntegration.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Guilds/IPartialIntegration.cs similarity index 98% rename from src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IPartialIntegration.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Guilds/IPartialIntegration.cs index a106a83ebf..c5d2ec47df 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IPartialIntegration.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Guilds/IPartialIntegration.cs @@ -7,7 +7,7 @@ using DSharpPlus.Entities; -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents a partially populated integration object. diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IPartialRole.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Guilds/IPartialRole.cs similarity index 97% rename from src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IPartialRole.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Guilds/IPartialRole.cs index 939fc6412c..b3bc50b06a 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IPartialRole.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Guilds/IPartialRole.cs @@ -4,7 +4,7 @@ using DSharpPlus.Entities; -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents a partially populated role object. diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IRole.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Guilds/IRole.cs similarity index 97% rename from src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IRole.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Guilds/IRole.cs index bca8e1c0c0..d3061c69a2 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IRole.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Guilds/IRole.cs @@ -4,7 +4,7 @@ using DSharpPlus.Entities; -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents a role within a guild. diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IRoleTags.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Guilds/IRoleTags.cs similarity index 96% rename from src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IRoleTags.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Guilds/IRoleTags.cs index cef076d536..2d84a67ad6 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IRoleTags.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Guilds/IRoleTags.cs @@ -2,7 +2,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Contains additional tags associated with a given role. diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IWelcomeScreen.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Guilds/IWelcomeScreen.cs similarity index 93% rename from src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IWelcomeScreen.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Guilds/IWelcomeScreen.cs index 54ba6e94e4..ab7b87c0e9 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IWelcomeScreen.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Guilds/IWelcomeScreen.cs @@ -4,7 +4,7 @@ using System.Collections.Generic; -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents a guild welcome screen, showing the user a brief description and a few channels to check out. diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IWelcomeScreenChannel.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Guilds/IWelcomeScreenChannel.cs similarity index 95% rename from src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IWelcomeScreenChannel.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Guilds/IWelcomeScreenChannel.cs index ceef81f1b4..ecdaaf7983 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Guilds/IWelcomeScreenChannel.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Guilds/IWelcomeScreenChannel.cs @@ -2,7 +2,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents a single shown in the welcome screen. diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IApplicationCommandInteractionData.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Interactions/IApplicationCommandInteractionData.cs similarity index 96% rename from src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IApplicationCommandInteractionData.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Interactions/IApplicationCommandInteractionData.cs index 11556452ad..ef175e5f26 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IApplicationCommandInteractionData.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Interactions/IApplicationCommandInteractionData.cs @@ -6,7 +6,7 @@ using DSharpPlus.Entities; -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Contains the interaction metadata for application commands. diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IApplicationCommandInteractionDataOption.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Interactions/IApplicationCommandInteractionDataOption.cs similarity index 96% rename from src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IApplicationCommandInteractionDataOption.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Interactions/IApplicationCommandInteractionDataOption.cs index e167bcf281..c2cbe552df 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IApplicationCommandInteractionDataOption.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Interactions/IApplicationCommandInteractionDataOption.cs @@ -8,7 +8,7 @@ using OneOf; -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents submitted data for a single application command option. diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IAutocompleteCallbackData.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Interactions/IAutocompleteCallbackData.cs similarity index 91% rename from src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IAutocompleteCallbackData.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Interactions/IAutocompleteCallbackData.cs index 540b846b6b..111329f1ba 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IAutocompleteCallbackData.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Interactions/IAutocompleteCallbackData.cs @@ -4,7 +4,7 @@ using System.Collections.Generic; -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents callback data for responding to an autocomplete interaction. diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IInteraction.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Interactions/IInteraction.cs similarity index 98% rename from src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IInteraction.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Interactions/IInteraction.cs index cdc5288dc8..72847a2129 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IInteraction.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Interactions/IInteraction.cs @@ -8,7 +8,7 @@ using OneOf; -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents an incoming interaction, received when an user submits an application command diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IInteractionResponse.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Interactions/IInteractionResponse.cs similarity index 93% rename from src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IInteractionResponse.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Interactions/IInteractionResponse.cs index c97ecd2284..2fc521c1f6 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IInteractionResponse.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Interactions/IInteractionResponse.cs @@ -6,7 +6,7 @@ using OneOf; -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents an outgoing response to an interaction. diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IMessageCallbackData.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Interactions/IMessageCallbackData.cs similarity index 96% rename from src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IMessageCallbackData.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Interactions/IMessageCallbackData.cs index 886211d82f..bf4e3580e3 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IMessageCallbackData.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Interactions/IMessageCallbackData.cs @@ -6,7 +6,7 @@ using DSharpPlus.Entities; -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents a response payload for creating or updating a message. diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IMessageComponentInteractionData.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Interactions/IMessageComponentInteractionData.cs similarity index 95% rename from src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IMessageComponentInteractionData.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Interactions/IMessageComponentInteractionData.cs index 1abb05a69d..0736c8cf3f 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IMessageComponentInteractionData.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Interactions/IMessageComponentInteractionData.cs @@ -6,7 +6,7 @@ using DSharpPlus.Entities; -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents metadata for a message component interaction. diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IMessageInteraction.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Interactions/IMessageInteraction.cs similarity index 95% rename from src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IMessageInteraction.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Interactions/IMessageInteraction.cs index 3eeaab7b5f..9d01c1b31e 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IMessageInteraction.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Interactions/IMessageInteraction.cs @@ -4,7 +4,7 @@ using DSharpPlus.Entities; -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents metadata on a message when the message is an original response to an interaction. diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IModalCallbackData.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Interactions/IModalCallbackData.cs similarity index 94% rename from src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IModalCallbackData.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Interactions/IModalCallbackData.cs index 1c830e0118..683cd87022 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IModalCallbackData.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Interactions/IModalCallbackData.cs @@ -4,7 +4,7 @@ using System.Collections.Generic; -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents callback data for creating a modal. diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IModalInteractionData.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Interactions/IModalInteractionData.cs similarity index 92% rename from src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IModalInteractionData.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Interactions/IModalInteractionData.cs index 3c3310dd64..9918bfd2b1 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IModalInteractionData.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Interactions/IModalInteractionData.cs @@ -4,7 +4,7 @@ using System.Collections.Generic; -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Contains metadata for a modal submission interaction. diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IResolvedData.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Interactions/IResolvedData.cs similarity index 96% rename from src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IResolvedData.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Interactions/IResolvedData.cs index 20d464f9f6..a5ba0d8bee 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Interactions/IResolvedData.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Interactions/IResolvedData.cs @@ -4,7 +4,7 @@ using System.Collections.Generic; -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents data resolved by Discord from s. diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Invites/IInvite.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Invites/IInvite.cs similarity index 93% rename from src/core/DSharpPlus.Core.Abstractions.Models/Invites/IInvite.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Invites/IInvite.cs index 9f6f40ed1d..bbeb77ee3e 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Invites/IInvite.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Invites/IInvite.cs @@ -2,7 +2,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents a discord invite object. diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Invites/IPartialInvite.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Invites/IPartialInvite.cs similarity index 98% rename from src/core/DSharpPlus.Core.Abstractions.Models/Invites/IPartialInvite.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Invites/IPartialInvite.cs index 5734e7d0b2..a4581e2ed5 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Invites/IPartialInvite.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Invites/IPartialInvite.cs @@ -6,7 +6,7 @@ using DSharpPlus.Entities; -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents a partially populated invite object. diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IActionRowComponent.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IActionRowComponent.cs similarity index 93% rename from src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IActionRowComponent.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IActionRowComponent.cs index 9deb0e964e..136c58cb27 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IActionRowComponent.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IActionRowComponent.cs @@ -6,7 +6,7 @@ using DSharpPlus.Entities; -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents a container component for other components. diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IButtonComponent.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IButtonComponent.cs similarity index 96% rename from src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IButtonComponent.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IButtonComponent.cs index 424d26c0bb..259f8a78ec 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IButtonComponent.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IButtonComponent.cs @@ -4,7 +4,7 @@ using DSharpPlus.Entities; -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents a button attached to a message. diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IChannelSelectComponent.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IChannelSelectComponent.cs similarity index 97% rename from src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IChannelSelectComponent.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IChannelSelectComponent.cs index b8ab6bddb7..6fcc92eb2b 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IChannelSelectComponent.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IChannelSelectComponent.cs @@ -6,7 +6,7 @@ using DSharpPlus.Entities; -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents a dropdown menu from where users can select discord-supplied channels, diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IDefaultSelectValue.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IDefaultSelectValue.cs similarity index 92% rename from src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IDefaultSelectValue.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IDefaultSelectValue.cs index a80494a828..5f8e4b4071 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IDefaultSelectValue.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IDefaultSelectValue.cs @@ -2,7 +2,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents a default value for an auto-populated select menu. diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IInteractiveComponent.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IInteractiveComponent.cs similarity index 86% rename from src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IInteractiveComponent.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IInteractiveComponent.cs index 616e867e68..8608201d3e 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IInteractiveComponent.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IInteractiveComponent.cs @@ -2,7 +2,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents a message component that users can interact with. diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IMentionableSelectComponent.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IMentionableSelectComponent.cs similarity index 97% rename from src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IMentionableSelectComponent.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IMentionableSelectComponent.cs index 8a8ed5a7d6..19ef590b58 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IMentionableSelectComponent.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IMentionableSelectComponent.cs @@ -6,7 +6,7 @@ using DSharpPlus.Entities; -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents a dropdown menu from where users can select discord-supplied users and roles. diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IRoleSelectComponent.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IRoleSelectComponent.cs similarity index 96% rename from src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IRoleSelectComponent.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IRoleSelectComponent.cs index fe5cd93136..b5cea01da7 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IRoleSelectComponent.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IRoleSelectComponent.cs @@ -6,7 +6,7 @@ using DSharpPlus.Entities; -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents a dropdown menu from where users can select discord-supplied roles. diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/ISelectOption.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/ISelectOption.cs similarity index 95% rename from src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/ISelectOption.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/ISelectOption.cs index a5c012882e..025f18338a 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/ISelectOption.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/ISelectOption.cs @@ -2,7 +2,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents a single text option in a . diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IStringSelectComponent.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IStringSelectComponent.cs similarity index 96% rename from src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IStringSelectComponent.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IStringSelectComponent.cs index e32668932f..b58c8a3434 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IStringSelectComponent.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IStringSelectComponent.cs @@ -6,7 +6,7 @@ using DSharpPlus.Entities; -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents a dropdown menu from where users can select dev-supplied strings. diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/ITextInputComponent.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/ITextInputComponent.cs similarity index 97% rename from src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/ITextInputComponent.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/ITextInputComponent.cs index d8b6af80f9..4845f1e878 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/ITextInputComponent.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/ITextInputComponent.cs @@ -4,7 +4,7 @@ using DSharpPlus.Entities; -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents a text input field in a modal. diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IUserSelectComponent.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IUserSelectComponent.cs similarity index 96% rename from src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IUserSelectComponent.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IUserSelectComponent.cs index b25befde2d..1477848520 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/MessageComponents/IUserSelectComponent.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IUserSelectComponent.cs @@ -6,7 +6,7 @@ using DSharpPlus.Entities; -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents a dropdown menu from where users can select discord-supplied users. diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/RoleConnections/IRoleConnectionMetadata.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/RoleConnections/IRoleConnectionMetadata.cs similarity index 96% rename from src/core/DSharpPlus.Core.Abstractions.Models/RoleConnections/IRoleConnectionMetadata.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/RoleConnections/IRoleConnectionMetadata.cs index 80d64e7281..029c4b11ad 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/RoleConnections/IRoleConnectionMetadata.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/RoleConnections/IRoleConnectionMetadata.cs @@ -6,7 +6,7 @@ using DSharpPlus.Entities; -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Contains role connection metadata for an application. diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/ScheduledEvents/IPartialScheduledEvent.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/ScheduledEvents/IPartialScheduledEvent.cs similarity index 98% rename from src/core/DSharpPlus.Core.Abstractions.Models/ScheduledEvents/IPartialScheduledEvent.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/ScheduledEvents/IPartialScheduledEvent.cs index 688df24f50..76b9752b6e 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/ScheduledEvents/IPartialScheduledEvent.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/ScheduledEvents/IPartialScheduledEvent.cs @@ -6,7 +6,7 @@ using DSharpPlus.Entities; -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents a partially populated scheduled event. diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/ScheduledEvents/IScheduledEvent.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/ScheduledEvents/IScheduledEvent.cs similarity index 97% rename from src/core/DSharpPlus.Core.Abstractions.Models/ScheduledEvents/IScheduledEvent.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/ScheduledEvents/IScheduledEvent.cs index 488de7b7fd..286dde9c1a 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/ScheduledEvents/IScheduledEvent.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/ScheduledEvents/IScheduledEvent.cs @@ -6,7 +6,7 @@ using DSharpPlus.Entities; -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents a guild scheduled event. diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/ScheduledEvents/IScheduledEventMetadata.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/ScheduledEvents/IScheduledEventMetadata.cs similarity index 90% rename from src/core/DSharpPlus.Core.Abstractions.Models/ScheduledEvents/IScheduledEventMetadata.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/ScheduledEvents/IScheduledEventMetadata.cs index 90e12d8e76..9cb22e50e7 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/ScheduledEvents/IScheduledEventMetadata.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/ScheduledEvents/IScheduledEventMetadata.cs @@ -2,7 +2,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents metadata for a scheduled event. diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/ScheduledEvents/IScheduledEventUser.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/ScheduledEvents/IScheduledEventUser.cs similarity index 94% rename from src/core/DSharpPlus.Core.Abstractions.Models/ScheduledEvents/IScheduledEventUser.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/ScheduledEvents/IScheduledEventUser.cs index ad98140da6..da018bacc6 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/ScheduledEvents/IScheduledEventUser.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/ScheduledEvents/IScheduledEventUser.cs @@ -2,7 +2,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Serves as a container object for users and the scheduled event they have subscribed to. diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Skus/ISku.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Skus/ISku.cs similarity index 95% rename from src/core/DSharpPlus.Core.Abstractions.Models/Skus/ISku.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Skus/ISku.cs index 6e9b0536f1..d8379da8bd 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Skus/ISku.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Skus/ISku.cs @@ -4,7 +4,7 @@ using DSharpPlus.Entities; -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents a premium offering that can be made available to your application's users or guilds. diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/StageInstances/IPartialStageInstance.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/StageInstances/IPartialStageInstance.cs similarity index 96% rename from src/core/DSharpPlus.Core.Abstractions.Models/StageInstances/IPartialStageInstance.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/StageInstances/IPartialStageInstance.cs index 704db97a9c..5b7c144b41 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/StageInstances/IPartialStageInstance.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/StageInstances/IPartialStageInstance.cs @@ -4,7 +4,7 @@ using DSharpPlus.Entities; -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents a partial stage instance. diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/StageInstances/IStageInstance.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/StageInstances/IStageInstance.cs similarity index 96% rename from src/core/DSharpPlus.Core.Abstractions.Models/StageInstances/IStageInstance.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/StageInstances/IStageInstance.cs index 8bd3d53670..ef0a76747f 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/StageInstances/IStageInstance.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/StageInstances/IStageInstance.cs @@ -4,7 +4,7 @@ using DSharpPlus.Entities; -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents a live stage channel. diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Stickers/IPartialSticker.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Stickers/IPartialSticker.cs similarity index 97% rename from src/core/DSharpPlus.Core.Abstractions.Models/Stickers/IPartialSticker.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Stickers/IPartialSticker.cs index 9da7d5455f..61fe95b165 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Stickers/IPartialSticker.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Stickers/IPartialSticker.cs @@ -4,7 +4,7 @@ using DSharpPlus.Entities; -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents a partially populated sticker object. diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Stickers/ISticker.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Stickers/ISticker.cs similarity index 96% rename from src/core/DSharpPlus.Core.Abstractions.Models/Stickers/ISticker.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Stickers/ISticker.cs index bc7ec2854b..37a97286d5 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Stickers/ISticker.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Stickers/ISticker.cs @@ -4,7 +4,7 @@ using DSharpPlus.Entities; -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents a discord sticker that can be sent in messages. diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Stickers/IStickerItem.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Stickers/IStickerItem.cs similarity index 93% rename from src/core/DSharpPlus.Core.Abstractions.Models/Stickers/IStickerItem.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Stickers/IStickerItem.cs index 7271a73985..56e3ee5586 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Stickers/IStickerItem.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Stickers/IStickerItem.cs @@ -4,7 +4,7 @@ using DSharpPlus.Entities; -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Contains the information needed to render a sticker. diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Stickers/IStickerPack.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Stickers/IStickerPack.cs similarity index 96% rename from src/core/DSharpPlus.Core.Abstractions.Models/Stickers/IStickerPack.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Stickers/IStickerPack.cs index a67dfcf8c6..3b1df219a5 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Stickers/IStickerPack.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Stickers/IStickerPack.cs @@ -4,7 +4,7 @@ using System.Collections.Generic; -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents a pack of standard stickers. diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Teams/ITeam.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Teams/ITeam.cs similarity index 95% rename from src/core/DSharpPlus.Core.Abstractions.Models/Teams/ITeam.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Teams/ITeam.cs index d7c74ad003..c8eaf4dea2 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Teams/ITeam.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Teams/ITeam.cs @@ -4,7 +4,7 @@ using System.Collections.Generic; -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents a developer team on Discord. Teams can collectively own applications diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Teams/ITeamMember.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Teams/ITeamMember.cs similarity index 95% rename from src/core/DSharpPlus.Core.Abstractions.Models/Teams/ITeamMember.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Teams/ITeamMember.cs index 38d73f70bb..857b0d72e1 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Teams/ITeamMember.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Teams/ITeamMember.cs @@ -6,7 +6,7 @@ using DSharpPlus.Entities; -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents a single member of a . diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Users/IApplicationRoleConnection.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Users/IApplicationRoleConnection.cs similarity index 94% rename from src/core/DSharpPlus.Core.Abstractions.Models/Users/IApplicationRoleConnection.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Users/IApplicationRoleConnection.cs index 490918f30d..2ce2b7bd99 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Users/IApplicationRoleConnection.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Users/IApplicationRoleConnection.cs @@ -4,7 +4,7 @@ using System.Collections.Generic; -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents a role connection object that an application has attached to a user. diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Users/IConnection.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Users/IConnection.cs similarity index 97% rename from src/core/DSharpPlus.Core.Abstractions.Models/Users/IConnection.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Users/IConnection.cs index 31294843f3..f48d2f11d2 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Users/IConnection.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Users/IConnection.cs @@ -6,7 +6,7 @@ using DSharpPlus.Entities; -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents an account connection on an user. diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Users/IPartialUser.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Users/IPartialUser.cs similarity index 98% rename from src/core/DSharpPlus.Core.Abstractions.Models/Users/IPartialUser.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Users/IPartialUser.cs index 90aa4546d5..853c09efd8 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Users/IPartialUser.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Users/IPartialUser.cs @@ -4,7 +4,7 @@ using DSharpPlus.Entities; -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents a partially populated user object. diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Users/IUser.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Users/IUser.cs similarity index 96% rename from src/core/DSharpPlus.Core.Abstractions.Models/Users/IUser.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Users/IUser.cs index 152feaf675..435a6a4bb5 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Users/IUser.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Users/IUser.cs @@ -2,7 +2,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents an user object. diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Voice/IVoiceRegion.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Voice/IVoiceRegion.cs similarity index 95% rename from src/core/DSharpPlus.Core.Abstractions.Models/Voice/IVoiceRegion.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Voice/IVoiceRegion.cs index 88e47c0177..9daf95fee5 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Voice/IVoiceRegion.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Voice/IVoiceRegion.cs @@ -2,7 +2,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents metadata about a voice region. diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Voice/IVoiceState.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Voice/IVoiceState.cs similarity index 97% rename from src/core/DSharpPlus.Core.Abstractions.Models/Voice/IVoiceState.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Voice/IVoiceState.cs index 5a217ef62a..c4985e3e90 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Voice/IVoiceState.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Voice/IVoiceState.cs @@ -4,7 +4,7 @@ using System; -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents a user's voice connection status. diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Webhooks/IPartialWebhook.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Webhooks/IPartialWebhook.cs similarity index 97% rename from src/core/DSharpPlus.Core.Abstractions.Models/Webhooks/IPartialWebhook.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Webhooks/IPartialWebhook.cs index bdfc2f81c1..9384c25aa2 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Webhooks/IPartialWebhook.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Webhooks/IPartialWebhook.cs @@ -4,7 +4,7 @@ using DSharpPlus.Entities; -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents a partially populated webhook object. diff --git a/src/core/DSharpPlus.Core.Abstractions.Models/Webhooks/IWebhook.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Webhooks/IWebhook.cs similarity index 96% rename from src/core/DSharpPlus.Core.Abstractions.Models/Webhooks/IWebhook.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Webhooks/IWebhook.cs index 01c89c84c0..6c963272e5 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Models/Webhooks/IWebhook.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Webhooks/IWebhook.cs @@ -4,7 +4,7 @@ using DSharpPlus.Entities; -namespace DSharpPlus.Core.Abstractions.Models; +namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents a discord webhook. diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IApplicationCommandsRestAPI.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IApplicationCommandsRestAPI.cs similarity index 98% rename from src/core/DSharpPlus.Core.Abstractions.Rest/API/IApplicationCommandsRestAPI.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/API/IApplicationCommandsRestAPI.cs index c3ca3f5eaf..1b4f2ecbad 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IApplicationCommandsRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IApplicationCommandsRestAPI.cs @@ -6,14 +6,14 @@ using System.Threading; using System.Threading.Tasks; -using DSharpPlus.Core.Abstractions.Models; -using DSharpPlus.Core.Abstractions.Rest.Payloads; -using DSharpPlus.Core.Abstractions.Rest.Queries; -using DSharpPlus.Core.Abstractions.Rest.Responses; +using DSharpPlus.Internal.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Rest.Payloads; +using DSharpPlus.Internal.Abstractions.Rest.Queries; +using DSharpPlus.Internal.Abstractions.Rest.Responses; using Remora.Results; -namespace DSharpPlus.Core.Abstractions.Rest.API; +namespace DSharpPlus.Internal.Abstractions.Rest.API; /// /// Provides access to application commands-related API calls. diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IApplicationRestAPI.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IApplicationRestAPI.cs similarity index 90% rename from src/core/DSharpPlus.Core.Abstractions.Rest/API/IApplicationRestAPI.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/API/IApplicationRestAPI.cs index f1ec229e2b..131db88470 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IApplicationRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IApplicationRestAPI.cs @@ -5,12 +5,12 @@ using System.Threading; using System.Threading.Tasks; -using DSharpPlus.Core.Abstractions.Models; -using DSharpPlus.Core.Abstractions.Rest.Payloads; +using DSharpPlus.Internal.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Rest.Payloads; using Remora.Results; -namespace DSharpPlus.Core.Abstractions.Rest.API; +namespace DSharpPlus.Internal.Abstractions.Rest.API; /// /// Provides access to application-related rest API calls. diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IAuditLogsRestAPI.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IAuditLogsRestAPI.cs similarity index 89% rename from src/core/DSharpPlus.Core.Abstractions.Rest/API/IAuditLogsRestAPI.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/API/IAuditLogsRestAPI.cs index 8fe2cb41cd..a63586bfea 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IAuditLogsRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IAuditLogsRestAPI.cs @@ -5,12 +5,12 @@ using System.Threading; using System.Threading.Tasks; -using DSharpPlus.Core.Abstractions.Models; -using DSharpPlus.Core.Abstractions.Rest.Queries; +using DSharpPlus.Internal.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Rest.Queries; using Remora.Results; -namespace DSharpPlus.Core.Abstractions.Rest.API; +namespace DSharpPlus.Internal.Abstractions.Rest.API; /// /// Provides access to audit log related rest API calls. diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IAutoModerationRestAPI.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IAutoModerationRestAPI.cs similarity index 96% rename from src/core/DSharpPlus.Core.Abstractions.Rest/API/IAutoModerationRestAPI.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/API/IAutoModerationRestAPI.cs index 0858f98a38..0841c9edb8 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IAutoModerationRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IAutoModerationRestAPI.cs @@ -6,12 +6,12 @@ using System.Threading; using System.Threading.Tasks; -using DSharpPlus.Core.Abstractions.Models; -using DSharpPlus.Core.Abstractions.Rest.Payloads; +using DSharpPlus.Internal.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Rest.Payloads; using Remora.Results; -namespace DSharpPlus.Core.Abstractions.Rest.API; +namespace DSharpPlus.Internal.Abstractions.Rest.API; /// /// Provides access to managing the built-in auto moderator via the API. diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IChannelRestAPI.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IChannelRestAPI.cs similarity index 99% rename from src/core/DSharpPlus.Core.Abstractions.Rest/API/IChannelRestAPI.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/API/IChannelRestAPI.cs index accef9bf93..a5e9766aee 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IChannelRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IChannelRestAPI.cs @@ -6,14 +6,14 @@ using System.Threading; using System.Threading.Tasks; -using DSharpPlus.Core.Abstractions.Models; -using DSharpPlus.Core.Abstractions.Rest.Payloads; -using DSharpPlus.Core.Abstractions.Rest.Queries; -using DSharpPlus.Core.Abstractions.Rest.Responses; +using DSharpPlus.Internal.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Rest.Payloads; +using DSharpPlus.Internal.Abstractions.Rest.Queries; +using DSharpPlus.Internal.Abstractions.Rest.Responses; using Remora.Results; -namespace DSharpPlus.Core.Abstractions.Rest.API; +namespace DSharpPlus.Internal.Abstractions.Rest.API; /// /// Provides access to channel-related rest API calls. diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IEmojiRestAPI.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IEmojiRestAPI.cs similarity index 96% rename from src/core/DSharpPlus.Core.Abstractions.Rest/API/IEmojiRestAPI.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/API/IEmojiRestAPI.cs index 78a99f7ed2..08ba28ec64 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IEmojiRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IEmojiRestAPI.cs @@ -6,12 +6,12 @@ using System.Threading; using System.Threading.Tasks; -using DSharpPlus.Core.Abstractions.Models; -using DSharpPlus.Core.Abstractions.Rest.Payloads; +using DSharpPlus.Internal.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Rest.Payloads; using Remora.Results; -namespace DSharpPlus.Core.Abstractions.Rest.API; +namespace DSharpPlus.Internal.Abstractions.Rest.API; /// /// Provides access to emoji-related rest API calls. diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IEntitlementsRestAPI.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IEntitlementsRestAPI.cs similarity index 93% rename from src/core/DSharpPlus.Core.Abstractions.Rest/API/IEntitlementsRestAPI.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/API/IEntitlementsRestAPI.cs index d3839951b3..c8273c3593 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IEntitlementsRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IEntitlementsRestAPI.cs @@ -6,12 +6,12 @@ using System.Threading; using System.Threading.Tasks; -using DSharpPlus.Core.Abstractions.Models; -using DSharpPlus.Core.Abstractions.Rest.Payloads; -using DSharpPlus.Core.Abstractions.Rest.Queries; +using DSharpPlus.Internal.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Rest.Payloads; +using DSharpPlus.Internal.Abstractions.Rest.Queries; using Remora.Results; -namespace DSharpPlus.Core.Abstractions.Rest.API; +namespace DSharpPlus.Internal.Abstractions.Rest.API; /// /// Provides access to entitlements-related API calls. diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IGuildRestAPI.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IGuildRestAPI.cs similarity index 99% rename from src/core/DSharpPlus.Core.Abstractions.Rest/API/IGuildRestAPI.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/API/IGuildRestAPI.cs index 14a2f7c090..009549d414 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IGuildRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IGuildRestAPI.cs @@ -7,15 +7,15 @@ using System.Threading; using System.Threading.Tasks; -using DSharpPlus.Core.Abstractions.Models; -using DSharpPlus.Core.Abstractions.Rest.Payloads; -using DSharpPlus.Core.Abstractions.Rest.Queries; -using DSharpPlus.Core.Abstractions.Rest.Responses; +using DSharpPlus.Internal.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Rest.Payloads; +using DSharpPlus.Internal.Abstractions.Rest.Queries; +using DSharpPlus.Internal.Abstractions.Rest.Responses; using DSharpPlus.Entities; using Remora.Results; -namespace DSharpPlus.Core.Abstractions.Rest.API; +namespace DSharpPlus.Internal.Abstractions.Rest.API; /// /// Provides access to guild-related rest API calls. diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IGuildScheduledEventRestAPI.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IGuildScheduledEventRestAPI.cs similarity index 96% rename from src/core/DSharpPlus.Core.Abstractions.Rest/API/IGuildScheduledEventRestAPI.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/API/IGuildScheduledEventRestAPI.cs index f27b9c63ff..3865b03e8a 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IGuildScheduledEventRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IGuildScheduledEventRestAPI.cs @@ -6,12 +6,12 @@ using System.Threading; using System.Threading.Tasks; -using DSharpPlus.Core.Abstractions.Models; -using DSharpPlus.Core.Abstractions.Rest.Payloads; -using DSharpPlus.Core.Abstractions.Rest.Queries; +using DSharpPlus.Internal.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Rest.Payloads; +using DSharpPlus.Internal.Abstractions.Rest.Queries; using Remora.Results; -namespace DSharpPlus.Core.Abstractions.Rest.API; +namespace DSharpPlus.Internal.Abstractions.Rest.API; /// /// Provides access to guild-scheduled-event-related rest API calls. diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IGuildTemplateRestAPI.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IGuildTemplateRestAPI.cs similarity index 97% rename from src/core/DSharpPlus.Core.Abstractions.Rest/API/IGuildTemplateRestAPI.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/API/IGuildTemplateRestAPI.cs index cfa3088059..a9ca68de0e 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IGuildTemplateRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IGuildTemplateRestAPI.cs @@ -6,12 +6,12 @@ using System.Threading; using System.Threading.Tasks; -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; using Remora.Results; -using DSharpPlus.Core.Abstractions.Rest.Payloads; +using DSharpPlus.Internal.Abstractions.Rest.Payloads; -namespace DSharpPlus.Core.Abstractions.Rest.API; +namespace DSharpPlus.Internal.Abstractions.Rest.API; /// /// Provides access to guild-template-related API calls. diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IInteractionRestAPI.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IInteractionRestAPI.cs similarity index 97% rename from src/core/DSharpPlus.Core.Abstractions.Rest/API/IInteractionRestAPI.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/API/IInteractionRestAPI.cs index 2d14240cf8..b63769f73d 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IInteractionRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IInteractionRestAPI.cs @@ -5,12 +5,12 @@ using System.Threading; using System.Threading.Tasks; -using DSharpPlus.Core.Abstractions.Models; -using DSharpPlus.Core.Abstractions.Rest.Payloads; +using DSharpPlus.Internal.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Rest.Payloads; using Remora.Results; -namespace DSharpPlus.Core.Abstractions.Rest.API; +namespace DSharpPlus.Internal.Abstractions.Rest.API; /// /// Provides access to interaction-related rest API calls. diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IInviteRestAPI.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IInviteRestAPI.cs similarity index 91% rename from src/core/DSharpPlus.Core.Abstractions.Rest/API/IInviteRestAPI.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/API/IInviteRestAPI.cs index 9536190a30..46f4119c4d 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IInviteRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IInviteRestAPI.cs @@ -5,12 +5,12 @@ using System.Threading; using System.Threading.Tasks; -using DSharpPlus.Core.Abstractions.Models; -using DSharpPlus.Core.Abstractions.Rest.Queries; +using DSharpPlus.Internal.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Rest.Queries; using Remora.Results; -namespace DSharpPlus.Core.Abstractions.Rest.API; +namespace DSharpPlus.Internal.Abstractions.Rest.API; /// /// Provides access to invite-related API calls. diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IRoleConnectionsRestAPI.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IRoleConnectionsRestAPI.cs similarity index 94% rename from src/core/DSharpPlus.Core.Abstractions.Rest/API/IRoleConnectionsRestAPI.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/API/IRoleConnectionsRestAPI.cs index 1261dff0ed..b453f24fe4 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IRoleConnectionsRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IRoleConnectionsRestAPI.cs @@ -6,11 +6,11 @@ using System.Threading; using System.Threading.Tasks; -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; using Remora.Results; -namespace DSharpPlus.Core.Abstractions.Rest.API; +namespace DSharpPlus.Internal.Abstractions.Rest.API; /// /// Provides access to managing role connections via the API. diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/API/ISkusRestAPI.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/ISkusRestAPI.cs similarity index 92% rename from src/core/DSharpPlus.Core.Abstractions.Rest/API/ISkusRestAPI.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/API/ISkusRestAPI.cs index c0b40bf7d2..5801cf1e77 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/API/ISkusRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/ISkusRestAPI.cs @@ -6,12 +6,12 @@ using System.Threading; using System.Threading.Tasks; -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; using Remora.Results; -namespace DSharpPlus.Core.Abstractions.Rest.API; +namespace DSharpPlus.Internal.Abstractions.Rest.API; /// /// Provides access to SKUs-related API calls. diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IStageInstanceRestAPI.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IStageInstanceRestAPI.cs similarity index 95% rename from src/core/DSharpPlus.Core.Abstractions.Rest/API/IStageInstanceRestAPI.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/API/IStageInstanceRestAPI.cs index cb1258eeae..788198d7ea 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IStageInstanceRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IStageInstanceRestAPI.cs @@ -5,12 +5,12 @@ using System.Threading; using System.Threading.Tasks; -using DSharpPlus.Core.Abstractions.Models; -using DSharpPlus.Core.Abstractions.Rest.Payloads; +using DSharpPlus.Internal.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Rest.Payloads; using Remora.Results; -namespace DSharpPlus.Core.Abstractions.Rest.API; +namespace DSharpPlus.Internal.Abstractions.Rest.API; /// /// Provides access to stage-instance-related API calls. diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IStickerRestAPI.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IStickerRestAPI.cs similarity index 95% rename from src/core/DSharpPlus.Core.Abstractions.Rest/API/IStickerRestAPI.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/API/IStickerRestAPI.cs index b228b4a436..8521f32ac7 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IStickerRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IStickerRestAPI.cs @@ -8,11 +8,11 @@ using Remora.Results; -using DSharpPlus.Core.Abstractions.Models; -using DSharpPlus.Core.Abstractions.Rest.Responses; -using DSharpPlus.Core.Abstractions.Rest.Payloads; +using DSharpPlus.Internal.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Rest.Responses; +using DSharpPlus.Internal.Abstractions.Rest.Payloads; -namespace DSharpPlus.Core.Abstractions.Rest.API; +namespace DSharpPlus.Internal.Abstractions.Rest.API; /// /// Provides access to sticker-related API calls. diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IUserRestAPI.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IUserRestAPI.cs similarity index 97% rename from src/core/DSharpPlus.Core.Abstractions.Rest/API/IUserRestAPI.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/API/IUserRestAPI.cs index 2f2f9f96fa..b10246a486 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IUserRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IUserRestAPI.cs @@ -6,12 +6,12 @@ using System.Threading; using System.Threading.Tasks; -using DSharpPlus.Core.Abstractions.Models; -using DSharpPlus.Core.Abstractions.Rest.Payloads; -using DSharpPlus.Core.Abstractions.Rest.Queries; +using DSharpPlus.Internal.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Rest.Payloads; +using DSharpPlus.Internal.Abstractions.Rest.Queries; using Remora.Results; -namespace DSharpPlus.Core.Abstractions.Rest.API; +namespace DSharpPlus.Internal.Abstractions.Rest.API; /// /// Provides access to user-related API calls. diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IVoiceRestAPI.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IVoiceRestAPI.cs similarity index 90% rename from src/core/DSharpPlus.Core.Abstractions.Rest/API/IVoiceRestAPI.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/API/IVoiceRestAPI.cs index 30131875f6..5773577cf3 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IVoiceRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IVoiceRestAPI.cs @@ -6,11 +6,11 @@ using System.Threading; using System.Threading.Tasks; -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; using Remora.Results; -namespace DSharpPlus.Core.Abstractions.Rest.API; +namespace DSharpPlus.Internal.Abstractions.Rest.API; /// /// Provides access to voice-related API calls. diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IWebhookRestAPI.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IWebhookRestAPI.cs similarity index 98% rename from src/core/DSharpPlus.Core.Abstractions.Rest/API/IWebhookRestAPI.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/API/IWebhookRestAPI.cs index 519b5f0cce..d4d79acdd0 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/API/IWebhookRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IWebhookRestAPI.cs @@ -6,12 +6,12 @@ using System.Threading; using System.Threading.Tasks; -using DSharpPlus.Core.Abstractions.Models; -using DSharpPlus.Core.Abstractions.Rest.Payloads; -using DSharpPlus.Core.Abstractions.Rest.Queries; +using DSharpPlus.Internal.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Rest.Payloads; +using DSharpPlus.Internal.Abstractions.Rest.Queries; using Remora.Results; -namespace DSharpPlus.Core.Abstractions.Rest.API; +namespace DSharpPlus.Internal.Abstractions.Rest.API; /// /// Provides access to webhook-related API calls. diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/AttachmentData.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/AttachmentData.cs similarity index 94% rename from src/core/DSharpPlus.Core.Abstractions.Rest/AttachmentData.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/AttachmentData.cs index 186dcf29b2..f62537f06b 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/AttachmentData.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/AttachmentData.cs @@ -4,7 +4,7 @@ using System.IO.Pipelines; -namespace DSharpPlus.Core.Abstractions.Rest; +namespace DSharpPlus.Internal.Abstractions.Rest; /// /// Contains the information necessary for sending an attachment to Discord. diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/DSharpPlus.Internal.Abstractions.Rest.csproj b/src/core/DSharpPlus.Internal.Abstractions.Rest/DSharpPlus.Internal.Abstractions.Rest.csproj new file mode 100644 index 0000000000..e2624cdb86 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/DSharpPlus.Internal.Abstractions.Rest.csproj @@ -0,0 +1,16 @@ + + + + $(_DSharpPlusInternalAbstractionsRestVersion) + + + + + + + + + + + + diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Errors/HttpError.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Errors/HttpError.cs similarity index 95% rename from src/core/DSharpPlus.Core.Abstractions.Rest/Errors/HttpError.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/Errors/HttpError.cs index eca0e331b9..7471b27cc2 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/Errors/HttpError.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Errors/HttpError.cs @@ -6,7 +6,7 @@ using Remora.Results; -namespace DSharpPlus.Core.Abstractions.Rest.Errors; +namespace DSharpPlus.Internal.Abstractions.Rest.Errors; /// /// Represents a HTTP error returned by an API call. diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Errors/ValidationError.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Errors/ValidationError.cs similarity index 91% rename from src/core/DSharpPlus.Core.Abstractions.Rest/Errors/ValidationError.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/Errors/ValidationError.cs index 0bf46050c9..c44bbbb328 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/Errors/ValidationError.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Errors/ValidationError.cs @@ -4,7 +4,7 @@ using Remora.Results; -namespace DSharpPlus.Core.Abstractions.Rest.Errors; +namespace DSharpPlus.Internal.Abstractions.Rest.Errors; /// /// Represents an error encountered during parameter validation. diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/IRatelimitCallbackInfo.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/IRatelimitCallbackInfo.cs similarity index 96% rename from src/core/DSharpPlus.Core.Abstractions.Rest/IRatelimitCallbackInfo.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/IRatelimitCallbackInfo.cs index 1f6ce77d15..b8628ad692 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/IRatelimitCallbackInfo.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/IRatelimitCallbackInfo.cs @@ -4,7 +4,7 @@ using System; -namespace DSharpPlus.Core.Abstractions.Rest; +namespace DSharpPlus.Internal.Abstractions.Rest; /// /// Represents information and operations on a callback. diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/ApplicationCommands/ICreateGlobalApplicationCommandPayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/ApplicationCommands/ICreateGlobalApplicationCommandPayload.cs similarity index 96% rename from src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/ApplicationCommands/ICreateGlobalApplicationCommandPayload.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/ApplicationCommands/ICreateGlobalApplicationCommandPayload.cs index 80baa2d894..0cadaa6d6d 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/ApplicationCommands/ICreateGlobalApplicationCommandPayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/ApplicationCommands/ICreateGlobalApplicationCommandPayload.cs @@ -6,7 +6,7 @@ using DSharpPlus.Entities; -namespace DSharpPlus.Core.Abstractions.Rest.Payloads; +namespace DSharpPlus.Internal.Abstractions.Rest.Payloads; /// /// Represents a payload to POST /applications/:application-id/commands. diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/ApplicationCommands/ICreateGuildApplicationCommandPayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/ApplicationCommands/ICreateGuildApplicationCommandPayload.cs similarity index 96% rename from src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/ApplicationCommands/ICreateGuildApplicationCommandPayload.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/ApplicationCommands/ICreateGuildApplicationCommandPayload.cs index f2c81300ee..cc44913849 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/ApplicationCommands/ICreateGuildApplicationCommandPayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/ApplicationCommands/ICreateGuildApplicationCommandPayload.cs @@ -6,7 +6,7 @@ using DSharpPlus.Entities; -namespace DSharpPlus.Core.Abstractions.Rest.Payloads; +namespace DSharpPlus.Internal.Abstractions.Rest.Payloads; /// /// Represents a payload to POST /applications/:application-id/guilds/:guild-id/commands diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/ApplicationCommands/IEditGlobalApplicationCommandPayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/ApplicationCommands/IEditGlobalApplicationCommandPayload.cs similarity index 96% rename from src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/ApplicationCommands/IEditGlobalApplicationCommandPayload.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/ApplicationCommands/IEditGlobalApplicationCommandPayload.cs index e04b8b71d0..f373a6c31b 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/ApplicationCommands/IEditGlobalApplicationCommandPayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/ApplicationCommands/IEditGlobalApplicationCommandPayload.cs @@ -6,7 +6,7 @@ using DSharpPlus.Entities; -namespace DSharpPlus.Core.Abstractions.Rest.Payloads; +namespace DSharpPlus.Internal.Abstractions.Rest.Payloads; /// /// Represents a payload to PATCH /applications/:application-id/commands/:command-id. diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/ApplicationCommands/IEditGuildApplicationCommandPayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/ApplicationCommands/IEditGuildApplicationCommandPayload.cs similarity index 96% rename from src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/ApplicationCommands/IEditGuildApplicationCommandPayload.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/ApplicationCommands/IEditGuildApplicationCommandPayload.cs index e3d6d83d1a..2a4a112ce6 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/ApplicationCommands/IEditGuildApplicationCommandPayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/ApplicationCommands/IEditGuildApplicationCommandPayload.cs @@ -6,7 +6,7 @@ using DSharpPlus.Entities; -namespace DSharpPlus.Core.Abstractions.Rest.Payloads; +namespace DSharpPlus.Internal.Abstractions.Rest.Payloads; /// /// Represents a payload to PATCH /applications/:application-id/guilds/:guild-id/commands/:command-id. diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Applications/IEditCurrentApplicationPayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Applications/IEditCurrentApplicationPayload.cs similarity index 94% rename from src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Applications/IEditCurrentApplicationPayload.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Applications/IEditCurrentApplicationPayload.cs index f44467cc00..5bd700ddb9 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Applications/IEditCurrentApplicationPayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Applications/IEditCurrentApplicationPayload.cs @@ -4,10 +4,10 @@ using System.Collections.Generic; -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; -namespace DSharpPlus.Core.Abstractions.Rest.Payloads; +namespace DSharpPlus.Internal.Abstractions.Rest.Payloads; /// /// Represents a payload to PATCH /applications/@me. diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/AutoModeration/ICreateAutoModerationRulePayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/AutoModeration/ICreateAutoModerationRulePayload.cs similarity index 94% rename from src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/AutoModeration/ICreateAutoModerationRulePayload.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/AutoModeration/ICreateAutoModerationRulePayload.cs index 6e1c0bd200..1116e92124 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/AutoModeration/ICreateAutoModerationRulePayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/AutoModeration/ICreateAutoModerationRulePayload.cs @@ -4,10 +4,10 @@ using System.Collections.Generic; -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; -namespace DSharpPlus.Core.Abstractions.Rest.Payloads; +namespace DSharpPlus.Internal.Abstractions.Rest.Payloads; /// /// Represents a payload to POST /guilds/:guild-id/auto-moderation/rules. diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/AutoModeration/IModifyAutoModerationRulePayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/AutoModeration/IModifyAutoModerationRulePayload.cs similarity index 93% rename from src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/AutoModeration/IModifyAutoModerationRulePayload.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/AutoModeration/IModifyAutoModerationRulePayload.cs index 9757b51903..967a6f5769 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/AutoModeration/IModifyAutoModerationRulePayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/AutoModeration/IModifyAutoModerationRulePayload.cs @@ -4,10 +4,10 @@ using System.Collections.Generic; -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; -namespace DSharpPlus.Core.Abstractions.Rest.Payloads; +namespace DSharpPlus.Internal.Abstractions.Rest.Payloads; /// /// Represents a payload to PATCH /guilds/:guild-id/auto-moderation/rules/:automod-rule-id. diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Channels/ICreateChannelInvitePayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Channels/ICreateChannelInvitePayload.cs similarity index 96% rename from src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Channels/ICreateChannelInvitePayload.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Channels/ICreateChannelInvitePayload.cs index 0787ed0a21..4ffd09452e 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Channels/ICreateChannelInvitePayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Channels/ICreateChannelInvitePayload.cs @@ -4,7 +4,7 @@ using DSharpPlus.Entities; -namespace DSharpPlus.Core.Abstractions.Rest.Payloads; +namespace DSharpPlus.Internal.Abstractions.Rest.Payloads; /// /// Represents a payload to POST /channels/:channel-id/invites. diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Channels/ICreateMessagePayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Channels/ICreateMessagePayload.cs similarity index 95% rename from src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Channels/ICreateMessagePayload.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Channels/ICreateMessagePayload.cs index 56c5dbdacd..f86155910b 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Channels/ICreateMessagePayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Channels/ICreateMessagePayload.cs @@ -4,10 +4,10 @@ using System.Collections.Generic; -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; -namespace DSharpPlus.Core.Abstractions.Rest.Payloads; +namespace DSharpPlus.Internal.Abstractions.Rest.Payloads; /// /// Represents a payload to POST /channels/:channel-id/messages. diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Channels/IEditChannelPermissionsPayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Channels/IEditChannelPermissionsPayload.cs similarity index 93% rename from src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Channels/IEditChannelPermissionsPayload.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Channels/IEditChannelPermissionsPayload.cs index 011bc0c4d2..e87a1c02a0 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Channels/IEditChannelPermissionsPayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Channels/IEditChannelPermissionsPayload.cs @@ -4,7 +4,7 @@ using DSharpPlus.Entities; -namespace DSharpPlus.Core.Abstractions.Rest.Payloads; +namespace DSharpPlus.Internal.Abstractions.Rest.Payloads; /// /// Represents a payload for PUT /channels/:channel-id/permissions/:overwrite-id. diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Channels/IEditMessagePayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Channels/IEditMessagePayload.cs similarity index 94% rename from src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Channels/IEditMessagePayload.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Channels/IEditMessagePayload.cs index 006b53ec41..f696c4b163 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Channels/IEditMessagePayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Channels/IEditMessagePayload.cs @@ -4,10 +4,10 @@ using System.Collections.Generic; -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; -namespace DSharpPlus.Core.Abstractions.Rest.Payloads; +namespace DSharpPlus.Internal.Abstractions.Rest.Payloads; /// /// Represents a payload to PATCH /channels/:channel-id/messages/:message-id. diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Channels/IFollowAnnouncementChannelPayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Channels/IFollowAnnouncementChannelPayload.cs similarity index 90% rename from src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Channels/IFollowAnnouncementChannelPayload.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Channels/IFollowAnnouncementChannelPayload.cs index e4193cf65c..a91be97937 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Channels/IFollowAnnouncementChannelPayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Channels/IFollowAnnouncementChannelPayload.cs @@ -2,7 +2,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -namespace DSharpPlus.Core.Abstractions.Rest.Payloads; +namespace DSharpPlus.Internal.Abstractions.Rest.Payloads; /// /// Represents a payload to POST /channels/:channel-id/followers diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Channels/IForumAndMediaThreadMessage.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Channels/IForumAndMediaThreadMessage.cs similarity index 93% rename from src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Channels/IForumAndMediaThreadMessage.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Channels/IForumAndMediaThreadMessage.cs index 25dc1a563a..7d7ec6e064 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Channels/IForumAndMediaThreadMessage.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Channels/IForumAndMediaThreadMessage.cs @@ -4,10 +4,10 @@ using System.Collections.Generic; -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; -namespace DSharpPlus.Core.Abstractions.Rest.Payloads; +namespace DSharpPlus.Internal.Abstractions.Rest.Payloads; public interface IForumAndMediaThreadMessage { diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Channels/IGroupDMAddRecipientPayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Channels/IGroupDMAddRecipientPayload.cs similarity index 91% rename from src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Channels/IGroupDMAddRecipientPayload.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Channels/IGroupDMAddRecipientPayload.cs index 4b570be1c9..6999f059da 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Channels/IGroupDMAddRecipientPayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Channels/IGroupDMAddRecipientPayload.cs @@ -2,7 +2,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -namespace DSharpPlus.Core.Abstractions.Rest.Payloads; +namespace DSharpPlus.Internal.Abstractions.Rest.Payloads; /// /// Represents a payload to PUT /channel/:channel-id/recipients/:user-id. diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Channels/IModifyGroupDMPayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Channels/IModifyGroupDMPayload.cs similarity index 91% rename from src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Channels/IModifyGroupDMPayload.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Channels/IModifyGroupDMPayload.cs index 045769bab0..3080cc9f8f 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Channels/IModifyGroupDMPayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Channels/IModifyGroupDMPayload.cs @@ -2,7 +2,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -namespace DSharpPlus.Core.Abstractions.Rest.Payloads; +namespace DSharpPlus.Internal.Abstractions.Rest.Payloads; /// /// Represents a payload to PATCH /channels/:channel-id. diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Channels/IModifyGuildChannelPayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Channels/IModifyGuildChannelPayload.cs similarity index 97% rename from src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Channels/IModifyGuildChannelPayload.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Channels/IModifyGuildChannelPayload.cs index 9845e58bfa..c9dc78c9af 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Channels/IModifyGuildChannelPayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Channels/IModifyGuildChannelPayload.cs @@ -4,10 +4,10 @@ using System.Collections.Generic; -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; -namespace DSharpPlus.Core.Abstractions.Rest.Payloads; +namespace DSharpPlus.Internal.Abstractions.Rest.Payloads; /// /// Represents a payload to PATCH /channels/:channel-id. diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Channels/IModifyThreadChannelPayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Channels/IModifyThreadChannelPayload.cs similarity index 96% rename from src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Channels/IModifyThreadChannelPayload.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Channels/IModifyThreadChannelPayload.cs index 73e4e788a3..4e908e9121 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Channels/IModifyThreadChannelPayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Channels/IModifyThreadChannelPayload.cs @@ -6,7 +6,7 @@ using DSharpPlus.Entities; -namespace DSharpPlus.Core.Abstractions.Rest.Payloads; +namespace DSharpPlus.Internal.Abstractions.Rest.Payloads; /// /// Represents a payload to PATCH /channels/:channel-id. diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Channels/IStartThreadFromMessagePayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Channels/IStartThreadFromMessagePayload.cs similarity index 93% rename from src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Channels/IStartThreadFromMessagePayload.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Channels/IStartThreadFromMessagePayload.cs index 39d9599891..5270f0a558 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Channels/IStartThreadFromMessagePayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Channels/IStartThreadFromMessagePayload.cs @@ -2,7 +2,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -namespace DSharpPlus.Core.Abstractions.Rest.Payloads; +namespace DSharpPlus.Internal.Abstractions.Rest.Payloads; /// /// Represents a payload to POST /channels/:channel-id/messages/:message-id/threads. diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Channels/IStartThreadInForumOrMediaChannelPayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Channels/IStartThreadInForumOrMediaChannelPayload.cs similarity index 95% rename from src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Channels/IStartThreadInForumOrMediaChannelPayload.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Channels/IStartThreadInForumOrMediaChannelPayload.cs index 4beb914d6b..e8cf50cb31 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Channels/IStartThreadInForumOrMediaChannelPayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Channels/IStartThreadInForumOrMediaChannelPayload.cs @@ -4,7 +4,7 @@ using System.Collections.Generic; -namespace DSharpPlus.Core.Abstractions.Rest.Payloads; +namespace DSharpPlus.Internal.Abstractions.Rest.Payloads; /// /// Represents a payload to POST /channels/:channel-id/threads. diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Channels/IStartThreadWithoutMessagePayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Channels/IStartThreadWithoutMessagePayload.cs similarity index 95% rename from src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Channels/IStartThreadWithoutMessagePayload.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Channels/IStartThreadWithoutMessagePayload.cs index a1facf651a..afa89696d5 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Channels/IStartThreadWithoutMessagePayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Channels/IStartThreadWithoutMessagePayload.cs @@ -4,7 +4,7 @@ using DSharpPlus.Entities; -namespace DSharpPlus.Core.Abstractions.Rest.Payloads; +namespace DSharpPlus.Internal.Abstractions.Rest.Payloads; /// /// Represents a payload to POST /channels/:channel-id/threads. diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Emojis/ICreateGuildEmojiPayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Emojis/ICreateGuildEmojiPayload.cs similarity index 92% rename from src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Emojis/ICreateGuildEmojiPayload.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Emojis/ICreateGuildEmojiPayload.cs index 4a6c47362c..6fc34c6cc7 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Emojis/ICreateGuildEmojiPayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Emojis/ICreateGuildEmojiPayload.cs @@ -4,7 +4,7 @@ using System.Collections.Generic; -namespace DSharpPlus.Core.Abstractions.Rest.Payloads; +namespace DSharpPlus.Internal.Abstractions.Rest.Payloads; /// /// Represents a payload to POST /guilds/:guild-id/emojis. diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Emojis/IModifyGuildEmojiPayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Emojis/IModifyGuildEmojiPayload.cs similarity index 92% rename from src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Emojis/IModifyGuildEmojiPayload.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Emojis/IModifyGuildEmojiPayload.cs index 89c242ba1a..03cc3d17c1 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Emojis/IModifyGuildEmojiPayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Emojis/IModifyGuildEmojiPayload.cs @@ -4,7 +4,7 @@ using System.Collections.Generic; -namespace DSharpPlus.Core.Abstractions.Rest.Payloads; +namespace DSharpPlus.Internal.Abstractions.Rest.Payloads; /// /// Represents a payload to PATCH /guilds/:guild-id/emojis/:emoji-id. diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Entitlements/ICreateTestEntitlementPayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Entitlements/ICreateTestEntitlementPayload.cs similarity index 93% rename from src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Entitlements/ICreateTestEntitlementPayload.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Entitlements/ICreateTestEntitlementPayload.cs index d0c640e7bd..fe8082b1ac 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Entitlements/ICreateTestEntitlementPayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Entitlements/ICreateTestEntitlementPayload.cs @@ -4,7 +4,7 @@ using DSharpPlus.Entities; -namespace DSharpPlus.Core.Abstractions.Rest.Payloads; +namespace DSharpPlus.Internal.Abstractions.Rest.Payloads; /// /// Represents a payload to POST /applications/:application-id/entitlements. diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/GuildTemplates/ICreateGuildFromGuildTemplatePayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/GuildTemplates/ICreateGuildFromGuildTemplatePayload.cs similarity index 91% rename from src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/GuildTemplates/ICreateGuildFromGuildTemplatePayload.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/GuildTemplates/ICreateGuildFromGuildTemplatePayload.cs index 1c8bfb3faa..9883ddbe5c 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/GuildTemplates/ICreateGuildFromGuildTemplatePayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/GuildTemplates/ICreateGuildFromGuildTemplatePayload.cs @@ -2,7 +2,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -namespace DSharpPlus.Core.Abstractions.Rest.Payloads; +namespace DSharpPlus.Internal.Abstractions.Rest.Payloads; /// /// Represents a payload to POST /guilds/templates/:template-code. diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/GuildTemplates/ICreateGuildTemplatePayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/GuildTemplates/ICreateGuildTemplatePayload.cs similarity index 91% rename from src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/GuildTemplates/ICreateGuildTemplatePayload.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/GuildTemplates/ICreateGuildTemplatePayload.cs index d8233a51a2..53ed8ffe28 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/GuildTemplates/ICreateGuildTemplatePayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/GuildTemplates/ICreateGuildTemplatePayload.cs @@ -2,7 +2,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -namespace DSharpPlus.Core.Abstractions.Rest.Payloads; +namespace DSharpPlus.Internal.Abstractions.Rest.Payloads; /// /// Represents a payload to POST /guilds/:guild-id/templates diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/GuildTemplates/IModifyGuildTemplatePayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/GuildTemplates/IModifyGuildTemplatePayload.cs similarity index 91% rename from src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/GuildTemplates/IModifyGuildTemplatePayload.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/GuildTemplates/IModifyGuildTemplatePayload.cs index 36399b2197..b68e789309 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/GuildTemplates/IModifyGuildTemplatePayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/GuildTemplates/IModifyGuildTemplatePayload.cs @@ -2,7 +2,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -namespace DSharpPlus.Core.Abstractions.Rest.Payloads; +namespace DSharpPlus.Internal.Abstractions.Rest.Payloads; /// /// Represents a payload to POST /guilds/:guild-id/templates diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Guilds/IAddGuildMemberPayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Guilds/IAddGuildMemberPayload.cs similarity index 94% rename from src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Guilds/IAddGuildMemberPayload.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Guilds/IAddGuildMemberPayload.cs index 6fd694c92b..5e7938e387 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Guilds/IAddGuildMemberPayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Guilds/IAddGuildMemberPayload.cs @@ -4,7 +4,7 @@ using System.Collections.Generic; -namespace DSharpPlus.Core.Abstractions.Rest.Payloads; +namespace DSharpPlus.Internal.Abstractions.Rest.Payloads; /// /// Represents a payload to PUT /guilds/:guild-id/members/:user-id. diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Guilds/ICreateGuildChannelPayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Guilds/ICreateGuildChannelPayload.cs similarity index 96% rename from src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Guilds/ICreateGuildChannelPayload.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Guilds/ICreateGuildChannelPayload.cs index 79cec71d63..9dbdbcb83d 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Guilds/ICreateGuildChannelPayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Guilds/ICreateGuildChannelPayload.cs @@ -4,10 +4,10 @@ using System.Collections.Generic; -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; -namespace DSharpPlus.Core.Abstractions.Rest.Payloads; +namespace DSharpPlus.Internal.Abstractions.Rest.Payloads; /// /// Represents a payload to POST /guilds/:guild-id/channels. diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Guilds/ICreateGuildPayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Guilds/ICreateGuildPayload.cs similarity index 96% rename from src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Guilds/ICreateGuildPayload.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Guilds/ICreateGuildPayload.cs index aec837ce32..eb5b4c2324 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Guilds/ICreateGuildPayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Guilds/ICreateGuildPayload.cs @@ -4,10 +4,10 @@ using System.Collections.Generic; -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; -namespace DSharpPlus.Core.Abstractions.Rest.Payloads; +namespace DSharpPlus.Internal.Abstractions.Rest.Payloads; /// /// Represents a payload to POST /guilds. diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Guilds/ICreateGuildRolePayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Guilds/ICreateGuildRolePayload.cs similarity index 96% rename from src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Guilds/ICreateGuildRolePayload.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Guilds/ICreateGuildRolePayload.cs index e89ab80fde..def297f844 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Guilds/ICreateGuildRolePayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Guilds/ICreateGuildRolePayload.cs @@ -4,7 +4,7 @@ using DSharpPlus.Entities; -namespace DSharpPlus.Core.Abstractions.Rest.Payloads; +namespace DSharpPlus.Internal.Abstractions.Rest.Payloads; /// /// Represents a payload to POST /guilds/:guild-id/roles diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Guilds/IModifyCurrentMemberPayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Guilds/IModifyCurrentMemberPayload.cs similarity index 89% rename from src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Guilds/IModifyCurrentMemberPayload.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Guilds/IModifyCurrentMemberPayload.cs index 73b8b8bc7c..0a2c699bf1 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Guilds/IModifyCurrentMemberPayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Guilds/IModifyCurrentMemberPayload.cs @@ -2,7 +2,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -namespace DSharpPlus.Core.Abstractions.Rest.Payloads; +namespace DSharpPlus.Internal.Abstractions.Rest.Payloads; /// /// Represents a payload to PATCH /guilds/:guild-id/members/@me. diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Guilds/IModifyCurrentUserVoiceStatePayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Guilds/IModifyCurrentUserVoiceStatePayload.cs similarity index 93% rename from src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Guilds/IModifyCurrentUserVoiceStatePayload.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Guilds/IModifyCurrentUserVoiceStatePayload.cs index ba732cf132..dcf3cefe39 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Guilds/IModifyCurrentUserVoiceStatePayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Guilds/IModifyCurrentUserVoiceStatePayload.cs @@ -4,7 +4,7 @@ using System; -namespace DSharpPlus.Core.Abstractions.Rest.Payloads; +namespace DSharpPlus.Internal.Abstractions.Rest.Payloads; /// /// Represents a payload to PATCH /guilds/:guild-id/voice-states/@me. diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Guilds/IModifyGuildChannelPositionsPayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Guilds/IModifyGuildChannelPositionsPayload.cs similarity index 94% rename from src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Guilds/IModifyGuildChannelPositionsPayload.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Guilds/IModifyGuildChannelPositionsPayload.cs index 3f1060652f..f97e5a2b30 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Guilds/IModifyGuildChannelPositionsPayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Guilds/IModifyGuildChannelPositionsPayload.cs @@ -2,7 +2,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -namespace DSharpPlus.Core.Abstractions.Rest.Payloads; +namespace DSharpPlus.Internal.Abstractions.Rest.Payloads; /// /// Represents a payload to PATCH /guilds/:guild-id/channels. diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Guilds/IModifyGuildMemberPayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Guilds/IModifyGuildMemberPayload.cs similarity index 95% rename from src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Guilds/IModifyGuildMemberPayload.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Guilds/IModifyGuildMemberPayload.cs index 39020a01b9..223cc0a1b1 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Guilds/IModifyGuildMemberPayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Guilds/IModifyGuildMemberPayload.cs @@ -5,7 +5,7 @@ using System; using System.Collections.Generic; -namespace DSharpPlus.Core.Abstractions.Rest.Payloads; +namespace DSharpPlus.Internal.Abstractions.Rest.Payloads; /// /// Represents a payload to PATCH /guilds/:guild-id/members/:user-id. diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Guilds/IModifyGuildMfaLevelPayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Guilds/IModifyGuildMfaLevelPayload.cs similarity index 89% rename from src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Guilds/IModifyGuildMfaLevelPayload.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Guilds/IModifyGuildMfaLevelPayload.cs index 31e91fe250..e00f81213d 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Guilds/IModifyGuildMfaLevelPayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Guilds/IModifyGuildMfaLevelPayload.cs @@ -4,7 +4,7 @@ using DSharpPlus.Entities; -namespace DSharpPlus.Core.Abstractions.Rest.Payloads; +namespace DSharpPlus.Internal.Abstractions.Rest.Payloads; /// /// Represents a payload to POST /guilds/:guild-id/mfa. diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Guilds/IModifyGuildOnboardingPayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Guilds/IModifyGuildOnboardingPayload.cs similarity index 90% rename from src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Guilds/IModifyGuildOnboardingPayload.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Guilds/IModifyGuildOnboardingPayload.cs index 48de580a0a..217e8f2160 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Guilds/IModifyGuildOnboardingPayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Guilds/IModifyGuildOnboardingPayload.cs @@ -4,10 +4,10 @@ using System.Collections.Generic; -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; -namespace DSharpPlus.Core.Abstractions.Rest.Payloads; +namespace DSharpPlus.Internal.Abstractions.Rest.Payloads; /// /// Represents a payload to PUT /guilds/:guild-id/onboarding. diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Guilds/IModifyGuildPayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Guilds/IModifyGuildPayload.cs similarity index 98% rename from src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Guilds/IModifyGuildPayload.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Guilds/IModifyGuildPayload.cs index 18998e48cf..eac9bbe2ba 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Guilds/IModifyGuildPayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Guilds/IModifyGuildPayload.cs @@ -6,7 +6,7 @@ using DSharpPlus.Entities; -namespace DSharpPlus.Core.Abstractions.Rest.Payloads; +namespace DSharpPlus.Internal.Abstractions.Rest.Payloads; /// /// Represents a payload to PATCH /guilds/:guild-id. diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Guilds/IModifyGuildRolePayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Guilds/IModifyGuildRolePayload.cs similarity index 96% rename from src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Guilds/IModifyGuildRolePayload.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Guilds/IModifyGuildRolePayload.cs index 1b6f3359e0..284f3077e2 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Guilds/IModifyGuildRolePayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Guilds/IModifyGuildRolePayload.cs @@ -4,7 +4,7 @@ using DSharpPlus.Entities; -namespace DSharpPlus.Core.Abstractions.Rest.Payloads; +namespace DSharpPlus.Internal.Abstractions.Rest.Payloads; /// /// Represents a payload to PATCH /guilds/:guild-id/roles/:role-id diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Guilds/IModifyGuildRolePositionsPayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Guilds/IModifyGuildRolePositionsPayload.cs similarity index 91% rename from src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Guilds/IModifyGuildRolePositionsPayload.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Guilds/IModifyGuildRolePositionsPayload.cs index 0db3abd999..6e10722554 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Guilds/IModifyGuildRolePositionsPayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Guilds/IModifyGuildRolePositionsPayload.cs @@ -2,7 +2,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -namespace DSharpPlus.Core.Abstractions.Rest.Payloads; +namespace DSharpPlus.Internal.Abstractions.Rest.Payloads; /// /// Represents a payload to PATCH /guilds/:guild-id/roles. diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Guilds/IModifyGuildWelcomeScreenPayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Guilds/IModifyGuildWelcomeScreenPayload.cs similarity index 89% rename from src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Guilds/IModifyGuildWelcomeScreenPayload.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Guilds/IModifyGuildWelcomeScreenPayload.cs index 6b32d5b823..6af4b8f7e0 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Guilds/IModifyGuildWelcomeScreenPayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Guilds/IModifyGuildWelcomeScreenPayload.cs @@ -4,9 +4,9 @@ using System.Collections.Generic; -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; -namespace DSharpPlus.Core.Abstractions.Rest.Payloads; +namespace DSharpPlus.Internal.Abstractions.Rest.Payloads; /// /// Represents a payload to PATCH /guilds/:guild-id/welcome-screen. diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Guilds/IModifyUserVoiceStatePayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Guilds/IModifyUserVoiceStatePayload.cs similarity index 91% rename from src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Guilds/IModifyUserVoiceStatePayload.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Guilds/IModifyUserVoiceStatePayload.cs index 221574a2a4..8c9debfdd3 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Guilds/IModifyUserVoiceStatePayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Guilds/IModifyUserVoiceStatePayload.cs @@ -2,7 +2,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -namespace DSharpPlus.Core.Abstractions.Rest.Payloads; +namespace DSharpPlus.Internal.Abstractions.Rest.Payloads; /// /// Represents a payload to PATCH /guilds/:guild-id/voice-states/:user-id. diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Interactions/ICreateFollowupMessagePayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Interactions/ICreateFollowupMessagePayload.cs similarity index 94% rename from src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Interactions/ICreateFollowupMessagePayload.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Interactions/ICreateFollowupMessagePayload.cs index 15e7f72296..8767afda47 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Interactions/ICreateFollowupMessagePayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Interactions/ICreateFollowupMessagePayload.cs @@ -4,10 +4,10 @@ using System.Collections.Generic; -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; -namespace DSharpPlus.Core.Abstractions.Rest.Payloads; +namespace DSharpPlus.Internal.Abstractions.Rest.Payloads; /// /// Represents a payload to POST /webhooks/:application-id/:interaction-token. diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Interactions/IEditFollowupMessagePayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Interactions/IEditFollowupMessagePayload.cs similarity index 92% rename from src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Interactions/IEditFollowupMessagePayload.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Interactions/IEditFollowupMessagePayload.cs index a7447d767a..26d07f0f69 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Interactions/IEditFollowupMessagePayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Interactions/IEditFollowupMessagePayload.cs @@ -4,9 +4,9 @@ using System.Collections.Generic; -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; -namespace DSharpPlus.Core.Abstractions.Rest.Payloads; +namespace DSharpPlus.Internal.Abstractions.Rest.Payloads; /// /// Represents a payload to PATCH /webhooks/:application-id/:interaction-token/messages/:message-id. diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Interactions/IEditInteractionResponsePayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Interactions/IEditInteractionResponsePayload.cs similarity index 92% rename from src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Interactions/IEditInteractionResponsePayload.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Interactions/IEditInteractionResponsePayload.cs index 8ac4a7351a..9ec9fbab2a 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Interactions/IEditInteractionResponsePayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Interactions/IEditInteractionResponsePayload.cs @@ -4,9 +4,9 @@ using System.Collections.Generic; -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; -namespace DSharpPlus.Core.Abstractions.Rest.Payloads; +namespace DSharpPlus.Internal.Abstractions.Rest.Payloads; /// /// Represents a payload to PATCH /webhooks/:application-id/:interaction-token/messages/@original. diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/ScheduledEvents/ICreateGuildScheduledEventPayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/ScheduledEvents/ICreateGuildScheduledEventPayload.cs similarity index 94% rename from src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/ScheduledEvents/ICreateGuildScheduledEventPayload.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/ScheduledEvents/ICreateGuildScheduledEventPayload.cs index dcb9df80fc..fdfe3624c4 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/ScheduledEvents/ICreateGuildScheduledEventPayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/ScheduledEvents/ICreateGuildScheduledEventPayload.cs @@ -4,10 +4,10 @@ using System; -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; -namespace DSharpPlus.Core.Abstractions.Rest.Payloads; +namespace DSharpPlus.Internal.Abstractions.Rest.Payloads; /// /// Represents a payload to POST /guilds/:guild-id/scheduled-events. diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/ScheduledEvents/IModifyGuildScheduledEventPayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/ScheduledEvents/IModifyGuildScheduledEventPayload.cs similarity index 95% rename from src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/ScheduledEvents/IModifyGuildScheduledEventPayload.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/ScheduledEvents/IModifyGuildScheduledEventPayload.cs index e77915f3a3..172dd0356f 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/ScheduledEvents/IModifyGuildScheduledEventPayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/ScheduledEvents/IModifyGuildScheduledEventPayload.cs @@ -2,11 +2,11 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; using System; -namespace DSharpPlus.Core.Abstractions.Rest.Payloads; +namespace DSharpPlus.Internal.Abstractions.Rest.Payloads; /// /// Represents a payload to PATCH /guilds/:guild-id/scheduled-events/:event-id. diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/StageInstances/ICreateStageInstancePayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/StageInstances/ICreateStageInstancePayload.cs similarity index 95% rename from src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/StageInstances/ICreateStageInstancePayload.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/StageInstances/ICreateStageInstancePayload.cs index e379aabb08..5437d39bfd 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/StageInstances/ICreateStageInstancePayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/StageInstances/ICreateStageInstancePayload.cs @@ -4,7 +4,7 @@ using DSharpPlus.Entities; -namespace DSharpPlus.Core.Abstractions.Rest.Payloads; +namespace DSharpPlus.Internal.Abstractions.Rest.Payloads; /// /// Represents a payload to POST /stage-instances. diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/StageInstances/IModifyStageInstancePayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/StageInstances/IModifyStageInstancePayload.cs similarity index 92% rename from src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/StageInstances/IModifyStageInstancePayload.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/StageInstances/IModifyStageInstancePayload.cs index 849a2e8fba..dc00fa72a6 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/StageInstances/IModifyStageInstancePayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/StageInstances/IModifyStageInstancePayload.cs @@ -4,7 +4,7 @@ using DSharpPlus.Entities; -namespace DSharpPlus.Core.Abstractions.Rest.Payloads; +namespace DSharpPlus.Internal.Abstractions.Rest.Payloads; /// /// Represents a payload to PATCH /stage-instances/:channel-id. diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Stickers/ICreateGuildStickerPayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Stickers/ICreateGuildStickerPayload.cs similarity index 93% rename from src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Stickers/ICreateGuildStickerPayload.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Stickers/ICreateGuildStickerPayload.cs index acfed5d1dc..095a503b0f 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Stickers/ICreateGuildStickerPayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Stickers/ICreateGuildStickerPayload.cs @@ -2,7 +2,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -namespace DSharpPlus.Core.Abstractions.Rest.Payloads; +namespace DSharpPlus.Internal.Abstractions.Rest.Payloads; /// /// Rpresents a payload to POST /guilds/:guild-id/stickers. diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Stickers/IModifyGuildStickerPayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Stickers/IModifyGuildStickerPayload.cs similarity index 92% rename from src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Stickers/IModifyGuildStickerPayload.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Stickers/IModifyGuildStickerPayload.cs index 04730db50e..7041363cf2 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Stickers/IModifyGuildStickerPayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Stickers/IModifyGuildStickerPayload.cs @@ -2,7 +2,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -namespace DSharpPlus.Core.Abstractions.Rest.Payloads; +namespace DSharpPlus.Internal.Abstractions.Rest.Payloads; /// /// Represents a payload to PATCH /guilds/:guild-id/stickers/:sticker-id. diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Users/ICreateDmPayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Users/ICreateDmPayload.cs similarity index 89% rename from src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Users/ICreateDmPayload.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Users/ICreateDmPayload.cs index 17bbeef971..52c83c80ba 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Users/ICreateDmPayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Users/ICreateDmPayload.cs @@ -2,7 +2,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -namespace DSharpPlus.Core.Abstractions.Rest.Payloads; +namespace DSharpPlus.Internal.Abstractions.Rest.Payloads; /// /// Represents a payload to POST /users/@me/channels. diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Users/ICreateGroupDmPayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Users/ICreateGroupDmPayload.cs similarity index 92% rename from src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Users/ICreateGroupDmPayload.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Users/ICreateGroupDmPayload.cs index c00f67e518..160fb72d41 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Users/ICreateGroupDmPayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Users/ICreateGroupDmPayload.cs @@ -4,7 +4,7 @@ using System.Collections.Generic; -namespace DSharpPlus.Core.Abstractions.Rest.Payloads; +namespace DSharpPlus.Internal.Abstractions.Rest.Payloads; /// /// Represents a payload to POST /users/@me/channels. diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Users/IModifyCurrentUserPayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Users/IModifyCurrentUserPayload.cs similarity index 93% rename from src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Users/IModifyCurrentUserPayload.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Users/IModifyCurrentUserPayload.cs index dec4a226d7..b8cdaed12e 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Users/IModifyCurrentUserPayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Users/IModifyCurrentUserPayload.cs @@ -2,7 +2,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -namespace DSharpPlus.Core.Abstractions.Rest.Payloads; +namespace DSharpPlus.Internal.Abstractions.Rest.Payloads; /// /// Represents a payload to PATCH /users/@me. diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Users/IUpdateCurrentUserApplicationRoleConnectionPayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Users/IUpdateCurrentUserApplicationRoleConnectionPayload.cs similarity index 93% rename from src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Users/IUpdateCurrentUserApplicationRoleConnectionPayload.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Users/IUpdateCurrentUserApplicationRoleConnectionPayload.cs index 65be2bffda..9cc9698324 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Users/IUpdateCurrentUserApplicationRoleConnectionPayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Users/IUpdateCurrentUserApplicationRoleConnectionPayload.cs @@ -2,7 +2,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -namespace DSharpPlus.Core.Abstractions.Rest.Payloads; +namespace DSharpPlus.Internal.Abstractions.Rest.Payloads; /// /// Represents a payload to PUT /users/@me/applications/:application-id/role-connection. diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Webhooks/ICreateWebhookPayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Webhooks/ICreateWebhookPayload.cs similarity index 95% rename from src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Webhooks/ICreateWebhookPayload.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Webhooks/ICreateWebhookPayload.cs index 89ebf5d676..88f35f6108 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Webhooks/ICreateWebhookPayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Webhooks/ICreateWebhookPayload.cs @@ -2,7 +2,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -namespace DSharpPlus.Core.Abstractions.Rest.Payloads; +namespace DSharpPlus.Internal.Abstractions.Rest.Payloads; /// /// Represents a payload to POST /channels/:channel-id/webhooks. diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Webhooks/IEditWebhookMessagePayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Webhooks/IEditWebhookMessagePayload.cs similarity index 93% rename from src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Webhooks/IEditWebhookMessagePayload.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Webhooks/IEditWebhookMessagePayload.cs index 080e36965a..81dde617bb 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Webhooks/IEditWebhookMessagePayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Webhooks/IEditWebhookMessagePayload.cs @@ -4,9 +4,9 @@ using System.Collections.Generic; -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; -namespace DSharpPlus.Core.Abstractions.Rest.Payloads; +namespace DSharpPlus.Internal.Abstractions.Rest.Payloads; /// /// Represents a payload to PATCH /webhooks/:webhook-id/:webhook-token/messages/:message-id. diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Webhooks/IExecuteWebhookPayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Webhooks/IExecuteWebhookPayload.cs similarity index 95% rename from src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Webhooks/IExecuteWebhookPayload.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Webhooks/IExecuteWebhookPayload.cs index 306d051d95..645bba9730 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Webhooks/IExecuteWebhookPayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Webhooks/IExecuteWebhookPayload.cs @@ -4,10 +4,10 @@ using System.Collections.Generic; -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; -namespace DSharpPlus.Core.Abstractions.Rest.Payloads; +namespace DSharpPlus.Internal.Abstractions.Rest.Payloads; /// /// Represents a payload to POST /webhooks/:webhook-id/:webhook-token. diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Webhooks/IModifyWebhookPayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Webhooks/IModifyWebhookPayload.cs similarity index 92% rename from src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Webhooks/IModifyWebhookPayload.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Webhooks/IModifyWebhookPayload.cs index 5fd1d657be..051cfb84da 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Webhooks/IModifyWebhookPayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Webhooks/IModifyWebhookPayload.cs @@ -2,7 +2,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -namespace DSharpPlus.Core.Abstractions.Rest.Payloads; +namespace DSharpPlus.Internal.Abstractions.Rest.Payloads; /// /// Represents a payload to PATCH /webhooks/:webhook-id. diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Webhooks/IModifyWebhookWithTokenPayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Webhooks/IModifyWebhookWithTokenPayload.cs similarity index 91% rename from src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Webhooks/IModifyWebhookWithTokenPayload.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Webhooks/IModifyWebhookWithTokenPayload.cs index d7963b45cc..b738a52af5 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/Payloads/Webhooks/IModifyWebhookWithTokenPayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Webhooks/IModifyWebhookWithTokenPayload.cs @@ -2,7 +2,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -namespace DSharpPlus.Core.Abstractions.Rest.Payloads; +namespace DSharpPlus.Internal.Abstractions.Rest.Payloads; /// /// Represents a payload to PATCH /webhooks/:webhook-id/:webhook-token. diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/ApplicationCommands/LocalizationQuery.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/ApplicationCommands/LocalizationQuery.cs similarity index 91% rename from src/core/DSharpPlus.Core.Abstractions.Rest/Queries/ApplicationCommands/LocalizationQuery.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/ApplicationCommands/LocalizationQuery.cs index 0b11449a0c..c23d63e641 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/ApplicationCommands/LocalizationQuery.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/ApplicationCommands/LocalizationQuery.cs @@ -2,7 +2,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -namespace DSharpPlus.Core.Abstractions.Rest.Queries; +namespace DSharpPlus.Internal.Abstractions.Rest.Queries; /// /// Contains query parameters for application command endpoints that can include localizations diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/AuditLogs/ListGuildAuditLogEntriesQuery.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/AuditLogs/ListGuildAuditLogEntriesQuery.cs similarity index 95% rename from src/core/DSharpPlus.Core.Abstractions.Rest/Queries/AuditLogs/ListGuildAuditLogEntriesQuery.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/AuditLogs/ListGuildAuditLogEntriesQuery.cs index 1729ff421f..602fc06e3d 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/AuditLogs/ListGuildAuditLogEntriesQuery.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/AuditLogs/ListGuildAuditLogEntriesQuery.cs @@ -4,7 +4,7 @@ using DSharpPlus.Entities; -namespace DSharpPlus.Core.Abstractions.Rest.Queries; +namespace DSharpPlus.Internal.Abstractions.Rest.Queries; /// /// Contains the query parameters to IAuditLogsRestAPI.ListGuildAuditLogEntriesAsync. diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Channels/GetChannelMessagesQuery.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Channels/GetChannelMessagesQuery.cs similarity index 95% rename from src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Channels/GetChannelMessagesQuery.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Channels/GetChannelMessagesQuery.cs index f2fb668d89..ad429c22eb 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Channels/GetChannelMessagesQuery.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Channels/GetChannelMessagesQuery.cs @@ -2,7 +2,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -namespace DSharpPlus.Core.Abstractions.Rest.Queries; +namespace DSharpPlus.Internal.Abstractions.Rest.Queries; /// /// Contains query parameters for IChannelRestAPI.GetChannelMessagesAsync. diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Channels/GetThreadMemberQuery.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Channels/GetThreadMemberQuery.cs similarity index 90% rename from src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Channels/GetThreadMemberQuery.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Channels/GetThreadMemberQuery.cs index 21c8ed1ddb..1f67636c69 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Channels/GetThreadMemberQuery.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Channels/GetThreadMemberQuery.cs @@ -2,7 +2,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -namespace DSharpPlus.Core.Abstractions.Rest.Queries; +namespace DSharpPlus.Internal.Abstractions.Rest.Queries; /// /// Contains the query parameters for IChannelRestAPI.GetThreadMemberAsync. diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Channels/ListArchivedThreadsQuery.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Channels/ListArchivedThreadsQuery.cs similarity index 92% rename from src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Channels/ListArchivedThreadsQuery.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Channels/ListArchivedThreadsQuery.cs index e5b5347fc4..3dd7b75d0e 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Channels/ListArchivedThreadsQuery.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Channels/ListArchivedThreadsQuery.cs @@ -4,7 +4,7 @@ using System; -namespace DSharpPlus.Core.Abstractions.Rest.Queries; +namespace DSharpPlus.Internal.Abstractions.Rest.Queries; /// /// Contains the query parameters for endpoints listing archived threads. diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Channels/ListThreadMembersQuery.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Channels/ListThreadMembersQuery.cs similarity index 93% rename from src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Channels/ListThreadMembersQuery.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Channels/ListThreadMembersQuery.cs index ff867b560e..79ca3fd520 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Channels/ListThreadMembersQuery.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Channels/ListThreadMembersQuery.cs @@ -2,7 +2,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -namespace DSharpPlus.Core.Abstractions.Rest.Queries; +namespace DSharpPlus.Internal.Abstractions.Rest.Queries; /// /// Contains the query parameters for IChannelRestAPI.ListThreadMembersAsync. diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Entitlements/ListEntitlementsQuery.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Entitlements/ListEntitlementsQuery.cs similarity index 95% rename from src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Entitlements/ListEntitlementsQuery.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Entitlements/ListEntitlementsQuery.cs index f174e7cb6f..e9eecc0aff 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Entitlements/ListEntitlementsQuery.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Entitlements/ListEntitlementsQuery.cs @@ -2,7 +2,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -namespace DSharpPlus.Core.Abstractions.Rest.Queries; +namespace DSharpPlus.Internal.Abstractions.Rest.Queries; /// /// Contains the query parameters to IEntitlementsRestAPI.ListEntitlementsAsync. diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/ForwardsPaginatedQuery.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/ForwardsPaginatedQuery.cs similarity index 90% rename from src/core/DSharpPlus.Core.Abstractions.Rest/Queries/ForwardsPaginatedQuery.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/ForwardsPaginatedQuery.cs index b390fcf748..ee1a7832b7 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/ForwardsPaginatedQuery.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/ForwardsPaginatedQuery.cs @@ -2,7 +2,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -namespace DSharpPlus.Core.Abstractions.Rest.Queries; +namespace DSharpPlus.Internal.Abstractions.Rest.Queries; public readonly record struct ForwardsPaginatedQuery { diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Guilds/BanMemberQuery.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Guilds/BanMemberQuery.cs similarity index 89% rename from src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Guilds/BanMemberQuery.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Guilds/BanMemberQuery.cs index 6a7a4bebff..9de7b944b6 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Guilds/BanMemberQuery.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Guilds/BanMemberQuery.cs @@ -2,7 +2,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -namespace DSharpPlus.Core.Abstractions.Rest.Queries; +namespace DSharpPlus.Internal.Abstractions.Rest.Queries; public readonly record struct BanMemberQuery { diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Guilds/BeginGuildPruneQuery.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Guilds/BeginGuildPruneQuery.cs similarity index 94% rename from src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Guilds/BeginGuildPruneQuery.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Guilds/BeginGuildPruneQuery.cs index 11f89343bd..2136b59f7a 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Guilds/BeginGuildPruneQuery.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Guilds/BeginGuildPruneQuery.cs @@ -2,7 +2,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -namespace DSharpPlus.Core.Abstractions.Rest.Queries; +namespace DSharpPlus.Internal.Abstractions.Rest.Queries; /// /// Contains the query parameters for IGuildRestAPI.BeginGuildPruneAsync. diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Guilds/GetGuildPruneCountQuery.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Guilds/GetGuildPruneCountQuery.cs similarity index 93% rename from src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Guilds/GetGuildPruneCountQuery.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Guilds/GetGuildPruneCountQuery.cs index f35dea5bfb..92ed1d7b41 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Guilds/GetGuildPruneCountQuery.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Guilds/GetGuildPruneCountQuery.cs @@ -2,7 +2,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -namespace DSharpPlus.Core.Abstractions.Rest.Queries; +namespace DSharpPlus.Internal.Abstractions.Rest.Queries; /// /// Contains the query parameters for IGuildRestAPI.GetGuildPruneCountAsync. diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Guilds/GetGuildQuery.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Guilds/GetGuildQuery.cs similarity index 89% rename from src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Guilds/GetGuildQuery.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Guilds/GetGuildQuery.cs index 6cea1d5e82..abad8372f4 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Guilds/GetGuildQuery.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Guilds/GetGuildQuery.cs @@ -2,7 +2,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -namespace DSharpPlus.Core.Abstractions.Rest.Queries; +namespace DSharpPlus.Internal.Abstractions.Rest.Queries; /// /// Contains query parameters for IGuildRestAPI.GetGuildAsync. diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Guilds/SearchGuildMembersQuery.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Guilds/SearchGuildMembersQuery.cs similarity index 90% rename from src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Guilds/SearchGuildMembersQuery.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Guilds/SearchGuildMembersQuery.cs index 479637ecb6..24083f754f 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Guilds/SearchGuildMembersQuery.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Guilds/SearchGuildMembersQuery.cs @@ -2,7 +2,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -namespace DSharpPlus.Core.Abstractions.Rest.Queries; +namespace DSharpPlus.Internal.Abstractions.Rest.Queries; /// /// Contains the query parameters to IGuildRestAPI.SearchGuildMembersAsync. This request cannot diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/IPaginatedQuery.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/IPaginatedQuery.cs similarity index 94% rename from src/core/DSharpPlus.Core.Abstractions.Rest/Queries/IPaginatedQuery.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/IPaginatedQuery.cs index e8b0ab45f8..c6f687ee9a 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/IPaginatedQuery.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/IPaginatedQuery.cs @@ -2,7 +2,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -namespace DSharpPlus.Core.Abstractions.Rest.Queries; +namespace DSharpPlus.Internal.Abstractions.Rest.Queries; /// /// Represents a base interface for all snowflake-paginated queries, for user convenience. diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Invites/GetInviteQuery.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Invites/GetInviteQuery.cs similarity index 93% rename from src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Invites/GetInviteQuery.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Invites/GetInviteQuery.cs index 2a4e6b394b..a998ba0454 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Invites/GetInviteQuery.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Invites/GetInviteQuery.cs @@ -2,7 +2,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -namespace DSharpPlus.Core.Abstractions.Rest.Queries; +namespace DSharpPlus.Internal.Abstractions.Rest.Queries; /// /// Contains query parameters to IInviteRestAPI.GetInviteAsync. diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/PaginatedQuery.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/PaginatedQuery.cs similarity index 90% rename from src/core/DSharpPlus.Core.Abstractions.Rest/Queries/PaginatedQuery.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/PaginatedQuery.cs index 11d783454d..ecc20c4919 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/PaginatedQuery.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/PaginatedQuery.cs @@ -2,7 +2,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -namespace DSharpPlus.Core.Abstractions.Rest.Queries; +namespace DSharpPlus.Internal.Abstractions.Rest.Queries; /// /// Contains the query parameters for all purely snowflake-paginated requests. diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/ScheduledEvents/GetScheduledEventUsersQuery.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/ScheduledEvents/GetScheduledEventUsersQuery.cs similarity index 93% rename from src/core/DSharpPlus.Core.Abstractions.Rest/Queries/ScheduledEvents/GetScheduledEventUsersQuery.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/ScheduledEvents/GetScheduledEventUsersQuery.cs index 70d4ad35d6..f7b8f569e9 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/ScheduledEvents/GetScheduledEventUsersQuery.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/ScheduledEvents/GetScheduledEventUsersQuery.cs @@ -3,7 +3,7 @@ // file, You can obtain one at https://mozilla.org/MPL/2.0/. -namespace DSharpPlus.Core.Abstractions.Rest.Queries; +namespace DSharpPlus.Internal.Abstractions.Rest.Queries; /// /// Contains the query parameters to IGuildScheduledEventRestAPI.GetScheduledEventUsersAsync. diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/ScheduledEvents/WithUserCountQuery.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/ScheduledEvents/WithUserCountQuery.cs similarity index 90% rename from src/core/DSharpPlus.Core.Abstractions.Rest/Queries/ScheduledEvents/WithUserCountQuery.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/ScheduledEvents/WithUserCountQuery.cs index 6fffea557e..8468eb750c 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/ScheduledEvents/WithUserCountQuery.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/ScheduledEvents/WithUserCountQuery.cs @@ -2,7 +2,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -namespace DSharpPlus.Core.Abstractions.Rest.Queries; +namespace DSharpPlus.Internal.Abstractions.Rest.Queries; /// /// Contains the query parameters for scheduled events that may be returned with user counts. diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Users/GetCurrentUserGuildsQuery.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Users/GetCurrentUserGuildsQuery.cs similarity index 93% rename from src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Users/GetCurrentUserGuildsQuery.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Users/GetCurrentUserGuildsQuery.cs index f3239ae3fa..73c8829ee5 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Users/GetCurrentUserGuildsQuery.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Users/GetCurrentUserGuildsQuery.cs @@ -3,7 +3,7 @@ // file, You can obtain one at https://mozilla.org/MPL/2.0/. -namespace DSharpPlus.Core.Abstractions.Rest.Queries; +namespace DSharpPlus.Internal.Abstractions.Rest.Queries; /// /// Contains the query parameters to IUserRestAPI.GetCurrentUserGuildsAsync. diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Webhooks/ExecuteWebhookQuery.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Webhooks/ExecuteWebhookQuery.cs similarity index 90% rename from src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Webhooks/ExecuteWebhookQuery.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Webhooks/ExecuteWebhookQuery.cs index 265917d2ff..4ed17f4f80 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Webhooks/ExecuteWebhookQuery.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Webhooks/ExecuteWebhookQuery.cs @@ -2,9 +2,9 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; -namespace DSharpPlus.Core.Abstractions.Rest.Queries; +namespace DSharpPlus.Internal.Abstractions.Rest.Queries; /// /// Contains the query parameters to IWebhookRestAPI.ExecuteWebhookAsync. diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Webhooks/ThreadIdQuery.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Webhooks/ThreadIdQuery.cs similarity index 92% rename from src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Webhooks/ThreadIdQuery.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Webhooks/ThreadIdQuery.cs index 001869af5b..a93d454854 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/Queries/Webhooks/ThreadIdQuery.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Webhooks/ThreadIdQuery.cs @@ -2,7 +2,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -namespace DSharpPlus.Core.Abstractions.Rest.Queries; +namespace DSharpPlus.Internal.Abstractions.Rest.Queries; /// /// Contains the ThreadId query parameter for webhook requests that can target a message in a thread. diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/RequestInfo.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/RequestInfo.cs similarity index 97% rename from src/core/DSharpPlus.Core.Abstractions.Rest/RequestInfo.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/RequestInfo.cs index 5261923d01..f406d6c060 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/RequestInfo.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/RequestInfo.cs @@ -5,7 +5,7 @@ using System; using System.Threading.Tasks; -namespace DSharpPlus.Core.Abstractions.Rest; +namespace DSharpPlus.Internal.Abstractions.Rest; /// /// Contains additional instructions on how to execute a request. diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Responses/BeginGuildPruneResponse.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Responses/BeginGuildPruneResponse.cs similarity index 90% rename from src/core/DSharpPlus.Core.Abstractions.Rest/Responses/BeginGuildPruneResponse.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/Responses/BeginGuildPruneResponse.cs index 6cca77aca1..e102e8c66f 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/Responses/BeginGuildPruneResponse.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Responses/BeginGuildPruneResponse.cs @@ -2,7 +2,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -namespace DSharpPlus.Core.Abstractions.Rest.Responses; +namespace DSharpPlus.Internal.Abstractions.Rest.Responses; /// /// Represents a response from POST /guilds/:guild-id/prune diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Responses/CreateApplicationCommandResponse.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Responses/CreateApplicationCommandResponse.cs similarity index 87% rename from src/core/DSharpPlus.Core.Abstractions.Rest/Responses/CreateApplicationCommandResponse.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/Responses/CreateApplicationCommandResponse.cs index 956d83457f..e97a874bc8 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/Responses/CreateApplicationCommandResponse.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Responses/CreateApplicationCommandResponse.cs @@ -2,9 +2,9 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; -namespace DSharpPlus.Core.Abstractions.Rest.Responses; +namespace DSharpPlus.Internal.Abstractions.Rest.Responses; /// /// Represents the information returned by POST /applications/:application-id/commands. diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Responses/ListActiveGuildThreadsResponse.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Responses/ListActiveGuildThreadsResponse.cs similarity index 88% rename from src/core/DSharpPlus.Core.Abstractions.Rest/Responses/ListActiveGuildThreadsResponse.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/Responses/ListActiveGuildThreadsResponse.cs index 1d47ca8d1a..9fe84b2c68 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/Responses/ListActiveGuildThreadsResponse.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Responses/ListActiveGuildThreadsResponse.cs @@ -4,9 +4,9 @@ using System.Collections.Generic; -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; -namespace DSharpPlus.Core.Abstractions.Rest.Responses; +namespace DSharpPlus.Internal.Abstractions.Rest.Responses; /// /// Represents a response from GET /guilds/:guild-id/threads/active. diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Responses/ListArchivedThreadsResponse.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Responses/ListArchivedThreadsResponse.cs similarity index 89% rename from src/core/DSharpPlus.Core.Abstractions.Rest/Responses/ListArchivedThreadsResponse.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/Responses/ListArchivedThreadsResponse.cs index 4050ca4a65..4c27bf44f4 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/Responses/ListArchivedThreadsResponse.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Responses/ListArchivedThreadsResponse.cs @@ -4,9 +4,9 @@ using System.Collections.Generic; -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; -namespace DSharpPlus.Core.Abstractions.Rest.Responses; +namespace DSharpPlus.Internal.Abstractions.Rest.Responses; /// /// Represents the response received from fetching archived threads. diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/Responses/ListStickerPacksResponse.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Responses/ListStickerPacksResponse.cs similarity index 83% rename from src/core/DSharpPlus.Core.Abstractions.Rest/Responses/ListStickerPacksResponse.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/Responses/ListStickerPacksResponse.cs index 94472616c8..d73636333f 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/Responses/ListStickerPacksResponse.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Responses/ListStickerPacksResponse.cs @@ -4,9 +4,9 @@ using System.Collections.Generic; -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; -namespace DSharpPlus.Core.Abstractions.Rest.Responses; +namespace DSharpPlus.Internal.Abstractions.Rest.Responses; /// /// Represents a response from GET /sticker-packs. diff --git a/src/core/DSharpPlus.Core.Abstractions.Rest/RetryMode.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/RetryMode.cs similarity index 97% rename from src/core/DSharpPlus.Core.Abstractions.Rest/RetryMode.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/RetryMode.cs index edb838f87f..7048e2d573 100644 --- a/src/core/DSharpPlus.Core.Abstractions.Rest/RetryMode.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/RetryMode.cs @@ -4,7 +4,7 @@ using System; -namespace DSharpPlus.Core.Abstractions.Rest; +namespace DSharpPlus.Internal.Abstractions.Rest; /// /// Specifies behaviour flags to apply to retrying a request. diff --git a/src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommand.cs b/src/core/DSharpPlus.Internal.Models/ApplicationCommands/ApplicationCommand.cs similarity index 94% rename from src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommand.cs rename to src/core/DSharpPlus.Internal.Models/ApplicationCommands/ApplicationCommand.cs index c57880bd2f..2106dbd729 100644 --- a/src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommand.cs +++ b/src/core/DSharpPlus.Internal.Models/ApplicationCommands/ApplicationCommand.cs @@ -4,10 +4,10 @@ using System.Collections.Generic; -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record ApplicationCommand : IApplicationCommand diff --git a/src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommandOption.cs b/src/core/DSharpPlus.Internal.Models/ApplicationCommands/ApplicationCommandOption.cs similarity index 95% rename from src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommandOption.cs rename to src/core/DSharpPlus.Internal.Models/ApplicationCommands/ApplicationCommandOption.cs index e8f8a08e87..690fd287e6 100644 --- a/src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommandOption.cs +++ b/src/core/DSharpPlus.Internal.Models/ApplicationCommands/ApplicationCommandOption.cs @@ -4,12 +4,12 @@ using System.Collections.Generic; -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; using OneOf; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record ApplicationCommandOption : IApplicationCommandOption diff --git a/src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommandOptionChoice.cs b/src/core/DSharpPlus.Internal.Models/ApplicationCommands/ApplicationCommandOptionChoice.cs similarity index 88% rename from src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommandOptionChoice.cs rename to src/core/DSharpPlus.Internal.Models/ApplicationCommands/ApplicationCommandOptionChoice.cs index 2e999ced3f..a3a9747a4e 100644 --- a/src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommandOptionChoice.cs +++ b/src/core/DSharpPlus.Internal.Models/ApplicationCommands/ApplicationCommandOptionChoice.cs @@ -4,11 +4,11 @@ using System.Collections.Generic; -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; using OneOf; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record ApplicationCommandOptionChoice : IApplicationCommandOptionChoice diff --git a/src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommandPermission.cs b/src/core/DSharpPlus.Internal.Models/ApplicationCommands/ApplicationCommandPermission.cs similarity index 87% rename from src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommandPermission.cs rename to src/core/DSharpPlus.Internal.Models/ApplicationCommands/ApplicationCommandPermission.cs index 98311d17f9..8b5a1b79af 100644 --- a/src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommandPermission.cs +++ b/src/core/DSharpPlus.Internal.Models/ApplicationCommands/ApplicationCommandPermission.cs @@ -2,10 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record ApplicationCommandPermission : IApplicationCommandPermission diff --git a/src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommandPermissions.cs b/src/core/DSharpPlus.Internal.Models/ApplicationCommands/ApplicationCommandPermissions.cs similarity index 89% rename from src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommandPermissions.cs rename to src/core/DSharpPlus.Internal.Models/ApplicationCommands/ApplicationCommandPermissions.cs index e129549546..9196643e9b 100644 --- a/src/core/DSharpPlus.Core.Models/ApplicationCommands/ApplicationCommandPermissions.cs +++ b/src/core/DSharpPlus.Internal.Models/ApplicationCommands/ApplicationCommandPermissions.cs @@ -4,9 +4,9 @@ using System.Collections.Generic; -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record ApplicationCommandPermissions : IApplicationCommandPermissions diff --git a/src/core/DSharpPlus.Core.Models/ApplicationCommands/PartialApplicationCommandPermissions.cs b/src/core/DSharpPlus.Internal.Models/ApplicationCommands/PartialApplicationCommandPermissions.cs similarity index 89% rename from src/core/DSharpPlus.Core.Models/ApplicationCommands/PartialApplicationCommandPermissions.cs rename to src/core/DSharpPlus.Internal.Models/ApplicationCommands/PartialApplicationCommandPermissions.cs index 85bc56ed75..1981540df8 100644 --- a/src/core/DSharpPlus.Core.Models/ApplicationCommands/PartialApplicationCommandPermissions.cs +++ b/src/core/DSharpPlus.Internal.Models/ApplicationCommands/PartialApplicationCommandPermissions.cs @@ -4,9 +4,9 @@ using System.Collections.Generic; -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record PartialApplicationCommandPermissions : IPartialApplicationCommandPermissions diff --git a/src/core/DSharpPlus.Core.Models/Applications/Application.cs b/src/core/DSharpPlus.Internal.Models/Applications/Application.cs similarity index 96% rename from src/core/DSharpPlus.Core.Models/Applications/Application.cs rename to src/core/DSharpPlus.Internal.Models/Applications/Application.cs index 324b3f6ab4..27b410c451 100644 --- a/src/core/DSharpPlus.Core.Models/Applications/Application.cs +++ b/src/core/DSharpPlus.Internal.Models/Applications/Application.cs @@ -4,10 +4,10 @@ using System.Collections.Generic; -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record Application : IApplication diff --git a/src/core/DSharpPlus.Core.Models/Applications/InstallParameters.cs b/src/core/DSharpPlus.Internal.Models/Applications/InstallParameters.cs similarity index 86% rename from src/core/DSharpPlus.Core.Models/Applications/InstallParameters.cs rename to src/core/DSharpPlus.Internal.Models/Applications/InstallParameters.cs index c8864ad2bd..13045ee86b 100644 --- a/src/core/DSharpPlus.Core.Models/Applications/InstallParameters.cs +++ b/src/core/DSharpPlus.Internal.Models/Applications/InstallParameters.cs @@ -4,10 +4,10 @@ using System.Collections.Generic; -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record InstallParameters : IInstallParameters diff --git a/src/core/DSharpPlus.Core.Models/Applications/PartialApplication.cs b/src/core/DSharpPlus.Internal.Models/Applications/PartialApplication.cs similarity index 96% rename from src/core/DSharpPlus.Core.Models/Applications/PartialApplication.cs rename to src/core/DSharpPlus.Internal.Models/Applications/PartialApplication.cs index acf645e825..52e1db9854 100644 --- a/src/core/DSharpPlus.Core.Models/Applications/PartialApplication.cs +++ b/src/core/DSharpPlus.Internal.Models/Applications/PartialApplication.cs @@ -4,10 +4,10 @@ using System.Collections.Generic; -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record PartialApplication : IPartialApplication diff --git a/src/core/DSharpPlus.Core.Models/AuditLogs/AuditLog.cs b/src/core/DSharpPlus.Internal.Models/AuditLogs/AuditLog.cs similarity index 93% rename from src/core/DSharpPlus.Core.Models/AuditLogs/AuditLog.cs rename to src/core/DSharpPlus.Internal.Models/AuditLogs/AuditLog.cs index 66d207a78f..7bddd18cf2 100644 --- a/src/core/DSharpPlus.Core.Models/AuditLogs/AuditLog.cs +++ b/src/core/DSharpPlus.Internal.Models/AuditLogs/AuditLog.cs @@ -4,9 +4,9 @@ using System.Collections.Generic; -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record AuditLog : IAuditLog diff --git a/src/core/DSharpPlus.Core.Models/AuditLogs/AuditLogChange.cs b/src/core/DSharpPlus.Internal.Models/AuditLogs/AuditLogChange.cs similarity index 86% rename from src/core/DSharpPlus.Core.Models/AuditLogs/AuditLogChange.cs rename to src/core/DSharpPlus.Internal.Models/AuditLogs/AuditLogChange.cs index db0702d6f2..851289f358 100644 --- a/src/core/DSharpPlus.Core.Models/AuditLogs/AuditLogChange.cs +++ b/src/core/DSharpPlus.Internal.Models/AuditLogs/AuditLogChange.cs @@ -2,9 +2,9 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record AuditLogChange : IAuditLogChange diff --git a/src/core/DSharpPlus.Core.Models/AuditLogs/AuditLogEntry.cs b/src/core/DSharpPlus.Internal.Models/AuditLogs/AuditLogEntry.cs similarity index 91% rename from src/core/DSharpPlus.Core.Models/AuditLogs/AuditLogEntry.cs rename to src/core/DSharpPlus.Internal.Models/AuditLogs/AuditLogEntry.cs index 376f91f697..4b449b472a 100644 --- a/src/core/DSharpPlus.Core.Models/AuditLogs/AuditLogEntry.cs +++ b/src/core/DSharpPlus.Internal.Models/AuditLogs/AuditLogEntry.cs @@ -4,12 +4,12 @@ using System.Collections.Generic; -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; using OneOf; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record AuditLogEntry : IAuditLogEntry diff --git a/src/core/DSharpPlus.Core.Models/AuditLogs/AuditLogEntryInfo.cs b/src/core/DSharpPlus.Internal.Models/AuditLogs/AuditLogEntryInfo.cs similarity index 93% rename from src/core/DSharpPlus.Core.Models/AuditLogs/AuditLogEntryInfo.cs rename to src/core/DSharpPlus.Internal.Models/AuditLogs/AuditLogEntryInfo.cs index 8778315766..0eccde3cd8 100644 --- a/src/core/DSharpPlus.Core.Models/AuditLogs/AuditLogEntryInfo.cs +++ b/src/core/DSharpPlus.Internal.Models/AuditLogs/AuditLogEntryInfo.cs @@ -2,9 +2,9 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record AuditLogEntryInfo : IAuditLogEntryInfo diff --git a/src/core/DSharpPlus.Core.Models/AutoModeration/AutoModerationAction.cs b/src/core/DSharpPlus.Internal.Models/AutoModeration/AutoModerationAction.cs similarity index 86% rename from src/core/DSharpPlus.Core.Models/AutoModeration/AutoModerationAction.cs rename to src/core/DSharpPlus.Internal.Models/AutoModeration/AutoModerationAction.cs index 66fd41db9a..6fa6763aa5 100644 --- a/src/core/DSharpPlus.Core.Models/AutoModeration/AutoModerationAction.cs +++ b/src/core/DSharpPlus.Internal.Models/AutoModeration/AutoModerationAction.cs @@ -2,10 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record AutoModerationAction : IAutoModerationAction diff --git a/src/core/DSharpPlus.Core.Models/AutoModeration/AutoModerationActionMetadata.cs b/src/core/DSharpPlus.Internal.Models/AutoModeration/AutoModerationActionMetadata.cs similarity index 83% rename from src/core/DSharpPlus.Core.Models/AutoModeration/AutoModerationActionMetadata.cs rename to src/core/DSharpPlus.Internal.Models/AutoModeration/AutoModerationActionMetadata.cs index 978cb39e49..728f3aea11 100644 --- a/src/core/DSharpPlus.Core.Models/AutoModeration/AutoModerationActionMetadata.cs +++ b/src/core/DSharpPlus.Internal.Models/AutoModeration/AutoModerationActionMetadata.cs @@ -2,9 +2,9 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// /// Placeholder implementation of a marker interface. Please report spotting this to library developers. diff --git a/src/core/DSharpPlus.Core.Models/AutoModeration/AutoModerationRule.cs b/src/core/DSharpPlus.Internal.Models/AutoModeration/AutoModerationRule.cs similarity index 94% rename from src/core/DSharpPlus.Core.Models/AutoModeration/AutoModerationRule.cs rename to src/core/DSharpPlus.Internal.Models/AutoModeration/AutoModerationRule.cs index 80413df074..69a8756126 100644 --- a/src/core/DSharpPlus.Core.Models/AutoModeration/AutoModerationRule.cs +++ b/src/core/DSharpPlus.Internal.Models/AutoModeration/AutoModerationRule.cs @@ -4,10 +4,10 @@ using System.Collections.Generic; -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record AutoModerationRule : IAutoModerationRule diff --git a/src/core/DSharpPlus.Core.Models/AutoModeration/AutoModerationTriggerMetadata.cs b/src/core/DSharpPlus.Internal.Models/AutoModeration/AutoModerationTriggerMetadata.cs similarity index 92% rename from src/core/DSharpPlus.Core.Models/AutoModeration/AutoModerationTriggerMetadata.cs rename to src/core/DSharpPlus.Internal.Models/AutoModeration/AutoModerationTriggerMetadata.cs index 08416794b5..ae087907e9 100644 --- a/src/core/DSharpPlus.Core.Models/AutoModeration/AutoModerationTriggerMetadata.cs +++ b/src/core/DSharpPlus.Internal.Models/AutoModeration/AutoModerationTriggerMetadata.cs @@ -4,10 +4,10 @@ using System.Collections.Generic; -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record AutoModerationTriggerMetadata : IAutoModerationTriggerMetadata diff --git a/src/core/DSharpPlus.Core.Models/AutoModeration/BlockMessageActionMetadata.cs b/src/core/DSharpPlus.Internal.Models/AutoModeration/BlockMessageActionMetadata.cs similarity index 84% rename from src/core/DSharpPlus.Core.Models/AutoModeration/BlockMessageActionMetadata.cs rename to src/core/DSharpPlus.Internal.Models/AutoModeration/BlockMessageActionMetadata.cs index 4309f28217..470860a39d 100644 --- a/src/core/DSharpPlus.Core.Models/AutoModeration/BlockMessageActionMetadata.cs +++ b/src/core/DSharpPlus.Internal.Models/AutoModeration/BlockMessageActionMetadata.cs @@ -2,10 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record BlockMessageActionMetadata : IBlockMessageActionMetadata diff --git a/src/core/DSharpPlus.Core.Models/AutoModeration/PartialAutoModerationRule.cs b/src/core/DSharpPlus.Internal.Models/AutoModeration/PartialAutoModerationRule.cs similarity index 94% rename from src/core/DSharpPlus.Core.Models/AutoModeration/PartialAutoModerationRule.cs rename to src/core/DSharpPlus.Internal.Models/AutoModeration/PartialAutoModerationRule.cs index e500f3eb31..19a63b9741 100644 --- a/src/core/DSharpPlus.Core.Models/AutoModeration/PartialAutoModerationRule.cs +++ b/src/core/DSharpPlus.Internal.Models/AutoModeration/PartialAutoModerationRule.cs @@ -4,10 +4,10 @@ using System.Collections.Generic; -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record PartialAutoModerationRule : IPartialAutoModerationRule diff --git a/src/core/DSharpPlus.Core.Models/AutoModeration/SendAlertMessageActionMetadata.cs b/src/core/DSharpPlus.Internal.Models/AutoModeration/SendAlertMessageActionMetadata.cs similarity index 84% rename from src/core/DSharpPlus.Core.Models/AutoModeration/SendAlertMessageActionMetadata.cs rename to src/core/DSharpPlus.Internal.Models/AutoModeration/SendAlertMessageActionMetadata.cs index 9e5f613417..e5a6656fa1 100644 --- a/src/core/DSharpPlus.Core.Models/AutoModeration/SendAlertMessageActionMetadata.cs +++ b/src/core/DSharpPlus.Internal.Models/AutoModeration/SendAlertMessageActionMetadata.cs @@ -2,10 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record SendAlertMessageActionMetadata : ISendAlertMessageActionMetadata diff --git a/src/core/DSharpPlus.Core.Models/AutoModeration/TimeoutActionMetadata.cs b/src/core/DSharpPlus.Internal.Models/AutoModeration/TimeoutActionMetadata.cs similarity index 83% rename from src/core/DSharpPlus.Core.Models/AutoModeration/TimeoutActionMetadata.cs rename to src/core/DSharpPlus.Internal.Models/AutoModeration/TimeoutActionMetadata.cs index 0783287bfa..028527eb07 100644 --- a/src/core/DSharpPlus.Core.Models/AutoModeration/TimeoutActionMetadata.cs +++ b/src/core/DSharpPlus.Internal.Models/AutoModeration/TimeoutActionMetadata.cs @@ -2,10 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record TimeoutActionMetadata : ITimeoutActionMetadata diff --git a/src/core/DSharpPlus.Core.Models/Channels/AllowedMentions.cs b/src/core/DSharpPlus.Internal.Models/Channels/AllowedMentions.cs similarity index 88% rename from src/core/DSharpPlus.Core.Models/Channels/AllowedMentions.cs rename to src/core/DSharpPlus.Internal.Models/Channels/AllowedMentions.cs index b8090522b9..2e75c35dd4 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/AllowedMentions.cs +++ b/src/core/DSharpPlus.Internal.Models/Channels/AllowedMentions.cs @@ -4,9 +4,9 @@ using System.Collections.Generic; -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record AllowedMentions : IAllowedMentions diff --git a/src/core/DSharpPlus.Core.Models/Channels/Attachment.cs b/src/core/DSharpPlus.Internal.Models/Channels/Attachment.cs similarity index 93% rename from src/core/DSharpPlus.Core.Models/Channels/Attachment.cs rename to src/core/DSharpPlus.Internal.Models/Channels/Attachment.cs index f1c96bfa59..4b89f4c201 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/Attachment.cs +++ b/src/core/DSharpPlus.Internal.Models/Channels/Attachment.cs @@ -4,10 +4,10 @@ using System; -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record Attachment : IAttachment diff --git a/src/core/DSharpPlus.Core.Models/Channels/Channel.cs b/src/core/DSharpPlus.Internal.Models/Channels/Channel.cs similarity index 97% rename from src/core/DSharpPlus.Core.Models/Channels/Channel.cs rename to src/core/DSharpPlus.Internal.Models/Channels/Channel.cs index d4997fe315..1e41a0f7fa 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/Channel.cs +++ b/src/core/DSharpPlus.Internal.Models/Channels/Channel.cs @@ -5,10 +5,10 @@ using System; using System.Collections.Generic; -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record Channel : IChannel diff --git a/src/core/DSharpPlus.Core.Models/Channels/ChannelMention.cs b/src/core/DSharpPlus.Internal.Models/Channels/ChannelMention.cs similarity index 88% rename from src/core/DSharpPlus.Core.Models/Channels/ChannelMention.cs rename to src/core/DSharpPlus.Internal.Models/Channels/ChannelMention.cs index 4a13f8a031..184ddbb058 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/ChannelMention.cs +++ b/src/core/DSharpPlus.Internal.Models/Channels/ChannelMention.cs @@ -2,10 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record ChannelMention : IChannelMention diff --git a/src/core/DSharpPlus.Core.Models/Channels/ChannelOverwrite.cs b/src/core/DSharpPlus.Internal.Models/Channels/ChannelOverwrite.cs similarity index 88% rename from src/core/DSharpPlus.Core.Models/Channels/ChannelOverwrite.cs rename to src/core/DSharpPlus.Internal.Models/Channels/ChannelOverwrite.cs index 8332974eba..c9e09097f8 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/ChannelOverwrite.cs +++ b/src/core/DSharpPlus.Internal.Models/Channels/ChannelOverwrite.cs @@ -2,10 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record ChannelOverwrite : IChannelOverwrite diff --git a/src/core/DSharpPlus.Core.Models/Channels/DefaultReaction.cs b/src/core/DSharpPlus.Internal.Models/Channels/DefaultReaction.cs similarity index 83% rename from src/core/DSharpPlus.Core.Models/Channels/DefaultReaction.cs rename to src/core/DSharpPlus.Internal.Models/Channels/DefaultReaction.cs index 14a9756cc1..3bd156f0c0 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/DefaultReaction.cs +++ b/src/core/DSharpPlus.Internal.Models/Channels/DefaultReaction.cs @@ -2,9 +2,9 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record DefaultReaction : IDefaultReaction diff --git a/src/core/DSharpPlus.Core.Models/Channels/Embed.cs b/src/core/DSharpPlus.Internal.Models/Channels/Embed.cs similarity index 94% rename from src/core/DSharpPlus.Core.Models/Channels/Embed.cs rename to src/core/DSharpPlus.Internal.Models/Channels/Embed.cs index 3f5f794cce..54f3ac7732 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/Embed.cs +++ b/src/core/DSharpPlus.Internal.Models/Channels/Embed.cs @@ -5,9 +5,9 @@ using System; using System.Collections.Generic; -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record Embed : IEmbed diff --git a/src/core/DSharpPlus.Core.Models/Channels/EmbedAuthor.cs b/src/core/DSharpPlus.Internal.Models/Channels/EmbedAuthor.cs similarity index 87% rename from src/core/DSharpPlus.Core.Models/Channels/EmbedAuthor.cs rename to src/core/DSharpPlus.Internal.Models/Channels/EmbedAuthor.cs index 5d28fbf216..a70c637dcb 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/EmbedAuthor.cs +++ b/src/core/DSharpPlus.Internal.Models/Channels/EmbedAuthor.cs @@ -2,9 +2,9 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record EmbedAuthor : IEmbedAuthor diff --git a/src/core/DSharpPlus.Core.Models/Channels/EmbedField.cs b/src/core/DSharpPlus.Internal.Models/Channels/EmbedField.cs similarity index 85% rename from src/core/DSharpPlus.Core.Models/Channels/EmbedField.cs rename to src/core/DSharpPlus.Internal.Models/Channels/EmbedField.cs index 3507e24174..dfba94145a 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/EmbedField.cs +++ b/src/core/DSharpPlus.Internal.Models/Channels/EmbedField.cs @@ -2,9 +2,9 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record EmbedField : IEmbedField diff --git a/src/core/DSharpPlus.Core.Models/Channels/EmbedFooter.cs b/src/core/DSharpPlus.Internal.Models/Channels/EmbedFooter.cs similarity index 85% rename from src/core/DSharpPlus.Core.Models/Channels/EmbedFooter.cs rename to src/core/DSharpPlus.Internal.Models/Channels/EmbedFooter.cs index 0d624ea8c7..9386af213f 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/EmbedFooter.cs +++ b/src/core/DSharpPlus.Internal.Models/Channels/EmbedFooter.cs @@ -2,9 +2,9 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record EmbedFooter : IEmbedFooter diff --git a/src/core/DSharpPlus.Core.Models/Channels/EmbedImage.cs b/src/core/DSharpPlus.Internal.Models/Channels/EmbedImage.cs similarity index 87% rename from src/core/DSharpPlus.Core.Models/Channels/EmbedImage.cs rename to src/core/DSharpPlus.Internal.Models/Channels/EmbedImage.cs index f22964556b..5e2f47bd72 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/EmbedImage.cs +++ b/src/core/DSharpPlus.Internal.Models/Channels/EmbedImage.cs @@ -2,9 +2,9 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record EmbedImage : IEmbedImage diff --git a/src/core/DSharpPlus.Core.Models/Channels/EmbedProvider.cs b/src/core/DSharpPlus.Internal.Models/Channels/EmbedProvider.cs similarity index 83% rename from src/core/DSharpPlus.Core.Models/Channels/EmbedProvider.cs rename to src/core/DSharpPlus.Internal.Models/Channels/EmbedProvider.cs index 40aab10700..531c8908a5 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/EmbedProvider.cs +++ b/src/core/DSharpPlus.Internal.Models/Channels/EmbedProvider.cs @@ -2,9 +2,9 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record EmbedProvider : IEmbedProvider diff --git a/src/core/DSharpPlus.Core.Models/Channels/EmbedThumbnail.cs b/src/core/DSharpPlus.Internal.Models/Channels/EmbedThumbnail.cs similarity index 87% rename from src/core/DSharpPlus.Core.Models/Channels/EmbedThumbnail.cs rename to src/core/DSharpPlus.Internal.Models/Channels/EmbedThumbnail.cs index 9579e15434..26db818a6f 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/EmbedThumbnail.cs +++ b/src/core/DSharpPlus.Internal.Models/Channels/EmbedThumbnail.cs @@ -2,9 +2,9 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record EmbedThumbnail : IEmbedThumbnail diff --git a/src/core/DSharpPlus.Core.Models/Channels/EmbedVideo.cs b/src/core/DSharpPlus.Internal.Models/Channels/EmbedVideo.cs similarity index 87% rename from src/core/DSharpPlus.Core.Models/Channels/EmbedVideo.cs rename to src/core/DSharpPlus.Internal.Models/Channels/EmbedVideo.cs index df6b63e2c8..f1df768180 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/EmbedVideo.cs +++ b/src/core/DSharpPlus.Internal.Models/Channels/EmbedVideo.cs @@ -2,9 +2,9 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record EmbedVideo : IEmbedVideo diff --git a/src/core/DSharpPlus.Core.Models/Channels/FollowedChannel.cs b/src/core/DSharpPlus.Internal.Models/Channels/FollowedChannel.cs similarity index 84% rename from src/core/DSharpPlus.Core.Models/Channels/FollowedChannel.cs rename to src/core/DSharpPlus.Internal.Models/Channels/FollowedChannel.cs index 98a636bcee..56e488d6a8 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/FollowedChannel.cs +++ b/src/core/DSharpPlus.Internal.Models/Channels/FollowedChannel.cs @@ -2,9 +2,9 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record FollowedChannel : IFollowedChannel diff --git a/src/core/DSharpPlus.Core.Models/Channels/ForumTag.cs b/src/core/DSharpPlus.Internal.Models/Channels/ForumTag.cs similarity index 88% rename from src/core/DSharpPlus.Core.Models/Channels/ForumTag.cs rename to src/core/DSharpPlus.Internal.Models/Channels/ForumTag.cs index fbaa76ae5e..f093919ab6 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/ForumTag.cs +++ b/src/core/DSharpPlus.Internal.Models/Channels/ForumTag.cs @@ -2,9 +2,9 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record ForumTag : IForumTag diff --git a/src/core/DSharpPlus.Core.Models/Channels/Message.cs b/src/core/DSharpPlus.Internal.Models/Channels/Message.cs similarity index 97% rename from src/core/DSharpPlus.Core.Models/Channels/Message.cs rename to src/core/DSharpPlus.Internal.Models/Channels/Message.cs index 34804a4ecd..bb9fe07193 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/Message.cs +++ b/src/core/DSharpPlus.Internal.Models/Channels/Message.cs @@ -5,10 +5,10 @@ using System; using System.Collections.Generic; -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record Message : IMessage diff --git a/src/core/DSharpPlus.Core.Models/Channels/MessageActivity.cs b/src/core/DSharpPlus.Internal.Models/Channels/MessageActivity.cs similarity index 85% rename from src/core/DSharpPlus.Core.Models/Channels/MessageActivity.cs rename to src/core/DSharpPlus.Internal.Models/Channels/MessageActivity.cs index 7cd3bd67d3..8eacc4f4de 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/MessageActivity.cs +++ b/src/core/DSharpPlus.Internal.Models/Channels/MessageActivity.cs @@ -2,10 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record MessageActivity : IMessageActivity diff --git a/src/core/DSharpPlus.Core.Models/Channels/MessageReference.cs b/src/core/DSharpPlus.Internal.Models/Channels/MessageReference.cs similarity index 88% rename from src/core/DSharpPlus.Core.Models/Channels/MessageReference.cs rename to src/core/DSharpPlus.Internal.Models/Channels/MessageReference.cs index 64f9106e4a..b47e7ea778 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/MessageReference.cs +++ b/src/core/DSharpPlus.Internal.Models/Channels/MessageReference.cs @@ -2,9 +2,9 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record MessageReference : IMessageReference diff --git a/src/core/DSharpPlus.Core.Models/Channels/PartialAttachment.cs b/src/core/DSharpPlus.Internal.Models/Channels/PartialAttachment.cs similarity index 94% rename from src/core/DSharpPlus.Core.Models/Channels/PartialAttachment.cs rename to src/core/DSharpPlus.Internal.Models/Channels/PartialAttachment.cs index 80e789f139..9ba1d49a91 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/PartialAttachment.cs +++ b/src/core/DSharpPlus.Internal.Models/Channels/PartialAttachment.cs @@ -4,10 +4,10 @@ using System; -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record PartialAttachment : IPartialAttachment diff --git a/src/core/DSharpPlus.Core.Models/Channels/PartialChannel.cs b/src/core/DSharpPlus.Internal.Models/Channels/PartialChannel.cs similarity index 97% rename from src/core/DSharpPlus.Core.Models/Channels/PartialChannel.cs rename to src/core/DSharpPlus.Internal.Models/Channels/PartialChannel.cs index cbfb226c19..349c9e998f 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/PartialChannel.cs +++ b/src/core/DSharpPlus.Internal.Models/Channels/PartialChannel.cs @@ -5,10 +5,10 @@ using System; using System.Collections.Generic; -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record PartialChannel : IPartialChannel diff --git a/src/core/DSharpPlus.Core.Models/Channels/PartialChannelOverwrite.cs b/src/core/DSharpPlus.Internal.Models/Channels/PartialChannelOverwrite.cs similarity index 89% rename from src/core/DSharpPlus.Core.Models/Channels/PartialChannelOverwrite.cs rename to src/core/DSharpPlus.Internal.Models/Channels/PartialChannelOverwrite.cs index 7317849c1d..6e12416530 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/PartialChannelOverwrite.cs +++ b/src/core/DSharpPlus.Internal.Models/Channels/PartialChannelOverwrite.cs @@ -2,10 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record PartialChannelOverwrite : IPartialChannelOverwrite diff --git a/src/core/DSharpPlus.Core.Models/Channels/PartialMessage.cs b/src/core/DSharpPlus.Internal.Models/Channels/PartialMessage.cs similarity index 97% rename from src/core/DSharpPlus.Core.Models/Channels/PartialMessage.cs rename to src/core/DSharpPlus.Internal.Models/Channels/PartialMessage.cs index 287e26848c..516e76d720 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/PartialMessage.cs +++ b/src/core/DSharpPlus.Internal.Models/Channels/PartialMessage.cs @@ -5,10 +5,10 @@ using System; using System.Collections.Generic; -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record PartialMessage : IPartialMessage diff --git a/src/core/DSharpPlus.Core.Models/Channels/Reaction.cs b/src/core/DSharpPlus.Internal.Models/Channels/Reaction.cs similarity index 85% rename from src/core/DSharpPlus.Core.Models/Channels/Reaction.cs rename to src/core/DSharpPlus.Internal.Models/Channels/Reaction.cs index c572360385..c404d3204e 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/Reaction.cs +++ b/src/core/DSharpPlus.Internal.Models/Channels/Reaction.cs @@ -2,9 +2,9 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record Reaction : IReaction diff --git a/src/core/DSharpPlus.Core.Models/Channels/RoleSubscriptionData.cs b/src/core/DSharpPlus.Internal.Models/Channels/RoleSubscriptionData.cs similarity index 88% rename from src/core/DSharpPlus.Core.Models/Channels/RoleSubscriptionData.cs rename to src/core/DSharpPlus.Internal.Models/Channels/RoleSubscriptionData.cs index 335cbcf008..8673710cec 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/RoleSubscriptionData.cs +++ b/src/core/DSharpPlus.Internal.Models/Channels/RoleSubscriptionData.cs @@ -2,9 +2,9 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record RoleSubscriptionData : IRoleSubscriptionData diff --git a/src/core/DSharpPlus.Core.Models/Channels/ThreadMember.cs b/src/core/DSharpPlus.Internal.Models/Channels/ThreadMember.cs similarity index 89% rename from src/core/DSharpPlus.Core.Models/Channels/ThreadMember.cs rename to src/core/DSharpPlus.Internal.Models/Channels/ThreadMember.cs index 4139e3f355..f67558eb8f 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/ThreadMember.cs +++ b/src/core/DSharpPlus.Internal.Models/Channels/ThreadMember.cs @@ -4,9 +4,9 @@ using System; -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record ThreadMember : IThreadMember diff --git a/src/core/DSharpPlus.Core.Models/Channels/ThreadMetadata.cs b/src/core/DSharpPlus.Internal.Models/Channels/ThreadMetadata.cs similarity index 90% rename from src/core/DSharpPlus.Core.Models/Channels/ThreadMetadata.cs rename to src/core/DSharpPlus.Internal.Models/Channels/ThreadMetadata.cs index d9d2246160..6e39227a19 100644 --- a/src/core/DSharpPlus.Core.Models/Channels/ThreadMetadata.cs +++ b/src/core/DSharpPlus.Internal.Models/Channels/ThreadMetadata.cs @@ -4,9 +4,9 @@ using System; -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record ThreadMetadata : IThreadMetadata diff --git a/src/core/DSharpPlus.Core.Models/DSharpPlus.Core.Models.csproj b/src/core/DSharpPlus.Internal.Models/DSharpPlus.Internal.Models.csproj similarity index 63% rename from src/core/DSharpPlus.Core.Models/DSharpPlus.Core.Models.csproj rename to src/core/DSharpPlus.Internal.Models/DSharpPlus.Internal.Models.csproj index efd579aa26..d2eb15f798 100644 --- a/src/core/DSharpPlus.Core.Models/DSharpPlus.Core.Models.csproj +++ b/src/core/DSharpPlus.Internal.Models/DSharpPlus.Internal.Models.csproj @@ -1,7 +1,7 @@  - $(_DSharpPlusCoreModelsVersion) + $(_DSharpPlusInternalModelsVersion) $(Description) This package implements the serialization models mirroring the Discord API. Library @@ -13,7 +13,7 @@ - + diff --git a/src/core/DSharpPlus.Core.Models/Emojis/Emoji.cs b/src/core/DSharpPlus.Internal.Models/Emojis/Emoji.cs similarity index 91% rename from src/core/DSharpPlus.Core.Models/Emojis/Emoji.cs rename to src/core/DSharpPlus.Internal.Models/Emojis/Emoji.cs index 2a0fc5e86d..e4a57379c2 100644 --- a/src/core/DSharpPlus.Core.Models/Emojis/Emoji.cs +++ b/src/core/DSharpPlus.Internal.Models/Emojis/Emoji.cs @@ -4,9 +4,9 @@ using System.Collections.Generic; -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record Emoji : IEmoji diff --git a/src/core/DSharpPlus.Core.Models/Emojis/PartialEmoji.cs b/src/core/DSharpPlus.Internal.Models/Emojis/PartialEmoji.cs similarity index 91% rename from src/core/DSharpPlus.Core.Models/Emojis/PartialEmoji.cs rename to src/core/DSharpPlus.Internal.Models/Emojis/PartialEmoji.cs index 2de09a4747..f0cca2d9d0 100644 --- a/src/core/DSharpPlus.Core.Models/Emojis/PartialEmoji.cs +++ b/src/core/DSharpPlus.Internal.Models/Emojis/PartialEmoji.cs @@ -4,9 +4,9 @@ using System.Collections.Generic; -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record PartialEmoji : IPartialEmoji diff --git a/src/core/DSharpPlus.Core.Models/Entitlements/Entitlement.cs b/src/core/DSharpPlus.Internal.Models/Entitlements/Entitlement.cs similarity index 92% rename from src/core/DSharpPlus.Core.Models/Entitlements/Entitlement.cs rename to src/core/DSharpPlus.Internal.Models/Entitlements/Entitlement.cs index 49387253d8..819c6d4c79 100644 --- a/src/core/DSharpPlus.Core.Models/Entitlements/Entitlement.cs +++ b/src/core/DSharpPlus.Internal.Models/Entitlements/Entitlement.cs @@ -4,10 +4,10 @@ using System; -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record Entitlement : IEntitlement diff --git a/src/core/DSharpPlus.Core.Models/Entitlements/PartialEntitlement.cs b/src/core/DSharpPlus.Internal.Models/Entitlements/PartialEntitlement.cs similarity index 92% rename from src/core/DSharpPlus.Core.Models/Entitlements/PartialEntitlement.cs rename to src/core/DSharpPlus.Internal.Models/Entitlements/PartialEntitlement.cs index 767041756f..0ecfdac36e 100644 --- a/src/core/DSharpPlus.Core.Models/Entitlements/PartialEntitlement.cs +++ b/src/core/DSharpPlus.Internal.Models/Entitlements/PartialEntitlement.cs @@ -4,10 +4,10 @@ using System; -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record PartialEntitlement : IPartialEntitlement diff --git a/src/core/DSharpPlus.Core.Models/Extensions/ServiceCollectionExtensions.cs b/src/core/DSharpPlus.Internal.Models/Extensions/ServiceCollectionExtensions.cs similarity index 97% rename from src/core/DSharpPlus.Core.Models/Extensions/ServiceCollectionExtensions.cs rename to src/core/DSharpPlus.Internal.Models/Extensions/ServiceCollectionExtensions.cs index e8eb0ad1f7..a70533dcec 100644 --- a/src/core/DSharpPlus.Core.Models/Extensions/ServiceCollectionExtensions.cs +++ b/src/core/DSharpPlus.Internal.Models/Extensions/ServiceCollectionExtensions.cs @@ -4,14 +4,14 @@ using System.Text.Json; -using DSharpPlus.Core.Abstractions.Models; -using DSharpPlus.Core.Models.Serialization.Converters; -using DSharpPlus.Core.Models.Serialization.Resolvers; +using DSharpPlus.Internal.Abstractions.Models; +using DSharpPlus.Internal.Models.Serialization.Converters; +using DSharpPlus.Internal.Models.Serialization.Resolvers; using DSharpPlus.Serialization; using Microsoft.Extensions.DependencyInjection; -namespace DSharpPlus.Core.Models.Extensions; +namespace DSharpPlus.Internal.Models.Extensions; /// /// Provides extensions on IServiceCollection to register our JSON serialization of Discord models. diff --git a/src/core/DSharpPlus.Core.Models/GuildTemplates/Template.cs b/src/core/DSharpPlus.Internal.Models/GuildTemplates/Template.cs similarity index 93% rename from src/core/DSharpPlus.Core.Models/GuildTemplates/Template.cs rename to src/core/DSharpPlus.Internal.Models/GuildTemplates/Template.cs index d088b3b316..e77bba318b 100644 --- a/src/core/DSharpPlus.Core.Models/GuildTemplates/Template.cs +++ b/src/core/DSharpPlus.Internal.Models/GuildTemplates/Template.cs @@ -4,9 +4,9 @@ using System; -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record Template : ITemplate diff --git a/src/core/DSharpPlus.Core.Models/Guilds/Ban.cs b/src/core/DSharpPlus.Internal.Models/Guilds/Ban.cs similarity index 82% rename from src/core/DSharpPlus.Core.Models/Guilds/Ban.cs rename to src/core/DSharpPlus.Internal.Models/Guilds/Ban.cs index 59a4e90363..ed0925016a 100644 --- a/src/core/DSharpPlus.Core.Models/Guilds/Ban.cs +++ b/src/core/DSharpPlus.Internal.Models/Guilds/Ban.cs @@ -2,9 +2,9 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record Ban : IBan diff --git a/src/core/DSharpPlus.Core.Models/Guilds/Guild.cs b/src/core/DSharpPlus.Internal.Models/Guilds/Guild.cs similarity index 97% rename from src/core/DSharpPlus.Core.Models/Guilds/Guild.cs rename to src/core/DSharpPlus.Internal.Models/Guilds/Guild.cs index 8b479b8931..e5beb14922 100644 --- a/src/core/DSharpPlus.Core.Models/Guilds/Guild.cs +++ b/src/core/DSharpPlus.Internal.Models/Guilds/Guild.cs @@ -4,10 +4,10 @@ using System.Collections.Generic; -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record Guild : IGuild diff --git a/src/core/DSharpPlus.Core.Models/Guilds/GuildMember.cs b/src/core/DSharpPlus.Internal.Models/Guilds/GuildMember.cs similarity index 94% rename from src/core/DSharpPlus.Core.Models/Guilds/GuildMember.cs rename to src/core/DSharpPlus.Internal.Models/Guilds/GuildMember.cs index 6c433a9784..513310cb37 100644 --- a/src/core/DSharpPlus.Core.Models/Guilds/GuildMember.cs +++ b/src/core/DSharpPlus.Internal.Models/Guilds/GuildMember.cs @@ -5,10 +5,10 @@ using System; using System.Collections.Generic; -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record GuildMember : IGuildMember diff --git a/src/core/DSharpPlus.Core.Models/Guilds/GuildPreview.cs b/src/core/DSharpPlus.Internal.Models/Guilds/GuildPreview.cs similarity index 93% rename from src/core/DSharpPlus.Core.Models/Guilds/GuildPreview.cs rename to src/core/DSharpPlus.Internal.Models/Guilds/GuildPreview.cs index 6bda23806a..11e6580e45 100644 --- a/src/core/DSharpPlus.Core.Models/Guilds/GuildPreview.cs +++ b/src/core/DSharpPlus.Internal.Models/Guilds/GuildPreview.cs @@ -4,9 +4,9 @@ using System.Collections.Generic; -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record GuildPreview : IGuildPreview diff --git a/src/core/DSharpPlus.Core.Models/Guilds/GuildWidget.cs b/src/core/DSharpPlus.Internal.Models/Guilds/GuildWidget.cs similarity index 90% rename from src/core/DSharpPlus.Core.Models/Guilds/GuildWidget.cs rename to src/core/DSharpPlus.Internal.Models/Guilds/GuildWidget.cs index b790a58fe3..656c3ec21d 100644 --- a/src/core/DSharpPlus.Core.Models/Guilds/GuildWidget.cs +++ b/src/core/DSharpPlus.Internal.Models/Guilds/GuildWidget.cs @@ -4,9 +4,9 @@ using System.Collections.Generic; -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record GuildWidget : IGuildWidget diff --git a/src/core/DSharpPlus.Core.Models/Guilds/GuildWidgetSettings.cs b/src/core/DSharpPlus.Internal.Models/Guilds/GuildWidgetSettings.cs similarity index 84% rename from src/core/DSharpPlus.Core.Models/Guilds/GuildWidgetSettings.cs rename to src/core/DSharpPlus.Internal.Models/Guilds/GuildWidgetSettings.cs index 8892a812db..75e96dca25 100644 --- a/src/core/DSharpPlus.Core.Models/Guilds/GuildWidgetSettings.cs +++ b/src/core/DSharpPlus.Internal.Models/Guilds/GuildWidgetSettings.cs @@ -2,9 +2,9 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record GuildWidgetSettings : IGuildWidgetSettings diff --git a/src/core/DSharpPlus.Core.Models/Guilds/Integration.cs b/src/core/DSharpPlus.Internal.Models/Guilds/Integration.cs similarity index 95% rename from src/core/DSharpPlus.Core.Models/Guilds/Integration.cs rename to src/core/DSharpPlus.Internal.Models/Guilds/Integration.cs index 2f6c3b24d5..0148e91d42 100644 --- a/src/core/DSharpPlus.Core.Models/Guilds/Integration.cs +++ b/src/core/DSharpPlus.Internal.Models/Guilds/Integration.cs @@ -5,10 +5,10 @@ using System; using System.Collections.Generic; -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record Integration : IIntegration diff --git a/src/core/DSharpPlus.Core.Models/Guilds/IntegrationAccount.cs b/src/core/DSharpPlus.Internal.Models/Guilds/IntegrationAccount.cs similarity index 84% rename from src/core/DSharpPlus.Core.Models/Guilds/IntegrationAccount.cs rename to src/core/DSharpPlus.Internal.Models/Guilds/IntegrationAccount.cs index c4b550f10f..00edc79b1a 100644 --- a/src/core/DSharpPlus.Core.Models/Guilds/IntegrationAccount.cs +++ b/src/core/DSharpPlus.Internal.Models/Guilds/IntegrationAccount.cs @@ -2,9 +2,9 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record IntegrationAccount : IIntegrationAccount diff --git a/src/core/DSharpPlus.Core.Models/Guilds/IntegrationApplication.cs b/src/core/DSharpPlus.Internal.Models/Guilds/IntegrationApplication.cs similarity index 88% rename from src/core/DSharpPlus.Core.Models/Guilds/IntegrationApplication.cs rename to src/core/DSharpPlus.Internal.Models/Guilds/IntegrationApplication.cs index 8ce61e64e3..a0e94792ac 100644 --- a/src/core/DSharpPlus.Core.Models/Guilds/IntegrationApplication.cs +++ b/src/core/DSharpPlus.Internal.Models/Guilds/IntegrationApplication.cs @@ -2,9 +2,9 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record IntegrationApplication : IIntegrationApplication diff --git a/src/core/DSharpPlus.Core.Models/Guilds/Onboarding.cs b/src/core/DSharpPlus.Internal.Models/Guilds/Onboarding.cs similarity index 90% rename from src/core/DSharpPlus.Core.Models/Guilds/Onboarding.cs rename to src/core/DSharpPlus.Internal.Models/Guilds/Onboarding.cs index 4104328091..4ecf4fe759 100644 --- a/src/core/DSharpPlus.Core.Models/Guilds/Onboarding.cs +++ b/src/core/DSharpPlus.Internal.Models/Guilds/Onboarding.cs @@ -4,10 +4,10 @@ using System.Collections.Generic; -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record Onboarding : IOnboarding diff --git a/src/core/DSharpPlus.Core.Models/Guilds/OnboardingPrompt.cs b/src/core/DSharpPlus.Internal.Models/Guilds/OnboardingPrompt.cs similarity index 91% rename from src/core/DSharpPlus.Core.Models/Guilds/OnboardingPrompt.cs rename to src/core/DSharpPlus.Internal.Models/Guilds/OnboardingPrompt.cs index 7af80e023a..bf1c386d6b 100644 --- a/src/core/DSharpPlus.Core.Models/Guilds/OnboardingPrompt.cs +++ b/src/core/DSharpPlus.Internal.Models/Guilds/OnboardingPrompt.cs @@ -4,10 +4,10 @@ using System.Collections.Generic; -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record OnboardingPrompt : IOnboardingPrompt diff --git a/src/core/DSharpPlus.Core.Models/Guilds/OnboardingPromptOption.cs b/src/core/DSharpPlus.Internal.Models/Guilds/OnboardingPromptOption.cs similarity index 92% rename from src/core/DSharpPlus.Core.Models/Guilds/OnboardingPromptOption.cs rename to src/core/DSharpPlus.Internal.Models/Guilds/OnboardingPromptOption.cs index 2fac3933d6..94aadad807 100644 --- a/src/core/DSharpPlus.Core.Models/Guilds/OnboardingPromptOption.cs +++ b/src/core/DSharpPlus.Internal.Models/Guilds/OnboardingPromptOption.cs @@ -4,9 +4,9 @@ using System.Collections.Generic; -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record OnboardingPromptOption : IOnboardingPromptOption diff --git a/src/core/DSharpPlus.Core.Models/Guilds/PartialGuild.cs b/src/core/DSharpPlus.Internal.Models/Guilds/PartialGuild.cs similarity index 97% rename from src/core/DSharpPlus.Core.Models/Guilds/PartialGuild.cs rename to src/core/DSharpPlus.Internal.Models/Guilds/PartialGuild.cs index c4456eb8f8..2584da5b8f 100644 --- a/src/core/DSharpPlus.Core.Models/Guilds/PartialGuild.cs +++ b/src/core/DSharpPlus.Internal.Models/Guilds/PartialGuild.cs @@ -4,10 +4,10 @@ using System.Collections.Generic; -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record PartialGuild : IPartialGuild diff --git a/src/core/DSharpPlus.Core.Models/Guilds/PartialGuildMember.cs b/src/core/DSharpPlus.Internal.Models/Guilds/PartialGuildMember.cs similarity index 94% rename from src/core/DSharpPlus.Core.Models/Guilds/PartialGuildMember.cs rename to src/core/DSharpPlus.Internal.Models/Guilds/PartialGuildMember.cs index 639e4df778..3f1631f243 100644 --- a/src/core/DSharpPlus.Core.Models/Guilds/PartialGuildMember.cs +++ b/src/core/DSharpPlus.Internal.Models/Guilds/PartialGuildMember.cs @@ -5,10 +5,10 @@ using System; using System.Collections.Generic; -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record PartialGuildMember : IPartialGuildMember diff --git a/src/core/DSharpPlus.Core.Models/Guilds/PartialIntegration.cs b/src/core/DSharpPlus.Internal.Models/Guilds/PartialIntegration.cs similarity index 95% rename from src/core/DSharpPlus.Core.Models/Guilds/PartialIntegration.cs rename to src/core/DSharpPlus.Internal.Models/Guilds/PartialIntegration.cs index bb2b1e262c..b2f20c0063 100644 --- a/src/core/DSharpPlus.Core.Models/Guilds/PartialIntegration.cs +++ b/src/core/DSharpPlus.Internal.Models/Guilds/PartialIntegration.cs @@ -5,10 +5,10 @@ using System; using System.Collections.Generic; -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record PartialIntegration : IPartialIntegration diff --git a/src/core/DSharpPlus.Core.Models/Guilds/PartialRole.cs b/src/core/DSharpPlus.Internal.Models/Guilds/PartialRole.cs similarity index 93% rename from src/core/DSharpPlus.Core.Models/Guilds/PartialRole.cs rename to src/core/DSharpPlus.Internal.Models/Guilds/PartialRole.cs index 95136434be..280cb7302f 100644 --- a/src/core/DSharpPlus.Core.Models/Guilds/PartialRole.cs +++ b/src/core/DSharpPlus.Internal.Models/Guilds/PartialRole.cs @@ -2,10 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record PartialRole : IPartialRole diff --git a/src/core/DSharpPlus.Core.Models/Guilds/Role.cs b/src/core/DSharpPlus.Internal.Models/Guilds/Role.cs similarity index 93% rename from src/core/DSharpPlus.Core.Models/Guilds/Role.cs rename to src/core/DSharpPlus.Internal.Models/Guilds/Role.cs index 3820f5599a..28e2c6a45d 100644 --- a/src/core/DSharpPlus.Core.Models/Guilds/Role.cs +++ b/src/core/DSharpPlus.Internal.Models/Guilds/Role.cs @@ -2,10 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record Role : IRole diff --git a/src/core/DSharpPlus.Core.Models/Guilds/RoleTags.cs b/src/core/DSharpPlus.Internal.Models/Guilds/RoleTags.cs similarity index 90% rename from src/core/DSharpPlus.Core.Models/Guilds/RoleTags.cs rename to src/core/DSharpPlus.Internal.Models/Guilds/RoleTags.cs index 8d2c6a8fe3..86ed1616bc 100644 --- a/src/core/DSharpPlus.Core.Models/Guilds/RoleTags.cs +++ b/src/core/DSharpPlus.Internal.Models/Guilds/RoleTags.cs @@ -2,9 +2,9 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record RoleTags : IRoleTags diff --git a/src/core/DSharpPlus.Core.Models/Guilds/WelcomeScreen.cs b/src/core/DSharpPlus.Internal.Models/Guilds/WelcomeScreen.cs similarity index 85% rename from src/core/DSharpPlus.Core.Models/Guilds/WelcomeScreen.cs rename to src/core/DSharpPlus.Internal.Models/Guilds/WelcomeScreen.cs index f60fcb346a..3282897a46 100644 --- a/src/core/DSharpPlus.Core.Models/Guilds/WelcomeScreen.cs +++ b/src/core/DSharpPlus.Internal.Models/Guilds/WelcomeScreen.cs @@ -4,9 +4,9 @@ using System.Collections.Generic; -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record WelcomeScreen : IWelcomeScreen diff --git a/src/core/DSharpPlus.Core.Models/Guilds/WelcomeScreenChannel.cs b/src/core/DSharpPlus.Internal.Models/Guilds/WelcomeScreenChannel.cs similarity index 87% rename from src/core/DSharpPlus.Core.Models/Guilds/WelcomeScreenChannel.cs rename to src/core/DSharpPlus.Internal.Models/Guilds/WelcomeScreenChannel.cs index 5ff7e6dfcd..fddbce72ae 100644 --- a/src/core/DSharpPlus.Core.Models/Guilds/WelcomeScreenChannel.cs +++ b/src/core/DSharpPlus.Internal.Models/Guilds/WelcomeScreenChannel.cs @@ -2,9 +2,9 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record WelcomeScreenChannel : IWelcomeScreenChannel diff --git a/src/core/DSharpPlus.Core.Models/Interactions/ApplicationCommandInteractionData.cs b/src/core/DSharpPlus.Internal.Models/Interactions/ApplicationCommandInteractionData.cs similarity index 92% rename from src/core/DSharpPlus.Core.Models/Interactions/ApplicationCommandInteractionData.cs rename to src/core/DSharpPlus.Internal.Models/Interactions/ApplicationCommandInteractionData.cs index 2036460983..7d6e0f1e55 100644 --- a/src/core/DSharpPlus.Core.Models/Interactions/ApplicationCommandInteractionData.cs +++ b/src/core/DSharpPlus.Internal.Models/Interactions/ApplicationCommandInteractionData.cs @@ -4,10 +4,10 @@ using System.Collections.Generic; -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record ApplicationCommandInteractionData : IApplicationCommandInteractionData diff --git a/src/core/DSharpPlus.Core.Models/Interactions/ApplicationCommandInteractionDataOption.cs b/src/core/DSharpPlus.Internal.Models/Interactions/ApplicationCommandInteractionDataOption.cs similarity index 91% rename from src/core/DSharpPlus.Core.Models/Interactions/ApplicationCommandInteractionDataOption.cs rename to src/core/DSharpPlus.Internal.Models/Interactions/ApplicationCommandInteractionDataOption.cs index 79c93d3770..f709d0f2a1 100644 --- a/src/core/DSharpPlus.Core.Models/Interactions/ApplicationCommandInteractionDataOption.cs +++ b/src/core/DSharpPlus.Internal.Models/Interactions/ApplicationCommandInteractionDataOption.cs @@ -4,12 +4,12 @@ using System.Collections.Generic; -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; using OneOf; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record ApplicationCommandInteractionDataOption : IApplicationCommandInteractionDataOption diff --git a/src/core/DSharpPlus.Core.Models/Interactions/AutocompleteCallbackData.cs b/src/core/DSharpPlus.Internal.Models/Interactions/AutocompleteCallbackData.cs similarity index 85% rename from src/core/DSharpPlus.Core.Models/Interactions/AutocompleteCallbackData.cs rename to src/core/DSharpPlus.Internal.Models/Interactions/AutocompleteCallbackData.cs index 9c825386c6..6f7179f48f 100644 --- a/src/core/DSharpPlus.Core.Models/Interactions/AutocompleteCallbackData.cs +++ b/src/core/DSharpPlus.Internal.Models/Interactions/AutocompleteCallbackData.cs @@ -4,9 +4,9 @@ using System.Collections.Generic; -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record AutocompleteCallbackData : IAutocompleteCallbackData diff --git a/src/core/DSharpPlus.Core.Models/Interactions/Interaction.cs b/src/core/DSharpPlus.Internal.Models/Interactions/Interaction.cs similarity index 95% rename from src/core/DSharpPlus.Core.Models/Interactions/Interaction.cs rename to src/core/DSharpPlus.Internal.Models/Interactions/Interaction.cs index 0c58fc45fa..6c1b72ca42 100644 --- a/src/core/DSharpPlus.Core.Models/Interactions/Interaction.cs +++ b/src/core/DSharpPlus.Internal.Models/Interactions/Interaction.cs @@ -4,12 +4,12 @@ using System.Collections.Generic; -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; using OneOf; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record Interaction : IInteraction diff --git a/src/core/DSharpPlus.Core.Models/Interactions/InteractionResponse.cs b/src/core/DSharpPlus.Internal.Models/Interactions/InteractionResponse.cs similarity index 87% rename from src/core/DSharpPlus.Core.Models/Interactions/InteractionResponse.cs rename to src/core/DSharpPlus.Internal.Models/Interactions/InteractionResponse.cs index 286913311d..b35696e7d8 100644 --- a/src/core/DSharpPlus.Core.Models/Interactions/InteractionResponse.cs +++ b/src/core/DSharpPlus.Internal.Models/Interactions/InteractionResponse.cs @@ -2,12 +2,12 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; using OneOf; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record InteractionResponse : IInteractionResponse diff --git a/src/core/DSharpPlus.Core.Models/Interactions/MessageCallbackData.cs b/src/core/DSharpPlus.Internal.Models/Interactions/MessageCallbackData.cs similarity index 92% rename from src/core/DSharpPlus.Core.Models/Interactions/MessageCallbackData.cs rename to src/core/DSharpPlus.Internal.Models/Interactions/MessageCallbackData.cs index 5a4019d051..01b2d26188 100644 --- a/src/core/DSharpPlus.Core.Models/Interactions/MessageCallbackData.cs +++ b/src/core/DSharpPlus.Internal.Models/Interactions/MessageCallbackData.cs @@ -4,10 +4,10 @@ using System.Collections.Generic; -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record MessageCallbackData : IMessageCallbackData diff --git a/src/core/DSharpPlus.Core.Models/Interactions/MessageComponentInteractionData.cs b/src/core/DSharpPlus.Internal.Models/Interactions/MessageComponentInteractionData.cs similarity index 90% rename from src/core/DSharpPlus.Core.Models/Interactions/MessageComponentInteractionData.cs rename to src/core/DSharpPlus.Internal.Models/Interactions/MessageComponentInteractionData.cs index 13eab2b36b..1441bc3310 100644 --- a/src/core/DSharpPlus.Core.Models/Interactions/MessageComponentInteractionData.cs +++ b/src/core/DSharpPlus.Internal.Models/Interactions/MessageComponentInteractionData.cs @@ -4,10 +4,10 @@ using System.Collections.Generic; -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record MessageComponentInteractionData : IMessageComponentInteractionData diff --git a/src/core/DSharpPlus.Core.Models/Interactions/MessageInteraction.cs b/src/core/DSharpPlus.Internal.Models/Interactions/MessageInteraction.cs similarity index 89% rename from src/core/DSharpPlus.Core.Models/Interactions/MessageInteraction.cs rename to src/core/DSharpPlus.Internal.Models/Interactions/MessageInteraction.cs index 14ca9252ef..082a8d4ebe 100644 --- a/src/core/DSharpPlus.Core.Models/Interactions/MessageInteraction.cs +++ b/src/core/DSharpPlus.Internal.Models/Interactions/MessageInteraction.cs @@ -2,10 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record MessageInteraction : IMessageInteraction diff --git a/src/core/DSharpPlus.Core.Models/Interactions/ModalCallbackData.cs b/src/core/DSharpPlus.Internal.Models/Interactions/ModalCallbackData.cs similarity index 87% rename from src/core/DSharpPlus.Core.Models/Interactions/ModalCallbackData.cs rename to src/core/DSharpPlus.Internal.Models/Interactions/ModalCallbackData.cs index f3624aa537..67398d0b9c 100644 --- a/src/core/DSharpPlus.Core.Models/Interactions/ModalCallbackData.cs +++ b/src/core/DSharpPlus.Internal.Models/Interactions/ModalCallbackData.cs @@ -4,9 +4,9 @@ using System.Collections.Generic; -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record ModalCallbackData : IModalCallbackData diff --git a/src/core/DSharpPlus.Core.Models/Interactions/ModalInteractionData.cs b/src/core/DSharpPlus.Internal.Models/Interactions/ModalInteractionData.cs similarity index 86% rename from src/core/DSharpPlus.Core.Models/Interactions/ModalInteractionData.cs rename to src/core/DSharpPlus.Internal.Models/Interactions/ModalInteractionData.cs index 6095abdc12..5263dee7fc 100644 --- a/src/core/DSharpPlus.Core.Models/Interactions/ModalInteractionData.cs +++ b/src/core/DSharpPlus.Internal.Models/Interactions/ModalInteractionData.cs @@ -4,9 +4,9 @@ using System.Collections.Generic; -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record ModalInteractionData : IModalInteractionData diff --git a/src/core/DSharpPlus.Core.Models/Interactions/ResolvedData.cs b/src/core/DSharpPlus.Internal.Models/Interactions/ResolvedData.cs similarity index 92% rename from src/core/DSharpPlus.Core.Models/Interactions/ResolvedData.cs rename to src/core/DSharpPlus.Internal.Models/Interactions/ResolvedData.cs index 2d40808d65..2b57cb7e4a 100644 --- a/src/core/DSharpPlus.Core.Models/Interactions/ResolvedData.cs +++ b/src/core/DSharpPlus.Internal.Models/Interactions/ResolvedData.cs @@ -4,9 +4,9 @@ using System.Collections.Generic; -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record ResolvedData : IResolvedData diff --git a/src/core/DSharpPlus.Core.Models/Invites/Invite.cs b/src/core/DSharpPlus.Internal.Models/Invites/Invite.cs similarity index 94% rename from src/core/DSharpPlus.Core.Models/Invites/Invite.cs rename to src/core/DSharpPlus.Internal.Models/Invites/Invite.cs index 6c60bd58a4..445030e990 100644 --- a/src/core/DSharpPlus.Core.Models/Invites/Invite.cs +++ b/src/core/DSharpPlus.Internal.Models/Invites/Invite.cs @@ -4,10 +4,10 @@ using System; -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record Invite : IInvite diff --git a/src/core/DSharpPlus.Core.Models/Invites/PartialInvite.cs b/src/core/DSharpPlus.Internal.Models/Invites/PartialInvite.cs similarity index 95% rename from src/core/DSharpPlus.Core.Models/Invites/PartialInvite.cs rename to src/core/DSharpPlus.Internal.Models/Invites/PartialInvite.cs index e52268c5f4..1c53630533 100644 --- a/src/core/DSharpPlus.Core.Models/Invites/PartialInvite.cs +++ b/src/core/DSharpPlus.Internal.Models/Invites/PartialInvite.cs @@ -4,10 +4,10 @@ using System; -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record PartialInvite : IPartialInvite diff --git a/src/core/DSharpPlus.Core.Models/MessageComponents/ActionRowComponent.cs b/src/core/DSharpPlus.Internal.Models/MessageComponents/ActionRowComponent.cs similarity index 87% rename from src/core/DSharpPlus.Core.Models/MessageComponents/ActionRowComponent.cs rename to src/core/DSharpPlus.Internal.Models/MessageComponents/ActionRowComponent.cs index 1b979d58d1..553ca95078 100644 --- a/src/core/DSharpPlus.Core.Models/MessageComponents/ActionRowComponent.cs +++ b/src/core/DSharpPlus.Internal.Models/MessageComponents/ActionRowComponent.cs @@ -4,10 +4,10 @@ using System.Collections.Generic; -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record ActionRowComponent : IActionRowComponent diff --git a/src/core/DSharpPlus.Core.Models/MessageComponents/ButtonComponent.cs b/src/core/DSharpPlus.Internal.Models/MessageComponents/ButtonComponent.cs similarity index 91% rename from src/core/DSharpPlus.Core.Models/MessageComponents/ButtonComponent.cs rename to src/core/DSharpPlus.Internal.Models/MessageComponents/ButtonComponent.cs index 7fe38e479e..9aa102b7ad 100644 --- a/src/core/DSharpPlus.Core.Models/MessageComponents/ButtonComponent.cs +++ b/src/core/DSharpPlus.Internal.Models/MessageComponents/ButtonComponent.cs @@ -2,10 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record ButtonComponent : IButtonComponent diff --git a/src/core/DSharpPlus.Core.Models/MessageComponents/ChannelSelectComponent.cs b/src/core/DSharpPlus.Internal.Models/MessageComponents/ChannelSelectComponent.cs similarity index 92% rename from src/core/DSharpPlus.Core.Models/MessageComponents/ChannelSelectComponent.cs rename to src/core/DSharpPlus.Internal.Models/MessageComponents/ChannelSelectComponent.cs index 2b26dfa9a2..2ab9883926 100644 --- a/src/core/DSharpPlus.Core.Models/MessageComponents/ChannelSelectComponent.cs +++ b/src/core/DSharpPlus.Internal.Models/MessageComponents/ChannelSelectComponent.cs @@ -4,10 +4,10 @@ using System.Collections.Generic; -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record ChannelSelectComponent : IChannelSelectComponent diff --git a/src/core/DSharpPlus.Core.Models/MessageComponents/DefaultSelectValue.cs b/src/core/DSharpPlus.Internal.Models/MessageComponents/DefaultSelectValue.cs similarity index 84% rename from src/core/DSharpPlus.Core.Models/MessageComponents/DefaultSelectValue.cs rename to src/core/DSharpPlus.Internal.Models/MessageComponents/DefaultSelectValue.cs index 9eea134cf8..80a96fa1ad 100644 --- a/src/core/DSharpPlus.Core.Models/MessageComponents/DefaultSelectValue.cs +++ b/src/core/DSharpPlus.Internal.Models/MessageComponents/DefaultSelectValue.cs @@ -2,9 +2,9 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record DefaultSelectValue : IDefaultSelectValue diff --git a/src/core/DSharpPlus.Core.Models/MessageComponents/InteractiveComponent.cs b/src/core/DSharpPlus.Internal.Models/MessageComponents/InteractiveComponent.cs similarity index 82% rename from src/core/DSharpPlus.Core.Models/MessageComponents/InteractiveComponent.cs rename to src/core/DSharpPlus.Internal.Models/MessageComponents/InteractiveComponent.cs index dcfd83e904..5fa975e40f 100644 --- a/src/core/DSharpPlus.Core.Models/MessageComponents/InteractiveComponent.cs +++ b/src/core/DSharpPlus.Internal.Models/MessageComponents/InteractiveComponent.cs @@ -2,9 +2,9 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// /// Placeholder implementation of a marker interface. Please report spotting this to library developers. diff --git a/src/core/DSharpPlus.Core.Models/MessageComponents/MentionableSelectComponent.cs b/src/core/DSharpPlus.Internal.Models/MessageComponents/MentionableSelectComponent.cs similarity index 91% rename from src/core/DSharpPlus.Core.Models/MessageComponents/MentionableSelectComponent.cs rename to src/core/DSharpPlus.Internal.Models/MessageComponents/MentionableSelectComponent.cs index 3ee76006ae..f6c9cb4a19 100644 --- a/src/core/DSharpPlus.Core.Models/MessageComponents/MentionableSelectComponent.cs +++ b/src/core/DSharpPlus.Internal.Models/MessageComponents/MentionableSelectComponent.cs @@ -4,10 +4,10 @@ using System.Collections.Generic; -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record MentionableSelectComponent : IMentionableSelectComponent diff --git a/src/core/DSharpPlus.Core.Models/MessageComponents/RoleSelectComponent.cs b/src/core/DSharpPlus.Internal.Models/MessageComponents/RoleSelectComponent.cs similarity index 91% rename from src/core/DSharpPlus.Core.Models/MessageComponents/RoleSelectComponent.cs rename to src/core/DSharpPlus.Internal.Models/MessageComponents/RoleSelectComponent.cs index bd6036a5a6..088902328c 100644 --- a/src/core/DSharpPlus.Core.Models/MessageComponents/RoleSelectComponent.cs +++ b/src/core/DSharpPlus.Internal.Models/MessageComponents/RoleSelectComponent.cs @@ -4,10 +4,10 @@ using System.Collections.Generic; -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record RoleSelectComponent : IRoleSelectComponent diff --git a/src/core/DSharpPlus.Core.Models/MessageComponents/SelectOption.cs b/src/core/DSharpPlus.Internal.Models/MessageComponents/SelectOption.cs similarity index 88% rename from src/core/DSharpPlus.Core.Models/MessageComponents/SelectOption.cs rename to src/core/DSharpPlus.Internal.Models/MessageComponents/SelectOption.cs index ec910bce9a..344ea8fe03 100644 --- a/src/core/DSharpPlus.Core.Models/MessageComponents/SelectOption.cs +++ b/src/core/DSharpPlus.Internal.Models/MessageComponents/SelectOption.cs @@ -2,9 +2,9 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record SelectOption : ISelectOption diff --git a/src/core/DSharpPlus.Core.Models/MessageComponents/StringSelectComponent.cs b/src/core/DSharpPlus.Internal.Models/MessageComponents/StringSelectComponent.cs similarity index 91% rename from src/core/DSharpPlus.Core.Models/MessageComponents/StringSelectComponent.cs rename to src/core/DSharpPlus.Internal.Models/MessageComponents/StringSelectComponent.cs index 9ad8d36a21..6a90cb35a3 100644 --- a/src/core/DSharpPlus.Core.Models/MessageComponents/StringSelectComponent.cs +++ b/src/core/DSharpPlus.Internal.Models/MessageComponents/StringSelectComponent.cs @@ -4,10 +4,10 @@ using System.Collections.Generic; -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record StringSelectComponent : IStringSelectComponent diff --git a/src/core/DSharpPlus.Core.Models/MessageComponents/TextInputComponent.cs b/src/core/DSharpPlus.Internal.Models/MessageComponents/TextInputComponent.cs similarity index 92% rename from src/core/DSharpPlus.Core.Models/MessageComponents/TextInputComponent.cs rename to src/core/DSharpPlus.Internal.Models/MessageComponents/TextInputComponent.cs index b742f6312c..9c689e604d 100644 --- a/src/core/DSharpPlus.Core.Models/MessageComponents/TextInputComponent.cs +++ b/src/core/DSharpPlus.Internal.Models/MessageComponents/TextInputComponent.cs @@ -2,10 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record TextInputComponent : ITextInputComponent diff --git a/src/core/DSharpPlus.Core.Models/MessageComponents/UserSelectComponent.cs b/src/core/DSharpPlus.Internal.Models/MessageComponents/UserSelectComponent.cs similarity index 91% rename from src/core/DSharpPlus.Core.Models/MessageComponents/UserSelectComponent.cs rename to src/core/DSharpPlus.Internal.Models/MessageComponents/UserSelectComponent.cs index f618aeb7ff..927e52a63b 100644 --- a/src/core/DSharpPlus.Core.Models/MessageComponents/UserSelectComponent.cs +++ b/src/core/DSharpPlus.Internal.Models/MessageComponents/UserSelectComponent.cs @@ -4,10 +4,10 @@ using System.Collections.Generic; -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record UserSelectComponent : IUserSelectComponent diff --git a/src/core/DSharpPlus.Core.Models/RoleConnections/RoleConnectionMetadata.cs b/src/core/DSharpPlus.Internal.Models/RoleConnections/RoleConnectionMetadata.cs similarity index 91% rename from src/core/DSharpPlus.Core.Models/RoleConnections/RoleConnectionMetadata.cs rename to src/core/DSharpPlus.Internal.Models/RoleConnections/RoleConnectionMetadata.cs index 7d72e1391b..217358ee80 100644 --- a/src/core/DSharpPlus.Core.Models/RoleConnections/RoleConnectionMetadata.cs +++ b/src/core/DSharpPlus.Internal.Models/RoleConnections/RoleConnectionMetadata.cs @@ -4,10 +4,10 @@ using System.Collections.Generic; -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record RoleConnectionMetadata : IRoleConnectionMetadata diff --git a/src/core/DSharpPlus.Core.Models/ScheduledEvents/PartialScheduledEvent.cs b/src/core/DSharpPlus.Internal.Models/ScheduledEvents/PartialScheduledEvent.cs similarity index 94% rename from src/core/DSharpPlus.Core.Models/ScheduledEvents/PartialScheduledEvent.cs rename to src/core/DSharpPlus.Internal.Models/ScheduledEvents/PartialScheduledEvent.cs index 4deca40b39..05960ae80d 100644 --- a/src/core/DSharpPlus.Core.Models/ScheduledEvents/PartialScheduledEvent.cs +++ b/src/core/DSharpPlus.Internal.Models/ScheduledEvents/PartialScheduledEvent.cs @@ -4,10 +4,10 @@ using System; -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record PartialScheduledEvent : IPartialScheduledEvent diff --git a/src/core/DSharpPlus.Core.Models/ScheduledEvents/ScheduledEvent.cs b/src/core/DSharpPlus.Internal.Models/ScheduledEvents/ScheduledEvent.cs similarity index 94% rename from src/core/DSharpPlus.Core.Models/ScheduledEvents/ScheduledEvent.cs rename to src/core/DSharpPlus.Internal.Models/ScheduledEvents/ScheduledEvent.cs index 17d478ea07..796dcf60a8 100644 --- a/src/core/DSharpPlus.Core.Models/ScheduledEvents/ScheduledEvent.cs +++ b/src/core/DSharpPlus.Internal.Models/ScheduledEvents/ScheduledEvent.cs @@ -4,10 +4,10 @@ using System; -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record ScheduledEvent : IScheduledEvent diff --git a/src/core/DSharpPlus.Core.Models/ScheduledEvents/ScheduledEventMetadata.cs b/src/core/DSharpPlus.Internal.Models/ScheduledEvents/ScheduledEventMetadata.cs similarity index 82% rename from src/core/DSharpPlus.Core.Models/ScheduledEvents/ScheduledEventMetadata.cs rename to src/core/DSharpPlus.Internal.Models/ScheduledEvents/ScheduledEventMetadata.cs index 6d752044b2..e0c4ff0def 100644 --- a/src/core/DSharpPlus.Core.Models/ScheduledEvents/ScheduledEventMetadata.cs +++ b/src/core/DSharpPlus.Internal.Models/ScheduledEvents/ScheduledEventMetadata.cs @@ -2,9 +2,9 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record ScheduledEventMetadata : IScheduledEventMetadata diff --git a/src/core/DSharpPlus.Core.Models/ScheduledEvents/ScheduledEventUser.cs b/src/core/DSharpPlus.Internal.Models/ScheduledEvents/ScheduledEventUser.cs similarity index 86% rename from src/core/DSharpPlus.Core.Models/ScheduledEvents/ScheduledEventUser.cs rename to src/core/DSharpPlus.Internal.Models/ScheduledEvents/ScheduledEventUser.cs index 132318c91f..41bcd9d5fe 100644 --- a/src/core/DSharpPlus.Core.Models/ScheduledEvents/ScheduledEventUser.cs +++ b/src/core/DSharpPlus.Internal.Models/ScheduledEvents/ScheduledEventUser.cs @@ -2,9 +2,9 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record ScheduledEventUser : IScheduledEventUser diff --git a/src/core/DSharpPlus.Core.Models/Serialization/Converters/AuditLogChangeConverter.cs b/src/core/DSharpPlus.Internal.Models/Serialization/Converters/AuditLogChangeConverter.cs similarity index 95% rename from src/core/DSharpPlus.Core.Models/Serialization/Converters/AuditLogChangeConverter.cs rename to src/core/DSharpPlus.Internal.Models/Serialization/Converters/AuditLogChangeConverter.cs index 3c77e96555..82f32e488f 100644 --- a/src/core/DSharpPlus.Core.Models/Serialization/Converters/AuditLogChangeConverter.cs +++ b/src/core/DSharpPlus.Internal.Models/Serialization/Converters/AuditLogChangeConverter.cs @@ -6,9 +6,9 @@ using System.Text.Json; using System.Text.Json.Serialization; -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; -namespace DSharpPlus.Core.Models.Serialization.Converters; +namespace DSharpPlus.Internal.Models.Serialization.Converters; /// /// Provides conversion for s. diff --git a/src/core/DSharpPlus.Core.Models/Serialization/Converters/AutoModerationActionConverter.cs b/src/core/DSharpPlus.Internal.Models/Serialization/Converters/AutoModerationActionConverter.cs similarity index 96% rename from src/core/DSharpPlus.Core.Models/Serialization/Converters/AutoModerationActionConverter.cs rename to src/core/DSharpPlus.Internal.Models/Serialization/Converters/AutoModerationActionConverter.cs index 80be092ce9..d81c53ca3d 100644 --- a/src/core/DSharpPlus.Core.Models/Serialization/Converters/AutoModerationActionConverter.cs +++ b/src/core/DSharpPlus.Internal.Models/Serialization/Converters/AutoModerationActionConverter.cs @@ -6,10 +6,10 @@ using System.Text.Json; using System.Text.Json.Serialization; -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; -namespace DSharpPlus.Core.Models.Serialization.Converters; +namespace DSharpPlus.Internal.Models.Serialization.Converters; /// /// Provides conversion for . diff --git a/src/core/DSharpPlus.Core.Models/Serialization/Converters/DiscordPermissionConverter.cs b/src/core/DSharpPlus.Internal.Models/Serialization/Converters/DiscordPermissionConverter.cs similarity index 95% rename from src/core/DSharpPlus.Core.Models/Serialization/Converters/DiscordPermissionConverter.cs rename to src/core/DSharpPlus.Internal.Models/Serialization/Converters/DiscordPermissionConverter.cs index 370191e27c..219d7eea8b 100644 --- a/src/core/DSharpPlus.Core.Models/Serialization/Converters/DiscordPermissionConverter.cs +++ b/src/core/DSharpPlus.Internal.Models/Serialization/Converters/DiscordPermissionConverter.cs @@ -9,7 +9,7 @@ using DSharpPlus.Entities; -namespace DSharpPlus.Core.Models.Serialization.Converters; +namespace DSharpPlus.Internal.Models.Serialization.Converters; /// /// Enables serializing and deserializing Discord permissions. diff --git a/src/core/DSharpPlus.Core.Models/Serialization/Converters/MessageComponentConverter.cs b/src/core/DSharpPlus.Internal.Models/Serialization/Converters/MessageComponentConverter.cs similarity index 97% rename from src/core/DSharpPlus.Core.Models/Serialization/Converters/MessageComponentConverter.cs rename to src/core/DSharpPlus.Internal.Models/Serialization/Converters/MessageComponentConverter.cs index 1822521f3d..ec86402ae3 100644 --- a/src/core/DSharpPlus.Core.Models/Serialization/Converters/MessageComponentConverter.cs +++ b/src/core/DSharpPlus.Internal.Models/Serialization/Converters/MessageComponentConverter.cs @@ -6,10 +6,10 @@ using System.Text.Json; using System.Text.Json.Serialization; -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; -namespace DSharpPlus.Core.Models.Serialization.Converters; +namespace DSharpPlus.Internal.Models.Serialization.Converters; /// /// Converts between message components and JSON. diff --git a/src/core/DSharpPlus.Core.Models/Serialization/Converters/NullBooleanConverter.cs b/src/core/DSharpPlus.Internal.Models/Serialization/Converters/NullBooleanConverter.cs similarity index 96% rename from src/core/DSharpPlus.Core.Models/Serialization/Converters/NullBooleanConverter.cs rename to src/core/DSharpPlus.Internal.Models/Serialization/Converters/NullBooleanConverter.cs index 1c8dd5895a..fe7c0daf64 100644 --- a/src/core/DSharpPlus.Core.Models/Serialization/Converters/NullBooleanConverter.cs +++ b/src/core/DSharpPlus.Internal.Models/Serialization/Converters/NullBooleanConverter.cs @@ -6,7 +6,7 @@ using System.Text.Json; using System.Text.Json.Serialization; -namespace DSharpPlus.Core.Models.Serialization.Converters; +namespace DSharpPlus.Internal.Models.Serialization.Converters; /// /// Provides serialization for discord's optional null booleans, see diff --git a/src/core/DSharpPlus.Core.Models/Serialization/Converters/OneOfConverter.cs b/src/core/DSharpPlus.Internal.Models/Serialization/Converters/OneOfConverter.cs similarity index 99% rename from src/core/DSharpPlus.Core.Models/Serialization/Converters/OneOfConverter.cs rename to src/core/DSharpPlus.Internal.Models/Serialization/Converters/OneOfConverter.cs index 529cce62fb..066232b152 100644 --- a/src/core/DSharpPlus.Core.Models/Serialization/Converters/OneOfConverter.cs +++ b/src/core/DSharpPlus.Internal.Models/Serialization/Converters/OneOfConverter.cs @@ -16,7 +16,7 @@ using OneOf; -namespace DSharpPlus.Core.Models.Serialization.Converters; +namespace DSharpPlus.Internal.Models.Serialization.Converters; /// /// Provides a mechanicsm for serializing and deserializing objects. diff --git a/src/core/DSharpPlus.Core.Models/Serialization/Converters/OneOfConverterFactory.cs b/src/core/DSharpPlus.Internal.Models/Serialization/Converters/OneOfConverterFactory.cs similarity index 93% rename from src/core/DSharpPlus.Core.Models/Serialization/Converters/OneOfConverterFactory.cs rename to src/core/DSharpPlus.Internal.Models/Serialization/Converters/OneOfConverterFactory.cs index 6247bb8bf4..5b43c00763 100644 --- a/src/core/DSharpPlus.Core.Models/Serialization/Converters/OneOfConverterFactory.cs +++ b/src/core/DSharpPlus.Internal.Models/Serialization/Converters/OneOfConverterFactory.cs @@ -8,7 +8,7 @@ using OneOf; -namespace DSharpPlus.Core.Models.Serialization.Converters; +namespace DSharpPlus.Internal.Models.Serialization.Converters; /// /// Provides a factory for OneOf converters. diff --git a/src/core/DSharpPlus.Core.Models/Serialization/Converters/OptionalConverter.cs b/src/core/DSharpPlus.Internal.Models/Serialization/Converters/OptionalConverter.cs similarity index 93% rename from src/core/DSharpPlus.Core.Models/Serialization/Converters/OptionalConverter.cs rename to src/core/DSharpPlus.Internal.Models/Serialization/Converters/OptionalConverter.cs index 10ef490241..74b5373161 100644 --- a/src/core/DSharpPlus.Core.Models/Serialization/Converters/OptionalConverter.cs +++ b/src/core/DSharpPlus.Internal.Models/Serialization/Converters/OptionalConverter.cs @@ -6,7 +6,7 @@ using System.Text.Json; using System.Text.Json.Serialization; -namespace DSharpPlus.Core.Models.Serialization.Converters; +namespace DSharpPlus.Internal.Models.Serialization.Converters; /// /// A converter for . diff --git a/src/core/DSharpPlus.Core.Models/Serialization/Converters/OptionalConverterFactory.cs b/src/core/DSharpPlus.Internal.Models/Serialization/Converters/OptionalConverterFactory.cs similarity index 93% rename from src/core/DSharpPlus.Core.Models/Serialization/Converters/OptionalConverterFactory.cs rename to src/core/DSharpPlus.Internal.Models/Serialization/Converters/OptionalConverterFactory.cs index 9beca654ba..5c45051c48 100644 --- a/src/core/DSharpPlus.Core.Models/Serialization/Converters/OptionalConverterFactory.cs +++ b/src/core/DSharpPlus.Internal.Models/Serialization/Converters/OptionalConverterFactory.cs @@ -6,7 +6,7 @@ using System.Text.Json; using System.Text.Json.Serialization; -namespace DSharpPlus.Core.Models.Serialization.Converters; +namespace DSharpPlus.Internal.Models.Serialization.Converters; /// /// A converter factory for . diff --git a/src/core/DSharpPlus.Core.Models/Serialization/Converters/SnowflakeConverter.cs b/src/core/DSharpPlus.Internal.Models/Serialization/Converters/SnowflakeConverter.cs similarity index 93% rename from src/core/DSharpPlus.Core.Models/Serialization/Converters/SnowflakeConverter.cs rename to src/core/DSharpPlus.Internal.Models/Serialization/Converters/SnowflakeConverter.cs index 462e48cdf5..ea4bcb8711 100644 --- a/src/core/DSharpPlus.Core.Models/Serialization/Converters/SnowflakeConverter.cs +++ b/src/core/DSharpPlus.Internal.Models/Serialization/Converters/SnowflakeConverter.cs @@ -7,7 +7,7 @@ using System.Text.Json; using System.Text.Json.Serialization; -namespace DSharpPlus.Core.Models.Serialization.Converters; +namespace DSharpPlus.Internal.Models.Serialization.Converters; public sealed class SnowflakeConverter : JsonConverter { diff --git a/src/core/DSharpPlus.Core.Models/Serialization/Resolvers/NullBooleanTypeInfoResolver.cs b/src/core/DSharpPlus.Internal.Models/Serialization/Resolvers/NullBooleanTypeInfoResolver.cs similarity index 85% rename from src/core/DSharpPlus.Core.Models/Serialization/Resolvers/NullBooleanTypeInfoResolver.cs rename to src/core/DSharpPlus.Internal.Models/Serialization/Resolvers/NullBooleanTypeInfoResolver.cs index 7bedc9bbe2..8f90dbb6fc 100644 --- a/src/core/DSharpPlus.Core.Models/Serialization/Resolvers/NullBooleanTypeInfoResolver.cs +++ b/src/core/DSharpPlus.Internal.Models/Serialization/Resolvers/NullBooleanTypeInfoResolver.cs @@ -4,10 +4,10 @@ using System.Text.Json.Serialization.Metadata; -using DSharpPlus.Core.Abstractions.Models; -using DSharpPlus.Core.Models.Serialization.Converters; +using DSharpPlus.Internal.Abstractions.Models; +using DSharpPlus.Internal.Models.Serialization.Converters; -namespace DSharpPlus.Core.Models.Serialization.Resolvers; +namespace DSharpPlus.Internal.Models.Serialization.Resolvers; public static class NullBooleanTypeInfoResolver { diff --git a/src/core/DSharpPlus.Core.Models/Serialization/Resolvers/OptionalTypeInfoResolver.cs b/src/core/DSharpPlus.Internal.Models/Serialization/Resolvers/OptionalTypeInfoResolver.cs similarity index 96% rename from src/core/DSharpPlus.Core.Models/Serialization/Resolvers/OptionalTypeInfoResolver.cs rename to src/core/DSharpPlus.Internal.Models/Serialization/Resolvers/OptionalTypeInfoResolver.cs index 10faad2db1..c454eb5df4 100644 --- a/src/core/DSharpPlus.Core.Models/Serialization/Resolvers/OptionalTypeInfoResolver.cs +++ b/src/core/DSharpPlus.Internal.Models/Serialization/Resolvers/OptionalTypeInfoResolver.cs @@ -7,7 +7,7 @@ using System.Runtime.CompilerServices; using System.Text.Json.Serialization.Metadata; -namespace DSharpPlus.Core.Models.Serialization.Resolvers; +namespace DSharpPlus.Internal.Models.Serialization.Resolvers; /// /// Provides a mechanism for resolving serialization of . diff --git a/src/core/DSharpPlus.Core.Models/Skus/Sku.cs b/src/core/DSharpPlus.Internal.Models/Skus/Sku.cs similarity index 89% rename from src/core/DSharpPlus.Core.Models/Skus/Sku.cs rename to src/core/DSharpPlus.Internal.Models/Skus/Sku.cs index d4b8130e59..7f63453799 100644 --- a/src/core/DSharpPlus.Core.Models/Skus/Sku.cs +++ b/src/core/DSharpPlus.Internal.Models/Skus/Sku.cs @@ -2,10 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record Sku : ISku diff --git a/src/core/DSharpPlus.Core.Models/StageInstances/PartialStageInstance.cs b/src/core/DSharpPlus.Internal.Models/StageInstances/PartialStageInstance.cs similarity index 90% rename from src/core/DSharpPlus.Core.Models/StageInstances/PartialStageInstance.cs rename to src/core/DSharpPlus.Internal.Models/StageInstances/PartialStageInstance.cs index eb28293664..53ac4c288d 100644 --- a/src/core/DSharpPlus.Core.Models/StageInstances/PartialStageInstance.cs +++ b/src/core/DSharpPlus.Internal.Models/StageInstances/PartialStageInstance.cs @@ -2,10 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record PartialStageInstance : IPartialStageInstance diff --git a/src/core/DSharpPlus.Core.Models/StageInstances/StageInstance.cs b/src/core/DSharpPlus.Internal.Models/StageInstances/StageInstance.cs similarity index 90% rename from src/core/DSharpPlus.Core.Models/StageInstances/StageInstance.cs rename to src/core/DSharpPlus.Internal.Models/StageInstances/StageInstance.cs index db335f77bd..9948a3e151 100644 --- a/src/core/DSharpPlus.Core.Models/StageInstances/StageInstance.cs +++ b/src/core/DSharpPlus.Internal.Models/StageInstances/StageInstance.cs @@ -2,10 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record StageInstance : IStageInstance diff --git a/src/core/DSharpPlus.Core.Models/Stickers/PartialSticker.cs b/src/core/DSharpPlus.Internal.Models/Stickers/PartialSticker.cs similarity index 93% rename from src/core/DSharpPlus.Core.Models/Stickers/PartialSticker.cs rename to src/core/DSharpPlus.Internal.Models/Stickers/PartialSticker.cs index ed77dc1c6b..a336844216 100644 --- a/src/core/DSharpPlus.Core.Models/Stickers/PartialSticker.cs +++ b/src/core/DSharpPlus.Internal.Models/Stickers/PartialSticker.cs @@ -2,10 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record PartialSticker : IPartialSticker diff --git a/src/core/DSharpPlus.Core.Models/Stickers/Sticker.cs b/src/core/DSharpPlus.Internal.Models/Stickers/Sticker.cs similarity index 93% rename from src/core/DSharpPlus.Core.Models/Stickers/Sticker.cs rename to src/core/DSharpPlus.Internal.Models/Stickers/Sticker.cs index 034a80c2f5..7df13068e8 100644 --- a/src/core/DSharpPlus.Core.Models/Stickers/Sticker.cs +++ b/src/core/DSharpPlus.Internal.Models/Stickers/Sticker.cs @@ -2,10 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record Sticker : ISticker diff --git a/src/core/DSharpPlus.Core.Models/Stickers/StickerItem.cs b/src/core/DSharpPlus.Internal.Models/Stickers/StickerItem.cs similarity index 86% rename from src/core/DSharpPlus.Core.Models/Stickers/StickerItem.cs rename to src/core/DSharpPlus.Internal.Models/Stickers/StickerItem.cs index ebf3da77ed..d14c44d847 100644 --- a/src/core/DSharpPlus.Core.Models/Stickers/StickerItem.cs +++ b/src/core/DSharpPlus.Internal.Models/Stickers/StickerItem.cs @@ -2,10 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record StickerItem : IStickerItem diff --git a/src/core/DSharpPlus.Core.Models/Stickers/StickerPack.cs b/src/core/DSharpPlus.Internal.Models/Stickers/StickerPack.cs similarity index 91% rename from src/core/DSharpPlus.Core.Models/Stickers/StickerPack.cs rename to src/core/DSharpPlus.Internal.Models/Stickers/StickerPack.cs index 6bd3781051..27b2312f85 100644 --- a/src/core/DSharpPlus.Core.Models/Stickers/StickerPack.cs +++ b/src/core/DSharpPlus.Internal.Models/Stickers/StickerPack.cs @@ -4,9 +4,9 @@ using System.Collections.Generic; -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record StickerPack : IStickerPack diff --git a/src/core/DSharpPlus.Core.Models/Teams/Team.cs b/src/core/DSharpPlus.Internal.Models/Teams/Team.cs similarity index 88% rename from src/core/DSharpPlus.Core.Models/Teams/Team.cs rename to src/core/DSharpPlus.Internal.Models/Teams/Team.cs index cbc782d878..c231cc0ac4 100644 --- a/src/core/DSharpPlus.Core.Models/Teams/Team.cs +++ b/src/core/DSharpPlus.Internal.Models/Teams/Team.cs @@ -4,9 +4,9 @@ using System.Collections.Generic; -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record Team : ITeam diff --git a/src/core/DSharpPlus.Core.Models/Teams/TeamMember.cs b/src/core/DSharpPlus.Internal.Models/Teams/TeamMember.cs similarity index 89% rename from src/core/DSharpPlus.Core.Models/Teams/TeamMember.cs rename to src/core/DSharpPlus.Internal.Models/Teams/TeamMember.cs index 11282bd99d..64d6be01a2 100644 --- a/src/core/DSharpPlus.Core.Models/Teams/TeamMember.cs +++ b/src/core/DSharpPlus.Internal.Models/Teams/TeamMember.cs @@ -4,10 +4,10 @@ using System.Collections.Generic; -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record TeamMember : ITeamMember diff --git a/src/core/DSharpPlus.Core.Models/Users/ApplicationRoleConnection.cs b/src/core/DSharpPlus.Internal.Models/Users/ApplicationRoleConnection.cs similarity index 87% rename from src/core/DSharpPlus.Core.Models/Users/ApplicationRoleConnection.cs rename to src/core/DSharpPlus.Internal.Models/Users/ApplicationRoleConnection.cs index 8676778956..7e62e90c5d 100644 --- a/src/core/DSharpPlus.Core.Models/Users/ApplicationRoleConnection.cs +++ b/src/core/DSharpPlus.Internal.Models/Users/ApplicationRoleConnection.cs @@ -4,9 +4,9 @@ using System.Collections.Generic; -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record ApplicationRoleConnection : IApplicationRoleConnection diff --git a/src/core/DSharpPlus.Core.Models/Users/Connection.cs b/src/core/DSharpPlus.Internal.Models/Users/Connection.cs similarity index 93% rename from src/core/DSharpPlus.Core.Models/Users/Connection.cs rename to src/core/DSharpPlus.Internal.Models/Users/Connection.cs index e1205bed09..04c3285569 100644 --- a/src/core/DSharpPlus.Core.Models/Users/Connection.cs +++ b/src/core/DSharpPlus.Internal.Models/Users/Connection.cs @@ -4,10 +4,10 @@ using System.Collections.Generic; -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record Connection : IConnection diff --git a/src/core/DSharpPlus.Core.Models/Users/PartialUser.cs b/src/core/DSharpPlus.Internal.Models/Users/PartialUser.cs similarity index 95% rename from src/core/DSharpPlus.Core.Models/Users/PartialUser.cs rename to src/core/DSharpPlus.Internal.Models/Users/PartialUser.cs index 82ea15bfc9..0ed02231ec 100644 --- a/src/core/DSharpPlus.Core.Models/Users/PartialUser.cs +++ b/src/core/DSharpPlus.Internal.Models/Users/PartialUser.cs @@ -2,10 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record PartialUser : IPartialUser diff --git a/src/core/DSharpPlus.Core.Models/Users/User.cs b/src/core/DSharpPlus.Internal.Models/Users/User.cs similarity index 94% rename from src/core/DSharpPlus.Core.Models/Users/User.cs rename to src/core/DSharpPlus.Internal.Models/Users/User.cs index 77880b7692..8f06b1dbf9 100644 --- a/src/core/DSharpPlus.Core.Models/Users/User.cs +++ b/src/core/DSharpPlus.Internal.Models/Users/User.cs @@ -2,10 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record User : IUser diff --git a/src/core/DSharpPlus.Core.Models/Voice/VoiceRegion.cs b/src/core/DSharpPlus.Internal.Models/Voice/VoiceRegion.cs similarity index 88% rename from src/core/DSharpPlus.Core.Models/Voice/VoiceRegion.cs rename to src/core/DSharpPlus.Internal.Models/Voice/VoiceRegion.cs index 8bb2a41bc4..0d6d293abd 100644 --- a/src/core/DSharpPlus.Core.Models/Voice/VoiceRegion.cs +++ b/src/core/DSharpPlus.Internal.Models/Voice/VoiceRegion.cs @@ -2,9 +2,9 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record VoiceRegion : IVoiceRegion diff --git a/src/core/DSharpPlus.Core.Models/Voice/VoiceState.cs b/src/core/DSharpPlus.Internal.Models/Voice/VoiceState.cs similarity index 93% rename from src/core/DSharpPlus.Core.Models/Voice/VoiceState.cs rename to src/core/DSharpPlus.Internal.Models/Voice/VoiceState.cs index faf08fd406..fb15409fe7 100644 --- a/src/core/DSharpPlus.Core.Models/Voice/VoiceState.cs +++ b/src/core/DSharpPlus.Internal.Models/Voice/VoiceState.cs @@ -4,9 +4,9 @@ using System; -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record VoiceState : IVoiceState diff --git a/src/core/DSharpPlus.Core.Models/Webhooks/PartialWebhook.cs b/src/core/DSharpPlus.Internal.Models/Webhooks/PartialWebhook.cs similarity index 93% rename from src/core/DSharpPlus.Core.Models/Webhooks/PartialWebhook.cs rename to src/core/DSharpPlus.Internal.Models/Webhooks/PartialWebhook.cs index 2fd280354a..c30fcc772b 100644 --- a/src/core/DSharpPlus.Core.Models/Webhooks/PartialWebhook.cs +++ b/src/core/DSharpPlus.Internal.Models/Webhooks/PartialWebhook.cs @@ -2,10 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record PartialWebhook : IPartialWebhook diff --git a/src/core/DSharpPlus.Core.Models/Webhooks/Webhook.cs b/src/core/DSharpPlus.Internal.Models/Webhooks/Webhook.cs similarity index 93% rename from src/core/DSharpPlus.Core.Models/Webhooks/Webhook.cs rename to src/core/DSharpPlus.Internal.Models/Webhooks/Webhook.cs index 032332d354..b86d804dd6 100644 --- a/src/core/DSharpPlus.Core.Models/Webhooks/Webhook.cs +++ b/src/core/DSharpPlus.Internal.Models/Webhooks/Webhook.cs @@ -2,10 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Core.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; -namespace DSharpPlus.Core.Models; +namespace DSharpPlus.Internal.Models; /// public sealed record Webhook : IWebhook diff --git a/src/core/DSharpPlus.Core.Rest/DSharpPlus.Core.Rest.csproj b/src/core/DSharpPlus.Internal.Rest/DSharpPlus.Internal.Rest.csproj similarity index 55% rename from src/core/DSharpPlus.Core.Rest/DSharpPlus.Core.Rest.csproj rename to src/core/DSharpPlus.Internal.Rest/DSharpPlus.Internal.Rest.csproj index 3c46fcea0f..fc2b149010 100644 --- a/src/core/DSharpPlus.Core.Rest/DSharpPlus.Core.Rest.csproj +++ b/src/core/DSharpPlus.Internal.Rest/DSharpPlus.Internal.Rest.csproj @@ -1,7 +1,7 @@  - $(_DSharpPlusCoreRestVersion) + $(_DSharpPlusInternalRestVersion) diff --git a/tests/core/DSharpPlus.Core.Models.Tests/Converters/AuditLogChangeTests.cs b/tests/core/DSharpPlus.Internal.Models.Tests/Converters/AuditLogChangeTests.cs similarity index 95% rename from tests/core/DSharpPlus.Core.Models.Tests/Converters/AuditLogChangeTests.cs rename to tests/core/DSharpPlus.Internal.Models.Tests/Converters/AuditLogChangeTests.cs index a0e4151d3d..8790e460c9 100644 --- a/tests/core/DSharpPlus.Core.Models.Tests/Converters/AuditLogChangeTests.cs +++ b/tests/core/DSharpPlus.Internal.Models.Tests/Converters/AuditLogChangeTests.cs @@ -4,8 +4,8 @@ using System; -using DSharpPlus.Core.Abstractions.Models; -using DSharpPlus.Core.Models.Extensions; +using DSharpPlus.Internal.Abstractions.Models; +using DSharpPlus.Internal.Models.Extensions; using DSharpPlus.Serialization; using Microsoft.Extensions.DependencyInjection; @@ -14,7 +14,7 @@ using Xunit; -namespace DSharpPlus.Core.Models.Tests.Converters; +namespace DSharpPlus.Internal.Models.Tests.Converters; public class AuditLogChangeTests { diff --git a/tests/core/DSharpPlus.Core.Models.Tests/Converters/OneOfConverterTests.Models.cs b/tests/core/DSharpPlus.Internal.Models.Tests/Converters/OneOfConverterTests.Models.cs similarity index 94% rename from tests/core/DSharpPlus.Core.Models.Tests/Converters/OneOfConverterTests.Models.cs rename to tests/core/DSharpPlus.Internal.Models.Tests/Converters/OneOfConverterTests.Models.cs index 00bd008442..6858d923cc 100644 --- a/tests/core/DSharpPlus.Core.Models.Tests/Converters/OneOfConverterTests.Models.cs +++ b/tests/core/DSharpPlus.Internal.Models.Tests/Converters/OneOfConverterTests.Models.cs @@ -4,8 +4,8 @@ using System; -using DSharpPlus.Core.Abstractions.Models; -using DSharpPlus.Core.Models.Extensions; +using DSharpPlus.Internal.Abstractions.Models; +using DSharpPlus.Internal.Models.Extensions; using DSharpPlus.Serialization; using Microsoft.Extensions.DependencyInjection; @@ -14,7 +14,7 @@ using Xunit; -namespace DSharpPlus.Core.Models.Tests.Converters; +namespace DSharpPlus.Internal.Models.Tests.Converters; // tests one-of deserialization on example payloads for actual models partial class OneOfConverterTests diff --git a/tests/core/DSharpPlus.Core.Models.Tests/Converters/OneOfConverterTests.Precedence.cs b/tests/core/DSharpPlus.Internal.Models.Tests/Converters/OneOfConverterTests.Precedence.cs similarity index 95% rename from tests/core/DSharpPlus.Core.Models.Tests/Converters/OneOfConverterTests.Precedence.cs rename to tests/core/DSharpPlus.Internal.Models.Tests/Converters/OneOfConverterTests.Precedence.cs index 4b8b669e56..8f7e9f4f4b 100644 --- a/tests/core/DSharpPlus.Core.Models.Tests/Converters/OneOfConverterTests.Precedence.cs +++ b/tests/core/DSharpPlus.Internal.Models.Tests/Converters/OneOfConverterTests.Precedence.cs @@ -5,13 +5,13 @@ using System; using System.Text.Json; -using DSharpPlus.Core.Models.Serialization.Converters; +using DSharpPlus.Internal.Models.Serialization.Converters; using OneOf; using Xunit; -namespace DSharpPlus.Core.Models.Tests.Converters; +namespace DSharpPlus.Internal.Models.Tests.Converters; // here we test whether we handle precedence correctly, with intentionally annoying unions public partial class OneOfConverterTests diff --git a/tests/core/DSharpPlus.Core.Models.Tests/DSharpPlus.Core.Models.Tests.csproj b/tests/core/DSharpPlus.Internal.Models.Tests/DSharpPlus.Internal.Models.Tests.csproj similarity index 88% rename from tests/core/DSharpPlus.Core.Models.Tests/DSharpPlus.Core.Models.Tests.csproj rename to tests/core/DSharpPlus.Internal.Models.Tests/DSharpPlus.Internal.Models.Tests.csproj index a8393dce24..844c267c48 100644 --- a/tests/core/DSharpPlus.Core.Models.Tests/DSharpPlus.Core.Models.Tests.csproj +++ b/tests/core/DSharpPlus.Internal.Models.Tests/DSharpPlus.Internal.Models.Tests.csproj @@ -22,7 +22,7 @@ - + diff --git a/tools/generators/generate-concrete-objects.csx b/tools/generators/generate-concrete-objects.csx index 8c6dea4269..0fbf93653c 100644 --- a/tools/generators/generate-concrete-objects.csx +++ b/tools/generators/generate-concrete-objects.csx @@ -42,12 +42,12 @@ AnsiConsole.MarkupLine string input, output; // there are no args passed, proceed with default args: -// args[0] = src/core/DSharpPlus.Core.Abstractions.Models -// args[1] = src/core/DSharpPlus.Core.Models +// args[0] = src/core/DSharpPlus.Internal.Abstractions.Models +// args[1] = src/core/DSharpPlus.Internal.Models if (Args.Count == 0) { - input = "src/core/DSharpPlus.Core.Abstractions.Models"; - output = "src/core/DSharpPlus.Core.Models"; + input = "src/core/DSharpPlus.Internal.Abstractions.Models"; + output = "src/core/DSharpPlus.Internal.Models"; } // there are args passed, which override the given instructions @@ -201,9 +201,9 @@ for (int i = 0; i < collectedMetadata.Count; i++) // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. - using DSharpPlus.Core.Abstractions.Models; + using DSharpPlus.Internal.Abstractions.Models; - namespace DSharpPlus.Core.Models; + namespace DSharpPlus.Internal.Models; /// /// Placeholder implementation of a marker interface. Please report spotting this to library developers. @@ -233,7 +233,7 @@ for (int i = 0; i < collectedMetadata.Count; i++) // we're going to employ a hack and return "!" as the key if it's a system using, which is higher than any // legal namespace name IEnumerable> groupedUsings = metadata.UsingDirectives! - .Append("using DSharpPlus.Core.Abstractions.Models;") + .Append("using DSharpPlus.Internal.Abstractions.Models;") .Distinct() .GroupBy ( @@ -278,7 +278,7 @@ for (int i = 0; i < collectedMetadata.Count; i++) writer.AppendLine ( $$""" - namespace DSharpPlus.Core.Models; + namespace DSharpPlus.Internal.Models; /// public sealed record {{metadata.Name[1..]}} : {{metadata.Name}} From 88935da6d021f026da4e16b0b83602c20ba00949 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sun, 31 Dec 2023 15:58:13 +0100 Subject: [PATCH 240/323] expand ValidationError to optionally cover multiple parameters --- .../Errors/ValidationError.cs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Errors/ValidationError.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Errors/ValidationError.cs index c44bbbb328..2f96f66abd 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/Errors/ValidationError.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Errors/ValidationError.cs @@ -2,6 +2,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +using System.Collections.Generic; + using Remora.Results; namespace DSharpPlus.Internal.Abstractions.Rest.Errors; @@ -9,15 +11,19 @@ namespace DSharpPlus.Internal.Abstractions.Rest.Errors; /// /// Represents an error encountered during parameter validation. /// -public sealed record ValidationError : ResultError +public record ValidationError : ResultError { + /// + /// If this error was caused by any specific parameters, contains the names of the invalid parameters. + /// + public IReadOnlyList? ParameterNames { get; init; } + /// /// Initializes a new validation error. /// /// The human-readable error message. - public ValidationError(string message) - : base(message) - { - - } + /// If applicable, the names of parameters that failed validation. + public ValidationError(string message, params string[] parameters) + : base(message) + => this.ParameterNames = parameters.Length != 0 ? parameters : null; } From b22514035255471fb2d82e1dfa43461f235b25da Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Mon, 1 Jan 2024 18:38:29 +0100 Subject: [PATCH 241/323] add an embed builder --- DSharpPlus.sln | 9 + Directory.Build.props | 8 + dsharpplus.csx | 11 +- meta/builder-concrete-types.json | 3 + ...rpPlus.Extensions.Internal.Builders.csproj | 20 ++ .../Errors/BuilderValidationError.cs | 58 ++++ .../Implementations/BuiltEmbed.cs | 53 ++++ .../Messages/EmbedBuilder.cs | 264 ++++++++++++++++++ src/extensions/DSharpPlus.Extensions.sln | 22 ++ .../copy-concrete-implementations.csx | 150 ++++++++++ .../generators/generate-concrete-objects.csx | 2 +- 11 files changed, 597 insertions(+), 3 deletions(-) create mode 100644 meta/builder-concrete-types.json create mode 100644 src/extensions/DSharpPlus.Extensions.Internal.Builders/DSharpPlus.Extensions.Internal.Builders.csproj create mode 100644 src/extensions/DSharpPlus.Extensions.Internal.Builders/Errors/BuilderValidationError.cs create mode 100644 src/extensions/DSharpPlus.Extensions.Internal.Builders/Implementations/BuiltEmbed.cs create mode 100644 src/extensions/DSharpPlus.Extensions.Internal.Builders/Messages/EmbedBuilder.cs create mode 100644 src/extensions/DSharpPlus.Extensions.sln create mode 100644 tools/generators/copy-concrete-implementations.csx diff --git a/DSharpPlus.sln b/DSharpPlus.sln index 6e06391542..06591ada92 100644 --- a/DSharpPlus.sln +++ b/DSharpPlus.sln @@ -25,6 +25,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DSharpPlus.Internal.Abstrac EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DSharpPlus.Internal.Rest", "src\core\DSharpPlus.Internal.Rest\DSharpPlus.Internal.Rest.csproj", "{9CEC3D27-9014-48B6-910F-D25233BF8C44}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Extensions", "Extensions", "{96A3D7EF-3576-423C-9529-60C8AE319C15}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DSharpPlus.Extensions.Internal.Builders", "src\extensions\DSharpPlus.Extensions.Internal.Builders\DSharpPlus.Extensions.Internal.Builders.csproj", "{7A6F0CF2-2BB9-4AAC-95EC-8640A06DD17B}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -59,6 +63,10 @@ Global {9CEC3D27-9014-48B6-910F-D25233BF8C44}.Debug|Any CPU.Build.0 = Debug|Any CPU {9CEC3D27-9014-48B6-910F-D25233BF8C44}.Release|Any CPU.ActiveCfg = Release|Any CPU {9CEC3D27-9014-48B6-910F-D25233BF8C44}.Release|Any CPU.Build.0 = Release|Any CPU + {7A6F0CF2-2BB9-4AAC-95EC-8640A06DD17B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7A6F0CF2-2BB9-4AAC-95EC-8640A06DD17B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7A6F0CF2-2BB9-4AAC-95EC-8640A06DD17B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7A6F0CF2-2BB9-4AAC-95EC-8640A06DD17B}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -72,6 +80,7 @@ Global {9F25D892-3CB0-4D47-B67D-D3FFFADC03E0} = {21927A64-7345-4D90-9EE2-7FA4B1973AAC} {CD440954-E19A-4E94-A217-CCC1DC4AF095} = {BC8D8750-48A4-49EF-9D1F-BE4DBA5B500E} {9CEC3D27-9014-48B6-910F-D25233BF8C44} = {BC8D8750-48A4-49EF-9D1F-BE4DBA5B500E} + {7A6F0CF2-2BB9-4AAC-95EC-8640A06DD17B} = {96A3D7EF-3576-423C-9529-60C8AE319C15} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {55CDA684-8900-479B-9DAE-BA3BE09B337B} diff --git a/Directory.Build.props b/Directory.Build.props index 242b47ece3..6ddd84f233 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -4,6 +4,7 @@ net9.0 enable + disable preview True True @@ -33,6 +34,8 @@ + + <_DSharpPlusReleaseVersion>6.0.0 @@ -47,6 +50,11 @@ <_DSharpPlusInternalRestVersion>0.1.0 + + + + + <_DSharpPlusExtensionsInternalBuildersVersion>0.1.0 \ No newline at end of file diff --git a/dsharpplus.csx b/dsharpplus.csx index 17f6cb53af..0fd5573096 100644 --- a/dsharpplus.csx +++ b/dsharpplus.csx @@ -34,12 +34,19 @@ ToolMetadata[] tools = Name = "generate-concrete-objects", Subset = "core", Type = ToolType.Generator + }, + new() + { + Name = "copy-concrete-implementations", + Subset = "extensions", + Type = ToolType.Generator } }; string[] subsets = { - "core" + "core", + "extensions" }; // executes a given tool @@ -157,7 +164,7 @@ if (Args.Count >= 1 && Args[0] == "publish") if (Args[0] != "run") { - AnsiConsole.MarkupLine($"[red]The only supported top-level verbs are 'run' and 'publish', found {Args[0]}.[/]"); + AnsiConsole.MarkupLine($"[red]The only supported top-level verbs are 'clear', 'run' and 'publish', found {Args[0]}.[/]"); return 1; } diff --git a/meta/builder-concrete-types.json b/meta/builder-concrete-types.json new file mode 100644 index 0000000000..76e5177f1a --- /dev/null +++ b/meta/builder-concrete-types.json @@ -0,0 +1,3 @@ +[ + "./src/core/DSharpPlus.Internal.Models/Channels/Embed.cs" +] \ No newline at end of file diff --git a/src/extensions/DSharpPlus.Extensions.Internal.Builders/DSharpPlus.Extensions.Internal.Builders.csproj b/src/extensions/DSharpPlus.Extensions.Internal.Builders/DSharpPlus.Extensions.Internal.Builders.csproj new file mode 100644 index 0000000000..a5412d584b --- /dev/null +++ b/src/extensions/DSharpPlus.Extensions.Internal.Builders/DSharpPlus.Extensions.Internal.Builders.csproj @@ -0,0 +1,20 @@ + + + + $(_DSharpPlusExtensionsInternalBuildersVersion) + + $(Description) This package provides useful builder utilities for working directly with the internal models. + It is strictly bound to our concrete model implementation, and may be of limited use. + + Library + + + + + + + + + + + diff --git a/src/extensions/DSharpPlus.Extensions.Internal.Builders/Errors/BuilderValidationError.cs b/src/extensions/DSharpPlus.Extensions.Internal.Builders/Errors/BuilderValidationError.cs new file mode 100644 index 0000000000..d80f7b0d45 --- /dev/null +++ b/src/extensions/DSharpPlus.Extensions.Internal.Builders/Errors/BuilderValidationError.cs @@ -0,0 +1,58 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; + +using Remora.Results; + +namespace DSharpPlus.Extensions.Internal.Builders.Errors; + +/// +/// Represents an error encountered when attempting to validate a builder. +/// +public record BuilderValidationError : ResultError +{ + /// + /// If this error was caused by any specific parameters, contains the names of the invalid parameters. + /// + public IReadOnlyDictionary? ParameterNames { get; init; } + + /// + /// Initializes a new validation error. + /// + /// The human-readable error message. + /// If applicable, the names of parameters that failed validation. + public BuilderValidationError(string message, params (string Key, string Value)[] parameters) + : base(message) + { + if (parameters.Length == 0) + { + return; + } + + this.ParameterNames = parameters.ToDictionary(x => x.Key, x => x.Value); + } + + public override string ToString() + { + if (this.ParameterNames is null) + { + return base.ToString(); + } + + StringBuilder builder = new($"BuilderValidationError\n{{\n\t{this.Message},\n\tParameters:\n\t["); + + foreach (KeyValuePair kvp in this.ParameterNames) + { + builder.Append(CultureInfo.InvariantCulture, $"\n\t\t{kvp.Key}: {kvp.Value}"); + } + + builder.Append("\n\t]\n}"); + + return builder.ToString(); + } +} \ No newline at end of file diff --git a/src/extensions/DSharpPlus.Extensions.Internal.Builders/Implementations/BuiltEmbed.cs b/src/extensions/DSharpPlus.Extensions.Internal.Builders/Implementations/BuiltEmbed.cs new file mode 100644 index 0000000000..54c6e242d7 --- /dev/null +++ b/src/extensions/DSharpPlus.Extensions.Internal.Builders/Implementations/BuiltEmbed.cs @@ -0,0 +1,53 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; +using System.Collections.Generic; + +using DSharpPlus.Internal.Abstractions.Models; + +namespace DSharpPlus.Extensions.Internal.Builders.Implementations; + +/// +internal sealed record BuiltEmbed : IEmbed +{ + /// + public Optional Title { get; init; } + + /// + public Optional Type { get; init; } + + /// + public Optional Description { get; init; } + + /// + public Optional Url { get; init; } + + /// + public Optional Timestamp { get; init; } + + /// + public Optional Color { get; init; } + + /// + public Optional Footer { get; init; } + + /// + public Optional Image { get; init; } + + /// + public Optional Thumbnail { get; init; } + + /// + public Optional Video { get; init; } + + /// + public Optional Provider { get; init; } + + /// + public Optional Author { get; init; } + + /// + public Optional> Fields { get; init; } +} \ No newline at end of file diff --git a/src/extensions/DSharpPlus.Extensions.Internal.Builders/Messages/EmbedBuilder.cs b/src/extensions/DSharpPlus.Extensions.Internal.Builders/Messages/EmbedBuilder.cs new file mode 100644 index 0000000000..af746b6cca --- /dev/null +++ b/src/extensions/DSharpPlus.Extensions.Internal.Builders/Messages/EmbedBuilder.cs @@ -0,0 +1,264 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +#pragma warning disable IDE0046 + +using System; +using System.Collections.Generic; + +using DSharpPlus.Extensions.Internal.Builders.Errors; +using DSharpPlus.Extensions.Internal.Builders.Implementations; +using DSharpPlus.Internal.Abstractions.Models; + +using Remora.Results; + +namespace DSharpPlus.Extensions.Internal.Builders.Messages; + +/// +/// Represents an currently under construction. +/// +public record struct EmbedBuilder +{ + /// + public Optional Title { get; set; } + + /// + public Optional Description { get; set; } + + /// + public Optional Color { get; set; } + + /// + public Optional Url { get; set; } + + /// + public Optional Timestamp { get; set; } + + /// + public Optional Footer { get; set; } + + /// + public Optional Author { get; set; } + + /// + public Optional> Fields { get; set; } +} + +public static class EmbedBuilderExtensions +{ + /// + /// Sets the title of the embed to the specified string. + /// + /// The embed builder for chaining. + public static ref EmbedBuilder WithTitle(ref this EmbedBuilder builder, string title) + { + builder.Title = title; + return ref builder; + } + + /// + /// Sets the description of the embed to the specified string. + /// + /// The embed builder for chaining. + public static ref EmbedBuilder WithDescription(ref this EmbedBuilder builder, string description) + { + builder.Description = description; + return ref builder; + } + + /// + /// Sets the sidebar color of the embed to the specified color code. + /// + /// The embed builder for chaining. + public static ref EmbedBuilder WithColor(ref this EmbedBuilder builder, int color) + { + builder.Color = color; + return ref builder; + } + + /// + /// Sets the url of the embed to the specified link. + /// + /// The embed builder for chaining. + public static ref EmbedBuilder WithUrl(ref this EmbedBuilder builder, string url) + { + builder.Url = url; + return ref builder; + } + + /// + /// Sets the url of the embed to the specified link. + /// + /// The embed builder for chaining. + public static ref EmbedBuilder WithUrl(ref this EmbedBuilder builder, Uri url) + { + builder.Url = url.AbsoluteUri; + return ref builder; + } + + /// + /// Sets the timestamp of the embed to the specified value. + /// + /// The embed builder for chaining. + public static ref EmbedBuilder WithTimestamp(ref this EmbedBuilder builder, DateTimeOffset timestamp) + { + builder.Timestamp = timestamp; + return ref builder; + } + + /// + /// Sets the footer of the embed to the specified value. + /// + /// The embed builder for chaining. + public static ref EmbedBuilder WithFooter(ref this EmbedBuilder builder, IEmbedFooter footer) + { + builder.Footer = new(footer); + return ref builder; + } + + /// + /// Sets the author of the embed to the specified value. + /// + /// The embed builder for chaining. + public static ref EmbedBuilder WithAuthor(ref this EmbedBuilder builder, IEmbedAuthor author) + { + builder.Author = new(author); + return ref builder; + } + + /// + /// Adds a field to the embed builder. + /// + /// The embed builder for chaining. + public static ref EmbedBuilder AddField(ref this EmbedBuilder builder, IEmbedField field) + { + builder.Fields = builder.Fields.MapOr>> + ( + transformation: fields => new([..fields, field]), + value: new([field]) + ); + + return ref builder; + } + + /// + /// Verifies whether the embed builder can be transformed into a valid embed. + /// + public static Result Validate(ref this EmbedBuilder builder) + { + int totalCount = 0; + List<(string, string)> errors = []; + + if (builder.Title.TryGetNonNullValue(out string? title)) + { + if (title.Length > 256) + { + errors.Add((nameof(EmbedBuilder.Title), "The length of the title cannot exceed 256 characters.")); + } + + totalCount += title.Length; + } + + if (builder.Description.TryGetNonNullValue(out string? desc)) + { + if (desc.Length > 256) + { + errors.Add((nameof(EmbedBuilder.Description), "The length of the description cannot exceed 4096 characters.")); + } + + totalCount += desc.Length; + } + + if (builder.Color.TryGetNonNullValue(out int color)) + { + if (color < 0x000000 || color > 0xFFFFFF) + { + errors.Add((nameof(EmbedBuilder.Color), "The color code must be between 0x000000 and 0xFFFFFF.")); + } + } + + if (builder.Footer.TryGetNonNullValue(out IEmbedFooter? footer)) + { + if (footer.Text.Length > 2048) + { + errors.Add((nameof(EmbedBuilder.Footer), "The length of the footer text cannot exceed 2048 characters.")); + } + + totalCount += footer.Text.Length; + } + + if (builder.Author.TryGetNonNullValue(out IEmbedAuthor? author)) + { + if (author.Name.Length > 256) + { + errors.Add((nameof(EmbedBuilder.Author), "The length of the author name cannot exceed 256 characters.")); + } + + totalCount += author.Name.Length; + } + + if (builder.Fields.TryGetNonNullValue(out IReadOnlyList? fields)) + { + if (fields.Count > 25) + { + errors.Add((nameof(EmbedBuilder.Fields), "There cannot be more than 25 fields in an embed.")); + } + + for (int i = 0; i < 25; i++) + { + if (fields[i].Name.Length > 256) + { + errors.Add(($"Fields[{i}]", "The title of a field cannot exceed 256 characters.")); + } + + if (fields[i].Value.Length > 1024) + { + errors.Add(($"Fields[{i}]", "The length of a field value cannot exceed 1024 characters.")); + } + + totalCount += fields[i].Name.Length + fields[i].Value.Length; + } + } + + if (totalCount > 6000 && errors is not []) + { + return new BuilderValidationError + ( + "The total length of the embed exceeded 6000 characters, and some embed fields were invalid.", + errors.ToArray() + ); + } + else if (totalCount > 6000) + { + return new BuilderValidationError("The total length of the embed cannot exceed 6000 characters."); + } + else if (errors is not []) + { + return new BuilderValidationError + ( + "Some embed fields were invalid. See the attached dictionary for further information.", + errors.ToArray() + ); + } + else + { + return Result.Success; + } + } + + public static IEmbed Build(ref this EmbedBuilder builder) + { + return new BuiltEmbed + { + Title = builder.Title, + Description = builder.Description, + Color = builder.Color, + Url = builder.Url, + Timestamp = builder.Timestamp, + Footer = builder.Footer, + Author = builder.Author, + Fields = builder.Fields + }; + } +} \ No newline at end of file diff --git a/src/extensions/DSharpPlus.Extensions.sln b/src/extensions/DSharpPlus.Extensions.sln new file mode 100644 index 0000000000..aa0e1dfffb --- /dev/null +++ b/src/extensions/DSharpPlus.Extensions.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.0.31903.59 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DSharpPlus.Extensions.Internal.Builders", "DSharpPlus.Extensions.Internal.Builders\DSharpPlus.Extensions.Internal.Builders.csproj", "{6278DA69-38C9-4A8A-9ACA-DFA9E2A9E65A}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {6278DA69-38C9-4A8A-9ACA-DFA9E2A9E65A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6278DA69-38C9-4A8A-9ACA-DFA9E2A9E65A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6278DA69-38C9-4A8A-9ACA-DFA9E2A9E65A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6278DA69-38C9-4A8A-9ACA-DFA9E2A9E65A}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/tools/generators/copy-concrete-implementations.csx b/tools/generators/copy-concrete-implementations.csx new file mode 100644 index 0000000000..9fe691174d --- /dev/null +++ b/tools/generators/copy-concrete-implementations.csx @@ -0,0 +1,150 @@ +#!/usr/bin/env dotnet-script + +#nullable enable + +#r "nuget:Spectre.Console, 0.47.1-preview.0.26" + +#load "../incremental-utility.csx" + +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text.Json; + +using Spectre.Console; + +// Syntax: +// copy-concrete-implementations [path to meta file] +if (Args is ["-h" or "--help" or "-?"]) +{ + AnsiConsole.MarkupLine + ( + """ + [plum1]DSharpPlus Concrete Implementation Theft, v0.1.0[/] + + Usage: copy-concrete-implementations.csx [path to meta file]] + Extracts the required concrete types for DSharpPlus.Extensions.Internal.Builders to remove dependency on concrete implementations. + + """ + ); + + return 0; +} + +AnsiConsole.MarkupLine +( + """ + [plum1]DSharpPlus Concrete Implementation Theft, v0.1.0[/] + + Extracts the required concrete types for DSharpPlus.Extensions.Internal.Builders to remove dependency on concrete implementations. + + """ +); + +string meta; +string basePath = "./src/extensions/DSharpPlus.Extensions.Internal.Builders/Implementations/"; + +if (Args.Count == 0) +{ + meta = "./meta/builder-concrete-types.json"; +} + +// there are args passed, which override the given instructions +// validate the passed arguments are correct +else if (Args.Any(path => !Directory.Exists(path))) +{ + AnsiConsole.MarkupLine + ( + """ + [red]The provided path could not be found on the file system.[/] + """ + ); + + return 1; +} + +// all args are fine +else +{ + meta = Args[0]; +} + +string[] files = JsonSerializer.Deserialize(File.ReadAllText(meta))!; + +Changes changes = GetFileChanges("copy-concrete-implementations", files); + +if (!changes.Added.Any() && !changes.Modified.Any() && !changes.Removed.Any()) +{ + AnsiConsole.MarkupLine + ( + """ + [darkseagreen1_1]There were no changes to the interface definitions, exiting generate-concrete-objects.[/] + """ + ); + + return 0; +} + +if (changes.Removed.Any()) +{ + AnsiConsole.MarkupLine + ( + """ + [red]Some concrete types were deleted. Please update the meta file and the corresponding builder code, if applicable: + """ + ); + + foreach (string removed in changes.Removed) + { + Console.WriteLine($" {removed}"); + } + + return 1; +} + +if (changes.Added.Any() || changes.Modified.Any()) +{ + AnsiConsole.MarkupLine("Extracting added and modified objects..."); +} + +IEnumerable toExtract = changes.Added.Concat(changes.Modified); + +bool success = toExtract.AsParallel() + .All + ( + path => + { + Console.WriteLine($" Extracting {path}"); + + try + { + string text = File.ReadAllText(path); + + int typeIndex = text.IndexOf("record"); + + text = text.Insert(typeIndex + 7, "Built"); + + int namespaceIndex = text.IndexOf("namespace"); + int endOfNamespaceLine = text.IndexOf('\n', namespaceIndex); + + text = text.Remove(namespaceIndex, endOfNamespaceLine - namespaceIndex); + text = text.Insert(namespaceIndex, "namespace DSharpPlus.Extensions.Internal.Builders.Implementations;"); + + text = text.Replace("public sealed record", "internal sealed record"); + + string filename = path.Split('/').Last(); + string outPath = basePath + "Built" + filename; + + File.WriteAllText(outPath, text); + } + catch (Exception e) + { + Console.WriteLine($"{e}: {e.Message}\n{e.StackTrace}"); + return false; + } + + return true; + } + ); + +return success ? 0 : 1; \ No newline at end of file diff --git a/tools/generators/generate-concrete-objects.csx b/tools/generators/generate-concrete-objects.csx index 0fbf93653c..6813c42981 100644 --- a/tools/generators/generate-concrete-objects.csx +++ b/tools/generators/generate-concrete-objects.csx @@ -35,7 +35,7 @@ if (Args is ["-h" or "--help" or "-?"]) AnsiConsole.MarkupLine ( """ - [plum1]DSharpPlus Concrete API Object Generator, v0.1.0[/] + [plum1]DSharpPlus Concrete API Object Generator, v0.2.0[/] """ ); From a16197f9d70c3911a3f3a51fc8c3aafeeeb0f045 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Mon, 1 Jan 2024 18:40:37 +0100 Subject: [PATCH 242/323] remove wrong note from the description --- .../DSharpPlus.Extensions.Internal.Builders.csproj | 1 - 1 file changed, 1 deletion(-) diff --git a/src/extensions/DSharpPlus.Extensions.Internal.Builders/DSharpPlus.Extensions.Internal.Builders.csproj b/src/extensions/DSharpPlus.Extensions.Internal.Builders/DSharpPlus.Extensions.Internal.Builders.csproj index a5412d584b..5fffcb91a7 100644 --- a/src/extensions/DSharpPlus.Extensions.Internal.Builders/DSharpPlus.Extensions.Internal.Builders.csproj +++ b/src/extensions/DSharpPlus.Extensions.Internal.Builders/DSharpPlus.Extensions.Internal.Builders.csproj @@ -4,7 +4,6 @@ $(_DSharpPlusExtensionsInternalBuildersVersion) $(Description) This package provides useful builder utilities for working directly with the internal models. - It is strictly bound to our concrete model implementation, and may be of limited use. Library From 535e8017a6f28c2d98c168b1972b0aff7ee02c2a Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Mon, 1 Jan 2024 18:50:48 +0100 Subject: [PATCH 243/323] adapt the generator for rest payloads --- dsharpplus.csx | 6 + .../ApplicationCommands/ApplicationCommand.cs | 2 +- .../ApplicationCommandOption.cs | 2 +- .../ApplicationCommandPermission.cs | 2 +- .../Applications/Application.cs | 2 +- .../Applications/InstallParameters.cs | 2 +- .../Applications/PartialApplication.cs | 2 +- .../AuditLogs/AuditLogEntry.cs | 2 +- .../AutoModeration/AutoModerationAction.cs | 2 +- .../AutoModeration/AutoModerationRule.cs | 2 +- .../AutoModerationTriggerMetadata.cs | 2 +- .../BlockMessageActionMetadata.cs | 2 +- .../PartialAutoModerationRule.cs | 2 +- .../SendAlertMessageActionMetadata.cs | 2 +- .../AutoModeration/TimeoutActionMetadata.cs | 2 +- .../Channels/Attachment.cs | 2 +- .../Channels/Channel.cs | 2 +- .../Channels/ChannelMention.cs | 2 +- .../Channels/ChannelOverwrite.cs | 2 +- .../Channels/Message.cs | 2 +- .../Channels/MessageActivity.cs | 2 +- .../Channels/PartialAttachment.cs | 2 +- .../Channels/PartialChannel.cs | 2 +- .../Channels/PartialChannelOverwrite.cs | 2 +- .../Channels/PartialMessage.cs | 2 +- .../Entitlements/Entitlement.cs | 2 +- .../Entitlements/PartialEntitlement.cs | 2 +- .../Guilds/Guild.cs | 2 +- .../Guilds/GuildMember.cs | 2 +- .../Guilds/Integration.cs | 2 +- .../Guilds/Onboarding.cs | 2 +- .../Guilds/OnboardingPrompt.cs | 2 +- .../Guilds/PartialGuild.cs | 2 +- .../Guilds/PartialGuildMember.cs | 2 +- .../Guilds/PartialIntegration.cs | 2 +- .../Guilds/PartialRole.cs | 2 +- .../DSharpPlus.Internal.Models/Guilds/Role.cs | 2 +- .../ApplicationCommandInteractionData.cs | 2 +- ...ApplicationCommandInteractionDataOption.cs | 2 +- .../Interactions/Interaction.cs | 2 +- .../Interactions/InteractionResponse.cs | 2 +- .../Interactions/MessageCallbackData.cs | 2 +- .../MessageComponentInteractionData.cs | 2 +- .../Interactions/MessageInteraction.cs | 2 +- .../Invites/Invite.cs | 2 +- .../Invites/PartialInvite.cs | 2 +- .../MessageComponents/ActionRowComponent.cs | 2 +- .../MessageComponents/ButtonComponent.cs | 2 +- .../ChannelSelectComponent.cs | 2 +- .../MentionableSelectComponent.cs | 2 +- .../MessageComponents/RoleSelectComponent.cs | 2 +- .../StringSelectComponent.cs | 2 +- .../MessageComponents/TextInputComponent.cs | 2 +- .../MessageComponents/UserSelectComponent.cs | 2 +- .../RoleConnections/RoleConnectionMetadata.cs | 2 +- .../ScheduledEvents/PartialScheduledEvent.cs | 2 +- .../ScheduledEvents/ScheduledEvent.cs | 2 +- .../DSharpPlus.Internal.Models/Skus/Sku.cs | 2 +- .../StageInstances/PartialStageInstance.cs | 2 +- .../StageInstances/StageInstance.cs | 2 +- .../Stickers/PartialSticker.cs | 2 +- .../Stickers/Sticker.cs | 2 +- .../Stickers/StickerItem.cs | 2 +- .../Teams/TeamMember.cs | 2 +- .../Users/Connection.cs | 2 +- .../Users/PartialUser.cs | 2 +- .../DSharpPlus.Internal.Models/Users/User.cs | 2 +- .../Webhooks/PartialWebhook.cs | 2 +- .../Webhooks/Webhook.cs | 2 +- .../DSharpPlus.Internal.Rest.csproj | 4 + .../CreateGlobalApplicationCommandPayload.cs | 38 +++ .../CreateGuildApplicationCommandPayload.cs | 35 +++ .../EditGlobalApplicationCommandPayload.cs | 38 +++ .../EditGuildApplicationCommandPayload.cs | 35 +++ .../EditCurrentApplicationPayload.cs | 42 +++ .../CreateAutoModerationRulePayload.cs | 39 +++ .../ModifyAutoModerationRulePayload.cs | 36 +++ .../Channels/CreateChannelInvitePayload.cs | 33 +++ .../Payloads/Channels/CreateMessagePayload.cs | 48 +++ .../Channels/EditChannelPermissionsPayload.cs | 21 ++ .../Payloads/Channels/EditMessagePayload.cs | 36 +++ .../FollowAnnouncementChannelPayload.cs | 14 + .../Channels/ForumAndMediaThreadMessage.cs | 36 +++ .../Channels/GroupDMAddRecipientPayload.cs | 17 ++ .../Payloads/Channels/ModifyGroupDMPayload.cs | 17 ++ .../Channels/ModifyGuildChannelPayload.cs | 72 +++++ .../Channels/ModifyThreadChannelPayload.cs | 38 +++ .../Channels/StartThreadFromMessagePayload.cs | 20 ++ ...StartThreadInForumOrMediaChannelPayload.cs | 31 ++ .../StartThreadWithoutMessagePayload.cs | 27 ++ .../Emojis/CreateGuildEmojiPayload.cs | 22 ++ .../Emojis/ModifyGuildEmojiPayload.cs | 19 ++ .../CreateTestEntitlementPayload.cs | 21 ++ .../CreateGuildFromGuildTemplatePayload.cs | 17 ++ .../CreateGuildTemplatePayload.cs | 17 ++ .../ModifyGuildTemplatePayload.cs | 17 ++ .../Payloads/Guilds/AddGuildMemberPayload.cs | 28 ++ .../Guilds/CreateGuildChannelPayload.cs | 69 +++++ .../Payloads/Guilds/CreateGuildPayload.cs | 48 +++ .../Payloads/Guilds/CreateGuildRolePayload.cs | 33 +++ .../Guilds/ModifyCurrentMemberPayload.cs | 14 + .../ModifyCurrentUserVoiceStatePayload.cs | 22 ++ .../ModifyGuildChannelPositionsPayload.cs | 23 ++ .../Guilds/ModifyGuildMemberPayload.cs | 32 ++ .../Guilds/ModifyGuildMfaLevelPayload.cs | 15 + .../Guilds/ModifyGuildOnboardingPayload.cs | 27 ++ .../Payloads/Guilds/ModifyGuildPayload.cs | 74 +++++ .../Payloads/Guilds/ModifyGuildRolePayload.cs | 33 +++ .../Guilds/ModifyGuildRolePositionsPayload.cs | 17 ++ .../Guilds/ModifyGuildWelcomeScreenPayload.cs | 23 ++ .../Guilds/ModifyUserVoiceStatePayload.cs | 17 ++ .../CreateFollowupMessagePayload.cs | 39 +++ .../EditFollowupMessagePayload.cs | 32 ++ .../EditInteractionResponsePayload.cs | 32 ++ .../CreateGuildScheduledEventPayload.cs | 42 +++ .../ModifyGuildScheduledEventPayload.cs | 45 +++ .../CreateStageInstancePayload.cs | 27 ++ .../ModifyStageInstancePayload.cs | 18 ++ .../Stickers/CreateGuildStickerPayload.cs | 23 ++ .../Stickers/ModifyGuildStickerPayload.cs | 20 ++ .../Payloads/Users/CreateDmPayload.cs | 14 + .../Payloads/Users/CreateGroupDmPayload.cs | 19 ++ .../Users/ModifyCurrentUserPayload.cs | 17 ++ ...entUserApplicationRoleConnectionPayload.cs | 20 ++ .../Payloads/Webhooks/CreateWebhookPayload.cs | 17 ++ .../Webhooks/EditWebhookMessagePayload.cs | 32 ++ .../Webhooks/ExecuteWebhookPayload.cs | 51 ++++ .../Payloads/Webhooks/ModifyWebhookPayload.cs | 20 ++ .../Webhooks/ModifyWebhookWithTokenPayload.cs | 17 ++ tools/generators/generate-rest-payloads.csx | 276 ++++++++++++++++++ 130 files changed, 2100 insertions(+), 68 deletions(-) create mode 100644 src/core/DSharpPlus.Internal.Rest/Payloads/ApplicationCommands/CreateGlobalApplicationCommandPayload.cs create mode 100644 src/core/DSharpPlus.Internal.Rest/Payloads/ApplicationCommands/CreateGuildApplicationCommandPayload.cs create mode 100644 src/core/DSharpPlus.Internal.Rest/Payloads/ApplicationCommands/EditGlobalApplicationCommandPayload.cs create mode 100644 src/core/DSharpPlus.Internal.Rest/Payloads/ApplicationCommands/EditGuildApplicationCommandPayload.cs create mode 100644 src/core/DSharpPlus.Internal.Rest/Payloads/Applications/EditCurrentApplicationPayload.cs create mode 100644 src/core/DSharpPlus.Internal.Rest/Payloads/AutoModeration/CreateAutoModerationRulePayload.cs create mode 100644 src/core/DSharpPlus.Internal.Rest/Payloads/AutoModeration/ModifyAutoModerationRulePayload.cs create mode 100644 src/core/DSharpPlus.Internal.Rest/Payloads/Channels/CreateChannelInvitePayload.cs create mode 100644 src/core/DSharpPlus.Internal.Rest/Payloads/Channels/CreateMessagePayload.cs create mode 100644 src/core/DSharpPlus.Internal.Rest/Payloads/Channels/EditChannelPermissionsPayload.cs create mode 100644 src/core/DSharpPlus.Internal.Rest/Payloads/Channels/EditMessagePayload.cs create mode 100644 src/core/DSharpPlus.Internal.Rest/Payloads/Channels/FollowAnnouncementChannelPayload.cs create mode 100644 src/core/DSharpPlus.Internal.Rest/Payloads/Channels/ForumAndMediaThreadMessage.cs create mode 100644 src/core/DSharpPlus.Internal.Rest/Payloads/Channels/GroupDMAddRecipientPayload.cs create mode 100644 src/core/DSharpPlus.Internal.Rest/Payloads/Channels/ModifyGroupDMPayload.cs create mode 100644 src/core/DSharpPlus.Internal.Rest/Payloads/Channels/ModifyGuildChannelPayload.cs create mode 100644 src/core/DSharpPlus.Internal.Rest/Payloads/Channels/ModifyThreadChannelPayload.cs create mode 100644 src/core/DSharpPlus.Internal.Rest/Payloads/Channels/StartThreadFromMessagePayload.cs create mode 100644 src/core/DSharpPlus.Internal.Rest/Payloads/Channels/StartThreadInForumOrMediaChannelPayload.cs create mode 100644 src/core/DSharpPlus.Internal.Rest/Payloads/Channels/StartThreadWithoutMessagePayload.cs create mode 100644 src/core/DSharpPlus.Internal.Rest/Payloads/Emojis/CreateGuildEmojiPayload.cs create mode 100644 src/core/DSharpPlus.Internal.Rest/Payloads/Emojis/ModifyGuildEmojiPayload.cs create mode 100644 src/core/DSharpPlus.Internal.Rest/Payloads/Entitlements/CreateTestEntitlementPayload.cs create mode 100644 src/core/DSharpPlus.Internal.Rest/Payloads/GuildTemplates/CreateGuildFromGuildTemplatePayload.cs create mode 100644 src/core/DSharpPlus.Internal.Rest/Payloads/GuildTemplates/CreateGuildTemplatePayload.cs create mode 100644 src/core/DSharpPlus.Internal.Rest/Payloads/GuildTemplates/ModifyGuildTemplatePayload.cs create mode 100644 src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/AddGuildMemberPayload.cs create mode 100644 src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/CreateGuildChannelPayload.cs create mode 100644 src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/CreateGuildPayload.cs create mode 100644 src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/CreateGuildRolePayload.cs create mode 100644 src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyCurrentMemberPayload.cs create mode 100644 src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyCurrentUserVoiceStatePayload.cs create mode 100644 src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyGuildChannelPositionsPayload.cs create mode 100644 src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyGuildMemberPayload.cs create mode 100644 src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyGuildMfaLevelPayload.cs create mode 100644 src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyGuildOnboardingPayload.cs create mode 100644 src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyGuildPayload.cs create mode 100644 src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyGuildRolePayload.cs create mode 100644 src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyGuildRolePositionsPayload.cs create mode 100644 src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyGuildWelcomeScreenPayload.cs create mode 100644 src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyUserVoiceStatePayload.cs create mode 100644 src/core/DSharpPlus.Internal.Rest/Payloads/Interactions/CreateFollowupMessagePayload.cs create mode 100644 src/core/DSharpPlus.Internal.Rest/Payloads/Interactions/EditFollowupMessagePayload.cs create mode 100644 src/core/DSharpPlus.Internal.Rest/Payloads/Interactions/EditInteractionResponsePayload.cs create mode 100644 src/core/DSharpPlus.Internal.Rest/Payloads/ScheduledEvents/CreateGuildScheduledEventPayload.cs create mode 100644 src/core/DSharpPlus.Internal.Rest/Payloads/ScheduledEvents/ModifyGuildScheduledEventPayload.cs create mode 100644 src/core/DSharpPlus.Internal.Rest/Payloads/StageInstances/CreateStageInstancePayload.cs create mode 100644 src/core/DSharpPlus.Internal.Rest/Payloads/StageInstances/ModifyStageInstancePayload.cs create mode 100644 src/core/DSharpPlus.Internal.Rest/Payloads/Stickers/CreateGuildStickerPayload.cs create mode 100644 src/core/DSharpPlus.Internal.Rest/Payloads/Stickers/ModifyGuildStickerPayload.cs create mode 100644 src/core/DSharpPlus.Internal.Rest/Payloads/Users/CreateDmPayload.cs create mode 100644 src/core/DSharpPlus.Internal.Rest/Payloads/Users/CreateGroupDmPayload.cs create mode 100644 src/core/DSharpPlus.Internal.Rest/Payloads/Users/ModifyCurrentUserPayload.cs create mode 100644 src/core/DSharpPlus.Internal.Rest/Payloads/Users/UpdateCurrentUserApplicationRoleConnectionPayload.cs create mode 100644 src/core/DSharpPlus.Internal.Rest/Payloads/Webhooks/CreateWebhookPayload.cs create mode 100644 src/core/DSharpPlus.Internal.Rest/Payloads/Webhooks/EditWebhookMessagePayload.cs create mode 100644 src/core/DSharpPlus.Internal.Rest/Payloads/Webhooks/ExecuteWebhookPayload.cs create mode 100644 src/core/DSharpPlus.Internal.Rest/Payloads/Webhooks/ModifyWebhookPayload.cs create mode 100644 src/core/DSharpPlus.Internal.Rest/Payloads/Webhooks/ModifyWebhookWithTokenPayload.cs create mode 100644 tools/generators/generate-rest-payloads.csx diff --git a/dsharpplus.csx b/dsharpplus.csx index 0fd5573096..efa14d5691 100644 --- a/dsharpplus.csx +++ b/dsharpplus.csx @@ -36,6 +36,12 @@ ToolMetadata[] tools = Type = ToolType.Generator }, new() + { + Name = "generate-rest-payloads", + Subset = "core", + Type = ToolType.Generator + }, + new() { Name = "copy-concrete-implementations", Subset = "extensions", diff --git a/src/core/DSharpPlus.Internal.Models/ApplicationCommands/ApplicationCommand.cs b/src/core/DSharpPlus.Internal.Models/ApplicationCommands/ApplicationCommand.cs index 2106dbd729..0a75dbdd02 100644 --- a/src/core/DSharpPlus.Internal.Models/ApplicationCommands/ApplicationCommand.cs +++ b/src/core/DSharpPlus.Internal.Models/ApplicationCommands/ApplicationCommand.cs @@ -4,8 +4,8 @@ using System.Collections.Generic; -using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; namespace DSharpPlus.Internal.Models; diff --git a/src/core/DSharpPlus.Internal.Models/ApplicationCommands/ApplicationCommandOption.cs b/src/core/DSharpPlus.Internal.Models/ApplicationCommands/ApplicationCommandOption.cs index 690fd287e6..bff9107100 100644 --- a/src/core/DSharpPlus.Internal.Models/ApplicationCommands/ApplicationCommandOption.cs +++ b/src/core/DSharpPlus.Internal.Models/ApplicationCommands/ApplicationCommandOption.cs @@ -4,8 +4,8 @@ using System.Collections.Generic; -using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; using OneOf; diff --git a/src/core/DSharpPlus.Internal.Models/ApplicationCommands/ApplicationCommandPermission.cs b/src/core/DSharpPlus.Internal.Models/ApplicationCommands/ApplicationCommandPermission.cs index 8b5a1b79af..9cf1645161 100644 --- a/src/core/DSharpPlus.Internal.Models/ApplicationCommands/ApplicationCommandPermission.cs +++ b/src/core/DSharpPlus.Internal.Models/ApplicationCommands/ApplicationCommandPermission.cs @@ -2,8 +2,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; namespace DSharpPlus.Internal.Models; diff --git a/src/core/DSharpPlus.Internal.Models/Applications/Application.cs b/src/core/DSharpPlus.Internal.Models/Applications/Application.cs index 27b410c451..6f3b74d0c0 100644 --- a/src/core/DSharpPlus.Internal.Models/Applications/Application.cs +++ b/src/core/DSharpPlus.Internal.Models/Applications/Application.cs @@ -4,8 +4,8 @@ using System.Collections.Generic; -using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; namespace DSharpPlus.Internal.Models; diff --git a/src/core/DSharpPlus.Internal.Models/Applications/InstallParameters.cs b/src/core/DSharpPlus.Internal.Models/Applications/InstallParameters.cs index 13045ee86b..05378c8034 100644 --- a/src/core/DSharpPlus.Internal.Models/Applications/InstallParameters.cs +++ b/src/core/DSharpPlus.Internal.Models/Applications/InstallParameters.cs @@ -4,8 +4,8 @@ using System.Collections.Generic; -using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; namespace DSharpPlus.Internal.Models; diff --git a/src/core/DSharpPlus.Internal.Models/Applications/PartialApplication.cs b/src/core/DSharpPlus.Internal.Models/Applications/PartialApplication.cs index 52e1db9854..6316a9858f 100644 --- a/src/core/DSharpPlus.Internal.Models/Applications/PartialApplication.cs +++ b/src/core/DSharpPlus.Internal.Models/Applications/PartialApplication.cs @@ -4,8 +4,8 @@ using System.Collections.Generic; -using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; namespace DSharpPlus.Internal.Models; diff --git a/src/core/DSharpPlus.Internal.Models/AuditLogs/AuditLogEntry.cs b/src/core/DSharpPlus.Internal.Models/AuditLogs/AuditLogEntry.cs index 4b449b472a..070074845f 100644 --- a/src/core/DSharpPlus.Internal.Models/AuditLogs/AuditLogEntry.cs +++ b/src/core/DSharpPlus.Internal.Models/AuditLogs/AuditLogEntry.cs @@ -4,8 +4,8 @@ using System.Collections.Generic; -using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; using OneOf; diff --git a/src/core/DSharpPlus.Internal.Models/AutoModeration/AutoModerationAction.cs b/src/core/DSharpPlus.Internal.Models/AutoModeration/AutoModerationAction.cs index 6fa6763aa5..6b4829a76e 100644 --- a/src/core/DSharpPlus.Internal.Models/AutoModeration/AutoModerationAction.cs +++ b/src/core/DSharpPlus.Internal.Models/AutoModeration/AutoModerationAction.cs @@ -2,8 +2,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; namespace DSharpPlus.Internal.Models; diff --git a/src/core/DSharpPlus.Internal.Models/AutoModeration/AutoModerationRule.cs b/src/core/DSharpPlus.Internal.Models/AutoModeration/AutoModerationRule.cs index 69a8756126..8b54fdd4f0 100644 --- a/src/core/DSharpPlus.Internal.Models/AutoModeration/AutoModerationRule.cs +++ b/src/core/DSharpPlus.Internal.Models/AutoModeration/AutoModerationRule.cs @@ -4,8 +4,8 @@ using System.Collections.Generic; -using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; namespace DSharpPlus.Internal.Models; diff --git a/src/core/DSharpPlus.Internal.Models/AutoModeration/AutoModerationTriggerMetadata.cs b/src/core/DSharpPlus.Internal.Models/AutoModeration/AutoModerationTriggerMetadata.cs index ae087907e9..fedb2b02be 100644 --- a/src/core/DSharpPlus.Internal.Models/AutoModeration/AutoModerationTriggerMetadata.cs +++ b/src/core/DSharpPlus.Internal.Models/AutoModeration/AutoModerationTriggerMetadata.cs @@ -4,8 +4,8 @@ using System.Collections.Generic; -using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; namespace DSharpPlus.Internal.Models; diff --git a/src/core/DSharpPlus.Internal.Models/AutoModeration/BlockMessageActionMetadata.cs b/src/core/DSharpPlus.Internal.Models/AutoModeration/BlockMessageActionMetadata.cs index 470860a39d..5c6719126b 100644 --- a/src/core/DSharpPlus.Internal.Models/AutoModeration/BlockMessageActionMetadata.cs +++ b/src/core/DSharpPlus.Internal.Models/AutoModeration/BlockMessageActionMetadata.cs @@ -2,8 +2,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; namespace DSharpPlus.Internal.Models; diff --git a/src/core/DSharpPlus.Internal.Models/AutoModeration/PartialAutoModerationRule.cs b/src/core/DSharpPlus.Internal.Models/AutoModeration/PartialAutoModerationRule.cs index 19a63b9741..5d5107bee0 100644 --- a/src/core/DSharpPlus.Internal.Models/AutoModeration/PartialAutoModerationRule.cs +++ b/src/core/DSharpPlus.Internal.Models/AutoModeration/PartialAutoModerationRule.cs @@ -4,8 +4,8 @@ using System.Collections.Generic; -using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; namespace DSharpPlus.Internal.Models; diff --git a/src/core/DSharpPlus.Internal.Models/AutoModeration/SendAlertMessageActionMetadata.cs b/src/core/DSharpPlus.Internal.Models/AutoModeration/SendAlertMessageActionMetadata.cs index e5a6656fa1..f96df74c97 100644 --- a/src/core/DSharpPlus.Internal.Models/AutoModeration/SendAlertMessageActionMetadata.cs +++ b/src/core/DSharpPlus.Internal.Models/AutoModeration/SendAlertMessageActionMetadata.cs @@ -2,8 +2,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; namespace DSharpPlus.Internal.Models; diff --git a/src/core/DSharpPlus.Internal.Models/AutoModeration/TimeoutActionMetadata.cs b/src/core/DSharpPlus.Internal.Models/AutoModeration/TimeoutActionMetadata.cs index 028527eb07..0f31482a86 100644 --- a/src/core/DSharpPlus.Internal.Models/AutoModeration/TimeoutActionMetadata.cs +++ b/src/core/DSharpPlus.Internal.Models/AutoModeration/TimeoutActionMetadata.cs @@ -2,8 +2,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; namespace DSharpPlus.Internal.Models; diff --git a/src/core/DSharpPlus.Internal.Models/Channels/Attachment.cs b/src/core/DSharpPlus.Internal.Models/Channels/Attachment.cs index 4b89f4c201..edaeb716f7 100644 --- a/src/core/DSharpPlus.Internal.Models/Channels/Attachment.cs +++ b/src/core/DSharpPlus.Internal.Models/Channels/Attachment.cs @@ -4,8 +4,8 @@ using System; -using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; namespace DSharpPlus.Internal.Models; diff --git a/src/core/DSharpPlus.Internal.Models/Channels/Channel.cs b/src/core/DSharpPlus.Internal.Models/Channels/Channel.cs index 1e41a0f7fa..d561f36344 100644 --- a/src/core/DSharpPlus.Internal.Models/Channels/Channel.cs +++ b/src/core/DSharpPlus.Internal.Models/Channels/Channel.cs @@ -5,8 +5,8 @@ using System; using System.Collections.Generic; -using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; namespace DSharpPlus.Internal.Models; diff --git a/src/core/DSharpPlus.Internal.Models/Channels/ChannelMention.cs b/src/core/DSharpPlus.Internal.Models/Channels/ChannelMention.cs index 184ddbb058..cd2e870b7f 100644 --- a/src/core/DSharpPlus.Internal.Models/Channels/ChannelMention.cs +++ b/src/core/DSharpPlus.Internal.Models/Channels/ChannelMention.cs @@ -2,8 +2,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; namespace DSharpPlus.Internal.Models; diff --git a/src/core/DSharpPlus.Internal.Models/Channels/ChannelOverwrite.cs b/src/core/DSharpPlus.Internal.Models/Channels/ChannelOverwrite.cs index c9e09097f8..ee5d3f904a 100644 --- a/src/core/DSharpPlus.Internal.Models/Channels/ChannelOverwrite.cs +++ b/src/core/DSharpPlus.Internal.Models/Channels/ChannelOverwrite.cs @@ -2,8 +2,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; namespace DSharpPlus.Internal.Models; diff --git a/src/core/DSharpPlus.Internal.Models/Channels/Message.cs b/src/core/DSharpPlus.Internal.Models/Channels/Message.cs index bb9fe07193..71ce5d217f 100644 --- a/src/core/DSharpPlus.Internal.Models/Channels/Message.cs +++ b/src/core/DSharpPlus.Internal.Models/Channels/Message.cs @@ -5,8 +5,8 @@ using System; using System.Collections.Generic; -using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; namespace DSharpPlus.Internal.Models; diff --git a/src/core/DSharpPlus.Internal.Models/Channels/MessageActivity.cs b/src/core/DSharpPlus.Internal.Models/Channels/MessageActivity.cs index 8eacc4f4de..9051e346e9 100644 --- a/src/core/DSharpPlus.Internal.Models/Channels/MessageActivity.cs +++ b/src/core/DSharpPlus.Internal.Models/Channels/MessageActivity.cs @@ -2,8 +2,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; namespace DSharpPlus.Internal.Models; diff --git a/src/core/DSharpPlus.Internal.Models/Channels/PartialAttachment.cs b/src/core/DSharpPlus.Internal.Models/Channels/PartialAttachment.cs index 9ba1d49a91..e3bd350100 100644 --- a/src/core/DSharpPlus.Internal.Models/Channels/PartialAttachment.cs +++ b/src/core/DSharpPlus.Internal.Models/Channels/PartialAttachment.cs @@ -4,8 +4,8 @@ using System; -using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; namespace DSharpPlus.Internal.Models; diff --git a/src/core/DSharpPlus.Internal.Models/Channels/PartialChannel.cs b/src/core/DSharpPlus.Internal.Models/Channels/PartialChannel.cs index 349c9e998f..041c876fa3 100644 --- a/src/core/DSharpPlus.Internal.Models/Channels/PartialChannel.cs +++ b/src/core/DSharpPlus.Internal.Models/Channels/PartialChannel.cs @@ -5,8 +5,8 @@ using System; using System.Collections.Generic; -using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; namespace DSharpPlus.Internal.Models; diff --git a/src/core/DSharpPlus.Internal.Models/Channels/PartialChannelOverwrite.cs b/src/core/DSharpPlus.Internal.Models/Channels/PartialChannelOverwrite.cs index 6e12416530..f4bd0c06ea 100644 --- a/src/core/DSharpPlus.Internal.Models/Channels/PartialChannelOverwrite.cs +++ b/src/core/DSharpPlus.Internal.Models/Channels/PartialChannelOverwrite.cs @@ -2,8 +2,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; namespace DSharpPlus.Internal.Models; diff --git a/src/core/DSharpPlus.Internal.Models/Channels/PartialMessage.cs b/src/core/DSharpPlus.Internal.Models/Channels/PartialMessage.cs index 516e76d720..49027cb79f 100644 --- a/src/core/DSharpPlus.Internal.Models/Channels/PartialMessage.cs +++ b/src/core/DSharpPlus.Internal.Models/Channels/PartialMessage.cs @@ -5,8 +5,8 @@ using System; using System.Collections.Generic; -using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; namespace DSharpPlus.Internal.Models; diff --git a/src/core/DSharpPlus.Internal.Models/Entitlements/Entitlement.cs b/src/core/DSharpPlus.Internal.Models/Entitlements/Entitlement.cs index 819c6d4c79..5a41631112 100644 --- a/src/core/DSharpPlus.Internal.Models/Entitlements/Entitlement.cs +++ b/src/core/DSharpPlus.Internal.Models/Entitlements/Entitlement.cs @@ -4,8 +4,8 @@ using System; -using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; namespace DSharpPlus.Internal.Models; diff --git a/src/core/DSharpPlus.Internal.Models/Entitlements/PartialEntitlement.cs b/src/core/DSharpPlus.Internal.Models/Entitlements/PartialEntitlement.cs index 0ecfdac36e..23330c235d 100644 --- a/src/core/DSharpPlus.Internal.Models/Entitlements/PartialEntitlement.cs +++ b/src/core/DSharpPlus.Internal.Models/Entitlements/PartialEntitlement.cs @@ -4,8 +4,8 @@ using System; -using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; namespace DSharpPlus.Internal.Models; diff --git a/src/core/DSharpPlus.Internal.Models/Guilds/Guild.cs b/src/core/DSharpPlus.Internal.Models/Guilds/Guild.cs index e5beb14922..89845799b0 100644 --- a/src/core/DSharpPlus.Internal.Models/Guilds/Guild.cs +++ b/src/core/DSharpPlus.Internal.Models/Guilds/Guild.cs @@ -4,8 +4,8 @@ using System.Collections.Generic; -using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; namespace DSharpPlus.Internal.Models; diff --git a/src/core/DSharpPlus.Internal.Models/Guilds/GuildMember.cs b/src/core/DSharpPlus.Internal.Models/Guilds/GuildMember.cs index 513310cb37..ccee97e284 100644 --- a/src/core/DSharpPlus.Internal.Models/Guilds/GuildMember.cs +++ b/src/core/DSharpPlus.Internal.Models/Guilds/GuildMember.cs @@ -5,8 +5,8 @@ using System; using System.Collections.Generic; -using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; namespace DSharpPlus.Internal.Models; diff --git a/src/core/DSharpPlus.Internal.Models/Guilds/Integration.cs b/src/core/DSharpPlus.Internal.Models/Guilds/Integration.cs index 0148e91d42..ab433b198b 100644 --- a/src/core/DSharpPlus.Internal.Models/Guilds/Integration.cs +++ b/src/core/DSharpPlus.Internal.Models/Guilds/Integration.cs @@ -5,8 +5,8 @@ using System; using System.Collections.Generic; -using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; namespace DSharpPlus.Internal.Models; diff --git a/src/core/DSharpPlus.Internal.Models/Guilds/Onboarding.cs b/src/core/DSharpPlus.Internal.Models/Guilds/Onboarding.cs index 4ecf4fe759..0871b3eb81 100644 --- a/src/core/DSharpPlus.Internal.Models/Guilds/Onboarding.cs +++ b/src/core/DSharpPlus.Internal.Models/Guilds/Onboarding.cs @@ -4,8 +4,8 @@ using System.Collections.Generic; -using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; namespace DSharpPlus.Internal.Models; diff --git a/src/core/DSharpPlus.Internal.Models/Guilds/OnboardingPrompt.cs b/src/core/DSharpPlus.Internal.Models/Guilds/OnboardingPrompt.cs index bf1c386d6b..7124867ce4 100644 --- a/src/core/DSharpPlus.Internal.Models/Guilds/OnboardingPrompt.cs +++ b/src/core/DSharpPlus.Internal.Models/Guilds/OnboardingPrompt.cs @@ -4,8 +4,8 @@ using System.Collections.Generic; -using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; namespace DSharpPlus.Internal.Models; diff --git a/src/core/DSharpPlus.Internal.Models/Guilds/PartialGuild.cs b/src/core/DSharpPlus.Internal.Models/Guilds/PartialGuild.cs index 2584da5b8f..2860f20e4d 100644 --- a/src/core/DSharpPlus.Internal.Models/Guilds/PartialGuild.cs +++ b/src/core/DSharpPlus.Internal.Models/Guilds/PartialGuild.cs @@ -4,8 +4,8 @@ using System.Collections.Generic; -using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; namespace DSharpPlus.Internal.Models; diff --git a/src/core/DSharpPlus.Internal.Models/Guilds/PartialGuildMember.cs b/src/core/DSharpPlus.Internal.Models/Guilds/PartialGuildMember.cs index 3f1631f243..757f21e718 100644 --- a/src/core/DSharpPlus.Internal.Models/Guilds/PartialGuildMember.cs +++ b/src/core/DSharpPlus.Internal.Models/Guilds/PartialGuildMember.cs @@ -5,8 +5,8 @@ using System; using System.Collections.Generic; -using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; namespace DSharpPlus.Internal.Models; diff --git a/src/core/DSharpPlus.Internal.Models/Guilds/PartialIntegration.cs b/src/core/DSharpPlus.Internal.Models/Guilds/PartialIntegration.cs index b2f20c0063..e3ca0c85d1 100644 --- a/src/core/DSharpPlus.Internal.Models/Guilds/PartialIntegration.cs +++ b/src/core/DSharpPlus.Internal.Models/Guilds/PartialIntegration.cs @@ -5,8 +5,8 @@ using System; using System.Collections.Generic; -using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; namespace DSharpPlus.Internal.Models; diff --git a/src/core/DSharpPlus.Internal.Models/Guilds/PartialRole.cs b/src/core/DSharpPlus.Internal.Models/Guilds/PartialRole.cs index 280cb7302f..1c3741e3ad 100644 --- a/src/core/DSharpPlus.Internal.Models/Guilds/PartialRole.cs +++ b/src/core/DSharpPlus.Internal.Models/Guilds/PartialRole.cs @@ -2,8 +2,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; namespace DSharpPlus.Internal.Models; diff --git a/src/core/DSharpPlus.Internal.Models/Guilds/Role.cs b/src/core/DSharpPlus.Internal.Models/Guilds/Role.cs index 28e2c6a45d..e664623f06 100644 --- a/src/core/DSharpPlus.Internal.Models/Guilds/Role.cs +++ b/src/core/DSharpPlus.Internal.Models/Guilds/Role.cs @@ -2,8 +2,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; namespace DSharpPlus.Internal.Models; diff --git a/src/core/DSharpPlus.Internal.Models/Interactions/ApplicationCommandInteractionData.cs b/src/core/DSharpPlus.Internal.Models/Interactions/ApplicationCommandInteractionData.cs index 7d6e0f1e55..6336e0c4a1 100644 --- a/src/core/DSharpPlus.Internal.Models/Interactions/ApplicationCommandInteractionData.cs +++ b/src/core/DSharpPlus.Internal.Models/Interactions/ApplicationCommandInteractionData.cs @@ -4,8 +4,8 @@ using System.Collections.Generic; -using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; namespace DSharpPlus.Internal.Models; diff --git a/src/core/DSharpPlus.Internal.Models/Interactions/ApplicationCommandInteractionDataOption.cs b/src/core/DSharpPlus.Internal.Models/Interactions/ApplicationCommandInteractionDataOption.cs index f709d0f2a1..0386534f0b 100644 --- a/src/core/DSharpPlus.Internal.Models/Interactions/ApplicationCommandInteractionDataOption.cs +++ b/src/core/DSharpPlus.Internal.Models/Interactions/ApplicationCommandInteractionDataOption.cs @@ -4,8 +4,8 @@ using System.Collections.Generic; -using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; using OneOf; diff --git a/src/core/DSharpPlus.Internal.Models/Interactions/Interaction.cs b/src/core/DSharpPlus.Internal.Models/Interactions/Interaction.cs index 6c1b72ca42..6731b8f35d 100644 --- a/src/core/DSharpPlus.Internal.Models/Interactions/Interaction.cs +++ b/src/core/DSharpPlus.Internal.Models/Interactions/Interaction.cs @@ -4,8 +4,8 @@ using System.Collections.Generic; -using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; using OneOf; diff --git a/src/core/DSharpPlus.Internal.Models/Interactions/InteractionResponse.cs b/src/core/DSharpPlus.Internal.Models/Interactions/InteractionResponse.cs index b35696e7d8..7a492cf8a3 100644 --- a/src/core/DSharpPlus.Internal.Models/Interactions/InteractionResponse.cs +++ b/src/core/DSharpPlus.Internal.Models/Interactions/InteractionResponse.cs @@ -2,8 +2,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; using OneOf; diff --git a/src/core/DSharpPlus.Internal.Models/Interactions/MessageCallbackData.cs b/src/core/DSharpPlus.Internal.Models/Interactions/MessageCallbackData.cs index 01b2d26188..80707c68e3 100644 --- a/src/core/DSharpPlus.Internal.Models/Interactions/MessageCallbackData.cs +++ b/src/core/DSharpPlus.Internal.Models/Interactions/MessageCallbackData.cs @@ -4,8 +4,8 @@ using System.Collections.Generic; -using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; namespace DSharpPlus.Internal.Models; diff --git a/src/core/DSharpPlus.Internal.Models/Interactions/MessageComponentInteractionData.cs b/src/core/DSharpPlus.Internal.Models/Interactions/MessageComponentInteractionData.cs index 1441bc3310..42fec00765 100644 --- a/src/core/DSharpPlus.Internal.Models/Interactions/MessageComponentInteractionData.cs +++ b/src/core/DSharpPlus.Internal.Models/Interactions/MessageComponentInteractionData.cs @@ -4,8 +4,8 @@ using System.Collections.Generic; -using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; namespace DSharpPlus.Internal.Models; diff --git a/src/core/DSharpPlus.Internal.Models/Interactions/MessageInteraction.cs b/src/core/DSharpPlus.Internal.Models/Interactions/MessageInteraction.cs index 082a8d4ebe..49a8c2b215 100644 --- a/src/core/DSharpPlus.Internal.Models/Interactions/MessageInteraction.cs +++ b/src/core/DSharpPlus.Internal.Models/Interactions/MessageInteraction.cs @@ -2,8 +2,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; namespace DSharpPlus.Internal.Models; diff --git a/src/core/DSharpPlus.Internal.Models/Invites/Invite.cs b/src/core/DSharpPlus.Internal.Models/Invites/Invite.cs index 445030e990..bea894b0e1 100644 --- a/src/core/DSharpPlus.Internal.Models/Invites/Invite.cs +++ b/src/core/DSharpPlus.Internal.Models/Invites/Invite.cs @@ -4,8 +4,8 @@ using System; -using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; namespace DSharpPlus.Internal.Models; diff --git a/src/core/DSharpPlus.Internal.Models/Invites/PartialInvite.cs b/src/core/DSharpPlus.Internal.Models/Invites/PartialInvite.cs index 1c53630533..7aa243ea39 100644 --- a/src/core/DSharpPlus.Internal.Models/Invites/PartialInvite.cs +++ b/src/core/DSharpPlus.Internal.Models/Invites/PartialInvite.cs @@ -4,8 +4,8 @@ using System; -using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; namespace DSharpPlus.Internal.Models; diff --git a/src/core/DSharpPlus.Internal.Models/MessageComponents/ActionRowComponent.cs b/src/core/DSharpPlus.Internal.Models/MessageComponents/ActionRowComponent.cs index 553ca95078..5cfd073238 100644 --- a/src/core/DSharpPlus.Internal.Models/MessageComponents/ActionRowComponent.cs +++ b/src/core/DSharpPlus.Internal.Models/MessageComponents/ActionRowComponent.cs @@ -4,8 +4,8 @@ using System.Collections.Generic; -using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; namespace DSharpPlus.Internal.Models; diff --git a/src/core/DSharpPlus.Internal.Models/MessageComponents/ButtonComponent.cs b/src/core/DSharpPlus.Internal.Models/MessageComponents/ButtonComponent.cs index 9aa102b7ad..1726964647 100644 --- a/src/core/DSharpPlus.Internal.Models/MessageComponents/ButtonComponent.cs +++ b/src/core/DSharpPlus.Internal.Models/MessageComponents/ButtonComponent.cs @@ -2,8 +2,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; namespace DSharpPlus.Internal.Models; diff --git a/src/core/DSharpPlus.Internal.Models/MessageComponents/ChannelSelectComponent.cs b/src/core/DSharpPlus.Internal.Models/MessageComponents/ChannelSelectComponent.cs index 2ab9883926..54025d7724 100644 --- a/src/core/DSharpPlus.Internal.Models/MessageComponents/ChannelSelectComponent.cs +++ b/src/core/DSharpPlus.Internal.Models/MessageComponents/ChannelSelectComponent.cs @@ -4,8 +4,8 @@ using System.Collections.Generic; -using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; namespace DSharpPlus.Internal.Models; diff --git a/src/core/DSharpPlus.Internal.Models/MessageComponents/MentionableSelectComponent.cs b/src/core/DSharpPlus.Internal.Models/MessageComponents/MentionableSelectComponent.cs index f6c9cb4a19..4132f05864 100644 --- a/src/core/DSharpPlus.Internal.Models/MessageComponents/MentionableSelectComponent.cs +++ b/src/core/DSharpPlus.Internal.Models/MessageComponents/MentionableSelectComponent.cs @@ -4,8 +4,8 @@ using System.Collections.Generic; -using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; namespace DSharpPlus.Internal.Models; diff --git a/src/core/DSharpPlus.Internal.Models/MessageComponents/RoleSelectComponent.cs b/src/core/DSharpPlus.Internal.Models/MessageComponents/RoleSelectComponent.cs index 088902328c..03600d46cf 100644 --- a/src/core/DSharpPlus.Internal.Models/MessageComponents/RoleSelectComponent.cs +++ b/src/core/DSharpPlus.Internal.Models/MessageComponents/RoleSelectComponent.cs @@ -4,8 +4,8 @@ using System.Collections.Generic; -using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; namespace DSharpPlus.Internal.Models; diff --git a/src/core/DSharpPlus.Internal.Models/MessageComponents/StringSelectComponent.cs b/src/core/DSharpPlus.Internal.Models/MessageComponents/StringSelectComponent.cs index 6a90cb35a3..1b35b53ab7 100644 --- a/src/core/DSharpPlus.Internal.Models/MessageComponents/StringSelectComponent.cs +++ b/src/core/DSharpPlus.Internal.Models/MessageComponents/StringSelectComponent.cs @@ -4,8 +4,8 @@ using System.Collections.Generic; -using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; namespace DSharpPlus.Internal.Models; diff --git a/src/core/DSharpPlus.Internal.Models/MessageComponents/TextInputComponent.cs b/src/core/DSharpPlus.Internal.Models/MessageComponents/TextInputComponent.cs index 9c689e604d..df75bfd404 100644 --- a/src/core/DSharpPlus.Internal.Models/MessageComponents/TextInputComponent.cs +++ b/src/core/DSharpPlus.Internal.Models/MessageComponents/TextInputComponent.cs @@ -2,8 +2,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; namespace DSharpPlus.Internal.Models; diff --git a/src/core/DSharpPlus.Internal.Models/MessageComponents/UserSelectComponent.cs b/src/core/DSharpPlus.Internal.Models/MessageComponents/UserSelectComponent.cs index 927e52a63b..2d08593d40 100644 --- a/src/core/DSharpPlus.Internal.Models/MessageComponents/UserSelectComponent.cs +++ b/src/core/DSharpPlus.Internal.Models/MessageComponents/UserSelectComponent.cs @@ -4,8 +4,8 @@ using System.Collections.Generic; -using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; namespace DSharpPlus.Internal.Models; diff --git a/src/core/DSharpPlus.Internal.Models/RoleConnections/RoleConnectionMetadata.cs b/src/core/DSharpPlus.Internal.Models/RoleConnections/RoleConnectionMetadata.cs index 217358ee80..ecbc246636 100644 --- a/src/core/DSharpPlus.Internal.Models/RoleConnections/RoleConnectionMetadata.cs +++ b/src/core/DSharpPlus.Internal.Models/RoleConnections/RoleConnectionMetadata.cs @@ -4,8 +4,8 @@ using System.Collections.Generic; -using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; namespace DSharpPlus.Internal.Models; diff --git a/src/core/DSharpPlus.Internal.Models/ScheduledEvents/PartialScheduledEvent.cs b/src/core/DSharpPlus.Internal.Models/ScheduledEvents/PartialScheduledEvent.cs index 05960ae80d..199adb79f6 100644 --- a/src/core/DSharpPlus.Internal.Models/ScheduledEvents/PartialScheduledEvent.cs +++ b/src/core/DSharpPlus.Internal.Models/ScheduledEvents/PartialScheduledEvent.cs @@ -4,8 +4,8 @@ using System; -using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; namespace DSharpPlus.Internal.Models; diff --git a/src/core/DSharpPlus.Internal.Models/ScheduledEvents/ScheduledEvent.cs b/src/core/DSharpPlus.Internal.Models/ScheduledEvents/ScheduledEvent.cs index 796dcf60a8..de00571b09 100644 --- a/src/core/DSharpPlus.Internal.Models/ScheduledEvents/ScheduledEvent.cs +++ b/src/core/DSharpPlus.Internal.Models/ScheduledEvents/ScheduledEvent.cs @@ -4,8 +4,8 @@ using System; -using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; namespace DSharpPlus.Internal.Models; diff --git a/src/core/DSharpPlus.Internal.Models/Skus/Sku.cs b/src/core/DSharpPlus.Internal.Models/Skus/Sku.cs index 7f63453799..6352cd880a 100644 --- a/src/core/DSharpPlus.Internal.Models/Skus/Sku.cs +++ b/src/core/DSharpPlus.Internal.Models/Skus/Sku.cs @@ -2,8 +2,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; namespace DSharpPlus.Internal.Models; diff --git a/src/core/DSharpPlus.Internal.Models/StageInstances/PartialStageInstance.cs b/src/core/DSharpPlus.Internal.Models/StageInstances/PartialStageInstance.cs index 53ac4c288d..d2dcc1b3c2 100644 --- a/src/core/DSharpPlus.Internal.Models/StageInstances/PartialStageInstance.cs +++ b/src/core/DSharpPlus.Internal.Models/StageInstances/PartialStageInstance.cs @@ -2,8 +2,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; namespace DSharpPlus.Internal.Models; diff --git a/src/core/DSharpPlus.Internal.Models/StageInstances/StageInstance.cs b/src/core/DSharpPlus.Internal.Models/StageInstances/StageInstance.cs index 9948a3e151..038429bdaa 100644 --- a/src/core/DSharpPlus.Internal.Models/StageInstances/StageInstance.cs +++ b/src/core/DSharpPlus.Internal.Models/StageInstances/StageInstance.cs @@ -2,8 +2,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; namespace DSharpPlus.Internal.Models; diff --git a/src/core/DSharpPlus.Internal.Models/Stickers/PartialSticker.cs b/src/core/DSharpPlus.Internal.Models/Stickers/PartialSticker.cs index a336844216..71242b22af 100644 --- a/src/core/DSharpPlus.Internal.Models/Stickers/PartialSticker.cs +++ b/src/core/DSharpPlus.Internal.Models/Stickers/PartialSticker.cs @@ -2,8 +2,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; namespace DSharpPlus.Internal.Models; diff --git a/src/core/DSharpPlus.Internal.Models/Stickers/Sticker.cs b/src/core/DSharpPlus.Internal.Models/Stickers/Sticker.cs index 7df13068e8..65a765a877 100644 --- a/src/core/DSharpPlus.Internal.Models/Stickers/Sticker.cs +++ b/src/core/DSharpPlus.Internal.Models/Stickers/Sticker.cs @@ -2,8 +2,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; namespace DSharpPlus.Internal.Models; diff --git a/src/core/DSharpPlus.Internal.Models/Stickers/StickerItem.cs b/src/core/DSharpPlus.Internal.Models/Stickers/StickerItem.cs index d14c44d847..cf40f6510b 100644 --- a/src/core/DSharpPlus.Internal.Models/Stickers/StickerItem.cs +++ b/src/core/DSharpPlus.Internal.Models/Stickers/StickerItem.cs @@ -2,8 +2,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; namespace DSharpPlus.Internal.Models; diff --git a/src/core/DSharpPlus.Internal.Models/Teams/TeamMember.cs b/src/core/DSharpPlus.Internal.Models/Teams/TeamMember.cs index 64d6be01a2..cfdcc8dc34 100644 --- a/src/core/DSharpPlus.Internal.Models/Teams/TeamMember.cs +++ b/src/core/DSharpPlus.Internal.Models/Teams/TeamMember.cs @@ -4,8 +4,8 @@ using System.Collections.Generic; -using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; namespace DSharpPlus.Internal.Models; diff --git a/src/core/DSharpPlus.Internal.Models/Users/Connection.cs b/src/core/DSharpPlus.Internal.Models/Users/Connection.cs index 04c3285569..c83a922347 100644 --- a/src/core/DSharpPlus.Internal.Models/Users/Connection.cs +++ b/src/core/DSharpPlus.Internal.Models/Users/Connection.cs @@ -4,8 +4,8 @@ using System.Collections.Generic; -using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; namespace DSharpPlus.Internal.Models; diff --git a/src/core/DSharpPlus.Internal.Models/Users/PartialUser.cs b/src/core/DSharpPlus.Internal.Models/Users/PartialUser.cs index 0ed02231ec..7c93745737 100644 --- a/src/core/DSharpPlus.Internal.Models/Users/PartialUser.cs +++ b/src/core/DSharpPlus.Internal.Models/Users/PartialUser.cs @@ -2,8 +2,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; namespace DSharpPlus.Internal.Models; diff --git a/src/core/DSharpPlus.Internal.Models/Users/User.cs b/src/core/DSharpPlus.Internal.Models/Users/User.cs index 8f06b1dbf9..6670194df6 100644 --- a/src/core/DSharpPlus.Internal.Models/Users/User.cs +++ b/src/core/DSharpPlus.Internal.Models/Users/User.cs @@ -2,8 +2,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; namespace DSharpPlus.Internal.Models; diff --git a/src/core/DSharpPlus.Internal.Models/Webhooks/PartialWebhook.cs b/src/core/DSharpPlus.Internal.Models/Webhooks/PartialWebhook.cs index c30fcc772b..70f039c16a 100644 --- a/src/core/DSharpPlus.Internal.Models/Webhooks/PartialWebhook.cs +++ b/src/core/DSharpPlus.Internal.Models/Webhooks/PartialWebhook.cs @@ -2,8 +2,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; namespace DSharpPlus.Internal.Models; diff --git a/src/core/DSharpPlus.Internal.Models/Webhooks/Webhook.cs b/src/core/DSharpPlus.Internal.Models/Webhooks/Webhook.cs index b86d804dd6..ab4498fe0e 100644 --- a/src/core/DSharpPlus.Internal.Models/Webhooks/Webhook.cs +++ b/src/core/DSharpPlus.Internal.Models/Webhooks/Webhook.cs @@ -2,8 +2,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; namespace DSharpPlus.Internal.Models; diff --git a/src/core/DSharpPlus.Internal.Rest/DSharpPlus.Internal.Rest.csproj b/src/core/DSharpPlus.Internal.Rest/DSharpPlus.Internal.Rest.csproj index fc2b149010..0d17e37212 100644 --- a/src/core/DSharpPlus.Internal.Rest/DSharpPlus.Internal.Rest.csproj +++ b/src/core/DSharpPlus.Internal.Rest/DSharpPlus.Internal.Rest.csproj @@ -4,4 +4,8 @@ $(_DSharpPlusInternalRestVersion) + + + + diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/ApplicationCommands/CreateGlobalApplicationCommandPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/ApplicationCommands/CreateGlobalApplicationCommandPayload.cs new file mode 100644 index 0000000000..2d42209065 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/ApplicationCommands/CreateGlobalApplicationCommandPayload.cs @@ -0,0 +1,38 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Rest.Payloads; + +namespace DSharpPlus.Internal.Rest.Payloads; + +/// +public sealed record CreateGlobalApplicationCommandPayload : ICreateGlobalApplicationCommandPayload +{ + /// + public required string Name { get; init; } + + /// + public Optional?> NameLocalizations { get; init; } + + /// + public Optional Description { get; init; } + + /// + public Optional?> DescriptionLocalizations { get; init; } + + /// + public Optional DefaultMemberPermissions { get; init; } + + /// + public Optional DmPermission { get; init; } + + /// + public Optional Type { get; init; } + + /// + public Optional Nsfw { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/ApplicationCommands/CreateGuildApplicationCommandPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/ApplicationCommands/CreateGuildApplicationCommandPayload.cs new file mode 100644 index 0000000000..0d83ce3a3a --- /dev/null +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/ApplicationCommands/CreateGuildApplicationCommandPayload.cs @@ -0,0 +1,35 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Rest.Payloads; + +namespace DSharpPlus.Internal.Rest.Payloads; + +/// +public sealed record CreateGuildApplicationCommandPayload : ICreateGuildApplicationCommandPayload +{ + /// + public required string Name { get; init; } + + /// + public Optional?> NameLocalizations { get; init; } + + /// + public Optional Description { get; init; } + + /// + public Optional?> DescriptionLocalizations { get; init; } + + /// + public Optional DefaultMemberPermissions { get; init; } + + /// + public Optional Type { get; init; } + + /// + public Optional Nsfw { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/ApplicationCommands/EditGlobalApplicationCommandPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/ApplicationCommands/EditGlobalApplicationCommandPayload.cs new file mode 100644 index 0000000000..2a4758c581 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/ApplicationCommands/EditGlobalApplicationCommandPayload.cs @@ -0,0 +1,38 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Rest.Payloads; + +namespace DSharpPlus.Internal.Rest.Payloads; + +/// +public sealed record EditGlobalApplicationCommandPayload : IEditGlobalApplicationCommandPayload +{ + /// + public Optional Name { get; init; } + + /// + public Optional?> NameLocalizations { get; init; } + + /// + public Optional Description { get; init; } + + /// + public Optional?> DescriptionLocalizations { get; init; } + + /// + public Optional DefaultMemberPermissions { get; init; } + + /// + public Optional DmPermission { get; init; } + + /// + public Optional Type { get; init; } + + /// + public Optional Nsfw { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/ApplicationCommands/EditGuildApplicationCommandPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/ApplicationCommands/EditGuildApplicationCommandPayload.cs new file mode 100644 index 0000000000..01a294cdd1 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/ApplicationCommands/EditGuildApplicationCommandPayload.cs @@ -0,0 +1,35 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Rest.Payloads; + +namespace DSharpPlus.Internal.Rest.Payloads; + +/// +public sealed record EditGuildApplicationCommandPayload : IEditGuildApplicationCommandPayload +{ + /// + public Optional Name { get; init; } + + /// + public Optional?> NameLocalizations { get; init; } + + /// + public Optional Description { get; init; } + + /// + public Optional?> DescriptionLocalizations { get; init; } + + /// + public Optional DefaultMemberPermissions { get; init; } + + /// + public Optional Type { get; init; } + + /// + public Optional Nsfw { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Applications/EditCurrentApplicationPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Applications/EditCurrentApplicationPayload.cs new file mode 100644 index 0000000000..5a6890811f --- /dev/null +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Applications/EditCurrentApplicationPayload.cs @@ -0,0 +1,42 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Rest.Payloads; + +namespace DSharpPlus.Internal.Rest.Payloads; + +/// +public sealed record EditCurrentApplicationPayload : IEditCurrentApplicationPayload +{ + /// + public Optional CustomInstallUrl { get; init; } + + /// + public Optional Description { get; init; } + + /// + public Optional RoleConnectionsVerificationUrl { get; init; } + + /// + public Optional InstallParams { get; init; } + + /// + public Optional Flags { get; init; } + + /// + public Optional Icon { get; init; } + + /// + public Optional CoverImage { get; init; } + + /// + public Optional InteractionsEndpointUrl { get; init; } + + /// + public Optional> Tags { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/AutoModeration/CreateAutoModerationRulePayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/AutoModeration/CreateAutoModerationRulePayload.cs new file mode 100644 index 0000000000..d6738d0184 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/AutoModeration/CreateAutoModerationRulePayload.cs @@ -0,0 +1,39 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Rest.Payloads; + +namespace DSharpPlus.Internal.Rest.Payloads; + +/// +public sealed record CreateAutoModerationRulePayload : ICreateAutoModerationRulePayload +{ + /// + public required string Name { get; init; } + + /// + public required DiscordAutoModerationEventType EventType { get; init; } + + /// + public required DiscordAutoModerationTriggerType TriggerType { get; init; } + + /// + public Optional TriggerMetadata { get; init; } + + /// + public required IReadOnlyList Actions { get; init; } + + /// + public Optional Enabled { get; init; } + + /// + public Optional> ExemptRoles { get; init; } + + /// + public Optional> ExemptChannels { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/AutoModeration/ModifyAutoModerationRulePayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/AutoModeration/ModifyAutoModerationRulePayload.cs new file mode 100644 index 0000000000..e5614894e6 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/AutoModeration/ModifyAutoModerationRulePayload.cs @@ -0,0 +1,36 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Rest.Payloads; + +namespace DSharpPlus.Internal.Rest.Payloads; + +/// +public sealed record ModifyAutoModerationRulePayload : IModifyAutoModerationRulePayload +{ + /// + public Optional Name { get; init; } + + /// + public Optional EventType { get; init; } + + /// + public Optional TriggerMetadata { get; init; } + + /// + public Optional> Actions { get; init; } + + /// + public Optional Enabled { get; init; } + + /// + public Optional> ExemptRoles { get; init; } + + /// + public Optional> ExemptChannels { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/CreateChannelInvitePayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/CreateChannelInvitePayload.cs new file mode 100644 index 0000000000..e2471e9e80 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/CreateChannelInvitePayload.cs @@ -0,0 +1,33 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Rest.Payloads; + +namespace DSharpPlus.Internal.Rest.Payloads; + +/// +public sealed record CreateChannelInvitePayload : ICreateChannelInvitePayload +{ + /// + public Optional MaxAge { get; init; } + + /// + public Optional MaxUses { get; init; } + + /// + public Optional Temporary { get; init; } + + /// + public Optional Unique { get; init; } + + /// + public Optional TargetType { get; init; } + + /// + public Optional TargetUserId { get; init; } + + /// + public Optional TargetApplicationId { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/CreateMessagePayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/CreateMessagePayload.cs new file mode 100644 index 0000000000..e7f8c2e08e --- /dev/null +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/CreateMessagePayload.cs @@ -0,0 +1,48 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Rest.Payloads; + +namespace DSharpPlus.Internal.Rest.Payloads; + +/// +public sealed record CreateMessagePayload : ICreateMessagePayload +{ + /// + public Optional Content { get; init; } + + /// + public Optional Nonce { get; init; } + + /// + public Optional Tts { get; init; } + + /// + public Optional> Embeds { get; init; } + + /// + public Optional AllowedMentions { get; init; } + + /// + public Optional MessageReference { get; init; } + + /// + public Optional> Components { get; init; } + + /// + public Optional> StickerIds { get; init; } + + /// + public IReadOnlyList? Files { get; init; } + + /// + public Optional> Attachments { get; init; } + + /// + public Optional Flags { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/EditChannelPermissionsPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/EditChannelPermissionsPayload.cs new file mode 100644 index 0000000000..536ce1064a --- /dev/null +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/EditChannelPermissionsPayload.cs @@ -0,0 +1,21 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Rest.Payloads; + +namespace DSharpPlus.Internal.Rest.Payloads; + +/// +public sealed record EditChannelPermissionsPayload : IEditChannelPermissionsPayload +{ + /// + public required DiscordChannelOverwriteType Type { get; init; } + + /// + public Optional Allow { get; init; } + + /// + public Optional Deny { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/EditMessagePayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/EditMessagePayload.cs new file mode 100644 index 0000000000..54336c6287 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/EditMessagePayload.cs @@ -0,0 +1,36 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Rest.Payloads; + +namespace DSharpPlus.Internal.Rest.Payloads; + +/// +public sealed record EditMessagePayload : IEditMessagePayload +{ + /// + public Optional Content { get; init; } + + /// + public Optional?> Embeds { get; init; } + + /// + public Optional Flags { get; init; } + + /// + public Optional AllowedMentions { get; init; } + + /// + public Optional?> Components { get; init; } + + /// + public IReadOnlyList? Files { get; init; } + + /// + public Optional?> Attachments { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/FollowAnnouncementChannelPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/FollowAnnouncementChannelPayload.cs new file mode 100644 index 0000000000..b2b2602d71 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/FollowAnnouncementChannelPayload.cs @@ -0,0 +1,14 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Internal.Abstractions.Rest.Payloads; + +namespace DSharpPlus.Internal.Rest.Payloads; + +/// +public sealed record FollowAnnouncementChannelPayload : IFollowAnnouncementChannelPayload +{ + /// + public required Snowflake WebhookChannelId { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/ForumAndMediaThreadMessage.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/ForumAndMediaThreadMessage.cs new file mode 100644 index 0000000000..41b974213a --- /dev/null +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/ForumAndMediaThreadMessage.cs @@ -0,0 +1,36 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Rest.Payloads; + +namespace DSharpPlus.Internal.Rest.Payloads; + +/// +public sealed record ForumAndMediaThreadMessage : IForumAndMediaThreadMessage +{ + /// + public Optional Content { get; init; } + + /// + public Optional> Embeds { get; init; } + + /// + public Optional AllowedMentions { get; init; } + + /// + public Optional> Components { get; init; } + + /// + public Optional> StickerIds { get; init; } + + /// + public Optional> Attachments { get; init; } + + /// + public Optional Flags { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/GroupDMAddRecipientPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/GroupDMAddRecipientPayload.cs new file mode 100644 index 0000000000..8864f2d02c --- /dev/null +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/GroupDMAddRecipientPayload.cs @@ -0,0 +1,17 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Internal.Abstractions.Rest.Payloads; + +namespace DSharpPlus.Internal.Rest.Payloads; + +/// +public sealed record GroupDMAddRecipientPayload : IGroupDMAddRecipientPayload +{ + /// + public required string AccessToken { get; init; } + + /// + public required string Nick { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/ModifyGroupDMPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/ModifyGroupDMPayload.cs new file mode 100644 index 0000000000..ccde5673e8 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/ModifyGroupDMPayload.cs @@ -0,0 +1,17 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Internal.Abstractions.Rest.Payloads; + +namespace DSharpPlus.Internal.Rest.Payloads; + +/// +public sealed record ModifyGroupDMPayload : IModifyGroupDMPayload +{ + /// + public Optional Name { get; init; } + + /// + public Optional Icon { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/ModifyGuildChannelPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/ModifyGuildChannelPayload.cs new file mode 100644 index 0000000000..29f48bbbb8 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/ModifyGuildChannelPayload.cs @@ -0,0 +1,72 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Rest.Payloads; + +namespace DSharpPlus.Internal.Rest.Payloads; + +/// +public sealed record ModifyGuildChannelPayload : IModifyGuildChannelPayload +{ + /// + public Optional Name { get; init; } + + /// + public Optional Type { get; init; } + + /// + public Optional Position { get; init; } + + /// + public Optional Topic { get; init; } + + /// + public Optional Nsfw { get; init; } + + /// + public Optional RateLimitPerUser { get; init; } + + /// + public Optional Bitrate { get; init; } + + /// + public Optional UserLimit { get; init; } + + /// + public Optional?> PermissionOverwrites { get; init; } + + /// + public Optional ParentId { get; init; } + + /// + public Optional RtcRegion { get; init; } + + /// + public Optional VideoQualityMode { get; init; } + + /// + public Optional DefaultAutoArchiveDuration { get; init; } + + /// + public Optional Flags { get; init; } + + /// + public Optional> AvailableTags { get; init; } + + /// + public Optional DefaultReactionEmoji { get; init; } + + /// + public Optional DefaultThreadRateLimitPerUser { get; init; } + + /// + public Optional DefaultSortOrder { get; init; } + + /// + public Optional DefaultForumLayout { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/ModifyThreadChannelPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/ModifyThreadChannelPayload.cs new file mode 100644 index 0000000000..4cff23cc13 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/ModifyThreadChannelPayload.cs @@ -0,0 +1,38 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Rest.Payloads; + +namespace DSharpPlus.Internal.Rest.Payloads; + +/// +public sealed record ModifyThreadChannelPayload : IModifyThreadChannelPayload +{ + /// + public Optional Name { get; init; } + + /// + public Optional Archived { get; init; } + + /// + public Optional AutoArchiveDuration { get; init; } + + /// + public Optional Locked { get; init; } + + /// + public Optional Invitable { get; init; } + + /// + public Optional RateLimitPerUser { get; init; } + + /// + public Optional Flags { get; init; } + + /// + public Optional> AppliedTags { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/StartThreadFromMessagePayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/StartThreadFromMessagePayload.cs new file mode 100644 index 0000000000..f8a360d846 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/StartThreadFromMessagePayload.cs @@ -0,0 +1,20 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Internal.Abstractions.Rest.Payloads; + +namespace DSharpPlus.Internal.Rest.Payloads; + +/// +public sealed record StartThreadFromMessagePayload : IStartThreadFromMessagePayload +{ + /// + public required string Name { get; init; } + + /// + public Optional AutoArchiveDuration { get; init; } + + /// + public Optional RateLimitPerUser { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/StartThreadInForumOrMediaChannelPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/StartThreadInForumOrMediaChannelPayload.cs new file mode 100644 index 0000000000..9b56411f11 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/StartThreadInForumOrMediaChannelPayload.cs @@ -0,0 +1,31 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Internal.Abstractions.Rest.Payloads; + +namespace DSharpPlus.Internal.Rest.Payloads; + +/// +public sealed record StartThreadInForumOrMediaChannelPayload : IStartThreadInForumOrMediaChannelPayload +{ + /// + public required string Name { get; init; } + + /// + public Optional AutoArchiveDuration { get; init; } + + /// + public Optional RateLimitPerUser { get; init; } + + /// + public required IForumAndMediaThreadMessage Message { get; init; } + + /// + public Optional> AppliedTags { get; init; } + + /// + public IReadOnlyList? Files { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/StartThreadWithoutMessagePayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/StartThreadWithoutMessagePayload.cs new file mode 100644 index 0000000000..fd0ac19fae --- /dev/null +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/StartThreadWithoutMessagePayload.cs @@ -0,0 +1,27 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Rest.Payloads; + +namespace DSharpPlus.Internal.Rest.Payloads; + +/// +public sealed record StartThreadWithoutMessagePayload : IStartThreadWithoutMessagePayload +{ + /// + public required string Name { get; init; } + + /// + public Optional AutoArchiveDuration { get; init; } + + /// + public Optional RateLimitPerUser { get; init; } + + /// + public required DiscordChannelType Type { get; init; } + + /// + public Optional Invitable { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Emojis/CreateGuildEmojiPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Emojis/CreateGuildEmojiPayload.cs new file mode 100644 index 0000000000..d45de62aa7 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Emojis/CreateGuildEmojiPayload.cs @@ -0,0 +1,22 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Internal.Abstractions.Rest.Payloads; + +namespace DSharpPlus.Internal.Rest.Payloads; + +/// +public sealed record CreateGuildEmojiPayload : ICreateGuildEmojiPayload +{ + /// + public required string Name { get; init; } + + /// + public required ImageData Image { get; init; } + + /// + public Optional> Roles { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Emojis/ModifyGuildEmojiPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Emojis/ModifyGuildEmojiPayload.cs new file mode 100644 index 0000000000..66aa8e2c3a --- /dev/null +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Emojis/ModifyGuildEmojiPayload.cs @@ -0,0 +1,19 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Internal.Abstractions.Rest.Payloads; + +namespace DSharpPlus.Internal.Rest.Payloads; + +/// +public sealed record ModifyGuildEmojiPayload : IModifyGuildEmojiPayload +{ + /// + public Optional Name { get; init; } + + /// + public Optional> Roles { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Entitlements/CreateTestEntitlementPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Entitlements/CreateTestEntitlementPayload.cs new file mode 100644 index 0000000000..6b7484b995 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Entitlements/CreateTestEntitlementPayload.cs @@ -0,0 +1,21 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Rest.Payloads; + +namespace DSharpPlus.Internal.Rest.Payloads; + +/// +public sealed record CreateTestEntitlementPayload : ICreateTestEntitlementPayload +{ + /// + public required Snowflake SkuId { get; init; } + + /// + public required Snowflake OwnerId { get; init; } + + /// + public required DiscordEntitlementOwnerType OwnerType { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/GuildTemplates/CreateGuildFromGuildTemplatePayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/GuildTemplates/CreateGuildFromGuildTemplatePayload.cs new file mode 100644 index 0000000000..e562e13f52 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/GuildTemplates/CreateGuildFromGuildTemplatePayload.cs @@ -0,0 +1,17 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Internal.Abstractions.Rest.Payloads; + +namespace DSharpPlus.Internal.Rest.Payloads; + +/// +public sealed record CreateGuildFromGuildTemplatePayload : ICreateGuildFromGuildTemplatePayload +{ + /// + public required string Name { get; init; } + + /// + public Optional Icon { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/GuildTemplates/CreateGuildTemplatePayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/GuildTemplates/CreateGuildTemplatePayload.cs new file mode 100644 index 0000000000..1ae182ce49 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/GuildTemplates/CreateGuildTemplatePayload.cs @@ -0,0 +1,17 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Internal.Abstractions.Rest.Payloads; + +namespace DSharpPlus.Internal.Rest.Payloads; + +/// +public sealed record CreateGuildTemplatePayload : ICreateGuildTemplatePayload +{ + /// + public required string Name { get; init; } + + /// + public Optional Description { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/GuildTemplates/ModifyGuildTemplatePayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/GuildTemplates/ModifyGuildTemplatePayload.cs new file mode 100644 index 0000000000..7b4c2f1713 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/GuildTemplates/ModifyGuildTemplatePayload.cs @@ -0,0 +1,17 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Internal.Abstractions.Rest.Payloads; + +namespace DSharpPlus.Internal.Rest.Payloads; + +/// +public sealed record ModifyGuildTemplatePayload : IModifyGuildTemplatePayload +{ + /// + public Optional Name { get; init; } + + /// + public Optional Description { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/AddGuildMemberPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/AddGuildMemberPayload.cs new file mode 100644 index 0000000000..d34e8480f3 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/AddGuildMemberPayload.cs @@ -0,0 +1,28 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Internal.Abstractions.Rest.Payloads; + +namespace DSharpPlus.Internal.Rest.Payloads; + +/// +public sealed record AddGuildMemberPayload : IAddGuildMemberPayload +{ + /// + public required string AccessToken { get; init; } + + /// + public Optional Nickname { get; init; } + + /// + public Optional> Roles { get; init; } + + /// + public Optional Mute { get; init; } + + /// + public Optional Deaf { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/CreateGuildChannelPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/CreateGuildChannelPayload.cs new file mode 100644 index 0000000000..abeb172fd2 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/CreateGuildChannelPayload.cs @@ -0,0 +1,69 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Rest.Payloads; + +namespace DSharpPlus.Internal.Rest.Payloads; + +/// +public sealed record CreateGuildChannelPayload : ICreateGuildChannelPayload +{ + /// + public required string Name { get; init; } + + /// + public Optional Type { get; init; } + + /// + public Optional Topic { get; init; } + + /// + public Optional Bitrate { get; init; } + + /// + public Optional UserLimit { get; init; } + + /// + public Optional RateLimitPerUser { get; init; } + + /// + public Optional Position { get; init; } + + /// + public Optional?> PermissionOverwrites { get; init; } + + /// + public Optional ParentId { get; init; } + + /// + public Optional Nsfw { get; init; } + + /// + public Optional RtcRegion { get; init; } + + /// + public Optional VideoQualityMode { get; init; } + + /// + public Optional DefaultAutoArchiveDuration { get; init; } + + /// + public Optional DefaultReactionEmoji { get; init; } + + /// + public Optional?> AvailableTags { get; init; } + + /// + public Optional DefaultSortOrder { get; init; } + + /// + public Optional DefaultForumLayout { get; init; } + + /// + public Optional DefaultThreadRateLimitPerUser { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/CreateGuildPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/CreateGuildPayload.cs new file mode 100644 index 0000000000..9713248373 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/CreateGuildPayload.cs @@ -0,0 +1,48 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Rest.Payloads; + +namespace DSharpPlus.Internal.Rest.Payloads; + +/// +public sealed record CreateGuildPayload : ICreateGuildPayload +{ + /// + public required string Name { get; init; } + + /// + public Optional Icon { get; init; } + + /// + public Optional VerificationLevel { get; init; } + + /// + public Optional DefaultMessageNotifications { get; init; } + + /// + public Optional ExplicitContentFilter { get; init; } + + /// + public Optional> Roles { get; init; } + + /// + public Optional> Channels { get; init; } + + /// + public Optional AfkChannelId { get; init; } + + /// + public Optional AfkTimeout { get; init; } + + /// + public Optional SystemChannelId { get; init; } + + /// + public Optional SystemChannelFlags { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/CreateGuildRolePayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/CreateGuildRolePayload.cs new file mode 100644 index 0000000000..0ca3556210 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/CreateGuildRolePayload.cs @@ -0,0 +1,33 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Rest.Payloads; + +namespace DSharpPlus.Internal.Rest.Payloads; + +/// +public sealed record CreateGuildRolePayload : ICreateGuildRolePayload +{ + /// + public Optional Name { get; init; } + + /// + public Optional Permissions { get; init; } + + /// + public Optional Color { get; init; } + + /// + public Optional Hoist { get; init; } + + /// + public Optional Icon { get; init; } + + /// + public Optional UnicodeEmoji { get; init; } + + /// + public Optional Mentionable { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyCurrentMemberPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyCurrentMemberPayload.cs new file mode 100644 index 0000000000..c05cc38cf4 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyCurrentMemberPayload.cs @@ -0,0 +1,14 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Internal.Abstractions.Rest.Payloads; + +namespace DSharpPlus.Internal.Rest.Payloads; + +/// +public sealed record ModifyCurrentMemberPayload : IModifyCurrentMemberPayload +{ + /// + public Optional Nick { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyCurrentUserVoiceStatePayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyCurrentUserVoiceStatePayload.cs new file mode 100644 index 0000000000..8599d8dfb6 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyCurrentUserVoiceStatePayload.cs @@ -0,0 +1,22 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; + +using DSharpPlus.Internal.Abstractions.Rest.Payloads; + +namespace DSharpPlus.Internal.Rest.Payloads; + +/// +public sealed record ModifyCurrentUserVoiceStatePayload : IModifyCurrentUserVoiceStatePayload +{ + /// + public Optional ChannelId { get; init; } + + /// + public Optional Suppress { get; init; } + + /// + public Optional RequestToSpeakTimestamp { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyGuildChannelPositionsPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyGuildChannelPositionsPayload.cs new file mode 100644 index 0000000000..b0882eb6ed --- /dev/null +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyGuildChannelPositionsPayload.cs @@ -0,0 +1,23 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Internal.Abstractions.Rest.Payloads; + +namespace DSharpPlus.Internal.Rest.Payloads; + +/// +public sealed record ModifyGuildChannelPositionsPayload : IModifyGuildChannelPositionsPayload +{ + /// + public required Snowflake ChannelId { get; init; } + + /// + public Optional Position { get; init; } + + /// + public Optional LockPermissions { get; init; } + + /// + public Optional ParentChannelId { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyGuildMemberPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyGuildMemberPayload.cs new file mode 100644 index 0000000000..2af47abf88 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyGuildMemberPayload.cs @@ -0,0 +1,32 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; +using System.Collections.Generic; + +using DSharpPlus.Internal.Abstractions.Rest.Payloads; + +namespace DSharpPlus.Internal.Rest.Payloads; + +/// +public sealed record ModifyGuildMemberPayload : IModifyGuildMemberPayload +{ + /// + public Optional Nickname { get; init; } + + /// + public Optional?> Roles { get; init; } + + /// + public Optional Mute { get; init; } + + /// + public Optional Deaf { get; init; } + + /// + public Optional ChannelId { get; init; } + + /// + public Optional CommunicationDisabledUntil { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyGuildMfaLevelPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyGuildMfaLevelPayload.cs new file mode 100644 index 0000000000..de2ac8360c --- /dev/null +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyGuildMfaLevelPayload.cs @@ -0,0 +1,15 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Rest.Payloads; + +namespace DSharpPlus.Internal.Rest.Payloads; + +/// +public sealed record ModifyGuildMfaLevelPayload : IModifyGuildMfaLevelPayload +{ + /// + public required DiscordMfaLevel Level { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyGuildOnboardingPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyGuildOnboardingPayload.cs new file mode 100644 index 0000000000..03b75258ea --- /dev/null +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyGuildOnboardingPayload.cs @@ -0,0 +1,27 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Rest.Payloads; + +namespace DSharpPlus.Internal.Rest.Payloads; + +/// +public sealed record ModifyGuildOnboardingPayload : IModifyGuildOnboardingPayload +{ + /// + public required IReadOnlyList Prompts { get; init; } + + /// + public required IReadOnlyList DefaultChannelIds { get; init; } + + /// + public required bool Enabled { get; init; } + + /// + public required DiscordGuildOnboardingMode Mode { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyGuildPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyGuildPayload.cs new file mode 100644 index 0000000000..9de19a3171 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyGuildPayload.cs @@ -0,0 +1,74 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Rest.Payloads; + +namespace DSharpPlus.Internal.Rest.Payloads; + +/// +public sealed record ModifyGuildPayload : IModifyGuildPayload +{ + /// + public Optional Name { get; init; } + + /// + public Optional VerificationLevel { get; init; } + + /// + public Optional DefaultMessageNotifications { get; init; } + + /// + public Optional ExplicitContentFilter { get; init; } + + /// + public Optional AfkChannelId { get; init; } + + /// + public Optional AfkTimeout { get; init; } + + /// + public Optional Icon { get; init; } + + /// + public Optional OwnerId { get; init; } + + /// + public Optional Splash { get; init; } + + /// + public Optional DiscoverySplash { get; init; } + + /// + public Optional Banner { get; init; } + + /// + public Optional SystemChannelId { get; init; } + + /// + public Optional SystemChannelFlags { get; init; } + + /// + public Optional RulesChannelId { get; init; } + + /// + public Optional PublicUpdatesChannelId { get; init; } + + /// + public Optional PreferredLocale { get; init; } + + /// + public Optional> Features { get; init; } + + /// + public Optional Description { get; init; } + + /// + public Optional PremiumProgressBarEnabled { get; init; } + + /// + public Optional SafetyAlertsChannelId { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyGuildRolePayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyGuildRolePayload.cs new file mode 100644 index 0000000000..7cbfb6369a --- /dev/null +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyGuildRolePayload.cs @@ -0,0 +1,33 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Rest.Payloads; + +namespace DSharpPlus.Internal.Rest.Payloads; + +/// +public sealed record ModifyGuildRolePayload : IModifyGuildRolePayload +{ + /// + public Optional Name { get; init; } + + /// + public Optional Permissions { get; init; } + + /// + public Optional Color { get; init; } + + /// + public Optional Hoist { get; init; } + + /// + public Optional Icon { get; init; } + + /// + public Optional UnicodeEmoji { get; init; } + + /// + public Optional Mentionable { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyGuildRolePositionsPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyGuildRolePositionsPayload.cs new file mode 100644 index 0000000000..2e717a3d5e --- /dev/null +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyGuildRolePositionsPayload.cs @@ -0,0 +1,17 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Internal.Abstractions.Rest.Payloads; + +namespace DSharpPlus.Internal.Rest.Payloads; + +/// +public sealed record ModifyGuildRolePositionsPayload : IModifyGuildRolePositionsPayload +{ + /// + public required Snowflake Id { get; init; } + + /// + public Optional Position { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyGuildWelcomeScreenPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyGuildWelcomeScreenPayload.cs new file mode 100644 index 0000000000..234267ae01 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyGuildWelcomeScreenPayload.cs @@ -0,0 +1,23 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Internal.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Rest.Payloads; + +namespace DSharpPlus.Internal.Rest.Payloads; + +/// +public sealed record ModifyGuildWelcomeScreenPayload : IModifyGuildWelcomeScreenPayload +{ + /// + public Optional Enabled { get; init; } + + /// + public Optional?> WelcomeChannels { get; init; } + + /// + public Optional Description { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyUserVoiceStatePayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyUserVoiceStatePayload.cs new file mode 100644 index 0000000000..aaf8c9c3f4 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyUserVoiceStatePayload.cs @@ -0,0 +1,17 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Internal.Abstractions.Rest.Payloads; + +namespace DSharpPlus.Internal.Rest.Payloads; + +/// +public sealed record ModifyUserVoiceStatePayload : IModifyUserVoiceStatePayload +{ + /// + public required Snowflake ChannelId { get; init; } + + /// + public Optional Suppress { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Interactions/CreateFollowupMessagePayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Interactions/CreateFollowupMessagePayload.cs new file mode 100644 index 0000000000..769fc846aa --- /dev/null +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Interactions/CreateFollowupMessagePayload.cs @@ -0,0 +1,39 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Rest.Payloads; + +namespace DSharpPlus.Internal.Rest.Payloads; + +/// +public sealed record CreateFollowupMessagePayload : ICreateFollowupMessagePayload +{ + /// + public Optional Content { get; init; } + + /// + public Optional Tts { get; init; } + + /// + public Optional> Embeds { get; init; } + + /// + public Optional AllowedMentions { get; init; } + + /// + public Optional> Components { get; init; } + + /// + public IReadOnlyList? Files { get; init; } + + /// + public Optional> Attachments { get; init; } + + /// + public Optional Flags { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Interactions/EditFollowupMessagePayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Interactions/EditFollowupMessagePayload.cs new file mode 100644 index 0000000000..e2622e3ed3 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Interactions/EditFollowupMessagePayload.cs @@ -0,0 +1,32 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Internal.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Rest.Payloads; + +namespace DSharpPlus.Internal.Rest.Payloads; + +/// +public sealed record EditFollowupMessagePayload : IEditFollowupMessagePayload +{ + /// + public Optional Content { get; init; } + + /// + public Optional?> Embeds { get; init; } + + /// + public Optional AllowedMentions { get; init; } + + /// + public Optional?> Components { get; init; } + + /// + public Optional?> Attachments { get; init; } + + /// + public IReadOnlyList? Files { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Interactions/EditInteractionResponsePayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Interactions/EditInteractionResponsePayload.cs new file mode 100644 index 0000000000..4d3f44d2f1 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Interactions/EditInteractionResponsePayload.cs @@ -0,0 +1,32 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Internal.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Rest.Payloads; + +namespace DSharpPlus.Internal.Rest.Payloads; + +/// +public sealed record EditInteractionResponsePayload : IEditInteractionResponsePayload +{ + /// + public Optional Content { get; init; } + + /// + public Optional?> Embeds { get; init; } + + /// + public Optional AllowedMentions { get; init; } + + /// + public Optional?> Components { get; init; } + + /// + public Optional?> Attachments { get; init; } + + /// + public IReadOnlyList? Files { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/ScheduledEvents/CreateGuildScheduledEventPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/ScheduledEvents/CreateGuildScheduledEventPayload.cs new file mode 100644 index 0000000000..878f4cff20 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/ScheduledEvents/CreateGuildScheduledEventPayload.cs @@ -0,0 +1,42 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; + +using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Rest.Payloads; + +namespace DSharpPlus.Internal.Rest.Payloads; + +/// +public sealed record CreateGuildScheduledEventPayload : ICreateGuildScheduledEventPayload +{ + /// + public Optional ChannelId { get; init; } + + /// + public Optional EntityMetadata { get; init; } + + /// + public required string Name { get; init; } + + /// + public required DiscordScheduledEventPrivacyLevel PrivacyLevel { get; init; } + + /// + public required DateTimeOffset ScheduledStartTime { get; init; } + + /// + public Optional ScheduledEndTime { get; init; } + + /// + public Optional Description { get; init; } + + /// + public required DiscordScheduledEventType EntityType { get; init; } + + /// + public Optional Image { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/ScheduledEvents/ModifyGuildScheduledEventPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/ScheduledEvents/ModifyGuildScheduledEventPayload.cs new file mode 100644 index 0000000000..6ffa92f810 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/ScheduledEvents/ModifyGuildScheduledEventPayload.cs @@ -0,0 +1,45 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; + +using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Rest.Payloads; + +namespace DSharpPlus.Internal.Rest.Payloads; + +/// +public sealed record ModifyGuildScheduledEventPayload : IModifyGuildScheduledEventPayload +{ + /// + public Optional ChannelId { get; init; } + + /// + public Optional EntityMetadata { get; init; } + + /// + public Optional Name { get; init; } + + /// + public Optional PrivacyLevel { get; init; } + + /// + public Optional ScheduledStartTime { get; init; } + + /// + public Optional ScheduledEndTime { get; init; } + + /// + public Optional Description { get; init; } + + /// + public Optional EntityType { get; init; } + + /// + public Optional Status { get; init; } + + /// + public Optional Image { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/StageInstances/CreateStageInstancePayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/StageInstances/CreateStageInstancePayload.cs new file mode 100644 index 0000000000..0439844832 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/StageInstances/CreateStageInstancePayload.cs @@ -0,0 +1,27 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Rest.Payloads; + +namespace DSharpPlus.Internal.Rest.Payloads; + +/// +public sealed record CreateStageInstancePayload : ICreateStageInstancePayload +{ + /// + public required Snowflake ChannelId { get; init; } + + /// + public required string Topic { get; init; } + + /// + public Optional PrivacyLevel { get; init; } + + /// + public Optional SendStartNotification { get; init; } + + /// + public Optional GuildScheduledEventId { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/StageInstances/ModifyStageInstancePayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/StageInstances/ModifyStageInstancePayload.cs new file mode 100644 index 0000000000..0f3bf6b5fa --- /dev/null +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/StageInstances/ModifyStageInstancePayload.cs @@ -0,0 +1,18 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Rest.Payloads; + +namespace DSharpPlus.Internal.Rest.Payloads; + +/// +public sealed record ModifyStageInstancePayload : IModifyStageInstancePayload +{ + /// + public Optional Topic { get; init; } + + /// + public Optional PrivacyLevel { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Stickers/CreateGuildStickerPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Stickers/CreateGuildStickerPayload.cs new file mode 100644 index 0000000000..29cbbfe5af --- /dev/null +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Stickers/CreateGuildStickerPayload.cs @@ -0,0 +1,23 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Internal.Abstractions.Rest.Payloads; + +namespace DSharpPlus.Internal.Rest.Payloads; + +/// +public sealed record CreateGuildStickerPayload : ICreateGuildStickerPayload +{ + /// + public required string Name { get; init; } + + /// + public required string Description { get; init; } + + /// + public required string Tags { get; init; } + + /// + public required AttachmentData File { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Stickers/ModifyGuildStickerPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Stickers/ModifyGuildStickerPayload.cs new file mode 100644 index 0000000000..7eb3d43cbb --- /dev/null +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Stickers/ModifyGuildStickerPayload.cs @@ -0,0 +1,20 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Internal.Abstractions.Rest.Payloads; + +namespace DSharpPlus.Internal.Rest.Payloads; + +/// +public sealed record ModifyGuildStickerPayload : IModifyGuildStickerPayload +{ + /// + public Optional Name { get; init; } + + /// + public Optional Description { get; init; } + + /// + public Optional Tags { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Users/CreateDmPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Users/CreateDmPayload.cs new file mode 100644 index 0000000000..7365e13813 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Users/CreateDmPayload.cs @@ -0,0 +1,14 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Internal.Abstractions.Rest.Payloads; + +namespace DSharpPlus.Internal.Rest.Payloads; + +/// +public sealed record CreateDmPayload : ICreateDmPayload +{ + /// + public required Snowflake RecipientId { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Users/CreateGroupDmPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Users/CreateGroupDmPayload.cs new file mode 100644 index 0000000000..7209c0f482 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Users/CreateGroupDmPayload.cs @@ -0,0 +1,19 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Internal.Abstractions.Rest.Payloads; + +namespace DSharpPlus.Internal.Rest.Payloads; + +/// +public sealed record CreateGroupDmPayload : ICreateGroupDmPayload +{ + /// + public required IReadOnlyList AccessTokens { get; init; } + + /// + public required IReadOnlyDictionary Nicks { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Users/ModifyCurrentUserPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Users/ModifyCurrentUserPayload.cs new file mode 100644 index 0000000000..7c4678433e --- /dev/null +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Users/ModifyCurrentUserPayload.cs @@ -0,0 +1,17 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Internal.Abstractions.Rest.Payloads; + +namespace DSharpPlus.Internal.Rest.Payloads; + +/// +public sealed record ModifyCurrentUserPayload : IModifyCurrentUserPayload +{ + /// + public Optional Username { get; init; } + + /// + public Optional Avatar { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Users/UpdateCurrentUserApplicationRoleConnectionPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Users/UpdateCurrentUserApplicationRoleConnectionPayload.cs new file mode 100644 index 0000000000..3e9e8bbce6 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Users/UpdateCurrentUserApplicationRoleConnectionPayload.cs @@ -0,0 +1,20 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Internal.Abstractions.Rest.Payloads; + +namespace DSharpPlus.Internal.Rest.Payloads; + +/// +public sealed record UpdateCurrentUserApplicationRoleConnectionPayload : IUpdateCurrentUserApplicationRoleConnectionPayload +{ + /// + public Optional PlatformName { get; init; } + + /// + public Optional PlatformUsername { get; init; } + + /// + public Optional Metadata { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Webhooks/CreateWebhookPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Webhooks/CreateWebhookPayload.cs new file mode 100644 index 0000000000..29f2f2e959 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Webhooks/CreateWebhookPayload.cs @@ -0,0 +1,17 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Internal.Abstractions.Rest.Payloads; + +namespace DSharpPlus.Internal.Rest.Payloads; + +/// +public sealed record CreateWebhookPayload : ICreateWebhookPayload +{ + /// + public required string Name { get; init; } + + /// + public Optional Avatar { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Webhooks/EditWebhookMessagePayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Webhooks/EditWebhookMessagePayload.cs new file mode 100644 index 0000000000..cbd3db2f6a --- /dev/null +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Webhooks/EditWebhookMessagePayload.cs @@ -0,0 +1,32 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Internal.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Rest.Payloads; + +namespace DSharpPlus.Internal.Rest.Payloads; + +/// +public sealed record EditWebhookMessagePayload : IEditWebhookMessagePayload +{ + /// + public Optional Content { get; init; } + + /// + public Optional?> Embeds { get; init; } + + /// + public Optional AllowedMentions { get; init; } + + /// + public Optional?> Components { get; init; } + + /// + public IReadOnlyList? Files { get; init; } + + /// + public Optional?> Attachments { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Webhooks/ExecuteWebhookPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Webhooks/ExecuteWebhookPayload.cs new file mode 100644 index 0000000000..d5c7c872e0 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Webhooks/ExecuteWebhookPayload.cs @@ -0,0 +1,51 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Rest.Payloads; + +namespace DSharpPlus.Internal.Rest.Payloads; + +/// +public sealed record ExecuteWebhookPayload : IExecuteWebhookPayload +{ + /// + public Optional Content { get; init; } + + /// + public Optional Username { get; init; } + + /// + public Optional AvatarUrl { get; init; } + + /// + public Optional Tts { get; init; } + + /// + public Optional> Embeds { get; init; } + + /// + public Optional AllowedMentions { get; init; } + + /// + public Optional> Components { get; init; } + + /// + public IReadOnlyList? Files { get; init; } + + /// + public Optional> Attachments { get; init; } + + /// + public Optional Flags { get; init; } + + /// + public Optional ThreadName { get; init; } + + /// + public Optional> AppliedTags { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Webhooks/ModifyWebhookPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Webhooks/ModifyWebhookPayload.cs new file mode 100644 index 0000000000..574247327d --- /dev/null +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Webhooks/ModifyWebhookPayload.cs @@ -0,0 +1,20 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Internal.Abstractions.Rest.Payloads; + +namespace DSharpPlus.Internal.Rest.Payloads; + +/// +public sealed record ModifyWebhookPayload : IModifyWebhookPayload +{ + /// + public Optional Name { get; init; } + + /// + public Optional Avatar { get; init; } + + /// + public Optional ChannelId { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Webhooks/ModifyWebhookWithTokenPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Webhooks/ModifyWebhookWithTokenPayload.cs new file mode 100644 index 0000000000..fa1bc16abc --- /dev/null +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Webhooks/ModifyWebhookWithTokenPayload.cs @@ -0,0 +1,17 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Internal.Abstractions.Rest.Payloads; + +namespace DSharpPlus.Internal.Rest.Payloads; + +/// +public sealed record ModifyWebhookWithTokenPayload : IModifyWebhookWithTokenPayload +{ + /// + public Optional Name { get; init; } + + /// + public Optional Avatar { get; init; } +} \ No newline at end of file diff --git a/tools/generators/generate-rest-payloads.csx b/tools/generators/generate-rest-payloads.csx new file mode 100644 index 0000000000..f046baa397 --- /dev/null +++ b/tools/generators/generate-rest-payloads.csx @@ -0,0 +1,276 @@ +#!/usr/bin/env dotnet-script + +#nullable enable + +#r "nuget:Microsoft.CodeAnalysis.CSharp, 4.8.0-2.final" +#r "nuget:Spectre.Console, 0.47.1-preview.0.26" + +#load "../incremental-utility.csx" +#load "./parse-interface.csx" + +using System; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading; + +using Spectre.Console; + +// Syntax: +// generate-rest-payloads [abstraction path] [output path] +if (Args is ["-h" or "--help" or "-?"]) +{ + AnsiConsole.MarkupLine + ( + """ + [plum1]DSharpPlus Rest Payload Generator, v0.1.0[/] + + Usage: generate-rest-payloads.csx [[abstraction root path]] [[output root path]] + """ + ); + + return 0; +} + +AnsiConsole.MarkupLine +( + """ + [plum1]DSharpPlus Rest Payload Generator, v0.1.0[/] + """ +); + +string input, output; + +// there are no args passed, proceed with default args: +// args[0] = src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads +// args[1] = src/core/DSharpPlus.Internal.Rest/Payloads +if (Args.Count == 0) +{ + input = "src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads"; + output = "src/core/DSharpPlus.Internal.Rest/Payloads"; +} + +// there are args passed, which override the given instructions +// validate the passed arguments are correct +else if (Args.Any(path => !Directory.Exists(path))) +{ + AnsiConsole.MarkupLine + ( + """ + [red]The paths provided could not be found on the file system.[/] + """ + ); + + return 1; +} + +// all args are fine +else +{ + input = Args[0]; + output = Args[1]; +} + +string[] files = Directory.GetFiles(input, "I*.cs", SearchOption.AllDirectories); + +files = files + .Select + ( + path => + { + FileInfo file = new(path); + return file.FullName.Replace('\\', '/'); + } + ) + .ToArray(); + +Changes changes = GetFileChanges("generate-rest-payloads", files); + +if (!changes.Added.Any() && !changes.Modified.Any() && !changes.Removed.Any()) +{ + AnsiConsole.MarkupLine + ( + """ + [darkseagreen1_1]There were no changes to the interface definitions, exiting generate-rest-payloads.[/] + """ + ); + + return 0; +} + +AnsiConsole.MarkupLine +( + $""" + {changes.Added.Count} added, {changes.Modified.Count} modified, {changes.Removed.Count} removed. + """ +); + +if (changes.Removed.Any()) +{ + AnsiConsole.MarkupLine("Deleting counterparts to removed files..."); + + Parallel.ForEach + ( + changes.Removed, + path => + { + int index = path.LastIndexOf('/'); + string deletePath = path.Remove(index + 1, 1).Replace(input, output); + + AnsiConsole.MarkupLine($" Deleting '{deletePath}'..."); + + if (File.Exists(deletePath)) + { + File.Delete(deletePath); + } + } + ); +} + +if (changes.Added.Any() || changes.Modified.Any()) +{ + AnsiConsole.MarkupLine("Generating objects for modified/new definitions..."); +} + +IEnumerable added = changes.Added.Select +( + file => + { + FileInfo info = new(file); + return info.FullName.Replace('\\', '/'); + } +); + +IEnumerable modified = changes.Modified.Select +( + file => + { + FileInfo info = new(file); + return info.FullName.Replace('\\', '/'); + } +); + +IEnumerable editedFiles = added.Concat(modified); +List collectedMetadata = editedFiles + .AsParallel() + .Select(path => ParseInterface(path, input)) + .Where(meta => meta is not null) + .Cast() + .AsEnumerable() + .ToList(); + +for (int i = 0; i < collectedMetadata.Count; i++) +{ + InterfaceMetadata metadata = collectedMetadata[i]; + + int index = metadata.Path.LastIndexOf('/'); + string outputPath = metadata.Path.Remove(index + 1, 1).Replace(input, output); + + FileInfo info = new(outputPath); + + if (!Directory.Exists(info.DirectoryName!)) + { + Directory.CreateDirectory(info.DirectoryName!); + } + + StringBuilder writer = new(); + + AnsiConsole.MarkupLine($" Generating '{outputPath}'..."); + + writer.AppendLine + ( + """ + // This Source Code form is subject to the terms of the Mozilla Public + // License, v. 2.0. If a copy of the MPL was not distributed with this + // file, You can obtain one at https://mozilla.org/MPL/2.0/. + + """ + ); + + // we specifically want the grouping here, that's how we group usings together + // this doesn't currently handle using statics, but it doesn't need to just yet + // + // sorting system directives first is annoying, and not strictly necessary, but we want to do it anyway + // we're going to employ a hack and return "!" as the key if it's a system using, which is higher than any + // legal namespace name + IEnumerable> groupedUsings = metadata.UsingDirectives! + .Append("using DSharpPlus.Internal.Abstractions.Rest.Payloads;") + .Distinct() + .GroupBy + ( + directive => + { + int index = directive.IndexOf('.'); + int semicolonIndex = directive.IndexOf(';'); + return directive[..(index != -1 ? index : semicolonIndex)]; + } + ) + .OrderBy + ( + group => + { + if (group.First().StartsWith("using System")) + { + return "!"; + } + else + { + string directive = group.First(); + + int index = directive.IndexOf('.'); + int semicolonIndex = directive.IndexOf(';'); + return directive[..(index != -1 ? index : semicolonIndex)]; + } + }, + StringComparer.Ordinal + ); + + foreach(IGrouping group in groupedUsings) + { + writer.AppendLine + ( + $""" + {string.Join('\n', group.OrderBy(name => name))} + + """ + ); + } + + writer.AppendLine + ( + $$""" + namespace DSharpPlus.Internal.Rest.Payloads; + + /// + public sealed record {{metadata.Name[1..]}} : {{metadata.Name}} + { + """ + ); + + InterfaceMetadata principal = metadata.PartialParent ?? metadata; + + foreach (PropertyMetadata property in principal.Properties!) + { + bool required = !(property.IsOptional || property.IsNullable); + string type = property.Type; + + writer.AppendLine + ( + $$""" + /// + public {{(required ? "required " : "")}}{{type}} {{property.Name}} { get; init; } + + """ + ); + } + + writer.Append('}'); + + string code = writer.ToString(); + + code = code.Remove(code.Length - Environment.NewLine.Length - 1, Environment.NewLine.Length); + + File.WriteAllText(outputPath, code); +} + +return 0; \ No newline at end of file From b4741222d4d3771c56a6b1442c69c0b7bce7f95c Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Tue, 2 Jan 2024 14:22:05 +0100 Subject: [PATCH 244/323] add modal and text input builders --- meta/builder-concrete-types.json | 6 +- ...rpPlus.Extensions.Internal.Builders.csproj | 1 + .../BuiltActionRowComponent.cs | 20 ++ .../BuiltInteractionResponse.cs | 20 ++ .../Implementations/BuiltModalCallbackData.cs | 22 ++ .../BuiltTextInputComponent.cs | 39 +++ .../Interactions/ModalBuilder.cs | 151 +++++++++++ .../Interactions/TextInputComponentBuilder.cs | 249 ++++++++++++++++++ .../Messages/EmbedBuilder.cs | 3 + .../generators/generate-concrete-objects.csx | 2 +- 10 files changed, 511 insertions(+), 2 deletions(-) create mode 100644 src/extensions/DSharpPlus.Extensions.Internal.Builders/Implementations/BuiltActionRowComponent.cs create mode 100644 src/extensions/DSharpPlus.Extensions.Internal.Builders/Implementations/BuiltInteractionResponse.cs create mode 100644 src/extensions/DSharpPlus.Extensions.Internal.Builders/Implementations/BuiltModalCallbackData.cs create mode 100644 src/extensions/DSharpPlus.Extensions.Internal.Builders/Implementations/BuiltTextInputComponent.cs create mode 100644 src/extensions/DSharpPlus.Extensions.Internal.Builders/Interactions/ModalBuilder.cs create mode 100644 src/extensions/DSharpPlus.Extensions.Internal.Builders/Interactions/TextInputComponentBuilder.cs diff --git a/meta/builder-concrete-types.json b/meta/builder-concrete-types.json index 76e5177f1a..2af3c009e8 100644 --- a/meta/builder-concrete-types.json +++ b/meta/builder-concrete-types.json @@ -1,3 +1,7 @@ [ - "./src/core/DSharpPlus.Internal.Models/Channels/Embed.cs" + "./src/core/DSharpPlus.Internal.Models/Channels/Embed.cs", + "./src/core/DSharpPlus.Internal.Models/Interactions/InteractionResponse.cs", + "./src/core/DSharpPlus.Internal.Models/Interactions/ModalCallbackData.cs", + "./src/core/DSharpPlus.Internal.Models/MessageComponents/ActionRowComponent.cs", + "./src/core/DSharpPlus.Internal.Models/MessageComponents/TextInputComponent.cs" ] \ No newline at end of file diff --git a/src/extensions/DSharpPlus.Extensions.Internal.Builders/DSharpPlus.Extensions.Internal.Builders.csproj b/src/extensions/DSharpPlus.Extensions.Internal.Builders/DSharpPlus.Extensions.Internal.Builders.csproj index 5fffcb91a7..556c492afe 100644 --- a/src/extensions/DSharpPlus.Extensions.Internal.Builders/DSharpPlus.Extensions.Internal.Builders.csproj +++ b/src/extensions/DSharpPlus.Extensions.Internal.Builders/DSharpPlus.Extensions.Internal.Builders.csproj @@ -14,6 +14,7 @@ + diff --git a/src/extensions/DSharpPlus.Extensions.Internal.Builders/Implementations/BuiltActionRowComponent.cs b/src/extensions/DSharpPlus.Extensions.Internal.Builders/Implementations/BuiltActionRowComponent.cs new file mode 100644 index 0000000000..787d50e3ae --- /dev/null +++ b/src/extensions/DSharpPlus.Extensions.Internal.Builders/Implementations/BuiltActionRowComponent.cs @@ -0,0 +1,20 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; + +namespace DSharpPlus.Extensions.Internal.Builders.Implementations; + +/// +internal sealed record BuiltActionRowComponent : IActionRowComponent +{ + /// + public required DiscordMessageComponentType Type { get; init; } + + /// + public required IReadOnlyList Components { get; init; } +} \ No newline at end of file diff --git a/src/extensions/DSharpPlus.Extensions.Internal.Builders/Implementations/BuiltInteractionResponse.cs b/src/extensions/DSharpPlus.Extensions.Internal.Builders/Implementations/BuiltInteractionResponse.cs new file mode 100644 index 0000000000..67ef92edf2 --- /dev/null +++ b/src/extensions/DSharpPlus.Extensions.Internal.Builders/Implementations/BuiltInteractionResponse.cs @@ -0,0 +1,20 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; + +using OneOf; + +namespace DSharpPlus.Extensions.Internal.Builders.Implementations; + +/// +internal sealed record BuiltInteractionResponse : IInteractionResponse +{ + /// + public required DiscordInteractionCallbackType Type { get; init; } + + /// + public Optional> Data { get; init; } +} \ No newline at end of file diff --git a/src/extensions/DSharpPlus.Extensions.Internal.Builders/Implementations/BuiltModalCallbackData.cs b/src/extensions/DSharpPlus.Extensions.Internal.Builders/Implementations/BuiltModalCallbackData.cs new file mode 100644 index 0000000000..9614bbf91c --- /dev/null +++ b/src/extensions/DSharpPlus.Extensions.Internal.Builders/Implementations/BuiltModalCallbackData.cs @@ -0,0 +1,22 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Internal.Abstractions.Models; + +namespace DSharpPlus.Extensions.Internal.Builders.Implementations; + +/// +internal sealed record BuiltModalCallbackData : IModalCallbackData +{ + /// + public required string CustomId { get; init; } + + /// + public required string Title { get; init; } + + /// + public required IReadOnlyList Components { get; init; } +} \ No newline at end of file diff --git a/src/extensions/DSharpPlus.Extensions.Internal.Builders/Implementations/BuiltTextInputComponent.cs b/src/extensions/DSharpPlus.Extensions.Internal.Builders/Implementations/BuiltTextInputComponent.cs new file mode 100644 index 0000000000..f812b1c8ee --- /dev/null +++ b/src/extensions/DSharpPlus.Extensions.Internal.Builders/Implementations/BuiltTextInputComponent.cs @@ -0,0 +1,39 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; + +namespace DSharpPlus.Extensions.Internal.Builders.Implementations; + +/// +internal sealed record BuiltTextInputComponent : ITextInputComponent +{ + /// + public required DiscordMessageComponentType Type { get; init; } + + /// + public required string CustomId { get; init; } + + /// + public required DiscordTextInputStyle Style { get; init; } + + /// + public required string Label { get; init; } + + /// + public Optional MinLength { get; init; } + + /// + public Optional MaxLength { get; init; } + + /// + public Optional Required { get; init; } + + /// + public Optional Value { get; init; } + + /// + public Optional Placeholder { get; init; } +} \ No newline at end of file diff --git a/src/extensions/DSharpPlus.Extensions.Internal.Builders/Interactions/ModalBuilder.cs b/src/extensions/DSharpPlus.Extensions.Internal.Builders/Interactions/ModalBuilder.cs new file mode 100644 index 0000000000..12d1759f66 --- /dev/null +++ b/src/extensions/DSharpPlus.Extensions.Internal.Builders/Interactions/ModalBuilder.cs @@ -0,0 +1,151 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +#pragma warning disable IDE0046 + +using System; +using System.Collections.Generic; +using System.Linq; +using DSharpPlus.Entities; +using DSharpPlus.Extensions.Internal.Builders.Errors; +using DSharpPlus.Extensions.Internal.Builders.Implementations; +using DSharpPlus.Internal.Abstractions.Models; + +using OneOf; + +using Remora.Results; + +namespace DSharpPlus.Extensions.Internal.Builders.Interactions; + +/// +/// Represents a modal under construction. +/// +public record struct ModalBuilder +{ + /// + public string? CustomId { get; set; } + + /// + public string? Title { get; set; } + + /// + public IReadOnlyList? Components { get; set; } +} + +public static class ModalBuilderExtensions +{ + /// + /// Sets the custom ID of the modal. + /// + /// The modal builder for chaining. + public static ref ModalBuilder WithCustomId(ref this ModalBuilder builder, string customId) + { + builder.CustomId = customId; + return ref builder; + } + + /// + /// Sets the title of the modal. + /// + /// The modal builder for chaining. + public static ref ModalBuilder WithTitle(ref this ModalBuilder builder, string title) + { + builder.Title = title; + return ref builder; + } + + /// + /// Adds a text input component to the modal. + /// + /// The modal builder for chaining. + public static ref ModalBuilder AddComponent(ref this ModalBuilder builder, ITextInputComponent component) + { + if (builder.Components is null) + { + builder.Components = [component]; + return ref builder; + } + + builder.Components = [..builder.Components, component]; + return ref builder; + } + + /// + /// Verifies whether the modal builder can be transformed into a valid modal. + /// + public static Result Validate(ref this ModalBuilder builder) + { + List<(string, string)> errors = []; + + if (builder.CustomId is null) + { + errors.Add((nameof(builder.CustomId), "The custom ID of a modal must be provided.")); + } + else if (builder.CustomId.Length > 100) + { + errors.Add((nameof(builder.CustomId), "A custom ID cannot exceed 100 characters in length.")); + } + + if (builder.Title is null) + { + errors.Add((nameof(builder.Title), "The title of a modal must be provided.")); + } + else if (builder.Title.Length > 45) + { + errors.Add((nameof(builder.CustomId), "A modal title cannot exceed 45 characters in length.")); + } + + if (builder.Components is null || builder.Components.Count is not >= 1 and <= 5) + { + errors.Add((nameof(builder.Components), "There must be between one and five components provided.")); + } + + if (errors is not []) + { + return new BuilderValidationError + ( + "Some modal fields were invalid. See the attached dictionary for further information.", + errors.ToArray() + ); + } + else + { + return Result.Success; + } + } + + /// + /// Builds the modal. This does not enforce validity, past enforcing all fields are present. + /// + public static IInteractionResponse Build(ref this ModalBuilder builder) + { + ArgumentNullException.ThrowIfNull(builder.Title); + ArgumentNullException.ThrowIfNull(builder.CustomId); + ArgumentNullException.ThrowIfNull(builder.Components); + + return new BuiltInteractionResponse + { + Type = DiscordInteractionCallbackType.Modal, + Data = OneOf.FromT2 + ( + new BuiltModalCallbackData + { + Title = builder.Title, + CustomId = builder.CustomId, + Components = builder.Components.Select + ( + x => + { + return new BuiltActionRowComponent + { + Type = DiscordMessageComponentType.ActionRow, + Components = [x] + }; + } + ).ToArray() + } + ) + }; + } +} \ No newline at end of file diff --git a/src/extensions/DSharpPlus.Extensions.Internal.Builders/Interactions/TextInputComponentBuilder.cs b/src/extensions/DSharpPlus.Extensions.Internal.Builders/Interactions/TextInputComponentBuilder.cs new file mode 100644 index 0000000000..d254fe17f0 --- /dev/null +++ b/src/extensions/DSharpPlus.Extensions.Internal.Builders/Interactions/TextInputComponentBuilder.cs @@ -0,0 +1,249 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +#pragma warning disable IDE0046 + +using System; +using System.Collections.Generic; + +using DSharpPlus.Entities; +using DSharpPlus.Extensions.Internal.Builders.Errors; +using DSharpPlus.Extensions.Internal.Builders.Implementations; +using DSharpPlus.Internal.Abstractions.Models; + +using Remora.Results; + +namespace DSharpPlus.Extensions.Internal.Builders.Interactions; + +/// +/// Represents a under construction. +/// +public record struct TextInputComponentBuilder +{ + /// + public string? CustomId { get; set; } + + /// + public DiscordTextInputStyle? Style { get; set; } + + /// + public string? Label { get; set; } + + /// + public Optional MinLength { get; set; } + + /// + public Optional MaxLength { get; set; } + + /// + public Optional Required { get; set; } + + /// + public Optional Placeholder { get; set; } + + /// + public Optional Value { get; set; } +} + +public static class TextInputComponentBuilderExtensions +{ + /// + /// Sets the custom ID of the component for later identification. + /// + /// The component builder for chaining. + public static ref TextInputComponentBuilder WithCustomId + ( + ref this TextInputComponentBuilder builder, + string customId + ) + { + builder.CustomId = customId; + return ref builder; + } + + /// + /// Sets the style of the component. + /// + /// The component builder for chaining. + public static ref TextInputComponentBuilder WithStyle + ( + ref this TextInputComponentBuilder builder, + DiscordTextInputStyle style + ) + { + builder.Style = style; + return ref builder; + } + + /// + /// Sets the label of the component. + /// + /// The component builder for chaining. + public static ref TextInputComponentBuilder WithLabel + ( + ref this TextInputComponentBuilder builder, + string label + ) + { + builder.Label = label; + return ref builder; + } + + /// + /// Sets the minimum length of the text the user is required to put in. + /// + /// The component builder for chaining. + public static ref TextInputComponentBuilder WithMinLength + ( + ref this TextInputComponentBuilder builder, + int minLength + ) + { + builder.MinLength = minLength; + return ref builder; + } + + /// + /// Sets the maximum length of the text the user is required to put in. + /// + /// The component builder for chaining. + public static ref TextInputComponentBuilder WithMaxLength + ( + ref this TextInputComponentBuilder builder, + int maxLength + ) + { + builder.MaxLength = maxLength; + return ref builder; + } + + /// + /// Sets whether this input component is required to be filled. + /// + /// The component builder for chaining. + public static ref TextInputComponentBuilder SetRequired + ( + ref this TextInputComponentBuilder builder, + bool required = true + ) + { + builder.Required = required; + return ref builder; + } + + /// + /// Sets the placeholder value of this component. + /// + /// The component builder for chaining. + public static ref TextInputComponentBuilder WithPlaceholder + ( + ref this TextInputComponentBuilder builder, + string placeholder + ) + { + builder.Placeholder = placeholder; + return ref builder; + } + + /// + /// Sets the default value of this component. + /// + /// The component builder for chaining. + public static ref TextInputComponentBuilder WithValue + ( + ref this TextInputComponentBuilder builder, + string value + ) + { + builder.Value = value; + return ref builder; + } + + /// + /// Validates whether the builder can be converted into a legal component. + /// + public static Result Validate(ref this TextInputComponentBuilder builder) + { + List<(string, string)> errors = []; + + if (builder.CustomId is null) + { + errors.Add((nameof(builder.CustomId), "The custom ID of a text input component must be provided.")); + } + else if (builder.CustomId.Length > 100) + { + errors.Add((nameof(builder.CustomId), "A custom ID cannot exceed 100 characters in length.")); + } + + if (builder.Style is null) + { + errors.Add((nameof(builder.Style), "The style of a text input component must be provided.")); + } + + if (builder.Label is null) + { + errors.Add((nameof(builder.Label), "The label of a text input component must be provided")); + } + else if (builder.Label.Length > 45) + { + errors.Add((nameof(builder.Label), "A text input component's label cannot exceed 45 characters in length.")); + } + + if (builder.MinLength.HasValue && builder.MinLength.Value is not > 0 and < 4000) + { + errors.Add((nameof(builder.MinLength), "The minimum length must be between 0 and 4000.")); + } + + if (builder.MaxLength.HasValue && builder.MaxLength.Value is not > 1 and < 4000) + { + errors.Add((nameof(builder.MaxLength), "The maximum length must be between 1 and 4000.")); + } + + if (builder.Placeholder.HasValue && builder.Placeholder.Value!.Length > 100) + { + errors.Add((nameof(builder.Placeholder), "A placeholder cannot exceed 100 characters in length.")); + } + + if (builder.Value.HasValue && builder.Value.Value!.Length > 4000) + { + errors.Add((nameof(builder.Value), "The default value cannot exceed 4000 characters in length.")); + } + + if (errors is not []) + { + return new BuilderValidationError + ( + "Some component fields were invalid. See the attached dictionary for further information.", + errors.ToArray() + ); + } + else + { + return Result.Success; + } + } + + /// + /// Builds the text input component. This does not enforce validity, past enforcing all fields are present. + /// + public static ITextInputComponent Build(ref this TextInputComponentBuilder builder) + { + ArgumentNullException.ThrowIfNull(builder.CustomId); + ArgumentNullException.ThrowIfNull(builder.Label); + ArgumentNullException.ThrowIfNull(builder.Style); + + return new BuiltTextInputComponent + { + Type = DiscordMessageComponentType.TextInput, + CustomId = builder.CustomId, + Style = builder.Style.Value, + Label = builder.Label, + MinLength = builder.MinLength, + MaxLength = builder.MaxLength, + Required = builder.Required, + Value = builder.Value, + Placeholder = builder.Placeholder + }; + } +} \ No newline at end of file diff --git a/src/extensions/DSharpPlus.Extensions.Internal.Builders/Messages/EmbedBuilder.cs b/src/extensions/DSharpPlus.Extensions.Internal.Builders/Messages/EmbedBuilder.cs index af746b6cca..998e6e37a7 100644 --- a/src/extensions/DSharpPlus.Extensions.Internal.Builders/Messages/EmbedBuilder.cs +++ b/src/extensions/DSharpPlus.Extensions.Internal.Builders/Messages/EmbedBuilder.cs @@ -247,6 +247,9 @@ public static Result Validate(ref this EmbedBuilder builder) } } + /// + /// Builds the embed. This does not enforce validity. + /// public static IEmbed Build(ref this EmbedBuilder builder) { return new BuiltEmbed diff --git a/tools/generators/generate-concrete-objects.csx b/tools/generators/generate-concrete-objects.csx index 6813c42981..3b2aeca5a4 100644 --- a/tools/generators/generate-concrete-objects.csx +++ b/tools/generators/generate-concrete-objects.csx @@ -91,7 +91,7 @@ if (!changes.Added.Any() && !changes.Modified.Any() && !changes.Removed.Any()) AnsiConsole.MarkupLine ( """ - [darkseagreen1_1]There were no changes to the interface definitions, exiting generate-concrete-objects.[/] + [darkseagreen1_1]There were no changes to the specified records, exiting generate-concrete-objects.[/] """ ); From 3a74425ae171a8ffc9748059aaa08419c9749b19 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Tue, 2 Jan 2024 14:29:35 +0100 Subject: [PATCH 245/323] wrong tool name --- tools/generators/copy-concrete-implementations.csx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/generators/copy-concrete-implementations.csx b/tools/generators/copy-concrete-implementations.csx index 9fe691174d..63874ba635 100644 --- a/tools/generators/copy-concrete-implementations.csx +++ b/tools/generators/copy-concrete-implementations.csx @@ -78,7 +78,7 @@ if (!changes.Added.Any() && !changes.Modified.Any() && !changes.Removed.Any()) AnsiConsole.MarkupLine ( """ - [darkseagreen1_1]There were no changes to the interface definitions, exiting generate-concrete-objects.[/] + [darkseagreen1_1]There were no changes to the interface definitions, exiting copy-concrete-implementations.[/] """ ); From 082509b12648bc82b752de6ae95068112c55b915 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Thu, 4 Jan 2024 21:03:42 +0100 Subject: [PATCH 246/323] add a rest client abstraction too --- .../IRestClient.cs | 33 +++++++++++++++++++ .../IRestRequest.cs | 23 +++++++++++++ .../Interactions/ModalBuilder.cs | 3 +- 3 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 src/core/DSharpPlus.Internal.Abstractions.Rest/IRestClient.cs create mode 100644 src/core/DSharpPlus.Internal.Abstractions.Rest/IRestRequest.cs diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/IRestClient.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/IRestClient.cs new file mode 100644 index 0000000000..d27e5b2a16 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/IRestClient.cs @@ -0,0 +1,33 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Net.Http; +using System.Threading; +using System.Threading.Tasks; + +using Remora.Results; + +namespace DSharpPlus.Internal.Abstractions.Rest; + +/// +/// Represents the central rest client handling the requests made to Discord. +/// +public interface IRestClient +{ + /// + /// Sends a request to the Discord API. + /// + /// The concrete type of request. + /// + /// The request object. Implementers should handle all types, but may special-case well-known types. + /// + /// A cancellation token for this operation. + /// The response from Discord, or an appropriate error. + public ValueTask> ExecuteRequestAsync + ( + T request, + CancellationToken ct = default + ) + where T : IRestRequest; +} diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/IRestRequest.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/IRestRequest.cs new file mode 100644 index 0000000000..43040283ab --- /dev/null +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/IRestRequest.cs @@ -0,0 +1,23 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Net.Http; + +namespace DSharpPlus.Internal.Abstractions.Rest; + +/// +/// Represents a basic rest request to Discord. +/// +public interface IRestRequest +{ + /// + /// Gets an attached RequestInfo. + /// + public RequestInfo Info { get; } + + /// + /// Builds this request into a request message. + /// + public HttpRequestMessage Build(); +} diff --git a/src/extensions/DSharpPlus.Extensions.Internal.Builders/Interactions/ModalBuilder.cs b/src/extensions/DSharpPlus.Extensions.Internal.Builders/Interactions/ModalBuilder.cs index 12d1759f66..6c33dd8cef 100644 --- a/src/extensions/DSharpPlus.Extensions.Internal.Builders/Interactions/ModalBuilder.cs +++ b/src/extensions/DSharpPlus.Extensions.Internal.Builders/Interactions/ModalBuilder.cs @@ -7,6 +7,7 @@ using System; using System.Collections.Generic; using System.Linq; + using DSharpPlus.Entities; using DSharpPlus.Extensions.Internal.Builders.Errors; using DSharpPlus.Extensions.Internal.Builders.Implementations; @@ -148,4 +149,4 @@ public static IInteractionResponse Build(ref this ModalBuilder builder) ) }; } -} \ No newline at end of file +} From dce39b115d55c3187d49b82ca1042e515c429bd3 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sun, 7 Jan 2024 17:28:40 +0100 Subject: [PATCH 247/323] implement everything we need to start working on rest resources --- Directory.Packages.props | 2 + lib/bundles | 2 +- lib/etf | 2 +- .../IRestClient.cs | 38 ++++-- .../IRestRequest.cs | 23 ---- .../ICreateGlobalApplicationCommandPayload.cs | 6 + .../RequestBuilder.cs | 111 ++++++++++++++++++ .../API/ApplicationCommandsRestAPI.cs | 102 ++++++++++++++++ .../DSharpPlus.Internal.Rest.csproj | 9 ++ .../CreateGlobalApplicationCommandPayload.cs | 4 + .../DSharpPlus.Internal.Rest/QueryBuilder.cs | 30 +++++ .../Ratelimiting/ISimpleRatelimitRoute.cs | 13 ++ .../SimpleSnowflakeRatelimitRoute.cs | 15 +++ .../SimpleStringRatelimitRoute.cs | 21 ++++ .../Ratelimiting/TopLevelResource.cs | 16 +++ .../RequestBuilderExtensions.cs | 29 +++++ 16 files changed, 390 insertions(+), 33 deletions(-) delete mode 100644 src/core/DSharpPlus.Internal.Abstractions.Rest/IRestRequest.cs create mode 100644 src/core/DSharpPlus.Internal.Abstractions.Rest/RequestBuilder.cs create mode 100644 src/core/DSharpPlus.Internal.Rest/API/ApplicationCommandsRestAPI.cs create mode 100644 src/core/DSharpPlus.Internal.Rest/QueryBuilder.cs create mode 100644 src/core/DSharpPlus.Internal.Rest/Ratelimiting/ISimpleRatelimitRoute.cs create mode 100644 src/core/DSharpPlus.Internal.Rest/Ratelimiting/SimpleSnowflakeRatelimitRoute.cs create mode 100644 src/core/DSharpPlus.Internal.Rest/Ratelimiting/SimpleStringRatelimitRoute.cs create mode 100644 src/core/DSharpPlus.Internal.Rest/Ratelimiting/TopLevelResource.cs create mode 100644 src/core/DSharpPlus.Internal.Rest/RequestBuilderExtensions.cs diff --git a/Directory.Packages.props b/Directory.Packages.props index ae0311f80f..5f9f29af1b 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -4,11 +4,13 @@ + + diff --git a/lib/bundles b/lib/bundles index c8add31634..de83c25d01 160000 --- a/lib/bundles +++ b/lib/bundles @@ -1 +1 @@ -Subproject commit c8add31634cc6b947f69976fd873895da393312c +Subproject commit de83c25d01c22298d2bd39e5f0c58a74ac6fe168 diff --git a/lib/etf b/lib/etf index 811229da20..0423eefb10 160000 --- a/lib/etf +++ b/lib/etf @@ -1 +1 @@ -Subproject commit 811229da20fd78ec9b6bbb2eb2c734a7c5f27132 +Subproject commit 0423eefb1080c119d093a2e19772f9e37e020821 diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/IRestClient.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/IRestClient.cs index d27e5b2a16..54423411ca 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/IRestClient.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/IRestClient.cs @@ -2,6 +2,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +using System; using System.Net.Http; using System.Threading; using System.Threading.Tasks; @@ -18,16 +19,37 @@ public interface IRestClient /// /// Sends a request to the Discord API. /// - /// The concrete type of request. - /// - /// The request object. Implementers should handle all types, but may special-case well-known types. - /// + /// The type to deserialize into. + /// The HTTP method this request should be sent to. + /// The path this request will take. + /// Constructs the request to be sent to Discord. + /// Specifies additional parameters for this request. /// A cancellation token for this operation. /// The response from Discord, or an appropriate error. - public ValueTask> ExecuteRequestAsync + public ValueTask> ExecuteRequestAsync ( - T request, + HttpMethod method, + string path, + Action request, + RequestInfo info = default, CancellationToken ct = default - ) - where T : IRestRequest; + ); + + /// + /// Sends a request to the Discord API. + /// + /// The HTTP method this request should be sent to. + /// The path this request will take. + /// Constructs the request to be sent to Discord. + /// Specifies additional parameters for this request. + /// A cancellation token for this operation. + /// The response from Discord, or an appropriate error. + public ValueTask> ExecuteRequestAsync + ( + HttpMethod method, + string path, + Action request, + RequestInfo info = default, + CancellationToken ct = default + ); } diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/IRestRequest.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/IRestRequest.cs deleted file mode 100644 index 43040283ab..0000000000 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/IRestRequest.cs +++ /dev/null @@ -1,23 +0,0 @@ -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -using System.Net.Http; - -namespace DSharpPlus.Internal.Abstractions.Rest; - -/// -/// Represents a basic rest request to Discord. -/// -public interface IRestRequest -{ - /// - /// Gets an attached RequestInfo. - /// - public RequestInfo Info { get; } - - /// - /// Builds this request into a request message. - /// - public HttpRequestMessage Build(); -} diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/ApplicationCommands/ICreateGlobalApplicationCommandPayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/ApplicationCommands/ICreateGlobalApplicationCommandPayload.cs index 0cadaa6d6d..34d13fc23a 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/ApplicationCommands/ICreateGlobalApplicationCommandPayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/ApplicationCommands/ICreateGlobalApplicationCommandPayload.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; namespace DSharpPlus.Internal.Abstractions.Rest.Payloads; @@ -33,6 +34,11 @@ public interface ICreateGlobalApplicationCommandPayload /// public Optional?> DescriptionLocalizations { get; } + /// + /// Up to 25 parameters for this comand, or its subcommands. + /// + public Optional> Options { get; } + /// /// The default permissions needed to see this command. /// diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/RequestBuilder.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/RequestBuilder.cs new file mode 100644 index 0000000000..f5dfeefc08 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/RequestBuilder.cs @@ -0,0 +1,111 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +#pragma warning disable CA2227 + +using System.Collections.Generic; + +namespace DSharpPlus.Internal.Abstractions.Rest; + +/// +/// Provides an user-friendly way to build a rest request to Discord. +/// +public class RequestBuilder +{ + /// + /// The audit log reason for Discord, if applicable. + /// + public string? AuditLogReason { get; set; } + + /// + /// The payload to send to discord. + /// + public object? Payload { get; set; } + + /// + /// The route this request will take. + /// + public string? Route { get; set; } + + /// + /// Additional information to pass to the rest client. + /// + public IDictionary? AdditionalContext { get; set; } + + /// + /// Additional files to upload with this request. + /// + public IDictionary? AdditionalFiles { get; set; } + + /// + /// Additional headers to add to this request. + /// + public IDictionary? Headers { get; set; } + + /// + /// Specifies the audit log reason for this request. + /// + /// The builder for chaining. + public RequestBuilder WithAuditLogReason(string reason) + { + this.AuditLogReason = reason; + return this; + } + + /// + /// Attaches a payload to this request. + /// + /// The builder for chaining. + public RequestBuilder WithPayload(object payload) + { + this.Payload = payload; + return this; + } + + /// + /// Specifies the route this request will take. + /// + /// The builder for chaining. + public RequestBuilder WithRoute(string route) + { + this.Route = route; + return this; + } + + /// + /// Adds a field to the request context. + /// + /// The builder for chaining. + public RequestBuilder AddToContext(string key, object value) + { + this.AdditionalContext ??= new Dictionary(); + + this.AdditionalContext.Add(key, value); + return this; + } + + /// + /// Adds a file to attach to the request. + /// + /// The builder for chaining. + public RequestBuilder AddFile(string name, AttachmentData file) + { + this.AdditionalFiles ??= new Dictionary(); + + this.AdditionalFiles.Add(name, file); + return this; + } + + /// + /// Adds a header to the request. + /// + /// The builder for chaining. + public RequestBuilder AddHeader(string key, string value) + { + this.Headers ??= new Dictionary(); + + this.Headers.Add(key, value); + return this; + } +} diff --git a/src/core/DSharpPlus.Internal.Rest/API/ApplicationCommandsRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/ApplicationCommandsRestAPI.cs new file mode 100644 index 0000000000..772e866105 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Rest/API/ApplicationCommandsRestAPI.cs @@ -0,0 +1,102 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +#pragma warning disable IDE0046 + +using System.Collections.Generic; +using System.Net.Http; +using System.Threading; +using System.Threading.Tasks; + +using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Rest; +using DSharpPlus.Internal.Abstractions.Rest.API; +using DSharpPlus.Internal.Abstractions.Rest.Errors; +using DSharpPlus.Internal.Abstractions.Rest.Payloads; +using DSharpPlus.Internal.Abstractions.Rest.Queries; +using DSharpPlus.Internal.Abstractions.Rest.Responses; +using DSharpPlus.Internal.Rest.Ratelimiting; + +using Remora.Results; + +namespace DSharpPlus.Internal.Rest.API; + +/// +public sealed class ApplicationCommandsRestAPI +( + IRestClient restClient +) + : IApplicationCommandsRestAPI +{ + /// + public async ValueTask>> BulkOverwriteGlobalApplicationCommandsAsync + ( + Snowflake applicationId, + IReadOnlyList payload, + RequestInfo info = default, + CancellationToken ct = default + ) + { + foreach(ICreateGlobalApplicationCommandPayload command in payload) + { + if (command.Name.Length is > 32 or < 1) + { + return new ValidationError("The name of an application command must be between 1 and 32 characters."); + } + + if (command.Name.Length is > 100 or < 1) + { + return new ValidationError("The description of an application command must be between 1 and 100 characters."); + } + + if (command.Options.HasValue && command.Type != DiscordApplicationCommandType.ChatInput) + { + return new ValidationError("Only chat input commands can have options and subcommands."); + } + + if (command.Options.HasValue && command.Options.Value!.Count > 25) + { + return new ValidationError("An application command can only have up to 25 options and subcommands."); + } + } + + if (payload.Count > 100) + { + return new ValidationError("An application can only have up to 100 global commands."); + } + + return await restClient.ExecuteRequestAsync> + ( + HttpMethod.Put, + $"applications/{applicationId}/commands", + b => b.WithSimpleRoute + ( + new SimpleStringRatelimitRoute + { + IsFracturable = false, + Resource = TopLevelResource.Other, + Route = "applications/:application-id/commands" + } + ) + .WithPayload(payload), + info, + ct + ); + } + + public ValueTask>> BulkOverwriteGuildApplicationCommandsAsync(Snowflake applicationId, Snowflake guildId, IReadOnlyList payload, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); + public ValueTask> CreateGlobalApplicationCommandAsync(Snowflake applicationId, ICreateGlobalApplicationCommandPayload payload, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); + public ValueTask> CreateGuildApplicationCommandAsync(Snowflake applicationId, Snowflake guildId, ICreateGuildApplicationCommandPayload payload, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); + public ValueTask DeleteGlobalApplicationCommandAsync(Snowflake applicationId, Snowflake commandId, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); + public ValueTask DeleteGuildApplicationCommandAsync(Snowflake applicationId, Snowflake guildId, Snowflake commandId, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); + public ValueTask> EditGlobalApplicationCommandAsync(Snowflake applicationId, Snowflake commandId, IEditGlobalApplicationCommandPayload payload, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); + public ValueTask> EditGuildApplicationCommandAsync(Snowflake applicationId, Snowflake guildId, Snowflake commandId, IEditGuildApplicationCommandPayload payload, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); + public ValueTask> GetApplicationCommandPermissionsAsync(Snowflake applicationId, Snowflake guildId, Snowflake commandId, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); + public ValueTask> GetGlobalApplicationCommandAsync(Snowflake applicationId, Snowflake commandId, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); + public ValueTask>> GetGlobalApplicationCommandsAsync(Snowflake applicationId, LocalizationQuery query = default, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); + public ValueTask> GetGuildApplicationCommandAsync(Snowflake applicationId, Snowflake guildId, Snowflake commandId, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); + public ValueTask>> GetGuildApplicationCommandPermissionsAsync(Snowflake applicationId, Snowflake guildId, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); + public ValueTask>> GetGuildApplicationCommandsAsync(Snowflake applicationId, Snowflake guildId, LocalizationQuery query = default, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); +} diff --git a/src/core/DSharpPlus.Internal.Rest/DSharpPlus.Internal.Rest.csproj b/src/core/DSharpPlus.Internal.Rest/DSharpPlus.Internal.Rest.csproj index 0d17e37212..8c665210ed 100644 --- a/src/core/DSharpPlus.Internal.Rest/DSharpPlus.Internal.Rest.csproj +++ b/src/core/DSharpPlus.Internal.Rest/DSharpPlus.Internal.Rest.csproj @@ -4,8 +4,17 @@ $(_DSharpPlusInternalRestVersion) + + + + + + + + + diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/ApplicationCommands/CreateGlobalApplicationCommandPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/ApplicationCommands/CreateGlobalApplicationCommandPayload.cs index 2d42209065..94bd199aaa 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/ApplicationCommands/CreateGlobalApplicationCommandPayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/ApplicationCommands/CreateGlobalApplicationCommandPayload.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Internal.Abstractions.Rest.Payloads; namespace DSharpPlus.Internal.Rest.Payloads; @@ -24,6 +25,9 @@ public sealed record CreateGlobalApplicationCommandPayload : ICreateGlobalApplic /// public Optional?> DescriptionLocalizations { get; init; } + /// + public Optional> Options { get; init; } + /// public Optional DefaultMemberPermissions { get; init; } diff --git a/src/core/DSharpPlus.Internal.Rest/QueryBuilder.cs b/src/core/DSharpPlus.Internal.Rest/QueryBuilder.cs new file mode 100644 index 0000000000..a7bc000e25 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Rest/QueryBuilder.cs @@ -0,0 +1,30 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; +using System.Linq; + +using Bundles; + +namespace DSharpPlus.Internal.Rest; + +/// +/// Constructs a new query from the specified parameters. +/// +internal record struct QueryBuilder +{ + public string RootUri { get; set; } + + public DictionarySlim Parameters { get; set; } + + public readonly QueryBuilder AddParameter(string key, string value) + { + ref string parameter = ref this.Parameters.GetOrAddValueRef(key); + parameter = value; + return this; + } + + public readonly string Build() + => this.RootUri + string.Join("&", this.Parameters.Select(e => Uri.EscapeDataString(e.Key) + '=' + Uri.EscapeDataString(e.Value))); +} diff --git a/src/core/DSharpPlus.Internal.Rest/Ratelimiting/ISimpleRatelimitRoute.cs b/src/core/DSharpPlus.Internal.Rest/Ratelimiting/ISimpleRatelimitRoute.cs new file mode 100644 index 0000000000..1ff6d9a756 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Rest/Ratelimiting/ISimpleRatelimitRoute.cs @@ -0,0 +1,13 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Internal.Rest.Ratelimiting; + +/// +/// Represents a common base for simple ratelimits. +/// +internal interface ISimpleRatelimitRoute +{ + public TopLevelResource Resource { get; } +} diff --git a/src/core/DSharpPlus.Internal.Rest/Ratelimiting/SimpleSnowflakeRatelimitRoute.cs b/src/core/DSharpPlus.Internal.Rest/Ratelimiting/SimpleSnowflakeRatelimitRoute.cs new file mode 100644 index 0000000000..1698d05ec0 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Rest/Ratelimiting/SimpleSnowflakeRatelimitRoute.cs @@ -0,0 +1,15 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Internal.Rest.Ratelimiting; + +/// +/// Specifies a route likely defined by its resource and a snowflake. +/// +internal readonly record struct SimpleSnowflakeRatelimitRoute : ISimpleRatelimitRoute +{ + public required TopLevelResource Resource { get; init; } + + public required Snowflake Id { get; init; } +} diff --git a/src/core/DSharpPlus.Internal.Rest/Ratelimiting/SimpleStringRatelimitRoute.cs b/src/core/DSharpPlus.Internal.Rest/Ratelimiting/SimpleStringRatelimitRoute.cs new file mode 100644 index 0000000000..28e86e9f1e --- /dev/null +++ b/src/core/DSharpPlus.Internal.Rest/Ratelimiting/SimpleStringRatelimitRoute.cs @@ -0,0 +1,21 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Internal.Rest.Ratelimiting; + +/// +/// Specifies a route likely defined by its resource and a string. +/// +internal readonly record struct SimpleStringRatelimitRoute : ISimpleRatelimitRoute +{ + public required TopLevelResource Resource { get; init; } + + /// + /// Specifies whether this route can fracture. This is the case for all routes with more than one method + /// pointing to the otherwise same route, and for all routes that use any ID as a top-level parameter. + /// + public required bool IsFracturable { get; init; } + + public required string Route { get; init; } +} diff --git a/src/core/DSharpPlus.Internal.Rest/Ratelimiting/TopLevelResource.cs b/src/core/DSharpPlus.Internal.Rest/Ratelimiting/TopLevelResource.cs new file mode 100644 index 0000000000..a70e57138d --- /dev/null +++ b/src/core/DSharpPlus.Internal.Rest/Ratelimiting/TopLevelResource.cs @@ -0,0 +1,16 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Internal.Rest.Ratelimiting; + +/// +/// Specifies the top-level resources for requests. +/// +internal enum TopLevelResource +{ + Channel, + Guild, + Webhook, + Other +} diff --git a/src/core/DSharpPlus.Internal.Rest/RequestBuilderExtensions.cs b/src/core/DSharpPlus.Internal.Rest/RequestBuilderExtensions.cs new file mode 100644 index 0000000000..cb710dee42 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Rest/RequestBuilderExtensions.cs @@ -0,0 +1,29 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Internal.Abstractions.Rest; +using DSharpPlus.Internal.Rest.Ratelimiting; + +namespace DSharpPlus.Internal.Rest; + +internal static class RequestBuilderExtensions +{ + public static RequestBuilder WithSimpleRoute(this RequestBuilder request, ISimpleRatelimitRoute route) + { + request.AddToContext("simple-route", route); + return request; + } + + public static RequestBuilder AsWebhookRequest(this RequestBuilder request, bool isWebhookRequest = true) + { + request.AddToContext("is-webhook-request", isWebhookRequest); + return request; + } + + public static RequestBuilder AsInteractionRequest(this RequestBuilder request, bool isInteractionRequest = true) + { + request.AddToContext("is-interaction-request", isInteractionRequest); + return request; + } +} From 948d94dd85c1cd81f0f426ebc697174718194ff5 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sun, 7 Jan 2024 19:32:34 +0100 Subject: [PATCH 248/323] implement application commands --- Directory.Build.props | 2 +- .../API/IApplicationCommandsRestAPI.cs | 2 +- .../ICreateGlobalApplicationCommandPayload.cs | 2 +- .../ICreateGuildApplicationCommandPayload.cs | 6 + .../IEditGlobalApplicationCommandPayload.cs | 6 + .../IEditGuildApplicationCommandPayload.cs | 6 + .../API/ApplicationCommandsRestAPI.cs | 542 +++++++++++++++++- .../CreateGuildApplicationCommandPayload.cs | 4 + .../EditGlobalApplicationCommandPayload.cs | 4 + .../EditGuildApplicationCommandPayload.cs | 4 + src/core/DSharpPlus.Shared/Optional`1.cs | 4 +- src/core/DSharpPlus.Shared/Snowflake.cs | 6 + 12 files changed, 569 insertions(+), 19 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index 6ddd84f233..fb1c86bac0 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -9,7 +9,7 @@ True True All - $(NoWarn);CS1591;CA1028;CA1062;CA1711;CA1716;CA1720;CA2007;CA2225 + $(NoWarn);CS1591;CA1028;CA1062;CA1308;CA1711;CA1716;CA1720;CA2007;CA2225 True diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IApplicationCommandsRestAPI.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IApplicationCommandsRestAPI.cs index 1b4f2ecbad..ad01ea9a8c 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IApplicationCommandsRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IApplicationCommandsRestAPI.cs @@ -156,7 +156,7 @@ public ValueTask>> GetGuildApplication /// Additional instructions regarding this request. /// A cancellation token for this operation. /// The created application command object. - public ValueTask> CreateGuildApplicationCommandAsync + public ValueTask> CreateGuildApplicationCommandAsync ( Snowflake applicationId, Snowflake guildId, diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/ApplicationCommands/ICreateGlobalApplicationCommandPayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/ApplicationCommands/ICreateGlobalApplicationCommandPayload.cs index 34d13fc23a..418da8ee8f 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/ApplicationCommands/ICreateGlobalApplicationCommandPayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/ApplicationCommands/ICreateGlobalApplicationCommandPayload.cs @@ -35,7 +35,7 @@ public interface ICreateGlobalApplicationCommandPayload public Optional?> DescriptionLocalizations { get; } /// - /// Up to 25 parameters for this comand, or its subcommands. + /// Up to 25 parameters for this command, or its subcommands. /// public Optional> Options { get; } diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/ApplicationCommands/ICreateGuildApplicationCommandPayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/ApplicationCommands/ICreateGuildApplicationCommandPayload.cs index cc44913849..be528ab2e4 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/ApplicationCommands/ICreateGuildApplicationCommandPayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/ApplicationCommands/ICreateGuildApplicationCommandPayload.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; namespace DSharpPlus.Internal.Abstractions.Rest.Payloads; @@ -23,6 +24,11 @@ public interface ICreateGuildApplicationCommandPayload /// public Optional?> NameLocalizations { get; } + /// + /// Up to 25 parameters for this command, or its subcommands. + /// + public Optional> Options { get; } + /// /// The description for this chat input command, between 1 and 100 characters. /// diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/ApplicationCommands/IEditGlobalApplicationCommandPayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/ApplicationCommands/IEditGlobalApplicationCommandPayload.cs index f373a6c31b..899d57597b 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/ApplicationCommands/IEditGlobalApplicationCommandPayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/ApplicationCommands/IEditGlobalApplicationCommandPayload.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; namespace DSharpPlus.Internal.Abstractions.Rest.Payloads; @@ -33,6 +34,11 @@ public interface IEditGlobalApplicationCommandPayload /// public Optional?> DescriptionLocalizations { get; } + /// + /// Up to 25 parameters for this command, or its subcommands. + /// + public Optional> Options { get; } + /// /// The default permissions needed to see this command. /// diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/ApplicationCommands/IEditGuildApplicationCommandPayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/ApplicationCommands/IEditGuildApplicationCommandPayload.cs index 2a4a112ce6..64eec077ef 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/ApplicationCommands/IEditGuildApplicationCommandPayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/ApplicationCommands/IEditGuildApplicationCommandPayload.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; namespace DSharpPlus.Internal.Abstractions.Rest.Payloads; @@ -33,6 +34,11 @@ public interface IEditGuildApplicationCommandPayload /// public Optional?> DescriptionLocalizations { get; } + /// + /// Up to 25 parameters for this command, or its subcommands. + /// + public Optional> Options { get; } + /// /// The default permissions needed to see this command. /// diff --git a/src/core/DSharpPlus.Internal.Rest/API/ApplicationCommandsRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/ApplicationCommandsRestAPI.cs index 772e866105..7833e0fdef 100644 --- a/src/core/DSharpPlus.Internal.Rest/API/ApplicationCommandsRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Rest/API/ApplicationCommandsRestAPI.cs @@ -5,6 +5,7 @@ #pragma warning disable IDE0046 using System.Collections.Generic; +using System.Net; using System.Net.Http; using System.Threading; using System.Threading.Tasks; @@ -18,6 +19,7 @@ using DSharpPlus.Internal.Abstractions.Rest.Queries; using DSharpPlus.Internal.Abstractions.Rest.Responses; using DSharpPlus.Internal.Rest.Ratelimiting; +using DSharpPlus.Serialization; using Remora.Results; @@ -26,7 +28,8 @@ namespace DSharpPlus.Internal.Rest.API; /// public sealed class ApplicationCommandsRestAPI ( - IRestClient restClient + IRestClient restClient, + ISerializationService serializationService ) : IApplicationCommandsRestAPI { @@ -86,17 +89,528 @@ public async ValueTask>> BulkOverwrite ); } - public ValueTask>> BulkOverwriteGuildApplicationCommandsAsync(Snowflake applicationId, Snowflake guildId, IReadOnlyList payload, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); - public ValueTask> CreateGlobalApplicationCommandAsync(Snowflake applicationId, ICreateGlobalApplicationCommandPayload payload, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); - public ValueTask> CreateGuildApplicationCommandAsync(Snowflake applicationId, Snowflake guildId, ICreateGuildApplicationCommandPayload payload, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); - public ValueTask DeleteGlobalApplicationCommandAsync(Snowflake applicationId, Snowflake commandId, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); - public ValueTask DeleteGuildApplicationCommandAsync(Snowflake applicationId, Snowflake guildId, Snowflake commandId, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); - public ValueTask> EditGlobalApplicationCommandAsync(Snowflake applicationId, Snowflake commandId, IEditGlobalApplicationCommandPayload payload, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); - public ValueTask> EditGuildApplicationCommandAsync(Snowflake applicationId, Snowflake guildId, Snowflake commandId, IEditGuildApplicationCommandPayload payload, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); - public ValueTask> GetApplicationCommandPermissionsAsync(Snowflake applicationId, Snowflake guildId, Snowflake commandId, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); - public ValueTask> GetGlobalApplicationCommandAsync(Snowflake applicationId, Snowflake commandId, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); - public ValueTask>> GetGlobalApplicationCommandsAsync(Snowflake applicationId, LocalizationQuery query = default, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); - public ValueTask> GetGuildApplicationCommandAsync(Snowflake applicationId, Snowflake guildId, Snowflake commandId, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); - public ValueTask>> GetGuildApplicationCommandPermissionsAsync(Snowflake applicationId, Snowflake guildId, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); - public ValueTask>> GetGuildApplicationCommandsAsync(Snowflake applicationId, Snowflake guildId, LocalizationQuery query = default, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); + /// + public async ValueTask>> BulkOverwriteGuildApplicationCommandsAsync + ( + Snowflake applicationId, + Snowflake guildId, + IReadOnlyList payload, + RequestInfo info = default, + CancellationToken ct = default + ) + { + foreach (ICreateGuildApplicationCommandPayload command in payload) + { + if (command.Name.Length is > 32 or < 1) + { + return new ValidationError("The name of an application command must be between 1 and 32 characters."); + } + + if (command.Name.Length is > 100 or < 1) + { + return new ValidationError("The description of an application command must be between 1 and 100 characters."); + } + + if (command.Options.HasValue && command.Type != DiscordApplicationCommandType.ChatInput) + { + return new ValidationError("Only chat input commands can have options and subcommands."); + } + + if (command.Options.HasValue && command.Options.Value!.Count > 25) + { + return new ValidationError("An application command can only have up to 25 options and subcommands."); + } + } + + if (payload.Count > 100) + { + return new ValidationError("An application can only have up to 100 global commands."); + } + + return await restClient.ExecuteRequestAsync> + ( + HttpMethod.Put, + $"applications/{applicationId}/guilds/{guildId}/commands", + b => b.WithSimpleRoute + ( + new SimpleStringRatelimitRoute + { + IsFracturable = false, + Resource = TopLevelResource.Other, + Route = "applications/:application-id/guilds/:guild-id/commands" + } + ) + .WithPayload(payload), + info, + ct + ); + } + + /// + public async ValueTask> CreateGlobalApplicationCommandAsync + ( + Snowflake applicationId, + ICreateGlobalApplicationCommandPayload payload, + RequestInfo info = default, + CancellationToken ct = default + ) + { + if (payload.Name.Length is > 32 or < 1) + { + return new ValidationError("The name of an application command must be between 1 and 32 characters."); + } + + if (payload.Name.Length is > 100 or < 1) + { + return new ValidationError("The description of an application command must be between 1 and 100 characters."); + } + + if (payload.Options.HasValue && payload.Type != DiscordApplicationCommandType.ChatInput) + { + return new ValidationError("Only chat input commands can have options and subcommands."); + } + + if (payload.Options.HasValue && payload.Options.Value!.Count > 25) + { + return new ValidationError("An application command can only have up to 25 options and subcommands."); + } + + Result response = await restClient.ExecuteRequestAsync + ( + HttpMethod.Post, + $"applications/{applicationId}/commands", + b => b.WithSimpleRoute + ( + new SimpleStringRatelimitRoute + { + IsFracturable = false, + Resource = TopLevelResource.Other, + Route = "applications/:application-id/commands" + } + ) + .WithPayload(payload), + info, + ct + ); + + if (!response.IsSuccess) + { + return Result.FromError(response.Error); + } + + return new CreateApplicationCommandResponse + { + CreatedCommand = serializationService.DeserializeModel + ( + await response.Entity.Content.ReadAsByteArrayAsync(ct) + ), + IsNewlyCreated = response.Entity.StatusCode == HttpStatusCode.Created + }; + } + + /// + public async ValueTask> CreateGuildApplicationCommandAsync + ( + Snowflake applicationId, + Snowflake guildId, + ICreateGuildApplicationCommandPayload payload, + RequestInfo info = default, + CancellationToken ct = default + ) + { + if (payload.Name.Length is > 32 or < 1) + { + return new ValidationError("The name of an application command must be between 1 and 32 characters."); + } + + if (payload.Name.Length is > 100 or < 1) + { + return new ValidationError("The description of an application command must be between 1 and 100 characters."); + } + + if (payload.Options.HasValue && payload.Type != DiscordApplicationCommandType.ChatInput) + { + return new ValidationError("Only chat input commands can have options and subcommands."); + } + + if (payload.Options.HasValue && payload.Options.Value!.Count > 25) + { + return new ValidationError("An application command can only have up to 25 options and subcommands."); + } + + Result response = await restClient.ExecuteRequestAsync + ( + HttpMethod.Post, + $"applications/{applicationId}/guilds/{guildId}/commands", + b => b.WithSimpleRoute + ( + new SimpleStringRatelimitRoute + { + IsFracturable = false, + Resource = TopLevelResource.Other, + Route = "applications/:application-id/guilds/:guild-id/commands" + } + ) + .WithPayload(payload), + info, + ct + ); + + if (!response.IsSuccess) + { + return Result.FromError(response.Error); + } + + return new CreateApplicationCommandResponse + { + CreatedCommand = serializationService.DeserializeModel + ( + await response.Entity.Content.ReadAsByteArrayAsync(ct) + ), + IsNewlyCreated = response.Entity.StatusCode == HttpStatusCode.Created + }; + } + + /// + public async ValueTask DeleteGlobalApplicationCommandAsync + ( + Snowflake applicationId, + Snowflake commandId, + RequestInfo info = default, + CancellationToken ct = default + ) + { + Result response = await restClient.ExecuteRequestAsync + ( + HttpMethod.Delete, + $"applications/{applicationId}/commands/{commandId}", + b => b.WithSimpleRoute + ( + new SimpleStringRatelimitRoute + { + IsFracturable = false, + Resource = TopLevelResource.Other, + Route = "applications/:application-id/commands/:command-id" + } + ), + info, + ct + ); + + return (Result)response; + } + + /// + public async ValueTask DeleteGuildApplicationCommandAsync + ( + Snowflake applicationId, + Snowflake guildId, + Snowflake commandId, + RequestInfo info = default, + CancellationToken ct = default + ) + { + Result response = await restClient.ExecuteRequestAsync + ( + HttpMethod.Delete, + $"applications/{applicationId}/guilds/{guildId}/commands/{commandId}", + b => b.WithSimpleRoute + ( + new SimpleStringRatelimitRoute + { + IsFracturable = false, + Resource = TopLevelResource.Other, + Route = "applications/:application-id/guilds/:guild-id/commands/:command-id" + } + ), + info, + ct + ); + + return (Result)response; + } + + /// + public async ValueTask> EditGlobalApplicationCommandAsync + ( + Snowflake applicationId, + Snowflake commandId, + IEditGlobalApplicationCommandPayload payload, + RequestInfo info = default, + CancellationToken ct = default + ) + { + if (payload.Name.HasValue && payload.Name.Value.Length is > 32 or < 1) + { + return new ValidationError("The name of an application command must be between 1 and 32 characters."); + } + + if (payload.Name.HasValue && payload.Name.Value.Length is > 100 or < 1) + { + return new ValidationError("The description of an application command must be between 1 and 100 characters."); + } + + if (payload.Options.HasValue && payload.Type != DiscordApplicationCommandType.ChatInput) + { + return new ValidationError("Only chat input commands can have options and subcommands."); + } + + if (payload.Options.HasValue && payload.Options.Value.Count > 25) + { + return new ValidationError("An application command can only have up to 25 options and subcommands."); + } + + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Patch, + $"applications/{applicationId}/commands/{commandId}", + b => b.WithSimpleRoute + ( + new SimpleStringRatelimitRoute + { + IsFracturable = false, + Resource = TopLevelResource.Other, + Route = "applications/:application-id/commands/:command-id" + } + ) + .WithPayload(payload), + info, + ct + ); + } + + /// + public async ValueTask> EditGuildApplicationCommandAsync + ( + Snowflake applicationId, + Snowflake guildId, + Snowflake commandId, + IEditGuildApplicationCommandPayload payload, + RequestInfo info = default, + CancellationToken ct = default + ) + { + if (payload.Name.HasValue && payload.Name.Value.Length is > 32 or < 1) + { + return new ValidationError("The name of an application command must be between 1 and 32 characters."); + } + + if (payload.Name.HasValue && payload.Name.Value.Length is > 100 or < 1) + { + return new ValidationError("The description of an application command must be between 1 and 100 characters."); + } + + if (payload.Options.HasValue && payload.Type != DiscordApplicationCommandType.ChatInput) + { + return new ValidationError("Only chat input commands can have options and subcommands."); + } + + if (payload.Options.HasValue && payload.Options.Value.Count > 25) + { + return new ValidationError("An application command can only have up to 25 options and subcommands."); + } + + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Patch, + $"applications/{applicationId}/guild/{guildId}/commands/{commandId}", + b => b.WithSimpleRoute + ( + new SimpleStringRatelimitRoute + { + IsFracturable = false, + Resource = TopLevelResource.Other, + Route = "applications/:application-id/guilds/:guild-id/commands/:command-id" + } + ) + .WithPayload(payload), + info, + ct + ); + } + + /// + public async ValueTask> GetApplicationCommandPermissionsAsync + ( + Snowflake applicationId, + Snowflake guildId, + Snowflake commandId, + RequestInfo info = default, + CancellationToken ct = default + ) + { + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Get, + $"applications/{applicationId}/guild/{guildId}/commands/{commandId}/permissions", + b => b.WithSimpleRoute + ( + new SimpleStringRatelimitRoute + { + IsFracturable = false, + Resource = TopLevelResource.Other, + Route = "applications/:application-id/guilds/:guild-id/commands/:command-id/permissions" + } + ), + info, + ct + ); + } + + /// + public async ValueTask> GetGlobalApplicationCommandAsync + ( + Snowflake applicationId, + Snowflake commandId, + RequestInfo info = default, + CancellationToken ct = default + ) + { + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Get, + $"applications/{applicationId}/commands/{commandId}", + b => b.WithSimpleRoute + ( + new SimpleStringRatelimitRoute + { + IsFracturable = false, + Resource = TopLevelResource.Other, + Route = "applications/:application-id/commands/:command-id" + } + ), + info, + ct + ); + } + + /// + public async ValueTask>> GetGlobalApplicationCommandsAsync + ( + Snowflake applicationId, + LocalizationQuery query = default, + RequestInfo info = default, + CancellationToken ct = default + ) + { + QueryBuilder builder = new() + { + RootUri = $"applications/{applicationId}/commands" + }; + + if (query.WithLocalizations is not null) + { + builder.AddParameter("with_localizations", query.WithLocalizations.Value.ToString().ToLowerInvariant()); + } + + return await restClient.ExecuteRequestAsync> + ( + HttpMethod.Get, + $"applications/{applicationId}/commands", + b => b.WithSimpleRoute + ( + new SimpleStringRatelimitRoute + { + IsFracturable = false, + Resource = TopLevelResource.Other, + Route = "applications/:application-id/commands" + } + ), + info, + ct + ); + } + + /// + public async ValueTask> GetGuildApplicationCommandAsync + ( + Snowflake applicationId, + Snowflake guildId, + Snowflake commandId, + RequestInfo info = default, + CancellationToken ct = default + ) + { + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Get, + $"applications/{applicationId}/guilds/{guildId}/commands/{commandId}", + b => b.WithSimpleRoute + ( + new SimpleStringRatelimitRoute + { + IsFracturable = false, + Resource = TopLevelResource.Other, + Route = "applications/:application-id/guilds/:guild-id/commands/:command-id" + } + ), + info, + ct + ); + } + + /// + public async ValueTask>> GetGuildApplicationCommandPermissionsAsync + ( + Snowflake applicationId, + Snowflake guildId, + RequestInfo info = default, + CancellationToken ct = default + ) + { + return await restClient.ExecuteRequestAsync> + ( + HttpMethod.Get, + $"applications/{applicationId}/guild/{guildId}/commands/permissions", + b => b.WithSimpleRoute + ( + new SimpleStringRatelimitRoute + { + IsFracturable = false, + Resource = TopLevelResource.Other, + Route = "applications/:application-id/guilds/:guild-id/commands/permissions" + } + ), + info, + ct + ); + } + + /// + public async ValueTask>> GetGuildApplicationCommandsAsync + ( + Snowflake applicationId, + Snowflake guildId, + LocalizationQuery query = default, + RequestInfo info = default, + CancellationToken ct = default + ) + { + QueryBuilder builder = new() + { + RootUri = $"applications/{applicationId}/guilds/{guildId}/commands" + }; + + if (query.WithLocalizations is not null) + { + builder.AddParameter("with_localizations", query.WithLocalizations.Value.ToString().ToLowerInvariant()); + } + + return await restClient.ExecuteRequestAsync> + ( + HttpMethod.Get, + $"applications/{applicationId}/commands", + b => b.WithSimpleRoute + ( + new SimpleStringRatelimitRoute + { + IsFracturable = false, + Resource = TopLevelResource.Other, + Route = "applications/:application-id/guilds/:guild-id/commands" + } + ), + info, + ct + ); + } } diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/ApplicationCommands/CreateGuildApplicationCommandPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/ApplicationCommands/CreateGuildApplicationCommandPayload.cs index 0d83ce3a3a..411ee34778 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/ApplicationCommands/CreateGuildApplicationCommandPayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/ApplicationCommands/CreateGuildApplicationCommandPayload.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Internal.Abstractions.Rest.Payloads; namespace DSharpPlus.Internal.Rest.Payloads; @@ -18,6 +19,9 @@ public sealed record CreateGuildApplicationCommandPayload : ICreateGuildApplicat /// public Optional?> NameLocalizations { get; init; } + /// + public Optional> Options { get; init; } + /// public Optional Description { get; init; } diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/ApplicationCommands/EditGlobalApplicationCommandPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/ApplicationCommands/EditGlobalApplicationCommandPayload.cs index 2a4758c581..8c3fd7e85e 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/ApplicationCommands/EditGlobalApplicationCommandPayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/ApplicationCommands/EditGlobalApplicationCommandPayload.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Internal.Abstractions.Rest.Payloads; namespace DSharpPlus.Internal.Rest.Payloads; @@ -24,6 +25,9 @@ public sealed record EditGlobalApplicationCommandPayload : IEditGlobalApplicatio /// public Optional?> DescriptionLocalizations { get; init; } + /// + public Optional> Options { get; init; } + /// public Optional DefaultMemberPermissions { get; init; } diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/ApplicationCommands/EditGuildApplicationCommandPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/ApplicationCommands/EditGuildApplicationCommandPayload.cs index 01a294cdd1..b02f6c9155 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/ApplicationCommands/EditGuildApplicationCommandPayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/ApplicationCommands/EditGuildApplicationCommandPayload.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Internal.Abstractions.Rest.Payloads; namespace DSharpPlus.Internal.Rest.Payloads; @@ -24,6 +25,9 @@ public sealed record EditGuildApplicationCommandPayload : IEditGuildApplicationC /// public Optional?> DescriptionLocalizations { get; init; } + /// + public Optional> Options { get; init; } + /// public Optional DefaultMemberPermissions { get; init; } diff --git a/src/core/DSharpPlus.Shared/Optional`1.cs b/src/core/DSharpPlus.Shared/Optional`1.cs index 585355e907..61d6286c62 100644 --- a/src/core/DSharpPlus.Shared/Optional`1.cs +++ b/src/core/DSharpPlus.Shared/Optional`1.cs @@ -21,7 +21,7 @@ namespace DSharpPlus; /// /// Retrieves the underlying value, if present. /// - public T? Value + public T Value { get { @@ -30,7 +30,7 @@ public T? Value ThrowHelper.ThrowOptionalNoValuePresent(); } - return this.value; + return this.value!; } } diff --git a/src/core/DSharpPlus.Shared/Snowflake.cs b/src/core/DSharpPlus.Shared/Snowflake.cs index 289adfe31f..0cc139c62b 100644 --- a/src/core/DSharpPlus.Shared/Snowflake.cs +++ b/src/core/DSharpPlus.Shared/Snowflake.cs @@ -5,6 +5,7 @@ #pragma warning disable CA5394 using System; +using System.Globalization; namespace DSharpPlus; @@ -24,6 +25,11 @@ namespace DSharpPlus; /// public long Value { get; } + /// + /// Returns the string representation of this snowflake. + /// + public override string ToString() => this.Value.ToString(CultureInfo.InvariantCulture); + /// /// The time when this snowflake was created. /// From 7266c42cb365d7da82faaac394579858471715a7 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sun, 7 Jan 2024 19:41:44 +0100 Subject: [PATCH 249/323] slim ValidationError --- .../Errors/ValidationError.cs | 20 ++----------------- 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Errors/ValidationError.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Errors/ValidationError.cs index 2f96f66abd..c8f060728c 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/Errors/ValidationError.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Errors/ValidationError.cs @@ -2,8 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using System.Collections.Generic; - using Remora.Results; namespace DSharpPlus.Internal.Abstractions.Rest.Errors; @@ -11,19 +9,5 @@ namespace DSharpPlus.Internal.Abstractions.Rest.Errors; /// /// Represents an error encountered during parameter validation. /// -public record ValidationError : ResultError -{ - /// - /// If this error was caused by any specific parameters, contains the names of the invalid parameters. - /// - public IReadOnlyList? ParameterNames { get; init; } - - /// - /// Initializes a new validation error. - /// - /// The human-readable error message. - /// If applicable, the names of parameters that failed validation. - public ValidationError(string message, params string[] parameters) - : base(message) - => this.ParameterNames = parameters.Length != 0 ? parameters : null; -} +/// The human-readable error message. +public record ValidationError(string message) : ResultError(message); From a1f04402161d9469bfdb5fc517d6336cb10b50d5 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sun, 7 Jan 2024 19:41:54 +0100 Subject: [PATCH 250/323] implement application rest api calls --- .../API/ApplicationRestAPI.cs | 93 +++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 src/core/DSharpPlus.Internal.Rest/API/ApplicationRestAPI.cs diff --git a/src/core/DSharpPlus.Internal.Rest/API/ApplicationRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/ApplicationRestAPI.cs new file mode 100644 index 0000000000..e7da9128d5 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Rest/API/ApplicationRestAPI.cs @@ -0,0 +1,93 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; +using System.Linq; +using System.Net.Http; +using System.Threading; +using System.Threading.Tasks; + +using DSharpPlus.Internal.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Rest; +using DSharpPlus.Internal.Abstractions.Rest.API; +using DSharpPlus.Internal.Abstractions.Rest.Errors; +using DSharpPlus.Internal.Abstractions.Rest.Payloads; +using DSharpPlus.Internal.Rest.Ratelimiting; + +using Remora.Results; + +namespace DSharpPlus.Internal.Rest.API; + +/// +public sealed class ApplicationRestAPI +( + IRestClient restClient +) + : IApplicationRestAPI +{ + /// + public async ValueTask> EditCurrentApplicationAsync + ( + IEditCurrentApplicationPayload payload, + RequestInfo info = default, + CancellationToken ct = default + ) + { + if (payload.Tags.TryGetNonNullValue(out IReadOnlyList? value)) + { + if (value.Count > 5) + { + return new ValidationError("An application can only have up to five tags."); + } + + if (value.Any(tag => tag.Length > 20)) + { + return new ValidationError("Tags of an application cannot exceed 20 characters."); + } + } + + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Patch, + $"applications/@me", + b => b.WithSimpleRoute + ( + new SimpleStringRatelimitRoute + { + IsFracturable = false, + Resource = TopLevelResource.Other, + Route = "applications/@me" + } + ) + .WithPayload(payload), + info, + ct + ); + } + + /// + public async ValueTask> GetCurrentApplicationAsync + ( + RequestInfo info = default, + CancellationToken ct = default + ) + { + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Get, + $"applications/@me", + b => b.WithSimpleRoute + ( + new SimpleStringRatelimitRoute + { + IsFracturable = false, + Resource = TopLevelResource.Other, + Route = "applications/@me" + } + ), + info, + ct + ); + } +} From 9c0e2883e7ded93895380829b2dc8376a5ada99f Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sun, 7 Jan 2024 22:09:52 +0100 Subject: [PATCH 251/323] audit logs :3 --- .../API/ApplicationCommandsRestAPI.cs | 4 +- .../API/AuditLogsRestAPI.cs | 90 +++++++++++++++++++ 2 files changed, 92 insertions(+), 2 deletions(-) create mode 100644 src/core/DSharpPlus.Internal.Rest/API/AuditLogsRestAPI.cs diff --git a/src/core/DSharpPlus.Internal.Rest/API/ApplicationCommandsRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/ApplicationCommandsRestAPI.cs index 7833e0fdef..f99e3fd1ec 100644 --- a/src/core/DSharpPlus.Internal.Rest/API/ApplicationCommandsRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Rest/API/ApplicationCommandsRestAPI.cs @@ -506,7 +506,7 @@ public async ValueTask>> GetGlobalAppl return await restClient.ExecuteRequestAsync> ( HttpMethod.Get, - $"applications/{applicationId}/commands", + builder.Build(), b => b.WithSimpleRoute ( new SimpleStringRatelimitRoute @@ -599,7 +599,7 @@ public async ValueTask>> GetGuildAppli return await restClient.ExecuteRequestAsync> ( HttpMethod.Get, - $"applications/{applicationId}/commands", + builder.Build(), b => b.WithSimpleRoute ( new SimpleStringRatelimitRoute diff --git a/src/core/DSharpPlus.Internal.Rest/API/AuditLogsRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/AuditLogsRestAPI.cs new file mode 100644 index 0000000000..a7e83a921d --- /dev/null +++ b/src/core/DSharpPlus.Internal.Rest/API/AuditLogsRestAPI.cs @@ -0,0 +1,90 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Globalization; +using System.Net.Http; +using System.Threading; +using System.Threading.Tasks; + +using DSharpPlus.Internal.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Rest; +using DSharpPlus.Internal.Abstractions.Rest.API; +using DSharpPlus.Internal.Abstractions.Rest.Errors; +using DSharpPlus.Internal.Abstractions.Rest.Queries; +using DSharpPlus.Internal.Rest.Ratelimiting; + +using Remora.Results; + +namespace DSharpPlus.Internal.Rest.API; + +/// +public sealed class AuditLogsRestAPI +( + IRestClient restClient +) + : IAuditLogsRestAPI +{ + /// + public async ValueTask> ListGuildAuditLogEntriesAsync + ( + Snowflake guildId, + ListGuildAuditLogEntriesQuery query = default, + RequestInfo info = default, + CancellationToken ct = default + ) + { + if (query.Limit is not null and (< 1 or > 1000)) + { + return new ValidationError("The limit of entries to return must be between 1 and 1000."); + } + + QueryBuilder builder = new() + { + RootUri = $"guilds/{guildId}/audit-logs" + }; + + if (query.ActionType is not null) + { + int value = (int)query.ActionType.Value; + builder.AddParameter("action_type", value.ToString(CultureInfo.InvariantCulture)); + } + + if (query.After is not null) + { + builder.AddParameter("after", query.After.Value.ToString()); + } + + if (query.Before is not null) + { + builder.AddParameter("before", query.Before.Value.ToString()); + } + + if (query.Limit is not null) + { + builder.AddParameter("limit", query.Limit.Value.ToString(CultureInfo.InvariantCulture)); + } + + if (query.UserId is not null) + { + builder.AddParameter("user_id", query.UserId.Value.ToString()); + } + + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Get, + builder.Build(), + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Guild, + Id = guildId + } + ) + .WithRoute($"guilds/{guildId}/audit-logs"), + info, + ct + ); + } +} From 45b23ff6e41de3f41c3dda88b077c086cf8d6dde Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sun, 7 Jan 2024 22:33:30 +0100 Subject: [PATCH 252/323] implement automod --- .../RequestBuilder.cs | 2 +- .../API/AutoModerationRestAPI.cs | 192 ++++++++++++++++++ 2 files changed, 193 insertions(+), 1 deletion(-) create mode 100644 src/core/DSharpPlus.Internal.Rest/API/AutoModerationRestAPI.cs diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/RequestBuilder.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/RequestBuilder.cs index f5dfeefc08..1276b5090e 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/RequestBuilder.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/RequestBuilder.cs @@ -47,7 +47,7 @@ public class RequestBuilder /// Specifies the audit log reason for this request. /// /// The builder for chaining. - public RequestBuilder WithAuditLogReason(string reason) + public RequestBuilder WithAuditLogReason(string? reason) { this.AuditLogReason = reason; return this; diff --git a/src/core/DSharpPlus.Internal.Rest/API/AutoModerationRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/AutoModerationRestAPI.cs new file mode 100644 index 0000000000..cd2c7702f4 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Rest/API/AutoModerationRestAPI.cs @@ -0,0 +1,192 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +#pragma warning disable IDE0046 + +using System.Collections.Generic; +using System.Net.Http; +using System.Threading; +using System.Threading.Tasks; + +using DSharpPlus.Internal.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Rest; +using DSharpPlus.Internal.Abstractions.Rest.API; +using DSharpPlus.Internal.Abstractions.Rest.Errors; +using DSharpPlus.Internal.Abstractions.Rest.Payloads; +using DSharpPlus.Internal.Rest.Ratelimiting; + +using Remora.Results; + +namespace DSharpPlus.Internal.Rest.API; + +/// +public sealed class AutoModerationRestAPI +( + IRestClient restClient +) + : IAutoModerationRestAPI +{ + /// + public async ValueTask> CreateAutoModerationRuleAsync + ( + Snowflake guildId, + ICreateAutoModerationRulePayload payload, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ) + { + if (payload.ExemptRoles.HasValue && payload.ExemptRoles.Value.Count > 20) + { + return new ValidationError("Only up to 20 roles can be exempted from an automod rule."); + } + + if (payload.ExemptChannels.HasValue && payload.ExemptChannels.Value.Count > 50) + { + return new ValidationError("Ibkt yp to 50 channels can be exempted from an automod rule."); + } + + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Post, + $"guilds/{guildId}/auto-moderation/rules", + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Guild, + Id = guildId + } + ) + .WithRoute($"guilds/{guildId}/auto-moderation/rules") + .WithAuditLogReason(reason), + info, + ct + ); + } + + /// + public async ValueTask DeleteAutoModerationRuleAsync + ( + Snowflake guildId, + Snowflake ruleId, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ) + { + Result response = await restClient.ExecuteRequestAsync + ( + HttpMethod.Delete, + $"guilds/{guildId}/auto-moderation/rules/{ruleId}", + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Guild, + Id = guildId + } + ) + .WithRoute($"guilds/{guildId}/auto-moderation/rules/:rule-id") + .WithAuditLogReason(reason), + info, + ct + ); + + return (Result)response; + } + + /// + public async ValueTask> GetAutoModerationRuleAsync + ( + Snowflake guildId, + Snowflake ruleId, + RequestInfo info = default, + CancellationToken ct = default + ) + { + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Get, + $"guilds/{guildId}/auto-moderation/rules/{ruleId}", + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Guild, + Id = guildId + } + ) + .WithRoute($"guilds/{guildId}/auto-moderation/rules/:rule-id"), + info, + ct + ); + } + + /// + public async ValueTask>> ListAutoModerationRulesAsync + ( + Snowflake guildId, + RequestInfo info = default, + CancellationToken ct = default + ) + { + return await restClient.ExecuteRequestAsync> + ( + HttpMethod.Get, + $"guilds/{guildId}/auto-moderation/rules", + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Guild, + Id = guildId + } + ) + .WithRoute($"guilds/{guildId}/auto-moderation/rules"), + info, + ct + ); + } + + /// + public async ValueTask> ModifyAutoModerationRuleAsync + ( + Snowflake guildId, + Snowflake ruleId, + IModifyAutoModerationRulePayload payload, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ) + { + if (payload.ExemptRoles.HasValue && payload.ExemptRoles.Value.Count > 20) + { + return new ValidationError("Only up to 20 roles can be exempted from an automod rule."); + } + + if (payload.ExemptChannels.HasValue && payload.ExemptChannels.Value.Count > 50) + { + return new ValidationError("Ibkt yp to 50 channels can be exempted from an automod rule."); + } + + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Patch, + $"guilds/{guildId}/auto-moderation/rules/{ruleId}", + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Guild, + Id = guildId + } + ) + .WithRoute($"guilds/{guildId}/auto-moderation/rules/:rule-id") + .WithAuditLogReason(reason), + info, + ct + ); + } +} From d3fab9e7f8c3d59b5b989366a785553d203b6fcd Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Mon, 8 Jan 2024 21:30:25 +0100 Subject: [PATCH 253/323] implement channels --- .../API/IChannelRestAPI.cs | 12 +- .../Channels/IBulkDeleteMessagesPayload.cs | 18 + .../ListJoinedPrivateArchivedThreadsQuery.cs | 21 + .../API/ChannelRestAPI.cs | 1588 +++++++++++++++++ .../Channels/BulkDeleteMessagesPayload.cs | 16 + 5 files changed, 1649 insertions(+), 6 deletions(-) create mode 100644 src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Channels/IBulkDeleteMessagesPayload.cs create mode 100644 src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Channels/ListJoinedPrivateArchivedThreadsQuery.cs create mode 100644 src/core/DSharpPlus.Internal.Rest/API/ChannelRestAPI.cs create mode 100644 src/core/DSharpPlus.Internal.Rest/Payloads/Channels/BulkDeleteMessagesPayload.cs diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IChannelRestAPI.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IChannelRestAPI.cs index a5e9766aee..dbec40f7fa 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IChannelRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IChannelRestAPI.cs @@ -314,7 +314,7 @@ public ValueTask DeleteMessageAsync /// Bulk-deletes the provided messages. /// /// The snowflake identifier of the message's parent channel. - /// + /// /// Up to 100 message IDs to delete. If any messages older than two weeks are included, /// or any of the IDs are duplicated, the entire request will fail. /// @@ -325,7 +325,7 @@ public ValueTask DeleteMessageAsync public ValueTask BulkDeleteMessagesAsync ( Snowflake channelId, - IReadOnlyList messageIds, + IBulkDeleteMessagesPayload payload, string? reason = null, RequestInfo info = default, CancellationToken ct = default @@ -588,12 +588,12 @@ public ValueTask JoinThreadAsync /// /// Adds another member into a thread. /// - /// The nowflake identifier of the thread to be joined. + /// The snowflake identifier of the thread to be joined. /// The snowflake identifier of the user to join into the thread. /// Additional instructions regarding this request. /// A cancellation token for this operation. /// Whether the operation was successful. - public ValueTask AddToThreadAsync + public ValueTask AddThreadMemberAsync ( Snowflake threadId, Snowflake userId, @@ -623,7 +623,7 @@ public ValueTask LeaveThreadAsync /// Additional instructions regarding this request. /// A cancellation token for this operation. /// Whether the operation was successful. - public ValueTask RemoveFromThreadAsync + public ValueTask RemoveThreadMemberAsync ( Snowflake threadId, Snowflake userId, @@ -707,7 +707,7 @@ public ValueTask> ListPrivateArchivedThreads public ValueTask> ListJoinedPrivateArchivedThreadsAsync ( Snowflake channelId, - ListArchivedThreadsQuery query = default, + ListJoinedPrivateArchivedThreadsQuery query = default, RequestInfo info = default, CancellationToken ct = default ); diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Channels/IBulkDeleteMessagesPayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Channels/IBulkDeleteMessagesPayload.cs new file mode 100644 index 0000000000..9f38eff052 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Channels/IBulkDeleteMessagesPayload.cs @@ -0,0 +1,18 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +namespace DSharpPlus.Internal.Abstractions.Rest.Payloads; + +/// +/// Represents a payload to POST /channels/:channel-id/messages/bulk-delete. +/// +public interface IBulkDeleteMessagesPayload +{ + /// + /// The message IDs to bulk delete, between 2 and 100. + /// + public IReadOnlyList Messages { get; } +} diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Channels/ListJoinedPrivateArchivedThreadsQuery.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Channels/ListJoinedPrivateArchivedThreadsQuery.cs new file mode 100644 index 0000000000..319b066c89 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Channels/ListJoinedPrivateArchivedThreadsQuery.cs @@ -0,0 +1,21 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Internal.Abstractions.Rest.Queries; + +/// +/// Contains the query parameters for listing joined private archived threads, specifically. +/// +public readonly record struct ListJoinedPrivateArchivedThreadsQuery +{ + /// + /// A snowflake to filter threads by: only threads archived before this timestamp will be returned. + /// + public Snowflake? Before { get; init; } + + /// + /// The maximum number of threads to return from this request. + /// + public int? Limit { get; init; } +} diff --git a/src/core/DSharpPlus.Internal.Rest/API/ChannelRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/ChannelRestAPI.cs new file mode 100644 index 0000000000..8f0ed0c775 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Rest/API/ChannelRestAPI.cs @@ -0,0 +1,1588 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +#pragma warning disable IDE0046 + +using System.Collections.Generic; +using System.Globalization; +using System.Net.Http; +using System.Threading; +using System.Threading.Tasks; + +using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Rest; +using DSharpPlus.Internal.Abstractions.Rest.API; +using DSharpPlus.Internal.Abstractions.Rest.Errors; +using DSharpPlus.Internal.Abstractions.Rest.Payloads; +using DSharpPlus.Internal.Abstractions.Rest.Queries; +using DSharpPlus.Internal.Abstractions.Rest.Responses; +using DSharpPlus.Internal.Rest.Ratelimiting; + +using Remora.Results; + +namespace DSharpPlus.Internal.Rest.API; + +/// +public sealed class ChannelRestAPI +( + IRestClient restClient +) + : IChannelRestAPI +{ + /// + public async ValueTask AddThreadMemberAsync + ( + Snowflake threadId, + Snowflake userId, + RequestInfo info = default, + CancellationToken ct = default + ) + { + Result response = await restClient.ExecuteRequestAsync + ( + HttpMethod.Put, + $"channels/{threadId}/thread-members/{userId}", + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Channel, + Id = threadId + } + ) + .WithRoute($"channels/{threadId}/thread-members/:user-id"), + info, + ct + ); + + return (Result)response; + } + + /// + public async ValueTask BulkDeleteMessagesAsync + ( + Snowflake channelId, + IBulkDeleteMessagesPayload payload, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ) + { + Result response = await restClient.ExecuteRequestAsync + ( + HttpMethod.Post, + $"channels/{channelId}/messages/bulk-delete", + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Channel, + Id = channelId + } + ) + .WithRoute($"channels/{channelId}/messages/bulk-delete") + .WithPayload(payload) + .WithAuditLogReason(reason), + info, + ct + ); + + return (Result)response; + } + + /// + public async ValueTask> CreateChannelInviteAsync + ( + Snowflake channelId, + ICreateChannelInvitePayload payload, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ) + { + if (payload.MaxAge.HasValue && payload.MaxAge.Value is < 0 or > 604800) + { + return new ValidationError + ( + "The maximum age of an invite must be between 0 and 604800 seconds. A maximum age of 0 makes it never expire." + ); + } + + if (payload.MaxUses.HasValue && payload.MaxUses.Value is < 0 or > 100) + { + return new ValidationError + ( + "The maximum use count of an invite must be between 0 and 100. A value of 0 makes it unlimited." + ); + } + + if (payload.TargetType.TryGetNonNullValue(out DiscordInviteTargetType type)) + { + if (type == DiscordInviteTargetType.Stream && !payload.TargetUserId.HasValue) + { + return new ValidationError("A target type of Stream requires a streaming user as target."); + } + + if (type == DiscordInviteTargetType.EmbeddedApplication && !payload.TargetApplicationId.HasValue) + { + return new ValidationError("A target type of EmbeddedApplication requires an application as target."); + } + } + + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Post, + $"channels/{channelId}/invites", + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Channel, + Id = channelId + } + ) + .WithRoute($"channels/{channelId}/invites") + .WithPayload(payload) + .WithAuditLogReason(reason), + info, + ct + ); + } + + /// + public async ValueTask> CreateMessageAsync + ( + Snowflake channelId, + ICreateMessagePayload payload, + RequestInfo info = default, + CancellationToken ct = default + ) + { + if + ( + !(payload.Content.HasValue || payload.Embeds.HasValue || payload.StickerIds.HasValue + || payload.Components.HasValue || payload.Files is not null) + ) + { + return new ValidationError + ( + "At least one of Content, Embeds, StickerIds, Components or Files must be sent." + ); + } + + if (payload.Content.HasValue && payload.Content.Value.Length > 2000) + { + return new ValidationError("The content of a message cannot exceed 2000 characters."); + } + + if (payload.Nonce.HasValue && payload.Nonce.Value.Length > 25) + { + return new ValidationError("The nonce of a message cannot exceed 25 characters."); + } + + if (payload.Embeds.HasValue && payload.Embeds.Value.Count > 10) + { + return new ValidationError("Only up to 10 embeds can be sent with a message."); + } + + if (payload.StickerIds.HasValue && payload.StickerIds.Value.Count > 3) + { + return new ValidationError("Only up to 3 stickers can be sent with a message."); + } + + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Post, + $"channels/{channelId}/messages", + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Channel, + Id = channelId + } + ) + .WithRoute($"channels/{channelId}/messages") + .WithPayload(payload), + info, + ct + ); + } + + /// + public async ValueTask CreateReactionAsync + ( + Snowflake channelId, + Snowflake messageId, + string emoji, + RequestInfo info = default, + CancellationToken ct = default + ) + { + Result response = await restClient.ExecuteRequestAsync + ( + HttpMethod.Put, + $"channels/{channelId}/messages/{messageId}/reactions/{emoji}/@me", + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Channel, + Id = channelId + } + ) + .WithRoute($"channels/{channelId}/messages/:message-id/reactions/:emoji/@me"), + info, + ct + ); + + return (Result)response; + } + + /// + public async ValueTask> CrosspostMessageAsync + ( + Snowflake channelId, + Snowflake messageId, + RequestInfo info = default, + CancellationToken ct = default + ) + { + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Post, + $"channels/{channelId}/messages/{messageId}/crosspost", + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Channel, + Id = channelId + } + ) + .WithRoute($"channels/{channelId}/messages/:message-id/crosspost"), + info, + ct + ); + } + + /// + public async ValueTask DeleteAllReactionsAsync + ( + Snowflake channelId, + Snowflake messageId, + RequestInfo info = default, + CancellationToken ct = default + ) + { + Result response = await restClient.ExecuteRequestAsync + ( + HttpMethod.Delete, + $"channels/{channelId}/messages/{messageId}/reactions", + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Channel, + Id = channelId + } + ) + .WithRoute($"channels/{channelId}/messages/:message-id/reactions"), + info, + ct + ); + + return (Result)response; + } + + /// + public async ValueTask DeleteAllReactionsForEmojiAsync + ( + Snowflake channelId, + Snowflake messageId, + string emoji, + RequestInfo info = default, + CancellationToken ct = default + ) + { + Result response = await restClient.ExecuteRequestAsync + ( + HttpMethod.Delete, + $"channels/{channelId}/messages/{messageId}/reactions/{emoji}", + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Channel, + Id = channelId + } + ) + .WithRoute($"channels/{channelId}/messages/:message-id/reactions/:emoji"), + info, + ct + ); + + return (Result)response; + } + + /// + public async ValueTask> DeleteChannelAsync + ( + Snowflake channelId, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ) + { + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Delete, + $"channels/{channelId}", + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Channel, + Id = channelId + } + ) + .WithRoute($"channels/{channelId}") + .WithAuditLogReason(reason), + info, + ct + ); + } + + /// + public async ValueTask DeleteChannelPermissionAsync + ( + Snowflake channelId, + Snowflake overwriteId, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ) + { + Result response = await restClient.ExecuteRequestAsync + ( + HttpMethod.Delete, + $"channels/{channelId}/permissions/{overwriteId}", + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Channel, + Id = channelId + } + ) + .WithRoute($"channels/{channelId}/permissions/:overwrite-id") + .WithAuditLogReason(reason), + info, + ct + ); + + return (Result)response; + } + + /// + public async ValueTask DeleteMessageAsync + ( + Snowflake channelId, + Snowflake messageId, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ) + { + Result response = await restClient.ExecuteRequestAsync + ( + HttpMethod.Delete, + $"channels/{channelId}/messages/{messageId}", + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Channel, + Id = channelId + } + ) + .WithRoute($"channels/{channelId}/messages/:message-id") + .WithAuditLogReason(reason), + info, + ct + ); + + return (Result)response; + } + + /// + public async ValueTask DeleteOwnReactionAsync + ( + Snowflake channelId, + Snowflake messageId, + string emoji, + RequestInfo info = default, + CancellationToken ct = default + ) + { + Result response = await restClient.ExecuteRequestAsync + ( + HttpMethod.Delete, + $"channels/{channelId}/messages/{messageId}/reactions/{emoji}/@me", + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Channel, + Id = channelId + } + ) + .WithRoute($"channels/{channelId}/messages/:message-id/reactions/:emoji/@me"), + info, + ct + ); + + return (Result)response; + } + + /// + public async ValueTask DeleteUserReactionAsync + ( + Snowflake channelId, + Snowflake messageId, + Snowflake userId, + string emoji, + RequestInfo info = default, + CancellationToken ct = default + ) + { + Result response = await restClient.ExecuteRequestAsync + ( + HttpMethod.Delete, + $"channels/{channelId}/messages/{messageId}/reactions/{emoji}/{userId}", + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Channel, + Id = channelId + } + ) + .WithRoute($"channels/{channelId}/messages/:message-id/reactions/:emoji/:user-id"), + info, + ct + ); + + return (Result)response; + } + + /// + public async ValueTask EditChannelPermissionsAsync + ( + Snowflake channelId, + Snowflake overwriteId, + IEditChannelPermissionsPayload payload, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ) + { + Result response = await restClient.ExecuteRequestAsync + ( + HttpMethod.Put, + $"channels/{channelId}/permissions/{overwriteId}", + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Channel, + Id = channelId + } + ) + .WithRoute($"channels/{channelId}/permissions/:overwrite-id") + .WithPayload(payload) + .WithAuditLogReason(reason), + info, + ct + ); + + return (Result)response; + } + + /// + public async ValueTask> EditMessageAsync + ( + Snowflake channelId, + Snowflake messageId, + IEditMessagePayload payload, + RequestInfo info = default, + CancellationToken ct = default + ) + { + if (payload.Content.TryGetNonNullValue(out string? content) && content.Length > 2000) + { + return new ValidationError("The content of a message cannot exceed 2000 characters."); + } + + if (payload.Embeds.TryGetNonNullValue(out IReadOnlyList? embeds) && embeds.Count > 10) + { + return new ValidationError("A message can only have up to 10 embeds."); + } + + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Patch, + $"channels/{channelId}/messages/{messageId}", + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Channel, + Id = channelId + } + ) + .WithRoute($"channels/{channelId}/messages/:message-id") + .WithPayload(payload), + info, + ct + ); + } + + /// + public async ValueTask> FollowAnnouncementChannelAsync + ( + Snowflake channelId, + IFollowAnnouncementChannelPayload payload, + RequestInfo info = default, + CancellationToken ct = default + ) + { + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Post, + $"channels/{channelId}/followers", + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Channel, + Id = channelId + } + ) + .WithRoute($"channels/{channelId}/followers") + .WithPayload(payload), + info, + ct + ); + } + + /// + public async ValueTask> GetChannelAsync + ( + Snowflake channelId, + RequestInfo info = default, + CancellationToken ct = default + ) + { + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Get, + $"channels/{channelId}", + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Channel, + Id = channelId + } + ), + info, + ct + ); + } + + /// + public async ValueTask>> GetChannelInvitesAsync + ( + Snowflake channelId, + RequestInfo info = default, + CancellationToken ct = default + ) + { + return await restClient.ExecuteRequestAsync> + ( + HttpMethod.Get, + $"channels/{channelId}", + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Channel, + Id = channelId + } + ), + info, + ct + ); + } + + /// + public async ValueTask> GetChannelMessageAsync + ( + Snowflake channelId, + Snowflake messageId, + RequestInfo info = default, + CancellationToken ct = default + ) + { + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Get, + $"channels/{channelId}/messages/{messageId}", + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Channel, + Id = channelId + } + ) + .WithRoute($"channels/{channelId}/messages/:message-id"), + info, + ct + ); + } + + /// + public async ValueTask>> GetChannelMessagesAsync + ( + Snowflake channelId, + GetChannelMessagesQuery query = default, + RequestInfo info = default, + CancellationToken ct = default + ) + { + if (query.Limit is not null and (< 1 or > 100)) + { + return new ValidationError("The limit for messages to request at once must be between 1 and 100."); + } + + QueryBuilder builder = new() + { + RootUri = $"channels/{channelId}/messages" + }; + + if (query.Limit is not null) + { + builder.AddParameter("limit", query.Limit.Value.ToString(CultureInfo.InvariantCulture)); + } + + if (query.Around is not null) + { + builder.AddParameter("around", query.Around.Value.ToString()); + } + else if (query.Before is not null) + { + builder.AddParameter("before", query.Before.Value.ToString()); + } + else if (query.After is not null) + { + builder.AddParameter("after", query.After.Value.ToString()); + } + + return await restClient.ExecuteRequestAsync> + ( + HttpMethod.Get, + builder.Build(), + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Channel, + Id = channelId + } + ) + .WithRoute($"channels/{channelId}/messages"), + info, + ct + ); + } + + /// + public async ValueTask>> GetPinnedMessagesAsync + ( + Snowflake channelId, + RequestInfo info = default, + CancellationToken ct = default + ) + { + return await restClient.ExecuteRequestAsync> + ( + HttpMethod.Get, + $"channels/{channelId}/pins", + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Channel, + Id = channelId + } + ) + .WithRoute($"channels/{channelId}/pins"), + info, + ct + ); + } + + /// + public async ValueTask>> GetReactionsAsync + ( + Snowflake channelId, + Snowflake messageId, + string emoji, + ForwardsPaginatedQuery query = default, + RequestInfo info = default, + CancellationToken ct = default + ) + { + if (query.Limit is not null and (< 1 or > 100)) + { + return new ValidationError("The limit of reactions to request must be between 1 and 100."); + } + + QueryBuilder builder = new() + { + RootUri = $"channels/{channelId}/messages/{messageId}/reactions/{emoji}" + }; + + if (query.After is not null) + { + builder.AddParameter("after", query.After.Value.ToString()); + } + + return await restClient.ExecuteRequestAsync> + ( + HttpMethod.Get, + builder.Build(), + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Channel, + Id = channelId + } + ) + .WithRoute($"channels/{channelId}/messages/:message-id/reactions/:emoji"), + info, + ct + ); + } + + /// + public async ValueTask> GetThreadMemberAsync + ( + Snowflake threadId, + Snowflake userId, + GetThreadMemberQuery query = default, + RequestInfo info = default, + CancellationToken ct = default + ) + { + QueryBuilder builder = new() + { + RootUri = $"channels/{threadId}/thread-members/{userId}" + }; + + if (query.WithMember is not null) + { + builder.AddParameter("after", query.WithMember.Value.ToString().ToLowerInvariant()); + } + + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Get, + builder.Build(), + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Channel, + Id = threadId + } + ) + .WithRoute($"channels/{threadId}/thread-members/:user-id"), + info, + ct + ); + } + + /// + public async ValueTask GroupDMAddRecipientAsync + ( + Snowflake channelId, + Snowflake userId, + IGroupDMAddRecipientPayload payload, + RequestInfo info = default, + CancellationToken ct = default + ) + { + Result response = await restClient.ExecuteRequestAsync + ( + HttpMethod.Put, + $"channels/{channelId}/recipients/{userId}", + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Channel, + Id = channelId + } + ) + .WithRoute($"channels/{channelId}/recipients/:user-id") + .WithPayload(payload), + info, + ct + ); + + return (Result)response; + } + + /// + public async ValueTask GroupDMRemoveRecipientAsync + ( + Snowflake channelId, + Snowflake userId, + RequestInfo info = default, + CancellationToken ct = default + ) + { + Result response = await restClient.ExecuteRequestAsync + ( + HttpMethod.Delete, + $"channels/{channelId}/recipients/{userId}", + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Channel, + Id = channelId + } + ) + .WithRoute($"channels/{channelId}/recipients/:user-id"), + info, + ct + ); + + return (Result)response; + } + + /// + public async ValueTask JoinThreadAsync + ( + Snowflake threadId, + RequestInfo info = default, + CancellationToken ct = default + ) + { + Result response = await restClient.ExecuteRequestAsync + ( + HttpMethod.Put, + $"channels/{threadId}/recipients/@me", + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Channel, + Id = threadId + } + ) + .WithRoute($"channels/{threadId}/recipients/@me"), + info, + ct + ); + + return (Result)response; + } + + /// + public async ValueTask LeaveThreadAsync + ( + Snowflake threadId, + RequestInfo info = default, + CancellationToken ct = default + ) + { + Result response = await restClient.ExecuteRequestAsync + ( + HttpMethod.Delete, + $"channels/{threadId}/recipients/@me", + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Channel, + Id = threadId + } + ) + .WithRoute($"channels/{threadId}/recipients/@me"), + info, + ct + ); + + return (Result)response; + } + + /// + public async ValueTask> ListJoinedPrivateArchivedThreadsAsync + ( + Snowflake channelId, + ListJoinedPrivateArchivedThreadsQuery query = default, + RequestInfo info = default, + CancellationToken ct = default + ) + { + if (query.Limit is not null and (< 1 or > 100)) + { + return new ValidationError("The limit of threads to return must be between 1 and 100."); + } + + QueryBuilder builder = new() + { + RootUri = $"channels/{channelId}/users/@me/threads/archived/private" + }; + + if (query.Limit is not null) + { + builder.AddParameter("limit", query.Limit.Value.ToString(CultureInfo.InvariantCulture)); + } + + if (query.Before is not null) + { + builder.AddParameter("before", query.Before.Value.ToString()); + } + + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Get, + builder.Build(), + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Channel, + Id = channelId + } + ) + .WithRoute($"channels/{channelId}/users/@me/threads/archived/private"), + info, + ct + ); + } + + /// + public async ValueTask> ListPrivateArchivedThreadsAsync + ( + Snowflake channelId, + ListArchivedThreadsQuery query = default, + RequestInfo info = default, + CancellationToken ct = default + ) + { + if (query.Limit is not null and (< 1 or > 100)) + { + return new ValidationError("The limit of threads to return must be between 1 and 100."); + } + + QueryBuilder builder = new() + { + RootUri = $"channels/{channelId}/users/@me/threads/archived/private" + }; + + if (query.Limit is not null) + { + builder.AddParameter("limit", query.Limit.Value.ToString(CultureInfo.InvariantCulture)); + } + + if (query.Before is not null) + { + builder.AddParameter("before", query.Before.Value.ToString("o", CultureInfo.InvariantCulture)); + } + + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Get, + builder.Build(), + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Channel, + Id = channelId + } + ) + .WithRoute($"channels/{channelId}/users/@me/threads/archived/private"), + info, + ct + ); + } + + /// + public async ValueTask> ListPublicArchivedThreadsAsync + ( + Snowflake channelId, + ListArchivedThreadsQuery query = default, + RequestInfo info = default, + CancellationToken ct = default + ) + { + if (query.Limit is not null and (< 1 or > 100)) + { + return new ValidationError("The limit of threads to return must be between 1 and 100."); + } + + QueryBuilder builder = new() + { + RootUri = $"channels/{channelId}/threads/archived/public" + }; + + if (query.Limit is not null) + { + builder.AddParameter("limit", query.Limit.Value.ToString(CultureInfo.InvariantCulture)); + } + + if (query.Before is not null) + { + builder.AddParameter("before", query.Before.Value.ToString("o", CultureInfo.InvariantCulture)); + } + + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Get, + builder.Build(), + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Channel, + Id = channelId + } + ) + .WithRoute($"channels/{channelId}/threads/archived/public"), + info, + ct + ); + } + + /// + public async ValueTask>> ListThreadMembersAsync + ( + Snowflake threadId, + ListThreadMembersQuery query = default, + RequestInfo info = default, + CancellationToken ct = default + ) + { + if (query.Limit is not null and (< 1 or > 100)) + { + return new ValidationError("The limit of threads to return must be between 1 and 100."); + } + + QueryBuilder builder = new() + { + RootUri = $"channels/{threadId}/thread-members" + }; + + if (query.Limit is not null) + { + builder.AddParameter("limit", query.Limit.Value.ToString(CultureInfo.InvariantCulture)); + } + + if (query.After is not null) + { + builder.AddParameter("after", query.After.Value.ToString()); + } + + if (query.WithMember is not null) + { + builder.AddParameter("with_member", query.WithMember.Value.ToString().ToLowerInvariant()); + } + + return await restClient.ExecuteRequestAsync> + ( + HttpMethod.Get, + builder.Build(), + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Channel, + Id = threadId + } + ) + .WithRoute($"channels/{threadId}/thread-members"), + info, + ct + ); + } + + /// + public async ValueTask> ModifyChannelAsync + ( + Snowflake channelId, + IModifyGroupDMPayload payload, + RequestInfo info = default, + CancellationToken ct = default + ) + { + if (payload.Name.HasValue && payload.Name.Value.Length > 100) + { + return new ValidationError("The name of a channel cannot exceed 100 characters."); + } + + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Patch, + $"channels/{channelId}", + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Channel, + Id = channelId + } + ), + info, + ct + ); + } + + /// + public async ValueTask> ModifyChannelAsync + ( + Snowflake channelId, + IModifyGuildChannelPayload payload, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ) + { + if (payload.Name.HasValue && payload.Name.Value.Length > 100) + { + return new ValidationError("The name of a channel cannot exceed 100 characters."); + } + + if (payload.RateLimitPerUser.HasValue && payload.RateLimitPerUser.Value is < 0 or > 21600) + { + return new ValidationError + ( + "The slowmode (rate limit per user) in a channel must be between 0 and 6 hours, or 21600 seconds." + ); + } + + if (payload.Bitrate.TryGetNonNullValue(out int? value) && value < 8000) + { + return new ValidationError("The bitrate of a voice channel cannot be below 8000."); + } + + if (payload.UserLimit.TryGetNonNullValue(out int? userLimit)) + { + if (payload.Type.HasValue && payload.Type == DiscordChannelType.GuildVoice && userLimit > 99) + { + return new ValidationError("The user limit of a voice channel cannot exceed 99."); + } + + if (userLimit > 10000) + { + return new ValidationError("The user limit of a stage channel cannot exceed 10,000."); + } + } + + if (payload.DefaultThreadRateLimitPerUser.HasValue && payload.DefaultThreadRateLimitPerUser.Value is < 0 or > 21600) + { + return new ValidationError + ( + "The default slowmode (rate limit per user) for threads must be between 0 and 6 hours, or 21600 seconds." + ); + } + + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Patch, + $"channels/{channelId}", + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Channel, + Id = channelId + } + ) + .WithAuditLogReason(reason), + info, + ct + ); + } + + /// + public async ValueTask> ModifyChannelAsync + ( + Snowflake channelId, + IModifyThreadChannelPayload payload, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ) + { + if (payload.Name.HasValue && payload.Name.Value.Length > 100) + { + return new ValidationError("The name of a channel cannot exceed 100 characters."); + } + + if (payload.RateLimitPerUser.HasValue && payload.RateLimitPerUser.Value is < 0 or > 21600) + { + return new ValidationError + ( + "The slowmode (rate limit per user) in a channel must be between 0 and 6 hours, or 21600 seconds." + ); + } + + if (payload.AutoArchiveDuration.HasValue && !(payload.AutoArchiveDuration.Value is 60 or 1440 or 4320 or 10080)) + { + return new ValidationError + ( + "The auto-archive duration of a thread must be either 60, 1440, 4320 or 10080 minutes." + ); + } + + if (payload.AppliedTags.HasValue && payload.AppliedTags.Value.Count > 5) + { + return new ValidationError("A thread can only have up to five tags applied."); + } + + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Patch, + $"channels/{channelId}", + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Channel, + Id = channelId + } + ) + .WithAuditLogReason(reason), + info, + ct + ); + } + + /// + public async ValueTask PinMessageAsync + ( + Snowflake channelId, + Snowflake messageId, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ) + { + Result response = await restClient.ExecuteRequestAsync + ( + HttpMethod.Put, + $"channels/{channelId}/pins/{messageId}", + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Channel, + Id = channelId + } + ) + .WithAuditLogReason(reason) + .WithRoute($"channels/{channelId}/pins/:message-id"), + info, + ct + ); + + return (Result)response; + } + + /// + public async ValueTask RemoveThreadMemberAsync + ( + Snowflake threadId, + Snowflake userId, + RequestInfo info = default, + CancellationToken ct = default + ) + { + Result response = await restClient.ExecuteRequestAsync + ( + HttpMethod.Delete, + $"channels/{threadId}/thread-members/{userId}", + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Channel, + Id = threadId + } + ) + .WithRoute($"channels/{threadId}/thread-members/:user-id"), + info, + ct + ); + + return (Result)response; + } + + /// + public async ValueTask> StartThreadFromMessageAsync + ( + Snowflake channelId, + Snowflake messageId, + IStartThreadFromMessagePayload payload, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ) + { + if (payload.Name.Length > 100) + { + return new ValidationError("The name of a channel cannot exceed 100 characters."); + } + + if (payload.RateLimitPerUser.HasValue && payload.RateLimitPerUser.Value is < 0 or > 21600) + { + return new ValidationError + ( + "The slowmode (rate limit per user) in a channel must be between 0 and 6 hours, or 21600 seconds." + ); + } + + if (payload.AutoArchiveDuration.HasValue && !(payload.AutoArchiveDuration.Value is 60 or 1440 or 4320 or 10080)) + { + return new ValidationError + ( + "The auto-archive duration of a thread must be either 60, 1440, 4320 or 10080 minutes." + ); + } + + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Post, + $"channels/{channelId}/messages/{messageId}/threads", + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Channel, + Id = channelId + } + ) + .WithRoute($"channels/{channelId}/messages/:message-id/threads") + .WithPayload(payload) + .WithAuditLogReason(reason), + info, + ct + ); + } + + /// + public async ValueTask> StartThreadInForumOrMediaChannelAsync + ( + Snowflake channelId, + IStartThreadInForumOrMediaChannelPayload payload, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ) + { + if (payload.Name.Length > 100) + { + return new ValidationError("The name of a channel cannot exceed 100 characters."); + } + + if (payload.RateLimitPerUser.HasValue && payload.RateLimitPerUser.Value is < 0 or > 21600) + { + return new ValidationError + ( + "The slowmode (rate limit per user) in a channel must be between 0 and 6 hours, or 21600 seconds." + ); + } + + if (payload.AutoArchiveDuration.HasValue && !(payload.AutoArchiveDuration.Value is 60 or 1440 or 4320 or 10080)) + { + return new ValidationError + ( + "The auto-archive duration of a thread must be either 60, 1440, 4320 or 10080 minutes." + ); + } + + if (payload.AppliedTags.HasValue && payload.AppliedTags.Value.Count > 5) + { + return new ValidationError("A thread can only have up to five tags applied to it."); + } + + if + ( + !(payload.Message.Content.HasValue + || payload.Message.Embeds.HasValue + || payload.Message.StickerIds.HasValue + || payload.Message.Components.HasValue + || payload.Files is not null) + ) + { + return new ValidationError + ( + "At least one of Content, Embeds, StickerIds, Components or Files must be sent." + ); + } + + if (payload.Message.Content.HasValue && payload.Message.Content.Value.Length > 2000) + { + return new ValidationError("The content of a message cannot exceed 2000 characters."); + } + + if (payload.Message.Embeds.HasValue && payload.Message.Embeds.Value.Count > 10) + { + return new ValidationError("Only up to 10 embeds can be sent with a message."); + } + + if (payload.Message.StickerIds.HasValue && payload.Message.StickerIds.Value.Count > 3) + { + return new ValidationError("Only up to 3 stickers can be sent with a message."); + } + + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Post, + $"channels/{channelId}/threads", + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Channel, + Id = channelId + } + ) + .WithRoute($"channels/{channelId}/threads") + .WithPayload(payload) + .WithAuditLogReason(reason), + info, + ct + ); + } + + /// + public async ValueTask> StartThreadWithoutMessageAsync + ( + Snowflake channelId, + IStartThreadWithoutMessagePayload payload, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ) + { + if (payload.Name.Length > 100) + { + return new ValidationError("The name of a channel cannot exceed 100 characters."); + } + + if (payload.RateLimitPerUser.HasValue && payload.RateLimitPerUser.Value is < 0 or > 21600) + { + return new ValidationError + ( + "The slowmode (rate limit per user) in a channel must be between 0 and 6 hours, or 21600 seconds." + ); + } + + if (payload.AutoArchiveDuration.HasValue && !(payload.AutoArchiveDuration.Value is 60 or 1440 or 4320 or 10080)) + { + return new ValidationError + ( + "The auto-archive duration of a thread must be either 60, 1440, 4320 or 10080 minutes." + ); + } + + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Post, + $"channels/{channelId}/threads", + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Channel, + Id = channelId + } + ) + .WithRoute($"channels/{channelId}/threads") + .WithPayload(payload) + .WithAuditLogReason(reason), + info, + ct + ); + } + + /// + public async ValueTask TriggerTypingIndicatorAsync + ( + Snowflake channelId, + RequestInfo info = default, + CancellationToken ct = default + ) + { + Result response = await restClient.ExecuteRequestAsync + ( + HttpMethod.Post, + $"channels/{channelId}/typing", + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Channel, + Id = channelId + } + ) + .WithRoute($"channels/{channelId}/typing"), + info, + ct + ); + + return (Result)response; + } + + /// + public async ValueTask UnpinMessageAsync + ( + Snowflake channelId, + Snowflake messageId, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ) + { + Result response = await restClient.ExecuteRequestAsync + ( + HttpMethod.Delete, + $"channels/{channelId}/pins/{messageId}", + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Channel, + Id = channelId + } + ) + .WithRoute($"channels/{channelId}/pins/:message-id"), + info, + ct + ); + + return (Result)response; + } +} diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/BulkDeleteMessagesPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/BulkDeleteMessagesPayload.cs new file mode 100644 index 0000000000..af1c9237cb --- /dev/null +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/BulkDeleteMessagesPayload.cs @@ -0,0 +1,16 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Internal.Abstractions.Rest.Payloads; + +namespace DSharpPlus.Internal.Rest.Payloads; + +/// +public sealed record BulkDeleteMessagesPayload : IBulkDeleteMessagesPayload +{ + /// + public required IReadOnlyList Messages { get; init; } +} \ No newline at end of file From 47ad545c36375158ecdb102c61081216a6e2de81 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Mon, 8 Jan 2024 22:07:57 +0100 Subject: [PATCH 254/323] ratelimits suck, part 1/5 --- .../API/ApplicationCommandsRestAPI.cs | 42 ++++++++++++------- .../RequestBuilderExtensions.cs | 6 +++ 2 files changed, 34 insertions(+), 14 deletions(-) diff --git a/src/core/DSharpPlus.Internal.Rest/API/ApplicationCommandsRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/ApplicationCommandsRestAPI.cs index f99e3fd1ec..ac111851d2 100644 --- a/src/core/DSharpPlus.Internal.Rest/API/ApplicationCommandsRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Rest/API/ApplicationCommandsRestAPI.cs @@ -83,7 +83,8 @@ public async ValueTask>> BulkOverwrite Route = "applications/:application-id/commands" } ) - .WithPayload(payload), + .WithPayload(payload) + .WithFullRatelimit("PUT applications/:application-id/commands"), info, ct ); @@ -140,7 +141,8 @@ public async ValueTask>> BulkOverwrite Route = "applications/:application-id/guilds/:guild-id/commands" } ) - .WithPayload(payload), + .WithPayload(payload) + .WithFullRatelimit("PUT applications/:application-id/guilds/:guild-id/commands"), info, ct ); @@ -188,7 +190,8 @@ public async ValueTask> CreateGlobalApp Route = "applications/:application-id/commands" } ) - .WithPayload(payload), + .WithPayload(payload) + .WithFullRatelimit("POST applications/:application-id/commands"), info, ct ); @@ -251,7 +254,8 @@ public async ValueTask> CreateGuildAppl Route = "applications/:application-id/guilds/:guild-id/commands" } ) - .WithPayload(payload), + .WithPayload(payload) + .WithFullRatelimit("POST applications/:application-id/guilds/:guild-id/commands"), info, ct ); @@ -292,7 +296,8 @@ public async ValueTask DeleteGlobalApplicationCommandAsync Resource = TopLevelResource.Other, Route = "applications/:application-id/commands/:command-id" } - ), + ) + .WithFullRatelimit("DELETE applications/:application-id/commands/:command-id"), info, ct ); @@ -322,7 +327,8 @@ public async ValueTask DeleteGuildApplicationCommandAsync Resource = TopLevelResource.Other, Route = "applications/:application-id/guilds/:guild-id/commands/:command-id" } - ), + ) + .WithFullRatelimit("DELETE applications/:application-id/guilds/:guild-id/commands/:command-id"), info, ct ); @@ -373,7 +379,8 @@ public async ValueTask> EditGlobalApplicationCommand Route = "applications/:application-id/commands/:command-id" } ) - .WithPayload(payload), + .WithPayload(payload) + .WithFullRatelimit("PATCH applications/:application-id/commands/:command-id"), info, ct ); @@ -423,7 +430,8 @@ public async ValueTask> EditGuildApplicationCommandA Route = "applications/:application-id/guilds/:guild-id/commands/:command-id" } ) - .WithPayload(payload), + .WithPayload(payload) + .WithFullRatelimit("PATCH applications/:application-id/guilds/:guild-id/commands/:command-id"), info, ct ); @@ -451,7 +459,8 @@ public async ValueTask> GetApplicationCom Resource = TopLevelResource.Other, Route = "applications/:application-id/guilds/:guild-id/commands/:command-id/permissions" } - ), + ) + .WithFullRatelimit("GET applications/:application-id/guilds/:guild-id/commands/:command-id/permissions"), info, ct ); @@ -478,7 +487,8 @@ public async ValueTask> GetGlobalApplicationCommandA Resource = TopLevelResource.Other, Route = "applications/:application-id/commands/:command-id" } - ), + ) + .WithFullRatelimit("GET applications/:application-id/commands/:command-id"), info, ct ); @@ -515,7 +525,8 @@ public async ValueTask>> GetGlobalAppl Resource = TopLevelResource.Other, Route = "applications/:application-id/commands" } - ), + ) + .WithFullRatelimit("GET applications/:application-id/commands"), info, ct ); @@ -543,7 +554,8 @@ public async ValueTask> GetGuildApplicationCommandAs Resource = TopLevelResource.Other, Route = "applications/:application-id/guilds/:guild-id/commands/:command-id" } - ), + ) + .WithFullRatelimit("GET applications/:application-id/guilds/:guild-id/commands/:command-id"), info, ct ); @@ -570,7 +582,8 @@ public async ValueTask>> Ge Resource = TopLevelResource.Other, Route = "applications/:application-id/guilds/:guild-id/commands/permissions" } - ), + ) + .WithFullRatelimit("GET applications/:application-id/guilds/:guild-id/commands/permissions"), info, ct ); @@ -608,7 +621,8 @@ public async ValueTask>> GetGuildAppli Resource = TopLevelResource.Other, Route = "applications/:application-id/guilds/:guild-id/commands" } - ), + ) + .WithFullRatelimit("GET applications/:application-id/guilds/:guild-id/commands"), info, ct ); diff --git a/src/core/DSharpPlus.Internal.Rest/RequestBuilderExtensions.cs b/src/core/DSharpPlus.Internal.Rest/RequestBuilderExtensions.cs index cb710dee42..ed62f59e89 100644 --- a/src/core/DSharpPlus.Internal.Rest/RequestBuilderExtensions.cs +++ b/src/core/DSharpPlus.Internal.Rest/RequestBuilderExtensions.cs @@ -15,6 +15,12 @@ public static RequestBuilder WithSimpleRoute(this RequestBuilder request, ISimpl return request; } + public static RequestBuilder WithFullRatelimit(this RequestBuilder request, string route) + { + request.AddToContext("full-ratelimit", route); + return request; + } + public static RequestBuilder AsWebhookRequest(this RequestBuilder request, bool isWebhookRequest = true) { request.AddToContext("is-webhook-request", isWebhookRequest); From bb3f5f476d0862a2f9ea4f70c6abcd39c56c89fb Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Tue, 9 Jan 2024 12:37:55 +0100 Subject: [PATCH 255/323] ratelimits suck, parts 2 and 3 --- src/core/DSharpPlus.Internal.Rest/API/ApplicationRestAPI.cs | 6 ++++-- src/core/DSharpPlus.Internal.Rest/API/AuditLogsRestAPI.cs | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/core/DSharpPlus.Internal.Rest/API/ApplicationRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/ApplicationRestAPI.cs index e7da9128d5..e00fd1430a 100644 --- a/src/core/DSharpPlus.Internal.Rest/API/ApplicationRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Rest/API/ApplicationRestAPI.cs @@ -60,7 +60,8 @@ public async ValueTask> EditCurrentApplicationAsync Route = "applications/@me" } ) - .WithPayload(payload), + .WithPayload(payload) + .WithFullRatelimit("PATCH applications/@me"), info, ct ); @@ -85,7 +86,8 @@ public async ValueTask> GetCurrentApplicationAsync Resource = TopLevelResource.Other, Route = "applications/@me" } - ), + ) + .WithFullRatelimit("GET applications/@me"), info, ct ); diff --git a/src/core/DSharpPlus.Internal.Rest/API/AuditLogsRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/AuditLogsRestAPI.cs index a7e83a921d..2648364061 100644 --- a/src/core/DSharpPlus.Internal.Rest/API/AuditLogsRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Rest/API/AuditLogsRestAPI.cs @@ -82,7 +82,8 @@ public async ValueTask> ListGuildAuditLogEntriesAsync Id = guildId } ) - .WithRoute($"guilds/{guildId}/audit-logs"), + .WithRoute($"guilds/{guildId}/audit-logs") + .WithFullRatelimit($"GET guilds/{guildId}/audit-logs"), info, ct ); From b3d7ce7a070aa1a3108491ad6bc2589752e1331e Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Tue, 9 Jan 2024 12:57:18 +0100 Subject: [PATCH 256/323] ratelimits suck, part 4 --- .../API/AutoModerationRestAPI.cs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/core/DSharpPlus.Internal.Rest/API/AutoModerationRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/AutoModerationRestAPI.cs index cd2c7702f4..b2788e788a 100644 --- a/src/core/DSharpPlus.Internal.Rest/API/AutoModerationRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Rest/API/AutoModerationRestAPI.cs @@ -60,6 +60,7 @@ public async ValueTask> CreateAutoModerationRuleAsyn } ) .WithRoute($"guilds/{guildId}/auto-moderation/rules") + .WithFullRatelimit($"POST guilds/{guildId}/auto-moderation/rules") .WithAuditLogReason(reason), info, ct @@ -89,6 +90,7 @@ public async ValueTask DeleteAutoModerationRuleAsync } ) .WithRoute($"guilds/{guildId}/auto-moderation/rules/:rule-id") + .WithFullRatelimit($"DELETE guilds/{guildId}/auto-moderation/rules/:rule-id") .WithAuditLogReason(reason), info, ct @@ -118,7 +120,8 @@ public async ValueTask> GetAutoModerationRuleAsync Id = guildId } ) - .WithRoute($"guilds/{guildId}/auto-moderation/rules/:rule-id"), + .WithRoute($"guilds/{guildId}/auto-moderation/rules/:rule-id") + .WithFullRatelimit($"GET guilds/{guildId}/auto-moderation/rules/:rule-id"), info, ct ); @@ -144,7 +147,8 @@ public async ValueTask>> ListAutoModer Id = guildId } ) - .WithRoute($"guilds/{guildId}/auto-moderation/rules"), + .WithRoute($"guilds/{guildId}/auto-moderation/rules") + .WithFullRatelimit($"GET guilds/{guildId}/auto-moderation/rules"), info, ct ); @@ -168,7 +172,7 @@ public async ValueTask> ModifyAutoModerationRuleAsyn if (payload.ExemptChannels.HasValue && payload.ExemptChannels.Value.Count > 50) { - return new ValidationError("Ibkt yp to 50 channels can be exempted from an automod rule."); + return new ValidationError("Only up to 50 channels can be exempted from an automod rule."); } return await restClient.ExecuteRequestAsync @@ -184,6 +188,7 @@ public async ValueTask> ModifyAutoModerationRuleAsyn } ) .WithRoute($"guilds/{guildId}/auto-moderation/rules/:rule-id") + .WithFullRatelimit($"PATCH guilds/{guildId}/auto-moderation/rules/:rule-id") .WithAuditLogReason(reason), info, ct From 7a743cdb66dace9922a8b427e62336f27ab07c7a Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Tue, 9 Jan 2024 13:11:58 +0100 Subject: [PATCH 257/323] ratelimits suck, part 5/5 --- .../API/ChannelRestAPI.cs | 95 +++++++++++++------ 1 file changed, 68 insertions(+), 27 deletions(-) diff --git a/src/core/DSharpPlus.Internal.Rest/API/ChannelRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/ChannelRestAPI.cs index 8f0ed0c775..6110f08662 100644 --- a/src/core/DSharpPlus.Internal.Rest/API/ChannelRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Rest/API/ChannelRestAPI.cs @@ -52,7 +52,8 @@ public async ValueTask AddThreadMemberAsync Id = threadId } ) - .WithRoute($"channels/{threadId}/thread-members/:user-id"), + .WithRoute($"channels/{threadId}/thread-members/:user-id") + .WithFullRatelimit($"PUT channels/{threadId}/thread-members/:user-id"), info, ct ); @@ -83,6 +84,7 @@ public async ValueTask BulkDeleteMessagesAsync } ) .WithRoute($"channels/{channelId}/messages/bulk-delete") + .WithFullRatelimit($"POST channels/{channelId}/messages/bulk-delete") .WithPayload(payload) .WithAuditLogReason(reason), info, @@ -144,6 +146,7 @@ public async ValueTask> CreateChannelInviteAsync } ) .WithRoute($"channels/{channelId}/invites") + .WithFullRatelimit($"POST channels/{channelId}/invites") .WithPayload(payload) .WithAuditLogReason(reason), info, @@ -205,6 +208,7 @@ public async ValueTask> CreateMessageAsync } ) .WithRoute($"channels/{channelId}/messages") + .WithFullRatelimit($"POST channels/{channelId}/messages") .WithPayload(payload), info, ct @@ -233,7 +237,8 @@ public async ValueTask CreateReactionAsync Id = channelId } ) - .WithRoute($"channels/{channelId}/messages/:message-id/reactions/:emoji/@me"), + .WithRoute($"channels/{channelId}/messages/:message-id/reactions/:emoji/@me") + .WithFullRatelimit($"PUT channels/{channelId}/messages/:message-id/reactions/:emoji/@me"), info, ct ); @@ -262,7 +267,8 @@ public async ValueTask> CrosspostMessageAsync Id = channelId } ) - .WithRoute($"channels/{channelId}/messages/:message-id/crosspost"), + .WithRoute($"channels/{channelId}/messages/:message-id/crosspost") + .WithFullRatelimit($"POST channels/{channelId}/messages/:message-id/crosspost"), info, ct ); @@ -289,7 +295,8 @@ public async ValueTask DeleteAllReactionsAsync Id = channelId } ) - .WithRoute($"channels/{channelId}/messages/:message-id/reactions"), + .WithRoute($"channels/{channelId}/messages/:message-id/reactions") + .WithFullRatelimit($"DELETE channels/{channelId}/messages/:message-id/reactions"), info, ct ); @@ -319,7 +326,8 @@ public async ValueTask DeleteAllReactionsForEmojiAsync Id = channelId } ) - .WithRoute($"channels/{channelId}/messages/:message-id/reactions/:emoji"), + .WithRoute($"channels/{channelId}/messages/:message-id/reactions/:emoji") + .WithFullRatelimit($"DELETE channels/{channelId}/messages/:message-id/reactions/:emoji"), info, ct ); @@ -349,6 +357,7 @@ public async ValueTask> DeleteChannelAsync } ) .WithRoute($"channels/{channelId}") + .WithFullRatelimit($"DELETE channels/{channelId}") .WithAuditLogReason(reason), info, ct @@ -378,6 +387,7 @@ public async ValueTask DeleteChannelPermissionAsync } ) .WithRoute($"channels/{channelId}/permissions/:overwrite-id") + .WithFullRatelimit($"DELETE channels/{channelId}/permissions/:overwrite-id") .WithAuditLogReason(reason), info, ct @@ -409,6 +419,7 @@ public async ValueTask DeleteMessageAsync } ) .WithRoute($"channels/{channelId}/messages/:message-id") + .WithFullRatelimit($"DELETE channels/{channelId}/messages/:message-id") .WithAuditLogReason(reason), info, ct @@ -439,7 +450,8 @@ public async ValueTask DeleteOwnReactionAsync Id = channelId } ) - .WithRoute($"channels/{channelId}/messages/:message-id/reactions/:emoji/@me"), + .WithRoute($"channels/{channelId}/messages/:message-id/reactions/:emoji/@me") + .WithFullRatelimit($"DELETE channels/{channelId}/messages/:message-id/reactions/:emoji/@me"), info, ct ); @@ -470,7 +482,8 @@ public async ValueTask DeleteUserReactionAsync Id = channelId } ) - .WithRoute($"channels/{channelId}/messages/:message-id/reactions/:emoji/:user-id"), + .WithRoute($"channels/{channelId}/messages/:message-id/reactions/:emoji/:user-id") + .WithFullRatelimit($"DELETE channels/{channelId}/messages/:message-id/reactions/:emoji/:user-id"), info, ct ); @@ -502,6 +515,7 @@ public async ValueTask EditChannelPermissionsAsync } ) .WithRoute($"channels/{channelId}/permissions/:overwrite-id") + .WithFullRatelimit($"PUT channels/{channelId}/permissions/:overwrite-id") .WithPayload(payload) .WithAuditLogReason(reason), info, @@ -544,6 +558,7 @@ public async ValueTask> EditMessageAsync } ) .WithRoute($"channels/{channelId}/messages/:message-id") + .WithFullRatelimit($"PATCH channels/{channelId}/messages/:message-id") .WithPayload(payload), info, ct @@ -572,6 +587,7 @@ public async ValueTask> FollowAnnouncementChannelAsync } ) .WithRoute($"channels/{channelId}/followers") + .WithFullRatelimit($"POST channels/{channelId}/followers") .WithPayload(payload), info, ct @@ -597,7 +613,8 @@ public async ValueTask> GetChannelAsync Resource = TopLevelResource.Channel, Id = channelId } - ), + ) + .WithFullRatelimit($"GET channels/{channelId}"), info, ct ); @@ -614,7 +631,7 @@ public async ValueTask>> GetChannelInvitesAsync return await restClient.ExecuteRequestAsync> ( HttpMethod.Get, - $"channels/{channelId}", + $"channels/{channelId}/invites", b => b.WithSimpleRoute ( new SimpleSnowflakeRatelimitRoute @@ -622,7 +639,8 @@ public async ValueTask>> GetChannelInvitesAsync Resource = TopLevelResource.Channel, Id = channelId } - ), + ) + .WithFullRatelimit($"GET channels/{channelId}/invites"), info, ct ); @@ -649,7 +667,8 @@ public async ValueTask> GetChannelMessageAsync Id = channelId } ) - .WithRoute($"channels/{channelId}/messages/:message-id"), + .WithRoute($"channels/{channelId}/messages/:message-id") + .WithFullRatelimit($"GET channels/{channelId}/messages/:message-id"), info, ct ); @@ -704,7 +723,8 @@ public async ValueTask>> GetChannelMessagesAsync Id = channelId } ) - .WithRoute($"channels/{channelId}/messages"), + .WithRoute($"channels/{channelId}/messages") + .WithFullRatelimit($"GET channels/{channelId}/messages"), info, ct ); @@ -730,7 +750,8 @@ public async ValueTask>> GetPinnedMessagesAsync Id = channelId } ) - .WithRoute($"channels/{channelId}/pins"), + .WithRoute($"channels/{channelId}/pins") + .WithFullRatelimit($"GET channels/{channelId}/pins"), info, ct ); @@ -774,7 +795,8 @@ public async ValueTask>> GetReactionsAsync Id = channelId } ) - .WithRoute($"channels/{channelId}/messages/:message-id/reactions/:emoji"), + .WithRoute($"channels/{channelId}/messages/:message-id/reactions/:emoji") + .WithFullRatelimit($"GET channels/{channelId}/messages/:message-id/reactions/:emoji"), info, ct ); @@ -812,7 +834,8 @@ public async ValueTask> GetThreadMemberAsync Id = threadId } ) - .WithRoute($"channels/{threadId}/thread-members/:user-id"), + .WithRoute($"channels/{threadId}/thread-members/:user-id") + .WithFullRatelimit($"GET channels/{threadId}/thread-members/:user-id"), info, ct ); @@ -841,6 +864,7 @@ public async ValueTask GroupDMAddRecipientAsync } ) .WithRoute($"channels/{channelId}/recipients/:user-id") + .WithFullRatelimit($"PUT channels/{channelId}/recipients/:user-id") .WithPayload(payload), info, ct @@ -870,7 +894,8 @@ public async ValueTask GroupDMRemoveRecipientAsync Id = channelId } ) - .WithRoute($"channels/{channelId}/recipients/:user-id"), + .WithRoute($"channels/{channelId}/recipients/:user-id") + .WithFullRatelimit($"DELETE channels/{channelId}/recipients/:user-id"), info, ct ); @@ -898,7 +923,8 @@ public async ValueTask JoinThreadAsync Id = threadId } ) - .WithRoute($"channels/{threadId}/recipients/@me"), + .WithRoute($"channels/{threadId}/recipients/@me") + .WithFullRatelimit($"PUT channels/{threadId}/recipients/@me"), info, ct ); @@ -926,7 +952,8 @@ public async ValueTask LeaveThreadAsync Id = threadId } ) - .WithRoute($"channels/{threadId}/recipients/@me"), + .WithRoute($"channels/{threadId}/recipients/@me") + .WithFullRatelimit($"DELETE channels/{threadId}/recipients/@me"), info, ct ); @@ -975,7 +1002,8 @@ public async ValueTask> ListJoinedPrivateArc Id = channelId } ) - .WithRoute($"channels/{channelId}/users/@me/threads/archived/private"), + .WithRoute($"channels/{channelId}/users/@me/threads/archived/private") + .WithFullRatelimit($"GET channels/{channelId}/users/@me/threads/archived/private"), info, ct ); @@ -1022,7 +1050,8 @@ public async ValueTask> ListPrivateArchivedT Id = channelId } ) - .WithRoute($"channels/{channelId}/users/@me/threads/archived/private"), + .WithRoute($"channels/{channelId}/users/@me/threads/archived/private") + .WithFullRatelimit($"GET channels/{channelId}/users/@me/threads/archived/private"), info, ct ); @@ -1069,7 +1098,8 @@ public async ValueTask> ListPublicArchivedTh Id = channelId } ) - .WithRoute($"channels/{channelId}/threads/archived/public"), + .WithRoute($"channels/{channelId}/threads/archived/public") + .WithFullRatelimit($"GET channels/{channelId}/threads/archived/public"), info, ct ); @@ -1121,7 +1151,8 @@ public async ValueTask>> ListThreadMembersAs Id = threadId } ) - .WithRoute($"channels/{threadId}/thread-members"), + .WithRoute($"channels/{threadId}/thread-members") + .WithFullRatelimit($"GET channels/{threadId}/thread-members"), info, ct ); @@ -1152,7 +1183,8 @@ public async ValueTask> ModifyChannelAsync Resource = TopLevelResource.Channel, Id = channelId } - ), + ) + .WithFullRatelimit($"PATCH channels/{channelId}"), info, ct ); @@ -1219,6 +1251,7 @@ public async ValueTask> ModifyChannelAsync Id = channelId } ) + .WithFullRatelimit($"PATCH channels/{channelId}") .WithAuditLogReason(reason), info, ct @@ -1273,6 +1306,7 @@ public async ValueTask> ModifyChannelAsync Id = channelId } ) + .WithFullRatelimit($"PATCH channels/{channelId}") .WithAuditLogReason(reason), info, ct @@ -1302,7 +1336,8 @@ public async ValueTask PinMessageAsync } ) .WithAuditLogReason(reason) - .WithRoute($"channels/{channelId}/pins/:message-id"), + .WithRoute($"channels/{channelId}/pins/:message-id") + .WithFullRatelimit($"PUT channels/{channelId}/pins/:message-id"), info, ct ); @@ -1331,7 +1366,8 @@ public async ValueTask RemoveThreadMemberAsync Id = threadId } ) - .WithRoute($"channels/{threadId}/thread-members/:user-id"), + .WithRoute($"channels/{threadId}/thread-members/:user-id") + .WithFullRatelimit($"DELETE channels/{threadId}/thread-members/:user-id"), info, ct ); @@ -1384,6 +1420,7 @@ public async ValueTask> StartThreadFromMessageAsync } ) .WithRoute($"channels/{channelId}/messages/:message-id/threads") + .WithFullRatelimit($"POST channels/{channelId}/messages/:message-id/threads") .WithPayload(payload) .WithAuditLogReason(reason), info, @@ -1470,6 +1507,7 @@ public async ValueTask> StartThreadInForumOrMediaChannelAsync } ) .WithRoute($"channels/{channelId}/threads") + .WithFullRatelimit($"POST channels/{channelId}/threads") .WithPayload(payload) .WithAuditLogReason(reason), info, @@ -1521,6 +1559,7 @@ public async ValueTask> StartThreadWithoutMessageAsync } ) .WithRoute($"channels/{channelId}/threads") + .WithFullRatelimit($"POST channels/{channelId}/threads") .WithPayload(payload) .WithAuditLogReason(reason), info, @@ -1548,7 +1587,8 @@ public async ValueTask TriggerTypingIndicatorAsync Id = channelId } ) - .WithRoute($"channels/{channelId}/typing"), + .WithRoute($"channels/{channelId}/typing") + .WithFullRatelimit($"POST channels/{channelId}/typing"), info, ct ); @@ -1578,7 +1618,8 @@ public async ValueTask UnpinMessageAsync Id = channelId } ) - .WithRoute($"channels/{channelId}/pins/:message-id"), + .WithRoute($"channels/{channelId}/pins/:message-id") + .WithFullRatelimit($"DELETE channels/{channelId}/pins/:message-id"), info, ct ); From 212d8f0c89f2f8a095d14e3dc235fdc9f493d94f Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Tue, 9 Jan 2024 13:23:50 +0100 Subject: [PATCH 258/323] implement emojis --- .../API/IEmojiRestAPI.cs | 2 +- .../API/EmojiRestAPI.cs | 179 ++++++++++++++++++ 2 files changed, 180 insertions(+), 1 deletion(-) create mode 100644 src/core/DSharpPlus.Internal.Rest/API/EmojiRestAPI.cs diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IEmojiRestAPI.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IEmojiRestAPI.cs index 08ba28ec64..2f5d0dd51c 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IEmojiRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IEmojiRestAPI.cs @@ -16,7 +16,7 @@ namespace DSharpPlus.Internal.Abstractions.Rest.API; /// /// Provides access to emoji-related rest API calls. /// -public interface IDiscordEmojiRestResource +public interface IEmojiRestAPI { /// /// Fetches a list of emojis for the given guild. diff --git a/src/core/DSharpPlus.Internal.Rest/API/EmojiRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/EmojiRestAPI.cs new file mode 100644 index 0000000000..4b0280e68b --- /dev/null +++ b/src/core/DSharpPlus.Internal.Rest/API/EmojiRestAPI.cs @@ -0,0 +1,179 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; +using System.Net.Http; +using System.Threading; +using System.Threading.Tasks; + +using DSharpPlus.Internal.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Rest; +using DSharpPlus.Internal.Abstractions.Rest.API; +using DSharpPlus.Internal.Abstractions.Rest.Payloads; +using DSharpPlus.Internal.Rest.Ratelimiting; + +using Remora.Results; + +namespace DSharpPlus.Internal.Rest.API; + +// as per https://discord.com/developers/docs/topics/rate-limits, emojis are handled separately from other +// ratelimits. we therefore never count them towards the simple guild limit, and instead specify them as +// 'other' -> emojis/:guild-id so that their erratic behaviour doesn't mess with the rest of our ratelimits. + +/// +public sealed class EmojiRestAPI +( + IRestClient restClient +) + : IEmojiRestAPI +{ + /// + public async ValueTask> CreateGuildEmojiAsync + ( + Snowflake guildId, + ICreateGuildEmojiPayload payload, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ) + { + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Post, + $"guilds/{guildId}/emojis", + b => b.WithSimpleRoute + ( + new SimpleStringRatelimitRoute + { + IsFracturable = true, + Resource = TopLevelResource.Other, + Route = $"emojis/{guildId}" + } + ) + .WithFullRatelimit($"POST guilds/{guildId}/emojis") + .WithAuditLogReason(reason), + info, + ct + ); + } + + /// + public async ValueTask DeleteGuildEmojiAsync + ( + Snowflake guildId, + Snowflake emojiId, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ) + { + Result response = await restClient.ExecuteRequestAsync + ( + HttpMethod.Delete, + $"guilds/{guildId}/emojis/{emojiId}", + b => b.WithSimpleRoute + ( + new SimpleStringRatelimitRoute + { + IsFracturable = true, + Resource = TopLevelResource.Other, + Route = $"emojis/{guildId}" + } + ) + .WithFullRatelimit($"DELETE guilds/{guildId}/emojis/:emoji-id") + .WithAuditLogReason(reason), + info, + ct + ); + + return (Result)response; + } + + /// + public async ValueTask> GetGuildEmojiAsync + ( + Snowflake guildId, + Snowflake emojiId, + RequestInfo info = default, + CancellationToken ct = default + ) + { + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Get, + $"guilds/{guildId}/emojis/{emojiId}", + b => b.WithSimpleRoute + ( + new SimpleStringRatelimitRoute + { + IsFracturable = true, + Resource = TopLevelResource.Other, + Route = $"emojis/{guildId}" + } + ) + .WithFullRatelimit($"GET guilds/{guildId}/emojis/:emoji-id"), + info, + ct + ); + } + + /// + public async ValueTask>> ListGuildEmojisAsync + ( + Snowflake guildId, + RequestInfo info = default, + CancellationToken ct = default + ) + { + return await restClient.ExecuteRequestAsync> + ( + HttpMethod.Get, + $"guilds/{guildId}/emojis", + b => b.WithSimpleRoute + ( + new SimpleStringRatelimitRoute + { + IsFracturable = true, + Resource = TopLevelResource.Other, + Route = $"emojis/{guildId}" + } + ) + .WithFullRatelimit($"GET guilds/{guildId}/emojis"), + info, + ct + ); + } + + /// + public async ValueTask> ModifyGuildEmojiAsync + ( + Snowflake guildId, + Snowflake emojiId, + IModifyGuildEmojiPayload payload, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ) + { + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Patch, + $"guilds/{guildId}/emojis/{emojiId}", + b => b.WithSimpleRoute + ( + new SimpleStringRatelimitRoute + { + IsFracturable = true, + Resource = TopLevelResource.Other, + Route = $"emojis/{guildId}" + } + ) + .WithFullRatelimit($"GET guilds/{guildId}/emojis/:emoji-id") + .WithPayload(payload) + .WithAuditLogReason(reason), + info, + ct + ); + } +} From 7ed1a129f6bdeb15a0125e617920514cd051f08b Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Tue, 9 Jan 2024 13:34:16 +0100 Subject: [PATCH 259/323] tragically, implement entitlements --- .../API/EntitlementsRestAPI.cs | 161 ++++++++++++++++++ 1 file changed, 161 insertions(+) create mode 100644 src/core/DSharpPlus.Internal.Rest/API/EntitlementsRestAPI.cs diff --git a/src/core/DSharpPlus.Internal.Rest/API/EntitlementsRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/EntitlementsRestAPI.cs new file mode 100644 index 0000000000..e45b4db39b --- /dev/null +++ b/src/core/DSharpPlus.Internal.Rest/API/EntitlementsRestAPI.cs @@ -0,0 +1,161 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; +using System.Globalization; +using System.Net.Http; +using System.Threading; +using System.Threading.Tasks; + +using DSharpPlus.Internal.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Rest; +using DSharpPlus.Internal.Abstractions.Rest.API; +using DSharpPlus.Internal.Abstractions.Rest.Errors; +using DSharpPlus.Internal.Abstractions.Rest.Payloads; +using DSharpPlus.Internal.Abstractions.Rest.Queries; +using DSharpPlus.Internal.Rest.Ratelimiting; + +using Remora.Results; + +namespace DSharpPlus.Internal.Rest.API; + +/// +public sealed class EntitlementsRestAPI +( + IRestClient restClient +) + : IEntitlementsRestAPI +{ + /// + public async ValueTask> CreateTestEntitlementAsync + ( + Snowflake applicationId, + ICreateTestEntitlementPayload payload, + RequestInfo info = default, + CancellationToken ct = default + ) + { + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Post, + $"applications/{applicationId}/entitlements", + b => b.WithSimpleRoute + ( + new SimpleStringRatelimitRoute + { + IsFracturable = false, + Resource = TopLevelResource.Other, + Route = "applications/:application-id/entitlements" + } + ) + .WithFullRatelimit($"POST applications/:application-id/entitlements") + .WithPayload(payload), + info, + ct + ); + } + + /// + public async ValueTask DeleteTestEntitlementAsync + ( + Snowflake applicationId, + Snowflake entitlementId, + RequestInfo info = default, + CancellationToken ct = default + ) + { + Result response = await restClient.ExecuteRequestAsync + ( + HttpMethod.Delete, + $"applications/{applicationId}/entitlements", + b => b.WithSimpleRoute + ( + new SimpleStringRatelimitRoute + { + IsFracturable = false, + Resource = TopLevelResource.Other, + Route = "applications/:application-id/entitlements/:entitlement-id" + } + ) + .WithFullRatelimit($"DELETE applications/:application-id/entitlements/:entitlement-id"), + info, + ct + ); + + return (Result)response; + } + + /// + public async ValueTask>> ListEntitlementsAsync + ( + Snowflake applicationId, + ListEntitlementsQuery query = default, + RequestInfo info = default, + CancellationToken ct = default + ) + { + if (query.Limit is not null and (< 1 or > 100)) + { + return new ValidationError("The limit of entitlements to list must be between 1 and 100."); + } + + QueryBuilder builder = new() + { + RootUri = $"applications/{applicationId}/entitlements" + }; + + if (query.UserId is not null) + { + builder.AddParameter("user_id", query.UserId.Value.ToString()); + } + + if (query.SkuIds is not null) + { + builder.AddParameter("sku_ids", query.SkuIds); + } + + if (query.Before is not null) + { + builder.AddParameter("before", query.Before.Value.ToString()); + } + + if (query.After is not null) + { + builder.AddParameter("after", query.After.Value.ToString()); + } + + if (query.Limit is not null) + { + builder.AddParameter("limit", query.Limit.Value.ToString(CultureInfo.InvariantCulture)); + } + + if (query.GuildId is not null) + { + builder.AddParameter("guild_id", query.GuildId.Value.ToString()); + } + + if (query.ExcludeEnded is not null) + { + builder.AddParameter("exclude_ended", query.ExcludeEnded.Value.ToString().ToLowerInvariant()); + } + + return await restClient.ExecuteRequestAsync> + ( + HttpMethod.Get, + builder.Build(), + b => b.WithSimpleRoute + ( + new SimpleStringRatelimitRoute + { + IsFracturable = false, + Resource = TopLevelResource.Other, + Route = "applications/:application-id/entitlements" + } + ) + .WithFullRatelimit($"GET applications/:application-id/entitlements"), + info, + ct + ); + } +} From c7bce99cd4b51fac38f88166e3f57f8f8de859f6 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Fri, 12 Jan 2024 13:59:19 +0100 Subject: [PATCH 260/323] start on guilds --- .../API/IGuildRestAPI.cs | 4 +- .../Payloads/Guilds/IAddGuildMemberPayload.cs | 4 +- ...nMemberQuery.cs => CreateGuildBanQuery.cs} | 4 +- .../API/GuildRestAPI.cs | 262 ++++++++++++++++++ 4 files changed, 268 insertions(+), 6 deletions(-) rename src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Guilds/{BanMemberQuery.cs => CreateGuildBanQuery.cs} (90%) create mode 100644 src/core/DSharpPlus.Internal.Rest/API/GuildRestAPI.cs diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IGuildRestAPI.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IGuildRestAPI.cs index 009549d414..8dfc52c17d 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IGuildRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IGuildRestAPI.cs @@ -363,11 +363,11 @@ public ValueTask> GetGuildBanAsync /// Specifies an audit log reason for the ban. /// Additional instructions regarding this request. /// A cancellation token for this operation. - public ValueTask BanMemberAsync + public ValueTask CreateGuildBanAsync ( Snowflake guildId, Snowflake userId, - BanMemberQuery query = default, + CreateGuildBanQuery query = default, string? reason = null, RequestInfo info = default, CancellationToken ct = default diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Guilds/IAddGuildMemberPayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Guilds/IAddGuildMemberPayload.cs index 5e7938e387..39e72488ea 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Guilds/IAddGuildMemberPayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Guilds/IAddGuildMemberPayload.cs @@ -12,8 +12,8 @@ namespace DSharpPlus.Internal.Abstractions.Rest.Payloads; public interface IAddGuildMemberPayload { /// - /// An OAuth2 access token granted with the guilds.join scope. - /// + /// An OAuth2 access token granted with the guilds.join scope. + /// public string AccessToken { get; } /// diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Guilds/BanMemberQuery.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Guilds/CreateGuildBanQuery.cs similarity index 90% rename from src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Guilds/BanMemberQuery.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Guilds/CreateGuildBanQuery.cs index 9de7b944b6..2fd9916edc 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Guilds/BanMemberQuery.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Guilds/CreateGuildBanQuery.cs @@ -4,11 +4,11 @@ namespace DSharpPlus.Internal.Abstractions.Rest.Queries; -public readonly record struct BanMemberQuery +public readonly record struct CreateGuildBanQuery { /// /// Specifies how many seconds worth of message history should be deleted along with this ban. /// This allows up to 7 days, or 604800 seconds. /// public int? DeleteMessageSeconds { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Rest/API/GuildRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/GuildRestAPI.cs new file mode 100644 index 0000000000..62e82da455 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Rest/API/GuildRestAPI.cs @@ -0,0 +1,262 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; +using System.Globalization; +using System.IO; +using System.Net.Http; +using System.Threading; +using System.Threading.Tasks; + +using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Rest; +using DSharpPlus.Internal.Abstractions.Rest.API; +using DSharpPlus.Internal.Abstractions.Rest.Payloads; +using DSharpPlus.Internal.Abstractions.Rest.Queries; +using DSharpPlus.Internal.Abstractions.Rest.Responses; +using DSharpPlus.Internal.Rest.Ratelimiting; + +using Remora.Results; + +namespace DSharpPlus.Internal.Rest.API; + +/// +public sealed class GuildRestAPI +( + IRestClient restClient +) + : IGuildRestAPI +{ + /// + public async ValueTask> AddGuildMemberAsync + ( + Snowflake guildId, + Snowflake userId, + IAddGuildMemberPayload payload, + RequestInfo info = default, + CancellationToken ct = default + ) + { + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Put, + $"guilds/{guildId}/members/{userId}", + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Guild, + Id = guildId + } + ) + .WithRoute($"guilds/{guildId}/members/:user-id") + .WithFullRatelimit($"PUT guilds/{guildId}/members/:user-id"), + info, + ct + ); + } + + /// + public async ValueTask AddGuildMemberRoleAsync + ( + Snowflake guildId, + Snowflake userId, + Snowflake roleId, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ) + { + Result response = await restClient.ExecuteRequestAsync + ( + HttpMethod.Put, + $"guilds/{guildId}/members/{userId}/roles/{roleId}", + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Guild, + Id = guildId + } + ) + .WithRoute($"guilds/{guildId}/members/:user-id/roles/:role-id") + .WithFullRatelimit($"PUT guilds/{guildId}/members/:user-id/roles/:role-id") + .WithAuditLogReason(reason), + info, + ct + ); + + return (Result)response; + } + + /// + public async ValueTask CreateGuildBanAsync + ( + Snowflake guildId, + Snowflake userId, + CreateGuildBanQuery query = default, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ) + { + QueryBuilder builder = new() + { + RootUri = $"guilds/{guildId}/bans/{userId}" + }; + + if (query.DeleteMessageSeconds is not null) + { + builder.AddParameter("delete_message_seconds", query.DeleteMessageSeconds.Value.ToString(CultureInfo.InvariantCulture)); + } + + Result response = await restClient.ExecuteRequestAsync + ( + HttpMethod.Put, + builder.Build(), + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Guild, + Id = guildId + } + ) + .WithRoute($"guilds/{guildId}/bans/:user-id") + .WithFullRatelimit($"PUT guilds/{guildId}/bans/:user-id") + .WithAuditLogReason(reason), + info, + ct + ); + + return (Result)response; + } + + /// + public async ValueTask> BeginGuildPruneAsync(Snowflake guildId, BeginGuildPruneQuery query = default, string? reason = null, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); + + /// + public async ValueTask> CreateGuildAsync(ICreateGuildPayload payload, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); + + /// + public async ValueTask> CreateGuildChannelAsync(Snowflake guildId, ICreateGuildChannelPayload payload, string? reason = null, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); + + /// + public async ValueTask> CreateGuildRoleAsync(Snowflake guildId, ICreateGuildRolePayload payload, string? reason = null, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); + + /// + public async ValueTask DeleteGuildAsync(Snowflake guildId, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); + + /// + public async ValueTask DeleteGuildIntegrationAsync(Snowflake guildId, Snowflake integrationId, string? reason = null, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); + + /// + public async ValueTask DeleteRoleAsync(Snowflake guildId, Snowflake roleId, string? reason, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); + + /// + public async ValueTask> GetGuildAsync(Snowflake guildId, GetGuildQuery query = default, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); + + /// + public async ValueTask> GetGuildBanAsync(Snowflake guildId, Snowflake userId, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); + + /// + public async ValueTask>> GetGuildBansAsync(Snowflake guildId, PaginatedQuery query = default, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); + + /// + public async ValueTask>> GetGuildChannelsAsync(Snowflake guildId, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); + + /// + public async ValueTask>> GetGuildIntegrationsAsync(Snowflake guildId, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); + + /// + public async ValueTask>> GetGuildInvitesAsync(Snowflake guildId, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); + + /// + public async ValueTask> GetGuildMemberAsync(Snowflake guildId, Snowflake userId, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); + + /// + public async ValueTask> GetGuildOnboardingAsync(Snowflake guildId, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); + + /// + public async ValueTask> GetGuildPreviewAsync(Snowflake guildId, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); + + /// + public async ValueTask> GetGuildPruneCountAsync(Snowflake guildId, GetGuildPruneCountQuery query = default, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); + + /// + public async ValueTask>> GetGuildRolesAsync(Snowflake guildId, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); + + /// + public async ValueTask> GetGuildVanityUrlAsync(Snowflake guildId, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); + + /// + public async ValueTask>> GetGuildVoiceRegionsAsync(Snowflake guildId, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); + + /// + public async ValueTask> GetGuildWelcomeScreenAsync(Snowflake guildId, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); + + /// + public async ValueTask> GetGuildWidgetAsync(Snowflake guildId, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); + + /// + public async ValueTask> GetGuildWidgetImageAsync(Snowflake guildId, string? style = null, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); + + /// + public async ValueTask> GetGuildWidgetSettingsAsync(Snowflake guildId, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); + + /// + public async ValueTask> ListActiveGuildThreadsAsync(Snowflake guildId, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); + + /// + public async ValueTask>> ListGuildMembersAsync(Snowflake guildId, ForwardsPaginatedQuery query = default, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); + + /// + public async ValueTask> ModifyCurrentMemberAsync(Snowflake guildId, IModifyCurrentMemberPayload payload, string? reason = null, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); + + /// + public async ValueTask ModifyCurrentUserVoiceStateAsync(Snowflake guildId, IModifyCurrentUserVoiceStatePayload payload, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); + + /// + public async ValueTask> ModifyGuildAsync(Snowflake guildId, IModifyGuildPayload payload, string? reason = null, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); + + /// + public async ValueTask ModifyGuildChannelPositionsAsync(Snowflake guildId, IReadOnlyList payload, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); + + /// + public async ValueTask> ModifyGuildMemberAsync(Snowflake guildId, Snowflake userId, IModifyGuildMemberPayload payload, string? reason = null, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); + + /// + public async ValueTask> ModifyGuildMFALevelAsync(Snowflake guildId, IModifyGuildMfaLevelPayload payload, string? reason = null, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); + + /// + public async ValueTask> ModifyGuildOnboardingAsync(Snowflake guildId, IModifyGuildOnboardingPayload payload, string? reason = null, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); + + /// + public async ValueTask> ModifyGuildRoleAsync(Snowflake guildId, Snowflake roleId, IModifyGuildRolePayload payload, string? reason = null, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); + + /// + public async ValueTask>> ModifyGuildRolePositionsAsync(Snowflake guildId, IReadOnlyList payload, string? reason = null, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); + + /// + public async ValueTask> ModifyGuildWelcomeScreenAsync(Snowflake guildId, IModifyGuildWelcomeScreenPayload payload, string? reason = null, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); + + /// + public async ValueTask> ModifyGuildWidgetSettingsAsync(Snowflake guildId, IGuildWidgetSettings settings, string? reason = null, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); + + /// + public async ValueTask ModifyUserVoiceStateAsync(Snowflake guildId, Snowflake userId, IModifyUserVoiceStatePayload payload, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); + + /// + public async ValueTask RemoveGuildBanAsync(Snowflake guildId, Snowflake userId, string? reason = null, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); + + /// + public async ValueTask RemoveGuildMemberAsync(Snowflake guildId, Snowflake userId, string? reason = null, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); + + /// + public async ValueTask RemoveGuildMemberRoleAsync(Snowflake guildId, Snowflake userId, Snowflake roleId, string? reason = null, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); + + /// + public async ValueTask>> SearchGuildMembersAsync(Snowflake guildId, string queryString, SearchGuildMembersQuery query = default, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); +} From 0575058188e474a88166a43d6089c02ee9c6f8d3 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Tue, 16 Jan 2024 17:34:56 +0100 Subject: [PATCH 261/323] remove some manual fuckery --- .git-hooks/pre-commit | 16 ---------------- .gitconfig | 2 -- .pre-commit-config.yaml | 9 +++++++++ 3 files changed, 9 insertions(+), 18 deletions(-) delete mode 100644 .git-hooks/pre-commit delete mode 100644 .gitconfig create mode 100644 .pre-commit-config.yaml diff --git a/.git-hooks/pre-commit b/.git-hooks/pre-commit deleted file mode 100644 index 45668cdf20..0000000000 --- a/.git-hooks/pre-commit +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/sh -# https://gist.github.com/EtherZa/581d9276336353838b2c939f9554d479 - -LC_ALL=C - -# Select files to format -FILES=$(git diff --cached --name-only --diff-filter=ACM "*.cs" | sed 's| |\\ |g') -[ -z "$FILES" ] && exit 0 - -# Format all selected files -echo "$FILES" | cat | xargs | sed -e 's/ /,/g' | xargs dotnet format --include - -# Add back the modified files to staging -echo "$FILES" | xargs git add - -exit 0 \ No newline at end of file diff --git a/.gitconfig b/.gitconfig deleted file mode 100644 index c9ba6ad618..0000000000 --- a/.gitconfig +++ /dev/null @@ -1,2 +0,0 @@ -[core] - hooksPath = .git-hooks diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000000..cbdaf98663 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,9 @@ +repos: +- repo: https://github.com/dotnet/format + rev: "v5.1.225507" + hooks: + - id: dotnet-format + name: dotnet-format + language: system + entry: dotnet format --include + types_or: ["c#"] \ No newline at end of file From d41f2a670be27899d9adbe800dc5d5d90811e7f7 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Tue, 16 Jan 2024 17:53:39 +0100 Subject: [PATCH 262/323] turns out these are json parameters --- .../API/IGuildRestAPI.cs | 6 ++-- .../Guilds/IBeginGuildPrunePayload.cs} | 14 ++++----- .../API/GuildRestAPI.cs | 30 ++++++++++++++++++- 3 files changed, 39 insertions(+), 11 deletions(-) rename src/core/DSharpPlus.Internal.Abstractions.Rest/{Queries/Guilds/BeginGuildPruneQuery.cs => Payloads/Guilds/IBeginGuildPrunePayload.cs} (71%) diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IGuildRestAPI.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IGuildRestAPI.cs index 8dfc52c17d..05d71d56e8 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IGuildRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IGuildRestAPI.cs @@ -7,11 +7,11 @@ using System.Threading; using System.Threading.Tasks; +using DSharpPlus.Entities; using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Internal.Abstractions.Rest.Payloads; using DSharpPlus.Internal.Abstractions.Rest.Queries; using DSharpPlus.Internal.Abstractions.Rest.Responses; -using DSharpPlus.Entities; using Remora.Results; @@ -513,7 +513,7 @@ public ValueTask> GetGuildPruneCountAsync /// Initiates a prune from the guild in question. /// /// The snowflake identifier of the guild in question. - /// Contains additional information on which users to consider. + /// Contains additional information on which users to consider. /// Optional audit log reason for the prune. /// Additional instructions regarding this request. /// A cancellation token for this operation. @@ -521,7 +521,7 @@ public ValueTask> GetGuildPruneCountAsync public ValueTask> BeginGuildPruneAsync ( Snowflake guildId, - BeginGuildPruneQuery query = default, + IBeginGuildPrunePayload payload, string? reason = null, RequestInfo info = default, CancellationToken ct = default diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Guilds/BeginGuildPruneQuery.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Guilds/IBeginGuildPrunePayload.cs similarity index 71% rename from src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Guilds/BeginGuildPruneQuery.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Guilds/IBeginGuildPrunePayload.cs index 2136b59f7a..23a1aec711 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Guilds/BeginGuildPruneQuery.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Guilds/IBeginGuildPrunePayload.cs @@ -2,17 +2,17 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -namespace DSharpPlus.Internal.Abstractions.Rest.Queries; +namespace DSharpPlus.Internal.Abstractions.Rest.Payloads; /// -/// Contains the query parameters for IGuildRestAPI.BeginGuildPruneAsync. +/// Represents a payload to POST guilds/:guild-id/prune. /// -public readonly record struct BeginGuildPruneQuery +public interface IBeginGuildPrunePayload { /// /// The days of inactivity to measure, from 0 to 30. /// - public int? Days { get; init; } + public int? Days { get; } /// /// A comma-separated list of snowflake identifiers of roles to include in the prune. @@ -21,10 +21,10 @@ public readonly record struct BeginGuildPruneQuery /// Any user with a subset of these roles will be considered for the prune. Any user with any role /// not listed here will not be included in the count. /// - public string? IncludeRoles { get; init; } + public string? IncludeRoles { get; } /// /// Specifies whether the amount of users pruned should be computed and returned. /// - public bool? ComputeCount { get; init; } -} \ No newline at end of file + public bool? ComputeCount { get; } +} diff --git a/src/core/DSharpPlus.Internal.Rest/API/GuildRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/GuildRestAPI.cs index 62e82da455..6f8785278a 100644 --- a/src/core/DSharpPlus.Internal.Rest/API/GuildRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Rest/API/GuildRestAPI.cs @@ -135,7 +135,35 @@ public async ValueTask CreateGuildBanAsync } /// - public async ValueTask> BeginGuildPruneAsync(Snowflake guildId, BeginGuildPruneQuery query = default, string? reason = null, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); + public async ValueTask> BeginGuildPruneAsync + ( + Snowflake guildId, + IBeginGuildPrunePayload payload, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ) + { + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Post, + $"guilds/{guildId}/prune", + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Guild, + Id = guildId + } + ) + .WithRoute($"guilds/{guildId}/prune") + .WithFullRatelimit($"PUT guilds/{guildId}/prune") + .WithPayload(payload) + .WithAuditLogReason(reason), + info, + ct + ); + } /// public async ValueTask> CreateGuildAsync(ICreateGuildPayload payload, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); From 9e1b2dda596a529aaf8dfc13a5832f2580213620 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Wed, 17 Jan 2024 13:20:30 +0100 Subject: [PATCH 263/323] the guild rest api --- .../API/IGuildRestAPI.cs | 16 +- .../Guilds/GetGuildWidgetImageQuery.cs | 16 + .../Queries/Guilds/SearchGuildMembersQuery.cs | 7 +- .../GetScheduledEventUsersQuery.cs | 3 +- .../Users/GetCurrentUserGuildsQuery.cs | 3 +- .../Responses/GetGuildPruneCountResponse.cs | 16 + .../API/GuildRestAPI.cs | 1393 ++++++++++++++++- .../Messages/EmbedBuilder.cs | 10 +- .../DSharpPlus.Internal.Models.Tests.csproj | 1 + 9 files changed, 1375 insertions(+), 90 deletions(-) create mode 100644 src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Guilds/GetGuildWidgetImageQuery.cs create mode 100644 src/core/DSharpPlus.Internal.Abstractions.Rest/Responses/GetGuildPruneCountResponse.cs diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IGuildRestAPI.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IGuildRestAPI.cs index 05d71d56e8..0431970b6b 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IGuildRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IGuildRestAPI.cs @@ -196,15 +196,13 @@ public ValueTask>> ListGuildMembersAsync /// Returns a list of guild member objects whose username or nickname starts with the given string. /// /// The snowflake identifier of the string in question. - /// The query string to search for. - /// The maximum amount of members to return; 1 - 1000. + /// The string to search for and the maximum amount of members to return; 1 - 1000. /// Additional instructions regarding this request. /// A cancellation token for this operation. public ValueTask>> SearchGuildMembersAsync ( Snowflake guildId, - string queryString, - SearchGuildMembersQuery query = default, + SearchGuildMembersQuery query, RequestInfo info = default, CancellationToken ct = default ); @@ -485,7 +483,7 @@ public ValueTask> ModifyGuildMFALevelAsync /// An optional audit log reason. /// Additional instructions regarding this request. /// A cancellation token for this operation. - public ValueTask DeleteRoleAsync + public ValueTask DeleteGuildRoleAsync ( Snowflake guildId, Snowflake roleId, @@ -501,7 +499,7 @@ public ValueTask DeleteRoleAsync /// Provides additional information on which members to count. /// Additional instructions regarding this request. /// A cancellation token for this operation. - public ValueTask> GetGuildPruneCountAsync + public ValueTask> GetGuildPruneCountAsync ( Snowflake guildId, GetGuildPruneCountQuery query = default, @@ -606,7 +604,7 @@ public ValueTask> GetGuildWidgetSettingsAsync /// Additional instructions regarding this request. /// A cancellation token for this operation. /// The new guild widget object. - public ValueTask> ModifyGuildWidgetSettingsAsync + public ValueTask> ModifyGuildWidgetAsync ( Snowflake guildId, IGuildWidgetSettings settings, @@ -645,13 +643,13 @@ public ValueTask> GetGuildVanityUrlAsync /// Returns the guild widget image as a binary stream. /// /// The snowflake identifier of the guild in question. - /// The widget style, either "shield" (default) or "banner1" through "banner4". + /// The widget style, either "shield" (default) or "banner1" through "banner4". /// Additional instructions regarding this request. /// A cancellation token for this operation. public ValueTask> GetGuildWidgetImageAsync ( Snowflake guildId, - string? style = null, + GetGuildWidgetImageQuery query = default, RequestInfo info = default, CancellationToken ct = default ); diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Guilds/GetGuildWidgetImageQuery.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Guilds/GetGuildWidgetImageQuery.cs new file mode 100644 index 0000000000..bc3269762a --- /dev/null +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Guilds/GetGuildWidgetImageQuery.cs @@ -0,0 +1,16 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Internal.Abstractions.Rest.Queries; + +/// +/// Contains the request parameters to IGuildRestAPI.GetGuildWidgetImageAsync. +/// +public readonly record struct GetGuildWidgetImageQuery +{ + /// + /// The style of the widget image, one of 'shield' or 'banner1' through 'banner4'. + /// + public string? Style { get; init; } +} diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Guilds/SearchGuildMembersQuery.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Guilds/SearchGuildMembersQuery.cs index 24083f754f..f77a946067 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Guilds/SearchGuildMembersQuery.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Guilds/SearchGuildMembersQuery.cs @@ -10,8 +10,13 @@ namespace DSharpPlus.Internal.Abstractions.Rest.Queries; /// public readonly record struct SearchGuildMembersQuery { + /// + /// The query string to match usernames and nicknames against. + /// + public required string Query { get; init; } + /// /// The amount of guild members to return. /// public int? Limit { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/ScheduledEvents/GetScheduledEventUsersQuery.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/ScheduledEvents/GetScheduledEventUsersQuery.cs index f7b8f569e9..d9b9b3c9d6 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/ScheduledEvents/GetScheduledEventUsersQuery.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/ScheduledEvents/GetScheduledEventUsersQuery.cs @@ -2,7 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. - namespace DSharpPlus.Internal.Abstractions.Rest.Queries; /// @@ -23,4 +22,4 @@ namespace DSharpPlus.Internal.Abstractions.Rest.Queries; /// Specifies whether the response should include guild member data. /// public bool? WithMember { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Users/GetCurrentUserGuildsQuery.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Users/GetCurrentUserGuildsQuery.cs index 73c8829ee5..7449bba518 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Users/GetCurrentUserGuildsQuery.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Users/GetCurrentUserGuildsQuery.cs @@ -2,7 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. - namespace DSharpPlus.Internal.Abstractions.Rest.Queries; /// @@ -23,4 +22,4 @@ namespace DSharpPlus.Internal.Abstractions.Rest.Queries; /// Specifies whether the returned guild objects should include approximate member counts. /// public bool? WithCounts { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Responses/GetGuildPruneCountResponse.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Responses/GetGuildPruneCountResponse.cs new file mode 100644 index 0000000000..118c568f15 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Responses/GetGuildPruneCountResponse.cs @@ -0,0 +1,16 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Internal.Abstractions.Rest.Responses; + +/// +/// Represents a response from GET /guilds/:guild-id/prune +/// +public readonly record struct GetGuildPruneCountResponse +{ + /// + /// The amount of members that would be pruned in this operation. + /// + public int Pruned { get; init; } +} diff --git a/src/core/DSharpPlus.Internal.Rest/API/GuildRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/GuildRestAPI.cs index 6f8785278a..e3647a3847 100644 --- a/src/core/DSharpPlus.Internal.Rest/API/GuildRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Rest/API/GuildRestAPI.cs @@ -2,6 +2,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +#pragma warning disable IDE0046 + using System.Collections.Generic; using System.Globalization; using System.IO; @@ -13,6 +15,7 @@ using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Internal.Abstractions.Rest; using DSharpPlus.Internal.Abstractions.Rest.API; +using DSharpPlus.Internal.Abstractions.Rest.Errors; using DSharpPlus.Internal.Abstractions.Rest.Payloads; using DSharpPlus.Internal.Abstractions.Rest.Queries; using DSharpPlus.Internal.Abstractions.Rest.Responses; @@ -144,6 +147,11 @@ public async ValueTask> BeginGuildPruneAsync CancellationToken ct = default ) { + if (payload.Days is < 1 or > 30) + { + return new ValidationError("The number of days to prune must be between 1 and 30."); + } + return await restClient.ExecuteRequestAsync ( HttpMethod.Post, @@ -166,125 +174,1368 @@ public async ValueTask> BeginGuildPruneAsync } /// - public async ValueTask> CreateGuildAsync(ICreateGuildPayload payload, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); - - /// - public async ValueTask> CreateGuildChannelAsync(Snowflake guildId, ICreateGuildChannelPayload payload, string? reason = null, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); - - /// - public async ValueTask> CreateGuildRoleAsync(Snowflake guildId, ICreateGuildRolePayload payload, string? reason = null, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); - - /// - public async ValueTask DeleteGuildAsync(Snowflake guildId, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); - - /// - public async ValueTask DeleteGuildIntegrationAsync(Snowflake guildId, Snowflake integrationId, string? reason = null, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); - - /// - public async ValueTask DeleteRoleAsync(Snowflake guildId, Snowflake roleId, string? reason, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); + public async ValueTask> CreateGuildAsync + ( + ICreateGuildPayload payload, + RequestInfo info = default, + CancellationToken ct = default + ) + { + if (payload.Name.Length is < 2 or > 100) + { + return new ValidationError("The name of a guild must be between 2 and 100 characters long."); + } - /// - public async ValueTask> GetGuildAsync(Snowflake guildId, GetGuildQuery query = default, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); + if (payload.AfkTimeout.HasValue && payload.AfkTimeout.Value is not (60 or 300 or 900 or 1800 or 3600)) + { + return new ValidationError("The AFK timeout of a guild must be either 60, 300, 900, 1800 or 3600 seconds."); + } - /// - public async ValueTask> GetGuildBanAsync(Snowflake guildId, Snowflake userId, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Post, + $"guilds", + b => b.WithSimpleRoute + ( + new SimpleStringRatelimitRoute + { + IsFracturable = false, + Resource = TopLevelResource.Other, + Route = "guilds" + } + ) + .WithFullRatelimit($"POST guilds") + .WithPayload(payload), + info, + ct + ); + } /// - public async ValueTask>> GetGuildBansAsync(Snowflake guildId, PaginatedQuery query = default, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); + public async ValueTask> CreateGuildChannelAsync + ( + Snowflake guildId, + ICreateGuildChannelPayload payload, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ) + { + if (payload.Name.Length is < 1 or > 100) + { + return new ValidationError("The channel name must be between 1 and 100 characters in length."); + } - /// - public async ValueTask>> GetGuildChannelsAsync(Snowflake guildId, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); + if (payload.Topic.TryGetNonNullValue(out string? topic) && topic.Length > 1024) + { + return new ValidationError("The channel topic must not exceed 1024 characters in length."); + } - /// - public async ValueTask>> GetGuildIntegrationsAsync(Snowflake guildId, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); + if (payload.Bitrate.TryGetNonNullValue(out int? bitrate) && bitrate < 8000) + { + return new ValidationError("The bitrate of a voice channel must not be below 8000 bits."); + } - /// - public async ValueTask>> GetGuildInvitesAsync(Snowflake guildId, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); + if (payload.RateLimitPerUser.TryGetNonNullValue(out int? slowmode) && slowmode is < 0 or > 21600) + { + return new ValidationError("The slowmode (rate limit per user) of a channel must be between 0 and 21600 seconds."); + } - /// - public async ValueTask> GetGuildMemberAsync(Snowflake guildId, Snowflake userId, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); + if (payload.DefaultThreadRateLimitPerUser.TryGetNonNullValue(out int? threadSlowmode) && threadSlowmode is < 0 or > 21600) + { + return new ValidationError + ( + "The slowmode (rate limit per user) of threads created in channel must be between 0 and 21600 seconds." + ); + } - /// - public async ValueTask> GetGuildOnboardingAsync(Snowflake guildId, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Post, + $"guilds/{guildId}/channels", + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Guild, + Id = guildId + } + ) + .WithRoute($"guilds/{guildId}/channels") + .WithFullRatelimit($"POST guilds/{guildId}/channels") + .WithPayload(payload) + .WithAuditLogReason(reason), + info, + ct + ); + } /// - public async ValueTask> GetGuildPreviewAsync(Snowflake guildId, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); + public async ValueTask> CreateGuildRoleAsync + ( + Snowflake guildId, + ICreateGuildRolePayload payload, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ) + { + if (payload.Name.HasValue && payload.Name.Value.Length > 100) + { + return new ValidationError("A role name cannot exceed 100 characters in length."); + } - /// - public async ValueTask> GetGuildPruneCountAsync(Snowflake guildId, GetGuildPruneCountQuery query = default, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); + if (payload.Color.HasValue && payload.Color.Value is < 0 or > 0xFFFFFF) + { + return new ValidationError("The role color must be a valid RGB color code."); + } - /// - public async ValueTask>> GetGuildRolesAsync(Snowflake guildId, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Post, + $"guilds/{guildId}/roles", + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Guild, + Id = guildId + } + ) + .WithRoute($"guilds/{guildId}/roles") + .WithFullRatelimit($"POST guilds/{guildId}/roles") + .WithPayload(payload) + .WithAuditLogReason(reason), + info, + ct + ); + } /// - public async ValueTask> GetGuildVanityUrlAsync(Snowflake guildId, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); + public async ValueTask DeleteGuildAsync + ( + Snowflake guildId, + RequestInfo info = default, + CancellationToken ct = default + ) + { + Result response = await restClient.ExecuteRequestAsync + ( + HttpMethod.Delete, + $"guilds/{guildId}", + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Guild, + Id = guildId + } + ) + .WithFullRatelimit($"DELETE guilds/{guildId}"), + info, + ct + ); - /// - public async ValueTask>> GetGuildVoiceRegionsAsync(Snowflake guildId, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); + return (Result)response; + } /// - public async ValueTask> GetGuildWelcomeScreenAsync(Snowflake guildId, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); + public async ValueTask DeleteGuildIntegrationAsync + ( + Snowflake guildId, + Snowflake integrationId, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ) + { + Result response = await restClient.ExecuteRequestAsync + ( + HttpMethod.Delete, + $"guilds/{guildId}/integrations/{integrationId}", + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Guild, + Id = guildId + } + ) + .WithRoute($"guilds/{guildId}/integrations/:integration-id") + .WithFullRatelimit($"DELETE guilds/{guildId}/integrations/:integration-id") + .WithAuditLogReason(reason), + info, + ct + ); - /// - public async ValueTask> GetGuildWidgetAsync(Snowflake guildId, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); + return (Result)response; + } /// - public async ValueTask> GetGuildWidgetImageAsync(Snowflake guildId, string? style = null, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); + public async ValueTask DeleteGuildRoleAsync + ( + Snowflake guildId, + Snowflake roleId, + string? reason, + RequestInfo info = default, + CancellationToken ct = default + ) + { + Result response = await restClient.ExecuteRequestAsync + ( + HttpMethod.Delete, + $"guilds/{guildId}/roles/{roleId}", + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Guild, + Id = guildId + } + ) + .WithRoute($"guilds/{guildId}/roles/:role-id") + .WithFullRatelimit($"DELETE guilds/{guildId}/roles/:role-id") + .WithAuditLogReason(reason), + info, + ct + ); - /// - public async ValueTask> GetGuildWidgetSettingsAsync(Snowflake guildId, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); + return (Result)response; + } /// - public async ValueTask> ListActiveGuildThreadsAsync(Snowflake guildId, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); + public async ValueTask> GetGuildAsync + ( + Snowflake guildId, + GetGuildQuery query = default, + RequestInfo info = default, + CancellationToken ct = default + ) + { + QueryBuilder builder = new() + { + RootUri = $"guilds/{guildId}" + }; - /// - public async ValueTask>> ListGuildMembersAsync(Snowflake guildId, ForwardsPaginatedQuery query = default, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); + if (query.WithCounts.HasValue) + { + builder.AddParameter("with_counts", query.WithCounts.Value.ToString().ToLowerInvariant()); + } - /// - public async ValueTask> ModifyCurrentMemberAsync(Snowflake guildId, IModifyCurrentMemberPayload payload, string? reason = null, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Get, + builder.Build(), + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Guild, + Id = guildId + } + ) + .WithFullRatelimit($"GET guilds/{guildId}"), + info, + ct + ); + } /// - public async ValueTask ModifyCurrentUserVoiceStateAsync(Snowflake guildId, IModifyCurrentUserVoiceStatePayload payload, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); + public async ValueTask> GetGuildBanAsync + ( + Snowflake guildId, + Snowflake userId, + RequestInfo info = default, + CancellationToken ct = default + ) + { + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Get, + $"guilds/{guildId}/bans/{userId}", + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Guild, + Id = guildId + } + ) + .WithRoute($"guilds/{guildId}/bans/:user-id") + .WithFullRatelimit($"GET guilds/{guildId}/bans/:user-id"), + info, + ct + ); + } /// - public async ValueTask> ModifyGuildAsync(Snowflake guildId, IModifyGuildPayload payload, string? reason = null, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); + public async ValueTask>> GetGuildBansAsync + ( + Snowflake guildId, + PaginatedQuery query = default, + RequestInfo info = default, + CancellationToken ct = default + ) + { + QueryBuilder builder = new() + { + RootUri = $"guilds/{guildId}/bans" + }; - /// - public async ValueTask ModifyGuildChannelPositionsAsync(Snowflake guildId, IReadOnlyList payload, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); + if (query.Limit.HasValue) + { + if (query.Limit.Value is < 1 or > 1000) + { + return new ValidationError("The amount of bans to request must be between 1 and 1000."); + } - /// - public async ValueTask> ModifyGuildMemberAsync(Snowflake guildId, Snowflake userId, IModifyGuildMemberPayload payload, string? reason = null, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); + builder.AddParameter("limit", query.Limit.Value.ToString(CultureInfo.InvariantCulture)); + } - /// - public async ValueTask> ModifyGuildMFALevelAsync(Snowflake guildId, IModifyGuildMfaLevelPayload payload, string? reason = null, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); + if (query.Before.HasValue) + { + builder.AddParameter("before", query.Before.Value.ToString()); + } - /// - public async ValueTask> ModifyGuildOnboardingAsync(Snowflake guildId, IModifyGuildOnboardingPayload payload, string? reason = null, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); + if (query.After.HasValue) + { + builder.AddParameter("after", query.After.Value.ToString()); + } - /// - public async ValueTask> ModifyGuildRoleAsync(Snowflake guildId, Snowflake roleId, IModifyGuildRolePayload payload, string? reason = null, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); + return await restClient.ExecuteRequestAsync> + ( + HttpMethod.Get, + builder.Build(), + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Guild, + Id = guildId + } + ) + .WithRoute($"guilds/{guildId}/bans") + .WithFullRatelimit($"GET guilds/{guildId}/bans"), + info, + ct + ); + } /// - public async ValueTask>> ModifyGuildRolePositionsAsync(Snowflake guildId, IReadOnlyList payload, string? reason = null, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); - + public async ValueTask>> GetGuildChannelsAsync + ( + Snowflake guildId, + RequestInfo info = default, + CancellationToken ct = default + ) + { + return await restClient.ExecuteRequestAsync> + ( + HttpMethod.Get, + $"guilds/{guildId}/channels", + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Guild, + Id = guildId + } + ) + .WithRoute($"guilds/{guildId}/channels") + .WithFullRatelimit($"GET guilds/{guildId}/channels"), + info, + ct + ); + } + + /// + public async ValueTask>> GetGuildIntegrationsAsync + ( + Snowflake guildId, + RequestInfo info = default, + CancellationToken ct = default + ) + { + return await restClient.ExecuteRequestAsync> + ( + HttpMethod.Get, + $"guilds/{guildId}/integrations", + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Guild, + Id = guildId + } + ) + .WithRoute($"guilds/{guildId}/integrations") + .WithFullRatelimit($"GET guilds/{guildId}/integrations"), + info, + ct + ); + } + + /// + public async ValueTask>> GetGuildInvitesAsync + ( + Snowflake guildId, + RequestInfo info = default, + CancellationToken ct = default + ) + { + return await restClient.ExecuteRequestAsync> + ( + HttpMethod.Get, + $"guilds/{guildId}/invites", + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Guild, + Id = guildId + } + ) + .WithRoute($"guilds/{guildId}/invites") + .WithFullRatelimit($"GET guilds/{guildId}/invites"), + info, + ct + ); + } + + /// + public async ValueTask> GetGuildMemberAsync + ( + Snowflake guildId, + Snowflake userId, + RequestInfo info = default, + CancellationToken ct = default + ) + { + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Get, + $"guilds/{guildId}/members/{userId}", + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Guild, + Id = guildId + } + ) + .WithRoute($"guilds/{guildId}/members/:user-id") + .WithFullRatelimit($"GET guilds/{guildId}/members/:user-id"), + info, + ct + ); + } + + /// + public async ValueTask> GetGuildOnboardingAsync + ( + Snowflake guildId, + RequestInfo info = default, + CancellationToken ct = default + ) + { + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Get, + $"guilds/{guildId}/onboarding", + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Guild, + Id = guildId + } + ) + .WithRoute($"guilds/{guildId}/onboarding") + .WithFullRatelimit($"GET guilds/{guildId}/onboarding"), + info, + ct + ); + } + + /// + public async ValueTask> GetGuildPreviewAsync + ( + Snowflake guildId, + RequestInfo info = default, + CancellationToken ct = default + ) + { + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Get, + $"guilds/{guildId}/preview", + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Guild, + Id = guildId + } + ) + .WithRoute($"guilds/{guildId}/preview") + .WithFullRatelimit($"GET guilds/{guildId}/preview"), + info, + ct + ); + } + + /// + public async ValueTask> GetGuildPruneCountAsync + ( + Snowflake guildId, + GetGuildPruneCountQuery query = default, + RequestInfo info = default, + CancellationToken ct = default + ) + { + QueryBuilder builder = new() + { + RootUri = $"guilds/{guildId}/prune" + }; + + if (query.Days.HasValue) + { + if (query.Days is < 1 or > 30) + { + return new ValidationError("The number of days to prune must be between 1 and 30."); + } + + builder.AddParameter("days", query.Days.Value.ToString(CultureInfo.InvariantCulture)); + } + + if (query.IncludeRoles is not null) + { + builder.AddParameter("include_roles", query.IncludeRoles); + } + + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Get, + builder.Build(), + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Guild, + Id = guildId + } + ) + .WithRoute($"guilds/{guildId}/prune") + .WithFullRatelimit($"GET guilds/{guildId}/prune"), + info, + ct + ); + } + + /// + public async ValueTask>> GetGuildRolesAsync + ( + Snowflake guildId, + RequestInfo info = default, + CancellationToken ct = default + ) + { + return await restClient.ExecuteRequestAsync> + ( + HttpMethod.Get, + $"guilds/{guildId}/roles", + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Guild, + Id = guildId + } + ) + .WithRoute($"guilds/{guildId}/roles") + .WithFullRatelimit($"GET guilds/{guildId}/roles"), + info, + ct + ); + } + + /// + public async ValueTask> GetGuildVanityUrlAsync + ( + Snowflake guildId, + RequestInfo info = default, + CancellationToken ct = default + ) + { + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Get, + $"guilds/{guildId}/vanity-url", + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Guild, + Id = guildId + } + ) + .WithRoute($"guilds/{guildId}/vanity-url") + .WithFullRatelimit($"GET guilds/{guildId}/vanity-url"), + info, + ct + ); + } + + /// + public async ValueTask>> GetGuildVoiceRegionsAsync + ( + Snowflake guildId, + RequestInfo info = default, + CancellationToken ct = default + ) + { + return await restClient.ExecuteRequestAsync> + ( + HttpMethod.Get, + $"guilds/{guildId}/regions", + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Guild, + Id = guildId + } + ) + .WithRoute($"guilds/{guildId}/regions") + .WithFullRatelimit($"GET guilds/{guildId}/regions"), + info, + ct + ); + } + + /// + public async ValueTask> GetGuildWelcomeScreenAsync + ( + Snowflake guildId, + RequestInfo info = default, + CancellationToken ct = default + ) + { + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Get, + $"guilds/{guildId}/welcome-screen", + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Guild, + Id = guildId + } + ) + .WithRoute($"guilds/{guildId}/welcome-screen") + .WithFullRatelimit($"GET guilds/{guildId}/welcome-screen"), + info, + ct + ); + } + + /// + public async ValueTask> GetGuildWidgetAsync + ( + Snowflake guildId, + RequestInfo info = default, + CancellationToken ct = default + ) + { + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Get, + $"guilds/{guildId}/widget.json", + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Guild, + Id = guildId + } + ) + .WithRoute($"guilds/{guildId}/widget.json") + .WithFullRatelimit($"GET guilds/{guildId}/widget.json"), + info, + ct + ); + } + + /// + public async ValueTask> GetGuildWidgetImageAsync + ( + Snowflake guildId, + GetGuildWidgetImageQuery query = default, + RequestInfo info = default, + CancellationToken ct = default + ) + { + Result response = await restClient.ExecuteRequestAsync + ( + HttpMethod.Get, + $"guilds/{guildId}/widget.json", + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Guild, + Id = guildId + } + ) + .WithRoute($"guilds/{guildId}/widget.json") + .WithFullRatelimit($"GET guilds/{guildId}/widget.json"), + info, + ct + ); + + return response.Map(message => message.Content.ReadAsStream()); + } + + /// + public async ValueTask> GetGuildWidgetSettingsAsync + ( + Snowflake guildId, + RequestInfo info = default, + CancellationToken ct = default + ) + { + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Get, + $"guilds/{guildId}/widget", + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Guild, + Id = guildId + } + ) + .WithRoute($"guilds/{guildId}/widget") + .WithFullRatelimit($"GET guilds/{guildId}/widget"), + info, + ct + ); + } + + /// + public async ValueTask> ListActiveGuildThreadsAsync + ( + Snowflake guildId, + RequestInfo info = default, + CancellationToken ct = default + ) + { + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Get, + $"guilds/{guildId}/threads/active", + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Guild, + Id = guildId + } + ) + .WithRoute($"guilds/{guildId}/threads/active") + .WithFullRatelimit($"GET guilds/{guildId}/threads/active"), + info, + ct + ); + } + + /// + public async ValueTask>> ListGuildMembersAsync + ( + Snowflake guildId, + ForwardsPaginatedQuery query = default, + RequestInfo info = default, + CancellationToken ct = default + ) + { + QueryBuilder builder = new() + { + RootUri = $"guilds/{guildId}/members" + }; + + if (query.Limit is not null) + { + if (query.Limit is < 1 or > 1000) + { + return new ValidationError("The amount of members to query at once must be between 1 and 1000."); + } + + builder.AddParameter("limit", query.Limit.Value.ToString(CultureInfo.InvariantCulture)); + } + + if (query.After is not null) + { + builder.AddParameter("after", query.After.Value.ToString()); + } + + return await restClient.ExecuteRequestAsync> + ( + HttpMethod.Get, + builder.Build(), + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Guild, + Id = guildId + } + ) + .WithRoute($"guilds/{guildId}/members") + .WithFullRatelimit($"GET guilds/{guildId}/members"), + info, + ct + ); + } + + /// + public async ValueTask> ModifyCurrentMemberAsync + ( + Snowflake guildId, + IModifyCurrentMemberPayload payload, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ) + { + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Patch, + $"guilds/{guildId}/members/@me", + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Guild, + Id = guildId + } + ) + .WithRoute($"guilds/{guildId}/members/@me") + .WithFullRatelimit($"PATCH guilds/{guildId}/members/@me") + .WithPayload(payload), + info, + ct + ); + } + + /// + public async ValueTask ModifyCurrentUserVoiceStateAsync + ( + Snowflake guildId, + IModifyCurrentUserVoiceStatePayload payload, + RequestInfo info = default, + CancellationToken ct = default + ) + { + Result response = await restClient.ExecuteRequestAsync + ( + HttpMethod.Patch, + $"guilds/{guildId}/voice-states/@me", + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Guild, + Id = guildId + } + ) + .WithRoute($"guilds/{guildId}/voice-states/@me") + .WithFullRatelimit($"PATCH guilds/{guildId}/voice-states/@me") + .WithPayload(payload), + info, + ct + ); + + return (Result)response; + } + + /// + public async ValueTask> ModifyGuildAsync + ( + Snowflake guildId, + IModifyGuildPayload payload, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ) + { + if (payload.Name.HasValue && payload.Name.Value.Length is < 2 or > 100) + { + return new ValidationError("The name of a guild must be between 2 and 100 characters long."); + } + + if (payload.AfkTimeout.HasValue && payload.AfkTimeout.Value is not (60 or 300 or 900 or 1800 or 3600)) + { + return new ValidationError("The AFK timeout of a guild must be either 60, 300, 900, 1800 or 3600 seconds."); + } + + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Patch, + $"guilds/{guildId}", + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Guild, + Id = guildId + } + ) + .WithFullRatelimit($"POST guilds") + .WithPayload(payload) + .WithAuditLogReason(reason), + info, + ct + ); + } + + /// + public async ValueTask ModifyGuildChannelPositionsAsync + ( + Snowflake guildId, + IReadOnlyList payload, + RequestInfo info = default, + CancellationToken ct = default + ) + { + Result response = await restClient.ExecuteRequestAsync + ( + HttpMethod.Patch, + $"guilds/{guildId}/channels", + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Guild, + Id = guildId + } + ) + .WithRoute($"guilds/{guildId}/channels") + .WithFullRatelimit($"PATCH guilds/{guildId}/channels") + .WithPayload(payload), + info, + ct + ); + + return (Result)response; + } + + /// + public async ValueTask> ModifyGuildMemberAsync + ( + Snowflake guildId, + Snowflake userId, + IModifyGuildMemberPayload payload, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ) + { + if (payload.Nickname.TryGetNonNullValue(out string? nick) && nick.Length > 32) + { + return new ValidationError("Nicknames of guild members cannot be longer than 32 characters."); + } + + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Patch, + $"guilds/{guildId}/members/{userId}", + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Guild, + Id = guildId + } + ) + .WithRoute($"guilds/{guildId}/members/:user-id") + .WithFullRatelimit($"PATCH guilds/{guildId}/members/:user-id") + .WithPayload(payload) + .WithAuditLogReason(reason), + info, + ct + ); + } + + /// + public async ValueTask> ModifyGuildMFALevelAsync + ( + Snowflake guildId, + IModifyGuildMfaLevelPayload payload, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ) + { + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Patch, + $"guilds/{guildId}/mfa", + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Guild, + Id = guildId + } + ) + .WithRoute($"guilds/{guildId}/mfa") + .WithFullRatelimit($"PATCH guilds/{guildId}/mfa") + .WithPayload(payload) + .WithAuditLogReason(reason), + info, + ct + ); + } + + /// + public async ValueTask> ModifyGuildOnboardingAsync + ( + Snowflake guildId, + IModifyGuildOnboardingPayload payload, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ) + { + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Patch, + $"guilds/{guildId}/onboarding", + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Guild, + Id = guildId + } + ) + .WithRoute($"guilds/{guildId}/onboarding") + .WithFullRatelimit($"PATCH guilds/{guildId}/onboarding") + .WithPayload(payload) + .WithAuditLogReason(reason), + info, + ct + ); + } + + /// + public async ValueTask> ModifyGuildRoleAsync + ( + Snowflake guildId, + Snowflake roleId, + IModifyGuildRolePayload payload, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ) + { + if (payload.Name.TryGetNonNullValue(out string? name) && name.Length > 100) + { + return new ValidationError("The name of a role cannot exceed 100 characters in length."); + } + + if (payload.Color.TryGetNonNullValue(out int? value) && value is < 0 or > 0xFFFFFF) + { + return new ValidationError("The color of a role must be a valid RGB color code."); + } + + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Patch, + $"guilds/{guildId}/roles/{roleId}", + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Guild, + Id = guildId + } + ) + .WithRoute($"guilds/{guildId}/roles/:role-id") + .WithFullRatelimit($"PATCH guilds/{guildId}/roles/:role-id") + .WithPayload(payload) + .WithAuditLogReason(reason), + info, + ct + ); + } + + /// + public async ValueTask>> ModifyGuildRolePositionsAsync + ( + Snowflake guildId, + IReadOnlyList payload, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ) + { + return await restClient.ExecuteRequestAsync> + ( + HttpMethod.Patch, + $"guilds/{guildId}/roles", + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Guild, + Id = guildId + } + ) + .WithRoute($"guilds/{guildId}/roles") + .WithFullRatelimit($"PATCH guilds/{guildId}/roles") + .WithPayload(payload) + .WithAuditLogReason(reason), + info, + ct + ); + } + /// - public async ValueTask> ModifyGuildWelcomeScreenAsync(Snowflake guildId, IModifyGuildWelcomeScreenPayload payload, string? reason = null, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); + public async ValueTask> ModifyGuildWelcomeScreenAsync + ( + Snowflake guildId, + IModifyGuildWelcomeScreenPayload payload, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ) + { + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Patch, + $"guilds/{guildId}/welcome-screen", + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Guild, + Id = guildId + } + ) + .WithRoute($"guilds/{guildId}/welcome-screen") + .WithFullRatelimit($"PATCH guilds/{guildId}/welcome-screen") + .WithPayload(payload) + .WithAuditLogReason(reason), + info, + ct + ); + } /// - public async ValueTask> ModifyGuildWidgetSettingsAsync(Snowflake guildId, IGuildWidgetSettings settings, string? reason = null, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); + public async ValueTask> ModifyGuildWidgetAsync + ( + Snowflake guildId, + IGuildWidgetSettings settings, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ) + { + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Patch, + $"guilds/{guildId}/widget", + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Guild, + Id = guildId + } + ) + .WithRoute($"guilds/{guildId}/widget") + .WithFullRatelimit($"PATCH guilds/{guildId}/widget") + .WithPayload(settings) + .WithAuditLogReason(reason), + info, + ct + ); + } /// - public async ValueTask ModifyUserVoiceStateAsync(Snowflake guildId, Snowflake userId, IModifyUserVoiceStatePayload payload, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); + public async ValueTask ModifyUserVoiceStateAsync + ( + Snowflake guildId, + Snowflake userId, + IModifyUserVoiceStatePayload payload, + RequestInfo info = default, + CancellationToken ct = default + ) + { + Result response = await restClient.ExecuteRequestAsync + ( + HttpMethod.Patch, + $"guilds/{guildId}/voice-states/{userId}", + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Guild, + Id = guildId + } + ) + .WithRoute($"guilds/{guildId}/voice-states/:user-id") + .WithFullRatelimit($"PATCH guilds/{guildId}/voice-states/:user-id") + .WithPayload(payload), + info, + ct + ); + + return (Result)response; + } /// - public async ValueTask RemoveGuildBanAsync(Snowflake guildId, Snowflake userId, string? reason = null, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); + public async ValueTask RemoveGuildBanAsync + ( + Snowflake guildId, + Snowflake userId, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ) + { + Result response = await restClient.ExecuteRequestAsync + ( + HttpMethod.Delete, + $"guilds/{guildId}/bans/{userId}", + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Guild, + Id = guildId + } + ) + .WithRoute($"guilds/{guildId}/bans/:user-id") + .WithFullRatelimit($"DELETE guilds/{guildId}/bans/:user-id") + .WithAuditLogReason(reason), + info, + ct + ); + + return (Result)response; + } /// - public async ValueTask RemoveGuildMemberAsync(Snowflake guildId, Snowflake userId, string? reason = null, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); + public async ValueTask RemoveGuildMemberAsync + ( + Snowflake guildId, + Snowflake userId, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ) + { + Result response = await restClient.ExecuteRequestAsync + ( + HttpMethod.Delete, + $"guilds/{guildId}/members/{userId}", + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Guild, + Id = guildId + } + ) + .WithRoute($"guilds/{guildId}/members/:user-id") + .WithFullRatelimit($"DELETE guilds/{guildId}/members/:user-id") + .WithAuditLogReason(reason), + info, + ct + ); + + return (Result)response; + } /// - public async ValueTask RemoveGuildMemberRoleAsync(Snowflake guildId, Snowflake userId, Snowflake roleId, string? reason = null, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); + public async ValueTask RemoveGuildMemberRoleAsync + ( + Snowflake guildId, + Snowflake userId, + Snowflake roleId, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ) + { + Result response = await restClient.ExecuteRequestAsync + ( + HttpMethod.Delete, + $"guilds/{guildId}/members/{userId}/roles/{roleId}", + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Guild, + Id = guildId + } + ) + .WithRoute($"guilds/{guildId}/members/:user-id/roles/:role-id") + .WithFullRatelimit($"DELETE guilds/{guildId}/members/:user-id/roles/:role-id") + .WithAuditLogReason(reason), + info, + ct + ); + + return (Result)response; + } /// - public async ValueTask>> SearchGuildMembersAsync(Snowflake guildId, string queryString, SearchGuildMembersQuery query = default, RequestInfo info = default, CancellationToken ct = default) => throw new System.NotImplementedException(); + public async ValueTask>> SearchGuildMembersAsync + ( + Snowflake guildId, + SearchGuildMembersQuery query, + RequestInfo info = default, + CancellationToken ct = default + ) + { + QueryBuilder builder = new() + { + RootUri = $"guilds/{guildId}/members/search" + }; + + builder.AddParameter("query", query.Query); + + if (query.Limit is not null) + { + if (query.Limit is < 1 or > 1000) + { + return new ValidationError("The amount of members to request must be between 1 and 1000."); + } + + builder.AddParameter("limit", query.Limit.Value.ToString(CultureInfo.InvariantCulture)); + } + + return await restClient.ExecuteRequestAsync> + ( + HttpMethod.Get, + $"guilds/{guildId}/members/search", + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Guild, + Id = guildId + } + ) + .WithRoute($"guilds/{guildId}/members/search") + .WithFullRatelimit($"DELETE guilds/{guildId}/members/search"), + info, + ct + ); + } } diff --git a/src/extensions/DSharpPlus.Extensions.Internal.Builders/Messages/EmbedBuilder.cs b/src/extensions/DSharpPlus.Extensions.Internal.Builders/Messages/EmbedBuilder.cs index 998e6e37a7..26baf229cf 100644 --- a/src/extensions/DSharpPlus.Extensions.Internal.Builders/Messages/EmbedBuilder.cs +++ b/src/extensions/DSharpPlus.Extensions.Internal.Builders/Messages/EmbedBuilder.cs @@ -135,7 +135,7 @@ public static ref EmbedBuilder AddField(ref this EmbedBuilder builder, IEmbedFie { builder.Fields = builder.Fields.MapOr>> ( - transformation: fields => new([..fields, field]), + transformation: fields => new([.. fields, field]), value: new([field]) ); @@ -156,7 +156,7 @@ public static Result Validate(ref this EmbedBuilder builder) { errors.Add((nameof(EmbedBuilder.Title), "The length of the title cannot exceed 256 characters.")); } - + totalCount += title.Length; } @@ -166,13 +166,13 @@ public static Result Validate(ref this EmbedBuilder builder) { errors.Add((nameof(EmbedBuilder.Description), "The length of the description cannot exceed 4096 characters.")); } - + totalCount += desc.Length; } if (builder.Color.TryGetNonNullValue(out int color)) { - if (color < 0x000000 || color > 0xFFFFFF) + if (color is < 0x000000 or > 0xFFFFFF) { errors.Add((nameof(EmbedBuilder.Color), "The color code must be between 0x000000 and 0xFFFFFF.")); } @@ -264,4 +264,4 @@ public static IEmbed Build(ref this EmbedBuilder builder) Fields = builder.Fields }; } -} \ No newline at end of file +} diff --git a/tests/core/DSharpPlus.Internal.Models.Tests/DSharpPlus.Internal.Models.Tests.csproj b/tests/core/DSharpPlus.Internal.Models.Tests/DSharpPlus.Internal.Models.Tests.csproj index 844c267c48..e8e13b5700 100644 --- a/tests/core/DSharpPlus.Internal.Models.Tests/DSharpPlus.Internal.Models.Tests.csproj +++ b/tests/core/DSharpPlus.Internal.Models.Tests/DSharpPlus.Internal.Models.Tests.csproj @@ -6,6 +6,7 @@ false true + $(NoWarn);CA1515 From 541933d09eb672884b182db24386036b85b611e7 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Wed, 17 Jan 2024 13:46:27 +0100 Subject: [PATCH 264/323] fix build errors --- .../AttachmentData.cs | 28 ------------------- .../DSharpPlus.Internal.Models.csproj | 2 +- .../Converters/OneOfConverter.cs | 8 +++--- 3 files changed, 5 insertions(+), 33 deletions(-) delete mode 100644 src/core/DSharpPlus.Internal.Abstractions.Rest/AttachmentData.cs diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/AttachmentData.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/AttachmentData.cs deleted file mode 100644 index f62537f06b..0000000000 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/AttachmentData.cs +++ /dev/null @@ -1,28 +0,0 @@ -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -using System.IO.Pipelines; - -namespace DSharpPlus.Internal.Abstractions.Rest; - -/// -/// Contains the information necessary for sending an attachment to Discord. -/// -public readonly record struct AttachmentData -{ - /// - /// The filename as uploaded to Discord. - /// - public required string Name { get; init; } - - /// - /// An optional description/alt text for this file. - /// - public string? Description { get; init; } - - /// - /// A pipe with the contents of the file. - /// - public required PipeReader Content { get; init; } -} diff --git a/src/core/DSharpPlus.Internal.Models/DSharpPlus.Internal.Models.csproj b/src/core/DSharpPlus.Internal.Models/DSharpPlus.Internal.Models.csproj index d2eb15f798..22c7b1fbd1 100644 --- a/src/core/DSharpPlus.Internal.Models/DSharpPlus.Internal.Models.csproj +++ b/src/core/DSharpPlus.Internal.Models/DSharpPlus.Internal.Models.csproj @@ -5,7 +5,7 @@ $(Description) This package implements the serialization models mirroring the Discord API. Library - $(NoWarn);CA1812 + $(NoWarn);CA1812;IDE0005 diff --git a/src/core/DSharpPlus.Internal.Models/Serialization/Converters/OneOfConverter.cs b/src/core/DSharpPlus.Internal.Models/Serialization/Converters/OneOfConverter.cs index 066232b152..811177d391 100644 --- a/src/core/DSharpPlus.Internal.Models/Serialization/Converters/OneOfConverter.cs +++ b/src/core/DSharpPlus.Internal.Models/Serialization/Converters/OneOfConverter.cs @@ -23,7 +23,7 @@ namespace DSharpPlus.Internal.Models.Serialization.Converters; /// public sealed class OneOfConverter : JsonConverter where TUnion : IOneOf -{ +{ // using type handles turns out to be marginally faster than Type, but it doesn't fundamentally matter // and this might well change in future .NET versions, in which case this code should use Type for ease // of reading @@ -159,8 +159,8 @@ Type @interface public override TUnion? Read ( - ref Utf8JsonReader reader, - Type typeToConvert, + ref Utf8JsonReader reader, + Type typeToConvert, JsonSerializerOptions options ) { @@ -178,7 +178,7 @@ JsonSerializerOptions options continue; } - return (TUnion)constructionMethods[type.TypeHandle.Value].Invoke(null, new object[] { value })!; + return (TUnion)constructionMethods[type.TypeHandle.Value].Invoke(null, [value])!; } throw new JsonException("The value could not be parsed into the given union."); From 7d2e9b773f5038c1c048004ce1fe1f18fa2a8815 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Wed, 17 Jan 2024 14:15:53 +0100 Subject: [PATCH 265/323] scheduled events in rest --- .../API/GuildScheduledEventRestAPI.cs | 258 ++++++++++++++++++ 1 file changed, 258 insertions(+) create mode 100644 src/core/DSharpPlus.Internal.Rest/API/GuildScheduledEventRestAPI.cs diff --git a/src/core/DSharpPlus.Internal.Rest/API/GuildScheduledEventRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/GuildScheduledEventRestAPI.cs new file mode 100644 index 0000000000..370fbda20b --- /dev/null +++ b/src/core/DSharpPlus.Internal.Rest/API/GuildScheduledEventRestAPI.cs @@ -0,0 +1,258 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; +using System.Globalization; +using System.Net.Http; +using System.Threading; +using System.Threading.Tasks; + +using DSharpPlus.Internal.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Rest; +using DSharpPlus.Internal.Abstractions.Rest.API; +using DSharpPlus.Internal.Abstractions.Rest.Errors; +using DSharpPlus.Internal.Abstractions.Rest.Payloads; +using DSharpPlus.Internal.Abstractions.Rest.Queries; +using DSharpPlus.Internal.Rest.Ratelimiting; + +using Remora.Results; + +namespace DSharpPlus.Internal.Rest.API; + +/// +public sealed class GuildScheduledEventRestAPI +( + IRestClient restClient +) + : IGuildScheduledEventRestAPI +{ + /// + public async ValueTask> CreateGuildScheduledEventAsync + ( + Snowflake guildId, + ICreateGuildScheduledEventPayload payload, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ) + { + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Post, + $"guilds/{guildId}/scheduled-events", + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Guild, + Id = guildId + } + ) + .WithRoute($"guilds/{guildId}/scheduled-events") + .WithFullRatelimit($"POST guilds/{guildId}/scheduled-events") + .WithPayload(payload) + .WithAuditLogReason(reason), + info, + ct + ); + } + + /// + public async ValueTask DeleteScheduledEventAsync + ( + Snowflake guildId, + Snowflake eventId, + RequestInfo info = default, + CancellationToken ct = default + ) + { + Result response = await restClient.ExecuteRequestAsync + ( + HttpMethod.Delete, + $"guilds/{guildId}/scheduled-events/{eventId}", + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Guild, + Id = guildId + } + ) + .WithRoute($"guilds/{guildId}/scheduled-events/:event-id") + .WithFullRatelimit($"DELETE guilds/{guildId}/scheduled-events/:event-id"), + info, + ct + ); + + return (Result)response; + } + + /// + public async ValueTask> GetScheduledEventAsync + ( + Snowflake guildId, + Snowflake eventId, + WithUserCountQuery query = default, + RequestInfo info = default, + CancellationToken ct = default + ) + { + QueryBuilder builder = new() + { + RootUri = $"guilds/{guildId}/scheduled-events/{eventId}" + }; + + if (query.WithUserCount is not null) + { + builder.AddParameter("with_user_count", query.WithUserCount.Value.ToString().ToLowerInvariant()); + } + + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Get, + builder.Build(), + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Guild, + Id = guildId + } + ) + .WithRoute($"guilds/{guildId}/scheduled-events/:event-id") + .WithFullRatelimit($"GET guilds/{guildId}/scheduled-events/:event-id"), + info, + ct + ); + } + + /// + public async ValueTask>> GetScheduledEventUsersAsync + ( + Snowflake guildId, + Snowflake eventId, + GetScheduledEventUsersQuery query = default, + RequestInfo info = default, + CancellationToken ct = default + ) + { + QueryBuilder builder = new() + { + RootUri = $"guilds/{guildId}/scheduled-events/{eventId}/users" + }; + + if (query.Limit is not null) + { + if (query.Limit is < 1 or > 100) + { + return new ValidationError("The amount of scheduled event users to request must be between 1 and 100."); + } + + builder.AddParameter("limit", query.Limit.Value.ToString(CultureInfo.InvariantCulture)); + } + + if (query.WithMember is not null) + { + builder.AddParameter("with_member", query.WithMember.Value.ToString().ToLowerInvariant()); + } + + if (query.Before is not null) + { + builder.AddParameter("before", query.Before.Value.ToString()); + } + + if (query.After is not null) + { + builder.AddParameter("after", query.After.Value.ToString()); + } + + return await restClient.ExecuteRequestAsync> + ( + HttpMethod.Get, + builder.Build(), + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Guild, + Id = guildId + } + ) + .WithRoute($"guilds/{guildId}/scheduled-events/:event-id/users") + .WithFullRatelimit($"GET guilds/{guildId}/scheduled-events/:event-id/users"), + info, + ct + ); + } + + /// + public async ValueTask>> ListScheduledEventsForGuildAsync + ( + Snowflake guildId, + WithUserCountQuery query = default, + RequestInfo info = default, + CancellationToken ct = default + ) + { + QueryBuilder builder = new() + { + RootUri = $"guilds/{guildId}/scheduled-events" + }; + + if (query.WithUserCount is not null) + { + builder.AddParameter("with_user_count", query.WithUserCount.Value.ToString().ToLowerInvariant()); + } + + return await restClient.ExecuteRequestAsync> + ( + HttpMethod.Get, + builder.Build(), + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Guild, + Id = guildId + } + ) + .WithRoute($"guilds/{guildId}/scheduled-events") + .WithFullRatelimit($"GET guilds/{guildId}/scheduled-events"), + info, + ct + ); + } + + /// + public async ValueTask> ModifyScheduledEventAsync + ( + Snowflake guildId, + Snowflake eventId, + IModifyGuildScheduledEventPayload payload, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ) + { + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Patch, + $"guilds/{guildId}/scheduled-events/{eventId}", + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Guild, + Id = guildId + } + ) + .WithRoute($"guilds/{guildId}/scheduled-events/:event-id") + .WithFullRatelimit($"POST guilds/{guildId}/scheduled-events/:event-id") + .WithPayload(payload) + .WithAuditLogReason(reason), + info, + ct + ); + } +} From 4fd971ec1592d283b5577ffe2abc0a75b01e7fd8 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Wed, 17 Jan 2024 14:36:12 +0100 Subject: [PATCH 266/323] guild template rest api --- .../API/GuildTemplateRestAPI.cs | 252 ++++++++++++++++++ 1 file changed, 252 insertions(+) create mode 100644 src/core/DSharpPlus.Internal.Rest/API/GuildTemplateRestAPI.cs diff --git a/src/core/DSharpPlus.Internal.Rest/API/GuildTemplateRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/GuildTemplateRestAPI.cs new file mode 100644 index 0000000000..3d50bcf802 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Rest/API/GuildTemplateRestAPI.cs @@ -0,0 +1,252 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +#pragma warning disable IDE0046 + +using System.Collections.Generic; +using System.Net.Http; +using System.Threading; +using System.Threading.Tasks; + +using DSharpPlus.Internal.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Rest; +using DSharpPlus.Internal.Abstractions.Rest.API; +using DSharpPlus.Internal.Abstractions.Rest.Errors; +using DSharpPlus.Internal.Abstractions.Rest.Payloads; +using DSharpPlus.Internal.Rest.Ratelimiting; + +using Remora.Results; + +namespace DSharpPlus.Internal.Rest.API; + +/// +public sealed class GuildTemplateRestAPI +( + IRestClient restClient +) + : IGuildTemplateRestAPI +{ + /// + public async ValueTask> CreateGuildFromGuildTemplateAsync + ( + string templateCode, + ICreateGuildFromGuildTemplatePayload payload, + RequestInfo info = default, + CancellationToken ct = default + ) + { + if (payload.Name.Length is < 2 or > 100) + { + return new ValidationError("The length of a guild name must be between 2 and 100 characters."); + } + + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Post, + $"guilds/templates/{templateCode}", + b => b.WithSimpleRoute + ( + new SimpleStringRatelimitRoute + { + IsFracturable = true, + Resource = TopLevelResource.Other, + Route = $"guilds/templates/{templateCode}" + } + ) + .WithFullRatelimit($"POST guilds/templates/{templateCode}") + .WithPayload(payload), + info, + ct + ); + } + + /// + public async ValueTask> CreateGuildTemplateAsync + ( + Snowflake guildId, + ICreateGuildTemplatePayload payload, + RequestInfo info = default, + CancellationToken ct = default + ) + { + if (payload.Name.Length > 100) + { + return new ValidationError("The length of a template name must be between 2 and 100 characters."); + } + + if (payload.Description.TryGetNonNullValue(out string? description) && description.Length > 120) + { + return new ValidationError("The description of a template name must not exceed 120 characters."); + } + + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Post, + $"guilds/{guildId}/templates", + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Guild, + Id = guildId + } + ) + .WithRoute($"guilds/{guildId}/templates") + .WithFullRatelimit($"POST guilds/{guildId}/templates") + .WithPayload(payload), + info, + ct + ); + } + + /// + public async ValueTask> DeleteGuildTemplateAsync + ( + Snowflake guildId, + string templateCode, + RequestInfo info = default, + CancellationToken ct = default + ) + { + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Delete, + $"guilds/{guildId}/templates/{templateCode}", + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Guild, + Id = guildId + } + ) + .WithRoute($"guilds/{guildId}/templates/:template-code") + .WithFullRatelimit($"DELETE guilds/{guildId}/templates/:template-code"), + info, + ct + ); + } + + /// + public async ValueTask> GetGuildTemplateAsync + ( + string templateCode, + RequestInfo info = default, + CancellationToken ct = default + ) + { + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Get, + $"guilds/templates/{templateCode}", + b => b.WithSimpleRoute + ( + new SimpleStringRatelimitRoute + { + IsFracturable = true, + Resource = TopLevelResource.Other, + Route = $"guilds/templates/{templateCode}" + } + ) + .WithFullRatelimit($"POST guilds/templates/{templateCode}"), + info, + ct + ); + } + + /// + public async ValueTask>> GetGuildTemplatesAsync + ( + Snowflake guildId, + RequestInfo info = default, + CancellationToken ct = default + ) + { + return await restClient.ExecuteRequestAsync> + ( + HttpMethod.Get, + $"guilds/{guildId}/templates", + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Guild, + Id = guildId + } + ) + .WithRoute($"guilds/{guildId}/templates") + .WithFullRatelimit($"DELETE guilds/{guildId}/templates"), + info, + ct + ); + } + + /// + public async ValueTask> ModifyGuildTemplateAsync + ( + Snowflake guildId, + string templateCode, + IModifyGuildTemplatePayload payload, + RequestInfo info = default, + CancellationToken ct = default + ) + { + if (payload.Name.HasValue && payload.Name.Value.Length > 100) + { + return new ValidationError("The length of a template name must be between 2 and 100 characters."); + } + + if (payload.Description.TryGetNonNullValue(out string? description) && description.Length > 120) + { + return new ValidationError("The description of a template name must not exceed 120 characters."); + } + + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Patch, + $"guilds/{guildId}/templates/{templateCode}", + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Guild, + Id = guildId + } + ) + .WithRoute($"guilds/{guildId}/templates/:template-code") + .WithFullRatelimit($"PATCH guilds/{guildId}/templates/:template-code") + .WithPayload(payload), + info, + ct + ); + } + + /// + public async ValueTask> SyncGuildTemplateAsync + ( + Snowflake guildId, + string templateCode, + RequestInfo info = default, + CancellationToken ct = default + ) + { + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Put, + $"guilds/{guildId}/templates/{templateCode}", + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Guild, + Id = guildId + } + ) + .WithRoute($"guilds/{guildId}/templates/:template-code") + .WithFullRatelimit($"PUT guilds/{guildId}/templates/:template-code"), + info, + ct + ); + } +} From 60986fc5f947ca2eae0aedf409d81106572aa702 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Wed, 17 Jan 2024 18:55:10 +0100 Subject: [PATCH 267/323] implement interactions rest calls --- .../Interactions/IMessageCallbackData.cs | 2 + .../Interactions/MessageCallbackData.cs | 5 +- .../API/InteractionRestAPI.cs | 356 ++++++++++++++++++ .../Payloads/Guilds/BeginGuildPrunePayload.cs | 20 + 4 files changed, 382 insertions(+), 1 deletion(-) create mode 100644 src/core/DSharpPlus.Internal.Rest/API/InteractionRestAPI.cs create mode 100644 src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/BeginGuildPrunePayload.cs diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/Interactions/IMessageCallbackData.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Interactions/IMessageCallbackData.cs index bf4e3580e3..77240880ec 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Models/Interactions/IMessageCallbackData.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Interactions/IMessageCallbackData.cs @@ -47,4 +47,6 @@ public interface IMessageCallbackData /// Attachments to this message. /// public Optional> Attachments { get; } + + public IReadOnlyList? Files { get; } } diff --git a/src/core/DSharpPlus.Internal.Models/Interactions/MessageCallbackData.cs b/src/core/DSharpPlus.Internal.Models/Interactions/MessageCallbackData.cs index 80707c68e3..25873aa014 100644 --- a/src/core/DSharpPlus.Internal.Models/Interactions/MessageCallbackData.cs +++ b/src/core/DSharpPlus.Internal.Models/Interactions/MessageCallbackData.cs @@ -32,4 +32,7 @@ public sealed record MessageCallbackData : IMessageCallbackData /// public Optional> Attachments { get; init; } -} \ No newline at end of file + + /// + public IReadOnlyList? Files { get; init; } +} diff --git a/src/core/DSharpPlus.Internal.Rest/API/InteractionRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/InteractionRestAPI.cs new file mode 100644 index 0000000000..2e100b7d19 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Rest/API/InteractionRestAPI.cs @@ -0,0 +1,356 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +#pragma warning disable IDE0046 + +using System.Collections.Generic; +using System.Net.Http; +using System.Threading; +using System.Threading.Tasks; + +using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Rest; +using DSharpPlus.Internal.Abstractions.Rest.API; +using DSharpPlus.Internal.Abstractions.Rest.Errors; +using DSharpPlus.Internal.Abstractions.Rest.Payloads; +using DSharpPlus.Internal.Rest.Ratelimiting; + +using Remora.Results; + +namespace DSharpPlus.Internal.Rest.API; + +/// +public sealed class InteractionRestAPI(IRestClient restClient) + : IInteractionRestAPI +{ + /// + public async ValueTask> CreateFollowupMessageAsync + ( + Snowflake applicationId, + string interactionToken, + ICreateFollowupMessagePayload payload, + RequestInfo info = default, + CancellationToken ct = default + ) + { + if (!(payload.Content.HasValue || payload.Embeds.HasValue || payload.Components.HasValue || payload.Files is not null)) + { + return new ValidationError + ( + "At least one of Content, Embeds, Components or Files must be sent." + ); + } + + if (payload.Content.HasValue && payload.Content.Value.Length > 2000) + { + return new ValidationError("The content of a message cannot exceed 2000 characters."); + } + + if (payload.Embeds.HasValue && payload.Embeds.Value.Count > 10) + { + return new ValidationError("Only up to 10 embeds can be sent with a message."); + } + + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Post, + $"webhooks/{applicationId}/{interactionToken}", + b => b.WithSimpleRoute + ( + new SimpleStringRatelimitRoute + { + IsFracturable = true, + Resource = TopLevelResource.Webhook, + Route = $"webhooks/{applicationId}/{interactionToken}" + } + ) + .WithRoute($"webhooks/{applicationId}/{interactionToken}") + .WithFullRatelimit($"POST webhooks/{applicationId}/{interactionToken}") + .WithPayload(payload), + info, + ct + ); + } + + /// + public async ValueTask CreateInteractionResponseAsync + ( + Snowflake interactionId, + string interactionToken, + IInteractionResponse payload, + RequestInfo info = default, + CancellationToken ct = default + ) + { + if (payload.Type is DiscordInteractionCallbackType.ChannelMessageWithSource or DiscordInteractionCallbackType.UpdateMessage) + { + IMessageCallbackData message = payload.Data.Value.AsT1; + + if (!(message.Content.HasValue || message.Embeds.HasValue || message.Components.HasValue || message.Files is not null)) + { + return new ValidationError + ( + "At least one of Content, Embeds, Components or Files must be sent." + ); + } + + if (message.Content.HasValue && message.Content.Value.Length > 2000) + { + return new ValidationError("The content of a message cannot exceed 2000 characters."); + } + + if (message.Embeds.HasValue && message.Embeds.Value.Count > 10) + { + return new ValidationError("Only up to 10 embeds can be sent with a message."); + } + } + else if (payload.Type is DiscordInteractionCallbackType.Modal) + { + IModalCallbackData modal = payload.Data.Value.AsT2; + + if (modal.CustomId.Length > 100) + { + return new ValidationError("The length of the custom ID of a modal cannot exceed 100 characters."); + } + + if (modal.Title.Length > 45) + { + return new ValidationError("The length of the modal title cannot exceed 45 characters."); + } + + if (modal.Components.Count > 5) + { + return new ValidationError("A modal does not support more than five components."); + } + } + + Result response = await restClient.ExecuteRequestAsync + ( + HttpMethod.Post, + $"interactions/{interactionId}/{interactionToken}/callback", + b => b.WithSimpleRoute + ( + new SimpleStringRatelimitRoute + { + IsFracturable = true, + Resource = TopLevelResource.Webhook, + Route = $"interactions/{interactionId}/{interactionToken}" + } + ) + .WithRoute($"interactions/{interactionId}/{interactionToken}/callback") + .WithFullRatelimit($"POST interactions/{interactionId}/{interactionToken}/callback") + .WithPayload(payload), + info, + ct + ); + + return (Result)response; + } + + /// + public async ValueTask DeleteFollowupMessageAsync + ( + Snowflake applicationId, + string interactionToken, + Snowflake messageId, + RequestInfo info = default, + CancellationToken ct = default + ) + { + Result response = await restClient.ExecuteRequestAsync + ( + HttpMethod.Delete, + $"webhooks/{applicationId}/{interactionToken}/messages/{messageId}", + b => b.WithSimpleRoute + ( + new SimpleStringRatelimitRoute + { + IsFracturable = true, + Resource = TopLevelResource.Webhook, + Route = $"webhooks/{applicationId}/{interactionToken}" + } + ) + .WithRoute($"webhooks/{applicationId}/{interactionToken}/messages/:message-id") + .WithFullRatelimit($"DELETE webhooks/{applicationId}/{interactionToken}/messages/:message-id"), + info, + ct + ); + + return (Result)response; + } + + /// + public async ValueTask DeleteInteractionResponseAsync + ( + Snowflake applicationId, + string interactionToken, + RequestInfo info = default, + CancellationToken ct = default + ) + { + Result response = await restClient.ExecuteRequestAsync + ( + HttpMethod.Delete, + $"webhooks/{applicationId}/{interactionToken}/messages/@original", + b => b.WithSimpleRoute + ( + new SimpleStringRatelimitRoute + { + IsFracturable = true, + Resource = TopLevelResource.Webhook, + Route = $"webhooks/{applicationId}/{interactionToken}" + } + ) + .WithRoute($"webhooks/{applicationId}/{interactionToken}/messages/@original") + .WithFullRatelimit($"DELETE webhooks/{applicationId}/{interactionToken}/messages/@original"), + info, + ct + ); + + return (Result)response; + } + + /// + public async ValueTask> EditFollowupMessageAsync + ( + Snowflake applicationId, + string interactionToken, + Snowflake messageId, + IEditFollowupMessagePayload payload, + RequestInfo info = default, + CancellationToken ct = default + ) + { + if (payload.Content.TryGetNonNullValue(out string? content) && content.Length > 2000) + { + return new ValidationError("The content of a message cannot exceed 2000 characters."); + } + + if (payload.Embeds.TryGetNonNullValue(out IReadOnlyList? embeds) && embeds.Count > 10) + { + return new ValidationError("Only up to 10 embeds can be sent with a message."); + } + + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Patch, + $"webhooks/{applicationId}/{interactionToken}/messages/{messageId}", + b => b.WithSimpleRoute + ( + new SimpleStringRatelimitRoute + { + IsFracturable = true, + Resource = TopLevelResource.Webhook, + Route = $"webhooks/{applicationId}/{interactionToken}" + } + ) + .WithRoute($"webhooks/{applicationId}/{interactionToken}/messages/:message-id") + .WithFullRatelimit($"PATCH webhooks/{applicationId}/{interactionToken}/messages/:message-id") + .WithPayload(payload), + info, + ct + ); + } + + /// + public async ValueTask> EditInteractionResponseAsync + ( + Snowflake applicationId, + string interactionToken, + IEditInteractionResponsePayload payload, + RequestInfo info = default, + CancellationToken ct = default + ) + { + if (payload.Content.TryGetNonNullValue(out string? content) && content.Length > 2000) + { + return new ValidationError("The content of a message cannot exceed 2000 characters."); + } + + if (payload.Embeds.TryGetNonNullValue(out IReadOnlyList? embeds) && embeds.Count > 10) + { + return new ValidationError("Only up to 10 embeds can be sent with a message."); + } + + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Patch, + $"webhooks/{applicationId}/{interactionToken}/messages/@original", + b => b.WithSimpleRoute + ( + new SimpleStringRatelimitRoute + { + IsFracturable = true, + Resource = TopLevelResource.Webhook, + Route = $"webhooks/{applicationId}/{interactionToken}" + } + ) + .WithRoute($"webhooks/{applicationId}/{interactionToken}/messages/@original") + .WithFullRatelimit($"PATCH webhooks/{applicationId}/{interactionToken}/messages/@original") + .WithPayload(payload), + info, + ct + ); + } + + /// + public async ValueTask> GetFollowupMessageAsync + ( + Snowflake applicationId, + string interactionToken, + Snowflake messageId, + RequestInfo info = default, + CancellationToken ct = default + ) + { + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Get, + $"webhooks/{applicationId}/{interactionToken}/messages/{messageId}", + b => b.WithSimpleRoute + ( + new SimpleStringRatelimitRoute + { + IsFracturable = true, + Resource = TopLevelResource.Webhook, + Route = $"webhooks/{applicationId}/{interactionToken}" + } + ) + .WithRoute($"webhooks/{applicationId}/{interactionToken}/messages/{messageId}") + .WithFullRatelimit($"GET webhooks/{applicationId}/{interactionToken}/messages/{messageId}"), + info, + ct + ); + } + + /// + public async ValueTask> GetInteractionResponseAsync + ( + Snowflake applicationId, + string interactionToken, + RequestInfo info = default, + CancellationToken ct = default + ) + { + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Get, + $"webhooks/{applicationId}/{interactionToken}/messages/@original", + b => b.WithSimpleRoute + ( + new SimpleStringRatelimitRoute + { + IsFracturable = true, + Resource = TopLevelResource.Webhook, + Route = $"webhooks/{applicationId}/{interactionToken}" + } + ) + .WithRoute($"webhooks/{applicationId}/{interactionToken}/messages/@original") + .WithFullRatelimit($"GET webhooks/{applicationId}/{interactionToken}/messages/@original"), + info, + ct + ); + } +} diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/BeginGuildPrunePayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/BeginGuildPrunePayload.cs new file mode 100644 index 0000000000..62c548da28 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/BeginGuildPrunePayload.cs @@ -0,0 +1,20 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Internal.Abstractions.Rest.Payloads; + +namespace DSharpPlus.Internal.Rest.Payloads; + +/// +public sealed record BeginGuildPrunePayload : IBeginGuildPrunePayload +{ + /// + public int? Days { get; init; } + + /// + public string? IncludeRoles { get; init; } + + /// + public bool? ComputeCount { get; init; } +} From 8c10797a0304a1f3d76060d029e94b9543ba5b00 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Wed, 17 Jan 2024 19:02:48 +0100 Subject: [PATCH 268/323] invite rest api --- .../API/InviteRestAPI.cs | 99 +++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 src/core/DSharpPlus.Internal.Rest/API/InviteRestAPI.cs diff --git a/src/core/DSharpPlus.Internal.Rest/API/InviteRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/InviteRestAPI.cs new file mode 100644 index 0000000000..1acc942f7a --- /dev/null +++ b/src/core/DSharpPlus.Internal.Rest/API/InviteRestAPI.cs @@ -0,0 +1,99 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Net.Http; +using System.Threading; +using System.Threading.Tasks; + +using DSharpPlus.Internal.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Rest; +using DSharpPlus.Internal.Abstractions.Rest.API; +using DSharpPlus.Internal.Abstractions.Rest.Queries; +using DSharpPlus.Internal.Rest.Ratelimiting; + +using Remora.Results; + +namespace DSharpPlus.Internal.Rest.API; + +/// +public sealed class InviteRestAPI(IRestClient restClient) + : IInviteRestAPI +{ + /// + public async ValueTask> DeleteInviteAsync + ( + string inviteCode, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ) + { + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Delete, + $"invites/{inviteCode}", + b => b.WithSimpleRoute + ( + new SimpleStringRatelimitRoute + { + IsFracturable = false, + Resource = TopLevelResource.Other, + Route = $"invites/:invite-code" + } + ) + .WithFullRatelimit($"DELETE invites/:invite-code") + .WithAuditLogReason(reason), + info, + ct + ); + } + + /// + public async ValueTask> GetInviteAsync + ( + string inviteCode, + GetInviteQuery query = default, + RequestInfo info = default, + CancellationToken ct = default + ) + { + QueryBuilder builder = new() + { + RootUri = $"invites/{inviteCode}" + }; + + if (query.WithCounts is not null) + { + builder.AddParameter("with_counts", query.WithCounts.Value.ToString().ToLowerInvariant()); + } + + if (query.WithExpiration is not null) + { + builder.AddParameter("with_expiration", query.WithExpiration.Value.ToString().ToLowerInvariant()); + } + + if (query.GuildScheduledEventId is not null) + { + builder.AddParameter("guild_scheduled_event_id", query.GuildScheduledEventId.Value.ToString()); + } + + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Get, + builder.Build(), + b => b.WithSimpleRoute + ( + new SimpleStringRatelimitRoute + { + IsFracturable = false, + Resource = TopLevelResource.Other, + Route = $"invites/:invite-code" + } + ) + .WithFullRatelimit($"GET invites/:invite-code"), + info, + ct + ); + } +} From 1f334c0d13921242e0d1a17683d7ee4f42a84608 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Wed, 17 Jan 2024 19:16:34 +0100 Subject: [PATCH 269/323] role connections rest api --- .../API/RoleConnectionsRestAPI.cs | 86 +++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 src/core/DSharpPlus.Internal.Rest/API/RoleConnectionsRestAPI.cs diff --git a/src/core/DSharpPlus.Internal.Rest/API/RoleConnectionsRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/RoleConnectionsRestAPI.cs new file mode 100644 index 0000000000..9cefd7dd82 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Rest/API/RoleConnectionsRestAPI.cs @@ -0,0 +1,86 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +#pragma warning disable IDE0046 + +using System.Collections.Generic; +using System.Net.Http; +using System.Threading; +using System.Threading.Tasks; + +using DSharpPlus.Internal.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Rest; +using DSharpPlus.Internal.Abstractions.Rest.API; +using DSharpPlus.Internal.Abstractions.Rest.Errors; +using DSharpPlus.Internal.Rest.Ratelimiting; + +using Remora.Results; + +namespace DSharpPlus.Internal.Rest.API; + +/// +public sealed class RoleConnectionsRestAPI(IRestClient restClient) + : IRoleConnectionsRestAPI +{ + /// + public async ValueTask>> GetRoleConnectionMetadataRecordsAsync + ( + Snowflake applicationId, + RequestInfo info = default, + CancellationToken ct = default + ) + { + return await restClient.ExecuteRequestAsync> + ( + HttpMethod.Get, + $"applications/{applicationId}/role-connections/metadata", + b => b.WithSimpleRoute + ( + new SimpleStringRatelimitRoute + { + IsFracturable = false, + Resource = TopLevelResource.Other, + Route = "applications/:application-id/role-connections/metadata" + } + ) + .WithFullRatelimit("GET applications/:application-id/role-connections/metadata"), + info, + ct + ); + } + + /// + public async ValueTask>> UpdateRoleConnectionMetadataRecordsAsync + ( + Snowflake applicationId, + IReadOnlyList payload, + RequestInfo info = default, + CancellationToken ct = default + ) + { + if (payload.Count > 5) + { + return new ValidationError("An application can have up to five role connection metadata records."); + } + + return await restClient.ExecuteRequestAsync> + ( + HttpMethod.Put, + $"applications/{applicationId}/role-connections/metadata", + b => b.WithSimpleRoute + ( + new SimpleStringRatelimitRoute + { + IsFracturable = false, + Resource = TopLevelResource.Other, + Route = "applications/:application-id/role-connections/metadata" + } + ) + .WithFullRatelimit("PUT applications/:application-id/role-connections/metadata") + .WithPayload(payload), + info, + ct + ); + } +} From 30363c6d3196da62f59063b081664507ce1f38ef Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Wed, 17 Jan 2024 19:19:08 +0100 Subject: [PATCH 270/323] sku rest api (oh the misery) --- .../API/SkusRestAPI.cs | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 src/core/DSharpPlus.Internal.Rest/API/SkusRestAPI.cs diff --git a/src/core/DSharpPlus.Internal.Rest/API/SkusRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/SkusRestAPI.cs new file mode 100644 index 0000000000..24d26ebc99 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Rest/API/SkusRestAPI.cs @@ -0,0 +1,49 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; +using System.Net.Http; +using System.Threading; +using System.Threading.Tasks; + +using DSharpPlus.Internal.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Rest; +using DSharpPlus.Internal.Abstractions.Rest.API; +using DSharpPlus.Internal.Rest.Ratelimiting; + +using Remora.Results; + +namespace DSharpPlus.Internal.Rest.API; + +/// +public sealed class SkusRestAPI(IRestClient restClient) + : ISkusRestAPI +{ + /// + public async ValueTask>> ListSkusAsync + ( + Snowflake applicationId, + RequestInfo info = default, + CancellationToken ct = default + ) + { + return await restClient.ExecuteRequestAsync> + ( + HttpMethod.Get, + $"applications/{applicationId}/skus", + b => b.WithSimpleRoute + ( + new SimpleStringRatelimitRoute + { + IsFracturable = false, + Resource = TopLevelResource.Other, + Route = "applications/:application-id/skus" + } + ) + .WithFullRatelimit("GET applications/:application-id/skus"), + info, + ct + ); + } +} From 924e5ae8eeb7e8c41b23b6248d996943a06d4dd5 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Wed, 17 Jan 2024 19:30:32 +0100 Subject: [PATCH 271/323] stage instance rest api --- .../API/StageInstanceRestAPI.cs | 149 ++++++++++++++++++ 1 file changed, 149 insertions(+) create mode 100644 src/core/DSharpPlus.Internal.Rest/API/StageInstanceRestAPI.cs diff --git a/src/core/DSharpPlus.Internal.Rest/API/StageInstanceRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/StageInstanceRestAPI.cs new file mode 100644 index 0000000000..e0cad22602 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Rest/API/StageInstanceRestAPI.cs @@ -0,0 +1,149 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +#pragma warning disable IDE0046 + +using System.Net.Http; +using System.Threading; +using System.Threading.Tasks; +using DSharpPlus.Internal.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Rest; +using DSharpPlus.Internal.Abstractions.Rest.API; +using DSharpPlus.Internal.Abstractions.Rest.Errors; +using DSharpPlus.Internal.Abstractions.Rest.Payloads; +using DSharpPlus.Internal.Rest.Ratelimiting; +using Remora.Results; + +namespace DSharpPlus.Internal.Rest.API; + +/// +public sealed class StageInstanceRestAPI(IRestClient restClient) + : IStageInstanceRestAPI +{ + /// + public async ValueTask> CreateStageInstanceAsync + ( + ICreateStageInstancePayload payload, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ) + { + if (payload.Topic.Length > 120) + { + return new ValidationError("The length of a stage topic cannot exceed 120 characters."); + } + + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Post, + $"stage-instances", + b => b.WithSimpleRoute + ( + new SimpleStringRatelimitRoute + { + IsFracturable = false, + Resource = TopLevelResource.Other, + Route = "stage-instances" + } + ) + .WithFullRatelimit("POST stage-instances") + .WithPayload(payload) + .WithAuditLogReason(reason), + info, + ct + ); + } + + /// + public async ValueTask DeleteStageInstanceAsync + ( + Snowflake channelId, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ) + { + Result response = await restClient.ExecuteRequestAsync + ( + HttpMethod.Delete, + $"stage-instances/{channelId}", + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Channel, + Id = channelId + } + ) + .WithFullRatelimit($"DELETE stage-instances/{channelId}") + .WithAuditLogReason(reason), + info, + ct + ); + + return (Result)response; + } + + /// + public async ValueTask> GetStageInstanceAsync + ( + Snowflake channelId, + RequestInfo info = default, + CancellationToken ct = default + ) + { + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Get, + $"stage-instances/{channelId}", + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Channel, + Id = channelId + } + ) + .WithFullRatelimit($"GET stage-instances/{channelId}"), + info, + ct + ); + } + + /// + public async ValueTask> ModifyStageInstanceAsync + ( + Snowflake channelId, + IModifyStageInstancePayload payload, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ) + { + if (payload.Topic.HasValue && payload.Topic.Value.Length > 120) + { + return new ValidationError("The length of a stage topic cannot exceed 120 characters."); + } + + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Patch, + $"stage-instances/{channelId}", + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Channel, + Id = channelId + } + ) + .WithFullRatelimit($"PATCH stage-instances/{channelId}") + .WithPayload(payload) + .WithAuditLogReason(reason), + info, + ct + ); + } +} From 947dba8200088798fad320ac452b44fdf6459164 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Thu, 18 Jan 2024 16:19:23 +0100 Subject: [PATCH 272/323] sticker rest api --- .../IRestClient.cs | 19 ++ .../API/StickerRestAPI.cs | 267 ++++++++++++++++++ 2 files changed, 286 insertions(+) create mode 100644 src/core/DSharpPlus.Internal.Rest/API/StickerRestAPI.cs diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/IRestClient.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/IRestClient.cs index 54423411ca..a48a310abd 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/IRestClient.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/IRestClient.cs @@ -35,6 +35,25 @@ public ValueTask> ExecuteRequestAsync CancellationToken ct = default ); + /// + /// Sends a request to the Discord API, serializing every payload element into a separate form parameter. + /// + /// The type to deserialize into. + /// The HTTP method this request should be sent to. + /// The path this request will take. + /// Constructs the request to be sent to Discord. + /// Specifies additional parameters for this request. + /// A cancellation token for this operation. + /// The response from Discord, or an appropriate error. + public ValueTask> ExecuteMultipartPayloadRequestAsync + ( + HttpMethod method, + string path, + Action request, + RequestInfo info = default, + CancellationToken ct = default + ); + /// /// Sends a request to the Discord API. /// diff --git a/src/core/DSharpPlus.Internal.Rest/API/StickerRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/StickerRestAPI.cs new file mode 100644 index 0000000000..50e86597c0 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Rest/API/StickerRestAPI.cs @@ -0,0 +1,267 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +#pragma warning disable IDE0046 + +using System.Collections.Generic; +using System.Net.Http; +using System.Threading; +using System.Threading.Tasks; + +using DSharpPlus.Internal.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Rest; +using DSharpPlus.Internal.Abstractions.Rest.API; +using DSharpPlus.Internal.Abstractions.Rest.Errors; +using DSharpPlus.Internal.Abstractions.Rest.Payloads; +using DSharpPlus.Internal.Abstractions.Rest.Responses; +using DSharpPlus.Internal.Rest.Ratelimiting; + +using Remora.Results; + +namespace DSharpPlus.Internal.Rest.API; + +/// +public sealed class StickerRestAPI(IRestClient restClient) + : IStickerRestAPI +{ + /// + public async ValueTask> CreateGuildStickerAsync + ( + Snowflake guildId, + ICreateGuildStickerPayload payload, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ) + { + if (payload.Name.Length is < 2 or > 30) + { + return new ValidationError("Sticker names must be between 2 and 30 characters in length."); + } + + if (!string.IsNullOrWhiteSpace(payload.Description) && payload.Description.Length is < 2 or > 100) + { + return new ValidationError("Sticker descriptions must be either empty or between 2 and 100 characters in length."); + } + + if (payload.Tags.Length > 200) + { + return new ValidationError("Sticker tags must not exceed 200 characters in length."); + } + + return await restClient.ExecuteMultipartPayloadRequestAsync + ( + HttpMethod.Post, + $"guilds/{guildId}/stickers", + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Guild, + Id = guildId + } + ) + .WithRoute($"guilds/{guildId}/stickers") + .WithFullRatelimit($"POST guilds/{guildId}/stickers") + .WithPayload(payload) + .WithAuditLogReason(reason), + info, + ct + ); + } + + /// + public async ValueTask DeleteGuildStickerAsync + ( + Snowflake guildId, + Snowflake stickerId, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ) + { + Result response = await restClient.ExecuteRequestAsync + ( + HttpMethod.Delete, + $"guilds/{guildId}/stickers/{stickerId}", + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Guild, + Id = guildId + } + ) + .WithRoute($"guilds/{guildId}/stickers/:sticker-id") + .WithFullRatelimit($"DELETE guilds/{guildId}/stickers/:sticker-id") + .WithAuditLogReason(reason), + info, + ct + ); + + return (Result)response; + } + + /// + public async ValueTask> GetGuildStickerAsync + ( + Snowflake guildId, + Snowflake stickerId, + RequestInfo info = default, + CancellationToken ct = default + ) + { + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Get, + $"guilds/{guildId}/stickers/{stickerId}", + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Guild, + Id = guildId + } + ) + .WithRoute($"guilds/{guildId}/stickers/:sticker-id") + .WithFullRatelimit($"GET guilds/{guildId}/stickers/:sticker-id"), + info, + ct + ); + } + + /// + public async ValueTask> GetStickerAsync + ( + Snowflake stickerId, + RequestInfo info = default, + CancellationToken ct = default + ) + { + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Get, + $"stickers/{stickerId}", + b => b.WithSimpleRoute + ( + new SimpleStringRatelimitRoute + { + IsFracturable = false, + Resource = TopLevelResource.Other, + Route = "stickers/:sticker-id" + } + ) + .WithRoute("stickers/:sticker-id") + .WithFullRatelimit("GET stickers/:sticker-id"), + info, + ct + ); + } + + /// + public async ValueTask>> ListGuildStickersAsync + ( + Snowflake guildId, + RequestInfo info = default, + CancellationToken ct = default + ) + { + return await restClient.ExecuteRequestAsync> + ( + HttpMethod.Get, + $"guilds/{guildId}/stickers", + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Guild, + Id = guildId + } + ) + .WithRoute($"guilds/{guildId}/stickers") + .WithFullRatelimit($"GET guilds/{guildId}/stickers"), + info, + ct + ); + } + + /// + public async ValueTask> ListStickerPacksAsync + ( + RequestInfo info = default, + CancellationToken ct = default + ) + { + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Get, + "sticker-packs", + b => b.WithSimpleRoute + ( + new SimpleStringRatelimitRoute + { + IsFracturable = false, + Resource = TopLevelResource.Other, + Route = "sticker-packs" + } + ) + .WithRoute("sticker-packs") + .WithFullRatelimit("GET sticker-packs"), + info, + ct + ); + } + + /// + public async ValueTask> ModifyGuildStickerAsync + ( + Snowflake guildId, + Snowflake stickerId, + IModifyGuildStickerPayload payload, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ) + { + if (payload.Name.HasValue && payload.Name.Value.Length is < 2 or > 30) + { + return new ValidationError("Sticker names must be between 2 and 30 characters in length."); + } + + if + ( + payload.Description.TryGetNonNullValue(out string? description) + && !string.IsNullOrWhiteSpace(description) + && description.Length is < 2 or > 100 + ) + { + return new ValidationError("Sticker descriptions must be either empty or between 2 and 100 characters in length."); + } + + if (payload.Tags.HasValue && payload.Tags.Value.Length > 200) + { + return new ValidationError("Sticker tags must not exceed 200 characters in length."); + } + + return await restClient.ExecuteMultipartPayloadRequestAsync + ( + HttpMethod.Patch, + $"guilds/{guildId}/stickers/{stickerId}", + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Guild, + Id = guildId + } + ) + .WithRoute($"guilds/{guildId}/stickers/:sticker-id") + .WithFullRatelimit($"PATCH guilds/{guildId}/stickers/:sticker-id") + .WithPayload(payload) + .WithAuditLogReason(reason), + info, + ct + ); + } +} From d3415e8489c8d7ed3feb120a3680047d2afb6cbf Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Thu, 18 Jan 2024 16:48:14 +0100 Subject: [PATCH 273/323] user rest api --- .../API/StickerRestAPI.cs | 2 +- .../API/UserRestAPI.cs | 370 ++++++++++++++++++ 2 files changed, 371 insertions(+), 1 deletion(-) create mode 100644 src/core/DSharpPlus.Internal.Rest/API/UserRestAPI.cs diff --git a/src/core/DSharpPlus.Internal.Rest/API/StickerRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/StickerRestAPI.cs index 50e86597c0..e10ee65380 100644 --- a/src/core/DSharpPlus.Internal.Rest/API/StickerRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Rest/API/StickerRestAPI.cs @@ -244,7 +244,7 @@ public async ValueTask> ModifyGuildStickerAsync return new ValidationError("Sticker tags must not exceed 200 characters in length."); } - return await restClient.ExecuteMultipartPayloadRequestAsync + return await restClient.ExecuteRequestAsync ( HttpMethod.Patch, $"guilds/{guildId}/stickers/{stickerId}", diff --git a/src/core/DSharpPlus.Internal.Rest/API/UserRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/UserRestAPI.cs new file mode 100644 index 0000000000..093a40cc80 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Rest/API/UserRestAPI.cs @@ -0,0 +1,370 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +#pragma warning disable IDE0046 + +using System.Collections.Generic; +using System.Globalization; +using System.Net.Http; +using System.Threading; +using System.Threading.Tasks; + +using DSharpPlus.Internal.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Rest; +using DSharpPlus.Internal.Abstractions.Rest.API; +using DSharpPlus.Internal.Abstractions.Rest.Errors; +using DSharpPlus.Internal.Abstractions.Rest.Payloads; +using DSharpPlus.Internal.Abstractions.Rest.Queries; +using DSharpPlus.Internal.Rest.Ratelimiting; + +using Remora.Results; + +namespace DSharpPlus.Internal.Rest.API; + +/// +public sealed class UserRestAPI(IRestClient restClient) + : IUserRestAPI +{ + /// + public async ValueTask> CreateDmAsync + ( + ICreateDmPayload payload, + RequestInfo info = default, + CancellationToken ct = default + ) + { + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Post, + "users/@me/channels", + b => b.WithSimpleRoute + ( + new SimpleStringRatelimitRoute + { + IsFracturable = false, + Resource = TopLevelResource.Other, + Route = "users/@me/channels" + } + ) + .WithFullRatelimit($"POST users/@me/channels") + .WithPayload(payload), + info, + ct + ); + } + + /// + public async ValueTask> CreateGroupDmAsync + ( + ICreateGroupDmPayload payload, + RequestInfo info = default, + CancellationToken ct = default + ) + { + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Post, + "users/@me/channels", + b => b.WithSimpleRoute + ( + new SimpleStringRatelimitRoute + { + IsFracturable = false, + Resource = TopLevelResource.Other, + Route = "users/@me/channels" + } + ) + .WithFullRatelimit($"POST users/@me/channels") + .WithPayload(payload), + info, + ct + ); + } + + /// + public async ValueTask> GetCurrentUserApplicationRoleConnectionAsync + ( + Snowflake applicationId, + RequestInfo info = default, + CancellationToken ct = default + ) + { + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Get, + $"users/@me/applications/{applicationId}/role-connection", + b => b.WithSimpleRoute + ( + new SimpleStringRatelimitRoute + { + IsFracturable = false, + Resource = TopLevelResource.Other, + Route = "users/@me/applications/:application-id/role-connection" + } + ) + .WithFullRatelimit($"GET users/@me/applications/:application-id/role-connection"), + info, + ct + ); + } + + /// + public async ValueTask> GetCurrentUserAsync + ( + RequestInfo info = default, + CancellationToken ct = default + ) + { + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Get, + "users/@me", + b => b.WithSimpleRoute + ( + new SimpleStringRatelimitRoute + { + IsFracturable = false, + Resource = TopLevelResource.Other, + Route = "users/@me" + } + ) + .WithFullRatelimit($"GET users/@me"), + info, + ct + ); + } + + /// + public async ValueTask>> GetCurrentUserConnectionsAsync + ( + RequestInfo info = default, + CancellationToken ct = default + ) + { + return await restClient.ExecuteRequestAsync> + ( + HttpMethod.Get, + "users/@me/connections", + b => b.WithSimpleRoute + ( + new SimpleStringRatelimitRoute + { + IsFracturable = false, + Resource = TopLevelResource.Other, + Route = "users/@me/connections" + } + ) + .WithFullRatelimit("GET users/@me/connections"), + info, + ct + ); + } + + /// + public async ValueTask> GetCurrentUserGuildMemberAsync + ( + Snowflake guildId, + RequestInfo info = default, + CancellationToken ct = default + ) + { + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Get, + $"users/@me/guilds/{guildId}/member", + b => b.WithSimpleRoute + ( + new SimpleStringRatelimitRoute + { + IsFracturable = false, + Resource = TopLevelResource.Guild, + Route = $"users/@me/guilds/{guildId}/member" + } + ) + .WithFullRatelimit($"GET users/@me/guilds/{guildId}/member"), + info, + ct + ); + } + + /// + public async ValueTask>> GetCurrentUserGuildsAsync + ( + GetCurrentUserGuildsQuery query = default, + RequestInfo info = default, + CancellationToken ct = default + ) + { + QueryBuilder builder = new() + { + RootUri = "users/@me/guilds" + }; + + if (query.Limit is not null) + { + if (query.Limit.Value is < 1 or > 200) + { + return new ValidationError("The limit of guilds to request must be between 1 and 200."); + } + + builder.AddParameter("limit", query.Limit.Value.ToString(CultureInfo.InvariantCulture)); + } + + if (query.Before is not null) + { + builder.AddParameter("before", query.Before.Value.ToString()); + } + + if (query.After is not null) + { + builder.AddParameter("after", query.After.Value.ToString()); + } + + if (query.WithCounts is not null) + { + builder.AddParameter("with_counts", query.WithCounts.Value.ToString().ToLowerInvariant()); + } + + return await restClient.ExecuteRequestAsync> + ( + HttpMethod.Get, + builder.Build(), + b => b.WithSimpleRoute + ( + new SimpleStringRatelimitRoute + { + IsFracturable = false, + Resource = TopLevelResource.Other, + Route = "users/@me/guilds" + } + ) + .WithFullRatelimit("GET users/@me/guilds"), + info, + ct + ); + } + + /// + public async ValueTask> GetUserAsync + ( + Snowflake userId, + RequestInfo info = default, + CancellationToken ct = default + ) + { + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Get, + $"users/{userId}", + b => b.WithSimpleRoute + ( + new SimpleStringRatelimitRoute + { + IsFracturable = false, + Resource = TopLevelResource.Other, + Route = "users/:user-id" + } + ) + .WithFullRatelimit("GET users/:user-id"), + info, + ct + ); + } + + /// + public async ValueTask LeaveGuildAsync + ( + Snowflake guildId, + RequestInfo info = default, + CancellationToken ct = default + ) + { + Result response = await restClient.ExecuteRequestAsync + ( + HttpMethod.Delete, + $"users/@me/guilds/{guildId}", + b => b.WithSimpleRoute + ( + new SimpleStringRatelimitRoute + { + IsFracturable = false, + Resource = TopLevelResource.Guild, + Route = $"users/@me/guilds/{guildId}" + } + ) + .WithFullRatelimit($"DELETE users/@me/guilds/{guildId}"), + info, + ct + ); + + return (Result)response; + } + + /// + public async ValueTask> ModifyCurrentUserAsync + ( + IModifyCurrentUserPayload payload, + RequestInfo info = default, + CancellationToken ct = default + ) + { + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Patch, + "users/@me", + b => b.WithSimpleRoute + ( + new SimpleStringRatelimitRoute + { + IsFracturable = false, + Resource = TopLevelResource.Other, + Route = "users/@me" + } + ) + .WithFullRatelimit("PATCH users/@me") + .WithPayload(payload), + info, + ct + ); + } + + /// + public async ValueTask> UpdateCurrentUserApplicationRoleConnectionAsync + ( + Snowflake applicationId, + IUpdateCurrentUserApplicationRoleConnectionPayload payload, + RequestInfo info = default, + CancellationToken ct = default + ) + { + if (payload.PlatformName.HasValue && payload.PlatformName.Value.Length > 50) + { + return new ValidationError("The platform name of a role connection cannot exceed 50 characters."); + } + + if (payload.PlatformUsername.HasValue && payload.PlatformUsername.Value.Length > 100) + { + return new ValidationError("The platform username of a role connection cannot exceed 100 characters."); + } + + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Put, + $"users/@me/applications/{applicationId}/role-connection", + b => b.WithSimpleRoute + ( + new SimpleStringRatelimitRoute + { + IsFracturable = false, + Resource = TopLevelResource.Other, + Route = "users/@me/applications/:application-id/role-connection" + } + ) + .WithFullRatelimit("PUT users/@me/applications/:application-id/role-connection") + .WithPayload(payload), + info, + ct + ); + } +} From 7a2c0409e8958a703e57fa29d085395310d71dbf Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Thu, 18 Jan 2024 16:50:26 +0100 Subject: [PATCH 274/323] voice rest api --- .../API/VoiceRestAPI.cs | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 src/core/DSharpPlus.Internal.Rest/API/VoiceRestAPI.cs diff --git a/src/core/DSharpPlus.Internal.Rest/API/VoiceRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/VoiceRestAPI.cs new file mode 100644 index 0000000000..4c2ebd8fd2 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Rest/API/VoiceRestAPI.cs @@ -0,0 +1,48 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; +using System.Net.Http; +using System.Threading; +using System.Threading.Tasks; + +using DSharpPlus.Internal.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Rest; +using DSharpPlus.Internal.Abstractions.Rest.API; +using DSharpPlus.Internal.Rest.Ratelimiting; + +using Remora.Results; + +namespace DSharpPlus.Internal.Rest.API; + +/// +public sealed class VoiceRestAPI(IRestClient restClient) + : IVoiceRestAPI +{ + /// + public async ValueTask>> ListVoiceRegionsAsync + ( + RequestInfo info = default, + CancellationToken ct = default + ) + { + return await restClient.ExecuteRequestAsync> + ( + HttpMethod.Get, + $"voice/regions", + b => b.WithSimpleRoute + ( + new SimpleStringRatelimitRoute + { + IsFracturable = false, + Resource = TopLevelResource.Other, + Route = "voice/regions" + } + ) + .WithFullRatelimit("GET voice/regions"), + info, + ct + ); + } +} From 3c78efb60724213600d58dfa2c0895084b762e32 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Thu, 18 Jan 2024 21:58:14 +0100 Subject: [PATCH 275/323] webhook rest api --- .../API/WebhookRestAPI.cs | 560 ++++++++++++++++++ 1 file changed, 560 insertions(+) create mode 100644 src/core/DSharpPlus.Internal.Rest/API/WebhookRestAPI.cs diff --git a/src/core/DSharpPlus.Internal.Rest/API/WebhookRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/WebhookRestAPI.cs new file mode 100644 index 0000000000..b974a51ba3 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Rest/API/WebhookRestAPI.cs @@ -0,0 +1,560 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +#pragma warning disable IDE0046 + +using System; +using System.Collections.Generic; +using System.Net.Http; +using System.Threading; +using System.Threading.Tasks; + +using DSharpPlus.Internal.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Rest; +using DSharpPlus.Internal.Abstractions.Rest.API; +using DSharpPlus.Internal.Abstractions.Rest.Errors; +using DSharpPlus.Internal.Abstractions.Rest.Payloads; +using DSharpPlus.Internal.Abstractions.Rest.Queries; +using DSharpPlus.Internal.Rest.Ratelimiting; + +using Remora.Results; + +namespace DSharpPlus.Internal.Rest.API; + +/// +public sealed class WebhookRestAPI(IRestClient restClient) + : IWebhookRestAPI +{ + /// + public async ValueTask> CreateWebhookAsync + ( + Snowflake channelId, + ICreateWebhookPayload payload, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ) + { + if (payload.Name.Length > 80) + { + return new ValidationError("A webhook name cannot exceed 80 characters."); + } + + if + ( + payload.Name.Contains("discord", StringComparison.InvariantCultureIgnoreCase) + || payload.Name.Contains("clyde", StringComparison.InvariantCultureIgnoreCase) + ) + { + return new ValidationError("A webhook name cannot contain the substrings \"clyde\" or \"discord\"."); + } + + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Post, + $"channels/{channelId}/webhooks", + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Channel, + Id = channelId + } + ) + .WithFullRatelimit($"POST channels/{channelId}/webhooks") + .WithAuditLogReason(reason), + info, + ct + ); + } + + /// + public async ValueTask DeleteWebhookAsync + ( + Snowflake webhookId, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ) + { + Result response = await restClient.ExecuteRequestAsync + ( + HttpMethod.Delete, + $"webhooks/{webhookId}", + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Webhook, + Id = webhookId + } + ) + .WithFullRatelimit($"DELETE webhooks/{webhookId}") + .WithAuditLogReason(reason), + info, + ct + ); + + return (Result)response; + } + + /// + public async ValueTask DeleteWebhookMessageAsync + ( + Snowflake webhookId, + string webhookToken, + Snowflake messageId, + ThreadIdQuery query = default, + RequestInfo info = default, + CancellationToken ct = default + ) + { + QueryBuilder builder = new() + { + RootUri = $"webhooks/{webhookId}/{webhookToken}/messages/{messageId}" + }; + + if (query.ThreadId is not null) + { + builder.AddParameter("thread_id", query.ThreadId.Value.ToString()); + } + + Result response = await restClient.ExecuteRequestAsync + ( + HttpMethod.Delete, + builder.ToString(), + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Webhook, + Id = webhookId + } + ) + .WithFullRatelimit($"DELETE webhooks/{webhookId}/:webhook-token/messages/:message-id") + .AsWebhookRequest(), + info, + ct + ); + + return (Result)response; + } + + /// + public async ValueTask DeleteWebhookWithTokenAsync + ( + Snowflake webhookId, + string webhookToken, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ) + { + Result response = await restClient.ExecuteRequestAsync + ( + HttpMethod.Delete, + $"webhooks/{webhookId}/{webhookToken}", + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Webhook, + Id = webhookId + } + ) + .WithFullRatelimit($"DELETE webhooks/{webhookId}/:webhook-token") + .WithAuditLogReason(reason) + .AsWebhookRequest(), + info, + ct + ); + + return (Result)response; + } + + /// + public async ValueTask> EditWebhookMessageAsync + ( + Snowflake webhookId, + string webhookToken, + Snowflake messageId, + IEditWebhookMessagePayload payload, + ThreadIdQuery query = default, + RequestInfo info = default, + CancellationToken ct = default + ) + { + if (payload.Content.TryGetNonNullValue(out string? content) && content.Length > 2000) + { + return new ValidationError("A webhook message cannot exceed 2000 characters in length."); + } + + if (payload.Embeds.TryGetNonNullValue(out IReadOnlyList? embeds) && embeds.Count > 10) + { + return new ValidationError("A webhook message cannot contain more than 10 embeds."); + } + + if (payload.Components.TryGetNonNullValue(out IReadOnlyList? components) && components.Count > 5) + { + return new ValidationError("A webhook message cannot contain more than 5 action rows."); + } + + QueryBuilder builder = new() + { + RootUri = $"webhooks/{webhookId}/{webhookToken}/messages/{messageId}" + }; + + if (query.ThreadId is not null) + { + builder.AddParameter("thread_id", query.ThreadId.Value.ToString()); + } + + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Patch, + builder.Build(), + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Webhook, + Id = webhookId + } + ) + .WithFullRatelimit($"PATCH webhooks/{webhookId}/:webhook-token/messages/:message-id") + .WithPayload(payload) + .AsWebhookRequest(), + info, + ct + ); + } + + /// + public async ValueTask> ExecuteWebhookAsync + ( + Snowflake webhookId, + string webhookToken, + IExecuteWebhookPayload payload, + ExecuteWebhookQuery query = default, + RequestInfo info = default, + CancellationToken ct = default + ) + { + if (payload.Content.TryGetNonNullValue(out string? content) && content.Length > 2000) + { + return new ValidationError("A webhook message cannot exceed 2000 characters in length."); + } + + if (payload.Embeds.TryGetNonNullValue(out IReadOnlyList? embeds) && embeds.Count > 10) + { + return new ValidationError("A webhook message cannot contain more than 10 embeds."); + } + + if (payload.Components.TryGetNonNullValue(out IReadOnlyList? components) && components.Count > 5) + { + return new ValidationError("A webhook message cannot contain more than 5 action rows."); + } + + QueryBuilder builder = new() + { + RootUri = $"webhooks/{webhookId}/{webhookToken}" + }; + + if (query.ThreadId is not null) + { + builder.AddParameter("thread_id", query.ThreadId.Value.ToString()); + } + + if (query.Wait is not null) + { + builder.AddParameter("wait", query.Wait.Value.ToString().ToLowerInvariant()); + } + + if (query.Wait == true) + { +#pragma warning disable CS8619 // Nullability of reference types in value doesn't match target type. + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Patch, + builder.Build(), + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Webhook, + Id = webhookId + } + ) + .WithFullRatelimit($"PATCH webhooks/{webhookId}/:webhook-token/messages/:message-id") + .WithPayload(payload) + .AsWebhookRequest(), + info, + ct + ); +#pragma warning restore CS8619 // Nullability of reference types in value doesn't match target type. + } + else + { + Result response = await restClient.ExecuteRequestAsync + ( + HttpMethod.Patch, + builder.Build(), + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Webhook, + Id = webhookId + } + ) + .WithFullRatelimit($"PATCH webhooks/{webhookId}/:webhook-token/messages/:message-id") + .WithPayload(payload) + .AsWebhookRequest(), + info, + ct + ); + + return response.Map(message => null); + } + } + + /// + public async ValueTask>> GetChannelWebhooksAsync + ( + Snowflake channelId, + RequestInfo info = default, + CancellationToken ct = default + ) + { + return await restClient.ExecuteRequestAsync> + ( + HttpMethod.Get, + $"channels/{channelId}/webhooks", + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Channel, + Id = channelId + } + ) + .WithFullRatelimit($"GET channels/{channelId}/webhooks"), + info, + ct + ); + } + + /// + public async ValueTask>> GetGuildWebhooksAsync + ( + Snowflake guildId, + RequestInfo info = default, + CancellationToken ct = default + ) + { + return await restClient.ExecuteRequestAsync> + ( + HttpMethod.Get, + $"guilds/{guildId}/webhooks", + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Guild, + Id = guildId + } + ) + .WithFullRatelimit($"GET guilds/{guildId}/webhooks"), + info, + ct + ); + } + + /// + public async ValueTask> GetWebhookAsync + ( + Snowflake webhookId, + RequestInfo info = default, + CancellationToken ct = default + ) + { + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Get, + $"webhooks/{webhookId}", + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Webhook, + Id = webhookId + } + ) + .WithFullRatelimit($"GET webhooks/{webhookId}"), + info, + ct + ); + } + + /// + public async ValueTask> GetWebhookMessageAsync + ( + Snowflake webhookId, + string webhookToken, + Snowflake messageId, + ThreadIdQuery query = default, + RequestInfo info = default, + CancellationToken ct = default + ) + { + QueryBuilder builder = new() + { + RootUri = $"webhooks/{webhookId}/{webhookToken}/messages/{messageId}" + }; + + if (query.ThreadId is not null) + { + builder.AddParameter("thread_id", query.ThreadId.Value.ToString()); + } + + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Get, + builder.Build(), + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Webhook, + Id = webhookId + } + ) + .WithFullRatelimit($"PATCH webhooks/{webhookId}/:webhook-token/messages/:message-id"), + info, + ct + ); + } + + /// + public async ValueTask> GetWebhookWithTokenAsync + ( + Snowflake webhookId, + string webhookToken, + RequestInfo info = default, + CancellationToken ct = default + ) + { + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Get, + $"webhooks/{webhookId}/{webhookToken}", + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Webhook, + Id = webhookId + } + ) + .WithFullRatelimit($"GET webhooks/{webhookId}/:webhook-token") + .AsWebhookRequest(), + info, + ct + ); + } + + /// + public async ValueTask> ModifyWebhookAsync + ( + Snowflake webhookId, + IModifyWebhookPayload payload, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ) + { + if (payload.Name.HasValue) + { + if (payload.Name.Value.Length > 80) + { + return new ValidationError("A webhook name cannot exceed 80 characters."); + } + + if + ( + payload.Name.Value.Contains("discord", StringComparison.InvariantCultureIgnoreCase) + || payload.Name.Value.Contains("clyde", StringComparison.InvariantCultureIgnoreCase) + ) + { + return new ValidationError("A webhook name cannot contain the substrings \"clyde\" or \"discord\"."); + } + } + + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Patch, + $"webhooks/{webhookId}", + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Webhook, + Id = webhookId + } + ) + .WithFullRatelimit($"PATCH webhooks/{webhookId}") + .WithAuditLogReason(reason), + info, + ct + ); + } + + /// + public async ValueTask> ModifyWebhookWithTokenAsync + ( + Snowflake webhookId, + string webhookToken, + IModifyWebhookWithTokenPayload payload, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ) + { + if (payload.Name.HasValue) + { + if (payload.Name.Value.Length > 80) + { + return new ValidationError("A webhook name cannot exceed 80 characters."); + } + + if + ( + payload.Name.Value.Contains("discord", StringComparison.InvariantCultureIgnoreCase) + || payload.Name.Value.Contains("clyde", StringComparison.InvariantCultureIgnoreCase) + ) + { + return new ValidationError("A webhook name cannot contain the substrings \"clyde\" or \"discord\"."); + } + } + + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Patch, + $"webhooks/{webhookId}/{webhookToken}", + b => b.WithSimpleRoute + ( + new SimpleSnowflakeRatelimitRoute + { + Resource = TopLevelResource.Webhook, + Id = webhookId + } + ) + .WithFullRatelimit($"PATCH webhooks/{webhookId}/:webhook-token") + .WithAuditLogReason(reason) + .AsWebhookRequest(), + info, + ct + ); + } +} From b4414f508a2113c0832961e8c6d6e2ca4e4827b7 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Fri, 19 Jan 2024 17:01:00 +0100 Subject: [PATCH 276/323] the great ratelimit simplification --- .../IRestClient.cs | 6 +- .../RequestBuilder.cs | 8 +- .../API/ApplicationCommandsRestAPI.cs | 267 ++++-------- .../API/ApplicationRestAPI.cs | 42 +- .../API/AuditLogsRestAPI.cs | 9 +- .../API/AutoModerationRestAPI.cs | 56 ++- .../API/ChannelRestAPI.cs | 391 ++++++++---------- .../API/EmojiRestAPI.cs | 87 +--- .../API/EntitlementsRestAPI.cs | 61 +-- .../API/GuildRestAPI.cs | 183 ++------ .../API/GuildScheduledEventRestAPI.cs | 23 +- .../API/GuildTemplateRestAPI.cs | 42 +- .../API/InteractionRestAPI.cs | 102 +---- .../API/InviteRestAPI.cs | 23 +- .../API/RoleConnectionsRestAPI.cs | 23 +- .../API/SkusRestAPI.cs | 12 +- .../API/StageInstanceRestAPI.cs | 18 +- .../API/StickerRestAPI.cs | 38 +- .../API/UserRestAPI.cs | 113 +---- .../API/VoiceRestAPI.cs | 12 +- .../API/WebhookRestAPI.cs | 26 +- .../Ratelimiting/ISimpleRatelimitRoute.cs | 13 - .../SimpleSnowflakeRatelimitRoute.cs | 2 +- .../SimpleStringRatelimitRoute.cs | 21 - .../RequestBuilderExtensions.cs | 2 +- 25 files changed, 427 insertions(+), 1153 deletions(-) delete mode 100644 src/core/DSharpPlus.Internal.Rest/Ratelimiting/ISimpleRatelimitRoute.cs delete mode 100644 src/core/DSharpPlus.Internal.Rest/Ratelimiting/SimpleStringRatelimitRoute.cs diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/IRestClient.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/IRestClient.cs index a48a310abd..9066d1b98a 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/IRestClient.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/IRestClient.cs @@ -30,7 +30,7 @@ public ValueTask> ExecuteRequestAsync ( HttpMethod method, string path, - Action request, + Action? request = null, RequestInfo info = default, CancellationToken ct = default ); @@ -49,7 +49,7 @@ public ValueTask> ExecuteMultipartPayloadRequestAsync ( HttpMethod method, string path, - Action request, + Action? request = null, RequestInfo info = default, CancellationToken ct = default ); @@ -67,7 +67,7 @@ public ValueTask> ExecuteRequestAsync ( HttpMethod method, string path, - Action request, + Action? request = null, RequestInfo info = default, CancellationToken ct = default ); diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/RequestBuilder.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/RequestBuilder.cs index 1276b5090e..018cb26217 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/RequestBuilder.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/RequestBuilder.cs @@ -36,7 +36,7 @@ public class RequestBuilder /// /// Additional files to upload with this request. /// - public IDictionary? AdditionalFiles { get; set; } + public IList? AdditionalFiles { get; set; } /// /// Additional headers to add to this request. @@ -89,11 +89,11 @@ public RequestBuilder AddToContext(string key, object value) /// Adds a file to attach to the request. /// /// The builder for chaining. - public RequestBuilder AddFile(string name, AttachmentData file) + public RequestBuilder AddFile(AttachmentData file) { - this.AdditionalFiles ??= new Dictionary(); + this.AdditionalFiles ??= []; - this.AdditionalFiles.Add(name, file); + this.AdditionalFiles.Add(file); return this; } diff --git a/src/core/DSharpPlus.Internal.Rest/API/ApplicationCommandsRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/ApplicationCommandsRestAPI.cs index ac111851d2..0a8eb5355d 100644 --- a/src/core/DSharpPlus.Internal.Rest/API/ApplicationCommandsRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Rest/API/ApplicationCommandsRestAPI.cs @@ -18,7 +18,6 @@ using DSharpPlus.Internal.Abstractions.Rest.Payloads; using DSharpPlus.Internal.Abstractions.Rest.Queries; using DSharpPlus.Internal.Abstractions.Rest.Responses; -using DSharpPlus.Internal.Rest.Ratelimiting; using DSharpPlus.Serialization; using Remora.Results; @@ -36,13 +35,13 @@ ISerializationService serializationService /// public async ValueTask>> BulkOverwriteGlobalApplicationCommandsAsync ( - Snowflake applicationId, - IReadOnlyList payload, - RequestInfo info = default, + Snowflake applicationId, + IReadOnlyList payload, + RequestInfo info = default, CancellationToken ct = default ) { - foreach(ICreateGlobalApplicationCommandPayload command in payload) + foreach (ICreateGlobalApplicationCommandPayload command in payload) { if (command.Name.Length is > 32 or < 1) { @@ -74,17 +73,8 @@ public async ValueTask>> BulkOverwrite ( HttpMethod.Put, $"applications/{applicationId}/commands", - b => b.WithSimpleRoute - ( - new SimpleStringRatelimitRoute - { - IsFracturable = false, - Resource = TopLevelResource.Other, - Route = "applications/:application-id/commands" - } - ) - .WithPayload(payload) - .WithFullRatelimit("PUT applications/:application-id/commands"), + b => b.WithPayload(payload) + .WithRoute("PUT applications/:application-id/commands"), info, ct ); @@ -93,10 +83,10 @@ public async ValueTask>> BulkOverwrite /// public async ValueTask>> BulkOverwriteGuildApplicationCommandsAsync ( - Snowflake applicationId, - Snowflake guildId, - IReadOnlyList payload, - RequestInfo info = default, + Snowflake applicationId, + Snowflake guildId, + IReadOnlyList payload, + RequestInfo info = default, CancellationToken ct = default ) { @@ -132,17 +122,8 @@ public async ValueTask>> BulkOverwrite ( HttpMethod.Put, $"applications/{applicationId}/guilds/{guildId}/commands", - b => b.WithSimpleRoute - ( - new SimpleStringRatelimitRoute - { - IsFracturable = false, - Resource = TopLevelResource.Other, - Route = "applications/:application-id/guilds/:guild-id/commands" - } - ) - .WithPayload(payload) - .WithFullRatelimit("PUT applications/:application-id/guilds/:guild-id/commands"), + b => b.WithPayload(payload) + .WithRoute("PUT applications/:application-id/guilds/:guild-id/commands"), info, ct ); @@ -151,9 +132,9 @@ public async ValueTask>> BulkOverwrite /// public async ValueTask> CreateGlobalApplicationCommandAsync ( - Snowflake applicationId, - ICreateGlobalApplicationCommandPayload payload, - RequestInfo info = default, + Snowflake applicationId, + ICreateGlobalApplicationCommandPayload payload, + RequestInfo info = default, CancellationToken ct = default ) { @@ -181,17 +162,8 @@ public async ValueTask> CreateGlobalApp ( HttpMethod.Post, $"applications/{applicationId}/commands", - b => b.WithSimpleRoute - ( - new SimpleStringRatelimitRoute - { - IsFracturable = false, - Resource = TopLevelResource.Other, - Route = "applications/:application-id/commands" - } - ) - .WithPayload(payload) - .WithFullRatelimit("POST applications/:application-id/commands"), + b => b.WithPayload(payload) + .WithRoute("POST applications/:application-id/commands"), info, ct ); @@ -214,10 +186,10 @@ await response.Entity.Content.ReadAsByteArrayAsync(ct) /// public async ValueTask> CreateGuildApplicationCommandAsync ( - Snowflake applicationId, - Snowflake guildId, - ICreateGuildApplicationCommandPayload payload, - RequestInfo info = default, + Snowflake applicationId, + Snowflake guildId, + ICreateGuildApplicationCommandPayload payload, + RequestInfo info = default, CancellationToken ct = default ) { @@ -245,17 +217,8 @@ public async ValueTask> CreateGuildAppl ( HttpMethod.Post, $"applications/{applicationId}/guilds/{guildId}/commands", - b => b.WithSimpleRoute - ( - new SimpleStringRatelimitRoute - { - IsFracturable = false, - Resource = TopLevelResource.Other, - Route = "applications/:application-id/guilds/:guild-id/commands" - } - ) - .WithPayload(payload) - .WithFullRatelimit("POST applications/:application-id/guilds/:guild-id/commands"), + b => b.WithPayload(payload) + .WithRoute("POST applications/:application-id/guilds/:guild-id/commands"), info, ct ); @@ -278,9 +241,9 @@ await response.Entity.Content.ReadAsByteArrayAsync(ct) /// public async ValueTask DeleteGlobalApplicationCommandAsync ( - Snowflake applicationId, - Snowflake commandId, - RequestInfo info = default, + Snowflake applicationId, + Snowflake commandId, + RequestInfo info = default, CancellationToken ct = default ) { @@ -288,16 +251,7 @@ public async ValueTask DeleteGlobalApplicationCommandAsync ( HttpMethod.Delete, $"applications/{applicationId}/commands/{commandId}", - b => b.WithSimpleRoute - ( - new SimpleStringRatelimitRoute - { - IsFracturable = false, - Resource = TopLevelResource.Other, - Route = "applications/:application-id/commands/:command-id" - } - ) - .WithFullRatelimit("DELETE applications/:application-id/commands/:command-id"), + b => b.WithRoute("DELETE applications/:application-id/commands/:command-id"), info, ct ); @@ -308,10 +262,10 @@ public async ValueTask DeleteGlobalApplicationCommandAsync /// public async ValueTask DeleteGuildApplicationCommandAsync ( - Snowflake applicationId, - Snowflake guildId, - Snowflake commandId, - RequestInfo info = default, + Snowflake applicationId, + Snowflake guildId, + Snowflake commandId, + RequestInfo info = default, CancellationToken ct = default ) { @@ -319,16 +273,7 @@ public async ValueTask DeleteGuildApplicationCommandAsync ( HttpMethod.Delete, $"applications/{applicationId}/guilds/{guildId}/commands/{commandId}", - b => b.WithSimpleRoute - ( - new SimpleStringRatelimitRoute - { - IsFracturable = false, - Resource = TopLevelResource.Other, - Route = "applications/:application-id/guilds/:guild-id/commands/:command-id" - } - ) - .WithFullRatelimit("DELETE applications/:application-id/guilds/:guild-id/commands/:command-id"), + b => b.WithRoute("DELETE applications/:application-id/guilds/:guild-id/commands/:command-id"), info, ct ); @@ -339,10 +284,10 @@ public async ValueTask DeleteGuildApplicationCommandAsync /// public async ValueTask> EditGlobalApplicationCommandAsync ( - Snowflake applicationId, - Snowflake commandId, - IEditGlobalApplicationCommandPayload payload, - RequestInfo info = default, + Snowflake applicationId, + Snowflake commandId, + IEditGlobalApplicationCommandPayload payload, + RequestInfo info = default, CancellationToken ct = default ) { @@ -370,17 +315,8 @@ public async ValueTask> EditGlobalApplicationCommand ( HttpMethod.Patch, $"applications/{applicationId}/commands/{commandId}", - b => b.WithSimpleRoute - ( - new SimpleStringRatelimitRoute - { - IsFracturable = false, - Resource = TopLevelResource.Other, - Route = "applications/:application-id/commands/:command-id" - } - ) - .WithPayload(payload) - .WithFullRatelimit("PATCH applications/:application-id/commands/:command-id"), + b => b.WithPayload(payload) + .WithRoute("PATCH applications/:application-id/commands/:command-id"), info, ct ); @@ -389,11 +325,11 @@ public async ValueTask> EditGlobalApplicationCommand /// public async ValueTask> EditGuildApplicationCommandAsync ( - Snowflake applicationId, - Snowflake guildId, - Snowflake commandId, - IEditGuildApplicationCommandPayload payload, - RequestInfo info = default, + Snowflake applicationId, + Snowflake guildId, + Snowflake commandId, + IEditGuildApplicationCommandPayload payload, + RequestInfo info = default, CancellationToken ct = default ) { @@ -421,17 +357,8 @@ public async ValueTask> EditGuildApplicationCommandA ( HttpMethod.Patch, $"applications/{applicationId}/guild/{guildId}/commands/{commandId}", - b => b.WithSimpleRoute - ( - new SimpleStringRatelimitRoute - { - IsFracturable = false, - Resource = TopLevelResource.Other, - Route = "applications/:application-id/guilds/:guild-id/commands/:command-id" - } - ) - .WithPayload(payload) - .WithFullRatelimit("PATCH applications/:application-id/guilds/:guild-id/commands/:command-id"), + b => b.WithPayload(payload) + .WithRoute("PATCH applications/:application-id/guilds/:guild-id/commands/:command-id"), info, ct ); @@ -440,10 +367,10 @@ public async ValueTask> EditGuildApplicationCommandA /// public async ValueTask> GetApplicationCommandPermissionsAsync ( - Snowflake applicationId, - Snowflake guildId, - Snowflake commandId, - RequestInfo info = default, + Snowflake applicationId, + Snowflake guildId, + Snowflake commandId, + RequestInfo info = default, CancellationToken ct = default ) { @@ -451,16 +378,7 @@ public async ValueTask> GetApplicationCom ( HttpMethod.Get, $"applications/{applicationId}/guild/{guildId}/commands/{commandId}/permissions", - b => b.WithSimpleRoute - ( - new SimpleStringRatelimitRoute - { - IsFracturable = false, - Resource = TopLevelResource.Other, - Route = "applications/:application-id/guilds/:guild-id/commands/:command-id/permissions" - } - ) - .WithFullRatelimit("GET applications/:application-id/guilds/:guild-id/commands/:command-id/permissions"), + b => b.WithRoute("GET applications/:application-id/guilds/:guild-id/commands/:command-id/permissions"), info, ct ); @@ -469,9 +387,9 @@ public async ValueTask> GetApplicationCom /// public async ValueTask> GetGlobalApplicationCommandAsync ( - Snowflake applicationId, - Snowflake commandId, - RequestInfo info = default, + Snowflake applicationId, + Snowflake commandId, + RequestInfo info = default, CancellationToken ct = default ) { @@ -479,16 +397,7 @@ public async ValueTask> GetGlobalApplicationCommandA ( HttpMethod.Get, $"applications/{applicationId}/commands/{commandId}", - b => b.WithSimpleRoute - ( - new SimpleStringRatelimitRoute - { - IsFracturable = false, - Resource = TopLevelResource.Other, - Route = "applications/:application-id/commands/:command-id" - } - ) - .WithFullRatelimit("GET applications/:application-id/commands/:command-id"), + b => b.WithRoute("GET applications/:application-id/commands/:command-id"), info, ct ); @@ -497,9 +406,9 @@ public async ValueTask> GetGlobalApplicationCommandA /// public async ValueTask>> GetGlobalApplicationCommandsAsync ( - Snowflake applicationId, - LocalizationQuery query = default, - RequestInfo info = default, + Snowflake applicationId, + LocalizationQuery query = default, + RequestInfo info = default, CancellationToken ct = default ) { @@ -517,16 +426,7 @@ public async ValueTask>> GetGlobalAppl ( HttpMethod.Get, builder.Build(), - b => b.WithSimpleRoute - ( - new SimpleStringRatelimitRoute - { - IsFracturable = false, - Resource = TopLevelResource.Other, - Route = "applications/:application-id/commands" - } - ) - .WithFullRatelimit("GET applications/:application-id/commands"), + b => b.WithRoute("GET applications/:application-id/commands"), info, ct ); @@ -536,9 +436,9 @@ public async ValueTask>> GetGlobalAppl public async ValueTask> GetGuildApplicationCommandAsync ( Snowflake applicationId, - Snowflake guildId, + Snowflake guildId, Snowflake commandId, - RequestInfo info = default, + RequestInfo info = default, CancellationToken ct = default ) { @@ -546,16 +446,7 @@ public async ValueTask> GetGuildApplicationCommandAs ( HttpMethod.Get, $"applications/{applicationId}/guilds/{guildId}/commands/{commandId}", - b => b.WithSimpleRoute - ( - new SimpleStringRatelimitRoute - { - IsFracturable = false, - Resource = TopLevelResource.Other, - Route = "applications/:application-id/guilds/:guild-id/commands/:command-id" - } - ) - .WithFullRatelimit("GET applications/:application-id/guilds/:guild-id/commands/:command-id"), + b => b.WithRoute("GET applications/:application-id/guilds/:guild-id/commands/:command-id"), info, ct ); @@ -564,9 +455,9 @@ public async ValueTask> GetGuildApplicationCommandAs /// public async ValueTask>> GetGuildApplicationCommandPermissionsAsync ( - Snowflake applicationId, - Snowflake guildId, - RequestInfo info = default, + Snowflake applicationId, + Snowflake guildId, + RequestInfo info = default, CancellationToken ct = default ) { @@ -574,16 +465,7 @@ public async ValueTask>> Ge ( HttpMethod.Get, $"applications/{applicationId}/guild/{guildId}/commands/permissions", - b => b.WithSimpleRoute - ( - new SimpleStringRatelimitRoute - { - IsFracturable = false, - Resource = TopLevelResource.Other, - Route = "applications/:application-id/guilds/:guild-id/commands/permissions" - } - ) - .WithFullRatelimit("GET applications/:application-id/guilds/:guild-id/commands/permissions"), + b => b.WithRoute("GET applications/:application-id/guilds/:guild-id/commands/permissions"), info, ct ); @@ -592,10 +474,10 @@ public async ValueTask>> Ge /// public async ValueTask>> GetGuildApplicationCommandsAsync ( - Snowflake applicationId, - Snowflake guildId, - LocalizationQuery query = default, - RequestInfo info = default, + Snowflake applicationId, + Snowflake guildId, + LocalizationQuery query = default, + RequestInfo info = default, CancellationToken ct = default ) { @@ -613,16 +495,7 @@ public async ValueTask>> GetGuildAppli ( HttpMethod.Get, builder.Build(), - b => b.WithSimpleRoute - ( - new SimpleStringRatelimitRoute - { - IsFracturable = false, - Resource = TopLevelResource.Other, - Route = "applications/:application-id/guilds/:guild-id/commands" - } - ) - .WithFullRatelimit("GET applications/:application-id/guilds/:guild-id/commands"), + b => b.WithRoute("GET applications/:application-id/guilds/:guild-id/commands"), info, ct ); diff --git a/src/core/DSharpPlus.Internal.Rest/API/ApplicationRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/ApplicationRestAPI.cs index e00fd1430a..aa5eee5c2d 100644 --- a/src/core/DSharpPlus.Internal.Rest/API/ApplicationRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Rest/API/ApplicationRestAPI.cs @@ -13,24 +13,20 @@ using DSharpPlus.Internal.Abstractions.Rest.API; using DSharpPlus.Internal.Abstractions.Rest.Errors; using DSharpPlus.Internal.Abstractions.Rest.Payloads; -using DSharpPlus.Internal.Rest.Ratelimiting; using Remora.Results; namespace DSharpPlus.Internal.Rest.API; /// -public sealed class ApplicationRestAPI -( - IRestClient restClient -) +public sealed class ApplicationRestAPI(IRestClient restClient) : IApplicationRestAPI { /// public async ValueTask> EditCurrentApplicationAsync ( - IEditCurrentApplicationPayload payload, - RequestInfo info = default, + IEditCurrentApplicationPayload payload, + RequestInfo info = default, CancellationToken ct = default ) { @@ -51,17 +47,7 @@ public async ValueTask> EditCurrentApplicationAsync ( HttpMethod.Patch, $"applications/@me", - b => b.WithSimpleRoute - ( - new SimpleStringRatelimitRoute - { - IsFracturable = false, - Resource = TopLevelResource.Other, - Route = "applications/@me" - } - ) - .WithPayload(payload) - .WithFullRatelimit("PATCH applications/@me"), + b => b.WithPayload(payload), info, ct ); @@ -70,26 +56,16 @@ public async ValueTask> EditCurrentApplicationAsync /// public async ValueTask> GetCurrentApplicationAsync ( - RequestInfo info = default, + RequestInfo info = default, CancellationToken ct = default ) { return await restClient.ExecuteRequestAsync ( - HttpMethod.Get, - $"applications/@me", - b => b.WithSimpleRoute - ( - new SimpleStringRatelimitRoute - { - IsFracturable = false, - Resource = TopLevelResource.Other, - Route = "applications/@me" - } - ) - .WithFullRatelimit("GET applications/@me"), - info, - ct + method: HttpMethod.Get, + path: $"applications/@me", + info: info, + ct: ct ); } } diff --git a/src/core/DSharpPlus.Internal.Rest/API/AuditLogsRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/AuditLogsRestAPI.cs index 2648364061..e516b91b2b 100644 --- a/src/core/DSharpPlus.Internal.Rest/API/AuditLogsRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Rest/API/AuditLogsRestAPI.cs @@ -28,9 +28,9 @@ IRestClient restClient /// public async ValueTask> ListGuildAuditLogEntriesAsync ( - Snowflake guildId, - ListGuildAuditLogEntriesQuery query = default, - RequestInfo info = default, + Snowflake guildId, + ListGuildAuditLogEntriesQuery query = default, + RequestInfo info = default, CancellationToken ct = default ) { @@ -82,8 +82,7 @@ public async ValueTask> ListGuildAuditLogEntriesAsync Id = guildId } ) - .WithRoute($"guilds/{guildId}/audit-logs") - .WithFullRatelimit($"GET guilds/{guildId}/audit-logs"), + .WithRoute($"GET guilds/{guildId}/audit-logs"), info, ct ); diff --git a/src/core/DSharpPlus.Internal.Rest/API/AutoModerationRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/AutoModerationRestAPI.cs index b2788e788a..5f367d265f 100644 --- a/src/core/DSharpPlus.Internal.Rest/API/AutoModerationRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Rest/API/AutoModerationRestAPI.cs @@ -21,19 +21,16 @@ namespace DSharpPlus.Internal.Rest.API; /// -public sealed class AutoModerationRestAPI -( - IRestClient restClient -) +public sealed class AutoModerationRestAPI(IRestClient restClient) : IAutoModerationRestAPI { /// public async ValueTask> CreateAutoModerationRuleAsync ( - Snowflake guildId, - ICreateAutoModerationRulePayload payload, - string? reason = null, - RequestInfo info = default, + Snowflake guildId, + ICreateAutoModerationRulePayload payload, + string? reason = null, + RequestInfo info = default, CancellationToken ct = default ) { @@ -59,8 +56,6 @@ public async ValueTask> CreateAutoModerationRuleAsyn Id = guildId } ) - .WithRoute($"guilds/{guildId}/auto-moderation/rules") - .WithFullRatelimit($"POST guilds/{guildId}/auto-moderation/rules") .WithAuditLogReason(reason), info, ct @@ -70,10 +65,10 @@ public async ValueTask> CreateAutoModerationRuleAsyn /// public async ValueTask DeleteAutoModerationRuleAsync ( - Snowflake guildId, - Snowflake ruleId, - string? reason = null, - RequestInfo info = default, + Snowflake guildId, + Snowflake ruleId, + string? reason = null, + RequestInfo info = default, CancellationToken ct = default ) { @@ -89,8 +84,7 @@ public async ValueTask DeleteAutoModerationRuleAsync Id = guildId } ) - .WithRoute($"guilds/{guildId}/auto-moderation/rules/:rule-id") - .WithFullRatelimit($"DELETE guilds/{guildId}/auto-moderation/rules/:rule-id") + .WithRoute($"DELETE guilds/{guildId}/auto-moderation/rules/:rule-id") .WithAuditLogReason(reason), info, ct @@ -102,9 +96,9 @@ public async ValueTask DeleteAutoModerationRuleAsync /// public async ValueTask> GetAutoModerationRuleAsync ( - Snowflake guildId, - Snowflake ruleId, - RequestInfo info = default, + Snowflake guildId, + Snowflake ruleId, + RequestInfo info = default, CancellationToken ct = default ) { @@ -120,8 +114,7 @@ public async ValueTask> GetAutoModerationRuleAsync Id = guildId } ) - .WithRoute($"guilds/{guildId}/auto-moderation/rules/:rule-id") - .WithFullRatelimit($"GET guilds/{guildId}/auto-moderation/rules/:rule-id"), + .WithRoute($"GET guilds/{guildId}/auto-moderation/rules/:rule-id"), info, ct ); @@ -130,8 +123,8 @@ public async ValueTask> GetAutoModerationRuleAsync /// public async ValueTask>> ListAutoModerationRulesAsync ( - Snowflake guildId, - RequestInfo info = default, + Snowflake guildId, + RequestInfo info = default, CancellationToken ct = default ) { @@ -146,9 +139,7 @@ public async ValueTask>> ListAutoModer Resource = TopLevelResource.Guild, Id = guildId } - ) - .WithRoute($"guilds/{guildId}/auto-moderation/rules") - .WithFullRatelimit($"GET guilds/{guildId}/auto-moderation/rules"), + ), info, ct ); @@ -157,11 +148,11 @@ public async ValueTask>> ListAutoModer /// public async ValueTask> ModifyAutoModerationRuleAsync ( - Snowflake guildId, - Snowflake ruleId, - IModifyAutoModerationRulePayload payload, - string? reason = null, - RequestInfo info = default, + Snowflake guildId, + Snowflake ruleId, + IModifyAutoModerationRulePayload payload, + string? reason = null, + RequestInfo info = default, CancellationToken ct = default ) { @@ -187,8 +178,7 @@ public async ValueTask> ModifyAutoModerationRuleAsyn Id = guildId } ) - .WithRoute($"guilds/{guildId}/auto-moderation/rules/:rule-id") - .WithFullRatelimit($"PATCH guilds/{guildId}/auto-moderation/rules/:rule-id") + .WithRoute($"PATCH guilds/{guildId}/auto-moderation/rules/:rule-id") .WithAuditLogReason(reason), info, ct diff --git a/src/core/DSharpPlus.Internal.Rest/API/ChannelRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/ChannelRestAPI.cs index 6110f08662..1bcaea7865 100644 --- a/src/core/DSharpPlus.Internal.Rest/API/ChannelRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Rest/API/ChannelRestAPI.cs @@ -25,18 +25,15 @@ namespace DSharpPlus.Internal.Rest.API; /// -public sealed class ChannelRestAPI -( - IRestClient restClient -) +public sealed class ChannelRestAPI(IRestClient restClient) : IChannelRestAPI { /// public async ValueTask AddThreadMemberAsync ( - Snowflake threadId, - Snowflake userId, - RequestInfo info = default, + Snowflake threadId, + Snowflake userId, + RequestInfo info = default, CancellationToken ct = default ) { @@ -52,8 +49,7 @@ public async ValueTask AddThreadMemberAsync Id = threadId } ) - .WithRoute($"channels/{threadId}/thread-members/:user-id") - .WithFullRatelimit($"PUT channels/{threadId}/thread-members/:user-id"), + .WithRoute($"PUT channels/{threadId}/thread-members/:user-id"), info, ct ); @@ -64,10 +60,10 @@ public async ValueTask AddThreadMemberAsync /// public async ValueTask BulkDeleteMessagesAsync ( - Snowflake channelId, - IBulkDeleteMessagesPayload payload, - string? reason = null, - RequestInfo info = default, + Snowflake channelId, + IBulkDeleteMessagesPayload payload, + string? reason = null, + RequestInfo info = default, CancellationToken ct = default ) { @@ -83,8 +79,6 @@ public async ValueTask BulkDeleteMessagesAsync Id = channelId } ) - .WithRoute($"channels/{channelId}/messages/bulk-delete") - .WithFullRatelimit($"POST channels/{channelId}/messages/bulk-delete") .WithPayload(payload) .WithAuditLogReason(reason), info, @@ -97,10 +91,10 @@ public async ValueTask BulkDeleteMessagesAsync /// public async ValueTask> CreateChannelInviteAsync ( - Snowflake channelId, - ICreateChannelInvitePayload payload, - string? reason = null, - RequestInfo info = default, + Snowflake channelId, + ICreateChannelInvitePayload payload, + string? reason = null, + RequestInfo info = default, CancellationToken ct = default ) { @@ -145,8 +139,6 @@ public async ValueTask> CreateChannelInviteAsync Id = channelId } ) - .WithRoute($"channels/{channelId}/invites") - .WithFullRatelimit($"POST channels/{channelId}/invites") .WithPayload(payload) .WithAuditLogReason(reason), info, @@ -157,13 +149,13 @@ public async ValueTask> CreateChannelInviteAsync /// public async ValueTask> CreateMessageAsync ( - Snowflake channelId, + Snowflake channelId, ICreateMessagePayload payload, RequestInfo info = default, CancellationToken ct = default ) { - if + if ( !(payload.Content.HasValue || payload.Embeds.HasValue || payload.StickerIds.HasValue || payload.Components.HasValue || payload.Files is not null) @@ -207,8 +199,6 @@ public async ValueTask> CreateMessageAsync Id = channelId } ) - .WithRoute($"channels/{channelId}/messages") - .WithFullRatelimit($"POST channels/{channelId}/messages") .WithPayload(payload), info, ct @@ -218,10 +208,10 @@ public async ValueTask> CreateMessageAsync /// public async ValueTask CreateReactionAsync ( - Snowflake channelId, - Snowflake messageId, - string emoji, - RequestInfo info = default, + Snowflake channelId, + Snowflake messageId, + string emoji, + RequestInfo info = default, CancellationToken ct = default ) { @@ -237,8 +227,7 @@ public async ValueTask CreateReactionAsync Id = channelId } ) - .WithRoute($"channels/{channelId}/messages/:message-id/reactions/:emoji/@me") - .WithFullRatelimit($"PUT channels/{channelId}/messages/:message-id/reactions/:emoji/@me"), + .WithRoute($"PUT channels/{channelId}/messages/:message-id/reactions/:emoji/@me"), info, ct ); @@ -249,9 +238,9 @@ public async ValueTask CreateReactionAsync /// public async ValueTask> CrosspostMessageAsync ( - Snowflake channelId, - Snowflake messageId, - RequestInfo info = default, + Snowflake channelId, + Snowflake messageId, + RequestInfo info = default, CancellationToken ct = default ) { @@ -267,8 +256,7 @@ public async ValueTask> CrosspostMessageAsync Id = channelId } ) - .WithRoute($"channels/{channelId}/messages/:message-id/crosspost") - .WithFullRatelimit($"POST channels/{channelId}/messages/:message-id/crosspost"), + .WithRoute($"POST channels/{channelId}/messages/:message-id/crosspost"), info, ct ); @@ -277,9 +265,9 @@ public async ValueTask> CrosspostMessageAsync /// public async ValueTask DeleteAllReactionsAsync ( - Snowflake channelId, - Snowflake messageId, - RequestInfo info = default, + Snowflake channelId, + Snowflake messageId, + RequestInfo info = default, CancellationToken ct = default ) { @@ -295,8 +283,7 @@ public async ValueTask DeleteAllReactionsAsync Id = channelId } ) - .WithRoute($"channels/{channelId}/messages/:message-id/reactions") - .WithFullRatelimit($"DELETE channels/{channelId}/messages/:message-id/reactions"), + .WithRoute($"DELETE channels/{channelId}/messages/:message-id/reactions"), info, ct ); @@ -307,10 +294,10 @@ public async ValueTask DeleteAllReactionsAsync /// public async ValueTask DeleteAllReactionsForEmojiAsync ( - Snowflake channelId, - Snowflake messageId, - string emoji, - RequestInfo info = default, + Snowflake channelId, + Snowflake messageId, + string emoji, + RequestInfo info = default, CancellationToken ct = default ) { @@ -326,8 +313,7 @@ public async ValueTask DeleteAllReactionsForEmojiAsync Id = channelId } ) - .WithRoute($"channels/{channelId}/messages/:message-id/reactions/:emoji") - .WithFullRatelimit($"DELETE channels/{channelId}/messages/:message-id/reactions/:emoji"), + .WithRoute($"DELETE channels/{channelId}/messages/:message-id/reactions/:emoji"), info, ct ); @@ -338,9 +324,9 @@ public async ValueTask DeleteAllReactionsForEmojiAsync /// public async ValueTask> DeleteChannelAsync ( - Snowflake channelId, - string? reason = null, - RequestInfo info = default, + Snowflake channelId, + string? reason = null, + RequestInfo info = default, CancellationToken ct = default ) { @@ -356,8 +342,6 @@ public async ValueTask> DeleteChannelAsync Id = channelId } ) - .WithRoute($"channels/{channelId}") - .WithFullRatelimit($"DELETE channels/{channelId}") .WithAuditLogReason(reason), info, ct @@ -367,8 +351,8 @@ public async ValueTask> DeleteChannelAsync /// public async ValueTask DeleteChannelPermissionAsync ( - Snowflake channelId, - Snowflake overwriteId, + Snowflake channelId, + Snowflake overwriteId, string? reason = null, RequestInfo info = default, CancellationToken ct = default @@ -386,8 +370,6 @@ public async ValueTask DeleteChannelPermissionAsync Id = channelId } ) - .WithRoute($"channels/{channelId}/permissions/:overwrite-id") - .WithFullRatelimit($"DELETE channels/{channelId}/permissions/:overwrite-id") .WithAuditLogReason(reason), info, ct @@ -399,10 +381,10 @@ public async ValueTask DeleteChannelPermissionAsync /// public async ValueTask DeleteMessageAsync ( - Snowflake channelId, - Snowflake messageId, - string? reason = null, - RequestInfo info = default, + Snowflake channelId, + Snowflake messageId, + string? reason = null, + RequestInfo info = default, CancellationToken ct = default ) { @@ -418,8 +400,7 @@ public async ValueTask DeleteMessageAsync Id = channelId } ) - .WithRoute($"channels/{channelId}/messages/:message-id") - .WithFullRatelimit($"DELETE channels/{channelId}/messages/:message-id") + .WithRoute($"DELETE channels/{channelId}/messages/:message-id") .WithAuditLogReason(reason), info, ct @@ -431,10 +412,10 @@ public async ValueTask DeleteMessageAsync /// public async ValueTask DeleteOwnReactionAsync ( - Snowflake channelId, - Snowflake messageId, - string emoji, - RequestInfo info = default, + Snowflake channelId, + Snowflake messageId, + string emoji, + RequestInfo info = default, CancellationToken ct = default ) { @@ -450,8 +431,7 @@ public async ValueTask DeleteOwnReactionAsync Id = channelId } ) - .WithRoute($"channels/{channelId}/messages/:message-id/reactions/:emoji/@me") - .WithFullRatelimit($"DELETE channels/{channelId}/messages/:message-id/reactions/:emoji/@me"), + .WithRoute($"DELETE channels/{channelId}/messages/:message-id/reactions/:emoji/@me"), info, ct ); @@ -462,11 +442,11 @@ public async ValueTask DeleteOwnReactionAsync /// public async ValueTask DeleteUserReactionAsync ( - Snowflake channelId, - Snowflake messageId, - Snowflake userId, - string emoji, - RequestInfo info = default, + Snowflake channelId, + Snowflake messageId, + Snowflake userId, + string emoji, + RequestInfo info = default, CancellationToken ct = default ) { @@ -482,8 +462,7 @@ public async ValueTask DeleteUserReactionAsync Id = channelId } ) - .WithRoute($"channels/{channelId}/messages/:message-id/reactions/:emoji/:user-id") - .WithFullRatelimit($"DELETE channels/{channelId}/messages/:message-id/reactions/:emoji/:user-id"), + .WithRoute($"DELETE channels/{channelId}/messages/:message-id/reactions/:emoji/:user-id"), info, ct ); @@ -494,8 +473,8 @@ public async ValueTask DeleteUserReactionAsync /// public async ValueTask EditChannelPermissionsAsync ( - Snowflake channelId, - Snowflake overwriteId, + Snowflake channelId, + Snowflake overwriteId, IEditChannelPermissionsPayload payload, string? reason = null, RequestInfo info = default, @@ -514,8 +493,7 @@ public async ValueTask EditChannelPermissionsAsync Id = channelId } ) - .WithRoute($"channels/{channelId}/permissions/:overwrite-id") - .WithFullRatelimit($"PUT channels/{channelId}/permissions/:overwrite-id") + .WithRoute($"PUT channels/{channelId}/permissions/:overwrite-id") .WithPayload(payload) .WithAuditLogReason(reason), info, @@ -528,10 +506,10 @@ public async ValueTask EditChannelPermissionsAsync /// public async ValueTask> EditMessageAsync ( - Snowflake channelId, - Snowflake messageId, - IEditMessagePayload payload, - RequestInfo info = default, + Snowflake channelId, + Snowflake messageId, + IEditMessagePayload payload, + RequestInfo info = default, CancellationToken ct = default ) { @@ -557,8 +535,7 @@ public async ValueTask> EditMessageAsync Id = channelId } ) - .WithRoute($"channels/{channelId}/messages/:message-id") - .WithFullRatelimit($"PATCH channels/{channelId}/messages/:message-id") + .WithRoute($"PATCH channels/{channelId}/messages/:message-id") .WithPayload(payload), info, ct @@ -568,9 +545,9 @@ public async ValueTask> EditMessageAsync /// public async ValueTask> FollowAnnouncementChannelAsync ( - Snowflake channelId, - IFollowAnnouncementChannelPayload payload, - RequestInfo info = default, + Snowflake channelId, + IFollowAnnouncementChannelPayload payload, + RequestInfo info = default, CancellationToken ct = default ) { @@ -586,8 +563,6 @@ public async ValueTask> FollowAnnouncementChannelAsync Id = channelId } ) - .WithRoute($"channels/{channelId}/followers") - .WithFullRatelimit($"POST channels/{channelId}/followers") .WithPayload(payload), info, ct @@ -597,8 +572,8 @@ public async ValueTask> FollowAnnouncementChannelAsync /// public async ValueTask> GetChannelAsync ( - Snowflake channelId, - RequestInfo info = default, + Snowflake channelId, + RequestInfo info = default, CancellationToken ct = default ) { @@ -613,8 +588,7 @@ public async ValueTask> GetChannelAsync Resource = TopLevelResource.Channel, Id = channelId } - ) - .WithFullRatelimit($"GET channels/{channelId}"), + ), info, ct ); @@ -623,8 +597,8 @@ public async ValueTask> GetChannelAsync /// public async ValueTask>> GetChannelInvitesAsync ( - Snowflake channelId, - RequestInfo info = default, + Snowflake channelId, + RequestInfo info = default, CancellationToken ct = default ) { @@ -639,8 +613,7 @@ public async ValueTask>> GetChannelInvitesAsync Resource = TopLevelResource.Channel, Id = channelId } - ) - .WithFullRatelimit($"GET channels/{channelId}/invites"), + ), info, ct ); @@ -649,9 +622,9 @@ public async ValueTask>> GetChannelInvitesAsync /// public async ValueTask> GetChannelMessageAsync ( - Snowflake channelId, - Snowflake messageId, - RequestInfo info = default, + Snowflake channelId, + Snowflake messageId, + RequestInfo info = default, CancellationToken ct = default ) { @@ -667,8 +640,7 @@ public async ValueTask> GetChannelMessageAsync Id = channelId } ) - .WithRoute($"channels/{channelId}/messages/:message-id") - .WithFullRatelimit($"GET channels/{channelId}/messages/:message-id"), + .WithRoute($"GET channels/{channelId}/messages/:message-id"), info, ct ); @@ -677,9 +649,9 @@ public async ValueTask> GetChannelMessageAsync /// public async ValueTask>> GetChannelMessagesAsync ( - Snowflake channelId, - GetChannelMessagesQuery query = default, - RequestInfo info = default, + Snowflake channelId, + GetChannelMessagesQuery query = default, + RequestInfo info = default, CancellationToken ct = default ) { @@ -722,9 +694,7 @@ public async ValueTask>> GetChannelMessagesAsync Resource = TopLevelResource.Channel, Id = channelId } - ) - .WithRoute($"channels/{channelId}/messages") - .WithFullRatelimit($"GET channels/{channelId}/messages"), + ), info, ct ); @@ -749,9 +719,7 @@ public async ValueTask>> GetPinnedMessagesAsync Resource = TopLevelResource.Channel, Id = channelId } - ) - .WithRoute($"channels/{channelId}/pins") - .WithFullRatelimit($"GET channels/{channelId}/pins"), + ), info, ct ); @@ -760,11 +728,11 @@ public async ValueTask>> GetPinnedMessagesAsync /// public async ValueTask>> GetReactionsAsync ( - Snowflake channelId, - Snowflake messageId, - string emoji, - ForwardsPaginatedQuery query = default, - RequestInfo info = default, + Snowflake channelId, + Snowflake messageId, + string emoji, + ForwardsPaginatedQuery query = default, + RequestInfo info = default, CancellationToken ct = default ) { @@ -795,8 +763,7 @@ public async ValueTask>> GetReactionsAsync Id = channelId } ) - .WithRoute($"channels/{channelId}/messages/:message-id/reactions/:emoji") - .WithFullRatelimit($"GET channels/{channelId}/messages/:message-id/reactions/:emoji"), + .WithRoute($"GET channels/{channelId}/messages/:message-id/reactions/:emoji"), info, ct ); @@ -805,10 +772,10 @@ public async ValueTask>> GetReactionsAsync /// public async ValueTask> GetThreadMemberAsync ( - Snowflake threadId, - Snowflake userId, - GetThreadMemberQuery query = default, - RequestInfo info = default, + Snowflake threadId, + Snowflake userId, + GetThreadMemberQuery query = default, + RequestInfo info = default, CancellationToken ct = default ) { @@ -834,8 +801,7 @@ public async ValueTask> GetThreadMemberAsync Id = threadId } ) - .WithRoute($"channels/{threadId}/thread-members/:user-id") - .WithFullRatelimit($"GET channels/{threadId}/thread-members/:user-id"), + .WithRoute($"GET channels/{threadId}/thread-members/:user-id"), info, ct ); @@ -844,10 +810,10 @@ public async ValueTask> GetThreadMemberAsync /// public async ValueTask GroupDMAddRecipientAsync ( - Snowflake channelId, - Snowflake userId, - IGroupDMAddRecipientPayload payload, - RequestInfo info = default, + Snowflake channelId, + Snowflake userId, + IGroupDMAddRecipientPayload payload, + RequestInfo info = default, CancellationToken ct = default ) { @@ -863,8 +829,7 @@ public async ValueTask GroupDMAddRecipientAsync Id = channelId } ) - .WithRoute($"channels/{channelId}/recipients/:user-id") - .WithFullRatelimit($"PUT channels/{channelId}/recipients/:user-id") + .WithRoute($"PUT channels/{channelId}/recipients/:user-id") .WithPayload(payload), info, ct @@ -876,9 +841,9 @@ public async ValueTask GroupDMAddRecipientAsync /// public async ValueTask GroupDMRemoveRecipientAsync ( - Snowflake channelId, - Snowflake userId, - RequestInfo info = default, + Snowflake channelId, + Snowflake userId, + RequestInfo info = default, CancellationToken ct = default ) { @@ -894,8 +859,7 @@ public async ValueTask GroupDMRemoveRecipientAsync Id = channelId } ) - .WithRoute($"channels/{channelId}/recipients/:user-id") - .WithFullRatelimit($"DELETE channels/{channelId}/recipients/:user-id"), + .WithRoute($"DELETE channels/{channelId}/recipients/:user-id"), info, ct ); @@ -906,8 +870,8 @@ public async ValueTask GroupDMRemoveRecipientAsync /// public async ValueTask JoinThreadAsync ( - Snowflake threadId, - RequestInfo info = default, + Snowflake threadId, + RequestInfo info = default, CancellationToken ct = default ) { @@ -922,9 +886,7 @@ public async ValueTask JoinThreadAsync Resource = TopLevelResource.Channel, Id = threadId } - ) - .WithRoute($"channels/{threadId}/recipients/@me") - .WithFullRatelimit($"PUT channels/{threadId}/recipients/@me"), + ), info, ct ); @@ -935,8 +897,8 @@ public async ValueTask JoinThreadAsync /// public async ValueTask LeaveThreadAsync ( - Snowflake threadId, - RequestInfo info = default, + Snowflake threadId, + RequestInfo info = default, CancellationToken ct = default ) { @@ -951,9 +913,7 @@ public async ValueTask LeaveThreadAsync Resource = TopLevelResource.Channel, Id = threadId } - ) - .WithRoute($"channels/{threadId}/recipients/@me") - .WithFullRatelimit($"DELETE channels/{threadId}/recipients/@me"), + ), info, ct ); @@ -964,9 +924,9 @@ public async ValueTask LeaveThreadAsync /// public async ValueTask> ListJoinedPrivateArchivedThreadsAsync ( - Snowflake channelId, - ListJoinedPrivateArchivedThreadsQuery query = default, - RequestInfo info = default, + Snowflake channelId, + ListJoinedPrivateArchivedThreadsQuery query = default, + RequestInfo info = default, CancellationToken ct = default ) { @@ -1001,9 +961,7 @@ public async ValueTask> ListJoinedPrivateArc Resource = TopLevelResource.Channel, Id = channelId } - ) - .WithRoute($"channels/{channelId}/users/@me/threads/archived/private") - .WithFullRatelimit($"GET channels/{channelId}/users/@me/threads/archived/private"), + ), info, ct ); @@ -1012,9 +970,9 @@ public async ValueTask> ListJoinedPrivateArc /// public async ValueTask> ListPrivateArchivedThreadsAsync ( - Snowflake channelId, - ListArchivedThreadsQuery query = default, - RequestInfo info = default, + Snowflake channelId, + ListArchivedThreadsQuery query = default, + RequestInfo info = default, CancellationToken ct = default ) { @@ -1049,9 +1007,7 @@ public async ValueTask> ListPrivateArchivedT Resource = TopLevelResource.Channel, Id = channelId } - ) - .WithRoute($"channels/{channelId}/users/@me/threads/archived/private") - .WithFullRatelimit($"GET channels/{channelId}/users/@me/threads/archived/private"), + ), info, ct ); @@ -1061,8 +1017,8 @@ public async ValueTask> ListPrivateArchivedT public async ValueTask> ListPublicArchivedThreadsAsync ( Snowflake channelId, - ListArchivedThreadsQuery query = default, - RequestInfo info = default, + ListArchivedThreadsQuery query = default, + RequestInfo info = default, CancellationToken ct = default ) { @@ -1097,9 +1053,7 @@ public async ValueTask> ListPublicArchivedTh Resource = TopLevelResource.Channel, Id = channelId } - ) - .WithRoute($"channels/{channelId}/threads/archived/public") - .WithFullRatelimit($"GET channels/{channelId}/threads/archived/public"), + ), info, ct ); @@ -1108,9 +1062,9 @@ public async ValueTask> ListPublicArchivedTh /// public async ValueTask>> ListThreadMembersAsync ( - Snowflake threadId, - ListThreadMembersQuery query = default, - RequestInfo info = default, + Snowflake threadId, + ListThreadMembersQuery query = default, + RequestInfo info = default, CancellationToken ct = default ) { @@ -1150,9 +1104,7 @@ public async ValueTask>> ListThreadMembersAs Resource = TopLevelResource.Channel, Id = threadId } - ) - .WithRoute($"channels/{threadId}/thread-members") - .WithFullRatelimit($"GET channels/{threadId}/thread-members"), + ), info, ct ); @@ -1161,7 +1113,7 @@ public async ValueTask>> ListThreadMembersAs /// public async ValueTask> ModifyChannelAsync ( - Snowflake channelId, + Snowflake channelId, IModifyGroupDMPayload payload, RequestInfo info = default, CancellationToken ct = default @@ -1183,8 +1135,7 @@ public async ValueTask> ModifyChannelAsync Resource = TopLevelResource.Channel, Id = channelId } - ) - .WithFullRatelimit($"PATCH channels/{channelId}"), + ), info, ct ); @@ -1193,10 +1144,10 @@ public async ValueTask> ModifyChannelAsync /// public async ValueTask> ModifyChannelAsync ( - Snowflake channelId, - IModifyGuildChannelPayload payload, - string? reason = null, - RequestInfo info = default, + Snowflake channelId, + IModifyGuildChannelPayload payload, + string? reason = null, + RequestInfo info = default, CancellationToken ct = default ) { @@ -1251,7 +1202,6 @@ public async ValueTask> ModifyChannelAsync Id = channelId } ) - .WithFullRatelimit($"PATCH channels/{channelId}") .WithAuditLogReason(reason), info, ct @@ -1261,10 +1211,10 @@ public async ValueTask> ModifyChannelAsync /// public async ValueTask> ModifyChannelAsync ( - Snowflake channelId, - IModifyThreadChannelPayload payload, - string? reason = null, - RequestInfo info = default, + Snowflake channelId, + IModifyThreadChannelPayload payload, + string? reason = null, + RequestInfo info = default, CancellationToken ct = default ) { @@ -1306,7 +1256,6 @@ public async ValueTask> ModifyChannelAsync Id = channelId } ) - .WithFullRatelimit($"PATCH channels/{channelId}") .WithAuditLogReason(reason), info, ct @@ -1316,10 +1265,10 @@ public async ValueTask> ModifyChannelAsync /// public async ValueTask PinMessageAsync ( - Snowflake channelId, - Snowflake messageId, - string? reason = null, - RequestInfo info = default, + Snowflake channelId, + Snowflake messageId, + string? reason = null, + RequestInfo info = default, CancellationToken ct = default ) { @@ -1336,8 +1285,7 @@ public async ValueTask PinMessageAsync } ) .WithAuditLogReason(reason) - .WithRoute($"channels/{channelId}/pins/:message-id") - .WithFullRatelimit($"PUT channels/{channelId}/pins/:message-id"), + .WithRoute($"PUT channels/{channelId}/pins/:message-id"), info, ct ); @@ -1348,9 +1296,9 @@ public async ValueTask PinMessageAsync /// public async ValueTask RemoveThreadMemberAsync ( - Snowflake threadId, - Snowflake userId, - RequestInfo info = default, + Snowflake threadId, + Snowflake userId, + RequestInfo info = default, CancellationToken ct = default ) { @@ -1366,8 +1314,7 @@ public async ValueTask RemoveThreadMemberAsync Id = threadId } ) - .WithRoute($"channels/{threadId}/thread-members/:user-id") - .WithFullRatelimit($"DELETE channels/{threadId}/thread-members/:user-id"), + .WithRoute($"DELETE channels/{threadId}/thread-members/:user-id"), info, ct ); @@ -1378,11 +1325,11 @@ public async ValueTask RemoveThreadMemberAsync /// public async ValueTask> StartThreadFromMessageAsync ( - Snowflake channelId, - Snowflake messageId, - IStartThreadFromMessagePayload payload, - string? reason = null, - RequestInfo info = default, + Snowflake channelId, + Snowflake messageId, + IStartThreadFromMessagePayload payload, + string? reason = null, + RequestInfo info = default, CancellationToken ct = default ) { @@ -1419,8 +1366,7 @@ public async ValueTask> StartThreadFromMessageAsync Id = channelId } ) - .WithRoute($"channels/{channelId}/messages/:message-id/threads") - .WithFullRatelimit($"POST channels/{channelId}/messages/:message-id/threads") + .WithRoute($"POST channels/{channelId}/messages/:message-id/threads") .WithPayload(payload) .WithAuditLogReason(reason), info, @@ -1431,10 +1377,10 @@ public async ValueTask> StartThreadFromMessageAsync /// public async ValueTask> StartThreadInForumOrMediaChannelAsync ( - Snowflake channelId, - IStartThreadInForumOrMediaChannelPayload payload, - string? reason = null, - RequestInfo info = default, + Snowflake channelId, + IStartThreadInForumOrMediaChannelPayload payload, + string? reason = null, + RequestInfo info = default, CancellationToken ct = default ) { @@ -1466,10 +1412,10 @@ public async ValueTask> StartThreadInForumOrMediaChannelAsync if ( - !(payload.Message.Content.HasValue - || payload.Message.Embeds.HasValue + !(payload.Message.Content.HasValue + || payload.Message.Embeds.HasValue || payload.Message.StickerIds.HasValue - || payload.Message.Components.HasValue + || payload.Message.Components.HasValue || payload.Files is not null) ) { @@ -1506,8 +1452,6 @@ public async ValueTask> StartThreadInForumOrMediaChannelAsync Id = channelId } ) - .WithRoute($"channels/{channelId}/threads") - .WithFullRatelimit($"POST channels/{channelId}/threads") .WithPayload(payload) .WithAuditLogReason(reason), info, @@ -1518,10 +1462,10 @@ public async ValueTask> StartThreadInForumOrMediaChannelAsync /// public async ValueTask> StartThreadWithoutMessageAsync ( - Snowflake channelId, - IStartThreadWithoutMessagePayload payload, - string? reason = null, - RequestInfo info = default, + Snowflake channelId, + IStartThreadWithoutMessagePayload payload, + string? reason = null, + RequestInfo info = default, CancellationToken ct = default ) { @@ -1558,8 +1502,6 @@ public async ValueTask> StartThreadWithoutMessageAsync Id = channelId } ) - .WithRoute($"channels/{channelId}/threads") - .WithFullRatelimit($"POST channels/{channelId}/threads") .WithPayload(payload) .WithAuditLogReason(reason), info, @@ -1570,8 +1512,8 @@ public async ValueTask> StartThreadWithoutMessageAsync /// public async ValueTask TriggerTypingIndicatorAsync ( - Snowflake channelId, - RequestInfo info = default, + Snowflake channelId, + RequestInfo info = default, CancellationToken ct = default ) { @@ -1586,9 +1528,7 @@ public async ValueTask TriggerTypingIndicatorAsync Resource = TopLevelResource.Channel, Id = channelId } - ) - .WithRoute($"channels/{channelId}/typing") - .WithFullRatelimit($"POST channels/{channelId}/typing"), + ), info, ct ); @@ -1599,10 +1539,10 @@ public async ValueTask TriggerTypingIndicatorAsync /// public async ValueTask UnpinMessageAsync ( - Snowflake channelId, - Snowflake messageId, - string? reason = null, - RequestInfo info = default, + Snowflake channelId, + Snowflake messageId, + string? reason = null, + RequestInfo info = default, CancellationToken ct = default ) { @@ -1618,8 +1558,7 @@ public async ValueTask UnpinMessageAsync Id = channelId } ) - .WithRoute($"channels/{channelId}/pins/:message-id") - .WithFullRatelimit($"DELETE channels/{channelId}/pins/:message-id"), + .WithRoute($"DELETE channels/{channelId}/pins/:message-id"), info, ct ); diff --git a/src/core/DSharpPlus.Internal.Rest/API/EmojiRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/EmojiRestAPI.cs index 4b0280e68b..91939a53d2 100644 --- a/src/core/DSharpPlus.Internal.Rest/API/EmojiRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Rest/API/EmojiRestAPI.cs @@ -11,7 +11,6 @@ using DSharpPlus.Internal.Abstractions.Rest; using DSharpPlus.Internal.Abstractions.Rest.API; using DSharpPlus.Internal.Abstractions.Rest.Payloads; -using DSharpPlus.Internal.Rest.Ratelimiting; using Remora.Results; @@ -22,19 +21,16 @@ namespace DSharpPlus.Internal.Rest.API; // 'other' -> emojis/:guild-id so that their erratic behaviour doesn't mess with the rest of our ratelimits. /// -public sealed class EmojiRestAPI -( - IRestClient restClient -) +public sealed class EmojiRestAPI(IRestClient restClient) : IEmojiRestAPI { /// public async ValueTask> CreateGuildEmojiAsync ( - Snowflake guildId, - ICreateGuildEmojiPayload payload, - string? reason = null, - RequestInfo info = default, + Snowflake guildId, + ICreateGuildEmojiPayload payload, + string? reason = null, + RequestInfo info = default, CancellationToken ct = default ) { @@ -42,16 +38,7 @@ public async ValueTask> CreateGuildEmojiAsync ( HttpMethod.Post, $"guilds/{guildId}/emojis", - b => b.WithSimpleRoute - ( - new SimpleStringRatelimitRoute - { - IsFracturable = true, - Resource = TopLevelResource.Other, - Route = $"emojis/{guildId}" - } - ) - .WithFullRatelimit($"POST guilds/{guildId}/emojis") + b => b.WithRoute($"POST emojis/{guildId}") .WithAuditLogReason(reason), info, ct @@ -61,9 +48,9 @@ public async ValueTask> CreateGuildEmojiAsync /// public async ValueTask DeleteGuildEmojiAsync ( - Snowflake guildId, - Snowflake emojiId, - string? reason = null, + Snowflake guildId, + Snowflake emojiId, + string? reason = null, RequestInfo info = default, CancellationToken ct = default ) @@ -72,16 +59,7 @@ public async ValueTask DeleteGuildEmojiAsync ( HttpMethod.Delete, $"guilds/{guildId}/emojis/{emojiId}", - b => b.WithSimpleRoute - ( - new SimpleStringRatelimitRoute - { - IsFracturable = true, - Resource = TopLevelResource.Other, - Route = $"emojis/{guildId}" - } - ) - .WithFullRatelimit($"DELETE guilds/{guildId}/emojis/:emoji-id") + b => b.WithFullRatelimit($"DELETE emojis/{guildId}") .WithAuditLogReason(reason), info, ct @@ -93,8 +71,8 @@ public async ValueTask DeleteGuildEmojiAsync /// public async ValueTask> GetGuildEmojiAsync ( - Snowflake guildId, - Snowflake emojiId, + Snowflake guildId, + Snowflake emojiId, RequestInfo info = default, CancellationToken ct = default ) @@ -103,16 +81,7 @@ public async ValueTask> GetGuildEmojiAsync ( HttpMethod.Get, $"guilds/{guildId}/emojis/{emojiId}", - b => b.WithSimpleRoute - ( - new SimpleStringRatelimitRoute - { - IsFracturable = true, - Resource = TopLevelResource.Other, - Route = $"emojis/{guildId}" - } - ) - .WithFullRatelimit($"GET guilds/{guildId}/emojis/:emoji-id"), + b => b.WithFullRatelimit($"GET emojis/{guildId}"), info, ct ); @@ -121,8 +90,8 @@ public async ValueTask> GetGuildEmojiAsync /// public async ValueTask>> ListGuildEmojisAsync ( - Snowflake guildId, - RequestInfo info = default, + Snowflake guildId, + RequestInfo info = default, CancellationToken ct = default ) { @@ -130,16 +99,7 @@ public async ValueTask>> ListGuildEmojisAsync ( HttpMethod.Get, $"guilds/{guildId}/emojis", - b => b.WithSimpleRoute - ( - new SimpleStringRatelimitRoute - { - IsFracturable = true, - Resource = TopLevelResource.Other, - Route = $"emojis/{guildId}" - } - ) - .WithFullRatelimit($"GET guilds/{guildId}/emojis"), + b => b.WithFullRatelimit($"GET emojis/{guildId}"), info, ct ); @@ -148,8 +108,8 @@ public async ValueTask>> ListGuildEmojisAsync /// public async ValueTask> ModifyGuildEmojiAsync ( - Snowflake guildId, - Snowflake emojiId, + Snowflake guildId, + Snowflake emojiId, IModifyGuildEmojiPayload payload, string? reason = null, RequestInfo info = default, @@ -160,16 +120,7 @@ public async ValueTask> ModifyGuildEmojiAsync ( HttpMethod.Patch, $"guilds/{guildId}/emojis/{emojiId}", - b => b.WithSimpleRoute - ( - new SimpleStringRatelimitRoute - { - IsFracturable = true, - Resource = TopLevelResource.Other, - Route = $"emojis/{guildId}" - } - ) - .WithFullRatelimit($"GET guilds/{guildId}/emojis/:emoji-id") + b => b.WithFullRatelimit($"GET emojis/{guildId}") .WithPayload(payload) .WithAuditLogReason(reason), info, diff --git a/src/core/DSharpPlus.Internal.Rest/API/EntitlementsRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/EntitlementsRestAPI.cs index e45b4db39b..7c43520229 100644 --- a/src/core/DSharpPlus.Internal.Rest/API/EntitlementsRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Rest/API/EntitlementsRestAPI.cs @@ -14,23 +14,19 @@ using DSharpPlus.Internal.Abstractions.Rest.Errors; using DSharpPlus.Internal.Abstractions.Rest.Payloads; using DSharpPlus.Internal.Abstractions.Rest.Queries; -using DSharpPlus.Internal.Rest.Ratelimiting; using Remora.Results; namespace DSharpPlus.Internal.Rest.API; /// -public sealed class EntitlementsRestAPI -( - IRestClient restClient -) +public sealed class EntitlementsRestAPI(IRestClient restClient) : IEntitlementsRestAPI { /// public async ValueTask> CreateTestEntitlementAsync ( - Snowflake applicationId, + Snowflake applicationId, ICreateTestEntitlementPayload payload, RequestInfo info = default, CancellationToken ct = default @@ -40,17 +36,7 @@ public async ValueTask> CreateTestEntitlementAsync ( HttpMethod.Post, $"applications/{applicationId}/entitlements", - b => b.WithSimpleRoute - ( - new SimpleStringRatelimitRoute - { - IsFracturable = false, - Resource = TopLevelResource.Other, - Route = "applications/:application-id/entitlements" - } - ) - .WithFullRatelimit($"POST applications/:application-id/entitlements") - .WithPayload(payload), + b => b.WithPayload(payload), info, ct ); @@ -59,26 +45,17 @@ public async ValueTask> CreateTestEntitlementAsync /// public async ValueTask DeleteTestEntitlementAsync ( - Snowflake applicationId, - Snowflake entitlementId, - RequestInfo info = default, + Snowflake applicationId, + Snowflake entitlementId, + RequestInfo info = default, CancellationToken ct = default ) { Result response = await restClient.ExecuteRequestAsync ( HttpMethod.Delete, - $"applications/{applicationId}/entitlements", - b => b.WithSimpleRoute - ( - new SimpleStringRatelimitRoute - { - IsFracturable = false, - Resource = TopLevelResource.Other, - Route = "applications/:application-id/entitlements/:entitlement-id" - } - ) - .WithFullRatelimit($"DELETE applications/:application-id/entitlements/:entitlement-id"), + $"applications/{applicationId}/entitlements/{entitlementId}", + b => b.WithRoute($"DELETE applications/:application-id/entitlements/:entitlement-id"), info, ct ); @@ -89,9 +66,9 @@ public async ValueTask DeleteTestEntitlementAsync /// public async ValueTask>> ListEntitlementsAsync ( - Snowflake applicationId, + Snowflake applicationId, ListEntitlementsQuery query = default, - RequestInfo info = default, + RequestInfo info = default, CancellationToken ct = default ) { @@ -142,20 +119,10 @@ public async ValueTask>> ListEntitlementsAsyn return await restClient.ExecuteRequestAsync> ( - HttpMethod.Get, - builder.Build(), - b => b.WithSimpleRoute - ( - new SimpleStringRatelimitRoute - { - IsFracturable = false, - Resource = TopLevelResource.Other, - Route = "applications/:application-id/entitlements" - } - ) - .WithFullRatelimit($"GET applications/:application-id/entitlements"), - info, - ct + method: HttpMethod.Get, + path: builder.Build(), + info: info, + ct: ct ); } } diff --git a/src/core/DSharpPlus.Internal.Rest/API/GuildRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/GuildRestAPI.cs index e3647a3847..6a8afa9ead 100644 --- a/src/core/DSharpPlus.Internal.Rest/API/GuildRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Rest/API/GuildRestAPI.cs @@ -26,10 +26,7 @@ namespace DSharpPlus.Internal.Rest.API; /// -public sealed class GuildRestAPI -( - IRestClient restClient -) +public sealed class GuildRestAPI(IRestClient restClient) : IGuildRestAPI { /// @@ -54,8 +51,7 @@ public async ValueTask> AddGuildMemberAsync Id = guildId } ) - .WithRoute($"guilds/{guildId}/members/:user-id") - .WithFullRatelimit($"PUT guilds/{guildId}/members/:user-id"), + .WithRoute($"PUT guilds/{guildId}/members/:user-id"), info, ct ); @@ -84,8 +80,7 @@ public async ValueTask AddGuildMemberRoleAsync Id = guildId } ) - .WithRoute($"guilds/{guildId}/members/:user-id/roles/:role-id") - .WithFullRatelimit($"PUT guilds/{guildId}/members/:user-id/roles/:role-id") + .WithRoute($"PUT guilds/{guildId}/members/:user-id/roles/:role-id") .WithAuditLogReason(reason), info, ct @@ -127,8 +122,7 @@ public async ValueTask CreateGuildBanAsync Id = guildId } ) - .WithRoute($"guilds/{guildId}/bans/:user-id") - .WithFullRatelimit($"PUT guilds/{guildId}/bans/:user-id") + .WithRoute($"PUT guilds/{guildId}/bans/:user-id") .WithAuditLogReason(reason), info, ct @@ -164,8 +158,6 @@ public async ValueTask> BeginGuildPruneAsync Id = guildId } ) - .WithRoute($"guilds/{guildId}/prune") - .WithFullRatelimit($"PUT guilds/{guildId}/prune") .WithPayload(payload) .WithAuditLogReason(reason), info, @@ -195,17 +187,7 @@ public async ValueTask> CreateGuildAsync ( HttpMethod.Post, $"guilds", - b => b.WithSimpleRoute - ( - new SimpleStringRatelimitRoute - { - IsFracturable = false, - Resource = TopLevelResource.Other, - Route = "guilds" - } - ) - .WithFullRatelimit($"POST guilds") - .WithPayload(payload), + b => b.WithPayload(payload), info, ct ); @@ -261,8 +243,6 @@ public async ValueTask> CreateGuildChannelAsync Id = guildId } ) - .WithRoute($"guilds/{guildId}/channels") - .WithFullRatelimit($"POST guilds/{guildId}/channels") .WithPayload(payload) .WithAuditLogReason(reason), info, @@ -302,8 +282,6 @@ public async ValueTask> CreateGuildRoleAsync Id = guildId } ) - .WithRoute($"guilds/{guildId}/roles") - .WithFullRatelimit($"POST guilds/{guildId}/roles") .WithPayload(payload) .WithAuditLogReason(reason), info, @@ -321,19 +299,10 @@ public async ValueTask DeleteGuildAsync { Result response = await restClient.ExecuteRequestAsync ( - HttpMethod.Delete, - $"guilds/{guildId}", - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Guild, - Id = guildId - } - ) - .WithFullRatelimit($"DELETE guilds/{guildId}"), - info, - ct + method: HttpMethod.Delete, + path: $"guilds/{guildId}", + info: info, + ct: ct ); return (Result)response; @@ -361,8 +330,7 @@ public async ValueTask DeleteGuildIntegrationAsync Id = guildId } ) - .WithRoute($"guilds/{guildId}/integrations/:integration-id") - .WithFullRatelimit($"DELETE guilds/{guildId}/integrations/:integration-id") + .WithRoute($"DELETE guilds/{guildId}/integrations/:integration-id") .WithAuditLogReason(reason), info, ct @@ -393,8 +361,7 @@ public async ValueTask DeleteGuildRoleAsync Id = guildId } ) - .WithRoute($"guilds/{guildId}/roles/:role-id") - .WithFullRatelimit($"DELETE guilds/{guildId}/roles/:role-id") + .WithRoute($"DELETE guilds/{guildId}/roles/:role-id") .WithAuditLogReason(reason), info, ct @@ -424,19 +391,10 @@ public async ValueTask> GetGuildAsync return await restClient.ExecuteRequestAsync ( - HttpMethod.Get, - builder.Build(), - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Guild, - Id = guildId - } - ) - .WithFullRatelimit($"GET guilds/{guildId}"), - info, - ct + method: HttpMethod.Get, + path: builder.Build(), + info: info, + ct: ct ); } @@ -461,8 +419,7 @@ public async ValueTask> GetGuildBanAsync Id = guildId } ) - .WithRoute($"guilds/{guildId}/bans/:user-id") - .WithFullRatelimit($"GET guilds/{guildId}/bans/:user-id"), + .WithRoute($"GET guilds/{guildId}/bans/:user-id"), info, ct ); @@ -513,9 +470,7 @@ public async ValueTask>> GetGuildBansAsync Resource = TopLevelResource.Guild, Id = guildId } - ) - .WithRoute($"guilds/{guildId}/bans") - .WithFullRatelimit($"GET guilds/{guildId}/bans"), + ), info, ct ); @@ -540,9 +495,7 @@ public async ValueTask>> GetGuildChannelsAsync Resource = TopLevelResource.Guild, Id = guildId } - ) - .WithRoute($"guilds/{guildId}/channels") - .WithFullRatelimit($"GET guilds/{guildId}/channels"), + ), info, ct ); @@ -567,9 +520,7 @@ public async ValueTask>> GetGuildIntegrations Resource = TopLevelResource.Guild, Id = guildId } - ) - .WithRoute($"guilds/{guildId}/integrations") - .WithFullRatelimit($"GET guilds/{guildId}/integrations"), + ), info, ct ); @@ -594,9 +545,7 @@ public async ValueTask>> GetGuildInvitesAsync Resource = TopLevelResource.Guild, Id = guildId } - ) - .WithRoute($"guilds/{guildId}/invites") - .WithFullRatelimit($"GET guilds/{guildId}/invites"), + ), info, ct ); @@ -623,8 +572,7 @@ public async ValueTask> GetGuildMemberAsync Id = guildId } ) - .WithRoute($"guilds/{guildId}/members/:user-id") - .WithFullRatelimit($"GET guilds/{guildId}/members/:user-id"), + .WithRoute($"GET guilds/{guildId}/members/:user-id"), info, ct ); @@ -649,9 +597,7 @@ public async ValueTask> GetGuildOnboardingAsync Resource = TopLevelResource.Guild, Id = guildId } - ) - .WithRoute($"guilds/{guildId}/onboarding") - .WithFullRatelimit($"GET guilds/{guildId}/onboarding"), + ), info, ct ); @@ -676,9 +622,7 @@ public async ValueTask> GetGuildPreviewAsync Resource = TopLevelResource.Guild, Id = guildId } - ) - .WithRoute($"guilds/{guildId}/preview") - .WithFullRatelimit($"GET guilds/{guildId}/preview"), + ), info, ct ); @@ -724,9 +668,7 @@ public async ValueTask> GetGuildPruneCountAsy Resource = TopLevelResource.Guild, Id = guildId } - ) - .WithRoute($"guilds/{guildId}/prune") - .WithFullRatelimit($"GET guilds/{guildId}/prune"), + ), info, ct ); @@ -751,9 +693,7 @@ public async ValueTask>> GetGuildRolesAsync Resource = TopLevelResource.Guild, Id = guildId } - ) - .WithRoute($"guilds/{guildId}/roles") - .WithFullRatelimit($"GET guilds/{guildId}/roles"), + ), info, ct ); @@ -778,9 +718,7 @@ public async ValueTask> GetGuildVanityUrlAsync Resource = TopLevelResource.Guild, Id = guildId } - ) - .WithRoute($"guilds/{guildId}/vanity-url") - .WithFullRatelimit($"GET guilds/{guildId}/vanity-url"), + ), info, ct ); @@ -805,9 +743,7 @@ public async ValueTask>> GetGuildVoiceRegions Resource = TopLevelResource.Guild, Id = guildId } - ) - .WithRoute($"guilds/{guildId}/regions") - .WithFullRatelimit($"GET guilds/{guildId}/regions"), + ), info, ct ); @@ -832,9 +768,7 @@ public async ValueTask> GetGuildWelcomeScreenAsync Resource = TopLevelResource.Guild, Id = guildId } - ) - .WithRoute($"guilds/{guildId}/welcome-screen") - .WithFullRatelimit($"GET guilds/{guildId}/welcome-screen"), + ), info, ct ); @@ -859,9 +793,7 @@ public async ValueTask> GetGuildWidgetAsync Resource = TopLevelResource.Guild, Id = guildId } - ) - .WithRoute($"guilds/{guildId}/widget.json") - .WithFullRatelimit($"GET guilds/{guildId}/widget.json"), + ), info, ct ); @@ -879,7 +811,7 @@ public async ValueTask> GetGuildWidgetImageAsync Result response = await restClient.ExecuteRequestAsync ( HttpMethod.Get, - $"guilds/{guildId}/widget.json", + $"guilds/{guildId}/widget.png", b => b.WithSimpleRoute ( new SimpleSnowflakeRatelimitRoute @@ -887,9 +819,7 @@ public async ValueTask> GetGuildWidgetImageAsync Resource = TopLevelResource.Guild, Id = guildId } - ) - .WithRoute($"guilds/{guildId}/widget.json") - .WithFullRatelimit($"GET guilds/{guildId}/widget.json"), + ), info, ct ); @@ -916,9 +846,7 @@ public async ValueTask> GetGuildWidgetSettingsAsync Resource = TopLevelResource.Guild, Id = guildId } - ) - .WithRoute($"guilds/{guildId}/widget") - .WithFullRatelimit($"GET guilds/{guildId}/widget"), + ), info, ct ); @@ -943,9 +871,7 @@ public async ValueTask> ListActiveGuildTh Resource = TopLevelResource.Guild, Id = guildId } - ) - .WithRoute($"guilds/{guildId}/threads/active") - .WithFullRatelimit($"GET guilds/{guildId}/threads/active"), + ), info, ct ); @@ -991,9 +917,7 @@ public async ValueTask>> ListGuildMembersAsyn Resource = TopLevelResource.Guild, Id = guildId } - ) - .WithRoute($"guilds/{guildId}/members") - .WithFullRatelimit($"GET guilds/{guildId}/members"), + ), info, ct ); @@ -1021,8 +945,6 @@ public async ValueTask> ModifyCurrentMemberAsync Id = guildId } ) - .WithRoute($"guilds/{guildId}/members/@me") - .WithFullRatelimit($"PATCH guilds/{guildId}/members/@me") .WithPayload(payload), info, ct @@ -1050,8 +972,6 @@ public async ValueTask ModifyCurrentUserVoiceStateAsync Id = guildId } ) - .WithRoute($"guilds/{guildId}/voice-states/@me") - .WithFullRatelimit($"PATCH guilds/{guildId}/voice-states/@me") .WithPayload(payload), info, ct @@ -1092,7 +1012,6 @@ public async ValueTask> ModifyGuildAsync Id = guildId } ) - .WithFullRatelimit($"POST guilds") .WithPayload(payload) .WithAuditLogReason(reason), info, @@ -1121,8 +1040,6 @@ public async ValueTask ModifyGuildChannelPositionsAsync Id = guildId } ) - .WithRoute($"guilds/{guildId}/channels") - .WithFullRatelimit($"PATCH guilds/{guildId}/channels") .WithPayload(payload), info, ct @@ -1159,8 +1076,7 @@ public async ValueTask> ModifyGuildMemberAsync Id = guildId } ) - .WithRoute($"guilds/{guildId}/members/:user-id") - .WithFullRatelimit($"PATCH guilds/{guildId}/members/:user-id") + .WithRoute($"PATCH guilds/{guildId}/members/:user-id") .WithPayload(payload) .WithAuditLogReason(reason), info, @@ -1190,8 +1106,6 @@ public async ValueTask> ModifyGuildMFALevelAsync Id = guildId } ) - .WithRoute($"guilds/{guildId}/mfa") - .WithFullRatelimit($"PATCH guilds/{guildId}/mfa") .WithPayload(payload) .WithAuditLogReason(reason), info, @@ -1221,8 +1135,6 @@ public async ValueTask> ModifyGuildOnboardingAsync Id = guildId } ) - .WithRoute($"guilds/{guildId}/onboarding") - .WithFullRatelimit($"PATCH guilds/{guildId}/onboarding") .WithPayload(payload) .WithAuditLogReason(reason), info, @@ -1263,8 +1175,7 @@ public async ValueTask> ModifyGuildRoleAsync Id = guildId } ) - .WithRoute($"guilds/{guildId}/roles/:role-id") - .WithFullRatelimit($"PATCH guilds/{guildId}/roles/:role-id") + .WithRoute($"PATCH guilds/{guildId}/roles/:role-id") .WithPayload(payload) .WithAuditLogReason(reason), info, @@ -1294,8 +1205,6 @@ public async ValueTask>> ModifyGuildRolePositionsAsy Id = guildId } ) - .WithRoute($"guilds/{guildId}/roles") - .WithFullRatelimit($"PATCH guilds/{guildId}/roles") .WithPayload(payload) .WithAuditLogReason(reason), info, @@ -1325,8 +1234,6 @@ public async ValueTask> ModifyGuildWelcomeScreenAsync Id = guildId } ) - .WithRoute($"guilds/{guildId}/welcome-screen") - .WithFullRatelimit($"PATCH guilds/{guildId}/welcome-screen") .WithPayload(payload) .WithAuditLogReason(reason), info, @@ -1356,8 +1263,6 @@ public async ValueTask> ModifyGuildWidgetAsync Id = guildId } ) - .WithRoute($"guilds/{guildId}/widget") - .WithFullRatelimit($"PATCH guilds/{guildId}/widget") .WithPayload(settings) .WithAuditLogReason(reason), info, @@ -1387,8 +1292,7 @@ public async ValueTask ModifyUserVoiceStateAsync Id = guildId } ) - .WithRoute($"guilds/{guildId}/voice-states/:user-id") - .WithFullRatelimit($"PATCH guilds/{guildId}/voice-states/:user-id") + .WithRoute($"PATCH guilds/{guildId}/voice-states/:user-id") .WithPayload(payload), info, ct @@ -1419,8 +1323,7 @@ public async ValueTask RemoveGuildBanAsync Id = guildId } ) - .WithRoute($"guilds/{guildId}/bans/:user-id") - .WithFullRatelimit($"DELETE guilds/{guildId}/bans/:user-id") + .WithRoute($"DELETE guilds/{guildId}/bans/:user-id") .WithAuditLogReason(reason), info, ct @@ -1451,8 +1354,7 @@ public async ValueTask RemoveGuildMemberAsync Id = guildId } ) - .WithRoute($"guilds/{guildId}/members/:user-id") - .WithFullRatelimit($"DELETE guilds/{guildId}/members/:user-id") + .WithRoute($"DELETE guilds/{guildId}/members/:user-id") .WithAuditLogReason(reason), info, ct @@ -1484,8 +1386,7 @@ public async ValueTask RemoveGuildMemberRoleAsync Id = guildId } ) - .WithRoute($"guilds/{guildId}/members/:user-id/roles/:role-id") - .WithFullRatelimit($"DELETE guilds/{guildId}/members/:user-id/roles/:role-id") + .WithRoute($"DELETE guilds/{guildId}/members/:user-id/roles/:role-id") .WithAuditLogReason(reason), info, ct @@ -1531,9 +1432,7 @@ public async ValueTask>> SearchGuildMembersAs Resource = TopLevelResource.Guild, Id = guildId } - ) - .WithRoute($"guilds/{guildId}/members/search") - .WithFullRatelimit($"DELETE guilds/{guildId}/members/search"), + ), info, ct ); diff --git a/src/core/DSharpPlus.Internal.Rest/API/GuildScheduledEventRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/GuildScheduledEventRestAPI.cs index 370fbda20b..69137b4805 100644 --- a/src/core/DSharpPlus.Internal.Rest/API/GuildScheduledEventRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Rest/API/GuildScheduledEventRestAPI.cs @@ -21,10 +21,7 @@ namespace DSharpPlus.Internal.Rest.API; /// -public sealed class GuildScheduledEventRestAPI -( - IRestClient restClient -) +public sealed class GuildScheduledEventRestAPI(IRestClient restClient) : IGuildScheduledEventRestAPI { /// @@ -49,8 +46,6 @@ public async ValueTask> CreateGuildScheduledEventAsync Id = guildId } ) - .WithRoute($"guilds/{guildId}/scheduled-events") - .WithFullRatelimit($"POST guilds/{guildId}/scheduled-events") .WithPayload(payload) .WithAuditLogReason(reason), info, @@ -79,8 +74,7 @@ public async ValueTask DeleteScheduledEventAsync Id = guildId } ) - .WithRoute($"guilds/{guildId}/scheduled-events/:event-id") - .WithFullRatelimit($"DELETE guilds/{guildId}/scheduled-events/:event-id"), + .WithRoute($"DELETE guilds/{guildId}/scheduled-events/:event-id"), info, ct ); @@ -120,8 +114,7 @@ public async ValueTask> GetScheduledEventAsync Id = guildId } ) - .WithRoute($"guilds/{guildId}/scheduled-events/:event-id") - .WithFullRatelimit($"GET guilds/{guildId}/scheduled-events/:event-id"), + .WithRoute($"GET guilds/{guildId}/scheduled-events/:event-id"), info, ct ); @@ -179,8 +172,7 @@ public async ValueTask>> GetScheduledE Id = guildId } ) - .WithRoute($"guilds/{guildId}/scheduled-events/:event-id/users") - .WithFullRatelimit($"GET guilds/{guildId}/scheduled-events/:event-id/users"), + .WithRoute($"GET guilds/{guildId}/scheduled-events/:event-id/users"), info, ct ); @@ -216,9 +208,7 @@ public async ValueTask>> ListScheduledEven Resource = TopLevelResource.Guild, Id = guildId } - ) - .WithRoute($"guilds/{guildId}/scheduled-events") - .WithFullRatelimit($"GET guilds/{guildId}/scheduled-events"), + ), info, ct ); @@ -247,8 +237,7 @@ public async ValueTask> ModifyScheduledEventAsync Id = guildId } ) - .WithRoute($"guilds/{guildId}/scheduled-events/:event-id") - .WithFullRatelimit($"POST guilds/{guildId}/scheduled-events/:event-id") + .WithRoute($"POST guilds/{guildId}/scheduled-events/:event-id") .WithPayload(payload) .WithAuditLogReason(reason), info, diff --git a/src/core/DSharpPlus.Internal.Rest/API/GuildTemplateRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/GuildTemplateRestAPI.cs index 3d50bcf802..21c7c262c8 100644 --- a/src/core/DSharpPlus.Internal.Rest/API/GuildTemplateRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Rest/API/GuildTemplateRestAPI.cs @@ -21,10 +21,7 @@ namespace DSharpPlus.Internal.Rest.API; /// -public sealed class GuildTemplateRestAPI -( - IRestClient restClient -) +public sealed class GuildTemplateRestAPI(IRestClient restClient) : IGuildTemplateRestAPI { /// @@ -45,16 +42,7 @@ public async ValueTask> CreateGuildFromGuildTemplateAsync ( HttpMethod.Post, $"guilds/templates/{templateCode}", - b => b.WithSimpleRoute - ( - new SimpleStringRatelimitRoute - { - IsFracturable = true, - Resource = TopLevelResource.Other, - Route = $"guilds/templates/{templateCode}" - } - ) - .WithFullRatelimit($"POST guilds/templates/{templateCode}") + b => b.WithRoute($"POST guilds/templates/:template-code") .WithPayload(payload), info, ct @@ -92,8 +80,6 @@ public async ValueTask> CreateGuildTemplateAsync Id = guildId } ) - .WithRoute($"guilds/{guildId}/templates") - .WithFullRatelimit($"POST guilds/{guildId}/templates") .WithPayload(payload), info, ct @@ -121,8 +107,7 @@ public async ValueTask> DeleteGuildTemplateAsync Id = guildId } ) - .WithRoute($"guilds/{guildId}/templates/:template-code") - .WithFullRatelimit($"DELETE guilds/{guildId}/templates/:template-code"), + .WithRoute($"DELETE guilds/{guildId}/templates/:template-code"), info, ct ); @@ -140,16 +125,7 @@ public async ValueTask> GetGuildTemplateAsync ( HttpMethod.Get, $"guilds/templates/{templateCode}", - b => b.WithSimpleRoute - ( - new SimpleStringRatelimitRoute - { - IsFracturable = true, - Resource = TopLevelResource.Other, - Route = $"guilds/templates/{templateCode}" - } - ) - .WithFullRatelimit($"POST guilds/templates/{templateCode}"), + b => b.WithRoute($"POST guilds/templates/:template-code"), info, ct ); @@ -174,9 +150,7 @@ public async ValueTask>> GetGuildTemplatesAsync Resource = TopLevelResource.Guild, Id = guildId } - ) - .WithRoute($"guilds/{guildId}/templates") - .WithFullRatelimit($"DELETE guilds/{guildId}/templates"), + ), info, ct ); @@ -214,8 +188,7 @@ public async ValueTask> ModifyGuildTemplateAsync Id = guildId } ) - .WithRoute($"guilds/{guildId}/templates/:template-code") - .WithFullRatelimit($"PATCH guilds/{guildId}/templates/:template-code") + .WithRoute($"PATCH guilds/{guildId}/templates/:template-code") .WithPayload(payload), info, ct @@ -243,8 +216,7 @@ public async ValueTask> SyncGuildTemplateAsync Id = guildId } ) - .WithRoute($"guilds/{guildId}/templates/:template-code") - .WithFullRatelimit($"PUT guilds/{guildId}/templates/:template-code"), + .WithRoute($"PUT guilds/{guildId}/templates/:template-code"), info, ct ); diff --git a/src/core/DSharpPlus.Internal.Rest/API/InteractionRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/InteractionRestAPI.cs index 2e100b7d19..e204b15e26 100644 --- a/src/core/DSharpPlus.Internal.Rest/API/InteractionRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Rest/API/InteractionRestAPI.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; using System.Net.Http; +using System.Runtime.CompilerServices; using System.Threading; using System.Threading.Tasks; @@ -57,17 +58,8 @@ public async ValueTask> CreateFollowupMessageAsync ( HttpMethod.Post, $"webhooks/{applicationId}/{interactionToken}", - b => b.WithSimpleRoute - ( - new SimpleStringRatelimitRoute - { - IsFracturable = true, - Resource = TopLevelResource.Webhook, - Route = $"webhooks/{applicationId}/{interactionToken}" - } - ) - .WithRoute($"webhooks/{applicationId}/{interactionToken}") - .WithFullRatelimit($"POST webhooks/{applicationId}/{interactionToken}") + b => b.WithRoute($"POST webhooks/:application-id/{interactionToken}") + .AsInteractionRequest() .WithPayload(payload), info, ct @@ -75,6 +67,7 @@ public async ValueTask> CreateFollowupMessageAsync } /// + [AsyncMethodBuilder(typeof(PoolingAsyncValueTaskMethodBuilder<>))] public async ValueTask CreateInteractionResponseAsync ( Snowflake interactionId, @@ -132,15 +125,14 @@ public async ValueTask CreateInteractionResponseAsync $"interactions/{interactionId}/{interactionToken}/callback", b => b.WithSimpleRoute ( - new SimpleStringRatelimitRoute + new SimpleSnowflakeRatelimitRoute { - IsFracturable = true, Resource = TopLevelResource.Webhook, - Route = $"interactions/{interactionId}/{interactionToken}" + Id = interactionId } ) - .WithRoute($"interactions/{interactionId}/{interactionToken}/callback") - .WithFullRatelimit($"POST interactions/{interactionId}/{interactionToken}/callback") + .WithRoute($"POST interactions/{interactionId}/{interactionToken}/callback") + .AsInteractionRequest() .WithPayload(payload), info, ct @@ -163,17 +155,8 @@ public async ValueTask DeleteFollowupMessageAsync ( HttpMethod.Delete, $"webhooks/{applicationId}/{interactionToken}/messages/{messageId}", - b => b.WithSimpleRoute - ( - new SimpleStringRatelimitRoute - { - IsFracturable = true, - Resource = TopLevelResource.Webhook, - Route = $"webhooks/{applicationId}/{interactionToken}" - } - ) - .WithRoute($"webhooks/{applicationId}/{interactionToken}/messages/:message-id") - .WithFullRatelimit($"DELETE webhooks/{applicationId}/{interactionToken}/messages/:message-id"), + b => b.WithRoute($"DELETE webhooks/:application-id/{interactionToken}/messages/:message-id") + .AsInteractionRequest(), info, ct ); @@ -194,17 +177,8 @@ public async ValueTask DeleteInteractionResponseAsync ( HttpMethod.Delete, $"webhooks/{applicationId}/{interactionToken}/messages/@original", - b => b.WithSimpleRoute - ( - new SimpleStringRatelimitRoute - { - IsFracturable = true, - Resource = TopLevelResource.Webhook, - Route = $"webhooks/{applicationId}/{interactionToken}" - } - ) - .WithRoute($"webhooks/{applicationId}/{interactionToken}/messages/@original") - .WithFullRatelimit($"DELETE webhooks/{applicationId}/{interactionToken}/messages/@original"), + b => b.WithRoute($"webhooks/:application-id/{interactionToken}/messages/@original") + .AsInteractionRequest(), info, ct ); @@ -237,17 +211,8 @@ public async ValueTask> EditFollowupMessageAsync ( HttpMethod.Patch, $"webhooks/{applicationId}/{interactionToken}/messages/{messageId}", - b => b.WithSimpleRoute - ( - new SimpleStringRatelimitRoute - { - IsFracturable = true, - Resource = TopLevelResource.Webhook, - Route = $"webhooks/{applicationId}/{interactionToken}" - } - ) - .WithRoute($"webhooks/{applicationId}/{interactionToken}/messages/:message-id") - .WithFullRatelimit($"PATCH webhooks/{applicationId}/{interactionToken}/messages/:message-id") + b => b.WithRoute($"PATCH webhooks/:application-id/{interactionToken}/messages/:message-id") + .AsInteractionRequest() .WithPayload(payload), info, ct @@ -278,17 +243,8 @@ public async ValueTask> EditInteractionResponseAsync ( HttpMethod.Patch, $"webhooks/{applicationId}/{interactionToken}/messages/@original", - b => b.WithSimpleRoute - ( - new SimpleStringRatelimitRoute - { - IsFracturable = true, - Resource = TopLevelResource.Webhook, - Route = $"webhooks/{applicationId}/{interactionToken}" - } - ) - .WithRoute($"webhooks/{applicationId}/{interactionToken}/messages/@original") - .WithFullRatelimit($"PATCH webhooks/{applicationId}/{interactionToken}/messages/@original") + b => b.WithRoute($"PATCH webhooks/:application-id/{interactionToken}/messages/@original") + .AsInteractionRequest() .WithPayload(payload), info, ct @@ -309,17 +265,8 @@ public async ValueTask> GetFollowupMessageAsync ( HttpMethod.Get, $"webhooks/{applicationId}/{interactionToken}/messages/{messageId}", - b => b.WithSimpleRoute - ( - new SimpleStringRatelimitRoute - { - IsFracturable = true, - Resource = TopLevelResource.Webhook, - Route = $"webhooks/{applicationId}/{interactionToken}" - } - ) - .WithRoute($"webhooks/{applicationId}/{interactionToken}/messages/{messageId}") - .WithFullRatelimit($"GET webhooks/{applicationId}/{interactionToken}/messages/{messageId}"), + b => b.WithRoute($"GET webhooks/:application-id/{interactionToken}/messages/{messageId}") + .AsInteractionRequest(), info, ct ); @@ -338,17 +285,8 @@ public async ValueTask> GetInteractionResponseAsync ( HttpMethod.Get, $"webhooks/{applicationId}/{interactionToken}/messages/@original", - b => b.WithSimpleRoute - ( - new SimpleStringRatelimitRoute - { - IsFracturable = true, - Resource = TopLevelResource.Webhook, - Route = $"webhooks/{applicationId}/{interactionToken}" - } - ) - .WithRoute($"webhooks/{applicationId}/{interactionToken}/messages/@original") - .WithFullRatelimit($"GET webhooks/{applicationId}/{interactionToken}/messages/@original"), + b => b.WithRoute($"GET webhooks/:application-id/{interactionToken}/messages/@original") + .AsInteractionRequest(), info, ct ); diff --git a/src/core/DSharpPlus.Internal.Rest/API/InviteRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/InviteRestAPI.cs index 1acc942f7a..1e6531c38d 100644 --- a/src/core/DSharpPlus.Internal.Rest/API/InviteRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Rest/API/InviteRestAPI.cs @@ -10,7 +10,6 @@ using DSharpPlus.Internal.Abstractions.Rest; using DSharpPlus.Internal.Abstractions.Rest.API; using DSharpPlus.Internal.Abstractions.Rest.Queries; -using DSharpPlus.Internal.Rest.Ratelimiting; using Remora.Results; @@ -33,16 +32,7 @@ public async ValueTask> DeleteInviteAsync ( HttpMethod.Delete, $"invites/{inviteCode}", - b => b.WithSimpleRoute - ( - new SimpleStringRatelimitRoute - { - IsFracturable = false, - Resource = TopLevelResource.Other, - Route = $"invites/:invite-code" - } - ) - .WithFullRatelimit($"DELETE invites/:invite-code") + b => b.WithRoute($"DELETE invites/:invite-code") .WithAuditLogReason(reason), info, ct @@ -82,16 +72,7 @@ public async ValueTask> GetInviteAsync ( HttpMethod.Get, builder.Build(), - b => b.WithSimpleRoute - ( - new SimpleStringRatelimitRoute - { - IsFracturable = false, - Resource = TopLevelResource.Other, - Route = $"invites/:invite-code" - } - ) - .WithFullRatelimit($"GET invites/:invite-code"), + b => b.WithRoute($"GET invites/:invite-code"), info, ct ); diff --git a/src/core/DSharpPlus.Internal.Rest/API/RoleConnectionsRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/RoleConnectionsRestAPI.cs index 9cefd7dd82..fd8c34f569 100644 --- a/src/core/DSharpPlus.Internal.Rest/API/RoleConnectionsRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Rest/API/RoleConnectionsRestAPI.cs @@ -13,7 +13,6 @@ using DSharpPlus.Internal.Abstractions.Rest; using DSharpPlus.Internal.Abstractions.Rest.API; using DSharpPlus.Internal.Abstractions.Rest.Errors; -using DSharpPlus.Internal.Rest.Ratelimiting; using Remora.Results; @@ -35,16 +34,7 @@ public async ValueTask>> GetRoleCo ( HttpMethod.Get, $"applications/{applicationId}/role-connections/metadata", - b => b.WithSimpleRoute - ( - new SimpleStringRatelimitRoute - { - IsFracturable = false, - Resource = TopLevelResource.Other, - Route = "applications/:application-id/role-connections/metadata" - } - ) - .WithFullRatelimit("GET applications/:application-id/role-connections/metadata"), + b => b.WithRoute("GET applications/:application-id/role-connections/metadata"), info, ct ); @@ -68,16 +58,7 @@ public async ValueTask>> UpdateRol ( HttpMethod.Put, $"applications/{applicationId}/role-connections/metadata", - b => b.WithSimpleRoute - ( - new SimpleStringRatelimitRoute - { - IsFracturable = false, - Resource = TopLevelResource.Other, - Route = "applications/:application-id/role-connections/metadata" - } - ) - .WithFullRatelimit("PUT applications/:application-id/role-connections/metadata") + b => b.WithRoute("PUT applications/:application-id/role-connections/metadata") .WithPayload(payload), info, ct diff --git a/src/core/DSharpPlus.Internal.Rest/API/SkusRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/SkusRestAPI.cs index 24d26ebc99..30682f0b2f 100644 --- a/src/core/DSharpPlus.Internal.Rest/API/SkusRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Rest/API/SkusRestAPI.cs @@ -10,7 +10,6 @@ using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Internal.Abstractions.Rest; using DSharpPlus.Internal.Abstractions.Rest.API; -using DSharpPlus.Internal.Rest.Ratelimiting; using Remora.Results; @@ -32,16 +31,7 @@ public async ValueTask>> ListSkusAsync ( HttpMethod.Get, $"applications/{applicationId}/skus", - b => b.WithSimpleRoute - ( - new SimpleStringRatelimitRoute - { - IsFracturable = false, - Resource = TopLevelResource.Other, - Route = "applications/:application-id/skus" - } - ) - .WithFullRatelimit("GET applications/:application-id/skus"), + b => b.WithRoute("GET applications/:application-id/skus"), info, ct ); diff --git a/src/core/DSharpPlus.Internal.Rest/API/StageInstanceRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/StageInstanceRestAPI.cs index e0cad22602..4e50cbce5f 100644 --- a/src/core/DSharpPlus.Internal.Rest/API/StageInstanceRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Rest/API/StageInstanceRestAPI.cs @@ -39,17 +39,7 @@ public async ValueTask> CreateStageInstanceAsync ( HttpMethod.Post, $"stage-instances", - b => b.WithSimpleRoute - ( - new SimpleStringRatelimitRoute - { - IsFracturable = false, - Resource = TopLevelResource.Other, - Route = "stage-instances" - } - ) - .WithFullRatelimit("POST stage-instances") - .WithPayload(payload) + b => b.WithPayload(payload) .WithAuditLogReason(reason), info, ct @@ -77,7 +67,7 @@ public async ValueTask DeleteStageInstanceAsync Id = channelId } ) - .WithFullRatelimit($"DELETE stage-instances/{channelId}") + .WithRoute($"DELETE stage-instances/{channelId}") .WithAuditLogReason(reason), info, ct @@ -106,7 +96,7 @@ public async ValueTask> GetStageInstanceAsync Id = channelId } ) - .WithFullRatelimit($"GET stage-instances/{channelId}"), + .WithRoute($"GET stage-instances/{channelId}"), info, ct ); @@ -139,7 +129,7 @@ public async ValueTask> ModifyStageInstanceAsync Id = channelId } ) - .WithFullRatelimit($"PATCH stage-instances/{channelId}") + .WithRoute($"PATCH stage-instances/{channelId}") .WithPayload(payload) .WithAuditLogReason(reason), info, diff --git a/src/core/DSharpPlus.Internal.Rest/API/StickerRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/StickerRestAPI.cs index e10ee65380..54be5124eb 100644 --- a/src/core/DSharpPlus.Internal.Rest/API/StickerRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Rest/API/StickerRestAPI.cs @@ -62,8 +62,6 @@ public async ValueTask> CreateGuildStickerAsync Id = guildId } ) - .WithRoute($"guilds/{guildId}/stickers") - .WithFullRatelimit($"POST guilds/{guildId}/stickers") .WithPayload(payload) .WithAuditLogReason(reason), info, @@ -93,8 +91,7 @@ public async ValueTask DeleteGuildStickerAsync Id = guildId } ) - .WithRoute($"guilds/{guildId}/stickers/:sticker-id") - .WithFullRatelimit($"DELETE guilds/{guildId}/stickers/:sticker-id") + .WithRoute($"DELETE guilds/{guildId}/stickers/:sticker-id") .WithAuditLogReason(reason), info, ct @@ -124,8 +121,7 @@ public async ValueTask> GetGuildStickerAsync Id = guildId } ) - .WithRoute($"guilds/{guildId}/stickers/:sticker-id") - .WithFullRatelimit($"GET guilds/{guildId}/stickers/:sticker-id"), + .WithRoute($"GET guilds/{guildId}/stickers/:sticker-id"), info, ct ); @@ -143,17 +139,7 @@ public async ValueTask> GetStickerAsync ( HttpMethod.Get, $"stickers/{stickerId}", - b => b.WithSimpleRoute - ( - new SimpleStringRatelimitRoute - { - IsFracturable = false, - Resource = TopLevelResource.Other, - Route = "stickers/:sticker-id" - } - ) - .WithRoute("stickers/:sticker-id") - .WithFullRatelimit("GET stickers/:sticker-id"), + b => b.WithRoute("GET stickers/:sticker-id"), info, ct ); @@ -179,8 +165,7 @@ public async ValueTask>> ListGuildStickersAsync Id = guildId } ) - .WithRoute($"guilds/{guildId}/stickers") - .WithFullRatelimit($"GET guilds/{guildId}/stickers"), + .WithRoute($"GET guilds/{guildId}/stickers"), info, ct ); @@ -197,17 +182,7 @@ public async ValueTask> ListStickerPacksAsync ( HttpMethod.Get, "sticker-packs", - b => b.WithSimpleRoute - ( - new SimpleStringRatelimitRoute - { - IsFracturable = false, - Resource = TopLevelResource.Other, - Route = "sticker-packs" - } - ) - .WithRoute("sticker-packs") - .WithFullRatelimit("GET sticker-packs"), + b => b.WithRoute("GET sticker-packs"), info, ct ); @@ -256,8 +231,7 @@ public async ValueTask> ModifyGuildStickerAsync Id = guildId } ) - .WithRoute($"guilds/{guildId}/stickers/:sticker-id") - .WithFullRatelimit($"PATCH guilds/{guildId}/stickers/:sticker-id") + .WithRoute($"PATCH guilds/{guildId}/stickers/:sticker-id") .WithPayload(payload) .WithAuditLogReason(reason), info, diff --git a/src/core/DSharpPlus.Internal.Rest/API/UserRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/UserRestAPI.cs index 093a40cc80..018593e617 100644 --- a/src/core/DSharpPlus.Internal.Rest/API/UserRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Rest/API/UserRestAPI.cs @@ -38,16 +38,7 @@ public async ValueTask> CreateDmAsync ( HttpMethod.Post, "users/@me/channels", - b => b.WithSimpleRoute - ( - new SimpleStringRatelimitRoute - { - IsFracturable = false, - Resource = TopLevelResource.Other, - Route = "users/@me/channels" - } - ) - .WithFullRatelimit($"POST users/@me/channels") + b => b.WithRoute($"POST users/@me/channels") .WithPayload(payload), info, ct @@ -66,16 +57,7 @@ public async ValueTask> CreateGroupDmAsync ( HttpMethod.Post, "users/@me/channels", - b => b.WithSimpleRoute - ( - new SimpleStringRatelimitRoute - { - IsFracturable = false, - Resource = TopLevelResource.Other, - Route = "users/@me/channels" - } - ) - .WithFullRatelimit($"POST users/@me/channels") + b => b.WithRoute($"POST users/@me/channels") .WithPayload(payload), info, ct @@ -94,16 +76,7 @@ public async ValueTask> GetCurrentUserApplica ( HttpMethod.Get, $"users/@me/applications/{applicationId}/role-connection", - b => b.WithSimpleRoute - ( - new SimpleStringRatelimitRoute - { - IsFracturable = false, - Resource = TopLevelResource.Other, - Route = "users/@me/applications/:application-id/role-connection" - } - ) - .WithFullRatelimit($"GET users/@me/applications/:application-id/role-connection"), + b => b.WithRoute($"GET users/@me/applications/:application-id/role-connection"), info, ct ); @@ -120,16 +93,7 @@ public async ValueTask> GetCurrentUserAsync ( HttpMethod.Get, "users/@me", - b => b.WithSimpleRoute - ( - new SimpleStringRatelimitRoute - { - IsFracturable = false, - Resource = TopLevelResource.Other, - Route = "users/@me" - } - ) - .WithFullRatelimit($"GET users/@me"), + b => b.WithRoute($"GET users/@me"), info, ct ); @@ -146,16 +110,7 @@ public async ValueTask>> GetCurrentUserConnect ( HttpMethod.Get, "users/@me/connections", - b => b.WithSimpleRoute - ( - new SimpleStringRatelimitRoute - { - IsFracturable = false, - Resource = TopLevelResource.Other, - Route = "users/@me/connections" - } - ) - .WithFullRatelimit("GET users/@me/connections"), + b => b.WithRoute("GET users/@me/connections"), info, ct ); @@ -175,14 +130,13 @@ public async ValueTask> GetCurrentUserGuildMemberAsync $"users/@me/guilds/{guildId}/member", b => b.WithSimpleRoute ( - new SimpleStringRatelimitRoute + new SimpleSnowflakeRatelimitRoute { - IsFracturable = false, Resource = TopLevelResource.Guild, - Route = $"users/@me/guilds/{guildId}/member" + Id = guildId } ) - .WithFullRatelimit($"GET users/@me/guilds/{guildId}/member"), + .WithRoute($"GET users/@me/guilds/{guildId}/member"), info, ct ); @@ -230,16 +184,7 @@ public async ValueTask>> GetCurrentUserGuild ( HttpMethod.Get, builder.Build(), - b => b.WithSimpleRoute - ( - new SimpleStringRatelimitRoute - { - IsFracturable = false, - Resource = TopLevelResource.Other, - Route = "users/@me/guilds" - } - ) - .WithFullRatelimit("GET users/@me/guilds"), + b => b.WithRoute("GET users/@me/guilds"), info, ct ); @@ -257,16 +202,7 @@ public async ValueTask> GetUserAsync ( HttpMethod.Get, $"users/{userId}", - b => b.WithSimpleRoute - ( - new SimpleStringRatelimitRoute - { - IsFracturable = false, - Resource = TopLevelResource.Other, - Route = "users/:user-id" - } - ) - .WithFullRatelimit("GET users/:user-id"), + b => b.WithRoute("GET users/:user-id"), info, ct ); @@ -286,14 +222,13 @@ public async ValueTask LeaveGuildAsync $"users/@me/guilds/{guildId}", b => b.WithSimpleRoute ( - new SimpleStringRatelimitRoute + new SimpleSnowflakeRatelimitRoute { - IsFracturable = false, Resource = TopLevelResource.Guild, - Route = $"users/@me/guilds/{guildId}" + Id = guildId } ) - .WithFullRatelimit($"DELETE users/@me/guilds/{guildId}"), + .WithRoute($"DELETE users/@me/guilds/{guildId}"), info, ct ); @@ -313,16 +248,7 @@ public async ValueTask> ModifyCurrentUserAsync ( HttpMethod.Patch, "users/@me", - b => b.WithSimpleRoute - ( - new SimpleStringRatelimitRoute - { - IsFracturable = false, - Resource = TopLevelResource.Other, - Route = "users/@me" - } - ) - .WithFullRatelimit("PATCH users/@me") + b => b.WithRoute("PATCH users/@me") .WithPayload(payload), info, ct @@ -352,16 +278,7 @@ public async ValueTask> UpdateCurrentUserAppl ( HttpMethod.Put, $"users/@me/applications/{applicationId}/role-connection", - b => b.WithSimpleRoute - ( - new SimpleStringRatelimitRoute - { - IsFracturable = false, - Resource = TopLevelResource.Other, - Route = "users/@me/applications/:application-id/role-connection" - } - ) - .WithFullRatelimit("PUT users/@me/applications/:application-id/role-connection") + b => b.WithRoute("PUT users/@me/applications/:application-id/role-connection") .WithPayload(payload), info, ct diff --git a/src/core/DSharpPlus.Internal.Rest/API/VoiceRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/VoiceRestAPI.cs index 4c2ebd8fd2..ea66310623 100644 --- a/src/core/DSharpPlus.Internal.Rest/API/VoiceRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Rest/API/VoiceRestAPI.cs @@ -10,7 +10,6 @@ using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Internal.Abstractions.Rest; using DSharpPlus.Internal.Abstractions.Rest.API; -using DSharpPlus.Internal.Rest.Ratelimiting; using Remora.Results; @@ -31,16 +30,7 @@ public async ValueTask>> ListVoiceRegionsAsyn ( HttpMethod.Get, $"voice/regions", - b => b.WithSimpleRoute - ( - new SimpleStringRatelimitRoute - { - IsFracturable = false, - Resource = TopLevelResource.Other, - Route = "voice/regions" - } - ) - .WithFullRatelimit("GET voice/regions"), + b => b.WithRoute("GET voice/regions"), info, ct ); diff --git a/src/core/DSharpPlus.Internal.Rest/API/WebhookRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/WebhookRestAPI.cs index b974a51ba3..24606def4a 100644 --- a/src/core/DSharpPlus.Internal.Rest/API/WebhookRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Rest/API/WebhookRestAPI.cs @@ -62,7 +62,6 @@ public async ValueTask> CreateWebhookAsync Id = channelId } ) - .WithFullRatelimit($"POST channels/{channelId}/webhooks") .WithAuditLogReason(reason), info, ct @@ -90,7 +89,6 @@ public async ValueTask DeleteWebhookAsync Id = webhookId } ) - .WithFullRatelimit($"DELETE webhooks/{webhookId}") .WithAuditLogReason(reason), info, ct @@ -132,7 +130,7 @@ public async ValueTask DeleteWebhookMessageAsync Id = webhookId } ) - .WithFullRatelimit($"DELETE webhooks/{webhookId}/:webhook-token/messages/:message-id") + .WithRoute($"DELETE webhooks/{webhookId}/:webhook-token/messages/:message-id") .AsWebhookRequest(), info, ct @@ -163,7 +161,7 @@ public async ValueTask DeleteWebhookWithTokenAsync Id = webhookId } ) - .WithFullRatelimit($"DELETE webhooks/{webhookId}/:webhook-token") + .WithRoute($"DELETE webhooks/{webhookId}/:webhook-token") .WithAuditLogReason(reason) .AsWebhookRequest(), info, @@ -222,7 +220,7 @@ public async ValueTask> EditWebhookMessageAsync Id = webhookId } ) - .WithFullRatelimit($"PATCH webhooks/{webhookId}/:webhook-token/messages/:message-id") + .WithRoute($"PATCH webhooks/{webhookId}/:webhook-token/messages/:message-id") .WithPayload(payload) .AsWebhookRequest(), info, @@ -286,7 +284,7 @@ public async ValueTask> ExecuteWebhookAsync Id = webhookId } ) - .WithFullRatelimit($"PATCH webhooks/{webhookId}/:webhook-token/messages/:message-id") + .WithRoute($"PATCH webhooks/{webhookId}/:webhook-token/messages/:message-id") .WithPayload(payload) .AsWebhookRequest(), info, @@ -308,7 +306,7 @@ public async ValueTask> ExecuteWebhookAsync Id = webhookId } ) - .WithFullRatelimit($"PATCH webhooks/{webhookId}/:webhook-token/messages/:message-id") + .WithRoute($"PATCH webhooks/{webhookId}/:webhook-token/messages/:message-id") .WithPayload(payload) .AsWebhookRequest(), info, @@ -338,8 +336,7 @@ public async ValueTask>> GetChannelWebhooksAsync Resource = TopLevelResource.Channel, Id = channelId } - ) - .WithFullRatelimit($"GET channels/{channelId}/webhooks"), + ), info, ct ); @@ -364,8 +361,7 @@ public async ValueTask>> GetGuildWebhooksAsync Resource = TopLevelResource.Guild, Id = guildId } - ) - .WithFullRatelimit($"GET guilds/{guildId}/webhooks"), + ), info, ct ); @@ -390,8 +386,7 @@ public async ValueTask> GetWebhookAsync Resource = TopLevelResource.Webhook, Id = webhookId } - ) - .WithFullRatelimit($"GET webhooks/{webhookId}"), + ), info, ct ); @@ -430,7 +425,7 @@ public async ValueTask> GetWebhookMessageAsync Id = webhookId } ) - .WithFullRatelimit($"PATCH webhooks/{webhookId}/:webhook-token/messages/:message-id"), + .WithRoute($"PATCH webhooks/{webhookId}/:webhook-token/messages/:message-id"), info, ct ); @@ -457,7 +452,6 @@ public async ValueTask> GetWebhookWithTokenAsync Id = webhookId } ) - .WithFullRatelimit($"GET webhooks/{webhookId}/:webhook-token") .AsWebhookRequest(), info, ct @@ -503,7 +497,6 @@ public async ValueTask> ModifyWebhookAsync Id = webhookId } ) - .WithFullRatelimit($"PATCH webhooks/{webhookId}") .WithAuditLogReason(reason), info, ct @@ -550,7 +543,6 @@ public async ValueTask> ModifyWebhookWithTokenAsync Id = webhookId } ) - .WithFullRatelimit($"PATCH webhooks/{webhookId}/:webhook-token") .WithAuditLogReason(reason) .AsWebhookRequest(), info, diff --git a/src/core/DSharpPlus.Internal.Rest/Ratelimiting/ISimpleRatelimitRoute.cs b/src/core/DSharpPlus.Internal.Rest/Ratelimiting/ISimpleRatelimitRoute.cs deleted file mode 100644 index 1ff6d9a756..0000000000 --- a/src/core/DSharpPlus.Internal.Rest/Ratelimiting/ISimpleRatelimitRoute.cs +++ /dev/null @@ -1,13 +0,0 @@ -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -namespace DSharpPlus.Internal.Rest.Ratelimiting; - -/// -/// Represents a common base for simple ratelimits. -/// -internal interface ISimpleRatelimitRoute -{ - public TopLevelResource Resource { get; } -} diff --git a/src/core/DSharpPlus.Internal.Rest/Ratelimiting/SimpleSnowflakeRatelimitRoute.cs b/src/core/DSharpPlus.Internal.Rest/Ratelimiting/SimpleSnowflakeRatelimitRoute.cs index 1698d05ec0..b67c4a9606 100644 --- a/src/core/DSharpPlus.Internal.Rest/Ratelimiting/SimpleSnowflakeRatelimitRoute.cs +++ b/src/core/DSharpPlus.Internal.Rest/Ratelimiting/SimpleSnowflakeRatelimitRoute.cs @@ -7,7 +7,7 @@ namespace DSharpPlus.Internal.Rest.Ratelimiting; /// /// Specifies a route likely defined by its resource and a snowflake. /// -internal readonly record struct SimpleSnowflakeRatelimitRoute : ISimpleRatelimitRoute +internal readonly record struct SimpleSnowflakeRatelimitRoute { public required TopLevelResource Resource { get; init; } diff --git a/src/core/DSharpPlus.Internal.Rest/Ratelimiting/SimpleStringRatelimitRoute.cs b/src/core/DSharpPlus.Internal.Rest/Ratelimiting/SimpleStringRatelimitRoute.cs deleted file mode 100644 index 28e86e9f1e..0000000000 --- a/src/core/DSharpPlus.Internal.Rest/Ratelimiting/SimpleStringRatelimitRoute.cs +++ /dev/null @@ -1,21 +0,0 @@ -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -namespace DSharpPlus.Internal.Rest.Ratelimiting; - -/// -/// Specifies a route likely defined by its resource and a string. -/// -internal readonly record struct SimpleStringRatelimitRoute : ISimpleRatelimitRoute -{ - public required TopLevelResource Resource { get; init; } - - /// - /// Specifies whether this route can fracture. This is the case for all routes with more than one method - /// pointing to the otherwise same route, and for all routes that use any ID as a top-level parameter. - /// - public required bool IsFracturable { get; init; } - - public required string Route { get; init; } -} diff --git a/src/core/DSharpPlus.Internal.Rest/RequestBuilderExtensions.cs b/src/core/DSharpPlus.Internal.Rest/RequestBuilderExtensions.cs index ed62f59e89..07b00cfd34 100644 --- a/src/core/DSharpPlus.Internal.Rest/RequestBuilderExtensions.cs +++ b/src/core/DSharpPlus.Internal.Rest/RequestBuilderExtensions.cs @@ -9,7 +9,7 @@ namespace DSharpPlus.Internal.Rest; internal static class RequestBuilderExtensions { - public static RequestBuilder WithSimpleRoute(this RequestBuilder request, ISimpleRatelimitRoute route) + public static RequestBuilder WithSimpleRoute(this RequestBuilder request, SimpleSnowflakeRatelimitRoute route) { request.AddToContext("simple-route", route); return request; From 5a4676a03acb943f517a548c6b7d88dc60c6a64e Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Fri, 19 Jan 2024 17:39:42 +0100 Subject: [PATCH 277/323] we can also stop explicitly initializing simple routes --- .../API/AuditLogsRestAPI.cs | 9 +- .../API/AutoModerationRestAPI.cs | 45 +-- .../API/ChannelRestAPI.cs | 369 ++--------------- .../API/GuildRestAPI.cs | 378 ++---------------- .../API/GuildScheduledEventRestAPI.cs | 54 +-- .../API/GuildTemplateRestAPI.cs | 45 +-- .../API/InteractionRestAPI.cs | 9 +- .../API/StageInstanceRestAPI.cs | 27 +- .../API/StickerRestAPI.cs | 45 +-- .../API/UserRestAPI.cs | 18 +- .../API/WebhookRestAPI.cs | 126 +----- .../RequestBuilderExtensions.cs | 13 +- 12 files changed, 136 insertions(+), 1002 deletions(-) diff --git a/src/core/DSharpPlus.Internal.Rest/API/AuditLogsRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/AuditLogsRestAPI.cs index e516b91b2b..849fcd69db 100644 --- a/src/core/DSharpPlus.Internal.Rest/API/AuditLogsRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Rest/API/AuditLogsRestAPI.cs @@ -74,14 +74,7 @@ public async ValueTask> ListGuildAuditLogEntriesAsync ( HttpMethod.Get, builder.Build(), - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Guild, - Id = guildId - } - ) + b => b.WithSimpleRoute(TopLevelResource.Guild, guildId) .WithRoute($"GET guilds/{guildId}/audit-logs"), info, ct diff --git a/src/core/DSharpPlus.Internal.Rest/API/AutoModerationRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/AutoModerationRestAPI.cs index 5f367d265f..4a30596b3f 100644 --- a/src/core/DSharpPlus.Internal.Rest/API/AutoModerationRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Rest/API/AutoModerationRestAPI.cs @@ -48,14 +48,7 @@ public async ValueTask> CreateAutoModerationRuleAsyn ( HttpMethod.Post, $"guilds/{guildId}/auto-moderation/rules", - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Guild, - Id = guildId - } - ) + b => b.WithSimpleRoute(TopLevelResource.Guild, guildId) .WithAuditLogReason(reason), info, ct @@ -76,14 +69,7 @@ public async ValueTask DeleteAutoModerationRuleAsync ( HttpMethod.Delete, $"guilds/{guildId}/auto-moderation/rules/{ruleId}", - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Guild, - Id = guildId - } - ) + b => b.WithSimpleRoute(TopLevelResource.Guild, guildId) .WithRoute($"DELETE guilds/{guildId}/auto-moderation/rules/:rule-id") .WithAuditLogReason(reason), info, @@ -106,14 +92,7 @@ public async ValueTask> GetAutoModerationRuleAsync ( HttpMethod.Get, $"guilds/{guildId}/auto-moderation/rules/{ruleId}", - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Guild, - Id = guildId - } - ) + b => b.WithSimpleRoute(TopLevelResource.Guild, guildId) .WithRoute($"GET guilds/{guildId}/auto-moderation/rules/:rule-id"), info, ct @@ -132,14 +111,7 @@ public async ValueTask>> ListAutoModer ( HttpMethod.Get, $"guilds/{guildId}/auto-moderation/rules", - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Guild, - Id = guildId - } - ), + b => b.WithSimpleRoute(TopLevelResource.Guild, guildId), info, ct ); @@ -170,14 +142,7 @@ public async ValueTask> ModifyAutoModerationRuleAsyn ( HttpMethod.Patch, $"guilds/{guildId}/auto-moderation/rules/{ruleId}", - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Guild, - Id = guildId - } - ) + b => b.WithSimpleRoute(TopLevelResource.Guild, guildId) .WithRoute($"PATCH guilds/{guildId}/auto-moderation/rules/:rule-id") .WithAuditLogReason(reason), info, diff --git a/src/core/DSharpPlus.Internal.Rest/API/ChannelRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/ChannelRestAPI.cs index 1bcaea7865..ebea091cc6 100644 --- a/src/core/DSharpPlus.Internal.Rest/API/ChannelRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Rest/API/ChannelRestAPI.cs @@ -41,14 +41,7 @@ public async ValueTask AddThreadMemberAsync ( HttpMethod.Put, $"channels/{threadId}/thread-members/{userId}", - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Channel, - Id = threadId - } - ) + b => b.WithSimpleRoute(TopLevelResource.Channel, threadId) .WithRoute($"PUT channels/{threadId}/thread-members/:user-id"), info, ct @@ -71,14 +64,7 @@ public async ValueTask BulkDeleteMessagesAsync ( HttpMethod.Post, $"channels/{channelId}/messages/bulk-delete", - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Channel, - Id = channelId - } - ) + b => b.WithSimpleRoute(TopLevelResource.Channel, channelId) .WithPayload(payload) .WithAuditLogReason(reason), info, @@ -131,14 +117,7 @@ public async ValueTask> CreateChannelInviteAsync ( HttpMethod.Post, $"channels/{channelId}/invites", - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Channel, - Id = channelId - } - ) + b => b.WithSimpleRoute(TopLevelResource.Channel, channelId) .WithPayload(payload) .WithAuditLogReason(reason), info, @@ -191,14 +170,7 @@ public async ValueTask> CreateMessageAsync ( HttpMethod.Post, $"channels/{channelId}/messages", - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Channel, - Id = channelId - } - ) + b => b.WithSimpleRoute(TopLevelResource.Channel, channelId) .WithPayload(payload), info, ct @@ -219,14 +191,7 @@ public async ValueTask CreateReactionAsync ( HttpMethod.Put, $"channels/{channelId}/messages/{messageId}/reactions/{emoji}/@me", - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Channel, - Id = channelId - } - ) + b => b.WithSimpleRoute(TopLevelResource.Channel, channelId) .WithRoute($"PUT channels/{channelId}/messages/:message-id/reactions/:emoji/@me"), info, ct @@ -248,14 +213,7 @@ public async ValueTask> CrosspostMessageAsync ( HttpMethod.Post, $"channels/{channelId}/messages/{messageId}/crosspost", - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Channel, - Id = channelId - } - ) + b => b.WithSimpleRoute(TopLevelResource.Channel, channelId) .WithRoute($"POST channels/{channelId}/messages/:message-id/crosspost"), info, ct @@ -275,14 +233,7 @@ public async ValueTask DeleteAllReactionsAsync ( HttpMethod.Delete, $"channels/{channelId}/messages/{messageId}/reactions", - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Channel, - Id = channelId - } - ) + b => b.WithSimpleRoute(TopLevelResource.Channel, channelId) .WithRoute($"DELETE channels/{channelId}/messages/:message-id/reactions"), info, ct @@ -305,14 +256,7 @@ public async ValueTask DeleteAllReactionsForEmojiAsync ( HttpMethod.Delete, $"channels/{channelId}/messages/{messageId}/reactions/{emoji}", - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Channel, - Id = channelId - } - ) + b => b.WithSimpleRoute(TopLevelResource.Channel, channelId) .WithRoute($"DELETE channels/{channelId}/messages/:message-id/reactions/:emoji"), info, ct @@ -334,14 +278,7 @@ public async ValueTask> DeleteChannelAsync ( HttpMethod.Delete, $"channels/{channelId}", - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Channel, - Id = channelId - } - ) + b => b.WithSimpleRoute(TopLevelResource.Channel, channelId) .WithAuditLogReason(reason), info, ct @@ -362,14 +299,7 @@ public async ValueTask DeleteChannelPermissionAsync ( HttpMethod.Delete, $"channels/{channelId}/permissions/{overwriteId}", - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Channel, - Id = channelId - } - ) + b => b.WithSimpleRoute(TopLevelResource.Channel, channelId) .WithAuditLogReason(reason), info, ct @@ -392,14 +322,7 @@ public async ValueTask DeleteMessageAsync ( HttpMethod.Delete, $"channels/{channelId}/messages/{messageId}", - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Channel, - Id = channelId - } - ) + b => b.WithSimpleRoute(TopLevelResource.Channel, channelId) .WithRoute($"DELETE channels/{channelId}/messages/:message-id") .WithAuditLogReason(reason), info, @@ -423,14 +346,7 @@ public async ValueTask DeleteOwnReactionAsync ( HttpMethod.Delete, $"channels/{channelId}/messages/{messageId}/reactions/{emoji}/@me", - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Channel, - Id = channelId - } - ) + b => b.WithSimpleRoute(TopLevelResource.Channel, channelId) .WithRoute($"DELETE channels/{channelId}/messages/:message-id/reactions/:emoji/@me"), info, ct @@ -454,14 +370,7 @@ public async ValueTask DeleteUserReactionAsync ( HttpMethod.Delete, $"channels/{channelId}/messages/{messageId}/reactions/{emoji}/{userId}", - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Channel, - Id = channelId - } - ) + b => b.WithSimpleRoute(TopLevelResource.Channel, channelId) .WithRoute($"DELETE channels/{channelId}/messages/:message-id/reactions/:emoji/:user-id"), info, ct @@ -485,14 +394,7 @@ public async ValueTask EditChannelPermissionsAsync ( HttpMethod.Put, $"channels/{channelId}/permissions/{overwriteId}", - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Channel, - Id = channelId - } - ) + b => b.WithSimpleRoute(TopLevelResource.Channel, channelId) .WithRoute($"PUT channels/{channelId}/permissions/:overwrite-id") .WithPayload(payload) .WithAuditLogReason(reason), @@ -527,14 +429,7 @@ public async ValueTask> EditMessageAsync ( HttpMethod.Patch, $"channels/{channelId}/messages/{messageId}", - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Channel, - Id = channelId - } - ) + b => b.WithSimpleRoute(TopLevelResource.Channel, channelId) .WithRoute($"PATCH channels/{channelId}/messages/:message-id") .WithPayload(payload), info, @@ -555,14 +450,7 @@ public async ValueTask> FollowAnnouncementChannelAsync ( HttpMethod.Post, $"channels/{channelId}/followers", - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Channel, - Id = channelId - } - ) + b => b.WithSimpleRoute(TopLevelResource.Channel, channelId) .WithPayload(payload), info, ct @@ -581,14 +469,7 @@ public async ValueTask> GetChannelAsync ( HttpMethod.Get, $"channels/{channelId}", - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Channel, - Id = channelId - } - ), + b => b.WithSimpleRoute(TopLevelResource.Channel, channelId), info, ct ); @@ -606,14 +487,7 @@ public async ValueTask>> GetChannelInvitesAsync ( HttpMethod.Get, $"channels/{channelId}/invites", - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Channel, - Id = channelId - } - ), + b => b.WithSimpleRoute(TopLevelResource.Channel, channelId), info, ct ); @@ -632,14 +506,7 @@ public async ValueTask> GetChannelMessageAsync ( HttpMethod.Get, $"channels/{channelId}/messages/{messageId}", - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Channel, - Id = channelId - } - ) + b => b.WithSimpleRoute(TopLevelResource.Channel, channelId) .WithRoute($"GET channels/{channelId}/messages/:message-id"), info, ct @@ -687,14 +554,7 @@ public async ValueTask>> GetChannelMessagesAsync ( HttpMethod.Get, builder.Build(), - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Channel, - Id = channelId - } - ), + b => b.WithSimpleRoute(TopLevelResource.Channel, channelId), info, ct ); @@ -712,14 +572,7 @@ public async ValueTask>> GetPinnedMessagesAsync ( HttpMethod.Get, $"channels/{channelId}/pins", - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Channel, - Id = channelId - } - ), + b => b.WithSimpleRoute(TopLevelResource.Channel, channelId), info, ct ); @@ -755,14 +608,7 @@ public async ValueTask>> GetReactionsAsync ( HttpMethod.Get, builder.Build(), - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Channel, - Id = channelId - } - ) + b => b.WithSimpleRoute(TopLevelResource.Channel, channelId) .WithRoute($"GET channels/{channelId}/messages/:message-id/reactions/:emoji"), info, ct @@ -793,14 +639,7 @@ public async ValueTask> GetThreadMemberAsync ( HttpMethod.Get, builder.Build(), - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Channel, - Id = threadId - } - ) + b => b.WithSimpleRoute(TopLevelResource.Channel, threadId) .WithRoute($"GET channels/{threadId}/thread-members/:user-id"), info, ct @@ -821,14 +660,7 @@ public async ValueTask GroupDMAddRecipientAsync ( HttpMethod.Put, $"channels/{channelId}/recipients/{userId}", - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Channel, - Id = channelId - } - ) + b => b.WithSimpleRoute(TopLevelResource.Channel, channelId) .WithRoute($"PUT channels/{channelId}/recipients/:user-id") .WithPayload(payload), info, @@ -851,14 +683,7 @@ public async ValueTask GroupDMRemoveRecipientAsync ( HttpMethod.Delete, $"channels/{channelId}/recipients/{userId}", - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Channel, - Id = channelId - } - ) + b => b.WithSimpleRoute(TopLevelResource.Channel, channelId) .WithRoute($"DELETE channels/{channelId}/recipients/:user-id"), info, ct @@ -879,14 +704,7 @@ public async ValueTask JoinThreadAsync ( HttpMethod.Put, $"channels/{threadId}/recipients/@me", - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Channel, - Id = threadId - } - ), + b => b.WithSimpleRoute(TopLevelResource.Channel, threadId), info, ct ); @@ -906,14 +724,7 @@ public async ValueTask LeaveThreadAsync ( HttpMethod.Delete, $"channels/{threadId}/recipients/@me", - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Channel, - Id = threadId - } - ), + b => b.WithSimpleRoute(TopLevelResource.Channel, threadId), info, ct ); @@ -954,14 +765,7 @@ public async ValueTask> ListJoinedPrivateArc ( HttpMethod.Get, builder.Build(), - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Channel, - Id = channelId - } - ), + b => b.WithSimpleRoute(TopLevelResource.Channel, channelId), info, ct ); @@ -1000,14 +804,7 @@ public async ValueTask> ListPrivateArchivedT ( HttpMethod.Get, builder.Build(), - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Channel, - Id = channelId - } - ), + b => b.WithSimpleRoute(TopLevelResource.Channel, channelId), info, ct ); @@ -1046,14 +843,7 @@ public async ValueTask> ListPublicArchivedTh ( HttpMethod.Get, builder.Build(), - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Channel, - Id = channelId - } - ), + b => b.WithSimpleRoute(TopLevelResource.Channel, channelId), info, ct ); @@ -1097,14 +887,7 @@ public async ValueTask>> ListThreadMembersAs ( HttpMethod.Get, builder.Build(), - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Channel, - Id = threadId - } - ), + b => b.WithSimpleRoute(TopLevelResource.Channel, threadId), info, ct ); @@ -1128,14 +911,7 @@ public async ValueTask> ModifyChannelAsync ( HttpMethod.Patch, $"channels/{channelId}", - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Channel, - Id = channelId - } - ), + b => b.WithSimpleRoute(TopLevelResource.Channel, channelId), info, ct ); @@ -1194,14 +970,7 @@ public async ValueTask> ModifyChannelAsync ( HttpMethod.Patch, $"channels/{channelId}", - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Channel, - Id = channelId - } - ) + b => b.WithSimpleRoute(TopLevelResource.Channel, channelId) .WithAuditLogReason(reason), info, ct @@ -1248,14 +1017,7 @@ public async ValueTask> ModifyChannelAsync ( HttpMethod.Patch, $"channels/{channelId}", - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Channel, - Id = channelId - } - ) + b => b.WithSimpleRoute(TopLevelResource.Channel, channelId) .WithAuditLogReason(reason), info, ct @@ -1276,14 +1038,7 @@ public async ValueTask PinMessageAsync ( HttpMethod.Put, $"channels/{channelId}/pins/{messageId}", - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Channel, - Id = channelId - } - ) + b => b.WithSimpleRoute(TopLevelResource.Channel, channelId) .WithAuditLogReason(reason) .WithRoute($"PUT channels/{channelId}/pins/:message-id"), info, @@ -1306,14 +1061,7 @@ public async ValueTask RemoveThreadMemberAsync ( HttpMethod.Delete, $"channels/{threadId}/thread-members/{userId}", - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Channel, - Id = threadId - } - ) + b => b.WithSimpleRoute(TopLevelResource.Channel, threadId) .WithRoute($"DELETE channels/{threadId}/thread-members/:user-id"), info, ct @@ -1358,14 +1106,7 @@ public async ValueTask> StartThreadFromMessageAsync ( HttpMethod.Post, $"channels/{channelId}/messages/{messageId}/threads", - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Channel, - Id = channelId - } - ) + b => b.WithSimpleRoute(TopLevelResource.Channel, channelId) .WithRoute($"POST channels/{channelId}/messages/:message-id/threads") .WithPayload(payload) .WithAuditLogReason(reason), @@ -1444,14 +1185,7 @@ public async ValueTask> StartThreadInForumOrMediaChannelAsync ( HttpMethod.Post, $"channels/{channelId}/threads", - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Channel, - Id = channelId - } - ) + b => b.WithSimpleRoute(TopLevelResource.Channel, channelId) .WithPayload(payload) .WithAuditLogReason(reason), info, @@ -1494,14 +1228,7 @@ public async ValueTask> StartThreadWithoutMessageAsync ( HttpMethod.Post, $"channels/{channelId}/threads", - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Channel, - Id = channelId - } - ) + b => b.WithSimpleRoute(TopLevelResource.Channel, channelId) .WithPayload(payload) .WithAuditLogReason(reason), info, @@ -1521,14 +1248,7 @@ public async ValueTask TriggerTypingIndicatorAsync ( HttpMethod.Post, $"channels/{channelId}/typing", - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Channel, - Id = channelId - } - ), + b => b.WithSimpleRoute(TopLevelResource.Channel, channelId), info, ct ); @@ -1550,14 +1270,7 @@ public async ValueTask UnpinMessageAsync ( HttpMethod.Delete, $"channels/{channelId}/pins/{messageId}", - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Channel, - Id = channelId - } - ) + b => b.WithSimpleRoute(TopLevelResource.Channel, channelId) .WithRoute($"DELETE channels/{channelId}/pins/:message-id"), info, ct diff --git a/src/core/DSharpPlus.Internal.Rest/API/GuildRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/GuildRestAPI.cs index 6a8afa9ead..49e250dbdb 100644 --- a/src/core/DSharpPlus.Internal.Rest/API/GuildRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Rest/API/GuildRestAPI.cs @@ -43,14 +43,7 @@ public async ValueTask> AddGuildMemberAsync ( HttpMethod.Put, $"guilds/{guildId}/members/{userId}", - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Guild, - Id = guildId - } - ) + b => b.WithSimpleRoute(TopLevelResource.Guild, guildId) .WithRoute($"PUT guilds/{guildId}/members/:user-id"), info, ct @@ -72,14 +65,7 @@ public async ValueTask AddGuildMemberRoleAsync ( HttpMethod.Put, $"guilds/{guildId}/members/{userId}/roles/{roleId}", - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Guild, - Id = guildId - } - ) + b => b.WithSimpleRoute(TopLevelResource.Guild, guildId) .WithRoute($"PUT guilds/{guildId}/members/:user-id/roles/:role-id") .WithAuditLogReason(reason), info, @@ -114,14 +100,7 @@ public async ValueTask CreateGuildBanAsync ( HttpMethod.Put, builder.Build(), - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Guild, - Id = guildId - } - ) + b => b.WithSimpleRoute(TopLevelResource.Guild, guildId) .WithRoute($"PUT guilds/{guildId}/bans/:user-id") .WithAuditLogReason(reason), info, @@ -150,14 +129,7 @@ public async ValueTask> BeginGuildPruneAsync ( HttpMethod.Post, $"guilds/{guildId}/prune", - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Guild, - Id = guildId - } - ) + b => b.WithSimpleRoute(TopLevelResource.Guild, guildId) .WithPayload(payload) .WithAuditLogReason(reason), info, @@ -235,14 +207,7 @@ public async ValueTask> CreateGuildChannelAsync ( HttpMethod.Post, $"guilds/{guildId}/channels", - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Guild, - Id = guildId - } - ) + b => b.WithSimpleRoute(TopLevelResource.Guild, guildId) .WithPayload(payload) .WithAuditLogReason(reason), info, @@ -274,14 +239,7 @@ public async ValueTask> CreateGuildRoleAsync ( HttpMethod.Post, $"guilds/{guildId}/roles", - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Guild, - Id = guildId - } - ) + b => b.WithSimpleRoute(TopLevelResource.Guild, guildId) .WithPayload(payload) .WithAuditLogReason(reason), info, @@ -322,14 +280,7 @@ public async ValueTask DeleteGuildIntegrationAsync ( HttpMethod.Delete, $"guilds/{guildId}/integrations/{integrationId}", - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Guild, - Id = guildId - } - ) + b => b.WithSimpleRoute(TopLevelResource.Guild, guildId) .WithRoute($"DELETE guilds/{guildId}/integrations/:integration-id") .WithAuditLogReason(reason), info, @@ -353,14 +304,7 @@ public async ValueTask DeleteGuildRoleAsync ( HttpMethod.Delete, $"guilds/{guildId}/roles/{roleId}", - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Guild, - Id = guildId - } - ) + b => b.WithSimpleRoute(TopLevelResource.Guild, guildId) .WithRoute($"DELETE guilds/{guildId}/roles/:role-id") .WithAuditLogReason(reason), info, @@ -411,14 +355,7 @@ public async ValueTask> GetGuildBanAsync ( HttpMethod.Get, $"guilds/{guildId}/bans/{userId}", - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Guild, - Id = guildId - } - ) + b => b.WithSimpleRoute(TopLevelResource.Guild, guildId) .WithRoute($"GET guilds/{guildId}/bans/:user-id"), info, ct @@ -463,14 +400,7 @@ public async ValueTask>> GetGuildBansAsync ( HttpMethod.Get, builder.Build(), - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Guild, - Id = guildId - } - ), + b => b.WithSimpleRoute(TopLevelResource.Guild, guildId), info, ct ); @@ -488,14 +418,7 @@ public async ValueTask>> GetGuildChannelsAsync ( HttpMethod.Get, $"guilds/{guildId}/channels", - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Guild, - Id = guildId - } - ), + b => b.WithSimpleRoute(TopLevelResource.Guild, guildId), info, ct ); @@ -513,14 +436,7 @@ public async ValueTask>> GetGuildIntegrations ( HttpMethod.Get, $"guilds/{guildId}/integrations", - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Guild, - Id = guildId - } - ), + b => b.WithSimpleRoute(TopLevelResource.Guild, guildId), info, ct ); @@ -538,14 +454,7 @@ public async ValueTask>> GetGuildInvitesAsync ( HttpMethod.Get, $"guilds/{guildId}/invites", - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Guild, - Id = guildId - } - ), + b => b.WithSimpleRoute(TopLevelResource.Guild, guildId), info, ct ); @@ -564,14 +473,7 @@ public async ValueTask> GetGuildMemberAsync ( HttpMethod.Get, $"guilds/{guildId}/members/{userId}", - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Guild, - Id = guildId - } - ) + b => b.WithSimpleRoute(TopLevelResource.Guild, guildId) .WithRoute($"GET guilds/{guildId}/members/:user-id"), info, ct @@ -590,14 +492,7 @@ public async ValueTask> GetGuildOnboardingAsync ( HttpMethod.Get, $"guilds/{guildId}/onboarding", - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Guild, - Id = guildId - } - ), + b => b.WithSimpleRoute(TopLevelResource.Guild, guildId), info, ct ); @@ -615,14 +510,7 @@ public async ValueTask> GetGuildPreviewAsync ( HttpMethod.Get, $"guilds/{guildId}/preview", - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Guild, - Id = guildId - } - ), + b => b.WithSimpleRoute(TopLevelResource.Guild, guildId), info, ct ); @@ -661,14 +549,7 @@ public async ValueTask> GetGuildPruneCountAsy ( HttpMethod.Get, builder.Build(), - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Guild, - Id = guildId - } - ), + b => b.WithSimpleRoute(TopLevelResource.Guild, guildId), info, ct ); @@ -686,14 +567,7 @@ public async ValueTask>> GetGuildRolesAsync ( HttpMethod.Get, $"guilds/{guildId}/roles", - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Guild, - Id = guildId - } - ), + b => b.WithSimpleRoute(TopLevelResource.Guild, guildId), info, ct ); @@ -711,14 +585,7 @@ public async ValueTask> GetGuildVanityUrlAsync ( HttpMethod.Get, $"guilds/{guildId}/vanity-url", - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Guild, - Id = guildId - } - ), + b => b.WithSimpleRoute(TopLevelResource.Guild, guildId), info, ct ); @@ -736,14 +603,7 @@ public async ValueTask>> GetGuildVoiceRegions ( HttpMethod.Get, $"guilds/{guildId}/regions", - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Guild, - Id = guildId - } - ), + b => b.WithSimpleRoute(TopLevelResource.Guild, guildId), info, ct ); @@ -761,14 +621,7 @@ public async ValueTask> GetGuildWelcomeScreenAsync ( HttpMethod.Get, $"guilds/{guildId}/welcome-screen", - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Guild, - Id = guildId - } - ), + b => b.WithSimpleRoute(TopLevelResource.Guild, guildId), info, ct ); @@ -786,14 +639,7 @@ public async ValueTask> GetGuildWidgetAsync ( HttpMethod.Get, $"guilds/{guildId}/widget.json", - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Guild, - Id = guildId - } - ), + b => b.WithSimpleRoute(TopLevelResource.Guild, guildId), info, ct ); @@ -812,14 +658,7 @@ public async ValueTask> GetGuildWidgetImageAsync ( HttpMethod.Get, $"guilds/{guildId}/widget.png", - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Guild, - Id = guildId - } - ), + b => b.WithSimpleRoute(TopLevelResource.Guild, guildId), info, ct ); @@ -839,14 +678,7 @@ public async ValueTask> GetGuildWidgetSettingsAsync ( HttpMethod.Get, $"guilds/{guildId}/widget", - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Guild, - Id = guildId - } - ), + b => b.WithSimpleRoute(TopLevelResource.Guild, guildId), info, ct ); @@ -864,14 +696,7 @@ public async ValueTask> ListActiveGuildTh ( HttpMethod.Get, $"guilds/{guildId}/threads/active", - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Guild, - Id = guildId - } - ), + b => b.WithSimpleRoute(TopLevelResource.Guild, guildId), info, ct ); @@ -910,14 +735,7 @@ public async ValueTask>> ListGuildMembersAsyn ( HttpMethod.Get, builder.Build(), - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Guild, - Id = guildId - } - ), + b => b.WithSimpleRoute(TopLevelResource.Guild, guildId), info, ct ); @@ -937,14 +755,7 @@ public async ValueTask> ModifyCurrentMemberAsync ( HttpMethod.Patch, $"guilds/{guildId}/members/@me", - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Guild, - Id = guildId - } - ) + b => b.WithSimpleRoute(TopLevelResource.Guild, guildId) .WithPayload(payload), info, ct @@ -964,14 +775,7 @@ public async ValueTask ModifyCurrentUserVoiceStateAsync ( HttpMethod.Patch, $"guilds/{guildId}/voice-states/@me", - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Guild, - Id = guildId - } - ) + b => b.WithSimpleRoute(TopLevelResource.Guild, guildId) .WithPayload(payload), info, ct @@ -1004,14 +808,7 @@ public async ValueTask> ModifyGuildAsync ( HttpMethod.Patch, $"guilds/{guildId}", - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Guild, - Id = guildId - } - ) + b => b.WithSimpleRoute(TopLevelResource.Guild, guildId) .WithPayload(payload) .WithAuditLogReason(reason), info, @@ -1032,14 +829,7 @@ public async ValueTask ModifyGuildChannelPositionsAsync ( HttpMethod.Patch, $"guilds/{guildId}/channels", - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Guild, - Id = guildId - } - ) + b => b.WithSimpleRoute(TopLevelResource.Guild, guildId) .WithPayload(payload), info, ct @@ -1068,14 +858,7 @@ public async ValueTask> ModifyGuildMemberAsync ( HttpMethod.Patch, $"guilds/{guildId}/members/{userId}", - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Guild, - Id = guildId - } - ) + b => b.WithSimpleRoute(TopLevelResource.Guild, guildId) .WithRoute($"PATCH guilds/{guildId}/members/:user-id") .WithPayload(payload) .WithAuditLogReason(reason), @@ -1098,14 +881,7 @@ public async ValueTask> ModifyGuildMFALevelAsync ( HttpMethod.Patch, $"guilds/{guildId}/mfa", - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Guild, - Id = guildId - } - ) + b => b.WithSimpleRoute(TopLevelResource.Guild, guildId) .WithPayload(payload) .WithAuditLogReason(reason), info, @@ -1127,14 +903,7 @@ public async ValueTask> ModifyGuildOnboardingAsync ( HttpMethod.Patch, $"guilds/{guildId}/onboarding", - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Guild, - Id = guildId - } - ) + b => b.WithSimpleRoute(TopLevelResource.Guild, guildId) .WithPayload(payload) .WithAuditLogReason(reason), info, @@ -1167,14 +936,7 @@ public async ValueTask> ModifyGuildRoleAsync ( HttpMethod.Patch, $"guilds/{guildId}/roles/{roleId}", - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Guild, - Id = guildId - } - ) + b => b.WithSimpleRoute(TopLevelResource.Guild, guildId) .WithRoute($"PATCH guilds/{guildId}/roles/:role-id") .WithPayload(payload) .WithAuditLogReason(reason), @@ -1197,14 +959,7 @@ public async ValueTask>> ModifyGuildRolePositionsAsy ( HttpMethod.Patch, $"guilds/{guildId}/roles", - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Guild, - Id = guildId - } - ) + b => b.WithSimpleRoute(TopLevelResource.Guild, guildId) .WithPayload(payload) .WithAuditLogReason(reason), info, @@ -1226,14 +981,7 @@ public async ValueTask> ModifyGuildWelcomeScreenAsync ( HttpMethod.Patch, $"guilds/{guildId}/welcome-screen", - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Guild, - Id = guildId - } - ) + b => b.WithSimpleRoute(TopLevelResource.Guild, guildId) .WithPayload(payload) .WithAuditLogReason(reason), info, @@ -1255,14 +1003,7 @@ public async ValueTask> ModifyGuildWidgetAsync ( HttpMethod.Patch, $"guilds/{guildId}/widget", - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Guild, - Id = guildId - } - ) + b => b.WithSimpleRoute(TopLevelResource.Guild, guildId) .WithPayload(settings) .WithAuditLogReason(reason), info, @@ -1284,14 +1025,7 @@ public async ValueTask ModifyUserVoiceStateAsync ( HttpMethod.Patch, $"guilds/{guildId}/voice-states/{userId}", - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Guild, - Id = guildId - } - ) + b => b.WithSimpleRoute(TopLevelResource.Guild, guildId) .WithRoute($"PATCH guilds/{guildId}/voice-states/:user-id") .WithPayload(payload), info, @@ -1315,14 +1049,7 @@ public async ValueTask RemoveGuildBanAsync ( HttpMethod.Delete, $"guilds/{guildId}/bans/{userId}", - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Guild, - Id = guildId - } - ) + b => b.WithSimpleRoute(TopLevelResource.Guild, guildId) .WithRoute($"DELETE guilds/{guildId}/bans/:user-id") .WithAuditLogReason(reason), info, @@ -1346,14 +1073,7 @@ public async ValueTask RemoveGuildMemberAsync ( HttpMethod.Delete, $"guilds/{guildId}/members/{userId}", - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Guild, - Id = guildId - } - ) + b => b.WithSimpleRoute(TopLevelResource.Guild, guildId) .WithRoute($"DELETE guilds/{guildId}/members/:user-id") .WithAuditLogReason(reason), info, @@ -1378,14 +1098,7 @@ public async ValueTask RemoveGuildMemberRoleAsync ( HttpMethod.Delete, $"guilds/{guildId}/members/{userId}/roles/{roleId}", - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Guild, - Id = guildId - } - ) + b => b.WithSimpleRoute(TopLevelResource.Guild, guildId) .WithRoute($"DELETE guilds/{guildId}/members/:user-id/roles/:role-id") .WithAuditLogReason(reason), info, @@ -1425,14 +1138,7 @@ public async ValueTask>> SearchGuildMembersAs ( HttpMethod.Get, $"guilds/{guildId}/members/search", - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Guild, - Id = guildId - } - ), + b => b.WithSimpleRoute(TopLevelResource.Guild, guildId), info, ct ); diff --git a/src/core/DSharpPlus.Internal.Rest/API/GuildScheduledEventRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/GuildScheduledEventRestAPI.cs index 69137b4805..00d84b3c17 100644 --- a/src/core/DSharpPlus.Internal.Rest/API/GuildScheduledEventRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Rest/API/GuildScheduledEventRestAPI.cs @@ -38,14 +38,7 @@ public async ValueTask> CreateGuildScheduledEventAsync ( HttpMethod.Post, $"guilds/{guildId}/scheduled-events", - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Guild, - Id = guildId - } - ) + b => b.WithSimpleRoute(TopLevelResource.Guild, guildId) .WithPayload(payload) .WithAuditLogReason(reason), info, @@ -66,14 +59,7 @@ public async ValueTask DeleteScheduledEventAsync ( HttpMethod.Delete, $"guilds/{guildId}/scheduled-events/{eventId}", - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Guild, - Id = guildId - } - ) + b => b.WithSimpleRoute(TopLevelResource.Guild, guildId) .WithRoute($"DELETE guilds/{guildId}/scheduled-events/:event-id"), info, ct @@ -106,14 +92,7 @@ public async ValueTask> GetScheduledEventAsync ( HttpMethod.Get, builder.Build(), - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Guild, - Id = guildId - } - ) + b => b.WithSimpleRoute(TopLevelResource.Guild, guildId) .WithRoute($"GET guilds/{guildId}/scheduled-events/:event-id"), info, ct @@ -164,14 +143,7 @@ public async ValueTask>> GetScheduledE ( HttpMethod.Get, builder.Build(), - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Guild, - Id = guildId - } - ) + b => b.WithSimpleRoute(TopLevelResource.Guild, guildId) .WithRoute($"GET guilds/{guildId}/scheduled-events/:event-id/users"), info, ct @@ -201,14 +173,7 @@ public async ValueTask>> ListScheduledEven ( HttpMethod.Get, builder.Build(), - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Guild, - Id = guildId - } - ), + b => b.WithSimpleRoute(TopLevelResource.Guild, guildId), info, ct ); @@ -229,14 +194,7 @@ public async ValueTask> ModifyScheduledEventAsync ( HttpMethod.Patch, $"guilds/{guildId}/scheduled-events/{eventId}", - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Guild, - Id = guildId - } - ) + b => b.WithSimpleRoute(TopLevelResource.Guild, guildId) .WithRoute($"POST guilds/{guildId}/scheduled-events/:event-id") .WithPayload(payload) .WithAuditLogReason(reason), diff --git a/src/core/DSharpPlus.Internal.Rest/API/GuildTemplateRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/GuildTemplateRestAPI.cs index 21c7c262c8..b575c78028 100644 --- a/src/core/DSharpPlus.Internal.Rest/API/GuildTemplateRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Rest/API/GuildTemplateRestAPI.cs @@ -72,14 +72,7 @@ public async ValueTask> CreateGuildTemplateAsync ( HttpMethod.Post, $"guilds/{guildId}/templates", - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Guild, - Id = guildId - } - ) + b => b.WithSimpleRoute(TopLevelResource.Guild, guildId) .WithPayload(payload), info, ct @@ -99,14 +92,7 @@ public async ValueTask> DeleteGuildTemplateAsync ( HttpMethod.Delete, $"guilds/{guildId}/templates/{templateCode}", - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Guild, - Id = guildId - } - ) + b => b.WithSimpleRoute(TopLevelResource.Guild, guildId) .WithRoute($"DELETE guilds/{guildId}/templates/:template-code"), info, ct @@ -143,14 +129,7 @@ public async ValueTask>> GetGuildTemplatesAsync ( HttpMethod.Get, $"guilds/{guildId}/templates", - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Guild, - Id = guildId - } - ), + b => b.WithSimpleRoute(TopLevelResource.Guild, guildId), info, ct ); @@ -180,14 +159,7 @@ public async ValueTask> ModifyGuildTemplateAsync ( HttpMethod.Patch, $"guilds/{guildId}/templates/{templateCode}", - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Guild, - Id = guildId - } - ) + b => b.WithSimpleRoute(TopLevelResource.Guild, guildId) .WithRoute($"PATCH guilds/{guildId}/templates/:template-code") .WithPayload(payload), info, @@ -208,14 +180,7 @@ public async ValueTask> SyncGuildTemplateAsync ( HttpMethod.Put, $"guilds/{guildId}/templates/{templateCode}", - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Guild, - Id = guildId - } - ) + b => b.WithSimpleRoute(TopLevelResource.Guild, guildId) .WithRoute($"PUT guilds/{guildId}/templates/:template-code"), info, ct diff --git a/src/core/DSharpPlus.Internal.Rest/API/InteractionRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/InteractionRestAPI.cs index e204b15e26..fc16ec03d8 100644 --- a/src/core/DSharpPlus.Internal.Rest/API/InteractionRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Rest/API/InteractionRestAPI.cs @@ -123,14 +123,7 @@ public async ValueTask CreateInteractionResponseAsync ( HttpMethod.Post, $"interactions/{interactionId}/{interactionToken}/callback", - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Webhook, - Id = interactionId - } - ) + b => b.WithSimpleRoute(TopLevelResource.Webhook, interactionId) .WithRoute($"POST interactions/{interactionId}/{interactionToken}/callback") .AsInteractionRequest() .WithPayload(payload), diff --git a/src/core/DSharpPlus.Internal.Rest/API/StageInstanceRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/StageInstanceRestAPI.cs index 4e50cbce5f..141e61c7cb 100644 --- a/src/core/DSharpPlus.Internal.Rest/API/StageInstanceRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Rest/API/StageInstanceRestAPI.cs @@ -59,14 +59,7 @@ public async ValueTask DeleteStageInstanceAsync ( HttpMethod.Delete, $"stage-instances/{channelId}", - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Channel, - Id = channelId - } - ) + b => b.WithSimpleRoute(TopLevelResource.Channel, channelId) .WithRoute($"DELETE stage-instances/{channelId}") .WithAuditLogReason(reason), info, @@ -88,14 +81,7 @@ public async ValueTask> GetStageInstanceAsync ( HttpMethod.Get, $"stage-instances/{channelId}", - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Channel, - Id = channelId - } - ) + b => b.WithSimpleRoute(TopLevelResource.Channel, channelId) .WithRoute($"GET stage-instances/{channelId}"), info, ct @@ -121,14 +107,7 @@ public async ValueTask> ModifyStageInstanceAsync ( HttpMethod.Patch, $"stage-instances/{channelId}", - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Channel, - Id = channelId - } - ) + b => b.WithSimpleRoute(TopLevelResource.Channel, channelId) .WithRoute($"PATCH stage-instances/{channelId}") .WithPayload(payload) .WithAuditLogReason(reason), diff --git a/src/core/DSharpPlus.Internal.Rest/API/StickerRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/StickerRestAPI.cs index 54be5124eb..cb800a06f3 100644 --- a/src/core/DSharpPlus.Internal.Rest/API/StickerRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Rest/API/StickerRestAPI.cs @@ -54,14 +54,7 @@ public async ValueTask> CreateGuildStickerAsync ( HttpMethod.Post, $"guilds/{guildId}/stickers", - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Guild, - Id = guildId - } - ) + b => b.WithSimpleRoute(TopLevelResource.Guild, guildId) .WithPayload(payload) .WithAuditLogReason(reason), info, @@ -83,14 +76,7 @@ public async ValueTask DeleteGuildStickerAsync ( HttpMethod.Delete, $"guilds/{guildId}/stickers/{stickerId}", - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Guild, - Id = guildId - } - ) + b => b.WithSimpleRoute(TopLevelResource.Guild, guildId) .WithRoute($"DELETE guilds/{guildId}/stickers/:sticker-id") .WithAuditLogReason(reason), info, @@ -113,14 +99,7 @@ public async ValueTask> GetGuildStickerAsync ( HttpMethod.Get, $"guilds/{guildId}/stickers/{stickerId}", - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Guild, - Id = guildId - } - ) + b => b.WithSimpleRoute(TopLevelResource.Guild, guildId) .WithRoute($"GET guilds/{guildId}/stickers/:sticker-id"), info, ct @@ -157,14 +136,7 @@ public async ValueTask>> ListGuildStickersAsync ( HttpMethod.Get, $"guilds/{guildId}/stickers", - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Guild, - Id = guildId - } - ) + b => b.WithSimpleRoute(TopLevelResource.Guild, guildId) .WithRoute($"GET guilds/{guildId}/stickers"), info, ct @@ -223,14 +195,7 @@ public async ValueTask> ModifyGuildStickerAsync ( HttpMethod.Patch, $"guilds/{guildId}/stickers/{stickerId}", - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Guild, - Id = guildId - } - ) + b => b.WithSimpleRoute(TopLevelResource.Guild, guildId) .WithRoute($"PATCH guilds/{guildId}/stickers/:sticker-id") .WithPayload(payload) .WithAuditLogReason(reason), diff --git a/src/core/DSharpPlus.Internal.Rest/API/UserRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/UserRestAPI.cs index 018593e617..4602ba9ee1 100644 --- a/src/core/DSharpPlus.Internal.Rest/API/UserRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Rest/API/UserRestAPI.cs @@ -128,14 +128,7 @@ public async ValueTask> GetCurrentUserGuildMemberAsync ( HttpMethod.Get, $"users/@me/guilds/{guildId}/member", - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Guild, - Id = guildId - } - ) + b => b.WithSimpleRoute(TopLevelResource.Guild, guildId) .WithRoute($"GET users/@me/guilds/{guildId}/member"), info, ct @@ -220,14 +213,7 @@ public async ValueTask LeaveGuildAsync ( HttpMethod.Delete, $"users/@me/guilds/{guildId}", - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Guild, - Id = guildId - } - ) + b => b.WithSimpleRoute(TopLevelResource.Guild, guildId) .WithRoute($"DELETE users/@me/guilds/{guildId}"), info, ct diff --git a/src/core/DSharpPlus.Internal.Rest/API/WebhookRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/WebhookRestAPI.cs index 24606def4a..8c8c6869fb 100644 --- a/src/core/DSharpPlus.Internal.Rest/API/WebhookRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Rest/API/WebhookRestAPI.cs @@ -54,14 +54,7 @@ public async ValueTask> CreateWebhookAsync ( HttpMethod.Post, $"channels/{channelId}/webhooks", - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Channel, - Id = channelId - } - ) + b => b.WithSimpleRoute(TopLevelResource.Channel, channelId) .WithAuditLogReason(reason), info, ct @@ -81,14 +74,7 @@ public async ValueTask DeleteWebhookAsync ( HttpMethod.Delete, $"webhooks/{webhookId}", - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Webhook, - Id = webhookId - } - ) + b => b.WithSimpleRoute(TopLevelResource.Webhook, webhookId) .WithAuditLogReason(reason), info, ct @@ -122,14 +108,7 @@ public async ValueTask DeleteWebhookMessageAsync ( HttpMethod.Delete, builder.ToString(), - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Webhook, - Id = webhookId - } - ) + b => b.WithSimpleRoute(TopLevelResource.Webhook, webhookId) .WithRoute($"DELETE webhooks/{webhookId}/:webhook-token/messages/:message-id") .AsWebhookRequest(), info, @@ -153,14 +132,7 @@ public async ValueTask DeleteWebhookWithTokenAsync ( HttpMethod.Delete, $"webhooks/{webhookId}/{webhookToken}", - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Webhook, - Id = webhookId - } - ) + b => b.WithSimpleRoute(TopLevelResource.Webhook, webhookId) .WithRoute($"DELETE webhooks/{webhookId}/:webhook-token") .WithAuditLogReason(reason) .AsWebhookRequest(), @@ -212,14 +184,7 @@ public async ValueTask> EditWebhookMessageAsync ( HttpMethod.Patch, builder.Build(), - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Webhook, - Id = webhookId - } - ) + b => b.WithSimpleRoute(TopLevelResource.Webhook, webhookId) .WithRoute($"PATCH webhooks/{webhookId}/:webhook-token/messages/:message-id") .WithPayload(payload) .AsWebhookRequest(), @@ -276,14 +241,7 @@ public async ValueTask> ExecuteWebhookAsync ( HttpMethod.Patch, builder.Build(), - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Webhook, - Id = webhookId - } - ) + b => b.WithSimpleRoute(TopLevelResource.Webhook, webhookId) .WithRoute($"PATCH webhooks/{webhookId}/:webhook-token/messages/:message-id") .WithPayload(payload) .AsWebhookRequest(), @@ -298,14 +256,7 @@ public async ValueTask> ExecuteWebhookAsync ( HttpMethod.Patch, builder.Build(), - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Webhook, - Id = webhookId - } - ) + b => b.WithSimpleRoute(TopLevelResource.Webhook, webhookId) .WithRoute($"PATCH webhooks/{webhookId}/:webhook-token/messages/:message-id") .WithPayload(payload) .AsWebhookRequest(), @@ -329,14 +280,7 @@ public async ValueTask>> GetChannelWebhooksAsync ( HttpMethod.Get, $"channels/{channelId}/webhooks", - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Channel, - Id = channelId - } - ), + b => b.WithSimpleRoute(TopLevelResource.Channel, channelId), info, ct ); @@ -354,14 +298,7 @@ public async ValueTask>> GetGuildWebhooksAsync ( HttpMethod.Get, $"guilds/{guildId}/webhooks", - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Guild, - Id = guildId - } - ), + b => b.WithSimpleRoute(TopLevelResource.Guild, guildId), info, ct ); @@ -379,14 +316,7 @@ public async ValueTask> GetWebhookAsync ( HttpMethod.Get, $"webhooks/{webhookId}", - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Webhook, - Id = webhookId - } - ), + b => b.WithSimpleRoute(TopLevelResource.Webhook, webhookId), info, ct ); @@ -417,14 +347,7 @@ public async ValueTask> GetWebhookMessageAsync ( HttpMethod.Get, builder.Build(), - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Webhook, - Id = webhookId - } - ) + b => b.WithSimpleRoute(TopLevelResource.Webhook, webhookId) .WithRoute($"PATCH webhooks/{webhookId}/:webhook-token/messages/:message-id"), info, ct @@ -444,14 +367,7 @@ public async ValueTask> GetWebhookWithTokenAsync ( HttpMethod.Get, $"webhooks/{webhookId}/{webhookToken}", - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Webhook, - Id = webhookId - } - ) + b => b.WithSimpleRoute(TopLevelResource.Webhook, webhookId) .AsWebhookRequest(), info, ct @@ -489,14 +405,7 @@ public async ValueTask> ModifyWebhookAsync ( HttpMethod.Patch, $"webhooks/{webhookId}", - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Webhook, - Id = webhookId - } - ) + b => b.WithSimpleRoute(TopLevelResource.Webhook, webhookId) .WithAuditLogReason(reason), info, ct @@ -535,14 +444,7 @@ public async ValueTask> ModifyWebhookWithTokenAsync ( HttpMethod.Patch, $"webhooks/{webhookId}/{webhookToken}", - b => b.WithSimpleRoute - ( - new SimpleSnowflakeRatelimitRoute - { - Resource = TopLevelResource.Webhook, - Id = webhookId - } - ) + b => b.WithSimpleRoute(TopLevelResource.Webhook, webhookId) .WithAuditLogReason(reason) .AsWebhookRequest(), info, diff --git a/src/core/DSharpPlus.Internal.Rest/RequestBuilderExtensions.cs b/src/core/DSharpPlus.Internal.Rest/RequestBuilderExtensions.cs index 07b00cfd34..be82e5c118 100644 --- a/src/core/DSharpPlus.Internal.Rest/RequestBuilderExtensions.cs +++ b/src/core/DSharpPlus.Internal.Rest/RequestBuilderExtensions.cs @@ -9,9 +9,18 @@ namespace DSharpPlus.Internal.Rest; internal static class RequestBuilderExtensions { - public static RequestBuilder WithSimpleRoute(this RequestBuilder request, SimpleSnowflakeRatelimitRoute route) + public static RequestBuilder WithSimpleRoute(this RequestBuilder request, TopLevelResource resource, Snowflake id) { - request.AddToContext("simple-route", route); + request.AddToContext + ( + "simple-route", + new SimpleSnowflakeRatelimitRoute + { + Id = id, + Resource = resource + } + ); + return request; } From 3c2bf1f4cf5ae065578136ff4dd709c390ffb9f2 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Thu, 8 Feb 2024 19:48:46 +0100 Subject: [PATCH 278/323] it's ratelimiting time --- Directory.Packages.props | 2 + .../API/ChannelRestAPI.cs | 3 +- .../API/EmojiRestAPI.cs | 8 +- .../API/InteractionRestAPI.cs | 2 +- .../DSharpPlus.Internal.Rest.csproj | 8 + .../Ratelimiting/IRatelimitRegistry.cs | 32 ++ .../Ratelimiting/RatelimitBucket.cs | 37 ++ .../Ratelimiting/RatelimitOptions.cs | 28 ++ .../Ratelimiting/RatelimitRegistry.cs | 346 ++++++++++++++++++ ...elimitRoute.cs => SimpleRatelimitRoute.cs} | 2 +- .../RequestBuilderExtensions.cs | 6 +- 11 files changed, 464 insertions(+), 10 deletions(-) create mode 100644 src/core/DSharpPlus.Internal.Rest/Ratelimiting/IRatelimitRegistry.cs create mode 100644 src/core/DSharpPlus.Internal.Rest/Ratelimiting/RatelimitBucket.cs create mode 100644 src/core/DSharpPlus.Internal.Rest/Ratelimiting/RatelimitOptions.cs create mode 100644 src/core/DSharpPlus.Internal.Rest/Ratelimiting/RatelimitRegistry.cs rename src/core/DSharpPlus.Internal.Rest/Ratelimiting/{SimpleSnowflakeRatelimitRoute.cs => SimpleRatelimitRoute.cs} (88%) diff --git a/Directory.Packages.props b/Directory.Packages.props index 5f9f29af1b..4a27cbcc9f 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -2,6 +2,7 @@ + @@ -9,6 +10,7 @@ + diff --git a/src/core/DSharpPlus.Internal.Rest/API/ChannelRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/ChannelRestAPI.cs index ebea091cc6..4a7cb53afd 100644 --- a/src/core/DSharpPlus.Internal.Rest/API/ChannelRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Rest/API/ChannelRestAPI.cs @@ -911,7 +911,8 @@ public async ValueTask> ModifyChannelAsync ( HttpMethod.Patch, $"channels/{channelId}", - b => b.WithSimpleRoute(TopLevelResource.Channel, channelId), + b => b.WithSimpleRoute(TopLevelResource.Channel, channelId) + .WithPayload(payload), info, ct ); diff --git a/src/core/DSharpPlus.Internal.Rest/API/EmojiRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/EmojiRestAPI.cs index 91939a53d2..72889cdcde 100644 --- a/src/core/DSharpPlus.Internal.Rest/API/EmojiRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Rest/API/EmojiRestAPI.cs @@ -59,7 +59,7 @@ public async ValueTask DeleteGuildEmojiAsync ( HttpMethod.Delete, $"guilds/{guildId}/emojis/{emojiId}", - b => b.WithFullRatelimit($"DELETE emojis/{guildId}") + b => b.WithRoute($"DELETE emojis/{guildId}") .WithAuditLogReason(reason), info, ct @@ -81,7 +81,7 @@ public async ValueTask> GetGuildEmojiAsync ( HttpMethod.Get, $"guilds/{guildId}/emojis/{emojiId}", - b => b.WithFullRatelimit($"GET emojis/{guildId}"), + b => b.WithRoute($"GET emojis/{guildId}"), info, ct ); @@ -99,7 +99,7 @@ public async ValueTask>> ListGuildEmojisAsync ( HttpMethod.Get, $"guilds/{guildId}/emojis", - b => b.WithFullRatelimit($"GET emojis/{guildId}"), + b => b.WithRoute($"GET emojis/{guildId}"), info, ct ); @@ -120,7 +120,7 @@ public async ValueTask> ModifyGuildEmojiAsync ( HttpMethod.Patch, $"guilds/{guildId}/emojis/{emojiId}", - b => b.WithFullRatelimit($"GET emojis/{guildId}") + b => b.WithRoute($"GET emojis/{guildId}") .WithPayload(payload) .WithAuditLogReason(reason), info, diff --git a/src/core/DSharpPlus.Internal.Rest/API/InteractionRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/InteractionRestAPI.cs index fc16ec03d8..3eef3fa900 100644 --- a/src/core/DSharpPlus.Internal.Rest/API/InteractionRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Rest/API/InteractionRestAPI.cs @@ -125,7 +125,7 @@ public async ValueTask CreateInteractionResponseAsync $"interactions/{interactionId}/{interactionToken}/callback", b => b.WithSimpleRoute(TopLevelResource.Webhook, interactionId) .WithRoute($"POST interactions/{interactionId}/{interactionToken}/callback") - .AsInteractionRequest() + .AsExempt() .WithPayload(payload), info, ct diff --git a/src/core/DSharpPlus.Internal.Rest/DSharpPlus.Internal.Rest.csproj b/src/core/DSharpPlus.Internal.Rest/DSharpPlus.Internal.Rest.csproj index 8c665210ed..6d413c4121 100644 --- a/src/core/DSharpPlus.Internal.Rest/DSharpPlus.Internal.Rest.csproj +++ b/src/core/DSharpPlus.Internal.Rest/DSharpPlus.Internal.Rest.csproj @@ -5,10 +5,12 @@ + + @@ -17,4 +19,10 @@ + + + <_Parameter1>DSharpPlus.Internal.Rest.Tests + + + diff --git a/src/core/DSharpPlus.Internal.Rest/Ratelimiting/IRatelimitRegistry.cs b/src/core/DSharpPlus.Internal.Rest/Ratelimiting/IRatelimitRegistry.cs new file mode 100644 index 0000000000..4e1dcb0163 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Rest/Ratelimiting/IRatelimitRegistry.cs @@ -0,0 +1,32 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Net.Http; + +using Remora.Results; + +namespace DSharpPlus.Internal.Rest.Ratelimiting; + +/// +/// Represents a library hook for modifying ratelimiting behaviour. This is called into by rest-internal code, +/// and third-party rest implementations may not behave identically. +/// +public interface IRatelimitRegistry +{ + /// + /// Checks whether this request should be allowed to proceed. This should be considering as enqueuing a request + /// as far as is concerned. + /// + public Result CheckRatelimit(HttpRequestMessage request); + + /// + /// Updates the ratelimits encountered from the given request. + /// + public Result UpdateRatelimit(HttpRequestMessage request, HttpResponseMessage response); + + /// + /// Cancels a request reservation made in . + /// + public Result CancelRequest(HttpRequestMessage request); +} diff --git a/src/core/DSharpPlus.Internal.Rest/Ratelimiting/RatelimitBucket.cs b/src/core/DSharpPlus.Internal.Rest/Ratelimiting/RatelimitBucket.cs new file mode 100644 index 0000000000..eada2078fa --- /dev/null +++ b/src/core/DSharpPlus.Internal.Rest/Ratelimiting/RatelimitBucket.cs @@ -0,0 +1,37 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Threading; + +namespace DSharpPlus.Internal.Rest.Ratelimiting; + +/// +/// Represents a full ratelimiting bucket. +/// +// this is a class because we use a ConditionalWeakTable to hold it, but there's room for improvement here. +internal sealed class RatelimitBucket +{ + public required float Expiry { get => this.expiry; set => this.expiry = value; } + private float expiry; + + public required int Limit { get => this.limit; set => this.limit = value; } + private int limit; + + public required int Remaining { get => this.remaining; set => this.remaining = value; } + private int remaining; + + public required int Reserved { get => this.reserved; set => this.reserved = value; } + private int reserved; + + public void UpdateFromResponse(float expiry, int limit, int remaining) + { + Interlocked.Exchange(ref this.expiry, expiry); + Interlocked.Exchange(ref this.limit, limit); + Interlocked.Exchange(ref this.remaining, remaining); + Interlocked.Decrement(ref this.reserved); + } + + public void Reserve() => Interlocked.Increment(ref this.reserved); + public void CancelReservation() => Interlocked.Decrement(ref this.reserved); +} diff --git a/src/core/DSharpPlus.Internal.Rest/Ratelimiting/RatelimitOptions.cs b/src/core/DSharpPlus.Internal.Rest/Ratelimiting/RatelimitOptions.cs new file mode 100644 index 0000000000..7542077bce --- /dev/null +++ b/src/core/DSharpPlus.Internal.Rest/Ratelimiting/RatelimitOptions.cs @@ -0,0 +1,28 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Threading; + +namespace DSharpPlus.Internal.Rest.Ratelimiting; + +/// +/// Contains options ot configure ratelimiting behaviour. +/// +public sealed class RatelimitOptions +{ + /// + /// Indicates to the library whether to use a separate thread to clean up old ratelimits. + /// + public bool UseSeparateCleanupThread { get; set; } = true; + + /// + /// Specifies the interval in milliseconds at which ratelimits are cleaned up. + /// + public int CleanupInterval { get; set; } = 10000; + + /// + /// Gets a cancellation token for ratelimit cleanup. + /// + public CancellationToken Token { get; set; } +} diff --git a/src/core/DSharpPlus.Internal.Rest/Ratelimiting/RatelimitRegistry.cs b/src/core/DSharpPlus.Internal.Rest/Ratelimiting/RatelimitRegistry.cs new file mode 100644 index 0000000000..42c9ae2db3 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Rest/Ratelimiting/RatelimitRegistry.cs @@ -0,0 +1,346 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +#pragma warning disable CA1812, CA2008 + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net; +using System.Net.Http; +using System.Net.Http.Headers; +using System.Runtime.CompilerServices; +using System.Threading; +using System.Threading.Tasks; + +using DSharpPlus.Internal.Abstractions.Rest; + +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Options; +using Microsoft.Extensions.Primitives; + +using NonBlocking; + +using Polly; + +using Remora.Results; + +namespace DSharpPlus.Internal.Rest.Ratelimiting; + +/// +/// Contains and manages ratelimits as far as known. +/// +public sealed class RatelimitRegistry : IRatelimitRegistry +{ + private readonly ConcurrentDictionary webhook429s = new(); + private readonly ConcurrentDictionary route429s = new(); + private readonly ConcurrentDictionary hashes = new(); + private readonly ConditionalWeakTable ratelimitBuckets = []; + private readonly ILogger logger; + + private readonly double timeReferencePoint; + + private bool dirty; + + public RatelimitRegistry + ( + ILogger logger, + IOptions options + ) + { + this.logger = logger; + + // ExecuteSynchronously ensures we never leave that thread. + TaskFactory factory = options.Value.UseSeparateCleanupThread + ? new TaskFactory(TaskCreationOptions.LongRunning, TaskContinuationOptions.ExecuteSynchronously) + : Task.Factory; + + _ = factory.StartNew(() => this.CleanupSimpleRatelimitsAsync(options.Value.CleanupInterval, options.Value.Token)); + this.timeReferencePoint = DateTimeOffset.UtcNow.ToUnixTimeSeconds(); + } + + private async ValueTask CleanupSimpleRatelimitsAsync(int interval, CancellationToken ct) + { + using PeriodicTimer timer = new(TimeSpan.FromMilliseconds(interval)); + + // 2x the interval, rounded down + int decay = interval / 500; + int counter = 0; + + startingCleanupLoop(this.logger, interval, decay, null); + + while (await timer.WaitForNextTickAsync(ct)) + { + if (!this.dirty) + { +#pragma warning disable CA1848 // there's no performance improvement to be gained from not having any placeholders. + this.logger.LogTrace("There was no simple ratelimit added since last cleanup, skipping."); + continue; +#pragma warning restore CA1848 + } + + double currentTime = DateTimeOffset.UtcNow.ToUnixTimeSeconds(); + initiatingCleanupMessage(this.logger, "webhook", this.webhook429s.Count, null); + + // we iterate on a snapshot. this leads to rare race conditions if a bucket is updated while we're iterating, + // but since we only remove considerably outdated buckets that have already reset a while ago, the worst that + // can happen is that we delete the first response, the second will then be correctly limited - unless the bucket + // is extremely long-lived and we hit this condition on every request. this is unlikely enough to assume it + // doesn't happen, i believe. + foreach (KeyValuePair pair in this.webhook429s) + { + if (currentTime > pair.Value + this.timeReferencePoint) + { + this.webhook429s.Remove(pair.Key, out _); + } + } + + completedCleanupMessage(this.logger, "webhook", this.webhook429s.Count, null); + initiatingCleanupMessage(this.logger, "route", this.route429s.Count, null); + + foreach (KeyValuePair pair in this.route429s) + { + if (currentTime > pair.Value + this.timeReferencePoint) + { + this.route429s.Remove(pair.Key, out _); + } + } + + completedCleanupMessage(this.logger, "route", this.route429s.Count, null); + + // only clean buckets every ten iterations. this can be changed later + if (counter >= 10) + { + initiatingHashCleanupMessage(this.logger, this.hashes.Count, null); + + foreach (KeyValuePair pair in this.hashes) + { + if (this.ratelimitBuckets.TryGetValue(pair.Key, out RatelimitBucket? bucket)) + { + if (currentTime > bucket.Expiry + this.timeReferencePoint) + { + // since we use a CWT, the bucket will automatically die once all routes holding on to it are dead + this.hashes.Remove(pair.Key, out _); + } + } + } + + completedHashCleanupMessage(this.logger, this.hashes.Count, null); + counter = 0; + } + + this.dirty = false; + counter++; + } + } + + /// + public Result CheckRatelimit(HttpRequestMessage request) + { + Context? context = request.GetPolicyExecutionContext(); + double currentTime = DateTimeOffset.UtcNow.ToUnixTimeSeconds(); + + string route = context is not null && context.TryGetValue("route", out object rawRoute) && rawRoute is string contextRoute + ? contextRoute + : $"{request.Method.ToString().ToUpperInvariant()} {request.RequestUri}"; + + // we know the route - easy enough + if (this.hashes.TryGetValue(route, out string? hash) && this.ratelimitBuckets.TryGetValue(hash, out RatelimitBucket? bucket)) + { + bool success = bucket.Remaining - bucket.Reserved > 0; + + if (!success) + { + rejectedRatelimit(this.logger, request.RequestUri!.AbsoluteUri, "conclusively", null); + } + + bucket.Reserve(); + return success; + } + + // what if we don't know this route? check whether we know related routes, answer heuristically based on that + int index = route.IndexOf(' ', StringComparison.Ordinal); + StringSegment segment = new(route, index + 1, route.Length - index - 1); + + if (this.route429s.TryGetValue(segment, out float last429Expiry)) + { + bool success = currentTime > this.timeReferencePoint + last429Expiry; + + if (!success) + { + rejectedRatelimit(this.logger, request.RequestUri!.AbsoluteUri, "speculatively based on route ratelimits", null); + } + + return success; + } + + // we don't know related routes yet. if it's a webhook route, we check the simple route. for other kinds of routes we + // can impl heuristics here too, but not yet + if + ( + context is not null + && context.TryGetValue("simple-route", out object rawSimpleRoute) + && rawSimpleRoute is SimpleRatelimitRoute simpleRoute + && simpleRoute.Resource == TopLevelResource.Webhook + ) + { + if (this.webhook429s.TryGetValue(simpleRoute.Id, out last429Expiry)) + { + bool success = currentTime > this.timeReferencePoint + last429Expiry; + + if (!success) + { + rejectedRatelimit(this.logger, request.RequestUri!.AbsoluteUri, "speculatively based on webhook ratelimits", null); + } + + return success; + } + } + + return true; + } + + /// + public Result UpdateRatelimit(HttpRequestMessage request, HttpResponseMessage response) + { + // extract the reset time, immediately bail if we couldn't find one + HttpResponseHeaders headers = response.Headers; + double reset = 0; + + if + ( + !headers.TryGetValues("X-RateLimit-Reset", out IEnumerable? rawReset) + && !double.TryParse(rawReset?.SingleOrDefault(), out reset) + ) + { + return new ArgumentInvalidError("response.Headers", "Failed to parse an X-RateLimit-Reset header from the response."); + } + + Context? context = request.GetPolicyExecutionContext(); + + string route = context is not null && context.TryGetValue("route", out object rawRoute) && rawRoute is string contextRoute + ? contextRoute + : $"{request.Method.ToString().ToUpperInvariant()} {request.RequestUri}"; + + // if we have a ratelimit, try to encode the result into the preemptive handlers if necessary + if (response.StatusCode == HttpStatusCode.TooManyRequests) + { + if + ( + context is not null + && context.TryGetValue("simple-route", out object rawSimpleRoute) + && rawSimpleRoute is SimpleRatelimitRoute simpleRoute + && simpleRoute.Resource == TopLevelResource.Webhook + ) + { + this.webhook429s[simpleRoute.Id] = (float)(reset - this.timeReferencePoint); + } + else + { + // what if we don't know this route? check whether we know related routes, answer heuristically based on that + int index = route.IndexOf(' ', StringComparison.Ordinal); + StringSegment segment = new(route, index + 1, route.Length - index - 1); + + this.route429s[segment] = (float)(reset - this.timeReferencePoint); + } + } + + // update the bucket, first by extracting the other relevant information... + if (!headers.TryGetValues("X-RateLimit-Bucket", out IEnumerable? rawBucket)) + { + return new ArgumentInvalidError("response.Headers", "Failed to parse an X-RateLimit-Bucket header from the response."); + } + + string hash = rawBucket.Single(); + short limit = 0, remaining = 0; + + if + ( + !headers.TryGetValues("X-RateLimit-Limit", out IEnumerable? rawLimit) + && !short.TryParse(rawLimit?.SingleOrDefault(), out limit) + ) + { + return new ArgumentInvalidError("response.Headers", "Failed to parse an X-RateLimit-Limit header from the response."); + } + + if + ( + !headers.TryGetValues("X-RateLimit-Remaining", out IEnumerable? rawRemaining) + && !short.TryParse(rawRemaining?.SingleOrDefault(), out remaining) + ) + { + return new ArgumentInvalidError("response.Headers", "Failed to parse an X-RateLimit-Remaining header from the response."); + } + + this.dirty = true; + + // ... and then by updating the values we know. + this.hashes[route] = hash; + RatelimitBucket bucket = this.ratelimitBuckets.GetOrCreateValue(hash); + + bucket.UpdateFromResponse((float)(reset - this.timeReferencePoint), limit, remaining); + + return default; + } + + public Result CancelRequest(HttpRequestMessage request) + { + Context? context = request.GetPolicyExecutionContext(); + + string route = context is not null && context.TryGetValue("route", out object rawRoute) && rawRoute is string contextRoute + ? contextRoute + : $"{request.Method.ToString().ToUpperInvariant()} {request.RequestUri}"; + + if (this.hashes.TryGetValue(route, out string? hash) && this.ratelimitBuckets.TryGetValue(hash, out RatelimitBucket? bucket)) + { + bucket.CancelReservation(); + } + + return default; + } + + // logging delegates defined down here + + private static readonly Action initiatingCleanupMessage = LoggerMessage.Define + ( + LogLevel.Trace, + default, + "Initiating {Kind}-based heuristic cleanup, current size: {Size}." + ); + + private static readonly Action completedCleanupMessage = LoggerMessage.Define + ( + LogLevel.Trace, + default, + "Completed {Kind}-based heuristic cleanup, new size: {Size}." + ); + + private static readonly Action initiatingHashCleanupMessage = LoggerMessage.Define + ( + LogLevel.Trace, + default, + "Initiating ratelimit hash cleanup, current size: {Size}." + ); + + private static readonly Action completedHashCleanupMessage = LoggerMessage.Define + ( + LogLevel.Trace, + default, + "Completed ratelimit hash cleanup, new size: {Size}." + ); + + private static readonly Action startingCleanupLoop = LoggerMessage.Define + ( + LogLevel.Debug, + default, + "Starting heuristic cleanup loop with an interval of {Interval}ms and a bucket decay of {Decay}s." + ); + + private static readonly Action rejectedRatelimit = LoggerMessage.Define + ( + LogLevel.Debug, + default, + "Rejected request to {Url}, {Status}." + ); +} diff --git a/src/core/DSharpPlus.Internal.Rest/Ratelimiting/SimpleSnowflakeRatelimitRoute.cs b/src/core/DSharpPlus.Internal.Rest/Ratelimiting/SimpleRatelimitRoute.cs similarity index 88% rename from src/core/DSharpPlus.Internal.Rest/Ratelimiting/SimpleSnowflakeRatelimitRoute.cs rename to src/core/DSharpPlus.Internal.Rest/Ratelimiting/SimpleRatelimitRoute.cs index b67c4a9606..c4e7d60a11 100644 --- a/src/core/DSharpPlus.Internal.Rest/Ratelimiting/SimpleSnowflakeRatelimitRoute.cs +++ b/src/core/DSharpPlus.Internal.Rest/Ratelimiting/SimpleRatelimitRoute.cs @@ -7,7 +7,7 @@ namespace DSharpPlus.Internal.Rest.Ratelimiting; /// /// Specifies a route likely defined by its resource and a snowflake. /// -internal readonly record struct SimpleSnowflakeRatelimitRoute +internal readonly record struct SimpleRatelimitRoute { public required TopLevelResource Resource { get; init; } diff --git a/src/core/DSharpPlus.Internal.Rest/RequestBuilderExtensions.cs b/src/core/DSharpPlus.Internal.Rest/RequestBuilderExtensions.cs index be82e5c118..72f1132eb3 100644 --- a/src/core/DSharpPlus.Internal.Rest/RequestBuilderExtensions.cs +++ b/src/core/DSharpPlus.Internal.Rest/RequestBuilderExtensions.cs @@ -14,7 +14,7 @@ public static RequestBuilder WithSimpleRoute(this RequestBuilder request, TopLev request.AddToContext ( "simple-route", - new SimpleSnowflakeRatelimitRoute + new SimpleRatelimitRoute { Id = id, Resource = resource @@ -24,9 +24,9 @@ public static RequestBuilder WithSimpleRoute(this RequestBuilder request, TopLev return request; } - public static RequestBuilder WithFullRatelimit(this RequestBuilder request, string route) + public static RequestBuilder AsExempt(this RequestBuilder request, bool isExempt = true) { - request.AddToContext("full-ratelimit", route); + request.AddToContext("is-exempt", isExempt); return request; } From 1dde64ebba0e079d29938880ee145c66feadef34 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Thu, 8 Feb 2024 23:44:10 +0100 Subject: [PATCH 279/323] appease vamplay --- src/core/DSharpPlus.Shared/Optional`1.cs | 55 +++++++----------------- 1 file changed, 15 insertions(+), 40 deletions(-) diff --git a/src/core/DSharpPlus.Shared/Optional`1.cs b/src/core/DSharpPlus.Shared/Optional`1.cs index 61d6286c62..d95926ba49 100644 --- a/src/core/DSharpPlus.Shared/Optional`1.cs +++ b/src/core/DSharpPlus.Shared/Optional`1.cs @@ -2,6 +2,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +#pragma warning disable CA1000 + using System; using System.Diagnostics.CodeAnalysis; @@ -34,22 +36,18 @@ public T Value } } - public Optional - ( - T? value - ) + public Optional(T? value) { this.HasValue = true; this.value = value; } + public static Optional None => default; + /// /// Returns the contained value if one is present, or throws the given exception if none is present. /// - public readonly T? Expect - ( - Func exception - ) + public readonly T? Expect(Func exception) { if (!this.HasValue) { @@ -62,23 +60,19 @@ Func exception /// /// Returns the contained value if present, or the provided value if not present. /// - public readonly T? Or(T value) + public readonly T? Or(T value) => this.HasValue ? this.value : value; /// /// Returns the contained value if present, or the default value for this type if not present. /// - public readonly T? OrDefault() - => this.HasValue ? this.value : default; + public readonly T? OrDefault() => this.value; /// /// Transforms the given optional to an optional of if it has a value, /// returning an empty optional if there was no value present. /// - public readonly Optional Map - ( - Func transformation - ) + public readonly Optional Map(Func transformation) { return this.HasValue ? new Optional(transformation(this.value)) @@ -89,11 +83,7 @@ public readonly Optional Map /// Transforms the value of the given optional to , returning /// if there was no value present. /// - public readonly TOther? MapOr - ( - Func transformation, - TOther? value - ) + public readonly TOther? MapOr(Func transformation, TOther? value) { return this.HasValue ? transformation(this.value) @@ -104,19 +94,10 @@ public readonly TOther? MapOr /// Returns a value indicating whether is set. /// /// The value of this optional. This may still be null if the set value was null. - public readonly bool TryGetValue - ( - out T? value - ) + public readonly bool TryGetValue(out T? value) { - if (this.HasValue) - { - value = this.value; - return true; - } - - value = default; - return false; + value = this.value; + return this.HasValue; } /// @@ -130,14 +111,8 @@ public readonly bool TryGetNonNullValue out T? value ) { - if (this.HasValue && this.value is not null) - { - value = this.value; - return true; - } - - value = default; - return false; + value = this.value; + return this.value is not null; } /// From 7967997e94500558c3acbd7f2f5483d05e0cb20a Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Thu, 8 Feb 2024 23:46:43 +0100 Subject: [PATCH 280/323] i got too clever --- src/core/DSharpPlus.Shared/Optional`1.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/DSharpPlus.Shared/Optional`1.cs b/src/core/DSharpPlus.Shared/Optional`1.cs index d95926ba49..0916aeb1f6 100644 --- a/src/core/DSharpPlus.Shared/Optional`1.cs +++ b/src/core/DSharpPlus.Shared/Optional`1.cs @@ -112,7 +112,7 @@ out T? value ) { value = this.value; - return this.value is not null; + return this.value is not null && this.HasValue; } /// From 0cdeae823a97c00e0c8d0c55012de1c29eca0536 Mon Sep 17 00:00:00 2001 From: DPlayer234 Date: Fri, 9 Feb 2024 16:09:14 +0100 Subject: [PATCH 281/323] fix nullability annotations for Optional (#1755) --- .../Converters/OptionalConverter.cs | 2 +- src/core/DSharpPlus.Shared/Optional`1.cs | 22 +++++++++---------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/core/DSharpPlus.Internal.Models/Serialization/Converters/OptionalConverter.cs b/src/core/DSharpPlus.Internal.Models/Serialization/Converters/OptionalConverter.cs index 74b5373161..bce74953d9 100644 --- a/src/core/DSharpPlus.Internal.Models/Serialization/Converters/OptionalConverter.cs +++ b/src/core/DSharpPlus.Internal.Models/Serialization/Converters/OptionalConverter.cs @@ -14,7 +14,7 @@ namespace DSharpPlus.Internal.Models.Serialization.Converters; public sealed class OptionalConverter : JsonConverter> { public override Optional Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) - => new(JsonSerializer.Deserialize(ref reader, options)); + => new(JsonSerializer.Deserialize(ref reader, options)!); public override void Write ( diff --git a/src/core/DSharpPlus.Shared/Optional`1.cs b/src/core/DSharpPlus.Shared/Optional`1.cs index 0916aeb1f6..32eddaf052 100644 --- a/src/core/DSharpPlus.Shared/Optional`1.cs +++ b/src/core/DSharpPlus.Shared/Optional`1.cs @@ -36,7 +36,7 @@ public T Value } } - public Optional(T? value) + public Optional(T value) { this.HasValue = true; this.value = value; @@ -47,21 +47,21 @@ public Optional(T? value) /// /// Returns the contained value if one is present, or throws the given exception if none is present. /// - public readonly T? Expect(Func exception) + public readonly T Expect(Func exception) { if (!this.HasValue) { ThrowHelper.ThrowFunc(exception); } - return this.value; + return this.value!; } /// /// Returns the contained value if present, or the provided value if not present. /// - public readonly T? Or(T value) - => this.HasValue ? this.value : value; + public readonly T Or(T value) + => this.HasValue ? this.value! : value; /// /// Returns the contained value if present, or the default value for this type if not present. @@ -72,21 +72,21 @@ public Optional(T? value) /// Transforms the given optional to an optional of if it has a value, /// returning an empty optional if there was no value present. /// - public readonly Optional Map(Func transformation) + public readonly Optional Map(Func transformation) { return this.HasValue - ? new Optional(transformation(this.value)) - : new Optional(); + ? new Optional(transformation(this.value!)) + : Optional.None; } /// /// Transforms the value of the given optional to , returning /// if there was no value present. /// - public readonly TOther? MapOr(Func transformation, TOther? value) + public readonly TOther MapOr(Func transformation, TOther value) { return this.HasValue - ? transformation(this.value) + ? transformation(this.value!) : value; } @@ -94,7 +94,7 @@ public readonly Optional Map(Func transformation) /// Returns a value indicating whether is set. /// /// The value of this optional. This may still be null if the set value was null. - public readonly bool TryGetValue(out T? value) + public readonly bool TryGetValue([MaybeNullWhen(false)] out T value) { value = this.value; return this.HasValue; From 1ed5c9c6383502ec934d9eb326762c2e8a99de0c Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sat, 10 Feb 2024 16:32:12 +0100 Subject: [PATCH 282/323] formatting --- src/core/DSharpPlus.Shared/Optional`1.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/core/DSharpPlus.Shared/Optional`1.cs b/src/core/DSharpPlus.Shared/Optional`1.cs index 32eddaf052..dcacbbda0a 100644 --- a/src/core/DSharpPlus.Shared/Optional`1.cs +++ b/src/core/DSharpPlus.Shared/Optional`1.cs @@ -94,7 +94,11 @@ public readonly TOther MapOr(Func transformation, TOther valu /// Returns a value indicating whether is set. /// /// The value of this optional. This may still be null if the set value was null. - public readonly bool TryGetValue([MaybeNullWhen(false)] out T value) + public readonly bool TryGetValue + ( + [MaybeNullWhen(false)] + out T value + ) { value = this.value; return this.HasValue; From 496f525e646a564379cc644901a6f51aeee0f7f6 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Mon, 12 Feb 2024 12:56:48 +0100 Subject: [PATCH 283/323] switch to using version prefix --- Directory.Build.targets | 5 ----- src/core/DSharpPlus.Shared/DSharpPlus.Shared.csproj | 2 +- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/Directory.Build.targets b/Directory.Build.targets index 9b81f5d160..5f837e8d23 100644 --- a/Directory.Build.targets +++ b/Directory.Build.targets @@ -50,10 +50,5 @@ - - - - $(_DSharpPlusReleaseVersion) - \ No newline at end of file diff --git a/src/core/DSharpPlus.Shared/DSharpPlus.Shared.csproj b/src/core/DSharpPlus.Shared/DSharpPlus.Shared.csproj index 904eb82ab4..d845686479 100644 --- a/src/core/DSharpPlus.Shared/DSharpPlus.Shared.csproj +++ b/src/core/DSharpPlus.Shared/DSharpPlus.Shared.csproj @@ -1,7 +1,7 @@  - true + $(_DSharpPlusReleaseVersion) $(Description) This package contains shared types between public-facing and internal implementation packages. Library true From 14067f5577e2577c4e6852ea2bfe335adff13bc0 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sat, 17 Feb 2024 22:45:50 +0100 Subject: [PATCH 284/323] result basics, sugar and default error suite coming soon --- .../DSharpPlus.Shared/Results/Errors/Error.cs | 19 +++ .../Results/Errors/ExceptionError.cs | 33 +++++ .../ExceptionServices/ExceptionMarshaller.cs | 113 ++++++++++++++++++ .../Results/ExceptionServices/MarshalError.cs | 25 ++++ .../ExceptionServices/MarshalException.cs | 24 ++++ src/core/DSharpPlus.Shared/Results/Result.cs | 36 ++++++ .../DSharpPlus.Shared/Results/Result`1.cs | 50 ++++++++ 7 files changed, 300 insertions(+) create mode 100644 src/core/DSharpPlus.Shared/Results/Errors/Error.cs create mode 100644 src/core/DSharpPlus.Shared/Results/Errors/ExceptionError.cs create mode 100644 src/core/DSharpPlus.Shared/Results/ExceptionServices/ExceptionMarshaller.cs create mode 100644 src/core/DSharpPlus.Shared/Results/ExceptionServices/MarshalError.cs create mode 100644 src/core/DSharpPlus.Shared/Results/ExceptionServices/MarshalException.cs create mode 100644 src/core/DSharpPlus.Shared/Results/Result.cs create mode 100644 src/core/DSharpPlus.Shared/Results/Result`1.cs diff --git a/src/core/DSharpPlus.Shared/Results/Errors/Error.cs b/src/core/DSharpPlus.Shared/Results/Errors/Error.cs new file mode 100644 index 0000000000..848d460249 --- /dev/null +++ b/src/core/DSharpPlus.Shared/Results/Errors/Error.cs @@ -0,0 +1,19 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Results.Errors; + +/// +/// Represents an error that has occurred during the operation described by the Result containing this error. +/// +public abstract record Error +{ + /// + /// The human-readable error message. + /// + public string Message { get; init; } + + protected Error(string message) + => this.Message = message; +} diff --git a/src/core/DSharpPlus.Shared/Results/Errors/ExceptionError.cs b/src/core/DSharpPlus.Shared/Results/Errors/ExceptionError.cs new file mode 100644 index 0000000000..3832143123 --- /dev/null +++ b/src/core/DSharpPlus.Shared/Results/Errors/ExceptionError.cs @@ -0,0 +1,33 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +#pragma warning disable CA2201 + +using System; + +namespace DSharpPlus.Results.Errors; + +/// +/// Provides a base class for errors that can map to an exception. +/// +public abstract record ExceptionError : Error +{ + /// + /// Converts this error into a throwable exception. + /// + public virtual Exception ToException() => new(this.Message); + + protected ExceptionError(string message) : base(message) + { + + } + + /// + /// Override this constructor to provide a way to be constructible from an exception. + /// + protected ExceptionError(Exception exception) : base(exception.Message) + { + + } +} diff --git a/src/core/DSharpPlus.Shared/Results/ExceptionServices/ExceptionMarshaller.cs b/src/core/DSharpPlus.Shared/Results/ExceptionServices/ExceptionMarshaller.cs new file mode 100644 index 0000000000..62387ace27 --- /dev/null +++ b/src/core/DSharpPlus.Shared/Results/ExceptionServices/ExceptionMarshaller.cs @@ -0,0 +1,113 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +#pragma warning disable IDE0046 + +using System; + +using DSharpPlus.Results.Errors; + +namespace DSharpPlus.Results.ExceptionServices; + +/// +/// Provides a way to marshal results to exceptions, if erroneous. Exceptions and result may not be able to be round-tripped. +/// +public static class ExceptionMarshaller +{ + /// + /// Creates an exception from the specified result error. + /// + public static Exception MarshalResultErrorToException(Error error) + { + // if we previously failed to marshal this into an error, just get the original exception + if (error.GetType() == typeof(MarshalError)) + { + return ((MarshalError)(object)error).Exception; + } + + // if this is freely convertible, just do that + if (error.GetType().IsAssignableTo(typeof(ExceptionError))) + { + return ((ExceptionError)(object)error).ToException(); + } + + return new MarshalException(error); + } + + /// + /// Creates a result error from the specified exception. + /// + public static Error MarshalExceptionToResultError(Exception exception) + { + if (exception.GetType() == typeof(MarshalException)) + { + return ((MarshalException)(object)exception).Error; + } + + // see if we can find a matching error in a sufficiently similarly named namespace, + // ie DSharpPlus.Exceptions.DiscordException -> DSharpPlus.Errors.DiscordError + if (Type.GetType(exception.GetType().FullName!.Replace("Exception", "Error", StringComparison.Ordinal)) is Type candidate) + { + if (candidate.IsAssignableTo(typeof(ExceptionError))) + { + return (Error)candidate.GetConstructor([typeof(Exception)])!.Invoke([exception]); + } + } + + // try replacing the namespace with DSharpPlus.Results.Errors, too + if + ( + Type.GetType + ( + $"DSharpPlus.Results.Errors.{exception.GetType().Name!.Replace("Exception", "Error", StringComparison.Ordinal)}" + ) is Type secondCandidate + ) + { + if (secondCandidate.IsAssignableTo(typeof(ExceptionError))) + { + return (Error)secondCandidate.GetConstructor([typeof(Exception)])!.Invoke([exception]); + } + } + + return new MarshalError(exception); + } + + /// + /// Creates an exception from the specified result, if erroneous. + /// + public static Exception? MarshalResultToException(Result result) + { + if (result.IsSuccess) + { + return null; + } + + return MarshalResultErrorToException(result.Error); + } + + /// + /// Creates an exception from the specified generic result, if erroneous. + /// + public static Exception? MarshalResultToException(Result result) + { + if (result.IsSuccess) + { + return null; + } + + return MarshalResultErrorToException(result.Error); + } + + /// + /// Creates an erroneous result from the specified exception. + /// + public static Result MarshalExceptionToResult(Exception exception) + => new(MarshalExceptionToResultError(exception)); + + /// + /// Creates an erroneous generic result from the specified exception. + /// + public static Result MarshalExceptionToResult(Exception exception) + => new(MarshalExceptionToResultError(exception)); +} diff --git a/src/core/DSharpPlus.Shared/Results/ExceptionServices/MarshalError.cs b/src/core/DSharpPlus.Shared/Results/ExceptionServices/MarshalError.cs new file mode 100644 index 0000000000..5c5c2114c8 --- /dev/null +++ b/src/core/DSharpPlus.Shared/Results/ExceptionServices/MarshalError.cs @@ -0,0 +1,25 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; +using System.Diagnostics.CodeAnalysis; + +using DSharpPlus.Results.Errors; + +namespace DSharpPlus.Results.ExceptionServices; + +/// +/// Used by the result-exception marshaller when failing to find a matching result error. +/// +public sealed record MarshalError : Error +{ + /// + /// Gets the exception that failed to marshal. + /// + public required Exception Exception { get; init; } + + [SetsRequiredMembers] + public MarshalError(Exception exception) : base("Failed to find a suitable result type for the exception.") + => this.Exception = exception; +} diff --git a/src/core/DSharpPlus.Shared/Results/ExceptionServices/MarshalException.cs b/src/core/DSharpPlus.Shared/Results/ExceptionServices/MarshalException.cs new file mode 100644 index 0000000000..a50bb49f95 --- /dev/null +++ b/src/core/DSharpPlus.Shared/Results/ExceptionServices/MarshalException.cs @@ -0,0 +1,24 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +#pragma warning disable CA1032 + +using System; +using System.Diagnostics.CodeAnalysis; + +using DSharpPlus.Results.Errors; + +namespace DSharpPlus.Results.ExceptionServices; + +public sealed class MarshalException : Exception +{ + /// + /// Gets the result error this was originally + /// + public required Error Error { get; init; } + + [SetsRequiredMembers] + public MarshalException(Error underlying) : base("Failed to find a matching exception type for this result error.") + => this.Error = underlying; +} diff --git a/src/core/DSharpPlus.Shared/Results/Result.cs b/src/core/DSharpPlus.Shared/Results/Result.cs new file mode 100644 index 0000000000..8c7973a103 --- /dev/null +++ b/src/core/DSharpPlus.Shared/Results/Result.cs @@ -0,0 +1,36 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Diagnostics.CodeAnalysis; + +using DSharpPlus.Results.Errors; + +namespace DSharpPlus.Results; + +/// +/// Represents the success or failure of an operation, and optionally the error returned. +/// +public readonly record struct Result +{ + /// + /// The error this operation returned, if applicable. + /// + public Error? Error { get; init; } + + /// + /// Indicates whether this operation was successful. + /// + [MemberNotNullWhen(false, nameof(Error))] + public bool IsSuccess => this.Error is null; + + /// + /// Constructs a new result from the specified failure case. + /// + /// + public Result(Error error) + => this.Error = error; + + public static implicit operator Result(Error error) + => new(error); +} diff --git a/src/core/DSharpPlus.Shared/Results/Result`1.cs b/src/core/DSharpPlus.Shared/Results/Result`1.cs new file mode 100644 index 0000000000..65b7d0a9e4 --- /dev/null +++ b/src/core/DSharpPlus.Shared/Results/Result`1.cs @@ -0,0 +1,50 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Diagnostics.CodeAnalysis; + +using DSharpPlus.Results.Errors; + +namespace DSharpPlus.Results; + +/// +/// Represents the success or failure of an operation, and the error or value returned as applicable. +/// +public readonly record struct Result +{ + /// + /// The value this operation returned, if applicable. + /// + [AllowNull] + public TValue Value { get; init; } + + /// + /// The error this operation returned, if applicable. + /// + public Error? Error { get; init; } + + /// + /// Indicates whether this operation was successful. + /// + [MemberNotNullWhen(false, nameof(Error))] + public bool IsSuccess => this.Error is null; + + /// + /// Constructs a new result from the specified failure case. + /// + public Result(Error error) + => this.Error = error; + + /// + /// Constructs a new successful result from the specified value. + /// + public Result(TValue value) + => this.Value = value; + + public static implicit operator Result(Error error) + => new(error); + + public static implicit operator Result(TValue value) + => new(value); +} From f6380334b74137596ce98d2332b2c912be5bcfc7 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Wed, 20 Mar 2024 19:06:18 +0100 Subject: [PATCH 285/323] satisfy CA2263 --- .../Serialization/Resolvers/OptionalTypeInfoResolver.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/DSharpPlus.Internal.Models/Serialization/Resolvers/OptionalTypeInfoResolver.cs b/src/core/DSharpPlus.Internal.Models/Serialization/Resolvers/OptionalTypeInfoResolver.cs index c454eb5df4..5a6f76c134 100644 --- a/src/core/DSharpPlus.Internal.Models/Serialization/Resolvers/OptionalTypeInfoResolver.cs +++ b/src/core/DSharpPlus.Internal.Models/Serialization/Resolvers/OptionalTypeInfoResolver.cs @@ -37,7 +37,7 @@ public static class OptionalTypeInfoResolver ( property.PropertyType.GetGenericArguments()[0]! ) - .CreateDelegate(typeof(Func)) + .CreateDelegate>() ); } } From 794a28f2ba96ce7767631d7ee469aa3ecd486444 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Wed, 3 Apr 2024 22:26:26 +0200 Subject: [PATCH 286/323] results prototype --- src/core/DSharpPlus.Shared/Results/Result.cs | 38 ++++++++ .../DSharpPlus.Shared/Results/Result`1.cs | 90 ++++++++++++++++++- 2 files changed, 127 insertions(+), 1 deletion(-) diff --git a/src/core/DSharpPlus.Shared/Results/Result.cs b/src/core/DSharpPlus.Shared/Results/Result.cs index 8c7973a103..570ab9a592 100644 --- a/src/core/DSharpPlus.Shared/Results/Result.cs +++ b/src/core/DSharpPlus.Shared/Results/Result.cs @@ -2,9 +2,12 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +using System; +using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using DSharpPlus.Results.Errors; +using DSharpPlus.Results.ExceptionServices; namespace DSharpPlus.Results; @@ -33,4 +36,39 @@ public Result(Error error) public static implicit operator Result(Error error) => new(error); + + public static implicit operator bool(Result result) + => result.IsSuccess; + + /// + /// Throws the result error as an exception, if applicable. + /// + [DebuggerHidden] + [StackTraceHidden] + public void Expect() + { + if (!this.IsSuccess) + { + throw ExceptionMarshaller.MarshalResultErrorToException(this.Error); + } + } + + /// + /// Throws the result error as an exception according to the provided transform, if applicable. + /// + [DebuggerHidden] + [StackTraceHidden] + public void Expect(Func transform) + { + if (!this.IsSuccess) + { + throw transform(this); + } + } + + /// + /// Transforms the result error according to the provided function, returning either a successful result or the transformed result. + /// + public Result MapError(Func transform) + => this.IsSuccess ? this : new(transform(this.Error)); } diff --git a/src/core/DSharpPlus.Shared/Results/Result`1.cs b/src/core/DSharpPlus.Shared/Results/Result`1.cs index 65b7d0a9e4..e1afe4cade 100644 --- a/src/core/DSharpPlus.Shared/Results/Result`1.cs +++ b/src/core/DSharpPlus.Shared/Results/Result`1.cs @@ -2,9 +2,11 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +using System; +using System.Diagnostics; using System.Diagnostics.CodeAnalysis; - using DSharpPlus.Results.Errors; +using DSharpPlus.Results.ExceptionServices; namespace DSharpPlus.Results; @@ -47,4 +49,90 @@ public static implicit operator Result(Error error) public static implicit operator Result(TValue value) => new(value); + + public static implicit operator bool(Result result) + => result.IsSuccess; + + /// + /// Throws the result error as an exception, if applicable. + /// + [DebuggerHidden] + [StackTraceHidden] + public void Expect() + { + if (!this.IsSuccess) + { + throw ExceptionMarshaller.MarshalResultErrorToException(this.Error); + } + } + + /// + /// Throws the result error as an exception according to the provided transform, if applicable. + /// + [DebuggerHidden] + [StackTraceHidden] + public void Expect(Func, Exception> transform) + { + if (!this.IsSuccess) + { + throw transform(this); + } + } + + /// + /// Unwraps the result, throwing an exception if unsuccessful. + /// + public TValue Unwrap() + { + this.Expect(); + return this.Value; + } + + /// + /// Unwraps the result, returning a provided default value if unsuccessful. + /// + public TValue UnwrapOr(TValue defaultValue) + => this.IsSuccess ? this.Value : defaultValue; + + /// + /// Unwraps the result, returning the default value if unsuccessful. + /// + public TValue? UnwrapOrDefault() + => this.IsSuccess ? this.Value : default; + + /// + /// Unwraps the result, returning the result of evaluating the provided function if unsuccessful. + /// + public TValue UnwrapOrElse(Func, TValue> fallback) + => this.IsSuccess ? this.Value : fallback(this); + + /// + /// Transforms the result value according to the provided function, returning either the transformed result or a failed result. + /// + public Result Map(Func transform) + => this.IsSuccess ? new(transform(this.Value)) : new(this.Error); + + /// + /// Transforms the result error according to the provided function, returning either a successful result or the transformed result. + /// + public Result MapError(Func transform) + => this.IsSuccess ? this : new(transform(this.Error)); + + /// + /// Transforms the result value according to the provided function, returning either the transformed result or the provided default value. + /// + public Result MapOr(Func transform, TResult fallback) + => this.IsSuccess ? new(transform(this.Value)) : new(fallback); + + /// + /// Transforms the result value according to the provided function, returning either the transformed result or a default value. + /// + public Result MapOrDefault(Func transform) + => this.IsSuccess ? new(transform(this.Value)) : new(default(TResult)); + + /// + /// Transforms the result value and error according to the provided functions. + /// + public Result MapOrElse(Func transformValue, Func transformError) + => this.IsSuccess ? new(transformValue(this.Value)) : new(transformError(this.Error)); } From e5e2ad9dfc6fac25ddaa5630e76a0787d7099674 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Thu, 4 Apr 2024 16:15:18 +0200 Subject: [PATCH 287/323] address vam's feedback --- src/core/DSharpPlus.Shared/Results/Result.cs | 8 ++++--- .../DSharpPlus.Shared/Results/Result`1.cs | 24 +++++++++++++++---- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/src/core/DSharpPlus.Shared/Results/Result.cs b/src/core/DSharpPlus.Shared/Results/Result.cs index 570ab9a592..ea08a03d28 100644 --- a/src/core/DSharpPlus.Shared/Results/Result.cs +++ b/src/core/DSharpPlus.Shared/Results/Result.cs @@ -16,10 +16,12 @@ namespace DSharpPlus.Results; /// public readonly record struct Result { + public static Result Success => default; + /// /// The error this operation returned, if applicable. /// - public Error? Error { get; init; } + public Error? Error { get; private init; } /// /// Indicates whether this operation was successful. @@ -58,11 +60,11 @@ public void Expect() /// [DebuggerHidden] [StackTraceHidden] - public void Expect(Func transform) + public void Expect(Func transform) { if (!this.IsSuccess) { - throw transform(this); + throw transform(this.Error); } } diff --git a/src/core/DSharpPlus.Shared/Results/Result`1.cs b/src/core/DSharpPlus.Shared/Results/Result`1.cs index e1afe4cade..7b7cbe696e 100644 --- a/src/core/DSharpPlus.Shared/Results/Result`1.cs +++ b/src/core/DSharpPlus.Shared/Results/Result`1.cs @@ -19,12 +19,12 @@ public readonly record struct Result /// The value this operation returned, if applicable. /// [AllowNull] - public TValue Value { get; init; } + public TValue Value { get; private init; } /// /// The error this operation returned, if applicable. /// - public Error? Error { get; init; } + public Error? Error { get; private init; } /// /// Indicates whether this operation was successful. @@ -71,11 +71,11 @@ public void Expect() /// [DebuggerHidden] [StackTraceHidden] - public void Expect(Func, Exception> transform) + public void Expect(Func transform) { if (!this.IsSuccess) { - throw transform(this); + throw transform(this.Error); } } @@ -135,4 +135,20 @@ public Result MapError(Func transform) /// public Result MapOrElse(Func transformValue, Func transformError) => this.IsSuccess ? new(transformValue(this.Value)) : new(transformError(this.Error)); + +#pragma warning disable CA1000 + + /// + /// Creates a new failed result from the specified error. + /// + public static Result FromError(Error error) => new(error); + + /// + /// Creates a new successful result from the specified value. + /// + /// + /// + public static Result FromSuccess(TValue value) => new(value); + +#pragma warning restore CA1000 } From 0701a4ba72bc38433c5b1d31a423bc02f4713dc7 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Fri, 5 Apr 2024 21:59:12 +0200 Subject: [PATCH 288/323] add error types --- .../Results/Errors/ArgumentError.cs | 41 +++++++++++++++++++ .../Results/Errors/ArgumentNullError.cs | 40 ++++++++++++++++++ .../Results/Errors/ArgumentOutOfRangeError.cs | 40 ++++++++++++++++++ .../Results/Errors/InvalidOperationError.cs | 28 +++++++++++++ 4 files changed, 149 insertions(+) create mode 100644 src/core/DSharpPlus.Shared/Results/Errors/ArgumentError.cs create mode 100644 src/core/DSharpPlus.Shared/Results/Errors/ArgumentNullError.cs create mode 100644 src/core/DSharpPlus.Shared/Results/Errors/ArgumentOutOfRangeError.cs create mode 100644 src/core/DSharpPlus.Shared/Results/Errors/InvalidOperationError.cs diff --git a/src/core/DSharpPlus.Shared/Results/Errors/ArgumentError.cs b/src/core/DSharpPlus.Shared/Results/Errors/ArgumentError.cs new file mode 100644 index 0000000000..e7a4e9cc95 --- /dev/null +++ b/src/core/DSharpPlus.Shared/Results/Errors/ArgumentError.cs @@ -0,0 +1,41 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; + +namespace DSharpPlus.Results.Errors; + +/// +/// An error returned when a provided argument was invalid. +/// +public record ArgumentError : ExceptionError +{ + /// + /// The name of the invalid argument. + /// + public string ArgumentName { get; private protected set; } + + /// + /// Creates a new with the specified message and an unspecified argument name. + /// + public ArgumentError(string message) : base(message) + => this.ArgumentName = "Unspecified."; + + /// + /// Creates a new with the specified message and argument name. + /// + public ArgumentError(string message, string argumentName) : base(message) + => this.ArgumentName = argumentName; + + /// + /// Creates a new from the specified exception. + /// + public ArgumentError(Exception exception) : base(exception) + { + this.Message = exception.Message; + this.ArgumentName = exception is ArgumentException { ParamName: { } argument } ? argument : "Unspecified."; + } + + public override Exception ToException() => new ArgumentException(this.Message, this.ArgumentName); +} diff --git a/src/core/DSharpPlus.Shared/Results/Errors/ArgumentNullError.cs b/src/core/DSharpPlus.Shared/Results/Errors/ArgumentNullError.cs new file mode 100644 index 0000000000..d6f8021d5c --- /dev/null +++ b/src/core/DSharpPlus.Shared/Results/Errors/ArgumentNullError.cs @@ -0,0 +1,40 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; + +namespace DSharpPlus.Results.Errors; + +/// +/// An error returned when a provided argument was null. +/// +public record ArgumentNullError : ArgumentError +{ + /// + /// Creates a new with the default message and specified argument name. + /// + public ArgumentNullError(string argumentName) : base("The provided value must not be null", argumentName) + { + + } + + /// + /// Creates a new with the specified message and argument name. + /// + public ArgumentNullError(string message, string argumentName) : base(message, argumentName) + { + + } + + /// + /// Creates a new from the specified exception. + /// + public ArgumentNullError(Exception exception) : base(exception) + { + this.Message = exception.Message; + this.ArgumentName = exception is ArgumentNullException { ParamName: { } argument } ? argument : "Unspecified."; + } + + public override Exception ToException() => new ArgumentNullException(this.Message, this.ArgumentName); +} diff --git a/src/core/DSharpPlus.Shared/Results/Errors/ArgumentOutOfRangeError.cs b/src/core/DSharpPlus.Shared/Results/Errors/ArgumentOutOfRangeError.cs new file mode 100644 index 0000000000..52f2c7e572 --- /dev/null +++ b/src/core/DSharpPlus.Shared/Results/Errors/ArgumentOutOfRangeError.cs @@ -0,0 +1,40 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; + +namespace DSharpPlus.Results.Errors; + +/// +/// An error returned when a provided argument was null. +/// +public record ArgumentOutOfRangeError : ArgumentError +{ + /// + /// Creates a new with the specified message and an unspecified argument name. + /// + public ArgumentOutOfRangeError(string message) : base(message) + { + + } + + /// + /// Creates a new with the specified message and argument name. + /// + public ArgumentOutOfRangeError(string message, string argumentName) : base(message, argumentName) + { + + } + + /// + /// Creates a new from the specified exception. + /// + public ArgumentOutOfRangeError(Exception exception) : base(exception) + { + this.Message = exception.Message; + this.ArgumentName = exception is ArgumentOutOfRangeException { ParamName: { } argument } ? argument : "Unspecified."; + } + + public override Exception ToException() => new ArgumentOutOfRangeException(this.Message, this.ArgumentName); +} diff --git a/src/core/DSharpPlus.Shared/Results/Errors/InvalidOperationError.cs b/src/core/DSharpPlus.Shared/Results/Errors/InvalidOperationError.cs new file mode 100644 index 0000000000..a4a97ca196 --- /dev/null +++ b/src/core/DSharpPlus.Shared/Results/Errors/InvalidOperationError.cs @@ -0,0 +1,28 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; + +namespace DSharpPlus.Results.Errors; + +/// +/// An error indicating an invalid operation. +/// +public record InvalidOperationError : ExceptionError +{ + /// + /// Creates a new with the specified message. + /// + public InvalidOperationError(string message) : base(message) + { + } + + /// + /// Creates a new from the specified exception. + /// + public InvalidOperationError(Exception exception) : base(exception) + => this.Message = exception.Message; + + public override Exception ToException() => new InvalidOperationException(this.Message); +} From 3916fbff8136fb88ed5eff18f6d40792f2a0cf33 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Fri, 5 Apr 2024 22:13:44 +0200 Subject: [PATCH 289/323] update to in-house results --- Directory.Packages.props | 1 - .../API/IApplicationCommandsRestAPI.cs | 3 +-- .../API/IApplicationRestAPI.cs | 3 +-- .../API/IAuditLogsRestAPI.cs | 3 +-- .../API/IAutoModerationRestAPI.cs | 3 +-- .../API/IChannelRestAPI.cs | 3 +-- .../API/IEmojiRestAPI.cs | 3 +-- .../API/IEntitlementsRestAPI.cs | 2 +- .../API/IGuildRestAPI.cs | 3 +-- .../API/IGuildScheduledEventRestAPI.cs | 2 +- .../API/IGuildTemplateRestAPI.cs | 3 +-- .../API/IInteractionRestAPI.cs | 3 +-- .../API/IInviteRestAPI.cs | 3 +-- .../API/IRoleConnectionsRestAPI.cs | 3 +-- .../API/ISkusRestAPI.cs | 6 ++---- .../API/IStageInstanceRestAPI.cs | 3 +-- .../API/IStickerRestAPI.cs | 6 ++---- .../API/IUserRestAPI.cs | 2 +- .../API/IVoiceRestAPI.cs | 3 +-- .../API/IWebhookRestAPI.cs | 2 +- ...harpPlus.Internal.Abstractions.Rest.csproj | 1 - .../Errors/HttpError.cs | 4 ++-- .../Errors/ValidationError.cs | 4 ++-- .../IRestClient.cs | 2 +- .../API/ApplicationCommandsRestAPI.cs | 20 +++++++------------ .../API/ApplicationRestAPI.cs | 3 +-- .../API/AuditLogsRestAPI.cs | 3 +-- .../API/AutoModerationRestAPI.cs | 3 +-- .../API/ChannelRestAPI.cs | 3 +-- .../API/EmojiRestAPI.cs | 3 +-- .../API/EntitlementsRestAPI.cs | 3 +-- .../API/GuildRestAPI.cs | 3 +-- .../API/GuildScheduledEventRestAPI.cs | 3 +-- .../API/GuildTemplateRestAPI.cs | 3 +-- .../API/InteractionRestAPI.cs | 3 +-- .../API/InviteRestAPI.cs | 3 +-- .../API/RoleConnectionsRestAPI.cs | 3 +-- .../API/SkusRestAPI.cs | 3 +-- .../API/StageInstanceRestAPI.cs | 2 +- .../API/StickerRestAPI.cs | 3 +-- .../API/UserRestAPI.cs | 3 +-- .../API/VoiceRestAPI.cs | 3 +-- .../API/WebhookRestAPI.cs | 3 +-- .../Ratelimiting/IRatelimitRegistry.cs | 2 +- .../Ratelimiting/RatelimitRegistry.cs | 12 +++++------ .../DSharpPlus.Shared/Results/Result`1.cs | 3 +++ ...rpPlus.Extensions.Internal.Builders.csproj | 4 ---- .../Errors/BuilderValidationError.cs | 8 ++++---- .../Interactions/ModalBuilder.cs | 9 +++------ .../Interactions/TextInputComponentBuilder.cs | 6 +++--- .../Messages/EmbedBuilder.cs | 2 +- 51 files changed, 72 insertions(+), 118 deletions(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index 4a27cbcc9f..1fdfa67df5 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -13,7 +13,6 @@ - diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IApplicationCommandsRestAPI.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IApplicationCommandsRestAPI.cs index ad01ea9a8c..83840e6b4f 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IApplicationCommandsRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IApplicationCommandsRestAPI.cs @@ -10,8 +10,7 @@ using DSharpPlus.Internal.Abstractions.Rest.Payloads; using DSharpPlus.Internal.Abstractions.Rest.Queries; using DSharpPlus.Internal.Abstractions.Rest.Responses; - -using Remora.Results; +using DSharpPlus.Results; namespace DSharpPlus.Internal.Abstractions.Rest.API; diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IApplicationRestAPI.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IApplicationRestAPI.cs index 131db88470..fa46a80a44 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IApplicationRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IApplicationRestAPI.cs @@ -7,8 +7,7 @@ using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Internal.Abstractions.Rest.Payloads; - -using Remora.Results; +using DSharpPlus.Results; namespace DSharpPlus.Internal.Abstractions.Rest.API; diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IAuditLogsRestAPI.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IAuditLogsRestAPI.cs index a63586bfea..2719933295 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IAuditLogsRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IAuditLogsRestAPI.cs @@ -7,8 +7,7 @@ using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Internal.Abstractions.Rest.Queries; - -using Remora.Results; +using DSharpPlus.Results; namespace DSharpPlus.Internal.Abstractions.Rest.API; diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IAutoModerationRestAPI.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IAutoModerationRestAPI.cs index 0841c9edb8..65b5f8861d 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IAutoModerationRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IAutoModerationRestAPI.cs @@ -8,8 +8,7 @@ using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Internal.Abstractions.Rest.Payloads; - -using Remora.Results; +using DSharpPlus.Results; namespace DSharpPlus.Internal.Abstractions.Rest.API; diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IChannelRestAPI.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IChannelRestAPI.cs index dbec40f7fa..50dad1636b 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IChannelRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IChannelRestAPI.cs @@ -10,8 +10,7 @@ using DSharpPlus.Internal.Abstractions.Rest.Payloads; using DSharpPlus.Internal.Abstractions.Rest.Queries; using DSharpPlus.Internal.Abstractions.Rest.Responses; - -using Remora.Results; +using DSharpPlus.Results; namespace DSharpPlus.Internal.Abstractions.Rest.API; diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IEmojiRestAPI.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IEmojiRestAPI.cs index 2f5d0dd51c..2a6340a9de 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IEmojiRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IEmojiRestAPI.cs @@ -8,8 +8,7 @@ using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Internal.Abstractions.Rest.Payloads; - -using Remora.Results; +using DSharpPlus.Results; namespace DSharpPlus.Internal.Abstractions.Rest.API; diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IEntitlementsRestAPI.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IEntitlementsRestAPI.cs index c8273c3593..bd34267fd4 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IEntitlementsRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IEntitlementsRestAPI.cs @@ -9,7 +9,7 @@ using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Internal.Abstractions.Rest.Payloads; using DSharpPlus.Internal.Abstractions.Rest.Queries; -using Remora.Results; +using DSharpPlus.Results; namespace DSharpPlus.Internal.Abstractions.Rest.API; diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IGuildRestAPI.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IGuildRestAPI.cs index 0431970b6b..70562f45c8 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IGuildRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IGuildRestAPI.cs @@ -12,8 +12,7 @@ using DSharpPlus.Internal.Abstractions.Rest.Payloads; using DSharpPlus.Internal.Abstractions.Rest.Queries; using DSharpPlus.Internal.Abstractions.Rest.Responses; - -using Remora.Results; +using DSharpPlus.Results; namespace DSharpPlus.Internal.Abstractions.Rest.API; diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IGuildScheduledEventRestAPI.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IGuildScheduledEventRestAPI.cs index 3865b03e8a..ea1c74594e 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IGuildScheduledEventRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IGuildScheduledEventRestAPI.cs @@ -9,7 +9,7 @@ using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Internal.Abstractions.Rest.Payloads; using DSharpPlus.Internal.Abstractions.Rest.Queries; -using Remora.Results; +using DSharpPlus.Results; namespace DSharpPlus.Internal.Abstractions.Rest.API; diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IGuildTemplateRestAPI.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IGuildTemplateRestAPI.cs index a9ca68de0e..6bf8e94682 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IGuildTemplateRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IGuildTemplateRestAPI.cs @@ -7,9 +7,8 @@ using System.Threading.Tasks; using DSharpPlus.Internal.Abstractions.Models; - -using Remora.Results; using DSharpPlus.Internal.Abstractions.Rest.Payloads; +using DSharpPlus.Results; namespace DSharpPlus.Internal.Abstractions.Rest.API; diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IInteractionRestAPI.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IInteractionRestAPI.cs index b63769f73d..51509db56c 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IInteractionRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IInteractionRestAPI.cs @@ -7,8 +7,7 @@ using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Internal.Abstractions.Rest.Payloads; - -using Remora.Results; +using DSharpPlus.Results; namespace DSharpPlus.Internal.Abstractions.Rest.API; diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IInviteRestAPI.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IInviteRestAPI.cs index 46f4119c4d..d90f0d467b 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IInviteRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IInviteRestAPI.cs @@ -7,8 +7,7 @@ using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Internal.Abstractions.Rest.Queries; - -using Remora.Results; +using DSharpPlus.Results; namespace DSharpPlus.Internal.Abstractions.Rest.API; diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IRoleConnectionsRestAPI.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IRoleConnectionsRestAPI.cs index b453f24fe4..062407488c 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IRoleConnectionsRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IRoleConnectionsRestAPI.cs @@ -7,8 +7,7 @@ using System.Threading.Tasks; using DSharpPlus.Internal.Abstractions.Models; - -using Remora.Results; +using DSharpPlus.Results; namespace DSharpPlus.Internal.Abstractions.Rest.API; diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/API/ISkusRestAPI.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/ISkusRestAPI.cs index 5801cf1e77..995ea8aea4 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/API/ISkusRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/ISkusRestAPI.cs @@ -5,11 +5,9 @@ using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; - -using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; - -using Remora.Results; +using DSharpPlus.Internal.Abstractions.Models; +using DSharpPlus.Results; namespace DSharpPlus.Internal.Abstractions.Rest.API; diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IStageInstanceRestAPI.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IStageInstanceRestAPI.cs index 788198d7ea..574cbda68f 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IStageInstanceRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IStageInstanceRestAPI.cs @@ -7,8 +7,7 @@ using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Internal.Abstractions.Rest.Payloads; - -using Remora.Results; +using DSharpPlus.Results; namespace DSharpPlus.Internal.Abstractions.Rest.API; diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IStickerRestAPI.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IStickerRestAPI.cs index 8521f32ac7..ea488a461d 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IStickerRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IStickerRestAPI.cs @@ -5,12 +5,10 @@ using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; - -using Remora.Results; - using DSharpPlus.Internal.Abstractions.Models; -using DSharpPlus.Internal.Abstractions.Rest.Responses; using DSharpPlus.Internal.Abstractions.Rest.Payloads; +using DSharpPlus.Internal.Abstractions.Rest.Responses; +using DSharpPlus.Results; namespace DSharpPlus.Internal.Abstractions.Rest.API; diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IUserRestAPI.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IUserRestAPI.cs index b10246a486..162679cec4 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IUserRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IUserRestAPI.cs @@ -9,7 +9,7 @@ using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Internal.Abstractions.Rest.Payloads; using DSharpPlus.Internal.Abstractions.Rest.Queries; -using Remora.Results; +using DSharpPlus.Results; namespace DSharpPlus.Internal.Abstractions.Rest.API; diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IVoiceRestAPI.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IVoiceRestAPI.cs index 5773577cf3..e382754c7d 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IVoiceRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IVoiceRestAPI.cs @@ -7,8 +7,7 @@ using System.Threading.Tasks; using DSharpPlus.Internal.Abstractions.Models; - -using Remora.Results; +using DSharpPlus.Results; namespace DSharpPlus.Internal.Abstractions.Rest.API; diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IWebhookRestAPI.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IWebhookRestAPI.cs index d4d79acdd0..07e47c5d3c 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IWebhookRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IWebhookRestAPI.cs @@ -9,7 +9,7 @@ using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Internal.Abstractions.Rest.Payloads; using DSharpPlus.Internal.Abstractions.Rest.Queries; -using Remora.Results; +using DSharpPlus.Results; namespace DSharpPlus.Internal.Abstractions.Rest.API; diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/DSharpPlus.Internal.Abstractions.Rest.csproj b/src/core/DSharpPlus.Internal.Abstractions.Rest/DSharpPlus.Internal.Abstractions.Rest.csproj index e2624cdb86..e0b8624597 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/DSharpPlus.Internal.Abstractions.Rest.csproj +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/DSharpPlus.Internal.Abstractions.Rest.csproj @@ -5,7 +5,6 @@ - diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Errors/HttpError.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Errors/HttpError.cs index 7471b27cc2..d7f0e5e72c 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/Errors/HttpError.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Errors/HttpError.cs @@ -4,14 +4,14 @@ using System.Net; -using Remora.Results; +using DSharpPlus.Results.Errors; namespace DSharpPlus.Internal.Abstractions.Rest.Errors; /// /// Represents a HTTP error returned by an API call. /// -public sealed record HttpError : ResultError +public sealed record HttpError : Error { /// /// The encountered status code. diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Errors/ValidationError.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Errors/ValidationError.cs index c8f060728c..e742d53fcb 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/Errors/ValidationError.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Errors/ValidationError.cs @@ -2,7 +2,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using Remora.Results; +using DSharpPlus.Results.Errors; namespace DSharpPlus.Internal.Abstractions.Rest.Errors; @@ -10,4 +10,4 @@ namespace DSharpPlus.Internal.Abstractions.Rest.Errors; /// Represents an error encountered during parameter validation. /// /// The human-readable error message. -public record ValidationError(string message) : ResultError(message); +public record ValidationError(string message) : Error(message); diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/IRestClient.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/IRestClient.cs index 9066d1b98a..1b7d2b8a5d 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/IRestClient.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/IRestClient.cs @@ -7,7 +7,7 @@ using System.Threading; using System.Threading.Tasks; -using Remora.Results; +using DSharpPlus.Results; namespace DSharpPlus.Internal.Abstractions.Rest; diff --git a/src/core/DSharpPlus.Internal.Rest/API/ApplicationCommandsRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/ApplicationCommandsRestAPI.cs index 0a8eb5355d..65defdf3e2 100644 --- a/src/core/DSharpPlus.Internal.Rest/API/ApplicationCommandsRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Rest/API/ApplicationCommandsRestAPI.cs @@ -9,7 +9,6 @@ using System.Net.Http; using System.Threading; using System.Threading.Tasks; - using DSharpPlus.Entities; using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Internal.Abstractions.Rest; @@ -18,10 +17,9 @@ using DSharpPlus.Internal.Abstractions.Rest.Payloads; using DSharpPlus.Internal.Abstractions.Rest.Queries; using DSharpPlus.Internal.Abstractions.Rest.Responses; +using DSharpPlus.Results; using DSharpPlus.Serialization; -using Remora.Results; - namespace DSharpPlus.Internal.Rest.API; /// @@ -177,9 +175,9 @@ public async ValueTask> CreateGlobalApp { CreatedCommand = serializationService.DeserializeModel ( - await response.Entity.Content.ReadAsByteArrayAsync(ct) + await response.Value.Content.ReadAsByteArrayAsync(ct) ), - IsNewlyCreated = response.Entity.StatusCode == HttpStatusCode.Created + IsNewlyCreated = response.Value.StatusCode == HttpStatusCode.Created }; } @@ -232,9 +230,9 @@ public async ValueTask> CreateGuildAppl { CreatedCommand = serializationService.DeserializeModel ( - await response.Entity.Content.ReadAsByteArrayAsync(ct) + await response.Value.Content.ReadAsByteArrayAsync(ct) ), - IsNewlyCreated = response.Entity.StatusCode == HttpStatusCode.Created + IsNewlyCreated = response.Value.StatusCode == HttpStatusCode.Created }; } @@ -247,7 +245,7 @@ public async ValueTask DeleteGlobalApplicationCommandAsync CancellationToken ct = default ) { - Result response = await restClient.ExecuteRequestAsync + return await restClient.ExecuteRequestAsync ( HttpMethod.Delete, $"applications/{applicationId}/commands/{commandId}", @@ -255,8 +253,6 @@ public async ValueTask DeleteGlobalApplicationCommandAsync info, ct ); - - return (Result)response; } /// @@ -269,7 +265,7 @@ public async ValueTask DeleteGuildApplicationCommandAsync CancellationToken ct = default ) { - Result response = await restClient.ExecuteRequestAsync + return await restClient.ExecuteRequestAsync ( HttpMethod.Delete, $"applications/{applicationId}/guilds/{guildId}/commands/{commandId}", @@ -277,8 +273,6 @@ public async ValueTask DeleteGuildApplicationCommandAsync info, ct ); - - return (Result)response; } /// diff --git a/src/core/DSharpPlus.Internal.Rest/API/ApplicationRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/ApplicationRestAPI.cs index aa5eee5c2d..3e61573e56 100644 --- a/src/core/DSharpPlus.Internal.Rest/API/ApplicationRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Rest/API/ApplicationRestAPI.cs @@ -13,8 +13,7 @@ using DSharpPlus.Internal.Abstractions.Rest.API; using DSharpPlus.Internal.Abstractions.Rest.Errors; using DSharpPlus.Internal.Abstractions.Rest.Payloads; - -using Remora.Results; +using DSharpPlus.Results; namespace DSharpPlus.Internal.Rest.API; diff --git a/src/core/DSharpPlus.Internal.Rest/API/AuditLogsRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/AuditLogsRestAPI.cs index 849fcd69db..e78878834e 100644 --- a/src/core/DSharpPlus.Internal.Rest/API/AuditLogsRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Rest/API/AuditLogsRestAPI.cs @@ -13,8 +13,7 @@ using DSharpPlus.Internal.Abstractions.Rest.Errors; using DSharpPlus.Internal.Abstractions.Rest.Queries; using DSharpPlus.Internal.Rest.Ratelimiting; - -using Remora.Results; +using DSharpPlus.Results; namespace DSharpPlus.Internal.Rest.API; diff --git a/src/core/DSharpPlus.Internal.Rest/API/AutoModerationRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/AutoModerationRestAPI.cs index 4a30596b3f..8bf5073ac2 100644 --- a/src/core/DSharpPlus.Internal.Rest/API/AutoModerationRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Rest/API/AutoModerationRestAPI.cs @@ -15,8 +15,7 @@ using DSharpPlus.Internal.Abstractions.Rest.Errors; using DSharpPlus.Internal.Abstractions.Rest.Payloads; using DSharpPlus.Internal.Rest.Ratelimiting; - -using Remora.Results; +using DSharpPlus.Results; namespace DSharpPlus.Internal.Rest.API; diff --git a/src/core/DSharpPlus.Internal.Rest/API/ChannelRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/ChannelRestAPI.cs index 4a7cb53afd..3061cb4929 100644 --- a/src/core/DSharpPlus.Internal.Rest/API/ChannelRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Rest/API/ChannelRestAPI.cs @@ -19,8 +19,7 @@ using DSharpPlus.Internal.Abstractions.Rest.Queries; using DSharpPlus.Internal.Abstractions.Rest.Responses; using DSharpPlus.Internal.Rest.Ratelimiting; - -using Remora.Results; +using DSharpPlus.Results; namespace DSharpPlus.Internal.Rest.API; diff --git a/src/core/DSharpPlus.Internal.Rest/API/EmojiRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/EmojiRestAPI.cs index 72889cdcde..01e819ab0e 100644 --- a/src/core/DSharpPlus.Internal.Rest/API/EmojiRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Rest/API/EmojiRestAPI.cs @@ -11,8 +11,7 @@ using DSharpPlus.Internal.Abstractions.Rest; using DSharpPlus.Internal.Abstractions.Rest.API; using DSharpPlus.Internal.Abstractions.Rest.Payloads; - -using Remora.Results; +using DSharpPlus.Results; namespace DSharpPlus.Internal.Rest.API; diff --git a/src/core/DSharpPlus.Internal.Rest/API/EntitlementsRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/EntitlementsRestAPI.cs index 7c43520229..5bb9d21aa6 100644 --- a/src/core/DSharpPlus.Internal.Rest/API/EntitlementsRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Rest/API/EntitlementsRestAPI.cs @@ -14,8 +14,7 @@ using DSharpPlus.Internal.Abstractions.Rest.Errors; using DSharpPlus.Internal.Abstractions.Rest.Payloads; using DSharpPlus.Internal.Abstractions.Rest.Queries; - -using Remora.Results; +using DSharpPlus.Results; namespace DSharpPlus.Internal.Rest.API; diff --git a/src/core/DSharpPlus.Internal.Rest/API/GuildRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/GuildRestAPI.cs index 49e250dbdb..641116742f 100644 --- a/src/core/DSharpPlus.Internal.Rest/API/GuildRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Rest/API/GuildRestAPI.cs @@ -20,8 +20,7 @@ using DSharpPlus.Internal.Abstractions.Rest.Queries; using DSharpPlus.Internal.Abstractions.Rest.Responses; using DSharpPlus.Internal.Rest.Ratelimiting; - -using Remora.Results; +using DSharpPlus.Results; namespace DSharpPlus.Internal.Rest.API; diff --git a/src/core/DSharpPlus.Internal.Rest/API/GuildScheduledEventRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/GuildScheduledEventRestAPI.cs index 00d84b3c17..fb1495a5ee 100644 --- a/src/core/DSharpPlus.Internal.Rest/API/GuildScheduledEventRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Rest/API/GuildScheduledEventRestAPI.cs @@ -15,8 +15,7 @@ using DSharpPlus.Internal.Abstractions.Rest.Payloads; using DSharpPlus.Internal.Abstractions.Rest.Queries; using DSharpPlus.Internal.Rest.Ratelimiting; - -using Remora.Results; +using DSharpPlus.Results; namespace DSharpPlus.Internal.Rest.API; diff --git a/src/core/DSharpPlus.Internal.Rest/API/GuildTemplateRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/GuildTemplateRestAPI.cs index b575c78028..efe75b29bf 100644 --- a/src/core/DSharpPlus.Internal.Rest/API/GuildTemplateRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Rest/API/GuildTemplateRestAPI.cs @@ -15,8 +15,7 @@ using DSharpPlus.Internal.Abstractions.Rest.Errors; using DSharpPlus.Internal.Abstractions.Rest.Payloads; using DSharpPlus.Internal.Rest.Ratelimiting; - -using Remora.Results; +using DSharpPlus.Results; namespace DSharpPlus.Internal.Rest.API; diff --git a/src/core/DSharpPlus.Internal.Rest/API/InteractionRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/InteractionRestAPI.cs index 3eef3fa900..4af05ea91c 100644 --- a/src/core/DSharpPlus.Internal.Rest/API/InteractionRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Rest/API/InteractionRestAPI.cs @@ -17,8 +17,7 @@ using DSharpPlus.Internal.Abstractions.Rest.Errors; using DSharpPlus.Internal.Abstractions.Rest.Payloads; using DSharpPlus.Internal.Rest.Ratelimiting; - -using Remora.Results; +using DSharpPlus.Results; namespace DSharpPlus.Internal.Rest.API; diff --git a/src/core/DSharpPlus.Internal.Rest/API/InviteRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/InviteRestAPI.cs index 1e6531c38d..2a944e63df 100644 --- a/src/core/DSharpPlus.Internal.Rest/API/InviteRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Rest/API/InviteRestAPI.cs @@ -10,8 +10,7 @@ using DSharpPlus.Internal.Abstractions.Rest; using DSharpPlus.Internal.Abstractions.Rest.API; using DSharpPlus.Internal.Abstractions.Rest.Queries; - -using Remora.Results; +using DSharpPlus.Results; namespace DSharpPlus.Internal.Rest.API; diff --git a/src/core/DSharpPlus.Internal.Rest/API/RoleConnectionsRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/RoleConnectionsRestAPI.cs index fd8c34f569..cc8d9e518c 100644 --- a/src/core/DSharpPlus.Internal.Rest/API/RoleConnectionsRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Rest/API/RoleConnectionsRestAPI.cs @@ -13,8 +13,7 @@ using DSharpPlus.Internal.Abstractions.Rest; using DSharpPlus.Internal.Abstractions.Rest.API; using DSharpPlus.Internal.Abstractions.Rest.Errors; - -using Remora.Results; +using DSharpPlus.Results; namespace DSharpPlus.Internal.Rest.API; diff --git a/src/core/DSharpPlus.Internal.Rest/API/SkusRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/SkusRestAPI.cs index 30682f0b2f..d1e28cdd08 100644 --- a/src/core/DSharpPlus.Internal.Rest/API/SkusRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Rest/API/SkusRestAPI.cs @@ -10,8 +10,7 @@ using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Internal.Abstractions.Rest; using DSharpPlus.Internal.Abstractions.Rest.API; - -using Remora.Results; +using DSharpPlus.Results; namespace DSharpPlus.Internal.Rest.API; diff --git a/src/core/DSharpPlus.Internal.Rest/API/StageInstanceRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/StageInstanceRestAPI.cs index 141e61c7cb..34ec5d34bf 100644 --- a/src/core/DSharpPlus.Internal.Rest/API/StageInstanceRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Rest/API/StageInstanceRestAPI.cs @@ -13,7 +13,7 @@ using DSharpPlus.Internal.Abstractions.Rest.Errors; using DSharpPlus.Internal.Abstractions.Rest.Payloads; using DSharpPlus.Internal.Rest.Ratelimiting; -using Remora.Results; +using DSharpPlus.Results; namespace DSharpPlus.Internal.Rest.API; diff --git a/src/core/DSharpPlus.Internal.Rest/API/StickerRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/StickerRestAPI.cs index cb800a06f3..6d271781c5 100644 --- a/src/core/DSharpPlus.Internal.Rest/API/StickerRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Rest/API/StickerRestAPI.cs @@ -16,8 +16,7 @@ using DSharpPlus.Internal.Abstractions.Rest.Payloads; using DSharpPlus.Internal.Abstractions.Rest.Responses; using DSharpPlus.Internal.Rest.Ratelimiting; - -using Remora.Results; +using DSharpPlus.Results; namespace DSharpPlus.Internal.Rest.API; diff --git a/src/core/DSharpPlus.Internal.Rest/API/UserRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/UserRestAPI.cs index 4602ba9ee1..a522d89d32 100644 --- a/src/core/DSharpPlus.Internal.Rest/API/UserRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Rest/API/UserRestAPI.cs @@ -17,8 +17,7 @@ using DSharpPlus.Internal.Abstractions.Rest.Payloads; using DSharpPlus.Internal.Abstractions.Rest.Queries; using DSharpPlus.Internal.Rest.Ratelimiting; - -using Remora.Results; +using DSharpPlus.Results; namespace DSharpPlus.Internal.Rest.API; diff --git a/src/core/DSharpPlus.Internal.Rest/API/VoiceRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/VoiceRestAPI.cs index ea66310623..bfa930c76d 100644 --- a/src/core/DSharpPlus.Internal.Rest/API/VoiceRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Rest/API/VoiceRestAPI.cs @@ -10,8 +10,7 @@ using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Internal.Abstractions.Rest; using DSharpPlus.Internal.Abstractions.Rest.API; - -using Remora.Results; +using DSharpPlus.Results; namespace DSharpPlus.Internal.Rest.API; diff --git a/src/core/DSharpPlus.Internal.Rest/API/WebhookRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/WebhookRestAPI.cs index 8c8c6869fb..1757a4f4b6 100644 --- a/src/core/DSharpPlus.Internal.Rest/API/WebhookRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Rest/API/WebhookRestAPI.cs @@ -17,8 +17,7 @@ using DSharpPlus.Internal.Abstractions.Rest.Payloads; using DSharpPlus.Internal.Abstractions.Rest.Queries; using DSharpPlus.Internal.Rest.Ratelimiting; - -using Remora.Results; +using DSharpPlus.Results; namespace DSharpPlus.Internal.Rest.API; diff --git a/src/core/DSharpPlus.Internal.Rest/Ratelimiting/IRatelimitRegistry.cs b/src/core/DSharpPlus.Internal.Rest/Ratelimiting/IRatelimitRegistry.cs index 4e1dcb0163..d977ab64a4 100644 --- a/src/core/DSharpPlus.Internal.Rest/Ratelimiting/IRatelimitRegistry.cs +++ b/src/core/DSharpPlus.Internal.Rest/Ratelimiting/IRatelimitRegistry.cs @@ -4,7 +4,7 @@ using System.Net.Http; -using Remora.Results; +using DSharpPlus.Results; namespace DSharpPlus.Internal.Rest.Ratelimiting; diff --git a/src/core/DSharpPlus.Internal.Rest/Ratelimiting/RatelimitRegistry.cs b/src/core/DSharpPlus.Internal.Rest/Ratelimiting/RatelimitRegistry.cs index 42c9ae2db3..04a12a12ca 100644 --- a/src/core/DSharpPlus.Internal.Rest/Ratelimiting/RatelimitRegistry.cs +++ b/src/core/DSharpPlus.Internal.Rest/Ratelimiting/RatelimitRegistry.cs @@ -15,6 +15,8 @@ using System.Threading.Tasks; using DSharpPlus.Internal.Abstractions.Rest; +using DSharpPlus.Results; +using DSharpPlus.Results.Errors; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; @@ -24,8 +26,6 @@ using Polly; -using Remora.Results; - namespace DSharpPlus.Internal.Rest.Ratelimiting; /// @@ -214,7 +214,7 @@ public Result UpdateRatelimit(HttpRequestMessage request, HttpResponseMessage re && !double.TryParse(rawReset?.SingleOrDefault(), out reset) ) { - return new ArgumentInvalidError("response.Headers", "Failed to parse an X-RateLimit-Reset header from the response."); + return new ArgumentError("response.Headers", "Failed to parse an X-RateLimit-Reset header from the response."); } Context? context = request.GetPolicyExecutionContext(); @@ -249,7 +249,7 @@ context is not null // update the bucket, first by extracting the other relevant information... if (!headers.TryGetValues("X-RateLimit-Bucket", out IEnumerable? rawBucket)) { - return new ArgumentInvalidError("response.Headers", "Failed to parse an X-RateLimit-Bucket header from the response."); + return new ArgumentError("response.Headers", "Failed to parse an X-RateLimit-Bucket header from the response."); } string hash = rawBucket.Single(); @@ -261,7 +261,7 @@ context is not null && !short.TryParse(rawLimit?.SingleOrDefault(), out limit) ) { - return new ArgumentInvalidError("response.Headers", "Failed to parse an X-RateLimit-Limit header from the response."); + return new ArgumentError("response.Headers", "Failed to parse an X-RateLimit-Limit header from the response."); } if @@ -270,7 +270,7 @@ context is not null && !short.TryParse(rawRemaining?.SingleOrDefault(), out remaining) ) { - return new ArgumentInvalidError("response.Headers", "Failed to parse an X-RateLimit-Remaining header from the response."); + return new ArgumentError("response.Headers", "Failed to parse an X-RateLimit-Remaining header from the response."); } this.dirty = true; diff --git a/src/core/DSharpPlus.Shared/Results/Result`1.cs b/src/core/DSharpPlus.Shared/Results/Result`1.cs index 7b7cbe696e..7e41233eb1 100644 --- a/src/core/DSharpPlus.Shared/Results/Result`1.cs +++ b/src/core/DSharpPlus.Shared/Results/Result`1.cs @@ -53,6 +53,9 @@ public static implicit operator Result(TValue value) public static implicit operator bool(Result result) => result.IsSuccess; + public static implicit operator Result(Result result) + => result.IsSuccess ? Result.Success : new(result.Error); + /// /// Throws the result error as an exception, if applicable. /// diff --git a/src/extensions/DSharpPlus.Extensions.Internal.Builders/DSharpPlus.Extensions.Internal.Builders.csproj b/src/extensions/DSharpPlus.Extensions.Internal.Builders/DSharpPlus.Extensions.Internal.Builders.csproj index 556c492afe..69875d9aca 100644 --- a/src/extensions/DSharpPlus.Extensions.Internal.Builders/DSharpPlus.Extensions.Internal.Builders.csproj +++ b/src/extensions/DSharpPlus.Extensions.Internal.Builders/DSharpPlus.Extensions.Internal.Builders.csproj @@ -8,10 +8,6 @@ Library - - - - diff --git a/src/extensions/DSharpPlus.Extensions.Internal.Builders/Errors/BuilderValidationError.cs b/src/extensions/DSharpPlus.Extensions.Internal.Builders/Errors/BuilderValidationError.cs index d80f7b0d45..1d8e95b550 100644 --- a/src/extensions/DSharpPlus.Extensions.Internal.Builders/Errors/BuilderValidationError.cs +++ b/src/extensions/DSharpPlus.Extensions.Internal.Builders/Errors/BuilderValidationError.cs @@ -7,14 +7,14 @@ using System.Linq; using System.Text; -using Remora.Results; +using DSharpPlus.Results.Errors; namespace DSharpPlus.Extensions.Internal.Builders.Errors; /// /// Represents an error encountered when attempting to validate a builder. /// -public record BuilderValidationError : ResultError +public record BuilderValidationError : Error { /// /// If this error was caused by any specific parameters, contains the names of the invalid parameters. @@ -27,7 +27,7 @@ public record BuilderValidationError : ResultError /// The human-readable error message. /// If applicable, the names of parameters that failed validation. public BuilderValidationError(string message, params (string Key, string Value)[] parameters) - : base(message) + : base(message) { if (parameters.Length == 0) { @@ -55,4 +55,4 @@ public override string ToString() return builder.ToString(); } -} \ No newline at end of file +} diff --git a/src/extensions/DSharpPlus.Extensions.Internal.Builders/Interactions/ModalBuilder.cs b/src/extensions/DSharpPlus.Extensions.Internal.Builders/Interactions/ModalBuilder.cs index 6c33dd8cef..143f1e0332 100644 --- a/src/extensions/DSharpPlus.Extensions.Internal.Builders/Interactions/ModalBuilder.cs +++ b/src/extensions/DSharpPlus.Extensions.Internal.Builders/Interactions/ModalBuilder.cs @@ -7,16 +7,13 @@ using System; using System.Collections.Generic; using System.Linq; - using DSharpPlus.Entities; using DSharpPlus.Extensions.Internal.Builders.Errors; using DSharpPlus.Extensions.Internal.Builders.Implementations; using DSharpPlus.Internal.Abstractions.Models; - +using DSharpPlus.Results; using OneOf; -using Remora.Results; - namespace DSharpPlus.Extensions.Internal.Builders.Interactions; /// @@ -68,7 +65,7 @@ public static ref ModalBuilder AddComponent(ref this ModalBuilder builder, IText return ref builder; } - builder.Components = [..builder.Components, component]; + builder.Components = [.. builder.Components, component]; return ref builder; } @@ -136,7 +133,7 @@ public static IInteractionResponse Build(ref this ModalBuilder builder) CustomId = builder.CustomId, Components = builder.Components.Select ( - x => + x => { return new BuiltActionRowComponent { diff --git a/src/extensions/DSharpPlus.Extensions.Internal.Builders/Interactions/TextInputComponentBuilder.cs b/src/extensions/DSharpPlus.Extensions.Internal.Builders/Interactions/TextInputComponentBuilder.cs index d254fe17f0..9af176670b 100644 --- a/src/extensions/DSharpPlus.Extensions.Internal.Builders/Interactions/TextInputComponentBuilder.cs +++ b/src/extensions/DSharpPlus.Extensions.Internal.Builders/Interactions/TextInputComponentBuilder.cs @@ -12,7 +12,7 @@ using DSharpPlus.Extensions.Internal.Builders.Implementations; using DSharpPlus.Internal.Abstractions.Models; -using Remora.Results; +using DSharpPlus.Results; namespace DSharpPlus.Extensions.Internal.Builders.Interactions; @@ -54,7 +54,7 @@ public static class TextInputComponentBuilderExtensions /// The component builder for chaining. public static ref TextInputComponentBuilder WithCustomId ( - ref this TextInputComponentBuilder builder, + ref this TextInputComponentBuilder builder, string customId ) { @@ -246,4 +246,4 @@ public static ITextInputComponent Build(ref this TextInputComponentBuilder build Placeholder = builder.Placeholder }; } -} \ No newline at end of file +} diff --git a/src/extensions/DSharpPlus.Extensions.Internal.Builders/Messages/EmbedBuilder.cs b/src/extensions/DSharpPlus.Extensions.Internal.Builders/Messages/EmbedBuilder.cs index 26baf229cf..b8cbe093c2 100644 --- a/src/extensions/DSharpPlus.Extensions.Internal.Builders/Messages/EmbedBuilder.cs +++ b/src/extensions/DSharpPlus.Extensions.Internal.Builders/Messages/EmbedBuilder.cs @@ -11,7 +11,7 @@ using DSharpPlus.Extensions.Internal.Builders.Implementations; using DSharpPlus.Internal.Abstractions.Models; -using Remora.Results; +using DSharpPlus.Results; namespace DSharpPlus.Extensions.Internal.Builders.Messages; From 6a1c67a70757cf3e5823678757fb84413af2b395 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Fri, 5 Apr 2024 22:26:33 +0200 Subject: [PATCH 290/323] implement support for bulk bans --- .../API/IGuildRestAPI.cs | 20 ++++++++++++ .../Payloads/Guilds/IBulkGuildBanPayload.cs | 24 ++++++++++++++ .../Responses/BulkGuildBanResponse.cs | 23 +++++++++++++ .../API/GuildRestAPI.cs | 32 +++++++++++++++++++ .../Payloads/Guilds/BulkGuildBanPayload.cs | 19 +++++++++++ 5 files changed, 118 insertions(+) create mode 100644 src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Guilds/IBulkGuildBanPayload.cs create mode 100644 src/core/DSharpPlus.Internal.Abstractions.Rest/Responses/BulkGuildBanResponse.cs create mode 100644 src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/BulkGuildBanPayload.cs diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IGuildRestAPI.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IGuildRestAPI.cs index 70562f45c8..0e67705e22 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IGuildRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IGuildRestAPI.cs @@ -387,6 +387,26 @@ public ValueTask RemoveGuildBanAsync CancellationToken ct = default ); + /// + /// Bans up to 200 users from the given guild. + /// + /// The snowflake identifier of the guild in question. + /// + /// The snowflake identifiers of the users to ban, and the amount of seconds to delete messages from. + /// + /// An optional audit log reason for the bans. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + /// The snowflake identifiers of users that were banned and users that could not be banned. + public ValueTask> BulkGuildBanAsync + ( + Snowflake guildId, + IBulkGuildBanPayload payload, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ); + /// /// Fetches the role list of the specified guild. /// diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Guilds/IBulkGuildBanPayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Guilds/IBulkGuildBanPayload.cs new file mode 100644 index 0000000000..ff5b2fbf10 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Guilds/IBulkGuildBanPayload.cs @@ -0,0 +1,24 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +namespace DSharpPlus.Internal.Abstractions.Rest.Payloads; + +/// +/// Represents a payload to POST /guilds/:guild-id/bulk-ban. +/// +public interface IBulkGuildBanPayload +{ + /// + /// The snowflake identifiers of users to bulk ban. + /// + public IReadOnlyList UserIds { get; } + + /// + /// If any of the users have sent messages in the specified amount of seconds, these messages will be deleted if the + /// ban succeeds. + /// + public Optional DeleteMessageSeconds { get; } +} diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Responses/BulkGuildBanResponse.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Responses/BulkGuildBanResponse.cs new file mode 100644 index 0000000000..cfcfdac27b --- /dev/null +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Responses/BulkGuildBanResponse.cs @@ -0,0 +1,23 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +namespace DSharpPlus.Internal.Abstractions.Rest.Responses; + +/// +/// Represents a response from POST /guilds/:guild-id/bulk-ban. +/// +public readonly record struct BulkGuildBanResponse +{ + /// + /// The snowflakes of users that were successfully banned. + /// + public required IReadOnlyList BannedUsers { get; init; } + + /// + /// The snowflakes of users that could not be banned. + /// + public required IReadOnlyList FailedUsers { get; init; } +} diff --git a/src/core/DSharpPlus.Internal.Rest/API/GuildRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/GuildRestAPI.cs index 641116742f..4256369b48 100644 --- a/src/core/DSharpPlus.Internal.Rest/API/GuildRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Rest/API/GuildRestAPI.cs @@ -1142,4 +1142,36 @@ public async ValueTask>> SearchGuildMembersAs ct ); } + + /// + public async ValueTask> BulkGuildBanAsync + ( + Snowflake guildId, + IBulkGuildBanPayload payload, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ) + { + if (payload.DeleteMessageSeconds is { HasValue: true, Value: < 0 or > 604800 }) + { + return new ValidationError("The seconds to delete messages from must be between 0 and 604800, or 7 days."); + } + + if (payload.UserIds.Count > 200) + { + return new ValidationError("Up to 200 users may be bulk-banned at once."); + } + + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Post, + $"guilds/{guildId}/bulk-ban", + b => b.WithSimpleRoute(TopLevelResource.Guild, guildId) + .WithPayload(payload) + .WithAuditLogReason(reason), + info, + ct + ); + } } diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/BulkGuildBanPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/BulkGuildBanPayload.cs new file mode 100644 index 0000000000..9d3fb59eea --- /dev/null +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/BulkGuildBanPayload.cs @@ -0,0 +1,19 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Internal.Abstractions.Rest.Payloads; + +namespace DSharpPlus.Internal.Rest.Payloads; + +/// +public sealed record BulkGuildBanPayload : IBulkGuildBanPayload +{ + /// + public required IReadOnlyList UserIds { get; init; } + + /// + public Optional DeleteMessageSeconds { get; init; } +} From 65d66bf8225257d08e61819d03b9d62aaac6658e Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sat, 6 Apr 2024 15:09:09 +0200 Subject: [PATCH 291/323] support user-installable apps --- .../IApplicationCommand.cs | 16 ++- ...ApplicationIntegrationTypeConfiguration.cs | 16 +++ .../Applications/IInstallParameters.cs | 4 +- .../Applications/IPartialApplication.cs | 5 + .../Channels/IMessageInteractionMetadata.cs | 51 ++++++++++ .../Channels/IPartialMessage.cs | 2 +- .../Interactions/IInteraction.cs | 12 ++- .../Interactions/IMessageInteraction.cs | 38 -------- .../ICreateGlobalApplicationCommandPayload.cs | 19 ++-- .../IEditGlobalApplicationCommandPayload.cs | 17 +++- .../ApplicationCommands/ApplicationCommand.cs | 9 +- .../Applications/Application.cs | 5 +- ...ApplicationIntegrationTypeConfiguration.cs | 14 +++ .../Applications/PartialApplication.cs | 5 +- .../Channels/Message.cs | 4 +- .../Channels/MessageInteractionMetadata.cs | 35 +++++++ .../Channels/PartialMessage.cs | 4 +- .../Extensions/ServiceCollectionExtensions.cs | 4 +- .../Interactions/Interaction.cs | 10 +- .../Interactions/MessageInteraction.cs | 27 ------ .../ApplicationIntegrationTypeKeyConverter.cs | 74 ++++++++++++++ .../CreateGlobalApplicationCommandPayload.cs | 11 ++- .../EditGlobalApplicationCommandPayload.cs | 11 ++- .../DiscordApplicationIntegrationType.cs | 21 ++++ .../DiscordInteractionContextType.cs | 26 +++++ .../ApplicationIntegrationTypeKeyTests.cs | 97 +++++++++++++++++++ 26 files changed, 432 insertions(+), 105 deletions(-) create mode 100644 src/core/DSharpPlus.Internal.Abstractions.Models/Applications/IApplicationIntegrationTypeConfiguration.cs create mode 100644 src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IMessageInteractionMetadata.cs delete mode 100644 src/core/DSharpPlus.Internal.Abstractions.Models/Interactions/IMessageInteraction.cs create mode 100644 src/core/DSharpPlus.Internal.Models/Applications/ApplicationIntegrationTypeConfiguration.cs create mode 100644 src/core/DSharpPlus.Internal.Models/Channels/MessageInteractionMetadata.cs delete mode 100644 src/core/DSharpPlus.Internal.Models/Interactions/MessageInteraction.cs create mode 100644 src/core/DSharpPlus.Internal.Models/Serialization/Converters/ApplicationIntegrationTypeKeyConverter.cs create mode 100644 src/core/DSharpPlus.Shared/Entities/Applications/DiscordApplicationIntegrationType.cs create mode 100644 src/core/DSharpPlus.Shared/Entities/Interactions/DiscordInteractionContextType.cs create mode 100644 tests/core/DSharpPlus.Internal.Models.Tests/Converters/ApplicationIntegrationTypeKeyTests.cs diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/ApplicationCommands/IApplicationCommand.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/ApplicationCommands/IApplicationCommand.cs index 592e3bfae3..4237c906c1 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Models/ApplicationCommands/IApplicationCommand.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/ApplicationCommands/IApplicationCommand.cs @@ -67,15 +67,21 @@ public interface IApplicationCommand public DiscordPermissions? DefaultMemberPermissions { get; } /// - /// Indicates whether this command is available in DMs with the app. This is only applicable - /// to globally-scoped commands. + /// Indicates whether this command is age-restricted. /// - public Optional DmPermission { get; } + public Optional Nsfw { get; } /// - /// Indicates whether this command is age-restricted. + /// Specifies installation contexts where this command is available; only for globally-scoped commands. Defaults to + /// . /// - public Optional Nsfw { get; } + public Optional> IntegrationTypes { get; } + + /// + /// Specifies contexts where this command can be used; only for globally-scoped commands. Defaults to including all + /// context types. + /// + public Optional?> Contexts { get; } /// /// An autoincrementing version identifier updated during substantial changes. diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/Applications/IApplicationIntegrationTypeConfiguration.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Applications/IApplicationIntegrationTypeConfiguration.cs new file mode 100644 index 0000000000..8198529b53 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Applications/IApplicationIntegrationTypeConfiguration.cs @@ -0,0 +1,16 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Internal.Abstractions.Models; + +/// +/// Specifies the default scopes and permissions for a given application. +/// +public interface IApplicationIntegrationTypeConfiguration +{ + /// + /// The installation parameters for each context's default in-app installation link. + /// + public Optional Oauth2InstallParams { get; } +} diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/Applications/IInstallParameters.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Applications/IInstallParameters.cs index 4e0fc19fbe..2718eddf53 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Models/Applications/IInstallParameters.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Applications/IInstallParameters.cs @@ -14,12 +14,12 @@ namespace DSharpPlus.Internal.Abstractions.Models; public interface IInstallParameters { /// - /// The OAuth2 scopes to add the application to the server with. + /// The OAuth2 scopes to add the application to the present context with. /// public IReadOnlyList Scopes { get; } /// - /// The permissions to request for the bot role. + /// The permissions to request for the present context. /// public DiscordPermissions Permissions { get; } } diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/Applications/IPartialApplication.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Applications/IPartialApplication.cs index 1a225aef3a..82fc0a6aed 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Models/Applications/IPartialApplication.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Applications/IPartialApplication.cs @@ -140,6 +140,11 @@ public interface IPartialApplication /// public Optional InstallParams { get; } + /// + /// The default scopes and permissions for each supported installation context. + /// + public Optional> IntegrationTypesConfig { get; } + /// /// The default custom authorization link for this application, if enabled. /// diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IMessageInteractionMetadata.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IMessageInteractionMetadata.cs new file mode 100644 index 0000000000..c5f1e30bf3 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IMessageInteractionMetadata.cs @@ -0,0 +1,51 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Entities; + +namespace DSharpPlus.Internal.Abstractions.Models; + +/// +/// Represents metadata about an interaction a message was sent in response to. +/// +public interface IMessageInteractionMetadata +{ + /// + /// The snowflake identifier of the interaction. + /// + public Snowflake Id { get; } + + /// + /// The type of this interaction. + /// + public DiscordInteractionType Type { get; } + + /// + /// The snowflake identifier of the user who triggered this interaction. + /// + public Snowflake UserId { get; } + + /// + /// The installation contexts related to this interaction. + /// + public IReadOnlyDictionary AuthorizingIntegrationOwners { get; } + + /// + /// The snowflake identifier of the original response to the interaction. This is only present on follow-up responses. + /// + public Optional OriginalResponseMessageId { get; } + + /// + /// If this interaction was created from a component, this is the snowflake identifier of the message containing the component. + /// + public Optional InteractedMessageId { get; } + + /// + /// If this message was sent in response to a modal interaction, this specifies metadata for the parent interaction the modal + /// was created in response to. + /// + public Optional TriggeringInteractionMetadata { get; } +} diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IPartialMessage.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IPartialMessage.cs index 62a8ef9552..10b5a91c03 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IPartialMessage.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IPartialMessage.cs @@ -142,7 +142,7 @@ public interface IPartialMessage /// /// Additional metadata if this message is the original response to an interaction. /// - public Optional Interaction { get; } + public Optional InteractionMetadata { get; } /// /// The thread that was started from this message. diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/Interactions/IInteraction.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Interactions/IInteraction.cs index 72847a2129..7df06b9178 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Models/Interactions/IInteraction.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Interactions/IInteraction.cs @@ -98,5 +98,15 @@ public interface IInteraction /// /// For monetized apps, any entitlements for the invoking user. /// - public Optional> Entitlements { get; } + public IReadOnlyList Entitlements { get; } + + /// + /// The user or guild IDs the integration is authorized in for the given context. + /// + public IReadOnlyDictionary AuthorizingIntegrationOwners { get; } + + /// + /// The context the interaction was triggered in. + /// + public Optional Context { get; } } diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/Interactions/IMessageInteraction.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Interactions/IMessageInteraction.cs deleted file mode 100644 index 9d01c1b31e..0000000000 --- a/src/core/DSharpPlus.Internal.Abstractions.Models/Interactions/IMessageInteraction.cs +++ /dev/null @@ -1,38 +0,0 @@ -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -using DSharpPlus.Entities; - -namespace DSharpPlus.Internal.Abstractions.Models; - -/// -/// Represents metadata on a message when the message is an original response to an interaction. -/// -public interface IMessageInteraction -{ - /// - /// The snowflake identifier of the interaction. - /// - public Snowflake Id { get; } - - /// - /// The type of this interaction. - /// - public DiscordInteractionType Type { get; } - - /// - /// The name of the application command invoked, including subcommands and subcommand groups. - /// - public string Name { get; } - - /// - /// The user who invoked this interaction. - /// - public IUser User { get; } - - /// - /// The guild member who invoked this interaction. - /// - public Optional Member { get; } -} diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/ApplicationCommands/ICreateGlobalApplicationCommandPayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/ApplicationCommands/ICreateGlobalApplicationCommandPayload.cs index 418da8ee8f..924e1681ab 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/ApplicationCommands/ICreateGlobalApplicationCommandPayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/ApplicationCommands/ICreateGlobalApplicationCommandPayload.cs @@ -44,18 +44,25 @@ public interface ICreateGlobalApplicationCommandPayload /// public Optional DefaultMemberPermissions { get; } - /// - /// Indicates whether this command is available in DMs with this app. - /// - public Optional DmPermission { get; } - /// /// The type of this command. /// public Optional Type { get; } - + /// /// Indicates whether this command is age-restricted. /// public Optional Nsfw { get; } + + /// + /// Specifies installation contexts where this command is available; only for globally-scoped commands. Defaults to + /// . + /// + public IReadOnlyList IntegrationTypes { get; } + + /// + /// Specifies contexts where this command can be used; only for globally-scoped commands. Defaults to including all + /// context types. + /// + public IReadOnlyList Contexts { get; } } diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/ApplicationCommands/IEditGlobalApplicationCommandPayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/ApplicationCommands/IEditGlobalApplicationCommandPayload.cs index 899d57597b..1a2b0c1a94 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/ApplicationCommands/IEditGlobalApplicationCommandPayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/ApplicationCommands/IEditGlobalApplicationCommandPayload.cs @@ -44,11 +44,6 @@ public interface IEditGlobalApplicationCommandPayload /// public Optional DefaultMemberPermissions { get; } - /// - /// Indicates whether this command is available in DMs with this app. - /// - public Optional DmPermission { get; } - /// /// The type of this command. /// @@ -58,4 +53,16 @@ public interface IEditGlobalApplicationCommandPayload /// Indicates whether this command is age-restricted. /// public Optional Nsfw { get; } + + /// + /// Specifies installation contexts where this command is available; only for globally-scoped commands. Defaults to + /// . + /// + public IReadOnlyList IntegrationTypes { get; } + + /// + /// Specifies contexts where this command can be used; only for globally-scoped commands. Defaults to including all + /// context types. + /// + public IReadOnlyList Contexts { get; } } diff --git a/src/core/DSharpPlus.Internal.Models/ApplicationCommands/ApplicationCommand.cs b/src/core/DSharpPlus.Internal.Models/ApplicationCommands/ApplicationCommand.cs index 0a75dbdd02..30a06a9769 100644 --- a/src/core/DSharpPlus.Internal.Models/ApplicationCommands/ApplicationCommand.cs +++ b/src/core/DSharpPlus.Internal.Models/ApplicationCommands/ApplicationCommand.cs @@ -43,11 +43,14 @@ public sealed record ApplicationCommand : IApplicationCommand public DiscordPermissions? DefaultMemberPermissions { get; init; } /// - public Optional DmPermission { get; init; } + public Optional Nsfw { get; init; } /// - public Optional Nsfw { get; init; } + public Optional> IntegrationTypes { get; init; } + + /// + public Optional?> Contexts { get; init; } /// public required Snowflake Version { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/Applications/Application.cs b/src/core/DSharpPlus.Internal.Models/Applications/Application.cs index 6f3b74d0c0..babdf00af9 100644 --- a/src/core/DSharpPlus.Internal.Models/Applications/Application.cs +++ b/src/core/DSharpPlus.Internal.Models/Applications/Application.cs @@ -87,6 +87,9 @@ public sealed record Application : IApplication /// public Optional InstallParams { get; init; } + /// + public Optional> IntegrationTypesConfig { get; init; } + /// public Optional CustomInstallUrl { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/Applications/ApplicationIntegrationTypeConfiguration.cs b/src/core/DSharpPlus.Internal.Models/Applications/ApplicationIntegrationTypeConfiguration.cs new file mode 100644 index 0000000000..2e280addbf --- /dev/null +++ b/src/core/DSharpPlus.Internal.Models/Applications/ApplicationIntegrationTypeConfiguration.cs @@ -0,0 +1,14 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Internal.Abstractions.Models; + +namespace DSharpPlus.Internal.Models; + +/// +public sealed record ApplicationIntegrationTypeConfiguration : IApplicationIntegrationTypeConfiguration +{ + /// + public Optional Oauth2InstallParams { get; init; } +} diff --git a/src/core/DSharpPlus.Internal.Models/Applications/PartialApplication.cs b/src/core/DSharpPlus.Internal.Models/Applications/PartialApplication.cs index 6316a9858f..69b372b804 100644 --- a/src/core/DSharpPlus.Internal.Models/Applications/PartialApplication.cs +++ b/src/core/DSharpPlus.Internal.Models/Applications/PartialApplication.cs @@ -87,6 +87,9 @@ public sealed record PartialApplication : IPartialApplication /// public Optional InstallParams { get; init; } + /// + public Optional> IntegrationTypesConfig { get; init; } + /// public Optional CustomInstallUrl { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/Channels/Message.cs b/src/core/DSharpPlus.Internal.Models/Channels/Message.cs index 71ce5d217f..23d81a22c5 100644 --- a/src/core/DSharpPlus.Internal.Models/Channels/Message.cs +++ b/src/core/DSharpPlus.Internal.Models/Channels/Message.cs @@ -86,7 +86,7 @@ public sealed record Message : IMessage public Optional ReferencedMessage { get; init; } /// - public Optional Interaction { get; init; } + public Optional InteractionMetadata { get; init; } /// public Optional Thread { get; init; } @@ -102,4 +102,4 @@ public sealed record Message : IMessage /// public Optional RoleSubscriptionData { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/Channels/MessageInteractionMetadata.cs b/src/core/DSharpPlus.Internal.Models/Channels/MessageInteractionMetadata.cs new file mode 100644 index 0000000000..788ef01b42 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Models/Channels/MessageInteractionMetadata.cs @@ -0,0 +1,35 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; + +namespace DSharpPlus.Internal.Models; + +/// +public sealed record MessageInteractionMetadata : IMessageInteractionMetadata +{ + /// + public required Snowflake Id { get; init; } + + /// + public required DiscordInteractionType Type { get; init; } + + /// + public required Snowflake UserId { get; init; } + + /// + public required IReadOnlyDictionary AuthorizingIntegrationOwners { get; init; } + + /// + public Optional OriginalResponseMessageId { get; init; } + + /// + public Optional InteractedMessageId { get; init; } + + /// + public Optional TriggeringInteractionMetadata { get; init; } +} diff --git a/src/core/DSharpPlus.Internal.Models/Channels/PartialMessage.cs b/src/core/DSharpPlus.Internal.Models/Channels/PartialMessage.cs index 49027cb79f..044f3516c5 100644 --- a/src/core/DSharpPlus.Internal.Models/Channels/PartialMessage.cs +++ b/src/core/DSharpPlus.Internal.Models/Channels/PartialMessage.cs @@ -86,7 +86,7 @@ public sealed record PartialMessage : IPartialMessage public Optional ReferencedMessage { get; init; } /// - public Optional Interaction { get; init; } + public Optional InteractionMetadata { get; init; } /// public Optional Thread { get; init; } @@ -102,4 +102,4 @@ public sealed record PartialMessage : IPartialMessage /// public Optional RoleSubscriptionData { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/Extensions/ServiceCollectionExtensions.cs b/src/core/DSharpPlus.Internal.Models/Extensions/ServiceCollectionExtensions.cs index a70533dcec..91f2a296c4 100644 --- a/src/core/DSharpPlus.Internal.Models/Extensions/ServiceCollectionExtensions.cs +++ b/src/core/DSharpPlus.Internal.Models/Extensions/ServiceCollectionExtensions.cs @@ -45,6 +45,7 @@ public static IServiceCollection RegisterDiscordModelSerialization options.Converters.Add(new AutoModerationActionConverter()); options.Converters.Add(new DiscordPermissionConverter()); options.Converters.Add(new MessageComponentConverter()); + options.Converters.Add(new ApplicationIntegrationTypeKeyConverter()); options.TypeInfoResolverChain.Add(OptionalTypeInfoResolver.Default); options.TypeInfoResolverChain.Add(NullBooleanTypeInfoResolver.Default); @@ -63,6 +64,7 @@ public static IServiceCollection RegisterDiscordModelSerialization options.AddModel(); options.AddModel(); + options.AddModel(); options.AddModel(); options.AddModel(); @@ -92,6 +94,7 @@ public static IServiceCollection RegisterDiscordModelSerialization options.AddModel(); options.AddModel(); options.AddModel(); + options.AddModel(); options.AddModel(); options.AddModel(); options.AddModel(); @@ -135,7 +138,6 @@ public static IServiceCollection RegisterDiscordModelSerialization options.AddModel(); options.AddModel(); options.AddModel(); - options.AddModel(); options.AddModel(); options.AddModel(); options.AddModel(); diff --git a/src/core/DSharpPlus.Internal.Models/Interactions/Interaction.cs b/src/core/DSharpPlus.Internal.Models/Interactions/Interaction.cs index 6731b8f35d..42572933ad 100644 --- a/src/core/DSharpPlus.Internal.Models/Interactions/Interaction.cs +++ b/src/core/DSharpPlus.Internal.Models/Interactions/Interaction.cs @@ -60,5 +60,11 @@ public sealed record Interaction : IInteraction public Optional GuildLocale { get; init; } /// - public Optional> Entitlements { get; init; } -} \ No newline at end of file + public required IReadOnlyList Entitlements { get; init; } + + /// + public required IReadOnlyDictionary AuthorizingIntegrationOwners { get; init; } + + /// + public Optional Context { get; init; } +} diff --git a/src/core/DSharpPlus.Internal.Models/Interactions/MessageInteraction.cs b/src/core/DSharpPlus.Internal.Models/Interactions/MessageInteraction.cs deleted file mode 100644 index 49a8c2b215..0000000000 --- a/src/core/DSharpPlus.Internal.Models/Interactions/MessageInteraction.cs +++ /dev/null @@ -1,27 +0,0 @@ -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -using DSharpPlus.Entities; -using DSharpPlus.Internal.Abstractions.Models; - -namespace DSharpPlus.Internal.Models; - -/// -public sealed record MessageInteraction : IMessageInteraction -{ - /// - public required Snowflake Id { get; init; } - - /// - public required DiscordInteractionType Type { get; init; } - - /// - public required string Name { get; init; } - - /// - public required IUser User { get; init; } - - /// - public Optional Member { get; init; } -} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Models/Serialization/Converters/ApplicationIntegrationTypeKeyConverter.cs b/src/core/DSharpPlus.Internal.Models/Serialization/Converters/ApplicationIntegrationTypeKeyConverter.cs new file mode 100644 index 0000000000..eb22052b99 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Models/Serialization/Converters/ApplicationIntegrationTypeKeyConverter.cs @@ -0,0 +1,74 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +#pragma warning disable IDE0046 + +using System; +using System.Diagnostics.CodeAnalysis; +using System.Globalization; +using System.Text.Json; +using System.Text.Json.Serialization; + +using DSharpPlus.Entities; + +namespace DSharpPlus.Internal.Models.Serialization.Converters; + +/// +/// Enables to be used as a dictionary key. +/// +public class ApplicationIntegrationTypeKeyConverter : JsonConverter +{ + // short-circuit read and write + + /// + public override DiscordApplicationIntegrationType Read + ( + ref Utf8JsonReader reader, + Type typeToConvert, + JsonSerializerOptions options + ) + => JsonSerializer.Deserialize(ref reader, options); + + /// + public override void Write + ( + Utf8JsonWriter writer, + DiscordApplicationIntegrationType value, + JsonSerializerOptions options + ) + => writer.WriteNumberValue((int)value); + + // what we actually want to override is Read/WriteAsPropertyName + + /// + public override DiscordApplicationIntegrationType ReadAsPropertyName + ( + ref Utf8JsonReader reader, + Type typeToConvert, + JsonSerializerOptions options + ) + { + if (reader.TokenType is not JsonTokenType.PropertyName) + { + throw new JsonException("Expected a property name."); + } + + string? name = reader.GetString(); + + return !int.TryParse(name, CultureInfo.InvariantCulture, out int value) + ? throw new JsonException("Expected an integer key.") + : (DiscordApplicationIntegrationType)value; + } + + /// + public override void WriteAsPropertyName + ( + Utf8JsonWriter writer, + + [DisallowNull] + DiscordApplicationIntegrationType value, + JsonSerializerOptions options + ) + => writer.WritePropertyName(((int)value).ToString(CultureInfo.InvariantCulture)); +} diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/ApplicationCommands/CreateGlobalApplicationCommandPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/ApplicationCommands/CreateGlobalApplicationCommandPayload.cs index 94bd199aaa..c60107d703 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/ApplicationCommands/CreateGlobalApplicationCommandPayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/ApplicationCommands/CreateGlobalApplicationCommandPayload.cs @@ -31,12 +31,15 @@ public sealed record CreateGlobalApplicationCommandPayload : ICreateGlobalApplic /// public Optional DefaultMemberPermissions { get; init; } - /// - public Optional DmPermission { get; init; } - /// public Optional Type { get; init; } /// public Optional Nsfw { get; init; } -} \ No newline at end of file + + /// + public required IReadOnlyList IntegrationTypes { get; init; } + + /// + public required IReadOnlyList Contexts { get; init; } +} diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/ApplicationCommands/EditGlobalApplicationCommandPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/ApplicationCommands/EditGlobalApplicationCommandPayload.cs index 8c3fd7e85e..32396c570a 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/ApplicationCommands/EditGlobalApplicationCommandPayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/ApplicationCommands/EditGlobalApplicationCommandPayload.cs @@ -31,12 +31,15 @@ public sealed record EditGlobalApplicationCommandPayload : IEditGlobalApplicatio /// public Optional DefaultMemberPermissions { get; init; } - /// - public Optional DmPermission { get; init; } - /// public Optional Type { get; init; } /// public Optional Nsfw { get; init; } -} \ No newline at end of file + + /// + public required IReadOnlyList IntegrationTypes { get; init; } + + /// + public required IReadOnlyList Contexts { get; init; } +} diff --git a/src/core/DSharpPlus.Shared/Entities/Applications/DiscordApplicationIntegrationType.cs b/src/core/DSharpPlus.Shared/Entities/Applications/DiscordApplicationIntegrationType.cs new file mode 100644 index 0000000000..07f200055e --- /dev/null +++ b/src/core/DSharpPlus.Shared/Entities/Applications/DiscordApplicationIntegrationType.cs @@ -0,0 +1,21 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Entities; + +/// +/// Specifies where an application can be installed. +/// +public enum DiscordApplicationIntegrationType +{ + /// + /// Specifies that this application can be installed to guilds. + /// + GuildInstall, + + /// + /// Specifies that this application can be installed to users. + /// + UserInstall +} diff --git a/src/core/DSharpPlus.Shared/Entities/Interactions/DiscordInteractionContextType.cs b/src/core/DSharpPlus.Shared/Entities/Interactions/DiscordInteractionContextType.cs new file mode 100644 index 0000000000..5079f82d34 --- /dev/null +++ b/src/core/DSharpPlus.Shared/Entities/Interactions/DiscordInteractionContextType.cs @@ -0,0 +1,26 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Entities; + +/// +/// Specifies contexts where an interaction can be used or was triggered from. +/// +public enum DiscordInteractionContextType +{ + /// + /// This interaction can be used or was used within a guild. + /// + Guild, + + /// + /// This interaction can be used or was used in a direct message with the bot. + /// + BotDm, + + /// + /// This interaction can be used or was used in a DM or group DM without the bot. + /// + PrivateChannel +} diff --git a/tests/core/DSharpPlus.Internal.Models.Tests/Converters/ApplicationIntegrationTypeKeyTests.cs b/tests/core/DSharpPlus.Internal.Models.Tests/Converters/ApplicationIntegrationTypeKeyTests.cs new file mode 100644 index 0000000000..fe1a3f8892 --- /dev/null +++ b/tests/core/DSharpPlus.Internal.Models.Tests/Converters/ApplicationIntegrationTypeKeyTests.cs @@ -0,0 +1,97 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; +using System.Collections.Generic; +using System.Text.Json; + +using DSharpPlus.Entities; +using DSharpPlus.Internal.Models.Serialization.Converters; + +using Xunit; + +namespace DSharpPlus.Internal.Models.Tests.Converters; + +public class ApplicationIntegrationTypeKeyTests +{ + private static ReadOnlySpan ValidPayload => + """ + { + "0": 2748, + "1": 28 + } + """u8; + + private static ReadOnlySpan InvalidFloatPayload => + """ + { + "0": 237, + "1.1": 47 + } + """u8; + + private static ReadOnlySpan InvalidStringPayload => + """ + { + "1": 83, + "fail": 23 + } + """u8; + + private readonly JsonSerializerOptions options; + + public ApplicationIntegrationTypeKeyTests() + { + this.options = new(); + this.options.Converters.Add(new ApplicationIntegrationTypeKeyConverter()); + } + + [Fact] + public void TestSuccess() + { + Dictionary value = + JsonSerializer.Deserialize>(ValidPayload, this.options)!; + + Assert.Equal(2, value.Count); + Assert.Equal(28, value[DiscordApplicationIntegrationType.UserInstall]); + } + + [Fact] + public void TestFloatFailure() + { + try + { + _ = JsonSerializer.Deserialize>(InvalidFloatPayload, this.options); + Assert.Fail("This should not have been reached."); + } + catch (JsonException exception) + { + Assert.Equal("Expected an integer key.", exception.Message); + } + catch + { + Assert.Fail("Wrong exception type thrown."); + throw; + } + } + + [Fact] + public void TestStringFailure() + { + try + { + _ = JsonSerializer.Deserialize>(InvalidStringPayload, this.options); + Assert.Fail("This should not have been reached."); + } + catch (JsonException exception) + { + Assert.Equal("Expected an integer key.", exception.Message); + } + catch + { + Assert.Fail("Wrong exception type thrown."); + throw; + } + } +} From e5b075d67c7d194ab7ad73b990944e1437455c11 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Fri, 19 Apr 2024 15:02:51 +0200 Subject: [PATCH 292/323] pattern match --- .../Results/ExceptionServices/ExceptionMarshaller.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/core/DSharpPlus.Shared/Results/ExceptionServices/ExceptionMarshaller.cs b/src/core/DSharpPlus.Shared/Results/ExceptionServices/ExceptionMarshaller.cs index 62387ace27..06422a60f5 100644 --- a/src/core/DSharpPlus.Shared/Results/ExceptionServices/ExceptionMarshaller.cs +++ b/src/core/DSharpPlus.Shared/Results/ExceptionServices/ExceptionMarshaller.cs @@ -21,15 +21,15 @@ public static class ExceptionMarshaller public static Exception MarshalResultErrorToException(Error error) { // if we previously failed to marshal this into an error, just get the original exception - if (error.GetType() == typeof(MarshalError)) + if (error is MarshalError marshalError) { - return ((MarshalError)(object)error).Exception; + return marshalError.Exception; } // if this is freely convertible, just do that - if (error.GetType().IsAssignableTo(typeof(ExceptionError))) + if (error is ExceptionError exceptionError) { - return ((ExceptionError)(object)error).ToException(); + return exceptionError.ToException(); } return new MarshalException(error); @@ -40,9 +40,9 @@ public static Exception MarshalResultErrorToException(Error error) /// public static Error MarshalExceptionToResultError(Exception exception) { - if (exception.GetType() == typeof(MarshalException)) + if (exception is MarshalException marshalException) { - return ((MarshalException)(object)exception).Error; + return marshalException.Error; } // see if we can find a matching error in a sufficiently similarly named namespace, From 4e85cb2bc9d7731279ba4d047c4564fd83566c9b Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Fri, 19 Apr 2024 16:01:33 +0200 Subject: [PATCH 293/323] add poll support --- .../Channels/IPartialMessage.cs | 10 +++ .../Interactions/IMessageCallbackData.cs | 5 ++ .../Polls/ICreatePoll.cs | 40 +++++++++ .../Polls/IPoll.cs | 41 +++++++++ .../Polls/IPollAnswer.cs | 24 ++++++ .../Polls/IPollAnswerCount.cs | 26 ++++++ .../Polls/IPollMedia.cs | 22 +++++ .../Polls/IPollResults.cs | 28 +++++++ .../API/IPollRestAPI.cs | 53 ++++++++++++ .../Channels/ICreateMessagePayload.cs | 15 +++- .../ICreateFollowupMessagePayload.cs | 8 +- .../Webhooks/IExecuteWebhookPayload.cs | 8 +- .../Responses/GetAnswerVotersResponse.cs | 20 +++++ .../Channels/Message.cs | 6 ++ .../Channels/PartialMessage.cs | 6 ++ .../Interactions/MessageCallbackData.cs | 3 + .../Polls/CreatePoll.cs | 29 +++++++ .../DSharpPlus.Internal.Models/Polls/Poll.cs | 30 +++++++ .../Polls/PollAnswer.cs | 17 ++++ .../Polls/PollAnswerCount.cs | 20 +++++ .../Polls/PollMedia.cs | 17 ++++ .../Polls/PollResults.cs | 19 +++++ .../API/ChannelRestAPI.cs | 14 ++++ .../API/InteractionRestAPI.cs | 27 ++++++ .../API/PollRestAPI.cs | 83 +++++++++++++++++++ .../API/WebhookRestAPI.cs | 14 ++++ .../Payloads/Channels/CreateMessagePayload.cs | 8 +- .../CreateFollowupMessagePayload.cs | 5 +- .../Webhooks/ExecuteWebhookPayload.cs | 5 +- .../DSharpPlus.Internal.Rest/QueryBuilder.cs | 4 +- .../Entities/DiscordPermissions.cs | 7 +- .../Entities/Polls/DiscordPollLayoutType.cs | 16 ++++ 32 files changed, 617 insertions(+), 13 deletions(-) create mode 100644 src/core/DSharpPlus.Internal.Abstractions.Models/Polls/ICreatePoll.cs create mode 100644 src/core/DSharpPlus.Internal.Abstractions.Models/Polls/IPoll.cs create mode 100644 src/core/DSharpPlus.Internal.Abstractions.Models/Polls/IPollAnswer.cs create mode 100644 src/core/DSharpPlus.Internal.Abstractions.Models/Polls/IPollAnswerCount.cs create mode 100644 src/core/DSharpPlus.Internal.Abstractions.Models/Polls/IPollMedia.cs create mode 100644 src/core/DSharpPlus.Internal.Abstractions.Models/Polls/IPollResults.cs create mode 100644 src/core/DSharpPlus.Internal.Abstractions.Rest/API/IPollRestAPI.cs create mode 100644 src/core/DSharpPlus.Internal.Abstractions.Rest/Responses/GetAnswerVotersResponse.cs create mode 100644 src/core/DSharpPlus.Internal.Models/Polls/CreatePoll.cs create mode 100644 src/core/DSharpPlus.Internal.Models/Polls/Poll.cs create mode 100644 src/core/DSharpPlus.Internal.Models/Polls/PollAnswer.cs create mode 100644 src/core/DSharpPlus.Internal.Models/Polls/PollAnswerCount.cs create mode 100644 src/core/DSharpPlus.Internal.Models/Polls/PollMedia.cs create mode 100644 src/core/DSharpPlus.Internal.Models/Polls/PollResults.cs create mode 100644 src/core/DSharpPlus.Internal.Rest/API/PollRestAPI.cs create mode 100644 src/core/DSharpPlus.Shared/Entities/Polls/DiscordPollLayoutType.cs diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IPartialMessage.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IPartialMessage.cs index 10b5a91c03..4b326c3a29 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IPartialMessage.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IPartialMessage.cs @@ -169,4 +169,14 @@ public interface IPartialMessage /// Metadata for the role subscription purchase or renewal that prompted this message. /// public Optional RoleSubscriptionData { get; } + + /// + /// Resolved data for users, members, channels and roles in this messages auto-populated select menus. + /// + public Optional Resolved { get; } + + /// + /// A poll being created with this message. + /// + public Optional Poll { get; } } diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/Interactions/IMessageCallbackData.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Interactions/IMessageCallbackData.cs index 77240880ec..3fea107af4 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Models/Interactions/IMessageCallbackData.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Interactions/IMessageCallbackData.cs @@ -48,5 +48,10 @@ public interface IMessageCallbackData /// public Optional> Attachments { get; } + /// + /// The poll to create along with this message. + /// + public Optional Poll { get; } + public IReadOnlyList? Files { get; } } diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/Polls/ICreatePoll.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Polls/ICreatePoll.cs new file mode 100644 index 0000000000..fc95976de1 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Polls/ICreatePoll.cs @@ -0,0 +1,40 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Entities; + +namespace DSharpPlus.Internal.Abstractions.Models; + +/// +/// Represents a poll currently being created by this application. +/// +public interface ICreatePoll +{ + /// + /// The question this poll asks. The text is limited to 300 characters. + /// + public IPollMedia Question { get; } + + /// + /// The answers available within this poll, between 1 and 10. + /// + public IReadOnlyList Answers { get; } + + /// + /// The duration in hours this poll should last; up to 7 days or 168 hours. + /// + public int Duration { get; } + + /// + /// Specifies whether this poll allows selecting multiple answers. + /// + public bool AllowMultiselect { get; } + + /// + /// The layout type of this poll. "Defaults to... DEFAULT!" - Discord. + /// + public Optional LayoutType { get; } +} diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/Polls/IPoll.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Polls/IPoll.cs new file mode 100644 index 0000000000..edbe6b8ed3 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Polls/IPoll.cs @@ -0,0 +1,41 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; +using System.Collections.Generic; + +using DSharpPlus.Entities; + +namespace DSharpPlus.Internal.Abstractions.Models; + +/// +/// Represents a poll object. +/// +public interface IPoll +{ + /// + /// The question this poll asks. The text is limited to 300 characters. + /// + public IPollMedia Question { get; } + + /// + /// The answers available within this poll, between 1 and 10. + /// + public IReadOnlyList Answers { get; } + + /// + /// The timestamp at which this poll expires. + /// + public DateTimeOffset Expiry { get; } + + /// + /// Specifies whether this poll allows selecting multiple answers. + /// + public bool AllowMultiselect { get; } + + /// + /// The layout type of this poll. "Defaults to... DEFAULT!" - Discord. + /// + public Optional LayoutType { get; } +} diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/Polls/IPollAnswer.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Polls/IPollAnswer.cs new file mode 100644 index 0000000000..6a2cdc4418 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Polls/IPollAnswer.cs @@ -0,0 +1,24 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Internal.Abstractions.Models; + +/// +/// Represents an answer option to a poll. +/// +public interface IPollAnswer +{ + /// + /// The numeric ID of this answer. + /// + /// + /// This is only sent as part of responses from the API or gateway. + /// + public int AnswerId { get; } + + /// + /// The text and optional emoji of this answer. The text is limited to 55 characters. + /// + public IPollMedia PollMedia { get; } +} diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/Polls/IPollAnswerCount.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Polls/IPollAnswerCount.cs new file mode 100644 index 0000000000..c27cdfc0b7 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Polls/IPollAnswerCount.cs @@ -0,0 +1,26 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Internal.Abstractions.Models; + +/// +/// Represents the answer count for a poll. +/// +public interface IPollAnswerCount +{ + /// + /// The ID of the answer, corresponds to . + /// + public int Id { get; } + + /// + /// The amount of votes this answer received. + /// + public int Count { get; } + + /// + /// Indicates whether the current user has voted on this poll. Applications are not allowed to vote on polls. + /// + public bool MeVoted { get; } +} diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/Polls/IPollMedia.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Polls/IPollMedia.cs new file mode 100644 index 0000000000..156530800e --- /dev/null +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Polls/IPollMedia.cs @@ -0,0 +1,22 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Internal.Abstractions.Models; + +/// +/// The backing text field object for polls. Questions can only contain , while answers can also contain +/// . +/// +public interface IPollMedia +{ + /// + /// The contents of the text field. + /// + public Optional Text { get; } + + /// + /// An optional emoji attached to poll answers. + /// + public Optional Emoji { get; } +} diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/Polls/IPollResults.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Polls/IPollResults.cs new file mode 100644 index 0000000000..2213571dd1 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Polls/IPollResults.cs @@ -0,0 +1,28 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +namespace DSharpPlus.Internal.Abstractions.Models; + +/// +/// Represents the results from a poll. +/// +/// +/// While a poll is in progress, the results may not be entirely accurate, though they shouldn't deviate by much. +/// After a poll finishes, Discord performs a final, accurate tally. If is set to true, +/// this tally has concluded and the results are accurate. +/// +public interface IPollResults +{ + /// + /// Indicates whether the votes have been fully counted. + /// + public bool IsFinalized { get; } + + /// + /// The counts for each answer. If an answer is missing, it received 0 votes. + /// + public IReadOnlyList AnswerCounts { get; } +} diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IPollRestAPI.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IPollRestAPI.cs new file mode 100644 index 0000000000..22b1b0838f --- /dev/null +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IPollRestAPI.cs @@ -0,0 +1,53 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Threading; +using System.Threading.Tasks; + +using DSharpPlus.Internal.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Rest.Queries; +using DSharpPlus.Internal.Abstractions.Rest.Responses; +using DSharpPlus.Results; + +namespace DSharpPlus.Internal.Abstractions.Rest.API; + +/// +/// Provides access to poll-related REST API calls. +/// +public interface IPollRestAPI +{ + /// + /// Gets a list of users who voted for the given answer. + /// + /// The snowflake identifier of the channel containing this poll. + /// The snowflake identifier of the message containing this poll. + /// The numeric identifier of the answer to query users for. + /// Pagination info for this request. The default limit is 25, but it may range between 1 and 100. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public ValueTask> GetAnswerVotersAsync + ( + Snowflake channelId, + Snowflake messageId, + int answerId, + ForwardsPaginatedQuery query = default, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Immediately ends the provided poll. You cannot end polls from other users. + /// + /// The snowflake identifier of the channel containing this poll. + /// The snowflake identifier of the message containing this poll. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public ValueTask> EndPollAsync + ( + Snowflake channelId, + Snowflake messageId, + RequestInfo info = default, + CancellationToken ct = default + ); +} diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Channels/ICreateMessagePayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Channels/ICreateMessagePayload.cs index f86155910b..0ee2f29623 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Channels/ICreateMessagePayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Channels/ICreateMessagePayload.cs @@ -3,9 +3,8 @@ // file, You can obtain one at https://mozilla.org/MPL/2.0/. using System.Collections.Generic; - -using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; namespace DSharpPlus.Internal.Abstractions.Rest.Payloads; @@ -68,4 +67,16 @@ public interface ICreateMessagePayload /// Message flags, combined as bitfield. Only can be set. /// public Optional Flags { get; } + + /// + /// If this is set to true and a is present, it will be checked for uniqueness in the past few + /// minutes. If another message was created by this user with the same nonce, that message will be returned and no new + /// message will be created. + /// + public Optional EnforceNonce { get; } + + /// + /// A poll attached to this message. + /// + public Optional Poll { get; } } diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Interactions/ICreateFollowupMessagePayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Interactions/ICreateFollowupMessagePayload.cs index 8767afda47..ea815fb8cc 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Interactions/ICreateFollowupMessagePayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Interactions/ICreateFollowupMessagePayload.cs @@ -3,9 +3,8 @@ // file, You can obtain one at https://mozilla.org/MPL/2.0/. using System.Collections.Generic; - -using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; namespace DSharpPlus.Internal.Abstractions.Rest.Payloads; @@ -56,4 +55,9 @@ public interface ICreateFollowupMessagePayload /// Additional message flags for this message. SuppressEmbeds and Ephemeral can be set. /// public Optional Flags { get; } + + /// + /// The poll object created with this message. + /// + public Optional Poll { get; } } diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Webhooks/IExecuteWebhookPayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Webhooks/IExecuteWebhookPayload.cs index 645bba9730..fa9b5de6ef 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Webhooks/IExecuteWebhookPayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Webhooks/IExecuteWebhookPayload.cs @@ -3,9 +3,8 @@ // file, You can obtain one at https://mozilla.org/MPL/2.0/. using System.Collections.Generic; - -using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; namespace DSharpPlus.Internal.Abstractions.Rest.Payloads; @@ -73,4 +72,9 @@ public interface IExecuteWebhookPayload /// The snowflake identifiers of tags to apply to the thread, if applicable. /// public Optional> AppliedTags { get; } + + /// + /// The poll object created with this message. + /// + public Optional Poll { get; } } diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Responses/GetAnswerVotersResponse.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Responses/GetAnswerVotersResponse.cs new file mode 100644 index 0000000000..14e69994b3 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Responses/GetAnswerVotersResponse.cs @@ -0,0 +1,20 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Internal.Abstractions.Models; + +namespace DSharpPlus.Internal.Abstractions.Rest.Responses; + +/// +/// Represents a response from GET /channels/:channel-id/polls/:message-id/answers/:answer-id. +/// +public readonly record struct GetAnswerVotersResponse +{ + /// + /// The users who voted for this answer. + /// + public IReadOnlyList Users { get; init; } +} diff --git a/src/core/DSharpPlus.Internal.Models/Channels/Message.cs b/src/core/DSharpPlus.Internal.Models/Channels/Message.cs index 23d81a22c5..16b4edadee 100644 --- a/src/core/DSharpPlus.Internal.Models/Channels/Message.cs +++ b/src/core/DSharpPlus.Internal.Models/Channels/Message.cs @@ -102,4 +102,10 @@ public sealed record Message : IMessage /// public Optional RoleSubscriptionData { get; init; } + + /// + public Optional Resolved { get; init; } + + /// + public Optional Poll { get; init; } } diff --git a/src/core/DSharpPlus.Internal.Models/Channels/PartialMessage.cs b/src/core/DSharpPlus.Internal.Models/Channels/PartialMessage.cs index 044f3516c5..d4d9e54c20 100644 --- a/src/core/DSharpPlus.Internal.Models/Channels/PartialMessage.cs +++ b/src/core/DSharpPlus.Internal.Models/Channels/PartialMessage.cs @@ -102,4 +102,10 @@ public sealed record PartialMessage : IPartialMessage /// public Optional RoleSubscriptionData { get; init; } + + /// + public Optional Resolved { get; init; } + + /// + public Optional Poll { get; init; } } diff --git a/src/core/DSharpPlus.Internal.Models/Interactions/MessageCallbackData.cs b/src/core/DSharpPlus.Internal.Models/Interactions/MessageCallbackData.cs index 25873aa014..36ae55c44e 100644 --- a/src/core/DSharpPlus.Internal.Models/Interactions/MessageCallbackData.cs +++ b/src/core/DSharpPlus.Internal.Models/Interactions/MessageCallbackData.cs @@ -33,6 +33,9 @@ public sealed record MessageCallbackData : IMessageCallbackData /// public Optional> Attachments { get; init; } + /// + public Optional Poll { get; init; } + /// public IReadOnlyList? Files { get; init; } } diff --git a/src/core/DSharpPlus.Internal.Models/Polls/CreatePoll.cs b/src/core/DSharpPlus.Internal.Models/Polls/CreatePoll.cs new file mode 100644 index 0000000000..3d60e7f934 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Models/Polls/CreatePoll.cs @@ -0,0 +1,29 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; + +namespace DSharpPlus.Internal.Models; + +/// +public sealed record CreatePoll : ICreatePoll +{ + /// + public required IPollMedia Question { get; init; } + + /// + public required IReadOnlyList Answers { get; init; } + + /// + public required int Duration { get; init; } + + /// + public required bool AllowMultiselect { get; init; } + + /// + public Optional LayoutType { get; init; } +} diff --git a/src/core/DSharpPlus.Internal.Models/Polls/Poll.cs b/src/core/DSharpPlus.Internal.Models/Polls/Poll.cs new file mode 100644 index 0000000000..a122a5e087 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Models/Polls/Poll.cs @@ -0,0 +1,30 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; +using System.Collections.Generic; + +using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; + +namespace DSharpPlus.Internal.Models; + +/// +public sealed record Poll : IPoll +{ + /// + public required IPollMedia Question { get; init; } + + /// + public required IReadOnlyList Answers { get; init; } + + /// + public required DateTimeOffset Expiry { get; init; } + + /// + public required bool AllowMultiselect { get; init; } + + /// + public Optional LayoutType { get; init; } +} diff --git a/src/core/DSharpPlus.Internal.Models/Polls/PollAnswer.cs b/src/core/DSharpPlus.Internal.Models/Polls/PollAnswer.cs new file mode 100644 index 0000000000..14b2bff419 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Models/Polls/PollAnswer.cs @@ -0,0 +1,17 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Internal.Abstractions.Models; + +namespace DSharpPlus.Internal.Models; + +/// +public sealed record PollAnswer : IPollAnswer +{ + /// + public required int AnswerId { get; init; } + + /// + public required IPollMedia PollMedia { get; init; } +} diff --git a/src/core/DSharpPlus.Internal.Models/Polls/PollAnswerCount.cs b/src/core/DSharpPlus.Internal.Models/Polls/PollAnswerCount.cs new file mode 100644 index 0000000000..54e7df2db9 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Models/Polls/PollAnswerCount.cs @@ -0,0 +1,20 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Internal.Abstractions.Models; + +namespace DSharpPlus.Internal.Models; + +/// +public sealed record PollAnswerCount : IPollAnswerCount +{ + /// + public required int Id { get; init; } + + /// + public required int Count { get; init; } + + /// + public required bool MeVoted { get; init; } +} diff --git a/src/core/DSharpPlus.Internal.Models/Polls/PollMedia.cs b/src/core/DSharpPlus.Internal.Models/Polls/PollMedia.cs new file mode 100644 index 0000000000..c79ec380df --- /dev/null +++ b/src/core/DSharpPlus.Internal.Models/Polls/PollMedia.cs @@ -0,0 +1,17 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Internal.Abstractions.Models; + +namespace DSharpPlus.Internal.Models; + +/// +public sealed record PollMedia : IPollMedia +{ + /// + public Optional Text { get; init; } + + /// + public Optional Emoji { get; init; } +} diff --git a/src/core/DSharpPlus.Internal.Models/Polls/PollResults.cs b/src/core/DSharpPlus.Internal.Models/Polls/PollResults.cs new file mode 100644 index 0000000000..4fd2ae8efc --- /dev/null +++ b/src/core/DSharpPlus.Internal.Models/Polls/PollResults.cs @@ -0,0 +1,19 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Internal.Abstractions.Models; + +namespace DSharpPlus.Internal.Models; + +/// +public sealed record PollResults : IPollResults +{ + /// + public required bool IsFinalized { get; init; } + + /// + public required IReadOnlyList AnswerCounts { get; init; } +} diff --git a/src/core/DSharpPlus.Internal.Rest/API/ChannelRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/ChannelRestAPI.cs index 3061cb4929..e74348e275 100644 --- a/src/core/DSharpPlus.Internal.Rest/API/ChannelRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Rest/API/ChannelRestAPI.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; using System.Globalization; +using System.Linq; using System.Net.Http; using System.Threading; using System.Threading.Tasks; @@ -165,6 +166,19 @@ public async ValueTask> CreateMessageAsync return new ValidationError("Only up to 3 stickers can be sent with a message."); } + if (payload.Poll.TryGetNonNullValue(out ICreatePoll? poll)) + { + if (poll.Question.Text is { HasValue: true, Value.Length: > 300 }) + { + return new ValidationError("The poll must specify a question that cannot exceed 300 characters."); + } + + if (poll.Answers.Any(answer => answer.PollMedia.Text is { HasValue: true, Value.Length: > 55 })) + { + return new ValidationError("The answer text of a poll cannot exceed 55 characters."); + } + } + return await restClient.ExecuteRequestAsync ( HttpMethod.Post, diff --git a/src/core/DSharpPlus.Internal.Rest/API/InteractionRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/InteractionRestAPI.cs index 4af05ea91c..d4c19419cc 100644 --- a/src/core/DSharpPlus.Internal.Rest/API/InteractionRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Rest/API/InteractionRestAPI.cs @@ -5,6 +5,7 @@ #pragma warning disable IDE0046 using System.Collections.Generic; +using System.Linq; using System.Net.Http; using System.Runtime.CompilerServices; using System.Threading; @@ -53,6 +54,19 @@ public async ValueTask> CreateFollowupMessageAsync return new ValidationError("Only up to 10 embeds can be sent with a message."); } + if (payload.Poll.TryGetNonNullValue(out ICreatePoll? poll)) + { + if (poll.Question.Text is { HasValue: true, Value.Length: > 300 }) + { + return new ValidationError("The poll must specify a question that cannot exceed 300 characters."); + } + + if (poll.Answers.Any(answer => answer.PollMedia.Text is { HasValue: true, Value.Length: > 55 })) + { + return new ValidationError("The answer text of a poll cannot exceed 55 characters."); + } + } + return await restClient.ExecuteRequestAsync ( HttpMethod.Post, @@ -97,6 +111,19 @@ public async ValueTask CreateInteractionResponseAsync { return new ValidationError("Only up to 10 embeds can be sent with a message."); } + + if (message.Poll.TryGetNonNullValue(out ICreatePoll? poll)) + { + if (poll.Question.Text is { HasValue: true, Value.Length: > 300 }) + { + return new ValidationError("The poll must specify a question that cannot exceed 300 characters."); + } + + if (poll.Answers.Any(answer => answer.PollMedia.Text is { HasValue: true, Value.Length: > 55 })) + { + return new ValidationError("The answer text of a poll cannot exceed 55 characters."); + } + } } else if (payload.Type is DiscordInteractionCallbackType.Modal) { diff --git a/src/core/DSharpPlus.Internal.Rest/API/PollRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/PollRestAPI.cs new file mode 100644 index 0000000000..193e039d61 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Rest/API/PollRestAPI.cs @@ -0,0 +1,83 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Globalization; +using System.Net.Http; +using System.Threading; +using System.Threading.Tasks; + +using DSharpPlus.Internal.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Rest; +using DSharpPlus.Internal.Abstractions.Rest.API; +using DSharpPlus.Internal.Abstractions.Rest.Errors; +using DSharpPlus.Internal.Abstractions.Rest.Queries; +using DSharpPlus.Internal.Abstractions.Rest.Responses; +using DSharpPlus.Internal.Rest.Ratelimiting; +using DSharpPlus.Results; + +namespace DSharpPlus.Internal.Rest.API; + +/// +public sealed class PollRestAPI(IRestClient restClient) + : IPollRestAPI +{ + /// + public async ValueTask> EndPollAsync + ( + Snowflake channelId, + Snowflake messageId, + RequestInfo info = default, + CancellationToken ct = default + ) + { + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Post, + $"channels/{channelId}/polls/{messageId}/expire", + b => b.WithSimpleRoute(TopLevelResource.Channel, channelId) + .WithRoute($"POST channels/{channelId}/polls/:message-id/expire"), + info, + ct + ); + } + + /// + public async ValueTask> GetAnswerVotersAsync + ( + Snowflake channelId, + Snowflake messageId, + int answerId, + ForwardsPaginatedQuery query = default, + RequestInfo info = default, + CancellationToken ct = default + ) + { + QueryBuilder builder = new($"channels/{channelId}/polls/{messageId}/answers/{answerId}"); + + if (query.After is not null) + { + _ = builder.AddParameter("after", query.After.Value.ToString()); + } + + if (query.Limit is not null) + { + if (query.Limit is < 1 or > 100) + { + return new ValidationError("The provided limit must be between 1 and 100."); + } + + _ = builder.AddParameter("limit", query.Limit.Value.ToString(CultureInfo.InvariantCulture)); + } + + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Post, + builder.Build(), + b => b.WithSimpleRoute(TopLevelResource.Channel, channelId) + .WithRoute($"POST channels/{channelId}/polls/:message-id/answers/:answer-id"), + info, + ct + ); + } +} diff --git a/src/core/DSharpPlus.Internal.Rest/API/WebhookRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/WebhookRestAPI.cs index 1757a4f4b6..678f141f17 100644 --- a/src/core/DSharpPlus.Internal.Rest/API/WebhookRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Rest/API/WebhookRestAPI.cs @@ -6,6 +6,7 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Net.Http; using System.Threading; using System.Threading.Tasks; @@ -218,6 +219,19 @@ public async ValueTask> ExecuteWebhookAsync return new ValidationError("A webhook message cannot contain more than 5 action rows."); } + if (payload.Poll.TryGetNonNullValue(out ICreatePoll? poll)) + { + if (poll.Question.Text is { HasValue: true, Value.Length: > 300 }) + { + return new ValidationError("The poll must specify a question that cannot exceed 300 characters."); + } + + if (poll.Answers.Any(answer => answer.PollMedia.Text is { HasValue: true, Value.Length: > 55 })) + { + return new ValidationError("The answer text of a poll cannot exceed 55 characters."); + } + } + QueryBuilder builder = new() { RootUri = $"webhooks/{webhookId}/{webhookToken}" diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/CreateMessagePayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/CreateMessagePayload.cs index e7f8c2e08e..952acaae0c 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/CreateMessagePayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/CreateMessagePayload.cs @@ -45,4 +45,10 @@ public sealed record CreateMessagePayload : ICreateMessagePayload /// public Optional Flags { get; init; } -} \ No newline at end of file + + /// + public Optional EnforceNonce { get; init; } + + /// + public Optional Poll { get; init; } +} diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Interactions/CreateFollowupMessagePayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Interactions/CreateFollowupMessagePayload.cs index 769fc846aa..1aaa07b41b 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/Interactions/CreateFollowupMessagePayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Interactions/CreateFollowupMessagePayload.cs @@ -36,4 +36,7 @@ public sealed record CreateFollowupMessagePayload : ICreateFollowupMessagePayloa /// public Optional Flags { get; init; } -} \ No newline at end of file + + /// + public Optional Poll { get; init; } +} diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Webhooks/ExecuteWebhookPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Webhooks/ExecuteWebhookPayload.cs index d5c7c872e0..cf1aeecdb7 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/Webhooks/ExecuteWebhookPayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Webhooks/ExecuteWebhookPayload.cs @@ -48,4 +48,7 @@ public sealed record ExecuteWebhookPayload : IExecuteWebhookPayload /// public Optional> AppliedTags { get; init; } -} \ No newline at end of file + + /// + public Optional Poll { get; init; } +} diff --git a/src/core/DSharpPlus.Internal.Rest/QueryBuilder.cs b/src/core/DSharpPlus.Internal.Rest/QueryBuilder.cs index a7bc000e25..c4a43b39f2 100644 --- a/src/core/DSharpPlus.Internal.Rest/QueryBuilder.cs +++ b/src/core/DSharpPlus.Internal.Rest/QueryBuilder.cs @@ -12,10 +12,8 @@ namespace DSharpPlus.Internal.Rest; /// /// Constructs a new query from the specified parameters. /// -internal record struct QueryBuilder +internal record struct QueryBuilder(string RootUri) { - public string RootUri { get; set; } - public DictionarySlim Parameters { get; set; } public readonly QueryBuilder AddParameter(string key, string value) diff --git a/src/core/DSharpPlus.Shared/Entities/DiscordPermissions.cs b/src/core/DSharpPlus.Shared/Entities/DiscordPermissions.cs index 6b7ae4d84b..d74e500bee 100644 --- a/src/core/DSharpPlus.Shared/Entities/DiscordPermissions.cs +++ b/src/core/DSharpPlus.Shared/Entities/DiscordPermissions.cs @@ -235,5 +235,10 @@ public enum DiscordPermissions : ulong /// /// Allows members to send voice messages. /// - SendVoiceMessages = 1L << 46 + SendVoiceMessages = 1L << 46, + + /// + /// Allows members to send polls. + /// + SendPolls = 1L << 49 } diff --git a/src/core/DSharpPlus.Shared/Entities/Polls/DiscordPollLayoutType.cs b/src/core/DSharpPlus.Shared/Entities/Polls/DiscordPollLayoutType.cs new file mode 100644 index 0000000000..5315df7d4f --- /dev/null +++ b/src/core/DSharpPlus.Shared/Entities/Polls/DiscordPollLayoutType.cs @@ -0,0 +1,16 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Entities; + +/// +/// Represents the available layout types for polls. +/// +public enum DiscordPollLayoutType +{ + /// + /// "The, uhm, default layout type." - Discord. + /// + Default = 1 +} From 6597e3962da7f0cf8aab9f9d3c79689d529d0427 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Fri, 19 Apr 2024 16:15:45 +0200 Subject: [PATCH 294/323] formatting fixes --- .../Entitlements/IPartialEntitlement.cs | 3 +- .../ScheduledEvents/IScheduledEventUser.cs | 2 +- .../IEditCurrentApplicationPayload.cs | 3 +- .../ICreateAutoModerationRulePayload.cs | 3 +- .../IModifyAutoModerationRulePayload.cs | 3 +- .../Channels/ICreateMessagePayload.cs | 1 + .../Payloads/Channels/IEditMessagePayload.cs | 3 +- .../Channels/IForumAndMediaThreadMessage.cs | 3 +- .../Channels/IModifyGuildChannelPayload.cs | 3 +- .../Guilds/ICreateGuildChannelPayload.cs | 3 +- .../Payloads/Guilds/ICreateGuildPayload.cs | 3 +- .../Guilds/IModifyGuildOnboardingPayload.cs | 3 +- .../ICreateFollowupMessagePayload.cs | 1 + .../ICreateGuildScheduledEventPayload.cs | 5 +- .../IModifyGuildScheduledEventPayload.cs | 4 +- .../Webhooks/IExecuteWebhookPayload.cs | 1 + .../ApplicationCommands/LocalizationQuery.cs | 2 +- .../ListGuildAuditLogEntriesQuery.cs | 2 +- .../Channels/GetChannelMessagesQuery.cs | 2 +- .../Queries/Channels/GetThreadMemberQuery.cs | 2 +- .../Channels/ListArchivedThreadsQuery.cs | 2 +- .../Channels/ListThreadMembersQuery.cs | 2 +- .../Entitlements/ListEntitlementsQuery.cs | 2 +- .../Queries/ForwardsPaginatedQuery.cs | 2 +- .../Queries/Guilds/GetGuildPruneCountQuery.cs | 2 +- .../Queries/Guilds/GetGuildQuery.cs | 2 +- .../Queries/IPaginatedQuery.cs | 2 +- .../Queries/Invites/GetInviteQuery.cs | 2 +- .../Queries/PaginatedQuery.cs | 2 +- .../ScheduledEvents/WithUserCountQuery.cs | 2 +- .../Queries/Webhooks/ExecuteWebhookQuery.cs | 2 +- .../Queries/Webhooks/ThreadIdQuery.cs | 2 +- .../CreateApplicationCommandResponse.cs | 2 +- .../ApplicationCommandOption.cs | 2 +- .../ApplicationCommandOptionChoice.cs | 2 +- .../ApplicationCommandPermission.cs | 2 +- .../ApplicationCommandPermissions.cs | 2 +- .../PartialApplicationCommandPermissions.cs | 2 +- .../Applications/InstallParameters.cs | 2 +- .../AuditLogs/AuditLog.cs | 2 +- .../AuditLogs/AuditLogChange.cs | 2 +- .../AuditLogs/AuditLogEntry.cs | 2 +- .../AuditLogs/AuditLogEntryInfo.cs | 2 +- .../AutoModeration/AutoModerationAction.cs | 2 +- .../AutoModerationActionMetadata.cs | 2 +- .../AutoModeration/AutoModerationRule.cs | 2 +- .../AutoModerationTriggerMetadata.cs | 2 +- .../BlockMessageActionMetadata.cs | 2 +- .../PartialAutoModerationRule.cs | 2 +- .../SendAlertMessageActionMetadata.cs | 2 +- .../AutoModeration/TimeoutActionMetadata.cs | 2 +- .../Channels/AllowedMentions.cs | 2 +- .../Channels/Attachment.cs | 2 +- .../Channels/Channel.cs | 2 +- .../Channels/ChannelMention.cs | 2 +- .../Channels/ChannelOverwrite.cs | 2 +- .../Channels/DefaultReaction.cs | 2 +- .../Channels/Embed.cs | 2 +- .../Channels/EmbedAuthor.cs | 2 +- .../Channels/EmbedField.cs | 2 +- .../Channels/EmbedFooter.cs | 2 +- .../Channels/EmbedImage.cs | 2 +- .../Channels/EmbedProvider.cs | 2 +- .../Channels/EmbedThumbnail.cs | 2 +- .../Channels/EmbedVideo.cs | 2 +- .../Channels/FollowedChannel.cs | 2 +- .../Channels/ForumTag.cs | 2 +- .../Channels/MessageActivity.cs | 2 +- .../Channels/MessageReference.cs | 2 +- .../Channels/PartialAttachment.cs | 2 +- .../Channels/PartialChannel.cs | 2 +- .../Channels/PartialChannelOverwrite.cs | 2 +- .../Channels/Reaction.cs | 2 +- .../Channels/RoleSubscriptionData.cs | 2 +- .../Channels/ThreadMember.cs | 2 +- .../Channels/ThreadMetadata.cs | 2 +- .../Emojis/Emoji.cs | 2 +- .../Emojis/PartialEmoji.cs | 2 +- .../Entitlements/Entitlement.cs | 2 +- .../Entitlements/PartialEntitlement.cs | 2 +- .../GuildTemplates/Template.cs | 2 +- .../DSharpPlus.Internal.Models/Guilds/Ban.cs | 2 +- .../Guilds/Guild.cs | 2 +- .../Guilds/GuildMember.cs | 2 +- .../Guilds/GuildPreview.cs | 2 +- .../Guilds/GuildWidget.cs | 2 +- .../Guilds/GuildWidgetSettings.cs | 2 +- .../Guilds/Integration.cs | 2 +- .../Guilds/IntegrationAccount.cs | 2 +- .../Guilds/IntegrationApplication.cs | 2 +- .../Guilds/Onboarding.cs | 2 +- .../Guilds/OnboardingPrompt.cs | 2 +- .../Guilds/OnboardingPromptOption.cs | 2 +- .../Guilds/PartialGuild.cs | 2 +- .../Guilds/PartialGuildMember.cs | 2 +- .../Guilds/PartialIntegration.cs | 2 +- .../Guilds/PartialRole.cs | 2 +- .../DSharpPlus.Internal.Models/Guilds/Role.cs | 2 +- .../Guilds/RoleTags.cs | 2 +- .../Guilds/WelcomeScreen.cs | 2 +- .../Guilds/WelcomeScreenChannel.cs | 2 +- .../ApplicationCommandInteractionData.cs | 2 +- ...ApplicationCommandInteractionDataOption.cs | 2 +- .../Interactions/AutocompleteCallbackData.cs | 2 +- .../Interactions/InteractionResponse.cs | 2 +- .../MessageComponentInteractionData.cs | 2 +- .../Interactions/ModalCallbackData.cs | 2 +- .../Interactions/ModalInteractionData.cs | 2 +- .../Interactions/ResolvedData.cs | 2 +- .../Invites/Invite.cs | 2 +- .../Invites/PartialInvite.cs | 2 +- .../MessageComponents/ActionRowComponent.cs | 2 +- .../MessageComponents/ButtonComponent.cs | 2 +- .../ChannelSelectComponent.cs | 2 +- .../MessageComponents/DefaultSelectValue.cs | 2 +- .../MessageComponents/InteractiveComponent.cs | 2 +- .../MentionableSelectComponent.cs | 2 +- .../MessageComponents/RoleSelectComponent.cs | 2 +- .../MessageComponents/SelectOption.cs | 2 +- .../StringSelectComponent.cs | 2 +- .../MessageComponents/TextInputComponent.cs | 2 +- .../MessageComponents/UserSelectComponent.cs | 2 +- .../RoleConnections/RoleConnectionMetadata.cs | 2 +- .../ScheduledEvents/PartialScheduledEvent.cs | 2 +- .../ScheduledEvents/ScheduledEvent.cs | 2 +- .../ScheduledEvents/ScheduledEventMetadata.cs | 2 +- .../ScheduledEvents/ScheduledEventUser.cs | 2 +- .../AutoModerationActionConverter.cs | 3 +- .../Converters/MessageComponentConverter.cs | 3 +- .../Converters/OneOfConverterFactory.cs | 2 +- .../Converters/OptionalConverter.cs | 6 +- .../Converters/OptionalConverterFactory.cs | 2 +- .../DSharpPlus.Internal.Models/Skus/Sku.cs | 2 +- .../StageInstances/PartialStageInstance.cs | 2 +- .../StageInstances/StageInstance.cs | 2 +- .../Stickers/PartialSticker.cs | 2 +- .../Stickers/Sticker.cs | 2 +- .../Stickers/StickerItem.cs | 2 +- .../Stickers/StickerPack.cs | 2 +- .../DSharpPlus.Internal.Models/Teams/Team.cs | 2 +- .../Teams/TeamMember.cs | 2 +- .../Users/ApplicationRoleConnection.cs | 2 +- .../Users/Connection.cs | 2 +- .../Users/PartialUser.cs | 2 +- .../DSharpPlus.Internal.Models/Users/User.cs | 2 +- .../Voice/VoiceRegion.cs | 2 +- .../Voice/VoiceState.cs | 2 +- .../Webhooks/PartialWebhook.cs | 2 +- .../Webhooks/Webhook.cs | 2 +- .../API/ApplicationCommandsRestAPI.cs | 15 ++--- .../API/AuditLogsRestAPI.cs | 15 ++--- .../API/ChannelRestAPI.cs | 65 +++++++------------ .../API/EntitlementsRestAPI.cs | 19 +++--- .../API/GuildRestAPI.cs | 52 +++++---------- .../API/GuildScheduledEventRestAPI.cs | 27 +++----- .../API/InviteRestAPI.cs | 11 ++-- .../API/UserRestAPI.cs | 13 ++-- .../API/WebhookRestAPI.cs | 30 +++------ .../CreateGuildApplicationCommandPayload.cs | 2 +- .../EditGuildApplicationCommandPayload.cs | 2 +- .../EditCurrentApplicationPayload.cs | 2 +- .../CreateAutoModerationRulePayload.cs | 2 +- .../ModifyAutoModerationRulePayload.cs | 2 +- .../Channels/BulkDeleteMessagesPayload.cs | 2 +- .../Channels/CreateChannelInvitePayload.cs | 2 +- .../Channels/EditChannelPermissionsPayload.cs | 2 +- .../Payloads/Channels/EditMessagePayload.cs | 2 +- .../FollowAnnouncementChannelPayload.cs | 2 +- .../Channels/ForumAndMediaThreadMessage.cs | 2 +- .../Channels/GroupDMAddRecipientPayload.cs | 2 +- .../Payloads/Channels/ModifyGroupDMPayload.cs | 2 +- .../Channels/ModifyGuildChannelPayload.cs | 2 +- .../Channels/ModifyThreadChannelPayload.cs | 2 +- .../Channels/StartThreadFromMessagePayload.cs | 2 +- ...StartThreadInForumOrMediaChannelPayload.cs | 2 +- .../StartThreadWithoutMessagePayload.cs | 2 +- .../Emojis/CreateGuildEmojiPayload.cs | 2 +- .../Emojis/ModifyGuildEmojiPayload.cs | 2 +- .../CreateTestEntitlementPayload.cs | 2 +- .../CreateGuildFromGuildTemplatePayload.cs | 2 +- .../CreateGuildTemplatePayload.cs | 2 +- .../ModifyGuildTemplatePayload.cs | 2 +- .../Payloads/Guilds/AddGuildMemberPayload.cs | 2 +- .../Guilds/CreateGuildChannelPayload.cs | 2 +- .../Payloads/Guilds/CreateGuildPayload.cs | 2 +- .../Payloads/Guilds/CreateGuildRolePayload.cs | 2 +- .../Guilds/ModifyCurrentMemberPayload.cs | 2 +- .../ModifyCurrentUserVoiceStatePayload.cs | 2 +- .../ModifyGuildChannelPositionsPayload.cs | 2 +- .../Guilds/ModifyGuildMemberPayload.cs | 2 +- .../Guilds/ModifyGuildMfaLevelPayload.cs | 2 +- .../Guilds/ModifyGuildOnboardingPayload.cs | 2 +- .../Payloads/Guilds/ModifyGuildPayload.cs | 2 +- .../Payloads/Guilds/ModifyGuildRolePayload.cs | 2 +- .../Guilds/ModifyGuildRolePositionsPayload.cs | 2 +- .../Guilds/ModifyGuildWelcomeScreenPayload.cs | 2 +- .../Guilds/ModifyUserVoiceStatePayload.cs | 2 +- .../EditFollowupMessagePayload.cs | 2 +- .../EditInteractionResponsePayload.cs | 2 +- .../CreateGuildScheduledEventPayload.cs | 2 +- .../ModifyGuildScheduledEventPayload.cs | 2 +- .../CreateStageInstancePayload.cs | 2 +- .../ModifyStageInstancePayload.cs | 2 +- .../Stickers/CreateGuildStickerPayload.cs | 2 +- .../Stickers/ModifyGuildStickerPayload.cs | 2 +- .../Payloads/Users/CreateDmPayload.cs | 2 +- .../Payloads/Users/CreateGroupDmPayload.cs | 2 +- .../Users/ModifyCurrentUserPayload.cs | 2 +- ...entUserApplicationRoleConnectionPayload.cs | 2 +- .../Payloads/Webhooks/CreateWebhookPayload.cs | 2 +- .../Webhooks/EditWebhookMessagePayload.cs | 2 +- .../Payloads/Webhooks/ModifyWebhookPayload.cs | 2 +- .../Webhooks/ModifyWebhookWithTokenPayload.cs | 2 +- src/core/DSharpPlus.Shared/AttachmentData.cs | 8 +-- .../AuditLogs/DiscordAuditLogEvent.cs | 2 +- .../Guilds/DiscordGuildMemberFlags.cs | 2 +- .../Entities/Users/DiscordUserFlags.cs | 6 +- src/core/DSharpPlus.Shared/ImageData.cs | 10 +-- .../Serialization/ImageDataConverter.cs | 4 +- .../Serialization/RedirectingConverter.cs | 8 +-- .../Serialization/SerializationService.cs | 16 ++--- .../Snowflake.GenericMath.cs | 8 +-- .../BuiltActionRowComponent.cs | 2 +- .../Implementations/BuiltEmbed.cs | 2 +- .../BuiltInteractionResponse.cs | 2 +- .../Implementations/BuiltModalCallbackData.cs | 2 +- .../BuiltTextInputComponent.cs | 2 +- .../Interactions/TextInputComponentBuilder.cs | 5 +- .../Converters/AuditLogChangeTests.cs | 6 +- 229 files changed, 338 insertions(+), 420 deletions(-) diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/Entitlements/IPartialEntitlement.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Entitlements/IPartialEntitlement.cs index 08dd7f5716..c8f04de621 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Models/Entitlements/IPartialEntitlement.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Entitlements/IPartialEntitlement.cs @@ -2,9 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Entities; using System; +using DSharpPlus.Entities; + namespace DSharpPlus.Internal.Abstractions.Models; /// diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/ScheduledEvents/IScheduledEventUser.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/ScheduledEvents/IScheduledEventUser.cs index da018bacc6..bed5baa77e 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Models/ScheduledEvents/IScheduledEventUser.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/ScheduledEvents/IScheduledEventUser.cs @@ -13,7 +13,7 @@ public interface IScheduledEventUser /// The snowflake identifier of the event this user has subscribed to. /// public Snowflake GuildScheduledEventId { get; } - + /// /// The user which subscribed to the event. /// diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Applications/IEditCurrentApplicationPayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Applications/IEditCurrentApplicationPayload.cs index 5bd700ddb9..ddfa751138 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Applications/IEditCurrentApplicationPayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Applications/IEditCurrentApplicationPayload.cs @@ -3,9 +3,8 @@ // file, You can obtain one at https://mozilla.org/MPL/2.0/. using System.Collections.Generic; - -using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; namespace DSharpPlus.Internal.Abstractions.Rest.Payloads; diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/AutoModeration/ICreateAutoModerationRulePayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/AutoModeration/ICreateAutoModerationRulePayload.cs index 1116e92124..3bfab72ef0 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/AutoModeration/ICreateAutoModerationRulePayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/AutoModeration/ICreateAutoModerationRulePayload.cs @@ -3,9 +3,8 @@ // file, You can obtain one at https://mozilla.org/MPL/2.0/. using System.Collections.Generic; - -using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; namespace DSharpPlus.Internal.Abstractions.Rest.Payloads; diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/AutoModeration/IModifyAutoModerationRulePayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/AutoModeration/IModifyAutoModerationRulePayload.cs index 967a6f5769..a5b0ca9319 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/AutoModeration/IModifyAutoModerationRulePayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/AutoModeration/IModifyAutoModerationRulePayload.cs @@ -3,9 +3,8 @@ // file, You can obtain one at https://mozilla.org/MPL/2.0/. using System.Collections.Generic; - -using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; namespace DSharpPlus.Internal.Abstractions.Rest.Payloads; diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Channels/ICreateMessagePayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Channels/ICreateMessagePayload.cs index 0ee2f29623..20a2738d9c 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Channels/ICreateMessagePayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Channels/ICreateMessagePayload.cs @@ -3,6 +3,7 @@ // file, You can obtain one at https://mozilla.org/MPL/2.0/. using System.Collections.Generic; + using DSharpPlus.Entities; using DSharpPlus.Internal.Abstractions.Models; diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Channels/IEditMessagePayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Channels/IEditMessagePayload.cs index f696c4b163..5c07092186 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Channels/IEditMessagePayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Channels/IEditMessagePayload.cs @@ -3,9 +3,8 @@ // file, You can obtain one at https://mozilla.org/MPL/2.0/. using System.Collections.Generic; - -using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; namespace DSharpPlus.Internal.Abstractions.Rest.Payloads; diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Channels/IForumAndMediaThreadMessage.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Channels/IForumAndMediaThreadMessage.cs index 7d7ec6e064..d64915fb80 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Channels/IForumAndMediaThreadMessage.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Channels/IForumAndMediaThreadMessage.cs @@ -3,9 +3,8 @@ // file, You can obtain one at https://mozilla.org/MPL/2.0/. using System.Collections.Generic; - -using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; namespace DSharpPlus.Internal.Abstractions.Rest.Payloads; diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Channels/IModifyGuildChannelPayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Channels/IModifyGuildChannelPayload.cs index c9dc78c9af..83af0664af 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Channels/IModifyGuildChannelPayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Channels/IModifyGuildChannelPayload.cs @@ -3,9 +3,8 @@ // file, You can obtain one at https://mozilla.org/MPL/2.0/. using System.Collections.Generic; - -using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; namespace DSharpPlus.Internal.Abstractions.Rest.Payloads; diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Guilds/ICreateGuildChannelPayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Guilds/ICreateGuildChannelPayload.cs index 9dbdbcb83d..f8ec7e4cd6 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Guilds/ICreateGuildChannelPayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Guilds/ICreateGuildChannelPayload.cs @@ -3,9 +3,8 @@ // file, You can obtain one at https://mozilla.org/MPL/2.0/. using System.Collections.Generic; - -using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; namespace DSharpPlus.Internal.Abstractions.Rest.Payloads; diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Guilds/ICreateGuildPayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Guilds/ICreateGuildPayload.cs index eb5b4c2324..2cd1ec27b1 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Guilds/ICreateGuildPayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Guilds/ICreateGuildPayload.cs @@ -3,9 +3,8 @@ // file, You can obtain one at https://mozilla.org/MPL/2.0/. using System.Collections.Generic; - -using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; namespace DSharpPlus.Internal.Abstractions.Rest.Payloads; diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Guilds/IModifyGuildOnboardingPayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Guilds/IModifyGuildOnboardingPayload.cs index 217e8f2160..bd71569ab3 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Guilds/IModifyGuildOnboardingPayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Guilds/IModifyGuildOnboardingPayload.cs @@ -3,9 +3,8 @@ // file, You can obtain one at https://mozilla.org/MPL/2.0/. using System.Collections.Generic; - -using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; namespace DSharpPlus.Internal.Abstractions.Rest.Payloads; diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Interactions/ICreateFollowupMessagePayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Interactions/ICreateFollowupMessagePayload.cs index ea815fb8cc..a4783bb1ec 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Interactions/ICreateFollowupMessagePayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Interactions/ICreateFollowupMessagePayload.cs @@ -3,6 +3,7 @@ // file, You can obtain one at https://mozilla.org/MPL/2.0/. using System.Collections.Generic; + using DSharpPlus.Entities; using DSharpPlus.Internal.Abstractions.Models; diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/ScheduledEvents/ICreateGuildScheduledEventPayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/ScheduledEvents/ICreateGuildScheduledEventPayload.cs index fdfe3624c4..54b90cb383 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/ScheduledEvents/ICreateGuildScheduledEventPayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/ScheduledEvents/ICreateGuildScheduledEventPayload.cs @@ -3,9 +3,8 @@ // file, You can obtain one at https://mozilla.org/MPL/2.0/. using System; - -using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; namespace DSharpPlus.Internal.Abstractions.Rest.Payloads; @@ -32,7 +31,7 @@ public interface ICreateGuildScheduledEventPayload /// /// Privacy level for this scheduled event. /// - public DiscordScheduledEventPrivacyLevel PrivacyLevel { get;} + public DiscordScheduledEventPrivacyLevel PrivacyLevel { get; } /// /// Indicates the time at which this event is scheduled to start. diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/ScheduledEvents/IModifyGuildScheduledEventPayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/ScheduledEvents/IModifyGuildScheduledEventPayload.cs index 172dd0356f..cf48331e03 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/ScheduledEvents/IModifyGuildScheduledEventPayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/ScheduledEvents/IModifyGuildScheduledEventPayload.cs @@ -2,9 +2,9 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Internal.Abstractions.Models; -using DSharpPlus.Entities; using System; +using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; namespace DSharpPlus.Internal.Abstractions.Rest.Payloads; diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Webhooks/IExecuteWebhookPayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Webhooks/IExecuteWebhookPayload.cs index fa9b5de6ef..896a0bdd9e 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Webhooks/IExecuteWebhookPayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Webhooks/IExecuteWebhookPayload.cs @@ -3,6 +3,7 @@ // file, You can obtain one at https://mozilla.org/MPL/2.0/. using System.Collections.Generic; + using DSharpPlus.Entities; using DSharpPlus.Internal.Abstractions.Models; diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/ApplicationCommands/LocalizationQuery.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/ApplicationCommands/LocalizationQuery.cs index c23d63e641..91401d953a 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/ApplicationCommands/LocalizationQuery.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/ApplicationCommands/LocalizationQuery.cs @@ -14,4 +14,4 @@ public readonly record struct LocalizationQuery /// Indicates whether to include command localizations with the command object. /// public bool? WithLocalizations { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/AuditLogs/ListGuildAuditLogEntriesQuery.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/AuditLogs/ListGuildAuditLogEntriesQuery.cs index 602fc06e3d..72ca146cc1 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/AuditLogs/ListGuildAuditLogEntriesQuery.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/AuditLogs/ListGuildAuditLogEntriesQuery.cs @@ -35,4 +35,4 @@ namespace DSharpPlus.Internal.Abstractions.Rest.Queries; /// The maximum number of entries, between 1 and 100. /// public int? Limit { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Channels/GetChannelMessagesQuery.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Channels/GetChannelMessagesQuery.cs index ad429c22eb..c9b9fdb4bf 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Channels/GetChannelMessagesQuery.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Channels/GetChannelMessagesQuery.cs @@ -31,4 +31,4 @@ namespace DSharpPlus.Internal.Abstractions.Rest.Queries; /// public int? Limit { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Channels/GetThreadMemberQuery.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Channels/GetThreadMemberQuery.cs index 1f67636c69..e9845f21e1 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Channels/GetThreadMemberQuery.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Channels/GetThreadMemberQuery.cs @@ -13,4 +13,4 @@ public readonly record struct GetThreadMemberQuery /// Specifies whether the returned thread member object should contain guild member data. /// public bool? WithMember { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Channels/ListArchivedThreadsQuery.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Channels/ListArchivedThreadsQuery.cs index 3dd7b75d0e..90bf67fca6 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Channels/ListArchivedThreadsQuery.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Channels/ListArchivedThreadsQuery.cs @@ -20,4 +20,4 @@ public readonly record struct ListArchivedThreadsQuery /// The maximum number of threads to return from this request. /// public int? Limit { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Channels/ListThreadMembersQuery.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Channels/ListThreadMembersQuery.cs index 79ca3fd520..6e3403c1f0 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Channels/ListThreadMembersQuery.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Channels/ListThreadMembersQuery.cs @@ -23,4 +23,4 @@ public readonly record struct ListThreadMembersQuery /// The maximum number of entities for this request. /// public int? Limit { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Entitlements/ListEntitlementsQuery.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Entitlements/ListEntitlementsQuery.cs index e9eecc0aff..31af180917 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Entitlements/ListEntitlementsQuery.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Entitlements/ListEntitlementsQuery.cs @@ -37,4 +37,4 @@ namespace DSharpPlus.Internal.Abstractions.Rest.Queries; /// Specifies whether or not to include ended entitlements. /// public bool? ExcludeEnded { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/ForwardsPaginatedQuery.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/ForwardsPaginatedQuery.cs index ee1a7832b7..36e1f9bf9f 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/ForwardsPaginatedQuery.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/ForwardsPaginatedQuery.cs @@ -15,4 +15,4 @@ public readonly record struct ForwardsPaginatedQuery /// The maximum number of entities to return from this request. /// public int? Limit { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Guilds/GetGuildPruneCountQuery.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Guilds/GetGuildPruneCountQuery.cs index 92ed1d7b41..6d72eb416f 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Guilds/GetGuildPruneCountQuery.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Guilds/GetGuildPruneCountQuery.cs @@ -22,4 +22,4 @@ public readonly record struct GetGuildPruneCountQuery /// not listed here will not be included in the count. /// public string? IncludeRoles { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Guilds/GetGuildQuery.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Guilds/GetGuildQuery.cs index abad8372f4..10940e7106 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Guilds/GetGuildQuery.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Guilds/GetGuildQuery.cs @@ -13,4 +13,4 @@ public readonly record struct GetGuildQuery /// Specifies whether the response should include online member counts. /// public bool? WithCounts { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/IPaginatedQuery.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/IPaginatedQuery.cs index c6f687ee9a..76052ec3c9 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/IPaginatedQuery.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/IPaginatedQuery.cs @@ -26,4 +26,4 @@ public interface IPaginatedQuery /// The maximum number of entities to return from this request. /// public int? Limit { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Invites/GetInviteQuery.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Invites/GetInviteQuery.cs index a998ba0454..fa79debee5 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Invites/GetInviteQuery.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Invites/GetInviteQuery.cs @@ -23,4 +23,4 @@ public readonly record struct GetInviteQuery /// The snowflake identifier of the scheduled event to include with the invite. /// public Snowflake? GuildScheduledEventId { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/PaginatedQuery.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/PaginatedQuery.cs index ecc20c4919..31438fd908 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/PaginatedQuery.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/PaginatedQuery.cs @@ -17,4 +17,4 @@ namespace DSharpPlus.Internal.Abstractions.Rest.Queries; /// public int? Limit { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/ScheduledEvents/WithUserCountQuery.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/ScheduledEvents/WithUserCountQuery.cs index 8468eb750c..941e1df48e 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/ScheduledEvents/WithUserCountQuery.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/ScheduledEvents/WithUserCountQuery.cs @@ -13,4 +13,4 @@ public readonly record struct WithUserCountQuery /// Specifies whether to include user counts in the returned scheduled events. /// public bool? WithUserCount { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Webhooks/ExecuteWebhookQuery.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Webhooks/ExecuteWebhookQuery.cs index 4ed17f4f80..3d9bff6976 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Webhooks/ExecuteWebhookQuery.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Webhooks/ExecuteWebhookQuery.cs @@ -24,4 +24,4 @@ public readonly record struct ExecuteWebhookQuery /// webhook can be passed. /// public Snowflake? ThreadId { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Webhooks/ThreadIdQuery.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Webhooks/ThreadIdQuery.cs index a93d454854..6b3910bda9 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Webhooks/ThreadIdQuery.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Webhooks/ThreadIdQuery.cs @@ -15,4 +15,4 @@ public readonly record struct ThreadIdQuery /// as the webhook can be passed. /// public Snowflake? ThreadId { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Responses/CreateApplicationCommandResponse.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Responses/CreateApplicationCommandResponse.cs index e97a874bc8..50ee22a31f 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/Responses/CreateApplicationCommandResponse.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Responses/CreateApplicationCommandResponse.cs @@ -14,7 +14,7 @@ public readonly record struct CreateApplicationCommandResponse /// /// Indicates whether this command was newly created or whether it already existed. /// - public required bool IsNewlyCreated { get; init; } + public required bool IsNewlyCreated { get; init; } /// /// The created command. diff --git a/src/core/DSharpPlus.Internal.Models/ApplicationCommands/ApplicationCommandOption.cs b/src/core/DSharpPlus.Internal.Models/ApplicationCommands/ApplicationCommandOption.cs index bff9107100..be38909503 100644 --- a/src/core/DSharpPlus.Internal.Models/ApplicationCommands/ApplicationCommandOption.cs +++ b/src/core/DSharpPlus.Internal.Models/ApplicationCommands/ApplicationCommandOption.cs @@ -55,4 +55,4 @@ public sealed record ApplicationCommandOption : IApplicationCommandOption /// public Optional Autocomplete { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/ApplicationCommands/ApplicationCommandOptionChoice.cs b/src/core/DSharpPlus.Internal.Models/ApplicationCommands/ApplicationCommandOptionChoice.cs index a3a9747a4e..85c0e2b2d5 100644 --- a/src/core/DSharpPlus.Internal.Models/ApplicationCommands/ApplicationCommandOptionChoice.cs +++ b/src/core/DSharpPlus.Internal.Models/ApplicationCommands/ApplicationCommandOptionChoice.cs @@ -21,4 +21,4 @@ public sealed record ApplicationCommandOptionChoice : IApplicationCommandOptionC /// public required OneOf Value { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/ApplicationCommands/ApplicationCommandPermission.cs b/src/core/DSharpPlus.Internal.Models/ApplicationCommands/ApplicationCommandPermission.cs index 9cf1645161..003518e08d 100644 --- a/src/core/DSharpPlus.Internal.Models/ApplicationCommands/ApplicationCommandPermission.cs +++ b/src/core/DSharpPlus.Internal.Models/ApplicationCommands/ApplicationCommandPermission.cs @@ -18,4 +18,4 @@ public sealed record ApplicationCommandPermission : IApplicationCommandPermissio /// public required bool Permission { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/ApplicationCommands/ApplicationCommandPermissions.cs b/src/core/DSharpPlus.Internal.Models/ApplicationCommands/ApplicationCommandPermissions.cs index 9196643e9b..0066c2f948 100644 --- a/src/core/DSharpPlus.Internal.Models/ApplicationCommands/ApplicationCommandPermissions.cs +++ b/src/core/DSharpPlus.Internal.Models/ApplicationCommands/ApplicationCommandPermissions.cs @@ -22,4 +22,4 @@ public sealed record ApplicationCommandPermissions : IApplicationCommandPermissi /// public required IReadOnlyList Permissions { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/ApplicationCommands/PartialApplicationCommandPermissions.cs b/src/core/DSharpPlus.Internal.Models/ApplicationCommands/PartialApplicationCommandPermissions.cs index 1981540df8..0c0bd49695 100644 --- a/src/core/DSharpPlus.Internal.Models/ApplicationCommands/PartialApplicationCommandPermissions.cs +++ b/src/core/DSharpPlus.Internal.Models/ApplicationCommands/PartialApplicationCommandPermissions.cs @@ -22,4 +22,4 @@ public sealed record PartialApplicationCommandPermissions : IPartialApplicationC /// public Optional> Permissions { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/Applications/InstallParameters.cs b/src/core/DSharpPlus.Internal.Models/Applications/InstallParameters.cs index 05378c8034..93b028aaeb 100644 --- a/src/core/DSharpPlus.Internal.Models/Applications/InstallParameters.cs +++ b/src/core/DSharpPlus.Internal.Models/Applications/InstallParameters.cs @@ -17,4 +17,4 @@ public sealed record InstallParameters : IInstallParameters /// public required DiscordPermissions Permissions { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/AuditLogs/AuditLog.cs b/src/core/DSharpPlus.Internal.Models/AuditLogs/AuditLog.cs index 7bddd18cf2..7dd525dd57 100644 --- a/src/core/DSharpPlus.Internal.Models/AuditLogs/AuditLog.cs +++ b/src/core/DSharpPlus.Internal.Models/AuditLogs/AuditLog.cs @@ -34,4 +34,4 @@ public sealed record AuditLog : IAuditLog /// public required IReadOnlyList Webhooks { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/AuditLogs/AuditLogChange.cs b/src/core/DSharpPlus.Internal.Models/AuditLogs/AuditLogChange.cs index 851289f358..c5f7fd8037 100644 --- a/src/core/DSharpPlus.Internal.Models/AuditLogs/AuditLogChange.cs +++ b/src/core/DSharpPlus.Internal.Models/AuditLogs/AuditLogChange.cs @@ -17,4 +17,4 @@ public sealed record AuditLogChange : IAuditLogChange /// public required string Key { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/AuditLogs/AuditLogEntry.cs b/src/core/DSharpPlus.Internal.Models/AuditLogs/AuditLogEntry.cs index 070074845f..1fa0fd9d5e 100644 --- a/src/core/DSharpPlus.Internal.Models/AuditLogs/AuditLogEntry.cs +++ b/src/core/DSharpPlus.Internal.Models/AuditLogs/AuditLogEntry.cs @@ -34,4 +34,4 @@ public sealed record AuditLogEntry : IAuditLogEntry /// public Optional Reason { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/AuditLogs/AuditLogEntryInfo.cs b/src/core/DSharpPlus.Internal.Models/AuditLogs/AuditLogEntryInfo.cs index 0eccde3cd8..2c10286b2e 100644 --- a/src/core/DSharpPlus.Internal.Models/AuditLogs/AuditLogEntryInfo.cs +++ b/src/core/DSharpPlus.Internal.Models/AuditLogs/AuditLogEntryInfo.cs @@ -41,4 +41,4 @@ public sealed record AuditLogEntryInfo : IAuditLogEntryInfo /// public Optional Type { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/AutoModeration/AutoModerationAction.cs b/src/core/DSharpPlus.Internal.Models/AutoModeration/AutoModerationAction.cs index 6b4829a76e..81cd5b58c0 100644 --- a/src/core/DSharpPlus.Internal.Models/AutoModeration/AutoModerationAction.cs +++ b/src/core/DSharpPlus.Internal.Models/AutoModeration/AutoModerationAction.cs @@ -15,4 +15,4 @@ public sealed record AutoModerationAction : IAutoModerationAction /// public Optional Metadata { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/AutoModeration/AutoModerationActionMetadata.cs b/src/core/DSharpPlus.Internal.Models/AutoModeration/AutoModerationActionMetadata.cs index 728f3aea11..cd977e68c4 100644 --- a/src/core/DSharpPlus.Internal.Models/AutoModeration/AutoModerationActionMetadata.cs +++ b/src/core/DSharpPlus.Internal.Models/AutoModeration/AutoModerationActionMetadata.cs @@ -9,4 +9,4 @@ namespace DSharpPlus.Internal.Models; /// /// Placeholder implementation of a marker interface. Please report spotting this to library developers. /// -internal sealed record AutoModerationActionMetadata : IAutoModerationActionMetadata; \ No newline at end of file +internal sealed record AutoModerationActionMetadata : IAutoModerationActionMetadata; diff --git a/src/core/DSharpPlus.Internal.Models/AutoModeration/AutoModerationRule.cs b/src/core/DSharpPlus.Internal.Models/AutoModeration/AutoModerationRule.cs index 8b54fdd4f0..e35f12a6cb 100644 --- a/src/core/DSharpPlus.Internal.Models/AutoModeration/AutoModerationRule.cs +++ b/src/core/DSharpPlus.Internal.Models/AutoModeration/AutoModerationRule.cs @@ -44,4 +44,4 @@ public sealed record AutoModerationRule : IAutoModerationRule /// public required IReadOnlyList ExemptChannels { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/AutoModeration/AutoModerationTriggerMetadata.cs b/src/core/DSharpPlus.Internal.Models/AutoModeration/AutoModerationTriggerMetadata.cs index fedb2b02be..5aae09b169 100644 --- a/src/core/DSharpPlus.Internal.Models/AutoModeration/AutoModerationTriggerMetadata.cs +++ b/src/core/DSharpPlus.Internal.Models/AutoModeration/AutoModerationTriggerMetadata.cs @@ -29,4 +29,4 @@ public sealed record AutoModerationTriggerMetadata : IAutoModerationTriggerMetad /// public Optional MentionRaidProtectionEnabled { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/AutoModeration/BlockMessageActionMetadata.cs b/src/core/DSharpPlus.Internal.Models/AutoModeration/BlockMessageActionMetadata.cs index 5c6719126b..450b757f92 100644 --- a/src/core/DSharpPlus.Internal.Models/AutoModeration/BlockMessageActionMetadata.cs +++ b/src/core/DSharpPlus.Internal.Models/AutoModeration/BlockMessageActionMetadata.cs @@ -12,4 +12,4 @@ public sealed record BlockMessageActionMetadata : IBlockMessageActionMetadata { /// public Optional CustomMessage { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/AutoModeration/PartialAutoModerationRule.cs b/src/core/DSharpPlus.Internal.Models/AutoModeration/PartialAutoModerationRule.cs index 5d5107bee0..774b8b65f9 100644 --- a/src/core/DSharpPlus.Internal.Models/AutoModeration/PartialAutoModerationRule.cs +++ b/src/core/DSharpPlus.Internal.Models/AutoModeration/PartialAutoModerationRule.cs @@ -44,4 +44,4 @@ public sealed record PartialAutoModerationRule : IPartialAutoModerationRule /// public Optional> ExemptChannels { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/AutoModeration/SendAlertMessageActionMetadata.cs b/src/core/DSharpPlus.Internal.Models/AutoModeration/SendAlertMessageActionMetadata.cs index f96df74c97..6e9bef62cf 100644 --- a/src/core/DSharpPlus.Internal.Models/AutoModeration/SendAlertMessageActionMetadata.cs +++ b/src/core/DSharpPlus.Internal.Models/AutoModeration/SendAlertMessageActionMetadata.cs @@ -12,4 +12,4 @@ public sealed record SendAlertMessageActionMetadata : ISendAlertMessageActionMet { /// public required Snowflake ChannelId { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/AutoModeration/TimeoutActionMetadata.cs b/src/core/DSharpPlus.Internal.Models/AutoModeration/TimeoutActionMetadata.cs index 0f31482a86..364e06a2bc 100644 --- a/src/core/DSharpPlus.Internal.Models/AutoModeration/TimeoutActionMetadata.cs +++ b/src/core/DSharpPlus.Internal.Models/AutoModeration/TimeoutActionMetadata.cs @@ -12,4 +12,4 @@ public sealed record TimeoutActionMetadata : ITimeoutActionMetadata { /// public required int DurationSeconds { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/Channels/AllowedMentions.cs b/src/core/DSharpPlus.Internal.Models/Channels/AllowedMentions.cs index 2e75c35dd4..8db12ecd5a 100644 --- a/src/core/DSharpPlus.Internal.Models/Channels/AllowedMentions.cs +++ b/src/core/DSharpPlus.Internal.Models/Channels/AllowedMentions.cs @@ -22,4 +22,4 @@ public sealed record AllowedMentions : IAllowedMentions /// public Optional RepliedUser { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/Channels/Attachment.cs b/src/core/DSharpPlus.Internal.Models/Channels/Attachment.cs index edaeb716f7..ee62553829 100644 --- a/src/core/DSharpPlus.Internal.Models/Channels/Attachment.cs +++ b/src/core/DSharpPlus.Internal.Models/Channels/Attachment.cs @@ -50,4 +50,4 @@ public sealed record Attachment : IAttachment /// public Optional Flags { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/Channels/Channel.cs b/src/core/DSharpPlus.Internal.Models/Channels/Channel.cs index d561f36344..f64a533dcb 100644 --- a/src/core/DSharpPlus.Internal.Models/Channels/Channel.cs +++ b/src/core/DSharpPlus.Internal.Models/Channels/Channel.cs @@ -117,4 +117,4 @@ public sealed record Channel : IChannel /// public Optional DefaultForumLayout { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/Channels/ChannelMention.cs b/src/core/DSharpPlus.Internal.Models/Channels/ChannelMention.cs index cd2e870b7f..26cb1050e4 100644 --- a/src/core/DSharpPlus.Internal.Models/Channels/ChannelMention.cs +++ b/src/core/DSharpPlus.Internal.Models/Channels/ChannelMention.cs @@ -21,4 +21,4 @@ public sealed record ChannelMention : IChannelMention /// public required string Name { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/Channels/ChannelOverwrite.cs b/src/core/DSharpPlus.Internal.Models/Channels/ChannelOverwrite.cs index ee5d3f904a..148266e5b7 100644 --- a/src/core/DSharpPlus.Internal.Models/Channels/ChannelOverwrite.cs +++ b/src/core/DSharpPlus.Internal.Models/Channels/ChannelOverwrite.cs @@ -21,4 +21,4 @@ public sealed record ChannelOverwrite : IChannelOverwrite /// public required DiscordPermissions Deny { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/Channels/DefaultReaction.cs b/src/core/DSharpPlus.Internal.Models/Channels/DefaultReaction.cs index 3bd156f0c0..0e35da28ee 100644 --- a/src/core/DSharpPlus.Internal.Models/Channels/DefaultReaction.cs +++ b/src/core/DSharpPlus.Internal.Models/Channels/DefaultReaction.cs @@ -14,4 +14,4 @@ public sealed record DefaultReaction : IDefaultReaction /// public string? EmojiName { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/Channels/Embed.cs b/src/core/DSharpPlus.Internal.Models/Channels/Embed.cs index 54f3ac7732..8b3cb3d436 100644 --- a/src/core/DSharpPlus.Internal.Models/Channels/Embed.cs +++ b/src/core/DSharpPlus.Internal.Models/Channels/Embed.cs @@ -50,4 +50,4 @@ public sealed record Embed : IEmbed /// public Optional> Fields { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/Channels/EmbedAuthor.cs b/src/core/DSharpPlus.Internal.Models/Channels/EmbedAuthor.cs index a70c637dcb..561ee08cfa 100644 --- a/src/core/DSharpPlus.Internal.Models/Channels/EmbedAuthor.cs +++ b/src/core/DSharpPlus.Internal.Models/Channels/EmbedAuthor.cs @@ -20,4 +20,4 @@ public sealed record EmbedAuthor : IEmbedAuthor /// public Optional ProxyIconUrl { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/Channels/EmbedField.cs b/src/core/DSharpPlus.Internal.Models/Channels/EmbedField.cs index dfba94145a..493d2ec019 100644 --- a/src/core/DSharpPlus.Internal.Models/Channels/EmbedField.cs +++ b/src/core/DSharpPlus.Internal.Models/Channels/EmbedField.cs @@ -17,4 +17,4 @@ public sealed record EmbedField : IEmbedField /// public Optional Inline { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/Channels/EmbedFooter.cs b/src/core/DSharpPlus.Internal.Models/Channels/EmbedFooter.cs index 9386af213f..8cb5ac0dc6 100644 --- a/src/core/DSharpPlus.Internal.Models/Channels/EmbedFooter.cs +++ b/src/core/DSharpPlus.Internal.Models/Channels/EmbedFooter.cs @@ -17,4 +17,4 @@ public sealed record EmbedFooter : IEmbedFooter /// public Optional ProxyIconUrl { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/Channels/EmbedImage.cs b/src/core/DSharpPlus.Internal.Models/Channels/EmbedImage.cs index 5e2f47bd72..6c81869ae0 100644 --- a/src/core/DSharpPlus.Internal.Models/Channels/EmbedImage.cs +++ b/src/core/DSharpPlus.Internal.Models/Channels/EmbedImage.cs @@ -20,4 +20,4 @@ public sealed record EmbedImage : IEmbedImage /// public Optional Width { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/Channels/EmbedProvider.cs b/src/core/DSharpPlus.Internal.Models/Channels/EmbedProvider.cs index 531c8908a5..59b63a530c 100644 --- a/src/core/DSharpPlus.Internal.Models/Channels/EmbedProvider.cs +++ b/src/core/DSharpPlus.Internal.Models/Channels/EmbedProvider.cs @@ -14,4 +14,4 @@ public sealed record EmbedProvider : IEmbedProvider /// public Optional Url { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/Channels/EmbedThumbnail.cs b/src/core/DSharpPlus.Internal.Models/Channels/EmbedThumbnail.cs index 26db818a6f..d4a512fbc2 100644 --- a/src/core/DSharpPlus.Internal.Models/Channels/EmbedThumbnail.cs +++ b/src/core/DSharpPlus.Internal.Models/Channels/EmbedThumbnail.cs @@ -20,4 +20,4 @@ public sealed record EmbedThumbnail : IEmbedThumbnail /// public Optional Width { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/Channels/EmbedVideo.cs b/src/core/DSharpPlus.Internal.Models/Channels/EmbedVideo.cs index f1df768180..14a58635de 100644 --- a/src/core/DSharpPlus.Internal.Models/Channels/EmbedVideo.cs +++ b/src/core/DSharpPlus.Internal.Models/Channels/EmbedVideo.cs @@ -20,4 +20,4 @@ public sealed record EmbedVideo : IEmbedVideo /// public Optional Width { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/Channels/FollowedChannel.cs b/src/core/DSharpPlus.Internal.Models/Channels/FollowedChannel.cs index 56e488d6a8..d6748dc27d 100644 --- a/src/core/DSharpPlus.Internal.Models/Channels/FollowedChannel.cs +++ b/src/core/DSharpPlus.Internal.Models/Channels/FollowedChannel.cs @@ -14,4 +14,4 @@ public sealed record FollowedChannel : IFollowedChannel /// public required Snowflake WebhookId { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/Channels/ForumTag.cs b/src/core/DSharpPlus.Internal.Models/Channels/ForumTag.cs index f093919ab6..e81c27a394 100644 --- a/src/core/DSharpPlus.Internal.Models/Channels/ForumTag.cs +++ b/src/core/DSharpPlus.Internal.Models/Channels/ForumTag.cs @@ -23,4 +23,4 @@ public sealed record ForumTag : IForumTag /// public string? EmojiName { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/Channels/MessageActivity.cs b/src/core/DSharpPlus.Internal.Models/Channels/MessageActivity.cs index 9051e346e9..e22f4e16e2 100644 --- a/src/core/DSharpPlus.Internal.Models/Channels/MessageActivity.cs +++ b/src/core/DSharpPlus.Internal.Models/Channels/MessageActivity.cs @@ -15,4 +15,4 @@ public sealed record MessageActivity : IMessageActivity /// public Optional PartyId { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/Channels/MessageReference.cs b/src/core/DSharpPlus.Internal.Models/Channels/MessageReference.cs index b47e7ea778..0c2a3c8178 100644 --- a/src/core/DSharpPlus.Internal.Models/Channels/MessageReference.cs +++ b/src/core/DSharpPlus.Internal.Models/Channels/MessageReference.cs @@ -20,4 +20,4 @@ public sealed record MessageReference : IMessageReference /// public Optional FailIfNotExists { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/Channels/PartialAttachment.cs b/src/core/DSharpPlus.Internal.Models/Channels/PartialAttachment.cs index e3bd350100..8a5e1f532d 100644 --- a/src/core/DSharpPlus.Internal.Models/Channels/PartialAttachment.cs +++ b/src/core/DSharpPlus.Internal.Models/Channels/PartialAttachment.cs @@ -50,4 +50,4 @@ public sealed record PartialAttachment : IPartialAttachment /// public Optional Flags { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/Channels/PartialChannel.cs b/src/core/DSharpPlus.Internal.Models/Channels/PartialChannel.cs index 041c876fa3..9c100a299e 100644 --- a/src/core/DSharpPlus.Internal.Models/Channels/PartialChannel.cs +++ b/src/core/DSharpPlus.Internal.Models/Channels/PartialChannel.cs @@ -117,4 +117,4 @@ public sealed record PartialChannel : IPartialChannel /// public Optional DefaultForumLayout { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/Channels/PartialChannelOverwrite.cs b/src/core/DSharpPlus.Internal.Models/Channels/PartialChannelOverwrite.cs index f4bd0c06ea..24bee8573d 100644 --- a/src/core/DSharpPlus.Internal.Models/Channels/PartialChannelOverwrite.cs +++ b/src/core/DSharpPlus.Internal.Models/Channels/PartialChannelOverwrite.cs @@ -21,4 +21,4 @@ public sealed record PartialChannelOverwrite : IPartialChannelOverwrite /// public Optional Deny { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/Channels/Reaction.cs b/src/core/DSharpPlus.Internal.Models/Channels/Reaction.cs index c404d3204e..1774bfdfa0 100644 --- a/src/core/DSharpPlus.Internal.Models/Channels/Reaction.cs +++ b/src/core/DSharpPlus.Internal.Models/Channels/Reaction.cs @@ -17,4 +17,4 @@ public sealed record Reaction : IReaction /// public required IPartialEmoji Emoji { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/Channels/RoleSubscriptionData.cs b/src/core/DSharpPlus.Internal.Models/Channels/RoleSubscriptionData.cs index 8673710cec..b4962d4ee6 100644 --- a/src/core/DSharpPlus.Internal.Models/Channels/RoleSubscriptionData.cs +++ b/src/core/DSharpPlus.Internal.Models/Channels/RoleSubscriptionData.cs @@ -20,4 +20,4 @@ public sealed record RoleSubscriptionData : IRoleSubscriptionData /// public required bool IsRenewal { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/Channels/ThreadMember.cs b/src/core/DSharpPlus.Internal.Models/Channels/ThreadMember.cs index f67558eb8f..fabc2a036d 100644 --- a/src/core/DSharpPlus.Internal.Models/Channels/ThreadMember.cs +++ b/src/core/DSharpPlus.Internal.Models/Channels/ThreadMember.cs @@ -25,4 +25,4 @@ public sealed record ThreadMember : IThreadMember /// public Optional Member { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/Channels/ThreadMetadata.cs b/src/core/DSharpPlus.Internal.Models/Channels/ThreadMetadata.cs index 6e39227a19..47327b3197 100644 --- a/src/core/DSharpPlus.Internal.Models/Channels/ThreadMetadata.cs +++ b/src/core/DSharpPlus.Internal.Models/Channels/ThreadMetadata.cs @@ -28,4 +28,4 @@ public sealed record ThreadMetadata : IThreadMetadata /// public Optional CreateTimestamp { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/Emojis/Emoji.cs b/src/core/DSharpPlus.Internal.Models/Emojis/Emoji.cs index e4a57379c2..bb0542d2f8 100644 --- a/src/core/DSharpPlus.Internal.Models/Emojis/Emoji.cs +++ b/src/core/DSharpPlus.Internal.Models/Emojis/Emoji.cs @@ -34,4 +34,4 @@ public sealed record Emoji : IEmoji /// public Optional Available { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/Emojis/PartialEmoji.cs b/src/core/DSharpPlus.Internal.Models/Emojis/PartialEmoji.cs index f0cca2d9d0..4fb192ce1f 100644 --- a/src/core/DSharpPlus.Internal.Models/Emojis/PartialEmoji.cs +++ b/src/core/DSharpPlus.Internal.Models/Emojis/PartialEmoji.cs @@ -34,4 +34,4 @@ public sealed record PartialEmoji : IPartialEmoji /// public Optional Available { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/Entitlements/Entitlement.cs b/src/core/DSharpPlus.Internal.Models/Entitlements/Entitlement.cs index 5a41631112..8f2eb2141f 100644 --- a/src/core/DSharpPlus.Internal.Models/Entitlements/Entitlement.cs +++ b/src/core/DSharpPlus.Internal.Models/Entitlements/Entitlement.cs @@ -38,4 +38,4 @@ public sealed record Entitlement : IEntitlement /// public Optional EndsAt { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/Entitlements/PartialEntitlement.cs b/src/core/DSharpPlus.Internal.Models/Entitlements/PartialEntitlement.cs index 23330c235d..f9bf5d596e 100644 --- a/src/core/DSharpPlus.Internal.Models/Entitlements/PartialEntitlement.cs +++ b/src/core/DSharpPlus.Internal.Models/Entitlements/PartialEntitlement.cs @@ -38,4 +38,4 @@ public sealed record PartialEntitlement : IPartialEntitlement /// public Optional EndsAt { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/GuildTemplates/Template.cs b/src/core/DSharpPlus.Internal.Models/GuildTemplates/Template.cs index e77bba318b..95c3c4732c 100644 --- a/src/core/DSharpPlus.Internal.Models/GuildTemplates/Template.cs +++ b/src/core/DSharpPlus.Internal.Models/GuildTemplates/Template.cs @@ -43,4 +43,4 @@ public sealed record Template : ITemplate /// public bool? IsDirty { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/Guilds/Ban.cs b/src/core/DSharpPlus.Internal.Models/Guilds/Ban.cs index ed0925016a..cd4694c540 100644 --- a/src/core/DSharpPlus.Internal.Models/Guilds/Ban.cs +++ b/src/core/DSharpPlus.Internal.Models/Guilds/Ban.cs @@ -14,4 +14,4 @@ public sealed record Ban : IBan /// public required IUser User { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/Guilds/Guild.cs b/src/core/DSharpPlus.Internal.Models/Guilds/Guild.cs index 89845799b0..0a2d6d387a 100644 --- a/src/core/DSharpPlus.Internal.Models/Guilds/Guild.cs +++ b/src/core/DSharpPlus.Internal.Models/Guilds/Guild.cs @@ -137,4 +137,4 @@ public sealed record Guild : IGuild /// public Snowflake? SafetyAlertsChannelId { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/Guilds/GuildMember.cs b/src/core/DSharpPlus.Internal.Models/Guilds/GuildMember.cs index ccee97e284..6995a030fd 100644 --- a/src/core/DSharpPlus.Internal.Models/Guilds/GuildMember.cs +++ b/src/core/DSharpPlus.Internal.Models/Guilds/GuildMember.cs @@ -48,4 +48,4 @@ public sealed record GuildMember : IGuildMember /// public Optional CommunicationDisabledUntil { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/Guilds/GuildPreview.cs b/src/core/DSharpPlus.Internal.Models/Guilds/GuildPreview.cs index 11e6580e45..f6e8226d16 100644 --- a/src/core/DSharpPlus.Internal.Models/Guilds/GuildPreview.cs +++ b/src/core/DSharpPlus.Internal.Models/Guilds/GuildPreview.cs @@ -43,4 +43,4 @@ public sealed record GuildPreview : IGuildPreview /// public required IReadOnlyList Stickers { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/Guilds/GuildWidget.cs b/src/core/DSharpPlus.Internal.Models/Guilds/GuildWidget.cs index 656c3ec21d..42aeafbfe4 100644 --- a/src/core/DSharpPlus.Internal.Models/Guilds/GuildWidget.cs +++ b/src/core/DSharpPlus.Internal.Models/Guilds/GuildWidget.cs @@ -28,4 +28,4 @@ public sealed record GuildWidget : IGuildWidget /// public required int PresenceCount { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/Guilds/GuildWidgetSettings.cs b/src/core/DSharpPlus.Internal.Models/Guilds/GuildWidgetSettings.cs index 75e96dca25..ba4ba8f80f 100644 --- a/src/core/DSharpPlus.Internal.Models/Guilds/GuildWidgetSettings.cs +++ b/src/core/DSharpPlus.Internal.Models/Guilds/GuildWidgetSettings.cs @@ -14,4 +14,4 @@ public sealed record GuildWidgetSettings : IGuildWidgetSettings /// public Snowflake? ChannelId { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/Guilds/Integration.cs b/src/core/DSharpPlus.Internal.Models/Guilds/Integration.cs index ab433b198b..476db799dd 100644 --- a/src/core/DSharpPlus.Internal.Models/Guilds/Integration.cs +++ b/src/core/DSharpPlus.Internal.Models/Guilds/Integration.cs @@ -60,4 +60,4 @@ public sealed record Integration : IIntegration /// public Optional> Scopes { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/Guilds/IntegrationAccount.cs b/src/core/DSharpPlus.Internal.Models/Guilds/IntegrationAccount.cs index 00edc79b1a..e229d5eafb 100644 --- a/src/core/DSharpPlus.Internal.Models/Guilds/IntegrationAccount.cs +++ b/src/core/DSharpPlus.Internal.Models/Guilds/IntegrationAccount.cs @@ -14,4 +14,4 @@ public sealed record IntegrationAccount : IIntegrationAccount /// public required string Name { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/Guilds/IntegrationApplication.cs b/src/core/DSharpPlus.Internal.Models/Guilds/IntegrationApplication.cs index a0e94792ac..c9b3d7bd6e 100644 --- a/src/core/DSharpPlus.Internal.Models/Guilds/IntegrationApplication.cs +++ b/src/core/DSharpPlus.Internal.Models/Guilds/IntegrationApplication.cs @@ -23,4 +23,4 @@ public sealed record IntegrationApplication : IIntegrationApplication /// public Optional Bot { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/Guilds/Onboarding.cs b/src/core/DSharpPlus.Internal.Models/Guilds/Onboarding.cs index 0871b3eb81..03ac3cea95 100644 --- a/src/core/DSharpPlus.Internal.Models/Guilds/Onboarding.cs +++ b/src/core/DSharpPlus.Internal.Models/Guilds/Onboarding.cs @@ -26,4 +26,4 @@ public sealed record Onboarding : IOnboarding /// public required DiscordGuildOnboardingPromptType Mode { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/Guilds/OnboardingPrompt.cs b/src/core/DSharpPlus.Internal.Models/Guilds/OnboardingPrompt.cs index 7124867ce4..34df643e52 100644 --- a/src/core/DSharpPlus.Internal.Models/Guilds/OnboardingPrompt.cs +++ b/src/core/DSharpPlus.Internal.Models/Guilds/OnboardingPrompt.cs @@ -32,4 +32,4 @@ public sealed record OnboardingPrompt : IOnboardingPrompt /// public required bool InOnboarding { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/Guilds/OnboardingPromptOption.cs b/src/core/DSharpPlus.Internal.Models/Guilds/OnboardingPromptOption.cs index 94aadad807..dcb178d0bf 100644 --- a/src/core/DSharpPlus.Internal.Models/Guilds/OnboardingPromptOption.cs +++ b/src/core/DSharpPlus.Internal.Models/Guilds/OnboardingPromptOption.cs @@ -37,4 +37,4 @@ public sealed record OnboardingPromptOption : IOnboardingPromptOption /// public string? Description { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/Guilds/PartialGuild.cs b/src/core/DSharpPlus.Internal.Models/Guilds/PartialGuild.cs index 2860f20e4d..e4054c0a7c 100644 --- a/src/core/DSharpPlus.Internal.Models/Guilds/PartialGuild.cs +++ b/src/core/DSharpPlus.Internal.Models/Guilds/PartialGuild.cs @@ -137,4 +137,4 @@ public sealed record PartialGuild : IPartialGuild /// public Optional SafetyAlertsChannelId { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/Guilds/PartialGuildMember.cs b/src/core/DSharpPlus.Internal.Models/Guilds/PartialGuildMember.cs index 757f21e718..989225cfb9 100644 --- a/src/core/DSharpPlus.Internal.Models/Guilds/PartialGuildMember.cs +++ b/src/core/DSharpPlus.Internal.Models/Guilds/PartialGuildMember.cs @@ -48,4 +48,4 @@ public sealed record PartialGuildMember : IPartialGuildMember /// public Optional CommunicationDisabledUntil { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/Guilds/PartialIntegration.cs b/src/core/DSharpPlus.Internal.Models/Guilds/PartialIntegration.cs index e3ca0c85d1..bb27b3aca6 100644 --- a/src/core/DSharpPlus.Internal.Models/Guilds/PartialIntegration.cs +++ b/src/core/DSharpPlus.Internal.Models/Guilds/PartialIntegration.cs @@ -60,4 +60,4 @@ public sealed record PartialIntegration : IPartialIntegration /// public Optional> Scopes { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/Guilds/PartialRole.cs b/src/core/DSharpPlus.Internal.Models/Guilds/PartialRole.cs index 1c3741e3ad..9c3c6be1c7 100644 --- a/src/core/DSharpPlus.Internal.Models/Guilds/PartialRole.cs +++ b/src/core/DSharpPlus.Internal.Models/Guilds/PartialRole.cs @@ -45,4 +45,4 @@ public sealed record PartialRole : IPartialRole /// public Optional Flags { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/Guilds/Role.cs b/src/core/DSharpPlus.Internal.Models/Guilds/Role.cs index e664623f06..c554e30469 100644 --- a/src/core/DSharpPlus.Internal.Models/Guilds/Role.cs +++ b/src/core/DSharpPlus.Internal.Models/Guilds/Role.cs @@ -45,4 +45,4 @@ public sealed record Role : IRole /// public required DiscordRoleFlags Flags { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/Guilds/RoleTags.cs b/src/core/DSharpPlus.Internal.Models/Guilds/RoleTags.cs index 86ed1616bc..1d9caff635 100644 --- a/src/core/DSharpPlus.Internal.Models/Guilds/RoleTags.cs +++ b/src/core/DSharpPlus.Internal.Models/Guilds/RoleTags.cs @@ -26,4 +26,4 @@ public sealed record RoleTags : IRoleTags /// public required bool GuildConnections { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/Guilds/WelcomeScreen.cs b/src/core/DSharpPlus.Internal.Models/Guilds/WelcomeScreen.cs index 3282897a46..d119e123d4 100644 --- a/src/core/DSharpPlus.Internal.Models/Guilds/WelcomeScreen.cs +++ b/src/core/DSharpPlus.Internal.Models/Guilds/WelcomeScreen.cs @@ -16,4 +16,4 @@ public sealed record WelcomeScreen : IWelcomeScreen /// public required IReadOnlyList WelcomeChannels { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/Guilds/WelcomeScreenChannel.cs b/src/core/DSharpPlus.Internal.Models/Guilds/WelcomeScreenChannel.cs index fddbce72ae..2a0995c87e 100644 --- a/src/core/DSharpPlus.Internal.Models/Guilds/WelcomeScreenChannel.cs +++ b/src/core/DSharpPlus.Internal.Models/Guilds/WelcomeScreenChannel.cs @@ -20,4 +20,4 @@ public sealed record WelcomeScreenChannel : IWelcomeScreenChannel /// public string? EmojiName { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/Interactions/ApplicationCommandInteractionData.cs b/src/core/DSharpPlus.Internal.Models/Interactions/ApplicationCommandInteractionData.cs index 6336e0c4a1..1cab8a21d8 100644 --- a/src/core/DSharpPlus.Internal.Models/Interactions/ApplicationCommandInteractionData.cs +++ b/src/core/DSharpPlus.Internal.Models/Interactions/ApplicationCommandInteractionData.cs @@ -32,4 +32,4 @@ public sealed record ApplicationCommandInteractionData : IApplicationCommandInte /// public Optional TargetId { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/Interactions/ApplicationCommandInteractionDataOption.cs b/src/core/DSharpPlus.Internal.Models/Interactions/ApplicationCommandInteractionDataOption.cs index 0386534f0b..52aaddad88 100644 --- a/src/core/DSharpPlus.Internal.Models/Interactions/ApplicationCommandInteractionDataOption.cs +++ b/src/core/DSharpPlus.Internal.Models/Interactions/ApplicationCommandInteractionDataOption.cs @@ -28,4 +28,4 @@ public sealed record ApplicationCommandInteractionDataOption : IApplicationComma /// public Optional Focused { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/Interactions/AutocompleteCallbackData.cs b/src/core/DSharpPlus.Internal.Models/Interactions/AutocompleteCallbackData.cs index 6f7179f48f..73d90ff561 100644 --- a/src/core/DSharpPlus.Internal.Models/Interactions/AutocompleteCallbackData.cs +++ b/src/core/DSharpPlus.Internal.Models/Interactions/AutocompleteCallbackData.cs @@ -13,4 +13,4 @@ public sealed record AutocompleteCallbackData : IAutocompleteCallbackData { /// public required IReadOnlyList Choices { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/Interactions/InteractionResponse.cs b/src/core/DSharpPlus.Internal.Models/Interactions/InteractionResponse.cs index 7a492cf8a3..9d6879ab99 100644 --- a/src/core/DSharpPlus.Internal.Models/Interactions/InteractionResponse.cs +++ b/src/core/DSharpPlus.Internal.Models/Interactions/InteractionResponse.cs @@ -17,4 +17,4 @@ public sealed record InteractionResponse : IInteractionResponse /// public Optional> Data { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/Interactions/MessageComponentInteractionData.cs b/src/core/DSharpPlus.Internal.Models/Interactions/MessageComponentInteractionData.cs index 42fec00765..eeaf44f197 100644 --- a/src/core/DSharpPlus.Internal.Models/Interactions/MessageComponentInteractionData.cs +++ b/src/core/DSharpPlus.Internal.Models/Interactions/MessageComponentInteractionData.cs @@ -23,4 +23,4 @@ public sealed record MessageComponentInteractionData : IMessageComponentInteract /// public Optional Resolved { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/Interactions/ModalCallbackData.cs b/src/core/DSharpPlus.Internal.Models/Interactions/ModalCallbackData.cs index 67398d0b9c..d145ff0479 100644 --- a/src/core/DSharpPlus.Internal.Models/Interactions/ModalCallbackData.cs +++ b/src/core/DSharpPlus.Internal.Models/Interactions/ModalCallbackData.cs @@ -19,4 +19,4 @@ public sealed record ModalCallbackData : IModalCallbackData /// public required IReadOnlyList Components { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/Interactions/ModalInteractionData.cs b/src/core/DSharpPlus.Internal.Models/Interactions/ModalInteractionData.cs index 5263dee7fc..488f20579c 100644 --- a/src/core/DSharpPlus.Internal.Models/Interactions/ModalInteractionData.cs +++ b/src/core/DSharpPlus.Internal.Models/Interactions/ModalInteractionData.cs @@ -16,4 +16,4 @@ public sealed record ModalInteractionData : IModalInteractionData /// public required IReadOnlyList Components { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/Interactions/ResolvedData.cs b/src/core/DSharpPlus.Internal.Models/Interactions/ResolvedData.cs index 2b57cb7e4a..2963949a34 100644 --- a/src/core/DSharpPlus.Internal.Models/Interactions/ResolvedData.cs +++ b/src/core/DSharpPlus.Internal.Models/Interactions/ResolvedData.cs @@ -28,4 +28,4 @@ public sealed record ResolvedData : IResolvedData /// public Optional> Attachments { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/Invites/Invite.cs b/src/core/DSharpPlus.Internal.Models/Invites/Invite.cs index bea894b0e1..647142d9a2 100644 --- a/src/core/DSharpPlus.Internal.Models/Invites/Invite.cs +++ b/src/core/DSharpPlus.Internal.Models/Invites/Invite.cs @@ -59,4 +59,4 @@ public sealed record Invite : IInvite /// public Optional CreatedAt { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/Invites/PartialInvite.cs b/src/core/DSharpPlus.Internal.Models/Invites/PartialInvite.cs index 7aa243ea39..be5af8fca5 100644 --- a/src/core/DSharpPlus.Internal.Models/Invites/PartialInvite.cs +++ b/src/core/DSharpPlus.Internal.Models/Invites/PartialInvite.cs @@ -59,4 +59,4 @@ public sealed record PartialInvite : IPartialInvite /// public Optional CreatedAt { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/MessageComponents/ActionRowComponent.cs b/src/core/DSharpPlus.Internal.Models/MessageComponents/ActionRowComponent.cs index 5cfd073238..f063d5d1d8 100644 --- a/src/core/DSharpPlus.Internal.Models/MessageComponents/ActionRowComponent.cs +++ b/src/core/DSharpPlus.Internal.Models/MessageComponents/ActionRowComponent.cs @@ -17,4 +17,4 @@ public sealed record ActionRowComponent : IActionRowComponent /// public required IReadOnlyList Components { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/MessageComponents/ButtonComponent.cs b/src/core/DSharpPlus.Internal.Models/MessageComponents/ButtonComponent.cs index 1726964647..a64138a388 100644 --- a/src/core/DSharpPlus.Internal.Models/MessageComponents/ButtonComponent.cs +++ b/src/core/DSharpPlus.Internal.Models/MessageComponents/ButtonComponent.cs @@ -30,4 +30,4 @@ public sealed record ButtonComponent : IButtonComponent /// public Optional Disabled { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/MessageComponents/ChannelSelectComponent.cs b/src/core/DSharpPlus.Internal.Models/MessageComponents/ChannelSelectComponent.cs index 54025d7724..adaa26c995 100644 --- a/src/core/DSharpPlus.Internal.Models/MessageComponents/ChannelSelectComponent.cs +++ b/src/core/DSharpPlus.Internal.Models/MessageComponents/ChannelSelectComponent.cs @@ -35,4 +35,4 @@ public sealed record ChannelSelectComponent : IChannelSelectComponent /// public Optional Disabled { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/MessageComponents/DefaultSelectValue.cs b/src/core/DSharpPlus.Internal.Models/MessageComponents/DefaultSelectValue.cs index 80a96fa1ad..e8eb68efd2 100644 --- a/src/core/DSharpPlus.Internal.Models/MessageComponents/DefaultSelectValue.cs +++ b/src/core/DSharpPlus.Internal.Models/MessageComponents/DefaultSelectValue.cs @@ -14,4 +14,4 @@ public sealed record DefaultSelectValue : IDefaultSelectValue /// public required string Type { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/MessageComponents/InteractiveComponent.cs b/src/core/DSharpPlus.Internal.Models/MessageComponents/InteractiveComponent.cs index 5fa975e40f..5ad58968df 100644 --- a/src/core/DSharpPlus.Internal.Models/MessageComponents/InteractiveComponent.cs +++ b/src/core/DSharpPlus.Internal.Models/MessageComponents/InteractiveComponent.cs @@ -9,4 +9,4 @@ namespace DSharpPlus.Internal.Models; /// /// Placeholder implementation of a marker interface. Please report spotting this to library developers. /// -internal sealed record InteractiveComponent : IInteractiveComponent; \ No newline at end of file +internal sealed record InteractiveComponent : IInteractiveComponent; diff --git a/src/core/DSharpPlus.Internal.Models/MessageComponents/MentionableSelectComponent.cs b/src/core/DSharpPlus.Internal.Models/MessageComponents/MentionableSelectComponent.cs index 4132f05864..fdf65ec208 100644 --- a/src/core/DSharpPlus.Internal.Models/MessageComponents/MentionableSelectComponent.cs +++ b/src/core/DSharpPlus.Internal.Models/MessageComponents/MentionableSelectComponent.cs @@ -32,4 +32,4 @@ public sealed record MentionableSelectComponent : IMentionableSelectComponent /// public Optional Disabled { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/MessageComponents/RoleSelectComponent.cs b/src/core/DSharpPlus.Internal.Models/MessageComponents/RoleSelectComponent.cs index 03600d46cf..7630e7abb6 100644 --- a/src/core/DSharpPlus.Internal.Models/MessageComponents/RoleSelectComponent.cs +++ b/src/core/DSharpPlus.Internal.Models/MessageComponents/RoleSelectComponent.cs @@ -32,4 +32,4 @@ public sealed record RoleSelectComponent : IRoleSelectComponent /// public Optional Disabled { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/MessageComponents/SelectOption.cs b/src/core/DSharpPlus.Internal.Models/MessageComponents/SelectOption.cs index 344ea8fe03..1842f1c7b3 100644 --- a/src/core/DSharpPlus.Internal.Models/MessageComponents/SelectOption.cs +++ b/src/core/DSharpPlus.Internal.Models/MessageComponents/SelectOption.cs @@ -23,4 +23,4 @@ public sealed record SelectOption : ISelectOption /// public Optional Default { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/MessageComponents/StringSelectComponent.cs b/src/core/DSharpPlus.Internal.Models/MessageComponents/StringSelectComponent.cs index 1b35b53ab7..6c82e70a60 100644 --- a/src/core/DSharpPlus.Internal.Models/MessageComponents/StringSelectComponent.cs +++ b/src/core/DSharpPlus.Internal.Models/MessageComponents/StringSelectComponent.cs @@ -32,4 +32,4 @@ public sealed record StringSelectComponent : IStringSelectComponent /// public Optional Disabled { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/MessageComponents/TextInputComponent.cs b/src/core/DSharpPlus.Internal.Models/MessageComponents/TextInputComponent.cs index df75bfd404..33463ecffc 100644 --- a/src/core/DSharpPlus.Internal.Models/MessageComponents/TextInputComponent.cs +++ b/src/core/DSharpPlus.Internal.Models/MessageComponents/TextInputComponent.cs @@ -36,4 +36,4 @@ public sealed record TextInputComponent : ITextInputComponent /// public Optional Placeholder { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/MessageComponents/UserSelectComponent.cs b/src/core/DSharpPlus.Internal.Models/MessageComponents/UserSelectComponent.cs index 2d08593d40..7d2031e92b 100644 --- a/src/core/DSharpPlus.Internal.Models/MessageComponents/UserSelectComponent.cs +++ b/src/core/DSharpPlus.Internal.Models/MessageComponents/UserSelectComponent.cs @@ -32,4 +32,4 @@ public sealed record UserSelectComponent : IUserSelectComponent /// public Optional Disabled { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/RoleConnections/RoleConnectionMetadata.cs b/src/core/DSharpPlus.Internal.Models/RoleConnections/RoleConnectionMetadata.cs index ecbc246636..db19662aaa 100644 --- a/src/core/DSharpPlus.Internal.Models/RoleConnections/RoleConnectionMetadata.cs +++ b/src/core/DSharpPlus.Internal.Models/RoleConnections/RoleConnectionMetadata.cs @@ -29,4 +29,4 @@ public sealed record RoleConnectionMetadata : IRoleConnectionMetadata /// public Optional?> DescriptionLocalizations { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/ScheduledEvents/PartialScheduledEvent.cs b/src/core/DSharpPlus.Internal.Models/ScheduledEvents/PartialScheduledEvent.cs index 199adb79f6..a066f26948 100644 --- a/src/core/DSharpPlus.Internal.Models/ScheduledEvents/PartialScheduledEvent.cs +++ b/src/core/DSharpPlus.Internal.Models/ScheduledEvents/PartialScheduledEvent.cs @@ -50,4 +50,4 @@ public sealed record PartialScheduledEvent : IPartialScheduledEvent /// public Optional Image { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/ScheduledEvents/ScheduledEvent.cs b/src/core/DSharpPlus.Internal.Models/ScheduledEvents/ScheduledEvent.cs index de00571b09..10555dd4c3 100644 --- a/src/core/DSharpPlus.Internal.Models/ScheduledEvents/ScheduledEvent.cs +++ b/src/core/DSharpPlus.Internal.Models/ScheduledEvents/ScheduledEvent.cs @@ -50,4 +50,4 @@ public sealed record ScheduledEvent : IScheduledEvent /// public Optional Image { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/ScheduledEvents/ScheduledEventMetadata.cs b/src/core/DSharpPlus.Internal.Models/ScheduledEvents/ScheduledEventMetadata.cs index e0c4ff0def..473ddd4743 100644 --- a/src/core/DSharpPlus.Internal.Models/ScheduledEvents/ScheduledEventMetadata.cs +++ b/src/core/DSharpPlus.Internal.Models/ScheduledEvents/ScheduledEventMetadata.cs @@ -11,4 +11,4 @@ public sealed record ScheduledEventMetadata : IScheduledEventMetadata { /// public Optional Location { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/ScheduledEvents/ScheduledEventUser.cs b/src/core/DSharpPlus.Internal.Models/ScheduledEvents/ScheduledEventUser.cs index 41bcd9d5fe..2615e4ba8d 100644 --- a/src/core/DSharpPlus.Internal.Models/ScheduledEvents/ScheduledEventUser.cs +++ b/src/core/DSharpPlus.Internal.Models/ScheduledEvents/ScheduledEventUser.cs @@ -17,4 +17,4 @@ public sealed record ScheduledEventUser : IScheduledEventUser /// public Optional Member { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/Serialization/Converters/AutoModerationActionConverter.cs b/src/core/DSharpPlus.Internal.Models/Serialization/Converters/AutoModerationActionConverter.cs index d81c53ca3d..1db1e5dda6 100644 --- a/src/core/DSharpPlus.Internal.Models/Serialization/Converters/AutoModerationActionConverter.cs +++ b/src/core/DSharpPlus.Internal.Models/Serialization/Converters/AutoModerationActionConverter.cs @@ -5,9 +5,8 @@ using System; using System.Text.Json; using System.Text.Json.Serialization; - -using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; namespace DSharpPlus.Internal.Models.Serialization.Converters; diff --git a/src/core/DSharpPlus.Internal.Models/Serialization/Converters/MessageComponentConverter.cs b/src/core/DSharpPlus.Internal.Models/Serialization/Converters/MessageComponentConverter.cs index ec86402ae3..af889092b1 100644 --- a/src/core/DSharpPlus.Internal.Models/Serialization/Converters/MessageComponentConverter.cs +++ b/src/core/DSharpPlus.Internal.Models/Serialization/Converters/MessageComponentConverter.cs @@ -5,9 +5,8 @@ using System; using System.Text.Json; using System.Text.Json.Serialization; - -using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; namespace DSharpPlus.Internal.Models.Serialization.Converters; diff --git a/src/core/DSharpPlus.Internal.Models/Serialization/Converters/OneOfConverterFactory.cs b/src/core/DSharpPlus.Internal.Models/Serialization/Converters/OneOfConverterFactory.cs index 5b43c00763..3718c14acc 100644 --- a/src/core/DSharpPlus.Internal.Models/Serialization/Converters/OneOfConverterFactory.cs +++ b/src/core/DSharpPlus.Internal.Models/Serialization/Converters/OneOfConverterFactory.cs @@ -20,7 +20,7 @@ public override bool CanConvert(Type typeToConvert) public override JsonConverter? CreateConverter ( - Type typeToConvert, + Type typeToConvert, JsonSerializerOptions options ) { diff --git a/src/core/DSharpPlus.Internal.Models/Serialization/Converters/OptionalConverter.cs b/src/core/DSharpPlus.Internal.Models/Serialization/Converters/OptionalConverter.cs index bce74953d9..5e66eefd8d 100644 --- a/src/core/DSharpPlus.Internal.Models/Serialization/Converters/OptionalConverter.cs +++ b/src/core/DSharpPlus.Internal.Models/Serialization/Converters/OptionalConverter.cs @@ -13,13 +13,13 @@ namespace DSharpPlus.Internal.Models.Serialization.Converters; /// public sealed class OptionalConverter : JsonConverter> { - public override Optional Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + public override Optional Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) => new(JsonSerializer.Deserialize(ref reader, options)!); public override void Write ( - Utf8JsonWriter writer, - Optional value, + Utf8JsonWriter writer, + Optional value, JsonSerializerOptions options ) { diff --git a/src/core/DSharpPlus.Internal.Models/Serialization/Converters/OptionalConverterFactory.cs b/src/core/DSharpPlus.Internal.Models/Serialization/Converters/OptionalConverterFactory.cs index 5c45051c48..a4d73f781d 100644 --- a/src/core/DSharpPlus.Internal.Models/Serialization/Converters/OptionalConverterFactory.cs +++ b/src/core/DSharpPlus.Internal.Models/Serialization/Converters/OptionalConverterFactory.cs @@ -18,7 +18,7 @@ public override bool CanConvert(Type typeToConvert) public override JsonConverter? CreateConverter ( - Type typeToConvert, + Type typeToConvert, JsonSerializerOptions options ) { diff --git a/src/core/DSharpPlus.Internal.Models/Skus/Sku.cs b/src/core/DSharpPlus.Internal.Models/Skus/Sku.cs index 6352cd880a..77c21ab64f 100644 --- a/src/core/DSharpPlus.Internal.Models/Skus/Sku.cs +++ b/src/core/DSharpPlus.Internal.Models/Skus/Sku.cs @@ -27,4 +27,4 @@ public sealed record Sku : ISku /// public required DiscordSkuFlags Flags { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/StageInstances/PartialStageInstance.cs b/src/core/DSharpPlus.Internal.Models/StageInstances/PartialStageInstance.cs index d2dcc1b3c2..f442e7cc7e 100644 --- a/src/core/DSharpPlus.Internal.Models/StageInstances/PartialStageInstance.cs +++ b/src/core/DSharpPlus.Internal.Models/StageInstances/PartialStageInstance.cs @@ -27,4 +27,4 @@ public sealed record PartialStageInstance : IPartialStageInstance /// public Optional GuildScheduledEventId { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/StageInstances/StageInstance.cs b/src/core/DSharpPlus.Internal.Models/StageInstances/StageInstance.cs index 038429bdaa..88d587261a 100644 --- a/src/core/DSharpPlus.Internal.Models/StageInstances/StageInstance.cs +++ b/src/core/DSharpPlus.Internal.Models/StageInstances/StageInstance.cs @@ -27,4 +27,4 @@ public sealed record StageInstance : IStageInstance /// public Snowflake? GuildScheduledEventId { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/Stickers/PartialSticker.cs b/src/core/DSharpPlus.Internal.Models/Stickers/PartialSticker.cs index 71242b22af..7ed8636836 100644 --- a/src/core/DSharpPlus.Internal.Models/Stickers/PartialSticker.cs +++ b/src/core/DSharpPlus.Internal.Models/Stickers/PartialSticker.cs @@ -42,4 +42,4 @@ public sealed record PartialSticker : IPartialSticker /// public Optional SortValue { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/Stickers/Sticker.cs b/src/core/DSharpPlus.Internal.Models/Stickers/Sticker.cs index 65a765a877..3385397e26 100644 --- a/src/core/DSharpPlus.Internal.Models/Stickers/Sticker.cs +++ b/src/core/DSharpPlus.Internal.Models/Stickers/Sticker.cs @@ -42,4 +42,4 @@ public sealed record Sticker : ISticker /// public Optional SortValue { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/Stickers/StickerItem.cs b/src/core/DSharpPlus.Internal.Models/Stickers/StickerItem.cs index cf40f6510b..5156d4be0a 100644 --- a/src/core/DSharpPlus.Internal.Models/Stickers/StickerItem.cs +++ b/src/core/DSharpPlus.Internal.Models/Stickers/StickerItem.cs @@ -18,4 +18,4 @@ public sealed record StickerItem : IStickerItem /// public required DiscordStickerFormatType FormatType { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/Stickers/StickerPack.cs b/src/core/DSharpPlus.Internal.Models/Stickers/StickerPack.cs index 27b2312f85..f0691e757f 100644 --- a/src/core/DSharpPlus.Internal.Models/Stickers/StickerPack.cs +++ b/src/core/DSharpPlus.Internal.Models/Stickers/StickerPack.cs @@ -31,4 +31,4 @@ public sealed record StickerPack : IStickerPack /// public Optional BannerAssetId { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/Teams/Team.cs b/src/core/DSharpPlus.Internal.Models/Teams/Team.cs index c231cc0ac4..53212b7327 100644 --- a/src/core/DSharpPlus.Internal.Models/Teams/Team.cs +++ b/src/core/DSharpPlus.Internal.Models/Teams/Team.cs @@ -25,4 +25,4 @@ public sealed record Team : ITeam /// public required Snowflake OwnerUserId { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/Teams/TeamMember.cs b/src/core/DSharpPlus.Internal.Models/Teams/TeamMember.cs index cfdcc8dc34..5cc7461fee 100644 --- a/src/core/DSharpPlus.Internal.Models/Teams/TeamMember.cs +++ b/src/core/DSharpPlus.Internal.Models/Teams/TeamMember.cs @@ -23,4 +23,4 @@ public sealed record TeamMember : ITeamMember /// public required IPartialUser User { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/Users/ApplicationRoleConnection.cs b/src/core/DSharpPlus.Internal.Models/Users/ApplicationRoleConnection.cs index 7e62e90c5d..23c597e0fb 100644 --- a/src/core/DSharpPlus.Internal.Models/Users/ApplicationRoleConnection.cs +++ b/src/core/DSharpPlus.Internal.Models/Users/ApplicationRoleConnection.cs @@ -19,4 +19,4 @@ public sealed record ApplicationRoleConnection : IApplicationRoleConnection /// public required IReadOnlyDictionary Metadata { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/Users/Connection.cs b/src/core/DSharpPlus.Internal.Models/Users/Connection.cs index c83a922347..9935f9893f 100644 --- a/src/core/DSharpPlus.Internal.Models/Users/Connection.cs +++ b/src/core/DSharpPlus.Internal.Models/Users/Connection.cs @@ -41,4 +41,4 @@ public sealed record Connection : IConnection /// public required DiscordConnectionVisibility Visibility { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/Users/PartialUser.cs b/src/core/DSharpPlus.Internal.Models/Users/PartialUser.cs index 7c93745737..9b60dc5c20 100644 --- a/src/core/DSharpPlus.Internal.Models/Users/PartialUser.cs +++ b/src/core/DSharpPlus.Internal.Models/Users/PartialUser.cs @@ -60,4 +60,4 @@ public sealed record PartialUser : IPartialUser /// public Optional AvatarDecoration { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/Users/User.cs b/src/core/DSharpPlus.Internal.Models/Users/User.cs index 6670194df6..0fab8adcad 100644 --- a/src/core/DSharpPlus.Internal.Models/Users/User.cs +++ b/src/core/DSharpPlus.Internal.Models/Users/User.cs @@ -60,4 +60,4 @@ public sealed record User : IUser /// public Optional AvatarDecoration { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/Voice/VoiceRegion.cs b/src/core/DSharpPlus.Internal.Models/Voice/VoiceRegion.cs index 0d6d293abd..e3ce616747 100644 --- a/src/core/DSharpPlus.Internal.Models/Voice/VoiceRegion.cs +++ b/src/core/DSharpPlus.Internal.Models/Voice/VoiceRegion.cs @@ -23,4 +23,4 @@ public sealed record VoiceRegion : IVoiceRegion /// public required bool Custom { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/Voice/VoiceState.cs b/src/core/DSharpPlus.Internal.Models/Voice/VoiceState.cs index fb15409fe7..39d5abc9a4 100644 --- a/src/core/DSharpPlus.Internal.Models/Voice/VoiceState.cs +++ b/src/core/DSharpPlus.Internal.Models/Voice/VoiceState.cs @@ -49,4 +49,4 @@ public sealed record VoiceState : IVoiceState /// public DateTimeOffset? RequestToSpeakTimestamp { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/Webhooks/PartialWebhook.cs b/src/core/DSharpPlus.Internal.Models/Webhooks/PartialWebhook.cs index 70f039c16a..3ee5f39c54 100644 --- a/src/core/DSharpPlus.Internal.Models/Webhooks/PartialWebhook.cs +++ b/src/core/DSharpPlus.Internal.Models/Webhooks/PartialWebhook.cs @@ -45,4 +45,4 @@ public sealed record PartialWebhook : IPartialWebhook /// public Optional Url { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/Webhooks/Webhook.cs b/src/core/DSharpPlus.Internal.Models/Webhooks/Webhook.cs index ab4498fe0e..ac592031e0 100644 --- a/src/core/DSharpPlus.Internal.Models/Webhooks/Webhook.cs +++ b/src/core/DSharpPlus.Internal.Models/Webhooks/Webhook.cs @@ -45,4 +45,4 @@ public sealed record Webhook : IWebhook /// public Optional Url { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Rest/API/ApplicationCommandsRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/ApplicationCommandsRestAPI.cs index 65defdf3e2..5af686b3c2 100644 --- a/src/core/DSharpPlus.Internal.Rest/API/ApplicationCommandsRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Rest/API/ApplicationCommandsRestAPI.cs @@ -9,6 +9,7 @@ using System.Net.Http; using System.Threading; using System.Threading.Tasks; + using DSharpPlus.Entities; using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Internal.Abstractions.Rest; @@ -406,14 +407,11 @@ public async ValueTask>> GetGlobalAppl CancellationToken ct = default ) { - QueryBuilder builder = new() - { - RootUri = $"applications/{applicationId}/commands" - }; + QueryBuilder builder = new($"applications/{applicationId}/commands"); if (query.WithLocalizations is not null) { - builder.AddParameter("with_localizations", query.WithLocalizations.Value.ToString().ToLowerInvariant()); + _ = builder.AddParameter("with_localizations", query.WithLocalizations.Value.ToString().ToLowerInvariant()); } return await restClient.ExecuteRequestAsync> @@ -475,14 +473,11 @@ public async ValueTask>> GetGuildAppli CancellationToken ct = default ) { - QueryBuilder builder = new() - { - RootUri = $"applications/{applicationId}/guilds/{guildId}/commands" - }; + QueryBuilder builder = new($"applications/{applicationId}/guilds/{guildId}/commands"); if (query.WithLocalizations is not null) { - builder.AddParameter("with_localizations", query.WithLocalizations.Value.ToString().ToLowerInvariant()); + _ = builder.AddParameter("with_localizations", query.WithLocalizations.Value.ToString().ToLowerInvariant()); } return await restClient.ExecuteRequestAsync> diff --git a/src/core/DSharpPlus.Internal.Rest/API/AuditLogsRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/AuditLogsRestAPI.cs index e78878834e..d4113c16f6 100644 --- a/src/core/DSharpPlus.Internal.Rest/API/AuditLogsRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Rest/API/AuditLogsRestAPI.cs @@ -38,35 +38,32 @@ public async ValueTask> ListGuildAuditLogEntriesAsync return new ValidationError("The limit of entries to return must be between 1 and 1000."); } - QueryBuilder builder = new() - { - RootUri = $"guilds/{guildId}/audit-logs" - }; + QueryBuilder builder = new($"guilds/{guildId}/audit-logs"); if (query.ActionType is not null) { int value = (int)query.ActionType.Value; - builder.AddParameter("action_type", value.ToString(CultureInfo.InvariantCulture)); + _ = builder.AddParameter("action_type", value.ToString(CultureInfo.InvariantCulture)); } if (query.After is not null) { - builder.AddParameter("after", query.After.Value.ToString()); + _ = builder.AddParameter("after", query.After.Value.ToString()); } if (query.Before is not null) { - builder.AddParameter("before", query.Before.Value.ToString()); + _ = builder.AddParameter("before", query.Before.Value.ToString()); } if (query.Limit is not null) { - builder.AddParameter("limit", query.Limit.Value.ToString(CultureInfo.InvariantCulture)); + _ = builder.AddParameter("limit", query.Limit.Value.ToString(CultureInfo.InvariantCulture)); } if (query.UserId is not null) { - builder.AddParameter("user_id", query.UserId.Value.ToString()); + _ = builder.AddParameter("user_id", query.UserId.Value.ToString()); } return await restClient.ExecuteRequestAsync diff --git a/src/core/DSharpPlus.Internal.Rest/API/ChannelRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/ChannelRestAPI.cs index e74348e275..e735e2554a 100644 --- a/src/core/DSharpPlus.Internal.Rest/API/ChannelRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Rest/API/ChannelRestAPI.cs @@ -540,27 +540,24 @@ public async ValueTask>> GetChannelMessagesAsync return new ValidationError("The limit for messages to request at once must be between 1 and 100."); } - QueryBuilder builder = new() - { - RootUri = $"channels/{channelId}/messages" - }; + QueryBuilder builder = new($"channels/{channelId}/messages"); if (query.Limit is not null) { - builder.AddParameter("limit", query.Limit.Value.ToString(CultureInfo.InvariantCulture)); + _ = builder.AddParameter("limit", query.Limit.Value.ToString(CultureInfo.InvariantCulture)); } if (query.Around is not null) { - builder.AddParameter("around", query.Around.Value.ToString()); + _ = builder.AddParameter("around", query.Around.Value.ToString()); } else if (query.Before is not null) { - builder.AddParameter("before", query.Before.Value.ToString()); + _ = builder.AddParameter("before", query.Before.Value.ToString()); } else if (query.After is not null) { - builder.AddParameter("after", query.After.Value.ToString()); + _ = builder.AddParameter("after", query.After.Value.ToString()); } return await restClient.ExecuteRequestAsync> @@ -607,14 +604,11 @@ public async ValueTask>> GetReactionsAsync return new ValidationError("The limit of reactions to request must be between 1 and 100."); } - QueryBuilder builder = new() - { - RootUri = $"channels/{channelId}/messages/{messageId}/reactions/{emoji}" - }; + QueryBuilder builder = new($"channels/{channelId}/messages/{messageId}/reactions/{emoji}"); if (query.After is not null) { - builder.AddParameter("after", query.After.Value.ToString()); + _ = builder.AddParameter("after", query.After.Value.ToString()); } return await restClient.ExecuteRequestAsync> @@ -638,14 +632,11 @@ public async ValueTask> GetThreadMemberAsync CancellationToken ct = default ) { - QueryBuilder builder = new() - { - RootUri = $"channels/{threadId}/thread-members/{userId}" - }; + QueryBuilder builder = new($"channels/{threadId}/thread-members/{userId}"); if (query.WithMember is not null) { - builder.AddParameter("after", query.WithMember.Value.ToString().ToLowerInvariant()); + _ = builder.AddParameter("after", query.WithMember.Value.ToString().ToLowerInvariant()); } return await restClient.ExecuteRequestAsync @@ -759,19 +750,16 @@ public async ValueTask> ListJoinedPrivateArc return new ValidationError("The limit of threads to return must be between 1 and 100."); } - QueryBuilder builder = new() - { - RootUri = $"channels/{channelId}/users/@me/threads/archived/private" - }; + QueryBuilder builder = new($"channels/{channelId}/users/@me/threads/archived/private"); if (query.Limit is not null) { - builder.AddParameter("limit", query.Limit.Value.ToString(CultureInfo.InvariantCulture)); + _ = builder.AddParameter("limit", query.Limit.Value.ToString(CultureInfo.InvariantCulture)); } if (query.Before is not null) { - builder.AddParameter("before", query.Before.Value.ToString()); + _ = builder.AddParameter("before", query.Before.Value.ToString()); } return await restClient.ExecuteRequestAsync @@ -798,19 +786,16 @@ public async ValueTask> ListPrivateArchivedT return new ValidationError("The limit of threads to return must be between 1 and 100."); } - QueryBuilder builder = new() - { - RootUri = $"channels/{channelId}/users/@me/threads/archived/private" - }; + QueryBuilder builder = new($"channels/{channelId}/users/@me/threads/archived/private"); if (query.Limit is not null) { - builder.AddParameter("limit", query.Limit.Value.ToString(CultureInfo.InvariantCulture)); + _ = builder.AddParameter("limit", query.Limit.Value.ToString(CultureInfo.InvariantCulture)); } if (query.Before is not null) { - builder.AddParameter("before", query.Before.Value.ToString("o", CultureInfo.InvariantCulture)); + _ = builder.AddParameter("before", query.Before.Value.ToString("o", CultureInfo.InvariantCulture)); } return await restClient.ExecuteRequestAsync @@ -837,19 +822,16 @@ public async ValueTask> ListPublicArchivedTh return new ValidationError("The limit of threads to return must be between 1 and 100."); } - QueryBuilder builder = new() - { - RootUri = $"channels/{channelId}/threads/archived/public" - }; + QueryBuilder builder = new($"channels/{channelId}/threads/archived/public"); if (query.Limit is not null) { - builder.AddParameter("limit", query.Limit.Value.ToString(CultureInfo.InvariantCulture)); + _ = builder.AddParameter("limit", query.Limit.Value.ToString(CultureInfo.InvariantCulture)); } if (query.Before is not null) { - builder.AddParameter("before", query.Before.Value.ToString("o", CultureInfo.InvariantCulture)); + _ = builder.AddParameter("before", query.Before.Value.ToString("o", CultureInfo.InvariantCulture)); } return await restClient.ExecuteRequestAsync @@ -876,24 +858,21 @@ public async ValueTask>> ListThreadMembersAs return new ValidationError("The limit of threads to return must be between 1 and 100."); } - QueryBuilder builder = new() - { - RootUri = $"channels/{threadId}/thread-members" - }; + QueryBuilder builder = new($"channels/{threadId}/thread-members"); if (query.Limit is not null) { - builder.AddParameter("limit", query.Limit.Value.ToString(CultureInfo.InvariantCulture)); + _ = builder.AddParameter("limit", query.Limit.Value.ToString(CultureInfo.InvariantCulture)); } if (query.After is not null) { - builder.AddParameter("after", query.After.Value.ToString()); + _ = builder.AddParameter("after", query.After.Value.ToString()); } if (query.WithMember is not null) { - builder.AddParameter("with_member", query.WithMember.Value.ToString().ToLowerInvariant()); + _ = builder.AddParameter("with_member", query.WithMember.Value.ToString().ToLowerInvariant()); } return await restClient.ExecuteRequestAsync> diff --git a/src/core/DSharpPlus.Internal.Rest/API/EntitlementsRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/EntitlementsRestAPI.cs index 5bb9d21aa6..7053b1bb6c 100644 --- a/src/core/DSharpPlus.Internal.Rest/API/EntitlementsRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Rest/API/EntitlementsRestAPI.cs @@ -76,44 +76,41 @@ public async ValueTask>> ListEntitlementsAsyn return new ValidationError("The limit of entitlements to list must be between 1 and 100."); } - QueryBuilder builder = new() - { - RootUri = $"applications/{applicationId}/entitlements" - }; + QueryBuilder builder = new($"applications/{applicationId}/entitlements"); if (query.UserId is not null) { - builder.AddParameter("user_id", query.UserId.Value.ToString()); + _ = builder.AddParameter("user_id", query.UserId.Value.ToString()); } if (query.SkuIds is not null) { - builder.AddParameter("sku_ids", query.SkuIds); + _ = builder.AddParameter("sku_ids", query.SkuIds); } if (query.Before is not null) { - builder.AddParameter("before", query.Before.Value.ToString()); + _ = builder.AddParameter("before", query.Before.Value.ToString()); } if (query.After is not null) { - builder.AddParameter("after", query.After.Value.ToString()); + _ = builder.AddParameter("after", query.After.Value.ToString()); } if (query.Limit is not null) { - builder.AddParameter("limit", query.Limit.Value.ToString(CultureInfo.InvariantCulture)); + _ = builder.AddParameter("limit", query.Limit.Value.ToString(CultureInfo.InvariantCulture)); } if (query.GuildId is not null) { - builder.AddParameter("guild_id", query.GuildId.Value.ToString()); + _ = builder.AddParameter("guild_id", query.GuildId.Value.ToString()); } if (query.ExcludeEnded is not null) { - builder.AddParameter("exclude_ended", query.ExcludeEnded.Value.ToString().ToLowerInvariant()); + _ = builder.AddParameter("exclude_ended", query.ExcludeEnded.Value.ToString().ToLowerInvariant()); } return await restClient.ExecuteRequestAsync> diff --git a/src/core/DSharpPlus.Internal.Rest/API/GuildRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/GuildRestAPI.cs index 4256369b48..bb1ca226b4 100644 --- a/src/core/DSharpPlus.Internal.Rest/API/GuildRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Rest/API/GuildRestAPI.cs @@ -85,14 +85,11 @@ public async ValueTask CreateGuildBanAsync CancellationToken ct = default ) { - QueryBuilder builder = new() - { - RootUri = $"guilds/{guildId}/bans/{userId}" - }; + QueryBuilder builder = new($"guilds/{guildId}/bans/{userId}"); if (query.DeleteMessageSeconds is not null) { - builder.AddParameter("delete_message_seconds", query.DeleteMessageSeconds.Value.ToString(CultureInfo.InvariantCulture)); + _ = builder.AddParameter("delete_message_seconds", query.DeleteMessageSeconds.Value.ToString(CultureInfo.InvariantCulture)); } Result response = await restClient.ExecuteRequestAsync @@ -322,14 +319,11 @@ public async ValueTask> GetGuildAsync CancellationToken ct = default ) { - QueryBuilder builder = new() - { - RootUri = $"guilds/{guildId}" - }; + QueryBuilder builder = new($"guilds/{guildId}"); if (query.WithCounts.HasValue) { - builder.AddParameter("with_counts", query.WithCounts.Value.ToString().ToLowerInvariant()); + _ = builder.AddParameter("with_counts", query.WithCounts.Value.ToString().ToLowerInvariant()); } return await restClient.ExecuteRequestAsync @@ -370,10 +364,7 @@ public async ValueTask>> GetGuildBansAsync CancellationToken ct = default ) { - QueryBuilder builder = new() - { - RootUri = $"guilds/{guildId}/bans" - }; + QueryBuilder builder = new($"guilds/{guildId}/bans"); if (query.Limit.HasValue) { @@ -382,17 +373,17 @@ public async ValueTask>> GetGuildBansAsync return new ValidationError("The amount of bans to request must be between 1 and 1000."); } - builder.AddParameter("limit", query.Limit.Value.ToString(CultureInfo.InvariantCulture)); + _ = builder.AddParameter("limit", query.Limit.Value.ToString(CultureInfo.InvariantCulture)); } if (query.Before.HasValue) { - builder.AddParameter("before", query.Before.Value.ToString()); + _ = builder.AddParameter("before", query.Before.Value.ToString()); } if (query.After.HasValue) { - builder.AddParameter("after", query.After.Value.ToString()); + _ = builder.AddParameter("after", query.After.Value.ToString()); } return await restClient.ExecuteRequestAsync> @@ -524,10 +515,7 @@ public async ValueTask> GetGuildPruneCountAsy CancellationToken ct = default ) { - QueryBuilder builder = new() - { - RootUri = $"guilds/{guildId}/prune" - }; + QueryBuilder builder = new($"guilds/{guildId}/prune"); if (query.Days.HasValue) { @@ -536,12 +524,12 @@ public async ValueTask> GetGuildPruneCountAsy return new ValidationError("The number of days to prune must be between 1 and 30."); } - builder.AddParameter("days", query.Days.Value.ToString(CultureInfo.InvariantCulture)); + _ = builder.AddParameter("days", query.Days.Value.ToString(CultureInfo.InvariantCulture)); } if (query.IncludeRoles is not null) { - builder.AddParameter("include_roles", query.IncludeRoles); + _ = builder.AddParameter("include_roles", query.IncludeRoles); } return await restClient.ExecuteRequestAsync @@ -710,10 +698,7 @@ public async ValueTask>> ListGuildMembersAsyn CancellationToken ct = default ) { - QueryBuilder builder = new() - { - RootUri = $"guilds/{guildId}/members" - }; + QueryBuilder builder = new($"guilds/{guildId}/members"); if (query.Limit is not null) { @@ -722,12 +707,12 @@ public async ValueTask>> ListGuildMembersAsyn return new ValidationError("The amount of members to query at once must be between 1 and 1000."); } - builder.AddParameter("limit", query.Limit.Value.ToString(CultureInfo.InvariantCulture)); + _ = builder.AddParameter("limit", query.Limit.Value.ToString(CultureInfo.InvariantCulture)); } if (query.After is not null) { - builder.AddParameter("after", query.After.Value.ToString()); + _ = builder.AddParameter("after", query.After.Value.ToString()); } return await restClient.ExecuteRequestAsync> @@ -1116,12 +1101,9 @@ public async ValueTask>> SearchGuildMembersAs CancellationToken ct = default ) { - QueryBuilder builder = new() - { - RootUri = $"guilds/{guildId}/members/search" - }; + QueryBuilder builder = new($"guilds/{guildId}/members/search"); - builder.AddParameter("query", query.Query); + _ = builder.AddParameter("query", query.Query); if (query.Limit is not null) { @@ -1130,7 +1112,7 @@ public async ValueTask>> SearchGuildMembersAs return new ValidationError("The amount of members to request must be between 1 and 1000."); } - builder.AddParameter("limit", query.Limit.Value.ToString(CultureInfo.InvariantCulture)); + _ = builder.AddParameter("limit", query.Limit.Value.ToString(CultureInfo.InvariantCulture)); } return await restClient.ExecuteRequestAsync> diff --git a/src/core/DSharpPlus.Internal.Rest/API/GuildScheduledEventRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/GuildScheduledEventRestAPI.cs index fb1495a5ee..1c47e7663d 100644 --- a/src/core/DSharpPlus.Internal.Rest/API/GuildScheduledEventRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Rest/API/GuildScheduledEventRestAPI.cs @@ -77,14 +77,11 @@ public async ValueTask> GetScheduledEventAsync CancellationToken ct = default ) { - QueryBuilder builder = new() - { - RootUri = $"guilds/{guildId}/scheduled-events/{eventId}" - }; + QueryBuilder builder = new($"guilds/{guildId}/scheduled-events/{eventId}"); if (query.WithUserCount is not null) { - builder.AddParameter("with_user_count", query.WithUserCount.Value.ToString().ToLowerInvariant()); + _ = builder.AddParameter("with_user_count", query.WithUserCount.Value.ToString().ToLowerInvariant()); } return await restClient.ExecuteRequestAsync @@ -108,10 +105,7 @@ public async ValueTask>> GetScheduledE CancellationToken ct = default ) { - QueryBuilder builder = new() - { - RootUri = $"guilds/{guildId}/scheduled-events/{eventId}/users" - }; + QueryBuilder builder = new($"guilds/{guildId}/scheduled-events/{eventId}/users"); if (query.Limit is not null) { @@ -120,22 +114,22 @@ public async ValueTask>> GetScheduledE return new ValidationError("The amount of scheduled event users to request must be between 1 and 100."); } - builder.AddParameter("limit", query.Limit.Value.ToString(CultureInfo.InvariantCulture)); + _ = builder.AddParameter("limit", query.Limit.Value.ToString(CultureInfo.InvariantCulture)); } if (query.WithMember is not null) { - builder.AddParameter("with_member", query.WithMember.Value.ToString().ToLowerInvariant()); + _ = builder.AddParameter("with_member", query.WithMember.Value.ToString().ToLowerInvariant()); } if (query.Before is not null) { - builder.AddParameter("before", query.Before.Value.ToString()); + _ = builder.AddParameter("before", query.Before.Value.ToString()); } if (query.After is not null) { - builder.AddParameter("after", query.After.Value.ToString()); + _ = builder.AddParameter("after", query.After.Value.ToString()); } return await restClient.ExecuteRequestAsync> @@ -158,14 +152,11 @@ public async ValueTask>> ListScheduledEven CancellationToken ct = default ) { - QueryBuilder builder = new() - { - RootUri = $"guilds/{guildId}/scheduled-events" - }; + QueryBuilder builder = new($"guilds/{guildId}/scheduled-events"); if (query.WithUserCount is not null) { - builder.AddParameter("with_user_count", query.WithUserCount.Value.ToString().ToLowerInvariant()); + _ = builder.AddParameter("with_user_count", query.WithUserCount.Value.ToString().ToLowerInvariant()); } return await restClient.ExecuteRequestAsync> diff --git a/src/core/DSharpPlus.Internal.Rest/API/InviteRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/InviteRestAPI.cs index 2a944e63df..a941c45f42 100644 --- a/src/core/DSharpPlus.Internal.Rest/API/InviteRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Rest/API/InviteRestAPI.cs @@ -47,24 +47,21 @@ public async ValueTask> GetInviteAsync CancellationToken ct = default ) { - QueryBuilder builder = new() - { - RootUri = $"invites/{inviteCode}" - }; + QueryBuilder builder = new($"invites/{inviteCode}"); if (query.WithCounts is not null) { - builder.AddParameter("with_counts", query.WithCounts.Value.ToString().ToLowerInvariant()); + _ = builder.AddParameter("with_counts", query.WithCounts.Value.ToString().ToLowerInvariant()); } if (query.WithExpiration is not null) { - builder.AddParameter("with_expiration", query.WithExpiration.Value.ToString().ToLowerInvariant()); + _ = builder.AddParameter("with_expiration", query.WithExpiration.Value.ToString().ToLowerInvariant()); } if (query.GuildScheduledEventId is not null) { - builder.AddParameter("guild_scheduled_event_id", query.GuildScheduledEventId.Value.ToString()); + _ = builder.AddParameter("guild_scheduled_event_id", query.GuildScheduledEventId.Value.ToString()); } return await restClient.ExecuteRequestAsync diff --git a/src/core/DSharpPlus.Internal.Rest/API/UserRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/UserRestAPI.cs index a522d89d32..7db4abed6e 100644 --- a/src/core/DSharpPlus.Internal.Rest/API/UserRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Rest/API/UserRestAPI.cs @@ -142,10 +142,7 @@ public async ValueTask>> GetCurrentUserGuild CancellationToken ct = default ) { - QueryBuilder builder = new() - { - RootUri = "users/@me/guilds" - }; + QueryBuilder builder = new("users/@me/guilds"); if (query.Limit is not null) { @@ -154,22 +151,22 @@ public async ValueTask>> GetCurrentUserGuild return new ValidationError("The limit of guilds to request must be between 1 and 200."); } - builder.AddParameter("limit", query.Limit.Value.ToString(CultureInfo.InvariantCulture)); + _ = builder.AddParameter("limit", query.Limit.Value.ToString(CultureInfo.InvariantCulture)); } if (query.Before is not null) { - builder.AddParameter("before", query.Before.Value.ToString()); + _ = builder.AddParameter("before", query.Before.Value.ToString()); } if (query.After is not null) { - builder.AddParameter("after", query.After.Value.ToString()); + _ = builder.AddParameter("after", query.After.Value.ToString()); } if (query.WithCounts is not null) { - builder.AddParameter("with_counts", query.WithCounts.Value.ToString().ToLowerInvariant()); + _ = builder.AddParameter("with_counts", query.WithCounts.Value.ToString().ToLowerInvariant()); } return await restClient.ExecuteRequestAsync> diff --git a/src/core/DSharpPlus.Internal.Rest/API/WebhookRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/WebhookRestAPI.cs index 678f141f17..5fc64222c9 100644 --- a/src/core/DSharpPlus.Internal.Rest/API/WebhookRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Rest/API/WebhookRestAPI.cs @@ -94,14 +94,11 @@ public async ValueTask DeleteWebhookMessageAsync CancellationToken ct = default ) { - QueryBuilder builder = new() - { - RootUri = $"webhooks/{webhookId}/{webhookToken}/messages/{messageId}" - }; + QueryBuilder builder = new($"webhooks/{webhookId}/{webhookToken}/messages/{messageId}"); if (query.ThreadId is not null) { - builder.AddParameter("thread_id", query.ThreadId.Value.ToString()); + _ = builder.AddParameter("thread_id", query.ThreadId.Value.ToString()); } Result response = await restClient.ExecuteRequestAsync @@ -170,14 +167,11 @@ public async ValueTask> EditWebhookMessageAsync return new ValidationError("A webhook message cannot contain more than 5 action rows."); } - QueryBuilder builder = new() - { - RootUri = $"webhooks/{webhookId}/{webhookToken}/messages/{messageId}" - }; + QueryBuilder builder = new($"webhooks/{webhookId}/{webhookToken}/messages/{messageId}"); if (query.ThreadId is not null) { - builder.AddParameter("thread_id", query.ThreadId.Value.ToString()); + _ = builder.AddParameter("thread_id", query.ThreadId.Value.ToString()); } return await restClient.ExecuteRequestAsync @@ -232,19 +226,16 @@ public async ValueTask> ExecuteWebhookAsync } } - QueryBuilder builder = new() - { - RootUri = $"webhooks/{webhookId}/{webhookToken}" - }; + QueryBuilder builder = new($"webhooks/{webhookId}/{webhookToken}"); if (query.ThreadId is not null) { - builder.AddParameter("thread_id", query.ThreadId.Value.ToString()); + _ = builder.AddParameter("thread_id", query.ThreadId.Value.ToString()); } if (query.Wait is not null) { - builder.AddParameter("wait", query.Wait.Value.ToString().ToLowerInvariant()); + _ = builder.AddParameter("wait", query.Wait.Value.ToString().ToLowerInvariant()); } if (query.Wait == true) @@ -346,14 +337,11 @@ public async ValueTask> GetWebhookMessageAsync CancellationToken ct = default ) { - QueryBuilder builder = new() - { - RootUri = $"webhooks/{webhookId}/{webhookToken}/messages/{messageId}" - }; + QueryBuilder builder = new($"webhooks/{webhookId}/{webhookToken}/messages/{messageId}"); if (query.ThreadId is not null) { - builder.AddParameter("thread_id", query.ThreadId.Value.ToString()); + _ = builder.AddParameter("thread_id", query.ThreadId.Value.ToString()); } return await restClient.ExecuteRequestAsync diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/ApplicationCommands/CreateGuildApplicationCommandPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/ApplicationCommands/CreateGuildApplicationCommandPayload.cs index 411ee34778..c1cb878e24 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/ApplicationCommands/CreateGuildApplicationCommandPayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/ApplicationCommands/CreateGuildApplicationCommandPayload.cs @@ -36,4 +36,4 @@ public sealed record CreateGuildApplicationCommandPayload : ICreateGuildApplicat /// public Optional Nsfw { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/ApplicationCommands/EditGuildApplicationCommandPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/ApplicationCommands/EditGuildApplicationCommandPayload.cs index b02f6c9155..8a4c1b2fbe 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/ApplicationCommands/EditGuildApplicationCommandPayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/ApplicationCommands/EditGuildApplicationCommandPayload.cs @@ -36,4 +36,4 @@ public sealed record EditGuildApplicationCommandPayload : IEditGuildApplicationC /// public Optional Nsfw { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Applications/EditCurrentApplicationPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Applications/EditCurrentApplicationPayload.cs index 5a6890811f..ecd7b0da7a 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/Applications/EditCurrentApplicationPayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Applications/EditCurrentApplicationPayload.cs @@ -39,4 +39,4 @@ public sealed record EditCurrentApplicationPayload : IEditCurrentApplicationPayl /// public Optional> Tags { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/AutoModeration/CreateAutoModerationRulePayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/AutoModeration/CreateAutoModerationRulePayload.cs index d6738d0184..f82de35924 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/AutoModeration/CreateAutoModerationRulePayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/AutoModeration/CreateAutoModerationRulePayload.cs @@ -36,4 +36,4 @@ public sealed record CreateAutoModerationRulePayload : ICreateAutoModerationRule /// public Optional> ExemptChannels { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/AutoModeration/ModifyAutoModerationRulePayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/AutoModeration/ModifyAutoModerationRulePayload.cs index e5614894e6..5ab5ba34d9 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/AutoModeration/ModifyAutoModerationRulePayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/AutoModeration/ModifyAutoModerationRulePayload.cs @@ -33,4 +33,4 @@ public sealed record ModifyAutoModerationRulePayload : IModifyAutoModerationRule /// public Optional> ExemptChannels { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/BulkDeleteMessagesPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/BulkDeleteMessagesPayload.cs index af1c9237cb..c9e7802e42 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/BulkDeleteMessagesPayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/BulkDeleteMessagesPayload.cs @@ -13,4 +13,4 @@ public sealed record BulkDeleteMessagesPayload : IBulkDeleteMessagesPayload { /// public required IReadOnlyList Messages { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/CreateChannelInvitePayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/CreateChannelInvitePayload.cs index e2471e9e80..da8d6e6b85 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/CreateChannelInvitePayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/CreateChannelInvitePayload.cs @@ -30,4 +30,4 @@ public sealed record CreateChannelInvitePayload : ICreateChannelInvitePayload /// public Optional TargetApplicationId { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/EditChannelPermissionsPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/EditChannelPermissionsPayload.cs index 536ce1064a..1dfab8efd5 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/EditChannelPermissionsPayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/EditChannelPermissionsPayload.cs @@ -18,4 +18,4 @@ public sealed record EditChannelPermissionsPayload : IEditChannelPermissionsPayl /// public Optional Deny { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/EditMessagePayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/EditMessagePayload.cs index 54336c6287..b61cf2c88e 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/EditMessagePayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/EditMessagePayload.cs @@ -33,4 +33,4 @@ public sealed record EditMessagePayload : IEditMessagePayload /// public Optional?> Attachments { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/FollowAnnouncementChannelPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/FollowAnnouncementChannelPayload.cs index b2b2602d71..2906fb6a72 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/FollowAnnouncementChannelPayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/FollowAnnouncementChannelPayload.cs @@ -11,4 +11,4 @@ public sealed record FollowAnnouncementChannelPayload : IFollowAnnouncementChann { /// public required Snowflake WebhookChannelId { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/ForumAndMediaThreadMessage.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/ForumAndMediaThreadMessage.cs index 41b974213a..a10a0be920 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/ForumAndMediaThreadMessage.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/ForumAndMediaThreadMessage.cs @@ -33,4 +33,4 @@ public sealed record ForumAndMediaThreadMessage : IForumAndMediaThreadMessage /// public Optional Flags { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/GroupDMAddRecipientPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/GroupDMAddRecipientPayload.cs index 8864f2d02c..481bf65031 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/GroupDMAddRecipientPayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/GroupDMAddRecipientPayload.cs @@ -14,4 +14,4 @@ public sealed record GroupDMAddRecipientPayload : IGroupDMAddRecipientPayload /// public required string Nick { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/ModifyGroupDMPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/ModifyGroupDMPayload.cs index ccde5673e8..568f84b817 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/ModifyGroupDMPayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/ModifyGroupDMPayload.cs @@ -14,4 +14,4 @@ public sealed record ModifyGroupDMPayload : IModifyGroupDMPayload /// public Optional Icon { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/ModifyGuildChannelPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/ModifyGuildChannelPayload.cs index 29f48bbbb8..51d043c92e 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/ModifyGuildChannelPayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/ModifyGuildChannelPayload.cs @@ -69,4 +69,4 @@ public sealed record ModifyGuildChannelPayload : IModifyGuildChannelPayload /// public Optional DefaultForumLayout { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/ModifyThreadChannelPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/ModifyThreadChannelPayload.cs index 4cff23cc13..fbc487d386 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/ModifyThreadChannelPayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/ModifyThreadChannelPayload.cs @@ -35,4 +35,4 @@ public sealed record ModifyThreadChannelPayload : IModifyThreadChannelPayload /// public Optional> AppliedTags { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/StartThreadFromMessagePayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/StartThreadFromMessagePayload.cs index f8a360d846..6d949afd19 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/StartThreadFromMessagePayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/StartThreadFromMessagePayload.cs @@ -17,4 +17,4 @@ public sealed record StartThreadFromMessagePayload : IStartThreadFromMessagePayl /// public Optional RateLimitPerUser { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/StartThreadInForumOrMediaChannelPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/StartThreadInForumOrMediaChannelPayload.cs index 9b56411f11..c9a7a1d289 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/StartThreadInForumOrMediaChannelPayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/StartThreadInForumOrMediaChannelPayload.cs @@ -28,4 +28,4 @@ public sealed record StartThreadInForumOrMediaChannelPayload : IStartThreadInFor /// public IReadOnlyList? Files { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/StartThreadWithoutMessagePayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/StartThreadWithoutMessagePayload.cs index fd0ac19fae..f776b31819 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/StartThreadWithoutMessagePayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/StartThreadWithoutMessagePayload.cs @@ -24,4 +24,4 @@ public sealed record StartThreadWithoutMessagePayload : IStartThreadWithoutMessa /// public Optional Invitable { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Emojis/CreateGuildEmojiPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Emojis/CreateGuildEmojiPayload.cs index d45de62aa7..082c6283ff 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/Emojis/CreateGuildEmojiPayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Emojis/CreateGuildEmojiPayload.cs @@ -19,4 +19,4 @@ public sealed record CreateGuildEmojiPayload : ICreateGuildEmojiPayload /// public Optional> Roles { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Emojis/ModifyGuildEmojiPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Emojis/ModifyGuildEmojiPayload.cs index 66aa8e2c3a..d360660d5d 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/Emojis/ModifyGuildEmojiPayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Emojis/ModifyGuildEmojiPayload.cs @@ -16,4 +16,4 @@ public sealed record ModifyGuildEmojiPayload : IModifyGuildEmojiPayload /// public Optional> Roles { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Entitlements/CreateTestEntitlementPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Entitlements/CreateTestEntitlementPayload.cs index 6b7484b995..ea48d30b9f 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/Entitlements/CreateTestEntitlementPayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Entitlements/CreateTestEntitlementPayload.cs @@ -18,4 +18,4 @@ public sealed record CreateTestEntitlementPayload : ICreateTestEntitlementPayloa /// public required DiscordEntitlementOwnerType OwnerType { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/GuildTemplates/CreateGuildFromGuildTemplatePayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/GuildTemplates/CreateGuildFromGuildTemplatePayload.cs index e562e13f52..ab9c07b803 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/GuildTemplates/CreateGuildFromGuildTemplatePayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/GuildTemplates/CreateGuildFromGuildTemplatePayload.cs @@ -14,4 +14,4 @@ public sealed record CreateGuildFromGuildTemplatePayload : ICreateGuildFromGuild /// public Optional Icon { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/GuildTemplates/CreateGuildTemplatePayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/GuildTemplates/CreateGuildTemplatePayload.cs index 1ae182ce49..d10b497d37 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/GuildTemplates/CreateGuildTemplatePayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/GuildTemplates/CreateGuildTemplatePayload.cs @@ -14,4 +14,4 @@ public sealed record CreateGuildTemplatePayload : ICreateGuildTemplatePayload /// public Optional Description { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/GuildTemplates/ModifyGuildTemplatePayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/GuildTemplates/ModifyGuildTemplatePayload.cs index 7b4c2f1713..f802264bec 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/GuildTemplates/ModifyGuildTemplatePayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/GuildTemplates/ModifyGuildTemplatePayload.cs @@ -14,4 +14,4 @@ public sealed record ModifyGuildTemplatePayload : IModifyGuildTemplatePayload /// public Optional Description { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/AddGuildMemberPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/AddGuildMemberPayload.cs index d34e8480f3..80302eea4a 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/AddGuildMemberPayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/AddGuildMemberPayload.cs @@ -25,4 +25,4 @@ public sealed record AddGuildMemberPayload : IAddGuildMemberPayload /// public Optional Deaf { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/CreateGuildChannelPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/CreateGuildChannelPayload.cs index abeb172fd2..4193aaae7c 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/CreateGuildChannelPayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/CreateGuildChannelPayload.cs @@ -66,4 +66,4 @@ public sealed record CreateGuildChannelPayload : ICreateGuildChannelPayload /// public Optional DefaultThreadRateLimitPerUser { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/CreateGuildPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/CreateGuildPayload.cs index 9713248373..4aed99537a 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/CreateGuildPayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/CreateGuildPayload.cs @@ -45,4 +45,4 @@ public sealed record CreateGuildPayload : ICreateGuildPayload /// public Optional SystemChannelFlags { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/CreateGuildRolePayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/CreateGuildRolePayload.cs index 0ca3556210..1da1701af7 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/CreateGuildRolePayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/CreateGuildRolePayload.cs @@ -30,4 +30,4 @@ public sealed record CreateGuildRolePayload : ICreateGuildRolePayload /// public Optional Mentionable { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyCurrentMemberPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyCurrentMemberPayload.cs index c05cc38cf4..9217d9c9eb 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyCurrentMemberPayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyCurrentMemberPayload.cs @@ -11,4 +11,4 @@ public sealed record ModifyCurrentMemberPayload : IModifyCurrentMemberPayload { /// public Optional Nick { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyCurrentUserVoiceStatePayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyCurrentUserVoiceStatePayload.cs index 8599d8dfb6..9979c5bf0f 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyCurrentUserVoiceStatePayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyCurrentUserVoiceStatePayload.cs @@ -19,4 +19,4 @@ public sealed record ModifyCurrentUserVoiceStatePayload : IModifyCurrentUserVoic /// public Optional RequestToSpeakTimestamp { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyGuildChannelPositionsPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyGuildChannelPositionsPayload.cs index b0882eb6ed..1b4d5dd551 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyGuildChannelPositionsPayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyGuildChannelPositionsPayload.cs @@ -20,4 +20,4 @@ public sealed record ModifyGuildChannelPositionsPayload : IModifyGuildChannelPos /// public Optional ParentChannelId { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyGuildMemberPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyGuildMemberPayload.cs index 2af47abf88..9692272dfb 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyGuildMemberPayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyGuildMemberPayload.cs @@ -29,4 +29,4 @@ public sealed record ModifyGuildMemberPayload : IModifyGuildMemberPayload /// public Optional CommunicationDisabledUntil { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyGuildMfaLevelPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyGuildMfaLevelPayload.cs index de2ac8360c..a5c4fb2d9d 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyGuildMfaLevelPayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyGuildMfaLevelPayload.cs @@ -12,4 +12,4 @@ public sealed record ModifyGuildMfaLevelPayload : IModifyGuildMfaLevelPayload { /// public required DiscordMfaLevel Level { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyGuildOnboardingPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyGuildOnboardingPayload.cs index 03b75258ea..7c7aab9ac4 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyGuildOnboardingPayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyGuildOnboardingPayload.cs @@ -24,4 +24,4 @@ public sealed record ModifyGuildOnboardingPayload : IModifyGuildOnboardingPayloa /// public required DiscordGuildOnboardingMode Mode { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyGuildPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyGuildPayload.cs index 9de19a3171..c4f5f15c6f 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyGuildPayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyGuildPayload.cs @@ -71,4 +71,4 @@ public sealed record ModifyGuildPayload : IModifyGuildPayload /// public Optional SafetyAlertsChannelId { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyGuildRolePayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyGuildRolePayload.cs index 7cbfb6369a..78a1a9b50e 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyGuildRolePayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyGuildRolePayload.cs @@ -30,4 +30,4 @@ public sealed record ModifyGuildRolePayload : IModifyGuildRolePayload /// public Optional Mentionable { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyGuildRolePositionsPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyGuildRolePositionsPayload.cs index 2e717a3d5e..e454455230 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyGuildRolePositionsPayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyGuildRolePositionsPayload.cs @@ -14,4 +14,4 @@ public sealed record ModifyGuildRolePositionsPayload : IModifyGuildRolePositions /// public Optional Position { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyGuildWelcomeScreenPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyGuildWelcomeScreenPayload.cs index 234267ae01..925a170b4d 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyGuildWelcomeScreenPayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyGuildWelcomeScreenPayload.cs @@ -20,4 +20,4 @@ public sealed record ModifyGuildWelcomeScreenPayload : IModifyGuildWelcomeScreen /// public Optional Description { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyUserVoiceStatePayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyUserVoiceStatePayload.cs index aaf8c9c3f4..a861f58679 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyUserVoiceStatePayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyUserVoiceStatePayload.cs @@ -14,4 +14,4 @@ public sealed record ModifyUserVoiceStatePayload : IModifyUserVoiceStatePayload /// public Optional Suppress { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Interactions/EditFollowupMessagePayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Interactions/EditFollowupMessagePayload.cs index e2622e3ed3..00cde4d846 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/Interactions/EditFollowupMessagePayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Interactions/EditFollowupMessagePayload.cs @@ -29,4 +29,4 @@ public sealed record EditFollowupMessagePayload : IEditFollowupMessagePayload /// public IReadOnlyList? Files { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Interactions/EditInteractionResponsePayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Interactions/EditInteractionResponsePayload.cs index 4d3f44d2f1..36a2c46875 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/Interactions/EditInteractionResponsePayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Interactions/EditInteractionResponsePayload.cs @@ -29,4 +29,4 @@ public sealed record EditInteractionResponsePayload : IEditInteractionResponsePa /// public IReadOnlyList? Files { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/ScheduledEvents/CreateGuildScheduledEventPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/ScheduledEvents/CreateGuildScheduledEventPayload.cs index 878f4cff20..ddccf69d77 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/ScheduledEvents/CreateGuildScheduledEventPayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/ScheduledEvents/CreateGuildScheduledEventPayload.cs @@ -39,4 +39,4 @@ public sealed record CreateGuildScheduledEventPayload : ICreateGuildScheduledEve /// public Optional Image { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/ScheduledEvents/ModifyGuildScheduledEventPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/ScheduledEvents/ModifyGuildScheduledEventPayload.cs index 6ffa92f810..7050c6a108 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/ScheduledEvents/ModifyGuildScheduledEventPayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/ScheduledEvents/ModifyGuildScheduledEventPayload.cs @@ -42,4 +42,4 @@ public sealed record ModifyGuildScheduledEventPayload : IModifyGuildScheduledEve /// public Optional Image { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/StageInstances/CreateStageInstancePayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/StageInstances/CreateStageInstancePayload.cs index 0439844832..918eb113a5 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/StageInstances/CreateStageInstancePayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/StageInstances/CreateStageInstancePayload.cs @@ -24,4 +24,4 @@ public sealed record CreateStageInstancePayload : ICreateStageInstancePayload /// public Optional GuildScheduledEventId { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/StageInstances/ModifyStageInstancePayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/StageInstances/ModifyStageInstancePayload.cs index 0f3bf6b5fa..d49d997fa0 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/StageInstances/ModifyStageInstancePayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/StageInstances/ModifyStageInstancePayload.cs @@ -15,4 +15,4 @@ public sealed record ModifyStageInstancePayload : IModifyStageInstancePayload /// public Optional PrivacyLevel { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Stickers/CreateGuildStickerPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Stickers/CreateGuildStickerPayload.cs index 29cbbfe5af..cd1039b969 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/Stickers/CreateGuildStickerPayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Stickers/CreateGuildStickerPayload.cs @@ -20,4 +20,4 @@ public sealed record CreateGuildStickerPayload : ICreateGuildStickerPayload /// public required AttachmentData File { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Stickers/ModifyGuildStickerPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Stickers/ModifyGuildStickerPayload.cs index 7eb3d43cbb..cc3e6942d0 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/Stickers/ModifyGuildStickerPayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Stickers/ModifyGuildStickerPayload.cs @@ -17,4 +17,4 @@ public sealed record ModifyGuildStickerPayload : IModifyGuildStickerPayload /// public Optional Tags { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Users/CreateDmPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Users/CreateDmPayload.cs index 7365e13813..dd25507054 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/Users/CreateDmPayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Users/CreateDmPayload.cs @@ -11,4 +11,4 @@ public sealed record CreateDmPayload : ICreateDmPayload { /// public required Snowflake RecipientId { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Users/CreateGroupDmPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Users/CreateGroupDmPayload.cs index 7209c0f482..b13986d780 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/Users/CreateGroupDmPayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Users/CreateGroupDmPayload.cs @@ -16,4 +16,4 @@ public sealed record CreateGroupDmPayload : ICreateGroupDmPayload /// public required IReadOnlyDictionary Nicks { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Users/ModifyCurrentUserPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Users/ModifyCurrentUserPayload.cs index 7c4678433e..9fa4056d69 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/Users/ModifyCurrentUserPayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Users/ModifyCurrentUserPayload.cs @@ -14,4 +14,4 @@ public sealed record ModifyCurrentUserPayload : IModifyCurrentUserPayload /// public Optional Avatar { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Users/UpdateCurrentUserApplicationRoleConnectionPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Users/UpdateCurrentUserApplicationRoleConnectionPayload.cs index 3e9e8bbce6..8abee779e3 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/Users/UpdateCurrentUserApplicationRoleConnectionPayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Users/UpdateCurrentUserApplicationRoleConnectionPayload.cs @@ -17,4 +17,4 @@ public sealed record UpdateCurrentUserApplicationRoleConnectionPayload : IUpdate /// public Optional Metadata { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Webhooks/CreateWebhookPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Webhooks/CreateWebhookPayload.cs index 29f2f2e959..b9c5145e2d 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/Webhooks/CreateWebhookPayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Webhooks/CreateWebhookPayload.cs @@ -14,4 +14,4 @@ public sealed record CreateWebhookPayload : ICreateWebhookPayload /// public Optional Avatar { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Webhooks/EditWebhookMessagePayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Webhooks/EditWebhookMessagePayload.cs index cbd3db2f6a..350f9d5e94 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/Webhooks/EditWebhookMessagePayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Webhooks/EditWebhookMessagePayload.cs @@ -29,4 +29,4 @@ public sealed record EditWebhookMessagePayload : IEditWebhookMessagePayload /// public Optional?> Attachments { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Webhooks/ModifyWebhookPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Webhooks/ModifyWebhookPayload.cs index 574247327d..f01edbb06b 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/Webhooks/ModifyWebhookPayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Webhooks/ModifyWebhookPayload.cs @@ -17,4 +17,4 @@ public sealed record ModifyWebhookPayload : IModifyWebhookPayload /// public Optional ChannelId { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Webhooks/ModifyWebhookWithTokenPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Webhooks/ModifyWebhookWithTokenPayload.cs index fa1bc16abc..bc700053b2 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/Webhooks/ModifyWebhookWithTokenPayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Webhooks/ModifyWebhookWithTokenPayload.cs @@ -14,4 +14,4 @@ public sealed record ModifyWebhookWithTokenPayload : IModifyWebhookWithTokenPayl /// public Optional Avatar { get; init; } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Shared/AttachmentData.cs b/src/core/DSharpPlus.Shared/AttachmentData.cs index da13a36a55..93a2cd87e9 100644 --- a/src/core/DSharpPlus.Shared/AttachmentData.cs +++ b/src/core/DSharpPlus.Shared/AttachmentData.cs @@ -2,13 +2,13 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +using System; using System.Buffers; +using System.Buffers.Text; using System.Diagnostics; -using System; using System.IO; using System.IO.Pipelines; using System.Threading.Tasks; -using System.Buffers.Text; namespace DSharpPlus; @@ -18,7 +18,7 @@ namespace DSharpPlus; public readonly record struct AttachmentData { private readonly Stream stream; - + /// /// The media type of this attachment. Defaults to empty, in which case it will be interpreted according to /// the file extension as provided by . @@ -104,7 +104,7 @@ private readonly async ValueTask WriteToPipeAsBase64Async(PipeWriter writer) PipeReader reader = PipeReader.Create ( - this.stream, + this.stream, new StreamPipeReaderOptions ( bufferSize: 12288, diff --git a/src/core/DSharpPlus.Shared/Entities/AuditLogs/DiscordAuditLogEvent.cs b/src/core/DSharpPlus.Shared/Entities/AuditLogs/DiscordAuditLogEvent.cs index b9ebed3e82..bbe09a5e86 100644 --- a/src/core/DSharpPlus.Shared/Entities/AuditLogs/DiscordAuditLogEvent.cs +++ b/src/core/DSharpPlus.Shared/Entities/AuditLogs/DiscordAuditLogEvent.cs @@ -416,7 +416,7 @@ public enum DiscordAuditLogEvent /// Metadata is provided for an auto moderation rule object. /// AutoModerationRuleDeleted = 142, - + /// /// A message was blocked by the discord automod. /// diff --git a/src/core/DSharpPlus.Shared/Entities/Guilds/DiscordGuildMemberFlags.cs b/src/core/DSharpPlus.Shared/Entities/Guilds/DiscordGuildMemberFlags.cs index 5eeebffb4a..0ae15f52be 100644 --- a/src/core/DSharpPlus.Shared/Entities/Guilds/DiscordGuildMemberFlags.cs +++ b/src/core/DSharpPlus.Shared/Entities/Guilds/DiscordGuildMemberFlags.cs @@ -13,7 +13,7 @@ namespace DSharpPlus.Entities; public enum DiscordGuildMemberFlags { None = 0, - + /// /// Indicates that this member has left and rejoined this guild. /// diff --git a/src/core/DSharpPlus.Shared/Entities/Users/DiscordUserFlags.cs b/src/core/DSharpPlus.Shared/Entities/Users/DiscordUserFlags.cs index 1fe56566c8..eb2e0402f1 100644 --- a/src/core/DSharpPlus.Shared/Entities/Users/DiscordUserFlags.cs +++ b/src/core/DSharpPlus.Shared/Entities/Users/DiscordUserFlags.cs @@ -35,7 +35,7 @@ public enum DiscordUserFlags /// /// First of two badges for bug hunters. Discord doesn't tell us any further information. /// - BugHunterLevel1 = 1 << 3, + BugHunterLevel1 = 1 << 3, /// /// Profile badge indicating this user is a member of the HypeSquad House of Bravery. @@ -60,12 +60,12 @@ public enum DiscordUserFlags /// /// Profile badge indicating... what, exactly? Discord doesn't tell us. /// - TeamUser = 1 << 10, + TeamUser = 1 << 10, /// /// Bug hunter badge, Level 2 /// - BugHunterLevel2 = 1 << 14, + BugHunterLevel2 = 1 << 14, /// /// Profile badge indicating this bot is a verified bot. diff --git a/src/core/DSharpPlus.Shared/ImageData.cs b/src/core/DSharpPlus.Shared/ImageData.cs index cb4c2dad3c..8f427a376c 100644 --- a/src/core/DSharpPlus.Shared/ImageData.cs +++ b/src/core/DSharpPlus.Shared/ImageData.cs @@ -99,11 +99,11 @@ public readonly void WriteTo(ArrayPoolBufferWriter writer) OperationStatus status = Base64.EncodeToUtf8 ( - bytes: readSpan[..currentLength], - utf8: writeSpan, - bytesConsumed: out int consumed, - bytesWritten: out int written, - isFinalBlock: false + bytes: readSpan[..currentLength], + utf8: writeSpan, + bytesConsumed: out int consumed, + bytesWritten: out int written, + isFinalBlock: false ); Debug.Assert(status is OperationStatus.Done or OperationStatus.NeedMoreData); diff --git a/src/core/DSharpPlus.Shared/Serialization/ImageDataConverter.cs b/src/core/DSharpPlus.Shared/Serialization/ImageDataConverter.cs index 52ae3feee2..f40f9d50a5 100644 --- a/src/core/DSharpPlus.Shared/Serialization/ImageDataConverter.cs +++ b/src/core/DSharpPlus.Shared/Serialization/ImageDataConverter.cs @@ -19,8 +19,8 @@ public sealed class ImageDataConverter : JsonConverter public override void Write ( - Utf8JsonWriter writer, - ImageData value, + Utf8JsonWriter writer, + ImageData value, JsonSerializerOptions options ) { diff --git a/src/core/DSharpPlus.Shared/Serialization/RedirectingConverter.cs b/src/core/DSharpPlus.Shared/Serialization/RedirectingConverter.cs index 753304aaf5..124e3db57d 100644 --- a/src/core/DSharpPlus.Shared/Serialization/RedirectingConverter.cs +++ b/src/core/DSharpPlus.Shared/Serialization/RedirectingConverter.cs @@ -16,8 +16,8 @@ internal sealed class RedirectingConverter : JsonConverter ( ReadOnlySpan data - ) + ) where TModel : notnull { return this.format switch @@ -84,19 +84,19 @@ ReadOnlySpan data /// public void SerializeModel ( - TModel model, + TModel model, ArrayPoolBufferWriter target - ) + ) where TModel : notnull { switch (this.format) { case "json": - { - using Utf8JsonWriter writer = new(target); - JsonSerializer.Serialize(writer, model, this.jsonOptions!); - break; - } + { + using Utf8JsonWriter writer = new(target); + JsonSerializer.Serialize(writer, model, this.jsonOptions!); + break; + } default: throw new InvalidOperationException($"The model could not be serialized to {this.format}."); } diff --git a/src/core/DSharpPlus.Shared/Snowflake.GenericMath.cs b/src/core/DSharpPlus.Shared/Snowflake.GenericMath.cs index 5c4f102e91..71f0c7df9a 100644 --- a/src/core/DSharpPlus.Shared/Snowflake.GenericMath.cs +++ b/src/core/DSharpPlus.Shared/Snowflake.GenericMath.cs @@ -5,12 +5,12 @@ #pragma warning disable CA1031 using System; -using System.Numerics; -using System.Globalization; +using System.Buffers.Binary; using System.Diagnostics.CodeAnalysis; +using System.Globalization; +using System.Numerics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -using System.Buffers.Binary; namespace DSharpPlus; @@ -939,7 +939,7 @@ ref MemoryMarshal.GetReference(destination), => -value.Value; /// - public static Snowflake operator -(Snowflake left,Snowflake right) + public static Snowflake operator -(Snowflake left, Snowflake right) => left.Value - right.Value; /// diff --git a/src/extensions/DSharpPlus.Extensions.Internal.Builders/Implementations/BuiltActionRowComponent.cs b/src/extensions/DSharpPlus.Extensions.Internal.Builders/Implementations/BuiltActionRowComponent.cs index 787d50e3ae..4eba4dadf6 100644 --- a/src/extensions/DSharpPlus.Extensions.Internal.Builders/Implementations/BuiltActionRowComponent.cs +++ b/src/extensions/DSharpPlus.Extensions.Internal.Builders/Implementations/BuiltActionRowComponent.cs @@ -17,4 +17,4 @@ internal sealed record BuiltActionRowComponent : IActionRowComponent /// public required IReadOnlyList Components { get; init; } -} \ No newline at end of file +} diff --git a/src/extensions/DSharpPlus.Extensions.Internal.Builders/Implementations/BuiltEmbed.cs b/src/extensions/DSharpPlus.Extensions.Internal.Builders/Implementations/BuiltEmbed.cs index 54c6e242d7..c482c18f3e 100644 --- a/src/extensions/DSharpPlus.Extensions.Internal.Builders/Implementations/BuiltEmbed.cs +++ b/src/extensions/DSharpPlus.Extensions.Internal.Builders/Implementations/BuiltEmbed.cs @@ -50,4 +50,4 @@ internal sealed record BuiltEmbed : IEmbed /// public Optional> Fields { get; init; } -} \ No newline at end of file +} diff --git a/src/extensions/DSharpPlus.Extensions.Internal.Builders/Implementations/BuiltInteractionResponse.cs b/src/extensions/DSharpPlus.Extensions.Internal.Builders/Implementations/BuiltInteractionResponse.cs index 67ef92edf2..b6bd35b0db 100644 --- a/src/extensions/DSharpPlus.Extensions.Internal.Builders/Implementations/BuiltInteractionResponse.cs +++ b/src/extensions/DSharpPlus.Extensions.Internal.Builders/Implementations/BuiltInteractionResponse.cs @@ -17,4 +17,4 @@ internal sealed record BuiltInteractionResponse : IInteractionResponse /// public Optional> Data { get; init; } -} \ No newline at end of file +} diff --git a/src/extensions/DSharpPlus.Extensions.Internal.Builders/Implementations/BuiltModalCallbackData.cs b/src/extensions/DSharpPlus.Extensions.Internal.Builders/Implementations/BuiltModalCallbackData.cs index 9614bbf91c..3d62263f97 100644 --- a/src/extensions/DSharpPlus.Extensions.Internal.Builders/Implementations/BuiltModalCallbackData.cs +++ b/src/extensions/DSharpPlus.Extensions.Internal.Builders/Implementations/BuiltModalCallbackData.cs @@ -19,4 +19,4 @@ internal sealed record BuiltModalCallbackData : IModalCallbackData /// public required IReadOnlyList Components { get; init; } -} \ No newline at end of file +} diff --git a/src/extensions/DSharpPlus.Extensions.Internal.Builders/Implementations/BuiltTextInputComponent.cs b/src/extensions/DSharpPlus.Extensions.Internal.Builders/Implementations/BuiltTextInputComponent.cs index f812b1c8ee..8bd290958d 100644 --- a/src/extensions/DSharpPlus.Extensions.Internal.Builders/Implementations/BuiltTextInputComponent.cs +++ b/src/extensions/DSharpPlus.Extensions.Internal.Builders/Implementations/BuiltTextInputComponent.cs @@ -36,4 +36,4 @@ internal sealed record BuiltTextInputComponent : ITextInputComponent /// public Optional Placeholder { get; init; } -} \ No newline at end of file +} diff --git a/src/extensions/DSharpPlus.Extensions.Internal.Builders/Interactions/TextInputComponentBuilder.cs b/src/extensions/DSharpPlus.Extensions.Internal.Builders/Interactions/TextInputComponentBuilder.cs index 9af176670b..af460f5f2a 100644 --- a/src/extensions/DSharpPlus.Extensions.Internal.Builders/Interactions/TextInputComponentBuilder.cs +++ b/src/extensions/DSharpPlus.Extensions.Internal.Builders/Interactions/TextInputComponentBuilder.cs @@ -231,7 +231,10 @@ public static ITextInputComponent Build(ref this TextInputComponentBuilder build { ArgumentNullException.ThrowIfNull(builder.CustomId); ArgumentNullException.ThrowIfNull(builder.Label); - ArgumentNullException.ThrowIfNull(builder.Style); + if (!builder.Style.HasValue) + { + throw new ArgumentNullException(nameof(builder.Style)); + } return new BuiltTextInputComponent { diff --git a/tests/core/DSharpPlus.Internal.Models.Tests/Converters/AuditLogChangeTests.cs b/tests/core/DSharpPlus.Internal.Models.Tests/Converters/AuditLogChangeTests.cs index 8790e460c9..64d8631036 100644 --- a/tests/core/DSharpPlus.Internal.Models.Tests/Converters/AuditLogChangeTests.cs +++ b/tests/core/DSharpPlus.Internal.Models.Tests/Converters/AuditLogChangeTests.cs @@ -40,7 +40,7 @@ public AuditLogChangeTests() this.serializer = provider.GetRequiredService>(); } - private static readonly byte[] IntPayload = + private static readonly byte[] IntPayload = """ { "key": "$test", @@ -48,7 +48,7 @@ public AuditLogChangeTests() "old_value": 83 } """u8.ToArray(); - + private static readonly byte[] StringPayload = """ { @@ -73,7 +73,7 @@ public AuditLogChangeTests() "new_value": "this is the new value" } """u8.ToArray(); - + [Fact] public void TestIntegerPayload() { From d4368a884e4aa984fa65d6b6a4e07786986ecadc Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Tue, 21 May 2024 14:26:01 +0200 Subject: [PATCH 295/323] fix xmldocs, spacing issues and analyzer warnings --- .../IApplicationCommand.cs | 10 +++---- .../IApplicationCommandOption.cs | 30 +++++++++---------- .../IApplicationCommandOptionChoice.cs | 4 +-- .../AuditLogs/IAuditLogChange.cs | 4 +-- .../AuditLogs/IAuditLogEntryInfo.cs | 6 ++-- .../IAutoModerationTriggerMetadata.cs | 4 +-- .../IBlockMessageActionMetadata.cs | 2 +- .../ISendAlertMessageActionMetadata.cs | 2 +- .../AutoModeration/ITimeoutActionMetadata.cs | 2 +- .../Channels/IAllowedMentions.cs | 4 +-- .../Channels/IDefaultReaction.cs | 4 +-- .../Channels/IForumTag.cs | 4 +-- .../Channels/IPartialChannel.cs | 4 +-- .../Channels/IPartialMessage.cs | 4 +-- .../Guilds/IOnboardingPrompt.cs | 2 +- .../Guilds/IPartialGuild.cs | 2 +- .../Interactions/IInteraction.cs | 2 +- .../Interactions/IResolvedData.cs | 2 +- .../MessageComponents/IActionRowComponent.cs | 2 +- .../MessageComponents/IButtonComponent.cs | 4 +-- .../IChannelSelectComponent.cs | 2 +- .../MessageComponents/IDefaultSelectValue.cs | 2 +- .../IMentionableSelectComponent.cs | 2 +- .../MessageComponents/IRoleSelectComponent.cs | 2 +- .../MessageComponents/ISelectOption.cs | 2 +- .../MessageComponents/IUserSelectComponent.cs | 2 +- .../Polls/IPollAnswerCount.cs | 2 +- .../Polls/IPollMedia.cs | 4 +-- .../Polls/IPollResults.cs | 2 +- .../IRoleConnectionMetadata.cs | 4 +-- .../Teams/ITeamMember.cs | 2 +- .../API/IChannelRestAPI.cs | 2 +- .../API/IGuildScheduledEventRestAPI.cs | 2 +- .../API/IInteractionRestAPI.cs | 6 ++-- .../API/ISkusRestAPI.cs | 3 +- .../API/IStickerRestAPI.cs | 1 + .../API/IUserRestAPI.cs | 2 +- .../API/IWebhookRestAPI.cs | 4 +-- .../ICreateGlobalApplicationCommandPayload.cs | 6 ++-- .../ICreateGuildApplicationCommandPayload.cs | 4 +-- .../IEditGlobalApplicationCommandPayload.cs | 6 ++-- .../IEditGuildApplicationCommandPayload.cs | 4 +-- .../IEditCurrentApplicationPayload.cs | 1 + .../ICreateAutoModerationRulePayload.cs | 1 + .../IModifyAutoModerationRulePayload.cs | 1 + .../Channels/ICreateChannelInvitePayload.cs | 4 +-- .../Channels/ICreateMessagePayload.cs | 2 +- .../Payloads/Channels/IEditMessagePayload.cs | 1 + .../Channels/IForumAndMediaThreadMessage.cs | 1 + .../Channels/IModifyGuildChannelPayload.cs | 9 +++--- .../Guilds/ICreateGuildChannelPayload.cs | 1 + .../Payloads/Guilds/ICreateGuildPayload.cs | 15 +++++----- .../Guilds/IModifyGuildOnboardingPayload.cs | 1 + .../ICreateFollowupMessagePayload.cs | 2 +- .../ICreateGuildScheduledEventPayload.cs | 1 + .../IModifyGuildScheduledEventPayload.cs | 1 + .../Channels/GetChannelMessagesQuery.cs | 6 ++-- .../RetryMode.cs | 2 +- .../Extensions/ServiceCollectionExtensions.cs | 2 ++ .../ApplicationIntegrationTypeKeyConverter.cs | 4 +-- .../Converters/AuditLogChangeConverter.cs | 2 +- .../AutoModerationActionConverter.cs | 6 +++- .../Converters/MessageComponentConverter.cs | 1 + .../Converters/NullBooleanConverter.cs | 2 +- .../Converters/OptionalConverter.cs | 2 +- .../Converters/OptionalConverterFactory.cs | 2 +- .../Converters/SnowflakeConverter.cs | 2 ++ .../Resolvers/OptionalTypeInfoResolver.cs | 2 +- .../API/StageInstanceRestAPI.cs | 1 + .../Ratelimiting/IRatelimitRegistry.cs | 4 +-- .../Ratelimiting/RatelimitBucket.cs | 8 ++--- .../Ratelimiting/RatelimitRegistry.cs | 6 ++-- .../RequestBuilderExtensions.cs | 2 ++ src/core/DSharpPlus.Shared/AttachmentData.cs | 22 ++++++++++---- .../Applications/DiscordApplicationFlags.cs | 6 ++-- .../DiscordAutoModerationActionType.cs | 4 +-- .../DiscordAutoModerationPresetType.cs | 2 +- .../Entities/Channels/DiscordChannelType.cs | 2 +- .../DiscordInteractionCallbackType.cs | 2 +- .../DiscordScheduledEventStatus.cs | 2 +- src/core/DSharpPlus.Shared/ImageData.cs | 2 ++ src/core/DSharpPlus.Shared/ImageFormat.cs | 2 +- .../Results/Errors/ArgumentError.cs | 6 ++-- .../Results/Errors/ArgumentNullError.cs | 6 ++-- .../Results/Errors/ArgumentOutOfRangeError.cs | 6 ++-- .../Results/Errors/InvalidOperationError.cs | 4 +-- .../ExceptionServices/MarshalException.cs | 10 +++---- .../DSharpPlus.Shared/Results/Result`1.cs | 1 + .../Errors/BuilderValidationError.cs | 4 +-- .../Interactions/ModalBuilder.cs | 2 ++ .../Interactions/TextInputComponentBuilder.cs | 5 +++- .../Messages/EmbedBuilder.cs | 2 +- .../Converters/AuditLogChangeTests.cs | 2 ++ .../Converters/OneOfConverterTests.Models.cs | 2 ++ 94 files changed, 199 insertions(+), 154 deletions(-) diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/ApplicationCommands/IApplicationCommand.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/ApplicationCommands/IApplicationCommand.cs index 4237c906c1..c8a2d3baf9 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Models/ApplicationCommands/IApplicationCommand.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/ApplicationCommands/IApplicationCommand.cs @@ -20,7 +20,7 @@ public interface IApplicationCommand public Snowflake Id { get; } /// - /// The type of this command, default: . + /// The type of this command, default: . /// public Optional Type { get; } @@ -40,19 +40,19 @@ public interface IApplicationCommand public string Name { get; } /// - /// A localization dictionary for , with the keys being locales. + /// A localization dictionary for , with the keys being locales. /// public Optional?> NameLocalizations { get; } /// - /// If this command is a command, the + /// If this command is a command, the /// description of this command, between 1 and 100 characters. This is an empty string for all /// other command types. /// public string Description { get; } /// - /// A localization dictionary for , with the keys being locales. + /// A localization dictionary for , with the keys being locales. /// public Optional?> DescriptionLocalizations { get; } @@ -73,7 +73,7 @@ public interface IApplicationCommand /// /// Specifies installation contexts where this command is available; only for globally-scoped commands. Defaults to - /// . + /// . /// public Optional> IntegrationTypes { get; } diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/ApplicationCommands/IApplicationCommandOption.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/ApplicationCommands/IApplicationCommandOption.cs index 1e6a5ea852..fd7f826380 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Models/ApplicationCommands/IApplicationCommandOption.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/ApplicationCommands/IApplicationCommandOption.cs @@ -26,7 +26,7 @@ public interface IApplicationCommandOption public string Name { get; } /// - /// A localization dictionary for , with the keys being locales. + /// A localization dictionary for , with the keys being locales. /// public Optional?> NameLocalizations { get; } @@ -36,7 +36,7 @@ public interface IApplicationCommandOption public string Description { get; } /// - /// A localization dictionary for , with the keys being locales. + /// A localization dictionary for , with the keys being locales. /// public Optional?> DescriptionLocalizations { get; } @@ -46,53 +46,53 @@ public interface IApplicationCommandOption public Optional Required { get; } /// - /// If this application command option is of , - /// or - /// , up to 25 options to choose from. + /// If this application command option is of , + /// or + /// , up to 25 options to choose from. /// These options will be the only valid options for this command. /// public Optional> Choices { get; } /// - /// If this option is of or - /// , these options will be the + /// If this option is of or + /// , these options will be the /// parameters (or subcommands if this is a subcommand group). /// public Optional> Options { get; } /// - /// If this option is of , shown + /// If this option is of , shown /// channels will be restricted to these types. /// public Optional> ChannelTypes { get; } /// - /// If this option is of or - /// , the minimum value permitted. + /// If this option is of or + /// , the minimum value permitted. /// public Optional> MinValue { get; } /// - /// If this option is of or - /// , the maximum value permitted. + /// If this option is of or + /// , the maximum value permitted. /// public Optional> MaxValue { get; } /// - /// If this option is of , the minimum + /// If this option is of , the minimum /// length permitted, between 0 and 6000. /// public Optional MinLength { get; } /// - /// If this option is of , the maximum + /// If this option is of , the maximum /// length permitted, between 1 and 6000. /// public Optional MaxLength { get; } /// /// Indicates whether this option is subject to autocomplete. This is mutually exclusive with - /// being defined. + /// being defined. /// public Optional Autocomplete { get; } } diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/ApplicationCommands/IApplicationCommandOptionChoice.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/ApplicationCommands/IApplicationCommandOptionChoice.cs index 39a793e75c..045aaf4b96 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Models/ApplicationCommands/IApplicationCommandOptionChoice.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/ApplicationCommands/IApplicationCommandOptionChoice.cs @@ -9,7 +9,7 @@ namespace DSharpPlus.Internal.Abstractions.Models; /// -/// Specifies one choice for a . +/// Specifies one choice for a . /// public interface IApplicationCommandOptionChoice { @@ -19,7 +19,7 @@ public interface IApplicationCommandOptionChoice public string Name { get; } /// - /// A localization dictionary for , with the keys being locales. + /// A localization dictionary for , with the keys being locales. /// public Optional?> NameLocalizations { get; } diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/AuditLogs/IAuditLogChange.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/AuditLogs/IAuditLogChange.cs index bf3aa04fa2..e6f6fbecb3 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Models/AuditLogs/IAuditLogChange.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/AuditLogs/IAuditLogChange.cs @@ -21,8 +21,8 @@ public interface IAuditLogChange /// /// The name of the changed field, with a few exceptions: see - /// - /// the documentation. + /// + /// the documentation. /// public string Key { get; } } diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/AuditLogs/IAuditLogEntryInfo.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/AuditLogs/IAuditLogEntryInfo.cs index 8df589af49..5d3246bc2b 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Models/AuditLogs/IAuditLogEntryInfo.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/AuditLogs/IAuditLogEntryInfo.cs @@ -8,10 +8,10 @@ namespace DSharpPlus.Internal.Abstractions.Models; /// Contains additional metadata for an audit log entry. /// /// -/// Presence of a field is dictated by its parent . When deciding +/// Presence of a field is dictated by its parent . When deciding /// what to access, refer to the -/// -/// Event Types section in the docs. +/// +/// Event Types section in the docs. /// public interface IAuditLogEntryInfo { diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/AutoModeration/IAutoModerationTriggerMetadata.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/AutoModeration/IAutoModerationTriggerMetadata.cs index 97bbddf6ea..5200bd3813 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Models/AutoModeration/IAutoModerationTriggerMetadata.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/AutoModeration/IAutoModerationTriggerMetadata.cs @@ -13,8 +13,8 @@ namespace DSharpPlus.Internal.Abstractions.Models; /// /// /// Which fields may be meaningful depends on the trigger type of the parent rule, see -/// -/// the documentation for additional information. +/// +/// the documentation for additional information. /// public interface IAutoModerationTriggerMetadata { diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/AutoModeration/IBlockMessageActionMetadata.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/AutoModeration/IBlockMessageActionMetadata.cs index 2fe8f251cb..95b8d05039 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Models/AutoModeration/IBlockMessageActionMetadata.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/AutoModeration/IBlockMessageActionMetadata.cs @@ -8,7 +8,7 @@ namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents metadata for auto moderation actions of type -/// . +/// . /// public interface IBlockMessageActionMetadata : IAutoModerationActionMetadata { diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/AutoModeration/ISendAlertMessageActionMetadata.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/AutoModeration/ISendAlertMessageActionMetadata.cs index 2ef0e36214..1fceec8262 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Models/AutoModeration/ISendAlertMessageActionMetadata.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/AutoModeration/ISendAlertMessageActionMetadata.cs @@ -8,7 +8,7 @@ namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents metadata for auto moderation actions of type -/// . +/// . /// public interface ISendAlertMessageActionMetadata : IAutoModerationActionMetadata { diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/AutoModeration/ITimeoutActionMetadata.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/AutoModeration/ITimeoutActionMetadata.cs index 2730f4b053..0cfd9dac4b 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Models/AutoModeration/ITimeoutActionMetadata.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/AutoModeration/ITimeoutActionMetadata.cs @@ -8,7 +8,7 @@ namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents metadata for auto moderation actions of type -/// . +/// . /// public interface ITimeoutActionMetadata : IAutoModerationActionMetadata { diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IAllowedMentions.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IAllowedMentions.cs index c859f3540e..3b0e0145ee 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IAllowedMentions.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IAllowedMentions.cs @@ -9,8 +9,8 @@ namespace DSharpPlus.Internal.Abstractions.Models; /// /// Stores information about what mentions should be allowed and which ones should be /// ignored when handling read states and notifications. Refer to -/// -/// the Discord docs for further information. +/// +/// the Discord docs for further information. /// public interface IAllowedMentions { diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IDefaultReaction.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IDefaultReaction.cs index 8366668e9f..ca38a57e70 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IDefaultReaction.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IDefaultReaction.cs @@ -11,13 +11,13 @@ public interface IDefaultReaction { /// /// The snowflake identifier of a custom emoji to react with. Mutually exclusive with - /// . + /// . /// public Snowflake? EmojiId { get; } /// /// The unicode representation of a default emoji to react with. Mutually exclusive with - /// . + /// . /// public string? EmojiName { get; } } diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IForumTag.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IForumTag.cs index 5d2e507146..adc7b3d8e6 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IForumTag.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IForumTag.cs @@ -26,13 +26,13 @@ public interface IForumTag /// /// The snowflake identifier of a custom emoji to be applied to this tag. Mutually exclusive with - /// . + /// . /// public Snowflake? EmojiId { get; } /// /// The unicode representation of a default emoji to be applied to this tag. Mutually exclusive with - /// . + /// . /// public string? EmojiName { get; } } diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IPartialChannel.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IPartialChannel.cs index 490fcf97b2..da1d17eb5a 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IPartialChannel.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IPartialChannel.cs @@ -45,8 +45,8 @@ public interface IPartialChannel public Optional Name { get; } /// - /// The channel topic/description. For and - /// , up to 4096 characters are allowed, for all other + /// The channel topic/description. For and + /// , up to 4096 characters are allowed, for all other /// types up to 1024 characters. /// public Optional Topic { get; } diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IPartialMessage.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IPartialMessage.cs index 4b326c3a29..ee9c694041 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IPartialMessage.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IPartialMessage.cs @@ -26,7 +26,7 @@ public interface IPartialMessage /// /// The author of this message. This is not guaranteed to be a valid user; if this message was sent - /// by a webhook it will contain webhook metadata instead. Check to see + /// by a webhook it will contain webhook metadata instead. Check to see /// whether this message was generated by a webhook. /// public Optional Author { get; } @@ -135,7 +135,7 @@ public interface IPartialMessage public Optional Flags { get; } /// - /// The message associated with the . + /// The message associated with the . /// public Optional ReferencedMessage { get; } diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/Guilds/IOnboardingPrompt.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Guilds/IOnboardingPrompt.cs index 2e5dec4fec..3cfd252cca 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Models/Guilds/IOnboardingPrompt.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Guilds/IOnboardingPrompt.cs @@ -34,7 +34,7 @@ public interface IOnboardingPrompt public string Title { get; } /// - /// Indicates whether users are limited to selecting only one of the . + /// Indicates whether users are limited to selecting only one of the . /// public bool SingleSelect { get; } diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/Guilds/IPartialGuild.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Guilds/IPartialGuild.cs index f1d2041024..fef8962e80 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Models/Guilds/IPartialGuild.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Guilds/IPartialGuild.cs @@ -29,7 +29,7 @@ public interface IPartialGuild public Optional Icon { get; } /// - /// The icon hash for this guild. This field, unlike , is only sent when a part of + /// The icon hash for this guild. This field, unlike , is only sent when a part of /// the guild template object. /// public Optional IconHash { get; } diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/Interactions/IInteraction.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Interactions/IInteraction.cs index 7df06b9178..f7fe8a03fa 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Models/Interactions/IInteraction.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Interactions/IInteraction.cs @@ -36,7 +36,7 @@ public interface IInteraction public DiscordInteractionType Type { get; } /// - /// The data payload, depending on the . + /// The data payload, depending on the . /// public Optional> Data { get; } diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/Interactions/IResolvedData.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Interactions/IResolvedData.cs index a5ba0d8bee..6fc6ade4ca 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Models/Interactions/IResolvedData.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Interactions/IResolvedData.cs @@ -7,7 +7,7 @@ namespace DSharpPlus.Internal.Abstractions.Models; /// -/// Represents data resolved by Discord from s. +/// Represents data resolved by Discord from s. /// public interface IResolvedData { diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IActionRowComponent.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IActionRowComponent.cs index 136c58cb27..e146dc222d 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IActionRowComponent.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IActionRowComponent.cs @@ -14,7 +14,7 @@ namespace DSharpPlus.Internal.Abstractions.Models; public interface IActionRowComponent { /// - /// + /// /// public DiscordMessageComponentType Type { get; } diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IButtonComponent.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IButtonComponent.cs index 259f8a78ec..5b747d7297 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IButtonComponent.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IButtonComponent.cs @@ -33,12 +33,12 @@ public interface IButtonComponent : IInteractiveComponent /// /// A developer-defined identifier for this button, up to 100 characters. This is mutually - /// exclusive with . + /// exclusive with . /// public Optional CustomId { get; } /// - /// An URL for link-style buttons. This is mutually exclusive with . + /// An URL for link-style buttons. This is mutually exclusive with . /// public Optional Url { get; } diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IChannelSelectComponent.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IChannelSelectComponent.cs index 6fcc92eb2b..f1e5c580a7 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IChannelSelectComponent.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IChannelSelectComponent.cs @@ -36,7 +36,7 @@ public interface IChannelSelectComponent : IInteractiveComponent /// /// A list of default values for this select; the number of default values must be within the range defined by - /// and . + /// and . /// public Optional> DefaultValues { get; } diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IDefaultSelectValue.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IDefaultSelectValue.cs index 5f8e4b4071..f9317bb22b 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IDefaultSelectValue.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IDefaultSelectValue.cs @@ -15,7 +15,7 @@ public interface IDefaultSelectValue public Snowflake Id { get; } /// - /// The type of the value represented by ; either "user", "role" or "channel". + /// The type of the value represented by ; either "user", "role" or "channel". /// public string Type { get; } } diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IMentionableSelectComponent.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IMentionableSelectComponent.cs index 19ef590b58..6d9f442808 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IMentionableSelectComponent.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IMentionableSelectComponent.cs @@ -30,7 +30,7 @@ public interface IMentionableSelectComponent : IInteractiveComponent /// /// A list of default values for this select; the number of default values must be within the range defined by - /// and . + /// and . /// public Optional> DefaultValues { get; } diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IRoleSelectComponent.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IRoleSelectComponent.cs index b5cea01da7..a0e750a4d0 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IRoleSelectComponent.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IRoleSelectComponent.cs @@ -30,7 +30,7 @@ public interface IRoleSelectComponent : IInteractiveComponent /// /// A list of default values for this select; the number of default values must be within the range defined by - /// and . + /// and . /// public Optional> DefaultValues { get; } diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/ISelectOption.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/ISelectOption.cs index 025f18338a..2039698dac 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/ISelectOption.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/ISelectOption.cs @@ -5,7 +5,7 @@ namespace DSharpPlus.Internal.Abstractions.Models; /// -/// Represents a single text option in a . +/// Represents a single text option in a . /// public interface ISelectOption { diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IUserSelectComponent.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IUserSelectComponent.cs index 1477848520..1783f3a806 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IUserSelectComponent.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IUserSelectComponent.cs @@ -30,7 +30,7 @@ public interface IUserSelectComponent : IInteractiveComponent /// /// A list of default values for this select; the number of default values must be within the range defined by - /// and . + /// and . /// public Optional> DefaultValues { get; } diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/Polls/IPollAnswerCount.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Polls/IPollAnswerCount.cs index c27cdfc0b7..300b6737b2 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Models/Polls/IPollAnswerCount.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Polls/IPollAnswerCount.cs @@ -10,7 +10,7 @@ namespace DSharpPlus.Internal.Abstractions.Models; public interface IPollAnswerCount { /// - /// The ID of the answer, corresponds to . + /// The ID of the answer, corresponds to . /// public int Id { get; } diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/Polls/IPollMedia.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Polls/IPollMedia.cs index 156530800e..d8f9faf9be 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Models/Polls/IPollMedia.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Polls/IPollMedia.cs @@ -5,8 +5,8 @@ namespace DSharpPlus.Internal.Abstractions.Models; /// -/// The backing text field object for polls. Questions can only contain , while answers can also contain -/// . +/// The backing text field object for polls. Questions can only contain , while answers can also contain +/// . /// public interface IPollMedia { diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/Polls/IPollResults.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Polls/IPollResults.cs index 2213571dd1..4b458dbbb4 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Models/Polls/IPollResults.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Polls/IPollResults.cs @@ -11,7 +11,7 @@ namespace DSharpPlus.Internal.Abstractions.Models; /// /// /// While a poll is in progress, the results may not be entirely accurate, though they shouldn't deviate by much. -/// After a poll finishes, Discord performs a final, accurate tally. If is set to true, +/// After a poll finishes, Discord performs a final, accurate tally. If is set to true, /// this tally has concluded and the results are accurate. /// public interface IPollResults diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/RoleConnections/IRoleConnectionMetadata.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/RoleConnections/IRoleConnectionMetadata.cs index 029c4b11ad..524432b8ef 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Models/RoleConnections/IRoleConnectionMetadata.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/RoleConnections/IRoleConnectionMetadata.cs @@ -29,7 +29,7 @@ public interface IRoleConnectionMetadata public string Name { get; } /// - /// A localization dictionary for , with the keys being locales. + /// A localization dictionary for , with the keys being locales. /// public Optional?> NameLocalizations { get; } @@ -39,7 +39,7 @@ public interface IRoleConnectionMetadata public string Description { get; } /// - /// A localization dictionary for , with the keys being locales. + /// A localization dictionary for , with the keys being locales. /// public Optional?> DescriptionLocalizations { get; } } diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/Teams/ITeamMember.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Teams/ITeamMember.cs index 857b0d72e1..81f6e6ecf9 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Models/Teams/ITeamMember.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Teams/ITeamMember.cs @@ -9,7 +9,7 @@ namespace DSharpPlus.Internal.Abstractions.Models; /// -/// Represents a single member of a . +/// Represents a single member of a . /// public interface ITeamMember { diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IChannelRestAPI.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IChannelRestAPI.cs index 50dad1636b..7b38314e89 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IChannelRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IChannelRestAPI.cs @@ -554,7 +554,7 @@ public ValueTask> StartThreadWithoutMessageAsync /// /// The snowflake identifier of the parent forum channel. /// - /// A payload object for starting a thread from a message containing a . + /// A payload object for starting a thread from a message containing a . /// A new message is created, then a thread is started from it. /// /// An optional audit log reason. diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IGuildScheduledEventRestAPI.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IGuildScheduledEventRestAPI.cs index ea1c74594e..1dd9ee095b 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IGuildScheduledEventRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IGuildScheduledEventRestAPI.cs @@ -107,7 +107,7 @@ public ValueTask DeleteScheduledEventAsync ); /// - /// Returns objects for each participant of the given scheduled event. + /// Returns objects for each participant of the given scheduled event. /// /// The snowflake identifier of the guild this scheduled event belongs to. /// The snowflake identifier of the scheduled event in question. diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IInteractionRestAPI.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IInteractionRestAPI.cs index 51509db56c..f4a4f62481 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IInteractionRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IInteractionRestAPI.cs @@ -84,9 +84,9 @@ public ValueTask DeleteInteractionResponseAsync /// /// Creates a followup message for an interaction. If this is the first followup to a deferred interaction /// response as created by - /// , - /// ephemerality of this message will be dictated by the supplied - /// originally instead of . + /// , + /// ephemerality of this message will be dictated by the supplied + /// originally instead of . /// /// The snowflake identifier of your application. /// The interaction token received with the interaction. diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/API/ISkusRestAPI.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/ISkusRestAPI.cs index 995ea8aea4..8b9cd1719c 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/API/ISkusRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/ISkusRestAPI.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; + using DSharpPlus.Entities; using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Results; @@ -20,7 +21,7 @@ public interface ISkusRestAPI /// Returns all SKUs for a given applications. You will see two SKUs for your premium offering, "because of /// how our SKU and subscription systems work" - Discord.
/// For integration and testing entitlements you should use the SKU with type - /// . + /// . /// /// The snowflake identifier of the parent application. /// Additional instructions regarding this request. diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IStickerRestAPI.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IStickerRestAPI.cs index ea488a461d..488c2a909c 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IStickerRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IStickerRestAPI.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; + using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Internal.Abstractions.Rest.Payloads; using DSharpPlus.Internal.Abstractions.Rest.Responses; diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IUserRestAPI.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IUserRestAPI.cs index 162679cec4..ab9ef33f40 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IUserRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IUserRestAPI.cs @@ -64,7 +64,7 @@ public ValueTask> ModifyCurrentUserAsync /// Returns a list of partial guild objects representing the guilds the current user has joined. /// /// - /// defaults to 200 guilds, which is the maximum + /// defaults to 200 guilds, which is the maximum /// number of guilds an user account can join. Pagination is therefore not needed for obtaining user /// guilds, but may be needed for obtaining bot guilds. /// diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IWebhookRestAPI.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IWebhookRestAPI.cs index 07e47c5d3c..8ba186b1c1 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IWebhookRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IWebhookRestAPI.cs @@ -181,8 +181,8 @@ public ValueTask DeleteWebhookWithTokenAsync /// Additional instructions regarding this request. /// A cancellation token for this operation. /// - /// If was set to , a - /// object. If was set to + /// If was set to , a + /// object. If was set to /// , . /// public ValueTask> ExecuteWebhookAsync diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/ApplicationCommands/ICreateGlobalApplicationCommandPayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/ApplicationCommands/ICreateGlobalApplicationCommandPayload.cs index 924e1681ab..8de89b845c 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/ApplicationCommands/ICreateGlobalApplicationCommandPayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/ApplicationCommands/ICreateGlobalApplicationCommandPayload.cs @@ -20,7 +20,7 @@ public interface ICreateGlobalApplicationCommandPayload public string Name { get; } /// - /// A localization dictionary for the field. Values follow the same restrictions. + /// A localization dictionary for the field. Values follow the same restrictions. /// public Optional?> NameLocalizations { get; } @@ -30,7 +30,7 @@ public interface ICreateGlobalApplicationCommandPayload public Optional Description { get; } /// - /// A localization dictionary for the field. Values follow the same restrictions. + /// A localization dictionary for the field. Values follow the same restrictions. /// public Optional?> DescriptionLocalizations { get; } @@ -56,7 +56,7 @@ public interface ICreateGlobalApplicationCommandPayload /// /// Specifies installation contexts where this command is available; only for globally-scoped commands. Defaults to - /// . + /// . /// public IReadOnlyList IntegrationTypes { get; } diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/ApplicationCommands/ICreateGuildApplicationCommandPayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/ApplicationCommands/ICreateGuildApplicationCommandPayload.cs index be528ab2e4..5ba13e7218 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/ApplicationCommands/ICreateGuildApplicationCommandPayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/ApplicationCommands/ICreateGuildApplicationCommandPayload.cs @@ -20,7 +20,7 @@ public interface ICreateGuildApplicationCommandPayload public string Name { get; } /// - /// A localization dictionary for the field. Values follow the same restrictions. + /// A localization dictionary for the field. Values follow the same restrictions. /// public Optional?> NameLocalizations { get; } @@ -35,7 +35,7 @@ public interface ICreateGuildApplicationCommandPayload public Optional Description { get; } /// - /// A localization dictionary for the field. Values follow the same restrictions. + /// A localization dictionary for the field. Values follow the same restrictions. /// public Optional?> DescriptionLocalizations { get; } diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/ApplicationCommands/IEditGlobalApplicationCommandPayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/ApplicationCommands/IEditGlobalApplicationCommandPayload.cs index 1a2b0c1a94..6d0d3189aa 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/ApplicationCommands/IEditGlobalApplicationCommandPayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/ApplicationCommands/IEditGlobalApplicationCommandPayload.cs @@ -20,7 +20,7 @@ public interface IEditGlobalApplicationCommandPayload public Optional Name { get; } /// - /// A localization dictionary for the field. Values follow the same restrictions. + /// A localization dictionary for the field. Values follow the same restrictions. /// public Optional?> NameLocalizations { get; } @@ -30,7 +30,7 @@ public interface IEditGlobalApplicationCommandPayload public Optional Description { get; } /// - /// A localization dictionary for the field. Values follow the same restrictions. + /// A localization dictionary for the field. Values follow the same restrictions. /// public Optional?> DescriptionLocalizations { get; } @@ -56,7 +56,7 @@ public interface IEditGlobalApplicationCommandPayload /// /// Specifies installation contexts where this command is available; only for globally-scoped commands. Defaults to - /// . + /// . /// public IReadOnlyList IntegrationTypes { get; } diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/ApplicationCommands/IEditGuildApplicationCommandPayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/ApplicationCommands/IEditGuildApplicationCommandPayload.cs index 64eec077ef..4b9b76b7b2 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/ApplicationCommands/IEditGuildApplicationCommandPayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/ApplicationCommands/IEditGuildApplicationCommandPayload.cs @@ -20,7 +20,7 @@ public interface IEditGuildApplicationCommandPayload public Optional Name { get; } /// - /// A localization dictionary for the field. Values follow the same restrictions. + /// A localization dictionary for the field. Values follow the same restrictions. /// public Optional?> NameLocalizations { get; } @@ -30,7 +30,7 @@ public interface IEditGuildApplicationCommandPayload public Optional Description { get; } /// - /// A localization dictionary for the field. Values follow the same restrictions. + /// A localization dictionary for the field. Values follow the same restrictions. /// public Optional?> DescriptionLocalizations { get; } diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Applications/IEditCurrentApplicationPayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Applications/IEditCurrentApplicationPayload.cs index ddfa751138..fb3857bc81 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Applications/IEditCurrentApplicationPayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Applications/IEditCurrentApplicationPayload.cs @@ -3,6 +3,7 @@ // file, You can obtain one at https://mozilla.org/MPL/2.0/. using System.Collections.Generic; + using DSharpPlus.Entities; using DSharpPlus.Internal.Abstractions.Models; diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/AutoModeration/ICreateAutoModerationRulePayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/AutoModeration/ICreateAutoModerationRulePayload.cs index 3bfab72ef0..795f8a70cf 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/AutoModeration/ICreateAutoModerationRulePayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/AutoModeration/ICreateAutoModerationRulePayload.cs @@ -3,6 +3,7 @@ // file, You can obtain one at https://mozilla.org/MPL/2.0/. using System.Collections.Generic; + using DSharpPlus.Entities; using DSharpPlus.Internal.Abstractions.Models; diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/AutoModeration/IModifyAutoModerationRulePayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/AutoModeration/IModifyAutoModerationRulePayload.cs index a5b0ca9319..c173c3fb7c 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/AutoModeration/IModifyAutoModerationRulePayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/AutoModeration/IModifyAutoModerationRulePayload.cs @@ -3,6 +3,7 @@ // file, You can obtain one at https://mozilla.org/MPL/2.0/. using System.Collections.Generic; + using DSharpPlus.Entities; using DSharpPlus.Internal.Abstractions.Models; diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Channels/ICreateChannelInvitePayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Channels/ICreateChannelInvitePayload.cs index 4ffd09452e..27eb370112 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Channels/ICreateChannelInvitePayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Channels/ICreateChannelInvitePayload.cs @@ -37,8 +37,8 @@ public interface ICreateChannelInvitePayload public Optional TargetType { get; init; } /// - /// Snowflake identifier of the invite's target user if is - /// . + /// Snowflake identifier of the invite's target user if is + /// . /// public Optional TargetUserId { get; init; } diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Channels/ICreateMessagePayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Channels/ICreateMessagePayload.cs index 20a2738d9c..69956149fa 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Channels/ICreateMessagePayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Channels/ICreateMessagePayload.cs @@ -70,7 +70,7 @@ public interface ICreateMessagePayload public Optional Flags { get; } /// - /// If this is set to true and a is present, it will be checked for uniqueness in the past few + /// If this is set to true and a is present, it will be checked for uniqueness in the past few /// minutes. If another message was created by this user with the same nonce, that message will be returned and no new /// message will be created. /// diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Channels/IEditMessagePayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Channels/IEditMessagePayload.cs index 5c07092186..69db0bdf54 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Channels/IEditMessagePayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Channels/IEditMessagePayload.cs @@ -3,6 +3,7 @@ // file, You can obtain one at https://mozilla.org/MPL/2.0/. using System.Collections.Generic; + using DSharpPlus.Entities; using DSharpPlus.Internal.Abstractions.Models; diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Channels/IForumAndMediaThreadMessage.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Channels/IForumAndMediaThreadMessage.cs index d64915fb80..e9086915df 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Channels/IForumAndMediaThreadMessage.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Channels/IForumAndMediaThreadMessage.cs @@ -3,6 +3,7 @@ // file, You can obtain one at https://mozilla.org/MPL/2.0/. using System.Collections.Generic; + using DSharpPlus.Entities; using DSharpPlus.Internal.Abstractions.Models; diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Channels/IModifyGuildChannelPayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Channels/IModifyGuildChannelPayload.cs index 83af0664af..69a1775232 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Channels/IModifyGuildChannelPayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Channels/IModifyGuildChannelPayload.cs @@ -3,6 +3,7 @@ // file, You can obtain one at https://mozilla.org/MPL/2.0/. using System.Collections.Generic; + using DSharpPlus.Entities; using DSharpPlus.Internal.Abstractions.Models; @@ -19,8 +20,8 @@ public interface IModifyGuildChannelPayload public Optional Name { get; } /// - /// The new channel type for this channel. Only converting between and - /// is supported. + /// The new channel type for this channel. Only converting between and + /// is supported. /// public Optional Type { get; } @@ -80,8 +81,8 @@ public interface IModifyGuildChannelPayload public Optional DefaultAutoArchiveDuration { get; } /// - /// The new channel flags. Currently only and - /// are supported. + /// The new channel flags. Currently only and + /// are supported. /// public Optional Flags { get; } diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Guilds/ICreateGuildChannelPayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Guilds/ICreateGuildChannelPayload.cs index f8ec7e4cd6..d93bc64b1c 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Guilds/ICreateGuildChannelPayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Guilds/ICreateGuildChannelPayload.cs @@ -3,6 +3,7 @@ // file, You can obtain one at https://mozilla.org/MPL/2.0/. using System.Collections.Generic; + using DSharpPlus.Entities; using DSharpPlus.Internal.Abstractions.Models; diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Guilds/ICreateGuildPayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Guilds/ICreateGuildPayload.cs index 2cd1ec27b1..7166848e80 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Guilds/ICreateGuildPayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Guilds/ICreateGuildPayload.cs @@ -3,6 +3,7 @@ // file, You can obtain one at https://mozilla.org/MPL/2.0/. using System.Collections.Generic; + using DSharpPlus.Entities; using DSharpPlus.Internal.Abstractions.Models; @@ -44,8 +45,8 @@ public interface ICreateGuildPayload /// /// ICreateGuildPayload.Roles[0] is used to configure the @everyone role. If you are trying /// to bootstrap a guild with additional roles, you can set this first role to a placeholder.
- /// The field is a placeholder to allow you to reference the role - /// elsewhere, namely when passing in default channels to and specifying + /// The field is a placeholder to allow you to reference the role + /// elsewhere, namely when passing in default channels to and specifying /// overwrites for them. ///
public Optional> Roles { get; } @@ -54,15 +55,15 @@ public interface ICreateGuildPayload /// The channels to create this guild with. If this is set, none of the default channels will be created. /// /// - /// The field is ignored.
- /// The field is a placeholder to allow creating category channels by - /// setting the field to the parents' ID. Category channels must + /// The field is ignored.
+ /// The field is a placeholder to allow creating category channels by + /// setting the field to the parents' ID. Category channels must /// be listed before any of their children. The ID also serves for other fields to reference channels. ///
public Optional> Channels { get; } /// - /// The identifier of the AFK voice channel, referring to a placeholder ID in . + /// The identifier of the AFK voice channel, referring to a placeholder ID in . /// public Optional AfkChannelId { get; } @@ -73,7 +74,7 @@ public interface ICreateGuildPayload /// /// The identifier of the system channel where guild notices such as welcome messages are posted, referring - /// to a placeholder ID in . + /// to a placeholder ID in . /// public Optional SystemChannelId { get; } diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Guilds/IModifyGuildOnboardingPayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Guilds/IModifyGuildOnboardingPayload.cs index bd71569ab3..a3e5ab6228 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Guilds/IModifyGuildOnboardingPayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Guilds/IModifyGuildOnboardingPayload.cs @@ -3,6 +3,7 @@ // file, You can obtain one at https://mozilla.org/MPL/2.0/. using System.Collections.Generic; + using DSharpPlus.Entities; using DSharpPlus.Internal.Abstractions.Models; diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Interactions/ICreateFollowupMessagePayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Interactions/ICreateFollowupMessagePayload.cs index a4783bb1ec..577cfcaf2c 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Interactions/ICreateFollowupMessagePayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Interactions/ICreateFollowupMessagePayload.cs @@ -13,7 +13,7 @@ namespace DSharpPlus.Internal.Abstractions.Rest.Payloads; /// Represents a payload to POST /webhooks/:application-id/:interaction-token. /// /// -/// Either , or must be set. +/// Either , or must be set. /// public interface ICreateFollowupMessagePayload { diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/ScheduledEvents/ICreateGuildScheduledEventPayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/ScheduledEvents/ICreateGuildScheduledEventPayload.cs index 54b90cb383..64c3ae654d 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/ScheduledEvents/ICreateGuildScheduledEventPayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/ScheduledEvents/ICreateGuildScheduledEventPayload.cs @@ -3,6 +3,7 @@ // file, You can obtain one at https://mozilla.org/MPL/2.0/. using System; + using DSharpPlus.Entities; using DSharpPlus.Internal.Abstractions.Models; diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/ScheduledEvents/IModifyGuildScheduledEventPayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/ScheduledEvents/IModifyGuildScheduledEventPayload.cs index cf48331e03..2177aef84a 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/ScheduledEvents/IModifyGuildScheduledEventPayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/ScheduledEvents/IModifyGuildScheduledEventPayload.cs @@ -3,6 +3,7 @@ // file, You can obtain one at https://mozilla.org/MPL/2.0/. using System; + using DSharpPlus.Entities; using DSharpPlus.Internal.Abstractions.Models; diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Channels/GetChannelMessagesQuery.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Channels/GetChannelMessagesQuery.cs index c9b9fdb4bf..4d832e9ca8 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Channels/GetChannelMessagesQuery.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Channels/GetChannelMessagesQuery.cs @@ -13,19 +13,19 @@ namespace DSharpPlus.Internal.Abstractions.Rest.Queries; /// If specified, request entities around this ID. /// /// - /// Mutually exclusive with and . + /// Mutually exclusive with and . /// public Snowflake? Around { get; init; } /// /// - /// Mutually exclusive with and . + /// Mutually exclusive with and . /// public Snowflake? Before { get; init; } /// /// - /// Mutually exclusive with and . + /// Mutually exclusive with and . /// public Snowflake? After { get; init; } diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/RetryMode.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/RetryMode.cs index 7048e2d573..77c29b25a6 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/RetryMode.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/RetryMode.cs @@ -18,7 +18,7 @@ public enum RetryMode None = 0, /// - /// Suppresses executing a configured . + /// Suppresses executing a configured . /// SuppressCallback = 1 << 1, diff --git a/src/core/DSharpPlus.Internal.Models/Extensions/ServiceCollectionExtensions.cs b/src/core/DSharpPlus.Internal.Models/Extensions/ServiceCollectionExtensions.cs index 91f2a296c4..360d4bc4ee 100644 --- a/src/core/DSharpPlus.Internal.Models/Extensions/ServiceCollectionExtensions.cs +++ b/src/core/DSharpPlus.Internal.Models/Extensions/ServiceCollectionExtensions.cs @@ -2,6 +2,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +#pragma warning disable IDE0058 + using System.Text.Json; using DSharpPlus.Internal.Abstractions.Models; diff --git a/src/core/DSharpPlus.Internal.Models/Serialization/Converters/ApplicationIntegrationTypeKeyConverter.cs b/src/core/DSharpPlus.Internal.Models/Serialization/Converters/ApplicationIntegrationTypeKeyConverter.cs index eb22052b99..1883d0acf9 100644 --- a/src/core/DSharpPlus.Internal.Models/Serialization/Converters/ApplicationIntegrationTypeKeyConverter.cs +++ b/src/core/DSharpPlus.Internal.Models/Serialization/Converters/ApplicationIntegrationTypeKeyConverter.cs @@ -2,8 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -#pragma warning disable IDE0046 - using System; using System.Diagnostics.CodeAnalysis; using System.Globalization; @@ -15,7 +13,7 @@ namespace DSharpPlus.Internal.Models.Serialization.Converters; /// -/// Enables to be used as a dictionary key. +/// Enables to be used as a dictionary key. /// public class ApplicationIntegrationTypeKeyConverter : JsonConverter { diff --git a/src/core/DSharpPlus.Internal.Models/Serialization/Converters/AuditLogChangeConverter.cs b/src/core/DSharpPlus.Internal.Models/Serialization/Converters/AuditLogChangeConverter.cs index 82f32e488f..be30f56c56 100644 --- a/src/core/DSharpPlus.Internal.Models/Serialization/Converters/AuditLogChangeConverter.cs +++ b/src/core/DSharpPlus.Internal.Models/Serialization/Converters/AuditLogChangeConverter.cs @@ -11,7 +11,7 @@ namespace DSharpPlus.Internal.Models.Serialization.Converters; /// -/// Provides conversion for s. +/// Provides conversion for s. /// public class AuditLogChangeConverter : JsonConverter { diff --git a/src/core/DSharpPlus.Internal.Models/Serialization/Converters/AutoModerationActionConverter.cs b/src/core/DSharpPlus.Internal.Models/Serialization/Converters/AutoModerationActionConverter.cs index 1db1e5dda6..af764c4c24 100644 --- a/src/core/DSharpPlus.Internal.Models/Serialization/Converters/AutoModerationActionConverter.cs +++ b/src/core/DSharpPlus.Internal.Models/Serialization/Converters/AutoModerationActionConverter.cs @@ -5,13 +5,14 @@ using System; using System.Text.Json; using System.Text.Json.Serialization; + using DSharpPlus.Entities; using DSharpPlus.Internal.Abstractions.Models; namespace DSharpPlus.Internal.Models.Serialization.Converters; /// -/// Provides conversion for . +/// Provides conversion for . /// public class AutoModerationActionConverter : JsonConverter { @@ -93,6 +94,9 @@ JsonSerializerOptions options case ITimeoutActionMetadata timeout: JsonSerializer.Serialize(writer, timeout, options); break; + + default: + break; } writer.WriteEndObject(); diff --git a/src/core/DSharpPlus.Internal.Models/Serialization/Converters/MessageComponentConverter.cs b/src/core/DSharpPlus.Internal.Models/Serialization/Converters/MessageComponentConverter.cs index af889092b1..7bf4ef9a03 100644 --- a/src/core/DSharpPlus.Internal.Models/Serialization/Converters/MessageComponentConverter.cs +++ b/src/core/DSharpPlus.Internal.Models/Serialization/Converters/MessageComponentConverter.cs @@ -5,6 +5,7 @@ using System; using System.Text.Json; using System.Text.Json.Serialization; + using DSharpPlus.Entities; using DSharpPlus.Internal.Abstractions.Models; diff --git a/src/core/DSharpPlus.Internal.Models/Serialization/Converters/NullBooleanConverter.cs b/src/core/DSharpPlus.Internal.Models/Serialization/Converters/NullBooleanConverter.cs index fe7c0daf64..90bc4efb6c 100644 --- a/src/core/DSharpPlus.Internal.Models/Serialization/Converters/NullBooleanConverter.cs +++ b/src/core/DSharpPlus.Internal.Models/Serialization/Converters/NullBooleanConverter.cs @@ -10,7 +10,7 @@ namespace DSharpPlus.Internal.Models.Serialization.Converters; /// /// Provides serialization for discord's optional null booleans, see -/// . +/// . /// /// /// This needs to be applied to every null boolean property individually. diff --git a/src/core/DSharpPlus.Internal.Models/Serialization/Converters/OptionalConverter.cs b/src/core/DSharpPlus.Internal.Models/Serialization/Converters/OptionalConverter.cs index 5e66eefd8d..2f001c4cf1 100644 --- a/src/core/DSharpPlus.Internal.Models/Serialization/Converters/OptionalConverter.cs +++ b/src/core/DSharpPlus.Internal.Models/Serialization/Converters/OptionalConverter.cs @@ -9,7 +9,7 @@ namespace DSharpPlus.Internal.Models.Serialization.Converters; /// -/// A converter for . +/// A converter for . /// public sealed class OptionalConverter : JsonConverter> { diff --git a/src/core/DSharpPlus.Internal.Models/Serialization/Converters/OptionalConverterFactory.cs b/src/core/DSharpPlus.Internal.Models/Serialization/Converters/OptionalConverterFactory.cs index a4d73f781d..f0210b12a8 100644 --- a/src/core/DSharpPlus.Internal.Models/Serialization/Converters/OptionalConverterFactory.cs +++ b/src/core/DSharpPlus.Internal.Models/Serialization/Converters/OptionalConverterFactory.cs @@ -9,7 +9,7 @@ namespace DSharpPlus.Internal.Models.Serialization.Converters; /// -/// A converter factory for . +/// A converter factory for . /// public class OptionalConverterFactory : JsonConverterFactory { diff --git a/src/core/DSharpPlus.Internal.Models/Serialization/Converters/SnowflakeConverter.cs b/src/core/DSharpPlus.Internal.Models/Serialization/Converters/SnowflakeConverter.cs index ea4bcb8711..fc4988dbd4 100644 --- a/src/core/DSharpPlus.Internal.Models/Serialization/Converters/SnowflakeConverter.cs +++ b/src/core/DSharpPlus.Internal.Models/Serialization/Converters/SnowflakeConverter.cs @@ -2,6 +2,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +#pragma warning disable IDE0072 + using System; using System.Globalization; using System.Text.Json; diff --git a/src/core/DSharpPlus.Internal.Models/Serialization/Resolvers/OptionalTypeInfoResolver.cs b/src/core/DSharpPlus.Internal.Models/Serialization/Resolvers/OptionalTypeInfoResolver.cs index 5a6f76c134..1f9b4665fe 100644 --- a/src/core/DSharpPlus.Internal.Models/Serialization/Resolvers/OptionalTypeInfoResolver.cs +++ b/src/core/DSharpPlus.Internal.Models/Serialization/Resolvers/OptionalTypeInfoResolver.cs @@ -10,7 +10,7 @@ namespace DSharpPlus.Internal.Models.Serialization.Resolvers; /// -/// Provides a mechanism for resolving serialization of . +/// Provides a mechanism for resolving serialization of . /// public static class OptionalTypeInfoResolver { diff --git a/src/core/DSharpPlus.Internal.Rest/API/StageInstanceRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/StageInstanceRestAPI.cs index 34ec5d34bf..c0a526db2d 100644 --- a/src/core/DSharpPlus.Internal.Rest/API/StageInstanceRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Rest/API/StageInstanceRestAPI.cs @@ -7,6 +7,7 @@ using System.Net.Http; using System.Threading; using System.Threading.Tasks; + using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Internal.Abstractions.Rest; using DSharpPlus.Internal.Abstractions.Rest.API; diff --git a/src/core/DSharpPlus.Internal.Rest/Ratelimiting/IRatelimitRegistry.cs b/src/core/DSharpPlus.Internal.Rest/Ratelimiting/IRatelimitRegistry.cs index d977ab64a4..ea5d8b36b7 100644 --- a/src/core/DSharpPlus.Internal.Rest/Ratelimiting/IRatelimitRegistry.cs +++ b/src/core/DSharpPlus.Internal.Rest/Ratelimiting/IRatelimitRegistry.cs @@ -16,7 +16,7 @@ public interface IRatelimitRegistry { /// /// Checks whether this request should be allowed to proceed. This should be considering as enqueuing a request - /// as far as is concerned. + /// as far as is concerned. /// public Result CheckRatelimit(HttpRequestMessage request); @@ -26,7 +26,7 @@ public interface IRatelimitRegistry public Result UpdateRatelimit(HttpRequestMessage request, HttpResponseMessage response); /// - /// Cancels a request reservation made in . + /// Cancels a request reservation made in . /// public Result CancelRequest(HttpRequestMessage request); } diff --git a/src/core/DSharpPlus.Internal.Rest/Ratelimiting/RatelimitBucket.cs b/src/core/DSharpPlus.Internal.Rest/Ratelimiting/RatelimitBucket.cs index eada2078fa..e580009fa5 100644 --- a/src/core/DSharpPlus.Internal.Rest/Ratelimiting/RatelimitBucket.cs +++ b/src/core/DSharpPlus.Internal.Rest/Ratelimiting/RatelimitBucket.cs @@ -26,10 +26,10 @@ internal sealed class RatelimitBucket public void UpdateFromResponse(float expiry, int limit, int remaining) { - Interlocked.Exchange(ref this.expiry, expiry); - Interlocked.Exchange(ref this.limit, limit); - Interlocked.Exchange(ref this.remaining, remaining); - Interlocked.Decrement(ref this.reserved); + _ = Interlocked.Exchange(ref this.expiry, expiry); + _ = Interlocked.Exchange(ref this.limit, limit); + _ = Interlocked.Exchange(ref this.remaining, remaining); + _ = Interlocked.Decrement(ref this.reserved); } public void Reserve() => Interlocked.Increment(ref this.reserved); diff --git a/src/core/DSharpPlus.Internal.Rest/Ratelimiting/RatelimitRegistry.cs b/src/core/DSharpPlus.Internal.Rest/Ratelimiting/RatelimitRegistry.cs index 04a12a12ca..ad5294a046 100644 --- a/src/core/DSharpPlus.Internal.Rest/Ratelimiting/RatelimitRegistry.cs +++ b/src/core/DSharpPlus.Internal.Rest/Ratelimiting/RatelimitRegistry.cs @@ -92,7 +92,7 @@ private async ValueTask CleanupSimpleRatelimitsAsync(int interval, CancellationT { if (currentTime > pair.Value + this.timeReferencePoint) { - this.webhook429s.Remove(pair.Key, out _); + _ = this.webhook429s.Remove(pair.Key, out _); } } @@ -103,7 +103,7 @@ private async ValueTask CleanupSimpleRatelimitsAsync(int interval, CancellationT { if (currentTime > pair.Value + this.timeReferencePoint) { - this.route429s.Remove(pair.Key, out _); + _ = this.route429s.Remove(pair.Key, out _); } } @@ -121,7 +121,7 @@ private async ValueTask CleanupSimpleRatelimitsAsync(int interval, CancellationT if (currentTime > bucket.Expiry + this.timeReferencePoint) { // since we use a CWT, the bucket will automatically die once all routes holding on to it are dead - this.hashes.Remove(pair.Key, out _); + _ = this.hashes.Remove(pair.Key, out _); } } } diff --git a/src/core/DSharpPlus.Internal.Rest/RequestBuilderExtensions.cs b/src/core/DSharpPlus.Internal.Rest/RequestBuilderExtensions.cs index 72f1132eb3..1cac07378b 100644 --- a/src/core/DSharpPlus.Internal.Rest/RequestBuilderExtensions.cs +++ b/src/core/DSharpPlus.Internal.Rest/RequestBuilderExtensions.cs @@ -2,6 +2,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +#pragma warning disable IDE0058 + using DSharpPlus.Internal.Abstractions.Rest; using DSharpPlus.Internal.Rest.Ratelimiting; diff --git a/src/core/DSharpPlus.Shared/AttachmentData.cs b/src/core/DSharpPlus.Shared/AttachmentData.cs index 93a2cd87e9..1e2bd20d54 100644 --- a/src/core/DSharpPlus.Shared/AttachmentData.cs +++ b/src/core/DSharpPlus.Shared/AttachmentData.cs @@ -21,7 +21,7 @@ public readonly record struct AttachmentData /// /// The media type of this attachment. Defaults to empty, in which case it will be interpreted according to - /// the file extension as provided by . + /// the file extension as provided by . /// public string? MediaType { get; init; } @@ -151,14 +151,20 @@ void ProcessResult(ReadResult result, PipeReader reader) { if (sequence.Remaining + readRollover >= readSegmentLength) { - sequence.TryCopyTo(readSpan[readRollover..]); + if (!sequence.TryCopyTo(readSpan[readRollover..])) + { + Trace.Assert(false); + } sequence.Advance(readSegmentLength - readRollover); readRollover = 0; } else { - sequence.TryCopyTo(readSpan.Slice(readRollover, (int)sequence.Remaining)); + if (!sequence.TryCopyTo(readSpan.Slice(readRollover, (int)sequence.Remaining))) + { + Trace.Assert(false); + } readRollover += (int)sequence.Remaining; sequence.Advance((int)sequence.Remaining); @@ -167,13 +173,19 @@ void ProcessResult(ReadResult result, PipeReader reader) } else if (sequence.Remaining >= readSegmentLength) { - sequence.TryCopyTo(readSpan); + if (!sequence.TryCopyTo(readSpan)) + { + Trace.Assert(false); + } sequence.Advance(readSegmentLength); } else { - sequence.TryCopyTo(readSpan[..(int)sequence.Remaining]); + if (!sequence.TryCopyTo(readSpan[..(int)sequence.Remaining])) + { + Trace.Assert(false); + } readRollover += (int)sequence.Remaining; sequence.AdvanceToEnd(); diff --git a/src/core/DSharpPlus.Shared/Entities/Applications/DiscordApplicationFlags.cs b/src/core/DSharpPlus.Shared/Entities/Applications/DiscordApplicationFlags.cs index 351f5eaa4f..df89c38895 100644 --- a/src/core/DSharpPlus.Shared/Entities/Applications/DiscordApplicationFlags.cs +++ b/src/core/DSharpPlus.Shared/Entities/Applications/DiscordApplicationFlags.cs @@ -24,7 +24,7 @@ public enum DiscordApplicationFlags /// /// The intent required for bots in less than 100 servers to receive presence update events. - /// Unlike , this does not require staff approval. + /// Unlike , this does not require staff approval. /// GatewayPresenceLimited = 1 << 13, @@ -35,7 +35,7 @@ public enum DiscordApplicationFlags /// /// The intent required for bots in less than 100 servers to receive guild member related events. - /// Unlike , this does not require staff approval. + /// Unlike , this does not require staff approval. /// GatewayGuildMembersLimited = 1 << 15, @@ -56,7 +56,7 @@ public enum DiscordApplicationFlags /// /// The intent required for bots in less than 100 servers to receive message content. - /// Unlike , this does not require staff approval. + /// Unlike , this does not require staff approval. /// GatewayMessageContentLimited = 1 << 19, diff --git a/src/core/DSharpPlus.Shared/Entities/AutoModeration/DiscordAutoModerationActionType.cs b/src/core/DSharpPlus.Shared/Entities/AutoModeration/DiscordAutoModerationActionType.cs index ce85376e7a..2272736912 100644 --- a/src/core/DSharpPlus.Shared/Entities/AutoModeration/DiscordAutoModerationActionType.cs +++ b/src/core/DSharpPlus.Shared/Entities/AutoModeration/DiscordAutoModerationActionType.cs @@ -22,8 +22,8 @@ public enum DiscordAutoModerationActionType /// /// Causes an user to be timed out for a specified duration. This can only be applied to rules of types - /// and - /// . + /// and + /// . /// Timeout } diff --git a/src/core/DSharpPlus.Shared/Entities/AutoModeration/DiscordAutoModerationPresetType.cs b/src/core/DSharpPlus.Shared/Entities/AutoModeration/DiscordAutoModerationPresetType.cs index 018e0a6ce0..abc0b11200 100644 --- a/src/core/DSharpPlus.Shared/Entities/AutoModeration/DiscordAutoModerationPresetType.cs +++ b/src/core/DSharpPlus.Shared/Entities/AutoModeration/DiscordAutoModerationPresetType.cs @@ -6,7 +6,7 @@ namespace DSharpPlus.Entities; /// /// Specifies the internal keyword presets for auto-moderation rules of type -/// . +/// . /// public enum DiscordAutoModerationPresetType { diff --git a/src/core/DSharpPlus.Shared/Entities/Channels/DiscordChannelType.cs b/src/core/DSharpPlus.Shared/Entities/Channels/DiscordChannelType.cs index 8e34b5b851..d4ee64bdbd 100644 --- a/src/core/DSharpPlus.Shared/Entities/Channels/DiscordChannelType.cs +++ b/src/core/DSharpPlus.Shared/Entities/Channels/DiscordChannelType.cs @@ -70,7 +70,7 @@ public enum DiscordChannelType GuildForum, /// - /// A channel that can only contain threads, similar to . + /// A channel that can only contain threads, similar to . /// GuildMedia } diff --git a/src/core/DSharpPlus.Shared/Entities/Interactions/DiscordInteractionCallbackType.cs b/src/core/DSharpPlus.Shared/Entities/Interactions/DiscordInteractionCallbackType.cs index f21bd55dd9..70e1af63df 100644 --- a/src/core/DSharpPlus.Shared/Entities/Interactions/DiscordInteractionCallbackType.cs +++ b/src/core/DSharpPlus.Shared/Entities/Interactions/DiscordInteractionCallbackType.cs @@ -10,7 +10,7 @@ namespace DSharpPlus.Entities; public enum DiscordInteractionCallbackType { /// - /// Acknowledges a . + /// Acknowledges a . /// Pong = 1, diff --git a/src/core/DSharpPlus.Shared/Entities/ScheduledEvents/DiscordScheduledEventStatus.cs b/src/core/DSharpPlus.Shared/Entities/ScheduledEvents/DiscordScheduledEventStatus.cs index c78519dd85..da88644692 100644 --- a/src/core/DSharpPlus.Shared/Entities/ScheduledEvents/DiscordScheduledEventStatus.cs +++ b/src/core/DSharpPlus.Shared/Entities/ScheduledEvents/DiscordScheduledEventStatus.cs @@ -8,7 +8,7 @@ namespace DSharpPlus.Entities; /// Specifies the valid states of a scheduled event. /// /// -/// Once the status is set to or , it can no longer +/// Once the status is set to or , it can no longer /// be updated. /// public enum DiscordScheduledEventStatus diff --git a/src/core/DSharpPlus.Shared/ImageData.cs b/src/core/DSharpPlus.Shared/ImageData.cs index 8f427a376c..fdef065941 100644 --- a/src/core/DSharpPlus.Shared/ImageData.cs +++ b/src/core/DSharpPlus.Shared/ImageData.cs @@ -2,6 +2,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +#pragma warning disable IDE0072 + using System; using System.Buffers; using System.Buffers.Text; diff --git a/src/core/DSharpPlus.Shared/ImageFormat.cs b/src/core/DSharpPlus.Shared/ImageFormat.cs index 48fb4be319..437fb5f9d7 100644 --- a/src/core/DSharpPlus.Shared/ImageFormat.cs +++ b/src/core/DSharpPlus.Shared/ImageFormat.cs @@ -5,7 +5,7 @@ namespace DSharpPlus; /// -/// Represents formats recognized and handled by . +/// Represents formats recognized and handled by . /// public enum ImageFormat { diff --git a/src/core/DSharpPlus.Shared/Results/Errors/ArgumentError.cs b/src/core/DSharpPlus.Shared/Results/Errors/ArgumentError.cs index e7a4e9cc95..0c17002245 100644 --- a/src/core/DSharpPlus.Shared/Results/Errors/ArgumentError.cs +++ b/src/core/DSharpPlus.Shared/Results/Errors/ArgumentError.cs @@ -17,19 +17,19 @@ public record ArgumentError : ExceptionError public string ArgumentName { get; private protected set; } /// - /// Creates a new with the specified message and an unspecified argument name. + /// Creates a new with the specified message and an unspecified argument name. /// public ArgumentError(string message) : base(message) => this.ArgumentName = "Unspecified."; /// - /// Creates a new with the specified message and argument name. + /// Creates a new with the specified message and argument name. /// public ArgumentError(string message, string argumentName) : base(message) => this.ArgumentName = argumentName; /// - /// Creates a new from the specified exception. + /// Creates a new from the specified exception. /// public ArgumentError(Exception exception) : base(exception) { diff --git a/src/core/DSharpPlus.Shared/Results/Errors/ArgumentNullError.cs b/src/core/DSharpPlus.Shared/Results/Errors/ArgumentNullError.cs index d6f8021d5c..aae42f9982 100644 --- a/src/core/DSharpPlus.Shared/Results/Errors/ArgumentNullError.cs +++ b/src/core/DSharpPlus.Shared/Results/Errors/ArgumentNullError.cs @@ -12,7 +12,7 @@ namespace DSharpPlus.Results.Errors; public record ArgumentNullError : ArgumentError { /// - /// Creates a new with the default message and specified argument name. + /// Creates a new with the default message and specified argument name. /// public ArgumentNullError(string argumentName) : base("The provided value must not be null", argumentName) { @@ -20,7 +20,7 @@ public ArgumentNullError(string argumentName) : base("The provided value must no } /// - /// Creates a new with the specified message and argument name. + /// Creates a new with the specified message and argument name. /// public ArgumentNullError(string message, string argumentName) : base(message, argumentName) { @@ -28,7 +28,7 @@ public ArgumentNullError(string message, string argumentName) : base(message, ar } /// - /// Creates a new from the specified exception. + /// Creates a new from the specified exception. /// public ArgumentNullError(Exception exception) : base(exception) { diff --git a/src/core/DSharpPlus.Shared/Results/Errors/ArgumentOutOfRangeError.cs b/src/core/DSharpPlus.Shared/Results/Errors/ArgumentOutOfRangeError.cs index 52f2c7e572..6cfcc51123 100644 --- a/src/core/DSharpPlus.Shared/Results/Errors/ArgumentOutOfRangeError.cs +++ b/src/core/DSharpPlus.Shared/Results/Errors/ArgumentOutOfRangeError.cs @@ -12,7 +12,7 @@ namespace DSharpPlus.Results.Errors; public record ArgumentOutOfRangeError : ArgumentError { /// - /// Creates a new with the specified message and an unspecified argument name. + /// Creates a new with the specified message and an unspecified argument name. /// public ArgumentOutOfRangeError(string message) : base(message) { @@ -20,7 +20,7 @@ public ArgumentOutOfRangeError(string message) : base(message) } /// - /// Creates a new with the specified message and argument name. + /// Creates a new with the specified message and argument name. /// public ArgumentOutOfRangeError(string message, string argumentName) : base(message, argumentName) { @@ -28,7 +28,7 @@ public ArgumentOutOfRangeError(string message, string argumentName) : base(messa } /// - /// Creates a new from the specified exception. + /// Creates a new from the specified exception. /// public ArgumentOutOfRangeError(Exception exception) : base(exception) { diff --git a/src/core/DSharpPlus.Shared/Results/Errors/InvalidOperationError.cs b/src/core/DSharpPlus.Shared/Results/Errors/InvalidOperationError.cs index a4a97ca196..e101a34d5f 100644 --- a/src/core/DSharpPlus.Shared/Results/Errors/InvalidOperationError.cs +++ b/src/core/DSharpPlus.Shared/Results/Errors/InvalidOperationError.cs @@ -12,14 +12,14 @@ namespace DSharpPlus.Results.Errors; public record InvalidOperationError : ExceptionError { /// - /// Creates a new with the specified message. + /// Creates a new with the specified message. /// public InvalidOperationError(string message) : base(message) { } /// - /// Creates a new from the specified exception. + /// Creates a new from the specified exception. /// public InvalidOperationError(Exception exception) : base(exception) => this.Message = exception.Message; diff --git a/src/core/DSharpPlus.Shared/Results/ExceptionServices/MarshalException.cs b/src/core/DSharpPlus.Shared/Results/ExceptionServices/MarshalException.cs index a50bb49f95..c4e8d6cd38 100644 --- a/src/core/DSharpPlus.Shared/Results/ExceptionServices/MarshalException.cs +++ b/src/core/DSharpPlus.Shared/Results/ExceptionServices/MarshalException.cs @@ -11,14 +11,12 @@ namespace DSharpPlus.Results.ExceptionServices; -public sealed class MarshalException : Exception +[method: SetsRequiredMembers] +public sealed class MarshalException(Error underlying) + : Exception("Failed to find a matching exception type for this result error.") { /// /// Gets the result error this was originally /// - public required Error Error { get; init; } - - [SetsRequiredMembers] - public MarshalException(Error underlying) : base("Failed to find a matching exception type for this result error.") - => this.Error = underlying; + public required Error Error { get; init; } = underlying; } diff --git a/src/core/DSharpPlus.Shared/Results/Result`1.cs b/src/core/DSharpPlus.Shared/Results/Result`1.cs index 7e41233eb1..59c4df0caa 100644 --- a/src/core/DSharpPlus.Shared/Results/Result`1.cs +++ b/src/core/DSharpPlus.Shared/Results/Result`1.cs @@ -5,6 +5,7 @@ using System; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; + using DSharpPlus.Results.Errors; using DSharpPlus.Results.ExceptionServices; diff --git a/src/extensions/DSharpPlus.Extensions.Internal.Builders/Errors/BuilderValidationError.cs b/src/extensions/DSharpPlus.Extensions.Internal.Builders/Errors/BuilderValidationError.cs index 1d8e95b550..f35c4ac2aa 100644 --- a/src/extensions/DSharpPlus.Extensions.Internal.Builders/Errors/BuilderValidationError.cs +++ b/src/extensions/DSharpPlus.Extensions.Internal.Builders/Errors/BuilderValidationError.cs @@ -48,10 +48,10 @@ public override string ToString() foreach (KeyValuePair kvp in this.ParameterNames) { - builder.Append(CultureInfo.InvariantCulture, $"\n\t\t{kvp.Key}: {kvp.Value}"); + _ = builder.Append(CultureInfo.InvariantCulture, $"\n\t\t{kvp.Key}: {kvp.Value}"); } - builder.Append("\n\t]\n}"); + _ = builder.Append("\n\t]\n}"); return builder.ToString(); } diff --git a/src/extensions/DSharpPlus.Extensions.Internal.Builders/Interactions/ModalBuilder.cs b/src/extensions/DSharpPlus.Extensions.Internal.Builders/Interactions/ModalBuilder.cs index 143f1e0332..1922db8a74 100644 --- a/src/extensions/DSharpPlus.Extensions.Internal.Builders/Interactions/ModalBuilder.cs +++ b/src/extensions/DSharpPlus.Extensions.Internal.Builders/Interactions/ModalBuilder.cs @@ -7,11 +7,13 @@ using System; using System.Collections.Generic; using System.Linq; + using DSharpPlus.Entities; using DSharpPlus.Extensions.Internal.Builders.Errors; using DSharpPlus.Extensions.Internal.Builders.Implementations; using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Results; + using OneOf; namespace DSharpPlus.Extensions.Internal.Builders.Interactions; diff --git a/src/extensions/DSharpPlus.Extensions.Internal.Builders/Interactions/TextInputComponentBuilder.cs b/src/extensions/DSharpPlus.Extensions.Internal.Builders/Interactions/TextInputComponentBuilder.cs index af460f5f2a..aa77917356 100644 --- a/src/extensions/DSharpPlus.Extensions.Internal.Builders/Interactions/TextInputComponentBuilder.cs +++ b/src/extensions/DSharpPlus.Extensions.Internal.Builders/Interactions/TextInputComponentBuilder.cs @@ -6,6 +6,7 @@ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using DSharpPlus.Entities; using DSharpPlus.Extensions.Internal.Builders.Errors; @@ -17,7 +18,7 @@ namespace DSharpPlus.Extensions.Internal.Builders.Interactions; /// -/// Represents a under construction. +/// Represents a under construction. /// public record struct TextInputComponentBuilder { @@ -227,10 +228,12 @@ public static Result Validate(ref this TextInputComponentBuilder builder) /// /// Builds the text input component. This does not enforce validity, past enforcing all fields are present. /// + [SuppressMessage("Usage", "CA2208", Justification = "We fully intend to pass builder.Style here.")] public static ITextInputComponent Build(ref this TextInputComponentBuilder builder) { ArgumentNullException.ThrowIfNull(builder.CustomId); ArgumentNullException.ThrowIfNull(builder.Label); + if (!builder.Style.HasValue) { throw new ArgumentNullException(nameof(builder.Style)); diff --git a/src/extensions/DSharpPlus.Extensions.Internal.Builders/Messages/EmbedBuilder.cs b/src/extensions/DSharpPlus.Extensions.Internal.Builders/Messages/EmbedBuilder.cs index b8cbe093c2..cc99bda35e 100644 --- a/src/extensions/DSharpPlus.Extensions.Internal.Builders/Messages/EmbedBuilder.cs +++ b/src/extensions/DSharpPlus.Extensions.Internal.Builders/Messages/EmbedBuilder.cs @@ -16,7 +16,7 @@ namespace DSharpPlus.Extensions.Internal.Builders.Messages; /// -/// Represents an currently under construction. +/// Represents an currently under construction. /// public record struct EmbedBuilder { diff --git a/tests/core/DSharpPlus.Internal.Models.Tests/Converters/AuditLogChangeTests.cs b/tests/core/DSharpPlus.Internal.Models.Tests/Converters/AuditLogChangeTests.cs index 64d8631036..47ca2d0e37 100644 --- a/tests/core/DSharpPlus.Internal.Models.Tests/Converters/AuditLogChangeTests.cs +++ b/tests/core/DSharpPlus.Internal.Models.Tests/Converters/AuditLogChangeTests.cs @@ -2,6 +2,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +#pragma warning disable IDE0058 + using System; using DSharpPlus.Internal.Abstractions.Models; diff --git a/tests/core/DSharpPlus.Internal.Models.Tests/Converters/OneOfConverterTests.Models.cs b/tests/core/DSharpPlus.Internal.Models.Tests/Converters/OneOfConverterTests.Models.cs index 6858d923cc..1e5de784f7 100644 --- a/tests/core/DSharpPlus.Internal.Models.Tests/Converters/OneOfConverterTests.Models.cs +++ b/tests/core/DSharpPlus.Internal.Models.Tests/Converters/OneOfConverterTests.Models.cs @@ -2,6 +2,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +#pragma warning disable IDE0058 + using System; using DSharpPlus.Internal.Abstractions.Models; From 3a07d8e0f9b1ab4aff94b88a203b80edbc9c7752 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Tue, 21 May 2024 18:59:50 +0200 Subject: [PATCH 296/323] update to the latest api docs --- .../Channels/IMessageCall.cs | 24 +++++++++++ .../Channels/IMessageInteractionMetadata.cs | 4 +- .../Channels/IPartialMessage.cs | 9 ++++- .../Entitlements/IPartialEntitlement.cs | 5 +++ .../Guilds/IPartialGuildMember.cs | 5 +++ .../Interactions/IInteraction.cs | 5 +++ .../Invites/IInvite.cs | 8 ++++ .../Invites/IPartialInvite.cs | 5 +++ .../Users/IAvatarDecorationData.cs | 21 ++++++++++ .../Users/IPartialUser.cs | 4 +- .../API/IChannelRestAPI.cs | 4 +- .../API/IEntitlementsRestAPI.cs | 17 ++++++++ .../Users/IModifyCurrentUserPayload.cs | 5 +++ .../Queries/Channels/GetReactionsQuery.cs | 23 +++++++++++ .../Queries/Channels/ReactionType.cs | 21 ++++++++++ .../ApplicationCommands/ApplicationCommand.cs | 2 +- .../ApplicationCommandOption.cs | 2 +- .../ApplicationCommandOptionChoice.cs | 2 +- .../AuditLogs/AuditLogChange.cs | 2 +- .../AuditLogs/AuditLogEntryInfo.cs | 2 +- .../AutoModerationTriggerMetadata.cs | 2 +- .../BlockMessageActionMetadata.cs | 2 +- .../SendAlertMessageActionMetadata.cs | 2 +- .../AutoModeration/TimeoutActionMetadata.cs | 2 +- .../Channels/AllowedMentions.cs | 2 +- .../Channels/Channel.cs | 2 +- .../Channels/DefaultReaction.cs | 2 +- .../Channels/ForumTag.cs | 2 +- .../Channels/Message.cs | 7 +++- .../Channels/MessageCall.cs | 20 ++++++++++ .../Channels/MessageInteractionMetadata.cs | 4 +- .../Channels/PartialChannel.cs | 2 +- .../Channels/PartialMessage.cs | 7 +++- .../Entitlements/Entitlement.cs | 5 ++- .../Entitlements/PartialEntitlement.cs | 5 ++- .../Guilds/Guild.cs | 2 +- .../Guilds/GuildMember.cs | 5 ++- .../Guilds/OnboardingPrompt.cs | 2 +- .../Guilds/PartialGuild.cs | 2 +- .../Guilds/PartialGuildMember.cs | 5 ++- .../Interactions/Interaction.cs | 5 ++- .../Interactions/ResolvedData.cs | 2 +- .../Invites/Invite.cs | 5 ++- .../Invites/PartialInvite.cs | 5 ++- .../MessageComponents/ActionRowComponent.cs | 2 +- .../MessageComponents/ButtonComponent.cs | 2 +- .../ChannelSelectComponent.cs | 2 +- .../MessageComponents/DefaultSelectValue.cs | 2 +- .../MentionableSelectComponent.cs | 2 +- .../MessageComponents/RoleSelectComponent.cs | 2 +- .../MessageComponents/SelectOption.cs | 2 +- .../MessageComponents/UserSelectComponent.cs | 2 +- .../Polls/PollAnswerCount.cs | 2 +- .../Polls/PollMedia.cs | 2 +- .../Polls/PollResults.cs | 2 +- .../RoleConnections/RoleConnectionMetadata.cs | 2 +- .../ScheduledEvents/ScheduledEventUser.cs | 2 +- .../Teams/TeamMember.cs | 2 +- .../Users/AvatarDecorationData.cs | 17 ++++++++ .../Users/PartialUser.cs | 4 +- .../DSharpPlus.Internal.Models/Users/User.cs | 4 +- .../API/ChannelRestAPI.cs | 16 +++++++- .../API/EntitlementsRestAPI.cs | 18 +++++++++ .../CreateGlobalApplicationCommandPayload.cs | 2 +- .../CreateGuildApplicationCommandPayload.cs | 2 +- .../EditGlobalApplicationCommandPayload.cs | 2 +- .../EditGuildApplicationCommandPayload.cs | 2 +- .../EditCurrentApplicationPayload.cs | 2 +- .../CreateAutoModerationRulePayload.cs | 2 +- .../ModifyAutoModerationRulePayload.cs | 2 +- .../Channels/CreateChannelInvitePayload.cs | 2 +- .../Payloads/Channels/CreateMessagePayload.cs | 2 +- .../Payloads/Channels/EditMessagePayload.cs | 2 +- .../Channels/ForumAndMediaThreadMessage.cs | 2 +- .../Channels/ModifyGuildChannelPayload.cs | 2 +- .../Guilds/CreateGuildChannelPayload.cs | 2 +- .../Payloads/Guilds/CreateGuildPayload.cs | 2 +- .../Guilds/ModifyGuildOnboardingPayload.cs | 2 +- .../CreateFollowupMessagePayload.cs | 2 +- .../CreateGuildScheduledEventPayload.cs | 2 +- .../ModifyGuildScheduledEventPayload.cs | 2 +- .../Users/ModifyCurrentUserPayload.cs | 5 ++- .../Webhooks/ExecuteWebhookPayload.cs | 2 +- .../Entitlements/DiscordEntitlementType.cs | 40 ++++++++++++++++++- .../Entities/Invites/DiscordInviteType.cs | 26 ++++++++++++ .../Entities/Skus/DiscordSkuType.cs | 10 +++++ .../BuiltActionRowComponent.cs | 2 +- 87 files changed, 397 insertions(+), 80 deletions(-) create mode 100644 src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IMessageCall.cs create mode 100644 src/core/DSharpPlus.Internal.Abstractions.Models/Users/IAvatarDecorationData.cs create mode 100644 src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Channels/GetReactionsQuery.cs create mode 100644 src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Channels/ReactionType.cs create mode 100644 src/core/DSharpPlus.Internal.Models/Channels/MessageCall.cs create mode 100644 src/core/DSharpPlus.Internal.Models/Users/AvatarDecorationData.cs create mode 100644 src/core/DSharpPlus.Shared/Entities/Invites/DiscordInviteType.cs diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IMessageCall.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IMessageCall.cs new file mode 100644 index 0000000000..5f47337d1c --- /dev/null +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IMessageCall.cs @@ -0,0 +1,24 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; +using System.Collections.Generic; + +namespace DSharpPlus.Internal.Abstractions.Models; + +/// +/// Contains information about a call in a private channel. +/// +public interface IMessageCall +{ + /// + /// The snowflake IDs of participating users. + /// + public IReadOnlyList Participants { get; } + + /// + /// The timestamp at which the call ended. + /// + public Optional EndedTimestamp { get; } +} diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IMessageInteractionMetadata.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IMessageInteractionMetadata.cs index c5f1e30bf3..b887151512 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IMessageInteractionMetadata.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IMessageInteractionMetadata.cs @@ -24,9 +24,9 @@ public interface IMessageInteractionMetadata public DiscordInteractionType Type { get; } /// - /// The snowflake identifier of the user who triggered this interaction. + /// The user who triggered this interaction. /// - public Snowflake UserId { get; } + public IUser User { get; } /// /// The installation contexts related to this interaction. diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IPartialMessage.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IPartialMessage.cs index ee9c694041..b9742075d6 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IPartialMessage.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IPartialMessage.cs @@ -176,7 +176,12 @@ public interface IPartialMessage public Optional Resolved { get; } /// - /// A poll being created with this message. + /// A poll attached to this message. /// - public Optional Poll { get; } + public Optional Poll { get; } + + /// + /// A call associated with this message. + /// + public Optional Call { get; } } diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/Entitlements/IPartialEntitlement.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Entitlements/IPartialEntitlement.cs index c8f04de621..0f2517ccce 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Models/Entitlements/IPartialEntitlement.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Entitlements/IPartialEntitlement.cs @@ -57,4 +57,9 @@ public interface IPartialEntitlement /// The date at which this entitlement is no longer valid. Not present when using test entitlements. /// public Optional EndsAt { get; } + + /// + /// Indicates whether this entitlement has been consumed. + /// + public Optional Consumed { get; } } diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/Guilds/IPartialGuildMember.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Guilds/IPartialGuildMember.cs index 2cfacc507b..b60aa255ff 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Models/Guilds/IPartialGuildMember.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Guilds/IPartialGuildMember.cs @@ -75,4 +75,9 @@ public interface IPartialGuildMember /// The timestamp at which this user's timeout expires. /// public Optional CommunicationDisabledUntil { get; } + + /// + /// If present, contains data for the member's avatar decoration. + /// + public Optional AvatarDecorationData { get; } } diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/Interactions/IInteraction.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Interactions/IInteraction.cs index f7fe8a03fa..32243821a1 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Models/Interactions/IInteraction.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Interactions/IInteraction.cs @@ -40,6 +40,11 @@ public interface IInteraction /// public Optional> Data { get; } + /// + /// The guild this interaction was sent from. + /// + public Optional Guild { get; } + /// /// The snowflake identifier of the guild this interaction was sent from, if applicable. /// diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/Invites/IInvite.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Invites/IInvite.cs index bbeb77ee3e..439d1c846d 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Models/Invites/IInvite.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Invites/IInvite.cs @@ -2,6 +2,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +using DSharpPlus.Entities; + namespace DSharpPlus.Internal.Abstractions.Models; /// @@ -9,6 +11,9 @@ namespace DSharpPlus.Internal.Abstractions.Models; /// public interface IInvite : IPartialInvite { + /// + public new DiscordInviteType Type { get; } + /// public new string Code { get; } @@ -17,6 +22,9 @@ public interface IInvite : IPartialInvite // partial access routes + /// + Optional IPartialInvite.Type => this.Type; + /// Optional IPartialInvite.Code => this.Code; diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/Invites/IPartialInvite.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Invites/IPartialInvite.cs index a4581e2ed5..49274510a2 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Models/Invites/IPartialInvite.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Invites/IPartialInvite.cs @@ -13,6 +13,11 @@ namespace DSharpPlus.Internal.Abstractions.Models; /// public interface IPartialInvite { + /// + /// Specifies the type of this invite. + /// + public Optional Type { get; } + /// /// The unique invite code. /// diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/Users/IAvatarDecorationData.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Users/IAvatarDecorationData.cs new file mode 100644 index 0000000000..d583687a47 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Users/IAvatarDecorationData.cs @@ -0,0 +1,21 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Internal.Abstractions.Models; + +/// +/// Contains the data for an user's avatar decoration. +/// +public interface IAvatarDecorationData +{ + /// + /// The hash of the avatar decoration. + /// + public string Asset { get; } + + /// + /// The snowflake identifier of the associated SKU. + /// + public Snowflake SkuId { get; } +} diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/Users/IPartialUser.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Users/IPartialUser.cs index 853c09efd8..937e043d34 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Models/Users/IPartialUser.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Users/IPartialUser.cs @@ -92,7 +92,7 @@ public interface IPartialUser public Optional PublicFlags { get; } /// - /// The user's avatar decoration hash. + /// The user's avatar decoration data. /// - public Optional AvatarDecoration { get; } + public Optional AvatarDecorationData { get; } } diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IChannelRestAPI.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IChannelRestAPI.cs index 7b38314e89..61ebd13708 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IChannelRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IChannelRestAPI.cs @@ -237,7 +237,7 @@ public ValueTask>> GetReactionsAsync Snowflake channelId, Snowflake messageId, string emoji, - ForwardsPaginatedQuery query = default, + GetReactionsQuery query = default, RequestInfo info = default, CancellationToken ct = default ); @@ -406,6 +406,7 @@ public ValueTask DeleteChannelPermissionAsync /// /// The payload, containing the snowflake identifier of the channel you want messages to be cross-posted into. /// + /// An optional audit log reason. /// Additional instructions regarding this request. /// A cancellation token for this operation. /// The created followed channel object. @@ -413,6 +414,7 @@ public ValueTask> FollowAnnouncementChannelAsync ( Snowflake channelId, IFollowAnnouncementChannelPayload payload, + string? reason = null, RequestInfo info = default, CancellationToken ct = default ); diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IEntitlementsRestAPI.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IEntitlementsRestAPI.cs index bd34267fd4..97bf028508 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IEntitlementsRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IEntitlementsRestAPI.cs @@ -67,4 +67,21 @@ public ValueTask DeleteTestEntitlementAsync RequestInfo info = default, CancellationToken ct = default ); + + /// + /// Marks an entitlement as consumed. The entitlement will have set to true + /// if queried. + /// + /// The snowflake identifier of your application. + /// The snowflake identifier of the entitlement to consume. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + /// + public ValueTask ConsumeEntitlementAsync + ( + Snowflake applicationId, + Snowflake entitlementId, + RequestInfo info = default, + CancellationToken ct = default + ); } diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Users/IModifyCurrentUserPayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Users/IModifyCurrentUserPayload.cs index b8cdaed12e..d96ed6d1ba 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Users/IModifyCurrentUserPayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Users/IModifyCurrentUserPayload.cs @@ -20,4 +20,9 @@ public interface IModifyCurrentUserPayload /// The new avatar for this user. /// public Optional Avatar { get; } + + /// + /// The new banner for this user. + /// + public Optional Banner { get; } } diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Channels/GetReactionsQuery.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Channels/GetReactionsQuery.cs new file mode 100644 index 0000000000..d70620b1bf --- /dev/null +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Channels/GetReactionsQuery.cs @@ -0,0 +1,23 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Internal.Abstractions.Rest.Queries; + +public readonly record struct GetReactionsQuery +{ + /// + /// The type of reactions to query for. + /// + public ReactionType? Type { get; init; } + + /// + /// If specified, only request entities with an ID greater than this ID. + /// + public Snowflake? After { get; init; } + + /// + /// The maximum number of entities to return from this request. + /// + public int? Limit { get; init; } +} diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Channels/ReactionType.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Channels/ReactionType.cs new file mode 100644 index 0000000000..0def512725 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Channels/ReactionType.cs @@ -0,0 +1,21 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Internal.Abstractions.Rest.Queries; + +/// +/// Enumerates reaction types to query for. +/// +public enum ReactionType +{ + /// + /// Standard reactions. + /// + Normal, + + /// + /// Super reactions. + /// + Burst +} diff --git a/src/core/DSharpPlus.Internal.Models/ApplicationCommands/ApplicationCommand.cs b/src/core/DSharpPlus.Internal.Models/ApplicationCommands/ApplicationCommand.cs index 30a06a9769..c45e932373 100644 --- a/src/core/DSharpPlus.Internal.Models/ApplicationCommands/ApplicationCommand.cs +++ b/src/core/DSharpPlus.Internal.Models/ApplicationCommands/ApplicationCommand.cs @@ -53,4 +53,4 @@ public sealed record ApplicationCommand : IApplicationCommand /// public required Snowflake Version { get; init; } -} +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Models/ApplicationCommands/ApplicationCommandOption.cs b/src/core/DSharpPlus.Internal.Models/ApplicationCommands/ApplicationCommandOption.cs index be38909503..bff9107100 100644 --- a/src/core/DSharpPlus.Internal.Models/ApplicationCommands/ApplicationCommandOption.cs +++ b/src/core/DSharpPlus.Internal.Models/ApplicationCommands/ApplicationCommandOption.cs @@ -55,4 +55,4 @@ public sealed record ApplicationCommandOption : IApplicationCommandOption /// public Optional Autocomplete { get; init; } -} +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Models/ApplicationCommands/ApplicationCommandOptionChoice.cs b/src/core/DSharpPlus.Internal.Models/ApplicationCommands/ApplicationCommandOptionChoice.cs index 85c0e2b2d5..a3a9747a4e 100644 --- a/src/core/DSharpPlus.Internal.Models/ApplicationCommands/ApplicationCommandOptionChoice.cs +++ b/src/core/DSharpPlus.Internal.Models/ApplicationCommands/ApplicationCommandOptionChoice.cs @@ -21,4 +21,4 @@ public sealed record ApplicationCommandOptionChoice : IApplicationCommandOptionC /// public required OneOf Value { get; init; } -} +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Models/AuditLogs/AuditLogChange.cs b/src/core/DSharpPlus.Internal.Models/AuditLogs/AuditLogChange.cs index c5f7fd8037..851289f358 100644 --- a/src/core/DSharpPlus.Internal.Models/AuditLogs/AuditLogChange.cs +++ b/src/core/DSharpPlus.Internal.Models/AuditLogs/AuditLogChange.cs @@ -17,4 +17,4 @@ public sealed record AuditLogChange : IAuditLogChange /// public required string Key { get; init; } -} +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Models/AuditLogs/AuditLogEntryInfo.cs b/src/core/DSharpPlus.Internal.Models/AuditLogs/AuditLogEntryInfo.cs index 2c10286b2e..0eccde3cd8 100644 --- a/src/core/DSharpPlus.Internal.Models/AuditLogs/AuditLogEntryInfo.cs +++ b/src/core/DSharpPlus.Internal.Models/AuditLogs/AuditLogEntryInfo.cs @@ -41,4 +41,4 @@ public sealed record AuditLogEntryInfo : IAuditLogEntryInfo /// public Optional Type { get; init; } -} +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Models/AutoModeration/AutoModerationTriggerMetadata.cs b/src/core/DSharpPlus.Internal.Models/AutoModeration/AutoModerationTriggerMetadata.cs index 5aae09b169..fedb2b02be 100644 --- a/src/core/DSharpPlus.Internal.Models/AutoModeration/AutoModerationTriggerMetadata.cs +++ b/src/core/DSharpPlus.Internal.Models/AutoModeration/AutoModerationTriggerMetadata.cs @@ -29,4 +29,4 @@ public sealed record AutoModerationTriggerMetadata : IAutoModerationTriggerMetad /// public Optional MentionRaidProtectionEnabled { get; init; } -} +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Models/AutoModeration/BlockMessageActionMetadata.cs b/src/core/DSharpPlus.Internal.Models/AutoModeration/BlockMessageActionMetadata.cs index 450b757f92..5c6719126b 100644 --- a/src/core/DSharpPlus.Internal.Models/AutoModeration/BlockMessageActionMetadata.cs +++ b/src/core/DSharpPlus.Internal.Models/AutoModeration/BlockMessageActionMetadata.cs @@ -12,4 +12,4 @@ public sealed record BlockMessageActionMetadata : IBlockMessageActionMetadata { /// public Optional CustomMessage { get; init; } -} +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Models/AutoModeration/SendAlertMessageActionMetadata.cs b/src/core/DSharpPlus.Internal.Models/AutoModeration/SendAlertMessageActionMetadata.cs index 6e9bef62cf..f96df74c97 100644 --- a/src/core/DSharpPlus.Internal.Models/AutoModeration/SendAlertMessageActionMetadata.cs +++ b/src/core/DSharpPlus.Internal.Models/AutoModeration/SendAlertMessageActionMetadata.cs @@ -12,4 +12,4 @@ public sealed record SendAlertMessageActionMetadata : ISendAlertMessageActionMet { /// public required Snowflake ChannelId { get; init; } -} +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Models/AutoModeration/TimeoutActionMetadata.cs b/src/core/DSharpPlus.Internal.Models/AutoModeration/TimeoutActionMetadata.cs index 364e06a2bc..0f31482a86 100644 --- a/src/core/DSharpPlus.Internal.Models/AutoModeration/TimeoutActionMetadata.cs +++ b/src/core/DSharpPlus.Internal.Models/AutoModeration/TimeoutActionMetadata.cs @@ -12,4 +12,4 @@ public sealed record TimeoutActionMetadata : ITimeoutActionMetadata { /// public required int DurationSeconds { get; init; } -} +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Models/Channels/AllowedMentions.cs b/src/core/DSharpPlus.Internal.Models/Channels/AllowedMentions.cs index 8db12ecd5a..2e75c35dd4 100644 --- a/src/core/DSharpPlus.Internal.Models/Channels/AllowedMentions.cs +++ b/src/core/DSharpPlus.Internal.Models/Channels/AllowedMentions.cs @@ -22,4 +22,4 @@ public sealed record AllowedMentions : IAllowedMentions /// public Optional RepliedUser { get; init; } -} +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Models/Channels/Channel.cs b/src/core/DSharpPlus.Internal.Models/Channels/Channel.cs index f64a533dcb..d561f36344 100644 --- a/src/core/DSharpPlus.Internal.Models/Channels/Channel.cs +++ b/src/core/DSharpPlus.Internal.Models/Channels/Channel.cs @@ -117,4 +117,4 @@ public sealed record Channel : IChannel /// public Optional DefaultForumLayout { get; init; } -} +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Models/Channels/DefaultReaction.cs b/src/core/DSharpPlus.Internal.Models/Channels/DefaultReaction.cs index 0e35da28ee..3bd156f0c0 100644 --- a/src/core/DSharpPlus.Internal.Models/Channels/DefaultReaction.cs +++ b/src/core/DSharpPlus.Internal.Models/Channels/DefaultReaction.cs @@ -14,4 +14,4 @@ public sealed record DefaultReaction : IDefaultReaction /// public string? EmojiName { get; init; } -} +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Models/Channels/ForumTag.cs b/src/core/DSharpPlus.Internal.Models/Channels/ForumTag.cs index e81c27a394..f093919ab6 100644 --- a/src/core/DSharpPlus.Internal.Models/Channels/ForumTag.cs +++ b/src/core/DSharpPlus.Internal.Models/Channels/ForumTag.cs @@ -23,4 +23,4 @@ public sealed record ForumTag : IForumTag /// public string? EmojiName { get; init; } -} +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Models/Channels/Message.cs b/src/core/DSharpPlus.Internal.Models/Channels/Message.cs index 16b4edadee..a98374870d 100644 --- a/src/core/DSharpPlus.Internal.Models/Channels/Message.cs +++ b/src/core/DSharpPlus.Internal.Models/Channels/Message.cs @@ -107,5 +107,8 @@ public sealed record Message : IMessage public Optional Resolved { get; init; } /// - public Optional Poll { get; init; } -} + public Optional Poll { get; init; } + + /// + public Optional Call { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Models/Channels/MessageCall.cs b/src/core/DSharpPlus.Internal.Models/Channels/MessageCall.cs new file mode 100644 index 0000000000..b6102772da --- /dev/null +++ b/src/core/DSharpPlus.Internal.Models/Channels/MessageCall.cs @@ -0,0 +1,20 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; +using System.Collections.Generic; + +using DSharpPlus.Internal.Abstractions.Models; + +namespace DSharpPlus.Internal.Models; + +/// +public sealed record MessageCall : IMessageCall +{ + /// + public required IReadOnlyList Participants { get; init; } + + /// + public Optional EndedTimestamp { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Models/Channels/MessageInteractionMetadata.cs b/src/core/DSharpPlus.Internal.Models/Channels/MessageInteractionMetadata.cs index 788ef01b42..9b26135319 100644 --- a/src/core/DSharpPlus.Internal.Models/Channels/MessageInteractionMetadata.cs +++ b/src/core/DSharpPlus.Internal.Models/Channels/MessageInteractionMetadata.cs @@ -19,7 +19,7 @@ public sealed record MessageInteractionMetadata : IMessageInteractionMetadata public required DiscordInteractionType Type { get; init; } /// - public required Snowflake UserId { get; init; } + public required IUser User { get; init; } /// public required IReadOnlyDictionary AuthorizingIntegrationOwners { get; init; } @@ -32,4 +32,4 @@ public sealed record MessageInteractionMetadata : IMessageInteractionMetadata /// public Optional TriggeringInteractionMetadata { get; init; } -} +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Models/Channels/PartialChannel.cs b/src/core/DSharpPlus.Internal.Models/Channels/PartialChannel.cs index 9c100a299e..041c876fa3 100644 --- a/src/core/DSharpPlus.Internal.Models/Channels/PartialChannel.cs +++ b/src/core/DSharpPlus.Internal.Models/Channels/PartialChannel.cs @@ -117,4 +117,4 @@ public sealed record PartialChannel : IPartialChannel /// public Optional DefaultForumLayout { get; init; } -} +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Models/Channels/PartialMessage.cs b/src/core/DSharpPlus.Internal.Models/Channels/PartialMessage.cs index d4d9e54c20..f5afc97ad6 100644 --- a/src/core/DSharpPlus.Internal.Models/Channels/PartialMessage.cs +++ b/src/core/DSharpPlus.Internal.Models/Channels/PartialMessage.cs @@ -107,5 +107,8 @@ public sealed record PartialMessage : IPartialMessage public Optional Resolved { get; init; } /// - public Optional Poll { get; init; } -} + public Optional Poll { get; init; } + + /// + public Optional Call { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Models/Entitlements/Entitlement.cs b/src/core/DSharpPlus.Internal.Models/Entitlements/Entitlement.cs index 8f2eb2141f..b5f89c37e3 100644 --- a/src/core/DSharpPlus.Internal.Models/Entitlements/Entitlement.cs +++ b/src/core/DSharpPlus.Internal.Models/Entitlements/Entitlement.cs @@ -38,4 +38,7 @@ public sealed record Entitlement : IEntitlement /// public Optional EndsAt { get; init; } -} + + /// + public Optional Consumed { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Models/Entitlements/PartialEntitlement.cs b/src/core/DSharpPlus.Internal.Models/Entitlements/PartialEntitlement.cs index f9bf5d596e..b2f4a2164c 100644 --- a/src/core/DSharpPlus.Internal.Models/Entitlements/PartialEntitlement.cs +++ b/src/core/DSharpPlus.Internal.Models/Entitlements/PartialEntitlement.cs @@ -38,4 +38,7 @@ public sealed record PartialEntitlement : IPartialEntitlement /// public Optional EndsAt { get; init; } -} + + /// + public Optional Consumed { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Models/Guilds/Guild.cs b/src/core/DSharpPlus.Internal.Models/Guilds/Guild.cs index 0a2d6d387a..89845799b0 100644 --- a/src/core/DSharpPlus.Internal.Models/Guilds/Guild.cs +++ b/src/core/DSharpPlus.Internal.Models/Guilds/Guild.cs @@ -137,4 +137,4 @@ public sealed record Guild : IGuild /// public Snowflake? SafetyAlertsChannelId { get; init; } -} +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Models/Guilds/GuildMember.cs b/src/core/DSharpPlus.Internal.Models/Guilds/GuildMember.cs index 6995a030fd..8180618c8a 100644 --- a/src/core/DSharpPlus.Internal.Models/Guilds/GuildMember.cs +++ b/src/core/DSharpPlus.Internal.Models/Guilds/GuildMember.cs @@ -48,4 +48,7 @@ public sealed record GuildMember : IGuildMember /// public Optional CommunicationDisabledUntil { get; init; } -} + + /// + public Optional AvatarDecorationData { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Models/Guilds/OnboardingPrompt.cs b/src/core/DSharpPlus.Internal.Models/Guilds/OnboardingPrompt.cs index 34df643e52..7124867ce4 100644 --- a/src/core/DSharpPlus.Internal.Models/Guilds/OnboardingPrompt.cs +++ b/src/core/DSharpPlus.Internal.Models/Guilds/OnboardingPrompt.cs @@ -32,4 +32,4 @@ public sealed record OnboardingPrompt : IOnboardingPrompt /// public required bool InOnboarding { get; init; } -} +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Models/Guilds/PartialGuild.cs b/src/core/DSharpPlus.Internal.Models/Guilds/PartialGuild.cs index e4054c0a7c..2860f20e4d 100644 --- a/src/core/DSharpPlus.Internal.Models/Guilds/PartialGuild.cs +++ b/src/core/DSharpPlus.Internal.Models/Guilds/PartialGuild.cs @@ -137,4 +137,4 @@ public sealed record PartialGuild : IPartialGuild /// public Optional SafetyAlertsChannelId { get; init; } -} +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Models/Guilds/PartialGuildMember.cs b/src/core/DSharpPlus.Internal.Models/Guilds/PartialGuildMember.cs index 989225cfb9..2a17dd7eef 100644 --- a/src/core/DSharpPlus.Internal.Models/Guilds/PartialGuildMember.cs +++ b/src/core/DSharpPlus.Internal.Models/Guilds/PartialGuildMember.cs @@ -48,4 +48,7 @@ public sealed record PartialGuildMember : IPartialGuildMember /// public Optional CommunicationDisabledUntil { get; init; } -} + + /// + public Optional AvatarDecorationData { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Models/Interactions/Interaction.cs b/src/core/DSharpPlus.Internal.Models/Interactions/Interaction.cs index 42572933ad..95283d6ec0 100644 --- a/src/core/DSharpPlus.Internal.Models/Interactions/Interaction.cs +++ b/src/core/DSharpPlus.Internal.Models/Interactions/Interaction.cs @@ -26,6 +26,9 @@ public sealed record Interaction : IInteraction /// public Optional> Data { get; init; } + /// + public Optional Guild { get; init; } + /// public Optional GuildId { get; init; } @@ -67,4 +70,4 @@ public sealed record Interaction : IInteraction /// public Optional Context { get; init; } -} +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Models/Interactions/ResolvedData.cs b/src/core/DSharpPlus.Internal.Models/Interactions/ResolvedData.cs index 2963949a34..2b57cb7e4a 100644 --- a/src/core/DSharpPlus.Internal.Models/Interactions/ResolvedData.cs +++ b/src/core/DSharpPlus.Internal.Models/Interactions/ResolvedData.cs @@ -28,4 +28,4 @@ public sealed record ResolvedData : IResolvedData /// public Optional> Attachments { get; init; } -} +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Models/Invites/Invite.cs b/src/core/DSharpPlus.Internal.Models/Invites/Invite.cs index 647142d9a2..c35068fca2 100644 --- a/src/core/DSharpPlus.Internal.Models/Invites/Invite.cs +++ b/src/core/DSharpPlus.Internal.Models/Invites/Invite.cs @@ -12,6 +12,9 @@ namespace DSharpPlus.Internal.Models; /// public sealed record Invite : IInvite { + /// + public required DiscordInviteType Type { get; init; } + /// public required string Code { get; init; } @@ -59,4 +62,4 @@ public sealed record Invite : IInvite /// public Optional CreatedAt { get; init; } -} +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Models/Invites/PartialInvite.cs b/src/core/DSharpPlus.Internal.Models/Invites/PartialInvite.cs index be5af8fca5..49ee583b37 100644 --- a/src/core/DSharpPlus.Internal.Models/Invites/PartialInvite.cs +++ b/src/core/DSharpPlus.Internal.Models/Invites/PartialInvite.cs @@ -12,6 +12,9 @@ namespace DSharpPlus.Internal.Models; /// public sealed record PartialInvite : IPartialInvite { + /// + public Optional Type { get; init; } + /// public Optional Code { get; init; } @@ -59,4 +62,4 @@ public sealed record PartialInvite : IPartialInvite /// public Optional CreatedAt { get; init; } -} +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Models/MessageComponents/ActionRowComponent.cs b/src/core/DSharpPlus.Internal.Models/MessageComponents/ActionRowComponent.cs index f063d5d1d8..5cfd073238 100644 --- a/src/core/DSharpPlus.Internal.Models/MessageComponents/ActionRowComponent.cs +++ b/src/core/DSharpPlus.Internal.Models/MessageComponents/ActionRowComponent.cs @@ -17,4 +17,4 @@ public sealed record ActionRowComponent : IActionRowComponent /// public required IReadOnlyList Components { get; init; } -} +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Models/MessageComponents/ButtonComponent.cs b/src/core/DSharpPlus.Internal.Models/MessageComponents/ButtonComponent.cs index a64138a388..1726964647 100644 --- a/src/core/DSharpPlus.Internal.Models/MessageComponents/ButtonComponent.cs +++ b/src/core/DSharpPlus.Internal.Models/MessageComponents/ButtonComponent.cs @@ -30,4 +30,4 @@ public sealed record ButtonComponent : IButtonComponent /// public Optional Disabled { get; init; } -} +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Models/MessageComponents/ChannelSelectComponent.cs b/src/core/DSharpPlus.Internal.Models/MessageComponents/ChannelSelectComponent.cs index adaa26c995..54025d7724 100644 --- a/src/core/DSharpPlus.Internal.Models/MessageComponents/ChannelSelectComponent.cs +++ b/src/core/DSharpPlus.Internal.Models/MessageComponents/ChannelSelectComponent.cs @@ -35,4 +35,4 @@ public sealed record ChannelSelectComponent : IChannelSelectComponent /// public Optional Disabled { get; init; } -} +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Models/MessageComponents/DefaultSelectValue.cs b/src/core/DSharpPlus.Internal.Models/MessageComponents/DefaultSelectValue.cs index e8eb68efd2..80a96fa1ad 100644 --- a/src/core/DSharpPlus.Internal.Models/MessageComponents/DefaultSelectValue.cs +++ b/src/core/DSharpPlus.Internal.Models/MessageComponents/DefaultSelectValue.cs @@ -14,4 +14,4 @@ public sealed record DefaultSelectValue : IDefaultSelectValue /// public required string Type { get; init; } -} +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Models/MessageComponents/MentionableSelectComponent.cs b/src/core/DSharpPlus.Internal.Models/MessageComponents/MentionableSelectComponent.cs index fdf65ec208..4132f05864 100644 --- a/src/core/DSharpPlus.Internal.Models/MessageComponents/MentionableSelectComponent.cs +++ b/src/core/DSharpPlus.Internal.Models/MessageComponents/MentionableSelectComponent.cs @@ -32,4 +32,4 @@ public sealed record MentionableSelectComponent : IMentionableSelectComponent /// public Optional Disabled { get; init; } -} +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Models/MessageComponents/RoleSelectComponent.cs b/src/core/DSharpPlus.Internal.Models/MessageComponents/RoleSelectComponent.cs index 7630e7abb6..03600d46cf 100644 --- a/src/core/DSharpPlus.Internal.Models/MessageComponents/RoleSelectComponent.cs +++ b/src/core/DSharpPlus.Internal.Models/MessageComponents/RoleSelectComponent.cs @@ -32,4 +32,4 @@ public sealed record RoleSelectComponent : IRoleSelectComponent /// public Optional Disabled { get; init; } -} +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Models/MessageComponents/SelectOption.cs b/src/core/DSharpPlus.Internal.Models/MessageComponents/SelectOption.cs index 1842f1c7b3..344ea8fe03 100644 --- a/src/core/DSharpPlus.Internal.Models/MessageComponents/SelectOption.cs +++ b/src/core/DSharpPlus.Internal.Models/MessageComponents/SelectOption.cs @@ -23,4 +23,4 @@ public sealed record SelectOption : ISelectOption /// public Optional Default { get; init; } -} +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Models/MessageComponents/UserSelectComponent.cs b/src/core/DSharpPlus.Internal.Models/MessageComponents/UserSelectComponent.cs index 7d2031e92b..2d08593d40 100644 --- a/src/core/DSharpPlus.Internal.Models/MessageComponents/UserSelectComponent.cs +++ b/src/core/DSharpPlus.Internal.Models/MessageComponents/UserSelectComponent.cs @@ -32,4 +32,4 @@ public sealed record UserSelectComponent : IUserSelectComponent /// public Optional Disabled { get; init; } -} +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Models/Polls/PollAnswerCount.cs b/src/core/DSharpPlus.Internal.Models/Polls/PollAnswerCount.cs index 54e7df2db9..a4e4f19cdd 100644 --- a/src/core/DSharpPlus.Internal.Models/Polls/PollAnswerCount.cs +++ b/src/core/DSharpPlus.Internal.Models/Polls/PollAnswerCount.cs @@ -17,4 +17,4 @@ public sealed record PollAnswerCount : IPollAnswerCount /// public required bool MeVoted { get; init; } -} +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Models/Polls/PollMedia.cs b/src/core/DSharpPlus.Internal.Models/Polls/PollMedia.cs index c79ec380df..14f313e153 100644 --- a/src/core/DSharpPlus.Internal.Models/Polls/PollMedia.cs +++ b/src/core/DSharpPlus.Internal.Models/Polls/PollMedia.cs @@ -14,4 +14,4 @@ public sealed record PollMedia : IPollMedia /// public Optional Emoji { get; init; } -} +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Models/Polls/PollResults.cs b/src/core/DSharpPlus.Internal.Models/Polls/PollResults.cs index 4fd2ae8efc..92a20f8f29 100644 --- a/src/core/DSharpPlus.Internal.Models/Polls/PollResults.cs +++ b/src/core/DSharpPlus.Internal.Models/Polls/PollResults.cs @@ -16,4 +16,4 @@ public sealed record PollResults : IPollResults /// public required IReadOnlyList AnswerCounts { get; init; } -} +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Models/RoleConnections/RoleConnectionMetadata.cs b/src/core/DSharpPlus.Internal.Models/RoleConnections/RoleConnectionMetadata.cs index db19662aaa..ecbc246636 100644 --- a/src/core/DSharpPlus.Internal.Models/RoleConnections/RoleConnectionMetadata.cs +++ b/src/core/DSharpPlus.Internal.Models/RoleConnections/RoleConnectionMetadata.cs @@ -29,4 +29,4 @@ public sealed record RoleConnectionMetadata : IRoleConnectionMetadata /// public Optional?> DescriptionLocalizations { get; init; } -} +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Models/ScheduledEvents/ScheduledEventUser.cs b/src/core/DSharpPlus.Internal.Models/ScheduledEvents/ScheduledEventUser.cs index 2615e4ba8d..41bcd9d5fe 100644 --- a/src/core/DSharpPlus.Internal.Models/ScheduledEvents/ScheduledEventUser.cs +++ b/src/core/DSharpPlus.Internal.Models/ScheduledEvents/ScheduledEventUser.cs @@ -17,4 +17,4 @@ public sealed record ScheduledEventUser : IScheduledEventUser /// public Optional Member { get; init; } -} +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Models/Teams/TeamMember.cs b/src/core/DSharpPlus.Internal.Models/Teams/TeamMember.cs index 5cc7461fee..cfdcc8dc34 100644 --- a/src/core/DSharpPlus.Internal.Models/Teams/TeamMember.cs +++ b/src/core/DSharpPlus.Internal.Models/Teams/TeamMember.cs @@ -23,4 +23,4 @@ public sealed record TeamMember : ITeamMember /// public required IPartialUser User { get; init; } -} +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Models/Users/AvatarDecorationData.cs b/src/core/DSharpPlus.Internal.Models/Users/AvatarDecorationData.cs new file mode 100644 index 0000000000..d78256c8b4 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Models/Users/AvatarDecorationData.cs @@ -0,0 +1,17 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Internal.Abstractions.Models; + +namespace DSharpPlus.Internal.Models; + +/// +public sealed record AvatarDecorationData : IAvatarDecorationData +{ + /// + public required string Asset { get; init; } + + /// + public required Snowflake SkuId { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Models/Users/PartialUser.cs b/src/core/DSharpPlus.Internal.Models/Users/PartialUser.cs index 9b60dc5c20..91bccf6103 100644 --- a/src/core/DSharpPlus.Internal.Models/Users/PartialUser.cs +++ b/src/core/DSharpPlus.Internal.Models/Users/PartialUser.cs @@ -59,5 +59,5 @@ public sealed record PartialUser : IPartialUser public Optional PublicFlags { get; init; } /// - public Optional AvatarDecoration { get; init; } -} + public Optional AvatarDecorationData { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Models/Users/User.cs b/src/core/DSharpPlus.Internal.Models/Users/User.cs index 0fab8adcad..d0cd9b7258 100644 --- a/src/core/DSharpPlus.Internal.Models/Users/User.cs +++ b/src/core/DSharpPlus.Internal.Models/Users/User.cs @@ -59,5 +59,5 @@ public sealed record User : IUser public Optional PublicFlags { get; init; } /// - public Optional AvatarDecoration { get; init; } -} + public Optional AvatarDecorationData { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Rest/API/ChannelRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/ChannelRestAPI.cs index e735e2554a..5c174683bc 100644 --- a/src/core/DSharpPlus.Internal.Rest/API/ChannelRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Rest/API/ChannelRestAPI.cs @@ -455,6 +455,7 @@ public async ValueTask> FollowAnnouncementChannelAsync ( Snowflake channelId, IFollowAnnouncementChannelPayload payload, + string? reason = null, RequestInfo info = default, CancellationToken ct = default ) @@ -464,7 +465,8 @@ public async ValueTask> FollowAnnouncementChannelAsync HttpMethod.Post, $"channels/{channelId}/followers", b => b.WithSimpleRoute(TopLevelResource.Channel, channelId) - .WithPayload(payload), + .WithPayload(payload) + .WithAuditLogReason(reason), info, ct ); @@ -594,7 +596,7 @@ public async ValueTask>> GetReactionsAsync Snowflake channelId, Snowflake messageId, string emoji, - ForwardsPaginatedQuery query = default, + GetReactionsQuery query = default, RequestInfo info = default, CancellationToken ct = default ) @@ -611,6 +613,16 @@ public async ValueTask>> GetReactionsAsync _ = builder.AddParameter("after", query.After.Value.ToString()); } + if (query.Limit is not null) + { + _ = builder.AddParameter("limit", query.Limit.Value.ToString(CultureInfo.InvariantCulture)); + } + + if (query.Type is not null) + { + _ = builder.AddParameter("type", ((int)query.Type.Value).ToString(CultureInfo.InvariantCulture)); + } + return await restClient.ExecuteRequestAsync> ( HttpMethod.Get, diff --git a/src/core/DSharpPlus.Internal.Rest/API/EntitlementsRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/EntitlementsRestAPI.cs index 7053b1bb6c..2846970e8f 100644 --- a/src/core/DSharpPlus.Internal.Rest/API/EntitlementsRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Rest/API/EntitlementsRestAPI.cs @@ -22,6 +22,24 @@ namespace DSharpPlus.Internal.Rest.API; public sealed class EntitlementsRestAPI(IRestClient restClient) : IEntitlementsRestAPI { + /// + public async ValueTask ConsumeEntitlementAsync + ( + Snowflake applicationId, + Snowflake entitlementId, + RequestInfo info = default, + CancellationToken ct = default + ) + { + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Post, + $"applications/{applicationId}/entitlements/{entitlementId}/consume", + info: info, + ct: ct + ); + } + /// public async ValueTask> CreateTestEntitlementAsync ( diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/ApplicationCommands/CreateGlobalApplicationCommandPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/ApplicationCommands/CreateGlobalApplicationCommandPayload.cs index c60107d703..50d4d08f7f 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/ApplicationCommands/CreateGlobalApplicationCommandPayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/ApplicationCommands/CreateGlobalApplicationCommandPayload.cs @@ -42,4 +42,4 @@ public sealed record CreateGlobalApplicationCommandPayload : ICreateGlobalApplic /// public required IReadOnlyList Contexts { get; init; } -} +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/ApplicationCommands/CreateGuildApplicationCommandPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/ApplicationCommands/CreateGuildApplicationCommandPayload.cs index c1cb878e24..411ee34778 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/ApplicationCommands/CreateGuildApplicationCommandPayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/ApplicationCommands/CreateGuildApplicationCommandPayload.cs @@ -36,4 +36,4 @@ public sealed record CreateGuildApplicationCommandPayload : ICreateGuildApplicat /// public Optional Nsfw { get; init; } -} +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/ApplicationCommands/EditGlobalApplicationCommandPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/ApplicationCommands/EditGlobalApplicationCommandPayload.cs index 32396c570a..b406a2d6dd 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/ApplicationCommands/EditGlobalApplicationCommandPayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/ApplicationCommands/EditGlobalApplicationCommandPayload.cs @@ -42,4 +42,4 @@ public sealed record EditGlobalApplicationCommandPayload : IEditGlobalApplicatio /// public required IReadOnlyList Contexts { get; init; } -} +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/ApplicationCommands/EditGuildApplicationCommandPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/ApplicationCommands/EditGuildApplicationCommandPayload.cs index 8a4c1b2fbe..b02f6c9155 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/ApplicationCommands/EditGuildApplicationCommandPayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/ApplicationCommands/EditGuildApplicationCommandPayload.cs @@ -36,4 +36,4 @@ public sealed record EditGuildApplicationCommandPayload : IEditGuildApplicationC /// public Optional Nsfw { get; init; } -} +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Applications/EditCurrentApplicationPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Applications/EditCurrentApplicationPayload.cs index ecd7b0da7a..5a6890811f 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/Applications/EditCurrentApplicationPayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Applications/EditCurrentApplicationPayload.cs @@ -39,4 +39,4 @@ public sealed record EditCurrentApplicationPayload : IEditCurrentApplicationPayl /// public Optional> Tags { get; init; } -} +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/AutoModeration/CreateAutoModerationRulePayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/AutoModeration/CreateAutoModerationRulePayload.cs index f82de35924..d6738d0184 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/AutoModeration/CreateAutoModerationRulePayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/AutoModeration/CreateAutoModerationRulePayload.cs @@ -36,4 +36,4 @@ public sealed record CreateAutoModerationRulePayload : ICreateAutoModerationRule /// public Optional> ExemptChannels { get; init; } -} +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/AutoModeration/ModifyAutoModerationRulePayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/AutoModeration/ModifyAutoModerationRulePayload.cs index 5ab5ba34d9..e5614894e6 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/AutoModeration/ModifyAutoModerationRulePayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/AutoModeration/ModifyAutoModerationRulePayload.cs @@ -33,4 +33,4 @@ public sealed record ModifyAutoModerationRulePayload : IModifyAutoModerationRule /// public Optional> ExemptChannels { get; init; } -} +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/CreateChannelInvitePayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/CreateChannelInvitePayload.cs index da8d6e6b85..e2471e9e80 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/CreateChannelInvitePayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/CreateChannelInvitePayload.cs @@ -30,4 +30,4 @@ public sealed record CreateChannelInvitePayload : ICreateChannelInvitePayload /// public Optional TargetApplicationId { get; init; } -} +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/CreateMessagePayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/CreateMessagePayload.cs index 952acaae0c..3260020291 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/CreateMessagePayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/CreateMessagePayload.cs @@ -51,4 +51,4 @@ public sealed record CreateMessagePayload : ICreateMessagePayload /// public Optional Poll { get; init; } -} +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/EditMessagePayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/EditMessagePayload.cs index b61cf2c88e..54336c6287 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/EditMessagePayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/EditMessagePayload.cs @@ -33,4 +33,4 @@ public sealed record EditMessagePayload : IEditMessagePayload /// public Optional?> Attachments { get; init; } -} +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/ForumAndMediaThreadMessage.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/ForumAndMediaThreadMessage.cs index a10a0be920..41b974213a 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/ForumAndMediaThreadMessage.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/ForumAndMediaThreadMessage.cs @@ -33,4 +33,4 @@ public sealed record ForumAndMediaThreadMessage : IForumAndMediaThreadMessage /// public Optional Flags { get; init; } -} +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/ModifyGuildChannelPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/ModifyGuildChannelPayload.cs index 51d043c92e..29f48bbbb8 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/ModifyGuildChannelPayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/ModifyGuildChannelPayload.cs @@ -69,4 +69,4 @@ public sealed record ModifyGuildChannelPayload : IModifyGuildChannelPayload /// public Optional DefaultForumLayout { get; init; } -} +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/CreateGuildChannelPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/CreateGuildChannelPayload.cs index 4193aaae7c..abeb172fd2 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/CreateGuildChannelPayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/CreateGuildChannelPayload.cs @@ -66,4 +66,4 @@ public sealed record CreateGuildChannelPayload : ICreateGuildChannelPayload /// public Optional DefaultThreadRateLimitPerUser { get; init; } -} +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/CreateGuildPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/CreateGuildPayload.cs index 4aed99537a..9713248373 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/CreateGuildPayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/CreateGuildPayload.cs @@ -45,4 +45,4 @@ public sealed record CreateGuildPayload : ICreateGuildPayload /// public Optional SystemChannelFlags { get; init; } -} +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyGuildOnboardingPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyGuildOnboardingPayload.cs index 7c7aab9ac4..03b75258ea 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyGuildOnboardingPayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyGuildOnboardingPayload.cs @@ -24,4 +24,4 @@ public sealed record ModifyGuildOnboardingPayload : IModifyGuildOnboardingPayloa /// public required DiscordGuildOnboardingMode Mode { get; init; } -} +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Interactions/CreateFollowupMessagePayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Interactions/CreateFollowupMessagePayload.cs index 1aaa07b41b..d6c7d6c89f 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/Interactions/CreateFollowupMessagePayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Interactions/CreateFollowupMessagePayload.cs @@ -39,4 +39,4 @@ public sealed record CreateFollowupMessagePayload : ICreateFollowupMessagePayloa /// public Optional Poll { get; init; } -} +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/ScheduledEvents/CreateGuildScheduledEventPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/ScheduledEvents/CreateGuildScheduledEventPayload.cs index ddccf69d77..878f4cff20 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/ScheduledEvents/CreateGuildScheduledEventPayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/ScheduledEvents/CreateGuildScheduledEventPayload.cs @@ -39,4 +39,4 @@ public sealed record CreateGuildScheduledEventPayload : ICreateGuildScheduledEve /// public Optional Image { get; init; } -} +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/ScheduledEvents/ModifyGuildScheduledEventPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/ScheduledEvents/ModifyGuildScheduledEventPayload.cs index 7050c6a108..6ffa92f810 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/ScheduledEvents/ModifyGuildScheduledEventPayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/ScheduledEvents/ModifyGuildScheduledEventPayload.cs @@ -42,4 +42,4 @@ public sealed record ModifyGuildScheduledEventPayload : IModifyGuildScheduledEve /// public Optional Image { get; init; } -} +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Users/ModifyCurrentUserPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Users/ModifyCurrentUserPayload.cs index 9fa4056d69..30aab26145 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/Users/ModifyCurrentUserPayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Users/ModifyCurrentUserPayload.cs @@ -14,4 +14,7 @@ public sealed record ModifyCurrentUserPayload : IModifyCurrentUserPayload /// public Optional Avatar { get; init; } -} + + /// + public Optional Banner { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Webhooks/ExecuteWebhookPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Webhooks/ExecuteWebhookPayload.cs index cf1aeecdb7..1932f90940 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/Webhooks/ExecuteWebhookPayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Webhooks/ExecuteWebhookPayload.cs @@ -51,4 +51,4 @@ public sealed record ExecuteWebhookPayload : IExecuteWebhookPayload /// public Optional Poll { get; init; } -} +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Shared/Entities/Entitlements/DiscordEntitlementType.cs b/src/core/DSharpPlus.Shared/Entities/Entitlements/DiscordEntitlementType.cs index 8768f46ebb..254bad0b28 100644 --- a/src/core/DSharpPlus.Shared/Entities/Entitlements/DiscordEntitlementType.cs +++ b/src/core/DSharpPlus.Shared/Entities/Entitlements/DiscordEntitlementType.cs @@ -4,10 +4,48 @@ namespace DSharpPlus.Entities; +/// +/// The type of an entitlement. +/// public enum DiscordEntitlementType { + /// + /// The entitlement was purchased by the user. + /// + Purchase = 1, + + /// + /// The entitlement was given for a Nitro subscription. + /// + PremiumSubscription, + + /// + /// The entitlement was a gift from the developer. + /// + DeveloperGift, + + /// + /// The entitlement was purchased by a developer in test mode. + /// + TestModePurchase, + + /// + /// The entitlement was granted when the SKU was free. + /// + FreePurchase, + + /// + /// The entitlement was gifted by another user. + /// + UserGift, + + /// + /// The entitlement was claimed by the user as a Nitro subscriber. + /// + PremiumPurchase, + /// /// This entitlement was purchased as an app subscription. /// - ApplicationSubscription = 8 + ApplicationSubscription } diff --git a/src/core/DSharpPlus.Shared/Entities/Invites/DiscordInviteType.cs b/src/core/DSharpPlus.Shared/Entities/Invites/DiscordInviteType.cs new file mode 100644 index 0000000000..637b3d4669 --- /dev/null +++ b/src/core/DSharpPlus.Shared/Entities/Invites/DiscordInviteType.cs @@ -0,0 +1,26 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Entities; + +/// +/// Specifies the type of an invite. +/// +public enum DiscordInviteType +{ + /// + /// An invite to a guild. + /// + Guild, + + /// + /// An invite to a group DM. + /// + GroupDm, + + /// + /// A friend invite. + /// + Friend +} diff --git a/src/core/DSharpPlus.Shared/Entities/Skus/DiscordSkuType.cs b/src/core/DSharpPlus.Shared/Entities/Skus/DiscordSkuType.cs index 0ea1c1d6da..646aac127f 100644 --- a/src/core/DSharpPlus.Shared/Entities/Skus/DiscordSkuType.cs +++ b/src/core/DSharpPlus.Shared/Entities/Skus/DiscordSkuType.cs @@ -9,6 +9,16 @@ namespace DSharpPlus.Entities; /// public enum DiscordSkuType { + /// + /// Represents a permanent one-time purchase. + /// + Durable = 2, + + /// + /// Represents a consumable one-time purchase. + /// + Consumable = 3, + /// /// Represents a recurring subscription. /// diff --git a/src/extensions/DSharpPlus.Extensions.Internal.Builders/Implementations/BuiltActionRowComponent.cs b/src/extensions/DSharpPlus.Extensions.Internal.Builders/Implementations/BuiltActionRowComponent.cs index 4eba4dadf6..787d50e3ae 100644 --- a/src/extensions/DSharpPlus.Extensions.Internal.Builders/Implementations/BuiltActionRowComponent.cs +++ b/src/extensions/DSharpPlus.Extensions.Internal.Builders/Implementations/BuiltActionRowComponent.cs @@ -17,4 +17,4 @@ internal sealed record BuiltActionRowComponent : IActionRowComponent /// public required IReadOnlyList Components { get; init; } -} +} \ No newline at end of file From 503e9ce76d20bad6376f8bf9c091eaa2c93d5768 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sun, 26 May 2024 19:44:32 +0200 Subject: [PATCH 297/323] auto-generate model serialization registration --- dsharpplus.csx | 6 + ...erviceCollectionExtensions.Registration.cs | 154 ++++++++++++++++++ .../Extensions/ServiceCollectionExtensions.cs | 137 +--------------- ...erviceCollectionExtensions.Registration.cs | 88 ++++++++++ .../generate-serialization-registration.csx | 120 ++++++++++++++ 5 files changed, 370 insertions(+), 135 deletions(-) create mode 100644 src/core/DSharpPlus.Internal.Models/Extensions/ServiceCollectionExtensions.Registration.cs create mode 100644 src/core/DSharpPlus.Internal.Rest/Extensions/ServiceCollectionExtensions.Registration.cs create mode 100644 tools/generators/generate-serialization-registration.csx diff --git a/dsharpplus.csx b/dsharpplus.csx index efa14d5691..065307ed70 100644 --- a/dsharpplus.csx +++ b/dsharpplus.csx @@ -46,6 +46,12 @@ ToolMetadata[] tools = Name = "copy-concrete-implementations", Subset = "extensions", Type = ToolType.Generator + }, + new() + { + Name = "generate-serialization-registration", + Subset = "core", + Type = ToolType.Generator } }; diff --git a/src/core/DSharpPlus.Internal.Models/Extensions/ServiceCollectionExtensions.Registration.cs b/src/core/DSharpPlus.Internal.Models/Extensions/ServiceCollectionExtensions.Registration.cs new file mode 100644 index 0000000000..ea69885e43 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Models/Extensions/ServiceCollectionExtensions.Registration.cs @@ -0,0 +1,154 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +#pragma warning disable IDE0058 + +using DSharpPlus.Internal.Abstractions.Models; +using DSharpPlus.Internal.Models; +using DSharpPlus.Serialization; + +using Microsoft.Extensions.DependencyInjection; + +namespace DSharpPlus.Internal.Models.Extensions; + +partial class ServiceCollectionExtensions +{ + private static void RegisterSerialization(IServiceCollection services) + { + services.Configure + ( + options => + { + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + } + ); + } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Models/Extensions/ServiceCollectionExtensions.cs b/src/core/DSharpPlus.Internal.Models/Extensions/ServiceCollectionExtensions.cs index 360d4bc4ee..a9ae755870 100644 --- a/src/core/DSharpPlus.Internal.Models/Extensions/ServiceCollectionExtensions.cs +++ b/src/core/DSharpPlus.Internal.Models/Extensions/ServiceCollectionExtensions.cs @@ -18,7 +18,7 @@ namespace DSharpPlus.Internal.Models.Extensions; /// /// Provides extensions on IServiceCollection to register our JSON serialization of Discord models. /// -public static class ServiceCollectionExtensions +public static partial class ServiceCollectionExtensions { /// /// Registers converters for Discord's API models. @@ -54,140 +54,7 @@ public static IServiceCollection RegisterDiscordModelSerialization } ); - services.Configure - ( - options => - { - options.AddModel(); - options.AddModel(); - options.AddModel(); - options.AddModel(); - options.AddModel(); - options.AddModel(); - - options.AddModel(); - options.AddModel(); - options.AddModel(); - options.AddModel(); - - options.AddModel(); - options.AddModel(); - options.AddModel(); - options.AddModel(); - options.AddModel(); - options.AddModel(); - options.AddModel(); - - options.AddModel(); - options.AddModel(); - options.AddModel(); - options.AddModel(); - options.AddModel(); - options.AddModel(); - options.AddModel(); - options.AddModel(); - options.AddModel(); - options.AddModel(); - options.AddModel(); - options.AddModel(); - options.AddModel(); - options.AddModel(); - options.AddModel(); - options.AddModel(); - options.AddModel(); - options.AddModel(); - options.AddModel(); - options.AddModel(); - options.AddModel(); - options.AddModel(); - options.AddModel(); - options.AddModel(); - options.AddModel(); - options.AddModel(); - options.AddModel(); - options.AddModel(); - - options.AddModel(); - options.AddModel(); - - options.AddModel(); - - options.AddModel(); - options.AddModel(); - options.AddModel(); - options.AddModel(); - options.AddModel(); - options.AddModel(); - options.AddModel(); - options.AddModel(); - options.AddModel(); - options.AddModel(); - options.AddModel(); - options.AddModel(); - options.AddModel(); - options.AddModel(); - options.AddModel(); - options.AddModel(); - options.AddModel(); - options.AddModel(); - - options.AddModel(); - - options.AddModel(); - options.AddModel(); - options.AddModel(); - options.AddModel(); - options.AddModel(); - options.AddModel(); - options.AddModel(); - options.AddModel(); - options.AddModel(); - options.AddModel(); - - options.AddModel(); - options.AddModel(); - - options.AddModel(); - options.AddModel(); - options.AddModel(); - options.AddModel(); - options.AddModel(); - options.AddModel(); - options.AddModel(); - options.AddModel(); - options.AddModel(); - - options.AddModel(); - - options.AddModel(); - options.AddModel(); - options.AddModel(); - - options.AddModel(); - - options.AddModel(); - options.AddModel(); - - options.AddModel(); - options.AddModel(); - options.AddModel(); - options.AddModel(); - - options.AddModel(); - options.AddModel(); - - options.AddModel(); - options.AddModel(); - options.AddModel(); - options.AddModel(); - - options.AddModel(); - options.AddModel(); - - options.AddModel(); - options.AddModel(); - } - ); + RegisterSerialization(services); return services; } diff --git a/src/core/DSharpPlus.Internal.Rest/Extensions/ServiceCollectionExtensions.Registration.cs b/src/core/DSharpPlus.Internal.Rest/Extensions/ServiceCollectionExtensions.Registration.cs new file mode 100644 index 0000000000..274188bd9e --- /dev/null +++ b/src/core/DSharpPlus.Internal.Rest/Extensions/ServiceCollectionExtensions.Registration.cs @@ -0,0 +1,88 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +#pragma warning disable IDE0058 + +using DSharpPlus.Internal.Abstractions.Rest.Payloads; +using DSharpPlus.Internal.Rest.Payloads; +using DSharpPlus.Serialization; + +using Microsoft.Extensions.DependencyInjection; + +namespace DSharpPlus.Internal.Rest.Extensions; + +partial class ServiceCollectionExtensions +{ + private static void RegisterSerialization(IServiceCollection services) + { + services.Configure + ( + options => + { + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + } + ); + } +} \ No newline at end of file diff --git a/tools/generators/generate-serialization-registration.csx b/tools/generators/generate-serialization-registration.csx new file mode 100644 index 0000000000..223d9df8a0 --- /dev/null +++ b/tools/generators/generate-serialization-registration.csx @@ -0,0 +1,120 @@ +#!/usr/bin/env dotnet-script + +#nullable enable + +#r "nuget:Spectre.Console, 0.47.1-preview.0.26" + +using System.IO; + +using Spectre.Console; + +// Syntax: +// generate-rest-payloads [abstraction path] [output path] +if (Args is ["-h" or "--help" or "-?"]) +{ + AnsiConsole.MarkupLine + ( + """ + [plum1]DSharpPlus Serialization Generator, v0.1.0[/] + + Usage: generate-serialization-registration.csx + """ + ); + + return 0; +} + +AnsiConsole.MarkupLine +( + """ + [plum1]DSharpPlus Serialization Generator, v0.1.0[/] + """ +); + +WriteSerializationRegistration +( + "src/core/DSharpPlus.Internal.Models", + "src/core/DSharpPlus.Internal.Models/Extensions/ServiceCollectionExtensions.Registration.cs", + "DSharpPlus.Internal.Abstractions.Models", + "DSharpPlus.Internal.Models", + "DSharpPlus.Internal.Models.Extensions" +); + +WriteSerializationRegistration +( + "src/core/DSharpPlus.Internal.Rest/Payloads", + "src/core/DSharpPlus.Internal.Rest/Extensions/ServiceCollectionExtensions.Registration.cs", + "DSharpPlus.Internal.Abstractions.Rest.Payloads", + "DSharpPlus.Internal.Rest.Payloads", + "DSharpPlus.Internal.Rest.Extensions" +); + +public void WriteSerializationRegistration +( + string input, + string output, + string abstractionNamespace, + string targetNamespace, + string outputNamespace +) +{ + string[] files = Directory.GetFiles(input, "*.cs", SearchOption.AllDirectories); + + files = files.Where + ( + x => + { + return !x.Contains("/Extensions/") && !x.Contains("\\Extensions\\") + && !x.Contains("/Serialization/") && !x.Contains("\\Serialization\\"); + } + ) + .Select + ( + path => + { + FileInfo file = new(path); + return file.Name.Replace(".cs", ""); + } + ) + .ToArray(); + + using StreamWriter writer = new(output); + + writer.Write($$""" +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +#pragma warning disable IDE0058 + +using {{abstractionNamespace}}; +using {{targetNamespace}}; +using DSharpPlus.Serialization; + +using Microsoft.Extensions.DependencyInjection; + +namespace {{outputNamespace}}; + +partial class ServiceCollectionExtensions +{ + private static void RegisterSerialization(IServiceCollection services) + { + services.Configure + ( + options => + { + +"""); + + foreach (string s in files) + { + writer.Write($" options.AddModel();\r\n"); + } + + writer.Write(""" + } + ); + } +} +"""); +} \ No newline at end of file From 90135ac2579cf45697739331750c35f5eb896249 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Tue, 18 Jun 2024 14:25:49 +0200 Subject: [PATCH 298/323] add convenience extension methods for responding to interactions --- meta/builder-concrete-types.json | 6 +- ...erviceCollectionExtensions.Registration.cs | 2 +- .../InteractionRestAPIExtensions.cs | 293 ++++++++++++++++++ .../BuiltCreateFollowupMessagePayload.cs | 42 +++ .../BuiltEditFollowupMessagePayload.cs | 32 ++ .../BuiltEditInteractionResponsePayload.cs | 32 ++ .../BuiltMessageCallbackData.cs | 41 +++ .../Interactions/ModalBuilder.cs | 4 +- .../Interactions/TextInputComponentBuilder.cs | 1 - .../copy-concrete-implementations.csx | 4 +- .../generators/generate-concrete-objects.csx | 2 +- tools/generators/generate-rest-payloads.csx | 2 +- 12 files changed, 451 insertions(+), 10 deletions(-) create mode 100644 src/extensions/DSharpPlus.Extensions.Internal.Builders/Extensions/InteractionRestAPIExtensions.cs create mode 100644 src/extensions/DSharpPlus.Extensions.Internal.Builders/Implementations/BuiltCreateFollowupMessagePayload.cs create mode 100644 src/extensions/DSharpPlus.Extensions.Internal.Builders/Implementations/BuiltEditFollowupMessagePayload.cs create mode 100644 src/extensions/DSharpPlus.Extensions.Internal.Builders/Implementations/BuiltEditInteractionResponsePayload.cs create mode 100644 src/extensions/DSharpPlus.Extensions.Internal.Builders/Implementations/BuiltMessageCallbackData.cs diff --git a/meta/builder-concrete-types.json b/meta/builder-concrete-types.json index 2af3c009e8..00805b7639 100644 --- a/meta/builder-concrete-types.json +++ b/meta/builder-concrete-types.json @@ -2,6 +2,10 @@ "./src/core/DSharpPlus.Internal.Models/Channels/Embed.cs", "./src/core/DSharpPlus.Internal.Models/Interactions/InteractionResponse.cs", "./src/core/DSharpPlus.Internal.Models/Interactions/ModalCallbackData.cs", + "./src/core/DSharpPlus.Internal.Models/Interactions/MessageCallbackData.cs", "./src/core/DSharpPlus.Internal.Models/MessageComponents/ActionRowComponent.cs", - "./src/core/DSharpPlus.Internal.Models/MessageComponents/TextInputComponent.cs" + "./src/core/DSharpPlus.Internal.Models/MessageComponents/TextInputComponent.cs", + "./src/core/DSharpPlus.Internal.Rest/Payloads/Interactions/CreateFollowupMessagePayload.cs", + "./src/core/DSharpPlus.Internal.Rest/Payloads/Interactions/EditFollowupMessagePayload.cs", + "./src/core/DSharpPlus.Internal.Rest/Payloads/Interactions/EditInteractionResponsePayload.cs" ] \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Models/Extensions/ServiceCollectionExtensions.Registration.cs b/src/core/DSharpPlus.Internal.Models/Extensions/ServiceCollectionExtensions.Registration.cs index ea69885e43..ed54e2ed15 100644 --- a/src/core/DSharpPlus.Internal.Models/Extensions/ServiceCollectionExtensions.Registration.cs +++ b/src/core/DSharpPlus.Internal.Models/Extensions/ServiceCollectionExtensions.Registration.cs @@ -151,4 +151,4 @@ private static void RegisterSerialization(IServiceCollection services) } ); } -} \ No newline at end of file +} diff --git a/src/extensions/DSharpPlus.Extensions.Internal.Builders/Extensions/InteractionRestAPIExtensions.cs b/src/extensions/DSharpPlus.Extensions.Internal.Builders/Extensions/InteractionRestAPIExtensions.cs new file mode 100644 index 0000000000..95e4f36a32 --- /dev/null +++ b/src/extensions/DSharpPlus.Extensions.Internal.Builders/Extensions/InteractionRestAPIExtensions.cs @@ -0,0 +1,293 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +#pragma warning disable IDE0046 // we have a lot of early returns here that we don't want to become ternaries. + +using System.Collections.Generic; +using System.Diagnostics; +using System.Runtime.CompilerServices; +using System.Threading; +using System.Threading.Tasks; + +using DSharpPlus.Entities; +using DSharpPlus.Extensions.Internal.Builders.Implementations; +using DSharpPlus.Extensions.Internal.Builders.Interactions; +using DSharpPlus.Extensions.Internal.Builders.Messages; +using DSharpPlus.Internal.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Rest; +using DSharpPlus.Internal.Abstractions.Rest.API; +using DSharpPlus.Results; + +namespace DSharpPlus.Extensions.Internal.Builders.Extensions; + +/// +/// Contains extension methods on to enable using builders. +/// +public static class InteractionRestAPIExtensions +{ + /// + /// Responds to the specified interaction using a modal. + /// + /// The underlying interaction API. + /// The snowflake identifier of the interaction. + /// The interaction token received with the interaction. + /// The modal builder to respond with. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + [AsyncMethodBuilder(typeof(PoolingAsyncValueTaskMethodBuilder<>))] + public static async ValueTask RespondWithModalAsync + ( + this IInteractionRestAPI underlying, + Snowflake interactionId, + string interactionToken, + ModalBuilder modal, + RequestInfo info = default, + CancellationToken ct = default + ) + { + Result result = modal.Validate(); + + if (!result.IsSuccess) + { + return result; + } + + return await underlying.CreateInteractionResponseAsync + ( + interactionId, + interactionToken, + modal.Build(), + info, + ct + ); + } + + /// + /// Responds to the specified interaction using an embed. + /// + /// The underlying interaction API. + /// The snowflake identifier of the interaction. + /// The interaction token received with the interaction. + /// The embed builder to respond with. + /// Specifies whether the response to this request should be ephemeral. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + [AsyncMethodBuilder(typeof(PoolingAsyncValueTaskMethodBuilder<>))] + public static async ValueTask RespondWithEmbedAsync + ( + this IInteractionRestAPI underlying, + Snowflake interactionId, + string interactionToken, + EmbedBuilder embed, + bool ephemeral, + RequestInfo info = default, + CancellationToken ct = default + ) + { + Result result = embed.Validate(); + + if (!result.IsSuccess) + { + return result; + } + + BuiltInteractionResponse response = new() + { + Type = DiscordInteractionCallbackType.ChannelMessageWithSource, + Data = new + ( + new BuiltMessageCallbackData() + { + Embeds = new Optional>([embed.Build()]), + Flags = ephemeral ? new(DiscordMessageFlags.Ephemeral) : Optional.None + } + ) + }; + + return await underlying.CreateInteractionResponseAsync + ( + interactionId, + interactionToken, + response, + info, + ct + ); + } + + /// + /// Creates a followup response containing an embed. If this is the first followup to a deferred interaction + /// response as created by , + /// ephemerality of this message will be dictated by the specified originally, + /// and will be ignored. + /// + /// The underlying interaction API. + /// The snowflake identifier of your application. + /// The interaction token received with the interaction. + /// The embed builder to respond with. + /// Specifies whether this response should be ephemeral. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public static async ValueTask> FollowupWithEmbedAsync + ( + this IInteractionRestAPI underlying, + Snowflake applicationId, + string interactionToken, + EmbedBuilder embed, + bool ephemeral, + RequestInfo info = default, + CancellationToken ct = default + ) + { + Result result = embed.Validate(); + + if (!result.IsSuccess) + { + return Result.FromError(result.Error); + } + + return await underlying.CreateFollowupMessageAsync + ( + applicationId, + interactionToken, + new BuiltCreateFollowupMessagePayload + { + Embeds = new([embed.Build()]), + Flags = ephemeral ? new(DiscordMessageFlags.Ephemeral) : Optional.None + }, + info, + ct + ); + } + + /// + /// Edits the original response with the specified embed. This will leave all fields but embeds intact. + /// Ephemerality is dictated by the original response. + /// + /// The underlying interaction API. + /// The snowflake identifier of your application. + /// The interaction token received with the interaction. + /// The embed builder to respond with. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public static async ValueTask> ModifyResponseWithEmbedAsync + ( + this IInteractionRestAPI underlying, + Snowflake applicationId, + string interactionToken, + EmbedBuilder embed, + RequestInfo info = default, + CancellationToken ct = default + ) + { + Result result = embed.Validate(); + + if (!result.IsSuccess) + { + return Result.FromError(result.Error); + } + + return await underlying.EditInteractionResponseAsync + ( + applicationId, + interactionToken, + new BuiltEditInteractionResponsePayload + { + Embeds = new([embed.Build()]) + }, + info, + ct + ); + } + + /// + /// Edits the original response with the specified embed. This will leave all fields but embeds intact. + /// Ephemerality is dictated by the original response. + /// + /// The underlying interaction API. + /// The snowflake identifier of your application. + /// The interaction token received with the interaction. + /// The snowflake identifier of the followup message. + /// The embed builder to respond with. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public static async ValueTask> ModifyFollowupWithEmbedAsync + ( + this IInteractionRestAPI underlying, + Snowflake applicationId, + string interactionToken, + Snowflake messageId, + EmbedBuilder embed, + RequestInfo info = default, + CancellationToken ct = default + ) + { + Result result = embed.Validate(); + + if (!result.IsSuccess) + { + return Result.FromError(result.Error); + } + + return await underlying.EditFollowupMessageAsync + ( + applicationId, + interactionToken, + messageId, + new BuiltEditFollowupMessagePayload + { + Embeds = new([embed.Build()]) + }, + info, + ct + ); + } + + /// + [StackTraceHidden] + [DebuggerStepThrough] + public static ValueTask RespondWithEmbedAsync + ( + this IInteractionRestAPI underlying, + Snowflake interactionId, + string interactionToken, + EmbedBuilder embed, + RequestInfo info = default, + CancellationToken ct = default + ) + { + return underlying.RespondWithEmbedAsync + ( + interactionId, + interactionToken, + embed, + false, + info, + ct + ); + } + + /// + [StackTraceHidden] + [DebuggerStepThrough] + public static ValueTask> FollowupWithEmbedAsync + ( + this IInteractionRestAPI underlying, + Snowflake applicationId, + string interactionToken, + EmbedBuilder embed, + RequestInfo info = default, + CancellationToken ct = default + ) + { + return underlying.FollowupWithEmbedAsync + ( + applicationId, + interactionToken, + embed, + false, + info, + ct + ); + } +} diff --git a/src/extensions/DSharpPlus.Extensions.Internal.Builders/Implementations/BuiltCreateFollowupMessagePayload.cs b/src/extensions/DSharpPlus.Extensions.Internal.Builders/Implementations/BuiltCreateFollowupMessagePayload.cs new file mode 100644 index 0000000000..819d6d30fa --- /dev/null +++ b/src/extensions/DSharpPlus.Extensions.Internal.Builders/Implementations/BuiltCreateFollowupMessagePayload.cs @@ -0,0 +1,42 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Rest.Payloads; + +namespace DSharpPlus.Extensions.Internal.Builders.Implementations; + +/// +internal sealed record BuiltCreateFollowupMessagePayload : ICreateFollowupMessagePayload +{ + /// + public Optional Content { get; init; } + + /// + public Optional Tts { get; init; } + + /// + public Optional> Embeds { get; init; } + + /// + public Optional AllowedMentions { get; init; } + + /// + public Optional> Components { get; init; } + + /// + public IReadOnlyList? Files { get; init; } + + /// + public Optional> Attachments { get; init; } + + /// + public Optional Flags { get; init; } + + /// + public Optional Poll { get; init; } +} \ No newline at end of file diff --git a/src/extensions/DSharpPlus.Extensions.Internal.Builders/Implementations/BuiltEditFollowupMessagePayload.cs b/src/extensions/DSharpPlus.Extensions.Internal.Builders/Implementations/BuiltEditFollowupMessagePayload.cs new file mode 100644 index 0000000000..1411bd3d7a --- /dev/null +++ b/src/extensions/DSharpPlus.Extensions.Internal.Builders/Implementations/BuiltEditFollowupMessagePayload.cs @@ -0,0 +1,32 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Internal.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Rest.Payloads; + +namespace DSharpPlus.Extensions.Internal.Builders.Implementations; + +/// +internal sealed record BuiltEditFollowupMessagePayload : IEditFollowupMessagePayload +{ + /// + public Optional Content { get; init; } + + /// + public Optional?> Embeds { get; init; } + + /// + public Optional AllowedMentions { get; init; } + + /// + public Optional?> Components { get; init; } + + /// + public Optional?> Attachments { get; init; } + + /// + public IReadOnlyList? Files { get; init; } +} diff --git a/src/extensions/DSharpPlus.Extensions.Internal.Builders/Implementations/BuiltEditInteractionResponsePayload.cs b/src/extensions/DSharpPlus.Extensions.Internal.Builders/Implementations/BuiltEditInteractionResponsePayload.cs new file mode 100644 index 0000000000..2403856706 --- /dev/null +++ b/src/extensions/DSharpPlus.Extensions.Internal.Builders/Implementations/BuiltEditInteractionResponsePayload.cs @@ -0,0 +1,32 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Internal.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Rest.Payloads; + +namespace DSharpPlus.Extensions.Internal.Builders.Implementations; + +/// +internal sealed record BuiltEditInteractionResponsePayload : IEditInteractionResponsePayload +{ + /// + public Optional Content { get; init; } + + /// + public Optional?> Embeds { get; init; } + + /// + public Optional AllowedMentions { get; init; } + + /// + public Optional?> Components { get; init; } + + /// + public Optional?> Attachments { get; init; } + + /// + public IReadOnlyList? Files { get; init; } +} diff --git a/src/extensions/DSharpPlus.Extensions.Internal.Builders/Implementations/BuiltMessageCallbackData.cs b/src/extensions/DSharpPlus.Extensions.Internal.Builders/Implementations/BuiltMessageCallbackData.cs new file mode 100644 index 0000000000..4af05b433f --- /dev/null +++ b/src/extensions/DSharpPlus.Extensions.Internal.Builders/Implementations/BuiltMessageCallbackData.cs @@ -0,0 +1,41 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; + +namespace DSharpPlus.Extensions.Internal.Builders.Implementations; + +/// +internal sealed record BuiltMessageCallbackData : IMessageCallbackData +{ + /// + public Optional Tts { get; init; } + + /// + public Optional Content { get; init; } + + /// + public Optional> Embeds { get; init; } + + /// + public Optional AllowedMentions { get; init; } + + /// + public Optional Flags { get; init; } + + /// + public Optional> Components { get; init; } + + /// + public Optional> Attachments { get; init; } + + /// + public Optional Poll { get; init; } + + /// + public IReadOnlyList? Files { get; init; } +} diff --git a/src/extensions/DSharpPlus.Extensions.Internal.Builders/Interactions/ModalBuilder.cs b/src/extensions/DSharpPlus.Extensions.Internal.Builders/Interactions/ModalBuilder.cs index 1922db8a74..ae68c416df 100644 --- a/src/extensions/DSharpPlus.Extensions.Internal.Builders/Interactions/ModalBuilder.cs +++ b/src/extensions/DSharpPlus.Extensions.Internal.Builders/Interactions/ModalBuilder.cs @@ -14,8 +14,6 @@ using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Results; -using OneOf; - namespace DSharpPlus.Extensions.Internal.Builders.Interactions; /// @@ -127,7 +125,7 @@ public static IInteractionResponse Build(ref this ModalBuilder builder) return new BuiltInteractionResponse { Type = DiscordInteractionCallbackType.Modal, - Data = OneOf.FromT2 + Data = new ( new BuiltModalCallbackData { diff --git a/src/extensions/DSharpPlus.Extensions.Internal.Builders/Interactions/TextInputComponentBuilder.cs b/src/extensions/DSharpPlus.Extensions.Internal.Builders/Interactions/TextInputComponentBuilder.cs index aa77917356..0f5633dfbf 100644 --- a/src/extensions/DSharpPlus.Extensions.Internal.Builders/Interactions/TextInputComponentBuilder.cs +++ b/src/extensions/DSharpPlus.Extensions.Internal.Builders/Interactions/TextInputComponentBuilder.cs @@ -12,7 +12,6 @@ using DSharpPlus.Extensions.Internal.Builders.Errors; using DSharpPlus.Extensions.Internal.Builders.Implementations; using DSharpPlus.Internal.Abstractions.Models; - using DSharpPlus.Results; namespace DSharpPlus.Extensions.Internal.Builders.Interactions; diff --git a/tools/generators/copy-concrete-implementations.csx b/tools/generators/copy-concrete-implementations.csx index 63874ba635..646bd7bf90 100644 --- a/tools/generators/copy-concrete-implementations.csx +++ b/tools/generators/copy-concrete-implementations.csx @@ -22,7 +22,7 @@ if (Args is ["-h" or "--help" or "-?"]) """ [plum1]DSharpPlus Concrete Implementation Theft, v0.1.0[/] - Usage: copy-concrete-implementations.csx [path to meta file]] + Usage: copy-concrete-implementations.csx [[path to meta file]] Extracts the required concrete types for DSharpPlus.Extensions.Internal.Builders to remove dependency on concrete implementations. """ @@ -90,7 +90,7 @@ if (changes.Removed.Any()) AnsiConsole.MarkupLine ( """ - [red]Some concrete types were deleted. Please update the meta file and the corresponding builder code, if applicable: + [red]Some concrete types were deleted. Please update the meta file and the corresponding builder code, if applicable:[/] """ ); diff --git a/tools/generators/generate-concrete-objects.csx b/tools/generators/generate-concrete-objects.csx index 3b2aeca5a4..ac179d9bc3 100644 --- a/tools/generators/generate-concrete-objects.csx +++ b/tools/generators/generate-concrete-objects.csx @@ -269,7 +269,7 @@ for (int i = 0; i < collectedMetadata.Count; i++) writer.AppendLine ( $""" - {string.Join('\n', group.OrderBy(name => name))} + {string.Join("\r\n", group.OrderBy(name => name))} """ ); diff --git a/tools/generators/generate-rest-payloads.csx b/tools/generators/generate-rest-payloads.csx index f046baa397..e087a99a1e 100644 --- a/tools/generators/generate-rest-payloads.csx +++ b/tools/generators/generate-rest-payloads.csx @@ -230,7 +230,7 @@ for (int i = 0; i < collectedMetadata.Count; i++) writer.AppendLine ( $""" - {string.Join('\n', group.OrderBy(name => name))} + {string.Join("\r\n", group.OrderBy(name => name))} """ ); From dbe7918649b46a40faa184bd298c9b254818c705 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Tue, 18 Jun 2024 14:27:26 +0200 Subject: [PATCH 299/323] these can just be optional parameters --- .../InteractionRestAPIExtensions.cs | 53 +------------------ 1 file changed, 2 insertions(+), 51 deletions(-) diff --git a/src/extensions/DSharpPlus.Extensions.Internal.Builders/Extensions/InteractionRestAPIExtensions.cs b/src/extensions/DSharpPlus.Extensions.Internal.Builders/Extensions/InteractionRestAPIExtensions.cs index 95e4f36a32..770eaf62da 100644 --- a/src/extensions/DSharpPlus.Extensions.Internal.Builders/Extensions/InteractionRestAPIExtensions.cs +++ b/src/extensions/DSharpPlus.Extensions.Internal.Builders/Extensions/InteractionRestAPIExtensions.cs @@ -5,7 +5,6 @@ #pragma warning disable IDE0046 // we have a lot of early returns here that we don't want to become ternaries. using System.Collections.Generic; -using System.Diagnostics; using System.Runtime.CompilerServices; using System.Threading; using System.Threading.Tasks; @@ -80,7 +79,7 @@ public static async ValueTask RespondWithEmbedAsync Snowflake interactionId, string interactionToken, EmbedBuilder embed, - bool ephemeral, + bool ephemeral = false, RequestInfo info = default, CancellationToken ct = default ) @@ -134,7 +133,7 @@ public static async ValueTask> FollowupWithEmbedAsync Snowflake applicationId, string interactionToken, EmbedBuilder embed, - bool ephemeral, + bool ephemeral = false, RequestInfo info = default, CancellationToken ct = default ) @@ -242,52 +241,4 @@ public static async ValueTask> ModifyFollowupWithEmbedAsync ct ); } - - /// - [StackTraceHidden] - [DebuggerStepThrough] - public static ValueTask RespondWithEmbedAsync - ( - this IInteractionRestAPI underlying, - Snowflake interactionId, - string interactionToken, - EmbedBuilder embed, - RequestInfo info = default, - CancellationToken ct = default - ) - { - return underlying.RespondWithEmbedAsync - ( - interactionId, - interactionToken, - embed, - false, - info, - ct - ); - } - - /// - [StackTraceHidden] - [DebuggerStepThrough] - public static ValueTask> FollowupWithEmbedAsync - ( - this IInteractionRestAPI underlying, - Snowflake applicationId, - string interactionToken, - EmbedBuilder embed, - RequestInfo info = default, - CancellationToken ct = default - ) - { - return underlying.FollowupWithEmbedAsync - ( - applicationId, - interactionToken, - embed, - false, - info, - ct - ); - } } From c99aecf442937de62c2b56916e0f5ddd517cd09d Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Tue, 18 Jun 2024 18:24:22 +0200 Subject: [PATCH 300/323] utilities for sending embed builders too --- meta/builder-concrete-types.json | 2 + ...erviceCollectionExtensions.Registration.cs | 2 +- .../Extensions/ChannelRestAPIExtensions.cs | 100 ++++++++++++++++++ .../BuiltCreateMessagePayload.cs | 54 ++++++++++ .../BuiltEditMessagePayload.cs | 36 +++++++ 5 files changed, 193 insertions(+), 1 deletion(-) create mode 100644 src/extensions/DSharpPlus.Extensions.Internal.Builders/Extensions/ChannelRestAPIExtensions.cs create mode 100644 src/extensions/DSharpPlus.Extensions.Internal.Builders/Implementations/BuiltCreateMessagePayload.cs create mode 100644 src/extensions/DSharpPlus.Extensions.Internal.Builders/Implementations/BuiltEditMessagePayload.cs diff --git a/meta/builder-concrete-types.json b/meta/builder-concrete-types.json index 00805b7639..44071c787c 100644 --- a/meta/builder-concrete-types.json +++ b/meta/builder-concrete-types.json @@ -5,6 +5,8 @@ "./src/core/DSharpPlus.Internal.Models/Interactions/MessageCallbackData.cs", "./src/core/DSharpPlus.Internal.Models/MessageComponents/ActionRowComponent.cs", "./src/core/DSharpPlus.Internal.Models/MessageComponents/TextInputComponent.cs", + "./src/core/DSharpPlus.Internal.Rest/Payloads/Channels/CreateMessagePayload.cs", + "./src/core/DSharpPlus.Internal.Rest/Payloads/Channels/EditMessagePayload.cs", "./src/core/DSharpPlus.Internal.Rest/Payloads/Interactions/CreateFollowupMessagePayload.cs", "./src/core/DSharpPlus.Internal.Rest/Payloads/Interactions/EditFollowupMessagePayload.cs", "./src/core/DSharpPlus.Internal.Rest/Payloads/Interactions/EditInteractionResponsePayload.cs" diff --git a/src/core/DSharpPlus.Internal.Models/Extensions/ServiceCollectionExtensions.Registration.cs b/src/core/DSharpPlus.Internal.Models/Extensions/ServiceCollectionExtensions.Registration.cs index ed54e2ed15..ea69885e43 100644 --- a/src/core/DSharpPlus.Internal.Models/Extensions/ServiceCollectionExtensions.Registration.cs +++ b/src/core/DSharpPlus.Internal.Models/Extensions/ServiceCollectionExtensions.Registration.cs @@ -151,4 +151,4 @@ private static void RegisterSerialization(IServiceCollection services) } ); } -} +} \ No newline at end of file diff --git a/src/extensions/DSharpPlus.Extensions.Internal.Builders/Extensions/ChannelRestAPIExtensions.cs b/src/extensions/DSharpPlus.Extensions.Internal.Builders/Extensions/ChannelRestAPIExtensions.cs new file mode 100644 index 0000000000..3666ce5b19 --- /dev/null +++ b/src/extensions/DSharpPlus.Extensions.Internal.Builders/Extensions/ChannelRestAPIExtensions.cs @@ -0,0 +1,100 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +#pragma warning disable IDE0046 // we have a lot of early returns here that we don't want to become ternaries. + +using System.Threading; +using System.Threading.Tasks; + +using DSharpPlus.Extensions.Internal.Builders.Implementations; +using DSharpPlus.Extensions.Internal.Builders.Messages; +using DSharpPlus.Internal.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Rest; +using DSharpPlus.Internal.Abstractions.Rest.API; +using DSharpPlus.Results; + +namespace DSharpPlus.Extensions.Internal.Builders.Extensions; + +/// +/// Contains extension methods on to enable using builders. +/// +public static class ChannelRestAPIExtensions +{ + /// + /// Creates a new message comprising the specified embed in a channel. + /// + /// The underlying channel API. + /// The snowflake identifier of the message's target channel. + /// The embed this message is to be comprised of. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + /// The newly created message object. + public static async ValueTask> SendEmbedAsync + ( + this IChannelRestAPI underlying, + Snowflake channelId, + EmbedBuilder embed, + RequestInfo info = default, + CancellationToken ct = default + ) + { + Result result = embed.Validate(); + + if (!result.IsSuccess) + { + return Result.FromError(result.Error); + } + + return await underlying.CreateMessageAsync + ( + channelId, + new BuiltCreateMessagePayload + { + Embeds = new([embed.Build()]) + }, + info, + ct + ); + } + + /// + /// Modifies the specified message to comprise the specified embed. This will only update embeds for this message. + /// + /// The underlying channel API. + /// The snowflake identifier of the channel this message was sent in. + /// The snowflake identifier of the message to modify with the embed. + /// The embed this message is to be comprised of. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + /// The newly modified message object. + public static async ValueTask> ModifyEmbedAsync + ( + this IChannelRestAPI underlying, + Snowflake channelId, + Snowflake messageId, + EmbedBuilder embed, + RequestInfo info = default, + CancellationToken ct = default + ) + { + Result result = embed.Validate(); + + if (!result.IsSuccess) + { + return Result.FromError(result.Error); + } + + return await underlying.EditMessageAsync + ( + channelId, + messageId, + new BuiltEditMessagePayload + { + Embeds = new([embed.Build()]) + }, + info, + ct + ); + } +} diff --git a/src/extensions/DSharpPlus.Extensions.Internal.Builders/Implementations/BuiltCreateMessagePayload.cs b/src/extensions/DSharpPlus.Extensions.Internal.Builders/Implementations/BuiltCreateMessagePayload.cs new file mode 100644 index 0000000000..db432fcbf8 --- /dev/null +++ b/src/extensions/DSharpPlus.Extensions.Internal.Builders/Implementations/BuiltCreateMessagePayload.cs @@ -0,0 +1,54 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Rest.Payloads; + +namespace DSharpPlus.Extensions.Internal.Builders.Implementations; + +/// +internal sealed record BuiltCreateMessagePayload : ICreateMessagePayload +{ + /// + public Optional Content { get; init; } + + /// + public Optional Nonce { get; init; } + + /// + public Optional Tts { get; init; } + + /// + public Optional> Embeds { get; init; } + + /// + public Optional AllowedMentions { get; init; } + + /// + public Optional MessageReference { get; init; } + + /// + public Optional> Components { get; init; } + + /// + public Optional> StickerIds { get; init; } + + /// + public IReadOnlyList? Files { get; init; } + + /// + public Optional> Attachments { get; init; } + + /// + public Optional Flags { get; init; } + + /// + public Optional EnforceNonce { get; init; } + + /// + public Optional Poll { get; init; } +} \ No newline at end of file diff --git a/src/extensions/DSharpPlus.Extensions.Internal.Builders/Implementations/BuiltEditMessagePayload.cs b/src/extensions/DSharpPlus.Extensions.Internal.Builders/Implementations/BuiltEditMessagePayload.cs new file mode 100644 index 0000000000..19c0943100 --- /dev/null +++ b/src/extensions/DSharpPlus.Extensions.Internal.Builders/Implementations/BuiltEditMessagePayload.cs @@ -0,0 +1,36 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Rest.Payloads; + +namespace DSharpPlus.Extensions.Internal.Builders.Implementations; + +/// +internal sealed record BuiltEditMessagePayload : IEditMessagePayload +{ + /// + public Optional Content { get; init; } + + /// + public Optional?> Embeds { get; init; } + + /// + public Optional Flags { get; init; } + + /// + public Optional AllowedMentions { get; init; } + + /// + public Optional?> Components { get; init; } + + /// + public IReadOnlyList? Files { get; init; } + + /// + public Optional?> Attachments { get; init; } +} \ No newline at end of file From cee57c397d30190a71ec8882f51cfe96aba843fc Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Wed, 19 Jun 2024 14:12:10 +0200 Subject: [PATCH 301/323] update to latest API docs --- .../MessageComponents/IButtonComponent.cs | 5 +++++ .../MessageComponents/ButtonComponent.cs | 3 +++ .../DiscordAutoModerationActionType.cs | 7 ++++++- .../AutoModeration/DiscordAutoModerationEventType.cs | 7 ++++++- .../DiscordAutoModerationTriggerType.cs | 7 ++++++- .../Entities/Channels/DiscordMessageType.cs | 10 +++++++--- .../Entities/MessageComponents/DiscordButtonStyle.cs | 7 ++++++- tools/generators/copy-concrete-implementations.csx | 12 +++++++++--- 8 files changed, 48 insertions(+), 10 deletions(-) diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IButtonComponent.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IButtonComponent.cs index 5b747d7297..b20f16e0e1 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IButtonComponent.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IButtonComponent.cs @@ -46,4 +46,9 @@ public interface IButtonComponent : IInteractiveComponent /// Indicates whether this button is disabled, default false. /// public Optional Disabled { get; } + + /// + /// A snowflake identifier of a purchasable SKU to link to. This is only available on premium buttons. + /// + public Optional SkuId { get; } } diff --git a/src/core/DSharpPlus.Internal.Models/MessageComponents/ButtonComponent.cs b/src/core/DSharpPlus.Internal.Models/MessageComponents/ButtonComponent.cs index 1726964647..88931fd644 100644 --- a/src/core/DSharpPlus.Internal.Models/MessageComponents/ButtonComponent.cs +++ b/src/core/DSharpPlus.Internal.Models/MessageComponents/ButtonComponent.cs @@ -30,4 +30,7 @@ public sealed record ButtonComponent : IButtonComponent /// public Optional Disabled { get; init; } + + /// + public Optional SkuId { get; init; } } \ No newline at end of file diff --git a/src/core/DSharpPlus.Shared/Entities/AutoModeration/DiscordAutoModerationActionType.cs b/src/core/DSharpPlus.Shared/Entities/AutoModeration/DiscordAutoModerationActionType.cs index 2272736912..9427ac2131 100644 --- a/src/core/DSharpPlus.Shared/Entities/AutoModeration/DiscordAutoModerationActionType.cs +++ b/src/core/DSharpPlus.Shared/Entities/AutoModeration/DiscordAutoModerationActionType.cs @@ -25,5 +25,10 @@ public enum DiscordAutoModerationActionType /// and /// . /// - Timeout + Timeout, + + /// + /// Prevents a member from using text, voice or other interactions. + /// + BlockMemberInteraction } diff --git a/src/core/DSharpPlus.Shared/Entities/AutoModeration/DiscordAutoModerationEventType.cs b/src/core/DSharpPlus.Shared/Entities/AutoModeration/DiscordAutoModerationEventType.cs index a65856ea1d..9e598d8322 100644 --- a/src/core/DSharpPlus.Shared/Entities/AutoModeration/DiscordAutoModerationEventType.cs +++ b/src/core/DSharpPlus.Shared/Entities/AutoModeration/DiscordAutoModerationEventType.cs @@ -12,5 +12,10 @@ public enum DiscordAutoModerationEventType /// /// Fired when a member sends or edits a message. /// - MessageSend = 1 + MessageSend = 1, + + /// + /// Fired when a member edits their profile. + /// + MemberUpdate } diff --git a/src/core/DSharpPlus.Shared/Entities/AutoModeration/DiscordAutoModerationTriggerType.cs b/src/core/DSharpPlus.Shared/Entities/AutoModeration/DiscordAutoModerationTriggerType.cs index d1068c0851..04fe5d10cb 100644 --- a/src/core/DSharpPlus.Shared/Entities/AutoModeration/DiscordAutoModerationTriggerType.cs +++ b/src/core/DSharpPlus.Shared/Entities/AutoModeration/DiscordAutoModerationTriggerType.cs @@ -28,5 +28,10 @@ public enum DiscordAutoModerationTriggerType /// /// Check whether the message content contains more unique mentions than allowed. /// - MentionSpam + MentionSpam, + + /// + /// Check whether the member profile contains words from an user-defined list of keyword. + /// + MemberProfile } diff --git a/src/core/DSharpPlus.Shared/Entities/Channels/DiscordMessageType.cs b/src/core/DSharpPlus.Shared/Entities/Channels/DiscordMessageType.cs index c291911227..d71c5060a8 100644 --- a/src/core/DSharpPlus.Shared/Entities/Channels/DiscordMessageType.cs +++ b/src/core/DSharpPlus.Shared/Entities/Channels/DiscordMessageType.cs @@ -2,11 +2,11 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +#pragma warning disable CA1027 // this is not a flags enum. + namespace DSharpPlus.Entities; -#pragma warning disable CA1027 // this is not a flags enum. public enum DiscordMessageType -#pragma warning restore CA1027 { Default, RecipientAdd, @@ -38,5 +38,9 @@ public enum DiscordMessageType StageEnd, StageSpeaker, StageTopic = 31, - GuildApplicationPremiumSubscription + GuildApplicationPremiumSubscription, + GuildIncidentAlertModeEnabled = 36, + GuildIncidentAlertModeDisabled, + GuildIncidentReportRaid, + GuildIncidentReportFalseAlarm } diff --git a/src/core/DSharpPlus.Shared/Entities/MessageComponents/DiscordButtonStyle.cs b/src/core/DSharpPlus.Shared/Entities/MessageComponents/DiscordButtonStyle.cs index 9fd09778b8..1e08fa4d8f 100644 --- a/src/core/DSharpPlus.Shared/Entities/MessageComponents/DiscordButtonStyle.cs +++ b/src/core/DSharpPlus.Shared/Entities/MessageComponents/DiscordButtonStyle.cs @@ -32,5 +32,10 @@ public enum DiscordButtonStyle /// /// A gray button, navigating to an URL. /// - Link + Link, + + /// + /// A discord-blurple button directing an user to purchase an SKU. + /// + Premium } diff --git a/tools/generators/copy-concrete-implementations.csx b/tools/generators/copy-concrete-implementations.csx index 646bd7bf90..7248976237 100644 --- a/tools/generators/copy-concrete-implementations.csx +++ b/tools/generators/copy-concrete-implementations.csx @@ -35,9 +35,6 @@ AnsiConsole.MarkupLine ( """ [plum1]DSharpPlus Concrete Implementation Theft, v0.1.0[/] - - Extracts the required concrete types for DSharpPlus.Extensions.Internal.Builders to remove dependency on concrete implementations. - """ ); @@ -85,6 +82,15 @@ if (!changes.Added.Any() && !changes.Modified.Any() && !changes.Removed.Any()) return 0; } +AnsiConsole.MarkupLine +( + """ + + Extracts the required concrete types for DSharpPlus.Extensions.Internal.Builders to remove dependency on concrete implementations. + + """ +) + if (changes.Removed.Any()) { AnsiConsole.MarkupLine From b3f17f9abfbdfa5d9614ae41be87b376fdd1eaa6 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Wed, 31 Jul 2024 18:48:46 +0200 Subject: [PATCH 302/323] scalable permissions --- DSharpPlus.sln | 7 + Directory.Build.props | 2 +- Directory.Packages.props | 21 +- ...erviceCollectionExtensions.Registration.cs | 2 +- .../Converters/DiscordPermissionConverter.cs | 21 +- .../DSharpPlus.Shared.csproj | 1 + .../Entities/DiscordPermission.cs | 294 +++++++++++++ .../DiscordPermissions.Manipulation.cs | 196 +++++++++ .../Entities/DiscordPermissions.Utility.cs | 54 +++ .../Entities/DiscordPermissions.cs | 404 ++++++++++-------- .../Converters/DiscordPermissionTests.cs | 34 ++ .../DSharpPlus.Shared.Tests.csproj | 24 ++ .../Permissions/ConstructionTests.cs | 118 +++++ .../Permissions/EqualityTests.cs | 29 ++ .../Permissions/OperatorTests.cs | 141 ++++++ .../Permissions/ToStringTests.cs | 73 ++++ .../Permissions/UtilityTests.cs | 54 +++ 17 files changed, 1282 insertions(+), 193 deletions(-) create mode 100644 src/core/DSharpPlus.Shared/Entities/DiscordPermission.cs create mode 100644 src/core/DSharpPlus.Shared/Entities/DiscordPermissions.Manipulation.cs create mode 100644 src/core/DSharpPlus.Shared/Entities/DiscordPermissions.Utility.cs create mode 100644 tests/core/DSharpPlus.Internal.Models.Tests/Converters/DiscordPermissionTests.cs create mode 100644 tests/core/DSharpPlus.Shared.Tests/DSharpPlus.Shared.Tests.csproj create mode 100644 tests/core/DSharpPlus.Shared.Tests/Permissions/ConstructionTests.cs create mode 100644 tests/core/DSharpPlus.Shared.Tests/Permissions/EqualityTests.cs create mode 100644 tests/core/DSharpPlus.Shared.Tests/Permissions/OperatorTests.cs create mode 100644 tests/core/DSharpPlus.Shared.Tests/Permissions/ToStringTests.cs create mode 100644 tests/core/DSharpPlus.Shared.Tests/Permissions/UtilityTests.cs diff --git a/DSharpPlus.sln b/DSharpPlus.sln index 06591ada92..c6fa9254f4 100644 --- a/DSharpPlus.sln +++ b/DSharpPlus.sln @@ -29,6 +29,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Extensions", "Extensions", EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DSharpPlus.Extensions.Internal.Builders", "src\extensions\DSharpPlus.Extensions.Internal.Builders\DSharpPlus.Extensions.Internal.Builders.csproj", "{7A6F0CF2-2BB9-4AAC-95EC-8640A06DD17B}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DSharpPlus.Shared.Tests", "tests\core\DSharpPlus.Shared.Tests\DSharpPlus.Shared.Tests.csproj", "{E0EB9E13-D33A-4C2A-BB87-09D2B706597A}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -67,6 +69,10 @@ Global {7A6F0CF2-2BB9-4AAC-95EC-8640A06DD17B}.Debug|Any CPU.Build.0 = Debug|Any CPU {7A6F0CF2-2BB9-4AAC-95EC-8640A06DD17B}.Release|Any CPU.ActiveCfg = Release|Any CPU {7A6F0CF2-2BB9-4AAC-95EC-8640A06DD17B}.Release|Any CPU.Build.0 = Release|Any CPU + {E0EB9E13-D33A-4C2A-BB87-09D2B706597A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E0EB9E13-D33A-4C2A-BB87-09D2B706597A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E0EB9E13-D33A-4C2A-BB87-09D2B706597A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E0EB9E13-D33A-4C2A-BB87-09D2B706597A}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -81,6 +87,7 @@ Global {CD440954-E19A-4E94-A217-CCC1DC4AF095} = {BC8D8750-48A4-49EF-9D1F-BE4DBA5B500E} {9CEC3D27-9014-48B6-910F-D25233BF8C44} = {BC8D8750-48A4-49EF-9D1F-BE4DBA5B500E} {7A6F0CF2-2BB9-4AAC-95EC-8640A06DD17B} = {96A3D7EF-3576-423C-9529-60C8AE319C15} + {E0EB9E13-D33A-4C2A-BB87-09D2B706597A} = {21927A64-7345-4D90-9EE2-7FA4B1973AAC} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {55CDA684-8900-479B-9DAE-BA3BE09B337B} diff --git a/Directory.Build.props b/Directory.Build.props index fb1c86bac0..28e6c79a0a 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -9,7 +9,7 @@ True True All - $(NoWarn);CS1591;CA1028;CA1062;CA1308;CA1711;CA1716;CA1720;CA2007;CA2225 + $(NoWarn);CS1591;CA1028;CA1062;CA1308;CA1711;CA1716;CA1720;CA2007;CA2225;IDE0130 True diff --git a/Directory.Packages.props b/Directory.Packages.props index 1fdfa67df5..9b6435602d 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -1,23 +1,24 @@ - + - - + + - - - + + + + - - + + - - + + \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Models/Extensions/ServiceCollectionExtensions.Registration.cs b/src/core/DSharpPlus.Internal.Models/Extensions/ServiceCollectionExtensions.Registration.cs index ea69885e43..ed54e2ed15 100644 --- a/src/core/DSharpPlus.Internal.Models/Extensions/ServiceCollectionExtensions.Registration.cs +++ b/src/core/DSharpPlus.Internal.Models/Extensions/ServiceCollectionExtensions.Registration.cs @@ -151,4 +151,4 @@ private static void RegisterSerialization(IServiceCollection services) } ); } -} \ No newline at end of file +} diff --git a/src/core/DSharpPlus.Internal.Models/Serialization/Converters/DiscordPermissionConverter.cs b/src/core/DSharpPlus.Internal.Models/Serialization/Converters/DiscordPermissionConverter.cs index 219d7eea8b..f9607204d9 100644 --- a/src/core/DSharpPlus.Internal.Models/Serialization/Converters/DiscordPermissionConverter.cs +++ b/src/core/DSharpPlus.Internal.Models/Serialization/Converters/DiscordPermissionConverter.cs @@ -2,8 +2,12 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +#pragma warning disable IDE0072 + using System; +using System.Buffers; using System.Globalization; +using System.Numerics; using System.Text.Json; using System.Text.Json.Serialization; @@ -24,16 +28,15 @@ public override DiscordPermissions Read JsonSerializerOptions options ) { - if (reader.TokenType is not JsonTokenType.String or JsonTokenType.Number) + return reader.TokenType switch { - throw new JsonException("The provided permission value was provided in an unrecognized format."); - } - - string raw = reader.GetString()!; + JsonTokenType.String => !BigInteger.TryParse(reader.GetString()!, out BigInteger permissions) + ? throw new JsonException("The provided permission value could not be parsed.") + : new DiscordPermissions(permissions), - return !ulong.TryParse(raw, out ulong permissions) - ? throw new JsonException("The provided permission value could not be parsed.") - : (DiscordPermissions)permissions; + JsonTokenType.Number => new DiscordPermissions(new BigInteger(reader.GetUInt64())), + _ => throw new JsonException("The provided permission value was provided in an unrecognized format.") + }; } /// @@ -43,5 +46,5 @@ public override void Write DiscordPermissions value, JsonSerializerOptions options ) - => writer.WriteStringValue(((ulong)value).ToString(CultureInfo.InvariantCulture)); + => writer.WriteStringValue(value.ToString()); } diff --git a/src/core/DSharpPlus.Shared/DSharpPlus.Shared.csproj b/src/core/DSharpPlus.Shared/DSharpPlus.Shared.csproj index d845686479..362c701119 100644 --- a/src/core/DSharpPlus.Shared/DSharpPlus.Shared.csproj +++ b/src/core/DSharpPlus.Shared/DSharpPlus.Shared.csproj @@ -14,6 +14,7 @@ + diff --git a/src/core/DSharpPlus.Shared/Entities/DiscordPermission.cs b/src/core/DSharpPlus.Shared/Entities/DiscordPermission.cs new file mode 100644 index 0000000000..7962972e10 --- /dev/null +++ b/src/core/DSharpPlus.Shared/Entities/DiscordPermission.cs @@ -0,0 +1,294 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +#pragma warning disable CA1027 + +using System.ComponentModel.DataAnnotations; + +using NetEscapades.EnumGenerators; + +namespace DSharpPlus.Entities; + +/// +/// Represents a single discord permission. +/// +[EnumExtensions] +public enum DiscordPermission +{ + /// + /// Allows members to create invites. + /// + [Display(Name = "Create Invites")] + CreateInvite = 0, + + /// + /// Allows members to kick others, limited by role hierarchy. + /// + [Display(Name = "Kick Members")] + KickMembers = 1, + + /// + /// Allows members to ban others, limited by role hierarchy. + /// + [Display(Name = "Ban Members")] + BanMembers = 2, + + /// + /// Administrator permission. Overrides every other permission, allows bypassing channel-specific restrictions. + /// + [Display(Name = "Administrator")] + Administrator = 3, + + /// + /// Allows members to create, edit and delete channels. + /// + [Display(Name = "Manage Channels")] + ManageChannels = 4, + + /// + /// Allows members to change (most) guild settings. + /// + [Display(Name = "Manage Guild")] + ManageGuild = 5, + + /// + /// Allows members to add a reaction to a message. + /// + [Display(Name = "Add Reactions")] + AddReactions = 6, + + /// + /// Allows members to access the guild's audit logs. + /// + [Display(Name = "View Audit Log")] + ViewAuditLog = 7, + + /// + /// Allows members to use Priority Speaker functionality. + /// + [Display(Name = "Priority Speaker")] + PrioritySpeaker = 8, + + /// + /// Allows members to go live in voice channels. + /// + [Display(Name = "Stream")] + Stream = 9, + + /// + /// Allows members to view (read) channels. + /// + [Display(Name = "View Channel")] + ViewChannel = 10, + + /// + /// Allows members to send messages in channels and to create threads in a forum channel. + /// + [Display(Name = "Send Messages")] + SendMessages = 11, + + /// + /// Allows members to send text-to-speech messages. + /// + [Display(Name = "Send Text-to-speech Messages")] + SendTTSMessages = 12, + + /// + /// Allows members to delete other's messages. + /// + [Display(Name = "Manage Messages")] + ManageMessages = 13, + + /// + /// Allows members' messages to embed sent links. + /// + [Display(Name = "Embed Links")] + EmbedLinks = 14, + + /// + /// Allows members to attach files. + /// + [Display(Name = "Attach Files")] + AttachFiles = 15, + + /// + /// Allows members to read a channels' message history. + /// + [Display(Name = "Read Message History")] + ReadMessageHistory = 16, + + /// + /// Allows members to mention @everyone, @here and all roles. + /// + [Display(Name = "Mention Everyone")] + MentionEveryone = 17, + + /// + /// Allows members to use emojis from other guilds. + /// + [Display(Name = "Use External Emojis")] + UseExternalEmojis = 18, + + /// + /// Allows members to access and view the Guild Insights menu. + /// + [Display(Name = "View Guild Insights")] + ViewGuildInsights = 19, + + /// + /// Allows members to connect to voice channels. + /// + [Display(Name = "Connect")] + Connect = 20, + + /// + /// Allows members to speak in voice channels. + /// + [Display(Name = "Speak")] + Speak = 21, + + /// + /// Allows members to mute others in voice channels. + /// + [Display(Name = "Mute Members")] + MuteMembers = 22, + + /// + /// Allows members to deafen others in voice channels. + /// + [Display(Name = "Deafen Members")] + DeafenMembers = 23, + + /// + /// Allows members to move others between voice channels they have access to. + /// + [Display(Name = "Move Members")] + MoveMembers = 24, + + /// + /// Allows members to use voice activity detection instead of push-to-talk. + /// + [Display(Name = "Use Voice Activity Detection")] + UseVoiceActivity = 25, + + /// + /// Allows members to change their own nickname. + /// + [Display(Name = "Change Nickname")] + ChangeNickname = 26, + + /// + /// Allows members to change and remove other's nicknames. + /// + [Display(Name = "Manage Nicknames")] + ManageNicknames = 27, + + /// + /// Allows members to create, change and grant roles lower than their highest role. + /// + [Display(Name = "Manage Roles")] + ManageRoles = 28, + + /// + /// Allows members to create and delete webhooks. + /// + [Display(Name = "Manage Webhooks")] + ManageWebhooks = 29, + + /// + /// Allows members to manage guild emojis and stickers. + /// + [Display(Name = "Manage Guild Expressions")] + ManageGuildExpressions = 30, + + /// + /// Allows members to use slash and right-click commands. + /// + [Display(Name = "Use Application Commands")] + UseApplicationCommands = 31, + + /// + /// Allows members to request to speak in stage channels. + /// + [Display(Name = "Request to Speak")] + RequestToSpeak = 32, + + /// + /// Allows members to create, edit and delete events. + /// + [Display(Name = "Manage Events")] + ManageEvents = 33, + + /// + /// Allows members to manage threads. + /// + [Display(Name = "Manage Threads")] + ManageThreads = 34, + + /// + /// Allows members to create public threads. + /// + [Display(Name = "Create Public Threads")] + CreatePublicThreads = 35, + + /// + /// Allows members to create private threads. + /// + [Display(Name = "Create Private Threads")] + CreatePrivateThreads = 36, + + /// + /// Allows members to use stickers from other guilds. + /// + [Display(Name = "Use External Stickers")] + UseExternalStickers = 37, + + /// + /// Allows members to send messages in threads. + /// + [Display(Name = "Send Messages in Threads")] + SendThreadMessages = 38, + + /// + /// Allows members to start embedded activities. + /// + [Display(Name = "Start Embedded Activities")] + StartEmbeddedActivities = 39, + + /// + /// Allows members to time out other members. + /// + [Display(Name = "Moderate Members")] + ModerateMembers = 40, + + /// + /// Allows members to view role subscription insights. + /// + [Display(Name = "View Creator Monetization Analytics")] + ViewCreatorMonetizationAnalytics = 41, + + /// + /// Allows members to use the soundboard in a voice channel. + /// + [Display(Name = "Use Soundboard")] + UseSoundboard = 42, + + /// + /// Allows members to send voice messages. + /// + [Display(Name = "Send Voice Messages")] + SendVoiceMessages = 46, + + /// + /// Allows members to send polls. + /// + [Display(Name = "Send Polls")] + SendPolls = 49, + + /// + /// Allows members to use external, user-installable apps. + /// + [Display(Name = "Use External Apps")] + UseExternalApps = 50 +} diff --git a/src/core/DSharpPlus.Shared/Entities/DiscordPermissions.Manipulation.cs b/src/core/DSharpPlus.Shared/Entities/DiscordPermissions.Manipulation.cs new file mode 100644 index 0000000000..63377b3c0a --- /dev/null +++ b/src/core/DSharpPlus.Shared/Entities/DiscordPermissions.Manipulation.cs @@ -0,0 +1,196 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; +using System.Runtime.Intrinsics; + +namespace DSharpPlus.Entities; + +// contains the code for manipulating DiscordPermissions, via operators and method calls. all of these are copying operations. + +partial struct DiscordPermissions +{ + // ADD-REMOVE + // add is equivalent to or, remove is an and-not operation + + /// + /// Adds a permission to this permission set. + /// + /// The permission field to add. + /// A new permission set containing all previous permissions along with the new permission. + public DiscordPermissions Add(DiscordPermission permission) + => new(this.AsSpan, [permission], []); + + /// + /// Adds multiple permissions to this permission set. + /// + /// The permission fields to add. + /// A new permission set containing all previous permissions along with the new permissions. + public DiscordPermissions Add(params ReadOnlySpan permissions) + => new(this.AsSpan, permissions, []); + + /// + /// Adds the specified permission to the permission set. + /// + public static DiscordPermissions operator +(DiscordPermissions value, DiscordPermission add) => value.Add(add); + + /// + /// Removes a permission from this permission set. + /// + /// The permission field to remove. + /// A new permission set containing all previous permissions except the specified permission. + public DiscordPermissions Remove(DiscordPermission permission) + => new(this.AsSpan, [], [permission]); + + /// + /// Removes multiple permission from this permission set. + /// + /// The permission fields to remove. + /// A new permission set containing all previous permissions except the specified permissions. + public DiscordPermissions Remove(params ReadOnlySpan permissions) + => new(this.AsSpan, [], permissions); + + /// + /// Removes the specified permission from a permission set. + /// + public static DiscordPermissions operator -(DiscordPermissions value, DiscordPermission remove) => value.Remove(remove); + + /// + /// Removes all permissions specified in the right-hand set from the left-hand set and returns the new permission set. + /// + public static DiscordPermissions operator -(DiscordPermissions left, DiscordPermissions right) + { + ReadOnlySpan current = left.AsSpan; + ReadOnlySpan other = right.AsSpan; + Span result = stackalloc byte[ContainerByteCount]; + + for (int i = 0; i < ContainerByteCount; i += 16) + { + Vector128 v1 = Vector128.LoadUnsafe(in current[i]); + Vector128 v2 = Vector128.LoadUnsafe(in other[i]); + + Vector128 removed = Vector128.AndNot(v1, v2); + removed.StoreUnsafe(ref result[i]); + } + + return new(result); + } + + // OR + // we can short-circuit single-flag OR into Add + + /// + /// Adds the specified permission to the permission set. + /// + public static DiscordPermissions operator |(DiscordPermissions value, DiscordPermission flag) => value.Add(flag); + + /// + /// Merges both permission sets into one, taking all set permissions from both. + /// + public static DiscordPermissions operator |(DiscordPermissions left, DiscordPermissions right) + { + ReadOnlySpan current = left.AsSpan; + ReadOnlySpan other = right.AsSpan; + Span result = stackalloc byte[ContainerByteCount]; + + for (int i = 0; i < ContainerByteCount; i += 16) + { + Vector128 v1 = Vector128.LoadUnsafe(in current[i]); + Vector128 v2 = Vector128.LoadUnsafe(in other[i]); + + Vector128 or = Vector128.BitwiseOr(v1, v2); + or.StoreUnsafe(ref result[i]); + } + + return new(result); + } + + // AND + + /// + /// Returns a permission set containing either no value if the flag was not found, or exactly the specified flag if it was. + /// + public static DiscordPermissions operator &(DiscordPermissions value, DiscordPermission flag) + => value & (DiscordPermissions)flag; + + /// + /// Performs a bitwise AND between the two permission sets. + /// + public static DiscordPermissions operator &(DiscordPermissions left, DiscordPermissions right) + { + ReadOnlySpan current = left.AsSpan; + ReadOnlySpan other = right.AsSpan; + Span result = stackalloc byte[ContainerByteCount]; + + for (int i = 0; i < ContainerByteCount; i += 16) + { + Vector128 v1 = Vector128.LoadUnsafe(in current[i]); + Vector128 v2 = Vector128.LoadUnsafe(in other[i]); + + Vector128 and = Vector128.BitwiseAnd(v1, v2); + and.StoreUnsafe(ref result[i]); + } + + return new(result); + } + + // XOR + + /// + /// Toggles the specified flag in the permission set. + /// + public static DiscordPermissions operator ^(DiscordPermissions value, DiscordPermission flag) + { + bool currentFlagValue = value.GetFlag((int)flag); + bool newFlagValue = currentFlagValue ^ true; + + return new(value, (int)flag, newFlagValue); + } + + /// + /// Performs a bitwise XOR operation between the two permission sets. + /// + public static DiscordPermissions operator ^(DiscordPermissions left, DiscordPermissions right) + { + ReadOnlySpan current = left.AsSpan; + ReadOnlySpan other = right.AsSpan; + Span result = stackalloc byte[ContainerByteCount]; + + for (int i = 0; i < ContainerByteCount; i += 16) + { + Vector128 v1 = Vector128.LoadUnsafe(in current[i]); + Vector128 v2 = Vector128.LoadUnsafe(in other[i]); + + Vector128 xor = Vector128.Xor(v1, v2); + xor.StoreUnsafe(ref result[i]); + } + + return new(result); + } + + // NOT + + /// + /// Negates the specified permission set. + /// + /// + /// Since is a normal flag for the intents and purposes of this method, + /// it is recommended to be careful uploading return values to the Discord API. + /// + public static DiscordPermissions operator ~(DiscordPermissions value) + { + ReadOnlySpan current = value.AsSpan; + Span result = stackalloc byte[ContainerByteCount]; + + for (int i = 0; i < ContainerByteCount; i += 16) + { + Vector128 vec = Vector128.LoadUnsafe(in current[i]); + + Vector128 not = ~vec; + not.StoreUnsafe(ref result[i]); + } + + return new(result); + } +} diff --git a/src/core/DSharpPlus.Shared/Entities/DiscordPermissions.Utility.cs b/src/core/DSharpPlus.Shared/Entities/DiscordPermissions.Utility.cs new file mode 100644 index 0000000000..139cba0b1c --- /dev/null +++ b/src/core/DSharpPlus.Shared/Entities/DiscordPermissions.Utility.cs @@ -0,0 +1,54 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; + +namespace DSharpPlus.Entities; + +partial struct DiscordPermissions +{ + /// + /// Toggles the specified permission between states. + /// + public DiscordPermissions Toggle(DiscordPermission permission) + => this ^ permission; + + /// + /// Toggles all of the specified permissions between states. + /// + public DiscordPermissions Toggle(params ReadOnlySpan permissions) + => this ^ new DiscordPermissions(permissions); + + /// + /// Returns whether the specified permission is set explicitly. + /// + public bool HasFlag(DiscordPermission flag) + => GetFlag((int)flag); + + /// + /// Returns whether the specified permission is granted, either directly or through Administrator permissions. + /// + public bool HasPermission(DiscordPermission permission) + => this.HasFlag(DiscordPermission.Administrator) || this.HasFlag(permission); + + /// + /// Returns whether any of the specified permissions are granted, either directly or through Administrator permissions. + /// + public bool HasAnyPermission(params ReadOnlySpan permissions) + => this.HasFlag(DiscordPermission.Administrator) || (this & new DiscordPermissions(permissions)) != None; + + /// + /// Returns whether all of the specified permissions are gratned, either directly or through Administrator permissions. + /// + public bool HasAllPermissions(params ReadOnlySpan permissions) + { + if (this.HasFlag(DiscordPermission.Administrator)) + { + return true; + } + + DiscordPermissions expected = new(permissions); + return (this & expected) == expected; + } +} diff --git a/src/core/DSharpPlus.Shared/Entities/DiscordPermissions.cs b/src/core/DSharpPlus.Shared/Entities/DiscordPermissions.cs index d74e500bee..6492fe57f0 100644 --- a/src/core/DSharpPlus.Shared/Entities/DiscordPermissions.cs +++ b/src/core/DSharpPlus.Shared/Entities/DiscordPermissions.cs @@ -3,242 +3,302 @@ // file, You can obtain one at https://mozilla.org/MPL/2.0/. using System; +using System.Buffers.Binary; +using System.Collections.Generic; +using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; +using System.Globalization; +using System.Numerics; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Runtime.Intrinsics; +using System.Text; + +using CommunityToolkit.HighPerformance.Helpers; + +using HashCode = CommunityToolkit.HighPerformance.Helpers.HashCode; namespace DSharpPlus.Entities; /// -/// Represents discord permissions - role permission, channel overwrites. +/// Represents a set of Discord permissions. /// -[Flags] -public enum DiscordPermissions : ulong +/// +/// This type expects to be zero-initialized. Using this type in [SkipLocalsInit] contexts may be dangerous. +/// +public readonly partial struct DiscordPermissions + : IEquatable { - /// - /// No permissions. - /// - None = 0, + // only change ContainerWidth here, the other two constants are automatically updated for internal uses + // for ContainerWidth, 1 width == 128 bits. + private const int ContainerWidth = 1; + private const int ContainerElementCount = ContainerWidth * 4; + private const int ContainerByteCount = ContainerWidth * 16; - /// - /// Allows members to create invites. - /// - CreateInvite = 1 << 0, + private readonly DiscordPermissionContainer data; /// - /// Allows members to kick others, limited by role hierarchy. + /// Creates a new instance of this type from exactly the specified permission. /// - KickMembers = 1 << 1, + public DiscordPermissions(DiscordPermission permission) + => this.data.SetFlag((int)permission, true); /// - /// Allows members to ban others, limited by role hierarchy. + /// Creates a new instance of this type from the specified permissions. /// - BanMembers = 1 << 2, + public DiscordPermissions(params ReadOnlySpan permissions) + { + foreach (DiscordPermission permission in permissions) + { + this.data.SetFlag((int)permission, true); + } + } /// - /// Administrator permission. Overrides every other permission, allows bypassing channel-specific restrictions. + /// Creates a new instance of this type from the specified big integer. This assumes that the data is unsigned. /// - Administrator = 1 << 3, + public DiscordPermissions(BigInteger permissionSet) + { + Span buffer = MemoryMarshal.Cast(MemoryMarshal.CreateSpan(ref this.data[0], ContainerElementCount)); - /// - /// Allows members to create, edit and delete channels. - /// - ManageChannels = 1 << 4, + if (!permissionSet.TryWriteBytes(buffer, out _, isUnsigned: true)) + { + // we don't want to fail in release mode, which would break perfectly working code because the library + // hasn't been updated to support a new permission or because Discord is testing in prod again. + // seeing this assertion in dev should be an indication to expand this type. + Debug.Assert(false, "The amount of permissions DSharpPlus can represent has been exceeded."); + } + } /// - /// Allows members to change (most) guild settings. + /// Creates a new instance of this type from the specified raw data. This assumes that the data is unsigned. /// - ManageGuild = 1 << 5, + public DiscordPermissions(scoped ReadOnlySpan raw) + { + Span buffer = MemoryMarshal.Cast(MemoryMarshal.CreateSpan(ref this.data[0], ContainerElementCount * 4)); - /// - /// Allows members to add a reaction to a message. - /// - AddReactions = 1 << 6, + if (!raw.TryCopyTo(buffer)) + { + // we don't want to fail in release mode, which would break perfectly working code because the library + // hasn't been updated to support a new permission or because Discord is testing in prod again. + // seeing this assertion in dev should be an indication to expand this type. + Debug.Assert(false, "The amount of permissions DSharpPlus can represent has been exceeded."); + } + } /// - /// Allows members to access the guild's audit logs. + /// A copy constructor that sets an arbitrary amount of flags to their respective values. /// - ViewAuditLog = 1 << 7, + private DiscordPermissions + ( + scoped ReadOnlySpan raw, + ReadOnlySpan setPermissions, + ReadOnlySpan removePermissions + ) + : this(raw) + { + foreach (DiscordPermission permission in setPermissions) + { + this.data.SetFlag((int)permission, true); + } - /// - /// Allows members to use Priority Speaker functionality. - /// - PrioritySpeaker = 1 << 8, + foreach (DiscordPermission permission in removePermissions) + { + this.data.SetFlag((int)permission, false); + } + } /// - /// Allows members to go live in voice channels. + /// A copy constructor that sets one specific flag to the specified value. /// - Stream = 1 << 9, + private DiscordPermissions(DiscordPermissions original, int index, bool flag) + : this(original.AsSpan) + => this.data.SetFlag(index, flag); - /// - /// Allows members to view (read) channels. - /// - ViewChannel = 1 << 10, + public static implicit operator DiscordPermissions(DiscordPermission initial) => new(initial); /// - /// Allows members to send messages in channels and to create threads in a forum channel. + /// Returns an empty Discord permission set. /// - SendMessages = 1 << 11, + public static DiscordPermissions None => default; /// - /// Allows members to send text-to-speech messages. + /// Returns a full Discord permission set with all flags set to true. /// - SendTTSMessages = 1 << 12, + public static DiscordPermissions AllBitsSet + { + get + { + Span result = stackalloc byte[ContainerByteCount]; - /// - /// Allows members to delete other's messages. - /// - ManageMessages = 1 << 13, + for (int i = 0; i < ContainerElementCount; i += 16) + { + Vector128.StoreUnsafe(Vector128.AllBitsSet, ref result[i]); + } - /// - /// Allows members' messages to embed sent links. - /// - EmbedLinks = 1 << 14, + return new(result); + } + } /// - /// Allows members to attach files. + /// Returns a Discord permission set with all documented permissions set to true. /// - AttachFiles = 1 << 15, + public static DiscordPermissions All { get; } = new(DiscordPermissionExtensions.GetValues()); - /// - /// Allows members to read a channels' message history. - /// - ReadMessageHistory = 1 << 16, + private ReadOnlySpan AsSpan + => MemoryMarshal.Cast(MemoryMarshal.CreateReadOnlySpan(in this.data[0], ContainerElementCount)); - /// - /// Allows members to mention @everyone, @here and all roles. - /// - MentionEveryone = 1 << 17, + private bool GetFlag(int index) + => this.data.HasFlag(index); /// - /// Allows members to use emojis from other guilds. + /// Determines whether this Discord permission set is equal to the provided object. /// - UseExternalEmojis = 1 << 18, + public override bool Equals([NotNullWhen(true)] object? obj) + => obj is DiscordPermissions permissions && this.Equals(permissions); /// - /// Allows members to access and view the Guild Insights menu. + /// Determines whether this Discord permission set is equal to the provided Discord permission set. /// - ViewGuildInsights = 1 << 19, + public bool Equals(DiscordPermissions other) + { + for (int i = 0; i < ContainerElementCount; i += 4) + { + Vector128 current = Vector128.LoadUnsafe(in this.data[i]); + Vector128 comparison = Vector128.LoadUnsafe(in other.data[i]); - /// - /// Allows members to connect to voice channels. - /// - Connect = 1 << 20, + if (current != comparison) + { + return false; + } + } - /// - /// Allows members to speak in voice channels. - /// - Speak = 1 << 21, + return true; + } /// - /// Allows members to mute others in voice channels. + /// Returns a string representation of this permission set. /// - MuteMembers = 1 << 22, + public override string ToString() => this.ToString("a placeholder format string that doesn't do anything"); /// - /// Allows members to deafen others in voice channels. + /// Returns a string representation of this permission set, according to the provided format string. /// - DeafenMembers = 1 << 23, + /// + /// Specifies the format in which the string should be created. Currently supported formats are:
+ /// - raw: This prints the raw, byte-wise backing data of this instance.
+ /// - name: This prints each flag by name, separated by commas.
+ /// - anything else will print the integer value contained in this instance. + /// + public string ToString(string format) + { + if (format == "raw") + { + StringBuilder builder = new("DiscordPermissions - raw value:"); - /// - /// Allows members to move others between voice channels they have access to. - /// - MoveMembers = 1 << 24, + foreach (byte b in this.AsSpan) + { + _ = builder.Append(' '); + _ = builder.Append(b.ToString("x2", CultureInfo.InvariantCulture)); + } - /// - /// Allows members to use voice activity detection instead of push-to-talk. - /// - UseVoiceActivity = 1 << 25, + return builder.ToString(); + } + else if (format == "name") + { + StringBuilder builder = new(); - /// - /// Allows members to change their own nickname. - /// - ChangeNickname = 1 << 26, + foreach (DiscordPermission permission in EnumeratePermissions()) + { + _ = builder.Append(permission.ToStringFast()); + _ = builder.Append(", "); + } - /// - /// Allows members to change and remove other's nicknames. - /// - ManageNicknames = 1 << 27, + return builder.ToString().TrimEnd(", "); + } + else + { + Span buffer = stackalloc byte[ContainerElementCount * 4]; + this.AsSpan.CopyTo(buffer); - /// - /// Allows members to create, change and grant roles lower than their highest role. - /// - ManageRoles = 1 << 28, + if (!BitConverter.IsLittleEndian) + { + Span bigEndianWorkaround = MemoryMarshal.Cast(buffer); + BinaryPrimitives.ReverseEndianness(bigEndianWorkaround, bigEndianWorkaround); + } - /// - /// Allows members to create and delete webhooks. - /// - ManageWebhooks = 1 << 29, + return new BigInteger(buffer, true, false).ToString(CultureInfo.InvariantCulture); + } + } /// - /// Allows members to manage guild emojis and stickers. + /// Calculates a hash code for this Discord permission set. The hash code is only guaranteed to be consistent + /// within a process, and sharing this data across process boundaries is dangerous. /// - ManageEmojisStickers = 1 << 30, + public override int GetHashCode() + => HashCode.Combine(MemoryMarshal.Cast(MemoryMarshal.CreateReadOnlySpan(in this.data[0], ContainerElementCount))); - /// - /// Allows members to use slash and right-click commands. - /// - UseApplicationCommands = 1L << 31, - - /// - /// Allows members to request to speak in stage channels. - /// - RequestToSpeak = 1L << 32, - - /// - /// Allows members to create, edit and delete events. - /// - ManageEvents = 1L << 33, - - /// - /// Allows members to manage threads. - /// - ManageThreads = 1L << 34, - - /// - /// Allows members to create public threads. - /// - CreatePublicThreads = 1L << 35, - - /// - /// Allows members to create private threads. - /// - CreatePrivateThreads = 1L << 36, - - /// - /// Allows members to use stickers from other guilds. - /// - UseExternalStickers = 1L << 37, - - /// - /// Allows members to send messages in threads. - /// - SendThreadMessages = 1L << 38, - - /// - /// Allows members to start embedded activities. - /// - StartEmbeddedActivities = 1L << 39, - - /// - /// Allows members to time out other members. - /// - ModerateMembers = 1L << 40, - - /// - /// Allows members to view role subscription insights. - /// - ViewCreatorMonetizationAnalytics = 1L << 41, - - /// - /// Allows members to use the soundboard in a voice channel. - /// - UseSoundboard = 1L << 42, - - /// - /// Allows members to send voice messages. - /// - SendVoiceMessages = 1L << 46, - - /// - /// Allows members to send polls. - /// - SendPolls = 1L << 49 + public IEnumerable EnumeratePermissions() + { + for (int block = 0; block < ContainerElementCount; block++) + { + uint value = this.data[block]; + + for (int bit = 0; bit < 32; bit++) + { + if (BitHelper.HasFlag(value, bit)) + { + yield return (DiscordPermission)(32 * block) + bit; + } + } + } + + yield break; + } + + public static bool operator ==(DiscordPermissions left, DiscordPermissions right) => left.Equals(right); + public static bool operator !=(DiscordPermissions left, DiscordPermissions right) => !(left == right); + + // we will be using an inline array from the start here so that further increases in the bit width + // only require increasing this number instead of switching to a new backing implementation strategy. + // if Discord changes the way permissions are represented in the API, this will obviously have to change. + // + // this should always be backed by a 32-bit integer, to make our life easier around popcnt and BitHelper. + // + /// + /// Represents a container for the backing storage of Discord permissions. + /// + [InlineArray(ContainerElementCount)] + private struct DiscordPermissionContainer + { + public uint value; + + /// + /// Sets a specified flag to the specific value. This function fails in debug mode if the flag was out of range. + /// + public void SetFlag(int index, bool value) + { + int fieldIndex = index >> 5; + + Debug.Assert(fieldIndex < ContainerElementCount); + + int bitIndex = index & 0x1F; + ref uint segment = ref this[fieldIndex]; + BitHelper.SetFlag(ref segment, bitIndex, value); + } + + /// + /// Returns the value of a specified flag. This function fails in debug mode if the flag was out of range. + /// + public readonly bool HasFlag(int index) + { + int fieldIndex = index >> 5; + + Debug.Assert(fieldIndex < ContainerElementCount); + + int bitIndex = index & 0x1F; + uint segment = this[fieldIndex]; + return BitHelper.HasFlag(segment, bitIndex); + } + } } diff --git a/tests/core/DSharpPlus.Internal.Models.Tests/Converters/DiscordPermissionTests.cs b/tests/core/DSharpPlus.Internal.Models.Tests/Converters/DiscordPermissionTests.cs new file mode 100644 index 0000000000..45187c5587 --- /dev/null +++ b/tests/core/DSharpPlus.Internal.Models.Tests/Converters/DiscordPermissionTests.cs @@ -0,0 +1,34 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +#pragma warning disable IDE0058 + +using System.Text.Json; + +using DSharpPlus.Entities; +using DSharpPlus.Internal.Models.Serialization.Converters; + +using Xunit; + +namespace DSharpPlus.Internal.Models.Tests.Converters; + +public class DiscordPermissionTests +{ + private readonly JsonSerializerOptions options; + + public DiscordPermissionTests() + { + this.options = new(); + this.options.Converters.Add(new DiscordPermissionConverter()); + } + + [Fact] + public void DeserializePermissions() + { + DiscordPermissions expected = new(DiscordPermission.PrioritySpeaker); + DiscordPermissions actual = JsonSerializer.Deserialize("256", this.options); + + Assert.Equal(expected, actual); + } +} diff --git a/tests/core/DSharpPlus.Shared.Tests/DSharpPlus.Shared.Tests.csproj b/tests/core/DSharpPlus.Shared.Tests/DSharpPlus.Shared.Tests.csproj new file mode 100644 index 0000000000..34a3846b99 --- /dev/null +++ b/tests/core/DSharpPlus.Shared.Tests/DSharpPlus.Shared.Tests.csproj @@ -0,0 +1,24 @@ + + + + net9.0 + enable + + false + true + $(NoWarn);CA1515;CA1707 + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + diff --git a/tests/core/DSharpPlus.Shared.Tests/Permissions/ConstructionTests.cs b/tests/core/DSharpPlus.Shared.Tests/Permissions/ConstructionTests.cs new file mode 100644 index 0000000000..fd33b3f4a4 --- /dev/null +++ b/tests/core/DSharpPlus.Shared.Tests/Permissions/ConstructionTests.cs @@ -0,0 +1,118 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; +using System.Numerics; + +using DSharpPlus.Entities; + +using Xunit; + +namespace DSharpPlus.Shared.Tests.Permissions; + +public class ConstructionTests +{ + private static ReadOnlySpan FirstBit => + [ + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 + ]; + + private static ReadOnlySpan FirstTwoBits => + [ + 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 + ]; + + private static ReadOnlySpan ThirtyThirdBit => + [ + 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 + ]; + + [Fact] + public void FirstBitSetCorrectly_Constructor() + { + DiscordPermissions permissions = new(DiscordPermission.CreateInvite); + DiscordPermissions expected = new(FirstBit); + + Assert.Equal(expected, permissions); + } + + [Fact] + public void FirstBitSetCorrectly_Add() + { + DiscordPermissions permissions = DiscordPermissions.None.Add(DiscordPermission.CreateInvite); + DiscordPermissions expected = new(FirstBit); + + Assert.Equal(expected, permissions); + } + + [Fact] + public void FirstTwoBitsSetCorrectly_Constructor() + { + DiscordPermissions permissions = new(DiscordPermission.CreateInvite, DiscordPermission.KickMembers); + DiscordPermissions expected = new(FirstTwoBits); + + Assert.Equal(expected, permissions); + } + + [Fact] + public void FirstTwoBitsSetCorrectly_Add() + { + DiscordPermissions permissions = DiscordPermissions.None + .Add(DiscordPermission.CreateInvite) + .Add(DiscordPermission.KickMembers); + DiscordPermissions expected = new(FirstTwoBits); + + Assert.Equal(expected, permissions); + } + + [Fact] + public void FirstTwoBitsSetCorrectly_AddMultiple() + { + DiscordPermissions permissions = DiscordPermissions.None + .Add(DiscordPermission.CreateInvite, DiscordPermission.KickMembers); + DiscordPermissions expected = new(FirstTwoBits); + + Assert.Equal(expected, permissions); + } + + [Fact] + public void TestUnderlyingUInt32Rollover() + { + DiscordPermissions permissions = new(DiscordPermission.RequestToSpeak, DiscordPermission.CreateInvite); + DiscordPermissions expected = new(ThirtyThirdBit); + + Assert.Equal(expected, permissions); + } + + [Fact] + public void FirstBitSetCorrectly_BigInteger() + { + BigInteger bigint = new(1); + DiscordPermissions permissions = new(bigint); + DiscordPermissions expected = new(FirstBit); + + Assert.Equal(expected, permissions); + } + + [Fact] + public void ThirtyThirdBitSetCorrectly_BigInteger() + { + BigInteger bigint = new(4294967297); + DiscordPermissions permissions = new(bigint); + DiscordPermissions expected = new(ThirtyThirdBit); + + Assert.Equal(expected, permissions); + } + + [Fact] + public void OpImplicit() + { + DiscordPermissions expected = new(FirstBit); + + Assert.Equal(expected, DiscordPermission.CreateInvite); + } +} diff --git a/tests/core/DSharpPlus.Shared.Tests/Permissions/EqualityTests.cs b/tests/core/DSharpPlus.Shared.Tests/Permissions/EqualityTests.cs new file mode 100644 index 0000000000..1c3b158c4c --- /dev/null +++ b/tests/core/DSharpPlus.Shared.Tests/Permissions/EqualityTests.cs @@ -0,0 +1,29 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; + +using DSharpPlus.Entities; + +using Xunit; + +namespace DSharpPlus.Shared.Tests.Permissions; + +public class EqualityTests +{ + private static ReadOnlySpan FirstBit => + [ + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 + ]; + + [Fact] + public void EqualsCorrect_OneBit() + { + DiscordPermissions permissions = new(DiscordPermission.CreateInvite); + DiscordPermissions expected = new(FirstBit); + + Assert.True(expected.Equals(permissions)); + } +} diff --git a/tests/core/DSharpPlus.Shared.Tests/Permissions/OperatorTests.cs b/tests/core/DSharpPlus.Shared.Tests/Permissions/OperatorTests.cs new file mode 100644 index 0000000000..b2bc31aacd --- /dev/null +++ b/tests/core/DSharpPlus.Shared.Tests/Permissions/OperatorTests.cs @@ -0,0 +1,141 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; + +using DSharpPlus.Entities; + +using Xunit; + +namespace DSharpPlus.Shared.Tests.Permissions; + +public class OperatorTests +{ + public static ReadOnlySpan AllButFirstBit => + [ + 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF + ]; + + [Fact] + public void TestRemove_SingleBit() + { + DiscordPermissions permissions = new(DiscordPermission.CreateInvite); + permissions = permissions.Remove(DiscordPermission.CreateInvite); + + Assert.Equal(DiscordPermissions.None, permissions); + + permissions = new(DiscordPermission.CreateInvite); + Assert.Equal(DiscordPermissions.None, permissions - DiscordPermission.CreateInvite); + } + + [Fact] + public void TestRemove_Bulk() + { + DiscordPermissions permissions = new(DiscordPermission.CreateInvite, DiscordPermission.BanMembers); + permissions = permissions.Remove(DiscordPermission.CreateInvite, DiscordPermission.BanMembers); + + Assert.Equal(DiscordPermissions.None, permissions); + } + + [Fact] + public void TestRemove_Set() + { + DiscordPermissions permissions = new(DiscordPermission.CreateInvite, DiscordPermission.BanMembers); + DiscordPermissions remove = new(DiscordPermission.CreateInvite); + + Assert.Equal(DiscordPermission.BanMembers, permissions - remove); + } + + [Fact] + public void TestOr_Flag() + { + DiscordPermissions permissions = new(DiscordPermission.CreateInvite); + DiscordPermissions two = permissions | DiscordPermission.BanMembers; + + Assert.Equal(new(DiscordPermission.CreateInvite, DiscordPermission.BanMembers), two); + } + + [Fact] + public void TestOr_Set() + { + DiscordPermissions one = new(DiscordPermission.AddReactions); + DiscordPermissions two = new(DiscordPermission.Administrator); + + DiscordPermissions actual = one | two; + + Assert.Equal(new(DiscordPermission.AddReactions, DiscordPermission.Administrator), actual); + } + + [Fact] + public void TestAnd_Flag() + { + DiscordPermissions permissions = new(DiscordPermission.Administrator, DiscordPermission.Connect); + Assert.Equal(DiscordPermission.Administrator, permissions & DiscordPermission.Administrator); + } + + [Fact] + public void TestAnd_Set() + { + DiscordPermissions permissions = new + ( + DiscordPermission.Administrator, + DiscordPermission.ChangeNickname, + DiscordPermission.CreatePublicThreads, + DiscordPermission.Speak + ); + + DiscordPermissions mask = new + ( + DiscordPermission.Administrator, + DiscordPermission.CreateInvite + ); + + Assert.Equal(DiscordPermission.Administrator, permissions & mask); + } + + [Fact] + public void TestXor_Flag() + { + DiscordPermissions permissions = new(DiscordPermission.Administrator, DiscordPermission.Connect); + Assert.Equal(DiscordPermission.Connect, permissions ^ DiscordPermission.Administrator); + } + + [Fact] + public void TestXor_Set() + { + DiscordPermissions permissions = new + ( + DiscordPermission.Administrator, + DiscordPermission.ChangeNickname, + DiscordPermission.CreatePublicThreads, + DiscordPermission.Speak + ); + + DiscordPermissions mask = new + ( + DiscordPermission.Administrator, + DiscordPermission.CreateInvite + ); + + DiscordPermissions expected = new + ( + DiscordPermission.ChangeNickname, + DiscordPermission.CreatePublicThreads, + DiscordPermission.Speak, + DiscordPermission.CreateInvite + ); + + Assert.Equal(expected, permissions ^ mask); + } + + [Fact] + public void TestNot() + { + DiscordPermissions permissions = new(DiscordPermission.CreateInvite); + DiscordPermissions expected = new(AllButFirstBit); + + Assert.Equal(expected, ~permissions); + } +} diff --git a/tests/core/DSharpPlus.Shared.Tests/Permissions/ToStringTests.cs b/tests/core/DSharpPlus.Shared.Tests/Permissions/ToStringTests.cs new file mode 100644 index 0000000000..e44b824a82 --- /dev/null +++ b/tests/core/DSharpPlus.Shared.Tests/Permissions/ToStringTests.cs @@ -0,0 +1,73 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Entities; + +using Xunit; + +namespace DSharpPlus.Shared.Tests.Permissions; + +public class ToStringTests +{ + [Fact] + public void TestFirstBit() + { + DiscordPermissions permissions = new(DiscordPermission.CreateInvite); + Assert.Equal("1", permissions.ToString()); + } + + [Fact] + public void TestByteOrder_SecondByte() + { + DiscordPermissions permissions = new(DiscordPermission.PrioritySpeaker); + Assert.Equal("256", permissions.ToString()); + } + + [Fact] + public void TestInternalElementOrder_SecondElement() + { + DiscordPermissions permissions = new(DiscordPermission.RequestToSpeak); + Assert.Equal("4294967296", permissions.ToString()); + } + + [Fact] + public void TestRawFirstBit() + { + DiscordPermissions permissions = new(DiscordPermission.CreateInvite); + + Assert.Equal + ( + "DiscordPermissions - raw value: 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00", + permissions.ToString("raw") + ); + } + + [Fact] + public void TestRawSecondElement() + { + DiscordPermissions permissions = new(DiscordPermission.RequestToSpeak); + + Assert.Equal + ( + "DiscordPermissions - raw value: 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00", + permissions.ToString("raw") + ); + } + + [Fact] + public void TestNameFirstElement() + { + DiscordPermissions permissions = new(DiscordPermission.CreateInvite); + + Assert.Equal("Create Invites", permissions.ToString("name")); + } + + [Fact] + public void TestNameOrder() + { + DiscordPermissions permissions = new(DiscordPermission.RequestToSpeak, DiscordPermission.CreateInvite); + + Assert.Equal("Create Invites, Request to Speak", permissions.ToString("name")); + } +} diff --git a/tests/core/DSharpPlus.Shared.Tests/Permissions/UtilityTests.cs b/tests/core/DSharpPlus.Shared.Tests/Permissions/UtilityTests.cs new file mode 100644 index 0000000000..d240f5bf37 --- /dev/null +++ b/tests/core/DSharpPlus.Shared.Tests/Permissions/UtilityTests.cs @@ -0,0 +1,54 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Entities; + +using Xunit; + +namespace DSharpPlus.Shared.Tests.Permissions; + +public class UtilityTests +{ + [Fact] + public void HasPermissionRespectsAdministrator() + { + DiscordPermissions permissions = new(DiscordPermission.Administrator, DiscordPermission.AddReactions); + Assert.True(permissions.HasPermission(DiscordPermission.BanMembers)); + + permissions = new(DiscordPermission.AddReactions); + Assert.False(permissions.HasPermission(DiscordPermission.BanMembers)); + } + + [Fact] + public void HasAnyPermissionAlwaysSucceedsWithAdministrator() + { + DiscordPermissions permissions = new(DiscordPermission.Administrator, DiscordPermission.AddReactions); + Assert.True(permissions.HasAnyPermission(DiscordPermission.BanMembers, DiscordPermission.CreateInvite)); + } + + [Fact] + public void HasAnyPermissionWithoutAdministrator() + { + DiscordPermissions permissions = new(DiscordPermission.CreateInvite, DiscordPermission.AddReactions); + Assert.True(permissions.HasAnyPermission(DiscordPermission.BanMembers, DiscordPermission.CreateInvite)); + Assert.False(permissions.HasAnyPermission(DiscordPermission.AttachFiles, DiscordPermission.Connect)); + } + + [Fact] + public void HasAllPermissionsAlwaysSucceedsWithAdministrator() + { + DiscordPermissions permissions = new(DiscordPermission.Administrator); + Assert.True(permissions.HasAllPermissions(DiscordPermission.CreatePrivateThreads, DiscordPermission.KickMembers)); + } + + [Fact] + public void HasAllPermissionsWithoutAdministrator() + { + DiscordPermissions permissions = new(DiscordPermission.CreateInvite, DiscordPermission.AddReactions); + permissions += DiscordPermission.ManageGuild; + + Assert.True(permissions.HasAllPermissions(DiscordPermission.ManageGuild, DiscordPermission.CreateInvite)); + Assert.False(permissions.HasAllPermissions(DiscordPermission.CreateInvite, DiscordPermission.Connect)); + } +} From 99c7b6de9b7c070c0b22f6a9361a38d3c0febdec Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Thu, 1 Aug 2024 02:55:36 +0200 Subject: [PATCH 303/323] update to latest API docs commits --- meta/builder-concrete-types.json | 6 +- .../IAllowedMentions.cs | 0 .../{Channels => Messages}/IAttachment.cs | 0 .../{Channels => Messages}/IChannelMention.cs | 0 .../{Channels => Messages}/IEmbed.cs | 0 .../{Channels => Messages}/IEmbedAuthor.cs | 0 .../{Channels => Messages}/IEmbedField.cs | 0 .../{Channels => Messages}/IEmbedFooter.cs | 0 .../{Channels => Messages}/IEmbedImage.cs | 0 .../{Channels => Messages}/IEmbedProvider.cs | 0 .../{Channels => Messages}/IEmbedThumbnail.cs | 0 .../{Channels => Messages}/IEmbedVideo.cs | 0 .../{Channels => Messages}/IMessage.cs | 0 .../IMessageActivity.cs | 0 .../{Channels => Messages}/IMessageCall.cs | 0 .../IMessageInteractionMetadata.cs | 0 .../IMessageReference.cs | 7 + .../Messages/IMessageSnapshot.cs | 16 + .../IPartialAttachment.cs | 5 + .../{Channels => Messages}/IPartialMessage.cs | 9 +- .../{Channels => Messages}/IReaction.cs | 17 + .../Messages/IReactionCountDetails.cs | 21 + .../IRoleSubscriptionData.cs | 0 .../Polls/ICreatePoll.cs | 8 +- .../API/IChannelRestAPI.cs | 228 ---------- .../API/IEmojiRestAPI.cs | 79 ++++ .../API/IMessageRestAPI.cs | 248 +++++++++++ .../Emojis/ICreateApplicationEmojiPayload.cs | 21 + .../Emojis/IModifyApplicationEmojiPayload.cs | 16 + .../IBulkDeleteMessagesPayload.cs | 0 .../ICreateMessagePayload.cs | 0 .../IEditMessagePayload.cs | 0 .../GetChannelMessagesQuery.cs | 0 .../GetReactionsQuery.cs | 0 .../{Channels => Messages}/ReactionType.cs | 0 .../ListApplicationEmojisResponse.cs | 17 + ...erviceCollectionExtensions.Registration.cs | 44 +- .../{Channels => Messages}/AllowedMentions.cs | 0 .../{Channels => Messages}/Attachment.cs | 5 +- .../{Channels => Messages}/ChannelMention.cs | 2 +- .../{Channels => Messages}/Embed.cs | 2 +- .../{Channels => Messages}/EmbedAuthor.cs | 2 +- .../{Channels => Messages}/EmbedField.cs | 2 +- .../{Channels => Messages}/EmbedFooter.cs | 2 +- .../{Channels => Messages}/EmbedImage.cs | 2 +- .../{Channels => Messages}/EmbedProvider.cs | 2 +- .../{Channels => Messages}/EmbedThumbnail.cs | 2 +- .../{Channels => Messages}/EmbedVideo.cs | 2 +- .../{Channels => Messages}/Message.cs | 5 +- .../{Channels => Messages}/MessageActivity.cs | 2 +- .../{Channels => Messages}/MessageCall.cs | 0 .../MessageInteractionMetadata.cs | 0 .../MessageReference.cs | 6 +- .../Messages/MessageSnapshot.cs | 14 + .../PartialAttachment.cs | 5 +- .../{Channels => Messages}/PartialMessage.cs | 5 +- .../{Channels => Messages}/Reaction.cs | 13 +- .../Messages/ReactionCountDetails.cs | 17 + .../RoleSubscriptionData.cs | 2 +- .../Polls/CreatePoll.cs | 6 +- .../AutoModerationActionConverter.cs | 42 +- .../API/ChannelRestAPI.cs | 389 ---------------- .../API/EmojiRestAPI.cs | 105 ++++- .../API/MessageRestAPI.cs | 416 ++++++++++++++++++ ...erviceCollectionExtensions.Registration.cs | 8 +- .../Emojis/CreateApplicationEmojiPayload.cs | 17 + .../Emojis/ModifyApplicationEmojiPayload.cs | 14 + .../BulkDeleteMessagesPayload.cs | 2 +- .../CreateMessagePayload.cs | 0 .../EditMessagePayload.cs | 0 .../DiscordAttachmentFlags.cs | 0 .../DiscordMessageActivityType.cs | 0 .../DiscordMessageFlags.cs | 0 .../Messages/DiscordMessageReferenceType.cs | 21 + .../DiscordMessageType.cs | 0 ...ensions.cs => MessageRestAPIExtensions.cs} | 12 +- .../copy-concrete-implementations.csx | 2 +- 77 files changed, 1175 insertions(+), 693 deletions(-) rename src/core/DSharpPlus.Internal.Abstractions.Models/{Channels => Messages}/IAllowedMentions.cs (100%) rename src/core/DSharpPlus.Internal.Abstractions.Models/{Channels => Messages}/IAttachment.cs (100%) rename src/core/DSharpPlus.Internal.Abstractions.Models/{Channels => Messages}/IChannelMention.cs (100%) rename src/core/DSharpPlus.Internal.Abstractions.Models/{Channels => Messages}/IEmbed.cs (100%) rename src/core/DSharpPlus.Internal.Abstractions.Models/{Channels => Messages}/IEmbedAuthor.cs (100%) rename src/core/DSharpPlus.Internal.Abstractions.Models/{Channels => Messages}/IEmbedField.cs (100%) rename src/core/DSharpPlus.Internal.Abstractions.Models/{Channels => Messages}/IEmbedFooter.cs (100%) rename src/core/DSharpPlus.Internal.Abstractions.Models/{Channels => Messages}/IEmbedImage.cs (100%) rename src/core/DSharpPlus.Internal.Abstractions.Models/{Channels => Messages}/IEmbedProvider.cs (100%) rename src/core/DSharpPlus.Internal.Abstractions.Models/{Channels => Messages}/IEmbedThumbnail.cs (100%) rename src/core/DSharpPlus.Internal.Abstractions.Models/{Channels => Messages}/IEmbedVideo.cs (100%) rename src/core/DSharpPlus.Internal.Abstractions.Models/{Channels => Messages}/IMessage.cs (100%) rename src/core/DSharpPlus.Internal.Abstractions.Models/{Channels => Messages}/IMessageActivity.cs (100%) rename src/core/DSharpPlus.Internal.Abstractions.Models/{Channels => Messages}/IMessageCall.cs (100%) rename src/core/DSharpPlus.Internal.Abstractions.Models/{Channels => Messages}/IMessageInteractionMetadata.cs (100%) rename src/core/DSharpPlus.Internal.Abstractions.Models/{Channels => Messages}/IMessageReference.cs (82%) create mode 100644 src/core/DSharpPlus.Internal.Abstractions.Models/Messages/IMessageSnapshot.cs rename src/core/DSharpPlus.Internal.Abstractions.Models/{Channels => Messages}/IPartialAttachment.cs (95%) rename src/core/DSharpPlus.Internal.Abstractions.Models/{Channels => Messages}/IPartialMessage.cs (96%) rename src/core/DSharpPlus.Internal.Abstractions.Models/{Channels => Messages}/IReaction.cs (59%) create mode 100644 src/core/DSharpPlus.Internal.Abstractions.Models/Messages/IReactionCountDetails.cs rename src/core/DSharpPlus.Internal.Abstractions.Models/{Channels => Messages}/IRoleSubscriptionData.cs (100%) create mode 100644 src/core/DSharpPlus.Internal.Abstractions.Rest/API/IMessageRestAPI.cs create mode 100644 src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Emojis/ICreateApplicationEmojiPayload.cs create mode 100644 src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Emojis/IModifyApplicationEmojiPayload.cs rename src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/{Channels => Messages}/IBulkDeleteMessagesPayload.cs (100%) rename src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/{Channels => Messages}/ICreateMessagePayload.cs (100%) rename src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/{Channels => Messages}/IEditMessagePayload.cs (100%) rename src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/{Channels => Messages}/GetChannelMessagesQuery.cs (100%) rename src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/{Channels => Messages}/GetReactionsQuery.cs (100%) rename src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/{Channels => Messages}/ReactionType.cs (100%) create mode 100644 src/core/DSharpPlus.Internal.Abstractions.Rest/Responses/ListApplicationEmojisResponse.cs rename src/core/DSharpPlus.Internal.Models/{Channels => Messages}/AllowedMentions.cs (100%) rename src/core/DSharpPlus.Internal.Models/{Channels => Messages}/Attachment.cs (95%) rename src/core/DSharpPlus.Internal.Models/{Channels => Messages}/ChannelMention.cs (99%) rename src/core/DSharpPlus.Internal.Models/{Channels => Messages}/Embed.cs (99%) rename src/core/DSharpPlus.Internal.Models/{Channels => Messages}/EmbedAuthor.cs (99%) rename src/core/DSharpPlus.Internal.Models/{Channels => Messages}/EmbedField.cs (99%) rename src/core/DSharpPlus.Internal.Models/{Channels => Messages}/EmbedFooter.cs (99%) rename src/core/DSharpPlus.Internal.Models/{Channels => Messages}/EmbedImage.cs (99%) rename src/core/DSharpPlus.Internal.Models/{Channels => Messages}/EmbedProvider.cs (99%) rename src/core/DSharpPlus.Internal.Models/{Channels => Messages}/EmbedThumbnail.cs (99%) rename src/core/DSharpPlus.Internal.Models/{Channels => Messages}/EmbedVideo.cs (99%) rename src/core/DSharpPlus.Internal.Models/{Channels => Messages}/Message.cs (96%) rename src/core/DSharpPlus.Internal.Models/{Channels => Messages}/MessageActivity.cs (99%) rename src/core/DSharpPlus.Internal.Models/{Channels => Messages}/MessageCall.cs (100%) rename src/core/DSharpPlus.Internal.Models/{Channels => Messages}/MessageInteractionMetadata.cs (100%) rename src/core/DSharpPlus.Internal.Models/{Channels => Messages}/MessageReference.cs (85%) create mode 100644 src/core/DSharpPlus.Internal.Models/Messages/MessageSnapshot.cs rename src/core/DSharpPlus.Internal.Models/{Channels => Messages}/PartialAttachment.cs (95%) rename src/core/DSharpPlus.Internal.Models/{Channels => Messages}/PartialMessage.cs (96%) rename src/core/DSharpPlus.Internal.Models/{Channels => Messages}/Reaction.cs (67%) create mode 100644 src/core/DSharpPlus.Internal.Models/Messages/ReactionCountDetails.cs rename src/core/DSharpPlus.Internal.Models/{Channels => Messages}/RoleSubscriptionData.cs (99%) create mode 100644 src/core/DSharpPlus.Internal.Rest/API/MessageRestAPI.cs create mode 100644 src/core/DSharpPlus.Internal.Rest/Payloads/Emojis/CreateApplicationEmojiPayload.cs create mode 100644 src/core/DSharpPlus.Internal.Rest/Payloads/Emojis/ModifyApplicationEmojiPayload.cs rename src/core/DSharpPlus.Internal.Rest/Payloads/{Channels => Messages}/BulkDeleteMessagesPayload.cs (99%) rename src/core/DSharpPlus.Internal.Rest/Payloads/{Channels => Messages}/CreateMessagePayload.cs (100%) rename src/core/DSharpPlus.Internal.Rest/Payloads/{Channels => Messages}/EditMessagePayload.cs (100%) rename src/core/DSharpPlus.Shared/Entities/{Channels => Messages}/DiscordAttachmentFlags.cs (100%) rename src/core/DSharpPlus.Shared/Entities/{Channels => Messages}/DiscordMessageActivityType.cs (100%) rename src/core/DSharpPlus.Shared/Entities/{Channels => Messages}/DiscordMessageFlags.cs (100%) create mode 100644 src/core/DSharpPlus.Shared/Entities/Messages/DiscordMessageReferenceType.cs rename src/core/DSharpPlus.Shared/Entities/{Channels => Messages}/DiscordMessageType.cs (100%) rename src/extensions/DSharpPlus.Extensions.Internal.Builders/Extensions/{ChannelRestAPIExtensions.cs => MessageRestAPIExtensions.cs} (91%) diff --git a/meta/builder-concrete-types.json b/meta/builder-concrete-types.json index 44071c787c..bab9a23cd0 100644 --- a/meta/builder-concrete-types.json +++ b/meta/builder-concrete-types.json @@ -1,12 +1,12 @@ [ - "./src/core/DSharpPlus.Internal.Models/Channels/Embed.cs", + "./src/core/DSharpPlus.Internal.Models/Messages/Embed.cs", "./src/core/DSharpPlus.Internal.Models/Interactions/InteractionResponse.cs", "./src/core/DSharpPlus.Internal.Models/Interactions/ModalCallbackData.cs", "./src/core/DSharpPlus.Internal.Models/Interactions/MessageCallbackData.cs", "./src/core/DSharpPlus.Internal.Models/MessageComponents/ActionRowComponent.cs", "./src/core/DSharpPlus.Internal.Models/MessageComponents/TextInputComponent.cs", - "./src/core/DSharpPlus.Internal.Rest/Payloads/Channels/CreateMessagePayload.cs", - "./src/core/DSharpPlus.Internal.Rest/Payloads/Channels/EditMessagePayload.cs", + "./src/core/DSharpPlus.Internal.Rest/Payloads/Messages/CreateMessagePayload.cs", + "./src/core/DSharpPlus.Internal.Rest/Payloads/Messages/EditMessagePayload.cs", "./src/core/DSharpPlus.Internal.Rest/Payloads/Interactions/CreateFollowupMessagePayload.cs", "./src/core/DSharpPlus.Internal.Rest/Payloads/Interactions/EditFollowupMessagePayload.cs", "./src/core/DSharpPlus.Internal.Rest/Payloads/Interactions/EditInteractionResponsePayload.cs" diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IAllowedMentions.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Messages/IAllowedMentions.cs similarity index 100% rename from src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IAllowedMentions.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Messages/IAllowedMentions.cs diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IAttachment.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Messages/IAttachment.cs similarity index 100% rename from src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IAttachment.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Messages/IAttachment.cs diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IChannelMention.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Messages/IChannelMention.cs similarity index 100% rename from src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IChannelMention.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Messages/IChannelMention.cs diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IEmbed.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Messages/IEmbed.cs similarity index 100% rename from src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IEmbed.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Messages/IEmbed.cs diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IEmbedAuthor.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Messages/IEmbedAuthor.cs similarity index 100% rename from src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IEmbedAuthor.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Messages/IEmbedAuthor.cs diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IEmbedField.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Messages/IEmbedField.cs similarity index 100% rename from src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IEmbedField.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Messages/IEmbedField.cs diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IEmbedFooter.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Messages/IEmbedFooter.cs similarity index 100% rename from src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IEmbedFooter.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Messages/IEmbedFooter.cs diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IEmbedImage.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Messages/IEmbedImage.cs similarity index 100% rename from src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IEmbedImage.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Messages/IEmbedImage.cs diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IEmbedProvider.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Messages/IEmbedProvider.cs similarity index 100% rename from src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IEmbedProvider.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Messages/IEmbedProvider.cs diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IEmbedThumbnail.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Messages/IEmbedThumbnail.cs similarity index 100% rename from src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IEmbedThumbnail.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Messages/IEmbedThumbnail.cs diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IEmbedVideo.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Messages/IEmbedVideo.cs similarity index 100% rename from src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IEmbedVideo.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Messages/IEmbedVideo.cs diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IMessage.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Messages/IMessage.cs similarity index 100% rename from src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IMessage.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Messages/IMessage.cs diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IMessageActivity.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Messages/IMessageActivity.cs similarity index 100% rename from src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IMessageActivity.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Messages/IMessageActivity.cs diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IMessageCall.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Messages/IMessageCall.cs similarity index 100% rename from src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IMessageCall.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Messages/IMessageCall.cs diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IMessageInteractionMetadata.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Messages/IMessageInteractionMetadata.cs similarity index 100% rename from src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IMessageInteractionMetadata.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Messages/IMessageInteractionMetadata.cs diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IMessageReference.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Messages/IMessageReference.cs similarity index 82% rename from src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IMessageReference.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Messages/IMessageReference.cs index cecdb9159d..739746b9a3 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IMessageReference.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Messages/IMessageReference.cs @@ -2,6 +2,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +using DSharpPlus.Entities; + namespace DSharpPlus.Internal.Abstractions.Models; /// @@ -10,6 +12,11 @@ namespace DSharpPlus.Internal.Abstractions.Models; /// public interface IMessageReference { + /// + /// The type of this reference. If this is unset, should be assumed. + /// + public Optional Type { get; } + /// /// The snowflake identifier of the originating message. /// diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/Messages/IMessageSnapshot.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Messages/IMessageSnapshot.cs new file mode 100644 index 0000000000..01e848a19b --- /dev/null +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Messages/IMessageSnapshot.cs @@ -0,0 +1,16 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Internal.Abstractions.Models; + +/// +/// Represents a snapshot taken of a message. +/// +public interface IMessageSnapshot +{ + /// + /// A subset of the data contained within the referenced message. + /// + public IPartialMessage Message { get; } +} diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IPartialAttachment.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Messages/IPartialAttachment.cs similarity index 95% rename from src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IPartialAttachment.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Messages/IPartialAttachment.cs index bd2be5cbe7..dee13d4c1f 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IPartialAttachment.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Messages/IPartialAttachment.cs @@ -23,6 +23,11 @@ public interface IPartialAttachment /// public Optional Filename { get; } + /// + /// The attachment's title. + /// + public Optional Title { get; } + /// /// The file description, up to 1024 characters. /// diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IPartialMessage.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Messages/IPartialMessage.cs similarity index 96% rename from src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IPartialMessage.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Messages/IPartialMessage.cs index b9742075d6..1e5ab35f5b 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IPartialMessage.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Messages/IPartialMessage.cs @@ -123,6 +123,11 @@ public interface IPartialMessage /// public Optional ApplicationId { get; } + /// + /// Additional flags for this message. + /// + public Optional Flags { get; } + /// /// A message reference showing the source of a crosspost, channel follow, pin, reply or thread /// creation/start message. @@ -130,9 +135,9 @@ public interface IPartialMessage public Optional MessageReference { get; } /// - /// Additional flags for this message. + /// Contains message snapshot objects associated with the . /// - public Optional Flags { get; } + public Optional> MessageSnapshots { get; } /// /// The message associated with the . diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IReaction.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Messages/IReaction.cs similarity index 59% rename from src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IReaction.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Messages/IReaction.cs index f0254b5817..dff8fbb3dd 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IReaction.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Messages/IReaction.cs @@ -2,6 +2,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +using System.Collections.Generic; + namespace DSharpPlus.Internal.Abstractions.Models; /// @@ -14,13 +16,28 @@ public interface IReaction /// public int Count { get; } + /// + /// Contains additional information about how often this emoji has been reacted with. + /// + public IReactionCountDetails CountDetails { get; } + /// /// Indicates whether the current user has reacted using this emoji. /// public bool Me { get; } + /// + /// Indicates whether the current user has super-reacted using this emoji. + /// + public bool MeBurst { get; } + /// /// The emoji that is being reacted with. /// public IPartialEmoji Emoji { get; } + + /// + /// The color codes used for super reactions. + /// + public IReadOnlyList BurstColors { get; } } diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/Messages/IReactionCountDetails.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Messages/IReactionCountDetails.cs new file mode 100644 index 0000000000..c72ca780a1 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Messages/IReactionCountDetails.cs @@ -0,0 +1,21 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Internal.Abstractions.Models; + +/// +/// Provides additional information about how many times a reaction was applied to a message. +/// +public interface IReactionCountDetails +{ + /// + /// Specifies the amount of super reactions of this emoji applied to the message. + /// + public int Burst { get; } + + /// + /// Specifies the amount of standard reactions of this emoji applied to the message. + /// + public int Normal { get; } +} diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IRoleSubscriptionData.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Messages/IRoleSubscriptionData.cs similarity index 100% rename from src/core/DSharpPlus.Internal.Abstractions.Models/Channels/IRoleSubscriptionData.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Messages/IRoleSubscriptionData.cs diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/Polls/ICreatePoll.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Polls/ICreatePoll.cs index fc95976de1..8aeff9c5bd 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Models/Polls/ICreatePoll.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Polls/ICreatePoll.cs @@ -24,14 +24,14 @@ public interface ICreatePoll public IReadOnlyList Answers { get; } /// - /// The duration in hours this poll should last; up to 7 days or 168 hours. + /// The duration in hours this poll should last; up to 32 days or 768 hours. Defaults to one day or 24 hours. /// - public int Duration { get; } + public Optional Duration { get; } /// - /// Specifies whether this poll allows selecting multiple answers. + /// Specifies whether this poll allows selecting multiple answers. Defaults to false. /// - public bool AllowMultiselect { get; } + public Optional AllowMultiselect { get; } /// /// The layout type of this poll. "Defaults to... DEFAULT!" - Discord. diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IChannelRestAPI.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IChannelRestAPI.cs index 61ebd13708..95be20ccba 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IChannelRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IChannelRestAPI.cs @@ -102,234 +102,6 @@ public ValueTask> DeleteChannelAsync CancellationToken ct = default ); - /// - /// Returns a set amount of messages, optionally before, after or around a certain message. - /// - /// - /// around, before and after are mutually exclusive. Only one may be passed. If multiple are passed, - /// only the first one in the parameter list is respected, independent of the order they are passed in client code. - /// - /// The snowflake identifier of the channel in question. - /// Specifies where to get messages from, used for paginating. - /// Additional instructions regarding this request. - /// A cancellation token for this operation. - public ValueTask>> GetChannelMessagesAsync - ( - Snowflake channelId, - GetChannelMessagesQuery query = default, - RequestInfo info = default, - CancellationToken ct = default - ); - - /// - /// Gets a message by its snowflake identifier. - /// - /// The snowflake identifier of the message's parent channel. - /// The snowflake identifier of the message in question. - /// Additional instructions regarding this request. - /// A cancellation token for this operation. - public ValueTask> GetChannelMessageAsync - ( - Snowflake channelId, - Snowflake messageId, - RequestInfo info = default, - CancellationToken ct = default - ); - - /// - /// Creates a new message in a channel. - /// - /// The snowflake identifier of the message's target channel. - /// Message creation payload including potential attachment files. - /// Additional instructions regarding this request. - /// A cancellation token for this operation. - /// The newly created message object. - public ValueTask> CreateMessageAsync - ( - Snowflake channelId, - ICreateMessagePayload payload, - RequestInfo info = default, - CancellationToken ct = default - ); - - /// - /// Publishes a message in an announcement channel to following channels. - /// - /// The origin announcement channel of this message. - /// The snowflake identifier of the message. - /// Additional instructions regarding this request. - /// A cancellation token for this operation. - public ValueTask> CrosspostMessageAsync - ( - Snowflake channelId, - Snowflake messageId, - RequestInfo info = default, - CancellationToken ct = default - ); - - /// - /// Creates a reaction with the given emoji on the specified message. - /// - /// The snowflake identifier of the message's parent channel. - /// The snowflake identifier of the message in question. - /// The string representation of the emoji. - /// Additional instructions regarding this request. - /// A cancellation token for this operation. - /// Whether the reaction was added successfully. - public ValueTask CreateReactionAsync - ( - Snowflake channelId, - Snowflake messageId, - string emoji, - RequestInfo info = default, - CancellationToken ct = default - ); - - /// - /// Deletes your own reaction with the specified emoji on the specified message. - /// - /// The snowflake identifier of the message's parent channel. - /// The snowflake identifier of the message in question. - /// The string representation of the emoji. - /// Additional instructions regarding this request. - /// A cancellation token for this operation. - /// Whether the reaction was removed successfully. - public ValueTask DeleteOwnReactionAsync - ( - Snowflake channelId, - Snowflake messageId, - string emoji, - RequestInfo info = default, - CancellationToken ct = default - ); - - /// - /// Deletes the specified user's reaction with the specified emoji on the specified message. - /// - /// The snowflake identifier of the message's parent channel. - /// The snowflake identifier of the message in question. - /// The snowflake identifier of the user in question. - /// The string representation of the emoji. - /// Additional instructions regarding this request. - /// A cancellation token for this operation. - /// Whether the reaction was removed successfully. - public ValueTask DeleteUserReactionAsync - ( - Snowflake channelId, - Snowflake messageId, - Snowflake userId, - string emoji, - RequestInfo info = default, - CancellationToken ct = default - ); - - /// - /// Gets a list of users that reacted with the given emoji. - /// - /// The snowflake identifier of the message's parent channel. - /// The snowflake identifier of the message in question. - /// The string representation of the queried emoji. - /// Contains query information related to request pagination. - /// Additional instructions regarding this request. - /// A cancellation token for this operation. - public ValueTask>> GetReactionsAsync - ( - Snowflake channelId, - Snowflake messageId, - string emoji, - GetReactionsQuery query = default, - RequestInfo info = default, - CancellationToken ct = default - ); - - /// - /// Deletes all reactions on the given message. - /// - /// The snowflake identifier of the message's parent channel. - /// The snowflake identifier of the message in question. - /// Additional instructions regarding this request. - /// A cancellation token for this operation. - public ValueTask DeleteAllReactionsAsync - ( - Snowflake channelId, - Snowflake messageId, - RequestInfo info = default, - CancellationToken ct = default - ); - - /// - /// Deletes all reactions with a specific emoji from the specified message. - /// - /// The snowflake identifier of the message's parent channel. - /// The snowflake identifier of the message in question. - /// The string representation of the emoji in question. - /// Additional instructions regarding this request. - /// A cancellation token for this operation. - public ValueTask DeleteAllReactionsForEmojiAsync - ( - Snowflake channelId, - Snowflake messageId, - string emoji, - RequestInfo info = default, - CancellationToken ct = default - ); - - /// - /// Edits the given message. - /// - /// The snowflake identifier of the message's parent channel. - /// The snowflake identifier of the message in question. - /// A payload object containing information on how to edit this message. - /// Additional instructions regarding this request. - /// A cancellation token for this operation. - public ValueTask> EditMessageAsync - ( - Snowflake channelId, - Snowflake messageId, - IEditMessagePayload payload, - RequestInfo info = default, - CancellationToken ct = default - ); - - /// - /// Deletes a given message. - /// - /// The nowflake identifier of the message's parent channel. - /// The snowflake identifier of the message. - /// An optional audit log reason. - /// Additional instructions regarding this request. - /// A cancellation token for this operation. - /// Whether the message was successfully deleted. - public ValueTask DeleteMessageAsync - ( - Snowflake channelId, - Snowflake messageId, - string? reason = null, - RequestInfo info = default, - CancellationToken ct = default - ); - - /// - /// Bulk-deletes the provided messages. - /// - /// The snowflake identifier of the message's parent channel. - /// - /// Up to 100 message IDs to delete. If any messages older than two weeks are included, - /// or any of the IDs are duplicated, the entire request will fail. - /// - /// An optional audit log reason. - /// Additional instructions regarding this request. - /// A cancellation token for this operation. - /// Whether the messages were deleted successfully. - public ValueTask BulkDeleteMessagesAsync - ( - Snowflake channelId, - IBulkDeleteMessagesPayload payload, - string? reason = null, - RequestInfo info = default, - CancellationToken ct = default - ); - /// /// Edits a permission overwrite for a guild channel. /// diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IEmojiRestAPI.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IEmojiRestAPI.cs index 2a6340a9de..2cb109e90d 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IEmojiRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IEmojiRestAPI.cs @@ -8,6 +8,7 @@ using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Internal.Abstractions.Rest.Payloads; +using DSharpPlus.Internal.Abstractions.Rest.Responses; using DSharpPlus.Results; namespace DSharpPlus.Internal.Abstractions.Rest.API; @@ -100,4 +101,82 @@ public ValueTask DeleteGuildEmojiAsync RequestInfo info = default, CancellationToken ct = default ); + + /// + /// Lists all emojis belonging to the given application. + /// + /// The snowflake identifier of the current application. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public ValueTask> ListApplicationEmojisAsync + ( + Snowflake applicationId, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Returns a specified emoji from the given application. + /// + /// The snowflake identifier of the current application. + /// The snowflake identifier of the requested emoji. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public ValueTask> GetApplicationEmojiAsync + ( + Snowflake applicationId, + Snowflake emojiId, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Creates a new emoji for the given application. + /// + /// The snowflake identifier of the current application. + /// The payload containing the new emoji. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + /// The newly created emoji. + public ValueTask> CreateApplicationEmojiAsync + ( + Snowflake applicationId, + ICreateApplicationEmojiPayload payload, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Modifies an existing emoji of the given application. + /// + /// The snowflake identifier of the current application. + /// The snowflake identifier of the emoji to modify. + /// The payload containing updated information. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + /// The newly modified emoji. + public ValueTask> ModifyApplicationEmojiAsync + ( + Snowflake applicationId, + Snowflake emojiId, + IModifyApplicationEmojiPayload payload, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Deletes an existing emoji of the given application. + /// + /// The snowflake identifier of the current application. + /// The snowflake identifier of the emoji to delete. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + /// A value indicating whether the deletion was successful. + public ValueTask DeleteApplicationEmojiAsync + ( + Snowflake applicationId, + Snowflake emojiId, + RequestInfo info = default, + CancellationToken ct = default + ); } diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IMessageRestAPI.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IMessageRestAPI.cs new file mode 100644 index 0000000000..ad0d039bb5 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IMessageRestAPI.cs @@ -0,0 +1,248 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; + +using DSharpPlus.Internal.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Rest.Payloads; +using DSharpPlus.Internal.Abstractions.Rest.Queries; +using DSharpPlus.Results; + +namespace DSharpPlus.Internal.Abstractions.Rest.API; + +/// +/// Provides access to message-related rest API calls. +/// +public interface IMessageRestAPI +{ + /// + /// Returns a set amount of messages, optionally before, after or around a certain message. + /// + /// + /// around, before and after are mutually exclusive. Only one may be passed. If multiple are passed, + /// only the first one in the parameter list is respected, independent of the order they are passed in client code. + /// + /// The snowflake identifier of the channel in question. + /// Specifies where to get messages from, used for paginating. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public ValueTask>> GetChannelMessagesAsync + ( + Snowflake channelId, + GetChannelMessagesQuery query = default, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Gets a message by its snowflake identifier. + /// + /// The snowflake identifier of the message's parent channel. + /// The snowflake identifier of the message in question. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public ValueTask> GetChannelMessageAsync + ( + Snowflake channelId, + Snowflake messageId, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Creates a new message in a channel. + /// + /// The snowflake identifier of the message's target channel. + /// Message creation payload including potential attachment files. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + /// The newly created message object. + public ValueTask> CreateMessageAsync + ( + Snowflake channelId, + ICreateMessagePayload payload, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Publishes a message in an announcement channel to following channels. + /// + /// The origin announcement channel of this message. + /// The snowflake identifier of the message. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public ValueTask> CrosspostMessageAsync + ( + Snowflake channelId, + Snowflake messageId, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Creates a reaction with the given emoji on the specified message. + /// + /// The snowflake identifier of the message's parent channel. + /// The snowflake identifier of the message in question. + /// The string representation of the emoji. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + /// Whether the reaction was added successfully. + public ValueTask CreateReactionAsync + ( + Snowflake channelId, + Snowflake messageId, + string emoji, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Deletes your own reaction with the specified emoji on the specified message. + /// + /// The snowflake identifier of the message's parent channel. + /// The snowflake identifier of the message in question. + /// The string representation of the emoji. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + /// Whether the reaction was removed successfully. + public ValueTask DeleteOwnReactionAsync + ( + Snowflake channelId, + Snowflake messageId, + string emoji, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Deletes the specified user's reaction with the specified emoji on the specified message. + /// + /// The snowflake identifier of the message's parent channel. + /// The snowflake identifier of the message in question. + /// The snowflake identifier of the user in question. + /// The string representation of the emoji. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + /// Whether the reaction was removed successfully. + public ValueTask DeleteUserReactionAsync + ( + Snowflake channelId, + Snowflake messageId, + Snowflake userId, + string emoji, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Gets a list of users that reacted with the given emoji. + /// + /// The snowflake identifier of the message's parent channel. + /// The snowflake identifier of the message in question. + /// The string representation of the queried emoji. + /// Contains query information related to request pagination. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public ValueTask>> GetReactionsAsync + ( + Snowflake channelId, + Snowflake messageId, + string emoji, + GetReactionsQuery query = default, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Deletes all reactions on the given message. + /// + /// The snowflake identifier of the message's parent channel. + /// The snowflake identifier of the message in question. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public ValueTask DeleteAllReactionsAsync + ( + Snowflake channelId, + Snowflake messageId, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Deletes all reactions with a specific emoji from the specified message. + /// + /// The snowflake identifier of the message's parent channel. + /// The snowflake identifier of the message in question. + /// The string representation of the emoji in question. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public ValueTask DeleteAllReactionsForEmojiAsync + ( + Snowflake channelId, + Snowflake messageId, + string emoji, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Edits the given message. + /// + /// The snowflake identifier of the message's parent channel. + /// The snowflake identifier of the message in question. + /// A payload object containing information on how to edit this message. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public ValueTask> EditMessageAsync + ( + Snowflake channelId, + Snowflake messageId, + IEditMessagePayload payload, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Deletes a given message. + /// + /// The nowflake identifier of the message's parent channel. + /// The snowflake identifier of the message. + /// An optional audit log reason. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + /// Whether the message was successfully deleted. + public ValueTask DeleteMessageAsync + ( + Snowflake channelId, + Snowflake messageId, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Bulk-deletes the provided messages. + /// + /// The snowflake identifier of the message's parent channel. + /// + /// Up to 100 message IDs to delete. If any messages older than two weeks are included, + /// or any of the IDs are duplicated, the entire request will fail. + /// + /// An optional audit log reason. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + /// Whether the messages were deleted successfully. + public ValueTask BulkDeleteMessagesAsync + ( + Snowflake channelId, + IBulkDeleteMessagesPayload payload, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ); +} diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Emojis/ICreateApplicationEmojiPayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Emojis/ICreateApplicationEmojiPayload.cs new file mode 100644 index 0000000000..695b7421b6 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Emojis/ICreateApplicationEmojiPayload.cs @@ -0,0 +1,21 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Internal.Abstractions.Rest.Payloads; + +/// +/// Represents a payload to POST /applications/:application-id/emojis. +/// +public interface ICreateApplicationEmojiPayload +{ + /// + /// The name of the new emoji. + /// + public string Name { get; } + + /// + /// The 128x128 emoji image. + /// + public ImageData Image { get; } +} diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Emojis/IModifyApplicationEmojiPayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Emojis/IModifyApplicationEmojiPayload.cs new file mode 100644 index 0000000000..0f1881119e --- /dev/null +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Emojis/IModifyApplicationEmojiPayload.cs @@ -0,0 +1,16 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Internal.Abstractions.Rest.Payloads; + +/// +/// Represents a payload to PATCH /applications/:application-id/emojis/:emoji-id +/// +public interface IModifyApplicationEmojiPayload +{ + /// + /// The new name of the emoji. + /// + public string Name { get; } +} diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Channels/IBulkDeleteMessagesPayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Messages/IBulkDeleteMessagesPayload.cs similarity index 100% rename from src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Channels/IBulkDeleteMessagesPayload.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Messages/IBulkDeleteMessagesPayload.cs diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Channels/ICreateMessagePayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Messages/ICreateMessagePayload.cs similarity index 100% rename from src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Channels/ICreateMessagePayload.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Messages/ICreateMessagePayload.cs diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Channels/IEditMessagePayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Messages/IEditMessagePayload.cs similarity index 100% rename from src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Channels/IEditMessagePayload.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Messages/IEditMessagePayload.cs diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Channels/GetChannelMessagesQuery.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Messages/GetChannelMessagesQuery.cs similarity index 100% rename from src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Channels/GetChannelMessagesQuery.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Messages/GetChannelMessagesQuery.cs diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Channels/GetReactionsQuery.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Messages/GetReactionsQuery.cs similarity index 100% rename from src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Channels/GetReactionsQuery.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Messages/GetReactionsQuery.cs diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Channels/ReactionType.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Messages/ReactionType.cs similarity index 100% rename from src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Channels/ReactionType.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Messages/ReactionType.cs diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Responses/ListApplicationEmojisResponse.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Responses/ListApplicationEmojisResponse.cs new file mode 100644 index 0000000000..b6098439ed --- /dev/null +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Responses/ListApplicationEmojisResponse.cs @@ -0,0 +1,17 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Internal.Abstractions.Models; + +namespace DSharpPlus.Internal.Abstractions.Rest.Responses; + +/// +/// Represents a response from GET /applications/:application-id/emojis. +/// +public readonly record struct ListApplicationEmojisResponse +{ + public IReadOnlyList Items { get; init; } +} diff --git a/src/core/DSharpPlus.Internal.Models/Extensions/ServiceCollectionExtensions.Registration.cs b/src/core/DSharpPlus.Internal.Models/Extensions/ServiceCollectionExtensions.Registration.cs index ed54e2ed15..875c8a0364 100644 --- a/src/core/DSharpPlus.Internal.Models/Extensions/ServiceCollectionExtensions.Registration.cs +++ b/src/core/DSharpPlus.Internal.Models/Extensions/ServiceCollectionExtensions.Registration.cs @@ -42,33 +42,13 @@ private static void RegisterSerialization(IServiceCollection services) options.AddModel(); options.AddModel(); options.AddModel(); - options.AddModel(); - options.AddModel(); options.AddModel(); - options.AddModel(); options.AddModel(); options.AddModel(); - options.AddModel(); - options.AddModel(); - options.AddModel(); - options.AddModel(); - options.AddModel(); - options.AddModel(); - options.AddModel(); - options.AddModel(); options.AddModel(); options.AddModel(); - options.AddModel(); - options.AddModel(); - options.AddModel(); - options.AddModel(); - options.AddModel(); - options.AddModel(); options.AddModel(); options.AddModel(); - options.AddModel(); - options.AddModel(); - options.AddModel(); options.AddModel(); options.AddModel(); options.AddModel(); @@ -119,6 +99,28 @@ private static void RegisterSerialization(IServiceCollection services) options.AddModel(); options.AddModel(); options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); options.AddModel(); options.AddModel(); options.AddModel(); @@ -151,4 +153,4 @@ private static void RegisterSerialization(IServiceCollection services) } ); } -} +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Models/Channels/AllowedMentions.cs b/src/core/DSharpPlus.Internal.Models/Messages/AllowedMentions.cs similarity index 100% rename from src/core/DSharpPlus.Internal.Models/Channels/AllowedMentions.cs rename to src/core/DSharpPlus.Internal.Models/Messages/AllowedMentions.cs diff --git a/src/core/DSharpPlus.Internal.Models/Channels/Attachment.cs b/src/core/DSharpPlus.Internal.Models/Messages/Attachment.cs similarity index 95% rename from src/core/DSharpPlus.Internal.Models/Channels/Attachment.cs rename to src/core/DSharpPlus.Internal.Models/Messages/Attachment.cs index ee62553829..0862c949c5 100644 --- a/src/core/DSharpPlus.Internal.Models/Channels/Attachment.cs +++ b/src/core/DSharpPlus.Internal.Models/Messages/Attachment.cs @@ -18,6 +18,9 @@ public sealed record Attachment : IAttachment /// public required string Filename { get; init; } + /// + public Optional Title { get; init; } + /// public Optional Description { get; init; } @@ -50,4 +53,4 @@ public sealed record Attachment : IAttachment /// public Optional Flags { get; init; } -} +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Models/Channels/ChannelMention.cs b/src/core/DSharpPlus.Internal.Models/Messages/ChannelMention.cs similarity index 99% rename from src/core/DSharpPlus.Internal.Models/Channels/ChannelMention.cs rename to src/core/DSharpPlus.Internal.Models/Messages/ChannelMention.cs index 26cb1050e4..cd2e870b7f 100644 --- a/src/core/DSharpPlus.Internal.Models/Channels/ChannelMention.cs +++ b/src/core/DSharpPlus.Internal.Models/Messages/ChannelMention.cs @@ -21,4 +21,4 @@ public sealed record ChannelMention : IChannelMention /// public required string Name { get; init; } -} +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Models/Channels/Embed.cs b/src/core/DSharpPlus.Internal.Models/Messages/Embed.cs similarity index 99% rename from src/core/DSharpPlus.Internal.Models/Channels/Embed.cs rename to src/core/DSharpPlus.Internal.Models/Messages/Embed.cs index 8b3cb3d436..54f3ac7732 100644 --- a/src/core/DSharpPlus.Internal.Models/Channels/Embed.cs +++ b/src/core/DSharpPlus.Internal.Models/Messages/Embed.cs @@ -50,4 +50,4 @@ public sealed record Embed : IEmbed /// public Optional> Fields { get; init; } -} +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Models/Channels/EmbedAuthor.cs b/src/core/DSharpPlus.Internal.Models/Messages/EmbedAuthor.cs similarity index 99% rename from src/core/DSharpPlus.Internal.Models/Channels/EmbedAuthor.cs rename to src/core/DSharpPlus.Internal.Models/Messages/EmbedAuthor.cs index 561ee08cfa..a70c637dcb 100644 --- a/src/core/DSharpPlus.Internal.Models/Channels/EmbedAuthor.cs +++ b/src/core/DSharpPlus.Internal.Models/Messages/EmbedAuthor.cs @@ -20,4 +20,4 @@ public sealed record EmbedAuthor : IEmbedAuthor /// public Optional ProxyIconUrl { get; init; } -} +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Models/Channels/EmbedField.cs b/src/core/DSharpPlus.Internal.Models/Messages/EmbedField.cs similarity index 99% rename from src/core/DSharpPlus.Internal.Models/Channels/EmbedField.cs rename to src/core/DSharpPlus.Internal.Models/Messages/EmbedField.cs index 493d2ec019..dfba94145a 100644 --- a/src/core/DSharpPlus.Internal.Models/Channels/EmbedField.cs +++ b/src/core/DSharpPlus.Internal.Models/Messages/EmbedField.cs @@ -17,4 +17,4 @@ public sealed record EmbedField : IEmbedField /// public Optional Inline { get; init; } -} +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Models/Channels/EmbedFooter.cs b/src/core/DSharpPlus.Internal.Models/Messages/EmbedFooter.cs similarity index 99% rename from src/core/DSharpPlus.Internal.Models/Channels/EmbedFooter.cs rename to src/core/DSharpPlus.Internal.Models/Messages/EmbedFooter.cs index 8cb5ac0dc6..9386af213f 100644 --- a/src/core/DSharpPlus.Internal.Models/Channels/EmbedFooter.cs +++ b/src/core/DSharpPlus.Internal.Models/Messages/EmbedFooter.cs @@ -17,4 +17,4 @@ public sealed record EmbedFooter : IEmbedFooter /// public Optional ProxyIconUrl { get; init; } -} +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Models/Channels/EmbedImage.cs b/src/core/DSharpPlus.Internal.Models/Messages/EmbedImage.cs similarity index 99% rename from src/core/DSharpPlus.Internal.Models/Channels/EmbedImage.cs rename to src/core/DSharpPlus.Internal.Models/Messages/EmbedImage.cs index 6c81869ae0..5e2f47bd72 100644 --- a/src/core/DSharpPlus.Internal.Models/Channels/EmbedImage.cs +++ b/src/core/DSharpPlus.Internal.Models/Messages/EmbedImage.cs @@ -20,4 +20,4 @@ public sealed record EmbedImage : IEmbedImage /// public Optional Width { get; init; } -} +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Models/Channels/EmbedProvider.cs b/src/core/DSharpPlus.Internal.Models/Messages/EmbedProvider.cs similarity index 99% rename from src/core/DSharpPlus.Internal.Models/Channels/EmbedProvider.cs rename to src/core/DSharpPlus.Internal.Models/Messages/EmbedProvider.cs index 59b63a530c..531c8908a5 100644 --- a/src/core/DSharpPlus.Internal.Models/Channels/EmbedProvider.cs +++ b/src/core/DSharpPlus.Internal.Models/Messages/EmbedProvider.cs @@ -14,4 +14,4 @@ public sealed record EmbedProvider : IEmbedProvider /// public Optional Url { get; init; } -} +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Models/Channels/EmbedThumbnail.cs b/src/core/DSharpPlus.Internal.Models/Messages/EmbedThumbnail.cs similarity index 99% rename from src/core/DSharpPlus.Internal.Models/Channels/EmbedThumbnail.cs rename to src/core/DSharpPlus.Internal.Models/Messages/EmbedThumbnail.cs index d4a512fbc2..26db818a6f 100644 --- a/src/core/DSharpPlus.Internal.Models/Channels/EmbedThumbnail.cs +++ b/src/core/DSharpPlus.Internal.Models/Messages/EmbedThumbnail.cs @@ -20,4 +20,4 @@ public sealed record EmbedThumbnail : IEmbedThumbnail /// public Optional Width { get; init; } -} +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Models/Channels/EmbedVideo.cs b/src/core/DSharpPlus.Internal.Models/Messages/EmbedVideo.cs similarity index 99% rename from src/core/DSharpPlus.Internal.Models/Channels/EmbedVideo.cs rename to src/core/DSharpPlus.Internal.Models/Messages/EmbedVideo.cs index 14a58635de..f1df768180 100644 --- a/src/core/DSharpPlus.Internal.Models/Channels/EmbedVideo.cs +++ b/src/core/DSharpPlus.Internal.Models/Messages/EmbedVideo.cs @@ -20,4 +20,4 @@ public sealed record EmbedVideo : IEmbedVideo /// public Optional Width { get; init; } -} +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Models/Channels/Message.cs b/src/core/DSharpPlus.Internal.Models/Messages/Message.cs similarity index 96% rename from src/core/DSharpPlus.Internal.Models/Channels/Message.cs rename to src/core/DSharpPlus.Internal.Models/Messages/Message.cs index a98374870d..1742824f1a 100644 --- a/src/core/DSharpPlus.Internal.Models/Channels/Message.cs +++ b/src/core/DSharpPlus.Internal.Models/Messages/Message.cs @@ -76,11 +76,14 @@ public sealed record Message : IMessage /// public Optional ApplicationId { get; init; } + /// + public Optional Flags { get; init; } + /// public Optional MessageReference { get; init; } /// - public Optional Flags { get; init; } + public Optional> MessageSnapshots { get; init; } /// public Optional ReferencedMessage { get; init; } diff --git a/src/core/DSharpPlus.Internal.Models/Channels/MessageActivity.cs b/src/core/DSharpPlus.Internal.Models/Messages/MessageActivity.cs similarity index 99% rename from src/core/DSharpPlus.Internal.Models/Channels/MessageActivity.cs rename to src/core/DSharpPlus.Internal.Models/Messages/MessageActivity.cs index e22f4e16e2..9051e346e9 100644 --- a/src/core/DSharpPlus.Internal.Models/Channels/MessageActivity.cs +++ b/src/core/DSharpPlus.Internal.Models/Messages/MessageActivity.cs @@ -15,4 +15,4 @@ public sealed record MessageActivity : IMessageActivity /// public Optional PartyId { get; init; } -} +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Models/Channels/MessageCall.cs b/src/core/DSharpPlus.Internal.Models/Messages/MessageCall.cs similarity index 100% rename from src/core/DSharpPlus.Internal.Models/Channels/MessageCall.cs rename to src/core/DSharpPlus.Internal.Models/Messages/MessageCall.cs diff --git a/src/core/DSharpPlus.Internal.Models/Channels/MessageInteractionMetadata.cs b/src/core/DSharpPlus.Internal.Models/Messages/MessageInteractionMetadata.cs similarity index 100% rename from src/core/DSharpPlus.Internal.Models/Channels/MessageInteractionMetadata.cs rename to src/core/DSharpPlus.Internal.Models/Messages/MessageInteractionMetadata.cs diff --git a/src/core/DSharpPlus.Internal.Models/Channels/MessageReference.cs b/src/core/DSharpPlus.Internal.Models/Messages/MessageReference.cs similarity index 85% rename from src/core/DSharpPlus.Internal.Models/Channels/MessageReference.cs rename to src/core/DSharpPlus.Internal.Models/Messages/MessageReference.cs index 0c2a3c8178..c7493b4db8 100644 --- a/src/core/DSharpPlus.Internal.Models/Channels/MessageReference.cs +++ b/src/core/DSharpPlus.Internal.Models/Messages/MessageReference.cs @@ -2,6 +2,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +using DSharpPlus.Entities; using DSharpPlus.Internal.Abstractions.Models; namespace DSharpPlus.Internal.Models; @@ -9,6 +10,9 @@ namespace DSharpPlus.Internal.Models; /// public sealed record MessageReference : IMessageReference { + /// + public Optional Type { get; init; } + /// public Optional MessageId { get; init; } @@ -20,4 +24,4 @@ public sealed record MessageReference : IMessageReference /// public Optional FailIfNotExists { get; init; } -} +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Models/Messages/MessageSnapshot.cs b/src/core/DSharpPlus.Internal.Models/Messages/MessageSnapshot.cs new file mode 100644 index 0000000000..94be1df3c8 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Models/Messages/MessageSnapshot.cs @@ -0,0 +1,14 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Internal.Abstractions.Models; + +namespace DSharpPlus.Internal.Models; + +/// +public sealed record MessageSnapshot : IMessageSnapshot +{ + /// + public required IPartialMessage Message { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Models/Channels/PartialAttachment.cs b/src/core/DSharpPlus.Internal.Models/Messages/PartialAttachment.cs similarity index 95% rename from src/core/DSharpPlus.Internal.Models/Channels/PartialAttachment.cs rename to src/core/DSharpPlus.Internal.Models/Messages/PartialAttachment.cs index 8a5e1f532d..ccc19f85b7 100644 --- a/src/core/DSharpPlus.Internal.Models/Channels/PartialAttachment.cs +++ b/src/core/DSharpPlus.Internal.Models/Messages/PartialAttachment.cs @@ -18,6 +18,9 @@ public sealed record PartialAttachment : IPartialAttachment /// public Optional Filename { get; init; } + /// + public Optional Title { get; init; } + /// public Optional Description { get; init; } @@ -50,4 +53,4 @@ public sealed record PartialAttachment : IPartialAttachment /// public Optional Flags { get; init; } -} +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Models/Channels/PartialMessage.cs b/src/core/DSharpPlus.Internal.Models/Messages/PartialMessage.cs similarity index 96% rename from src/core/DSharpPlus.Internal.Models/Channels/PartialMessage.cs rename to src/core/DSharpPlus.Internal.Models/Messages/PartialMessage.cs index f5afc97ad6..2eceeadfd0 100644 --- a/src/core/DSharpPlus.Internal.Models/Channels/PartialMessage.cs +++ b/src/core/DSharpPlus.Internal.Models/Messages/PartialMessage.cs @@ -76,11 +76,14 @@ public sealed record PartialMessage : IPartialMessage /// public Optional ApplicationId { get; init; } + /// + public Optional Flags { get; init; } + /// public Optional MessageReference { get; init; } /// - public Optional Flags { get; init; } + public Optional> MessageSnapshots { get; init; } /// public Optional ReferencedMessage { get; init; } diff --git a/src/core/DSharpPlus.Internal.Models/Channels/Reaction.cs b/src/core/DSharpPlus.Internal.Models/Messages/Reaction.cs similarity index 67% rename from src/core/DSharpPlus.Internal.Models/Channels/Reaction.cs rename to src/core/DSharpPlus.Internal.Models/Messages/Reaction.cs index 1774bfdfa0..d6de702260 100644 --- a/src/core/DSharpPlus.Internal.Models/Channels/Reaction.cs +++ b/src/core/DSharpPlus.Internal.Models/Messages/Reaction.cs @@ -2,6 +2,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +using System.Collections.Generic; + using DSharpPlus.Internal.Abstractions.Models; namespace DSharpPlus.Internal.Models; @@ -12,9 +14,18 @@ public sealed record Reaction : IReaction /// public required int Count { get; init; } + /// + public required IReactionCountDetails CountDetails { get; init; } + /// public required bool Me { get; init; } + /// + public required bool MeBurst { get; init; } + /// public required IPartialEmoji Emoji { get; init; } -} + + /// + public required IReadOnlyList BurstColors { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Models/Messages/ReactionCountDetails.cs b/src/core/DSharpPlus.Internal.Models/Messages/ReactionCountDetails.cs new file mode 100644 index 0000000000..7f40e8877d --- /dev/null +++ b/src/core/DSharpPlus.Internal.Models/Messages/ReactionCountDetails.cs @@ -0,0 +1,17 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Internal.Abstractions.Models; + +namespace DSharpPlus.Internal.Models; + +/// +public sealed record ReactionCountDetails : IReactionCountDetails +{ + /// + public required int Burst { get; init; } + + /// + public required int Normal { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Models/Channels/RoleSubscriptionData.cs b/src/core/DSharpPlus.Internal.Models/Messages/RoleSubscriptionData.cs similarity index 99% rename from src/core/DSharpPlus.Internal.Models/Channels/RoleSubscriptionData.cs rename to src/core/DSharpPlus.Internal.Models/Messages/RoleSubscriptionData.cs index b4962d4ee6..8673710cec 100644 --- a/src/core/DSharpPlus.Internal.Models/Channels/RoleSubscriptionData.cs +++ b/src/core/DSharpPlus.Internal.Models/Messages/RoleSubscriptionData.cs @@ -20,4 +20,4 @@ public sealed record RoleSubscriptionData : IRoleSubscriptionData /// public required bool IsRenewal { get; init; } -} +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Models/Polls/CreatePoll.cs b/src/core/DSharpPlus.Internal.Models/Polls/CreatePoll.cs index 3d60e7f934..6478175a76 100644 --- a/src/core/DSharpPlus.Internal.Models/Polls/CreatePoll.cs +++ b/src/core/DSharpPlus.Internal.Models/Polls/CreatePoll.cs @@ -19,11 +19,11 @@ public sealed record CreatePoll : ICreatePoll public required IReadOnlyList Answers { get; init; } /// - public required int Duration { get; init; } + public Optional Duration { get; init; } /// - public required bool AllowMultiselect { get; init; } + public Optional AllowMultiselect { get; init; } /// public Optional LayoutType { get; init; } -} +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Models/Serialization/Converters/AutoModerationActionConverter.cs b/src/core/DSharpPlus.Internal.Models/Serialization/Converters/AutoModerationActionConverter.cs index af764c4c24..41dc744a2f 100644 --- a/src/core/DSharpPlus.Internal.Models/Serialization/Converters/AutoModerationActionConverter.cs +++ b/src/core/DSharpPlus.Internal.Models/Serialization/Converters/AutoModerationActionConverter.cs @@ -32,24 +32,42 @@ JsonSerializerOptions options if ( !JsonDocument.TryParseValue(ref reader, out JsonDocument? document) - || document.RootElement.TryGetProperty("type", out JsonElement property) - || !property.TryGetInt32(out int type) - || document.RootElement.TryGetProperty("metadata", out JsonElement metadata) + || document.RootElement.TryGetProperty("type", out JsonElement typeElement) + || !typeElement.TryGetInt32(out int type) ) { throw new JsonException("The provided JSON object was malformed."); } - Optional data = (DiscordAutoModerationActionType)type switch + Optional data; + + // these three types have associated metadata, deserialize accordingly + if + ( + (DiscordAutoModerationActionType)type is DiscordAutoModerationActionType.BlockMessage + or DiscordAutoModerationActionType.SendAlertMessage + or DiscordAutoModerationActionType.Timeout + && document.RootElement.TryGetProperty("metadata", out JsonElement metadata) + ) { - DiscordAutoModerationActionType.BlockMessage - => new(metadata.Deserialize(options)!), - DiscordAutoModerationActionType.SendAlertMessage - => new(metadata.Deserialize(options)!), - DiscordAutoModerationActionType.Timeout - => new(metadata.Deserialize(options)!), - _ => new() - }; +#pragma warning disable IDE0072 + data = (DiscordAutoModerationActionType)type switch + { + DiscordAutoModerationActionType.BlockMessage + => new(metadata.Deserialize(options)!), + DiscordAutoModerationActionType.SendAlertMessage + => new(metadata.Deserialize(options)!), + DiscordAutoModerationActionType.Timeout + => new(metadata.Deserialize(options)!), + _ => Optional.None + }; +#pragma warning restore IDE0072 + } + // everyone else doesn't have metadata, good job, we made it through + else + { + data = Optional.None; + } document.Dispose(); diff --git a/src/core/DSharpPlus.Internal.Rest/API/ChannelRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/ChannelRestAPI.cs index 5c174683bc..f0bb13071f 100644 --- a/src/core/DSharpPlus.Internal.Rest/API/ChannelRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Rest/API/ChannelRestAPI.cs @@ -6,7 +6,6 @@ using System.Collections.Generic; using System.Globalization; -using System.Linq; using System.Net.Http; using System.Threading; using System.Threading.Tasks; @@ -50,30 +49,6 @@ public async ValueTask AddThreadMemberAsync return (Result)response; } - /// - public async ValueTask BulkDeleteMessagesAsync - ( - Snowflake channelId, - IBulkDeleteMessagesPayload payload, - string? reason = null, - RequestInfo info = default, - CancellationToken ct = default - ) - { - Result response = await restClient.ExecuteRequestAsync - ( - HttpMethod.Post, - $"channels/{channelId}/messages/bulk-delete", - b => b.WithSimpleRoute(TopLevelResource.Channel, channelId) - .WithPayload(payload) - .WithAuditLogReason(reason), - info, - ct - ); - - return (Result)response; - } - /// public async ValueTask> CreateChannelInviteAsync ( @@ -125,159 +100,6 @@ public async ValueTask> CreateChannelInviteAsync ); } - /// - public async ValueTask> CreateMessageAsync - ( - Snowflake channelId, - ICreateMessagePayload payload, - RequestInfo info = default, - CancellationToken ct = default - ) - { - if - ( - !(payload.Content.HasValue || payload.Embeds.HasValue || payload.StickerIds.HasValue - || payload.Components.HasValue || payload.Files is not null) - ) - { - return new ValidationError - ( - "At least one of Content, Embeds, StickerIds, Components or Files must be sent." - ); - } - - if (payload.Content.HasValue && payload.Content.Value.Length > 2000) - { - return new ValidationError("The content of a message cannot exceed 2000 characters."); - } - - if (payload.Nonce.HasValue && payload.Nonce.Value.Length > 25) - { - return new ValidationError("The nonce of a message cannot exceed 25 characters."); - } - - if (payload.Embeds.HasValue && payload.Embeds.Value.Count > 10) - { - return new ValidationError("Only up to 10 embeds can be sent with a message."); - } - - if (payload.StickerIds.HasValue && payload.StickerIds.Value.Count > 3) - { - return new ValidationError("Only up to 3 stickers can be sent with a message."); - } - - if (payload.Poll.TryGetNonNullValue(out ICreatePoll? poll)) - { - if (poll.Question.Text is { HasValue: true, Value.Length: > 300 }) - { - return new ValidationError("The poll must specify a question that cannot exceed 300 characters."); - } - - if (poll.Answers.Any(answer => answer.PollMedia.Text is { HasValue: true, Value.Length: > 55 })) - { - return new ValidationError("The answer text of a poll cannot exceed 55 characters."); - } - } - - return await restClient.ExecuteRequestAsync - ( - HttpMethod.Post, - $"channels/{channelId}/messages", - b => b.WithSimpleRoute(TopLevelResource.Channel, channelId) - .WithPayload(payload), - info, - ct - ); - } - - /// - public async ValueTask CreateReactionAsync - ( - Snowflake channelId, - Snowflake messageId, - string emoji, - RequestInfo info = default, - CancellationToken ct = default - ) - { - Result response = await restClient.ExecuteRequestAsync - ( - HttpMethod.Put, - $"channels/{channelId}/messages/{messageId}/reactions/{emoji}/@me", - b => b.WithSimpleRoute(TopLevelResource.Channel, channelId) - .WithRoute($"PUT channels/{channelId}/messages/:message-id/reactions/:emoji/@me"), - info, - ct - ); - - return (Result)response; - } - - /// - public async ValueTask> CrosspostMessageAsync - ( - Snowflake channelId, - Snowflake messageId, - RequestInfo info = default, - CancellationToken ct = default - ) - { - return await restClient.ExecuteRequestAsync - ( - HttpMethod.Post, - $"channels/{channelId}/messages/{messageId}/crosspost", - b => b.WithSimpleRoute(TopLevelResource.Channel, channelId) - .WithRoute($"POST channels/{channelId}/messages/:message-id/crosspost"), - info, - ct - ); - } - - /// - public async ValueTask DeleteAllReactionsAsync - ( - Snowflake channelId, - Snowflake messageId, - RequestInfo info = default, - CancellationToken ct = default - ) - { - Result response = await restClient.ExecuteRequestAsync - ( - HttpMethod.Delete, - $"channels/{channelId}/messages/{messageId}/reactions", - b => b.WithSimpleRoute(TopLevelResource.Channel, channelId) - .WithRoute($"DELETE channels/{channelId}/messages/:message-id/reactions"), - info, - ct - ); - - return (Result)response; - } - - /// - public async ValueTask DeleteAllReactionsForEmojiAsync - ( - Snowflake channelId, - Snowflake messageId, - string emoji, - RequestInfo info = default, - CancellationToken ct = default - ) - { - Result response = await restClient.ExecuteRequestAsync - ( - HttpMethod.Delete, - $"channels/{channelId}/messages/{messageId}/reactions/{emoji}", - b => b.WithSimpleRoute(TopLevelResource.Channel, channelId) - .WithRoute($"DELETE channels/{channelId}/messages/:message-id/reactions/:emoji"), - info, - ct - ); - - return (Result)response; - } - /// public async ValueTask> DeleteChannelAsync ( @@ -321,77 +143,6 @@ public async ValueTask DeleteChannelPermissionAsync return (Result)response; } - /// - public async ValueTask DeleteMessageAsync - ( - Snowflake channelId, - Snowflake messageId, - string? reason = null, - RequestInfo info = default, - CancellationToken ct = default - ) - { - Result response = await restClient.ExecuteRequestAsync - ( - HttpMethod.Delete, - $"channels/{channelId}/messages/{messageId}", - b => b.WithSimpleRoute(TopLevelResource.Channel, channelId) - .WithRoute($"DELETE channels/{channelId}/messages/:message-id") - .WithAuditLogReason(reason), - info, - ct - ); - - return (Result)response; - } - - /// - public async ValueTask DeleteOwnReactionAsync - ( - Snowflake channelId, - Snowflake messageId, - string emoji, - RequestInfo info = default, - CancellationToken ct = default - ) - { - Result response = await restClient.ExecuteRequestAsync - ( - HttpMethod.Delete, - $"channels/{channelId}/messages/{messageId}/reactions/{emoji}/@me", - b => b.WithSimpleRoute(TopLevelResource.Channel, channelId) - .WithRoute($"DELETE channels/{channelId}/messages/:message-id/reactions/:emoji/@me"), - info, - ct - ); - - return (Result)response; - } - - /// - public async ValueTask DeleteUserReactionAsync - ( - Snowflake channelId, - Snowflake messageId, - Snowflake userId, - string emoji, - RequestInfo info = default, - CancellationToken ct = default - ) - { - Result response = await restClient.ExecuteRequestAsync - ( - HttpMethod.Delete, - $"channels/{channelId}/messages/{messageId}/reactions/{emoji}/{userId}", - b => b.WithSimpleRoute(TopLevelResource.Channel, channelId) - .WithRoute($"DELETE channels/{channelId}/messages/:message-id/reactions/:emoji/:user-id"), - info, - ct - ); - - return (Result)response; - } - /// public async ValueTask EditChannelPermissionsAsync ( @@ -418,38 +169,6 @@ public async ValueTask EditChannelPermissionsAsync return (Result)response; } - /// - public async ValueTask> EditMessageAsync - ( - Snowflake channelId, - Snowflake messageId, - IEditMessagePayload payload, - RequestInfo info = default, - CancellationToken ct = default - ) - { - if (payload.Content.TryGetNonNullValue(out string? content) && content.Length > 2000) - { - return new ValidationError("The content of a message cannot exceed 2000 characters."); - } - - if (payload.Embeds.TryGetNonNullValue(out IReadOnlyList? embeds) && embeds.Count > 10) - { - return new ValidationError("A message can only have up to 10 embeds."); - } - - return await restClient.ExecuteRequestAsync - ( - HttpMethod.Patch, - $"channels/{channelId}/messages/{messageId}", - b => b.WithSimpleRoute(TopLevelResource.Channel, channelId) - .WithRoute($"PATCH channels/{channelId}/messages/:message-id") - .WithPayload(payload), - info, - ct - ); - } - /// public async ValueTask> FollowAnnouncementChannelAsync ( @@ -508,70 +227,6 @@ public async ValueTask>> GetChannelInvitesAsync ); } - /// - public async ValueTask> GetChannelMessageAsync - ( - Snowflake channelId, - Snowflake messageId, - RequestInfo info = default, - CancellationToken ct = default - ) - { - return await restClient.ExecuteRequestAsync - ( - HttpMethod.Get, - $"channels/{channelId}/messages/{messageId}", - b => b.WithSimpleRoute(TopLevelResource.Channel, channelId) - .WithRoute($"GET channels/{channelId}/messages/:message-id"), - info, - ct - ); - } - - /// - public async ValueTask>> GetChannelMessagesAsync - ( - Snowflake channelId, - GetChannelMessagesQuery query = default, - RequestInfo info = default, - CancellationToken ct = default - ) - { - if (query.Limit is not null and (< 1 or > 100)) - { - return new ValidationError("The limit for messages to request at once must be between 1 and 100."); - } - - QueryBuilder builder = new($"channels/{channelId}/messages"); - - if (query.Limit is not null) - { - _ = builder.AddParameter("limit", query.Limit.Value.ToString(CultureInfo.InvariantCulture)); - } - - if (query.Around is not null) - { - _ = builder.AddParameter("around", query.Around.Value.ToString()); - } - else if (query.Before is not null) - { - _ = builder.AddParameter("before", query.Before.Value.ToString()); - } - else if (query.After is not null) - { - _ = builder.AddParameter("after", query.After.Value.ToString()); - } - - return await restClient.ExecuteRequestAsync> - ( - HttpMethod.Get, - builder.Build(), - b => b.WithSimpleRoute(TopLevelResource.Channel, channelId), - info, - ct - ); - } - /// public async ValueTask>> GetPinnedMessagesAsync ( @@ -590,50 +245,6 @@ public async ValueTask>> GetPinnedMessagesAsync ); } - /// - public async ValueTask>> GetReactionsAsync - ( - Snowflake channelId, - Snowflake messageId, - string emoji, - GetReactionsQuery query = default, - RequestInfo info = default, - CancellationToken ct = default - ) - { - if (query.Limit is not null and (< 1 or > 100)) - { - return new ValidationError("The limit of reactions to request must be between 1 and 100."); - } - - QueryBuilder builder = new($"channels/{channelId}/messages/{messageId}/reactions/{emoji}"); - - if (query.After is not null) - { - _ = builder.AddParameter("after", query.After.Value.ToString()); - } - - if (query.Limit is not null) - { - _ = builder.AddParameter("limit", query.Limit.Value.ToString(CultureInfo.InvariantCulture)); - } - - if (query.Type is not null) - { - _ = builder.AddParameter("type", ((int)query.Type.Value).ToString(CultureInfo.InvariantCulture)); - } - - return await restClient.ExecuteRequestAsync> - ( - HttpMethod.Get, - builder.Build(), - b => b.WithSimpleRoute(TopLevelResource.Channel, channelId) - .WithRoute($"GET channels/{channelId}/messages/:message-id/reactions/:emoji"), - info, - ct - ); - } - /// public async ValueTask> GetThreadMemberAsync ( diff --git a/src/core/DSharpPlus.Internal.Rest/API/EmojiRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/EmojiRestAPI.cs index 01e819ab0e..551a1c39b3 100644 --- a/src/core/DSharpPlus.Internal.Rest/API/EmojiRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Rest/API/EmojiRestAPI.cs @@ -11,6 +11,7 @@ using DSharpPlus.Internal.Abstractions.Rest; using DSharpPlus.Internal.Abstractions.Rest.API; using DSharpPlus.Internal.Abstractions.Rest.Payloads; +using DSharpPlus.Internal.Abstractions.Rest.Responses; using DSharpPlus.Results; namespace DSharpPlus.Internal.Rest.API; @@ -18,11 +19,33 @@ namespace DSharpPlus.Internal.Rest.API; // as per https://discord.com/developers/docs/topics/rate-limits, emojis are handled separately from other // ratelimits. we therefore never count them towards the simple guild limit, and instead specify them as // 'other' -> emojis/:guild-id so that their erratic behaviour doesn't mess with the rest of our ratelimits. +// +// application emojis kinda muddy the water here, but we'll just assume they're well-behaved for lack of actual docs. /// public sealed class EmojiRestAPI(IRestClient restClient) : IEmojiRestAPI { + /// + public async ValueTask> CreateApplicationEmojiAsync + ( + Snowflake applicationId, + ICreateApplicationEmojiPayload payload, + RequestInfo info = default, + CancellationToken ct = default + ) + { + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Post, + $"applications/{applicationId}/emojis", + b => b.WithRoute($"POST applications/:application-id/emojis") + .WithPayload(payload), + info, + ct + ); + } + /// public async ValueTask> CreateGuildEmojiAsync ( @@ -38,12 +61,32 @@ public async ValueTask> CreateGuildEmojiAsync HttpMethod.Post, $"guilds/{guildId}/emojis", b => b.WithRoute($"POST emojis/{guildId}") + .WithPayload(payload) .WithAuditLogReason(reason), info, ct ); } + /// + public async ValueTask DeleteApplicationEmojiAsync + ( + Snowflake applicationId, + Snowflake emojiId, + RequestInfo info = default, + CancellationToken ct = default + ) + { + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Delete, + $"applications/{applicationId}/emojis/{emojiId}", + b => b.WithRoute($"DELETE applications/:application-id/emojis/:emoji-id"), + info, + ct + ); + } + /// public async ValueTask DeleteGuildEmojiAsync ( @@ -54,7 +97,7 @@ public async ValueTask DeleteGuildEmojiAsync CancellationToken ct = default ) { - Result response = await restClient.ExecuteRequestAsync + return await restClient.ExecuteRequestAsync ( HttpMethod.Delete, $"guilds/{guildId}/emojis/{emojiId}", @@ -63,8 +106,25 @@ public async ValueTask DeleteGuildEmojiAsync info, ct ); + } - return (Result)response; + /// + public async ValueTask> GetApplicationEmojiAsync + ( + Snowflake applicationId, + Snowflake emojiId, + RequestInfo info = default, + CancellationToken ct = default + ) + { + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Get, + $"applications/{applicationId}/emojis/{emojiId}", + b => b.WithRoute($"GET applications/:application-id/emojis/:emoji-id"), + info, + ct + ); } /// @@ -86,6 +146,24 @@ public async ValueTask> GetGuildEmojiAsync ); } + /// + public async ValueTask> ListApplicationEmojisAsync + ( + Snowflake applicationId, + RequestInfo info = default, + CancellationToken ct = default + ) + { + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Get, + $"applications/{applicationId}/emojis", + b => b.WithRoute($"GET applications/:application-id/emojis"), + info, + ct + ); + } + /// public async ValueTask>> ListGuildEmojisAsync ( @@ -104,6 +182,27 @@ public async ValueTask>> ListGuildEmojisAsync ); } + /// + public async ValueTask> ModifyApplicationEmojiAsync + ( + Snowflake applicationId, + Snowflake emojiId, + IModifyApplicationEmojiPayload payload, + RequestInfo info = default, + CancellationToken ct = default + ) + { + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Patch, + $"applications/{applicationId}/emojis/{emojiId}", + b => b.WithRoute($"PATCH applications/:application-id/emojis/:emoji-id") + .WithPayload(payload), + info, + ct + ); + } + /// public async ValueTask> ModifyGuildEmojiAsync ( @@ -119,7 +218,7 @@ public async ValueTask> ModifyGuildEmojiAsync ( HttpMethod.Patch, $"guilds/{guildId}/emojis/{emojiId}", - b => b.WithRoute($"GET emojis/{guildId}") + b => b.WithRoute($"PATCH emojis/{guildId}") .WithPayload(payload) .WithAuditLogReason(reason), info, diff --git a/src/core/DSharpPlus.Internal.Rest/API/MessageRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/MessageRestAPI.cs new file mode 100644 index 0000000000..1332e76dad --- /dev/null +++ b/src/core/DSharpPlus.Internal.Rest/API/MessageRestAPI.cs @@ -0,0 +1,416 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +#pragma warning disable IDE0046 + +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Net.Http; +using System.Threading; +using System.Threading.Tasks; + +using DSharpPlus.Internal.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Rest; +using DSharpPlus.Internal.Abstractions.Rest.API; +using DSharpPlus.Internal.Abstractions.Rest.Errors; +using DSharpPlus.Internal.Abstractions.Rest.Payloads; +using DSharpPlus.Internal.Abstractions.Rest.Queries; +using DSharpPlus.Internal.Rest.Ratelimiting; +using DSharpPlus.Results; + +namespace DSharpPlus.Internal.Rest.API; + +/// +public sealed class MessageRestAPI(IRestClient restClient) + : IMessageRestAPI +{ + /// + public async ValueTask BulkDeleteMessagesAsync + ( + Snowflake channelId, + IBulkDeleteMessagesPayload payload, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ) + { + Result response = await restClient.ExecuteRequestAsync + ( + HttpMethod.Post, + $"channels/{channelId}/messages/bulk-delete", + b => b.WithSimpleRoute(TopLevelResource.Channel, channelId) + .WithPayload(payload) + .WithAuditLogReason(reason), + info, + ct + ); + + return (Result)response; + } + + /// + public async ValueTask> CreateMessageAsync + ( + Snowflake channelId, + ICreateMessagePayload payload, + RequestInfo info = default, + CancellationToken ct = default + ) + { + if + ( + !(payload.Content.HasValue || payload.Embeds.HasValue || payload.StickerIds.HasValue + || payload.Components.HasValue || payload.Files is not null) + ) + { + return new ValidationError + ( + "At least one of Content, Embeds, StickerIds, Components or Files must be sent." + ); + } + + if (payload.Content.HasValue && payload.Content.Value.Length > 2000) + { + return new ValidationError("The content of a message cannot exceed 2000 characters."); + } + + if (payload.Nonce.HasValue && payload.Nonce.Value.Length > 25) + { + return new ValidationError("The nonce of a message cannot exceed 25 characters."); + } + + if (payload.Embeds.HasValue && payload.Embeds.Value.Count > 10) + { + return new ValidationError("Only up to 10 embeds can be sent with a message."); + } + + if (payload.StickerIds.HasValue && payload.StickerIds.Value.Count > 3) + { + return new ValidationError("Only up to 3 stickers can be sent with a message."); + } + + if (payload.Poll.TryGetNonNullValue(out ICreatePoll? poll)) + { + if (poll.Question.Text is { HasValue: true, Value.Length: > 300 }) + { + return new ValidationError("The poll must specify a question that cannot exceed 300 characters."); + } + + if (poll.Answers.Any(answer => answer.PollMedia.Text is { HasValue: true, Value.Length: > 55 })) + { + return new ValidationError("The answer text of a poll cannot exceed 55 characters."); + } + } + + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Post, + $"channels/{channelId}/messages", + b => b.WithSimpleRoute(TopLevelResource.Channel, channelId) + .WithPayload(payload), + info, + ct + ); + } + + /// + public async ValueTask CreateReactionAsync + ( + Snowflake channelId, + Snowflake messageId, + string emoji, + RequestInfo info = default, + CancellationToken ct = default + ) + { + Result response = await restClient.ExecuteRequestAsync + ( + HttpMethod.Put, + $"channels/{channelId}/messages/{messageId}/reactions/{emoji}/@me", + b => b.WithSimpleRoute(TopLevelResource.Channel, channelId) + .WithRoute($"PUT channels/{channelId}/messages/:message-id/reactions/:emoji/@me"), + info, + ct + ); + + return (Result)response; + } + + /// + public async ValueTask> CrosspostMessageAsync + ( + Snowflake channelId, + Snowflake messageId, + RequestInfo info = default, + CancellationToken ct = default + ) + { + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Post, + $"channels/{channelId}/messages/{messageId}/crosspost", + b => b.WithSimpleRoute(TopLevelResource.Channel, channelId) + .WithRoute($"POST channels/{channelId}/messages/:message-id/crosspost"), + info, + ct + ); + } + + /// + public async ValueTask DeleteAllReactionsAsync + ( + Snowflake channelId, + Snowflake messageId, + RequestInfo info = default, + CancellationToken ct = default + ) + { + Result response = await restClient.ExecuteRequestAsync + ( + HttpMethod.Delete, + $"channels/{channelId}/messages/{messageId}/reactions", + b => b.WithSimpleRoute(TopLevelResource.Channel, channelId) + .WithRoute($"DELETE channels/{channelId}/messages/:message-id/reactions"), + info, + ct + ); + + return (Result)response; + } + + /// + public async ValueTask DeleteAllReactionsForEmojiAsync + ( + Snowflake channelId, + Snowflake messageId, + string emoji, + RequestInfo info = default, + CancellationToken ct = default + ) + { + Result response = await restClient.ExecuteRequestAsync + ( + HttpMethod.Delete, + $"channels/{channelId}/messages/{messageId}/reactions/{emoji}", + b => b.WithSimpleRoute(TopLevelResource.Channel, channelId) + .WithRoute($"DELETE channels/{channelId}/messages/:message-id/reactions/:emoji"), + info, + ct + ); + + return (Result)response; + } + + /// + public async ValueTask DeleteMessageAsync + ( + Snowflake channelId, + Snowflake messageId, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ) + { + Result response = await restClient.ExecuteRequestAsync + ( + HttpMethod.Delete, + $"channels/{channelId}/messages/{messageId}", + b => b.WithSimpleRoute(TopLevelResource.Channel, channelId) + .WithRoute($"DELETE channels/{channelId}/messages/:message-id") + .WithAuditLogReason(reason), + info, + ct + ); + + return (Result)response; + } + + /// + public async ValueTask DeleteOwnReactionAsync + ( + Snowflake channelId, + Snowflake messageId, + string emoji, + RequestInfo info = default, + CancellationToken ct = default + ) + { + Result response = await restClient.ExecuteRequestAsync + ( + HttpMethod.Delete, + $"channels/{channelId}/messages/{messageId}/reactions/{emoji}/@me", + b => b.WithSimpleRoute(TopLevelResource.Channel, channelId) + .WithRoute($"DELETE channels/{channelId}/messages/:message-id/reactions/:emoji/@me"), + info, + ct + ); + + return (Result)response; + } + + /// + public async ValueTask DeleteUserReactionAsync + ( + Snowflake channelId, + Snowflake messageId, + Snowflake userId, + string emoji, + RequestInfo info = default, + CancellationToken ct = default + ) + { + Result response = await restClient.ExecuteRequestAsync + ( + HttpMethod.Delete, + $"channels/{channelId}/messages/{messageId}/reactions/{emoji}/{userId}", + b => b.WithSimpleRoute(TopLevelResource.Channel, channelId) + .WithRoute($"DELETE channels/{channelId}/messages/:message-id/reactions/:emoji/:user-id"), + info, + ct + ); + + return (Result)response; + } + + /// + public async ValueTask> EditMessageAsync + ( + Snowflake channelId, + Snowflake messageId, + IEditMessagePayload payload, + RequestInfo info = default, + CancellationToken ct = default + ) + { + if (payload.Content.TryGetNonNullValue(out string? content) && content.Length > 2000) + { + return new ValidationError("The content of a message cannot exceed 2000 characters."); + } + + if (payload.Embeds.TryGetNonNullValue(out IReadOnlyList? embeds) && embeds.Count > 10) + { + return new ValidationError("A message can only have up to 10 embeds."); + } + + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Patch, + $"channels/{channelId}/messages/{messageId}", + b => b.WithSimpleRoute(TopLevelResource.Channel, channelId) + .WithRoute($"PATCH channels/{channelId}/messages/:message-id") + .WithPayload(payload), + info, + ct + ); + } + + /// + public async ValueTask> GetChannelMessageAsync + ( + Snowflake channelId, + Snowflake messageId, + RequestInfo info = default, + CancellationToken ct = default + ) + { + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Get, + $"channels/{channelId}/messages/{messageId}", + b => b.WithSimpleRoute(TopLevelResource.Channel, channelId) + .WithRoute($"GET channels/{channelId}/messages/:message-id"), + info, + ct + ); + } + + /// + public async ValueTask>> GetChannelMessagesAsync + ( + Snowflake channelId, + GetChannelMessagesQuery query = default, + RequestInfo info = default, + CancellationToken ct = default + ) + { + if (query.Limit is not null and (< 1 or > 100)) + { + return new ValidationError("The limit for messages to request at once must be between 1 and 100."); + } + + QueryBuilder builder = new($"channels/{channelId}/messages"); + + if (query.Limit is not null) + { + _ = builder.AddParameter("limit", query.Limit.Value.ToString(CultureInfo.InvariantCulture)); + } + + if (query.Around is not null) + { + _ = builder.AddParameter("around", query.Around.Value.ToString()); + } + else if (query.Before is not null) + { + _ = builder.AddParameter("before", query.Before.Value.ToString()); + } + else if (query.After is not null) + { + _ = builder.AddParameter("after", query.After.Value.ToString()); + } + + return await restClient.ExecuteRequestAsync> + ( + HttpMethod.Get, + builder.Build(), + b => b.WithSimpleRoute(TopLevelResource.Channel, channelId), + info, + ct + ); + } + + /// + public async ValueTask>> GetReactionsAsync + ( + Snowflake channelId, + Snowflake messageId, + string emoji, + GetReactionsQuery query = default, + RequestInfo info = default, + CancellationToken ct = default + ) + { + if (query.Limit is not null and (< 1 or > 100)) + { + return new ValidationError("The limit of reactions to request must be between 1 and 100."); + } + + QueryBuilder builder = new($"channels/{channelId}/messages/{messageId}/reactions/{emoji}"); + + if (query.After is not null) + { + _ = builder.AddParameter("after", query.After.Value.ToString()); + } + + if (query.Limit is not null) + { + _ = builder.AddParameter("limit", query.Limit.Value.ToString(CultureInfo.InvariantCulture)); + } + + if (query.Type is not null) + { + _ = builder.AddParameter("type", ((int)query.Type.Value).ToString(CultureInfo.InvariantCulture)); + } + + return await restClient.ExecuteRequestAsync> + ( + HttpMethod.Get, + builder.Build(), + b => b.WithSimpleRoute(TopLevelResource.Channel, channelId) + .WithRoute($"GET channels/{channelId}/messages/:message-id/reactions/:emoji"), + info, + ct + ); + } +} diff --git a/src/core/DSharpPlus.Internal.Rest/Extensions/ServiceCollectionExtensions.Registration.cs b/src/core/DSharpPlus.Internal.Rest/Extensions/ServiceCollectionExtensions.Registration.cs index 274188bd9e..817320e748 100644 --- a/src/core/DSharpPlus.Internal.Rest/Extensions/ServiceCollectionExtensions.Registration.cs +++ b/src/core/DSharpPlus.Internal.Rest/Extensions/ServiceCollectionExtensions.Registration.cs @@ -27,11 +27,8 @@ private static void RegisterSerialization(IServiceCollection services) options.AddModel(); options.AddModel(); options.AddModel(); - options.AddModel(); options.AddModel(); - options.AddModel(); options.AddModel(); - options.AddModel(); options.AddModel(); options.AddModel(); options.AddModel(); @@ -41,7 +38,9 @@ private static void RegisterSerialization(IServiceCollection services) options.AddModel(); options.AddModel(); options.AddModel(); + options.AddModel(); options.AddModel(); + options.AddModel(); options.AddModel(); options.AddModel(); options.AddModel(); @@ -67,6 +66,9 @@ private static void RegisterSerialization(IServiceCollection services) options.AddModel(); options.AddModel(); options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); options.AddModel(); options.AddModel(); options.AddModel(); diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Emojis/CreateApplicationEmojiPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Emojis/CreateApplicationEmojiPayload.cs new file mode 100644 index 0000000000..0480308d43 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Emojis/CreateApplicationEmojiPayload.cs @@ -0,0 +1,17 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Internal.Abstractions.Rest.Payloads; + +namespace DSharpPlus.Internal.Rest.Payloads; + +/// +public sealed record CreateApplicationEmojiPayload : ICreateApplicationEmojiPayload +{ + /// + public required string Name { get; init; } + + /// + public required ImageData Image { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Emojis/ModifyApplicationEmojiPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Emojis/ModifyApplicationEmojiPayload.cs new file mode 100644 index 0000000000..c961501d61 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Emojis/ModifyApplicationEmojiPayload.cs @@ -0,0 +1,14 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Internal.Abstractions.Rest.Payloads; + +namespace DSharpPlus.Internal.Rest.Payloads; + +/// +public sealed record ModifyApplicationEmojiPayload : IModifyApplicationEmojiPayload +{ + /// + public required string Name { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/BulkDeleteMessagesPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Messages/BulkDeleteMessagesPayload.cs similarity index 99% rename from src/core/DSharpPlus.Internal.Rest/Payloads/Channels/BulkDeleteMessagesPayload.cs rename to src/core/DSharpPlus.Internal.Rest/Payloads/Messages/BulkDeleteMessagesPayload.cs index c9e7802e42..af1c9237cb 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/BulkDeleteMessagesPayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Messages/BulkDeleteMessagesPayload.cs @@ -13,4 +13,4 @@ public sealed record BulkDeleteMessagesPayload : IBulkDeleteMessagesPayload { /// public required IReadOnlyList Messages { get; init; } -} +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/CreateMessagePayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Messages/CreateMessagePayload.cs similarity index 100% rename from src/core/DSharpPlus.Internal.Rest/Payloads/Channels/CreateMessagePayload.cs rename to src/core/DSharpPlus.Internal.Rest/Payloads/Messages/CreateMessagePayload.cs diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/EditMessagePayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Messages/EditMessagePayload.cs similarity index 100% rename from src/core/DSharpPlus.Internal.Rest/Payloads/Channels/EditMessagePayload.cs rename to src/core/DSharpPlus.Internal.Rest/Payloads/Messages/EditMessagePayload.cs diff --git a/src/core/DSharpPlus.Shared/Entities/Channels/DiscordAttachmentFlags.cs b/src/core/DSharpPlus.Shared/Entities/Messages/DiscordAttachmentFlags.cs similarity index 100% rename from src/core/DSharpPlus.Shared/Entities/Channels/DiscordAttachmentFlags.cs rename to src/core/DSharpPlus.Shared/Entities/Messages/DiscordAttachmentFlags.cs diff --git a/src/core/DSharpPlus.Shared/Entities/Channels/DiscordMessageActivityType.cs b/src/core/DSharpPlus.Shared/Entities/Messages/DiscordMessageActivityType.cs similarity index 100% rename from src/core/DSharpPlus.Shared/Entities/Channels/DiscordMessageActivityType.cs rename to src/core/DSharpPlus.Shared/Entities/Messages/DiscordMessageActivityType.cs diff --git a/src/core/DSharpPlus.Shared/Entities/Channels/DiscordMessageFlags.cs b/src/core/DSharpPlus.Shared/Entities/Messages/DiscordMessageFlags.cs similarity index 100% rename from src/core/DSharpPlus.Shared/Entities/Channels/DiscordMessageFlags.cs rename to src/core/DSharpPlus.Shared/Entities/Messages/DiscordMessageFlags.cs diff --git a/src/core/DSharpPlus.Shared/Entities/Messages/DiscordMessageReferenceType.cs b/src/core/DSharpPlus.Shared/Entities/Messages/DiscordMessageReferenceType.cs new file mode 100644 index 0000000000..b7bd6e2a7c --- /dev/null +++ b/src/core/DSharpPlus.Shared/Entities/Messages/DiscordMessageReferenceType.cs @@ -0,0 +1,21 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Entities; + +/// +/// Represents the type of a message reference. +/// +public enum DiscordMessageReferenceType +{ + /// + /// A standard reference used by replies. + /// + Default, + + /// + /// A reference used to point to a message at a certain point in time. + /// + Forward +} diff --git a/src/core/DSharpPlus.Shared/Entities/Channels/DiscordMessageType.cs b/src/core/DSharpPlus.Shared/Entities/Messages/DiscordMessageType.cs similarity index 100% rename from src/core/DSharpPlus.Shared/Entities/Channels/DiscordMessageType.cs rename to src/core/DSharpPlus.Shared/Entities/Messages/DiscordMessageType.cs diff --git a/src/extensions/DSharpPlus.Extensions.Internal.Builders/Extensions/ChannelRestAPIExtensions.cs b/src/extensions/DSharpPlus.Extensions.Internal.Builders/Extensions/MessageRestAPIExtensions.cs similarity index 91% rename from src/extensions/DSharpPlus.Extensions.Internal.Builders/Extensions/ChannelRestAPIExtensions.cs rename to src/extensions/DSharpPlus.Extensions.Internal.Builders/Extensions/MessageRestAPIExtensions.cs index 3666ce5b19..2d8f019cb4 100644 --- a/src/extensions/DSharpPlus.Extensions.Internal.Builders/Extensions/ChannelRestAPIExtensions.cs +++ b/src/extensions/DSharpPlus.Extensions.Internal.Builders/Extensions/MessageRestAPIExtensions.cs @@ -17,14 +17,14 @@ namespace DSharpPlus.Extensions.Internal.Builders.Extensions; /// -/// Contains extension methods on to enable using builders. +/// Contains extension methods on to enable using builders. /// -public static class ChannelRestAPIExtensions +public static class MessageRestAPIExtensions { /// /// Creates a new message comprising the specified embed in a channel. /// - /// The underlying channel API. + /// The underlying message API. /// The snowflake identifier of the message's target channel. /// The embed this message is to be comprised of. /// Additional instructions regarding this request. @@ -32,7 +32,7 @@ public static class ChannelRestAPIExtensions /// The newly created message object. public static async ValueTask> SendEmbedAsync ( - this IChannelRestAPI underlying, + this IMessageRestAPI underlying, Snowflake channelId, EmbedBuilder embed, RequestInfo info = default, @@ -61,7 +61,7 @@ public static async ValueTask> SendEmbedAsync /// /// Modifies the specified message to comprise the specified embed. This will only update embeds for this message. /// - /// The underlying channel API. + /// The underlying message API. /// The snowflake identifier of the channel this message was sent in. /// The snowflake identifier of the message to modify with the embed. /// The embed this message is to be comprised of. @@ -70,7 +70,7 @@ public static async ValueTask> SendEmbedAsync /// The newly modified message object. public static async ValueTask> ModifyEmbedAsync ( - this IChannelRestAPI underlying, + this IMessageRestAPI underlying, Snowflake channelId, Snowflake messageId, EmbedBuilder embed, diff --git a/tools/generators/copy-concrete-implementations.csx b/tools/generators/copy-concrete-implementations.csx index 7248976237..edcf0a8ee9 100644 --- a/tools/generators/copy-concrete-implementations.csx +++ b/tools/generators/copy-concrete-implementations.csx @@ -89,7 +89,7 @@ AnsiConsole.MarkupLine Extracts the required concrete types for DSharpPlus.Extensions.Internal.Builders to remove dependency on concrete implementations. """ -) +); if (changes.Removed.Any()) { From f6c1a706916b1c35538312a2014dd822ce8ffc57 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Thu, 1 Aug 2024 02:59:55 +0200 Subject: [PATCH 304/323] force crlf --- .gitattributes | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000000..a95dacdbdf --- /dev/null +++ b/.gitattributes @@ -0,0 +1,8 @@ +*.cs text eol=crlf +*.json text eol=crlf +*.txt text eol=crlf +*.md text eol=crlf +*.yml text eol=crlf +*.sln text eol=crlf +*.csproj text eol=crlf +.* text eol=crlf \ No newline at end of file From 22e3cbdfe6b9cc2fbe301bc5ffd64bdd0f61fbd7 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sun, 4 Aug 2024 13:29:26 +0200 Subject: [PATCH 305/323] test whether we aren't reading/writing out of bounds the debugger's immediate window really does not like this code --- Directory.Packages.props | 1 + .../DSharpPlus.Shared.Tests.csproj | 2 + .../Permissions/BoundTests.cs | 136 ++++++++++++++++++ .../Util/FactExceptOnlyOnWindowsAttribute.cs | 20 +++ 4 files changed, 159 insertions(+) create mode 100644 tests/core/DSharpPlus.Shared.Tests/Permissions/BoundTests.cs create mode 100644 tests/core/DSharpPlus.Shared.Tests/Util/FactExceptOnlyOnWindowsAttribute.cs diff --git a/Directory.Packages.props b/Directory.Packages.props index 9b6435602d..8802b7d6f3 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -18,6 +18,7 @@ + diff --git a/tests/core/DSharpPlus.Shared.Tests/DSharpPlus.Shared.Tests.csproj b/tests/core/DSharpPlus.Shared.Tests/DSharpPlus.Shared.Tests.csproj index 34a3846b99..d3c1b9fec8 100644 --- a/tests/core/DSharpPlus.Shared.Tests/DSharpPlus.Shared.Tests.csproj +++ b/tests/core/DSharpPlus.Shared.Tests/DSharpPlus.Shared.Tests.csproj @@ -3,6 +3,7 @@ net9.0 enable + true false true @@ -11,6 +12,7 @@ + all diff --git a/tests/core/DSharpPlus.Shared.Tests/Permissions/BoundTests.cs b/tests/core/DSharpPlus.Shared.Tests/Permissions/BoundTests.cs new file mode 100644 index 0000000000..91cf5eb0c6 --- /dev/null +++ b/tests/core/DSharpPlus.Shared.Tests/Permissions/BoundTests.cs @@ -0,0 +1,136 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +// if you find youself here, my condolences. +// here we test whether we read or write out of bounds at any point. currently, these tests work only on windows +// (because i was too lazy to write allocation code for linux, this just uses terrafx on windows), and they're not very +// pleasant to run, but avoiding out of bounds memory accesses is probably worth it. +// also, yes, i am aware this leaks memory. for some reason beyond my comprehension, VirtualFree fails with the error message +// "success". and since this is a test type that will be torn down soon enough, and it's only 12kb, it's not the end of the +// world to leak this here. + +using System; +using System.Runtime.CompilerServices; +using System.Runtime.Versioning; + +using DSharpPlus.Entities; +using DSharpPlus.Shared.Tests.Util; + +using TerraFX.Interop.Windows; + +using Xunit; + +namespace DSharpPlus.Shared.Tests.Permissions; + +[SupportedOSPlatform("windows")] +public sealed unsafe class BoundTests +{ + private readonly byte* usableAllocation; + + public BoundTests() + { + nuint zero = nuint.Zero; + uint _; + + // allocate three pages, immediately commit them and mark them as NO_ACCESS + void* allocHandle = Windows.VirtualAlloc + ( + lpAddress: (void*)zero, + dwSize: (nuint)(3 * Environment.SystemPageSize), + flAllocationType: 0x3000, // RESERVE and COMMIT + flProtect: 0x1 // NO_ACCESS + ); + + if (allocHandle == null || allocHandle == (void*)nuint.Zero) + { + throw new InvalidOperationException($"Failed to allocate three sequential pages. Handle: {(nuint)allocHandle}"); + } + + // we allocated successfully, now mark the middle page as READWRITE + + BOOL success = Windows.VirtualProtect + ( + lpAddress: (byte*)allocHandle + Environment.SystemPageSize, + dwSize: (nuint)Environment.SystemPageSize, + flNewProtect: 0x4, // READWRITE + lpflOldProtect: &_ + ); + + if (success != BOOL.TRUE) + { + throw new InvalidOperationException("Failed to patch protection status of the middle page."); + } + + // everything is successful, store the pointers for use in tests + + this.usableAllocation = (byte*)allocHandle + Environment.SystemPageSize; + } + + private static int GetLength() => 16; + + private ref DiscordPermissions AllocateStart() + => ref Unsafe.As(ref Unsafe.AsRef(this.usableAllocation)); + + private ref DiscordPermissions AllocateEnd() + { + return ref Unsafe.As + ( + ref Unsafe.AsRef(this.usableAllocation + Environment.SystemPageSize - GetLength()) + ); + } + + [FactExceptOnlyOnWindows] + public void VectorOpsInBounds_MemoryRegionStart() + { + try + { + // this includes the OR operator + scoped ref DiscordPermissions permissionsAdd = ref this.AllocateStart(); + permissionsAdd += (DiscordPermission)117; + + scoped ref DiscordPermissions permissionsRemove = ref this.AllocateStart(); + permissionsRemove -= (DiscordPermission)117; + + scoped ref DiscordPermissions permissionsNegate = ref this.AllocateStart(); + permissionsNegate = ~permissionsNegate; + + scoped ref DiscordPermissions permissionsAnd = ref this.AllocateStart(); + permissionsAnd &= DiscordPermissions.All; + + scoped ref DiscordPermissions permissionsXor = ref this.AllocateStart(); + permissionsXor ^= DiscordPermissions.All; + } + catch (AccessViolationException) + { + Assert.Fail("Access violation thrown, a starting boundary has been violated."); + } + } + + [FactExceptOnlyOnWindows] + public void VectorOpsInBounds_MemoryRegionEnd() + { + try + { + // this includes the OR operator + scoped ref DiscordPermissions permissionsAdd = ref this.AllocateEnd(); + permissionsAdd += (DiscordPermission)117; + + scoped ref DiscordPermissions permissionsRemove = ref this.AllocateEnd(); + permissionsRemove -= (DiscordPermission)117; + + scoped ref DiscordPermissions permissionsNegate = ref this.AllocateEnd(); + permissionsNegate = ~permissionsNegate; + + scoped ref DiscordPermissions permissionsAnd = ref this.AllocateEnd(); + permissionsAnd &= DiscordPermissions.All; + + scoped ref DiscordPermissions permissionsXor = ref this.AllocateEnd(); + permissionsXor ^= DiscordPermissions.All; + } + catch (AccessViolationException) + { + Assert.Fail("Access violation thrown, an ending boundary has been violated."); + } + } +} diff --git a/tests/core/DSharpPlus.Shared.Tests/Util/FactExceptOnlyOnWindowsAttribute.cs b/tests/core/DSharpPlus.Shared.Tests/Util/FactExceptOnlyOnWindowsAttribute.cs new file mode 100644 index 0000000000..1fe3d2bcf0 --- /dev/null +++ b/tests/core/DSharpPlus.Shared.Tests/Util/FactExceptOnlyOnWindowsAttribute.cs @@ -0,0 +1,20 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; + +using Xunit; + +namespace DSharpPlus.Shared.Tests.Util; + +internal sealed class FactExceptOnlyOnWindowsAttribute : FactAttribute +{ + public FactExceptOnlyOnWindowsAttribute() + { + if (!OperatingSystem.IsWindows()) + { + Skip = "Ignored on non-Windows platforms."; + } + } +} From f690de7a4e8f3fb1ee666a4c860070bdacdc5b51 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Mon, 5 Aug 2024 00:22:54 +0200 Subject: [PATCH 306/323] let users shoot themselves in the foot :shipit: --- .../RequiresRestRequestLoggingAttribute.cs | 15 +++++++++ .../RuntimeFeatures/RestRequestLogging.cs | 31 +++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 src/core/DSharpPlus.Shared/Runtime/RuntimeFeatures/RequiresRestRequestLoggingAttribute.cs create mode 100644 src/core/DSharpPlus.Shared/Runtime/RuntimeFeatures/RestRequestLogging.cs diff --git a/src/core/DSharpPlus.Shared/Runtime/RuntimeFeatures/RequiresRestRequestLoggingAttribute.cs b/src/core/DSharpPlus.Shared/Runtime/RuntimeFeatures/RequiresRestRequestLoggingAttribute.cs new file mode 100644 index 0000000000..675d86d7e0 --- /dev/null +++ b/src/core/DSharpPlus.Shared/Runtime/RuntimeFeatures/RequiresRestRequestLoggingAttribute.cs @@ -0,0 +1,15 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; + +namespace DSharpPlus.Runtime.RuntimeFeatures; + +/// +/// This attribute causes code to be trimmed or ignored at JIT time conditional on the feature switch +/// DSharpPlus.DisableRestRequestLogging. +/// +/// +[AttributeUsage(AttributeTargets.All, Inherited = true)] +public sealed class RequiresRestRequestLoggingAttribute : Attribute; diff --git a/src/core/DSharpPlus.Shared/Runtime/RuntimeFeatures/RestRequestLogging.cs b/src/core/DSharpPlus.Shared/Runtime/RuntimeFeatures/RestRequestLogging.cs new file mode 100644 index 0000000000..b609fb6bc1 --- /dev/null +++ b/src/core/DSharpPlus.Shared/Runtime/RuntimeFeatures/RestRequestLogging.cs @@ -0,0 +1,31 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; +using System.Diagnostics.CodeAnalysis; + +namespace DSharpPlus.Runtime.RuntimeFeatures; + +/// +/// Contains the runtime feature switch for logging rest request data. +/// +public static class RestRequestLogging +{ + /// + /// Indicates to the library whether rest request contents should be logged. This feature switch can be controlled + /// from csproj files, where it will enable trimming the relevant code, and from runtimeconfig.json. + /// + /// + /// Enabling this switch will have catastrophic consequences for debugging issues related to rest requests and should + /// only ever be considered if there is concrete evidence to back it up.

+ /// This switch, if enabled in the project file, will enable trimming all related code away:
+ /// + /// ]]> + /// + ///
+ [FeatureSwitchDefinition("DSharpPlus.DisableRestRequestLogging")] + [FeatureGuard(typeof(RequiresRestRequestLoggingAttribute))] + public static bool IsEnabled + => !AppContext.TryGetSwitch("DSharpPlus.DisableRestRequestLogging", out bool enabled) || !enabled; +} From b2fc65b90f6f6456285e90af924d519f5b2463b9 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Thu, 8 Aug 2024 00:14:03 +0200 Subject: [PATCH 307/323] slnx is so beautiful --- DSharpPlus.sln | 95 ------------------------------------------------- DSharpPlus.slnx | 23 ++++++++++++ 2 files changed, 23 insertions(+), 95 deletions(-) delete mode 100644 DSharpPlus.sln create mode 100644 DSharpPlus.slnx diff --git a/DSharpPlus.sln b/DSharpPlus.sln deleted file mode 100644 index c6fa9254f4..0000000000 --- a/DSharpPlus.sln +++ /dev/null @@ -1,95 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 17 -VisualStudioVersion = 17.0.31903.59 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DSharpPlus.Internal.Models", "src\core\DSharpPlus.Internal.Models\DSharpPlus.Internal.Models.csproj", "{FBCCE5A7-0E07-4FCF-B9BB-B913F5A17FB2}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DSharpPlus.Shared", "src\core\DSharpPlus.Shared\DSharpPlus.Shared.csproj", "{964AD252-F077-4AB5-8D92-6C594D08F078}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DSharpPlus.Internal.Abstractions.Models", "src\core\DSharpPlus.Internal.Abstractions.Models\DSharpPlus.Internal.Abstractions.Models.csproj", "{E14B0AE9-FE71-4DE4-BEB1-4A8E139DB84C}" -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Core", "Core", "{BC8D8750-48A4-49EF-9D1F-BE4DBA5B500E}" -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{EAE89CF5-AA91-4A22-9949-A46FAE1BF0D0}" -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Core", "Core", "{21927A64-7345-4D90-9EE2-7FA4B1973AAC}" -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Generators", "Generators", "{5FBB4590-56B0-453B-A87B-08A17C599B5C}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DSharpPlus.SourceGenerators.Common", "gen\common\DSharpPlus.SourceGenerators.Common.csproj", "{98D2C52C-E3BA-4564-919C-750775B7BA9C}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DSharpPlus.Internal.Models.Tests", "tests\core\DSharpPlus.Internal.Models.Tests\DSharpPlus.Internal.Models.Tests.csproj", "{9F25D892-3CB0-4D47-B67D-D3FFFADC03E0}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DSharpPlus.Internal.Abstractions.Rest", "src\core\DSharpPlus.Internal.Abstractions.Rest\DSharpPlus.Internal.Abstractions.Rest.csproj", "{CD440954-E19A-4E94-A217-CCC1DC4AF095}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DSharpPlus.Internal.Rest", "src\core\DSharpPlus.Internal.Rest\DSharpPlus.Internal.Rest.csproj", "{9CEC3D27-9014-48B6-910F-D25233BF8C44}" -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Extensions", "Extensions", "{96A3D7EF-3576-423C-9529-60C8AE319C15}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DSharpPlus.Extensions.Internal.Builders", "src\extensions\DSharpPlus.Extensions.Internal.Builders\DSharpPlus.Extensions.Internal.Builders.csproj", "{7A6F0CF2-2BB9-4AAC-95EC-8640A06DD17B}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DSharpPlus.Shared.Tests", "tests\core\DSharpPlus.Shared.Tests\DSharpPlus.Shared.Tests.csproj", "{E0EB9E13-D33A-4C2A-BB87-09D2B706597A}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {FBCCE5A7-0E07-4FCF-B9BB-B913F5A17FB2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {FBCCE5A7-0E07-4FCF-B9BB-B913F5A17FB2}.Debug|Any CPU.Build.0 = Debug|Any CPU - {FBCCE5A7-0E07-4FCF-B9BB-B913F5A17FB2}.Release|Any CPU.ActiveCfg = Release|Any CPU - {FBCCE5A7-0E07-4FCF-B9BB-B913F5A17FB2}.Release|Any CPU.Build.0 = Release|Any CPU - {964AD252-F077-4AB5-8D92-6C594D08F078}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {964AD252-F077-4AB5-8D92-6C594D08F078}.Debug|Any CPU.Build.0 = Debug|Any CPU - {964AD252-F077-4AB5-8D92-6C594D08F078}.Release|Any CPU.ActiveCfg = Release|Any CPU - {964AD252-F077-4AB5-8D92-6C594D08F078}.Release|Any CPU.Build.0 = Release|Any CPU - {E14B0AE9-FE71-4DE4-BEB1-4A8E139DB84C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {E14B0AE9-FE71-4DE4-BEB1-4A8E139DB84C}.Debug|Any CPU.Build.0 = Debug|Any CPU - {E14B0AE9-FE71-4DE4-BEB1-4A8E139DB84C}.Release|Any CPU.ActiveCfg = Release|Any CPU - {E14B0AE9-FE71-4DE4-BEB1-4A8E139DB84C}.Release|Any CPU.Build.0 = Release|Any CPU - {98D2C52C-E3BA-4564-919C-750775B7BA9C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {98D2C52C-E3BA-4564-919C-750775B7BA9C}.Debug|Any CPU.Build.0 = Debug|Any CPU - {98D2C52C-E3BA-4564-919C-750775B7BA9C}.Release|Any CPU.ActiveCfg = Release|Any CPU - {98D2C52C-E3BA-4564-919C-750775B7BA9C}.Release|Any CPU.Build.0 = Release|Any CPU - {9F25D892-3CB0-4D47-B67D-D3FFFADC03E0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {9F25D892-3CB0-4D47-B67D-D3FFFADC03E0}.Debug|Any CPU.Build.0 = Debug|Any CPU - {9F25D892-3CB0-4D47-B67D-D3FFFADC03E0}.Release|Any CPU.ActiveCfg = Release|Any CPU - {9F25D892-3CB0-4D47-B67D-D3FFFADC03E0}.Release|Any CPU.Build.0 = Release|Any CPU - {CD440954-E19A-4E94-A217-CCC1DC4AF095}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {CD440954-E19A-4E94-A217-CCC1DC4AF095}.Debug|Any CPU.Build.0 = Debug|Any CPU - {CD440954-E19A-4E94-A217-CCC1DC4AF095}.Release|Any CPU.ActiveCfg = Release|Any CPU - {CD440954-E19A-4E94-A217-CCC1DC4AF095}.Release|Any CPU.Build.0 = Release|Any CPU - {9CEC3D27-9014-48B6-910F-D25233BF8C44}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {9CEC3D27-9014-48B6-910F-D25233BF8C44}.Debug|Any CPU.Build.0 = Debug|Any CPU - {9CEC3D27-9014-48B6-910F-D25233BF8C44}.Release|Any CPU.ActiveCfg = Release|Any CPU - {9CEC3D27-9014-48B6-910F-D25233BF8C44}.Release|Any CPU.Build.0 = Release|Any CPU - {7A6F0CF2-2BB9-4AAC-95EC-8640A06DD17B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {7A6F0CF2-2BB9-4AAC-95EC-8640A06DD17B}.Debug|Any CPU.Build.0 = Debug|Any CPU - {7A6F0CF2-2BB9-4AAC-95EC-8640A06DD17B}.Release|Any CPU.ActiveCfg = Release|Any CPU - {7A6F0CF2-2BB9-4AAC-95EC-8640A06DD17B}.Release|Any CPU.Build.0 = Release|Any CPU - {E0EB9E13-D33A-4C2A-BB87-09D2B706597A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {E0EB9E13-D33A-4C2A-BB87-09D2B706597A}.Debug|Any CPU.Build.0 = Debug|Any CPU - {E0EB9E13-D33A-4C2A-BB87-09D2B706597A}.Release|Any CPU.ActiveCfg = Release|Any CPU - {E0EB9E13-D33A-4C2A-BB87-09D2B706597A}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(NestedProjects) = preSolution - {FBCCE5A7-0E07-4FCF-B9BB-B913F5A17FB2} = {BC8D8750-48A4-49EF-9D1F-BE4DBA5B500E} - {964AD252-F077-4AB5-8D92-6C594D08F078} = {BC8D8750-48A4-49EF-9D1F-BE4DBA5B500E} - {E14B0AE9-FE71-4DE4-BEB1-4A8E139DB84C} = {BC8D8750-48A4-49EF-9D1F-BE4DBA5B500E} - {21927A64-7345-4D90-9EE2-7FA4B1973AAC} = {EAE89CF5-AA91-4A22-9949-A46FAE1BF0D0} - {98D2C52C-E3BA-4564-919C-750775B7BA9C} = {5FBB4590-56B0-453B-A87B-08A17C599B5C} - {9F25D892-3CB0-4D47-B67D-D3FFFADC03E0} = {21927A64-7345-4D90-9EE2-7FA4B1973AAC} - {CD440954-E19A-4E94-A217-CCC1DC4AF095} = {BC8D8750-48A4-49EF-9D1F-BE4DBA5B500E} - {9CEC3D27-9014-48B6-910F-D25233BF8C44} = {BC8D8750-48A4-49EF-9D1F-BE4DBA5B500E} - {7A6F0CF2-2BB9-4AAC-95EC-8640A06DD17B} = {96A3D7EF-3576-423C-9529-60C8AE319C15} - {E0EB9E13-D33A-4C2A-BB87-09D2B706597A} = {21927A64-7345-4D90-9EE2-7FA4B1973AAC} - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {55CDA684-8900-479B-9DAE-BA3BE09B337B} - EndGlobalSection -EndGlobal diff --git a/DSharpPlus.slnx b/DSharpPlus.slnx new file mode 100644 index 0000000000..df70f0171c --- /dev/null +++ b/DSharpPlus.slnx @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + + From 64e4b10796ca9f526b9f3215828501829e362cad Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Fri, 9 Aug 2024 15:41:25 +0200 Subject: [PATCH 308/323] support recurring events and fetching voice states over http --- DSharpPlus.slnx | 18 ++-- .../ScheduledEvents/IPartialScheduledEvent.cs | 5 + .../ScheduledEvents/IScheduledEvent.cs | 6 ++ .../IScheduledEventRecurrenceDay.cs | 23 ++++ .../IScheduledEventRecurrenceRule.cs | 101 ++++++++++++++++++ .../API/IGuildRestAPI.cs | 32 ------ .../API/IVoiceRestAPI.cs | 61 +++++++++++ .../ICreateGuildScheduledEventPayload.cs | 5 + .../IModifyGuildScheduledEventPayload.cs | 5 + .../IModifyCurrentUserVoiceStatePayload.cs | 0 .../IModifyUserVoiceStatePayload.cs | 0 ...erviceCollectionExtensions.Registration.cs | 2 + .../Extensions/ServiceCollectionExtensions.cs | 1 + .../ScheduledEvents/PartialScheduledEvent.cs | 5 +- .../ScheduledEvents/ScheduledEvent.cs | 5 +- .../ScheduledEventRecurrenceDay.cs | 18 ++++ .../ScheduledEventRecurrenceRule.cs | 45 ++++++++ .../Converters}/ImageDataConverter.cs | 0 .../API/GuildRestAPI.cs | 46 -------- .../API/VoiceRestAPI.cs | 86 +++++++++++++++ ...erviceCollectionExtensions.Registration.cs | 4 +- .../CreateGuildScheduledEventPayload.cs | 3 + .../ModifyGuildScheduledEventPayload.cs | 3 + .../ModifyCurrentUserVoiceStatePayload.cs | 2 +- .../ModifyUserVoiceStatePayload.cs | 2 +- ...iscordScheduledEventRecurrenceFrequency.cs | 16 +++ .../DiscordScheduledEventRecurrenceMonth.cs | 24 +++++ .../DiscordScheduledEventRecurrenceWeekday.cs | 19 ++++ 28 files changed, 444 insertions(+), 93 deletions(-) create mode 100644 src/core/DSharpPlus.Internal.Abstractions.Models/ScheduledEvents/IScheduledEventRecurrenceDay.cs create mode 100644 src/core/DSharpPlus.Internal.Abstractions.Models/ScheduledEvents/IScheduledEventRecurrenceRule.cs rename src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/{Guilds => Voice}/IModifyCurrentUserVoiceStatePayload.cs (100%) rename src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/{Guilds => Voice}/IModifyUserVoiceStatePayload.cs (100%) create mode 100644 src/core/DSharpPlus.Internal.Models/ScheduledEvents/ScheduledEventRecurrenceDay.cs create mode 100644 src/core/DSharpPlus.Internal.Models/ScheduledEvents/ScheduledEventRecurrenceRule.cs rename src/core/{DSharpPlus.Shared/Serialization => DSharpPlus.Internal.Models/Serialization/Converters}/ImageDataConverter.cs (100%) rename src/core/DSharpPlus.Internal.Rest/Payloads/{Guilds => Voice}/ModifyCurrentUserVoiceStatePayload.cs (99%) rename src/core/DSharpPlus.Internal.Rest/Payloads/{Guilds => Voice}/ModifyUserVoiceStatePayload.cs (99%) create mode 100644 src/core/DSharpPlus.Shared/Entities/ScheduledEvents/DiscordScheduledEventRecurrenceFrequency.cs create mode 100644 src/core/DSharpPlus.Shared/Entities/ScheduledEvents/DiscordScheduledEventRecurrenceMonth.cs create mode 100644 src/core/DSharpPlus.Shared/Entities/ScheduledEvents/DiscordScheduledEventRecurrenceWeekday.cs diff --git a/DSharpPlus.slnx b/DSharpPlus.slnx index df70f0171c..8e3564ba39 100644 --- a/DSharpPlus.slnx +++ b/DSharpPlus.slnx @@ -1,21 +1,21 @@ - - - - - + + + + + - + - + - - + + diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/ScheduledEvents/IPartialScheduledEvent.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/ScheduledEvents/IPartialScheduledEvent.cs index 76b9752b6e..7cfef139a1 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Models/ScheduledEvents/IPartialScheduledEvent.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/ScheduledEvents/IPartialScheduledEvent.cs @@ -85,4 +85,9 @@ public interface IPartialScheduledEvent /// The cover image hash of this event. ///
public Optional Image { get; } + + /// + /// A definition for how often and at what dates this event should recur. + /// + public Optional RecurrenceRule { get; } } diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/ScheduledEvents/IScheduledEvent.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/ScheduledEvents/IScheduledEvent.cs index 286dde9c1a..7069682ab7 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Models/ScheduledEvents/IScheduledEvent.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/ScheduledEvents/IScheduledEvent.cs @@ -37,6 +37,9 @@ public interface IScheduledEvent : IPartialScheduledEvent /// public new DiscordScheduledEventType EntityType { get; } + /// + public new IScheduledEventRecurrenceRule? RecurrenceRule { get; } + // partial access routes /// @@ -62,4 +65,7 @@ public interface IScheduledEvent : IPartialScheduledEvent /// Optional IPartialScheduledEvent.EntityType => this.EntityType; + + /// + Optional IPartialScheduledEvent.RecurrenceRule => new(this.RecurrenceRule); } diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/ScheduledEvents/IScheduledEventRecurrenceDay.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/ScheduledEvents/IScheduledEventRecurrenceDay.cs new file mode 100644 index 0000000000..286074fab8 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/ScheduledEvents/IScheduledEventRecurrenceDay.cs @@ -0,0 +1,23 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Entities; + +namespace DSharpPlus.Internal.Abstractions.Models; + +/// +/// Describes which day within a month an event should recur on. +/// +public interface IScheduledEventRecurrenceDay +{ + /// + /// The week of the month this recurrence point refers to. Restricted to 1-5. + /// + public int N { get; } + + /// + /// The day of the specified week to recur at. + /// + public DiscordScheduledEventRecurrenceWeekday Day { get; } +} diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/ScheduledEvents/IScheduledEventRecurrenceRule.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/ScheduledEvents/IScheduledEventRecurrenceRule.cs new file mode 100644 index 0000000000..e49859129b --- /dev/null +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/ScheduledEvents/IScheduledEventRecurrenceRule.cs @@ -0,0 +1,101 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; +using System.Collections.Generic; + +using DSharpPlus.Entities; + +namespace DSharpPlus.Internal.Abstractions.Models; + +/// +/// Represents a rule for recurring scheduled events. This is a subset of the +/// iCalendar specification and has some rather specific +/// limitations, documented where appropriate. +/// +public interface IScheduledEventRecurrenceRule +{ + /// + /// Specifies the starting time of the recurrence interval. + /// + public DateTimeOffset Start { get; } + + /// + /// Specifies the ending time of the recurrence interval. This cannot be set by the application. + /// + public DateTimeOffset End { get; } + + /// + /// Specifies how often this event should occur. + /// + public DiscordScheduledEventRecurrenceFrequency Frequency { get; } + + /// + /// Specifies the interval according to . For example, a frequency of + /// with an interval of 2 would mean "every other week". + /// + public int Interval { get; } + + /// + /// Specifies a set of specific days within a week to recur on. This is mutually exclusive with + /// and + . + /// + /// + /// This field is only valid for daily and weekly events according to . However, it also + /// behaves differently depending on the frequency:

+ /// IF the frequency is set to , the values must be a + /// "known set" of weekdays. The following sets are currently allowed:
+ /// - Monday to Friday
+ /// - Tuesday to Saturday
+ /// - Sunday to Thursday
+ /// - Friday and Saturday
+ /// - Saturday and Sunday
+ /// - Sunday and Monday

+ /// IF the frequency is set to , the array must have + /// a length of 1, so only one weekday can have a recurring event on. If you wish to have an event recur on multiple + /// days within a week, use a daily-frequency event. + ///
+ public IReadOnlyList? ByWeekday { get; } + + /// + /// Specifies a set of specific days within a month to recur on. This is mutually exclusive with + /// and + + /// + /// + /// This field is only valid for monthly events according to . It may only contain + /// a single element. + /// + public IReadOnlyList? ByNWeekday { get; } + + /// + /// Specifies a set of months within a year to recur in. This is mutually exclusive with + /// and and requires to also be specified. + /// + /// + /// This field is only valid for yearly events according to . It may only contain a single + /// element. + /// + public IReadOnlyList? ByMonth { get; } + + /// + /// Specifies a date within a month to recur on. This is mutually exclusive with and + /// and requires to also be specified. + /// + /// + /// This field is only valid for yearly events according to . It may only contain a single + /// element. + /// + public IReadOnlyList? ByMonthDay { get; } + + /// + /// Specifies the set of days within the year to recur on. This cannot be set by the application. + /// + public IReadOnlyList? ByYearDay { get; } + + /// + /// Specifies the total amount of times this event is allowed to recur before stopping. This cannot be set by the + /// application. + /// + public int? Count { get; } +} diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IGuildRestAPI.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IGuildRestAPI.cs index 0e67705e22..0fca953c99 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IGuildRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IGuildRestAPI.cs @@ -734,36 +734,4 @@ public ValueTask> ModifyGuildOnboardingAsync RequestInfo info = default, CancellationToken ct = default ); - - /// - /// Modifies the current user's stage voice state. - /// - /// The snowflake identifier of the guild everything takes place in. - /// Information on how to update the current voice state. - /// Additional instructions regarding this request. - /// A cancellation token for this operation. - public ValueTask ModifyCurrentUserVoiceStateAsync - ( - Snowflake guildId, - IModifyCurrentUserVoiceStatePayload payload, - RequestInfo info = default, - CancellationToken ct = default - ); - - /// - /// Modifies another user's stage voice state. - /// - /// The snowflake identifier of the guild everything takes place in. - /// The snowflake identifier of the user whose voice state to modify. - /// Information on how to modify the user's voice state. - /// Additional instructions regarding this request. - /// A cancellation token for this operation. - public ValueTask ModifyUserVoiceStateAsync - ( - Snowflake guildId, - Snowflake userId, - IModifyUserVoiceStatePayload payload, - RequestInfo info = default, - CancellationToken ct = default - ); } diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IVoiceRestAPI.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IVoiceRestAPI.cs index e382754c7d..a36746472b 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IVoiceRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IVoiceRestAPI.cs @@ -7,6 +7,7 @@ using System.Threading.Tasks; using DSharpPlus.Internal.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Rest.Payloads; using DSharpPlus.Results; namespace DSharpPlus.Internal.Abstractions.Rest.API; @@ -26,4 +27,64 @@ public ValueTask>> ListVoiceRegionsAsync RequestInfo info = default, CancellationToken ct = default ); + + /// + /// Returns the current user's voice state in the specified guild. + /// + /// The snowflake identifier of the specified guild. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public ValueTask> GetCurrentUserVoiceStateAsync + ( + Snowflake guildId, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Returns the specified user's voice state in the specified guild. + /// + /// The snowflake identifier specifying the guild. + /// The snowflake identifier specifying the user. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public ValueTask> GetUserVoiceStateAsync + ( + Snowflake guildId, + Snowflake userId, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Modifies the current user's voice state. + /// + /// The snowflake identifier of the guild everything takes place in. + /// Information on how to update the current voice state. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public ValueTask ModifyCurrentUserVoiceStateAsync + ( + Snowflake guildId, + IModifyCurrentUserVoiceStatePayload payload, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Modifies another user's voice state. + /// + /// The snowflake identifier of the guild everything takes place in. + /// The snowflake identifier of the user whose voice state to modify. + /// Information on how to modify the user's voice state. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public ValueTask ModifyUserVoiceStateAsync + ( + Snowflake guildId, + Snowflake userId, + IModifyUserVoiceStatePayload payload, + RequestInfo info = default, + CancellationToken ct = default + ); } diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/ScheduledEvents/ICreateGuildScheduledEventPayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/ScheduledEvents/ICreateGuildScheduledEventPayload.cs index 64c3ae654d..2370e23f76 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/ScheduledEvents/ICreateGuildScheduledEventPayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/ScheduledEvents/ICreateGuildScheduledEventPayload.cs @@ -58,4 +58,9 @@ public interface ICreateGuildScheduledEventPayload /// Image data representing the cover image of this scheduled event. ///
public Optional Image { get; } + + /// + /// A definition for how often and at what dates this event should recur. + /// + public Optional RecurrenceRule { get; } } diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/ScheduledEvents/IModifyGuildScheduledEventPayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/ScheduledEvents/IModifyGuildScheduledEventPayload.cs index 2177aef84a..9db0dd3926 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/ScheduledEvents/IModifyGuildScheduledEventPayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/ScheduledEvents/IModifyGuildScheduledEventPayload.cs @@ -63,4 +63,9 @@ public interface IModifyGuildScheduledEventPayload /// Image data representing the cover image of this scheduled event. ///
public Optional Image { get; } + + /// + /// A definition for how often and at what dates this event should recur. + /// + public Optional RecurrenceRule { get; } } diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Guilds/IModifyCurrentUserVoiceStatePayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Voice/IModifyCurrentUserVoiceStatePayload.cs similarity index 100% rename from src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Guilds/IModifyCurrentUserVoiceStatePayload.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Voice/IModifyCurrentUserVoiceStatePayload.cs diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Guilds/IModifyUserVoiceStatePayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Voice/IModifyUserVoiceStatePayload.cs similarity index 100% rename from src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Guilds/IModifyUserVoiceStatePayload.cs rename to src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Voice/IModifyUserVoiceStatePayload.cs diff --git a/src/core/DSharpPlus.Internal.Models/Extensions/ServiceCollectionExtensions.Registration.cs b/src/core/DSharpPlus.Internal.Models/Extensions/ServiceCollectionExtensions.Registration.cs index 875c8a0364..d0a0f5ef9e 100644 --- a/src/core/DSharpPlus.Internal.Models/Extensions/ServiceCollectionExtensions.Registration.cs +++ b/src/core/DSharpPlus.Internal.Models/Extensions/ServiceCollectionExtensions.Registration.cs @@ -131,6 +131,8 @@ private static void RegisterSerialization(IServiceCollection services) options.AddModel(); options.AddModel(); options.AddModel(); + options.AddModel(); + options.AddModel(); options.AddModel(); options.AddModel(); options.AddModel(); diff --git a/src/core/DSharpPlus.Internal.Models/Extensions/ServiceCollectionExtensions.cs b/src/core/DSharpPlus.Internal.Models/Extensions/ServiceCollectionExtensions.cs index a9ae755870..3aaf86afbc 100644 --- a/src/core/DSharpPlus.Internal.Models/Extensions/ServiceCollectionExtensions.cs +++ b/src/core/DSharpPlus.Internal.Models/Extensions/ServiceCollectionExtensions.cs @@ -42,6 +42,7 @@ public static IServiceCollection RegisterDiscordModelSerialization options.Converters.Add(new OptionalConverterFactory()); options.Converters.Add(new SnowflakeConverter()); options.Converters.Add(new OneOfConverterFactory()); + options.Converters.Add(new ImageDataConverter()); options.Converters.Add(new AuditLogChangeConverter()); options.Converters.Add(new AutoModerationActionConverter()); diff --git a/src/core/DSharpPlus.Internal.Models/ScheduledEvents/PartialScheduledEvent.cs b/src/core/DSharpPlus.Internal.Models/ScheduledEvents/PartialScheduledEvent.cs index a066f26948..24d7dacc7c 100644 --- a/src/core/DSharpPlus.Internal.Models/ScheduledEvents/PartialScheduledEvent.cs +++ b/src/core/DSharpPlus.Internal.Models/ScheduledEvents/PartialScheduledEvent.cs @@ -50,4 +50,7 @@ public sealed record PartialScheduledEvent : IPartialScheduledEvent /// public Optional Image { get; init; } -} + + /// + public Optional RecurrenceRule { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Models/ScheduledEvents/ScheduledEvent.cs b/src/core/DSharpPlus.Internal.Models/ScheduledEvents/ScheduledEvent.cs index 10555dd4c3..1f07522c52 100644 --- a/src/core/DSharpPlus.Internal.Models/ScheduledEvents/ScheduledEvent.cs +++ b/src/core/DSharpPlus.Internal.Models/ScheduledEvents/ScheduledEvent.cs @@ -50,4 +50,7 @@ public sealed record ScheduledEvent : IScheduledEvent /// public Optional Image { get; init; } -} + + /// + public IScheduledEventRecurrenceRule? RecurrenceRule { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Models/ScheduledEvents/ScheduledEventRecurrenceDay.cs b/src/core/DSharpPlus.Internal.Models/ScheduledEvents/ScheduledEventRecurrenceDay.cs new file mode 100644 index 0000000000..7228288fd2 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Models/ScheduledEvents/ScheduledEventRecurrenceDay.cs @@ -0,0 +1,18 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; + +namespace DSharpPlus.Internal.Models; + +/// +public sealed record ScheduledEventRecurrenceDay : IScheduledEventRecurrenceDay +{ + /// + public required int N { get; init; } + + /// + public required DiscordScheduledEventRecurrenceWeekday Day { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Models/ScheduledEvents/ScheduledEventRecurrenceRule.cs b/src/core/DSharpPlus.Internal.Models/ScheduledEvents/ScheduledEventRecurrenceRule.cs new file mode 100644 index 0000000000..523c60e6d5 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Models/ScheduledEvents/ScheduledEventRecurrenceRule.cs @@ -0,0 +1,45 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; +using System.Collections.Generic; + +using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; + +namespace DSharpPlus.Internal.Models; + +/// +public sealed record ScheduledEventRecurrenceRule : IScheduledEventRecurrenceRule +{ + /// + public required DateTimeOffset Start { get; init; } + + /// + public required DateTimeOffset End { get; init; } + + /// + public required DiscordScheduledEventRecurrenceFrequency Frequency { get; init; } + + /// + public required int Interval { get; init; } + + /// + public IReadOnlyList? ByWeekday { get; init; } + + /// + public IReadOnlyList? ByNWeekday { get; init; } + + /// + public IReadOnlyList? ByMonth { get; init; } + + /// + public IReadOnlyList? ByMonthDay { get; init; } + + /// + public IReadOnlyList? ByYearDay { get; init; } + + /// + public int? Count { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Shared/Serialization/ImageDataConverter.cs b/src/core/DSharpPlus.Internal.Models/Serialization/Converters/ImageDataConverter.cs similarity index 100% rename from src/core/DSharpPlus.Shared/Serialization/ImageDataConverter.cs rename to src/core/DSharpPlus.Internal.Models/Serialization/Converters/ImageDataConverter.cs diff --git a/src/core/DSharpPlus.Internal.Rest/API/GuildRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/GuildRestAPI.cs index bb1ca226b4..e4a0633364 100644 --- a/src/core/DSharpPlus.Internal.Rest/API/GuildRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Rest/API/GuildRestAPI.cs @@ -746,28 +746,6 @@ public async ValueTask> ModifyCurrentMemberAsync ); } - /// - public async ValueTask ModifyCurrentUserVoiceStateAsync - ( - Snowflake guildId, - IModifyCurrentUserVoiceStatePayload payload, - RequestInfo info = default, - CancellationToken ct = default - ) - { - Result response = await restClient.ExecuteRequestAsync - ( - HttpMethod.Patch, - $"guilds/{guildId}/voice-states/@me", - b => b.WithSimpleRoute(TopLevelResource.Guild, guildId) - .WithPayload(payload), - info, - ct - ); - - return (Result)response; - } - /// public async ValueTask> ModifyGuildAsync ( @@ -995,30 +973,6 @@ public async ValueTask> ModifyGuildWidgetAsync ); } - /// - public async ValueTask ModifyUserVoiceStateAsync - ( - Snowflake guildId, - Snowflake userId, - IModifyUserVoiceStatePayload payload, - RequestInfo info = default, - CancellationToken ct = default - ) - { - Result response = await restClient.ExecuteRequestAsync - ( - HttpMethod.Patch, - $"guilds/{guildId}/voice-states/{userId}", - b => b.WithSimpleRoute(TopLevelResource.Guild, guildId) - .WithRoute($"PATCH guilds/{guildId}/voice-states/:user-id") - .WithPayload(payload), - info, - ct - ); - - return (Result)response; - } - /// public async ValueTask RemoveGuildBanAsync ( diff --git a/src/core/DSharpPlus.Internal.Rest/API/VoiceRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/VoiceRestAPI.cs index bfa930c76d..8becbef7ae 100644 --- a/src/core/DSharpPlus.Internal.Rest/API/VoiceRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Rest/API/VoiceRestAPI.cs @@ -10,6 +10,8 @@ using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Internal.Abstractions.Rest; using DSharpPlus.Internal.Abstractions.Rest.API; +using DSharpPlus.Internal.Abstractions.Rest.Payloads; +using DSharpPlus.Internal.Rest.Ratelimiting; using DSharpPlus.Results; namespace DSharpPlus.Internal.Rest.API; @@ -18,6 +20,44 @@ namespace DSharpPlus.Internal.Rest.API; public sealed class VoiceRestAPI(IRestClient restClient) : IVoiceRestAPI { + /// + public async ValueTask> GetCurrentUserVoiceStateAsync + ( + Snowflake guildId, + RequestInfo info = default, + CancellationToken ct = default + ) + { + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Get, + $"guilds/{guildId}/voice-states/@me", + b => b.WithSimpleRoute(TopLevelResource.Guild, guildId), + info, + ct + ); + } + + /// + public async ValueTask> GetUserVoiceStateAsync + ( + Snowflake guildId, + Snowflake userId, + RequestInfo info = default, + CancellationToken ct = default + ) + { + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Get, + $"guilds/{guildId}/voice-states/{userId}", + b => b.WithSimpleRoute(TopLevelResource.Guild, guildId) + .WithRoute($"GET guilds/{guildId}/voice-states/:user-id"), + info, + ct + ); + } + /// public async ValueTask>> ListVoiceRegionsAsync ( @@ -34,4 +74,50 @@ public async ValueTask>> ListVoiceRegionsAsyn ct ); } + + /// + public async ValueTask ModifyCurrentUserVoiceStateAsync + ( + Snowflake guildId, + IModifyCurrentUserVoiceStatePayload payload, + RequestInfo info = default, + CancellationToken ct = default + ) + { + Result response = await restClient.ExecuteRequestAsync + ( + HttpMethod.Patch, + $"guilds/{guildId}/voice-states/@me", + b => b.WithSimpleRoute(TopLevelResource.Guild, guildId) + .WithPayload(payload), + info, + ct + ); + + return (Result)response; + } + + /// + public async ValueTask ModifyUserVoiceStateAsync + ( + Snowflake guildId, + Snowflake userId, + IModifyUserVoiceStatePayload payload, + RequestInfo info = default, + CancellationToken ct = default + ) + { + Result response = await restClient.ExecuteRequestAsync + ( + HttpMethod.Patch, + $"guilds/{guildId}/voice-states/{userId}", + b => b.WithSimpleRoute(TopLevelResource.Guild, guildId) + .WithRoute($"PATCH guilds/{guildId}/voice-states/:user-id") + .WithPayload(payload), + info, + ct + ); + + return (Result)response; + } } diff --git a/src/core/DSharpPlus.Internal.Rest/Extensions/ServiceCollectionExtensions.Registration.cs b/src/core/DSharpPlus.Internal.Rest/Extensions/ServiceCollectionExtensions.Registration.cs index 817320e748..fdd7a046ee 100644 --- a/src/core/DSharpPlus.Internal.Rest/Extensions/ServiceCollectionExtensions.Registration.cs +++ b/src/core/DSharpPlus.Internal.Rest/Extensions/ServiceCollectionExtensions.Registration.cs @@ -50,7 +50,6 @@ private static void RegisterSerialization(IServiceCollection services) options.AddModel(); options.AddModel(); options.AddModel(); - options.AddModel(); options.AddModel(); options.AddModel(); options.AddModel(); @@ -59,7 +58,6 @@ private static void RegisterSerialization(IServiceCollection services) options.AddModel(); options.AddModel(); options.AddModel(); - options.AddModel(); options.AddModel(); options.AddModel(); options.AddModel(); @@ -79,6 +77,8 @@ private static void RegisterSerialization(IServiceCollection services) options.AddModel(); options.AddModel(); options.AddModel(); + options.AddModel(); + options.AddModel(); options.AddModel(); options.AddModel(); options.AddModel(); diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/ScheduledEvents/CreateGuildScheduledEventPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/ScheduledEvents/CreateGuildScheduledEventPayload.cs index 878f4cff20..1518227adc 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/ScheduledEvents/CreateGuildScheduledEventPayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/ScheduledEvents/CreateGuildScheduledEventPayload.cs @@ -39,4 +39,7 @@ public sealed record CreateGuildScheduledEventPayload : ICreateGuildScheduledEve /// public Optional Image { get; init; } + + /// + public Optional RecurrenceRule { get; init; } } \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/ScheduledEvents/ModifyGuildScheduledEventPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/ScheduledEvents/ModifyGuildScheduledEventPayload.cs index 6ffa92f810..81c51131a9 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/ScheduledEvents/ModifyGuildScheduledEventPayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/ScheduledEvents/ModifyGuildScheduledEventPayload.cs @@ -42,4 +42,7 @@ public sealed record ModifyGuildScheduledEventPayload : IModifyGuildScheduledEve /// public Optional Image { get; init; } + + /// + public Optional RecurrenceRule { get; init; } } \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyCurrentUserVoiceStatePayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Voice/ModifyCurrentUserVoiceStatePayload.cs similarity index 99% rename from src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyCurrentUserVoiceStatePayload.cs rename to src/core/DSharpPlus.Internal.Rest/Payloads/Voice/ModifyCurrentUserVoiceStatePayload.cs index 9979c5bf0f..8599d8dfb6 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyCurrentUserVoiceStatePayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Voice/ModifyCurrentUserVoiceStatePayload.cs @@ -19,4 +19,4 @@ public sealed record ModifyCurrentUserVoiceStatePayload : IModifyCurrentUserVoic /// public Optional RequestToSpeakTimestamp { get; init; } -} +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyUserVoiceStatePayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Voice/ModifyUserVoiceStatePayload.cs similarity index 99% rename from src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyUserVoiceStatePayload.cs rename to src/core/DSharpPlus.Internal.Rest/Payloads/Voice/ModifyUserVoiceStatePayload.cs index a861f58679..aaf8c9c3f4 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyUserVoiceStatePayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Voice/ModifyUserVoiceStatePayload.cs @@ -14,4 +14,4 @@ public sealed record ModifyUserVoiceStatePayload : IModifyUserVoiceStatePayload /// public Optional Suppress { get; init; } -} +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Shared/Entities/ScheduledEvents/DiscordScheduledEventRecurrenceFrequency.cs b/src/core/DSharpPlus.Shared/Entities/ScheduledEvents/DiscordScheduledEventRecurrenceFrequency.cs new file mode 100644 index 0000000000..12ed55f278 --- /dev/null +++ b/src/core/DSharpPlus.Shared/Entities/ScheduledEvents/DiscordScheduledEventRecurrenceFrequency.cs @@ -0,0 +1,16 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Entities; + +/// +/// Specifies the frequency of a recurrence rule. +/// +public enum DiscordScheduledEventRecurrenceFrequency +{ + Yearly, + Monthly, + Weekly, + Daily +} diff --git a/src/core/DSharpPlus.Shared/Entities/ScheduledEvents/DiscordScheduledEventRecurrenceMonth.cs b/src/core/DSharpPlus.Shared/Entities/ScheduledEvents/DiscordScheduledEventRecurrenceMonth.cs new file mode 100644 index 0000000000..222ab44a6b --- /dev/null +++ b/src/core/DSharpPlus.Shared/Entities/ScheduledEvents/DiscordScheduledEventRecurrenceMonth.cs @@ -0,0 +1,24 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Entities; + +/// +/// Specifies months to recur on. +/// +public enum DiscordScheduledEventRecurrenceMonth +{ + January = 1, + February, + March, + April, + May, + June, + July, + August, + September, + October, + November, + December +} diff --git a/src/core/DSharpPlus.Shared/Entities/ScheduledEvents/DiscordScheduledEventRecurrenceWeekday.cs b/src/core/DSharpPlus.Shared/Entities/ScheduledEvents/DiscordScheduledEventRecurrenceWeekday.cs new file mode 100644 index 0000000000..231709d00d --- /dev/null +++ b/src/core/DSharpPlus.Shared/Entities/ScheduledEvents/DiscordScheduledEventRecurrenceWeekday.cs @@ -0,0 +1,19 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Entities; + +/// +/// Specifies weekdays to recur on. +/// +public enum DiscordScheduledEventRecurrenceWeekday +{ + Monday, + Tuesday, + Wednesday, + Thursday, + Friday, + Saturday, + Sunday +} From 2312824a48c8e8daa1fd794b2ac283cbd28f3673 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sun, 11 Aug 2024 20:35:27 +0200 Subject: [PATCH 309/323] restructure toolbox and add a recurrence rule helper --- DSharpPlus.slnx | 18 +- Directory.Build.props | 4 +- ...types.json => toolbox-concrete-types.json} | 2 + .../IScheduledEventRecurrenceRule.cs | 5 +- .../ScheduledEventRecurrenceRule.cs | 2 +- .../Builders}/Interactions/ModalBuilder.cs | 6 +- .../Interactions/TextInputComponentBuilder.cs | 0 .../Builders}/Messages/EmbedBuilder.cs | 6 +- ...rpPlus.Extensions.Internal.Toolbox.csproj} | 8 +- .../Errors/BuilderValidationError.cs | 2 +- .../InteractionRestAPIExtensions.cs | 8 +- .../Extensions/MessageRestAPIExtensions.cs | 6 +- .../BuiltActionRowComponent.cs | 2 +- .../BuiltCreateFollowupMessagePayload.cs | 2 +- .../BuiltCreateMessagePayload.cs | 4 +- .../BuiltEditFollowupMessagePayload.cs | 2 +- .../BuiltEditInteractionResponsePayload.cs | 2 +- .../BuiltEditMessagePayload.cs | 2 +- .../Implementations/BuiltEmbed.cs | 4 +- .../BuiltInteractionResponse.cs | 2 +- .../BuiltMessageCallbackData.cs | 2 +- .../Implementations/BuiltModalCallbackData.cs | 2 +- .../BuiltScheduledEventRecurrenceDay.cs | 18 ++ .../BuiltScheduledEventRecurrenceRule.cs | 45 +++++ .../BuiltTextInputComponent.cs | 2 +- .../RecurrenceRule.cs | 189 ++++++++++++++++++ src/extensions/DSharpPlus.Extensions.sln | 10 +- .../copy-concrete-implementations.csx | 21 +- 28 files changed, 311 insertions(+), 65 deletions(-) rename meta/{builder-concrete-types.json => toolbox-concrete-types.json} (83%) rename src/extensions/{DSharpPlus.Extensions.Internal.Builders => DSharpPlus.Extensions.Internal.Toolbox/Builders}/Interactions/ModalBuilder.cs (96%) rename src/extensions/{DSharpPlus.Extensions.Internal.Builders => DSharpPlus.Extensions.Internal.Toolbox/Builders}/Interactions/TextInputComponentBuilder.cs (100%) rename src/extensions/{DSharpPlus.Extensions.Internal.Builders => DSharpPlus.Extensions.Internal.Toolbox/Builders}/Messages/EmbedBuilder.cs (97%) rename src/extensions/{DSharpPlus.Extensions.Internal.Builders/DSharpPlus.Extensions.Internal.Builders.csproj => DSharpPlus.Extensions.Internal.Toolbox/DSharpPlus.Extensions.Internal.Toolbox.csproj} (58%) rename src/extensions/{DSharpPlus.Extensions.Internal.Builders => DSharpPlus.Extensions.Internal.Toolbox}/Errors/BuilderValidationError.cs (96%) rename src/extensions/{DSharpPlus.Extensions.Internal.Builders => DSharpPlus.Extensions.Internal.Toolbox}/Extensions/InteractionRestAPIExtensions.cs (97%) rename src/extensions/{DSharpPlus.Extensions.Internal.Builders => DSharpPlus.Extensions.Internal.Toolbox}/Extensions/MessageRestAPIExtensions.cs (94%) rename src/extensions/{DSharpPlus.Extensions.Internal.Builders => DSharpPlus.Extensions.Internal.Toolbox}/Implementations/BuiltActionRowComponent.cs (90%) rename src/extensions/{DSharpPlus.Extensions.Internal.Builders => DSharpPlus.Extensions.Internal.Toolbox}/Implementations/BuiltCreateFollowupMessagePayload.cs (95%) rename src/extensions/{DSharpPlus.Extensions.Internal.Builders => DSharpPlus.Extensions.Internal.Toolbox}/Implementations/BuiltCreateMessagePayload.cs (95%) rename src/extensions/{DSharpPlus.Extensions.Internal.Builders => DSharpPlus.Extensions.Internal.Toolbox}/Implementations/BuiltEditFollowupMessagePayload.cs (93%) rename src/extensions/{DSharpPlus.Extensions.Internal.Builders => DSharpPlus.Extensions.Internal.Toolbox}/Implementations/BuiltEditInteractionResponsePayload.cs (94%) rename src/extensions/{DSharpPlus.Extensions.Internal.Builders => DSharpPlus.Extensions.Internal.Toolbox}/Implementations/BuiltEditMessagePayload.cs (94%) rename src/extensions/{DSharpPlus.Extensions.Internal.Builders => DSharpPlus.Extensions.Internal.Toolbox}/Implementations/BuiltEmbed.cs (95%) rename src/extensions/{DSharpPlus.Extensions.Internal.Builders => DSharpPlus.Extensions.Internal.Toolbox}/Implementations/BuiltInteractionResponse.cs (90%) rename src/extensions/{DSharpPlus.Extensions.Internal.Builders => DSharpPlus.Extensions.Internal.Toolbox}/Implementations/BuiltMessageCallbackData.cs (94%) rename src/extensions/{DSharpPlus.Extensions.Internal.Builders => DSharpPlus.Extensions.Internal.Toolbox}/Implementations/BuiltModalCallbackData.cs (90%) create mode 100644 src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Implementations/BuiltScheduledEventRecurrenceDay.cs create mode 100644 src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Implementations/BuiltScheduledEventRecurrenceRule.cs rename src/extensions/{DSharpPlus.Extensions.Internal.Builders => DSharpPlus.Extensions.Internal.Toolbox}/Implementations/BuiltTextInputComponent.cs (94%) create mode 100644 src/extensions/DSharpPlus.Extensions.Internal.Toolbox/RecurrenceRule.cs diff --git a/DSharpPlus.slnx b/DSharpPlus.slnx index 8e3564ba39..330d47c7cc 100644 --- a/DSharpPlus.slnx +++ b/DSharpPlus.slnx @@ -1,21 +1,21 @@ - - - - - + + + + + - + - + - - + + diff --git a/Directory.Build.props b/Directory.Build.props index 28e6c79a0a..7d0079626a 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -53,8 +53,8 @@ - - <_DSharpPlusExtensionsInternalBuildersVersion>0.1.0 + + <_DSharpPlusExtensionsInternalToolboxVersion>0.1.0 \ No newline at end of file diff --git a/meta/builder-concrete-types.json b/meta/toolbox-concrete-types.json similarity index 83% rename from meta/builder-concrete-types.json rename to meta/toolbox-concrete-types.json index bab9a23cd0..727616e1d6 100644 --- a/meta/builder-concrete-types.json +++ b/meta/toolbox-concrete-types.json @@ -5,6 +5,8 @@ "./src/core/DSharpPlus.Internal.Models/Interactions/MessageCallbackData.cs", "./src/core/DSharpPlus.Internal.Models/MessageComponents/ActionRowComponent.cs", "./src/core/DSharpPlus.Internal.Models/MessageComponents/TextInputComponent.cs", + "./src/core/DSharpPlus.Internal.Models/ScheduledEvents/ScheduledEventRecurrenceDay.cs", + "./src/core/DSharpPlus.Internal.Models/ScheduledEvents/ScheduledEventRecurrenceRule.cs", "./src/core/DSharpPlus.Internal.Rest/Payloads/Messages/CreateMessagePayload.cs", "./src/core/DSharpPlus.Internal.Rest/Payloads/Messages/EditMessagePayload.cs", "./src/core/DSharpPlus.Internal.Rest/Payloads/Interactions/CreateFollowupMessagePayload.cs", diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/ScheduledEvents/IScheduledEventRecurrenceRule.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/ScheduledEvents/IScheduledEventRecurrenceRule.cs index e49859129b..26992d04a4 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Models/ScheduledEvents/IScheduledEventRecurrenceRule.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/ScheduledEvents/IScheduledEventRecurrenceRule.cs @@ -24,7 +24,7 @@ public interface IScheduledEventRecurrenceRule /// /// Specifies the ending time of the recurrence interval. This cannot be set by the application. /// - public DateTimeOffset End { get; } + public DateTimeOffset? End { get; } /// /// Specifies how often this event should occur. @@ -35,6 +35,9 @@ public interface IScheduledEventRecurrenceRule /// Specifies the interval according to . For example, a frequency of /// with an interval of 2 would mean "every other week". /// + /// + /// This can only be set to 1 or 2 (not higher) for weekly events, and exactly 1 for all other events. + /// public int Interval { get; } /// diff --git a/src/core/DSharpPlus.Internal.Models/ScheduledEvents/ScheduledEventRecurrenceRule.cs b/src/core/DSharpPlus.Internal.Models/ScheduledEvents/ScheduledEventRecurrenceRule.cs index 523c60e6d5..d8bfa9fab8 100644 --- a/src/core/DSharpPlus.Internal.Models/ScheduledEvents/ScheduledEventRecurrenceRule.cs +++ b/src/core/DSharpPlus.Internal.Models/ScheduledEvents/ScheduledEventRecurrenceRule.cs @@ -17,7 +17,7 @@ public sealed record ScheduledEventRecurrenceRule : IScheduledEventRecurrenceRul public required DateTimeOffset Start { get; init; } /// - public required DateTimeOffset End { get; init; } + public DateTimeOffset? End { get; init; } /// public required DiscordScheduledEventRecurrenceFrequency Frequency { get; init; } diff --git a/src/extensions/DSharpPlus.Extensions.Internal.Builders/Interactions/ModalBuilder.cs b/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Builders/Interactions/ModalBuilder.cs similarity index 96% rename from src/extensions/DSharpPlus.Extensions.Internal.Builders/Interactions/ModalBuilder.cs rename to src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Builders/Interactions/ModalBuilder.cs index ae68c416df..b0e59633ed 100644 --- a/src/extensions/DSharpPlus.Extensions.Internal.Builders/Interactions/ModalBuilder.cs +++ b/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Builders/Interactions/ModalBuilder.cs @@ -9,12 +9,12 @@ using System.Linq; using DSharpPlus.Entities; -using DSharpPlus.Extensions.Internal.Builders.Errors; -using DSharpPlus.Extensions.Internal.Builders.Implementations; +using DSharpPlus.Extensions.Internal.Toolbox.Errors; +using DSharpPlus.Extensions.Internal.Toolbox.Implementations; using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Results; -namespace DSharpPlus.Extensions.Internal.Builders.Interactions; +namespace DSharpPlus.Extensions.Internal.Toolbox.Builders.Interactions; /// /// Represents a modal under construction. diff --git a/src/extensions/DSharpPlus.Extensions.Internal.Builders/Interactions/TextInputComponentBuilder.cs b/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Builders/Interactions/TextInputComponentBuilder.cs similarity index 100% rename from src/extensions/DSharpPlus.Extensions.Internal.Builders/Interactions/TextInputComponentBuilder.cs rename to src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Builders/Interactions/TextInputComponentBuilder.cs diff --git a/src/extensions/DSharpPlus.Extensions.Internal.Builders/Messages/EmbedBuilder.cs b/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Builders/Messages/EmbedBuilder.cs similarity index 97% rename from src/extensions/DSharpPlus.Extensions.Internal.Builders/Messages/EmbedBuilder.cs rename to src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Builders/Messages/EmbedBuilder.cs index cc99bda35e..92a197daf5 100644 --- a/src/extensions/DSharpPlus.Extensions.Internal.Builders/Messages/EmbedBuilder.cs +++ b/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Builders/Messages/EmbedBuilder.cs @@ -7,13 +7,13 @@ using System; using System.Collections.Generic; -using DSharpPlus.Extensions.Internal.Builders.Errors; -using DSharpPlus.Extensions.Internal.Builders.Implementations; +using DSharpPlus.Extensions.Internal.Toolbox.Errors; +using DSharpPlus.Extensions.Internal.Toolbox.Implementations; using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Results; -namespace DSharpPlus.Extensions.Internal.Builders.Messages; +namespace DSharpPlus.Extensions.Internal.Toolbox.Builders.Messages; /// /// Represents an currently under construction. diff --git a/src/extensions/DSharpPlus.Extensions.Internal.Builders/DSharpPlus.Extensions.Internal.Builders.csproj b/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/DSharpPlus.Extensions.Internal.Toolbox.csproj similarity index 58% rename from src/extensions/DSharpPlus.Extensions.Internal.Builders/DSharpPlus.Extensions.Internal.Builders.csproj rename to src/extensions/DSharpPlus.Extensions.Internal.Toolbox/DSharpPlus.Extensions.Internal.Toolbox.csproj index 69875d9aca..4ceab133be 100644 --- a/src/extensions/DSharpPlus.Extensions.Internal.Builders/DSharpPlus.Extensions.Internal.Builders.csproj +++ b/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/DSharpPlus.Extensions.Internal.Toolbox.csproj @@ -1,11 +1,9 @@  - $(_DSharpPlusExtensionsInternalBuildersVersion) - - $(Description) This package provides useful builder utilities for working directly with the internal models. - - Library + net9.0 + enable + $(_DSharpPlusExtensionsInternalToolboxVersion) diff --git a/src/extensions/DSharpPlus.Extensions.Internal.Builders/Errors/BuilderValidationError.cs b/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Errors/BuilderValidationError.cs similarity index 96% rename from src/extensions/DSharpPlus.Extensions.Internal.Builders/Errors/BuilderValidationError.cs rename to src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Errors/BuilderValidationError.cs index f35c4ac2aa..51773eda31 100644 --- a/src/extensions/DSharpPlus.Extensions.Internal.Builders/Errors/BuilderValidationError.cs +++ b/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Errors/BuilderValidationError.cs @@ -9,7 +9,7 @@ using DSharpPlus.Results.Errors; -namespace DSharpPlus.Extensions.Internal.Builders.Errors; +namespace DSharpPlus.Extensions.Internal.Toolbox.Errors; /// /// Represents an error encountered when attempting to validate a builder. diff --git a/src/extensions/DSharpPlus.Extensions.Internal.Builders/Extensions/InteractionRestAPIExtensions.cs b/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Extensions/InteractionRestAPIExtensions.cs similarity index 97% rename from src/extensions/DSharpPlus.Extensions.Internal.Builders/Extensions/InteractionRestAPIExtensions.cs rename to src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Extensions/InteractionRestAPIExtensions.cs index 770eaf62da..40dd9b9a85 100644 --- a/src/extensions/DSharpPlus.Extensions.Internal.Builders/Extensions/InteractionRestAPIExtensions.cs +++ b/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Extensions/InteractionRestAPIExtensions.cs @@ -10,15 +10,15 @@ using System.Threading.Tasks; using DSharpPlus.Entities; -using DSharpPlus.Extensions.Internal.Builders.Implementations; -using DSharpPlus.Extensions.Internal.Builders.Interactions; -using DSharpPlus.Extensions.Internal.Builders.Messages; +using DSharpPlus.Extensions.Internal.Toolbox.Implementations; +using DSharpPlus.Extensions.Internal.Toolbox.Builders.Interactions; +using DSharpPlus.Extensions.Internal.Toolbox.Builders.Messages; using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Internal.Abstractions.Rest; using DSharpPlus.Internal.Abstractions.Rest.API; using DSharpPlus.Results; -namespace DSharpPlus.Extensions.Internal.Builders.Extensions; +namespace DSharpPlus.Extensions.Internal.Toolbox.Extensions; /// /// Contains extension methods on to enable using builders. diff --git a/src/extensions/DSharpPlus.Extensions.Internal.Builders/Extensions/MessageRestAPIExtensions.cs b/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Extensions/MessageRestAPIExtensions.cs similarity index 94% rename from src/extensions/DSharpPlus.Extensions.Internal.Builders/Extensions/MessageRestAPIExtensions.cs rename to src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Extensions/MessageRestAPIExtensions.cs index 2d8f019cb4..1824866757 100644 --- a/src/extensions/DSharpPlus.Extensions.Internal.Builders/Extensions/MessageRestAPIExtensions.cs +++ b/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Extensions/MessageRestAPIExtensions.cs @@ -7,14 +7,14 @@ using System.Threading; using System.Threading.Tasks; -using DSharpPlus.Extensions.Internal.Builders.Implementations; -using DSharpPlus.Extensions.Internal.Builders.Messages; +using DSharpPlus.Extensions.Internal.Toolbox.Implementations; +using DSharpPlus.Extensions.Internal.Toolbox.Builders.Messages; using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Internal.Abstractions.Rest; using DSharpPlus.Internal.Abstractions.Rest.API; using DSharpPlus.Results; -namespace DSharpPlus.Extensions.Internal.Builders.Extensions; +namespace DSharpPlus.Extensions.Internal.Toolbox.Extensions; /// /// Contains extension methods on to enable using builders. diff --git a/src/extensions/DSharpPlus.Extensions.Internal.Builders/Implementations/BuiltActionRowComponent.cs b/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Implementations/BuiltActionRowComponent.cs similarity index 90% rename from src/extensions/DSharpPlus.Extensions.Internal.Builders/Implementations/BuiltActionRowComponent.cs rename to src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Implementations/BuiltActionRowComponent.cs index 787d50e3ae..1a62140dd1 100644 --- a/src/extensions/DSharpPlus.Extensions.Internal.Builders/Implementations/BuiltActionRowComponent.cs +++ b/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Implementations/BuiltActionRowComponent.cs @@ -7,7 +7,7 @@ using DSharpPlus.Entities; using DSharpPlus.Internal.Abstractions.Models; -namespace DSharpPlus.Extensions.Internal.Builders.Implementations; +namespace DSharpPlus.Extensions.Internal.Toolbox.Implementations; /// internal sealed record BuiltActionRowComponent : IActionRowComponent diff --git a/src/extensions/DSharpPlus.Extensions.Internal.Builders/Implementations/BuiltCreateFollowupMessagePayload.cs b/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Implementations/BuiltCreateFollowupMessagePayload.cs similarity index 95% rename from src/extensions/DSharpPlus.Extensions.Internal.Builders/Implementations/BuiltCreateFollowupMessagePayload.cs rename to src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Implementations/BuiltCreateFollowupMessagePayload.cs index 819d6d30fa..338b3d2923 100644 --- a/src/extensions/DSharpPlus.Extensions.Internal.Builders/Implementations/BuiltCreateFollowupMessagePayload.cs +++ b/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Implementations/BuiltCreateFollowupMessagePayload.cs @@ -8,7 +8,7 @@ using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Internal.Abstractions.Rest.Payloads; -namespace DSharpPlus.Extensions.Internal.Builders.Implementations; +namespace DSharpPlus.Extensions.Internal.Toolbox.Implementations; /// internal sealed record BuiltCreateFollowupMessagePayload : ICreateFollowupMessagePayload diff --git a/src/extensions/DSharpPlus.Extensions.Internal.Builders/Implementations/BuiltCreateMessagePayload.cs b/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Implementations/BuiltCreateMessagePayload.cs similarity index 95% rename from src/extensions/DSharpPlus.Extensions.Internal.Builders/Implementations/BuiltCreateMessagePayload.cs rename to src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Implementations/BuiltCreateMessagePayload.cs index db432fcbf8..787e1dc6a3 100644 --- a/src/extensions/DSharpPlus.Extensions.Internal.Builders/Implementations/BuiltCreateMessagePayload.cs +++ b/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Implementations/BuiltCreateMessagePayload.cs @@ -8,7 +8,7 @@ using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Internal.Abstractions.Rest.Payloads; -namespace DSharpPlus.Extensions.Internal.Builders.Implementations; +namespace DSharpPlus.Extensions.Internal.Toolbox.Implementations; /// internal sealed record BuiltCreateMessagePayload : ICreateMessagePayload @@ -51,4 +51,4 @@ internal sealed record BuiltCreateMessagePayload : ICreateMessagePayload /// public Optional Poll { get; init; } -} \ No newline at end of file +} diff --git a/src/extensions/DSharpPlus.Extensions.Internal.Builders/Implementations/BuiltEditFollowupMessagePayload.cs b/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Implementations/BuiltEditFollowupMessagePayload.cs similarity index 93% rename from src/extensions/DSharpPlus.Extensions.Internal.Builders/Implementations/BuiltEditFollowupMessagePayload.cs rename to src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Implementations/BuiltEditFollowupMessagePayload.cs index 1411bd3d7a..b845ed5657 100644 --- a/src/extensions/DSharpPlus.Extensions.Internal.Builders/Implementations/BuiltEditFollowupMessagePayload.cs +++ b/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Implementations/BuiltEditFollowupMessagePayload.cs @@ -7,7 +7,7 @@ using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Internal.Abstractions.Rest.Payloads; -namespace DSharpPlus.Extensions.Internal.Builders.Implementations; +namespace DSharpPlus.Extensions.Internal.Toolbox.Implementations; /// internal sealed record BuiltEditFollowupMessagePayload : IEditFollowupMessagePayload diff --git a/src/extensions/DSharpPlus.Extensions.Internal.Builders/Implementations/BuiltEditInteractionResponsePayload.cs b/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Implementations/BuiltEditInteractionResponsePayload.cs similarity index 94% rename from src/extensions/DSharpPlus.Extensions.Internal.Builders/Implementations/BuiltEditInteractionResponsePayload.cs rename to src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Implementations/BuiltEditInteractionResponsePayload.cs index 2403856706..440f774b67 100644 --- a/src/extensions/DSharpPlus.Extensions.Internal.Builders/Implementations/BuiltEditInteractionResponsePayload.cs +++ b/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Implementations/BuiltEditInteractionResponsePayload.cs @@ -7,7 +7,7 @@ using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Internal.Abstractions.Rest.Payloads; -namespace DSharpPlus.Extensions.Internal.Builders.Implementations; +namespace DSharpPlus.Extensions.Internal.Toolbox.Implementations; /// internal sealed record BuiltEditInteractionResponsePayload : IEditInteractionResponsePayload diff --git a/src/extensions/DSharpPlus.Extensions.Internal.Builders/Implementations/BuiltEditMessagePayload.cs b/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Implementations/BuiltEditMessagePayload.cs similarity index 94% rename from src/extensions/DSharpPlus.Extensions.Internal.Builders/Implementations/BuiltEditMessagePayload.cs rename to src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Implementations/BuiltEditMessagePayload.cs index 19c0943100..4e5a430fcd 100644 --- a/src/extensions/DSharpPlus.Extensions.Internal.Builders/Implementations/BuiltEditMessagePayload.cs +++ b/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Implementations/BuiltEditMessagePayload.cs @@ -8,7 +8,7 @@ using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Internal.Abstractions.Rest.Payloads; -namespace DSharpPlus.Extensions.Internal.Builders.Implementations; +namespace DSharpPlus.Extensions.Internal.Toolbox.Implementations; /// internal sealed record BuiltEditMessagePayload : IEditMessagePayload diff --git a/src/extensions/DSharpPlus.Extensions.Internal.Builders/Implementations/BuiltEmbed.cs b/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Implementations/BuiltEmbed.cs similarity index 95% rename from src/extensions/DSharpPlus.Extensions.Internal.Builders/Implementations/BuiltEmbed.cs rename to src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Implementations/BuiltEmbed.cs index c482c18f3e..208ede0923 100644 --- a/src/extensions/DSharpPlus.Extensions.Internal.Builders/Implementations/BuiltEmbed.cs +++ b/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Implementations/BuiltEmbed.cs @@ -7,7 +7,7 @@ using DSharpPlus.Internal.Abstractions.Models; -namespace DSharpPlus.Extensions.Internal.Builders.Implementations; +namespace DSharpPlus.Extensions.Internal.Toolbox.Implementations; /// internal sealed record BuiltEmbed : IEmbed @@ -50,4 +50,4 @@ internal sealed record BuiltEmbed : IEmbed /// public Optional> Fields { get; init; } -} +} \ No newline at end of file diff --git a/src/extensions/DSharpPlus.Extensions.Internal.Builders/Implementations/BuiltInteractionResponse.cs b/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Implementations/BuiltInteractionResponse.cs similarity index 90% rename from src/extensions/DSharpPlus.Extensions.Internal.Builders/Implementations/BuiltInteractionResponse.cs rename to src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Implementations/BuiltInteractionResponse.cs index b6bd35b0db..935bc66e6e 100644 --- a/src/extensions/DSharpPlus.Extensions.Internal.Builders/Implementations/BuiltInteractionResponse.cs +++ b/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Implementations/BuiltInteractionResponse.cs @@ -7,7 +7,7 @@ using OneOf; -namespace DSharpPlus.Extensions.Internal.Builders.Implementations; +namespace DSharpPlus.Extensions.Internal.Toolbox.Implementations; /// internal sealed record BuiltInteractionResponse : IInteractionResponse diff --git a/src/extensions/DSharpPlus.Extensions.Internal.Builders/Implementations/BuiltMessageCallbackData.cs b/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Implementations/BuiltMessageCallbackData.cs similarity index 94% rename from src/extensions/DSharpPlus.Extensions.Internal.Builders/Implementations/BuiltMessageCallbackData.cs rename to src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Implementations/BuiltMessageCallbackData.cs index 4af05b433f..b0ed649ad1 100644 --- a/src/extensions/DSharpPlus.Extensions.Internal.Builders/Implementations/BuiltMessageCallbackData.cs +++ b/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Implementations/BuiltMessageCallbackData.cs @@ -7,7 +7,7 @@ using DSharpPlus.Entities; using DSharpPlus.Internal.Abstractions.Models; -namespace DSharpPlus.Extensions.Internal.Builders.Implementations; +namespace DSharpPlus.Extensions.Internal.Toolbox.Implementations; /// internal sealed record BuiltMessageCallbackData : IMessageCallbackData diff --git a/src/extensions/DSharpPlus.Extensions.Internal.Builders/Implementations/BuiltModalCallbackData.cs b/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Implementations/BuiltModalCallbackData.cs similarity index 90% rename from src/extensions/DSharpPlus.Extensions.Internal.Builders/Implementations/BuiltModalCallbackData.cs rename to src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Implementations/BuiltModalCallbackData.cs index 3d62263f97..f3f8749c77 100644 --- a/src/extensions/DSharpPlus.Extensions.Internal.Builders/Implementations/BuiltModalCallbackData.cs +++ b/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Implementations/BuiltModalCallbackData.cs @@ -6,7 +6,7 @@ using DSharpPlus.Internal.Abstractions.Models; -namespace DSharpPlus.Extensions.Internal.Builders.Implementations; +namespace DSharpPlus.Extensions.Internal.Toolbox.Implementations; /// internal sealed record BuiltModalCallbackData : IModalCallbackData diff --git a/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Implementations/BuiltScheduledEventRecurrenceDay.cs b/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Implementations/BuiltScheduledEventRecurrenceDay.cs new file mode 100644 index 0000000000..b2595c7cce --- /dev/null +++ b/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Implementations/BuiltScheduledEventRecurrenceDay.cs @@ -0,0 +1,18 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; + +namespace DSharpPlus.Extensions.Internal.Toolbox.Implementations; + +/// +internal sealed record BuiltScheduledEventRecurrenceDay : IScheduledEventRecurrenceDay +{ + /// + public required int N { get; init; } + + /// + public required DiscordScheduledEventRecurrenceWeekday Day { get; init; } +} \ No newline at end of file diff --git a/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Implementations/BuiltScheduledEventRecurrenceRule.cs b/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Implementations/BuiltScheduledEventRecurrenceRule.cs new file mode 100644 index 0000000000..03bd96b511 --- /dev/null +++ b/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Implementations/BuiltScheduledEventRecurrenceRule.cs @@ -0,0 +1,45 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; +using System.Collections.Generic; + +using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; + +namespace DSharpPlus.Extensions.Internal.Toolbox.Implementations; + +/// +internal sealed record BuiltScheduledEventRecurrenceRule : IScheduledEventRecurrenceRule +{ + /// + public required DateTimeOffset Start { get; init; } + + /// + public DateTimeOffset? End { get; init; } + + /// + public required DiscordScheduledEventRecurrenceFrequency Frequency { get; init; } + + /// + public required int Interval { get; init; } + + /// + public IReadOnlyList? ByWeekday { get; init; } + + /// + public IReadOnlyList? ByNWeekday { get; init; } + + /// + public IReadOnlyList? ByMonth { get; init; } + + /// + public IReadOnlyList? ByMonthDay { get; init; } + + /// + public IReadOnlyList? ByYearDay { get; init; } + + /// + public int? Count { get; init; } +} \ No newline at end of file diff --git a/src/extensions/DSharpPlus.Extensions.Internal.Builders/Implementations/BuiltTextInputComponent.cs b/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Implementations/BuiltTextInputComponent.cs similarity index 94% rename from src/extensions/DSharpPlus.Extensions.Internal.Builders/Implementations/BuiltTextInputComponent.cs rename to src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Implementations/BuiltTextInputComponent.cs index 8bd290958d..0180bb4c37 100644 --- a/src/extensions/DSharpPlus.Extensions.Internal.Builders/Implementations/BuiltTextInputComponent.cs +++ b/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Implementations/BuiltTextInputComponent.cs @@ -5,7 +5,7 @@ using DSharpPlus.Entities; using DSharpPlus.Internal.Abstractions.Models; -namespace DSharpPlus.Extensions.Internal.Builders.Implementations; +namespace DSharpPlus.Extensions.Internal.Toolbox.Implementations; /// internal sealed record BuiltTextInputComponent : ITextInputComponent diff --git a/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/RecurrenceRule.cs b/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/RecurrenceRule.cs new file mode 100644 index 0000000000..f5abe2b12c --- /dev/null +++ b/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/RecurrenceRule.cs @@ -0,0 +1,189 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; + +using DSharpPlus.Entities; +using DSharpPlus.Extensions.Internal.Toolbox.Implementations; +using DSharpPlus.Internal.Abstractions.Models; + +namespace DSharpPlus.Extensions.Internal.Toolbox; + +/// +/// Provides utilities for writing recurrence rules. +/// +public static class RecurrenceRule +{ + /// + public static IScheduledEventRecurrenceRule Yearly(DateOnly date) + => Yearly(date, DateTimeOffset.UtcNow); + + /// + /// Creates a rule to recur every year on the specified date. + /// + /// The date to recur on. will be ignored. + /// The starting date of the recurring event. + public static IScheduledEventRecurrenceRule Yearly(DateOnly date, DateTimeOffset startDate) + { + return new BuiltScheduledEventRecurrenceRule + { + Start = startDate, + Frequency = DiscordScheduledEventRecurrenceFrequency.Yearly, + ByMonth = [(DiscordScheduledEventRecurrenceMonth)date.Month], + ByMonthDay = [date.Day], + Interval = 1 + }; + } + + /// + public static IScheduledEventRecurrenceRule Monthly(int week, DayOfWeek day) + => Monthly(week, day, DateTimeOffset.UtcNow); + + /// + /// Creates a rule to recur every month on the specified day. + /// + /// Specifies the week within the month to recur in. + /// Specifies the day within the week to recur on. + /// The starting date of the recurring event. + public static IScheduledEventRecurrenceRule Monthly(int week, DayOfWeek day, DateTimeOffset startDate) + { + return new BuiltScheduledEventRecurrenceRule + { + Start = startDate, + Frequency = DiscordScheduledEventRecurrenceFrequency.Monthly, + ByNWeekday = + [ + new BuiltScheduledEventRecurrenceDay + { + Day = ToMondayWeek(day), + N = week + } + ], + Interval = 1 + }; + } + + /// + public static IScheduledEventRecurrenceRule Weekly(DayOfWeek day) + => Weekly(day, DateTimeOffset.UtcNow); + + /// + /// Creates a new recurrence rule to recur every week on the specified weekday. + /// + /// The weekday to recur on. + /// The starting date of the recurring event. + public static IScheduledEventRecurrenceRule Weekly(DayOfWeek day, DateTimeOffset startDate) + { + return new BuiltScheduledEventRecurrenceRule + { + Start = startDate, + Frequency = DiscordScheduledEventRecurrenceFrequency.Weekly, + ByWeekday = [ToMondayWeek(day)], + Interval = 1 + }; + } + + /// + public static IScheduledEventRecurrenceRule BiWeekly(DayOfWeek day) + => BiWeekly(day, DateTimeOffset.UtcNow); + + /// + /// Creates a new recurrence rule to recur every other week on the specified weekday. + /// + /// The weekday to recur on. + /// The starting date of the recurring event. + public static IScheduledEventRecurrenceRule BiWeekly(DayOfWeek day, DateTimeOffset startDate) + { + return new BuiltScheduledEventRecurrenceRule + { + Start = startDate, + Frequency = DiscordScheduledEventRecurrenceFrequency.Weekly, + ByWeekday = [ToMondayWeek(day)], + Interval = 2 + }; + } + + /// + public static IScheduledEventRecurrenceRule Daily() + => Daily(DateTimeOffset.UtcNow); + + /// + /// Creates a new recurrence rule to recur every day. + /// + /// The starting date of the recurring event. + public static IScheduledEventRecurrenceRule Daily(DateTimeOffset startDate) + { + return new BuiltScheduledEventRecurrenceRule + { + Start = startDate, + Frequency = DiscordScheduledEventRecurrenceFrequency.Daily, + Interval = 1 + }; + } + + /// + public static IScheduledEventRecurrenceRule OnWorkingDays() + => OnWorkingDays(DateTimeOffset.UtcNow); + + /// + /// Creates a new recurrence rule to recur every working day, monday to friday. + /// + /// The starting date of the recurring event. + public static IScheduledEventRecurrenceRule OnWorkingDays(DateTimeOffset startDate) + { + return new BuiltScheduledEventRecurrenceRule + { + Start = startDate, + Frequency = DiscordScheduledEventRecurrenceFrequency.Daily, + ByWeekday = + [ + DiscordScheduledEventRecurrenceWeekday.Monday, + DiscordScheduledEventRecurrenceWeekday.Tuesday, + DiscordScheduledEventRecurrenceWeekday.Wednesday, + DiscordScheduledEventRecurrenceWeekday.Thursday, + DiscordScheduledEventRecurrenceWeekday.Friday + ], + Interval = 1 + }; + } + + /// + public static IScheduledEventRecurrenceRule OnWeekends() + => OnWeekends(DateTimeOffset.UtcNow); + + /// + /// Creates a new recurrence rule to recur every weekend, on saturday and sunday. + /// + /// The starting date of the recurring event. + public static IScheduledEventRecurrenceRule OnWeekends(DateTimeOffset startDate) + { + return new BuiltScheduledEventRecurrenceRule + { + Start = startDate, + Frequency = DiscordScheduledEventRecurrenceFrequency.Daily, + ByWeekday = + [ + DiscordScheduledEventRecurrenceWeekday.Saturday, + DiscordScheduledEventRecurrenceWeekday.Sunday + ], + Interval = 1 + }; + } + + // the enum layout of DayOfWeek and DiscordScheduledEventRecurrenceWeekday isn't the same. + private static DiscordScheduledEventRecurrenceWeekday ToMondayWeek(DayOfWeek day) + { + return day switch + { + DayOfWeek.Monday => DiscordScheduledEventRecurrenceWeekday.Monday, + DayOfWeek.Tuesday => DiscordScheduledEventRecurrenceWeekday.Tuesday, + DayOfWeek.Wednesday => DiscordScheduledEventRecurrenceWeekday.Wednesday, + DayOfWeek.Thursday => DiscordScheduledEventRecurrenceWeekday.Thursday, + DayOfWeek.Friday => DiscordScheduledEventRecurrenceWeekday.Friday, + DayOfWeek.Saturday => DiscordScheduledEventRecurrenceWeekday.Saturday, + DayOfWeek.Sunday => DiscordScheduledEventRecurrenceWeekday.Sunday, + _ => throw new NotImplementedException("There are seven weekdays.") + }; + } +} diff --git a/src/extensions/DSharpPlus.Extensions.sln b/src/extensions/DSharpPlus.Extensions.sln index aa0e1dfffb..e8b5bb657f 100644 --- a/src/extensions/DSharpPlus.Extensions.sln +++ b/src/extensions/DSharpPlus.Extensions.sln @@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.0.31903.59 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DSharpPlus.Extensions.Internal.Builders", "DSharpPlus.Extensions.Internal.Builders\DSharpPlus.Extensions.Internal.Builders.csproj", "{6278DA69-38C9-4A8A-9ACA-DFA9E2A9E65A}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DSharpPlus.Extensions.Internal.Toolbox", "DSharpPlus.Extensions.Internal.Toolbox\DSharpPlus.Extensions.Internal.Toolbox.csproj", "{40CC040B-F757-42AA-8BC8-44F6EA6DCE7E}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -14,9 +14,9 @@ Global HideSolutionNode = FALSE EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {6278DA69-38C9-4A8A-9ACA-DFA9E2A9E65A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {6278DA69-38C9-4A8A-9ACA-DFA9E2A9E65A}.Debug|Any CPU.Build.0 = Debug|Any CPU - {6278DA69-38C9-4A8A-9ACA-DFA9E2A9E65A}.Release|Any CPU.ActiveCfg = Release|Any CPU - {6278DA69-38C9-4A8A-9ACA-DFA9E2A9E65A}.Release|Any CPU.Build.0 = Release|Any CPU + {40CC040B-F757-42AA-8BC8-44F6EA6DCE7E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {40CC040B-F757-42AA-8BC8-44F6EA6DCE7E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {40CC040B-F757-42AA-8BC8-44F6EA6DCE7E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {40CC040B-F757-42AA-8BC8-44F6EA6DCE7E}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection EndGlobal diff --git a/tools/generators/copy-concrete-implementations.csx b/tools/generators/copy-concrete-implementations.csx index edcf0a8ee9..52cff4f7d6 100644 --- a/tools/generators/copy-concrete-implementations.csx +++ b/tools/generators/copy-concrete-implementations.csx @@ -20,10 +20,10 @@ if (Args is ["-h" or "--help" or "-?"]) AnsiConsole.MarkupLine ( """ - [plum1]DSharpPlus Concrete Implementation Theft, v0.1.0[/] + [plum1]DSharpPlus Concrete Implementation Theft, v0.2.0[/] Usage: copy-concrete-implementations.csx [[path to meta file]] - Extracts the required concrete types for DSharpPlus.Extensions.Internal.Builders to remove dependency on concrete implementations. + Extracts the required concrete types for DSharpPlus.Extensions.Internal.Toolbox to remove dependency on concrete implementations. """ ); @@ -34,16 +34,16 @@ if (Args is ["-h" or "--help" or "-?"]) AnsiConsole.MarkupLine ( """ - [plum1]DSharpPlus Concrete Implementation Theft, v0.1.0[/] + [plum1]DSharpPlus Concrete Implementation Theft, v0.2.0[/] """ ); string meta; -string basePath = "./src/extensions/DSharpPlus.Extensions.Internal.Builders/Implementations/"; +string basePath = "./src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Implementations/"; if (Args.Count == 0) { - meta = "./meta/builder-concrete-types.json"; + meta = "./meta/toolbox-concrete-types.json"; } // there are args passed, which override the given instructions @@ -82,15 +82,6 @@ if (!changes.Added.Any() && !changes.Modified.Any() && !changes.Removed.Any()) return 0; } -AnsiConsole.MarkupLine -( - """ - - Extracts the required concrete types for DSharpPlus.Extensions.Internal.Builders to remove dependency on concrete implementations. - - """ -); - if (changes.Removed.Any()) { AnsiConsole.MarkupLine @@ -134,7 +125,7 @@ bool success = toExtract.AsParallel() int endOfNamespaceLine = text.IndexOf('\n', namespaceIndex); text = text.Remove(namespaceIndex, endOfNamespaceLine - namespaceIndex); - text = text.Insert(namespaceIndex, "namespace DSharpPlus.Extensions.Internal.Builders.Implementations;"); + text = text.Insert(namespaceIndex, "namespace DSharpPlus.Extensions.Internal.Toolbox.Implementations;"); text = text.Replace("public sealed record", "internal sealed record"); From 6c5ed0977e56e7d1366a25c2719c0d1ed2d9491f Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Mon, 12 Aug 2024 14:54:29 +0200 Subject: [PATCH 310/323] xmldocs and a quick fast-path for empty permission units (currently at least two per set) --- src/core/DSharpPlus.Shared/Entities/DiscordPermissions.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/core/DSharpPlus.Shared/Entities/DiscordPermissions.cs b/src/core/DSharpPlus.Shared/Entities/DiscordPermissions.cs index 6492fe57f0..44c2514ff5 100644 --- a/src/core/DSharpPlus.Shared/Entities/DiscordPermissions.cs +++ b/src/core/DSharpPlus.Shared/Entities/DiscordPermissions.cs @@ -238,12 +238,20 @@ public string ToString(string format) public override int GetHashCode() => HashCode.Combine(MemoryMarshal.Cast(MemoryMarshal.CreateReadOnlySpan(in this.data[0], ContainerElementCount))); + /// + /// Enumerates all permissions specified by this set. + /// public IEnumerable EnumeratePermissions() { for (int block = 0; block < ContainerElementCount; block++) { uint value = this.data[block]; + if (BitOperations.PopCount(value) == 0) + { + continue; + } + for (int bit = 0; bit < 32; bit++) { if (BitHelper.HasFlag(value, bit)) From 6cbf15853f39921294634bfb2503f09b35dd61b6 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Mon, 12 Aug 2024 16:53:28 +0200 Subject: [PATCH 311/323] remove all allocations from EnumeratePermissions --- ...DiscordPermissions.EnumeratePermissions.cs | 93 +++++++++++++++++++ .../Entities/DiscordPermissions.cs | 29 +----- 2 files changed, 97 insertions(+), 25 deletions(-) create mode 100644 src/core/DSharpPlus.Shared/Entities/DiscordPermissions.EnumeratePermissions.cs diff --git a/src/core/DSharpPlus.Shared/Entities/DiscordPermissions.EnumeratePermissions.cs b/src/core/DSharpPlus.Shared/Entities/DiscordPermissions.EnumeratePermissions.cs new file mode 100644 index 0000000000..8abe51dd61 --- /dev/null +++ b/src/core/DSharpPlus.Shared/Entities/DiscordPermissions.EnumeratePermissions.cs @@ -0,0 +1,93 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +#pragma warning disable CA1034 +#pragma warning disable CA1815 + +using System.Collections; +using System.Collections.Generic; +using System.Numerics; + +using CommunityToolkit.HighPerformance.Helpers; + +namespace DSharpPlus.Entities; + +// contains the implementation details for EnumeratePermissions +partial struct DiscordPermissions +{ + /// + /// Presents a slim enumerable wrapper around a set of permissions. + /// + public readonly struct DiscordPermissionEnumerable : IEnumerable + { + private readonly DiscordPermissionContainer data; + + internal DiscordPermissionEnumerable(DiscordPermissionContainer data) + => this.data = data; + + /// + /// Gets an enumerator for the present permission set. + /// + public readonly DiscordPermissionEnumerator GetEnumerator() => new(this.data); + + // implementations for IEnumerable, we'd like to not box by default + IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator(); + IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator(); + } + + /// + /// Represents an enumerator for permission fields within a permission set. + /// + public struct DiscordPermissionEnumerator : IEnumerator + { + private readonly DiscordPermissionContainer data; + + internal DiscordPermissionEnumerator(DiscordPermissionContainer data) + => this.data = data; + + public readonly DiscordPermission Current => (DiscordPermission)(32 * this.block) + this.bit; + + readonly object IEnumerator.Current => this.Current; + + private int block = 0; + private int bit = -1; + + public bool MoveNext() + { + for (; this.block < 4; this.block++) + { + this.bit++; + uint value = this.data[this.block]; + + if (BitOperations.PopCount(value) == 0) + { + continue; + } + + for (; this.bit < 32; this.bit++) + { + if (BitHelper.HasFlag(value, this.bit)) + { + return true; + } + } + + this.bit = -1; + } + + return false; + } + + public void Reset() + { + this.block = 0; + this.bit = -1; + } + + public readonly void Dispose() + { + + } + } +} diff --git a/src/core/DSharpPlus.Shared/Entities/DiscordPermissions.cs b/src/core/DSharpPlus.Shared/Entities/DiscordPermissions.cs index 44c2514ff5..c7c952c945 100644 --- a/src/core/DSharpPlus.Shared/Entities/DiscordPermissions.cs +++ b/src/core/DSharpPlus.Shared/Entities/DiscordPermissions.cs @@ -4,7 +4,6 @@ using System; using System.Buffers.Binary; -using System.Collections.Generic; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.Globalization; @@ -239,30 +238,10 @@ public override int GetHashCode() => HashCode.Combine(MemoryMarshal.Cast(MemoryMarshal.CreateReadOnlySpan(in this.data[0], ContainerElementCount))); /// - /// Enumerates all permissions specified by this set. + /// Provides an enumeration of all permissions specified by this set. /// - public IEnumerable EnumeratePermissions() - { - for (int block = 0; block < ContainerElementCount; block++) - { - uint value = this.data[block]; - - if (BitOperations.PopCount(value) == 0) - { - continue; - } - - for (int bit = 0; bit < 32; bit++) - { - if (BitHelper.HasFlag(value, bit)) - { - yield return (DiscordPermission)(32 * block) + bit; - } - } - } - - yield break; - } + public DiscordPermissionEnumerable EnumeratePermissions() + => new(this.data); public static bool operator ==(DiscordPermissions left, DiscordPermissions right) => left.Equals(right); public static bool operator !=(DiscordPermissions left, DiscordPermissions right) => !(left == right); @@ -277,7 +256,7 @@ public IEnumerable EnumeratePermissions() /// Represents a container for the backing storage of Discord permissions. /// [InlineArray(ContainerElementCount)] - private struct DiscordPermissionContainer + internal struct DiscordPermissionContainer { public uint value; From 6c60c361d00dc1c752c7fd799292d5a8a6a9c168 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Mon, 12 Aug 2024 18:06:29 +0200 Subject: [PATCH 312/323] improve readability/safety, from vam Co-authored-by: DPlayer234 --- .../Entities/DiscordPermissions.cs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/core/DSharpPlus.Shared/Entities/DiscordPermissions.cs b/src/core/DSharpPlus.Shared/Entities/DiscordPermissions.cs index c7c952c945..7e6d2867ad 100644 --- a/src/core/DSharpPlus.Shared/Entities/DiscordPermissions.cs +++ b/src/core/DSharpPlus.Shared/Entities/DiscordPermissions.cs @@ -15,7 +15,7 @@ using CommunityToolkit.HighPerformance.Helpers; -using HashCode = CommunityToolkit.HighPerformance.Helpers.HashCode; +using HashCode = CommunityToolkit.HighPerformance.Helpers.HashCode; namespace DSharpPlus.Entities; @@ -111,8 +111,10 @@ ReadOnlySpan removePermissions /// A copy constructor that sets one specific flag to the specified value. /// private DiscordPermissions(DiscordPermissions original, int index, bool flag) - : this(original.AsSpan) - => this.data.SetFlag(index, flag); + { + this.data = original.data; + this.data.SetFlag(index, flag); + } public static implicit operator DiscordPermissions(DiscordPermission initial) => new(initial); @@ -144,8 +146,9 @@ public static DiscordPermissions AllBitsSet /// public static DiscordPermissions All { get; } = new(DiscordPermissionExtensions.GetValues()); + [UnscopedRef] private ReadOnlySpan AsSpan - => MemoryMarshal.Cast(MemoryMarshal.CreateReadOnlySpan(in this.data[0], ContainerElementCount)); + => MemoryMarshal.Cast((ReadOnlySpan)this.data); private bool GetFlag(int index) => this.data.HasFlag(index); @@ -235,7 +238,7 @@ public string ToString(string format) /// within a process, and sharing this data across process boundaries is dangerous. /// public override int GetHashCode() - => HashCode.Combine(MemoryMarshal.Cast(MemoryMarshal.CreateReadOnlySpan(in this.data[0], ContainerElementCount))); + => HashCode.Combine(this.data); /// /// Provides an enumeration of all permissions specified by this set. From b50aa76ec06201abc8384af0f5afbd0292a97097 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Wed, 14 Aug 2024 12:28:46 +0200 Subject: [PATCH 313/323] licensing shenanigans --- LICENSE-MIT | 9 +++++++++ readme.md | 13 ++++++------- 2 files changed, 15 insertions(+), 7 deletions(-) create mode 100644 LICENSE-MIT diff --git a/LICENSE-MIT b/LICENSE-MIT new file mode 100644 index 0000000000..27b55660c0 --- /dev/null +++ b/LICENSE-MIT @@ -0,0 +1,9 @@ +Copyright (c) 2015 Mike Santiago +Copyright (c) 2016-2023 DSharpPlus Development Team (v1-v5) +Copyright (c) 2023- DSharpPlus Development Team (v6+, only contributions by the specified contributors: ./readme.md#licensing) + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/readme.md b/readme.md index 47fd699aaa..a0ad4a73ee 100644 --- a/readme.md +++ b/readme.md @@ -6,14 +6,13 @@ while DSharpPlus v5 is tracked on the master branch. ## Licensing -DSharpPlus is based off DiscordSharp, whose license can be found [here](./DiscordSharp.LICENSE). +DSharpPlus is based off DiscordSharp, whose license can be found [here](./DiscordSharp.Old.License). -DSharpPlus, up to version 5.x, uses the MIT License, which can be found [here](./LICENSE-OLD) +DSharpPlus, up to version 5.x, uses the MIT License, which can be found [here](./DSharpPlus.Old.License) DSharpPlus, starting with version 6.x, uses the Mozilla Public License, v2.0, which can be found [here](./LICENSE). -This version does not contain any code from previous versions, and is built from ground up. +This version does not contain any code from previous versions, and is built from ground up. -Additionally, because DSharpPlus references LGPL libraries, single-file published distributions of applications using -DSharpPlus must in turn be licensed compatibly with LGPL. This is not applicable for undistributed applications or -applications distributed with multiple files, because only a single-file distribution is statically linked to LGPL -software and thus falls under the LGPL requirement of compatible licensing for statically linking code. +The following contributor(s) to v6 and up have chosen to license their code under the [MIT License](./LICENSE-MIT) +in addition to MPL-2.0: +- [akiraveliara](https://github.com/akiraveliara) From 8c4cd6c01ae4f479bcb70e554dca2b8b070541aa Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sat, 24 Aug 2024 13:04:32 +0200 Subject: [PATCH 314/323] tiny permission improvements - optimizes AND against just one permission. don't really see the usecase for this, but it's faster now? - expresses a multiplication in enumerating permissions as a bitshift --- .../Entities/DiscordPermissions.EnumeratePermissions.cs | 4 ++-- .../Entities/DiscordPermissions.Manipulation.cs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/core/DSharpPlus.Shared/Entities/DiscordPermissions.EnumeratePermissions.cs b/src/core/DSharpPlus.Shared/Entities/DiscordPermissions.EnumeratePermissions.cs index 8abe51dd61..0431d819ea 100644 --- a/src/core/DSharpPlus.Shared/Entities/DiscordPermissions.EnumeratePermissions.cs +++ b/src/core/DSharpPlus.Shared/Entities/DiscordPermissions.EnumeratePermissions.cs @@ -46,7 +46,7 @@ public struct DiscordPermissionEnumerator : IEnumerator internal DiscordPermissionEnumerator(DiscordPermissionContainer data) => this.data = data; - public readonly DiscordPermission Current => (DiscordPermission)(32 * this.block) + this.bit; + public readonly DiscordPermission Current => (DiscordPermission)(this.block << 5) + this.bit; readonly object IEnumerator.Current => this.Current; @@ -55,7 +55,7 @@ internal DiscordPermissionEnumerator(DiscordPermissionContainer data) public bool MoveNext() { - for (; this.block < 4; this.block++) + for (; this.block < ContainerElementCount; this.block++) { this.bit++; uint value = this.data[this.block]; diff --git a/src/core/DSharpPlus.Shared/Entities/DiscordPermissions.Manipulation.cs b/src/core/DSharpPlus.Shared/Entities/DiscordPermissions.Manipulation.cs index 63377b3c0a..8a718e238f 100644 --- a/src/core/DSharpPlus.Shared/Entities/DiscordPermissions.Manipulation.cs +++ b/src/core/DSharpPlus.Shared/Entities/DiscordPermissions.Manipulation.cs @@ -112,7 +112,7 @@ public DiscordPermissions Remove(params ReadOnlySpan permissi /// Returns a permission set containing either no value if the flag was not found, or exactly the specified flag if it was. /// public static DiscordPermissions operator &(DiscordPermissions value, DiscordPermission flag) - => value & (DiscordPermissions)flag; + => value.HasFlag(flag) ? new(flag) : None; /// /// Performs a bitwise AND between the two permission sets. From 5a4f9462fe9b2e002e86b8e29e37984d1bd2f220 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sat, 31 Aug 2024 10:41:50 +0200 Subject: [PATCH 315/323] add an indented text writer for later use:tm: --- lib/bundles | 2 +- .../RequiresRestRequestLoggingAttribute.cs | 2 +- .../RuntimeFeatures/RestRequestLogging.cs | 2 +- .../IndentedArrayPoolUtf16TextWriter.cs | 160 ++++++++++++++++++ .../TextWriters/IndentedArrayPoolUtf16.cs | 80 +++++++++ 5 files changed, 243 insertions(+), 3 deletions(-) rename src/core/DSharpPlus.Shared/{Runtime => RuntimeServices}/RuntimeFeatures/RequiresRestRequestLoggingAttribute.cs (91%) rename src/core/DSharpPlus.Shared/{Runtime => RuntimeServices}/RuntimeFeatures/RestRequestLogging.cs (96%) create mode 100644 src/core/DSharpPlus.Shared/RuntimeServices/TextWriters/IndentedArrayPoolUtf16TextWriter.cs create mode 100644 tests/core/DSharpPlus.Shared.Tests/TextWriters/IndentedArrayPoolUtf16.cs diff --git a/lib/bundles b/lib/bundles index de83c25d01..c6212e3406 160000 --- a/lib/bundles +++ b/lib/bundles @@ -1 +1 @@ -Subproject commit de83c25d01c22298d2bd39e5f0c58a74ac6fe168 +Subproject commit c6212e340614aaeadc40d137c09010dbc860f89d diff --git a/src/core/DSharpPlus.Shared/Runtime/RuntimeFeatures/RequiresRestRequestLoggingAttribute.cs b/src/core/DSharpPlus.Shared/RuntimeServices/RuntimeFeatures/RequiresRestRequestLoggingAttribute.cs similarity index 91% rename from src/core/DSharpPlus.Shared/Runtime/RuntimeFeatures/RequiresRestRequestLoggingAttribute.cs rename to src/core/DSharpPlus.Shared/RuntimeServices/RuntimeFeatures/RequiresRestRequestLoggingAttribute.cs index 675d86d7e0..333092bc08 100644 --- a/src/core/DSharpPlus.Shared/Runtime/RuntimeFeatures/RequiresRestRequestLoggingAttribute.cs +++ b/src/core/DSharpPlus.Shared/RuntimeServices/RuntimeFeatures/RequiresRestRequestLoggingAttribute.cs @@ -4,7 +4,7 @@ using System; -namespace DSharpPlus.Runtime.RuntimeFeatures; +namespace DSharpPlus.RuntimeServices.RuntimeFeatures; /// /// This attribute causes code to be trimmed or ignored at JIT time conditional on the feature switch diff --git a/src/core/DSharpPlus.Shared/Runtime/RuntimeFeatures/RestRequestLogging.cs b/src/core/DSharpPlus.Shared/RuntimeServices/RuntimeFeatures/RestRequestLogging.cs similarity index 96% rename from src/core/DSharpPlus.Shared/Runtime/RuntimeFeatures/RestRequestLogging.cs rename to src/core/DSharpPlus.Shared/RuntimeServices/RuntimeFeatures/RestRequestLogging.cs index b609fb6bc1..9ae1b78d01 100644 --- a/src/core/DSharpPlus.Shared/Runtime/RuntimeFeatures/RestRequestLogging.cs +++ b/src/core/DSharpPlus.Shared/RuntimeServices/RuntimeFeatures/RestRequestLogging.cs @@ -5,7 +5,7 @@ using System; using System.Diagnostics.CodeAnalysis; -namespace DSharpPlus.Runtime.RuntimeFeatures; +namespace DSharpPlus.RuntimeServices.RuntimeFeatures; /// /// Contains the runtime feature switch for logging rest request data. diff --git a/src/core/DSharpPlus.Shared/RuntimeServices/TextWriters/IndentedArrayPoolUtf16TextWriter.cs b/src/core/DSharpPlus.Shared/RuntimeServices/TextWriters/IndentedArrayPoolUtf16TextWriter.cs new file mode 100644 index 0000000000..1fa13761ae --- /dev/null +++ b/src/core/DSharpPlus.Shared/RuntimeServices/TextWriters/IndentedArrayPoolUtf16TextWriter.cs @@ -0,0 +1,160 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +#pragma warning disable CA1001 // yes, that type absolutely is disposable. + +using System; +using System.Buffers; +using System.Reflection.Metadata; +using System.Text; +using CommunityToolkit.HighPerformance.Buffers; + +namespace DSharpPlus.RuntimeServices.TextWriters; + +/// +/// Provides a simple and efficient way to write indented UTF-16 text using pooled buffers. +/// +public record struct IndentedArrayPoolUtf16TextWriter : IDisposable +{ + private static ReadOnlySpan SingleIndentation => " "; + private static ReadOnlySpan DoubleIndentation => " "; + private static ReadOnlySpan TripleIndentation => " "; + private static ReadOnlySpan QuadrupleIndentation => " "; + private static ReadOnlySpan DefaultNewline => "\r\n"; + + private int currentIndentation; + + private readonly ArrayPoolBufferWriter writer; + + public IndentedArrayPoolUtf16TextWriter() + => this.writer = new(); + + /// + /// Increases the indentation of this text writer by one level. + /// + public void IncreaseIndentation() => this.currentIndentation++; + + /// + /// Decreases the indentation of this text writer by one level. + /// + public void DecreaseIndentation() => this.currentIndentation--; + + /// + /// Writes the provided text to the writer, without appending a newline. + /// + /// The text to append to this text writer. + /// + /// Indicates whether this is literal text and thus whether each individual line should be properly indented. Defaults + /// to non-literal text where each line will be indented relative to the current writer indentation. + /// + public readonly void Write(ReadOnlySpan text, bool literal = false) + { + if (literal) + { + this.WriteCurrentIndentation(); + this.writer.Write(text); + return; + } + + while (text.Length > 0) + { + int newlineIndex = text.IndexOf(DefaultNewline); + + if (newlineIndex < 0) + { + this.WriteCurrentIndentation(); + this.writer.Write(text); + break; + } + else + { + ReadOnlySpan line = text[..newlineIndex]; + + if (!line.IsEmpty) + { + this.WriteCurrentIndentation(); + this.writer.Write(line); + } + + this.WriteLine(); + text = text[newlineIndex..]; + text = text[text.IndexOfAnyExcept("\r\n")..]; + } + } + } + + /// + /// Writes the provided text to the writer, appending a newline at the end. + /// + /// The text to append to this text writer. + /// + /// Indicates whether this is literal text and thus whether each individual line should be properly indented. Defaults + /// to non-literal text where each line will be indented relative to the current writer indentation. + /// + public readonly void WriteLine(ReadOnlySpan text, bool literal = false) + { + this.Write(text, literal); + this.writer.Write(DefaultNewline); + } + + /// + /// Writes a newline to the writer. + /// + public readonly void WriteLine() + => this.writer.Write(DefaultNewline); + + /// + /// Ascertains that the writer ends on a newline and not any other character. + /// + public readonly void EnsureEndsInNewline() + { + if (this.writer.WrittenSpan is [.., '\n']) + { + return; + } + + this.writer.Write(DefaultNewline); + } + + /// + /// Writes the current indentation to the writer using the cached indentation values. + /// + private readonly void WriteCurrentIndentation() + { + int quadrupleIndentationLevels = this.currentIndentation / 4; + + for (int i = 0; i < quadrupleIndentationLevels; i++) + { + this.writer.Write(QuadrupleIndentation); + } + + switch (this.currentIndentation % 4) + { + case 3: + this.writer.Write(TripleIndentation); + break; + + case 2: + this.writer.Write(DoubleIndentation); + break; + + case 1: + this.writer.Write(SingleIndentation); + break; + + default: + break; + } + } + + /// + /// Builds the current text writer into a string. Note that this operation is computationally expensive. + /// + /// + public override readonly string ToString() + => new(this.writer.WrittenSpan); + + /// + public readonly void Dispose() => this.writer.Dispose(); +} diff --git a/tests/core/DSharpPlus.Shared.Tests/TextWriters/IndentedArrayPoolUtf16.cs b/tests/core/DSharpPlus.Shared.Tests/TextWriters/IndentedArrayPoolUtf16.cs new file mode 100644 index 0000000000..d86f74155b --- /dev/null +++ b/tests/core/DSharpPlus.Shared.Tests/TextWriters/IndentedArrayPoolUtf16.cs @@ -0,0 +1,80 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.RuntimeServices.TextWriters; + +using Xunit; + +namespace DSharpPlus.Shared.Tests.TextWriters; + +public class IndentedArrayPoolUtf16 +{ + [Fact] + public void TestIndentationIncrementDecrement() + { + using IndentedArrayPoolUtf16TextWriter writer = new(); + + writer.WriteLine("{"); + writer.IncreaseIndentation(); + writer.WriteLine(); + writer.DecreaseIndentation(); + writer.WriteLine("}"); + + Assert.Equal + ( + """ + { + + } + """, + writer.ToString().Trim(" \r\n") + ); + } + + [Fact] + public void TestIndentingWrite() + { + using IndentedArrayPoolUtf16TextWriter writer = new(); + + writer.WriteLine("{"); + writer.IncreaseIndentation(); + writer.WriteLine("\"stuff\":\r\n1", false); + writer.DecreaseIndentation(); + writer.WriteLine("}"); + + Assert.Equal + ( + """ + { + "stuff": + 1 + } + """, + writer.ToString().Trim(" \r\n") + ); + } + + [Fact] + public void TestLiteralPreservingWrite() + { + using IndentedArrayPoolUtf16TextWriter writer = new(); + + writer.WriteLine("{"); + writer.IncreaseIndentation(); + writer.WriteLine("\"stuff\":\r\n1", true); + writer.DecreaseIndentation(); + writer.WriteLine("}"); + + Assert.Equal + ( + """ + { + "stuff": + 1 + } + """, + writer.ToString().Trim(" \r\n") + ); + } +} From 149b4660326c8f759453715c8750128261eb839e Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sat, 7 Sep 2024 14:37:51 +0200 Subject: [PATCH 316/323] support latest API features --- .../Applications/IActivityInstance.cs | 38 ++++ .../Applications/IActivityLocation.cs | 32 +++ .../Applications/IPartialApplication.cs | 5 + .../Messages/IMessage.cs | 6 - .../Messages/IMessageSnapshot.cs | 5 +- .../Messages/IMessageSnapshotContent.cs | 71 ++++++ .../Messages/IPartialMessage.cs | 2 +- .../Subscriptions/ISubscription.cs | 62 ++++++ .../API/IGuildRestAPI.cs | 15 ++ .../API/IStickerRestAPI.cs | 13 ++ .../API/ISubscriptionRestAPI.cs | 49 +++++ .../IModifyGuildScheduledEventPayload.cs | 2 +- .../ListSkuSubscriptionsQuery.cs | 24 ++ .../Applications/ActivityInstance.cs | 28 +++ .../Applications/ActivityLocation.cs | 23 ++ .../Applications/Application.cs | 5 +- .../Applications/PartialApplication.cs | 5 +- ...erviceCollectionExtensions.Registration.cs | 4 + .../Messages/MessageSnapshot.cs | 2 +- .../Messages/MessageSnapshotContent.cs | 48 ++++ .../Messages/PartialMessage.cs | 2 +- .../Subscriptions/Subscription.cs | 42 ++++ .../API/GuildRestAPI.cs | 20 ++ .../API/StickerRestAPI.cs | 18 ++ .../API/SubscriptionRestAPI.cs | 90 ++++++++ .../ModifyGuildScheduledEventPayload.cs | 2 +- .../Guilds/DiscordGuildMemberFlags.cs | 27 ++- .../Entities/Messages/DiscordMessageType.cs | 4 +- .../DiscordSubscriptionStatus.cs | 26 +++ .../IndentedArrayPoolUtf16TextWriter.cs | 3 +- .../PollResultMessage.cs | 208 ++++++++++++++++++ 31 files changed, 863 insertions(+), 18 deletions(-) create mode 100644 src/core/DSharpPlus.Internal.Abstractions.Models/Applications/IActivityInstance.cs create mode 100644 src/core/DSharpPlus.Internal.Abstractions.Models/Applications/IActivityLocation.cs create mode 100644 src/core/DSharpPlus.Internal.Abstractions.Models/Messages/IMessageSnapshotContent.cs create mode 100644 src/core/DSharpPlus.Internal.Abstractions.Models/Subscriptions/ISubscription.cs create mode 100644 src/core/DSharpPlus.Internal.Abstractions.Rest/API/ISubscriptionRestAPI.cs create mode 100644 src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Subscriptions/ListSkuSubscriptionsQuery.cs create mode 100644 src/core/DSharpPlus.Internal.Models/Applications/ActivityInstance.cs create mode 100644 src/core/DSharpPlus.Internal.Models/Applications/ActivityLocation.cs create mode 100644 src/core/DSharpPlus.Internal.Models/Messages/MessageSnapshotContent.cs create mode 100644 src/core/DSharpPlus.Internal.Models/Subscriptions/Subscription.cs create mode 100644 src/core/DSharpPlus.Internal.Rest/API/SubscriptionRestAPI.cs create mode 100644 src/core/DSharpPlus.Shared/Entities/Subscriptions/DiscordSubscriptionStatus.cs create mode 100644 src/extensions/DSharpPlus.Extensions.Internal.Toolbox/PollResultMessage.cs diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/Applications/IActivityInstance.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Applications/IActivityInstance.cs new file mode 100644 index 0000000000..a975058d25 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Applications/IActivityInstance.cs @@ -0,0 +1,38 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +namespace DSharpPlus.Internal.Abstractions.Models; + +/// +/// Represents a live instance of a running activity. +/// +public interface IActivityInstance +{ + /// + /// The snowflake identifier of the application executing the activity. + /// + public Snowflake ApplicationId { get; } + + /// + /// An unique identifier of the current activity instance. + /// + public string InstanceId { get; } + + /// + /// A snowflake identifier created for the launch of this activity. + /// + public Snowflake LaunchId { get; } + + /// + /// The guild and channel this activity is running in. + /// + public IActivityLocation Location { get; } + + /// + /// The snowflake identifiers of users currently connected to this instance. + /// + public IReadOnlyList Users { get; } +} diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/Applications/IActivityLocation.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Applications/IActivityLocation.cs new file mode 100644 index 0000000000..e437ada735 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Applications/IActivityLocation.cs @@ -0,0 +1,32 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Internal.Abstractions.Models; + +/// +/// Specifies the location an activity is running in. +/// +public interface IActivityLocation +{ + /// + /// A unique identifier for this location. + /// + public string Id { get; } + + /// + /// Specifies what this location is: "gc" for a guild channel, "pc" for a private channel such as direct message + /// or group chat. + /// + public string Kind { get; } + + /// + /// The snowflake identifier of the channel hosting the activity. + /// + public Snowflake ChannelId { get; } + + /// + /// The snowflake identifier of the guild hosting the activity. + /// + public Optional GuildId { get; } +} diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/Applications/IPartialApplication.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Applications/IPartialApplication.cs index 82fc0a6aed..06c862e7f5 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Models/Applications/IPartialApplication.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Applications/IPartialApplication.cs @@ -149,4 +149,9 @@ public interface IPartialApplication /// The default custom authorization link for this application, if enabled. /// public Optional CustomInstallUrl { get; } + + /// + /// An approximate to the amount of users who installed this app. + /// + public Optional ApproximateUserInstallCount { get; } } diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/Messages/IMessage.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Messages/IMessage.cs index e0d1f7fb7b..04bbb08ef9 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Models/Messages/IMessage.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Messages/IMessage.cs @@ -14,9 +14,6 @@ namespace DSharpPlus.Internal.Abstractions.Models; /// public interface IMessage : IPartialMessage { - /// - public new Snowflake Id { get; } - /// public new Snowflake ChannelId { get; } @@ -58,9 +55,6 @@ public interface IMessage : IPartialMessage // explicit routes for partial access - /// - Optional IPartialMessage.Id => this.Id; - /// Optional IPartialMessage.ChannelId => this.ChannelId; diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/Messages/IMessageSnapshot.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Messages/IMessageSnapshot.cs index 01e848a19b..c062547eb0 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Models/Messages/IMessageSnapshot.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Messages/IMessageSnapshot.cs @@ -9,8 +9,11 @@ namespace DSharpPlus.Internal.Abstractions.Models; /// public interface IMessageSnapshot { + // this is documented as IPartialMessage, however, per the documentation it is not explicitly guaranteed to + // have an ID - therefore, we represent it as a distinct type that does not assume an ID is present + /// /// A subset of the data contained within the referenced message. /// - public IPartialMessage Message { get; } + public IMessageSnapshotContent Message { get; } } diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/Messages/IMessageSnapshotContent.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Messages/IMessageSnapshotContent.cs new file mode 100644 index 0000000000..89f594f462 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Messages/IMessageSnapshotContent.cs @@ -0,0 +1,71 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Entities; +using System.Collections.Generic; +using System; + +namespace DSharpPlus.Internal.Abstractions.Models; + +/// +/// Represents the contents of a . +/// +public interface IMessageSnapshotContent +{ + /// + /// The text contents of this message. This will be empty if your application does not have the + /// message content intent. + /// + public Optional Content { get; } + + /// + /// The timestamp at which this message was sent. + /// + public Optional Timestamp { get; } + + /// + /// The timestamp at which this message was last edited. + /// + public Optional EditedTimestamp { get; } + + /// + /// The users specifically mentioned in this message. + /// + public Optional> Mentions { get; } + + /// + /// The roles specifically mentioned in this message. + /// + public Optional> MentionRoles { get; } + + /// + /// The files attached to this message. + /// + public Optional> Attachments { get; } + + /// + /// The embeds added to this message. + /// + public Optional> Embeds { get; } + + /// + /// The type of this message. + /// + public Optional Type { get; } + + /// + /// Additional flags for this message. + /// + public Optional Flags { get; } + + /// + /// The components attached to this message. + /// + public Optional> Components { get; } + + /// + /// The stickers sent along with this message. + /// + public Optional StickerItems { get; } +} diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/Messages/IPartialMessage.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Messages/IPartialMessage.cs index 1e5ab35f5b..f3b931a059 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Models/Messages/IPartialMessage.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Messages/IPartialMessage.cs @@ -17,7 +17,7 @@ public interface IPartialMessage /// /// The snowflake identifier of this message. /// - public Optional Id { get; } + public Snowflake Id { get; } /// /// The snowflake identifier of the channel this message was sent in. diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/Subscriptions/ISubscription.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Subscriptions/ISubscription.cs new file mode 100644 index 0000000000..f7b1f439fc --- /dev/null +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Subscriptions/ISubscription.cs @@ -0,0 +1,62 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; +using System.Collections.Generic; + +using DSharpPlus.Entities; + +namespace DSharpPlus.Internal.Abstractions.Models; + +/// +/// Represents a subscription to an . +/// +public interface ISubscription +{ + /// + /// The snowflake identifier of this subscription. + /// + public Snowflake Id { get; } + + /// + /// The snowflake identifier of the subscribing user. + /// + public Snowflake UserId { get; } + + /// + /// The list of SKUs this subscription applies to. + /// + public IReadOnlyList SkuIds { get; } + + /// + /// The list of entitlements this subscription applies to. + /// + public IReadOnlyList EntitlementIds { get; } + + /// + /// The starting timestamp of the current subscription period. + /// + public DateTimeOffset CurrentPeriodStart { get; } + + /// + /// The ending timestamp of the current subscription period. + /// + public DateTimeOffset CurrentPeriodEnd { get; } + + /// + /// Specifies the status of this subscription. + /// + public DiscordSubscriptionStatus Status { get; } + + /// + /// Indicates when the subscription was cancelled, if applicable. + /// + public DateTimeOffset? CanceledAt { get; } + + /// + /// Specifies the ISO3166-1-alpha-2 country code of the payment source used to purchase the subscription. + /// Missing unless queried with a private OAuth2 scope. + /// + public Optional Country { get; } +} diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IGuildRestAPI.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IGuildRestAPI.cs index 0fca953c99..d7bfe15520 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IGuildRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IGuildRestAPI.cs @@ -420,6 +420,21 @@ public ValueTask>> GetGuildRolesAsync CancellationToken ct = default ); + /// + /// Fetches the specified role from the specified guild. + /// + /// The snowflake identifier of the guild in question. + /// The snowflake identifier of the role in question. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public ValueTask> GetGuildRoleAsync + ( + Snowflake guildId, + Snowflake roleId, + RequestInfo info = default, + CancellationToken ct = default + ); + /// /// Creates a role in a given guild. /// diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IStickerRestAPI.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IStickerRestAPI.cs index 488c2a909c..5901bc3e8c 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IStickerRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IStickerRestAPI.cs @@ -124,4 +124,17 @@ public ValueTask DeleteGuildStickerAsync RequestInfo info = default, CancellationToken ct = default ); + + /// + /// Gets the specified sticker pack. + /// + /// The snowflake identifier of the sticker pack in question. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public ValueTask> GetStickerPackAsync + ( + Snowflake packId, + RequestInfo info = default, + CancellationToken ct = default + ); } diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/API/ISubscriptionRestAPI.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/ISubscriptionRestAPI.cs new file mode 100644 index 0000000000..108a61f819 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/ISubscriptionRestAPI.cs @@ -0,0 +1,49 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; + +using DSharpPlus.Internal.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Rest.Queries; +using DSharpPlus.Results; + +namespace DSharpPlus.Internal.Abstractions.Rest.API; + +/// +/// Provides access to subscription-related rest API calls. +/// +public interface ISubscriptionRestAPI +{ + /// + /// Fetches all subscriptions pertaining to the relevant SKU, filtered by user. + /// + /// The snowflake identifier of the queried SKU. + /// Additional query arguments for pagination and user filtering. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public ValueTask>> ListSkuSubscriptionsAsync + ( + Snowflake skuId, + ListSkuSubscriptionsQuery query, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Fetches a subscription by ID. + /// + /// The snowflake identifier of the SKU this subscription corresponds to. + /// The snowflake identifier of the subscription to query. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public ValueTask> GetSkuSubscriptionAsync + ( + Snowflake skuId, + Snowflake subscriptionId, + RequestInfo info = default, + CancellationToken ct = default + ); +} diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/ScheduledEvents/IModifyGuildScheduledEventPayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/ScheduledEvents/IModifyGuildScheduledEventPayload.cs index 9db0dd3926..baed1d22d8 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/ScheduledEvents/IModifyGuildScheduledEventPayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/ScheduledEvents/IModifyGuildScheduledEventPayload.cs @@ -67,5 +67,5 @@ public interface IModifyGuildScheduledEventPayload /// /// A definition for how often and at what dates this event should recur. /// - public Optional RecurrenceRule { get; } + public Optional RecurrenceRule { get; } } diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Subscriptions/ListSkuSubscriptionsQuery.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Subscriptions/ListSkuSubscriptionsQuery.cs new file mode 100644 index 0000000000..9e3d393e74 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Subscriptions/ListSkuSubscriptionsQuery.cs @@ -0,0 +1,24 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + + +namespace DSharpPlus.Internal.Abstractions.Rest.Queries; + +public readonly record struct ListSkuSubscriptionsQuery : IPaginatedQuery +{ + + /// + public Snowflake? Before { get; init; } + + /// + public Snowflake? After { get; init; } + + /// + public int? Limit { get; init; } + + /// + /// Specifies a user ID for whom to query subscriptions. This is required except for OAuth2 queries. + /// + public Snowflake? UserId { get; init; } +} diff --git a/src/core/DSharpPlus.Internal.Models/Applications/ActivityInstance.cs b/src/core/DSharpPlus.Internal.Models/Applications/ActivityInstance.cs new file mode 100644 index 0000000000..ada41c8c15 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Models/Applications/ActivityInstance.cs @@ -0,0 +1,28 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Internal.Abstractions.Models; + +namespace DSharpPlus.Internal.Models; + +/// +public sealed record ActivityInstance : IActivityInstance +{ + /// + public required Snowflake ApplicationId { get; init; } + + /// + public required string InstanceId { get; init; } + + /// + public required Snowflake LaunchId { get; init; } + + /// + public required IActivityLocation Location { get; init; } + + /// + public required IReadOnlyList Users { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Models/Applications/ActivityLocation.cs b/src/core/DSharpPlus.Internal.Models/Applications/ActivityLocation.cs new file mode 100644 index 0000000000..4bb9bac18f --- /dev/null +++ b/src/core/DSharpPlus.Internal.Models/Applications/ActivityLocation.cs @@ -0,0 +1,23 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Internal.Abstractions.Models; + +namespace DSharpPlus.Internal.Models; + +/// +public sealed record ActivityLocation : IActivityLocation +{ + /// + public required string Id { get; init; } + + /// + public required string Kind { get; init; } + + /// + public required Snowflake ChannelId { get; init; } + + /// + public Optional GuildId { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Models/Applications/Application.cs b/src/core/DSharpPlus.Internal.Models/Applications/Application.cs index babdf00af9..6fe5f43126 100644 --- a/src/core/DSharpPlus.Internal.Models/Applications/Application.cs +++ b/src/core/DSharpPlus.Internal.Models/Applications/Application.cs @@ -92,4 +92,7 @@ public sealed record Application : IApplication /// public Optional CustomInstallUrl { get; init; } -} + + /// + public Optional ApproximateUserInstallCount { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Models/Applications/PartialApplication.cs b/src/core/DSharpPlus.Internal.Models/Applications/PartialApplication.cs index 69b372b804..72eb1faf15 100644 --- a/src/core/DSharpPlus.Internal.Models/Applications/PartialApplication.cs +++ b/src/core/DSharpPlus.Internal.Models/Applications/PartialApplication.cs @@ -92,4 +92,7 @@ public sealed record PartialApplication : IPartialApplication /// public Optional CustomInstallUrl { get; init; } -} + + /// + public Optional ApproximateUserInstallCount { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Models/Extensions/ServiceCollectionExtensions.Registration.cs b/src/core/DSharpPlus.Internal.Models/Extensions/ServiceCollectionExtensions.Registration.cs index d0a0f5ef9e..34015f7c6e 100644 --- a/src/core/DSharpPlus.Internal.Models/Extensions/ServiceCollectionExtensions.Registration.cs +++ b/src/core/DSharpPlus.Internal.Models/Extensions/ServiceCollectionExtensions.Registration.cs @@ -26,6 +26,8 @@ private static void RegisterSerialization(IServiceCollection services) options.AddModel(); options.AddModel(); options.AddModel(); + options.AddModel(); + options.AddModel(); options.AddModel(); options.AddModel(); options.AddModel(); @@ -116,6 +118,7 @@ private static void RegisterSerialization(IServiceCollection services) options.AddModel(); options.AddModel(); options.AddModel(); + options.AddModel(); options.AddModel(); options.AddModel(); options.AddModel(); @@ -141,6 +144,7 @@ private static void RegisterSerialization(IServiceCollection services) options.AddModel(); options.AddModel(); options.AddModel(); + options.AddModel(); options.AddModel(); options.AddModel(); options.AddModel(); diff --git a/src/core/DSharpPlus.Internal.Models/Messages/MessageSnapshot.cs b/src/core/DSharpPlus.Internal.Models/Messages/MessageSnapshot.cs index 94be1df3c8..0bcd7985cf 100644 --- a/src/core/DSharpPlus.Internal.Models/Messages/MessageSnapshot.cs +++ b/src/core/DSharpPlus.Internal.Models/Messages/MessageSnapshot.cs @@ -10,5 +10,5 @@ namespace DSharpPlus.Internal.Models; public sealed record MessageSnapshot : IMessageSnapshot { /// - public required IPartialMessage Message { get; init; } + public required IMessageSnapshotContent Message { get; init; } } \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Models/Messages/MessageSnapshotContent.cs b/src/core/DSharpPlus.Internal.Models/Messages/MessageSnapshotContent.cs new file mode 100644 index 0000000000..c50a1774ed --- /dev/null +++ b/src/core/DSharpPlus.Internal.Models/Messages/MessageSnapshotContent.cs @@ -0,0 +1,48 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; +using System.Collections.Generic; + +using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; + +namespace DSharpPlus.Internal.Models; + +/// +public sealed record MessageSnapshotContent : IMessageSnapshotContent +{ + /// + public Optional Content { get; init; } + + /// + public Optional Timestamp { get; init; } + + /// + public Optional EditedTimestamp { get; init; } + + /// + public Optional> Mentions { get; init; } + + /// + public Optional> MentionRoles { get; init; } + + /// + public Optional> Attachments { get; init; } + + /// + public Optional> Embeds { get; init; } + + /// + public Optional Type { get; init; } + + /// + public Optional Flags { get; init; } + + /// + public Optional> Components { get; init; } + + /// + public Optional StickerItems { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Models/Messages/PartialMessage.cs b/src/core/DSharpPlus.Internal.Models/Messages/PartialMessage.cs index 2eceeadfd0..24fbe584b7 100644 --- a/src/core/DSharpPlus.Internal.Models/Messages/PartialMessage.cs +++ b/src/core/DSharpPlus.Internal.Models/Messages/PartialMessage.cs @@ -14,7 +14,7 @@ namespace DSharpPlus.Internal.Models; public sealed record PartialMessage : IPartialMessage { /// - public Optional Id { get; init; } + public required Snowflake Id { get; init; } /// public Optional ChannelId { get; init; } diff --git a/src/core/DSharpPlus.Internal.Models/Subscriptions/Subscription.cs b/src/core/DSharpPlus.Internal.Models/Subscriptions/Subscription.cs new file mode 100644 index 0000000000..af98f710c9 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Models/Subscriptions/Subscription.cs @@ -0,0 +1,42 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; +using System.Collections.Generic; + +using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; + +namespace DSharpPlus.Internal.Models; + +/// +public sealed record Subscription : ISubscription +{ + /// + public required Snowflake Id { get; init; } + + /// + public required Snowflake UserId { get; init; } + + /// + public required IReadOnlyList SkuIds { get; init; } + + /// + public required IReadOnlyList EntitlementIds { get; init; } + + /// + public required DateTimeOffset CurrentPeriodStart { get; init; } + + /// + public required DateTimeOffset CurrentPeriodEnd { get; init; } + + /// + public required DiscordSubscriptionStatus Status { get; init; } + + /// + public DateTimeOffset? CanceledAt { get; init; } + + /// + public Optional Country { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Rest/API/GuildRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/GuildRestAPI.cs index e4a0633364..a1b43c2bb5 100644 --- a/src/core/DSharpPlus.Internal.Rest/API/GuildRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Rest/API/GuildRestAPI.cs @@ -1110,4 +1110,24 @@ public async ValueTask> BulkGuildBanAsync ct ); } + + /// + public async ValueTask> GetGuildRoleAsync + ( + Snowflake guildId, + Snowflake roleId, + RequestInfo info = default, + CancellationToken ct = default + ) + { + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Get, + $"guilds/{guildId}/roles/{roleId}", + b => b.WithSimpleRoute(TopLevelResource.Guild, guildId) + .WithRoute($"GET guilds/{guildId}/roles/:role-id"), + info, + ct + ); + } } diff --git a/src/core/DSharpPlus.Internal.Rest/API/StickerRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/StickerRestAPI.cs index 6d271781c5..cadca2a27d 100644 --- a/src/core/DSharpPlus.Internal.Rest/API/StickerRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Rest/API/StickerRestAPI.cs @@ -123,6 +123,24 @@ public async ValueTask> GetStickerAsync ); } + /// + public async ValueTask> GetStickerPackAsync + ( + Snowflake packId, + RequestInfo info = default, + CancellationToken ct = default + ) + { + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Get, + $"sticker-packs/{packId}", + b => b.WithRoute("GET sticker-packs/:pack-id"), + info, + ct + ); + } + /// public async ValueTask>> ListGuildStickersAsync ( diff --git a/src/core/DSharpPlus.Internal.Rest/API/SubscriptionRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/SubscriptionRestAPI.cs new file mode 100644 index 0000000000..819e42b981 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Rest/API/SubscriptionRestAPI.cs @@ -0,0 +1,90 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +#pragma warning disable IDE0046 + +using System.Collections.Generic; +using System.Globalization; +using System.Net.Http; +using System.Threading; +using System.Threading.Tasks; + +using DSharpPlus.Internal.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Rest; +using DSharpPlus.Internal.Abstractions.Rest.API; +using DSharpPlus.Internal.Abstractions.Rest.Errors; +using DSharpPlus.Internal.Abstractions.Rest.Queries; +using DSharpPlus.Results; + +namespace DSharpPlus.Internal.Rest.API; + +/// +public sealed class SubscriptionRestAPI(IRestClient restClient) + : ISubscriptionRestAPI +{ + /// + public async ValueTask> GetSkuSubscriptionAsync + ( + Snowflake skuId, + Snowflake subscriptionId, + RequestInfo info = default, + CancellationToken ct = default + ) + { + return await restClient.ExecuteMultipartPayloadRequestAsync + ( + HttpMethod.Get, + $"skus/{skuId}/subscriptions/{subscriptionId}", + b => b.WithRoute("GET skus/:sku-id/subscriptions/:subscription-id"), + info, + ct + ); + } + + /// + public async ValueTask>> ListSkuSubscriptionsAsync + ( + Snowflake skuId, + ListSkuSubscriptionsQuery query, + RequestInfo info = default, + CancellationToken ct = default + ) + { + if (query.Limit is < 1 or > 100) + { + return new ValidationError("The limit of subscriptions to query must be between 1 and 100."); + } + + QueryBuilder queryBuilder = new($"skus/{skuId}/subscriptions"); + + if (query.Before is Snowflake before) + { + _ = queryBuilder.AddParameter("before", before.ToString()); + } + + if (query.After is Snowflake after) + { + _ = queryBuilder.AddParameter("after", after.ToString()); + } + + if (query.Limit is int limit) + { + _ = queryBuilder.AddParameter("limit", limit.ToString(CultureInfo.InvariantCulture)); + } + + if (query.UserId is Snowflake userId) + { + _ = queryBuilder.AddParameter("user_id", userId.ToString()); + } + + return await restClient.ExecuteMultipartPayloadRequestAsync> + ( + HttpMethod.Get, + queryBuilder.Build(), + b => b.WithRoute("GET skus/:sku-id/subscriptions"), + info, + ct + ); + } +} diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/ScheduledEvents/ModifyGuildScheduledEventPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/ScheduledEvents/ModifyGuildScheduledEventPayload.cs index 81c51131a9..a1f2a4214b 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/ScheduledEvents/ModifyGuildScheduledEventPayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/ScheduledEvents/ModifyGuildScheduledEventPayload.cs @@ -44,5 +44,5 @@ public sealed record ModifyGuildScheduledEventPayload : IModifyGuildScheduledEve public Optional Image { get; init; } /// - public Optional RecurrenceRule { get; init; } + public Optional RecurrenceRule { get; init; } } \ No newline at end of file diff --git a/src/core/DSharpPlus.Shared/Entities/Guilds/DiscordGuildMemberFlags.cs b/src/core/DSharpPlus.Shared/Entities/Guilds/DiscordGuildMemberFlags.cs index 0ae15f52be..37efa0152d 100644 --- a/src/core/DSharpPlus.Shared/Entities/Guilds/DiscordGuildMemberFlags.cs +++ b/src/core/DSharpPlus.Shared/Entities/Guilds/DiscordGuildMemberFlags.cs @@ -33,5 +33,30 @@ public enum DiscordGuildMemberFlags /// /// Indicates that this member has started the guild onboarding process. /// - StartedOnboarding = 1 << 3 + StartedOnboarding = 1 << 3, + + /// + /// Indicates that this member is a guest and can only access the voice channel they were invited to. + /// + IsGuest = 1 << 4, + + /// + /// Indicates that this member has started the 'new member' actions in the server guide. + /// + StartedServerGuide = 1 << 5, + + /// + /// Indicates that this member has completed the 'new member' actions in the server guide. + /// + CompletedServerGuide = 1 << 6, + + /// + /// Indicates that this member was quarantined by automod for their username, global name or nickname. + /// + AutomodQuarantinedUsername = 1 << 7, + + /// + /// Indicates that this member has acknowledged and dismissed the DM settings upsell. + /// + DmSettingsUpsellAcknowledged = 1 << 9 } diff --git a/src/core/DSharpPlus.Shared/Entities/Messages/DiscordMessageType.cs b/src/core/DSharpPlus.Shared/Entities/Messages/DiscordMessageType.cs index d71c5060a8..ef2a104af7 100644 --- a/src/core/DSharpPlus.Shared/Entities/Messages/DiscordMessageType.cs +++ b/src/core/DSharpPlus.Shared/Entities/Messages/DiscordMessageType.cs @@ -42,5 +42,7 @@ public enum DiscordMessageType GuildIncidentAlertModeEnabled = 36, GuildIncidentAlertModeDisabled, GuildIncidentReportRaid, - GuildIncidentReportFalseAlarm + GuildIncidentReportFalseAlarm, + PurchaseNotification = 44, + PollResult = 46 } diff --git a/src/core/DSharpPlus.Shared/Entities/Subscriptions/DiscordSubscriptionStatus.cs b/src/core/DSharpPlus.Shared/Entities/Subscriptions/DiscordSubscriptionStatus.cs new file mode 100644 index 0000000000..b2f80c083b --- /dev/null +++ b/src/core/DSharpPlus.Shared/Entities/Subscriptions/DiscordSubscriptionStatus.cs @@ -0,0 +1,26 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Entities; + +/// +/// Indicates the status of a subscription object. +/// +public enum DiscordSubscriptionStatus +{ + /// + /// Specifies that the subscription is active and will renew. + /// + Active, + + /// + /// Specifies that the subscription is active and will not renew. + /// + Ending, + + /// + /// Specifies that the subscription is inactive. + /// + Inactive +} diff --git a/src/core/DSharpPlus.Shared/RuntimeServices/TextWriters/IndentedArrayPoolUtf16TextWriter.cs b/src/core/DSharpPlus.Shared/RuntimeServices/TextWriters/IndentedArrayPoolUtf16TextWriter.cs index 1fa13761ae..bfe737b7f7 100644 --- a/src/core/DSharpPlus.Shared/RuntimeServices/TextWriters/IndentedArrayPoolUtf16TextWriter.cs +++ b/src/core/DSharpPlus.Shared/RuntimeServices/TextWriters/IndentedArrayPoolUtf16TextWriter.cs @@ -6,8 +6,7 @@ using System; using System.Buffers; -using System.Reflection.Metadata; -using System.Text; + using CommunityToolkit.HighPerformance.Buffers; namespace DSharpPlus.RuntimeServices.TextWriters; diff --git a/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/PollResultMessage.cs b/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/PollResultMessage.cs new file mode 100644 index 0000000000..c80aa59fde --- /dev/null +++ b/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/PollResultMessage.cs @@ -0,0 +1,208 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Globalization; + +using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; + +namespace DSharpPlus.Extensions.Internal.Toolbox; + +/// +/// Provides a helper to deconstruct poll result messages into readable C# code. +/// +public readonly record struct PollResultMessage +{ + private PollResultMessage + ( + string questionText, + int answerVotes, + int totalVotes, + int? answerId, + string? answerText, + Snowflake? answerEmojiId, + string? answerEmojiName, + bool? isAnswerEmojiAnimated + ) + { + this.PollQuestionText = questionText; + this.WinningAnswerVoteCount = answerVotes; + this.TotalVotes = totalVotes; + this.WinningAnswerId = answerId; + this.WinningAnswerText = answerText; + this.WinningAnswerEmojiId = answerEmojiId; + this.WinningAnswerEmojiName = answerEmojiName; + this.IsWinningAnswerEmojiAnimated = isAnswerEmojiAnimated; + } + + /// + /// Attempts to deconstruct a message or partial message into a poll result message. + /// + /// The message object to attempt to deconstruct. + /// If possible, a C# representation of a poll result message. + /// A value indicating whether deconstruction was successful. + public static bool TryDeconstructPollResult(IPartialMessage message, out PollResultMessage result) + { + if (message.Type != DiscordMessageType.PollResult) + { + result = default; + return false; + } + + if (message.Embeds is not { HasValue: true, Value: [IEmbed embed] }) + { + result = default; + return false; + } + + if (embed.Type != "poll_result" || !embed.Fields.HasValue) + { + result = default; + return false; + } + + string questionText = "unknown"; + int answerVotes = 0; + int totalVotes = 0; + int? answerId = default; + string? answerText = default; + Snowflake? answerEmojiId = default; + string? answerEmojiName = default; + bool? isAnswerEmojiAnimated = default; + + // https://discord.com/developers/docs/resources/message#embed-fields-by-embed-type-poll-result-embed-fields + // i asked the devil whether they understood what the thought process here was, they said no. + foreach (IEmbedField field in embed.Fields.Value) + { + switch (field.Name) + { + case "poll_question_text": + questionText = field.Value; + break; + + case "victor_answer_votes": + + if (!int.TryParse(field.Value, CultureInfo.InvariantCulture, out answerVotes)) + { + result = default; + return false; + } + + break; + + case "total_votes": + + if (!int.TryParse(field.Value, CultureInfo.InvariantCulture, out totalVotes)) + { + result = default; + return false; + } + + break; + + case "victor_answer_id": + + if (!int.TryParse(field.Value, CultureInfo.InvariantCulture, out int id)) + { + result = default; + return false; + } + + answerId = id; + + break; + + case "victor_answer_text": + answerText = field.Value; + break; + + case "victor_answer_emoji_id": + + if (!Snowflake.TryParse(field.Value, CultureInfo.InvariantCulture, out Snowflake emojiId)) + { + result = default; + return false; + } + + answerEmojiId = emojiId; + + break; + + case "victor_answer_emoji_name": + answerEmojiName = field.Value; + break; + + case "victor_answer_emoji_animated": + + + if (!bool.TryParse(field.Value, out bool isAnimated)) + { + result = default; + return false; + } + + isAnswerEmojiAnimated = isAnimated; + + break; + + default: + continue; + } + } + + result = new + ( + questionText, + answerVotes, + totalVotes, + answerId, + answerText, + answerEmojiId, + answerEmojiName, + isAnswerEmojiAnimated + ); + + return true; + } + + /// + /// The text of the original poll question. + /// + public string PollQuestionText { get; } + + /// + /// The amount of votes cast for the winning answer. + /// + public int WinningAnswerVoteCount { get; } + + /// + /// The amounts of votes cast in total, across all answers. + /// + public int TotalVotes { get; } + + /// + /// The of the winning answer. + /// + public int? WinningAnswerId { get; } + + /// + /// The text of the winning answer. + /// + public string? WinningAnswerText { get; } + + /// + /// The emoji ID associated with the winning answer. + /// + public Snowflake? WinningAnswerEmojiId { get; } + + /// + /// The emoji name associated with the winning answer. + /// + public string? WinningAnswerEmojiName { get; } + + /// + /// Indicates whether the winning answer emoji is animated, if applicable. + /// + public bool? IsWinningAnswerEmojiAnimated { get; } +} From b96449d7d33593d8dfc4b86299de467d55c5310f Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sat, 7 Sep 2024 15:50:07 +0200 Subject: [PATCH 317/323] deal with component changes --- .../Interactions/IMessageCallbackData.cs | 2 +- .../Interactions/IModalCallbackData.cs | 2 +- .../Interactions/IModalInteractionData.cs | 2 +- .../MessageComponents/IActionRowComponent.cs | 4 +- .../MessageComponents/IButtonComponent.cs | 2 +- .../IChannelSelectComponent.cs | 2 +- ...IInteractiveComponent.cs => IComponent.cs} | 2 +- .../IMentionableSelectComponent.cs | 2 +- .../MessageComponents/IRoleSelectComponent.cs | 2 +- .../IStringSelectComponent.cs | 2 +- .../MessageComponents/ITextInputComponent.cs | 2 +- .../MessageComponents/IUnknownComponent.cs | 23 ++++ .../MessageComponents/IUserSelectComponent.cs | 2 +- .../Messages/IMessageSnapshotContent.cs | 2 +- .../Messages/IPartialMessage.cs | 2 +- .../Channels/IForumAndMediaThreadMessage.cs | 2 +- .../ICreateFollowupMessagePayload.cs | 2 +- .../IEditFollowupMessagePayload.cs | 2 +- .../IEditInteractionResponsePayload.cs | 2 +- .../Messages/ICreateMessagePayload.cs | 2 +- .../Payloads/Messages/IEditMessagePayload.cs | 2 +- .../Webhooks/IEditWebhookMessagePayload.cs | 2 +- .../Webhooks/IExecuteWebhookPayload.cs | 2 +- ...erviceCollectionExtensions.Registration.cs | 3 +- .../Extensions/ServiceCollectionExtensions.cs | 2 +- .../Interactions/MessageCallbackData.cs | 4 +- .../Interactions/ModalCallbackData.cs | 4 +- .../Interactions/ModalInteractionData.cs | 4 +- .../MessageComponents/ActionRowComponent.cs | 2 +- .../{InteractiveComponent.cs => Component.cs} | 2 +- .../StringSelectComponent.cs | 2 +- .../MessageComponents/TextInputComponent.cs | 2 +- .../MessageComponents/UnknownComponent.cs | 18 +++ .../Messages/Message.cs | 2 +- .../Messages/MessageSnapshotContent.cs | 2 +- .../Messages/PartialMessage.cs | 2 +- ...nentConverter.cs => ComponentConverter.cs} | 62 ++-------- .../API/WebhookRestAPI.cs | 4 +- .../Channels/ForumAndMediaThreadMessage.cs | 2 +- .../CreateFollowupMessagePayload.cs | 2 +- .../EditFollowupMessagePayload.cs | 4 +- .../EditInteractionResponsePayload.cs | 4 +- .../Payloads/Messages/CreateMessagePayload.cs | 2 +- .../Payloads/Messages/EditMessagePayload.cs | 2 +- .../Webhooks/EditWebhookMessagePayload.cs | 4 +- .../Webhooks/ExecuteWebhookPayload.cs | 2 +- .../Builders/Interactions/ModalBuilder.cs | 2 +- .../BuiltActionRowComponent.cs | 2 +- .../BuiltCreateFollowupMessagePayload.cs | 2 +- .../BuiltCreateMessagePayload.cs | 4 +- .../BuiltEditFollowupMessagePayload.cs | 4 +- .../BuiltEditInteractionResponsePayload.cs | 4 +- .../BuiltEditMessagePayload.cs | 2 +- .../BuiltMessageCallbackData.cs | 4 +- .../Implementations/BuiltModalCallbackData.cs | 4 +- .../BuiltTextInputComponent.cs | 2 +- .../Converters/ComponentTests.cs | 108 ++++++++++++++++++ 57 files changed, 228 insertions(+), 116 deletions(-) rename src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/{IInteractiveComponent.cs => IComponent.cs} (89%) create mode 100644 src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IUnknownComponent.cs rename src/core/DSharpPlus.Internal.Models/MessageComponents/{InteractiveComponent.cs => Component.cs} (86%) create mode 100644 src/core/DSharpPlus.Internal.Models/MessageComponents/UnknownComponent.cs rename src/core/DSharpPlus.Internal.Models/Serialization/Converters/{MessageComponentConverter.cs => ComponentConverter.cs} (51%) create mode 100644 tests/core/DSharpPlus.Internal.Models.Tests/Converters/ComponentTests.cs diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/Interactions/IMessageCallbackData.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Interactions/IMessageCallbackData.cs index 3fea107af4..d402c84d06 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Models/Interactions/IMessageCallbackData.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Interactions/IMessageCallbackData.cs @@ -41,7 +41,7 @@ public interface IMessageCallbackData /// /// Up to five action rows of components to attach to this message. /// - public Optional> Components { get; } + public Optional> Components { get; } /// /// Attachments to this message. diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/Interactions/IModalCallbackData.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Interactions/IModalCallbackData.cs index 683cd87022..24c6015901 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Models/Interactions/IModalCallbackData.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Interactions/IModalCallbackData.cs @@ -24,5 +24,5 @@ public interface IModalCallbackData /// /// Between 1 and 5 action rows containing each one text input component. /// - public IReadOnlyList Components { get; } + public IReadOnlyList Components { get; } } diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/Interactions/IModalInteractionData.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Interactions/IModalInteractionData.cs index 9918bfd2b1..e9551a74dc 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Models/Interactions/IModalInteractionData.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Interactions/IModalInteractionData.cs @@ -19,5 +19,5 @@ public interface IModalInteractionData /// /// The values submitted by the user. /// - public IReadOnlyList Components { get; } + public IReadOnlyList Components { get; } } diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IActionRowComponent.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IActionRowComponent.cs index e146dc222d..117fa4faaf 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IActionRowComponent.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IActionRowComponent.cs @@ -11,7 +11,7 @@ namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents a container component for other components. /// -public interface IActionRowComponent +public interface IActionRowComponent : IComponent { /// /// @@ -21,5 +21,5 @@ public interface IActionRowComponent /// /// The child components of this action row: up to five buttons, or one non-button component. /// - public IReadOnlyList Components { get; } + public IReadOnlyList Components { get; } } diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IButtonComponent.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IButtonComponent.cs index b20f16e0e1..f94b335083 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IButtonComponent.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IButtonComponent.cs @@ -9,7 +9,7 @@ namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents a button attached to a message. /// -public interface IButtonComponent : IInteractiveComponent +public interface IButtonComponent : IComponent { /// /// The type of this component. diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IChannelSelectComponent.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IChannelSelectComponent.cs index f1e5c580a7..919d415a29 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IChannelSelectComponent.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IChannelSelectComponent.cs @@ -12,7 +12,7 @@ namespace DSharpPlus.Internal.Abstractions.Models; /// Represents a dropdown menu from where users can select discord-supplied channels, /// optionally restricted by channel type. /// -public interface IChannelSelectComponent : IInteractiveComponent +public interface IChannelSelectComponent : IComponent { /// /// The type of this component. diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IInteractiveComponent.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IComponent.cs similarity index 89% rename from src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IInteractiveComponent.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IComponent.cs index 8608201d3e..8ae2b183a6 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IInteractiveComponent.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IComponent.cs @@ -7,4 +7,4 @@ namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents a message component that users can interact with. /// -public interface IInteractiveComponent; +public interface IComponent; diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IMentionableSelectComponent.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IMentionableSelectComponent.cs index 6d9f442808..cc7a044213 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IMentionableSelectComponent.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IMentionableSelectComponent.cs @@ -11,7 +11,7 @@ namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents a dropdown menu from where users can select discord-supplied users and roles. /// -public interface IMentionableSelectComponent : IInteractiveComponent +public interface IMentionableSelectComponent : IComponent { /// /// The type of this component. diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IRoleSelectComponent.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IRoleSelectComponent.cs index a0e750a4d0..0127fae34c 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IRoleSelectComponent.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IRoleSelectComponent.cs @@ -11,7 +11,7 @@ namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents a dropdown menu from where users can select discord-supplied roles. /// -public interface IRoleSelectComponent : IInteractiveComponent +public interface IRoleSelectComponent : IComponent { /// /// The type of this component. diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IStringSelectComponent.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IStringSelectComponent.cs index b58c8a3434..11bd47000e 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IStringSelectComponent.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IStringSelectComponent.cs @@ -11,7 +11,7 @@ namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents a dropdown menu from where users can select dev-supplied strings. /// -public interface IStringSelectComponent : IInteractiveComponent +public interface IStringSelectComponent : IComponent { /// /// The type of this component. diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/ITextInputComponent.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/ITextInputComponent.cs index 4845f1e878..5398f3933c 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/ITextInputComponent.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/ITextInputComponent.cs @@ -9,7 +9,7 @@ namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents a text input field in a modal. /// -public interface ITextInputComponent : IInteractiveComponent +public interface ITextInputComponent : IComponent { /// /// The type of this component. diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IUnknownComponent.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IUnknownComponent.cs new file mode 100644 index 0000000000..fa7db1114f --- /dev/null +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IUnknownComponent.cs @@ -0,0 +1,23 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Entities; + +namespace DSharpPlus.Internal.Abstractions.Models; + +/// +/// Specifies a component of unknown type. +/// +public interface IUnknownComponent : IComponent +{ + /// + /// Gets the type of this component. You should expect to handle values not specified by the enum type. + /// + public DiscordMessageComponentType Type { get; } + + /// + /// Gets the raw string represented by this component. + /// + public string RawPayload { get; } +} diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IUserSelectComponent.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IUserSelectComponent.cs index 1783f3a806..33f459edbe 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IUserSelectComponent.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IUserSelectComponent.cs @@ -11,7 +11,7 @@ namespace DSharpPlus.Internal.Abstractions.Models; /// /// Represents a dropdown menu from where users can select discord-supplied users. /// -public interface IUserSelectComponent : IInteractiveComponent +public interface IUserSelectComponent : IComponent { /// /// The type of this component. diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/Messages/IMessageSnapshotContent.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Messages/IMessageSnapshotContent.cs index 89f594f462..26770f21c2 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Models/Messages/IMessageSnapshotContent.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Messages/IMessageSnapshotContent.cs @@ -62,7 +62,7 @@ public interface IMessageSnapshotContent /// /// The components attached to this message. /// - public Optional> Components { get; } + public Optional> Components { get; } /// /// The stickers sent along with this message. diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/Messages/IPartialMessage.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Messages/IPartialMessage.cs index f3b931a059..9bc1ab659a 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Models/Messages/IPartialMessage.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Messages/IPartialMessage.cs @@ -157,7 +157,7 @@ public interface IPartialMessage /// /// The components attached to this message. /// - public Optional> Components { get; } + public Optional> Components { get; } /// /// The stickers sent along with this message. diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Channels/IForumAndMediaThreadMessage.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Channels/IForumAndMediaThreadMessage.cs index e9086915df..ab8906840c 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Channels/IForumAndMediaThreadMessage.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Channels/IForumAndMediaThreadMessage.cs @@ -29,7 +29,7 @@ public interface IForumAndMediaThreadMessage /// /// A list of components to include with the message. /// - public Optional> Components { get; } + public Optional> Components { get; } /// /// Up to 3 snowflake identifiers of stickers to be attached to this message. diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Interactions/ICreateFollowupMessagePayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Interactions/ICreateFollowupMessagePayload.cs index 577cfcaf2c..6e5af568ac 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Interactions/ICreateFollowupMessagePayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Interactions/ICreateFollowupMessagePayload.cs @@ -40,7 +40,7 @@ public interface ICreateFollowupMessagePayload /// /// Up to five action rows worth of components to include with this message. /// - public Optional> Components { get; } + public Optional> Components { get; } /// /// Files to upload with this message. diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Interactions/IEditFollowupMessagePayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Interactions/IEditFollowupMessagePayload.cs index 26d07f0f69..13df1502e6 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Interactions/IEditFollowupMessagePayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Interactions/IEditFollowupMessagePayload.cs @@ -31,7 +31,7 @@ public interface IEditFollowupMessagePayload /// /// The components for this message. /// - public Optional?> Components { get; } + public Optional?> Components { get; } /// /// Attached files to keep and possible descriptions for new files to upload. diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Interactions/IEditInteractionResponsePayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Interactions/IEditInteractionResponsePayload.cs index 9ec9fbab2a..c159bf4977 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Interactions/IEditInteractionResponsePayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Interactions/IEditInteractionResponsePayload.cs @@ -31,7 +31,7 @@ public interface IEditInteractionResponsePayload /// /// The components for this message. /// - public Optional?> Components { get; } + public Optional?> Components { get; } /// /// Attached files to keep and possible descriptions for new files to upload. diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Messages/ICreateMessagePayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Messages/ICreateMessagePayload.cs index 69956149fa..4a5887c564 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Messages/ICreateMessagePayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Messages/ICreateMessagePayload.cs @@ -47,7 +47,7 @@ public interface ICreateMessagePayload /// /// A list of components to include with the message. /// - public Optional> Components { get; } + public Optional> Components { get; } /// /// Up to 3 snowflake identifiers of stickers to be attached to this message. diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Messages/IEditMessagePayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Messages/IEditMessagePayload.cs index 69db0bdf54..d9a6639b62 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Messages/IEditMessagePayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Messages/IEditMessagePayload.cs @@ -39,7 +39,7 @@ public interface IEditMessagePayload /// /// New components for this message. /// - public Optional?> Components { get; } + public Optional?> Components { get; } /// /// Attached files to this message. This must include old attachments to be retained and new attachments, diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Webhooks/IEditWebhookMessagePayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Webhooks/IEditWebhookMessagePayload.cs index 81dde617bb..50892730d7 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Webhooks/IEditWebhookMessagePayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Webhooks/IEditWebhookMessagePayload.cs @@ -31,7 +31,7 @@ public interface IEditWebhookMessagePayload /// /// The new components attached to this message. /// - public Optional?> Components { get; } + public Optional?> Components { get; } /// /// The new files to be sent along with the edit. Note that all used files in this message must be passed here, diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Webhooks/IExecuteWebhookPayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Webhooks/IExecuteWebhookPayload.cs index 896a0bdd9e..d0ef8f24b7 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Webhooks/IExecuteWebhookPayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Webhooks/IExecuteWebhookPayload.cs @@ -47,7 +47,7 @@ public interface IExecuteWebhookPayload /// /// Components to include with this message. /// - public Optional> Components { get; } + public Optional> Components { get; } /// /// Attachment files to include with this message. diff --git a/src/core/DSharpPlus.Internal.Models/Extensions/ServiceCollectionExtensions.Registration.cs b/src/core/DSharpPlus.Internal.Models/Extensions/ServiceCollectionExtensions.Registration.cs index 34015f7c6e..84f2236e96 100644 --- a/src/core/DSharpPlus.Internal.Models/Extensions/ServiceCollectionExtensions.Registration.cs +++ b/src/core/DSharpPlus.Internal.Models/Extensions/ServiceCollectionExtensions.Registration.cs @@ -93,13 +93,14 @@ private static void RegisterSerialization(IServiceCollection services) options.AddModel(); options.AddModel(); options.AddModel(); + options.AddModel(); options.AddModel(); - options.AddModel(); options.AddModel(); options.AddModel(); options.AddModel(); options.AddModel(); options.AddModel(); + options.AddModel(); options.AddModel(); options.AddModel(); options.AddModel(); diff --git a/src/core/DSharpPlus.Internal.Models/Extensions/ServiceCollectionExtensions.cs b/src/core/DSharpPlus.Internal.Models/Extensions/ServiceCollectionExtensions.cs index 3aaf86afbc..f3b43c385e 100644 --- a/src/core/DSharpPlus.Internal.Models/Extensions/ServiceCollectionExtensions.cs +++ b/src/core/DSharpPlus.Internal.Models/Extensions/ServiceCollectionExtensions.cs @@ -47,7 +47,7 @@ public static IServiceCollection RegisterDiscordModelSerialization options.Converters.Add(new AuditLogChangeConverter()); options.Converters.Add(new AutoModerationActionConverter()); options.Converters.Add(new DiscordPermissionConverter()); - options.Converters.Add(new MessageComponentConverter()); + options.Converters.Add(new ComponentConverter()); options.Converters.Add(new ApplicationIntegrationTypeKeyConverter()); options.TypeInfoResolverChain.Add(OptionalTypeInfoResolver.Default); diff --git a/src/core/DSharpPlus.Internal.Models/Interactions/MessageCallbackData.cs b/src/core/DSharpPlus.Internal.Models/Interactions/MessageCallbackData.cs index 36ae55c44e..bb9c96d125 100644 --- a/src/core/DSharpPlus.Internal.Models/Interactions/MessageCallbackData.cs +++ b/src/core/DSharpPlus.Internal.Models/Interactions/MessageCallbackData.cs @@ -28,7 +28,7 @@ public sealed record MessageCallbackData : IMessageCallbackData public Optional Flags { get; init; } /// - public Optional> Components { get; init; } + public Optional> Components { get; init; } /// public Optional> Attachments { get; init; } @@ -38,4 +38,4 @@ public sealed record MessageCallbackData : IMessageCallbackData /// public IReadOnlyList? Files { get; init; } -} +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Models/Interactions/ModalCallbackData.cs b/src/core/DSharpPlus.Internal.Models/Interactions/ModalCallbackData.cs index d145ff0479..6d00440964 100644 --- a/src/core/DSharpPlus.Internal.Models/Interactions/ModalCallbackData.cs +++ b/src/core/DSharpPlus.Internal.Models/Interactions/ModalCallbackData.cs @@ -18,5 +18,5 @@ public sealed record ModalCallbackData : IModalCallbackData public required string Title { get; init; } /// - public required IReadOnlyList Components { get; init; } -} + public required IReadOnlyList Components { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Models/Interactions/ModalInteractionData.cs b/src/core/DSharpPlus.Internal.Models/Interactions/ModalInteractionData.cs index 488f20579c..3a7b2302e1 100644 --- a/src/core/DSharpPlus.Internal.Models/Interactions/ModalInteractionData.cs +++ b/src/core/DSharpPlus.Internal.Models/Interactions/ModalInteractionData.cs @@ -15,5 +15,5 @@ public sealed record ModalInteractionData : IModalInteractionData public required string CustomId { get; init; } /// - public required IReadOnlyList Components { get; init; } -} + public required IReadOnlyList Components { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Models/MessageComponents/ActionRowComponent.cs b/src/core/DSharpPlus.Internal.Models/MessageComponents/ActionRowComponent.cs index 5cfd073238..7b28013a64 100644 --- a/src/core/DSharpPlus.Internal.Models/MessageComponents/ActionRowComponent.cs +++ b/src/core/DSharpPlus.Internal.Models/MessageComponents/ActionRowComponent.cs @@ -16,5 +16,5 @@ public sealed record ActionRowComponent : IActionRowComponent public required DiscordMessageComponentType Type { get; init; } /// - public required IReadOnlyList Components { get; init; } + public required IReadOnlyList Components { get; init; } } \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Models/MessageComponents/InteractiveComponent.cs b/src/core/DSharpPlus.Internal.Models/MessageComponents/Component.cs similarity index 86% rename from src/core/DSharpPlus.Internal.Models/MessageComponents/InteractiveComponent.cs rename to src/core/DSharpPlus.Internal.Models/MessageComponents/Component.cs index 5ad58968df..2b0979c066 100644 --- a/src/core/DSharpPlus.Internal.Models/MessageComponents/InteractiveComponent.cs +++ b/src/core/DSharpPlus.Internal.Models/MessageComponents/Component.cs @@ -9,4 +9,4 @@ namespace DSharpPlus.Internal.Models; /// /// Placeholder implementation of a marker interface. Please report spotting this to library developers. /// -internal sealed record InteractiveComponent : IInteractiveComponent; +internal sealed record Component : IComponent; \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Models/MessageComponents/StringSelectComponent.cs b/src/core/DSharpPlus.Internal.Models/MessageComponents/StringSelectComponent.cs index 6c82e70a60..1b35b53ab7 100644 --- a/src/core/DSharpPlus.Internal.Models/MessageComponents/StringSelectComponent.cs +++ b/src/core/DSharpPlus.Internal.Models/MessageComponents/StringSelectComponent.cs @@ -32,4 +32,4 @@ public sealed record StringSelectComponent : IStringSelectComponent /// public Optional Disabled { get; init; } -} +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Models/MessageComponents/TextInputComponent.cs b/src/core/DSharpPlus.Internal.Models/MessageComponents/TextInputComponent.cs index 33463ecffc..df75bfd404 100644 --- a/src/core/DSharpPlus.Internal.Models/MessageComponents/TextInputComponent.cs +++ b/src/core/DSharpPlus.Internal.Models/MessageComponents/TextInputComponent.cs @@ -36,4 +36,4 @@ public sealed record TextInputComponent : ITextInputComponent /// public Optional Placeholder { get; init; } -} +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Models/MessageComponents/UnknownComponent.cs b/src/core/DSharpPlus.Internal.Models/MessageComponents/UnknownComponent.cs new file mode 100644 index 0000000000..9c84065002 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Models/MessageComponents/UnknownComponent.cs @@ -0,0 +1,18 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; + +namespace DSharpPlus.Internal.Models; + +/// +public sealed record UnknownComponent : IUnknownComponent +{ + /// + public required DiscordMessageComponentType Type { get; init; } + + /// + public required string RawPayload { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Models/Messages/Message.cs b/src/core/DSharpPlus.Internal.Models/Messages/Message.cs index 1742824f1a..baf3b1273c 100644 --- a/src/core/DSharpPlus.Internal.Models/Messages/Message.cs +++ b/src/core/DSharpPlus.Internal.Models/Messages/Message.cs @@ -95,7 +95,7 @@ public sealed record Message : IMessage public Optional Thread { get; init; } /// - public Optional> Components { get; init; } + public Optional> Components { get; init; } /// public Optional StickerItems { get; init; } diff --git a/src/core/DSharpPlus.Internal.Models/Messages/MessageSnapshotContent.cs b/src/core/DSharpPlus.Internal.Models/Messages/MessageSnapshotContent.cs index c50a1774ed..8d4c7bc6bb 100644 --- a/src/core/DSharpPlus.Internal.Models/Messages/MessageSnapshotContent.cs +++ b/src/core/DSharpPlus.Internal.Models/Messages/MessageSnapshotContent.cs @@ -41,7 +41,7 @@ public sealed record MessageSnapshotContent : IMessageSnapshotContent public Optional Flags { get; init; } /// - public Optional> Components { get; init; } + public Optional> Components { get; init; } /// public Optional StickerItems { get; init; } diff --git a/src/core/DSharpPlus.Internal.Models/Messages/PartialMessage.cs b/src/core/DSharpPlus.Internal.Models/Messages/PartialMessage.cs index 24fbe584b7..c5be6c7bef 100644 --- a/src/core/DSharpPlus.Internal.Models/Messages/PartialMessage.cs +++ b/src/core/DSharpPlus.Internal.Models/Messages/PartialMessage.cs @@ -95,7 +95,7 @@ public sealed record PartialMessage : IPartialMessage public Optional Thread { get; init; } /// - public Optional> Components { get; init; } + public Optional> Components { get; init; } /// public Optional StickerItems { get; init; } diff --git a/src/core/DSharpPlus.Internal.Models/Serialization/Converters/MessageComponentConverter.cs b/src/core/DSharpPlus.Internal.Models/Serialization/Converters/ComponentConverter.cs similarity index 51% rename from src/core/DSharpPlus.Internal.Models/Serialization/Converters/MessageComponentConverter.cs rename to src/core/DSharpPlus.Internal.Models/Serialization/Converters/ComponentConverter.cs index 7bf4ef9a03..3114678b0f 100644 --- a/src/core/DSharpPlus.Internal.Models/Serialization/Converters/MessageComponentConverter.cs +++ b/src/core/DSharpPlus.Internal.Models/Serialization/Converters/ComponentConverter.cs @@ -11,13 +11,10 @@ namespace DSharpPlus.Internal.Models.Serialization.Converters; -/// -/// Converts between message components and JSON. -/// -public class MessageComponentConverter : JsonConverter +public class ComponentConverter : JsonConverter { /// - public override IInteractiveComponent? Read + public override IComponent? Read ( ref Utf8JsonReader reader, Type typeToConvert, @@ -32,17 +29,17 @@ JsonSerializerOptions options if ( !JsonDocument.TryParseValue(ref reader, out JsonDocument? document) - || document.RootElement.TryGetProperty("type", out JsonElement property) + || !document.RootElement.TryGetProperty("type", out JsonElement property) || !property.TryGetInt32(out int type) ) { throw new JsonException("The provided JSON object was malformed."); } - IInteractiveComponent? component = (DiscordMessageComponentType)type switch + IComponent? component = (DiscordMessageComponentType)type switch { DiscordMessageComponentType.ActionRow - => throw new JsonException("Invalid JSON structure: expected an interactive component, not an action row."), + => document.Deserialize(options), DiscordMessageComponentType.Button => document.Deserialize(options), @@ -65,7 +62,11 @@ JsonSerializerOptions options DiscordMessageComponentType.ChannelSelect => document.Deserialize(options), - _ => throw new JsonException("Unknown component type.") + _ => new UnknownComponent + { + Type = (DiscordMessageComponentType)type, + RawPayload = JsonSerializer.Serialize(document) + } }; document.Dispose(); @@ -73,45 +74,6 @@ JsonSerializerOptions options } /// - public override void Write - ( - Utf8JsonWriter writer, - IInteractiveComponent value, - JsonSerializerOptions options - ) - { - switch (value) - { - case IButtonComponent button: - JsonSerializer.Serialize(writer, button, options); - break; - - case IStringSelectComponent stringSelect: - JsonSerializer.Serialize(writer, stringSelect, options); - break; - - case ITextInputComponent text: - JsonSerializer.Serialize(writer, text, options); - break; - - case IUserSelectComponent user: - JsonSerializer.Serialize(writer, user, options); - break; - - case IRoleSelectComponent role: - JsonSerializer.Serialize(writer, role, options); - break; - - case IMentionableSelectComponent mentionable: - JsonSerializer.Serialize(writer, mentionable, options); - break; - - case IChannelSelectComponent channel: - JsonSerializer.Serialize(writer, channel, options); - break; - - default: - throw new InvalidOperationException($"The component {value} could not be serialized."); - } - } + public override void Write(Utf8JsonWriter writer, IComponent value, JsonSerializerOptions options) + => JsonSerializer.Serialize(writer, (object)value, options); } diff --git a/src/core/DSharpPlus.Internal.Rest/API/WebhookRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/WebhookRestAPI.cs index 5fc64222c9..547c00208e 100644 --- a/src/core/DSharpPlus.Internal.Rest/API/WebhookRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Rest/API/WebhookRestAPI.cs @@ -162,7 +162,7 @@ public async ValueTask> EditWebhookMessageAsync return new ValidationError("A webhook message cannot contain more than 10 embeds."); } - if (payload.Components.TryGetNonNullValue(out IReadOnlyList? components) && components.Count > 5) + if (payload.Components.TryGetNonNullValue(out IReadOnlyList? components) && components.Count > 5) { return new ValidationError("A webhook message cannot contain more than 5 action rows."); } @@ -208,7 +208,7 @@ public async ValueTask> ExecuteWebhookAsync return new ValidationError("A webhook message cannot contain more than 10 embeds."); } - if (payload.Components.TryGetNonNullValue(out IReadOnlyList? components) && components.Count > 5) + if (payload.Components.TryGetNonNullValue(out IReadOnlyList? components) && components.Count > 5) { return new ValidationError("A webhook message cannot contain more than 5 action rows."); } diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/ForumAndMediaThreadMessage.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/ForumAndMediaThreadMessage.cs index 41b974213a..cfd9b2bbc8 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/ForumAndMediaThreadMessage.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/ForumAndMediaThreadMessage.cs @@ -23,7 +23,7 @@ public sealed record ForumAndMediaThreadMessage : IForumAndMediaThreadMessage public Optional AllowedMentions { get; init; } /// - public Optional> Components { get; init; } + public Optional> Components { get; init; } /// public Optional> StickerIds { get; init; } diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Interactions/CreateFollowupMessagePayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Interactions/CreateFollowupMessagePayload.cs index d6c7d6c89f..8b16a90ea4 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/Interactions/CreateFollowupMessagePayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Interactions/CreateFollowupMessagePayload.cs @@ -26,7 +26,7 @@ public sealed record CreateFollowupMessagePayload : ICreateFollowupMessagePayloa public Optional AllowedMentions { get; init; } /// - public Optional> Components { get; init; } + public Optional> Components { get; init; } /// public IReadOnlyList? Files { get; init; } diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Interactions/EditFollowupMessagePayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Interactions/EditFollowupMessagePayload.cs index 00cde4d846..183f0ad2e2 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/Interactions/EditFollowupMessagePayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Interactions/EditFollowupMessagePayload.cs @@ -22,11 +22,11 @@ public sealed record EditFollowupMessagePayload : IEditFollowupMessagePayload public Optional AllowedMentions { get; init; } /// - public Optional?> Components { get; init; } + public Optional?> Components { get; init; } /// public Optional?> Attachments { get; init; } /// public IReadOnlyList? Files { get; init; } -} +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Interactions/EditInteractionResponsePayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Interactions/EditInteractionResponsePayload.cs index 36a2c46875..a8cc2f374b 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/Interactions/EditInteractionResponsePayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Interactions/EditInteractionResponsePayload.cs @@ -22,11 +22,11 @@ public sealed record EditInteractionResponsePayload : IEditInteractionResponsePa public Optional AllowedMentions { get; init; } /// - public Optional?> Components { get; init; } + public Optional?> Components { get; init; } /// public Optional?> Attachments { get; init; } /// public IReadOnlyList? Files { get; init; } -} +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Messages/CreateMessagePayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Messages/CreateMessagePayload.cs index 3260020291..95dc0cdc27 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/Messages/CreateMessagePayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Messages/CreateMessagePayload.cs @@ -32,7 +32,7 @@ public sealed record CreateMessagePayload : ICreateMessagePayload public Optional MessageReference { get; init; } /// - public Optional> Components { get; init; } + public Optional> Components { get; init; } /// public Optional> StickerIds { get; init; } diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Messages/EditMessagePayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Messages/EditMessagePayload.cs index 54336c6287..95b4ca4841 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/Messages/EditMessagePayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Messages/EditMessagePayload.cs @@ -26,7 +26,7 @@ public sealed record EditMessagePayload : IEditMessagePayload public Optional AllowedMentions { get; init; } /// - public Optional?> Components { get; init; } + public Optional?> Components { get; init; } /// public IReadOnlyList? Files { get; init; } diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Webhooks/EditWebhookMessagePayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Webhooks/EditWebhookMessagePayload.cs index 350f9d5e94..ffbb15de00 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/Webhooks/EditWebhookMessagePayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Webhooks/EditWebhookMessagePayload.cs @@ -22,11 +22,11 @@ public sealed record EditWebhookMessagePayload : IEditWebhookMessagePayload public Optional AllowedMentions { get; init; } /// - public Optional?> Components { get; init; } + public Optional?> Components { get; init; } /// public IReadOnlyList? Files { get; init; } /// public Optional?> Attachments { get; init; } -} +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Webhooks/ExecuteWebhookPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Webhooks/ExecuteWebhookPayload.cs index 1932f90940..8754612707 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/Webhooks/ExecuteWebhookPayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Webhooks/ExecuteWebhookPayload.cs @@ -32,7 +32,7 @@ public sealed record ExecuteWebhookPayload : IExecuteWebhookPayload public Optional AllowedMentions { get; init; } /// - public Optional> Components { get; init; } + public Optional> Components { get; init; } /// public IReadOnlyList? Files { get; init; } diff --git a/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Builders/Interactions/ModalBuilder.cs b/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Builders/Interactions/ModalBuilder.cs index b0e59633ed..1731f9515a 100644 --- a/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Builders/Interactions/ModalBuilder.cs +++ b/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Builders/Interactions/ModalBuilder.cs @@ -131,7 +131,7 @@ public static IInteractionResponse Build(ref this ModalBuilder builder) { Title = builder.Title, CustomId = builder.CustomId, - Components = builder.Components.Select + Components = builder.Components.Select ( x => { diff --git a/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Implementations/BuiltActionRowComponent.cs b/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Implementations/BuiltActionRowComponent.cs index 1a62140dd1..864224a49c 100644 --- a/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Implementations/BuiltActionRowComponent.cs +++ b/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Implementations/BuiltActionRowComponent.cs @@ -16,5 +16,5 @@ internal sealed record BuiltActionRowComponent : IActionRowComponent public required DiscordMessageComponentType Type { get; init; } /// - public required IReadOnlyList Components { get; init; } + public required IReadOnlyList Components { get; init; } } \ No newline at end of file diff --git a/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Implementations/BuiltCreateFollowupMessagePayload.cs b/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Implementations/BuiltCreateFollowupMessagePayload.cs index 338b3d2923..bdb029cacc 100644 --- a/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Implementations/BuiltCreateFollowupMessagePayload.cs +++ b/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Implementations/BuiltCreateFollowupMessagePayload.cs @@ -26,7 +26,7 @@ internal sealed record BuiltCreateFollowupMessagePayload : ICreateFollowupMessag public Optional AllowedMentions { get; init; } /// - public Optional> Components { get; init; } + public Optional> Components { get; init; } /// public IReadOnlyList? Files { get; init; } diff --git a/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Implementations/BuiltCreateMessagePayload.cs b/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Implementations/BuiltCreateMessagePayload.cs index 787e1dc6a3..186a374d1a 100644 --- a/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Implementations/BuiltCreateMessagePayload.cs +++ b/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Implementations/BuiltCreateMessagePayload.cs @@ -32,7 +32,7 @@ internal sealed record BuiltCreateMessagePayload : ICreateMessagePayload public Optional MessageReference { get; init; } /// - public Optional> Components { get; init; } + public Optional> Components { get; init; } /// public Optional> StickerIds { get; init; } @@ -51,4 +51,4 @@ internal sealed record BuiltCreateMessagePayload : ICreateMessagePayload /// public Optional Poll { get; init; } -} +} \ No newline at end of file diff --git a/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Implementations/BuiltEditFollowupMessagePayload.cs b/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Implementations/BuiltEditFollowupMessagePayload.cs index b845ed5657..1f1b7d0690 100644 --- a/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Implementations/BuiltEditFollowupMessagePayload.cs +++ b/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Implementations/BuiltEditFollowupMessagePayload.cs @@ -22,11 +22,11 @@ internal sealed record BuiltEditFollowupMessagePayload : IEditFollowupMessagePay public Optional AllowedMentions { get; init; } /// - public Optional?> Components { get; init; } + public Optional?> Components { get; init; } /// public Optional?> Attachments { get; init; } /// public IReadOnlyList? Files { get; init; } -} +} \ No newline at end of file diff --git a/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Implementations/BuiltEditInteractionResponsePayload.cs b/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Implementations/BuiltEditInteractionResponsePayload.cs index 440f774b67..96460ba076 100644 --- a/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Implementations/BuiltEditInteractionResponsePayload.cs +++ b/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Implementations/BuiltEditInteractionResponsePayload.cs @@ -22,11 +22,11 @@ internal sealed record BuiltEditInteractionResponsePayload : IEditInteractionRes public Optional AllowedMentions { get; init; } /// - public Optional?> Components { get; init; } + public Optional?> Components { get; init; } /// public Optional?> Attachments { get; init; } /// public IReadOnlyList? Files { get; init; } -} +} \ No newline at end of file diff --git a/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Implementations/BuiltEditMessagePayload.cs b/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Implementations/BuiltEditMessagePayload.cs index 4e5a430fcd..8c7ff84bcf 100644 --- a/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Implementations/BuiltEditMessagePayload.cs +++ b/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Implementations/BuiltEditMessagePayload.cs @@ -26,7 +26,7 @@ internal sealed record BuiltEditMessagePayload : IEditMessagePayload public Optional AllowedMentions { get; init; } /// - public Optional?> Components { get; init; } + public Optional?> Components { get; init; } /// public IReadOnlyList? Files { get; init; } diff --git a/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Implementations/BuiltMessageCallbackData.cs b/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Implementations/BuiltMessageCallbackData.cs index b0ed649ad1..8494473351 100644 --- a/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Implementations/BuiltMessageCallbackData.cs +++ b/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Implementations/BuiltMessageCallbackData.cs @@ -28,7 +28,7 @@ internal sealed record BuiltMessageCallbackData : IMessageCallbackData public Optional Flags { get; init; } /// - public Optional> Components { get; init; } + public Optional> Components { get; init; } /// public Optional> Attachments { get; init; } @@ -38,4 +38,4 @@ internal sealed record BuiltMessageCallbackData : IMessageCallbackData /// public IReadOnlyList? Files { get; init; } -} +} \ No newline at end of file diff --git a/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Implementations/BuiltModalCallbackData.cs b/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Implementations/BuiltModalCallbackData.cs index f3f8749c77..f126877def 100644 --- a/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Implementations/BuiltModalCallbackData.cs +++ b/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Implementations/BuiltModalCallbackData.cs @@ -18,5 +18,5 @@ internal sealed record BuiltModalCallbackData : IModalCallbackData public required string Title { get; init; } /// - public required IReadOnlyList Components { get; init; } -} + public required IReadOnlyList Components { get; init; } +} \ No newline at end of file diff --git a/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Implementations/BuiltTextInputComponent.cs b/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Implementations/BuiltTextInputComponent.cs index 0180bb4c37..e636cc1b34 100644 --- a/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Implementations/BuiltTextInputComponent.cs +++ b/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Implementations/BuiltTextInputComponent.cs @@ -36,4 +36,4 @@ internal sealed record BuiltTextInputComponent : ITextInputComponent /// public Optional Placeholder { get; init; } -} +} \ No newline at end of file diff --git a/tests/core/DSharpPlus.Internal.Models.Tests/Converters/ComponentTests.cs b/tests/core/DSharpPlus.Internal.Models.Tests/Converters/ComponentTests.cs new file mode 100644 index 0000000000..3a33192746 --- /dev/null +++ b/tests/core/DSharpPlus.Internal.Models.Tests/Converters/ComponentTests.cs @@ -0,0 +1,108 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +#pragma warning disable IDE0058 + +using System; +using DSharpPlus.Internal.Abstractions.Models; +using DSharpPlus.Internal.Models.Extensions; +using DSharpPlus.Serialization; + +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging.Abstractions; +using Xunit; + +namespace DSharpPlus.Internal.Models.Tests.Converters; + +public class ComponentTests +{ + private readonly ISerializationService serializer; + + public ComponentTests() + { + IServiceCollection services = new ServiceCollection(); + services.RegisterDiscordModelSerialization(); + services.Configure + ( + options => options.SetFormat() + ); + + services.AddLogging + ( + builder => builder.ClearProviders().AddProvider(NullLoggerProvider.Instance) + ); + + services.AddSingleton(typeof(ISerializationService<>), typeof(SerializationService<>)); + + IServiceProvider provider = services.BuildServiceProvider(); + this.serializer = provider.GetRequiredService>(); + } + + private static ReadOnlySpan ActionRowTestPayload => + """ + { + "id": 0, + "content": "This is a message with components", + "components": [ + { + "type": 1, + "components": [ + { + "type": 2, + "label": "Click me!", + "style": 1, + "custom_id": "click_one" + } + ] + } + ] + } + """u8; + + private static ReadOnlySpan OtherTopLevelComponentTestPayload => + """ + { + "id": 0, + "content": "This is a message with weird components!", + "components": [ + { + "type": 1, + "components": [ + { + "type": 2, + "label": "Don't click me!", + "style": 1, + "custom_id": "click_one" + } + ] + }, + { + "type": 2784, + "random_ignored_data": "ekh" + } + ] + } + """u8; + + [Fact] + public void TestCorrectActionRowDeserialization() + { + IPartialMessage message = this.serializer.DeserializeModel(ActionRowTestPayload); + + Assert.Single(message.Components.Value); + Assert.IsAssignableFrom(message.Components.Value[0]); + Assert.Single(((IActionRowComponent)message.Components.Value[0]).Components); + } + + [Fact] + public void TestCorrectUnknownComponentDeserialization() + { + IPartialMessage message = this.serializer.DeserializeModel(OtherTopLevelComponentTestPayload); + + Assert.Equal(2, message.Components.Value.Count); + Assert.IsAssignableFrom(message.Components.Value[0]); + Assert.IsAssignableFrom(message.Components.Value[1]); + } +} From 38cde98df504e06c52f55799e38ba3494bf30a71 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Thu, 3 Oct 2024 14:20:08 +0200 Subject: [PATCH 318/323] rewire the serialization service to be more easily extendable --- ...ionService.cs => ISerializationBackend.cs} | 16 +-- .../Serialization/SerializationOptions.cs | 16 ++- .../Serialization/SerializationService.cs | 107 ++++++------------ .../SystemTextJsonFormatMarker.cs | 14 +++ .../SystemTextJsonSerializationBackend.cs | 61 ++++++++++ .../Converters/AuditLogChangeTests.cs | 7 +- .../Converters/ComponentTests.cs | 7 +- .../Converters/OneOfConverterTests.Models.cs | 7 +- 8 files changed, 143 insertions(+), 92 deletions(-) rename src/core/DSharpPlus.Shared/Serialization/{ISerializationService.cs => ISerializationBackend.cs} (71%) create mode 100644 src/core/DSharpPlus.Shared/Serialization/SystemTextJsonFormatMarker.cs create mode 100644 src/core/DSharpPlus.Shared/Serialization/SystemTextJsonSerializationBackend.cs diff --git a/src/core/DSharpPlus.Shared/Serialization/ISerializationService.cs b/src/core/DSharpPlus.Shared/Serialization/ISerializationBackend.cs similarity index 71% rename from src/core/DSharpPlus.Shared/Serialization/ISerializationService.cs rename to src/core/DSharpPlus.Shared/Serialization/ISerializationBackend.cs index d11c144fa0..0b94a6a340 100644 --- a/src/core/DSharpPlus.Shared/Serialization/ISerializationService.cs +++ b/src/core/DSharpPlus.Shared/Serialization/ISerializationBackend.cs @@ -9,11 +9,15 @@ namespace DSharpPlus.Serialization; /// -/// Represents an abstraction over model serialization. +/// Represents a serialization backend managed by . /// -/// The library component a given instance is associated with. -public interface ISerializationService +public interface ISerializationBackend { + /// + /// A unique ID for this backend, used to distinguish if multiple different backends are in use at once. + /// + public static abstract string Id { get; } + /// /// Serializes a given serialization model to the given writer. /// @@ -21,11 +25,7 @@ public interface ISerializationService /// This method serializes the library data models specifically, and may not exhibit correct behaviour /// for other types. /// - public void SerializeModel - ( - TModel model, - ArrayPoolBufferWriter target - ) + public void SerializeModel(TModel model, ArrayPoolBufferWriter target) where TModel : notnull; /// diff --git a/src/core/DSharpPlus.Shared/Serialization/SerializationOptions.cs b/src/core/DSharpPlus.Shared/Serialization/SerializationOptions.cs index 90804ba7b9..e954951bf2 100644 --- a/src/core/DSharpPlus.Shared/Serialization/SerializationOptions.cs +++ b/src/core/DSharpPlus.Shared/Serialization/SerializationOptions.cs @@ -22,9 +22,21 @@ public sealed class SerializationOptions /// "etf", on top of ETFKit, not installed by default. /// /// - internal Dictionary Formats { get; } = new(2); + internal Dictionary Formats { get; } = new(4) + { + [typeof(SystemTextJsonFormatMarker)] = "json" + }; - internal Dictionary InterfacesToConcrete { get; } = new(256); + internal Dictionary InterfacesToConcrete { get; } = new(512); + + internal Dictionary BackendImplementations { get; } = new(2) + { + ["json"] = typeof(SystemTextJsonSerializationBackend) + }; + + public void RegisterBackendImplementation() + where T : ISerializationBackend + => this.BackendImplementations[T.Id] = typeof(T); /// /// Specifies the concrete type used to deserialize an interface. diff --git a/src/core/DSharpPlus.Shared/Serialization/SerializationService.cs b/src/core/DSharpPlus.Shared/Serialization/SerializationService.cs index 0b4259547a..8c319ba377 100644 --- a/src/core/DSharpPlus.Shared/Serialization/SerializationService.cs +++ b/src/core/DSharpPlus.Shared/Serialization/SerializationService.cs @@ -3,13 +3,9 @@ // file, You can obtain one at https://mozilla.org/MPL/2.0/. using System; -using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; -using System.Text.Json; -using System.Text.Json.Serialization; using CommunityToolkit.HighPerformance.Buffers; - using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; @@ -19,66 +15,36 @@ namespace DSharpPlus.Serialization; /// /// Handles serializing and deserializing models between different formats as necessary. /// -/// The library component a given instance is associated with. [RequiresDynamicCode("Serialization in DSharpPlus presently depends on unreferenced and dynamic code.")] [RequiresUnreferencedCode("Serialization in DSharpPlus presently depends on unreferenced and dynamic code.")] -public sealed partial class SerializationService : ISerializationService +public sealed partial class SerializationService +( + IOptions options, + IServiceProvider services, + ILogger> logger +) { - private readonly string format; - - private readonly JsonSerializerOptions? jsonOptions; - - public SerializationService - ( - IOptions formats, - ILogger> logger, - IServiceProvider provider - ) + /// + public TModel DeserializeModel(ReadOnlySpan data) + where TModel : notnull { - if (formats.Value.Formats.TryGetValue(typeof(T), out string? format)) - { - LogFormatSpecified(logger, format, typeof(T)); + ISerializationBackend backendImpl; - this.format = format; + if + ( + options.Value.Formats.TryGetValue(typeof(T), out string? name) + && options.Value.BackendImplementations.TryGetValue(name, out Type? backendType) + ) + { + backendImpl = (ISerializationBackend)services.GetRequiredService(backendType); } else { LogFormatFallback(logger, typeof(T)); - - this.format = "json"; + backendImpl = services.GetRequiredService(); } - if (this.format == "json") - { - this.jsonOptions = provider.GetRequiredService>().Get("dsharpplus"); - - foreach (KeyValuePair map in formats.Value.InterfacesToConcrete) - { - this.jsonOptions.Converters.Add - ( - (JsonConverter)typeof(RedirectingConverter<,>) - .MakeGenericType(map.Key, map.Value) - .GetConstructor(Type.EmptyTypes)! - .Invoke(null)! - ); - } - - this.jsonOptions.MakeReadOnly(); - } - } - - /// - public TModel DeserializeModel - ( - ReadOnlySpan data - ) - where TModel : notnull - { - return this.format switch - { - "json" => JsonSerializer.Deserialize(data, this.jsonOptions)!, - _ => throw new InvalidOperationException($"The model could not be deserialized from {this.format}."), - }; + return backendImpl.DeserializeModel(data); } /// @@ -89,29 +55,24 @@ ArrayPoolBufferWriter target ) where TModel : notnull { - switch (this.format) + ISerializationBackend backendImpl; + + if + ( + options.Value.Formats.TryGetValue(typeof(T), out string? name) + && options.Value.BackendImplementations.TryGetValue(name, out Type? backendType) + ) { - case "json": - { - using Utf8JsonWriter writer = new(target); - JsonSerializer.Serialize(writer, model, this.jsonOptions!); - break; - } - default: - throw new InvalidOperationException($"The model could not be serialized to {this.format}."); + backendImpl = (ISerializationBackend)services.GetRequiredService(backendType); + } + else + { + LogFormatFallback(logger, typeof(T)); + backendImpl = services.GetRequiredService(); } - } - [LoggerMessage( - Level = LogLevel.Information, - Message = "Setting serialization format {Format} for library component {Component}." - )] - private static partial void LogFormatSpecified - ( - ILogger logger, - string format, - Type component - ); + backendImpl.SerializeModel(model, target); + } [LoggerMessage( Level = LogLevel.Warning, diff --git a/src/core/DSharpPlus.Shared/Serialization/SystemTextJsonFormatMarker.cs b/src/core/DSharpPlus.Shared/Serialization/SystemTextJsonFormatMarker.cs new file mode 100644 index 0000000000..898800f253 --- /dev/null +++ b/src/core/DSharpPlus.Shared/Serialization/SystemTextJsonFormatMarker.cs @@ -0,0 +1,14 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Serialization; + +/// +/// Provides a marker type to force to use System.Text.Json. +/// +public abstract class SystemTextJsonFormatMarker +{ + // can't inherit it + internal SystemTextJsonFormatMarker() { } +} diff --git a/src/core/DSharpPlus.Shared/Serialization/SystemTextJsonSerializationBackend.cs b/src/core/DSharpPlus.Shared/Serialization/SystemTextJsonSerializationBackend.cs new file mode 100644 index 0000000000..73ae5a1c0c --- /dev/null +++ b/src/core/DSharpPlus.Shared/Serialization/SystemTextJsonSerializationBackend.cs @@ -0,0 +1,61 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; +using System.Collections.Generic; +using System.Text.Json.Serialization; +using System.Text.Json; + +using CommunityToolkit.HighPerformance.Buffers; + +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Options; + +namespace DSharpPlus.Serialization; + +/// +/// Implements a System.Text.Json-based serialization backend; the default backend used across DSharpPlus. +/// +public sealed class SystemTextJsonSerializationBackend : ISerializationBackend +{ + private readonly JsonSerializerOptions? jsonOptions; + + public SystemTextJsonSerializationBackend + ( + IOptions formats, + IServiceProvider provider + ) + { + this.jsonOptions = provider.GetRequiredService>().Get("dsharpplus"); + + foreach (KeyValuePair map in formats.Value.InterfacesToConcrete) + { + this.jsonOptions.Converters.Add + ( + (JsonConverter)typeof(RedirectingConverter<,>) + .MakeGenericType(map.Key, map.Value) + .GetConstructor(Type.EmptyTypes)! + .Invoke(null)! + ); + } + + this.jsonOptions.MakeReadOnly(); + } + + // the default STJ backend gets to be just 'json' + public static string Id => "json"; + + /// + public TModel DeserializeModel(ReadOnlySpan data) + where TModel : notnull + => JsonSerializer.Deserialize(data, this.jsonOptions)!; + + /// + public void SerializeModel(TModel model, ArrayPoolBufferWriter target) + where TModel : notnull + { + using Utf8JsonWriter writer = new(target); + JsonSerializer.Serialize(writer, model, this.jsonOptions!); + } +} diff --git a/tests/core/DSharpPlus.Internal.Models.Tests/Converters/AuditLogChangeTests.cs b/tests/core/DSharpPlus.Internal.Models.Tests/Converters/AuditLogChangeTests.cs index 47ca2d0e37..6e04e2b7ec 100644 --- a/tests/core/DSharpPlus.Internal.Models.Tests/Converters/AuditLogChangeTests.cs +++ b/tests/core/DSharpPlus.Internal.Models.Tests/Converters/AuditLogChangeTests.cs @@ -20,7 +20,7 @@ namespace DSharpPlus.Internal.Models.Tests.Converters; public class AuditLogChangeTests { - private readonly ISerializationService serializer; + private readonly SerializationService serializer; public AuditLogChangeTests() { @@ -36,10 +36,11 @@ public AuditLogChangeTests() builder => builder.ClearProviders().AddProvider(NullLoggerProvider.Instance) ); - services.AddSingleton(typeof(ISerializationService<>), typeof(SerializationService<>)); + services.AddSingleton(typeof(SerializationService<>)); + services.AddSingleton(); IServiceProvider provider = services.BuildServiceProvider(); - this.serializer = provider.GetRequiredService>(); + this.serializer = provider.GetRequiredService>(); } private static readonly byte[] IntPayload = diff --git a/tests/core/DSharpPlus.Internal.Models.Tests/Converters/ComponentTests.cs b/tests/core/DSharpPlus.Internal.Models.Tests/Converters/ComponentTests.cs index 3a33192746..ef8f472bf4 100644 --- a/tests/core/DSharpPlus.Internal.Models.Tests/Converters/ComponentTests.cs +++ b/tests/core/DSharpPlus.Internal.Models.Tests/Converters/ComponentTests.cs @@ -18,7 +18,7 @@ namespace DSharpPlus.Internal.Models.Tests.Converters; public class ComponentTests { - private readonly ISerializationService serializer; + private readonly SerializationService serializer; public ComponentTests() { @@ -34,10 +34,11 @@ public ComponentTests() builder => builder.ClearProviders().AddProvider(NullLoggerProvider.Instance) ); - services.AddSingleton(typeof(ISerializationService<>), typeof(SerializationService<>)); + services.AddSingleton(typeof(SerializationService<>)); + services.AddSingleton(); IServiceProvider provider = services.BuildServiceProvider(); - this.serializer = provider.GetRequiredService>(); + this.serializer = provider.GetRequiredService>(); } private static ReadOnlySpan ActionRowTestPayload => diff --git a/tests/core/DSharpPlus.Internal.Models.Tests/Converters/OneOfConverterTests.Models.cs b/tests/core/DSharpPlus.Internal.Models.Tests/Converters/OneOfConverterTests.Models.cs index 1e5de784f7..7555ec7864 100644 --- a/tests/core/DSharpPlus.Internal.Models.Tests/Converters/OneOfConverterTests.Models.cs +++ b/tests/core/DSharpPlus.Internal.Models.Tests/Converters/OneOfConverterTests.Models.cs @@ -21,7 +21,7 @@ namespace DSharpPlus.Internal.Models.Tests.Converters; // tests one-of deserialization on example payloads for actual models partial class OneOfConverterTests { - private readonly ISerializationService serializer; + private readonly SerializationService serializer; public OneOfConverterTests() { @@ -37,10 +37,11 @@ public OneOfConverterTests() builder => builder.ClearProviders().AddProvider(NullLoggerProvider.Instance) ); - services.AddSingleton(typeof(ISerializationService<>), typeof(SerializationService<>)); + services.AddSingleton(typeof(SerializationService<>)); + services.AddSingleton(); IServiceProvider provider = services.BuildServiceProvider(); - this.serializer = provider.GetRequiredService>(); + this.serializer = provider.GetRequiredService>(); } [Fact] From 2dd599b3540c9ada834f36778c6006bd2ba093b7 Mon Sep 17 00:00:00 2001 From: akiraveliara Date: Sun, 17 Nov 2024 20:15:23 +0100 Subject: [PATCH 319/323] support soundboard and update to latest api docs --- .gitattributes | 1 + DSharpPlus.slnx | 2 +- Directory.Build.props | 2 +- .../Applications/IPartialApplication.cs | 4 +- .../Soundboard/IPartialSoundboardSound.cs | 51 +++++ .../Soundboard/ISoundboardSound.cs | 41 ++++ .../API/ISoundboardRestAPI.cs | 135 ++++++++++++ .../IEditCurrentApplicationPayload.cs | 4 +- .../Channels/IModifyGroupDMPayload.cs | 2 +- .../Emojis/ICreateApplicationEmojiPayload.cs | 2 +- .../Emojis/ICreateGuildEmojiPayload.cs | 2 +- .../ICreateGuildFromGuildTemplatePayload.cs | 2 +- .../Payloads/Guilds/ICreateGuildPayload.cs | 2 +- .../Guilds/ICreateGuildRolePayload.cs | 2 +- .../Payloads/Guilds/IModifyGuildPayload.cs | 8 +- .../Guilds/IModifyGuildRolePayload.cs | 2 +- .../IEditInteractionResponsePayload.cs | 5 + .../ICreateGuildScheduledEventPayload.cs | 2 +- .../IModifyGuildScheduledEventPayload.cs | 2 +- .../ICreateGuildSoundboardSoundPayload.cs | 36 ++++ .../IModifyGuildSoundboardSoundPayload.cs | 31 +++ .../Soundboard/ISendSoundboardSoundPayload.cs | 22 ++ .../Users/IModifyCurrentUserPayload.cs | 4 +- .../Webhooks/ICreateWebhookPayload.cs | 2 +- .../Webhooks/IModifyWebhookPayload.cs | 2 +- .../IModifyWebhookWithTokenPayload.cs | 2 +- .../ListSkuSubscriptionsQuery.cs | 1 - .../ListGuildSoundboardSoundsResponse.cs | 20 ++ .../Applications/Application.cs | 4 +- .../Applications/PartialApplication.cs | 4 +- ...erviceCollectionExtensions.Registration.cs | 2 + .../Extensions/ServiceCollectionExtensions.cs | 2 + .../Converters/ImageDataConverter.cs | 6 +- .../AttachmentDataTypeInfoResolver.cs | 36 ++++ .../Soundboard/PartialSoundboardSound.cs | 35 ++++ .../Soundboard/SoundboardSound.cs | 35 ++++ .../API/ApplicationCommandsRestAPI.cs | 2 +- .../API/SoundboardRestAPI.cs | 197 ++++++++++++++++++ ...erviceCollectionExtensions.Registration.cs | 2 + .../EditCurrentApplicationPayload.cs | 4 +- .../Payloads/Channels/ModifyGroupDMPayload.cs | 4 +- .../Emojis/CreateApplicationEmojiPayload.cs | 2 +- .../Emojis/CreateGuildEmojiPayload.cs | 4 +- .../CreateGuildFromGuildTemplatePayload.cs | 4 +- .../Payloads/Guilds/CreateGuildPayload.cs | 2 +- .../Payloads/Guilds/CreateGuildRolePayload.cs | 4 +- .../Payloads/Guilds/ModifyGuildPayload.cs | 10 +- .../Payloads/Guilds/ModifyGuildRolePayload.cs | 4 +- .../EditInteractionResponsePayload.cs | 3 + .../CreateGuildScheduledEventPayload.cs | 2 +- .../ModifyGuildScheduledEventPayload.cs | 2 +- .../CreateGuildSoundboardSoundPayload.cs | 26 +++ .../ModifyGuildSoundboardSoundPayload.cs | 23 ++ .../Users/ModifyCurrentUserPayload.cs | 4 +- .../Payloads/Webhooks/CreateWebhookPayload.cs | 4 +- .../Payloads/Webhooks/ModifyWebhookPayload.cs | 4 +- .../Webhooks/ModifyWebhookWithTokenPayload.cs | 4 +- .../DSharpPlus.Internal.Rest/QueryBuilder.cs | 2 +- .../AuditLogs/DiscordAuditLogEvent.cs | 24 +++ ...n.cs => DiscordPermissions.Arithmetics.cs} | 0 ...s.cs => DiscordPermissions.Enumeration.cs} | 14 +- .../Entities/DiscordPermissions.cs | 35 +++- .../{ImageData.cs => InlineMediaData.cs} | 22 +- .../{ImageFormat.cs => MediaFormat.cs} | 6 +- src/core/DSharpPlus.Shared/Optional`1.cs | 3 +- .../Builders/Interactions/ModalBuilder.cs | 2 +- .../Interactions/TextInputComponentBuilder.cs | 6 +- .../Builders/Messages/EmbedBuilder.cs | 4 +- ...arpPlus.Extensions.Internal.Toolbox.csproj | 1 - .../BuiltEditInteractionResponsePayload.cs | 5 +- .../PollResultMessage.cs | 1 - .../DSharpPlus.Internal.Models.Tests.csproj | 2 +- .../DSharpPlus.Shared.Tests.csproj | 2 +- .../TextWriters/IndentedArrayPoolUtf16.cs | 6 +- 74 files changed, 864 insertions(+), 97 deletions(-) create mode 100644 src/core/DSharpPlus.Internal.Abstractions.Models/Soundboard/IPartialSoundboardSound.cs create mode 100644 src/core/DSharpPlus.Internal.Abstractions.Models/Soundboard/ISoundboardSound.cs create mode 100644 src/core/DSharpPlus.Internal.Abstractions.Rest/API/ISoundboardRestAPI.cs create mode 100644 src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Soundboard/ICreateGuildSoundboardSoundPayload.cs create mode 100644 src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Soundboard/IModifyGuildSoundboardSoundPayload.cs create mode 100644 src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Soundboard/ISendSoundboardSoundPayload.cs create mode 100644 src/core/DSharpPlus.Internal.Abstractions.Rest/Responses/ListGuildSoundboardSoundsResponse.cs create mode 100644 src/core/DSharpPlus.Internal.Models/Serialization/Resolvers/AttachmentDataTypeInfoResolver.cs create mode 100644 src/core/DSharpPlus.Internal.Models/Soundboard/PartialSoundboardSound.cs create mode 100644 src/core/DSharpPlus.Internal.Models/Soundboard/SoundboardSound.cs create mode 100644 src/core/DSharpPlus.Internal.Rest/API/SoundboardRestAPI.cs create mode 100644 src/core/DSharpPlus.Internal.Rest/Payloads/Soundboard/CreateGuildSoundboardSoundPayload.cs create mode 100644 src/core/DSharpPlus.Internal.Rest/Payloads/Soundboard/ModifyGuildSoundboardSoundPayload.cs rename src/core/DSharpPlus.Shared/Entities/{DiscordPermissions.Manipulation.cs => DiscordPermissions.Arithmetics.cs} (100%) rename src/core/DSharpPlus.Shared/Entities/{DiscordPermissions.EnumeratePermissions.cs => DiscordPermissions.Enumeration.cs} (85%) rename src/core/DSharpPlus.Shared/{ImageData.cs => InlineMediaData.cs} (82%) rename src/core/DSharpPlus.Shared/{ImageFormat.cs => MediaFormat.cs} (72%) diff --git a/.gitattributes b/.gitattributes index a95dacdbdf..2a64a7c366 100644 --- a/.gitattributes +++ b/.gitattributes @@ -5,4 +5,5 @@ *.yml text eol=crlf *.sln text eol=crlf *.csproj text eol=crlf +*.sh text eol=lf .* text eol=crlf \ No newline at end of file diff --git a/DSharpPlus.slnx b/DSharpPlus.slnx index 330d47c7cc..b339300190 100644 --- a/DSharpPlus.slnx +++ b/DSharpPlus.slnx @@ -18,6 +18,6 @@ - + diff --git a/Directory.Build.props b/Directory.Build.props index 7d0079626a..6e8326d6a5 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -2,7 +2,7 @@ - net9.0 + net10.0 enable disable preview diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/Applications/IPartialApplication.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Applications/IPartialApplication.cs index 06c862e7f5..08c6d01167 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Models/Applications/IPartialApplication.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Applications/IPartialApplication.cs @@ -122,13 +122,13 @@ public interface IPartialApplication /// /// The interactions endpoint url for this app, if it uses HTTP interactions. /// - public Optional InteractionsEndpointUrl { get; } + public Optional InteractionsEndpointUrl { get; } /// /// This application's role connection verification entry point; which, when configured, will render /// the application as a verification method in the guild role verification configuration. /// - public Optional RoleConnectionsVerificationUrl { get; } + public Optional RoleConnectionsVerificationUrl { get; } /// /// Up to five tags describing content and functionality of the application. diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/Soundboard/IPartialSoundboardSound.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Soundboard/IPartialSoundboardSound.cs new file mode 100644 index 0000000000..c268cee76d --- /dev/null +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Soundboard/IPartialSoundboardSound.cs @@ -0,0 +1,51 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Internal.Abstractions.Models; + +/// +/// Represents a playable soundboard sound. +/// +public interface IPartialSoundboardSound +{ + /// + /// The snowflake identifier of this sound. + /// + public Snowflake SoundId { get; } + + /// + /// The user-readable name of this sound. + /// + public Optional Name { get; } + + /// + /// The volume of this sound, in fractions from 0 to 1. + /// + public Optional Volume { get; } + + /// + /// The snowflake identifier of this sound's associated custom emoji. Mutually exclusive with . + /// + public Optional EmojiId { get; } + + /// + /// The name of this sound's associated unicode emoji. Mutually exclusive with . + /// + public Optional EmojiName { get; } + + /// + /// The snowflake identifier of the guild this sound lives in. This may be missing for global soundboard sounds. + /// + public Optional GuildId { get; } + + /// + /// Indicates whether this sound is currently available for use. + /// + public Optional Available { get; } + + /// + /// The user who uploaded this sound, if applicable. + /// + public Optional User { get; } +} diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/Soundboard/ISoundboardSound.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Soundboard/ISoundboardSound.cs new file mode 100644 index 0000000000..aa93e76a73 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Soundboard/ISoundboardSound.cs @@ -0,0 +1,41 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Internal.Abstractions.Models; + +/// +public interface ISoundboardSound : IPartialSoundboardSound +{ + /// + public new string Name { get; } + + /// + public new double Volume { get; } + + /// + public new Snowflake? EmojiId { get; } + + /// + public new string? EmojiName { get; } + + /// + public new bool Available { get; } + + // partial access + + /// + Optional IPartialSoundboardSound.Name => Name; + + /// + Optional IPartialSoundboardSound.Volume => Volume; + + /// + Optional IPartialSoundboardSound.EmojiId => EmojiId; + + /// + Optional IPartialSoundboardSound.EmojiName => EmojiName; + + /// + Optional IPartialSoundboardSound.Available => Available; +} diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/API/ISoundboardRestAPI.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/ISoundboardRestAPI.cs new file mode 100644 index 0000000000..4a1a53350b --- /dev/null +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/ISoundboardRestAPI.cs @@ -0,0 +1,135 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; + +using DSharpPlus.Internal.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Rest.Payloads; +using DSharpPlus.Internal.Abstractions.Rest.Responses; +using DSharpPlus.Results; + +namespace DSharpPlus.Internal.Abstractions.Rest.API; + +/// +/// Provides access to soundboard-related REST API calls. +/// +public interface ISoundboardRestAPI +{ + /// + /// Sends a soundboard sound in the voice channel the current user is connected to. + /// + /// + /// In addition to the relevant soundboard permissions, this also requires that the user + /// is not muted, suppressed, or, importantly, deafened/self-deafened. + /// + /// The snowflake identifier of the channel the user is connected to. + /// The sound ID and source. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + /// A value indicating whether the operation was successful. + public ValueTask SendSoundboardSoundAsync + ( + Snowflake channelId, + ISendSoundboardSoundPayload payload, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Lists the default soundboard sounds that can be used by all users. + /// + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public ValueTask>> ListDefaultSoundboardSoundsAsync + ( + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Lists the soundboard sounds available in the given guild. + /// + /// The snowflake identifier of the guild to query. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public ValueTask> ListGuildSoundboardSoundsAsync + ( + Snowflake guildId, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Gets a soundboard sound from the specified guild. + /// + /// The snowflake identifier of the given guild. + /// The snowflake identifier of the given sound. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + public ValueTask> GetGuildSoundboardSoundAsync + ( + Snowflake guildId, + Snowflake soundId, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Creates a soundboard sound in the specified guild. + /// + /// The snowflake identifier of the given guild. + /// The infomration necessary to create the sound. + /// An optional audit log reason. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + /// The newly created soundboard sound. + public ValueTask> CreateGuildSoundboardSoundAsync + ( + Snowflake guildId, + ICreateGuildSoundboardSoundPayload payload, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Modifies the specified soundboard sound in the specified guild. + /// + /// The snowflake identifier of the given guild. + /// The snowflake identifier of the sound to modify. + /// The infomration necessary to create the sound. + /// An optional audit log reason. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + /// The modified soundboard sound. + public ValueTask> ModifyGuildSoundboardSoundAsync + ( + Snowflake guildId, + Snowflake soundId, + IModifyGuildSoundboardSoundPayload payload, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ); + + /// + /// Deletes the specified soundboard sound in the specified guild. + /// + /// The snowflake identifier of the given guild. + /// The snowflake identifier of the sound to delete. + /// An optional audit log reason. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + /// A value indicating whether deletion was successful. + public ValueTask DeleteGuildSoundboardSoundAsync + ( + Snowflake guildId, + Snowflake soundId, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ); +} diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Applications/IEditCurrentApplicationPayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Applications/IEditCurrentApplicationPayload.cs index fb3857bc81..38a7cfc280 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Applications/IEditCurrentApplicationPayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Applications/IEditCurrentApplicationPayload.cs @@ -42,12 +42,12 @@ public interface IEditCurrentApplicationPayload /// /// The icon for this application. /// - public Optional Icon { get; } + public Optional Icon { get; } /// /// The default rich presence invite cover image for this application. /// - public Optional CoverImage { get; } + public Optional CoverImage { get; } /// /// The interactions endpoint url for this application. diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Channels/IModifyGroupDMPayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Channels/IModifyGroupDMPayload.cs index 3080cc9f8f..cfbdf06143 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Channels/IModifyGroupDMPayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Channels/IModifyGroupDMPayload.cs @@ -17,5 +17,5 @@ public interface IModifyGroupDMPayload /// /// The icon of this group DM channel. /// - public Optional Icon { get; } + public Optional Icon { get; } } diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Emojis/ICreateApplicationEmojiPayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Emojis/ICreateApplicationEmojiPayload.cs index 695b7421b6..ce0b6c2a65 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Emojis/ICreateApplicationEmojiPayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Emojis/ICreateApplicationEmojiPayload.cs @@ -17,5 +17,5 @@ public interface ICreateApplicationEmojiPayload /// /// The 128x128 emoji image. /// - public ImageData Image { get; } + public InlineMediaData Image { get; } } diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Emojis/ICreateGuildEmojiPayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Emojis/ICreateGuildEmojiPayload.cs index 6fc34c6cc7..65d363ea6f 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Emojis/ICreateGuildEmojiPayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Emojis/ICreateGuildEmojiPayload.cs @@ -19,7 +19,7 @@ public interface ICreateGuildEmojiPayload /// /// The 128x128 emoji image. /// - public ImageData Image { get; } + public InlineMediaData Image { get; } /// /// The snowflake identifiers of roles allowed to use this emoji. diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/GuildTemplates/ICreateGuildFromGuildTemplatePayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/GuildTemplates/ICreateGuildFromGuildTemplatePayload.cs index 9883ddbe5c..b58aae10f2 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/GuildTemplates/ICreateGuildFromGuildTemplatePayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/GuildTemplates/ICreateGuildFromGuildTemplatePayload.cs @@ -17,5 +17,5 @@ public interface ICreateGuildFromGuildTemplatePayload /// /// The 128x128 icon for this guild. /// - public Optional Icon { get; } + public Optional Icon { get; } } diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Guilds/ICreateGuildPayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Guilds/ICreateGuildPayload.cs index 7166848e80..9795d0b5d0 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Guilds/ICreateGuildPayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Guilds/ICreateGuildPayload.cs @@ -22,7 +22,7 @@ public interface ICreateGuildPayload /// /// The 128x128 icon of this guild. /// - public Optional Icon { get; } + public Optional Icon { get; } /// /// The verification level required by this guild. diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Guilds/ICreateGuildRolePayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Guilds/ICreateGuildRolePayload.cs index def297f844..ea5aa37c41 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Guilds/ICreateGuildRolePayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Guilds/ICreateGuildRolePayload.cs @@ -34,7 +34,7 @@ public interface ICreateGuildRolePayload /// /// The role's icon image, if it is a custom icon. /// - public Optional Icon { get; init; } + public Optional Icon { get; init; } /// /// The role's unicode emoji as role icon, if applicable. diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Guilds/IModifyGuildPayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Guilds/IModifyGuildPayload.cs index eac9bbe2ba..ba00aa2052 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Guilds/IModifyGuildPayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Guilds/IModifyGuildPayload.cs @@ -46,7 +46,7 @@ public interface IModifyGuildPayload /// /// The new icon for this guild. /// - public Optional Icon { get; } + public Optional Icon { get; } /// /// The snowflake identifier of this guild's new owner. Used to transfer guild ownership. @@ -56,17 +56,17 @@ public interface IModifyGuildPayload /// /// The new splash for this guild. /// - public Optional Splash { get; } + public Optional Splash { get; } /// /// The new guild discovery splash for this guild. /// - public Optional DiscoverySplash { get; } + public Optional DiscoverySplash { get; } /// /// The new banner for this guild. /// - public Optional Banner { get; } + public Optional Banner { get; } /// /// The snowflake identifier of the new system channel. diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Guilds/IModifyGuildRolePayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Guilds/IModifyGuildRolePayload.cs index 284f3077e2..26c8d92448 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Guilds/IModifyGuildRolePayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Guilds/IModifyGuildRolePayload.cs @@ -34,7 +34,7 @@ public interface IModifyGuildRolePayload /// /// The role's icon image, if it is a custom icon. /// - public Optional Icon { get; init; } + public Optional Icon { get; init; } /// /// The role's unicode emoji as role icon, if applicable. diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Interactions/IEditInteractionResponsePayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Interactions/IEditInteractionResponsePayload.cs index c159bf4977..00fbeb5933 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Interactions/IEditInteractionResponsePayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Interactions/IEditInteractionResponsePayload.cs @@ -42,4 +42,9 @@ public interface IEditInteractionResponsePayload /// File contents to send or edit. /// public IReadOnlyList? Files { get; } + + /// + /// A poll to add to this message. + /// + public Optional Poll { get; } } diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/ScheduledEvents/ICreateGuildScheduledEventPayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/ScheduledEvents/ICreateGuildScheduledEventPayload.cs index 2370e23f76..8f8d4b8b6e 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/ScheduledEvents/ICreateGuildScheduledEventPayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/ScheduledEvents/ICreateGuildScheduledEventPayload.cs @@ -57,7 +57,7 @@ public interface ICreateGuildScheduledEventPayload /// /// Image data representing the cover image of this scheduled event. /// - public Optional Image { get; } + public Optional Image { get; } /// /// A definition for how often and at what dates this event should recur. diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/ScheduledEvents/IModifyGuildScheduledEventPayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/ScheduledEvents/IModifyGuildScheduledEventPayload.cs index baed1d22d8..d4ad414172 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/ScheduledEvents/IModifyGuildScheduledEventPayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/ScheduledEvents/IModifyGuildScheduledEventPayload.cs @@ -62,7 +62,7 @@ public interface IModifyGuildScheduledEventPayload /// /// Image data representing the cover image of this scheduled event. /// - public Optional Image { get; } + public Optional Image { get; } /// /// A definition for how often and at what dates this event should recur. diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Soundboard/ICreateGuildSoundboardSoundPayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Soundboard/ICreateGuildSoundboardSoundPayload.cs new file mode 100644 index 0000000000..e8d1890289 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Soundboard/ICreateGuildSoundboardSoundPayload.cs @@ -0,0 +1,36 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Internal.Abstractions.Rest.Payloads; + +/// +/// Represents a payload to POST guilds/:guild-id/soundboard-sounds. +/// +public interface ICreateGuildSoundboardSoundPayload +{ + /// + /// The name of the soundboard sound, 2-32 characters long. + /// + public string Name { get; } + + /// + /// The sound data. This must be mp3 or ogg encoded. + /// + public InlineMediaData Sound { get; } + + /// + /// The volume of this soundboard sound, from 0 to 1. Defaults to 1. + /// + public Optional Volume { get; } + + /// + /// The snowflake identifier of the custom emoji associated with this soundboard sound. + /// + public Optional EmojiId { get; } + + /// + /// The unicode representation of the standard emoji associated with this soundboard sound. + /// + public Optional EmojiName { get; } +} diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Soundboard/IModifyGuildSoundboardSoundPayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Soundboard/IModifyGuildSoundboardSoundPayload.cs new file mode 100644 index 0000000000..4dd078c997 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Soundboard/IModifyGuildSoundboardSoundPayload.cs @@ -0,0 +1,31 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Internal.Abstractions.Rest.Payloads; + +/// +/// Represents a payload to PATCH guilds/:guild-id/soundboard-sounds/:sound-id. +/// +public interface IModifyGuildSoundboardSoundPayload +{ + /// + /// The name of the soundboard sound, 2-32 characters long. + /// + public Optional Name { get; } + + /// + /// The volume of this soundboard sound, from 0 to 1. Defaults to 1. + /// + public Optional Volume { get; } + + /// + /// The snowflake identifier of the custom emoji associated with this soundboard sound. + /// + public Optional EmojiId { get; } + + /// + /// The unicode representation of the standard emoji associated with this soundboard sound. + /// + public Optional EmojiName { get; } +} diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Soundboard/ISendSoundboardSoundPayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Soundboard/ISendSoundboardSoundPayload.cs new file mode 100644 index 0000000000..3c5756c360 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Soundboard/ISendSoundboardSoundPayload.cs @@ -0,0 +1,22 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Internal.Abstractions.Rest.Payloads; + +/// +/// Represents a payload to POST channels/:channel-id/send-soundboard-sound. +/// +public interface ISendSoundboardSoundPayload +{ + /// + /// The snowflake identifier of the soundboard sound to play. + /// + public Snowflake SoundId { get; } + + /// + /// The snowflake identifier of the guild the soundboard sound originates from. + /// This is required to play sounds from different guilds to the present guild. + /// + public Optional SourceGuildId { get; } +} diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Users/IModifyCurrentUserPayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Users/IModifyCurrentUserPayload.cs index d96ed6d1ba..2706e2fb4d 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Users/IModifyCurrentUserPayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Users/IModifyCurrentUserPayload.cs @@ -19,10 +19,10 @@ public interface IModifyCurrentUserPayload /// /// The new avatar for this user. /// - public Optional Avatar { get; } + public Optional Avatar { get; } /// /// The new banner for this user. /// - public Optional Banner { get; } + public Optional Banner { get; } } diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Webhooks/ICreateWebhookPayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Webhooks/ICreateWebhookPayload.cs index 88f35f6108..b2e16d4211 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Webhooks/ICreateWebhookPayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Webhooks/ICreateWebhookPayload.cs @@ -26,5 +26,5 @@ public interface ICreateWebhookPayload /// /// The default webhook avatar. This may be overridden by messages. /// - public Optional Avatar { get; } + public Optional Avatar { get; } } diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Webhooks/IModifyWebhookPayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Webhooks/IModifyWebhookPayload.cs index 051cfb84da..d30c6a0316 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Webhooks/IModifyWebhookPayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Webhooks/IModifyWebhookPayload.cs @@ -17,7 +17,7 @@ public interface IModifyWebhookPayload /// /// The new default webhook avatar image. /// - public Optional Avatar { get; } + public Optional Avatar { get; } /// /// The snowflake identifier of the channel this webhook should be moved to. diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Webhooks/IModifyWebhookWithTokenPayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Webhooks/IModifyWebhookWithTokenPayload.cs index b738a52af5..ab77ef072f 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Webhooks/IModifyWebhookWithTokenPayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Webhooks/IModifyWebhookWithTokenPayload.cs @@ -17,5 +17,5 @@ public interface IModifyWebhookWithTokenPayload /// /// The new default webhook avatar image. /// - public Optional Avatar { get; } + public Optional Avatar { get; } } diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Subscriptions/ListSkuSubscriptionsQuery.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Subscriptions/ListSkuSubscriptionsQuery.cs index 9e3d393e74..d96d462b0e 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Subscriptions/ListSkuSubscriptionsQuery.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Subscriptions/ListSkuSubscriptionsQuery.cs @@ -2,7 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. - namespace DSharpPlus.Internal.Abstractions.Rest.Queries; public readonly record struct ListSkuSubscriptionsQuery : IPaginatedQuery diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Responses/ListGuildSoundboardSoundsResponse.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Responses/ListGuildSoundboardSoundsResponse.cs new file mode 100644 index 0000000000..3e58d45619 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Responses/ListGuildSoundboardSoundsResponse.cs @@ -0,0 +1,20 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Internal.Abstractions.Models; + +namespace DSharpPlus.Internal.Abstractions.Rest.Responses; + +/// +/// Represents a response from GET guilds/:guild-id/soundboard-sounds. +/// +public readonly record struct ListGuildSoundboardSoundsResponse +{ + /// + /// The soundboard sounds present in the provided guild. + /// + public IReadOnlyList Items { get; init; } +} diff --git a/src/core/DSharpPlus.Internal.Models/Applications/Application.cs b/src/core/DSharpPlus.Internal.Models/Applications/Application.cs index 6fe5f43126..b099ba05f2 100644 --- a/src/core/DSharpPlus.Internal.Models/Applications/Application.cs +++ b/src/core/DSharpPlus.Internal.Models/Applications/Application.cs @@ -76,10 +76,10 @@ public sealed record Application : IApplication public Optional> RedirectUris { get; init; } /// - public Optional InteractionsEndpointUrl { get; init; } + public Optional InteractionsEndpointUrl { get; init; } /// - public Optional RoleConnectionsVerificationUrl { get; init; } + public Optional RoleConnectionsVerificationUrl { get; init; } /// public Optional> Tags { get; init; } diff --git a/src/core/DSharpPlus.Internal.Models/Applications/PartialApplication.cs b/src/core/DSharpPlus.Internal.Models/Applications/PartialApplication.cs index 72eb1faf15..c1edbc339c 100644 --- a/src/core/DSharpPlus.Internal.Models/Applications/PartialApplication.cs +++ b/src/core/DSharpPlus.Internal.Models/Applications/PartialApplication.cs @@ -76,10 +76,10 @@ public sealed record PartialApplication : IPartialApplication public Optional> RedirectUris { get; init; } /// - public Optional InteractionsEndpointUrl { get; init; } + public Optional InteractionsEndpointUrl { get; init; } /// - public Optional RoleConnectionsVerificationUrl { get; init; } + public Optional RoleConnectionsVerificationUrl { get; init; } /// public Optional> Tags { get; init; } diff --git a/src/core/DSharpPlus.Internal.Models/Extensions/ServiceCollectionExtensions.Registration.cs b/src/core/DSharpPlus.Internal.Models/Extensions/ServiceCollectionExtensions.Registration.cs index 84f2236e96..836f9dea78 100644 --- a/src/core/DSharpPlus.Internal.Models/Extensions/ServiceCollectionExtensions.Registration.cs +++ b/src/core/DSharpPlus.Internal.Models/Extensions/ServiceCollectionExtensions.Registration.cs @@ -139,6 +139,8 @@ private static void RegisterSerialization(IServiceCollection services) options.AddModel(); options.AddModel(); options.AddModel(); + options.AddModel(); + options.AddModel(); options.AddModel(); options.AddModel(); options.AddModel(); diff --git a/src/core/DSharpPlus.Internal.Models/Extensions/ServiceCollectionExtensions.cs b/src/core/DSharpPlus.Internal.Models/Extensions/ServiceCollectionExtensions.cs index f3b43c385e..2382a3a8eb 100644 --- a/src/core/DSharpPlus.Internal.Models/Extensions/ServiceCollectionExtensions.cs +++ b/src/core/DSharpPlus.Internal.Models/Extensions/ServiceCollectionExtensions.cs @@ -52,6 +52,8 @@ public static IServiceCollection RegisterDiscordModelSerialization options.TypeInfoResolverChain.Add(OptionalTypeInfoResolver.Default); options.TypeInfoResolverChain.Add(NullBooleanTypeInfoResolver.Default); + // this needs to be below OptionalTypeInfoResolver so as to avoid the former overwriting this + options.TypeInfoResolverChain.Add(AttachmentDataTypeInfoResolver.Default); } ); diff --git a/src/core/DSharpPlus.Internal.Models/Serialization/Converters/ImageDataConverter.cs b/src/core/DSharpPlus.Internal.Models/Serialization/Converters/ImageDataConverter.cs index f40f9d50a5..ed6e403032 100644 --- a/src/core/DSharpPlus.Internal.Models/Serialization/Converters/ImageDataConverter.cs +++ b/src/core/DSharpPlus.Internal.Models/Serialization/Converters/ImageDataConverter.cs @@ -10,17 +10,17 @@ namespace DSharpPlus.Serialization; -public sealed class ImageDataConverter : JsonConverter +public sealed class ImageDataConverter : JsonConverter { /// /// Deserializing image data is unsupported. /// - public override ImageData Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) => throw new NotSupportedException(); + public override InlineMediaData Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) => throw new NotSupportedException(); public override void Write ( Utf8JsonWriter writer, - ImageData value, + InlineMediaData value, JsonSerializerOptions options ) { diff --git a/src/core/DSharpPlus.Internal.Models/Serialization/Resolvers/AttachmentDataTypeInfoResolver.cs b/src/core/DSharpPlus.Internal.Models/Serialization/Resolvers/AttachmentDataTypeInfoResolver.cs new file mode 100644 index 0000000000..03072c4b91 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Models/Serialization/Resolvers/AttachmentDataTypeInfoResolver.cs @@ -0,0 +1,36 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; +using System.Collections.Generic; +using System.Text.Json.Serialization.Metadata; + +namespace DSharpPlus.Internal.Models.Serialization.Resolvers; + +public static class AttachmentDataTypeInfoResolver +{ + public static IJsonTypeInfoResolver Default { get; } = new DefaultJsonTypeInfoResolver + { + Modifiers = + { + (type) => + { + foreach (JsonPropertyInfo property in type.Properties) + { + if + ( + property.PropertyType == typeof(AttachmentData) + || property.PropertyType == typeof(AttachmentData?) + || property.PropertyType == typeof(Optional) + || property.PropertyType == typeof(Optional) + || property.PropertyType == typeof(IReadOnlyList) + ) + { + property.ShouldSerialize = (_, _) => false; + } + } + } + } + }; +} diff --git a/src/core/DSharpPlus.Internal.Models/Soundboard/PartialSoundboardSound.cs b/src/core/DSharpPlus.Internal.Models/Soundboard/PartialSoundboardSound.cs new file mode 100644 index 0000000000..c3d9bad26b --- /dev/null +++ b/src/core/DSharpPlus.Internal.Models/Soundboard/PartialSoundboardSound.cs @@ -0,0 +1,35 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Internal.Abstractions.Models; + +namespace DSharpPlus.Internal.Models; + +/// +public sealed record PartialSoundboardSound : IPartialSoundboardSound +{ + /// + public required Snowflake SoundId { get; init; } + + /// + public Optional Name { get; init; } + + /// + public Optional Volume { get; init; } + + /// + public Optional EmojiId { get; init; } + + /// + public Optional EmojiName { get; init; } + + /// + public Optional GuildId { get; init; } + + /// + public Optional Available { get; init; } + + /// + public Optional User { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Models/Soundboard/SoundboardSound.cs b/src/core/DSharpPlus.Internal.Models/Soundboard/SoundboardSound.cs new file mode 100644 index 0000000000..47b78e29c5 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Models/Soundboard/SoundboardSound.cs @@ -0,0 +1,35 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Internal.Abstractions.Models; + +namespace DSharpPlus.Internal.Models; + +/// +public sealed record SoundboardSound : ISoundboardSound +{ + /// + public required Snowflake SoundId { get; init; } + + /// + public required string Name { get; init; } + + /// + public required double Volume { get; init; } + + /// + public Snowflake? EmojiId { get; init; } + + /// + public string? EmojiName { get; init; } + + /// + public Optional GuildId { get; init; } + + /// + public required bool Available { get; init; } + + /// + public Optional User { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Rest/API/ApplicationCommandsRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/ApplicationCommandsRestAPI.cs index 5af686b3c2..5f306c2c68 100644 --- a/src/core/DSharpPlus.Internal.Rest/API/ApplicationCommandsRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Rest/API/ApplicationCommandsRestAPI.cs @@ -27,7 +27,7 @@ namespace DSharpPlus.Internal.Rest.API; public sealed class ApplicationCommandsRestAPI ( IRestClient restClient, - ISerializationService serializationService + SerializationService serializationService ) : IApplicationCommandsRestAPI { diff --git a/src/core/DSharpPlus.Internal.Rest/API/SoundboardRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/SoundboardRestAPI.cs new file mode 100644 index 0000000000..a1acdc4b5f --- /dev/null +++ b/src/core/DSharpPlus.Internal.Rest/API/SoundboardRestAPI.cs @@ -0,0 +1,197 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +#pragma warning disable IDE0046 + +using System.Collections.Generic; +using System.Net.Http; +using System.Threading; +using System.Threading.Tasks; + +using DSharpPlus.Internal.Abstractions.Models; +using DSharpPlus.Internal.Abstractions.Rest; +using DSharpPlus.Internal.Abstractions.Rest.API; +using DSharpPlus.Internal.Abstractions.Rest.Errors; +using DSharpPlus.Internal.Abstractions.Rest.Payloads; +using DSharpPlus.Internal.Abstractions.Rest.Responses; +using DSharpPlus.Internal.Rest.Ratelimiting; +using DSharpPlus.Results; + +namespace DSharpPlus.Internal.Rest.API; + +/// +public sealed class SoundboardRestAPI(IRestClient restClient) + : ISoundboardRestAPI +{ + /// + public async ValueTask> CreateGuildSoundboardSoundAsync + ( + Snowflake guildId, + ICreateGuildSoundboardSoundPayload payload, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ) + { + if (payload.Name.Length is < 2 or > 32) + { + return new ValidationError("The sound name must be between 2 and 32 characters."); + } + + if (payload.Volume.TryGetNonNullValue(out double? value) && value is < 0.0 or > 1.0) + { + return new ValidationError("The sound volume must be between 0.0 and 1.0."); + } + + if (payload.EmojiId.TryGetNonNullValue(out _) && payload.EmojiName.TryGetNonNullValue(out _)) + { + return new ValidationError("A sound must not have a custom emoji and an unicode emoji defined at the same time."); + } + + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Post, + $"guilds/{guildId}/soundboard-sounds", + b => b.WithPayload(payload) + .WithSimpleRoute(TopLevelResource.Guild, guildId) + .WithAuditLogReason(reason), + info, + ct + ); + } + + /// + public async ValueTask DeleteGuildSoundboardSoundAsync + ( + Snowflake guildId, + Snowflake soundId, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ) + { + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Post, + $"guilds/{guildId}/soundboard-sounds/{soundId}", + b => b.WithSimpleRoute(TopLevelResource.Guild, guildId) + .WithRoute($"POST guilds/{guildId}/soundboard-sounds/:sound-id") + .WithAuditLogReason(reason), + info, + ct + ); + } + + /// + public async ValueTask> GetGuildSoundboardSoundAsync + ( + Snowflake guildId, + Snowflake soundId, + RequestInfo info = default, + CancellationToken ct = default + ) + { + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Get, + $"guilds/{guildId}/soundboard-sounds/{soundId}", + b => b.WithSimpleRoute(TopLevelResource.Guild, guildId) + .WithRoute($"GET guilds/{guildId}/soundboard-sounds/:sound-id"), + info, + ct + ); + } + + /// + public async ValueTask>> ListDefaultSoundboardSoundsAsync + ( + RequestInfo info = default, + CancellationToken ct = default + ) + { + return await restClient.ExecuteRequestAsync> + ( + HttpMethod.Get, + "soundboard-default-sounds", + info: info, + ct: ct + ); + } + + /// + public async ValueTask> ListGuildSoundboardSoundsAsync + ( + Snowflake guildId, + RequestInfo info = default, + CancellationToken ct = default + ) + { + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Get, + $"guilds/{guildId}/soundboard-sounds/", + b => b.WithSimpleRoute(TopLevelResource.Guild, guildId), + info, + ct + ); + } + + /// + public async ValueTask> ModifyGuildSoundboardSoundAsync + ( + Snowflake guildId, + Snowflake soundId, + IModifyGuildSoundboardSoundPayload payload, + string? reason = null, + RequestInfo info = default, + CancellationToken ct = default + ) + { + if (payload.Name.TryGetNonNullValue(out string? name) && name.Length is < 2 or > 32) + { + return new ValidationError("The sound name must be between 2 and 32 characters."); + } + + if (payload.Volume.TryGetNonNullValue(out double? value) && value is < 0.0 or > 1.0) + { + return new ValidationError("The sound volume must be between 0.0 and 1.0."); + } + + if (payload.EmojiId.TryGetNonNullValue(out _) && payload.EmojiName.TryGetNonNullValue(out _)) + { + return new ValidationError("A sound must not have a custom emoji and an unicode emoji defined at the same time."); + } + + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Patch, + $"guilds/{guildId}/soundboard-sounds", + b => b.WithPayload(payload) + .WithSimpleRoute(TopLevelResource.Guild, guildId) + .WithAuditLogReason(reason), + info, + ct + ); + } + + /// + public async ValueTask SendSoundboardSoundAsync + ( + Snowflake channelId, + ISendSoundboardSoundPayload payload, + RequestInfo info = default, + CancellationToken ct = default + ) + { + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Post, + $"channels/{channelId}/send-soundboard-sound", + b => b.WithSimpleRoute(TopLevelResource.Channel, channelId) + .WithPayload(payload), + info, + ct + ); + } +} diff --git a/src/core/DSharpPlus.Internal.Rest/Extensions/ServiceCollectionExtensions.Registration.cs b/src/core/DSharpPlus.Internal.Rest/Extensions/ServiceCollectionExtensions.Registration.cs index fdd7a046ee..9a2d7e4b0f 100644 --- a/src/core/DSharpPlus.Internal.Rest/Extensions/ServiceCollectionExtensions.Registration.cs +++ b/src/core/DSharpPlus.Internal.Rest/Extensions/ServiceCollectionExtensions.Registration.cs @@ -69,6 +69,8 @@ private static void RegisterSerialization(IServiceCollection services) options.AddModel(); options.AddModel(); options.AddModel(); + options.AddModel(); + options.AddModel(); options.AddModel(); options.AddModel(); options.AddModel(); diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Applications/EditCurrentApplicationPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Applications/EditCurrentApplicationPayload.cs index 5a6890811f..ab4be9fae3 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/Applications/EditCurrentApplicationPayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Applications/EditCurrentApplicationPayload.cs @@ -29,10 +29,10 @@ public sealed record EditCurrentApplicationPayload : IEditCurrentApplicationPayl public Optional Flags { get; init; } /// - public Optional Icon { get; init; } + public Optional Icon { get; init; } /// - public Optional CoverImage { get; init; } + public Optional CoverImage { get; init; } /// public Optional InteractionsEndpointUrl { get; init; } diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/ModifyGroupDMPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/ModifyGroupDMPayload.cs index 568f84b817..2a58fd64fd 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/ModifyGroupDMPayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Channels/ModifyGroupDMPayload.cs @@ -13,5 +13,5 @@ public sealed record ModifyGroupDMPayload : IModifyGroupDMPayload public Optional Name { get; init; } /// - public Optional Icon { get; init; } -} + public Optional Icon { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Emojis/CreateApplicationEmojiPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Emojis/CreateApplicationEmojiPayload.cs index 0480308d43..bc1dd2a503 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/Emojis/CreateApplicationEmojiPayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Emojis/CreateApplicationEmojiPayload.cs @@ -13,5 +13,5 @@ public sealed record CreateApplicationEmojiPayload : ICreateApplicationEmojiPayl public required string Name { get; init; } /// - public required ImageData Image { get; init; } + public required InlineMediaData Image { get; init; } } \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Emojis/CreateGuildEmojiPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Emojis/CreateGuildEmojiPayload.cs index 082c6283ff..fdb1efe990 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/Emojis/CreateGuildEmojiPayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Emojis/CreateGuildEmojiPayload.cs @@ -15,8 +15,8 @@ public sealed record CreateGuildEmojiPayload : ICreateGuildEmojiPayload public required string Name { get; init; } /// - public required ImageData Image { get; init; } + public required InlineMediaData Image { get; init; } /// public Optional> Roles { get; init; } -} +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/GuildTemplates/CreateGuildFromGuildTemplatePayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/GuildTemplates/CreateGuildFromGuildTemplatePayload.cs index ab9c07b803..a47cbfd8be 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/GuildTemplates/CreateGuildFromGuildTemplatePayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/GuildTemplates/CreateGuildFromGuildTemplatePayload.cs @@ -13,5 +13,5 @@ public sealed record CreateGuildFromGuildTemplatePayload : ICreateGuildFromGuild public required string Name { get; init; } /// - public Optional Icon { get; init; } -} + public Optional Icon { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/CreateGuildPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/CreateGuildPayload.cs index 9713248373..385b982370 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/CreateGuildPayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/CreateGuildPayload.cs @@ -17,7 +17,7 @@ public sealed record CreateGuildPayload : ICreateGuildPayload public required string Name { get; init; } /// - public Optional Icon { get; init; } + public Optional Icon { get; init; } /// public Optional VerificationLevel { get; init; } diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/CreateGuildRolePayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/CreateGuildRolePayload.cs index 1da1701af7..045d445716 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/CreateGuildRolePayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/CreateGuildRolePayload.cs @@ -23,11 +23,11 @@ public sealed record CreateGuildRolePayload : ICreateGuildRolePayload public Optional Hoist { get; init; } /// - public Optional Icon { get; init; } + public Optional Icon { get; init; } /// public Optional UnicodeEmoji { get; init; } /// public Optional Mentionable { get; init; } -} +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyGuildPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyGuildPayload.cs index c4f5f15c6f..d3ecc90225 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyGuildPayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyGuildPayload.cs @@ -31,19 +31,19 @@ public sealed record ModifyGuildPayload : IModifyGuildPayload public Optional AfkTimeout { get; init; } /// - public Optional Icon { get; init; } + public Optional Icon { get; init; } /// public Optional OwnerId { get; init; } /// - public Optional Splash { get; init; } + public Optional Splash { get; init; } /// - public Optional DiscoverySplash { get; init; } + public Optional DiscoverySplash { get; init; } /// - public Optional Banner { get; init; } + public Optional Banner { get; init; } /// public Optional SystemChannelId { get; init; } @@ -71,4 +71,4 @@ public sealed record ModifyGuildPayload : IModifyGuildPayload /// public Optional SafetyAlertsChannelId { get; init; } -} +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyGuildRolePayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyGuildRolePayload.cs index 78a1a9b50e..eea0f47f9f 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyGuildRolePayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyGuildRolePayload.cs @@ -23,11 +23,11 @@ public sealed record ModifyGuildRolePayload : IModifyGuildRolePayload public Optional Hoist { get; init; } /// - public Optional Icon { get; init; } + public Optional Icon { get; init; } /// public Optional UnicodeEmoji { get; init; } /// public Optional Mentionable { get; init; } -} +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Interactions/EditInteractionResponsePayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Interactions/EditInteractionResponsePayload.cs index a8cc2f374b..180701af7e 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/Interactions/EditInteractionResponsePayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Interactions/EditInteractionResponsePayload.cs @@ -29,4 +29,7 @@ public sealed record EditInteractionResponsePayload : IEditInteractionResponsePa /// public IReadOnlyList? Files { get; init; } + + /// + public Optional Poll { get; init; } } \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/ScheduledEvents/CreateGuildScheduledEventPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/ScheduledEvents/CreateGuildScheduledEventPayload.cs index 1518227adc..0fe9970a0b 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/ScheduledEvents/CreateGuildScheduledEventPayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/ScheduledEvents/CreateGuildScheduledEventPayload.cs @@ -38,7 +38,7 @@ public sealed record CreateGuildScheduledEventPayload : ICreateGuildScheduledEve public required DiscordScheduledEventType EntityType { get; init; } /// - public Optional Image { get; init; } + public Optional Image { get; init; } /// public Optional RecurrenceRule { get; init; } diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/ScheduledEvents/ModifyGuildScheduledEventPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/ScheduledEvents/ModifyGuildScheduledEventPayload.cs index a1f2a4214b..412eda735b 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/ScheduledEvents/ModifyGuildScheduledEventPayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/ScheduledEvents/ModifyGuildScheduledEventPayload.cs @@ -41,7 +41,7 @@ public sealed record ModifyGuildScheduledEventPayload : IModifyGuildScheduledEve public Optional Status { get; init; } /// - public Optional Image { get; init; } + public Optional Image { get; init; } /// public Optional RecurrenceRule { get; init; } diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Soundboard/CreateGuildSoundboardSoundPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Soundboard/CreateGuildSoundboardSoundPayload.cs new file mode 100644 index 0000000000..7e309fded7 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Soundboard/CreateGuildSoundboardSoundPayload.cs @@ -0,0 +1,26 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Internal.Abstractions.Rest.Payloads; + +namespace DSharpPlus.Internal.Rest.Payloads; + +/// +public sealed record CreateGuildSoundboardSoundPayload : ICreateGuildSoundboardSoundPayload +{ + /// + public required string Name { get; init; } + + /// + public required InlineMediaData Sound { get; init; } + + /// + public Optional Volume { get; init; } + + /// + public Optional EmojiId { get; init; } + + /// + public Optional EmojiName { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Soundboard/ModifyGuildSoundboardSoundPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Soundboard/ModifyGuildSoundboardSoundPayload.cs new file mode 100644 index 0000000000..98ab221515 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Soundboard/ModifyGuildSoundboardSoundPayload.cs @@ -0,0 +1,23 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Internal.Abstractions.Rest.Payloads; + +namespace DSharpPlus.Internal.Rest.Payloads; + +/// +public sealed record ModifyGuildSoundboardSoundPayload : IModifyGuildSoundboardSoundPayload +{ + /// + public Optional Name { get; init; } + + /// + public Optional Volume { get; init; } + + /// + public Optional EmojiId { get; init; } + + /// + public Optional EmojiName { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Users/ModifyCurrentUserPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Users/ModifyCurrentUserPayload.cs index 30aab26145..f0adf1c6a5 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/Users/ModifyCurrentUserPayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Users/ModifyCurrentUserPayload.cs @@ -13,8 +13,8 @@ public sealed record ModifyCurrentUserPayload : IModifyCurrentUserPayload public Optional Username { get; init; } /// - public Optional Avatar { get; init; } + public Optional Avatar { get; init; } /// - public Optional Banner { get; init; } + public Optional Banner { get; init; } } \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Webhooks/CreateWebhookPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Webhooks/CreateWebhookPayload.cs index b9c5145e2d..a9ca335f57 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/Webhooks/CreateWebhookPayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Webhooks/CreateWebhookPayload.cs @@ -13,5 +13,5 @@ public sealed record CreateWebhookPayload : ICreateWebhookPayload public required string Name { get; init; } /// - public Optional Avatar { get; init; } -} + public Optional Avatar { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Webhooks/ModifyWebhookPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Webhooks/ModifyWebhookPayload.cs index f01edbb06b..f292d1a108 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/Webhooks/ModifyWebhookPayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Webhooks/ModifyWebhookPayload.cs @@ -13,8 +13,8 @@ public sealed record ModifyWebhookPayload : IModifyWebhookPayload public Optional Name { get; init; } /// - public Optional Avatar { get; init; } + public Optional Avatar { get; init; } /// public Optional ChannelId { get; init; } -} +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Webhooks/ModifyWebhookWithTokenPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Webhooks/ModifyWebhookWithTokenPayload.cs index bc700053b2..b7cfd2950a 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/Webhooks/ModifyWebhookWithTokenPayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Webhooks/ModifyWebhookWithTokenPayload.cs @@ -13,5 +13,5 @@ public sealed record ModifyWebhookWithTokenPayload : IModifyWebhookWithTokenPayl public Optional Name { get; init; } /// - public Optional Avatar { get; init; } -} + public Optional Avatar { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Rest/QueryBuilder.cs b/src/core/DSharpPlus.Internal.Rest/QueryBuilder.cs index c4a43b39f2..0ac4546b36 100644 --- a/src/core/DSharpPlus.Internal.Rest/QueryBuilder.cs +++ b/src/core/DSharpPlus.Internal.Rest/QueryBuilder.cs @@ -14,7 +14,7 @@ namespace DSharpPlus.Internal.Rest; /// internal record struct QueryBuilder(string RootUri) { - public DictionarySlim Parameters { get; set; } + public DictionarySlim Parameters { get; } = new(); public readonly QueryBuilder AddParameter(string key, string value) { diff --git a/src/core/DSharpPlus.Shared/Entities/AuditLogs/DiscordAuditLogEvent.cs b/src/core/DSharpPlus.Shared/Entities/AuditLogs/DiscordAuditLogEvent.cs index bbe09a5e86..2332cb3bc6 100644 --- a/src/core/DSharpPlus.Shared/Entities/AuditLogs/DiscordAuditLogEvent.cs +++ b/src/core/DSharpPlus.Shared/Entities/AuditLogs/DiscordAuditLogEvent.cs @@ -393,6 +393,30 @@ public enum DiscordAuditLogEvent /// ApplicationCommandPermissionsUpdated = 121, + /// + /// A soundboard sound was created. + /// + /// + /// Metadata is provided for a soundboard sound object. + /// + SoundboardSoundCreated = 130, + + /// + /// A soundboard sound was updated. + /// + /// + /// Metadata is provided for a soundboard sound object. + /// + SoundboardSoundUpdated = 131, + + /// + /// A soundboard sound was deleted. + /// + /// + /// Metadata is provided for a soundboard sound object. + /// + SoundboardSoundDeleted = 132, + /// /// An auto moderation rule was created. /// diff --git a/src/core/DSharpPlus.Shared/Entities/DiscordPermissions.Manipulation.cs b/src/core/DSharpPlus.Shared/Entities/DiscordPermissions.Arithmetics.cs similarity index 100% rename from src/core/DSharpPlus.Shared/Entities/DiscordPermissions.Manipulation.cs rename to src/core/DSharpPlus.Shared/Entities/DiscordPermissions.Arithmetics.cs diff --git a/src/core/DSharpPlus.Shared/Entities/DiscordPermissions.EnumeratePermissions.cs b/src/core/DSharpPlus.Shared/Entities/DiscordPermissions.Enumeration.cs similarity index 85% rename from src/core/DSharpPlus.Shared/Entities/DiscordPermissions.EnumeratePermissions.cs rename to src/core/DSharpPlus.Shared/Entities/DiscordPermissions.Enumeration.cs index 0431d819ea..936232222c 100644 --- a/src/core/DSharpPlus.Shared/Entities/DiscordPermissions.EnumeratePermissions.cs +++ b/src/core/DSharpPlus.Shared/Entities/DiscordPermissions.Enumeration.cs @@ -50,7 +50,8 @@ internal DiscordPermissionEnumerator(DiscordPermissionContainer data) readonly object IEnumerator.Current => this.Current; - private int block = 0; + private bool hasEnteredBlock = false; + private short block = 0; private int bit = -1; public bool MoveNext() @@ -60,12 +61,18 @@ public bool MoveNext() this.bit++; uint value = this.data[this.block]; - if (BitOperations.PopCount(value) == 0) + if (value == 0) { continue; } - for (; this.bit < 32; this.bit++) + if (!this.hasEnteredBlock) + { + this.hasEnteredBlock = true; + this.bit = BitOperations.TrailingZeroCount(value); + } + + for (; this.bit < (32 - BitOperations.LeadingZeroCount(value)); this.bit++) { if (BitHelper.HasFlag(value, this.bit)) { @@ -74,6 +81,7 @@ public bool MoveNext() } this.bit = -1; + this.hasEnteredBlock = false; } return false; diff --git a/src/core/DSharpPlus.Shared/Entities/DiscordPermissions.cs b/src/core/DSharpPlus.Shared/Entities/DiscordPermissions.cs index 7e6d2867ad..2d09528dcc 100644 --- a/src/core/DSharpPlus.Shared/Entities/DiscordPermissions.cs +++ b/src/core/DSharpPlus.Shared/Entities/DiscordPermissions.cs @@ -4,6 +4,7 @@ using System; using System.Buffers.Binary; +using System.Collections.Generic; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.Globalization; @@ -45,6 +46,7 @@ public DiscordPermissions(DiscordPermission permission) /// /// Creates a new instance of this type from the specified permissions. /// + [OverloadResolutionPriority(1)] public DiscordPermissions(params ReadOnlySpan permissions) { foreach (DiscordPermission permission in permissions) @@ -53,6 +55,18 @@ public DiscordPermissions(params ReadOnlySpan permissions) } } + /// + /// Creates a new instance of this type from the specified permissions. + /// + [OverloadResolutionPriority(0)] + public DiscordPermissions(IReadOnlyList permissions) + { + foreach (DiscordPermission permission in permissions) + { + this.data.SetFlag((int)permission, true); + } + } + /// /// Creates a new instance of this type from the specified big integer. This assumes that the data is unsigned. /// @@ -208,15 +222,26 @@ public string ToString(string format) } else if (format == "name") { - StringBuilder builder = new(); + int pop = 0; + + for (int i = 0; i < ContainerElementCount; i += 4) + { + pop += BitOperations.PopCount(this.data[i]); + pop += BitOperations.PopCount(this.data[i + 1]); + pop += BitOperations.PopCount(this.data[i + 2]); + pop += BitOperations.PopCount(this.data[i + 3]); + } + + string[] names = new string[pop]; + DiscordPermissionEnumerator enumerator = new(this.data); - foreach (DiscordPermission permission in EnumeratePermissions()) + for (int i = 0; i < pop; i++) { - _ = builder.Append(permission.ToStringFast()); - _ = builder.Append(", "); + _ = enumerator.MoveNext(); + names[i] = enumerator.Current.ToStringFast(); } - return builder.ToString().TrimEnd(", "); + return string.Join(", ", names); } else { diff --git a/src/core/DSharpPlus.Shared/ImageData.cs b/src/core/DSharpPlus.Shared/InlineMediaData.cs similarity index 82% rename from src/core/DSharpPlus.Shared/ImageData.cs rename to src/core/DSharpPlus.Shared/InlineMediaData.cs index fdef065941..38ab1b6410 100644 --- a/src/core/DSharpPlus.Shared/ImageData.cs +++ b/src/core/DSharpPlus.Shared/InlineMediaData.cs @@ -18,23 +18,25 @@ namespace DSharpPlus; /// /// Represents an image sent to Discord as part of JSON payloads. /// -public readonly record struct ImageData +public readonly record struct InlineMediaData { private static ReadOnlySpan PngString => "data:image/png;base64,"u8; private static ReadOnlySpan JpegString => "data:image/jpeg;base64,"u8; private static ReadOnlySpan GifString => "data:image/gif;base64,"u8; private static ReadOnlySpan WebpString => "data:image/webp;base64,"u8; + private static ReadOnlySpan OggString => "data:audio/ogg;base64,"u8; + private static ReadOnlySpan Mp3String => "data:audio/mpeg;base64,"u8; private static ReadOnlySpan AutoString => "data:image/auto;base64,"u8; private readonly Stream reader; - private readonly ImageFormat format; + private readonly MediaFormat format; /// /// Creates a new instance of this struct from the provided stream. /// /// The Stream to convert to base64. /// The format of this image. - public ImageData(Stream reader, ImageFormat format) + public InlineMediaData(Stream reader, MediaFormat format) { this.reader = reader; this.format = format; @@ -45,7 +47,7 @@ public ImageData(Stream reader, ImageFormat format) /// /// The pipe to conver to base64. /// The format of this image. - public ImageData(PipeReader reader, ImageFormat format) : this(reader.AsStream(), format) + public InlineMediaData(PipeReader reader, MediaFormat format) : this(reader.AsStream(), format) { } @@ -55,7 +57,7 @@ public ImageData(PipeReader reader, ImageFormat format) : this(reader.AsStream() /// /// The buffer to convert to base64. /// The format of this image. - public ImageData(ReadOnlySequence data, ImageFormat format) : this(PipeReader.Create(data), format) + public InlineMediaData(ReadOnlySequence data, MediaFormat format) : this(PipeReader.Create(data), format) { } @@ -73,10 +75,12 @@ public readonly void WriteTo(ArrayPoolBufferWriter writer) ( this.format switch { - ImageFormat.Png => PngString, - ImageFormat.Gif => GifString, - ImageFormat.Jpeg => JpegString, - ImageFormat.WebP => WebpString, + MediaFormat.Png => PngString, + MediaFormat.Gif => GifString, + MediaFormat.Jpeg => JpegString, + MediaFormat.WebP => WebpString, + MediaFormat.Ogg => OggString, + MediaFormat.Mp3 => Mp3String, _ => AutoString } ); diff --git a/src/core/DSharpPlus.Shared/ImageFormat.cs b/src/core/DSharpPlus.Shared/MediaFormat.cs similarity index 72% rename from src/core/DSharpPlus.Shared/ImageFormat.cs rename to src/core/DSharpPlus.Shared/MediaFormat.cs index 437fb5f9d7..731ae06e6f 100644 --- a/src/core/DSharpPlus.Shared/ImageFormat.cs +++ b/src/core/DSharpPlus.Shared/MediaFormat.cs @@ -5,14 +5,16 @@ namespace DSharpPlus; /// -/// Represents formats recognized and handled by . +/// Represents formats recognized and handled by . /// -public enum ImageFormat +public enum MediaFormat { Png, Gif, Jpeg, WebP, + Ogg, + Mp3, Auto, Unknown, } diff --git a/src/core/DSharpPlus.Shared/Optional`1.cs b/src/core/DSharpPlus.Shared/Optional`1.cs index dcacbbda0a..452bda8a18 100644 --- a/src/core/DSharpPlus.Shared/Optional`1.cs +++ b/src/core/DSharpPlus.Shared/Optional`1.cs @@ -111,8 +111,9 @@ out T value [MemberNotNullWhen(true, nameof(value))] public readonly bool TryGetNonNullValue ( + [MaybeNullWhen(false)] [NotNullWhen(true)] - out T? value + out T value ) { value = this.value; diff --git a/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Builders/Interactions/ModalBuilder.cs b/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Builders/Interactions/ModalBuilder.cs index 1731f9515a..f96af4308f 100644 --- a/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Builders/Interactions/ModalBuilder.cs +++ b/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Builders/Interactions/ModalBuilder.cs @@ -104,7 +104,7 @@ public static Result Validate(ref this ModalBuilder builder) return new BuilderValidationError ( "Some modal fields were invalid. See the attached dictionary for further information.", - errors.ToArray() + [.. errors] ); } else diff --git a/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Builders/Interactions/TextInputComponentBuilder.cs b/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Builders/Interactions/TextInputComponentBuilder.cs index 0f5633dfbf..6c9a5ac0df 100644 --- a/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Builders/Interactions/TextInputComponentBuilder.cs +++ b/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Builders/Interactions/TextInputComponentBuilder.cs @@ -9,8 +9,8 @@ using System.Diagnostics.CodeAnalysis; using DSharpPlus.Entities; -using DSharpPlus.Extensions.Internal.Builders.Errors; -using DSharpPlus.Extensions.Internal.Builders.Implementations; +using DSharpPlus.Extensions.Internal.Toolbox.Errors; +using DSharpPlus.Extensions.Internal.Toolbox.Implementations; using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Results; @@ -215,7 +215,7 @@ public static Result Validate(ref this TextInputComponentBuilder builder) return new BuilderValidationError ( "Some component fields were invalid. See the attached dictionary for further information.", - errors.ToArray() + [.. errors] ); } else diff --git a/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Builders/Messages/EmbedBuilder.cs b/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Builders/Messages/EmbedBuilder.cs index 92a197daf5..3020bfca56 100644 --- a/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Builders/Messages/EmbedBuilder.cs +++ b/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Builders/Messages/EmbedBuilder.cs @@ -226,7 +226,7 @@ public static Result Validate(ref this EmbedBuilder builder) return new BuilderValidationError ( "The total length of the embed exceeded 6000 characters, and some embed fields were invalid.", - errors.ToArray() + [.. errors] ); } else if (totalCount > 6000) @@ -238,7 +238,7 @@ public static Result Validate(ref this EmbedBuilder builder) return new BuilderValidationError ( "Some embed fields were invalid. See the attached dictionary for further information.", - errors.ToArray() + [.. errors] ); } else diff --git a/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/DSharpPlus.Extensions.Internal.Toolbox.csproj b/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/DSharpPlus.Extensions.Internal.Toolbox.csproj index 4ceab133be..6c6a23aa23 100644 --- a/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/DSharpPlus.Extensions.Internal.Toolbox.csproj +++ b/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/DSharpPlus.Extensions.Internal.Toolbox.csproj @@ -1,7 +1,6 @@  - net9.0 enable $(_DSharpPlusExtensionsInternalToolboxVersion) diff --git a/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Implementations/BuiltEditInteractionResponsePayload.cs b/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Implementations/BuiltEditInteractionResponsePayload.cs index 96460ba076..cd2aba2c9e 100644 --- a/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Implementations/BuiltEditInteractionResponsePayload.cs +++ b/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Implementations/BuiltEditInteractionResponsePayload.cs @@ -29,4 +29,7 @@ internal sealed record BuiltEditInteractionResponsePayload : IEditInteractionRes /// public IReadOnlyList? Files { get; init; } -} \ No newline at end of file + + /// + public Optional Poll { get; init; } +} diff --git a/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/PollResultMessage.cs b/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/PollResultMessage.cs index c80aa59fde..f8007c5e27 100644 --- a/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/PollResultMessage.cs +++ b/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/PollResultMessage.cs @@ -135,7 +135,6 @@ public static bool TryDeconstructPollResult(IPartialMessage message, out PollRes case "victor_answer_emoji_animated": - if (!bool.TryParse(field.Value, out bool isAnimated)) { result = default; diff --git a/tests/core/DSharpPlus.Internal.Models.Tests/DSharpPlus.Internal.Models.Tests.csproj b/tests/core/DSharpPlus.Internal.Models.Tests/DSharpPlus.Internal.Models.Tests.csproj index e8e13b5700..66d43ac0ab 100644 --- a/tests/core/DSharpPlus.Internal.Models.Tests/DSharpPlus.Internal.Models.Tests.csproj +++ b/tests/core/DSharpPlus.Internal.Models.Tests/DSharpPlus.Internal.Models.Tests.csproj @@ -1,7 +1,7 @@ - net9.0 + net10.0 enable false diff --git a/tests/core/DSharpPlus.Shared.Tests/DSharpPlus.Shared.Tests.csproj b/tests/core/DSharpPlus.Shared.Tests/DSharpPlus.Shared.Tests.csproj index d3c1b9fec8..861090c4a9 100644 --- a/tests/core/DSharpPlus.Shared.Tests/DSharpPlus.Shared.Tests.csproj +++ b/tests/core/DSharpPlus.Shared.Tests/DSharpPlus.Shared.Tests.csproj @@ -1,7 +1,7 @@  - net9.0 + net10.0 enable true diff --git a/tests/core/DSharpPlus.Shared.Tests/TextWriters/IndentedArrayPoolUtf16.cs b/tests/core/DSharpPlus.Shared.Tests/TextWriters/IndentedArrayPoolUtf16.cs index d86f74155b..92b49a7d11 100644 --- a/tests/core/DSharpPlus.Shared.Tests/TextWriters/IndentedArrayPoolUtf16.cs +++ b/tests/core/DSharpPlus.Shared.Tests/TextWriters/IndentedArrayPoolUtf16.cs @@ -28,7 +28,7 @@ public void TestIndentationIncrementDecrement() } """, - writer.ToString().Trim(" \r\n") + writer.ToString().Trim(' ', '\r', 'n') ); } @@ -51,7 +51,7 @@ public void TestIndentingWrite() 1 } """, - writer.ToString().Trim(" \r\n") + writer.ToString().Trim(' ', '\r', 'n') ); } @@ -74,7 +74,7 @@ public void TestLiteralPreservingWrite() 1 } """, - writer.ToString().Trim(" \r\n") + writer.ToString().Trim(' ', '\r', 'n') ); } } From 2b0ce02520289e330bb1624c2f51329fceb77a4c Mon Sep 17 00:00:00 2001 From: Livia-Valeriya Silvercrown Date: Sun, 18 May 2025 22:47:21 +0200 Subject: [PATCH 320/323] update permissions, use TUnit, other assorted stuff --- DSharpPlus.slnx | 47 +++---- Directory.Build.props | 119 ++++++++--------- Directory.Packages.props | 45 +++---- LICENSE-MIT | 32 +++-- Solution.Build.Targets | 10 ++ ...harpPlus.Internal.Abstractions.Rest.csproj | 4 - .../DSharpPlus.Shared.csproj | 1 - .../DiscordPermissions.Arithmetics.cs | 68 ++++++++-- .../DiscordPermissions.Enumeration.cs | 28 ++-- .../Entities/DiscordPermissions.Utility.cs | 24 ++-- .../Entities/DiscordPermissions.cs | 120 ++++++++++-------- ...xtensions.Internal.BadRequestHelper.csproj | 13 ++ .../ResultExtensions.cs | 46 +++++++ src/extensions/DSharpPlus.Extensions.sln | 6 + .../ApplicationIntegrationTypeKeyTests.cs | 27 ++-- .../Converters/AuditLogChangeTests.cs | 55 ++++---- .../Converters/ComponentTests.cs | 29 +++-- .../Converters/DiscordPermissionTests.cs | 9 +- .../Converters/OneOfConverterTests.Models.cs | 15 +-- .../OneOfConverterTests.Precedence.cs | 27 ++-- .../DSharpPlus.Internal.Models.Tests.csproj | 13 +- .../DSharpPlus.Shared.Tests.csproj | 10 +- .../Permissions/BoundTests.cs | 9 +- .../Permissions/ConstructionTests.cs | 70 +++++----- .../Permissions/EqualityTests.cs | 28 ++-- .../Permissions/OperatorTests.cs | 89 ++++++++----- .../Permissions/ToStringTests.cs | 97 ++++++++++---- .../Permissions/UtilityTests.cs | 49 ++++--- .../TextWriters/IndentedArrayPoolUtf16.cs | 31 ++--- .../Util/FactExceptOnlyOnWindowsAttribute.cs | 20 --- 30 files changed, 659 insertions(+), 482 deletions(-) create mode 100644 Solution.Build.Targets create mode 100644 src/extensions/DSharpPlus.Extensions.Internal.BadRequestHelper/DSharpPlus.Extensions.Internal.BadRequestHelper.csproj create mode 100644 src/extensions/DSharpPlus.Extensions.Internal.BadRequestHelper/ResultExtensions.cs delete mode 100644 tests/core/DSharpPlus.Shared.Tests/Util/FactExceptOnlyOnWindowsAttribute.cs diff --git a/DSharpPlus.slnx b/DSharpPlus.slnx index b339300190..a0a7cf53e3 100644 --- a/DSharpPlus.slnx +++ b/DSharpPlus.slnx @@ -1,23 +1,24 @@ - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Directory.Build.props b/Directory.Build.props index 6e8326d6a5..3865007bd9 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,60 +1,61 @@ - - - - - net10.0 - enable - disable - preview - True - True - All - $(NoWarn);CS1591;CA1028;CA1062;CA1308;CA1711;CA1716;CA1720;CA2007;CA2225;IDE0130 - - - True - true - true - - - - - - Naamloos, afroraydude, DrCreo, Death, TiaqoY0, Axiom, Emzi0767, IDoEverything, Velvet, OoLunar, akiraveliara, DSharpPlus contributors - - A C# API for Discord based off DiscordSharp. - DSharpPlus Contributors - https://github.com/DSharpPlus/DSharpPlus - https://github.com/DSharpPlus/DSharpPlus - Git - MPL - dsharpplus.png - https://raw.githubusercontent.com/DSharpPlus/DSharpPlus/master/logo/dsharpplus.png - - - - - - - - <_DSharpPlusReleaseVersion>6.0.0 - - - <_DSharpPlusInternalAbstractionsModelsVersion>0.1.0 - - - <_DSharpPlusInternalModelsVersion>0.1.0 - - - <_DSharpPlusInternalAbstractionsRestVersion>0.1.0 - - - <_DSharpPlusInternalRestVersion>0.1.0 - - - - - <_DSharpPlusExtensionsInternalToolboxVersion>0.1.0 - - + + + + + net10.0 + enable + disable + preview + True + True + All + $(NoWarn);CS1591;CA1028;CA1062;CA1308;CA1711;CA1716;CA1720;CA2007;CA2225;IDE0130 + + + True + true + true + + + + + DSharpPlus + A C# API for Discord based off DiscordSharp. + DSharpPlus Contributors + https://github.com/DSharpPlus/DSharpPlus + https://github.com/DSharpPlus/DSharpPlus + Git + MPL + dsharpplus.png + https://raw.githubusercontent.com/DSharpPlus/DSharpPlus/master/logo/dsharpplus.png + + + + + + + + <_DSharpPlusReleaseVersion>6.0.0 + + + <_DSharpPlusInternalAbstractionsModelsVersion>0.1.0 + + + <_DSharpPlusInternalModelsVersion>0.1.0 + + + <_DSharpPlusInternalAbstractionsRestVersion>0.1.0 + + + <_DSharpPlusInternalRestVersion>0.1.0 + + + + + <_DSharpPlusExtensionsInternalToolboxVersion>0.1.0 + + + <_DSharpPlusExtensionsInternalBadRequestHelperVersion>0.1.0 + + \ No newline at end of file diff --git a/Directory.Packages.props b/Directory.Packages.props index 8802b7d6f3..933f18ec48 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -1,25 +1,22 @@ - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/LICENSE-MIT b/LICENSE-MIT index 27b55660c0..2f0a224ca8 100644 --- a/LICENSE-MIT +++ b/LICENSE-MIT @@ -1,9 +1,23 @@ -Copyright (c) 2015 Mike Santiago -Copyright (c) 2016-2023 DSharpPlus Development Team (v1-v5) -Copyright (c) 2023- DSharpPlus Development Team (v6+, only contributions by the specified contributors: ./readme.md#licensing) - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +The MIT License (MIT) + +Copyright (c) 2015 Mike Santiago +Copyright (c) 2016-2025 DSharpPlus Development Team (v1-v5) +Copyright (c) 2023-2025 DSharpPlus Development Team (v6+, selected contributors: ./readme.md#licensing) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/Solution.Build.Targets b/Solution.Build.Targets new file mode 100644 index 0000000000..5f319aa2f5 --- /dev/null +++ b/Solution.Build.Targets @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/DSharpPlus.Internal.Abstractions.Rest.csproj b/src/core/DSharpPlus.Internal.Abstractions.Rest/DSharpPlus.Internal.Abstractions.Rest.csproj index e0b8624597..30e6b8165c 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/DSharpPlus.Internal.Abstractions.Rest.csproj +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/DSharpPlus.Internal.Abstractions.Rest.csproj @@ -4,10 +4,6 @@ $(_DSharpPlusInternalAbstractionsRestVersion) - - - - diff --git a/src/core/DSharpPlus.Shared/DSharpPlus.Shared.csproj b/src/core/DSharpPlus.Shared/DSharpPlus.Shared.csproj index 362c701119..c834d118ba 100644 --- a/src/core/DSharpPlus.Shared/DSharpPlus.Shared.csproj +++ b/src/core/DSharpPlus.Shared/DSharpPlus.Shared.csproj @@ -15,7 +15,6 @@ - diff --git a/src/core/DSharpPlus.Shared/Entities/DiscordPermissions.Arithmetics.cs b/src/core/DSharpPlus.Shared/Entities/DiscordPermissions.Arithmetics.cs index 8a718e238f..d132fa0db1 100644 --- a/src/core/DSharpPlus.Shared/Entities/DiscordPermissions.Arithmetics.cs +++ b/src/core/DSharpPlus.Shared/Entities/DiscordPermissions.Arithmetics.cs @@ -2,6 +2,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +#pragma warning disable SYSLIB5001 + using System; using System.Runtime.Intrinsics; @@ -19,42 +21,57 @@ partial struct DiscordPermissions /// /// The permission field to add. /// A new permission set containing all previous permissions along with the new permission. - public DiscordPermissions Add(DiscordPermission permission) - => new(this.AsSpan, [permission], []); + public void Add(DiscordPermission permission) + => Add([permission]); /// /// Adds multiple permissions to this permission set. /// /// The permission fields to add. /// A new permission set containing all previous permissions along with the new permissions. - public DiscordPermissions Add(params ReadOnlySpan permissions) - => new(this.AsSpan, permissions, []); + public void Add(params ReadOnlySpan permissions) + { + foreach (DiscordPermission permission in permissions) + { + this.data.SetFlag((int)permission, true); + } + } /// /// Adds the specified permission to the permission set. /// - public static DiscordPermissions operator +(DiscordPermissions value, DiscordPermission add) => value.Add(add); + public static DiscordPermissions operator +(DiscordPermissions value, DiscordPermission add) + => value | add; + + public static DiscordPermissions operator +(DiscordPermissions value, DiscordPermissions add) + => value | add; /// /// Removes a permission from this permission set. /// /// The permission field to remove. /// A new permission set containing all previous permissions except the specified permission. - public DiscordPermissions Remove(DiscordPermission permission) - => new(this.AsSpan, [], [permission]); + public void Remove(DiscordPermission permission) + => Remove([permission]); /// /// Removes multiple permission from this permission set. /// /// The permission fields to remove. /// A new permission set containing all previous permissions except the specified permissions. - public DiscordPermissions Remove(params ReadOnlySpan permissions) - => new(this.AsSpan, [], permissions); + public void Remove(params ReadOnlySpan permissions) + { + foreach (DiscordPermission permission in permissions) + { + this.data.SetFlag((int)permission, false); + } + } /// /// Removes the specified permission from a permission set. /// - public static DiscordPermissions operator -(DiscordPermissions value, DiscordPermission remove) => value.Remove(remove); + public static DiscordPermissions operator -(DiscordPermissions value, DiscordPermission remove) + => value - [remove]; /// /// Removes all permissions specified in the right-hand set from the left-hand set and returns the new permission set. @@ -83,7 +100,8 @@ public DiscordPermissions Remove(params ReadOnlySpan permissi /// /// Adds the specified permission to the permission set. /// - public static DiscordPermissions operator |(DiscordPermissions value, DiscordPermission flag) => value.Add(flag); + public static DiscordPermissions operator |(DiscordPermissions value, DiscordPermission flag) + => value | [flag]; /// /// Merges both permission sets into one, taking all set permissions from both. @@ -193,4 +211,32 @@ public DiscordPermissions Remove(params ReadOnlySpan permissi return new(result); } + + /// + /// Adds the provided permission sets together. + /// + /// + /// This is semantically equivalent to repeatedly calling Add, just, faster. + /// + public static DiscordPermissions Combine(params ReadOnlySpan permissions) + { + Span result = stackalloc byte[ContainerByteCount]; + + for (int i = 0; i < ContainerByteCount; i += 16) + { + Vector128 v1 = Vector128.Zero; + + foreach (DiscordPermissions set in permissions) + { + ReadOnlySpan other = set.AsSpan; + Vector128 v2 = Vector128.LoadUnsafe(in other[i]); + + v1 = Vector128.BitwiseOr(v1, v2); + } + + v1.StoreUnsafe(ref result[i]); + } + + return new(result); + } } diff --git a/src/core/DSharpPlus.Shared/Entities/DiscordPermissions.Enumeration.cs b/src/core/DSharpPlus.Shared/Entities/DiscordPermissions.Enumeration.cs index 936232222c..427ec954e3 100644 --- a/src/core/DSharpPlus.Shared/Entities/DiscordPermissions.Enumeration.cs +++ b/src/core/DSharpPlus.Shared/Entities/DiscordPermissions.Enumeration.cs @@ -8,7 +8,7 @@ using System.Collections; using System.Collections.Generic; using System.Numerics; - +using System.Runtime.CompilerServices; using CommunityToolkit.HighPerformance.Helpers; namespace DSharpPlus.Entities; @@ -16,32 +16,22 @@ namespace DSharpPlus.Entities; // contains the implementation details for EnumeratePermissions partial struct DiscordPermissions { + /// - /// Presents a slim enumerable wrapper around a set of permissions. + /// Gets an enumerator for the present permission set. /// - public readonly struct DiscordPermissionEnumerable : IEnumerable - { - private readonly DiscordPermissionContainer data; + public readonly DiscordPermissionEnumerator GetEnumerator() => new(this.data); - internal DiscordPermissionEnumerable(DiscordPermissionContainer data) - => this.data = data; - - /// - /// Gets an enumerator for the present permission set. - /// - public readonly DiscordPermissionEnumerator GetEnumerator() => new(this.data); - - // implementations for IEnumerable, we'd like to not box by default - IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator(); - IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator(); - } + // implementations for IEnumerable, we'd like to not box by default + readonly IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator(); + readonly IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator(); /// /// Represents an enumerator for permission fields within a permission set. /// public struct DiscordPermissionEnumerator : IEnumerator { - private readonly DiscordPermissionContainer data; + private DiscordPermissionContainer data; internal DiscordPermissionEnumerator(DiscordPermissionContainer data) => this.data = data; @@ -59,7 +49,7 @@ public bool MoveNext() for (; this.block < ContainerElementCount; this.block++) { this.bit++; - uint value = this.data[this.block]; + uint value = Unsafe.Add(ref Unsafe.As(ref this.data), this.block); if (value == 0) { diff --git a/src/core/DSharpPlus.Shared/Entities/DiscordPermissions.Utility.cs b/src/core/DSharpPlus.Shared/Entities/DiscordPermissions.Utility.cs index 139cba0b1c..a5fb174beb 100644 --- a/src/core/DSharpPlus.Shared/Entities/DiscordPermissions.Utility.cs +++ b/src/core/DSharpPlus.Shared/Entities/DiscordPermissions.Utility.cs @@ -11,19 +11,19 @@ partial struct DiscordPermissions /// /// Toggles the specified permission between states. /// - public DiscordPermissions Toggle(DiscordPermission permission) + public readonly DiscordPermissions Toggle(DiscordPermission permission) => this ^ permission; /// /// Toggles all of the specified permissions between states. /// - public DiscordPermissions Toggle(params ReadOnlySpan permissions) + public readonly DiscordPermissions Toggle(params ReadOnlySpan permissions) => this ^ new DiscordPermissions(permissions); /// /// Returns whether the specified permission is set explicitly. /// - public bool HasFlag(DiscordPermission flag) + public readonly bool HasFlag(DiscordPermission flag) => GetFlag((int)flag); /// @@ -35,20 +35,12 @@ public bool HasPermission(DiscordPermission permission) /// /// Returns whether any of the specified permissions are granted, either directly or through Administrator permissions. /// - public bool HasAnyPermission(params ReadOnlySpan permissions) - => this.HasFlag(DiscordPermission.Administrator) || (this & new DiscordPermissions(permissions)) != None; + public bool HasAnyPermission(DiscordPermissions permissions) + => this.HasFlag(DiscordPermission.Administrator) || (this & permissions) != None; /// - /// Returns whether all of the specified permissions are gratned, either directly or through Administrator permissions. + /// Returns whether all of the specified permissions are granted, either directly or through Administrator permissions. /// - public bool HasAllPermissions(params ReadOnlySpan permissions) - { - if (this.HasFlag(DiscordPermission.Administrator)) - { - return true; - } - - DiscordPermissions expected = new(permissions); - return (this & expected) == expected; - } + public bool HasAllPermissions(DiscordPermissions expected) + => this.HasFlag(DiscordPermission.Administrator) || (this & expected) == expected; } diff --git a/src/core/DSharpPlus.Shared/Entities/DiscordPermissions.cs b/src/core/DSharpPlus.Shared/Entities/DiscordPermissions.cs index 2d09528dcc..81f8a06f55 100644 --- a/src/core/DSharpPlus.Shared/Entities/DiscordPermissions.cs +++ b/src/core/DSharpPlus.Shared/Entities/DiscordPermissions.cs @@ -2,6 +2,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +#pragma warning disable SYSLIB5001 + using System; using System.Buffers.Binary; using System.Collections.Generic; @@ -26,8 +28,9 @@ namespace DSharpPlus.Entities; /// /// This type expects to be zero-initialized. Using this type in [SkipLocalsInit] contexts may be dangerous. /// -public readonly partial struct DiscordPermissions - : IEquatable +[DebuggerDisplay("{ToString(\"name\")}")] +public partial struct DiscordPermissions + : IEquatable, IEnumerable { // only change ContainerWidth here, the other two constants are automatically updated for internal uses // for ContainerWidth, 1 width == 128 bits. @@ -35,6 +38,9 @@ public readonly partial struct DiscordPermissions private const int ContainerElementCount = ContainerWidth * 4; private const int ContainerByteCount = ContainerWidth * 16; + private static readonly string[] permissionNames = CreatePermissionNameArray(); + private static readonly int highestDefinedValue = (int)DiscordPermissionExtensions.GetValues()[^1]; + private readonly DiscordPermissionContainer data; /// @@ -99,28 +105,6 @@ public DiscordPermissions(scoped ReadOnlySpan raw) } } - /// - /// A copy constructor that sets an arbitrary amount of flags to their respective values. - /// - private DiscordPermissions - ( - scoped ReadOnlySpan raw, - ReadOnlySpan setPermissions, - ReadOnlySpan removePermissions - ) - : this(raw) - { - foreach (DiscordPermission permission in setPermissions) - { - this.data.SetFlag((int)permission, true); - } - - foreach (DiscordPermission permission in removePermissions) - { - this.data.SetFlag((int)permission, false); - } - } - /// /// A copy constructor that sets one specific flag to the specified value. /// @@ -161,41 +145,28 @@ public static DiscordPermissions AllBitsSet public static DiscordPermissions All { get; } = new(DiscordPermissionExtensions.GetValues()); [UnscopedRef] - private ReadOnlySpan AsSpan - => MemoryMarshal.Cast((ReadOnlySpan)this.data); + private readonly ReadOnlySpan AsSpan + => MemoryMarshal.Cast(this.data); - private bool GetFlag(int index) + private readonly bool GetFlag(int index) => this.data.HasFlag(index); /// /// Determines whether this Discord permission set is equal to the provided object. /// - public override bool Equals([NotNullWhen(true)] object? obj) + public override readonly bool Equals([NotNullWhen(true)] object? obj) => obj is DiscordPermissions permissions && this.Equals(permissions); /// /// Determines whether this Discord permission set is equal to the provided Discord permission set. /// - public bool Equals(DiscordPermissions other) - { - for (int i = 0; i < ContainerElementCount; i += 4) - { - Vector128 current = Vector128.LoadUnsafe(in this.data[i]); - Vector128 comparison = Vector128.LoadUnsafe(in other.data[i]); - - if (current != comparison) - { - return false; - } - } - - return true; - } + public readonly bool Equals(DiscordPermissions other) + => ((ReadOnlySpan)this.data).SequenceEqual(other.data); /// /// Returns a string representation of this permission set. /// - public override string ToString() => this.ToString("a placeholder format string that doesn't do anything"); + public override readonly string ToString() => this.ToString("a placeholder format string that doesn't do anything"); /// /// Returns a string representation of this permission set, according to the provided format string. @@ -204,9 +175,10 @@ public bool Equals(DiscordPermissions other) /// Specifies the format in which the string should be created. Currently supported formats are:
/// - raw: This prints the raw, byte-wise backing data of this instance.
/// - name: This prints each flag by name, separated by commas.
+ /// - name:format: This prints each flag by name according to the specified format. The string {permission} must be contained to mark the position of the flag.
/// - anything else will print the integer value contained in this instance. /// - public string ToString(string format) + public readonly string ToString(string format) { if (format == "raw") { @@ -232,17 +204,44 @@ public string ToString(string format) pop += BitOperations.PopCount(this.data[i + 3]); } - string[] names = new string[pop]; + if (pop == 0) + { + return "None"; + } + + Span names = new string[pop]; DiscordPermissionEnumerator enumerator = new(this.data); for (int i = 0; i < pop; i++) { _ = enumerator.MoveNext(); - names[i] = enumerator.Current.ToStringFast(); + int flag = (int)enumerator.Current; + names[i] = flag <= highestDefinedValue ? permissionNames[flag] : flag.ToString(CultureInfo.InvariantCulture); } return string.Join(", ", names); } + else if (format.StartsWith("name:")) + { + string trimmedFormat = format[5..]; + + if (string.IsNullOrWhiteSpace(trimmedFormat) || !trimmedFormat.Contains("{permission}")) + { + ThrowFormatException(format); + } + + StringBuilder builder = new(); + + foreach (DiscordPermission permission in this) + { + int flag = (int)permission; + string permissionName = flag <= highestDefinedValue ? permissionNames[flag] : flag.ToString(CultureInfo.InvariantCulture); + + _ = builder.Append(trimmedFormat.Replace("{permission}", permissionName)); + } + + return builder.ToString(); + } else { Span buffer = stackalloc byte[ContainerElementCount * 4]; @@ -262,18 +261,31 @@ public string ToString(string format) /// Calculates a hash code for this Discord permission set. The hash code is only guaranteed to be consistent /// within a process, and sharing this data across process boundaries is dangerous. ///
- public override int GetHashCode() + public override readonly int GetHashCode() => HashCode.Combine(this.data); - /// - /// Provides an enumeration of all permissions specified by this set. - /// - public DiscordPermissionEnumerable EnumeratePermissions() - => new(this.data); - public static bool operator ==(DiscordPermissions left, DiscordPermissions right) => left.Equals(right); public static bool operator !=(DiscordPermissions left, DiscordPermissions right) => !(left == right); + private static string[] CreatePermissionNameArray() + { + int highest = (int)DiscordPermissionExtensions.GetValues()[^1]; + string[] names = new string[highest + 1]; + + for (int i = 0; i <= highest; i++) + { + names[i] = ((DiscordPermission)i).ToStringFast(true); + } + + return names; + } + + [DoesNotReturn] + [DebuggerHidden] + [StackTraceHidden] + private static void ThrowFormatException(string format) + => throw new FormatException($"The format string \"{format}\" was empty or malformed: it must contain an instruction to print a permission."); + // we will be using an inline array from the start here so that further increases in the bit width // only require increasing this number instead of switching to a new backing implementation strategy. // if Discord changes the way permissions are represented in the API, this will obviously have to change. diff --git a/src/extensions/DSharpPlus.Extensions.Internal.BadRequestHelper/DSharpPlus.Extensions.Internal.BadRequestHelper.csproj b/src/extensions/DSharpPlus.Extensions.Internal.BadRequestHelper/DSharpPlus.Extensions.Internal.BadRequestHelper.csproj new file mode 100644 index 0000000000..d3b5ef2909 --- /dev/null +++ b/src/extensions/DSharpPlus.Extensions.Internal.BadRequestHelper/DSharpPlus.Extensions.Internal.BadRequestHelper.csproj @@ -0,0 +1,13 @@ + + + + $(_DSharpPlusExtensionsInternalBadRequestHelperVersion) + enable + + + + + + + + diff --git a/src/extensions/DSharpPlus.Extensions.Internal.BadRequestHelper/ResultExtensions.cs b/src/extensions/DSharpPlus.Extensions.Internal.BadRequestHelper/ResultExtensions.cs new file mode 100644 index 0000000000..657aeae6cb --- /dev/null +++ b/src/extensions/DSharpPlus.Extensions.Internal.BadRequestHelper/ResultExtensions.cs @@ -0,0 +1,46 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +#pragma warning disable CA1031 + +using System.Net; +using System.Text.Json; + +using DSharpPlus.Internal.Abstractions.Rest.Errors; +using DSharpPlus.Results; + +namespace DSharpPlus.Extensions.Internal.BadRequestHelper; + +public static class ResultExtensions +{ + public static Result ExpandBadRequestError(this Result result, object payload) + { + return result.MapError + ( + error => + { + if (error is not HttpError { StatusCode: HttpStatusCode.BadRequest }) + { + return error; + } + + try + { + using JsonDocument document = JsonDocument.Parse(error.Message); + + if (document.RootElement.TryGetProperty("errors", out JsonElement errors)) + { + return error; //placeholder + } + } + catch + { + return error; + } + + return error; //placeholder + } + ); + } +} diff --git a/src/extensions/DSharpPlus.Extensions.sln b/src/extensions/DSharpPlus.Extensions.sln index e8b5bb657f..cf259e04db 100644 --- a/src/extensions/DSharpPlus.Extensions.sln +++ b/src/extensions/DSharpPlus.Extensions.sln @@ -5,6 +5,8 @@ VisualStudioVersion = 17.0.31903.59 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DSharpPlus.Extensions.Internal.Toolbox", "DSharpPlus.Extensions.Internal.Toolbox\DSharpPlus.Extensions.Internal.Toolbox.csproj", "{40CC040B-F757-42AA-8BC8-44F6EA6DCE7E}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DSharpPlus.Extensions.Internal.BadRequestHelper", "DSharpPlus.Extensions.Internal.BadRequestHelper\DSharpPlus.Extensions.Internal.BadRequestHelper.csproj", "{F513621F-3E05-4028-96EF-D62F63736614}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -18,5 +20,9 @@ Global {40CC040B-F757-42AA-8BC8-44F6EA6DCE7E}.Debug|Any CPU.Build.0 = Debug|Any CPU {40CC040B-F757-42AA-8BC8-44F6EA6DCE7E}.Release|Any CPU.ActiveCfg = Release|Any CPU {40CC040B-F757-42AA-8BC8-44F6EA6DCE7E}.Release|Any CPU.Build.0 = Release|Any CPU + {F513621F-3E05-4028-96EF-D62F63736614}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F513621F-3E05-4028-96EF-D62F63736614}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F513621F-3E05-4028-96EF-D62F63736614}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F513621F-3E05-4028-96EF-D62F63736614}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection EndGlobal diff --git a/tests/core/DSharpPlus.Internal.Models.Tests/Converters/ApplicationIntegrationTypeKeyTests.cs b/tests/core/DSharpPlus.Internal.Models.Tests/Converters/ApplicationIntegrationTypeKeyTests.cs index fe1a3f8892..9f9dc7ce3a 100644 --- a/tests/core/DSharpPlus.Internal.Models.Tests/Converters/ApplicationIntegrationTypeKeyTests.cs +++ b/tests/core/DSharpPlus.Internal.Models.Tests/Converters/ApplicationIntegrationTypeKeyTests.cs @@ -5,12 +5,11 @@ using System; using System.Collections.Generic; using System.Text.Json; +using System.Threading.Tasks; using DSharpPlus.Entities; using DSharpPlus.Internal.Models.Serialization.Converters; -using Xunit; - namespace DSharpPlus.Internal.Models.Tests.Converters; public class ApplicationIntegrationTypeKeyTests @@ -47,18 +46,22 @@ public ApplicationIntegrationTypeKeyTests() this.options.Converters.Add(new ApplicationIntegrationTypeKeyConverter()); } - [Fact] - public void TestSuccess() + [Test] + public async Task TestSuccess() { Dictionary value = JsonSerializer.Deserialize>(ValidPayload, this.options)!; - Assert.Equal(2, value.Count); - Assert.Equal(28, value[DiscordApplicationIntegrationType.UserInstall]); + using (Assert.Multiple()) + { + + await Assert.That(value.Count).IsEqualTo(2); + await Assert.That(value[DiscordApplicationIntegrationType.UserInstall]).IsEqualTo(28); + } } - [Fact] - public void TestFloatFailure() + [Test] + public async Task TestFloatFailure() { try { @@ -67,7 +70,7 @@ public void TestFloatFailure() } catch (JsonException exception) { - Assert.Equal("Expected an integer key.", exception.Message); + await Assert.That(exception.Message).IsEqualTo("Expected an integer key."); } catch { @@ -76,8 +79,8 @@ public void TestFloatFailure() } } - [Fact] - public void TestStringFailure() + [Test] + public async Task TestStringFailure() { try { @@ -86,7 +89,7 @@ public void TestStringFailure() } catch (JsonException exception) { - Assert.Equal("Expected an integer key.", exception.Message); + await Assert.That(exception.Message).IsEqualTo("Expected an integer key."); } catch { diff --git a/tests/core/DSharpPlus.Internal.Models.Tests/Converters/AuditLogChangeTests.cs b/tests/core/DSharpPlus.Internal.Models.Tests/Converters/AuditLogChangeTests.cs index 6e04e2b7ec..52b8db1474 100644 --- a/tests/core/DSharpPlus.Internal.Models.Tests/Converters/AuditLogChangeTests.cs +++ b/tests/core/DSharpPlus.Internal.Models.Tests/Converters/AuditLogChangeTests.cs @@ -5,6 +5,7 @@ #pragma warning disable IDE0058 using System; +using System.Threading.Tasks; using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Internal.Models.Extensions; @@ -14,8 +15,6 @@ using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; -using Xunit; - namespace DSharpPlus.Internal.Models.Tests.Converters; public class AuditLogChangeTests @@ -77,47 +76,59 @@ public AuditLogChangeTests() } """u8.ToArray(); - [Fact] - public void TestIntegerPayload() + [Test] + public async Task TestIntegerPayload() { IAuditLogChange change = this.serializer.DeserializeModel(IntPayload); - Assert.True(change.NewValue.HasValue); - Assert.True(change.OldValue.HasValue); + using (Assert.Multiple()) + { + await Assert.That(change.NewValue.HasValue).IsTrue(); + await Assert.That(change.OldValue.HasValue).IsTrue(); - Assert.Equal("17", change.NewValue.Value); + await Assert.That(change.NewValue.Value).IsEqualTo("17"); + } } - [Fact] - public void TestStringPayload() + [Test] + public async Task TestStringPayload() { IAuditLogChange change = this.serializer.DeserializeModel(StringPayload); - Assert.True(change.NewValue.HasValue); - Assert.True(change.OldValue.HasValue); + using (Assert.Multiple()) + { + await Assert.That(change.NewValue.HasValue).IsTrue(); + await Assert.That(change.OldValue.HasValue).IsTrue(); - Assert.Equal("\"this was the old value\"", change.OldValue.Value); + await Assert.That(change.OldValue.Value).IsEqualTo("\"this was the old value\""); + } } - [Fact] - public void TestNewValueMissing() + [Test] + public async Task TestNewValueMissing() { IAuditLogChange change = this.serializer.DeserializeModel(NewValueMissingPayload); - Assert.False(change.NewValue.HasValue); - Assert.True(change.OldValue.HasValue); + using (Assert.Multiple()) + { + await Assert.That(change.NewValue.HasValue).IsFalse(); + await Assert.That(change.OldValue.HasValue).IsTrue(); - Assert.Equal("\"this was the old value\"", change.OldValue.Value); + await Assert.That(change.OldValue.Value).IsEqualTo("\"this was the old value\""); + } } - [Fact] - public void TestOldValueMissing() + [Test] + public async Task TestOldValueMissing() { IAuditLogChange change = this.serializer.DeserializeModel(OldValueMissingPayload); - Assert.True(change.NewValue.HasValue); - Assert.False(change.OldValue.HasValue); + using (Assert.Multiple()) + { + await Assert.That(change.NewValue.HasValue).IsTrue(); + await Assert.That(change.OldValue.HasValue).IsFalse(); - Assert.Equal("\"this is the new value\"", change.NewValue.Value); + await Assert.That(change.NewValue.Value).IsEqualTo("\"this is the new value\""); + } } } diff --git a/tests/core/DSharpPlus.Internal.Models.Tests/Converters/ComponentTests.cs b/tests/core/DSharpPlus.Internal.Models.Tests/Converters/ComponentTests.cs index ef8f472bf4..e90165efab 100644 --- a/tests/core/DSharpPlus.Internal.Models.Tests/Converters/ComponentTests.cs +++ b/tests/core/DSharpPlus.Internal.Models.Tests/Converters/ComponentTests.cs @@ -5,6 +5,8 @@ #pragma warning disable IDE0058 using System; +using System.Threading.Tasks; + using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Internal.Models.Extensions; using DSharpPlus.Serialization; @@ -12,7 +14,6 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; -using Xunit; namespace DSharpPlus.Internal.Models.Tests.Converters; @@ -87,23 +88,29 @@ public ComponentTests() } """u8; - [Fact] - public void TestCorrectActionRowDeserialization() + [Test] + public async Task TestCorrectActionRowDeserialization() { IPartialMessage message = this.serializer.DeserializeModel(ActionRowTestPayload); - Assert.Single(message.Components.Value); - Assert.IsAssignableFrom(message.Components.Value[0]); - Assert.Single(((IActionRowComponent)message.Components.Value[0]).Components); + using (Assert.Multiple()) + { + await Assert.That(message.Components.Value).HasSingleItem(); + await Assert.That(message.Components.Value[0]).IsAssignableTo(); + await Assert.That(((IActionRowComponent)message.Components.Value[0]).Components).HasSingleItem(); + } } - [Fact] - public void TestCorrectUnknownComponentDeserialization() + [Test] + public async Task TestCorrectUnknownComponentDeserialization() { IPartialMessage message = this.serializer.DeserializeModel(OtherTopLevelComponentTestPayload); - Assert.Equal(2, message.Components.Value.Count); - Assert.IsAssignableFrom(message.Components.Value[0]); - Assert.IsAssignableFrom(message.Components.Value[1]); + using (Assert.Multiple()) + { + await Assert.That(message.Components.Value.Count).IsEqualTo(2); + await Assert.That(message.Components.Value[0]).IsAssignableTo(); + await Assert.That(message.Components.Value[1]).IsAssignableTo(); + } } } diff --git a/tests/core/DSharpPlus.Internal.Models.Tests/Converters/DiscordPermissionTests.cs b/tests/core/DSharpPlus.Internal.Models.Tests/Converters/DiscordPermissionTests.cs index 45187c5587..f34f6ad5ff 100644 --- a/tests/core/DSharpPlus.Internal.Models.Tests/Converters/DiscordPermissionTests.cs +++ b/tests/core/DSharpPlus.Internal.Models.Tests/Converters/DiscordPermissionTests.cs @@ -5,12 +5,11 @@ #pragma warning disable IDE0058 using System.Text.Json; +using System.Threading.Tasks; using DSharpPlus.Entities; using DSharpPlus.Internal.Models.Serialization.Converters; -using Xunit; - namespace DSharpPlus.Internal.Models.Tests.Converters; public class DiscordPermissionTests @@ -23,12 +22,12 @@ public DiscordPermissionTests() this.options.Converters.Add(new DiscordPermissionConverter()); } - [Fact] - public void DeserializePermissions() + [Test] + public async Task DeserializePermissions() { DiscordPermissions expected = new(DiscordPermission.PrioritySpeaker); DiscordPermissions actual = JsonSerializer.Deserialize("256", this.options); - Assert.Equal(expected, actual); + await Assert.That(actual).IsEqualTo(expected); } } diff --git a/tests/core/DSharpPlus.Internal.Models.Tests/Converters/OneOfConverterTests.Models.cs b/tests/core/DSharpPlus.Internal.Models.Tests/Converters/OneOfConverterTests.Models.cs index 7555ec7864..136fb95cb1 100644 --- a/tests/core/DSharpPlus.Internal.Models.Tests/Converters/OneOfConverterTests.Models.cs +++ b/tests/core/DSharpPlus.Internal.Models.Tests/Converters/OneOfConverterTests.Models.cs @@ -5,6 +5,7 @@ #pragma warning disable IDE0058 using System; +using System.Threading.Tasks; using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Internal.Models.Extensions; @@ -14,8 +15,6 @@ using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; -using Xunit; - namespace DSharpPlus.Internal.Models.Tests.Converters; // tests one-of deserialization on example payloads for actual models @@ -44,8 +43,8 @@ public OneOfConverterTests() this.serializer = provider.GetRequiredService>(); } - [Fact] - public void TestApplicationCommandInteractionDataOptionUnion() + [Test] + public async Task TestApplicationCommandInteractionDataOptionUnion() { IApplicationCommandInteractionDataOption value = this.serializer.DeserializeModel ( @@ -64,11 +63,11 @@ public void TestApplicationCommandInteractionDataOptionUnion() """u8 ); - Assert.Equal(17, value.Options.Value![0].Value.Value); + await Assert.That(value.Options.Value![0].Value.Value).IsEqualTo(17); } - [Fact] - public void TestInteractionResponseUnion() + [Test] + public async Task TestInteractionResponseUnion() { IInteractionResponse response = this.serializer.DeserializeModel ( @@ -87,6 +86,6 @@ public void TestInteractionResponseUnion() """u8 ); - Assert.Equal("thingie", response.Data.Value.AsT0.Choices[0].Value); + await Assert.That(response.Data.Value.AsT0.Choices[0].Value).IsEqualTo("thingie"); } } diff --git a/tests/core/DSharpPlus.Internal.Models.Tests/Converters/OneOfConverterTests.Precedence.cs b/tests/core/DSharpPlus.Internal.Models.Tests/Converters/OneOfConverterTests.Precedence.cs index 8f7e9f4f4b..d9d0c41740 100644 --- a/tests/core/DSharpPlus.Internal.Models.Tests/Converters/OneOfConverterTests.Precedence.cs +++ b/tests/core/DSharpPlus.Internal.Models.Tests/Converters/OneOfConverterTests.Precedence.cs @@ -4,13 +4,12 @@ using System; using System.Text.Json; +using System.Threading.Tasks; using DSharpPlus.Internal.Models.Serialization.Converters; using OneOf; -using Xunit; - namespace DSharpPlus.Internal.Models.Tests.Converters; // here we test whether we handle precedence correctly, with intentionally annoying unions @@ -20,8 +19,8 @@ public partial class OneOfConverterTests private static ReadOnlySpan SnowflakeStringPayload => "\"737837872\""u8; private static ReadOnlySpan IntegerFloatPayload => "887673"u8; - [Fact] - public void TestSnowflakeLongPrecedence() + [Test] + public async Task TestSnowflakeLongPrecedence() { JsonSerializerOptions options = new(); options.Converters.Add(new OneOfConverterFactory()); @@ -33,7 +32,7 @@ public void TestSnowflakeLongPrecedence() options ); - Assert.True(union.IsT0); + await Assert.That(union.IsT0).IsTrue(); OneOf otherUnion = JsonSerializer.Deserialize> ( @@ -41,11 +40,11 @@ public void TestSnowflakeLongPrecedence() options ); - Assert.True(otherUnion.IsT1); + await Assert.That(otherUnion.IsT1).IsTrue(); } - [Fact] - public void TestSnowflakeStringPrecedence() + [Test] + public async Task TestSnowflakeStringPrecedence() { JsonSerializerOptions options = new(); options.Converters.Add(new OneOfConverterFactory()); @@ -57,7 +56,7 @@ public void TestSnowflakeStringPrecedence() options ); - Assert.True(union.IsT0); + await Assert.That(union.IsT0).IsTrue(); OneOf otherUnion = JsonSerializer.Deserialize> ( @@ -65,11 +64,11 @@ public void TestSnowflakeStringPrecedence() options ); - Assert.True(otherUnion.IsT1); + await Assert.That(otherUnion.IsT1).IsTrue(); } - [Fact] - public void TestIntegerFloatPrecedence() + [Test] + public async Task TestIntegerFloatPrecedence() { JsonSerializerOptions options = new(); options.Converters.Add(new OneOfConverterFactory()); @@ -80,7 +79,7 @@ public void TestIntegerFloatPrecedence() options ); - Assert.True(union.IsT0); + await Assert.That(union.IsT0).IsTrue(); OneOf otherUnion = JsonSerializer.Deserialize> ( @@ -88,6 +87,6 @@ public void TestIntegerFloatPrecedence() options ); - Assert.True(otherUnion.IsT1); + await Assert.That(otherUnion.IsT1).IsTrue(); } } diff --git a/tests/core/DSharpPlus.Internal.Models.Tests/DSharpPlus.Internal.Models.Tests.csproj b/tests/core/DSharpPlus.Internal.Models.Tests/DSharpPlus.Internal.Models.Tests.csproj index 66d43ac0ab..3e987fbde0 100644 --- a/tests/core/DSharpPlus.Internal.Models.Tests/DSharpPlus.Internal.Models.Tests.csproj +++ b/tests/core/DSharpPlus.Internal.Models.Tests/DSharpPlus.Internal.Models.Tests.csproj @@ -1,4 +1,4 @@ - + net10.0 @@ -6,20 +6,13 @@ false true - $(NoWarn);CA1515 + $(NoWarn);CA1515;CA1822;IDE0058;IDE1006 - - - - - - runtime; build; native; contentfiles; analyzers; buildtransitive - all - + diff --git a/tests/core/DSharpPlus.Shared.Tests/DSharpPlus.Shared.Tests.csproj b/tests/core/DSharpPlus.Shared.Tests/DSharpPlus.Shared.Tests.csproj index 861090c4a9..8fff45208a 100644 --- a/tests/core/DSharpPlus.Shared.Tests/DSharpPlus.Shared.Tests.csproj +++ b/tests/core/DSharpPlus.Shared.Tests/DSharpPlus.Shared.Tests.csproj @@ -7,20 +7,14 @@ false true - $(NoWarn);CA1515;CA1707 + $(NoWarn);CA1515;CA1707;CA1822;IDE0058;IDE1006 - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - + - diff --git a/tests/core/DSharpPlus.Shared.Tests/Permissions/BoundTests.cs b/tests/core/DSharpPlus.Shared.Tests/Permissions/BoundTests.cs index 91cf5eb0c6..f5405fce66 100644 --- a/tests/core/DSharpPlus.Shared.Tests/Permissions/BoundTests.cs +++ b/tests/core/DSharpPlus.Shared.Tests/Permissions/BoundTests.cs @@ -15,12 +15,9 @@ using System.Runtime.Versioning; using DSharpPlus.Entities; -using DSharpPlus.Shared.Tests.Util; using TerraFX.Interop.Windows; -using Xunit; - namespace DSharpPlus.Shared.Tests.Permissions; [SupportedOSPlatform("windows")] @@ -80,7 +77,8 @@ ref Unsafe.AsRef(this.usableAllocation + Environment.SystemPageSize - GetL ); } - [FactExceptOnlyOnWindows] + [Test] + [Explicit] public void VectorOpsInBounds_MemoryRegionStart() { try @@ -107,7 +105,8 @@ public void VectorOpsInBounds_MemoryRegionStart() } } - [FactExceptOnlyOnWindows] + [Test] + [Explicit] public void VectorOpsInBounds_MemoryRegionEnd() { try diff --git a/tests/core/DSharpPlus.Shared.Tests/Permissions/ConstructionTests.cs b/tests/core/DSharpPlus.Shared.Tests/Permissions/ConstructionTests.cs index fd33b3f4a4..b85033d7bf 100644 --- a/tests/core/DSharpPlus.Shared.Tests/Permissions/ConstructionTests.cs +++ b/tests/core/DSharpPlus.Shared.Tests/Permissions/ConstructionTests.cs @@ -4,11 +4,10 @@ using System; using System.Numerics; +using System.Threading.Tasks; using DSharpPlus.Entities; -using Xunit; - namespace DSharpPlus.Shared.Tests.Permissions; public class ConstructionTests @@ -31,88 +30,89 @@ public class ConstructionTests 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ]; - [Fact] - public void FirstBitSetCorrectly_Constructor() + [Test] + public async Task FirstBitSetCorrectly_Constructor() { DiscordPermissions permissions = new(DiscordPermission.CreateInvite); DiscordPermissions expected = new(FirstBit); - Assert.Equal(expected, permissions); + await Assert.That(expected).IsEqualTo(permissions); } - [Fact] - public void FirstBitSetCorrectly_Add() + [Test] + public async Task FirstBitSetCorrectly_Add() { - DiscordPermissions permissions = DiscordPermissions.None.Add(DiscordPermission.CreateInvite); + DiscordPermissions permissions = DiscordPermissions.None; + permissions.Add(DiscordPermission.CreateInvite); DiscordPermissions expected = new(FirstBit); - Assert.Equal(expected, permissions); + await Assert.That(expected).IsEqualTo(permissions); } - [Fact] - public void FirstTwoBitsSetCorrectly_Constructor() + [Test] + public async Task FirstTwoBitsSetCorrectly_Constructor() { DiscordPermissions permissions = new(DiscordPermission.CreateInvite, DiscordPermission.KickMembers); DiscordPermissions expected = new(FirstTwoBits); - Assert.Equal(expected, permissions); + await Assert.That(expected).IsEqualTo(permissions); } - [Fact] - public void FirstTwoBitsSetCorrectly_Add() + [Test] + public async Task FirstTwoBitsSetCorrectly_Add() { - DiscordPermissions permissions = DiscordPermissions.None - .Add(DiscordPermission.CreateInvite) - .Add(DiscordPermission.KickMembers); + DiscordPermissions permissions = DiscordPermissions.None; + permissions.Add(DiscordPermission.CreateInvite); + permissions.Add(DiscordPermission.KickMembers); DiscordPermissions expected = new(FirstTwoBits); - Assert.Equal(expected, permissions); + await Assert.That(expected).IsEqualTo(permissions); } - [Fact] - public void FirstTwoBitsSetCorrectly_AddMultiple() + [Test] + public async Task FirstTwoBitsSetCorrectly_AddMultiple() { - DiscordPermissions permissions = DiscordPermissions.None - .Add(DiscordPermission.CreateInvite, DiscordPermission.KickMembers); + DiscordPermissions permissions = DiscordPermissions.None; + permissions.Add(DiscordPermission.CreateInvite, DiscordPermission.KickMembers); DiscordPermissions expected = new(FirstTwoBits); - Assert.Equal(expected, permissions); + await Assert.That(expected).IsEqualTo(permissions); } - [Fact] - public void TestUnderlyingUInt32Rollover() + [Test] + public async Task TestUnderlyingUInt32Rollover() { DiscordPermissions permissions = new(DiscordPermission.RequestToSpeak, DiscordPermission.CreateInvite); DiscordPermissions expected = new(ThirtyThirdBit); - Assert.Equal(expected, permissions); + await Assert.That(expected).IsEqualTo(permissions); } - [Fact] - public void FirstBitSetCorrectly_BigInteger() + [Test] + public async Task FirstBitSetCorrectly_BigInteger() { BigInteger bigint = new(1); DiscordPermissions permissions = new(bigint); DiscordPermissions expected = new(FirstBit); - Assert.Equal(expected, permissions); + await Assert.That(expected).IsEqualTo(permissions); } - [Fact] - public void ThirtyThirdBitSetCorrectly_BigInteger() + [Test] + public async Task ThirtyThirdBitSetCorrectly_BigInteger() { BigInteger bigint = new(4294967297); DiscordPermissions permissions = new(bigint); DiscordPermissions expected = new(ThirtyThirdBit); - Assert.Equal(expected, permissions); + await Assert.That(expected).IsEqualTo(permissions); } - [Fact] - public void OpImplicit() + [Test] + public async Task OpImplicit() { DiscordPermissions expected = new(FirstBit); - Assert.Equal(expected, DiscordPermission.CreateInvite); + await Assert.That(expected).IsEqualTo(DiscordPermission.CreateInvite); } } diff --git a/tests/core/DSharpPlus.Shared.Tests/Permissions/EqualityTests.cs b/tests/core/DSharpPlus.Shared.Tests/Permissions/EqualityTests.cs index 1c3b158c4c..d23a786237 100644 --- a/tests/core/DSharpPlus.Shared.Tests/Permissions/EqualityTests.cs +++ b/tests/core/DSharpPlus.Shared.Tests/Permissions/EqualityTests.cs @@ -2,28 +2,30 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using System; +using System.Threading.Tasks; using DSharpPlus.Entities; -using Xunit; - namespace DSharpPlus.Shared.Tests.Permissions; public class EqualityTests { - private static ReadOnlySpan FirstBit => - [ - 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - ]; + [Test] + public async Task EqualsCorrect_OneBit() + { + DiscordPermissions a = new(DiscordPermission.CreateInvite); + DiscordPermissions b = new(DiscordPermission.CreateInvite); + + // we explicitly don't want the default equals assertion here + await Assert.That(a.Equals(b)).IsTrue(); + } - [Fact] - public void EqualsCorrect_OneBit() + [Test] + public async Task EqualsCorrect_ThirtyThirdBit() { - DiscordPermissions permissions = new(DiscordPermission.CreateInvite); - DiscordPermissions expected = new(FirstBit); + DiscordPermissions a = new(DiscordPermission.RequestToSpeak); + DiscordPermissions b = new(DiscordPermission.RequestToSpeak); - Assert.True(expected.Equals(permissions)); + await Assert.That(a.Equals(b)).IsTrue(); } } diff --git a/tests/core/DSharpPlus.Shared.Tests/Permissions/OperatorTests.cs b/tests/core/DSharpPlus.Shared.Tests/Permissions/OperatorTests.cs index b2bc31aacd..284cf8e96b 100644 --- a/tests/core/DSharpPlus.Shared.Tests/Permissions/OperatorTests.cs +++ b/tests/core/DSharpPlus.Shared.Tests/Permissions/OperatorTests.cs @@ -3,11 +3,10 @@ // file, You can obtain one at https://mozilla.org/MPL/2.0/. using System; +using System.Threading.Tasks; using DSharpPlus.Entities; -using Xunit; - namespace DSharpPlus.Shared.Tests.Permissions; public class OperatorTests @@ -18,65 +17,65 @@ public class OperatorTests 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF ]; - [Fact] - public void TestRemove_SingleBit() + [Test] + public async Task TestRemove_SingleBit() { DiscordPermissions permissions = new(DiscordPermission.CreateInvite); - permissions = permissions.Remove(DiscordPermission.CreateInvite); + permissions.Remove(DiscordPermission.CreateInvite); - Assert.Equal(DiscordPermissions.None, permissions); + await Assert.That(permissions).IsEqualTo(DiscordPermissions.None); permissions = new(DiscordPermission.CreateInvite); - Assert.Equal(DiscordPermissions.None, permissions - DiscordPermission.CreateInvite); + await Assert.That(permissions - DiscordPermission.CreateInvite).IsEqualTo(DiscordPermissions.None); } - [Fact] - public void TestRemove_Bulk() + [Test] + public async Task TestRemove_Bulk() { DiscordPermissions permissions = new(DiscordPermission.CreateInvite, DiscordPermission.BanMembers); - permissions = permissions.Remove(DiscordPermission.CreateInvite, DiscordPermission.BanMembers); + permissions.Remove([DiscordPermission.CreateInvite, DiscordPermission.BanMembers]); - Assert.Equal(DiscordPermissions.None, permissions); + await Assert.That(permissions).IsEqualTo(DiscordPermissions.None); } - [Fact] - public void TestRemove_Set() + [Test] + public async Task TestRemove_Set() { DiscordPermissions permissions = new(DiscordPermission.CreateInvite, DiscordPermission.BanMembers); DiscordPermissions remove = new(DiscordPermission.CreateInvite); - Assert.Equal(DiscordPermission.BanMembers, permissions - remove); + await Assert.That(permissions - remove).IsEqualTo(DiscordPermission.BanMembers); } - [Fact] - public void TestOr_Flag() + [Test] + public async Task TestOr_Flag() { DiscordPermissions permissions = new(DiscordPermission.CreateInvite); DiscordPermissions two = permissions | DiscordPermission.BanMembers; - Assert.Equal(new(DiscordPermission.CreateInvite, DiscordPermission.BanMembers), two); + await Assert.That(two).IsEqualTo(new(DiscordPermission.CreateInvite, DiscordPermission.BanMembers)); } - [Fact] - public void TestOr_Set() + [Test] + public async Task TestOr_Set() { DiscordPermissions one = new(DiscordPermission.AddReactions); DiscordPermissions two = new(DiscordPermission.Administrator); DiscordPermissions actual = one | two; - Assert.Equal(new(DiscordPermission.AddReactions, DiscordPermission.Administrator), actual); + await Assert.That(actual).IsEqualTo(new(DiscordPermission.AddReactions, DiscordPermission.Administrator)); } - [Fact] - public void TestAnd_Flag() + [Test] + public async Task TestAnd_Flag() { DiscordPermissions permissions = new(DiscordPermission.Administrator, DiscordPermission.Connect); - Assert.Equal(DiscordPermission.Administrator, permissions & DiscordPermission.Administrator); + await Assert.That(permissions & DiscordPermission.Administrator).IsEqualTo(DiscordPermission.Administrator); } - [Fact] - public void TestAnd_Set() + [Test] + public async Task TestAnd_Set() { DiscordPermissions permissions = new ( @@ -92,18 +91,18 @@ public void TestAnd_Set() DiscordPermission.CreateInvite ); - Assert.Equal(DiscordPermission.Administrator, permissions & mask); + await Assert.That(permissions & mask).IsEqualTo(DiscordPermission.Administrator); } - [Fact] - public void TestXor_Flag() + [Test] + public async Task TestXor_Flag() { DiscordPermissions permissions = new(DiscordPermission.Administrator, DiscordPermission.Connect); - Assert.Equal(DiscordPermission.Connect, permissions ^ DiscordPermission.Administrator); + await Assert.That(permissions ^ DiscordPermission.Administrator).IsEqualTo(DiscordPermission.Connect); } - [Fact] - public void TestXor_Set() + [Test] + public async Task TestXor_Set() { DiscordPermissions permissions = new ( @@ -127,15 +126,35 @@ public void TestXor_Set() DiscordPermission.CreateInvite ); - Assert.Equal(expected, permissions ^ mask); + await Assert.That(permissions ^ mask).IsEqualTo(expected); } - [Fact] - public void TestNot() + [Test] + public async Task TestNot() { DiscordPermissions permissions = new(DiscordPermission.CreateInvite); DiscordPermissions expected = new(AllButFirstBit); - Assert.Equal(expected, ~permissions); + await Assert.That(~permissions).IsEqualTo(expected); + } + + [Test] + public async Task TestCombine_NonOverlapping() + { + DiscordPermissions set1 = new(DiscordPermission.CreateInvite); + DiscordPermissions set2 = new(DiscordPermission.Connect); + DiscordPermissions expected = new(DiscordPermission.CreateInvite, DiscordPermission.Connect); + + await Assert.That(DiscordPermissions.Combine(set1, set2)).IsEqualTo(expected); + } + + [Test] + public async Task TestCombine_Overlapping() + { + DiscordPermissions set1 = new(DiscordPermission.CreateInvite, DiscordPermission.Connect); + DiscordPermissions set2 = new(DiscordPermission.Connect); + DiscordPermissions expected = new(DiscordPermission.CreateInvite, DiscordPermission.Connect); + + await Assert.That(DiscordPermissions.Combine(set1, set2)).IsEqualTo(expected); } } diff --git a/tests/core/DSharpPlus.Shared.Tests/Permissions/ToStringTests.cs b/tests/core/DSharpPlus.Shared.Tests/Permissions/ToStringTests.cs index e44b824a82..ae72a1e1bb 100644 --- a/tests/core/DSharpPlus.Shared.Tests/Permissions/ToStringTests.cs +++ b/tests/core/DSharpPlus.Shared.Tests/Permissions/ToStringTests.cs @@ -2,72 +2,115 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Entities; +using System; +using System.Threading.Tasks; -using Xunit; +using DSharpPlus.Entities; namespace DSharpPlus.Shared.Tests.Permissions; public class ToStringTests { - [Fact] - public void TestFirstBit() + [Test] + public async Task TestFirstBit() { DiscordPermissions permissions = new(DiscordPermission.CreateInvite); - Assert.Equal("1", permissions.ToString()); + await Assert.That(permissions.ToString()).IsEqualTo("1"); } - [Fact] - public void TestByteOrder_SecondByte() + [Test] + public async Task TestByteOrder_SecondByte() { DiscordPermissions permissions = new(DiscordPermission.PrioritySpeaker); - Assert.Equal("256", permissions.ToString()); + await Assert.That(permissions.ToString()).IsEqualTo("256"); } - [Fact] - public void TestInternalElementOrder_SecondElement() + [Test] + public async Task TestInternalElementOrder_SecondElement() { DiscordPermissions permissions = new(DiscordPermission.RequestToSpeak); - Assert.Equal("4294967296", permissions.ToString()); + await Assert.That(permissions.ToString()).IsEqualTo("4294967296"); } - [Fact] - public void TestRawFirstBit() + [Test] + public async Task TestRawFirstBit() { DiscordPermissions permissions = new(DiscordPermission.CreateInvite); - Assert.Equal + await Assert.That(permissions.ToString("raw")).IsEqualTo ( - "DiscordPermissions - raw value: 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00", - permissions.ToString("raw") + "DiscordPermissions - raw value: 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00" ); } - [Fact] - public void TestRawSecondElement() + [Test] + public async Task TestRawSecondElement() { DiscordPermissions permissions = new(DiscordPermission.RequestToSpeak); - Assert.Equal + await Assert.That(permissions.ToString("raw")).IsEqualTo ( - "DiscordPermissions - raw value: 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00", - permissions.ToString("raw") + "DiscordPermissions - raw value: 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00" ); } - [Fact] - public void TestNameFirstElement() + [Test] + public async Task TestNameFirstElement() { DiscordPermissions permissions = new(DiscordPermission.CreateInvite); - Assert.Equal("Create Invites", permissions.ToString("name")); + await Assert.That(permissions.ToString("name")).IsEqualTo("Create Invites"); } - [Fact] - public void TestNameOrder() + [Test] + public async Task TestNameOrder() { DiscordPermissions permissions = new(DiscordPermission.RequestToSpeak, DiscordPermission.CreateInvite); - Assert.Equal("Create Invites, Request to Speak", permissions.ToString("name")); + await Assert.That(permissions.ToString("name")).IsEqualTo("Create Invites, Request to Speak"); + } + + [Test] + public async Task TestUndefinedFlags() + { + DiscordPermissions permissions = new((DiscordPermission)48, (DiscordPermission)65, (DiscordPermission)97, (DiscordPermission)127); + + await Assert.That(permissions.ToString("name")).IsEqualTo("48, 65, 97, 127"); + } + + // when updating this test, try to find holes to use for this + [Test] + public async Task TestNameOrderUndefinedFlags() + { + DiscordPermissions permissions = new(DiscordPermission.ReadMessageHistory, (DiscordPermission)48, DiscordPermission.UseExternalApps); + + await Assert.That(permissions.ToString("name")).IsEqualTo("Read Message History, 48, Use External Apps"); + } + + [Test] + public async Task TestCustomFormatThrowsIfMalformed() + { + DiscordPermissions permissions = new(DiscordPermission.ReadMessageHistory, DiscordPermission.UseExternalApps); + + await Assert.ThrowsAsync(() => + { + _ = permissions.ToString("name:"); + return Task.CompletedTask; + }); + + await Assert.ThrowsAsync(() => + { + _ = permissions.ToString("name:with a format but without the permission marker"); + return Task.CompletedTask; + }); + } + + [Test] + public async Task TestCustomFormat() + { + DiscordPermissions permissions = new(DiscordPermission.ReadMessageHistory, DiscordPermission.UseExternalApps); + string expected = " - Read Message History\r\n - Use External Apps\r\n"; + + await Assert.That(permissions.ToString("name: - {permission}\r\n")).IsEqualTo(expected); } } diff --git a/tests/core/DSharpPlus.Shared.Tests/Permissions/UtilityTests.cs b/tests/core/DSharpPlus.Shared.Tests/Permissions/UtilityTests.cs index d240f5bf37..a65c518ef9 100644 --- a/tests/core/DSharpPlus.Shared.Tests/Permissions/UtilityTests.cs +++ b/tests/core/DSharpPlus.Shared.Tests/Permissions/UtilityTests.cs @@ -2,53 +2,62 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Entities; +using System.Threading.Tasks; -using Xunit; +using DSharpPlus.Entities; namespace DSharpPlus.Shared.Tests.Permissions; public class UtilityTests { - [Fact] - public void HasPermissionRespectsAdministrator() + [Test] + public async Task HasPermissionRespectsAdministrator() { DiscordPermissions permissions = new(DiscordPermission.Administrator, DiscordPermission.AddReactions); - Assert.True(permissions.HasPermission(DiscordPermission.BanMembers)); + await Assert.That(permissions.HasPermission(DiscordPermission.BanMembers)).IsTrue(); permissions = new(DiscordPermission.AddReactions); - Assert.False(permissions.HasPermission(DiscordPermission.BanMembers)); + await Assert.That(permissions.HasPermission(DiscordPermission.BanMembers)).IsFalse(); } - [Fact] - public void HasAnyPermissionAlwaysSucceedsWithAdministrator() + [Test] + public async Task HasAnyPermissionAlwaysSucceedsWithAdministrator() { DiscordPermissions permissions = new(DiscordPermission.Administrator, DiscordPermission.AddReactions); - Assert.True(permissions.HasAnyPermission(DiscordPermission.BanMembers, DiscordPermission.CreateInvite)); + await Assert.That(permissions.HasAnyPermission([DiscordPermission.BanMembers, DiscordPermission.CreateInvite])).IsTrue(); } - [Fact] - public void HasAnyPermissionWithoutAdministrator() + [Test] + public async Task HasAnyPermissionWithoutAdministrator() { DiscordPermissions permissions = new(DiscordPermission.CreateInvite, DiscordPermission.AddReactions); - Assert.True(permissions.HasAnyPermission(DiscordPermission.BanMembers, DiscordPermission.CreateInvite)); - Assert.False(permissions.HasAnyPermission(DiscordPermission.AttachFiles, DiscordPermission.Connect)); + + using (Assert.Multiple()) + { + await Assert.That(permissions.HasAnyPermission([DiscordPermission.BanMembers, DiscordPermission.CreateInvite])).IsTrue(); + await Assert.That(permissions.HasAnyPermission([DiscordPermission.AttachFiles, DiscordPermission.Connect])).IsFalse(); + } } - [Fact] - public void HasAllPermissionsAlwaysSucceedsWithAdministrator() + [Test] + public async Task HasAllPermissionsAlwaysSucceedsWithAdministrator() { DiscordPermissions permissions = new(DiscordPermission.Administrator); - Assert.True(permissions.HasAllPermissions(DiscordPermission.CreatePrivateThreads, DiscordPermission.KickMembers)); + await Assert.That(permissions.HasAllPermissions([DiscordPermission.CreatePrivateThreads, DiscordPermission.KickMembers])).IsTrue(); } - [Fact] - public void HasAllPermissionsWithoutAdministrator() + [Test] + public async Task HasAllPermissionsWithoutAdministrator() { DiscordPermissions permissions = new(DiscordPermission.CreateInvite, DiscordPermission.AddReactions); + DiscordPermissions testificate = [DiscordPermission.CreateInvite, DiscordPermission.Connect]; permissions += DiscordPermission.ManageGuild; - Assert.True(permissions.HasAllPermissions(DiscordPermission.ManageGuild, DiscordPermission.CreateInvite)); - Assert.False(permissions.HasAllPermissions(DiscordPermission.CreateInvite, DiscordPermission.Connect)); + using (Assert.Multiple()) + { + await Assert.That(permissions.HasAllPermissions([DiscordPermission.ManageGuild, DiscordPermission.CreateInvite])).IsTrue(); + await Assert.That(permissions.HasAllPermissions([DiscordPermission.CreateInvite, DiscordPermission.Connect])).IsFalse(); + await Assert.That(testificate.HasPermission(DiscordPermission.Connect)).IsTrue(); + } } } diff --git a/tests/core/DSharpPlus.Shared.Tests/TextWriters/IndentedArrayPoolUtf16.cs b/tests/core/DSharpPlus.Shared.Tests/TextWriters/IndentedArrayPoolUtf16.cs index 92b49a7d11..edbfdcb941 100644 --- a/tests/core/DSharpPlus.Shared.Tests/TextWriters/IndentedArrayPoolUtf16.cs +++ b/tests/core/DSharpPlus.Shared.Tests/TextWriters/IndentedArrayPoolUtf16.cs @@ -2,16 +2,16 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.RuntimeServices.TextWriters; +using System.Threading.Tasks; -using Xunit; +using DSharpPlus.RuntimeServices.TextWriters; namespace DSharpPlus.Shared.Tests.TextWriters; public class IndentedArrayPoolUtf16 { - [Fact] - public void TestIndentationIncrementDecrement() + [Test] + public async Task TestIndentationIncrementDecrement() { using IndentedArrayPoolUtf16TextWriter writer = new(); @@ -21,19 +21,18 @@ public void TestIndentationIncrementDecrement() writer.DecreaseIndentation(); writer.WriteLine("}"); - Assert.Equal + await Assert.That(writer.ToString().Trim(' ', '\r', '\n')).IsEqualTo ( """ { } - """, - writer.ToString().Trim(' ', '\r', 'n') + """ ); } - [Fact] - public void TestIndentingWrite() + [Test] + public async Task TestIndentingWrite() { using IndentedArrayPoolUtf16TextWriter writer = new(); @@ -43,20 +42,19 @@ public void TestIndentingWrite() writer.DecreaseIndentation(); writer.WriteLine("}"); - Assert.Equal + await Assert.That(writer.ToString().Trim(' ', '\r', '\n')).IsEqualTo ( """ { "stuff": 1 } - """, - writer.ToString().Trim(' ', '\r', 'n') + """ ); } - [Fact] - public void TestLiteralPreservingWrite() + [Test] + public async Task TestLiteralPreservingWrite() { using IndentedArrayPoolUtf16TextWriter writer = new(); @@ -66,15 +64,14 @@ public void TestLiteralPreservingWrite() writer.DecreaseIndentation(); writer.WriteLine("}"); - Assert.Equal + await Assert.That(writer.ToString().Trim(' ', '\r', '\n')).IsEqualTo ( """ { "stuff": 1 } - """, - writer.ToString().Trim(' ', '\r', 'n') + """ ); } } diff --git a/tests/core/DSharpPlus.Shared.Tests/Util/FactExceptOnlyOnWindowsAttribute.cs b/tests/core/DSharpPlus.Shared.Tests/Util/FactExceptOnlyOnWindowsAttribute.cs deleted file mode 100644 index 1fe3d2bcf0..0000000000 --- a/tests/core/DSharpPlus.Shared.Tests/Util/FactExceptOnlyOnWindowsAttribute.cs +++ /dev/null @@ -1,20 +0,0 @@ -// This Source Code form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -using System; - -using Xunit; - -namespace DSharpPlus.Shared.Tests.Util; - -internal sealed class FactExceptOnlyOnWindowsAttribute : FactAttribute -{ - public FactExceptOnlyOnWindowsAttribute() - { - if (!OperatingSystem.IsWindows()) - { - Skip = "Ignored on non-Windows platforms."; - } - } -} From 3ae768735797f236b3f6bcdf2176492cb1ea7cd5 Mon Sep 17 00:00:00 2001 From: Livia-Valeriya Silvercrown Date: Sun, 18 May 2025 22:51:55 +0200 Subject: [PATCH 321/323] this can't be readonly actually --- src/core/DSharpPlus.Shared/Entities/DiscordPermissions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/DSharpPlus.Shared/Entities/DiscordPermissions.cs b/src/core/DSharpPlus.Shared/Entities/DiscordPermissions.cs index 81f8a06f55..d58621d81f 100644 --- a/src/core/DSharpPlus.Shared/Entities/DiscordPermissions.cs +++ b/src/core/DSharpPlus.Shared/Entities/DiscordPermissions.cs @@ -41,7 +41,7 @@ public partial struct DiscordPermissions private static readonly string[] permissionNames = CreatePermissionNameArray(); private static readonly int highestDefinedValue = (int)DiscordPermissionExtensions.GetValues()[^1]; - private readonly DiscordPermissionContainer data; + private DiscordPermissionContainer data; /// /// Creates a new instance of this type from exactly the specified permission. From faaf65db452d9e937eaea54f50e3ff02473fd584 Mon Sep 17 00:00:00 2001 From: Livia-Valeriya Silvercrown Date: Sun, 18 May 2025 22:52:50 +0200 Subject: [PATCH 322/323] mark the other three methods as readonly --- .../Entities/DiscordPermissions.Enumeration.cs | 3 +-- .../Entities/DiscordPermissions.Utility.cs | 6 +++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/core/DSharpPlus.Shared/Entities/DiscordPermissions.Enumeration.cs b/src/core/DSharpPlus.Shared/Entities/DiscordPermissions.Enumeration.cs index 427ec954e3..6b7e711584 100644 --- a/src/core/DSharpPlus.Shared/Entities/DiscordPermissions.Enumeration.cs +++ b/src/core/DSharpPlus.Shared/Entities/DiscordPermissions.Enumeration.cs @@ -13,10 +13,9 @@ namespace DSharpPlus.Entities; -// contains the implementation details for EnumeratePermissions +// contains the implementation details for enumerating permissions partial struct DiscordPermissions { - /// /// Gets an enumerator for the present permission set. /// diff --git a/src/core/DSharpPlus.Shared/Entities/DiscordPermissions.Utility.cs b/src/core/DSharpPlus.Shared/Entities/DiscordPermissions.Utility.cs index a5fb174beb..1336ea1fd6 100644 --- a/src/core/DSharpPlus.Shared/Entities/DiscordPermissions.Utility.cs +++ b/src/core/DSharpPlus.Shared/Entities/DiscordPermissions.Utility.cs @@ -29,18 +29,18 @@ public readonly bool HasFlag(DiscordPermission flag) /// /// Returns whether the specified permission is granted, either directly or through Administrator permissions. /// - public bool HasPermission(DiscordPermission permission) + public readonly bool HasPermission(DiscordPermission permission) => this.HasFlag(DiscordPermission.Administrator) || this.HasFlag(permission); /// /// Returns whether any of the specified permissions are granted, either directly or through Administrator permissions. /// - public bool HasAnyPermission(DiscordPermissions permissions) + public readonly bool HasAnyPermission(DiscordPermissions permissions) => this.HasFlag(DiscordPermission.Administrator) || (this & permissions) != None; /// /// Returns whether all of the specified permissions are granted, either directly or through Administrator permissions. /// - public bool HasAllPermissions(DiscordPermissions expected) + public readonly bool HasAllPermissions(DiscordPermissions expected) => this.HasFlag(DiscordPermission.Administrator) || (this & expected) == expected; } From 48b0ddb0cde70cd23df0be74643aa8530209fce1 Mon Sep 17 00:00:00 2001 From: Livia-Valeriya Silvercrown Date: Fri, 23 May 2025 22:10:05 +0200 Subject: [PATCH 323/323] components v2 + assorted other API features --- .editorconfig | 3 +- DSharpPlus.slnx | 18 +++++-- meta/toolbox-concrete-types.json | 4 +- .../IActionRowComponent.cs | 5 ++ .../IButtonComponent.cs | 5 ++ .../IChannelSelectComponent.cs | 5 ++ .../IComponent.cs | 0 .../Components/IContainerComponent.cs | 41 ++++++++++++++++ .../IDefaultSelectValue.cs | 0 .../Components/IFileComponent.cs | 33 +++++++++++++ .../Components/IMediaGalleryComponent.cs | 30 ++++++++++++ .../Components/IMediaGalleryItem.cs | 26 ++++++++++ .../IMentionableSelectComponent.cs | 5 ++ .../IRoleSelectComponent.cs | 5 ++ .../Components/ISectionComponent.cs | 35 ++++++++++++++ .../ISelectOption.cs | 0 .../Components/ISeparatorComponent.cs | 33 +++++++++++++ .../IStringSelectComponent.cs | 5 ++ .../Components/ITextDisplayComponent.cs | 29 +++++++++++ .../ITextInputComponent.cs | 5 ++ .../Components/IThumbnailComponent.cs | 35 ++++++++++++++ .../Components/IUnfurledMediaItem.cs | 36 ++++++++++++++ .../IUnknownComponent.cs | 5 ++ .../IUserSelectComponent.cs | 5 ++ .../Entitlements/IEntitlement.cs | 12 +++++ .../Entitlements/IPartialEntitlement.cs | 4 +- .../Guilds/IGuild.cs | 5 ++ .../Guilds/IIncidentsData.cs | 34 +++++++++++++ .../Guilds/IPartialGuild.cs | 5 ++ .../Guilds/IPartialGuildMember.cs | 5 ++ .../Interactions/IInteraction.cs | 5 ++ .../Messages/IAllowedMentions.cs | 2 +- .../Subscriptions/ISubscription.cs | 5 ++ .../API/IGuildRestAPI.cs | 31 ++++++------ .../API/IWebhookRestAPI.cs | 2 +- .../IModifyGuildIncidentActionsPayload.cs | 24 ++++++++++ .../Webhooks/IEditWebhookMessagePayload.cs | 7 +++ .../Webhooks/EditWebhookMessageQuery.cs | 25 ++++++++++ .../Queries/Webhooks/ExecuteWebhookQuery.cs | 6 +++ .../BlockMessageActionMetadata.cs | 1 - .../SendAlertMessageActionMetadata.cs | 1 - .../AutoModeration/TimeoutActionMetadata.cs | 1 - .../ActionRowComponent.cs | 3 ++ .../ButtonComponent.cs | 3 ++ .../ChannelSelectComponent.cs | 3 ++ .../Component.cs | 0 .../Components/ContainerComponent.cs | 29 +++++++++++ .../DefaultSelectValue.cs | 0 .../Components/FileComponent.cs | 24 ++++++++++ .../Components/MediaGalleryComponent.cs | 23 +++++++++ .../Components/MediaGalleryItem.cs | 20 ++++++++ .../MentionableSelectComponent.cs | 3 ++ .../RoleSelectComponent.cs | 3 ++ .../Components/SectionComponent.cs | 26 ++++++++++ .../SelectOption.cs | 0 .../Components/SeparatorComponent.cs | 24 ++++++++++ .../StringSelectComponent.cs | 3 ++ .../Components/TextDisplayComponent.cs | 21 ++++++++ .../TextInputComponent.cs | 3 ++ .../Components/ThumbnailComponent.cs | 27 +++++++++++ .../Components/UnfurledMediaItem.cs | 26 ++++++++++ .../UnknownComponent.cs | 3 ++ .../UserSelectComponent.cs | 3 ++ .../Entitlements/Entitlement.cs | 4 +- .../Entitlements/PartialEntitlement.cs | 4 +- ...erviceCollectionExtensions.Registration.cs | 34 ++++++++----- .../Extensions/ServiceCollectionExtensions.cs | 1 - .../Guilds/Guild.cs | 3 ++ .../Guilds/GuildMember.cs | 3 ++ .../Guilds/IncidentsData.cs | 25 ++++++++++ .../Guilds/PartialGuild.cs | 3 ++ .../Guilds/PartialGuildMember.cs | 3 ++ .../Interactions/Interaction.cs | 3 ++ .../Messages/AllowedMentions.cs | 2 +- .../Converters/ComponentConverter.cs | 38 ++++++--------- .../Converters/DiscordPermissionConverter.cs | 2 - .../AttachmentDataTypeInfoResolver.cs | 1 - .../Subscriptions/Subscription.cs | 3 ++ .../API/GuildRestAPI.cs | 48 ++++++++----------- .../API/WebhookRestAPI.cs | 12 ++++- ...erviceCollectionExtensions.Registration.cs | 2 + .../ModifyGuildIncidentActionsPayload.cs | 19 ++++++++ .../Soundboard/SendSoundboardSoundPayload.cs | 17 +++++++ .../Webhooks/EditWebhookMessagePayload.cs | 4 ++ .../DSharpPlus.Shared.csproj | 4 ++ .../DiscordButtonStyle.cs | 0 .../DiscordMessageComponentType.cs | 37 +++++++++++++- .../Components/DiscordSeparatorSpacingSize.cs | 21 ++++++++ .../DiscordTextInputStyle.cs | 0 .../DiscordPermissions.Enumeration.cs | 1 + .../Entities/Messages/DiscordMessageFlags.cs | 12 ++++- src/core/DSharpPlus.Shared/InlineMediaData.cs | 2 + src/core/DSharpPlus.Shared/MediaFormat.cs | 1 + .../Interactions/TextInputComponentBuilder.cs | 1 - .../BuiltTextInputComponent.cs | 1 - 95 files changed, 995 insertions(+), 106 deletions(-) rename src/core/DSharpPlus.Internal.Abstractions.Models/{MessageComponents => Components}/IActionRowComponent.cs (85%) rename src/core/DSharpPlus.Internal.Abstractions.Models/{MessageComponents => Components}/IButtonComponent.cs (92%) rename src/core/DSharpPlus.Internal.Abstractions.Models/{MessageComponents => Components}/IChannelSelectComponent.cs (93%) rename src/core/DSharpPlus.Internal.Abstractions.Models/{MessageComponents => Components}/IComponent.cs (100%) create mode 100644 src/core/DSharpPlus.Internal.Abstractions.Models/Components/IContainerComponent.cs rename src/core/DSharpPlus.Internal.Abstractions.Models/{MessageComponents => Components}/IDefaultSelectValue.cs (100%) create mode 100644 src/core/DSharpPlus.Internal.Abstractions.Models/Components/IFileComponent.cs create mode 100644 src/core/DSharpPlus.Internal.Abstractions.Models/Components/IMediaGalleryComponent.cs create mode 100644 src/core/DSharpPlus.Internal.Abstractions.Models/Components/IMediaGalleryItem.cs rename src/core/DSharpPlus.Internal.Abstractions.Models/{MessageComponents => Components}/IMentionableSelectComponent.cs (92%) rename src/core/DSharpPlus.Internal.Abstractions.Models/{MessageComponents => Components}/IRoleSelectComponent.cs (92%) create mode 100644 src/core/DSharpPlus.Internal.Abstractions.Models/Components/ISectionComponent.cs rename src/core/DSharpPlus.Internal.Abstractions.Models/{MessageComponents => Components}/ISelectOption.cs (100%) create mode 100644 src/core/DSharpPlus.Internal.Abstractions.Models/Components/ISeparatorComponent.cs rename src/core/DSharpPlus.Internal.Abstractions.Models/{MessageComponents => Components}/IStringSelectComponent.cs (91%) create mode 100644 src/core/DSharpPlus.Internal.Abstractions.Models/Components/ITextDisplayComponent.cs rename src/core/DSharpPlus.Internal.Abstractions.Models/{MessageComponents => Components}/ITextInputComponent.cs (93%) create mode 100644 src/core/DSharpPlus.Internal.Abstractions.Models/Components/IThumbnailComponent.cs create mode 100644 src/core/DSharpPlus.Internal.Abstractions.Models/Components/IUnfurledMediaItem.cs rename src/core/DSharpPlus.Internal.Abstractions.Models/{MessageComponents => Components}/IUnknownComponent.cs (84%) rename src/core/DSharpPlus.Internal.Abstractions.Models/{MessageComponents => Components}/IUserSelectComponent.cs (92%) create mode 100644 src/core/DSharpPlus.Internal.Abstractions.Models/Guilds/IIncidentsData.cs create mode 100644 src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Guilds/IModifyGuildIncidentActionsPayload.cs create mode 100644 src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Webhooks/EditWebhookMessageQuery.cs rename src/core/DSharpPlus.Internal.Models/{MessageComponents => Components}/ActionRowComponent.cs (90%) rename src/core/DSharpPlus.Internal.Models/{MessageComponents => Components}/ButtonComponent.cs (94%) rename src/core/DSharpPlus.Internal.Models/{MessageComponents => Components}/ChannelSelectComponent.cs (94%) rename src/core/DSharpPlus.Internal.Models/{MessageComponents => Components}/Component.cs (100%) create mode 100644 src/core/DSharpPlus.Internal.Models/Components/ContainerComponent.cs rename src/core/DSharpPlus.Internal.Models/{MessageComponents => Components}/DefaultSelectValue.cs (100%) create mode 100644 src/core/DSharpPlus.Internal.Models/Components/FileComponent.cs create mode 100644 src/core/DSharpPlus.Internal.Models/Components/MediaGalleryComponent.cs create mode 100644 src/core/DSharpPlus.Internal.Models/Components/MediaGalleryItem.cs rename src/core/DSharpPlus.Internal.Models/{MessageComponents => Components}/MentionableSelectComponent.cs (94%) rename src/core/DSharpPlus.Internal.Models/{MessageComponents => Components}/RoleSelectComponent.cs (94%) create mode 100644 src/core/DSharpPlus.Internal.Models/Components/SectionComponent.cs rename src/core/DSharpPlus.Internal.Models/{MessageComponents => Components}/SelectOption.cs (100%) create mode 100644 src/core/DSharpPlus.Internal.Models/Components/SeparatorComponent.cs rename src/core/DSharpPlus.Internal.Models/{MessageComponents => Components}/StringSelectComponent.cs (93%) create mode 100644 src/core/DSharpPlus.Internal.Models/Components/TextDisplayComponent.cs rename src/core/DSharpPlus.Internal.Models/{MessageComponents => Components}/TextInputComponent.cs (94%) create mode 100644 src/core/DSharpPlus.Internal.Models/Components/ThumbnailComponent.cs create mode 100644 src/core/DSharpPlus.Internal.Models/Components/UnfurledMediaItem.cs rename src/core/DSharpPlus.Internal.Models/{MessageComponents => Components}/UnknownComponent.cs (89%) rename src/core/DSharpPlus.Internal.Models/{MessageComponents => Components}/UserSelectComponent.cs (94%) create mode 100644 src/core/DSharpPlus.Internal.Models/Guilds/IncidentsData.cs create mode 100644 src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyGuildIncidentActionsPayload.cs create mode 100644 src/core/DSharpPlus.Internal.Rest/Payloads/Soundboard/SendSoundboardSoundPayload.cs rename src/core/DSharpPlus.Shared/Entities/{MessageComponents => Components}/DiscordButtonStyle.cs (100%) rename src/core/DSharpPlus.Shared/Entities/{MessageComponents => Components}/DiscordMessageComponentType.cs (58%) create mode 100644 src/core/DSharpPlus.Shared/Entities/Components/DiscordSeparatorSpacingSize.cs rename src/core/DSharpPlus.Shared/Entities/{MessageComponents => Components}/DiscordTextInputStyle.cs (100%) diff --git a/.editorconfig b/.editorconfig index b676699d66..2e438f15e1 100644 --- a/.editorconfig +++ b/.editorconfig @@ -27,6 +27,7 @@ end_of_line = crlf indent_size = 4 insert_final_newline = true charset = utf-8 +end_of_line = crlf ############################### # .NET Coding Conventions # @@ -38,7 +39,7 @@ file_header_template = This Source Code form is subject to the terms of the Mozi # Organize usings dotnet_sort_system_directives_first = true:error -dotnet_separate_import_directive_groups = true:error +dotnet_separate_import_directive_groups = true csharp_qualified_using_at_nested_scope = true:error # usings before namespace csharp_using_directive_placement = outside_namespace:error diff --git a/DSharpPlus.slnx b/DSharpPlus.slnx index a0a7cf53e3..eae872a936 100644 --- a/DSharpPlus.slnx +++ b/DSharpPlus.slnx @@ -7,18 +7,28 @@ - + + + + - - - + + + + + + + + + + diff --git a/meta/toolbox-concrete-types.json b/meta/toolbox-concrete-types.json index 727616e1d6..ad555cfccf 100644 --- a/meta/toolbox-concrete-types.json +++ b/meta/toolbox-concrete-types.json @@ -3,8 +3,8 @@ "./src/core/DSharpPlus.Internal.Models/Interactions/InteractionResponse.cs", "./src/core/DSharpPlus.Internal.Models/Interactions/ModalCallbackData.cs", "./src/core/DSharpPlus.Internal.Models/Interactions/MessageCallbackData.cs", - "./src/core/DSharpPlus.Internal.Models/MessageComponents/ActionRowComponent.cs", - "./src/core/DSharpPlus.Internal.Models/MessageComponents/TextInputComponent.cs", + "./src/core/DSharpPlus.Internal.Models/Components/ActionRowComponent.cs", + "./src/core/DSharpPlus.Internal.Models/Components/TextInputComponent.cs", "./src/core/DSharpPlus.Internal.Models/ScheduledEvents/ScheduledEventRecurrenceDay.cs", "./src/core/DSharpPlus.Internal.Models/ScheduledEvents/ScheduledEventRecurrenceRule.cs", "./src/core/DSharpPlus.Internal.Rest/Payloads/Messages/CreateMessagePayload.cs", diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IActionRowComponent.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Components/IActionRowComponent.cs similarity index 85% rename from src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IActionRowComponent.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Components/IActionRowComponent.cs index 117fa4faaf..a757aec900 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IActionRowComponent.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Components/IActionRowComponent.cs @@ -18,6 +18,11 @@ public interface IActionRowComponent : IComponent /// public DiscordMessageComponentType Type { get; } + /// + /// An optional numeric identifier for this component. + /// + public Optional Id { get; } + /// /// The child components of this action row: up to five buttons, or one non-button component. /// diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IButtonComponent.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Components/IButtonComponent.cs similarity index 92% rename from src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IButtonComponent.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Components/IButtonComponent.cs index f94b335083..5e27d492b4 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IButtonComponent.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Components/IButtonComponent.cs @@ -16,6 +16,11 @@ public interface IButtonComponent : IComponent ///
public DiscordMessageComponentType Type { get; } + /// + /// An optional numeric identifier for this component. + /// + public Optional Id { get; } + /// /// The visual style of this button. /// diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IChannelSelectComponent.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Components/IChannelSelectComponent.cs similarity index 93% rename from src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IChannelSelectComponent.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Components/IChannelSelectComponent.cs index 919d415a29..75cabd974d 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IChannelSelectComponent.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Components/IChannelSelectComponent.cs @@ -19,6 +19,11 @@ public interface IChannelSelectComponent : IComponent ///
public DiscordMessageComponentType Type { get; } + /// + /// An optional numeric identifier for this component. + /// + public Optional Id { get; } + /// /// The developer-defined ID for this select menu, up to 100 characters. /// diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IComponent.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Components/IComponent.cs similarity index 100% rename from src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IComponent.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Components/IComponent.cs diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/Components/IContainerComponent.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Components/IContainerComponent.cs new file mode 100644 index 0000000000..efbfa5ee33 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Components/IContainerComponent.cs @@ -0,0 +1,41 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Entities; + +namespace DSharpPlus.Internal.Abstractions.Models; + +/// +/// A top-level layout-only component that is visually distinct from the background and has a customizable colour bar akin to an embed. +/// +public interface IContainerComponent : IComponent +{ + /// + /// The type of this component. + /// + public DiscordMessageComponentType Type { get; } + + /// + /// An optional numeric identifier for this component. + /// + public Optional Id { get; } + + /// + /// The components to display in this container. + /// + public IReadOnlyList Components { get; } + + /// + /// The colour for the colour bar. Unset blends it with the container's background, which depends on client theme. + /// + public Optional AccentColor { get; } + + /// + /// Indicates whether the container should be spoilered, that is, blurred out until clicked or if the user automatically shows all spoilers. + /// Defaults to false. + /// + public Optional Spoiler { get; } +} diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IDefaultSelectValue.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Components/IDefaultSelectValue.cs similarity index 100% rename from src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IDefaultSelectValue.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Components/IDefaultSelectValue.cs diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/Components/IFileComponent.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Components/IFileComponent.cs new file mode 100644 index 0000000000..eca86f6401 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Components/IFileComponent.cs @@ -0,0 +1,33 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Entities; + +namespace DSharpPlus.Internal.Abstractions.Models; + +/// +/// A top-level component that allows displaying an uploaded file. +/// +public interface IFileComponent : IComponent +{ + /// + /// The type of this component. + /// + public DiscordMessageComponentType Type { get; } + + /// + /// An optional numeric identifier for this component. + /// + public Optional Id { get; } + + /// + /// The file to display. In this case, only uploads are supported via attachment:// reference, not other arbitrary URLs. + /// + public IUnfurledMediaItem File { get; } + + /// + /// Indicates whether the file should be spoilered. Defaults to false. + /// + public Optional Spoiler { get; } +} diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/Components/IMediaGalleryComponent.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Components/IMediaGalleryComponent.cs new file mode 100644 index 0000000000..e9453ad6f4 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Components/IMediaGalleryComponent.cs @@ -0,0 +1,30 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Entities; + +namespace DSharpPlus.Internal.Abstractions.Models; + +/// +/// Represents a gallery of one to ten media items to display. +/// +public interface IMediaGalleryComponent : IComponent +{ + /// + /// The type of this component. + /// + public DiscordMessageComponentType Type { get; } + + /// + /// An optional numeric identifier for this component. + /// + public Optional Id { get; } + + /// + /// 1-10 media items. + /// + public IReadOnlyList Items { get; } +} diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/Components/IMediaGalleryItem.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Components/IMediaGalleryItem.cs new file mode 100644 index 0000000000..20fca1f5ff --- /dev/null +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Components/IMediaGalleryItem.cs @@ -0,0 +1,26 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Internal.Abstractions.Models; + +/// +/// Represents a single media item inside a media gallery. +/// +public interface IMediaGalleryItem +{ + /// + /// The underlying media item to display. + /// + public IUnfurledMediaItem Media { get; } + + /// + /// Alt text for this media item. + /// + public Optional Description { get; } + + /// + /// Indicates whether this media item should be spoilered; that is, blurred out and only showed on click or if the user automatically shows all spoilers. + /// + public Optional Spoiler { get; } +} diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IMentionableSelectComponent.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Components/IMentionableSelectComponent.cs similarity index 92% rename from src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IMentionableSelectComponent.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Components/IMentionableSelectComponent.cs index cc7a044213..f192b8a6f0 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IMentionableSelectComponent.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Components/IMentionableSelectComponent.cs @@ -18,6 +18,11 @@ public interface IMentionableSelectComponent : IComponent ///
public DiscordMessageComponentType Type { get; } + /// + /// An optional numeric identifier for this component. + /// + public Optional Id { get; } + /// /// The developer-defined ID for this select menu, up to 100 characters. /// diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IRoleSelectComponent.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Components/IRoleSelectComponent.cs similarity index 92% rename from src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IRoleSelectComponent.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Components/IRoleSelectComponent.cs index 0127fae34c..89ced9a516 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IRoleSelectComponent.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Components/IRoleSelectComponent.cs @@ -18,6 +18,11 @@ public interface IRoleSelectComponent : IComponent ///
public DiscordMessageComponentType Type { get; } + /// + /// An optional numeric identifier for this component. + /// + public Optional Id { get; } + /// /// The developer-defined ID for this select menu, up to 100 characters. /// diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/Components/ISectionComponent.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Components/ISectionComponent.cs new file mode 100644 index 0000000000..1608193ae3 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Components/ISectionComponent.cs @@ -0,0 +1,35 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Entities; + +namespace DSharpPlus.Internal.Abstractions.Models; + +/// +/// A top-level layout component that allows combining text with an accessory. +/// +public interface ISectionComponent : IComponent +{ + /// + /// The type of this component. + /// + public DiscordMessageComponentType Type { get; } + + /// + /// An optional numeric identifier for this component. + /// + public Optional Id { get; } + + /// + /// One to three text components to send within this section. + /// + public IReadOnlyList Components { get; } + + /// + /// A thumbnail or button component to group with the text in this component. + /// + public IComponent Accessory { get; } +} diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/ISelectOption.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Components/ISelectOption.cs similarity index 100% rename from src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/ISelectOption.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Components/ISelectOption.cs diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/Components/ISeparatorComponent.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Components/ISeparatorComponent.cs new file mode 100644 index 0000000000..d232d32d3b --- /dev/null +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Components/ISeparatorComponent.cs @@ -0,0 +1,33 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Entities; + +namespace DSharpPlus.Internal.Abstractions.Models; + +/// +/// A top-level component that adds vertical padding and/or visual division between components. +/// +public interface ISeparatorComponent : IComponent +{ + /// + /// The type of this component. + /// + public DiscordMessageComponentType Type { get; } + + /// + /// An optional numeric identifier for this component. + /// + public Optional Id { get; } + + /// + /// Indicates whether a visual divider should be displayed in this component. Defaults to true. + /// + public Optional Divider { get; } + + /// + /// The amount of space this separator takes up. + /// + public Optional Spacing { get; } +} diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IStringSelectComponent.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Components/IStringSelectComponent.cs similarity index 91% rename from src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IStringSelectComponent.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Components/IStringSelectComponent.cs index 11bd47000e..d3e5a906e4 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IStringSelectComponent.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Components/IStringSelectComponent.cs @@ -18,6 +18,11 @@ public interface IStringSelectComponent : IComponent ///
public DiscordMessageComponentType Type { get; } + /// + /// An optional numeric identifier for this component. + /// + public Optional Id { get; } + /// /// The developer-defined ID for this select menu, up to 100 characters. /// diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/Components/ITextDisplayComponent.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Components/ITextDisplayComponent.cs new file mode 100644 index 0000000000..1efc318996 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Components/ITextDisplayComponent.cs @@ -0,0 +1,29 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Entities; + +namespace DSharpPlus.Internal.Abstractions.Models; + +/// +/// A top-level component displaying markdown text. Mentions in the text are controlled by the message's +/// . +/// +public interface ITextDisplayComponent : IComponent +{ + /// + /// The type of this component. + /// + public DiscordMessageComponentType Type { get; } + + /// + /// An optional numeric identifier for this component. + /// + public Optional Id { get; } + + /// + /// The text to display with this component. + /// + public string Content { get; } +} diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/ITextInputComponent.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Components/ITextInputComponent.cs similarity index 93% rename from src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/ITextInputComponent.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Components/ITextInputComponent.cs index 5398f3933c..b748649617 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/ITextInputComponent.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Components/ITextInputComponent.cs @@ -16,6 +16,11 @@ public interface ITextInputComponent : IComponent ///
public DiscordMessageComponentType Type { get; } + /// + /// An optional numeric identifier for this component. + /// + public Optional Id { get; } + /// /// The identifier of this input field, up to 100 characters. /// diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/Components/IThumbnailComponent.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Components/IThumbnailComponent.cs new file mode 100644 index 0000000000..c527db03ae --- /dev/null +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Components/IThumbnailComponent.cs @@ -0,0 +1,35 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Entities; + +namespace DSharpPlus.Internal.Abstractions.Models; + +public interface IThumbnailComponent : IComponent +{ + /// + /// The type of this component. + /// + public DiscordMessageComponentType Type { get; } + + /// + /// An optional numeric identifier for this component. + /// + public Optional Id { get; } + + /// + /// The media item to be displayed in this thumbnail. + /// + public IUnfurledMediaItem Media { get; } + + /// + /// Alt text for this thumbnail. + /// + public Optional Description { get; } + + /// + /// Indicates whether this thumbnail should be spoilered; that is, blurred out and only showed on click or if the user automatically shows all spoilers. + /// + public Optional Spoiler { get; } +} diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/Components/IUnfurledMediaItem.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Components/IUnfurledMediaItem.cs new file mode 100644 index 0000000000..98a0960619 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Components/IUnfurledMediaItem.cs @@ -0,0 +1,36 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Internal.Abstractions.Models; + +/// +/// Represents an attachment reference for use in components. +/// +public interface IUnfurledMediaItem +{ + /// + /// The URL to the attachment; supports arbitrary URLs and attachemnt:// references to files uploaded along the message. + /// + public string Url { get; } + + /// + /// The proxied URL of this media item. + /// + public Optional ProxyUrl { get; } + + /// + /// The height of this media item. + /// + public Optional Height { get; } + + /// + /// The width of this media item. + /// + public Optional Width { get; } + + /// + /// The MIME/content type of the content. + /// + public Optional ContentType { get; } +} diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IUnknownComponent.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Components/IUnknownComponent.cs similarity index 84% rename from src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IUnknownComponent.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Components/IUnknownComponent.cs index fa7db1114f..3f3881cf3a 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IUnknownComponent.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Components/IUnknownComponent.cs @@ -16,6 +16,11 @@ public interface IUnknownComponent : IComponent ///
public DiscordMessageComponentType Type { get; } + /// + /// An optional numeric identifier for this component. + /// + public Optional Id { get; } + /// /// Gets the raw string represented by this component. /// diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IUserSelectComponent.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Components/IUserSelectComponent.cs similarity index 92% rename from src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IUserSelectComponent.cs rename to src/core/DSharpPlus.Internal.Abstractions.Models/Components/IUserSelectComponent.cs index 33f459edbe..4119dacdfb 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Models/MessageComponents/IUserSelectComponent.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Components/IUserSelectComponent.cs @@ -18,6 +18,11 @@ public interface IUserSelectComponent : IComponent ///
public DiscordMessageComponentType Type { get; } + /// + /// An optional numeric identifier for this component. + /// + public Optional Id { get; } + /// /// The developer-defined ID for this select menu, up to 100 characters. /// diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/Entitlements/IEntitlement.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Entitlements/IEntitlement.cs index 99554c78f3..80c833ccff 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Models/Entitlements/IEntitlement.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Entitlements/IEntitlement.cs @@ -2,6 +2,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +using System; + using DSharpPlus.Entities; namespace DSharpPlus.Internal.Abstractions.Models; @@ -23,6 +25,12 @@ public interface IEntitlement : IPartialEntitlement /// public new bool Deleted { get; } + /// + public new DateTimeOffset? StartsAt { get; } + + /// + public new DateTimeOffset? EndsAt { get; } + // partial access Optional IPartialEntitlement.SkuId => this.SkuId; @@ -32,4 +40,8 @@ public interface IEntitlement : IPartialEntitlement Optional IPartialEntitlement.Type => this.Type; Optional IPartialEntitlement.Deleted => this.Deleted; + + Optional IPartialEntitlement.StartsAt => this.StartsAt; + + Optional IPartialEntitlement.EndsAt => this.EndsAt; } diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/Entitlements/IPartialEntitlement.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Entitlements/IPartialEntitlement.cs index 0f2517ccce..b84649f2b0 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Models/Entitlements/IPartialEntitlement.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Entitlements/IPartialEntitlement.cs @@ -51,12 +51,12 @@ public interface IPartialEntitlement /// /// The starting date at which this entitlement is valid. Not present when using test entitlements. /// - public Optional StartsAt { get; } + public Optional StartsAt { get; } /// /// The date at which this entitlement is no longer valid. Not present when using test entitlements. /// - public Optional EndsAt { get; } + public Optional EndsAt { get; } /// /// Indicates whether this entitlement has been consumed. diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/Guilds/IGuild.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Guilds/IGuild.cs index 15f5c7f442..28a3c4d5c3 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Models/Guilds/IGuild.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Guilds/IGuild.cs @@ -97,6 +97,9 @@ public interface IGuild : IPartialGuild /// public new Snowflake? SafetyAlertsChannelId { get; } + /// + public new IIncidentsData? IncidentsData { get; } + // routes for partial access /// @@ -182,4 +185,6 @@ public interface IGuild : IPartialGuild /// Optional IPartialGuild.SafetyAlertsChannelId => this.SafetyAlertsChannelId; + + Optional IPartialGuild.IncidentsData => new(this.IncidentsData); } diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/Guilds/IIncidentsData.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Guilds/IIncidentsData.cs new file mode 100644 index 0000000000..d2048f6dd0 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Guilds/IIncidentsData.cs @@ -0,0 +1,34 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; + +namespace DSharpPlus.Internal.Abstractions.Models; + +/// +/// Contains metadata for a guild pertaining to recent incidents and moderation actions, such as temporarily disabling invites or detected raids. +/// +public interface IIncidentsData +{ + /// + /// Indicates when invites get enabled again. + /// + public DateTimeOffset? InvitesDisabledUntil { get; } + + /// + /// Indicates when direct messages between guild members get enabled again. Note that they can still message each other if they can do so through other + /// means, such as being friends or sharing another mutual server. + /// + public DateTimeOffset? DmsDisabledUntil { get; } + + /// + /// Indicates when DM spam was last detected in the guild. + /// + public Optional DmSpamDetectedAt { get; } + + /// + /// Indicates when a raid was last detected in the guild. + /// + public Optional RaidDetectedAt { get; } +} diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/Guilds/IPartialGuild.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Guilds/IPartialGuild.cs index fef8962e80..94e5b6642e 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Models/Guilds/IPartialGuild.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Guilds/IPartialGuild.cs @@ -225,4 +225,9 @@ public interface IPartialGuild /// The snowflake identifier of the channel where community servers receive safety alerts. /// public Optional SafetyAlertsChannelId { get; } + + /// + /// Guild metadata pertaining to raids and spam incidents and actions taken to resolve them. + /// + public Optional IncidentsData { get; } } diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/Guilds/IPartialGuildMember.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Guilds/IPartialGuildMember.cs index b60aa255ff..35d30a67ac 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Models/Guilds/IPartialGuildMember.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Guilds/IPartialGuildMember.cs @@ -29,6 +29,11 @@ public interface IPartialGuildMember ///
public Optional Avatar { get; } + /// + /// The user's guild banner hash. + /// + public Optional Banner { get; } + /// /// This user's list of roles. /// diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/Interactions/IInteraction.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Interactions/IInteraction.cs index 32243821a1..302d3498de 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Models/Interactions/IInteraction.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Interactions/IInteraction.cs @@ -114,4 +114,9 @@ public interface IInteraction /// The context the interaction was triggered in. ///
public Optional Context { get; } + + /// + /// The size limit for attachments this interaction can be responded to with, in bytes. + /// + public int AttachmentSizeLimit { get; } } diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/Messages/IAllowedMentions.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Messages/IAllowedMentions.cs index 3b0e0145ee..417280b57f 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Models/Messages/IAllowedMentions.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Messages/IAllowedMentions.cs @@ -19,7 +19,7 @@ public interface IAllowedMentions /// "roles" for parsing role mentions, "users" for parsing user mentions and /// "everyone" for parsing @everyone and @here mentions. ///
- public IReadOnlyList Parse { get; } + public Optional> Parse { get; } /// /// An array of role IDs to mention, up to 100. diff --git a/src/core/DSharpPlus.Internal.Abstractions.Models/Subscriptions/ISubscription.cs b/src/core/DSharpPlus.Internal.Abstractions.Models/Subscriptions/ISubscription.cs index f7b1f439fc..f1fdeaaddf 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Models/Subscriptions/ISubscription.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Models/Subscriptions/ISubscription.cs @@ -34,6 +34,11 @@ public interface ISubscription /// public IReadOnlyList EntitlementIds { get; } + /// + /// The list of SKUs this user will be subscribed to at renewal. + /// + public IReadOnlyList? RenewalSkuIds { get; } + /// /// The starting timestamp of the current subscription period. /// diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IGuildRestAPI.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IGuildRestAPI.cs index d7bfe15520..f941dd8992 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IGuildRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IGuildRestAPI.cs @@ -21,21 +21,6 @@ namespace DSharpPlus.Internal.Abstractions.Rest.API; ///
public interface IGuildRestAPI { - /// - /// Creates a new guild with the bot user as its owner. This endpoint can only be used by bots in less than - /// 10 guilds. - /// - /// The information to create this guild with. - /// Additional instructions regarding this request. - /// A cancellation token for this operation. - /// The newly created guild. - public ValueTask> CreateGuildAsync - ( - ICreateGuildPayload payload, - RequestInfo info = default, - CancellationToken ct = default - ); - /// /// Fetches a guild from its snowflake identifier. /// @@ -749,4 +734,20 @@ public ValueTask> ModifyGuildOnboardingAsync RequestInfo info = default, CancellationToken ct = default ); + + /// + /// Modifies the actions taken in response to a raid or spam incident in the given guild. + /// + /// The snowflake identifier of the guild in question. + /// The new action data to modify the guild with. + /// Additional instructions regarding this request. + /// A cancellation token for this operation. + /// The newly updated actions taken and, if applicable, ongoing incidents. + public ValueTask> ModifyGuildIncidentActionsAsync + ( + Snowflake guildId, + IModifyGuildIncidentActionsPayload payload, + RequestInfo info = default, + CancellationToken ct = default + ); } diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IWebhookRestAPI.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IWebhookRestAPI.cs index 8ba186b1c1..a533cedae2 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IWebhookRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/API/IWebhookRestAPI.cs @@ -241,7 +241,7 @@ public ValueTask> EditWebhookMessageAsync string webhookToken, Snowflake messageId, IEditWebhookMessagePayload payload, - ThreadIdQuery query = default, + EditWebhookMessageQuery query = default, RequestInfo info = default, CancellationToken ct = default ); diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Guilds/IModifyGuildIncidentActionsPayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Guilds/IModifyGuildIncidentActionsPayload.cs new file mode 100644 index 0000000000..e77d88158c --- /dev/null +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Guilds/IModifyGuildIncidentActionsPayload.cs @@ -0,0 +1,24 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; + +namespace DSharpPlus.Internal.Abstractions.Rest.Payloads; + +/// +/// Represents a payload to PUT /guilds/:guild-id/incident-actions. +/// +public interface IModifyGuildIncidentActionsPayload +{ + /// + /// Disables invites up until the specified time. + /// + public Optional InvitesDisabledUntil { get; } + + /// + /// Disables direct messages between guild members up until the specified time. Note that this does not prevent members from messaging each other + /// if they have another avenue of doing so, such as another mutual server or being friends. + /// + public Optional DmsDisabledUntil { get; } +} diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Webhooks/IEditWebhookMessagePayload.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Webhooks/IEditWebhookMessagePayload.cs index 50892730d7..f9d71c82f0 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Webhooks/IEditWebhookMessagePayload.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Payloads/Webhooks/IEditWebhookMessagePayload.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; +using DSharpPlus.Entities; using DSharpPlus.Internal.Abstractions.Models; namespace DSharpPlus.Internal.Abstractions.Rest.Payloads; @@ -23,6 +24,12 @@ public interface IEditWebhookMessagePayload ///
public Optional?> Embeds { get; } + /// + /// The flags to edit this message with. may be set but not removed, + /// may be set and removed, and all other flags cannot be set or removed. + /// + public Optional Flags { get; } + /// /// The new allowed mentions object for this message. /// diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Webhooks/EditWebhookMessageQuery.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Webhooks/EditWebhookMessageQuery.cs new file mode 100644 index 0000000000..9c74e9ea3d --- /dev/null +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Webhooks/EditWebhookMessageQuery.cs @@ -0,0 +1,25 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Internal.Abstractions.Rest.Queries; + +/// +/// Contains the query parameters to IWebhookRestAPI.EditWebhookMessageAsync. +/// +public readonly record struct EditWebhookMessageQuery +{ + + /// + /// Specifies a thread to edit the message in rather than directly in the parent channel. If the thread + /// is archived, this will automatically unarchive it. Only threads with the same parent channel as the + /// webhook can be passed. + /// + public Snowflake? ThreadId { get; init; } + + /// + /// Specifies whether this request will allow sending non-interactive components for non-application-owned webhooks. + /// Defaults to + /// + public bool? WithComponents { get; init; } +} diff --git a/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Webhooks/ExecuteWebhookQuery.cs b/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Webhooks/ExecuteWebhookQuery.cs index 3d9bff6976..b9975cb1bb 100644 --- a/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Webhooks/ExecuteWebhookQuery.cs +++ b/src/core/DSharpPlus.Internal.Abstractions.Rest/Queries/Webhooks/ExecuteWebhookQuery.cs @@ -24,4 +24,10 @@ public readonly record struct ExecuteWebhookQuery /// webhook can be passed. ///
public Snowflake? ThreadId { get; init; } + + /// + /// Specifies whether this request will allow sending non-interactive components for non-application-owned webhooks. + /// Defaults to + /// + public bool? WithComponents { get; init; } } diff --git a/src/core/DSharpPlus.Internal.Models/AutoModeration/BlockMessageActionMetadata.cs b/src/core/DSharpPlus.Internal.Models/AutoModeration/BlockMessageActionMetadata.cs index 5c6719126b..6f7b3e4bd7 100644 --- a/src/core/DSharpPlus.Internal.Models/AutoModeration/BlockMessageActionMetadata.cs +++ b/src/core/DSharpPlus.Internal.Models/AutoModeration/BlockMessageActionMetadata.cs @@ -2,7 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Entities; using DSharpPlus.Internal.Abstractions.Models; namespace DSharpPlus.Internal.Models; diff --git a/src/core/DSharpPlus.Internal.Models/AutoModeration/SendAlertMessageActionMetadata.cs b/src/core/DSharpPlus.Internal.Models/AutoModeration/SendAlertMessageActionMetadata.cs index f96df74c97..d13868210c 100644 --- a/src/core/DSharpPlus.Internal.Models/AutoModeration/SendAlertMessageActionMetadata.cs +++ b/src/core/DSharpPlus.Internal.Models/AutoModeration/SendAlertMessageActionMetadata.cs @@ -2,7 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Entities; using DSharpPlus.Internal.Abstractions.Models; namespace DSharpPlus.Internal.Models; diff --git a/src/core/DSharpPlus.Internal.Models/AutoModeration/TimeoutActionMetadata.cs b/src/core/DSharpPlus.Internal.Models/AutoModeration/TimeoutActionMetadata.cs index 0f31482a86..19be154272 100644 --- a/src/core/DSharpPlus.Internal.Models/AutoModeration/TimeoutActionMetadata.cs +++ b/src/core/DSharpPlus.Internal.Models/AutoModeration/TimeoutActionMetadata.cs @@ -2,7 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DSharpPlus.Entities; using DSharpPlus.Internal.Abstractions.Models; namespace DSharpPlus.Internal.Models; diff --git a/src/core/DSharpPlus.Internal.Models/MessageComponents/ActionRowComponent.cs b/src/core/DSharpPlus.Internal.Models/Components/ActionRowComponent.cs similarity index 90% rename from src/core/DSharpPlus.Internal.Models/MessageComponents/ActionRowComponent.cs rename to src/core/DSharpPlus.Internal.Models/Components/ActionRowComponent.cs index 7b28013a64..89ac6c62d1 100644 --- a/src/core/DSharpPlus.Internal.Models/MessageComponents/ActionRowComponent.cs +++ b/src/core/DSharpPlus.Internal.Models/Components/ActionRowComponent.cs @@ -15,6 +15,9 @@ public sealed record ActionRowComponent : IActionRowComponent /// public required DiscordMessageComponentType Type { get; init; } + /// + public Optional Id { get; init; } + /// public required IReadOnlyList Components { get; init; } } \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Models/MessageComponents/ButtonComponent.cs b/src/core/DSharpPlus.Internal.Models/Components/ButtonComponent.cs similarity index 94% rename from src/core/DSharpPlus.Internal.Models/MessageComponents/ButtonComponent.cs rename to src/core/DSharpPlus.Internal.Models/Components/ButtonComponent.cs index 88931fd644..08aedeb440 100644 --- a/src/core/DSharpPlus.Internal.Models/MessageComponents/ButtonComponent.cs +++ b/src/core/DSharpPlus.Internal.Models/Components/ButtonComponent.cs @@ -13,6 +13,9 @@ public sealed record ButtonComponent : IButtonComponent /// public required DiscordMessageComponentType Type { get; init; } + /// + public Optional Id { get; init; } + /// public required DiscordButtonStyle Style { get; init; } diff --git a/src/core/DSharpPlus.Internal.Models/MessageComponents/ChannelSelectComponent.cs b/src/core/DSharpPlus.Internal.Models/Components/ChannelSelectComponent.cs similarity index 94% rename from src/core/DSharpPlus.Internal.Models/MessageComponents/ChannelSelectComponent.cs rename to src/core/DSharpPlus.Internal.Models/Components/ChannelSelectComponent.cs index 54025d7724..7f6c48e5fd 100644 --- a/src/core/DSharpPlus.Internal.Models/MessageComponents/ChannelSelectComponent.cs +++ b/src/core/DSharpPlus.Internal.Models/Components/ChannelSelectComponent.cs @@ -15,6 +15,9 @@ public sealed record ChannelSelectComponent : IChannelSelectComponent /// public required DiscordMessageComponentType Type { get; init; } + /// + public Optional Id { get; init; } + /// public required string CustomId { get; init; } diff --git a/src/core/DSharpPlus.Internal.Models/MessageComponents/Component.cs b/src/core/DSharpPlus.Internal.Models/Components/Component.cs similarity index 100% rename from src/core/DSharpPlus.Internal.Models/MessageComponents/Component.cs rename to src/core/DSharpPlus.Internal.Models/Components/Component.cs diff --git a/src/core/DSharpPlus.Internal.Models/Components/ContainerComponent.cs b/src/core/DSharpPlus.Internal.Models/Components/ContainerComponent.cs new file mode 100644 index 0000000000..716677e8d7 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Models/Components/ContainerComponent.cs @@ -0,0 +1,29 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; + +namespace DSharpPlus.Internal.Models; + +/// +public sealed record ContainerComponent : IContainerComponent +{ + /// + public required DiscordMessageComponentType Type { get; init; } + + /// + public Optional Id { get; init; } + + /// + public required IReadOnlyList Components { get; init; } + + /// + public Optional AccentColor { get; init; } + + /// + public Optional Spoiler { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Models/MessageComponents/DefaultSelectValue.cs b/src/core/DSharpPlus.Internal.Models/Components/DefaultSelectValue.cs similarity index 100% rename from src/core/DSharpPlus.Internal.Models/MessageComponents/DefaultSelectValue.cs rename to src/core/DSharpPlus.Internal.Models/Components/DefaultSelectValue.cs diff --git a/src/core/DSharpPlus.Internal.Models/Components/FileComponent.cs b/src/core/DSharpPlus.Internal.Models/Components/FileComponent.cs new file mode 100644 index 0000000000..a0bfc44922 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Models/Components/FileComponent.cs @@ -0,0 +1,24 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; + +namespace DSharpPlus.Internal.Models; + +/// +public sealed record FileComponent : IFileComponent +{ + /// + public required DiscordMessageComponentType Type { get; init; } + + /// + public Optional Id { get; init; } + + /// + public required IUnfurledMediaItem File { get; init; } + + /// + public Optional Spoiler { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Models/Components/MediaGalleryComponent.cs b/src/core/DSharpPlus.Internal.Models/Components/MediaGalleryComponent.cs new file mode 100644 index 0000000000..9dd206628e --- /dev/null +++ b/src/core/DSharpPlus.Internal.Models/Components/MediaGalleryComponent.cs @@ -0,0 +1,23 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; + +namespace DSharpPlus.Internal.Models; + +/// +public sealed record MediaGalleryComponent : IMediaGalleryComponent +{ + /// + public required DiscordMessageComponentType Type { get; init; } + + /// + public Optional Id { get; init; } + + /// + public required IReadOnlyList Items { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Models/Components/MediaGalleryItem.cs b/src/core/DSharpPlus.Internal.Models/Components/MediaGalleryItem.cs new file mode 100644 index 0000000000..b447dc9f56 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Models/Components/MediaGalleryItem.cs @@ -0,0 +1,20 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Internal.Abstractions.Models; + +namespace DSharpPlus.Internal.Models; + +/// +public sealed record MediaGalleryItem : IMediaGalleryItem +{ + /// + public required IUnfurledMediaItem Media { get; init; } + + /// + public Optional Description { get; init; } + + /// + public Optional Spoiler { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Models/MessageComponents/MentionableSelectComponent.cs b/src/core/DSharpPlus.Internal.Models/Components/MentionableSelectComponent.cs similarity index 94% rename from src/core/DSharpPlus.Internal.Models/MessageComponents/MentionableSelectComponent.cs rename to src/core/DSharpPlus.Internal.Models/Components/MentionableSelectComponent.cs index 4132f05864..c0a55a356a 100644 --- a/src/core/DSharpPlus.Internal.Models/MessageComponents/MentionableSelectComponent.cs +++ b/src/core/DSharpPlus.Internal.Models/Components/MentionableSelectComponent.cs @@ -15,6 +15,9 @@ public sealed record MentionableSelectComponent : IMentionableSelectComponent /// public required DiscordMessageComponentType Type { get; init; } + /// + public Optional Id { get; init; } + /// public required string CustomId { get; init; } diff --git a/src/core/DSharpPlus.Internal.Models/MessageComponents/RoleSelectComponent.cs b/src/core/DSharpPlus.Internal.Models/Components/RoleSelectComponent.cs similarity index 94% rename from src/core/DSharpPlus.Internal.Models/MessageComponents/RoleSelectComponent.cs rename to src/core/DSharpPlus.Internal.Models/Components/RoleSelectComponent.cs index 03600d46cf..6927670b42 100644 --- a/src/core/DSharpPlus.Internal.Models/MessageComponents/RoleSelectComponent.cs +++ b/src/core/DSharpPlus.Internal.Models/Components/RoleSelectComponent.cs @@ -15,6 +15,9 @@ public sealed record RoleSelectComponent : IRoleSelectComponent /// public required DiscordMessageComponentType Type { get; init; } + /// + public Optional Id { get; init; } + /// public required string CustomId { get; init; } diff --git a/src/core/DSharpPlus.Internal.Models/Components/SectionComponent.cs b/src/core/DSharpPlus.Internal.Models/Components/SectionComponent.cs new file mode 100644 index 0000000000..adf699e900 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Models/Components/SectionComponent.cs @@ -0,0 +1,26 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System.Collections.Generic; + +using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; + +namespace DSharpPlus.Internal.Models; + +/// +public sealed record SectionComponent : ISectionComponent +{ + /// + public required DiscordMessageComponentType Type { get; init; } + + /// + public Optional Id { get; init; } + + /// + public required IReadOnlyList Components { get; init; } + + /// + public required IComponent Accessory { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Models/MessageComponents/SelectOption.cs b/src/core/DSharpPlus.Internal.Models/Components/SelectOption.cs similarity index 100% rename from src/core/DSharpPlus.Internal.Models/MessageComponents/SelectOption.cs rename to src/core/DSharpPlus.Internal.Models/Components/SelectOption.cs diff --git a/src/core/DSharpPlus.Internal.Models/Components/SeparatorComponent.cs b/src/core/DSharpPlus.Internal.Models/Components/SeparatorComponent.cs new file mode 100644 index 0000000000..dd6feb2e42 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Models/Components/SeparatorComponent.cs @@ -0,0 +1,24 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; + +namespace DSharpPlus.Internal.Models; + +/// +public sealed record SeparatorComponent : ISeparatorComponent +{ + /// + public required DiscordMessageComponentType Type { get; init; } + + /// + public Optional Id { get; init; } + + /// + public Optional Divider { get; init; } + + /// + public Optional Spacing { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Models/MessageComponents/StringSelectComponent.cs b/src/core/DSharpPlus.Internal.Models/Components/StringSelectComponent.cs similarity index 93% rename from src/core/DSharpPlus.Internal.Models/MessageComponents/StringSelectComponent.cs rename to src/core/DSharpPlus.Internal.Models/Components/StringSelectComponent.cs index 1b35b53ab7..2c288de0de 100644 --- a/src/core/DSharpPlus.Internal.Models/MessageComponents/StringSelectComponent.cs +++ b/src/core/DSharpPlus.Internal.Models/Components/StringSelectComponent.cs @@ -15,6 +15,9 @@ public sealed record StringSelectComponent : IStringSelectComponent /// public required DiscordMessageComponentType Type { get; init; } + /// + public Optional Id { get; init; } + /// public required string CustomId { get; init; } diff --git a/src/core/DSharpPlus.Internal.Models/Components/TextDisplayComponent.cs b/src/core/DSharpPlus.Internal.Models/Components/TextDisplayComponent.cs new file mode 100644 index 0000000000..2dc60a511a --- /dev/null +++ b/src/core/DSharpPlus.Internal.Models/Components/TextDisplayComponent.cs @@ -0,0 +1,21 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; + +namespace DSharpPlus.Internal.Models; + +/// +public sealed record TextDisplayComponent : ITextDisplayComponent +{ + /// + public required DiscordMessageComponentType Type { get; init; } + + /// + public Optional Id { get; init; } + + /// + public required string Content { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Models/MessageComponents/TextInputComponent.cs b/src/core/DSharpPlus.Internal.Models/Components/TextInputComponent.cs similarity index 94% rename from src/core/DSharpPlus.Internal.Models/MessageComponents/TextInputComponent.cs rename to src/core/DSharpPlus.Internal.Models/Components/TextInputComponent.cs index df75bfd404..474a70989e 100644 --- a/src/core/DSharpPlus.Internal.Models/MessageComponents/TextInputComponent.cs +++ b/src/core/DSharpPlus.Internal.Models/Components/TextInputComponent.cs @@ -13,6 +13,9 @@ public sealed record TextInputComponent : ITextInputComponent /// public required DiscordMessageComponentType Type { get; init; } + /// + public Optional Id { get; init; } + /// public required string CustomId { get; init; } diff --git a/src/core/DSharpPlus.Internal.Models/Components/ThumbnailComponent.cs b/src/core/DSharpPlus.Internal.Models/Components/ThumbnailComponent.cs new file mode 100644 index 0000000000..ff49e9460b --- /dev/null +++ b/src/core/DSharpPlus.Internal.Models/Components/ThumbnailComponent.cs @@ -0,0 +1,27 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Entities; +using DSharpPlus.Internal.Abstractions.Models; + +namespace DSharpPlus.Internal.Models; + +/// +public sealed record ThumbnailComponent : IThumbnailComponent +{ + /// + public required DiscordMessageComponentType Type { get; init; } + + /// + public Optional Id { get; init; } + + /// + public required IUnfurledMediaItem Media { get; init; } + + /// + public Optional Description { get; init; } + + /// + public Optional Spoiler { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Models/Components/UnfurledMediaItem.cs b/src/core/DSharpPlus.Internal.Models/Components/UnfurledMediaItem.cs new file mode 100644 index 0000000000..39a2e7a407 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Models/Components/UnfurledMediaItem.cs @@ -0,0 +1,26 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Internal.Abstractions.Models; + +namespace DSharpPlus.Internal.Models; + +/// +public sealed record UnfurledMediaItem : IUnfurledMediaItem +{ + /// + public required string Url { get; init; } + + /// + public Optional ProxyUrl { get; init; } + + /// + public Optional Height { get; init; } + + /// + public Optional Width { get; init; } + + /// + public Optional ContentType { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Models/MessageComponents/UnknownComponent.cs b/src/core/DSharpPlus.Internal.Models/Components/UnknownComponent.cs similarity index 89% rename from src/core/DSharpPlus.Internal.Models/MessageComponents/UnknownComponent.cs rename to src/core/DSharpPlus.Internal.Models/Components/UnknownComponent.cs index 9c84065002..497307fb4e 100644 --- a/src/core/DSharpPlus.Internal.Models/MessageComponents/UnknownComponent.cs +++ b/src/core/DSharpPlus.Internal.Models/Components/UnknownComponent.cs @@ -13,6 +13,9 @@ public sealed record UnknownComponent : IUnknownComponent /// public required DiscordMessageComponentType Type { get; init; } + /// + public Optional Id { get; init; } + /// public required string RawPayload { get; init; } } \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Models/MessageComponents/UserSelectComponent.cs b/src/core/DSharpPlus.Internal.Models/Components/UserSelectComponent.cs similarity index 94% rename from src/core/DSharpPlus.Internal.Models/MessageComponents/UserSelectComponent.cs rename to src/core/DSharpPlus.Internal.Models/Components/UserSelectComponent.cs index 2d08593d40..4be6c44c3d 100644 --- a/src/core/DSharpPlus.Internal.Models/MessageComponents/UserSelectComponent.cs +++ b/src/core/DSharpPlus.Internal.Models/Components/UserSelectComponent.cs @@ -15,6 +15,9 @@ public sealed record UserSelectComponent : IUserSelectComponent /// public required DiscordMessageComponentType Type { get; init; } + /// + public Optional Id { get; init; } + /// public required string CustomId { get; init; } diff --git a/src/core/DSharpPlus.Internal.Models/Entitlements/Entitlement.cs b/src/core/DSharpPlus.Internal.Models/Entitlements/Entitlement.cs index b5f89c37e3..878eab1b3e 100644 --- a/src/core/DSharpPlus.Internal.Models/Entitlements/Entitlement.cs +++ b/src/core/DSharpPlus.Internal.Models/Entitlements/Entitlement.cs @@ -34,10 +34,10 @@ public sealed record Entitlement : IEntitlement public required bool Deleted { get; init; } /// - public Optional StartsAt { get; init; } + public DateTimeOffset? StartsAt { get; init; } /// - public Optional EndsAt { get; init; } + public DateTimeOffset? EndsAt { get; init; } /// public Optional Consumed { get; init; } diff --git a/src/core/DSharpPlus.Internal.Models/Entitlements/PartialEntitlement.cs b/src/core/DSharpPlus.Internal.Models/Entitlements/PartialEntitlement.cs index b2f4a2164c..9629d58219 100644 --- a/src/core/DSharpPlus.Internal.Models/Entitlements/PartialEntitlement.cs +++ b/src/core/DSharpPlus.Internal.Models/Entitlements/PartialEntitlement.cs @@ -34,10 +34,10 @@ public sealed record PartialEntitlement : IPartialEntitlement public Optional Deleted { get; init; } /// - public Optional StartsAt { get; init; } + public Optional StartsAt { get; init; } /// - public Optional EndsAt { get; init; } + public Optional EndsAt { get; init; } /// public Optional Consumed { get; init; } diff --git a/src/core/DSharpPlus.Internal.Models/Extensions/ServiceCollectionExtensions.Registration.cs b/src/core/DSharpPlus.Internal.Models/Extensions/ServiceCollectionExtensions.Registration.cs index 836f9dea78..3eea272d8a 100644 --- a/src/core/DSharpPlus.Internal.Models/Extensions/ServiceCollectionExtensions.Registration.cs +++ b/src/core/DSharpPlus.Internal.Models/Extensions/ServiceCollectionExtensions.Registration.cs @@ -53,6 +53,27 @@ private static void RegisterSerialization(IServiceCollection services) options.AddModel(); options.AddModel(); options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); + options.AddModel(); options.AddModel(); options.AddModel(); options.AddModel(); @@ -63,6 +84,7 @@ private static void RegisterSerialization(IServiceCollection services) options.AddModel(); options.AddModel(); options.AddModel(); + options.AddModel(); options.AddModel(); options.AddModel(); options.AddModel(); @@ -90,18 +112,6 @@ private static void RegisterSerialization(IServiceCollection services) options.AddModel(); options.AddModel(); options.AddModel(); - options.AddModel(); - options.AddModel(); - options.AddModel(); - options.AddModel(); - options.AddModel(); - options.AddModel(); - options.AddModel(); - options.AddModel(); - options.AddModel(); - options.AddModel(); - options.AddModel(); - options.AddModel(); options.AddModel(); options.AddModel(); options.AddModel(); diff --git a/src/core/DSharpPlus.Internal.Models/Extensions/ServiceCollectionExtensions.cs b/src/core/DSharpPlus.Internal.Models/Extensions/ServiceCollectionExtensions.cs index 2382a3a8eb..f27d9574da 100644 --- a/src/core/DSharpPlus.Internal.Models/Extensions/ServiceCollectionExtensions.cs +++ b/src/core/DSharpPlus.Internal.Models/Extensions/ServiceCollectionExtensions.cs @@ -6,7 +6,6 @@ using System.Text.Json; -using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Internal.Models.Serialization.Converters; using DSharpPlus.Internal.Models.Serialization.Resolvers; using DSharpPlus.Serialization; diff --git a/src/core/DSharpPlus.Internal.Models/Guilds/Guild.cs b/src/core/DSharpPlus.Internal.Models/Guilds/Guild.cs index 89845799b0..68eaab0533 100644 --- a/src/core/DSharpPlus.Internal.Models/Guilds/Guild.cs +++ b/src/core/DSharpPlus.Internal.Models/Guilds/Guild.cs @@ -137,4 +137,7 @@ public sealed record Guild : IGuild /// public Snowflake? SafetyAlertsChannelId { get; init; } + + /// + public IIncidentsData? IncidentsData { get; init; } } \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Models/Guilds/GuildMember.cs b/src/core/DSharpPlus.Internal.Models/Guilds/GuildMember.cs index 8180618c8a..476820816e 100644 --- a/src/core/DSharpPlus.Internal.Models/Guilds/GuildMember.cs +++ b/src/core/DSharpPlus.Internal.Models/Guilds/GuildMember.cs @@ -22,6 +22,9 @@ public sealed record GuildMember : IGuildMember /// public Optional Avatar { get; init; } + /// + public Optional Banner { get; init; } + /// public required IReadOnlyList Roles { get; init; } diff --git a/src/core/DSharpPlus.Internal.Models/Guilds/IncidentsData.cs b/src/core/DSharpPlus.Internal.Models/Guilds/IncidentsData.cs new file mode 100644 index 0000000000..bd0706c647 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Models/Guilds/IncidentsData.cs @@ -0,0 +1,25 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; + +using DSharpPlus.Internal.Abstractions.Models; + +namespace DSharpPlus.Internal.Models; + +/// +public sealed record IncidentsData : IIncidentsData +{ + /// + public DateTimeOffset? InvitesDisabledUntil { get; init; } + + /// + public DateTimeOffset? DmsDisabledUntil { get; init; } + + /// + public Optional DmSpamDetectedAt { get; init; } + + /// + public Optional RaidDetectedAt { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Models/Guilds/PartialGuild.cs b/src/core/DSharpPlus.Internal.Models/Guilds/PartialGuild.cs index 2860f20e4d..e60323468b 100644 --- a/src/core/DSharpPlus.Internal.Models/Guilds/PartialGuild.cs +++ b/src/core/DSharpPlus.Internal.Models/Guilds/PartialGuild.cs @@ -137,4 +137,7 @@ public sealed record PartialGuild : IPartialGuild /// public Optional SafetyAlertsChannelId { get; init; } + + /// + public Optional IncidentsData { get; init; } } \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Models/Guilds/PartialGuildMember.cs b/src/core/DSharpPlus.Internal.Models/Guilds/PartialGuildMember.cs index 2a17dd7eef..e69a3b3338 100644 --- a/src/core/DSharpPlus.Internal.Models/Guilds/PartialGuildMember.cs +++ b/src/core/DSharpPlus.Internal.Models/Guilds/PartialGuildMember.cs @@ -22,6 +22,9 @@ public sealed record PartialGuildMember : IPartialGuildMember /// public Optional Avatar { get; init; } + /// + public Optional Banner { get; init; } + /// public Optional> Roles { get; init; } diff --git a/src/core/DSharpPlus.Internal.Models/Interactions/Interaction.cs b/src/core/DSharpPlus.Internal.Models/Interactions/Interaction.cs index 95283d6ec0..83d3891a51 100644 --- a/src/core/DSharpPlus.Internal.Models/Interactions/Interaction.cs +++ b/src/core/DSharpPlus.Internal.Models/Interactions/Interaction.cs @@ -70,4 +70,7 @@ public sealed record Interaction : IInteraction /// public Optional Context { get; init; } + + /// + public required int AttachmentSizeLimit { get; init; } } \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Models/Messages/AllowedMentions.cs b/src/core/DSharpPlus.Internal.Models/Messages/AllowedMentions.cs index 2e75c35dd4..39325b0bda 100644 --- a/src/core/DSharpPlus.Internal.Models/Messages/AllowedMentions.cs +++ b/src/core/DSharpPlus.Internal.Models/Messages/AllowedMentions.cs @@ -12,7 +12,7 @@ namespace DSharpPlus.Internal.Models; public sealed record AllowedMentions : IAllowedMentions { /// - public required IReadOnlyList Parse { get; init; } + public Optional> Parse { get; init; } /// public Optional> Roles { get; init; } diff --git a/src/core/DSharpPlus.Internal.Models/Serialization/Converters/ComponentConverter.cs b/src/core/DSharpPlus.Internal.Models/Serialization/Converters/ComponentConverter.cs index 3114678b0f..1545cc48b3 100644 --- a/src/core/DSharpPlus.Internal.Models/Serialization/Converters/ComponentConverter.cs +++ b/src/core/DSharpPlus.Internal.Models/Serialization/Converters/ComponentConverter.cs @@ -38,29 +38,21 @@ JsonSerializerOptions options IComponent? component = (DiscordMessageComponentType)type switch { - DiscordMessageComponentType.ActionRow - => document.Deserialize(options), - - DiscordMessageComponentType.Button - => document.Deserialize(options), - - DiscordMessageComponentType.StringSelect - => document.Deserialize(options), - - DiscordMessageComponentType.TextInput - => document.Deserialize(options), - - DiscordMessageComponentType.UserSelect - => document.Deserialize(options), - - DiscordMessageComponentType.RoleSelect - => document.Deserialize(options), - - DiscordMessageComponentType.MentionableSelect - => document.Deserialize(options), - - DiscordMessageComponentType.ChannelSelect - => document.Deserialize(options), + DiscordMessageComponentType.ActionRow => document.Deserialize(options), + DiscordMessageComponentType.Button => document.Deserialize(options), + DiscordMessageComponentType.StringSelect => document.Deserialize(options), + DiscordMessageComponentType.TextInput => document.Deserialize(options), + DiscordMessageComponentType.UserSelect => document.Deserialize(options), + DiscordMessageComponentType.RoleSelect => document.Deserialize(options), + DiscordMessageComponentType.MentionableSelect => document.Deserialize(options), + DiscordMessageComponentType.ChannelSelect => document.Deserialize(options), + DiscordMessageComponentType.Section => document.Deserialize(options), + DiscordMessageComponentType.TextDisplay => document.Deserialize(options), + DiscordMessageComponentType.Thumbnail => document.Deserialize(options), + DiscordMessageComponentType.MediaGallery => document.Deserialize(options), + DiscordMessageComponentType.File => document.Deserialize(options), + DiscordMessageComponentType.Separator => document.Deserialize(options), + DiscordMessageComponentType.Container => document.Deserialize(options), _ => new UnknownComponent { diff --git a/src/core/DSharpPlus.Internal.Models/Serialization/Converters/DiscordPermissionConverter.cs b/src/core/DSharpPlus.Internal.Models/Serialization/Converters/DiscordPermissionConverter.cs index f9607204d9..dca010b60a 100644 --- a/src/core/DSharpPlus.Internal.Models/Serialization/Converters/DiscordPermissionConverter.cs +++ b/src/core/DSharpPlus.Internal.Models/Serialization/Converters/DiscordPermissionConverter.cs @@ -5,8 +5,6 @@ #pragma warning disable IDE0072 using System; -using System.Buffers; -using System.Globalization; using System.Numerics; using System.Text.Json; using System.Text.Json.Serialization; diff --git a/src/core/DSharpPlus.Internal.Models/Serialization/Resolvers/AttachmentDataTypeInfoResolver.cs b/src/core/DSharpPlus.Internal.Models/Serialization/Resolvers/AttachmentDataTypeInfoResolver.cs index 03072c4b91..e1f9442135 100644 --- a/src/core/DSharpPlus.Internal.Models/Serialization/Resolvers/AttachmentDataTypeInfoResolver.cs +++ b/src/core/DSharpPlus.Internal.Models/Serialization/Resolvers/AttachmentDataTypeInfoResolver.cs @@ -2,7 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using System; using System.Collections.Generic; using System.Text.Json.Serialization.Metadata; diff --git a/src/core/DSharpPlus.Internal.Models/Subscriptions/Subscription.cs b/src/core/DSharpPlus.Internal.Models/Subscriptions/Subscription.cs index af98f710c9..917b65c9eb 100644 --- a/src/core/DSharpPlus.Internal.Models/Subscriptions/Subscription.cs +++ b/src/core/DSharpPlus.Internal.Models/Subscriptions/Subscription.cs @@ -25,6 +25,9 @@ public sealed record Subscription : ISubscription /// public required IReadOnlyList EntitlementIds { get; init; } + /// + public IReadOnlyList? RenewalSkuIds { get; init; } + /// public required DateTimeOffset CurrentPeriodStart { get; init; } diff --git a/src/core/DSharpPlus.Internal.Rest/API/GuildRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/GuildRestAPI.cs index a1b43c2bb5..592fd9c65b 100644 --- a/src/core/DSharpPlus.Internal.Rest/API/GuildRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Rest/API/GuildRestAPI.cs @@ -133,34 +133,6 @@ public async ValueTask> BeginGuildPruneAsync ); } - /// - public async ValueTask> CreateGuildAsync - ( - ICreateGuildPayload payload, - RequestInfo info = default, - CancellationToken ct = default - ) - { - if (payload.Name.Length is < 2 or > 100) - { - return new ValidationError("The name of a guild must be between 2 and 100 characters long."); - } - - if (payload.AfkTimeout.HasValue && payload.AfkTimeout.Value is not (60 or 300 or 900 or 1800 or 3600)) - { - return new ValidationError("The AFK timeout of a guild must be either 60, 300, 900, 1800 or 3600 seconds."); - } - - return await restClient.ExecuteRequestAsync - ( - HttpMethod.Post, - $"guilds", - b => b.WithPayload(payload), - info, - ct - ); - } - /// public async ValueTask> CreateGuildChannelAsync ( @@ -1130,4 +1102,24 @@ public async ValueTask> GetGuildRoleAsync ct ); } + + /// + public async ValueTask> ModifyGuildIncidentActionsAsync + ( + Snowflake guildId, + IModifyGuildIncidentActionsPayload payload, + RequestInfo info = default, + CancellationToken ct = default + ) + { + return await restClient.ExecuteRequestAsync + ( + HttpMethod.Put, + $"guilds/{guildId}/incident-actions", + b => b.WithSimpleRoute(TopLevelResource.Guild, guildId) + .WithPayload(payload), + info, + ct + ); + } } diff --git a/src/core/DSharpPlus.Internal.Rest/API/WebhookRestAPI.cs b/src/core/DSharpPlus.Internal.Rest/API/WebhookRestAPI.cs index 547c00208e..326e8dca65 100644 --- a/src/core/DSharpPlus.Internal.Rest/API/WebhookRestAPI.cs +++ b/src/core/DSharpPlus.Internal.Rest/API/WebhookRestAPI.cs @@ -147,7 +147,7 @@ public async ValueTask> EditWebhookMessageAsync string webhookToken, Snowflake messageId, IEditWebhookMessagePayload payload, - ThreadIdQuery query = default, + EditWebhookMessageQuery query = default, RequestInfo info = default, CancellationToken ct = default ) @@ -174,6 +174,11 @@ public async ValueTask> EditWebhookMessageAsync _ = builder.AddParameter("thread_id", query.ThreadId.Value.ToString()); } + if (query.WithComponents is not null) + { + _ = builder.AddParameter("with_components", query.WithComponents.Value.ToString().ToLowerInvariant()); + } + return await restClient.ExecuteRequestAsync ( HttpMethod.Patch, @@ -238,6 +243,11 @@ public async ValueTask> ExecuteWebhookAsync _ = builder.AddParameter("wait", query.Wait.Value.ToString().ToLowerInvariant()); } + if (query.WithComponents is not null) + { + _ = builder.AddParameter("with_components", query.WithComponents.Value.ToString().ToLowerInvariant()); + } + if (query.Wait == true) { #pragma warning disable CS8619 // Nullability of reference types in value doesn't match target type. diff --git a/src/core/DSharpPlus.Internal.Rest/Extensions/ServiceCollectionExtensions.Registration.cs b/src/core/DSharpPlus.Internal.Rest/Extensions/ServiceCollectionExtensions.Registration.cs index 9a2d7e4b0f..b0d0045c8a 100644 --- a/src/core/DSharpPlus.Internal.Rest/Extensions/ServiceCollectionExtensions.Registration.cs +++ b/src/core/DSharpPlus.Internal.Rest/Extensions/ServiceCollectionExtensions.Registration.cs @@ -51,6 +51,7 @@ private static void RegisterSerialization(IServiceCollection services) options.AddModel(); options.AddModel(); options.AddModel(); + options.AddModel(); options.AddModel(); options.AddModel(); options.AddModel(); @@ -71,6 +72,7 @@ private static void RegisterSerialization(IServiceCollection services) options.AddModel(); options.AddModel(); options.AddModel(); + options.AddModel(); options.AddModel(); options.AddModel(); options.AddModel(); diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyGuildIncidentActionsPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyGuildIncidentActionsPayload.cs new file mode 100644 index 0000000000..6f606bdcbf --- /dev/null +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Guilds/ModifyGuildIncidentActionsPayload.cs @@ -0,0 +1,19 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; + +using DSharpPlus.Internal.Abstractions.Rest.Payloads; + +namespace DSharpPlus.Internal.Rest.Payloads; + +/// +public sealed record ModifyGuildIncidentActionsPayload : IModifyGuildIncidentActionsPayload +{ + /// + public Optional InvitesDisabledUntil { get; init; } + + /// + public Optional DmsDisabledUntil { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Soundboard/SendSoundboardSoundPayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Soundboard/SendSoundboardSoundPayload.cs new file mode 100644 index 0000000000..ae44451297 --- /dev/null +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Soundboard/SendSoundboardSoundPayload.cs @@ -0,0 +1,17 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DSharpPlus.Internal.Abstractions.Rest.Payloads; + +namespace DSharpPlus.Internal.Rest.Payloads; + +/// +public sealed record SendSoundboardSoundPayload : ISendSoundboardSoundPayload +{ + /// + public required Snowflake SoundId { get; init; } + + /// + public Optional SourceGuildId { get; init; } +} \ No newline at end of file diff --git a/src/core/DSharpPlus.Internal.Rest/Payloads/Webhooks/EditWebhookMessagePayload.cs b/src/core/DSharpPlus.Internal.Rest/Payloads/Webhooks/EditWebhookMessagePayload.cs index ffbb15de00..2a7acc0ccc 100644 --- a/src/core/DSharpPlus.Internal.Rest/Payloads/Webhooks/EditWebhookMessagePayload.cs +++ b/src/core/DSharpPlus.Internal.Rest/Payloads/Webhooks/EditWebhookMessagePayload.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; +using DSharpPlus.Entities; using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Internal.Abstractions.Rest.Payloads; @@ -18,6 +19,9 @@ public sealed record EditWebhookMessagePayload : IEditWebhookMessagePayload /// public Optional?> Embeds { get; init; } + /// + public Optional Flags { get; init; } + /// public Optional AllowedMentions { get; init; } diff --git a/src/core/DSharpPlus.Shared/DSharpPlus.Shared.csproj b/src/core/DSharpPlus.Shared/DSharpPlus.Shared.csproj index c834d118ba..cd32215efa 100644 --- a/src/core/DSharpPlus.Shared/DSharpPlus.Shared.csproj +++ b/src/core/DSharpPlus.Shared/DSharpPlus.Shared.csproj @@ -21,4 +21,8 @@ + + + + diff --git a/src/core/DSharpPlus.Shared/Entities/MessageComponents/DiscordButtonStyle.cs b/src/core/DSharpPlus.Shared/Entities/Components/DiscordButtonStyle.cs similarity index 100% rename from src/core/DSharpPlus.Shared/Entities/MessageComponents/DiscordButtonStyle.cs rename to src/core/DSharpPlus.Shared/Entities/Components/DiscordButtonStyle.cs diff --git a/src/core/DSharpPlus.Shared/Entities/MessageComponents/DiscordMessageComponentType.cs b/src/core/DSharpPlus.Shared/Entities/Components/DiscordMessageComponentType.cs similarity index 58% rename from src/core/DSharpPlus.Shared/Entities/MessageComponents/DiscordMessageComponentType.cs rename to src/core/DSharpPlus.Shared/Entities/Components/DiscordMessageComponentType.cs index 7596ae388d..2baa453f4b 100644 --- a/src/core/DSharpPlus.Shared/Entities/MessageComponents/DiscordMessageComponentType.cs +++ b/src/core/DSharpPlus.Shared/Entities/Components/DiscordMessageComponentType.cs @@ -47,5 +47,40 @@ public enum DiscordMessageComponentType /// /// A select menu for picking from channels. /// - ChannelSelect + ChannelSelect, + + /// + /// A container to display text alongside an accessory component (button or thumbnail). + /// + Section, + + /// + /// A component containing markdown text. + /// + TextDisplay, + + /// + /// A small image that can be used as an accessory for a . + /// + Thumbnail, + + /// + /// A component displaying media items. + /// + MediaGallery, + + /// + /// A component displaying an attached file. + /// + File, + + /// + /// A component to add vertical padding and/or display a vertical line between other components. + /// + Separator, + + /// + /// A container that visually groups components, akin to an embed. + /// + Container = 17 } diff --git a/src/core/DSharpPlus.Shared/Entities/Components/DiscordSeparatorSpacingSize.cs b/src/core/DSharpPlus.Shared/Entities/Components/DiscordSeparatorSpacingSize.cs new file mode 100644 index 0000000000..c0d1b0c5eb --- /dev/null +++ b/src/core/DSharpPlus.Shared/Entities/Components/DiscordSeparatorSpacingSize.cs @@ -0,0 +1,21 @@ +// This Source Code form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace DSharpPlus.Entities; + +/// +/// Represents the spacing size for a separator. +/// +public enum DiscordSeparatorSpacingSize +{ + /// + /// 17px, or about one line of text, worth of space. + /// + Small = 1, + + /// + /// 33px, or about two lines of text, worth of space. + /// + Large +} diff --git a/src/core/DSharpPlus.Shared/Entities/MessageComponents/DiscordTextInputStyle.cs b/src/core/DSharpPlus.Shared/Entities/Components/DiscordTextInputStyle.cs similarity index 100% rename from src/core/DSharpPlus.Shared/Entities/MessageComponents/DiscordTextInputStyle.cs rename to src/core/DSharpPlus.Shared/Entities/Components/DiscordTextInputStyle.cs diff --git a/src/core/DSharpPlus.Shared/Entities/DiscordPermissions.Enumeration.cs b/src/core/DSharpPlus.Shared/Entities/DiscordPermissions.Enumeration.cs index 6b7e711584..770f2dbbd3 100644 --- a/src/core/DSharpPlus.Shared/Entities/DiscordPermissions.Enumeration.cs +++ b/src/core/DSharpPlus.Shared/Entities/DiscordPermissions.Enumeration.cs @@ -9,6 +9,7 @@ using System.Collections.Generic; using System.Numerics; using System.Runtime.CompilerServices; + using CommunityToolkit.HighPerformance.Helpers; namespace DSharpPlus.Entities; diff --git a/src/core/DSharpPlus.Shared/Entities/Messages/DiscordMessageFlags.cs b/src/core/DSharpPlus.Shared/Entities/Messages/DiscordMessageFlags.cs index dff7961cda..47844e8d60 100644 --- a/src/core/DSharpPlus.Shared/Entities/Messages/DiscordMessageFlags.cs +++ b/src/core/DSharpPlus.Shared/Entities/Messages/DiscordMessageFlags.cs @@ -67,5 +67,15 @@ public enum DiscordMessageFlags /// /// This message is a voice message. /// - IsVoiceMessage = 1 << 13 + IsVoiceMessage = 1 << 13, + + /// + /// This message contains a message snapshot, via forwarding. + /// + HasSnapshot = 1 << 14, + + /// + /// This message contains layout components and does not contain content, embeds, polls or stickers. + /// + EnableLayoutComponents = 1 << 15, } diff --git a/src/core/DSharpPlus.Shared/InlineMediaData.cs b/src/core/DSharpPlus.Shared/InlineMediaData.cs index 38ab1b6410..9d8fc9a543 100644 --- a/src/core/DSharpPlus.Shared/InlineMediaData.cs +++ b/src/core/DSharpPlus.Shared/InlineMediaData.cs @@ -24,6 +24,7 @@ public readonly record struct InlineMediaData private static ReadOnlySpan JpegString => "data:image/jpeg;base64,"u8; private static ReadOnlySpan GifString => "data:image/gif;base64,"u8; private static ReadOnlySpan WebpString => "data:image/webp;base64,"u8; + private static ReadOnlySpan AvifString => "data:image/avif;base64,"u8; private static ReadOnlySpan OggString => "data:audio/ogg;base64,"u8; private static ReadOnlySpan Mp3String => "data:audio/mpeg;base64,"u8; private static ReadOnlySpan AutoString => "data:image/auto;base64,"u8; @@ -79,6 +80,7 @@ public readonly void WriteTo(ArrayPoolBufferWriter writer) MediaFormat.Gif => GifString, MediaFormat.Jpeg => JpegString, MediaFormat.WebP => WebpString, + MediaFormat.Avif => AvifString, MediaFormat.Ogg => OggString, MediaFormat.Mp3 => Mp3String, _ => AutoString diff --git a/src/core/DSharpPlus.Shared/MediaFormat.cs b/src/core/DSharpPlus.Shared/MediaFormat.cs index 731ae06e6f..cee3478ca6 100644 --- a/src/core/DSharpPlus.Shared/MediaFormat.cs +++ b/src/core/DSharpPlus.Shared/MediaFormat.cs @@ -13,6 +13,7 @@ public enum MediaFormat Gif, Jpeg, WebP, + Avif, Ogg, Mp3, Auto, diff --git a/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Builders/Interactions/TextInputComponentBuilder.cs b/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Builders/Interactions/TextInputComponentBuilder.cs index 6c9a5ac0df..2d15030f41 100644 --- a/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Builders/Interactions/TextInputComponentBuilder.cs +++ b/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Builders/Interactions/TextInputComponentBuilder.cs @@ -11,7 +11,6 @@ using DSharpPlus.Entities; using DSharpPlus.Extensions.Internal.Toolbox.Errors; using DSharpPlus.Extensions.Internal.Toolbox.Implementations; -using DSharpPlus.Internal.Abstractions.Models; using DSharpPlus.Results; namespace DSharpPlus.Extensions.Internal.Builders.Interactions; diff --git a/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Implementations/BuiltTextInputComponent.cs b/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Implementations/BuiltTextInputComponent.cs index e636cc1b34..4aa1e3ee50 100644 --- a/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Implementations/BuiltTextInputComponent.cs +++ b/src/extensions/DSharpPlus.Extensions.Internal.Toolbox/Implementations/BuiltTextInputComponent.cs @@ -3,7 +3,6 @@ // file, You can obtain one at https://mozilla.org/MPL/2.0/. using DSharpPlus.Entities; -using DSharpPlus.Internal.Abstractions.Models; namespace DSharpPlus.Extensions.Internal.Toolbox.Implementations;