mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-04 14:38:45 +00:00
120 in printWidth since rocky got md
This commit is contained in:
1 parent
f552c1212c
commit
d27aeb3b0e
90 files changed
+398
-1146
No files matched your search
@@ -13,9 +13,7 @@ import { mainLogger } from './sv_logger';
|
||||
// we require set mysql_connection_string to be set in the 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.`,
|
||||
);
|
||||
const error = new Error(`No connection string provided. make sure "${CONNECTION_STRING}" is set in your config.`);
|
||||
mainLogger.error(error.message);
|
||||
throw error;
|
||||
}
|
||||
|
||||
@@ -14,9 +14,7 @@ interface Map {
|
||||
export function parseSemiColonFormat(connectionString: string): Map {
|
||||
const parts = connectionString.split(';');
|
||||
if (parts.length === 1) {
|
||||
throw new Error(
|
||||
`Connection string ${connectionString} is in the incorrect format. Please follow the README.`,
|
||||
);
|
||||
throw new Error(`Connection string ${connectionString} is in the incorrect format. Please follow the README.`);
|
||||
}
|
||||
|
||||
return parts.reduce((connectionInfo: Map, part) => {
|
||||
|
||||
@@ -15,10 +15,7 @@ const DISCORD_HEADERS = { authorization: `Bot ${DISCORD_TOKEN}` };
|
||||
const BASE_URL = 'https://discord.com/api';
|
||||
const POST_CHANNEL_URL = `${BASE_URL}/channels/${DISCORD_CHANNEL_ID}/messages`;
|
||||
|
||||
export async function reportTweetToDiscord(
|
||||
tweet: Tweet,
|
||||
reportingProfile: Profile,
|
||||
): Promise<any> {
|
||||
export async function reportTweetToDiscord(tweet: Tweet, reportingProfile: Profile): Promise<any> {
|
||||
if (!DISCORD_TOKEN || !DISCORD_CHANNEL_ID) {
|
||||
discordLogger.warn(`Got a request to report a tweet but discord is not
|
||||
configured. See README on how to configure discord endpoints.`);
|
||||
|
||||
@@ -13,9 +13,7 @@ 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)}`,
|
||||
);
|
||||
bankLogger.verbose(`Fetched all transactions (${identifier}) - ${JSON.stringify(transactions)}`);
|
||||
|
||||
return transactions;
|
||||
}
|
||||
|
||||
+20
-42
@@ -1,11 +1,6 @@
|
||||
import { ESX } from './server';
|
||||
import events from '../utils/events';
|
||||
import {
|
||||
getIdentifierByPhoneNumber,
|
||||
usePhoneNumber,
|
||||
getIdentifier,
|
||||
getSource,
|
||||
} from './functions';
|
||||
import { getIdentifierByPhoneNumber, usePhoneNumber, getIdentifier, getSource } from './functions';
|
||||
import { XPlayer } from 'esx.js/@types/server';
|
||||
import { ICall } from '../../phone/src/common/typings/call';
|
||||
|
||||
@@ -35,8 +30,7 @@ async function getPlayerFromIdentifier(identifier: string): Promise<XPlayer> {
|
||||
}
|
||||
|
||||
async function saveCall(call: ICall) {
|
||||
const query =
|
||||
'INSERT INTO npwd_calls (identifier, transmitter, receiver, start) VALUES (?, ?, ?, ?)';
|
||||
const query = 'INSERT INTO npwd_calls (identifier, transmitter, receiver, start) VALUES (?, ?, ?, ?)';
|
||||
await pool.query(query, [call.identifier, call.transmitter, call.receiver, call.start]);
|
||||
}
|
||||
|
||||
@@ -46,8 +40,7 @@ async function updateCall(call: ICall, isAccepted: boolean, end: number) {
|
||||
}
|
||||
|
||||
async function fetchCalls(phoneNumber: string): Promise<ICall[]> {
|
||||
const query =
|
||||
'SELECT * FROM npwd_calls WHERE receiver = ? OR transmitter = ? ORDER BY id DESC';
|
||||
const query = 'SELECT * FROM npwd_calls WHERE receiver = ? OR transmitter = ? ORDER BY id DESC';
|
||||
const [result] = await pool.query(query, [phoneNumber, phoneNumber]);
|
||||
const calls = <ICall[]>result;
|
||||
return calls;
|
||||
@@ -87,13 +80,7 @@ onNet(events.PHONE_INITIALIZE_CALL, async (phoneNumber: string, timestamp: numbe
|
||||
emitNet(events.PHONE_START_CALL, _source, transmitterNumber, receiverNumber, true);
|
||||
|
||||
// client that is being called
|
||||
emitNet(
|
||||
events.PHONE_START_CALL,
|
||||
xReceiver.source,
|
||||
transmitterNumber,
|
||||
receiverNumber,
|
||||
false,
|
||||
);
|
||||
emitNet(events.PHONE_START_CALL, xReceiver.source, transmitterNumber, receiverNumber, false);
|
||||
});
|
||||
|
||||
onNet(events.PHONE_ACCEPT_CALL, async (transmitterNumber: string) => {
|
||||
@@ -108,13 +95,7 @@ onNet(events.PHONE_ACCEPT_CALL, async (transmitterNumber: string) => {
|
||||
emitNet(events.PHONE_CALL_WAS_ACCEPTED, pSource, channelId, currentCall, false);
|
||||
|
||||
// player who is calling
|
||||
emitNet(
|
||||
events.PHONE_CALL_WAS_ACCEPTED,
|
||||
currentCall.transmitterSource,
|
||||
channelId,
|
||||
currentCall,
|
||||
true,
|
||||
);
|
||||
emitNet(events.PHONE_CALL_WAS_ACCEPTED, currentCall.transmitterSource, channelId, currentCall, true);
|
||||
|
||||
currentCall.accepted = true;
|
||||
} catch (e) {
|
||||
@@ -124,25 +105,22 @@ onNet(events.PHONE_ACCEPT_CALL, async (transmitterNumber: string) => {
|
||||
}
|
||||
});
|
||||
|
||||
onNet(
|
||||
events.PHONE_CALL_REJECTED,
|
||||
async (transmitterNumber: string, timestamp: number) => {
|
||||
const pSource = getSource();
|
||||
try {
|
||||
const currentCall = calls.get(transmitterNumber);
|
||||
await updateCall(currentCall, false, timestamp);
|
||||
onNet(events.PHONE_CALL_REJECTED, async (transmitterNumber: string, timestamp: number) => {
|
||||
const pSource = getSource();
|
||||
try {
|
||||
const currentCall = calls.get(transmitterNumber);
|
||||
await updateCall(currentCall, false, timestamp);
|
||||
|
||||
// player who is called and initiasted the rejection.
|
||||
emitNet(events.PHONE_CALL_WAS_REJECTED, currentCall.receiverSource);
|
||||
// player who is calling and recieved the rejection.
|
||||
emitNet(events.PHONE_CALL_WAS_REJECTED, currentCall.transmitterSource);
|
||||
} catch (e) {
|
||||
callLogger.error(`Phone Call Rejected Event Error ${e.message}`, {
|
||||
source: pSource,
|
||||
});
|
||||
}
|
||||
},
|
||||
);
|
||||
// player who is called and initiasted the rejection.
|
||||
emitNet(events.PHONE_CALL_WAS_REJECTED, currentCall.receiverSource);
|
||||
// player who is calling and recieved the rejection.
|
||||
emitNet(events.PHONE_CALL_WAS_REJECTED, currentCall.transmitterSource);
|
||||
} catch (e) {
|
||||
callLogger.error(`Phone Call Rejected Event Error ${e.message}`, {
|
||||
source: pSource,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
onNet(events.PHONE_END_CALL, async (transmitterNumber: string, timestamp: number) => {
|
||||
const pSource = getSource();
|
||||
|
||||
@@ -18,35 +18,21 @@ interface ContactId {
|
||||
}
|
||||
|
||||
async function fetchAllContacts(identifier: string): Promise<Contacts[]> {
|
||||
const query =
|
||||
'SELECT * FROM npwd_phone_contacts WHERE identifier = ? ORDER BY display ASC';
|
||||
const query = 'SELECT * FROM npwd_phone_contacts WHERE identifier = ? ORDER BY display ASC';
|
||||
const [results] = await pool.query(query, [identifier]);
|
||||
const contacts = <Contacts[]>results;
|
||||
return contacts;
|
||||
}
|
||||
|
||||
async function addContact(
|
||||
identifier: string,
|
||||
number: string,
|
||||
display: string,
|
||||
avatar: string,
|
||||
): Promise<any> {
|
||||
const query =
|
||||
'INSERT INTO npwd_phone_contacts (identifier, number, display, avatar) VALUES (?, ?, ?, ?)';
|
||||
async function addContact(identifier: string, number: string, display: string, avatar: string): Promise<any> {
|
||||
const query = 'INSERT INTO npwd_phone_contacts (identifier, number, display, avatar) VALUES (?, ?, ?, ?)';
|
||||
|
||||
const [result] = await pool.query(query, [identifier, number, display, avatar]);
|
||||
}
|
||||
|
||||
async function updateContact(contact: Contacts, identifier: string): Promise<any> {
|
||||
const query =
|
||||
'UPDATE npwd_phone_contacts SET number = ?, display = ?, avatar = ? WHERE id = ? AND identifier = ?';
|
||||
await pool.query(query, [
|
||||
contact.number,
|
||||
contact.display,
|
||||
contact.avatar,
|
||||
contact.id,
|
||||
identifier,
|
||||
]);
|
||||
const query = 'UPDATE npwd_phone_contacts SET number = ?, display = ?, avatar = ? WHERE id = ? AND identifier = ?';
|
||||
await pool.query(query, [contact.number, contact.display, contact.avatar, contact.id, identifier]);
|
||||
}
|
||||
|
||||
async function deleteContact(contact: ContactId, identifier: string): Promise<any> {
|
||||
@@ -66,29 +52,26 @@ onNet(events.CONTACTS_GET_CONTACTS, async () => {
|
||||
}
|
||||
});
|
||||
|
||||
onNet(
|
||||
events.CONTACTS_ADD_CONTACT,
|
||||
async (number: string, display: string, avatar: string) => {
|
||||
const _source = getSource();
|
||||
try {
|
||||
const _identifier = getIdentifier(_source);
|
||||
await addContact(_identifier, number, display, avatar);
|
||||
emitNet(events.CONTACTS_ADD_CONTACT_SUCCESS, _source);
|
||||
emitNet(events.CONTACTS_ACTION_RESULT, _source, {
|
||||
message: 'CONTACT_ADD_SUCCESS',
|
||||
type: 'success',
|
||||
});
|
||||
} catch (e) {
|
||||
emitNet(events.CONTACTS_ACTION_RESULT, _source, {
|
||||
message: 'CONTACT_ADD_FAILED',
|
||||
type: 'error',
|
||||
});
|
||||
contactsLogger.error(`Failed to add contact, ${e.message}`, {
|
||||
source: _source,
|
||||
});
|
||||
}
|
||||
},
|
||||
);
|
||||
onNet(events.CONTACTS_ADD_CONTACT, async (number: string, display: string, avatar: string) => {
|
||||
const _source = getSource();
|
||||
try {
|
||||
const _identifier = getIdentifier(_source);
|
||||
await addContact(_identifier, number, display, avatar);
|
||||
emitNet(events.CONTACTS_ADD_CONTACT_SUCCESS, _source);
|
||||
emitNet(events.CONTACTS_ACTION_RESULT, _source, {
|
||||
message: 'CONTACT_ADD_SUCCESS',
|
||||
type: 'success',
|
||||
});
|
||||
} catch (e) {
|
||||
emitNet(events.CONTACTS_ACTION_RESULT, _source, {
|
||||
message: 'CONTACT_ADD_FAILED',
|
||||
type: 'error',
|
||||
});
|
||||
contactsLogger.error(`Failed to add contact, ${e.message}`, {
|
||||
source: _source,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
onNet(events.CONTACTS_UPDATE_CONTACT, async (contact: Contacts) => {
|
||||
const _source = getSource();
|
||||
|
||||
@@ -7,14 +7,12 @@ const manualColorize = (strToColor: string): string => `[\x1b[35m${strToColor}\x
|
||||
|
||||
// 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}`;
|
||||
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')}`;
|
||||
const findLogPath = () => `${path.join(GetResourcePath(GetCurrentResourceName()), 'sv_npwd.log')}`;
|
||||
// Initiate the main logger for NPWD
|
||||
|
||||
export const mainLogger = winston.createLogger({
|
||||
|
||||
@@ -1,12 +1,7 @@
|
||||
import { ESX } from './server';
|
||||
import { pool } from './db';
|
||||
import config from '../utils/config';
|
||||
import {
|
||||
getIdentifier,
|
||||
getIdentifierByPhoneNumber,
|
||||
getSource,
|
||||
usePhoneNumber,
|
||||
} from './functions';
|
||||
import { getIdentifier, getIdentifierByPhoneNumber, getSource, usePhoneNumber } from './functions';
|
||||
import { mainLogger } from './sv_logger';
|
||||
|
||||
//db = DatabaseConfig //helper variable for use in server function
|
||||
|
||||
+65
-106
@@ -1,11 +1,7 @@
|
||||
import md5 from 'md5';
|
||||
|
||||
import events from '../utils/events';
|
||||
import {
|
||||
Message,
|
||||
MessageGroup,
|
||||
CreateMessageGroupResult,
|
||||
} from '../../phone/src/common/typings/messages';
|
||||
import { Message, MessageGroup, CreateMessageGroupResult } from '../../phone/src/common/typings/messages';
|
||||
import { pool, withTransaction } from './db';
|
||||
import { getSource, getIdentifier } from './functions';
|
||||
import { mainLogger } from './sv_logger';
|
||||
@@ -46,11 +42,7 @@ interface MessageGroupMapping {
|
||||
* @param groupId - the message group ID to attach this message to
|
||||
* @param message - content of the message
|
||||
*/
|
||||
async function createMessage(
|
||||
userIdentifier: string,
|
||||
groupId: string,
|
||||
message: string,
|
||||
): Promise<any> {
|
||||
async function createMessage(userIdentifier: string, groupId: string, message: string): Promise<any> {
|
||||
const query = `
|
||||
INSERT INTO npwd_messages
|
||||
(user_identifier, message, group_id)
|
||||
@@ -65,9 +57,7 @@ async function createMessage(
|
||||
* populate the list of message groups on the UI
|
||||
* @param userIdentifier - identifier of the user to get message groups for
|
||||
*/
|
||||
async function getMessageGroups(
|
||||
userIdentifier: string,
|
||||
): Promise<UnformattedMessageGroup[]> {
|
||||
async function getMessageGroups(userIdentifier: string): Promise<UnformattedMessageGroup[]> {
|
||||
const query = `
|
||||
SELECT
|
||||
npwd_messages_groups.group_id,
|
||||
@@ -89,11 +79,7 @@ async function getMessageGroups(
|
||||
WHERE npwd_messages_groups.participant_identifier != ?
|
||||
ORDER BY npwd_messages_groups.createdAt DESC
|
||||
`;
|
||||
const [results] = await pool.query(query, [
|
||||
userIdentifier,
|
||||
userIdentifier,
|
||||
userIdentifier,
|
||||
]);
|
||||
const [results] = await pool.query(query, [userIdentifier, userIdentifier, userIdentifier]);
|
||||
return <UnformattedMessageGroup[]>results;
|
||||
}
|
||||
|
||||
@@ -136,11 +122,7 @@ async function getMessages(userIdentifier: string, groupId: string): Promise<Mes
|
||||
* @param groupId - groupId this label is attached to
|
||||
* @param label - the label itself
|
||||
*/
|
||||
async function createLabel(
|
||||
userIdentifier: string,
|
||||
groupId: string,
|
||||
label: string,
|
||||
): Promise<any> {
|
||||
async function createLabel(userIdentifier: string, groupId: string, label: string): Promise<any> {
|
||||
const query = `
|
||||
INSERT INTO npwd_messages_labels
|
||||
(user_identifier, group_id, label)
|
||||
@@ -166,11 +148,7 @@ async function createMessageGroup(
|
||||
(user_identifier, group_id, participant_identifier)
|
||||
VALUES (?, ?, ?)
|
||||
`;
|
||||
const [results] = await pool.query(query, [
|
||||
userIdentifier,
|
||||
groupId,
|
||||
participantIdentifier,
|
||||
]);
|
||||
const [results] = await pool.query(query, [userIdentifier, groupId, participantIdentifier]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -225,36 +203,28 @@ async function getMessageCountByGroup(groupId: string): Promise<number> {
|
||||
* groups into a single MessageGroup object.
|
||||
* @param userIdentifier - the user identifier to get message groups for
|
||||
*/
|
||||
async function getConsolidatedMessageGroups(
|
||||
userIdentifier: string,
|
||||
): Promise<MessageGroupMapping> {
|
||||
async function getConsolidatedMessageGroups(userIdentifier: string): Promise<MessageGroupMapping> {
|
||||
const messageGroups = await getMessageGroups(userIdentifier);
|
||||
return messageGroups.reduce(
|
||||
(mapping: MessageGroupMapping, messageGroup: UnformattedMessageGroup) => {
|
||||
const groupId = messageGroup.group_id;
|
||||
const displayTerm = messageGroup.display || messageGroup.phone_number || '???';
|
||||
return messageGroups.reduce((mapping: MessageGroupMapping, messageGroup: UnformattedMessageGroup) => {
|
||||
const groupId = messageGroup.group_id;
|
||||
const displayTerm = messageGroup.display || messageGroup.phone_number || '???';
|
||||
|
||||
if (groupId in mapping) {
|
||||
mapping[groupId].participants = mapping[groupId].participants.concat(displayTerm);
|
||||
} else {
|
||||
mapping[groupId] = {
|
||||
user_identifier: messageGroup.user_identifier,
|
||||
avatar: messageGroup.avatar,
|
||||
label: messageGroup.label,
|
||||
participants: [displayTerm],
|
||||
updatedAt: messageGroup.updatedAt ? messageGroup.updatedAt.toString() : null,
|
||||
};
|
||||
}
|
||||
return mapping;
|
||||
},
|
||||
{},
|
||||
);
|
||||
if (groupId in mapping) {
|
||||
mapping[groupId].participants = mapping[groupId].participants.concat(displayTerm);
|
||||
} else {
|
||||
mapping[groupId] = {
|
||||
user_identifier: messageGroup.user_identifier,
|
||||
avatar: messageGroup.avatar,
|
||||
label: messageGroup.label,
|
||||
participants: [displayTerm],
|
||||
updatedAt: messageGroup.updatedAt ? messageGroup.updatedAt.toString() : null,
|
||||
};
|
||||
}
|
||||
return mapping;
|
||||
}, {});
|
||||
}
|
||||
|
||||
async function getGroupIds(
|
||||
userIdentifier: string,
|
||||
groupMapping: MessageGroupMapping,
|
||||
): Promise<string[]> {
|
||||
async function getGroupIds(userIdentifier: string, groupMapping: MessageGroupMapping): Promise<string[]> {
|
||||
const groupIds: string[] = [];
|
||||
for (const groupId of Object.keys(groupMapping)) {
|
||||
const isMine = groupMapping[groupId].user_identifier === userIdentifier;
|
||||
@@ -270,9 +240,7 @@ async function getGroupIds(
|
||||
* of MessageGroup objects ready for the UI to consume
|
||||
* @param userIdentifier - user to generate the MessageGroups for
|
||||
*/
|
||||
async function getFormattedMessageGroups(
|
||||
userIdentifier: string,
|
||||
): Promise<MessageGroup[]> {
|
||||
async function getFormattedMessageGroups(userIdentifier: string): Promise<MessageGroup[]> {
|
||||
const groupMapping = await getConsolidatedMessageGroups(userIdentifier);
|
||||
const groupIds = await getGroupIds(userIdentifier, groupMapping);
|
||||
|
||||
@@ -352,9 +320,7 @@ async function createMessageGroupsFromPhoneNumbers(
|
||||
// create a row that contains ourselves so reverse accessing from
|
||||
// other players works as expected
|
||||
createMessageGroup(userIdentifier, groupId, userIdentifier),
|
||||
...identifiers.map((identifier) =>
|
||||
createMessageGroup(userIdentifier, groupId, identifier),
|
||||
),
|
||||
...identifiers.map((identifier) => createMessageGroup(userIdentifier, groupId, identifier)),
|
||||
];
|
||||
|
||||
// we allow users to attach labels to name their group chats
|
||||
@@ -386,60 +352,53 @@ onNet(events.MESSAGES_FETCH_MESSAGE_GROUPS, async () => {
|
||||
}
|
||||
});
|
||||
|
||||
onNet(
|
||||
events.MESSAGES_CREATE_MESSAGE_GROUP,
|
||||
async (phoneNumbers: string[], label: string = null) => {
|
||||
const _source = getSource();
|
||||
try {
|
||||
const _identifier = await getIdentifier(_source);
|
||||
const result = await createMessageGroupsFromPhoneNumbers(
|
||||
_identifier,
|
||||
phoneNumbers,
|
||||
label,
|
||||
);
|
||||
onNet(events.MESSAGES_CREATE_MESSAGE_GROUP, async (phoneNumbers: string[], label: string = null) => {
|
||||
const _source = getSource();
|
||||
try {
|
||||
const _identifier = await getIdentifier(_source);
|
||||
const result = await createMessageGroupsFromPhoneNumbers(_identifier, phoneNumbers, label);
|
||||
|
||||
if (result.error && result.duplicate) {
|
||||
emitNet(events.MESSAGES_ACTION_RESULT, _source, {
|
||||
message: 'MESSAGES_MESSAGE_GROUP_DUPLICATE',
|
||||
type: 'error',
|
||||
});
|
||||
if (result.error && result.duplicate) {
|
||||
emitNet(events.MESSAGES_ACTION_RESULT, _source, {
|
||||
message: 'MESSAGES_MESSAGE_GROUP_DUPLICATE',
|
||||
type: 'error',
|
||||
});
|
||||
|
||||
// if the phoneNumber is invalid
|
||||
} else if (result.error && result.phoneNumber) {
|
||||
emitNet(events.MESSAGES_ACTION_RESULT, _source, {
|
||||
message: 'MESSAGES_INVALID_PHONE_NUMBER',
|
||||
type: 'error',
|
||||
});
|
||||
|
||||
// if you are try to add yourself
|
||||
} else if (result.error && result.mine) {
|
||||
emitNet(events.MESSAGES_ACTION_RESULT, _source, {
|
||||
message: 'MESSAGES_MESSAGE_GROUP_CREATE_MINE',
|
||||
type: 'error',
|
||||
});
|
||||
} else if (result.error) {
|
||||
// if it just fails, welp
|
||||
emitNet(events.MESSAGES_CREATE_MESSAGE_GROUP_FAILED, _source, result);
|
||||
emitNet(events.MESSAGES_ACTION_RESULT, _source, {
|
||||
message: `MESSAGES_MESSAGE_GROUP_CREATE_FAILED:`,
|
||||
type: 'error',
|
||||
});
|
||||
} else {
|
||||
emitNet(events.MESSAGES_CREATE_MESSAGE_GROUP_SUCCESS, _source, result);
|
||||
}
|
||||
} catch (e) {
|
||||
emitNet(events.MESSAGES_CREATE_MESSAGE_GROUP_FAILED, _source);
|
||||
// if the phoneNumber is invalid
|
||||
} else if (result.error && result.phoneNumber) {
|
||||
emitNet(events.MESSAGES_ACTION_RESULT, _source, {
|
||||
message: 'MESSAGES_INVALID_PHONE_NUMBER',
|
||||
type: 'error',
|
||||
});
|
||||
|
||||
// if you are try to add yourself
|
||||
} else if (result.error && result.mine) {
|
||||
emitNet(events.MESSAGES_ACTION_RESULT, _source, {
|
||||
message: 'MESSAGES_MESSAGE_GROUP_CREATE_MINE',
|
||||
type: 'error',
|
||||
});
|
||||
} else if (result.error) {
|
||||
// if it just fails, welp
|
||||
emitNet(events.MESSAGES_CREATE_MESSAGE_GROUP_FAILED, _source, result);
|
||||
emitNet(events.MESSAGES_ACTION_RESULT, _source, {
|
||||
message: `MESSAGES_MESSAGE_GROUP_CREATE_FAILED:`,
|
||||
type: 'error',
|
||||
});
|
||||
messageLogger.error(`Failed to create message group, ${e.message}`, {
|
||||
source: _source,
|
||||
});
|
||||
} else {
|
||||
emitNet(events.MESSAGES_CREATE_MESSAGE_GROUP_SUCCESS, _source, result);
|
||||
}
|
||||
},
|
||||
);
|
||||
} catch (e) {
|
||||
emitNet(events.MESSAGES_CREATE_MESSAGE_GROUP_FAILED, _source);
|
||||
|
||||
emitNet(events.MESSAGES_ACTION_RESULT, _source, {
|
||||
message: `MESSAGES_MESSAGE_GROUP_CREATE_FAILED:`,
|
||||
type: 'error',
|
||||
});
|
||||
messageLogger.error(`Failed to create message group, ${e.message}`, {
|
||||
source: _source,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
onNet(events.MESSAGES_FETCH_MESSAGES, async (groupId: string) => {
|
||||
const _source = getSource();
|
||||
|
||||
@@ -23,8 +23,7 @@ async function deleteNote(noteId: number, identifier: string) {
|
||||
}
|
||||
|
||||
async function updateNote(note: Note, identifier: string): Promise<any> {
|
||||
const query =
|
||||
'UPDATE npwd_notes SET title = ?, content = ? WHERE id = ? AND identifier = ?';
|
||||
const query = 'UPDATE npwd_notes SET title = ?, content = ? WHERE id = ? AND identifier = ?';
|
||||
await pool.query(query, [note.title, note.content, note.id, identifier]);
|
||||
}
|
||||
|
||||
|
||||
@@ -12,8 +12,7 @@ async function uploadPhoto(identifier: string, image: string) {
|
||||
}
|
||||
|
||||
async function getPhotosByIdentifier(identifier: string): Promise<IPhoto[]> {
|
||||
const query =
|
||||
'SELECT id, image FROM npwd_phone_gallery WHERE identifier = ? ORDER BY id DESC';
|
||||
const query = '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;
|
||||
|
||||
@@ -17,22 +17,10 @@ async function fetchAllListings(): Promise<MarketplaceListing[]> {
|
||||
return listings;
|
||||
}
|
||||
|
||||
async function addListing(
|
||||
identifier: string,
|
||||
name: string,
|
||||
number: any,
|
||||
listing: MarketplaceListing,
|
||||
): Promise<void> {
|
||||
async function addListing(identifier: string, name: string, number: any, listing: MarketplaceListing): Promise<void> {
|
||||
const query =
|
||||
'INSERT INTO npwd_sellout_listings (identifier, name, number, title, url, description) VALUES (?, ?, ?, ?, ?, ?)';
|
||||
await pool.query(query, [
|
||||
identifier,
|
||||
name,
|
||||
number,
|
||||
listing.title,
|
||||
listing.url,
|
||||
listing.description,
|
||||
]);
|
||||
await pool.query(query, [identifier, name, number, listing.title, listing.url, listing.description]);
|
||||
}
|
||||
|
||||
onNet(events.SELLOUT_FETCH_LISTING, async () => {
|
||||
|
||||
@@ -49,10 +49,7 @@ async function fetchAllTweets(profileId: number): Promise<Tweet[]> {
|
||||
* @param profileId - twitter profile id of the player
|
||||
* @param searchValue - value to search
|
||||
*/
|
||||
async function fetchTweetsFiltered(
|
||||
profileId: number,
|
||||
searchValue: string,
|
||||
): Promise<Tweet[]> {
|
||||
async function fetchTweetsFiltered(profileId: number, searchValue: string): Promise<Tweet[]> {
|
||||
const parameterizedSearchValue = `%${searchValue}%`;
|
||||
const query = `
|
||||
SELECT
|
||||
@@ -71,12 +68,7 @@ async function fetchTweetsFiltered(
|
||||
ORDER BY npwd_twitter_tweets.createdAt DESC
|
||||
LIMIT 100
|
||||
`;
|
||||
const [results] = await pool.query(query, [
|
||||
profileId,
|
||||
profileId,
|
||||
parameterizedSearchValue,
|
||||
parameterizedSearchValue,
|
||||
]);
|
||||
const [results] = await pool.query(query, [profileId, profileId, parameterizedSearchValue, parameterizedSearchValue]);
|
||||
const tweets = <Tweet[]>results;
|
||||
return tweets.map((tweet) => ({
|
||||
...tweet,
|
||||
|
||||
Reference in new issue
Block a user