Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V10 Updates #15

Merged
merged 16 commits into from
Mar 18, 2023
4 changes: 2 additions & 2 deletions .github/workflows/code_quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
with:
fetch-depth: 0
- name: 'Qodana Scan'
uses: JetBrains/qodana-action@v2022.2.3
uses: JetBrains/qodana-action@v2022.3.4

- uses: github/codeql-action/upload-sarif@v2
with:
Expand All @@ -26,4 +26,4 @@ jobs:
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ${{ runner.temp }}/qodana/results/report
destination_dir: ./
destination_dir: ./
43 changes: 22 additions & 21 deletions api/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,33 @@

package api

import "github.com/veteran-software/discord-api-wrapper/oauth2"
import "github.com/veteran-software/discord-api-wrapper/v10/oauth2"

// Application - an application which operates on Discord, commonly referred to as bots
//
//goland:noinspection SpellCheckingInspection
type Application struct {
ID Snowflake `json:"id"` // the id of the app
Name string `json:"name"` // the name of the app
Icon *string `json:"icon"` // the icon hash of the app
Description string `json:"description"` // the description of the app
RpcOrigins []string `json:"rpc_origins"` // an array of rpc origin urls, if rpc is enabled
BotPublic bool `json:"bot_public"` // when false only app owner can join the app's bot to guilds
BotRequireCodeGrant bool `json:"bot_require_code_grant"` // when true the app's bot will only join upon completion of the full oauth2 code grant flow
TermsOfServiceURL string `json:"terms_of_service_url,omitempty"` // the url of the app's terms of service
PrivacyPolicyURL string `json:"privacy_policy_url,omitempty"` // the url of the app's privacy policy
Owner User `json:"owner,omitempty"` // partial user object containing info on the owner of the application
VerifyKey string `json:"verify_key"` // the hex encoded key for verification in interactions and the GameSDK's GetTicket
Team *Team `json:"team"` // if the application belongs to a team, this will be a list of the members of that team
GuildID Snowflake `json:"guild_id,omitempty"` // if this application is a game sold on Discord, this field will be the guild to which it has been linked
PrimarySkuID Snowflake `json:"primary_sku_id"` // if this application is a game sold on Discord, this field will be the id of the "Game SKU" that is created, if exists
Slug string `json:"slug,omitempty"` // if this application is a game sold on Discord, this field will be the URL slug that links to the store page
CoverImage string `json:"cover_image,omitempty"` // the application's default rich presence invite cover image hash
Flags ApplicationFlags `json:"flags,omitempty"` // the application's public ApplicationFlags
Tags []string `json:"tags,omitempty"` // up to 5 tags describing the content and functionality of the application
InstallParams InstallParams `json:"install_params,omitempty"` // settings for the application's default in-app authorization link, if enabled
CustomInstallURL string `json:"custom_install_url,omitempty"` // the application's default custom authorization link, if enabled
ID Snowflake `json:"id"` // the id of the app
Name string `json:"name"` // the name of the app
Icon *string `json:"icon"` // the icon hash of the app
Description string `json:"description"` // the description of the app
RpcOrigins []string `json:"rpc_origins"` // an array of rpc origin urls, if rpc is enabled
BotPublic bool `json:"bot_public"` // when false only app owner can join the app's bot to guilds
BotRequireCodeGrant bool `json:"bot_require_code_grant"` // when true the app's bot will only join upon completion of the full oauth2 code grant flow
TermsOfServiceURL string `json:"terms_of_service_url,omitempty"` // the url of the app's terms of service
PrivacyPolicyURL string `json:"privacy_policy_url,omitempty"` // the url of the app's privacy policy
Owner User `json:"owner,omitempty"` // partial user object containing info on the owner of the application
VerifyKey string `json:"verify_key"` // the hex encoded key for verification in interactions and the GameSDK's GetTicket
Team *Team `json:"team"` // if the application belongs to a team, this will be a list of the members of that team
GuildID Snowflake `json:"guild_id,omitempty"` // if this application is a game sold on Discord, this field will be the guild to which it has been linked
PrimarySkuID Snowflake `json:"primary_sku_id"` // if this application is a game sold on Discord, this field will be the id of the "Game SKU" that is created, if exists
Slug string `json:"slug,omitempty"` // if this application is a game sold on Discord, this field will be the URL slug that links to the store page
CoverImage string `json:"cover_image,omitempty"` // the application's default rich presence invite cover image hash
Flags ApplicationFlags `json:"flags,omitempty"` // the application's public ApplicationFlags
Tags []string `json:"tags,omitempty"` // up to 5 tags describing the content and functionality of the application
InstallParams InstallParams `json:"install_params,omitempty"` // settings for the application's default in-app authorization link, if enabled
CustomInstallURL string `json:"custom_install_url,omitempty"` // the application's default custom authorization link, if enabled
RoleConnectionsVerificationURL string `json:"role_connections_verification_url"` // the application's role connection verification entry point, which when configured will render the app as a verification method in the guild role verification configuration
}

