|
17 | 17 | public class D4JAnalytics extends AnalyticsBase { |
18 | 18 | private final DiscordClient client; |
19 | 19 |
|
20 | | - private Number guildCount; |
21 | | - private Number userCount; |
22 | | - private ArrayList<String> guildsLocales; |
23 | | - private ArrayList<String> locales; |
24 | | - private ArrayList<String> interactions; |
25 | | - |
26 | 20 | public D4JAnalytics(DiscordClient client, EventsTracker eventsToTrack, String apiKey) { |
27 | 21 | super(eventsToTrack, apiKey); |
28 | 22 | this.client = client; |
29 | 23 | this.baseAPIUrl = ApiEndpoints.BASE_URL + ApiEndpoints.BOT_STATS.replace("[id]", Objects.requireNonNull(Objects.requireNonNull(client.getSelf().block()).id().asString())); |
30 | 24 |
|
31 | 25 | String[] date = new Date().toString().split(" "); |
32 | | - String dateString = date[5] + "-" + monthToNumber(date[1]) + "-" + date[2]; |
33 | 26 |
|
34 | 27 | this.setData(new HashMap<>() {{ |
35 | | - put("date", dateString); |
| 28 | + put("date", date[5] + "-" + monthToNumber(date[1]) + "-" + date[2]); |
36 | 29 | put("guilds", client.getGuilds().count().block()); |
37 | 30 | put("users", client.getGuilds().flatMap(guild -> client.getGuildById(Snowflake.of(guild.id())).getMembers().count()).reduce(0L, Long::sum).block()); |
38 | 31 | put("interactions", new ArrayList<>()); |
39 | 32 | put("locales", new ArrayList<>()); |
40 | 33 | put("guildsLocales", new ArrayList<>()); |
41 | 34 | }}); |
42 | | - |
43 | | - this.guildCount = (Number) getData().get("guilds"); |
44 | | - this.userCount = (Number) getData().get("users"); |
45 | | - this.guildsLocales = (ArrayList<String>) getData().get("guildsLocales"); |
46 | | - this.locales = (ArrayList<String>) getData().get("locales"); |
47 | | - this.interactions = (ArrayList<String>) getData().get("interactions"); |
48 | 35 | } |
49 | 36 |
|
50 | 37 | private boolean isInvalidClient() { |
@@ -73,6 +60,12 @@ public void trackEvents() throws IOException, InterruptedException { |
73 | 60 | client.withGateway((GatewayDiscordClient gateway) -> { |
74 | 61 | if (eventsToTrack.trackInteractions) { |
75 | 62 | gateway.on(InteractionCreateEvent.class, event -> { |
| 63 | + Number guildCount = eventsToTrack.trackGuilds ? client.getGuilds().count().block() : null; |
| 64 | + Number userCount = eventsToTrack.trackUserCount ? client.getGuilds().flatMap(guild -> client.getGuildById(Snowflake.of(guild.id())).getMembers().count()).reduce(0L, Long::sum).block() : null; |
| 65 | + ArrayList<String> guildsLocales = (ArrayList<String>) getData().get("guildsLocales"); |
| 66 | + ArrayList<String> locales = (ArrayList<String>) getData().get("locales"); |
| 67 | + ArrayList<String> interactions = (ArrayList<String>) getData().get("interactions"); |
| 68 | + |
76 | 69 | String[] date = new Date().toString().split(" "); |
77 | 70 | String dateString = date[5] + "-" + monthToNumber(date[1]) + "-" + date[2]; |
78 | 71 |
|
@@ -134,8 +127,8 @@ public void trackEvents() throws IOException, InterruptedException { |
134 | 127 | put("guilds", guildCount); |
135 | 128 | put("users", userCount); |
136 | 129 | put("interactions", interactions); |
137 | | - put("locales", locales); |
138 | | - put("guildsLocales", guildsLocales); |
| 130 | + put("locales", eventsToTrack.trackUserLanguage ? locales : new ArrayList<>()); |
| 131 | + put("guildsLocales", eventsToTrack.trackGuildsLocale ? guildsLocales : new ArrayList<>()); |
139 | 132 | }}); |
140 | 133 |
|
141 | 134 | return Mono.empty(); |
|
0 commit comments