Skip to content

Commit

Permalink
Add getUser()
Browse files Browse the repository at this point in the history
  • Loading branch information
zzarcon committed Apr 13, 2019
1 parent 35b6e8a commit 7ed1f28
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
9 changes: 8 additions & 1 deletion example/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ const run = async () => {
const bot = new LuckyBot(user, pass, {debug: true, cookiePath});

await bot.login();
await likeFollowersPhotos(bot);
await getUser(bot, 'zzarcon');
// await likeFollowersPhotos(bot);
// await likeHashtag(bot);
console.log('CLOSE...');
await bot.close();
Expand All @@ -29,4 +30,10 @@ const likeHashtag = async (bot: LuckyBot) => {
await bot.likePhotos(hastag, {maxLikes: 5});
}

const getUser = async (bot: LuckyBot, username: string) => {
const user = await bot.getUser(username);

console.log(user)
}

run();
6 changes: 5 additions & 1 deletion src/luckybot.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Strategy, MediaLocation, LikeFollowerOptions } from "./strategies/strategy";
import { Strategy, MediaLocation, LikeFollowerOptions, User } from "./strategies/strategy";
import { RestApi } from "./strategies/api";

export interface LuckyBotOptions {
Expand Down Expand Up @@ -48,6 +48,10 @@ export class LuckyBot {
return this.client.likeFollowersPhotos(accountId, options);
}

async getUser(username: string): Promise<User> {
return this.client.getUser(username);
};

async close() {
await this.client.close();
}
Expand Down
12 changes: 12 additions & 0 deletions src/strategies/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,18 @@ export class RestApi implements Strategy {
return totalLikedMedia;
}

async getUser(username: string): Promise<User> {
const {session} = this;
const user = await Client.Account.searchForUser(session, username);

return {
username,
id: user.id,
isPrivate: user.params.isPrivate,
followerCount: user.params.followerCount
}
}

async close() {

}
Expand Down
2 changes: 2 additions & 0 deletions src/strategies/strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export interface User {
id: string;
username: string;
isPrivate: boolean;
followerCount?: number;
}

export interface Strategy {
Expand All @@ -33,6 +34,7 @@ export interface Strategy {
searchLocation(query: string): Promise<MediaLocation>;
searchMediaByLocation(location: MediaLocation): Promise<Media[]>;
getFollowers(accountId: string): Promise<User[]>;
getUser(username: string): Promise<User>;
likeFollowersPhotos(accountId: string, options?: LikeFollowerOptions): Promise<Media[]>;
close(): Promise<void>;
}

0 comments on commit 7ed1f28

Please sign in to comment.