mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-11-16 06:06:11 +01:00
feat: start of monorepo
This commit is contained in:
1 parent
14f39d71ac
commit
73c7bdf0c0
260 files changed
+1236
-1235
No files matched your search
@@ -1,5 +1,5 @@
|
||||
import { assertSecret } from '@blitzkit/core';
|
||||
import { Region } from '../../constants/regions';
|
||||
import { WARGAMING_APPLICATION_ID } from '../../constants/wargamingApplicationID';
|
||||
import { EventManager } from '../blitzkit/eventManager';
|
||||
import { patientFetch } from '../blitzkit/patientFetch';
|
||||
|
||||
@@ -73,7 +73,7 @@ export default function fetchBlitz<Data extends object>(
|
||||
return new Promise<Data>((resolve) => {
|
||||
queue.push({
|
||||
url: `https://api.wotblitz.${region}/wotb/${path}/?${Object.entries({
|
||||
application_id: WARGAMING_APPLICATION_ID,
|
||||
application_id: assertSecret(process.env.WARGAMING_APPLICATION_ID),
|
||||
...params,
|
||||
})
|
||||
.filter(([_, value]) => value !== undefined)
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
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');
|
||||
} else if (id >= 31e8) {
|
||||
throw new Error('china id');
|
||||
} else if (id >= 20e8) {
|
||||
return 'asia';
|
||||
} else if (id >= 10e8) {
|
||||
return 'com';
|
||||
} else if (id >= 5e8) {
|
||||
return 'eu';
|
||||
} else if (id >= 0) {
|
||||
throw new Error('ru id');
|
||||
} else {
|
||||
throw new Error(`id ${id} is out of range`);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
import { assertSecret } from '@blitzkit/core/src/blitzkit/assertSecret';
|
||||
import { ASSETS_REPO } from '../../constants/assets';
|
||||
import { assertSecret } from './secret';
|
||||
|
||||
export function asset(path: string) {
|
||||
return `https://raw.githubusercontent.com/tresabhi/${ASSETS_REPO}/${assertSecret(
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { assertSecret } from '../../../packages/core/src/blitzkit/assertSecret';
|
||||
import { ASSETS_REPO } from '../../constants/assets';
|
||||
import commitMultipleFiles, { FileChange } from './commitMultipleFiles';
|
||||
import { assertSecret } from './secret';
|
||||
|
||||
export async function commitAssets(message: string, changes: FileChange[]) {
|
||||
console.log(`Committing ${message}...`);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { superDecompress } from './superDecompress';
|
||||
import { superDecompress } from '@blitzkit/core/src/blitzkit/superDecompress';
|
||||
|
||||
export async function fetchCdonLz4<Type>(url: string) {
|
||||
return await fetch(url, { cache: 'no-store' })
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { TankFilters } from '../../stores/tankFilters';
|
||||
import { TankFilters } from '../../../packages/website/src/stores/tankFilters';
|
||||
import { TankDefinition } from './tankDefinitions';
|
||||
|
||||
export function filterTank(filters: TankFilters, tank: TankDefinition) {
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
import { asset } from './asset';
|
||||
import { fetchCdonLz4 } from './fetchCdonLz4';
|
||||
|
||||
interface GameMode {
|
||||
name: string;
|
||||
}
|
||||
|
||||
export interface GameDefinitions {
|
||||
version: string;
|
||||
nations: string[];
|
||||
gameModes: Record<number, GameMode>;
|
||||
roles: Record<
|
||||
number,
|
||||
{
|
||||
provisions: number[];
|
||||
consumables: number[];
|
||||
}
|
||||
>;
|
||||
}
|
||||
|
||||
export const gameDefinitions = fetchCdonLz4<GameDefinitions>(
|
||||
asset('definitions/game.cdon.lz4'),
|
||||
);
|
||||
@@ -1,7 +1,7 @@
|
||||
import { superDecompress } from '@blitzkit/core/src/blitzkit/superDecompress';
|
||||
import { RatingInfo } from '../../commands/ratingLeaderboard';
|
||||
import { Region } from '../../constants/regions';
|
||||
import { asset } from './asset';
|
||||
import { superDecompress } from './superDecompress';
|
||||
|
||||
const cache: Record<
|
||||
Region,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { EquipmentMatrix } from '../../stores/duel';
|
||||
import { EquipmentMatrix } from '../../../packages/website/src/stores/duel';
|
||||
import { equipmentDefinitions } from './equipmentDefinitions';
|
||||
|
||||
export async function hasEquipment(
|
||||
|
||||
@@ -1,50 +0,0 @@
|
||||
export enum ImgurSize {
|
||||
/**
|
||||
* The default size
|
||||
*/
|
||||
Default = '',
|
||||
/**
|
||||
* Unknown size but really really small
|
||||
*/
|
||||
UltraSmall = 'ss',
|
||||
/**
|
||||
* 90x90
|
||||
*/
|
||||
SmallSquare = 's',
|
||||
/**
|
||||
* 160x160
|
||||
*/
|
||||
BigSquare = 'b',
|
||||
/**
|
||||
* 160x160
|
||||
*/
|
||||
SmallThumbnail = 't',
|
||||
/**
|
||||
* 320x320
|
||||
*/
|
||||
MediumThumbnail = 'm',
|
||||
/**
|
||||
* 640x640
|
||||
*/
|
||||
LargeThumbnail = 'l',
|
||||
/**
|
||||
* 1024x1024
|
||||
*/
|
||||
HugeThumbnail = 'h',
|
||||
}
|
||||
|
||||
interface ImgurOptions {
|
||||
format: 'jpeg' | 'png';
|
||||
size: ImgurSize;
|
||||
}
|
||||
|
||||
const defaultImgurOptions: ImgurOptions = {
|
||||
format: 'png',
|
||||
size: ImgurSize.Default,
|
||||
};
|
||||
|
||||
export function imgur(id: string, imgurOptions?: Partial<ImgurOptions>) {
|
||||
const options = { ...defaultImgurOptions, ...imgurOptions };
|
||||
|
||||
return `https://i.imgur.com/${id}${options.size}.${options.format}`;
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
import { throttling } from '@octokit/plugin-throttling';
|
||||
import { Octokit } from '@octokit/rest';
|
||||
import { assertSecret } from './secret';
|
||||
import { assertSecret } from '../../../packages/core/src/blitzkit/assertSecret';
|
||||
|
||||
Octokit.plugin(throttling);
|
||||
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
import { assertSecret } from './secret';
|
||||
|
||||
export function patreonLoginUrl() {
|
||||
const params = new URLSearchParams({
|
||||
response_type: 'code',
|
||||
client_id: assertSecret(process.env.NEXT_PUBLIC_PATREON_CLIENT_ID),
|
||||
redirect_uri: assertSecret(process.env.NEXT_PUBLIC_PATREON_REDIRECT_URI),
|
||||
scope: 'identity',
|
||||
});
|
||||
|
||||
return `https://www.patreon.com/oauth2/authorize?${params}`;
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
export function assertSecret(secret?: string) {
|
||||
if (secret === undefined) throw new Error('Missing secret');
|
||||
return secret;
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
import { compress } from 'lz4js';
|
||||
import { CdonWriteStream } from '../streams/cdon';
|
||||
|
||||
export function superCompress(object: any) {
|
||||
const write = new CdonWriteStream().cdon(object);
|
||||
const compressed = compress(write.uint8Array);
|
||||
return Buffer.from(compressed).toString('base64');
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
import { decompress } from 'lz4js';
|
||||
import { CdonReadStream } from '../streams/cdon';
|
||||
|
||||
export function superDecompress<Type>(buffer: ArrayBuffer) {
|
||||
const decompressed = decompress(new Uint8Array(buffer)).buffer as ArrayBuffer;
|
||||
const read = new CdonReadStream(decompressed);
|
||||
return read.cdon() as Type;
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import { EquipmentMatrix } from '../../stores/duel';
|
||||
import { EquipmentMatrix } from '../../../packages/website/src/stores/duel';
|
||||
import { isExplosive } from '../blitz/isExplosive';
|
||||
import { resolveNearPenetration } from '../blitz/resolveNearPenetration';
|
||||
import { resolvePenetrationCoefficient } from '../blitz/resolvePenetrationCoefficient';
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { uniqueId } from 'lodash';
|
||||
import { CompareMember } from '../../stores/compareEphemeral';
|
||||
import { CompareMember } from '../../../packages/website/src/stores/compareEphemeral';
|
||||
import { ProvisionDefinitions } from './provisionDefinitions';
|
||||
import { TankDefinition } from './tankDefinitions';
|
||||
import { tankToDuelMember } from './tankToDuelMember';
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { DuelMember } from '../../stores/duel';
|
||||
import { genericDefaultEquipmentMatrix } from '../../stores/duel/constants';
|
||||
import { DuelMember } from '../../../packages/website/src/stores/duel';
|
||||
import { genericDefaultEquipmentMatrix } from '../../../packages/website/src/stores/duel/constants';
|
||||
import { availableProvisions } from './availableProvisions';
|
||||
import { ProvisionDefinitions } from './provisionDefinitions';
|
||||
import { TankDefinition } from './tankDefinitions';
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { gameDefinitions } from '@blitzkit/core/src/blitzkit/gameDefinitions';
|
||||
import {
|
||||
SlashCommandBuilder,
|
||||
SlashCommandSubcommandBuilder,
|
||||
SlashCommandSubcommandGroupBuilder,
|
||||
} from 'discord.js';
|
||||
import { gameDefinitions } from '../blitzkit/gameDefinitions';
|
||||
import { addFilterOptions } from './addFilterOptions';
|
||||
import { addPeriodSubCommands } from './addPeriodSubCommands';
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { ShardingManager } from 'discord.js';
|
||||
import { assertSecret } from '../blitzkit/secret';
|
||||
import { assertSecret } from '../../../packages/core/src/blitzkit/assertSecret';
|
||||
|
||||
export const manager = new ShardingManager('dist/bot/workers/bot.js', {
|
||||
token: assertSecret(process.env.DISCORD_TOKEN),
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { assertSecret } from '../../../packages/core/src/blitzkit/assertSecret';
|
||||
import { ASSETS_REPO } from '../../constants/assets';
|
||||
import { GithubChangeBlob, createBlob } from '../blitzkit/createBlob';
|
||||
import { octokit } from '../blitzkit/octokit';
|
||||
import { assertSecret } from '../blitzkit/secret';
|
||||
|
||||
export class AssetCommit {
|
||||
constructor(public message: string) {}
|
||||
|
||||
@@ -1,86 +0,0 @@
|
||||
import { Draft, produce } from 'immer';
|
||||
import {
|
||||
createContext,
|
||||
ReactNode,
|
||||
useContext,
|
||||
useEffect,
|
||||
useRef,
|
||||
useState,
|
||||
} from 'react';
|
||||
import { StoreApi, useStore as useStoreZustand } from 'zustand';
|
||||
|
||||
type StoreProviderProps<InitData> = {
|
||||
children: ReactNode;
|
||||
} & (InitData extends unknown ? { data?: InitData } : { data: InitData });
|
||||
|
||||
// idk why zustand doesn't export this
|
||||
type ExtractState<S> = S extends {
|
||||
getState: () => infer T;
|
||||
}
|
||||
? T
|
||||
: never;
|
||||
|
||||
export function createNextSafeStore<Store extends StoreApi<unknown>, InitData>(
|
||||
initialize: (data: InitData) => Store,
|
||||
) {
|
||||
type Type = Store extends StoreApi<infer T> ? T : never;
|
||||
|
||||
const Context = createContext<Store | undefined>(undefined);
|
||||
|
||||
function Provider(props: StoreProviderProps<InitData>) {
|
||||
const storeRef = useRef<Store>();
|
||||
if (!storeRef.current) {
|
||||
storeRef.current = initialize((props as { data: InitData }).data);
|
||||
}
|
||||
|
||||
return (
|
||||
<Context.Provider value={storeRef.current}>
|
||||
{props.children}
|
||||
</Context.Provider>
|
||||
);
|
||||
}
|
||||
|
||||
function useStore() {
|
||||
const store = useContext(Context);
|
||||
if (!store) throw new Error('useStore must be used within Provider');
|
||||
return store as Store;
|
||||
}
|
||||
|
||||
function use<Slice = Type>(
|
||||
selector: (store: Type) => Slice = (state) => state as Slice,
|
||||
) {
|
||||
const store = useStore();
|
||||
return useStoreZustand(
|
||||
store,
|
||||
selector as (state: ExtractState<Store>) => Slice,
|
||||
);
|
||||
}
|
||||
|
||||
function useDeferred<Slice = Type>(
|
||||
initial: Slice,
|
||||
selector: (store: Type) => Slice = (state) => state as Slice,
|
||||
) {
|
||||
const [state, setState] = useState(initial);
|
||||
const trueState = use(selector);
|
||||
|
||||
useEffect(() => {
|
||||
setState(trueState);
|
||||
}, [trueState]);
|
||||
|
||||
return state;
|
||||
}
|
||||
|
||||
function useMutation() {
|
||||
const counterStoreContext = useStore();
|
||||
|
||||
return function (recipe: (draft: Draft<Type>) => void) {
|
||||
counterStoreContext.setState(
|
||||
produce<Type>((draft) => {
|
||||
recipe(draft);
|
||||
}),
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
return { Provider, use, useMutation, useStore, useDeferred };
|
||||
}
|
||||
Reference in new issue
Block a user