mirror of
https://github.com/captbaritone/webamp.git
synced 2026-07-22 17:47:16 +00:00
Alert on follower count milestones
This commit is contained in:
parent
4738bcc3c2
commit
83d18ed9b7
5 changed files with 48 additions and 5 deletions
|
|
@ -131,6 +131,12 @@ export default class DiscordEventHandler {
|
|||
await dest.send(message);
|
||||
break;
|
||||
}
|
||||
case "TWEET_BOT_MILESTONE": {
|
||||
const dest = await this.getChannel(Config.POPULAR_TWEETS_CHANNEL_ID);
|
||||
const message = `🎉 Tweet Bot Milestone! Just passed ${action.bracket.toLocaleString()} Followers 🎉`;
|
||||
await dest.send(message);
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -23,7 +23,8 @@ export type ApiAction =
|
|||
| { type: "GOT_FEEDBACK"; message: string; email?: string; url?: string }
|
||||
| { type: "SYNCED_TO_ARCHIVE"; successes: number; errors: number }
|
||||
| { type: "STARTED_SYNC_TO_ARCHIVE"; count: number }
|
||||
| { type: "POPULAR_TWEET"; bracket: number; url: string, likes: number, date: Date };
|
||||
| { type: "POPULAR_TWEET"; bracket: number; url: string, likes: number, date: Date }
|
||||
| { type: "TWEET_BOT_MILESTONE"; bracket: number; count: number};
|
||||
|
||||
export type EventHandler = (event: ApiAction) => void;
|
||||
export type Logger = {
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ import md5Buffer from "md5";
|
|||
import { addSkinFromBuffer } from "./addSkin";
|
||||
import { searchIndex } from "./algolia";
|
||||
import { scrapeLikeData } from "./tasks/scrapeLikes";
|
||||
import {popularTweets} from "./tasks/popularTweets"
|
||||
import {followerCount, popularTweets} from "./tasks/tweetMilestones"
|
||||
import UserContext from "./data/UserContext";
|
||||
import { integrityCheck } from "./tasks/integrityCheck";
|
||||
import { ensureWebampLinks, syncWithArchive } from "./tasks/syncWithArchive";
|
||||
|
|
@ -25,9 +25,6 @@ import _temp from "temp";
|
|||
import Shooter from "./shooter";
|
||||
import rl from "readline";
|
||||
|
||||
import _temp from "temp";
|
||||
import Shooter from "./shooter";
|
||||
|
||||
const temp = _temp.track();
|
||||
|
||||
async function main() {
|
||||
|
|
@ -205,6 +202,11 @@ async function main() {
|
|||
break;
|
||||
}
|
||||
|
||||
case "follower-count": {
|
||||
await followerCount(handler);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
console.log(`Unknown command ${argv._[0]}`);
|
||||
}
|
||||
|
|
|
|||
1
packages/skin-database/followerCount.json
Normal file
1
packages/skin-database/followerCount.json
Normal file
|
|
@ -0,0 +1 @@
|
|||
10000
|
||||
|
|
@ -90,3 +90,36 @@ export async function popularTweets(handler: DiscordEventHandler) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
const FOLLOW_COUNT_FILE_NAME = "./followerCount.json";
|
||||
const FOLLOW_COUNT_BRACKET_SIZE = 1000;
|
||||
|
||||
export async function followerCount(handler: DiscordEventHandler) {
|
||||
const twitterClient = getTwitterClient();
|
||||
|
||||
const response = await twitterClient.get("users/show", {
|
||||
screen_name: "winampskins",
|
||||
});
|
||||
const user = response.data;
|
||||
|
||||
const followerCount = user.followers_count;
|
||||
const currentJSON = fs.readFileSync(FOLLOW_COUNT_FILE_NAME, "utf8");
|
||||
const current: { count: number } = JSON.parse(currentJSON);
|
||||
const currentNumber = current.count;
|
||||
|
||||
const nextMilestone = currentNumber + FOLLOW_COUNT_BRACKET_SIZE;
|
||||
|
||||
if (followerCount > nextMilestone) {
|
||||
await handler.handle({
|
||||
type: "TWEET_BOT_MILESTONE",
|
||||
bracket: nextMilestone,
|
||||
count: followerCount,
|
||||
});
|
||||
fs.writeFileSync(
|
||||
FOLLOW_COUNT_FILE_NAME,
|
||||
JSON.stringify({ count: nextMilestone }, null, 2)
|
||||
);
|
||||
} else {
|
||||
console.log(`Not notifying: ${followerCount} < ${nextMilestone}`);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue