fix: formatting code using swiftlint and added env example
This commit is contained in:
parent
a11d671942
commit
d1d0292045
6 changed files with 18 additions and 14 deletions
1
.env.example
Normal file
1
.env.example
Normal file
|
@ -0,0 +1 @@
|
||||||
|
TG_BOT_API=""
|
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -6,3 +6,6 @@ DerivedData/
|
||||||
.swiftpm/configuration/registries.json
|
.swiftpm/configuration/registries.json
|
||||||
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
|
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
|
||||||
.netrc
|
.netrc
|
||||||
|
.env
|
||||||
|
.env.*
|
||||||
|
!.env.example
|
||||||
|
|
2
.mise.toml
Normal file
2
.mise.toml
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
[tools]
|
||||||
|
swiftlint = "latest"
|
|
@ -3,13 +3,12 @@
|
||||||
|
|
||||||
import PackageDescription
|
import PackageDescription
|
||||||
|
|
||||||
|
|
||||||
var packageDependencies: [Package.Dependency] = [
|
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] = [
|
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")))
|
packageDependencies.append(.package(url: "https://github.com/nerzh/swift-telegram-sdk", .upToNextMajor(from: "3.0.3")))
|
||||||
|
@ -24,6 +23,6 @@ let package = Package(
|
||||||
.executableTarget(
|
.executableTarget(
|
||||||
name: "TelegramModeratorBot",
|
name: "TelegramModeratorBot",
|
||||||
dependencies: targetDependencies
|
dependencies: targetDependencies
|
||||||
),
|
)
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
|
@ -17,15 +17,15 @@ public enum TGHTTPMediaType: String, Equatable {
|
||||||
private struct TGEmptyParams: Encodable {}
|
private struct TGEmptyParams: Encodable {}
|
||||||
|
|
||||||
public final class VaporTGClient: TGClientPrtcl {
|
public final class VaporTGClient: TGClientPrtcl {
|
||||||
|
|
||||||
public typealias HTTPMediaType = SwiftTelegramSdk.HTTPMediaType
|
public typealias HTTPMediaType = SwiftTelegramSdk.HTTPMediaType
|
||||||
public var log: Logging.Logger = .init(label: "VaporTGClient")
|
public var log: Logging.Logger = .init(label: "VaporTGClient")
|
||||||
private let client: Vapor.Client
|
private let client: Vapor.Client
|
||||||
|
|
||||||
public init(client: Vapor.Client) {
|
public init(client: Vapor.Client) {
|
||||||
self.client = client
|
self.client = client
|
||||||
}
|
}
|
||||||
|
|
||||||
@discardableResult
|
@discardableResult
|
||||||
public func post<Params: Encodable, Response: Decodable>
|
public func post<Params: Encodable, Response: Decodable>
|
||||||
(
|
(
|
||||||
|
@ -66,12 +66,12 @@ public final class VaporTGClient: TGClientPrtcl {
|
||||||
let telegramContainer: TGTelegramContainer = try clientResponse.content.decode(TGTelegramContainer<Response>.self)
|
let telegramContainer: TGTelegramContainer = try clientResponse.content.decode(TGTelegramContainer<Response>.self)
|
||||||
return try processContainer(telegramContainer)
|
return try processContainer(telegramContainer)
|
||||||
}
|
}
|
||||||
|
|
||||||
@discardableResult
|
@discardableResult
|
||||||
public func post<Response: Decodable>(_ url: URL) async throws -> Response {
|
public func post<Response: Decodable>(_ url: URL) async throws -> Response {
|
||||||
try await post(url, params: TGEmptyParams(), as: nil)
|
try await post(url, params: TGEmptyParams(), as: nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
private func processContainer<T: Decodable>(_ container: TGTelegramContainer<T>) throws -> T {
|
private func processContainer<T: Decodable>(_ container: TGTelegramContainer<T>) throws -> T {
|
||||||
guard container.ok else {
|
guard container.ok else {
|
||||||
let desc = """
|
let desc = """
|
||||||
|
@ -86,7 +86,7 @@ public final class VaporTGClient: TGClientPrtcl {
|
||||||
log.error(error.logMessage)
|
log.error(error.logMessage)
|
||||||
throw error
|
throw error
|
||||||
}
|
}
|
||||||
|
|
||||||
guard let result = container.result else {
|
guard let result = container.result else {
|
||||||
let error = BotError(
|
let error = BotError(
|
||||||
type: .server,
|
type: .server,
|
||||||
|
@ -95,14 +95,14 @@ public final class VaporTGClient: TGClientPrtcl {
|
||||||
log.error(error.logMessage)
|
log.error(error.logMessage)
|
||||||
throw error
|
throw error
|
||||||
}
|
}
|
||||||
|
|
||||||
let logString = """
|
let logString = """
|
||||||
|
|
||||||
Response:
|
Response:
|
||||||
Code: \(container.errorCode ?? 0)
|
Code: \(container.errorCode ?? 0)
|
||||||
Status OK: \(container.ok)
|
Status OK: \(container.ok)
|
||||||
Description: \(container.description ?? "Empty")
|
Description: \(container.description ?? "Empty")
|
||||||
|
|
||||||
"""
|
"""
|
||||||
log.trace(logString.logMessage)
|
log.trace(logString.logMessage)
|
||||||
return result
|
return result
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
/*
|
/*
|
||||||
import Vapor
|
import Vapor
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue