Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
c7e38b1
feat (bot): initial bot support
cryptoAlgorithm Nov 23, 2022
730865e
chore!: merge DiscordKitCommon into DiscordKitCore
cryptoAlgorithm Nov 23, 2022
16474b2
patch (bot): set properties in identify to represent the library for …
cryptoAlgorithm Nov 23, 2022
4f8e38a
fix: build failures due to DiscordKitCore merger
cryptoAlgorithm Nov 23, 2022
da6d13f
patch (identify): use enum for current OS with current field
cryptoAlgorithm Nov 23, 2022
1104bb6
feat (bot): add initial notification support
cryptoAlgorithm Nov 23, 2022
87756cb
fix (lint): configure cyclomatic_complexity to ignore cases
cryptoAlgorithm Nov 23, 2022
7501693
chore (lint): fixed a bunch of linting warnings
cryptoAlgorithm Nov 23, 2022
15be635
fix (lint): more linting warnings
cryptoAlgorithm Nov 24, 2022
eb123b8
fix (lint): many many linting warnings
cryptoAlgorithm Nov 24, 2022
4c27613
patch (actions): only run lint action on push for main branch
cryptoAlgorithm Nov 24, 2022
fa61156
patch (README): update bot support status
cryptoAlgorithm Nov 24, 2022
7ce93da
fix (lint): more warnings from GitHub actions
cryptoAlgorithm Nov 24, 2022
9931eb6
fix (lint): last effort at fixing more linting warnings
cryptoAlgorithm Nov 24, 2022
f49b63c
feat!: refactor incoming gateway struct to use enums with associated …
cryptoAlgorithm Nov 25, 2022
62b2fb3
patch (logging): Migrate to SwiftLog (#21)
cryptoAlgorithm Nov 25, 2022
93980f8
feat (events): add message events under new payload struct format
cryptoAlgorithm Nov 25, 2022
d1ae347
patch (bot): update client handler for new payload system
cryptoAlgorithm Nov 25, 2022
2abc172
fix (logging): change decompression stats to trace level
cryptoAlgorithm Nov 26, 2022
71cb503
fix!: migrate DiscordKit to new enum based payload events
cryptoAlgorithm Nov 26, 2022
43ff1d9
patch (actions): cache swift build cache in build and test stages
cryptoAlgorithm Nov 26, 2022
83e11cd
patch (bot): store application id in member var
cryptoAlgorithm Nov 26, 2022
a4bf846
fix (rest): set authorization header with correct content
cryptoAlgorithm Nov 26, 2022
f027c50
feat (rest)!: major rest refactor to use Result for return types
cryptoAlgorithm Dec 2, 2022
9661478
fix (rest)!: update use of rest api in extension in DiscordKit
cryptoAlgorithm Dec 2, 2022
5f27613
fix (rest): remove duplicate case in RequestError to fix linting error
cryptoAlgorithm Dec 2, 2022
06b1726
patch (rest)!: major refactor to remove uses of Result
cryptoAlgorithm Dec 4, 2022
6b91063
feat (event): revamped NotificationCenter wrapper
cryptoAlgorithm Dec 5, 2022
ae5eba1
patch (rest/types): change structure of CreateAppCmd struct
cryptoAlgorithm Dec 12, 2022
82d0f9b
feat (inteaction): create slash commands via result builder
cryptoAlgorithm Dec 12, 2022
f7b4633
patch (command)!: refactor to make structs built by resultBuilder enc…
cryptoAlgorithm Dec 12, 2022
2b8c706
feat (command)!: added cmd handler called for interactions, allowing …
cryptoAlgorithm Dec 12, 2022
a9da1d8
patch (docc): more detailed and fill in missing docc comments
cryptoAlgorithm Dec 13, 2022
6ad9bfb
feat (command): support integer, number and boolean option types
cryptoAlgorithm Dec 13, 2022
4e27859
patch (client)!: only fire ready event once per login
cryptoAlgorithm Dec 13, 2022
98fc0b6
feat (command): add sub-command support
cryptoAlgorithm Dec 13, 2022
f5719c6
patch (command)!: completely rework how option values are retrieved
cryptoAlgorithm Dec 13, 2022
f32677a
patch (client)!: bulk overwrite commands during command registration
cryptoAlgorithm Dec 13, 2022
5561c8b
patch (client): provide login method that retrieves token from enviro…
cryptoAlgorithm Dec 14, 2022
067f323
patch (bot): use weak vars for the rest handler in wrapper structs
cryptoAlgorithm Dec 14, 2022
5c95d92
patch (client): also check if token is empty as a precondition
cryptoAlgorithm Dec 15, 2022
ec7060f
feat (bot/message): move reply method to BotMessage
cryptoAlgorithm Dec 15, 2022
1e7b882
feat (command): support deferred responses and follow up messages
cryptoAlgorithm Dec 15, 2022
54bea4a
feat (command)!: update command builder with modifiers
cryptoAlgorithm Dec 16, 2022
0753ae9
feat (command): key command handlers by command ID instead of name
cryptoAlgorithm Dec 16, 2022
ce6662d
chore (api): bump api version for bots to v10
cryptoAlgorithm Dec 16, 2022
ae7b1ed
feat (embed): added embed builders
cryptoAlgorithm Dec 17, 2022
1db6133
feat (interaction): allow sending follow-up response with embeds
cryptoAlgorithm Dec 17, 2022
114367a
feat (interaction): support ephemeral responses
cryptoAlgorithm Dec 17, 2022
cce10f5
patch (README): update with new icon and changed style
cryptoAlgorithm Dec 19, 2022
46035ff
patch (README): add minimal example and restructured readme
cryptoAlgorithm Dec 20, 2022
e29e80e
patch (README): re-add LoC badge pointing to self-hosted tokei_rs
cryptoAlgorithm Dec 20, 2022
af5cbf2
fix (README): make discord invite point to right server
cryptoAlgorithm Dec 20, 2022
e51eb8c
feat (endpoints): add auto-generated endpoints (#23)
Helloyunho Jan 25, 2023
0393481
patch: merge remote-tracking branch 'origin/main' into bot-support
cryptoAlgorithm Jan 25, 2023
aeaa46b
feat (component): initial impl, with resultBuilder support
cryptoAlgorithm Jan 27, 2023
ecb25ad
patch (embed): add modifier to change footer text
cryptoAlgorithm Jan 27, 2023
94e7021
feat (interaction): handle component interactions
cryptoAlgorithm Jan 28, 2023
c203186
fix (user): change in purchase_flags type
cryptoAlgorithm Feb 15, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions .github/FUNDING.yml

This file was deleted.

23 changes: 16 additions & 7 deletions .github/workflows/lint-and-test.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
name: Lint and Test

env:
GH_USER: cryptoAlgorithm

on:
push:
branches: [ main ] # Running on every branch causes double runs for PR commits
Expand All @@ -20,9 +17,15 @@ jobs:
- uses: actions/checkout@v3

- name: Xcode Select
uses: devbotsxyz/[email protected]
uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: '14.1'

- name: Cache Swift Build
uses: actions/cache@v3
with:
version: 13.3.1
path: .build
key: swift-build-cache

# Runs a single command using the runners shell
- name: Build
Expand All @@ -36,9 +39,15 @@ jobs:
- uses: actions/checkout@v3

- name: Xcode Select
uses: devbotsxyz/[email protected]
uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: '14.1'

- name: Cache Swift Build
uses: actions/cache@v3
with:
version: 13.3.1
path: .build
key: swift-build-cache # -${{ hashFiles('**/*.swift') }}

- name: Test
run: swift test
Expand Down
9 changes: 9 additions & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ disabled_rules:
- unused_closure_parameter
- multiple_closures_with_trailing_closure
- large_tuple
- todo # TODOs are precisely for reminding me of tasks I'll have to do in the future. If they are flagged as violations, it completely defeats the point.
opt_in_rules:

force_cast: warning
force_try: warning

excluded:
- Sources/DiscordKit/protos
- .build

identifier_name:
min_length:
Expand All @@ -19,4 +21,11 @@ identifier_name:
warning: 40
error: 50
allowed_symbols: ["_"]
cyclomatic_complexity:
ignores_case_statements: true
nesting:
type_level:
warning: 5
error: 8

reporter: "xcode" # reporter type (xcode, json, csv, checkstyle, junit, html, emoji, sonarqube, markdown)
9 changes: 9 additions & 0 deletions Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 17 additions & 9 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,44 @@ let package = Package(
],
products: [
.library(name: "DiscordKitCore", targets: ["DiscordKitCore"]),
.library(name: "DiscordKit", targets: ["DiscordKit"]),
.library(name: "DiscordKitCommon", targets: ["DiscordKitCommon"]),
.library(name: "DiscordKit", targets: ["DiscordKit"]), // User-oriented module, simplifies use of API for UI apps
.library(name: "DiscordKitBot", targets: ["DiscordKitBot"]) // Bot-oriented module, for use in bots
],
dependencies: [
.package(url: "https://github.com/ashleymills/Reachability.swift", from: "5.1.0"),
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"),
.package(url: "https://github.com/apple/swift-protobuf.git", from: "1.6.0"),
.package(url: "https://github.com/apple/swift-log.git", from: "1.0.0")
],
targets: [
.target(
name: "DiscordKitCore",
dependencies: [
.product(name: "Reachability", package: "Reachability.swift", condition: .when(platforms: [.macOS])),
.product(name: "SwiftProtobuf", package: "swift-protobuf"),
.target(name: "DiscordKitCommon"),
.product(name: "Logging", package: "swift-log")
],
exclude: [
"REST/README.md",
"Gateway/README.md"
"Gateway/README.md",
"Objects/README.md"
]
),
.target(
name: "DiscordKit",
dependencies: [.target(name: "DiscordKitCore")]
dependencies: [
.target(name: "DiscordKitCore"),
.product(name: "Logging", package: "swift-log")
]
),
.target(
name: "DiscordKitCommon",
exclude: ["Objects/README.md"]
.target(
name: "DiscordKitBot",
dependencies: [
.target(name: "DiscordKitCore"),
.product(name: "SwiftProtobuf", package: "swift-protobuf")
]
),
.testTarget(name: "DiscordKitCommonTests", dependencies: ["DiscordKitCommon"])
.testTarget(name: "DiscordKitCommonTests", dependencies: ["DiscordKitCore"])
],
swiftLanguageVersions: [.v5]
)
120 changes: 100 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,112 @@
# DiscordKit
<p align="center">
<img src="https://user-images.githubusercontent.com/64193267/208341700-75fb1d63-f044-4b60-9c86-ed945916b65c.png" height="128">
</p>

![Discord](https://img.shields.io/discord/964741354112577557?style=for-the-badge)
<h1 align="center">DiscordKit</h1>

The Discord API implementation that powers [Swiftcord](https://github.com/SwiftcordApp/Swiftcord),
a native Discord client for macOS also written in Swift.
<p align="center">
<a aria-label="Join the community on Discord" href="https://discord.gg/he7n6MGDXS" target="_blank">
<img alt="" src="https://img.shields.io/discord/964741354112577557?style=for-the-badge&labelColor=black&label=Discord">
</a>

A (mainly) fully functional Discord API library written from scratch fully in Swift!
Currently only supports user accounts, bot support coming soon. Check out the
[`bot-support`](https://github.com/SwiftcordApp/DiscordKit/tree/bot-support) branch
and SwiftcordApp/DiscordKit#18 for a quick peep into what we've been up to ;D
<!-- Self-hosted tokei_rs instance, only works for repos in the SwiftcordApp org -->
<img alt="" src="https://vinkwok.tk/tokei/github/SwiftcordApp/DiscordKit?style=for-the-badge&branch=bot-support">

**If you like DiscordKit, please give it a ⭐ star, or consider sponsoring! It helps motivate
me to continue developing it**
<a aria-label="DiscordKit Guide" href="https://swiftcord.gitbook.io/discordkit-guide/" target="_blank">
<img alt="" src="https://img.shields.io/badge/guide-gitbook-important?style=for-the-badge&labelColor=black">
</a>
</p>

## Documentation
<p align="center">Package for interacting with Discord's API to build Swift bots</p>

WIP Developer Documentation is available [here](https://swiftcordapp.github.io/DiscordKit/documentation/discordkit/).
> DiscordKit for Bots is now released! Use DiscordKit to create that bot you've been
> looking to make, in the Swift that you know and love!

## Platform Support
## About

DiscordKit is a Swift package for creating Discord bots in Swift.

**If DiscordKit has helped you, please give it a ⭐ star, or consider sponsoring! It
keeps me motivated to continue developing this and other projects.**

## Installation

### Swift Package Manager (SPM):

<details>
<summary><code>Package.swift</code></summary>

Add the following to your `Package.swift`:
```swift
.package(url: "https://github.com/SwiftcordApp/DiscordKit", branch: "bot-support")
```
</details>
<details>
<summary>Xcode Project</summary>

Currently, DiscordKit only offically supports macOS versions 12 and up. Theoretically, You should be able to compile and use DiscordKit on i(Pad)OS/tvOS, however this has not been tested and is considered an unsupported setup.
Add a package dependancy in your Xcode project with the following parameters:

Linux and Windows is not supported at the moment, due to our reliance on Apple's `Security` and `SystemConfiguration` frameworks. We have not blocked building DiscordKit on Linux and Windows in the event that support for those frameworks is added in the future. We may rework the code to add support for linux/windows in the future.
**Package URL:**
```
https://github.com/SwiftcordApp/DiscordKit
```

**Branch:**
```
bot-support
```

**Product:**
- [x] DiscordKitBot
</details>

For more detailed instructions, refer to [this page](https://app.gitbook.com/o/bq2pyf3PEDPf2CURHt4z/s/WJuHiYLW9jKqPb7h8D7t/getting-started/installation)
in the DiscordKit guide.

## Example Usage

Create a simple bot with a **/ping** command:

## Adding DiscordKit to your project
### SPM:
Add the following to your `Package.swift`:
```swift
.package(url: "https://github.com/SwiftcordApp/DiscordKit", branch: "main"),

import DiscordKitBot

let bot = Client(intents: .unprivileged)

bot.ready.listen {
print("Logged in as \(bot.user!.username)#\(bot.user!.discriminator)!")

print("Started refreshing application (/) commands.")
try? await bot.registerApplicationCommands(guild: ProcessInfo.processInfo.environment["COMMAND_GUILD_ID"]) {
NewAppCommand("ping", description: "Ping me!") { interaction in
try? await interaction.reply("Pong!")
}
}
print("Successfully reloaded application (/) commands.")
}

bot.login() // Reads the bot token from the DISCORD_TOKEN environment variable and logs in with the token

// Run the main RunLoop to prevent the program from exiting
RunLoop.main.run()
```
Currently, DiscordKit is in alpha, so it's recommended to use the latest commit on the `main` branch.
_(Yes, that's really the whole code, no messing with registering commands with the REST
API or anything!)_

Not sure what to do next? Check out the guide below, which walks you through
all the steps to create your own Discord bot!

## Resources

Here are some (WIP) resources that might be useful while developing with DiscordKit.

* [DiscordKit Guide](https://swiftcord.gitbook.io/discordkit-guide/)
* [Developer Documentation](https://swiftcordapp.github.io/DiscordKit/documentation/discordkit/)

## Platform Support

Currently, DiscordKit only offically supports macOS versions 11 and up. Theoretically, you should be able to compile and use DiscordKit on any Apple platform with equivalent APIs, however this has not been tested and is considered an unsupported setup.

Linux and Windows is not supported at the moment, primarily due to our reliance on Apple's `Combine` framework. We have not blocked building DiscordKit on other platforms in the event that support for those frameworks is added to Swift's corelibs in the future.

Linux support is planned, and will arrive sometime in the future. Unfortunately, we do not have a timeline for that at the moment.
4 changes: 2 additions & 2 deletions Sources/DiscordKit/Extensions/Presence+.swift
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
//
// File.swift
// Presence+.swift
//
//
// Created by Vincent Kwok on 7/9/22.
//

import Foundation
import DiscordKitCommon
import DiscordKitCore

extension Presence {
init(protoStatus: StatusSettings, id: Snowflake) {
Expand Down
Loading