Skip to content

Commit

Permalink
Make DemoReceiver final to fix Sendable conformance
Browse files Browse the repository at this point in the history
  • Loading branch information
fwcd committed Oct 19, 2024
1 parent 74df210 commit 3ecb668
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 8 deletions.
6 changes: 3 additions & 3 deletions Sources/D2Handlers/D2Receiver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ public class D2Receiver: Receiver {
}

public func on(receiveReady: [String: Any], sink: any Sink) async {
let guildCount = sink.guilds?.count ?? 0
let guildCount = await sink.guilds?.count ?? 0
log.info("Received ready! \(guildCount) \("guild".pluralized(with: guildCount)) found.")

if let presence = initialPresence {
Expand All @@ -483,7 +483,7 @@ public class D2Receiver: Receiver {
}

do {
try partyGameDB.setupTables()
try await partyGameDB.setupTables()
} catch {
log.warning("Could not setup party game database: \(error)")
}
Expand All @@ -501,7 +501,7 @@ public class D2Receiver: Receiver {
.prefix(10)

let options = shownCmds
.map {
.asyncMap { @CommandActor in
MIOCommand.Option(
type: .subCommand,
name: ([$0.name] + $0.aliases).first { (3..<32).contains($0.count) } ?? $0.name.truncated(to: 28, appending: "..."),
Expand Down
2 changes: 1 addition & 1 deletion Sources/D2Handlers/DemoReceiver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Logging

fileprivate let log = Logger(label: "D2Handlers.DemoReceiver")

public class DemoReceiver: Receiver {
public final class DemoReceiver: Receiver {
public func on(createMessage message: Message, sink: any Sink) {
log.info("Created message \(message.content)")
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import NIO
import Utils
import D2MessageIO
import D2Permissions
import D2Commands
Expand Down Expand Up @@ -31,7 +32,7 @@ public struct MIOCommandInteractionHandler: InteractionHandler {
content: content,
author: interaction.member?.user,
channelId: interaction.channelId,
guild: interaction.guildId.flatMap(sink.guild(for:)),
guild: interaction.guildId.asyncFlatMap(sink.guild(for:)),
guildMember: interaction.member
),
commandPrefix: "/", // TODO: Find a more elegant solution than hardcoding the slash
Expand All @@ -45,7 +46,7 @@ public struct MIOCommandInteractionHandler: InteractionHandler {
await output.append(errorText: "The interaction must have an author!")
return true
}
guard let command = registry[invocation.name] else {
guard let command = await registry[invocation.name] else {
await output.append(errorText: "Unknown command name `\(invocation.name)`")
return true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public struct SubscriptionInteractionHandler: InteractionHandler {
subscriptions: $1,
eventLoopGroup: eventLoopGroup
)
let output = MessageIOInteractionOutput(interaction: interaction, context: context)
let output = await MessageIOInteractionOutput(interaction: interaction, context: context)
await registry[$0]?.onSubscriptionInteraction(with: customId, by: user, output: output, context: context)
}
return true
Expand Down
3 changes: 2 additions & 1 deletion Sources/D2Handlers/Message/Handler/SubscriptionManager.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import D2MessageIO
import D2Commands

@CommandActor
public class SubscriptionManager {
private let registry: CommandRegistry
private var subscriptionSets: [String: SubscriptionSet] = [:]
Expand All @@ -25,7 +26,7 @@ public class SubscriptionManager {
subscriptionSets[commandName]?.contains(channel) ?? false
}

public func notifySubscriptions(on channel: ChannelID, isBot: Bool, action: (String, SubscriptionSet) async -> Void) async {
public func notifySubscriptions(on channel: ChannelID, isBot: Bool, action: @CommandActor (String, SubscriptionSet) async -> Void) async {
for (commandName, subscriptionSet) in subscriptionSets {
let allowed = !isBot || !(registry[commandName]?.info.subscriptionsUserOnly ?? true)
if allowed && subscriptionSet.contains(channel) {
Expand Down

0 comments on commit 3ecb668

Please sign in to comment.