mirror of
https://github.com/DreamExposure/DisCal-Discord-Bot.git
synced 2026-05-04 16:19:37 -05:00
Upgrade to D4J 3.2.0-SNAPSHOT
This way I can utilize my contrib to d4j that allows easier checking of role permissions on the Rest Client Also sets explicit intents and updates sass.
This commit is contained in:
@@ -1,40 +1,7 @@
|
||||
package org.dreamexposure.discal.client;
|
||||
|
||||
import org.dreamexposure.discal.client.listeners.discord.ChannelDeleteListener;
|
||||
import org.dreamexposure.discal.client.listeners.discord.MessageCreateListener;
|
||||
import org.dreamexposure.discal.client.listeners.discord.ReadyEventListener;
|
||||
import org.dreamexposure.discal.client.listeners.discord.RoleDeleteListener;
|
||||
import org.dreamexposure.discal.client.message.Messages;
|
||||
import org.dreamexposure.discal.client.module.announcement.AnnouncementThread;
|
||||
import org.dreamexposure.discal.client.module.command.AddCalendarCommand;
|
||||
import org.dreamexposure.discal.client.module.command.AnnouncementCommand;
|
||||
import org.dreamexposure.discal.client.module.command.CalendarCommand;
|
||||
import org.dreamexposure.discal.client.module.command.CommandExecutor;
|
||||
import org.dreamexposure.discal.client.module.command.DevCommand;
|
||||
import org.dreamexposure.discal.client.module.command.DisCalCommand;
|
||||
import org.dreamexposure.discal.client.module.command.EventCommand;
|
||||
import org.dreamexposure.discal.client.module.command.EventListCommand;
|
||||
import org.dreamexposure.discal.client.module.command.HelpCommand;
|
||||
import org.dreamexposure.discal.client.module.command.LinkCalendarCommand;
|
||||
import org.dreamexposure.discal.client.module.command.RsvpCommand;
|
||||
import org.dreamexposure.discal.client.module.command.TimeCommand;
|
||||
import org.dreamexposure.discal.client.service.KeepAliveHandler;
|
||||
import org.dreamexposure.discal.client.service.TimeManager;
|
||||
import org.dreamexposure.discal.core.calendar.CalendarAuth;
|
||||
import org.dreamexposure.discal.core.database.DatabaseManager;
|
||||
import org.dreamexposure.discal.core.logger.LogFeed;
|
||||
import org.dreamexposure.discal.core.logger.object.LogObject;
|
||||
import org.dreamexposure.discal.core.network.google.Authorization;
|
||||
import org.dreamexposure.discal.core.object.BotSettings;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.autoconfigure.session.SessionAutoConfiguration;
|
||||
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.time.Duration;
|
||||
import java.util.Properties;
|
||||
|
||||
import discord4j.common.store.Store;
|
||||
import discord4j.common.store.legacy.LegacyStoreLayout;
|
||||
import discord4j.core.DiscordClientBuilder;
|
||||
import discord4j.core.GatewayDiscordClient;
|
||||
import discord4j.core.event.domain.channel.TextChannelDeleteEvent;
|
||||
@@ -46,15 +13,40 @@ import discord4j.core.object.presence.Presence;
|
||||
import discord4j.core.shard.ShardingStrategy;
|
||||
import discord4j.discordjson.json.GuildData;
|
||||
import discord4j.discordjson.json.MessageData;
|
||||
import discord4j.gateway.intent.Intent;
|
||||
import discord4j.gateway.intent.IntentSet;
|
||||
import discord4j.store.api.mapping.MappingStoreService;
|
||||
import discord4j.store.api.service.StoreService;
|
||||
import discord4j.store.jdk.JdkStoreService;
|
||||
import discord4j.store.redis.RedisStoreService;
|
||||
import io.lettuce.core.RedisClient;
|
||||
import io.lettuce.core.RedisURI;
|
||||
import org.dreamexposure.discal.client.listeners.discord.ChannelDeleteListener;
|
||||
import org.dreamexposure.discal.client.listeners.discord.MessageCreateListener;
|
||||
import org.dreamexposure.discal.client.listeners.discord.ReadyEventListener;
|
||||
import org.dreamexposure.discal.client.listeners.discord.RoleDeleteListener;
|
||||
import org.dreamexposure.discal.client.message.Messages;
|
||||
import org.dreamexposure.discal.client.module.announcement.AnnouncementThread;
|
||||
import org.dreamexposure.discal.client.module.command.*;
|
||||
import org.dreamexposure.discal.client.service.KeepAliveHandler;
|
||||
import org.dreamexposure.discal.client.service.TimeManager;
|
||||
import org.dreamexposure.discal.core.calendar.CalendarAuth;
|
||||
import org.dreamexposure.discal.core.database.DatabaseManager;
|
||||
import org.dreamexposure.discal.core.logger.LogFeed;
|
||||
import org.dreamexposure.discal.core.logger.object.LogObject;
|
||||
import org.dreamexposure.discal.core.network.google.Authorization;
|
||||
import org.dreamexposure.discal.core.object.BotSettings;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.autoconfigure.session.SessionAutoConfiguration;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.time.Duration;
|
||||
import java.util.Properties;
|
||||
|
||||
@SpringBootApplication(exclude = SessionAutoConfiguration.class)
|
||||
public class DisCalClient {
|
||||
private static GatewayDiscordClient client;
|
||||
@@ -123,8 +115,9 @@ public class DisCalClient {
|
||||
//Login
|
||||
DiscordClientBuilder.create(BotSettings.TOKEN.get())
|
||||
.build().gateway()
|
||||
.setEnabledIntents(getIntents())
|
||||
.setSharding(getStrategy())
|
||||
.setStoreService(getStores())
|
||||
.setStore(Store.fromLayout(LegacyStoreLayout.of(getStores())))
|
||||
.setInitialStatus(shard -> Presence.online(Activity.playing("Booting Up!")))
|
||||
.withGateway(client -> {
|
||||
DisCalClient.client = client;
|
||||
@@ -185,6 +178,17 @@ public class DisCalClient {
|
||||
}
|
||||
}
|
||||
|
||||
private static IntentSet getIntents() {
|
||||
return IntentSet.of(
|
||||
Intent.GUILDS,
|
||||
Intent.GUILD_MEMBERS,
|
||||
Intent.GUILD_MESSAGES,
|
||||
Intent.GUILD_MESSAGE_REACTIONS,
|
||||
Intent.DIRECT_MESSAGES,
|
||||
Intent.DIRECT_MESSAGE_REACTIONS
|
||||
);
|
||||
}
|
||||
|
||||
//Public stuffs
|
||||
@Deprecated
|
||||
public static GatewayDiscordClient getClient() {
|
||||
|
||||
+2
-2
@@ -25,7 +25,7 @@
|
||||
<dependency>
|
||||
<groupId>com.discord4j</groupId>
|
||||
<artifactId>stores-redis</artifactId>
|
||||
<version>${discord4j.version}</version>
|
||||
<version>${discord4j.stores.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>io.netty</groupId>
|
||||
@@ -65,4 +65,4 @@
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
</project>
|
||||
|
||||
@@ -8,6 +8,7 @@ import discord4j.core.event.domain.message.MessageCreateEvent
|
||||
import discord4j.rest.http.client.ClientException
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
import org.dreamexposure.discal.core.`object`.BotSettings
|
||||
import org.dreamexposure.discal.core.serializers.SnowflakeAsStringSerializer
|
||||
import reactor.core.publisher.Flux
|
||||
import reactor.core.publisher.Mono
|
||||
@@ -153,7 +154,6 @@ data class RsvpData(
|
||||
|
||||
fun clearRole(event: MessageCreateEvent) = clearRole(event.client.rest())
|
||||
|
||||
//TODO: Add check for if role can be assigned once D4J accepts my PR
|
||||
//Functions
|
||||
fun removeCompletely(userId: String, client: DiscordClient): Mono<Void> {
|
||||
return Mono.just(userId)
|
||||
@@ -163,9 +163,7 @@ data class RsvpData(
|
||||
.doOnNext(undecided::remove)
|
||||
.flatMap {
|
||||
if (roleId != null) {
|
||||
client.getGuildById(this.guildId)
|
||||
.removeMemberRole(Snowflake.of(it), roleId, "Removed RSVP to event with ID: $eventId")
|
||||
.onErrorResume(ClientException::class.java) { Mono.empty() }
|
||||
removeRole(it, roleId!!, "Removed RSVP to event with ID: $eventId", client)
|
||||
} else Mono.empty()
|
||||
}.then()
|
||||
}
|
||||
@@ -177,9 +175,7 @@ data class RsvpData(
|
||||
.doOnNext(goingOnTime::add)
|
||||
.flatMap {
|
||||
if (roleId != null) {
|
||||
client.getGuildById(this.guildId)
|
||||
.addMemberRole(Snowflake.of(it), roleId, "RSVP'd to event with ID: $eventId")
|
||||
.onErrorResume(ClientException::class.java) { Mono.empty() }
|
||||
addRole(it, roleId!!, "RSVP'd to event with ID: $eventId", client)
|
||||
} else Mono.empty()
|
||||
}.then()
|
||||
}
|
||||
@@ -191,9 +187,7 @@ data class RsvpData(
|
||||
.doOnNext(goingLate::add)
|
||||
.flatMap {
|
||||
if (roleId != null) {
|
||||
client.getGuildById(this.guildId)
|
||||
.addMemberRole(Snowflake.of(it), roleId, "RSVP'd to event with ID: $eventId")
|
||||
.onErrorResume(ClientException::class.java) { Mono.empty() }
|
||||
addRole(it, roleId!!, "RSVP'd to event with ID: $eventId", client)
|
||||
} else Mono.empty()
|
||||
}.then()
|
||||
}
|
||||
@@ -207,4 +201,26 @@ data class RsvpData(
|
||||
|| this.undecided.isNotEmpty()
|
||||
|| limit != -1
|
||||
}
|
||||
|
||||
private fun addRole(userId: String, roleId: Snowflake, reason: String, client: DiscordClient): Mono<Void> {
|
||||
return client.getMemberById(this.guildId, Snowflake.of(BotSettings.ID.get()))
|
||||
.isHigher(Snowflake.of(userId))
|
||||
.filter { it }
|
||||
.flatMap {
|
||||
client.getGuildById(this.guildId)
|
||||
.addMemberRole(Snowflake.of(userId), roleId, reason)
|
||||
.onErrorResume(ClientException::class.java) { Mono.empty() }
|
||||
}
|
||||
}
|
||||
|
||||
private fun removeRole(userId: String, roleId: Snowflake, reason: String, client: DiscordClient): Mono<Void> {
|
||||
return client.getMemberById(this.guildId, Snowflake.of(BotSettings.ID.get()))
|
||||
.isHigher(Snowflake.of(userId))
|
||||
.filter { it }
|
||||
.flatMap {
|
||||
client.getGuildById(this.guildId)
|
||||
.removeMemberRole(Snowflake.of(userId), roleId, reason)
|
||||
.onErrorResume(ClientException::class.java) { Mono.empty() }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Generated
+18010
-8050
File diff suppressed because it is too large
Load Diff
+5
-3
@@ -25,18 +25,20 @@
|
||||
"gulp-header": "2.0.9",
|
||||
"gulp-rename": "2.0.0",
|
||||
"gulp-sass": "4.1.0",
|
||||
"node-sass": "5.0.0",
|
||||
"ts-loader": "8.0.11",
|
||||
"webpack": "5.10.0",
|
||||
"webpack-cli": "4.2.0",
|
||||
"ts-loader": "8.0.11"
|
||||
"webpack-cli": "4.2.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@fortawesome/fontawesome-free": "5.15.1",
|
||||
"bootstrap": "4.5.3",
|
||||
"typescript": "4.1.2",
|
||||
"chart.js": "2.9.4",
|
||||
"datatables.net-bs4": "1.10.22",
|
||||
"jquery": "3.5.1",
|
||||
"jquery.easing": "1.4.1",
|
||||
"sass": "^1.32.8",
|
||||
"typescript": "4.1.2",
|
||||
"what-input": "5.2.10"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,8 @@
|
||||
<spring.session.version>2.4.1</spring.session.version>
|
||||
<spring.maven-plugin.version>2.4.0</spring.maven-plugin.version>
|
||||
|
||||
<discord4j.version>3.1.3</discord4j.version>
|
||||
<discord4j.version>3.2.0-SNAPSHOT</discord4j.version>
|
||||
<discord4j.stores.version>3.1.5</discord4j.stores.version>
|
||||
|
||||
<google.client-api.core.version>1.31.1</google.client-api.core.version>
|
||||
<google.client-api.calendar.version>v3-rev411-1.25.0</google.client-api.calendar.version>
|
||||
|
||||
Reference in New Issue
Block a user