Skip to content

Commit

Permalink
Change channelID field in GraphQL to channel.
Browse files Browse the repository at this point in the history
  • Loading branch information
retrixe committed Mar 5, 2019
1 parent 7f566c6 commit 2a90021
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 23 deletions.
2 changes: 1 addition & 1 deletion components/dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ query getServerSettings($server: String!, $token: String!) {
addRoleForAll
joinAutorole
joinLeaveMessages {
channelID
channel
joinMessage
leaveMessage
banMessage
Expand Down
12 changes: 6 additions & 6 deletions components/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { gql } from 'apollo-boost'
interface Props {
data: {
addRoleForAll: string, joinAutorole: string, ocrOnSend: boolean, joinLeaveMessages: {
channelID: string,
channel: string,
joinMessage: string,
leaveMessage: string,
banMessage: string
Expand All @@ -27,7 +27,7 @@ interface State {
joinAutorole: string,
ocrOnSend: boolean,
joinLeaveMessages: {
channelID: string,
channel: string,
joinMessage: string,
leaveMessage: string,
banMessage: string
Expand All @@ -40,7 +40,7 @@ export default class Settings extends React.Component<Props, State> {
joinAutorole: this.props.data.joinAutorole,
ocrOnSend: this.props.data.ocrOnSend,
joinLeaveMessages: {
channelID: this.props.data.joinLeaveMessages.channelID,
channel: this.props.data.joinLeaveMessages.channel,
joinMessage: this.props.data.joinLeaveMessages.joinMessage,
leaveMessage: this.props.data.joinLeaveMessages.leaveMessage,
banMessage: this.props.data.joinLeaveMessages.banMessage
Expand All @@ -62,7 +62,7 @@ mutation variables(
joinAutorole
ocrOnSend
joinLeaveMessages {
channelID
channel
joinMessage
leaveMessage
banMessage
Expand Down Expand Up @@ -127,10 +127,10 @@ mutation variables(
<Typography gutterBottom>Ensure the channel name is correct.</Typography>
<FormControl fullWidth>
<InputLabel>Channel Name</InputLabel>
<Select value={this.state.joinLeaveMessages.channelID} fullWidth margin='dense'
<Select value={this.state.joinLeaveMessages.channel} fullWidth margin='dense'
onChange={e => this.setState({
joinLeaveMessages: {
...this.state.joinLeaveMessages, channelID: e.target.value
...this.state.joinLeaveMessages, channel: e.target.value
}
})}
>
Expand Down
14 changes: 6 additions & 8 deletions server/bot/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,15 @@ export const guildMemberAdd = (client: Client, db: Db, tempDB: DB) => async (
}
// If join/leave messages is not configured/improperly configured..
if (!serverSettings.joinLeaveMessages) return
const { joinMessage, channelName } = serverSettings.joinLeaveMessages
if (!channelName || !joinMessage) return
const { joinMessage, channel } = serverSettings.joinLeaveMessages
if (!channel || !joinMessage) return
// We send a message.
try {
const channelID = guild.channels.find(i => i.name === channelName).id
const toSend = joinMessage
.split('{un}').join(member.user.username) // Replace the username.
.split('{m}').join(member.user.mention) // Replace the mention.
.split('{d}').join(member.user.discriminator) // Replace the discriminator.
client.createMessage(channelID, toSend)
await client.createMessage(channel, toSend)
} catch (e) {}
}

Expand All @@ -56,18 +55,17 @@ export const guildMemberRemove = (client: Client, db: Db) => async (
const serverSettings = await getServerSettings(db, guild.id)
// If join/leave messages is not configured/improperly configured..
if (!serverSettings.joinLeaveMessages) return
const { leaveMessage, channelName, banMessage } = serverSettings.joinLeaveMessages
if (!channelName || !leaveMessage) return
const { leaveMessage, channel, banMessage } = serverSettings.joinLeaveMessages
if (!channel || !leaveMessage) return
// If there is a ban message and the user is banned.
if (banMessage && (await guild.getBans()).find(i => i.id === member.user.id)) return
// We send a message.
try {
const channelID = guild.channels.find(i => i.name === channelName).id
const toSend = leaveMessage
.split('{un}').join(member.user.username) // Replace the username.
.split('{m}').join(member.user.mention) // Replace the mention.
.split('{d}').join(member.user.discriminator) // Replace the discriminator.
client.createMessage(channelID, toSend)
await client.createMessage(channel, toSend)
} catch (e) {}
}

Expand Down
8 changes: 4 additions & 4 deletions server/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ export default (ctx: { tempDB: DB, client: Client }) => ({
} = await getServerSettings(db, serverId)
// Insert default values for all properties.
joinLeaveMessages = joinLeaveMessages ? {
channelID: joinLeaveMessages.channelID || '',
channel: joinLeaveMessages.channel || '',
joinMessage: joinLeaveMessages.joinMessage || '',
leaveMessage: joinLeaveMessages.leaveMessage || '',
banMessage: joinLeaveMessages.banMessage || ''
} : { channelID: '', joinMessage: '', leaveMessage: '', banMessage: '' }
} : { channel: '', joinMessage: '', leaveMessage: '', banMessage: '' }
addRoleForAll = addRoleForAll || ''
ocrOnSend = ocrOnSend || false
joinAutorole = joinAutorole || ''
Expand Down Expand Up @@ -79,7 +79,7 @@ export default (ctx: { tempDB: DB, client: Client }) => ({
_: string, { input }: { input: { // eslint-disable-next-line indent
serverId: string, linkToken: string, addRoleForAll: string, joinAutorole: string,
// eslint-disable-next-line indent
joinLeaveMessages: { channelID: string, joinMessage: string, leaveMessage: string },
joinLeaveMessages: { channel: string, joinMessage: string, leaveMessage: string },
// eslint-disable-next-line indent
ocrOnSend: boolean
} }
Expand All @@ -96,7 +96,7 @@ export default (ctx: { tempDB: DB, client: Client }) => ({
joinAutorole: joinAutorole || undefined,
ocrOnSend,
joinLeaveMessages: joinLeaveMessages ? {
channelID: '',
channel: '',
joinMessage: '',
leaveMessage: '',
banMessage: '',
Expand Down
8 changes: 4 additions & 4 deletions server/schema.graphql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Joining and leaving servers.
type JoinLeaveMessages {
# Name of channel.
channelID: String
# ID of channel.
channel: String
# What to post when joining.
joinMessage: String
# What to post when leaving.
Expand Down Expand Up @@ -58,8 +58,8 @@ type Query {

# Input for modifying join/leave messages.
input JoinLeaveMessagesInput {
# Name of channel.
channelID: String!
# ID of channel.
channel: String!
# What to post when joining.
joinMessage: String
# What to post when leaving.
Expand Down

0 comments on commit 2a90021

Please sign in to comment.