This commit is contained in:
Taso committed 2021-04-18 15:38:50 -04:00
1 parent 949ea4ba4b
commit e01fa0ab0a
16 files changed
+406 -231

No files matched your search

@@ -0,0 +1,28 @@
import PlayerService from '../players/player.service';
import { clean } from './miscUtils';
/**
* Generate a profile name by the player's name and/or phone number
* @param identifier - player's identifier
* @param delimiter - What we split the profile name by, defaults to -
*/
export async function generateProfileName(
identifier: string,
delimiter: string = '_',
): Promise<string | null> {
const player = PlayerService.getPlayerFromIdentifier(identifier);
const firstname = clean(player.getFirstName());
const lastname = clean(player.getLastName());
const phone_number = clean(player.getPhoneNumber());
if (firstname && lastname) {
return `${firstname}${delimiter}${lastname}`;
} else if (firstname) {
return firstname;
} else if (lastname) {
return lastname;
} else if (phone_number) {
return phone_number;
}
return null;
}
@@ -0,0 +1,15 @@
export const getPlayerGameLicense = (src: number): null | string => {
// Parse specifically for license identifier as its
// guaranteed
const playerIdentifiers = getPlayerIdentifiers(src.toString());
let playerIdentifier;
for (const identifier of playerIdentifiers) {
if (identifier.includes('license:')) {
playerIdentifier = identifier.split(':')[1];
}
}
if (!playerIdentifier) return null;
return playerIdentifier;
};
@@ -0,0 +1,13 @@
import { config } from '../server';
export function getRandomPhoneNumber() {
if (!config.general.useDashNumber) {
return Math.floor(Math.random() * 10000000).toString(); // 10000000 creates a number with 7 characters.
}
return Math.floor(Math.random() * 10000000)
.toString()
.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
}
+5
View File
@@ -0,0 +1,5 @@
// Will apply any type to source
export const getSource = () => (global as any).source;
// Will clean string of any character that isn't 0-9, or a-z
export const clean = (input: string) => (input ? input.replace(/[^0-9a-z]/gi, '') : input);