aboutsummaryrefslogtreecommitdiff
path: root/commandManager.js
blob: 668ff7c52b3a1785f53392ea2e04b06f80ffeb32 (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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
import { openTimerGui } from "./render/guis/timerGui.js"
import { openPowderGui } from "./render/guis/powertrackerGui"
import { openCoordsGui } from "./render/guis/coordsGui.js"
import { openDowntimeGui } from "./render/guis/downtimeGui.js"
import { openCwGui, reloadColeweight } from "./render/guis/cwGui"
import { openCollectionGui, reloadCollection, trackCollection } from "./render/guis/collectionGui"
import { help } from "./commands/help"
import { setkey } from "./commands/setkey"
import { leaderboard } from "./commands/leaderboard"
import { update } from "./commands/update"
import { fetchDiscord } from "./commands/fetchDiscord"
import { findColeweight } from "./commands/findColeweight"
import { time } from "./commands/time"
import { info } from "./commands/info"
import { credits } from "./commands/credits"
import Settings from "./settings"
import constants from "./util/constants"
import { clearLobbies } from "./commands/markingLobbies"
import { calculate } from "./commands/calculate/calculate.js"
import { openMiningAbilitiesGui } from "./render/miningAbilities.js"
import { spiral } from "./commands/coords/spiral"
import { throne } from "./commands/coords/throne"
import { divans } from "./commands/coords/divans"
import { yog } from "./commands/coords/yog"
import { automatons } from "./commands/coords/automatons"
import { drawLine } from "./commands/drawLine.js"


register("command", (...args) => {
    if (args[0] == undefined) {Settings.openGUI(); return}
    switch(args[0].toString().toLowerCase())
    {
        case "setkey":
            setkey(args[1])
            break
        case "help":
            help()
            break
        case "move":
            if (args[1] == undefined) {ChatLib.chat(`${constants.PREFIX}&cNot enough arguments.`); return}
            switch(args[1].toLowerCase())
            {
                case "coleweight":
                    openCwGui()
                    break
                case "powdertracker":
                    openPowderGui()
                    break
                case "time":
                case "timer":
                    openTimerGui()
                    break
                case "downtime":
                    openDowntimeGui()
                    break
                case "collection":
                    openCollectionGui()
                    break
                case "miningabilities":
                    openMiningAbilitiesGui()
                    break
                default:
                    ChatLib.chat(`${constants.PREFIX}&cNo such gui as '${arg2}'.`)
            }
            break
        case "throne":
            throne(args[1])
            break
        case "spiral":
            spiral(args[1])
            break
        case "reload":
            if(args[1] == undefined)
                return ChatLib.chat(`${constants.PREFIX}&cMust specify a gui. Hit tab on '/cw reload ' for options.`)
            switch(args[1].toLowerCase())
            {
                case "coleweight":
                    reloadColeweight()
                    break
                case "collection":
                    reloadCollection()
                    break
                default:
                    ChatLib.chat(`${constants.PREFIX}&cNo such gui as '${args[1]}'.`)
            }
            break
        case "lb":
        case "top":
        case "leaderboard":
            leaderboard(args[1], args[2])
            break
        case "update":
            update()
            break
        case "config":
        case "settings":
            Settings.openGUI()
            break
        case "powdertrackersync":
            updateDisplay()
            break
        case "time":
            time()
            break
        case "info":
            info()
            break
        case "clearlobbies":
            clearLobbies()
            break
        case "yog":
            yog(args[1])
            break
        case "divans":
        case "divan":
            divans(args[1])
            break
        case "automaton":
        case "automatons":
            automatons(args[1])
            break
        case "coord":
        case "coords":
            openCoordsGui()
            break
        case "credits":
            credits()
            break
        case "track":
            trackCollection(args[1])
            break
        case "calc":
        case "calculate":
            calculate(args.slice(1))
            break
        case "drawline":
            drawLine(args)
            break
        default:
            findColeweight(args[0])
    }
}).setTabCompletions((args) => {
    let output = [],
     reloadOptions = ["coleweight", "collection"],
     calculateOptions = ["tick", "ms2toprofessional", "hotm", "calchotm"],
     commands = ["setkey", "help", "move", "toggle", "throne", "spiral", "reload", "leaderboard", 
        "settings", "time", "info", "clearlobbies", "yog", "divan", "automatons", "coords", "credits", "track", "calculate", "drawline"]
    
    if(args[0].length == 0 || args[0] == undefined)
        return output = commands

    switch(args[0])
    {
        case "reload":
            output = findTabOutput(args[1], reloadOptions)
            break
        case "calculate":
        case "calc":
            output = findTabOutput(args[1], calculateOptions)
            break
        default:
            output = findTabOutput(args[0], commands)
            break
    }
    return output
}).setName("cw").setAliases(["coleweight"])

register("command", (arg) => {
    fetchDiscord(arg)
}).setTabCompletions((args) => {
    let players = World.getAllPlayers().map((p) => p.getName())
    .filter((n) =>
      n.toLowerCase().startsWith(args.length ? args[0].toLowerCase() : "")
    )
    .sort()
        
    return players
}).setName("fetchdiscord").setAliases(["fdiscord"]);

function findTabOutput(input, options)
{
    let output = []

    if(input == undefined || input == "") return options
    options.forEach(option => {
        for(let char = 0; char < input.length; char++)
        {
            if(option[char] != input[char])
                break
            else if(char == input.length - 1)
                output.push(option)
        }
    })

    return output
}