Merge pull request #14 from Scrumplex/scrumplex-moments
Scrumplex moments
This commit is contained in:
commit
fe692eba06
8 changed files with 54 additions and 50 deletions
|
@ -1,5 +1,6 @@
|
||||||
FROM docker.io/library/node:18-alpine
|
FROM docker.io/library/node:18-alpine
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY . .
|
COPY package.json yarn.lock ./
|
||||||
RUN yarn install --frozen-lockfile
|
RUN yarn install --frozen-lockfile
|
||||||
|
COPY . .
|
||||||
CMD [ "yarn", "start" ]
|
CMD [ "yarn", "start" ]
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"name": "roly-poly",
|
"name": "roly-poly",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"license": "MIT",
|
"license": "GPL-3.0",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "NODE_ENV=development tsx watch src/index.ts",
|
"dev": "NODE_ENV=development tsx watch src/index.ts",
|
||||||
"start": "tsx src/index.ts",
|
"start": "tsx src/index.ts",
|
||||||
|
|
|
@ -1,3 +1,22 @@
|
||||||
export const GUILD_ID = '923671181020766230';
|
export const GUILD_ID = '923671181020766230';
|
||||||
export const DEBUG_CHANNEL_ID = '977401259260788756';
|
export const DEBUG_CHANNEL_ID = '977401259260788756';
|
||||||
export const POLYCAT_CHANNEL_ID = '977797790749032448';
|
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',
|
||||||
|
];
|
||||||
|
|
28
src/index.ts
28
src/index.ts
|
@ -22,7 +22,7 @@ import { join } from 'path';
|
||||||
|
|
||||||
import { green, bold, blue, underline, yellow } from 'kleur/colors';
|
import { green, bold, blue, underline, yellow } from 'kleur/colors';
|
||||||
import 'dotenv/config';
|
import 'dotenv/config';
|
||||||
import { getLatestMinecraft } from './utils/minecraftVersion';
|
import { getLatestMinecraftVersion } from './utils/remoteVersions';
|
||||||
|
|
||||||
export interface Command {
|
export interface Command {
|
||||||
name: string;
|
name: string;
|
||||||
|
@ -79,7 +79,7 @@ client.once('ready', async () => {
|
||||||
);
|
);
|
||||||
|
|
||||||
client.user?.presence.set({
|
client.user?.presence.set({
|
||||||
activities: [{ name: `Minecraft ${await getLatestMinecraft()}` }],
|
activities: [{ name: `Minecraft ${await getLatestMinecraftVersion()}` }],
|
||||||
status: 'online',
|
status: 'online',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -105,25 +105,9 @@ client.once('ready', async () => {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (e.cleanContent.match(/(\b| )(eta|ETA)( |\?|!|\b)/)) {
|
if (e.cleanContent.match(BuildConfig.ETA_REGEX)) {
|
||||||
await e.reply(
|
await e.reply(
|
||||||
`${random([
|
`${random(BuildConfig.ETA_MESSAGES)} <:pofat:964546613194420294>`
|
||||||
'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>`
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -149,6 +133,7 @@ async function parseMsg(e: Message) {
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!cmd) {
|
if (!cmd) {
|
||||||
|
// TODO: Do not read tags.json everytime there is a new message
|
||||||
const tag = await getTags().then((r) =>
|
const tag = await getTags().then((r) =>
|
||||||
r.find(
|
r.find(
|
||||||
(t) => t.name == parsed.command || t.aliases?.includes(parsed.command)
|
(t) => t.name == parsed.command || t.aliases?.includes(parsed.command)
|
||||||
|
@ -158,12 +143,11 @@ async function parseMsg(e: Message) {
|
||||||
if (tag) {
|
if (tag) {
|
||||||
if (tag.text) {
|
if (tag.text) {
|
||||||
e.reply(tag.text);
|
e.reply(tag.text);
|
||||||
return true;
|
|
||||||
} else if (tag.embed) {
|
} else if (tag.embed) {
|
||||||
const em = new MessageEmbed(tag.embed);
|
const em = new MessageEmbed(tag.embed);
|
||||||
e.reply({ embeds: [em] });
|
e.reply({ embeds: [em] });
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { getLatest } from './version';
|
import { getLatestPolyMCVersion } from './utils/remoteVersions';
|
||||||
import { MessageEmbed } from 'discord.js';
|
import { MessageEmbed } from 'discord.js';
|
||||||
|
|
||||||
// log providers
|
// log providers
|
||||||
|
@ -34,7 +34,7 @@ const javaAnalyzer: Analyzer = async (text) => {
|
||||||
const versionAnalyzer: Analyzer = async (text) => {
|
const versionAnalyzer: Analyzer = async (text) => {
|
||||||
const vers = text.match(/PolyMC version: [0-9].[0-9].[0-9]/g);
|
const vers = text.match(/PolyMC version: [0-9].[0-9].[0-9]/g);
|
||||||
if (vers && vers[0]) {
|
if (vers && vers[0]) {
|
||||||
const latest = await getLatest();
|
const latest = await getLatestPolyMCVersion();
|
||||||
const current = vers[0].replace('PolyMC version: ', '');
|
const current = vers[0].replace('PolyMC version: ', '');
|
||||||
if (latest != current) {
|
if (latest != current) {
|
||||||
return [
|
return [
|
||||||
|
|
|
@ -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;
|
|
||||||
};
|
|
24
src/utils/remoteVersions.ts
Normal file
24
src/utils/remoteVersions.ts
Normal 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;
|
||||||
|
}
|
|
@ -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;
|
|
||||||
}
|
|
Loading…
Add table
Add a link
Reference in a new issue