// ApplicationFlags - the application's public ApplicationFlags
Expand Down
7 changes: 3 additions & 4 deletions api/application_commands.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022. Veteran Software
* Copyright (c) 2022-2023. Veteran Software
*
* Discord API Wrapper - A custom wrapper for the Discord REST API developed for a proprietary project.
*
Expand All @@ -19,8 +19,7 @@ package api
import (
"strconv"

"github.com/veteran-software/discord-api-wrapper/v10/logging"
"github.com/veteran-software/discord-api-wrapper/v10/utilities"
log "github.com/veteran-software/nowlive-logging"
)

// ApplicationCommand - A command, or each individual subcommand, can have a maximum of 25 options
Expand Down Expand Up @@ -138,7 +137,7 @@ func PermissionConstantsEveryone(guildID Snowflake) *Snowflake {
func PermissionsConstantsAllChannels(guildID Snowflake) *Snowflake {
snowflakeInt, err := strconv.ParseUint(string(guildID), 10, 64)
if err != nil {
logging.Errorln(utilities.FuncName(), err)
log.Errorln(log.FuncName(), err)
return new(Snowflake)
}

Expand Down
9 changes: 6 additions & 3 deletions api/application_commands_endpoints.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022. Veteran Software
* Copyright (c) 2022-2023. Veteran Software
*
* Discord API Wrapper - A custom wrapper for the Discord REST API developed for a proprietary project.
*
Expand Down Expand Up @@ -27,7 +27,8 @@ import (
// Returns an array of application command objects.
//
//goland:noinspection GoUnusedExportedFunction
func GetGlobalApplicationCommands(applicationID Snowflake, withLocalizations bool) ([]*ApplicationCommand, error) {
func GetGlobalApplicationCommands(applicationID Snowflake, withLocalizations bool) ([]*ApplicationCommand,
error) {
u := parseRoute(fmt.Sprintf(getGlobalApplicationCommands, api, applicationID.String()))

q := u.Query()
Expand Down Expand Up @@ -245,7 +246,9 @@ func (i *Interaction) EditGuildApplicationCommand(payload *EditApplicationComman
// DeleteGuildApplicationCommand - Delete a guild command. Returns 204 No Content on success.
//
//goland:noinspection GoUnusedExportedFunction
func DeleteGuildApplicationCommand(applicationID *Snowflake, guildID *Snowflake, commandID string) error {
func DeleteGuildApplicationCommand(applicationID *Snowflake,
guildID *Snowflake,
commandID string) error {
u := parseRoute(
fmt.Sprintf(
deleteGuildApplicationCommand,
Expand Down
67 changes: 67 additions & 0 deletions api/application_role_connection_metadata.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Copyright (c) 2023. Veteran Software
*
* Discord API Wrapper - A custom wrapper for the Discord REST API developed for a proprietary project.
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program.
* If not, see <http://www.gnu.org/licenses/>.
*/

package api

/*
ApplicationRoleConnectionMetadata

A representation of role connection metadata for an Application.

When a Guild has added a bot and that bot has configured its RoleConnectionsVerificationURL (in the developer portal), the application will render as a potential verification method in the guild's role verification configuration.

If an application has configured role connection metadata, its metadata will appear in the role verification configuration when the application has been added as a verification method to the role.

When a user connects their account using the bots RoleConnectionsVerificationURL, the bot will update a user's role connection with metadata using the OAuth2 scopes.RoleConnectionsWrite scope.
*/
type ApplicationRoleConnectionMetadata struct {
Type ApplicationRoleConnectionMetadataType // type of metadata value
Key string // dictionary key for the metadata field (must be a-z, 0-9, or _ characters; 1-50 characters)
Name string // name of the metadata field (1-100 characters)
NameLocalizations LocalizationDict // translations of the name
Description string // description of the metadata field (1-200 characters)
DescriptionsLocalizations LocalizationDict // translations of the description
}

// ApplicationRoleConnectionMetadataType - type of metadata value
type ApplicationRoleConnectionMetadataType int

//goland:noinspection GoUnusedConst
const (
// IntegerLessThanOrEqual - the metadata value (integer) is less than or equal to the guild's configured value (integer)
IntegerLessThanOrEqual ApplicationRoleConnectionMetadataType = iota + 1

// IntegerGreaterThanOrEqual - the metadata value (integer) is greater than or equal to the guild's configured value (integer)
IntegerGreaterThanOrEqual

// IntegerEqual - the metadata value (integer) is equal to the guild's configured value (integer)
IntegerEqual

// IntegerNotEqual - the metadata value (integer) is not equal to the guild's configured value (integer)
IntegerNotEqual

// DateTimeLessThanOrEqual - the metadata value (ISO8601 string) is less than or equal to the guild's configured value (integer; days before current date)
DateTimeLessThanOrEqual

// DateTimeGreaterThanOrEqual - the metadata value (ISO8601 string) is greater than or equal to the guild's configured value (integer; days before current date)
DateTimeGreaterThanOrEqual

// BooleanEqual - the metadata value (integer) is equal to the guild's configured value (integer; 1)
BooleanEqual

// BooleanNotEqual - the metadata value (integer) is not equal to the guild's configured value (integer; 1)
BooleanNotEqual
)
46 changes: 46 additions & 0 deletions api/application_role_connection_metadata_endpoints.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright (c) 2023. Veteran Software
*
* Discord API Wrapper - A custom wrapper for the Discord REST API developed for a proprietary project.
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program.
* If not, see <http://www.gnu.org/licenses/>.
*/

package api

import (
"encoding/json"
"fmt"
)

// GetApplicationRoleConnectionMetadataRecords - Returns a list of ApplicationRoleConnectionMetadata objects for the given Application.
//
//goland:noinspection GoUnusedExportedFunction
func GetApplicationRoleConnectionMetadataRecords(appID string) ([]*ApplicationRoleConnectionMetadata, error) {
u := parseRoute(fmt.Sprintf(getApplicationRoleConnectionMetadataRecords, api, appID))

var m []*ApplicationRoleConnectionMetadata
err := json.Unmarshal(fireGetRequest(u, nil, nil), &m)

return m, err
}

// UpdateApplicationRoleConnectionMetadataRecords - Updates and returns a list of ApplicationRoleConnectionMetadata objects for the given Application.
//
//goland:noinspection GoUnusedExportedFunction
func UpdateApplicationRoleConnectionMetadataRecords(appID string) ([]*ApplicationRoleConnectionMetadata, error) {
u := parseRoute(fmt.Sprintf(updateApplicationRoleConnectionMetadataRecords, api, appID))

var m []*ApplicationRoleConnectionMetadata
err := json.Unmarshal(firePutRequest(u, nil, nil), &m)

return m, err
}
18 changes: 12 additions & 6 deletions api/audit_log.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022. Veteran Software
* Copyright (c) 2022-2023. Veteran Software
*
* Discord API Wrapper - A custom wrapper for the Discord REST API developed for a proprietary project.
*
Expand All @@ -16,20 +16,25 @@

package api

/* Whenever an admin action is performed on the API, an entry is added to the respective guild's audit log.
/*
Whenever an admin action is performed on the API, an entry is added to the respective guild's audit log.
You can specify the reason by attaching the X-Audit-Log-Reason request header.
This header supports url encoded utf8 characters.
*/

// AuditLog - Whenever an admin action is performed on the API, an entry is added to the respective guild's audit log.
// AuditLog - When an administrative action is performed in a Guild, an entry is added to its AuditLog.
//
// Viewing audit logs requires the ViewAuditLog permission and can be fetched by apps using the GetGuildAuditLog endpoint, or seen by users in the guild's Server Settings.
//
// You can specify the reason by attaching the "X-Audit-Log-Reason" request header.
// All audit log entries are stored for 45 days.
//
// This header supports url encoded utf8 characters.
// When an app is performing an eligible action using the APIs, it can pass an X-Audit-Log-Reason header to indicate why the action was taken.
//
// More information is in the audit log entry section.
type AuditLog struct {
ApplicationCommands []*ApplicationCommand `json:"application_commands"` // List of ApplicationCommands referenced in the audit log
AuditLogEntries []*AuditLogEntry `json:"audit_log_entries"` // List of AuditLog entries, sorted from most to least recent
AutoModerationRules []string `json:"auto_moderation_rules"` // List of auto moderation rules referenced in the audit log
AutoModerationRules []AutoModerationRule `json:"auto_moderation_rules"` // List of AutoModerationRule referenced in the audit log
GuildScheduledEvents []*GuildScheduledEvent `json:"guild_scheduled_events"` // List of GuildScheduledEvents referenced in the audit log
Integrations []*Integration `json:"integrations"` // List of partial Integration objects
Threads []*Channel `json:"threads"` // List of Threads referenced in the audit log
Expand Down Expand Up @@ -61,6 +66,7 @@ const (
ChannelCreate AuditLogEvent = iota + 9
ChannelUpdate
ChannelDelete

ChannelOverwriteCreate
ChannelOverwriteUpdate
ChannelOverwriteDelete
Expand Down
21 changes: 17 additions & 4 deletions api/audit_log_endpoints.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022. Veteran Software
* Copyright (c) 2022-2023. Veteran Software
*
* Discord API Wrapper - A custom wrapper for the Discord REST API developed for a proprietary project.
*
Expand All @@ -23,10 +23,20 @@ import (
"strconv"
)

// GetGuildAuditLog - Returns an audit log object for the guild.
// GetGuildAuditLog - Returns an audit log object for the Guild. Requires the ViewAuditLog permission.
//
// Requires the ViewAuditLog permission.
func (g *Guild) GetGuildAuditLog(userID *Snowflake, actionType *uint64, before *Snowflake, limit *uint64) (*AuditLog, error) {
// The returned list of AuditLogEntry is ordered based on whether you use before or after.
//
// When using before, the list is ordered by the audit log entry ID descending (newer entries first).
//
// If after is used, the list is reversed and appears in ascending order (older entries first).
//
// Omitting both before and after defaults to before the current timestamp and will show the most recent entries in descending order by ID, the opposite can be achieved using after=0 (showing oldest entries).
func (g *Guild) GetGuildAuditLog(userID *Snowflake,
actionType *uint64,
before, after *Snowflake,
limit *uint64) (*AuditLog,
error) {
u := parseRoute(fmt.Sprintf(getGuildAuditLog, api, g.ID.String()))

// Set the optional qsp
Expand All @@ -40,6 +50,9 @@ func (g *Guild) GetGuildAuditLog(userID *Snowflake, actionType *uint64, before *
if before != nil {
q.Set("before", before.String())
}
if after != nil {
q.Set("after", after.String())
}
if limit != nil {
if *limit >= 1 && *limit <= 100 {
q.Set("limit", strconv.FormatUint(*limit, 10))
Expand Down
Loading