feat: id discovery

This commit is contained in:
TrèsAbhi committed 2024-05-18 21:12:11 -05:00
1 parent 87b44d1c27
commit b4c7b07158
6 files changed
+222

No files matched your search

+12
View File
@@ -1,5 +1,17 @@
import { Region } from '../../constants/regions';
export const MIN_IDS: Record<Region, number> = {
asia: 20e8,
com: 10e8,
eu: 5e8,
};
export const MAX_IDS: Record<Region, number> = {
asia: 31e8 - 1,
com: MIN_IDS.asia - 1,
eu: MIN_IDS.com - 1,
};
export function idToRegion(id: number): Region {
if (id >= 42e8) {
throw new Error('bot id');
+51
View File
@@ -0,0 +1,51 @@
import { times } from 'lodash';
import { ReadStream, WriteStream } from './buffer';
export class DidsReadStream extends ReadStream {
dids() {
this.magic();
this.header();
return this.body();
}
magic() {
const magic = this.utf8(4);
if (magic !== 'DIDS') {
throw new Error(`Invalid DIDS magic number: "${magic}"`);
}
}
header() {
return {
version: this.uint16(),
};
}
body() {
const count = this.uint32();
return times(count, () => this.uint32());
}
}
export class DidsWriteStream extends WriteStream {
dids(ids: number[]) {
this.magic();
this.header();
this.body(ids);
return this;
}
magic() {
this.utf8('DIDS');
}
header() {
this.uint16(1);
}
body(ids: number[]) {
this.uint32(ids.length);
ids.forEach((id) => this.uint32(id));
}
}