mirror of
https://github.com/roleypoly/roleypoly-v1.git
synced 2025-06-17 02:29:10 +00:00
lerna: complete refactor!
This commit is contained in:
parent
51dd8bd6b1
commit
e1bd5747b3
12 changed files with 83 additions and 71 deletions
|
@ -11,14 +11,14 @@ export default (ctx: AppContext, forceClear: ?boolean = false): {
|
|||
[rpc: string]: Function
|
||||
} => {
|
||||
let map = {}
|
||||
const apis = glob.sync(`./rpc/**/!(index).js`)
|
||||
const apis = glob.sync(`${__dirname}/**/!(index).js`).map(v => v.replace(__dirname, '.'))
|
||||
log.debug('found rpcs', apis)
|
||||
|
||||
for (let a of apis) {
|
||||
const filename = path.basename(a)
|
||||
const dirname = path.dirname(a)
|
||||
|
||||
const pathname = a.replace('rpc/', '')
|
||||
const pathname = a
|
||||
delete require.cache[require.resolve(pathname)]
|
||||
|
||||
// internal stuff
|
||||
|
|
|
@ -95,12 +95,12 @@ export const member = (
|
|||
$: AppContext,
|
||||
fn: (ctx: Context, server: string, ...args: any[]) => any,
|
||||
silent: boolean = false
|
||||
) => authed($, (
|
||||
) => authed($, async (
|
||||
ctx: Context,
|
||||
server: string,
|
||||
...args: any[]
|
||||
) => {
|
||||
if ($.discord.isMember(server, ctx.session.userId)) {
|
||||
if (await $.discord.isMember(server, ctx.session.userId)) {
|
||||
return fn(ctx, server, ...args)
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ import { type AppContext } from '../Roleypoly'
|
|||
import { type Context } from 'koa'
|
||||
import { type Guild } from 'eris'
|
||||
import * as secureAs from './_security'
|
||||
import RPCError from './_error'
|
||||
|
||||
export default ($: AppContext) => ({
|
||||
|
||||
|
@ -24,23 +25,18 @@ export default ($: AppContext) => ({
|
|||
return $.P.serverSlug(srv)
|
||||
},
|
||||
|
||||
getServer: secureAs.member($, (ctx: Context, id: string) => {
|
||||
getServer: secureAs.member($, async (ctx: Context, id: string) => {
|
||||
const { userId } = (ctx.session: { userId: string })
|
||||
|
||||
const srv = $.discord.client.guilds.get(id)
|
||||
const srv = await $.discord.fetcher.getGuild(id)
|
||||
if (srv == null) {
|
||||
return { err: 'not_found' }
|
||||
throw new RPCError('server not found', 404)
|
||||
}
|
||||
|
||||
let gm
|
||||
if (srv.members.has(userId)) {
|
||||
gm = $.discord.gm(id, userId)
|
||||
} else if ($.discord.isRoot(userId)) {
|
||||
gm = $.discord.fakeGm({ id: userId })
|
||||
}
|
||||
let gm = await $.discord.gm(id, userId, { canFake: true })
|
||||
|
||||
if (gm == null) {
|
||||
return { err: 'not_found' }
|
||||
throw new RPCError('server not found', 404)
|
||||
}
|
||||
|
||||
return $.P.presentableServer(srv, gm)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue