diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f0567f0f9..0801d58b9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,26 +1,28 @@ -name: "Build" +name: "Build Library" + on: push: pull_request: workflow_dispatch: + jobs: build: strategy: matrix: os: [ubuntu-latest, macos-latest, windows-latest] - dotnet: [6.0.400] + dotnet: [6.x] runs-on: ${{ matrix.os }} name: Build library steps: - name: Checkout repository uses: actions/checkout@v3 - name: Setup .NET uses: actions/setup-dotnet@v3.0.3 with: dotnet-version: ${{ matrix.dotnet }} - name: Restore dependencies run: dotnet restore - name: Build library run: dotnet build -c Release - name: Test library run: dotnet test --verbosity normal -c Release diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index e6eddcb70..7549a1c1d 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -1,32 +1,34 @@ name: "CodeQL" + on: push: branches: [ main ] pull_request: branches: [ main ] schedule: - cron: '39 18 * * 3' workflow_dispatch: + jobs: analyze: name: Analyze - runs-on: [ubuntu-latest] + runs-on: ubuntu-latest permissions: actions: read contents: read security-events: write strategy: fail-fast: false matrix: language: [ 'csharp' ] steps: - name: Checkout repository uses: actions/checkout@v3 - name: Initialize CodeQL uses: github/codeql-action/init@v2 with: languages: ${{ matrix.language }} - name: Autobuild uses: github/codeql-action/autobuild@v2 - name: Perform CodeQL Analysis uses: github/codeql-action/analyze@v2 diff --git a/.github/workflows/documentation.yml b/.github/workflows/documentation.yml index d5a21a8e6..9eb82982a 100644 --- a/.github/workflows/documentation.yml +++ b/.github/workflows/documentation.yml @@ -1,114 +1,112 @@ name: "Documentation" on: - push: - branches: [ main ] workflow_dispatch: env: DOTNET_NOLOGO: true DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true DOTNET_CLI_TELEMETRY_OPTOUT: true jobs: build: runs-on: ubuntu-latest name: Build documentation steps: - name: Checkout repository uses: actions/checkout@v3 with: token: ${{ secrets.NYUW_TOKEN_GH }} - name: Setup .NET uses: actions/setup-dotnet@v3.0.3 with: dotnet-version: 6.x - name: Git fetch unshallow run: git fetch --unshallow - name: Restore packages run: dotnet restore - name: Build library run: dotnet build -c Release continue-on-error: true - name: Build Docs shell: pwsh run: ./rebuild-docs.ps1 -DocsPath "./DisCatSharp.Docs" -Output "." -PackageName "dcs-docs" - name: Upload packed docs uses: actions/upload-artifact@v3 with: name: dcs-docs.zip path: dcs-docs.zip retention-days: 30 - name: Force add build files run: git add DisCatSharp.Docs/obj/.cache/build/* -f - name: Commit and push changes uses: EndBug/add-and-commit@main with: default_author: user_info author_name: NyuwBot author_email: nyuw@aitsys.dev committer_name: NyuwBot committer_email: nyuw@aitsys.dev commit: --signoff message: '[ci skip] Sync docs changes' tag_push: '--force' documentation: runs-on: ubuntu-latest name: Upload documentation needs: build steps: - name: Checkout docs repository uses: actions/checkout@v3 with: repository: Aiko-IT-Systems/DisCatSharp.Docs token: ${{ secrets.NYUW_TOKEN_GH }} - name: Purge old docs shell: pwsh run: Get-ChildItem -Exclude .git* | Remove-Item -Recurse -Force - name: Download packed docs uses: actions/download-artifact@v3 with: name: dcs-docs.zip - name: Extract new docs run: unzip dcs-docs.zip -d . - name: Deleze zip run: rm dcs-docs.zip - name: Delete packed docs uses: geekyeggo/delete-artifact@v2 with: name: dcs-docs.zip - name: Set access rights run: sudo chmod 777 -R . - name: Commit and push changes uses: EndBug/add-and-commit@main with: default_author: user_info author_name: NyuwBot author_email: nyuw@aitsys.dev committer_name: NyuwBot committer_email: nyuw@aitsys.dev commit: --signoff message: 'Docs update for https://github.com/${{github.repository}}/commit/${{github.sha}}' publish-main: runs-on: ubuntu-latest name: Publish documentation on main server needs: documentation steps: - name: Get SSH Agent uses: webfactory/ssh-agent@v0.7.0 with: ssh-private-key: ${{ secrets.AITSYS_SSH }} - name: Publish on server continue-on-error: true run: ssh -o StrictHostKeyChecking=no -T root@80.153.182.68 -f 'cd /var/www/dcs.aitsys.dev/docs && git pull -f && service apache2 restart' publish-backup: runs-on: ubuntu-latest name: Publish documentation on backup server needs: documentation steps: - name: Get SSH Agent uses: webfactory/ssh-agent@v0.7.0 with: ssh-private-key: ${{ secrets.AITSYS_SSH }} - name: Publish on server continue-on-error: true run: ssh -o StrictHostKeyChecking=no -T root@207.180.240.241 -f 'cd /var/www/dcsdocs && git pull -f && service apache2 restart' diff --git a/.github/workflows/documentation_test.yml b/.github/workflows/documentation_test.yml index 5e0505299..05011da80 100644 --- a/.github/workflows/documentation_test.yml +++ b/.github/workflows/documentation_test.yml @@ -1,42 +1,38 @@ name: "Test Documentation" on: workflow_dispatch: env: DOTNET_NOLOGO: true DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true DOTNET_CLI_TELEMETRY_OPTOUT: true jobs: build: runs-on: ubuntu-latest name: Build documentation steps: - name: Checkout repository uses: actions/checkout@v3 with: - path: DisCatSharp + token: ${{ secrets.NYUW_TOKEN_GH }} - name: Setup .NET uses: actions/setup-dotnet@v3.0.3 with: - dotnet-version: 6.0.400 + dotnet-version: 6.x + - name: Git fetch unshallow + run: git fetch --unshallow - name: Restore packages - working-directory: DisCatSharp run: dotnet restore - name: Build library - working-directory: DisCatSharp run: dotnet build -c Release - - name: Test library - working-directory: DisCatSharp - run: dotnet test -c Release continue-on-error: true - name: Build Docs - working-directory: DisCatSharp shell: pwsh - run: ./rebuild-docs.ps1 -DocsPath "./DisCatSharp.Docs" -Output ".." -PackageName "dcs-docs" + run: ./rebuild-docs.ps1 -DocsPath "./DisCatSharp.Docs" -Output "." -PackageName "dcs-docs" - name: Upload packed docs uses: actions/upload-artifact@v3 with: name: dcs-docs.zip path: dcs-docs.zip retention-days: 30 diff --git a/.github/workflows/labeler.yml b/.github/workflows/labeler.yml index 95b8a431f..9bca49f8c 100644 --- a/.github/workflows/labeler.yml +++ b/.github/workflows/labeler.yml @@ -1,13 +1,15 @@ -name: Label PRs +name: "Label PRs" + on: pull_request_target: types: - opened + jobs: label: runs-on: ubuntu-latest name: Label PRs steps: - uses: srvaroa/labeler@v0.9 env: GITHUB_TOKEN: "${{ secrets.NYUW_TOKEN_GH }}" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 4c1532aaf..c1ea138fc 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,47 +1,47 @@ name: "Release DisCatSharp" on: workflow_dispatch: inputs: version_suffix: description: "Version Suffix" required: false type: string release_as_prerelease: description: "Release as pre-release" required: true type: boolean jobs: release: runs-on: windows-latest name: Build library and release steps: - name: Checkout repository uses: actions/checkout@v3 - name: Setup .NET uses: actions/setup-dotnet@v3.0.3 with: - dotnet-version: 6.0.400 + dotnet-version: 6.x - name: Restore dependencies run: dotnet restore - name: Build library as full release if: ${{!inputs.release_as_prerelease}} shell: pwsh run: .\rebuild-lib.ps1 -ArtifactLocation ../dcs-artifacts -Configuration Release - name: Build library as pre-release if: ${{inputs.release_as_prerelease}} shell: pwsh run: .\rebuild-lib.ps1 -ArtifactLocation ../dcs-artifacts -Configuration Release -VersionSuffix ${{github.event.inputs.version_suffix}} - name: Remove invalid packages shell: pwsh run: rm *.symbols.* working-directory: ../dcs-artifacts - name: Publish to NuGet shell: pwsh run: dotnet nuget push --source https://api.nuget.org/v3/index.json -k ${{secrets.NUGET_API_KEY}} * --skip-duplicate working-directory: ../dcs-artifacts - name: Publish to GitHub Packages shell: pwsh run: dotnet nuget push --source https://nuget.pkg.github.com/Aiko-IT-Systems/index.json -k ${{secrets.NYUW_TOKEN_GH}} * working-directory: ../dcs-artifacts diff --git a/.github/workflows/typos.yml b/.github/workflows/typos.yml index 2e1a0ac62..b2f2418ab 100644 --- a/.github/workflows/typos.yml +++ b/.github/workflows/typos.yml @@ -1,14 +1,16 @@ -name: Typo check +name: "Check Typos" + on: push: pull_request: workflow_dispatch: + jobs: run: name: Spell Check with Typos runs-on: ubuntu-latest steps: - name: Checkout Actions Repository uses: actions/checkout@v3 - name: Check spelling of repo uses: crate-ci/typos@master diff --git a/DisCatSharp/Entities/Channel/DiscordDmChannel.cs b/DisCatSharp/Entities/Channel/DiscordDmChannel.cs index 4b872ebdf..a164a23eb 100644 --- a/DisCatSharp/Entities/Channel/DiscordDmChannel.cs +++ b/DisCatSharp/Entities/Channel/DiscordDmChannel.cs @@ -1,93 +1,93 @@ // This file is part of the DisCatSharp project, based off DSharpPlus. // // Copyright (c) 2021-2022 AITSYS // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in all // copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. using System.Collections.Generic; using System.Globalization; using System.Threading.Tasks; using DisCatSharp.Enums; using DisCatSharp.Exceptions; using DisCatSharp.Net; using Newtonsoft.Json; namespace DisCatSharp.Entities; /// /// Represents a direct message channel. /// public class DiscordDmChannel : DiscordChannel { /// /// Gets the recipients of this direct message. /// [JsonProperty("recipients", NullValueHandling = NullValueHandling.Ignore)] public IReadOnlyList Recipients { get; internal set; } /// /// Gets the hash of this channel's icon. /// [JsonProperty("icon", NullValueHandling = NullValueHandling.Ignore)] public string IconHash { get; internal set; } /// /// Gets the id of this direct message's creator. /// [JsonProperty("owner_id", NullValueHandling = NullValueHandling.Ignore)] public ulong OwnerId { get; internal set; } /// /// Gets the application id of the direct message's creator if it a bot. /// [JsonProperty("application_id", NullValueHandling = NullValueHandling.Ignore)] - public ulong ApplicationId { get; internal set; } + public ulong? ApplicationId { get; internal set; } /// /// Gets the URL of this channel's icon. /// [JsonIgnore] public string IconUrl => !string.IsNullOrWhiteSpace(this.IconHash) ? $"{DiscordDomain.GetDomain(CoreDomain.DiscordCdn).Url}{Endpoints.CHANNEL_ICONS}/{this.Id.ToString(CultureInfo.InvariantCulture)}/{this.IconHash}.png" : null; /// /// Only use for Group DMs! Whitelisted bots only. Requires user's oauth2 access token. /// /// The id of the user to add. /// The OAuth2 access token. /// The nickname to give to the user. /// Thrown when the channel does not exist. /// Thrown when an invalid parameter was provided. /// Thrown when Discord is unable to process the request. public Task AddDmRecipientAsync(ulong userId, string accessToken, string nickname) => this.Discord.ApiClient.AddGroupDmRecipientAsync(this.Id, userId, accessToken, nickname); /// /// Only use for Group DMs! Whitelisted bots only. Requires user's oauth2 access token. /// /// The id of the User to remove. /// The OAuth2 access token. /// Thrown when the channel does not exist. /// Thrown when an invalid parameter was provided. /// Thrown when Discord is unable to process the request. public Task RemoveDmRecipientAsync(ulong userId, string accessToken) => this.Discord.ApiClient.RemoveGroupDmRecipientAsync(this.Id, userId); } diff --git a/DisCatSharp/Entities/Channel/Overwrite/DiscordOverwrite.cs b/DisCatSharp/Entities/Channel/Overwrite/DiscordOverwrite.cs index 75db006c6..f8a017b18 100644 --- a/DisCatSharp/Entities/Channel/Overwrite/DiscordOverwrite.cs +++ b/DisCatSharp/Entities/Channel/Overwrite/DiscordOverwrite.cs @@ -1,157 +1,126 @@ // This file is part of the DisCatSharp project, based off DSharpPlus. // // Copyright (c) 2021-2022 AITSYS // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in all // copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. using System; using System.Threading.Tasks; using DisCatSharp.Enums; +using DisCatSharp.Exceptions; using Newtonsoft.Json; namespace DisCatSharp.Entities; /// /// Represents a permission overwrite for a channel. /// public class DiscordOverwrite : SnowflakeObject { /// /// Gets the type of the overwrite. Either "role" or "member". /// [JsonProperty("type", NullValueHandling = NullValueHandling.Ignore)] public OverwriteType Type { get; internal set; } /// /// Gets the allowed permission set. /// [JsonProperty("allow", NullValueHandling = NullValueHandling.Ignore)] public Permissions Allowed { get; internal set; } /// /// Gets the denied permission set. /// [JsonProperty("deny", NullValueHandling = NullValueHandling.Ignore)] public Permissions Denied { get; internal set; } [JsonIgnore] internal ulong ChannelId; #region Methods - -#pragma warning disable CS1574 // XML comment has cref attribute that could not be resolved -#pragma warning disable CS1574 // XML comment has cref attribute that could not be resolved -#pragma warning disable CS1574 // XML comment has cref attribute that could not be resolved -#pragma warning disable CS1574 // XML comment has cref attribute that could not be resolved -/// + + /// /// Deletes this channel overwrite. /// /// Reason as to why this overwrite gets deleted. /// Thrown when the client does not have the permission. /// Thrown when the overwrite does not exist. /// Thrown when an invalid parameter was provided. /// Thrown when Discord is unable to process the request. public Task DeleteAsync(string reason = null) => this.Discord.ApiClient.DeleteChannelPermissionAsync(this.ChannelId, this.Id, reason); -#pragma warning restore CS1574 // XML comment has cref attribute that could not be resolved -#pragma warning restore CS1574 // XML comment has cref attribute that could not be resolved -#pragma warning restore CS1574 // XML comment has cref attribute that could not be resolved -#pragma warning restore CS1574 // XML comment has cref attribute that could not be resolved - -#pragma warning disable CS1574 // XML comment has cref attribute that could not be resolved -#pragma warning disable CS1574 // XML comment has cref attribute that could not be resolved -#pragma warning disable CS1574 // XML comment has cref attribute that could not be resolved -#pragma warning disable CS1574 // XML comment has cref attribute that could not be resolved -/// + /// /// Updates this channel overwrite. /// /// Permissions that are allowed. /// Permissions that are denied. /// Reason as to why you made this change. /// Thrown when the client does not have the permission. /// Thrown when the overwrite does not exist. /// Thrown when an invalid parameter was provided. /// Thrown when Discord is unable to process the request. public Task UpdateAsync(Permissions? allow = null, Permissions? deny = null, string reason = null) -#pragma warning restore CS1574 // XML comment has cref attribute that could not be resolved -#pragma warning restore CS1574 // XML comment has cref attribute that could not be resolved -#pragma warning restore CS1574 // XML comment has cref attribute that could not be resolved -#pragma warning restore CS1574 // XML comment has cref attribute that could not be resolved => this.Discord.ApiClient.EditChannelPermissionsAsync(this.ChannelId, this.Id, allow ?? this.Allowed, deny ?? this.Denied, this.Type.ToString().ToLowerInvariant(), reason); - -#pragma warning disable CS1574 // XML comment has cref attribute that could not be resolved -#pragma warning disable CS1574 // XML comment has cref attribute that could not be resolved -#pragma warning disable CS1574 // XML comment has cref attribute that could not be resolved -#pragma warning disable CS1574 // XML comment has cref attribute that could not be resolved -/// + /// /// Gets the DiscordMember that is affected by this overwrite. /// /// The DiscordMember that is affected by this overwrite /// Thrown when the client does not have the permission. /// Thrown when the overwrite does not exist. /// Thrown when an invalid parameter was provided. /// Thrown when Discord is unable to process the request. public async Task GetMemberAsync() => this.Type != OverwriteType.Member ? throw new ArgumentException(nameof(this.Type), "This overwrite is for a role, not a member.") : await (await this.Discord.ApiClient.GetChannelAsync(this.ChannelId).ConfigureAwait(false)).Guild.GetMemberAsync(this.Id).ConfigureAwait(false); -#pragma warning restore CS1574 // XML comment has cref attribute that could not be resolved -#pragma warning restore CS1574 // XML comment has cref attribute that could not be resolved -#pragma warning restore CS1574 // XML comment has cref attribute that could not be resolved -#pragma warning restore CS1574 // XML comment has cref attribute that could not be resolved - -#pragma warning disable CS1574 // XML comment has cref attribute that could not be resolved -#pragma warning disable CS1574 // XML comment has cref attribute that could not be resolved -#pragma warning disable CS1574 // XML comment has cref attribute that could not be resolved -/// + /// /// Gets the DiscordRole that is affected by this overwrite. /// /// The DiscordRole that is affected by this overwrite /// Thrown when the role does not exist. /// Thrown when an invalid parameter was provided. /// Thrown when Discord is unable to process the request. public async Task GetRoleAsync() => this.Type != OverwriteType.Role ? throw new ArgumentException(nameof(this.Type), "This overwrite is for a member, not a role.") : (await this.Discord.ApiClient.GetChannelAsync(this.ChannelId).ConfigureAwait(false)).Guild.GetRole(this.Id); -#pragma warning restore CS1574 // XML comment has cref attribute that could not be resolved -#pragma warning restore CS1574 // XML comment has cref attribute that could not be resolved -#pragma warning restore CS1574 // XML comment has cref attribute that could not be resolved + #endregion /// /// Initializes a new instance of the class. /// internal DiscordOverwrite() { } /// /// Checks whether given permissions are allowed, denied, or not set. /// /// Permissions to check. /// Whether given permissions are allowed, denied, or not set. public PermissionLevel CheckPermission(Permissions permission) => (this.Allowed & permission) != 0 ? PermissionLevel.Allowed : (this.Denied & permission) != 0 ? PermissionLevel.Denied : PermissionLevel.Unset; }