diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..0d1cbf8 --- /dev/null +++ b/.env.example @@ -0,0 +1 @@ +TG_BOT_API="" diff --git a/.gitignore b/.gitignore index 0023a53..6389029 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,6 @@ DerivedData/ .swiftpm/configuration/registries.json .swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata .netrc +.env +.env.* +!.env.example diff --git a/.mise.toml b/.mise.toml new file mode 100644 index 0000000..9ef59e9 --- /dev/null +++ b/.mise.toml @@ -0,0 +1,2 @@ +[tools] +swiftlint = "latest" diff --git a/Package.swift b/Package.swift index ef9e02b..7cc2feb 100644 --- a/Package.swift +++ b/Package.swift @@ -3,13 +3,12 @@ import PackageDescription - var packageDependencies: [Package.Dependency] = [ - .package(url: "https://github.com/vapor/vapor.git", .upToNextMajor(from: "4.57.0")), + .package(url: "https://github.com/vapor/vapor.git", .upToNextMajor(from: "4.57.0")) ] var targetDependencies: [PackageDescription.Target.Dependency] = [ - .product(name: "Vapor", package: "vapor"), + .product(name: "Vapor", package: "vapor") ] packageDependencies.append(.package(url: "https://github.com/nerzh/swift-telegram-sdk", .upToNextMajor(from: "3.0.3"))) @@ -24,6 +23,6 @@ let package = Package( .executableTarget( name: "TelegramModeratorBot", dependencies: targetDependencies - ), + ) ] ) diff --git a/Sources/TelegramModeratorBot/VaporTGClient.swift b/Sources/TelegramModeratorBot/VaporTGClient.swift index c828a27..c526c0f 100644 --- a/Sources/TelegramModeratorBot/VaporTGClient.swift +++ b/Sources/TelegramModeratorBot/VaporTGClient.swift @@ -17,15 +17,15 @@ public enum TGHTTPMediaType: String, Equatable { private struct TGEmptyParams: Encodable {} public final class VaporTGClient: TGClientPrtcl { - + public typealias HTTPMediaType = SwiftTelegramSdk.HTTPMediaType public var log: Logging.Logger = .init(label: "VaporTGClient") private let client: Vapor.Client - + public init(client: Vapor.Client) { self.client = client } - + @discardableResult public func post ( @@ -66,12 +66,12 @@ public final class VaporTGClient: TGClientPrtcl { let telegramContainer: TGTelegramContainer = try clientResponse.content.decode(TGTelegramContainer.self) return try processContainer(telegramContainer) } - + @discardableResult public func post(_ url: URL) async throws -> Response { try await post(url, params: TGEmptyParams(), as: nil) } - + private func processContainer(_ container: TGTelegramContainer) throws -> T { guard container.ok else { let desc = """ @@ -86,7 +86,7 @@ public final class VaporTGClient: TGClientPrtcl { log.error(error.logMessage) throw error } - + guard let result = container.result else { let error = BotError( type: .server, @@ -95,14 +95,14 @@ public final class VaporTGClient: TGClientPrtcl { log.error(error.logMessage) throw error } - + let logString = """ - + Response: Code: \(container.errorCode ?? 0) Status OK: \(container.ok) Description: \(container.description ?? "Empty") - + """ log.trace(logString.logMessage) return result diff --git a/Sources/TelegramModeratorBot/routes.swift b/Sources/TelegramModeratorBot/routes.swift index 236285c..4e2cb44 100644 --- a/Sources/TelegramModeratorBot/routes.swift +++ b/Sources/TelegramModeratorBot/routes.swift @@ -1,4 +1,3 @@ - /* import Vapor