mirror of
https://github.com/roleypoly/roleypoly-v1.git
synced 2025-06-15 01:49:10 +00:00
sync
This commit is contained in:
parent
13cd3bd4a0
commit
52cb96baa3
43 changed files with 3257 additions and 1072 deletions
|
@ -46,13 +46,15 @@ class DiscordService extends Service {
|
|||
})
|
||||
}
|
||||
|
||||
presentableRoles (serverId) {
|
||||
return this.client.guilds.get(serverId).roles.map((role) => {
|
||||
presentableRoles (serverId, gm) {
|
||||
return this.client.guilds.get(serverId).roles.filter(r => r.id !== serverId).map((role) => {
|
||||
return {
|
||||
color: role.hexColor,
|
||||
position: role.calculatedPosition,
|
||||
position: role.position,
|
||||
calculatedPosition: role.calculatedPosition,
|
||||
id: role.id,
|
||||
|
||||
name: role.name,
|
||||
selected: gm.roles.has(role.id)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -71,6 +73,7 @@ class DiscordService extends Service {
|
|||
const rsp =
|
||||
await superagent
|
||||
.post(url)
|
||||
.set('Content-Type', 'application/x-www-form-urlencoded')
|
||||
.send({
|
||||
client_id: this.clientId,
|
||||
client_secret: this.clientSecret,
|
||||
|
@ -86,6 +89,20 @@ class DiscordService extends Service {
|
|||
}
|
||||
}
|
||||
|
||||
async getUser (authToken) {
|
||||
const url = 'https://discordapp.com/api/v6/users/@me'
|
||||
try {
|
||||
const rsp =
|
||||
await superagent
|
||||
.get(url)
|
||||
.set('Authorization', `Bearer ${authToken}`)
|
||||
return rsp.body
|
||||
} catch (e) {
|
||||
this.log.error('getUser error', e)
|
||||
throw e
|
||||
}
|
||||
}
|
||||
|
||||
// on sign out, we revoke the token we had.
|
||||
// async revokeAuthToken (code, state) {
|
||||
// const url = 'https://discordapp.com/api/oauth2/revoke'
|
||||
|
@ -119,7 +136,6 @@ class DiscordService extends Service {
|
|||
getBotJoinUrl () {
|
||||
return `https://discordapp.com/oauth2/authorize?client_id=${this.clientId}&scope=bot&permissions=268435456&redirect_uri=${this.botCallback}`
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = DiscordService
|
||||
|
|
37
Server/services/sessions.js
Normal file
37
Server/services/sessions.js
Normal file
|
@ -0,0 +1,37 @@
|
|||
const Service = require('./Service')
|
||||
|
||||
class SessionsService extends Service {
|
||||
constructor (ctx) {
|
||||
super(ctx)
|
||||
this.Session = ctx.M.Session
|
||||
}
|
||||
|
||||
async get (id) {
|
||||
const user = await this.Session.findOne({ where: { id } })
|
||||
|
||||
if (user === null) {
|
||||
return null
|
||||
}
|
||||
|
||||
return user.data
|
||||
}
|
||||
|
||||
async set (id, data, maxAge) {
|
||||
let session = await this.Session.findOne({ where: { id } })
|
||||
if (session === null) {
|
||||
session = this.Session.build({ id })
|
||||
}
|
||||
|
||||
session.data = data
|
||||
session.maxAge = maxAge
|
||||
|
||||
return session.save()
|
||||
}
|
||||
|
||||
async destroy (id) {
|
||||
return (await this.Session.findOne({ where: { id } })).destroy()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = SessionsService
|
Loading…
Add table
Add a link
Reference in a new issue