Skip to content

Commit

Permalink
feat: remove tweet and add ams server
Browse files Browse the repository at this point in the history
  • Loading branch information
TheAlexLichter committed May 2, 2024
1 parent bfc4a82 commit 0bc63f2
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 98 deletions.
6 changes: 3 additions & 3 deletions packages/api/routes/[server].ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { serverNameSchema } from "../../shared/types.js"
import { SERVER_NAMES } from "../../shared/types.js"

export default defineEventHandler((event) => {
const { server } = event.context.params
const result = serverNameSchema.safeParse(server)
if(!result.success) {
const isValidServer = SERVER_NAMES.includes(server)
if(!isValidServer) {
throw createError({
status: 400,
message: 'bad request'
Expand Down
5 changes: 3 additions & 2 deletions packages/scrape-and-tweet/constants.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ServerName } from "../shared/types.js";

export const STATUS_URLS: Record<ServerName, string> = {
east: 'https://serverstatus-sgp.albiononline.com/',
west: 'https://serverstatus.albiononline.com/',
sgp: 'https://serverstatus-sgp.albiononline.com/',
ams: 'https://serverstatus-ams.albiononline.com/',
was: 'https://serverstatus.albiononline.com/',
} as const
21 changes: 4 additions & 17 deletions packages/scrape-and-tweet/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@

import { scrape } from "./scrape.js"
import { tweet } from "./tweet.js"
import type { ServerName } from '../shared/types.js'
import { Env } from "./types.js"

export default {
Expand All @@ -11,25 +9,14 @@ export default {
ctx: ExecutionContext
): Promise<void> {
const result = await Promise.allSettled([
scrapeAndTweet('east', env),
scrapeAndTweet('west', env)
scrape('sgp', env),
scrape('ams', env),
scrape('was', env),
])

if (!result.every(({ status }) => status === 'fulfilled')) {
console.error('At least one scraper failed')
console.error(result)
}
}
}

async function scrapeAndTweet (server: ServerName, env: Env) {
const { didStatusUpdate, currentStatus } = await scrape(server, env)

if (!didStatusUpdate) {
console.log("Status did not update")
return { success: true, message: "Status did not update" }
}

console.log(`Tweeting new status - ${currentStatus.message}`)
await tweet({ status: currentStatus, server, env })
}
}
72 changes: 0 additions & 72 deletions packages/scrape-and-tweet/tweet.ts

This file was deleted.

6 changes: 2 additions & 4 deletions packages/shared/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { z } from 'zod'

export const serverNameSchema = z.enum(['east', 'west'])
export type ServerName = z.infer<typeof serverNameSchema>;
export const SERVER_NAMES = ['sgp', 'ams', 'was'] as const
export type ServerName = typeof SERVER_NAMES[number]

export type StatusType = 'online' | 'offline' | 'starting' | 'unknown'
export type Status = {
Expand Down

0 comments on commit 0bc63f2

Please sign in to comment.