Skip to content

Commit

Permalink
Fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
jaimeadf committed Oct 18, 2020
1 parent 2942515 commit aee8efc
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 27 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "discord-screenshot",
"version": "1.1.2",
"version": "1.1.3",
"description": "A resource for FiveM and RedM that takes a screenshot of a player and uploads it to a discord's webhook.",
"main": "index.js",
"scripts": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,32 @@ import getPlayerIdentifiers from '../../utils/getPlayerIdentifiers';

class StandaloneScreenshotCommandHandler extends ScreenshotCommandHandler {
public async execute(player: number, args: string[], rawCommand: string): Promise<void> {
const target = args[0];
if (target && player === 0 || IsPlayerAceAllowed(player.toString(), 'screenshot.command')) {
let targetPlayer = target;
const players = getPlayers();
if (player === 0 || IsPlayerAceAllowed(player.toString(), 'screenshot.command')) {
const target = args[0];
if (target !== undefined) {
let targetPlayer: string | undefined;
const players = getPlayers();

if (!players.includes(targetPlayer)) {
for (const player of players) {
const identifiers = getPlayerIdentifiers(player)
if (identifiers.includes(target)) {
targetPlayer = player;
break;
if (players.includes(target)) {
targetPlayer = target;
} else {
for (const player of players) {
const identifiers = getPlayerIdentifiers(player);
if (identifiers.includes(target)) {
targetPlayer = player;
break;
}
}
}
}

if (targetPlayer) {
await this._discordScreenshot.requestClientScreenshotDiscordUpload(targetPlayer, {
name: `[${targetPlayer}] ${GetPlayerName(targetPlayer)}`
});

if (targetPlayer !== undefined) {
await this._discordScreenshot.requestClientScreenshotDiscordUpload(targetPlayer, {
name: `[${targetPlayer}] ${GetPlayerName(targetPlayer)}`
});
}
}
}
}

private get
}

export default StandaloneScreenshotCommandHandler;
11 changes: 6 additions & 5 deletions src/server/commands/screenshot/VrpScreenshotCommandHandler.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import ScreenshotCommandHandler from './ScreenshotCommandHandler';
import DiscordScreenshot from '../../DiscordScreenshot';

import VrpProxy from '../../utils/VrpProxy';

class VrpScreenshotCommandHandler extends ScreenshotCommandHandler {
Expand All @@ -11,11 +12,11 @@ class VrpScreenshotCommandHandler extends ScreenshotCommandHandler {
}

public async execute(player: number, args: string[], rawCommand: string): Promise<void> {
const targetUserId = parseInt(args[0]);
if (targetUserId && player === 0 || await this._vrp.call('hasPermission', await this._vrp.call('getUserId', player), 'screenshot.command')) {
if (targetUserId) {
const targetSource = await this._vrp.call('getUserSource', targetUserId) as number;
if (targetSource) {
if (player === 0 || await this._vrp.call('hasPermission', await this._vrp.call('getUserId', player), 'screenshot.command')) {
const targetUserId = parseInt(args[0]);
if (targetUserId !== NaN) {
const targetSource = await this._vrp.call('getUserSource', targetUserId) as number | undefined;
if (targetSource !== undefined) {
await this._discordScreenshot.requestClientScreenshotDiscordUpload(targetSource, {
name: `[${targetUserId}] ${GetPlayerName(targetSource.toString())}`
});
Expand Down
4 changes: 2 additions & 2 deletions src/server/utils/VrpProxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class VrpProxy {

addEventListener(`${this._name}:${this._identifier}:proxy_res`, (requestId: number, response: unknown[]) => {
if (this._callbacks.hasOwnProperty(requestId)) {
if (response.length === 1) {
if (response.length <= 1) {
this._callbacks[requestId](response[0]);
} else {
this._callbacks[requestId](response);
Expand All @@ -50,7 +50,7 @@ class VrpProxy {
}

public async call(handlerName: string, ...args: any[]): Promise<unknown> {
return new Promise<unknown>((resolve) => {
return new Promise<unknown>(resolve => {
const id = this._ids.gen();
this._callbacks[id] = resolve;
emit(`${this._name}:proxy`, handlerName, args, this._identifier, id);
Expand Down
2 changes: 1 addition & 1 deletion src/static/fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ game 'common'

author 'Jaime Filho <https://github.com/jaimeadf>'
description "A resource for FiveM and RedM that takes a screenshot of a player and uploads it to a discord's webhook."
version '1.1.2'
version '1.1.3'
url 'https://github.com/jaimeadf/discord-screenshot'

server_script 'dist/server.js'
Expand Down

0 comments on commit aee8efc

Please sign in to comment.