Commit a764c716 authored by nanahira's avatar nanahira

lflist

parent d3ed7e14
......@@ -172,7 +172,7 @@ async function queryCards(queryInfo: QueryInfo) {
}
const wantedStatement = checkerInfo.statement != null ? checkerInfo.statement : true;
await checker.setInfo(checkerInfo.data);
cards = cards.filter(card => checker.check(card));
cards = cards.filter(card => !!checker.check(card) === wantedStatement);
}
}
return cards;
......
upper: 100000000
lower: 0
noFilterAlias: false
checkers:
conditions:
- type: lflist
statement: true
data:
......@@ -11,7 +11,7 @@ checkers:
statement: true
data:
field: name
pattern: '^.*$'
pattern: '^.*雷龙$'
where:
- "type & {TYPE_MONSTER} > 0"
mayIncorrectStatements:
......
......@@ -28,9 +28,17 @@
upper: 100000000
lower: 0
noFilterAlias: false
regexConditions:
- field: name
pattern: '^雷龙$'
conditions:
- type: lflist
statement: true
data:
match: '^2021.4$'
limit: 3
- type: regex
statement: true
data:
field: name
pattern: '^.*雷龙$'
where:
- "type & {TYPE_MONSTER} > 0"
mayIncorrectStatements:
......@@ -54,7 +62,7 @@ mayIncorrectStatements:
* `where` 约束条件,使用 SQL 语句填写,相互之间是 AND 的关系。
* `regexConditions` 卡名或描述的正则过滤条件。`field` 可以是 `name` 或者 `desc`
* `conditions` 额外过滤条件
### 模糊逻辑
......
import { AbstractChecker } from './checkers/AbstractChecker';
import { RegexChecker } from './checkers/RegexChecker';
import { LFListChecker } from './checkers/LFListChecker';
export interface Card {
id: number;
......@@ -21,6 +22,8 @@ export async function loadCheckers() {
// add checkers here
const regexChecker = new RegexChecker();
checkersList.set('regex', regexChecker);
const lflistChecker = new LFListChecker();
checkersList.set('lflist', lflistChecker);
for (let checkerName of checkersList.keys()) {
const checker = checkersList.get(checkerName);
......
import { AbstractChecker, Card } from "./AbstractChecker";
import { promises as fs } from "fs";
type Records = Map<number, number>;
class LFList {
name: string;
records: Records;
constructor(name: string) {
this.name = name;
this.records = new Map();
}
addRecord(id: number, num: number) {
this.records.set(id, num);
}
getNum(id: number) {
if (!this.records.has(id)) {
return 3;
}
return this.records.get(id);
}
}
export class LFListChecker extends AbstractChecker {
info: any;
lflists: LFList[];
pendingLists: LFList[];
expectedCount: number;
async initialize() {
this.lflists = [];
const content = await fs.readFile('./lflist.conf', "utf-8");
let currentLFList: LFList;
for (let _line of content.split('\n')) {
const line = _line.trim();
if (line.startsWith('#')) {
continue;
}
let match: RegExpMatchArray;
match = line.match(/^!(.+)$/);
if (match) {
const lflistName = match[1];
currentLFList = new LFList(lflistName);
console.log(`Loading LFList ${lflistName}`);
this.lflists.push(currentLFList);
continue;
}
match = line.match(/^(\d+) (\d).*$/);
if (match) {
if (currentLFList) {
currentLFList.addRecord(parseInt(match[1]), parseInt(match[2]));
}
continue;
}
}
}
async setInfo(info: any) {
await super.setInfo(info);
this.pendingLists = this.lflists.filter(list => list.name.match(info.match));
this.expectedCount = info.limit;
}
check(card: Card) {
return this.pendingLists.some(list => list.getNum(card.id) === this.expectedCount);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment