Skip to content

Commit

Permalink
Remove user login debug & more templates
Browse files Browse the repository at this point in the history
  • Loading branch information
DEVTomatoCake committed Nov 4, 2023
1 parent c514aa9 commit 13927be
Show file tree
Hide file tree
Showing 12 changed files with 117 additions and 100 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,13 @@ Exceptions:
- `requested` and `rerequested` actions of the `check_suite` event because they are not used for webhooks
- `project_card`, `project` and `project_column` have no templates due to being deprecated (Projects "Classic")
- `secret_scanning_alert_location` as it only triggers on issues `secret_scanning_alert` already triggers on
- `deleted` action of `repository` as it is not used for webhooks

## Variables

- Top level: `{{variable}}` or `{{ variable }}`
- Below: `{{ variable.data }}`
- Array length: `{{ count(variable.data) }}`
- Ternary: `{{ variable.data ? Yes : No }}`
- OR: `{{ variable.data || No }}`
- Double spaces are removed
31 changes: 23 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,28 @@ app.get("/servers/:id/hooks", async (req, res) => {
name: hook.name,
webhook: hook.webhook,
channel: hook.channel,
//message: hook.message,
message: hook.message,
messageUrl: "https://embed.tomatenkuchen.com/?dgh=1&data=" + Buffer.from(encodeURIComponent(JSON.stringify(hook.message))).toString("base64"),
filterEvent: hook.filterEvent,
filterAction: hook.filterAction
}))

const realServer = bot.guilds.cache.get(req.params.id)
if (!realServer) return res.status(404).send({success: false, error: "Server not found"})

const channels = realServer.channels.cache
.filter(c => c.type == Discord.ChannelType.GuildText || c.type == Discord.ChannelType.GuildAnnouncement || c.type == Discord.ChannelType.GuildVoice || c.type == Discord.ChannelType.GuildStageVoice)
.map(c => ({
id: c.id,
name: c.name,
type: c.type
}))

res.send({
name: bot.guilds.cache.get(req.params.id)?.name,
name: realServer.name,
hooks,
events
events,
channels
})
})

