Skip to content

Commit 820a342

Browse files
committed
feat: adapt to v1
1 parent 92ccb8a commit 820a342

File tree

9 files changed

+229
-195
lines changed

9 files changed

+229
-195
lines changed

README.md

Lines changed: 94 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,27 @@
22

33
The community-maintained PHP library for Top.gg.
44

5+
## Chapters
6+
7+
- [Installation](#installation)
8+
- [Setting up](#setting-up)
9+
- [Usage](#usage)
10+
- [API v1](#api-v1)
11+
- [Getting your project's vote information of a user](#getting-your-projects-vote-information-of-a-user)
12+
- [Posting your bot's application commands list](#posting-your-bots-application-commands-list)
13+
- [API v0](#api-v0)
14+
- [Getting a bot](#getting-a-bot)
15+
- [Getting several bots](#getting-several-bots)
16+
- [Getting your project's voters](#getting-your-projects-voters)
17+
- [Check if a user has voted for your project](#check-if-a-user-has-voted-for-your-project)
18+
- [Getting your bot's statistics](#getting-your-bots-statistics)
19+
- [Posting your bot's statistics](#posting-your-bots-statistics)
20+
- [Automatically posting your bot's statistics every few minutes](#automatically-posting-your-bots-statistics-every-few-minutes)
21+
- [Checking if the weekend vote multiplier is active](#checking-if-the-weekend-vote-multiplier-is-active)
22+
- [Generating widget URLs](#generating-widget-urls)
23+
- [Webhooks](#webhooks)
24+
- [Being notified whenever someone voted for your project](#being-notified-whenever-someone-voted-for-your-project)
25+
526
## Installation
627

728
```sh
@@ -10,74 +31,116 @@ $ composer require top-gg/php-sdk
1031

1132
## Setting up
1233

34+
### API v1
35+
36+
> **NOTE**: API v1 also includes API v0.
37+
38+
```php
39+
include_once __DIR__ . "/vendor/autoload.php";
40+
41+
use DBL\V1DBL;
42+
43+
$client = new V1DBL([
44+
"token" => "Top.gg API token"
45+
]);
46+
```
47+
48+
### API v0
49+
1350
```php
1451
include_once __DIR__ . "/vendor/autoload.php";
1552

1653
use DBL\DBL;
1754

1855
$client = new DBL([
19-
"token" => "Insert your Top.gg API token here."
56+
"token" => "Top.gg API token"
2057
]);
2158
```
2259

2360
## Usage
2461

25-
### Getting a bot
62+
### API v1
63+
64+
#### Getting your project's vote information of a user
2665

2766
```php
28-
$bot = $client->get_bot();
67+
$vote = $client->get_vote(661200758510977084);
2968
```
3069

31-
### Getting several bots
70+
#### Posting your bot's application commands list
3271

33-
#### With defaults
72+
```php
73+
$client->post_commands([
74+
[
75+
"options" => [],
76+
"name" => "test",
77+
"name_localizations" => null,
78+
"description" => "command description",
79+
"description_localizations" => null,
80+
"contexts" => [],
81+
"default_permission" => null,
82+
"default_member_permissions" => null,
83+
"dm_permission" => false,
84+
"integration_types" => [],
85+
"nsfw" => false
86+
]
87+
]);
88+
```
89+
90+
### API v0
91+
92+
#### Getting a bot
3493

3594
```php
36-
$bots = $client->get_bots();
95+
$bot = $client->get_bot(1026525568344264724);
3796
```
3897

39-
#### With explicit arguments
98+
#### Getting several bots
4099

41100
```php
42101
// Limit Offset Sort by
43-
$bots = $client->get_bots(50, 0, "date");
102+
$bots = $client->get_bots(50, 0, "monthlyPoints");
44103
```
45104

46-
### Getting your bot's voters
105+
#### Getting your project's voters
47106

48-
#### First page
107+
##### First page
49108

50109
```php
51-
$voters = $client->get_voters();
110+
$voters = $client->get_votes();
52111
```
53112

54-
#### Subsequent pages
113+
##### Subsequent pages
55114

56115
```php
57-
$voters = $client->get_voters(2);
116+
// Bot ID (unused) Page number
117+
$voters = $client->get_votes(0, 2);
58118
```
59119

60-
### Check if a user has voted for your bot
120+
#### Check if a user has voted for your project
61121

62122
```php
63-
$has_voted = $client->has_voted(205680187394752512);
123+
// Bot ID (unused) User ID
124+
$has_voted = $client->get_user_vote(0, 661200758510977084);
64125
```
65126

66-
### Getting your bot's server count
127+
#### Getting your bot's statistics
67128

68129
```php
69-
$server_count = $client->get_server_count();
130+
$stats = $client->get_stats();
70131
```
71132

72-
### Posting your bot's server count
133+
#### Posting your bot's statistics
73134

74135
```php
75-
$client->post_server_count($bot->get_server_count());
136+
$client->post_stats(0, [
137+
"server_count" => $bot->get_server_count()
138+
]);
76139
```
77140

78-
### Automatically posting your bot's server count every few minutes
141+
#### Automatically posting your bot's statistics every few minutes
79142

80-
> **NOTE:** Considering PHP's shortcomings, this is only possible via a URL.
143+
> **NOTE**: Considering PHP's shortcomings, this is only possible via a URL.
81144
82145
In your original client declaration:
83146

@@ -87,21 +150,23 @@ $client = new DBL([
87150
"auto_stats" => [
88151
"url": "Your URL",
89152
"callback": => function () use ($bot) {
90-
return $bot->get_server_count();
153+
return [
154+
"server_count" => $bot->get_server_count()
155+
];
91156
}
92157
]
93158
]);
94159
```
95160

96-
### Checking if the weekend vote multiplier is active
161+
#### Checking if the weekend vote multiplier is active
97162

98163
```php
99164
$is_weekend = $client->is_weekend();
100165
```
101166

102-
### Generating widget URLs
167+
#### Generating widget URLs
103168

104-
#### Large
169+
##### Large
105170

106171
```php
107172
use DBL\Widget;
@@ -110,7 +175,7 @@ use DBL\WidgetType;
110175
$widget_url = Widget::large(WidgetType::DiscordBot, 574652751745777665);
111176
```
112177

113-
#### Votes
178+
##### Votes
114179

115180
```php
116181
use DBL\Widget;
@@ -119,7 +184,7 @@ use DBL\WidgetType;
119184
$widget_url = Widget::votes(WidgetType::DiscordBot, 574652751745777665);
120185
```
121186

122-
#### Owner
187+
##### Owner
123188

124189
```php
125190
use DBL\Widget;
@@ -128,7 +193,7 @@ use DBL\WidgetType;
128193
$widget_url = Widget::owner(WidgetType::DiscordBot, 574652751745777665);
129194
```
130195

131-
#### Social
196+
##### Social
132197

133198
```php
134199
use DBL\Widget;
@@ -139,7 +204,7 @@ $widget_url = Widget::social(WidgetType::DiscordBot, 574652751745777665);
139204

140205
### Webhooks
141206

142-
#### Being notified whenever someone voted for your bot
207+
#### Being notified whenever someone voted for your project
143208

144209
**With Laravel:**
145210

main.php

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,61 @@
1818
*/
1919

2020
include_once __DIR__ . "/vendor/autoload.php";
21-
use DBL\DBL;
22-
use DBL\API\Http;
21+
use DBL\V1DBL;
2322

2423
$token = @file_get_contents(".TOKEN");
25-
$api = new DBL([
24+
$client = new V1DBL([
2625
"token" => $token
2726
]);
2827

28+
echo "\nrunning get bot:\n";
29+
$bot = $client->get_bot(1026525568344264724);
30+
print_r($bot);
31+
32+
echo "\nrunning get bots:\n";
33+
$bots = $client->get_bots();
34+
print_r($bots);
35+
36+
echo "\nrunning get votes:\n";
37+
$voters = $client->get_votes();
38+
print_r($voters);
39+
40+
echo "\nrunning get user vote:\n";
41+
$has_voted = $client->get_user_vote(0, 661200758510977084);
42+
print_r($has_voted);
43+
44+
echo "\nrunning get stats:\n";
45+
$stats = $client->get_stats();
46+
print_r($stats);
47+
48+
echo "\nrunning post stats:\n";
49+
$client->post_stats(0, [
50+
"server_count" => 2
51+
]);
52+
53+
echo "\nrunning is weekend:\n";
54+
$is_weekend = $client->is_weekend();
55+
print_r($is_weekend);
56+
57+
echo "\nrunning post commands:\n";
58+
$client->post_commands([
59+
[
60+
"options" => [],
61+
"name" => "test",
62+
"name_localizations" => null,
63+
"description" => "command description",
64+
"description_localizations" => null,
65+
"contexts" => [],
66+
"default_permission" => null,
67+
"default_member_permissions" => null,
68+
"dm_permission" => false,
69+
"integration_types" => [],
70+
"nsfw" => false
71+
]
72+
]);
73+
74+
echo "\nrunning get vote:\n";
75+
$vote = $client->get_vote(661200758510977084);
76+
print_r($vote);
77+
2978
?>

src/TopPHP/API/Exceptions/GlobalRatelimitException.php

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

src/TopPHP/API/Exceptions/MissingStatsException.php

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

0 commit comments

Comments
 (0)