This commit is contained in:
41666 2017-12-10 03:56:41 -06:00
parent 13cd3bd4a0
commit 52cb96baa3
43 changed files with 3257 additions and 1072 deletions

View file

@ -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

View 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