feat(server/debug): Added initial implementation of new Logger (#84)

- Logs out to a file w/ relevant meta data
- Provides better readability for end user

This should help provide better troubleshooting for both
development and end users.

This also fixes any previous catches that were attempting to print stack traces,
causing the [object Object] message to appear.

Co-authored-by: Christopher Gjelten <[email protected]>
This commit is contained in:
TasoandChristopher Gjelten authored and GitHub committed 2021-02-14 17:28:13 -05:00
1 parent a5491302b6
commit 211576e237
18 files changed
+363 -114

No files matched your search

+4 -1
View File
@@ -14,4 +14,7 @@ yarn-debug.log*
yarn-error.log*
# Mac thing
.DS_Store
.DS_Store
# Debug logs
sv_npwd.log
+4
View File
@@ -29,5 +29,9 @@
},
"bank": {
"showNotifications": true
},
"debug": {
"level": "debug",
"enabled": true
}
}
+6
View File
@@ -12,6 +12,11 @@ interface TwitterConfig {
maxImages: number;
}
interface Debug {
level: 'error' | 'warn' | 'info' | 'verbose' | 'debug';
enabled: boolean;
}
interface General {
useDashNumber: boolean;
}
@@ -38,4 +43,5 @@ export interface IServerConfig {
bank: BankConfig;
notificationPosition: NotificationConfig;
general: General;
debug: Debug;
}
+2 -1
View File
@@ -27,7 +27,8 @@
"fivem-js": "^1.3.1",
"md5": "^2.3.0",
"mysql2": "^2.2.5",
"uuid": "^8.3.2"
"uuid": "^8.3.2",
"winston": "^3.3.3"
},
"devDependencies": {
"@babel/preset-env": "^7.12.1",
+48 -37
View File
@@ -8,13 +8,16 @@ import {
getUserId,
getPassword,
} from './db_utils';
import { mainLogger } from './sv_logger';
// we require set mysql_connection_string to be set in the config
const mysqlConnectionString = GetConvar(CONNECTION_STRING, null);
if (mysqlConnectionString === null) {
throw new Error(
`No connection string provided. make sure "${CONNECTION_STRING} is set in your config.`
const mysqlConnectionString = GetConvar(CONNECTION_STRING, 'none');
if (mysqlConnectionString === 'none') {
const error = new Error(
`No connection string provided. make sure "${CONNECTION_STRING}" is set in your config.`
);
mainLogger.error(error.message);
throw error;
}
/**
@@ -26,39 +29,45 @@ if (mysqlConnectionString === null) {
* https://brouznouf.github.io/fivem-mysql-async/config/ and we need to handle both of them.
*/
export function generateConnectionPool() {
if (mysqlConnectionString.includes('database=')) {
// This is checking for this format:
// set mysql_connection_string "server=127.0.0.1;database=es_extended;userid=user;password=pass"
const config = parseSemiColonFormat(mysqlConnectionString);
return mysql.createPool({
host: getServerHost(config),
user: getUserId(config),
port: config.port ? parseInt(config.port) : DEFAULT_PORT,
password: getPassword(config),
database: config.database,
waitForConnections: true,
connectionLimit: 10,
queueLimit: 0,
});
} else {
// This is checking for this format:
// set mysql_connection_string "mysql://root:[email protected]/es_extended?charset=utf8mb4"
const connectionStringParser = new ConnectionStringParser({
scheme: 'mysql',
hosts: [],
});
const connectionOjbect = connectionStringParser.parse(
mysqlConnectionString
);
try {
if (mysqlConnectionString.includes('database=')) {
// This is checking for this format:
// set mysql_connection_string "server=127.0.0.1;database=es_extended;userid=user;password=pass"
const config = parseSemiColonFormat(mysqlConnectionString);
return mysql.createPool({
host: getServerHost(config),
user: getUserId(config),
port: config.port ? parseInt(config.port) : DEFAULT_PORT,
password: getPassword(config),
database: config.database,
waitForConnections: true,
connectionLimit: 10,
queueLimit: 0,
});
} else {
// This is checking for this format:
// set mysql_connection_string "mysql://root:[email protected]/es_extended?charset=utf8mb4"
const connectionStringParser = new ConnectionStringParser({
scheme: 'mysql',
hosts: [],
});
const connectionOjbect = connectionStringParser.parse(
mysqlConnectionString
);
return mysql.createPool({
host: connectionOjbect.hosts[0].host,
user: connectionOjbect.username,
password: connectionOjbect.password,
database: connectionOjbect.endpoint,
waitForConnections: true,
connectionLimit: 10,
queueLimit: 0,
return mysql.createPool({
host: connectionOjbect.hosts[0].host,
user: connectionOjbect.username,
password: connectionOjbect.password,
database: connectionOjbect.endpoint,
waitForConnections: true,
connectionLimit: 10,
queueLimit: 0,
});
}
} catch (e) {
mainLogger.error(`SQL Connection Pool Error: ${e.message}`, {
connection: mysqlConnectionString,
});
}
}
@@ -75,7 +84,9 @@ export async function withTransaction(queries: Promise<any>[]): Promise<any[]> {
await connection.release();
return results;
} catch (err) {
console.warn('Error when submitting queries');
mainLogger.warn(
`Error when submitting queries in transaction, ${err.message}`
);
await connection.rollback();
await connection.release();
return Promise.reject(err);
+4 -1
View File
@@ -2,6 +2,9 @@ import axios from 'axios';
import { Tweet, Profile } from '../../phone/src/common/typings/twitter';
import { IMAGE_DELIMITER } from '../../phone/src/apps/twitter/utils/images';
import { mainLogger } from './sv_logger';
const discordLogger = mainLogger.child({ module: 'discord' });
const DISCORD_TOKEN_ENV_VAR = 'discord_bot_token';
const DISCORD_TOKEN = GetConvar(DISCORD_TOKEN_ENV_VAR, '');
@@ -17,7 +20,7 @@ export async function reportTweetToDiscord(
reportingProfile: Profile
): Promise<any> {
if (!DISCORD_TOKEN || !DISCORD_CHANNEL_ID) {
console.warn(`Got a request to report a tweet but discord is not
discordLogger.warn(`Got a request to report a tweet but discord is not
configured. See README on how to configure discord endpoints.`);
return;
}
+8 -1
View File
@@ -10,9 +10,16 @@ import './sv_notes';
import './sv_photo';
import './sv_messages';
import './sv_call';
import { mainLogger } from './sv_logger';
export let ESX: Server = null;
export const getSource = () => (global as any).source;
emit('esx:getSharedObject', (obj: Server) => (ESX = obj));
emit('esx:getSharedObject', (obj: Server) => (ESX = obj));
on('onServerResourceStart', (resource: string) => {
if (resource === GetCurrentResourceName()) {
mainLogger.info('Sucessfully started');
}
});
+15 -6
View File
@@ -7,7 +7,9 @@ import {
IBankCredentials,
} from '../../phone/src/common/typings/bank';
import { useIdentifier } from './functions';
import { type } from 'os';
import { mainLogger } from './sv_logger';
const bankLogger = mainLogger.child({ module: 'bank' });
async function fetchAllTransactions(identifier: string): Promise<Transfer[]> {
const query =
@@ -15,6 +17,10 @@ async function fetchAllTransactions(identifier: string): Promise<Transfer[]> {
const [results] = await pool.query(query, [identifier]);
const transactions = <Transfer[]>results;
bankLogger.verbose(
`Fetched all transactions (${identifier}) - ${JSON.stringify(transactions)}`
);
return transactions;
}
@@ -27,6 +33,8 @@ function fetchCredentials(): IBankCredentials {
balance,
};
bankLogger.verbose(`Fetching banking credentials - ${name} - ${balance}`);
return result;
}
@@ -83,8 +91,8 @@ onNet(events.BANK_FETCH_TRANSACTIONS, async () => {
const transfer = await fetchAllTransactions(_identifier);
emitNet(events.BANK_SEND_TRANSFERS, _source, transfer);
} catch (error) {
console.log('Failed to fetch transactions');
} catch (e) {
bankLogger.error(`Failed to fetch transactions, ${e.message}`);
}
});
@@ -95,7 +103,8 @@ onNet(events.BANK_ADD_TRANSFER, async (transfer: Transfer) => {
const transferNotify = await addTransfer(_identifier, transfer);
emitNet(events.BANK_TRANSACTION_NOTIFICATION, xTarget, transferNotify);
emitNet(events.BANK_ADD_TRANSFER_SUCCESS, getSource());
} catch (error) {
} catch (e) {
bankLogger.error(`Failed to add transaction, ${e.message}`);
emitNet(events.BANK_TRANSACTION_ALERT, getSource(), false);
}
});
@@ -104,7 +113,7 @@ onNet(events.BANK_GET_CREDENTIALS, () => {
try {
const credentials = fetchCredentials();
emitNet(events.BANK_SEND_CREDENTIALS, getSource(), credentials);
} catch (error) {
console.log('Failed to fetch credentials');
} catch (e) {
bankLogger.error(`Failed to fetch credentials, ${e.message}`);
}
});
+9 -8
View File
@@ -10,8 +10,9 @@ import { ICall } from '../../phone/src/common/typings/call';
import { pool } from './db';
import { v4 as uuidv4 } from 'uuid';
import { ConnectionStringParser } from 'connection-string-parser';
import { time } from 'console';
import { mainLogger } from './sv_logger';
const callLogger = mainLogger.child({ module: 'calls' });
/**
* Returns the player phoneNumber for a passed identifier
@@ -139,8 +140,8 @@ onNet(events.PHONE_ACCEPT_CALL, async (transmitterNumber: string) => {
currentCall,
true
);
} catch (error) {
console.log(error, error.message);
} catch (e) {
callLogger.error('Accepting Call Error', e.message);
}
});
@@ -157,8 +158,8 @@ onNet(
// player who is calling
emitNet(events.PHONE_CALL_WAS_REJECTED, currentCall.transmitterSource);
} catch (error) {
console.log(error, error.message);
} catch (e) {
callLogger.error(`Phone Call Rejected Event Error ${e.message}`);
}
}
);
@@ -180,8 +181,8 @@ onNet(
emitNet(events.PHONE_CALL_WAS_ENDED, currentCall.transmitterSource);
calls.delete(transmitterNumber);
} catch (error) {
console.log(error, error.message);
} catch (e) {
callLogger.error(`Error ending Phone Call, ${e.message}`);
}
}
);
+21 -28
View File
@@ -2,6 +2,9 @@ import { ESX } from './server';
import { pool } from './db';
import events from '../utils/events';
import { useIdentifier, getSource } from './functions';
import { mainLogger } from './sv_logger';
const contactsLogger = mainLogger.child({ module: 'contact' });
interface Contacts {
id?: number;
@@ -70,8 +73,8 @@ onNet(events.CONTACTS_GET_CONTACTS, async () => {
const contacts = await fetchAllContacts(_identifier);
emitNet(events.CONTACTS_SEND_CONTACTS, _source, contacts);
} catch (error) {
console.log('Failed to fetch contacts: ', error);
} catch (e) {
contactsLogger.error(`Failed to fetch contacts, ${e.message}`);
}
});
@@ -83,43 +86,32 @@ onNet(
const _identifier = await useIdentifier();
addContact(_identifier, number, display, avatar);
emitNet(events.CONTACTS_ADD_CONTACT_SUCCESS, _source);
emitNet(
events.CONTACTS_ACTION_RESULT,
_source,
"CONTACT_ADD_SUCCESS"
);
} catch (error) {
emitNet(events.CONTACTS_ACTION_RESULT, _source, 'CONTACT_ADD_SUCCESS');
} catch (e) {
const _source = (global as any).source;
emitNet(events.CONTACTS_ACTION_RESULT, _source, "CONTACT_ADD_FAILED");
emitNet(events.CONTACTS_ACTION_RESULT, _source, 'CONTACT_ADD_FAILED');
contactsLogger.error(`Failed to add contact, ${e.message}`);
}
}
);
onNet(events.CONTACTS_UPDATE_CONTACT, async (contact: Contacts) => {
console.log('let me just log the contact first', contact);
try {
const _source = (global as any).source;
const _identifier = ESX.GetPlayerFromId(_source).getIdentifier();
console.log('nice identifier bro', _identifier);
// console.log('nice identifier bro', _identifier);
await updateContact(contact, _identifier);
console.log('i updated the contact server side!');
// console.log('i updated the contact server side!');
emitNet(events.CONTACTS_UPDATE_CONTACT_SUCCESS, _source);
console.log('ffs, didd it return successful');
emitNet(
events.CONTACTS_ACTION_RESULT,
_source,
"CONTACT_UPDATE_SUCCESS"
);
console.log("UPDATED CONTACT: ", contact);
} catch (error) {
// console.log('ffs, didd it return successful');
emitNet(events.CONTACTS_ACTION_RESULT, _source, 'CONTACT_UPDATE_SUCCESS');
// console.log('UPDATED CONTACT: ', contact);
} catch (e) {
const _source = (global as any).source;
emitNet(
events.CONTACTS_ACTION_RESULT,
_source,
"CONTACT_UPDATE_FAILED"
);
emitNet(events.CONTACTS_ACTION_RESULT, _source, 'CONTACT_UPDATE_FAILED');
contactsLogger.error(`Failed to update contact, ${e.message}`);
}
});
@@ -133,7 +125,8 @@ onNet(events.CONTACTS_DELETE_CONTACT, async (contact: ContactId) => {
getSource(),
'CONTACT_DELETE_SUCCESS'
);
} catch (error) {
} catch (e) {
contactsLogger.error(`Failed to delete contact, ${e.message}`);
emitNet(
events.CONTACTS_ACTION_RESULT,
getSource(),
+42
View File
@@ -0,0 +1,42 @@
import winston from 'winston';
import config from '../utils/config';
import path from 'path';
// Needed to manually apply a color to componenent property of log
const manualColorize = (strToColor: string): string =>
`[\x1b[35m${strToColor}\x1b[0m]`;
// Format handler passed to winston
const formatLogs = (log: winston.Logform.TransformableInfo): string => {
if (log.module)
return `${log.label} ${manualColorize(log.module)} [${log.level}]: ${
log.message
}`;
return `${log.label} [${log.level}]: ${log.message}`;
};
const findLogPath = () =>
`${path.join(GetResourcePath(GetCurrentResourceName()), 'sv_npwd.log')}`;
// Initiate the main logger for NPWD
export const mainLogger = winston.createLogger({
level: config.debug.level,
transports: [
new winston.transports.File({
filename: findLogPath(),
format: winston.format.combine(
winston.format.errors({ stack: true }),
winston.format.timestamp(),
winston.format.json()
),
}),
new winston.transports.Console({
format: winston.format.combine(
winston.format.label({ label: '[NPWD]' }),
winston.format.colorize({ all: true }),
winston.format.printf(formatLogs)
),
}),
],
});
+5 -2
View File
@@ -2,6 +2,7 @@ import { ESX } from './server';
import { pool } from './db';
import config from '../utils/config';
import { getIdentifierByPhoneNumber, usePhoneNumber } from './functions';
import { mainLogger } from './sv_logger';
//db = DatabaseConfig //helper variable for use in server function
@@ -30,6 +31,8 @@ function getRandomPhoneNumber() {
// Example: 123-4567
}
mainLogger.verbose(`Getting random number: ${randomNumber}`);
return randomNumber;
}
@@ -69,7 +72,7 @@ onNet('phone:getCredentials', async () => {
const _identifier = xPlayer.getIdentifier();
const number = await getCredentials(_identifier);
emitNet('phone:sendCredentials', _source, number);
} catch (error) {
console.log('Failed to get number. ', error);
} catch (e) {
mainLogger.error(`Failed to get a number, ${e.message}`);
}
});
+7
View File
@@ -8,6 +8,9 @@ import {
} from '../../phone/src/common/typings/messages';
import { pool, withTransaction } from './db';
import { getSource, useIdentifier } from './functions';
import { mainLogger } from './sv_logger';
const messageLogger = mainLogger.child({ module: 'messages' });
/**
* Used for the raw npwd_messages_groups row responses
@@ -383,6 +386,7 @@ onNet(events.MESSAGES_FETCH_MESSAGE_GROUPS, async () => {
);
} catch (e) {
emitNet(events.MESSAGES_FETCH_MESSAGE_GROUPS_FAILED, getSource());
messageLogger.error(`Failed to fetch messages groups, ${e.message}`);
}
});
@@ -412,6 +416,7 @@ onNet(
}
} catch (e) {
emitNet(events.MESSAGES_CREATE_MESSAGE_GROUP_FAILED, getSource());
messageLogger.error(`Failed to create message group, ${e.message}`);
}
}
);
@@ -423,6 +428,7 @@ onNet(events.MESSAGES_FETCH_MESSAGES, async (groupId: string) => {
emitNet(events.MESSAGES_FETCH_MESSAGES_SUCCESS, getSource(), messages);
} catch (e) {
emitNet(events.MESSAGES_FETCH_MESSAGES_FAILED, getSource());
messageLogger.error(`Failed to fetch messages, ${e.message}`);
}
});
@@ -435,6 +441,7 @@ onNet(
emitNet(events.MESSAGES_SEND_MESSAGE_SUCCESS, getSource(), groupId);
} catch (e) {
emitNet(events.MESSAGES_SEND_MESSAGE_FAILED, getSource());
messageLogger.error(`Failed to send message, ${e.message}`);
}
}
);
+16 -14
View File
@@ -1,7 +1,10 @@
import events from '../utils/events';
import { pool } from './db';
import { useIdentifier, getSource } from './functions';
import { useIdentifier } from './functions';
import { Note, NoteId } from '../../phone/src/common/typings/notes';
import { mainLogger } from './sv_logger';
const notesLogger = mainLogger.child({ module: 'notes' });
async function addNote(identifier: string, note: Note): Promise<any> {
const query =
@@ -29,27 +32,26 @@ async function updateNote(note: Note, identifier: string): Promise<any> {
onNet(events.NOTE_ADD_NOTE, async (note: Note) => {
try {
const pSource = (global as any).source
const pSource = (global as any).source;
const _identifier = await useIdentifier();
await addNote(_identifier, note);
emitNet(events.NOTE_SEND_NOTE_SUCCESS, pSource);
emitNet(events.NOTE_ACTION_RESULT, pSource, { message: 'NOTES_ADD_SUCCESS', type: 'success' })
} catch (error) {
const pSource = (global as any).source
} catch (e) {
const pSource = (global as any).source;
notesLogger.error(`Failed to add note ${e.message}`);
emitNet(events.NOTE_ACTION_RESULT, pSource, { message: 'NOTES_ADD_FAILED', type: 'error' })
}
});
onNet(events.NOTE_FETCH_ALL_NOTES, async () => {
try {
const pSource = (global as any).source
const pSource = (global as any).source;
const _identifier = await useIdentifier();
const notes = await fetchAllNotes(_identifier);
emitNet(events.NOTE_SEND_NOTE, pSource, notes);
} catch (error) {
console.dir(error)
} catch (e) {
notesLogger.error(`Failed to fetch notes ${e.message}`);
}
});
@@ -60,9 +62,9 @@ onNet(events.NOTE_DELETE_NOTE, async (noteId: NoteId) => {
await deleteNote(noteId.id, _identifier);
emitNet(events.NOTE_ACTION_RESULT, pSource, { message: 'NOTES_DELETE_SUCCESS', type: 'success' })
} catch (error) {
} catch (e) {
const pSource = (global as any).source;
notesLogger.error(`Failed to delete note, ${e.message}`);
emitNet(events.NOTE_ACTION_RESULT, pSource, { message: 'NOTES_DELETE_FAILED', type: 'error' })
}
});
@@ -73,12 +75,12 @@ onNet(events.NOTE_UPDATE_NOTE, async (note: Note) => {
const _identifier = await useIdentifier();
await updateNote(note, _identifier);
emitNet(events.NOTE_UPDATE_NOTE_SUCCESS, pSource);
emitNet(events.NOTE_ACTION_RESULT, pSource, { message: 'NOTES_UPDATE_SUCCESS', type: 'success' })
} catch (error) {
} catch (e) {
const pSource = (global as any).source;
emitNet(events.NOTE_UPDATE_NOTE_FAILURE, pSource);
notesLogger.error(`Failed to update note, ${e.message}`);
emitNet(events.NOTE_ACTION_RESULT, pSource, { message: 'NOTES_UPDATE_FAILED', type: 'error' })
}
});
+8 -6
View File
@@ -1,8 +1,11 @@
import events from '../utils/events';
import { ESX, getSource } from './server';
import { getSource } from './server';
import { pool } from './db';
import { useIdentifier } from './functions';
import { IPhoto } from '../../phone/src/common/typings/photo';
import { mainLogger } from './sv_logger';
const photoLogger = mainLogger.child({ module: 'photo' });
async function uploadPhoto(identifier: string, image: string) {
const query =
@@ -22,7 +25,6 @@ async function deletePhoto(photo: IPhoto, identifier: string) {
const query =
'DELETE FROM npwd_phone_gallery WHERE id = ? AND identifier = ?';
await pool.query(query, [photo.id, identifier]);
console.log(photo.id);
}
onNet(events.CAMERA_UPLOAD_PHOTO, async (image: string) => {
@@ -31,8 +33,8 @@ onNet(events.CAMERA_UPLOAD_PHOTO, async (image: string) => {
const identifier = await useIdentifier();
await uploadPhoto(identifier, image);
emitNet(events.CAMERA_UPLOAD_PHOTO_SUCCESS, pSource);
} catch (error) {
console.dir(error)
} catch (e) {
photoLogger.error(`Failed to upload photo, ${e.message}`);
}
});
@@ -47,7 +49,7 @@ onNet(events.CAMERA_DELETE_PHOTO, async (photo: IPhoto) => {
const identifier = await useIdentifier();
await deletePhoto(photo, identifier);
emitNet(events.CAMERA_DELETE_PHOTO_SUCCESS, getSource());
} catch (error) {
console.log(error);
} catch (e) {
photoLogger.error(`Failed to fetch photos, ${e.message}`);
}
});
+7 -4
View File
@@ -3,6 +3,9 @@ import { ESX } from './server';
import { getSource } from './functions';
import { pool } from './db';
import { usePhoneNumber } from './functions';
import { mainLogger } from './sv_logger';
const selloutLogger = mainLogger.child({ module: 'sellout' });
interface Listing {
title: string;
@@ -43,8 +46,8 @@ onNet(events.SELLOUT_FETCH_LISTING, async () => {
const _source = (global as any).source;
const listings = await fetchAllListings();
emitNet(events.SELLOUT_SEND_LISTING, _source, listings);
} catch (error) {
console.log(error);
} catch (e) {
selloutLogger.error(`Failed to fetch listings, ${e.message}`);
}
});
@@ -56,7 +59,7 @@ onNet(events.SELLOUT_ADD_LISTING, async (listing: Listing) => {
const phoneNumber = await usePhoneNumber(_identifier);
addListing(_identifier, name, phoneNumber, listing);
} catch (error) {
console.log('Failed to add contact: ', error);
} catch (e) {
selloutLogger.error(`Failed to add listing ${e.message}`);
}
});
+12 -1
View File
@@ -5,6 +5,9 @@ import { Tweet, Profile } from '../../phone/src/common/typings/twitter';
import events from '../utils/events';
import config from '../utils/config';
import { reportTweetToDiscord } from './discord';
import { mainLogger } from './sv_logger';
const twitterLogger = mainLogger.child({ module: 'twitter' });
interface ProfileName {
profile_name: string;
@@ -295,6 +298,7 @@ onNet(events.TWITTER_GET_OR_CREATE_PROFILE, async () => {
const profile = await getOrCreateProfile(identifier);
emitNet(events.TWITTER_GET_OR_CREATE_PROFILE_SUCCESS, getSource(), profile);
} catch (e) {
twitterLogger.error(`Failed to get or create profile, ${e.message}`);
emitNet(events.TWITTER_GET_OR_CREATE_PROFILE_FAILURE, getSource());
}
});
@@ -305,6 +309,7 @@ onNet(events.TWITTER_UPDATE_PROFILE, async (profile: Profile) => {
await updateProfile(identifier, profile);
emitNet(events.TWITTER_UPDATE_PROFILE_RESULT, getSource(), true);
} catch (e) {
twitterLogger.error(`Failed to update twitter profile: ${e.message}`);
emitNet(events.TWITTER_UPDATE_PROFILE_RESULT, getSource(), false);
}
});
@@ -316,6 +321,7 @@ onNet(events.TWITTER_FETCH_TWEETS, async () => {
const tweets = await fetchAllTweets(profile.id);
emitNet(events.TWITTER_FETCH_TWEETS_SUCCESS, getSource(), tweets);
} catch (e) {
twitterLogger.error(`Fetching tweets failed, ${e.message}`);
emitNet(events.TWITTER_FETCH_TWEETS_FAILURE, getSource());
}
});
@@ -327,6 +333,7 @@ onNet(events.TWITTER_FETCH_TWEETS_FILTERED, async (searchValue: string) => {
const tweets = await fetchTweetsFiltered(profile.id, searchValue);
emitNet(events.TWITTER_FETCH_TWEETS_FILTERED_SUCCESS, getSource(), tweets);
} catch (e) {
twitterLogger.error(`Fetch filtered tweets failed, ${e.message}`);
emitNet(events.TWITTER_FETCH_TWEETS_FILTERED_FAILURE, getSource());
}
});
@@ -339,6 +346,7 @@ onNet(events.TWITTER_CREATE_TWEET, async (tweet: Tweet) => {
emitNet(events.TWITTER_CREATE_TWEET_RESULT, getSource(), true);
emitNet(events.TWITTER_CREATE_TWEET_BROADCAST, -1, createdTweet);
} catch (e) {
twitterLogger.error(`Create tweet failed, ${e.message}`);
emitNet(events.TWITTER_CREATE_TWEET_RESULT, getSource(), false);
}
});
@@ -350,6 +358,7 @@ onNet(events.TWITTER_DELETE_TWEET, async (tweetId: number) => {
emitNet(events.TWITTER_DELETE_TWEET_SUCCESS, getSource());
} catch (e) {
twitterLogger.error(`Delete tweet failed, ${e.message}`);
emitNet(events.TWITTER_DELETE_TWEET_FAILURE, getSource());
}
});
@@ -366,6 +375,7 @@ onNet(events.TWITTER_TOGGLE_LIKE, async (tweetId: number) => {
}
emitNet(events.TWITTER_TOGGLE_LIKE_SUCCESS, getSource());
} catch (e) {
twitterLogger.error(`Like failed, ${e.message}`);
emitNet(events.TWITTER_TOGGLE_LIKE_FAILURE, getSource());
}
});
@@ -378,7 +388,7 @@ onNet(events.TWITTER_REPORT, async (tweetId: number) => {
const reportExists = await doesReportExist(tweet.id, profile.id);
if (reportExists) {
console.warn('This profile has already reported this tweet');
twitterLogger.warn('This profile has already reported this tweet');
} else {
await createTweetReport(tweet.id, profile.id);
await reportTweetToDiscord(tweet, profile);
@@ -387,5 +397,6 @@ onNet(events.TWITTER_REPORT, async (tweetId: number) => {
emitNet(events.TWITTER_REPORT_SUCCESS, getSource());
} catch (e) {
emitNet(events.TWITTER_REPORT_FAILURE, getSource());
twitterLogger.error(`Twitter report failed, ${e.message}`);
}
});
+145 -4
View File
@@ -895,6 +895,15 @@
exec-sh "^0.3.2"
minimist "^1.2.0"
"@dabh/diagnostics@^2.0.2":
version "2.0.2"
resolved "https://registry.yarnpkg.com/@dabh/diagnostics/-/diagnostics-2.0.2.tgz#290d08f7b381b8f94607dc8f471a12c675f9db31"
integrity sha512-+A1YivoVDNNVCdfozHSR8v/jyuuLTMXwjWuxPFlFlUapXoGc+Gj9mDlTDDfrwl7rXCl2tNZ0kE8sIBO6YOn96Q==
dependencies:
colorspace "1.1.x"
enabled "2.0.x"
kuler "^2.0.0"
"@eslint/eslintrc@^0.1.3":
version "0.1.3"
resolved "https://registry.yarnpkg.com/@eslint/eslintrc/-/eslintrc-0.1.3.tgz#7d1a2b2358552cc04834c0979bd4275362e37085"
@@ -1808,6 +1817,11 @@ async-each@^1.0.1:
resolved "https://registry.yarnpkg.com/async-each/-/async-each-1.0.3.tgz#b727dbf87d7651602f06f4d4ac387f47d91b0cbf"
integrity sha512-z/WhQ5FPySLdvREByI2vZiTWwCnF0moMJ1hK9YQwDTHKh6I7/uSckMetoRGb5UBZPC1z0jlw+n/XCgjeH7y1AQ==
async@^3.1.0:
version "3.2.0"
resolved "https://registry.yarnpkg.com/async/-/async-3.2.0.tgz#b3a2685c5ebb641d3de02d161002c60fc9f85720"
integrity sha512-TR2mEZFVOj2pLStYxLht7TyfuRzaydfpxr3k9RpHIzMgw7A64dzsdqCxH1WJyQdoe8T10nDXd9wnEigmiuHIZw==
asynckit@^0.4.0:
version "0.4.0"
resolved "https://registry.yarnpkg.com/asynckit/-/asynckit-0.4.0.tgz#c79ed97f7f34cb8f2ba1bc9790bcc366474b4b79"
@@ -2347,7 +2361,7 @@ collection-visit@^1.0.0:
map-visit "^1.0.0"
object-visit "^1.0.0"
color-convert@^1.9.0:
color-convert@^1.9.0, color-convert@^1.9.1:
version "1.9.3"
resolved "https://registry.yarnpkg.com/color-convert/-/color-convert-1.9.3.tgz#bb71850690e1f136567de629d2d5471deda4c1e8"
integrity sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==
@@ -2366,11 +2380,40 @@ [email protected]:
resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.3.tgz#a7d0558bd89c42f795dd42328f740831ca53bc25"
integrity sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=
color-name@~1.1.4:
color-name@^1.0.0, color-name@~1.1.4:
version "1.1.4"
resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.4.tgz#c2a09a87acbde69543de6f63fa3995c826c536a2"
integrity sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==
color-string@^1.5.2:
version "1.5.4"
resolved "https://registry.yarnpkg.com/color-string/-/color-string-1.5.4.tgz#dd51cd25cfee953d138fe4002372cc3d0e504cb6"
integrity sha512-57yF5yt8Xa3czSEW1jfQDE79Idk0+AkN/4KWad6tbdxUmAs3MvjxlWSWD4deYytcRfoZ9nhKyFl1kj5tBvidbw==
dependencies:
color-name "^1.0.0"
simple-swizzle "^0.2.2"
[email protected]:
version "3.0.0"
resolved "https://registry.yarnpkg.com/color/-/color-3.0.0.tgz#d920b4328d534a3ac8295d68f7bd4ba6c427be9a"
integrity sha512-jCpd5+s0s0t7p3pHQKpnJ0TpQKKdleP71LWcA0aqiljpiuAkOSUFN/dyH8ZwF0hRmFlrIuRhufds1QyEP9EB+w==
dependencies:
color-convert "^1.9.1"
color-string "^1.5.2"
colors@^1.2.1:
version "1.4.0"
resolved "https://registry.yarnpkg.com/colors/-/colors-1.4.0.tgz#c50491479d4c1bdaed2c9ced32cf7c7dc2360f78"
integrity sha512-a+UqTh4kgZg/SlGvfbzDHpgRu7AAQOmmqRHJnxhRZICKFUT91brVhNNt58CMWU9PsBbv3PDCZUHbVxuDiH2mtA==
[email protected]:
version "1.1.2"
resolved "https://registry.yarnpkg.com/colorspace/-/colorspace-1.1.2.tgz#e0128950d082b86a2168580796a0aa5d6c68d8c5"
integrity sha512-vt+OoIP2d76xLhjwbBaucYlNSpPsrJWPlBTtwCpQKIu6/CSMutyzX93O/Do0qzpH3YoHEes8YEFXyZ797rEhzQ==
dependencies:
color "3.0.x"
text-hex "1.0.x"
combined-stream@^1.0.6, combined-stream@~1.0.6:
version "1.0.8"
resolved "https://registry.yarnpkg.com/combined-stream/-/combined-stream-1.0.8.tgz#c3d45a8b34fd730631a110a8a2520682b31d5a7f"
@@ -2834,6 +2877,11 @@ emojis-list@^3.0.0:
resolved "https://registry.yarnpkg.com/emojis-list/-/emojis-list-3.0.0.tgz#5570662046ad29e2e916e71aae260abdff4f6a78"
integrity sha512-/kyM18EfinwXZbno9FyUGeFh87KC8HRQBQGildHZbEuRyWFOmv1U10o9BBp8XVZDVNNuQKyIGIu5ZYAAXJ0V2Q==
[email protected]:
version "2.0.0"
resolved "https://registry.yarnpkg.com/enabled/-/enabled-2.0.0.tgz#f9dd92ec2d6f4bbc0d5d1e64e21d61cd4665e7c2"
integrity sha512-AKrN98kuwOzMIdAizXGI86UFBoo26CL21UM763y1h/GMSJ4/OHU9k2YlsmBpyScFo/wbLzWQJBMCW4+IO3/+OQ==
end-of-stream@^1.0.0, end-of-stream@^1.1.0:
version "1.4.4"
resolved "https://registry.yarnpkg.com/end-of-stream/-/end-of-stream-1.4.4.tgz#5ae64a5f45057baf3626ec14da0ca5e4b2431eb0"
@@ -3264,6 +3312,11 @@ fast-levenshtein@^2.0.6, fast-levenshtein@~2.0.6:
resolved "https://registry.yarnpkg.com/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz#3d8a5c66883a16a30ca8643e851f19baa7797917"
integrity sha1-PYpcZog6FqMMqGQ+hR8Zuqd5eRc=
fast-safe-stringify@^2.0.4:
version "2.0.7"
resolved "https://registry.yarnpkg.com/fast-safe-stringify/-/fast-safe-stringify-2.0.7.tgz#124aa885899261f68aedb42a7c080de9da608743"
integrity sha512-Utm6CdzT+6xsDk2m8S6uL8VHxNwI6Jub+e9NYTcAms28T84pTa25GJQV9j0CY0N1rM8hK4x6grpF2BQf+2qwVA==
fastq@^1.6.0:
version "1.8.0"
resolved "https://registry.yarnpkg.com/fastq/-/fastq-1.8.0.tgz#550e1f9f59bbc65fe185cb6a9b4d95357107f481"
@@ -3278,6 +3331,11 @@ fb-watchman@^2.0.0:
dependencies:
bser "2.1.1"
fecha@^4.2.0:
version "4.2.0"
resolved "https://registry.yarnpkg.com/fecha/-/fecha-4.2.0.tgz#3ffb6395453e3f3efff850404f0a59b6747f5f41"
integrity sha512-aN3pcx/DSmtyoovUudctc8+6Hl4T+hI9GBBHLjA76jdZl7+b1sgh5g4k+u/GL3dTy1/pnYzKp69FpJ0OicE3Wg==
figgy-pudding@^3.5.1:
version "3.5.2"
resolved "https://registry.yarnpkg.com/figgy-pudding/-/figgy-pudding-3.5.2.tgz#b4eee8148abb01dcf1d1ac34367d59e12fa61d6e"
@@ -3406,6 +3464,11 @@ flush-write-stream@^1.0.0:
inherits "^2.0.3"
readable-stream "^2.3.6"
[email protected]:
version "1.1.0"
resolved "https://registry.yarnpkg.com/fn.name/-/fn.name-1.1.0.tgz#26cad8017967aea8731bc42961d04a3d5988accc"
integrity sha512-GRnmB5gPyJpAhTQdSZTSp9uaPSvl09KoYcMQtsB9rQoOmzs9dH6ffeccH+Z+cv6P68Hu5bC6JjRh4Ah/mHSNRw==
follow-redirects@^1.10.0:
version "1.13.0"
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.13.0.tgz#b42e8d93a2a7eea5ed88633676d6597bc8e384db"
@@ -3945,6 +4008,11 @@ is-arrayish@^0.2.1:
resolved "https://registry.yarnpkg.com/is-arrayish/-/is-arrayish-0.2.1.tgz#77c99840527aa8ecb1a8ba697b80645a7a926a9d"
integrity sha1-d8mYQFJ6qOyxqLppe4BkWnqSap0=
is-arrayish@^0.3.1:
version "0.3.2"
resolved "https://registry.yarnpkg.com/is-arrayish/-/is-arrayish-0.3.2.tgz#4574a2ae56f7ab206896fb431eaeed066fdf8f03"
integrity sha512-eVRqCvVlZbuw3GrM63ovNSNAeA1K16kaR/LRY/92w0zxQ5/1YzwblUX652i4Xs9RwAGjW9d9y6X88t8OaAJfWQ==
is-binary-path@^1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/is-binary-path/-/is-binary-path-1.0.1.tgz#75f16642b480f187a711c814161fd3a4a7655898"
@@ -4763,6 +4831,11 @@ kleur@^3.0.3:
resolved "https://registry.yarnpkg.com/kleur/-/kleur-3.0.3.tgz#a79c9ecc86ee1ce3fa6206d1216c501f147fc07e"
integrity sha512-eTIzlVOSUR+JxdDFepEYcBMtZ9Qqdef+rnzWdRZuMbOywu5tO2w2N7rqjoANZ5k9vywhL6Br1VRjUIgTQx4E8w==
kuler@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/kuler/-/kuler-2.0.0.tgz#e2c570a3800388fb44407e851531c1d670b061b3"
integrity sha512-Xq9nH7KlWZmXAtodXDDRE7vs6DU1gTU8zYDHDiWLSip45Egwq3plLHzPn27NgvzL2r1LMPC1vdqh98sQxtqj4A==
leven@^3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/leven/-/leven-3.1.0.tgz#77891de834064cccba82ae7842bb6b14a13ed7f2"
@@ -4894,6 +4967,17 @@ log-update@^4.0.0:
slice-ansi "^4.0.0"
wrap-ansi "^6.2.0"
logform@^2.2.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/logform/-/logform-2.2.0.tgz#40f036d19161fc76b68ab50fdc7fe495544492f2"
integrity sha512-N0qPlqfypFx7UHNn4B3lzS/b0uLqt2hmuoa+PpuXNYgozdJYAyauF5Ky0BWVjrxDlMWiT3qN4zPq3vVAfZy7Yg==
dependencies:
colors "^1.2.1"
fast-safe-stringify "^2.0.4"
fecha "^4.2.0"
ms "^2.1.1"
triple-beam "^1.3.0"
long@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/long/-/long-4.0.0.tgz#9a7b71cfb7d361a194ea555241c92f7468d5bf28"
@@ -5154,6 +5238,11 @@ [email protected]:
resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.2.tgz#d09d1f357b443f493382a8eb3ccd183872ae6009"
integrity sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==
ms@^2.1.1:
version "2.1.3"
resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.3.tgz#574c8138ce1d2b5861f0b44579dbadd60c6615b2"
integrity sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==
mysql2@^2.2.5:
version "2.2.5"
resolved "https://registry.yarnpkg.com/mysql2/-/mysql2-2.2.5.tgz#72624ffb4816f80f96b9c97fedd8c00935f9f340"
@@ -5386,6 +5475,13 @@ once@^1.3.0, once@^1.3.1, once@^1.4.0:
dependencies:
wrappy "1"
one-time@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/one-time/-/one-time-1.0.0.tgz#e06bc174aed214ed58edede573b433bbf827cb45"
integrity sha512-5DXOiRKwuSEcQ/l0kGCF6Q3jcADFv5tSmRaJck/OqkVFcOzutB134KRSfF0xDrL39MNnqxbHBbUUcjZIhTgb2g==
dependencies:
fn.name "1.x.x"
onetime@^5.1.0:
version "5.1.2"
resolved "https://registry.yarnpkg.com/onetime/-/onetime-5.1.2.tgz#d0e96ebb56b07476df1dd9c4806e5237985ca45e"
@@ -5861,7 +5957,7 @@ read-pkg@^5.2.0:
parse-json "^5.0.0"
type-fest "^0.6.0"
"readable-stream@1 || 2", readable-stream@^2.0.0, readable-stream@^2.0.1, readable-stream@^2.0.2, readable-stream@^2.1.5, readable-stream@^2.2.2, readable-stream@^2.3.3, readable-stream@^2.3.6, readable-stream@~2.3.6:
"readable-stream@1 || 2", readable-stream@^2.0.0, readable-stream@^2.0.1, readable-stream@^2.0.2, readable-stream@^2.1.5, readable-stream@^2.2.2, readable-stream@^2.3.3, readable-stream@^2.3.6, readable-stream@^2.3.7, readable-stream@~2.3.6:
version "2.3.7"
resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-2.3.7.tgz#1eca1cf711aef814c04f62252a36a62f6cb23b57"
integrity sha512-Ebho8K4jIbHAxnuxi7o42OrZgF/ZTNcsZj6nRKyUmkhLFq8CHItp/fy6hQZuZmP/n3yZ9VBUbp4zz/mX8hmYPw==
@@ -5874,7 +5970,7 @@ read-pkg@^5.2.0:
string_decoder "~1.1.1"
util-deprecate "~1.0.1"
readable-stream@^3.6.0:
readable-stream@^3.4.0, readable-stream@^3.6.0:
version "3.6.0"
resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-3.6.0.tgz#337bbda3adc0706bd3e024426a286d4b4b2c9198"
integrity sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA==
@@ -6323,6 +6419,13 @@ signal-exit@^3.0.0, signal-exit@^3.0.2:
resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.3.tgz#a1410c2edd8f077b08b4e253c8eacfcaf057461c"
integrity sha512-VUJ49FC8U1OxwZLxIbTTrDvLnf/6TDgxZcK8wxR8zs13xpx7xbG60ndBlhNrFi2EMuFRoeDoJO7wthSLq42EjA==
simple-swizzle@^0.2.2:
version "0.2.2"
resolved "https://registry.yarnpkg.com/simple-swizzle/-/simple-swizzle-0.2.2.tgz#a4da6b635ffcccca33f70d17cb92592de95e557a"
integrity sha1-pNprY1/8zMoz9w0Xy5JZLeleVXo=
dependencies:
is-arrayish "^0.3.1"
sisteransi@^1.0.4:
version "1.0.5"
resolved "https://registry.yarnpkg.com/sisteransi/-/sisteransi-1.0.5.tgz#134d681297756437cc05ca01370d3a7a571075ed"
@@ -6504,6 +6607,11 @@ ssri@^6.0.1:
dependencies:
figgy-pudding "^3.5.1"
[email protected]:
version "0.0.10"
resolved "https://registry.yarnpkg.com/stack-trace/-/stack-trace-0.0.10.tgz#547c70b347e8d32b4e108ea1a2a159e5fdde19c0"
integrity sha1-VHxws0fo0ytOEI6hoqFZ5f3eGcA=
stack-utils@^2.0.2:
version "2.0.2"
resolved "https://registry.yarnpkg.com/stack-utils/-/stack-utils-2.0.2.tgz#5cf48b4557becb4638d0bc4f21d23f5d19586593"
@@ -6750,6 +6858,11 @@ test-exclude@^6.0.0:
glob "^7.1.4"
minimatch "^3.0.4"
[email protected]:
version "1.0.0"
resolved "https://registry.yarnpkg.com/text-hex/-/text-hex-1.0.0.tgz#69dc9c1b17446ee79a92bf5b884bb4b9127506f5"
integrity sha512-uuVGNWzgJ4yhRaNSiubPY7OjISw4sw4E5Uv0wbjp+OzcbmVU/rsT8ujgcXJhn9ypzsgr5vlzpPqP+MBBKcGvbg==
text-table@^0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/text-table/-/text-table-0.2.0.tgz#7f5ee823ae805207c00af2df4a84ec3fcfa570b4"
@@ -6866,6 +6979,11 @@ [email protected]:
uuid "^3.3.2"
xdg-trashdir "^2.1.1"
triple-beam@^1.2.0, triple-beam@^1.3.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/triple-beam/-/triple-beam-1.3.0.tgz#a595214c7298db8339eeeee083e4d10bd8cb8dd9"
integrity sha512-XrHUvV5HpdLmIj4uVMxHggLbFSZYIn7HEWsqePZcI50pco+MPqJ50wMGY794X7AOOhxOBAjbkqfAbEe/QMp2Lw==
ts-jest@^26.4.1:
version "26.4.1"
resolved "https://registry.yarnpkg.com/ts-jest/-/ts-jest-26.4.1.tgz#08ec0d3fc2c3a39e4a46eae5610b69fafa6babd0"
@@ -7289,6 +7407,29 @@ which@^2.0.1, which@^2.0.2:
dependencies:
isexe "^2.0.0"
winston-transport@^4.4.0:
version "4.4.0"
resolved "https://registry.yarnpkg.com/winston-transport/-/winston-transport-4.4.0.tgz#17af518daa690d5b2ecccaa7acf7b20ca7925e59"
integrity sha512-Lc7/p3GtqtqPBYYtS6KCN3c77/2QCev51DvcJKbkFPQNoj1sinkGwLGFDxkXY9J6p9+EPnYs+D90uwbnaiURTw==
dependencies:
readable-stream "^2.3.7"
triple-beam "^1.2.0"
winston@^3.3.3:
version "3.3.3"
resolved "https://registry.yarnpkg.com/winston/-/winston-3.3.3.tgz#ae6172042cafb29786afa3d09c8ff833ab7c9170"
integrity sha512-oEXTISQnC8VlSAKf1KYSSd7J6IWuRPQqDdo8eoRNaYKLvwSb5+79Z3Yi1lrl6KDpU6/VWaxpakDAtb1oQ4n9aw==
dependencies:
"@dabh/diagnostics" "^2.0.2"
async "^3.1.0"
is-stream "^2.0.0"
logform "^2.2.0"
one-time "^1.0.0"
readable-stream "^3.4.0"
stack-trace "0.0.x"
triple-beam "^1.3.0"
winston-transport "^4.4.0"
word-wrap@^1.2.3, word-wrap@~1.2.3:
version "1.2.3"
resolved "https://registry.yarnpkg.com/word-wrap/-/word-wrap-1.2.3.tgz#610636f6b1f703891bd34771ccb17fb93b47079c"