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

Vapor3 #85

Open
wants to merge 124 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
124 commits
Select commit Hold shift + click to select a range
4f0620a
get something compiling
nuclearace Jul 29, 2018
1e019ba
catch errors trying to connect
nuclearace Aug 4, 2018
cc7c8e0
move c deps to package system targs instead of repos
nuclearace Sep 22, 2018
ba4b529
Merge branch 'development' into vapor3
nuclearace Oct 6, 2018
6833ee9
update deps
nuclearace Oct 6, 2018
d52672e
fiddle around with connecting
nuclearace Oct 6, 2018
63120e4
start adding back voice support
nuclearace Oct 7, 2018
aaf0374
Remove .swift-version
fwcd Aug 27, 2019
f58fafd
Add FoundationNetworking imports
fwcd Aug 27, 2019
8f5c696
Merge branch 'development' into vapor3
fwcd Aug 27, 2019
8045ab6
Upgrade vapor/WebSocket to 1.1.x
fwcd Aug 27, 2019
0816a04
Implement WebSocket using nio-websocket-client
fwcd Aug 28, 2019
49eda4c
Setup TLS in WebSocket configuration
fwcd Aug 28, 2019
62df10f
Update nio-websocket-client
fwcd Aug 28, 2019
f8e6cd4
Fix compilation warnings
fwcd Aug 28, 2019
f5ea9a6
Merge pull request #80 from fwcd/vapor3
nuclearace Sep 30, 2019
08f2cd0
Migrate to WebSocketKit
fwcd Oct 18, 2019
e5fec90
Handle successful web socket close
fwcd Oct 18, 2019
247e342
Use WebSocket.connect instead of WebSocketClient
fwcd Oct 18, 2019
6f85035
Add fallbacks for deprecated Process methods on macOS
fwcd Oct 18, 2019
8db478b
Merge pull request #84 from fwcd/vapor3
nuclearace Oct 26, 2019
d6bcc60
Fix libsodium import
TellowKrinkle Sep 2, 2019
5ea8875
Merge pull request #86 from tellowkrinkle/vapor3
nuclearace Nov 14, 2019
de153e3
Get vapor3 branch building again
nuclearace Dec 1, 2019
b45727b
Swift 5.1
nuclearace Dec 1, 2019
fcf87eb
fix tests
nuclearace Dec 1, 2019
9ac6a30
Try using swiftenv on linux for installing swift
nuclearace Dec 1, 2019
1f6dcd6
wrong command
nuclearace Dec 1, 2019
afbbcc4
actually install swift
nuclearace Dec 1, 2019
96bf60a
install over vapor swift
nuclearace Dec 1, 2019
2eefc6f
fix comment
nuclearace Dec 1, 2019
3fb14e9
uninstall vapor swift
nuclearace Dec 1, 2019
93225c3
more linux fiddling
nuclearace Dec 1, 2019
efef26a
more linux fiddling
nuclearace Dec 1, 2019
976689a
try run.sh
nuclearace Dec 1, 2019
3168bd6
more fiddling
nuclearace Dec 1, 2019
e3a16c5
use boinic
nuclearace Dec 1, 2019
3e58750
try installing swift in run.sh
nuclearace Dec 1, 2019
af82a80
Fix sending speaking packet
nuclearace Dec 1, 2019
4f8f528
use error log
nuclearace Dec 1, 2019
93fc7ab
Add swift-log
fwcd Jan 4, 2020
f2e2371
Change logging backend from NSLog to swift-log
fwcd Jan 4, 2020
c591e23
Migrate DiscordLogger.level to swift-log
fwcd Jan 4, 2020
67ee8a5
Migrate entire logging API to swift-log
fwcd Jan 14, 2020
c085050
Merge pull request #89 from fwcd/vapor3
nuclearace Jan 16, 2020
778c5dc
Add support for animated emojis
fwcd Apr 22, 2020
77e5f6a
Merge pull request #92 from fwcd/animated-emoji
nuclearace Apr 24, 2020
9e1d3bb
Update WebSocketKit to 2.1.0
fwcd May 26, 2020
a6776f0
Require macOS 10.15 as websocket-kit does
fwcd May 26, 2020
92600ba
Merge pull request #94 from fwcd/update-websocketkit
nuclearace May 27, 2020
de6594e
Fix a typo in EndpointRequest
fwcd Jun 29, 2020
3d0f88f
Make sure that all PUT/POST/PATCH requests have a body
fwcd Jun 29, 2020
8a2a995
Merge pull request #97 from fwcd/empty-body
nuclearace Jun 29, 2020
1cc219e
Merge pull request #96 from fwcd/put-typo
nuclearace Jun 29, 2020
b6bab98
Add support for multiple activites in a presence
fwcd Jul 16, 2020
edf8d06
Update URLs to discord.com
fwcd Jul 18, 2020
7bf832d
Merge pull request #99 from fwcd/discord-urls
nuclearace Jul 19, 2020
caf0753
Add endpoint consumer for emojis and CreateEmoji endpoint
fwcd Sep 3, 2020
ee3372f
Add DiscordEndpointConsumer.getGuildEmojis
fwcd Sep 3, 2020
1794d8c
Add a default value for the callback in createGuildEmoji
fwcd Sep 3, 2020
b7434ed
Add guild emoji endpoint
fwcd Sep 3, 2020
d8814eb
Add DiscordEndpointConsumer.getGuildEmoji
fwcd Sep 3, 2020
7afc8e9
Add DiscordEndpointConsumer.deleteGuildEmoji
fwcd Sep 3, 2020
baf298f
Return emoji object in createGuildEmoji
fwcd Sep 3, 2020
dbe20f4
Merge pull request #100 from fwcd/emoji-endpoints
nuclearace Sep 12, 2020
56c269e
Add reaction deletion endpoints
fwcd Nov 9, 2020
f1d54c9
Merge pull request #103 from fwcd/reaction-deletions
nuclearace Nov 10, 2020
e1fe1eb
Added banner
ttimpe Nov 16, 2020
44ebb8c
Added NSFW channel flag
ttimpe Nov 16, 2020
b7082e2
Merge pull request #104 from ttimpe/vapor3
nuclearace Nov 16, 2020
10f130f
Switch to v8 endpoints
fwcd Nov 20, 2020
6c3da19
Update to v8 gateway
fwcd Nov 20, 2020
5d795df
Add DiscordGatewayIntent
fwcd Nov 20, 2020
82188eb
Add common sets of intents
fwcd Nov 20, 2020
3de9116
Pass unprivileged intents to engine by default
fwcd Nov 20, 2020
2b635f1
Add client option for specifying intents
fwcd Nov 20, 2020
8e26efc
Merge branch 'activities' into v8
fwcd Nov 20, 2020
97c47ef
Remove game field from presence
fwcd Nov 20, 2020
930567b
Migrate 'event_enabled' to 'widget_enabled'
fwcd Nov 20, 2020
d0b7c72
Migrate 'embed_channel_id' to 'widget_channel_id'
fwcd Nov 20, 2020
65f7e0c
Set intents in test engine
fwcd Nov 20, 2020
2c330ea
Use floating points for rate limits
fwcd Nov 20, 2020
aea37f8
Add DiscordAllowedMentions structure
fwcd Nov 20, 2020
acf84e3
Add reply to message types
fwcd Nov 20, 2020
40b3de9
Add support for referenced messages and replies
fwcd Nov 20, 2020
9c4cb65
Add public initializers to allowed mention and message ref structs
fwcd Nov 20, 2020
aa3ba13
Add support for message stickers
fwcd Nov 20, 2020
7a43c44
Migrate to new string-serialized permissions
fwcd Nov 20, 2020
a3446f2
Encode permissions as string
fwcd Nov 20, 2020
a524ea9
Implement support for interaction events
fwcd Dec 22, 2020
a05c1b3
Add application command REST endpoints
fwcd Dec 22, 2020
00cfc1b
Add interaction callback endpoint
fwcd Dec 22, 2020
61b4beb
Add application command structures
fwcd Dec 22, 2020
a8879cd
Add correct coding keys to application command structures
fwcd Dec 22, 2020
9ecc8b8
Add application command decoders and stub out endpoint methods
fwcd Dec 22, 2020
b0abb74
Fix some typos
fwcd Dec 22, 2020
317c33e
Implement all get-commands endpoints
fwcd Dec 22, 2020
a900c0e
Stub out other CRUD endpoints for commands
fwcd Dec 22, 2020
e0f91d4
Implement create command endpoint
fwcd Dec 22, 2020
27fa4dc
Implement edit command endpoint
fwcd Dec 22, 2020
0f0409a
Implement command deletion endpoint
fwcd Dec 22, 2020
4e37476
Implement guild command endpoints
fwcd Dec 22, 2020
22d53d0
Implement interaction create handler
fwcd Dec 22, 2020
09250c5
Implement REST endpoint for interaction responses
fwcd Dec 22, 2020
3917ebb
Make callbacks optional in command creation methods
fwcd Dec 22, 2020
34adfca
Fix interaction type name typo
fwcd Dec 22, 2020
22497a7
Use interaction response structure in endpoint method
fwcd Dec 22, 2020
8ef8229
Add public initializer for interaction response structure
fwcd Dec 22, 2020
9c953ac
Add public initializers for command options
fwcd Dec 22, 2020
9d6461c
Add 'APPLICATION_COMMAND_CREATE' to the gateway events
fwcd Dec 22, 2020
168cd26
Merge pull request #105 from fwcd/v8
nuclearace Jan 27, 2021
e008a78
Merge pull request #106 from fwcd/interactions
nuclearace Jan 27, 2021
06cafaa
Replace protocol class bounds with AnyObject
fwcd May 13, 2021
37ffcd1
Merge pull request #107 from fwcd/replace-deprecated-class-bounds
nuclearace May 13, 2021
47b5125
Add new message components API
fwcd May 30, 2021
29e94c8
Add action rows and some helper functions
fwcd May 30, 2021
be1f35f
Add DiscordInteractionType.messageComponent
fwcd May 30, 2021
f4b3b3f
Parse message from interaction response
fwcd May 30, 2021
38289e3
Update components doc comment
fwcd May 30, 2021
8de1887
Add customId to DiscordInteraction
fwcd May 30, 2021
2fb1e2d
Add missing components coding key
fwcd May 31, 2021
a6f8f27
Move customId to application command interaction data
fwcd May 31, 2021
0625515
Make RawRepresentables Hashable
fwcd May 31, 2021
ae5acbf
Merge pull request #109 from fwcd/message-buttons
nuclearace May 31, 2021
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
1 change: 0 additions & 1 deletion .swift-version

This file was deleted.

4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
matrix:
include:
- os: linux
dist: trusty
dist: bionic
sudo: required
language: generic
- os: osx
osx_image: xcode9.3
osx_image: xcode11
language: objective-c
branches:
only:
Expand Down
4 changes: 2 additions & 2 deletions .travis/before_install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ if [[ $TRAVIS_OS_NAME == 'osx' ]]; then
brew install libsodium
brew install opus
else
# Install Swift, Vapor and Opus
# Install Vapor and Opus
eval "$(curl -sL https://apt.vapor.sh)"
sudo apt-get install swift vapor libopus-dev
sudo apt-get install vapor libopus-dev

# Sodium
wget https://download.libsodium.org/libsodium/releases/libsodium-1.0.16.tar.gz
Expand Down
13 changes: 11 additions & 2 deletions .travis/run.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
#!/bin/bash

if [[ $TRAVIS_OS_NAME == 'osx' ]]; then
swift test -Xlinker -L/usr/local/lib -Xlinker -lopus -Xcc -I/usr/local/include
swift test
else
swift test -Xlinker -L/usr/lib -Xlinker -lopus -Xcc -I/usr/include
git clone https://github.com/kylef/swiftenv.git ~/.swiftenv
echo 'export SWIFTENV_ROOT="$HOME/.swiftenv"' >> ~/.bash_profile
echo 'export PATH="$SWIFTENV_ROOT/bin:$PATH"' >> ~/.bash_profile
echo 'eval "$(swiftenv init -)"' >> ~/.bash_profile
source ~/.bash_profile

