code diff twitch follows

Created Diff never expires
3 removals
53 lines
1 addition
53 lines
import common from "../common-polling.mjs";
import common from "../common-polling.mjs";


export default {
export default {
...common,
...common,
name: "New Follower (Instant)",
name: "New Follower (Instant)",
key: "twitch-new-follower",
key: "twitch-new-follower",
description: "Emit new event when a new user follows your channel.",
description: "Emit new event when a new user follows your channel.",
type: "source",
type: "source",
version: "0.0.4",
version: "0.0.4",
methods: {
methods: {
...common.methods,
...common.methods,
async getTopics() {
async getTopics() {
// get the authenticated user
// get the authenticated user
const { data } = await this.twitch.getUsers();
const { data } = await this.twitch.getUsers();
return [
return [
`users/follows?first=1&to_id=${data[0].id}`,
`users/follows?first=1&to_id=${data[0].id}`,
];
];
},
},
getMeta(item) {
getMeta(item) {
const {
const {
from_id, to_id, followed_at, from_name,
to_id, followed_at, from_name,
} = item;
} = item;


return {
return {
id: from_id + to_id + followed_at,
id: to_id + followed_at,
summary: `${from_name} is a new follower`,
summary: `${from_name} is a new follower`,
ts: new Date(followed_at).getTime(),
ts: new Date(followed_at).getTime(),
};
};
},
},
},
},
hooks: {
hooks: {
async deploy() {
async deploy() {
// get the authenticated user
// get the authenticated user
const { data: authenticatedUserData } = await this.twitch.getUsers();
const { data: authenticatedUserData } = await this.twitch.getUsers();
this.db.set("authenticatedUserId", authenticatedUserData[0].id);
this.db.set("authenticatedUserId", authenticatedUserData[0].id);
},
},
},
},
async run() {
async run() {
const params = {
const params = {
from_id: this.db.get("authenticatedUserId"),
to_id: this.db.get("authenticatedUserId"),
};
};
// get the user_ids of the streamers followed by the authenticated user
// get the user_ids of the streamers followed by the authenticated user
const follows = this.paginate(
const follows = this.paginate(
this.twitch.getUserFollows.bind(this),
this.twitch.getUserFollows.bind(this),
params,
params,
);
);


for await (const follow of follows) {
for await (const follow of follows) {
this.$emit(follow, this.getMeta(follow));
this.$emit(follow, this.getMeta(follow));
}
}
},
},
};
};