From 1cc97f2625c5f5465dd800992d64eb9ea5eceeec Mon Sep 17 00:00:00 2001 From: Veit Progl Date: Wed, 18 Dec 2024 13:44:05 +0100 Subject: [PATCH 1/3] Add apple typos --- .../Command/Message Commands/AppleTypos.swift | 30 +++++++++++++++++++ Sources/SwiftDEBot/Commands.swift | 3 ++ 2 files changed, 33 insertions(+) create mode 100644 Sources/SwiftDEBot/Command/Message Commands/AppleTypos.swift diff --git a/Sources/SwiftDEBot/Command/Message Commands/AppleTypos.swift b/Sources/SwiftDEBot/Command/Message Commands/AppleTypos.swift new file mode 100644 index 0000000..fa73cfc --- /dev/null +++ b/Sources/SwiftDEBot/Command/Message Commands/AppleTypos.swift @@ -0,0 +1,30 @@ +import DiscordBM +import Foundation + +struct iPhoneTypoCommand: MessageCommand { + let helpText = "" + + func run(client: DiscordClient, message: Gateway.MessageCreate) async throws { + let content = message.content + guard content.contains("Iphone") || content.contains("IFöhn") || content.contains("ipHone") || content.contains("IPhone"), + let handle = message.author?.mentionHandle + else { + return + } + try await client.send("Psst \(handle), das schreibt sich iPhone.", to: message.channel_id) + } +} + +struct iPadTypoCommand: MessageCommand { + let helpText = "" + + func run(client: DiscordClient, message: Gateway.MessageCreate) async throws { + let content = message.content + guard content.contains("Ipad") || content.contains("IPad"), + let handle = message.author?.mentionHandle + else { + return + } + try await client.send("Psst \(handle), das schreibt sich iPad.", to: message.channel_id) + } +} diff --git a/Sources/SwiftDEBot/Commands.swift b/Sources/SwiftDEBot/Commands.swift index f2e5eb9..731aae2 100644 --- a/Sources/SwiftDEBot/Commands.swift +++ b/Sources/SwiftDEBot/Commands.swift @@ -13,6 +13,9 @@ let messageCommands: [MessageCommand] = [ HelpCommand(), UptimeCommand(), PingCommand(), + + iPhoneTypoCommand(), + iPadTypoCommand(), ] let reactionCommands: [ReactionCommand] = [ From 0e1903f077d6da6f425b5932bf046c7bf140b629 Mon Sep 17 00:00:00 2001 From: Veit Progl Date: Wed, 18 Dec 2024 14:09:55 +0100 Subject: [PATCH 2/3] Move AppleTypos to generic TypoCommand --- .../Command/Message Commands/AppleTypos.swift | 30 ------------------- .../Message Commands/TypoCommand.swift | 23 ++++++++++++++ Sources/SwiftDEBot/Commands.swift | 3 +- 3 files changed, 24 insertions(+), 32 deletions(-) delete mode 100644 Sources/SwiftDEBot/Command/Message Commands/AppleTypos.swift create mode 100644 Sources/SwiftDEBot/Command/Message Commands/TypoCommand.swift diff --git a/Sources/SwiftDEBot/Command/Message Commands/AppleTypos.swift b/Sources/SwiftDEBot/Command/Message Commands/AppleTypos.swift deleted file mode 100644 index fa73cfc..0000000 --- a/Sources/SwiftDEBot/Command/Message Commands/AppleTypos.swift +++ /dev/null @@ -1,30 +0,0 @@ -import DiscordBM -import Foundation - -struct iPhoneTypoCommand: MessageCommand { - let helpText = "" - - func run(client: DiscordClient, message: Gateway.MessageCreate) async throws { - let content = message.content - guard content.contains("Iphone") || content.contains("IFöhn") || content.contains("ipHone") || content.contains("IPhone"), - let handle = message.author?.mentionHandle - else { - return - } - try await client.send("Psst \(handle), das schreibt sich iPhone.", to: message.channel_id) - } -} - -struct iPadTypoCommand: MessageCommand { - let helpText = "" - - func run(client: DiscordClient, message: Gateway.MessageCreate) async throws { - let content = message.content - guard content.contains("Ipad") || content.contains("IPad"), - let handle = message.author?.mentionHandle - else { - return - } - try await client.send("Psst \(handle), das schreibt sich iPad.", to: message.channel_id) - } -} diff --git a/Sources/SwiftDEBot/Command/Message Commands/TypoCommand.swift b/Sources/SwiftDEBot/Command/Message Commands/TypoCommand.swift new file mode 100644 index 0000000..c2d221f --- /dev/null +++ b/Sources/SwiftDEBot/Command/Message Commands/TypoCommand.swift @@ -0,0 +1,23 @@ +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"] + ] + + 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/Commands.swift b/Sources/SwiftDEBot/Commands.swift index 731aae2..e9378b3 100644 --- a/Sources/SwiftDEBot/Commands.swift +++ b/Sources/SwiftDEBot/Commands.swift @@ -14,8 +14,7 @@ let messageCommands: [MessageCommand] = [ UptimeCommand(), PingCommand(), - iPhoneTypoCommand(), - iPadTypoCommand(), + TypoCommand(), ] let reactionCommands: [ReactionCommand] = [ From bd97afbc3420f6c4157d2a8b75dc2f57d7dab618 Mon Sep 17 00:00:00 2001 From: Veit Progl Date: Wed, 18 Dec 2024 14:15:53 +0100 Subject: [PATCH 3/3] move xcode typo to typoCommand --- .../Command/Message Commands/TypoCommand.swift | 3 ++- .../Command/Message Commands/Xcode.swift | 14 -------------- Sources/SwiftDEBot/Commands.swift | 1 - 3 files changed, 2 insertions(+), 16 deletions(-) diff --git a/Sources/SwiftDEBot/Command/Message Commands/TypoCommand.swift b/Sources/SwiftDEBot/Command/Message Commands/TypoCommand.swift index c2d221f..3c7e09f 100644 --- a/Sources/SwiftDEBot/Command/Message Commands/TypoCommand.swift +++ b/Sources/SwiftDEBot/Command/Message Commands/TypoCommand.swift @@ -6,7 +6,8 @@ struct TypoCommand: MessageCommand { let trigger: [String: [String]] = [ "iPhone": ["Iphone", "ipPhone", "IPhone", "IFöhn"], - "iPad": ["IPad", "Ipad"] + "iPad": ["IPad", "Ipad"], + "Xcode": ["XCode", "xCode"] ] func run(client: DiscordClient, message: Gateway.MessageCreate) async throws { 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 e9378b3..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(),