mirror of
https://github.com/captbaritone/webamp.git
synced 2026-07-28 12:36:35 +00:00
Different skins for Twitter and Instagram
This commit is contained in:
parent
45499a6397
commit
684d7a972d
4 changed files with 47 additions and 9 deletions
|
|
@ -123,10 +123,10 @@ async function main() {
|
|||
break;
|
||||
}
|
||||
case "tweet": {
|
||||
console.log("tweet");
|
||||
console.log("tweet & insta");
|
||||
const hash = argv._[1];
|
||||
const md5 = await tweet(client, hash);
|
||||
await insta(client, md5);
|
||||
await tweet(client, hash);
|
||||
await insta(client, hash);
|
||||
break;
|
||||
}
|
||||
case "insta": {
|
||||
|
|
|
|||
BIN
packages/skin-database/data/.DS_Store
vendored
Normal file
BIN
packages/skin-database/data/.DS_Store
vendored
Normal file
Binary file not shown.
|
|
@ -116,7 +116,10 @@ export async function markAsPostedToInstagram(
|
|||
postId: string,
|
||||
url: string
|
||||
): Promise<void> {
|
||||
await knex("instagram_posts").insert({ skin_md5: md5, post_id: postId, url }, []);
|
||||
await knex("instagram_posts").insert(
|
||||
{ skin_md5: md5, post_id: postId, url },
|
||||
[]
|
||||
);
|
||||
}
|
||||
|
||||
// TODO: Also path actor
|
||||
|
|
@ -391,6 +394,28 @@ export async function getSkinToTweet(): Promise<{
|
|||
return { md5: skin.md5, canonicalFilename: path.basename(skin.file_path) };
|
||||
}
|
||||
|
||||
export async function getSkinToPostToInstagram(): Promise<string | null> {
|
||||
// TODO: This does not account for skins that have been both approved and rejected
|
||||
const tweetables = await knex("skins")
|
||||
.leftJoin("skin_reviews", "skin_reviews.skin_md5", "=", "skins.md5")
|
||||
.leftJoin("instagram_posts", "instagram_posts.skin_md5", "=", "skins.md5")
|
||||
.leftJoin("refreshes", "refreshes.skin_md5", "=", "skins.md5")
|
||||
.where({
|
||||
"instagram_posts.id": null,
|
||||
skin_type: 1,
|
||||
"skin_reviews.review": "APPROVED",
|
||||
"refreshes.error": null,
|
||||
})
|
||||
.groupBy("skins.md5")
|
||||
.orderByRaw("random()")
|
||||
.limit(1);
|
||||
const skin = tweetables[0];
|
||||
if (skin == null) {
|
||||
return null;
|
||||
}
|
||||
return skin.md5;
|
||||
}
|
||||
|
||||
export async function getStats(): Promise<{
|
||||
approved: number;
|
||||
rejected: number;
|
||||
|
|
|
|||
|
|
@ -1,13 +1,27 @@
|
|||
import * as Skins from "../data/skins";
|
||||
import * as S3 from "../s3";
|
||||
import { INSTAGRAM_ACCESS_TOKEN, INSTAGRAM_ACCOUNT_ID, TWEET_BOT_CHANNEL_ID } from "../config";
|
||||
import {
|
||||
INSTAGRAM_ACCESS_TOKEN,
|
||||
INSTAGRAM_ACCOUNT_ID,
|
||||
TWEET_BOT_CHANNEL_ID,
|
||||
} from "../config";
|
||||
import { Client } from "discord.js";
|
||||
import sharp from "sharp";
|
||||
import SkinModel from "../data/SkinModel";
|
||||
import UserContext from "../data/UserContext";
|
||||
import fetch from "node-fetch";
|
||||
|
||||
export async function insta(discordClient: Client, md5: string): Promise<void> {
|
||||
export async function insta(
|
||||
discordClient: Client,
|
||||
md5: string | null
|
||||
): Promise<void> {
|
||||
if (md5 == null) {
|
||||
md5 = await Skins.getSkinToPostToInstagram();
|
||||
}
|
||||
if (md5 == null) {
|
||||
console.error("No skins to post to instagram");
|
||||
return;
|
||||
}
|
||||
const url = await post(md5);
|
||||
|
||||
console.log("Going to post to discord");
|
||||
|
|
@ -19,7 +33,6 @@ export async function insta(discordClient: Client, md5: string): Promise<void> {
|
|||
console.log("Posted to discord");
|
||||
}
|
||||
|
||||
|
||||
async function createContent(
|
||||
imageUrl: string,
|
||||
caption: string
|
||||
|
|
@ -133,11 +146,11 @@ async function post(md5: string): Promise<string> {
|
|||
console.log("Publishing content...");
|
||||
const id = await publish(contentId);
|
||||
|
||||
console.log("Getting permalink")
|
||||
console.log("Getting permalink");
|
||||
const permalink = await getPermalink(id);
|
||||
console.log("Permalink", permalink);
|
||||
|
||||
console.log("Marking posted in DB")
|
||||
console.log("Marking posted in DB");
|
||||
await Skins.markAsPostedToInstagram(md5, id, permalink);
|
||||
|
||||
return permalink;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue