mirror of
https://github.com/spacebarchat/server.git
synced 2026-10-22 11:52:34 +00:00
✨ AuditLog
This commit is contained in:
1 parent
ce01628650
commit
514afaca69
23 files changed
+136
-58
No files matched your search
@@ -7,7 +7,7 @@ export interface AuditLogResponse {
|
||||
webhooks: []; // TODO:
|
||||
users: PublicUser[];
|
||||
audit_log_entries: AuditLogEntries[];
|
||||
integrations: [];
|
||||
integrations: []; // TODO:
|
||||
}
|
||||
|
||||
export interface AuditLogEntries {
|
||||
|
||||
+1
-1
@@ -49,6 +49,7 @@ export interface Guild {
|
||||
}
|
||||
|
||||
export const GuildSchema = new Schema({
|
||||
id: { type: Types.Long, required: true },
|
||||
afk_channel_id: Types.Long,
|
||||
afk_timeout: Number,
|
||||
application_id: Types.Long,
|
||||
@@ -59,7 +60,6 @@ export const GuildSchema = new Schema({
|
||||
explicit_content_filter: Number,
|
||||
features: { type: [String], default: [] },
|
||||
icon: String,
|
||||
id: { type: Types.Long, required: true },
|
||||
large: Boolean,
|
||||
max_members: { type: Number, default: 100000 },
|
||||
max_presences: Number,
|
||||
|
||||
@@ -75,7 +75,7 @@ export const MemberSchema = new Schema({
|
||||
},
|
||||
});
|
||||
|
||||
exports.MemberSchema.virtual("user", {
|
||||
MemberSchema.virtual("user", {
|
||||
ref: UserModel,
|
||||
localField: "id",
|
||||
foreignField: "id",
|
||||
|
||||
+56
-21
@@ -1,10 +1,13 @@
|
||||
import { Schema, model, Types, Document } from "mongoose";
|
||||
import { ChannelType } from "./Channel";
|
||||
import { Schema, Types, Document } from "mongoose";
|
||||
import db from "../util/Database";
|
||||
import { UserModel } from "./User";
|
||||
import { MemberModel } from "./Member";
|
||||
import { RoleModel } from "./Role";
|
||||
|
||||
export interface Message extends Document {
|
||||
id: bigint;
|
||||
channel_id: bigint;
|
||||
guild_id?: bigint;
|
||||
author_id?: bigint;
|
||||
webhook_id?: bigint;
|
||||
application_id: bigint;
|
||||
@@ -13,14 +16,9 @@ export interface Message extends Document {
|
||||
edited_timestamp: number;
|
||||
tts: boolean;
|
||||
mention_everyone: boolean;
|
||||
mentions: bigint[];
|
||||
mention_roles: bigint[];
|
||||
mention_channels?: {
|
||||
id: bigint;
|
||||
guild_id: bigint;
|
||||
type: ChannelType;
|
||||
name: string;
|
||||
}[];
|
||||
mention_user_ids: bigint[];
|
||||
mention_role_ids: bigint[];
|
||||
mention_channels_ids: bigint[];
|
||||
attachments: Attachment[];
|
||||
embeds: Embed[];
|
||||
reactions?: Reaction[];
|
||||
@@ -154,7 +152,7 @@ const Reaction = {
|
||||
},
|
||||
};
|
||||
|
||||
const Embed = {
|
||||
export const Embed = {
|
||||
title: String, //title of embed
|
||||
type: String, // type of embed (always "rich" for webhook embeds)
|
||||
description: String, // description of embed
|
||||
@@ -193,22 +191,16 @@ export const MessageSchema = new Schema({
|
||||
channel_id: Types.Long,
|
||||
author_id: Types.Long,
|
||||
webhook_id: Types.Long,
|
||||
guild_id: Types.Long,
|
||||
application_id: Types.Long,
|
||||
content: String,
|
||||
timestamp: Number,
|
||||
edited_timestamp: Number,
|
||||
tts: Boolean,
|
||||
mention_everyone: Boolean,
|
||||
mentions: [Types.Long],
|
||||
mention_roles: [Types.Long],
|
||||
mention_channels: [
|
||||
{
|
||||
id: Types.Long,
|
||||
guild_id: Types.Long,
|
||||
type: { type: Number },
|
||||
name: String,
|
||||
},
|
||||
],
|
||||
mention_user_ids: [Types.Long],
|
||||
mention_role_ids: [Types.Long],
|
||||
mention_channel_ids: [Types.Long],
|
||||
attachments: [Attachment],
|
||||
embeds: [Embed],
|
||||
reactions: [Reaction],
|
||||
@@ -228,5 +220,48 @@ export const MessageSchema = new Schema({
|
||||
},
|
||||
});
|
||||
|
||||
MessageSchema.virtual("author", {
|
||||
ref: UserModel,
|
||||
localField: "author_id",
|
||||
foreignField: "id",
|
||||
justOne: true,
|
||||
});
|
||||
|
||||
MessageSchema.virtual("member", {
|
||||
ref: MemberModel,
|
||||
localField: "author_id",
|
||||
foreignField: "id",
|
||||
justOne: true,
|
||||
});
|
||||
|
||||
MessageSchema.virtual("mentions", {
|
||||
ref: UserModel,
|
||||
localField: "mention_user_ids",
|
||||
foreignField: "id",
|
||||
justOne: true,
|
||||
});
|
||||
|
||||
MessageSchema.virtual("mention_roles", {
|
||||
ref: RoleModel,
|
||||
localField: "mention_role_ids",
|
||||
foreignField: "id",
|
||||
justOne: true,
|
||||
});
|
||||
|
||||
MessageSchema.virtual("mention_channels", {
|
||||
ref: RoleModel,
|
||||
localField: "mention_role_ids",
|
||||
foreignField: "id",
|
||||
justOne: true,
|
||||
});
|
||||
|
||||
// TODO: missing Application Model
|
||||
// MessageSchema.virtual("application", {
|
||||
// ref: Application,
|
||||
// localField: "mention_role_ids",
|
||||
// foreignField: "id",
|
||||
// justOne: true,
|
||||
// });
|
||||
|
||||
// @ts-ignore
|
||||
export const MessageModel = db.model<Message>("Message", MessageSchema, "messages");
|
||||
+3
-1
@@ -21,7 +21,7 @@ export interface User {
|
||||
mfa_enabled: boolean; // if multi factor authentication is enabled
|
||||
created_at: number; // registration date
|
||||
verified: boolean; // if the user is offically verified
|
||||
email: string; // email of the user
|
||||
email?: string; // email of the user
|
||||
flags: bigint; // UserFlags
|
||||
public_flags: bigint;
|
||||
hash: string; // hash of the password, salt is saved in password (bcrypt)
|
||||
@@ -88,6 +88,7 @@ export interface UserSettings {
|
||||
enable_tts_command: boolean;
|
||||
explicit_content_filter: number;
|
||||
friend_source_flags: { all: boolean };
|
||||
gateway_connected: boolean;
|
||||
gif_auto_play: boolean;
|
||||
guild_folders: // every top guild is displayed as a "folder"
|
||||
{
|
||||
@@ -155,6 +156,7 @@ export const UserSchema = new Schema({
|
||||
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: [
|
||||
|
||||
@@ -137,7 +137,7 @@ export class BitField {
|
||||
const resolve = this.constructor?.resolve || this.resolve;
|
||||
return bit.map((p) => resolve(p)).reduce((prev, p) => BigInt(prev) | BigInt(p), 0n);
|
||||
}
|
||||
if (typeof bit === "string" && typeof FLAGS[bit] !== "undefined") return this.FLAGS[bit];
|
||||
if (typeof bit === "string" && typeof FLAGS[bit] !== "undefined") return FLAGS[bit];
|
||||
throw new RangeError("BITFIELD_INVALID: " + bit);
|
||||
}
|
||||
}
|
||||
@@ -33,7 +33,7 @@ class LongSchema extends mongoose.SchemaType {
|
||||
cast(val: any, scope?: any, init?: any, type?: string) {
|
||||
if (null === val) return val;
|
||||
if ("" === val) return null;
|
||||
if (typeof val === "bigint" && type === "query") {
|
||||
if (typeof val === "bigint") {
|
||||
return mongoose.mongo.Long.fromString(val.toString());
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import { ChannelDocument, ChannelModel } from "../models/Channel";
|
||||
import { ChannelPermissionOverwrite } from "../models/Channel";
|
||||
import { Role, RoleModel } from "../models/Role";
|
||||
import { BitField } from "./BitField";
|
||||
import { GuildDocument } from "../models/Guild";
|
||||
import { GuildDocument, GuildModel } from "../models/Guild";
|
||||
|
||||
export type PermissionResolvable = bigint | number | Permissions | PermissionResolvable[] | PermissionString;
|
||||
|
||||
@@ -151,6 +151,10 @@ export async function getPermission(
|
||||
) {
|
||||
var { channel, member } = cache || {};
|
||||
|
||||
const guild = await GuildModel.findOne({ id: guild_id }, { owner_id: true }).exec();
|
||||
if (!guild) throw new Error("Guild not found");
|
||||
if (guild.owner_id === user_id) return new Permissions(Permissions.FLAGS.ADMINISTRATOR);
|
||||
|
||||
member = await MemberModel.findOne({ guild_id, id: user_id }, "roles").exec();
|
||||
if (!member) throw new Error("Member not found");
|
||||
|
||||
|
||||
Reference in new issue
Block a user