diff --git a/config/games/allbadcards.ts b/config/games/allbadcards.ts new file mode 100644 index 0000000..2f8e9cb --- /dev/null +++ b/config/games/allbadcards.ts @@ -0,0 +1,57 @@ +import { ServerGame } from "../../types/types"; +import { postJson } from "../../utils/utils"; + +const fetchWithCookies = require("fetch-cookie")(fetch); + +const game: ServerGame = { + id: "allbadcards", + name: "All Bad Cards", + author: "Jake Lauer", + basedOn: { + game: "Cards Against Humanity", + link: "https://cardsagainsthumanity.com/", + }, + description: + "Be rude. Be irreverent. Be hilarious! Select the card from your hand that you think is best described by a card played by the judge!", + displayUrlText: "allbad.cards", + displayUrlHref: "https://allbad.cards/", + donationUrlText: "Support Jake on Patreon!", + donationUrlHref: "https://www.patreon.com/Allbadcards", + category: ["easy"], + players: "4-20+", + familyFriendly: false, + getJoinGameUrl: async () => { + const { guid } = await fetchWithCookies( + "https://allbad.cards/api/user/register" + ).then((res) => res.json()); + + const { id } = await postJson( + "https://allbad.cards/api/game/create", + { + guid, + nickname: "rocketcrab, leaving in 20 seconds!", + isFamily: false, + isPublic: false, + }, + fetchWithCookies + ); + + setTimeout(() => { + postJson( + "https://allbad.cards/api/game/kick", + { + gameId: id, + targetGuid: guid, + guid: guid, + }, + fetchWithCookies + ) + .then((a) => console.log(a)) + .catch((e) => console.error(e)); + }, 20 * 1000); + + return { playerURL: "https://allbad.cards/game/" + id }; + }, +}; + +export default game; diff --git a/package-lock.json b/package-lock.json index 519067d..f6f0541 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7064,6 +7064,14 @@ "bser": "2.1.1" } }, + "fetch-cookie": { + "version": "0.10.1", + "resolved": "https://registry.npmjs.org/fetch-cookie/-/fetch-cookie-0.10.1.tgz", + "integrity": "sha512-beB+VEd4cNeVG1PY+ee74+PkuCQnik78pgLi5Ah/7qdUfov8IctU0vLUbBT8/10Ma5GMBeI4wtxhGrEfKNYs2g==", + "requires": { + "tough-cookie": "^2.3.3 || ^3.0.1 || ^4.0.0" + } + }, "figgy-pudding": { "version": "3.5.2", "resolved": "https://registry.npmjs.org/figgy-pudding/-/figgy-pudding-3.5.2.tgz", @@ -7905,8 +7913,7 @@ "ip-regex": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/ip-regex/-/ip-regex-2.1.0.tgz", - "integrity": "sha1-+ni/XS5pE8kRzp+BnuUUa7bYROk=", - "dev": true + "integrity": "sha1-+ni/XS5pE8kRzp+BnuUUa7bYROk=" }, "ipaddr.js": { "version": "1.9.1", @@ -14057,8 +14064,7 @@ "psl": { "version": "1.8.0", "resolved": "https://registry.npmjs.org/psl/-/psl-1.8.0.tgz", - "integrity": "sha512-RIdOzyoavK+hA18OGGWDqUTsCLhtA7IcZ/6NCs4fFJaHBDab+pDDmDIByWFRQJq2Cd7r1OoQxBGKOaztq+hjIQ==", - "dev": true + "integrity": "sha512-RIdOzyoavK+hA18OGGWDqUTsCLhtA7IcZ/6NCs4fFJaHBDab+pDDmDIByWFRQJq2Cd7r1OoQxBGKOaztq+hjIQ==" }, "pstree.remy": { "version": "1.1.8", @@ -16119,7 +16125,6 @@ "version": "3.0.1", "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-3.0.1.tgz", "integrity": "sha512-yQyJ0u4pZsv9D4clxO69OEjLWYw+jbgspjTue4lTQZLfV0c5l1VmK2y1JK8E9ahdpltPOaAThPcp5nKPUgSnsg==", - "dev": true, "requires": { "ip-regex": "^2.1.0", "psl": "^1.1.28", diff --git a/package.json b/package.json index 66e5946..6beadc4 100644 --- a/package.json +++ b/package.json @@ -34,6 +34,7 @@ "body-parser": "^1.19.0", "cross-env": "^7.0.2", "express": "^4.17.1", + "fetch-cookie": "^0.10.1", "fontsource-inconsolata": "^3.0.5", "next": "^9.5.1", "nookies": "^2.4.0", diff --git a/utils/utils.ts b/utils/utils.ts index 8f07b36..a695a50 100644 --- a/utils/utils.ts +++ b/utils/utils.ts @@ -1,8 +1,12 @@ import { PromiseWebSocket } from "../types/types"; import WebSocket from "ws"; -export const postJson = (url = "", data = {}): Promise => - fetch(url, { +export const postJson = ( + url = "", + data = {}, + customFetch?: (input: RequestInfo, init?: RequestInit) => Promise +): Promise => + (customFetch || fetch)(url, { method: "POST", headers: { "Content-Type": "application/json",