Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
3 changes: 2 additions & 1 deletion config/vars.template.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
"OFFICE_STATUS_CHANNEL_ID": "CHANNEL_ID",
"RESUME_CHANNEL_ID": "CHANNEL_ID",
"IRC_USER_ID": "USER_ID",
"MOD_USER_ID_FOR_BAN_APPEAL": "USER_ID"
"MOD_USER_ID_FOR_BAN_APPEAL": "USER_ID",
"CRUNCHBASE_API_KEY": "CRUNCHBASE_KEY"
}
4 changes: 2 additions & 2 deletions docs/SETUP.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ Then, add your bot to the Discord testing server.
- `OFFICE_STATUS_CHANNEL_ID`: the ID of the office hours channel.
- `IRC_USER_ID`: the user ID of the irc-bridge bot.
- `MOD_USER_ID_FOR_BAN_APPEAL`: the user ID of the mod tagged in the appeal messages for bans.

Note that this file will not be pushed to the remote.
- `CRUNCHBASE_API_KEY`: api key if you wish to use the upcoming enroll company feature. (Create an account here)[https://www.crunchbase.com/home]. NOTE: feature is still under construction.
Note that this file will not be pushed to the remote.

6. Make an `.env` file in the root folder of the project, and put your Discord bot's token, which can be found in the Discord Developer Portal. The format of the `.env` file should be as follows.

Expand Down
36 changes: 36 additions & 0 deletions src/utils/companyinfo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { vars } from '../config';
import { isValidUrl } from './validateUrl';
import fetch from 'node-fetch';

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const getCompanyInfo = async (companyCrunchbaseLink: string) => {
// check if url contains crunchbase.com/organization
// if not, return null
if (
isValidUrl(companyCrunchbaseLink) &&
!companyCrunchbaseLink.includes('crunchbase.com/organization/')
) {
throw new Error('Invalid URL');
}

let companyName;
// check if urlPattern matches company_crunchbase_link
if (companyCrunchbaseLink.includes('crunchbase.com/organization/')) {
// grab everything after the last / character
companyName = companyCrunchbaseLink.split('/').pop();
} else {
// assume they just supplied the id
companyName = companyCrunchbaseLink;
}

const response = await fetch(
`https://api.crunchbase.com/api/v4/entities/organizations/${companyName}?user_key=${vars.CRUNCHBASE_API_KEY}&field_ids=categories,short_description`,
);
const data = await response.json();
if (data.error) {
throw new Error(data.error);
}
console.log(data);

return data;
};
12 changes: 12 additions & 0 deletions src/utils/validateUrl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export const isValidUrl = (url: string): boolean => {
const urlPattern = new RegExp(
'^(https?:\\/\\/)?' + // protocol
'((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|' + // domain name
'((\\d{1,3}\\.){3}\\d{1,3}))' + // OR ip (v4) address
'(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*' + // port and path
'(\\?[;&a-z\\d%_.~+=-]*)?' + // query string
'(\\#[-a-z\\d_]*)?$',
'i',
); // fragment locator
return urlPattern.test(url);
};