Webatrice: card import wizard (#4397)

This commit is contained in:
Jeremy Letto 2021-10-14 20:42:35 -05:00 committed by GitHub
parent dde0f568d9
commit 36e5a399d5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
41 changed files with 1479 additions and 35 deletions

View file

@ -0,0 +1,93 @@
export class Card {
artist: string;
availability: string[];
borderColor: string;
colorIdentity: string[];
colors: string[];
convertedManaCost: number;
edhrecRank: number;
flavorText: string;
identifiers: {
cardKingdomId: string;
mcmId: string;
mcmMetaId: string;
mtgjsonV4Id: string;
multiverseId: string;
scryfallId: string;
scryfallIllustrationId: string;
scryfallOracleId: string;
tcgplayerProductId: string;
};
isOnlineOnly: boolean;
layout: string;
legalities: {
brawl: string;
commander: string;
duel: string;
future: string;
gladiator: string;
historic: string;
legacy: string;
modern: string;
pauper: string;
penny: string;
pioneer: string;
premodern: string;
standard: string;
vintage: string;
};
manaCost: string;
name: string;
originalText: string;
originalType: string;
power: string;
printings: string[];
rarity: string;
rulings: {
date: string;
text: string;
}[];
side: string;
setCode: string;
subtypes: string[];
supertypes: string[];
text: string;
toughness: string;
type: string;
types: string[];
uuid: string;
variations: string[];
}
export class Set {
baseSetSize: number;
block: string;
cards: string[];
code: string;
isOnlineOnly: boolean;
name: string;
releaseDate: string;
totalSetSize: number;
type: string;
}
export class Token {
name: { value: string };
prop: {
value: {
cmc: { value: string; };
colors: { value: string; };
maintype: { value: string; };
pt: { value: string; };
type: { value: string; };
};
};
related: { value: string; }[];
'reverse-related': { value: string; }[];
set: {
value: string;
picURL: string;
}[];
tablerow: { value: string; };
text: { value: string; };
}

View file

@ -0,0 +1,84 @@
import {
URL_REGEX,
MESSAGE_SENDER_REGEX,
MENTION_REGEX,
CARD_CALLOUT_REGEX,
CALLOUT_BOUNDARY_REGEX,
} from './constants';
describe('RegEx', () => {
describe('URL_REGEX', () => {
it('should match and capture whole url in main capture group', () => {
const test = [
'http://example.com',
'https://example.com',
'https://www.example.com',
];
test.forEach(str => {
const match = str.match(URL_REGEX);
expect(match).toBeDefined();
expect(match[0]).toBe(str);
});
});
it('should not match bad urls', () => {
const test = [
'htt://example.com',
'https:/example.com',
'https//www.example.com',
'www.example.com',
'example.com',
];
test.forEach(str =>
expect(str.match(URL_REGEX)).toBe(null)
);
});
});
describe('MESSAGE_SENDER_REGEX', () => {
it('should match and capture sender name in second capture group', () => {
const sender = 'sender';
const match = `${sender}: message`.match(MESSAGE_SENDER_REGEX);
expect(match).toBeDefined();
expect(match[1]).toBe(sender);
});
it('should not match if spaces before :', () => {
const test = [
' sender: message',
'sender : message',
' sender : message',
];
test.forEach(str =>
expect(str.match(URL_REGEX)).toBe(null)
);
});
});
describe('MENTION_REGEX', () => {
it('should match and capture user mentions in second capture group', () => {
expect('@mention'.match(MENTION_REGEX)[0]).toBe('@mention');
expect('@mention '.match(MENTION_REGEX)[0]).toBe('@mention');
expect(' @mention'.match(MENTION_REGEX)[0]).toBe(' @mention');
expect(' @mention '.match(MENTION_REGEX)[0]).toBe(' @mention');
expect('leading @mention'.match(MENTION_REGEX)[0]).toBe(' @mention');
expect('leading @mention trailing'.match(MENTION_REGEX)[0]).toBe(' @mention');
expect('@mention trailing'.match(MENTION_REGEX)[0]).toBe('@mention');
});
it('should not match preceded by character', () => {
const test = [
'leading@mention',
];
test.forEach(str =>
expect(str.match(MENTION_REGEX)).toBe(null)
);
});
});
});

View file

@ -0,0 +1,6 @@
// eslint-disable-next-line
export const URL_REGEX = /(https?:\/\/(?:www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,4}\b(?:[-a-zA-Z0-9@:%_\+.~#?&//=]*))/g;
export const MESSAGE_SENDER_REGEX = /(^[^:\s]+):/;
export const MENTION_REGEX = /(^|\s)(@\w+)/g;
export const CARD_CALLOUT_REGEX = /(\[\[[^\]]+\]\])/g;
export const CALLOUT_BOUNDARY_REGEX = /(\[\[|\]\])/g;

View file

@ -1,6 +1,7 @@
export enum FormKey {
ADD_TO_BUDDIES = "ADD_TO_BUDDIES",
ADD_TO_IGNORE = "ADD_TO_IGNORE",
CARD_IMPORT = "CARD_IMPORT",
CONNECT = "CONNECT",
REGISTER = "REGISTER",
SEARCH_LOGS = "SEARCH_LOGS",

View file

@ -1,3 +1,5 @@
export * from "./cards";
export * from "./constants";
export * from "./game";
export * from "./room";
export * from "./server";

View file

@ -22,7 +22,7 @@ export enum KnownHost {
}
export const KnownHosts = {
[KnownHost.ROOSTER]: { port: 443, host: 'server.cockatrice.us', },
[KnownHost.ROOSTER]: { port: 4748, host: 'server.cockatrice.us', },
[KnownHost.TETRARCH]: { port: 443, host: 'mtg.tetrarch.co/servatrice'},
}