Skip to content

Commit fabd981

Browse files
authored
Merge pull request #3 from jaimeadf/develop
Update to 1.2
2 parents be7196f + d9dbf96 commit fabd981

25 files changed

+655
-221
lines changed

README.md

Lines changed: 55 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,18 @@ You can also read this README in [Portuguese](https://github.com/jaimeadf/discor
1919

2020
`discord-screenshot` is a resource for [FiveM](https://fivem.net) and [RedM](https://redm.gg) that takes a screenshot of a player and uploads it to a discord's webhook.
2121

22+
[![Showcase](https://img.youtube.com/vi/c9h40LoLky8/maxresdefault.jpg)](https://youtu.be/c9h40LoLky8)
23+
2224
## Installation
2325

2426
1. Make sure your server artifacts ([windows](https://runtime.fivem.net/artifacts/fivem/build_server_windows/master) or [linux](https://runtime.fivem.net/artifacts/fivem/build_proot_linux/master)) are up to date.
25-
2. Download the latest file at [releases](https://github.com/jaimeadf/discord-screenshot/releases) and extract it at your resources folder.
26-
3. Add `ensure screenshot-basic` and `ensure discord-screenshot` in your server.cfg before your framework's start.
27+
2. Download the latest zip file at [releases](https://github.com/jaimeadf/discord-screenshot/releases) and extract it at your resources folder.
28+
3. Add `ensure screenshot-basic` and `ensure discord-screenshot` in your server.cfg.
2729
4. Configure the resource in the `settings.json` file inside the discord-screenshot folder.
2830

2931
## Usage
3032

31-
A `/screenshot` command is created according to the framework you are using.
33+
A `/screenshot <target>` command is created according to the framework you are using. If you pass `-1` as target, a screenshot of everyone in the server will be taken.
3234

3335
**It only works outside `localhost`!**
3436

@@ -37,6 +39,11 @@ A `/screenshot` command is created according to the framework you are using.
3739
#### /screenshot &lt;player or identifier&gt;
3840
Can be used via console or by anyone with the `command.screenshot` ace permission.
3941

42+
### ESX
43+
44+
#### /screenshot &lt;player&gt;
45+
Can be used via console or by any admin.
46+
4047
### vRP
4148

4249
#### /screenshot &lt;user_id&gt;
@@ -46,41 +53,65 @@ Can be used via console or by anyone with the `command.screenshot` permission.
4653

4754
### Server
4855

49-
#### requestClientScreenshotDiscordUpload(player: string | number, webhookMessageAuthor?: DiscordWebhookMessageAuthor, webhookMessageContent?: string)
56+
#### requestClientScreenshotUploadToDiscord(player, webhookMessageDto)
5057
Takes a screenshot of the specified specific client and uploads it to the configured discord's webhook.
5158

5259
Arguments:
53-
* **player**: The target player index.
54-
* **webhookMessageAuthor**: An optional object containing the webhook message author information.
55-
* **name**: string? - An optional name for the author.
56-
* **avatarUrl**: string? - An optional url for the author avatar.
57-
* **webhookMessageContent**: An optional text for the webhook message content.
60+
* **player**: string | number
61+
* **webhookMessageDto**: [WebhookMessageDto](https://birdie0.github.io/discord-webhooks-guide/discord_webhook.html)
5862

5963
Example:
6064
```lua
61-
exports['discord-screenshot']:requestClientScreenshotDiscordUpload(GetPlayers()[1], {
62-
name = 'Screenshot',
63-
avatarUrl = 'https://canary.discord.com/assets/f78426a064bc9dd24847519259bc42af.png'
64-
}, 'This is an example.')
65+
exports['discord-screenshot']:requestClientScreenshotUploadToDiscord(GetPlayers()[1], {
66+
username = 'A cat',
67+
avatar_url = 'https://cdn2.thecatapi.com/images/IboDUkK8K.jpg',
68+
content = 'Meow!',
69+
embeds = {
70+
{
71+
color = 16771584,
72+
author = {
73+
name = 'Wow!',
74+
icon_url = 'https://cdn.discordapp.com/embed/avatars/0.png'
75+
},
76+
title = 'I can send anything.'
77+
}
78+
}
79+
})
6580
```
6681

67-
#### requestCustomClientScreenshotDiscordUpload(player: string | number, webhookUrl: string, webhookMessageAuthor?: DiscordWebhookMessageAuthor, webhookMessageContent?: string)
82+
#### requestCustomClientScreenshotUploadToDiscord(player, webhookUrl, webhookMessageDto)
6883
Takes a screenshot of the specified client and uploads it to the passed discord's webhook.
6984

7085
Arguments:
71-
* **player**: The target player index.
72-
* **webhookUrl**: The discord's webhook url.
73-
* **webhookMessageAuthor**: An optional object containing the webhook message author information.
74-
* **name**: string? - An optional name for the author.
75-
* **avatarUrl**: string? - An optional url for the author.
76-
* **webhookMessageContent**: An optional text for the webhook message content.
86+
* **player**: string | number
87+
* **webhookUrl**: string
88+
* **options**: object
89+
* **encoding**: 'png' | 'jpg' | 'webp'
90+
* **quality**: number
91+
* **webhookMessageDto**: [WebhookMessageDto](https://birdie0.github.io/discord-webhooks-guide/discord_webhook.html)
7792

7893
Example:
7994
```lua
80-
exports['discord-screenshot']:requestCustomClientScreenshotDiscordUpload(GetPlayers()[1], 'https://canary.discord.com/api/webhooks/412884227131886566/qFcXr19SozY5Bej5H74RdbRscsOjH4eVxgJO5Iwh5iawmkpRfjzijezlwdu15wNsCk4w', {
81-
name = 'Screenshot',
82-
avatarUrl = 'https://canary.discord.com/assets/f78426a064bc9dd24847519259bc42af.png'
83-
}, 'This is an example.')
95+
local screenshotOptions = {
96+
encoding = 'png',
97+
quality = 1
98+
}
99+
100+
exports['discord-screenshot']:requestCustomClientScreenshotUploadToDiscord(GetPlayers()[1], 'https://ptb.discord.com/api/webhooks/767824413780607097/WLjd77Y0CUvqXmhLCYzqkiZ-BrTpcGfNiZ7hXcJRgQxrU0YR8sy566MgMHgqRx8IZ9iu', screenshotOptions, {
101+
username = 'A cat',
102+
avatar_url = 'https://cdn2.thecatapi.com/images/IboDUkK8K.jpg',
103+
content = 'Meow!',
104+
embeds = {
105+
{
106+
color = 16771584,
107+
author = {
108+
name = 'Wow!',
109+
icon_url = 'https://cdn.discordapp.com/embed/avatars/0.png'
110+
},
111+
title = 'I can send anything.'
112+
}
113+
}
114+
})
84115
```
85116

86117
## Dependencies

README.pt.md

Lines changed: 55 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,18 @@
1616

1717
`discord-screenshot` é um resource para [FiveM](https://fivem.net) e [RedM](https://redm.gg) que tira uma captura de tela de um player e a upa para um webhook do discord.
1818

19+
[![Showcase](https://img.youtube.com/vi/c9h40LoLky8/maxresdefault.jpg)](https://youtu.be/c9h40LoLky8)
20+
1921
## Instalação
2022

2123
1. Certifique-se que seus artefatos ([windows](https://runtime.fivem.net/artifacts/fivem/build_server_windows/master) ou [linux](https://runtime.fivem.net/artifacts/fivem/build_proot_linux/master)) estejam atualizados.
22-
2. Baixe o último arquivo em [releases](https://github.com/jaimeadf/discord-screenshot/releases) e extraia na sua pasta resources.
23-
3. Adicione `ensure screenshot-basic` e `ensure discord-screenshot` no seu server.cfg antes do start de sua framework.
24+
2. Baixe o último arquivo zip em [releases](https://github.com/jaimeadf/discord-screenshot/releases) e extraia na sua pasta resources.
25+
3. Adicione `ensure screenshot-basic` e `ensure discord-screenshot` no seu server.cfg.
2426
4. Configure o resource no arquivo `settings.json` dentro da pasta discord-screenshot.
2527

2628
## Uso
2729

28-
Um comando `/screenshot` é criado de acordo com a framework que você está utilizando.
30+
Um comando `/screenshot <alvo>` é criado de acordo com a framework que você está utilizando. Se você passar `-1` como alvo, uma captura da tela de todos no servidor será tirada.
2931

3032
**Ele só funciona fora de `localhost`!**
3133

@@ -34,6 +36,11 @@ Um comando `/screenshot` é criado de acordo com a framework que você está uti
3436
#### /screenshot &lt;player ou identificador&gt;
3537
Pode ser usado via console ou por qualquer um com a permissão ace `command.screenshot`.
3638

39+
### ESX
40+
41+
#### /screenshot &lt;player&gt;
42+
Pode ser usado via console ou por qualquer admin.
43+
3744
### vRP
3845

3946
#### /screenshot &lt;user_id&gt;
@@ -43,41 +50,65 @@ Pode ser usado via console ou por qualquer um com a permissão `command.screensh
4350

4451
### Servidor
4552

46-
#### requestClientScreenshotDiscordUpload(player: string | number, webhookMessageAuthor?: DiscordWebhookMessageAuthor, webhookMessageContent?: string)
53+
#### requestClientScreenshotUploadToDiscord(player, webhookMessageDto)
4754
Tira uma captura de tela do cliente especificado e a envia para o webhook do discord configurado.
4855

4956
Argumentos:
50-
* **player**: O índice do player alvo.
51-
* **webhookMessageAuthor**: Um objeto opcional contendo as informações do autor da mensagem do webhook.
52-
* **name**: string? - Um nome opcional para o autor.
53-
* **avatarUrl**: string? - Uma url opcional para o avatar do autor.
54-
* **webhookMessageContent**: Um texto opcional para o contéudo da mensagem do webhook.
57+
* **player**: string | number
58+
* **webhookMessageDto**: [WebhookMessageDto](https://birdie0.github.io/discord-webhooks-guide/discord_webhook.html)
5559

5660
Exemplo:
5761
```lua
58-
exports['discord-screenshot']:requestClientScreenshotDiscordUpload(GetPlayers()[1], {
59-
name = 'Screenshot',
60-
avatarUrl = 'https://canary.discord.com/assets/f78426a064bc9dd24847519259bc42af.png'
61-
}, 'This is an example.')
62+
exports['discord-screenshot']:requestClientScreenshotUploadToDiscord(GetPlayers()[1], {
63+
username = 'A cat',
64+
avatar_url = 'https://cdn2.thecatapi.com/images/IboDUkK8K.jpg',
65+
content = 'Meow!',
66+
embeds = {
67+
{
68+
color = 16771584,
69+
author = {
70+
name = 'Wow!',
71+
icon_url = 'https://cdn.discordapp.com/embed/avatars/0.png'
72+
},
73+
title = 'I can send anything.'
74+
}
75+
}
76+
})
6277
```
6378

64-
#### requestCustomClientScreenshotDiscordUpload(player: string | number, webhookUrl: string, webhookMessageAuthor?: DiscordWebhookMessageAuthor, webhookMessageContent?: string)
79+
#### requestCustomClientScreenshotUploadToDiscord(player, webhookUrl, webhookMessageDto)
6580
Tira uma captura de tela do cliente especificado e a envia para o webhook do discord passado.
6681

6782
Argumentos:
68-
* **player**: O índice do player alvo.
69-
* **webhookUrl**: A url do webhook do discord.
70-
* **webhookMessageAuthor**: Um objeto opcional contendo as informações do autor da mensagem do webhook.
71-
* **name**: string? - Um nome opcional para o autor.
72-
* **avatarUrl**: string? - Uma url opcional para o avatar do autor.
73-
* **webhookMessageContent**: Um texto opcional para o contéudo da mensagem do webhook.
83+
* **player**: string | number
84+
* **webhookUrl**: string
85+
* **options**: object
86+
* **encoding**: 'png' | 'jpg' | 'webp'
87+
* **quality**: number
88+
* **webhookMessageDto**: [WebhookMessageDto](https://birdie0.github.io/discord-webhooks-guide/discord_webhook.html)
7489

7590
Exemplo:
7691
```lua
77-
exports['discord-screenshot']:requestCustomClientScreenshotDiscordUpload(GetPlayers()[1], 'https://canary.discord.com/api/webhooks/412884227131886566/qFcXr19SozY5Bej5H74RdbRscsOjH4eVxgJO5Iwh5iawmkpRfjzijezlwdu15wNsCk4w', {
78-
name = 'Screenshot',
79-
avatarUrl = 'https://canary.discord.com/assets/f78426a064bc9dd24847519259bc42af.png'
80-
}, 'This is an example.')
92+
local screenshotOptions = {
93+
encoding = 'png',
94+
quality = 1
95+
}
96+
97+
exports['discord-screenshot']:requestCustomClientScreenshotUploadToDiscord(GetPlayers()[1], 'https://ptb.discord.com/api/webhooks/767824413780607097/WLjd77Y0CUvqXmhLCYzqkiZ-BrTpcGfNiZ7hXcJRgQxrU0YR8sy566MgMHgqRx8IZ9iu', screenshotOptions, {
98+
username = 'A cat',
99+
avatar_url = 'https://cdn2.thecatapi.com/images/IboDUkK8K.jpg',
100+
content = 'Meow!',
101+
embeds = {
102+
{
103+
color = 16771584,
104+
author = {
105+
name = 'Wow!',
106+
icon_url = 'https://cdn.discordapp.com/embed/avatars/0.png'
107+
},
108+
title = 'I can send anything.'
109+
}
110+
}
111+
})
81112
```
82113

83114
## Dependências

package.json

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "discord-screenshot",
3-
"version": "1.1.5",
3+
"version": "1.2",
44
"description": "A resource for FiveM and RedM that takes a screenshot of a player and uploads it to a discord's webhook.",
55
"main": "index.js",
66
"scripts": {
@@ -13,18 +13,24 @@
1313
"@babel/plugin-transform-typescript": "^7.10.1",
1414
"@babel/preset-env": "^7.10.2",
1515
"@citizenfx/server": "^1.0.2613-1",
16-
"@types/data-urls": "^2.0.0",
16+
"@types/axios": "^0.14.0",
17+
"@types/color": "^3.0.1",
1718
"@types/node": "^14.0.13",
19+
"@types/whatwg-mimetype": "^2.1.0",
1820
"babel-loader": "^8.1.0",
1921
"copy-webpack-plugin": "^6.2.1",
22+
"fivem-esx-js": "^0.1.12",
2023
"typescript": "^4.0.3",
2124
"webpack": "^4.44.2",
2225
"webpack-cli": "^3.3.12"
2326
},
2427
"dependencies": {
28+
"axios": "^0.21.0",
29+
"color": "^3.1.3",
2530
"cross-blob": "^2.0.0",
26-
"data-urls": "^2.0.0",
2731
"form-data": "^3.0.0",
32+
"http-status-codes": "^2.1.4",
33+
"typescript-collections": "^1.3.3",
2834
"whatwg-mimetype": "^2.3.0"
2935
}
3036
}

src/server/DiscordScreenshot.ts

Lines changed: 0 additions & 27 deletions
This file was deleted.

src/server/commands/Command.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class Command {
77
this.handler = handler;
88

99
RegisterCommand(name, (player: number, args: string[], rawCommand: string) =>
10-
this.handler?.execute(player, args, rawCommand), false);
10+
this.handler?.execute(player.toString(), args, rawCommand), false);
1111
}
1212

1313
public setHandler(handler: CommandHandler) {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
interface CommandHandler {
2-
execute(player: number, args: string[], rawCommand: string): Promise<void>;
2+
execute(player: string, args: string[], rawCommand: string): Promise<void>;
33
}
44

55
export default CommandHandler;
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { ESXServer } from 'fivem-esx-js/server/esx_server';
2+
3+
import ScreenshotCommandHandler from './ScreenshotCommandHandler';
4+
import ScreenshotTaker from '../../screenshot/ScreenshotTaker';
5+
import DiscordWebhook from '../../discord/DiscordWebhook';
6+
7+
class EsxScreenshotCommandHandler extends ScreenshotCommandHandler {
8+
private readonly _esx: ESXServer;
9+
10+
public constructor(screenshotTaker: ScreenshotTaker, discordWebhook: DiscordWebhook) {
11+
super(screenshotTaker, discordWebhook);
12+
this._esx = global.exports['es_extended'].getSharedObject();
13+
}
14+
15+
public async execute(player: string, args: string[], rawCommand: string): Promise<void> {
16+
if (player !== '0') {
17+
const xPlayer = this._esx.GetPlayerFromId(parseInt(player));
18+
if (xPlayer.getGroup() !== 'admin') {
19+
return;
20+
}
21+
}
22+
23+
const target = args[0];
24+
if (target === '-1') {
25+
this.requestEveryoneScreenshotUploadToDiscord();
26+
} else {
27+
await this.requestClientScreenshotUploadToDiscord(target);
28+
}
29+
}
30+
}
31+
32+
export default EsxScreenshotCommandHandler;

0 commit comments

Comments
 (0)