Skip to content

Commit b1462e7

Browse files
authored
Merge pull request #5 from m7rlin/dev
Dev
2 parents f4542be + 7511c99 commit b1462e7

File tree

9 files changed

+421
-17
lines changed

9 files changed

+421
-17
lines changed

LoadWebhook.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
// Load DiscordWebhook library
44
require_once "../../lib/DiscordWebhook.php";
5+
require_once "../../lib/DiscordEmbed.php";
56

67
$webhook = [
7-
"url" => "https://discordapp.com/api/webhooks/536576089582075936/QkY4y6xDDlrPXXtnSXLiAOnIo961w6BXl1SLTE0bj-t0--A-P3thhos5tskW_lIhiRfG",
8+
"url" => "https://discordapp.com/api/webhooks/625657136378019840/ffDprzXmHRPJQprc1oBtzAq1dPN0_jo6X-BT2Fw7Cmy8wcYcstOYLhS9SmCoWF7IIO1c",
89
"username" => "",
910
"avatar" => ""
1011
];

README.md

+73-8
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,32 @@
22

33
Discord Webhook lightweight library for PHP
44

5+
Language: [English](README.md), [Polski](README.pl.md)
56

6-
Language: [🇺🇸 English](README.md), [🇵🇱 Polski](README.pl.md)
7-
8-
Discord Webhook Documentation: https://discordapp.com/developers/docs/resources/webhook#execute-webhook
7+
> Feel free to extend the library:
8+
> Discord Webhook Documentation: https://discordapp.com/developers/docs/resources/webhook#execute-webhook
99
1010
## Requirements
1111

12-
1312
Software you need to have installed before you can use this project:
1413

1514
**Local or dedicated server:**
1615

1716
They work almost the same way.
1817

