summaryrefslogtreecommitdiff
path: root/server/src/API/routers/GuildRouter.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/src/API/routers/GuildRouter.ts')
-rw-r--r--server/src/API/routers/GuildRouter.ts44
1 files changed, 44 insertions, 0 deletions
diff --git a/server/src/API/routers/GuildRouter.ts b/server/src/API/routers/GuildRouter.ts
new file mode 100644
index 0000000..01a8a9b
--- /dev/null
+++ b/server/src/API/routers/GuildRouter.ts
@@ -0,0 +1,44 @@
+import { Router, Request, Response, Application } from 'express';
+import { AkairoClient } from 'discord-akairo';
+import { Guild } from 'discord.js';
+import { authorization } from '../../Config';
+
+export default class GuildRouter {
+ protected app: Application;
+ protected client: AkairoClient;
+ protected router: Router;
+
+ public constructor(app: Application, client: AkairoClient) {
+ this.app = app;
+ this.client = client;
+ this.router = Router();
+
+ this.app.use(this.router);
+
+ this.router.get('/v1/get/guild/:id', (req: Request, res: Response) => {
+ const guild: Guild = this.client.guilds.cache.get(req.params.id);
+ if (!guild) return res.status(404).send({ message: 'Guild Not Found' });
+
+ return res.status(200).send({
+ name: guild.name,
+ owner: guild.owner.user.tag,
+ members: guild.memberCount
+ });
+ });
+
+ this.router.post('/v1/post/guild-name/:id', (req: Request, res: Response) => {
+ if (req.headers.authorization !== authorization) return res.status(401).send({ message: 'Unauthorized' });
+
+ const guild: Guild = this.client.guilds.cache.get(req.params.id);
+ if (!guild) return res.status(404).send({ message: 'Guild Not Found' });
+
+ if (!req.body.name) return res.status(404).send({ message: 'No Guild Name Provided' });
+ if (req.body.name.length > 32) return res.status(400).send({ message: 'Guild Name Exceeds 32 Characters' });
+ if (!guild.me.permissions.has('MANAGE_GUILD')) return res.status(401).send({ message: 'Cannot Manage Guild' });
+
+ guild.setName(req.body.name);
+
+ return res.status(201).send(req.body);
+ });
+ }
+} \ No newline at end of file