port overlort python ->Swift assed edition!

fukurou

the supreme coder
ADMIN
Swift:
class TrgTolerance {
    private var _maxRepeats: Int
    private var _repeats: Int

    init(_ maxrepeats: Int) {
        self._maxRepeats = maxrepeats
        self._repeats = 0
    }

    func setMaxRepeats(_ maxRepeats: Int) {
        self._maxRepeats = maxRepeats
        reset()
    }

    func reset() {
        _repeats = _maxRepeats
    }

    func trigger() -> Bool {
        _repeats -= 1
        return _repeats > 0
    }

    func disable() {
        _repeats = 0
    }
}
 

fukurou

the supreme coder
ADMIN
Swift:
class AXCmdBreaker {
    private var conjuration: String

    init(_ conjuration: String) {
        self.conjuration = conjuration
    }

    func extractCmdParam(_ s1: String) -> String {
        if s1.contains(conjuration) {
            return s1.replacingOccurrences(of: conjuration, with: "").trimmingCharacters(in: .whitespaces)
        }
        return ""
    }
}
 

fukurou

the supreme coder
ADMIN
Swift:
class AXContextCmd {
    var commands = UniqueItemSizeLimitedPriorityQueue(5)
    var contextCommands = UniqueItemSizeLimitedPriorityQueue(5)
    private var trgTolerance: Bool = false

    func engageCommand(_ s1: String) -> Bool {
        if s1.isEmpty {
            return false
        }
        if contextCommands.contains(s1) {
            trgTolerance = true
            return true
        }
        if trgTolerance && !commands.contains(s1) {
            trgTolerance = false
            return false
        }
        return trgTolerance
    }

    func engageCommandRetInt(_ s1: String) -> Int {
        if s1.isEmpty {
            return 0
        }
        if contextCommands.contains(s1) {
            trgTolerance = true
            return 1
        }
        if trgTolerance && !commands.contains(s1) {
            trgTolerance = false
            return 0
        }
        return trgTolerance ? 2 : 0
    }

    func disable() {
        trgTolerance = false
    }
}
 

fukurou

the supreme coder
ADMIN
Swift:
class AXInputWaiter {
    private var _trgTolerance: TrgTolerance

    init(_ tolerance: Int) {
        self._trgTolerance = TrgTolerance(tolerance)
        self._trgTolerance.reset()
    }

    func reset() {
        _trgTolerance.reset()
    }

    func wait(_ s1: String) -> Bool {
        // Return true until input arrives or trigger depletes
        if !s1.isEmpty {
            _trgTolerance.disable()
            return false
        }
        return _trgTolerance.trigger()
    }

    func setWait(_ timesToWait: Int) {
        _trgTolerance.setMaxRepeats(timesToWait)
    }
}
 

fukurou

the supreme coder
ADMIN
Swift:
class LGTypeConverter {
    static func convertToInt(_ v1: String) -> Int {
        let temp = RegexUtil.extractEnumRegex(.integer, v1)
        return temp.isEmpty ? 0 : Int(temp) ?? 0
    }

    static func convertToDouble(_ v1: String) -> Double {
        let temp = RegexUtil.extractEnumRegex(.doubleNum, v1)
        return temp.isEmpty ? 0.0 : Double(temp.replacingOccurrences(of: ",", with: ".")) ?? 0.0
    }

    static func convertToFloat(_ v1: String) -> Float {
        let temp = RegexUtil.extractEnumRegex(.doubleNum, v1)
        return temp.isEmpty ? 0.0 : Float(temp.replacingOccurrences(of: ",", with: ".")) ?? 0.0
    }

    static func convertToFloatV2(_ v1: String, _ precision: Int) -> Float {
        let temp = RegexUtil.extractEnumRegex(.doubleNum, v1)
        guard !temp.isEmpty, let value = Float(temp.replacingOccurrences(of: ",", with: ".")) else {
            return 0.0
        }
        let factor = pow(10.0, Float(precision))
        return round(value * factor) / factor
    }
}
 

