-
Notifications
You must be signed in to change notification settings - Fork 5
/
club.ts
133 lines (112 loc) · 3.67 KB
/
club.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import { Client } from '../core/client'
import { BaseClass, BaseResource } from './base'
import { AnimeMeta, CharacterMeta, MangaMeta } from './meta'
import { ImageFormatCollection } from './misc'
export type ClubCategory =
| 'ActorsAndArtists'
| 'Anime'
| 'Characters'
| 'CitiesAndNeighborhoods'
| 'Companies'
| 'Conventions'
| 'Games'
| 'Japan'
| 'Manga'
| 'Music'
| 'Others'
| 'Schools'
| 'None'
| 'Unknown'
export type ClubType =
| 'Public'
| 'Private'
| 'Secret'
| 'Unknown'
export class Club extends BaseResource {
/** @hidden */
public static parseCategory (input: any): ClubCategory {
switch (input?.toLowerCase().trim()) {
case 'actors & artists': return 'ActorsAndArtists'
case 'anime': return 'Anime'
case 'characters': return 'Characters'
case 'cities & neighborhoods': return 'CitiesAndNeighborhoods'
case 'companies': return 'Companies'
case 'conventions': return 'Conventions'
case 'games': return 'Games'
case 'japan': return 'Japan'
case 'manga': return 'Manga'
case 'music': return 'Music'
case 'other':
case 'others': return 'Others'
case 'schools': return 'Schools'
case 'none': return 'None'
default: return 'Unknown'
}
}
/** @hidden */
public static parseType (input: any): ClubType {
switch (input?.toLowerCase().trim()) {
case 'public': return 'Public'
case 'private': return 'Private'
case 'secret': return 'Secret'
default: return 'Unknown'
}
}
public readonly image: ImageFormatCollection | null
public readonly memberCount: number
public readonly pictureCount: number
public readonly category: ClubCategory
public readonly created: Date
public readonly type: ClubType
public readonly staff: Array<ClubStaff>
public getMembers () {
return <Promise<Array<ClubMember>>> this.client.clubs.getMembers(this.id)
}
public getStaff () {
return <Promise<Array<ClubStaff>>> this.client.clubs.getStaff(this.id)
}
public getRelations () {
return <Promise<ClubRelations>> this.client.clubs.getRelations(this.id)
}
public constructor (client: Client, data: any) {
super(client, data)
this.image = data.images != null ? new ImageFormatCollection(client, data.images) : null
this.memberCount = data.members_count
this.pictureCount = data.pictures_count
this.category = Club.parseCategory(data.category)
this.created = Club.parseDate(data.created)
this.type = Club.parseType(data.type)
this.staff = data.staff?.map((staff: any) => new ClubStaff(client, staff)) || []
}
}
export class ClubStaff extends BaseClass {
public readonly url: URL
public readonly username: string
public constructor (client: Client, data: any) {
super(client)
this.url = ClubStaff.parseURL(data.url)
this.username = data.username
}
}
export class ClubMember extends BaseClass {
public readonly URL: URL
public readonly username: string
public readonly imageURL: URL | null
public constructor (client: Client, data: any) {
super(client)
this.URL = ClubMember.parseURL(data.url)
this.username = data.username
this.imageURL = ClubMember.parseURL(data.image_url, true)
}
}
export class ClubRelations extends BaseClass {
public readonly anime: Array<AnimeMeta>
public readonly manga: Array<MangaMeta>
public readonly characters: Array<CharacterMeta>
public constructor (client: Client, data: any) {
super(client)
this.anime = data.map((anime: any) => new AnimeMeta(client, anime))
this.manga = data.map((manga: any) => new MangaMeta(client, manga))
this.characters = data.map((character: any) => new CharacterMeta(client, character))
}
}