-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add diferents images on special dates
- Loading branch information
1 parent
b375243
commit 1534a62
Showing
2 changed files
with
24 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,35 @@ | ||
import { getTimeLine, postStatus, uploadMedia } from '../Mastodon'; | ||
|
||
const wednesdayPosts = { | ||
defaultWednesday: { image: 'wednesday.jpg', description: 'It is Wednesday, my dudes. Big fat frog.' }, | ||
wednesdayOctober: { image: 'october-wednesday.jpg', description: 'It is Wednesday, my dudes. Big skeleton frog.' }, | ||
lastWednesdayOctober: { | ||
image: 'spoktober-wednesday.jpg', | ||
description: 'It is Hallowednesday, my doots. Big skeleton frog with trumpet.', | ||
}, | ||
}; | ||
|
||
const postOnWednesday = async (token: string, resources: R2Bucket) => { | ||
const now = new Date(); | ||
if (now.getDay() === 3) { | ||
if (now.getUTCDay() === 3) { | ||
const [lastPost]: any = await getTimeLine(token); | ||
if (!lastPost || new Date(lastPost.created_at).getDate() !== now.getDate()) { | ||
const image = await resources.get('wednesday.jpg'); | ||
if (image === null) return; | ||
const { id }: any = await uploadMedia(token, await image.blob()); | ||
const info = getImageInfo(now); | ||
const image = await resources.get(info.image); | ||
if (image === null) return 'Wednesday Not Found'; | ||
const { id }: any = await uploadMedia(token, await image.blob(), info.description); | ||
await postStatus(token, id); | ||
return "It's Wednesday My Dudes"; | ||
} else return 'Already Posted My Dude'; | ||
} else return "It's Not Wednesday My Dudes"; | ||
}; | ||
|
||
const getImageInfo = (date: Date) => { | ||
if (date.getUTCMonth() === 9) { | ||
if (date.getUTCDate() + 7 > 31) return wednesdayPosts.lastWednesdayOctober; | ||
return wednesdayPosts.wednesdayOctober; | ||
} | ||
return wednesdayPosts.defaultWednesday; | ||
}; | ||
|
||
export { postOnWednesday }; |