# Swift
swiftenv install 5.1 && swiftenv global 5.1
swift --version
swift test
fi
82 changes: 23 additions & 59 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
"object": {
"pins": [
{
"package": "Bits",
"repositoryURL": "https://github.com/vapor/bits.git",
"package": "Socket",
"repositoryURL": "https://github.com/IBM-Swift/BlueSocket",
"state": {
"branch": null,
"revision": "c32f5e6ae2007dccd21a92b7e33eba842dd80d2f",
"version": "1.1.0"
"revision": "c46a3d41f5b2401d18bcb46d0101cdc5cd13e307",
"version": "1.0.52"
}
},
{
Expand All @@ -20,84 +20,48 @@
}
},
{
"package": "Core",
"repositoryURL": "https://github.com/vapor/core.git",
"state": {
"branch": null,
"revision": "f9f3a585ab0ea5764b46d7a36d9c0d9d508b9c63",
"version": "2.2.0"
}
},
{
"package": "Crypto",
"repositoryURL": "https://github.com/vapor/crypto.git",
"state": {
"branch": null,
"revision": "946edc6642d6825982a2f52a268a8ba9bd520a3d",
"version": "2.1.2"
}
},
{
"package": "CTLS",
"repositoryURL": "https://github.com/vapor/ctls.git",
"state": {
"branch": null,
"revision": "fba1297f4986a4dac8b02f7ac4e84a77fd492e4c",
"version": "1.1.3"
}
},
{
"package": "Debugging",
"repositoryURL": "https://github.com/vapor/debugging.git",
"state": {
"branch": null,
"revision": "fc5a27d6eb236141dc24e5f14eedaa2e035ae7b3",
"version": "1.1.1"
}
},
{
"package": "Engine",
"repositoryURL": "https://github.com/vapor/engine",
"package": "Sodium",
"repositoryURL": "https://github.com/nuclearace/Sodium",
"state": {
"branch": null,
"revision": "0ecc50fa8c7bc03ec9af78ca37e3b57f192bd258",
"version": "2.2.4"
"revision": "5812a3d879b77aae0fdfbd62d0e8354e914d15ae",
"version": "2.0.0"
}
},
{
"package": "Random",
"repositoryURL": "https://github.com/vapor/random.git",
"package": "swift-log",
"repositoryURL": "https://github.com/apple/swift-log.git",
"state": {
"branch": null,
"revision": "d7c4397d125caba795d14d956efacfe2a27a63d0",
"revision": "74d7b91ceebc85daf387ebb206003f78813f71aa",
"version": "1.2.0"
}
},
{
"package": "Sockets",
"repositoryURL": "https://github.com/vapor/sockets.git",
"package": "swift-nio",
"repositoryURL": "https://github.com/apple/swift-nio.git",
"state": {
"branch": null,
"revision": "79fc180cdcb451dbbb01b1156be36720adde80e0",
"version": "2.2.3"
"revision": "c5fa0b456524cd73dc3ddbb263d4f46c20b86ca3",
"version": "2.17.0"
}
},
{
"package": "Sodium",
"repositoryURL": "https://github.com/nuclearace/Sodium",
"package": "swift-nio-ssl",
"repositoryURL": "https://github.com/apple/swift-nio-ssl.git",
"state": {
"branch": null,
"revision": "5812a3d879b77aae0fdfbd62d0e8354e914d15ae",
"version": "2.0.0"
"revision": "ccf96bbe65ecc7c1558ab0dba7ffabdea5c1d31f",
"version": "2.4.4"
}
},
{
"package": "TLS",
"repositoryURL": "https://github.com/vapor/tls.git",
"package": "websocket-kit",
"repositoryURL": "https://github.com/vapor/websocket-kit",
"state": {
"branch": null,
"revision": "02a47309249e69358aa3c28b5853897585d7a750",
"version": "2.1.2"
"revision": "021edd1ca55451ad15b3e84da6b4064e4b877b34",
"version": "2.1.0"
}
}
]
Expand Down
17 changes: 8 additions & 9 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:4.0
// swift-tools-version:5.1

