style(global): 🎨 format literally everything + update our secret loader for localdev

Signed-off-by: Andrei Jiroh Eugenio Halili <ajhalili2006@gmail.com>
This commit is contained in:
Andrei Jiroh Halili 2022-04-25 12:09:37 +00:00
parent 4503ce7450
commit 831016883a
21 changed files with 402 additions and 353 deletions

16
.eslintrc.js Normal file
View File

@ -0,0 +1,16 @@
module.exports = {
env: {
es6: true,
browser: true,
es2021: true,
},
extends: ["airbnb-base", "prettier", "plugin:prettier/recommended"],
parserOptions: {
ecmaVersion: 12,
sourceType: "module",
},
rules: {
"prettier/prettier": "error",
},
plugins: ["prettier"],
};

6
.prettierrc.js Normal file
View File

@ -0,0 +1,6 @@
module.exports = {
trailingComma: "es5",
tabWidth: 2,
semi: true,
singleQuote: false,
};

View File

@ -1,3 +1,5 @@
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN}); const lib = require("lib")({ token: process.env.STDLIB_SECRET_TOKEN });
return lib.discord.commands['@0.1.0'].list(); module.exports = async () => {
return lib.discord.commands["@0.1.0"].list();
};

View File

@ -1,12 +1,12 @@
const {loadEnvFromFile} = require("../../lib/secrets") const { loadEnvFromFile } = require("../../lib/secrets");
loadEnvFromFile() loadEnvFromFile();
const lib = require("lib")({ token: process.env.STDLIB_SECRET_TOKEN }) const lib = require("lib")({ token: process.env.STDLIB_SECRET_TOKEN });
module.exports = async(secret) => { module.exports = async (secret) => {
return { return {
headers: { headers: {
"Content-Type": "application/json; charset=utf-8" "Content-Type": "application/json; charset=utf-8",
}, },
body: Buffer.from(JSON.stringify(process.env)) body: Buffer.from(JSON.stringify(process.env)),
} };
} };

View File

@ -4,24 +4,28 @@
* into their server. If you want to add new commandshere, use https://autocode.com/tools/discord/command-builder/ * into their server. If you want to add new commandshere, use https://autocode.com/tools/discord/command-builder/
* to easily generate the code needed. * to easily generate the code needed.
*/ */
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN}); const lib = require("lib")({ token: process.env.STDLIB_SECRET_TOKEN });
const slashCommandsConfig = require("../../../../lib/slashCommands") const slashCommandsConfig = require("../../../../lib/slashCommands");
/** Internal commands go here **/ /** Internal commands go here **/
status = await lib.discord.commands['@0.0.0'].create(slashCommandsConfig.status); status = await lib.discord.commands["@0.0.0"].create(
slashCommandsConfig.status
);
/** After all of these, public commands go here **/ /** After all of these, public commands go here **/
gitConnect = await lib.discord.commands['@0.0.0'].create(slashCommandsConfig.connectGit); gitConnect = await lib.discord.commands["@0.0.0"].create(
verify = await lib.discord.commands['@0.0.0'].create(slashCommandsConfig.verify); slashCommandsConfig.connectGit
userLookup = await lib.discord.commands['@0.0.0'].create(slashCommandsConfig.userinfo); );
updateCommands = await lib.discord.commands['@0.0.0'].create(slashCommandsConfig.updateCommands); verify = await lib.discord.commands["@0.0.0"].create(
slashCommandsConfig.verify
);
userLookup = await lib.discord.commands["@0.0.0"].create(
slashCommandsConfig.userinfo
);
updateCommands = await lib.discord.commands["@0.0.0"].create(
slashCommandsConfig.updateCommands
);
return { return {
results: [ results: [status, gitConnect, verify, userLookup, updateCommands],
status, };
gitConnect,
verify,
userLookup,
updateCommands
]
}

View File

