Skip to content

Commit

Permalink
Format PR
Browse files Browse the repository at this point in the history
  • Loading branch information
dispherical committed Jun 5, 2024
1 parent 2e8b85c commit ad86917
Show file tree
Hide file tree
Showing 2 changed files with 152 additions and 136 deletions.
247 changes: 125 additions & 122 deletions commands/invite.js
Original file line number Diff line number Diff line change
@@ -1,129 +1,132 @@
async function invite(args) {
const { client, body, command, respond } = args
const user = await client.users.info({ user: command.user_id })
if (!user.user.is_admin) return await respond("Sorry, only admins can use /toriel-invite. Please instruct the person to use https://hackclub.com/slack to join.\n💡 Protip: Append ?event=[insert channel name] to the url (i.e. https://hackclub.com/slack?event=outernet) to add the person you wish to invite to the channel automagically (this only works if toriel has it specified it in <https://github.com/hackclub/toriel/blob/main/util/transcript.yml|transcript.yaml>)")
client.views.open({
trigger_id: body.trigger_id,
view: {
callback_id: "admin_invite_user",
"title": {
"type": "plain_text",
"text": "Invite a user",
"emoji": true
const { client, body, command, respond } = args
const user = await client.users.info({ user: command.user_id })
if (!user.user.is_admin)
return await respond(
'Sorry, only admins can use /toriel-invite. Please instruct the person to use https://hackclub.com/slack to join.\n💡 Protip: Append ?event=[insert channel name] to the url (i.e. https://hackclub.com/slack?event=outernet) to add the person you wish to invite to the channel automagically (this only works if toriel has it specified it in <https://github.com/hackclub/toriel/blob/main/util/transcript.yml|transcript.yaml>)'
)
client.views.open({
trigger_id: body.trigger_id,
view: {
callback_id: 'admin_invite_user',
title: {
type: 'plain_text',
text: 'Invite a user',
emoji: true,
},
submit: {
type: 'plain_text',
text: 'Submit',
emoji: true,
},
type: 'modal',
close: {
type: 'plain_text',
text: 'Cancel',
emoji: true,
},
blocks: [
{
type: 'section',
text: {
type: 'mrkdwn',
text: 'This modal will invite a user to Slack',
},
},
{
type: 'input',
element: {
type: 'email_text_input',
action_id: 'email',
},
label: {
type: 'plain_text',
text: 'Email',
emoji: true,
},
},
{
type: 'input',
element: {
type: 'plain_text_input',
action_id: 'reason',
},
label: {
type: 'plain_text',
text: 'Reason',
emoji: true,
},
},
{
type: 'input',
element: {
type: 'static_select',
placeholder: {
type: 'plain_text',
text: 'Select a continent',
emoji: true,
},
"submit": {
"type": "plain_text",
"text": "Submit",
"emoji": true
},
"type": "modal",
"close": {
"type": "plain_text",
"text": "Cancel",
"emoji": true
},
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "This modal will invite a user to Slack"
}
options: [
{
text: {
type: 'plain_text',
text: 'Africa',
emoji: true,
},
value: 'AFRICA',
},
{
text: {
type: 'plain_text',
text: 'Asia',
emoji: true,
},
value: 'ASIA',
},
{
text: {
type: 'plain_text',
text: 'Australia',
emoji: true,
},
value: 'AUSTRALIA',
},
{
text: {
type: 'plain_text',
text: 'Europe',
emoji: true,
},
{
"type": "input",
"element": {
"type": "email_text_input",
"action_id": "email"
},
"label": {
"type": "plain_text",
"text": "Email",
"emoji": true
}
value: 'EUROPE',
},
{
text: {
type: 'plain_text',
text: 'North America',
emoji: true,
},
{
"type": "input",
"element": {
"type": "plain_text_input",
"action_id": "reason"
},
"label": {
"type": "plain_text",
"text": "Reason",
"emoji": true
}
value: 'NORTH_AMERICA',
},
{
text: {
type: 'plain_text',
text: 'South America',
emoji: true,
},
{
"type": "input",
"element": {
"type": "static_select",
"placeholder": {
"type": "plain_text",
"text": "Select a continent",
"emoji": true
},
"options": [
{
"text": {
"type": "plain_text",
"text": "Africa",
"emoji": true
},
"value": "AFRICA"
},
{
"text": {
"type": "plain_text",
"text": "Asia",
"emoji": true
},
"value": "ASIA"
},
{
"text": {
"type": "plain_text",
"text": "Australia",
"emoji": true
},
"value": "AUSTRALIA"
},
{
"text": {
"type": "plain_text",
"text": "Europe",
"emoji": true
},
"value": "EUROPE"
},
{
"text": {
"type": "plain_text",
"text": "North America",
"emoji": true
},
"value": "NORTH_AMERICA"
},
{
"text": {
"type": "plain_text",
"text": "South America",
"emoji": true
},
"value": "SOUTH_AMERICA"
}
],
"action_id": "continent"
},
"label": {
"type": "plain_text",
"text": "Continent",
"emoji": true
}
}
]
}
})
value: 'SOUTH_AMERICA',
},
],
action_id: 'continent',
},
label: {
type: 'plain_text',
text: 'Continent',
emoji: true,
},
},
],
},
})
}

module.exports = invite
module.exports = invite
41 changes: 27 additions & 14 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,31 +250,44 @@ app.command(/.*?/, async (args) => {
console.error(e)
}
})
app.view('admin_invite_user', async ({ view, ack, body}) => {
app.view('admin_invite_user', async ({ view, ack, body }) => {
const submittedValues = view.state.values
console.log(submittedValues)
let email, reason, continent;
let email, reason, continent

for (let key in submittedValues) {
if (submittedValues[key]['email']) email = submittedValues[key]['email'].value
if (submittedValues[key]['reason']) reason = submittedValues[key]['reason'].value
if (submittedValues[key]['continent']) continent = submittedValues[key]['continent'].selected_option.value
if (submittedValues[key]['email'])
email = submittedValues[key]['email'].value
if (submittedValues[key]['reason'])
reason = submittedValues[key]['reason'].value
if (submittedValues[key]['continent'])
continent = submittedValues[key]['continent'].selected_option.value
}

if (!/^[a-zA-Z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/.test(email)) return await ack({
"response_action": "errors",
errors: {
"email": "This isn’t a valid email"
}
});
if (
!/^[a-zA-Z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/.test(
email
)
)
return await ack({
response_action: 'errors',
errors: {
email: 'This isn’t a valid email',
},
})
await ack()
await inviteUser({
email, reason, continent, ip: "0.0.0.0", userAgent: "ManualInvite/0.0.0", teen: true
email,
reason,
continent,
ip: '0.0.0.0',
userAgent: 'ManualInvite/0.0.0',
teen: true,
})
await client.chat.postMessage({
channel: body.user.id,
text: `Successfully invited ${email} to the Slack.`
});
text: `Successfully invited ${email} to the Slack.`,
})
})
app.action(/.*?/, async (args) => {
const { ack, respond, payload, client, body } = args
Expand Down

0 comments on commit ad86917

Please sign in to comment.