mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-05 06:28:51 +00:00
Mysql connection strings, unit tests, prettier on server
This adds support for the other type of Mysql connection string specified by mysql async. Support for both strings and their respective options are necessary to support backwards compatibility of existing server configurations. This also adds support for jest & unit testing on the server/client and some unit tests for some of the connection string parsing. It runs these test and prettier in a pre-commit hook.
This commit is contained in:
1 parent
8d2e0d9edb
commit
a5d1e54b56
21 files changed
+3948
-317
No files matched your search
@@ -0,0 +1,6 @@
|
||||
module.exports = {
|
||||
presets: [
|
||||
['@babel/preset-env', {targets: {node: 'current'}}],
|
||||
'@babel/preset-typescript',
|
||||
],
|
||||
};
|
||||
@@ -1,15 +1,14 @@
|
||||
import { ESX } from '../client/client';
|
||||
import events from '../utils/events';
|
||||
|
||||
import { ESX } from "../client/client";
|
||||
import events from "../utils/events";
|
||||
|
||||
onNet(events.CONTACTS_SEND_CONTACTS, (contacts: any) => {
|
||||
SendNuiMessage(
|
||||
JSON.stringify({
|
||||
app: 'CONTACTS',
|
||||
method: 'setContacts',
|
||||
data: contacts
|
||||
app: "CONTACTS",
|
||||
method: "setContacts",
|
||||
data: contacts,
|
||||
})
|
||||
)
|
||||
);
|
||||
});
|
||||
|
||||
RegisterNuiCallbackType(events.CONTACTS_ADD_CONTACT);
|
||||
@@ -20,6 +19,6 @@ on(`__cfx_nui:${events.CONTACTS_ADD_CONTACT}`, (data: any) => {
|
||||
emitNet(events.CONTACTS_ADD_CONTACT, number, display, avatar);
|
||||
|
||||
setTimeout(() => {
|
||||
emitNet(events.CONTACTS_GET_CONTACTS)
|
||||
}, 1000)
|
||||
emitNet(events.CONTACTS_GET_CONTACTS);
|
||||
}, 1000);
|
||||
});
|
||||
+248
-161
@@ -1,130 +1,215 @@
|
||||
import { ESX } from "../client/client";
|
||||
import config from '../utils/config';
|
||||
import { Delay } from '../utils/fivem';
|
||||
import events from '../utils/events';
|
||||
import config from "../utils/config";
|
||||
import { Delay } from "../utils/fivem";
|
||||
import events from "../utils/events";
|
||||
|
||||
|
||||
RegisterCommand('phone:close', (source: any, args: string[], raw: any) => {
|
||||
phoneCloseAnim()
|
||||
SetNuiFocus(false, false)
|
||||
RegisterCommand(
|
||||
"phone:close",
|
||||
(source: any, args: string[], raw: any) => {
|
||||
phoneCloseAnim();
|
||||
SetNuiFocus(false, false);
|
||||
SendNuiMessage(
|
||||
JSON.stringify({
|
||||
app: "PHONE",
|
||||
method: "setVisibility",
|
||||
data: false
|
||||
data: false,
|
||||
})
|
||||
)
|
||||
}, false);
|
||||
);
|
||||
},
|
||||
false
|
||||
);
|
||||
|
||||
let prop = 0
|
||||
let isPhoneOpen = false
|
||||
let propCreated = false
|
||||
let phoneModel = "prop_amb_phone" // Refered to in newphoneProp function. Requires custom phone being streamed.
|
||||
let prop = 0;
|
||||
let isPhoneOpen = false;
|
||||
let propCreated = false;
|
||||
let phoneModel = "prop_amb_phone"; // Refered to in newphoneProp function. Requires custom phone being streamed.
|
||||
|
||||
const newPhoneProp = async () => { //Function for creating the phone prop
|
||||
deletePhone() //deletes the already existing prop before creating another.
|
||||
const newPhoneProp = async () => {
|
||||
//Function for creating the phone prop
|
||||
deletePhone(); //deletes the already existing prop before creating another.
|
||||
if (!propCreated) {
|
||||
RequestModel(phoneModel)
|
||||
RequestModel(phoneModel);
|
||||
while (!HasModelLoaded(phoneModel)) {
|
||||
await Delay(1)
|
||||
console.log("MODEL HASNT LOADED")
|
||||
await Delay(1);
|
||||
console.log("MODEL HASNT LOADED");
|
||||
}
|
||||
|
||||
const playerPed = PlayerPedId()
|
||||
const playerPed = PlayerPedId();
|
||||
const [x, y, z] = GetEntityCoords(playerPed, true);
|
||||
prop = CreateObject(GetHashKey(phoneModel), x, y, z + 0.2, true, true, true)
|
||||
prop = CreateObject(
|
||||
GetHashKey(phoneModel),
|
||||
x,
|
||||
y,
|
||||
z + 0.2,
|
||||
true,
|
||||
true,
|
||||
true
|
||||
);
|
||||
//prop = CreateObject(GetHashKey(phoneModel), 1.0, 1.0, 1.0, 1, 1, 0)
|
||||
const boneIndex = GetPedBoneIndex(playerPed, 28422)
|
||||
AttachEntityToEntity(prop, playerPed, boneIndex, 0.0, 0.0, 0.0, 0.0, 0.0, -.0, true, true, false, true, 1.0, true); //-- Attaches the phone to the player.
|
||||
propCreated = true
|
||||
console.log("prop created")
|
||||
}
|
||||
else if (propCreated) {
|
||||
console.log("prop already created")
|
||||
}
|
||||
const boneIndex = GetPedBoneIndex(playerPed, 28422);
|
||||
AttachEntityToEntity(
|
||||
prop,
|
||||
playerPed,
|
||||
boneIndex,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
-0.0,
|
||||
true,
|
||||
true,
|
||||
false,
|
||||
true,
|
||||
1.0,
|
||||
true
|
||||
); //-- Attaches the phone to the player.
|
||||
propCreated = true;
|
||||
console.log("prop created");
|
||||
} else if (propCreated) {
|
||||
console.log("prop already created");
|
||||
}
|
||||
};
|
||||
|
||||
function deletePhone() { //-- Triggered in newphoneProp function. Only way to destory the prop correctly.
|
||||
function deletePhone() {
|
||||
//-- Triggered in newphoneProp function. Only way to destory the prop correctly.
|
||||
if (prop != 0) {
|
||||
//Citizen.invokeNative(0xAE3CBE5BF394C9C9 , Citizen.pointerValueIntInitialized(prop))
|
||||
DeleteEntity(prop);
|
||||
prop = 0
|
||||
propCreated = false
|
||||
console.log("prop destroyed")
|
||||
prop = 0;
|
||||
propCreated = false;
|
||||
console.log("prop destroyed");
|
||||
}
|
||||
}
|
||||
|
||||
async function loadAnimDict(dict: any) { //-- Loads the animation dict. Used in the anim functions.
|
||||
async function loadAnimDict(dict: any) {
|
||||
//-- Loads the animation dict. Used in the anim functions.
|
||||
while (!HasAnimDictLoaded(dict)) {
|
||||
RequestAnimDict(dict)
|
||||
await Delay(100)
|
||||
RequestAnimDict(dict);
|
||||
await Delay(100);
|
||||
}
|
||||
}
|
||||
|
||||
async function phoneOpenAnim() { //Phone Open Animation
|
||||
const flag = 50 //https://runtime.fivem.net/doc/natives/?_0xEA47FE3719165B94
|
||||
deletePhone() //Deleting before creating a new phone where itll be deleted again.
|
||||
if (IsPedInAnyVehicle(GetPlayerPed(-1), true)) { //-- true refers to at get in.
|
||||
const dict = 'anim@cellphone@in_car@ps'
|
||||
const kek = "pepein"
|
||||
async function phoneOpenAnim() {
|
||||
//Phone Open Animation
|
||||
const flag = 50; //https://runtime.fivem.net/doc/natives/?_0xEA47FE3719165B94
|
||||
deletePhone(); //Deleting before creating a new phone where itll be deleted again.
|
||||
if (IsPedInAnyVehicle(GetPlayerPed(-1), true)) {
|
||||
//-- true refers to at get in.
|
||||
const dict = "anim@cellphone@in_car@ps";
|
||||
const kek = "pepein";
|
||||
|
||||
ClearPedTasks(GetPlayerPed(-1))
|
||||
await loadAnimDict(dict)
|
||||
TaskPlayAnim(GetPlayerPed(-1), dict, 'cellphone_text_in', 8.0, -1, -1, flag, 0, false, false, false)
|
||||
await Delay(300) //Gives time for animation starts before creating the phone
|
||||
await newPhoneProp() //Creates the phone and attaches it.
|
||||
}
|
||||
else { //While not in a vehicle it will use this dict.
|
||||
const dict = 'cellphone@'
|
||||
const kek = "pepeout"
|
||||
ClearPedTasks(GetPlayerPed(-1));
|
||||
await loadAnimDict(dict);
|
||||
TaskPlayAnim(
|
||||
GetPlayerPed(-1),
|
||||
dict,
|
||||
"cellphone_text_in",
|
||||
8.0,
|
||||
-1,
|
||||
-1,
|
||||
flag,
|
||||
0,
|
||||
false,
|
||||
false,
|
||||
false
|
||||
);
|
||||
await Delay(300); //Gives time for animation starts before creating the phone
|
||||
await newPhoneProp(); //Creates the phone and attaches it.
|
||||
} else {
|
||||
//While not in a vehicle it will use this dict.
|
||||
const dict = "cellphone@";
|
||||
const kek = "pepeout";
|
||||
|
||||
ClearPedTasks(GetPlayerPed(-1))
|
||||
await loadAnimDict(dict)
|
||||
TaskPlayAnim(GetPlayerPed(-1), dict, 'cellphone_text_in', 8.0, -1, -1, flag, 0, false, false, false)
|
||||
await Delay(300) //Gives time for animation starts before creating the phone
|
||||
await newPhoneProp() //Creates the phone and attaches it.
|
||||
ClearPedTasks(GetPlayerPed(-1));
|
||||
await loadAnimDict(dict);
|
||||
TaskPlayAnim(
|
||||
GetPlayerPed(-1),
|
||||
dict,
|
||||
"cellphone_text_in",
|
||||
8.0,
|
||||
-1,
|
||||
-1,
|
||||
flag,
|
||||
0,
|
||||
false,
|
||||
false,
|
||||
false
|
||||
);
|
||||
await Delay(300); //Gives time for animation starts before creating the phone
|
||||
await newPhoneProp(); //Creates the phone and attaches it.
|
||||
}
|
||||
}
|
||||
|
||||
async function phoneCloseAnim() { //Phone Close Animation
|
||||
const flag = 50 //https://runtime.fivem.net/doc/natives/?_0xEA47FE3719165B94
|
||||
const anim = 'cellphone_text_out'
|
||||
if (IsPedInAnyVehicle(GetPlayerPed(-1), true)) { //true refers to at get in.
|
||||
const dict = 'anim@cellphone@in_car@ps'
|
||||
const kek = "pepein"
|
||||
async function phoneCloseAnim() {
|
||||
//Phone Close Animation
|
||||
const flag = 50; //https://runtime.fivem.net/doc/natives/?_0xEA47FE3719165B94
|
||||
const anim = "cellphone_text_out";
|
||||
if (IsPedInAnyVehicle(GetPlayerPed(-1), true)) {
|
||||
//true refers to at get in.
|
||||
const dict = "anim@cellphone@in_car@ps";
|
||||
const kek = "pepein";
|
||||
|
||||
StopAnimTask(GetPlayerPed(-1), dict, 'cellphone_text_in', 1.0) //Stop the pull out animation
|
||||
deletePhone() //Deletes the prop early incase they get out of the vehicle.
|
||||
await Delay(250) //lets it get to a certain point
|
||||
loadAnimDict(dict) //loads the new animation
|
||||
TaskPlayAnim(GetPlayerPed(-1), dict, anim, 8.0, -1, -1, flag, 1, false, false, false) //puts phone into pocket
|
||||
await Delay(200) //waits until the phone is in the pocket
|
||||
StopAnimTask(GetPlayerPed(-1), dict, anim, 1.0) //clears the animation
|
||||
}
|
||||
else { //While not in a vehicle it will use this dict.
|
||||
const dict = 'cellphone@'
|
||||
const kek = "pepeout"
|
||||
StopAnimTask(GetPlayerPed(-1), dict, "cellphone_text_in", 1.0); //Stop the pull out animation
|
||||
deletePhone(); //Deletes the prop early incase they get out of the vehicle.
|
||||
await Delay(250); //lets it get to a certain point
|
||||
loadAnimDict(dict); //loads the new animation
|
||||
TaskPlayAnim(
|
||||
GetPlayerPed(-1),
|
||||
dict,
|
||||
anim,
|
||||
8.0,
|
||||
-1,
|
||||
-1,
|
||||
flag,
|
||||
1,
|
||||
false,
|
||||
false,
|
||||
false
|
||||
); //puts phone into pocket
|
||||
await Delay(200); //waits until the phone is in the pocket
|
||||
StopAnimTask(GetPlayerPed(-1), dict, anim, 1.0); //clears the animation
|
||||
} else {
|
||||
//While not in a vehicle it will use this dict.
|
||||
const dict = "cellphone@";
|
||||
const kek = "pepeout";
|
||||
|
||||
StopAnimTask(GetPlayerPed(-1), dict, 'cellphone_text_in', 1.0) //Stop the pull out animation
|
||||
await Delay(100) //lets it get to a certain point
|
||||
loadAnimDict(dict) //loads the new animation
|
||||
TaskPlayAnim(GetPlayerPed(-1), dict, anim, 8.0, -1, -1, flag, 1, false, false, false) //puts phone into pocket
|
||||
await Delay(200) //waits until the phone is in the pocket
|
||||
StopAnimTask(GetPlayerPed(-1), dict, anim, 1.0) //clears the animation
|
||||
deletePhone() //Deletes the prop.
|
||||
StopAnimTask(GetPlayerPed(-1), dict, "cellphone_text_in", 1.0); //Stop the pull out animation
|
||||
await Delay(100); //lets it get to a certain point
|
||||
loadAnimDict(dict); //loads the new animation
|
||||
TaskPlayAnim(
|
||||
GetPlayerPed(-1),
|
||||
dict,
|
||||
anim,
|
||||
8.0,
|
||||
-1,
|
||||
-1,
|
||||
flag,
|
||||
1,
|
||||
false,
|
||||
false,
|
||||
false
|
||||
); //puts phone into pocket
|
||||
await Delay(200); //waits until the phone is in the pocket
|
||||
StopAnimTask(GetPlayerPed(-1), dict, anim, 1.0); //clears the animation
|
||||
deletePhone(); //Deletes the prop.
|
||||
}
|
||||
}
|
||||
|
||||
async function carryingPhone(cb: any) {
|
||||
if (ESX === null) return cb(0);
|
||||
ESX.TriggerServerCallback('phone:getItemAmount', (qtty: number) => {
|
||||
ESX.TriggerServerCallback(
|
||||
"phone:getItemAmount",
|
||||
(qtty: number) => {
|
||||
cb(qtty > 0);
|
||||
}, 'phone');
|
||||
},
|
||||
"phone"
|
||||
);
|
||||
}
|
||||
|
||||
function noPhone() {
|
||||
if (ESX === null) return;
|
||||
ESX.ShowNotification('Oi Mate, No El Telephono')
|
||||
ESX.ShowNotification("Oi Mate, No El Telephono");
|
||||
}
|
||||
|
||||
function sendPhoneConfig() {
|
||||
@@ -132,160 +217,162 @@ function sendPhoneConfig() {
|
||||
JSON.stringify({
|
||||
app: "PHONE",
|
||||
method: "phoneConfig",
|
||||
data: config
|
||||
data: config,
|
||||
})
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
setTick(() => {
|
||||
if (IsControlJustPressed(1, config.KeyTogglePhone)) {
|
||||
Phone();
|
||||
}
|
||||
})
|
||||
|
||||
});
|
||||
|
||||
async function Phone() {
|
||||
if (config.PhoneAsItem) {
|
||||
carryingPhone(async (carryingPhone: any) => {
|
||||
if (carryingPhone) {
|
||||
if (!isPhoneOpen) {
|
||||
isPhoneOpen = true
|
||||
await phoneOpenAnim()
|
||||
console.log("phone is now open") //Left for testing purposes.
|
||||
isPhoneOpen = true;
|
||||
await phoneOpenAnim();
|
||||
console.log("phone is now open"); //Left for testing purposes.
|
||||
emitNet(events.CONTACTS_GET_CONTACTS);
|
||||
emitNet('phone:getCredentials') // Gets the credentials. Will eventually most likely only get the phone number and name, idk.
|
||||
SetCursorLocation(0.936, 0.922) //Experimental
|
||||
let res = GetActiveScreenResolution()
|
||||
emitNet("phone:getCredentials"); // Gets the credentials. Will eventually most likely only get the phone number and name, idk.
|
||||
SetCursorLocation(0.936, 0.922); //Experimental
|
||||
let res = GetActiveScreenResolution();
|
||||
SendNuiMessage(
|
||||
JSON.stringify({
|
||||
app: "PHONE",
|
||||
method: "setVisibility",
|
||||
data: true
|
||||
data: true,
|
||||
})
|
||||
)
|
||||
sendPhoneConfig()
|
||||
SetNuiFocus(true, true)
|
||||
}
|
||||
else {
|
||||
isPhoneOpen = false
|
||||
console.log("phone is now closed") //Left for testing purposes.
|
||||
SendNuiMessage( //Hides phone
|
||||
);
|
||||
sendPhoneConfig();
|
||||
SetNuiFocus(true, true);
|
||||
} else {
|
||||
isPhoneOpen = false;
|
||||
console.log("phone is now closed"); //Left for testing purposes.
|
||||
SendNuiMessage(
|
||||
//Hides phone
|
||||
JSON.stringify({
|
||||
app: "PHONE",
|
||||
method: "setVisibility",
|
||||
data: false
|
||||
data: false,
|
||||
})
|
||||
)
|
||||
SetNuiFocus(false, false)
|
||||
phoneCloseAnim()
|
||||
);
|
||||
SetNuiFocus(false, false);
|
||||
phoneCloseAnim();
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
noPhone();
|
||||
}
|
||||
})
|
||||
}
|
||||
else if (!config.PhoneAsItem) {
|
||||
});
|
||||
} else if (!config.PhoneAsItem) {
|
||||
if (!isPhoneOpen) {
|
||||
isPhoneOpen = true
|
||||
await phoneOpenAnim()
|
||||
console.log("phone is now open") //Left for testing purposes.
|
||||
isPhoneOpen = true;
|
||||
await phoneOpenAnim();
|
||||
console.log("phone is now open"); //Left for testing purposes.
|
||||
emitNet(events.CONTACTS_GET_CONTACTS);
|
||||
emitNet('phone:getCredentials')
|
||||
SetCursorLocation(0.936, 0.922) //Experimental
|
||||
let res = GetActiveScreenResolution()
|
||||
emitNet("phone:getCredentials");
|
||||
SetCursorLocation(0.936, 0.922); //Experimental
|
||||
let res = GetActiveScreenResolution();
|
||||
SendNuiMessage(
|
||||
JSON.stringify({
|
||||
app: "PHONE",
|
||||
method: "setVisibility",
|
||||
data: true
|
||||
data: true,
|
||||
})
|
||||
)
|
||||
sendPhoneConfig()
|
||||
SetNuiFocus(true, true)
|
||||
}
|
||||
else {
|
||||
isPhoneOpen = false
|
||||
console.log("phone is now closed") //Left for testing purposes.
|
||||
SendNuiMessage( //Hides phone
|
||||
);
|
||||
sendPhoneConfig();
|
||||
SetNuiFocus(true, true);
|
||||
} else {
|
||||
isPhoneOpen = false;
|
||||
console.log("phone is now closed"); //Left for testing purposes.
|
||||
SendNuiMessage(
|
||||
//Hides phone
|
||||
JSON.stringify({
|
||||
app: "PHONE",
|
||||
method: "setVisibility",
|
||||
data: false
|
||||
data: false,
|
||||
})
|
||||
)
|
||||
SetNuiFocus(false, false)
|
||||
await phoneCloseAnim()
|
||||
);
|
||||
SetNuiFocus(false, false);
|
||||
await phoneCloseAnim();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
RegisterCommand(
|
||||
"phone",
|
||||
() => {
|
||||
//-- Toggles Phone
|
||||
Phone();
|
||||
},
|
||||
false
|
||||
);
|
||||
|
||||
RegisterCommand('phone', () => { //-- Toggles Phone
|
||||
Phone()
|
||||
}, false)
|
||||
|
||||
|
||||
RegisterNuiCallbackType('phone:close');
|
||||
RegisterNuiCallbackType("phone:close");
|
||||
on(`__cfx_nui:phone:close`, () => {
|
||||
Phone();
|
||||
}) // Called for when the phone is closed via the UI.
|
||||
}); // Called for when the phone is closed via the UI.
|
||||
|
||||
|
||||
AddEventHandler('onResourceStop', function(resource: string) {
|
||||
AddEventHandler("onResourceStop", function (resource: string) {
|
||||
if (resource === GetCurrentResourceName()) {
|
||||
SendNuiMessage(
|
||||
JSON.stringify({
|
||||
app: 'PHONE',
|
||||
method: 'setVisibility',
|
||||
data: false
|
||||
app: "PHONE",
|
||||
method: "setVisibility",
|
||||
data: false,
|
||||
})
|
||||
)
|
||||
SetNuiFocus(false, false)
|
||||
deletePhone() //Deletes the phone incase it was attached.
|
||||
ClearPedTasks(GetPlayerPed(-1)) //Leave here until launch as it'll fix any stuck animations.
|
||||
);
|
||||
SetNuiFocus(false, false);
|
||||
deletePhone(); //Deletes the phone incase it was attached.
|
||||
ClearPedTasks(GetPlayerPed(-1)); //Leave here until launch as it'll fix any stuck animations.
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
//
|
||||
//Phone Destory When Wet
|
||||
//
|
||||
function countPhone(cb: any) {
|
||||
if (ESX === null) return cb(0)
|
||||
ESX.TriggerServerCallback('phone:getItemAmount', (qtty: number) => {
|
||||
if (ESX === null) return cb(0);
|
||||
ESX.TriggerServerCallback(
|
||||
"phone:getItemAmount",
|
||||
(qtty: number) => {
|
||||
cb(qtty > 0);
|
||||
}, 'phone');
|
||||
},
|
||||
"phone"
|
||||
);
|
||||
}
|
||||
|
||||
let destroyedPhone = false
|
||||
|
||||
let destroyedPhone = false;
|
||||
|
||||
setTick(async () => {
|
||||
while (config.SwimDestroy) {
|
||||
await Delay(config.RunRate * 1000);
|
||||
if (IsPedSwimming(PlayerPedId())) {
|
||||
let chance = Math.floor((Math.random() * 100) + 1);
|
||||
let chance = Math.floor(Math.random() * 100 + 1);
|
||||
if (chance <= config.DestoryChance) {
|
||||
countPhone((countPhone: boolean) => {
|
||||
if (countPhone) {
|
||||
ESX.ShowNotification('Your phone is ruined from the water!')
|
||||
destroyedPhone = true
|
||||
ESX.ShowNotification("Your phone is ruined from the water!");
|
||||
destroyedPhone = true;
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
if (destroyedPhone) {
|
||||
await Delay(config.DestroyPhoneReCheck * 60000)
|
||||
await Delay(config.DestroyPhoneReCheck * 60000);
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
onNet('phone:sendCredentials', (number: string) => {
|
||||
onNet("phone:sendCredentials", (number: string) => {
|
||||
SendNuiMessage(
|
||||
JSON.stringify({
|
||||
app: "SIMCARD",
|
||||
method: "setNumber",
|
||||
data: number
|
||||
data: number,
|
||||
})
|
||||
)
|
||||
);
|
||||
});
|
||||
@@ -1,5 +1,5 @@
|
||||
import events from '../utils/events';
|
||||
import { sendTwitterMessage } from '../utils/messages';
|
||||
import events from "../utils/events";
|
||||
import { sendTwitterMessage } from "../utils/messages";
|
||||
|
||||
/**
|
||||
* Twitter get or create profile
|
||||
@@ -17,7 +17,6 @@ onNet(events.TWITTER_GET_OR_CREATE_PROFILE_FAILURE, () => {
|
||||
sendTwitterMessage(events.TWITTER_GET_OR_CREATE_PROFILE_FAILURE);
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
* Twitter update profile
|
||||
*/
|
||||
@@ -32,7 +31,6 @@ onNet(events.TWITTER_UPDATE_PROFILE_RESULT, (result: boolean) => {
|
||||
emitNet(events.TWITTER_GET_OR_CREATE_PROFILE);
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
* Twitter fetch tweets
|
||||
*/
|
||||
@@ -53,9 +51,12 @@ onNet(events.TWITTER_FETCH_TWEETS_FAILURE, () => {
|
||||
* Twitter fetch filtered tweets
|
||||
*/
|
||||
RegisterNuiCallbackType(events.TWITTER_FETCH_TWEETS_FILTERED);
|
||||
on(`__cfx_nui:${events.TWITTER_FETCH_TWEETS_FILTERED}`, (searchValue: string) => {
|
||||
on(
|
||||
`__cfx_nui:${events.TWITTER_FETCH_TWEETS_FILTERED}`,
|
||||
(searchValue: string) => {
|
||||
emitNet(events.TWITTER_FETCH_TWEETS_FILTERED, searchValue);
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
onNet(events.TWITTER_FETCH_TWEETS_FILTERED_SUCCESS, (tweets: any) => {
|
||||
sendTwitterMessage(events.TWITTER_FETCH_TWEETS_FILTERED_SUCCESS, tweets);
|
||||
@@ -65,7 +66,6 @@ onNet(events.TWITTER_FETCH_TWEETS_FILTERED_FAILURE, () => {
|
||||
sendTwitterMessage(events.TWITTER_FETCH_TWEETS_FILTERED_FAILURE);
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
* Twitter create tweet
|
||||
*/
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import { ESXClient } from "fivem-esx-js/client/esx_client";
|
||||
import './cl_main';
|
||||
import './cl_twitter';
|
||||
import './cl_contacts';
|
||||
import "./cl_main";
|
||||
import "./cl_twitter";
|
||||
import "./cl_contacts";
|
||||
|
||||
export let ESX: ESXClient = null;
|
||||
|
||||
setTick(() => {
|
||||
while (ESX === null) {
|
||||
emit('esx:getSharedObject', (obj: ESXClient) => ESX = obj);
|
||||
emit("esx:getSharedObject", (obj: ESXClient) => (ESX = obj));
|
||||
}
|
||||
});
|
||||
@@ -10,7 +10,7 @@
|
||||
"target": "es6",
|
||||
"allowJs": true,
|
||||
"lib": ["es2017"],
|
||||
"types": ["@citizenfx/client", "@types/node"],
|
||||
"types": ["@citizenfx/client", "@types/node", "jest"],
|
||||
"moduleResolution": "node",
|
||||
"resolveJsonModule": true,
|
||||
"esModuleInterop": true
|
||||
|
||||
+15
-3
@@ -7,31 +7,43 @@
|
||||
"author": "",
|
||||
"scripts": {
|
||||
"build": "webpack --mode production",
|
||||
"format": "prettier --write \"src/**/*.ts\"",
|
||||
"watch": "webpack --mode development --watch true"
|
||||
"format": "prettier --write \"./**/*.ts\"",
|
||||
"watch": "webpack --mode development --watch true",
|
||||
"test": "jest"
|
||||
},
|
||||
"license": "MIT",
|
||||
"private": false,
|
||||
"dependencies": {
|
||||
"@citizenfx/client": "^1.0.2792-1",
|
||||
"@citizenfx/server": "^1.0.2792-1",
|
||||
"@types/node": "^14.0.27",
|
||||
"@types/node": "^14.11.10",
|
||||
"connection-string-parser": "^1.0.3",
|
||||
"fivem-esx-js": "^0.1.12",
|
||||
"fivem-js": "^1.3.1",
|
||||
"mysql2": "^2.2.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/preset-env": "^7.12.1",
|
||||
"@babel/preset-typescript": "^7.12.1",
|
||||
"@types/jest": "^26.0.14",
|
||||
"@typescript-eslint/eslint-plugin": "^3.8.0",
|
||||
"@typescript-eslint/parser": "^4.4.0",
|
||||
"eslint": "^7.6.0",
|
||||
"eslint-config-prettier": "^6.11.0",
|
||||
"eslint-loader": "^4.0.2",
|
||||
"husky": "^4.3.0",
|
||||
"jest": "^26.5.3",
|
||||
"prettier": "^2.0.5",
|
||||
"remove-files-webpack-plugin": "^1.4.3",
|
||||
"ts-jest": "^26.4.1",
|
||||
"ts-loader": "^8.0.2",
|
||||
"typescript": "^3.9.7",
|
||||
"webpack": "^4.44.1",
|
||||
"webpack-cli": "^3.3.12"
|
||||
},
|
||||
"husky": {
|
||||
"hooks": {
|
||||
"pre-commit": "npm run format && npm run test"
|
||||
}
|
||||
}
|
||||
}
|
||||
+52
-8
@@ -1,22 +1,66 @@
|
||||
import mysql from 'mysql2/promise';
|
||||
import mysql from "mysql2/promise";
|
||||
import { ConnectionStringParser } from "connection-string-parser";
|
||||
import {
|
||||
CONNECTION_STRING,
|
||||
DEFAULT_PORT,
|
||||
parseSemiColonFormat,
|
||||
getServerHost,
|
||||
getUserId,
|
||||
getPassword,
|
||||
} from './db_utils';
|
||||
|
||||
const CONNECTION_STRING = 'mysql_connection_string';
|
||||
// we require set mysql_connection_string "mysql://root:password@localhost/es_extended?charset=utf8mb4" to be set in the config
|
||||
// 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.`)
|
||||
throw new Error(
|
||||
`No connection string provided. make sure "${CONNECTION_STRING} is set in your config.`
|
||||
);
|
||||
}
|
||||
|
||||
const connectionStringParser = new ConnectionStringParser({ scheme: 'mysql', hosts: []});
|
||||
const connectionOjbect = connectionStringParser .parse(mysqlConnectionString);
|
||||
/**
|
||||
* Most fivem servers utilize fivem-mysql-async (https://brouznouf.github.io/fivem-mysql-async/) and
|
||||
* define a environment variable "mysql_connection_string" in their configurations. We will try to
|
||||
* maintain backwards compatibility with this.
|
||||
*
|
||||
* fivem-mysql-async allows for two different connection string formats defined here:
|
||||
* 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
|
||||
);
|
||||
|
||||
export const pool = mysql.createPool({
|
||||
return mysql.createPool({
|
||||
host: connectionOjbect.hosts[0].host,
|
||||
user: connectionOjbect.username,
|
||||
password: connectionOjbect.password,
|
||||
database: connectionOjbect.endpoint,
|
||||
waitForConnections: true,
|
||||
connectionLimit: 10,
|
||||
queueLimit: 0
|
||||
queueLimit: 0,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export const pool = generateConnectionPool();
|
||||
@@ -0,0 +1,96 @@
|
||||
import * as db from "./db_utils";
|
||||
|
||||
const t = 'test value';
|
||||
|
||||
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;password=pass';
|
||||
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.password).toEqual('pass');
|
||||
});
|
||||
});
|
||||
|
||||
describe("getServerHost", () => {
|
||||
it("returns default", () => {
|
||||
expect(db.getServerHost({})).toEqual(db.DEFAULT_HOST);
|
||||
});
|
||||
|
||||
it("Correctly returns host", () => {
|
||||
expect(db.getServerHost({ host: t })).toEqual(t);
|
||||
});
|
||||
|
||||
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 datasource", () => {
|
||||
expect(db.getServerHost({ datasource: t })).toEqual(t);
|
||||
});
|
||||
|
||||
it("Correctly returns addr", () => {
|
||||
expect(db.getServerHost({ addr: t })).toEqual(t);
|
||||
});
|
||||
|
||||
it("Correctly returns address", () => {
|
||||
expect(db.getServerHost({ address: t })).toEqual(t);
|
||||
});
|
||||
});
|
||||
|
||||
describe("getUserId", () => {
|
||||
it("returns default", () => {
|
||||
expect(db.getUserId({})).toEqual(db.DEFAULT_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 userid", () => {
|
||||
expect(db.getUserId({ userid: t })).toEqual(t);
|
||||
});
|
||||
|
||||
it("Correctly returns user name", () => {
|
||||
expect(db.getUserId({ 'user name': t })).toEqual(t);
|
||||
});
|
||||
|
||||
it("Correctly returns username", () => {
|
||||
expect(db.getUserId({ username: t })).toEqual(t);
|
||||
});
|
||||
|
||||
it("Correctly returns uid", () => {
|
||||
expect(db.getUserId({ uid: t })).toEqual(t);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe("getPassword", () => {
|
||||
it("returns default", () => {
|
||||
expect(() => db.getPassword({})).toThrowError();
|
||||
});
|
||||
|
||||
it("Correctly returns password", () => {
|
||||
expect(db.getPassword({ password: t })).toEqual(t);
|
||||
});
|
||||
|
||||
it("Correctly returns pwd", () => {
|
||||
expect(db.getPassword({ pwd: t })).toEqual(t);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,73 @@
|
||||
export const CONNECTION_STRING = "mysql_connection_string";
|
||||
export const DEFAULT_PORT = 3306;
|
||||
export const DEFAULT_HOST = "localhost";
|
||||
export const DEFAULT_USER = "root";
|
||||
|
||||
|
||||
interface Map {
|
||||
[key: string]: string;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* parse the connection string from the format server=127.0.0.1;database=es_extended;userid=user;password=pass
|
||||
* @param connectionString - mysql_connection_string value
|
||||
*/
|
||||
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.`
|
||||
);
|
||||
}
|
||||
|
||||
return parts.reduce((connectionInfo: Map, part) => {
|
||||
const [key, value] = part.split("=");
|
||||
connectionInfo[key] = value;
|
||||
return connectionInfo;
|
||||
}, {});
|
||||
}
|
||||
|
||||
/**
|
||||
* allowed variable names: host | server | data source | datasource | addr | address
|
||||
* @param config - database config variables parsed from mysql_connection_string
|
||||
*/
|
||||
export function getServerHost(config: Map): string {
|
||||
return (
|
||||
config.host ||
|
||||
config.server ||
|
||||
config["data source"] ||
|
||||
config.datasource ||
|
||||
config.addr ||
|
||||
config.address ||
|
||||
DEFAULT_HOST
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* allowed variable names: user | user id | userid | user name | username | uid
|
||||
* @param config - database config variables parsed from mysql_connection_string
|
||||
*/
|
||||
export function getUserId(config: Map): string {
|
||||
return (
|
||||
config.user ||
|
||||
config["user id"] ||
|
||||
config.userid ||
|
||||
config["user name"] ||
|
||||
config.username ||
|
||||
config.uid ||
|
||||
DEFAULT_USER
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* allowed variable names: password | pwd
|
||||
* @param config - database config variables parsed from mysql_connection_string
|
||||
*/
|
||||
export function getPassword(config: Map): string {
|
||||
const password = config.password || config.pwd;
|
||||
if (!password) {
|
||||
throw new Error("Password is a required field");
|
||||
}
|
||||
return password;
|
||||
}
|
||||
@@ -1,12 +1,12 @@
|
||||
import { ESXServer } from "fivem-esx-js/server/esx_server";
|
||||
|
||||
import './db';
|
||||
import './sv_twitter';
|
||||
import './sv_main';
|
||||
import './sv_contacts';
|
||||
import "./db";
|
||||
import "./sv_twitter";
|
||||
import "./sv_main";
|
||||
import "./sv_contacts";
|
||||
|
||||
export let ESX: ESXServer = null;
|
||||
|
||||
emit('esx:getSharedObject', (obj: ESXServer) => ESX = obj);
|
||||
emit("esx:getSharedObject", (obj: ESXServer) => (ESX = obj));
|
||||
|
||||
export const getSource = () => parseInt(source);
|
||||
@@ -1,6 +1,6 @@
|
||||
import { ESX } from './server';
|
||||
import { pool } from './db';
|
||||
import events from '../utils/events';
|
||||
import { ESX } from "./server";
|
||||
import { pool } from "./db";
|
||||
import events from "../utils/events";
|
||||
|
||||
interface Contacts {
|
||||
display: string;
|
||||
@@ -14,8 +14,14 @@ async function fetchAllContacts(identifier: string) : Promise<Contacts[]> {
|
||||
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 (?, ?, ?, ?)";
|
||||
|
||||
await pool.query(query, [identifier, number, display, avatar]);
|
||||
}
|
||||
@@ -27,22 +33,23 @@ onNet(events.CONTACTS_GET_CONTACTS, async () => {
|
||||
const _identifier = xPlayer.getIdentifier();
|
||||
|
||||
const contacts = await fetchAllContacts(_identifier);
|
||||
emitNet(events.CONTACTS_SEND_CONTACTS, _source, contacts)
|
||||
|
||||
emitNet(events.CONTACTS_SEND_CONTACTS, _source, contacts);
|
||||
} catch (error) {
|
||||
console.log("Failed to fetch contacts: ", error);
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
onNet(events.CONTACTS_ADD_CONTACT, (number: string, display: string, avatar: string) => {
|
||||
onNet(
|
||||
events.CONTACTS_ADD_CONTACT,
|
||||
(number: string, display: string, avatar: string) => {
|
||||
try {
|
||||
const _source = (global as any).source;
|
||||
const xPlayer = ESX.GetPlayerFromId(_source);
|
||||
const _identifier = xPlayer.getIdentifier()
|
||||
const _identifier = xPlayer.getIdentifier();
|
||||
addContact(_identifier, number, display, avatar);
|
||||
emit(events.CONTACTS_GET_CONTACTS);
|
||||
|
||||
} catch (error) {
|
||||
console.log("Failed to add contact: ", error);
|
||||
}
|
||||
});
|
||||
}
|
||||
);
|
||||
@@ -1,5 +1,5 @@
|
||||
import { ESX } from './server';
|
||||
import { pool } from './db';
|
||||
import { ESX } from "./server";
|
||||
import { pool } from "./db";
|
||||
|
||||
//db = DatabaseConfig //helper variable for use in server function
|
||||
|
||||
@@ -21,14 +21,14 @@ async function getCredentials(identifier: string) : Promise<string> {
|
||||
return number[0].phone_number;
|
||||
}
|
||||
|
||||
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,7 +1,7 @@
|
||||
import { pool } from './db';
|
||||
import { ESX, getSource } from './server';
|
||||
import events from '../utils/events';
|
||||
import config from '../utils/config';
|
||||
import { pool } from "./db";
|
||||
import { ESX, getSource } from "./server";
|
||||
import events from "../utils/events";
|
||||
import config from "../utils/config";
|
||||
|
||||
interface Profile {
|
||||
id: number;
|
||||
@@ -60,7 +60,10 @@ 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
|
||||
@@ -76,7 +79,11 @@ async function fetchTweetsFiltered(profileId: number, searchValue: string): Prom
|
||||
ORDER BY npwd_twitter_tweets.createdAt DESC
|
||||
LIMIT 100
|
||||
`;
|
||||
const [ results ] = await pool.query(query, [profileId, parameterizedSearchValue, parameterizedSearchValue]);
|
||||
const [results] = await pool.query(query, [
|
||||
profileId,
|
||||
parameterizedSearchValue,
|
||||
parameterizedSearchValue,
|
||||
]);
|
||||
const tweets = <Tweet[]>results;
|
||||
return tweets;
|
||||
}
|
||||
@@ -90,8 +97,8 @@ async function createTweet(identifier: string, tweet: Tweet): Promise<any> {
|
||||
const query = `
|
||||
INSERT INTO npwd_twitter_tweets (identifier, message, images)
|
||||
VALUES (?, ?, ?)
|
||||
`
|
||||
await pool.query(query, [identifier, tweet.message, tweet.images])
|
||||
`;
|
||||
await pool.query(query, [identifier, tweet.message, tweet.images]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -114,14 +121,14 @@ 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 = `
|
||||
SELECT CONCAT(firstname, '_', lastname) AS profile_name
|
||||
FROM users
|
||||
WHERE identifier = ? LIMIT 1
|
||||
`
|
||||
`;
|
||||
const [results] = await pool.query(query, [identifier]);
|
||||
const profileNames = <ProfileName[]>results;
|
||||
|
||||
@@ -139,7 +146,7 @@ async function createDefaultProfile(identifier: string): Promise<Profile> {
|
||||
const query = `
|
||||
INSERT INTO npwd_twitter_profiles (identifier, profile_name)
|
||||
VALUES (?, ?)
|
||||
`
|
||||
`;
|
||||
const [result] = await pool.execute(query, [identifier, profileName]);
|
||||
return getProfile(identifier);
|
||||
}
|
||||
@@ -151,7 +158,7 @@ async function createDefaultProfile(identifier: string): Promise<Profile> {
|
||||
*/
|
||||
async function getOrCreateProfile(identifier: string): Promise<Profile> {
|
||||
const profile = await getProfile(identifier);
|
||||
return profile || await createDefaultProfile(identifier);
|
||||
return profile || (await createDefaultProfile(identifier));
|
||||
}
|
||||
|
||||
async function updateProfile(identifier: string, profile: Profile) {
|
||||
@@ -160,14 +167,14 @@ async function updateProfile(identifier: string, profile: Profile) {
|
||||
UPDATE npwd_twitter_profiles
|
||||
SET avatar_url = ?, profile_name = ?, bio = ?, location = ?, job = ?
|
||||
WHERE identifier = ?
|
||||
`
|
||||
`;
|
||||
await pool.execute(query, [
|
||||
avatar_url,
|
||||
profile_name,
|
||||
bio,
|
||||
location,
|
||||
job,
|
||||
identifier
|
||||
identifier,
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -180,7 +187,7 @@ async function createLike(profileId: number, tweetId: number): Promise<void> {
|
||||
const query = `
|
||||
INSERT INTO npwd_twitter_likes (profile_id, tweet_id)
|
||||
VALUES (?, ?)
|
||||
`
|
||||
`;
|
||||
await pool.execute(query, [profileId, tweetId]);
|
||||
}
|
||||
|
||||
@@ -193,7 +200,7 @@ async function deleteLike(profileId: number, tweetId: number): Promise<void> {
|
||||
const query = `
|
||||
DELETE FROM npwd_twitter_likes
|
||||
WHERE profile_id = ? AND tweet_id = ?
|
||||
`
|
||||
`;
|
||||
await pool.execute(query, [profileId, tweetId]);
|
||||
}
|
||||
|
||||
@@ -202,22 +209,24 @@ async function deleteLike(profileId: number, tweetId: number): Promise<void> {
|
||||
* @param profileId - primary key of the profile to check
|
||||
* @param tweetId - primary key of the tweet to check
|
||||
*/
|
||||
async function doesLikeExist(profileId: number, tweetId: number): Promise<boolean> {
|
||||
async function doesLikeExist(
|
||||
profileId: number,
|
||||
tweetId: number
|
||||
): Promise<boolean> {
|
||||
const query = `
|
||||
SELECT * FROM npwd_twitter_likes
|
||||
WHERE profile_id = ? AND tweet_id = ?
|
||||
LIMIT 1
|
||||
`
|
||||
`;
|
||||
const [results] = await pool.query(query, [profileId, tweetId]);
|
||||
const likes = <any[]>results;
|
||||
return likes.length > 0;
|
||||
}
|
||||
|
||||
|
||||
onNet(events.TWITTER_GET_OR_CREATE_PROFILE, async () => {
|
||||
try {
|
||||
const identifier = ESX.GetPlayerFromId(getSource()).getIdentifier();
|
||||
const profile = await getOrCreateProfile(identifier)
|
||||
const profile = await getOrCreateProfile(identifier);
|
||||
emitNet(events.TWITTER_GET_OR_CREATE_PROFILE_SUCCESS, getSource(), profile);
|
||||
} catch (e) {
|
||||
emitNet(events.TWITTER_GET_OR_CREATE_PROFILE_FAILURE, getSource());
|
||||
@@ -227,7 +236,7 @@ onNet(events.TWITTER_GET_OR_CREATE_PROFILE, async () => {
|
||||
onNet(events.TWITTER_UPDATE_PROFILE, async (profile: Profile) => {
|
||||
try {
|
||||
const identifier = ESX.GetPlayerFromId(getSource()).getIdentifier();
|
||||
await updateProfile(identifier, profile)
|
||||
await updateProfile(identifier, profile);
|
||||
emitNet(events.TWITTER_UPDATE_PROFILE_RESULT, getSource(), true);
|
||||
} catch (e) {
|
||||
emitNet(events.TWITTER_UPDATE_PROFILE_RESULT, getSource(), false);
|
||||
@@ -266,11 +275,10 @@ onNet(events.TWITTER_CREATE_TWEET, async (tweet: Tweet) => {
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
onNet(events.TWITTER_TOGGLE_LIKE, async (tweetId: number) => {
|
||||
try {
|
||||
const identifier = ESX.GetPlayerFromId(getSource()).getIdentifier();
|
||||
const profile = await getOrCreateProfile(identifier)
|
||||
const profile = await getOrCreateProfile(identifier);
|
||||
const likeExists = await doesLikeExist(profile.id, tweetId);
|
||||
if (likeExists) {
|
||||
await deleteLike(profile.id, tweetId);
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
"target": "es6",
|
||||
"allowJs": false,
|
||||
"lib": ["es2017"],
|
||||
"types": ["@citizenfx/server", "@types/node"],
|
||||
"types": ["@citizenfx/server", "@types/node", "jest"],
|
||||
"moduleResolution": "node",
|
||||
"emitDecoratorMetadata": true,
|
||||
"experimentalDecorators": true,
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
export default {
|
||||
TWITTER: 'TWITTER',
|
||||
}
|
||||
TWITTER: "TWITTER",
|
||||
};
|
||||
@@ -1,5 +1,5 @@
|
||||
export default {
|
||||
Locale: 'en',
|
||||
Locale: "en",
|
||||
KeyTogglePhone: 288,
|
||||
KeyTakeCall: 38,
|
||||
PhoneAsItem: false,
|
||||
@@ -19,5 +19,5 @@ export default {
|
||||
enableEmojis: true,
|
||||
enableImages: true,
|
||||
maxImages: 3,
|
||||
}
|
||||
},
|
||||
};
|
||||
+25
-25
@@ -1,29 +1,29 @@
|
||||
export default {
|
||||
// Twitter
|
||||
TWITTER_FETCH_TWEETS: 'phone:fetchTweets',
|
||||
TWITTER_FETCH_TWEETS_SUCCESS: 'fetchTweets',
|
||||
TWITTER_FETCH_TWEETS_FAILURE: 'fetchTweetsFailed',
|
||||
TWITTER_FETCH_TWEETS_FILTERED: 'phone:fetchTweetsFiltered',
|
||||
TWITTER_FETCH_TWEETS_FILTERED_SUCCESS: 'fetchTweetsFiltered',
|
||||
TWITTER_FETCH_TWEETS_FILTERED_FAILURE: 'fetchTweetsFilteredFailed',
|
||||
TWITTER_GET_OR_CREATE_PROFILE: 'phone:getOrCreateTwitterProfile',
|
||||
TWITTER_GET_OR_CREATE_PROFILE_SUCCESS: 'getOrCreateTwitterProfile',
|
||||
TWITTER_GET_OR_CREATE_PROFILE_FAILURE: 'getOrCreateTwitterProfileFailed',
|
||||
TWITTER_UPDATE_PROFILE: 'phone:updateTwitterProfile',
|
||||
TWITTER_UPDATE_PROFILE_LOADING: 'updateProfileLoading',
|
||||
TWITTER_UPDATE_PROFILE_RESULT: 'updateProfileResult',
|
||||
TWITTER_CREATE_TWEET: 'phone:createTweet',
|
||||
TWITTER_CREATE_TWEET_LOADING: 'createTweetLoading',
|
||||
TWITTER_CREATE_TWEET_RESULT: 'createTweetResult',
|
||||
TWITTER_CREATE_TWEET_FAILURE: 'createTweetResultFailed',
|
||||
TWITTER_TOGGLE_LIKE: 'phone:toggleLike',
|
||||
TWITTER_TOGGLE_LIKE_SUCCESS: 'toggleLikeSuccess',
|
||||
TWITTER_TOGGLE_LIKE_FAILURE: 'toggleLikeFailed',
|
||||
TWITTER_FETCH_TWEETS: "phone:fetchTweets",
|
||||
TWITTER_FETCH_TWEETS_SUCCESS: "fetchTweets",
|
||||
TWITTER_FETCH_TWEETS_FAILURE: "fetchTweetsFailed",
|
||||
TWITTER_FETCH_TWEETS_FILTERED: "phone:fetchTweetsFiltered",
|
||||
TWITTER_FETCH_TWEETS_FILTERED_SUCCESS: "fetchTweetsFiltered",
|
||||
TWITTER_FETCH_TWEETS_FILTERED_FAILURE: "fetchTweetsFilteredFailed",
|
||||
TWITTER_GET_OR_CREATE_PROFILE: "phone:getOrCreateTwitterProfile",
|
||||
TWITTER_GET_OR_CREATE_PROFILE_SUCCESS: "getOrCreateTwitterProfile",
|
||||
TWITTER_GET_OR_CREATE_PROFILE_FAILURE: "getOrCreateTwitterProfileFailed",
|
||||
TWITTER_UPDATE_PROFILE: "phone:updateTwitterProfile",
|
||||
TWITTER_UPDATE_PROFILE_LOADING: "updateProfileLoading",
|
||||
TWITTER_UPDATE_PROFILE_RESULT: "updateProfileResult",
|
||||
TWITTER_CREATE_TWEET: "phone:createTweet",
|
||||
TWITTER_CREATE_TWEET_LOADING: "createTweetLoading",
|
||||
TWITTER_CREATE_TWEET_RESULT: "createTweetResult",
|
||||
TWITTER_CREATE_TWEET_FAILURE: "createTweetResultFailed",
|
||||
TWITTER_TOGGLE_LIKE: "phone:toggleLike",
|
||||
TWITTER_TOGGLE_LIKE_SUCCESS: "toggleLikeSuccess",
|
||||
TWITTER_TOGGLE_LIKE_FAILURE: "toggleLikeFailed",
|
||||
|
||||
// Contacts
|
||||
CONTACTS_SEND_CONTACTS: 'phone:sendContacts',
|
||||
CONTACTS_GET_CONTACTS: 'phone:getContacts',
|
||||
CONTACTS_ADD_CONTACT_NUI: 'contacts:add',
|
||||
CONTACTS_ADD_CONTACT: 'contacts:add',
|
||||
CONTACTS_UPDATE_CONTACTS: 'phone:updateContacts'
|
||||
}
|
||||
CONTACTS_SEND_CONTACTS: "phone:sendContacts",
|
||||
CONTACTS_GET_CONTACTS: "phone:getContacts",
|
||||
CONTACTS_ADD_CONTACT_NUI: "contacts:add",
|
||||
CONTACTS_ADD_CONTACT: "contacts:add",
|
||||
CONTACTS_UPDATE_CONTACTS: "phone:updateContacts",
|
||||
};
|
||||
@@ -1,2 +1,2 @@
|
||||
// https://forum.cfx.re/t/typescript-vs-lua-questions/612483/11
|
||||
export const Delay = (ms: number) => new Promise(res => setTimeout(res, ms));
|
||||
export const Delay = (ms: number) => new Promise((res) => setTimeout(res, ms));
|
||||
@@ -1,11 +1,13 @@
|
||||
import apps from './apps';
|
||||
import apps from "./apps";
|
||||
|
||||
function sendMessage(app: string, method: string, data: any) {
|
||||
return SendNuiMessage(JSON.stringify({
|
||||
return SendNuiMessage(
|
||||
JSON.stringify({
|
||||
app,
|
||||
method,
|
||||
data,
|
||||
}))
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
export function sendTwitterMessage(method: string, data: any = {}) {
|
||||
|
||||
+3341
-44
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user