Skip to content

Commit

Permalink
Add join/leave messages to dashboard, still doesn't work.
Browse files Browse the repository at this point in the history
  • Loading branch information
retrixe committed Oct 14, 2018
1 parent 52fa139 commit 891b9a1
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 23 deletions.
5 changes: 5 additions & 0 deletions components/dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ query getServerSettings($server: String!, $token: String!) {
serverSettings(serverId: $server, linkToken: $token) {
addRoleForAll
joinAutorole
joinLeaveMessages {
channelName
joinMessage
leaveMessage
}
}
}
`
Expand Down
80 changes: 72 additions & 8 deletions components/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,56 @@ import { gql } from 'apollo-boost'

/* eslint-disable quotes, no-multi-str, no-undef */
interface Props {
data: { addRoleForAll: boolean, joinAutorole: string },
data: {
addRoleForAll: boolean, joinAutorole: string, joinLeaveMessages: {
channelName: string,
joinMessage: string,
leaveMessage: string
}
},
token: string,
server: string,
refetch: Function
}
interface State {
role: boolean,
joinAutorole: string
joinAutorole: string,
joinLeaveMessages: {
channelName: string,
joinMessage: string,
leaveMessage: string
}
}
export default class Settings extends React.Component<Props, State> {
constructor (props) {
super(props); this.state = {
role: this.props.data.addRoleForAll,
joinAutorole: this.props.data.joinAutorole
joinAutorole: this.props.data.joinAutorole,
joinLeaveMessages: {
channelName: this.props.data.joinLeaveMessages.channelName,
joinMessage: this.props.data.joinLeaveMessages.joinMessage,
leaveMessage: this.props.data.joinLeaveMessages.leaveMessage
}
}
}

render () {
const mutation = gql`
mutation variables($server: String!, $token: String!, $role: Boolean, $joinAutorole: String) {
mutation variables(
$server: String!, $token: String!, $role: Boolean, $joinAutorole: String,
$joinLeaveMessages: JoinLeaveMessagesInput
) {
editServerSettings(input: {
serverId: $server, linkToken: $token, addRoleForAll: $role, joinAutorole: $joinAutorole
serverId: $server, linkToken: $token, addRoleForAll: $role, joinAutorole: $joinAutorole,
joinLeaveMessages: $joinLeaveMessages
}) {
addRoleForAll
joinAutorole
joinLeaveMessages {
channelName
joinMessage
leaveMessage
}
}
}
`
Expand All @@ -42,7 +67,8 @@ mutation variables($server: String!, $token: String!, $role: Boolean, $joinAutor
token: this.props.token,
role: this.state.role,
server: this.props.server,
joinAutorole: this.state.joinAutorole
joinAutorole: this.state.joinAutorole,
joinLeaveMessages: this.state.joinLeaveMessages
}}>
{(updateSettings, { loading, error }) => (
<>
Expand Down Expand Up @@ -78,12 +104,50 @@ mutation variables($server: String!, $token: String!, $role: Boolean, $joinAutor
{'Use | to separate roles. If a role contains |, it will not be added. \
Prefix role names with bot- for adding roles to bots automatically.'}
</Typography>
<FormControl>
<FormControl fullWidth>
<InputLabel>Role Names</InputLabel>
<Input
value={this.state.joinAutorole} fullWidth
onChange={e => this.setState({ joinAutorole: e.target.value })} margin='dense' />
<FormHelperText>Leave blank to disable</FormHelperText>
<FormHelperText>Leave blank to disable autorole</FormHelperText>
</FormControl>
<br /><br /><Divider /><br />
<Typography variant='subheading' gutterBottom>Join/Leave Messages</Typography>
<Typography gutterBottom>
{'Join/leave messages send a customized message whenever someone joins or leaves \
\\o/'}
</Typography>
<Typography gutterBottom>Ensure the channel name is correct.</Typography>
<FormControl fullWidth>
<InputLabel>Channel Name</InputLabel>
<Input
value={this.state.joinLeaveMessages.channelName} fullWidth
onChange={e => this.setState({ joinLeaveMessages: {
...this.state.joinLeaveMessages, channelName: e.target.value
} })} margin='dense' />
<FormHelperText>Leave blank to disable join/leave messages</FormHelperText>
</FormControl>
<div style={{ height: 10 }} />
<Typography gutterBottom>
{'Use {un} for the username of the \
joining/leaving user, {m} for mentioning them and {d} for their discriminator.'}
</Typography>
<FormControl fullWidth>
<InputLabel>Join Message</InputLabel>
<Input
value={this.state.joinLeaveMessages.joinMessage} fullWidth
onChange={e => this.setState({ joinLeaveMessages: {
...this.state.joinLeaveMessages, joinMessage: e.target.value
} })} margin='dense' />
</FormControl>
<div style={{ height: 10 }} />
<FormControl fullWidth>
<InputLabel>Leave Message</InputLabel>
<Input
value={this.state.joinLeaveMessages.leaveMessage} fullWidth
onChange={e => this.setState({ joinLeaveMessages: {
...this.state.joinLeaveMessages, leaveMessage: e.target.value
} })} margin='dense' />
</FormControl>
<div style={{ height: 10 }} />
<Button size='small'>Cancel</Button>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"tap-nyan": "^1.1.0",
"ts-node": "6.2.0",
"typescript": "^3.0.1",
"typescript-eslint-parser": "^19.0.2"
"typescript-eslint-parser": "^20.0.0"
},
"husky": {
"hooks": {
Expand Down
1 change: 0 additions & 1 deletion server/bot/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ export default async (message: Message, client: Client, tempDB: DB, db: Db) => {
// Content of message and sendResponse.
const sendResponse = (m: string) => client.createMessage(message.channel.id, m)
const command = message.content.toLowerCase()
// Help command.
// Auto responses and easter eggs.
if (command.startsWith('is dot a good boy')) sendResponse('Shame on you. He\'s undefined.')
else if (command.startsWith('iphone x')) sendResponse(`You don't deserve it. 😎`)
Expand Down
17 changes: 14 additions & 3 deletions server/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ export default (ctx: { tempDB: DB, client: Client }) => ({
let {
addRoleForAll, joinLeaveMessages, joinAutorole
} = await getServerSettings(db, serverId)
joinLeaveMessages = joinLeaveMessages || {}
joinLeaveMessages = {
channelName: joinLeaveMessages.channelName || '',
joinMessage: joinLeaveMessages.joinMessage || '',
leaveMessage: joinLeaveMessages.leaveMessage || ''
}
if (
member.permission.has('manageGuild') || host === ctx.tempDB.link[linkToken]
) return { serverId, addRoleForAll, joinLeaveMessages, joinAutorole }
Expand Down Expand Up @@ -59,10 +65,12 @@ export default (ctx: { tempDB: DB, client: Client }) => ({
Mutation: {
editServerSettings: async (
_: string, { input }: { input: { // eslint-disable-next-line indent
serverId: string, linkToken: string, addRoleForAll: string, joinAutorole: string
serverId: string, linkToken: string, addRoleForAll: string, joinAutorole: string,
// eslint-disable-next-line indent
joinLeaveMessages: { channelName: string, joinMessage: string, leaveMessage: string }
} }
) => {
const { serverId, linkToken, addRoleForAll, joinAutorole } = input
const { serverId, linkToken, addRoleForAll, joinAutorole, joinLeaveMessages } = input
const member = ctx.client.guilds
.find(t => t.id === serverId).members.find(t => t.id === ctx.tempDB.link[linkToken])
if (
Expand All @@ -72,7 +80,10 @@ export default (ctx: { tempDB: DB, client: Client }) => ({
await db.collection('servers').updateOne({ serverID: serverId }, { $set: {
/* eslint-disable no-unneeded-ternary */
addRoleForAll: addRoleForAll ? addRoleForAll : undefined,
joinAutorole: joinAutorole ? joinAutorole : undefined
joinAutorole: joinAutorole ? joinAutorole : undefined,
joinLeaveMessages: {
channelName: null, joinMessage: null, leaveMessage: null, ...joinLeaveMessages
}
/* eslint-enable no-unneeded-ternary */
} })
return getServerSettings(db, serverId)
Expand Down
24 changes: 23 additions & 1 deletion server/schema.graphql
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
# Joining and leaving servers.
type JoinLeaveMessages {
# Name of channel.
channelName: String
# What to post when joining.
joinMessage: String
# What to post when leaving.
leaveMessage: String
}

# Server specific settings.
type ServerSetting {
# Server ID.
serverId: String!
# If add role is enabled for everyone.
addRoleForAll: Boolean
# If join/leave messages are enabled, and if so, what message and channel.
joinLeaveMessages: [String]
joinLeaveMessages: JoinLeaveMessages
# If join autorole is enabled, and if so, what role.
joinAutorole: String
}
Expand All @@ -32,6 +42,16 @@ type Query {
getBotId: String!
}

# Input for modifying join/leave messages.
input JoinLeaveMessagesInput {
# Name of channel.
channelName: String!
# What to post when joining.
joinMessage: String
# What to post when leaving.
leaveMessage: String
}

# Input for editServerSettings mutation.
input EditServerSettingsInput {
# Server ID of the server.
Expand All @@ -42,6 +62,8 @@ input EditServerSettingsInput {
addRoleForAll: Boolean
# Edit join autorole through this setting.
joinAutorole: String
# Edit join leave messages through this setting.
joinLeaveMessages: JoinLeaveMessagesInput
}

# Enable mutations.
Expand Down
18 changes: 9 additions & 9 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7863,18 +7863,18 @@ typedarray@^0.0.6:
resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"
integrity sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=

typescript-eslint-parser@^19.0.2:
version "19.0.2"
resolved "https://registry.yarnpkg.com/typescript-eslint-parser/-/typescript-eslint-parser-19.0.2.tgz#3df184b5290469598375e93842cd0a42d8b7745d"
integrity sha512-ZwbgliYgAjbeV+l7Ul8awcJlkzNeOLM2NiYgj1djOYl2WU0lRLIpr1HPmvBzqj9pK/Sf5Kn50ap9MAXCCDW5qA==
typescript-eslint-parser@^20.0.0:
version "20.0.0"
resolved "https://registry.yarnpkg.com/typescript-eslint-parser/-/typescript-eslint-parser-20.0.0.tgz#508678796bbcf60365ada28c38bd557e736bec01"
integrity sha512-HZEoGA+LnS3etUlVAPX6I8sZ7872Yb0vPvQv6QDCIE44KD3bFmvPEQ4LbiD+qGkcxh6segjVK0v3rxpb2R6oSA==
dependencies:
eslint "4.19.1"
typescript-estree "1.0.0"
typescript-estree "2.1.0"

typescript-estree@1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/typescript-estree/-/typescript-estree-1.0.0.tgz#6266f31108d2f12594cb996d0e16d938e3cb83cd"
integrity sha512-KTsKik/vCxgkRImEuE6LFcAImffc9HJ0vPURPlFSy80w5QdjQUpkjHvG0GR5fY36SlWhwxdB2HxICaCP3lqe0A==
typescript-estree@2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/typescript-estree/-/typescript-estree-2.1.0.tgz#b2f3353494409ed53bf7055b46f78c1fbbe47661"
integrity sha512-t4o+7pB4OnxV36Bp41Vgtq8vXIvIUbx1vM98PSE2mL5QBY6woFaBN9hhD8pZHIrAu24IB5gzxbkEJOXj4lWNXQ==
dependencies:
lodash.unescape "4.0.1"
semver "5.5.0"
Expand Down

0 comments on commit 891b9a1

Please sign in to comment.