@ -1,32 +1,36 @@
// authenticates you with the API standard library // authenticates you with the API standard library
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN}); const lib = require("lib")({ token: process.env.STDLIB_SECRET_TOKEN });
let messageResponse = await lib.discord.channels['@0.0.6'].messages.create({ let messageResponse = await lib.discord.channels["@0.0.6"].messages.create({
channel_id: `${context.params.event.channel_id}`, channel_id: `${context.params.event.channel_id}`,
content: [ content: [
`Hey <@!${context.params.event.author.id}>! I'm a bot powered by Autocode, with love by the Recap Time Squad.`, `Hey <@!${context.params.event.author.id}>! I'm a bot powered by Autocode, with love by the Recap Time Squad.`,
`Currently, most of the commands are only available via slash commands to simplify our workflow.` `Currently, most of the commands are only available via slash commands to simplify our workflow.`,
].join('\n'), ].join("\n"),
embed: { embed: {
title: 'About the bot', title: "About the bot",
type: 'rich', type: "rich",
color: 0x00AA00, // Green color color: 0x00aa00, // Green color
description: 'We built this bot for Discord, among other bots elsewhere, to compliment our verification process for both creators and communities on our platforms in an open-source way.', description:
fields: [{ "We built this bot for Discord, among other bots elsewhere, to compliment our verification process for both creators and communities on our platforms in an open-source way.",
name: 'Where is the source code?', fields: [
value: [ {
'We\'re working on to make it open-source outside Autocode pretty soon. You could ask us to give you access to the project', name: "Where is the source code?",
'and also help us bring even more features to the bot.' value: [
].join(' ') "We're working on to make it open-source outside Autocode pretty soon. You could ask us to give you access to the project",
}, { "and also help us bring even more features to the bot.",
name: 'Link your Discord to GitHub/GitLab SaaS username', ].join(" "),
value: [ },
'Check out the documentation on how you can', {
'https://autocode.com/app/discord/basic-discord-example/' name: "Link your Discord to GitHub/GitLab SaaS username",
].join('\n') value: [
}] "Check out the documentation on how you can",
"https://autocode.com/app/discord/basic-discord-example/",
].join("\n"),
},
],
}, },
tts: false tts: false,
}); });
return messageResponse; return messageResponse;

View File

@ -1,17 +1,15 @@
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN}); const lib = require("lib")({ token: process.env.STDLIB_SECRET_TOKEN });
let userData = context.params.event.user let userData = context.params.event.user;
let urlEncodedData = { let urlEncodedData = {
user: encodeURIComponent(userData.username), user: encodeURIComponent(userData.username),
tag: userData.discriminator tag: userData.discriminator,
} };
let discordUserMinced = `${userData.username}#${userData.discriminator}` let discordUserMinced = `${userData.username}#${userData.discriminator}`;
let updateDiscordAccountLink = `https://community.fandom.com/wiki/Special:VerifyUser?user=${urlEncodedData.user}&tag=${urlEncodedData.tag}&ch=verify-${userData.id}` let updateDiscordAccountLink = `https://community.fandom.com/wiki/Special:VerifyUser?user=${urlEncodedData.user}&tag=${urlEncodedData.tag}&ch=verify-${userData.id}`;
function requestUserId(user) { function requestUserId(user) {
const result = todo const result = todo;
if (true) { if (true) {
} else { } else {
} }
} }

View File

