-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resolves #1
- Loading branch information
Showing
11 changed files
with
859 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// | ||
// OptionSet.swift | ||
// | ||
// | ||
// Created by Jaehong Kang on 2022/07/21. | ||
// | ||
|
||
import Foundation | ||
|
||
extension OptionSet where RawValue: Decodable { | ||
public init(from decoder: Decoder) throws { | ||
let container = try decoder.singleValueContainer() | ||
|
||
self.init(rawValue: try container.decode(RawValue.self)) | ||
} | ||
} | ||
|
||
extension OptionSet where RawValue: Encodable { | ||
public func encode(to encoder: Encoder) throws { | ||
var container = encoder.singleValueContainer() | ||
|
||
try container.encode(rawValue) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// | ||
// Unknown.swift | ||
// | ||
// | ||
// Created by Jaehong Kang on 2022/07/21. | ||
// | ||
|
||
import Foundation | ||
|
||
public enum Unknown<T> where T: RawRepresentable { | ||
case value(T) | ||
case rawValue(T.RawValue) | ||
} | ||
|
||
extension Unknown: RawRepresentable { | ||
public var rawValue: T.RawValue { | ||
switch self { | ||
case .value(let value): | ||
return value.rawValue | ||
case .rawValue(let rawValue): | ||
return rawValue | ||
} | ||
} | ||
|
||
public init(rawValue: T.RawValue) { | ||
if let value = T(rawValue: rawValue) { | ||
self = .value(value) | ||
} else { | ||
self = .rawValue(rawValue) | ||
} | ||
} | ||
} | ||
|
||
extension Unknown: Equatable where T.RawValue: Equatable { | ||
public static func == (lhs: Self, rhs: Self) -> Bool { | ||
lhs.rawValue == rhs.rawValue | ||
} | ||
} | ||
|
||
extension Unknown: Hashable where T.RawValue: Hashable { | ||
public func hash(into hasher: inout Hasher) { | ||
hasher.combine(rawValue) | ||
} | ||
} | ||
|
||
extension Unknown: Comparable where T.RawValue: Comparable { | ||
public static func < (lhs: Unknown<T>, rhs: Unknown<T>) -> Bool { | ||
lhs.rawValue < rhs.rawValue | ||
} | ||
} | ||
|
||
extension Unknown: Codable where T: Codable, T.RawValue: Codable { | ||
public init(from decoder: Decoder) throws { | ||
let container = try decoder.singleValueContainer() | ||
|
||
let rawValue = try container.decode(T.RawValue.self) | ||
|
||
self.init(rawValue: rawValue) | ||
} | ||
|
||
public func encode(to encoder: Encoder) throws { | ||
var encoder = encoder.singleValueContainer() | ||
|
||
try encoder.encode(rawValue) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// | ||
// Emoji.swift | ||
// | ||
// | ||
// Created by Jaehong Kang on 2022/07/21. | ||
// | ||
|
||
import Foundation | ||
import Discord | ||
|
||
// TODO: Implement Properties | ||
public struct Emoji: Equatable, Hashable, Sendable, Codable { | ||
public let id: Snowflake? | ||
public let name: String? | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// | ||
// Guild+API.swift | ||
// | ||
// | ||
// Created by Jaehong Kang on 2022/07/21. | ||
// | ||
|
||
import Foundation | ||
#if canImport(FoundationNetworking) | ||
import FoundationNetworking | ||
#endif | ||
import Discord | ||
|
||
extension Guild { | ||
public static func myGuilds(session: Session) async throws -> [Guild] { | ||
var urlRequest = URLRequest(url: URL(discordAPIPath: "v10/users/@me/guilds")!) | ||
urlRequest.httpMethod = "GET" | ||
|
||
let (data, _) = try await session.data(for: urlRequest, includesOAuth2Credential: true) | ||
|
||
let guilds = try JSONDecoder.discord.decode([Guild].self, from: data) | ||
|
||
return guilds | ||
} | ||
} | ||
|
||
extension Guild { | ||
public init(guildID: Snowflake, session: Session) async throws { | ||
var urlRequest = URLRequest(url: URL(discordAPIPath: "v10/guilds/\(guildID.rawValue)")!) | ||
urlRequest.httpMethod = "GET" | ||
|
||
let (data, _) = try await session.data(for: urlRequest, includesOAuth2Credential: true) | ||
|
||
self = try JSONDecoder.discord.decode(Guild.self, from: data) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,187 @@ | ||
// | ||
// Guild.swift | ||
// | ||
// | ||
// Created by Jaehong Kang on 2022/07/19. | ||
// | ||
|
||
import Foundation | ||
import Discord | ||
|
||
public struct Guild { | ||
public enum VerificationLevel: Int, Sendable, Codable { | ||
case none = 0 | ||
case low | ||
case medium | ||
case high | ||
case veryHigh | ||
} | ||
|
||
public enum DefaultMessageNotificationLevel: Int, Sendable, Codable { | ||
case allMessages = 0 | ||
case onlyMentions | ||
} | ||
|
||
public enum ExplicitContentFilterLevel: Int, Sendable, Codable { | ||
case disabled = 0 | ||
case membersWithoutRoles | ||
case allMembers | ||
} | ||
|
||
public enum MFALevel: Int, Sendable, Codable { | ||
case none = 0 | ||
case elevated | ||
} | ||
|
||
public enum NSFWLevel: Int, Sendable, Codable { | ||
case `default` = 0 | ||
case explicit | ||
case safe | ||
case ageRestricted | ||
} | ||
|
||
public enum PremiumTier: Int, Sendable, Codable { | ||
case none = 0 | ||
case tier1 | ||
case tier2 | ||
case tier3 | ||
} | ||
|
||
public struct SystemChannelFlags: OptionSet, Codable, Sendable { | ||
public static let suppressJoinNotifications = Self.init(rawValue: 1 << 0) | ||
public static let suppressPremiumSubscriptions = Self.init(rawValue: 1 << 1) | ||
public static let suppressGuildReminderNotifications = Self.init(rawValue: 1 << 2) | ||
public static let suppressJoinNotificationsReplies = Self.init(rawValue: 1 << 3) | ||
|
||
public let rawValue: Int | ||
|
||
public init(rawValue: Int) { | ||
self.rawValue = rawValue | ||
} | ||
} | ||
|
||
public let id: Snowflake | ||
|
||
public let isUnavailable: Bool? | ||
|
||
public let name: String? | ||
public let icon: String? | ||
public let splash: String? | ||
public let discoverySplash: String? | ||
|
||
public let isOwner: Bool? | ||
public let ownerID: Snowflake? | ||
|
||
public let permissions: String? | ||
|
||
public let afkChannelID: Snowflake? | ||
public let afkTimeout: Int? | ||
|
||
public let isWidgetEnabled: Bool? | ||
public let widgetChannelID: Snowflake? | ||
|
||
public let verificationLevel: Unknown<VerificationLevel>? | ||
|
||
public let defaultMessageNotifications: Unknown<DefaultMessageNotificationLevel>? | ||
|
||
public let explicitContentFilter: Unknown<ExplicitContentFilterLevel>? | ||
|
||
public let roles: [Role]? | ||
public let emojis: [Emoji]? | ||
public let features: [String]? | ||
|
||
public let mfaLevel: Unknown<MFALevel>? | ||
|
||
public let applicationID: Snowflake? | ||
|
||
public let systemChannelID: Snowflake? | ||
public let systemChannelFlags: SystemChannelFlags? | ||
|
||
public let rulesChannelID: Snowflake? | ||
|
||
public let maxPresences: Int? | ||
public let maxMembers: Int? | ||
|
||
public let vanityURLCode: String? | ||
public let description: String? | ||
public let banner: String? | ||
|
||
public let premiumTier: Unknown<PremiumTier>? | ||
public let premiumSubscriptionCount: Int? | ||
|
||
public let preferredLocale: String? | ||
|
||
public let publicUpdatesChannelID: Snowflake? | ||
|
||
public let maxVideoChannelUsers: Int? | ||
|
||
public let approximateMemberCount: Int? | ||
public let approximatePresenceCount: Int? | ||
|
||
public let welcomeScreen: WelcomeScreen? | ||
|
||
public let nsfwLevel: Unknown<NSFWLevel>? | ||
|
||
public let stickers: [Sticker]? | ||
|
||
public let isPremiumProgressBarEnabled: Bool? | ||
} | ||
|
||
extension Guild: Codable { | ||
enum CodingKeys: String, CodingKey { | ||
case id | ||
|
||
case isUnavailable = "unavailable" | ||
|
||
case name | ||
case icon | ||
case splash | ||
case discoverySplash | ||
|
||
case isOwner = "owner" | ||
case ownerID = "ownerId" | ||
|
||
case permissions | ||
|
||
case afkChannelID = "afkChannelId" | ||
case afkTimeout | ||
|
||
case isWidgetEnabled = "widgetEnabled" | ||
case widgetChannelID = "widgetChannelId" | ||
|
||
case verificationLevel | ||
|
||
case defaultMessageNotifications | ||
|
||
case explicitContentFilter | ||
|
||
case roles | ||
case emojis | ||
case features | ||
|
||
case mfaLevel | ||
|
||
case applicationID = "applicationId" | ||
|
||
case systemChannelID = "systemChannelId" | ||
case systemChannelFlags | ||
case rulesChannelID = "rulesChannelId" | ||
case maxPresences | ||
case maxMembers | ||
case vanityURLCode = "vanityUrlCode" | ||
case description | ||
case banner | ||
case premiumTier | ||
case premiumSubscriptionCount | ||
case preferredLocale | ||
case publicUpdatesChannelID = "publicUpdatesChannelId" | ||
case maxVideoChannelUsers | ||
case approximateMemberCount | ||
case approximatePresenceCount | ||
case welcomeScreen | ||
case nsfwLevel | ||
case stickers | ||
case isPremiumProgressBarEnabled = "premiumProgressBarEnabled" | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// | ||
// Role.swift | ||
// | ||
// | ||
// Created by Jaehong Kang on 2022/07/21. | ||
// | ||
|
||
import Foundation | ||
import Discord | ||
|
||
// TODO: Implement Properties | ||
public struct Role: Equatable, Hashable, Identifiable, Sendable, Codable { | ||
public let id: Snowflake | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// | ||
// Sticker.swift | ||
// | ||
// | ||
// Created by Jaehong Kang on 2022/07/21. | ||
// | ||
|
||
import Foundation | ||
import Discord | ||
|
||
// TODO: Implement Properties | ||
public struct Sticker: Equatable, Hashable, Identifiable, Sendable, Codable { | ||
public let id: Snowflake | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// | ||
// WelcomeScreen.swift | ||
// | ||
// | ||
// Created by Jaehong Kang on 2022/07/21. | ||
// | ||
|
||
import Foundation | ||
import Discord | ||
|
||
// TODO: Implement Properties | ||
public struct WelcomeScreen: Equatable, Hashable, Sendable, Codable { | ||
public let description: String? | ||
} |
Oops, something went wrong.