1
0
Fork 0
mirror of https://github.com/diamondburned/arikawa.git synced 2025-07-27 07:50:55 +00:00

Compare commits

...

6 commits

Author SHA1 Message Date
diamondburned f8537d78bb
*: Fix GHA shell directive 2024-10-13 22:11:17 -07:00
diamondburned e198c6e8f2
*: Experiment with GHA weirdness 2024-10-13 22:07:20 -07:00
diamondburned 8c46c5bab3
*: Migrate to Nix flakes, deprecate non-GHA CI
This simplifies the project setup and makes it easier to maintain the
CI pipeline.
2024-10-13 21:31:57 -07:00
diamondburned 85debd971d
discord: Fix up documentation for MessageSnapshots
Follow up to PR #453.
2024-10-13 21:21:51 -07:00
diamondburned eb1d5817db
discord: Populate Relationship type with nickname 2024-10-13 21:17:07 -07:00
hi117 9e83b0ef90
discord: Add message_snapshot support (#453)
* Add new type field

https://discord.com/developers/docs/resources/message#message-reference-structure

* Update with changes

* Add message_snapshot

* fixup

* fixup

* Convert Message to MessageSnapshotMessage
2024-10-13 21:16:10 -07:00
9 changed files with 199 additions and 145 deletions

View file

@ -1,48 +0,0 @@
image: "nixos/latest"
packages:
- nixos.go
- nixos.git
- nixos.gcc
sources:
- https://github.com/diamondburned/arikawa
secrets:
# Integration test secrets.
- f51d6157-b4be-4697-99d0-6cd129243f63
environment:
GO111MODULE: "on"
CGO_ENABLED: "1"
# Integration test variables.
SHARD_COUNT: "2"
tested: "./api,./gateway,./bot,./discord"
cov_file: "/tmp/cov_results"
dismock: "github.com/mavolin/dismock/v2/pkg/dismock"
dismock_v: "259685b84e4b6ab364b0fd858aac2aa2dfa42502"
tasks:
- generate: |-
cd arikawa
go generate ./...
if [[ "$(git status --porcelain)" ]]; then
echo "Repository differ after regeneration."
exit 1
fi
- build: cd arikawa && go build ./...
- unit: cd arikawa && go test -tags unitonly -race ./...
- integration: |-
sh -c '
test -f ~/.env || {
echo "Skipped integration tests."
exit 0
}
cd arikawa
go get ./...
go get $dismock@$dismock_v
source ~/.env
go test -coverpkg $tested -coverprofile $cov_file -race ./... $dismock
go tool cover -func $cov_file
'

View file

@ -11,25 +11,18 @@ on:
default: false
type: boolean
defaults:
run:
shell: nix develop -c bash -e {0}
jobs:
nix-env:
name: Initialize Nix
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install Nix packages
uses: diamondburned/cache-install@main
generate:
name: Generate
needs: [nix-env]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install Nix packages
uses: diamondburned/cache-install@main
- uses: actions/checkout@v4
- uses: DeterminateSystems/nix-installer-action@main
- uses: DeterminateSystems/magic-nix-cache-action@main
- name: Generate
run: |
@ -52,23 +45,21 @@ jobs:
runs-on: ubuntu-latest
needs: [generate]
steps:
- uses: actions/checkout@v2
- name: Install Nix packages
uses: diamondburned/cache-install@main
- uses: actions/checkout@v4
- uses: DeterminateSystems/nix-installer-action@main
- uses: DeterminateSystems/magic-nix-cache-action@main
- name: Build
run: go build ./...
run: go build -v ./...
unit-test:
name: Unit Test
runs-on: ubuntu-latest
needs: [build]
steps:
- uses: actions/checkout@v2
- name: Install Nix packages
uses: diamondburned/cache-install@main
- uses: actions/checkout@v4
- uses: DeterminateSystems/nix-installer-action@main
- uses: DeterminateSystems/magic-nix-cache-action@main
- name: Test
run: go test $TEST_FLAGS ./...
@ -82,10 +73,9 @@ jobs:
runs-on: ubuntu-latest
needs: [build]
steps:
- uses: actions/checkout@v2
- name: Install Nix packages
uses: diamondburned/cache-install@main
- uses: actions/checkout@v4
- uses: DeterminateSystems/nix-installer-action@main
- uses: DeterminateSystems/magic-nix-cache-action@main
- name: Test
run: |

View file

@ -1,53 +0,0 @@
{
"image": "golang:alpine",
"variables": {
"GO111MODULE": "on",
"CGO_ENABLED": "1", # for the race detector
"COV": "/tmp/cov_results",
"dismock": "github.com/mavolin/dismock/v3/pkg/dismock",
"dismock_v": "259685b84e4b6ab364b0fd858aac2aa2dfa42502",
# used only in integration_test
"tested": "./api,./gateway,./bot,./discord"
},
"before_script": [
"apk add git build-base"
"go get ./...",
"go get $dismock@$dismock_v",
],
"stages": [
"build",
"test"
],
"build_test": {
"stage": "build",
"script": [
"go build ./..."
]
},
"unit_test": {
"stage": "test",
"timeout": "4m", # 4 minutes
# Don't run the test if we have a $BOT_TOKEN, because
# integration_test will run instead.
"except": {
"variables": [ "$BOT_TOKEN" ]
},
"script": [
"go test -coverpkg $tested -coverprofile $COV -tags unitonly -v -race ./... $dismock",
"go tool cover -func $COV"
]
},
"integration_test": {
"stage": "test",
"timeout": "8m", # 8 minutes
# Run the test only if we have $BOT_TOKEN, else fallback to unit
# tests.
"only": {
"variables": [ "$BOT_TOKEN", "$CHANNEL_ID", "$VOICE_ID" ]
},
"script": [
"go test -coverpkg $tested -coverprofile $COV -v -race ./... $dismock",
"go tool cover -func $COV"
]
}
}

View file

@ -100,7 +100,17 @@ type Message struct {
// the type is InlinedReplyMessage, the backend couldn't fetch the
// replied-to message. If null, the message was deleted. If present and
// non-null, it is a message object
//
// This field is only populated if Reference.Type is
// [MessageReferenceTypeDefault].
ReferencedMessage *Message `json:"referenced_message,omitempty"`
// MessageSnapshots contains the messages associated with the
// message_reference. This is a minimal subset of fields in a message (e.g.
// author is excluded.)
//
// This field is only populated if Reference.Type is
// [MessageReferenceTypeForward].
MessageSnapshots []MessageSnapshot `json:"message_snapshots,omitempty"`
// Interaction is the interaction that the message is in response to.
// This is only present if the message is in response to an interaction.
@ -365,6 +375,70 @@ func (m MessageApplication) CreatedAt() time.Time {
return m.ID.Time()
}
// https://discord.com/developers/docs/resources/message#message-snapshot-object
type MessageSnapshotMessage struct {
// Type is the type of message.
Type MessageType `json:"type"`
// Content contains the contents of the message.
Content string `json:"content"`
// Embeds contains any embedded content.
Embeds []Embed `json:"embeds"`
// Attachments contains any attached files.
Attachments []Attachment `json:"attachments"`
// Timestamp specifies when the message was sent
Timestamp Timestamp `json:"timestamp,omitempty"`
// EditedTimestamp specifies when this message was edited.
//
// IsValid() will return false, if the messages hasn't been edited.
EditedTimestamp Timestamp `json:"edited_timestamp,omitempty"`
// Flags are the MessageFlags.
Flags MessageFlags `json:"flags"`
// Mentions contains the users specifically mentioned in the message.
//
// The user objects in the mentions array will only have the partial
// member field present in MESSAGE_CREATE and MESSAGE_UPDATE events from
// text-based guild channels.
Mentions []GuildUser `json:"mentions"`
// MentionRoleIDs contains the ids of the roles specifically mentioned in
// the message.
MentionRoleIDs []RoleID `json:"mention_roles"`
// Stickers contains the sticker "items" sent with the message.
Stickers []StickerItem `json:"sticker_items,omitempty"`
// Components contains any attached components.
Components ContainerComponents `json:"components,omitempty"`
}
// https://discord.com/developers/docs/resources/message#message-snapshot-object
type MessageSnapshot struct {
// The embedded partial message object
Message MessageSnapshotMessage `json:"message"`
}
// Type of message reference
type MessageReferenceType int
const (
// MessageReferenceTypeDefault is the type for a standard reference used by
// replies.
// It populates the ReferencedMessage field in [Message].
MessageReferenceTypeDefault MessageReferenceType = iota
// MessageReferenceTypeForward is the type for a reference used to point to
// a message at a point in time.
// It populates the MessageSnapshots field in [Message].
MessageReferenceTypeForward
)
// MessageReference is used in four situations:
//
// # Crosspost messages
@ -396,6 +470,9 @@ func (m MessageApplication) CreatedAt() time.Time {
// When sending, only MessageID is required.
// https://discord.com/developers/docs/resources/channel#message-object-message-reference-structure
type MessageReference struct {
// Type describes whether MessageSnapshots or ReferencedMessage will be
// populated in [Message].
Type MessageReferenceType `json:"type"`
// MessageID is the id of the originating message.
MessageID MessageID `json:"message_id,omitempty"`
// ChannelID is the id of the originating message's channel.

View file

@ -3,6 +3,8 @@ package discord
import (
"strconv"
"time"
"github.com/diamondburned/arikawa/v3/utils/json/option"
)
type User struct {
@ -251,9 +253,11 @@ type ActivitySecrets struct {
// A Relationship between the logged in user and the user in the struct. This
// struct is undocumented.
type Relationship struct {
UserID UserID `json:"id"`
User User `json:"user"`
Type RelationshipType `json:"type"`
UserID UserID `json:"id"`
User User `json:"user"`
Type RelationshipType `json:"type"`
Since Timestamp `json:"since,omitempty"`
Nickname option.String `json:"nickname"`
}
// RelationshipType is an enum for a relationship.

61
flake.lock Normal file
View file

@ -0,0 +1,61 @@
{
"nodes": {
"flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1726560853,
"narHash": "sha256-X6rJYSESBVr3hBoH0WbKE5KvhPU5bloyZ2L4K60/fPQ=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "c1dfcf08411b08f6b8615f7d8971a2bfa81d5e8a",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1728492678,
"narHash": "sha256-9UTxR8eukdg+XZeHgxW5hQA9fIKHsKCdOIUycTryeVw=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "5633bcff0c6162b9e4b5f1264264611e950c8ec7",
"type": "github"
},
"original": {
"owner": "nixos",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
}
},
"root": "root",
"version": 7
}

31
flake.nix Normal file
View file

@ -0,0 +1,31 @@
{
inputs = {
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
};
outputs =
{
self,
nixpkgs,
flake-utils,
}:
flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = nixpkgs.legacyPackages.${system};
in
{
devShells.default = pkgs.mkShell {
packages = with pkgs; [
go_1_22
gopls
go-tools
nixfmt-rfc-style
];
};
}
);
}

View file

@ -1,3 +1,6 @@
github.com/diamondburned/arikawa/v3 v3.0.0-rc.6/go.mod h1:5jBSNnp82Z/EhsKa6Wk9FsOqSxfVkNZDTDBPOj47LpY=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
golang.org/x/sys v0.0.0-20211001092434-39dca1131b70/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/term v0.24.0/go.mod h1:lOBK/LVxemqiMij05LGJ0tzNr8xlmwBRJ81PX6wVLH8=
golang.org/x/text v0.18.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk=

View file

@ -1,11 +0,0 @@
{ pkgs ? import <nixpkgs> {} }:
pkgs.mkShell {
buildInputs = with pkgs; [
go
gopls
go-tools
];
CGO_ENABLED = "1";
}