Skip to content

Commit 735dcd6

Browse files
committed
Move weather query into reaction handler
1 parent 472fe89 commit 735dcd6

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

Diff for: Sources/D2Handlers/D2Receiver.swift

+1-8
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,7 @@ public class D2Receiver: Receiver {
8181
MentionD2Handler(conversator: FollowUpConversator(messageDB: messageDB)),
8282
MentionSomeoneHandler(),
8383
MessagePreviewHandler(configuration: _messagePreviewsConfiguration),
84-
TriggerReactionHandler {
85-
guard let city = cityConfiguration.city else { throw ReactionTriggerError.other("No city specified") }
86-
return OpenWeatherMapQuery(city: city).perform()
87-
.mapCatching {
88-
guard let emoji = $0.emoji else { throw ReactionTriggerError.other("No weather emoji") }
89-
return emoji
90-
}
91-
},
84+
TriggerReactionHandler(cityConfiguration: _cityConfiguration),
9285
CountToNHandler(),
9386
UniversalSummoningHandler(hostInfo: hostInfo),
9487
HaikuHandler(configuration: _haikuConfiguration, inventoryManager: inventoryManager),

Diff for: Sources/D2Handlers/message/handler/TriggerReactionHandler.swift

+12-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ public struct TriggerReactionHandler: MessageHandler {
1515

1616
public init(
1717
dateSpecificReactions: Bool = true,
18-
weatherEmojiProvider: @escaping () throws -> Promise<String, any Error>
18+
weatherReactions: Bool = true,
19+
cityConfiguration: AutoSerializing<CityConfiguration>
1920
) {
2021
self.init(triggers: [
2122
.init(keywords: ["hello"], emoji: "👋"),
@@ -60,8 +61,16 @@ public struct TriggerReactionHandler: MessageHandler {
6061
}
6162
}
6263

63-
// React with the weather
64-
return try weatherEmojiProvider()
64+
if weatherReactions {
65+
guard let city = cityConfiguration.wrappedValue.city else { throw ReactionTriggerError.other("No city specified") }
66+
return OpenWeatherMapQuery(city: city).perform()
67+
.mapCatching {
68+
guard let emoji = $0.emoji else { throw ReactionTriggerError.other("No weather emoji") }
69+
return emoji
70+
}
71+
}
72+
73+
throw ReactionTriggerError.other("No good morning/evening reaction configured")
6574
}
6675
}
6776
])

0 commit comments

Comments
 (0)