-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2fef85b
commit da0e59e
Showing
3 changed files
with
83 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
const { EmbedBuilder } = require('discord.js'); | ||
const moment = require('moment'); | ||
const config = require('../config.json'); | ||
|
||
/** | ||
* send embed message | ||
* @param {string} message | ||
* @returns pre-defined embed style | ||
*/ | ||
const sendEmbedMessage = (message) => { | ||
return new EmbedBuilder() | ||
.setDescription(message) | ||
.setColor(`#f213a4`); | ||
} | ||
|
||
/** | ||
* format time according to UTC | ||
* @param {number} date - epoch timestamp | ||
* @returns time and date format | ||
*/ | ||
const formatTime = (date) => { | ||
return moment.utc(date).utcOffset(config.utc_offset).format('M/DD/YYYY HH:mm:ss'); | ||
} | ||
|
||
/** | ||
* get username from ownerid/author.id | ||
* @param {number} id user's id | ||
* @returns | ||
*/ | ||
const getUsernameFromId = async (id) => { | ||
return (await client.users.fetch(id)).username; | ||
} | ||
|
||
module.exports = { | ||
sendEmbedMessage, | ||
formatTime, | ||
getUsernameFromId | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
const config = require('../config.json'); | ||
const { GoogleSpreadsheet } = require('google-spreadsheet'); | ||
require('dotenv').config(); | ||
|
||
// load the spreadsheet | ||
const doc = new GoogleSpreadsheet(process.env.GOOGLE_SPREADSHEET_ID); | ||
|
||
/** | ||
* sends data to the spreadsheet | ||
* @param {object} data - data being added as row in the spreadsheet | ||
* @param {string} datasheet - name of sheet where data being sent e.g. init, response, resolve | ||
*/ | ||
const sendData = async (data, datasheet) => { | ||
// authenticate | ||
await doc.useServiceAccountAuth({ | ||
client_email: process.env.GOOGLE_SERVICE_ACCOUNT_EMAIL, | ||
private_key: process.env.GOOGLE_PRIVATE_KEY.replace(/\\n/g, "\n"), | ||
}); | ||
// load the "initial" sheet | ||
await doc.loadInfo(); | ||
const sheet = doc.sheetsByTitle[datasheet]; | ||
|
||
// check if the data will be send to init sheet | ||
if (datasheet === config.datasheet_init) { | ||
await sheet.addRow(data); | ||
}; | ||
|
||
// check if the data will be send to response sheet | ||
if (datasheet === config.datasheet_response) { | ||
await sheet.addRow(data); | ||
} | ||
|
||
// check if the data will be send to resolve sheet | ||
if (datasheet === config.datasheet_resolve) { | ||
await sheet.addRow(data); | ||
}; | ||
} | ||
|
||
module.exports = { | ||
sendData | ||
} |