├── .gitignore ├── README.md ├── config.json ├── cookies.json ├── fonts ├── README.txt └── soft.ttf ├── index.js ├── package.json └── tools ├── ImageGenerator.js └── Quote.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | package-lock.json 3 | config.json 4 | cookies.json 5 | image.jpg -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 📸 INSTAGRAM AUTOPOST BOT 2 | This is just a bot I created for fun and decided to make it public so that you can enjoy it as well. It is already running as [silent_kid_in_shell](https://www.instagram.com/silent_kid_in_shell/), so you should check it out and follow it if you'd like. Also, please star this repository if you like it. 3 | 4 | ![](https://i.imgur.com/kQcmOAd.png) 5 | 6 | # 🤔 How to setup 7 | - Download codes 8 | - Run `npm install` 9 | - Fill all details in `config.json` 10 | - Run bot using `node index.js` 11 | 12 | # ⚠️ Notice 13 | - tags should not be too long 14 | - if you changed interval time to too low then you might get banned from insta 15 | - do not use this bot on your main acc 16 | 17 | # 🥺 Join Us 18 | Join our server and help us to grow : [Ctk's Server](https://2vr8.short.gy/discord) 19 | -------------------------------------------------------------------------------- /config.json: -------------------------------------------------------------------------------- 1 | { 2 | "username": "insta-username", 3 | "password": "your-pass", 4 | "tags": "#likes #like #follow #likeforlikes" 5 | } 6 | -------------------------------------------------------------------------------- /cookies.json: -------------------------------------------------------------------------------- 1 | {} 2 | -------------------------------------------------------------------------------- /fonts/README.txt: -------------------------------------------------------------------------------- 1 | To learn more about the font family and its license, visit https://www.fontmirror.com/renogare-soft 2 | 3 | License: Free for personal use. 4 | This is a preview font for testing, you can purchase its full version at https://www.creativefabrica.com/product/renogare-soft/ref/1095569/. -------------------------------------------------------------------------------- /fonts/soft.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CTK-WARRIOR/instagram-autopost-bot/cfe17a1d09998af60c57343609adac8046684341/fonts/soft.ttf -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | const Instagram = require('instagram-web-api') 2 | const Quote = require('./tools/Quote') 3 | 4 | const FileCookieStore = require('tough-cookie-filestore2') 5 | const cookieStore = new FileCookieStore('./cookies.json') 6 | 7 | const { username, password, tags } = require("./config.json") 8 | 9 | const client = new Instagram({ username, password, cookieStore }) 10 | const instaQuote = new Quote({ client, tags, interval: 1000 * 60 * 60 * 12 }) 11 | 12 | client.login().then(async () => { 13 | console.log("Connected to the instagram :)") 14 | await instaQuote.run() 15 | }) 16 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "insta-bot", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "start": "node index.js", 8 | "test": "echo \"Error: no test specified\" && exit 1" 9 | }, 10 | "keywords": [], 11 | "author": "", 12 | "license": "ISC", 13 | "engines": { 14 | "node": "16.x" 15 | }, 16 | "dependencies": { 17 | "axios": "^0.24.0", 18 | "canvas": "^2.8.0", 19 | "cheerio": "^1.0.0-rc.10", 20 | "instagram-web-api": "^2.2.2", 21 | "jimp": "^0.16.1", 22 | "tough-cookie-filestore2": "^1.0.0" 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /tools/ImageGenerator.js: -------------------------------------------------------------------------------- 1 | const axios = require("axios") 2 | const cheerio = require("cheerio") 3 | const jimp = require("jimp") 4 | const { createCanvas, loadImage } = require("canvas") 5 | 6 | async function getAnimeQuote() { 7 | const json = await axios(`https://animechan.vercel.app/api/random`) 8 | .then(res => res.data) 9 | .catch(err => { }) 10 | 11 | return json; 12 | } 13 | 14 | async function getWallpaper(anime, character) { 15 | const images = [] 16 | let url = null; 17 | 18 | let htmlData = await axios(`https://wall.alphacoders.com/search.php?search=${anime.split(" ").join("+")}`) 19 | .then(res => { 20 | url = res.request.res.responseUrl 21 | return res.data; 22 | }).catch(err => { }) 23 | 24 | if (!url) return console.log("[ERROR]: Unable to get location url.") 25 | 26 | let $ = cheerio.load(htmlData) 27 | const pages = $('span.btn.btn-info.btn-lg').text()?.split("/")[1] 28 | if (!pages) { 29 | $('div.thumb-container-big').each(function (i, elem) { 30 | $ = cheerio.load($(elem).html()) 31 | images.push({ 32 | url: $('img').attr('src')?.replace("thumbbig-", ""), 33 | size: $('div.boxcaption div.thumb-info span').text()?.split("x") 34 | }) 35 | 36 | }) 37 | if (images.length) return images[Math.floor(Math.random() * images.length)]; 38 | else return console.log("[ERROR]: Unable to get any image.") 39 | } 40 | 41 | htmlData = await axios(`${url}&page=${randomNumber(1, Number(pages))}`) 42 | .then(res => res.data) 43 | 44 | $ = cheerio.load(htmlData) 45 | $('div.thumb-container-big').each(function (i, elem) { 46 | $ = cheerio.load($(elem).html()) 47 | images.push({ 48 | url: $('img').attr('src')?.replace("thumbbig-", ""), 49 | size: $('div.boxcaption div.thumb-info span').text()?.split("x") 50 | }) 51 | 52 | }) 53 | 54 | return images[Math.floor(Math.random() * images.length)]; 55 | } 56 | 57 | async function generateImage(img, quote) { 58 | const canvas = createCanvas(1080, 1080) 59 | const ctx = canvas.getContext('2d') 60 | let [x, y] = img.size; 61 | 62 | x = Number(x) 63 | y = Number(y) 64 | 65 | let scale = Math.max(canvas.width / x, canvas.height / y); 66 | let xx = (canvas.width / 2) - (x / 2) * scale; 67 | let yy = (canvas.height / 2) - (y / 2) * scale; 68 | 69 | ctx.drawImage(await loadImage(img.url), xx, yy, x * scale, y * scale); 70 | 71 | ctx.rect(0, 0, canvas.width, canvas.height) 72 | ctx.globalAlpha = 0.9; 73 | ctx.fillStyle = "#000000" 74 | ctx.fill() 75 | ctx.globalAlpha = 1; 76 | 77 | ctx.font = `bold 20px soft` 78 | ctx.fillStyle = `#FFFFFF` 79 | ctx.textAlign = "end" 80 | ctx.fillText(`${quote.character} •`, 1050, 1050) 81 | ctx.textAlign = "start" 82 | ctx.fillText(`• ${quote.anime}`, 20, 50) 83 | 84 | 85 | ctx.font = `bold 40px soft`; 86 | const words = quote.quote.split(' '); 87 | drawWords(ctx, quote.quote, 50, 540 - ((words.length / 6) * 10), 1000, 40, 30, words) 88 | 89 | const image = await jimp.read(canvas.toBuffer()) 90 | return image.write("image.jpg") 91 | } 92 | 93 | 94 | function drawWords(context, text, x, y, maxWidth, lineHeight, rectHeight, words) { 95 | var line = ''; 96 | for (var n = 0; n < words.length; n++) { 97 | var testLine = line + words[n] + ' '; 98 | var metrics = context.measureText(testLine); 99 | var testWidth = metrics.width; 100 | if (testWidth > maxWidth && n > 0) { 101 | context.fillText(line, x, y); 102 | line = words[n] + ' '; 103 | y += lineHeight; 104 | } 105 | else { 106 | line = testLine; 107 | } 108 | } 109 | context.fillText(line, x, y); 110 | rectHeight = rectHeight + lineHeight; 111 | } 112 | 113 | function randomNumber(min, max) { 114 | min = Math.ceil(min); 115 | max = Math.floor(max); 116 | return Math.floor(Math.random() * (max - min + 1)) + min; 117 | } 118 | 119 | module.exports = { getAnimeQuote, getWallpaper, drawWords, generateImage } -------------------------------------------------------------------------------- /tools/Quote.js: -------------------------------------------------------------------------------- 1 | const { getAnimeQuote, getWallpaper, generateImage } = require("./ImageGenerator.js") 2 | const { registerFont } = require("canvas") 3 | registerFont('./fonts/soft.ttf', { family: 'soft' }) 4 | 5 | class Quote { 6 | constructor({ tags, client, interval } = {}) { 7 | this.tags = tags 8 | this.client = client 9 | this.interval = interval 10 | } 11 | 12 | async run() { 13 | console.log("- Instagram Quote Bot is Started 🥳 - ") 14 | const that = this 15 | 16 | setInterval(async function () { 17 | const quote = await getAnimeQuote() 18 | 19 | await that.generateQuoteImage(quote).catch(err => { 20 | console.log(err) 21 | }) 22 | 23 | setTimeout(async function () { 24 | const post = await that.postQuote(quote).catch(err => { }) 25 | if (!post) return console.log("[ERROR]: Unable to post quote.") 26 | 27 | console.log(`[https://www.instagram.com/p/${post.media.code}]: Uploaded new post from ${quote.anime}`) 28 | }, 5000) 29 | }, this.interval) 30 | } 31 | 32 | async generateQuoteImage(quote) { 33 | const image = await getWallpaper(quote.anime) 34 | !image ? image = await getWallpaper(quote.character) : image 35 | if (!image) throw "Unable to generate image." 36 | 37 | return generateImage(image, quote) 38 | } 39 | 40 | async postQuote(quote) { 41 | const post = await this.client.uploadPhoto({ 42 | photo: './image.jpg', 43 | caption: `"${quote.quote}"\n\n- ${quote.character} from ${quote.anime}\n\n\n#anime #${quote.anime.replace(/ /g, "")} ${this.tags}`, 44 | post: "feed" 45 | }) 46 | 47 | return post; 48 | } 49 | } 50 | 51 | module.exports = Quote; --------------------------------------------------------------------------------