mirror of
https://github.com/roleypoly/roleypoly-v1.git
synced 2025-06-17 10:39:09 +00:00
lerna: split up bulk of packages
This commit is contained in:
parent
cb0b1d2410
commit
47a2e5694e
90 changed files with 0 additions and 0 deletions
48
packages/roleypoly-server/rpc/servers.js
Normal file
48
packages/roleypoly-server/rpc/servers.js
Normal file
|
@ -0,0 +1,48 @@
|
|||
// @flow
|
||||
import { type AppContext } from '../Roleypoly'
|
||||
import { type Context } from 'koa'
|
||||
import { type Guild } from 'eris'
|
||||
import * as secureAs from './_security'
|
||||
|
||||
export default ($: AppContext) => ({
|
||||
|
||||
rootGetAllServers: secureAs.root($, (ctx: Context) => {
|
||||
return $.discord.client.guilds.map<{
|
||||
url: string,
|
||||
name: string,
|
||||
members: number,
|
||||
roles: number
|
||||
}>((g: Guild) => ({ url: `${$.config.appUrl}/s/${g.id}`, name: g.name, members: g.memberCount, roles: g.roles.size }))
|
||||
}),
|
||||
|
||||
getServerSlug (ctx: Context, id: string) {
|
||||
const srv = $.discord.client.guilds.get(id)
|
||||
if (srv == null) {
|
||||
return null
|
||||
}
|
||||
|
||||
return $.P.serverSlug(srv)
|
||||
},
|
||||
|
||||
getServer: secureAs.member($, (ctx: Context, id: string) => {
|
||||
const { userId } = (ctx.session: { userId: string })
|
||||
|
||||
const srv = $.discord.client.guilds.get(id)
|
||||
if (srv == null) {
|
||||
return { err: 'not_found' }
|
||||
}
|
||||
|
||||
let gm
|
||||
if (srv.members.has(userId)) {
|
||||
gm = $.discord.gm(id, userId)
|
||||
} else if ($.discord.isRoot(userId)) {
|
||||
gm = $.discord.fakeGm({ id: userId })
|
||||
}
|
||||
|
||||
if (gm == null) {
|
||||
return { err: 'not_found' }
|
||||
}
|
||||
|
||||
return $.P.presentableServer(srv, gm)
|
||||
})
|
||||
})
|
Loading…
Add table
Add a link
Reference in a new issue