summary refs log tree commit diff
path: root/src/util
diff options
context:
space:
mode:
authorMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2023-04-16 01:51:52 +1000
committerMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2023-04-16 01:51:52 +1000
commitb438f2b071dbaa82371016168ab843f24be5063e (patch)
treeeea50564f94b6992089ce097455404d89cd0ba56 /src/util
parentgenerated files (diff)
downloadserver-b438f2b071dbaa82371016168ab843f24be5063e.tar.xz
Rewrite getRouteDescriptions, fix message route not appearing in openapi spec
Diffstat (limited to 'src/util')
-rw-r--r--src/util/entities/Channel.ts24
-rw-r--r--src/util/util/Gifs.ts25
-rw-r--r--src/util/util/index.ts1
3 files changed, 50 insertions, 0 deletions
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";