mirror of
https://github.com/roleypoly/roleypoly-v1.git
synced 2025-04-24 19:59:12 +00:00
add server list connection to discord
This commit is contained in:
parent
6840446cdf
commit
13cd3bd4a0
13 changed files with 138 additions and 34 deletions
BIN
API.paw
Normal file
BIN
API.paw
Normal file
Binary file not shown.
14
Server/api/servers_test.js
Normal file
14
Server/api/servers_test.js
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
module.exports = (R, $) => {
|
||||||
|
R.get('/api/~/relevant-servers/:user', (ctx, next) => {
|
||||||
|
// ctx.body = 'ok'
|
||||||
|
const srv = $.discord.getRelevantServers(ctx.params.user)
|
||||||
|
ctx.body = $.discord.presentableServers(srv, ctx.params.user)
|
||||||
|
return
|
||||||
|
})
|
||||||
|
|
||||||
|
R.get('/api/~/roles/:server', (ctx, next) => {
|
||||||
|
// ctx.body = 'ok'
|
||||||
|
ctx.body = $.discord.getRoles(ctx.params.server)
|
||||||
|
return
|
||||||
|
})
|
||||||
|
}
|
|
@ -29,7 +29,7 @@
|
||||||
"pg": "^7.4.0",
|
"pg": "^7.4.0",
|
||||||
"pg-hstore": "^2.3.2",
|
"pg-hstore": "^2.3.2",
|
||||||
"pm2": "^2.8.0",
|
"pm2": "^2.8.0",
|
||||||
"sequelize": "^4.25.1",
|
"sequelize": "^4.26.0",
|
||||||
"socket.io": "^2.0.4",
|
"socket.io": "^2.0.4",
|
||||||
"standard": "^10.0.3",
|
"standard": "^10.0.3",
|
||||||
"superagent": "^3.8.1",
|
"superagent": "^3.8.1",
|
||||||
|
|
|
@ -10,13 +10,58 @@ class DiscordService extends Service {
|
||||||
this.clientId = process.env.DISCORD_CLIENT_ID
|
this.clientId = process.env.DISCORD_CLIENT_ID
|
||||||
this.clientSecret = process.env.DISCORD_CLIENT_SECRET
|
this.clientSecret = process.env.DISCORD_CLIENT_SECRET
|
||||||
this.oauthCallback = process.env.OAUTH_AUTH_CALLBACK
|
this.oauthCallback = process.env.OAUTH_AUTH_CALLBACK
|
||||||
this.botCallback = `${ctx.config.appUrl}/oauth/bot/callback`
|
this.botCallback = `${ctx.config.appUrl}/api/oauth/bot/callback`
|
||||||
|
|
||||||
|
this.client = new discord.Client()
|
||||||
|
|
||||||
this.startBot()
|
this.startBot()
|
||||||
}
|
}
|
||||||
|
|
||||||
async startBot () {
|
async startBot () {
|
||||||
await discord.login(this.botToken)
|
await this.client.login(this.botToken)
|
||||||
|
}
|
||||||
|
|
||||||
|
getRelevantServers (userId) {
|
||||||
|
return this.client.guilds.filter((g) => g.members.has(userId))
|
||||||
|
}
|
||||||
|
|
||||||
|
presentableServers (collection, userId) {
|
||||||
|
return collection.map((server) => {
|
||||||
|
const gm = server.members.get(userId)
|
||||||
|
|
||||||
|
return {
|
||||||
|
id: server.id,
|
||||||
|
gm: {
|
||||||
|
nickname: gm.nickname,
|
||||||
|
color: gm.displayHexColor
|
||||||
|
},
|
||||||
|
server: {
|
||||||
|
id: server.id,
|
||||||
|
name: server.name,
|
||||||
|
ownerID: server.ownerID,
|
||||||
|
icon: server.icon
|
||||||
|
},
|
||||||
|
perms: this.getPermissions(gm)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
presentableRoles (serverId) {
|
||||||
|
return this.client.guilds.get(serverId).roles.map((role) => {
|
||||||
|
return {
|
||||||
|
color: role.hexColor,
|
||||||
|
position: role.calculatedPosition,
|
||||||
|
id: role.id,
|
||||||
|
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
getPermissions (gm) {
|
||||||
|
return {
|
||||||
|
isAdmin: gm.permissions.hasPermission('ADMINISTRATOR'),
|
||||||
|
canManageRoles: gm.permissions.hasPermission('MANAGE_ROLES', false, true)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// oauth step 2 flow, grab the auth token via code
|
// oauth step 2 flow, grab the auth token via code
|
||||||
|
@ -42,31 +87,31 @@ class DiscordService extends Service {
|
||||||
}
|
}
|
||||||
|
|
||||||
// on sign out, we revoke the token we had.
|
// on sign out, we revoke the token we had.
|
||||||
async revokeAuthToken (code, state) {
|
// async revokeAuthToken (code, state) {
|
||||||
const url = 'https://discordapp.com/api/oauth2/revoke'
|
// const url = 'https://discordapp.com/api/oauth2/revoke'
|
||||||
try {
|
// try {
|
||||||
const rsp =
|
// const rsp =
|
||||||
await superagent
|
// await superagent
|
||||||
.post(url)
|
// .post(url)
|
||||||
.send({
|
// .send({
|
||||||
client_id: this.clientId,
|
// client_id: this.clientId,
|
||||||
client_secret: this.clientSecret,
|
// client_secret: this.clientSecret,
|
||||||
grant_type: 'authorization_code',
|
// grant_type: 'authorization_code',
|
||||||
code: code,
|
// code: code,
|
||||||
redirect_uri: this.oauthCallback
|
// redirect_uri: this.oauthCallback
|
||||||
})
|
// })
|
||||||
|
|
||||||
return rsp.body
|
// return rsp.body
|
||||||
} catch (e) {
|
// } catch (e) {
|
||||||
this.log.error('getAuthToken failed', e)
|
// this.log.error('getAuthToken failed', e)
|
||||||
throw e
|
// throw e
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
// returns oauth authorize url with IDENTIFY permission
|
// returns oauth authorize url with IDENTIFY permission
|
||||||
// we only need IDENTIFY because we only use it for matching IDs from the bot
|
// we only need IDENTIFY because we only use it for matching IDs from the bot
|
||||||
getAuthUrl (state) {
|
getAuthUrl (state) {
|
||||||
return `https://discordapp.com/oauth2/authorize?client_id=${this.clientId}&redirect_uri=${this.oauthCallback}&response_type=code&scope=identify`
|
return `https://discordapp.com/oauth2/authorize?client_id=${this.clientId}&redirect_uri=${this.oauthCallback}&response_type=code&scope=identify&state=${state}`
|
||||||
}
|
}
|
||||||
|
|
||||||
// returns the bot join url with MANAGE_ROLES permission
|
// returns the bot join url with MANAGE_ROLES permission
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
<link rel="icon" type="image/png" sizes="any" href="%PUBLIC_URL%/favicon.png"/>
|
<link rel="icon" type="image/png" sizes="any" href="%PUBLIC_URL%/favicon.png"/>
|
||||||
<title>Roleypoly</title>
|
<title>Roleypoly</title>
|
||||||
|
<link rel="stylesheet" href="https://use.typekit.net/bck0pci.css">
|
||||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/uikit/3.0.0-beta.35/css/uikit.min.css" />
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/uikit/3.0.0-beta.35/css/uikit.min.css" />
|
||||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/uikit/3.0.0-beta.35/js/uikit.min.js"></script>
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/uikit/3.0.0-beta.35/js/uikit.min.js"></script>
|
||||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/uikit/3.0.0-beta.35/js/uikit-icons.min.js"></script>
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/uikit/3.0.0-beta.35/js/uikit-icons.min.js"></script>
|
||||||
|
@ -11,7 +12,7 @@
|
||||||
<noscript>
|
<noscript>
|
||||||
You need to enable JavaScript to run this app.
|
You need to enable JavaScript to run this app.
|
||||||
</noscript>
|
</noscript>
|
||||||
<div id="root"></div>
|
<div id="root" class="tk-source-han-sans-japanese"></div>
|
||||||
<!--
|
<!--
|
||||||
This HTML file is a template.
|
This HTML file is a template.
|
||||||
If you open it directly in the browser, you will see an empty page.
|
If you open it directly in the browser, you will see an empty page.
|
||||||
|
|
|
@ -7,10 +7,11 @@ import UserCard from './UserCard'
|
||||||
|
|
||||||
class ServersNavigation extends Component {
|
class ServersNavigation extends Component {
|
||||||
render () {
|
render () {
|
||||||
|
console.log(this.props.servers)
|
||||||
return <Fragment>
|
return <Fragment>
|
||||||
<UserCard user={this.props.user} />
|
<UserCard user={this.props.user} />
|
||||||
<div className={this.props.className}>
|
<div className={this.props.className}>
|
||||||
{ this.props.servers.map((s, i) => <ServerCard server={s} key={i} />) }
|
{ this.props.servers.map((s, i) => <ServerCard server={s} user={this.props.user} key={i} />) }
|
||||||
</div>
|
</div>
|
||||||
</Fragment>
|
</Fragment>
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
.server-list__item {
|
.server-list__item {
|
||||||
display: flex;
|
display: flex;
|
||||||
border-bottom: 1px solid var(--c-3);
|
/* border-bottom: 1px solid var(--c-3); */
|
||||||
padding: 25px 15px;
|
padding: 25px 15px;
|
||||||
padding-right: 0;
|
padding-right: 0;
|
||||||
|
align-items: center;
|
||||||
|
/* justify-content: center; */
|
||||||
}
|
}
|
||||||
|
|
||||||
a.server-list__item {
|
a.server-list__item {
|
||||||
|
@ -21,6 +23,8 @@ a.server-list__item.active {
|
||||||
.server-list__item:hover:not(.active) {
|
.server-list__item:hover:not(.active) {
|
||||||
background-color: rgba(0,0,0,0.25) !important;
|
background-color: rgba(0,0,0,0.25) !important;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
|
transform: translateX(1px);
|
||||||
|
transition: background 0.05s ease-in-out, transform 0.1s ease-in-out;
|
||||||
}
|
}
|
||||||
|
|
||||||
.server-list__item:last-of-type {
|
.server-list__item:last-of-type {
|
||||||
|
|
|
@ -5,14 +5,25 @@ import './ServerCard.css'
|
||||||
|
|
||||||
class ServerCard extends Component {
|
class ServerCard extends Component {
|
||||||
render () {
|
render () {
|
||||||
const { server } = this.props
|
const { server: { server, id, gm, perms }, user } = this.props
|
||||||
return <NavLink className='server-list__item' activeClassName='active' to={`/s/${server.id}`}>
|
|
||||||
|
let icon = ''
|
||||||
|
|
||||||
|
if (perms.canManageRoles) {
|
||||||
|
icon = <span title='Role Manager' uk-tooltip=''>🔰</span>
|
||||||
|
}
|
||||||
|
|
||||||
|
if (perms.isAdmin) {
|
||||||
|
icon = <span title='Server Admin' uk-tooltip=''>🔰⭐️</span>
|
||||||
|
}
|
||||||
|
|
||||||
|
return <NavLink className='server-list__item' activeClassName='active' to={`/s/${id}`}>
|
||||||
<div className='server-list__item__icon'>
|
<div className='server-list__item__icon'>
|
||||||
<img src={`https://cdn.discordapp.com/icons/${server.id}/${server.icon}.png`} />
|
<img src={`https://cdn.discordapp.com/icons/${id}/${server.icon}.png`} />
|
||||||
</div>
|
</div>
|
||||||
<div className='server-list__item__info'>
|
<div className='server-list__item__info'>
|
||||||
<b>{server.name}</b><br />
|
<b>{server.name}</b><br />
|
||||||
<span>{server.name}</span>
|
<span style={{ color: gm.color }}>{ gm.nickname || user.username }</span> { icon }
|
||||||
</div>
|
</div>
|
||||||
</NavLink>
|
</NavLink>
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
position: relative;
|
position: relative;
|
||||||
display: flex;
|
display: flex;
|
||||||
background-color: rgba(0,0,0,0.3);
|
background-color: rgba(0,0,0,0.3);
|
||||||
border-bottom: 1px solid var(--c-3);
|
/* border-bottom: 1px solid var(--c-3); */
|
||||||
padding: 25px 15px;
|
padding: 25px 15px;
|
||||||
grid-area: user;
|
grid-area: user;
|
||||||
}
|
}
|
||||||
|
@ -40,6 +40,14 @@
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.user-card__actions svg {
|
||||||
|
transition: transform 0.05s ease-in-out;
|
||||||
|
}
|
||||||
|
|
||||||
|
.user-card__actions svg:hover {
|
||||||
|
transform: scale(1.15);
|
||||||
|
}
|
||||||
|
|
||||||
.user-card__actions polygon {
|
.user-card__actions polygon {
|
||||||
fill: var(--c-7);
|
fill: var(--c-7);
|
||||||
}
|
}
|
|
@ -1,5 +1,6 @@
|
||||||
import React, { Component } from 'react'
|
import React, { Component } from 'react'
|
||||||
import Radium from 'radium'
|
import Radium from 'radium'
|
||||||
|
import superagent from 'superagent'
|
||||||
import './index.css'
|
import './index.css'
|
||||||
|
|
||||||
import Navigation from './Navigation'
|
import Navigation from './Navigation'
|
||||||
|
@ -7,9 +8,20 @@ import Navigation from './Navigation'
|
||||||
import mockData from './mockData'
|
import mockData from './mockData'
|
||||||
|
|
||||||
class Servers extends Component {
|
class Servers extends Component {
|
||||||
|
state = {
|
||||||
|
user: mockData.user,
|
||||||
|
servers: [],
|
||||||
|
}
|
||||||
|
|
||||||
|
async componentWillMount () {
|
||||||
|
const rsp = await superagent.get(`/api/~/relevant-servers/62601275618889728`)
|
||||||
|
|
||||||
|
this.setState({ servers: rsp.body })
|
||||||
|
}
|
||||||
|
|
||||||
render () {
|
render () {
|
||||||
return <div className="servers">
|
return <div className="servers">
|
||||||
<Navigation className="servers__nav" servers={mockData.servers} user={mockData.user} />
|
<Navigation className="servers__nav" servers={this.state.servers} user={this.state.user} />
|
||||||
<div className="servers__content">
|
<div className="servers__content">
|
||||||
{/* another router probably. */}
|
{/* another router probably. */}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -3,6 +3,7 @@ import { Link } from 'react-router-dom'
|
||||||
import Radium from 'radium'
|
import Radium from 'radium'
|
||||||
import Logotype from '../logotype'
|
import Logotype from '../logotype'
|
||||||
import styles from './styles'
|
import styles from './styles'
|
||||||
|
import './wrapper.css'
|
||||||
|
|
||||||
class Wrapper extends Component {
|
class Wrapper extends Component {
|
||||||
render () {
|
render () {
|
||||||
|
@ -11,7 +12,7 @@ class Wrapper extends Component {
|
||||||
<div style={styles.container}>
|
<div style={styles.container}>
|
||||||
<nav uk-navbar='' style={styles.nav} className='uk-navbar-transparent'>
|
<nav uk-navbar='' style={styles.nav} className='uk-navbar-transparent'>
|
||||||
<div className='uk-navbar-left'>
|
<div className='uk-navbar-left'>
|
||||||
<Logotype style={{ height: '2rem' }} />
|
<Logotype style={{ height: '2rem' }} className='wrapper__logotype' />
|
||||||
</div>
|
</div>
|
||||||
<div class='uk-navbar-right'>
|
<div class='uk-navbar-right'>
|
||||||
<ul class='uk-navbar-nav'>
|
<ul class='uk-navbar-nav'>
|
||||||
|
|
4
UI/src/components/wrapper/wrapper.css
Normal file
4
UI/src/components/wrapper/wrapper.css
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
.wrapper__logo:hover mask {
|
||||||
|
/* transform: translate 1s ease-in-out repeat; */
|
||||||
|
transform: rotate(30deg)
|
||||||
|
}
|
|
@ -1,7 +1,10 @@
|
||||||
body {
|
body {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
font-family: sans-serif;
|
font-family: "source-han-sans-japanese", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
|
||||||
|
text-rendering: optimizeLegibility;
|
||||||
|
-webkit-font-smoothing: antialiased;
|
||||||
|
-moz-osx-font-smoothing: grayscale;
|
||||||
}
|
}
|
||||||
|
|
||||||
:root {
|
:root {
|
||||||
|
|
Loading…
Add table
Reference in a new issue