This repository was archived by the owner on Mar 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Replace JDA with Discord4J #4
Draft
duncte123
wants to merge
17
commits into
develop
Choose a base branch
from
feat/d4j
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 5 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
f6b653c
Start on swapping out JDA for Discord4j
duncte123 4f770ed
More rewriting to d4j
duncte123 cd2d71d
Almost completely strip out JDA
duncte123 c65a607
Start on converting the last parts
duncte123 915457b
Filter roles
duncte123 d3f4f4e
Make the role page work
duncte123 d056e72
An attempt to get the permissions for a member
duncte123 b74bfdb
Add check for permissions
duncte123 c8a815c
Got permissions
duncte123 bec194c
Add propper error pages for missing perms
duncte123 3c9eee8
more stuff
duncte123 7e0cfbb
aaaa
duncte123 7f0a440
Wip
duncte123 000f71a
Implement base permissions for member
duncte123 eb75697
Create loads more methods
duncte123 779b87a
God this is slow
duncte123 8c56b75
Merge dev
duncte123 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
src/main/kotlin/com/dunctebot/dashboard/websocket/handlers/DataUpdateHandler.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
src/main/kotlin/com/dunctebot/discord/DiscordRestClient.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| package com.dunctebot.discord | ||
|
|
||
| import com.github.benmanes.caffeine.cache.Caffeine | ||
| import discord4j.common.util.Snowflake | ||
| import discord4j.core.DiscordClient | ||
| import discord4j.discordjson.json.* | ||
| import discord4j.rest.entity.RestGuild | ||
| import discord4j.rest.entity.RestUser | ||
| import net.dv8tion.jda.api.entities.Guild | ||
| import reactor.core.publisher.Flux | ||
| import reactor.core.publisher.Mono | ||
| import java.util.concurrent.TimeUnit | ||
|
|
||
|
|
||
| /** | ||
| * Custom jda rest client that allows for rest-only usage of JDA | ||
| * | ||
| * This class has been inspired by GivawayBot and all credit goes to them https://github.com/jagrosh/GiveawayBot | ||
| */ | ||
| class DiscordRestClient(token: String) { | ||
| // create a guild cache that keeps the guilds in cache for 30 minutes | ||
| // When we stop accessing the guild it will be removed from the cache | ||
| // TODO: use expiring map instead | ||
| private val guildCache = Caffeine.newBuilder() | ||
| .expireAfterAccess(30, TimeUnit.MINUTES) | ||
| .build<String, Guild>() | ||
|
|
||
| private val client = DiscordClient.create(token) | ||
|
|
||
| // TODO: still needed? | ||
| fun invalidateGuild(guildId: Long) { | ||
| this.guildCache.invalidate(guildId.toString()) | ||
| } | ||
|
|
||
| // Note: instantly starts the request | ||
| fun retrieveD4JUserById(id: String): RestUser { | ||
| return this.client.getUserById(Snowflake.of(id)) | ||
| } | ||
|
|
||
| // TODO: cache this | ||
| fun retrieveD4JSelfUser(): Mono<UserData> { | ||
| return this.client.self | ||
| } | ||
|
|
||
| fun retrieveGuildData(guildId: Long): GuildUpdateData { | ||
| return this.getGuild(guildId).data.block()!! | ||
| } | ||
|
|
||
| fun getGuild(guildId: Long): RestGuild { | ||
| return this.client.getGuildById(Snowflake.of(guildId)) | ||
| } | ||
|
|
||
| fun retrieveGuildRoles(guildId: Long): Flux<RoleData> { | ||
| return this.getGuild(guildId).roles | ||
| } | ||
|
|
||
| fun retrieveGuildMembers(guildId: Long): Flux<MemberData> { | ||
| return this.getGuild(guildId).members | ||
| } | ||
|
|
||
| fun retrieveMemberById(guildId: Long, memberId: String): Mono<MemberData> { | ||
| return this.getGuild(guildId).getMember(Snowflake.of(memberId)) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| package com.dunctebot.discord.extensions | ||
|
|
||
| import discord4j.discordjson.json.UserData | ||
|
|
||
| val UserData.asTag: String | ||
| get() = "${this.username()}#${this.discriminator()}" |
This file was deleted.
Oops, something went wrong.
31 changes: 0 additions & 31 deletions
31
src/main/kotlin/com/dunctebot/jda/FakeSessionController.kt
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.