Skip to content

Commit

Permalink
Merge pull request gndx#4 from gndx/feature/twitter-bot
Browse files Browse the repository at this point in the history
[Add] Twitter integration
  • Loading branch information
gndx authored May 30, 2020
2 parents c9e824e + 4a60fcd commit d8232e5
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
16 changes: 16 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"dotenv": "^8.2.0",
"firebase-admin": "^8.12.1",
"node-cron": "^2.0.3",
"tmi.js": "^1.5.0"
"tmi.js": "^1.5.0",
"twitter": "^1.7.1"
},
"devDependencies": {
"nodemon": "^2.0.4"
Expand Down
19 changes: 18 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const tmi = require("tmi.js");
const Twitter = require('twitter');
const cron = require("node-cron");
const admin = require("firebase-admin");
const randomMsg = require('./utils/randomMsg');
Expand All @@ -14,6 +15,13 @@ admin.initializeApp({
databaseURL: "https://gndxtwitchbot.firebaseio.com"
});

const clientTwitter = new Twitter({
consumer_key: process.env.CONSUMER_KEY,
consumer_secret: process.env.CONSUMER_SECRECT,
access_token_key: process.env.TOKEN_KEY,
access_token_secret: process.env.TOKEN_SECRET
});

const db = admin.firestore();

const welcomeList = ["hola", "buenas", "saludos"];
Expand Down Expand Up @@ -60,7 +68,15 @@ const commandResolve = async (target, msg) => {
let randomUser = random(winner);
client.say(target, `BloodTrail El Ganador es @${randomUser.username} HolidayPresent`);
}

if (commandMessage.includes('twbot')) {
let msgTwitter = msg.substr(6);
const msg2 = `${msgTwitter} en vivo: https://twitch.tv/gndxdev #EStreamerCoders`;
clientTwitter.post('statuses/update', { status: msg2 }, function (error, tweet, response) {
if (error) throw error;
const tweetUrl = `https://twitter.com/i/web/status/${tweet.id_str}`;
client.say(target, `¡Hey dale RT! MrDestructoid ${tweetUrl}`);
});
}
const command = commandMessage in commands ? commands[commandMessage] : null;
if (command) client.say(target, command);
};
Expand All @@ -69,6 +85,7 @@ client.on("message", async (target, context, msg, self) => {
if (self) return;
const text = msg.toLowerCase();
const commandRaffle = text.replace("!", "");

if (commandRaffle === 'rifa') {
if (userList.includes(context.username)) {
client.say(target, `@${context.username}, ¡Ya estas particiando BibleThump!`)
Expand Down

0 comments on commit d8232e5

Please sign in to comment.