fukurou

the supreme coder
ADMIN
Swift:
class DrawRnd {
    private var strings = LGFIFO()
    private var _stringsSource: [String] = []

    init(_ values: String...) {
        for value in values {
            strings.insert(value)
            _stringsSource.append(value)
        }
    }

    func addElement(_ element: String) {
        strings.insert(element)
        _stringsSource.append(element)
    }

    func drawAndRemove() -> String {
        if strings.size() == 0 { return "" }
        let temp = strings.getRNDElement()
        strings.removeItem(temp)
        return temp
    }

    func drawAsIntegerAndRemove() -> Int {
        let temp = strings.getRNDElement()
        if temp.isEmpty { return 0 }
        strings.removeItem(temp)
        return LGTypeConverter.convertToInt(temp)
    }

    static func getSimpleRNDNum(_ lim: Int) -> Int {
        return Int.random(in: 0...lim)
    }

    func reset() {
        strings.clear()
        for t in _stringsSource {
            strings.insert(t)
        }
    }

    func isEmptied() -> Bool {
        return strings.size() == 0
    }

    func renewableDraw() -> String {
        if strings.size() == 0 {
            reset()
        }
        let temp = strings.getRNDElement()
        strings.removeItem(temp)
        return temp
    }
}

Swift:
class DrawRndDigits {
    private var strings = LGFIFO()
    private var _stringsSource: [Int] = []

    init(_ values: Int...) {
        for value in values {
            strings.insert(String(value))
            _stringsSource.append(value)
        }
    }

    func addElement(_ element: Int) {
        strings.insert(String(element))
        _stringsSource.append(element)
    }

    func drawAndRemove() -> Int {
        let temp = strings.getRNDElement()
        strings.removeItem(temp)
        return Int(temp) ?? 0
    }

    static func getSimpleRNDNum(_ lim: Int) -> Int {
        return Int.random(in: 0...lim)
    }

    func reset() {
        strings.clear()
        for t in _stringsSource {
            strings.insert(String(t))
        }
    }

    func isEmptied() -> Bool {
        return strings.size() == 0
    }

    func resetIfEmpty() {
        if strings.size() == 0 {
            reset()
        }
    }

    func containsElement(_ element: Int) -> Bool {
        return _stringsSource.contains(element)
    }

    func currentlyContainsElement(_ element: Int) -> Bool {
        return strings.contains(String(element))
    }

    func removeItem(_ element: Int) {
        strings.removeItem(String(element))
    }
}
 

fukurou

the supreme coder
ADMIN
Swift:
class AXPassword {
    private var _isOpen: Bool = false
    private var _maxAttempts: Int = 3
    private var _loginAttempts: Int = 3
    private var _code: Int = 0

    func codeUpdate(_ ear: String) -> Bool {
        guard _isOpen else { return false }
        if ear.contains("code") {
            let temp = RegexUtil.extractEnumRegex(.integer, ear)
            if !temp.isEmpty {
                _code = Int(temp) ?? 0
                return true
            }
        }
        return false
    }

    func openGate(_ ear: String) {
        guard ear.contains("code"), _loginAttempts > 0 else { return }
        let tempCode = RegexUtil.extractEnumRegex(.integer, ear)
        if !tempCode.isEmpty {
            let code_x = Int(tempCode) ?? -1
            if code_x == _code {
                _loginAttempts = _maxAttempts
                _isOpen = true
            } else {
                _loginAttempts -= 1
            }
        }
    }

    func isOpen() -> Bool {
        return _isOpen
    }

    func resetAttempts() {
        _loginAttempts = _maxAttempts
    }

    func getLoginAttempts() -> Int {
        return _loginAttempts
    }

    func closeGate() {
        _isOpen = false
    }

    func closeGateV2(_ ear: String) {
        if ear.contains("close") {
            _isOpen = false
        }
    }

    func setMaxAttempts(_ maximum: Int) {
        _maxAttempts = maximum
    }

