auths
objectreturn
or this.key = 'value'
, pass input data to your code viaparams
, and maintain state across executions with$checkpoint.async
(event, steps) => {
}
const { default: fetch } = await import('node-fetch');
// length to cache in ms (five days)
const CACHE_LENGTH = 5 * 24 * 60 * 60 * 1000;
if($checkpoint && $checkpoint.monsterCache && $checkpoint.monsterCache.lasthit) {
let lasthit = $checkpoint.monsterCache.lasthit;
let now = new Date().getTime();
console.log(`duration is ${now-lasthit}ms`);
if(now - lasthit < CACHE_LENGTH) this.monsters = $checkpoint.monsterCache.monsters;
if(this.monsters) console.log('i used the cached version');
}
if(!this.monsters) {
console.log('need to fetch monsters');
//first get all the monsters
let resp = await fetch('https://www.dnd5eapi.co/api/monsters');
let data = await resp.json();
this.monsters = data.results;
if(!$checkpoint) $checkpoint = {};
$checkpoint.monsterCache = {
lasthit:new Date().getTime(),
monsters:data.results
}
}
auths
objectreturn
or this.key = 'value'
, pass input data to your code viaparams
, and maintain state across executions with$checkpoint.async
(event, steps) => {
}
const { default: fetch } = await import('node-fetch');
getRandomInt = function(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min) + min); //The maximum is exclusive and the minimum is inclusive
}
randomAlignment = function() {
let law = ["lawful","neutral","chaotic"];
let good = ["good","neutral","evil"];
let alignment = law[getRandomInt(0,3)] + ' '+good[getRandomInt(0,3)];
if(alignment === 'neutral neutral') alignment = 'neutral';
return alignment;
}
this.monsterA = steps.get_monsters.monsters[getRandomInt(0, steps.get_monsters.monsters.length )].name;
//theoretically possible to select the same monter twice, I'm ok with that
this.monsterB = steps.get_monsters.monsters[getRandomInt(0, steps.get_monsters.monsters.length )].name;
// sometimes a creature name is: Werewolf, human form. Drop that
this.monsterA = this.monsterA.replace(/,.*/, '');
this.monsterB = this.monsterB.replace(/,.*/, '');
this.monsterAAlignment = randomAlignment();
this.monsterBAlignment = randomAlignment();
auths
objectreturn
or this.key = 'value'
, pass input data to your code viaparams
, and maintain state across executions with$checkpoint.async
(event, steps) => {
}
// import { generateSlug } from "random-word-slugs";
const indefinite = require('indefinite');
const { generateSlug } = await import('random-word-slugs');
const fightTypes = ["argument","heated discussion","Facebook comments argument","fight","misunderstanding",
"war of words","confrontation","verbal battle","debate","violent disagreement"];
const resolveTypes = [
"over a cup of tea",
"with a good hug",
"by calmly discussing their problem",
"with an epic dance off",
"by discussing the merits of cats instead"
];
getRandomInt = function(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min) + min); //The maximum is exclusive and the minimum is inclusive
}
let conflict = generateSlug(1, {
partsOfSpeech:['noun'],
format: 'lower' });
let fight = fightTypes[getRandomInt(0, fightTypes.length)];
let resolution = resolveTypes[getRandomInt(0, resolveTypes.length)];
this.conflict_text = `
${indefinite(steps.select_monsters.monsterAAlignment, {capitalize:true})} ${steps.select_monsters.monsterA} and ${indefinite(steps.select_monsters.monsterBAlignment)} ${steps.select_monsters.monsterB} are having a ${fight} over ${indefinite(conflict)}.
They resolve their issue ${resolution}.
`;
console.log(this.conflict_text);
async
(params, auths) => {
}
const axios = require('axios')
const {status, in_reply_to_status_id, auto_populate_reply_metadata, exclude_reply_user_ids, attachment_url, media_ids, possibly_sensitive, lat, long, place_id, display_coordinates, trim_user, enable_dmcommands, fail_dmcommands, card_uri} = params
const body = {
config: {
url: `https://api.twitter.com/1.1/statuses/update.json`,
method: 'POST',
params,
},
token: {
key: auths.twitter.oauth_access_token,
secret: auths.twitter.oauth_refresh_token,
},
}
const proxy = "https://api.pipedream.com/v1/oauth1/app_13GhY1"
const resp = await axios.post(proxy,body)
const {messages, data} = resp.data
for (const message of messages) {
console.log(message)
}
return data