diff options
| author | 8cy <[email protected]> | 2020-07-23 23:24:17 -0700 |
|---|---|---|
| committer | 8cy <[email protected]> | 2020-07-23 23:24:17 -0700 |
| commit | bb511abc03bb66848947e37a999502b813c77269 (patch) | |
| tree | 612c010fc8317e1cdf11471a18aad0270819d33e /server/src/API/routers/GuildRouter.ts | |
| parent | fix: if clear amount equal or over 100, round down to 99 (diff) | |
| download | dep-core-bb511abc03bb66848947e37a999502b813c77269.tar.xz dep-core-bb511abc03bb66848947e37a999502b813c77269.zip | |
goodbye old uwufier :cry:
Diffstat (limited to 'server/src/API/routers/GuildRouter.ts')
| -rw-r--r-- | server/src/API/routers/GuildRouter.ts | 44 |
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 |