Skip to content

Commit

Permalink
Replace Twitter/Facebook with BlueSky
Browse files Browse the repository at this point in the history
  • Loading branch information
bkimminich committed Nov 22, 2024
1 parent 4867f23 commit cbfa6dc
Show file tree
Hide file tree
Showing 11 changed files with 249 additions and 139 deletions.
8 changes: 2 additions & 6 deletions .github/workflows/coupon-distribution.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,8 @@ jobs:
- name: "Distribute coupons"
run: juicy-coupon-bot
env:
TWITTER_CONSUMER_KEY: ${{ secrets.TWITTER_CONSUMER_KEY }}
TWITTER_CONSUMER_SECRET: ${{ secrets.TWITTER_CONSUMER_SECRET }}
TWITTER_ACCESS_TOKEN_KEY: ${{ secrets.TWITTER_ACCESS_TOKEN_KEY }}
TWITTER_ACCESS_TOKEN_SECRET: ${{ secrets.TWITTER_ACCESS_TOKEN_SECRET }}
FACEBOOK_APP_SECRET: ${{ secrets.FACEBOOK_APP_SECRET }}
FACEBOOK_ACCESS_TOKEN: ${{ secrets.FACEBOOK_ACCESS_TOKEN }}
BLUESKY_IDENTIFIER: ${{ secrets.BLUESKY_IDENTIFIER }}
BLUESKY_PASSWORD: ${{ secrets.BLUESKY_PASSWORD }}
REDDIT_ACCOUNT_NAME: ${{ secrets.REDDIT_ACCOUNT_NAME }}
REDDIT_ACCOUNT_PASSWORD: ${{ secrets.REDDIT_ACCOUNT_PASSWORD }}
REDDIT_APP_ID: ${{ secrets.REDDIT_APP_ID }}
Expand Down
9 changes: 3 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,16 @@

const randomDiscount = require('./lib/randomDiscount')
const currentCoupons = require('./lib/currentCoupons')
const twitterStatus = require('./lib/twitterStatus')
const facebookPost = require('./lib/facebookPost')
const blueSkyPost = require('./lib/blueSkyPost')
const redditPost = require('./lib/redditPost')
const publishTweet = require('./lib/publishTweet')
const publishFacebook = require('./lib/publishFacebook')
const publishBlueSky = require('./lib/publishBlueSky')
const publishReddit = require('./lib/publishReddit')

module.exports = () => {
const { expiryDate, discountCodes } = currentCoupons()
const discount = randomDiscount()
const coupon = discountCodes[discount + '%']

publishTweet(twitterStatus(discount, coupon, expiryDate))
publishFacebook(facebookPost(discount, coupon, expiryDate))
publishBlueSky(blueSkyPost(discount, coupon, expiryDate))
publishReddit(redditPost(discount, coupon, expiryDate), `New coupon code (valid until ${expiryDate})`)
}
2 changes: 1 addition & 1 deletion lib/twitterStatus.js → lib/blueSkyPost.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ module.exports = (discount, coupon, expiryDate) => {
`[🤖] You're not seriously gonna miss out on ${discount}% off our assortment of juices? Better redeem #coupon code: ${coupon} (latest on ${expiryDate})`
]
const status = texts[Math.floor(Math.random() * texts.length)]
logger.info(`[${colors.green('✔')}] Twitter status prepared: ${colors.cyan(status)}`)
logger.info(`[${colors.green('✔')}] BlueSky post prepared: ${colors.cyan(status)}`)
return status
}
20 changes: 0 additions & 20 deletions lib/facebookPost.js

This file was deleted.

35 changes: 35 additions & 0 deletions lib/publishBlueSky.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright (c) 2019-2024 Bjoern Kimminich & the OWASP Juice Shop contributors.
* SPDX-License-Identifier: MIT
*/

const logger = require('./logger')
const colors = require('colors')
const { AtpAgent } = require('@atproto/api')
const agent = new AtpAgent({ service: 'https://bsky.social' })

module.exports = async (post) => {
if (process.env.PUBLISHING_MODE) {
try {
await agent.login({
identifier: process.env.BLUESKY_IDENTIFIER,
password: process.env.BLUESKY_PASSWORD
})

const res = await agent.api.com.atproto.repo.createRecord({
repo: agent.session.did,
collection: 'app.bsky.feed.post',
record: {
text: post,
createdAt: new Date().toISOString()
}
})

logger.info(`[${colors.green('✔')}] Post published: ${res}`)
} catch (error) {
logger.warn(`[${colors.red('❌')}] Post failed: ${colors.red(error)}`)
}
} else {
logger.info(`[${colors.yellow('❌')}] Skipped BlueSky post: ${colors.yellow('Post will only be published when PUBLISHING_MODE is set as an environment variable')}`)
}
}
24 changes: 0 additions & 24 deletions lib/publishFacebook.js

This file was deleted.

28 changes: 0 additions & 28 deletions lib/publishTweet.js

This file was deleted.

Loading

0 comments on commit cbfa6dc

Please sign in to comment.