diff --git a/src/api/routes/channels/#channel_id/invites.ts b/src/api/routes/channels/#channel_id/invites.ts
index f608cca2..b02f65d3 100644
--- a/src/api/routes/channels/#channel_id/invites.ts
+++ b/src/api/routes/channels/#channel_id/invites.ts
@@ -25,10 +25,10 @@ import {
PublicInviteRelation,
User,
emitEvent,
+ isTextChannel,
} from "@spacebar/util";
import { Request, Response, Router } from "express";
import { HTTPError } from "lambert-server";
-import { isTextChannel } from "./messages";
const router: Router = Router();
diff --git a/src/api/routes/channels/#channel_id/messages/index.ts b/src/api/routes/channels/#channel_id/messages/index.ts
index 811d2b4c..f031fa75 100644
--- a/src/api/routes/channels/#channel_id/messages/index.ts
+++ b/src/api/routes/channels/#channel_id/messages/index.ts
@@ -35,6 +35,7 @@ import {
User,
emitEvent,
getPermission,
+ isTextChannel,
uploadFile,
} from "@spacebar/util";
import { Request, Response, Router } from "express";
@@ -45,32 +46,6 @@ import { URL } from "url";
const router: Router = Router();
-export default router;
-
-export function isTextChannel(type: ChannelType): boolean {
- switch (type) {
- case ChannelType.GUILD_STORE:
- case ChannelType.GUILD_VOICE:
- case ChannelType.GUILD_STAGE_VOICE:
- case ChannelType.GUILD_CATEGORY:
- case ChannelType.GUILD_FORUM:
- case ChannelType.DIRECTORY:
- throw new HTTPError("not a text channel", 400);
- case ChannelType.DM:
- case ChannelType.GROUP_DM:
- case ChannelType.GUILD_NEWS:
- case ChannelType.GUILD_NEWS_THREAD:
- case ChannelType.GUILD_PUBLIC_THREAD:
- case ChannelType.GUILD_PRIVATE_THREAD:
- case ChannelType.GUILD_TEXT:
- case ChannelType.ENCRYPTED:
- case ChannelType.ENCRYPTED_THREAD:
- return true;
- default:
- throw new HTTPError("unimplemented", 400);
- }
-}
-
// https://discord.com/developers/docs/resources/channel#create-message
// get messages
router.get(
@@ -407,3 +382,5 @@ router.post(
return res.json(message);
},
);
+
+export default router;
diff --git a/src/api/routes/channels/#channel_id/purge.ts b/src/api/routes/channels/#channel_id/purge.ts
index cbd46bd0..012fec1c 100644
--- a/src/api/routes/channels/#channel_id/purge.ts
+++ b/src/api/routes/channels/#channel_id/purge.ts
@@ -25,11 +25,11 @@ import {
emitEvent,
getPermission,
getRights,
+ isTextChannel,
} from "@spacebar/util";
import { Request, Response, Router } from "express";
import { HTTPError } from "lambert-server";
import { Between, FindManyOptions, FindOperator, Not } from "typeorm";
-import { isTextChannel } from "./messages";
const router: Router = Router();
diff --git a/src/api/routes/channels/#channel_id/webhooks.ts b/src/api/routes/channels/#channel_id/webhooks.ts
index 6b81298f..d54756a1 100644
--- a/src/api/routes/channels/#channel_id/webhooks.ts
+++ b/src/api/routes/channels/#channel_id/webhooks.ts
@@ -27,11 +27,11 @@ import {
WebhookType,
handleFile,
trimSpecial,
+ isTextChannel,
} from "@spacebar/util";
import crypto from "crypto";
import { Request, Response, Router } from "express";
import { HTTPError } from "lambert-server";
-import { isTextChannel } from "./messages/index";
const router: Router = Router();
diff --git a/src/api/routes/gifs/search.ts b/src/api/routes/gifs/search.ts
index b51bba37..f125a463 100644
--- a/src/api/routes/gifs/search.ts
+++ b/src/api/routes/gifs/search.ts
@@ -17,11 +17,10 @@
*/
import { route } from "@spacebar/api";
-import { TenorMediaTypes } from "@spacebar/util";
+import { TenorMediaTypes, getGifApiKey, parseGifResult } from "@spacebar/util";
import { Request, Response, Router } from "express";
import fetch from "node-fetch";
import ProxyAgent from "proxy-agent";
-import { getGifApiKey, parseGifResult } from "./trending";
const router = Router();
diff --git a/src/api/routes/gifs/trending-gifs.ts b/src/api/routes/gifs/trending-gifs.ts
index 899250cf..d6fa89ac 100644
--- a/src/api/routes/gifs/trending-gifs.ts
+++ b/src/api/routes/gifs/trending-gifs.ts
@@ -17,11 +17,10 @@
*/
import { route } from "@spacebar/api";
-import { TenorMediaTypes } from "@spacebar/util";
+import { TenorMediaTypes, getGifApiKey, parseGifResult } from "@spacebar/util";
import { Request, Response, Router } from "express";
import fetch from "node-fetch";
import ProxyAgent from "proxy-agent";
-import { getGifApiKey, parseGifResult } from "./trending";
const router = Router();
diff --git a/src/api/routes/gifs/trending.ts b/src/api/routes/gifs/trending.ts
index 3c2ab6ab..e3d6e974 100644
--- a/src/api/routes/gifs/trending.ts
+++ b/src/api/routes/gifs/trending.ts
@@ -18,40 +18,17 @@
import { route } from "@spacebar/api";
import {
- Config,
TenorCategoriesResults,
- TenorGif,
TenorTrendingResults,
+ getGifApiKey,
+ parseGifResult,
} from "@spacebar/util";
import { Request, Response, Router } from "express";
-import { HTTPError } from "lambert-server";
import fetch from "node-fetch";
import ProxyAgent from "proxy-agent";
const router = Router();
-export function parseGifResult(result: TenorGif) {
- return {
- id: result.id,
- title: result.title,
- url: result.itemurl,
- src: result.media[0].mp4.url,
- gif_src: result.media[0].gif.url,
- width: result.media[0].mp4.dims[0],
- height: result.media[0].mp4.dims[1],
- preview: result.media[0].mp4.preview,
- };
-}
-
-export function getGifApiKey() {
- const { enabled, provider, apiKey } = Config.get().gif;
- if (!enabled) throw new HTTPError(`Gifs are disabled`);
- if (provider !== "tenor" || !apiKey)
- throw new HTTPError(`${provider} gif provider not supported`);
-
- return apiKey;
-}
-
router.get(
"/",
route({
diff --git a/src/api/routes/guilds/#guild_id/prune.ts b/src/api/routes/guilds/#guild_id/prune.ts
index 92ea91fc..2c77340d 100644
--- a/src/api/routes/guilds/#guild_id/prune.ts
+++ b/src/api/routes/guilds/#guild_id/prune.ts
@@ -23,7 +23,7 @@ import { IsNull, LessThan } from "typeorm";
const router = Router();
//Returns all inactive members, respecting role hierarchy
-export const inactiveMembers = async (
+const inactiveMembers = async (
guild_id: string,
user_id: string,
days: number,
diff --git a/src/api/routes/guilds/#guild_id/stickers.ts b/src/api/routes/guilds/#guild_id/stickers.ts
index 2da9a21e..88f9a40e 100644
--- a/src/api/routes/guilds/#guild_id/stickers.ts
+++ b/src/api/routes/guilds/#guild_id/stickers.ts
@@ -105,7 +105,7 @@ router.post(
},
);
-export function getStickerFormat(mime_type: string) {
+function getStickerFormat(mime_type: string) {
switch (mime_type) {
case "image/apng":
return StickerFormatType.APNG;
diff --git a/src/util/entities/Channel.ts b/src/util/entities/Channel.ts
index 9ce04848..e23d93db 100644
--- a/src/util/entities/Channel.ts
+++ b/src/util/entities/Channel.ts
@@ -482,3 +482,27 @@ export enum ChannelPermissionOverwriteType {
member = 1,
group = 2,
}
+
+export function isTextChannel(type: ChannelType): boolean {
+ switch (type) {
+ case ChannelType.GUILD_STORE:
+ case ChannelType.GUILD_VOICE:
+ case ChannelType.GUILD_STAGE_VOICE:
+ case ChannelType.GUILD_CATEGORY:
+ case ChannelType.GUILD_FORUM:
+ case ChannelType.DIRECTORY:
+ throw new HTTPError("not a text channel", 400);
+ case ChannelType.DM:
+ case ChannelType.GROUP_DM:
+ case ChannelType.GUILD_NEWS:
+ case ChannelType.GUILD_NEWS_THREAD:
+ case ChannelType.GUILD_PUBLIC_THREAD:
+ case ChannelType.GUILD_PRIVATE_THREAD:
+ case ChannelType.GUILD_TEXT:
+ case ChannelType.ENCRYPTED:
+ case ChannelType.ENCRYPTED_THREAD:
+ return true;
+ default:
+ throw new HTTPError("unimplemented", 400);
+ }
+}
diff --git a/src/util/util/Gifs.ts b/src/util/util/Gifs.ts
new file mode 100644
index 00000000..a5a5e64c
--- /dev/null
+++ b/src/util/util/Gifs.ts
@@ -0,0 +1,25 @@
+import { HTTPError } from "lambert-server";
+import { Config } from "./Config";
+import { TenorGif } from "..";
+
+export function parseGifResult(result: TenorGif) {
+ return {
+ id: result.id,
+ title: result.title,
+ url: result.itemurl,
+ src: result.media[0].mp4.url,
+ gif_src: result.media[0].gif.url,
+ width: result.media[0].mp4.dims[0],
+ height: result.media[0].mp4.dims[1],
+ preview: result.media[0].mp4.preview,
+ };
+}
+
+export function getGifApiKey() {
+ const { enabled, provider, apiKey } = Config.get().gif;
+ if (!enabled) throw new HTTPError(`Gifs are disabled`);
+ if (provider !== "tenor" || !apiKey)
+ throw new HTTPError(`${provider} gif provider not supported`);
+
+ return apiKey;
+}
diff --git a/src/util/util/index.ts b/src/util/util/index.ts
index 838239b7..3a98be15 100644
--- a/src/util/util/index.ts
+++ b/src/util/util/index.ts
@@ -41,3 +41,4 @@ export * from "./String";
export * from "./Token";
export * from "./TraverseDirectory";
export * from "./WebAuthn";
+export * from "./Gifs";
|