diff --git a/Sources/SwiftDEBot/Command/Message Commands/TypoCommand.swift b/Sources/SwiftDEBot/Command/Message Commands/TypoCommand.swift new file mode 100644 index 0000000..3c7e09f --- /dev/null +++ b/Sources/SwiftDEBot/Command/Message Commands/TypoCommand.swift @@ -0,0 +1,24 @@ +import DiscordBM +import Foundation + +struct TypoCommand: MessageCommand { + let helpText = "Hilft bei der Korrektur von Tippfehlern in Nachrichten." + + let trigger: [String: [String]] = [ + "iPhone": ["Iphone", "ipPhone", "IPhone", "IFöhn"], + "iPad": ["IPad", "Ipad"], + "Xcode": ["XCode", "xCode"] + ] + + func run(client: DiscordClient, message: Gateway.MessageCreate) async throws { + let content = message.content + + for (correctWord, typos) in trigger { + if typos.contains(where: content.contains), + let handle = message.author?.mentionHandle { + try await client.send("Psst \(handle), das schreibt sich \(correctWord).", to: message.channel_id) + break + } + } + } +} diff --git a/Sources/SwiftDEBot/Command/Message Commands/Xcode.swift b/Sources/SwiftDEBot/Command/Message Commands/Xcode.swift index b44c073..bde602f 100644 --- a/Sources/SwiftDEBot/Command/Message Commands/Xcode.swift +++ b/Sources/SwiftDEBot/Command/Message Commands/Xcode.swift @@ -1,20 +1,6 @@ import DiscordBM import Foundation -struct XcodeTypoCommand: MessageCommand { - let helpText = "" - - func run(client: DiscordClient, message: Gateway.MessageCreate) async throws { - let content = message.content - guard content.contains("XCode") || content.contains("xCode"), - let handle = message.author?.mentionHandle - else { - return - } - try await client.send("Psst \(handle), das schreibt sich Xcode.", to: message.channel_id) - } -} - struct XcodeLatestCommand: MessageCommand { let helpText = "`!xcode`: Was ist die aktuellste Version von Xcode?" diff --git a/Sources/SwiftDEBot/Commands.swift b/Sources/SwiftDEBot/Commands.swift index f2e5eb9..d7bf2dd 100644 --- a/Sources/SwiftDEBot/Commands.swift +++ b/Sources/SwiftDEBot/Commands.swift @@ -1,7 +1,6 @@ import DiscordBM let messageCommands: [MessageCommand] = [ - XcodeTypoCommand(), XcodeLatestCommand(), SwiftEvolutionCommand(), AppleStatusCommand(), @@ -13,6 +12,8 @@ let messageCommands: [MessageCommand] = [ HelpCommand(), UptimeCommand(), PingCommand(), + + TypoCommand(), ] let reactionCommands: [ReactionCommand] = [