// The MIT License (MIT)
// Copyright (c) 2016 Erik Little
Expand All @@ -20,27 +20,26 @@
import PackageDescription

var deps: [Package.Dependency] = [
.package(url: "https://github.com/vapor/websocket-kit", .upToNextMinor(from: "2.1.0")),
.package(url: "https://github.com/IBM-Swift/BlueSocket", .upToNextMinor(from: "1.0.0")),
.package(url: "https://github.com/nuclearace/copus", .upToNextMinor(from: "2.1.1")),
.package(url: "https://github.com/nuclearace/Sodium", .upToNextMinor(from: "2.0.0")),
.package(url: "https://github.com/vapor/engine", .upToNextMinor(from: "2.2.0")),
.package(url: "https://github.com/apple/swift-log.git", from: "1.0.0"),
]

var targetDeps: [Target.Dependency] = ["WebSockets"]

#if !os(Linux)
deps += [.package(url: "https://github.com/daltoniam/Starscream", .upToNextMinor(from: "3.0.0")),]
targetDeps += ["Starscream"]
#endif

var targetDeps: [Target.Dependency] = ["WebSocketKit", "COPUS", "Sodium", "Socket", "Logging"]

let package = Package(
name: "SwiftDiscord",
platforms: [.macOS(.v10_15)],
products: [
.library(name: "SwiftDiscord", targets: ["SwiftDiscord"])
],
dependencies: deps,
targets: [
.target(name: "SwiftDiscord", dependencies: targetDeps),
// .systemLibrary(name: "COPUS", pkgConfig: "opus"),
// .systemLibrary(name: "Sodium", pkgConfig: "libsodium"),
.testTarget(name: "SwiftDiscordTests", dependencies: ["SwiftDiscord"]),
]
)
5 changes: 5 additions & 0 deletions Sources/COPUS/module.modulemap
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module COPUS [system] {
header "shim.h"
link "opus"
export *
}
22 changes: 22 additions & 0 deletions Sources/COPUS/shim.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#ifndef __COPUS_SHIM_H__
#define __COPUS_SHIM_H__

