-
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.
fix(discord): now discord notifier shows user list with correct link url
- Loading branch information
Showing
7 changed files
with
91 additions
and
90 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
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
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 was deleted.
Oops, something went wrong.
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,30 +1,36 @@ | ||
/* eslint-disable @typescript-eslint/no-empty-function */ | ||
import pluralize from "pluralize"; | ||
import { TwitterApi, TwitterApiReadOnly } from "twitter-api-v2"; | ||
import { TwitterApiRateLimitPlugin } from "@twitter-api-v2/plugin-rate-limit"; | ||
|
||
import { UserData } from "@repositories/models/user"; | ||
|
||
import { BaseWatcher } from "@watchers/base"; | ||
import { TwitterWatcherOptions } from "@watchers/twitter/types"; | ||
|
||
import { TwitterHelper } from "@watchers/twitter/helper"; | ||
|
||
export class TwitterWatcher extends BaseWatcher<"Twitter"> { | ||
private readonly helper: TwitterHelper; | ||
private readonly twitterClient: TwitterApiReadOnly; | ||
|
||
public constructor({ bearerToken }: TwitterWatcherOptions) { | ||
super("Twitter"); | ||
this.helper = new TwitterHelper(bearerToken); | ||
this.twitterClient = new TwitterApi(bearerToken, { plugins: [new TwitterApiRateLimitPlugin()] }).readOnly; | ||
} | ||
|
||
public async initialize() { | ||
await this.helper.initialize(); | ||
return; | ||
} | ||
public getProfileUrl(user: UserData) { | ||
return `https://twitter.com/${user.userId}`; | ||
} | ||
public async getFollowers() { | ||
const allFollowers = await this.helper.getFollowers(); | ||
|
||
this.logger.verbose("Successfully crawled {} {}", [ | ||
allFollowers.length, | ||
pluralize("follower", allFollowers.length), | ||
]); | ||
protected async getFollowers() { | ||
const followers = await this.twitterClient.v2.followers("1569485307049033729", { | ||
max_results: 1000, | ||
"user.fields": ["id", "name", "username", "profile_image_url"], | ||
}); | ||
|
||
return allFollowers; | ||
return followers.data.map(user => ({ | ||
uniqueId: user.id, | ||
displayName: user.name, | ||
userId: user.username, | ||
})); | ||
} | ||
} |