aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/com/dulkirfabric/features/chat/AbiPhoneDND.kt
blob: 623c7b1acc3a7d2a3ac01348838106c6b8bfe8cf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package com.dulkirfabric.features.chat

import com.dulkirfabric.config.DulkirConfig
import com.dulkirfabric.events.PlaySoundEvent
import com.dulkirfabric.events.chat.ChatEvents
import com.dulkirfabric.util.TextUtils
import com.dulkirfabric.util.TextUtils.unformattedString
import meteordevelopment.orbit.EventHandler

object AbiPhoneDND {

    private val abiPhoneFormat = "✆ (\\w+) ✆ ".toRegex()
    private var lastRing = 0L

    //BLOCK ABIPHONE SOUNDS
    @EventHandler
    fun onSound(event: PlaySoundEvent) {
        if (!DulkirConfig.configOptions.abiPhoneDND) return
        if (System.currentTimeMillis() - lastRing < 5000) {
            if (event.sound.id.path == "block.note_block.pling" && event.sound.volume == 0.69f && event.sound.pitch == 1.6666666f) {
                event.cancel()
            }
        }
    }

    @EventHandler
    fun handle(event: ChatEvents.AllowChat) {
        if (!DulkirConfig.configOptions.abiPhoneDND) return
        val unformatted = event.message.unformattedString
        if (unformatted matches abiPhoneFormat && !unformatted.contains("Elle") && !unformatted.contains("Dean")) {
            val matchResult = abiPhoneFormat.find(unformatted)
            event.cancel()
            lastRing = System.currentTimeMillis()
            if (DulkirConfig.configOptions.abiPhoneCallerID) {
                val blocked = if (Math.random() < .001) "Breefing"
                else matchResult?.groups?.get(1)?.value
                TextUtils.info("§6Call blocked from $blocked!")
            }
        }
        if (unformatted.startsWith("✆ Ring...") && unformatted.endsWith("[PICK UP]")
            && System.currentTimeMillis() - lastRing < 5000
        ) {
            event.cancel()
        }
    }
}