#include <opus.h>

int configure_encoder(OpusEncoder *enc, int bitrate, int vbr)
{
int err;

err = opus_encoder_ctl(enc, OPUS_SET_BITRATE(bitrate));
err = opus_encoder_ctl(enc, OPUS_SET_VBR(vbr));

return err;
}

int configure_decoder(OpusDecoder *dec, int gain)
{
return opus_decoder_ctl(dec, OPUS_SET_GAIN(gain));
}


#endif
5 changes: 5 additions & 0 deletions Sources/Sodium/module.modulemap
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module Sodium [system] {
header "shim.h"
link "sodium"
export *
}
6 changes: 6 additions & 0 deletions Sources/Sodium/shim.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#ifndef __SODIUM_SHIM_H__
#define __SODIUM_SHIM_H__

#include <sodium.h>

#endif
2 changes: 1 addition & 1 deletion Sources/SwiftDiscord/Audit/DiscordAuditLogEntry.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public struct DiscordAuditLogEntry {

// TODO An actual struct for this?
/// Optional audit entry information for certain action types.
/// [Structure](https://discordapp.com/developers/docs/resources/audit-log#audit-log-entry-object-optional-audit-entry-info)
/// [Structure](https://discord.com/developers/docs/resources/audit-log#audit-log-entry-object-optional-audit-entry-info)
public let options: [String: Any]

/// The reason for this entry.
Expand Down
27 changes: 17 additions & 10 deletions Sources/SwiftDiscord/Channel/DiscordChannel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,15 @@
// DEALINGS IN THE SOFTWARE.

import Foundation
#if canImport(FoundationNetworking)
import FoundationNetworking
#endif
import Logging

import class Dispatch.DispatchSemaphore

fileprivate let logger = Logger(label: "DiscordChannel")

/// Protocol that declares a type will be a Discord channel.
public protocol DiscordChannel : DiscordClientHolder {
// MARK: Properties
Expand Down Expand Up @@ -56,7 +63,7 @@ public extension DiscordChannel {
// MARK: Properties

/// - returns: The guild that this channel is associated with. Or nil if this channel has no guild.
public var guild: DiscordGuild? {
var guild: DiscordGuild? {
return client?.guildForChannel(id)
}

Expand All @@ -65,10 +72,10 @@ public extension DiscordChannel {
///
/// Deletes this channel.
///
public func delete(reason: String? = nil) {
func delete(reason: String? = nil) {
guard let client = self.client else { return }

DefaultDiscordLogger.Logger.log("Deleting channel: \(id)", type: "DiscordChannel")
logger.info("Deleting channel: \(id)")

client.deleteChannel(id, reason: reason)
}
Expand All @@ -78,7 +85,7 @@ public extension DiscordChannel {
///
/// - parameter options: An array of `DiscordEndpointOptions.ModifyChannel`
///
public func modifyChannel(options: [DiscordEndpoint.Options.ModifyChannel], reason: String? = nil) {
func modifyChannel(options: [DiscordEndpoint.Options.ModifyChannel], reason: String? = nil) {
guard let client = self.client else { return }

client.modifyChannel(id, options: options, reason: reason)
Expand All @@ -93,7 +100,7 @@ public extension DiscordTextChannel {
///
/// - parameter message: The message to pin
///
public func pinMessage(_ message: DiscordMessage) {
func pinMessage(_ message: DiscordMessage) {
guard let client = self.client else { return }

client.addPinnedMessage(message.id, on: id)
Expand All @@ -104,7 +111,7 @@ public extension DiscordTextChannel {
///
/// - parameter message: The message to delete
///
public func deleteMessage(_ message: DiscordMessage) {
func deleteMessage(_ message: DiscordMessage) {
guard let client = self.client else { return }

client.deleteMessage(message.id, on: id)
Expand All @@ -115,7 +122,7 @@ public extension DiscordTextChannel {
///
/// - parameter callback: The callback.
///
public func getPinnedMessages(callback: @escaping ([DiscordMessage], HTTPURLResponse?) -> ()) {
func getPinnedMessages(callback: @escaping ([DiscordMessage], HTTPURLResponse?) -> ()) {
guard let client = self.client else { return callback([], nil) }

client.getPinnedMessages(for: id) {pins, response in
Expand Down Expand Up @@ -144,7 +151,7 @@ public extension DiscordTextChannel {
///
/// - parameter message: The message to send.
///
public func send(_ message: DiscordMessage) {
func send(_ message: DiscordMessage) {
guard let client = self.client else { return }

client.sendMessage(message, to: id)
Expand All @@ -153,7 +160,7 @@ public extension DiscordTextChannel {
///
/// Sends that this user is typing on this channel.
///
public func triggerTyping() {
func triggerTyping() {
guard let client = self.client else { return }

client.triggerTyping(on: id)
Expand All @@ -164,7 +171,7 @@ public extension DiscordTextChannel {
///
/// - parameter message: The message to unpin.
///
public func unpinMessage(_ message: DiscordMessage) {
func unpinMessage(_ message: DiscordMessage) {
guard let client = self.client else { return }

client.deletePinnedMessage(message.id, on: id)
Expand Down
Loading