Skip to content

Commit

Permalink
readme and comments
Browse files Browse the repository at this point in the history
  • Loading branch information
davila7 committed Jan 3, 2023
1 parent 8cf1621 commit ae9386e
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 27 deletions.
19 changes: 10 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# twitter-bot-v2
Bot en Twitter con Node.js y OpenAI
Twitter-Bot-GPT (Node.js y OpenAI)

### Install

```
$ npm install
```
Agrega el archivo .env y agrega las API Kyes de Twitter y OpenAI
Add the .env file and complete Twitter and OpenAI Kyes APIs
```
#dev
Expand All @@ -30,20 +30,21 @@ $ node index.js
```


# Tutoriales
# tutorials in Spanish

## Primera parte para conectar Twitter
## First part to connect Twitter

Construye conecta nodejs con twitter:
Connect Twitter:
[Youtube](https://youtu.be/hi_qOqTL4Hk)
[Bot en Twitter con Nodejs](https://medium.com/@dan.avila7/bot-en-twitter-con-nodejs-ccc35a8914ca)

## Segunda parte para conectar OpenAI
## Second part to connect OpenAI

Obtén el API Key, responde tweets con texto y con un generador de imágenes:
Connect OpenAI:
[Youtube](https://youtu.be/zVHDeeyIbXs)

## Artículo con el paso a paso para ejecutar

[Bot en Twitter con Nodejs](https://medium.com/@dan.avila7/bot-en-twitter-con-nodejs-ccc35a8914ca)




2 changes: 2 additions & 0 deletions client/dev_client.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
require('dotenv').config()

// Twitter v2 Dev Client
const {TwitterApi} = require('twitter-api-v2');

const dev_client = new TwitterApi(process.env.APP_TOKEN);
Expand Down
2 changes: 2 additions & 0 deletions client/openai.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
require('dotenv').config();


// OpenAI Client
const { Configuration, OpenAIApi } = require('openai');

const configuration = new Configuration({
Expand Down
2 changes: 2 additions & 0 deletions client/user_client.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
require('dotenv').config()

// Twitter v2 User Client
const {TwitterApi} = require('twitter-api-v2');

const user_client = new TwitterApi({
Expand Down
28 changes: 13 additions & 15 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,57 +7,55 @@ const {ETwitterStreamEvent} = require('twitter-api-v2');

async function main(){

//user
//Get the user
const user = await user_client.v2.me();
//console.log(user);
let user_id = '1598408860720570384'; // cambia esto a tu propio user id
let user_id = ''; // change this to your own user_id

const rules = await dev_client.v2.streamRules();
console.log(rules);

//descomenta para eliminar las reglas anteriores
// uncomment to remove old rules
// await dev_client.v2.updateStreamRules({
// delete: { ids: rules.data.map( rule => rule.id) }
// })

// regla
let regla = '#CodeGPT'; // cambia esto por tu propia regla
// create a rule
let rule = '#CodeGPT'; // change this to your own rule

//descomenta para agregar una nueva regla
// uncomment to add a new rules
// await dev_client.v2.updateStreamRules({
// add: [{ value: regla } ], // cambia esto por tus propias reglas
// add: [{ value: rule } ],
// });


//comienza el stream para obtener los datos de twitter
// start the stream to get twitter data
const stream = dev_client.v2.searchStream({
'tweet.fields' : ['referenced_tweets', 'author_id']
});

//recorremos el stream
(await stream).on(ETwitterStreamEvent.Data, async tweet => {
console.log(tweet.data.author_id);
console.log(tweet.data.text);

// ignora los retweets y también los tweets del mismo bot
// Ignore retweets and also tweets from the same bot
const isARt = tweet.data.referenced_tweets?.some(tweet => tweet.type === 'retweeted') ?? false;
console.log(isARt);
if (isARt || tweet.data.author_id === user_id) {
return;
}

// da like al tweet
// like
// await user_client.v2.like(user_id, tweet.data.id);

// da retweet al tweet
// retweet
// await user_client.v2.retweet(user_id, tweet.data.id);

// responde el tweet con un texto determinado
// reply tweet with a text
// await user_client.v1.reply('I like this!', tweet.data.id);

// responde el tweet con openai
// reply to the tweet with openai
let respuesta = '';

// le sacamos la regla al tweet y obtenemos el texto limpio
const clear_text = tweet.data.text.replace(regla, '');

Expand Down
4 changes: 2 additions & 2 deletions test_dalle.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ const openai = new OpenAIApi(configuration);

//Dall-e
async function main() {

const prompt = ""; // fill this prompt
const response = await openai.createImage({
prompt: 'Un programador youtuber Chileno que se llama Daniel San', // cambia este prompt para generar diferentes imágenes
prompt: prompt,
n: 1,
size: '1024x1024'
});
Expand Down
3 changes: 2 additions & 1 deletion test_davinci.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ const openai = new OpenAIApi(configuration);

//davinci
async function main() {
const prompt = ''; // fill this prompt
const completion = await openai.createCompletion({
model: "text-davinci-003",
prompt: 'Hola cómo estás?', // cambia este prompt para generar diferente texto
prompt: prompt,
temperature: 0.5,
max_tokens: 250,
top_p: 1.0,
Expand Down

0 comments on commit ae9386e

Please sign in to comment.