init starset feed algo

This commit is contained in:
CDN18 2024-11-28 14:40:15 +08:00
parent adf8c379f5
commit c918f652ea
Signed by: CDN
GPG key ID: 0C656827F9F80080
5 changed files with 53 additions and 12 deletions

View file

@ -3,12 +3,12 @@ import {
QueryParams, QueryParams,
OutputSchema as AlgoOutput, OutputSchema as AlgoOutput,
} from '../lexicon/types/app/bsky/feed/getFeedSkeleton' } from '../lexicon/types/app/bsky/feed/getFeedSkeleton'
import * as whatsAlf from './whats-alf' import * as starset from './starset'
type AlgoHandler = (ctx: AppContext, params: QueryParams) => Promise<AlgoOutput> type AlgoHandler = (ctx: AppContext, params: QueryParams) => Promise<AlgoOutput>
const algos: Record<string, AlgoHandler> = { const algos: Record<string, AlgoHandler> = {
[whatsAlf.shortname]: whatsAlf.handler, [starset.shortname]: starset.handler,
} }
export default algos export default algos

View file

@ -2,7 +2,7 @@ import { QueryParams } from '../lexicon/types/app/bsky/feed/getFeedSkeleton'
import { AppContext } from '../config' import { AppContext } from '../config'
// max 15 chars // max 15 chars
export const shortname = 'whats-alf' export const shortname = 'starset'
export const handler = async (ctx: AppContext, params: QueryParams) => { export const handler = async (ctx: AppContext, params: QueryParams) => {
let builder = ctx.db let builder = ctx.db

BIN
src/assets/sst-logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.4 KiB

31
src/filter.ts Normal file
View file

@ -0,0 +1,31 @@
export const keywords = ['starset', 'starsetonline']
export const users = [
'did:plc:aaa5q4evo6nnn35bjwuekdkh', // @mirror.starset.fans
]
export const bandMembers = [
'dustin bates', 'ron dechant', 'brock richards', 'adam gilbert'
]
export const albums = [
'transmissions', 'vessels', 'divisions', 'horizons'
]
export const songs = [
// transmissions
'first light', 'down with the fallen', 'halo', 'carnivore', 'telescope',
'it has begun', 'my demons', 'antigravity', 'dark on me', 'let it die',
'the future is now', 'point of no return', 'rise and fall',
// vessels
'the order', 'satellite', 'frequency', 'die for you', 'ricochet', 'starlight',
'into the unknown', 'gravity of you', 'back to the earth', 'last to fall',
'bringing it down', 'unbecoming', 'monster', 'telepathic', 'everglow',
// divisions
'a brief history of the future', 'manifest', 'echo', 'where the skies end',
'perfect machine', 'telekinetic', 'stratosphere', 'faultline', 'solstice',
'trials', 'waking up', 'other worlds than these', 'diving bell',
// horizons
'unveiling the architecture', 'the breach', 'otherworldly', 'icarus',
'earthrise', 'leaving this world behind', 'devolution', 'annihilated love',
'alchemy', 'disappear', 'this endless endeavor', 'symbiotic', 'dreamcatcher',
'tunnelvision', 'infected', 'something wicked',
// s5
'brave new world', 'degenerate', 'toksik', 'dystopia'
]

View file

@ -3,6 +3,7 @@ import {
isCommit, isCommit,
} from './lexicon/types/com/atproto/sync/subscribeRepos' } from './lexicon/types/com/atproto/sync/subscribeRepos'
import { FirehoseSubscriptionBase, getOpsByType } from './util/subscription' import { FirehoseSubscriptionBase, getOpsByType } from './util/subscription'
import { keywords, users, bandMembers, albums, songs } from './filter'
export class FirehoseSubscription extends FirehoseSubscriptionBase { export class FirehoseSubscription extends FirehoseSubscriptionBase {
async handleEvent(evt: RepoEvent) { async handleEvent(evt: RepoEvent) {
@ -10,21 +11,30 @@ export class FirehoseSubscription extends FirehoseSubscriptionBase {
const ops = await getOpsByType(evt) const ops = await getOpsByType(evt)
// This logs the text of every post off the firehose. // Test only
// Just for fun :) // for (const post of ops.posts.creates) {
// Delete before actually using // console.log('DEBUG: New Post')
for (const post of ops.posts.creates) { // console.log('DEBUG: Author', post.author)
console.log(post.record.text) // console.log('DEBUG: Text', post.record.text)
} // console.log('DEBUG: Tags', post.record.tags)
// }
const postsToDelete = ops.posts.deletes.map((del) => del.uri) const postsToDelete = ops.posts.deletes.map((del) => del.uri)
const postsToCreate = ops.posts.creates const postsToCreate = ops.posts.creates
.filter((create) => { .filter((create) => {
// only alf-related posts const text = create.record.text.toLowerCase()
return create.record.text.toLowerCase().includes('alf') const tags = create.record.tags?.map(tag => tag.toLowerCase()) || []
const author = create.author || ''
return (
keywords.some(keyword => text.includes(keyword)) ||
users.includes(author) ||
bandMembers.some(member => text.includes(member)) ||
albums.some(album => text.includes(album)) ||
songs.some(song => text.includes(song))
)
}) })
.map((create) => { .map((create) => {
// map alf-related posts to a db row
return { return {
uri: create.uri, uri: create.uri,
cid: create.cid, cid: create.cid,