mirror of
https://github.com/roleypoly/roleypoly-v1.git
synced 2025-04-25 04:09:12 +00:00
fake guildmember for root users
This commit is contained in:
parent
96d91caba0
commit
8599929531
2 changed files with 49 additions and 1 deletions
|
@ -23,7 +23,16 @@ module.exports = (R, $) => {
|
|||
return
|
||||
}
|
||||
|
||||
const gm = $.discord.gm(id, userId)
|
||||
let gm
|
||||
if (srv.members.has(userId)) {
|
||||
gm = $.discord.gm(id, userId)
|
||||
} else if ($.discord.isRoot(userId)) {
|
||||
gm = $.discord.fakeGm({ id: userId })
|
||||
} else {
|
||||
ctx.body = { err: 'not_a_member' }
|
||||
ctx.status = 400
|
||||
return
|
||||
}
|
||||
const server = await $.P.presentableServer(srv, gm)
|
||||
|
||||
ctx.body = server
|
||||
|
@ -49,7 +58,11 @@ module.exports = (R, $) => {
|
|||
R.patch('/api/server/:id', async (ctx) => {
|
||||
const { userId } = ctx.session
|
||||
const { id } = ctx.params
|
||||
|
||||
let gm = $.discord.gm(id, userId)
|
||||
if (gm == null && $.discord.isRoot(userId)) {
|
||||
gm = $.discord.fakeGm({ id: userId })
|
||||
}
|
||||
|
||||
// check perms
|
||||
if (!$.discord.getPermissions(gm).canManageRoles) {
|
||||
|
@ -69,10 +82,30 @@ module.exports = (R, $) => {
|
|||
ctx.body = { ok: true }
|
||||
})
|
||||
|
||||
R.get('/api/admin/servers', async ctx => {
|
||||
const { userId } = ctx.session
|
||||
if (!$.discord.isRoot(userId)) {
|
||||
return
|
||||
}
|
||||
|
||||
ctx.body = $.discord.client.guilds.map(g => ({ url: `${process.env.APP_URL}/s/${g.id}`, name: g.name, members: g.members.array().length, roles: g.roles.array().length }))
|
||||
})
|
||||
|
||||
R.patch('/api/servers/:server/roles', async ctx => {
|
||||
const { userId } = ctx.session
|
||||
const { server } = ctx.params
|
||||
|
||||
let gm = $.discord.gm(server, userId)
|
||||
if (gm == null && $.discord.isRoot(userId)) {
|
||||
gm = $.discord.fakeGm({ id: userId })
|
||||
}
|
||||
|
||||
// check perms
|
||||
// if (!$.discord.getPermissions(gm).canManageRoles) {
|
||||
// ctx.status = 403
|
||||
// ctx.body = { err: 'cannot_manage_roles' }
|
||||
// return
|
||||
// }
|
||||
|
||||
const { added, removed } = ctx.request.body
|
||||
|
||||
|
|
|
@ -27,6 +27,14 @@ class DiscordService extends Service {
|
|||
return this.gm(server, this.client.user.id)
|
||||
}
|
||||
|
||||
fakeGm({id = 0, nickname = '[none]', displayHexColor = '#ffffff'}) {
|
||||
return { id, nickname, displayHexColor, __faked: true, roles: { has() {return false} } }
|
||||
}
|
||||
|
||||
isRoot(id) {
|
||||
return this.rootUsers.has(id)
|
||||
}
|
||||
|
||||
async startBot () {
|
||||
await this.client.login(this.botToken)
|
||||
|
||||
|
@ -55,6 +63,13 @@ class DiscordService extends Service {
|
|||
}
|
||||
|
||||
getPermissions (gm) {
|
||||
if (this.isRoot(gm.id)) {
|
||||
return {
|
||||
isAdmin: true,
|
||||
canManageRoles: true
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
isAdmin: gm.permissions.hasPermission('ADMINISTRATOR'),
|
||||
canManageRoles: gm.permissions.hasPermission('MANAGE_ROLES', false, true)
|
||||
|
|
Loading…
Add table
Reference in a new issue