Skip to content

Commit

Permalink
Migrate MarkovCommand to regex literals
Browse files Browse the repository at this point in the history
  • Loading branch information
fwcd committed Feb 14, 2024
1 parent aed6e74 commit abb11dd
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions Sources/D2Commands/misc/MarkovCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import D2MessageIO
import D2Permissions
import Utils

fileprivate let flagPattern = try! LegacyRegex(from: "--(\\S+)")
fileprivate let pingPattern = try! LegacyRegex(from: "<@&?.+?>")
fileprivate let flagPattern = #/--(\S+)/#
fileprivate let pingPattern = #/<@&?.+?>/#

// TODO: Use Arg API

Expand All @@ -24,8 +24,8 @@ public class MarkovCommand: StringCommand {
}

public func invoke(with input: String, output: any CommandOutput, context: CommandContext) {
let flags = Set<String>(flagPattern.allGroups(in: input).map { $0[1] })
let cleanedInput = flagPattern.replace(in: input, with: "").nilIfEmpty
let flags = Set<String>(input.matches(of: flagPattern).map { String($0.1) })
let cleanedInput = input.replacing(flagPattern, with: "").nilIfEmpty

do {
// TODO: Use proper initial distribution without sacrificing performance
Expand Down

0 comments on commit abb11dd

Please sign in to comment.