Skip to content
This repository has been archived by the owner on Jan 12, 2023. It is now read-only.

Commit

Permalink
feat: simplifies mods tweet (#288)
Browse files Browse the repository at this point in the history
  • Loading branch information
cujarrett authored Jan 12, 2022
1 parent 9b7ce27 commit 717f5e3
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 137 deletions.
20 changes: 5 additions & 15 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
const { name, version } = require("./package.json")
const { ada1Mods } = require("./src/tweet-types/ada-1-mods.js")
const { banshee44Mods } = require("./src/tweet-types/banshee-44-mods.js")
const { mods } = require("./src/tweet-types/mods.js")
const { xurExotics } = require("./src/tweet-types/xur-exotics")
const { highStatLegendaryArmor } = require("./src/tweet-types/high-stat-legendary-armor.js")

exports.handler = async (event, context, callback) => {
console.log(`${name} ${version} called`)

let ada1ModsResult
let banshee44ModsResult
let modsResult
let xurExoticsResult
let ada1LegendaryArmorResults
let theDrifterLegendaryArmorResults
Expand All @@ -19,15 +17,8 @@ exports.handler = async (event, context, callback) => {
let xurLegendaryArmorResults

try {
ada1ModsResult = await ada1Mods()
console.log({ ada1ModsResult })
} catch (error) {
console.log(error)
}

try {
banshee44ModsResult = await banshee44Mods()
console.log({ banshee44ModsResult })
modsResult = await mods()
console.log({ modsResult })
} catch (error) {
console.log(error)
}
Expand Down Expand Up @@ -88,8 +79,7 @@ exports.handler = async (event, context, callback) => {
console.log(error)
}

const result = ada1ModsResult
&& banshee44ModsResult
const result = modsResult
&& xurExoticsResult
&& ada1LegendaryArmorResults
&& theDrifterLegendaryArmorResults
Expand Down
39 changes: 0 additions & 39 deletions src/tweet-types/ada-1-mods.js

This file was deleted.

39 changes: 0 additions & 39 deletions src/tweet-types/banshee-44-mods.js

This file was deleted.

51 changes: 51 additions & 0 deletions src/tweet-types/mods.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
const { getVendorInventory } = require("../integrations/destiny-insights-backend.js")
const { addItem, getLastSoldItems } = require("../integrations/dynamodb.js")
const { isNewInventory } = require ("../util/is-new-inventory.js")
const { tweet } = require("../integrations/twitter.js")

module.exports.getmodTweetMessage = (ada1Mod1, ada1Mod2, banshee44Mod1, banshee44Mod2) => {
return `Ada-1 mods for sale:
- ${ada1Mod1}
- ${ada1Mod2}
Banshee-44 mods for sale:
- ${banshee44Mod1}
- ${banshee44Mod2}
Mod sale stats available at https://destinyinsights.com
#Destiny2 #TwitterBot`
}

module.exports.mods = async () => {
let result
const { inventory: { mods: currentAda1Mods } } = await getVendorInventory("ada-1")
const lastSoldAda1Mods = await getLastSoldItems("ada-1", 1)
const newAda1Inventory = await isNewInventory(currentAda1Mods, lastSoldAda1Mods)

if (newAda1Inventory) {
const timestamp = new Date().toISOString()
for (const mod of currentAda1Mods) {
mod.source = "ada-1"
await addItem(mod, timestamp)
}
const ada1Mod1 = currentAda1Mods[0].name
const ada1Mod2 = currentAda1Mods[1].name

const { inventory: { mods: currentBanshee44Mods } } = await getVendorInventory("banshee-44")
for (const mod of currentBanshee44Mods) {
mod.source = "banshee-44"
await addItem(mod, timestamp)
}
const banshee44Mod1 = currentBanshee44Mods[0].name
const banshee44Mod2 = currentBanshee44Mods[1].name

const message = this.getmodTweetMessage(ada1Mod1, ada1Mod2, banshee44Mod1, banshee44Mod2)

await tweet(message)
result = `Tweeted:\n${message}`
} else {
result = "New mods tweet is not ready"
}
return result
}
39 changes: 0 additions & 39 deletions src/util/get-mod-info.js

This file was deleted.

5 changes: 0 additions & 5 deletions src/util/is-new-inventory.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
module.exports.isNewInventory = async (currentItems, lastSoldItems) => {
console.log({ currentItems })
console.log({ lastSoldItems })
let newItemsFound = false
const lastSoldItemNames = lastSoldItems.map((value) => value.name)

console.log({ lastSoldItemNames })

for (const currentItem of currentItems) {
if (!lastSoldItemNames.includes(currentItem.name)) {
console.log(`New item found: ${currentItem.name}`)
newItemsFound = true
}
}
Expand Down

0 comments on commit 717f5e3

Please sign in to comment.