mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-04 14:38:45 +00:00
Tweak/marketplace additions (#137)
Checks for being the OP of the listing. Calling, Message, Delete and Report. Updates to Locale is needed.
This commit is contained in:
1 parent
0203ebbe51
commit
6b6080c4b2
13 files changed
+277
-47
No files matched your search
@@ -13,17 +13,31 @@ onNet(events.SELLOUT_SEND_LISTING, (listing: MarketplaceListing) => {
|
||||
});
|
||||
|
||||
RegisterNuiCallbackType(events.SELLOUT_ADD_LISTING);
|
||||
on(`__cfx_nui:${events.SELLOUT_ADD_LISTING}`, (data: MarketplaceListing) => {
|
||||
on(`__cfx_nui:${events.SELLOUT_ADD_LISTING}`, (data: MarketplaceListing, cb: Function) => {
|
||||
emitNet(events.SELLOUT_ADD_LISTING, data);
|
||||
cb();
|
||||
});
|
||||
|
||||
// this will be triggerd when
|
||||
// the adding of a new listing is successfully
|
||||
RegisterNuiCallbackType(events.SELLOUT_DELETE_LISTING);
|
||||
on(`__cfx_nui:${events.SELLOUT_DELETE_LISTING}`, (data: MarketplaceListing, cb: Function) => {
|
||||
emitNet(events.SELLOUT_DELETE_LISTING, data.id);
|
||||
cb();
|
||||
});
|
||||
|
||||
RegisterNuiCallbackType(events.SELLOUT_REPORT_LISTING);
|
||||
on(`__cfx_nui:${events.SELLOUT_REPORT_LISTING}`, (data: MarketplaceListing, cb: Function) => {
|
||||
emitNet(events.SELLOUT_SEND_LISTING, data);
|
||||
cb();
|
||||
});
|
||||
|
||||
onNet(events.SELLOUT_ADD_LISTING_SUCCESS, () => {
|
||||
emitNet(events.SELLOUT_FETCH_LISTING);
|
||||
});
|
||||
|
||||
onNet(events.SELLOUT_DELETE_LISTING_SUCCESS, () => {
|
||||
emitNet(events.SELLOUT_FETCH_LISTING);
|
||||
});
|
||||
|
||||
onNet(events.SELLOUT_ACTION_RESULT, (alert: IAlertProps) => {
|
||||
SendNuiMessage(
|
||||
JSON.stringify({
|
||||
|
||||
@@ -3,6 +3,7 @@ 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';
|
||||
import { MarketplaceListing } from '../../phone/src/common/typings/marketplace';
|
||||
|
||||
const discordLogger = mainLogger.child({ module: 'discord' });
|
||||
|
||||
@@ -37,3 +38,28 @@ export async function reportTweetToDiscord(tweet: Tweet, reportingProfile: Profi
|
||||
|
||||
return await axios.post(POST_CHANNEL_URL, { content }, { headers: DISCORD_HEADERS });
|
||||
}
|
||||
|
||||
export async function reportListingToDiscord(
|
||||
listing: MarketplaceListing,
|
||||
reportingProfile: string,
|
||||
): Promise<any> {
|
||||
if (!DISCORD_TOKEN || !DISCORD_CHANNEL_ID) {
|
||||
discordLogger.warn(
|
||||
'Got a request to report a listing but discord is not configures. See README o how to configure discord endpoints.',
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
const content = `**REPORTED LISTING**
|
||||
-------------------------------------------------
|
||||
**Reporting User**: ${reportingProfile}
|
||||
**Reported User** ${listing.name} (${listing.username})
|
||||
-------------------------------------------------
|
||||
**Reported Listing**
|
||||
${listing.title}
|
||||
----
|
||||
${listing.description}
|
||||
`;
|
||||
|
||||
return await axios.post(POST_CHANNEL_URL, { content }, { headers: DISCORD_HEADERS });
|
||||
}
|
||||
@@ -1,10 +1,11 @@
|
||||
import events from '../utils/events';
|
||||
import { ESX } from './server';
|
||||
import { getSource } from './functions';
|
||||
import { getIdentifier, getSource } from './functions';
|
||||
import { pool } from './db';
|
||||
import { usePhoneNumber } from './functions';
|
||||
import { mainLogger } from './sv_logger';
|
||||
import { MarketplaceListing } from '../../phone/src/common/typings/marketplace';
|
||||
import { reportListingToDiscord } from './discord';
|
||||
|
||||
const selloutLogger = mainLogger.child({ module: 'sellout' });
|
||||
|
||||
@@ -19,14 +20,16 @@ async function fetchAllListings(): Promise<MarketplaceListing[]> {
|
||||
|
||||
async function addListing(
|
||||
identifier: string,
|
||||
username: string,
|
||||
name: string,
|
||||
number: any,
|
||||
listing: MarketplaceListing,
|
||||
): Promise<void> {
|
||||
const query =
|
||||
'INSERT INTO npwd_sellout_listings (identifier, name, number, title, url, description) VALUES (?, ?, ?, ?, ?, ?)';
|
||||
'INSERT INTO npwd_sellout_listings (identifier, username, name, number, title, url, description) VALUES (?, ?, ?, ?, ?, ?, ?)';
|
||||
await pool.query(query, [
|
||||
identifier,
|
||||
username,
|
||||
name,
|
||||
number,
|
||||
listing.title,
|
||||
@@ -35,6 +38,35 @@ async function addListing(
|
||||
]);
|
||||
}
|
||||
|
||||
async function deleteListing(listingId: number, identifier: string): Promise<void> {
|
||||
const query = 'DELETE FROM npwd_sellout_listings WHERE id = ? AND identifier = ?';
|
||||
|
||||
await pool.query(query, [listingId, identifier]);
|
||||
}
|
||||
|
||||
async function getListing(listingId: number): Promise<MarketplaceListing> {
|
||||
const query = `SELECT * FROM npwd_sellout_listings WHERE id = ?`;
|
||||
const [results] = await pool.query(query, [listingId]);
|
||||
const listings = <MarketplaceListing[]>results;
|
||||
const listing = listings[0];
|
||||
|
||||
return listing;
|
||||
}
|
||||
|
||||
async function reportListing(listingId: number, profile: string): Promise<void> {
|
||||
const query = `INSERT INTO npwd_marketplace_reports (listing_id, profile) VALUES (?, ?)`;
|
||||
|
||||
await pool.query(query, [listingId, profile]);
|
||||
}
|
||||
|
||||
async function doesReportExist(listingId: number, profile: string): Promise<boolean> {
|
||||
const query = `SELECT * FROM npwd_marketplace_reports WHERE listing_id = ? AND profile = ?`;
|
||||
const results = await pool.query(query, [listingId, profile]);
|
||||
const result = <any[]>results;
|
||||
|
||||
return result.length > 0;
|
||||
}
|
||||
|
||||
onNet(events.SELLOUT_FETCH_LISTING, async () => {
|
||||
const _source = getSource();
|
||||
try {
|
||||
@@ -54,8 +86,11 @@ onNet(events.SELLOUT_ADD_LISTING, async (listing: MarketplaceListing) => {
|
||||
const _identifier = xPlayer.getIdentifier();
|
||||
const name = xPlayer.getName();
|
||||
|
||||
// This is used as username for the reports
|
||||
const playerName = GetPlayerName(_source);
|
||||
|
||||
const phoneNumber = await usePhoneNumber(_identifier);
|
||||
await addListing(_identifier, name, phoneNumber, listing);
|
||||
await addListing(_identifier, playerName, name, phoneNumber, listing);
|
||||
|
||||
emitNet(events.SELLOUT_ADD_LISTING_SUCCESS, _source);
|
||||
emitNet(events.SELLOUT_ACTION_RESULT, _source, {
|
||||
@@ -73,3 +108,62 @@ onNet(events.SELLOUT_ADD_LISTING, async (listing: MarketplaceListing) => {
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
onNet(events.SELLOUT_DELETE_LISTING, async (listingId: number) => {
|
||||
const pSource = getSource();
|
||||
try {
|
||||
const identifier = getIdentifier(pSource);
|
||||
|
||||
await deleteListing(listingId, identifier);
|
||||
|
||||
// fetches the listings again
|
||||
emitNet(events.SELLOUT_DELETE_LISTING_SUCCESS, pSource);
|
||||
|
||||
emitNet(events.SELLOUT_ACTION_RESULT, pSource, {
|
||||
message: 'MARKETPLACE_DELETE_LISTING_SUCCESS',
|
||||
type: 'success',
|
||||
});
|
||||
} catch (e) {
|
||||
selloutLogger.error(`Failed to delete listing ${e.message}`, {
|
||||
source: pSource,
|
||||
});
|
||||
emitNet(events.SELLOUT_ACTION_RESULT, pSource, {
|
||||
message: 'MARKETPLACE_DELETE_LISTING_FAILED',
|
||||
type: 'error',
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
onNet(events.SELLOUT_REPORT_LISTING, async (listing: MarketplaceListing) => {
|
||||
const pSource = getSource();
|
||||
|
||||
try {
|
||||
const rListing = await getListing(listing.id);
|
||||
const reportExists = await doesReportExist(listing.id, listing.name);
|
||||
|
||||
// gets the player name (steam) of the player that is reporting
|
||||
const reportingPlayer = GetPlayerName(pSource);
|
||||
|
||||
if (reportExists) {
|
||||
// send an info alert
|
||||
selloutLogger.error(`This listing has already been reported`);
|
||||
|
||||
emitNet(events.SELLOUT_ACTION_RESULT, pSource, {
|
||||
message: 'MARKETPLACE_REPORT_LISTING_FAILED',
|
||||
type: 'info',
|
||||
});
|
||||
} else {
|
||||
await reportListing(rListing.id, rListing.name);
|
||||
await reportListingToDiscord(rListing, reportingPlayer);
|
||||
|
||||
emitNet(events.SELLOUT_ACTION_RESULT, pSource, {
|
||||
message: 'MARKETPLACE_REPORT_LISTING_SUCCESS',
|
||||
type: 'success',
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
selloutLogger.error(`Failed to report listing ${e.message}`, {
|
||||
source: pSource,
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -44,11 +44,17 @@ export default {
|
||||
CONTACTS_ACTION_RESULT: 'phone:contactActionResult',
|
||||
|
||||
// Sellout
|
||||
// these event keys needs to be changed to 'MARKETPLACE'
|
||||
SELLOUT_ADD_LISTING: 'phone:addListing',
|
||||
SELLOUT_ADD_LISTING_SUCCESS: 'phone:addListingSuccess',
|
||||
SELLOUT_FETCH_LISTING: 'phone:fetchAllListings',
|
||||
SELLOUT_SEND_LISTING: 'phone:sendAllListings',
|
||||
SELLOUT_ACTION_RESULT: 'phone:selloutActionResult',
|
||||
SELLOUT_DELETE_LISTING: 'phone:marketplaceDeleteListing',
|
||||
SELLOUT_DELETE_LISTING_SUCCESS: 'phone:marketplaceDeleteListingSuccess',
|
||||
SELLOUT_REPORT_LISTING: 'phone:reportListing',
|
||||
SELLOUT_REPORT_LISTING_SUCCESS: 'phone:reportListingSuccess',
|
||||
SELLOUT_REPORT_LISTING_SUCESS: 'phone:reportListingFailed',
|
||||
|
||||
//
|
||||
BANK_ADD_TRANSFER: 'phone:addTransfer',
|
||||
|
||||
Reference in new issue
Block a user