@ -1,70 +1,70 @@
// authenticates you with the API standard library // authenticates you with the API standard library
// type `await lib.` to display API autocomplete // type `await lib.` to display API autocomplete
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN}); const lib = require("lib")({ token: process.env.STDLIB_SECRET_TOKEN });
// our admin role ID and the guild ID for perm checks. // our admin role ID and the guild ID for perm checks.
let role = `${process.env.DISCORD_ROLE_ID}`; let role = `${process.env.DISCORD_ROLE_ID}`;
let serverInfo = await lib.discord.guilds['@0.2.3'].retrieve({ let serverInfo = await lib.discord.guilds["@0.2.3"].retrieve({
guild_id: `${process.env.DISCORD_GUILD_ID}`, guild_id: `${process.env.DISCORD_GUILD_ID}`,
with_counts: false with_counts: false,
}); });
let serverOwner = serverInfo.owner_id let serverOwner = serverInfo.owner_id;
// if they have admin perms and sent from an guild we specified earlier // if they have admin perms and sent from an guild we specified earlier
// or if they're the server owner themselves. // or if they're the server owner themselves.
if (context.params.event.member.roles.includes(role) || context.params.event.member.user.id === serverOwner) { if (
context.params.event.member.roles.includes(role) ||
context.params.event.member.user.id === serverOwner
) {
/* fetch options from the payload */ /* fetch options from the payload */
let status = context.params.event.data.options[0].value; let status = context.params.event.data.options[0].value;
let type = context.params.event.data.options[1].value; let type = context.params.event.data.options[1].value;
let name = context.params.event.data.options[2].value; let name = context.params.event.data.options[2].value;
let url = context.params.event.data.options[3]; let url = context.params.event.data.options[3];
// Converting variable from URL option // Converting variable from URL option
if (!url) { if (!url) {
url = ''; url = "";
} else { } else {
url = url.value; url = url.value;
} }
await lib.discord.users["@0.1.5"].me.status.update({
await lib.discord.users['@0.1.5'].me.status.update({ activity_name: name,
activity_name: name, activity_type: type,
activity_type: type, status: status,
status: status, url: url,
url: url, });
});
// TODO: Make this message invokation visible to sender only.
// TODO: Make this message invokation visible to sender only. return await lib.discord.channels["@0.2.0"].messages.create({
return await lib.discord.channels['@0.2.0'].messages.create({ channel_id: `${context.params.event.channel_id}`,
channel_id: `${context.params.event.channel_id}`, content: ``,
content: ``, tts: false,
"tts": false, embeds: [
"embeds": [ {
{ type: "rich",
"type": "rich", title: `✅ Status message successfully updated`,
"title": `✅ Status message successfully updated`, description: `Your client should shown the changes immediately. Otherwise, please restart your Discord client.`,
"description": `Your client should shown the changes immediately. Otherwise, please restart your Discord client.`, color: 0x00ff4c,
"color": 0x00ff4c },
} ],
], response_type: "CHANNEL_MESSAGE_WITH_SOURCE",
response_type: 'CHANNEL_MESSAGE_WITH_SOURCE' });
}); } else {
} // send a error message about missing perms and also pinging people with that role
else { let deny = await lib.discord.channels["@0.2.0"].messages.create({
// send a error message about missing perms and also pinging people with that role channel_id: `${context.params.event.channel_id}`,
let deny = await lib.discord.channels['@0.2.0'].messages.create({ content: ``,
channel_id: `${context.params.event.channel_id}`, tts: false,
content: ``, embeds: [
tts: false, {
embeds: [ type: "rich",
{ title: `❌ You don't have enough permissions to do this!`,
"type": "rich", description: `<@${context.params.event.member.user.id}>, please ask a <@&${process.env.DISCORD_ROLE_ID}> to update te bot's status.`,
"title": `❌ You don't have enough permissions to do this!`, color: 0xff0000,
"description": `<@${context.params.event.member.user.id}>, please ask a <@&${process.env.DISCORD_ROLE_ID}> to update te bot's status.`, },
"color": 0xff0000 ],
} response_type: "CHANNEL_MESSAGE_WITH_SOURCE",
], });
response_type: 'CHANNEL_MESSAGE_WITH_SOURCE' }
});
}

View File

@ -1,10 +1,10 @@
// authenticates you with the API standard library // authenticates you with the API standard library
// type `await lib.` to display API autocomplete // type `await lib.` to display API autocomplete
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN}); const lib = require("lib")({ token: process.env.STDLIB_SECRET_TOKEN });
if (context.params.event.member.permission_names.includes("MANAGE_GUILD")) { if (context.params.event.member.permission_names.includes("MANAGE_GUILD")) {
return lib.discord.interactions['@1.0.1'].followups.ephemeral.create({ return lib.discord.interactions["@1.0.1"].followups.ephemeral.create({
token: `${context.params.event.token}`, token: `${context.params.event.token}`,
content: `<@${context.params.event.member.user.id}>, we're updated the slash commands for this server. If you still seeing old data, wait for up to an hour before retrying.\n\nIn case that didn't work, join the support server at https://discord.gg/5dURUcM under \`recaptime-support\` channel and let us know.` content: `<@${context.params.event.member.user.id}>, we're updated the slash commands for this server. If you still seeing old data, wait for up to an hour before retrying.\n\nIn case that didn't work, join the support server at https://discord.gg/5dURUcM under \`recaptime-support\` channel and let us know.`,
}); });
} }

View File

@ -1,95 +1,96 @@
// authenticates you with the API standard library // authenticates you with the API standard library
// type `await lib.` to display API autocomplete // type `await lib.` to display API autocomplete
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN}); const lib = require("lib")({ token: process.env.STDLIB_SECRET_TOKEN });
let ghFormTemplateLink = `https://github.com/${process.env.GH_NAMESPACE}/${process.env.GH_REPO_SLUG}/issues/new?assignees=ajhalili2006%2CRecapTimeSquad&labels=request-forms%3Anew-entries%2Cenhancement&template=verify-an-entry.yml&title=Request+to+verify+Entry+Name+Here` let ghFormTemplateLink = `https://github.com/${process.env.GH_NAMESPACE}/${process.env.GH_REPO_SLUG}/issues/new?assignees=ajhalili2006%2CRecapTimeSquad&labels=request-forms%3Anew-entries%2Cenhancement&template=verify-an-entry.yml&title=Request+to+verify+Entry+Name+Here`;
const { getEmbedTemplate } = require('../../../../lib/embeds/verify') const { getEmbedTemplate } = require("../../../../lib/embeds/verify");
msgTemplate = { msgTemplate = {
"content": `The embed below contains the instructions you needed to follow an the button links you need. When prompted for your Discord ID for verification, your ID can be copied from the account settings OR your profile when you enable \n\n⚠️**IMPORTANT: Never share your personal data, including your goernment IDs in the issue tracker.** An maintainer may ask you to provide these for the second stage of the verification process after getting the semi-verified status in a private setting.`, content: `The embed below contains the instructions you needed to follow an the button links you need. When prompted for your Discord ID for verification, your ID can be copied from the account settings OR your profile when you enable \n\n⚠️**IMPORTANT: Never share your personal data, including your goernment IDs in the issue tracker.** An maintainer may ask you to provide these for the second stage of the verification process after getting the semi-verified status in a private setting.`,
"tts": false, tts: false,
"components": [ components: [
{ {
"type": 1, type: 1,
"components": [ components: [
{ {
"style": 5, style: 5,
"label": `Submit new request`, label: `Submit new request`,
"url": `https://github.com/${process.env.GH_NAMESPACE}/${process.env.GH_REPO_SLUG}/issues/new?assignees=ajhalili2006%2CRecapTimeSquad&labels=request-forms%3Anew-entries%2Cenhancement&template=verify-an-entry.yml&title=Request+to+verify+Entry+Name+Here`, url: `https://github.com/${process.env.GH_NAMESPACE}/${process.env.GH_REPO_SLUG}/issues/new?assignees=ajhalili2006%2CRecapTimeSquad&labels=request-forms%3Anew-entries%2Cenhancement&template=verify-an-entry.yml&title=Request+to+verify+Entry+Name+Here`,
"disabled": false, disabled: false,
"type": 2 type: 2,
}, },
{ {
"style": 5, style: 5,
"label": `Recommended: Find existing issues first`, label: `Recommended: Find existing issues first`,
"url": `https://gitlab.com/RecapTime/verify/issues`, url: `https://gitlab.com/RecapTime/verify/issues`,
"disabled": false, disabled: false,
"type": 2 type: 2,
}, },
{ {
"style": 5, style: 5,
"label": `Learn more in project's README`, label: `Learn more in project's README`,
"url": `https://gitlab.com/RecapTime/veriy`, url: `https://gitlab.com/RecapTime/veriy`,
"disabled": false, disabled: false,
"type": 2 type: 2,
} },
] ],
} },
], ],
"embeds": [ embeds: [
{ {
"type": "rich", type: "rich",
"title": `Instructions on how do you get Verified role in Recap Time Squad's server + services`, title: `Instructions on how do you get Verified role in Recap Time Squad's server + services`,
"description": "", description: "",
"color": 0x00ff73, color: 0x00ff73,
"fields": [ fields: [
{ {
"name": `1. Press the button below to get the GitHub issue form.`, name: `1. Press the button below to get the GitHub issue form.`,
"value": `In case GitHub is down or our GitHub app is having some hicupps on copying issues, you can directly [submit on GitLab here](https://gitlab.com/RecapTime/verify/issues/new) and select \`Add new entry\` issue template.` value: `In case GitHub is down or our GitHub app is having some hicupps on copying issues, you can directly [submit on GitLab here](https://gitlab.com/RecapTime/verify/issues/new) and select \`Add new entry\` issue template.`,
}, },
{ {
"name": `2. Read instructions as prompted. Any incomplete issue will be then closed without notice by any of the maintainers.`, name: `2. Read instructions as prompted. Any incomplete issue will be then closed without notice by any of the maintainers.`,
"value": `In GitLab, instructions are written as HTML comments, so please read them carefully. We're working on an webapp to simplify this workflow pretty soon.` value: `In GitLab, instructions are written as HTML comments, so please read them carefully. We're working on an webapp to simplify this workflow pretty soon.`,
}, },
{ {
"name": `3. Once you're satisified, you can hit the \"Create issue\" button`, name: `3. Once you're satisified, you can hit the \"Create issue\" button`,
"value": `**REMEMBER TO CHECK IF THERE ARE ANY EXISTING OPEN ISSUES!** If there are any, even close one, make sure to stay in the loop. You can also submit an merge request then. (We require each MRs to have its own issue for tracking purposes.)` value: `**REMEMBER TO CHECK IF THERE ARE ANY EXISTING OPEN ISSUES!** If there are any, even close one, make sure to stay in the loop. You can also submit an merge request then. (We require each MRs to have its own issue for tracking purposes.)`,
} },
] ],
} },
] ],
} };
if (!context.params.event.user) { if (!context.params.event.user) {
await lib.discord.interactions['@1.0.0'].responses.ephemeral.create({ // we send an ephemeral message to the user confirming that the responses have been logged await lib.discord.interactions["@1.0.0"].responses.ephemeral.create({
// we send an ephemeral message to the user confirming that the responses have been logged
token: `${context.params.event.token}`, token: `${context.params.event.token}`,
content: `<@!${context.params.event.member.user.id}>`, content: `<@!${context.params.event.member.user.id}>`,
"tts": false, tts: false,
embeds: [ embeds: [
{ {
"type": "rich", type: "rich",
"title": `Check your DMs for instructions!`, title: `Check your DMs for instructions!`,
"description": `If you don't allow server members to DMs you, including bots, please adjust your privacy settings for this server.`, description: `If you don't allow server members to DMs you, including bots, please adjust your privacy settings for this server.`,
"color": 0x9900ff, color: 0x9900ff,
"image": { image: {
"url": `https://i.imgur.com/vbPYlw1.png`, url: `https://i.imgur.com/vbPYlw1.png`,
"height": 0, height: 0,
"width": 0 width: 0,
} },
} },
], ],
response_type: 'CHANNEL_MESSAGE_WITH_SOURCE', response_type: "CHANNEL_MESSAGE_WITH_SOURCE",
}); });
await lib.discord.users['@0.2.0'].dms.create({ await lib.discord.users["@0.2.0"].dms.create({
recipient_id: `${context.params.event.member.user.id}`, recipient_id: `${context.params.event.member.user.id}`,
content: msgTemplate.content, content: msgTemplate.content,
embeds: msgTemplate.embeds, embeds: msgTemplate.embeds,
components: msgTemplate.components components: msgTemplate.components,
}); });
} else { } else {
await lib.discord.channels['@0.3.1'].messages.create({ await lib.discord.channels["@0.3.1"].messages.create({
channel_id: `${context.params.event.channel_id}`, channel_id: `${context.params.event.channel_id}`,
content: msgTemplate.content, content: msgTemplate.content,
embeds: msgTemplate.embeds, embeds: msgTemplate.embeds,
components: msgTemplate.components components: msgTemplate.components,
}); });
} }