    func getCode() -> Int {
        return _isOpen ? _code : -1
    }

    func randomizeCode(_ lim: Int, _ minimumLim: Int) {
        _code = DrawRnd.getSimpleRNDNum(lim) + minimumLim
    }

    func getCodeEvent() -> Int {
        return _code
    }
}
 

fukurou

the supreme coder
ADMIN
Swift:
class TrgTime {
    private var _t: String = "null"
    private var _alarm: Bool = true

    init() {
        // No super.init() needed unless subclassing
    }

    func setTime(_ v1: String) {
        var timeStr = v1
        if timeStr.hasPrefix("0") {
            timeStr.removeFirst()
        }
        _t = RegexUtil.extractEnumRegex(.simpleTimeStamp, timeStr)
    }

    func alarm() -> Bool {
        let now = TimeUtils.getCurrentTimeStamp()
        if _alarm {
            if now == _t {
                _alarm = false
                return true
            }
        }
        if now != _t {
            _alarm = true
        }
        return false
    }
}
 

fukurou

the supreme coder
ADMIN
Swift:
class Cron {
    private var _minutes: Int
    private var _timeStamp: String
    private var _initialTimeStamp: String
    private var _trgTime = TrgTime()
    private var _counter: Int = 0
    private var _limit: Int

    init(_ startTime: String, _ minutes: Int, _ limit: Int) {
        self._minutes = minutes
        self._timeStamp = startTime
        self._initialTimeStamp = startTime
        self._trgTime.setTime(startTime)
        self._limit = max(1, limit)
    }

    func setMinutes(_ minutes: Int) {
        if minutes > -1 {
            _minutes = minutes
        }
    }

    func getLimit() -> Int {
        return _limit
    }

    func setLimit(_ limit: Int) {
        if limit > 0 {
            _limit = limit
        }
    }

    func getCounter() -> Int {
        return _counter
    }

    func trigger() -> Bool {
        if _counter == _limit {
            _trgTime.setTime(_initialTimeStamp)
            _counter = 0
            return false
        }
        if _trgTime.alarm() {
            _timeStamp = TimeUtils.getFutureInXMin(_minutes)
            _trgTime.setTime(_timeStamp)
            _counter += 1
            return true
        }
        return false
    }

    func triggerWithoutRenewal() -> Bool {
        if _counter == _limit {
            _trgTime.setTime(_initialTimeStamp)
            return false
        }
        if _trgTime.alarm() {
            _timeStamp = TimeUtils.getFutureInXMin(_minutes)
            _trgTime.setTime(_timeStamp)
            _counter += 1
            return true
        }
        return false
    }

    func reset() {
        _counter = 0
    }

    func setStartTime(_ t1: String) {
        _initialTimeStamp = t1
        _timeStamp = t1
        _trgTime.setTime(t1)
        _counter = 0
    }

    func turnOff() {
        _counter = _limit
    }
}
 

fukurou

the supreme coder
ADMIN
Swift:
class AXStandBy {
    private var _tg: TimeGate

    init(_ pause: Int) {
        self._tg = TimeGate(pause)
        self._tg.openForPauseMinutes()
    }

    func standBy(_ ear: String) -> Bool {
        if !ear.isEmpty {
            _tg.openForPauseMinutes()
            return false
        }
        if _tg.isClosed() {
            _tg.openForPauseMinutes()
            return true
        }
        return false
    }
}
 

fukurou

the supreme coder
ADMIN
Swift:
class Cycler {
    private var limit: Int
    private var _cycler: Int

    init(_ limit: Int) {
        self.limit = limit
        self._cycler = limit
    }

    func cycleCount() -> Int {
        _cycler -= 1
        if _cycler < 0 {
            _cycler = limit
        }
        return _cycler
    }

    func reset() {
        _cycler = limit
    }

    func setToZero() {
        _cycler = 0
    }

    func sync(_ n: Int) {
        if n < -1 || n > limit {
            return
        }
        _cycler = n
    }

