mirror of
https://github.com/spacebarchat/server.git
synced 2024-11-25 19:52:36 +01:00
Move isTextChannel to channel
Signed-off-by: TheArcaneBrony <myrainbowdash949@gmail.com>
This commit is contained in:
parent
909a71ff89
commit
b3657f2cc8
@ -1,19 +1,5 @@
|
|||||||
import { Router, Response, Request } from "express";
|
import { Router, Response, Request } from "express";
|
||||||
import { route } from "@fosscord/api";
|
import { route } from "@fosscord/api";
|
||||||
import {
|
|
||||||
Channel,
|
|
||||||
Config,
|
|
||||||
handleFile,
|
|
||||||
trimSpecial,
|
|
||||||
User,
|
|
||||||
Webhook,
|
|
||||||
WebhookCreateSchema,
|
|
||||||
WebhookType,
|
|
||||||
} from "@fosscord/util";
|
|
||||||
import { HTTPError } from "lambert-server";
|
|
||||||
import { isTextChannel } from "./messages/index";
|
|
||||||
import { DiscordApiErrors } from "@fosscord/util";
|
|
||||||
import crypto from "crypto";
|
|
||||||
|
|
||||||
const router: Router = Router();
|
const router: Router = Router();
|
||||||
|
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
import { Router, Request, Response } from "express";
|
import { Router, Request, Response } from "express";
|
||||||
import { HTTPError } from "lambert-server";
|
import { HTTPError } from "lambert-server";
|
||||||
import { route } from "@fosscord/api";
|
import { route, random } from "@fosscord/api";
|
||||||
import { random } from "@fosscord/api";
|
|
||||||
import {
|
import {
|
||||||
Channel,
|
Channel,
|
||||||
Invite,
|
Invite,
|
||||||
@ -11,7 +10,6 @@ import {
|
|||||||
Guild,
|
Guild,
|
||||||
PublicInviteRelation,
|
PublicInviteRelation,
|
||||||
} from "@fosscord/util";
|
} from "@fosscord/util";
|
||||||
import { isTextChannel } from "../../../v0/channels/#channel_id/messages";
|
|
||||||
|
|
||||||
const router: Router = Router();
|
const router: Router = Router();
|
||||||
|
|
||||||
@ -29,7 +27,7 @@ router.post(
|
|||||||
where: { id: channel_id },
|
where: { id: channel_id },
|
||||||
select: ["id", "name", "type", "guild_id"],
|
select: ["id", "name", "type", "guild_id"],
|
||||||
});
|
});
|
||||||
isTextChannel(channel.type);
|
channel.isTextChannel();
|
||||||
|
|
||||||
if (!channel.guild_id) {
|
if (!channel.guild_id) {
|
||||||
throw new HTTPError("This channel doesn't exist", 404);
|
throw new HTTPError("This channel doesn't exist", 404);
|
||||||
|
@ -36,30 +36,6 @@ const router: Router = Router();
|
|||||||
|
|
||||||
export default 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
|
// https://discord.com/developers/docs/resources/channel#create-message
|
||||||
// get messages
|
// get messages
|
||||||
router.get("/", async (req: Request, res: Response) => {
|
router.get("/", async (req: Request, res: Response) => {
|
||||||
@ -67,7 +43,7 @@ router.get("/", async (req: Request, res: Response) => {
|
|||||||
const channel = await Channel.findOneOrFail({ where: { id: channel_id } });
|
const channel = await Channel.findOneOrFail({ where: { id: channel_id } });
|
||||||
if (!channel) throw new HTTPError("Channel not found", 404);
|
if (!channel) throw new HTTPError("Channel not found", 404);
|
||||||
|
|
||||||
isTextChannel(channel.type);
|
channel.isTextChannel();
|
||||||
const around = req.query.around ? `${req.query.around}` : undefined;
|
const around = req.query.around ? `${req.query.around}` : undefined;
|
||||||
const before = req.query.before ? `${req.query.before}` : undefined;
|
const before = req.query.before ? `${req.query.before}` : undefined;
|
||||||
const after = req.query.after ? `${req.query.after}` : undefined;
|
const after = req.query.after ? `${req.query.after}` : undefined;
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
import { HTTPError } from "lambert-server";
|
import { HTTPError } from "lambert-server";
|
||||||
import { route } from "@fosscord/api";
|
import { route } from "@fosscord/api";
|
||||||
import { isTextChannel } from "../../../v0/channels/#channel_id/messages";
|
|
||||||
import { FindManyOptions, Between, Not } from "typeorm";
|
import { FindManyOptions, Between, Not } from "typeorm";
|
||||||
import {
|
import {
|
||||||
Channel,
|
Channel,
|
||||||
@ -34,7 +33,7 @@ router.post(
|
|||||||
|
|
||||||
if (!channel.guild_id)
|
if (!channel.guild_id)
|
||||||
throw new HTTPError("Can't purge dm channels", 400);
|
throw new HTTPError("Can't purge dm channels", 400);
|
||||||
isTextChannel(channel.type);
|
channel.isTextChannel();
|
||||||
|
|
||||||
const rights = await getRights(req.user_id);
|
const rights = await getRights(req.user_id);
|
||||||
if (!rights.has("MANAGE_MESSAGES")) {
|
if (!rights.has("MANAGE_MESSAGES")) {
|
||||||
|
@ -11,7 +11,6 @@ import {
|
|||||||
WebhookType,
|
WebhookType,
|
||||||
} from "@fosscord/util";
|
} from "@fosscord/util";
|
||||||
import { HTTPError } from "lambert-server";
|
import { HTTPError } from "lambert-server";
|
||||||
import { isTextChannel } from "../../../v0/channels/#channel_id/messages/index";
|
|
||||||
import { DiscordApiErrors } from "@fosscord/util";
|
import { DiscordApiErrors } from "@fosscord/util";
|
||||||
import crypto from "crypto";
|
import crypto from "crypto";
|
||||||
|
|
||||||
@ -27,7 +26,7 @@ router.post(
|
|||||||
where: { id: channel_id },
|
where: { id: channel_id },
|
||||||
});
|
});
|
||||||
|
|
||||||
isTextChannel(channel.type);
|
channel.isTextChannel();
|
||||||
if (!channel.guild_id) throw new HTTPError("Not a guild channel", 400);
|
if (!channel.guild_id) throw new HTTPError("Not a guild channel", 400);
|
||||||
|
|
||||||
const webhook_count = await Webhook.count({ where: { channel_id } });
|
const webhook_count = await Webhook.count({ where: { channel_id } });
|
||||||
|
@ -450,6 +450,30 @@ export class Channel extends BaseClass {
|
|||||||
];
|
];
|
||||||
return disallowedChannelTypes.indexOf(this.type) == -1;
|
return disallowedChannelTypes.indexOf(this.type) == -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isTextChannel(): boolean {
|
||||||
|
switch (this.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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ChannelPermissionOverwrite {
|
export interface ChannelPermissionOverwrite {
|
||||||
|
Loading…
Reference in New Issue
Block a user