View File

@ -4,42 +4,43 @@
* @returns {any} result * @returns {any} result
*/ */
module.exports = async (event, context) => { module.exports = async (event, context) => {
// authenticates you with the API standard library // authenticates you with the API standard library
// type `await lib.` to display API autocomplete // type `await lib.` to display API autocomplete
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN}); const lib = require("lib")({ token: process.env.STDLIB_SECRET_TOKEN });
if (context.params.event.repository.owner.login == process.env.GH_NAMESPACE && context.params.event.repo == process.env.GH_REPO_SLUG) { if (
const issueMetadata = lib.github.issues['@0.3.5'].retrieve({ context.params.event.repository.owner.login == process.env.GH_NAMESPACE &&
owner: `${event.repository.owner.login}`, context.params.event.repo == process.env.GH_REPO_SLUG
repo: `${event.repository.name}`, ) {
issue_number: Number(`${event.issue.id}`) const issueMetadata = lib.github.issues["@0.3.5"].retrieve({
}); owner: `${event.repository.owner.login}`,
const issueBody = issueMetadata.body repo: `${event.repository.name}`,
let glApiResponse = lib.http.request['@1.1.6'].post({ issue_number: Number(`${event.issue.id}`),
});
const issueBody = issueMetadata.body;
let glApiResponse = lib.http.request["@1.1.6"].post({
url: `https://${process.env.GITLAB_HOST}/api/v3/projects/${process.env.GITLAB_PROJECT_ID}/issues`, url: `https://${process.env.GITLAB_HOST}/api/v3/projects/${process.env.GITLAB_PROJECT_ID}/issues`,
authorization: `${process.env.GITLAB_TOKEN}`, authorization: `${process.env.GITLAB_TOKEN}`,
params: { params: {
'title': `todo`, title: `todo`,
'body': `todo` body: `todo`,
} },
}); });
let closeThis = lib.github.issues['@0.3.5'].update({ let closeThis = lib.github.issues["@0.3.5"].update({
owner: `${event.repository.owner.login}`, owner: `${event.repository.owner.login}`,
repo: `${event.repository.name}`, repo: `${event.repository.name}`,
issue_number: Number(`${event.issue.number}`), issue_number: Number(`${event.issue.number}`),
state: 'closed' state: "closed",
}); });
return { return {
github: closeThis, github: closeThis,
gitlab: glApiResponse gitlab: glApiResponse,
} };
} else { } else {
return { return {
ok: false, ok: false,
error: "Repo name and owner login mismatch found!" error: "Repo name and owner login mismatch found!",
} };
} }
}; };

View File

@ -5,5 +5,5 @@
* @param {string} type What index we should * @param {string} type What index we should
*/ */
module.exports = async (username, type = "content_creator") => { module.exports = async (username, type = "content_creator") => {
return "todo" return "todo";
}; };

View File

@ -1,17 +1,20 @@
const { getRedirectUrl } = require('../../../lib/oauth/mw.js') const { getRedirectUrl } = require("../../../lib/oauth/mw.js");
module.exports = async (state = "abc123") => { module.exports = async (state = "abc123") => {
if (context.params.state) { if (context.params.state) {
return { return {
headers: {"Location": getRedirectUrl(context.params.state)}, headers: { Location: getRedirectUrl(context.params.state) },
statusCode: 302, statusCode: 302,
body: Buffer.from('') body: Buffer.from(""),
} };
} else { } else {
return { return {
headers: {"Location": "https://recaptime.miraheze.org/wiki/Portal:NoStateCodeDetected"}, headers: {
Location:
"https://recaptime.miraheze.org/wiki/Portal:NoStateCodeDetected",
},
statusCode: 302, statusCode: 302,
body: Buffer.from('') body: Buffer.from(""),
} };
} }
} };

View File

@ -1,16 +1,19 @@
const { getToken, getMe } = require('../../../lib/oauth/mw.js') const { getToken, getMe } = require("../../../lib/oauth/mw.js");
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN}); const lib = require("lib")({ token: process.env.STDLIB_SECRET_TOKEN });
module.exports = async (state, code) => { module.exports = async (state, code) => {
if (state) { if (state) {
if (state == "abc123") { if (state == "abc123") {
return getToken(code, state) return getToken(code, state);
} }
} else { } else {
return { return {
headers: {"Location": "https://recaptime.miraheze.org/wiki/Portal:NoStateCodeDetected"}, headers: {
Location:
"https://recaptime.miraheze.org/wiki/Portal:NoStateCodeDetected",
},
statusCode: 302, statusCode: 302,
body: Buffer.from('') body: Buffer.from(""),
} };
} }
} };

View File

@ -1,9 +1,8 @@
return { return {
statusCode: 404, statusCode: 404,
headers: {'Content-Type': 'application/json'}, headers: { "Content-Type": "application/json" },
body: { body: {
ok: false, ok: false,
error: "Endpoint not found" error: "Endpoint not found",
} },
}; };

View File