Expand Down Expand Up @@ -148,6 +161,9 @@ app.post("/servers/:id/hooks/:hook", async (req, res) => {
const hook = rows[0]
if (hook.server != req.params.id) return res.status(401).send({success: false, error: "Invalid server ID"})

if (!req.body.filterEvent || !Array.isArray(req.body.filterEvent)) req.body.filterEvent = req.body.filterEvent ? [req.body.filterEvent] : []
if (!req.body.filterAction || !Array.isArray(req.body.filterAction)) req.body.filterAction = req.body.filterAction ? [req.body.filterAction] : []

await pool.query(
"UPDATE `hook` SET `name` = ?, `webhook` = ?, `channel` = ?, `message` = ?, `filterEvent` = ?, `filterAction` = ? WHERE `id` = ?",
[req.body.name, req.body.webhook || null, req.body.channel || null, req.body.message || null, JSON.stringify(req.body.filterEvent), JSON.stringify(req.body.filterAction), req.params.hook]
Expand Down Expand Up @@ -189,6 +205,7 @@ app.post("/servers/:id/hooks/:hook/regen", async (req, res) => {

const secret = oauth.generateToken()
await pool.query("UPDATE `hook` SET `secret` = ? WHERE `id` = ?", [secret, req.params.hook])

res.send({success: true, secret})
})

Expand Down Expand Up @@ -216,15 +233,13 @@ app.get("/login", async (req, res) => {
}
})
const json = await fetched.json()
console.log(json)
if (json.error) return res.status(500).send({success: false, error: json.error + ": " + json.error_description})

const user = await oauth.getUser(json.access_token).catch(err => {
console.log(err)
const user = await oauth.getUser(json.access_token).catch(e => {
console.log(e)
res.status(500).send("Error getting user data")
})
if (user instanceof Error) return
console.log(user)

const token = oauth.generateToken()
res.cookie("auth", token, {signed: true, secure: true, httpOnly: true, expires: new Date(Date.now() + 1000 * 60 * 60 * 24 * 4), domain: "." + domain.split(".").slice(-2).join(".")})
Expand All @@ -235,7 +250,7 @@ app.get("/login", async (req, res) => {
[user.id, token, json.access_token, json.refresh_token, Date.now() + json.expires_in * 1000, token, json.access_token, json.refresh_token, Date.now() + json.expires_in * 1000]
)

res.send({token, avatar: "https://cdn.discordapp.com/avatars/" + user.id + "/" + user.avatar + ".webp?size=64"})
res.send({success: true})
})
app.get("/logout", (req, res) => {
if (!req.signedCookies.auth) return res.status(401).send("Missing auth cookie")
Expand Down
32 changes: 16 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
"nodemon": "^3.0.1"
},
"devDependencies": {
"eslint": "^8.52.0",
"eslint-plugin-sonarjs": "^0.22.0",
"eslint": "^8.53.0",
"eslint-plugin-sonarjs": "^0.23.0",
"eslint-plugin-unicorn": "^49.0.0"
}
}
8 changes: 4 additions & 4 deletions templates/branch_protection_configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ module.exports = [
icon_url: "{{ sender.avatar_url }}",
url: "{{ sender.html_url }}"
},
title: "[{{ repository.name }}] `branch_protection_configuration` (`disabled`)",
title: "[{{ repository.name }}] All branch protection rules disabled",
url: "{{ repository.html_url }}",
color: color("black")
color: color("darkRed")
}]
},{
action: "enabled",
Expand All @@ -21,9 +21,9 @@ module.exports = [
icon_url: "{{ sender.avatar_url }}",
url: "{{ sender.html_url }}"
},
title: "[{{ repository.name }}] `branch_protection_configuration` (`enabled`)",
title: "[{{ repository.name }}] All branch protection rules enabled",
url: "{{ repository.html_url }}",
color: color("black")
color: color("darkGreen")
}]
}
]
6 changes: 3 additions & 3 deletions templates/branch_protection_rule.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module.exports = [
icon_url: "{{ sender.avatar_url }}",
url: "{{ sender.html_url }}"
},
title: "[{{ repository.name }}] `branch_protection_rule` (`created`)",
title: "[{{ repository.name }}] Branch protection rule **{{ branch_protection_rule.name }}** created",
url: "{{ repository.html_url }}",
color: color("green")
}]
Expand All @@ -21,7 +21,7 @@ module.exports = [
icon_url: "{{ sender.avatar_url }}",
url: "{{ sender.html_url }}"
},
title: "[{{ repository.name }}] `branch_protection_rule` (`edited`)",
title: "[{{ repository.name }}] Branch protection rule **{{ branch_protection_rule.name }}** edited",
url: "{{ repository.html_url }}",
color: color("cyan")
}]
Expand All @@ -33,7 +33,7 @@ module.exports = [
icon_url: "{{ sender.avatar_url }}",
url: "{{ sender.html_url }}"
},
title: "[{{ repository.name }}] `branch_protection_rule` (`deleted`)",
title: "[{{ repository.name }}] Branch protection rule **{{ branch_protection_rule.name }}** deleted",
url: "{{ repository.html_url }}",
color: color("red")
}]
Expand Down
42 changes: 22 additions & 20 deletions templates/dependabot_alert.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ module.exports = [
icon_url: "{{ sender.avatar_url }}",
url: "{{ sender.html_url }}"
},
title: "[{{ repository.name }}] `dependabot_alert` (`auto_dismissed`)",
url: "{{ repository.html_url }}",
color: color("black")
title: "[{{ repository.name }}] Dependabot alert **#{{ alert.number }}** automatically dismissed",
url: "{{ alert.html_url }}",
color: color("green")
}]
},{
action: "auto_reopened",
Expand All @@ -21,9 +21,9 @@ module.exports = [
icon_url: "{{ sender.avatar_url }}",
url: "{{ sender.html_url }}"
},
title: "[{{ repository.name }}] `dependabot_alert` (`auto_reopened`)",
url: "{{ repository.html_url }}",
color: color("black")
title: "[{{ repository.name }}] Dependabot alert **#{{ alert.number }}** automatically reopened",
url: "{{ alert.html_url }}",
color: color("red")
}]
},{
action: "created",
Expand All @@ -33,9 +33,10 @@ module.exports = [
icon_url: "{{ sender.avatar_url }}",
url: "{{ sender.html_url }}"
},
title: "[{{ repository.name }}] `dependabot_alert` (`created`)",
url: "{{ repository.html_url }}",
color: color("green")
title: "[{{ repository.name }}] Dependabot alert **#{{ alert.number }}** created for **{{ alert.dependency.package.name }}**",
url: "{{ alert.html_url }}",
description: "{{ alert.security_advisory.cve_id }}",
color: color("red")
}]
},{
action: "dismissed",
Expand All @@ -45,9 +46,10 @@ module.exports = [
icon_url: "{{ sender.avatar_url }}",
url: "{{ sender.html_url }}"
},
title: "[{{ repository.name }}] `dependabot_alert` (`dismissed`)",
url: "{{ repository.html_url }}",
color: color("black")
title: "[{{ repository.name }}] Dependabot alert **#{{ alert.number }}** dismissed for {{ alert.dismissed_reason }}",
url: "{{ alert.html_url }}",
description: "{{ alert.dismissed_comment }}",
color: color("yellow")
}]
},{
action: "fixed",
Expand All @@ -57,9 +59,9 @@ module.exports = [
icon_url: "{{ sender.avatar_url }}",
url: "{{ sender.html_url }}"
},
title: "[{{ repository.name }}] `dependabot_alert` (`fixed`)",
url: "{{ repository.html_url }}",
color: color("black")
title: "[{{ repository.name }}] Dependabot alert **#{{ alert.number }}** fixed",
url: "{{ alert.html_url }}",
color: color("green")
}]
},{
action: "reintroduced",
Expand All @@ -69,9 +71,9 @@ module.exports = [
icon_url: "{{ sender.avatar_url }}",
url: "{{ sender.html_url }}"
},
title: "[{{ repository.name }}] `dependabot_alert` (`reintroduced`)",
title: "[{{ repository.name }}] Dependabot alert **#{{ alert.number }}** reintroduced",
url: "{{ repository.html_url }}",
color: color("black")
color: color("red")
}]
},{
action: "reopened",
Expand All @@ -81,9 +83,9 @@ module.exports = [
icon_url: "{{ sender.avatar_url }}",
url: "{{ sender.html_url }}"
},
title: "[{{ repository.name }}] `dependabot_alert` (`reopened`)",
url: "{{ repository.html_url }}",
color: color("black")
title: "[{{ repository.name }}] Dependabot alert **#{{ alert.number }}** reopened",
url: "{{ alert.html_url }}",
color: color("yellow")
}]
}
]
15 changes: 8 additions & 7 deletions templates/deployment_review.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ module.exports = [
icon_url: "{{ sender.avatar_url }}",
url: "{{ sender.html_url }}"
},
title: "[{{ repository.name }}] `deployment_review` (`approved`)",
url: "{{ repository.html_url }}",
title: "[{{ repository.name }}:{{ workflow_run.head_branch }}] Deployment review approved {{ workflow_run.conclusion }}",
url: "{{ workflow_run.html_url }}",
description: "{{ comment }}",
color: color("green")
}]
},{
Expand All @@ -21,8 +22,8 @@ module.exports = [
icon_url: "{{ sender.avatar_url }}",
url: "{{ sender.html_url }}"
},
title: "[{{ repository.name }}] `deployment_review` (`rejected`)",
url: "{{ repository.html_url }}",
title: "[{{ repository.name }}:{{ workflow_run.head_branch }}] Deployment review rejected {{ workflow_run.conclusion }}",
url: "{{ workflow_run.html_url }}",
color: color("red")
}]
},{
Expand All @@ -33,9 +34,9 @@ module.exports = [
icon_url: "{{ sender.avatar_url }}",
url: "{{ sender.html_url }}"
},
title: "[{{ repository.name }}] `deployment_review` (`requested`)",
url: "{{ repository.html_url }}",
color: color("black")
title: "[{{ repository.name }}:{{ workflow_run.head_branch }}] Deployment review requested {{ workflow_run.conclusion }}",
url: "{{ workflow_run.html_url }}",
color: color("gray")
}]
}
]
Loading

0 comments on commit 13927be

Please sign in to comment.