Skip to content

Commit

Permalink
Move to Swift 5.9 + More coin-sign cleanups (#117)
Browse files Browse the repository at this point in the history
  • Loading branch information
MahdiBM authored Sep 24, 2023
1 parent 4d01464 commit 05f2749
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 39 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy-all-lambdas.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
jobs:
deploy-lambdas:
runs-on: ubuntu-latest
container: swift:5.8-amazonlinux2
container: swift:5.9-amazonlinux2
env:
AWS_DEFAULT_REGION: eu-west-1
AWS_ACCESS_KEY_ID: ${{ secrets.DEPLOYER_ACCESS_KEY_ID }}
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# ================================
# Build image
# ================================
FROM swift:5.8-jammy as build
FROM swift:5.9-jammy as build

# Install updates
RUN export DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true \
Expand Down
7 changes: 4 additions & 3 deletions Lambdas/GHOAuth/Models/GHOAuthPayload.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ import JWTKit

/// This Payload will get sent along with the OAuth redirect to the GitHub OAuth page,
/// specifically inside the `state` query parameter.
/// This is used to verify the user's identity when they come back from GitHub
/// and that the request is not forged.
public struct GHOAuthPayload: JWTPayload {
/// Used to verify the user's identity when they come back from GitHub.
public let discordID: UserSnowflake
/// The interaction token to respond back to user on Discord with and notify of the result.
public let interactionToken: String
/// Expiration time of the token.
public let expiration: ExpirationClaim

public init(discordID: UserSnowflake, interactionToken: String) {
Expand All @@ -19,4 +20,4 @@ public struct GHOAuthPayload: JWTPayload {
public func verify(using signer: JWTSigner) throws {
try self.expiration.verifyNotExpired()
}
}
}
50 changes: 40 additions & 10 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.8
// swift-tools-version:5.9
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription
Expand Down Expand Up @@ -29,16 +29,22 @@ let upcomingFeaturesSwiftSettings: [SwiftSetting] = [
]

let targetsSwiftSettings: [SwiftSetting] = upcomingFeaturesSwiftSettings + [
/// https://github.com/apple/swift/issues/67214
.unsafeFlags(["-Xllvm", "-vectorize-slp=false"], .when(platforms: [.linux], configuration: .release)),
/// https://github.com/apple/swift/issues/67214
.unsafeFlags(["-Xllvm", "-vectorize-slp=false"], .when(platforms: [.linux], configuration: .release)),

/// `minimal` / `targeted` / `complete`
.unsafeFlags(["-strict-concurrency=complete"]),
]
/// https://github.com/apple/swift/pull/68671
.unsafeFlags(
["-Xlinker", "-u", "-Xlinker", "_swift_backtrace_isThunkFunction"],
.when(platforms: [.linux], configuration: .release)
),

/// `minimal` / `targeted` / `complete`
.enableExperimentalFeature("StrictConcurrency=complete"),
]

let testsSwiftSettings: [SwiftSetting] = upcomingFeaturesSwiftSettings + [
/// `minimal` / `targeted` / `complete`
.unsafeFlags(["-strict-concurrency=targeted"])
.enableExperimentalFeature("StrictConcurrency=targeted"),
]

extension PackageDescription.Target {
Expand Down Expand Up @@ -74,7 +80,6 @@ let package = Package(
.package(url: "https://github.com/apple/swift-nio.git", from: "2.57.0"),
.package(url: "https://github.com/swift-server/async-http-client.git", from: "1.9.0"),
.package(url: "https://github.com/apple/swift-crypto.git", from: "2.0.0"),
.package(url: "https://github.com/swift-server/swift-backtrace.git", from: "1.3.1"),
.package(url: "https://github.com/apple/swift-collections.git", from: "1.0.0"),
.package(url: "https://github.com/vapor/jwt-kit.git", from: "4.13.0"),
.package(url: "https://github.com/apple/swift-atomics.git", from: "1.1.0"),
Expand Down Expand Up @@ -116,7 +121,6 @@ let package = Package(
.executableTarget(
name: "Penny",
dependencies: [
.product(name: "Backtrace", package: "swift-backtrace"),
.product(name: "DiscordBM", package: "DiscordBM"),
.product(name: "DiscordLogger", package: "DiscordLogger"),
.product(name: "AsyncHTTPClient", package: "async-http-client"),
Expand Down Expand Up @@ -254,11 +258,24 @@ let package = Package(
name: "Fake",
dependencies: [
.product(name: "SotoDynamoDB", package: "soto"),
.product(name: "SotoS3", package: "soto"),
.product(name: "SotoCore", package: "soto-core"),
.product(name: "DiscordBM", package: "DiscordBM"),
.product(name: "LeafKit", package: "leaf-kit"),
.product(name: "Markdown", package: "swift-markdown"),
.product(name: "SwiftSemver", package: "swift-semver"),
.product(name: "DiscordLogger", package: "DiscordLogger"),
.product(name: "JWTKit", package: "jwt-kit"),
.product(name: "AWSLambdaRuntime", package: "swift-aws-lambda-runtime"),
.product(name: "AWSLambdaEvents", package: "swift-aws-lambda-events"),
.product(name: "OpenAPIRuntime", package: "swift-openapi-runtime"),
.target(name: "GHHooksLambda"),
.target(name: "GitHubAPI"),
.target(name: "LambdasShared"),
.target(name: "Shared"),
.target(name: "Rendering"),
.target(name: "Models"),
.target(name: "Penny"),
.target(name: "GHHooksLambda"),
],
path: "./Tests/Fake",
swiftSettings: testsSwiftSettings
Expand All @@ -267,7 +284,20 @@ let package = Package(
name: "PennyTests",
dependencies: [
.product(name: "SotoDynamoDB", package: "soto"),
.product(name: "SotoS3", package: "soto"),
.product(name: "SotoCore", package: "soto-core"),
.product(name: "LeafKit", package: "leaf-kit"),
.product(name: "Markdown", package: "swift-markdown"),
.product(name: "SwiftSemver", package: "swift-semver"),
.product(name: "DiscordLogger", package: "DiscordLogger"),
.product(name: "JWTKit", package: "jwt-kit"),
.product(name: "AWSLambdaRuntime", package: "swift-aws-lambda-runtime"),
.product(name: "AWSLambdaEvents", package: "swift-aws-lambda-events"),
.target(name: "GitHubAPI"),
.target(name: "LambdasShared"),
.target(name: "Shared"),
.target(name: "Rendering"),
.target(name: "Models"),
.target(name: "Penny"),
.target(name: "GHHooksLambda"),
.target(name: "Fake"),
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ Penny is a Swift bot that works for the [Vapor](https://vapor.codes) community.
<img src="https://github.com/vapor/penny-bot/actions/workflows/deploy-penny.yml/badge.svg?branch=main" alt="Deploy Penny CI">
</a>
<a href="https://swift.org">
<img src="https://img.shields.io/badge/swift-5.8-brightgreen.svg" alt="Swift 5.8">
<img src="https://img.shields.io/badge/swift-5.9-brightgreen.svg" alt="Swift 5.9">
</a>
</p>

### Features
* [x] Give coins to the members when they're "thanked".
* [x] Automatically ping members based on the ping-words they have set up.
* Implemented as `/auto-pings` slash command.
* Implemented as `/auto-pings` slash command.
* [x] Respond to certain command-texts with predefined answers.
* Implemented as `/faqs` slash command.
* [x] Automatically respond to commonly asked questions.
Expand Down
9 changes: 9 additions & 0 deletions Sources/Penny/Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ enum Constants {
static let ghOAuthClientID = env("GH_OAUTH_CLIENT_ID")
static let accountLinkOAuthPrivKey = env("ACCOUNT_LINKING_OAUTH_FLOW_PRIV_KEY")

/// U+1F3FB EMOJI MODIFIER FITZPATRICK TYPE-1-2...TYPE-6
static var emojiSkins: [String] {
["", "\u{1f3fb}", "\u{1f3fc}", "\u{1f3fd}", "\u{1f3fe}", "\u{1f3ff}"]
}
/// U+2640 FEMALE SIGN, U+2642 MALE SIGN, U+200D ZWJ, U+FE0F VARIATION SELECTOR 16
static var emojiGenders: [String] {
["", "\u{200d}\u{2640}\u{fe0f}", "\u{200d}\u{2642}\u{fe0f}"]
}

enum ServerEmojis {
case coin
case vapor
Expand Down
10 changes: 4 additions & 6 deletions Sources/Penny/Handlers/CoinFinder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,17 @@ struct CoinFinder {
/// All coin signs must be lowercased.
/// Add a test when you add a coin sign.
static let coinSigns = [
"🙌", "🙌🏻", "🙌🏼", "🙌🏽", "🙌🏾", "🙌🏿",
"🙏", "🙏🏻", "🙏🏼", "🙏🏽", "🙏🏾", "🙏🏿",
"👌", "👌🏻", "👌🏼", "👌🏽", "👌🏾", "👌🏿",
"👍", "👍🏻", "👍🏼", "👍🏽", "👍🏾", "👍🏿",
"🪙",
Constants.ServerEmojis.coin.emoji,
"🚀", "🎉", "💯",
Constants.ServerEmojis.love.emoji,
"🚀", "🎉", "💯", "🪙",
"thx", "thanks", "thank you",
"thanks a lot", "thanks a bunch", "thanks so much",
"thank you a lot", "thank you a bunch", "thank you so much",
"thanks for the help", "thanks for your help",
"+= 1", "+ 1"
]
+ Constants.emojiSkins.map { "🙌\($0)" }
+ Constants.emojiSkins.map { "🙏\($0)" }

/// Two or more of these characters, like `++` or `++++++++++++`.
static let twoOrMore_coinSigns: [Character] = ["+"]
Expand Down
15 changes: 3 additions & 12 deletions Sources/Penny/Handlers/ReactionHandler/ReactionHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,6 @@ import Foundation
struct ReactionHandler {

enum Configuration {
/// U+1F3FB EMOJI MODIFIER FITZPATRICK TYPE-1-2...TYPE-6
private static var emojiSkins: [String] {
["","\u{1f3fb}","\u{1f3fc}","\u{1f3fd}","\u{1f3fe}","\u{1f3ff}"]
}
/// U+2640 FEMALE SIGN, U+2642 MALE SIGN, U+200D ZWJ, U+FE0F VARIATION SELECTOR 16
private static var emojiGenders: [String] {
["", "\u{200d}\u{2640}\u{fe0f}", "\u{200d}\u{2642}\u{fe0f}"]
}

static let coinSignEmojis: Set<String> = [
Constants.ServerEmojis.love.name,
Constants.ServerEmojis.vapor.name,
Expand All @@ -24,9 +15,9 @@ struct ReactionHandler {
"❤️", "💙", "💜", "🤍", "🤎", "🖤", "💛", "💚", "🧡",
"🩷", "🩶", "🩵", "💗", "💕", "😍", "😻", "🎉", "💯",
]
+ emojiSkins.map { "🙌\($0)" }
+ emojiSkins.map { "🙏\($0)" }
+ emojiSkins.flatMap { s in emojiGenders.map { g in "🙇\(s)\(g)" } }
+ Constants.emojiSkins.map { "🙌\($0)" }
+ Constants.emojiSkins.map { "🙏\($0)" }
+ Constants.emojiSkins.flatMap { s in Constants.emojiGenders.map { g in "🙇\(s)\(g)" } }
}

let event: Gateway.MessageReactionAdd
Expand Down
3 changes: 0 additions & 3 deletions Sources/Penny/Penny.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import NIOPosix
import AsyncHTTPClient
import SotoS3
import Backtrace

@main
struct Penny {
Expand All @@ -10,8 +9,6 @@ struct Penny {
}

static func start(mainService: any MainService) async throws {
Backtrace.install()

/// Use `1` instead of `System.coreCount`.
/// This is preferred for apps that primarily use structured concurrency.
let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1)
Expand Down
2 changes: 1 addition & 1 deletion Sources/Penny/ProposalsChecker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ struct ReviewLinksFinder: MarkupWalker {
}

// MARK: - QueuedProposal
struct QueuedProposal: Codable {
struct QueuedProposal: Sendable, Codable {
let uuid: UUID
let firstKnownStateBeforeQueue: Proposal.Status.State?
var updatedAt: Date
Expand Down

0 comments on commit 05f2749

Please sign in to comment.