(result: CompletedEvent)
| 149 | } |
| 150 | |
| 151 | export function verify(result: CompletedEvent): string | null { |
| 152 | const loadedChallenge = getLoadedChallenge(); |
| 153 | |
| 154 | if (loadedChallenge === null) return null; |
| 155 | |
| 156 | try { |
| 157 | const afk = (result.afkDuration / result.testDuration) * 100; |
| 158 | |
| 159 | if (afk > 10) { |
| 160 | showNoticeNotification(`Challenge failed: AFK time is greater than 10%`); |
| 161 | return null; |
| 162 | } |
| 163 | |
| 164 | if (loadedChallenge.requirements === undefined) { |
| 165 | showSuccessNotification(`${loadedChallenge.display} challenge passed!`); |
| 166 | return loadedChallenge.name || null; |
| 167 | } else { |
| 168 | let requirementsMet = true; |
| 169 | const failReasons: string[] = []; |
| 170 | for (const requirementType of Misc.typedKeys( |
| 171 | loadedChallenge.requirements, |
| 172 | )) { |
| 173 | const [passed, requirementFailReasons] = verifyRequirement( |
| 174 | result, |
| 175 | loadedChallenge.requirements, |
| 176 | requirementType, |
| 177 | ); |
| 178 | if (!passed) { |
| 179 | requirementsMet = false; |
| 180 | } |
| 181 | failReasons.push(...requirementFailReasons); |
| 182 | } |
| 183 | if (requirementsMet) { |
| 184 | if (loadedChallenge.autoRole) { |
| 185 | showSuccessNotification( |
| 186 | "You will receive a role shortly. Please don't post a screenshot in challenge submissions.", |
| 187 | { durationMs: 5000 }, |
| 188 | ); |
| 189 | } |
| 190 | showSuccessNotification(`${loadedChallenge.display} challenge passed!`); |
| 191 | return loadedChallenge.name; |
| 192 | } else { |
| 193 | showNoticeNotification( |
| 194 | `${ |
| 195 | loadedChallenge.display |
| 196 | } challenge failed: ${failReasons.join(", ")}`, |
| 197 | ); |
| 198 | return null; |
| 199 | } |
| 200 | } |
| 201 | } catch (e) { |
| 202 | console.error(e); |
| 203 | showNoticeNotification( |
| 204 | `Something went wrong when verifying challenge: ${(e as Error).message}`, |
| 205 | ); |
| 206 | return null; |
| 207 | } |
| 208 | } |
nothing calls this directly
no test coverage detected