    func getMode() -> Int {
        return _cycler
    }
}
 

fukurou

the supreme coder
ADMIN
Swift:
class OnOffSwitch {
    private var _mode: Bool = false
    private var _timeGate = TimeGate(5)
    private var _on = Responder("on", "talk to me")
    private var _off = Responder("off", "stop", "shut up", "shut it", "whatever", "whateva")

    func setPause(_ minutes: Int) {
        _timeGate.setPause(minutes)
    }

    func setOn(_ on: Responder) {
        _on = on
    }

    func setOff(_ off: Responder) {
        _off = off
    }

    func getMode(_ ear: String) -> Bool {
        if _on.responsesContainsStr(ear) {
            _timeGate.openForPauseMinutes()
            _mode = true
            return true
        } else if _off.responsesContainsStr(ear) {
            _timeGate.close()
            _mode = false
        }
        if _timeGate.isClosed() {
            _mode = false
        }
        return _mode
    }

    func off() {
        _mode = false
    }
}
 

fukurou

the supreme coder
ADMIN
Swift:
class TimeAccumulator {
    private var _timeGate: TimeGate
    private var _accumulator: Int = 0

    init(_ tick: Int) {
        self._timeGate = TimeGate(tick)
        self._timeGate.openForPauseMinutes()
    }

    func setTick(_ tick: Int) {
        _timeGate.setPause(tick)
    }

    func getAccumulator() -> Int {
        return _accumulator
    }

    func reset() {
        _accumulator = 0
    }

    func tick() {
        if _timeGate.isClosed() {
            _timeGate.openForPauseMinutes()
            _accumulator += 1
        }
    }

    func decAccumulator() {
        if _accumulator > 0 {
            _accumulator -= 1
        }
    }
}
 

fukurou

the supreme coder
ADMIN
Swift:
class KeyWords {
    private var hashSet: Set<String> = []

    init(_ keywords: String...) {
        hashSet.formUnion(keywords)
    }

    func addKeyword(_ keyword: String) {
        hashSet.insert(keyword)
    }

    func extractor(_ str1: String) -> String {
        for keyword in hashSet {
            if str1.contains(keyword) {
                return keyword
            }
        }
        return ""
    }

    func excluder(_ str1: String) -> Bool {
        for keyword in hashSet {
            if str1.contains(keyword) {
                return true
            }
        }
        return false
    }
}
 

fukurou

the supreme coder
ADMIN
Swift:
class QuestionChecker {
    static let questionWords: Set<String> = [
        "what", "who", "where", "when", "why", "how",
        "is", "are", "was", "were", "do", "does", "did",
        "can", "could", "would", "will", "shall", "should",
        "have", "has", "am", "may", "might"
    ]

    static func isQuestion(_ inputText: String?) -> Bool {
        guard let text = inputText?.trimmingCharacters(in: .whitespacesAndNewlines).lowercased(),
              !text.isEmpty else {
            return false
        }

        // Check for question mark at end
        if text.hasSuffix("?") {
            return true
        }

        // Extract first word
        let firstSpaceIndex = text.firstIndex(of: " ") ?? text.endIndex
        var firstWord = String(text[..<firstSpaceIndex])

        // Handle contractions like "who's"
        if let apostropheIndex = firstWord.firstIndex(of: "'") {
            firstWord = String(firstWord[..<apostropheIndex])
        }

        return questionWords.contains(firstWord)
    }
}
 

fukurou

the supreme coder
ADMIN
Swift:
class TrgMinute {
    private var _hour1: Int = -1
    private var _minute: Int

    init() {
        _minute = Int.random(in: 0...60)
    }

    func setMinute(_ minute: Int) {
        if (0..<61).contains(minute) {
            _minute = minute
        }
    }

    func trigger() -> Bool {
        let currentHour = TimeUtils.getHoursAsInt()
        let currentMinute = TimeUtils.getMinutesAsInt()

        if currentHour != _hour1 {
            if currentMinute == _minute {
                _hour1 = currentHour
                return true
            }
        }
        return false
    }

