|
1 | 1 | const router = require('express').Router();
|
2 | 2 | const { Client } = require('eris');
|
3 | 3 | const bot = new Client();
|
| 4 | +const canvas = require('canvas'); |
| 5 | +const path = require('path'); |
4 | 6 |
|
5 | 7 |
|
6 | 8 | /**
|
@@ -98,6 +100,66 @@ router.post('/top.gg_vote', (req, res) => {
|
98 | 100 | });
|
99 | 101 |
|
100 | 102 |
|
| 103 | +let gavCahce; |
| 104 | +/** |
| 105 | + * @swagger |
| 106 | + * /other/gav: |
| 107 | + * get: |
| 108 | + * description: Gav |
| 109 | + * tags: [Other] |
| 110 | + * parameters: |
| 111 | + * - name: key |
| 112 | + * description: Your API key, Join our discord server to get one (https://monke.vip/discord) |
| 113 | + * in: query |
| 114 | + * type: string |
| 115 | + * - name: imgUrl |
| 116 | + * description: The url of the image to place on gav. |
| 117 | + * in: query |
| 118 | + * required: true |
| 119 | + * type: string |
| 120 | + * responses: |
| 121 | + * 200: |
| 122 | + * description: Success |
| 123 | + * 400: |
| 124 | + * description: Error |
| 125 | + */ |
| 126 | +router.get('/gav', async (req, res) => { |
| 127 | + |
| 128 | + const imgUrl = req.urlParams.imgUrl; |
| 129 | + |
| 130 | + if(!imgUrl) return res.json({ |
| 131 | + error: true, |
| 132 | + message: 'Missing imgUrl param' |
| 133 | + }); |
| 134 | + |
| 135 | + |
| 136 | + let toPlace; |
| 137 | + try{ |
| 138 | + toPlace = await canvas.loadImage(imgUrl); |
| 139 | + } catch (err) { |
| 140 | + console.log(err) |
| 141 | + return res.status(400).json({ |
| 142 | + error: true, |
| 143 | + message: 'Failed to load image.' |
| 144 | + }); |
| 145 | + }; |
| 146 | + |
| 147 | + let gav; |
| 148 | + if(gavCahce) gav = gavCahce; |
| 149 | + else gav = await canvas.loadImage(path.join(__dirname + '../../Assets', 'gav.png')); |
| 150 | + |
| 151 | + |
| 152 | + const Canvas = canvas.createCanvas(gav.width, gav.height); |
| 153 | + const ctx = Canvas.getContext('2d'); |
| 154 | + ctx.drawImage(gav, 0, 0, Canvas.width, Canvas.height); |
| 155 | + console.log(gav.height, gav.width) |
| 156 | + ctx.drawImage(toPlace, 270, 70, 60, 60); |
| 157 | + |
| 158 | + |
| 159 | + res.set({'Content-Type': 'image/png'}); |
| 160 | + res.status(200).send(Canvas.toBuffer()); |
| 161 | +}); |
| 162 | + |
101 | 163 |
|
102 | 164 | module.exports = {
|
103 | 165 | end: '/other/',
|
|
0 commit comments