rename @fosscord/server-util to -> @fosscord/util

This commit is contained in:
Flam3rboy
2021-08-13 12:59:59 +02:00
parent 0802d5e6a8
commit 90d5307a56
66 changed files with 154 additions and 165 deletions
+4 -4
View File
@@ -2,18 +2,18 @@ import {
ChannelCreateEvent,
ChannelModel,
ChannelType,
emitEvent,
getPermission,
GuildModel,
Snowflake,
TextChannel,
toObject,
VoiceChannel
} from "@fosscord/server-util";
} from "@fosscord/util";
import { HTTPError } from "lambert-server";
import { emitEvent } from "./Event";
// TODO: DM channel
export async function createChannel(channel: Partial<TextChannel | VoiceChannel>, user_id: string = "0") {
// Always check if user has permission first
const permissions = await getPermission(user_id, channel.guild_id);
permissions.hasThrow("MANAGE_CHANNELS");
@@ -50,7 +50,7 @@ export async function createChannel(channel: Partial<TextChannel | VoiceChannel>
recipient_ids: null
}).save();
await emitEvent({ event: "CHANNEL_CREATE", data: channel, guild_id: channel.guild_id } as ChannelCreateEvent);
await emitEvent({ event: "CHANNEL_CREATE", data: toObject(channel), guild_id: channel.guild_id } as ChannelCreateEvent);
return channel;
}
+2 -2
View File
@@ -1,7 +1,7 @@
// @ts-nocheck
import Ajv, { JSONSchemaType } from "ajv";
import { getConfigPathForFile } from "@fosscord/server-util/dist/util/Config";
import { Config } from "@fosscord/server-util";
import { getConfigPathForFile } from "@fosscord/util/dist/util/Config";
import { Config } from "@fosscord/util";
export interface RateLimitOptions {
count: number;
-26
View File
@@ -1,26 +0,0 @@
import { Config, Event, EventModel, RabbitMQ } from "@fosscord/server-util";
export async function emitEvent(payload: Omit<Event, "created_at">) {
if (RabbitMQ.connection) {
const id = (payload.channel_id || payload.user_id || payload.guild_id) as string;
if (!id) console.error("event doesn't contain any id", payload);
const data = typeof payload.data === "object" ? JSON.stringify(payload.data) : payload.data; // use rabbitmq for event transmission
await RabbitMQ.channel?.assertExchange(id, "fanout", { durable: false });
// assertQueue isn't needed, because a queue will automatically created if it doesn't exist
const successful = RabbitMQ.channel?.publish(id, "", Buffer.from(`${data}`), { type: payload.event });
if (!successful) throw new Error("failed to send event");
} else {
// use mongodb for event transmission
// TODO: use event emitter for local server bundle
const obj = {
created_at: new Date(), // in seconds
...payload
};
// TODO: bigint isn't working
return await new EventModel(obj).save();
}
}
export async function emitAuditLog(payload: any) {}
+4 -3
View File
@@ -11,11 +11,12 @@ import {
toObject,
UserModel,
GuildDocument,
Config
} from "@fosscord/server-util";
Config,
emitEvent
} from "@fosscord/util";
import { HTTPError } from "lambert-server";
import { emitEvent } from "./Event";
import { getPublicUser } from "./User";
export const PublicMemberProjection = {
+8 -8
View File
@@ -1,14 +1,14 @@
import { ChannelModel, Embed, Message, MessageCreateEvent, MessageUpdateEvent } from "@fosscord/server-util";
import { Snowflake } from "@fosscord/server-util";
import { MessageModel } from "@fosscord/server-util";
import { PublicMemberProjection } from "@fosscord/server-util";
import { toObject } from "@fosscord/server-util";
import { getPermission } from "@fosscord/server-util";
import { ChannelModel, Embed, emitEvent, Message, MessageCreateEvent, MessageUpdateEvent } from "@fosscord/util";
import { Snowflake } from "@fosscord/util";
import { MessageModel } from "@fosscord/util";
import { PublicMemberProjection } from "@fosscord/util";
import { toObject } from "@fosscord/util";
import { getPermission } from "@fosscord/util";
import { HTTPError } from "lambert-server";
import fetch from "node-fetch";
import cheerio from "cheerio";
import { emitEvent } from "./Event";
import { MessageType } from "@fosscord/server-util/dist/util/Constants";
import { MessageType } from "@fosscord/util/dist/util/Constants";
// TODO: check webhook, application, system author
const LINK_REGEX = /https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)/g;
+1 -1
View File
@@ -1,4 +1,4 @@
import { toObject, UserModel, PublicUserProjection } from "@fosscord/server-util";
import { toObject, UserModel, PublicUserProjection } from "@fosscord/util";
import { HTTPError } from "lambert-server";
export { PublicUserProjection };
+1 -1
View File
@@ -1,4 +1,4 @@
import { Config } from "@fosscord/server-util";
import { Config } from "@fosscord/util";
import FormData from "form-data";
import { HTTPError } from "lambert-server";
import fetch from "node-fetch";
+1 -1
View File
@@ -1,4 +1,4 @@
import { Config } from "@fosscord/server-util";
import { Config } from "@fosscord/util";
import { Request } from "express";
// use ipdata package instead of simple fetch because of integrated caching
import fetch from "node-fetch";
+1 -1
View File
@@ -1,4 +1,4 @@
import { Config } from "@fosscord/server-util";
import { Config } from "@fosscord/util";
import "missing-native-js-functions";
const reNUMBER = /[0-9]/g;