19-
+ [WAMP](http://www.wampserver.com/) — v3 or [XAMPP](https://www.apachefriends.org)
18+
- [WAMP](http://www.wampserver.com/) — v3 or [XAMPP](https://www.apachefriends.org)
2019

2120
Then you need the right PHP version. Below v7 won't work.
2221

23-
+ PHP — version 7.2.14+
22+
- PHP — version 7+
2423

2524
## Installation
2625

27-
Download or clone the repository. Place the project in your server folder — `www` for WAMP and `http` for XAMPP (when not changed).
26+
Download or clone the repository. Place the project in your server folder — folder `www` for WAMP server and folder `http` for XAMPP server (when not changed).
2827

29-
## Usage
28+
## Examples
29+
30+
> I created many examples to show you how you can use this library. I'm sure that everyone will find something for yourself.
3031
3132
Open your browser and type:
3233

@@ -41,6 +42,70 @@ or
4142
- `examples` — folder with all examples
4243
- `send-message` — example folder; you can change the name of the folder and modify the URL
4344

45+
## Usage
46+
47+
https://www.youtube.com/playlist?list=PLyBTvYfUy4lGoC9R1-Db_3OWZlevO8Hpv
48+
49+
**Simple example:**
50+
51+
![Website example](https://i.imgur.com/inA39rv.png)
52+
53+
```
54+
// load Webhook
55+
require_once "../../LoadWebhook.php";
56+
57+
$username = "__BOT_USERNAME__";
58+
$avatar_url = "__LINK_TO_AVATAR__";
59+
60+
$msg = new DiscordWebhook($webhook["url"]);
61+
62+
$msg->setUsername($username)->setAvatar($avatar_url)->send();
63+
```
64+
65+
**Simple embed example:**
66+
67+
![Website example](https://i.imgur.com/WfhnmH2.png)
68+
69+
![Discord example](https://i.imgur.com/KKpPWxA.png)
70+
71+
```
72+
// load Webhook
73+
require_once "../../LoadWebhook.php";
74+
75+
$username = "__BOT_USERNAME__";
76+
$avatar_url = "__LINK_TO_AVATAR__";
77+
78+
$embed = new DiscordEmbed();
79+
// basic settings
80+
$embed->setTitle("title", "https://www.magictm.com/")->setDescription("description");
81+
82+
$msg->setUsername($username)->setAvatar($avatar_url)->setEmbed($embed)->send();
83+
```
84+
85+
The library supports **method chaining**. This is optional, so you can use both options.
86+
87+
**No-Method-Chaining:**
88+
89+
```
90+
...
91+
$msg = new DiscordWebhook($webhook["url"]);
92+
93+
$msg->setUsername($username);
94+
$msg->setAvatar($avatar_url);
95+
$msg->send();
96+
...
97+
```
98+
99+
**Method-Chaining:**
100+
101+
```
102+
...
103+
$msg = new DiscordWebhook($webhook["url"]);
104+
105+
$msg->setUsername($username)->setAvatar($avatar_url)->send();
106+
...
107+
```
108+
44109
## License
45110

46111
[MIT](https://github.com/m7rlin/DiscordWebhook/blob/master/LICENSE)

README.pl.md

+73-6
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
Discord Webhook lekka biblioteka dla języka PHP
44

5-
Language: [🇺🇸 English](README.md), [🇵🇱 Polski](README.pl.md)
5+
Language: [English](README.md), [Polski](README.pl.md)
66

7-
Discord Webhook Dokumentacja: https://discordapp.com/developers/docs/resources/webhook#execute-webhook
7+
> Czuj się swobodnie rozszerzając bibliotekę:
8+
> Discord Webhook Dokumentacja: https://discordapp.com/developers/docs/resources/webhook#execute-webhook
89
910
## Wymagania
1011

@@ -18,13 +19,15 @@ One działają prawie tak samo.
1819

1920
Następnie potrzebujesz odpowiedniej wersji PHP. Poniżej v7 nie będzie działać.
2021

21-
- PHP — wersja 7.2.14+
22+
- PHP — wersja 7+
2223

2324
## Instalacja
2425

25-
Pobierz lub sklonuj repozytorium. Umieść projekt w folderze serwera - `www` dla WAMP i`http` dla XAMPP (jeżeli nie został zmieniony).
26+
Pobierz lub sklonuj repozytorium. Umieść projekt w folderze serwera — folder `www` dla serwera WAMP i folder `http` dla serwera XAMPP (jeżeli nie został zmieniony).
2627

27-
## Użycie
28+
## Przykłady
29+
30+
> Przygotowałem przykłady, aby pokazać jak korzystać z biblioteki. Na pewno każdy znajdzie coś dla siebie.
2831
2932
Otwórz przeglądarkę i wpisz:
3033

@@ -39,6 +42,70 @@ or
3942
- `examples` — folder z przykładami
4043
- `send-message` — folder z jednym przykładem; możesz zmienić nazwę folderu i zmodyfikować adres URL
4144

45+
## Użycie
46+
47+
https://www.youtube.com/playlist?list=PLyBTvYfUy4lGoC9R1-Db_3OWZlevO8Hpv
48+
49+
**Prosty przykład:**
50+
51+
![Website example](https://i.imgur.com/inA39rv.png)
52+
53+
```
54+
// load Webhook
55+
require_once "../../LoadWebhook.php";
56+
57+
$username = "__BOT_USERNAME__";
58+
$avatar_url = "__LINK_TO_AVATAR__";
59+
60+
$msg = new DiscordWebhook($webhook["url"]);
61+
62+
$msg->setUsername($username)->setAvatar($avatar_url)->send();
63+
```
64+
65+
**Prosty przykład z embed:**
66+
67+
![Website example](https://i.imgur.com/WfhnmH2.png)
68+
69+
![Discord example](https://i.imgur.com/KKpPWxA.png)
70+
71+
```
72+
// load Webhook
73+
require_once "../../LoadWebhook.php";
74+
75+
$username = "__BOT_USERNAME__";
76+
$avatar_url = "__LINK_TO_AVATAR__";
77+
78+
$embed = new DiscordEmbed();
79+
// basic settings
80+
$embed->setTitle("title", "https://www.magictm.com/")->setDescription("description");
81+
82+
$msg->setUsername($username)->setAvatar($avatar_url)->setEmbed($embed)->send();
83+
```
84+
85+
Biblioteka wspiera **łączenie metod**. Jest to opcjonalne, dlatego możesz używać obydwu opcji.
86+
87+
**Bez łączenia metod(funkcji):**
88+
89+
```
90+
...
91+
$msg = new DiscordWebhook($webhook["url"]);
92+
93+
$msg->setUsername($username);
94+
$msg->setAvatar($avatar_url);
95+
$msg->send();
96+
...
97+
```
98+
99+
**Z łączeniem metod(funkcji):**
100+
101+
```
102+
...
103+
$msg = new DiscordWebhook($webhook["url"]);
104+
105+
$msg->setUsername($username)->setAvatar($avatar_url)->send();
106+
...
107+
```
108+
42109
## Licencja
43110

44-
[MIT](LICENSE)
111+
[MIT](https://github.com/m7rlin/DiscordWebhook/blob/master/LICENSE)
+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Discord Simple Embed</title>
5+
<meta charset="utf-8">
6+
</head>
7+
<body>
8+
<main>
9+
<h1>Discord Webhook</h1>
10+
<p>&copy; Marcin "m7rlin" Stawowczyk</p>
11+
<div class="container">
12+
<form action="index.php" method="POST">
13+
14+
<fieldset>
15+
16+
<legend>Embed</legend>
17+
18+
<div class="row">
19+
<div class="col-25">
20+
<label for="title">Title:</label>
21+
</div>
22+
<div class="col-75">
23+
<input autocomplete="off" type="text" name="title" id="title" value="<?= input("title") ?>">
24+
</div>
25+
</div>
26+
27+
<div class="row">
28+
<div class="col-25">
29+
<label for="description">Description:</label>
30+
</div>
31+
<div class="col-75">
32+
<textarea autocomplete="off" name="description" id="description" cols="30" rows="4"><?= input("description") ?></textarea>
33+
</div>
34+
</div>
35+
36+
<div class="row">
37+
<div class="col-25">
38+
<label for="title_url">Title URL:</label>
39+
</div>
40+
<div class="col-75">
41+
<input autocomplete="off" type="url" name="title_url" id="title_url" value="<?= input("title_url") ?>">
42+
</div>
43+
</div>
44+
45+
</fieldset>
46+
47+
<fieldset>
48+
49+
<legend>Message</legend>
50+
51+
<div class="row">
52+
<div class="col-25">
53+
<label for="message">Message — optional:</label>
54+
</div>
55+
<div class="col-75">
56+
<textarea autocomplete="off" name="message" id="message" cols="30" rows="4"><?= input("message") ?></textarea>
57+
</div>
58+
</div>
59+
60+
<div class="row">
61+
<div class="col-25">
62+
<label for="username">Username:</label>
63+
</div>
64+
<div class="col-75">
65+
<input autocomplete="off" type="text" name="username" id="username" value="<?= input("username") ?>">
66+
</div>
67+
</div>
68+
69+
<div class="row">
70+
<div class="col-25">
71+
<label for="avatar_url">Avatar URL:</label>
72+
</div>
73+
<div class="col-75">
74+
<input autocomplete="off" type="url" name="avatar_url" id="avatar_url" value="<?= input("avatar_url") ?>">
75+
</div>
76+
</div>
77+
78+
<div class="row">
79+
<div class="col-25">
80+
<label for="tts">TTS:</label>
81+
</div>
82+
<div class="col-75">
83+
<input type="checkbox" name="tts" id="tts" value="true"> True<br>
84+
</div>
85+
</div>
86+
87+
</fieldset>
88+
89+
<div class="row">
90+
<input type="submit" name="action" value="Submit">
91+
</div>
92+
93+
</form>
94+
</div>
95+
</main>
96+
</body>
97+
</html>

examples/embed-simple-v2/index.php

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
/**
4+
* Checks if $_POST input exist and if so returns it.
5+
*
6+
* @param string|int $input_name
7+
* @param string $input_default_value
8+
* @return string|int
9+
*/
10+
function input($input_name, $input_default_value = "") {
11+
if (isset($_POST[$input_name])) {
12+
return $_POST[$input_name];
13+
} else {
14+
return $input_default_value;
15+
}
16+
}
17+
18+
19+
// clicked on submit
20+
if (isset($_POST["action"]) && $_POST["action"] === "Submit") {
21+
22+
// load Webhook
23+
require_once "../../LoadWebhook.php";
24+
25+
$message = $_POST["message"] ?? "";
26+
$username = $_POST["username"] ?? "www.magictm.com";
27+
$avatar_url = $_POST["avatar_url"] ?? null;
28+
$tts = $_POST["tts"] ?? false;
29+
30+
$title = $_POST["title"] ?? null;
31+
$title_url = $_POST["title_url"] ?? null;
32+
$description = $_POST["description"] ?? null;
33+
34+
$msg = new DiscordWebhook($webhook["url"]);
35+
36+
$embed = new DiscordEmbed();
37+
// basic settings
38+
$embed->setTitle($title, $title_url)->setDescription($description);
39+
40+
$msg->setMessage($message)->setUsername($username)->setAvatar($avatar_url)->setEmbed($embed)->send();
41+
}
42+
43+
// load website
44+
include "inc/page.inc.php";
45+
46+
?>

0 commit comments

Comments
 (0)