mirror of
https://github.com/roleypoly/roleypoly-v1.git
synced 2025-06-15 01:49:10 +00:00
fix redirects, fix server syncs on join
This commit is contained in:
parent
032831aff1
commit
f7238ab091
14 changed files with 132 additions and 101 deletions
|
@ -7,7 +7,7 @@ module.exports = (R, $) => {
|
|||
|
||||
ctx.body = presentable
|
||||
} catch (e) {
|
||||
console.error(e.trace)
|
||||
console.error(e.trace || e.stack)
|
||||
}
|
||||
})
|
||||
|
||||
|
@ -29,6 +29,23 @@ module.exports = (R, $) => {
|
|||
ctx.body = server
|
||||
})
|
||||
|
||||
R.get('/api/server/:id/slug', async (ctx) => {
|
||||
const { userId } = ctx.session
|
||||
const { id } = ctx.params
|
||||
|
||||
const srv = $.discord.client.guilds.get(id)
|
||||
|
||||
console.log(srv)
|
||||
|
||||
if (srv == null) {
|
||||
ctx.body = { err: 'not found' }
|
||||
ctx.status = 404
|
||||
return
|
||||
}
|
||||
|
||||
ctx.body = await $.P.serverSlug(srv)
|
||||
})
|
||||
|
||||
R.patch('/api/server/:id', async (ctx) => {
|
||||
const { userId } = ctx.session
|
||||
const { id } = ctx.params
|
||||
|
|
|
@ -34,6 +34,7 @@ class DiscordService extends Service {
|
|||
if (this.isBot) {
|
||||
this.log.info('this roleypoly is a bot')
|
||||
this.client.on('message', this.handleMessage.bind(this))
|
||||
this.client.on('guildCreate', this.handleJoin.bind(this))
|
||||
}
|
||||
|
||||
for (let server of this.client.guilds.array()) {
|
||||
|
@ -216,6 +217,10 @@ class DiscordService extends Service {
|
|||
}
|
||||
}
|
||||
|
||||
async handleJoin (guild) {
|
||||
await this.ctx.server.ensure(guild)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = DiscordService
|
||||
|
|
|
@ -10,6 +10,15 @@ class PresentationService extends Service {
|
|||
this.cache = LRU({ max: 500, maxAge: 100 * 60 * 5 })
|
||||
}
|
||||
|
||||
serverSlug (server) {
|
||||
return {
|
||||
id: server.id,
|
||||
name: server.name,
|
||||
ownerID: server.ownerID,
|
||||
icon: server.icon
|
||||
}
|
||||
}
|
||||
|
||||
async oldPresentableServers (collection, userId) {
|
||||
let servers = []
|
||||
|
||||
|
@ -39,12 +48,7 @@ class PresentationService extends Service {
|
|||
nickname: gm.nickname,
|
||||
color: gm.displayHexColor
|
||||
},
|
||||
server: {
|
||||
id: server.id,
|
||||
name: server.name,
|
||||
ownerID: server.ownerID,
|
||||
icon: server.icon
|
||||
},
|
||||
server: this.serverSlug(server),
|
||||
roles: (incRoles) ? (await this.rolesByServer(server, sd)).map(r => ({ ...r, selected: gm.roles.has(r.id) })) : [],
|
||||
message: sd.message,
|
||||
categories: sd.categories,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue