Skip to content

Commit be388fc

Browse files
feat(linux): Linux Support for DiscordKitBot (#30)
* More macOS and linter fixes * even more macOS fixes * more fixes * even more fixes * fix unused result warning * uncomment the commented out botReady decoder
1 parent 0b79131 commit be388fc

File tree

19 files changed

+299
-45
lines changed

19 files changed

+299
-45
lines changed

.swiftlint.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ disabled_rules:
44
- multiple_closures_with_trailing_closure
55
- large_tuple
66
- 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.
7+
- file_length
78
opt_in_rules:
89

910
force_cast: warning

Package.resolved

Lines changed: 54 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,22 @@ let package = Package(
1717
.package(url: "https://github.com/ashleymills/Reachability.swift", from: "5.1.0"),
1818
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"),
1919
.package(url: "https://github.com/apple/swift-protobuf.git", from: "1.6.0"),
20-
.package(url: "https://github.com/apple/swift-log.git", from: "1.0.0")
20+
.package(url: "https://github.com/apple/swift-log.git", from: "1.0.0"),
21+
.package(url: "https://github.com/OpenCombine/OpenCombine.git", from: "0.14.0"),
22+
.package(url: "https://github.com/tsolomko/SWCompression.git", from: "4.8.0"),
23+
.package(url: "https://github.com/tesseract-one/WebSocket.swift.git", from: "0.2.0")
2124
],
2225
targets: [
2326
.target(
2427
name: "DiscordKitCore",
2528
dependencies: [
2629
.product(name: "Reachability", package: "Reachability.swift", condition: .when(platforms: [.macOS])),
2730
.product(name: "SwiftProtobuf", package: "swift-protobuf"),
28-
.product(name: "Logging", package: "swift-log")
31+
.product(name: "Logging", package: "swift-log"),
32+
.product(name: "OpenCombine", package: "OpenCombine", condition: .when(platforms: [.linux])),
33+
.product(name: "OpenCombineFoundation", package: "OpenCombine", condition: .when(platforms: [.linux])),
34+
.product(name: "SWCompression", package: "SWCompression", condition: .when(platforms: [.linux])),
35+
.product(name: "WebSocket", package: "WebSocket.swift", condition: .when(platforms: [.linux]))
2936
],
3037
exclude: [
3138
"REST/README.md",

Sources/DiscordKitBot/ApplicationCommand/Option/CommandOption.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public protocol CommandOption: Encodable {
2525
/// If this command is required
2626
var required: Bool? { get set }
2727

28-
/// Channel types to restrict visibility of command to
28+
// Channel types to restrict visibility of command to
2929
// var channel_types: ChannelType? { get }
3030
}
3131

Sources/DiscordKitBot/MessageComponent/ActionRow.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,3 @@ public struct ActionRow: Component {
3232
}
3333
}
3434
}
35-

Sources/DiscordKitBot/NCWrapper.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public struct NCWrapper<Data> {
2323
}
2424

2525
public func listen(listener: @escaping (Data) -> Void) {
26-
notificationCenter.addObserver(forName: name, object: nil, queue: nil) { notif in
26+
_ = notificationCenter.addObserver(forName: name, object: nil, queue: nil) { notif in
2727
guard let obj = notif.object as? Data else { return }
2828
listener(obj)
2929
}

Sources/DiscordKitBot/Objects/InteractionResponse.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public struct InteractionResponse: Encodable {
5050
public let flags: DiscordKitCore.Message.Flags?
5151
public let components: [Component]?
5252
public let attachments: [NewAttachment]?
53-
53+
5454
enum CodingKeys: CodingKey {
5555
case content
5656
case tts

Sources/DiscordKitBot/Objects/WebhookResponse.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public struct WebhookResponse: Encodable {
6363
try container.encodeIfPresent(username, forKey: .username)
6464
try container.encodeIfPresent(avatar_url, forKey: .avatar_url)
6565
try container.encodeIfPresent(tts, forKey: .tts)
66-
try container.encodeIfPresent(embeds, forKey:.embeds)
66+
try container.encodeIfPresent(embeds, forKey: .embeds)
6767
try container.encodeIfPresent(allowed_mentions, forKey: .allowed_mentions)
6868
try container.encodeIfPresent(attachments, forKey: .attachments)
6969
try container.encodeIfPresent(flags, forKey: .flags)

Sources/DiscordKitCore/DiscordREST.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
import Foundation
99
import Logging
1010

11+
#if canImport(FoundationNetworking)
12+
import FoundationNetworking
13+
#endif
14+
1115
public class DiscordREST {
1216
static let log = Logger(label: "DiscordREST", level: nil)
1317
// How empty, everything is broken into smaller files (for now xD)

Sources/DiscordKitCore/Extensions/URL+.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,16 @@
66
//
77

88
import Foundation
9+
#if canImport(UniformTypeIdentifiers)
910
import UniformTypeIdentifiers
10-
11+
#endif
1112
public extension URL {
1213
var mimeType: String {
14+
#if canImport(UniformTypeIdentifiers)
1315
UTType(filenameExtension: self.pathExtension)?.preferredMIMEType ?? "application/octet-stream"
16+
#else
17+
"application/octet-stream" // We'll just assume this for now, since UniformTypeIdentifiers isn't available on linux at the moment
18+
#endif
1419
}
1520

1621
/// Appends one or more query items to the URL

0 commit comments

Comments
 (0)