diff options
author | Linnea Gräf <nea@nea.moe> | 2024-07-13 16:47:04 +0200 |
---|---|---|
committer | Linnea Gräf <nea@nea.moe> | 2024-07-13 16:47:04 +0200 |
commit | b125ce50a4a5e3760af64afc4fc0f12c627a18bd (patch) | |
tree | da810d4882a63790f3e880c2d1fb28106bfc1bfa | |
download | double-powder-tracker-b125ce50a4a5e3760af64afc4fc0f12c627a18bd.tar.gz double-powder-tracker-b125ce50a4a5e3760af64afc4fc0f12c627a18bd.tar.bz2 double-powder-tracker-b125ce50a4a5e3760af64afc4fc0f12c627a18bd.zip |
Init
-rw-r--r-- | .github/workflows/docker.yml | 51 | ||||
-rw-r--r-- | .gitignore | 2 | ||||
-rw-r--r-- | Dockerfile | 7 | ||||
-rw-r--r-- | double-powder-tracking.xml | 23 | ||||
-rw-r--r-- | package-lock.json | 175 | ||||
-rw-r--r-- | package.json | 16 | ||||
-rw-r--r-- | src/app.js | 57 |
7 files changed, 331 insertions, 0 deletions
diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 0000000..91c23c6 --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,51 @@ + +name: Create and publish a Docker image + +# Configures this workflow to run every time a change is pushed to the branch called `release`. +on: + push: + tags: + +# Defines two custom environment variables for the workflow. These are used for the Container registry domain, and a name for the Docker image that this workflow builds. +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +# There is a single job in this workflow. It's configured to run on the latest available version of Ubuntu. +jobs: + build-and-push-image: + runs-on: ubuntu-latest + # Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job. + permissions: + contents: read + packages: write + attestations: write + # + steps: + - name: Checkout repository + uses: actions/checkout@v4 + # Uses the `docker/login-action` action to log in to the Container registry registry using the account and password that will publish the packages. Once published, the packages are scoped to the account defined here. + - name: Log in to the Container registry + uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + # This step uses [docker/metadata-action](https://github.com/docker/metadata-action#about) to extract tags and labels that will be applied to the specified image. The `id` "meta" allows the output of this step to be referenced in a subsequent step. The `images` value provides the base name for the tags and labels. + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + # This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. If the build succeeds, it pushes the image to GitHub Packages. + # It uses the `context` parameter to define the build's context as the set of files located in the specified path. For more information, see "[Usage](https://github.com/docker/build-push-action#usage)" in the README of the `docker/build-push-action` repository. + # It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step. + - name: Build and push Docker image + id: push + uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6ed48a9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.env +node_modules diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..8f1e075 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,7 @@ +FROM node:22 +WORKDIR /app +COPY package.json ./ +COPY package-lock.json ./ +RUN npm install +COPY src ./src +ENTRYPOINT ["npm", "start"] diff --git a/double-powder-tracking.xml b/double-powder-tracking.xml new file mode 100644 index 0000000..b886a0b --- /dev/null +++ b/double-powder-tracking.xml @@ -0,0 +1,23 @@ +<?xml version="1.0"?> + <Container version="2"> + <Name>Double Powder Tracker</Name> + <Repository>ghcr.io/nea89o/double-powder-tracker</Repository> + <Registry>ghcr.io</Registry> + <Network>bridge</Network> + <Privileged>false</Privileged> + <Support>https://discord.gg/64pFP94AWA</Support> + <Project>https://github.com/nea89o/double-powder-tracker</Project> + <Overview></Overview> + <WebUI>https://www.youtube.com/watch?v=dQw4w9WgXcQ</WebUI> + <Icon>https://nea.moe/runescape.wiki/twinflower.jpg</Icon> + <ExtraParams/> + <PostArgs/> + <DonateText>Please give me SkyBlock coins</DonateText> + <DonateLink>https://sky.shiiyu.moe/stats/lrg89/</DonateLink> + + <Config Name="Role Id" Target="ROLE_ID" Default="" Mode="" Description="The role to ping every time there is an event" Type="Variable" Display="always" Required="true" Mask="false" /> + <Config Name="Check interval" Target="INTERVAL_IN_SECONDS" Default="60" Mode="" Description="Interval in which to check for new events" Type="Variable" Display="always" Required="true" Mask="false" /> + <Config Name="Event Name" Target="EVENT_NAME" Default="DOUBLE_POWDER" Mode="" Description="The event name to ping for" Type="Variable" Display="always" Required="true" Mask="false" /> + <Config Name="Event Location" Target="EVENT_LOCATION" Default="DWARVEN_MINES" Mode="" Description="The location to look events for" Type="Variable" Display="always" Required="true" Mask="false" /> + <Config Name="Webhook Url" Target="WEBHOOK_URL" Default="" Mode="" Description="The discord webhook url" Type="Variable" Display="always" Required="true" Mask="true" /> +</Container> diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..4ea6ee0 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,175 @@ +{ + "name": "bitch-quit-bot", + "version": "1.0.0", + "lockfileVersion": 2, + "requires": true, + "packages": { + "": { + "name": "bitch-quit-bot", + "version": "1.0.0", + "license": "ISC", + "dependencies": { + "dotenv": "^16.0.1", + "eris": "^0.16.1", + "node-fetch": "^2.6.7" + } + }, + "node_modules/dotenv": { + "version": "16.0.1", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.0.1.tgz", + "integrity": "sha512-1K6hR6wtk2FviQ4kEiSjFiH5rpzEVi8WW0x96aztHVMhEspNpc4DVOUTEHtEva5VThQ8IaBX1Pe4gSzpVVUsKQ==", + "engines": { + "node": ">=12" + } + }, + "node_modules/eris": { + "version": "0.16.1", + "resolved": "https://registry.npmjs.org/eris/-/eris-0.16.1.tgz", + "integrity": "sha512-fqjgaddSvUlUjA7s85OvZimLrgCwX58Z6FXOIxdNFJdT6XReJ/LOWZKdew2CaalM8BvN2JKzn98HmKYb3zMhKg==", + "dependencies": { + "ws": "^8.2.3" + }, + "engines": { + "node": ">=10.4.0" + }, + "optionalDependencies": { + "opusscript": "^0.0.8", + "tweetnacl": "^1.0.3" + } + }, + "node_modules/eris/node_modules/tweetnacl": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-1.0.3.tgz", + "integrity": "sha512-6rt+RN7aOi1nGMyC4Xa5DdYiukl2UWCbcJft7YhxReBGQD7OAM8Pbxw6YMo4r2diNEA8FEmu32YOn9rhaiE5yw==", + "optional": true + }, + "node_modules/node-fetch": { + "version": "2.6.7", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.7.tgz", + "integrity": "sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==", + "dependencies": { + "whatwg-url": "^5.0.0" + }, + "engines": { + "node": "4.x || >=6.0.0" + }, + "peerDependencies": { + "encoding": "^0.1.0" + }, + "peerDependenciesMeta": { + "encoding": { + "optional": true + } + } + }, + "node_modules/opusscript": { + "version": "0.0.8", + "resolved": "https://registry.npmjs.org/opusscript/-/opusscript-0.0.8.tgz", + "integrity": "sha512-VSTi1aWFuCkRCVq+tx/BQ5q9fMnQ9pVZ3JU4UHKqTkf0ED3fKEPdr+gKAAl3IA2hj9rrP6iyq3hlcJq3HELtNQ==", + "optional": true + }, + "node_modules/tr46": { + "version": "0.0.3", + "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz", + "integrity": "sha1-gYT9NH2snNwYWZLzpmIuFLnZq2o=" + }, + "node_modules/webidl-conversions": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz", + "integrity": "sha1-JFNCdeKnvGvnvIZhHMFq4KVlSHE=" + }, + "node_modules/whatwg-url": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz", + "integrity": "sha1-lmRU6HZUYuN2RNNib2dCzotwll0=", + "dependencies": { + "tr46": "~0.0.3", + "webidl-conversions": "^3.0.0" + } + }, + "node_modules/ws": { + "version": "8.6.0", + "resolved": "https://registry.npmjs.org/ws/-/ws-8.6.0.tgz", + "integrity": "sha512-AzmM3aH3gk0aX7/rZLYvjdvZooofDu3fFOzGqcSnQ1tOcTWwhM/o+q++E8mAyVVIyUdajrkzWUGftaVSDLn1bw==", + "engines": { + "node": ">=10.0.0" + }, + "peerDependencies": { + "bufferutil": "^4.0.1", + "utf-8-validate": "^5.0.2" + }, + "peerDependenciesMeta": { + "bufferutil": { + "optional": true + }, + "utf-8-validate": { + "optional": true + } + } + } + }, + "dependencies": { + "dotenv": { + "version": "16.0.1", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.0.1.tgz", + "integrity": "sha512-1K6hR6wtk2FviQ4kEiSjFiH5rpzEVi8WW0x96aztHVMhEspNpc4DVOUTEHtEva5VThQ8IaBX1Pe4gSzpVVUsKQ==" + }, + "eris": { + "version": "0.16.1", + "resolved": "https://registry.npmjs.org/eris/-/eris-0.16.1.tgz", + "integrity": "sha512-fqjgaddSvUlUjA7s85OvZimLrgCwX58Z6FXOIxdNFJdT6XReJ/LOWZKdew2CaalM8BvN2JKzn98HmKYb3zMhKg==", + "requires": { + "opusscript": "^0.0.8", + "tweetnacl": "^1.0.3", + "ws": "^8.2.3" + }, + "dependencies": { + "tweetnacl": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-1.0.3.tgz", + "integrity": "sha512-6rt+RN7aOi1nGMyC4Xa5DdYiukl2UWCbcJft7YhxReBGQD7OAM8Pbxw6YMo4r2diNEA8FEmu32YOn9rhaiE5yw==", + "optional": true + } + } + }, + "node-fetch": { + "version": "2.6.7", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.7.tgz", + "integrity": "sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==", + "requires": { + "whatwg-url": "^5.0.0" + } + }, + "opusscript": { + "version": "0.0.8", + "resolved": "https://registry.npmjs.org/opusscript/-/opusscript-0.0.8.tgz", + "integrity": "sha512-VSTi1aWFuCkRCVq+tx/BQ5q9fMnQ9pVZ3JU4UHKqTkf0ED3fKEPdr+gKAAl3IA2hj9rrP6iyq3hlcJq3HELtNQ==", + "optional": true + }, + "tr46": { + "version": "0.0.3", + "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz", + "integrity": "sha1-gYT9NH2snNwYWZLzpmIuFLnZq2o=" + }, + "webidl-conversions": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz", + "integrity": "sha1-JFNCdeKnvGvnvIZhHMFq4KVlSHE=" + }, + "whatwg-url": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz", + "integrity": "sha1-lmRU6HZUYuN2RNNib2dCzotwll0=", + "requires": { + "tr46": "~0.0.3", + "webidl-conversions": "^3.0.0" + } + }, + "ws": { + "version": "8.6.0", + "resolved": "https://registry.npmjs.org/ws/-/ws-8.6.0.tgz", + "integrity": "sha512-AzmM3aH3gk0aX7/rZLYvjdvZooofDu3fFOzGqcSnQ1tOcTWwhM/o+q++E8mAyVVIyUdajrkzWUGftaVSDLn1bw==", + "requires": {} + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..204b7b2 --- /dev/null +++ b/package.json @@ -0,0 +1,16 @@ +{ + "name": "bitch-quit-bot", + "version": "1.0.0", + "description": "", + "main": "src/app.js", + "scripts": { + "start": "node ." + }, + "author": "", + "license": "ISC", + "dependencies": { + "dotenv": "^16.0.1", + "eris": "^0.16.1", + "node-fetch": "^2.6.7" + } +} diff --git a/src/app.js b/src/app.js new file mode 100644 index 0000000..bfbdc44 --- /dev/null +++ b/src/app.js @@ -0,0 +1,57 @@ +const fetch = require('node-fetch'); +const dotenv = require('dotenv').config(); + +const roleId = process.env.ROLE_ID; +const interval = process.env.INTERVAL_IN_SECONDS; // Interval in Sekunden +const eventName = process.env.EVENT_NAME; // Der Name des Events +const eventLocation = process.env.EVENT_LOCATION; // Die Location des Events +const webhookUrl = process.env.WEBHOOK_URL; // Webhook-URL + +const url = 'https://api.soopy.dev/skyblock/chevents/get'; // API-URL + +var lastStatus = false; // Speichert den letzten Status, ob das Event aktiv war + +function sendDiscordMessage(message) { + fetch(webhookUrl, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ + content: message, + username: 'Powder Tracker', // Optional: Custom-Bot-Name + }) + }) + .then(res => res.text()) + .then(text => console.log(text)) + .catch(err => console.error('Fehler beim Senden der Webhook-Nachricht:', err)); +} + +setInterval(() => { + fetch(url) + .then(res => res.json()) + .then(json => { + const eventInfo = json.data.running_events[eventLocation]; + const specificEvent = eventInfo && eventInfo.find(e => e.event === eventName); + + // Überprüfung, ob das Event aktiv ist + const currentTime = json.data.curr_time; + const eventActive = specificEvent && currentTime <= specificEvent.ends_at; + const remainingTimeMs = specificEvent ? specificEvent.ends_at - currentTime : 0; // Verbleibende Zeit in Millisekunden + const remainingTimeMin = Math.floor(remainingTimeMs / 60000); // Verbleibende Zeit in Minuten + const lobbyCount = specificEvent ? specificEvent.lobby_count : 0; // Anzahl der Lobbys + + console.log(`Event '${eventName}' in '${eventLocation}': ${eventActive ? 'Aktiv' : 'Inaktiv'}`); + + if (eventActive && !lastStatus) { + const message = `<@&${roleId}> Hey there is a '${eventName}' in '${eventLocation}' aktiv. Time Left: ${remainingTimeMin} Min. Lobbys: ${lobbyCount}.`; + sendDiscordMessage(message); + lastStatus = true; // Aktualisierung des Status, um Mehrfachbenachrichtigungen zu vermeiden + } else if (!eventActive && lastStatus) { + lastStatus = false; // Zurücksetzen des Status + } + }) + .catch(err => { + console.error('Fehler beim Abrufen der API:', err); + }); +}, interval * 1000); |