Merge pull request #3 from Tyler-A/develop
IMPORTANT: Fix offline data storage
This commit is contained in:
commit
ee89814ac5
4 changed files with 11 additions and 10 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -1,4 +1,5 @@
|
|||
*.json
|
||||
*.data
|
||||
!package.json
|
||||
!tsconfig.json
|
||||
src/config.ts
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
//
|
||||
// Twitch.ts
|
||||
//
|
||||
// Written by: Tyler Akins (2020/01/06 - 2020/01/08)
|
||||
// Written by: Tyler Akins (2020/01/06 - 2020/01/09)
|
||||
//
|
||||
|
||||
|
||||
|
|
@ -71,10 +71,10 @@ export const START_BOT = async () => {
|
|||
.then((response: boolean) => {
|
||||
|
||||
// Ensure the user is live
|
||||
if (response) {
|
||||
if (!response) {
|
||||
data["offline"].total_bits += bits;
|
||||
data["offline"].donations.push(bits);
|
||||
data["offline"].donators.push(donator)
|
||||
data["offline"].donators.push(donator);
|
||||
} else {
|
||||
|
||||
// Data already exists
|
||||
|
|
|
|||
|
|
@ -7,4 +7,4 @@
|
|||
|
||||
export const TWITCH_URI: string = "https://api.twitch.tv/helix/streams";
|
||||
|
||||
export const DATAFILE: string = "data.temp.json";
|
||||
export const DATAPATH: string = "./data";
|
||||
12
src/utils.ts
12
src/utils.ts
|
|
@ -1,17 +1,17 @@
|
|||
//
|
||||
// utils.ts
|
||||
//
|
||||
// Written by: Tyler Akins (2020/01/06 - 2020/01/08)
|
||||
// Written by: Tyler Akins (2020/01/06 - 2020/01/09)
|
||||
//
|
||||
|
||||
|
||||
import { readFileSync, writeFileSync } from "fs"
|
||||
import { INDENT_DEPTH } from "./config";
|
||||
import { DATAFILE } from "./constants";
|
||||
import { INDENT_DEPTH, CHANNEL } from "./config";
|
||||
import { DATAPATH } from "./constants";
|
||||
|
||||
|
||||
|
||||
export const GET_FORMATTED_DATE = () => {
|
||||
export const GET_FORMATTED_DATE = (time=false) => {
|
||||
let date = new Date();
|
||||
|
||||
let year = date.getFullYear();
|
||||
|
|
@ -26,7 +26,7 @@ export const GET_FORMATTED_DATE = () => {
|
|||
|
||||
|
||||
export const LOAD_DATA = (): data => {
|
||||
let buffer = readFileSync(DATAFILE);
|
||||
let buffer = readFileSync(`${DATAPATH}/${CHANNEL}.data`);
|
||||
|
||||
// @ts-ignore
|
||||
return JSON.parse(buffer);
|
||||
|
|
@ -36,7 +36,7 @@ export const LOAD_DATA = (): data => {
|
|||
|
||||
export const WRITE_DATA = (data: data) => {
|
||||
writeFileSync(
|
||||
DATAFILE,
|
||||
`${DATAPATH}/${CHANNEL}.data`,
|
||||
JSON.stringify(data, null, INDENT_DEPTH)
|
||||
);
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue