Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Steal Command #85

Merged
merged 6 commits into from
Jul 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/transcript.yml
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,13 @@ messages:
invaliduser: Hmmmmmmmm THAT'S NOT A REAL USER!!!! What are you trying to pull here????
userArg: <@${this.userArg}>'s scrapbook is ${this.scrapbookLink}
self: Your scrapbook profile is ${this.scrapbookLink}
steal:
'invaliduser': Hmmmmmmmm THAT'S NOT A REAL USER!!!! What are you trying to pull here???? I don't like it :(
'done': <@${this.victimUser}>'s CSS is now live on your profile!
'noargs':
- |
You can't steal CSS from no one :facepalm: Make sure to mention someone after the command.
'empty': <@${this.victimUser}>'s custom CSS is empty, try another person.
profileUpdate: Your profile details have been updated! ${this.scrapbookLink}
assetReady: <@${this.user}> Your video has been processed and is live on your scrapbook!
errors:
Expand Down
3 changes: 3 additions & 0 deletions pages/api/slack/commands/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ export default async (req, res) => {
case 'open':
method = 'open'
break
case 'steal-css':
method = 'steal'
break
case 'help':
case '':
method = 'help'
Expand Down
41 changes: 41 additions & 0 deletions pages/api/slack/commands/steal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import {
unverifiedRequest,
getUserRecord,
accountsTable,
sendCommandResponse,
t
} from '../../../../lib/api-utils'

export default async (req, res) => {
if (unverifiedRequest(req))
return res.status(400).send('Unverified Slack request!')
else res.status(200).end()

const { user_id, response_url, text } = req.body
console.log('victim text', text)
const action = text.split(' ')[1]
const victimUser = text.split(' ')[2]?.split('@')[1].split('|')[0]
console.log('victim user', victimUser)

if (!action || !victimUser) {
return sendCommandResponse(response_url, t('messages.steal.noargs'))
}

let userRecord
try {
userRecord = await getUserRecord(user_id)
} catch {
return sendCommandResponse(response_url, t('messages.steal.invaliduser'))
}
const victimUserRecord = await getUserRecord(victimUser)
const newCSS = victimUserRecord.fields['CSS URL']

if ((newCSS = '')) {
sendCommandResponse(response_url, t(`messages.steal.empty`, { victimUser }))
}

await Promise.all([
accountsTable.update(userRecord.id, { 'CSS URL': newCSS }),
sendCommandResponse(response_url, t(`messages.steal.done`, { victimUser }))
])
}