mirror of
https://github.com/spacebarchat/server.git
synced 2024-11-10 20:52:42 +01:00
✨ typeorm entities
This commit is contained in:
parent
af1b5f30c6
commit
1e5ed28514
111
util/src/entities/Application.ts
Normal file
111
util/src/entities/Application.ts
Normal file
@ -0,0 +1,111 @@
|
||||
import { Column, Entity, JoinColumn, ManyToOne } from "typeorm";
|
||||
import { BaseClass } from "./BaseClass";
|
||||
import { Guild } from "./Guild";
|
||||
import { Team } from "./Team";
|
||||
|
||||
@Entity("applications")
|
||||
export class Application extends BaseClass {
|
||||
@Column()
|
||||
name: string;
|
||||
|
||||
@Column()
|
||||
icon?: string;
|
||||
|
||||
@Column()
|
||||
description: string;
|
||||
|
||||
@Column("simple-array")
|
||||
rpc_origins?: string[];
|
||||
|
||||
@Column()
|
||||
bot_public: boolean;
|
||||
|
||||
@Column()
|
||||
bot_require_code_grant: boolean;
|
||||
|
||||
@Column()
|
||||
terms_of_service_url?: string;
|
||||
|
||||
@Column()
|
||||
privacy_policy_url?: string;
|
||||
|
||||
@Column()
|
||||
owner_id: string;
|
||||
|
||||
@Column()
|
||||
summary?: string;
|
||||
|
||||
@Column()
|
||||
verify_key: string;
|
||||
|
||||
@Column()
|
||||
team_id: string;
|
||||
|
||||
@JoinColumn({ name: "team_id" })
|
||||
@ManyToOne(() => Team, (team: Team) => team.id)
|
||||
team?: Team;
|
||||
|
||||
@Column()
|
||||
guild_id: string;
|
||||
|
||||
@JoinColumn({ name: "guild_id" })
|
||||
@ManyToOne(() => Guild, (guild: Guild) => guild.id)
|
||||
guild: Guild; // if this application is a game sold, this field will be the guild to which it has been linked
|
||||
|
||||
@Column()
|
||||
primary_sku_id?: string; // if this application is a game sold, this field will be the id of the "Game SKU" that is created,
|
||||
|
||||
@Column()
|
||||
slug?: string; // if this application is a game sold, this field will be the URL slug that links to the store page
|
||||
|
||||
@Column()
|
||||
cover_image?: string; // the application's default rich presence invite cover image hash
|
||||
|
||||
@Column()
|
||||
flags: number; // the application's public flags
|
||||
}
|
||||
|
||||
export interface ApplicationCommand {
|
||||
id: string;
|
||||
application_id: string;
|
||||
name: string;
|
||||
description: string;
|
||||
options?: ApplicationCommandOption[];
|
||||
}
|
||||
|
||||
export interface ApplicationCommandOption {
|
||||
type: ApplicationCommandOptionType;
|
||||
name: string;
|
||||
description: string;
|
||||
required?: boolean;
|
||||
choices?: ApplicationCommandOptionChoice[];
|
||||
options?: ApplicationCommandOption[];
|
||||
}
|
||||
|
||||
export interface ApplicationCommandOptionChoice {
|
||||
name: string;
|
||||
value: string | number;
|
||||
}
|
||||
|
||||
export enum ApplicationCommandOptionType {
|
||||
SUB_COMMAND = 1,
|
||||
SUB_COMMAND_GROUP = 2,
|
||||
STRING = 3,
|
||||
INTEGER = 4,
|
||||
BOOLEAN = 5,
|
||||
USER = 6,
|
||||
CHANNEL = 7,
|
||||
ROLE = 8,
|
||||
}
|
||||
|
||||
export interface ApplicationCommandInteractionData {
|
||||
id: string;
|
||||
name: string;
|
||||
options?: ApplicationCommandInteractionDataOption[];
|
||||
}
|
||||
|
||||
export interface ApplicationCommandInteractionDataOption {
|
||||
name: string;
|
||||
value?: any;
|
||||
options?: ApplicationCommandInteractionDataOption[];
|
||||
}
|
147
util/src/entities/AuditLog.ts
Normal file
147
util/src/entities/AuditLog.ts
Normal file
@ -0,0 +1,147 @@
|
||||
import { Column, Entity, JoinColumn, ManyToOne } from "typeorm";
|
||||
import { BaseClass } from "./BaseClass";
|
||||
import { ChannelPermissionOverwrite } from "./Channel";
|
||||
import { User } from "./User";
|
||||
|
||||
export enum AuditLogEvents {
|
||||
GUILD_UPDATE = 1,
|
||||
CHANNEL_CREATE = 10,
|
||||
CHANNEL_UPDATE = 11,
|
||||
CHANNEL_DELETE = 12,
|
||||
CHANNEL_OVERWRITE_CREATE = 13,
|
||||
CHANNEL_OVERWRITE_UPDATE = 14,
|
||||
CHANNEL_OVERWRITE_DELETE = 15,
|
||||
MEMBER_KICK = 20,
|
||||
MEMBER_PRUNE = 21,
|
||||
MEMBER_BAN_ADD = 22,
|
||||
MEMBER_BAN_REMOVE = 23,
|
||||
MEMBER_UPDATE = 24,
|
||||
MEMBER_ROLE_UPDATE = 25,
|
||||
MEMBER_MOVE = 26,
|
||||
MEMBER_DISCONNECT = 27,
|
||||
BOT_ADD = 28,
|
||||
ROLE_CREATE = 30,
|
||||
ROLE_UPDATE = 31,
|
||||
ROLE_DELETE = 32,
|
||||
INVITE_CREATE = 40,
|
||||
INVITE_UPDATE = 41,
|
||||
INVITE_DELETE = 42,
|
||||
WEBHOOK_CREATE = 50,
|
||||
WEBHOOK_UPDATE = 51,
|
||||
WEBHOOK_DELETE = 52,
|
||||
EMOJI_CREATE = 60,
|
||||
EMOJI_UPDATE = 61,
|
||||
EMOJI_DELETE = 62,
|
||||
MESSAGE_DELETE = 72,
|
||||
MESSAGE_BULK_DELETE = 73,
|
||||
MESSAGE_PIN = 74,
|
||||
MESSAGE_UNPIN = 75,
|
||||
INTEGRATION_CREATE = 80,
|
||||
INTEGRATION_UPDATE = 81,
|
||||
INTEGRATION_DELETE = 82,
|
||||
}
|
||||
|
||||
@Entity("audit_logs")
|
||||
export class AuditLogEntry extends BaseClass {
|
||||
@Column()
|
||||
target_id: string;
|
||||
|
||||
@JoinColumn({ name: "user_id" })
|
||||
@ManyToOne(() => User, (user: User) => user.id)
|
||||
target?: User;
|
||||
|
||||
@Column()
|
||||
user_id: string;
|
||||
|
||||
@JoinColumn({ name: "user_id" })
|
||||
@ManyToOne(() => User, (user: User) => user.id)
|
||||
user: User;
|
||||
|
||||
@Column({
|
||||
type: "simple-enum",
|
||||
enum: AuditLogEvents,
|
||||
})
|
||||
action_type: AuditLogEvents;
|
||||
|
||||
@Column("simple-json")
|
||||
options?: {
|
||||
delete_member_days?: string;
|
||||
members_removed?: string;
|
||||
channel_id?: string;
|
||||
messaged_id?: string;
|
||||
count?: string;
|
||||
id?: string;
|
||||
type?: string;
|
||||
role_name?: string;
|
||||
};
|
||||
|
||||
@Column()
|
||||
@Column("simple-json")
|
||||
changes: AuditLogChange[];
|
||||
|
||||
@Column()
|
||||
reason?: string;
|
||||
}
|
||||
|
||||
export interface AuditLogChange {
|
||||
new_value?: AuditLogChangeValue;
|
||||
old_value?: AuditLogChangeValue;
|
||||
key: string;
|
||||
}
|
||||
|
||||
export interface AuditLogChangeValue {
|
||||
name?: string;
|
||||
description?: string;
|
||||
icon_hash?: string;
|
||||
splash_hash?: string;
|
||||
discovery_splash_hash?: string;
|
||||
banner_hash?: string;
|
||||
owner_id?: string;
|
||||
region?: string;
|
||||
preferred_locale?: string;
|
||||
afk_channel_id?: string;
|
||||
afk_timeout?: number;
|
||||
rules_channel_id?: string;
|
||||
public_updates_channel_id?: string;
|
||||
mfa_level?: number;
|
||||
verification_level?: number;
|
||||
explicit_content_filter?: number;
|
||||
default_message_notifications?: number;
|
||||
vanity_url_code?: string;
|
||||
$add?: {}[];
|
||||
$remove?: {}[];
|
||||
prune_delete_days?: number;
|
||||
widget_enabled?: boolean;
|
||||
widget_channel_id?: string;
|
||||
system_channel_id?: string;
|
||||
position?: number;
|
||||
topic?: string;
|
||||
bitrate?: number;
|
||||
permission_overwrites?: ChannelPermissionOverwrite[];
|
||||
nsfw?: boolean;
|
||||
application_id?: string;
|
||||
rate_limit_per_user?: number;
|
||||
permissions?: string;
|
||||
color?: number;
|
||||
hoist?: boolean;
|
||||
mentionable?: boolean;
|
||||
allow?: string;
|
||||
deny?: string;
|
||||
code?: string;
|
||||
channel_id?: string;
|
||||
inviter_id?: string;
|
||||
max_uses?: number;
|
||||
uses?: number;
|
||||
max_age?: number;
|
||||
temporary?: boolean;
|
||||
deaf?: boolean;
|
||||
mute?: boolean;
|
||||
nick?: string;
|
||||
avatar_hash?: string;
|
||||
id?: string;
|
||||
type?: number;
|
||||
enable_emoticons?: boolean;
|
||||
expire_behavior?: number;
|
||||
expire_grace_period?: number;
|
||||
user_limit?: number;
|
||||
}
|
34
util/src/entities/Ban.ts
Normal file
34
util/src/entities/Ban.ts
Normal file
@ -0,0 +1,34 @@
|
||||
import { Column, Entity, JoinColumn, ManyToOne } from "typeorm";
|
||||
import { BaseClass } from "./BaseClass";
|
||||
import { Guild } from "./Guild";
|
||||
import { User } from "./User";
|
||||
|
||||
@Entity("bans")
|
||||
export class Ban extends BaseClass {
|
||||
@Column()
|
||||
user_id: string;
|
||||
|
||||
@JoinColumn({ name: "user_id" })
|
||||
@ManyToOne(() => User, (user: User) => user.id)
|
||||
user: User;
|
||||
|
||||
@Column()
|
||||
guild_id: string;
|
||||
|
||||
@JoinColumn({ name: "guild_id" })
|
||||
@ManyToOne(() => Guild, (guild: Guild) => guild.id)
|
||||
guild: Guild;
|
||||
|
||||
@Column()
|
||||
executor_id: string;
|
||||
|
||||
@JoinColumn({ name: "executor_id" })
|
||||
@ManyToOne(() => User, (user: User) => user.id)
|
||||
executor: User;
|
||||
|
||||
@Column()
|
||||
ip: string;
|
||||
|
||||
@Column()
|
||||
reason?: string;
|
||||
}
|
61
util/src/entities/BaseClass.ts
Normal file
61
util/src/entities/BaseClass.ts
Normal file
@ -0,0 +1,61 @@
|
||||
import "reflect-metadata";
|
||||
import { BaseEntity, BeforeInsert, BeforeUpdate, PrimaryColumn } from "typeorm";
|
||||
import { Snowflake } from "../util/Snowflake";
|
||||
import Ajv, { ValidateFunction } from "ajv";
|
||||
import schema from "./schema.json";
|
||||
|
||||
const ajv = new Ajv({
|
||||
removeAdditional: "all",
|
||||
useDefaults: true,
|
||||
coerceTypes: true,
|
||||
validateFormats: false,
|
||||
allowUnionTypes: true,
|
||||
});
|
||||
// const validator = ajv.compile<BaseClass>(schema);
|
||||
|
||||
export class BaseClass extends BaseEntity {
|
||||
@PrimaryColumn()
|
||||
id: string;
|
||||
|
||||
// @ts-ignore
|
||||
constructor(props?: any, public opts: { id?: string } = {}) {
|
||||
super();
|
||||
this.assign(props);
|
||||
|
||||
if (!this.construct.schema) this.construct.schema = { ...schema, $ref: `#/definitions/${this.construct.name}` };
|
||||
}
|
||||
|
||||
get construct(): any {
|
||||
return this.constructor;
|
||||
}
|
||||
|
||||
assign(props: any) {
|
||||
if (!props || typeof props !== "object") return;
|
||||
|
||||
delete props.opts;
|
||||
|
||||
for (const key in props) {
|
||||
if (this.hasOwnProperty(key)) continue;
|
||||
|
||||
Object.defineProperty(this, key, { value: props[key] });
|
||||
}
|
||||
|
||||
this.id = this.opts.id || Snowflake.generate();
|
||||
}
|
||||
|
||||
@BeforeUpdate()
|
||||
@BeforeInsert()
|
||||
validate() {
|
||||
const valid = ajv.validate(this.construct.schema, this.toJSON());
|
||||
if (!valid) throw ajv.errors;
|
||||
}
|
||||
|
||||
get metadata() {
|
||||
return this.construct.getRepository().metadata;
|
||||
}
|
||||
|
||||
toJSON(): any {
|
||||
// @ts-ignore
|
||||
return Object.fromEntries(this.metadata.columns.map((x) => [x.propertyName, this[x.propertyName]]));
|
||||
}
|
||||
}
|
104
util/src/entities/Channel.ts
Normal file
104
util/src/entities/Channel.ts
Normal file
@ -0,0 +1,104 @@
|
||||
import { Column, Entity, JoinColumn, ManyToMany, ManyToOne } from "typeorm";
|
||||
import { BaseClass } from "./BaseClass";
|
||||
import { Guild } from "./Guild";
|
||||
import { Message } from "./Message";
|
||||
import { User } from "./User";
|
||||
|
||||
export enum ChannelType {
|
||||
GUILD_TEXT = 0, // a text channel within a server
|
||||
DM = 1, // a direct message between users
|
||||
GUILD_VOICE = 2, // a voice channel within a server
|
||||
GROUP_DM = 3, // a direct message between multiple users
|
||||
GUILD_CATEGORY = 4, // an organizational category that contains up to 50 channels
|
||||
GUILD_NEWS = 5, // a channel that users can follow and crosspost into their own server
|
||||
GUILD_STORE = 6, // a channel in which game developers can sell their game on Discord
|
||||
}
|
||||
|
||||
@Entity("channels")
|
||||
export class Channel extends BaseClass {
|
||||
@Column()
|
||||
created_at: Date;
|
||||
|
||||
@Column()
|
||||
name: string;
|
||||
|
||||
@Column({ type: "simple-enum", enum: ChannelType })
|
||||
type: ChannelType;
|
||||
|
||||
@Column("simple-array")
|
||||
recipient_ids: string[];
|
||||
|
||||
@JoinColumn({ name: "recipient_ids" })
|
||||
@ManyToMany(() => User, (user: User) => user.id)
|
||||
recipients?: User[];
|
||||
|
||||
@Column()
|
||||
last_message_id: string;
|
||||
|
||||
@JoinColumn({ name: "last_message_id" })
|
||||
@ManyToOne(() => Message, (message: Message) => message.id)
|
||||
last_message?: Message;
|
||||
|
||||
@Column()
|
||||
guild_id?: string;
|
||||
|
||||
@JoinColumn({ name: "guild_id" })
|
||||
@ManyToOne(() => Guild, (guild: Guild) => guild.id)
|
||||
guild: Guild;
|
||||
|
||||
@Column()
|
||||
parent_id: string;
|
||||
|
||||
@JoinColumn({ name: "parent_id" })
|
||||
@ManyToOne(() => Channel, (channel: Channel) => channel.id)
|
||||
parent?: Channel;
|
||||
|
||||
@Column()
|
||||
owner_id: string;
|
||||
|
||||
@JoinColumn({ name: "owner_id" })
|
||||
@ManyToOne(() => User, (user: User) => user.id)
|
||||
owner: User;
|
||||
|
||||
@Column()
|
||||
last_pin_timestamp?: number;
|
||||
|
||||
@Column()
|
||||
default_auto_archive_duration?: number;
|
||||
|
||||
@Column()
|
||||
position: number;
|
||||
|
||||
@Column("simple-json")
|
||||
permission_overwrites: ChannelPermissionOverwrite[];
|
||||
|
||||
@Column()
|
||||
video_quality_mode?: number;
|
||||
|
||||
@Column()
|
||||
bitrate?: number;
|
||||
|
||||
@Column()
|
||||
user_limit?: number;
|
||||
|
||||
@Column()
|
||||
nsfw: boolean;
|
||||
|
||||
@Column()
|
||||
rate_limit_per_user: number;
|
||||
|
||||
@Column()
|
||||
topic?: string;
|
||||
}
|
||||
|
||||
export interface ChannelPermissionOverwrite {
|
||||
allow: bigint; // for bitfields we use bigints
|
||||
deny: bigint; // for bitfields we use bigints
|
||||
id: string;
|
||||
type: ChannelPermissionOverwriteType;
|
||||
}
|
||||
|
||||
export enum ChannelPermissionOverwriteType {
|
||||
role = 0,
|
||||
member = 1,
|
||||
}
|
29
util/src/entities/ConnectedAccount.ts
Normal file
29
util/src/entities/ConnectedAccount.ts
Normal file
@ -0,0 +1,29 @@
|
||||
import { Column, Entity } from "typeorm";
|
||||
import { BaseClass } from "./BaseClass";
|
||||
|
||||
@Entity("connected_accounts")
|
||||
export class ConnectedAccount extends BaseClass {
|
||||
@Column()
|
||||
access_token: string;
|
||||
|
||||
@Column()
|
||||
friend_sync: boolean;
|
||||
|
||||
@Column()
|
||||
name: string;
|
||||
|
||||
@Column()
|
||||
revoked: boolean;
|
||||
|
||||
@Column()
|
||||
show_activity: boolean;
|
||||
|
||||
@Column()
|
||||
type: string;
|
||||
|
||||
@Column()
|
||||
verifie: boolean;
|
||||
|
||||
@Column()
|
||||
visibility: number;
|
||||
}
|
39
util/src/entities/Emoji.ts
Normal file
39
util/src/entities/Emoji.ts
Normal file
@ -0,0 +1,39 @@
|
||||
import { Column, Entity, JoinColumn, ManyToMany, ManyToOne } from "typeorm";
|
||||
import { BaseClass } from "./BaseClass";
|
||||
import { Guild } from "./Guild";
|
||||
import { Role } from "./Role";
|
||||
|
||||
@Entity("emojis")
|
||||
export class Emoji extends BaseClass {
|
||||
@Column()
|
||||
animated: boolean;
|
||||
|
||||
@Column()
|
||||
available: boolean;
|
||||
|
||||
@Column()
|
||||
guild_id: string;
|
||||
|
||||
@JoinColumn({ name: "guild_id" })
|
||||
@ManyToOne(() => Guild, (guild: Guild) => guild.id)
|
||||
guild: Guild;
|
||||
|
||||
@Column()
|
||||
managed: boolean;
|
||||
|
||||
@Column()
|
||||
name: string;
|
||||
|
||||
@Column()
|
||||
require_colons: boolean;
|
||||
|
||||
@Column()
|
||||
url: string;
|
||||
|
||||
@Column("simple-array")
|
||||
role_ids: string[];
|
||||
|
||||
@JoinColumn({ name: "role_ids" })
|
||||
@ManyToMany(() => Role, (role: Role) => role.id)
|
||||
roles: Role[]; // roles this emoji is whitelisted to (new discord feature?)
|
||||
}
|
179
util/src/entities/Guild.ts
Normal file
179
util/src/entities/Guild.ts
Normal file
@ -0,0 +1,179 @@
|
||||
import { Column, Entity, JoinColumn, ManyToMany, ManyToOne, OneToOne } from "typeorm";
|
||||
import { BaseClass } from "./BaseClass";
|
||||
import { Channel } from "./Channel";
|
||||
import { Emoji } from "./Emoji";
|
||||
import { Invite } from "./Invite";
|
||||
import { Member } from "./Member";
|
||||
import { Role } from "./Role";
|
||||
import { User } from "./User";
|
||||
import { VoiceState } from "./VoiceState";
|
||||
|
||||
@Entity("guilds")
|
||||
export class Guild extends BaseClass {
|
||||
@Column()
|
||||
afk_channel_id?: string;
|
||||
|
||||
@JoinColumn({ name: "afk_channel_id" })
|
||||
@ManyToOne(() => Channel, (channel: Channel) => channel.id)
|
||||
afk_channel?: Channel;
|
||||
|
||||
@Column()
|
||||
afk_timeout?: number;
|
||||
|
||||
// * commented out -> use owner instead
|
||||
// application id of the guild creator if it is bot-created
|
||||
// @Column()
|
||||
// application?: string;
|
||||
|
||||
@Column()
|
||||
banner?: string;
|
||||
|
||||
@Column()
|
||||
default_message_notifications?: number;
|
||||
|
||||
@Column()
|
||||
description?: string;
|
||||
|
||||
@Column()
|
||||
discovery_splash?: string;
|
||||
|
||||
@Column()
|
||||
explicit_content_filter?: number;
|
||||
|
||||
@Column("simple-array")
|
||||
features: string[];
|
||||
|
||||
@Column()
|
||||
icon?: string;
|
||||
|
||||
@Column()
|
||||
large?: boolean;
|
||||
|
||||
@Column()
|
||||
max_members?: number; // e.g. default 100.000
|
||||
|
||||
@Column()
|
||||
max_presences?: number;
|
||||
|
||||
@Column()
|
||||
max_video_channel_users?: number; // ? default: 25, is this max 25 streaming or watching
|
||||
|
||||
@Column()
|
||||
member_count?: number;
|
||||
|
||||
@Column()
|
||||
presence_count?: number; // users online
|
||||
|
||||
@Column("simple-array")
|
||||
member_ids: string[];
|
||||
|
||||
@JoinColumn({ name: "member_ids" })
|
||||
@ManyToMany(() => Member, (member: Member) => member.id)
|
||||
members: Member[];
|
||||
|
||||
@Column("simple-array")
|
||||
role_ids: string[];
|
||||
|
||||
@JoinColumn({ name: "role_ids" })
|
||||
@ManyToMany(() => Role, (role: Role) => role.id)
|
||||
roles: Role[];
|
||||
|
||||
@Column("simple-array")
|
||||
channel_ids: string[];
|
||||
|
||||
@JoinColumn({ name: "channel_ids" })
|
||||
@ManyToMany(() => Channel, (channel: Channel) => channel.id)
|
||||
channels: Channel[];
|
||||
|
||||
@Column("simple-array")
|
||||
emoji_ids: string[];
|
||||
|
||||
@JoinColumn({ name: "emoji_ids" })
|
||||
@ManyToMany(() => Emoji, (emoji: Emoji) => emoji.id)
|
||||
emojis: Emoji[];
|
||||
|
||||
@Column("simple-array")
|
||||
voice_state_ids: string[];
|
||||
|
||||
@JoinColumn({ name: "voice_state_ids" })
|
||||
@ManyToMany(() => VoiceState, (voicestate: VoiceState) => voicestate.id)
|
||||
voice_states: VoiceState[];
|
||||
|
||||
@Column()
|
||||
mfa_level?: number;
|
||||
|
||||
@Column()
|
||||
name: string;
|
||||
|
||||
@Column()
|
||||
owner_id: string;
|
||||
|
||||
@JoinColumn({ name: "owner_id" })
|
||||
@ManyToOne(() => User, (user: User) => user.id)
|
||||
owner: User;
|
||||
|
||||
@Column()
|
||||
preferred_locale?: string; // only community guilds can choose this
|
||||
|
||||
@Column()
|
||||
premium_subscription_count?: number;
|
||||
|
||||
@Column()
|
||||
premium_tier?: number; // nitro boost level
|
||||
|
||||
@JoinColumn({ name: "public_updates_channel_id" })
|
||||
@ManyToOne(() => Channel, (channel: Channel) => channel.id)
|
||||
public_updates_channel?: Channel;
|
||||
|
||||
@Column()
|
||||
rules_channel_id?: string;
|
||||
|
||||
@JoinColumn({ name: "rules_channel_id" })
|
||||
@ManyToOne(() => Channel, (channel: Channel) => channel.id)
|
||||
rules_channel?: string;
|
||||
|
||||
@Column()
|
||||
region?: string;
|
||||
|
||||
@Column()
|
||||
splash?: string;
|
||||
|
||||
@Column()
|
||||
system_channel_id?: string;
|
||||
|
||||
@JoinColumn({ name: "system_channel_id" })
|
||||
@ManyToMany(() => Channel, (channel: Channel) => channel.id)
|
||||
system_channel?: Channel;
|
||||
|
||||
@Column()
|
||||
system_channel_flags?: number;
|
||||
|
||||
@Column()
|
||||
unavailable?: boolean;
|
||||
|
||||
@JoinColumn({ name: "vanity_url_code" })
|
||||
@OneToOne(() => Invite, (invite: Invite) => invite.code)
|
||||
vanity_url?: Invite;
|
||||
|
||||
@Column()
|
||||
verification_level?: number;
|
||||
|
||||
@Column("simple-json")
|
||||
welcome_screen: {
|
||||
enabled: boolean;
|
||||
description: string;
|
||||
welcome_channels: {
|
||||
description: string;
|
||||
emoji_id?: string;
|
||||
emoji_name: string;
|
||||
channel_id: string;
|
||||
}[];
|
||||
};
|
||||
|
||||
@JoinColumn({ name: "widget_channel_id" })
|
||||
@ManyToOne(() => Channel, (channel: Channel) => channel.id)
|
||||
widget_channel?: Channel;
|
||||
|
||||
@Column()
|
||||
widget_enabled?: boolean;
|
||||
}
|
60
util/src/entities/Invite.ts
Normal file
60
util/src/entities/Invite.ts
Normal file
@ -0,0 +1,60 @@
|
||||
import { Column, Entity, JoinColumn, ManyToOne } from "typeorm";
|
||||
import { BaseClass } from "./BaseClass";
|
||||
import { Channel } from "./Channel";
|
||||
import { Guild } from "./Guild";
|
||||
import { User } from "./User";
|
||||
|
||||
@Entity("invites")
|
||||
export class Invite extends BaseClass {
|
||||
@Column()
|
||||
code: string;
|
||||
|
||||
@Column()
|
||||
temporary: boolean;
|
||||
|
||||
@Column()
|
||||
uses: number;
|
||||
|
||||
@Column()
|
||||
max_uses: number;
|
||||
|
||||
@Column()
|
||||
max_age: number;
|
||||
|
||||
@Column()
|
||||
created_at: Date;
|
||||
|
||||
@Column()
|
||||
expires_at: Date;
|
||||
|
||||
@Column()
|
||||
guild_id: string;
|
||||
|
||||
@JoinColumn({ name: "guild_id" })
|
||||
@ManyToOne(() => Guild, (guild: Guild) => guild.id)
|
||||
guild: Guild;
|
||||
|
||||
@Column()
|
||||
channel_id: string;
|
||||
|
||||
@JoinColumn({ name: "channel_id" })
|
||||
@ManyToOne(() => Channel, (channel: Channel) => channel.id)
|
||||
channel: Channel;
|
||||
|
||||
@Column()
|
||||
inviter_id: string;
|
||||
|
||||
@JoinColumn({ name: "inviter_id" })
|
||||
@ManyToOne(() => User, (user: User) => user.id)
|
||||
inviter: User;
|
||||
|
||||
@Column()
|
||||
target_usser_id: string;
|
||||
|
||||
@JoinColumn({ name: "target_user_id" })
|
||||
@ManyToOne(() => User, (user: User) => user.id)
|
||||
target_user?: string; // could be used for "User specific invites" https://github.com/fosscord/fosscord/issues/62
|
||||
|
||||
@Column()
|
||||
target_user_type?: number;
|
||||
}
|
87
util/src/entities/Member.ts
Normal file
87
util/src/entities/Member.ts
Normal file
@ -0,0 +1,87 @@
|
||||
import { PublicUser, User } from "./User";
|
||||
import { BaseClass } from "./BaseClass";
|
||||
import { Column, Entity, JoinColumn, ManyToOne } from "typeorm";
|
||||
import { Guild } from "./Guild";
|
||||
|
||||
@Entity("members")
|
||||
export class Member extends BaseClass {
|
||||
@Column()
|
||||
user_id: string;
|
||||
|
||||
@JoinColumn({ name: "user_id" })
|
||||
@ManyToOne(() => User, (user: User) => user.id)
|
||||
user: User;
|
||||
|
||||
@Column()
|
||||
guild_id: string;
|
||||
|
||||
@JoinColumn({ name: "guild_id" })
|
||||
@ManyToOne(() => Guild, (guild: Guild) => guild.id)
|
||||
guild: Guild;
|
||||
|
||||
@Column()
|
||||
nick?: string;
|
||||
|
||||
@Column("simple-array")
|
||||
roles: string[];
|
||||
|
||||
@Column()
|
||||
joined_at: Date;
|
||||
|
||||
@Column()
|
||||
premium_since?: number;
|
||||
|
||||
@Column()
|
||||
deaf: boolean;
|
||||
|
||||
@Column()
|
||||
mute: boolean;
|
||||
|
||||
@Column()
|
||||
pending: boolean;
|
||||
|
||||
@Column("simple-json")
|
||||
settings: UserGuildSettings;
|
||||
|
||||
// TODO: update
|
||||
@Column("simple-json")
|
||||
read_state: Record<string, string | null>;
|
||||
}
|
||||
|
||||
export interface UserGuildSettings {
|
||||
channel_overrides: {
|
||||
channel_id: string;
|
||||
message_notifications: number;
|
||||
mute_config: MuteConfig;
|
||||
muted: boolean;
|
||||
}[];
|
||||
message_notifications: number;
|
||||
mobile_push: boolean;
|
||||
mute_config: MuteConfig;
|
||||
muted: boolean;
|
||||
suppress_everyone: boolean;
|
||||
suppress_roles: boolean;
|
||||
version: number;
|
||||
}
|
||||
|
||||
export interface MuteConfig {
|
||||
end_time: number;
|
||||
selected_time_window: number;
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
export interface PublicMember extends Omit<Member, "settings" | "id" | "read_state"> {
|
||||
user: PublicUser;
|
||||
}
|
||||
|
||||
export const PublicMemberProjection = {
|
||||
id: true,
|
||||
guild_id: true,
|
||||
nick: true,
|
||||
roles: true,
|
||||
joined_at: true,
|
||||
pending: true,
|
||||
deaf: true,
|
||||
mute: true,
|
||||
premium_since: true,
|
||||
};
|
260
util/src/entities/Message.ts
Normal file
260
util/src/entities/Message.ts
Normal file
@ -0,0 +1,260 @@
|
||||
import { User } from "./User";
|
||||
import { Member } from "./Member";
|
||||
import { Role } from "./Role";
|
||||
import { Channel } from "./Channel";
|
||||
import { InteractionType } from "../interfaces/Interaction";
|
||||
import { Application } from "./Application";
|
||||
import { Column, CreateDateColumn, Entity, JoinColumn, ManyToMany, ManyToOne, UpdateDateColumn } from "typeorm";
|
||||
import { BaseClass } from "./BaseClass";
|
||||
import { Guild } from "./Guild";
|
||||
import { Webhook } from "./Webhook";
|
||||
|
||||
export enum MessageType {
|
||||
DEFAULT = 0,
|
||||
RECIPIENT_ADD = 1,
|
||||
RECIPIENT_REMOVE = 2,
|
||||
CALL = 3,
|
||||
CHANNEL_NAME_CHANGE = 4,
|
||||
CHANNEL_ICON_CHANGE = 5,
|
||||
CHANNEL_PINNED_MESSAGE = 6,
|
||||
GUILD_MEMBER_JOIN = 7,
|
||||
USER_PREMIUM_GUILD_SUBSCRIPTION = 8,
|
||||
USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_1 = 9,
|
||||
USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_2 = 10,
|
||||
USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_3 = 11,
|
||||
CHANNEL_FOLLOW_ADD = 12,
|
||||
GUILD_DISCOVERY_DISQUALIFIED = 14,
|
||||
GUILD_DISCOVERY_REQUALIFIED = 15,
|
||||
REPLY = 19,
|
||||
APPLICATION_COMMAND = 20,
|
||||
}
|
||||
|
||||
@Entity("messages")
|
||||
export class Message extends BaseClass {
|
||||
@Column()
|
||||
id: string;
|
||||
|
||||
@Column()
|
||||
channel_id: string;
|
||||
|
||||
@JoinColumn({ name: "channel_id" })
|
||||
@ManyToOne(() => Channel, (channel: Channel) => channel.id)
|
||||
channel: Channel;
|
||||
|
||||
@Column()
|
||||
guild_id: string;
|
||||
|
||||
@JoinColumn({ name: "guild_id" })
|
||||
@ManyToOne(() => Guild, (guild: Guild) => guild.id)
|
||||
guild?: Guild;
|
||||
|
||||
@Column()
|
||||
author_id: string;
|
||||
|
||||
@JoinColumn({ name: "author_id" })
|
||||
@ManyToOne(() => User, (user: User) => user.id)
|
||||
author?: User;
|
||||
|
||||
@Column()
|
||||
member_id: string;
|
||||
|
||||
@JoinColumn({ name: "member_id" })
|
||||
@ManyToOne(() => Member, (member: Member) => member.id)
|
||||
member?: Member;
|
||||
|
||||
@Column()
|
||||
webhook_id: string;
|
||||
|
||||
@JoinColumn({ name: "webhook_id" })
|
||||
@ManyToOne(() => Webhook, (webhook: Webhook) => webhook.id)
|
||||
webhook?: Webhook;
|
||||
|
||||
@Column()
|
||||
application_id: string;
|
||||
|
||||
@JoinColumn({ name: "application_id" })
|
||||
@ManyToOne(() => Application, (application: Application) => application.id)
|
||||
application?: Application;
|
||||
|
||||
@Column()
|
||||
content?: string;
|
||||
|
||||
@Column()
|
||||
@CreateDateColumn()
|
||||
timestamp: Date;
|
||||
|
||||
@Column()
|
||||
@UpdateDateColumn()
|
||||
edited_timestamp?: Date;
|
||||
|
||||
@Column()
|
||||
tts?: boolean;
|
||||
|
||||
@Column()
|
||||
mention_everyone?: boolean;
|
||||
|
||||
@Column("simple-array")
|
||||
mention_user_ids: string[];
|
||||
|
||||
@JoinColumn({ name: "mention_user_ids" })
|
||||
@ManyToMany(() => User, (user: User) => user.id)
|
||||
mention_users: User[];
|
||||
|
||||
@Column("simple-array")
|
||||
mention_role_ids: string[];
|
||||
|
||||
@JoinColumn({ name: "mention_role_ids" })
|
||||
@ManyToMany(() => Role, (role: Role) => role.id)
|
||||
mention_roles: Role[];
|
||||
|
||||
@Column("simple-array")
|
||||
mention_channel_ids: string[];
|
||||
|
||||
@JoinColumn({ name: "mention_channel_ids" })
|
||||
@ManyToMany(() => Channel, (channel: Channel) => channel.id)
|
||||
mention_channels: Channel[];
|
||||
|
||||
@Column("simple-json")
|
||||
attachments: Attachment[];
|
||||
|
||||
@Column("simple-json")
|
||||
embeds: Embed[];
|
||||
|
||||
@Column("simple-json")
|
||||
reactions: Reaction[];
|
||||
|
||||
@Column({ type: "text" })
|
||||
nonce?: string | number;
|
||||
|
||||
@Column()
|
||||
pinned?: boolean;
|
||||
|
||||
@Column({ type: "simple-enum", enum: MessageType })
|
||||
type: MessageType;
|
||||
|
||||
@Column("simple-json")
|
||||
activity?: {
|
||||
type: number;
|
||||
party_id: string;
|
||||
};
|
||||
|
||||
@Column({ type: "bigint" })
|
||||
flags?: bigint;
|
||||
|
||||
@Column("simple-json")
|
||||
stickers?: any[];
|
||||
|
||||
@Column("simple-json")
|
||||
message_reference?: {
|
||||
message_id: string;
|
||||
channel_id?: string;
|
||||
guild_id?: string;
|
||||
};
|
||||
|
||||
@Column("simple-json")
|
||||
interaction?: {
|
||||
id: string;
|
||||
type: InteractionType;
|
||||
name: string;
|
||||
user_id: string; // the user who invoked the interaction
|
||||
// user: User; // TODO: autopopulate user
|
||||
};
|
||||
|
||||
@Column("simple-json")
|
||||
components: MessageComponent[];
|
||||
}
|
||||
|
||||
export interface MessageComponent {
|
||||
type: number;
|
||||
style?: number;
|
||||
label?: string;
|
||||
emoji?: PartialEmoji;
|
||||
custom_id?: string;
|
||||
url?: string;
|
||||
disabled?: boolean;
|
||||
components: MessageComponent[];
|
||||
}
|
||||
|
||||
export enum MessageComponentType {
|
||||
ActionRow = 1,
|
||||
Button = 2,
|
||||
}
|
||||
|
||||
export interface Attachment {
|
||||
id: string; // attachment id
|
||||
filename: string; // name of file attached
|
||||
size: number; // size of file in bytes
|
||||
url: string; // source url of file
|
||||
proxy_url: string; // a proxied url of file
|
||||
height?: number; // height of file (if image)
|
||||
width?: number; // width of file (if image)
|
||||
content_type?: string;
|
||||
}
|
||||
|
||||
export interface Embed {
|
||||
title?: string; //title of embed
|
||||
type?: EmbedType; // type of embed (always "rich" for webhook embeds)
|
||||
description?: string; // description of embed
|
||||
url?: string; // url of embed
|
||||
timestamp?: Date; // timestamp of embed content
|
||||
color?: number; // color code of the embed
|
||||
footer?: {
|
||||
text: string;
|
||||
icon_url?: string;
|
||||
proxy_icon_url?: string;
|
||||
}; // footer object footer information
|
||||
image?: EmbedImage; // image object image information
|
||||
thumbnail?: EmbedImage; // thumbnail object thumbnail information
|
||||
video?: EmbedImage; // video object video information
|
||||
provider?: {
|
||||
name?: string;
|
||||
url?: string;
|
||||
}; // provider object provider information
|
||||
author?: {
|
||||
name?: string;
|
||||
url?: string;
|
||||
icon_url?: string;
|
||||
proxy_icon_url?: string;
|
||||
}; // author object author information
|
||||
fields?: {
|
||||
name: string;
|
||||
value: string;
|
||||
inline?: boolean;
|
||||
}[];
|
||||
}
|
||||
|
||||
export enum EmbedType {
|
||||
rich = "rich",
|
||||
image = "image",
|
||||
video = "video",
|
||||
gifv = "gifv",
|
||||
article = "article",
|
||||
link = "link",
|
||||
}
|
||||
|
||||
export interface EmbedImage {
|
||||
url?: string;
|
||||
proxy_url?: string;
|
||||
height?: number;
|
||||
width?: number;
|
||||
}
|
||||
|
||||
export interface Reaction {
|
||||
count: number;
|
||||
//// not saved in the database // me: boolean; // whether the current user reacted using this emoji
|
||||
emoji: PartialEmoji;
|
||||
user_ids: string[];
|
||||
}
|
||||
|
||||
export interface PartialEmoji {
|
||||
id?: string;
|
||||
name: string;
|
||||
animated?: boolean;
|
||||
}
|
||||
|
||||
export interface AllowedMentions {
|
||||
parse?: ("users" | "roles" | "everyone")[];
|
||||
roles?: string[];
|
||||
users?: string[];
|
||||
replied_user?: boolean;
|
||||
}
|
25
util/src/entities/RateLimit.ts
Normal file
25
util/src/entities/RateLimit.ts
Normal file
@ -0,0 +1,25 @@
|
||||
import { Column, Entity, JoinColumn, ManyToOne } from "typeorm";
|
||||
import { BaseClass } from "./BaseClass";
|
||||
import { User } from "./User";
|
||||
|
||||
@Entity("rate_limits")
|
||||
export class RateLimit extends BaseClass {
|
||||
@Column()
|
||||
id: "global" | "error" | string; // channel_239842397 | guild_238927349823 | webhook_238923423498
|
||||
|
||||
@Column()
|
||||
user_id: string;
|
||||
|
||||
@JoinColumn({ name: "user_id" })
|
||||
@ManyToOne(() => User, (user) => user.id)
|
||||
user: User;
|
||||
|
||||
@Column()
|
||||
hits: number;
|
||||
|
||||
@Column()
|
||||
blocked: boolean;
|
||||
|
||||
@Column()
|
||||
expires_at: Date;
|
||||
}
|
35
util/src/entities/ReadState.ts
Normal file
35
util/src/entities/ReadState.ts
Normal file
@ -0,0 +1,35 @@
|
||||
import { Column, Entity, JoinColumn, ManyToOne } from "typeorm";
|
||||
import { BaseClass } from "./BaseClass";
|
||||
import { Channel } from "./Channel";
|
||||
import { Message } from "./Message";
|
||||
import { User } from "./User";
|
||||
|
||||
@Entity("read_states")
|
||||
export class ReadState extends BaseClass {
|
||||
@Column()
|
||||
channel_id: string;
|
||||
|
||||
@JoinColumn({ name: "channel_id" })
|
||||
@ManyToOne(() => Channel, (channel: Channel) => channel.id)
|
||||
channel: Channel;
|
||||
|
||||
@Column()
|
||||
user_id: string;
|
||||
|
||||
@JoinColumn({ name: "user_id" })
|
||||
@ManyToOne(() => User, (user: User) => user.id)
|
||||
user: User;
|
||||
|
||||
@JoinColumn({ name: "last_message_id" })
|
||||
@ManyToOne(() => Message, (message: Message) => message.id)
|
||||
last_message?: Message;
|
||||
|
||||
@Column()
|
||||
last_pin_timestamp?: Date;
|
||||
|
||||
@Column()
|
||||
mention_count: number;
|
||||
|
||||
@Column()
|
||||
manual: boolean;
|
||||
}
|
26
util/src/entities/Relationship.ts
Normal file
26
util/src/entities/Relationship.ts
Normal file
@ -0,0 +1,26 @@
|
||||
import { Column, Entity, JoinColumn, ManyToOne, OneToMany } from "typeorm";
|
||||
import { BaseClass } from "./BaseClass";
|
||||
import { User } from "./User";
|
||||
|
||||
export enum RelationshipType {
|
||||
outgoing = 4,
|
||||
incoming = 3,
|
||||
blocked = 2,
|
||||
friends = 1,
|
||||
}
|
||||
|
||||
@Entity("relationships")
|
||||
export class Relationship extends BaseClass {
|
||||
@Column()
|
||||
user_id: string;
|
||||
|
||||
@JoinColumn({ name: "user_id" })
|
||||
@ManyToOne(() => User, (user: User) => user.id)
|
||||
user: User;
|
||||
|
||||
@Column()
|
||||
nickname?: string;
|
||||
|
||||
@Column({ type: "simple-enum", enum: RelationshipType })
|
||||
type: RelationshipType;
|
||||
}
|
41
util/src/entities/Role.ts
Normal file
41
util/src/entities/Role.ts
Normal file
@ -0,0 +1,41 @@
|
||||
import { Column, Entity, JoinColumn, ManyToOne } from "typeorm";
|
||||
import { BaseClass } from "./BaseClass";
|
||||
import { Guild } from "./Guild";
|
||||
|
||||
@Entity("roles")
|
||||
export class Role extends BaseClass {
|
||||
@Column()
|
||||
guild_id: string;
|
||||
|
||||
@JoinColumn({ name: "guild_id" })
|
||||
@ManyToOne(() => Guild, (guild: Guild) => guild.id)
|
||||
guild: Guild;
|
||||
|
||||
@Column()
|
||||
color: number;
|
||||
|
||||
@Column()
|
||||
hoist: boolean;
|
||||
|
||||
@Column()
|
||||
managed: boolean;
|
||||
|
||||
@Column()
|
||||
mentionable: boolean;
|
||||
|
||||
@Column()
|
||||
name: string;
|
||||
|
||||
@Column({ type: "bigint" })
|
||||
permissions: bigint;
|
||||
|
||||
@Column()
|
||||
position: number;
|
||||
|
||||
@Column({ type: "simple-json" })
|
||||
tags?: {
|
||||
bot_id?: string;
|
||||
integration_id?: string;
|
||||
premium_subscriber?: boolean;
|
||||
};
|
||||
}
|
27
util/src/entities/Team.ts
Normal file
27
util/src/entities/Team.ts
Normal file
@ -0,0 +1,27 @@
|
||||
import { Column, Entity, JoinColumn, ManyToMany, ManyToOne } from "typeorm";
|
||||
import { BaseClass } from "./BaseClass";
|
||||
import { TeamMember } from "./TeamMember";
|
||||
import { User } from "./User";
|
||||
|
||||
@Entity("teams")
|
||||
export class Team extends BaseClass {
|
||||
@Column()
|
||||
icon?: string;
|
||||
|
||||
@Column("simple-array")
|
||||
member_ids: string[];
|
||||
|
||||
@JoinColumn({ name: "member_ids" })
|
||||
@ManyToMany(() => TeamMember, (member: TeamMember) => member.id)
|
||||
members: TeamMember[];
|
||||
|
||||
@Column()
|
||||
name: string;
|
||||
|
||||
@Column()
|
||||
owner_user_id: string;
|
||||
|
||||
@JoinColumn({ name: "owner_user_id" })
|
||||
@ManyToOne(() => User, (user: User) => user.id)
|
||||
owner_user: User;
|
||||
}
|
31
util/src/entities/TeamMember.ts
Normal file
31
util/src/entities/TeamMember.ts
Normal file
@ -0,0 +1,31 @@
|
||||
import { Column, Entity, JoinColumn, ManyToOne } from "typeorm";
|
||||
import { BaseClass } from "./BaseClass";
|
||||
import { User } from "./User";
|
||||
|
||||
export enum TeamMemberState {
|
||||
INVITED = 1,
|
||||
ACCEPTED = 2,
|
||||
}
|
||||
|
||||
@Entity("team_members")
|
||||
export class TeamMember extends BaseClass {
|
||||
@Column({ type: "simple-enum", enum: TeamMemberState })
|
||||
membership_state: TeamMemberState;
|
||||
|
||||
@Column("simple-array")
|
||||
permissions: string[];
|
||||
|
||||
@Column()
|
||||
team_id: string;
|
||||
|
||||
@JoinColumn({ name: "team_id" })
|
||||
@ManyToOne(() => require("./Team").Team, (team: import("./Team").Team) => team.id)
|
||||
team: import("./Team").Team;
|
||||
|
||||
@Column()
|
||||
user_id: string;
|
||||
|
||||
@JoinColumn({ name: "user_id" })
|
||||
@ManyToOne(() => User, (user: User) => user.id)
|
||||
user: User;
|
||||
}
|
33
util/src/entities/Template.ts
Normal file
33
util/src/entities/Template.ts
Normal file
@ -0,0 +1,33 @@
|
||||
import { Column, Entity, JoinColumn, ManyToOne } from "typeorm";
|
||||
import { BaseClass } from "./BaseClass";
|
||||
import { Guild } from "./Guild";
|
||||
import { User } from "./User";
|
||||
|
||||
@Entity("templates")
|
||||
export class Template extends BaseClass {
|
||||
@Column()
|
||||
code: string;
|
||||
|
||||
@Column()
|
||||
name: string;
|
||||
|
||||
@Column()
|
||||
description?: string;
|
||||
|
||||
@Column()
|
||||
usage_count?: number;
|
||||
|
||||
@JoinColumn({ name: "creator_id" })
|
||||
@ManyToOne(() => User, (user: User) => user.id)
|
||||
creator: User;
|
||||
|
||||
@Column()
|
||||
created_at: Date;
|
||||
|
||||
@Column()
|
||||
updated_at: Date;
|
||||
|
||||
@JoinColumn({ name: "source_guild_id" })
|
||||
@ManyToOne(() => Guild, (guild: Guild) => guild.id)
|
||||
source_guild: Guild;
|
||||
}
|
188
util/src/entities/User.ts
Normal file
188
util/src/entities/User.ts
Normal file
@ -0,0 +1,188 @@
|
||||
import { Column, Entity, JoinColumn, OneToMany, OneToOne } from "typeorm";
|
||||
import { BaseClass } from "./BaseClass";
|
||||
import { BitField } from "../util/BitField";
|
||||
import { Relationship } from "./Relationship";
|
||||
import { ConnectedAccount } from "./ConnectedAccount";
|
||||
|
||||
export const PublicUserProjection = {
|
||||
username: true,
|
||||
discriminator: true,
|
||||
id: true,
|
||||
public_flags: true,
|
||||
avatar: true,
|
||||
accent_color: true,
|
||||
banner: true,
|
||||
bio: true,
|
||||
bot: true,
|
||||
};
|
||||
|
||||
@Entity("users")
|
||||
export class User extends BaseClass {
|
||||
@Column()
|
||||
username: string; // username max length 32, min 2 (should be configurable)
|
||||
|
||||
@Column()
|
||||
discriminator: string; // #0001 4 digit long string from #0001 - #9999
|
||||
|
||||
@Column()
|
||||
avatar?: string; // hash of the user avatar
|
||||
|
||||
@Column()
|
||||
accent_color?: number; // banner color of user
|
||||
|
||||
@Column()
|
||||
banner?: string; // hash of the user banner
|
||||
|
||||
@Column()
|
||||
phone?: string; // phone number of the user
|
||||
|
||||
@Column()
|
||||
desktop: boolean; // if the user has desktop app installed
|
||||
|
||||
@Column()
|
||||
mobile: boolean; // if the user has mobile app installed
|
||||
|
||||
@Column()
|
||||
premium: boolean; // if user bought nitro
|
||||
|
||||
@Column()
|
||||
premium_type: number; // nitro level
|
||||
|
||||
@Column()
|
||||
bot: boolean; // if user is bot
|
||||
|
||||
@Column()
|
||||
bio: string; // short description of the user (max 190 chars -> should be configurable)
|
||||
|
||||
@Column()
|
||||
system: boolean; // shouldn't be used, the api sents this field type true, if the generated message comes from a system generated author
|
||||
|
||||
@Column()
|
||||
nsfw_allowed: boolean; // if the user is older than 18 (resp. Config)
|
||||
|
||||
@Column()
|
||||
mfa_enabled: boolean; // if multi factor authentication is enabled
|
||||
|
||||
@Column()
|
||||
created_at: Date; // registration date
|
||||
|
||||
@Column()
|
||||
verified: boolean; // if the user is offically verified
|
||||
|
||||
@Column()
|
||||
disabled: boolean; // if the account is disabled
|
||||
|
||||
@Column()
|
||||
deleted: boolean; // if the user was deleted
|
||||
|
||||
@Column()
|
||||
email?: string; // email of the user
|
||||
|
||||
@Column({ type: "bigint" })
|
||||
flags: bigint; // UserFlags
|
||||
|
||||
@Column({ type: "bigint" })
|
||||
public_flags: bigint;
|
||||
|
||||
@Column("simple-array") // string in simple-array must not contain commas
|
||||
guilds: string[]; // array of guild ids the user is part of
|
||||
|
||||
@Column("simple-array") // string in simple-array must not contain commas
|
||||
relationship_ids: string[]; // array of guild ids the user is part of
|
||||
|
||||
@JoinColumn({ name: "relationship_ids" })
|
||||
@OneToMany(() => User, (user: User) => user.id)
|
||||
relationships: Relationship[];
|
||||
|
||||
@Column("simple-array") // string in simple-array must not contain commas
|
||||
connected_account_ids: string[]; // array of guild ids the user is part of
|
||||
|
||||
@JoinColumn({ name: "connected_account_ids" })
|
||||
@OneToMany(() => ConnectedAccount, (account: ConnectedAccount) => account.id)
|
||||
connected_accounts: ConnectedAccount[];
|
||||
|
||||
@Column({ type: "simple-json", select: false })
|
||||
user_data: {
|
||||
valid_tokens_since: Date; // all tokens with a previous issue date are invalid
|
||||
hash: string; // hash of the password, salt is saved in password (bcrypt)
|
||||
fingerprints: string[]; // array of fingerprints -> used to prevent multiple accounts
|
||||
};
|
||||
|
||||
@Column("simple-json")
|
||||
settings: UserSettings;
|
||||
}
|
||||
|
||||
export interface UserSettings {
|
||||
afk_timeout: number;
|
||||
allow_accessibility_detection: boolean;
|
||||
animate_emoji: boolean;
|
||||
animate_stickers: number;
|
||||
contact_sync_enabled: boolean;
|
||||
convert_emoticons: boolean;
|
||||
custom_status: {
|
||||
emoji_id?: string;
|
||||
emoji_name?: string;
|
||||
expires_at?: number;
|
||||
text?: string;
|
||||
};
|
||||
default_guilds_restricted: boolean;
|
||||
detect_platform_accounts: boolean;
|
||||
developer_mode: boolean;
|
||||
disable_games_tab: boolean;
|
||||
enable_tts_command: boolean;
|
||||
explicit_content_filter: number;
|
||||
friend_source_flags: { all: boolean };
|
||||
gateway_connected: boolean;
|
||||
gif_auto_play: boolean;
|
||||
// every top guild is displayed as a "folder"
|
||||
guild_folders: {
|
||||
color: number;
|
||||
guild_ids: string[];
|
||||
id: number;
|
||||
name: string;
|
||||
}[];
|
||||
guild_positions: string[]; // guild ids ordered by position
|
||||
inline_attachment_media: boolean;
|
||||
inline_embed_media: boolean;
|
||||
locale: string; // en_US
|
||||
message_display_compact: boolean;
|
||||
native_phone_integration_enabled: boolean;
|
||||
render_embeds: boolean;
|
||||
render_reactions: boolean;
|
||||
restricted_guilds: string[];
|
||||
show_current_game: boolean;
|
||||
status: "online" | "offline" | "dnd" | "idle";
|
||||
stream_notifications_enabled: boolean;
|
||||
theme: "dark" | "white"; // dark
|
||||
timezone_offset: number; // e.g -60
|
||||
}
|
||||
|
||||
// Private user data that should never get sent to the client
|
||||
export interface PublicUser {
|
||||
id: string;
|
||||
discriminator: string;
|
||||
username: string;
|
||||
avatar?: string;
|
||||
accent_color?: number;
|
||||
banner?: string;
|
||||
public_flags: bigint;
|
||||
bot: boolean;
|
||||
}
|
||||
|
||||
export class UserFlags extends BitField {
|
||||
static FLAGS = {
|
||||
DISCORD_EMPLOYEE: BigInt(1) << BigInt(0),
|
||||
PARTNERED_SERVER_OWNER: BigInt(1) << BigInt(1),
|
||||
HYPESQUAD_EVENTS: BigInt(1) << BigInt(2),
|
||||
BUGHUNTER_LEVEL_1: BigInt(1) << BigInt(3),
|
||||
HOUSE_BRAVERY: BigInt(1) << BigInt(6),
|
||||
HOUSE_BRILLIANCE: BigInt(1) << BigInt(7),
|
||||
HOUSE_BALANCE: BigInt(1) << BigInt(8),
|
||||
EARLY_SUPPORTER: BigInt(1) << BigInt(9),
|
||||
TEAM_USER: BigInt(1) << BigInt(10),
|
||||
SYSTEM: BigInt(1) << BigInt(12),
|
||||
BUGHUNTER_LEVEL_2: BigInt(1) << BigInt(14),
|
||||
VERIFIED_BOT: BigInt(1) << BigInt(16),
|
||||
EARLY_VERIFIED_BOT_DEVELOPER: BigInt(1) << BigInt(17),
|
||||
};
|
||||
}
|
44
util/src/entities/VoiceState.ts
Normal file
44
util/src/entities/VoiceState.ts
Normal file
@ -0,0 +1,44 @@
|
||||
import { Column, Entity, JoinColumn, ManyToOne, OneToOne } from "typeorm";
|
||||
import { BaseClass } from "./BaseClass";
|
||||
import { Channel } from "./Channel";
|
||||
import { Guild } from "./Guild";
|
||||
import { User } from "./User";
|
||||
|
||||
@Entity("voice_states")
|
||||
export class VoiceState extends BaseClass {
|
||||
@JoinColumn({ name: "guild_id" })
|
||||
@ManyToOne(() => Guild, (guild: Guild) => guild.id)
|
||||
guild?: Guild;
|
||||
|
||||
@JoinColumn({ name: "channel_id" })
|
||||
@ManyToOne(() => Channel, (channel: Channel) => channel.id)
|
||||
channel: Channel;
|
||||
|
||||
@JoinColumn({ name: "user_id" })
|
||||
@ManyToOne(() => User, (user: User) => user.id)
|
||||
user: User;
|
||||
|
||||
@Column()
|
||||
session_id: string;
|
||||
|
||||
@Column()
|
||||
deaf: boolean;
|
||||
|
||||
@Column()
|
||||
mute: boolean;
|
||||
|
||||
@Column()
|
||||
self_deaf: boolean;
|
||||
|
||||
@Column()
|
||||
self_mute: boolean;
|
||||
|
||||
@Column()
|
||||
self_stream?: boolean;
|
||||
|
||||
@Column()
|
||||
self_video: boolean;
|
||||
|
||||
@Column()
|
||||
suppress: boolean; // whether this user is muted by the current user
|
||||
}
|
40
util/src/entities/Webhook.ts
Normal file
40
util/src/entities/Webhook.ts
Normal file
@ -0,0 +1,40 @@
|
||||
import { Column, Entity, JoinColumn } from "typeorm";
|
||||
import { BaseClass } from "./BaseClass";
|
||||
|
||||
export enum WebhookType {
|
||||
Incoming = 1,
|
||||
ChannelFollower = 2,
|
||||
}
|
||||
|
||||
@Entity("webhooks")
|
||||
export class Webhook extends BaseClass {
|
||||
@Column()
|
||||
id: string;
|
||||
|
||||
@Column({ type: "simple-enum", enum: WebhookType })
|
||||
type: WebhookType;
|
||||
|
||||
@Column()
|
||||
name?: string;
|
||||
|
||||
@Column()
|
||||
avatar?: string;
|
||||
|
||||
@Column()
|
||||
token?: string;
|
||||
|
||||
@JoinColumn()
|
||||
guild?: string;
|
||||
|
||||
@JoinColumn()
|
||||
channel: string;
|
||||
|
||||
@JoinColumn()
|
||||
application?: string;
|
||||
|
||||
@JoinColumn()
|
||||
user?: string;
|
||||
|
||||
@JoinColumn()
|
||||
source_guild: string;
|
||||
}
|
21
util/src/entities/index.ts
Normal file
21
util/src/entities/index.ts
Normal file
@ -0,0 +1,21 @@
|
||||
export * from "./Application";
|
||||
export * from "./AuditLog";
|
||||
export * from "./Ban";
|
||||
export * from "./BaseClass";
|
||||
export * from "./Channel";
|
||||
export * from "./ConnectedAccount";
|
||||
export * from "./Emoji";
|
||||
export * from "./Guild";
|
||||
export * from "./Invite";
|
||||
export * from "./Member";
|
||||
export * from "./Message";
|
||||
export * from "./RateLimit";
|
||||
export * from "./ReadState";
|
||||
export * from "./Relationship";
|
||||
export * from "./Role";
|
||||
export * from "./Team";
|
||||
export * from "./TeamMember";
|
||||
export * from "./Template";
|
||||
export * from "./User";
|
||||
export * from "./VoiceState";
|
||||
export * from "./Webhook";
|
19389
util/src/entities/schema.json
Normal file
19389
util/src/entities/schema.json
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user