teknologi-umum / bot

Bot for a more interactive Teknologi Umum group
https://t.me/teknologi_umum
GNU General Public License v3.0
22 stars 22 forks source link

/carbon #7

Closed ronnygunawan closed 3 years ago

ronnygunawan commented 3 years ago

Kirim di private chat:

/carbon function foo() {
  console.log("hello world")
}

Bot akan bikinin carbon

aldy505 commented 3 years ago

Code snippets for bypassing carbon.now.sh's API.

// https://github.com/sindresorhus/got
import got from 'got';
import beautify from 'js-beautify';

/**
 * Generates image from code
 * @param {String} code
 * @param {String} extension something like js ts or anything to signify the file name
 * @returns {Promise<Buffer>}
 */
async function generateImage(code) {
    const carbon = await got.post('https://carbonara.vercel.app/api/cook', {
      json: { code: beautify.js(code) },
      responseType: 'buffer',
      headers: {
        'User-Agent': 'Teknologi Umum <teknologi.umum@gmail.com>',
        'Content-Type': 'application/json',
      },
    });
  // return carbon variable
}
lamualfa commented 3 years ago

Done https://github.com/teknologi-umum/bot/commit/1aa3d1ada9626d150a58912bf707cf50a177ff1b.