Skip to content

Commit a4d5286

Browse files
committed
Simple bot
0 parents  commit a4d5286

23 files changed

+26488
-0
lines changed

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
app/config.json
2+
./database.sqlite
3+
node_modules
4+
out
5+
.idea/*

.prettierrc

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"tabWidth": 2,
3+
"useTabs": false,
4+
"semi": false,
5+
"singleQuote": false,
6+
"trailingComma": "none",
7+
"bracketSpacing": true,
8+
"jsxBracketSameLine": false,
9+
"arrowParens": "always",
10+
"requirePragma": false,
11+
"insertPragma": false,
12+
"proseWrap": "always"
13+
}

.sequelizerc

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const path = require("path");
2+
3+
module.exports = {
4+
"config": path.resolve("app/config", "config.json"),
5+
"models-path": path.resolve("app", "models"),
6+
"seeders-path": path.resolve("app", "seeders"),
7+
"migrations-path": path.resolve("app", "migrations")
8+
};

app/config/config.json

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"development": {
3+
"storage": "./database.sqlite",
4+
"dialect": "sqlite"
5+
},
6+
"test": {
7+
"storage": "./database.sqlite",
8+
"dialect": "sqlite"
9+
},
10+
"production": {
11+
"storage": "./database.sqlite",
12+
"dialect": "sqlite"
13+
}
14+
}

app/db.ts

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { Sequelize } from "sequelize-typescript"
2+
import config from "./config/config.json"
3+
import { Stat } from "./models/stats.model"
4+
//@ts-ignore
5+
const sequelize = new Sequelize({
6+
//@ts-ignore
7+
dialect: config.development.dialect,
8+
storage: config.development.storage,
9+
logQueryParameters: true,
10+
models: ["/models"],
11+
modelMatch: () => {
12+
return true
13+
}
14+
})
15+
16+
sequelize.addModels([Stat])
17+
18+
export default sequelize as Sequelize

app/gql/fragment-masking.ts

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import type { ResultOf, DocumentTypeDecoration, TypedDocumentNode } from '@graphql-typed-document-node/core';
2+
import type { FragmentDefinitionNode } from 'graphql';
3+
import type { Incremental } from './graphql';
4+
5+
6+
export type FragmentType<TDocumentType extends DocumentTypeDecoration<any, any>> = TDocumentType extends DocumentTypeDecoration<
7+
infer TType,
8+
any
9+
>
10+
? [TType] extends [{ ' $fragmentName'?: infer TKey }]
11+
? TKey extends string
12+
? { ' $fragmentRefs'?: { [key in TKey]: TType } }
13+
: never
14+
: never
15+
: never;
16+
17+
// return non-nullable if `fragmentType` is non-nullable
18+
export function useFragment<TType>(
19+
_documentNode: DocumentTypeDecoration<TType, any>,
20+
fragmentType: FragmentType<DocumentTypeDecoration<TType, any>>
21+
): TType;
22+
// return nullable if `fragmentType` is nullable
23+
export function useFragment<TType>(
24+
_documentNode: DocumentTypeDecoration<TType, any>,
25+
fragmentType: FragmentType<DocumentTypeDecoration<TType, any>> | null | undefined
26+
): TType | null | undefined;
27+
// return array of non-nullable if `fragmentType` is array of non-nullable
28+
export function useFragment<TType>(
29+
_documentNode: DocumentTypeDecoration<TType, any>,
30+
fragmentType: ReadonlyArray<FragmentType<DocumentTypeDecoration<TType, any>>>
31+
): ReadonlyArray<TType>;
32+
// return array of nullable if `fragmentType` is array of nullable
33+
export function useFragment<TType>(
34+
_documentNode: DocumentTypeDecoration<TType, any>,
35+
fragmentType: ReadonlyArray<FragmentType<DocumentTypeDecoration<TType, any>>> | null | undefined
36+
): ReadonlyArray<TType> | null | undefined;
37+
export function useFragment<TType>(
38+
_documentNode: DocumentTypeDecoration<TType, any>,
39+
fragmentType: FragmentType<DocumentTypeDecoration<TType, any>> | ReadonlyArray<FragmentType<DocumentTypeDecoration<TType, any>>> | null | undefined
40+
): TType | ReadonlyArray<TType> | null | undefined {
41+
return fragmentType as any;
42+
}
43+
44+
45+
export function makeFragmentData<
46+
F extends DocumentTypeDecoration<any, any>,
47+
FT extends ResultOf<F>
48+
>(data: FT, _fragment: F): FragmentType<F> {
49+
return data as FragmentType<F>;
50+
}
51+
export function isFragmentReady<TQuery, TFrag>(
52+
queryNode: DocumentTypeDecoration<TQuery, any>,
53+
fragmentNode: TypedDocumentNode<TFrag>,
54+
data: FragmentType<TypedDocumentNode<Incremental<TFrag>, any>> | null | undefined
55+
): data is FragmentType<typeof fragmentNode> {
56+
const deferredFields = (queryNode as { __meta__?: { deferredFields: Record<string, (keyof TFrag)[]> } }).__meta__
57+
?.deferredFields;
58+
59+
if (!deferredFields) return true;
60+
61+
const fragDef = fragmentNode.definitions[0] as FragmentDefinitionNode | undefined;
62+
const fragName = fragDef?.name?.value;
63+
64+
const fields = (fragName && deferredFields[fragName]) || [];
65+
return fields.length > 0 && fields.every(field => data && field in data);
66+
}

app/gql/gql.ts

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/* eslint-disable */
2+
import * as types from './graphql';
3+
import type { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/core';
4+
5+
/**
6+
* Map of all GraphQL operations in the project.
7+
*
8+
* This map has several performance disadvantages:
9+
* 1. It is not tree-shakeable, so it will include all operations in the project.
10+
* 2. It is not minifiable, so the string of a GraphQL query will be multiple times inside the bundle.
11+
* 3. It does not support dead code elimination, so it will add unused operations.
12+
*
13+
* Therefore it is highly recommended to use the babel or swc plugin for production.
14+
*/
15+
const documents = {
16+
"\n mutation SendMessage($input: SendMessageInput!) {\n sendMessage(input: $input) {\n id\n }\n }\n": types.SendMessageDocument,
17+
"\n mutation RegisterBotCommand($input: RegisterCommand!) {\n registerBotCommand(input: $input) {\n success\n }\n }\n": types.RegisterBotCommandDocument,
18+
"\n mutation RegisterBotPrefix($input: RegisterPrefix!) {\n registerBotPrefix(input: $input) {\n success\n }\n }\n": types.RegisterBotPrefixDocument,
19+
};
20+
21+
/**
22+
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
23+
*
24+
*
25+
* @example
26+
* ```ts
27+
* const query = graphql(`query GetUser($id: ID!) { user(id: $id) { name } }`);
28+
* ```
29+
*
30+
* The query argument is unknown!
31+
* Please regenerate the types.
32+
*/
33+
export function graphql(source: string): unknown;
34+
35+
/**
36+
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
37+
*/
38+
export function graphql(source: "\n mutation SendMessage($input: SendMessageInput!) {\n sendMessage(input: $input) {\n id\n }\n }\n"): (typeof documents)["\n mutation SendMessage($input: SendMessageInput!) {\n sendMessage(input: $input) {\n id\n }\n }\n"];
39+
/**
40+
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
41+
*/
42+
export function graphql(source: "\n mutation RegisterBotCommand($input: RegisterCommand!) {\n registerBotCommand(input: $input) {\n success\n }\n }\n"): (typeof documents)["\n mutation RegisterBotCommand($input: RegisterCommand!) {\n registerBotCommand(input: $input) {\n success\n }\n }\n"];
43+
/**
44+
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
45+
*/
46+
export function graphql(source: "\n mutation RegisterBotPrefix($input: RegisterPrefix!) {\n registerBotPrefix(input: $input) {\n success\n }\n }\n"): (typeof documents)["\n mutation RegisterBotPrefix($input: RegisterPrefix!) {\n registerBotPrefix(input: $input) {\n success\n }\n }\n"];
47+
48+
export function graphql(source: string) {
49+
return (documents as any)[source] ?? {};
50+
}
51+
52+
export type DocumentType<TDocumentNode extends DocumentNode<any, any>> = TDocumentNode extends DocumentNode< infer TType, any> ? TType : never;

0 commit comments

Comments
 (0)