Skip to content

Commit 46dbc4b

Browse files
committed
add remaining BotMessage fields & ext method
1 parent 0d377f0 commit 46dbc4b

File tree

1 file changed

+45
-19
lines changed

1 file changed

+45
-19
lines changed
Lines changed: 45 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,75 @@
11
//
22
// BotMessage.swift
3-
//
3+
//
44
//
55
// Created by Vincent Kwok on 22/11/22.
66
//
77

8-
import Foundation
98
import DiscordKitCore
9+
import Foundation
1010

1111
/// A Discord message, with convenience methods
1212
///
1313
/// This struct represents a message on Discord,
1414
/// > Internally, `Message`s are converted to and from this type
1515
/// > for easier use
1616
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+
2652
public let inner: Message
2753

2854
// The REST handler associated with this message, used for message actions
2955
fileprivate weak var rest: DiscordREST?
3056

3157
internal init(from message: Message, rest: DiscordREST) {
3258
self.inner = message
33-
// content = message.content
34-
// channelID = message.channel_id
35-
// id = message.id
36-
// author = message.author
37-
3859
self.rest = rest
3960
}
4061
}
4162

42-
public extension BotMessage {
43-
func reply(_ content: String) async throws -> Message {
63+
extension BotMessage {
64+
public func reply(_ content: String) async throws -> Message {
4465
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: []),
4668
id: channelID
4769
)
4870
}
71+
72+
public func mentions(_ userID: Snowflake) -> Bool {
73+
return mentions.first(identifiedBy: userID) != nil
74+
}
4975
}

0 commit comments

Comments
 (0)