|
1 | 1 | //
|
2 | 2 | // BotMessage.swift
|
3 |
| -// |
| 3 | +// |
4 | 4 | //
|
5 | 5 | // Created by Vincent Kwok on 22/11/22.
|
6 | 6 | //
|
7 | 7 |
|
8 |
| -import Foundation |
9 | 8 | import DiscordKitCore
|
| 9 | +import Foundation |
10 | 10 |
|
11 | 11 | /// A Discord message, with convenience methods
|
12 | 12 | ///
|
13 | 13 | /// This struct represents a message on Discord,
|
14 | 14 | /// > Internally, `Message`s are converted to and from this type
|
15 | 15 | /// > for easier use
|
16 | 16 | public struct BotMessage {
|
17 |
| -// public let content: String |
18 |
| -// public let channelID: Snowflake // This will be changed very soon |
19 |
| -// public let id: Snowflake // This too |
20 |
| -// public let author: User |
21 |
| - |
22 |
| - public var content: String { get { return inner.content } } |
23 |
| - public var channelID: Snowflake { get { return inner.channel_id } } |
24 |
| - public var id: Snowflake { get { return inner.id } } |
25 |
| - |
| 17 | + public var id: Snowflake { return inner.id } |
| 18 | + public var channelID: Snowflake { return inner.channel_id } |
| 19 | + public var guildID: Snowflake? { return inner.guild_id } |
| 20 | + public var author: User { return inner.author } |
| 21 | + public var member: Member? { return inner.member } |
| 22 | + public var timestamp: Date { return inner.timestamp } |
| 23 | + public var editedTimestamp: Date? { return inner.edited_timestamp } |
| 24 | + public var tts: Bool { return inner.tts } |
| 25 | + public var mentionEveryone: Bool { return inner.mention_everyone } |
| 26 | + public var mentions: [User] { return inner.mentions } |
| 27 | + public var mentionRoles: [Snowflake] { return inner.mention_roles } |
| 28 | + public var mentionChannels: [ChannelMention]? { return inner.mention_channels } |
| 29 | + public var attachments: [Attachment] { return inner.attachments } |
| 30 | + public var embeds: [Embed] { return inner.embeds } |
| 31 | + public var reactions: [Reaction]? { return inner.reactions } |
| 32 | + public var nonce: Nonce? { return inner.nonce } |
| 33 | + public var pinned: Bool { return inner.pinned } |
| 34 | + public var webhookId: Snowflake? { return inner.webhook_id } |
| 35 | + public var type: MessageType { return inner.type } |
| 36 | + public var activity: MessageActivity? { return inner.activity } |
| 37 | + public var application: Application? { return inner.application } |
| 38 | + public var applicationId: Snowflake? { return inner.application_id } |
| 39 | + public var messageReference: MessageReference? { return inner.message_reference } |
| 40 | + public var flags: Int? { return inner.flags } |
| 41 | + public var referencedMessage: BotMessage? { |
| 42 | + guard let ref = inner.referenced_message else { return nil } |
| 43 | + return Self(from: ref, rest: self.rest!) |
| 44 | + } |
| 45 | + public var interaction: MessageInteraction? { return inner.interaction } |
| 46 | + public var thread: Channel? { return inner.thread } |
| 47 | + public var components: [MessageComponent]? { return inner.components } |
| 48 | + public var stickerItems: [StickerItem]? { return inner.sticker_items } |
| 49 | + public var call: CallMessageComponent? { return inner.call } |
| 50 | + public var content: String { return inner.content } |
| 51 | + |
26 | 52 | public let inner: Message
|
27 | 53 |
|
28 | 54 | // The REST handler associated with this message, used for message actions
|
29 | 55 | fileprivate weak var rest: DiscordREST?
|
30 | 56 |
|
31 | 57 | internal init(from message: Message, rest: DiscordREST) {
|
32 | 58 | self.inner = message
|
33 |
| -// content = message.content |
34 |
| -// channelID = message.channel_id |
35 |
| -// id = message.id |
36 |
| -// author = message.author |
37 |
| - |
38 | 59 | self.rest = rest
|
39 | 60 | }
|
40 | 61 | }
|
41 | 62 |
|
42 |
| -public extension BotMessage { |
43 |
| - func reply(_ content: String) async throws -> Message { |
| 63 | +extension BotMessage { |
| 64 | + public func reply(_ content: String) async throws -> Message { |
44 | 65 | return try await rest!.createChannelMsg(
|
45 |
| - message: .init(content: content, message_reference: .init(message_id: id), components: []), |
| 66 | + message: .init( |
| 67 | + content: content, message_reference: .init(message_id: id), components: []), |
46 | 68 | id: channelID
|
47 | 69 | )
|
48 | 70 | }
|
| 71 | + |
| 72 | + public func mentions(_ userID: Snowflake) -> Bool { |
| 73 | + return mentions.first(identifiedBy: userID) != nil |
| 74 | + } |
49 | 75 | }
|
0 commit comments