@ -1,39 +1,34 @@
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN}); const lib = require("lib")({ token: process.env.STDLIB_SECRET_TOKEN });
const slashCommandsConfig = require("../lib/slashCommands") const slashCommandsConfig = require("../lib/slashCommands");
try { try {
/** After all of these, public commands go here **/ /** After all of these, public commands go here **/
gitConnect = await lib.discord.commands['@0.0.0'].create({ gitConnect = await lib.discord.commands["@0.0.0"].create({
name: slashCommandsConfig.connectGit.name, name: slashCommandsConfig.connectGit.name,
description: slashCommandsConfig.connectGit.description, description: slashCommandsConfig.connectGit.description,
options: slashCommandsConfig.connectGit.options options: slashCommandsConfig.connectGit.options,
}); });
verify = await lib.discord.commands['@0.0.0'].create({ verify = await lib.discord.commands["@0.0.0"].create({
name: slashCommandsConfig.verify.name, name: slashCommandsConfig.verify.name,
description: slashCommandsConfig.verify.description} description: slashCommandsConfig.verify.description,
); });
userLookup = await lib.discord.commands['@0.0.0'].create({ userLookup = await lib.discord.commands["@0.0.0"].create({
name: slashCommandsConfig.userinfo.name, name: slashCommandsConfig.userinfo.name,
description: slashCommandsConfig.userinfo.description, description: slashCommandsConfig.userinfo.description,
options: slashCommandsConfig.userinfo.options options: slashCommandsConfig.userinfo.options,
}); });
updateCommands = await lib.discord.commands['@0.0.0'].create({ updateCommands = await lib.discord.commands["@0.0.0"].create({
name: slashCommandsConfig.updateCommands.name, name: slashCommandsConfig.updateCommands.name,
description: slashCommandsConfig.updateCommands.description description: slashCommandsConfig.updateCommands.description,
}); });
return { return {
statusCode: 200, statusCode: 200,
body: { body: {
ok: true, ok: true,
results: [ results: [gitConnect, verify, userLookup, updateCommands],
gitConnect, },
verify, };
userLookup,
updateCommands
]
}
}
} catch (err) { } catch (err) {
console.warn(err); console.warn(err);
return { return {
@ -41,7 +36,7 @@ try {
body: { body: {
ok: false, ok: false,
error: "Something went wrong.", error: "Something went wrong.",
traceback: err traceback: err,
} },
} };
} }

View File

@ -1,11 +1,9 @@
function getEmbedTemplate(userId, serverId, submissionType) { function getEmbedTemplate(userId, serverId, submissionType) {
if (submissionType == "content_creator") { if (submissionType == "content_creator") {
return { return {};
}
} }
} }
module.exports = { module.exports = {
getEmbedTemplate getEmbedTemplate,
} };

View File

@ -1,12 +1,44 @@
const mongoose = require('mongoose'); const mongoose = require("mongoose");
const Schema = mongoose.Schema; const Schema = mongoose.Schema;
const contentCreator = new Schema({ const index = new Schema({
name: String, name: String,
type: "content_creator", realName: {
annonations: Object type: String,
}) default: null
},
socials: {
discord: [
{
id: Number,
createdOn: Date,
discriminator: String
}
],
twitter: [
{
username: String,
id: Number,
createdOn: Date
}
],
miraheze: [{
username: String,
id: Number,
createdOn: Date
}],
telegram: [{
username: {
type: String,
default: null
},
id: Number
}]
},
type: "content_creator" || "community" || "entity",
annonations: Object,
});
module.exports = { module.exports = {
contentCreator index,
} };

View File

@ -1,25 +1,25 @@
const { loadEnvFromFile } = require("../secrets") const { loadEnvFromFile } = require("../secrets");
loadEnvFromFile() loadEnvFromFile();
const authroot = process.env.MW_OAUTH_ROOT; const authroot = process.env.MW_OAUTH_ROOT;
const authorize = `${authroot}/oauth2/authorize` const authorize = `${authroot}/oauth2/authorize`;
const token = `${authroot}/oauth2/access_token` const token = `${authroot}/oauth2/access_token`;
const profileurl = `${authroot}/oauth2/resource/profile` const profileurl = `${authroot}/oauth2/resource/profile`;
const axios = require('axios'); const axios = require("axios");
function getRedirectUrl (oauthState) { function getRedirectUrl(oauthState) {
let callback = encodeURIComponent(process.env.MW_OAUTH_CALLBACK) let callback = encodeURIComponent(process.env.MW_OAUTH_CALLBACK);
let str = `client_id=${process.env.MW_OAUTH_CLIENT_ID}&response_type=code&request_url=${callback}&state=${oauthState}` let str = `client_id=${process.env.MW_OAUTH_CLIENT_ID}&response_type=code&request_url=${callback}&state=${oauthState}`;
return `${authorize}?${str}` return `${authorize}?${str}`;
} }
/** /**
* Gets an OAuth2 access token from specific server * Gets an OAuth2 access token from specific server
* @param {"string"} respCode * @param {"string"} respCode
* @param {"string"} oauthState * @param {"string"} oauthState
* @returns * @returns
*/ */
function getToken (respCode, oauthState) { function getToken(respCode, oauthState) {
const oauthResult = axios(token, { const oauthResult = axios(token, {
method: "post", method: "post",
params: { params: {
@ -28,19 +28,19 @@ function getToken (respCode, oauthState) {
client_secret: process.env.MW_OAUTH_CLIENT_SECRET, client_secret: process.env.MW_OAUTH_CLIENT_SECRET,
redirect_url: process.env.MW_OAUTH_CALLBACK, redirect_url: process.env.MW_OAUTH_CALLBACK,
code: respCode, code: respCode,
state: oauthState state: oauthState,
} },
}) });
console.log(oauthResult); console.log(oauthResult);
return oauthResult return oauthResult;
} }
function getMe (token) { function getMe(token) {
// //
} }
module.exports = { module.exports = {
getRedirectUrl, getRedirectUrl,
getToken, getToken,
getMe getMe,
} };

View File

@ -4,32 +4,17 @@
* when doing API development using Gitpod/containers. * when doing API development using Gitpod/containers.
*/ */
function loadEnvFromFile() { function loadEnvFromFile() {
const fs = require('fs'); const fs = require("fs");
const env = require("../env.json")
fs.access("/opt/node_modules/autocode-common/configs", (err) => { if (process.env.LD == "/opt/node_modules/autocode-common/configs") {
if (err) { // noop
fs.access('env.json', (err) => { } else {
/** Object.keys(env.dev).forEach(function (key) {
* If env.json exists locally, attempt to load them automagically within the Node.js process. process.env[key] = env.dev[key]
*/ })
const env = require("../env.json") }
if (!err) {
process.env.MONGO_DATABASE = env.dev.MONGO_DATABASE
process.env.DISCORD_GUILD_ID = env.dev.DISCORD_GUILD_ID,
process.env.DISCORD_ROLE_ID = env.dev.DISCORD_GUILD_ID,
process.env.MW_OAUTH_CLIENT_ID = env.dev.MW_OAUTH_CLIENT_ID,
process.env.MW_OAUTH_CLIENT_SECRET = env.dev.MW_OAUTH_CLIENT_SECRET,
process.env.MW_MW_OAUTH_CALLBACK = env.dev.MW_OAUTH_CALLBACK,
process.env.MW_OAUTH_ROOT = env.dev.MW_OAUTH_ROOT
} else {
/** Otherwise, preload secrets using dotenv */
require("dotenv").config()
}
})
}
});
} }
module.exports = { module.exports = {
loadEnvFromFile loadEnvFromFile,
} };

