Files
interject/interject/Interject!/Intents.swift
T
2026-07-25 20:09:20 -05:00

39 lines
1.3 KiB
Swift

//
// Intents.swift
// Interject!
//
import AppIntents
struct GenerateDescriptorIntent: AppIntent {
static var title: LocalizedStringResource = "Interject"
static var description = IntentDescription("Generates a new random descriptive phrase.")
func perform() async throws -> some IntentResult & ReturnsValue<String> {
// Fall back to true (safe mode) if the app hasn't set the preference yet
let isSfw = UserDefaults.standard.object(forKey: "SFW") as? Bool ?? true
let sentence = Sentence().new(current: Sentence())
let interjection = [
sentence.word(.first, safe: isSfw),
sentence.word(.second, safe: isSfw),
sentence.word(.noun, safe: isSfw)
].joined(separator: " ")
return .result(value: interjection, dialog: IntentDialog(stringLiteral: interjection))
}
}
struct InterjectShortcuts: AppShortcutsProvider {
static var appShortcuts: [AppShortcut] {
AppShortcut(
intent: GenerateDescriptorIntent(),
phrases: [
"Generate an interjection with \(.applicationName)",
"Describe me with \(.applicationName)",
"Give me an interjection from \(.applicationName)"
],
shortTitle: "Generate Interjection",
systemImageName: "bubble.left.fill"
)
}
}