Skip to content

Commit 311e336

Browse files
committed
Add link to double factorial
1 parent 928efaa commit 311e336

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

Diff for: Sources/D2Handlers/Message/Handler/FactorialHandler.swift

+7-1
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,14 @@ public struct FactorialHandler: MessageHandler {
2424
let `operator` = match.output.operator
2525
let alpha = `operator`.count
2626
let result = multifactorial(operand, alpha)
27+
let link: String? = switch alpha {
28+
case 1: nil
29+
case 2: "https://en.wikipedia.org/wiki/Double_factorial"
30+
default: "https://en.wikipedia.org/wiki/Double_factorial#Definitions"
31+
}
32+
let formattedOperator = link.map { "[\(`operator`)](<\($0)>)" } ?? "\(`operator`)"
2733
do {
28-
try await sink.sendMessage("\(operand)\(`operator`) = \(result.isLessThanOrEqualTo(Double(Int.max)) ? String(Int(result)) : String(result))", to: channelId)
34+
try await sink.sendMessage("\(operand)\(formattedOperator) = \(result.isLessThanOrEqualTo(Double(Int.max)) ? String(Int(result)) : String(result))", to: channelId)
2935
} catch {
3036
log.warning("Could not send factorial message: \(error)")
3137
}

0 commit comments

Comments
 (0)