Skip to content

Commit

Permalink
Merge pull request #61 from GeneralMagicio/change-cast-copy
Browse files Browse the repository at this point in the history
Change cast copy and cronjob time
  • Loading branch information
mmahdigh authored Nov 1, 2024
2 parents 8169ca3 + b1d30c2 commit 474ecf3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
22 changes: 14 additions & 8 deletions src/cronJobs.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
import { schedule } from 'node-cron';
import { sendDailyCasts } from './neynar/utils';

const sendCastsCronJobTime = '21 1 17 * * *'; // at 17:01 every day
const sendCastsCronJobTime = '21 1 22 * * *'; // at 22:01 Tehran time every day

export const initializeCronJobs = () => {
sendCastsCronJob();
};

const sendCastsCronJob = () => {
schedule(sendCastsCronJobTime, async () => {
try {
await sendDailyCasts();
} catch (e) {
console.error('sendCastsCronJob error', e);
}
});
schedule(
sendCastsCronJobTime,
async () => {
try {
await sendDailyCasts();
} catch (e) {
console.error('sendCastsCronJob error', e);
}
},
{
timezone: 'Asia/Tehran',
},
);
};
9 changes: 4 additions & 5 deletions src/neynar/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,10 @@ const getDelegations = async (start: number, end?: number) => {

export const sendDailyCasts = async () => {
const currentTimestamp = new Date();
// Get the timestamp for 17:00 of the current day
const endTimestamp = new Date(currentTimestamp);
endTimestamp.setHours(17, 0, 0, 0); // set to 00:00:00
endTimestamp.setMinutes(0, 0, 0); // set to xx:00:00
const delegations = await getDelegations(
endTimestamp.getTime() - 24 * 60 * 60 * 1000, // Get the timestamp for 17:00 of the previous day
endTimestamp.getTime() - 24 * 60 * 60 * 1000, // Get the timestamp for xx:00 of the previous day
endTimestamp.getTime(),
);
if (!delegations || delegations.length === 0) return;
Expand Down Expand Up @@ -111,9 +110,9 @@ const sendDelegationCast = async (props: {
🗳️ ${totalDelegates} ${
oneDelegate ? 'person has' : 'people have'
} delegated to you in @Pairwise's Liquid Democracy experiment!
} delegated to you in @pairwise's Liquid Democracy experiment!
🤝 Delegate this voting power to the @Farcaster users you trust to judge the impact of the governance projects in @Optimism's Retro Funding 6 round or vote yourself! 🫡
🤝 Delegate this voting power to the @farcaster users you trust to judge projects in @optimism's Retro Funding 6 round or vote yourself! 🫡
👇
https://app.pairwise.vote
Expand Down

0 comments on commit 474ecf3

Please sign in to comment.