-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a576414
commit fd49d4b
Showing
6 changed files
with
542 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
name: Instagram Automation Commenter | ||
|
||
# Controls when the workflow will run | ||
on: | ||
# Triggers the workflow on push events but only for the master branch | ||
# push: | ||
# branches: [ master ] | ||
|
||
# Triggers the workflow with scheduler | ||
schedule: | ||
# every 1 hour | ||
- cron: '0 * * * *' | ||
|
||
# Allows you to run this workflow manually from the Actions tab | ||
workflow_dispatch: | ||
|
||
# A workflow run is made up of one or more jobs that can run sequentially or in parallel | ||
jobs: | ||
# This workflow contains a single job called "build" | ||
start-workflow-commenter: | ||
# The type of runner that the job will run on | ||
runs-on: ubuntu-latest | ||
# Steps represent a sequence of tasks that will be executed as part of the job | ||
steps: | ||
- uses: actions/checkout@v3 | ||
# NodeJS | ||
- name: Use Node.js | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: '16.x' | ||
|
||
- name: Install ts-node | ||
run: npm install -g ts-node | ||
|
||
- name: Install dependencies | ||
run: npm install | ||
|
||
- name: Run node script | ||
env: | ||
IG_USERNAME: '${{ secrets.IG_USERNAME }}' | ||
IG_PASSWORD: '${{ secrets.IG_PASSWORD }}' | ||
# UNSPLASH_ACCESS_KEY: '${{ secrets.UNSPLASH_ACCESS_KEY }}' | ||
QUOTES_API_KEY: '${{ secrets.QUOTES_API_KEY }}' | ||
run: ts-node commenter.ts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,93 @@ | ||
import { ChatGPTAPI } from 'chatgpt' | ||
const axios = require("axios"); | ||
import bluebird from "bluebird"; | ||
import { IgApiClient } from "instagram-private-api"; | ||
const translateGoogle = require("translate-google"); | ||
|
||
const api_key = "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" | ||
require("dotenv").config(); | ||
|
||
async function example() { | ||
const api = new ChatGPTAPI({ | ||
apiKey: api_key, | ||
}) | ||
const ig = new IgApiClient(); | ||
|
||
const res = await api.sendMessage('beri satu kata-kata bijak atau motivasi atau galau') | ||
console.log(res.text) | ||
async function login() { | ||
console.log("🚀 Login"); | ||
ig.state.generateDevice(process.env.IG_USERNAME ?? ""); | ||
// await ig.simulate.preLoginFlow(); | ||
try { | ||
await ig.account.login( | ||
process.env.IG_USERNAME ?? "", | ||
process.env.IG_PASSWORD ?? "" | ||
); | ||
console.log("✅ Login Success"); | ||
|
||
} catch (error) { | ||
console.log("❌ Error login", error); | ||
} | ||
// await ig.simulate.postLoginFlow(); | ||
// process.nextTick(async () => await ig.simulate.postLoginFlow()); | ||
} | ||
|
||
(async () => { | ||
await login(); | ||
|
||
const source = ["posts"]; | ||
const randSource = source[Math.floor(Math.random() * source.length)]; | ||
|
||
async function translateToID(text: string) { | ||
const randQuoteTextIndo = await translateGoogle(text, { to: "id" }); | ||
const caption = randQuoteTextIndo; | ||
return caption; | ||
} | ||
|
||
async function getQuotes() { | ||
console.log("🚀 Get Quotes"); | ||
const quotes = await axios("https://api.api-ninjas.com/v1/quotes", { | ||
headers: { | ||
"X-Api-Key": process.env.QUOTES_API_KEY, | ||
}, | ||
}); | ||
|
||
const quote = quotes.data[0].quote; | ||
const translateQuote = await translateToID(quote); | ||
return translateQuote; | ||
} | ||
|
||
// like and comment 5 timeline feeds | ||
console.log("🚀 Like Timeline Feeds 3 times"); | ||
let likeNcommentTimes = 3; | ||
|
||
try { | ||
const feed = ig.feed.timeline(); | ||
const items = await feed.items(); | ||
|
||
items.forEach(async (item) => { | ||
if (likeNcommentTimes === 0) return console.log("✅ Like Timeline Feeds 3 times finished"); | ||
|
||
if (item.user.username == "dhohirpradana") return console.log("❌ Skip own feed"); | ||
|
||
// like a timeline feed | ||
await ig.media.like({ | ||
mediaId: item.id, | ||
moduleInfo: { | ||
module_name: "profile", | ||
user_id: item.user.pk, | ||
username: item.user.username, | ||
}, | ||
d: 0, | ||
}); | ||
|
||
// comment a timeline feed | ||
const comment = await getQuotes(); | ||
|
||
await ig.media.comment({ | ||
mediaId: item.id, | ||
text: comment, | ||
}); | ||
|
||
// delay for random between 5 and 15 seconds | ||
await bluebird.delay(Math.floor(Math.random() * 10 + 5) * 1000); | ||
|
||
likeNcommentTimes--; | ||
}); | ||
} catch (error) { | ||
console.log("❌ Error get timeline feeds", error); | ||
} | ||
})(); |
Oops, something went wrong.