Merge pull request #14 from Scrumplex/scrumplex-moments

Scrumplex moments
This commit is contained in:
dada513 2022-06-14 15:34:02 +02:00 committed by GitHub
commit fe692eba06
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 54 additions and 50 deletions

View file

@ -1,5 +1,6 @@
FROM docker.io/library/node:18-alpine
WORKDIR /app
COPY . .
COPY package.json yarn.lock ./
RUN yarn install --frozen-lockfile
COPY . .
CMD [ "yarn", "start" ]

View file

@ -1,7 +1,7 @@
{
"name": "roly-poly",
"version": "1.0.0",
"license": "MIT",
"license": "GPL-3.0",
"scripts": {
"dev": "NODE_ENV=development tsx watch src/index.ts",
"start": "tsx src/index.ts",

View file

@ -1,3 +1,22 @@
export const GUILD_ID = '923671181020766230';
export const DEBUG_CHANNEL_ID = '977401259260788756';
export const POLYCAT_CHANNEL_ID = '977797790749032448';
export const ETA_REGEX = /\beta\b/i;
export const ETA_MESSAGES = [
'Sometime',
'Some day',
'Not far',
'The future',
'Never',
'Perhaps tomorrow?',
'There are no ETAs',
'No',
'Nah',
'Yes',
'Yas',
'Next month',
'Next year',
'Next week',
'In PolyMC 2.0.0',
];

View file

@ -22,7 +22,7 @@ import { join } from 'path';
import { green, bold, blue, underline, yellow } from 'kleur/colors';
import 'dotenv/config';
import { getLatestMinecraft } from './utils/minecraftVersion';
import { getLatestMinecraftVersion } from './utils/remoteVersions';
export interface Command {
name: string;
@ -79,7 +79,7 @@ client.once('ready', async () => {
);
client.user?.presence.set({
activities: [{ name: `Minecraft ${await getLatestMinecraft()}` }],
activities: [{ name: `Minecraft ${await getLatestMinecraftVersion()}` }],
status: 'online',
});
@ -105,25 +105,9 @@ client.once('ready', async () => {
return;
}
if (e.cleanContent.match(/(\b| )(eta|ETA)( |\?|!|\b)/)) {
if (e.cleanContent.match(BuildConfig.ETA_REGEX)) {
await e.reply(
`${random([
'Sometime',
'Some day',
'Not far',
'The future',
'Never',
'Perhaps tomorrow?',
'There are no ETAs',
'No',
'Nah',
'Yes',
'Yas',
'Next month',
'Next year',
'Next week',
'In PolyMC 2.0.0',
])} <:pofat:964546613194420294>`
`${random(BuildConfig.ETA_MESSAGES)} <:pofat:964546613194420294>`
);
}
@ -149,6 +133,7 @@ async function parseMsg(e: Message) {
);
if (!cmd) {
// TODO: Do not read tags.json everytime there is a new message
const tag = await getTags().then((r) =>
r.find(
(t) => t.name == parsed.command || t.aliases?.includes(parsed.command)
@ -158,12 +143,11 @@ async function parseMsg(e: Message) {
if (tag) {
if (tag.text) {
e.reply(tag.text);
return true;
} else if (tag.embed) {
const em = new MessageEmbed(tag.embed);
e.reply({ embeds: [em] });
return true;
}
return true;
}
return false;
}

View file

@ -1,4 +1,4 @@
import { getLatest } from './version';
import { getLatestPolyMCVersion } from './utils/remoteVersions';
import { MessageEmbed } from 'discord.js';
// log providers
@ -34,7 +34,7 @@ const javaAnalyzer: Analyzer = async (text) => {
const versionAnalyzer: Analyzer = async (text) => {
const vers = text.match(/PolyMC version: [0-9].[0-9].[0-9]/g);
if (vers && vers[0]) {
const latest = await getLatest();
const latest = await getLatestPolyMCVersion();
const current = vers[0].replace('PolyMC version: ', '');
if (latest != current) {
return [

View file

@ -1,13 +0,0 @@
interface SimplifiedMetaVersion {
recommended: boolean;
type: 'release' | 'snapshot';
version: string;
}
export const getLatestMinecraft = async () => {
const meta = (await fetch(
'https://meta.polymc.org/v1/net.minecraft/index.json'
).then((r) => r.json())) as { versions: SimplifiedMetaVersion[] };
return meta.versions.filter((v) => v.recommended)[0].version;
};

View file

@ -0,0 +1,24 @@
interface MetaPackage {
formatVersion: int;
name: string;
recommended: string[];
uid: string;
}
interface SimplifiedGHReleases {
tag_name: string;
}
// TODO: caching
export async function getLatestMinecraftVersion(): Promise<string> {
const f = await fetch('https://meta.polymc.org/v1/net.minecraft/package.json');
const package = await f.json() as MetaPackage;
return package.recommended[0];
}
// TODO: caching
export async function getLatestPolyMCVersion(): Promise<string> {
const f = await fetch('https://api.github.com/repos/PolyMC/PolyMC/releases');
const versions = await f.json() as SimplifiedGHReleases[];
return versions[0].tag_name;
}

View file

@ -1,11 +0,0 @@
let cachedVer: string;
let cachedTimestamp: number;
export async function getLatest(): Promise<string> {
if (cachedVer && Date.now() - cachedTimestamp < 600000) return cachedVer; // 10min
const f = await fetch('https://api.github.com/repos/PolyMC/PolyMC/releases');
const versions = await f.json();
cachedVer = versions[0].tag_name;
cachedTimestamp = Date.now();
return versions[0].tag_name;
}