View File

@ -1,28 +1,28 @@
module.exports = { module.exports = {
verify: { verify: {
name: 'verify', name: "verify",
description: description:
"Get you, your community or your company verified across Recap Time Squad's apps and through the API.", "Get you, your community or your company verified across Recap Time Squad's apps and through the API.",
options: [], options: [],
}, },
connectGit: { connectGit: {
name: 'connect-git', name: "connect-git",
description: description:
'Connect your Discord account to your GitHub/GitLab SaaS username. Rerun this when you change them.', "Connect your Discord account to your GitHub/GitLab SaaS username. Rerun this when you change them.",
options: [ options: [
{ {
type: 3, type: 3,
name: 'host', name: "host",
description: description:
"Git host we'll use to associate your CLA signature to your Discord account, among other things.", "Git host we'll use to associate your CLA signature to your Discord account, among other things.",
choices: [ choices: [
{ {
name: 'GitHub', name: "GitHub",
value: 'github.com', value: "github.com",
}, },
{ {
name: 'GitLab SaaS', name: "GitLab SaaS",
value: 'gitlab.com', value: "gitlab.com",
}, },
], ],
required: true, required: true,
@ -30,14 +30,14 @@ module.exports = {
], ],
}, },
userinfo: { userinfo: {
name: 'userinfo', name: "userinfo",
description: 'Query Discord user against the API for any associations.', description: "Query Discord user against the API for any associations.",
options: [ options: [
{ {
type: 6, type: 6,
name: 'target_user', name: "target_user",
description: description:
'Looks up either the mentioned Discord user or you against the API for any connected entries.', "Looks up either the mentioned Discord user or you against the API for any connected entries.",
}, },
], ],
}, },
@ -48,72 +48,74 @@ module.exports = {
options: [ options: [
{ {
type: 3, type: 3,
"name": "status", name: "status",
"description": "Set the bot's status on Discord", description: "Set the bot's status on Discord",
"choices": [ choices: [
{ {
"name": "Online", name: "Online",
"value": "ONLINE" value: "ONLINE",
}, },
{ {
"name": "Idle", name: "Idle",
"value": "IDLE" value: "IDLE",
}, },
{ {
"name": "Do Not Disturb", name: "Do Not Disturb",
"value": "DND" value: "DND",
}, },
{ {
"name": "Offline", name: "Offline",
"value": "INVISIBLE" value: "INVISIBLE",
} },
], ],
"required": true required: true,
}, },
{ {
"type": 3, type: 3,
"name": "type", name: "type",
"description": "Set the bot's activity type.", description: "Set the bot's activity type.",
"choices": [ choices: [
{ {
"name": "Playing", name: "Playing",
"value": "GAME" value: "GAME",
}, },
{ {
"name": "Watching", name: "Watching",
"value": "WATCHING" value: "WATCHING",
}, },
{ {
"name": "Listening to", name: "Listening to",
"value": "LISTENING" value: "LISTENING",
}, },
{ {
"name": "Competing in", name: "Competing in",
"value": "COMPETING" value: "COMPETING",
}, },
{ {
"name": "Streaming", name: "Streaming",
"value": "STREAMING" value: "STREAMING",
} },
], ],
"required": true required: true,
}, },
{ {
"type": 3, type: 3,
"name": "name", name: "name",
"description": "Set the name of your activity", description: "Set the name of your activity",
"required": true required: true,
}, },
{ {
"type": 3, type: 3,
"name": "url", name: "url",
"description": "The URL your streaming status will link to. (Works on Streaming status only)" description:
} "The URL your streaming status will link to. (Works on Streaming status only)",
] },
],
}, },
updateCommands: { updateCommands: {
name: "update-commands", name: "update-commands",
description: "Refreshes slash commands for this guild. Requires Manage Server perm to do this.", description:
"Refreshes slash commands for this guild. Requires Manage Server perm to do this.",
options: [], options: [],
} },
}; };