    func reset() {
        _hour1 = -1
    }
}
 

fukurou

the supreme coder
ADMIN
Swift:
class TrgEveryNMinutes {
    private var _minutes: Int
    private var _timeStamp: String
    private var _trgTime = TrgTime()

    init(_ startTime: String, _ minutes: Int) {
        self._minutes = minutes
        self._timeStamp = startTime
        self._trgTime.setTime(startTime)
    }

    func setMinutes(_ minutes: Int) {
        if minutes > -1 {
            _minutes = minutes
        }
    }

    func trigger() -> Bool {
        if _trgTime.alarm() {
            _timeStamp = TimeUtils.getFutureInXMin(_minutes)
            _trgTime.setTime(_timeStamp)
            return true
        }
        return false
    }

    func reset() {
        _timeStamp = TimeUtils.getCurrentTimeStamp()
    }
}
 

fukurou

the supreme coder
ADMIN
Swift:
// ╔════════════════════════════════════════════════════════════════════════╗
// ║                     SPECIAL SKILLS DEPENDENCIES                        ║
// ╚════════════════════════════════════════════════════════════════════════╝
 

fukurou

the supreme coder
ADMIN
Swift:
class TimedMessages {
    private var messages: [String: String] = [:]
    private var lastMSG: String = "nothing"
    private var msg: Bool = false

    func addMSG(_ ear: String) {
        let tempMSG = RegexUtil.extractRegex("(?<=remind me to).*?(?=at)", ear)
        if !tempMSG.isEmpty {
            let timeStamp = RegexUtil.extractEnumRegex(.simpleTimeStamp, ear)
            if !timeStamp.isEmpty {
                messages[timeStamp] = tempMSG.trimmingCharacters(in: .whitespaces)
            }
        }
    }

    func addMSGV2(_ timeStamp: String, _ msg: String) {
        messages[timeStamp] = msg
    }

    func sprinkleMSG(_ msg: String, _ amount: Int) {
        for _ in 0..<amount {
            messages[generateRandomTimestamp()] = msg
        }
    }

    func clear() {
        messages.removeAll()
    }

    func tick() {
        let now = TimeUtils.getCurrentTimeStamp()
        if let newMsg = messages[now], newMsg != lastMSG {
            lastMSG = newMsg
            msg = true
        }
    }

    func getLastMSG() -> String {
        msg = false
        return lastMSG
    }

    func getMsg() -> Bool {
        return msg
    }

    static func generateRandomTimestamp() -> String {
        let hours = Int.random(in: 0...11)
        let minutes = Int.random(in: 0...59)
        return String(format: "%d:%02d", hours, minutes)
    }
}
 

fukurou

the supreme coder
ADMIN
Swift:
class AXLearnability {
    private var algSent: Bool = false
    var defcons: Set<String> = []
    var defcon5: Set<String> = []
    var goals: Set<String> = []
    private var trgTolerance: TrgTolerance

    init(_ tolerance: Int) {
        self.trgTolerance = TrgTolerance(tolerance)
        self.trgTolerance.reset()
    }

    func pendAlg() {
        algSent = true
        _ = trgTolerance.trigger()
    }

    func pendAlgWithoutConfirmation() {
        algSent = true
        // Stick mode: no feedback confirmation
    }

    func mutateAlg(_ input1: String) -> Bool {
        guard algSent else { return false }

        if goals.contains(input1) {
            trgTolerance.reset()
            algSent = false
            return false
        }

        if defcon5.contains(input1) {
            trgTolerance.reset()
            algSent = false
            return true
        }

        if defcons.contains(input1) {
            algSent = false
            let mutate = !trgTolerance.trigger()
            if mutate {
                trgTolerance.reset()
            }
            return mutate
        }

        return false
    }

    func resetTolerance() {
        trgTolerance.reset()
    }
}
 
Top