This repository was archived by the owner on Oct 6, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathto-be-processed-java.txt
More file actions
326 lines (262 loc) · 10.4 KB
/
to-be-processed-java.txt
File metadata and controls
326 lines (262 loc) · 10.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
Author: Kaleidox#8536 (141476933849448448)
Message: **Language**: Java
**Library**: Javacord v3
**Maven Dependencies:**
```xml
<!-- https://mvnrepository.com/artifact/com.mashape.unirest/unirest-java -->
<dependency>
<groupId>com.mashape.unirest</groupId>
<artifactId>unirest-java</artifactId>
<version>1.4.9</version>
</dependency>
```
**Code:**
```java
String token = "YOUR TOKEN HERE";
String botId = "YOUR BOT ID HERE";
int serverCount = api.getServers().size();
JSONObject obj = new JSONObject()
.put("server_count", serverCount);
try {
Unirest.post("https://discordbots.org/api/bots/" + botId + "/stats")
.header("Authorization", token)
.header("Content-Type", "application/json")
.body(obj.toString())
.asJson();
} catch (UnirestException e) {
e.printStackTrace();
}
```
Author: duncte123#1245 (191231307290771456)
Message: **Language:** Java
**Library:** JDA
**Code:** ```JAVA
String url = "https://discordbots.org/api/bots/"+jda.getSelfUser().getId()+"/stats";
String discordbots_key = "";
JSONObject data = new JSONObject();
data.put("server_count", jda.getGuilds().size());
RequestBody body = RequestBody.create(MediaType.parse("application/json"), data.toString());
Request request = new Request.Builder()
.url(url)
.post(body)
.addHeader("User-Agent", "DiscordBot " + jda.getSelfUser().getName())
.addHeader("Authorization", discordbots_key)
.build();
try {
new OkHttpClient().newCall(request).execute();
} catch (IOException e) {
e.printStackTrace();
}```
Full class example: <https://gist.github.com/duncte123/d3ebf090cadddd3d91eff1da112960b4>
Author: Natan#1289 (182245310024777728)
Message: **Language**: Any JVM language
**Library**: Any library that runs on the JVM
**Code**: <https://github.com/natanbc/discordbots-api>
**Install**: `compile 'com.github.natanbc:discordbots-api:1.4` (gradle, needs the jcenter repository)
```java
DiscordBotsAPI api = new DiscordBotsAPI("yourToken");
//get upvotes
UpvoteInfo[] upvotes = api.getUpvoters(yourBotId);
//get stats
BotStats stats = api.getBotStats(someBotId);
//Get an user's info (they must have logged in on the website at least once)
UserInfo userInfo = api.getUser(someUserId);
//get a bot's info (it must be on the website)
BotInfo botInfo = api.getBot(someBotId);
//Post stats
api.postStats(yourBotId, shardId, shardTotal, serverCount);
//OR
api.postStats(yourBotId, new int[]{shard1ServerCount, shard2ServerCount, shard3ServerCount, ...})
//Search for bots
BotInfo[] first10BotsWithDotAsPrefix = api.search(new Search.Builder().withPrefix(".").build());
```
Author: jagrosh#4824 (113156185389092864)
Message: **Language**: Java
**Library**: JDA-Utilities
**Code**: ```java
// JDA-Utilities can automatically handle posting server counts when your bot joins a guild, leaves a guild, and at startup
CommandClientBuilder ccb;
/*
Insert code to create your builder here
*/
ccb.setDiscordBotListKey("YOUR TOKEN");
/*
Insert code to build the builder, add to a JDABuilder, etc
*/```
Author: Ague Mort#9036 (148336120936005632)
Message: Language: Java 8
Library: JDA 3 (sharded bot) / using OkHttp3 which JDA uses, so no extra dependencies!
Code: All the valuable strings/passwords are stored in an ENUM named Config
```Java
private void updateDiscordBotsOrgServerCount(JDA jda) {
String url = String.format("https://discordbots.org/api/bots/%s/stats", Config.DISCORD_CLIENT_ID.token()[0]);
JSONObject json = new JSONObject();
json.put("shard_id", jda.getShardInfo().getShardId());
json.put("shard_count", jda.getShardInfo().getShardTotal());
json.put("server_count", jda.getGuilds().size());
Request request = new Builder().url(url)
.header("Authorization", Config.DISCORD_BOTS_ORG.token()[0])
.header(CONTENT_TYPE, APPLICATION_JSON)
.post(RequestBody.create(MediaType.parse(APPLICATION_JSON), json.toString()))
.build();
try {
Response response = this.client.newCall(request).execute();
if (response.code() != 200) {
Logs.handler().logSystem(null, "DISCORDBOTS.ORG|FAIL");
} else {
Logs.handler().logSystem(null, "DISCORDBOTS.ORG|SUCCESS");
}
response.close();
} catch (IOException e) {
Logger.getAnonymousLogger().severe(e.getMessage());
}
}```
Author: MrPowerGamerBR#4185 (123170274651668480)
Message: **Language**: Java
**Library**: JDA
(Using HttpRequest library)
**Code**:
```java
String yourBotId = "40028922";
String yourDiscordBotsOrgKey = "somethinglol";
HttpRequest.post("https://discordbots.org/api/bots/" + yourBotId + "/stats")
.authorization(yourDiscordBotsOrgKey)
.acceptJson()
.send("{ \"server_count\": " + jda.getGuilds().getSize() + " }")
.body()
```
Author: Natan#1289 (182245310024777728)
Message: **Language**: Java (with okhttp)
**Library**: JDA
**Code**: ```java
private static final OkHttpClient client = new OkHttpClient();
public void sendStats() throws IOException {
JSONObject payload = new JSONObject().put("server_count", jda.getGuilds().size());
JDA.ShardInfo info = jda.getShardInfo();
if(info != null) {
payload.put("shard_id", info.getShardId()).put("shard_count", info.getShardTotal());
}
client.newCall(new Request.Builder()
.url("https://discordbots.org/api/bots/" + jda.getSelfUser().getId() + "/stats")
.addHeader("Content-Type", "application/json")
.addHeader("Authorization", "YOUR-TOKEN-GOES-HERE")
.post(RequestBody.create(MediaType.parse("application/json"), payload.toString()))
.build()
).execute().close();
}```
Author: Xevryll#2253 (138481382794985472)
Message: **Language:** Java 8
**Library:** JDA
**Code:**
```java
private void updateDiscordBotsCount(int i) {
try {
String auth = Credentials.DISCORDBOTS;
JSONObject json = new JSONObject().put("server_count", i);
String response = Unirest.post("https://discordbots.org/api/bots/{botId}/stats")
.header("User-Agent", "Bot")
.header("Authorization", auth)
.header("Content-Type", "application/json")
.header("Accept", "application/json")
.body(json)
.asString()
.getStatusText();
} catch (UnirestException e) {
e.printStackTrace();
}
}
```
Author: Ague Mort#9036 (148336120936005632)
Message: **Language**: Java 8 (using Apache HTTP Client)
**Library**: JDA 3 (sharded bot)
**Code**: *All the valuable strings/passwords are stored in an ENUM named Config*
```Java
private static void updateDiscordBotsOrgServerCount(JDA jda) {
HttpClient client = HttpClientBuilder.create().disableCookieManagement().build();
URIBuilder uriBuilder = new URIBuilder();
uriBuilder
.setScheme("https")
.setHost("discordbots.org")
.setPath("/api/bots/" + Config.DISCORD_CLIENT_ID.token() + "/stats");
HttpPost post = null;
try {
post = new HttpPost(uriBuilder.build());
} catch (URISyntaxException e) {
e.printStackTrace();
}
if (post != null) {
post.addHeader("Authorization", Config.DISCORD_BOTS_ORG.token());
post.addHeader("Content-Type", "application/json");
JSONObject json = new JSONObject();
json.put("server_count", jda.getGuilds().size());
json.put("shard_id", jda.getShardInfo().getShardId());
json.put("shard_count", jda.getShardInfo().getShardTotal());
try {
StringEntity entity = new StringEntity(json.toString());
post.setEntity(entity);
HttpResponse response = client.execute(post);
if (response.getStatusLine().getStatusCode() != 200) {
System.out.println("[~ERROR~] Failed updating server count on discordbots.org");
} else {
System.out.println("[SYSTEM] Successfully updated server count on discordbots.org");
}
} catch (IOException e) {
e.printStackTrace();
}
}
}```
Author: Ayylien™#3103 (248214880379863041)
Message: **Language:** Java
**Required:** Unirest
```java
Unirest.post(URL) .header("Authorization", Token)
.field("server_count", serverCount);
```
Author: ℒℯ 𝓦𝓲𝓷𝓽𝓮𝓻-𝔂 ℱℴ𝓍#9815 (288996157202497536)
Message: Java using Unirest (http://unirest.io/java.html)
```java
public static void postStats(int serverCount) {
JSONObject obj = new JSONObject();
obj.put("server_count", serverCount);
try {
Unirest.post("https://discordbots.org/api/bots/:id/stats")
.header("Authorization", "Your token here")
.header("Content-Type", "application/json")
.body(obj.toString())
.asJson();
} catch(UnirestException e) {
e.printStackTrace();
}
}
```
Author: Tis_awesomeness#8617 (211261249386708992)
Message: **Language:** Java
**Library:** JDA (works with other libraries if you edit it)
**Code:**
```java
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.URL;
import java.net.URLConnection;
public class GuildCountExample {
public void sendGuilds() {
String url = "https://discordbots.org/api/bots/" + jda.getSelfUser().getId() + "/stats";
int serverCount = jda.getGuilds().size();
int shardId = jda.getShardInfo().getShardId();
int shardCount = jda.getShardInfo().getShardTotal();
String query = "{\"server_count\": " + serverCount + ", \"shard_id\": " + shardId + ", \"shard_count\": " + shardCount + "}";
String token = jda.getToken();
String charset = java.nio.charset.StandardCharsets.UTF_8.name();
URLConnection conn = new URL(url).openConnection();
conn.setDoOutput(true);
conn.setRequestProperty("Accept-Charset", charset);
conn.setRequestProperty("Content-Type", "application/json");
conn.setRequestProperty("Authorization", token);
OutputStream output = conn.getOutputStream();
output.write(query.getBytes(charset));
output.close();
}
}
```