Add basic tweet-bot stuff

This commit is contained in:
Luke Berndt
2021-03-03 22:22:53 -05:00
parent b872cfee45
commit a2205f3bac
6 changed files with 60 additions and 2 deletions

View File

@@ -47,6 +47,7 @@
"mongoose": "5.11.10",
"node-mailjet": "3.3.1",
"passport": "0.4.1",
"passport-local": "1.0.0"
"passport-local": "1.0.0",
"passport-twitter": "1.0.4"
}
}

View File

@@ -0,0 +1,19 @@
var Strategy = require('passport-twitter').Strategy;
const User = require("../../models/user");
const twitter = new Strategy({
consumerKey: process.env['TWITTER_CONSUMER_KEY'],
consumerSecret: process.env['TWITTER_CONSUMER_SECRET'],
callbackURL: '/oauth/callback',
proxy: trustProxy
},
function(token, tokenSecret, profile, cb) {
// In this example, the user's Twitter profile is supplied as the user
// record. In a production-quality application, the Twitter profile should
// be associated with a user record in the application's database, which
// allows for account linking and authentication with other identity
// providers.
return cb(null, profile);
})
module.exports = local;

View File

@@ -1,6 +1,7 @@
/* Initializing PassportJS */
const User = require("../models/user");
const local = require("./passport-strategies/local");
const twitter = require("./passport-strategies/twitter");
module.exports = function (app, passport) {
// Configure Passport authenticated session persistence.

View File

@@ -32,6 +32,7 @@ const server = require('http').createServer(app);
const io = require('socket.io')(server, {});
var Twitter = require('twitter-lite');
io.origins('*:*');
@@ -50,6 +51,23 @@ io.on('connection', function(socket){
});
});
const client = new Twitter({
subdomain: "api", // "api" is the default (change for other subdomains)
version: "1.1", // version "1.1" is the default (change for other subdomains)
consumer_key: process.env.TWITTER_CONSUMER_KEY, // from Twitter.
consumer_secret: process.env.TWITTER_CONSUMER_SECRET, // from Twitter.
access_token_key: process.env.TWITTER_ACCESS_TOKEN_KEY, // from your User (oauth_token)
access_token_secret: process.env.TWITTER_ACCESS_TOKEN_SECRET // from your User (oauth_token_secret)
});
client
.get("account/verify_credentials")
.then(results => {
console.log("results", results);
})
.catch(console.error);
function getRole(req) {
if (req.params.shortName && req.user) {
var short_name = req.params.shortName.toLowerCase();
@@ -156,8 +174,19 @@ app.post('/:shortName/star/:id', calls.add_star, function(req,res) {
/*------ UPLOADS ---------- upload.single('call'), uploads.upload,*/
app.post('/:shortName/upload', upload.single('call'), uploads.upload, function(req,res) {
app.post('/:shortName/upload', upload.single('call'), uploads.upload, async function(req,res) {
notify_clients(req.call);
if ((req.call.shortName=="dcfd") && (req.call.talkgroupNum==101)) {
var call_time = new Date(req.call.time);
var call_link = "https://openmhz.com/system/dcfd?call-id=" + req.call._id + "&time=" + call_time.getTime();
var call_time_label = call_time.toLocaleDateString() + " " + call_time.toLocaleTimeString()
var status = req.call.len +" sec transmission\n" + call_time_label + "\n" + call_link;
const response = await client.post('statuses/update', {
status: status,
});
//console.log("Tweet Response: " + response);
}
});
/*------ SYSTEMS ----------*/

View File

@@ -65,6 +65,10 @@ services:
- S3_ENDPOINT
- S3_BUCKET
- S3_PROFILE
- TWITTER_CONSUMER_KEY
- TWITTER_CONSUMER_SECRET
- TWITTER_ACCESS_TOKEN_KEY
- TWITTER_ACCESS_TOKEN_SECRET
volumes:
- "~/.aws:/home/app/.aws"
depends_on:

View File

@@ -22,3 +22,7 @@ export REACT_APP_ACCOUNT_SERVER="${PROTOCOL}account.${DOMAIN_NAME}"
export REACT_APP_ADMIN_SERVER="${PROTOCOL}admin.${DOMAIN_NAME}"
export REACT_APP_COOKIE_DOMAIN=".${DOMAIN_NAME}"
export TWITTER_CONSUMER_KEY=""
export TWITTER_CONSUMER_SECRET=""
export TWITTER_ACCESS_TOKEN_KEY=""
export TWITTER_ACCESS_TOKEN_SECRET=""