-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathindex.js
71 lines (71 loc) · 2.94 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import bsky from '@atproto/api';
const { BskyAgent } = bsky;
import * as dotenv from 'dotenv';
import { CronJob } from 'cron';
import * as process from 'process';
dotenv.config();
const port = process.env.PORT || "8080";
// Create a Bluesky Agent
const agent = new BskyAgent({
service: 'https://bsky.social',
});
await agent.login({
identifier: process.env.BLUESKY_USERNAME,
password: process.env.BLUESKY_PASSWORD,
});
// Define emoji arrays
const MOON_EMOJI = ['🌕', '🌖', '🌗', '🌘', '🌒', '🌓', '🌙', '🌜', '🌝', '🌚'];
const SUN_EMOJI = ['🌞', '🌅', '🌄', '🌇', '⛅️', '🌤️', '🌥️', '🌦️'];
const STORM_EMOJI = ['🌧️', '🌨️', '⛈️', '🌩️', '🌪️'];
const CLEAR_EMOJI = ['☁️', ' '];
const BIRD_EMOJI = ['🦅', '🕊️', '🦆', '🦜', '🐥', '🦉'];
const FLORA_EMOJI = ['🌱', '🌷', '🌻', '🍀', '🌹', '🌴', '🌱', '🌵', '🌳', '🍄', '🌾', '🎋'];
// Function to get random emoji from an array
function getRandomEmoji(arr) {
return arr[Math.floor(Math.random() * arr.length)];
}
// Function to print random emojis in random positions
function printRandomEmojis() {
console.log("Running printRandomEmojis...");
const moonOrSun = Math.random() < 0.5 ? MOON_EMOJI : SUN_EMOJI;
const rainingOrClear = Math.random() < 0.5 ? STORM_EMOJI : CLEAR_EMOJI;
const emojiArrays = [moonOrSun, rainingOrClear, BIRD_EMOJI];
const emojis = emojiArrays.map((arr) => getRandomEmoji(arr));
// Add two random flora emojis to the last line
const flora1 = getRandomEmoji(FLORA_EMOJI);
let flora2 = getRandomEmoji(FLORA_EMOJI);
// Ensure the flora emojis are distinct
while (flora1 === flora2) {
flora2 = getRandomEmoji(FLORA_EMOJI);
}
// Generate random positions and repetitions for the flora emojis
const positions = [0, 1, 2, 3].map(() => Math.floor(Math.random() * 15)).sort((a, b) => a - b);
const repetitions = [Math.floor(Math.random() * 3) + 1, Math.floor(Math.random() * 3) + 1];
const floraLine = positions.map((position, index) => {
const emoji = index < repetitions[0] ? flora1 : flora2;
return ' '.repeat(position) + emoji;
}).join('');
let result = '';
emojis.forEach((emoji, index) => {
const randomPosition = Math.floor(Math.random() * 15);
result += ' '.repeat(randomPosition) + emoji;
if (index < emojis.length - 1) {
result += '\n';
}
});
result += '\n' + floraLine;
console.log(result);
postEmojisToBluesky(result);
return result;
}
async function postEmojisToBluesky(emojiString) {
const response = await agent.post({
text: emojiString
});
}
printRandomEmojis();
// Run this on a cron job
const scheduleExpressionMinute = '* * * * *'; // Run once every minute for testing
const scheduleExpression = '0 */3 * * *'; // Run once every three hours in prod
const job = new CronJob(scheduleExpression, printRandomEmojis);
job.start();