mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-04 14:38:45 +00:00
Fix: prettier config in resources\ not being standard.
This commit is contained in:
1 parent
d56112a0cb
commit
ec1451a9aa
28 files changed
+349
-349
No files matched your search
@@ -1,5 +1,5 @@
|
||||
import mysql from "mysql2/promise";
|
||||
import { ConnectionStringParser } from "connection-string-parser";
|
||||
import mysql from 'mysql2/promise';
|
||||
import { ConnectionStringParser } from 'connection-string-parser';
|
||||
import {
|
||||
CONNECTION_STRING,
|
||||
DEFAULT_PORT,
|
||||
@@ -7,7 +7,7 @@ import {
|
||||
getServerHost,
|
||||
getUserId,
|
||||
getPassword,
|
||||
} from "./db_utils";
|
||||
} from './db_utils';
|
||||
|
||||
// we require set mysql_connection_string to be set in the config
|
||||
const mysqlConnectionString = GetConvar(CONNECTION_STRING, null);
|
||||
@@ -26,7 +26,7 @@ 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=")) {
|
||||
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);
|
||||
@@ -44,7 +44,7 @@ export function generateConnectionPool() {
|
||||
// This is checking for this format:
|
||||
// set mysql_connection_string "mysql://root:[email protected]/es_extended?charset=utf8mb4"
|
||||
const connectionStringParser = new ConnectionStringParser({
|
||||
scheme: "mysql",
|
||||
scheme: 'mysql',
|
||||
hosts: [],
|
||||
});
|
||||
const connectionOjbect = connectionStringParser.parse(
|
||||
@@ -75,7 +75,7 @@ export async function withTransaction(queries: Promise<any>[]): Promise<any[]> {
|
||||
await connection.release();
|
||||
return results;
|
||||
} catch (err) {
|
||||
console.warn("Error when submitting queries");
|
||||
console.warn('Error when submitting queries');
|
||||
await connection.rollback();
|
||||
await connection.release();
|
||||
return Promise.reject(err);
|
||||
|
||||
@@ -1,93 +1,93 @@
|
||||
import * as db from "./db_utils";
|
||||
import * as db from './db_utils';
|
||||
|
||||
const t = "test value";
|
||||
const t = 'test value';
|
||||
|
||||
describe("parseSemiColonFormat", () => {
|
||||
it("Raises a error with invalid string", () => {
|
||||
expect(() => db.parseSemiColonFormat("no_variables_here")).toThrowError();
|
||||
describe('parseSemiColonFormat', () => {
|
||||
it('Raises a error with invalid string', () => {
|
||||
expect(() => db.parseSemiColonFormat('no_variables_here')).toThrowError();
|
||||
});
|
||||
|
||||
it("Correctly parses configuration options", () => {
|
||||
const test = "server=127.0.0.1;database=es_extended;userid=user;";
|
||||
it('Correctly parses configuration options', () => {
|
||||
const test = 'server=127.0.0.1;database=es_extended;userid=user;';
|
||||
const result = db.parseSemiColonFormat(test);
|
||||
|
||||
expect(result.server).toEqual("127.0.0.1");
|
||||
expect(result.database).toEqual("es_extended");
|
||||
expect(result.userid).toEqual("user");
|
||||
expect(result.server).toEqual('127.0.0.1');
|
||||
expect(result.database).toEqual('es_extended');
|
||||
expect(result.userid).toEqual('user');
|
||||
expect(result.password).toEqual(undefined);
|
||||
});
|
||||
});
|
||||
|
||||
describe("getServerHost", () => {
|
||||
it("returns default", () => {
|
||||
describe('getServerHost', () => {
|
||||
it('returns default', () => {
|
||||
expect(db.getServerHost({})).toEqual(db.DEFAULT_HOST);
|
||||
});
|
||||
|
||||
it("Correctly returns host", () => {
|
||||
it('Correctly returns host', () => {
|
||||
expect(db.getServerHost({ host: t })).toEqual(t);
|
||||
});
|
||||
|
||||
it("Correctly returns server", () => {
|
||||
it('Correctly returns server', () => {
|
||||
expect(db.getServerHost({ server: t })).toEqual(t);
|
||||
});
|
||||
|
||||
it("Correctly returns data source", () => {
|
||||
expect(db.getServerHost({ "data source": t })).toEqual(t);
|
||||
it('Correctly returns data source', () => {
|
||||
expect(db.getServerHost({ 'data source': t })).toEqual(t);
|
||||
});
|
||||
|
||||
it("Correctly returns datasource", () => {
|
||||
it('Correctly returns datasource', () => {
|
||||
expect(db.getServerHost({ datasource: t })).toEqual(t);
|
||||
});
|
||||
|
||||
it("Correctly returns addr", () => {
|
||||
it('Correctly returns addr', () => {
|
||||
expect(db.getServerHost({ addr: t })).toEqual(t);
|
||||
});
|
||||
|
||||
it("Correctly returns address", () => {
|
||||
it('Correctly returns address', () => {
|
||||
expect(db.getServerHost({ address: t })).toEqual(t);
|
||||
});
|
||||
});
|
||||
|
||||
describe("getUserId", () => {
|
||||
it("returns default", () => {
|
||||
describe('getUserId', () => {
|
||||
it('returns default', () => {
|
||||
expect(db.getUserId({})).toEqual(db.DEFAULT_USER);
|
||||
});
|
||||
|
||||
it("Correctly returns user", () => {
|
||||
it('Correctly returns user', () => {
|
||||
expect(db.getUserId({ user: t })).toEqual(t);
|
||||
});
|
||||
|
||||
it("Correctly returns user id", () => {
|
||||
expect(db.getUserId({ "user id": t })).toEqual(t);
|
||||
it('Correctly returns user id', () => {
|
||||
expect(db.getUserId({ 'user id': t })).toEqual(t);
|
||||
});
|
||||
|
||||
it("Correctly returns userid", () => {
|
||||
it('Correctly returns userid', () => {
|
||||
expect(db.getUserId({ userid: t })).toEqual(t);
|
||||
});
|
||||
|
||||
it("Correctly returns user name", () => {
|
||||
expect(db.getUserId({ "user name": t })).toEqual(t);
|
||||
it('Correctly returns user name', () => {
|
||||
expect(db.getUserId({ 'user name': t })).toEqual(t);
|
||||
});
|
||||
|
||||
it("Correctly returns username", () => {
|
||||
it('Correctly returns username', () => {
|
||||
expect(db.getUserId({ username: t })).toEqual(t);
|
||||
});
|
||||
|
||||
it("Correctly returns uid", () => {
|
||||
it('Correctly returns uid', () => {
|
||||
expect(db.getUserId({ uid: t })).toEqual(t);
|
||||
});
|
||||
});
|
||||
|
||||
describe("getPassword", () => {
|
||||
describe('getPassword', () => {
|
||||
// it("returns default", () => {
|
||||
// expect(() => db.getPassword({})).toThrowError();
|
||||
// });
|
||||
|
||||
it("Correctly returns password", () => {
|
||||
it('Correctly returns password', () => {
|
||||
expect(db.getPassword({ password: t })).toEqual(t);
|
||||
});
|
||||
|
||||
it("Correctly returns pwd", () => {
|
||||
it('Correctly returns pwd', () => {
|
||||
expect(db.getPassword({ pwd: t })).toEqual(t);
|
||||
});
|
||||
});
|
||||
@@ -1,7 +1,7 @@
|
||||
export const CONNECTION_STRING = "mysql_connection_string";
|
||||
export const CONNECTION_STRING = 'mysql_connection_string';
|
||||
export const DEFAULT_PORT = 3306;
|
||||
export const DEFAULT_HOST = "localhost";
|
||||
export const DEFAULT_USER = "root";
|
||||
export const DEFAULT_HOST = 'localhost';
|
||||
export const DEFAULT_USER = 'root';
|
||||
|
||||
interface Map {
|
||||
[key: string]: string;
|
||||
@@ -12,7 +12,7 @@ interface Map {
|
||||
* @param connectionString - mysql_connection_string value
|
||||
*/
|
||||
export function parseSemiColonFormat(connectionString: string): Map {
|
||||
const parts = connectionString.split(";");
|
||||
const parts = connectionString.split(';');
|
||||
if (parts.length === 1) {
|
||||
throw new Error(
|
||||
`Connection string ${connectionString} is in the incorrect format. Please follow the README.`
|
||||
@@ -20,7 +20,7 @@ export function parseSemiColonFormat(connectionString: string): Map {
|
||||
}
|
||||
|
||||
return parts.reduce((connectionInfo: Map, part) => {
|
||||
const [key, value] = part.split("=");
|
||||
const [key, value] = part.split('=');
|
||||
connectionInfo[key] = value;
|
||||
return connectionInfo;
|
||||
}, {});
|
||||
@@ -34,7 +34,7 @@ export function getServerHost(config: Map): string {
|
||||
return (
|
||||
config.host ||
|
||||
config.server ||
|
||||
config["data source"] ||
|
||||
config['data source'] ||
|
||||
config.datasource ||
|
||||
config.addr ||
|
||||
config.address ||
|
||||
@@ -49,9 +49,9 @@ export function getServerHost(config: Map): string {
|
||||
export function getUserId(config: Map): string {
|
||||
return (
|
||||
config.user ||
|
||||
config["user id"] ||
|
||||
config['user id'] ||
|
||||
config.userid ||
|
||||
config["user name"] ||
|
||||
config['user name'] ||
|
||||
config.username ||
|
||||
config.uid ||
|
||||
DEFAULT_USER
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
import axios from "axios";
|
||||
import axios from 'axios';
|
||||
|
||||
import { Tweet, Profile } from "../../phone/src/common/typings/twitter";
|
||||
import { IMAGE_DELIMITER } from "../../phone/src/apps/twitter/utils/images";
|
||||
import { Tweet, Profile } from '../../phone/src/common/typings/twitter';
|
||||
import { IMAGE_DELIMITER } from '../../phone/src/apps/twitter/utils/images';
|
||||
|
||||
const DISCORD_TOKEN_ENV_VAR = "discord_bot_token";
|
||||
const DISCORD_TOKEN = GetConvar(DISCORD_TOKEN_ENV_VAR, "");
|
||||
const DISCORD_CHANNEL_ENV_VAR = "discord_channel_id";
|
||||
const DISCORD_CHANNEL_ID = GetConvar(DISCORD_CHANNEL_ENV_VAR, "");
|
||||
const DISCORD_TOKEN_ENV_VAR = 'discord_bot_token';
|
||||
const DISCORD_TOKEN = GetConvar(DISCORD_TOKEN_ENV_VAR, '');
|
||||
const DISCORD_CHANNEL_ENV_VAR = 'discord_channel_id';
|
||||
const DISCORD_CHANNEL_ID = GetConvar(DISCORD_CHANNEL_ENV_VAR, '');
|
||||
const DISCORD_HEADERS = { authorization: `Bot ${DISCORD_TOKEN}` };
|
||||
|
||||
const BASE_URL = "https://discord.com/api";
|
||||
const BASE_URL = 'https://discord.com/api';
|
||||
const POST_CHANNEL_URL = `${BASE_URL}/channels/${DISCORD_CHANNEL_ID}/messages`;
|
||||
|
||||
export async function reportTweetToDiscord(
|
||||
@@ -34,7 +34,7 @@ export async function reportTweetToDiscord(
|
||||
${tweet.message}
|
||||
|
||||
**Reported Images**:
|
||||
${tweet.images.split(IMAGE_DELIMITER).join("\n")}
|
||||
${tweet.images.split(IMAGE_DELIMITER).join('\n')}
|
||||
`;
|
||||
|
||||
return await axios.post(
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { pool } from "./db";
|
||||
import { ESX } from "./server";
|
||||
import { pool } from './db';
|
||||
import { ESX } from './server';
|
||||
|
||||
interface IPhoneNumber {
|
||||
phone_number: string;
|
||||
@@ -10,7 +10,7 @@ interface Iidentifier {
|
||||
}
|
||||
|
||||
export async function usePhoneNumber(identifier: string): Promise<string> {
|
||||
const query = "SELECT phone_number FROM users WHERE identifier = ?";
|
||||
const query = 'SELECT phone_number FROM users WHERE identifier = ?';
|
||||
const [results] = await pool.query(query, [identifier]);
|
||||
const phoneNumber = <IPhoneNumber[]>results;
|
||||
return phoneNumber[0].phone_number;
|
||||
@@ -25,7 +25,7 @@ export async function useIdentifier(): Promise<string> {
|
||||
export async function getIdentifierByPhoneNumber(
|
||||
phoneNumber: string
|
||||
): Promise<string> {
|
||||
const query = "SELECT identifier FROM users WHERE phone_number = ?";
|
||||
const query = 'SELECT identifier FROM users WHERE phone_number = ?';
|
||||
const [results] = await pool.query(query, [phoneNumber]);
|
||||
const identifier = <Iidentifier[]>results;
|
||||
return identifier[0].identifier;
|
||||
|
||||
+11
-11
@@ -1,19 +1,19 @@
|
||||
import { Server } from "esx.js";
|
||||
import { Server } from 'esx.js';
|
||||
|
||||
import "./db";
|
||||
import "./sv_twitter";
|
||||
import "./sv_main";
|
||||
import "./sv_contacts";
|
||||
import "./sv_sellout";
|
||||
import "./sv_bank";
|
||||
import "./sv_notes";
|
||||
import "./sv_photo";
|
||||
import "./sv_messages";
|
||||
import './db';
|
||||
import './sv_twitter';
|
||||
import './sv_main';
|
||||
import './sv_contacts';
|
||||
import './sv_sellout';
|
||||
import './sv_bank';
|
||||
import './sv_notes';
|
||||
import './sv_photo';
|
||||
import './sv_messages';
|
||||
|
||||
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));
|
||||
|
||||
// i llke t-notify
|
||||
+17
-17
@@ -1,17 +1,17 @@
|
||||
import events from "../utils/events";
|
||||
import { ESX } from "./server";
|
||||
import { getSource } from "./functions";
|
||||
import { pool } from "./db";
|
||||
import events from '../utils/events';
|
||||
import { ESX } from './server';
|
||||
import { getSource } from './functions';
|
||||
import { pool } from './db';
|
||||
import {
|
||||
Transfer,
|
||||
IBankCredentials,
|
||||
} from "../../phone/src/common/typings/bank";
|
||||
import { useIdentifier } from "./functions";
|
||||
import { type } from "os";
|
||||
} from '../../phone/src/common/typings/bank';
|
||||
import { useIdentifier } from './functions';
|
||||
import { type } from 'os';
|
||||
|
||||
async function fetchAllTransactions(identifier: string): Promise<Transfer[]> {
|
||||
const query =
|
||||
"SELECT * FROM npwd_bank_transfers WHERE identifier = ? ORDER BY id DESC";
|
||||
'SELECT * FROM npwd_bank_transfers WHERE identifier = ? ORDER BY id DESC';
|
||||
const [results] = await pool.query(query, [identifier]);
|
||||
const transactions = <Transfer[]>results;
|
||||
|
||||
@@ -20,7 +20,7 @@ async function fetchAllTransactions(identifier: string): Promise<Transfer[]> {
|
||||
|
||||
function fetchCredentials(): IBankCredentials {
|
||||
const name = ESX.GetPlayerFromId(getSource()).getName();
|
||||
const balance = ESX.GetPlayerFromId(getSource()).getAccount("bank").money;
|
||||
const balance = ESX.GetPlayerFromId(getSource()).getAccount('bank').money;
|
||||
|
||||
const result = {
|
||||
name,
|
||||
@@ -35,7 +35,7 @@ async function addTransfer(
|
||||
transfer: Transfer
|
||||
): Promise<any> {
|
||||
const xPlayer = ESX.GetPlayerFromId(getSource());
|
||||
const bankBalance = xPlayer.getAccount("bank").money;
|
||||
const bankBalance = xPlayer.getAccount('bank').money;
|
||||
const sourceName = xPlayer.getName();
|
||||
|
||||
const xTarget = ESX.GetPlayerFromId(transfer.targetID);
|
||||
@@ -45,18 +45,18 @@ async function addTransfer(
|
||||
} else if (transfer.transferAmount < bankBalance) {
|
||||
emitNet(events.BANK_TRANSACTION_ALERT, getSource(), true);
|
||||
|
||||
xTarget.addAccountMoney("bank", transfer.transferAmount);
|
||||
xPlayer.removeAccountMoney("bank", transfer.transferAmount);
|
||||
xTarget.addAccountMoney('bank', transfer.transferAmount);
|
||||
xPlayer.removeAccountMoney('bank', transfer.transferAmount);
|
||||
|
||||
const query =
|
||||
"INSERT INTO npwd_bank_transfers (identifier, target, amount, message, type, source) VALUES (?, ?, ?, ?, ?, ?)";
|
||||
'INSERT INTO npwd_bank_transfers (identifier, target, amount, message, type, source) VALUES (?, ?, ?, ?, ?, ?)';
|
||||
|
||||
const [results] = await pool.query(query, [
|
||||
identifier,
|
||||
transfer.targetID,
|
||||
transfer.transferAmount,
|
||||
transfer.message,
|
||||
"Transfer",
|
||||
'Transfer',
|
||||
sourceName,
|
||||
]);
|
||||
const insertData = <any>results;
|
||||
@@ -69,7 +69,7 @@ async function addTransfer(
|
||||
* @param transferId - transfer id
|
||||
*/
|
||||
async function getTransfer(transferId: number): Promise<Transfer> {
|
||||
const query = "SELECT * FROM npwd_bank_transfers WHERE id = ?";
|
||||
const query = 'SELECT * FROM npwd_bank_transfers WHERE id = ?';
|
||||
const [results] = await pool.query(query, [transferId]);
|
||||
const transfers = <Transfer[]>results;
|
||||
const transfer = transfers[0];
|
||||
@@ -84,7 +84,7 @@ onNet(events.BANK_FETCH_TRANSACTIONS, async () => {
|
||||
|
||||
emitNet(events.BANK_SEND_TRANSFERS, _source, transfer);
|
||||
} catch (error) {
|
||||
console.log("Failed to fetch transactions");
|
||||
console.log('Failed to fetch transactions');
|
||||
}
|
||||
});
|
||||
|
||||
@@ -105,6 +105,6 @@ onNet(events.BANK_GET_CREDENTIALS, () => {
|
||||
const credentials = fetchCredentials();
|
||||
emitNet(events.BANK_SEND_CREDENTIALS, getSource(), credentials);
|
||||
} catch (error) {
|
||||
console.log("Failed to fetch credentials");
|
||||
console.log('Failed to fetch credentials');
|
||||
}
|
||||
});
|
||||
@@ -1,7 +1,7 @@
|
||||
import { ESX } from "./server";
|
||||
import { pool } from "./db";
|
||||
import events from "../utils/events";
|
||||
import { useIdentifier, getSource } from "./functions";
|
||||
import { ESX } from './server';
|
||||
import { pool } from './db';
|
||||
import events from '../utils/events';
|
||||
import { useIdentifier, getSource } from './functions';
|
||||
|
||||
interface Contacts {
|
||||
id?: number;
|
||||
@@ -15,7 +15,7 @@ interface ContactId {
|
||||
}
|
||||
|
||||
async function fetchAllContacts(identifier: string): Promise<Contacts[]> {
|
||||
const query = "SELECT * FROM npwd_phone_contacts WHERE identifier = ?";
|
||||
const query = 'SELECT * FROM npwd_phone_contacts WHERE identifier = ?';
|
||||
const [results] = await pool.query(query, [identifier]);
|
||||
const contacts = <Contacts[]>results;
|
||||
return contacts;
|
||||
@@ -28,7 +28,7 @@ async function addContact(
|
||||
avatar: string
|
||||
): Promise<any> {
|
||||
const query =
|
||||
"INSERT INTO npwd_phone_contacts (identifier, number, display, avatar) VALUES (?, ?, ?, ?)";
|
||||
'INSERT INTO npwd_phone_contacts (identifier, number, display, avatar) VALUES (?, ?, ?, ?)';
|
||||
|
||||
const [result] = await pool.query(query, [
|
||||
identifier,
|
||||
@@ -43,7 +43,7 @@ async function updateContact(
|
||||
identifier: string
|
||||
): Promise<any> {
|
||||
const query =
|
||||
"UPDATE npwd_phone_contacts SET number = ?, display = ?, avatar = ? WHERE id = ? AND identifier = ?";
|
||||
'UPDATE npwd_phone_contacts SET number = ?, display = ?, avatar = ? WHERE id = ? AND identifier = ?';
|
||||
await pool.query(query, [
|
||||
contact.number,
|
||||
contact.display,
|
||||
@@ -58,7 +58,7 @@ async function deleteContact(
|
||||
identifier: string
|
||||
): Promise<any> {
|
||||
const query =
|
||||
"DELETE FROM npwd_phone_contacts WHERE id = ? AND identifier = ?";
|
||||
'DELETE FROM npwd_phone_contacts WHERE id = ? AND identifier = ?';
|
||||
await pool.query(query, [contact.id, identifier]);
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ 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);
|
||||
console.log('Failed to fetch contacts: ', error);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -86,10 +86,10 @@ onNet(
|
||||
emitNet(
|
||||
events.CONTACTS_ACTION_RESULT,
|
||||
getSource(),
|
||||
"CONTACT_ADD_SUCCESS"
|
||||
'CONTACT_ADD_SUCCESS'
|
||||
);
|
||||
} catch (error) {
|
||||
emitNet(events.CONTACTS_ACTION_RESULT, getSource(), "CONTACT_ADD_FAILED");
|
||||
emitNet(events.CONTACTS_ACTION_RESULT, getSource(), 'CONTACT_ADD_FAILED');
|
||||
}
|
||||
}
|
||||
);
|
||||
@@ -103,13 +103,13 @@ onNet(events.CONTACTS_UPDATE_CONTACT, async (contact: Contacts) => {
|
||||
emitNet(
|
||||
events.CONTACTS_ACTION_RESULT,
|
||||
getSource(),
|
||||
"CONTACT_UPDATE_SUCCESS"
|
||||
'CONTACT_UPDATE_SUCCESS'
|
||||
);
|
||||
} catch (error) {
|
||||
emitNet(
|
||||
events.CONTACTS_ACTION_RESULT,
|
||||
getSource(),
|
||||
"CONTACT_UPDATE_FAILED"
|
||||
'CONTACT_UPDATE_FAILED'
|
||||
);
|
||||
}
|
||||
});
|
||||
@@ -122,13 +122,13 @@ onNet(events.CONTACTS_DELETE_CONTACT, async (contact: ContactId) => {
|
||||
emitNet(
|
||||
events.CONTACTS_ACTION_RESULT,
|
||||
getSource(),
|
||||
"CONTACT_DELETE_SUCCESS"
|
||||
'CONTACT_DELETE_SUCCESS'
|
||||
);
|
||||
} catch (error) {
|
||||
emitNet(
|
||||
events.CONTACTS_ACTION_RESULT,
|
||||
getSource(),
|
||||
"CONTACT_DELETE_FAILED"
|
||||
'CONTACT_DELETE_FAILED'
|
||||
);
|
||||
}
|
||||
});
|
||||
+12
-12
@@ -1,7 +1,7 @@
|
||||
import { ESX } from "./server";
|
||||
import { pool } from "./db";
|
||||
import config from "../utils/config";
|
||||
import { getIdentifierByPhoneNumber, usePhoneNumber } from "./functions";
|
||||
import { ESX } from './server';
|
||||
import { pool } from './db';
|
||||
import config from '../utils/config';
|
||||
import { getIdentifierByPhoneNumber, usePhoneNumber } from './functions';
|
||||
|
||||
//db = DatabaseConfig //helper variable for use in server function
|
||||
|
||||
@@ -25,7 +25,7 @@ function getRandomPhoneNumber() {
|
||||
} else {
|
||||
randomNumber = Math.floor(Math.random() * 10000000)
|
||||
.toString()
|
||||
.replace(/(\d{3})(\d{4})/, "$1-$2"); // ;
|
||||
.replace(/(\d{3})(\d{4})/, '$1-$2'); // ;
|
||||
// The numbers inside {} in replace() can be changed to how many digits you want on each side of the dash.
|
||||
// Example: 123-4567
|
||||
}
|
||||
@@ -41,7 +41,7 @@ async function generatePhoneNumber(identifier: string) {
|
||||
do {
|
||||
if (!phoneNumber) {
|
||||
phoneNumber = await getRandomPhoneNumber();
|
||||
const query = "UPDATE users SET phone_number = ? WHERE identifier = ?";
|
||||
const query = 'UPDATE users SET phone_number = ? WHERE identifier = ?';
|
||||
await pool.query(query, [phoneNumber, _identifier]);
|
||||
} else {
|
||||
break;
|
||||
@@ -50,26 +50,26 @@ async function generatePhoneNumber(identifier: string) {
|
||||
}
|
||||
|
||||
async function getCredentials(identifier: string): Promise<string> {
|
||||
const query = "SELECT phone_number FROM users WHERE identifier = ?";
|
||||
const query = 'SELECT phone_number FROM users WHERE identifier = ?';
|
||||
const [result] = await pool.query(query, [identifier]);
|
||||
const number = <Credentials[]>result;
|
||||
if (number.length === 0) return "###-####";
|
||||
if (number.length === 0) return '###-####';
|
||||
return number[0].phone_number;
|
||||
}
|
||||
|
||||
onNet("esx:playerLoaded", async (playerId: number, xPlayer: any) => {
|
||||
onNet('esx:playerLoaded', async (playerId: number, xPlayer: any) => {
|
||||
const identifier = xPlayer.identifier;
|
||||
await generatePhoneNumber(identifier);
|
||||
});
|
||||
|
||||
onNet("phone:getCredentials", async () => {
|
||||
onNet('phone:getCredentials', async () => {
|
||||
try {
|
||||
const _source = (global as any).source;
|
||||
const xPlayer = ESX.GetPlayerFromId(_source);
|
||||
const _identifier = xPlayer.getIdentifier();
|
||||
const number = await getCredentials(_identifier);
|
||||
emitNet("phone:sendCredentials", _source, number);
|
||||
emitNet('phone:sendCredentials', _source, number);
|
||||
} catch (error) {
|
||||
console.log("Failed to get number. ", error);
|
||||
console.log('Failed to get number. ', error);
|
||||
}
|
||||
});
|
||||
@@ -1,13 +1,13 @@
|
||||
import md5 from "md5";
|
||||
import md5 from 'md5';
|
||||
|
||||
import events from "../utils/events";
|
||||
import events from '../utils/events';
|
||||
import {
|
||||
Message,
|
||||
MessageGroup,
|
||||
CreateMessageGroupResult,
|
||||
} from "../../phone/src/common/typings/messages";
|
||||
import { pool, withTransaction } from "./db";
|
||||
import { getSource, useIdentifier } from "./functions";
|
||||
} from '../../phone/src/common/typings/messages';
|
||||
import { pool, withTransaction } from './db';
|
||||
import { getSource, useIdentifier } from './functions';
|
||||
|
||||
/**
|
||||
* Used for the raw npwd_messages_groups row responses
|
||||
@@ -188,7 +188,7 @@ async function getIdentifierFromPhoneNumber(
|
||||
`;
|
||||
const [results] = await pool.query(query, [phoneNumber]);
|
||||
const identifiers = <any>results;
|
||||
return identifiers[0]["identifier"];
|
||||
return identifiers[0]['identifier'];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -235,7 +235,7 @@ async function getConsolidatedMessageGroups(
|
||||
(mapping: MessageGroupMapping, messageGroup: UnformattedMessageGroup) => {
|
||||
const groupId = messageGroup.group_id;
|
||||
const displayTerm =
|
||||
messageGroup.display || messageGroup.phone_number || "???";
|
||||
messageGroup.display || messageGroup.phone_number || '???';
|
||||
|
||||
if (groupId in mapping) {
|
||||
mapping[groupId].participants = mapping[groupId].participants.concat(
|
||||
@@ -288,7 +288,7 @@ async function getFormattedMessageGroups(
|
||||
return {
|
||||
...group,
|
||||
groupId,
|
||||
groupDisplay: group.participants.join(", "),
|
||||
groupDisplay: group.participants.join(', '),
|
||||
// note that 1 here references how many participants besides the user
|
||||
isGroupChat: group.participants.length > 1,
|
||||
};
|
||||
@@ -336,7 +336,7 @@ async function createMessageGroupsFromPhoneNumbers(
|
||||
// that this not change! Changing this order can result in the ability
|
||||
// of duplicate message groups being created.
|
||||
identifiers.sort();
|
||||
const mergedIdentifiers = identifiers.join("-");
|
||||
const mergedIdentifiers = identifiers.join('-');
|
||||
// we don't need this to be secure. Its purpose is to create a unique
|
||||
// string derived from the identifiers. In this way we can check
|
||||
// that this groupId isn't used before. If it has then it means
|
||||
|
||||
@@ -1,30 +1,30 @@
|
||||
import events from "../utils/events";
|
||||
import { pool } from "./db";
|
||||
import { useIdentifier, getSource } from "./functions";
|
||||
import { Note, NoteId } from "../../phone/src/common/typings/notes";
|
||||
import events from '../utils/events';
|
||||
import { pool } from './db';
|
||||
import { useIdentifier, getSource } from './functions';
|
||||
import { Note, NoteId } from '../../phone/src/common/typings/notes';
|
||||
|
||||
async function addNote(identifier: string, note: Note): Promise<any> {
|
||||
const query =
|
||||
"INSERT INTO npwd_notes (identifier, title, content) VALUES (?, ?, ?)";
|
||||
'INSERT INTO npwd_notes (identifier, title, content) VALUES (?, ?, ?)';
|
||||
await pool.query(query, [identifier, note.title, note.content]);
|
||||
}
|
||||
|
||||
async function fetchAllNotes(identifier: string): Promise<Note[]> {
|
||||
const query =
|
||||
"SELECT * FROM npwd_notes WHERE identifier = ? ORDER BY id DESC";
|
||||
'SELECT * FROM npwd_notes WHERE identifier = ? ORDER BY id DESC';
|
||||
const [result] = await pool.query(query, [identifier]);
|
||||
const notes = <Note[]>result;
|
||||
return notes;
|
||||
}
|
||||
|
||||
async function deleteNote(noteId: number, identifier: string) {
|
||||
const query = "DELETE FROM npwd_notes WHERE id = ? AND identifier = ?";
|
||||
const query = 'DELETE FROM npwd_notes WHERE id = ? AND identifier = ?';
|
||||
await pool.query(query, [noteId, identifier]);
|
||||
}
|
||||
|
||||
async function updateNote(note: Note, identifier: string): Promise<any> {
|
||||
const query =
|
||||
"UPDATE npwd_notes SET title = ?, content = ? WHERE id = ? AND identifier = ?";
|
||||
'UPDATE npwd_notes SET title = ?, content = ? WHERE id = ? AND identifier = ?';
|
||||
await pool.query(query, [note.title, note.content, note.id, identifier]);
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ onNet(events.NOTE_ADD_NOTE, async (note: Note) => {
|
||||
addNote(_identifier, note);
|
||||
emitNet(events.NOTE_SEND_NOTE_SUCCESS, getSource());
|
||||
} catch (error) {
|
||||
console.log("NOTES ERROR: ", error);
|
||||
console.log('NOTES ERROR: ', error);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -45,7 +45,7 @@ onNet(events.NOTE_FETCH_ALL_NOTES, async () => {
|
||||
const notes = await fetchAllNotes(_identifier);
|
||||
emitNet(events.NOTE_SEND_NOTE, _source, notes);
|
||||
} catch (error) {
|
||||
console.log("NOTE ERROR: ", error);
|
||||
console.log('NOTE ERROR: ', error);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -55,7 +55,7 @@ onNet(events.NOTE_DELETE_NOTE, async (noteId: NoteId) => {
|
||||
const id = noteId.id;
|
||||
await deleteNote(id, _identifier);
|
||||
} catch (error) {
|
||||
console.log("NOTE ERROR:", error);
|
||||
console.log('NOTE ERROR:', error);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
import events from "../utils/events";
|
||||
import { ESX, getSource } from "./server";
|
||||
import { pool } from "./db";
|
||||
import { useIdentifier } from "./functions";
|
||||
import { IPhoto } from "../../phone/src/common/typings/photo";
|
||||
import events from '../utils/events';
|
||||
import { ESX, getSource } from './server';
|
||||
import { pool } from './db';
|
||||
import { useIdentifier } from './functions';
|
||||
import { IPhoto } from '../../phone/src/common/typings/photo';
|
||||
|
||||
async function uploadPhoto(identifier: string, image: string) {
|
||||
const query =
|
||||
"INSERT INTO npwd_phone_gallery (identifier, image) VALUES (?, ?)";
|
||||
'INSERT INTO npwd_phone_gallery (identifier, image) VALUES (?, ?)';
|
||||
await pool.query(query, [identifier, image]);
|
||||
}
|
||||
|
||||
async function getPhotosByIdentifier(identifier: string): Promise<IPhoto[]> {
|
||||
const query =
|
||||
"SELECT id, image FROM npwd_phone_gallery WHERE identifier = ? ORDER BY id DESC";
|
||||
'SELECT id, image FROM npwd_phone_gallery WHERE identifier = ? ORDER BY id DESC';
|
||||
const [results] = await pool.query(query, [identifier]);
|
||||
const photos = <IPhoto[]>results;
|
||||
return photos;
|
||||
@@ -20,7 +20,7 @@ async function getPhotosByIdentifier(identifier: string): Promise<IPhoto[]> {
|
||||
|
||||
async function deletePhoto(photo: IPhoto, identifier: string) {
|
||||
const query =
|
||||
"DELETE FROM npwd_phone_gallery WHERE id = ? AND identifier = ?";
|
||||
'DELETE FROM npwd_phone_gallery WHERE id = ? AND identifier = ?';
|
||||
await pool.query(query, [photo.id, identifier]);
|
||||
console.log(photo.id);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import events from "../utils/events";
|
||||
import { ESX } from "./server";
|
||||
import { getSource } from "./functions";
|
||||
import { pool } from "./db";
|
||||
import { usePhoneNumber } from "./functions";
|
||||
import events from '../utils/events';
|
||||
import { ESX } from './server';
|
||||
import { getSource } from './functions';
|
||||
import { pool } from './db';
|
||||
import { usePhoneNumber } from './functions';
|
||||
|
||||
interface Listing {
|
||||
title: string;
|
||||
@@ -12,7 +12,7 @@ interface Listing {
|
||||
}
|
||||
|
||||
async function fetchAllListings(): Promise<Listing[]> {
|
||||
const query = "SELECT * FROM npwd_sellout_listings ORDER BY id DESC";
|
||||
const query = 'SELECT * FROM npwd_sellout_listings ORDER BY id DESC';
|
||||
|
||||
const [results] = await pool.query(query);
|
||||
const listings = <Listing[]>results;
|
||||
@@ -27,7 +27,7 @@ async function addListing(
|
||||
listing: Listing
|
||||
): Promise<any> {
|
||||
const query =
|
||||
"INSERT INTO npwd_sellout_listings (identifier, name, number, title, url, description) VALUES (?, ?, ?, ?, ?, ?)";
|
||||
'INSERT INTO npwd_sellout_listings (identifier, name, number, title, url, description) VALUES (?, ?, ?, ?, ?, ?)';
|
||||
await pool.query(query, [
|
||||
identifier,
|
||||
name,
|
||||
@@ -57,6 +57,6 @@ 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);
|
||||
console.log('Failed to add contact: ', error);
|
||||
}
|
||||
});
|
||||
@@ -1,10 +1,10 @@
|
||||
import { pool } from "./db";
|
||||
import { ESX } from "./server";
|
||||
import { getSource } from "./functions";
|
||||
import { Tweet, Profile } from "../../phone/src/common/typings/twitter";
|
||||
import events from "../utils/events";
|
||||
import config from "../utils/config";
|
||||
import { reportTweetToDiscord } from "./discord";
|
||||
import { pool } from './db';
|
||||
import { ESX } from './server';
|
||||
import { getSource } from './functions';
|
||||
import { Tweet, Profile } from '../../phone/src/common/typings/twitter';
|
||||
import events from '../utils/events';
|
||||
import config from '../utils/config';
|
||||
import { reportTweetToDiscord } from './discord';
|
||||
|
||||
interface ProfileName {
|
||||
profile_name: string;
|
||||
@@ -153,7 +153,7 @@ async function getProfile(identifier: string): Promise<Profile | null> {
|
||||
* @param identifier - player's identifier
|
||||
*/
|
||||
async function generateProfileName(identifier: string): Promise<string> {
|
||||
const defaultProfileName = "";
|
||||
const defaultProfileName = '';
|
||||
if (!config.twitter.generateProfileNameFromUsers) return defaultProfileName;
|
||||
|
||||
const query = `
|
||||
@@ -378,7 +378,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");
|
||||
console.warn('This profile has already reported this tweet');
|
||||
} else {
|
||||
await createTweetReport(tweet.id, profile.id);
|
||||
await reportTweetToDiscord(tweet, profile);
|
||||
|
||||
Reference in new issue
Block a user