mirror of
https://github.com/roleypoly/roleypoly-v1.git
synced 2025-06-17 02:29:10 +00:00
temp commit
This commit is contained in:
parent
e86f7ff68e
commit
6fb39d6c4d
22 changed files with 282 additions and 39 deletions
|
@ -4,6 +4,8 @@ import type DiscordSvc from '../discord'
|
|||
import type ErisClient, { User, Member, Guild } from 'eris'
|
||||
import LRU from 'lru-cache'
|
||||
import logger from '../../logger'
|
||||
// $FlowFixMe
|
||||
import { OrderedSet } from 'immutable'
|
||||
const log = logger(__filename)
|
||||
|
||||
export default class BotFetcher implements IFetcher {
|
||||
|
@ -71,4 +73,31 @@ export default class BotFetcher implements IFetcher {
|
|||
return null
|
||||
}
|
||||
}
|
||||
|
||||
getGuilds = async (): Promise<Guild[]> => {
|
||||
const last: ?string = undefined
|
||||
const limit: number = 100
|
||||
let out = OrderedSet<Guild>()
|
||||
|
||||
try {
|
||||
while (true) {
|
||||
// $FlowFixMe -- last is optional, but typedef isn't.
|
||||
const gl = await this.client.getRESTGuilds(limit, last)
|
||||
|
||||
out = out.union(gl)
|
||||
if (gl.length !== limit) {
|
||||
break
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
log.error('getAllGuilds failed', e)
|
||||
throw e
|
||||
}
|
||||
|
||||
return out.toArray()
|
||||
}
|
||||
|
||||
invalidateGuild (id: string) {
|
||||
this.cache.del(`G:${id}`)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,4 +11,6 @@ export interface IFetcher {
|
|||
getGuild: (id: string) => Promise<?Guild>;
|
||||
|
||||
getMember: (server: string, user: string) => Promise<?Member>;
|
||||
|
||||
getGuilds: () => Promise<Guild[]>;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue